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),
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 += demux->AssignStreams(currentStream);
233 }
234 Ptr<Ipv6ExtensionRoutingDemux> demuxRouter = node->GetObject<Ipv6ExtensionRoutingDemux>();
235 if (demuxRouter)
236 {
237 currentStream += demuxRouter->AssignStreams(currentStream);
238 }
239 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
240 if (ipv4)
241 {
242 Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol>();
243 if (arpL3Protocol)
244 {
245 currentStream += arpL3Protocol->AssignStreams(currentStream);
246 }
247 }
248 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
249 if (ipv6)
250 {
251 Ptr<Icmpv6L4Protocol> icmpv6L4Protocol = ipv6->GetObject<Icmpv6L4Protocol>();
252 if (icmpv6L4Protocol)
253 {
254 currentStream += icmpv6L4Protocol->AssignStreams(currentStream);
255 }
256 }
257 }
258 return (currentStream - stream);
259}
260
261void
263{
264 for (auto i = c.Begin(); i != c.End(); ++i)
265 {
266 Install(*i);
267 }
268}
269
270void
275
276void
278{
279 TypeId tid = TypeId::LookupByName(typeId);
280 if (node->GetObject<Object>(tid))
281 {
282 return;
283 }
284
285 ObjectFactory factory;
286 factory.SetTypeId(typeId);
287 Ptr<Object> protocol = factory.Create<Object>();
288 node->AggregateObject(protocol);
289}
290
291void
293{
294 if (m_ipv4Enabled)
295 {
296 /* IPv4 stack */
297 CreateAndAggregateObjectFromTypeId(node, "ns3::ArpL3Protocol");
298 CreateAndAggregateObjectFromTypeId(node, "ns3::Ipv4L3Protocol");
299 CreateAndAggregateObjectFromTypeId(node, "ns3::Icmpv4L4Protocol");
301 {
302 Ptr<ArpL3Protocol> arp = node->GetObject<ArpL3Protocol>();
303 NS_ASSERT(arp);
304 arp->SetAttribute("RequestJitter",
305 StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
306 }
307
308 // Set routing
309 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
310 if (!ipv4->GetRoutingProtocol())
311 {
312 Ptr<Ipv4RoutingProtocol> ipv4Routing = m_routing->Create(node);
313 ipv4->SetRoutingProtocol(ipv4Routing);
314 }
315 }
316
317 if (m_ipv6Enabled)
318 {
319 /* IPv6 stack */
320 CreateAndAggregateObjectFromTypeId(node, "ns3::Ipv6L3Protocol");
321 CreateAndAggregateObjectFromTypeId(node, "ns3::Icmpv6L4Protocol");
323 {
324 Ptr<Icmpv6L4Protocol> icmpv6l4 = node->GetObject<Icmpv6L4Protocol>();
325 NS_ASSERT(icmpv6l4);
326 icmpv6l4->SetAttribute("SolicitationJitter",
327 StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
328 }
329 // Set routing
330 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
331 if (!ipv6->GetRoutingProtocol())
332 {
333 Ptr<Ipv6RoutingProtocol> ipv6Routing = m_routingv6->Create(node);
334 ipv6->SetRoutingProtocol(ipv6Routing);
335 }
336 /* register IPv6 extensions and options */
337 ipv6->RegisterExtensions();
338 ipv6->RegisterOptions();
339 }
340
342 {
343 CreateAndAggregateObjectFromTypeId(node, "ns3::TrafficControlLayer");
344 CreateAndAggregateObjectFromTypeId(node, "ns3::UdpL4Protocol");
345 CreateAndAggregateObjectFromTypeId(node, "ns3::TcpL4Protocol");
346 if (!node->GetObject<PacketSocketFactory>())
347 {
349 node->AggregateObject(factory);
350 }
351 }
352
353 if (m_ipv4Enabled)
354 {
355 Ptr<ArpL3Protocol> arp = node->GetObject<ArpL3Protocol>();
356 Ptr<TrafficControlLayer> tc = node->GetObject<TrafficControlLayer>();
357 NS_ASSERT(arp);
358 NS_ASSERT(tc);
359 arp->SetTrafficControl(tc);
360 }
361}
362
363void
364InternetStackHelper::Install(std::string nodeName) const
365{
366 Ptr<Node> node = Names::Find<Node>(nodeName);
367 Install(node);
368}
369
370/**
371 * @brief Sync function for IPv4 packet - Pcap output
372 * @param p smart pointer to the packet
373 * @param ipv4 smart pointer to the node's IPv4 stack
374 * @param interface incoming interface
375 */
376static void
378{
379 NS_LOG_FUNCTION(p << ipv4 << interface);
380
381 //
382 // Since trace sources are independent of interface, if we hook a source
383 // on a particular protocol we will get traces for all of its interfaces.
384 // We need to filter this to only report interfaces for which the user
385 // has expressed interest.
386 //
387 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
388 if (g_interfaceFileMapIpv4.find(pair) == g_interfaceFileMapIpv4.end())
389 {
390 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
391 return;
392 }
393
395 file->Write(Simulator::Now(), p);
396}
397
398bool
400{
401 auto id = ipv4->GetObject<Node>()->GetId();
402
403 for (auto i = g_interfaceFileMapIpv4.begin(); i != g_interfaceFileMapIpv4.end(); ++i)
404 {
405 if ((*i).first.first == id)
406 {
407 return true;
408 }
409 }
410 return false;
411}
412
413void
415 Ptr<Ipv4> ipv4,
416 uint32_t interface,
417 bool explicitFilename)
418{
419 NS_LOG_FUNCTION(prefix << ipv4 << interface);
420
421 if (!m_ipv4Enabled)
422 {
423 NS_LOG_INFO("Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
424 return;
425 }
426
427 //
428 // We have to create a file and a mapping from protocol/interface to file
429 // irrespective of how many times we want to trace a particular protocol.
430 //
431 PcapHelper pcapHelper;
432
433 std::string filename;
434 if (explicitFilename)
435 {
436 filename = prefix;
437 }
438 else
439 {
440 filename = pcapHelper.GetFilenameFromInterfacePair(prefix, ipv4, interface);
441 }
442
443 Ptr<PcapFileWrapper> file = pcapHelper.CreateFile(filename, std::ios::out, PcapHelper::DLT_RAW);
444
445 //
446 // However, we only hook the trace source once to avoid multiple trace sink
447 // calls per event (connect is independent of interface).
448 //
449 if (!PcapHooked(ipv4))
450 {
451 //
452 // Ptr<Ipv4> is aggregated to node and Ipv4L3Protocol is aggregated to
453 // node so we can get to Ipv4L3Protocol through Ipv4.
454 //
455 Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol>();
456 NS_ASSERT_MSG(ipv4L3Protocol,
457 "InternetStackHelper::EnablePcapIpv4Internal(): "
458 "m_ipv4Enabled and ipv4L3Protocol inconsistent");
459
460 bool result =
461 ipv4L3Protocol->TraceConnectWithoutContext("Tx", MakeCallback(&Ipv4L3ProtocolRxTxSink));
462 NS_ASSERT_MSG(result == true,
463 "InternetStackHelper::EnablePcapIpv4Internal(): "
464 "Unable to connect ipv4L3Protocol \"Tx\"");
465
466 result =
467 ipv4L3Protocol->TraceConnectWithoutContext("Rx", MakeCallback(&Ipv4L3ProtocolRxTxSink));
468 NS_ASSERT_MSG(result == true,
469 "InternetStackHelper::EnablePcapIpv4Internal(): "
470 "Unable to connect ipv4L3Protocol \"Rx\"");
471 }
472
473 g_interfaceFileMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] = file;
474}
475
476/**
477 * @brief Sync function for IPv6 packet - Pcap output
478 * @param p smart pointer to the packet
479 * @param ipv6 smart pointer to the node's IPv6 stack
480 * @param interface incoming interface
481 */
482static void
484{
485 NS_LOG_FUNCTION(p << ipv6 << interface);
486
487 //
488 // Since trace sources are independent of interface, if we hook a source
489 // on a particular protocol we will get traces for all of its interfaces.
490 // We need to filter this to only report interfaces for which the user
491 // has expressed interest.
492 //
493 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
494 if (g_interfaceFileMapIpv6.find(pair) == g_interfaceFileMapIpv6.end())
495 {
496 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
497 return;
498 }
499
501 file->Write(Simulator::Now(), p);
502}
503
504bool
506{
507 auto id = ipv6->GetObject<Node>()->GetId();
508
509 for (auto i = g_interfaceFileMapIpv6.begin(); i != g_interfaceFileMapIpv6.end(); ++i)
510 {
511 if ((*i).first.first == id)
512 {
513 return true;
514 }
515 }
516 return false;
517}
518
519void
521 Ptr<Ipv6> ipv6,
522 uint32_t interface,
523 bool explicitFilename)
524{
525 NS_LOG_FUNCTION(prefix << ipv6 << interface);
526
527 if (!m_ipv6Enabled)
528 {
529 NS_LOG_INFO("Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
530 return;
531 }
532
533 //
534 // We have to create a file and a mapping from protocol/interface to file
535 // irrespective of how many times we want to trace a particular protocol.
536 //
537 PcapHelper pcapHelper;
538
539 std::string filename;
540 if (explicitFilename)
541 {
542 filename = prefix;
543 }
544 else
545 {
546 filename = pcapHelper.GetFilenameFromInterfacePair(prefix, ipv6, interface);
547 }
548
549 Ptr<PcapFileWrapper> file = pcapHelper.CreateFile(filename, std::ios::out, PcapHelper::DLT_RAW);
550
551 //
552 // However, we only hook the trace source once to avoid multiple trace sink
553 // calls per event (connect is independent of interface).
554 //
555 if (!PcapHooked(ipv6))
556 {
557 //
558 // Ptr<Ipv6> is aggregated to node and Ipv6L3Protocol is aggregated to
559 // node so we can get to Ipv6L3Protocol through Ipv6.
560 //
561 Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol>();
562 NS_ASSERT_MSG(ipv6L3Protocol,
563 "InternetStackHelper::EnablePcapIpv6Internal(): "
564 "m_ipv6Enabled and ipv6L3Protocol inconsistent");
565
566 bool result =
567 ipv6L3Protocol->TraceConnectWithoutContext("Tx", MakeCallback(&Ipv6L3ProtocolRxTxSink));
568 NS_ASSERT_MSG(result == true,
569 "InternetStackHelper::EnablePcapIpv6Internal(): "
570 "Unable to connect ipv6L3Protocol \"Tx\"");
571
572 result =
573 ipv6L3Protocol->TraceConnectWithoutContext("Rx", MakeCallback(&Ipv6L3ProtocolRxTxSink));
574 NS_ASSERT_MSG(result == true,
575 "InternetStackHelper::EnablePcapIpv6Internal(): "
576 "Unable to connect ipv6L3Protocol \"Rx\"");
577 }
578
579 g_interfaceFileMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] = file;
580}
581
582/**
583 * @brief Sync function for IPv4 dropped packet - Ascii output
584 * @param stream the output stream
585 * @param header IPv4 header
586 * @param packet smart pointer to the packet
587 * @param reason the reason for the dropping
588 * @param ipv4 smart pointer to the node's IPv4 stack
589 * @param interface incoming interface
590 */
591static void
593 const Ipv4Header& header,
594 Ptr<const Packet> packet,
596 Ptr<Ipv4> ipv4,
597 uint32_t interface)
598{
599 //
600 // Since trace sources are independent of interface, if we hook a source
601 // on a particular protocol we will get traces for all of its interfaces.
602 // We need to filter this to only report interfaces for which the user
603 // has expressed interest.
604 //
605 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
607 {
608 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
609 return;
610 }
611
612 Ptr<Packet> p = packet->Copy();
613 p->AddHeader(header);
614 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << *p << std::endl;
615}
616
617/**
618 * @brief Sync function for IPv4 transmitted packet - Ascii output
619 * @param stream the output stream
620 * @param packet smart pointer to the packet
621 * @param ipv4 smart pointer to the node's IPv4 stack
622 * @param interface incoming interface
623 */
624static void
626 Ptr<const Packet> packet,
627 Ptr<Ipv4> ipv4,
628 uint32_t interface)
629{
630 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
631
633 {
634 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
635 return;
636 }
637 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
638}
639
640/**
641 * @brief Sync function for IPv4 received packet - Ascii output
642 * @param stream the output stream
643 * @param packet smart pointer to the packet
644 * @param ipv4 smart pointer to the node's IPv4 stack
645 * @param interface incoming interface
646 */
647static void
649 Ptr<const Packet> packet,
650 Ptr<Ipv4> ipv4,
651 uint32_t interface)
652{
653 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
655 {
656 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
657 return;
658 }
659
660 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
661}
662
663/**
664 * @brief Sync function for IPv4 dropped packet - Ascii output
665 * @param stream the output stream
666 * @param context the context
667 * @param header IPv4 header
668 * @param packet smart pointer to the packet
669 * @param reason the reason for the dropping
670 * @param ipv4 smart pointer to the node's IPv4 stack
671 * @param interface incoming interface
672 */
673static void
675 std::string context,
676 const Ipv4Header& header,
677 Ptr<const Packet> packet,
679 Ptr<Ipv4> ipv4,
680 uint32_t interface)
681{
682 //
683 // Since trace sources are independent of interface, if we hook a source
684 // on a particular protocol we will get traces for all of its interfaces.
685 // We need to filter this to only report interfaces for which the user
686 // has expressed interest.
687 //
688 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
690 {
691 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
692 return;
693 }
694
695 Ptr<Packet> p = packet->Copy();
696 p->AddHeader(header);
697#ifdef INTERFACE_CONTEXT
698 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << "("
699 << interface << ") " << *p << std::endl;
700#else
701 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << " " << *p
702 << std::endl;
703#endif
704}
705
706/**
707 * @brief Sync function for IPv4 transmitted packet - Ascii output
708 * @param stream the output stream
709 * @param context the context
710 * @param packet smart pointer to the packet
711 * @param ipv4 smart pointer to the node's IPv4 stack
712 * @param interface incoming interface
713 */
714static void
716 std::string context,
717 Ptr<const Packet> packet,
718 Ptr<Ipv4> ipv4,
719 uint32_t interface)
720{
721 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
723 {
724 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
725 return;
726 }
727
728#ifdef INTERFACE_CONTEXT
729 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << "("
730 << interface << ") " << *packet << std::endl;
731#else
732 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << " "
733 << *packet << std::endl;
734#endif
735}
736
737/**
738 * @brief Sync function for IPv4 received packet - Ascii output
739 * @param stream the output stream
740 * @param context the context
741 * @param packet smart pointer to the packet
742 * @param ipv4 smart pointer to the node's IPv4 stack
743 * @param interface incoming interface
744 */
745static void
747 std::string context,
748 Ptr<const Packet> packet,
749 Ptr<Ipv4> ipv4,
750 uint32_t interface)
751{
752 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
754 {
755 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
756 return;
757 }
758
759#ifdef INTERFACE_CONTEXT
760 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << "("
761 << interface << ") " << *packet << std::endl;
762#else
763 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << " "
764 << *packet << std::endl;
765#endif
766}
767
768bool
770{
771 auto id = ipv4->GetObject<Node>()->GetId();
772
773 for (auto i = g_interfaceStreamMapIpv4.begin(); i != g_interfaceStreamMapIpv4.end(); ++i)
774 {
775 if ((*i).first.first == id)
776 {
777 return true;
778 }
779 }
780 return false;
781}
782
783void
785 std::string prefix,
786 Ptr<Ipv4> ipv4,
787 uint32_t interface,
788 bool explicitFilename)
789{
790 if (!m_ipv4Enabled)
791 {
792 NS_LOG_INFO("Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
793 return;
794 }
795
796 //
797 // Our trace sinks are going to use packet printing, so we have to
798 // make sure that is turned on.
799 //
801
802 //
803 // If we are not provided an OutputStreamWrapper, we are expected to create
804 // one using the usual trace filename conventions and hook WithoutContext
805 // since there will be one file per context and therefore the context would
806 // be redundant.
807 //
808 if (!stream)
809 {
810 //
811 // Set up an output stream object to deal with private ofstream copy
812 // constructor and lifetime issues. Let the helper decide the actual
813 // name of the file given the prefix.
814 //
815 // We have to create a stream and a mapping from protocol/interface to
816 // stream irrespective of how many times we want to trace a particular
817 // protocol.
818 //
819 AsciiTraceHelper asciiTraceHelper;
820
821 std::string filename;
822 if (explicitFilename)
823 {
824 filename = prefix;
825 }
826 else
827 {
828 filename = asciiTraceHelper.GetFilenameFromInterfacePair(prefix, ipv4, interface);
829 }
830
831 Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream(filename);
832
833 //
834 // However, we only hook the trace sources once to avoid multiple trace sink
835 // calls per event (connect is independent of interface).
836 //
837 if (!AsciiHooked(ipv4))
838 {
839 //
840 // We can use the default drop sink for the ArpL3Protocol since it has
841 // the usual signature. We can get to the Ptr<ArpL3Protocol> through
842 // our Ptr<Ipv4> since they must both be aggregated to the same node.
843 //
844 Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol>();
845 asciiTraceHelper.HookDefaultDropSinkWithoutContext<ArpL3Protocol>(arpL3Protocol,
846 "Drop",
847 theStream);
848
849 //
850 // The drop sink for the Ipv4L3Protocol uses a different signature than
851 // the default sink, so we have to cook one up for ourselves. We can get
852 // to the Ptr<Ipv4L3Protocol> through our Ptr<Ipv4> since they must both
853 // be aggregated to the same node.
854 //
855 Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol>();
856 bool result = ipv4L3Protocol->TraceConnectWithoutContext(
857 "Drop",
859 NS_ASSERT_MSG(result == true,
860 "InternetStackHelper::EnableAsciiIpv4Internal(): "
861 "Unable to connect ipv4L3Protocol \"Drop\"");
862 result = ipv4L3Protocol->TraceConnectWithoutContext(
863 "Tx",
865 NS_ASSERT_MSG(result == true,
866 "InternetStackHelper::EnableAsciiIpv4Internal(): "
867 "Unable to connect ipv4L3Protocol \"Tx\"");
868 result = ipv4L3Protocol->TraceConnectWithoutContext(
869 "Rx",
871 NS_ASSERT_MSG(result == true,
872 "InternetStackHelper::EnableAsciiIpv4Internal(): "
873 "Unable to connect ipv4L3Protocol \"Rx\"");
874 }
875
876 g_interfaceStreamMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] =
877 theStream;
878 return;
879 }
880
881 //
882 // If we are provided an OutputStreamWrapper, we are expected to use it, and
883 // to provide a context. We are free to come up with our own context if we
884 // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
885 // compatibility and simplicity, we just use Config::Connect and let it deal
886 // with the context.
887 //
888 // We need to associate the ipv4/interface with a stream to express interest
889 // in tracing events on that pair, however, we only hook the trace sources
890 // once to avoid multiple trace sink calls per event (connect is independent
891 // of interface).
892 //
893 if (!AsciiHooked(ipv4))
894 {
895 Ptr<Node> node = ipv4->GetObject<Node>();
896 std::ostringstream oss;
897
898 //
899 // For the ARP Drop, we are going to use the default trace sink provided by
900 // the ascii trace helper. There is actually no AsciiTraceHelper in sight
901 // here, but the default trace sinks are actually publicly available static
902 // functions that are always there waiting for just such a case.
903 //
904 oss << "/NodeList/" << node->GetId() << "/$ns3::ArpL3Protocol/Drop";
905 Config::Connect(oss.str(),
907
908 //
909 // This has all kinds of parameters coming with, so we have to cook up our
910 // own sink.
911 //
912 oss.str("");
913 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Drop";
915 oss.str("");
916 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Tx";
918 oss.str("");
919 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Rx";
921 }
922
923 g_interfaceStreamMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] = stream;
924}
925
926/**
927 * @brief Sync function for IPv6 dropped packet - Ascii output
928 * @param stream the output stream
929 * @param header IPv6 header
930 * @param packet smart pointer to the packet
931 * @param reason the reason for the dropping
932 * @param ipv6 smart pointer to the node's IPv6 stack
933 * @param interface incoming interface
934 */
935static void
937 const Ipv6Header& header,
938 Ptr<const Packet> packet,
940 Ptr<Ipv6> ipv6,
941 uint32_t interface)
942{
943 //
944 // Since trace sources are independent of interface, if we hook a source
945 // on a particular protocol we will get traces for all of its interfaces.
946 // We need to filter this to only report interfaces for which the user
947 // has expressed interest.
948 //
949 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
951 {
952 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
953 return;
954 }
955
956 Ptr<Packet> p = packet->Copy();
957 p->AddHeader(header);
958 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << *p << std::endl;
959}
960
961/**
962 * @brief Sync function for IPv6 transmitted packet - Ascii output
963 * @param stream the output stream
964 * @param packet smart pointer to the packet
965 * @param ipv6 smart pointer to the node's IPv6 stack
966 * @param interface incoming interface
967 */
968static void
970 Ptr<const Packet> packet,
971 Ptr<Ipv6> ipv6,
972 uint32_t interface)
973{
974 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
976 {
977 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
978 return;
979 }
980
981 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
982}
983
984/**
985 * @brief Sync function for IPv6 received packet - Ascii output
986 * @param stream the output stream
987 * @param packet smart pointer to the packet
988 * @param ipv6 smart pointer to the node's IPv6 stack
989 * @param interface incoming interface
990 */
991static void
993 Ptr<const Packet> packet,
994 Ptr<Ipv6> ipv6,
995 uint32_t interface)
996{
997 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
999 {
1000 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1001 return;
1002 }
1003
1004 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
1005}
1006
1007/**
1008 * @brief Sync function for IPv6 dropped packet - Ascii output
1009 * @param stream the output stream
1010 * @param context the context
1011 * @param header IPv6 header
1012 * @param packet smart pointer to the packet
1013 * @param reason the reason for the dropping
1014 * @param ipv6 smart pointer to the node's IPv6 stack
1015 * @param interface incoming interface
1016 */
1017static void
1019 std::string context,
1020 const Ipv6Header& header,
1021 Ptr<const Packet> packet,
1023 Ptr<Ipv6> ipv6,
1024 uint32_t interface)
1025{
1026 //
1027 // Since trace sources are independent of interface, if we hook a source
1028 // on a particular protocol we will get traces for all of its interfaces.
1029 // We need to filter this to only report interfaces for which the user
1030 // has expressed interest.
1031 //
1032 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1033 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1034 {
1035 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1036 return;
1037 }
1038
1039 Ptr<Packet> p = packet->Copy();
1040 p->AddHeader(header);
1041#ifdef INTERFACE_CONTEXT
1042 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << "("
1043 << interface << ") " << *p << std::endl;
1044#else
1045 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << " " << *p
1046 << std::endl;
1047#endif
1048}
1049
1050/**
1051 * @brief Sync function for IPv6 transmitted packet - Ascii output
1052 * @param stream the output stream
1053 * @param context the context
1054 * @param packet smart pointer to the packet
1055 * @param ipv6 smart pointer to the node's IPv6 stack
1056 * @param interface incoming interface
1057 */
1058static void
1060 std::string context,
1061 Ptr<const Packet> packet,
1062 Ptr<Ipv6> ipv6,
1063 uint32_t interface)
1064{
1065 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1066 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1067 {
1068 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1069 return;
1070 }
1071
1072#ifdef INTERFACE_CONTEXT
1073 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << "("
1074 << interface << ") " << *packet << std::endl;
1075#else
1076 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << " "
1077 << *packet << std::endl;
1078#endif
1079}
1080
1081/**
1082 * @brief Sync function for IPv6 received packet - Ascii output
1083 * @param stream the output stream
1084 * @param context the context
1085 * @param packet smart pointer to the packet
1086 * @param ipv6 smart pointer to the node's IPv6 stack
1087 * @param interface incoming interface
1088 */
1089static void
1091 std::string context,
1092 Ptr<const Packet> packet,
1093 Ptr<Ipv6> ipv6,
1094 uint32_t interface)
1095{
1096 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1097 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1098 {
1099 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1100 return;
1101 }
1102
1103#ifdef INTERFACE_CONTEXT
1104 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << "("
1105 << interface << ") " << *packet << std::endl;
1106#else
1107 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << " "
1108 << *packet << std::endl;
1109#endif
1110}
1111
1112bool
1114{
1115 auto id = ipv6->GetObject<Node>()->GetId();
1116
1117 for (auto i = g_interfaceStreamMapIpv6.begin(); i != g_interfaceStreamMapIpv6.end(); ++i)
1118 {
1119 if ((*i).first.first == id)
1120 {
1121 return true;
1122 }
1123 }
1124 return false;
1125}
1126
1127void
1129 std::string prefix,
1130 Ptr<Ipv6> ipv6,
1131 uint32_t interface,
1132 bool explicitFilename)
1133{
1134 if (!m_ipv6Enabled)
1135 {
1136 NS_LOG_INFO("Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1137 return;
1138 }
1139
1140 //
1141 // Our trace sinks are going to use packet printing, so we have to
1142 // make sure that is turned on.
1143 //
1145
1146 //
1147 // If we are not provided an OutputStreamWrapper, we are expected to create
1148 // one using the usual trace filename conventions and do a hook WithoutContext
1149 // since there will be one file per context and therefore the context would
1150 // be redundant.
1151 //
1152 if (!stream)
1153 {
1154 //
1155 // Set up an output stream object to deal with private ofstream copy
1156 // constructor and lifetime issues. Let the helper decide the actual
1157 // name of the file given the prefix.
1158 //
1159 // We have to create a stream and a mapping from protocol/interface to
1160 // stream irrespective of how many times we want to trace a particular
1161 // protocol.
1162 //
1163 AsciiTraceHelper asciiTraceHelper;
1164
1165 std::string filename;
1166 if (explicitFilename)
1167 {
1168 filename = prefix;
1169 }
1170 else
1171 {
1172 filename = asciiTraceHelper.GetFilenameFromInterfacePair(prefix, ipv6, interface);
1173 }
1174
1175 Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream(filename);
1176
1177 //
1178 // However, we only hook the trace sources once to avoid multiple trace sink
1179 // calls per event (connect is independent of interface).
1180 //
1181 if (!AsciiHooked(ipv6))
1182 {
1183 //
1184 // The drop sink for the Ipv6L3Protocol uses a different signature than
1185 // the default sink, so we have to cook one up for ourselves. We can get
1186 // to the Ptr<Ipv6L3Protocol> through our Ptr<Ipv6> since they must both
1187 // be aggregated to the same node.
1188 //
1189 Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol>();
1190 bool result = ipv6L3Protocol->TraceConnectWithoutContext(
1191 "Drop",
1193 NS_ASSERT_MSG(result == true,
1194 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1195 "Unable to connect ipv6L3Protocol \"Drop\"");
1196 result = ipv6L3Protocol->TraceConnectWithoutContext(
1197 "Tx",
1199 NS_ASSERT_MSG(result == true,
1200 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1201 "Unable to connect ipv6L3Protocol \"Tx\"");
1202 result = ipv6L3Protocol->TraceConnectWithoutContext(
1203 "Rx",
1205 NS_ASSERT_MSG(result == true,
1206 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1207 "Unable to connect ipv6L3Protocol \"Rx\"");
1208 }
1209
1210 g_interfaceStreamMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] =
1211 theStream;
1212 return;
1213 }
1214
1215 //
1216 // If we are provided an OutputStreamWrapper, we are expected to use it, and
1217 // to provide a context. We are free to come up with our own context if we
1218 // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
1219 // compatibility and simplicity, we just use Config::Connect and let it deal
1220 // with the context.
1221 //
1222 // We need to associate the ipv4/interface with a stream to express interest
1223 // in tracing events on that pair, however, we only hook the trace sources
1224 // once to avoid multiple trace sink calls per event (connect is independent
1225 // of interface).
1226 //
1227 if (!AsciiHooked(ipv6))
1228 {
1229 Ptr<Node> node = ipv6->GetObject<Node>();
1230 std::ostringstream oss;
1231
1232 oss.str("");
1233 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Drop";
1235 oss.str("");
1236 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Tx";
1238 oss.str("");
1239 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Rx";
1241 }
1242
1243 g_interfaceStreamMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] = stream;
1244}
1245
1246} // namespace ns3
return result
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
Helper class that adds ns3::Ipv4StaticRouting objects.
Demultiplexes IPv6 extensions.
static const uint8_t EXT_NUMBER
Fragmentation extension number.
IPv6 Extension Routing Demux.
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 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:445
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
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:81
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.
Definition ptr.h:70
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
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:398
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:50
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:870
#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
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:690
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:970
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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:267
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition callback.h:753
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
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.
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.