A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
20
using 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
*/
33
class
GlobalRouteManagerImplTestCase
:
public
TestCase
34
{
35
public
:
36
GlobalRouteManagerImplTestCase
();
37
void
DoRun
()
override
;
38
};
39
40
GlobalRouteManagerImplTestCase::GlobalRouteManagerImplTestCase
()
41
:
TestCase
(
"GlobalRouteManagerImplTestCase"
)
42
{
43
}
44
45
void
46
GlobalRouteManagerImplTestCase::DoRun
()
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
80
auto
lr0 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::PointToPoint
,
81
"0.0.0.2"
,
// router ID 0.0.0.2
82
"10.1.1.1"
,
// local ID
83
1);
// metric
84
85
auto
lr1 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::StubNetwork
,
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
98
auto
lr2 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::PointToPoint
,
99
"0.0.0.2"
,
100
"10.1.2.1"
,
101
1);
102
103
auto
lr3 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::StubNetwork
,
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
116
auto
lr4 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::PointToPoint
,
117
"0.0.0.0"
,
118
"10.1.1.2"
,
119
1);
120
121
auto
lr5 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::StubNetwork
,
122
"10.1.1.2"
,
123
"255.255.255.252"
,
124
1);
125
126
auto
lr6 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::PointToPoint
,
127
"0.0.0.1"
,
128
"10.1.2.2"
,
129
1);
130
131
auto
lr7 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::StubNetwork
,
132
"10.1.2.2"
,
133
"255.255.255.252"
,
134
1);
135
136
auto
lr8 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::PointToPoint
,
137
"0.0.0.3"
,
138
"10.1.3.2"
,
139
1);
140
141
auto
lr9 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::StubNetwork
,
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
158
auto
lr10 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::PointToPoint
,
159
"0.0.0.2"
,
160
"10.1.2.1"
,
161
1);
162
163
auto
lr11 =
new
GlobalRoutingLinkRecord
(
GlobalRoutingLinkRecord::StubNetwork
,
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);
181
NS_TEST_ASSERT_MSG_EQ
(lsa2,
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
192
Simulator::Run
();
193
194
/// @todo here we should do some verification of the routes built
195
196
Simulator::Destroy
();
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
*/
212
class
GlobalRouteManagerImplTestSuite
:
public
TestSuite
213
{
214
public
:
215
GlobalRouteManagerImplTestSuite
();
216
217
private
:
218
};
219
220
GlobalRouteManagerImplTestSuite::GlobalRouteManagerImplTestSuite
()
221
:
TestSuite
(
"global-route-manager-impl"
,
Type
::UNIT)
222
{
223
AddTestCase
(
new
GlobalRouteManagerImplTestCase
(), TestCase::Duration::QUICK);
224
}
225
226
static
GlobalRouteManagerImplTestSuite
227
g_globalRoutingManagerImplTestSuite
;
//!< Static variable for test initialization
GlobalRouteManagerImplTestCase
Global Route Manager Test.
Definition
global-route-manager-impl-test-suite.cc:34
GlobalRouteManagerImplTestCase::GlobalRouteManagerImplTestCase
GlobalRouteManagerImplTestCase()
Definition
global-route-manager-impl-test-suite.cc:40
GlobalRouteManagerImplTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
global-route-manager-impl-test-suite.cc:46
GlobalRouteManagerImplTestSuite
Global Route Manager TestSuite.
Definition
global-route-manager-impl-test-suite.cc:213
GlobalRouteManagerImplTestSuite::GlobalRouteManagerImplTestSuite
GlobalRouteManagerImplTestSuite()
Definition
global-route-manager-impl-test-suite.cc:220
ns3::CandidateQueue
A Candidate Queue used in routing calculations.
Definition
candidate-queue.h:42
ns3::CandidateQueue::Pop
SPFVertex * Pop()
Pop the Shortest Path First Vertex pointer at the top of the queue.
Definition
candidate-queue.cc:99
ns3::CandidateQueue::Push
void Push(SPFVertex *vNew)
Push a Shortest Path First Vertex pointer onto the queue according to the priority scheme.
Definition
candidate-queue.cc:87
ns3::GlobalRouteManagerImpl
A global router implementation.
Definition
global-route-manager-impl.h:687
ns3::GlobalRouteManagerLSDB
The Link State DataBase (LSDB) of the Global Route Manager.
Definition
global-route-manager-impl.h:564
ns3::GlobalRoutingLSA
a Link State Advertisement (LSA) for a router, used in global routing.
Definition
global-router-interface.h:246
ns3::GlobalRoutingLSA::RouterLSA
@ RouterLSA
Definition
global-router-interface.h:255
ns3::GlobalRoutingLinkRecord
A single link record for a link state advertisement.
Definition
global-router-interface.h:43
ns3::GlobalRoutingLinkRecord::StubNetwork
@ StubNetwork
Record represents a leaf node network.
Definition
global-router-interface.h:59
ns3::GlobalRoutingLinkRecord::PointToPoint
@ PointToPoint
Record representing a point to point channel.
Definition
global-router-interface.h:57
ns3::SPFVertex
Vertex used in shortest path first (SPF) computations.
Definition
global-route-manager-impl.h:60
ns3::SPFVertex::SetDistanceFromRoot
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
Definition
global-route-manager-impl.cc:212
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
g_globalRoutingManagerImplTestSuite
static GlobalRouteManagerImplTestSuite g_globalRoutingManagerImplTestSuite
Static variable for test initialization.
Definition
global-route-manager-impl-test-suite.cc:227
NS_TEST_ASSERT_MSG_EQ
#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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
test
global-route-manager-impl-test-suite.cc
Generated on Fri Dec 13 2024 09:20:41 for ns-3 by
1.11.0