A Discrete-Event Network Simulator
API
internet-stack-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
20  */
21 
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/object.h"
25 #include "ns3/names.h"
26 #include "ns3/ipv4.h"
27 #include "ns3/ipv6.h"
28 #include "ns3/packet-socket-factory.h"
29 #include "ns3/config.h"
30 #include "ns3/simulator.h"
31 #include "ns3/string.h"
32 #include "ns3/net-device.h"
33 #include "ns3/callback.h"
34 #include "ns3/node.h"
35 #include "ns3/node-list.h"
36 #include "ns3/core-config.h"
37 #include "ns3/arp-l3-protocol.h"
38 #include "internet-stack-helper.h"
39 #include "ns3/ipv4-global-routing.h"
40 #include "ns3/ipv4-list-routing-helper.h"
41 #include "ns3/ipv4-static-routing-helper.h"
42 #include "ns3/ipv4-global-routing-helper.h"
43 #include "ns3/ipv6-static-routing-helper.h"
44 #include "ns3/ipv6-extension.h"
45 #include "ns3/ipv6-extension-demux.h"
46 #include "ns3/ipv6-extension-header.h"
47 #include "ns3/icmpv6-l4-protocol.h"
48 #include "ns3/global-router-interface.h"
49 #include "ns3/traffic-control-layer.h"
50 #include <limits>
51 #include <map>
52 
53 namespace ns3 {
54 
55 NS_LOG_COMPONENT_DEFINE ("InternetStackHelper");
56 
57 //
58 // Historically, the only context written to ascii traces was the protocol.
59 // Traces from the protocols include the interface, though. It is not
60 // possible to really determine where an event originated without including
61 // this. If you want the additional context information, define
62 // INTERFACE_CONTEXT. If you want compatibility with the old-style traces
63 // comment it out.
64 //
65 #define INTERFACE_CONTEXT
66 
67 //
68 // Things are going to work differently here with respect to trace file handling
69 // than in most places because the Tx and Rx trace sources we are interested in
70 // are going to multiplex receive and transmit callbacks for all Ipv4 and
71 // interface pairs through one callback. We want packets to or from each
72 // distinct pair to go to an individual file, so we have got to demultiplex the
73 // Ipv4 and interface pair into a corresponding Ptr<PcapFileWrapper> at the
74 // callback.
75 //
76 // A complication in this situation is that the trace sources are hooked on
77 // a protocol basis. There is no trace source hooked by an Ipv4 and interface
78 // pair. This means that if we naively proceed to hook, say, a drop trace
79 // for a given Ipv4 with interface 0, and then hook for Ipv4 with interface 1
80 // we will hook the drop trace twice and get two callbacks per event. What
81 // we need to do is to hook the event once, and that will result in a single
82 // callback per drop event, and the trace source will provide the interface
83 // which we filter on in the trace sink.
84 //
85 // This has got to continue to work properly after the helper has been
86 // destroyed; but must be cleaned up at the end of time to avoid leaks.
87 // Global maps of protocol/interface pairs to file objects seems to fit the
88 // bill.
89 //
90 typedef std::pair<Ptr<Ipv4>, uint32_t> InterfacePairIpv4;
91 typedef std::map<InterfacePairIpv4, Ptr<PcapFileWrapper> > InterfaceFileMapIpv4;
92 typedef std::map<InterfacePairIpv4, Ptr<OutputStreamWrapper> > InterfaceStreamMapIpv4;
94 static InterfaceFileMapIpv4 g_interfaceFileMapIpv4;
95 static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4;
97 typedef std::pair<Ptr<Ipv6>, uint32_t> InterfacePairIpv6;
98 typedef std::map<InterfacePairIpv6, Ptr<PcapFileWrapper> > InterfaceFileMapIpv6;
99 typedef std::map<InterfacePairIpv6, Ptr<OutputStreamWrapper> > InterfaceStreamMapIpv6;
101 static InterfaceFileMapIpv6 g_interfaceFileMapIpv6;
102 static InterfaceStreamMapIpv6 g_interfaceStreamMapIpv6;
105  : m_routing (0),
106  m_routingv6 (0),
107  m_ipv4Enabled (true),
108  m_ipv6Enabled (true),
109  m_ipv4ArpJitterEnabled (true),
110  m_ipv6NsRsJitterEnabled (true)
111 
112 {
113  Initialize ();
114 }
115 
116 // private method called by both constructor and Reset ()
117 void
119 {
120  SetTcp ("ns3::TcpL4Protocol");
121  Ipv4StaticRoutingHelper staticRouting;
122  Ipv4GlobalRoutingHelper globalRouting;
123  Ipv4ListRoutingHelper listRouting;
124  Ipv6StaticRoutingHelper staticRoutingv6;
125  listRouting.Add (staticRouting, 0);
126  listRouting.Add (globalRouting, -10);
127  SetRoutingHelper (listRouting);
128  SetRoutingHelper (staticRoutingv6);
129 }
130 
132 {
133  delete m_routing;
134  delete m_routingv6;
135 }
136 
138 {
139  m_routing = o.m_routing->Copy ();
140  m_routingv6 = o.m_routingv6->Copy ();
146 }
147 
150 {
151  if (this == &o)
152  {
153  return *this;
154  }
155  m_routing = o.m_routing->Copy ();
156  m_routingv6 = o.m_routingv6->Copy ();
157  return *this;
158 }
159 
160 void
162 {
163  delete m_routing;
164  m_routing = 0;
165  delete m_routingv6;
166  m_routingv6 = 0;
167  m_ipv4Enabled = true;
168  m_ipv6Enabled = true;
169  m_ipv4ArpJitterEnabled = true;
171  Initialize ();
172 }
173 
174 void
176 {
177  delete m_routing;
178  m_routing = routing.Copy ();
179 }
180 
181 void
183 {
184  delete m_routingv6;
185  m_routingv6 = routing.Copy ();
186 }
187 
188 void
190 {
191  m_ipv4Enabled = enable;
192 }
193 
195 {
196  m_ipv6Enabled = enable;
197 }
198 
200 {
201  m_ipv4ArpJitterEnabled = enable;
202 }
203 
205 {
206  m_ipv6NsRsJitterEnabled = enable;
207 }
208 
209 int64_t
211 {
212  int64_t currentStream = stream;
213  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
214  {
215  Ptr<Node> node = *i;
216  Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
217  if (router != 0)
218  {
219  Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
220  if (gr != 0)
221  {
222  currentStream += gr->AssignStreams (currentStream);
223  }
224  }
226  if (demux != 0)
227  {
228  Ptr<Ipv6Extension> fe = demux->GetExtension (Ipv6ExtensionFragment::EXT_NUMBER);
229  NS_ASSERT (fe); // should always exist in the demux
230  currentStream += fe->AssignStreams (currentStream);
231  }
232  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
233  if (ipv4 != 0)
234  {
235  Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol> ();
236  if (arpL3Protocol != 0)
237  {
238  currentStream += arpL3Protocol->AssignStreams (currentStream);
239  }
240  }
241  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
242  if (ipv6 != 0)
243  {
244  Ptr<Icmpv6L4Protocol> icmpv6L4Protocol = ipv6->GetObject<Icmpv6L4Protocol> ();
245  if (icmpv6L4Protocol != 0)
246  {
247  currentStream += icmpv6L4Protocol->AssignStreams (currentStream);
248  }
249  }
250  }
251  return (currentStream - stream);
252 }
253 
254 void
255 InternetStackHelper::SetTcp (const std::string tid)
256 {
257  m_tcpFactory.SetTypeId (tid);
258 }
259 
260 void
261 InternetStackHelper::SetTcp (std::string tid, std::string n0, const AttributeValue &v0)
262 {
263  m_tcpFactory.SetTypeId (tid);
264  m_tcpFactory.Set (n0,v0);
265 }
266 
267 void
269 {
270  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
271  {
272  Install (*i);
273  }
274 }
275 
276 void
278 {
280 }
281 
282 void
284 {
285  ObjectFactory factory;
286  factory.SetTypeId (typeId);
287  Ptr<Object> protocol = factory.Create <Object> ();
288  node->AggregateObject (protocol);
289 }
290 
291 void
293 {
294  if (m_ipv4Enabled)
295  {
296  if (node->GetObject<Ipv4> () != 0)
297  {
298  NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating "
299  "an InternetStack to a node with an existing Ipv4 object");
300  return;
301  }
302 
303  CreateAndAggregateObjectFromTypeId (node, "ns3::ArpL3Protocol");
304  CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv4L3Protocol");
305  CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv4L4Protocol");
306  if (m_ipv4ArpJitterEnabled == false)
307  {
309  NS_ASSERT (arp);
310  arp->SetAttribute ("RequestJitter", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
311  }
312  // Set routing
313  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
314  Ptr<Ipv4RoutingProtocol> ipv4Routing = m_routing->Create (node);
315  ipv4->SetRoutingProtocol (ipv4Routing);
316  }
317 
318  if (m_ipv6Enabled)
319  {
320  /* IPv6 stack */
321  if (node->GetObject<Ipv6> () != 0)
322  {
323  NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating "
324  "an InternetStack to a node with an existing Ipv6 object");
325  return;
326  }
327 
328  CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv6L3Protocol");
329  CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv6L4Protocol");
330  if (m_ipv6NsRsJitterEnabled == false)
331  {
332  Ptr<Icmpv6L4Protocol> icmpv6l4 = node->GetObject<Icmpv6L4Protocol> ();
333  NS_ASSERT (icmpv6l4);
334  icmpv6l4->SetAttribute ("SolicitationJitter", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
335  }
336  // Set routing
337  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
338  Ptr<Ipv6RoutingProtocol> ipv6Routing = m_routingv6->Create (node);
339  ipv6->SetRoutingProtocol (ipv6Routing);
340 
341  /* register IPv6 extensions and options */
342  ipv6->RegisterExtensions ();
343  ipv6->RegisterOptions ();
344  }
345 
347  {
348  CreateAndAggregateObjectFromTypeId (node, "ns3::TrafficControlLayer");
349  CreateAndAggregateObjectFromTypeId (node, "ns3::UdpL4Protocol");
351  Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
352  node->AggregateObject (factory);
353  }
354 }
355 
356 void
357 InternetStackHelper::Install (std::string nodeName) const
358 {
359  Ptr<Node> node = Names::Find<Node> (nodeName);
360  Install (node);
361 }
362 
369 static void
371 {
372  NS_LOG_FUNCTION (p << ipv4 << interface);
373 
374  //
375  // Since trace sources are independent of interface, if we hook a source
376  // on a particular protocol we will get traces for all of its interfaces.
377  // We need to filter this to only report interfaces for which the user
378  // has expressed interest.
379  //
380  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
381  if (g_interfaceFileMapIpv4.find (pair) == g_interfaceFileMapIpv4.end ())
382  {
383  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
384  return;
385  }
386 
387  Ptr<PcapFileWrapper> file = g_interfaceFileMapIpv4[pair];
388  file->Write (Simulator::Now (), p);
389 }
390 
391 bool
393 {
394  for ( InterfaceFileMapIpv4::const_iterator i = g_interfaceFileMapIpv4.begin ();
395  i != g_interfaceFileMapIpv4.end ();
396  ++i)
397  {
398  if ((*i).first.first == ipv4)
399  {
400  return true;
401  }
402  }
403  return false;
404 }
405 
406 void
407 InternetStackHelper::EnablePcapIpv4Internal (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename)
408 {
409  NS_LOG_FUNCTION (prefix << ipv4 << interface);
410 
411  if (!m_ipv4Enabled)
412  {
413  NS_LOG_INFO ("Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
414  return;
415  }
416 
417  //
418  // We have to create a file and a mapping from protocol/interface to file
419  // irrespective of how many times we want to trace a particular protocol.
420  //
421  PcapHelper pcapHelper;
422 
423  std::string filename;
424  if (explicitFilename)
425  {
426  filename = prefix;
427  }
428  else
429  {
430  filename = pcapHelper.GetFilenameFromInterfacePair (prefix, ipv4, interface);
431  }
432 
433  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, PcapHelper::DLT_RAW);
434 
435  //
436  // However, we only hook the trace source once to avoid multiple trace sink
437  // calls per event (connect is independent of interface).
438  //
439  if (!PcapHooked (ipv4))
440  {
441  //
442  // Ptr<Ipv4> is aggregated to node and Ipv4L3Protocol is aggregated to
443  // node so we can get to Ipv4L3Protocol through Ipv4.
444  //
445  Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol> ();
446  NS_ASSERT_MSG (ipv4L3Protocol, "InternetStackHelper::EnablePcapIpv4Internal(): "
447  "m_ipv4Enabled and ipv4L3Protocol inconsistent");
448 
449  bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx", MakeCallback (&Ipv4L3ProtocolRxTxSink));
450  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv4Internal(): "
451  "Unable to connect ipv4L3Protocol \"Tx\"");
452 
453  result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv4L3ProtocolRxTxSink));
454  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv4Internal(): "
455  "Unable to connect ipv4L3Protocol \"Rx\"");
456  }
457 
458  g_interfaceFileMapIpv4[std::make_pair (ipv4, interface)] = file;
459 }
460 
467 static void
469 {
470  NS_LOG_FUNCTION (p << ipv6 << interface);
471 
472  //
473  // Since trace sources are independent of interface, if we hook a source
474  // on a particular protocol we will get traces for all of its interfaces.
475  // We need to filter this to only report interfaces for which the user
476  // has expressed interest.
477  //
478  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
479  if (g_interfaceFileMapIpv6.find (pair) == g_interfaceFileMapIpv6.end ())
480  {
481  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
482  return;
483  }
484 
485  Ptr<PcapFileWrapper> file = g_interfaceFileMapIpv6[pair];
486  file->Write (Simulator::Now (), p);
487 }
488 
489 bool
491 {
492  for ( InterfaceFileMapIpv6::const_iterator i = g_interfaceFileMapIpv6.begin ();
493  i != g_interfaceFileMapIpv6.end ();
494  ++i)
495  {
496  if ((*i).first.first == ipv6)
497  {
498  return true;
499  }
500  }
501  return false;
502 }
503 
504 void
505 InternetStackHelper::EnablePcapIpv6Internal (std::string prefix, Ptr<Ipv6> ipv6, uint32_t interface, bool explicitFilename)
506 {
507  NS_LOG_FUNCTION (prefix << ipv6 << interface);
508 
509  if (!m_ipv6Enabled)
510  {
511  NS_LOG_INFO ("Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
512  return;
513  }
514 
515  //
516  // We have to create a file and a mapping from protocol/interface to file
517  // irrespective of how many times we want to trace a particular protocol.
518  //
519  PcapHelper pcapHelper;
520 
521  std::string filename;
522  if (explicitFilename)
523  {
524  filename = prefix;
525  }
526  else
527  {
528  filename = pcapHelper.GetFilenameFromInterfacePair (prefix, ipv6, interface);
529  }
530 
531  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, PcapHelper::DLT_RAW);
532 
533  //
534  // However, we only hook the trace source once to avoid multiple trace sink
535  // calls per event (connect is independent of interface).
536  //
537  if (!PcapHooked (ipv6))
538  {
539  //
540  // Ptr<Ipv6> is aggregated to node and Ipv6L3Protocol is aggregated to
541  // node so we can get to Ipv6L3Protocol through Ipv6.
542  //
543  Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol> ();
544  NS_ASSERT_MSG (ipv6L3Protocol, "InternetStackHelper::EnablePcapIpv6Internal(): "
545  "m_ipv6Enabled and ipv6L3Protocol inconsistent");
546 
547  bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx", MakeCallback (&Ipv6L3ProtocolRxTxSink));
548  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv6Internal(): "
549  "Unable to connect ipv6L3Protocol \"Tx\"");
550 
551  result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv6L3ProtocolRxTxSink));
552  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv6Internal(): "
553  "Unable to connect ipv6L3Protocol \"Rx\"");
554  }
555 
556  g_interfaceFileMapIpv6[std::make_pair (ipv6, interface)] = file;
557 }
558 
568 static void
571  Ipv4Header const &header,
572  Ptr<const Packet> packet,
574  Ptr<Ipv4> ipv4,
575  uint32_t interface)
576 {
577  //
578  // Since trace sources are independent of interface, if we hook a source
579  // on a particular protocol we will get traces for all of its interfaces.
580  // We need to filter this to only report interfaces for which the user
581  // has expressed interest.
582  //
583  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
584  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
585  {
586  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
587  return;
588  }
589 
590  Ptr<Packet> p = packet->Copy ();
591  p->AddHeader (header);
592  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
593 }
594 
602 static void
605  Ptr<const Packet> packet,
606  Ptr<Ipv4> ipv4,
607  uint32_t interface)
608 {
609  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
610  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
611  {
612  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
613  return;
614  }
615 
616  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
617 }
618 
626 static void
629  Ptr<const Packet> packet,
630  Ptr<Ipv4> ipv4,
631  uint32_t interface)
632 {
633  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
634  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
635  {
636  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
637  return;
638  }
639 
640  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
641 }
642 
653 static void
656  std::string context,
657  Ipv4Header const &header,
658  Ptr<const Packet> packet,
660  Ptr<Ipv4> ipv4,
661  uint32_t interface)
662 {
663  //
664  // Since trace sources are independent of interface, if we hook a source
665  // on a particular protocol we will get traces for all of its interfaces.
666  // We need to filter this to only report interfaces for which the user
667  // has expressed interest.
668  //
669  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
670  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
671  {
672  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
673  return;
674  }
675 
676  Ptr<Packet> p = packet->Copy ();
677  p->AddHeader (header);
678 #ifdef INTERFACE_CONTEXT
679  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
680  << *p << std::endl;
681 #else
682  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
683 #endif
684 }
685 
694 static void
697  std::string context,
698  Ptr<const Packet> packet,
699  Ptr<Ipv4> ipv4,
700  uint32_t interface)
701 {
702  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
703  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
704  {
705  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
706  return;
707  }
708 
709 #ifdef INTERFACE_CONTEXT
710  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
711  << *packet << std::endl;
712 #else
713  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
714 #endif
715 }
716 
725 static void
728  std::string context,
729  Ptr<const Packet> packet,
730  Ptr<Ipv4> ipv4,
731  uint32_t interface)
732 {
733  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
734  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
735  {
736  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
737  return;
738  }
739 
740 #ifdef INTERFACE_CONTEXT
741  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
742  << *packet << std::endl;
743 #else
744  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
745 #endif
746 }
747 
748 bool
750 {
751  for ( InterfaceStreamMapIpv4::const_iterator i = g_interfaceStreamMapIpv4.begin ();
752  i != g_interfaceStreamMapIpv4.end ();
753  ++i)
754  {
755  if ((*i).first.first == ipv4)
756  {
757  return true;
758  }
759  }
760  return false;
761 }
762 
763 void
765  Ptr<OutputStreamWrapper> stream,
766  std::string prefix,
767  Ptr<Ipv4> ipv4,
768  uint32_t interface,
769  bool explicitFilename)
770 {
771  if (!m_ipv4Enabled)
772  {
773  NS_LOG_INFO ("Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
774  return;
775  }
776 
777  //
778  // Our trace sinks are going to use packet printing, so we have to
779  // make sure that is turned on.
780  //
782 
783  //
784  // If we are not provided an OutputStreamWrapper, we are expected to create
785  // one using the usual trace filename conventions and hook WithoutContext
786  // since there will be one file per context and therefore the context would
787  // be redundant.
788  //
789  if (stream == 0)
790  {
791  //
792  // Set up an output stream object to deal with private ofstream copy
793  // constructor and lifetime issues. Let the helper decide the actual
794  // name of the file given the prefix.
795  //
796  // We have to create a stream and a mapping from protocol/interface to
797  // stream irrespective of how many times we want to trace a particular
798  // protocol.
799  //
800  AsciiTraceHelper asciiTraceHelper;
801 
802  std::string filename;
803  if (explicitFilename)
804  {
805  filename = prefix;
806  }
807  else
808  {
809  filename = asciiTraceHelper.GetFilenameFromInterfacePair (prefix, ipv4, interface);
810  }
811 
812  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
813 
814  //
815  // However, we only hook the trace sources once to avoid multiple trace sink
816  // calls per event (connect is independent of interface).
817  //
818  if (!AsciiHooked (ipv4))
819  {
820  //
821  // We can use the default drop sink for the ArpL3Protocol since it has
822  // the usual signature. We can get to the Ptr<ArpL3Protocol> through
823  // our Ptr<Ipv4> since they must both be aggregated to the same node.
824  //
825  Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol> ();
826  asciiTraceHelper.HookDefaultDropSinkWithoutContext<ArpL3Protocol> (arpL3Protocol, "Drop", theStream);
827 
828  //
829  // The drop sink for the Ipv4L3Protocol uses a different signature than
830  // the default sink, so we have to cook one up for ourselves. We can get
831  // to the Ptr<Ipv4L3Protocol> through our Ptr<Ipv4> since they must both
832  // be aggregated to the same node.
833  //
834  Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol> ();
835  bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop",
837  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
838  "Unable to connect ipv4L3Protocol \"Drop\"");
839  result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx",
841  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
842  "Unable to connect ipv4L3Protocol \"Tx\"");
843  result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx",
845  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
846  "Unable to connect ipv4L3Protocol \"Rx\"");
847  }
848 
849  g_interfaceStreamMapIpv4[std::make_pair (ipv4, interface)] = theStream;
850  return;
851  }
852 
853  //
854  // If we are provided an OutputStreamWrapper, we are expected to use it, and
855  // to provide a context. We are free to come up with our own context if we
856  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
857  // compatibility and simplicity, we just use Config::Connect and let it deal
858  // with the context.
859  //
860  // We need to associate the ipv4/interface with a stream to express interest
861  // in tracing events on that pair, however, we only hook the trace sources
862  // once to avoid multiple trace sink calls per event (connect is independent
863  // of interface).
864  //
865  if (!AsciiHooked (ipv4))
866  {
867  Ptr<Node> node = ipv4->GetObject<Node> ();
868  std::ostringstream oss;
869 
870  //
871  // For the ARP Drop, we are going to use the default trace sink provided by
872  // the ascii trace helper. There is actually no AsciiTraceHelper in sight
873  // here, but the default trace sinks are actually publicly available static
874  // functions that are always there waiting for just such a case.
875  //
876  oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop";
878 
879  //
880  // This has all kinds of parameters coming with, so we have to cook up our
881  // own sink.
882  //
883  oss.str ("");
884  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop";
886  oss.str ("");
887  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Tx";
889  oss.str ("");
890  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Rx";
892  }
893 
894  g_interfaceStreamMapIpv4[std::make_pair (ipv4, interface)] = stream;
895 }
896 
906 static void
909  Ipv6Header const &header,
910  Ptr<const Packet> packet,
912  Ptr<Ipv6> ipv6,
913  uint32_t interface)
914 {
915  //
916  // Since trace sources are independent of interface, if we hook a source
917  // on a particular protocol we will get traces for all of its interfaces.
918  // We need to filter this to only report interfaces for which the user
919  // has expressed interest.
920  //
921  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
922  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
923  {
924  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
925  return;
926  }
927 
928  Ptr<Packet> p = packet->Copy ();
929  p->AddHeader (header);
930  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
931 }
932 
940 static void
943  Ptr<const Packet> packet,
944  Ptr<Ipv6> ipv6,
945  uint32_t interface)
946 {
947  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
948  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
949  {
950  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
951  return;
952  }
953 
954  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
955 }
956 
964 static void
967  Ptr<const Packet> packet,
968  Ptr<Ipv6> ipv6,
969  uint32_t interface)
970 {
971  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
972  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
973  {
974  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
975  return;
976  }
977 
978  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
979 }
980 
991 static void
994  std::string context,
995  Ipv6Header const &header,
996  Ptr<const Packet> packet,
998  Ptr<Ipv6> ipv6,
999  uint32_t interface)
1000 {
1001  //
1002  // Since trace sources are independent of interface, if we hook a source
1003  // on a particular protocol we will get traces for all of its interfaces.
1004  // We need to filter this to only report interfaces for which the user
1005  // has expressed interest.
1006  //
1007  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1008  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1009  {
1010  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1011  return;
1012  }
1013 
1014  Ptr<Packet> p = packet->Copy ();
1015  p->AddHeader (header);
1016 #ifdef INTERFACE_CONTEXT
1017  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1018  << *p << std::endl;
1019 #else
1020  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
1021 #endif
1022 }
1023 
1032 static void
1034  Ptr<OutputStreamWrapper> stream,
1035  std::string context,
1036  Ptr<const Packet> packet,
1037  Ptr<Ipv6> ipv6,
1038  uint32_t interface)
1039 {
1040  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1041  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1042  {
1043  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1044  return;
1045  }
1046 
1047 #ifdef INTERFACE_CONTEXT
1048  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1049  << *packet << std::endl;
1050 #else
1051  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
1052 #endif
1053 }
1054 
1063 static void
1065  Ptr<OutputStreamWrapper> stream,
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, 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 () << "r " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1080  << *packet << std::endl;
1081 #else
1082  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
1083 #endif
1084 }
1085 
1086 bool
1088 {
1089  for ( InterfaceStreamMapIpv6::const_iterator i = g_interfaceStreamMapIpv6.begin ();
1090  i != g_interfaceStreamMapIpv6.end ();
1091  ++i)
1092  {
1093  if ((*i).first.first == ipv6)
1094  {
1095  return true;
1096  }
1097  }
1098  return false;
1099 }
1100 
1101 void
1103  Ptr<OutputStreamWrapper> stream,
1104  std::string prefix,
1105  Ptr<Ipv6> ipv6,
1106  uint32_t interface,
1107  bool explicitFilename)
1108 {
1109  if (!m_ipv6Enabled)
1110  {
1111  NS_LOG_INFO ("Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1112  return;
1113  }
1114 
1115  //
1116  // Our trace sinks are going to use packet printing, so we have to
1117  // make sure that is turned on.
1118  //
1120 
1121  //
1122  // If we are not provided an OutputStreamWrapper, we are expected to create
1123  // one using the usual trace filename conventions and do a hook WithoutContext
1124  // since there will be one file per context and therefore the context would
1125  // be redundant.
1126  //
1127  if (stream == 0)
1128  {
1129  //
1130  // Set up an output stream object to deal with private ofstream copy
1131  // constructor and lifetime issues. Let the helper decide the actual
1132  // name of the file given the prefix.
1133  //
1134  // We have to create a stream and a mapping from protocol/interface to
1135  // stream irrespective of how many times we want to trace a particular
1136  // protocol.
1137  //
1138  AsciiTraceHelper asciiTraceHelper;
1139 
1140  std::string filename;
1141  if (explicitFilename)
1142  {
1143  filename = prefix;
1144  }
1145  else
1146  {
1147  filename = asciiTraceHelper.GetFilenameFromInterfacePair (prefix, ipv6, interface);
1148  }
1149 
1150  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
1151 
1152  //
1153  // However, we only hook the trace sources once to avoid multiple trace sink
1154  // calls per event (connect is independent of interface).
1155  //
1156  if (!AsciiHooked (ipv6))
1157  {
1158  //
1159  // The drop sink for the Ipv6L3Protocol uses a different signature than
1160  // the default sink, so we have to cook one up for ourselves. We can get
1161  // to the Ptr<Ipv6L3Protocol> through our Ptr<Ipv6> since they must both
1162  // be aggregated to the same node.
1163  //
1164  Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol> ();
1165  bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Drop",
1167  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1168  "Unable to connect ipv6L3Protocol \"Drop\"");
1169  result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx",
1171  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1172  "Unable to connect ipv6L3Protocol \"Tx\"");
1173  result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx",
1175  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1176  "Unable to connect ipv6L3Protocol \"Rx\"");
1177  }
1178 
1179  g_interfaceStreamMapIpv6[std::make_pair (ipv6, interface)] = theStream;
1180  return;
1181  }
1182 
1183  //
1184  // If we are provided an OutputStreamWrapper, we are expected to use it, and
1185  // to provide a context. We are free to come up with our own context if we
1186  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
1187  // compatibility and simplicity, we just use Config::Connect and let it deal
1188  // with the context.
1189  //
1190  // We need to associate the ipv4/interface with a stream to express interest
1191  // in tracing events on that pair, however, we only hook the trace sources
1192  // once to avoid multiple trace sink calls per event (connect is independent
1193  // of interface).
1194  //
1195  if (!AsciiHooked (ipv6))
1196  {
1197  Ptr<Node> node = ipv6->GetObject<Node> ();
1198  std::ostringstream oss;
1199 
1200  oss.str ("");
1201  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Drop";
1203  oss.str ("");
1204  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Tx";
1206  oss.str ("");
1207  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Rx";
1209  }
1210 
1211  g_interfaceStreamMapIpv6[std::make_pair (ipv6, interface)] = stream;
1212 }
1213 
1214 } // namespace ns3
bool m_ipv4ArpJitterEnabled
IPv4 ARP Jitter state (enabled/disabled) ?
bool m_ipv6NsRsJitterEnabled
IPv6 IPv6 NS and RS Jitter state (enabled/disabled) ?
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Manage ASCII trace files for device models.
Definition: trace-helper.h:161
Packet header for IPv6.
Definition: ipv6-header.h:34
virtual void EnablePcapIpv6Internal(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename)
Enable pcap output the indicated Ipv6 and interface pair.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static void Ipv4L3ProtocolDropSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ipv4Header const &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 dropped packet - Ascii output.
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:483
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
Hold variables of type string.
Definition: string.h:41
static const uint8_t EXT_NUMBER
Fragmentation extension number.
Hold a value for an Attribute.
Definition: attribute.h:68
void SetIpv4ArpJitter(bool enable)
Enable/disable IPv4 ARP Jitter.
Manage pcap files for device models.
Definition: trace-helper.h:38
IPv6 layer implementation.
Demultiplexes IPv6 extensions.
void Write(Time t, Ptr< const Packet > p)
Write the next packet to file.
virtual Ipv4RoutingHelper * Copy(void) const =0
virtual constructor
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1686
static InterfaceFileMapIpv4 g_interfaceFileMapIpv4
A mapping of Ipv4/interface pairs to pcap files.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
ObjectFactory m_tcpFactory
TCP objects factory.
virtual Ipv6RoutingHelper * Copy(void) const =0
virtual constructor
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop default trace sink.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
aggregate IP/TCP/UDP functionality to existing Nodes.
std::map< InterfacePairIpv6, Ptr< PcapFileWrapper > > InterfaceFileMapIpv6
Ipv6/interface and Pcap file wrapper container.
static void Ipv4L3ProtocolRxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 received packet - Ascii output.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
static void Ipv6L3ProtocolDropSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ipv6Header const &header, Ptr< const Packet > packet, Ipv6L3Protocol::DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 dropped packet - Ascii output.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
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. ...
std::map< InterfacePairIpv6, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv6
Ipv6/interface and output stream container.
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
static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4
A mapping of Ipv4/interface pairs to ascii streams.
std::map< InterfacePairIpv4, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv4
Ipv4/interface and output stream container.
static void Ipv4L3ProtocolTxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 transmitted packet - Ascii output.
InternetStackHelper & operator=(const InternetStackHelper &o)
Copy constructor.
static void CreateAndAggregateObjectFromTypeId(Ptr< Node > node, const std::string typeId)
create an object from its TypeId and aggregates it to the node
DropReason
Reason why a packet has been dropped.
Packet header for IPv4.
Definition: ipv4-header.h:33
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
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.
virtual void EnablePcapIpv4Internal(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename)
Enable pcap output the indicated Ipv4 and interface pair.
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
void InstallAll(void) const
Aggregate IPv4, IPv6, UDP, and TCP stacks to all nodes in the simulation.
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:572
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
static InterfaceFileMapIpv6 g_interfaceFileMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
std::pair< Ptr< Ipv6 >, uint32_t > InterfacePairIpv6
Ipv6/interface pair.
A factory to create ns3::Ipv6RoutingProtocol objects.
void Reset(void)
Return helper internal state to that of a newly constructed one.
An implementation of the ICMPv6 protocol.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
bool PcapHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to a Pcap wrapper
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...
bool m_ipv6Enabled
IPv6 install state (enabled/disabled) ?
a factory to create ns3::Ipv4RoutingProtocol objects
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
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 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.
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
virtual Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const =0
static void Ipv6L3ProtocolRxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 received packet - Ascii output.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
Implement the IPv4 layer.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Helper class that adds ns3::Ipv6StaticRouting objects.
void Initialize(void)
Initialize the helper to its default values.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void SetTcp(std::string tid)
set the Tcp stack which will not need any other parameter.
static void Ipv6L3ProtocolDropSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ipv6Header const &header, Ptr< const Packet > packet, Ipv6L3Protocol::DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 dropped packet - Ascii output.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
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.
virtual ~InternetStackHelper(void)
Destroy the InternetStackHelper.
An interface aggregated to a node to provide global routing info.
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
std::pair< Ptr< Ipv4 >, uint32_t > InterfacePairIpv4
Ipv4/interface pair.
static void Ipv4L3ProtocolDropSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ipv4Header const &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 dropped packet - Ascii output.
Instantiate subclasses of ns3::Object.
const Ipv6RoutingHelper * m_routingv6
IPv6 routing helper.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
uint32_t GetId(void) const
Definition: node.cc:107
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.
Helper class that adds ns3::Ipv4StaticRouting objects.
A network Node.
Definition: node.h:56
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...
virtual Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const =0
An implementation of the ARP protocol.
DropReason
Reason why a packet has been dropped.
Helper class that adds ns3::Ipv4GlobalRouting objects.
Helper class that adds ns3::Ipv4ListRouting objects.
bool AsciiHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to an ascii output stream
virtual void EnableAsciiIpv6Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename)
Enable ascii trace output on the indicated Ipv6 and interface pair.
InternetStackHelper(void)
Create a new InternetStackHelper which uses a mix of static routing and global routing by default...
A base class which provides memory management and object aggregation.
Definition: object.h:87
std::map< InterfacePairIpv4, Ptr< PcapFileWrapper > > InterfaceFileMapIpv4
Ipv4/interface and Pcap file wrapper container.
const Ipv4RoutingHelper * m_routing
IPv4 routing helper.
void SetIpv6NsRsJitter(bool enable)
Enable/disable IPv6 NS and RS Jitter.
static InterfaceStreamMapIpv6 g_interfaceStreamMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
bool m_ipv4Enabled
IPv4 install state (enabled/disabled) ?
static void Ipv6L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 packet - Pcap output.
virtual void EnableAsciiIpv4Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename)
Enable ascii trace output on the indicated Ipv4 and interface pair.
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
static void Ipv4L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 packet - Pcap output.