author | Tom Henderson <tomh@tomh.org> |
Wed, 25 Mar 2009 10:40:01 -0700 | |
changeset 4297 | d8501bae8be1 |
parent 3969 | 1db8fca96193 |
child 4372 | d99061f1167c |
permissions | -rw-r--r-- |
1111 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
1457
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1421
diff
changeset
|
3 |
* Copyright 2007 University of Washington |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1421
diff
changeset
|
4 |
* Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1421
diff
changeset
|
5 |
* |
1111 | 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 |
|
1457
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1421
diff
changeset
|
18 |
* |
1505 | 19 |
* Authors: Tom Henderson (tomhend@u.washington.edu) |
1457
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1421
diff
changeset
|
20 |
* |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1421
diff
changeset
|
21 |
* Kunihiro Ishigura, Toshiaki Takada (GNU Zebra) are attributed authors |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1421
diff
changeset
|
22 |
* of the quagga 0.99.7/src/ospfd/ospf_spf.c code which was ported here |
1111 | 23 |
*/ |
24 |
||
25 |
#include <utility> |
|
26 |
#include <vector> |
|
27 |
#include <queue> |
|
28 |
#include "ns3/assert.h" |
|
29 |
#include "ns3/fatal-error.h" |
|
1505 | 30 |
#include "ns3/log.h" |
1111 | 31 |
#include "ns3/node-list.h" |
32 |
#include "ns3/ipv4.h" |
|
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
33 |
#include "ns3/ipv4-global-routing.h" |
1111 | 34 |
#include "global-router-interface.h" |
35 |
#include "global-route-manager-impl.h" |
|
36 |
#include "candidate-queue.h" |
|
37 |
||
1505 | 38 |
NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager"); |
1111 | 39 |
|
40 |
namespace ns3 { |
|
41 |
||
42 |
// --------------------------------------------------------------------------- |
|
43 |
// |
|
44 |
// SPFVertex Implementation |
|
45 |
// |
|
46 |
// --------------------------------------------------------------------------- |
|
47 |
||
48 |
SPFVertex::SPFVertex () : |
|
49 |
m_vertexType (VertexUnknown), |
|
50 |
m_vertexId ("255.255.255.255"), |
|
51 |
m_lsa (0), |
|
52 |
m_distanceFromRoot (SPF_INFINITY), |
|
53 |
m_rootOif (SPF_INFINITY), |
|
54 |
m_nextHop ("0.0.0.0"), |
|
55 |
m_parent (0), |
|
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
56 |
m_children (), |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
57 |
m_vertexProcessed (false) |
1111 | 58 |
{ |
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
59 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 60 |
} |
61 |
||
1278 | 62 |
SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : |
1111 | 63 |
m_vertexId (lsa->GetLinkStateId ()), |
64 |
m_lsa (lsa), |
|
65 |
m_distanceFromRoot (SPF_INFINITY), |
|
66 |
m_rootOif (SPF_INFINITY), |
|
67 |
m_nextHop ("0.0.0.0"), |
|
68 |
m_parent (0), |
|
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
69 |
m_children (), |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
70 |
m_vertexProcessed (false) |
1111 | 71 |
{ |
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
72 |
NS_LOG_FUNCTION_NOARGS (); |
1278 | 73 |
if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) |
74 |
{ |
|
1505 | 75 |
NS_LOG_LOGIC ("Setting m_vertexType to VertexRouter"); |
1278 | 76 |
m_vertexType = SPFVertex::VertexRouter; |
77 |
} |
|
78 |
else if (lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA) |
|
79 |
{ |
|
1505 | 80 |
NS_LOG_LOGIC ("Setting m_vertexType to VertexNetwork"); |
1278 | 81 |
m_vertexType = SPFVertex::VertexNetwork; |
82 |
} |
|
1111 | 83 |
} |
84 |
||
85 |
SPFVertex::~SPFVertex () |
|
86 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
87 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 88 |
for ( ListOfSPFVertex_t::iterator i = m_children.begin (); |
89 |
i != m_children.end (); |
|
90 |
i++) |
|
91 |
{ |
|
92 |
SPFVertex *p = *i; |
|
93 |
delete p; |
|
94 |
p = 0; |
|
95 |
*i = 0; |
|
96 |
} |
|
97 |
m_children.clear (); |
|
98 |
} |
|
99 |
||
100 |
void |
|
101 |
SPFVertex::SetVertexType (SPFVertex::VertexType type) |
|
102 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
103 |
NS_LOG_FUNCTION (type); |
1111 | 104 |
m_vertexType = type; |
105 |
} |
|
106 |
||
107 |
SPFVertex::VertexType |
|
108 |
SPFVertex::GetVertexType (void) const |
|
109 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
110 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 111 |
return m_vertexType; |
112 |
} |
|
113 |
||
114 |
void |
|
115 |
SPFVertex::SetVertexId (Ipv4Address id) |
|
116 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
117 |
NS_LOG_FUNCTION (id); |
1111 | 118 |
m_vertexId = id; |
119 |
} |
|
120 |
||
121 |
Ipv4Address |
|
122 |
SPFVertex::GetVertexId (void) const |
|
123 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
124 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 125 |
return m_vertexId; |
126 |
} |
|
127 |
||
128 |
void |
|
1278 | 129 |
SPFVertex::SetLSA (GlobalRoutingLSA* lsa) |
1111 | 130 |
{ |
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
131 |
NS_LOG_FUNCTION (lsa); |
1111 | 132 |
m_lsa = lsa; |
133 |
} |
|
134 |
||
1278 | 135 |
GlobalRoutingLSA* |
1111 | 136 |
SPFVertex::GetLSA (void) const |
137 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
138 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 139 |
return m_lsa; |
140 |
} |
|
141 |
||
142 |
void |
|
143 |
SPFVertex::SetDistanceFromRoot (uint32_t distance) |
|
144 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
145 |
NS_LOG_FUNCTION (distance); |
1111 | 146 |
m_distanceFromRoot = distance; |
147 |
} |
|
148 |
||
149 |
uint32_t |
|
150 |
SPFVertex::GetDistanceFromRoot (void) const |
|
151 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
152 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 153 |
return m_distanceFromRoot; |
154 |
} |
|
155 |
||
156 |
void |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
157 |
SPFVertex::SetOutgoingInterfaceId (uint32_t id) |
1111 | 158 |
{ |
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
159 |
NS_LOG_FUNCTION (id); |
1111 | 160 |
m_rootOif = id; |
161 |
} |
|
162 |
||
163 |
uint32_t |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
164 |
SPFVertex::GetOutgoingInterfaceId (void) const |
1111 | 165 |
{ |
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
166 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 167 |
return m_rootOif; |
168 |
} |
|
169 |
||
170 |
void |
|
171 |
SPFVertex::SetNextHop (Ipv4Address nextHop) |
|
172 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
173 |
NS_LOG_FUNCTION (nextHop); |
1111 | 174 |
m_nextHop = nextHop; |
175 |
} |
|
176 |
||
177 |
Ipv4Address |
|
178 |
SPFVertex::GetNextHop (void) const |
|
179 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
180 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 181 |
return m_nextHop; |
182 |
} |
|
183 |
||
184 |
void |
|
185 |
SPFVertex::SetParent (SPFVertex* parent) |
|
186 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
187 |
NS_LOG_FUNCTION (parent); |
1111 | 188 |
m_parent = parent; |
189 |
} |
|
190 |
||
191 |
SPFVertex* |
|
192 |
SPFVertex::GetParent (void) const |
|
193 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
194 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 195 |
return m_parent; |
196 |
} |
|
197 |
||
198 |
uint32_t |
|
199 |
SPFVertex::GetNChildren (void) const |
|
200 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
201 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 202 |
return m_children.size (); |
203 |
} |
|
204 |
||
205 |
SPFVertex* |
|
206 |
SPFVertex::GetChild (uint32_t n) const |
|
207 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
208 |
NS_LOG_FUNCTION (n); |
1111 | 209 |
uint32_t j = 0; |
210 |
||
211 |
for ( ListOfSPFVertex_t::const_iterator i = m_children.begin (); |
|
212 |
i != m_children.end (); |
|
213 |
i++, j++) |
|
214 |
{ |
|
215 |
if (j == n) |
|
216 |
{ |
|
217 |
return *i; |
|
218 |
} |
|
219 |
} |
|
3947
756887a9bbea
disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents:
3946
diff
changeset
|
220 |
NS_ASSERT_MSG (false, "Index <n> out of range."); |
1111 | 221 |
return 0; |
222 |
} |
|
223 |
||
224 |
uint32_t |
|
225 |
SPFVertex::AddChild (SPFVertex* child) |
|
226 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
227 |
NS_LOG_FUNCTION (child); |
1111 | 228 |
m_children.push_back (child); |
229 |
return m_children.size (); |
|
230 |
} |
|
231 |
||
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
232 |
void |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
233 |
SPFVertex::SetVertexProcessed (bool value) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
234 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
235 |
m_vertexProcessed = value; |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
236 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
237 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
238 |
bool |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
239 |
SPFVertex::IsVertexProcessed (void) const |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
240 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
241 |
return m_vertexProcessed; |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
242 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
243 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
244 |
|
1111 | 245 |
// --------------------------------------------------------------------------- |
246 |
// |
|
247 |
// GlobalRouteManagerLSDB Implementation |
|
248 |
// |
|
249 |
// --------------------------------------------------------------------------- |
|
250 |
||
251 |
GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () |
|
252 |
: |
|
253 |
m_database () |
|
254 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
255 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 256 |
} |
257 |
||
258 |
GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB () |
|
259 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
260 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 261 |
LSDBMap_t::iterator i; |
262 |
for (i= m_database.begin (); i!= m_database.end (); i++) |
|
263 |
{ |
|
1505 | 264 |
NS_LOG_LOGIC ("free LSA"); |
1278 | 265 |
GlobalRoutingLSA* temp = i->second; |
1111 | 266 |
delete temp; |
267 |
} |
|
1505 | 268 |
NS_LOG_LOGIC ("clear map"); |
1111 | 269 |
m_database.clear (); |
270 |
} |
|
271 |
||
272 |
void |
|
273 |
GlobalRouteManagerLSDB::Initialize () |
|
274 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
275 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 276 |
LSDBMap_t::iterator i; |
277 |
for (i= m_database.begin (); i!= m_database.end (); i++) |
|
278 |
{ |
|
1278 | 279 |
GlobalRoutingLSA* temp = i->second; |
280 |
temp->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); |
|
1111 | 281 |
} |
282 |
} |
|
283 |
||
284 |
void |
|
1278 | 285 |
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa) |
1111 | 286 |
{ |
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
287 |
NS_LOG_FUNCTION (addr << lsa); |
1111 | 288 |
m_database.insert (LSDBPair_t (addr, lsa)); |
289 |
} |
|
290 |
||
1278 | 291 |
GlobalRoutingLSA* |
1111 | 292 |
GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const |
293 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
294 |
NS_LOG_FUNCTION (addr); |
1111 | 295 |
// |
296 |
// Look up an LSA by its address. |
|
297 |
// |
|
298 |
LSDBMap_t::const_iterator i; |
|
299 |
for (i= m_database.begin (); i!= m_database.end (); i++) |
|
300 |
{ |
|
301 |
if (i->first == addr) |
|
302 |
{ |
|
303 |
return i->second; |
|
304 |
} |
|
305 |
} |
|
306 |
return 0; |
|
307 |
} |
|
308 |
||
1278 | 309 |
GlobalRoutingLSA* |
310 |
GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const |
|
311 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
312 |
NS_LOG_FUNCTION (addr); |
1278 | 313 |
// |
314 |
// Look up an LSA by its address. |
|
315 |
// |
|
316 |
LSDBMap_t::const_iterator i; |
|
317 |
for (i= m_database.begin (); i!= m_database.end (); i++) |
|
318 |
{ |
|
319 |
GlobalRoutingLSA* temp = i->second; |
|
320 |
// Iterate among temp's Link Records |
|
321 |
for (uint32_t j = 0; j < temp->GetNLinkRecords (); j++) |
|
322 |
{ |
|
323 |
GlobalRoutingLinkRecord *lr = temp->GetLinkRecord (j); |
|
324 |
if ( lr->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork && |
|
325 |
lr->GetLinkData () == addr) |
|
326 |
{ |
|
327 |
return temp; |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
return 0; |
|
332 |
} |
|
333 |
||
1111 | 334 |
// --------------------------------------------------------------------------- |
335 |
// |
|
336 |
// GlobalRouteManagerImpl Implementation |
|
337 |
// |
|
338 |
// --------------------------------------------------------------------------- |
|
339 |
||
340 |
GlobalRouteManagerImpl::GlobalRouteManagerImpl () |
|
341 |
: |
|
342 |
m_spfroot (0) |
|
343 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
344 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 345 |
m_lsdb = new GlobalRouteManagerLSDB (); |
346 |
} |
|
347 |
||
348 |
GlobalRouteManagerImpl::~GlobalRouteManagerImpl () |
|
349 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
350 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 351 |
if (m_lsdb) |
352 |
{ |
|
353 |
delete m_lsdb; |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
void |
|
358 |
GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb) |
|
359 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
360 |
NS_LOG_FUNCTION (lsdb); |
1111 | 361 |
if (m_lsdb) |
362 |
{ |
|
363 |
delete m_lsdb; |
|
364 |
} |
|
365 |
m_lsdb = lsdb; |
|
366 |
} |
|
367 |
||
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
368 |
void |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
369 |
GlobalRouteManagerImpl::DeleteGlobalRoutes () |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
370 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
371 |
NS_LOG_FUNCTION_NOARGS (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
372 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
373 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
374 |
Ptr<Node> node = *i; |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
375 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
376 |
uint32_t j = 0; |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
377 |
uint32_t nRoutes = gr->GetNRoutes (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
378 |
NS_LOG_LOGIC ("Deleting " << gr->GetNRoutes ()<< " routes from node " << node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
379 |
// Each time we delete route 0, the route index shifts downward |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
380 |
// We can delete all routes if we delete the route numbered 0 |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
381 |
// nRoutes times |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
382 |
for (j = 0; j < nRoutes; j++) |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
383 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
384 |
NS_LOG_LOGIC ("Deleting global route " << j << " from node " << node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
385 |
gr->RemoveRoute (0); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
386 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
387 |
NS_LOG_LOGIC ("Deleted " << j << " global routes from node "<< node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
388 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
389 |
if (m_lsdb) |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
390 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
391 |
NS_LOG_LOGIC ("Deleting LSDB, creating new one"); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
392 |
delete m_lsdb; |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
393 |
m_lsdb = new GlobalRouteManagerLSDB (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
394 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
395 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
396 |
|
1111 | 397 |
// |
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
398 |
// In order to build the routing database, we need at least one of the nodes |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
399 |
// to participate as a router. This is a convenience function that makes |
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
400 |
// all nodes routers. We do this by walking the list of nodes in the system |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
401 |
// and aggregating a Global Router Interface to each of the nodes. |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
402 |
// |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
403 |
void |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
404 |
GlobalRouteManagerImpl::SelectRouterNodes () |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
405 |
{ |
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
406 |
NS_LOG_FUNCTION_NOARGS (); |
1301
440379945254
use the NodeList::Iterator type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1282
diff
changeset
|
407 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
408 |
{ |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
409 |
Ptr<Node> node = *i; |
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
410 |
NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ()); |
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
411 |
|
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1881
diff
changeset
|
412 |
Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); |
2258
666099a753e0
AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
413 |
node->AggregateObject (globalRouter); |
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
414 |
|
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
415 |
NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
416 |
Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
417 |
// This is the object that will keep the global routes. We insert it |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
418 |
// at slightly higher priority than static routing (which is at zero). |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
419 |
// This means that global routes (e.g. host routes) will be consulted |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
420 |
// before static routes |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
421 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
422 |
NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): " |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
423 |
"GetObject for <Ipv4> interface failed"); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
424 |
// XXX make the below priority value an attribute |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
425 |
ipv4->AddRoutingProtocol (globalRouting, 3); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
426 |
// Locally cache the globalRouting pointer; we'll need it later |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
427 |
// when we add routes |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
428 |
AddGlobalRoutingProtocol (node->GetId (), globalRouting); |
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
429 |
} |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
430 |
} |
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
431 |
|
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
432 |
void |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
433 |
GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c) |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
434 |
{ |
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
435 |
NS_LOG_FUNCTION (&c); |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
436 |
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
437 |
{ |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
438 |
Ptr<Node> node = *i; |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
439 |
NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
440 |
node->GetId ()); |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
441 |
|
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
442 |
Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
443 |
node->AggregateObject (globalRouter); |
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
444 |
|
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
445 |
NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
446 |
Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
447 |
// This is the object that will keep the global routes. We insert it |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
448 |
// at slightly higher priority than static routing (which is at zero). |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
449 |
// This means that global routes (e.g. host routes) will be consulted |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
450 |
// before static routes |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
451 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
452 |
NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): " |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
453 |
"GetObject for <Ipv4> interface failed"); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
454 |
// XXX make the below priority value an attribute |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
455 |
ipv4->AddRoutingProtocol (globalRouting, 3); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
456 |
// Locally cache the globalRouting pointer; we'll need it later |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
457 |
// when we add routes |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
458 |
AddGlobalRoutingProtocol (node->GetId (), globalRouting); |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
459 |
} |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
460 |
} |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3365
diff
changeset
|
461 |
|
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
462 |
// |
1111 | 463 |
// In order to build the routing database, we need to walk the list of nodes |
464 |
// in the system and look for those that support the GlobalRouter interface. |
|
465 |
// These routers will export a number of Link State Advertisements (LSAs) |
|
466 |
// that describe the links and networks that are "adjacent" (i.e., that are |
|
467 |
// on the other side of a point-to-point link). We take these LSAs and put |
|
468 |
// add them to the Link State DataBase (LSDB) from which the routes will |
|
469 |
// ultimately be computed. |
|
470 |
// |
|
471 |
void |
|
472 |
GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () |
|
473 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
474 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 475 |
// |
3939
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3937
diff
changeset
|
476 |
// Walk the list of nodes looking for the GlobalRouter Interface. Nodes with |
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3937
diff
changeset
|
477 |
// global router interfaces are, not too surprisingly, our routers. |
1111 | 478 |
// |
1301
440379945254
use the NodeList::Iterator type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1282
diff
changeset
|
479 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
1111 | 480 |
{ |
481 |
Ptr<Node> node = *i; |
|
482 |
||
3939
206f627bd5af
factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents:
3937
diff
changeset
|
483 |
Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> (); |
1111 | 484 |
// |
485 |
// Ignore nodes that aren't participating in routing. |
|
486 |
// |
|
487 |
if (!rtr) |
|
488 |
{ |
|
489 |
continue; |
|
490 |
} |
|
491 |
// |
|
492 |
// You must call DiscoverLSAs () before trying to use any routing info or to |
|
493 |
// update LSAs. DiscoverLSAs () drives the process of discovering routes in |
|
494 |
// the GlobalRouter. Afterward, you may use GetNumLSAs (), which is a very |
|
495 |
// computationally inexpensive call. If you call GetNumLSAs () before calling |
|
496 |
// DiscoverLSAs () will get zero as the number since no routes have been |
|
497 |
// found. |
|
498 |
// |
|
499 |
uint32_t numLSAs = rtr->DiscoverLSAs (); |
|
1505 | 500 |
NS_LOG_LOGIC ("Found " << numLSAs << " LSAs"); |
1111 | 501 |
|
502 |
for (uint32_t j = 0; j < numLSAs; ++j) |
|
503 |
{ |
|
1278 | 504 |
GlobalRoutingLSA* lsa = new GlobalRoutingLSA (); |
1111 | 505 |
// |
506 |
// This is the call to actually fetch a Link State Advertisement from the |
|
507 |
// router. |
|
508 |
// |
|
509 |
rtr->GetLSA (j, *lsa); |
|
1505 | 510 |
NS_LOG_LOGIC (*lsa); |
1111 | 511 |
// |
512 |
// Write the newly discovered link state advertisement to the database. |
|
513 |
// |
|
514 |
m_lsdb->Insert (lsa->GetLinkStateId (), lsa); |
|
515 |
} |
|
516 |
} |
|
517 |
} |
|
518 |
||
519 |
// |
|
520 |
// For each node that is a global router (which is determined by the presence |
|
521 |
// of an aggregated GlobalRouter interface), run the Dijkstra SPF calculation |
|
522 |
// on the database rooted at that router, and populate the node forwarding |
|
523 |
// tables. |
|
524 |
// |
|
525 |
// This function parallels RFC2328, Section 16.1.1, and quagga ospfd |
|
526 |
// |
|
527 |
// This calculation yields the set of intra-area routes associated |
|
528 |
// with an area (called hereafter Area A). A router calculates the |
|
529 |
// shortest-path tree using itself as the root. The formation |
|
530 |
// of the shortest path tree is done here in two stages. In the |
|
531 |
// first stage, only links between routers and transit networks are |
|
532 |
// considered. Using the Dijkstra algorithm, a tree is formed from |
|
533 |
// this subset of the link state database. In the second stage, |
|
534 |
// leaves are added to the tree by considering the links to stub |
|
535 |
// networks. |
|
536 |
// |
|
537 |
// The area's link state database is represented as a directed graph. |
|
538 |
// The graph's vertices are routers, transit networks and stub networks. |
|
539 |
// |
|
540 |
// The first stage of the procedure (i.e., the Dijkstra algorithm) |
|
541 |
// can now be summarized as follows. At each iteration of the |
|
542 |
// algorithm, there is a list of candidate vertices. Paths from |
|
543 |
// the root to these vertices have been found, but not necessarily |
|
544 |
// the shortest ones. However, the paths to the candidate vertex |
|
545 |
// that is closest to the root are guaranteed to be shortest; this |
|
546 |
// vertex is added to the shortest-path tree, removed from the |
|
547 |
// candidate list, and its adjacent vertices are examined for |
|
548 |
// possible addition to/modification of the candidate list. The |
|
549 |
// algorithm then iterates again. It terminates when the candidate |
|
550 |
// list becomes empty. |
|
551 |
// |
|
552 |
void |
|
553 |
GlobalRouteManagerImpl::InitializeRoutes () |
|
554 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
555 |
NS_LOG_FUNCTION_NOARGS (); |
1111 | 556 |
// |
557 |
// Walk the list of nodes in the system. |
|
558 |
// |
|
1301
440379945254
use the NodeList::Iterator type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1282
diff
changeset
|
559 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
1111 | 560 |
{ |
561 |
Ptr<Node> node = *i; |
|
562 |
// |
|
563 |
// Look for the GlobalRouter interface that indicates that the node is |
|
564 |
// participating in routing. |
|
565 |
// |
|
566 |
Ptr<GlobalRouter> rtr = |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
567 |
node->GetObject<GlobalRouter> (); |
1111 | 568 |
// |
569 |
// if the node has a global router interface, then run the global routing |
|
570 |
// algorithms. |
|
571 |
// |
|
572 |
if (rtr && rtr->GetNumLSAs () ) |
|
573 |
{ |
|
574 |
SPFCalculate (rtr->GetRouterId ()); |
|
575 |
} |
|
576 |
} |
|
577 |
} |
|
578 |
||
579 |
// |
|
580 |
// This method is derived from quagga ospf_spf_next (). See RFC2328 Section |
|
581 |
// 16.1 (2) for further details. |
|
582 |
// |
|
583 |
// We're passed a parameter <v> that is a vertex which is already in the SPF |
|
584 |
// tree. A vertex represents a router node. We also get a reference to the |
|
585 |
// SPF candidate queue, which is a priority queue containing the shortest paths |
|
586 |
// to the networks we know about. |
|
587 |
// |
|
588 |
// We examine the links in v's LSA and update the list of candidates with any |
|
589 |
// vertices not already on the list. If a lower-cost path is found to a |
|
590 |
// vertex already on the candidate list, store the new (lower) cost. |
|
591 |
// |
|
592 |
void |
|
593 |
GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate) |
|
594 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
595 |
NS_LOG_FUNCTION (v << &candidate); |
1505 | 596 |
|
1111 | 597 |
SPFVertex* w = 0; |
1278 | 598 |
GlobalRoutingLSA* w_lsa = 0; |
599 |
GlobalRoutingLinkRecord *l = 0; |
|
1111 | 600 |
uint32_t distance = 0; |
1278 | 601 |
uint32_t numRecordsInVertex = 0; |
1505 | 602 |
// |
1278 | 603 |
// V points to a Router-LSA or Network-LSA |
604 |
// Loop over the links in router LSA or attached routers in Network LSA |
|
1505 | 605 |
// |
1278 | 606 |
if (v->GetVertexType () == SPFVertex::VertexRouter) |
1111 | 607 |
{ |
1278 | 608 |
numRecordsInVertex = v->GetLSA ()->GetNLinkRecords (); |
609 |
} |
|
610 |
if (v->GetVertexType () == SPFVertex::VertexNetwork) |
|
611 |
{ |
|
612 |
numRecordsInVertex = v->GetLSA ()->GetNAttachedRouters (); |
|
613 |
} |
|
614 |
||
615 |
for (uint32_t i = 0; i < numRecordsInVertex; i++) |
|
616 |
{ |
|
617 |
// Get w_lsa: In case of V is Router-LSA |
|
618 |
if (v->GetVertexType () == SPFVertex::VertexRouter) |
|
1111 | 619 |
{ |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
620 |
NS_LOG_LOGIC ("Examining link " << i << " of " << |
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
621 |
v->GetVertexId () << "'s " << |
1111 | 622 |
v->GetLSA ()->GetNLinkRecords () << " link records"); |
623 |
// |
|
624 |
// (a) If this is a link to a stub network, examine the next link in V's LSA. |
|
625 |
// Links to stub networks will be considered in the second stage of the |
|
626 |
// shortest path calculation. |
|
627 |
// |
|
1278 | 628 |
l = v->GetLSA ()->GetLinkRecord (i); |
629 |
if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork) |
|
630 |
{ |
|
1505 | 631 |
NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ()); |
1278 | 632 |
continue; |
633 |
} |
|
1111 | 634 |
// |
635 |
// (b) Otherwise, W is a transit vertex (router or transit network). Look up |
|
636 |
// the vertex W's LSA (router-LSA or network-LSA) in Area A's link state |
|
637 |
// database. |
|
638 |
// |
|
1278 | 639 |
if (l->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint) |
640 |
{ |
|
1111 | 641 |
// |
642 |
// Lookup the link state advertisement of the new link -- we call it <w> in |
|
643 |
// the link state database. |
|
644 |
// |
|
1278 | 645 |
w_lsa = m_lsdb->GetLSA (l->GetLinkId ()); |
646 |
NS_ASSERT (w_lsa); |
|
1505 | 647 |
NS_LOG_LOGIC ("Found a P2P record from " << |
1278 | 648 |
v->GetVertexId () << " to " << w_lsa->GetLinkStateId ()); |
649 |
} |
|
650 |
else if (l->GetLinkType () == |
|
651 |
GlobalRoutingLinkRecord::TransitNetwork) |
|
652 |
{ |
|
653 |
w_lsa = m_lsdb->GetLSA (l->GetLinkId ()); |
|
654 |
NS_ASSERT (w_lsa); |
|
1505 | 655 |
NS_LOG_LOGIC ("Found a Transit record from " << |
1278 | 656 |
v->GetVertexId () << " to " << w_lsa->GetLinkStateId ()); |
657 |
} |
|
658 |
else |
|
659 |
{ |
|
660 |
NS_ASSERT_MSG (0, "illegal Link Type"); |
|
661 |
} |
|
662 |
} |
|
663 |
// Get w_lsa: In case of V is Network-LSA |
|
664 |
if (v->GetVertexType () == SPFVertex::VertexNetwork) |
|
665 |
{ |
|
666 |
w_lsa = m_lsdb->GetLSAByLinkData |
|
667 |
(v->GetLSA ()->GetAttachedRouter (i)); |
|
668 |
if (!w_lsa) |
|
669 |
{ |
|
670 |
continue; |
|
671 |
} |
|
1505 | 672 |
NS_LOG_LOGIC ("Found a Network LSA from " << |
1278 | 673 |
v->GetVertexId () << " to " << w_lsa->GetLinkStateId ()); |
674 |
} |
|
675 |
||
676 |
// Note: w_lsa at this point may be either RouterLSA or NetworkLSA |
|
1111 | 677 |
// |
678 |
// (c) If vertex W is already on the shortest-path tree, examine the next |
|
679 |
// link in the LSA. |
|
680 |
// |
|
681 |
// If the link is to a router that is already in the shortest path first tree |
|
682 |
// then we have it covered -- ignore it. |
|
683 |
// |
|
1278 | 684 |
if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_IN_SPFTREE) |
685 |
{ |
|
1505 | 686 |
NS_LOG_LOGIC ("Skipping -> LSA "<< |
1278 | 687 |
w_lsa->GetLinkStateId () << " already in SPF tree"); |
688 |
continue; |
|
689 |
} |
|
1111 | 690 |
// |
691 |
// (d) Calculate the link state cost D of the resulting path from the root to |
|
692 |
// vertex W. D is equal to the sum of the link state cost of the (already |
|
693 |
// calculated) shortest path to vertex V and the advertised cost of the link |
|
694 |
// between vertices V and W. |
|
695 |
// |
|
1278 | 696 |
if (v->GetLSA ()->GetLSType () == GlobalRoutingLSA::RouterLSA) |
697 |
{ |
|
698 |
distance = v->GetDistanceFromRoot () + l->GetMetric (); |
|
699 |
} |
|
700 |
else |
|
701 |
{ |
|
702 |
distance = v->GetDistanceFromRoot (); |
|
703 |
} |
|
1111 | 704 |
|
1505 | 705 |
NS_LOG_LOGIC ("Considering w_lsa " << w_lsa->GetLinkStateId ()); |
1278 | 706 |
|
707 |
// Is there already vertex w in candidate list? |
|
708 |
if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED) |
|
709 |
{ |
|
710 |
||
711 |
// prepare vertex w |
|
712 |
w = new SPFVertex (w_lsa); |
|
713 |
// Calculate nexthop to w |
|
1111 | 714 |
// We need to figure out how to actually get to the new router represented |
715 |
// by <w>. This will (among other things) find the next hop address to send |
|
716 |
// packets destined for this network to, and also find the outbound interface |
|
717 |
// used to forward the packets. |
|
718 |
// |
|
1278 | 719 |
if (SPFNexthopCalculation (v, w, l, distance)) |
720 |
{ |
|
721 |
w_lsa->SetStatus (GlobalRoutingLSA::LSA_SPF_CANDIDATE); |
|
1111 | 722 |
// |
723 |
// Push this new vertex onto the priority queue (ordered by distance from the |
|
724 |
// root node). |
|
725 |
// |
|
1278 | 726 |
candidate.Push (w); |
1505 | 727 |
NS_LOG_LOGIC ("Pushing " << |
1278 | 728 |
w->GetVertexId () << ", parent vertexId: " << |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
729 |
v->GetVertexId () << ", distance: " << |
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
730 |
w->GetDistanceFromRoot ()); |
1278 | 731 |
} |
732 |
} |
|
733 |
else if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_CANDIDATE) |
|
734 |
{ |
|
1111 | 735 |
// |
736 |
// We have already considered the link represented by <w>. What wse have to |
|
737 |
// do now is to decide if this new router represents a route with a shorter |
|
738 |
// distance metric. |
|
739 |
// |
|
740 |
// So, locate the vertex in the candidate queue and take a look at the |
|
741 |
// distance. |
|
1278 | 742 |
w = candidate.Find (w_lsa->GetLinkStateId ()); |
743 |
if (w->GetDistanceFromRoot () < distance) |
|
744 |
{ |
|
1111 | 745 |
// |
746 |
// This is not a shorter path, so don't do anything. |
|
747 |
// |
|
1278 | 748 |
continue; |
749 |
} |
|
750 |
else if (w->GetDistanceFromRoot () == distance) |
|
751 |
{ |
|
1111 | 752 |
// |
753 |
// This path is one with an equal cost. Do nothing for now -- we're not doing |
|
754 |
// equal-cost multipath cases yet. |
|
755 |
// |
|
1278 | 756 |
} |
757 |
else |
|
758 |
{ |
|
1111 | 759 |
// |
760 |
// this path represents a new, lower-cost path to <w> (the vertex we found in |
|
761 |
// the current link record of the link state advertisement of the current root |
|
762 |
// (vertex <v>) |
|
763 |
// |
|
764 |
// N.B. the nexthop_calculation is conditional, if it finds a valid nexthop |
|
765 |
// it will call spf_add_parents, which will flush the old parents |
|
766 |
// |
|
1278 | 767 |
if (SPFNexthopCalculation (v, w, l, distance)) |
768 |
{ |
|
1111 | 769 |
// |
770 |
// If we've changed the cost to get to the vertex represented by <w>, we |
|
771 |
// must reorder the priority queue keyed to that cost. |
|
772 |
// |
|
1278 | 773 |
candidate.Reorder (); |
774 |
} |
|
775 |
} // new lower cost path found |
|
776 |
} // end W is already on the candidate list |
|
777 |
} // end loop over the links in V's LSA |
|
1111 | 778 |
} |
779 |
||
780 |
// |
|
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
781 |
// This method is derived from quagga ospf_nexthop_calculation() 16.1.1. |
1111 | 782 |
// |
1278 | 783 |
// Calculate nexthop from root through V (parent) to vertex W (destination) |
784 |
// with given distance from root->W. |
|
785 |
// |
|
786 |
// As appropriate, set w's parent, distance, and nexthop information |
|
1111 | 787 |
// |
788 |
// For now, this is greatly simplified from the quagga code |
|
789 |
// |
|
790 |
int |
|
791 |
GlobalRouteManagerImpl::SPFNexthopCalculation ( |
|
792 |
SPFVertex* v, |
|
793 |
SPFVertex* w, |
|
1278 | 794 |
GlobalRoutingLinkRecord* l, |
1111 | 795 |
uint32_t distance) |
796 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
797 |
NS_LOG_FUNCTION (v << w << l << distance); |
1505 | 798 |
// |
1278 | 799 |
// If w is a NetworkVertex, l should be null |
800 |
/* |
|
801 |
if (w->GetVertexType () == SPFVertex::VertexNetwork && l) |
|
802 |
{ |
|
3947
756887a9bbea
disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents:
3946
diff
changeset
|
803 |
NS_ASSERT_MSG (0, "Error: SPFNexthopCalculation parameter problem"); |
1278 | 804 |
} |
805 |
*/ |
|
806 |
||
1111 | 807 |
// |
808 |
// The vertex m_spfroot is a distinguished vertex representing the node at |
|
809 |
// the root of the calculations. That is, it is the node for which we are |
|
810 |
// calculating the routes. |
|
811 |
// |
|
812 |
// There are two distinct cases for calculating the next hop information. |
|
813 |
// First, if we're considering a hop from the root to an "adjacent" network |
|
814 |
// (one that is on the other side of a point-to-point link connected to the |
|
815 |
// root), then we need to store the information needed to forward down that |
|
816 |
// link. The second case is if the network is not directly adjacent. In that |
|
817 |
// case we need to use the forwarding information from the vertex on the path |
|
818 |
// to the destination that is directly adjacent [node 1] in both cases of the |
|
819 |
// diagram below. |
|
820 |
// |
|
821 |
// (1) [root] -> [point-to-point] -> [node 1] |
|
822 |
// (2) [root] -> [point-to-point] -> [node 1] -> [point-to-point] -> [node 2] |
|
823 |
// |
|
824 |
// We call the propagation of next hop information down vertices of a path |
|
825 |
// "inheriting" the next hop information. |
|
826 |
// |
|
827 |
// The point-to-point link information is only useful in this calculation when |
|
828 |
// we are examining the root node. |
|
829 |
// |
|
830 |
if (v == m_spfroot) |
|
831 |
{ |
|
832 |
// |
|
833 |
// In this case <v> is the root node, which means it is the starting point |
|
834 |
// for the packets forwarded by that node. This also means that the next hop |
|
835 |
// address of packets headed for some arbitrary off-network destination must |
|
836 |
// be the destination at the other end of one of the links off of the root |
|
837 |
// node if this root node is a router. We then need to see if this node <w> |
|
838 |
// is a router. |
|
839 |
// |
|
840 |
if (w->GetVertexType () == SPFVertex::VertexRouter) |
|
841 |
{ |
|
842 |
// |
|
843 |
// In the case of point-to-point links, the link data field (m_linkData) of a |
|
844 |
// Global Router Link Record contains the local IP address. If we look at the |
|
845 |
// link record describing the link from the perspecive of <w> (the remote |
|
846 |
// node from the viewpoint of <v>) back to the root node, we can discover the |
|
847 |
// IP address of the router to which <v> is adjacent. This is a distinguished |
|
848 |
// address -- the next hop address to get from <v> to <w> and all networks |
|
849 |
// accessed through that path. |
|
850 |
// |
|
851 |
// SPFGetNextLink () is a little odd. used in this way it is just going to |
|
852 |
// return the link record describing the link from <w> to <v>. Think of it as |
|
853 |
// SPFGetLink. |
|
854 |
// |
|
3947
756887a9bbea
disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents:
3946
diff
changeset
|
855 |
NS_ASSERT (l); |
1278 | 856 |
GlobalRoutingLinkRecord *linkRemote = 0; |
1111 | 857 |
linkRemote = SPFGetNextLink (w, v, linkRemote); |
858 |
// |
|
859 |
// At this point, <l> is the Global Router Link Record describing the point- |
|
860 |
// to point link from <v> to <w> from the perspective of <v>; and <linkRemote> |
|
861 |
// is the Global Router Link Record describing that same link from the |
|
862 |
// perspective of <w> (back to <v>). Now we can just copy the next hop |
|
863 |
// address from the m_linkData member variable. |
|
864 |
// |
|
865 |
// The next hop member variable we put in <w> has the sense "in order to get |
|
866 |
// from the root node to the host represented by vertex <w>, you have to send |
|
867 |
// the packet to the next hop address specified in w->m_nextHop. |
|
868 |
// |
|
3947
756887a9bbea
disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents:
3946
diff
changeset
|
869 |
w->SetNextHop (linkRemote->GetLinkData ()); |
1111 | 870 |
// |
871 |
// Now find the outgoing interface corresponding to the point to point link |
|
872 |
// from the perspective of <v> -- remember that <l> is the link "from" |
|
873 |
// <v> "to" <w>. |
|
874 |
// |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
875 |
w->SetOutgoingInterfaceId ( |
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
876 |
FindOutgoingInterfaceId (l->GetLinkData ())); |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
877 |
w->SetDistanceFromRoot (distance); |
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
878 |
w->SetParent (v); |
1505 | 879 |
NS_LOG_LOGIC ("Next hop from " << |
1111 | 880 |
v->GetVertexId () << " to " << w->GetVertexId () << |
881 |
" goes through next hop " << w->GetNextHop () << |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
882 |
" via outgoing interface " << w->GetOutgoingInterfaceId () << |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
883 |
" with distance " << distance); |
1278 | 884 |
} // end W is a router vertes |
885 |
else |
|
886 |
{ |
|
887 |
NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork); |
|
888 |
// W is a directly connected network; no next hop is required |
|
889 |
GlobalRoutingLSA* w_lsa = w->GetLSA (); |
|
890 |
NS_ASSERT (w_lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA); |
|
891 |
// Find outgoing interface ID for this network |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
892 |
w->SetOutgoingInterfaceId ( |
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
893 |
FindOutgoingInterfaceId (w_lsa->GetLinkStateId (), |
1278 | 894 |
w_lsa->GetNetworkLSANetworkMask () )); |
895 |
w->SetDistanceFromRoot (distance); |
|
896 |
w->SetParent (v); |
|
1505 | 897 |
NS_LOG_LOGIC ("Next hop from " << |
1278 | 898 |
v->GetVertexId () << " to network " << w->GetVertexId () << |
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
899 |
" via outgoing interface " << w->GetOutgoingInterfaceId () << |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
900 |
" with distance " << distance); |
1278 | 901 |
return 1; |
902 |
} |
|
903 |
} // end v is the root |
|
904 |
else if (v->GetVertexType () == SPFVertex::VertexNetwork) |
|
905 |
{ |
|
906 |
// See if any of v's parents are the root |
|
907 |
if (v->GetParent () == m_spfroot) |
|
908 |
{ |
|
909 |
// 16.1.1 para 5. ...the parent vertex is a network that |
|
910 |
// directly connects the calculating router to the destination |
|
911 |
// router. The list of next hops is then determined by |
|
912 |
// examining the destination's router-LSA... |
|
913 |
NS_ASSERT (w->GetVertexType () == SPFVertex::VertexRouter); |
|
914 |
GlobalRoutingLinkRecord *linkRemote = 0; |
|
915 |
while ((linkRemote = SPFGetNextLink (w, v, linkRemote))) |
|
916 |
{ |
|
917 |
/* ...For each link in the router-LSA that points back to the |
|
918 |
* parent network, the link's Link Data field provides the IP |
|
919 |
* address of a next hop router. The outgoing interface to |
|
920 |
* use can then be derived from the next hop IP address (or |
|
921 |
* it can be inherited from the parent network). |
|
922 |
*/ |
|
3947
756887a9bbea
disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents:
3946
diff
changeset
|
923 |
w->SetNextHop (linkRemote->GetLinkData ()); |
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
924 |
w->SetOutgoingInterfaceId (v->GetOutgoingInterfaceId ()); |
1505 | 925 |
NS_LOG_LOGIC ("Next hop from " << |
1278 | 926 |
v->GetVertexId () << " to " << w->GetVertexId () << |
927 |
" goes through next hop " << w->GetNextHop () << |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
928 |
" via outgoing interface " << w->GetOutgoingInterfaceId ()); |
1278 | 929 |
} |
930 |
} |
|
931 |
else |
|
932 |
{ |
|
933 |
w->SetNextHop (v->GetNextHop ()); |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
934 |
w->SetOutgoingInterfaceId (v->GetOutgoingInterfaceId ()); |
1111 | 935 |
} |
936 |
} |
|
937 |
else |
|
938 |
{ |
|
939 |
// |
|
940 |
// If we're calculating the next hop information from a node (v) that is |
|
941 |
// *not* the root, then we need to "inherit" the information needed to |
|
942 |
// forward the packet from the vertex closer to the root. That is, we'll |
|
943 |
// still send packets to the next hop address of the router adjacent to the |
|
944 |
// root on the path toward <w>. |
|
945 |
// |
|
946 |
// Above, when we were considering the root node, we calculated the next hop |
|
947 |
// address and outgoing interface required to get off of the root network. |
|
948 |
// At this point, we are further away from the root network along one of the |
|
949 |
// (shortest) paths. So the next hop and outoing interface remain the same |
|
950 |
// (are inherited). |
|
951 |
// |
|
952 |
w->SetNextHop (v->GetNextHop ()); |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
953 |
w->SetOutgoingInterfaceId (v->GetOutgoingInterfaceId ()); |
1111 | 954 |
} |
955 |
// |
|
956 |
// In all cases, we need valid values for the distance metric and a parent. |
|
957 |
// |
|
958 |
w->SetDistanceFromRoot (distance); |
|
959 |
w->SetParent (v); |
|
960 |
||
961 |
return 1; |
|
962 |
} |
|
963 |
||
964 |
// |
|
965 |
// This method is derived from quagga ospf_get_next_link () |
|
966 |
// |
|
967 |
// First search the Global Router Link Records of vertex <v> for one |
|
968 |
// representing a point-to point link to vertex <w>. |
|
969 |
// |
|
970 |
// What is done depends on prev_link. Contrary to appearances, prev_link just |
|
971 |
// acts as a flag here. If prev_link is NULL, we return the first Global |
|
972 |
// Router Link Record we find that describes a point-to-point link from <v> |
|
973 |
// to <w>. If prev_link is not NULL, we return a Global Router Link Record |
|
974 |
// representing a possible *second* link from <v> to <w>. |
|
975 |
// |
|
1278 | 976 |
GlobalRoutingLinkRecord* |
1111 | 977 |
GlobalRouteManagerImpl::SPFGetNextLink ( |
978 |
SPFVertex* v, |
|
979 |
SPFVertex* w, |
|
1278 | 980 |
GlobalRoutingLinkRecord* prev_link) |
1111 | 981 |
{ |
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
982 |
NS_LOG_FUNCTION (v << w << prev_link); |
1111 | 983 |
|
984 |
bool skip = true; |
|
1278 | 985 |
bool found_prev_link = false; |
986 |
GlobalRoutingLinkRecord* l; |
|
1111 | 987 |
// |
988 |
// If prev_link is 0, we are really looking for the first link, not the next |
|
989 |
// link. |
|
990 |
// |
|
991 |
if (prev_link == 0) |
|
992 |
{ |
|
993 |
skip = false; |
|
1278 | 994 |
found_prev_link = true; |
1111 | 995 |
} |
996 |
// |
|
997 |
// Iterate through the Global Router Link Records advertised by the vertex |
|
998 |
// <v> looking for records representing the point-to-point links off of this |
|
999 |
// vertex. |
|
1000 |
// |
|
1001 |
for (uint32_t i = 0; i < v->GetLSA ()->GetNLinkRecords (); ++i) |
|
1002 |
{ |
|
1003 |
l = v->GetLSA ()->GetLinkRecord (i); |
|
1004 |
// |
|
1005 |
// The link ID of a link record representing a point-to-point link is set to |
|
1006 |
// the router ID of the neighboring router -- the router to which the link |
|
1007 |
// connects from the perspective of <v> in this case. The vertex ID is also |
|
1008 |
// set to the router ID (using the link state advertisement of a router node). |
|
1009 |
// We're just checking to see if the link <l> is actually the link from <v> to |
|
1010 |
// <w>. |
|
1011 |
// |
|
1278 | 1012 |
if (l->GetLinkId () == w->GetVertexId ()) |
1013 |
{ |
|
1014 |
if (!found_prev_link) |
|
1015 |
{ |
|
1505 | 1016 |
NS_LOG_LOGIC ("Skipping links before prev_link found"); |
1278 | 1017 |
found_prev_link = true; |
1018 |
continue; |
|
1019 |
} |
|
1020 |
||
1505 | 1021 |
NS_LOG_LOGIC ("Found matching link l: linkId = " << |
1111 | 1022 |
l->GetLinkId () << " linkData = " << l->GetLinkData ()); |
1023 |
// |
|
1024 |
// If skip is false, don't (not too surprisingly) skip the link found -- it's |
|
1025 |
// the one we're interested in. That's either because we didn't pass in a |
|
1026 |
// previous link, and we're interested in the first one, or because we've |
|
1027 |
// skipped a previous link and moved forward to the next (which is then the |
|
1028 |
// one we want). |
|
1029 |
// |
|
1030 |
if (skip == false) |
|
1031 |
{ |
|
1505 | 1032 |
NS_LOG_LOGIC ("Returning the found link"); |
1111 | 1033 |
return l; |
1034 |
} |
|
1035 |
else |
|
1036 |
{ |
|
1037 |
// |
|
1038 |
// Skip is true and we've found a link from <v> to <w>. We want the next one. |
|
1039 |
// Setting skip to false gets us the next point-to-point global router link |
|
1040 |
// record in the LSA from <v>. |
|
1041 |
// |
|
1505 | 1042 |
NS_LOG_LOGIC ("Skipping the found link"); |
1111 | 1043 |
skip = false; |
1044 |
continue; |
|
1045 |
} |
|
1046 |
} |
|
1047 |
} |
|
1048 |
return 0; |
|
1049 |
} |
|
1050 |
||
1051 |
// |
|
1052 |
// Used for unit tests. |
|
1053 |
// |
|
1054 |
void |
|
1055 |
GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root) |
|
1056 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
1057 |
NS_LOG_FUNCTION (root); |
1111 | 1058 |
SPFCalculate (root); |
1059 |
} |
|
1060 |
||
1061 |
// quagga ospf_spf_calculate |
|
1062 |
void |
|
1063 |
GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) |
|
1064 |
{ |
|
2983
e3a416fe9dd5
NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2258
diff
changeset
|
1065 |
NS_LOG_FUNCTION (this << root); |
1111 | 1066 |
|
1067 |
SPFVertex *v; |
|
1068 |
// |
|
1069 |
// Initialize the Link State Database. |
|
1070 |
// |
|
1071 |
m_lsdb->Initialize (); |
|
1072 |
// |
|
1073 |
// The candidate queue is a priority queue of SPFVertex objects, with the top |
|
1074 |
// of the queue being the closest vertex in terms of distance from the root |
|
1075 |
// of the tree. Initially, this queue is empty. |
|
1076 |
// |
|
1077 |
CandidateQueue candidate; |
|
3947
756887a9bbea
disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents:
3946
diff
changeset
|
1078 |
NS_ASSERT (candidate.Size () == 0); |
1111 | 1079 |
// |
1080 |
// Initialize the shortest-path tree to only contain the router doing the |
|
1081 |
// calculation. Each router (and corresponding network) is a vertex in the |
|
1082 |
// shortest path first (SPF) tree. |
|
1083 |
// |
|
1084 |
v = new SPFVertex (m_lsdb->GetLSA (root)); |
|
1085 |
// |
|
1086 |
// This vertex is the root of the SPF tree and it is distance 0 from the root. |
|
1087 |
// We also mark this vertex as being in the SPF tree. |
|
1088 |
// |
|
1089 |
m_spfroot= v; |
|
1090 |
v->SetDistanceFromRoot (0); |
|
1278 | 1091 |
v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE); |
1776
0d5be0c3d229
Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents:
1505
diff
changeset
|
1092 |
NS_LOG_LOGIC ("Starting SPFCalculate for node " << root); |
1111 | 1093 |
|
1094 |
for (;;) |
|
1095 |
{ |
|
1096 |
// |
|
1097 |
// The operations we need to do are given in the OSPF RFC which we reference |
|
1098 |
// as we go along. |
|
1099 |
// |
|
1100 |
// RFC2328 16.1. (2). |
|
1101 |
// |
|
1102 |
// We examine the Global Router Link Records in the Link State |
|
1103 |
// Advertisements of the current vertex. If there are any point-to-point |
|
1104 |
// links to unexplored adjacent vertices we add them to the tree and update |
|
1105 |
// the distance and next hop information on how to get there. We also add |
|
1106 |
// the new vertices to the candidate queue (the priority queue ordered by |
|
1107 |
// shortest path). If the new vertices represent shorter paths, we use them |
|
1108 |
// and update the path cost. |
|
1109 |
// |
|
1110 |
SPFNext (v, candidate); |
|
1111 |
// |
|
1112 |
// RFC2328 16.1. (3). |
|
1113 |
// |
|
1114 |
// If at this step the candidate list is empty, the shortest-path tree (of |
|
1115 |
// transit vertices) has been completely built and this stage of the |
|
1116 |
// procedure terminates. |
|
1117 |
// |
|
1118 |
if (candidate.Size () == 0) |
|
1119 |
{ |
|
1120 |
break; |
|
1121 |
} |
|
1122 |
// |
|
1123 |
// Choose the vertex belonging to the candidate list that is closest to the |
|
1124 |
// root, and add it to the shortest-path tree (removing it from the candidate |
|
1125 |
// list in the process). |
|
1126 |
// |
|
1127 |
// Recall that in the previous step, we created SPFVertex structures for each |
|
1128 |
// of the routers found in the Global Router Link Records and added tehm to |
|
1129 |
// the candidate list. |
|
1130 |
// |
|
1131 |
v = candidate.Pop (); |
|
1505 | 1132 |
NS_LOG_LOGIC ("Popped vertex " << v->GetVertexId ()); |
1111 | 1133 |
// |
1134 |
// Update the status field of the vertex to indicate that it is in the SPF |
|
1135 |
// tree. |
|
1136 |
// |
|
1278 | 1137 |
v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE); |
1111 | 1138 |
// |
1139 |
// The current vertex has a parent pointer. By calling this rather oddly |
|
1140 |
// named method (blame quagga) we add the current vertex to the list of |
|
1141 |
// children of that parent vertex. In the next hop calculation called during |
|
1142 |
// SPFNext, the parent pointer was set but the vertex has been orphaned up |
|
1143 |
// to now. |
|
1144 |
// |
|
1145 |
SPFVertexAddParent (v); |
|
1146 |
// |
|
1147 |
// Note that when there is a choice of vertices closest to the root, network |
|
1148 |
// vertices must be chosen before router vertices in order to necessarily |
|
1149 |
// find all equal-cost paths. We don't do this at this moment, we should add |
|
1150 |
// the treatment above codes. -- kunihiro. |
|
1151 |
// |
|
1152 |
// RFC2328 16.1. (4). |
|
1153 |
// |
|
1154 |
// This is the method that actually adds the routes. It'll walk the list |
|
1155 |
// of nodes in the system, looking for the node corresponding to the router |
|
1156 |
// ID of the root of the tree -- that is the router we're building the routes |
|
1157 |
// for. It looks for the Ipv4 interface of that node and remembers it. So |
|
1158 |
// we are only actually adding routes to that one node at the root of the SPF |
|
1159 |
// tree. |
|
1160 |
// |
|
1161 |
// We're going to pop of a pointer to every vertex in the tree except the |
|
1162 |
// root in order of distance from the root. For each of the vertices, we call |
|
1163 |
// SPFIntraAddRouter (). Down in SPFIntraAddRouter, we look at all of the |
|
1164 |
// point-to-point Global Router Link Records (the links to nodes adjacent to |
|
1165 |
// the node represented by the vertex). We add a route to the IP address |
|
1166 |
// specified by the m_linkData field of each of those link records. This will |
|
1167 |
// be the *local* IP address associated with the interface attached to the |
|
1168 |
// link. We use the outbound interface and next hop information present in |
|
1169 |
// the vertex <v> which have possibly been inherited from the root. |
|
1170 |
// |
|
1171 |
// To summarize, we're going to look at the node represented by <v> and loop |
|
1172 |
// through its point-to-point links, adding a *host* route to the local IP |
|
1173 |
// address (at the <v> side) for each of those links. |
|
1174 |
// |
|
1278 | 1175 |
if (v->GetVertexType () == SPFVertex::VertexRouter) |
1176 |
{ |
|
1177 |
SPFIntraAddRouter (v); |
|
1178 |
} |
|
1179 |
else if (v->GetVertexType () == SPFVertex::VertexNetwork) |
|
1180 |
{ |
|
1181 |
SPFIntraAddTransit (v); |
|
1182 |
} |
|
1183 |
else |
|
1184 |
{ |
|
3947
756887a9bbea
disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents:
3946
diff
changeset
|
1185 |
NS_ASSERT_MSG (0, "illegal SPFVertex type"); |
1278 | 1186 |
} |
1111 | 1187 |
// |
1188 |
// RFC2328 16.1. (5). |
|
1189 |
// |
|
1190 |
// Iterate the algorithm by returning to Step 2 until there are no more |
|
1191 |
// candidate vertices. |
|
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1192 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1193 |
} // end for loop |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1194 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1195 |
// Second stage of SPF calculation procedure |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1196 |
SPFProcessStubs (m_spfroot); |
1111 | 1197 |
// |
1198 |
// We're all done setting the routing information for the node at the root of |
|
1199 |
// the SPF tree. Delete all of the vertices and corresponding resources. Go |
|
1200 |
// possibly do it again for the next router. |
|
1201 |
// |
|
1202 |
delete m_spfroot; |
|
1203 |
m_spfroot = 0; |
|
1204 |
} |
|
1205 |
||
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1206 |
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs () |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1207 |
// stub link records will exist for point-to-point interfaces and for |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1208 |
// broadcast interfaces for which no neighboring router can be found |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1209 |
void |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1210 |
GlobalRouteManagerImpl::SPFProcessStubs (SPFVertex* v) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1211 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1212 |
NS_LOG_FUNCTION_NOARGS (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1213 |
NS_LOG_LOGIC ("Processing stubs for " << v->GetVertexId ()); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1214 |
if (v->GetVertexType () == SPFVertex::VertexRouter) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1215 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1216 |
GlobalRoutingLSA *rlsa = v->GetLSA (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1217 |
NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ()); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1218 |
for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1219 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1220 |
NS_LOG_LOGIC ("Examining link " << i << " of " << |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1221 |
v->GetVertexId () << "'s " << |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1222 |
v->GetLSA ()->GetNLinkRecords () << " link records"); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1223 |
GlobalRoutingLinkRecord *l = v->GetLSA ()->GetLinkRecord (i); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1224 |
if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1225 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1226 |
NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ()); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1227 |
SPFIntraAddStub (l, v); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1228 |
continue; |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1229 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1230 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1231 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1232 |
for (uint32_t i = 0; i < v->GetNChildren (); i++) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1233 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1234 |
if (!v->GetChild (i)->IsVertexProcessed ()) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1235 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1236 |
SPFProcessStubs (v->GetChild (i)); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1237 |
v->GetChild (i)->SetVertexProcessed (true); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1238 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1239 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1240 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1241 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1242 |
// RFC2328 16.1. second stage. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1243 |
void |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1244 |
GlobalRouteManagerImpl::SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1245 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1246 |
NS_LOG_FUNCTION_NOARGS (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1247 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1248 |
NS_ASSERT_MSG (m_spfroot, |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1249 |
"GlobalRouteManagerImpl::SPFIntraAddStub (): Root pointer not set"); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1250 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1251 |
// XXX simplifed logic for the moment. There are two cases to consider: |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1252 |
// 1) the stub network is on this router; do nothing for now |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1253 |
// (already handled above) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1254 |
// 2) the stub network is on a remote router, so I should use the |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1255 |
// same next hop that I use to get to vertex v |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1256 |
if (v->GetVertexId () == m_spfroot->GetVertexId ()) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1257 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1258 |
NS_LOG_LOGIC ("Stub is on local host: " << v->GetVertexId () << "; returning"); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1259 |
return; |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1260 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1261 |
NS_LOG_LOGIC ("Stub is on remote host: " << v->GetVertexId () << "; installing"); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1262 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1263 |
// The root of the Shortest Path First tree is the router to which we are |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1264 |
// going to write the actual routing table entries. The vertex corresponding |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1265 |
// to this router has a vertex ID which is the router ID of that node. We're |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1266 |
// going to use this ID to discover which node it is that we're actually going |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1267 |
// to update. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1268 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1269 |
Ipv4Address routerId = m_spfroot->GetVertexId (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1270 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1271 |
NS_LOG_LOGIC ("Vertex ID = " << routerId); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1272 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1273 |
// We need to walk the list of nodes looking for the one that has the router |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1274 |
// ID corresponding to the root vertex. This is the one we're going to write |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1275 |
// the routing information to. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1276 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1277 |
NodeList::Iterator i = NodeList::Begin (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1278 |
for (; i != NodeList::End (); i++) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1279 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1280 |
Ptr<Node> node = *i; |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1281 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1282 |
// The router ID is accessible through the GlobalRouter interface, so we need |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1283 |
// to QI for that interface. If there's no GlobalRouter interface, the node |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1284 |
// in question cannot be the router we want, so we continue. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1285 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1286 |
Ptr<GlobalRouter> rtr = |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1287 |
node->GetObject<GlobalRouter> (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1288 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1289 |
if (rtr == 0) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1290 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1291 |
NS_LOG_LOGIC ("No GlobalRouter interface on node " << |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1292 |
node->GetId ()); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1293 |
continue; |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1294 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1295 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1296 |
// If the router ID of the current node is equal to the router ID of the |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1297 |
// root of the SPF tree, then this node is the one for which we need to |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1298 |
// write the routing tables. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1299 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1300 |
NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1301 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1302 |
if (rtr->GetRouterId () == routerId) |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1303 |
{ |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1304 |
NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1305 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1306 |
// Routing information is updated using the Ipv4 interface. We need to QI |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1307 |
// for that interface. If the node is acting as an IP version 4 router, it |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1308 |
// should absolutely have an Ipv4 interface. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1309 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1310 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1311 |
NS_ASSERT_MSG (ipv4, |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1312 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1313 |
"QI for <Ipv4> interface failed"); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1314 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1315 |
// Get the Global Router Link State Advertisement from the vertex we're |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1316 |
// adding the routes to. The LSA will have a number of attached Global Router |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1317 |
// Link Records corresponding to links off of that vertex / node. We're going |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1318 |
// to be interested in the records corresponding to point-to-point links. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1319 |
// |
3969 | 1320 |
NS_ASSERT_MSG (v->GetLSA (), |
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1321 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1322 |
"Expected valid LSA in SPFVertex* v"); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1323 |
Ipv4Mask tempmask ("255.255.255.0"); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1324 |
Ipv4Address tempip = l->GetLinkId (); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1325 |
tempip = tempip.CombineMask (tempmask); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1326 |
|
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1327 |
NS_LOG_LOGIC (" Node " << node->GetId () << |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1328 |
" add route to " << tempip << |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1329 |
" with mask " << tempmask << |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1330 |
" using next hop " << v->GetNextHop () << |
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1331 |
" via interface " << v->GetOutgoingInterfaceId ()); |
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1332 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1333 |
// Here's why we did all of that work. We're going to add a host route to the |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1334 |
// host address found in the m_linkData field of the point-to-point link |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1335 |
// record. In the case of a point-to-point link, this is the local IP address |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1336 |
// of the node connected to the link. Each of these point-to-point links |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1337 |
// will correspond to a local interface that has an IP address to which |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1338 |
// the node at the root of the SPF tree can send packets. The vertex <v> |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1339 |
// (corresponding to the node that has these links and interfaces) has |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1340 |
// an m_nextHop address precalculated for us that is the address to which the |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1341 |
// root node should send packets to be forwarded to these IP addresses. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1342 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1343 |
// which the packets should be send for forwarding. |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1344 |
// |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1345 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1346 |
NS_ASSERT (gr); |
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1347 |
gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingInterfaceId ()); |
3960
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1348 |
return; |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1349 |
} // if |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1350 |
} // for |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1351 |
} |
34908804c029
Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents:
3959
diff
changeset
|
1352 |
|
1111 | 1353 |
// |
1354 |
// Return the interface index corresponding to a given IP address |
|
1316
f357c6a2bb37
Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents:
1302
diff
changeset
|
1355 |
// This is a wrapper around GetIfIndexByIpv4Address(), but we first |
f357c6a2bb37
Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents:
1302
diff
changeset
|
1356 |
// have to find the right node pointer to pass to that function. |
1278 | 1357 |
// |
1358 |
uint32_t |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1359 |
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) |
1278 | 1360 |
{ |
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
1361 |
NS_LOG_FUNCTION (a << amask); |
1278 | 1362 |
// |
1363 |
// We have an IP address <a> and a vertex ID of the root of the SPF tree. |
|
1364 |
// The question is what interface index does this address correspond to. |
|
1365 |
// The answer is a little complicated since we have to find a pointer to |
|
1366 |
// the node corresponding to the vertex ID, find the Ipv4 interface on that |
|
1367 |
// node in order to iterate the interfaces and find the one corresponding to |
|
1368 |
// the address in question. |
|
1369 |
// |
|
1370 |
Ipv4Address routerId = m_spfroot->GetVertexId (); |
|
1371 |
// |
|
1372 |
// Walk the list of nodes in the system looking for the one corresponding to |
|
1373 |
// the node at the root of the SPF tree. This is the node for which we are |
|
1374 |
// building the routing table. |
|
1375 |
// |
|
1302
7dd6ea991e80
use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1301
diff
changeset
|
1376 |
NodeList::Iterator i = NodeList::Begin (); |
1278 | 1377 |
for (; i != NodeList::End (); i++) |
1378 |
{ |
|
1379 |
Ptr<Node> node = *i; |
|
1380 |
||
1381 |
Ptr<GlobalRouter> rtr = |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
1382 |
node->GetObject<GlobalRouter> (); |
1278 | 1383 |
// |
1384 |
// If the node doesn't have a GlobalRouter interface it can't be the one |
|
1385 |
// we're interested in. |
|
1386 |
// |
|
1387 |
if (rtr == 0) |
|
1388 |
{ |
|
1389 |
continue; |
|
1390 |
} |
|
1391 |
||
1392 |
if (rtr->GetRouterId () == routerId) |
|
1393 |
{ |
|
1394 |
// |
|
1395 |
// This is the node we're building the routing table for. We're going to need |
|
1396 |
// the Ipv4 interface to look for the ipv4 interface index. Since this node |
|
1397 |
// is participating in routing IP version 4 packets, it certainly must have |
|
1398 |
// an Ipv4 interface. |
|
1399 |
// |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
1400 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1278 | 1401 |
NS_ASSERT_MSG (ipv4, |
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1402 |
"GlobalRouteManagerImpl::FindOutgoingInterfaceId (): " |
1278 | 1403 |
"QI for <Ipv4> interface failed"); |
1404 |
// |
|
1405 |
// Look through the interfaces on this node for one that has the IP address |
|
1406 |
// we're looking for. If we find one, return the corresponding interface |
|
1407 |
// index. |
|
1408 |
// |
|
1824
fd6f6604caad
move ipv4 static to member functions
Tom Henderson <tomh@tomh.org>
parents:
1776
diff
changeset
|
1409 |
return (ipv4->GetIfIndexByAddress (a, amask) ); |
1278 | 1410 |
} |
1411 |
} |
|
1412 |
// |
|
1413 |
// Couldn't find it. |
|
1414 |
// |
|
1415 |
return 0; |
|
1416 |
} |
|
1417 |
||
1418 |
// |
|
1111 | 1419 |
// This method is derived from quagga ospf_intra_add_router () |
1420 |
// |
|
1421 |
// This is where we are actually going to add the host routes to the routing |
|
1422 |
// tables of the individual nodes. |
|
1423 |
// |
|
1424 |
// The vertex passed as a parameter has just been added to the SPF tree. |
|
1425 |
// This vertex must have a valid m_root_oid, corresponding to the outgoing |
|
1426 |
// interface on the root router of the tree that is the first hop on the path |
|
1427 |
// to the vertex. The vertex must also have a next hop address, corresponding |
|
1428 |
// to the next hop on the path to the vertex. The vertex has an m_lsa field |
|
1429 |
// that has some number of link records. For each point to point link record, |
|
1430 |
// the m_linkData is the local IP address of the link. This corresponds to |
|
1431 |
// a destination IP address, reachable from the root, to which we add a host |
|
1432 |
// route. |
|
1433 |
// |
|
1434 |
void |
|
1435 |
GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v) |
|
1436 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
1437 |
NS_LOG_FUNCTION (v); |
1111 | 1438 |
|
1439 |
NS_ASSERT_MSG (m_spfroot, |
|
1440 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set"); |
|
1441 |
// |
|
1442 |
// The root of the Shortest Path First tree is the router to which we are |
|
1443 |
// going to write the actual routing table entries. The vertex corresponding |
|
1444 |
// to this router has a vertex ID which is the router ID of that node. We're |
|
1445 |
// going to use this ID to discover which node it is that we're actually going |
|
1446 |
// to update. |
|
1447 |
// |
|
1448 |
Ipv4Address routerId = m_spfroot->GetVertexId (); |
|
1449 |
||
1505 | 1450 |
NS_LOG_LOGIC ("Vertex ID = " << routerId); |
1111 | 1451 |
// |
1452 |
// We need to walk the list of nodes looking for the one that has the router |
|
1453 |
// ID corresponding to the root vertex. This is the one we're going to write |
|
1454 |
// the routing information to. |
|
1455 |
// |
|
1302
7dd6ea991e80
use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1301
diff
changeset
|
1456 |
NodeList::Iterator i = NodeList::Begin (); |
1111 | 1457 |
for (; i != NodeList::End (); i++) |
1458 |
{ |
|
1459 |
Ptr<Node> node = *i; |
|
1460 |
// |
|
1461 |
// The router ID is accessible through the GlobalRouter interface, so we need |
|
1462 |
// to QI for that interface. If there's no GlobalRouter interface, the node |
|
1463 |
// in question cannot be the router we want, so we continue. |
|
1464 |
// |
|
1465 |
Ptr<GlobalRouter> rtr = |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
1466 |
node->GetObject<GlobalRouter> (); |
1111 | 1467 |
|
1468 |
if (rtr == 0) |
|
1469 |
{ |
|
1505 | 1470 |
NS_LOG_LOGIC ("No GlobalRouter interface on node " << |
1471 |
node->GetId ()); |
|
1111 | 1472 |
continue; |
1473 |
} |
|
1474 |
// |
|
1475 |
// If the router ID of the current node is equal to the router ID of the |
|
1476 |
// root of the SPF tree, then this node is the one for which we need to |
|
1477 |
// write the routing tables. |
|
1478 |
// |
|
1505 | 1479 |
NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); |
1111 | 1480 |
|
1481 |
if (rtr->GetRouterId () == routerId) |
|
1482 |
{ |
|
1505 | 1483 |
NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); |
1111 | 1484 |
// |
1485 |
// Routing information is updated using the Ipv4 interface. We need to QI |
|
1486 |
// for that interface. If the node is acting as an IP version 4 router, it |
|
1487 |
// should absolutely have an Ipv4 interface. |
|
1488 |
// |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
1489 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1111 | 1490 |
NS_ASSERT_MSG (ipv4, |
1491 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
|
1492 |
"QI for <Ipv4> interface failed"); |
|
1493 |
// |
|
1494 |
// Get the Global Router Link State Advertisement from the vertex we're |
|
1495 |
// adding the routes to. The LSA will have a number of attached Global Router |
|
1496 |
// Link Records corresponding to links off of that vertex / node. We're going |
|
1497 |
// to be interested in the records corresponding to point-to-point links. |
|
1498 |
// |
|
1278 | 1499 |
GlobalRoutingLSA *lsa = v->GetLSA (); |
1111 | 1500 |
NS_ASSERT_MSG (lsa, |
1501 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
|
1502 |
"Expected valid LSA in SPFVertex* v"); |
|
1503 |
||
1504 |
uint32_t nLinkRecords = lsa->GetNLinkRecords (); |
|
1505 |
// |
|
1506 |
// Iterate through the link records on the vertex to which we're going to add |
|
1507 |
// routes. To make sure we're being clear, we're going to add routing table |
|
1508 |
// entries to the tables on the node corresping to the root of the SPF tree. |
|
1509 |
// These entries will have routes to the IP addresses we find from looking at |
|
1510 |
// the local side of the point-to-point links found on the node described by |
|
1511 |
// the vertex <v>. |
|
1512 |
// |
|
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1513 |
NS_LOG_LOGIC (" Node " << node->GetId () << |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1514 |
" found " << nLinkRecords << " link records in LSA " << lsa << "with LinkStateId "<< lsa->GetLinkStateId ()); |
3091 | 1515 |
for (uint32_t j = 0; j < nLinkRecords; ++j) |
1111 | 1516 |
{ |
1517 |
// |
|
1518 |
// We are only concerned about point-to-point links |
|
1519 |
// |
|
1278 | 1520 |
GlobalRoutingLinkRecord *lr = lsa->GetLinkRecord (j); |
1521 |
if (lr->GetLinkType () != GlobalRoutingLinkRecord::PointToPoint) |
|
1111 | 1522 |
{ |
1523 |
continue; |
|
1524 |
} |
|
1525 |
||
1505 | 1526 |
NS_LOG_LOGIC (" Node " << node->GetId () << |
1111 | 1527 |
" add route to " << lr->GetLinkData () << |
1528 |
" using next hop " << v->GetNextHop () << |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1529 |
" via interface " << v->GetOutgoingInterfaceId ()); |
1111 | 1530 |
// |
1531 |
// Here's why we did all of that work. We're going to add a host route to the |
|
1532 |
// host address found in the m_linkData field of the point-to-point link |
|
1533 |
// record. In the case of a point-to-point link, this is the local IP address |
|
1534 |
// of the node connected to the link. Each of these point-to-point links |
|
1535 |
// will correspond to a local interface that has an IP address to which |
|
1536 |
// the node at the root of the SPF tree can send packets. The vertex <v> |
|
1537 |
// (corresponding to the node that has these links and interfaces) has |
|
1538 |
// an m_nextHop address precalculated for us that is the address to which the |
|
1539 |
// root node should send packets to be forwarded to these IP addresses. |
|
1540 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
|
1541 |
// which the packets should be send for forwarding. |
|
1542 |
// |
|
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1543 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1544 |
NS_ASSERT (gr); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1545 |
gr->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (), |
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1546 |
v->GetOutgoingInterfaceId ()); |
1111 | 1547 |
} |
1548 |
// |
|
1549 |
// Done adding the routes for the selected node. |
|
1550 |
// |
|
1551 |
return; |
|
1552 |
} |
|
1553 |
} |
|
1554 |
} |
|
1278 | 1555 |
void |
1556 |
GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) |
|
1557 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
1558 |
NS_LOG_FUNCTION (v); |
1278 | 1559 |
|
1560 |
NS_ASSERT_MSG (m_spfroot, |
|
1561 |
"GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set"); |
|
1562 |
// |
|
1563 |
// The root of the Shortest Path First tree is the router to which we are |
|
1564 |
// going to write the actual routing table entries. The vertex corresponding |
|
1565 |
// to this router has a vertex ID which is the router ID of that node. We're |
|
1566 |
// going to use this ID to discover which node it is that we're actually going |
|
1567 |
// to update. |
|
1568 |
// |
|
1569 |
Ipv4Address routerId = m_spfroot->GetVertexId (); |
|
1570 |
||
1505 | 1571 |
NS_LOG_LOGIC ("Vertex ID = " << routerId); |
1278 | 1572 |
// |
1573 |
// We need to walk the list of nodes looking for the one that has the router |
|
1574 |
// ID corresponding to the root vertex. This is the one we're going to write |
|
1575 |
// the routing information to. |
|
1576 |
// |
|
1302
7dd6ea991e80
use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1301
diff
changeset
|
1577 |
NodeList::Iterator i = NodeList::Begin (); |
1278 | 1578 |
for (; i != NodeList::End (); i++) |
1579 |
{ |
|
1580 |
Ptr<Node> node = *i; |
|
1581 |
// |
|
1582 |
// The router ID is accessible through the GlobalRouter interface, so we need |
|
1583 |
// to QI for that interface. If there's no GlobalRouter interface, the node |
|
1584 |
// in question cannot be the router we want, so we continue. |
|
1585 |
// |
|
1586 |
Ptr<GlobalRouter> rtr = |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
1587 |
node->GetObject<GlobalRouter> (); |
1278 | 1588 |
|
1589 |
if (rtr == 0) |
|
1590 |
{ |
|
1505 | 1591 |
NS_LOG_LOGIC ("No GlobalRouter interface on node " << |
1592 |
node->GetId ()); |
|
1278 | 1593 |
continue; |
1594 |
} |
|
1595 |
// |
|
1596 |
// If the router ID of the current node is equal to the router ID of the |
|
1597 |
// root of the SPF tree, then this node is the one for which we need to |
|
1598 |
// write the routing tables. |
|
1599 |
// |
|
1505 | 1600 |
NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); |
1278 | 1601 |
|
1602 |
if (rtr->GetRouterId () == routerId) |
|
1603 |
{ |
|
1505 | 1604 |
NS_LOG_LOGIC ("setting routes for node " << node->GetId ()); |
1278 | 1605 |
// |
1606 |
// Routing information is updated using the Ipv4 interface. We need to QI |
|
1607 |
// for that interface. If the node is acting as an IP version 4 router, it |
|
1608 |
// should absolutely have an Ipv4 interface. |
|
1609 |
// |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
1610 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1278 | 1611 |
NS_ASSERT_MSG (ipv4, |
1612 |
"GlobalRouteManagerImpl::SPFIntraAddTransit (): " |
|
1613 |
"QI for <Ipv4> interface failed"); |
|
1614 |
// |
|
1615 |
// Get the Global Router Link State Advertisement from the vertex we're |
|
1616 |
// adding the routes to. The LSA will have a number of attached Global Router |
|
1617 |
// Link Records corresponding to links off of that vertex / node. We're going |
|
1618 |
// to be interested in the records corresponding to point-to-point links. |
|
1619 |
// |
|
1620 |
GlobalRoutingLSA *lsa = v->GetLSA (); |
|
1621 |
NS_ASSERT_MSG (lsa, |
|
1622 |
"GlobalRouteManagerImpl::SPFIntraAddTransit (): " |
|
1623 |
"Expected valid LSA in SPFVertex* v"); |
|
1279
03ab1b7ad2d0
fix optimized build; remove old comment
Tom Henderson <tomh@tomh.org>
parents:
1278
diff
changeset
|
1624 |
Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask (); |
03ab1b7ad2d0
fix optimized build; remove old comment
Tom Henderson <tomh@tomh.org>
parents:
1278
diff
changeset
|
1625 |
Ipv4Address tempip = lsa->GetLinkStateId (); |
1278 | 1626 |
tempip = tempip.CombineMask (tempmask); |
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1627 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1628 |
NS_ASSERT (gr); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1629 |
gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), |
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1630 |
v->GetOutgoingInterfaceId ()); |
1505 | 1631 |
NS_LOG_LOGIC ("Node " << node->GetId () << |
1278 | 1632 |
" add network route to " << tempip << |
1633 |
" using next hop " << v->GetNextHop () << |
|
4297
d8501bae8be1
Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents:
3969
diff
changeset
|
1634 |
" via interface " << v->GetOutgoingInterfaceId ()); |
1278 | 1635 |
} |
1636 |
} |
|
1637 |
} |
|
1111 | 1638 |
|
1639 |
// Derived from quagga ospf_vertex_add_parents () |
|
1640 |
// |
|
1641 |
// This is a somewhat oddly named method (blame quagga). Although you might |
|
1642 |
// expect it to add a parent *to* something, it actually adds a vertex |
|
1643 |
// to the list of children *in* each of its parents. |
|
1644 |
// |
|
1645 |
// Given a pointer to a vertex, it links back to the vertex's parent that it |
|
1646 |
// already has set and adds itself to that vertex's list of children. |
|
1647 |
// |
|
1648 |
// For now, only one parent (not doing equal-cost multipath) |
|
1649 |
// |
|
1650 |
void |
|
1651 |
GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v) |
|
1652 |
{ |
|
3946
6a20c485ddb5
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents:
3939
diff
changeset
|
1653 |
NS_LOG_FUNCTION (v); |
1111 | 1654 |
v->GetParent ()->AddChild (v); |
1655 |
} |
|
1656 |
||
3959
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1657 |
void |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1658 |
GlobalRouteManagerImpl::AddGlobalRoutingProtocol (uint32_t nodeId, Ptr<Ipv4GlobalRouting> proto) |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1659 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1660 |
NS_LOG_FUNCTION (nodeId); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1661 |
m_routingProtocols.push_back |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1662 |
(std::pair<uint32_t, Ptr<Ipv4GlobalRouting> > (nodeId, proto)); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1663 |
m_routingProtocols.sort (); |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1664 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1665 |
|
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1666 |
Ptr<Ipv4GlobalRouting> |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1667 |
GlobalRouteManagerImpl::GetGlobalRoutingProtocol (uint32_t nodeId) |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1668 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1669 |
for (Ipv4GlobalRoutingList::const_iterator rprotoIter = m_routingProtocols.begin (); rprotoIter != m_routingProtocols.end (); rprotoIter++) |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1670 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1671 |
if ((*rprotoIter).first == nodeId) |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1672 |
{ |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1673 |
return (*rprotoIter).second; |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1674 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1675 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1676 |
return 0; |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1677 |
} |
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1678 |
|
ec65107df095
Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents:
3947
diff
changeset
|
1679 |
|
1111 | 1680 |
} // namespace ns3 |
1681 |
||
1682 |
#ifdef RUN_SELF_TESTS |
|
1683 |
||
1684 |
// --------------------------------------------------------------------------- |
|
1685 |
// |
|
1686 |
// Unit Tests |
|
1687 |
// |
|
1688 |
// --------------------------------------------------------------------------- |
|
1689 |
||
1690 |
#include "ns3/test.h" |
|
1200
ae6244482a59
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1121
diff
changeset
|
1691 |
#include "ns3/simulator.h" |
3365
6409d2460601
bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3091
diff
changeset
|
1692 |
#include <stdlib.h> // for rand () |
1111 | 1693 |
|
1694 |
namespace ns3 { |
|
1695 |
||
1696 |
class GlobalRouteManagerImplTest : public Test { |
|
1697 |
public: |
|
1698 |
GlobalRouteManagerImplTest (); |
|
1699 |
virtual ~GlobalRouteManagerImplTest (); |
|
1700 |
virtual bool RunTests (void); |
|
1701 |
}; |
|
1702 |
||
1703 |
GlobalRouteManagerImplTest::GlobalRouteManagerImplTest () |
|
1704 |
: Test ("GlobalRouteManagerImpl") |
|
1705 |
{ |
|
1706 |
} |
|
1707 |
||
1708 |
GlobalRouteManagerImplTest::~GlobalRouteManagerImplTest () |
|
1709 |
{} |
|
1710 |
||
1711 |
bool |
|
1712 |
GlobalRouteManagerImplTest::RunTests (void) |
|
1713 |
{ |
|
1714 |
bool ok = true; |
|
1715 |
||
1716 |
CandidateQueue candidate; |
|
1717 |
||
1718 |
for (int i = 0; i < 100; ++i) |
|
1719 |
{ |
|
1720 |
SPFVertex *v = new SPFVertex; |
|
1721 |
v->SetDistanceFromRoot (rand () % 100); |
|
1722 |
candidate.Push (v); |
|
1723 |
} |
|
1724 |
||
1725 |
uint32_t lastDistance = 0; |
|
1726 |
||
1727 |
for (int i = 0; i < 100; ++i) |
|
1728 |
{ |
|
1729 |
SPFVertex *v = candidate.Pop (); |
|
1730 |
if (v->GetDistanceFromRoot () < lastDistance) |
|
1731 |
{ |
|
1732 |
ok = false; |
|
1733 |
} |
|
1734 |
lastDistance = v->GetDistanceFromRoot (); |
|
1735 |
delete v; |
|
1736 |
v = 0; |
|
1737 |
} |
|
1738 |
||
1739 |
// Build fake link state database; four routers (0-3), 3 point-to-point |
|
1740 |
// links |
|
1741 |
// |
|
1742 |
// n0 |
|
1743 |
// \ link 0 |
|
1744 |
// \ link 2 |
|
1745 |
// n2 -------------------------n3 |
|
1746 |
// / |
|
1747 |
// / link 1 |
|
1748 |
// n1 |
|
1749 |
// |
|
1750 |
// link0: 10.1.1.1/30, 10.1.1.2/30 |
|
1751 |
// link1: 10.1.2.1/30, 10.1.2.2/30 |
|
1752 |
// link2: 10.1.3.1/30, 10.1.3.2/30 |
|
1753 |
// |
|
1754 |
// Router 0 |
|
1278 | 1755 |
GlobalRoutingLinkRecord* lr0 = new GlobalRoutingLinkRecord ( |
1756 |
GlobalRoutingLinkRecord::PointToPoint, |
|
1111 | 1757 |
"0.0.0.2", // router ID 0.0.0.2 |
1758 |
"10.1.1.1", // local ID |
|
1759 |
1); // metric |
|
1760 |
||
1278 | 1761 |
GlobalRoutingLinkRecord* lr1 = new GlobalRoutingLinkRecord ( |
1762 |
GlobalRoutingLinkRecord::StubNetwork, |
|
1111 | 1763 |
"10.1.1.1", |
1764 |
"255.255.255.252", |
|
1765 |
1); |
|
1766 |
||
1278 | 1767 |
GlobalRoutingLSA* lsa0 = new GlobalRoutingLSA (); |
1282 | 1768 |
lsa0->SetLSType (GlobalRoutingLSA::RouterLSA); |
1111 | 1769 |
lsa0->SetLinkStateId ("0.0.0.0"); |
1770 |
lsa0->SetAdvertisingRouter ("0.0.0.0"); |
|
1771 |
lsa0->AddLinkRecord (lr0); |
|
1772 |
lsa0->AddLinkRecord (lr1); |
|
1773 |
||
1774 |
// Router 1 |
|
1278 | 1775 |
GlobalRoutingLinkRecord* lr2 = new GlobalRoutingLinkRecord ( |
1776 |
GlobalRoutingLinkRecord::PointToPoint, |
|
1111 | 1777 |
"0.0.0.2", |
1778 |
"10.1.2.1", |
|
1779 |
1); |
|
1780 |
||
1278 | 1781 |
GlobalRoutingLinkRecord* lr3 = new GlobalRoutingLinkRecord ( |
1782 |
GlobalRoutingLinkRecord::StubNetwork, |
|
1111 | 1783 |
"10.1.2.1", |
1784 |
"255.255.255.252", |
|
1785 |
1); |
|
1786 |
||
1278 | 1787 |
GlobalRoutingLSA* lsa1 = new GlobalRoutingLSA (); |
1282 | 1788 |
lsa1->SetLSType (GlobalRoutingLSA::RouterLSA); |
1111 | 1789 |
lsa1->SetLinkStateId ("0.0.0.1"); |
1790 |
lsa1->SetAdvertisingRouter ("0.0.0.1"); |
|
1791 |
lsa1->AddLinkRecord (lr2); |
|
1792 |
lsa1->AddLinkRecord (lr3); |
|
1793 |
||
1794 |
// Router 2 |
|
1278 | 1795 |
GlobalRoutingLinkRecord* lr4 = new GlobalRoutingLinkRecord ( |
1796 |
GlobalRoutingLinkRecord::PointToPoint, |
|
1111 | 1797 |
"0.0.0.0", |
1798 |
"10.1.1.2", |
|
1799 |
1); |
|
1800 |
||
1278 | 1801 |
GlobalRoutingLinkRecord* lr5 = new GlobalRoutingLinkRecord ( |
1802 |
GlobalRoutingLinkRecord::StubNetwork, |
|
1111 | 1803 |
"10.1.1.2", |
1804 |
"255.255.255.252", |
|
1805 |
1); |
|
1806 |
||
1278 | 1807 |
GlobalRoutingLinkRecord* lr6 = new GlobalRoutingLinkRecord ( |
1808 |
GlobalRoutingLinkRecord::PointToPoint, |
|
1111 | 1809 |
"0.0.0.1", |
1810 |
"10.1.2.2", |
|
1811 |
1); |
|
1812 |
||
1278 | 1813 |
GlobalRoutingLinkRecord* lr7 = new GlobalRoutingLinkRecord ( |
1814 |
GlobalRoutingLinkRecord::StubNetwork, |
|
1111 | 1815 |
"10.1.2.2", |
1816 |
"255.255.255.252", |
|
1817 |
1); |
|
1818 |
||
1278 | 1819 |
GlobalRoutingLinkRecord* lr8 = new GlobalRoutingLinkRecord ( |
1820 |
GlobalRoutingLinkRecord::PointToPoint, |
|
1111 | 1821 |
"0.0.0.3", |
1822 |
"10.1.3.2", |
|
1823 |
1); |
|
1824 |
||
1278 | 1825 |
GlobalRoutingLinkRecord* lr9 = new GlobalRoutingLinkRecord ( |
1826 |
GlobalRoutingLinkRecord::StubNetwork, |
|
1111 | 1827 |
"10.1.3.2", |
1828 |
"255.255.255.252", |
|
1829 |
1); |
|
1830 |
||
1278 | 1831 |
GlobalRoutingLSA* lsa2 = new GlobalRoutingLSA (); |
1282 | 1832 |
lsa2->SetLSType (GlobalRoutingLSA::RouterLSA); |
1111 | 1833 |
lsa2->SetLinkStateId ("0.0.0.2"); |
1834 |
lsa2->SetAdvertisingRouter ("0.0.0.2"); |
|
1835 |
lsa2->AddLinkRecord (lr4); |
|
1836 |
lsa2->AddLinkRecord (lr5); |
|
1837 |
lsa2->AddLinkRecord (lr6); |
|
1838 |
lsa2->AddLinkRecord (lr7); |
|
1839 |
lsa2->AddLinkRecord (lr8); |
|
1840 |
lsa2->AddLinkRecord (lr9); |
|
1841 |
||
1842 |
// Router 3 |
|
1278 | 1843 |
GlobalRoutingLinkRecord* lr10 = new GlobalRoutingLinkRecord ( |
1844 |
GlobalRoutingLinkRecord::PointToPoint, |
|
1111 | 1845 |
"0.0.0.2", |
1846 |
"10.1.2.1", |
|
1847 |
1); |
|
1848 |
||
1278 | 1849 |
GlobalRoutingLinkRecord* lr11 = new GlobalRoutingLinkRecord ( |
1850 |
GlobalRoutingLinkRecord::StubNetwork, |
|
1111 | 1851 |
"10.1.2.1", |
1852 |
"255.255.255.252", |
|
1853 |
1); |
|
1854 |
||
1278 | 1855 |
GlobalRoutingLSA* lsa3 = new GlobalRoutingLSA (); |
1282 | 1856 |
lsa3->SetLSType (GlobalRoutingLSA::RouterLSA); |
1111 | 1857 |
lsa3->SetLinkStateId ("0.0.0.3"); |
1858 |
lsa3->SetAdvertisingRouter ("0.0.0.3"); |
|
1859 |
lsa3->AddLinkRecord (lr10); |
|
1860 |
lsa3->AddLinkRecord (lr11); |
|
1861 |
||
1862 |
// Test the database |
|
1863 |
GlobalRouteManagerLSDB* srmlsdb = new GlobalRouteManagerLSDB (); |
|
1864 |
srmlsdb->Insert (lsa0->GetLinkStateId (), lsa0); |
|
1865 |
srmlsdb->Insert (lsa1->GetLinkStateId (), lsa1); |
|
1866 |
srmlsdb->Insert (lsa2->GetLinkStateId (), lsa2); |
|
1867 |
srmlsdb->Insert (lsa3->GetLinkStateId (), lsa3); |
|
1868 |
NS_ASSERT (lsa2 == srmlsdb->GetLSA (lsa2->GetLinkStateId ())); |
|
1869 |
||
1870 |
// next, calculate routes based on the manually created LSDB |
|
1871 |
GlobalRouteManagerImpl* srm = new GlobalRouteManagerImpl (); |
|
1872 |
srm->DebugUseLsdb (srmlsdb); // manually add in an LSDB |
|
1873 |
// Note-- this will succeed without any nodes in the topology |
|
1874 |
// because the NodeList is empty |
|
1875 |
srm->DebugSPFCalculate (lsa0->GetLinkStateId ()); // node n0 |
|
1876 |
||
1200
ae6244482a59
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1121
diff
changeset
|
1877 |
Simulator::Run (); |
1316
f357c6a2bb37
Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents:
1302
diff
changeset
|
1878 |
|
f357c6a2bb37
Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents:
1302
diff
changeset
|
1879 |
// XXX here we should do some verification of the routes built |
f357c6a2bb37
Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents:
1302
diff
changeset
|
1880 |
|
1200
ae6244482a59
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1121
diff
changeset
|
1881 |
Simulator::Destroy (); |
ae6244482a59
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1121
diff
changeset
|
1882 |
|
1111 | 1883 |
// This delete clears the srm, which deletes the LSDB, which clears |
1884 |
// all of the LSAs, which each destroys the attached LinkRecords. |
|
1885 |
delete srm; |
|
1886 |
||
1887 |
return ok; |
|
1888 |
} |
|
1889 |
||
1890 |
// Instantiate this class for the unit tests |
|
1891 |
static GlobalRouteManagerImplTest g_globalRouteManagerTest; |
|
1892 |
||
1893 |
} // namespace ns3 |
|
1894 |
||
1895 |
#endif |