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 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Tom Henderson (tomhend@u.washington.edu)
19 *
20 * Kunihiro Ishigura, Toshiaki Takada (GNU Zebra) are attributed authors
21 * of the quagga 0.99.7/src/ospfd/ospf_spf.c code which was ported here
22 */
23
24#include "ns3/candidate-queue.h"
25#include "ns3/global-route-manager-impl.h"
26#include "ns3/simulator.h"
27#include "ns3/test.h"
28
29#include <cstdlib> // for rand()
30
31using namespace ns3;
32
33/**
34 * \ingroup internet
35 * \ingroup tests
36 * \defgroup internet-test internet module tests
37 */
38
39/**
40 * \ingroup internet-test
41 *
42 * \brief Global Route Manager Test
43 */
45{
46 public:
48 void DoRun() override;
49};
50
52 : TestCase("GlobalRouteManagerImplTestCase")
53{
54}
55
56void
58{
59 CandidateQueue candidate;
60
61 for (int i = 0; i < 100; ++i)
62 {
63 auto v = new SPFVertex;
64 v->SetDistanceFromRoot(std::rand() % 100);
65 candidate.Push(v);
66 }
67
68 for (int i = 0; i < 100; ++i)
69 {
70 SPFVertex* v = candidate.Pop();
71 delete v;
72 v = nullptr;
73 }
74
75 // Build fake link state database; four routers (0-3), 3 point-to-point
76 // links
77 //
78 // n0
79 // \ link 0
80 // \ link 2
81 // n2 -------------------------n3
82 // /
83 // / link 1
84 // n1
85 //
86 // link0: 10.1.1.1/30, 10.1.1.2/30
87 // link1: 10.1.2.1/30, 10.1.2.2/30
88 // link2: 10.1.3.1/30, 10.1.3.2/30
89 //
90 // Router 0
92 "0.0.0.2", // router ID 0.0.0.2
93 "10.1.1.1", // local ID
94 1); // metric
95
97 "10.1.1.1",
98 "255.255.255.252",
99 1);
100
101 auto lsa0 = new GlobalRoutingLSA();
102 lsa0->SetLSType(GlobalRoutingLSA::RouterLSA);
103 lsa0->SetLinkStateId("0.0.0.0");
104 lsa0->SetAdvertisingRouter("0.0.0.0");
105 lsa0->AddLinkRecord(lr0);
106 lsa0->AddLinkRecord(lr1);
107
108 // Router 1
110 "0.0.0.2",
111 "10.1.2.1",
112 1);
113
115 "10.1.2.1",
116 "255.255.255.252",
117 1);
118
119 auto lsa1 = new GlobalRoutingLSA();
120 lsa1->SetLSType(GlobalRoutingLSA::RouterLSA);
121 lsa1->SetLinkStateId("0.0.0.1");
122 lsa1->SetAdvertisingRouter("0.0.0.1");
123 lsa1->AddLinkRecord(lr2);
124 lsa1->AddLinkRecord(lr3);
125
126 // Router 2
128 "0.0.0.0",
129 "10.1.1.2",
130 1);
131
133 "10.1.1.2",
134 "255.255.255.252",
135 1);
136
138 "0.0.0.1",
139 "10.1.2.2",
140 1);
141
143 "10.1.2.2",
144 "255.255.255.252",
145 1);
146
148 "0.0.0.3",
149 "10.1.3.2",
150 1);
151
153 "10.1.3.2",
154 "255.255.255.252",
155 1);
156
157 auto lsa2 = new GlobalRoutingLSA();
158 lsa2->SetLSType(GlobalRoutingLSA::RouterLSA);
159 lsa2->SetLinkStateId("0.0.0.2");
160 lsa2->SetAdvertisingRouter("0.0.0.2");
161 lsa2->AddLinkRecord(lr4);
162 lsa2->AddLinkRecord(lr5);
163 lsa2->AddLinkRecord(lr6);
164 lsa2->AddLinkRecord(lr7);
165 lsa2->AddLinkRecord(lr8);
166 lsa2->AddLinkRecord(lr9);
167
168 // Router 3
170 "0.0.0.2",
171 "10.1.2.1",
172 1);
173
175 "10.1.2.1",
176 "255.255.255.252",
177 1);
178
179 auto lsa3 = new GlobalRoutingLSA();
180 lsa3->SetLSType(GlobalRoutingLSA::RouterLSA);
181 lsa3->SetLinkStateId("0.0.0.3");
182 lsa3->SetAdvertisingRouter("0.0.0.3");
183 lsa3->AddLinkRecord(lr10);
184 lsa3->AddLinkRecord(lr11);
185
186 // Test the database
187 auto srmlsdb = new GlobalRouteManagerLSDB();
188 srmlsdb->Insert(lsa0->GetLinkStateId(), lsa0);
189 srmlsdb->Insert(lsa1->GetLinkStateId(), lsa1);
190 srmlsdb->Insert(lsa2->GetLinkStateId(), lsa2);
191 srmlsdb->Insert(lsa3->GetLinkStateId(), lsa3);
193 srmlsdb->GetLSA(lsa2->GetLinkStateId()),
194 "The Ipv4Address is not stored as the link state ID");
195
196 // next, calculate routes based on the manually created LSDB
197 auto srm = new GlobalRouteManagerImpl();
198 srm->DebugUseLsdb(srmlsdb); // manually add in an LSDB
199 // Note-- this will succeed without any nodes in the topology
200 // because the NodeList is empty
201 srm->DebugSPFCalculate(lsa0->GetLinkStateId()); // node n0
202
204
205 /// \todo here we should do some verification of the routes built
206
208
209 // This delete clears the srm, which deletes the LSDB, which clears
210 // all of the LSAs, which each destroys the attached LinkRecords.
211 delete srm;
212
213 /// \todo Testing
214 // No testing has actually been done other than making sure that this code
215 // does not crash
216}
217
218/**
219 * \ingroup internet-test
220 *
221 * \brief Global Route Manager TestSuite
222 */
224{
225 public:
227
228 private:
229};
230
232 : TestSuite("global-route-manager-impl", Type::UNIT)
233{
234 AddTestCase(new GlobalRouteManagerImplTestCase(), TestCase::Duration::QUICK);
235}
236
238 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:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
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:145
Every class exported by the ns3 library is enclosed in the ns3 namespace.