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