|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
22 #include "ns3/assert.h"
24 #include "ns3/object.h"
25 #include "ns3/names.h"
28 #include "ns3/packet-socket-factory.h"
29 #include "ns3/config.h"
30 #include "ns3/simulator.h"
31 #include "ns3/string.h"
32 #include "ns3/net-device.h"
33 #include "ns3/callback.h"
35 #include "ns3/node-list.h"
36 #include "ns3/core-config.h"
37 #include "ns3/arp-l3-protocol.h"
39 #include "ns3/ipv4-global-routing.h"
40 #include "ns3/ipv4-list-routing-helper.h"
41 #include "ns3/ipv4-static-routing-helper.h"
42 #include "ns3/ipv4-global-routing-helper.h"
43 #include "ns3/ipv6-static-routing-helper.h"
44 #include "ns3/ipv6-extension.h"
45 #include "ns3/ipv6-extension-demux.h"
46 #include "ns3/ipv6-extension-header.h"
47 #include "ns3/icmpv6-l4-protocol.h"
48 #include "ns3/global-router-interface.h"
49 #include "ns3/traffic-control-layer.h"
65 #define INTERFACE_CONTEXT
107 m_ipv4Enabled (true),
108 m_ipv6Enabled (true),
109 m_ipv4ArpJitterEnabled (true),
110 m_ipv6NsRsJitterEnabled (true)
120 SetTcp (
"ns3::TcpL4Protocol");
125 listRouting.
Add (staticRouting, 0);
126 listRouting.
Add (globalRouting, -10);
212 int64_t currentStream = stream;
222 currentStream += gr->AssignStreams (currentStream);
236 if (arpL3Protocol != 0)
238 currentStream += arpL3Protocol->AssignStreams (currentStream);
245 if (icmpv6L4Protocol != 0)
247 currentStream += icmpv6L4Protocol->AssignStreams (currentStream);
251 return (currentStream - stream);
299 "an InternetStack to a node with an existing Ipv4 object");
310 arp->SetAttribute (
"RequestJitter",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
315 ipv4->SetRoutingProtocol (ipv4Routing);
324 "an InternetStack to a node with an existing Ipv6 object");
334 icmpv6l4->SetAttribute (
"SolicitationJitter",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
339 ipv6->SetRoutingProtocol (ipv6Routing);
342 ipv6->RegisterExtensions ();
343 ipv6->RegisterOptions ();
361 arp->SetTrafficControl (tc);
368 Ptr<Node> node = Names::Find<Node> (nodeName);
392 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
407 if ((*i).first.first == ipv4)
422 NS_LOG_INFO (
"Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
432 std::string filename;
433 if (explicitFilename)
455 NS_ASSERT_MSG (ipv4L3Protocol,
"InternetStackHelper::EnablePcapIpv4Internal(): "
456 "m_ipv4Enabled and ipv4L3Protocol inconsistent");
459 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv4Internal(): "
460 "Unable to connect ipv4L3Protocol \"Tx\"");
463 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv4Internal(): "
464 "Unable to connect ipv4L3Protocol \"Rx\"");
490 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
505 if ((*i).first.first == ipv6)
520 NS_LOG_INFO (
"Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
530 std::string filename;
531 if (explicitFilename)
553 NS_ASSERT_MSG (ipv6L3Protocol,
"InternetStackHelper::EnablePcapIpv6Internal(): "
554 "m_ipv6Enabled and ipv6L3Protocol inconsistent");
557 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv6Internal(): "
558 "Unable to connect ipv6L3Protocol \"Tx\"");
561 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv6Internal(): "
562 "Unable to connect ipv6L3Protocol \"Rx\"");
595 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
621 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
645 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
681 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
687 #ifdef INTERFACE_CONTEXT
714 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
718 #ifdef INTERFACE_CONTEXT
720 << *packet << std::endl;
745 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
749 #ifdef INTERFACE_CONTEXT
751 << *packet << std::endl;
764 if ((*i).first.first == ipv4)
778 bool explicitFilename)
782 NS_LOG_INFO (
"Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
811 std::string filename;
812 if (explicitFilename)
846 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv4Internal(): "
847 "Unable to connect ipv4L3Protocol \"Drop\"");
848 result = ipv4L3Protocol->TraceConnectWithoutContext (
"Tx",
850 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv4Internal(): "
851 "Unable to connect ipv4L3Protocol \"Tx\"");
852 result = ipv4L3Protocol->TraceConnectWithoutContext (
"Rx",
854 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv4Internal(): "
855 "Unable to connect ipv4L3Protocol \"Rx\"");
877 std::ostringstream oss;
885 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::ArpL3Protocol/Drop";
893 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv4L3Protocol/Drop";
896 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv4L3Protocol/Tx";
899 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv4L3Protocol/Rx";
933 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
959 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
983 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
1003 std::string context,
1019 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
1025 #ifdef INTERFACE_CONTEXT
1044 std::string context,
1052 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
1056 #ifdef INTERFACE_CONTEXT
1058 << *packet << std::endl;
1075 std::string context,
1083 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
1087 #ifdef INTERFACE_CONTEXT
1089 << *packet << std::endl;
1102 if ((*i).first.first == ipv6)
1116 bool explicitFilename)
1120 NS_LOG_INFO (
"Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1149 std::string filename;
1150 if (explicitFilename)
1174 bool result = ipv6L3Protocol->TraceConnectWithoutContext (
"Drop",
1176 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv6Internal(): "
1177 "Unable to connect ipv6L3Protocol \"Drop\"");
1178 result = ipv6L3Protocol->TraceConnectWithoutContext (
"Tx",
1180 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv6Internal(): "
1181 "Unable to connect ipv6L3Protocol \"Tx\"");
1182 result = ipv6L3Protocol->TraceConnectWithoutContext (
"Rx",
1184 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv6Internal(): "
1185 "Unable to connect ipv6L3Protocol \"Rx\"");
1207 std::ostringstream oss;
1210 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv6L3Protocol/Drop";
1213 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv6L3Protocol/Tx";
1216 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv6L3Protocol/Rx";
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
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.
bool m_ipv6Enabled
IPv6 install state (enabled/disabled) ?
std::pair< Ptr< Ipv4 >, uint32_t > InterfacePairIpv4
Ipv4/interface pair.
static void Ipv4L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 packet - Pcap output.
InternetStackHelper(void)
Create a new InternetStackHelper which uses a mix of static routing and global routing by default.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
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 InterfaceStreamMapIpv6 g_interfaceStreamMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
uint32_t GetId(void) const
void AddHeader(const Header &header)
Add header to this packet.
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 Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Helper class that adds ns3::Ipv4ListRouting objects.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
static void EnablePrinting(void)
Enable printing packets metadata.
IPv6 layer implementation.
Hold a value for an Attribute.
void SetIpv6NsRsJitter(bool enable)
Enable/disable IPv6 NS and RS Jitter.
virtual Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const =0
virtual void EnablePcapIpv6Internal(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename)
Enable pcap output the indicated Ipv6 and interface pair.
Demultiplexes IPv6 extensions.
An interface aggregated to a node to provide global routing info.
void Reset(void)
Return helper internal state to that of a newly constructed one.
void SetTcp(std::string tid)
set the Tcp stack which will not need any other parameter.
void InstallAll(void) const
Aggregate IPv4, IPv6, UDP, and TCP stacks to all nodes in the simulation.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
a factory to create ns3::Ipv4RoutingProtocol objects
DropReason
Reason why a packet has been dropped.
static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4
A mapping of Ipv4/interface pairs to ascii streams.
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.
std::pair< Ptr< Ipv6 >, uint32_t > InterfacePairIpv6
Ipv6/interface pair.
A factory to create ns3::Ipv6RoutingProtocol objects.
virtual Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const =0
std::map< InterfacePairIpv4, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv4
Ipv4/interface and output stream container.
An implementation of the ARP protocol.
DropReason
Reason why a packet has been dropped.
bool m_ipv4ArpJitterEnabled
IPv4 ARP Jitter state (enabled/disabled) ?
virtual ~InternetStackHelper(void)
Destroy the InternetStackHelper.
bool AsciiHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to an ascii output stream
Access to the IPv4 forwarding table, interfaces, and configuration.
Helper class that adds ns3::Ipv4StaticRouting objects.
static InterfaceFileMapIpv6 g_interfaceFileMapIpv6
A mapping of Ipv6/interface pairs to pcap files.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
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.
static void Ipv6L3ProtocolRxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 received 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.
A base class which provides memory management and object aggregation.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
std::map< InterfacePairIpv6, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv6
Ipv6/interface and output stream container.
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...
const Ipv6RoutingHelper * m_routingv6
IPv6 routing helper.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
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.
static void Ipv4L3ProtocolTxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Sync function for IPv4 transmitted packet - Ascii output.
Instantiate subclasses of ns3::Object.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
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.
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
Helper class that adds ns3::Ipv6StaticRouting objects.
bool m_ipv6NsRsJitterEnabled
IPv6 IPv6 NS and RS Jitter state (enabled/disabled) ?
static void Ipv6L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 packet - Pcap output.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Manage pcap files for device models.
void Initialize(void)
Initialize the helper to its default values.
static const uint8_t EXT_NUMBER
Fragmentation extension number.
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.
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 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.
void SetIpv4ArpJitter(bool enable)
Enable/disable IPv4 ARP Jitter.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Hold variables of type string.
Manage ASCII trace files for device models.
static void Ipv6L3ProtocolTxSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Sync function for IPv6 transmitted packet - Ascii output.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
void Connect(std::string path, const CallbackBase &cb)
Introspection did not find any typical Config paths.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
static InterfaceFileMapIpv4 g_interfaceFileMapIpv4
A mapping of Ipv4/interface pairs to pcap files.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
bool PcapHooked(Ptr< Ipv4 > ipv4)
checks if there is an hook to a Pcap wrapper
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Implement the IPv4 layer.
std::map< InterfacePairIpv4, Ptr< PcapFileWrapper > > InterfaceFileMapIpv4
Ipv4/interface and Pcap file wrapper container.
InternetStackHelper & operator=(const InternetStackHelper &o)
Copy constructor.
virtual Ipv4RoutingHelper * Copy(void) const =0
virtual constructor
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
keep track of a set of node pointers.
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...
Access to the IPv6 forwarding table, interfaces, and configuration.
Helper class that adds ns3::Ipv4GlobalRouting objects.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
const Ipv4RoutingHelper * m_routing
IPv4 routing helper.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
static void CreateAndAggregateObjectFromTypeId(Ptr< Node > node, const std::string typeId)
create an object from its TypeId and aggregates it to the node
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop default trace sink.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
virtual Ipv6RoutingHelper * Copy(void) const =0
virtual constructor
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
bool m_ipv4Enabled
IPv4 install state (enabled/disabled) ?
An implementation of the ICMPv6 protocol.
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.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
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.
std::map< InterfacePairIpv6, Ptr< PcapFileWrapper > > InterfaceFileMapIpv6
Ipv6/interface and Pcap file wrapper container.
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 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.
ObjectFactory m_tcpFactory
TCP objects factory.