23 #include "ns3/abort.h"
24 #include "ns3/assert.h"
28 #include "ns3/names.h"
29 #include "ns3/net-device.h"
30 #include "ns3/pcap-file-wrapper.h"
51 std::ios::openmode filemode,
52 uint32_t dataLinkType,
56 NS_LOG_FUNCTION (filename << filemode << dataLinkType << snapLen << tzCorrection);
59 file->Open (filename, filemode);
60 NS_ABORT_MSG_IF (file->Fail (),
"Unable to Open " << filename <<
" for mode " << filemode);
62 file->Init (dataLinkType, snapLen, tzCorrection);
85 std::ostringstream oss;
89 std::string devicename;
105 oss << node->
GetId ();
110 if (devicename.size ())
116 oss << device->GetIfIndex ();
130 std::ostringstream oss;
131 oss << prefix <<
"-";
134 std::string nodename;
148 else if (nodename.size ())
154 oss <<
"n" << node->
GetId ();
157 oss <<
"-i" <<
interface << ".pcap";
201 return StreamWrapper;
210 std::ostringstream oss;
211 oss << prefix <<
"-";
213 std::string nodename;
214 std::string devicename;
224 if (nodename.size ())
230 oss << node->
GetId ();
235 if (devicename.size ())
241 oss << device->GetIfIndex ();
259 std::ostringstream oss;
260 oss << prefix <<
"-";
263 std::string nodename;
277 else if (nodename.size ())
283 oss <<
"n" << node->
GetId ();
286 oss <<
"-i" <<
interface << ".tr";
403 EnablePcap (prefix, nd, promiscuous, explicitFilename);
423 for (uint32_t j = 0; j < node->
GetNDevices (); ++j)
445 if (node->
GetId () != nodeid)
502 bool explicitFilename)
567 for (uint32_t j = 0; j < node->
GetNDevices (); ++j)
610 bool explicitFilename)
624 bool explicitFilename)
631 if (node->
GetId () != nodeid)
637 "AsciiTraceHelperForDevice::EnableAscii(): Unknown deviceid = " << deviceid);
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
static void DefaultEnqueueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, uint32_t dataLinkType, uint32_t snapLen=65535, int32_t tzCorrection=0)
Create and initialize a pcap file.
void EnableAsciiImpl(Ptr< OutputStreamWrapper > stream, std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename)
std::vector< Ptr< Node > >::const_iterator Iterator
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits. ...
std::string GetFilenameFromDevice(std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true)
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated...
static void DefaultReceiveSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
double GetSeconds(void) const
std::string GetFilenameFromDevice(std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true)
Let the pcap helper figure out a reasonable filename to use for a pcap file associated with a device...
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > GetDevice(uint32_t index) const
static void DefaultEnqueueSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
std::string GetFilenameFromInterfacePair(std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true)
Let the pcap helper figure out a reasonable filename to use for the pcap file associated with a node...
static void DefaultDequeueSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
static void DefaultReceiveSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
uint32_t GetNDevices(void) const
static void DefaultSink(Ptr< PcapFileWrapper > file, Ptr< const Packet > p)
static void DefaultDequeueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)=0
Enable pcap output the indicated net device.
AsciiTraceHelper()
Create an ascii trace helper.
static void DefaultDropSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
static Time Now(void)
Return the "current simulation time".
PcapHelper()
Create a pcap helper.
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
void EnableAscii(std::string prefix, Ptr< NetDevice > nd, bool explicitFilename=false)
Enable ascii trace output on the indicated net device.
uint32_t GetId(void) const
std::string GetFilenameFromInterfacePair(std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true)
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated...
std::vector< Ptr< NetDevice > >::const_iterator Iterator
virtual void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)=0
Enable ascii trace output on the indicated net device.
NS_LOG_COMPONENT_DEFINE("TraceHelper")
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and...
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
~AsciiTraceHelper()
Destroy an ascii trace helper.
Ptr< T > GetObject(void) const
~PcapHelper()
Destroy a pcap helper.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.