A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-list-routing-helper.h"
173 #include "ns3/ipv6-static-routing-helper.h"
174 #include "ns3/ipv6-extension.h"
175 #include "ns3/ipv6-extension-demux.h"
176 #include "ns3/ipv6-extension-header.h"
177 #include "ns3/icmpv6-l4-protocol.h"
178 #include "ns3/global-router-interface.h"
179 #include <limits>
180 #include <map>
181 
182 NS_LOG_COMPONENT_DEFINE ("InternetStackHelper");
183 
184 namespace ns3 {
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;
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;
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  Ipv6ListRoutingHelper listRoutingv6;
254  Ipv6StaticRoutingHelper staticRoutingv6;
255  listRouting.Add (staticRouting, 0);
256  listRouting.Add (globalRouting, -10);
257  listRoutingv6.Add (staticRoutingv6, 0);
258  SetRoutingHelper (listRouting);
259  SetRoutingHelper (listRoutingv6);
260 }
261 
263 {
264  delete m_routing;
265  delete m_routingv6;
266 }
267 
269 {
270  m_routing = o.m_routing->Copy ();
271  m_routingv6 = o.m_routingv6->Copy ();
277 }
278 
281 {
282  if (this == &o)
283  {
284  return *this;
285  }
286  m_routing = o.m_routing->Copy ();
287  m_routingv6 = o.m_routingv6->Copy ();
288  return *this;
289 }
290 
291 void
293 {
294  delete m_routing;
295  m_routing = 0;
296  delete m_routingv6;
297  m_routingv6 = 0;
298  m_ipv4Enabled = true;
299  m_ipv6Enabled = true;
300  m_ipv4ArpJitterEnabled = true;
302  Initialize ();
303 }
304 
305 void
307 {
308  delete m_routing;
309  m_routing = routing.Copy ();
310 }
311 
312 void
314 {
315  delete m_routingv6;
316  m_routingv6 = routing.Copy ();
317 }
318 
319 void
321 {
322  m_ipv4Enabled = enable;
323 }
324 
326 {
327  m_ipv6Enabled = enable;
328 }
329 
331 {
332  m_ipv4ArpJitterEnabled = enable;
333 }
334 
336 {
337  m_ipv6NsRsJitterEnabled = enable;
338 }
339 
340 int64_t
342 {
343  int64_t currentStream = stream;
344  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
345  {
346  Ptr<Node> node = *i;
347  Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
348  if (router != 0)
349  {
350  Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
351  if (gr != 0)
352  {
353  currentStream += gr->AssignStreams (currentStream);
354  }
355  }
357  if (demux != 0)
358  {
359  Ptr<Ipv6Extension> fe = demux->GetExtension (Ipv6ExtensionFragment::EXT_NUMBER);
360  NS_ASSERT (fe); // should always exist in the demux
361  currentStream += fe->AssignStreams (currentStream);
362  }
363  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
364  if (ipv4 != 0)
365  {
366  Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol> ();
367  if (arpL3Protocol != 0)
368  {
369  currentStream += arpL3Protocol->AssignStreams (currentStream);
370  }
371  }
372  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
373  if (ipv6 != 0)
374  {
375  Ptr<Icmpv6L4Protocol> icmpv6L4Protocol = ipv6->GetObject<Icmpv6L4Protocol> ();
376  if (icmpv6L4Protocol != 0)
377  {
378  currentStream += icmpv6L4Protocol->AssignStreams (currentStream);
379  }
380  }
381  }
382  return (currentStream - stream);
383 }
384 
385 void
386 InternetStackHelper::SetTcp (const std::string tid)
387 {
388  m_tcpFactory.SetTypeId (tid);
389 }
390 
391 void
392 InternetStackHelper::SetTcp (std::string tid, std::string n0, const AttributeValue &v0)
393 {
394  m_tcpFactory.SetTypeId (tid);
395  m_tcpFactory.Set (n0,v0);
396 }
397 
398 void
400 {
401  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
402  {
403  Install (*i);
404  }
405 }
406 
407 void
409 {
411 }
412 
413 void
415 {
416  ObjectFactory factory;
417  factory.SetTypeId (typeId);
418  Ptr<Object> protocol = factory.Create <Object> ();
419  node->AggregateObject (protocol);
420 }
421 
422 void
424 {
425  if (m_ipv4Enabled)
426  {
427  if (node->GetObject<Ipv4> () != 0)
428  {
429  NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating "
430  "an InternetStack to a node with an existing Ipv4 object");
431  return;
432  }
433 
434  CreateAndAggregateObjectFromTypeId (node, "ns3::ArpL3Protocol");
435  CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv4L3Protocol");
436  CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv4L4Protocol");
437  if (m_ipv4ArpJitterEnabled == false)
438  {
440  NS_ASSERT (arp);
441  arp->SetAttribute ("RequestJitter", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
442  }
443  // Set routing
444  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
445  Ptr<Ipv4RoutingProtocol> ipv4Routing = m_routing->Create (node);
446  ipv4->SetRoutingProtocol (ipv4Routing);
447  }
448 
449  if (m_ipv6Enabled)
450  {
451  /* IPv6 stack */
452  if (node->GetObject<Ipv6> () != 0)
453  {
454  NS_FATAL_ERROR ("InternetStackHelper::Install (): Aggregating "
455  "an InternetStack to a node with an existing Ipv6 object");
456  return;
457  }
458 
459  CreateAndAggregateObjectFromTypeId (node, "ns3::Ipv6L3Protocol");
460  CreateAndAggregateObjectFromTypeId (node, "ns3::Icmpv6L4Protocol");
461  if (m_ipv6NsRsJitterEnabled == false)
462  {
463  Ptr<Icmpv6L4Protocol> icmpv6l4 = node->GetObject<Icmpv6L4Protocol> ();
464  NS_ASSERT (icmpv6l4);
465  icmpv6l4->SetAttribute ("SolicitationJitter", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
466  }
467  // Set routing
468  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
469  Ptr<Ipv6RoutingProtocol> ipv6Routing = m_routingv6->Create (node);
470  ipv6->SetRoutingProtocol (ipv6Routing);
471 
472  /* register IPv6 extensions and options */
473  ipv6->RegisterExtensions ();
474  ipv6->RegisterOptions ();
475  }
476 
478  {
479  CreateAndAggregateObjectFromTypeId (node, "ns3::UdpL4Protocol");
481  Ptr<PacketSocketFactory> factory = CreateObject<PacketSocketFactory> ();
482  node->AggregateObject (factory);
483  }
484 }
485 
486 void
487 InternetStackHelper::Install (std::string nodeName) const
488 {
489  Ptr<Node> node = Names::Find<Node> (nodeName);
490  Install (node);
491 }
492 
499 static void
501 {
502  NS_LOG_FUNCTION (p << ipv4 << interface);
503 
504  //
505  // Since trace sources are independent of interface, if we hook a source
506  // on a particular protocol we will get traces for all of its interfaces.
507  // We need to filter this to only report interfaces for which the user
508  // has expressed interest.
509  //
510  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
511  if (g_interfaceFileMapIpv4.find (pair) == g_interfaceFileMapIpv4.end ())
512  {
513  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
514  return;
515  }
516 
518  file->Write (Simulator::Now (), p);
519 }
520 
521 bool
523 {
524  for ( InterfaceFileMapIpv4::const_iterator i = g_interfaceFileMapIpv4.begin ();
525  i != g_interfaceFileMapIpv4.end ();
526  ++i)
527  {
528  if ((*i).first.first == ipv4)
529  {
530  return true;
531  }
532  }
533  return false;
534 }
535 
536 void
537 InternetStackHelper::EnablePcapIpv4Internal (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename)
538 {
539  NS_LOG_FUNCTION (prefix << ipv4 << interface);
540 
541  if (!m_ipv4Enabled)
542  {
543  NS_LOG_INFO ("Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
544  return;
545  }
546 
547  //
548  // We have to create a file and a mapping from protocol/interface to file
549  // irrespective of how many times we want to trace a particular protocol.
550  //
551  PcapHelper pcapHelper;
552 
553  std::string filename;
554  if (explicitFilename)
555  {
556  filename = prefix;
557  }
558  else
559  {
560  filename = pcapHelper.GetFilenameFromInterfacePair (prefix, ipv4, interface);
561  }
562 
563  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, PcapHelper::DLT_RAW);
564 
565  //
566  // However, we only hook the trace source once to avoid multiple trace sink
567  // calls per event (connect is independent of interface).
568  //
569  if (!PcapHooked (ipv4))
570  {
571  //
572  // Ptr<Ipv4> is aggregated to node and Ipv4L3Protocol is aggregated to
573  // node so we can get to Ipv4L3Protocol through Ipv4.
574  //
575  Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol> ();
576  NS_ASSERT_MSG (ipv4L3Protocol, "InternetStackHelper::EnablePcapIpv4Internal(): "
577  "m_ipv4Enabled and ipv4L3Protocol inconsistent");
578 
579  bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx", MakeCallback (&Ipv4L3ProtocolRxTxSink));
580  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv4Internal(): "
581  "Unable to connect ipv4L3Protocol \"Tx\"");
582 
583  result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv4L3ProtocolRxTxSink));
584  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv4Internal(): "
585  "Unable to connect ipv4L3Protocol \"Rx\"");
586  }
587 
588  g_interfaceFileMapIpv4[std::make_pair (ipv4, interface)] = file;
589 }
590 
597 static void
599 {
600  NS_LOG_FUNCTION (p << ipv6 << interface);
601 
602  //
603  // Since trace sources are independent of interface, if we hook a source
604  // on a particular protocol we will get traces for all of its interfaces.
605  // We need to filter this to only report interfaces for which the user
606  // has expressed interest.
607  //
608  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
609  if (g_interfaceFileMapIpv6.find (pair) == g_interfaceFileMapIpv6.end ())
610  {
611  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
612  return;
613  }
614 
616  file->Write (Simulator::Now (), p);
617 }
618 
619 bool
621 {
622  for ( InterfaceFileMapIpv6::const_iterator i = g_interfaceFileMapIpv6.begin ();
623  i != g_interfaceFileMapIpv6.end ();
624  ++i)
625  {
626  if ((*i).first.first == ipv6)
627  {
628  return true;
629  }
630  }
631  return false;
632 }
633 
634 void
635 InternetStackHelper::EnablePcapIpv6Internal (std::string prefix, Ptr<Ipv6> ipv6, uint32_t interface, bool explicitFilename)
636 {
637  NS_LOG_FUNCTION (prefix << ipv6 << interface);
638 
639  if (!m_ipv6Enabled)
640  {
641  NS_LOG_INFO ("Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
642  return;
643  }
644 
645  //
646  // We have to create a file and a mapping from protocol/interface to file
647  // irrespective of how many times we want to trace a particular protocol.
648  //
649  PcapHelper pcapHelper;
650 
651  std::string filename;
652  if (explicitFilename)
653  {
654  filename = prefix;
655  }
656  else
657  {
658  filename = pcapHelper.GetFilenameFromInterfacePair (prefix, ipv6, interface);
659  }
660 
661  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, PcapHelper::DLT_RAW);
662 
663  //
664  // However, we only hook the trace source once to avoid multiple trace sink
665  // calls per event (connect is independent of interface).
666  //
667  if (!PcapHooked (ipv6))
668  {
669  //
670  // Ptr<Ipv6> is aggregated to node and Ipv6L3Protocol is aggregated to
671  // node so we can get to Ipv6L3Protocol through Ipv6.
672  //
673  Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol> ();
674  NS_ASSERT_MSG (ipv6L3Protocol, "InternetStackHelper::EnablePcapIpv6Internal(): "
675  "m_ipv6Enabled and ipv6L3Protocol inconsistent");
676 
677  bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx", MakeCallback (&Ipv6L3ProtocolRxTxSink));
678  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv6Internal(): "
679  "Unable to connect ipv6L3Protocol \"Tx\"");
680 
681  result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv6L3ProtocolRxTxSink));
682  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv6Internal(): "
683  "Unable to connect ipv6L3Protocol \"Rx\"");
684  }
685 
686  g_interfaceFileMapIpv6[std::make_pair (ipv6, interface)] = file;
687 }
688 
698 static void
701  Ipv4Header const &header,
702  Ptr<const Packet> packet,
704  Ptr<Ipv4> ipv4,
705  uint32_t interface)
706 {
707  //
708  // Since trace sources are independent of interface, if we hook a source
709  // on a particular protocol we will get traces for all of its interfaces.
710  // We need to filter this to only report interfaces for which the user
711  // has expressed interest.
712  //
713  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
714  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
715  {
716  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
717  return;
718  }
719 
720  Ptr<Packet> p = packet->Copy ();
721  p->AddHeader (header);
722  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
723 }
724 
732 static void
735  Ptr<const Packet> packet,
736  Ptr<Ipv4> ipv4,
737  uint32_t interface)
738 {
739  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
740  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
741  {
742  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
743  return;
744  }
745 
746  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
747 }
748 
756 static void
759  Ptr<const Packet> packet,
760  Ptr<Ipv4> ipv4,
761  uint32_t interface)
762 {
763  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
764  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
765  {
766  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
767  return;
768  }
769 
770  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
771 }
772 
783 static void
786  std::string context,
787  Ipv4Header const &header,
788  Ptr<const Packet> packet,
790  Ptr<Ipv4> ipv4,
791  uint32_t interface)
792 {
793  //
794  // Since trace sources are independent of interface, if we hook a source
795  // on a particular protocol we will get traces for all of its interfaces.
796  // We need to filter this to only report interfaces for which the user
797  // has expressed interest.
798  //
799  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
800  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
801  {
802  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
803  return;
804  }
805 
806  Ptr<Packet> p = packet->Copy ();
807  p->AddHeader (header);
808 #ifdef INTERFACE_CONTEXT
809  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
810  << *p << std::endl;
811 #else
812  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
813 #endif
814 }
815 
824 static void
827  std::string context,
828  Ptr<const Packet> packet,
829  Ptr<Ipv4> ipv4,
830  uint32_t interface)
831 {
832  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
833  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
834  {
835  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
836  return;
837  }
838 
839 #ifdef INTERFACE_CONTEXT
840  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
841  << *packet << std::endl;
842 #else
843  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
844 #endif
845 }
846 
855 static void
858  std::string context,
859  Ptr<const Packet> packet,
860  Ptr<Ipv4> ipv4,
861  uint32_t interface)
862 {
863  InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
864  if (g_interfaceStreamMapIpv4.find (pair) == g_interfaceStreamMapIpv4.end ())
865  {
866  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
867  return;
868  }
869 
870 #ifdef INTERFACE_CONTEXT
871  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
872  << *packet << std::endl;
873 #else
874  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
875 #endif
876 }
877 
878 bool
880 {
881  for ( InterfaceStreamMapIpv4::const_iterator i = g_interfaceStreamMapIpv4.begin ();
882  i != g_interfaceStreamMapIpv4.end ();
883  ++i)
884  {
885  if ((*i).first.first == ipv4)
886  {
887  return true;
888  }
889  }
890  return false;
891 }
892 
893 void
895  Ptr<OutputStreamWrapper> stream,
896  std::string prefix,
897  Ptr<Ipv4> ipv4,
898  uint32_t interface,
899  bool explicitFilename)
900 {
901  if (!m_ipv4Enabled)
902  {
903  NS_LOG_INFO ("Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
904  return;
905  }
906 
907  //
908  // Our trace sinks are going to use packet printing, so we have to
909  // make sure that is turned on.
910  //
912 
913  //
914  // If we are not provided an OutputStreamWrapper, we are expected to create
915  // one using the usual trace filename conventions and hook WithoutContext
916  // since there will be one file per context and therefore the context would
917  // be redundant.
918  //
919  if (stream == 0)
920  {
921  //
922  // Set up an output stream object to deal with private ofstream copy
923  // constructor and lifetime issues. Let the helper decide the actual
924  // name of the file given the prefix.
925  //
926  // We have to create a stream and a mapping from protocol/interface to
927  // stream irrespective of how many times we want to trace a particular
928  // protocol.
929  //
930  AsciiTraceHelper asciiTraceHelper;
931 
932  std::string filename;
933  if (explicitFilename)
934  {
935  filename = prefix;
936  }
937  else
938  {
939  filename = asciiTraceHelper.GetFilenameFromInterfacePair (prefix, ipv4, interface);
940  }
941 
942  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
943 
944  //
945  // However, we only hook the trace sources once to avoid multiple trace sink
946  // calls per event (connect is independent of interface).
947  //
948  if (!AsciiHooked (ipv4))
949  {
950  //
951  // We can use the default drop sink for the ArpL3Protocol since it has
952  // the usual signature. We can get to the Ptr<ArpL3Protocol> through
953  // our Ptr<Ipv4> since they must both be aggregated to the same node.
954  //
955  Ptr<ArpL3Protocol> arpL3Protocol = ipv4->GetObject<ArpL3Protocol> ();
956  asciiTraceHelper.HookDefaultDropSinkWithoutContext<ArpL3Protocol> (arpL3Protocol, "Drop", theStream);
957 
958  //
959  // The drop sink for the Ipv4L3Protocol uses a different signature than
960  // the default sink, so we have to cook one up for ourselves. We can get
961  // to the Ptr<Ipv4L3Protocol> through our Ptr<Ipv4> since they must both
962  // be aggregated to the same node.
963  //
964  Ptr<Ipv4L3Protocol> ipv4L3Protocol = ipv4->GetObject<Ipv4L3Protocol> ();
965  bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop",
967  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
968  "Unable to connect ipv4L3Protocol \"Drop\"");
969  result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx",
971  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
972  "Unable to connect ipv4L3Protocol \"Tx\"");
973  result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx",
975  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): "
976  "Unable to connect ipv4L3Protocol \"Rx\"");
977  }
978 
979  g_interfaceStreamMapIpv4[std::make_pair (ipv4, interface)] = theStream;
980  return;
981  }
982 
983  //
984  // If we are provided an OutputStreamWrapper, we are expected to use it, and
985  // to provide a context. We are free to come up with our own context if we
986  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
987  // compatibility and simplicity, we just use Config::Connect and let it deal
988  // with the context.
989  //
990  // We need to associate the ipv4/interface with a stream to express interest
991  // in tracing events on that pair, however, we only hook the trace sources
992  // once to avoid multiple trace sink calls per event (connect is independent
993  // of interface).
994  //
995  if (!AsciiHooked (ipv4))
996  {
997  Ptr<Node> node = ipv4->GetObject<Node> ();
998  std::ostringstream oss;
999 
1000  //
1001  // For the ARP Drop, we are going to use the default trace sink provided by
1002  // the ascii trace helper. There is actually no AsciiTraceHelper in sight
1003  // here, but the default trace sinks are actually publicly available static
1004  // functions that are always there waiting for just such a case.
1005  //
1006  oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop";
1008 
1009  //
1010  // This has all kinds of parameters coming with, so we have to cook up our
1011  // own sink.
1012  //
1013  oss.str ("");
1014  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop";
1016  oss.str ("");
1017  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Tx";
1019  oss.str ("");
1020  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Rx";
1022  }
1023 
1024  g_interfaceStreamMapIpv4[std::make_pair (ipv4, interface)] = stream;
1025 }
1026 
1036 static void
1038  Ptr<OutputStreamWrapper> stream,
1039  Ipv6Header const &header,
1040  Ptr<const Packet> packet,
1042  Ptr<Ipv6> ipv6,
1043  uint32_t interface)
1044 {
1045  //
1046  // Since trace sources are independent of interface, if we hook a source
1047  // on a particular protocol we will get traces for all of its interfaces.
1048  // We need to filter this to only report interfaces for which the user
1049  // has expressed interest.
1050  //
1051  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1052  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1053  {
1054  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1055  return;
1056  }
1057 
1058  Ptr<Packet> p = packet->Copy ();
1059  p->AddHeader (header);
1060  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
1061 }
1062 
1070 static void
1072  Ptr<OutputStreamWrapper> stream,
1073  Ptr<const Packet> packet,
1074  Ptr<Ipv6> ipv6,
1075  uint32_t interface)
1076 {
1077  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1078  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1079  {
1080  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1081  return;
1082  }
1083 
1084  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
1085 }
1086 
1094 static void
1096  Ptr<OutputStreamWrapper> stream,
1097  Ptr<const Packet> packet,
1098  Ptr<Ipv6> ipv6,
1099  uint32_t interface)
1100 {
1101  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1102  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1103  {
1104  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1105  return;
1106  }
1107 
1108  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *packet << std::endl;
1109 }
1110 
1121 static void
1123  Ptr<OutputStreamWrapper> stream,
1124  std::string context,
1125  Ipv6Header const &header,
1126  Ptr<const Packet> packet,
1128  Ptr<Ipv6> ipv6,
1129  uint32_t interface)
1130 {
1131  //
1132  // Since trace sources are independent of interface, if we hook a source
1133  // on a particular protocol we will get traces for all of its interfaces.
1134  // We need to filter this to only report interfaces for which the user
1135  // has expressed interest.
1136  //
1137  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1138  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1139  {
1140  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1141  return;
1142  }
1143 
1144  Ptr<Packet> p = packet->Copy ();
1145  p->AddHeader (header);
1146 #ifdef INTERFACE_CONTEXT
1147  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1148  << *p << std::endl;
1149 #else
1150  *stream->GetStream () << "d " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
1151 #endif
1152 }
1153 
1162 static void
1164  Ptr<OutputStreamWrapper> stream,
1165  std::string context,
1166  Ptr<const Packet> packet,
1167  Ptr<Ipv6> ipv6,
1168  uint32_t interface)
1169 {
1170  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1171  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1172  {
1173  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1174  return;
1175  }
1176 
1177 #ifdef INTERFACE_CONTEXT
1178  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1179  << *packet << std::endl;
1180 #else
1181  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
1182 #endif
1183 }
1184 
1193 static void
1195  Ptr<OutputStreamWrapper> stream,
1196  std::string context,
1197  Ptr<const Packet> packet,
1198  Ptr<Ipv6> ipv6,
1199  uint32_t interface)
1200 {
1201  InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1202  if (g_interfaceStreamMapIpv6.find (pair) == g_interfaceStreamMapIpv6.end ())
1203  {
1204  NS_LOG_INFO ("Ignoring packet to/from interface " << interface);
1205  return;
1206  }
1207 
1208 #ifdef INTERFACE_CONTEXT
1209  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << "(" << interface << ") "
1210  << *packet << std::endl;
1211 #else
1212  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *packet << std::endl;
1213 #endif
1214 }
1215 
1216 bool
1218 {
1219  for ( InterfaceStreamMapIpv6::const_iterator i = g_interfaceStreamMapIpv6.begin ();
1220  i != g_interfaceStreamMapIpv6.end ();
1221  ++i)
1222  {
1223  if ((*i).first.first == ipv6)
1224  {
1225  return true;
1226  }
1227  }
1228  return false;
1229 }
1230 
1231 void
1233  Ptr<OutputStreamWrapper> stream,
1234  std::string prefix,
1235  Ptr<Ipv6> ipv6,
1236  uint32_t interface,
1237  bool explicitFilename)
1238 {
1239  if (!m_ipv6Enabled)
1240  {
1241  NS_LOG_INFO ("Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1242  return;
1243  }
1244 
1245  //
1246  // Our trace sinks are going to use packet printing, so we have to
1247  // make sure that is turned on.
1248  //
1250 
1251  //
1252  // If we are not provided an OutputStreamWrapper, we are expected to create
1253  // one using the usual trace filename conventions and do a hook WithoutContext
1254  // since there will be one file per context and therefore the context would
1255  // be redundant.
1256  //
1257  if (stream == 0)
1258  {
1259  //
1260  // Set up an output stream object to deal with private ofstream copy
1261  // constructor and lifetime issues. Let the helper decide the actual
1262  // name of the file given the prefix.
1263  //
1264  // We have to create a stream and a mapping from protocol/interface to
1265  // stream irrespective of how many times we want to trace a particular
1266  // protocol.
1267  //
1268  AsciiTraceHelper asciiTraceHelper;
1269 
1270  std::string filename;
1271  if (explicitFilename)
1272  {
1273  filename = prefix;
1274  }
1275  else
1276  {
1277  filename = asciiTraceHelper.GetFilenameFromInterfacePair (prefix, ipv6, interface);
1278  }
1279 
1280  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
1281 
1282  //
1283  // However, we only hook the trace sources once to avoid multiple trace sink
1284  // calls per event (connect is independent of interface).
1285  //
1286  if (!AsciiHooked (ipv6))
1287  {
1288  //
1289  // The drop sink for the Ipv6L3Protocol uses a different signature than
1290  // the default sink, so we have to cook one up for ourselves. We can get
1291  // to the Ptr<Ipv6L3Protocol> through our Ptr<Ipv6> since they must both
1292  // be aggregated to the same node.
1293  //
1294  Ptr<Ipv6L3Protocol> ipv6L3Protocol = ipv6->GetObject<Ipv6L3Protocol> ();
1295  bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Drop",
1297  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1298  "Unable to connect ipv6L3Protocol \"Drop\"");
1299  result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx",
1301  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1302  "Unable to connect ipv6L3Protocol \"Tx\"");
1303  result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx",
1305  NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): "
1306  "Unable to connect ipv6L3Protocol \"Rx\"");
1307  }
1308 
1309  g_interfaceStreamMapIpv6[std::make_pair (ipv6, interface)] = theStream;
1310  return;
1311  }
1312 
1313  //
1314  // If we are provided an OutputStreamWrapper, we are expected to use it, and
1315  // to provide a context. We are free to come up with our own context if we
1316  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
1317  // compatibility and simplicity, we just use Config::Connect and let it deal
1318  // with the context.
1319  //
1320  // We need to associate the ipv4/interface with a stream to express interest
1321  // in tracing events on that pair, however, we only hook the trace sources
1322  // once to avoid multiple trace sink calls per event (connect is independent
1323  // of interface).
1324  //
1325  if (!AsciiHooked (ipv6))
1326  {
1327  Ptr<Node> node = ipv6->GetObject<Node> ();
1328  std::ostringstream oss;
1329 
1330  oss.str ("");
1331  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Drop";
1333  oss.str ("");
1334  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Tx";
1336  oss.str ("");
1337  oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv6L3Protocol/Rx";
1339  }
1340 
1341  g_interfaceStreamMapIpv6[std::make_pair (ipv6, interface)] = stream;
1342 }
1343 
1344 } // 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:128
Doxygen 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)
Definition: log.h:345
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, uint32_t dataLinkType, uint32_t snapLen=65535, int32_t tzCorrection=0)
Create and initialize a pcap file.
Definition: trace-helper.cc:49
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:321
std::vector< Ptr< Node > >::const_iterator Iterator
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:79
hold variables of type string
Definition: string.h:19
static const uint8_t EXT_NUMBER
Fragmentation extension number.
Hold a value for an Attribute.
Definition: attribute.h:56
void SetIpv4ArpJitter(bool enable)
Enable/disable IPv4 ARP Jitter.
Manage pcap files for device models.
Definition: trace-helper.h:38
IPv6 layer implementation.
Doxygen 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)
Build bound Callbacks which take varying numbers of arguments, and potentially returning a value...
Definition: callback.h:1463
static InterfaceFileMapIpv4 g_interfaceFileMapIpv4
A mapping of Ipv4/interface pairs to pcap files.
ObjectFactory m_tcpFactory
TCP objects factory.
virtual Ipv6RoutingHelper * Copy(void) const =0
virtual constructor
#define NS_ASSERT(condition)
Definition: assert.h:64
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
void SetTypeId(TypeId tid)
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)
Definition: log.h:298
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.
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.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
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.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
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
Definition: nstime.h:274
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)
By default, packets do not keep around enough metadata to perform the operations requested by the Pri...
Definition: packet.cc:552
Ptr< Object > Create(void) const
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:1238
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...
void AggregateObject(Ptr< Object > other)
Definition: object.cc:243
bool m_ipv6Enabled
IPv6 install state (enabled/disabled) ?
a factory to create ns3::Ipv4RoutingProtocol objects
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:75
Ptr< Packet > Copy(void) const
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)
Definition: object-base.cc:269
Implement the Ipv4 layer.
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.
NS_LOG_COMPONENT_DEFINE("InternetStackHelper")
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)
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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)
Definition: assert.h:86
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
void Add(const Ipv6RoutingHelper &routing, int16_t priority)
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:104
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:55
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.
Helper class that adds ns3::Ipv4GlobalRouting objects.
Helper class that adds ns3::Ipv6ListRouting 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:63
std::map< InterfacePairIpv4, Ptr< PcapFileWrapper > > InterfaceFileMapIpv4
Ipv4/interface and Pcap file wrapper container.
const Ipv4RoutingHelper * m_routing
IPv4 routing helper.
Ptr< T > GetObject(void) const
Definition: object.h:361
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:253
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.