--- a/examples/routing/dynamic-global-routing.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/examples/routing/dynamic-global-routing.cc Fri Jan 22 00:58:01 2010 -0800
@@ -190,13 +190,14 @@
apps2.Stop (Seconds (16.0));
- std::ofstream ascii;
- ascii.open ("dynamic-global-routing.tr", std::ios_base::binary | std::ios_base::out);
+ AsciiTraceHelper ascii;
+ Ptr<OutputStreamObject> stream = ascii.CreateFileStream ("dynamic-global-routing.tr", "w");
+ p2p.EnableAsciiAll (stream);
+ csma.EnableAsciiAll (stream);
+ internet.EnableAsciiAll (stream);
+
p2p.EnablePcapAll ("dynamic-global-routing");
- PointToPointHelper::EnableAsciiAll (ascii);
csma.EnablePcapAll ("dynamic-global-routing", false);
- CsmaHelper::EnableAsciiAll (ascii);
- InternetStackHelper::EnableAsciiAll (ascii);
Ptr<Node> n1 = c.Get (1);
Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> ();
--- a/examples/routing/mixed-global-routing.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/examples/routing/mixed-global-routing.cc Fri Jan 22 00:58:01 2010 -0800
@@ -120,13 +120,13 @@
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
- std::ofstream ascii;
- ascii.open ("mixed-global-routing.tr");
+ AsciiTraceHelper ascii;
+ Ptr<OutputStreamObject> stream = ascii.CreateFileStream ("mixed-global-routing.tr", "w");
+ p2p.EnableAsciiAll (stream);
+ csma,EnableAsciiAll (stream);
+
p2p.EnablePcapAll ("mixed-global-routing");
- PointToPointHelper::EnableAsciiAll (ascii);
csma.EnablePcapAll ("mixed-global-routing", false);
- CsmaHelper::EnableAsciiAll (ascii);
-
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
--- a/src/devices/emu/emu-net-device.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/devices/emu/emu-net-device.h Fri Jan 22 00:58:01 2010 -0800
@@ -104,6 +104,14 @@
*/
void SetQueue (Ptr<Queue> queue);
+ /**
+ * Get a copy of the attached Queue.
+ *
+ * @returns Ptr to the queue.
+ */
+ Ptr<Queue> GetQueue(void) const;
+
+
//
// Pure virtual methods inherited from NetDevice we must implement.
//
@@ -219,16 +227,6 @@
std::string FindCreator (std::string creatorName);
/**
- * Get a copy of the attached Queue.
- *
- * This method is provided for any derived class that may need to get
- * direct access to the underlying queue.
- *
- * @returns Ptr to the queue.
- */
- Ptr<Queue> GetQueue(void) const;
-
- /**
* Spin up the device
*/
void StartDevice (void);
--- a/src/devices/point-to-point/point-to-point-net-device.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/devices/point-to-point/point-to-point-net-device.h Fri Jan 22 00:58:01 2010 -0800
@@ -108,6 +108,13 @@
void SetQueue (Ptr<Queue> queue);
/**
+ * Get a copy of the attached Queue.
+ *
+ * @returns Ptr to the queue.
+ */
+ Ptr<Queue> GetQueue(void) const;
+
+ /**
* Attach a receive ErrorModel to the PointToPointNetDevice.
*
* The PointToPointNetDevice may optionally include an ErrorModel in
@@ -261,16 +268,6 @@
virtual void DoDispose (void);
- /**
- * Get a copy of the attached Queue.
- *
- * This method is provided for any derived class that may need to get
- * direct access to the underlying queue.
- *
- * @returns Ptr to the queue.
- */
- Ptr<Queue> GetQueue(void) const;
-
private:
/**
* Calculate the value for the MTU that would result from
--- a/src/helper/ascii-trace-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/ascii-trace-helper.cc Fri Jan 22 00:58:01 2010 -0800
@@ -74,7 +74,7 @@
}
std::string
-AsciiTraceHelper::GetFilename (std::string prefix, Ptr<NetDevice> device, bool useObjectNames)
+AsciiTraceHelper::GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames)
{
NS_LOG_FUNCTION (prefix << device << useObjectNames);
NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string");
@@ -99,7 +99,7 @@
}
else
{
- oss << node->GetId ();
+ oss << "n" << node->GetId ();
}
oss << "-";
@@ -110,7 +110,7 @@
}
else
{
- oss << device->GetIfIndex ();
+ oss << "d" << device->GetIfIndex ();
}
oss << ".tr";
@@ -118,11 +118,46 @@
return oss.str ();
}
+std::string
+AsciiTraceHelper::GetFilenameFromInterfacePair (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool useObjectNames)
+{
+ NS_LOG_FUNCTION (prefix << ipv4 << interface << useObjectNames);
+ NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string");
+
+ std::ostringstream oss;
+ oss << prefix << "-";
+
+ std::string ipv4name;
+ std::string nodename;
+
+ Ptr<Node> node = ipv4->GetObject<Node> ();
+
+ if (useObjectNames)
+ {
+ ipv4name = Names::FindName (ipv4);
+ nodename = Names::FindName (node);
+ }
+
+ if (ipv4name.size ())
+ {
+ oss << ipv4name;
+ }
+ else if (nodename.size ())
+ {
+ oss << nodename;
+ }
+ else
+ {
+ oss << "n" << node->GetId ();
+ }
+
+ oss << "-i" << interface << ".tr";
+
+ return oss.str ();
+}
+
//
-// The basic default trace sinks. Ascii traces are collected for four
-// operations:
-//
-// Enqueue:
+// One of the basic default trace sink sets. Enqueue:
//
// When a packet has been sent to a device for transmission, the device is
// expected to place the packet onto a transmit queue even if it does not
@@ -132,7 +167,22 @@
// This is typically implemented by hooking the "TxQueue/Enqueue" trace hook
// in the device (actually the Queue in the device).
//
-// Drop:
+void
+AsciiTraceHelper::DefaultEnqueueSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
+{
+ NS_LOG_FUNCTION (file << p);
+ *file->GetStream () << "+ " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
+}
+
+void
+AsciiTraceHelper::DefaultEnqueueSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p)
+{
+ NS_LOG_FUNCTION (file << p);
+ *file->GetStream () << "+ " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
+}
+
+//
+// One of the basic default trace sink sets. Drop:
//
// When a packet has been sent to a device for transmission, the device is
// expected to place the packet onto a transmit queue. If this queue is
@@ -143,7 +193,22 @@
// This is typically implemented by hooking the "TxQueue/Drop" trace hook
// in the device (actually the Queue in the device).
//
-// Dequeue:
+void
+AsciiTraceHelper::DefaultDropSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
+{
+ NS_LOG_FUNCTION (file << p);
+ *file->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
+}
+
+void
+AsciiTraceHelper::DefaultDropSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p)
+{
+ NS_LOG_FUNCTION (file << p);
+ *file->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
+}
+
+//
+// One of the basic default trace sink sets. Dequeue:
//
// When a packet has been sent to a device for transmission, the device is
// expected to place the packet onto a transmit queue even if it does not
@@ -155,7 +220,22 @@
// This is typically implemented by hooking the "TxQueue/Dequeue" trace hook
// in the device (actually the Queue in the device).
//
-// Receive:
+void
+AsciiTraceHelper::DefaultDequeueSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
+{
+ NS_LOG_FUNCTION (file << p);
+ *file->GetStream () << "- " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
+}
+
+void
+AsciiTraceHelper::DefaultDequeueSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p)
+{
+ NS_LOG_FUNCTION (file << p);
+ *file->GetStream () << "- " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
+}
+
+//
+// One of the basic default trace sink sets. Receive:
//
// When a packet is received by a device for transmission, the device is
// expected to trigger this event to indicate the reception has occurred.
@@ -164,34 +244,18 @@
//
// This is typically implemented by hooking the "MacRx" trace hook in the
// device.
-//
-
void
-AsciiTraceHelper::DefaultEnqueueSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
-{
- NS_LOG_FUNCTION (file << p);
- *file->GetStream () << "+ " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
-}
-
-void
-AsciiTraceHelper::DefaultDropSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
-{
- NS_LOG_FUNCTION (file << p);
- *file->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
-}
-
-void
-AsciiTraceHelper::DefaultDequeueSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
-{
- NS_LOG_FUNCTION (file << p);
- *file->GetStream () << "- " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
-}
-
-void
-AsciiTraceHelper::DefaultReceiveSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
+AsciiTraceHelper::DefaultReceiveSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p)
{
NS_LOG_FUNCTION (file << p);
*file->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
}
+void
+AsciiTraceHelper::DefaultReceiveSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p)
+{
+ NS_LOG_FUNCTION (file << p);
+ *file->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
+}
+
} // namespace ns3
--- a/src/helper/ascii-trace-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/ascii-trace-helper.h Fri Jan 22 00:58:01 2010 -0800
@@ -19,9 +19,11 @@
#ifndef ASCII_TRACE_HELPER_H
#define ASCII_TRACE_HELPER_H
+#include "ns3/assert.h"
#include "ns3/net-device-container.h"
#include "ns3/node-container.h"
#include "ns3/simulator.h"
+#include "ns3/ipv4.h"
#include "ns3/output-stream-object.h"
namespace ns3 {
@@ -48,9 +50,16 @@
/**
* @brief Let the ascii trace helper figure out a reasonable filename to use
- * for the ascii trace file.
+ * for an ascii trace file associated with a device.
*/
- std::string GetFilename (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
+ std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
+
+ /**
+ * @brief Let the ascii trace helper figure out a reasonable filename to use
+ * for an ascii trace file associated with a node.
+ */
+ std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Ipv4> ipv4,
+ uint32_t interface, bool useObjectNames = true);
/**
* @brief Create and initialize an output stream object we'll use to write the
@@ -75,54 +84,144 @@
Ptr<OutputStreamObject> CreateFileStream (std::string filename, std::string filemode);
/**
- * @brief Hook a trace source to the default enqueue operation trace sink
+ * @brief Hook a trace source to the default enqueue operation trace sink that
+ * does not accept nor log a trace context.
*/
- template <typename T> void HookDefaultEnqueueSink (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+ template <typename T>
+ void HookDefaultEnqueueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
/**
- * @brief Hook a trace source to the default drop operation trace sink
+ * @brief Hook a trace source to the default enqueue operation trace sink that
+ * does accept and log a trace context.
+ */
+ template <typename T>
+ void HookDefaultEnqueueSinkWithContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+
+ /**
+ * @brief Hook a trace source to the default drop operation trace sink that
+ * does not accept nor log a trace context.
*/
- template <typename T> void HookDefaultDropSink (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+ template <typename T>
+ void HookDefaultDropSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+
+ /**
+ * @brief Hook a trace source to the default drop operation trace sink that
+ * does accept and log a trace context.
+ */
+ template <typename T>
+ void HookDefaultDropSinkWithContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
/**
* @brief Hook a trace source to the default dequeue operation trace sink
+ * that does not accept nor log a trace context.
*/
- template <typename T> void HookDefaultDequeueSink (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+ template <typename T>
+ void HookDefaultDequeueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+
+ /**
+ * @brief Hook a trace source to the default dequeue operation trace sink
+ * that does accept and log a trace context.
+ */
+ template <typename T>
+ void HookDefaultDequeueSinkWithContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+
+ /**
+ * @brief Hook a trace source to the default receive operation trace sink
+ * that does not accept nor log a trace context.
+ */
+ template <typename T>
+ void HookDefaultReceiveSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
/**
* @brief Hook a trace source to the default receive operation trace sink
+ * that does accept and log a trace context.
*/
- template <typename T> void HookDefaultReceiveSink (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+ template <typename T>
+ void HookDefaultReceiveSinkWithContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamObject> stream);
+
+ static void DefaultEnqueueSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
+ static void DefaultEnqueueSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p);
-private:
- static void DefaultEnqueueSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
- static void DefaultDropSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
- static void DefaultDequeueSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
- static void DefaultReceiveSink (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
+ static void DefaultDropSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
+ static void DefaultDropSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p);
+
+ static void DefaultDequeueSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
+ static void DefaultDequeueSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p);
+
+ static void DefaultReceiveSinkWithoutContext (Ptr<OutputStreamObject> file, Ptr<const Packet> p);
+ static void DefaultReceiveSinkWithContext (Ptr<OutputStreamObject> file, std::string context, Ptr<const Packet> p);
};
template <typename T> void
-AsciiTraceHelper::HookDefaultEnqueueSink (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+{
+ bool result = object->TraceConnectWithoutContext (tracename,
+ MakeBoundCallback (&DefaultEnqueueSinkWithoutContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \""
+ << tracename << "\"");
+}
+
+template <typename T> void
+AsciiTraceHelper::HookDefaultEnqueueSinkWithContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
{
- object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultEnqueueSink, file));
+ std::string context ("XXX");
+ bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultEnqueueSinkWithContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \""
+ << tracename << "\"");
+}
+
+template <typename T> void
+AsciiTraceHelper::HookDefaultDropSinkWithoutContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+{
+ bool result = object->TraceConnectWithoutContext (tracename,
+ MakeBoundCallback (&DefaultDropSinkWithoutContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \""
+ << tracename << "\"");
}
template <typename T> void
-AsciiTraceHelper::HookDefaultDropSink (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+AsciiTraceHelper::HookDefaultDropSinkWithContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
{
- object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultDropSink, file));
+ std::string context ("XXX");
+ bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDropSinkWithContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \""
+ << tracename << "\"");
+}
+
+template <typename T> void
+AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+{
+ bool result = object->TraceConnectWithoutContext (tracename,
+ MakeBoundCallback (&DefaultDequeueSinkWithoutContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \""
+ << tracename << "\"");
}
template <typename T> void
-AsciiTraceHelper::HookDefaultDequeueSink (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+AsciiTraceHelper::HookDefaultDequeueSinkWithContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
{
- object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultDequeueSink, file));
+ std::string context ("XXX");
+ bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDequeueSinkWithContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \""
+ << tracename << "\"");
}
template <typename T> void
-AsciiTraceHelper::HookDefaultReceiveSink (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
{
- object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultReceiveSink, file));
+ bool result = object->TraceConnectWithoutContext (tracename,
+ MakeBoundCallback (&DefaultReceiveSinkWithoutContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \""
+ << tracename << "\"");
+}
+
+template <typename T> void
+AsciiTraceHelper::HookDefaultReceiveSinkWithContext (Ptr<T> object, std::string tracename, Ptr<OutputStreamObject> file)
+{
+ std::string context ("XXX");
+ bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultReceiveSinkWithContext, file));
+ NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \""
+ << tracename << "\"");
}
} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/ascii-trace-user-helper-for-device.cc Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,205 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/abort.h"
+#include "ns3/names.h"
+#include "ascii-trace-user-helper-for-device.h"
+
+namespace ns3 {
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (std::string prefix, Ptr<NetDevice> nd)
+{
+ EnableAsciiInternal (Ptr<OutputStreamObject> (), prefix, nd);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, Ptr<NetDevice> nd)
+{
+ EnableAsciiInternal (stream, std::string (), nd);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (std::string prefix, std::string ndName)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, ndName);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, std::string ndName)
+{
+ EnableAsciiImpl (stream, std::string (), ndName);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, std::string ndName)
+{
+ Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
+ EnableAsciiImpl (stream, prefix, nd);
+}
+
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (std::string prefix, NetDeviceContainer d)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, d);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, NetDeviceContainer d)
+{
+ EnableAsciiImpl (stream, std::string (), d);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, NetDeviceContainer d)
+{
+ for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
+ {
+ Ptr<NetDevice> dev = *i;
+ EnableAsciiImpl (stream, prefix, dev);
+ }
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (std::string prefix, NodeContainer n)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, n);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, NodeContainer n)
+{
+ EnableAsciiImpl (stream, std::string (), n);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, NodeContainer n)
+{
+ NetDeviceContainer devs;
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ for (uint32_t j = 0; j < node->GetNDevices (); ++j)
+ {
+ devs.Add (node->GetDevice (j));
+ }
+ }
+ EnableAsciiImpl (stream, prefix, devs);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAsciiAll (std::string prefix)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, NodeContainer::GetGlobal ());
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAsciiAll (Ptr<OutputStreamObject> stream)
+{
+ EnableAsciiImpl (stream, std::string (), NodeContainer::GetGlobal ());
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (Ptr<OutputStreamObject> stream, uint32_t nodeid, uint32_t deviceid)
+{
+ EnableAsciiImpl (stream, std::string (), nodeid, deviceid);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, nodeid, deviceid);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForDevice::EnableAsciiImpl (
+ Ptr<OutputStreamObject> stream,
+ std::string prefix,
+ uint32_t nodeid,
+ uint32_t deviceid)
+{
+ NodeContainer n = NodeContainer::GetGlobal ();
+
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ if (node->GetId () != nodeid)
+ {
+ continue;
+ }
+
+ NS_ABORT_MSG_IF (deviceid >= node->GetNDevices (),
+ "AsciiTraceUserHelperForDevice::EnableAscii(): Unknown deviceid = " << deviceid);
+
+ Ptr<NetDevice> nd = node->GetDevice (deviceid);
+
+ EnableAsciiImpl (stream, prefix, nd);
+ return;
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/ascii-trace-user-helper-for-device.h Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,221 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef ASCII_TRACE_USER_HELPER_FOR_DEVICE_H
+#define ASCII_TRACE_USER_HELPER_FOR_DEVICE_H
+
+#include <string>
+#include "ns3/net-device-container.h"
+#include "ns3/node-container.h"
+#include "ns3/output-stream-object.h"
+
+namespace ns3 {
+
+/**
+ * @brief Base class providing common ascii trace operations for helpers
+ * working with devices.
+ *
+ * There are two basic flavors of ascii tracing. The first kind will case a
+ * trace file to be created for every traced device in the form
+ * <file prefix>-<node number>-<device index>.tr just like the pcap trace
+ * helpers would do. Additionally, if the object name service is used to
+ * define either the node or device, the name will be substituted in the
+ * file name. This form of ascii tracing does not include a context string
+ * and makes it easier to determine the source of the event.
+ *
+ * The second kind of tracing is more like ns-2 tracing in that there is
+ * one trace file into which all of the specified events of the specified
+ * devices are written. This form of ascii tracing does include a context
+ * string and interleaves the trace hits from all of the devices into a
+ * single file.
+ */
+class AsciiTraceUserHelperForDevice
+{
+public:
+ /**
+ * @brief Enable ascii trace output on the indicated net device.
+ * @internal
+ *
+ * The implementation is expected to use a provided Ptr<OutputStreamObject>
+ * if it is non-null. If the OutputStreamObject is null, the implementation
+ * is expected to use a provided prefix to construct a new file name for
+ * each net device using the rules described in the class overview.
+ *
+ * If the prefix is provided, there will be one file per net device created.
+ * In this case, adding a trace context to the file would be pointless, so
+ * the device implementation is expected to TraceConnectWithoutContext.
+ *
+ * If the output stream object is provided, there may be many different
+ * devices writing to a single file. In this case, the device adding a
+ * trace context could be important, so the device implementation is
+ * expected to TraceConnect.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param prefix Filename prefix to use for ascii trace files.
+ * @param nd Net device for which you want to enable tracing.
+ */
+ virtual void EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd) = 0;
+
+ /**
+ * @brief Enable ascii trace output on the indicated net device.
+ *
+ * @param prefix Filename prefix to use for ascii files.
+ * @param nd Net device for which you want to enable tracing.
+ */
+ void EnableAscii (std::string prefix, Ptr<NetDevice> nd);
+
+ /**
+ * @brief Enable ascii trace output on the indicated net device.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param nd Net device for which you want to enable tracing.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, Ptr<NetDevice> nd);
+
+ /**
+ * @brief Enable ascii trace output the indicated net device using a device
+ * previously named using the ns-3 object name service.
+ *
+ * @param filename filename prefix to use for ascii files.
+ * @param ndName The name of the net device in which you want to enable tracing.
+ */
+ void EnableAscii (std::string prefix, std::string ndName);
+
+ /**
+ * @brief Enable ascii trace output the indicated net device using a device
+ * previously named using the ns-3 object name service.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param ndName The name of the net device in which you want to enable tracing.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, std::string ndName);
+
+ /**
+ * @brief Enable ascii trace output on each device in the container which is
+ * of the appropriate type.
+ *
+ * @param prefix Filename prefix to use for ascii files.
+ * @param d container of devices of type ns3::CsmaNetDevice
+ */
+ void EnableAscii (std::string prefix, NetDeviceContainer d);
+
+ /**
+ * @brief Enable ascii trace output on each device in the container which is
+ * of the appropriate type.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param d container of devices of type ns3::CsmaNetDevice
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, NetDeviceContainer d);
+
+ /**
+ * @brief Enable ascii trace output on each device (which is of the
+ * appropriate type) in the nodes provided in the container.
+ *
+ * \param prefix Filename prefix to use for ascii files.
+ * \param n container of nodes.
+ */
+ void EnableAscii (std::string prefix, NodeContainer n);
+
+ /**
+ * @brief Enable ascii trace output on each device (which is of the
+ * appropriate type) in the nodes provided in the container.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * \param n container of nodes.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, NodeContainer n);
+
+ /**
+ * @brief Enable ascii trace output on each device (which is of the
+ * appropriate type) in the set of all nodes created in the simulation.
+ *
+ * @param prefix Filename prefix to use for ascii files.
+ */
+ void EnableAsciiAll (std::string prefix);
+
+ /**
+ * @brief Enable ascii trace output on each device (which is of the
+ * appropriate type) in the set of all nodes created in the simulation.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ */
+ void EnableAsciiAll (Ptr<OutputStreamObject> stream);
+
+ /**
+ * @brief Enable ascii trace output on the device specified by a global
+ * node-id (of a previously created node) and associated device-id.
+ *
+ * @param prefix Filename prefix to use when creating ascii trace files
+ * @param nodeid The node identifier/number of the node on which to enable
+ * ascii tracing
+ * @param deviceid The device identifier/index of the device on which to enable
+ * ascii tracing
+ */
+ void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid);
+
+ /**
+ * @brief Enable ascii trace output on the device specified by a global
+ * node-id (of a previously created node) and associated device-id.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param nodeid The node identifier/number of the node on which to enable
+ * ascii tracing
+ * @param deviceid The device identifier/index of the device on which to enable
+ * ascii tracing
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, uint32_t nodeid, uint32_t deviceid);
+
+private:
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, uint32_t nodeid, uint32_t deviceid);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, NodeContainer n);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, NetDeviceContainer d);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, std::string ndName);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd);
+
+};
+
+} // namespace ns3
+
+#endif // ASCII_USER_HELPER_FOR_DEVICE_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/ascii-trace-user-helper-for-ipv4.cc Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,210 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/abort.h"
+#include "ns3/names.h"
+#include "ascii-trace-user-helper-for-ipv4.h"
+
+namespace ns3 {
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface)
+{
+ EnableAsciiInternal (Ptr<OutputStreamObject> (), prefix, ipv4, interface);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (Ptr<OutputStreamObject> stream, Ptr<Ipv4> ipv4, uint32_t interface)
+{
+ EnableAsciiInternal (stream, std::string (), ipv4, interface);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (std::string prefix, std::string ipv4Name, uint32_t interface)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, ipv4Name, interface);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (Ptr<OutputStreamObject> stream, std::string ipv4Name, uint32_t interface)
+{
+ EnableAsciiImpl (stream, std::string (), ipv4Name, interface);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAsciiImpl (
+ Ptr<OutputStreamObject> stream,
+ std::string prefix,
+ std::string ipv4Name,
+ uint32_t interface)
+{
+ Ptr<Ipv4> ipv4 = Names::Find<Ipv4> (ipv4Name);
+ EnableAsciiImpl (stream, prefix, ipv4, interface);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (std::string prefix, Ipv4InterfaceContainer c)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, c);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (Ptr<OutputStreamObject> stream, Ipv4InterfaceContainer c)
+{
+ EnableAsciiImpl (stream, std::string (), c);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, Ipv4InterfaceContainer c)
+{
+ for (Ipv4InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+ {
+ std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
+ EnableAsciiImpl (stream, prefix, pair.first, pair.second);
+ }
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (std::string prefix, NodeContainer n)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, n);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (Ptr<OutputStreamObject> stream, NodeContainer n)
+{
+ EnableAsciiImpl (stream, std::string (), n);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, NodeContainer n)
+{
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+ if (ipv4)
+ {
+ for (uint32_t j = 0; j < ipv4->GetNInterfaces (); ++j)
+ {
+ EnableAsciiImpl (stream, prefix, ipv4, j);
+ }
+ }
+ }
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAsciiAll (std::string prefix)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, NodeContainer::GetGlobal ());
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAsciiAll (Ptr<OutputStreamObject> stream)
+{
+ EnableAsciiImpl (stream, std::string (), NodeContainer::GetGlobal ());
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (Ptr<OutputStreamObject> stream, uint32_t nodeid, uint32_t interface)
+{
+ EnableAsciiImpl (stream, std::string (), nodeid, interface);
+}
+
+//
+// Public API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAscii (std::string prefix, uint32_t nodeid, uint32_t interface)
+{
+ EnableAsciiImpl (Ptr<OutputStreamObject> (), prefix, nodeid, interface);
+}
+
+//
+// Private API
+//
+void
+AsciiTraceUserHelperForIpv4::EnableAsciiImpl (
+ Ptr<OutputStreamObject> stream,
+ std::string prefix,
+ uint32_t nodeid,
+ uint32_t interface)
+{
+ NodeContainer n = NodeContainer::GetGlobal ();
+
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ if (node->GetId () != nodeid)
+ {
+ continue;
+ }
+
+ Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+ if (ipv4)
+ {
+ EnableAsciiImpl (stream, prefix, ipv4, interface);
+ }
+
+ return;
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/ascii-trace-user-helper-for-ipv4.h Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,232 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef ASCII_TRACE_USER_HELPER_FOR_IPV4_H
+#define ASCII_TRACE_USER_HELPER_FOR_IPV4_H
+
+#include <string>
+#include "ns3/ipv4-interface-container.h"
+#include "ns3/node-container.h"
+#include "ns3/output-stream-object.h"
+
+namespace ns3 {
+
+/**
+ * @brief Base class providing common ascii trace operations for helpers
+ * working with devices.
+ *
+ * There are two basic flavors of ascii tracing. The first kind will case a
+ * trace file to be created for every traced device in the form
+ * <file prefix>-<node number>-<device index>.tr just like the pcap trace
+ * helpers would do. Additionally, if the object name service is used to
+ * define either the node or device, the name will be substituted in the
+ * file name. This form of ascii tracing does not include a context string
+ * and makes it easier to determine the source of the event.
+ *
+ * The second kind of tracing is more like ns-2 tracing in that there is
+ * one trace file into which all of the specified events of the specified
+ * devices are written. This form of ascii tracing does include a context
+ * string and interleaves the trace hits from all of the devices into a
+ * single file.
+ */
+class AsciiTraceUserHelperForIpv4
+{
+public:
+ /**
+ * @brief Enable ascii trace output on the indicated Ipv4 and interface pair.
+ * @internal
+ *
+ * The implementation is expected to use a provided Ptr<OutputStreamObject>
+ * if it is non-null. If the OutputStreamObject is null, the implementation
+ * is expected to use a provided prefix to construct a new file name for
+ * each net device using the rules described in the class overview.
+ *
+ * If the prefix is provided, there will be one file per Ipv4 and interface pair
+ * created. In this case, adding a trace context to the file would be pointless,
+ * so the helper implementation is expected to TraceConnectWithoutContext.
+ *
+ * If the output stream object is provided, there may be many different Ipv4
+ * and interface pairs writing to a single file. In this case, the trace
+ * context could be important, so the helper implementation is expected to
+ * TraceConnect.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param prefix Filename prefix to use for ascii trace files.
+ * @param ipv4 Ptr<Ipv4> on which you want to enable tracing.
+ * @param interface The interface on which you want to enable tracing.
+ */
+ virtual void EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix,
+ Ptr<Ipv4> ipv4, uint32_t interface) = 0;
+
+ /**
+ * @brief Enable ascii trace output on the indicated Ipv4 and interface pair.
+ *
+ * @param prefix Filename prefix to use for ascii files.
+ * @param ipv4 Ptr<Ipv4> on which you want to enable tracing.
+ * @param interface The interface on which you want to enable tracing.
+ */
+ void EnableAscii (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface);
+
+ /**
+ * @brief Enable ascii trace output on the indicated Ipv4 and interface pair.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param ipv4 Ptr<Ipv4> on which you want to enable tracing.
+ * @param interface The interface on which you want to enable tracing.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, Ptr<Ipv4> ipv4, uint32_t interface);
+
+ /**
+ * @brief Enable ascii trace output the indicated Ipv4 and interface pair
+ * using an Ipv4 previously named using the ns-3 object name service.
+ *
+ * @param filename filename prefix to use for ascii files.
+ * @param ipv4Name The name of the Ipv4 on which you want to enable tracing.
+ * @param interface The interface on which you want to enable tracing.
+ */
+ void EnableAscii (std::string prefix, std::string ipv4Name, uint32_t interface);
+
+ /**
+ * @brief Enable ascii trace output the indicated net device using a device
+ * previously named using the ns-3 object name service.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param ipv4Name The name of the Ipv4 on which you want to enable tracing.
+ * @param interface The interface on which you want to enable tracing.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, std::string ipv4Name, uint32_t interface);
+
+ /**
+ * @brief Enable ascii trace output on each Ipv4 and interface pair in the
+ * container
+ *
+ * @param prefix Filename prefix to use for ascii files.
+ * @param c Ipv4InterfaceContainer of Ipv4 and interface pairs on which to
+ * enable tracing.
+ */
+ void EnableAscii (std::string prefix, Ipv4InterfaceContainer c);
+
+ /**
+ * @brief Enable ascii trace output on each device in the container which is
+ * of the appropriate type.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param c Ipv4InterfaceContainer of Ipv4 and interface pairs on which to
+ * enable tracing.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, Ipv4InterfaceContainer c);
+
+ /**
+ * @brief Enable ascii trace output on all Ipv4 and interface pairs existing
+ * in the nodes provided in the container.
+ *
+ * \param prefix Filename prefix to use for ascii files.
+ * \param n container of nodes.
+ */
+ void EnableAscii (std::string prefix, NodeContainer n);
+
+ /**
+ * @brief Enable ascii trace output on all Ipv4 and interface pairs existing
+ * in the nodes provided in the container.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * \param n container of nodes.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, NodeContainer n);
+
+ /**
+ * @brief Enable ascii trace output on all Ipv4 and interface pairs existing
+ * in the set of all nodes created in the simulation.
+ *
+ * @param prefix Filename prefix to use for ascii files.
+ */
+ void EnableAsciiAll (std::string prefix);
+
+ /**
+ * @brief Enable ascii trace output on each device (which is of the
+ * appropriate type) in the set of all nodes created in the simulation.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ */
+ void EnableAsciiAll (Ptr<OutputStreamObject> stream);
+
+ /**
+ * @brief Enable pcap output on the Ipv4 and interface pair specified by a
+ * global node-id (of a previously created node) and interface. Since there
+ * can be only one Ipv4 aggregated to a node, the node-id unambiguously
+ * determines the Ipv4.
+ *
+ * @param prefix Filename prefix to use when creating ascii trace files
+ * @param nodeid The node identifier/number of the node on which to enable
+ * ascii tracing
+ * @param interface The device identifier/index of the device on which to enable
+ * ascii tracing
+ */
+ void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid);
+
+ /**
+ * @brief Enable pcap output on the Ipv4 and interface pair specified by a
+ * global node-id (of a previously created node) and interface. Since there
+ * can be only one Ipv4 aggregated to a node, the node-id unambiguously
+ * determines the Ipv4.
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param nodeid The node identifier/number of the node on which to enable
+ * ascii tracing
+ * @param interface The interface on which you want to enable tracing.
+ */
+ void EnableAscii (Ptr<OutputStreamObject> stream, uint32_t nodeid, uint32_t interface);
+
+private:
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, uint32_t nodeid, uint32_t interface);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, NodeContainer n);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, Ipv4InterfaceContainer c);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, std::string ipv4Name, uint32_t interface);
+
+ /**
+ * @internal Avoid code duplication.
+ */
+ void EnableAsciiImpl (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface);
+
+};
+
+} // namespace ns3
+
+#endif // ASCII_USER_HELPER_FOR_IPV4_H
--- a/src/helper/ascii-trace-user-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2010 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ns3/abort.h"
-#include "ns3/names.h"
-#include "ascii-trace-user-helper.h"
-
-namespace ns3 {
-
-void
-AsciiTraceUserHelper::EnableAscii (std::string prefix, Ptr<NetDevice> nd)
-{
- EnableAsciiInternal (prefix, nd);
-}
-
-void
-AsciiTraceUserHelper::EnableAscii (std::string prefix, std::string ndName)
-{
- Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
- EnableAscii (prefix, nd);
-}
-
-void
-AsciiTraceUserHelper::EnableAscii (std::string prefix, NetDeviceContainer d)
-{
- for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
- {
- Ptr<NetDevice> dev = *i;
- EnableAscii (prefix, dev);
- }
-}
-
-void
-AsciiTraceUserHelper::EnableAscii (std::string prefix, NodeContainer n)
-{
- NetDeviceContainer devs;
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
- }
- EnableAscii (prefix, devs);
-}
-
-void
-AsciiTraceUserHelper::EnableAsciiAllXXX (std::string prefix)
-{
- EnableAscii (prefix, NodeContainer::GetGlobal ());
-}
-
-void
-AsciiTraceUserHelper::EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid)
-{
- NodeContainer n = NodeContainer::GetGlobal ();
-
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- if (node->GetId () != nodeid)
- {
- continue;
- }
-
- NS_ABORT_MSG_IF (deviceid >= node->GetNDevices (),
- "AsciiTraceUserHelper::EnableAscii(): Unknown deviceid = " << deviceid);
-
- Ptr<NetDevice> nd = node->GetDevice (deviceid);
-
- EnableAscii (prefix, nd);
- return;
- }
-}
-
-} // namespace ns3
--- a/src/helper/ascii-trace-user-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2010 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef ASCII_USER_HELPER_H
-#define ASCII_USER_HELPER_H
-
-#include <string>
-#include "ns3/net-device-container.h"
-#include "ns3/node-container.h"
-
-namespace ns3 {
-
-/**
- * \brief Base class providing common ascii trace operations.
- */
-class AsciiTraceUserHelper
-{
-public:
- /**
- * @brief Enable ascii trace output on the indicated net device.
- * @internal
- *
- * @param prefix Filename prefix to use for ascii trace files.
- * @param nd Net device for which you want to enable tracing.
- */
- virtual void EnableAsciiInternal (std::string prefix, Ptr<NetDevice> nd) = 0;
-
- /**
- * @brief Enable ascii trace output on the indicated net device.
- *
- * @param prefix Filename prefix to use for ascii files.
- * @param nd Net device for which you want to enable tracing.
- */
- void EnableAscii (std::string prefix, Ptr<NetDevice> nd);
-
- /**
- * @brief Enable ascii trace output the indicated net device using a device
- * previously named using the ns-3 object name service.
- *
- * @param filename filename prefix to use for ascii files.
- * @param ndName The name of the net device in which you want to enable tracing.
- */
- void EnableAscii (std::string prefix, std::string ndName);
-
- /**
- * @brief Enable ascii trace output on each device in the container which is
- * of the appropriate type.
- *
- * @param prefix Filename prefix to use for ascii files.
- * @param d container of devices of type ns3::CsmaNetDevice
- */
- void EnableAscii (std::string prefix, NetDeviceContainer d);
-
- /**
- * @brief Enable ascii trace output on each device (which is of the
- * appropriate type) in the nodes provided in the container.
- *
- * \param prefix Filename prefix to use for ascii files.
- * \param n container of nodes.
- */
- void EnableAscii (std::string prefix, NodeContainer n);
-
- /**
- * @brief Enable ascii trace output on each device (which is of the
- * appropriate type) in the set of all nodes created in the simulation.
- *
- * @param prefix Filename prefix to use for ascii files.
- */
- void EnableAsciiAllXXX (std::string prefix);
-
- /**
- * @brief Enable ascii trace output on the device specified by a global
- * node-id (of a previously created node) and associated device-id.
- *
- * @param prefix Filename prefix to use for ascii files.
- */
- void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid);
-};
-
-} // namespace ns3
-
-#endif // ASCII_USER_HELPER_H
--- a/src/helper/csma-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/csma-helper.cc Fri Jan 22 00:58:01 2010 -0800
@@ -28,8 +28,6 @@
#include "ns3/config.h"
#include "ns3/packet.h"
#include "ns3/names.h"
-#include "ns3/pcap-writer.h"
-#include "ns3/ascii-writer.h"
#include "pcap-helper.h"
#include "ascii-trace-helper.h"
@@ -90,7 +88,7 @@
}
PcapHelper pcapHelper;
- std::string filename = pcapHelper.GetFilename (prefix, device);
+ std::string filename = pcapHelper.GetFilenameFromDevice (prefix, device);
Ptr<PcapFileObject> file = pcapHelper.CreateFile (filename, "w", PcapHelper::DLT_EN10MB);
if (promiscuous)
{
@@ -103,7 +101,7 @@
}
void
-CsmaHelper::EnableAsciiInternal (std::string prefix, Ptr<NetDevice> nd)
+CsmaHelper::EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd)
{
//
// All of the ascii enable functions vector through here including the ones
@@ -118,75 +116,75 @@
}
//
- // Set up an output stream object to deal with private ofstream copy
- // constructor and lifetime issues. Let the helper decide the actual
- // name of the file given the prefix.
+ // Our default trace sinks are going to use packet printing, so we have to
+ // make sure that is turned on.
//
- AsciiTraceHelper asciiTraceHelper;
- std::string filename = asciiTraceHelper.GetFilename (prefix, device);
- Ptr<OutputStreamObject> stream = asciiTraceHelper.CreateFileStream (filename, "w");
-
- //
- // The MacRx trace source provides our "r" event.
- //
- asciiTraceHelper.HookDefaultReceiveSink<CsmaNetDevice> (device, "MacRx", stream);
+ Packet::EnablePrinting ();
//
- // The "+", '-', and 'd' events are driven by trace sources actually in the
- // transmit queue.
+ // If we are not provided an OutputStreamObject, we are expected to create
+ // one using the usual trace filename conventions and do a Hook*WithoutContext
+ // since there will be one file per context and therefore the context would
+ // be redundant.
//
- Ptr<Queue> queue = device->GetQueue ();
- asciiTraceHelper.HookDefaultEnqueueSink<Queue> (queue, "Enqueue", stream);
- asciiTraceHelper.HookDefaultDropSink<Queue> (queue, "Drop", stream);
- asciiTraceHelper.HookDefaultDequeueSink<Queue> (queue, "Dequeue", stream);
-}
+ if (stream == 0)
+ {
+ //
+ // Set up an output stream object to deal with private ofstream copy
+ // constructor and lifetime issues. Let the helper decide the actual
+ // name of the file given the prefix.
+ //
+ AsciiTraceHelper asciiTraceHelper;
+ std::string filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
+ Ptr<OutputStreamObject> theStream = asciiTraceHelper.CreateFileStream (filename, "w");
+
+ //
+ // The MacRx trace source provides our "r" event.
+ //
+ asciiTraceHelper.HookDefaultReceiveSinkWithoutContext<CsmaNetDevice> (device, "MacRx", theStream);
-void
-CsmaHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
-{
- Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
- Packet::EnablePrinting ();
+ //
+ // The "+", '-', and 'd' events are driven by trace sources actually in the
+ // transmit queue.
+ //
+ Ptr<Queue> queue = device->GetQueue ();
+ asciiTraceHelper.HookDefaultEnqueueSinkWithoutContext<Queue> (queue, "Enqueue", theStream);
+ asciiTraceHelper.HookDefaultDropSinkWithoutContext<Queue> (queue, "Drop", theStream);
+ asciiTraceHelper.HookDefaultDequeueSinkWithoutContext<Queue> (queue, "Dequeue", theStream);
+
+ return;
+ }
+
+ //
+ // If we are provided an OutputStreamObject, we are expected to use it, and
+ // to providd a context. We are free to come up with our own context if we
+ // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
+ // compatibility and simplicity, we just use Config::Connect and let it deal
+ // with the context.
+ //
+ // Note that we are going to use the default trace sinks provided by the
+ // ascii trace helper. There is actually no AsciiTraceHelper in sight here,
+ // but the default trace sinks are actually publicly available static
+ // functions that are always there waiting for just such a case.
+ //
+ uint32_t nodeid = nd->GetNode ()->GetId ();
+ uint32_t deviceid = nd->GetIfIndex ();
std::ostringstream oss;
- oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/MacRx";
- Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, writer));
+
+ oss << "/NodeList/" << nd->GetNode ()->GetId () << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/MacRx";
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultReceiveSinkWithContext, stream));
+
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
- Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEnqueueEvent, writer));
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultEnqueueSinkWithContext, stream));
+
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Dequeue";
- Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDequeueEvent, writer));
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDequeueSinkWithContext, stream));
+
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Drop";
- Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDropEvent, writer));
-}
-void
-CsmaHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
-{
- for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
- {
- Ptr<NetDevice> dev = *i;
- EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
- }
-}
-void
-CsmaHelper::EnableAscii (std::ostream &os, NodeContainer n)
-{
- NetDeviceContainer devs;
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
- }
- EnableAscii (os, devs);
-}
-
-void
-CsmaHelper::EnableAsciiAll (std::ostream &os)
-{
- EnableAscii (os, NodeContainer::GetGlobal ());
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
}
NetDeviceContainer
@@ -272,28 +270,4 @@
return device;
}
-void
-CsmaHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::ENQUEUE, path, packet);
-}
-
-void
-CsmaHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::DEQUEUE, path, packet);
-}
-
-void
-CsmaHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::DROP, path, packet);
-}
-
-void
-CsmaHelper::AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::RX, path, packet);
-}
-
} // namespace ns3
--- a/src/helper/csma-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/csma-helper.h Fri Jan 22 00:58:01 2010 -0800
@@ -28,19 +28,17 @@
#include "ns3/node-container.h"
#include "ns3/csma-channel.h"
#include "ns3/deprecated.h"
-
-#include "pcap-user-helper.h"
-#include "ascii-trace-user-helper.h"
+#include "pcap-user-helper-for-device.h"
+#include "ascii-trace-user-helper-for-device.h"
namespace ns3 {
class Packet;
-class AsciiWriter;
/**
* \brief build a set of CsmaNetDevice objects
*/
-class CsmaHelper : public PcapUserHelper, public AsciiTraceUserHelper
+class CsmaHelper : public PcapUserHelperForDevice, public AsciiTraceUserHelperForDevice
{
public:
/**
@@ -87,45 +85,6 @@
void SetChannelAttribute (std::string n1, const AttributeValue &v1);
/**
- * \param os output stream
- * \param nodeid the id of the node to generate ascii output for.
- * \param deviceid the id of the device to generate ascii output for.
- *
- * Enable ascii output on the specified deviceid within the
- * specified nodeid if it is of type ns3::CsmaNetDevice and dump
- * that to the specified stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid);
- /**
- * \param os output stream
- * \param d device container
- *
- * Enable ascii output on each device which is of the
- * ns3::CsmaNetDevice type and which is located in the input
- * device container and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NetDeviceContainer d);
- /**
- * \param os output stream
- * \param n node container
- *
- * Enable ascii output on each device which is of the
- * ns3::CsmaNetDevice type and which is located in one
- * of the input node and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NodeContainer n);
- /**
- * \param os output stream
- *
- * Enable ascii output on each device which is of the
- * ns3::CsmaNetDevice type and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAsciiAll (std::ostream &os);
-
- /**
* This method creates an ns3::CsmaChannel with the attributes configured by
* CsmaHelper::SetChannelAttribute, an ns3::CsmaNetDevice with the attributes
* configured by CsmaHelper::SetDeviceAttribute and then adds the device
@@ -253,30 +212,11 @@
* NetDevice-specific implementation mechanism for hooking the trace and
* writing to the trace file.
*
- * \param prefix Filename prefix to use for pcap files.
+ * \param stream The output stream object to use when logging ascii traces.
+ * \param prefix Filename prefix to use for ascii trace files.
* \param nd Net device for which you want to enable tracing.
*/
- virtual void EnableAsciiInternal (std::string prefix, Ptr<NetDevice> nd);
-
- /*
- * \internal
- */
- static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
-
- /*
- * \internal
- */
- static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
-
- /*
- * \internal
- */
- static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
-
- /*
- * \internal
- */
- static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
+ virtual void EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd);
ObjectFactory m_queueFactory;
ObjectFactory m_deviceFactory;
--- a/src/helper/emu-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/emu-helper.cc Fri Jan 22 00:58:01 2010 -0800
@@ -24,12 +24,11 @@
#include "ns3/names.h"
#include "ns3/queue.h"
#include "ns3/emu-net-device.h"
-#include "ns3/pcap-writer.h"
-#include "ns3/ascii-writer.h"
#include "ns3/config.h"
#include "ns3/packet.h"
#include "pcap-helper.h"
+#include "ascii-trace-helper.h"
#include "emu-helper.h"
NS_LOG_COMPONENT_DEFINE ("EmuHelper");
@@ -82,7 +81,7 @@
}
PcapHelper pcapHelper;
- std::string filename = pcapHelper.GetFilename (prefix, device);
+ std::string filename = pcapHelper.GetFilenameFromDevice (prefix, device);
Ptr<PcapFileObject> file = pcapHelper.CreateFile (filename, "w", PcapHelper::DLT_EN10MB);
if (promiscuous)
{
@@ -95,61 +94,90 @@
}
void
-EmuHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
+EmuHelper::EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd)
{
- NS_LOG_FUNCTION (&os << nodeid << deviceid);
- Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
+ //
+ // All of the ascii enable functions vector through here including the ones
+ // that are wandering through all of devices on perhaps all of the nodes in
+ // the system. We can only deal with devices of type EmuNetDevice.
+ //
+ Ptr<EmuNetDevice> device = nd->GetObject<EmuNetDevice> ();
+ if (device == 0)
+ {
+ NS_LOG_INFO ("EmuHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::EmuNetDevice");
+ return;
+ }
+
+ //
+ // Our default trace sinks are going to use packet printing, so we have to
+ // make sure that is turned on.
+ //
Packet::EnablePrinting ();
+
+ //
+ // If we are not provided an OutputStreamObject, we are expected to create
+ // one using the usual trace filename conventions and do a Hook*WithoutContext
+ // since there will be one file per context and therefore the context would
+ // be redundant.
+ //
+ if (stream == 0)
+ {
+ //
+ // Set up an output stream object to deal with private ofstream copy
+ // constructor and lifetime issues. Let the helper decide the actual
+ // name of the file given the prefix.
+ //
+ AsciiTraceHelper asciiTraceHelper;
+ std::string filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
+ Ptr<OutputStreamObject> theStream = asciiTraceHelper.CreateFileStream (filename, "w");
+
+ //
+ // The MacRx trace source provides our "r" event.
+ //
+ asciiTraceHelper.HookDefaultReceiveSinkWithoutContext<EmuNetDevice> (device, "MacRx", theStream);
+
+ //
+ // The "+", '-', and 'd' events are driven by trace sources actually in the
+ // transmit queue.
+ //
+ Ptr<Queue> queue = device->GetQueue ();
+ asciiTraceHelper.HookDefaultEnqueueSinkWithoutContext<Queue> (queue, "Enqueue", theStream);
+ asciiTraceHelper.HookDefaultDropSinkWithoutContext<Queue> (queue, "Drop", theStream);
+ asciiTraceHelper.HookDefaultDequeueSinkWithoutContext<Queue> (queue, "Dequeue", theStream);
+
+ return;
+ }
+
+ //
+ // If we are provided an OutputStreamObject, we are expected to use it, and
+ // to providd a context. We are free to come up with our own context if we
+ // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
+ // compatibility and simplicity, we just use Config::Connect and let it deal
+ // with the context.
+ //
+ // Note that we are going to use the default trace sinks provided by the
+ // ascii trace helper. There is actually no AsciiTraceHelper in sight here,
+ // but the default trace sinks are actually publicly available static
+ // functions that are always there waiting for just such a case.
+ //
+ uint32_t nodeid = nd->GetNode ()->GetId ();
+ uint32_t deviceid = nd->GetIfIndex ();
std::ostringstream oss;
- oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/MacRx";
- Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiRxEvent, writer));
+ oss << "/NodeList/" << nd->GetNode ()->GetId () << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/MacRx";
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultReceiveSinkWithContext, stream));
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Enqueue";
- Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiEnqueueEvent, writer));
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultEnqueueSinkWithContext, stream));
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Dequeue";
- Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDequeueEvent, writer));
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDequeueSinkWithContext, stream));
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Drop";
- Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDropEvent, writer));
-}
-
-void
-EmuHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
-{
- NS_LOG_FUNCTION (&os << &d);
- for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
- {
- Ptr<NetDevice> dev = *i;
- EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
- }
-}
-
-void
-EmuHelper::EnableAscii (std::ostream &os, NodeContainer n)
-{
- NS_LOG_FUNCTION (&os << &n);
- NetDeviceContainer devs;
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
- }
- EnableAscii (os, devs);
-}
-
-void
-EmuHelper::EnableAsciiAll (std::ostream &os)
-{
- NS_LOG_FUNCTION (&os);
- EnableAscii (os, NodeContainer::GetGlobal ());
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
}
NetDeviceContainer
@@ -190,40 +218,4 @@
return device;
}
-void
-EmuHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer,
- std::string path,
- Ptr<const Packet> packet)
-{
- NS_LOG_FUNCTION (writer << path << packet);
- writer->WritePacket (AsciiWriter::ENQUEUE, path, packet);
-}
-
-void
-EmuHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer,
- std::string path,
- Ptr<const Packet> packet)
-{
- NS_LOG_FUNCTION (writer << path << packet);
- writer->WritePacket (AsciiWriter::DEQUEUE, path, packet);
-}
-
-void
-EmuHelper::AsciiDropEvent (Ptr<AsciiWriter> writer,
- std::string path,
- Ptr<const Packet> packet)
-{
- NS_LOG_FUNCTION (writer << path << packet);
- writer->WritePacket (AsciiWriter::DROP, path, packet);
-}
-
-void
-EmuHelper::AsciiRxEvent (Ptr<AsciiWriter> writer,
- std::string path,
- Ptr<const Packet> packet)
-{
- NS_LOG_FUNCTION (writer << path << packet);
- writer->WritePacket (AsciiWriter::RX, path, packet);
-}
-
} // namespace ns3
--- a/src/helper/emu-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/emu-helper.h Fri Jan 22 00:58:01 2010 -0800
@@ -28,18 +28,17 @@
#include "ns3/node-container.h"
#include "ns3/emu-net-device.h"
-#include "pcap-user-helper.h"
+#include "pcap-user-helper-for-device.h"
+#include "ascii-trace-user-helper-for-device.h"
namespace ns3 {
class Packet;
-class PcapWriter;
-class AsciiWriter;
/**
* \brief build a set of EmuNetDevice objects
*/
-class EmuHelper : public PcapUserHelper
+class EmuHelper : public PcapUserHelperForDevice, public AsciiTraceUserHelperForDevice
{
public:
/*
@@ -78,48 +77,6 @@
void SetAttribute (std::string n1, const AttributeValue &v1);
/**
- * \param os output stream
- * \param nodeid the id of the node to generate ascii output for.
- * \param deviceid the id of the device to generate ascii output for.
- *
- * Enable ascii output on the specified deviceid within the
- * specified nodeid if it is of type ns3::EmuNetDevice and dump
- * that to the specified stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid);
-
- /**
- * \param os output stream
- * \param d device container
- *
- * Enable ascii output on each device which is of the
- * ns3::EmuNetDevice type and which is located in the input
- * device container and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NetDeviceContainer d);
-
- /**
- * \param os output stream
- * \param n node container
- *
- * Enable ascii output on each device which is of the
- * ns3::EmuNetDevice type and which is located in one
- * of the input node and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NodeContainer n);
-
- /**
- * \param os output stream
- *
- * Enable ascii output on each device which is of the
- * ns3::EmuNetDevice type and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAsciiAll (std::ostream &os);
-
- /**
* This method creates an ns3::EmuNetDevice with the attributes configured by
* EmuHelper::SetDeviceAttribute and then adds the device to the node.
*
@@ -165,25 +122,18 @@
*/
virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false);
- /*
+ /**
+ * \brief Enable ascii trace output on the indicated net device.
* \internal
- */
- static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
-
- /*
- * \internal
+ *
+ * NetDevice-specific implementation mechanism for hooking the trace and
+ * writing to the trace file.
+ *
+ * \param stream The output stream object to use when logging ascii traces.
+ * \param prefix Filename prefix to use for ascii trace files.
+ * \param nd Net device for which you want to enable tracing.
*/
- static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
-
- /*
- * \internal
- */
- static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
-
- /*
- * \internal
- */
- static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
+ virtual void EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd);
ObjectFactory m_queueFactory;
ObjectFactory m_deviceFactory;
--- a/src/helper/internet-stack-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/internet-stack-helper.cc Fri Jan 22 00:58:01 2010 -0800
@@ -174,8 +174,10 @@
namespace ns3 {
+#if 0
std::vector<InternetStackHelper::Trace> InternetStackHelper::m_traces;
std::string InternetStackHelper::m_pcapBaseFilename;
+#endif
InternetStackHelper::InternetStackHelper ()
: m_routing (0),
@@ -270,6 +272,7 @@
void
InternetStackHelper::Cleanup (void)
{
+#if 0
uint32_t illegal = std::numeric_limits<uint32_t>::max ();
for (std::vector<Trace>::iterator i = m_traces.begin ();
@@ -280,6 +283,7 @@
i->writer = 0;
}
m_traces.clear ();
+#endif
}
void
@@ -373,6 +377,198 @@
Ptr<Node> node = Names::Find<Node> (nodeName);
Install (node);
}
+
+void
+InternetStackHelper::EnablePcapInternal (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface)
+{
+#if 0
+ //
+ // We would normally create the pcap file here, but we need to create a file
+ // for each interface. This is because when the trace sink for Rx and Tx are
+ // called, we get the packet and an interface ID. We want to group packets
+ // to/from a given interface id into a pcap file, but we have no knowledge
+ // here about what interfaces are created. So we have to go with the flow.
+ // Look for the file creation to happen in the
+ //
+ PcapHelper pcapHelper;
+ std::string filename = pcapHelper.GetFilenameFromNode (prefix, node);
+ Ptr<PcapFileObject> file = pcapHelper.CreateFile (filename, "w", PcapHelper::DLT_RAW);
+
+ //
+ // We want to enable Tx and Rx traces on Ipv4L3Protocol if m_ipv4Enabled; and
+ // we want to enable Tx and Rx traces on Ipv6L3Protocol if m_ipv6Enabled. The
+ // simple way to do that is to let Config::Connect wander through the global
+ // node list looking for <node> and then the appropriate protocols and trace
+ // sources. Since we have the node handy, we can be quicker about it, but it
+ // takes slightly more work here.
+ //
+ if (m_ipv4Enabled)
+ {
+ Ptr<Ipv4L3Protocol> ipv4L3Protocol = node->GetObject<Ipv4L3Protocol> ();
+ NS_ASSERT_MSG (ipv4L3Protocol, "InternetStackHelper::EnablePcapInternal(): "
+ "m_ipv4Enabled and ipv4L3Protocol inconsistent");
+
+ bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx", MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapInternal(): Unable to connect ipv4L3Protocol \"Tx\"");
+
+ result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx", MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapInternal(): Unable to connect ipv4L3Protocol \"Rx\"");
+
+ }
+
+ if (m_ipv6Enabled)
+ {
+ Ptr<Ipv6L3Protocol> ipv6L3Protocol = node->GetObject<Ipv6L3Protocol> ();
+ NS_FATAL_ERROR_UNLESS (ipv6L3Protocol, "InternetStackHelper::EnablePcapInternal(): "
+ "m_ipv6Enabled and ipv6L3Protocol inconsistent");
+
+ bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx", MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapInternal(): Unable to connect ipv6L3Protocol \"Tx\"");
+
+ result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx", MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapInternal(): Unable to connect ipv6L3Protocol \"Rx\"");
+
+ }
+#endif
+}
+
+
+
+#if 0
+ //
+ // We want to enable drop traces on Ipv4L3Protocol and ArpL3Protocol if
+ // m_ipv4Enabled; and we want to enable the drop trace on Ipv6L3Protocol
+ // if enabled. The simple way to do that is to let Config::Connect wander
+ // through the global node list looking for <node> and then the appropriate
+ // protocols and trace sources. Since we have the node handy, we can be
+ // quicker about it, but it takes slightly more work here.
+ //
+ if (m_ipv4Enabled)
+ {
+ Ptr<Ipv4L3Protocol> ipv4L3Protocol = node->GetObject<Ipv4L3Protocol> ();
+ NS_ASSERT_MSG (ipv4L3Protocol, "InternetStackHelper::EnablePcapInternal(): "
+ "m_ipv4Enabled and ipv4L3Protocol inconsistent");
+
+ bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop", MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapInternal(): Unable to connect ipv4L3Protocol \"Drop\"");
+
+ Ptr<ArpL3Protocol> arpL3Protocol = node->GetObject<ArpL3Protocol> ();
+ NS_ASSERT_MSG (arpL3Protocol, "InternetStackHelper::EnablePcapInternal(): "
+ "m_ipv4Enabled and arpL3Protocol inconsistent");
+
+ result = arpL3Protocol->TraceConnectWithoutContext ("Drop", MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapInternal(): Unable to connect arpL3Protocol \"Drop\"");
+ }
+
+ if (m_ipv6Enabled)
+ {
+ Ptr<Ipv6L3Protocol> ipv6L3Protocol = node->GetObject<Ipv6L3Protocol> ();
+ NS_FATAL_ERROR_UNLESS (ipv6L3Protocol, "InternetStackHelper::EnablePcapInternal(): "
+ "m_ipv6Enabled and ipv6L3Protocol inconsistent");
+
+ bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Drop", MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapInternal(): Unable to connect ipv6L3Protocol \"Drop\"");
+ }
+#endif
+
+
+
+void
+InternetStackHelper::EnableAsciiInternal (
+ Ptr<OutputStreamObject> stream,
+ std::string prefix,
+ Ptr<Ipv4> ipv4,
+ uint32_t interface)
+{
+#if 0
+ //
+ // All of the ascii enable functions vector through here including the ones
+ // that are wandering through all of devices on perhaps all of the nodes in
+ // the system. We can only deal with devices of type CsmaNetDevice.
+ //
+ Ptr<CsmaNetDevice> device = nd->GetObject<CsmaNetDevice> ();
+ if (device == 0)
+ {
+ NS_LOG_INFO ("CsmaHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::CsmaNetDevice");
+ return;
+ }
+
+ //
+ // Our default trace sinks are going to use packet printing, so we have to
+ // make sure that is turned on.
+ //
+ Packet::EnablePrinting ();
+
+ //
+ // If we are not provided an OutputStreamObject, we are expected to create
+ // one using the usual trace filename conventions and do a Hook*WithoutContext
+ // since there will be one file per context and therefore the context would
+ // be redundant.
+ //
+ if (stream == 0)
+ {
+ //
+ // Set up an output stream object to deal with private ofstream copy
+ // constructor and lifetime issues. Let the helper decide the actual
+ // name of the file given the prefix.
+ //
+ AsciiTraceHelper asciiTraceHelper;
+ std::string filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
+ Ptr<OutputStreamObject> theStream = asciiTraceHelper.CreateFileStream (filename, "w");
+
+ //
+ // The MacRx trace source provides our "r" event.
+ //
+ asciiTraceHelper.HookDefaultReceiveSinkWithoutContext<CsmaNetDevice> (device, "MacRx", theStream);
+
+ //
+ // The "+", '-', and 'd' events are driven by trace sources actually in the
+ // transmit queue.
+ //
+ Ptr<Queue> queue = device->GetQueue ();
+ asciiTraceHelper.HookDefaultEnqueueSinkWithoutContext<Queue> (queue, "Enqueue", theStream);
+ asciiTraceHelper.HookDefaultDropSinkWithoutContext<Queue> (queue, "Drop", theStream);
+ asciiTraceHelper.HookDefaultDequeueSinkWithoutContext<Queue> (queue, "Dequeue", theStream);
+
+ return;
+ }
+
+ //
+ // If we are provided an OutputStreamObject, we are expected to use it, and
+ // to providd a context. We are free to come up with our own context if we
+ // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
+ // compatibility and simplicity, we just use Config::Connect and let it deal
+ // with the context.
+ //
+ // Note that we are going to use the default trace sinks provided by the
+ // ascii trace helper. There is actually no AsciiTraceHelper in sight here,
+ // but the default trace sinks are actually publicly available static
+ // functions that are always there waiting for just such a case.
+ //
+ uint32_t nodeid = nd->GetNode ()->GetId ();
+ uint32_t deviceid = nd->GetIfIndex ();
+ std::ostringstream oss;
+
+ oss << "/NodeList/" << nd->GetNode ()->GetId () << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/MacRx";
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultReceiveSinkWithContext, stream));
+
+ oss.str ("");
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultEnqueueSinkWithContext, stream));
+
+ oss.str ("");
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Dequeue";
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDequeueSinkWithContext, stream));
+
+ oss.str ("");
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Drop";
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
+#endif
+}
+
+
+
+#if 0
void
InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n)
{
@@ -497,5 +693,6 @@
p->AddHeader (header);
writer->WritePacket (AsciiWriter::DROP, path, p);
}
+#endif
} // namespace ns3
--- a/src/helper/internet-stack-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/internet-stack-helper.h Fri Jan 22 00:58:01 2010 -0800
@@ -26,10 +26,10 @@
#include "ns3/packet.h"
#include "ns3/ptr.h"
#include "ns3/object-factory.h"
-#include "ns3/pcap-writer.h"
-#include "ns3/ascii-writer.h"
#include "ns3/ipv4-l3-protocol.h"
#include "ns3/ipv6-l3-protocol.h"
+#include "pcap-user-helper-for-ipv4.h"
+#include "ascii-trace-user-helper-for-ipv4.h"
namespace ns3 {
@@ -39,8 +39,15 @@
/**
* \brief aggregate IP/TCP/UDP functionality to existing Nodes.
+ *
+ * This helper enables pcap and ascii tracing of events in the internet stack
+ * associated with a node. This is substantially similar to the tracing
+ * that happens in device helpers, but the important difference is that, well,
+ * there is no device. This means that the creation of output file names will
+ * change, and also the user-visible methods will not reference devices and
+ * therefore the number of trace enable methods is reduced.
*/
-class InternetStackHelper
+class InternetStackHelper : public PcapUserHelperForIpv4, public AsciiTraceUserHelperForIpv4
{
public:
/**
@@ -145,43 +152,6 @@
void SetTcp (std::string tid, std::string attr, const AttributeValue &val);
/**
- * \param os output stream
- * \param n node container
- *
- * Enable ascii output on these drop traces, for each node in the NodeContainer..
- * /NodeList/[i]/$ns3ArpL3Protocol/Drop
- * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop
- * /NodeList/[i]/$ns3Ipv6L3Protocol/Drop
- */
- static void EnableAscii (std::ostream &os, NodeContainer n);
-
- /**
- * \param os output stream
- *
- * Enable ascii output on these drop traces, for all nodes.
- * /NodeList/[i]/$ns3ArpL3Protocol/Drop
- * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop
- * /NodeList/[i]/$ns3Ipv6L3Protocol/Drop
- */
- static void EnableAsciiAll (std::ostream &os);
-
- /**
- * Enable pcap output on each protocol instance which is of the
- * ns3::Ipv4L3Protocol or ns3::Ipv6L3Protocol type. Both Tx and
- * Rx events will be logged.
- *
- * \param filename filename prefix to use for pcap files.
- *
- * \warning If you perform multiple simulations in a single script,
- * each iteration of the simulation will result in the trace files
- * being overwritten. We don't attempt to anticipate what a user
- * might actually want to do, so we leave it up to them. If you want
- * to save any particular data, do so manually at inter-simulation
- * time.
- */
- static void EnablePcapAll (std::string filename);
-
- /**
* \brief Enable/disable IPv4 stack install.
* \param enable enable state
*/
@@ -194,6 +164,28 @@
void SetIpv6StackInstall (bool enable);
private:
+ /**
+ * @brief Enable pcap output the indicated Ipv4 and interface pair.
+ * @internal
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param ipv4 Ptr to the Ipv4 interface on which you want to enable tracing.
+ * @param interface Interface ID on the Ipv4 on which you want to enable tracing.
+ */
+ virtual void EnablePcapInternal (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface);
+
+ /**
+ * @brief Enable ascii trace output on the indicated Ipv4 and interface pair.
+ * @internal
+ *
+ * @param stream An OutputStreamObject representing an existing file to use
+ * when writing trace data.
+ * @param prefix Filename prefix to use for ascii trace files.
+ * @param ipv4 Ptr to the Ipv4 interface on which you want to enable tracing.
+ * @param interface Interface ID on the Ipv4 on which you want to enable tracing.
+ */
+ virtual void EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface);
+
void Initialize (void);
ObjectFactory m_tcpFactory;
const Ipv4RoutingHelper *m_routing;
@@ -214,6 +206,7 @@
*/
static void Cleanup (void);
+#if 0
/**
* \internal
*/
@@ -261,6 +254,7 @@
static uint32_t GetNodeIndex (std::string context);
static std::vector<Trace> m_traces;
+#endif
/**
* \brief IPv4 install state (enabled/disabled) ?
--- a/src/helper/ipv4-interface-container.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/ipv4-interface-container.cc Fri Jan 22 00:58:01 2010 -0800
@@ -16,6 +16,18 @@
}
}
+Ipv4InterfaceContainer::Iterator
+Ipv4InterfaceContainer::Begin (void) const
+{
+ return m_interfaces.begin ();
+}
+
+Ipv4InterfaceContainer::Iterator
+Ipv4InterfaceContainer::End (void) const
+{
+ return m_interfaces.end ();
+}
+
uint32_t
Ipv4InterfaceContainer::GetN (void) const
{
--- a/src/helper/ipv4-interface-container.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/ipv4-interface-container.h Fri Jan 22 00:58:01 2010 -0800
@@ -32,6 +32,8 @@
class Ipv4InterfaceContainer
{
public:
+ typedef std::vector<std::pair<Ptr<Ipv4>, uint32_t> >::const_iterator Iterator;
+
/**
* Create an empty Ipv4InterfaceContainer.
*/
@@ -44,8 +46,69 @@
void Add (Ipv4InterfaceContainer other);
/**
+ * \brief Get an iterator which refers to the first pair in the
+ * container.
+ *
+ * Pairs can be retrieved from the container in two ways. First,
+ * directly by an index into the container, and second, using an iterator.
+ * This method is used in the iterator method and is typically used in a
+ * for-loop to run through the pairs
+ *
+ * \code
+ * Ipv4InterfaceContainer::Iterator i;
+ * for (i = container.Begin (); i != container.End (); ++i)
+ * {
+ * std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
+ * method (pair.first, pair.second); // use the pair
+ * }
+ * \endcode
+ *
+ * \returns an iterator which refers to the first pair in the container.
+ */
+ Iterator Begin (void) const;
+
+ /**
+ * \brief Get an iterator which indicates past-the-last Node in the
+ * container.
+ *
+ * Nodes can be retrieved from the container in two ways. First,
+ * directly by an index into the container, and second, using an iterator.
+ * This method is used in the iterator method and is typically used in a
+ * for-loop to run through the Nodes
+ *
+ * \code
+ * NodeContainer::Iterator i;
+ * for (i = container.Begin (); i != container.End (); ++i)
+ * {
+ * std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
+ * method (pair.first, pair.second); // use the pair
+ * }
+ * \endcode
+ *
+ * \returns an iterator which indicates an ending condition for a loop.
+ */
+ Iterator End (void) const;
+
+ /**
* \returns the number of Ptr<Ipv4> and interface pairs stored in this
* Ipv4InterfaceContainer.
+ *
+ * Pairs can be retrieved from the container in two ways. First,
+ * directly by an index into the container, and second, using an iterator.
+ * This method is used in the direct method and is typically used to
+ * define an ending condition in a for-loop that runs through the stored
+ * Nodes
+ *
+ * \code
+ * uint32_t nNodes = container.GetN ();
+ * for (uint32_t i = 0 i < nNodes; ++i)
+ * {
+ * std::pair<Ptr<Ipv4>, uint32_t> pair = container.Get (i);
+ * method (pair.first, pair.second); // use the pair
+ * }
+ * \endcode
+ *
+ * \returns the number of Ptr<Node> stored in this container.
*/
uint32_t GetN (void) const;
@@ -61,7 +124,6 @@
*/
Ipv4Address GetAddress (uint32_t i, uint32_t j = 0) const;
-
void SetMetric (uint32_t i, uint16_t metric);
/**
--- a/src/helper/node-container.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/node-container.h Fri Jan 22 00:58:01 2010 -0800
@@ -189,10 +189,10 @@
* Nodes
*
* \code
- * uint32_t nNodes = continer.GetN ();
+ * uint32_t nNodes = container.GetN ();
* for (uint32_t i = 0 i < nNodes; ++i)
* {
- * Ptr<Node> p = continer.Get (i)
+ * Ptr<Node> p = container.Get (i)
* i->method (); // some Node method
* }
* \endcode
--- a/src/helper/pcap-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/pcap-helper.cc Fri Jan 22 00:58:01 2010 -0800
@@ -77,7 +77,7 @@
}
std::string
-PcapHelper::GetFilename (std::string prefix, Ptr<NetDevice> device, bool useObjectNames)
+PcapHelper::GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames)
{
NS_LOG_FUNCTION (prefix << device << useObjectNames);
NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string");
@@ -102,7 +102,7 @@
}
else
{
- oss << node->GetId ();
+ oss << "n" << node->GetId ();
}
oss << "-";
@@ -113,7 +113,7 @@
}
else
{
- oss << device->GetIfIndex ();
+ oss << "d" << device->GetIfIndex ();
}
oss << ".pcap";
@@ -121,6 +121,44 @@
return oss.str ();
}
+std::string
+PcapHelper::GetFilenameFromInterfacePair (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool useObjectNames)
+{
+ NS_LOG_FUNCTION (prefix << ipv4 << interface << useObjectNames);
+ NS_ABORT_MSG_UNLESS (prefix.size (), "Empty prefix string");
+
+ std::ostringstream oss;
+ oss << prefix << "-";
+
+ std::string ipv4name;
+ std::string nodename;
+
+ Ptr<Node> node = ipv4->GetObject<Node> ();
+
+ if (useObjectNames)
+ {
+ ipv4name = Names::FindName (ipv4);
+ nodename = Names::FindName (node);
+ }
+
+ if (ipv4name.size ())
+ {
+ oss << ipv4name;
+ }
+ else if (nodename.size ())
+ {
+ oss << nodename;
+ }
+ else
+ {
+ oss << "n" << node->GetId ();
+ }
+
+ oss << "-i" << interface << ".pcap";
+
+ return oss.str ();
+}
+
//
// The basic default trace sink. This one just writes the packet to the pcap
// file which is good enough for most kinds of captures.
--- a/src/helper/pcap-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/pcap-helper.h Fri Jan 22 00:58:01 2010 -0800
@@ -19,10 +19,12 @@
#ifndef PCAP_HELPER_H
#define PCAP_HELPER_H
+#include "ns3/assert.h"
#include "ns3/net-device-container.h"
#include "ns3/node-container.h"
#include "ns3/simulator.h"
#include "ns3/pcap-file-object.h"
+#include "ns3/ipv4.h"
namespace ns3 {
@@ -45,6 +47,7 @@
enum {DLT_NULL = 0};
enum {DLT_EN10MB = 1};
enum {DLT_PPP = 9};
+ enum {DLT_RAW = 101};
enum {DLT_IEEE802_11 = 105};
enum {DLT_PRISM_HEADER = 119};
enum {DLT_IEEE802_11_RADIO = 127};
@@ -60,10 +63,17 @@
~PcapHelper ();
/**
+ * @brief Let the pcap helper figure out a reasonable filename to use for a
+ * pcap file associated with a device.
+ */
+ std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
+
+ /**
* @brief Let the pcap helper figure out a reasonable filename to use for the
- * pcap file.
+ * pcap file associated with a node.
*/
- std::string GetFilename (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
+ std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Ipv4> ipv4,
+ uint32_t interface, bool useObjectNames = true);
/**
* @brief Create and initialize a pcap file.
@@ -82,7 +92,8 @@
template <typename T> void
PcapHelper::HookDefaultSink (Ptr<T> object, std::string tracename, Ptr<PcapFileObject> file)
{
- object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file));
+ bool result = object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file));
+ NS_ASSERT_MSG (result == true, "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\"");
}
} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/pcap-user-helper-for-device.cc Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,90 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/abort.h"
+#include "ns3/names.h"
+#include "pcap-user-helper-for-device.h"
+
+namespace ns3 {
+
+void
+PcapUserHelperForDevice::EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous)
+{
+ EnablePcapInternal (prefix, nd, promiscuous);
+}
+
+void
+PcapUserHelperForDevice::EnablePcap (std::string prefix, std::string ndName, bool promiscuous)
+{
+ Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
+ EnablePcap (prefix, nd, promiscuous);
+}
+
+void
+PcapUserHelperForDevice::EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous)
+{
+ for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
+ {
+ Ptr<NetDevice> dev = *i;
+ EnablePcap (prefix, dev, promiscuous);
+ }
+}
+
+void
+PcapUserHelperForDevice::EnablePcap (std::string prefix, NodeContainer n, bool promiscuous)
+{
+ NetDeviceContainer devs;
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ for (uint32_t j = 0; j < node->GetNDevices (); ++j)
+ {
+ devs.Add (node->GetDevice (j));
+ }
+ }
+ EnablePcap (prefix, devs, promiscuous);
+}
+
+void
+PcapUserHelperForDevice::EnablePcapAll (std::string prefix, bool promiscuous)
+{
+ EnablePcap (prefix, NodeContainer::GetGlobal (), promiscuous);
+}
+
+void
+PcapUserHelperForDevice::EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous)
+{
+ NodeContainer n = NodeContainer::GetGlobal ();
+
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ if (node->GetId () != nodeid)
+ {
+ continue;
+ }
+
+ NS_ABORT_MSG_IF (deviceid >= node->GetNDevices (), "PcapUserHelperForDevice::EnablePcap(): Unknown deviceid = "
+ << deviceid);
+ Ptr<NetDevice> nd = node->GetDevice (deviceid);
+ EnablePcap (prefix, nd, promiscuous);
+ return;
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/pcap-user-helper-for-device.h Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,105 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PCAP_USER_HELPER_H
+#define PCAP_USER_HELPER_H
+
+#include <string>
+#include "ns3/net-device-container.h"
+#include "ns3/node-container.h"
+
+namespace ns3 {
+
+/**
+ * \brief Base class providing common user-level pcap operations for helpers
+ * representing net devices.
+ */
+class PcapUserHelperForDevice
+{
+public:
+ /**
+ * @brief Enable pcap output the indicated net device.
+ * @internal
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param nd Net device for which you want to enable tracing.
+ * @param promiscuous If true capture all possible packets available at the device.
+ */
+ virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous) = 0;
+
+ /**
+ * @brief Enable pcap output the indicated net device.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param nd Net device for which you want to enable tracing.
+ * @param promiscuous If true capture all possible packets available at the device.
+ */
+ void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false);
+
+ /**
+ * @brief Enable pcap output the indicated net device using a device previously
+ * named using the ns-3 object name service.
+ *
+ * @param filename filename prefix to use for pcap files.
+ * @param ndName The name of the net device in which you want to enable tracing.
+ * @param promiscuous If true capture all possible packets available at the device.
+ */
+ void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false);
+
+ /**
+ * @brief Enable pcap output on each device in the container which is of the
+ * appropriate type.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param d container of devices of type ns3::CsmaNetDevice
+ * @param promiscuous If true capture all possible packets available at the device.
+ */
+ void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false);
+
+ /**
+ * @brief Enable pcap output on each device (which is of the appropriate type)
+ * in the nodes provided in the container.
+ *
+ * \param prefix Filename prefix to use for pcap files.
+ * \param n container of nodes.
+ * \param promiscuous If true capture all possible packets available at the device.
+ */
+ void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false);
+
+ /**
+ * @brief Enable pcap output on each device (which is of the appropriate type)
+ * in the set of all nodes created in the simulation.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param promiscuous If true capture all possible packets available at the device.
+ */
+ void EnablePcapAll (std::string prefix, bool promiscuous = false);
+
+ /**
+ * @brief Enable pcap output on the device specified by a global node-id (of
+ * a previously created node) and associated device-id.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param promiscuous If true capture all possible packets available at the device.
+ */
+ void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false);
+};
+
+} // namespace ns3
+
+#endif // PCAP_USER_HELPER_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/pcap-user-helper-for-ipv4.cc Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,93 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/abort.h"
+#include "ns3/names.h"
+#include "pcap-user-helper-for-ipv4.h"
+
+namespace ns3 {
+
+void
+PcapUserHelperForIpv4::EnablePcap (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface)
+{
+ EnablePcapInternal (prefix, ipv4, interface);
+}
+
+void
+PcapUserHelperForIpv4::EnablePcap (std::string prefix, std::string ipv4Name, uint32_t interface)
+{
+ Ptr<Ipv4> ipv4 = Names::Find<Ipv4> (ipv4Name);
+ EnablePcap (prefix, ipv4, interface);
+}
+
+void
+PcapUserHelperForIpv4::EnablePcap (std::string prefix, Ipv4InterfaceContainer c)
+{
+ for (Ipv4InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+ {
+ std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
+ EnablePcap (prefix, pair.first, pair.second);
+ }
+}
+
+void
+PcapUserHelperForIpv4::EnablePcap (std::string prefix, NodeContainer n)
+{
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+ if (ipv4)
+ {
+ for (uint32_t j = 0; j < ipv4->GetNInterfaces (); ++j)
+ {
+ EnablePcap (prefix, ipv4, j);
+ }
+ }
+ }
+}
+
+void
+PcapUserHelperForIpv4::EnablePcapAll (std::string prefix)
+{
+ EnablePcap (prefix, NodeContainer::GetGlobal ());
+}
+
+void
+PcapUserHelperForIpv4::EnablePcap (std::string prefix, uint32_t nodeid, uint32_t interface)
+{
+ NodeContainer n = NodeContainer::GetGlobal ();
+
+ for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+ {
+ Ptr<Node> node = *i;
+ if (node->GetId () != nodeid)
+ {
+ continue;
+ }
+
+ Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+ if (ipv4)
+ {
+ EnablePcap (prefix, ipv4, interface);
+ }
+ return;
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/pcap-user-helper-for-ipv4.h Fri Jan 22 00:58:01 2010 -0800
@@ -0,0 +1,102 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PCAP_USER_HELPER_FOR_IPV4_H
+#define PCAP_USER_HELPER_FOR_IPV4_H
+
+#include <string>
+#include "ns3/ipv4-interface-container.h"
+#include "ns3/node-container.h"
+
+namespace ns3 {
+
+/**
+ * \brief Base class providing common user-level pcap operations for helpers
+ * representing IPv4 protocols .
+ */
+class PcapUserHelperForIpv4
+{
+public:
+ /**
+ * @brief Enable pcap output the indicated Ipv4 and interface pair.
+ * @internal
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param ipv4 Ptr<Ipv4> on which you want to enable tracing.
+ * @param interface Interface on ipv4 on which you want to enable tracing.
+ */
+ virtual void EnablePcapInternal (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface) = 0;
+
+ /**
+ * @brief Enable pcap output the indicated Ipv4 and interface pair.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param ipv4 Ptr<Ipv4> on which you want to enable tracing.
+ * @param interface Interface on ipv4 on which you want to enable tracing.
+ */
+ void EnablePcap (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface);
+
+ /**
+ * @brief Enable pcap output the indicated Ipv4 and interface pair using a
+ * Ptr<Ipv4> previously named using the ns-3 object name service.
+ *
+ * @param filename filename prefix to use for pcap files.
+ * @param ipv4Name Name of the Ptr<Ipv4> on which you want to enable tracing.
+ * @param interface Interface on ipv4 on which you want to enable tracing.
+ */
+ void EnablePcap (std::string prefix, std::string ipv4Name, uint32_t interface);
+
+ /**
+ * @brief Enable pcap output on each Ipv4 and interface pair in the container.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ * @param c Ipv4InterfaceContainer of Ipv4 and interface pairs
+ */
+ void EnablePcap (std::string prefix, Ipv4InterfaceContainer c);
+
+ /**
+ * @brief Enable pcap output on all Ipv4 and interface pairs existing in the
+ * nodes provided in the container.
+ *
+ * \param prefix Filename prefix to use for pcap files.
+ * \param n container of nodes.
+ */
+ void EnablePcap (std::string prefix, NodeContainer n);
+
+ /**
+ * @brief Enable pcap output on all Ipv4 and interface pairs existing in the
+ * set of all nodes created in the simulation.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ */
+ void EnablePcapAll (std::string prefix);
+
+ /**
+ * @brief Enable pcap output on the Ipv4 and interface pair specified by a
+ * global node-id (of a previously created node) and interface. Since there
+ * can be only one Ipv4 aggregated to a node, the node-id unambiguously
+ * determines the Ipv4.
+ *
+ * @param prefix Filename prefix to use for pcap files.
+ */
+ void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t interface);
+};
+
+} // namespace ns3
+
+#endif // PCAP_USER_HELPER_FOR_IPV4_H
--- a/src/helper/pcap-user-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ns3/abort.h"
-#include "ns3/names.h"
-#include "pcap-user-helper.h"
-
-namespace ns3 {
-
-void
-PcapUserHelper::EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous)
-{
- EnablePcapInternal (prefix, nd, promiscuous);
-}
-
-void
-PcapUserHelper::EnablePcap (std::string prefix, std::string ndName, bool promiscuous)
-{
- Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
- EnablePcap (prefix, nd, promiscuous);
-}
-
-void
-PcapUserHelper::EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous)
-{
- for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
- {
- Ptr<NetDevice> dev = *i;
- EnablePcap (prefix, dev, promiscuous);
- }
-}
-
-void
-PcapUserHelper::EnablePcap (std::string prefix, NodeContainer n, bool promiscuous)
-{
- NetDeviceContainer devs;
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
- }
- EnablePcap (prefix, devs, promiscuous);
-}
-
-void
-PcapUserHelper::EnablePcapAll (std::string prefix, bool promiscuous)
-{
- EnablePcap (prefix, NodeContainer::GetGlobal (), promiscuous);
-}
-
-void
-PcapUserHelper::EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous)
-{
- NodeContainer n = NodeContainer::GetGlobal ();
-
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- if (node->GetId () != nodeid)
- {
- continue;
- }
-
- NS_ABORT_MSG_IF (deviceid >= node->GetNDevices (), "PcapUserHelper::EnablePcap(): Unknown deviceid = " << deviceid);
- Ptr<NetDevice> nd = node->GetDevice (deviceid);
-
- EnablePcap (prefix, nd, promiscuous);
- return;
- }
-}
-
-} // namespace ns3
--- a/src/helper/pcap-user-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PCAP_USER_HELPER_H
-#define PCAP_USER_HELPER_H
-
-#include <string>
-#include "ns3/net-device-container.h"
-#include "ns3/node-container.h"
-
-namespace ns3 {
-
-/**
- * \brief Base class providing common pcap operations.
- */
-class PcapUserHelper
-{
-public:
- /**
- * @brief Enable pcap output the indicated net device.
- * @internal
- *
- * @param prefix Filename prefix to use for pcap files.
- * @param nd Net device for which you want to enable tracing.
- * @param promiscuous If true capture all possible packets available at the device.
- */
- virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous) = 0;
-
- /**
- * @brief Enable pcap output the indicated net device.
- *
- * @param prefix Filename prefix to use for pcap files.
- * @param nd Net device for which you want to enable tracing.
- * @param promiscuous If true capture all possible packets available at the device.
- */
- void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false);
-
- /**
- * @brief Enable pcap output the indicated net device using a device previously
- * named using the ns-3 object name service.
- *
- * @param filename filename prefix to use for pcap files.
- * @param ndName The name of the net device in which you want to enable tracing.
- * @param promiscuous If true capture all possible packets available at the device.
- */
- void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false);
-
- /**
- * @brief Enable pcap output on each device in the container which is of the
- * appropriate type.
- *
- * @param prefix Filename prefix to use for pcap files.
- * @param d container of devices of type ns3::CsmaNetDevice
- * @param promiscuous If true capture all possible packets available at the device.
- */
- void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false);
-
- /**
- * @brief Enable pcap output on each device (which is of the appropriate type)
- * in the nodes provided in the container.
- *
- * \param prefix Filename prefix to use for pcap files.
- * \param n container of nodes.
- * \param promiscuous If true capture all possible packets available at the device.
- */
- void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false);
-
- /**
- * @brief Enable pcap output on each device (which is of the appropriate type)
- * in the set of all nodes created in the simulation.
- *
- * @param prefix Filename prefix to use for pcap files.
- * @param promiscuous If true capture all possible packets available at the device.
- */
- void EnablePcapAll (std::string prefix, bool promiscuous = false);
-
- /**
- * @brief Enable pcap output on the device specified by a global node-id (of
- * a previously created node) and associated device-id.
- *
- * @param prefix Filename prefix to use for pcap files.
- * @param promiscuous If true capture all possible packets available at the device.
- */
- void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false);
-};
-
-} // namespace ns3
-
-#endif // PCAP_USER_HELPER_H
--- a/src/helper/point-to-point-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/point-to-point-helper.cc Fri Jan 22 00:58:01 2010 -0800
@@ -27,10 +27,9 @@
#include "ns3/config.h"
#include "ns3/packet.h"
#include "ns3/names.h"
-#include "ns3/pcap-writer.h"
-#include "ns3/ascii-writer.h"
#include "pcap-helper.h"
+#include "ascii-trace-helper.h"
#include "point-to-point-helper.h"
NS_LOG_COMPONENT_DEFINE ("PointToPointHelper");
@@ -86,59 +85,97 @@
}
PcapHelper pcapHelper;
- std::string filename = pcapHelper.GetFilename (prefix, device);
+ std::string filename = pcapHelper.GetFilenameFromDevice (prefix, device);
Ptr<PcapFileObject> file = pcapHelper.CreateFile (filename, "w", PcapHelper::DLT_PPP);
pcapHelper.HookDefaultSink<PointToPointNetDevice> (device, "PromiscSniffer", file);
}
void
-PointToPointHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
+PointToPointHelper::EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd)
{
- Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
+ //
+ // All of the ascii enable functions vector through here including the ones
+ // that are wandering through all of devices on perhaps all of the nodes in
+ // the system. We can only deal with devices of type PointToPointNetDevice.
+ //
+ Ptr<PointToPointNetDevice> device = nd->GetObject<PointToPointNetDevice> ();
+ if (device == 0)
+ {
+ NS_LOG_INFO ("PointToPointHelper::EnableAsciiInternal(): Device " << device <<
+ " not of type ns3::PointToPointNetDevice");
+ return;
+ }
+
+ //
+ // Our default trace sinks are going to use packet printing, so we have to
+ // make sure that is turned on.
+ //
Packet::EnablePrinting ();
+
+ //
+ // If we are not provided an OutputStreamObject, we are expected to create
+ // one using the usual trace filename conventions and do a Hook*WithoutContext
+ // since there will be one file per context and therefore the context would
+ // be redundant.
+ //
+ if (stream == 0)
+ {
+ //
+ // Set up an output stream object to deal with private ofstream copy
+ // constructor and lifetime issues. Let the helper decide the actual
+ // name of the file given the prefix.
+ //
+ AsciiTraceHelper asciiTraceHelper;
+ std::string filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
+ Ptr<OutputStreamObject> theStream = asciiTraceHelper.CreateFileStream (filename, "w");
+
+ //
+ // The MacRx trace source provides our "r" event.
+ //
+ asciiTraceHelper.HookDefaultReceiveSinkWithoutContext<PointToPointNetDevice> (device, "MacRx", theStream);
+
+ //
+ // The "+", '-', and 'd' events are driven by trace sources actually in the
+ // transmit queue.
+ //
+ Ptr<Queue> queue = device->GetQueue ();
+ asciiTraceHelper.HookDefaultEnqueueSinkWithoutContext<Queue> (queue, "Enqueue", theStream);
+ asciiTraceHelper.HookDefaultDropSinkWithoutContext<Queue> (queue, "Drop", theStream);
+ asciiTraceHelper.HookDefaultDequeueSinkWithoutContext<Queue> (queue, "Dequeue", theStream);
+
+ return;
+ }
+
+ //
+ // If we are provided an OutputStreamObject, we are expected to use it, and
+ // to providd a context. We are free to come up with our own context if we
+ // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
+ // compatibility and simplicity, we just use Config::Connect and let it deal
+ // with the context.
+ //
+ // Note that we are going to use the default trace sinks provided by the
+ // ascii trace helper. There is actually no AsciiTraceHelper in sight here,
+ // but the default trace sinks are actually publicly available static
+ // functions that are always there waiting for just such a case.
+ //
+ uint32_t nodeid = nd->GetNode ()->GetId ();
+ uint32_t deviceid = nd->GetIfIndex ();
std::ostringstream oss;
- oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/MacRx";
- Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, writer));
+
+ oss << "/NodeList/" << nd->GetNode ()->GetId () << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/MacRx";
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultReceiveSinkWithContext, stream));
+
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
- Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiEnqueueEvent, writer));
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultEnqueueSinkWithContext, stream));
+
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Dequeue";
- Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDequeueEvent, writer));
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDequeueSinkWithContext, stream));
+
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Drop";
- Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDropEvent, writer));
-}
-
-void
-PointToPointHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
-{
- for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
- {
- Ptr<NetDevice> dev = *i;
- EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
- }
-}
-
-void
-PointToPointHelper::EnableAscii (std::ostream &os, NodeContainer n)
-{
- NetDeviceContainer devs;
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
- }
- EnableAscii (os, devs);
-}
-
-void
-PointToPointHelper::EnableAsciiAll (std::ostream &os)
-{
- EnableAscii (os, NodeContainer::GetGlobal ());
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
}
NetDeviceContainer
@@ -194,29 +231,4 @@
return Install (a, b);
}
-void
-PointToPointHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path,
- Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::ENQUEUE, path, packet);
-}
-
-void
-PointToPointHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::DEQUEUE, path, packet);
-}
-
-void
-PointToPointHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::DROP, path, packet);
-}
-
-void
-PointToPointHelper::AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
-{
- writer->WritePacket (AsciiWriter::RX, path, packet);
-}
-
} // namespace ns3
--- a/src/helper/point-to-point-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/point-to-point-helper.h Fri Jan 22 00:58:01 2010 -0800
@@ -20,25 +20,26 @@
#ifndef POINT_TO_POINT_HELPER_H
#define POINT_TO_POINT_HELPER_H
+#include <string>
+
#include "ns3/object-factory.h"
#include "ns3/net-device-container.h"
#include "ns3/node-container.h"
#include "ns3/deprecated.h"
-#include "pcap-user-helper.h"
-#include <string>
+
+#include "pcap-user-helper-for-device.h"
+#include "ascii-trace-user-helper-for-device.h"
namespace ns3 {
class Queue;
class NetDevice;
class Node;
-class PcapWriter;
-class AsciiWriter;
/**
* \brief Build a set of PointToPointNetDevice objects
*/
-class PointToPointHelper : public PcapUserHelper
+class PointToPointHelper : public PcapUserHelperForDevice, public AsciiTraceUserHelperForDevice
{
public:
/**
@@ -96,48 +97,6 @@
void SetChannelAttribute (std::string name, const AttributeValue &value);
/**
- * \param os output stream
- * \param nodeid the id of the node to generate ascii output for.
- * \param deviceid the id of the device to generate ascii output for.
- *
- * Enable ascii output on the specified deviceid within the
- * specified nodeid if it is of type ns3::PointToPointNetDevice and dump
- * that to the specified stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid);
-
- /**
- * \param os output stream
- * \param d device container
- *
- * Enable ascii output on each device which is of the
- * ns3::PointToPointNetDevice type and which is located in the input
- * device container and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NetDeviceContainer d);
-
- /**
- * \param os output stream
- * \param n node container
- *
- * Enable ascii output on each device which is of the
- * ns3::PointToPointNetDevice type and which is located in one
- * of the input node and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NodeContainer n);
-
- /**
- * \param os output stream
- *
- * Enable ascii output on each device which is of the
- * ns3::PointToPointNetDevice type and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAsciiAll (std::ostream &os);
-
- /**
* \param c a set of nodes
*
* This method creates a ns3::PointToPointChannel with the
@@ -194,11 +153,18 @@
*/
virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false);
- void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
- static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
- static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
- static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
- static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
+ /**
+ * \brief Enable ascii trace output on the indicated net device.
+ * \internal
+ *
+ * NetDevice-specific implementation mechanism for hooking the trace and
+ * writing to the trace file.
+ *
+ * \param stream The output stream object to use when logging ascii traces.
+ * \param prefix Filename prefix to use for ascii trace files.
+ * \param nd Net device for which you want to enable tracing.
+ */
+ virtual void EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd);
ObjectFactory m_queueFactory;
ObjectFactory m_channelFactory;
--- a/src/helper/wscript Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/wscript Fri Jan 22 00:58:01 2010 -0800
@@ -49,8 +49,10 @@
'csma-star-helper.cc',
'udp-client-server-helper.cc',
'pcap-helper.cc',
- 'pcap-user-helper.cc',
- 'ascii-trace-user-helper.cc',
+ 'pcap-user-helper-for-device.cc',
+ 'pcap-user-helper-for-ipv4.cc',
+ 'ascii-trace-user-helper-for-device.cc',
+ 'ascii-trace-user-helper-for-ipv4.cc',
'ascii-trace-helper.cc',
]
@@ -104,8 +106,10 @@
'csma-star-helper.h',
'udp-client-server-helper.h',
'pcap-helper.h',
- 'pcap-user-helper.h',
- 'ascii-trace-user-helper.h',
+ 'pcap-user-helper-for-device.h',
+ 'pcap-user-helper-for-ipv4.h',
+ 'ascii-trace-user-helper-for-device.h',
+ 'ascii-trace-user-helper-for-ipv4.h',
'ascii-trace-helper.h',
]
--- a/src/helper/yans-wifi-helper.cc Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/yans-wifi-helper.cc Fri Jan 22 00:58:01 2010 -0800
@@ -17,8 +17,9 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
+
#include "pcap-helper.h"
-#include "pcap-user-helper.h"
+#include "ascii-trace-helper.h"
#include "yans-wifi-helper.h"
#include "ns3/error-rate-model.h"
#include "ns3/propagation-loss-model.h"
@@ -40,21 +41,55 @@
namespace ns3 {
-static void AsciiPhyTxEvent (Ptr<AsciiWriter> writer, std::string path,
- Ptr<const Packet> packet,
- WifiMode mode, WifiPreamble preamble,
- uint8_t txLevel)
+static void
+AsciiPhyTransmitSinkWithContext (
+ Ptr<OutputStreamObject> stream,
+ std::string context,
+ Ptr<const Packet> p,
+ WifiMode mode,
+ WifiPreamble preamble,
+ uint8_t txLevel)
{
- writer->WritePacket (AsciiWriter::TX, path, packet);
+ NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
+ *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
+}
+
+static void
+AsciiPhyTransmitSinkWithoutContext (
+ Ptr<OutputStreamObject> stream,
+ Ptr<const Packet> p,
+ WifiMode mode,
+ WifiPreamble preamble,
+ uint8_t txLevel)
+{
+ NS_LOG_FUNCTION (stream << p << mode << preamble << txLevel);
+ *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
}
-static void AsciiPhyRxOkEvent (Ptr<AsciiWriter> writer, std::string path,
- Ptr<const Packet> packet, double snr, WifiMode mode,
- enum WifiPreamble preamble)
+static void
+AsciiPhyReceiveSinkWithContext (
+ Ptr<OutputStreamObject> stream,
+ std::string context,
+ Ptr<const Packet> p,
+ double snr,
+ WifiMode mode,
+ enum WifiPreamble preamble)
{
- writer->WritePacket (AsciiWriter::RX, path, packet);
+ NS_LOG_FUNCTION (stream << context << p << snr << mode << preamble);
+ *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
}
+static void
+AsciiPhyReceiveSinkWithoutContext (
+ Ptr<OutputStreamObject> stream,
+ Ptr<const Packet> p,
+ double snr,
+ WifiMode mode,
+ enum WifiPreamble preamble)
+{
+ NS_LOG_FUNCTION (stream << p << snr << mode << preamble);
+ *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
+}
YansWifiChannelHelper::YansWifiChannelHelper ()
{}
@@ -372,7 +407,7 @@
NS_ABORT_MSG_IF (phy == 0, "YansWifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
PcapHelper pcapHelper;
- std::string filename = pcapHelper.GetFilename (prefix, device);
+ std::string filename = pcapHelper.GetFilenameFromDevice (prefix, device);
Ptr<PcapFileObject> file = pcapHelper.CreateFile (filename, "w", m_pcapDlt);
@@ -381,45 +416,78 @@
}
void
-YansWifiPhyHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
+YansWifiPhyHelper::EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd)
{
- Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
+ //
+ // All of the ascii enable functions vector through here including the ones
+ // that are wandering through all of devices on perhaps all of the nodes in
+ // the system. We can only deal with devices of type CsmaNetDevice.
+ //
+ Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
+ if (device == 0)
+ {
+ NS_LOG_INFO ("YansWifiHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::WifiNetDevice");
+ return;
+ }
+
+ //
+ // Our trace sinks are going to use packet printing, so we have to make sure
+ // that is turned on.
+ //
Packet::EnablePrinting ();
+
+ uint32_t nodeid = nd->GetNode ()->GetId ();
+ uint32_t deviceid = nd->GetIfIndex ();
std::ostringstream oss;
+
+ //
+ // If we are not provided an OutputStreamObject, we are expected to create
+ // one using the usual trace filename conventions and write our traces
+ // without a context since there will be one file per context and therefore
+ // the context would be redundant.
+ //
+ if (stream == 0)
+ {
+ //
+ // Set up an output stream object to deal with private ofstream copy
+ // constructor and lifetime issues. Let the helper decide the actual
+ // name of the file given the prefix.
+ //
+ AsciiTraceHelper asciiTraceHelper;
+ std::string filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
+ Ptr<OutputStreamObject> theStream = asciiTraceHelper.CreateFileStream (filename, "w");
+
+ //
+ // We could go poking through the phy and the state looking for the
+ // correct trace source, but we can let Config deal with that with
+ // some search cost. Since this is presumably happening at topology
+ // creation time, it doesn't seem much of a price to pay.
+ //
+ oss.str ("");
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
+ Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&AsciiPhyReceiveSinkWithoutContext, stream));
+
+ oss.str ("");
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
+ Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&AsciiPhyTransmitSinkWithoutContext, stream));
+
+ return;
+ }
+
+ //
+ // If we are provided an OutputStreamObject, we are expected to use it, and
+ // to provide a context. We are free to come up with our own context if we
+ // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
+ // compatibility and simplicity, we just use Config::Connect and let it deal
+ // with coming up with a context.
+ //
+ oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
- Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, writer));
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyReceiveSinkWithContext, stream));
+
oss.str ("");
oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
- Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, writer));
-}
-void
-YansWifiPhyHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
-{
- for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
- {
- Ptr<NetDevice> dev = *i;
- EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
- }
-}
-void
-YansWifiPhyHelper::EnableAscii (std::ostream &os, NodeContainer n)
-{
- NetDeviceContainer devs;
- for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
- {
- Ptr<Node> node = *i;
- for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
- }
- EnableAscii (os, devs);
-}
-
-void
-YansWifiPhyHelper::EnableAsciiAll (std::ostream &os)
-{
- EnableAscii (os, NodeContainer::GetGlobal ());
+ Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTransmitSinkWithContext, stream));
}
} // namespace ns3
--- a/src/helper/yans-wifi-helper.h Tue Jan 19 10:32:13 2010 -0800
+++ b/src/helper/yans-wifi-helper.h Fri Jan 22 00:58:01 2010 -0800
@@ -21,7 +21,8 @@
#define YANS_WIFI_HELPER_H
#include "wifi-helper.h"
-#include "pcap-user-helper.h"
+#include "pcap-user-helper-for-device.h"
+#include "ascii-trace-user-helper-for-device.h"
#include "ns3/yans-wifi-channel.h"
#include "ns3/deprecated.h"
@@ -135,7 +136,7 @@
* The Pcap and ascii traces generated by the EnableAscii and EnablePcap methods defined
* in this class correspond to PHY-level traces.
*/
- class YansWifiPhyHelper : public WifiPhyHelper, public PcapUserHelper
+class YansWifiPhyHelper : public WifiPhyHelper, public PcapUserHelperForDevice, public AsciiTraceUserHelperForDevice
{
public:
/**
@@ -240,48 +241,6 @@
*/
void SetPcapDataLinkType (uint32_t dlt);
- /**
- * \param os output stream
- * \param nodeid the id of the node to generate ascii output for.
- * \param deviceid the id of the device to generate ascii output for.
- *
- * Enable ascii output on the specified deviceid within the
- * specified nodeid if it is of type ns3::WifiNetDevice and dump
- * that to the specified stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid);
-
- /**
- * \param os output stream
- * \param d device container
- *
- * Enable ascii output on each device which is of the
- * ns3::WifiNetDevice type and which is located in the input
- * device container and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NetDeviceContainer d);
-
- /**
- * \param os output stream
- * \param n node container
- *
- * Enable ascii output on each device which is of the
- * ns3::WifiNetDevice type and which is located in one
- * of the input node and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAscii (std::ostream &os, NodeContainer n);
-
- /**
- * \param os output stream
- *
- * Enable ascii output on each device which is of the
- * ns3::WifiNetDevice type and dump that to the specified
- * stdc++ output stream.
- */
- static void EnableAsciiAll (std::ostream &os);
-
private:
/**
* \param node the node on which we wish to create a wifi PHY
@@ -304,6 +263,19 @@
*/
virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous);
+ /**
+ * \brief Enable ascii trace output on the indicated net device.
+ * \internal
+ *
+ * NetDevice-specific implementation mechanism for hooking the trace and
+ * writing to the trace file.
+ *
+ * \param stream The output stream object to use when logging ascii traces.
+ * \param prefix Filename prefix to use for ascii trace files.
+ * \param nd Net device for which you want to enable tracing.
+ */
+ virtual void EnableAsciiInternal (Ptr<OutputStreamObject> stream, std::string prefix, Ptr<NetDevice> nd);
+
ObjectFactory m_phy;
ObjectFactory m_errorRateModel;
Ptr<YansWifiChannel> m_channel;