A Discrete-Event Network Simulator
API
trace-helper.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #ifndef TRACE_HELPER_H
20 #define TRACE_HELPER_H
21 
22 #include "ns3/assert.h"
23 #include "ns3/net-device-container.h"
24 #include "ns3/node-container.h"
25 #include "ns3/simulator.h"
26 #include "ns3/pcap-file-wrapper.h"
27 #include "ns3/output-stream-wrapper.h"
28 
29 namespace ns3 {
30 
39 {
40 public:
50  enum DataLinkType {
51  DLT_NULL = 0,
53  DLT_PPP = 9,
54  DLT_RAW = 101,
60  DLT_NETLINK = 253,
61  DLT_LORATAP = 270
62  };
63 
67  PcapHelper ();
68 
72  ~PcapHelper ();
73 
83  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
84 
95  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
96  uint32_t interface, bool useObjectNames = true);
97 
108  Ptr<PcapFileWrapper> CreateFile (std::string filename,
109  std::ios::openmode filemode,
110  DataLinkType dataLinkType,
111  uint32_t snapLen = std::numeric_limits<uint32_t>::max (),
112  int32_t tzCorrection = 0);
120  template <typename T> void HookDefaultSink (Ptr<T> object, std::string traceName, Ptr<PcapFileWrapper> file);
121 
122 private:
133 
144  static void SinkWithHeader (Ptr<PcapFileWrapper> file, const Header& header, Ptr<const Packet> p);
145 };
146 
147 template <typename T> void
149 {
150  bool result =
151  object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file));
152  NS_ASSERT_MSG (result == true, "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\"");
153 }
154 
163 {
164 public:
168  AsciiTraceHelper ();
169 
174 
184  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
185 
196  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
197  uint32_t interface, bool useObjectNames = true);
198 
223  Ptr<OutputStreamWrapper> CreateFileStream (std::string filename,
224  std::ios::openmode filemode = std::ios::out);
225 
234  template <typename T>
235  void HookDefaultEnqueueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
236 
246  template <typename T>
248  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
249 
258  template <typename T>
259  void HookDefaultDropSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
260 
270  template <typename T>
272  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
273 
282  template <typename T>
283  void HookDefaultDequeueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
284 
294  template <typename T>
296  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
297 
306  template <typename T>
307  void HookDefaultReceiveSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
308 
318  template <typename T>
320  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
321 
337 
354 
371 
388  static void DefaultDropSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
389 
407 
426 
442 
459 };
460 
461 template <typename T> void
463 {
464  bool result =
465  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultEnqueueSinkWithoutContext, file));
466  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \""
467  << tracename << "\"");
468 }
469 
470 template <typename T> void
472  Ptr<T> object,
473  std::string context,
474  std::string tracename,
476 {
477  bool result =
478  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultEnqueueSinkWithContext, stream));
479  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \""
480  << tracename << "\"");
481 }
482 
483 template <typename T> void
485 {
486  bool result =
487  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDropSinkWithoutContext, file));
488  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \""
489  << tracename << "\"");
490 }
491 
492 template <typename T> void
494  Ptr<T> object,
495  std::string context,
496  std::string tracename,
498 {
499  bool result =
500  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDropSinkWithContext, stream));
501  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \""
502  << tracename << "\"");
503 }
504 
505 template <typename T> void
507 {
508  bool result =
509  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDequeueSinkWithoutContext, file));
510  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \""
511  << tracename << "\"");
512 }
513 
514 template <typename T> void
516  Ptr<T> object,
517  std::string context,
518  std::string tracename,
520 {
521  bool result =
522  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDequeueSinkWithContext, stream));
523  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \""
524  << tracename << "\"");
525 }
526 
527 template <typename T> void
529 {
530  bool result =
531  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultReceiveSinkWithoutContext, file));
532  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \""
533  << tracename << "\"");
534 }
535 
536 template <typename T> void
538  Ptr<T> object,
539  std::string context,
540  std::string tracename,
542 {
543  bool result =
544  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultReceiveSinkWithContext, stream));
545  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \""
546  << tracename << "\"");
547 }
548 
554 {
555 public:
560 
564  virtual ~PcapHelperForDevice () {}
565 
574  virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename) = 0;
575 
584  void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false);
585 
595  void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false, bool explicitFilename = false);
596 
605  void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false);
606 
615  void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false);
616 
626  void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false);
627 
635  void EnablePcapAll (std::string prefix, bool promiscuous = false);
636 };
637 
643 {
644 public:
649 
654 
679  std::string prefix,
680  Ptr<NetDevice> nd,
681  bool explicitFilename) = 0;
682 
690  void EnableAscii (std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
691 
700 
709  void EnableAscii (std::string prefix, std::string ndName, bool explicitFilename = false);
710 
719  void EnableAscii (Ptr<OutputStreamWrapper> stream, std::string ndName);
720 
728  void EnableAscii (std::string prefix, NetDeviceContainer d);
729 
739 
747  void EnableAscii (std::string prefix, NodeContainer n);
748 
758 
765  void EnableAsciiAll (std::string prefix);
766 
775 
787  void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
788 
800  void EnableAscii (Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
801 
802 private:
818  std::string prefix,
819  uint32_t nodeid,
820  uint32_t deviceid,
821  bool explicitFilename);
822 
832  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n);
833 
843  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NetDeviceContainer d);
844 
855  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, std::string ndName, bool explicitFilename);
856 
866  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, Ptr<NetDevice> nd, bool explicitFilename);
867 };
868 
869 } // namespace ns3
870 
871 #endif /* TRACE_HELPER_H */
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
ns3::PcapHelperForDevice::EnablePcapInternal
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)=0
Enable pcap output the indicated net device.
ns3::PcapHelper::CreateFile
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, DataLinkType dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0)
Create and initialize a pcap file.
Definition: trace-helper.cc:49
ns3::AsciiTraceHelper::HookDefaultDequeueSinkWithContext
void HookDefaultDequeueSinkWithContext(Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default dequeue operation trace sink that does accept and log a trace cont...
Definition: trace-helper.h:515
ns3::AsciiTraceHelperForDevice::EnableAsciiAll
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...
Definition: trace-helper.cc:586
ns3::PcapHelper::DLT_EN10MB
@ DLT_EN10MB
Definition: trace-helper.h:52
ns3::PcapHelperForDevice::EnablePcap
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Definition: trace-helper.cc:401
ns3::PcapHelper::DLT_IEEE802_15_4
@ DLT_IEEE802_15_4
Definition: trace-helper.h:59
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::PcapHelper::GetFilenameFromDevice
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.
Definition: trace-helper.cc:80
ns3::AsciiTraceHelperForDevice::EnableAsciiImpl
void EnableAsciiImpl(Ptr< OutputStreamWrapper > stream, std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename)
Enable ascii trace output on the device specified by a global node-id (of a previously created node) ...
Definition: trace-helper.cc:626
ns3::PcapHelper::DLT_NETLINK
@ DLT_NETLINK
Definition: trace-helper.h:60
ns3::AsciiTraceHelper::DefaultEnqueueSinkWithoutContext
static void DefaultEnqueueSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Enqueue default trace sink.
Definition: trace-helper.cc:310
ns3::PcapHelper::PcapHelper
PcapHelper()
Create a pcap helper.
Definition: trace-helper.cc:38
ns3::AsciiTraceHelper::AsciiTraceHelper
AsciiTraceHelper()
Create an ascii trace helper.
Definition: trace-helper.cc:180
ns3::PcapHelperForDevice::EnablePcapAll
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 ...
Definition: trace-helper.cc:439
ns3::AsciiTraceHelperForDevice::AsciiTraceHelperForDevice
AsciiTraceHelperForDevice()
Construct an AsciiTraceHelperForDevice.
Definition: trace-helper.h:648
ns3::AsciiTraceHelper::~AsciiTraceHelper
~AsciiTraceHelper()
Destroy an ascii trace helper.
Definition: trace-helper.cc:185
ns3::PcapHelper::HookDefaultSink
void HookDefaultSink(Ptr< T > object, std::string traceName, Ptr< PcapFileWrapper > file)
Hook a trace source to the default trace sink.
Definition: trace-helper.h:148
ns3::AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext
void HookDefaultEnqueueSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default enqueue operation trace sink that does not accept nor log a trace ...
Definition: trace-helper.h:462
ns3::AsciiTraceHelper::DefaultReceiveSinkWithoutContext
static void DefaultReceiveSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Receive default trace sink.
Definition: trace-helper.cc:387
ns3::PcapHelper::DLT_RAW
@ DLT_RAW
Definition: trace-helper.h:54
ns3::AsciiTraceHelperForDevice::~AsciiTraceHelperForDevice
virtual ~AsciiTraceHelperForDevice()
Destroy an AsciiTraceHelperForDevice.
Definition: trace-helper.h:653
ns3::PcapHelper::DLT_PPP
@ DLT_PPP
Definition: trace-helper.h:53
ns3::PcapHelper::DLT_IEEE802_11
@ DLT_IEEE802_11
Definition: trace-helper.h:55
ns3::Ptr< NetDevice >
ns3::AsciiTraceHelper::HookDefaultEnqueueSinkWithContext
void HookDefaultEnqueueSinkWithContext(Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default enqueue operation trace sink that does accept and log a trace cont...
Definition: trace-helper.h:471
ns3::AsciiTraceHelper::HookDefaultDropSinkWithContext
void HookDefaultDropSinkWithContext(Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default drop operation trace sink that does accept and log a trace context...
Definition: trace-helper.h:493
ns3::PcapHelper::DLT_PRISM_HEADER
@ DLT_PRISM_HEADER
Definition: trace-helper.h:57
max
#define max(a, b)
Definition: 80211b.c:43
ns3::AsciiTraceHelper::CreateFileStream
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.
Definition: trace-helper.cc:191
ns3::AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext
void HookDefaultReceiveSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default receive operation trace sink that does not accept nor log a trace ...
Definition: trace-helper.h:528
ns3::PcapHelper::DefaultSink
static void DefaultSink(Ptr< PcapFileWrapper > file, Ptr< const Packet > p)
The basic default trace sink.
Definition: trace-helper.cc:167
ns3::PcapHelperForDevice::PcapHelperForDevice
PcapHelperForDevice()
Construct a PcapHelperForDevice.
Definition: trace-helper.h:559
ns3::Header
Protocol header serialization and deserialization.
Definition: header.h:43
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
ns3::PcapHelper
Manage pcap files for device models.
Definition: trace-helper.h:39
ns3::AsciiTraceHelper::HookDefaultReceiveSinkWithContext
void HookDefaultReceiveSinkWithContext(Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default receive operation trace sink that does accept and log a trace cont...
Definition: trace-helper.h:537
ns3::PcapHelper::DLT_IEEE802_11_RADIO
@ DLT_IEEE802_11_RADIO
Definition: trace-helper.h:58
ns3::AsciiTraceHelper::DefaultReceiveSinkWithContext
static void DefaultReceiveSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Receive default trace sink.
Definition: trace-helper.cc:394
ns3::AsciiTraceHelper
Manage ASCII trace files for device models.
Definition: trace-helper.h:163
ns3::AsciiTraceHelperForDevice::EnableAsciiImpl
void EnableAsciiImpl(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)
Enable ascii trace output the indicated net device (implementation).
ns3::AsciiTraceHelper::DefaultDropSinkWithoutContext
static void DefaultDropSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Drop default trace sink.
Definition: trace-helper.cc:336
ns3::PcapHelper::DLT_LORATAP
@ DLT_LORATAP
Definition: trace-helper.h:61
ns3::PcapHelper::DLT_LINUX_SLL
@ DLT_LINUX_SLL
Definition: trace-helper.h:56
ns3::AsciiTraceHelper::DefaultDequeueSinkWithContext
static void DefaultDequeueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Dequeue default trace sink.
Definition: trace-helper.cc:370
ns3::PcapHelperForDevice::~PcapHelperForDevice
virtual ~PcapHelperForDevice()
Destroy a PcapHelperForDevice.
Definition: trace-helper.h:564
ns3::MakeBoundCallback
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1703
ns3::PcapHelper::SinkWithHeader
static void SinkWithHeader(Ptr< PcapFileWrapper > file, const Header &header, Ptr< const Packet > p)
This trace sink passes a header separately from the packet to prevent creating a new packet (for perf...
Definition: trace-helper.cc:174
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::AsciiTraceHelper::HookDefaultDropSinkWithoutContext
void HookDefaultDropSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default drop operation trace sink that does not accept nor log a trace con...
Definition: trace-helper.h:484
ns3::AsciiTraceHelper::DefaultDequeueSinkWithoutContext
static void DefaultDequeueSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Dequeue default trace sink.
Definition: trace-helper.cc:363
ns3::AsciiTraceHelper::DefaultDropSinkWithContext
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop default trace sink.
Definition: trace-helper.cc:343
ns3::AsciiTraceHelperForDevice::EnableAsciiInternal
virtual void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)=0
Enable ascii trace output on the indicated net device.
ns3::AsciiTraceHelper::GetFilenameFromDevice
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...
Definition: trace-helper.cc:212
ns3::AsciiTraceHelper::DefaultEnqueueSinkWithContext
static void DefaultEnqueueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Enqueue default trace sink.
Definition: trace-helper.cc:317
ns3::PcapHelper::~PcapHelper
~PcapHelper()
Destroy a pcap helper.
Definition: trace-helper.cc:43
ns3::PcapHelper::DataLinkType
DataLinkType
This enumeration holds the data link types that will be written to the pcap file.
Definition: trace-helper.h:50
create-module.file
file
Definition: create-module.py:634
ns3::PcapHelperForDevice
Base class providing common user-level pcap operations for helpers representing net devices.
Definition: trace-helper.h:554
ns3::AsciiTraceHelperForDevice
Base class providing common user-level ascii trace operations for helpers representing net devices.
Definition: trace-helper.h:643
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::PcapHelper::GetFilenameFromInterfacePair
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.
Definition: trace-helper.cc:125
ns3::AsciiTraceHelper::GetFilenameFromInterfacePair
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...
Definition: trace-helper.cc:257
ns3::AsciiTraceHelperForDevice::EnableAscii
void EnableAscii(std::string prefix, Ptr< NetDevice > nd, bool explicitFilename=false)
Enable ascii trace output on the indicated net device.
Definition: trace-helper.cc:469
ns3::PcapHelper::DLT_NULL
@ DLT_NULL
Definition: trace-helper.h:51
ns3::AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext
void HookDefaultDequeueSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default dequeue operation trace sink that does not accept nor log a trace ...
Definition: trace-helper.h:506