151 #include "ns3/assert.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/global-router-interface.h"
193 #define INTERFACE_CONTEXT
218 typedef std::pair<Ptr<Ipv4>, uint32_t> InterfacePairIpv4;
219 typedef std::map<InterfacePairIpv4, Ptr<PcapFileWrapper> > InterfaceFileMapIpv4;
220 typedef std::map<InterfacePairIpv4, Ptr<OutputStreamWrapper> > InterfaceStreamMapIpv4;
225 typedef std::pair<Ptr<Ipv6>, uint32_t> InterfacePairIpv6;
226 typedef std::map<InterfacePairIpv6, Ptr<PcapFileWrapper> > InterfaceFileMapIpv6;
227 typedef std::map<InterfacePairIpv6, Ptr<OutputStreamWrapper> > InterfaceStreamMapIpv6;
235 m_ipv4Enabled (true),
243 InternetStackHelper::Initialize ()
245 SetTcp (
"ns3::TcpL4Protocol");
251 listRouting.
Add (staticRouting, 0);
252 listRouting.
Add (globalRouting, -10);
253 listRoutingv6.
Add (staticRoutingv6, 0);
266 m_routing = o.m_routing->
Copy ();
270 m_tcpFactory = o.m_tcpFactory;
273 InternetStackHelper &
274 InternetStackHelper::operator = (
const InternetStackHelper &o)
280 m_routing = o.m_routing->
Copy ();
301 m_routing = routing.
Copy ();
325 int64_t currentStream = stream;
326 for (NodeContainer::Iterator i = c.
Begin (); i != c.
End (); ++i)
335 currentStream += gr->AssignStreams (currentStream);
346 return (currentStream - stream);
359 m_tcpFactory.
Set (n0,v0);
365 for (NodeContainer::Iterator i = c.
Begin (); i != c.
End (); ++i)
374 for (NodeContainer::Iterator i = c.
Begin (); i != c.
End (); ++i)
403 "an InternetStack to a node with an existing Ipv4 object");
413 ipv4->SetRoutingProtocol (ipv4Routing);
422 "an InternetStack to a node with an existing Ipv6 object");
431 ipv6->SetRoutingProtocol (ipv6Routing);
434 ipv6->RegisterExtensions ();
435 ipv6->RegisterOptions ();
451 node->
GetObject <
Ipv4>()->GetRoutingProtocol()->SetRepository(repo);
457 Ptr<Node> node = Names::Find<Node> (nodeName);
472 InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
475 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
490 if ((*i).first.first == ipv4)
505 NS_LOG_INFO (
"Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
515 std::string filename;
516 if (explicitFilename)
538 NS_ASSERT_MSG (ipv4L3Protocol,
"InternetStackHelper::EnablePcapIpv4Internal(): "
539 "m_ipv4Enabled and ipv4L3Protocol inconsistent");
541 bool result = ipv4L3Protocol->TraceConnectWithoutContext (
"Tx",
MakeCallback (&Ipv4L3ProtocolRxTxSink));
542 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv4Internal(): "
543 "Unable to connect ipv4L3Protocol \"Tx\"");
545 result = ipv4L3Protocol->TraceConnectWithoutContext (
"Rx",
MakeCallback (&Ipv4L3ProtocolRxTxSink));
546 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv4Internal(): "
547 "Unable to connect ipv4L3Protocol \"Rx\"");
564 InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
567 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
582 if ((*i).first.first == ipv6)
597 NS_LOG_INFO (
"Call to enable Ipv6 pcap tracing but Ipv6 not enabled");
607 std::string filename;
608 if (explicitFilename)
630 NS_ASSERT_MSG (ipv6L3Protocol,
"InternetStackHelper::EnablePcapIpv6Internal(): "
631 "m_ipv6Enabled and ipv6L3Protocol inconsistent");
633 bool result = ipv6L3Protocol->TraceConnectWithoutContext (
"Tx",
MakeCallback (&Ipv6L3ProtocolRxTxSink));
634 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv6Internal(): "
635 "Unable to connect ipv6L3Protocol \"Tx\"");
637 result = ipv6L3Protocol->TraceConnectWithoutContext (
"Rx",
MakeCallback (&Ipv6L3ProtocolRxTxSink));
638 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnablePcapIpv6Internal(): "
639 "Unable to connect ipv6L3Protocol \"Rx\"");
646 Ipv4L3ProtocolDropSinkWithoutContext (
660 InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
663 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
667 Ptr<Packet> p = packet->
Copy ();
673 Ipv4L3ProtocolTxSinkWithoutContext (
674 Ptr<OutputStreamWrapper> stream,
675 Ptr<const Packet> packet,
679 InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
682 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
690 Ipv4L3ProtocolRxSinkWithoutContext (
691 Ptr<OutputStreamWrapper> stream,
692 Ptr<const Packet> packet,
696 InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
699 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
707 Ipv4L3ProtocolDropSinkWithContext (
708 Ptr<OutputStreamWrapper> stream,
710 Ipv4Header
const &header,
711 Ptr<const Packet> packet,
722 InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
725 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
729 Ptr<Packet> p = packet->Copy ();
730 p->AddHeader (header);
731 #ifdef INTERFACE_CONTEXT
740 Ipv4L3ProtocolTxSinkWithContext (
741 Ptr<OutputStreamWrapper> stream,
743 Ptr<const Packet> packet,
747 InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
750 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
754 #ifdef INTERFACE_CONTEXT
756 << *packet << std::endl;
763 Ipv4L3ProtocolRxSinkWithContext (
764 Ptr<OutputStreamWrapper> stream,
766 Ptr<const Packet> packet,
770 InterfacePairIpv4 pair = std::make_pair (ipv4, interface);
773 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
777 #ifdef INTERFACE_CONTEXT
779 << *packet << std::endl;
792 if ((*i).first.first == ipv4)
806 bool explicitFilename)
810 NS_LOG_INFO (
"Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
839 std::string filename;
840 if (explicitFilename)
873 MakeBoundCallback (&Ipv4L3ProtocolDropSinkWithoutContext, theStream));
874 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv4Internal(): "
875 "Unable to connect ipv4L3Protocol \"Drop\"");
876 result = ipv4L3Protocol->TraceConnectWithoutContext (
"Tx",
877 MakeBoundCallback (&Ipv4L3ProtocolTxSinkWithoutContext, theStream));
878 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv4Internal(): "
879 "Unable to connect ipv4L3Protocol \"Tx\"");
880 result = ipv4L3Protocol->TraceConnectWithoutContext (
"Rx",
881 MakeBoundCallback (&Ipv4L3ProtocolRxSinkWithoutContext, theStream));
882 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv4Internal(): "
883 "Unable to connect ipv4L3Protocol \"Rx\"");
905 std::ostringstream oss;
913 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::ArpL3Protocol/Drop";
914 Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
921 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv4L3Protocol/Drop";
922 Config::Connect (oss.str (), MakeBoundCallback (&Ipv4L3ProtocolDropSinkWithContext, stream));
924 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv4L3Protocol/Tx";
925 Config::Connect (oss.str (), MakeBoundCallback (&Ipv4L3ProtocolTxSinkWithContext, stream));
927 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv4L3Protocol/Rx";
928 Config::Connect (oss.str (), MakeBoundCallback (&Ipv4L3ProtocolRxSinkWithContext, stream));
935 Ipv6L3ProtocolDropSinkWithoutContext (
949 InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
952 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
956 Ptr<Packet> p = packet->
Copy ();
962 Ipv6L3ProtocolTxSinkWithoutContext (
963 Ptr<OutputStreamWrapper> stream,
964 Ptr<const Packet> packet,
968 InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
971 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
979 Ipv6L3ProtocolRxSinkWithoutContext (
980 Ptr<OutputStreamWrapper> stream,
981 Ptr<const Packet> packet,
985 InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
988 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
996 Ipv6L3ProtocolDropSinkWithContext (
997 Ptr<OutputStreamWrapper> stream,
999 Ipv6Header
const &header,
1000 Ptr<const Packet> packet,
1011 InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1014 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
1018 Ptr<Packet> p = packet->Copy ();
1019 p->AddHeader (header);
1020 #ifdef INTERFACE_CONTEXT
1029 Ipv6L3ProtocolTxSinkWithContext (
1030 Ptr<OutputStreamWrapper> stream,
1031 std::string context,
1032 Ptr<const Packet> packet,
1036 InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1039 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
1043 #ifdef INTERFACE_CONTEXT
1045 << *packet << std::endl;
1052 Ipv6L3ProtocolRxSinkWithContext (
1053 Ptr<OutputStreamWrapper> stream,
1054 std::string context,
1055 Ptr<const Packet> packet,
1059 InterfacePairIpv6 pair = std::make_pair (ipv6, interface);
1062 NS_LOG_INFO (
"Ignoring packet to/from interface " << interface);
1066 #ifdef INTERFACE_CONTEXT
1068 << *packet << std::endl;
1081 if ((*i).first.first == ipv6)
1095 bool explicitFilename)
1099 NS_LOG_INFO (
"Call to enable Ipv6 ascii tracing but Ipv6 not enabled");
1128 std::string filename;
1129 if (explicitFilename)
1153 bool result = ipv6L3Protocol->TraceConnectWithoutContext (
"Drop",
1154 MakeBoundCallback (&Ipv6L3ProtocolDropSinkWithoutContext, theStream));
1155 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv6Internal(): "
1156 "Unable to connect ipv6L3Protocol \"Drop\"");
1157 result = ipv6L3Protocol->TraceConnectWithoutContext (
"Tx",
1158 MakeBoundCallback (&Ipv6L3ProtocolTxSinkWithoutContext, theStream));
1159 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv6Internal(): "
1160 "Unable to connect ipv6L3Protocol \"Tx\"");
1161 result = ipv6L3Protocol->TraceConnectWithoutContext (
"Rx",
1162 MakeBoundCallback (&Ipv6L3ProtocolRxSinkWithoutContext, theStream));
1163 NS_ASSERT_MSG (result ==
true,
"InternetStackHelper::EnableAsciiIpv6Internal(): "
1164 "Unable to connect ipv6L3Protocol \"Rx\"");
1186 std::ostringstream oss;
1189 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv6L3Protocol/Drop";
1190 Config::Connect (oss.str (), MakeBoundCallback (&Ipv6L3ProtocolDropSinkWithContext, stream));
1192 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv6L3Protocol/Tx";
1193 Config::Connect (oss.str (), MakeBoundCallback (&Ipv6L3ProtocolTxSinkWithContext, stream));
1195 oss <<
"/NodeList/" << node->
GetId () <<
"/$ns3::Ipv6L3Protocol/Rx";
1196 Config::Connect (oss.str (), MakeBoundCallback (&Ipv6L3ProtocolRxSinkWithContext, stream));
void InstallCR(Ptr< Repository > repo, Ptr< Node > node) const
int64_t AssignStreams(int64_t stream)
Manage ASCII trace files for device models.
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)
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.
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.
static const uint8_t EXT_NUMBER
Fragmentation extension number.
Hold a value for an Attribute.
Manage pcap files for device models.
IPv6 layer implementation.
Demultiplexes IPv6 extensions.
virtual Ipv4RoutingHelper * Copy(void) const =0
virtual constructor
static InterfaceFileMapIpv4 g_interfaceFileMapIpv4
virtual Ipv6RoutingHelper * Copy(void) const =0
virtual constructor
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
void SetTypeId(TypeId tid)
aggregate IP/TCP/UDP functionality to existing Nodes.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
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. ...
void Connect(std::string path, const CallbackBase &cb)
static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4
#define NS_FATAL_ERROR(msg)
fatal error handling
static void CreateAndAggregateObjectFromTypeId(Ptr< Node > node, const std::string typeId)
DropReason
Reason why a packet has been dropped.
double GetSeconds(void) const
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
static void EnablePrinting(void)
Ptr< Object > Create(void) const
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
static InterfaceFileMapIpv6 g_interfaceFileMapIpv6
A factory to create ns3::Ipv6RoutingProtocol objects.
bool PcapHooked(Ptr< Ipv4 > ipv4)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
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)
bool m_ipv6Enabled
IPv6 install state (enabled/disabled) ?
a factory to create ns3::Ipv4RoutingProtocol objects
Access to the Ipv4 forwarding table, interfaces, and configuration.
Ptr< Packet > Copy(void) const
virtual Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const =0
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Implement the Ipv4 layer.
keep track of a set of node pointers.
Helper class that adds ns3::Ipv6StaticRouting objects.
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.
void Install(std::string nodeName) const
void Set(std::string name, const AttributeValue &value)
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
virtual ~InternetStackHelper(void)
An interface aggregated to a node to provide global routing info.
#define NS_ASSERT_MSG(condition, message)
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)
instantiate subclasses of ns3::Object.
const Ipv6RoutingHelper * m_routingv6
IPv6 routing helper.
int64_t AssignStreams(NodeContainer c, int64_t stream)
uint32_t GetId(void) const
Helper class that adds ns3::Ipv4StaticRouting objects.
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)
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)
a base class which provides memory management and object aggregation
Ptr< T > GetObject(void) const
static InterfaceStreamMapIpv6 g_interfaceStreamMapIpv6
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
std::ostream * GetStream(void)
void AddHeader(const Header &header)
bool m_ipv4Enabled
IPv4 install state (enabled/disabled) ?
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.