5#include "ns3/boolean.h"
6#include "ns3/bridge-helper.h"
8#include "ns3/global-route-manager.h"
9#include "ns3/inet-socket-address.h"
10#include "ns3/internet-stack-helper.h"
11#include "ns3/ipv4-address-helper.h"
12#include "ns3/ipv4-global-routing-helper.h"
13#include "ns3/ipv4-global-routing.h"
14#include "ns3/ipv4-interface.h"
15#include "ns3/ipv4-l3-protocol.h"
16#include "ns3/ipv4-packet-info-tag.h"
17#include "ns3/ipv4-routing-protocol.h"
18#include "ns3/ipv4-routing-table-entry.h"
19#include "ns3/ipv4-static-routing-helper.h"
21#include "ns3/node-container.h"
23#include "ns3/packet.h"
24#include "ns3/pointer.h"
25#include "ns3/simple-channel.h"
26#include "ns3/simple-net-device-helper.h"
27#include "ns3/simple-net-device.h"
28#include "ns3/simulator.h"
29#include "ns3/socket-factory.h"
30#include "ns3/string.h"
32#include "ns3/udp-socket-factory.h"
33#include "ns3/uinteger.h"
118 void DoRun()
override;
126 :
TestCase(
"Global routing on point-to-point link")
144 internet.SetRoutingHelper(ipv4RoutingHelper);
148 ipv4.SetBase(
"10.1.1.0",
"255.255.255.252");
169 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
178 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
181 route = globalRouting1->GetRoute(0);
202 void DoRun()
override;
210 :
TestCase(
"Global routing on broadcast link")
227 internet.SetRoutingHelper(ipv4RoutingHelper);
231 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
252 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
255 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
262 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
265 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
283 void DoRun()
override;
291 :
TestCase(
"Global routing across two hops (point-to-point links)")
316 internet.SetRoutingHelper(ipv4RoutingHelper);
320 ipv4.SetBase(
"10.1.1.0",
"255.255.255.252");
322 ipv4.SetBase(
"10.1.2.0",
"255.255.255.252");
349 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
360 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
362 route = globalRouting1->GetRoute(0);
366 route = globalRouting1->GetRoute(1);
370 route = globalRouting1->GetRoute(2);
374 route = globalRouting1->GetRoute(3);
381 uint32_t nRoutes2 = globalRouting2->GetNRoutes();
385 route = globalRouting2->GetRoute(0);
402 void DoRun()
override;
410 :
TestCase(
"Global routing across two hops (broadcast links)")
433 internet.SetRoutingHelper(ipv4RoutingHelper);
437 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
439 ipv4.SetBase(
"10.1.2.0",
"255.255.255.0");
465 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
472 route = globalRouting0->GetRoute(1);
478 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
481 route = globalRouting1->GetRoute(0);
485 route = globalRouting1->GetRoute(1);
502 void DoRun()
override;
510 :
TestCase(
"Global routing across bridging topology (bug 2102)")
533 bridgeFacingDevices.
Add(net2.
Get(0));
534 switchDevices.Add(net2.
Get(1));
541 bridgeFacingDevices.
Add(net3.
Get(1));
542 switchDevices.Add(net3.
Get(0));
552 bridge.
Install(switchNode, switchDevices);
558 internet.SetRoutingHelper(ipv4RoutingHelper);
567 address.SetBase(
"10.1.1.0",
"255.255.255.0");
570 address.SetBase(
"10.1.2.0",
"255.255.255.0");
571 address.Assign(bridgeFacingDevices);
573 address.SetBase(
"10.1.3.0",
"255.255.255.0");
574 address.Assign(net4);
607 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
610 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
612 route = globalRouting0->GetRoute(i);
620 "Error-- wrong destination");
623 "Error-- wrong gateway");
629 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
632 for (
uint32_t i = 0; i < globalRouting1->GetNRoutes(); i++)
634 route = globalRouting1->GetRoute(i);
642 "Error-- wrong destination");
645 "Error-- wrong gateway");
649 NS_LOG_DEBUG(
"BridgeTest skip print out of n2 and n3, go next to node n4");
654 uint32_t nRoutes4 = globalRouting4->GetNRoutes();
657 for (
uint32_t i = 0; i < globalRouting4->GetNRoutes(); i++)
659 route = globalRouting4->GetRoute(i);
667 "Error-- wrong destination");
670 "Error-- wrong gateway");
685 void DoRun()
override;
693 :
TestCase(
"Global routing across two bridges")
717 bridgeFacingDevices.
Add(net2.
Get(0));
718 switchn2Devices.
Add(net2.
Get(1));
725 switchn2Devices.
Add(net3.
Get(0));
726 switchn3Devices.
Add(net3.
Get(1));
733 switchn3Devices.
Add(net4.
Get(0));
734 bridgeFacingDevices.
Add(net4.
Get(1));
738 bridgen2Helper.
Install(switchn2Node, switchn2Devices);
742 bridgen3Helper.
Install(switchn3Node, switchn3Devices);
748 internet.SetRoutingHelper(ipv4RoutingHelper);
757 address.SetBase(
"10.1.1.0",
"255.255.255.0");
760 address.SetBase(
"10.1.2.0",
"255.255.255.0");
761 address.Assign(bridgeFacingDevices);
787 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
790 for (
uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
792 route = globalRouting0->GetRoute(i);
800 "Error-- wrong destination");
803 "Error-- wrong gateway");
806 NS_LOG_DEBUG(
"BridgeTest skip print out of n1-n3, go next to node n4");
811 uint32_t nRoutes4 = globalRouting4->GetNRoutes();
814 for (
uint32_t i = 0; i < globalRouting4->GetNRoutes(); i++)
816 route = globalRouting4->GetRoute(i);
824 "Error-- wrong destination");
827 "Error-- wrong gateway");
862 void DoRun()
override;
876 :
TestCase(
"Dynamic global routing example"),
891 iter->second =
false;
892 iter->first->Close();
893 iter->first =
nullptr;
903 while ((packet = socket->RecvFrom(from)))
905 if (packet->GetSize() == 0)
911 found = packet->PeekPacketTag(tag);
1001 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
1004 ipv4.SetBase(
"10.1.2.0",
"255.255.255.0");
1007 ipv4.SetBase(
"10.1.3.0",
"255.255.255.0");
1010 ipv4.SetBase(
"10.250.1.0",
"255.255.255.0");
1013 ipv4.SetBase(
"172.16.1.0",
"255.255.255.0");
1025 std::pair<Ptr<Socket>,
bool> sendSockA;
1027 sendSockA.first->Bind();
1029 sendSockA.second =
true;
1034 std::pair<Ptr<Socket>,
bool> sendSockB;
1036 sendSockB.first->Bind();
1038 sendSockB.second =
true;
1047 sink2->ShutdownSend();
1049 sink2->SetRecvPktInfo(
true);
1093 std::vector<uint8_t> firstInterfaceTest{0, 5, 0, 0, 5, 5, 0, 0, 5, 5, 0, 5, 0, 0, 5, 5};
1094 std::vector<uint8_t> secondInterfaceTest{0, 0, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 0, 0};
1096 for (
uint32_t index = 0; index < firstInterfaceTest.size(); index++)
1100 "Dynamic global routing did deliver the wrong number of packets "
1101 "to the first interface at time "
1105 for (
uint32_t index = 0; index < secondInterfaceTest.size(); index++)
1109 "Dynamic global routing did deliver the wrong number of packets "
1110 "to the second interface at time "
1149 void DoRun()
override;
1154 :
TestCase(
"Slash 32 global routing example")
1165 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
1169 "Received packet size is not equal to Rx buffer size");
1207 internet.Install(c);
1217 nA->AddDevice(deviceA);
1224 nC->AddDevice(deviceC);
1228 ipv4.SetBase(
"10.1.1.0",
"255.255.255.252");
1231 ipv4.SetBase(
"10.1.1.4",
"255.255.255.252");
1238 int32_t ifIndexA = ipv4A->AddInterface(deviceA);
1239 int32_t ifIndexC = ipv4C->AddInterface(deviceC);
1243 ipv4A->AddAddress(ifIndexA, ifInAddrA);
1244 ipv4A->SetMetric(ifIndexA, 1);
1245 ipv4A->SetUp(ifIndexA);
1249 ipv4C->AddAddress(ifIndexC, ifInAddrC);
1250 ipv4C->SetMetric(ifIndexC, 1);
1251 ipv4C->SetUp(ifIndexC);
1259 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
1266 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
1267 txSocket->SetAllowBroadcast(
true);
1275 "Static routing with /32 did not deliver all packets.");
1291 void DoRun()
override;
1298 :
TestCase(
"ECMP Route Calculation TestCase")
1335 stack.SetRoutingHelper(globalhelper);
1336 stack.Install(
nodes);
1368 address.SetBase(
"10.1.1.0",
"255.255.255.252");
1371 address.SetBase(
"10.1.2.0",
"255.255.255.252");
1374 address.SetBase(
"10.1.3.0",
"255.255.255.252");
1377 address.SetBase(
"10.1.4.0",
"255.255.255.224");
1380 address.SetBase(
"10.1.5.0",
"255.255.255.0");
1383 address.SetBase(
"10.1.6.0",
"255.255.255.0");
1414 void DoRun()
override;
1491 :
TestCase(
"Test API calls to GlobalRoutingProtocol")
1506 std::vector<Ipv4Address> path)
1515 "Error-- no Ipv4 routing protocol object at source node");
1519 "Error-- no Ipv4GlobalRouting object at source node");
1529 m_lastRoute = globalRouting->RouteOutput(packet, ipHeader, oif, errno_);
1531 for (
uint32_t i = 1; i < pathSize; i++)
1535 if (i != pathSize - 1)
1542 routing = ip->GetRoutingProtocol();
1547 "Error-- no Ipv4GlobalRouting object at node");
1630 bridgeFacingDevices.
Add(d78.
Get(0));
1631 switchDevices.Add(d78.
Get(1));
1632 bridgeFacingDevices.
Add(d89.
Get(1));
1633 switchDevices.Add(d89.
Get(0));
1637 bridge.
Install(switchNode, switchDevices);
1641 internet.SetRoutingHelper(glbrouting);
1655 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
1658 ipv4.SetBase(
"10.1.2.0",
"255.255.255.0");
1661 ipv4.SetBase(
"10.1.3.0",
"255.255.255.0");
1664 ipv4.SetBase(
"10.250.1.0",
"255.255.255.0");
1667 ipv4.SetBase(
"172.16.1.0",
"255.255.255.0");
1670 ipv4.SetBase(
"10.1.4.0",
"255.255.255.0");
1673 ipv4.SetBase(
"10.1.5.0",
"255.255.255.0");
1693 std::vector<Ipv4Address>
1697 pathToCheck1.emplace_back(
"10.1.1.1");
1698 pathToCheck1.emplace_back(
"10.1.1.2");
1699 pathToCheck1.emplace_back(
"10.1.2.1");
1700 pathToCheck1.emplace_back(
"172.16.1.2");
1702 std::vector<Ptr<Node>>
1704 pathNodes1.push_back(
nodes.
Get(0));
1705 pathNodes1.push_back(
nodes.
Get(2));
1706 pathNodes1.push_back(
nodes.
Get(1));
1707 pathNodes1.push_back(
nodes.
Get(6));
1712 std::vector<Ipv4Address> pathToCheck2;
1713 pathToCheck2.emplace_back(
"10.1.2.1");
1714 pathToCheck2.emplace_back(
"10.1.2.2");
1715 pathToCheck2.emplace_back(
"10.250.1.4");
1717 std::vector<Ptr<Node>> pathNodes2;
1718 pathNodes2.push_back(
nodes.
Get(1));
1719 pathNodes2.push_back(
nodes.
Get(2));
1720 pathNodes2.push_back(
nodes.
Get(5));
1725 std::vector<Ipv4Address> pathToCheck3;
1726 pathToCheck3.emplace_back(
"172.16.1.1");
1727 pathToCheck3.emplace_back(
"172.16.1.2");
1728 pathToCheck3.emplace_back(
"10.1.4.2");
1729 pathToCheck3.emplace_back(
"10.1.5.2");
1731 std::vector<Ptr<Node>> pathNodes3;
1732 pathNodes3.push_back(
nodes.
Get(1));
1733 pathNodes3.push_back(
nodes.
Get(6));
1734 pathNodes3.push_back(
nodes.
Get(7));
1735 pathNodes3.push_back(
nodes.
Get(9));
1740 std::vector<Ipv4Address> pathToCheck4;
1741 pathToCheck4.emplace_back(
"10.1.5.2");
1742 pathToCheck4.emplace_back(
"10.1.5.1");
1743 pathToCheck4.emplace_back(
"10.1.4.1");
1744 pathToCheck4.emplace_back(
"10.1.3.1");
1745 pathToCheck4.emplace_back(
"10.250.1.1");
1746 pathToCheck4.emplace_back(
"10.1.1.1");
1748 std::vector<Ptr<Node>> pathNodes4;
1749 pathNodes4.push_back(
nodes.
Get(9));
1750 pathNodes4.push_back(
nodes.
Get(7));
1751 pathNodes4.push_back(
nodes.
Get(6));
1752 pathNodes4.push_back(
nodes.
Get(5));
1753 pathNodes4.push_back(
nodes.
Get(2));
1754 pathNodes4.push_back(
nodes.
Get(0));
NodeContainer n1n2
Nodecontainer n1 + n2.
NodeContainer n0n2
Nodecontainer n0 + n2.
IPv4 GlobalRouting Bridge test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
This TestCase tests if ECMP Route Calculation works.
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
EcmpRouteCalculationTestCase()
NodeContainer nodes
Nodes used in the test.
TestCase to check calls to GlobalRoutingProtocol API.
Ipv4RoutingProtocol::UnicastForwardCallback m_ucb
Unicast forward callback.
void MyLocalDeliverCallback(Ptr< const Packet > packet, const Ipv4Header &header, uint32_t iif)
Callback function for RouteInput() API of GlobalRoutingProtocol.
void CheckPath(std::vector< Ptr< Node > > pathNodes, std::vector< Ipv4Address > path)
Checks the Path taken by packets by calling RouteInput() and RouteOutput() APIs of GlobalRoutingProto...
Ipv4RoutingProtocol::ErrorCallback m_ecb
Error callback.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void MyErrorCallback(Ptr< const Packet > packet, const Ipv4Header &header, Socket::SocketErrno errno_)
Callback function for RouteInput() API of GlobalRoutingProtocol.
NodeContainer nodes
Nodes used in the test.
GlobalRoutingProtocolTestCase()
~GlobalRoutingProtocolTestCase() override
Ipv4RoutingProtocol::MulticastForwardCallback m_mcb
Multicast forward callback.
Ptr< Ipv4Route > m_lastRoute
Route to be tested.
void DoRun() override
Implementation to actually run this TestCase.
void MyUnicastCallback(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Callback function for RouteInput() API of GlobalRoutingProtocol.
Ipv4RoutingProtocol::LocalDeliverCallback m_lcb
Local delivery callback.
IPv4 Dynamic GlobalRouting test.
void DoRun() override
Implementation to actually run this TestCase.
uint16_t m_packetSize
Packet size.
~Ipv4DynamicGlobalRoutingTestCase() override
std::vector< uint8_t > m_secondInterface
Packets received on the 2nd interface at a given time.
Ipv4DynamicGlobalRoutingTestCase()
void HandleRead(Ptr< Socket > socket)
Handle an incoming packet.
uint16_t m_count
Number of packets received.
DataRate m_dataRate
Data rate.
std::vector< std::pair< Ptr< Socket >, bool > > m_sendSocks
Sending sockets.
std::vector< uint8_t > m_firstInterface
Packets received on the 1st interface at a given time.
void ShutDownSock(uint8_t index)
Shutdown a socket.
void SendData(uint8_t index)
Send some data.
IPv4 Dynamic GlobalRouting /32 test.
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
void SendData(Ptr< Socket > socket, std::string to)
Send a packet.
~Ipv4GlobalRoutingSlash32TestCase() override
void DoRun() override
Implementation to actually run this TestCase.
Ipv4GlobalRoutingSlash32TestCase()
void DoSendData(Ptr< Socket > socket, std::string to)
Send a packet.
Ptr< Packet > m_receivedPacket
number of received packets
IPv4 GlobalRouting TestSuite.
Ipv4GlobalRoutingTestSuite()
IPv4 GlobalRouting LAN test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
IPv4 GlobalRouting Link test.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
IPv4 GlobalRouting Two bridges test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
IPv4 GlobalRouting Two LAN test.
NodeContainer m_nodes
Nodes used in the test.
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
IPv4 GlobalRouting Two Link test.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
a polymophic address class
AttributeValue implementation for Boolean.
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
Class for representing data rates.
uint64_t GetBitRate() const
Get the underlying bitrate.
static void ResetRouterId()
Reset the router ID counter to zero.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
Helper class that adds ns3::Ipv4GlobalRouting objects.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
Global routing protocol for IPv4 stacks.
Access to the IPv4 forwarding table, interfaces, and configuration.
virtual void SetUp(uint32_t interface)=0
virtual void SetDown(uint32_t interface)=0
a class to store IPv4 address information on an interface
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Implement the IPv4 layer.
a class to represent an Ipv4 address mask
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
uint32_t GetRecvIf() const
Get the tag's receiving interface.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
static Mac48Address Allocate()
Allocate a new Mac48Address.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Smart pointer class similar to boost::intrusive_ptr.
build a set of SimpleNetDevice objects
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
SocketErrno
Enumeration of the possible errors returned by a socket.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
API to create UDP socket instances.
void SetDefault(std::string name, const AttributeValue &value)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
static Ipv4GlobalRoutingTestSuite g_globalRoutingTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...