Lines 243-248
SPFVertex::IsVertexProcessed (void) cons
|
Link Here
|
---|
|
243 |
return m_vertexProcessed; |
243 |
return m_vertexProcessed; |
244 |
} |
244 |
} |
245 |
|
245 |
|
|
|
246 |
void |
247 |
SPFVertex::ClearVertexProcessed (void) |
248 |
{ |
249 |
for (uint32_t i = 0; i < this->GetNChildren (); i++) |
250 |
{ |
251 |
this->GetChild (i)->ClearVertexProcessed (); |
252 |
} |
253 |
this->SetVertexProcessed (false); |
254 |
} |
246 |
|
255 |
|
247 |
// --------------------------------------------------------------------------- |
256 |
// --------------------------------------------------------------------------- |
248 |
// |
257 |
// |
Lines 252-258
SPFVertex::IsVertexProcessed (void) cons
|
Link Here
|
---|
|
252 |
|
261 |
|
253 |
GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () |
262 |
GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () |
254 |
: |
263 |
: |
255 |
m_database () |
264 |
m_database (), |
|
|
265 |
m_extdatabase () |
256 |
{ |
266 |
{ |
257 |
NS_LOG_FUNCTION_NOARGS (); |
267 |
NS_LOG_FUNCTION_NOARGS (); |
258 |
} |
268 |
} |
Lines 265-270
GlobalRouteManagerLSDB::~GlobalRouteMana
|
Link Here
|
---|
|
265 |
{ |
275 |
{ |
266 |
NS_LOG_LOGIC ("free LSA"); |
276 |
NS_LOG_LOGIC ("free LSA"); |
267 |
GlobalRoutingLSA* temp = i->second; |
277 |
GlobalRoutingLSA* temp = i->second; |
|
|
278 |
delete temp; |
279 |
} |
280 |
for (uint32_t j=0; j<m_extdatabase.size (); j++) |
281 |
{ |
282 |
NS_LOG_LOGIC ("free ASexternalLSA"); |
283 |
GlobalRoutingLSA* temp = m_extdatabase.at (j); |
268 |
delete temp; |
284 |
delete temp; |
269 |
} |
285 |
} |
270 |
NS_LOG_LOGIC ("clear map"); |
286 |
NS_LOG_LOGIC ("clear map"); |
Lines 287-293
GlobalRouteManagerLSDB::Insert (Ipv4Addr
|
Link Here
|
---|
|
287 |
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa) |
303 |
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa) |
288 |
{ |
304 |
{ |
289 |
NS_LOG_FUNCTION (addr << lsa); |
305 |
NS_LOG_FUNCTION (addr << lsa); |
290 |
m_database.insert (LSDBPair_t (addr, lsa)); |
306 |
if (lsa->GetLSType() == GlobalRoutingLSA::ASExternalLSAs) { |
|
|
307 |
m_extdatabase.push_back (lsa); |
308 |
} else |
309 |
{ |
310 |
m_database.insert (LSDBPair_t (addr, lsa)); |
311 |
} |
312 |
} |
313 |
|
314 |
GlobalRoutingLSA* |
315 |
GlobalRouteManagerLSDB::GetExtLSA (uint32_t index) const |
316 |
{ |
317 |
return m_extdatabase.at (index); |
318 |
} |
319 |
|
320 |
uint32_t |
321 |
GlobalRouteManagerLSDB::GetNumExtLSAs () const |
322 |
{ |
323 |
return m_extdatabase.size (); |
291 |
} |
324 |
} |
292 |
|
325 |
|
293 |
GlobalRoutingLSA* |
326 |
GlobalRoutingLSA* |
Lines 438-443
GlobalRouteManagerImpl::BuildGlobalRouti
|
Link Here
|
---|
|
438 |
// DiscoverLSAs () will get zero as the number since no routes have been |
471 |
// DiscoverLSAs () will get zero as the number since no routes have been |
439 |
// found. |
472 |
// found. |
440 |
// |
473 |
// |
|
|
474 |
Ptr<Ipv4GlobalRouting> grouting = rtr->GetRoutingProtocol (); |
441 |
uint32_t numLSAs = rtr->DiscoverLSAs (); |
475 |
uint32_t numLSAs = rtr->DiscoverLSAs (); |
442 |
NS_LOG_LOGIC ("Found " << numLSAs << " LSAs"); |
476 |
NS_LOG_LOGIC ("Found " << numLSAs << " LSAs"); |
443 |
|
477 |
|
Lines 824-830
GlobalRouteManagerImpl::SPFNexthopCalcul
|
Link Here
|
---|
|
824 |
" via outgoing interface " << w->GetOutgoingInterfaceId () << |
858 |
" via outgoing interface " << w->GetOutgoingInterfaceId () << |
825 |
" with distance " << distance); |
859 |
" with distance " << distance); |
826 |
} // end W is a router vertes |
860 |
} // end W is a router vertes |
827 |
else |
861 |
else |
828 |
{ |
862 |
{ |
829 |
NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork); |
863 |
NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork); |
830 |
// W is a directly connected network; no next hop is required |
864 |
// W is a directly connected network; no next hop is required |
Lines 1237-1242
GlobalRouteManagerImpl::SPFCalculate (Ip
|
Link Here
|
---|
|
1237 |
|
1271 |
|
1238 |
// Second stage of SPF calculation procedure |
1272 |
// Second stage of SPF calculation procedure |
1239 |
SPFProcessStubs (m_spfroot); |
1273 |
SPFProcessStubs (m_spfroot); |
|
|
1274 |
for (uint32_t i = 0;i<m_lsdb->GetNumExtLSAs ();i++) |
1275 |
{ |
1276 |
m_spfroot->ClearVertexProcessed (); |
1277 |
GlobalRoutingLSA *extlsa = m_lsdb->GetExtLSA (i); |
1278 |
NS_LOG_LOGIC ("Processing External LSA with id " << extlsa->GetLinkStateId ()); |
1279 |
ProcessASExternals (m_spfroot, extlsa); |
1280 |
} |
1281 |
|
1240 |
// |
1282 |
// |
1241 |
// We're all done setting the routing information for the node at the root of |
1283 |
// We're all done setting the routing information for the node at the root of |
1242 |
// the SPF tree. Delete all of the vertices and corresponding resources. Go |
1284 |
// the SPF tree. Delete all of the vertices and corresponding resources. Go |
Lines 1245-1250
GlobalRouteManagerImpl::SPFCalculate (Ip
|
Link Here
|
---|
|
1245 |
delete m_spfroot; |
1287 |
delete m_spfroot; |
1246 |
m_spfroot = 0; |
1288 |
m_spfroot = 0; |
1247 |
} |
1289 |
} |
|
|
1290 |
|
1291 |
void |
1292 |
GlobalRouteManagerImpl::ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa) |
1293 |
{ |
1294 |
NS_LOG_FUNCTION_NOARGS (); |
1295 |
NS_LOG_LOGIC ("Processing external for destination " << |
1296 |
extlsa->GetLinkStateId () << |
1297 |
", for router " << v->GetVertexId () << |
1298 |
", advertised by " << extlsa->GetAdvertisingRouter ()); |
1299 |
if (v->GetVertexType () == SPFVertex::VertexRouter) |
1300 |
{ |
1301 |
GlobalRoutingLSA *rlsa = v->GetLSA (); |
1302 |
NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ()); |
1303 |
if ((rlsa->GetLinkStateId ()) == (extlsa->GetAdvertisingRouter ())) |
1304 |
{ |
1305 |
NS_LOG_LOGIC ("Found advertising router to destination"); |
1306 |
SPFAddASExternal(extlsa,v); |
1307 |
} |
1308 |
} |
1309 |
for (uint32_t i = 0; i < v->GetNChildren (); i++) |
1310 |
{ |
1311 |
if (!v->GetChild (i)->IsVertexProcessed ()) |
1312 |
{ |
1313 |
NS_LOG_LOGIC ("Vertex's child " << i << " not yet processed, processing..."); |
1314 |
ProcessASExternals (v->GetChild (i), extlsa); |
1315 |
v->GetChild (i)->SetVertexProcessed (true); |
1316 |
} |
1317 |
} |
1318 |
} |
1319 |
|
1320 |
// |
1321 |
// Adding external routes to routing table - modeled after |
1322 |
// SPFAddIntraAddStub() |
1323 |
// |
1324 |
|
1325 |
void |
1326 |
GlobalRouteManagerImpl::SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v) |
1327 |
{ |
1328 |
NS_LOG_FUNCTION_NOARGS (); |
1329 |
|
1330 |
NS_ASSERT_MSG (m_spfroot, |
1331 |
"GlobalRouteManagerImpl::SPFAddASExternal (): Root pointer not set"); |
1332 |
// Two cases to consider: We are advertising the external ourselves |
1333 |
// => No need to add anything |
1334 |
// OR find best path to the advertising router |
1335 |
if (v->GetVertexId () == m_spfroot->GetVertexId ()) |
1336 |
{ |
1337 |
NS_LOG_LOGIC ("External is on local host: " |
1338 |
<< v->GetVertexId () << "; returning"); |
1339 |
return; |
1340 |
} |
1341 |
NS_LOG_LOGIC ("External is on remote host: " |
1342 |
<< extlsa->GetAdvertisingRouter () << "; installing"); |
1343 |
|
1344 |
Ipv4Address routerId = m_spfroot->GetVertexId (); |
1345 |
|
1346 |
NS_LOG_LOGIC ("Vertex ID = " << routerId); |
1347 |
// |
1348 |
// We need to walk the list of nodes looking for the one that has the router |
1349 |
// ID corresponding to the root vertex. This is the one we're going to write |
1350 |
// the routing information to. |
1351 |
// |
1352 |
NodeList::Iterator i = NodeList::Begin (); |
1353 |
for (; i != NodeList::End (); i++) |
1354 |
{ |
1355 |
Ptr<Node> node = *i; |
1356 |
// |
1357 |
// The router ID is accessible through the GlobalRouter interface, so we need |
1358 |
// to QI for that interface. If there's no GlobalRouter interface, the node |
1359 |
// in question cannot be the router we want, so we continue. |
1360 |
// |
1361 |
Ptr<GlobalRouter> rtr = |
1362 |
node->GetObject<GlobalRouter> (); |
1363 |
|
1364 |
if (rtr == 0) |
1365 |
{ |
1366 |
NS_LOG_LOGIC ("No GlobalRouter interface on node " << |
1367 |
node->GetId ()); |
1368 |
continue; |
1369 |
} |
1370 |
// |
1371 |
// If the router ID of the current node is equal to the router ID of the |
1372 |
// root of the SPF tree, then this node is the one for which we need to |
1373 |
// write the routing tables. |
1374 |
// |
1375 |
NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); |
1376 |
|
1377 |
if (rtr->GetRouterId () == routerId) |
1378 |
{ |
1379 |
NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); |
1380 |
// |
1381 |
// Routing information is updated using the Ipv4 interface. We need to QI |
1382 |
// for that interface. If the node is acting as an IP version 4 router, it |
1383 |
// should absolutely have an Ipv4 interface. |
1384 |
// |
1385 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1386 |
NS_ASSERT_MSG (ipv4, |
1387 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
1388 |
"QI for <Ipv4> interface failed"); |
1389 |
// |
1390 |
// Get the Global Router Link State Advertisement from the vertex we're |
1391 |
// adding the routes to. The LSA will have a number of attached Global Router |
1392 |
// Link Records corresponding to links off of that vertex / node. We're going |
1393 |
// to be interested in the records corresponding to point-to-point links. |
1394 |
// |
1395 |
NS_ASSERT_MSG (v->GetLSA (), |
1396 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
1397 |
"Expected valid LSA in SPFVertex* v"); |
1398 |
Ipv4Mask tempmask = extlsa->GetNetworkLSANetworkMask(); |
1399 |
Ipv4Address tempip = extlsa->GetLinkStateId (); |
1400 |
tempip = tempip.CombineMask (tempmask); |
1401 |
|
1402 |
NS_LOG_LOGIC (" Node " << node->GetId () << |
1403 |
" add route to " << tempip << |
1404 |
" with mask " << tempmask << |
1405 |
" using next hop " << v->GetNextHop () << |
1406 |
" via interface " << v->GetOutgoingInterfaceId ()); |
1407 |
// |
1408 |
// Here's why we did all of that work. We're going to add a host route to the |
1409 |
// host address found in the m_linkData field of the point-to-point link |
1410 |
// record. In the case of a point-to-point link, this is the local IP address |
1411 |
// of the node connected to the link. Each of these point-to-point links |
1412 |
// will correspond to a local interface that has an IP address to which |
1413 |
// the node at the root of the SPF tree can send packets. The vertex <v> |
1414 |
// (corresponding to the node that has these links and interfaces) has |
1415 |
// an m_nextHop address precalculated for us that is the address to which the |
1416 |
// root node should send packets to be forwarded to these IP addresses. |
1417 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
1418 |
// which the packets should be send for forwarding. |
1419 |
// |
1420 |
Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> (); |
1421 |
if (router == 0) |
1422 |
{ |
1423 |
continue; |
1424 |
} |
1425 |
Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol (); |
1426 |
NS_ASSERT (gr); |
1427 |
if (v->GetOutgoingInterfaceId () >= 0) |
1428 |
{ |
1429 |
gr->AddASExternalRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingInterfaceId ()); |
1430 |
NS_LOG_LOGIC ("Node " << node->GetId () << |
1431 |
" add network route to " << tempip << |
1432 |
" using next hop " << v->GetNextHop () << |
1433 |
" via interface " << v->GetOutgoingInterfaceId ()); |
1434 |
} |
1435 |
else |
1436 |
{ |
1437 |
NS_LOG_LOGIC ("Node " << node->GetId () << |
1438 |
" NOT able to add network route to " << tempip << |
1439 |
" using next hop " << v->GetNextHop () << |
1440 |
" since outgoing interface id is negative"); |
1441 |
} |
1442 |
return; |
1443 |
} // if |
1444 |
} // for |
1445 |
} |
1446 |
|
1248 |
|
1447 |
|
1249 |
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs () |
1448 |
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs () |
1250 |
// stub link records will exist for point-to-point interfaces and for |
1449 |
// stub link records will exist for point-to-point interfaces and for |