A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 "ns3/assert.h"
22#include "ns3/net-device-container.h"
23#include "ns3/node-container.h"
24#include "ns3/output-stream-wrapper.h"
25#include "ns3/pcap-file-wrapper.h"
26#include "ns3/simulator.h"
27
28namespace ns3
29{
30
39{
40 public:
51 {
55 DLT_RAW = 101,
62 DLT_LORATAP = 270
63 };
64
68 PcapHelper();
69
74
84 std::string GetFilenameFromDevice(std::string prefix,
85 Ptr<NetDevice> device,
86 bool useObjectNames = true);
87
98 std::string GetFilenameFromInterfacePair(std::string prefix,
99 Ptr<Object> object,
100 uint32_t interface,
101 bool useObjectNames = true);
102
113 Ptr<PcapFileWrapper> CreateFile(std::string filename,
114 std::ios::openmode filemode,
115 DataLinkType dataLinkType,
116 uint32_t snapLen = std::numeric_limits<uint32_t>::max(),
117 int32_t tzCorrection = 0);
125 template <typename T>
126 void HookDefaultSink(Ptr<T> object, std::string traceName, Ptr<PcapFileWrapper> file);
127
128 private:
139
150 static void SinkWithHeader(Ptr<PcapFileWrapper> file,
151 const Header& header,
153};
154
155template <typename T>
156void
157PcapHelper::HookDefaultSink(Ptr<T> object, std::string tracename, Ptr<PcapFileWrapper> file)
158{
159 bool result =
160 object->TraceConnectWithoutContext(tracename, MakeBoundCallback(&DefaultSink, file));
161 NS_ASSERT_MSG(result == true,
162 "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\"");
163}
164
173{
174 public:
179
184
194 std::string GetFilenameFromDevice(std::string prefix,
195 Ptr<NetDevice> device,
196 bool useObjectNames = true);
197
208 std::string GetFilenameFromInterfacePair(std::string prefix,
209 Ptr<Object> object,
210 uint32_t interface,
211 bool useObjectNames = true);
212
237 Ptr<OutputStreamWrapper> CreateFileStream(std::string filename,
238 std::ios::openmode filemode = std::ios::out);
239
248 template <typename T>
250 std::string traceName,
252
262 template <typename T>
264 std::string context,
265 std::string traceName,
267
276 template <typename T>
278 std::string traceName,
280
290 template <typename T>
292 std::string context,
293 std::string traceName,
295
304 template <typename T>
306 std::string traceName,
308
318 template <typename T>
320 std::string context,
321 std::string traceName,
323
332 template <typename T>
334 std::string traceName,
336
346 template <typename T>
348 std::string context,
349 std::string traceName,
351
368
385 std::string context,
387
404
422 std::string context,
424
443
462 std::string context,
464
481
498 std::string context,
500};
501
502template <typename T>
503void
505 std::string tracename,
507{
508 bool result = object->TraceConnectWithoutContext(
509 tracename,
511 NS_ASSERT_MSG(result == true,
512 "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \""
513 << tracename << "\"");
514}
515
516template <typename T>
517void
519 std::string context,
520 std::string tracename,
522{
523 bool result = object->TraceConnect(tracename,
524 context,
526 NS_ASSERT_MSG(result == true,
527 "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \""
528 << tracename << "\"");
529}
530
531template <typename T>
532void
534 std::string tracename,
536{
537 bool result =
538 object->TraceConnectWithoutContext(tracename,
540 NS_ASSERT_MSG(result == true,
541 "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \""
542 << tracename << "\"");
543}
544
545template <typename T>
546void
548 std::string context,
549 std::string tracename,
551{
552 bool result = object->TraceConnect(tracename,
553 context,
555 NS_ASSERT_MSG(result == true,
556 "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \""
557 << tracename << "\"");
558}
559
560template <typename T>
561void
563 std::string tracename,
565{
566 bool result = object->TraceConnectWithoutContext(
567 tracename,
569 NS_ASSERT_MSG(result == true,
570 "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \""
571 << tracename << "\"");
572}
573
574template <typename T>
575void
577 std::string context,
578 std::string tracename,
580{
581 bool result = object->TraceConnect(tracename,
582 context,
584 NS_ASSERT_MSG(result == true,
585 "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \""
586 << tracename << "\"");
587}
588
589template <typename T>
590void
592 std::string tracename,
594{
595 bool result = object->TraceConnectWithoutContext(
596 tracename,
598 NS_ASSERT_MSG(result == true,
599 "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \""
600 << tracename << "\"");
601}
602
603template <typename T>
604void
606 std::string context,
607 std::string tracename,
609{
610 bool result = object->TraceConnect(tracename,
611 context,
613 NS_ASSERT_MSG(result == true,
614 "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \""
615 << tracename << "\"");
616}
617
623{
624 public:
629 {
630 }
631
636 {
637 }
638
647 virtual void EnablePcapInternal(std::string prefix,
649 bool promiscuous,
650 bool explicitFilename) = 0;
651
660 void EnablePcap(std::string prefix,
662 bool promiscuous = false,
663 bool explicitFilename = false);
664
674 void EnablePcap(std::string prefix,
675 std::string ndName,
676 bool promiscuous = false,
677 bool explicitFilename = false);
678
687 void EnablePcap(std::string prefix, NetDeviceContainer d, bool promiscuous = false);
688
697 void EnablePcap(std::string prefix, NodeContainer n, bool promiscuous = false);
698
708 void EnablePcap(std::string prefix,
709 uint32_t nodeid,
710 uint32_t deviceid,
711 bool promiscuous = false);
712
720 void EnablePcapAll(std::string prefix, bool promiscuous = false);
721};
722
728{
729 public:
734 {
735 }
736
741 {
742 }
743
768 std::string prefix,
770 bool explicitFilename) = 0;
771
779 void EnableAscii(std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
780
789
798 void EnableAscii(std::string prefix, std::string ndName, bool explicitFilename = false);
799
808 void EnableAscii(Ptr<OutputStreamWrapper> stream, std::string ndName);
809
817 void EnableAscii(std::string prefix, NetDeviceContainer d);
818
828
836 void EnableAscii(std::string prefix, NodeContainer n);
837
847
854 void EnableAsciiAll(std::string prefix);
855
864
876 void EnableAscii(std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
877
889 void EnableAscii(Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
890
891 private:
907 std::string prefix,
908 uint32_t nodeid,
909 uint32_t deviceid,
910 bool explicitFilename);
911
921 void EnableAsciiImpl(Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n);
922
932 void EnableAsciiImpl(Ptr<OutputStreamWrapper> stream, std::string prefix, NetDeviceContainer d);
933
945 std::string prefix,
946 std::string ndName,
947 bool explicitFilename);
948
959 std::string prefix,
961 bool explicitFilename);
962};
963
964} // namespace ns3
965
966#endif /* TRACE_HELPER_H */
Base class providing common user-level ascii trace operations for helpers representing net devices.
Definition: trace-helper.h:728
virtual ~AsciiTraceHelperForDevice()
Destroy an AsciiTraceHelperForDevice.
Definition: trace-helper.h:740
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:733
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:173
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:533
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:576
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:504
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:518
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:605
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:591
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:562
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:547
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:623
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:635
PcapHelperForDevice()
Construct a PcapHelperForDevice.
Definition: trace-helper.h:628
Manage pcap files for device models.
Definition: trace-helper.h:39
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:51
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:157
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:78
#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:763
Every class exported by the ns3 library is enclosed in the ns3 namespace.