18 #include "ns3/boolean.h"
19 #include "ns3/config.h"
20 #include "ns3/csma-helper.h"
21 #include "ns3/flow-monitor.h"
22 #include "ns3/flow-monitor-helper.h"
23 #include "ns3/inet-socket-address.h"
24 #include "ns3/internet-stack-helper.h"
25 #include "ns3/ipv4-address-helper.h"
26 #include "ns3/ipv4-global-routing-helper.h"
27 #include "ns3/ipv4-static-routing-helper.h"
29 #include "ns3/node-container.h"
30 #include "ns3/on-off-helper.h"
31 #include "ns3/packet.h"
32 #include "ns3/packet-sink-helper.h"
33 #include "ns3/packet-sink.h"
34 #include "ns3/packet-socket-helper.h"
35 #include "ns3/packet-socket-address.h"
36 #include "ns3/csma-net-device.h"
37 #include "ns3/point-to-point-helper.h"
38 #include "ns3/pointer.h"
39 #include "ns3/simple-channel.h"
40 #include "ns3/simulator.h"
41 #include "ns3/string.h"
43 #include "ns3/uinteger.h"
44 #include "ns3/ipv4-packet-info-tag.h"
57 virtual void DoRun (
void);
59 std::vector<uint8_t> m_firstInterface;
60 std::vector<uint8_t> m_secondInterface;
64 DynamicGlobalRoutingTestCase::DynamicGlobalRoutingTestCase ()
65 :
TestCase (
"Dynamic global routing example"), m_count (0)
67 m_firstInterface.resize (16);
68 m_secondInterface.resize (16);
71 DynamicGlobalRoutingTestCase::~DynamicGlobalRoutingTestCase ()
81 uint8_t now =
static_cast<uint8_t
> (Simulator::Now ().GetSeconds ());
86 m_firstInterface[now]++;
91 DynamicGlobalRoutingTestCase::HandleRead (
Ptr<Socket> socket)
95 while ((packet = socket->
RecvFrom (from)))
104 uint8_t now =
static_cast<uint8_t
> (Simulator::Now ().GetSeconds ());
107 if (tag.GetRecvIf () == 1)
109 m_firstInterface[now]++;
111 if (tag.GetRecvIf () == 2)
113 m_secondInterface[now]++;
144 Config::SetDefault (
"ns3::Ipv4GlobalRouting::RespondToInterfaceEvents",
BooleanValue (
true));
178 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
181 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
184 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
187 ipv4.
SetBase (
"10.250.1.0",
"255.255.255.0");
190 ipv4.
SetBase (
"172.16.1.0",
"255.255.255.0");
195 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
223 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
236 uint32_t ipv4ifIndex1 = 2;
239 Config::Connect (
"/NodeList/6/ApplicationList/*/$ns3::PacketSink/Rx",
240 MakeCallback (&DynamicGlobalRoutingTestCase::SinkRx,
this));
242 Simulator::Schedule (
Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
243 Simulator::Schedule (
Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
249 uint32_t ipv4ifIndex6 = 2;
250 Simulator::Schedule (
Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6);
251 Simulator::Schedule (
Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6);
253 Simulator::Schedule (
Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
254 Simulator::Schedule (
Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
258 NS_TEST_ASSERT_MSG_EQ (m_count, 68,
"Dynamic global routing did not deliver all packets");
262 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[1], 4,
"Dynamic global routing did not deliver all packets");
263 NS_TEST_ASSERT_MSG_EQ (m_secondInterface[2], 5,
"Dynamic global routing did not deliver all packets");
264 NS_TEST_ASSERT_MSG_EQ (m_secondInterface[3], 5,
"Dynamic global routing did not deliver all packets");
265 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[4], 5,
"Dynamic global routing did not deliver all packets");
266 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[5], 5,
"Dynamic global routing did not deliver all packets");
267 NS_TEST_ASSERT_MSG_EQ (m_secondInterface[6], 5,
"Dynamic global routing did not deliver all packets");
268 NS_TEST_ASSERT_MSG_EQ (m_secondInterface[7], 5,
"Dynamic global routing did not deliver all packets");
269 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[8], 5,
"Dynamic global routing did not deliver all packets");
270 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[9], 5,
"Dynamic global routing did not deliver all packets");
271 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[10], 0,
"Dynamic global routing did not deliver all packets");
272 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[11], 4,
"Dynamic global routing did not deliver all packets");
273 NS_TEST_ASSERT_MSG_EQ (m_secondInterface[12], 5,
"Dynamic global routing did not deliver all packets");
274 NS_TEST_ASSERT_MSG_EQ (m_secondInterface[13], 5,
"Dynamic global routing did not deliver all packets");
275 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[14], 5,
"Dynamic global routing did not deliver all packets");
276 NS_TEST_ASSERT_MSG_EQ (m_firstInterface[15], 5,
"Dynamic global routing did not deliver all packets");
277 Simulator::Destroy ();
287 virtual void DoRun (
void);
291 GlobalRoutingSlash32TestCase::GlobalRoutingSlash32TestCase ()
292 :
TestCase (
"Slash 32 global routing example")
296 GlobalRoutingSlash32TestCase::~GlobalRoutingSlash32TestCase ()
329 deviceA->
SetAddress (Mac48Address::Allocate ());
333 deviceC->
SetAddress (Mac48Address::Allocate ());
334 nC->AddDevice (deviceC);
338 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.252");
341 ipv4.
SetBase (
"10.1.1.4",
"255.255.255.252");
348 int32_t ifIndexC = ipv4C->AddInterface (deviceC);
353 ipv4A->
SetUp (ifIndexA);
356 ipv4C->AddAddress (ifIndexC, ifInAddrC);
357 ipv4C->SetMetric (ifIndexC, 1);
358 ipv4C->SetUp (ifIndexC);
362 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
384 NS_TEST_ASSERT_MSG_EQ (sinkPtr->
GetTotalRx (), 6656,
"Static routing with /32 did not deliver all packets");
385 Simulator::Destroy ();
395 GlobalRoutingTestSuite::GlobalRoutingTestSuite ()
holds a vector of ns3::Application pointers.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
holds a vector of std::pair of Ptr<Ipv4> and interface index.
hold variables of type string
NetDeviceContainer Install(NodeContainer c)
a class to represent an Ipv4 address mask
virtual int ShutdownSend(void)=0
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetSize(void) const
NetDeviceContainer Install(Ptr< Node > node) const
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
a polymophic address class
virtual int Listen(void)=0
Listen for incoming connections.
Class for representing data rates.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
bool PeekPacketTag(Tag &tag) const
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void SetUp(uint32_t interface)=0
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
virtual void DoRun(void)
Implementation to actually run this test case.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Access to the Ipv4 forwarding table, interfaces, and configuration.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Install(std::string nodeName) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
uint32_t GetTotalRx() const
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
build a set of CsmaNetDevice objects
void SetChannelAttribute(std::string name, const AttributeValue &value)
Ipv4 addresses are stored in host order in this class.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
uint32_t AddDevice(Ptr< NetDevice > device)
a class to store IPv4 address information on an interface
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
virtual void SetAddress(Address address)
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
ApplicationContainer Install(NodeContainer c) const
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
Ptr< T > GetObject(void) const
ApplicationContainer Install(NodeContainer c) const
a unique identifier for an interface.
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const