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
18
19#include "ns3/arp-l3-protocol.h"
20#include "ns3/assert.h"
21#include "ns3/callback.h"
22#include "ns3/config.h"
23#include "ns3/global-router-interface.h"
24#include "ns3/global-routing.h"
25#include "ns3/iana-link-type-numbers.h"
26#include "ns3/icmpv6-l4-protocol.h"
27#include "ns3/ipv4.h"
28#include "ns3/ipv6-extension-demux.h"
29#include "ns3/ipv6-extension-header.h"
30#include "ns3/ipv6-extension.h"
31#include "ns3/ipv6.h"
32#include "ns3/log.h"
33#include "ns3/names.h"
34#include "ns3/net-device.h"
35#include "ns3/node-list.h"
36#include "ns3/node.h"
37#include "ns3/object.h"
38#include "ns3/packet-socket-factory.h"
39#include "ns3/simulator.h"
40#include "ns3/string.h"
41#include "ns3/traffic-control-layer.h"
42
43#include <limits>
44#include <map>
45
46namespace ns3
47{
48
49NS_LOG_COMPONENT_DEFINE("InternetStackHelper");
50
51//
52// Historically, the only context written to ascii traces was the protocol.
53// Traces from the protocols include the interface, though. It is not
54// possible to really determine where an event originated without including
55// this. If you want the additional context information, define
56// INTERFACE_CONTEXT. If you want compatibility with the old-style traces
57// comment it out.
58//
59#define INTERFACE_CONTEXT
60
61//
62// Things are going to work differently here with respect to trace file handling
63// than in most places because the Tx and Rx trace sources we are interested in
64// are going to multiplex receive and transmit callbacks for all Ipv4 and
65// interface pairs through one callback. We want packets to or from each
66// distinct pair to go to an individual file, so we have got to demultiplex the
67// Ipv4 and interface pair into a corresponding Ptr<PcapFileWrapper> at the
68// callback.
69//
70// A complication in this situation is that the trace sources are hooked on
71// a protocol basis. There is no trace source hooked by an Ipv4 and interface
72// pair. This means that if we naively proceed to hook, say, a drop trace
73// for a given Ipv4 with interface 0, and then hook for Ipv4 with interface 1
74// we will hook the drop trace twice and get two callbacks per event. What
75// we need to do is to hook the event once, and that will result in a single
76// callback per drop event, and the trace source will provide the interface
77// which we filter on in the trace sink.
78//
79// The use of global maps allows this to continue to work properly even if
80// the helper is destroyed before the simulation completes. If the maps
81// are populated, the reference counting smart pointers to
82// OutputStreamWrapper and PcapFileWrapper will cause those objects to be
83// destroyed at static object destruction time; i.e., the simulator does
84// not explicitly clear these maps before the program ends.
85//
86typedef std::pair<uint32_t, uint32_t> InterfacePairIpv4; //!< Ipv4/interface pair
87typedef std::map<InterfacePairIpv4, Ptr<PcapFileWrapper>>
88 InterfaceFileMapIpv4; //!< Ipv4/interface and Pcap file wrapper container
89typedef std::map<InterfacePairIpv4, Ptr<OutputStreamWrapper>>
90 InterfaceStreamMapIpv4; //!< Ipv4/interface and output stream container
91
93 g_interfaceFileMapIpv4; //!< A mapping of Ipv4/interface pairs to pcap files
95 g_interfaceStreamMapIpv4; //!< A mapping of Ipv4/interface pairs to ascii streams
96
97typedef std::pair<uint32_t, uint32_t> InterfacePairIpv6; //!< Ipv6/interface pair
98typedef std::map<InterfacePairIpv6, Ptr<PcapFileWrapper>>
99 InterfaceFileMapIpv6; //!< Ipv6/interface and Pcap file wrapper container
100typedef std::map<InterfacePairIpv6, Ptr<OutputStreamWrapper>>
101 InterfaceStreamMapIpv6; //!< Ipv6/interface and output stream container
102
104 g_interfaceFileMapIpv6; //!< A mapping of Ipv6/interface pairs to pcap files
106 g_interfaceStreamMapIpv6; //!< A mapping of Ipv6/interface pairs to pcap files
107
109 : m_routing(nullptr),
110 m_routingv6(nullptr),
111 m_ipv4Enabled(true),
112 m_ipv6Enabled(true),
115
116{
117 Initialize();
118}
119
120// private method called by both constructor and Reset ()
121void
123{
124 Ipv4StaticRoutingHelper staticRouting;
125 Ipv4GlobalRoutingHelper globalRouting;
126 Ipv4ListRoutingHelper listRouting;
127 Ipv6StaticRoutingHelper staticRouting6;
128 Ipv6GlobalRoutingHelper globalRouting6;
129 Ipv6ListRoutingHelper listRouting6;
130 listRouting.Add(staticRouting, 0);
131 listRouting.Add(globalRouting, -10);
132 SetRoutingHelper(listRouting);
133 listRouting6.Add(staticRouting6, 0);
134 listRouting6.Add(globalRouting6, -10);
135 SetRoutingHelper(listRouting6);
136}
137
143
153
156{
157 if (this == &o)
158 {
159 return *this;
160 }
161 m_routing = o.m_routing->Copy();
163 return *this;
164}
165
166void
168{
169 delete m_routing;
170 m_routing = nullptr;
171 delete m_routingv6;
172 m_routingv6 = nullptr;
173 m_ipv4Enabled = true;
174 m_ipv6Enabled = true;
177 Initialize();
178}
179
180void
182{
183 delete m_routing;
184 m_routing = routing.Copy();
185}
186
187void
189{
190 delete m_routingv6;
191 m_routingv6 = routing.Copy();
192}
193
194void
196{
197 m_ipv4Enabled = enable;
198}
199
200void
202{
203 m_ipv6Enabled = enable;
204}
205
206void
211
212void
217
218int64_t
220{
221 int64_t currentStream = stream;
222 for (auto i = c.Begin(); i != c.End(); ++i)
223 {
224 Ptr<Node> node = *i;
225 Ptr<GlobalRouter<Ipv4Manager>> routerv4 = node->GetObject<GlobalRouter<Ipv4Manager>>();
226 if (routerv4)
227 {
228 Ptr<Ipv4GlobalRouting> gr = routerv4->GetRoutingProtocol();
229 if (gr)
230 {
231 currentStream += gr->AssignStreams(currentStream);
232 }
233 }
234 Ptr<Ipv6ExtensionDemux> demux = node->GetObject<Ipv6ExtensionDemux>();
235 if (demux)
236 {
238 NS_ASSERT(fe); // should always exist in the demux
239 currentStream += demux->AssignStreams(currentStream);
240 }
241 Ptr<Ipv6ExtensionRoutingDemux> demuxRouter = node->GetObject<Ipv6ExtensionRoutingDemux>();
242 if (demuxRouter)
243 {
244 currentStream += demuxRouter->AssignStreams(currentStream);
245 }
246 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
247 if (ipv4)
248 {
249 Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol>();
250 if (arpL3Protocol)
251 {
252 currentStream += arpL3Protocol->AssignStreams(currentStream);
253 }
254 }
255 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
256 if (ipv6)
257 {
258 Ptr<Icmpv6L4Protocol> icmpv6L4Protocol = ipv6->GetObject<Icmpv6L4Protocol>();
259 if (icmpv6L4Protocol)
260 {
261 currentStream += icmpv6L4Protocol->AssignStreams(currentStream);
262 }
263 }
264 }
265 // The below is intentionally left out of the above loop, to avoid some stream
266 // assignment perturbations on existing programs due to adding IPv6 global routing.
267 // Future extensions of this method should also copy this approach.
268 for (auto i = c.Begin(); i != c.End(); ++i)
269 {
270 Ptr<Node> node = *i;
271 Ptr<GlobalRouter<Ipv6Manager>> routerv6 = node->GetObject<GlobalRouter<Ipv6Manager>>();
272 if (routerv6)
273 {
274 Ptr<GlobalRouting<Ipv6RoutingProtocol>> gr = routerv6->GetRoutingProtocol();
275 if (gr)
276 {
277 currentStream += gr->AssignStreams(currentStream);
278 }
279 }
280 }
281 return (currentStream - stream);
282}
283
284void
286{
287 for (auto i = c.Begin(); i != c.End(); ++i)
288 {
289 Install(*i);
290 }
291}
292
293void
298
299void
301{
302 TypeId tid = TypeId::LookupByName(typeId);
303 if (node->GetObject<Object>(tid))
304 {
305 return;
306 }
307
308 ObjectFactory factory;
309 factory.SetTypeId(typeId);
310 Ptr<Object> protocol = factory.Create<Object>();
311 node->AggregateObject(protocol);
312}
313
314void
316{
317 if (m_ipv4Enabled)
318 {
319 /* IPv4 stack */
320 CreateAndAggregateObjectFromTypeId(node, "ns3::ArpL3Protocol");
321 CreateAndAggregateObjectFromTypeId(node, "ns3::Ipv4L3Protocol");
322 CreateAndAggregateObjectFromTypeId(node, "ns3::Icmpv4L4Protocol");
324 {
325 Ptr<ArpL3Protocol> arp = node->GetObject<ArpL3Protocol>();
326 NS_ASSERT(arp);
327 arp->SetAttribute("RequestJitter",
328 StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
329 }
330
331 // Set routing
332 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
333 if (!ipv4->GetRoutingProtocol())
334 {
335 Ptr<Ipv4RoutingProtocol> ipv4Routing = m_routing->Create(node);
336 ipv4->SetRoutingProtocol(ipv4Routing);
337 }
338 }
339
340 if (m_ipv6Enabled)
341 {
342 /* IPv6 stack */
343 CreateAndAggregateObjectFromTypeId(node, "ns3::Ipv6L3Protocol");
344 CreateAndAggregateObjectFromTypeId(node, "ns3::Icmpv6L4Protocol");
346 {
347 Ptr<Icmpv6L4Protocol> icmpv6l4 = node->GetObject<Icmpv6L4Protocol>();
348 NS_ASSERT(icmpv6l4);
349 icmpv6l4->SetAttribute("SolicitationJitter",
350 StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
351 }
352 // Set routing
353 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
354 if (!ipv6->GetRoutingProtocol())
355 {
356 Ptr<Ipv6RoutingProtocol> ipv6Routing = m_routingv6->Create(node);
357 ipv6->SetRoutingProtocol(ipv6Routing);
358 }
359 /* register IPv6 extensions and options */
360 ipv6->RegisterExtensions();
361 ipv6->RegisterOptions();
362 }
363
365 {
366 CreateAndAggregateObjectFromTypeId(node, "ns3::TrafficControlLayer");
367 CreateAndAggregateObjectFromTypeId(node, "ns3::UdpL4Protocol");
368 CreateAndAggregateObjectFromTypeId(node, "ns3::TcpL4Protocol");
369 if (!node->GetObject<PacketSocketFactory>())
370 {
372 node->AggregateObject(factory);
373 }
374 }
375
376 if (m_ipv4Enabled)
377 {
378 Ptr<ArpL3Protocol> arp = node->GetObject<ArpL3Protocol>();
379 Ptr<TrafficControlLayer> tc = node->GetObject<TrafficControlLayer>();
380 NS_ASSERT(arp);
381 NS_ASSERT(tc);
382 arp->SetTrafficControl(tc);
383 }
384}
385
386void
387InternetStackHelper::Install(std::string nodeName) const
388{
389 Ptr<Node> node = Names::Find<Node>(nodeName);
390 Install(node);
391}
392
393/**
394 * @brief Sync function for IPv4 packet - Pcap output
395 * @param p smart pointer to the packet
396 * @param ipv4 smart pointer to the node's IPv4 stack
397 * @param interface incoming interface
398 */
399static void
401{
402 NS_LOG_FUNCTION(p << ipv4 << interface);
403
404 //
405 // Since trace sources are independent of interface, if we hook a source
406 // on a particular protocol we will get traces for all of its interfaces.
407 // We need to filter this to only report interfaces for which the user
408 // has expressed interest.
409 //
410 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
411 if (g_interfaceFileMapIpv4.find(pair) == g_interfaceFileMapIpv4.end())
412 {
413 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
414 return;
415 }
416
418 file->Write(Simulator::Now(), p);
419}
420
421bool
423{
424 auto id = ipv4->GetObject<Node>()->GetId();
425
426 for (auto i = g_interfaceFileMapIpv4.begin(); i != g_interfaceFileMapIpv4.end(); ++i)
427 {
428 if ((*i).first.first == id)
429 {
430 return true;
431 }
432 }
433 return false;
434}
435
436void
438 Ptr<Ipv4> ipv4,
439 uint32_t interface,
440 bool explicitFilename)
441{
442 NS_LOG_FUNCTION(prefix << ipv4 << interface);
443
444 if (!m_ipv4Enabled)
445 {
446 NS_LOG_INFO("Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
447 return;
448 }
449
450 //
451 // We have to create a file and a mapping from protocol/interface to file
452 // irrespective of how many times we want to trace a particular protocol.
453 //
454 PcapHelper pcapHelper;
455
456 std::string filename;
457 if (explicitFilename)
458 {
459 filename = prefix;
460 }
461 else
462 {
463 filename = pcapHelper.GetFilenameFromInterfacePair(prefix, ipv4, interface);
464 }
465
466 Ptr<PcapFileWrapper> file = pcapHelper.CreateFile(filename, std::ios::out, iana::linktype::RAW);
467
468 //
469 // However, we only hook the trace source once to avoid multiple trace sink
470 // calls per event (connect is independent of interface).
471 //
472 if (!PcapHooked(ipv4))
473 {
474 //
475 // Ptr<Ipv4> is aggregated to node and Ipv4L3Protocol is aggregated to
476 // node so we can get to Ipv4L3Protocol through Ipv4.
477 //
478 Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol>();
479 NS_ASSERT_MSG(ipv4L3Protocol,
480 "InternetStackHelper::EnablePcapIpv4Internal(): "
481 "m_ipv4Enabled and ipv4L3Protocol inconsistent");
482
483 bool result =
484 ipv4L3Protocol->TraceConnectWithoutContext("Tx", MakeCallback(&Ipv4L3ProtocolRxTxSink));
485 NS_ASSERT_MSG(result == true,
486 "InternetStackHelper::EnablePcapIpv4Internal(): "
487 "Unable to connect ipv4L3Protocol \"Tx\"");
488
489 result =
490 ipv4L3Protocol->TraceConnectWithoutContext("Rx", MakeCallback(&Ipv4L3ProtocolRxTxSink));
491 NS_ASSERT_MSG(result == true,
492 "InternetStackHelper::EnablePcapIpv4Internal(): "
493 "Unable to connect ipv4L3Protocol \"Rx\"");
494 }
495
496 g_interfaceFileMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] = file;
497}
498
499/**
500 * @brief Sync function for IPv6 packet - Pcap output
501 * @param p smart pointer to the packet
502 * @param ipv6 smart pointer to the node's IPv6 stack
503 * @param interface incoming interface
504 */
505static void
507{
508 NS_LOG_FUNCTION(p << ipv6 << interface);
509
510 //
511 // Since trace sources are independent of interface, if we hook a source
512 // on a particular protocol we will get traces for all of its interfaces.
513 // We need to filter this to only report interfaces for which the user
514 // has expressed interest.
515 //
516 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
517 if (g_interfaceFileMapIpv6.find(pair) == g_interfaceFileMapIpv6.end())
518 {
519 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
520 return;
521 }
522
524 file->Write(Simulator::Now(), p);
525}
526
527bool
529{
530 auto id = ipv6->GetObject<Node>()->GetId();
531
532 for (auto i = g_interfaceFileMapIpv6.begin(); i != g_interfaceFileMapIpv6.end(); ++i)
533 {
534 if ((*i).first.first == id)
535 {
536 return true;
537 }
538 }
539 return false;
540}
541
542void
544 Ptr<Ipv6> ipv6,
545 uint32_t interface,
546 bool explicitFilename)
547{
548 NS_LOG_FUNCTION(prefix << ipv6 << interface);
549
550 if (!m_ipv6Enabled)
551 {
552 NS_LOG_INFO("Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
553 return;
554 }
555
556 //
557 // We have to create a file and a mapping from protocol/interface to file
558 // irrespective of how many times we want to trace a particular protocol.
559 //
560 PcapHelper pcapHelper;
561
562 std::string filename;
563 if (explicitFilename)
564 {
565 filename = prefix;
566 }
567 else
568 {
569 filename = pcapHelper.GetFilenameFromInterfacePair(prefix, ipv6, interface);
570 }
571
572 Ptr<PcapFileWrapper> file = pcapHelper.CreateFile(filename, std::ios::out, iana::linktype::RAW);
573
574 //
575 // However, we only hook the trace source once to avoid multiple trace sink
576 // calls per event (connect is independent of interface).
577 //
578 if (!PcapHooked(ipv6))
579 {
580 //
581 // Ptr<Ipv6> is aggregated to node and Ipv6L3Protocol is aggregated to
582 // node so we can get to Ipv6L3Protocol through Ipv6.
583 //
584 Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol>();
585 NS_ASSERT_MSG(ipv6L3Protocol,
586 "InternetStackHelper::EnablePcapIpv6Internal(): "
587 "m_ipv6Enabled and ipv6L3Protocol inconsistent");
588
589 bool result =
590 ipv6L3Protocol->TraceConnectWithoutContext("Tx", MakeCallback(&Ipv6L3ProtocolRxTxSink));
591 NS_ASSERT_MSG(result == true,
592 "InternetStackHelper::EnablePcapIpv6Internal(): "
593 "Unable to connect ipv6L3Protocol \"Tx\"");
594
595 result =
596 ipv6L3Protocol->TraceConnectWithoutContext("Rx", MakeCallback(&Ipv6L3ProtocolRxTxSink));
597 NS_ASSERT_MSG(result == true,
598 "InternetStackHelper::EnablePcapIpv6Internal(): "
599 "Unable to connect ipv6L3Protocol \"Rx\"");
600 }
601
602 g_interfaceFileMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] = file;
603}
604
605/**
606 * @brief Sync function for IPv4 dropped packet - Ascii output
607 * @param stream the output stream
608 * @param header IPv4 header
609 * @param packet smart pointer to the packet
610 * @param reason the reason for the dropping
611 * @param ipv4 smart pointer to the node's IPv4 stack
612 * @param interface incoming interface
613 */
614static void
616 const Ipv4Header& header,
617 Ptr<const Packet> packet,
619 Ptr<Ipv4> ipv4,
620 uint32_t interface)
621{
622 //
623 // Since trace sources are independent of interface, if we hook a source
624 // on a particular protocol we will get traces for all of its interfaces.
625 // We need to filter this to only report interfaces for which the user
626 // has expressed interest.
627 //
628 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
630 {
631 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
632 return;
633 }
634
635 Ptr<Packet> p = packet->Copy();
636 p->AddHeader(header);
637 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << *p << std::endl;
638}
639
640/**
641 * @brief Sync function for IPv4 transmitted 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);
654
656 {
657 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
658 return;
659 }
660 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
661}
662
663/**
664 * @brief Sync function for IPv4 received packet - Ascii output
665 * @param stream the output stream
666 * @param packet smart pointer to the packet
667 * @param ipv4 smart pointer to the node's IPv4 stack
668 * @param interface incoming interface
669 */
670static void
672 Ptr<const Packet> packet,
673 Ptr<Ipv4> ipv4,
674 uint32_t interface)
675{
676 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
678 {
679 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
680 return;
681 }
682
683 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
684}
685
686/**
687 * @brief Sync function for IPv4 dropped packet - Ascii output
688 * @param stream the output stream
689 * @param context the context
690 * @param header IPv4 header
691 * @param packet smart pointer to the packet
692 * @param reason the reason for the dropping
693 * @param ipv4 smart pointer to the node's IPv4 stack
694 * @param interface incoming interface
695 */
696static void
698 std::string context,
699 const Ipv4Header& header,
700 Ptr<const Packet> packet,
702 Ptr<Ipv4> ipv4,
703 uint32_t interface)
704{
705 //
706 // Since trace sources are independent of interface, if we hook a source
707 // on a particular protocol we will get traces for all of its interfaces.
708 // We need to filter this to only report interfaces for which the user
709 // has expressed interest.
710 //
711 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
713 {
714 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
715 return;
716 }
717
718 Ptr<Packet> p = packet->Copy();
719 p->AddHeader(header);
720#ifdef INTERFACE_CONTEXT
721 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << "("
722 << interface << ") " << *p << std::endl;
723#else
724 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << " " << *p
725 << std::endl;
726#endif
727}
728
729/**
730 * @brief Sync function for IPv4 transmitted packet - Ascii output
731 * @param stream the output stream
732 * @param context the context
733 * @param packet smart pointer to the packet
734 * @param ipv4 smart pointer to the node's IPv4 stack
735 * @param interface incoming interface
736 */
737static void
739 std::string context,
740 Ptr<const Packet> packet,
741 Ptr<Ipv4> ipv4,
742 uint32_t interface)
743{
744 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
746 {
747 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
748 return;
749 }
750
751#ifdef INTERFACE_CONTEXT
752 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << "("
753 << interface << ") " << *packet << std::endl;
754#else
755 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << " "
756 << *packet << std::endl;
757#endif
758}
759
760/**
761 * @brief Sync function for IPv4 received packet - Ascii output
762 * @param stream the output stream
763 * @param context the context
764 * @param packet smart pointer to the packet
765 * @param ipv4 smart pointer to the node's IPv4 stack
766 * @param interface incoming interface
767 */
768static void
770 std::string context,
771 Ptr<const Packet> packet,
772 Ptr<Ipv4> ipv4,
773 uint32_t interface)
774{
775 InterfacePairIpv4 pair = std::make_pair(ipv4->GetObject<Node>()->GetId(), interface);
777 {
778 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
779 return;
780 }
781
782#ifdef INTERFACE_CONTEXT
783 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << "("
784 << interface << ") " << *packet << std::endl;
785#else
786 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << " "
787 << *packet << std::endl;
788#endif
789}
790
791bool
793{
794 auto id = ipv4->GetObject<Node>()->GetId();
795
796 for (auto i = g_interfaceStreamMapIpv4.begin(); i != g_interfaceStreamMapIpv4.end(); ++i)
797 {
798 if ((*i).first.first == id)
799 {
800 return true;
801 }
802 }
803 return false;
804}
805
806void
808 std::string prefix,
809 Ptr<Ipv4> ipv4,
810 uint32_t interface,
811 bool explicitFilename)
812{
813 if (!m_ipv4Enabled)
814 {
815 NS_LOG_INFO("Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
816 return;
817 }
818
819 //
820 // Our trace sinks are going to use packet printing, so we have to
821 // make sure that is turned on.
822 //
824
825 //
826 // If we are not provided an OutputStreamWrapper, we are expected to create
827 // one using the usual trace filename conventions and hook WithoutContext
828 // since there will be one file per context and therefore the context would
829 // be redundant.
830 //
831 if (!stream)
832 {
833 //
834 // Set up an output stream object to deal with private ofstream copy
835 // constructor and lifetime issues. Let the helper decide the actual
836 // name of the file given the prefix.
837 //
838 // We have to create a stream and a mapping from protocol/interface to
839 // stream irrespective of how many times we want to trace a particular
840 // protocol.
841 //
842 AsciiTraceHelper asciiTraceHelper;
843
844 std::string filename;
845 if (explicitFilename)
846 {
847 filename = prefix;
848 }
849 else
850 {
851 filename = asciiTraceHelper.GetFilenameFromInterfacePair(prefix, ipv4, interface);
852 }
853
854 Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream(filename);
855
856 //
857 // However, we only hook the trace sources once to avoid multiple trace sink
858 // calls per event (connect is independent of interface).
859 //
860 if (!AsciiHooked(ipv4))
861 {
862 //
863 // We can use the default drop sink for the ArpL3Protocol since it has
864 // the usual signature. We can get to the Ptr<ArpL3Protocol> through
865 // our Ptr<Ipv4> since they must both be aggregated to the same node.
866 //
867 Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol>();
868 asciiTraceHelper.HookDefaultDropSinkWithoutContext<ArpL3Protocol>(arpL3Protocol,
869 "Drop",
870 theStream);
871
872 //
873 // The drop sink for the Ipv4L3Protocol uses a different signature than
874 // the default sink, so we have to cook one up for ourselves. We can get
875 // to the Ptr<Ipv4L3Protocol> through our Ptr<Ipv4> since they must both
876 // be aggregated to the same node.
877 //
878 Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol>();
879 bool result = ipv4L3Protocol->TraceConnectWithoutContext(
880 "Drop",
882 NS_ASSERT_MSG(result == true,
883 "InternetStackHelper::EnableAsciiIpv4Internal(): "
884 "Unable to connect ipv4L3Protocol \"Drop\"");
885 result = ipv4L3Protocol->TraceConnectWithoutContext(
886 "Tx",
888 NS_ASSERT_MSG(result == true,
889 "InternetStackHelper::EnableAsciiIpv4Internal(): "
890 "Unable to connect ipv4L3Protocol \"Tx\"");
891 result = ipv4L3Protocol->TraceConnectWithoutContext(
892 "Rx",
894 NS_ASSERT_MSG(result == true,
895 "InternetStackHelper::EnableAsciiIpv4Internal(): "
896 "Unable to connect ipv4L3Protocol \"Rx\"");
897 }
898
899 g_interfaceStreamMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] =
900 theStream;
901 return;
902 }
903
904 //
905 // If we are provided an OutputStreamWrapper, we are expected to use it, and
906 // to provide a context. We are free to come up with our own context if we
907 // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
908 // compatibility and simplicity, we just use Config::Connect and let it deal
909 // with the context.
910 //
911 // We need to associate the ipv4/interface with a stream to express interest
912 // in tracing events on that pair, however, we only hook the trace sources
913 // once to avoid multiple trace sink calls per event (connect is independent
914 // of interface).
915 //
916 if (!AsciiHooked(ipv4))
917 {
918 Ptr<Node> node = ipv4->GetObject<Node>();
919 std::ostringstream oss;
920
921 //
922 // For the ARP Drop, we are going to use the default trace sink provided by
923 // the ascii trace helper. There is actually no AsciiTraceHelper in sight
924 // here, but the default trace sinks are actually publicly available static
925 // functions that are always there waiting for just such a case.
926 //
927 oss << "/NodeList/" << node->GetId() << "/$ns3::ArpL3Protocol/Drop";
928 Config::Connect(oss.str(),
930
931 //
932 // This has all kinds of parameters coming with, so we have to cook up our
933 // own sink.
934 //
935 oss.str("");
936 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Drop";
938 oss.str("");
939 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Tx";
941 oss.str("");
942 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv4L3Protocol/Rx";
944 }
945
946 g_interfaceStreamMapIpv4[std::make_pair(ipv4->GetObject<Node>()->GetId(), interface)] = stream;
947}
948
949/**
950 * @brief Sync function for IPv6 dropped packet - Ascii output
951 * @param stream the output stream
952 * @param header IPv6 header
953 * @param packet smart pointer to the packet
954 * @param reason the reason for the dropping
955 * @param ipv6 smart pointer to the node's IPv6 stack
956 * @param interface incoming interface
957 */
958static void
960 const Ipv6Header& header,
961 Ptr<const Packet> packet,
963 Ptr<Ipv6> ipv6,
964 uint32_t interface)
965{
966 //
967 // Since trace sources are independent of interface, if we hook a source
968 // on a particular protocol we will get traces for all of its interfaces.
969 // We need to filter this to only report interfaces for which the user
970 // has expressed interest.
971 //
972 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
974 {
975 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
976 return;
977 }
978
979 Ptr<Packet> p = packet->Copy();
980 p->AddHeader(header);
981 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << *p << std::endl;
982}
983
984/**
985 * @brief Sync function for IPv6 transmitted 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() << "t " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
1005}
1006
1007/**
1008 * @brief Sync function for IPv6 received packet - Ascii output
1009 * @param stream the output stream
1010 * @param packet smart pointer to the packet
1011 * @param ipv6 smart pointer to the node's IPv6 stack
1012 * @param interface incoming interface
1013 */
1014static void
1016 Ptr<const Packet> packet,
1017 Ptr<Ipv6> ipv6,
1018 uint32_t interface)
1019{
1020 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1021 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1022 {
1023 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1024 return;
1025 }
1026
1027 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << *packet << std::endl;
1028}
1029
1030/**
1031 * @brief Sync function for IPv6 dropped packet - Ascii output
1032 * @param stream the output stream
1033 * @param context the context
1034 * @param header IPv6 header
1035 * @param packet smart pointer to the packet
1036 * @param reason the reason for the dropping
1037 * @param ipv6 smart pointer to the node's IPv6 stack
1038 * @param interface incoming interface
1039 */
1040static void
1042 std::string context,
1043 const Ipv6Header& header,
1044 Ptr<const Packet> packet,
1046 Ptr<Ipv6> ipv6,
1047 uint32_t interface)
1048{
1049 //
1050 // Since trace sources are independent of interface, if we hook a source
1051 // on a particular protocol we will get traces for all of its interfaces.
1052 // We need to filter this to only report interfaces for which the user
1053 // has expressed interest.
1054 //
1055 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1056 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1057 {
1058 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1059 return;
1060 }
1061
1062 Ptr<Packet> p = packet->Copy();
1063 p->AddHeader(header);
1064#ifdef INTERFACE_CONTEXT
1065 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << "("
1066 << interface << ") " << *p << std::endl;
1067#else
1068 *stream->GetStream() << "d " << Simulator::Now().GetSeconds() << " " << context << " " << *p
1069 << std::endl;
1070#endif
1071}
1072
1073/**
1074 * @brief Sync function for IPv6 transmitted packet - Ascii output
1075 * @param stream the output stream
1076 * @param context the context
1077 * @param packet smart pointer to the packet
1078 * @param ipv6 smart pointer to the node's IPv6 stack
1079 * @param interface incoming interface
1080 */
1081static void
1083 std::string context,
1084 Ptr<const Packet> packet,
1085 Ptr<Ipv6> ipv6,
1086 uint32_t interface)
1087{
1088 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1089 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1090 {
1091 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1092 return;
1093 }
1094
1095#ifdef INTERFACE_CONTEXT
1096 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << "("
1097 << interface << ") " << *packet << std::endl;
1098#else
1099 *stream->GetStream() << "t " << Simulator::Now().GetSeconds() << " " << context << " "
1100 << *packet << std::endl;
1101#endif
1102}
1103
1104/**
1105 * @brief Sync function for IPv6 received packet - Ascii output
1106 * @param stream the output stream
1107 * @param context the context
1108 * @param packet smart pointer to the packet
1109 * @param ipv6 smart pointer to the node's IPv6 stack
1110 * @param interface incoming interface
1111 */
1112static void
1114 std::string context,
1115 Ptr<const Packet> packet,
1116 Ptr<Ipv6> ipv6,
1117 uint32_t interface)
1118{
1119 InterfacePairIpv6 pair = std::make_pair(ipv6->GetObject<Node>()->GetId(), interface);
1120 if (g_interfaceStreamMapIpv6.find(pair) == g_interfaceStreamMapIpv6.end())
1121 {
1122 NS_LOG_INFO("Ignoring packet to/from interface " << interface);
1123 return;
1124 }
1125
1126#ifdef INTERFACE_CONTEXT
1127 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << "("
1128 << interface << ") " << *packet << std::endl;
1129#else
1130 *stream->GetStream() << "r " << Simulator::Now().GetSeconds() << " " << context << " "
1131 << *packet << std::endl;
1132#endif
1133}
1134
1135bool
1137{
1138 auto id = ipv6->GetObject<Node>()->GetId();
1139
1140 for (auto i = g_interfaceStreamMapIpv6.begin(); i != g_interfaceStreamMapIpv6.end(); ++i)
1141 {
1142 if ((*i).first.first == id)
1143 {
1144 return true;
1145 }
1146 }
1147 return false;
1148}
1149
1150void
1152 std::string prefix,
1153 Ptr<Ipv6> ipv6,
1154 uint32_t interface,
1155 bool explicitFilename)
1156{
1157 if (!m_ipv6Enabled)
1158 {
1159 NS_LOG_INFO("Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1160 return;
1161 }
1162
1163 //
1164 // Our trace sinks are going to use packet printing, so we have to
1165 // make sure that is turned on.
1166 //
1168
1169 //
1170 // If we are not provided an OutputStreamWrapper, we are expected to create
1171 // one using the usual trace filename conventions and do a hook WithoutContext
1172 // since there will be one file per context and therefore the context would
1173 // be redundant.
1174 //
1175 if (!stream)
1176 {
1177 //
1178 // Set up an output stream object to deal with private ofstream copy
1179 // constructor and lifetime issues. Let the helper decide the actual
1180 // name of the file given the prefix.
1181 //
1182 // We have to create a stream and a mapping from protocol/interface to
1183 // stream irrespective of how many times we want to trace a particular
1184 // protocol.
1185 //
1186 AsciiTraceHelper asciiTraceHelper;
1187
1188 std::string filename;
1189 if (explicitFilename)
1190 {
1191 filename = prefix;
1192 }
1193 else
1194 {
1195 filename = asciiTraceHelper.GetFilenameFromInterfacePair(prefix, ipv6, interface);
1196 }
1197
1198 Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream(filename);
1199
1200 //
1201 // However, we only hook the trace sources once to avoid multiple trace sink
1202 // calls per event (connect is independent of interface).
1203 //
1204 if (!AsciiHooked(ipv6))
1205 {
1206 //
1207 // The drop sink for the Ipv6L3Protocol uses a different signature than
1208 // the default sink, so we have to cook one up for ourselves. We can get
1209 // to the Ptr<Ipv6L3Protocol> through our Ptr<Ipv6> since they must both
1210 // be aggregated to the same node.
1211 //
1212 Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol>();
1213 bool result = ipv6L3Protocol->TraceConnectWithoutContext(
1214 "Drop",
1216 NS_ASSERT_MSG(result == true,
1217 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1218 "Unable to connect ipv6L3Protocol \"Drop\"");
1219 result = ipv6L3Protocol->TraceConnectWithoutContext(
1220 "Tx",
1222 NS_ASSERT_MSG(result == true,
1223 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1224 "Unable to connect ipv6L3Protocol \"Tx\"");
1225 result = ipv6L3Protocol->TraceConnectWithoutContext(
1226 "Rx",
1228 NS_ASSERT_MSG(result == true,
1229 "InternetStackHelper::EnableAsciiIpv6Internal(): "
1230 "Unable to connect ipv6L3Protocol \"Rx\"");
1231 }
1232
1233 g_interfaceStreamMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] =
1234 theStream;
1235 return;
1236 }
1237
1238 //
1239 // If we are provided an OutputStreamWrapper, we are expected to use it, and
1240 // to provide a context. We are free to come up with our own context if we
1241 // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
1242 // compatibility and simplicity, we just use Config::Connect and let it deal
1243 // with the context.
1244 //
1245 // We need to associate the ipv4/interface with a stream to express interest
1246 // in tracing events on that pair, however, we only hook the trace sources
1247 // once to avoid multiple trace sink calls per event (connect is independent
1248 // of interface).
1249 //
1250 if (!AsciiHooked(ipv6))
1251 {
1252 Ptr<Node> node = ipv6->GetObject<Node>();
1253 std::ostringstream oss;
1254
1255 oss.str("");
1256 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Drop";
1258 oss.str("");
1259 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Tx";
1261 oss.str("");
1262 oss << "/NodeList/" << node->GetId() << "/$ns3::Ipv6L3Protocol/Rx";
1264 }
1265
1266 g_interfaceStreamMapIpv6[std::make_pair(ipv6->GetObject<Node>()->GetId(), interface)] = stream;
1267}
1268
1269} // 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.
Helper class that adds ns3::Ipv4GlobalRouting objects.
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.
Helper class that adds ns3::Ipv6ListRouting objects.
void Add(const Ipv6RoutingHelper &routing, int16_t priority)
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:586
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.
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.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, uint16_t dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0)
Create and initialize a pcap file.
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:874
#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:76
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:966
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#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:274
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
constexpr uint16_t RAW
Raw IP; begins with an IPv4 or IPv6 header.
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.