A Discrete-Event Network Simulator
API
trace-helper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17 
18 #ifndef TRACE_HELPER_H
19 #define TRACE_HELPER_H
20 
21 #include "net-device-container.h"
22 #include "node-container.h"
23 
24 #include "ns3/assert.h"
25 #include "ns3/output-stream-wrapper.h"
26 #include "ns3/pcap-file-wrapper.h"
27 #include "ns3/simulator.h"
28 
29 namespace ns3
30 {
31 
40 {
41  public:
52  {
53  DLT_NULL = 0,
55  DLT_PPP = 9,
56  DLT_RAW = 101,
62  DLT_NETLINK = 253,
63  DLT_LORATAP = 270
64  };
65 
69  PcapHelper();
70 
74  ~PcapHelper();
75 
85  std::string GetFilenameFromDevice(std::string prefix,
86  Ptr<NetDevice> device,
87  bool useObjectNames = true);
88 
99  std::string GetFilenameFromInterfacePair(std::string prefix,
100  Ptr<Object> object,
101  uint32_t interface,
102  bool useObjectNames = true);
103 
114  Ptr<PcapFileWrapper> CreateFile(std::string filename,
115  std::ios::openmode filemode,
116  DataLinkType dataLinkType,
117  uint32_t snapLen = std::numeric_limits<uint32_t>::max(),
118  int32_t tzCorrection = 0);
126  template <typename T>
127  void HookDefaultSink(Ptr<T> object, std::string traceName, Ptr<PcapFileWrapper> file);
128 
129  private:
140 
152  const Header& header,
154 };
155 
156 template <typename T>
157 void
159 {
160  bool result =
161  object->TraceConnectWithoutContext(tracename, MakeBoundCallback(&DefaultSink, file));
162  NS_ASSERT_MSG(result == true,
163  "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\"");
164 }
165 
174 {
175  public:
180 
185 
195  std::string GetFilenameFromDevice(std::string prefix,
196  Ptr<NetDevice> device,
197  bool useObjectNames = true);
198 
209  std::string GetFilenameFromInterfacePair(std::string prefix,
210  Ptr<Object> object,
211  uint32_t interface,
212  bool useObjectNames = true);
213 
238  Ptr<OutputStreamWrapper> CreateFileStream(std::string filename,
239  std::ios::openmode filemode = std::ios::out);
240 
249  template <typename T>
251  std::string traceName,
252  Ptr<OutputStreamWrapper> stream);
253 
263  template <typename T>
265  std::string context,
266  std::string traceName,
267  Ptr<OutputStreamWrapper> stream);
268 
277  template <typename T>
279  std::string traceName,
280  Ptr<OutputStreamWrapper> stream);
281 
291  template <typename T>
293  std::string context,
294  std::string traceName,
295  Ptr<OutputStreamWrapper> stream);
296 
305  template <typename T>
307  std::string traceName,
308  Ptr<OutputStreamWrapper> stream);
309 
319  template <typename T>
321  std::string context,
322  std::string traceName,
323  Ptr<OutputStreamWrapper> stream);
324 
333  template <typename T>
335  std::string traceName,
336  Ptr<OutputStreamWrapper> stream);
337 
347  template <typename T>
349  std::string context,
350  std::string traceName,
351  Ptr<OutputStreamWrapper> stream);
352 
369 
386  std::string context,
388 
405 
423  std::string context,
425 
444 
463  std::string context,
465 
482 
499  std::string context,
501 };
502 
503 template <typename T>
504 void
506  std::string tracename,
508 {
509  bool result = object->TraceConnectWithoutContext(
510  tracename,
512  NS_ASSERT_MSG(result == true,
513  "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \""
514  << tracename << "\"");
515 }
516 
517 template <typename T>
518 void
520  std::string context,
521  std::string tracename,
523 {
524  bool result = object->TraceConnect(tracename,
525  context,
527  NS_ASSERT_MSG(result == true,
528  "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \""
529  << tracename << "\"");
530 }
531 
532 template <typename T>
533 void
535  std::string tracename,
537 {
538  bool result =
539  object->TraceConnectWithoutContext(tracename,
541  NS_ASSERT_MSG(result == true,
542  "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \""
543  << tracename << "\"");
544 }
545 
546 template <typename T>
547 void
549  std::string context,
550  std::string tracename,
552 {
553  bool result = object->TraceConnect(tracename,
554  context,
556  NS_ASSERT_MSG(result == true,
557  "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \""
558  << tracename << "\"");
559 }
560 
561 template <typename T>
562 void
564  std::string tracename,
566 {
567  bool result = object->TraceConnectWithoutContext(
568  tracename,
570  NS_ASSERT_MSG(result == true,
571  "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \""
572  << tracename << "\"");
573 }
574 
575 template <typename T>
576 void
578  std::string context,
579  std::string tracename,
581 {
582  bool result = object->TraceConnect(tracename,
583  context,
585  NS_ASSERT_MSG(result == true,
586  "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \""
587  << tracename << "\"");
588 }
589 
590 template <typename T>
591 void
593  std::string tracename,
595 {
596  bool result = object->TraceConnectWithoutContext(
597  tracename,
599  NS_ASSERT_MSG(result == true,
600  "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \""
601  << tracename << "\"");
602 }
603 
604 template <typename T>
605 void
607  std::string context,
608  std::string tracename,
610 {
611  bool result = object->TraceConnect(tracename,
612  context,
614  NS_ASSERT_MSG(result == true,
615  "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \""
616  << tracename << "\"");
617 }
618 
624 {
625  public:
630  {
631  }
632 
637  {
638  }
639 
648  virtual void EnablePcapInternal(std::string prefix,
649  Ptr<NetDevice> nd,
650  bool promiscuous,
651  bool explicitFilename) = 0;
652 
661  void EnablePcap(std::string prefix,
662  Ptr<NetDevice> nd,
663  bool promiscuous = false,
664  bool explicitFilename = false);
665 
675  void EnablePcap(std::string prefix,
676  std::string ndName,
677  bool promiscuous = false,
678  bool explicitFilename = false);
679 
688  void EnablePcap(std::string prefix, NetDeviceContainer d, bool promiscuous = false);
689 
698  void EnablePcap(std::string prefix, NodeContainer n, bool promiscuous = false);
699 
709  void EnablePcap(std::string prefix,
710  uint32_t nodeid,
711  uint32_t deviceid,
712  bool promiscuous = false);
713 
721  void EnablePcapAll(std::string prefix, bool promiscuous = false);
722 };
723 
729 {
730  public:
735  {
736  }
737 
742  {
743  }
744 
769  std::string prefix,
770  Ptr<NetDevice> nd,
771  bool explicitFilename) = 0;
772 
780  void EnableAscii(std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
781 
790 
799  void EnableAscii(std::string prefix, std::string ndName, bool explicitFilename = false);
800 
809  void EnableAscii(Ptr<OutputStreamWrapper> stream, std::string ndName);
810 
818  void EnableAscii(std::string prefix, NetDeviceContainer d);
819 
829 
837  void EnableAscii(std::string prefix, NodeContainer n);
838 
848 
855  void EnableAsciiAll(std::string prefix);
856 
865 
877  void EnableAscii(std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
878 
890  void EnableAscii(Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
891 
892  private:
908  std::string prefix,
909  uint32_t nodeid,
910  uint32_t deviceid,
911  bool explicitFilename);
912 
922  void EnableAsciiImpl(Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n);
923 
933  void EnableAsciiImpl(Ptr<OutputStreamWrapper> stream, std::string prefix, NetDeviceContainer d);
934 
946  std::string prefix,
947  std::string ndName,
948  bool explicitFilename);
949 
960  std::string prefix,
961  Ptr<NetDevice> nd,
962  bool explicitFilename);
963 };
964 
965 } // namespace ns3
966 
967 #endif /* TRACE_HELPER_H */
#define max(a, b)
Definition: 80211b.c:42
Base class providing common user-level ascii trace operations for helpers representing net devices.
Definition: trace-helper.h:729
virtual ~AsciiTraceHelperForDevice()
Destroy an AsciiTraceHelperForDevice.
Definition: trace-helper.h:741
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) ...
void EnableAscii(std::string prefix, Ptr< NetDevice > nd, bool explicitFilename=false)
Enable ascii trace output on the indicated net device.
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...
AsciiTraceHelperForDevice()
Construct an AsciiTraceHelperForDevice.
Definition: trace-helper.h:734
virtual void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)=0
Enable ascii trace output on the indicated net device.
void EnableAsciiImpl(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)
Enable ascii trace output the indicated net device (implementation).
Manage ASCII trace files for device models.
Definition: trace-helper.h:174
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:534
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 DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop default trace sink.
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...
static void DefaultReceiveSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Receive default trace sink.
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:577
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.
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:505
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:519
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:606
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:592
AsciiTraceHelper()
Create an ascii trace helper.
static void DefaultDequeueSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Dequeue default trace sink.
static void DefaultEnqueueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Enqueue default trace sink.
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:563
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:548
static void DefaultDropSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Drop default trace sink.
static void DefaultDequeueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Dequeue default trace sink.
static void DefaultEnqueueSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Enqueue default trace sink.
~AsciiTraceHelper()
Destroy an ascii trace helper.
static void DefaultReceiveSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Receive default trace sink.
Protocol header serialization and deserialization.
Definition: header.h:44
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Base class providing common user-level pcap operations for helpers representing net devices.
Definition: trace-helper.h:624
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 EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)=0
Enable pcap output the indicated net device.
virtual ~PcapHelperForDevice()
Destroy a PcapHelperForDevice.
Definition: trace-helper.h:636
PcapHelperForDevice()
Construct a PcapHelperForDevice.
Definition: trace-helper.h:629
Manage pcap files for device models.
Definition: trace-helper.h:40
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:79
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
DataLinkType
This enumeration holds the data link types that will be written to the pcap file.
Definition: trace-helper.h:52
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...
void HookDefaultSink(Ptr< T > object, std::string traceName, Ptr< PcapFileWrapper > file)
Hook a trace source to the default trace sink.
Definition: trace-helper.h:158
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.
~PcapHelper()
Destroy a pcap helper.
Definition: trace-helper.cc:43
static void DefaultSink(Ptr< PcapFileWrapper > file, Ptr< const Packet > p)
The basic default trace sink.
PcapHelper()
Create a pcap helper.
Definition: trace-helper.cc:38
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#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:86
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition: callback.h:765
Every class exported by the ns3 library is enclosed in the ns3 namespace.