A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
trace-helper.h
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,
49  DLT_EN10MB = 1,
50  DLT_PPP = 9,
51  DLT_RAW = 101,
52  DLT_IEEE802_11 = 105,
53  DLT_PRISM_HEADER = 119,
54  DLT_IEEE802_11_RADIO = 127
55  };
56 
60  PcapHelper ();
61 
65  ~PcapHelper ();
66 
71  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
72 
77  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
78  uint32_t interface, bool useObjectNames = true);
79 
83  Ptr<PcapFileWrapper> CreateFile (std::string filename, std::ios::openmode filemode,
84  uint32_t dataLinkType, uint32_t snapLen = 65535, int32_t tzCorrection = 0);
88  template <typename T> void HookDefaultSink (Ptr<T> object, std::string traceName, Ptr<PcapFileWrapper> file);
89 
90 private:
91  static void DefaultSink (Ptr<PcapFileWrapper> file, Ptr<const Packet> p);
92 };
93 
94 template <typename T> void
95 PcapHelper::HookDefaultSink (Ptr<T> object, std::string tracename, Ptr<PcapFileWrapper> file)
96 {
97  bool result =
98  object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file));
99  NS_ASSERT_MSG (result == true, "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\"");
100 }
101 
110 {
111 public:
115  AsciiTraceHelper ();
116 
121 
126  std::string GetFilenameFromDevice (std::string prefix, Ptr<NetDevice> device, bool useObjectNames = true);
127 
132  std::string GetFilenameFromInterfacePair (std::string prefix, Ptr<Object> object,
133  uint32_t interface, bool useObjectNames = true);
134 
155  Ptr<OutputStreamWrapper> CreateFileStream (std::string filename,
156  std::ios::openmode filemode = std::ios::out);
157 
162  template <typename T>
163  void HookDefaultEnqueueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
164 
169  template <typename T>
171  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
172 
177  template <typename T>
178  void HookDefaultDropSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
179 
184  template <typename T>
186  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
187 
192  template <typename T>
193  void HookDefaultDequeueSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
194 
199  template <typename T>
201  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
202 
207  template <typename T>
208  void HookDefaultReceiveSinkWithoutContext (Ptr<T> object, std::string traceName, Ptr<OutputStreamWrapper> stream);
209 
214  template <typename T>
216  std::string context, std::string traceName, Ptr<OutputStreamWrapper> stream);
217 
218  static void DefaultEnqueueSinkWithoutContext (Ptr<OutputStreamWrapper> file, Ptr<const Packet> p);
219  static void DefaultEnqueueSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
220 
221  static void DefaultDropSinkWithoutContext (Ptr<OutputStreamWrapper> file, Ptr<const Packet> p);
222  static void DefaultDropSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
223 
224  static void DefaultDequeueSinkWithoutContext (Ptr<OutputStreamWrapper> file, Ptr<const Packet> p);
225  static void DefaultDequeueSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
226 
227  static void DefaultReceiveSinkWithoutContext (Ptr<OutputStreamWrapper> file, Ptr<const Packet> p);
228  static void DefaultReceiveSinkWithContext (Ptr<OutputStreamWrapper> file, std::string context, Ptr<const Packet> p);
229 };
230 
231 template <typename T> void
233 {
234  bool result =
235  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultEnqueueSinkWithoutContext, file));
236  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \""
237  << tracename << "\"");
238 }
239 
240 template <typename T> void
242  Ptr<T> object,
243  std::string context,
244  std::string tracename,
246 {
247  bool result =
248  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultEnqueueSinkWithContext, stream));
249  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \""
250  << tracename << "\"");
251 }
252 
253 template <typename T> void
255 {
256  bool result =
257  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDropSinkWithoutContext, file));
258  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \""
259  << tracename << "\"");
260 }
261 
262 template <typename T> void
264  Ptr<T> object,
265  std::string context,
266  std::string tracename,
268 {
269  bool result =
270  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDropSinkWithContext, stream));
271  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \""
272  << tracename << "\"");
273 }
274 
275 template <typename T> void
277 {
278  bool result =
279  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDequeueSinkWithoutContext, file));
280  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \""
281  << tracename << "\"");
282 }
283 
284 template <typename T> void
286  Ptr<T> object,
287  std::string context,
288  std::string tracename,
290 {
291  bool result =
292  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDequeueSinkWithContext, stream));
293  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \""
294  << tracename << "\"");
295 }
296 
297 template <typename T> void
299 {
300  bool result =
301  object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultReceiveSinkWithoutContext, file));
302  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \""
303  << tracename << "\"");
304 }
305 
306 template <typename T> void
308  Ptr<T> object,
309  std::string context,
310  std::string tracename,
312 {
313  bool result =
314  object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultReceiveSinkWithContext, stream));
315  NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \""
316  << tracename << "\"");
317 }
318 
324 {
325 public:
330 
334  virtual ~PcapHelperForDevice () {}
335 
345  virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename) = 0;
346 
355  void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false);
356 
366  void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false, bool explicitFilename = false);
367 
376  void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false);
377 
386  void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false);
387 
397  void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false);
398 
406  void EnablePcapAll (std::string prefix, bool promiscuous = false);
407 };
408 
414 {
415 public:
420 
425 
450  virtual void EnableAsciiInternal (Ptr<OutputStreamWrapper> stream,
451  std::string prefix,
452  Ptr<NetDevice> nd,
453  bool explicitFilename) = 0;
454 
462  void EnableAscii (std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
463 
472 
481  void EnableAscii (std::string prefix, std::string ndName, bool explicitFilename = false);
482 
491  void EnableAscii (Ptr<OutputStreamWrapper> stream, std::string ndName);
492 
500  void EnableAscii (std::string prefix, NetDeviceContainer d);
501 
511 
519  void EnableAscii (std::string prefix, NodeContainer n);
520 
530 
537  void EnableAsciiAll (std::string prefix);
538 
547 
559  void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
560 
572  void EnableAscii (Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
573 
574 private:
579  std::string prefix,
580  uint32_t nodeid,
581  uint32_t deviceid,
582  bool explicitFilename);
583 
587  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n);
588 
592  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NetDeviceContainer d);
593 
597  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, std::string ndName, bool explicitFilename);
598 
602  void EnableAsciiImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, Ptr<NetDevice> nd, bool explicitFilename);
603 };
604 
605 } // namespace ns3
606 
607 #endif /* TRACE_HELPER_H */
Base class providing common user-level ascii trace operations for helpers representing net devices...
Definition: trace-helper.h:413
Manage ASCII trace files for device models.
Definition: trace-helper.h:109
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
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)
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:254
Manage pcap files for device models.
Definition: trace-helper.h:38
Base class providing common user-level pcap operations for helpers representing net devices...
Definition: trace-helper.h:323
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:285
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:232
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...
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
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...
AsciiTraceHelperForDevice()
Construct an AsciiTraceHelperForDevice.
Definition: trace-helper.h:419
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:307
AsciiTraceHelper()
Create an ascii trace helper.
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:298
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
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:329
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:95
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:241
~AsciiTraceHelper()
Destroy an ascii trace helper.
virtual ~PcapHelperForDevice()
Destroy a PcapHelperForDevice.
Definition: trace-helper.h:334
~PcapHelper()
Destroy a pcap helper.
Definition: trace-helper.cc:43
virtual ~AsciiTraceHelperForDevice()
Destroy an AsciiTraceHelperForDevice.
Definition: trace-helper.h:424
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:263
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:276