A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
internet-stack-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
8 */
9
11
16
17#include "ns3/arp-l3-protocol.h"
18#include "ns3/assert.h"
19#include "ns3/callback.h"
20#include "ns3/config.h"
21#include "ns3/global-router-interface.h"
22#include "ns3/icmpv6-l4-protocol.h"
23#include "ns3/ipv4-global-routing.h"
24#include "ns3/ipv4.h"
25#include "ns3/ipv6-extension-demux.h"
26#include "ns3/ipv6-extension-header.h"
27#include "ns3/ipv6-extension.h"
28#include "ns3/ipv6.h"
29#include "ns3/log.h"
30#include "ns3/names.h"
31#include "ns3/net-device.h"
32#include "ns3/node-list.h"
33#include "ns3/node.h"
34#include "ns3/object.h"
35#include "ns3/packet-socket-factory.h"
36#include "ns3/simulator.h"
37#include "ns3/string.h"
38#include "ns3/traffic-control-layer.h"
39
40#include <limits>
41#include <map>
42
43namespace ns3
44{
45
46NS_LOG_COMPONENT_DEFINE("InternetStackHelper");
47
48//
49// Historically, the only context written to ascii traces was the protocol.
50// Traces from the protocols include the interface, though. It is not
51// possible to really determine where an event originated without including
52// this. If you want the additional context information, define
53// INTERFACE_CONTEXT. If you want compatibility with the old-style traces
54// comment it out.
55//
56#define INTERFACE_CONTEXT
57
58//
59// Things are going to work differently here with respect to trace file handling
60// than in most places because the Tx and Rx trace sources we are interested in
61// are going to multiplex receive and transmit callbacks for all Ipv4 and
62// interface pairs through one callback. We want packets to or from each
63// distinct pair to go to an individual file, so we have got to demultiplex the
64// Ipv4 and interface pair into a corresponding Ptr<PcapFileWrapper> at the
65// callback.
66//
67// A complication in this situation is that the trace sources are hooked on
68// a protocol basis. There is no trace source hooked by an Ipv4 and interface
69// pair. This means that if we naively proceed to hook, say, a drop trace
70// for a given Ipv4 with interface 0, and then hook for Ipv4 with interface 1
71// we will hook the drop trace twice and get two callbacks per event. What
72// we need to do is to hook the event once, and that will result in a single
73// callback per drop event, and the trace source will provide the interface
74// which we filter on in the trace sink.
75//
76// The use of global maps allows this to continue to work properly even if
77// the helper is destroyed before the simulation completes. If the maps
78// are populated, the reference counting smart pointers to
79// OutputStreamWrapper and PcapFileWrapper will cause those objects to be
80// destroyed at static object destruction time; i.e., the simulator does
81// not explicitly clear these maps before the program ends.
82//
83typedef std::pair<uint32_t, uint32_t> InterfacePairIpv4; //!< Ipv4/interface pair
84typedef std::map<InterfacePairIpv4, Ptr<PcapFileWrapper>>
85 InterfaceFileMapIpv4; //!< Ipv4/interface and Pcap file wrapper container
86typedef std::map<InterfacePairIpv4, Ptr<OutputStreamWrapper>>
87 InterfaceStreamMapIpv4; //!< Ipv4/interface and output stream container
88
90 g_interfaceFileMapIpv4; //!< A mapping of Ipv4/interface pairs to pcap files
92 g_interfaceStreamMapIpv4; //!< A mapping of Ipv4/interface pairs to ascii streams
93
94typedef std::pair<uint32_t, uint32_t> InterfacePairIpv6; //!< Ipv6/interface pair
95typedef std::map<InterfacePairIpv6, Ptr<PcapFileWrapper>>
96 InterfaceFileMapIpv6; //!< Ipv6/interface and Pcap file wrapper container
97typedef std::map<InterfacePairIpv6, Ptr<OutputStreamWrapper>>
98 InterfaceStreamMapIpv6; //!< Ipv6/interface and output stream container
99
101 g_interfaceFileMapIpv6; //!< A mapping of Ipv6/interface pairs to pcap files
103 g_interfaceStreamMapIpv6; //!< A mapping of Ipv6/interface pairs to pcap files
104
106 : m_routing(nullptr),
107 m_routingv6(nullptr),
108 m_ipv4Enabled(true),
109 m_ipv6Enabled(true),
110 m_ipv4ArpJitterEnabled(true),
111 m_ipv6NsRsJitterEnabled(true)
112
113{
114 Initialize();
115}
116
117// private method called by both constructor and Reset ()
118void
120{
121 Ipv4StaticRoutingHelper staticRouting;
122 Ipv4GlobalRoutingHelper globalRouting;
123 Ipv4ListRoutingHelper listRouting;
124 Ipv6StaticRoutingHelper staticRoutingv6;
125 listRouting.Add(staticRouting, 0);
126 listRouting.Add(globalRouting, -10);
127 SetRoutingHelper(listRouting);
128 SetRoutingHelper(staticRoutingv6);
129}
130
136
146
149{
150 if (this == &o)
151 {
152 return *this;
153 }
154 m_routing = o.m_routing->Copy();
156 return *this;
157}
158
159void
161{
162 delete m_routing;
163 m_routing = nullptr;
164 delete m_routingv6;
165 m_routingv6 = nullptr;
166 m_ipv4Enabled = true;
167 m_ipv6Enabled = true;
170 Initialize();
171}
172
173void
175{
176 delete m_routing;
177 m_routing = routing.Copy();
178}
179
180void
182{
183 delete m_routingv6;
184 m_routingv6 = routing.Copy();
185}
186
187void
189{
190 m_ipv4Enabled = enable;
191}
192
193void
195{
196 m_ipv6Enabled = enable;
197}
198
199void
204
205void
210
211int64_t
213{
214 int64_t currentStream = stream;
215 for (auto i = c.Begin(); i != c.End(); ++i)
216 {
217 Ptr<Node> node = *i;
218 Ptr<GlobalRouter> router = node->GetObject<GlobalRouter>();
219 if (router)
220 {
221 Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol();
222 if (gr)
223 {
224 currentStream += gr->AssignStreams(currentStream);
225 }
226 }
227 Ptr<Ipv6ExtensionDemux> demux = node->GetObject<Ipv6ExtensionDemux>();
228 if (demux)
229 {
231 NS_ASSERT(fe); // should always exist in the demux
232 currentStream += fe->AssignStreams(currentStream);
233 }
234 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
235 if (ipv4)
236 {
237 Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol>();
238 if (arpL3Protocol)
239 {
240 currentStream += arpL3Protocol->AssignStreams(currentStream);
241 }
242 }
243 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
244 if (ipv6)
245 {
246 Ptr<Icmpv6L4Protocol> icmpv6L4Protocol = ipv6->GetObject<Icmpv6L4Protocol>();
247 if (icmpv6L4Protocol)
248 {
249 currentStream += icmpv6L4Protocol->AssignStreams(currentStream);
250 }
251 }
252 }
253 return (currentStream - stream);
254}
255
256void
258{
259 for (auto i = c.Begin(); i != c.End(); ++i)
260 {
261 Install(*i);
262 }
263}
264
265void
270
271void
273{
274 TypeId tid = TypeId::LookupByName(typeId);
275 if (node->GetObject<Object>(tid))
276 {
277 return;
278 }
279
280 ObjectFactory factory;
281 factory.SetTypeId(typeId);
282 Ptr<Object> protocol = factory.Create<Object>();
283 node->AggregateObject(protocol);
284}
285
286void
288{
289 if (m_ipv4Enabled)
290 {
291 /* IPv4 stack */
292 CreateAndAggregateObjectFromTypeId(node, "ns3::ArpL3Protocol");
293 CreateAndAggregateObjectFromTypeId(node, "ns3::Ipv4L3Protocol");
294 CreateAndAggregateObjectFromTypeId(node, "ns3::Icmpv4L4Protocol");
296 {
297 Ptr<ArpL3Protocol> arp = node->GetObject<ArpL3Protocol>();
298 NS_ASSERT(arp);
299 arp->SetAttribute("RequestJitter",
300 StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
301 }
302
303 // Set routing
304 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
305 if (!ipv4->GetRoutingProtocol())
306 {
307 Ptr<Ipv4RoutingProtocol> ipv4Routing = m_routing->Create(node);
308 ipv4->SetRoutingProtocol(ipv4Routing);
309 }
310 }
311
312 if (m_ipv6Enabled)
313 {
314 /* IPv6 stack */
315 CreateAndAggregateObjectFromTypeId(node, "ns3::Ipv6L3Protocol");
316 CreateAndAggregateObjectFromTypeId(node, "ns3::Icmpv6L4Protocol");
318 {
319 Ptr<Icmpv6L4Protocol> icmpv6l4 = node->GetObject<Icmpv6L4Protocol>();
320 NS_ASSERT(icmpv6l4);
321 icmpv6l4->SetAttribute("SolicitationJitter",
322 StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
323 }
324 // Set routing
325 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
326 if (!ipv6->GetRoutingProtocol())
327 {
328 Ptr<Ipv6RoutingProtocol> ipv6Routing = m_routingv6->Create(node);
329 ipv6->SetRoutingProtocol(ipv6Routing);
330 }
331 /* register IPv6 extensions and options */
332 ipv6->RegisterExtensions();
333 ipv6->RegisterOptions();
334 }
335
337 {
338 CreateAndAggregateObjectFromTypeId(node, "ns3::TrafficControlLayer");
339 CreateAndAggregateObjectFromTypeId(node, "ns3::UdpL4Protocol");
340 CreateAndAggregateObjectFromTypeId(node, "ns3::TcpL4Protocol");
341 if (!node->GetObject<PacketSocketFactory>())
342 {
344 node->AggregateObject(factory);
345 }
346 }
347
348 if (m_ipv4Enabled)
349 {
350 Ptr<ArpL3Protocol> arp = node->GetObject<ArpL3Protocol>();
351 Ptr<TrafficControlLayer> tc = node->GetObject<TrafficControlLayer>();
352 NS_ASSERT(arp);
353 NS_ASSERT(tc);
354 arp->SetTrafficControl(tc);
355 }
356}
357
358void
359InternetStackHelper::Install(std::string nodeName) const
360{
361 Ptr<Node> node = Names::Find<Node>(nodeName);
362 Install(node);
363}
364
365/**
366 * @brief Sync function for IPv4 packet - Pcap output
367 * @param p smart pointer to the packet
368 * @param ipv4 smart pointer to the node's IPv4 stack
369 * @param interface incoming interface
370 */
371static void
373{
374 NS_LOG_FUNCTION(p << ipv4 << interface);
375
376 //
377 // Since trace sources are independent of interface, if we hook a source
378 // on a particular protocol we will get traces for all of its interfaces.
379 // We need to filter this to only report interfaces for which the user
380 // has expressed interest.
381 //
382 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
383 if (g_interfaceFileMapIpv4.find(pair) == g_interfaceFileMapIpv4.end())
384 {
385 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
386 return;
387 }
388
390 file->Write(Simulator::Now(), p);
391}
392
393bool
395{
396 auto id = ipv4->GetObject<Node>()->GetId();
397
398 for (auto i = g_interfaceFileMapIpv4.begin(); i != g_interfaceFileMapIpv4.end(); ++i)
399 {
400 if ((*i).first.first == id)
401 {
402 return true;
403 }
404 }
405 return false;
406}
407
408void
410 Ptr<Ipv4> ipv4,
411 uint32_t interface,
412 bool explicitFilename)
413{
414 NS_LOG_FUNCTION(prefix << ipv4 << interface);
415
416 if (!m_ipv4Enabled)
417 {
418 NS_LOG_INFO("Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
419 return;
420 }
421
422 //
423 // We have to create a file and a mapping from protocol/interface to file
424 // irrespective of how many times we want to trace a particular protocol.
425 //
426 PcapHelper pcapHelper;
427
428 std::string filename;
429 if (explicitFilename)
430 {
431 filename = prefix;
432 }
433 else
434 {
435 filename = pcapHelper.GetFilenameFromInterfacePair(prefix, ipv4, interface);
436 }
437
438 Ptr<PcapFileWrapper> file = pcapHelper.CreateFile(filename, std::ios::out, PcapHelper::DLT_RAW);
439
440 //
441 // However, we only hook the trace source once to avoid multiple trace sink
442 // calls per event (connect is independent of interface).
443 //
444 if (!PcapHooked(ipv4))
445 {
446 //
447 // Ptr<Ipv4> is aggregated to node and Ipv4L3Protocol is aggregated to
448 // node so we can get to Ipv4L3Protocol through Ipv4.
449 //
450 Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol>();
451 NS_ASSERT_MSG(ipv4L3Protocol,
452 "InternetStackHelper::EnablePcapIpv4Internal(): "
453 "m_ipv4Enabled and ipv4L3Protocol inconsistent");
454
455 bool result =
456 ipv4L3Protocol->TraceConnectWithoutContext("Tx", MakeCallback(&Ipv4L3ProtocolRxTxSink));
457 NS_ASSERT_MSG(result == true,
458 "InternetStackHelper::EnablePcapIpv4Internal(): "
459 "Unable to connect ipv4L3Protocol \"Tx\"");
460
461 result =
462 ipv4L3Protocol->TraceConnectWithoutContext("Rx", MakeCallback(&Ipv4L3ProtocolRxTxSink));
463 NS_ASSERT_MSG(result == true,
464 "InternetStackHelper::EnablePcapIpv4Internal(): "
465 "Unable to connect ipv4L3Protocol \"Rx\"");
466 }
467
468 g_interfaceFileMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] = file;
469}
470
471/**
472 * @brief Sync function for IPv6 packet - Pcap output
473 * @param p smart pointer to the packet
474 * @param ipv6 smart pointer to the node's IPv6 stack
475 * @param interface incoming interface
476 */
477static void
479{
480 NS_LOG_FUNCTION(p << ipv6 << interface);
481
482 //
483 // Since trace sources are independent of interface, if we hook a source
484 // on a particular protocol we will get traces for all of its interfaces.
485 // We need to filter this to only report interfaces for which the user
486 // has expressed interest.
487 //
488 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
489 if (g_interfaceFileMapIpv6.find(pair) == g_interfaceFileMapIpv6.end())
490 {
491 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
492 return;
493 }
494
496 file->Write(Simulator::Now(), p);
497}
498
499bool
501{
502 auto id = ipv6->GetObject<Node>()->GetId();
503
504 for (auto i = g_interfaceFileMapIpv6.begin(); i != g_interfaceFileMapIpv6.end(); ++i)
505 {
506 if ((*i).first.first == id)
507 {
508 return true;
509 }
510 }
511 return false;
512}
513
514void
516 Ptr<Ipv6> ipv6,
517 uint32_t interface,
518 bool explicitFilename)
519{
520 NS_LOG_FUNCTION(prefix << ipv6 << interface);
521
522 if (!m_ipv6Enabled)
523 {
524 NS_LOG_INFO("Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
525 return;
526 }
527
528 //
529 // We have to create a file and a mapping from protocol/interface to file
530 // irrespective of how many times we want to trace a particular protocol.
531 //
532 PcapHelper pcapHelper;
533
534 std::string filename;
535 if (explicitFilename)
536 {
537 filename = prefix;
538 }
539 else
540 {
541 filename = pcapHelper.GetFilenameFromInterfacePair(prefix, ipv6, interface);
542 }
543
544 Ptr<PcapFileWrapper> file = pcapHelper.CreateFile(filename, std::ios::out, PcapHelper::DLT_RAW);
545
546 //
547 // However, we only hook the trace source once to avoid multiple trace sink
548 // calls per event (connect is independent of interface).
549 //
550 if (!PcapHooked(ipv6))
551 {
552 //
553 // Ptr<Ipv6> is aggregated to node and Ipv6L3Protocol is aggregated to
554 // node so we can get to Ipv6L3Protocol through Ipv6.
555 //
556 Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol>();
557 NS_ASSERT_MSG(ipv6L3Protocol,
558 "InternetStackHelper::EnablePcapIpv6Internal(): "
559 "m_ipv6Enabled and ipv6L3Protocol inconsistent");
560
561 bool result =
562 ipv6L3Protocol->TraceConnectWithoutContext("Tx", MakeCallback(&Ipv6L3ProtocolRxTxSink));
563 NS_ASSERT_MSG(result == true,
564 "InternetStackHelper::EnablePcapIpv6Internal(): "
565 "Unable to connect ipv6L3Protocol \"Tx\"");
566
567 result =
568 ipv6L3Protocol->TraceConnectWithoutContext("Rx", MakeCallback(&Ipv6L3ProtocolRxTxSink));
569 NS_ASSERT_MSG(result == true,
570 "InternetStackHelper::EnablePcapIpv6Internal(): "
571 "Unable to connect ipv6L3Protocol \"Rx\"");
572 }
573
574 g_interfaceFileMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] = file;
575}
576
577/**
578 * @brief Sync function for IPv4 dropped packet - Ascii output
579 * @param stream the output stream
580 * @param header IPv4 header
581 * @param packet smart pointer to the packet
582 * @param reason the reason for the dropping
583 * @param ipv4 smart pointer to the node's IPv4 stack
584 * @param interface incoming interface
585 */
586static void
588 const Ipv4Header& header,
589 Ptr<const Packet> packet,
591 Ptr<Ipv4> ipv4,
592 uint32_t interface)
593{
594 //
595 // Since trace sources are independent of interface, if we hook a source
596 // on a particular protocol we will get traces for all of its interfaces.
597 // We need to filter this to only report interfaces for which the user
598 // has expressed interest.
599 //
600 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
602 {
603 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
604 return;
605 }
606
607 Ptr<Packet> p = packet->Copy();
608 p->AddHeader(header);
609 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << *p << std::endl;
610}
611
612/**
613 * @brief Sync function for IPv4 transmitted packet - Ascii output
614 * @param stream the output stream
615 * @param packet smart pointer to the packet
616 * @param ipv4 smart pointer to the node's IPv4 stack
617 * @param interface incoming interface
618 */
619static void
621 Ptr<const Packet> packet,
622 Ptr<Ipv4> ipv4,
623 uint32_t interface)
624{
625 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
626
628 {
629 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
630 return;
631 }
632 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
633}
634
635/**
636 * @brief Sync function for IPv4 received packet - Ascii output
637 * @param stream the output stream
638 * @param packet smart pointer to the packet
639 * @param ipv4 smart pointer to the node's IPv4 stack
640 * @param interface incoming interface
641 */
642static void
644 Ptr<const Packet> packet,
645 Ptr<Ipv4> ipv4,
646 uint32_t interface)
647{
648 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
650 {
651 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
652 return;
653 }
654
655 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
656}
657
658/**
659 * @brief Sync function for IPv4 dropped packet - Ascii output
660 * @param stream the output stream
661 * @param context the context
662 * @param header IPv4 header
663 * @param packet smart pointer to the packet
664 * @param reason the reason for the dropping
665 * @param ipv4 smart pointer to the node's IPv4 stack
666 * @param interface incoming interface
667 */
668static void
670 std::string context,
671 const Ipv4Header& header,
672 Ptr<const Packet> packet,
674 Ptr<Ipv4> ipv4,
675 uint32_t interface)
676{
677 //
678 // Since trace sources are independent of interface, if we hook a source
679 // on a particular protocol we will get traces for all of its interfaces.
680 // We need to filter this to only report interfaces for which the user
681 // has expressed interest.
682 //
683 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
685 {
686 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
687 return;
688 }
689
690 Ptr<Packet> p = packet->Copy();
691 p->AddHeader(header);
692#ifdef INTERFACE_CONTEXT
693 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << "("
694 << interface << ") " << *p << std::endl;
695#else
696 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << " " << *p
697 << std::endl;
698#endif
699}
700
701/**
702 * @brief Sync function for IPv4 transmitted packet - Ascii output
703 * @param stream the output stream
704 * @param context the context
705 * @param packet smart pointer to the packet
706 * @param ipv4 smart pointer to the node's IPv4 stack
707 * @param interface incoming interface
708 */
709static void
711 std::string context,
712 Ptr<const Packet> packet,
713 Ptr<Ipv4> ipv4,
714 uint32_t interface)
715{
716 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
718 {
719 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
720 return;
721 }
722
723#ifdef INTERFACE_CONTEXT
724 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << "("
725 << interface << ") " << *packet << std::endl;
726#else
727 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << " "
728 << *packet << std::endl;
729#endif
730}
731
732/**
733 * @brief Sync function for IPv4 received packet - Ascii output
734 * @param stream the output stream
735 * @param context the context
736 * @param packet smart pointer to the packet
737 * @param ipv4 smart pointer to the node's IPv4 stack
738 * @param interface incoming interface
739 */
740static void
742 std::string context,
743 Ptr<const Packet> packet,
744 Ptr<Ipv4> ipv4,
745 uint32_t interface)
746{
747 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
749 {
750 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
751 return;
752 }
753
754#ifdef INTERFACE_CONTEXT
755 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << "("
756 << interface << ") " << *packet << std::endl;
757#else
758 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << " "
759 << *packet << std::endl;
760#endif
761}
762
763bool
765{
766 auto id = ipv4->GetObject<Node>()->GetId();
767
768 for (auto i = g_interfaceStreamMapIpv4.begin(); i != g_interfaceStreamMapIpv4.end(); ++i)
769 {
770 if ((*i).first.first == id)
771 {
772 return true;
773 }
774 }
775 return false;
776}
777
778void
780 std::string prefix,
781 Ptr<Ipv4> ipv4,
782 uint32_t interface,
783 bool explicitFilename)
784{
785 if (!m_ipv4Enabled)
786 {
787 NS_LOG_INFO("Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
788 return;
789 }
790
791 //
792 // Our trace sinks are going to use packet printing, so we have to
793 // make sure that is turned on.
794 //
796
797 //
798 // If we are not provided an OutputStreamWrapper, we are expected to create
799 // one using the usual trace filename conventions and hook WithoutContext
800 // since there will be one file per context and therefore the context would
801 // be redundant.
802 //
803 if (!stream)
804 {
805 //
806 // Set up an output stream object to deal with private ofstream copy
807 // constructor and lifetime issues. Let the helper decide the actual
808 // name of the file given the prefix.
809 //
810 // We have to create a stream and a mapping from protocol/interface to
811 // stream irrespective of how many times we want to trace a particular
812 // protocol.
813 //
814 AsciiTraceHelper asciiTraceHelper;
815
816 std::string filename;
817 if (explicitFilename)
818 {
819 filename = prefix;
820 }
821 else
822 {
823 filename = asciiTraceHelper.GetFilenameFromInterfacePair(prefix, ipv4, interface);
824 }
825
826 Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream(filename);
827
828 //
829 // However, we only hook the trace sources once to avoid multiple trace sink
830 // calls per event (connect is independent of interface).
831 //
832 if (!AsciiHooked(ipv4))
833 {
834 //
835 // We can use the default drop sink for the ArpL3Protocol since it has
836 // the usual signature. We can get to the Ptr<ArpL3Protocol> through
837 // our Ptr<Ipv4> since they must both be aggregated to the same node.
838 //
839 Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol>();
840 asciiTraceHelper.HookDefaultDropSinkWithoutContext<ArpL3Protocol>(arpL3Protocol,
841 "Drop",
842 theStream);
843
844 //
845 // The drop sink for the Ipv4L3Protocol uses a different signature than
846 // the default sink, so we have to cook one up for ourselves. We can get
847 // to the Ptr<Ipv4L3Protocol> through our Ptr<Ipv4> since they must both
848 // be aggregated to the same node.
849 //
850 Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol>();
851 bool result = ipv4L3Protocol->TraceConnectWithoutContext(
852 "Drop",
854 NS_ASSERT_MSG(result == true,
855 "InternetStackHelper::EnableAsciiIpv4Internal(): "
856 "Unable to connect ipv4L3Protocol \"Drop\"");
857 result = ipv4L3Protocol->TraceConnectWithoutContext(
858 "Tx",
860 NS_ASSERT_MSG(result == true,
861 "InternetStackHelper::EnableAsciiIpv4Internal(): "
862 "Unable to connect ipv4L3Protocol \"Tx\"");
863 result = ipv4L3Protocol->TraceConnectWithoutContext(
864 "Rx",
866 NS_ASSERT_MSG(result == true,
867 "InternetStackHelper::EnableAsciiIpv4Internal(): "
868 "Unable to connect ipv4L3Protocol \"Rx\"");
869 }
870
871 g_interfaceStreamMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] =
872 theStream;
873 return;
874 }
875
876 //
877 // If we are provided an OutputStreamWrapper, we are expected to use it, and
878 // to provide a context. We are free to come up with our own context if we
879 // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
880 // compatibility and simplicity, we just use Config::Connect and let it deal
881 // with the context.
882 //
883 // We need to associate the ipv4/interface with a stream to express interest
884 // in tracing events on that pair, however, we only hook the trace sources
885 // once to avoid multiple trace sink calls per event (connect is independent
886 // of interface).
887 //
888 if (!AsciiHooked(ipv4))
889 {
890 Ptr<Node> node = ipv4->GetObject<Node>();
891 std::ostringstream oss;
892
893 //
894 // For the ARP Drop, we are going to use the default trace sink provided by
895 // the ascii trace helper. There is actually no AsciiTraceHelper in sight
896 // here, but the default trace sinks are actually publicly available static
897 // functions that are always there waiting for just such a case.
898 //
899 oss << "/NodeList/" << node->GetId() << "/$ns3::ArpL3Protocol/Drop";
900 Config::Connect(oss.str(),
902
903 //
904 // This has all kinds of parameters coming with, so we have to cook up our
905 // own sink.
906 //
907 oss.str("");
908 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Drop";
910 oss.str("");
911 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Tx";
913 oss.str("");
914 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Rx";
916 }
917
918 g_interfaceStreamMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] = stream;
919}
920
921/**
922 * @brief Sync function for IPv6 dropped packet - Ascii output
923 * @param stream the output stream
924 * @param header IPv6 header
925 * @param packet smart pointer to the packet
926 * @param reason the reason for the dropping
927 * @param ipv6 smart pointer to the node's IPv6 stack
928 * @param interface incoming interface
929 */
930static void
932 const Ipv6Header& header,
933 Ptr<const Packet> packet,
935 Ptr<Ipv6> ipv6,
936 uint32_t interface)
937{
938 //
939 // Since trace sources are independent of interface, if we hook a source
940 // on a particular protocol we will get traces for all of its interfaces.
941 // We need to filter this to only report interfaces for which the user
942 // has expressed interest.
943 //
944 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
946 {
947 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
948 return;
949 }
950
951 Ptr<Packet> p = packet->Copy();
952 p->AddHeader(header);
953 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << *p << std::endl;
954}
955
956/**
957 * @brief Sync function for IPv6 transmitted packet - Ascii output
958 * @param stream the output stream
959 * @param packet smart pointer to the packet
960 * @param ipv6 smart pointer to the node's IPv6 stack
961 * @param interface incoming interface
962 */
963static void
965 Ptr<const Packet> packet,
966 Ptr<Ipv6> ipv6,
967 uint32_t interface)
968{
969 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
971 {
972 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
973 return;
974 }
975
976 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
977}
978
979/**
980 * @brief Sync function for IPv6 received packet - Ascii output
981 * @param stream the output stream
982 * @param packet smart pointer to the packet
983 * @param ipv6 smart pointer to the node's IPv6 stack
984 * @param interface incoming interface
985 */
986static void
988 Ptr<const Packet> packet,
989 Ptr<Ipv6> ipv6,
990 uint32_t interface)
991{
992 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
994 {
995 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
996 return;
997 }
998
999 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
1000}
1001
1002/**
1003 * @brief Sync function for IPv6 dropped packet - Ascii output
1004 * @param stream the output stream
1005 * @param context the context
1006 * @param header IPv6 header
1007 * @param packet smart pointer to the packet
1008 * @param reason the reason for the dropping
1009 * @param ipv6 smart pointer to the node's IPv6 stack
1010 * @param interface incoming interface
1011 */
1012static void
1014 std::string context,
1015 const Ipv6Header& header,
1016 Ptr<const Packet> packet,
1018 Ptr<Ipv6> ipv6,
1019 uint32_t interface)
1020{
1021 //
1022 // Since trace sources are independent of interface, if we hook a source
1023 // on a particular protocol we will get traces for all of its interfaces.
1024 // We need to filter this to only report interfaces for which the user
1025 // has expressed interest.
1026 //
1027 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1028 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1029 {
1030 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1031 return;
1032 }
1033
1034 Ptr<Packet> p = packet->Copy();
1035 p->AddHeader(header);
1036#ifdef INTERFACE_CONTEXT
1037 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << "("
1038 << interface << ") " << *p << std::endl;
1039#else
1040 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << " " << *p
1041 << std::endl;
1042#endif
1043}
1044
1045/**
1046 * @brief Sync function for IPv6 transmitted packet - Ascii output
1047 * @param stream the output stream
1048 * @param context the context
1049 * @param packet smart pointer to the packet
1050 * @param ipv6 smart pointer to the node's IPv6 stack
1051 * @param interface incoming interface
1052 */
1053static void
1055 std::string context,
1056 Ptr<const Packet> packet,
1057 Ptr<Ipv6> ipv6,
1058 uint32_t interface)
1059{
1060 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1061 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1062 {
1063 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1064 return;
1065 }
1066
1067#ifdef INTERFACE_CONTEXT
1068 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << "("
1069 << interface << ") " << *packet << std::endl;
1070#else
1071 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << " "
1072 << *packet << std::endl;
1073#endif
1074}
1075
1076/**
1077 * @brief Sync function for IPv6 received packet - Ascii output
1078 * @param stream the output stream
1079 * @param context the context
1080 * @param packet smart pointer to the packet
1081 * @param ipv6 smart pointer to the node's IPv6 stack
1082 * @param interface incoming interface
1083 */
1084static void
1086 std::string context,
1087 Ptr<const Packet> packet,
1088 Ptr<Ipv6> ipv6,
1089 uint32_t interface)
1090{
1091 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1092 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1093 {
1094 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1095 return;
1096 }
1097
1098#ifdef INTERFACE_CONTEXT
1099 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << "("
1100 << interface << ") " << *packet << std::endl;
1101#else
1102 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << " "
1103 << *packet << std::endl;
1104#endif
1105}
1106
1107bool
1109{
1110 auto id = ipv6->GetObject<Node>()->GetId();
1111
1112 for (auto i = g_interfaceStreamMapIpv6.begin(); i != g_interfaceStreamMapIpv6.end(); ++i)
1113 {
1114 if ((*i).first.first == id)
1115 {
1116 return true;
1117 }
1118 }
1119 return false;
1120}
1121
1122void
1124 std::string prefix,
1125 Ptr<Ipv6> ipv6,
1126 uint32_t interface,
1127 bool explicitFilename)
1128{
1129 if (!m_ipv6Enabled)
1130 {
1131 NS_LOG_INFO("Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1132 return;
1133 }
1134
1135 //
1136 // Our trace sinks are going to use packet printing, so we have to
1137 // make sure that is turned on.
1138 //
1140
1141 //
1142 // If we are not provided an OutputStreamWrapper, we are expected to create
1143 // one using the usual trace filename conventions and do a hook WithoutContext
1144 // since there will be one file per context and therefore the context would
1145 // be redundant.
1146 //
1147 if (!stream)
1148 {
1149 //
1150 // Set up an output stream object to deal with private ofstream copy
1151 // constructor and lifetime issues. Let the helper decide the actual
1152 // name of the file given the prefix.
1153 //
1154 // We have to create a stream and a mapping from protocol/interface to
1155 // stream irrespective of how many times we want to trace a particular
1156 // protocol.
1157 //
1158 AsciiTraceHelper asciiTraceHelper;
1159
1160 std::string filename;
1161 if (explicitFilename)
1162 {
1163 filename = prefix;
1164 }
1165 else
1166 {
1167 filename = asciiTraceHelper.GetFilenameFromInterfacePair(prefix, ipv6, interface);
1168 }
1169
1170 Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream(filename);
1171
1172 //
1173 // However, we only hook the trace sources once to avoid multiple trace sink
1174 // calls per event (connect is independent of interface).
1175 //
1176 if (!AsciiHooked(ipv6))
1177 {
1178 //
1179 // The drop sink for the Ipv6L3Protocol uses a different signature than
1180 // the default sink, so we have to cook one up for ourselves. We can get
1181 // to the Ptr<Ipv6L3Protocol> through our Ptr<Ipv6> since they must both
1182 // be aggregated to the same node.
1183 //
1184 Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol>();
1185 bool result = ipv6L3Protocol->TraceConnectWithoutContext(
1186 "Drop",
1188 NS_ASSERT_MSG(result == true,
1189 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1190 "Unable to connect ipv6L3Protocol \"Drop\"");
1191 result = ipv6L3Protocol->TraceConnectWithoutContext(
1192 "Tx",
1194 NS_ASSERT_MSG(result == true,
1195 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1196 "Unable to connect ipv6L3Protocol \"Tx\"");
1197 result = ipv6L3Protocol->TraceConnectWithoutContext(
1198 "Rx",
1200 NS_ASSERT_MSG(result == true,
1201 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1202 "Unable to connect ipv6L3Protocol \"Rx\"");
1203 }
1204
1205 g_interfaceStreamMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] =
1206 theStream;
1207 return;
1208 }
1209
1210 //
1211 // If we are provided an OutputStreamWrapper, we are expected to use it, and
1212 // to provide a context. We are free to come up with our own context if we
1213 // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
1214 // compatibility and simplicity, we just use Config::Connect and let it deal
1215 // with the context.
1216 //
1217 // We need to associate the ipv4/interface with a stream to express interest
1218 // in tracing events on that pair, however, we only hook the trace sources
1219 // once to avoid multiple trace sink calls per event (connect is independent
1220 // of interface).
1221 //
1222 if (!AsciiHooked(ipv6))
1223 {
1224 Ptr<Node> node = ipv6->GetObject<Node>();
1225 std::ostringstream oss;
1226
1227 oss.str("");
1228 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Drop";
1230 oss.str("");
1231 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Tx";
1233 oss.str("");
1234 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Rx";
1236 }
1237
1238 g_interfaceStreamMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] = stream;
1239}
1240
1241} // namespace ns3
An implementation of the ARP protocol.
Manage ASCII trace files for device models.
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...
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...
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.
An interface aggregated to a node to provide global routing info.
An implementation of the ICMPv6 protocol.
aggregate IP/TCP/UDP functionality to existing Nodes.
void EnablePcapIpv6Internal(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename) override
Enable pcap output the indicated Ipv6 and interface pair.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetIpv4ArpJitter(bool enable)
Enable/disable IPv4 ARP Jitter.
void EnableAsciiIpv4Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename) override
Enable ascii trace output on the indicated Ipv4 and interface pair.
bool m_ipv6Enabled
IPv6 install state (enabled/disabled) ?
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
bool m_ipv6NsRsJitterEnabled
IPv6 IPv6 NS and RS Jitter state (enabled/disabled) ?
bool AsciiHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to an ascii output stream
bool m_ipv4Enabled
IPv4 install state (enabled/disabled) ?
const Ipv4RoutingHelper * m_routing
IPv4 routing helper.
void InstallAll() const
Aggregate IPv4, IPv6, UDP, and TCP stacks to all nodes in the simulation.
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
static void CreateAndAggregateObjectFromTypeId(Ptr< Node > node, const std::string typeId)
create an object from its TypeId and aggregates it to the node.
void Initialize()
Initialize the helper to its default values.
void SetIpv6NsRsJitter(bool enable)
Enable/disable IPv6 NS and RS Jitter.
bool PcapHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to a Pcap wrapper
void EnablePcapIpv4Internal(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename) override
Enable pcap output the indicated Ipv4 and interface pair.
bool m_ipv4ArpJitterEnabled
IPv4 ARP Jitter state (enabled/disabled) ?
const Ipv6RoutingHelper * m_routingv6
IPv6 routing helper.
InternetStackHelper & operator=(const InternetStackHelper &o)
Copy constructor.
InternetStackHelper()
Create a new InternetStackHelper which uses a mix of static routing and global routing by default.
void Reset()
Return helper internal state to that of a newly constructed one.
~InternetStackHelper() override
Destroy the InternetStackHelper.
void EnableAsciiIpv6Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename) override
Enable ascii trace output on the indicated Ipv6 and interface pair.
Helper class that adds ns3::Ipv4GlobalRouting objects.
Packet header for IPv4.
Definition ipv4-header.h:23
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
Implement the IPv4 layer.
DropReason
Reason why a packet has been dropped.
Helper class that adds ns3::Ipv4ListRouting objects.
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
a factory to create ns3::Ipv4RoutingProtocol objects
virtual Ipv4RoutingHelper * Copy() const =0
virtual constructor
virtual Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const =0
Helper class that adds ns3::Ipv4StaticRouting objects.
Demultiplexes IPv6 extensions.
static const uint8_t EXT_NUMBER
Fragmentation extension number.
Packet header for IPv6.
Definition ipv6-header.h:24
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
IPv6 layer implementation.
DropReason
Reason why a packet has been dropped.
A factory to create ns3::Ipv6RoutingProtocol objects.
virtual Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const =0
virtual Ipv6RoutingHelper * Copy() const =0
virtual constructor
Helper class that adds ns3::Ipv6StaticRouting objects.
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
A network Node.
Definition node.h:46
uint32_t GetId() const
Definition node.cc:106
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
Definition object.h:78
static void EnablePrinting()
Enable printing packets metadata.
Definition packet.cc:585
This can be used as an interface in a node in order for the node to generate PacketSockets that can c...
Manage pcap files for device models.
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.
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.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Hold variables of type string.
Definition string.h:45
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructu...
a unique identifier for an interface.
Definition type-id.h:48
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:872
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition callback.h:745
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::pair< Ptr< Ipv4 >, uint32_t > InterfacePairIpv4
Ipv4/interface pair.
static void Ipv6L3ProtocolDropSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, const Ipv6Header &header, Ptr< const Packet > packet, Ipv6L3Protocol::DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 dropped packet - Ascii output.
std::map< InterfacePairIpv4, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv4
Ipv4/interface and output stream container.
static void Ipv4L3ProtocolDropSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, const Ipv4Header &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Packet dropped callback with context.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
static void Ipv6L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 packet - Pcap output.
std::map< InterfacePairIpv4, Ptr< PcapFileWrapper > > InterfaceFileMapIpv4
Ipv4/interface and Pcap file wrapper container.
static void Ipv4L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interface)
IPv4 Rx / Tx packet callback.
static void Ipv6L3ProtocolRxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 received packet - Ascii output.
std::map< InterfacePairIpv6, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv6
Ipv6/interface and output stream container.
static InterfaceStreamMapIpv6 g_interfaceStreamMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
std::map< InterfacePairIpv6, Ptr< PcapFileWrapper > > InterfaceFileMapIpv6
Ipv6/interface and Pcap file wrapper container.
std::pair< uint32_t, uint32_t > InterfacePairIpv6
Ipv6/interface pair.
static void Ipv4L3ProtocolRxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 received packet - Ascii output.
static void Ipv6L3ProtocolTxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 transmitted packet - Ascii output.
static void Ipv4L3ProtocolRxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 received packet - Ascii output.
static InterfaceFileMapIpv4 g_interfaceFileMapIpv4
A mapping of Ipv4/interface pairs to pcap files.
static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4
A mapping of Ipv4/interface pairs to ascii streams.
static void Ipv4L3ProtocolDropSinkWithoutContext(Ptr< OutputStreamWrapper > stream, const Ipv4Header &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Packet dropped callback without context.
static void Ipv4L3ProtocolTxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 transmitted packet - Ascii output.
static InterfaceFileMapIpv6 g_interfaceFileMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
static void Ipv4L3ProtocolTxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 transmitted packet - Ascii output.
static void Ipv6L3ProtocolRxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 received packet - Ascii output.
static void Ipv6L3ProtocolTxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 transmitted packet - Ascii output.
static void Ipv6L3ProtocolDropSinkWithoutContext(Ptr< OutputStreamWrapper > stream, const Ipv6Header &header, Ptr< const Packet > packet, Ipv6L3Protocol::DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 dropped packet - Ascii output.