15#include "ns3/candidate-queue.h"
16#include "ns3/config.h"
17#include "ns3/global-route-manager-impl.h"
18#include "ns3/internet-module.h"
19#include "ns3/internet-stack-helper.h"
20#include "ns3/ipv4-global-routing-helper.h"
21#include "ns3/ipv4-global-routing.h"
22#include "ns3/network-module.h"
23#include "ns3/node-container.h"
24#include "ns3/rng-seed-manager.h"
25#include "ns3/simple-net-device-helper.h"
26#include "ns3/simulator.h"
72 void DoRun()
override;
89 std::vector<Ipv4Address>& dests,
90 std::vector<Ipv4Address>& gws);
93 std::vector<GlobalRoutingLSA*>
m_lsas;
103 std::vector<Ipv4Address>& dests,
104 std::vector<Ipv4Address>& gws)
107 for (
uint32_t i = 0; i < globalroutingprotocol->GetNRoutes(); i++)
141 stack.SetRoutingHelper(globalhelper);
142 stack.Install(
nodes);
158 address.SetBase(
"10.1.1.0",
"255.255.255.252");
160 address.SetBase(
"10.1.2.0",
"255.255.255.252");
162 address.SetBase(
"10.1.3.0",
"255.255.255.252");
185 lsa0->SetLinkStateId(
"0.0.0.0");
186 lsa0->SetAdvertisingRouter(
"0.0.0.0");
188 lsa0->AddLinkRecord(lr0);
189 lsa0->AddLinkRecord(lr1);
205 lsa1->SetLinkStateId(
"0.0.0.1");
206 lsa1->SetAdvertisingRouter(
"0.0.0.1");
207 lsa1->AddLinkRecord(lr2);
208 lsa1->AddLinkRecord(lr3);
245 lsa2->SetLinkStateId(
"0.0.0.2");
246 lsa2->SetAdvertisingRouter(
"0.0.0.2");
247 lsa2->AddLinkRecord(lr4);
248 lsa2->AddLinkRecord(lr5);
249 lsa2->AddLinkRecord(lr6);
250 lsa2->AddLinkRecord(lr7);
251 lsa2->AddLinkRecord(lr8);
252 lsa2->AddLinkRecord(lr9);
269 lsa3->SetLinkStateId(
"0.0.0.3");
270 lsa3->SetAdvertisingRouter(
"0.0.0.3");
271 lsa3->AddLinkRecord(lr10);
272 lsa3->AddLinkRecord(lr11);
292 srmlsdb->Insert(
m_lsas[0]->GetLinkStateId(),
m_lsas[0]);
293 srmlsdb->Insert(
m_lsas[1]->GetLinkStateId(),
m_lsas[1]);
294 srmlsdb->Insert(
m_lsas[2]->GetLinkStateId(),
m_lsas[2]);
295 srmlsdb->Insert(
m_lsas[3]->GetLinkStateId(),
m_lsas[3]);
299 srmlsdb->GetLSA(
m_lsas[2]->GetLinkStateId()),
300 "The Ipv4Address is not stored as the link state ID");
307 srm->DebugUseLsdb(srmlsdb);
309 srm->DebugSPFCalculate(
m_lsas[0]->GetLinkStateId());
311 srm->DebugSPFCalculate(
m_lsas[1]->GetLinkStateId());
313 srm->DebugSPFCalculate(
m_lsas[2]->GetLinkStateId());
315 srm->DebugSPFCalculate(
m_lsas[3]->GetLinkStateId());
329 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
333 route = globalRouting0->GetRoute(0);
337 "Error-- wrong destination for default route");
349 uint32_t nRoutes2 = globalRouting2->GetNRoutes();
354 std::vector<Ipv4Address> expecteddests;
355 std::vector<Ipv4Address> expectedgws;
356 expecteddests.emplace_back(
"10.1.1.1");
357 expecteddests.emplace_back(
"10.1.2.1");
358 expecteddests.emplace_back(
"10.1.3.2");
359 expecteddests.emplace_back(
"10.1.1.0");
360 expecteddests.emplace_back(
"10.1.2.0");
361 expecteddests.emplace_back(
"10.1.3.0");
363 expectedgws.emplace_back(
"10.1.1.1");
364 expectedgws.emplace_back(
"10.1.2.1");
365 expectedgws.emplace_back(
"10.1.3.2");
366 expectedgws.emplace_back(
"10.1.1.1");
367 expectedgws.emplace_back(
"10.1.2.1");
368 expectedgws.emplace_back(
"10.1.3.2");
370 CheckRoutes(globalRouting2, expecteddests, expectedgws);
396 void DoRun()
override;
432 stack.SetRoutingHelper(globalhelper);
433 stack.Install(
nodes);
442 address.SetBase(
"10.1.1.0",
"255.255.255.248");
460 lsa0->AddLinkRecord(lr0);
461 lsa0->SetLinkStateId(
"0.0.0.0");
462 lsa0->SetAdvertisingRouter(
"0.0.0.0");
473 lsa1->AddLinkRecord(lr1);
474 lsa1->SetLinkStateId(
"0.0.0.1");
475 lsa1->SetAdvertisingRouter(
"0.0.0.1");
486 lsa2->AddLinkRecord(lr2);
487 lsa2->SetLinkStateId(
"0.0.0.2");
488 lsa2->SetAdvertisingRouter(
"0.0.0.2");
495 lsa0network->SetLinkStateId(
"10.1.1.1");
496 lsa0network->SetAdvertisingRouter(
"0.0.0.0");
497 lsa0network->AddAttachedRouter(
"10.1.1.1");
498 lsa0network->AddAttachedRouter(
"10.1.1.2");
499 lsa0network->AddAttachedRouter(
"10.1.1.3");
500 lsa0network->SetNetworkLSANetworkMask(
"255.255.255.248");
501 m_lsas.push_back(lsa0network);
511 srmlsdb->Insert(
m_lsas[0]->GetLinkStateId(),
m_lsas[0]);
512 srmlsdb->Insert(
m_lsas[1]->GetLinkStateId(),
m_lsas[1]);
513 srmlsdb->Insert(
m_lsas[2]->GetLinkStateId(),
m_lsas[2]);
514 srmlsdb->Insert(
m_lsas[3]->GetLinkStateId(),
m_lsas[3]);
518 srm->DebugUseLsdb(srmlsdb);
520 srm->DebugSPFCalculate(
m_lsas[0]->GetLinkStateId());
532 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
537 "Error-- wrong destination for network route");
540 "Error-- wrong gateway for network route");
564 void DoRun()
override;
587 std::vector<Ipv4Address>& dests,
588 std::vector<Ipv4Address>& gws);
626 stack.SetRoutingHelper(globalhelper);
627 stack.Install(
nodes);
645 address.SetBase(
"10.1.1.0",
"255.255.255.252");
648 address.SetBase(
"10.1.2.0",
"255.255.255.252");
651 address.SetBase(
"10.1.3.0",
"255.255.255.252");
654 address.SetBase(
"10.1.4.0",
"255.255.255.252");
660 std::vector<Ipv4Address>& dests,
661 std::vector<Ipv4Address>& gws)
664 for (
uint32_t i = 0; i < globalroutingprotocol->GetNRoutes(); i++)
676 if (route->GetGateway() ==
Ipv4Address(
"10.1.1.2"))
680 else if (route->GetGateway() ==
Ipv4Address(
"10.1.2.2"))
715 lsa0->SetLinkStateId(
"0.0.0.0");
716 lsa0->SetAdvertisingRouter(
"0.0.0.0");
718 lsa0->AddLinkRecord(lr0);
719 lsa0->AddLinkRecord(lr1);
720 lsa0->AddLinkRecord(lr2);
721 lsa0->AddLinkRecord(lr3);
746 lsa1->SetLinkStateId(
"0.0.0.1");
747 lsa1->SetAdvertisingRouter(
"0.0.0.1");
749 lsa1->AddLinkRecord(lr4);
750 lsa1->AddLinkRecord(lr5);
751 lsa1->AddLinkRecord(lr6);
752 lsa1->AddLinkRecord(lr7);
776 lsa2->SetLinkStateId(
"0.0.0.2");
777 lsa2->SetAdvertisingRouter(
"0.0.0.2");
779 lsa2->AddLinkRecord(lr8);
780 lsa2->AddLinkRecord(lr9);
781 lsa2->AddLinkRecord(lr10);
782 lsa2->AddLinkRecord(lr11);
806 lsa3->SetLinkStateId(
"0.0.0.3");
807 lsa3->SetAdvertisingRouter(
"0.0.0.3");
809 lsa3->AddLinkRecord(lr12);
810 lsa3->AddLinkRecord(lr13);
811 lsa3->AddLinkRecord(lr14);
812 lsa3->AddLinkRecord(lr15);
830 srmlsdb->Insert(
m_lsas[0]->GetLinkStateId(),
m_lsas[0]);
831 srmlsdb->Insert(
m_lsas[1]->GetLinkStateId(),
m_lsas[1]);
832 srmlsdb->Insert(
m_lsas[2]->GetLinkStateId(),
m_lsas[2]);
833 srmlsdb->Insert(
m_lsas[3]->GetLinkStateId(),
m_lsas[3]);
837 srm->DebugUseLsdb(srmlsdb);
840 srm->DebugSPFCalculate(
m_lsas[0]->GetLinkStateId());
852 globalRouting0->AssignStreams(0);
854 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
858 std::vector<Ipv4Address> expectedDests;
859 std::vector<Ipv4Address> expectedNextHops;
866 expectedDests.emplace_back(
"10.1.1.2");
867 expectedDests.emplace_back(
"10.1.3.1");
868 expectedDests.emplace_back(
"10.1.2.2");
869 expectedDests.emplace_back(
"10.1.4.1");
870 expectedDests.emplace_back(
"10.1.3.2");
871 expectedDests.emplace_back(
"10.1.3.2");
872 expectedDests.emplace_back(
"10.1.4.2");
873 expectedDests.emplace_back(
"10.1.4.2");
874 expectedDests.emplace_back(
"10.1.1.0");
875 expectedDests.emplace_back(
"10.1.3.0");
876 expectedDests.emplace_back(
"10.1.3.0");
877 expectedDests.emplace_back(
"10.1.4.0");
878 expectedDests.emplace_back(
"10.1.4.0");
879 expectedDests.emplace_back(
"10.1.2.0");
881 expectedNextHops.emplace_back(
"10.1.1.2");
882 expectedNextHops.emplace_back(
"10.1.1.2");
883 expectedNextHops.emplace_back(
"10.1.2.2");
884 expectedNextHops.emplace_back(
"10.1.2.2");
885 expectedNextHops.emplace_back(
"10.1.1.2");
886 expectedNextHops.emplace_back(
"10.1.2.2");
887 expectedNextHops.emplace_back(
"10.1.1.2");
888 expectedNextHops.emplace_back(
"10.1.2.2");
889 expectedNextHops.emplace_back(
"10.1.1.2");
890 expectedNextHops.emplace_back(
"10.1.1.2");
891 expectedNextHops.emplace_back(
"10.1.2.2");
892 expectedNextHops.emplace_back(
"10.1.1.2");
893 expectedNextHops.emplace_back(
"10.1.2.2");
894 expectedNextHops.emplace_back(
"10.1.2.2");
897 CheckRoutes(globalRouting0, expectedDests, expectedNextHops);
913 Ptr<Ipv4Route> route = globalRouting0->RouteOutput(packet, ipHeader, oif, errno_);
922 "The routing path for node 0 to node 3 does not match the expected output, "
923 "Equal Cost MultiPath (ECMP) routes are not being used correctly");
927 "The routing path for node 0 to node 3 does not match the expected output, "
928 "Equal Cost MultiPath (ECMP) routes are not being used correctly");
Global Route Manager TestSuite.
GlobalRouteManagerImplTestSuite()
This test case is to check if NetworkRoutes are being built correctly, i.e if route computation works...
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer nodes
NodeContainer to hold the nodes in the topology.
void BuildLsa()
Builds the LSAs for the topology.
std::vector< GlobalRoutingLSA * > m_lsas
The LSAs for the topology.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
Global Route Manager Test.
NodeContainer nodes
NodeContainer to hold the nodes in the topology.
std::vector< GlobalRoutingLSA * > m_lsas
The LSAs for the topology.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
void BuildLsa()
Builds the LSAs for the topology.
void CheckRoutes(Ptr< Ipv4GlobalRouting > &globalroutingprotocol, std::vector< Ipv4Address > &dests, std::vector< Ipv4Address > &gws)
Checks the Routing Table Entries for the expected output.
The purpose of this test is to check if Equal Cost MultiPath (ECMP) Routes are being built and used c...
void DoSetup() override
Implementation to do any local setup required for this TestCase.
uint32_t route1
Counter to keep track of the number of times route1 is used.
std::vector< GlobalRoutingLSA * > m_lsas
The LSAs for the topology.
void CheckRoutes(Ptr< Ipv4GlobalRouting > &globalroutingprotocol, std::vector< Ipv4Address > &dests, std::vector< Ipv4Address > &gws)
function that checks the routing table entries for the expected output.
NodeContainer nodes
NodeContainer to hold the nodes in the topology.
void BuildLsa()
Builds the LSAs for the topology.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t route2
Counter to keep track of the number of times route2 is used.
void IncrementCount(Ptr< Ipv4Route > &route)
Helper function that checks the output of the routing path and increments the corresponding route cou...
AttributeValue implementation for Boolean.
static void ResetRouterId()
Reset the router ID counter to zero.
A global router implementation.
The Link State DataBase (LSDB) of the Global Route Manager.
a Link State Advertisement (LSA) for a router, used in global routing.
@ LSA_SPF_NOT_EXPLORED
New vertex not yet considered.
A single link record for a link state advertisement.
@ StubNetwork
Record represents a leaf node network.
@ PointToPoint
Record representing a point to point channel.
@ TransitNetwork
Unused – for future OSPF compatibility
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.
Helper class that adds ns3::Ipv4GlobalRouting objects.
Global routing protocol for IPv4 stacks.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Implement the IPv4 layer.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
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.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static uint64_t GetRun()
Get the current run number.
static uint32_t GetSeed()
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
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 void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
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.
static GlobalRouteManagerImplTestSuite g_globalRoutingManagerImplTestSuite
Static variable for test initialization.
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_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.