17#include "ns3/arp-l3-protocol.h" 
   18#include "ns3/assert.h" 
   19#include "ns3/callback.h" 
   20#include "ns3/config.h" 
   21#include "ns3/global-router-interface.h" 
   22#include "ns3/icmpv6-l4-protocol.h" 
   23#include "ns3/ipv4-global-routing.h" 
   25#include "ns3/ipv6-extension-demux.h" 
   26#include "ns3/ipv6-extension-header.h" 
   27#include "ns3/ipv6-extension.h" 
   31#include "ns3/net-device.h" 
   32#include "ns3/node-list.h" 
   34#include "ns3/object.h" 
   35#include "ns3/packet-socket-factory.h" 
   36#include "ns3/simulator.h" 
   37#include "ns3/string.h" 
   38#include "ns3/traffic-control-layer.h" 
   56#define INTERFACE_CONTEXT 
   84typedef std::map<InterfacePairIpv4, Ptr<PcapFileWrapper>>
 
   86typedef std::map<InterfacePairIpv4, Ptr<OutputStreamWrapper>>
 
   95typedef std::map<InterfacePairIpv6, Ptr<PcapFileWrapper>>
 
   97typedef std::map<InterfacePairIpv6, Ptr<OutputStreamWrapper>>
 
  106    : m_routing(nullptr),
 
  107      m_routingv6(nullptr),
 
  110      m_ipv4ArpJitterEnabled(true),
 
  111      m_ipv6NsRsJitterEnabled(true)
 
 
  125    listRouting.
Add(staticRouting, 0);
 
  126    listRouting.
Add(globalRouting, -10);
 
 
  214    int64_t currentStream = stream;
 
  215    for (
auto i = c.
Begin(); i != c.
End(); ++i)
 
  224                currentStream += gr->AssignStreams(currentStream);
 
  232            currentStream += fe->AssignStreams(currentStream);
 
  240                currentStream += arpL3Protocol->AssignStreams(currentStream);
 
  247            if (icmpv6L4Protocol)
 
  249                currentStream += icmpv6L4Protocol->AssignStreams(currentStream);
 
  253    return (currentStream - stream);
 
 
  259    for (
auto i = c.
Begin(); i != c.
End(); ++i)
 
 
  275    if (node->GetObject<
Object>(tid))
 
  283    node->AggregateObject(protocol);
 
 
  299            arp->SetAttribute(
"RequestJitter",
 
  300                              StringValue(
"ns3::ConstantRandomVariable[Constant=0.0]"));
 
  305        if (!ipv4->GetRoutingProtocol())
 
  308            ipv4->SetRoutingProtocol(ipv4Routing);
 
  321            icmpv6l4->SetAttribute(
"SolicitationJitter",
 
  322                                   StringValue(
"ns3::ConstantRandomVariable[Constant=0.0]"));
 
  326        if (!ipv6->GetRoutingProtocol())
 
  329            ipv6->SetRoutingProtocol(ipv6Routing);
 
  332        ipv6->RegisterExtensions();
 
  333        ipv6->RegisterOptions();
 
  344            node->AggregateObject(factory);
 
  354        arp->SetTrafficControl(tc);
 
 
  385        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 
  396    auto id = ipv4->GetObject<
Node>()->GetId();
 
  400        if ((*i).first.first == 
id)
 
 
  412                                            bool explicitFilename)
 
  418        NS_LOG_INFO(
"Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
 
  428    std::string filename;
 
  429    if (explicitFilename)
 
  452                      "InternetStackHelper::EnablePcapIpv4Internal(): " 
  453                      "m_ipv4Enabled and ipv4L3Protocol inconsistent");
 
  458                      "InternetStackHelper::EnablePcapIpv4Internal():  " 
  459                      "Unable to connect ipv4L3Protocol \"Tx\"");
 
  464                      "InternetStackHelper::EnablePcapIpv4Internal():  " 
  465                      "Unable to connect ipv4L3Protocol \"Rx\"");
 
 
  491        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 
  502    auto id = ipv6->GetObject<
