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,
56  };
57 
61  PcapHelper ();
62 
66  ~PcapHelper ();
67 
77  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
78 
89  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
90  uint32_t interface, bool useObjectNames = true);
91 
102  Ptr<PcapFileWrapper> CreateFile (std::string filename, std::ios::openmode filemode,
103  uint32_t dataLinkType, uint32_t snapLen = 65535, int32_t tzCorrection = 0);
111  template <typename T> void HookDefaultSink (Ptr<T> object, std::string traceName, Ptr<PcapFileWrapper> file);
112 
113 private:
123  static void DefaultSink (Ptr<PcapFileWrapper> file, Ptr<const Packet> p);
124 };
125 
126 template <typename T> void
127 PcapHelper::HookDefaultSink (Ptr<T> object, std::string tracename, Ptr<PcapFileWrapper> file)
128 {
129  bool result =
130  object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file));
131  NS_ASSERT_MSG (result == true, "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\"");
132 }
133 
142 {
143 public:
147  AsciiTraceHelper ();
148 
153 
163  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
164 
175  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
176  uint32_t interface, bool useObjectNames = true);
177 
202  Ptr<OutputStreamWrapper> CreateFileStream (std::string filename,
203  std::ios::openmode filemode = std::ios::out);
204 
213  template <typename T>
214  void HookDefaultEnqueueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
215 
225  template <typename T>
227  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
228 
237  template <typename T>
238  void HookDefaultDropSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
239 
249  template <typename T>
251  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
252 
261  template <typename T>
262  void HookDefaultDequeueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
263 
273  template <typename T>
275  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
276 
285  template <typename T>
286  void HookDefaultReceiveSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
287 
297  template <typename T>
299  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
300 
316 
332  static void DefaultEnqueueSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
333 
350 
367  static void DefaultDropSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
368 
386 
404  static void DefaultDequeueSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
405 
421 
437  static void DefaultReceiveSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
438 };
439 
440 template <typename T> void
442 {
443  bool result =
444  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultEnqueueSinkWithoutContext, file));
445  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \""
446  << tracename << "\"");
447 }
448 
449 template <typename T> void
451  Ptr<T> object,
452  std::string context,
453  std::string tracename,
455 {
456  bool result =
457  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultEnqueueSinkWithContext, stream));
458  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \""
459  << tracename << "\"");
460 }
461 
462 template <typename T> void
464 {
465  bool result =
466  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDropSinkWithoutContext, file));
467  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \""
468  << tracename << "\"");
469 }
470 
471 template <typename T> void
473  Ptr<T> object,
474  std::string context,
475  std::string tracename,
477 {
478  bool result =
479  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDropSinkWithContext, stream));
480  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \""
481  << tracename << "\"");
482 }
483 
484 template <typename T> void
486 {
487  bool result =
488  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDequeueSinkWithoutContext, file));
489  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \""
490  << tracename << "\"");
491 }
492 
493 template <typename T> void
495  Ptr<T> object,
496  std::string context,
497  std::string tracename,
499 {
500  bool result =
501  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDequeueSinkWithContext, stream));
502  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \""
503  << tracename << "\"");
504 }
505 
506 template <typename T> void
508 {
509  bool result =
510  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultReceiveSinkWithoutContext, file));
511  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \""
512  << tracename << "\"");
513 }
514 
515 template <typename T> void
517  Ptr<T> object,
518  std::string context,
519  std::string tracename,
521 {
522  bool result =
523  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultReceiveSinkWithContext, stream));
524  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \""
525  << tracename << "\"");
526 }
527 
533 {
534 public:
539 
543  virtual ~PcapHelperForDevice () {}
544 
554  virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename) = 0;
555 
564  void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false);
565 
575  void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false, bool explicitFilename = false);
576 
585  void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false);
586 
595  void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false);
596 
606  void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false);
607 
615  void EnablePcapAll (std::string prefix, bool promiscuous = false);
616 };
617 
623 {
624 public:
629 
634 
659  virtual void EnableAsciiInternal (Ptr<OutputStreamWrapper> stream,
660  std::string prefix,
661  Ptr<NetDevice> nd,
662  bool explicitFilename) = 0;
663 
671  void EnableAscii (std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
672 
681 
690  void EnableAscii (std::string prefix, std::string ndName, bool explicitFilename = false);
691 
700  void EnableAscii (Ptr<OutputStreamWrapper> stream, std::string ndName);
701 
709  void EnableAscii (std::string prefix, NetDeviceContainer d);
710 
720 
728  void EnableAscii (std::string prefix, NodeContainer n);
729 
739 
746  void EnableAsciiAll (std::string prefix);
747 
756 
768  void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
769 
781  void EnableAscii (Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
782 
783 private:
801  std::string prefix,
802  uint32_t nodeid,
803  uint32_t deviceid,
804  bool explicitFilename);
805 
815  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n);
816 
826  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NetDeviceContainer d);
827 
838  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, std::string ndName, bool explicitFilename);
839 
849  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, Ptr<NetDevice> nd, bool explicitFilename);
850 };
851 
852 } // namespace ns3
853 
854 #endif /* TRACE_HELPER_H */
Base class providing common user-level ascii trace operations for helpers representing net devices...
Definition: trace-helper.h:622
Manage ASCII trace files for device models.
Definition: trace-helper.h:141
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
static void DefaultEnqueueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Enqueue default trace sink.
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.
Definition: trace-helper.cc:49
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:463
Manage pcap files for device models.
Definition: trace-helper.h:38
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Build bound Callbacks which take varying numbers of arguments, and potentially returning a value...
Definition: callback.h:1467
Base class providing common user-level pcap operations for helpers representing net devices...
Definition: trace-helper.h:532
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:494
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:441
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.
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 ...
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:628
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:516
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:507
#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:84
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.
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:538
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:127
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:450
~AsciiTraceHelper()
Destroy an ascii trace helper.
virtual ~PcapHelperForDevice()
Destroy a PcapHelperForDevice.
Definition: trace-helper.h:543
~PcapHelper()
Destroy a pcap helper.
Definition: trace-helper.cc:43
virtual ~AsciiTraceHelperForDevice()
Destroy an AsciiTraceHelperForDevice.
Definition: trace-helper.h:633
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:472
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:485