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
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
29namespace ns3
30{
31
32/**
33 * \brief Manage pcap files for device models
34 *
35 * Handling pcap files is a common operation for ns-3 devices. It is useful to
36 * provide a common base class for dealing with these ops.
37 */
38
40{
41 public:
42 /**
43 * This enumeration holds the data link types that will be written to the pcap file.
44 *
45 * We don't include pcap-bpf.h to avoid an explicit dependency on the real pcap
46 * and we don't make an enumeration of all of the values to make it easy to
47 * pass new values in.
48 *
49 * For a list of Data Link Types see http://www.tcpdump.org/linktypes.html
50 */
52 {
56 DLT_RAW = 101,
63 DLT_LORATAP = 270
64 };
65
66 /**
67 * @brief Create a pcap helper.
68 */
69 PcapHelper();
70
71 /**
72 * @brief Destroy a pcap helper.
73 */
75
76 /**
77 * @brief Let the pcap helper figure out a reasonable filename to use for a
78 * pcap file associated with a device.
79 *
80 * @param prefix prefix string
81 * @param device NetDevice
82 * @param useObjectNames use node and device names instead of indexes
83 * @returns file name
84 */
85 std::string GetFilenameFromDevice(std::string prefix,
86 Ptr<NetDevice> device,
87 bool useObjectNames = true);
88
89 /**
90 * @brief Let the pcap helper figure out a reasonable filename to use for the
91 * pcap file associated with a node.
92 *
93 * @param prefix prefix string
94 * @param object interface (such as Ipv4Interface or Ipv6Interface)
95 * @param interface interface id
96 * @param useObjectNames use node and device names instead of indexes
97 * @returns file name
98 */
99 std::string GetFilenameFromInterfacePair(std::string prefix,
100 Ptr<Object> object,
101 uint32_t interface,
102 bool useObjectNames = true);
103
104 /**
105 * @brief Create and initialize a pcap file.
106 *
107 * @param filename file name
108 * @param filemode file mode
109 * @param dataLinkType data link type of packet data
110 * @param snapLen maximum length of packet data stored in records
111 * @param tzCorrection time zone correction to be applied to timestamps of packets
112 * @returns a smart pointer to the Pcap file
113 */
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);
119 /**
120 * @brief Hook a trace source to the default trace sink
121 *
122 * @param object object
123 * @param traceName trace source name
124 * @param file file wrapper
125 */
126 template <typename T>
127 void HookDefaultSink(Ptr<T> object, std::string traceName, Ptr<PcapFileWrapper> file);
128
129 private:
130 /**
131 * The basic default trace sink.
132 *
133 * This one just writes the packet to the pcap
134 * file which is good enough for most kinds of captures.
135 *
136 * @param file the file to write to
137 * @param p the packet to write
138 */
140
141 /**
142 * This trace sink passes a header separately from the packet to prevent creating a new packet
143 * (for performance reasons)
144 *
145 * @param file the file to write to
146 * @param header header of the packet
147 * @param p the packet to write
148 *
149 * @see DefaultSink
150 */
151 static void SinkWithHeader(Ptr<PcapFileWrapper> file,
152 const Header& header,
154};
155
156template <typename T>
157void
158PcapHelper::HookDefaultSink(Ptr<T> object, std::string tracename, Ptr<PcapFileWrapper> file)
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
166/**
167 * \brief Manage ASCII trace files for device models
168 *
169 * Handling ascii trace files is a common operation for ns-3 devices. It is
170 * useful to provide a common base class for dealing with these ops.
171 */
172
174{
175 public:
176 /**
177 * @brief Create an ascii trace helper.
178 */
180
181 /**
182 * @brief Destroy an ascii trace helper.
183 */
185
186 /**
187 * @brief Let the ascii trace helper figure out a reasonable filename to use
188 * for an ascii trace file associated with a device.
189 *
190 * @param prefix prefix string
191 * @param device NetDevice
192 * @param useObjectNames use node and device names instead of indexes
193 * @returns file name
194 */
195 std::string GetFilenameFromDevice(std::string prefix,
196 Ptr<NetDevice> device,
197 bool useObjectNames = true);
198
199 /**
200 * @brief Let the ascii trace helper figure out a reasonable filename to use
201 * for an ascii trace file associated with a node.
202 *
203 * @param prefix prefix string
204 * @param object interface (such as Ipv4Interface or Ipv6Interface)
205 * @param interface interface id
206 * @param useObjectNames use node and device names instead of indexes
207 * @returns file name
208 */
209 std::string GetFilenameFromInterfacePair(std::string prefix,
210 Ptr<Object> object,
211 uint32_t interface,
212 bool useObjectNames = true);
213
214 /**
215 * @brief Create and initialize an output stream object we'll use to write the
216 * traced bits.
217 *
218 * One of the common issues users run into when trying to use tracing in ns-3
219 * is actually a design decision made in the C++ stream library. It is not
220 * widely known that copy and assignment of iostreams is forbidden by
221 * std::basic_ios<>. This is because it is not possible to predict the
222 * semantics of the stream desired by a user.
223 *
224 * The tempting ns-3 idiom when tracing to a file is to create a bound callback
225 * with an ofstream as the bound object. Unfortunately, this implies a copy
226 * construction in order to get the ofstream object into the callback. This
227 * operation, as mentioned above, is forbidden by the STL. You could use a
228 * global ostream and pass a pointer to it, but that is pretty ugly. You
229 * could create an ostream on the stack and pass a pointer to it, but you may
230 * run into object lifetime issues. Ns-3 has a nice reference counted object
231 * that can solve the problem so we use one of those to carry the stream
232 * around and deal with the lifetime issues.
233 *
234 * @param filename file name
235 * @param filemode file mode
236 * @returns a smart pointer to the output stream
237 */
238 Ptr<OutputStreamWrapper> CreateFileStream(std::string filename,
239 std::ios::openmode filemode = std::ios::out);
240
241 /**
242 * @brief Hook a trace source to the default enqueue operation trace sink that
243 * does not accept nor log a trace context.
244 *
245 * @param object object
246 * @param traceName trace source name
247 * @param stream output stream wrapper
248 */
249 template <typename T>
251 std::string traceName,
253
254 /**
255 * @brief Hook a trace source to the default enqueue operation trace sink that
256 * does accept and log a trace context.
257 *
258 * @param object object
259 * @param context context string
260 * @param traceName trace source name
261 * @param stream output stream wrapper
262 */
263 template <typename T>
265 std::string context,
266 std::string traceName,
268
269 /**
270 * @brief Hook a trace source to the default drop operation trace sink that
271 * does not accept nor log a trace context.
272 *
273 * @param object object
274 * @param traceName trace source name
275 * @param stream output stream wrapper
276 */
277 template <typename T>
279 std::string traceName,
281
282 /**
283 * @brief Hook a trace source to the default drop operation trace sink that
284 * does accept and log a trace context.
285 *
286 * @param object object
287 * @param context context string
288 * @param traceName trace source name
289 * @param stream output stream wrapper
290 */
291 template <typename T>
293 std::string context,
294 std::string traceName,
296
297 /**
298 * @brief Hook a trace source to the default dequeue operation trace sink
299 * that does not accept nor log a trace context.
300 *
301 * @param object object
302 * @param traceName trace source name
303 * @param stream output stream wrapper
304 */
305 template <typename T>
307 std::string traceName,
309
310 /**
311 * @brief Hook a trace source to the default dequeue operation trace sink
312 * that does accept and log a trace context.
313 *
314 * @param object object
315 * @param context context string
316 * @param traceName trace source name
317 * @param stream output stream wrapper
318 */
319 template <typename T>
321 std::string context,
322 std::string traceName,
324
325 /**
326 * @brief Hook a trace source to the default receive operation trace sink
327 * that does not accept nor log a trace context.
328 *
329 * @param object object
330 * @param traceName trace source name
331 * @param stream output stream wrapper
332 */
333 template <typename T>
335 std::string traceName,
337
338 /**
339 * @brief Hook a trace source to the default receive operation trace sink
340 * that does accept and log a trace context.
341 *
342 * @param object object
343 * @param context context string
344 * @param traceName trace source name
345 * @param stream output stream wrapper
346 */
347 template <typename T>
349 std::string context,
350 std::string traceName,
352
353 /**
354 * @brief Basic Enqueue default trace sink.
355 *
356 * When a packet has been sent to a device for transmission, the device is
357 * expected to place the packet onto a transmit queue even if it does not
358 * have to delay the packet at all, if only to trigger this event. This
359 * event will eventually translate into a '+' operation in the trace file.
360 *
361 * This is typically implemented by hooking the "TxQueue/Enqueue" trace hook
362 * in the device (actually the Queue in the device).
363 *
364 * @param file the output file
365 * @param p the packet
366 */
369
370 /**
371 * @brief Basic Enqueue default trace sink.
372 *
373 * When a packet has been sent to a device for transmission, the device is
374 * expected to place the packet onto a transmit queue even if it does not
375 * have to delay the packet at all, if only to trigger this event. This
376 * event will eventually translate into a '+' operation in the trace file.
377 *
378 * This is typically implemented by hooking the "TxQueue/Enqueue" trace hook
379 * in the device (actually the Queue in the device).
380 *
381 * @param file the output file
382 * @param context the context
383 * @param p the packet
384 */
386 std::string context,
388
389 /**
390 * @brief Basic Drop default trace sink.
391 *
392 * When a packet has been sent to a device for transmission, the device is
393 * expected to place the packet onto a transmit queue. If this queue is
394 * full the packet will be dropped. The device is expected to trigger an
395 * event to indicate that an outbound packet is being dropped. This event
396 * will eventually translate into a 'd' operation in the trace file.
397 *
398 * This is typically implemented by hooking the "TxQueue/Drop" trace hook
399 * in the device (actually the Queue in the device).
400 *
401 * @param file the output file
402 * @param p the packet
403 */
405
406 /**
407 * @brief Basic Drop default trace sink.
408 *
409 * When a packet has been sent to a device for transmission, the device is
410 * expected to place the packet onto a transmit queue. If this queue is
411 * full the packet will be dropped. The device is expected to trigger an
412 * event to indicate that an outbound packet is being dropped. This event
413 * will eventually translate into a 'd' operation in the trace file.
414 *
415 * This is typically implemented by hooking the "TxQueue/Drop" trace hook
416 * in the device (actually the Queue in the device).
417 *
418 * @param file the output file
419 * @param context the context
420 * @param p the packet
421 */
423 std::string context,
425
426 /**
427 * @brief Basic Dequeue default trace sink.
428 *
429 * When a packet has been sent to a device for transmission, the device is
430 * expected to place the packet onto a transmit queue even if it does not
431 * have to delay the packet at all. The device removes the packet from the
432 * transmit queue when the packet is ready to send, and this dequeue will
433 * fire a corresponding event. This event will eventually translate into a
434 * '-' operation in the trace file.
435 *
436 * This is typically implemented by hooking the "TxQueue/Dequeue" trace hook
437 * in the device (actually the Queue in the device).
438 *
439 * @param file the output file
440 * @param p the packet
441 */
444
445 /**
446 * @brief Basic Dequeue default trace sink.
447 *
448 * When a packet has been sent to a device for transmission, the device is
449 * expected to place the packet onto a transmit queue even if it does not
450 * have to delay the packet at all. The device removes the packet from the
451 * transmit queue when the packet is ready to send, and this dequeue will
452 * fire a corresponding event. This event will eventually translate into a
453 * '-' operation in the trace file.
454 *
455 * This is typically implemented by hooking the "TxQueue/Dequeue" trace hook
456 * in the device (actually the Queue in the device).
457 *
458 * @param file the output file
459 * @param context the context
460 * @param p the packet
461 */
463 std::string context,
465
466 /**
467 * @brief Basic Receive default trace sink.
468 *
469 * When a packet is received by a device for transmission, the device is
470 * expected to trigger this event to indicate the reception has occurred.
471 * This event will eventually translate into an 'r' operation in the trace
472 * file.
473 *
474 * This is typically implemented by hooking the "MacRx" trace hook in the
475 * device.
476 *
477 * @param file the output file
478 * @param p the packet
479 */
482
483 /**
484 * @brief Basic Receive default trace sink.
485 *
486 * When a packet is received by a device for transmission, the device is
487 * expected to trigger this event to indicate the reception has occurred.
488 * This event will eventually translate into an 'r' operation in the trace
489 * file.
490 *
491 * This is typically implemented by hooking the "MacRx" trace hook in the
492 * device.
493 *
494 * @param file the output file
495 * @param context the context
496 * @param p the packet
497 */
499 std::string context,
501};
502
503template <typename T>
504void
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
517template <typename T>
518void
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
532template <typename T>
533void
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
546template <typename T>
547void
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
561template <typename T>
562void
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
575template <typename T>
576void
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
590template <typename T>
591void
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
604template <typename T>
605void
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
619/**
620 * \brief Base class providing common user-level pcap operations for helpers
621 * representing net devices.
622 */
624{
625 public:
626 /**
627 * @brief Construct a PcapHelperForDevice
628 */
630 {
631 }
632
633 /**
634 * @brief Destroy a PcapHelperForDevice
635 */
637 {
638 }
639
640 /**
641 * @brief Enable pcap output the indicated net device.
642 *
643 * @param prefix Filename prefix to use for pcap files.
644 * @param nd Net device for which you want to enable tracing.
645 * @param promiscuous If true capture all possible packets available at the device.
646 * @param explicitFilename Treat the prefix as an explicit filename if true
647 */
648 virtual void EnablePcapInternal(std::string prefix,
650 bool promiscuous,
651 bool explicitFilename) = 0;
652
653 /**
654 * @brief Enable pcap output the indicated net device.
655 *
656 * @param prefix Filename prefix to use for pcap files.
657 * @param nd Net device for which you want to enable tracing.
658 * @param promiscuous If true capture all possible packets available at the device.
659 * @param explicitFilename Treat the prefix as an explicit filename if true
660 */
661 void EnablePcap(std::string prefix,
663 bool promiscuous = false,
664 bool explicitFilename = false);
665
666 /**
667 * @brief Enable pcap output the indicated net device using a device previously
668 * named using the ns-3 object name service.
669 *
670 * @param prefix filename prefix to use for pcap files.
671 * @param ndName The name of the net device in which you want to enable tracing.
672 * @param promiscuous If true capture all possible packets available at the device.
673 * @param explicitFilename Treat the prefix as an explicit filename if true
674 */
675 void EnablePcap(std::string prefix,
676 std::string ndName,
677 bool promiscuous = false,
678 bool explicitFilename = false);
679
680 /**
681 * @brief Enable pcap output on each device in the container which is of the
682 * appropriate type.
683 *
684 * @param prefix Filename prefix to use for pcap files.
685 * @param d container of devices of type ns3::CsmaNetDevice
686 * @param promiscuous If true capture all possible packets available at the device.
687 */
688 void EnablePcap(std::string prefix, NetDeviceContainer d, bool promiscuous = false);
689
690 /**
691 * @brief Enable pcap output on each device (which is of the appropriate type)
692 * in the nodes provided in the container.
693 *
694 * \param prefix Filename prefix to use for pcap files.
695 * \param n container of nodes.
696 * \param promiscuous If true capture all possible packets available at the device.
697 */
698 void EnablePcap(std::string prefix, NodeContainer n, bool promiscuous = false);
699
700 /**
701 * @brief Enable pcap output on the device specified by a global node-id (of
702 * a previously created node) and associated device-id.
703 *
704 * @param prefix Filename prefix to use for pcap files.
705 * @param nodeid the node id
706 * @param deviceid the device id
707 * @param promiscuous If true capture all possible packets available at the device.
708 */
709 void EnablePcap(std::string prefix,
710 uint32_t nodeid,
711 uint32_t deviceid,
712 bool promiscuous = false);
713
714 /**
715 * @brief Enable pcap output on each device (which is of the appropriate type)
716 * in the set of all nodes created in the simulation.
717 *
718 * @param prefix Filename prefix to use for pcap files.
719 * @param promiscuous If true capture all possible packets available at the device.
720 */
721 void EnablePcapAll(std::string prefix, bool promiscuous = false);
722};
723
724/**
725 * \brief Base class providing common user-level ascii trace operations for helpers
726 * representing net devices.
727 */
729{
730 public:
731 /**
732 * @brief Construct an AsciiTraceHelperForDevice.
733 */
735 {
736 }
737
738 /**
739 * @brief Destroy an AsciiTraceHelperForDevice.
740 */
742 {
743 }
744
745 /**
746 * @brief Enable ascii trace output on the indicated net device.
747 *
748 * The implementation is expected to use a provided Ptr<OutputStreamWrapper>
749 * if it is non-null. If the OutputStreamWrapper is null, the implementation
750 * is expected to use a provided prefix to construct a new file name for
751 * each net device using the rules described in the class overview.
752 *
753 * If the prefix is provided, there will be one file per net device created.
754 * In this case, adding a trace context to the file would be pointless, so
755 * the device implementation is expected to TraceConnectWithoutContext.
756 *
757 * If the output stream object is provided, there may be many different
758 * devices writing to a single file. In this case, the device adding a
759 * trace context could be important, so the device implementation is
760 * expected to TraceConnect.
761 *
762 * @param stream An OutputStreamWrapper representing an existing file to use
763 * when writing trace data.
764 * @param prefix Filename prefix to use for ascii trace files.
765 * @param nd Net device for which you want to enable tracing
766 * @param explicitFilename Treat the prefix as an explicit filename if true
767 */
769 std::string prefix,
771 bool explicitFilename) = 0;
772
773 /**
774 * @brief Enable ascii trace output on the indicated net device.
775 *
776 * @param prefix Filename prefix to use for ascii files.
777 * @param nd Net device for which you want to enable tracing.
778 * @param explicitFilename Treat the prefix as an explicit filename if true
779 */
780 void EnableAscii(std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
781
782 /**
783 * @brief Enable ascii trace output on the indicated net device.
784 *
785 * @param stream An OutputStreamWrapper representing an existing file to use
786 * when writing trace data.
787 * @param nd Net device for which you want to enable tracing.
788 */
790
791 /**
792 * @brief Enable ascii trace output the indicated net device using a device
793 * previously named using the ns-3 object name service.
794 *
795 * @param prefix filename prefix to use for ascii files.
796 * @param ndName The name of the net device in which you want to enable tracing.
797 * @param explicitFilename Treat the prefix as an explicit filename if true
798 */
799 void EnableAscii(std::string prefix, std::string ndName, bool explicitFilename = false);
800
801 /**
802 * @brief Enable ascii trace output the indicated net device using a device
803 * previously named using the ns-3 object name service.
804 *
805 * @param stream An OutputStreamWrapper representing an existing file to use
806 * when writing trace data.
807 * @param ndName The name of the net device in which you want to enable tracing.
808 */
809 void EnableAscii(Ptr<OutputStreamWrapper> stream, std::string ndName);
810
811 /**
812 * @brief Enable ascii trace output on each device in the container which is
813 * of the appropriate type.
814 *
815 * @param prefix Filename prefix to use for ascii files.
816 * @param d container of devices
817 */
818 void EnableAscii(std::string prefix, NetDeviceContainer d);
819
820 /**
821 * @brief Enable ascii trace output on each device in the container which is
822 * of the appropriate type.
823 *
824 * @param stream An OutputStreamWrapper representing an existing file to use
825 * when writing trace data.
826 * @param d container of devices
827 */
829
830 /**
831 * @brief Enable ascii trace output on each device (which is of the
832 * appropriate type) in the nodes provided in the container.
833 *
834 * \param prefix Filename prefix to use for ascii files.
835 * \param n container of nodes.
836 */
837 void EnableAscii(std::string prefix, NodeContainer n);
838
839 /**
840 * @brief Enable ascii trace output on each device (which is of the
841 * appropriate type) in the nodes provided in the container.
842 *
843 * @param stream An OutputStreamWrapper representing an existing file to use
844 * when writing trace data.
845 * \param n container of nodes.
846 */
848
849 /**
850 * @brief Enable ascii trace output on each device (which is of the
851 * appropriate type) in the set of all nodes created in the simulation.
852 *
853 * @param prefix Filename prefix to use for ascii files.
854 */
855 void EnableAsciiAll(std::string prefix);
856
857 /**
858 * @brief Enable ascii trace output on each device (which is of the
859 * appropriate type) in the set of all nodes created in the simulation.
860 *
861 * @param stream An OutputStreamWrapper representing an existing file to use
862 * when writing trace data.
863 */
865
866 /**
867 * @brief Enable ascii trace output on the device specified by a global
868 * node-id (of a previously created node) and associated device-id.
869 *
870 * @param prefix Filename prefix to use when creating ascii trace files
871 * @param nodeid The node identifier/number of the node on which to enable
872 * ascii tracing
873 * @param deviceid The device identifier/index of the device on which to enable
874 * ascii tracing
875 * @param explicitFilename Treat the prefix as an explicit filename if true
876 */
877 void EnableAscii(std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
878
879 /**
880 * @brief Enable ascii trace output on the device specified by a global
881 * node-id (of a previously created node) and associated device-id.
882 *
883 * @param stream An OutputStreamWrapper representing an existing file to use
884 * when writing trace data.
885 * @param nodeid The node identifier/number of the node on which to enable
886 * ascii tracing
887 * @param deviceid The device identifier/index of the device on which to enable
888 * ascii tracing
889 */
890 void EnableAscii(Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
891
892 private:
893 /**
894 * @brief Enable ascii trace output on the device specified by a global
895 * node-id (of a previously created node) and associated device-id (implementation)
896 *
897 * @param stream An OutputStreamWrapper representing an existing file to use
898 * when writing trace data.
899 * @param prefix Filename prefix to use for ascii trace files.
900 * @param nodeid The node identifier/number of the node on which to enable
901 * ascii tracing
902 * @param deviceid The device identifier/index of the device on which to enable
903 * ascii tracing
904 * @param explicitFilename Treat the prefix as an explicit filename if true
905 */
906
908 std::string prefix,
909 uint32_t nodeid,
910 uint32_t deviceid,
911 bool explicitFilename);
912
913 /**
914 * @brief Enable ascii trace output on each device (which is of the
915 * appropriate type) in the nodes provided in the container (implementation).
916 *
917 * @param stream An OutputStreamWrapper representing an existing file to use
918 * when writing trace data.
919 * @param prefix Filename prefix to use for ascii files.
920 * @param n container of nodes.
921 */
922 void EnableAsciiImpl(Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n);
923
924 /**
925 * @brief Enable ascii trace output on each device in the container which is
926 * of the appropriate type (implementation).
927 *
928 * @param stream An OutputStreamWrapper representing an existing file to use
929 * when writing trace data.
930 * @param prefix Filename prefix to use for ascii files.
931 * @param d container of devices
932 */
933 void EnableAsciiImpl(Ptr<OutputStreamWrapper> stream, std::string prefix, NetDeviceContainer d);
934
935 /**
936 * @brief Enable ascii trace output the indicated net device using a device
937 * previously named using the ns-3 object name service (implementation).
938 *
939 * @param stream An OutputStreamWrapper representing an existing file to use
940 * when writing trace data.
941 * @param prefix filename prefix to use for ascii files.
942 * @param ndName The name of the net device in which you want to enable tracing.
943 * @param explicitFilename Treat the prefix as an explicit filename if true
944 */
946 std::string prefix,
947 std::string ndName,
948 bool explicitFilename);
949
950 /**
951 * @brief Enable ascii trace output the indicated net device (implementation).
952 *
953 * @param stream An OutputStreamWrapper representing an existing file to use
954 * when writing trace data.
955 * @param prefix filename prefix to use for ascii files.
956 * @param nd Net device for which you want to enable tracing
957 * @param explicitFilename Treat the prefix as an explicit filename if true
958 */
960 std::string prefix,
962 bool explicitFilename);
963};
964
965} // namespace ns3
966
967#endif /* TRACE_HELPER_H */
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.