Node>()->GetId();
 
  506        if ((*i).first.first == 
id)
 
 
  518                                            bool explicitFilename)
 
  524        NS_LOG_INFO(
"Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
 
  534    std::string filename;
 
  535    if (explicitFilename)
 
  558                      "InternetStackHelper::EnablePcapIpv6Internal(): " 
  559                      "m_ipv6Enabled and ipv6L3Protocol inconsistent");
 
  564                      "InternetStackHelper::EnablePcapIpv6Internal():  " 
  565                      "Unable to connect ipv6L3Protocol \"Tx\"");
 
  570                      "InternetStackHelper::EnablePcapIpv6Internal():  " 
  571                      "Unable to connect ipv6L3Protocol \"Rx\"");
 
 
  603        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
  608    p->AddHeader(header);
 
 
  629        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 
  651        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 
  686        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
  691    p->AddHeader(header);
 
  692#ifdef INTERFACE_CONTEXT 
  694                         << 
interface << ") " << *p << std::endl;
 
 
  719        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
  723#ifdef INTERFACE_CONTEXT 
  725                         << 
interface << ") " << *packet << std::endl;
 
  728                         << *packet << std::endl;
 
 
  750        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
  754#ifdef INTERFACE_CONTEXT 
  756                         << 
interface << ") " << *packet << std::endl;
 
  759                         << *packet << std::endl;
 
 
  766    auto id = ipv4->GetObject<
Node>()->GetId();
 
  770        if ((*i).first.first == 
id)
 
 
  783                                             bool explicitFilename)
 
  787        NS_LOG_INFO(
"Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
 
  816        std::string filename;
 
  817        if (explicitFilename)
 
  855                          "InternetStackHelper::EnableAsciiIpv4Internal():  " 
  856                          "Unable to connect ipv4L3Protocol \"Drop\"");
 
  857            result = ipv4L3Protocol->TraceConnectWithoutContext(
 
  861                          "InternetStackHelper::EnableAsciiIpv4Internal():  " 
  862                          "Unable to connect ipv4L3Protocol \"Tx\"");
 
  863            result = ipv4L3Protocol->TraceConnectWithoutContext(
 
  867                          "InternetStackHelper::EnableAsciiIpv4Internal():  " 
  868                          "Unable to connect ipv4L3Protocol \"Rx\"");
 
  891        std::ostringstream oss;
 
  899        oss << 
"/NodeList/" << node->GetId() << 
"/$ns3::ArpL3Protocol/Drop";
 
  908        oss << 
"/NodeList/" << node->GetId() << 
"/$ns3::Ipv4L3Protocol/Drop";
 
  911        oss << 
"/NodeList/" << node->GetId() << 
"/$ns3::Ipv4L3Protocol/Tx";
 
  914        oss << 
"/NodeList/" << node->GetId() << 
"/$ns3::Ipv4L3Protocol/Rx";
 
 
  947        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
  952    p->AddHeader(header);
 
 
  972        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 
  995        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 
 1014                                  std::string context,
 
 1030        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 1035    p->AddHeader(header);
 
 1036#ifdef INTERFACE_CONTEXT 
 1038                         << 
interface << ") " << *p << std::endl;
 
 
 1055                                std::string context,
 
 1063        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 1067#ifdef INTERFACE_CONTEXT 
 1069                         << 
interface << ") " << *packet << std::endl;
 
 1072                         << *packet << std::endl;
 
 
 1086                                std::string context,
 
 1094        NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
 
 1098#ifdef INTERFACE_CONTEXT 
 1100                         << 
interface << ") " << *packet << std::endl;
 
 1103                         << *packet << std::endl;
 
 
 1110    auto id = ipv6->GetObject<
