A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-route-manager-impl-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright 2007 University of Washington
3 * Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Tom Henderson (tomhend@u.washington.edu)
8 *
9 * Kunihiro Ishigura, Toshiaki Takada (GNU Zebra) are attributed authors
10 * of the quagga 0.99.7/src/ospfd/ospf_spf.c code which was ported here
11 */
12
13#include "ns3/candidate-queue.h"
14#include "ns3/global-route-manager-impl.h"
15#include "ns3/simulator.h"
16#include "ns3/test.h"
17
18#include <cstdlib> // for rand()
19
20using namespace ns3;
21
22/**
23 * \ingroup internet
24 * \ingroup tests
25 * \defgroup internet-test internet module tests
26 */
27
28/**
29 * \ingroup internet-test
30 *
31 * \brief Global Route Manager Test
32 */
34{
35 public:
37 void DoRun() override;
38};
39
41 : TestCase("GlobalRouteManagerImplTestCase")
42{
43}
44
45void
47{
48 CandidateQueue candidate;
49
50 for (int i = 0; i < 100; ++i)
51 {
52 auto v = new SPFVertex;
53 v->SetDistanceFromRoot(std::rand() % 100);
54 candidate.Push(v);
55 }
56
57 for (int i = 0; i < 100; ++i)
58 {
59 SPFVertex* v = candidate.Pop();
60 delete v;
61 v = nullptr;
62 }
63
64 // Build fake link state database; four routers (0-3), 3 point-to-point
65 // links
66 //
67 // n0
68 // \ link 0
69 // \ link 2
70 // n2 -------------------------n3
71 // /
72 // / link 1
73 // n1
74 //
75 // link0: 10.1.1.1/30, 10.1.1.2/30
76 // link1: 10.1.2.1/30, 10.1.2.2/30
77 // link2: 10.1.3.1/30, 10.1.3.2/30
78 //
79 // Router 0
81 "0.0.0.2", // router ID 0.0.0.2
82 "10.1.1.1", // local ID
83 1); // metric
84
86 "10.1.1.1",
87 "255.255.255.252",
88 1);
89
90 auto lsa0 = new GlobalRoutingLSA();
91 lsa0->SetLSType(GlobalRoutingLSA::RouterLSA);
92 lsa0->SetLinkStateId("0.0.0.0");
93 lsa0->SetAdvertisingRouter("0.0.0.0");
94 lsa0->AddLinkRecord(lr0);
95 lsa0->AddLinkRecord(lr1);
96
97 // Router 1
99 "0.0.0.2",
100 "10.1.2.1",
101 1);
102
104 "10.1.2.1",
105 "255.255.255.252",
106 1);
107
108 auto lsa1 = new GlobalRoutingLSA();
109 lsa1->SetLSType(GlobalRoutingLSA::RouterLSA);
110 lsa1->SetLinkStateId("0.0.0.1");
111 lsa1->SetAdvertisingRouter("0.0.0.1");
112 lsa1->AddLinkRecord(lr2);
113 lsa1->AddLinkRecord(lr3);
114
115 // Router 2
117 "0.0.0.0",
118 "10.1.1.2",
119 1);
120
122 "10.1.1.2",
123 "255.255.255.252",
124 1);
125
127 "0.0.0.1",
128 "10.1.2.2",
129 1);
130
132 "10.1.2.2",
133 "255.255.255.252",
134 1);
135
137 "0.0.0.3",
138 "10.1.3.2",
139 1);
140
142 "10.1.3.2",
143 "255.255.255.252",
144 1);
145
146 auto lsa2 = new GlobalRoutingLSA();
147 lsa2->SetLSType(GlobalRoutingLSA::RouterLSA);
148 lsa2->SetLinkStateId("0.0.0.2");
149 lsa2->SetAdvertisingRouter("0.0.0.2");
150 lsa2->AddLinkRecord(lr4);
151 lsa2->AddLinkRecord(lr5);
152 lsa2->AddLinkRecord(lr6);
153 lsa2->AddLinkRecord(lr7);
154 lsa2->AddLinkRecord(lr8);
155 lsa2->AddLinkRecord(lr9);
156
157 // Router 3
159 "0.0.0.2",
160 "10.1.2.1",
161 1);
162
164 "10.1.2.1",
165 "255.255.255.252",
166 1);
167
168 auto lsa3 = new GlobalRoutingLSA();
169 lsa3->SetLSType(GlobalRoutingLSA::RouterLSA);
170 lsa3->SetLinkStateId("0.0.0.3");
171 lsa3->SetAdvertisingRouter("0.0.0.3");
172 lsa3->AddLinkRecord(lr10);
173 lsa3->AddLinkRecord(lr11);
174
175 // Test the database
176 auto srmlsdb = new GlobalRouteManagerLSDB();
177 srmlsdb->Insert(lsa0->GetLinkStateId(), lsa0);
178 srmlsdb->Insert(lsa1->GetLinkStateId(), lsa1);
179 srmlsdb->Insert(lsa2->GetLinkStateId(), lsa2);
180 srmlsdb->Insert(lsa3->GetLinkStateId(), lsa3);
182 srmlsdb->GetLSA(lsa2->GetLinkStateId()),
183 "The Ipv4Address is not stored as the link state ID");
184
185 // next, calculate routes based on the manually created LSDB
186 auto srm = new GlobalRouteManagerImpl();
187 srm->DebugUseLsdb(srmlsdb); // manually add in an LSDB
188 // Note-- this will succeed without any nodes in the topology
189 // because the NodeList is empty
190 srm->DebugSPFCalculate(lsa0->GetLinkStateId()); // node n0
191
193
194 /// \todo here we should do some verification of the routes built
195
197
198 // This delete clears the srm, which deletes the LSDB, which clears
199 // all of the LSAs, which each destroys the attached LinkRecords.
200 delete srm;
201
202 /// \todo Testing
203 // No testing has actually been done other than making sure that this code
204 // does not crash
205}
206
207/**
208 * \ingroup internet-test
209 *
210 * \brief Global Route Manager TestSuite
211 */
213{
214 public:
216
217 private:
218};
219
221 : TestSuite("global-route-manager-impl", Type::UNIT)
222{
223 AddTestCase(new GlobalRouteManagerImplTestCase(), TestCase::Duration::QUICK);
224}
225
227 g_globalRoutingManagerImplTestSuite; //!< Static variable for test initialization
void DoRun() override
Implementation to actually run this TestCase.
A Candidate Queue used in routing calculations.
SPFVertex * Pop()
Pop the Shortest Path First Vertex pointer at the top of the queue.
void Push(SPFVertex *vNew)
Push a Shortest Path First Vertex pointer onto the queue according to the priority scheme.
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.
Vertex used in shortest path first (SPF) computations.
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static GlobalRouteManagerImplTestSuite g_globalRoutingManagerImplTestSuite
Static variable for test initialization.
#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.
Definition test.h:134
Every class exported by the ns3 library is enclosed in the ns3 namespace.