A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
global-route-manager-impl-test-suite.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright 2007 University of Washington
4
* Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Authors: Tom Henderson (tomhend@u.washington.edu)
20
*
21
* Kunihiro Ishigura, Toshiaki Takada (GNU Zebra) are attributed authors
22
* of the quagga 0.99.7/src/ospfd/ospf_spf.c code which was ported here
23
*/
24
25
#include "ns3/test.h"
26
#include "ns3/global-route-manager-impl.h"
27
#include "ns3/candidate-queue.h"
28
#include "ns3/simulator.h"
29
#include <stdlib.h>
// for rand()
30
31
namespace
ns3 {
32
33
class
GlobalRouteManagerImplTestCase
:
public
TestCase
34
{
35
public
:
36
GlobalRouteManagerImplTestCase
();
37
virtual
void
DoRun
(
void
);
38
};
39
40
GlobalRouteManagerImplTestCase::GlobalRouteManagerImplTestCase
()
41
:
TestCase
(
"GlobalRouteManagerImplTestCase"
)
42
{
43
}
44
void
45
GlobalRouteManagerImplTestCase::DoRun
(
void
)
46
{
47
CandidateQueue
candidate;
48
49
for
(
int
i = 0; i < 100; ++i)
50
{
51
SPFVertex
*v =
new
SPFVertex
;
52
v->
SetDistanceFromRoot
(rand () % 100);
53
candidate.
Push
(v);
54
}
55
56
for
(
int
i = 0; i < 100; ++i)
57
{
58
SPFVertex
*v = candidate.
Pop
();
59
delete
v;
60
v = 0;
61
}
62
63
// Build fake link state database; four routers (0-3), 3 point-to-point
64
// links
65
//
66
// n0
67
// \ link 0
68
// \ link 2
69
// n2 -------------------------n3
70
// /
71
// / link 1
72
// n1
73
//
74
// link0: 10.1.1.1/30, 10.1.1.2/30
75
// link1: 10.1.2.1/30, 10.1.2.2/30
76
// link2: 10.1.3.1/30, 10.1.3.2/30
77
//
78
// Router 0
79
GlobalRoutingLinkRecord
* lr0 =
new
GlobalRoutingLinkRecord
(
80
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
GlobalRoutingLinkRecord
* lr1 =
new
GlobalRoutingLinkRecord
(
86
GlobalRoutingLinkRecord::StubNetwork
,
87
"10.1.1.1"
,
88
"255.255.255.252"
,
89
1);
90
91
GlobalRoutingLSA
* lsa0 =
new
GlobalRoutingLSA
();
92
lsa0->
SetLSType
(
GlobalRoutingLSA::RouterLSA
);
93
lsa0->
SetLinkStateId
(
"0.0.0.0"
);
94
lsa0->
SetAdvertisingRouter
(
"0.0.0.0"
);
95
lsa0->
AddLinkRecord
(lr0);
96
lsa0->
AddLinkRecord
(lr1);
97
98
// Router 1
99
GlobalRoutingLinkRecord
* lr2 =
new
GlobalRoutingLinkRecord
(
100
GlobalRoutingLinkRecord::PointToPoint
,
101
"0.0.0.2"
,
102
"10.1.2.1"
,
103
1);
104
105
GlobalRoutingLinkRecord
* lr3 =
new
GlobalRoutingLinkRecord
(
106
GlobalRoutingLinkRecord::StubNetwork
,
107
"10.1.2.1"
,
108
"255.255.255.252"
,
109
1);
110
111
GlobalRoutingLSA
* lsa1 =
new
GlobalRoutingLSA
();
112
lsa1->
SetLSType
(
GlobalRoutingLSA::RouterLSA
);
113
lsa1->
SetLinkStateId
(
"0.0.0.1"
);
114
lsa1->
SetAdvertisingRouter
(
"0.0.0.1"
);
115
lsa1->
AddLinkRecord
(lr2);
116
lsa1->
AddLinkRecord
(lr3);
117
118
// Router 2
119
GlobalRoutingLinkRecord
* lr4 =
new
GlobalRoutingLinkRecord
(
120
GlobalRoutingLinkRecord::PointToPoint
,
121
"0.0.0.0"
,
122
"10.1.1.2"
,
123
1);
124
125
GlobalRoutingLinkRecord
* lr5 =
new
GlobalRoutingLinkRecord
(
126
GlobalRoutingLinkRecord::StubNetwork
,
127
"10.1.1.2"
,
128
"255.255.255.252"
,
129
1);
130
131
GlobalRoutingLinkRecord
* lr6 =
new
GlobalRoutingLinkRecord
(
132
GlobalRoutingLinkRecord::PointToPoint
,
133
"0.0.0.1"
,
134
"10.1.2.2"
,
135
1);
136
137
GlobalRoutingLinkRecord
* lr7 =
new
GlobalRoutingLinkRecord
(
138
GlobalRoutingLinkRecord::StubNetwork
,
139
"10.1.2.2"
,
140
"255.255.255.252"
,
141
1);
142
143
GlobalRoutingLinkRecord
* lr8 =
new
GlobalRoutingLinkRecord
(
144
GlobalRoutingLinkRecord::PointToPoint
,
145
"0.0.0.3"
,
146
"10.1.3.2"
,
147
1);
148
149
GlobalRoutingLinkRecord
* lr9 =
new
GlobalRoutingLinkRecord
(
150
GlobalRoutingLinkRecord::StubNetwork
,
151
"10.1.3.2"
,
152
"255.255.255.252"
,
153
1);
154
155
GlobalRoutingLSA
* lsa2 =
new
GlobalRoutingLSA
();
156
lsa2->
SetLSType
(
GlobalRoutingLSA::RouterLSA
);
157
lsa2->
SetLinkStateId
(
"0.0.0.2"
);
158
lsa2->
SetAdvertisingRouter
(
"0.0.0.2"
);
159
lsa2->
AddLinkRecord
(lr4);
160
lsa2->
AddLinkRecord
(lr5);
161
lsa2->
AddLinkRecord
(lr6);
162
lsa2->
AddLinkRecord
(lr7);
163
lsa2->
AddLinkRecord
(lr8);
164
lsa2->
AddLinkRecord
(lr9);
165
166
// Router 3
167
GlobalRoutingLinkRecord
* lr10 =
new
GlobalRoutingLinkRecord
(
168
GlobalRoutingLinkRecord::PointToPoint
,
169
"0.0.0.2"
,
170
"10.1.2.1"
,
171
1);
172
173
GlobalRoutingLinkRecord
* lr11 =
new
GlobalRoutingLinkRecord
(
174
GlobalRoutingLinkRecord::StubNetwork
,
175
"10.1.2.1"
,
176
"255.255.255.252"
,
177
1);
178
179
GlobalRoutingLSA
* 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
GlobalRouteManagerLSDB
* 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);
192
NS_ASSERT
(lsa2 == srmlsdb->
GetLSA
(lsa2->
GetLinkStateId
()));
193
194
// next, calculate routes based on the manually created LSDB
195
GlobalRouteManagerImpl
* srm =
new
GlobalRouteManagerImpl
();
196
srm->
DebugUseLsdb
(srmlsdb);
// manually add in an LSDB
197
// Note-- this will succeed without any nodes in the topology
198
// because the NodeList is empty
199
srm->
DebugSPFCalculate
(lsa0->
GetLinkStateId
());
// node n0
200
201
Simulator::Run
();
202
203
// XXX here we should do some verification of the routes built
204
205
Simulator::Destroy
();
206
207
// This delete clears the srm, which deletes the LSDB, which clears
208
// all of the LSAs, which each destroys the attached LinkRecords.
209
delete
srm;
210
211
// XXX
212
// No testing has actually been done other than making sure that this code
213
// does not crash
214
}
215
216
217
static
class
GlobalRouteManagerImplTestSuite
:
public
TestSuite
218
{
219
public
:
220
GlobalRouteManagerImplTestSuite
()
221
:
TestSuite
(
"global-route-manager-impl"
,
UNIT
)
222
{
223
AddTestCase
(
new
GlobalRouteManagerImplTestCase
());
224
}
225
}
g_globalRoutingManagerImplTestSuite
;
226
227
}
// namespace ns3
src
internet
test
global-route-manager-impl-test-suite.cc
Generated on Tue Oct 9 2012 16:45:39 for ns-3 by
1.8.1.2