Node>()->GetId();
 
 1114        if ((*i).first.first == 
id)
 
 
 1127                                             bool explicitFilename)
 
 1131        NS_LOG_INFO(
"Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
 
 1160        std::string filename;
 
 1161        if (explicitFilename)
 
 1185            bool result = ipv6L3Protocol->TraceConnectWithoutContext(
 
 1189                          "InternetStackHelper::EnableAsciiIpv6Internal():  " 
 1190                          "Unable to connect ipv6L3Protocol \"Drop\"");
 
 1191            result = ipv6L3Protocol->TraceConnectWithoutContext(
 
 1195                          "InternetStackHelper::EnableAsciiIpv6Internal():  " 
 1196                          "Unable to connect ipv6L3Protocol \"Tx\"");
 
 1197            result = ipv6L3Protocol->TraceConnectWithoutContext(
 
 1201                          "InternetStackHelper::EnableAsciiIpv6Internal():  " 
 1202                          "Unable to connect ipv6L3Protocol \"Rx\"");
 
 1225        std::ostringstream oss;
 
 1228        oss << 
"/NodeList/" << node->GetId() << 
"/$ns3::Ipv6L3Protocol/Drop";
 
 1231        oss << 
"/NodeList/" << node->GetId() << 
"/$ns3::Ipv6L3Protocol/Tx";
 
 1234        oss << 
"/NodeList/" << node->GetId() << 
"/$ns3::Ipv6L3Protocol/Rx";
 
 
An implementation of the ARP protocol.
Manage ASCII trace files for device models.
void HookDefaultDropSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default drop operation trace sink that does not accept nor log a trace con...
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop default trace sink.
std::string GetFilenameFromInterfacePair(std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true)
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated...
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
An interface aggregated to a node to provide global routing info.
An implementation of the ICMPv6 protocol.
aggregate IP/TCP/UDP functionality to existing Nodes.
void EnablePcapIpv6Internal(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename) override
Enable pcap output the indicated Ipv6 and interface pair.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetIpv4ArpJitter(bool enable)
Enable/disable IPv4 ARP Jitter.
void EnableAsciiIpv4Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename) override
Enable ascii trace output on the indicated Ipv4 and interface pair.
bool m_ipv6Enabled
IPv6 install state (enabled/disabled) ?
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
bool m_ipv6NsRsJitterEnabled
IPv6 IPv6 NS and RS Jitter state (enabled/disabled) ?
bool AsciiHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to an ascii output stream
bool m_ipv4Enabled
IPv4 install state (enabled/disabled) ?
const Ipv4RoutingHelper * m_routing
IPv4 routing helper.
void InstallAll() const
Aggregate IPv4, IPv6, UDP, and TCP stacks to all nodes in the simulation.
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
static void CreateAndAggregateObjectFromTypeId(Ptr< Node > node, const std::string typeId)
create an object from its TypeId and aggregates it to the node.
void Initialize()
Initialize the helper to its default values.
void SetIpv6NsRsJitter(bool enable)
Enable/disable IPv6 NS and RS Jitter.
bool PcapHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to a Pcap wrapper
void EnablePcapIpv4Internal(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename) override
Enable pcap output the indicated Ipv4 and interface pair.
bool m_ipv4ArpJitterEnabled
IPv4 ARP Jitter state (enabled/disabled) ?
const Ipv6RoutingHelper * m_routingv6
IPv6 routing helper.
InternetStackHelper & operator=(const InternetStackHelper &o)
Copy constructor.
InternetStackHelper()
Create a new InternetStackHelper which uses a mix of static routing and global routing by default.
void Reset()
Return helper internal state to that of a newly constructed one.
~InternetStackHelper() override
Destroy the InternetStackHelper.
void EnableAsciiIpv6Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename) override
Enable ascii trace output on the indicated Ipv6 and interface pair.
Helper class that adds ns3::Ipv4GlobalRouting objects.
Access to the IPv4 forwarding table, interfaces, and configuration.
Implement the IPv4 layer.
DropReason
Reason why a packet has been dropped.
Helper class that adds ns3::Ipv4ListRouting objects.
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
a factory to create ns3::Ipv4RoutingProtocol objects
virtual Ipv4RoutingHelper * Copy() const =0
virtual constructor
virtual Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const =0
Helper class that adds ns3::Ipv4StaticRouting objects.
Demultiplexes IPv6 extensions.
static const uint8_t EXT_NUMBER
Fragmentation extension number.
Access to the IPv6 forwarding table, interfaces, and configuration.
IPv6 layer implementation.
DropReason
Reason why a packet has been dropped.
A factory to create ns3::Ipv6RoutingProtocol objects.
virtual Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const =0
virtual Ipv6RoutingHelper * Copy() const =0
virtual constructor
Helper class that adds ns3::Ipv6StaticRouting objects.
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
static void EnablePrinting()
Enable printing packets metadata.
This can be used as an interface in a node in order for the node to generate PacketSockets that can c...
Manage pcap files for device models.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, DataLinkType dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0)
Create and initialize a pcap file.
std::string GetFilenameFromInterfacePair(std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true)
Let the pcap helper figure out a reasonable filename to use for the pcap file associated with a node.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Hold variables of type string.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructu...
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void Connect(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::pair< Ptr< Ipv4 >, uint32_t > InterfacePairIpv4
Ipv4/interface pair.
static void Ipv6L3ProtocolDropSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, const Ipv6Header &header, Ptr< const Packet > packet, Ipv6L3Protocol::DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 dropped packet - Ascii output.
std::map< InterfacePairIpv4, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv4
Ipv4/interface and output stream container.
static void Ipv4L3ProtocolDropSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, const Ipv4Header &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Packet dropped callback with context.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static void Ipv6L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 packet - Pcap output.
std::map< InterfacePairIpv4, Ptr< PcapFileWrapper > > InterfaceFileMapIpv4
Ipv4/interface and Pcap file wrapper container.
static void Ipv4L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interface)
IPv4 Rx / Tx packet callback.
static void Ipv6L3ProtocolRxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 received packet - Ascii output.
std::map< InterfacePairIpv6, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv6
Ipv6/interface and output stream container.
static InterfaceStreamMapIpv6 g_interfaceStreamMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
std::map< InterfacePairIpv6, Ptr< PcapFileWrapper > > InterfaceFileMapIpv6
Ipv6/interface and Pcap file wrapper container.
std::pair< uint32_t, uint32_t > InterfacePairIpv6
Ipv6/interface pair.
static void Ipv4L3ProtocolRxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 received packet - Ascii output.
static void Ipv6L3ProtocolTxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 transmitted packet - Ascii output.
static void Ipv4L3ProtocolRxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 received packet - Ascii output.
static InterfaceFileMapIpv4 g_interfaceFileMapIpv4
A mapping of Ipv4/interface pairs to pcap files.
static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4
A mapping of Ipv4/interface pairs to ascii streams.
static void Ipv4L3ProtocolDropSinkWithoutContext(Ptr< OutputStreamWrapper > stream, const Ipv4Header &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Packet dropped callback without context.
static void Ipv4L3ProtocolTxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 transmitted packet - Ascii output.
static InterfaceFileMapIpv6 g_interfaceFileMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
static void Ipv4L3ProtocolTxSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 transmitted packet - Ascii output.
static void Ipv6L3ProtocolRxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 received packet - Ascii output.
static void Ipv6L3ProtocolTxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 transmitted packet - Ascii output.
static void Ipv6L3ProtocolDropSinkWithoutContext(Ptr< OutputStreamWrapper > stream, const Ipv6Header &header, Ptr< const Packet > packet, Ipv6L3Protocol::DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 dropped packet - Ascii output.