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