A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
41  //
42  // These are the data link types that will be written to the pcap file. We
43  // don't include pcap-bpf.h to avoid an explicit dependency on the real pcap
44  // and we don't make an enumeration of all of the values to make it easy to
45  // pass new values in.
46  //
47  enum {
48  DLT_NULL = 0,
50  DLT_PPP = 9,
51  DLT_RAW = 101,
59  };
60 
64  PcapHelper ();
65 
69  ~PcapHelper ();
70 
80  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
81 
92  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
93  uint32_t interface, bool useObjectNames = true);
94 
105  Ptr<PcapFileWrapper> CreateFile (std::string filename, std::ios::openmode filemode,
106  uint32_t dataLinkType, uint32_t snapLen = std::numeric_limits<uint32_t>::max (), int32_t tzCorrection = 0);
114  template <typename T> void HookDefaultSink (Ptr<T> object, std::string traceName, Ptr<PcapFileWrapper> file);
115 
116 private:
126  static void DefaultSink (Ptr<PcapFileWrapper> file, Ptr<const Packet> p);
127 
138  static void SinkWithHeader (Ptr<PcapFileWrapper> file, const Header& header, Ptr<const Packet> p);
139 };
140 
141 template <typename T> void
142 PcapHelper::HookDefaultSink (Ptr<T> object, std::string tracename, Ptr<PcapFileWrapper> file)
143 {
144  bool result =
145  object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file));
146  NS_ASSERT_MSG (result == true, "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\"");
147 }
148 
157 {
158 public:
162  AsciiTraceHelper ();
163 
168 
178  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
179 
190  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
191  uint32_t interface, bool useObjectNames = true);
192 
217  Ptr<OutputStreamWrapper> CreateFileStream (std::string filename,
218  std::ios::openmode filemode = std::ios::out);
219 
228  template <typename T>
229  void HookDefaultEnqueueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
230 
240  template <typename T>
242  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
243 
252  template <typename T>
253  void HookDefaultDropSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
254 
264  template <typename T>
266  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
267 
276  template <typename T>
277  void HookDefaultDequeueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
278 
288  template <typename T>
290  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
291 
300  template <typename T>
301  void HookDefaultReceiveSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
302 
312  template <typename T>
314  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
315 
331 
347  static void DefaultEnqueueSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
348 
365 
382  static void DefaultDropSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
383 
401 
419  static void DefaultDequeueSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
420 
436 
452  static void DefaultReceiveSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
453 };
454 
455 template <typename T> void
457 {
458  bool result =
459  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultEnqueueSinkWithoutContext, file));
460  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \""
461  << tracename << "\"");
462 }
463 
464 template <typename T> void
466  Ptr<T> object,
467  std::string context,
468  std::string tracename,
470 {
471  bool result =
472  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultEnqueueSinkWithContext, stream));
473  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \""
474  << tracename << "\"");
475 }
476 
477 template <typename T> void
479 {
480  bool result =
481  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDropSinkWithoutContext, file));
482  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \""
483  << tracename << "\"");
484 }
485 
486 template <typename T> void
488  Ptr<T> object,
489  std::string context,
490  std::string tracename,
492 {
493  bool result =
494  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDropSinkWithContext, stream));
495  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \""
496  << tracename << "\"");
497 }
498 
499 template <typename T> void
501 {
502  bool result =
503  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDequeueSinkWithoutContext, file));
504  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \""
505  << tracename << "\"");
506 }
507 
508 template <typename T> void
510  Ptr<T> object,
511  std::string context,
512  std::string tracename,
514 {
515  bool result =
516  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDequeueSinkWithContext, stream));
517  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \""
518  << tracename << "\"");
519 }
520 
521 template <typename T> void
523 {
524  bool result =
525  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultReceiveSinkWithoutContext, file));
526  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \""
527  << tracename << "\"");
528 }
529 
530 template <typename T> void
532  Ptr<T> object,
533  std::string context,
534  std::string tracename,
536 {
537  bool result =
538  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultReceiveSinkWithContext, stream));
539  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \""
540  << tracename << "\"");
541 }
542 
548 {
549 public:
554 
558  virtual ~PcapHelperForDevice () {}
559 
568  virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename) = 0;
569 
578  void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false);
579 
589  void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false, bool explicitFilename = false);
590 
599  void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false);
600 
609  void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false);
610 
620  void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false);
621 
629  void EnablePcapAll (std::string prefix, bool promiscuous = false);
630 };
631 
637 {
638 public:
643 
648 
672  virtual void EnableAsciiInternal (Ptr<OutputStreamWrapper> stream,
673  std::string prefix,
674  Ptr<NetDevice> nd,
675  bool explicitFilename) = 0;
676 
684  void EnableAscii (std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
685 
694 
703  void EnableAscii (std::string prefix, std::string ndName, bool explicitFilename = false);
704 
713  void EnableAscii (Ptr<OutputStreamWrapper> stream, std::string ndName);
714 
722  void EnableAscii (std::string prefix, NetDeviceContainer d);
723 
733 
741  void EnableAscii (std::string prefix, NodeContainer n);
742 
752 
759  void EnableAsciiAll (std::string prefix);
760 
769 
781  void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
782 
794  void EnableAscii (Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
795 
796 private:
812  std::string prefix,
813  uint32_t nodeid,
814  uint32_t deviceid,
815  bool explicitFilename);
816 
826  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n);
827 
837  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NetDeviceContainer d);
838 
849  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, std::string ndName, bool explicitFilename);
850 
860  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, Ptr<NetDevice> nd, bool explicitFilename);
861 };
862 
863 } // namespace ns3
864 
865 #endif /* TRACE_HELPER_H */
Protocol header serialization and deserialization.
Definition: header.h:42
Base class providing common user-level ascii trace operations for helpers representing net devices...
Definition: trace-helper.h:636
Manage ASCII trace files for device models.
Definition: trace-helper.h:156
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
static void DefaultEnqueueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Enqueue default trace sink.
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 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:478
Manage pcap files for device models.
Definition: trace-helper.h:38
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1686
Base class providing common user-level pcap operations for helpers representing net devices...
Definition: trace-helper.h:547
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop 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:509
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:456
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)
Basic Receive default trace sink.
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...
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
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 ...
#define max(a, b)
Definition: 80211b.c:45
holds a vector of ns3::NetDevice pointers
static void DefaultEnqueueSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Enqueue default trace sink.
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)
Basic Dequeue default trace sink.
AsciiTraceHelperForDevice()
Construct an AsciiTraceHelperForDevice.
Definition: trace-helper.h:642
static void DefaultReceiveSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Receive default trace sink.
static void DefaultSink(Ptr< PcapFileWrapper > file, Ptr< const Packet > p)
The basic default trace sink.
static void DefaultDequeueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Dequeue default trace sink.
keep track of a set of node pointers.
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)=0
Enable pcap output the indicated net device.
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:531
AsciiTraceHelper()
Create an ascii trace helper.
static void DefaultDropSinkWithoutContext(Ptr< OutputStreamWrapper > file, Ptr< const Packet > p)
Basic Drop default trace sink.
PcapHelper()
Create a pcap helper.
Definition: trace-helper.cc:38
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:522
#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:90
void EnableAscii(std::string prefix, Ptr< NetDevice > nd, bool explicitFilename=false)
Enable ascii trace output on the indicated net device.
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...
virtual void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)=0
Enable ascii trace output on the indicated net device.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, uint32_t 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
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...
PcapHelperForDevice()
Construct a PcapHelperForDevice.
Definition: trace-helper.h:553
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void HookDefaultSink(Ptr< T > object, std::string traceName, Ptr< PcapFileWrapper > file)
Hook a trace source to the default trace sink.
Definition: trace-helper.h:142
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:465
~AsciiTraceHelper()
Destroy an ascii trace helper.
virtual ~PcapHelperForDevice()
Destroy a PcapHelperForDevice.
Definition: trace-helper.h:558
~PcapHelper()
Destroy a pcap helper.
Definition: trace-helper.cc:43
virtual ~AsciiTraceHelperForDevice()
Destroy an AsciiTraceHelperForDevice.
Definition: trace-helper.h:647
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:487
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:500