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 
151 #include "ns3/assert.h"
152 #include "ns3/log.h"
153 #include "ns3/object.h"
154 #include "ns3/names.h"
155 #include "ns3/ipv4.h"
156 #include "ns3/ipv6.h"
157 #include "ns3/packet-socket-factory.h"
158 #include "ns3/config.h"
159 #include "ns3/simulator.h"
160 #include "ns3/string.h"
161 #include "ns3/net-device.h"
162 #include "ns3/callback.h"
163 #include "ns3/node.h"
164 #include "ns3/node-list.h"
165 #include "ns3/core-config.h"
166 #include "ns3/arp-l3-protocol.h"
167 #include "internet-stack-helper.h"
168 #include "ns3/ipv4-global-routing.h"
169 #include "ns3/ipv4-list-routing-helper.h"
170 #include "ns3/ipv4-static-routing-helper.h"
171 #include "ns3/ipv4-global-routing-helper.h"
172 #include "ns3/ipv6-static-routing-helper.h"
173 #include "ns3/ipv6-extension.h"
174 #include "ns3/ipv6-extension-demux.h"
175 #include "ns3/ipv6-extension-header.h"
176 #include "ns3/icmpv6-l4-protocol.h"
177 #include "ns3/global-router-interface.h"
178 #include "ns3/traffic-control-layer.h"
179 #include <limits>
180 #include <map>
181 
182 namespace ns3 {
183 
184 NS_LOG_COMPONENT_DEFINE ("InternetStackHelper");
185 
186 //
187 // Historically, the only context written to ascii traces was the protocol.
188 // Traces from the protocols include the interface, though. It is not
189 // possible to really determine where an event originated without including
190 // this. If you want the additional context information, define
191 // INTERFACE_CONTEXT. If you want compatibility with the old-style traces
192 // comment it out.
193 //
194 #define INTERFACE_CONTEXT
195 
196 //
197 // Things are going to work differently here with respect to trace file handling
198 // than in most places because the Tx and Rx trace sources we are interested in
199 // are going to multiplex receive and transmit callbacks for all Ipv4 and
200 // interface pairs through one callback. We want packets to or from each
201 // distinct pair to go to an individual file, so we have got to demultiplex the
202 // Ipv4 and interface pair into a corresponding Ptr<PcapFileWrapper> at the
203 // callback.
204 //
205 // A complication in this situation is that the trace sources are hooked on
206 // a protocol basis. There is no trace source hooked by an Ipv4 and interface
207 // pair. This means that if we naively proceed to hook, say, a drop trace
208 // for a given Ipv4 with interface 0, and then hook for Ipv4 with interface 1
209 // we will hook the drop trace twice and get two callbacks per event. What
210 // we need to do is to hook the event once, and that will result in a single
211 // callback per drop event, and the trace source will provide the interface
212 // which we filter on in the trace sink.
213 //
214 // This has got to continue to work properly after the helper has been
215 // destroyed; but must be cleaned up at the end of time to avoid leaks.
216 // Global maps of protocol/interface pairs to file objects seems to fit the
217 // bill.
218 //
219 typedef std::pair<Ptr<Ipv4>, uint32_t> InterfacePairIpv4;
220 typedef std::map<InterfacePairIpv4, Ptr<PcapFileWrapper> > InterfaceFileMapIpv4;
221 typedef std::map<InterfacePairIpv4, Ptr<OutputStreamWrapper> > InterfaceStreamMapIpv4;
223 static InterfaceFileMapIpv4 g_interfaceFileMapIpv4;
224 static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4;
226 typedef std::pair<Ptr<Ipv6>, uint32_t> InterfacePairIpv6;
227 typedef std::map<InterfacePairIpv6, Ptr<PcapFileWrapper> > InterfaceFileMapIpv6;
228 typedef std::map<InterfacePairIpv6, Ptr<OutputStreamWrapper> > InterfaceStreamMapIpv6;
230 static InterfaceFileMapIpv6 g_interfaceFileMapIpv6;
231 static InterfaceStreamMapIpv6 g_interfaceStreamMapIpv6;
234  : m_routing (0),
235  m_routingv6 (0),
236  m_ipv4Enabled (true),
237  m_ipv6Enabled (true),
238  m_ipv4ArpJitterEnabled (true),
239  m_ipv6NsRsJitterEnabled (true)
240 
241 {
242  Initialize ();
243 }
244 
245 // private method called by both constructor and Reset ()
246 void
248 {
249  SetTcp ("ns3::TcpL4Protocol");
250  Ipv4StaticRoutingHelper staticRouting;
251  Ipv4GlobalRoutingHelper globalRouting;
252  Ipv4ListRoutingHelper listRouting;
253  Ipv6StaticRoutingHelper staticRoutingv6;
254  listRouting.Add (staticRouting, 0);
255  listRouting.Add (globalRouting, -10);
256  SetRoutingHelper (listRouting);
257  SetRoutingHelper (staticRoutingv6);
258 }
259 
261 {
262  delete m_routing;
263  delete m_routingv6;
264 }
265 
267 {
268  m_routing = o.m_routing->Copy ();
269  m_routingv6 = o.m_routingv6->Copy ();
275 }
276 
279 {
280  if (this == &o)
281  {
282  return *this;
283  }
284  m_routing = o.m_routing->Copy ();
285  m_routingv6 = o.m_routingv6->Copy ();
286  return *this;
287 }
288 
289 void
291 {
292  delete m_routing;
293  m_routing = 0;
294  delete m_routingv6;
295  m_routingv6 = 0;
296  m_ipv4Enabled = true;
297  m_ipv6Enabled = true;
298  m_ipv4ArpJitterEnabled = true;
300  Initialize ();
301 }
302 
303 void
305 {
306  delete m_routing;
307  m_routing = routing.Copy ();
308 }
309 
310 void
312 {
313  delete m_routingv6;
314  m_routingv6 = routing.Copy ();
315 }
316 
317 void
319 {
320  m_ipv4Enabled = enable;
321 }
322 
324 {
325  m_ipv6Enabled = enable;
326 }
327 
329 {
330  m_ipv4ArpJitterEnabled = enable;
331 }
332 
334 {
335  m_ipv6NsRsJitterEnabled = enable;
336 }
337 
338 int64_t
340 {
341  int64_t currentStream = stream;
342  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
343  {
344  Ptr<Node> node = *i;
345  Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
346  if (router != 0)
347  {
348  Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
349  if (gr != 0)
350  {
351  currentStream += gr->AssignStreams (currentStream);
352  }
353  }
355  if (demux != 0)
356  {
357  Ptr<Ipv6Extension> fe = demux->GetExtension (Ipv6ExtensionFragment::EXT_NUMBER);
358  NS_ASSERT (fe); // should always exist in the demux
359  currentStream += fe->AssignStreams (currentStream);
360  }
361  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
362  if (ipv4 != 0)
363  {
364  Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol> ();
365  if (arpL3Protocol != 0)
366  {
367  currentStream += arpL3Protocol->AssignStreams (currentStream);
368  }
369  }
370  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
371  if (ipv6 != 0)
372  {
373  Ptr<Icmpv6L4Protocol> icmpv6L4Protocol = ipv6->GetObject<Icmpv6L4Protocol> ();
374  if (icmpv6L4Protocol != 0)
375  {
376  currentStream += icmpv6L4Protocol->AssignStreams (currentStream);
377  }
378  }
379  }
380  return (currentStream - stream);
381 }
382 
383 void
384 InternetStackHelper::SetTcp (const std::string tid)
385 {
386  m_tcpFactory.SetTypeId (tid);
387 }
388 
389 void
390 InternetStackHelper::SetTcp (std::string tid, std::string n0, const AttributeValue &v0)
391 {
392  m_tcpFactory.SetTypeId (tid);
393  m_tcpFactory.Set (n0,v0);
394 }
395 
396 void
398 {
399  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
400  {
401  Install (*i);
402  }
403 }
404 
405 void
407 {
409 }
410 
411 void
413 {
414  ObjectFactory factory;
415  factory.SetTypeId (typeId);
416  Ptr<Object> protocol = factory.Create <Object> ();
417  node->AggregateObject (protocol);
418 }
419 
420 void
422 {
423  if (m_ipv4Enabled)
424  {
425  if (node->GetObject<Ipv4> () != 0)
426  {
427  NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating "
428  "an InternetStack to a node with an existing Ipv4 object");
429  return;
430  }
431 
432  CreateAndAggregateObjectFromTypeId (node, "ns3::ArpL3Protocol");
433  CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv4L3Protocol");
434  CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv4L4Protocol");
435  if (m_ipv4ArpJitterEnabled == false)
436  {
438  NS_ASSERT (arp);
439  arp->SetAttribute ("RequestJitter", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
440  }
441  // Set routing
442  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
443  Ptr<Ipv4RoutingProtocol> ipv4Routing = m_routing->Create (node);
444  ipv4->SetRoutingProtocol (ipv4Routing);
445  }
446 
447  if (m_ipv6Enabled)
448  {
449  /* IPv6 stack */
450  if (node->GetObject<Ipv6> () != 0)
451  {
452  NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating "
453  "an InternetStack to a node with an existing Ipv6 object");
454  return;
455  }
456 
457  CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv6L3Protocol");
458  CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv6L4Protocol");
459  if (m_ipv6NsRsJitterEnabled == false)
460  {
461  Ptr<Icmpv6L4Protocol> icmpv6l4 = node->GetObject<Icmpv6L4Protocol> ();
462  NS_ASSERT (icmpv6l4);
463  icmpv6l4->SetAttribute ("SolicitationJitter", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
464  }
465  // Set routing
466  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
467  Ptr<Ipv6RoutingProtocol> ipv6Routing = m_routingv6->Create (node);
468  ipv6->SetRoutingProtocol (ipv6Routing);
469 
470  /* register IPv6 extensions and options */
471  ipv6->RegisterExtensions ();
472  ipv6->RegisterOptions ();
473  }
474 
476  {
477  CreateAndAggregateObjectFromTypeId (node, "ns3::TrafficControlLayer");
478  CreateAndAggregateObjectFromTypeId (node, "ns3::UdpL4Protocol");
480  Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
481  node->AggregateObject (factory);
482  }
483 }
484 
485 void
486 InternetStackHelper::Install (std::string nodeName) const
487 {
488  Ptr<Node> node = Names::Find<Node> (nodeName);
489  Install (node);
490 }
491 
498 static void
500 {
501  NS_LOG_FUNCTION (p << ipv4 << interface);
502 
503  //
504  // Since trace sources are independent of interface, if we hook a source
505  // on a particular protocol we will get traces for all of its interfaces.
506  // We need to filter this to only report interfaces for which the user
507  // has expressed interest.
508  //
509  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
510  if (g_interfaceFileMapIpv4.find (pair) == g_interfaceFileMapIpv4.end ())
511  {
512  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
513  return;
514  }
515 
516  Ptr<PcapFileWrapper> file = g_interfaceFileMapIpv4[pair];
517  file->Write (Simulator::Now (), p);
518 }
519 
520 bool
522 {
523  for ( InterfaceFileMapIpv4::const_iterator i = g_interfaceFileMapIpv4.begin ();
524  i != g_interfaceFileMapIpv4.end ();
525  ++i)
526  {
527  if ((*i).first.first == ipv4)
528  {
529  return true;
530  }
531  }
532  return false;
533 }
534 
535 void
536 InternetStackHelper::EnablePcapIpv4Internal (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename)
537 {
538  NS_LOG_FUNCTION (prefix << ipv4 << interface);
539 
540  if (!m_ipv4Enabled)
541  {
542  NS_LOG_INFO ("Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
543  return;
544  }
545 
546  //
547  // We have to create a file and a mapping from protocol/interface to file
548  // irrespective of how many times we want to trace a particular protocol.
549  //
550  PcapHelper pcapHelper;
551 
552  std::string filename;
553  if (explicitFilename)
554  {
555  filename = prefix;
556  }
557  else
558  {
559  filename = pcapHelper.GetFilenameFromInterfacePair (prefix, ipv4, interface);
560  }
561 
562  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, PcapHelper::DLT_RAW);
563 
564  //
565  // However, we only hook the trace source once to avoid multiple trace sink
566  // calls per event (connect is independent of interface).
567  //
568  if (!PcapHooked (ipv4))
569  {
570  //
571  // Ptr<Ipv4> is aggregated to node and Ipv4L3Protocol is aggregated to
572  // node so we can get to Ipv4L3Protocol through Ipv4.
573  //
574  Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol> ();
575  NS_ASSERT_MSG (ipv4L3Protocol, "InternetStackHelper::EnablePcapIpv4Internal(): "
576  "m_ipv4Enabled and ipv4L3Protocol inconsistent");
577 
578  bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx", MakeCallback (&Ipv4L3ProtocolRxTxSink));
579  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv4Internal(): "
580  "Unable to connect ipv4L3Protocol \"Tx\"");
581 
582  result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv4L3ProtocolRxTxSink));
583  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv4Internal(): "
584  "Unable to connect ipv4L3Protocol \"Rx\"");
585  }
586 
587  g_interfaceFileMapIpv4[std::make_pair (ipv4, interface)] = file;
588 }
589 
596 static void
598 {
599  NS_LOG_FUNCTION (p << ipv6 << interface);
600 
601  //
602  // Since trace sources are independent of interface, if we hook a source
603  // on a particular protocol we will get traces for all of its interfaces.
604  // We need to filter this to only report interfaces for which the user
605  // has expressed interest.
606  //
607  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
608  if (g_interfaceFileMapIpv6.find (pair) == g_interfaceFileMapIpv6.end ())
609  {
610  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
611  return;
612  }
613 
614  Ptr<PcapFileWrapper> file = g_interfaceFileMapIpv6[pair];
615  file->Write (Simulator::Now (), p);
616 }
617 
618 bool
620 {
621  for ( InterfaceFileMapIpv6::const_iterator i = g_interfaceFileMapIpv6.begin ();
622  i != g_interfaceFileMapIpv6.end ();
623  ++i)
624  {
625  if ((*i).first.first == ipv6)
626  {
627  return true;
628  }
629  }
630  return false;
631 }
632 
633 void
634 InternetStackHelper::EnablePcapIpv6Internal (std::string prefix, Ptr<Ipv6> ipv6, uint32_t interface, bool explicitFilename)
635 {
636  NS_LOG_FUNCTION (prefix << ipv6 << interface);
637 
638  if (!m_ipv6Enabled)
639  {
640  NS_LOG_INFO ("Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
641  return;
642  }
643 
644  //
645  // We have to create a file and a mapping from protocol/interface to file
646  // irrespective of how many times we want to trace a particular protocol.
647  //
648  PcapHelper pcapHelper;
649 
650  std::string filename;
651  if (explicitFilename)
652  {
653  filename = prefix;
654  }
655  else
656  {
657  filename = pcapHelper.GetFilenameFromInterfacePair (prefix, ipv6, interface);
658  }
659 
660  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, PcapHelper::DLT_RAW);
661 
662  //
663  // However, we only hook the trace source once to avoid multiple trace sink
664  // calls per event (connect is independent of interface).
665  //
666  if (!PcapHooked (ipv6))
667  {
668  //
669  // Ptr<Ipv6> is aggregated to node and Ipv6L3Protocol is aggregated to
670  // node so we can get to Ipv6L3Protocol through Ipv6.
671  //
672  Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol> ();
673  NS_ASSERT_MSG (ipv6L3Protocol, "InternetStackHelper::EnablePcapIpv6Internal(): "
674  "m_ipv6Enabled and ipv6L3Protocol inconsistent");
675 
676  bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx", MakeCallback (&Ipv6L3ProtocolRxTxSink));
677  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv6Internal(): "
678  "Unable to connect ipv6L3Protocol \"Tx\"");
679 
680  result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv6L3ProtocolRxTxSink));
681  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv6Internal(): "
682  "Unable to connect ipv6L3Protocol \"Rx\"");
683  }
684 
685  g_interfaceFileMapIpv6[std::make_pair (ipv6, interface)] = file;
686 }
687 
697 static void
700  Ipv4Header const &header,
701  Ptr<const Packet> packet,
703  Ptr<Ipv4> ipv4,
704  uint32_t interface)
705 {
706  //
707  // Since trace sources are independent of interface, if we hook a source
708  // on a particular protocol we will get traces for all of its interfaces.
709  // We need to filter this to only report interfaces for which the user
710  // has expressed interest.
711  //
712  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
713  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
714  {
715  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
716  return;
717  }
718 
719  Ptr<Packet> p = packet->Copy ();
720  p->AddHeader (header);
721  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
722 }
723 
731 static void
734  Ptr<const Packet> packet,
735  Ptr<Ipv4> ipv4,
736  uint32_t interface)
737 {
738  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
739  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
740  {
741  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
742  return;
743  }
744 
745  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
746 }
747 
755 static void
758  Ptr<const Packet> packet,
759  Ptr<Ipv4> ipv4,
760  uint32_t interface)
761 {
762  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
763  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
764  {
765  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
766  return;
767  }
768 
769  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
770 }
771 
782 static void
785  std::string context,
786  Ipv4Header const &header,
787  Ptr<const Packet> packet,
789  Ptr<Ipv4> ipv4,
790  uint32_t interface)
791 {
792  //
793  // Since trace sources are independent of interface, if we hook a source
794  // on a particular protocol we will get traces for all of its interfaces.
795  // We need to filter this to only report interfaces for which the user
796  // has expressed interest.
797  //
798  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
799  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
800  {
801  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
802  return;
803  }
804 
805  Ptr<Packet> p = packet->Copy ();
806  p->AddHeader (header);
807 #ifdef INTERFACE_CONTEXT
808  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
809  << *p << std::endl;
810 #else
811  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
812 #endif
813 }
814 
823 static void
826  std::string context,
827  Ptr<const Packet> packet,
828  Ptr<Ipv4> ipv4,
829  uint32_t interface)
830 {
831  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
832  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
833  {
834  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
835  return;
836  }
837 
838 #ifdef INTERFACE_CONTEXT
839  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
840  << *packet << std::endl;
841 #else
842  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
843 #endif
844 }
845 
854 static void
857  std::string context,
858  Ptr<const Packet> packet,
859  Ptr<Ipv4> ipv4,
860  uint32_t interface)
861 {
862  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
863  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
864  {
865  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
866  return;
867  }
868 
869 #ifdef INTERFACE_CONTEXT
870  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
871  << *packet << std::endl;
872 #else
873  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
874 #endif
875 }
876 
877 bool
879 {
880  for ( InterfaceStreamMapIpv4::const_iterator i = g_interfaceStreamMapIpv4.begin ();
881  i != g_interfaceStreamMapIpv4.end ();
882  ++i)
883  {
884  if ((*i).first.first == ipv4)
885  {
886  return true;
887  }
888  }
889  return false;
890 }
891 
892 void
894  Ptr<OutputStreamWrapper> stream,
895  std::string prefix,
896  Ptr<Ipv4> ipv4,
897  uint32_t interface,
898  bool explicitFilename)
899 {
900  if (!m_ipv4Enabled)
901  {
902  NS_LOG_INFO ("Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
903  return;
904  }
905 
906  //
907  // Our trace sinks are going to use packet printing, so we have to
908  // make sure that is turned on.
909  //
911 
912  //
913  // If we are not provided an OutputStreamWrapper, we are expected to create
914  // one using the usual trace filename conventions and hook WithoutContext
915  // since there will be one file per context and therefore the context would
916  // be redundant.
917  //
918  if (stream == 0)
919  {
920  //
921  // Set up an output stream object to deal with private ofstream copy
922  // constructor and lifetime issues. Let the helper decide the actual
923  // name of the file given the prefix.
924  //
925  // We have to create a stream and a mapping from protocol/interface to
926  // stream irrespective of how many times we want to trace a particular
927  // protocol.
928  //
929  AsciiTraceHelper asciiTraceHelper;
930 
931  std::string filename;
932  if (explicitFilename)
933  {
934  filename = prefix;
935  }
936  else
937  {
938  filename = asciiTraceHelper.GetFilenameFromInterfacePair (prefix, ipv4, interface);
939  }
940 
941  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
942 
943  //
944  // However, we only hook the trace sources once to avoid multiple trace sink
945  // calls per event (connect is independent of interface).
946  //
947  if (!AsciiHooked (ipv4))
948  {
949  //
950  // We can use the default drop sink for the ArpL3Protocol since it has
951  // the usual signature. We can get to the Ptr<ArpL3Protocol> through
952  // our Ptr<Ipv4> since they must both be aggregated to the same node.
953  //
954  Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol> ();
955  asciiTraceHelper.HookDefaultDropSinkWithoutContext<ArpL3Protocol> (arpL3Protocol, "Drop", theStream);
956 
957  //
958  // The drop sink for the Ipv4L3Protocol uses a different signature than
959  // the default sink, so we have to cook one up for ourselves. We can get
960  // to the Ptr<Ipv4L3Protocol> through our Ptr<Ipv4> since they must both
961  // be aggregated to the same node.
962  //
963  Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol> ();
964  bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop",
966  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
967  "Unable to connect ipv4L3Protocol \"Drop\"");
968  result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx",
970  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
971  "Unable to connect ipv4L3Protocol \"Tx\"");
972  result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx",
974  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
975  "Unable to connect ipv4L3Protocol \"Rx\"");
976  }
977 
978  g_interfaceStreamMapIpv4[std::make_pair (ipv4, interface)] = theStream;
979  return;
980  }
981 
982  //
983  // If we are provided an OutputStreamWrapper, we are expected to use it, and
984  // to provide a context. We are free to come up with our own context if we
985  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
986  // compatibility and simplicity, we just use Config::Connect and let it deal
987  // with the context.
988  //
989  // We need to associate the ipv4/interface with a stream to express interest
990  // in tracing events on that pair, however, we only hook the trace sources
991  // once to avoid multiple trace sink calls per event (connect is independent
992  // of interface).
993  //
994  if (!AsciiHooked (ipv4))
995  {
996  Ptr<Node> node = ipv4->GetObject<Node> ();
997  std::ostringstream oss;
998 
999  //
1000  // For the ARP Drop, we are going to use the default trace sink provided by
1001  // the ascii trace helper. There is actually no AsciiTraceHelper in sight
1002  // here, but the default trace sinks are actually publicly available static
1003  // functions that are always there waiting for just such a case.
1004  //
1005  oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop";
1007 
1008  //
1009  // This has all kinds of parameters coming with, so we have to cook up our
1010  // own sink.
1011  //
1012  oss.str ("");
1013  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop";
1015  oss.str ("");
1016  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Tx";
1018  oss.str ("");
1019  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Rx";
1021  }
1022 
1023  g_interfaceStreamMapIpv4[std::make_pair (ipv4, interface)] = stream;
1024 }
1025 
1035 static void
1037  Ptr<OutputStreamWrapper> stream,
1038  Ipv6Header const &header,
1039  Ptr<const Packet> packet,
1041  Ptr<Ipv6> ipv6,
1042  uint32_t interface)
1043 {
1044  //
1045  // Since trace sources are independent of interface, if we hook a source
1046  // on a particular protocol we will get traces for all of its interfaces.
1047  // We need to filter this to only report interfaces for which the user
1048  // has expressed interest.
1049  //
1050  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1051  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1052  {
1053  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1054  return;
1055  }
1056 
1057  Ptr<Packet> p = packet->Copy ();
1058  p->AddHeader (header);
1059  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
1060 }
1061 
1069 static void
1071  Ptr<OutputStreamWrapper> stream,
1072  Ptr<const Packet> packet,
1073  Ptr<Ipv6> ipv6,
1074  uint32_t interface)
1075 {
1076  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1077  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1078  {
1079  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1080  return;
1081  }
1082 
1083  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
1084 }
1085 
1093 static void
1095  Ptr<OutputStreamWrapper> stream,
1096  Ptr<const Packet> packet,
1097  Ptr<Ipv6> ipv6,
1098  uint32_t interface)
1099 {
1100  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1101  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1102  {
1103  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1104  return;
1105  }
1106 
1107  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
1108 }
1109 
1120 static void
1122  Ptr<OutputStreamWrapper> stream,
1123  std::string context,
1124  Ipv6Header const &header,
1125  Ptr<const Packet> packet,
1127  Ptr<Ipv6> ipv6,
1128  uint32_t interface)
1129 {
1130  //
1131  // Since trace sources are independent of interface, if we hook a source
1132  // on a particular protocol we will get traces for all of its interfaces.
1133  // We need to filter this to only report interfaces for which the user
1134  // has expressed interest.
1135  //
1136  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1137  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1138  {
1139  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1140  return;
1141  }
1142 
1143  Ptr<Packet> p = packet->Copy ();
1144  p->AddHeader (header);
1145 #ifdef INTERFACE_CONTEXT
1146  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1147  << *p << std::endl;
1148 #else
1149  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
1150 #endif
1151 }
1152 
1161 static void
1163  Ptr<OutputStreamWrapper> stream,
1164  std::string context,
1165  Ptr<const Packet> packet,
1166  Ptr<Ipv6> ipv6,
1167  uint32_t interface)
1168 {
1169  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1170  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1171  {
1172  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1173  return;
1174  }
1175 
1176 #ifdef INTERFACE_CONTEXT
1177  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1178  << *packet << std::endl;
1179 #else
1180  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
1181 #endif
1182 }
1183 
1192 static void
1194  Ptr<OutputStreamWrapper> stream,
1195  std::string context,
1196  Ptr<const Packet> packet,
1197  Ptr<Ipv6> ipv6,
1198  uint32_t interface)
1199 {
1200  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1201  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1202  {
1203  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1204  return;
1205  }
1206 
1207 #ifdef INTERFACE_CONTEXT
1208  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1209  << *packet << std::endl;
1210 #else
1211  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
1212 #endif
1213 }
1214 
1215 bool
1217 {
1218  for ( InterfaceStreamMapIpv6::const_iterator i = g_interfaceStreamMapIpv6.begin ();
1219  i != g_interfaceStreamMapIpv6.end ();
1220  ++i)
1221  {
1222  if ((*i).first.first == ipv6)
1223  {
1224  return true;
1225  }
1226  }
1227  return false;
1228 }
1229 
1230 void
1232  Ptr<OutputStreamWrapper> stream,
1233  std::string prefix,
1234  Ptr<Ipv6> ipv6,
1235  uint32_t interface,
1236  bool explicitFilename)
1237 {
1238  if (!m_ipv6Enabled)
1239  {
1240  NS_LOG_INFO ("Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1241  return;
1242  }
1243 
1244  //
1245  // Our trace sinks are going to use packet printing, so we have to
1246  // make sure that is turned on.
1247  //
1249 
1250  //
1251  // If we are not provided an OutputStreamWrapper, we are expected to create
1252  // one using the usual trace filename conventions and do a hook WithoutContext
1253  // since there will be one file per context and therefore the context would
1254  // be redundant.
1255  //
1256  if (stream == 0)
1257  {
1258  //
1259  // Set up an output stream object to deal with private ofstream copy
1260  // constructor and lifetime issues. Let the helper decide the actual
1261  // name of the file given the prefix.
1262  //
1263  // We have to create a stream and a mapping from protocol/interface to
1264  // stream irrespective of how many times we want to trace a particular
1265  // protocol.
1266  //
1267  AsciiTraceHelper asciiTraceHelper;
1268 
1269  std::string filename;
1270  if (explicitFilename)
1271  {
1272  filename = prefix;
1273  }
1274  else
1275  {
1276  filename = asciiTraceHelper.GetFilenameFromInterfacePair (prefix, ipv6, interface);
1277  }
1278 
1279  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
1280 
1281  //
1282  // However, we only hook the trace sources once to avoid multiple trace sink
1283  // calls per event (connect is independent of interface).
1284  //
1285  if (!AsciiHooked (ipv6))
1286  {
1287  //
1288  // The drop sink for the Ipv6L3Protocol uses a different signature than
1289  // the default sink, so we have to cook one up for ourselves. We can get
1290  // to the Ptr<Ipv6L3Protocol> through our Ptr<Ipv6> since they must both
1291  // be aggregated to the same node.
1292  //
1293  Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol> ();
1294  bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Drop",
1296  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1297  "Unable to connect ipv6L3Protocol \"Drop\"");
1298  result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx",
1300  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1301  "Unable to connect ipv6L3Protocol \"Tx\"");
1302  result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx",
1304  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1305  "Unable to connect ipv6L3Protocol \"Rx\"");
1306  }
1307 
1308  g_interfaceStreamMapIpv6[std::make_pair (ipv6, interface)] = theStream;
1309  return;
1310  }
1311 
1312  //
1313  // If we are provided an OutputStreamWrapper, we are expected to use it, and
1314  // to provide a context. We are free to come up with our own context if we
1315  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
1316  // compatibility and simplicity, we just use Config::Connect and let it deal
1317  // with the context.
1318  //
1319  // We need to associate the ipv4/interface with a stream to express interest
1320  // in tracing events on that pair, however, we only hook the trace sources
1321  // once to avoid multiple trace sink calls per event (connect is independent
1322  // of interface).
1323  //
1324  if (!AsciiHooked (ipv6))
1325  {
1326  Ptr<Node> node = ipv6->GetObject<Node> ();
1327  std::ostringstream oss;
1328 
1329  oss.str ("");
1330  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Drop";
1332  oss.str ("");
1333  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Tx";
1335  oss.str ("");
1336  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Rx";
1338  }
1339 
1340  g_interfaceStreamMapIpv6[std::make_pair (ipv6, interface)] = stream;
1341 }
1342 
1343 } // 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:155
Introspection did not find any typical Config paths.
Definition: ipv6-header.h:33
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:477
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:455
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.
Introspection did not find any typical Config paths.
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:1677
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:246
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:244
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:145
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.
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:31
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
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.
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:535
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:1480
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:835
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:122
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:299
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:223
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.
#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:90
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.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, uint32_t 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
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:257
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.
DropReason
Reason why a packet has been dropped.
static void Ipv4L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 packet - Pcap output.