author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 13 Mar 2008 12:56:49 -0700 | |
changeset 2602 | d9262bff6df2 |
parent 2257 | 71a58e70c671 |
child 2827 | 4bcc29436feb |
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:
1278
diff
changeset
|
3 |
* Copyright 2007 University of Washington |
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1278
diff
changeset
|
4 |
* |
1111 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
1457
562a7017ed93
Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents:
1278
diff
changeset
|
17 |
* |
1505 | 18 |
* Authors: Tom Henderson (tomhend@u.washington.edu) |
1111 | 19 |
*/ |
20 |
||
1505 | 21 |
#include "ns3/log.h" |
1111 | 22 |
#include "ns3/assert.h" |
23 |
#include "ns3/channel.h" |
|
24 |
#include "ns3/net-device.h" |
|
25 |
#include "ns3/internet-node.h" |
|
26 |
#include "ns3/ipv4.h" |
|
27 |
#include "global-router-interface.h" |
|
28 |
||
1505 | 29 |
NS_LOG_COMPONENT_DEFINE ("GlobalRouter"); |
1111 | 30 |
|
31 |
namespace ns3 { |
|
32 |
||
33 |
// --------------------------------------------------------------------------- |
|
34 |
// |
|
1278 | 35 |
// GlobalRoutingLinkRecord Implementation |
1111 | 36 |
// |
37 |
// --------------------------------------------------------------------------- |
|
38 |
||
1278 | 39 |
GlobalRoutingLinkRecord::GlobalRoutingLinkRecord () |
1111 | 40 |
: |
41 |
m_linkId ("0.0.0.0"), |
|
42 |
m_linkData ("0.0.0.0"), |
|
43 |
m_linkType (Unknown), |
|
44 |
m_metric (0) |
|
45 |
{ |
|
1505 | 46 |
NS_LOG_FUNCTION; |
1111 | 47 |
} |
48 |
||
1278 | 49 |
GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ( |
1111 | 50 |
LinkType linkType, |
51 |
Ipv4Address linkId, |
|
52 |
Ipv4Address linkData, |
|
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
|
53 |
uint16_t metric) |
1111 | 54 |
: |
55 |
m_linkId (linkId), |
|
56 |
m_linkData (linkData), |
|
57 |
m_linkType (linkType), |
|
58 |
m_metric (metric) |
|
59 |
{ |
|
1505 | 60 |
NS_LOG_FUNCTION; |
1828
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1776
diff
changeset
|
61 |
NS_LOG_PARAMS (this << linkType << linkId << linkData << metric); |
1111 | 62 |
} |
63 |
||
1278 | 64 |
GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord () |
1111 | 65 |
{ |
1505 | 66 |
NS_LOG_FUNCTION; |
1111 | 67 |
} |
68 |
||
69 |
Ipv4Address |
|
1278 | 70 |
GlobalRoutingLinkRecord::GetLinkId (void) const |
1111 | 71 |
{ |
1505 | 72 |
NS_LOG_FUNCTION; |
1111 | 73 |
return m_linkId; |
74 |
} |
|
75 |
||
76 |
void |
|
1278 | 77 |
GlobalRoutingLinkRecord::SetLinkId (Ipv4Address addr) |
1111 | 78 |
{ |
1505 | 79 |
NS_LOG_FUNCTION; |
1111 | 80 |
m_linkId = addr; |
81 |
} |
|
82 |
||
83 |
Ipv4Address |
|
1278 | 84 |
GlobalRoutingLinkRecord::GetLinkData (void) const |
1111 | 85 |
{ |
1505 | 86 |
NS_LOG_FUNCTION; |
1111 | 87 |
return m_linkData; |
88 |
} |
|
89 |
||
90 |
void |
|
1278 | 91 |
GlobalRoutingLinkRecord::SetLinkData (Ipv4Address addr) |
1111 | 92 |
{ |
1505 | 93 |
NS_LOG_FUNCTION; |
1111 | 94 |
m_linkData = addr; |
95 |
} |
|
96 |
||
1278 | 97 |
GlobalRoutingLinkRecord::LinkType |
98 |
GlobalRoutingLinkRecord::GetLinkType (void) const |
|
1111 | 99 |
{ |
1505 | 100 |
NS_LOG_FUNCTION; |
1111 | 101 |
return m_linkType; |
102 |
} |
|
103 |
||
104 |
void |
|
1278 | 105 |
GlobalRoutingLinkRecord::SetLinkType ( |
106 |
GlobalRoutingLinkRecord::LinkType linkType) |
|
1111 | 107 |
{ |
1505 | 108 |
NS_LOG_FUNCTION; |
1111 | 109 |
m_linkType = linkType; |
110 |
} |
|
111 |
||
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
|
112 |
uint16_t |
1278 | 113 |
GlobalRoutingLinkRecord::GetMetric (void) const |
1111 | 114 |
{ |
1505 | 115 |
NS_LOG_FUNCTION; |
1111 | 116 |
return m_metric; |
117 |
} |
|
118 |
||
119 |
void |
|
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
|
120 |
GlobalRoutingLinkRecord::SetMetric (uint16_t metric) |
1111 | 121 |
{ |
1505 | 122 |
NS_LOG_FUNCTION; |
1111 | 123 |
m_metric = metric; |
124 |
} |
|
125 |
||
126 |
// --------------------------------------------------------------------------- |
|
127 |
// |
|
1278 | 128 |
// GlobalRoutingLSA Implementation |
1111 | 129 |
// |
130 |
// --------------------------------------------------------------------------- |
|
131 |
||
1278 | 132 |
GlobalRoutingLSA::GlobalRoutingLSA() |
1111 | 133 |
: |
1278 | 134 |
m_lsType (GlobalRoutingLSA::Unknown), |
1111 | 135 |
m_linkStateId("0.0.0.0"), |
136 |
m_advertisingRtr("0.0.0.0"), |
|
137 |
m_linkRecords(), |
|
1278 | 138 |
m_networkLSANetworkMask("0.0.0.0"), |
139 |
m_attachedRouters(), |
|
140 |
m_status(GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED) |
|
1111 | 141 |
{ |
1505 | 142 |
NS_LOG_FUNCTION; |
1111 | 143 |
} |
144 |
||
1278 | 145 |
GlobalRoutingLSA::GlobalRoutingLSA ( |
146 |
GlobalRoutingLSA::SPFStatus status, |
|
1111 | 147 |
Ipv4Address linkStateId, |
148 |
Ipv4Address advertisingRtr) |
|
149 |
: |
|
1278 | 150 |
m_lsType (GlobalRoutingLSA::Unknown), |
1111 | 151 |
m_linkStateId(linkStateId), |
152 |
m_advertisingRtr(advertisingRtr), |
|
153 |
m_linkRecords(), |
|
1278 | 154 |
m_networkLSANetworkMask("0.0.0.0"), |
155 |
m_attachedRouters(), |
|
1111 | 156 |
m_status(status) |
157 |
{ |
|
1505 | 158 |
NS_LOG_FUNCTION; |
1828
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1776
diff
changeset
|
159 |
NS_LOG_PARAMS (this << status << linkStateId << advertisingRtr); |
1111 | 160 |
} |
161 |
||
1278 | 162 |
GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa) |
163 |
: m_lsType(lsa.m_lsType), m_linkStateId(lsa.m_linkStateId), |
|
164 |
m_advertisingRtr(lsa.m_advertisingRtr), |
|
165 |
m_networkLSANetworkMask(lsa.m_networkLSANetworkMask), |
|
1111 | 166 |
m_status(lsa.m_status) |
167 |
{ |
|
1505 | 168 |
NS_LOG_FUNCTION; |
1111 | 169 |
NS_ASSERT_MSG(IsEmpty(), |
1278 | 170 |
"GlobalRoutingLSA::GlobalRoutingLSA (): Non-empty LSA in constructor"); |
1111 | 171 |
CopyLinkRecords (lsa); |
172 |
} |
|
173 |
||
1278 | 174 |
GlobalRoutingLSA& |
175 |
GlobalRoutingLSA::operator= (const GlobalRoutingLSA& lsa) |
|
1111 | 176 |
{ |
1505 | 177 |
NS_LOG_FUNCTION; |
1278 | 178 |
m_lsType = lsa.m_lsType; |
1111 | 179 |
m_linkStateId = lsa.m_linkStateId; |
180 |
m_advertisingRtr = lsa.m_advertisingRtr; |
|
1278 | 181 |
m_networkLSANetworkMask = lsa.m_networkLSANetworkMask, |
1111 | 182 |
m_status = lsa.m_status; |
183 |
||
184 |
ClearLinkRecords (); |
|
185 |
CopyLinkRecords (lsa); |
|
186 |
return *this; |
|
187 |
} |
|
188 |
||
189 |
void |
|
1278 | 190 |
GlobalRoutingLSA::CopyLinkRecords (const GlobalRoutingLSA& lsa) |
1111 | 191 |
{ |
1505 | 192 |
NS_LOG_FUNCTION; |
1111 | 193 |
for (ListOfLinkRecords_t::const_iterator i = lsa.m_linkRecords.begin (); |
194 |
i != lsa.m_linkRecords.end (); |
|
195 |
i++) |
|
196 |
{ |
|
1278 | 197 |
GlobalRoutingLinkRecord *pSrc = *i; |
198 |
GlobalRoutingLinkRecord *pDst = new GlobalRoutingLinkRecord; |
|
1111 | 199 |
|
200 |
pDst->SetLinkType (pSrc->GetLinkType ()); |
|
201 |
pDst->SetLinkId (pSrc->GetLinkId ()); |
|
202 |
pDst->SetLinkData (pSrc->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
|
203 |
pDst->SetMetric (pSrc->GetMetric ()); |
1111 | 204 |
|
205 |
m_linkRecords.push_back(pDst); |
|
206 |
pDst = 0; |
|
207 |
} |
|
1278 | 208 |
|
209 |
m_attachedRouters = lsa.m_attachedRouters; |
|
1111 | 210 |
} |
211 |
||
1278 | 212 |
GlobalRoutingLSA::~GlobalRoutingLSA() |
1111 | 213 |
{ |
1505 | 214 |
NS_LOG_FUNCTION; |
1111 | 215 |
ClearLinkRecords (); |
216 |
} |
|
217 |
||
218 |
void |
|
1278 | 219 |
GlobalRoutingLSA::ClearLinkRecords(void) |
1111 | 220 |
{ |
1505 | 221 |
NS_LOG_FUNCTION; |
1111 | 222 |
for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin (); |
223 |
i != m_linkRecords.end (); |
|
224 |
i++) |
|
225 |
{ |
|
1505 | 226 |
NS_LOG_LOGIC ("Free link record"); |
1111 | 227 |
|
1278 | 228 |
GlobalRoutingLinkRecord *p = *i; |
1111 | 229 |
delete p; |
230 |
p = 0; |
|
231 |
||
232 |
*i = 0; |
|
233 |
} |
|
1505 | 234 |
NS_LOG_LOGIC ("Clear list"); |
1111 | 235 |
m_linkRecords.clear(); |
236 |
} |
|
237 |
||
238 |
uint32_t |
|
1278 | 239 |
GlobalRoutingLSA::AddLinkRecord (GlobalRoutingLinkRecord* lr) |
1111 | 240 |
{ |
1505 | 241 |
NS_LOG_FUNCTION; |
1111 | 242 |
m_linkRecords.push_back (lr); |
243 |
return m_linkRecords.size (); |
|
244 |
} |
|
245 |
||
246 |
uint32_t |
|
1278 | 247 |
GlobalRoutingLSA::GetNLinkRecords (void) const |
1111 | 248 |
{ |
1505 | 249 |
NS_LOG_FUNCTION; |
1111 | 250 |
return m_linkRecords.size (); |
251 |
} |
|
252 |
||
1278 | 253 |
GlobalRoutingLinkRecord * |
254 |
GlobalRoutingLSA::GetLinkRecord (uint32_t n) const |
|
1111 | 255 |
{ |
1505 | 256 |
NS_LOG_FUNCTION; |
1111 | 257 |
uint32_t j = 0; |
258 |
for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin (); |
|
259 |
i != m_linkRecords.end (); |
|
260 |
i++, j++) |
|
261 |
{ |
|
262 |
if (j == n) |
|
263 |
{ |
|
264 |
return *i; |
|
265 |
} |
|
266 |
} |
|
1278 | 267 |
NS_ASSERT_MSG(false, "GlobalRoutingLSA::GetLinkRecord (): invalid index"); |
1111 | 268 |
return 0; |
269 |
} |
|
270 |
||
271 |
bool |
|
1278 | 272 |
GlobalRoutingLSA::IsEmpty (void) const |
1111 | 273 |
{ |
1505 | 274 |
NS_LOG_FUNCTION; |
1111 | 275 |
return m_linkRecords.size () == 0; |
276 |
} |
|
277 |
||
1278 | 278 |
GlobalRoutingLSA::LSType |
279 |
GlobalRoutingLSA::GetLSType (void) const |
|
280 |
{ |
|
1505 | 281 |
NS_LOG_FUNCTION; |
1278 | 282 |
return m_lsType; |
283 |
} |
|
284 |
||
285 |
void |
|
286 |
GlobalRoutingLSA::SetLSType (GlobalRoutingLSA::LSType typ) |
|
287 |
{ |
|
1505 | 288 |
NS_LOG_FUNCTION; |
1278 | 289 |
m_lsType = typ; |
290 |
} |
|
291 |
||
1111 | 292 |
Ipv4Address |
1278 | 293 |
GlobalRoutingLSA::GetLinkStateId (void) const |
1111 | 294 |
{ |
1505 | 295 |
NS_LOG_FUNCTION; |
1111 | 296 |
return m_linkStateId; |
297 |
} |
|
298 |
||
299 |
void |
|
1278 | 300 |
GlobalRoutingLSA::SetLinkStateId (Ipv4Address addr) |
1111 | 301 |
{ |
1505 | 302 |
NS_LOG_FUNCTION; |
1111 | 303 |
m_linkStateId = addr; |
304 |
} |
|
305 |
||
306 |
Ipv4Address |
|
1278 | 307 |
GlobalRoutingLSA::GetAdvertisingRouter (void) const |
1111 | 308 |
{ |
1505 | 309 |
NS_LOG_FUNCTION; |
1111 | 310 |
return m_advertisingRtr; |
311 |
} |
|
312 |
||
313 |
void |
|
1278 | 314 |
GlobalRoutingLSA::SetAdvertisingRouter (Ipv4Address addr) |
1111 | 315 |
{ |
1505 | 316 |
NS_LOG_FUNCTION; |
1111 | 317 |
m_advertisingRtr = addr; |
318 |
} |
|
319 |
||
1278 | 320 |
void |
321 |
GlobalRoutingLSA::SetNetworkLSANetworkMask (Ipv4Mask mask) |
|
322 |
{ |
|
1505 | 323 |
NS_LOG_FUNCTION; |
1278 | 324 |
m_networkLSANetworkMask = mask; |
325 |
} |
|
326 |
||
327 |
Ipv4Mask |
|
328 |
GlobalRoutingLSA::GetNetworkLSANetworkMask (void) const |
|
329 |
{ |
|
1505 | 330 |
NS_LOG_FUNCTION; |
1278 | 331 |
return m_networkLSANetworkMask; |
332 |
} |
|
333 |
||
334 |
GlobalRoutingLSA::SPFStatus |
|
335 |
GlobalRoutingLSA::GetStatus (void) const |
|
1111 | 336 |
{ |
1505 | 337 |
NS_LOG_FUNCTION; |
1111 | 338 |
return m_status; |
339 |
} |
|
340 |
||
1278 | 341 |
uint32_t |
342 |
GlobalRoutingLSA::AddAttachedRouter (Ipv4Address addr) |
|
343 |
{ |
|
1505 | 344 |
NS_LOG_FUNCTION; |
1278 | 345 |
m_attachedRouters.push_back (addr); |
346 |
return m_attachedRouters.size (); |
|
347 |
} |
|
348 |
||
349 |
uint32_t |
|
350 |
GlobalRoutingLSA::GetNAttachedRouters (void) const |
|
351 |
{ |
|
1505 | 352 |
NS_LOG_FUNCTION; |
1278 | 353 |
return m_attachedRouters.size (); |
354 |
} |
|
355 |
||
356 |
Ipv4Address |
|
357 |
GlobalRoutingLSA::GetAttachedRouter (uint32_t n) const |
|
358 |
{ |
|
1505 | 359 |
NS_LOG_FUNCTION; |
1278 | 360 |
uint32_t j = 0; |
361 |
for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin (); |
|
362 |
i != m_attachedRouters.end (); |
|
363 |
i++, j++) |
|
364 |
{ |
|
365 |
if (j == n) |
|
366 |
{ |
|
367 |
return *i; |
|
368 |
} |
|
369 |
} |
|
1505 | 370 |
NS_ASSERT_MSG(false, |
371 |
"GlobalRoutingLSA::GetAttachedRouter (): invalid index"); |
|
1278 | 372 |
return Ipv4Address("0.0.0.0"); |
373 |
} |
|
374 |
||
1111 | 375 |
void |
1278 | 376 |
GlobalRoutingLSA::SetStatus (GlobalRoutingLSA::SPFStatus status) |
1111 | 377 |
{ |
1505 | 378 |
NS_LOG_FUNCTION; |
1111 | 379 |
m_status = status; |
380 |
} |
|
381 |
||
382 |
void |
|
1278 | 383 |
GlobalRoutingLSA::Print (std::ostream &os) const |
1111 | 384 |
{ |
1278 | 385 |
os << "m_lsType = " << m_lsType << std::endl << |
386 |
"m_linkStateId = " << m_linkStateId << std::endl << |
|
1111 | 387 |
"m_advertisingRtr = " << m_advertisingRtr << std::endl; |
388 |
||
1278 | 389 |
if (m_lsType == GlobalRoutingLSA::RouterLSA) |
390 |
{ |
|
391 |
for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin (); |
|
392 |
i != m_linkRecords.end (); |
|
393 |
i++) |
|
394 |
{ |
|
395 |
GlobalRoutingLinkRecord *p = *i; |
|
396 |
os << "----------" << std::endl; |
|
397 |
os << "m_linkId = " << p->GetLinkId () << std::endl; |
|
398 |
os << "m_linkData = " << p->GetLinkData () << std::endl; |
|
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
|
399 |
os << "m_metric = " << p->GetMetric () << std::endl; |
1278 | 400 |
} |
401 |
} |
|
402 |
else if (m_lsType == GlobalRoutingLSA::NetworkLSA) |
|
1111 | 403 |
{ |
404 |
os << "----------" << std::endl; |
|
1278 | 405 |
os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask |
406 |
<< std::endl; |
|
407 |
for ( ListOfAttachedRouters_t::const_iterator i = |
|
408 |
m_attachedRouters.begin (); |
|
409 |
i != m_attachedRouters.end (); |
|
410 |
i++) |
|
411 |
{ |
|
412 |
Ipv4Address p = *i; |
|
413 |
os << "attachedRouter = " << p << std::endl; |
|
414 |
} |
|
415 |
} |
|
416 |
else |
|
417 |
{ |
|
418 |
NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType); |
|
1111 | 419 |
} |
420 |
} |
|
421 |
||
1278 | 422 |
std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa) |
1111 | 423 |
{ |
424 |
lsa.Print (os); |
|
425 |
return os; |
|
426 |
} |
|
427 |
||
428 |
// --------------------------------------------------------------------------- |
|
429 |
// |
|
430 |
// GlobalRouter Implementation |
|
431 |
// |
|
432 |
// --------------------------------------------------------------------------- |
|
433 |
||
2249
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2238
diff
changeset
|
434 |
NS_OBJECT_ENSURE_REGISTERED (GlobalRouter); |
3a1da26d61dc
replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2238
diff
changeset
|
435 |
|
2250
18f432098389
InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2249
diff
changeset
|
436 |
TypeId |
2251
04963d8cca51
iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2250
diff
changeset
|
437 |
GlobalRouter::GetTypeId (void) |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
438 |
{ |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
439 |
static TypeId tid = TypeId ("ns3::GlobalRouter") |
2238
05affd9d0dc1
get rid of MakeInterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2232
diff
changeset
|
440 |
.SetParent<Object> (); |
2252
80595448707a
iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2251
diff
changeset
|
441 |
return tid; |
2232
9abd038ee588
replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2231
diff
changeset
|
442 |
} |
1111 | 443 |
|
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
444 |
GlobalRouter::GlobalRouter () |
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
445 |
: m_LSAs() |
1111 | 446 |
{ |
1505 | 447 |
NS_LOG_FUNCTION; |
1113
5b63b39161e7
remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents:
1111
diff
changeset
|
448 |
m_routerId.Set(GlobalRouteManager::AllocateRouterId ()); |
1111 | 449 |
} |
450 |
||
451 |
GlobalRouter::~GlobalRouter () |
|
452 |
{ |
|
1505 | 453 |
NS_LOG_FUNCTION; |
1111 | 454 |
ClearLSAs(); |
455 |
} |
|
456 |
||
1202
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1123
diff
changeset
|
457 |
void |
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1123
diff
changeset
|
458 |
GlobalRouter::DoDispose () |
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1123
diff
changeset
|
459 |
{ |
1505 | 460 |
NS_LOG_FUNCTION; |
1202
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1123
diff
changeset
|
461 |
Object::DoDispose (); |
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1123
diff
changeset
|
462 |
} |
953cc2fadcef
fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1123
diff
changeset
|
463 |
|
1111 | 464 |
void |
465 |
GlobalRouter::ClearLSAs () |
|
466 |
{ |
|
1505 | 467 |
NS_LOG_FUNCTION; |
1111 | 468 |
for ( ListOfLSAs_t::iterator i = m_LSAs.begin (); |
469 |
i != m_LSAs.end (); |
|
470 |
i++) |
|
471 |
{ |
|
1505 | 472 |
NS_LOG_LOGIC ("Free LSA"); |
1111 | 473 |
|
1278 | 474 |
GlobalRoutingLSA *p = *i; |
1111 | 475 |
delete p; |
476 |
p = 0; |
|
477 |
||
478 |
*i = 0; |
|
479 |
} |
|
1505 | 480 |
NS_LOG_LOGIC ("Clear list"); |
1111 | 481 |
m_LSAs.clear(); |
482 |
} |
|
483 |
||
484 |
Ipv4Address |
|
485 |
GlobalRouter::GetRouterId (void) const |
|
486 |
{ |
|
1505 | 487 |
NS_LOG_FUNCTION; |
1111 | 488 |
return m_routerId; |
489 |
} |
|
490 |
||
491 |
// |
|
492 |
// Go out and discover any adjacent routers and build the Link State |
|
493 |
// Advertisements that reflect them and their associated networks. |
|
494 |
// |
|
495 |
uint32_t |
|
496 |
GlobalRouter::DiscoverLSAs (void) |
|
497 |
{ |
|
1505 | 498 |
NS_LOG_FUNCTION; |
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
499 |
Ptr<Node> node = GetObject<Node> (); |
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
500 |
NS_LOG_LOGIC("For node " << node->GetId () ); |
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
501 |
NS_ASSERT_MSG(node, |
1111 | 502 |
"GlobalRouter::DiscoverLSAs (): <Node> interface not set"); |
503 |
||
504 |
ClearLSAs (); |
|
1278 | 505 |
|
506 |
// While building the router-LSA, keep a list of those NetDevices for |
|
507 |
// which I am the designated router and need to later build a NetworkLSA |
|
508 |
std::list<Ptr<NetDevice> > listOfDRInterfaces; |
|
509 |
||
1111 | 510 |
// |
511 |
// We're aggregated to a node. We need to ask the node for a pointer to its |
|
512 |
// Ipv4 interface. This is where the information regarding the attached |
|
513 |
// interfaces lives. |
|
514 |
// |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
515 |
Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> (); |
1111 | 516 |
NS_ASSERT_MSG(ipv4Local, |
517 |
"GlobalRouter::DiscoverLSAs (): QI for <Ipv4> interface failed"); |
|
518 |
// |
|
1278 | 519 |
// Each node originates a Router-LSA |
1111 | 520 |
// |
1278 | 521 |
GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; |
522 |
pLSA->SetLSType (GlobalRoutingLSA::RouterLSA); |
|
1111 | 523 |
pLSA->SetLinkStateId (m_routerId); |
524 |
pLSA->SetAdvertisingRouter (m_routerId); |
|
1278 | 525 |
pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); |
1111 | 526 |
// |
527 |
// We need to ask the node for the number of net devices attached. This isn't |
|
528 |
// necessarily equal to the number of links to adjacent nodes (other routers) |
|
529 |
// as the number of devices may include those for stub networks (e.g., |
|
1278 | 530 |
// ethernets, etc.). |
1111 | 531 |
// |
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
532 |
uint32_t numDevices = node->GetNDevices(); |
1505 | 533 |
NS_LOG_LOGIC ("numDevices = " << numDevices); |
1111 | 534 |
for (uint32_t i = 0; i < numDevices; ++i) |
535 |
{ |
|
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
536 |
Ptr<NetDevice> ndLocal = node->GetDevice(i); |
1111 | 537 |
|
1278 | 538 |
if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () ) |
1111 | 539 |
{ |
1505 | 540 |
NS_LOG_LOGIC ("Broadcast link"); |
1278 | 541 |
GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; |
542 |
// |
|
543 |
// We need to determine whether we are on a transit or stub network |
|
544 |
// If we find at least one more router on this channel, we are a transit |
|
545 |
// |
|
546 |
// |
|
547 |
// Now, we have to find the Ipv4 interface whose netdevice is the one we |
|
548 |
// just found. This is still the IP on the local side of the channel. There |
|
549 |
// is a function to do this used down in the guts of the stack, but it's not |
|
550 |
// exported so we had to whip up an equivalent. |
|
551 |
// |
|
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
552 |
uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); |
1278 | 553 |
Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); |
554 |
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); |
|
1505 | 555 |
NS_LOG_LOGIC ("Working with local address " << addrLocal); |
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
|
556 |
uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); |
1278 | 557 |
// |
558 |
// Now, we're going to walk over to the remote net device on the other end of |
|
559 |
// the point-to-point channel we now know we have. This is where our adjacent |
|
560 |
// router (to use OSPF lingo) is running. |
|
561 |
// |
|
562 |
Ptr<Channel> ch = ndLocal->GetChannel(); |
|
563 |
uint32_t nDevices = ch->GetNDevices(); |
|
564 |
if (nDevices == 1) |
|
565 |
{ |
|
566 |
// This is a stub broadcast interface |
|
1505 | 567 |
NS_LOG_LOGIC("Router-LSA stub broadcast link"); |
1278 | 568 |
// XXX in future, need to consider if >1 includes other routers |
569 |
plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); |
|
570 |
// Link ID is IP network number of attached network |
|
571 |
plr->SetLinkId (addrLocal.CombineMask(maskLocal)); |
|
572 |
// Link Data is network mask; convert to Ipv4Address |
|
573 |
Ipv4Address maskLocalAddr; |
|
574 |
maskLocalAddr.Set(maskLocal.GetHostOrder ()); |
|
575 |
plr->SetLinkData (maskLocalAddr); |
|
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
|
576 |
plr->SetMetric (metricLocal); |
1278 | 577 |
pLSA->AddLinkRecord(plr); |
578 |
plr = 0; |
|
579 |
continue; |
|
580 |
} |
|
581 |
else |
|
582 |
{ |
|
1505 | 583 |
NS_LOG_LOGIC ("Router-LSA Broadcast link"); |
1278 | 584 |
// multiple routers on a broadcast interface |
585 |
// lowest IP address is designated router |
|
586 |
plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); |
|
587 |
// Link ID is IP interface address of designated router |
|
588 |
Ipv4Address desigRtr = |
|
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
589 |
FindDesignatedRouterForLink (node, ndLocal); |
1278 | 590 |
if (desigRtr == addrLocal) |
591 |
{ |
|
592 |
listOfDRInterfaces.push_back (ndLocal); |
|
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
593 |
NS_LOG_LOGIC (node->GetId () << " is a DR"); |
1278 | 594 |
} |
595 |
plr->SetLinkId (desigRtr); |
|
596 |
// Link Data is router's own IP address |
|
597 |
plr->SetLinkData (addrLocal); |
|
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
|
598 |
plr->SetMetric (metricLocal); |
1278 | 599 |
pLSA->AddLinkRecord (plr); |
600 |
plr = 0; |
|
601 |
continue; |
|
602 |
} |
|
1111 | 603 |
} |
1278 | 604 |
else if (ndLocal->IsPointToPoint () ) |
605 |
{ |
|
1505 | 606 |
NS_LOG_LOGIC ("Router-LSA Point-to-point device"); |
1111 | 607 |
// |
608 |
// Now, we have to find the Ipv4 interface whose netdevice is the one we |
|
609 |
// just found. This is still the IP on the local side of the channel. There |
|
610 |
// is a function to do this used down in the guts of the stack, but it's not |
|
611 |
// exported so we had to whip up an equivalent. |
|
612 |
// |
|
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
613 |
uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); |
1111 | 614 |
// |
615 |
// Now that we have the Ipv4 interface index, we can get the address and mask |
|
616 |
// we need. |
|
617 |
// |
|
1278 | 618 |
Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); |
619 |
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); |
|
1505 | 620 |
NS_LOG_LOGIC ("Working with local address " << addrLocal); |
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
|
621 |
uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); |
1111 | 622 |
// |
623 |
// Now, we're going to walk over to the remote net device on the other end of |
|
624 |
// the point-to-point channel we now know we have. This is where our adjacent |
|
625 |
// router (to use OSPF lingo) is running. |
|
626 |
// |
|
1278 | 627 |
Ptr<Channel> ch = ndLocal->GetChannel(); |
628 |
Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch); |
|
1111 | 629 |
// |
630 |
// The adjacent net device is aggregated to a node. We need to ask that net |
|
631 |
// device for its node, then ask that node for its Ipv4 interface. |
|
632 |
// |
|
1278 | 633 |
Ptr<Node> nodeRemote = ndRemote->GetNode(); |
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
634 |
Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> (); |
1278 | 635 |
NS_ASSERT_MSG(ipv4Remote, |
636 |
"GlobalRouter::DiscoverLSAs (): QI for remote <Ipv4> failed"); |
|
1111 | 637 |
// |
638 |
// Per the OSPF spec, we're going to need the remote router ID, so we might as |
|
639 |
// well get it now. |
|
640 |
// |
|
1278 | 641 |
Ptr<GlobalRouter> srRemote = |
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
642 |
nodeRemote->GetObject<GlobalRouter> (); |
1278 | 643 |
NS_ASSERT_MSG(srRemote, |
644 |
"GlobalRouter::DiscoverLSAs():QI for remote <GlobalRouter> failed"); |
|
645 |
Ipv4Address rtrIdRemote = srRemote->GetRouterId(); |
|
1505 | 646 |
NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote); |
1111 | 647 |
// |
648 |
// Now, just like we did above, we need to get the IP interface index for the |
|
649 |
// net device on the other end of the point-to-point channel. |
|
650 |
// |
|
1278 | 651 |
uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote); |
1111 | 652 |
// |
653 |
// Now that we have the Ipv4 interface, we can get the (remote) address and |
|
654 |
// mask we need. |
|
655 |
// |
|
1278 | 656 |
Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote); |
657 |
Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote); |
|
1505 | 658 |
NS_LOG_LOGIC ("Working with remote address " << addrRemote); |
1111 | 659 |
// |
660 |
// Now we can fill out the link records for this link. There are always two |
|
661 |
// link records; the first is a point-to-point record describing the link and |
|
662 |
// the second is a stub network record with the network number. |
|
663 |
// |
|
1278 | 664 |
GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; |
665 |
plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint); |
|
666 |
plr->SetLinkId (rtrIdRemote); |
|
667 |
plr->SetLinkData (addrLocal); |
|
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
|
668 |
plr->SetMetric (metricLocal); |
1278 | 669 |
pLSA->AddLinkRecord (plr); |
670 |
plr = 0; |
|
1111 | 671 |
|
1278 | 672 |
plr = new GlobalRoutingLinkRecord; |
673 |
plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); |
|
674 |
plr->SetLinkId (addrRemote); |
|
675 |
plr->SetLinkData (Ipv4Address(maskRemote.GetHostOrder())); // Frown |
|
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
|
676 |
plr->SetMetric (metricLocal); |
1278 | 677 |
pLSA->AddLinkRecord (plr); |
678 |
plr = 0; |
|
679 |
} |
|
680 |
else |
|
681 |
{ |
|
682 |
NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type"); |
|
683 |
} |
|
684 |
||
1111 | 685 |
} |
686 |
// |
|
687 |
// The LSA goes on a list of LSAs in case we want to begin exporting other |
|
688 |
// kinds of advertisements (than Router LSAs). |
|
689 |
m_LSAs.push_back (pLSA); |
|
1505 | 690 |
NS_LOG_LOGIC (*pLSA); |
1278 | 691 |
|
692 |
// Now, determine whether we need to build a NetworkLSA |
|
693 |
if (listOfDRInterfaces.size () > 0) |
|
694 |
{ |
|
695 |
for (std::list<Ptr<NetDevice> >::iterator i = listOfDRInterfaces.begin (); |
|
696 |
i != listOfDRInterfaces.end (); i++) |
|
697 |
{ |
|
698 |
// Build one NetworkLSA for each interface that is a DR |
|
699 |
Ptr<NetDevice> ndLocal = *i; |
|
1881
24285ca5e94f
fix bug 113 on m_node parameter for GlobalRouter
Tom Henderson <tomh@tomh.org>
parents:
1828
diff
changeset
|
700 |
uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); |
1278 | 701 |
Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); |
702 |
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); |
|
703 |
||
704 |
GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; |
|
705 |
pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA); |
|
706 |
pLSA->SetLinkStateId (addrLocal); |
|
707 |
pLSA->SetAdvertisingRouter (m_routerId); |
|
708 |
pLSA->SetNetworkLSANetworkMask (maskLocal); |
|
709 |
pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); |
|
710 |
// Build list of AttachedRouters |
|
711 |
Ptr<Channel> ch = ndLocal->GetChannel(); |
|
712 |
uint32_t nDevices = ch->GetNDevices(); |
|
713 |
NS_ASSERT (nDevices); |
|
714 |
for (uint32_t i = 0; i < nDevices; i++) |
|
715 |
{ |
|
716 |
Ptr<NetDevice> tempNd = ch->GetDevice (i); |
|
717 |
NS_ASSERT (tempNd); |
|
718 |
Ptr<Node> tempNode = tempNd->GetNode (); |
|
719 |
uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd); |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
720 |
Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> (); |
1278 | 721 |
NS_ASSERT (tempIpv4); |
722 |
Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); |
|
723 |
pLSA->AddAttachedRouter (tempAddr); |
|
724 |
} |
|
725 |
m_LSAs.push_back (pLSA); |
|
1505 | 726 |
NS_LOG_LOGIC (*pLSA); |
1278 | 727 |
} |
728 |
} |
|
729 |
||
1111 | 730 |
return m_LSAs.size (); |
731 |
} |
|
732 |
||
1278 | 733 |
Ipv4Address |
734 |
GlobalRouter::FindDesignatedRouterForLink (Ptr<Node> node, |
|
735 |
Ptr<NetDevice> ndLocal) const |
|
736 |
{ |
|
737 |
uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
738 |
Ptr<Ipv4> ipv4Local = GetObject<Ipv4> (); |
1278 | 739 |
NS_ASSERT (ipv4Local); |
740 |
Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); |
|
741 |
Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); |
|
742 |
||
743 |
Ptr<Channel> ch = ndLocal->GetChannel(); |
|
744 |
uint32_t nDevices = ch->GetNDevices(); |
|
745 |
NS_ASSERT (nDevices); |
|
746 |
Ipv4Address lowest = addrLocal; |
|
747 |
// iterate all NetDevices and return the lowest numbered IP address |
|
748 |
for (uint32_t i = 0; i < nDevices; i++) |
|
749 |
{ |
|
750 |
Ptr<NetDevice> tempNd = ch->GetDevice (i); |
|
751 |
NS_ASSERT (tempNd); |
|
752 |
Ptr<Node> tempNode = tempNd->GetNode (); |
|
753 |
uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd); |
|
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
754 |
Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> (); |
1278 | 755 |
NS_ASSERT (tempIpv4); |
756 |
Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); |
|
757 |
if (tempAddr < addrLocal) |
|
758 |
{ |
|
759 |
addrLocal = tempAddr; |
|
760 |
} |
|
761 |
} |
|
762 |
return addrLocal; |
|
763 |
} |
|
764 |
||
1111 | 765 |
uint32_t |
766 |
GlobalRouter::GetNumLSAs (void) const |
|
767 |
{ |
|
1505 | 768 |
NS_LOG_FUNCTION; |
1111 | 769 |
return m_LSAs.size (); |
770 |
} |
|
771 |
||
772 |
// |
|
773 |
// Get the nth link state advertisement from this router. |
|
774 |
// |
|
775 |
bool |
|
1278 | 776 |
GlobalRouter::GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const |
1111 | 777 |
{ |
1505 | 778 |
NS_LOG_FUNCTION; |
1111 | 779 |
NS_ASSERT_MSG(lsa.IsEmpty(), "GlobalRouter::GetLSA (): Must pass empty LSA"); |
780 |
// |
|
781 |
// All of the work was done in GetNumLSAs. All we have to do here is to |
|
782 |
// walk the list of link state advertisements created there and return the |
|
783 |
// one the client is interested in. |
|
784 |
// |
|
785 |
ListOfLSAs_t::const_iterator i = m_LSAs.begin (); |
|
786 |
uint32_t j = 0; |
|
787 |
||
788 |
for (; i != m_LSAs.end (); i++, j++) |
|
789 |
{ |
|
790 |
if (j == n) |
|
791 |
{ |
|
1278 | 792 |
GlobalRoutingLSA *p = *i; |
1111 | 793 |
lsa = *p; |
794 |
return true; |
|
795 |
} |
|
796 |
} |
|
797 |
||
798 |
return false; |
|
799 |
} |
|
800 |
||
801 |
// |
|
802 |
// Link through the given channel and find the net device that's on the |
|
803 |
// other end. This only makes sense with a point-to-point channel. |
|
804 |
// |
|
805 |
Ptr<NetDevice> |
|
806 |
GlobalRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const |
|
807 |
{ |
|
1505 | 808 |
NS_LOG_FUNCTION; |
1123
f7a27e1a6744
fix optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1121
diff
changeset
|
809 |
NS_ASSERT_MSG(ch->GetNDevices() == 2, |
1111 | 810 |
"GlobalRouter::GetAdjacent (): Channel with other than two devices"); |
811 |
// |
|
812 |
// This is a point to point channel with two endpoints. Get both of them. |
|
813 |
// |
|
814 |
Ptr<NetDevice> nd1 = ch->GetDevice(0); |
|
815 |
Ptr<NetDevice> nd2 = ch->GetDevice(1); |
|
816 |
// |
|
817 |
// One of the endpoints is going to be "us" -- that is the net device attached |
|
818 |
// to the node on which we're running -- i.e., "nd". The other endpoint (the |
|
819 |
// one to which we are connected via the channel) is the adjacent router. |
|
820 |
// |
|
821 |
if (nd1 == nd) |
|
822 |
{ |
|
823 |
return nd2; |
|
824 |
} |
|
825 |
else if (nd2 == nd) |
|
826 |
{ |
|
827 |
return nd1; |
|
828 |
} |
|
829 |
else |
|
830 |
{ |
|
831 |
NS_ASSERT_MSG(false, |
|
832 |
"GlobalRouter::GetAdjacent (): Wrong or confused channel?"); |
|
833 |
return 0; |
|
834 |
} |
|
835 |
} |
|
836 |
||
837 |
// |
|
838 |
// Given a node and a net device, find the IPV4 interface index that |
|
839 |
// corresponds to that net device. |
|
840 |
// |
|
841 |
uint32_t |
|
842 |
GlobalRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const |
|
843 |
{ |
|
1505 | 844 |
NS_LOG_FUNCTION; |
2257
71a58e70c671
QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2252
diff
changeset
|
845 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1111 | 846 |
NS_ASSERT_MSG(ipv4, "QI for <Ipv4> interface failed"); |
847 |
for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i ) |
|
848 |
{ |
|
849 |
if (ipv4->GetNetDevice(i) == nd) |
|
850 |
{ |
|
851 |
return i; |
|
852 |
} |
|
853 |
} |
|
854 |
||
855 |
NS_ASSERT_MSG(0, "Cannot find interface for device"); |
|
856 |
return 0; |
|
857 |
} |
|
858 |
||
859 |
} // namespace ns3 |