OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright 2007 University of Washington | 3 * Copyright 2007 University of Washington |
4 * Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada | 4 * Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada |
5 *· | 5 *· |
6 * This program is free software; you can redistribute it and/or modify | 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 | 7 * it under the terms of the GNU General Public License version 2 as |
8 * published by the Free Software Foundation; | 8 * published by the Free Software Foundation; |
9 * | 9 * |
10 * This program is distributed in the hope that it will be useful, | 10 * This program is distributed in the hope that it will be useful, |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 #include <utility> | 25 #include <utility> |
26 #include <vector> | 26 #include <vector> |
27 #include <queue> | 27 #include <queue> |
28 #include "ns3/assert.h" | 28 #include "ns3/assert.h" |
29 #include "ns3/fatal-error.h" | 29 #include "ns3/fatal-error.h" |
30 #include "ns3/log.h" | 30 #include "ns3/log.h" |
31 #include "ns3/node-list.h" | 31 #include "ns3/node-list.h" |
32 #include "ns3/ipv4.h" | 32 #include "ns3/ipv4.h" |
33 #include "ns3/ipv4-global-routing.h" | 33 #include "ns3/ipv4-global-routing.h" |
| 34 #include "ns3/ipv4-routing-protocol.h" |
| 35 #include "ns3/ipv4-list-routing.h" |
34 #include "global-router-interface.h" | 36 #include "global-router-interface.h" |
35 #include "global-route-manager-impl.h" | 37 #include "global-route-manager-impl.h" |
36 #include "candidate-queue.h" | 38 #include "candidate-queue.h" |
37 | 39 |
38 NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager"); | 40 NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager"); |
39 | 41 |
40 namespace ns3 { | 42 namespace ns3 { |
41 | 43 |
42 // --------------------------------------------------------------------------- | 44 // --------------------------------------------------------------------------- |
43 // | 45 // |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 149 } |
148 | 150 |
149 uint32_t | 151 uint32_t |
150 SPFVertex::GetDistanceFromRoot (void) const | 152 SPFVertex::GetDistanceFromRoot (void) const |
151 { | 153 { |
152 NS_LOG_FUNCTION_NOARGS (); | 154 NS_LOG_FUNCTION_NOARGS (); |
153 return m_distanceFromRoot; | 155 return m_distanceFromRoot; |
154 } | 156 } |
155 | 157 |
156 void· | 158 void· |
157 SPFVertex::SetOutgoingInterfaceId (uint32_t id) | 159 SPFVertex::SetOutgoingInterfaceId (int32_t id) |
158 { | 160 { |
159 NS_LOG_FUNCTION (id); | 161 NS_LOG_FUNCTION (id); |
160 m_rootOif = id; | 162 m_rootOif = id; |
161 } | 163 } |
162 | 164 |
163 uint32_t· | 165 uint32_t· |
164 SPFVertex::GetOutgoingInterfaceId (void) const | 166 SPFVertex::GetOutgoingInterfaceId (void) const |
165 { | 167 { |
166 NS_LOG_FUNCTION_NOARGS (); | 168 NS_LOG_FUNCTION_NOARGS (); |
167 return m_rootOif; | 169 return m_rootOif; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) | 409 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
408 { | 410 { |
409 Ptr<Node> node = *i; | 411 Ptr<Node> node = *i; |
410 NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ()); | 412 NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ()); |
411 | 413 |
412 Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); | 414 Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); |
413 node->AggregateObject (globalRouter); | 415 node->AggregateObject (globalRouter); |
414 | 416 |
415 NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); | 417 NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); |
416 Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); | 418 Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); |
| 419 globalRouting->SetNode (node); |
| 420 // Here, we check whether there is an existing Ipv4RoutingProtocol object |
| 421 // to add this protocol to. |
| 422 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 423 NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): GetObj
ect for <Ipv4> interface failed"); |
| 424 // Now, we add this to an Ipv4ListRouting object.·· |
| 425 // XXX in the future, we may want to allow this to be added to Ipv4 |
| 426 // directly |
| 427 Ptr<Ipv4ListRouting> ipv4ListRouting = DynamicCast<Ipv4ListRouting> (ipv4-
>GetRoutingProtocol ()); |
| 428 NS_ASSERT_MSG (ipv4ListRouting, "GlobalRouteManagerImpl::SelectRouterNodes
(): Ipv4ListRouting not found");· |
417 // This is the object that will keep the global routes. We insert it | 429 // This is the object that will keep the global routes. We insert it |
418 // at slightly higher priority than static routing (which is at zero). | 430 // at slightly higher priority than static routing (which is at zero). |
419 // This means that global routes (e.g. host routes) will be consulted | 431 // This means that global routes (e.g. host routes) will be consulted |
420 // before static routes | 432 // before static routes |
421 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); | |
422 NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): " | |
423 "GetObject for <Ipv4> interface failed"); | |
424 // XXX make the below priority value an attribute | 433 // XXX make the below priority value an attribute |
425 ipv4->AddRoutingProtocol (globalRouting, 3);·· | 434 ipv4ListRouting->AddRoutingProtocol (globalRouting, 3);·· |
426 // Locally cache the globalRouting pointer; we'll need it later | 435 // Locally cache the globalRouting pointer; we'll need it later |
427 // when we add routes | 436 // when we add routes |
428 AddGlobalRoutingProtocol (node->GetId (), globalRouting); | 437 AddGlobalRoutingProtocol (node->GetId (), globalRouting); |
429 } | 438 } |
430 } | 439 } |
431 | 440 |
432 void | 441 void |
433 GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c)· | 442 GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c)· |
434 { | 443 { |
435 NS_LOG_FUNCTION (&c); | 444 NS_LOG_FUNCTION (&c); |
436 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) | 445 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) |
437 { | 446 { |
438 Ptr<Node> node = *i; | 447 Ptr<Node> node = *i; |
439 NS_LOG_LOGIC ("Adding GlobalRouter interface to node " <<· | 448 NS_LOG_LOGIC ("Adding GlobalRouter interface to node " <<· |
440 node->GetId ()); | 449 node->GetId ()); |
441 | 450 |
442 Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); | 451 Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); |
443 node->AggregateObject (globalRouter); | 452 node->AggregateObject (globalRouter); |
444 | 453 |
445 NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); | 454 NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); |
446 Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); | 455 Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); |
447 // This is the object that will keep the global routes. We insert it | 456 // This is the object that will keep the global routes. We insert it |
448 // at slightly higher priority than static routing (which is at zero). | 457 // at slightly higher priority than static routing (which is at zero). |
449 // This means that global routes (e.g. host routes) will be consulted | 458 // This means that global routes (e.g. host routes) will be consulted |
450 // before static routes | 459 // before static routes |
451 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); | 460 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
452 NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): " | 461 NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): " |
453 "GetObject for <Ipv4> interface failed"); | 462 "GetObject for <Ipv4> interface failed"); |
| 463 Ptr<Ipv4ListRouting> ipv4ListRouting = DynamicCast<Ipv4ListRouting> (ipv4-
>GetRoutingProtocol ()); |
| 464 NS_ASSERT_MSG (ipv4ListRouting, "GlobalRouteManagerImpl::SelectRouterNodes
(): Ipv4ListRouting not found");· |
454 // XXX make the below priority value an attribute | 465 // XXX make the below priority value an attribute |
455 ipv4->AddRoutingProtocol (globalRouting, 3);·· | 466 ipv4ListRouting->AddRoutingProtocol (globalRouting, 3);·· |
456 // Locally cache the globalRouting pointer; we'll need it later | 467 // Locally cache the globalRouting pointer; we'll need it later |
457 // when we add routes | 468 // when we add routes |
458 AddGlobalRoutingProtocol (node->GetId (), globalRouting); | 469 AddGlobalRoutingProtocol (node->GetId (), globalRouting); |
459 } | 470 } |
460 } | 471 } |
461 | 472 |
462 // | 473 // |
463 // In order to build the routing database, we need to walk the list of nodes | 474 // 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. | 475 // in the system and look for those that support the GlobalRouter interface. |
465 // These routers will export a number of Link State Advertisements (LSAs) | 476 // These routers will export a number of Link State Advertisements (LSAs) |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 // will correspond to a local interface that has an IP address to which | 1348 // will correspond to a local interface that has an IP address to which |
1338 // the node at the root of the SPF tree can send packets. The vertex <v>· | 1349 // the node at the root of the SPF tree can send packets. The vertex <v>· |
1339 // (corresponding to the node that has these links and interfaces) has· | 1350 // (corresponding to the node that has these links and interfaces) has· |
1340 // an m_nextHop address precalculated for us that is the address to which the | 1351 // an m_nextHop address precalculated for us that is the address to which the |
1341 // root node should send packets to be forwarded to these IP addresses. | 1352 // root node should send packets to be forwarded to these IP addresses. |
1342 // Similarly, the vertex <v> has an m_rootOif (outbound interface index) to | 1353 // Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
1343 // which the packets should be send for forwarding. | 1354 // which the packets should be send for forwarding. |
1344 // | 1355 // |
1345 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); | 1356 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
1346 NS_ASSERT (gr); | 1357 NS_ASSERT (gr); |
1347 gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgo
ingInterfaceId ()); | 1358 if (v->GetOutgoingInterfaceId () >= 0) |
| 1359 { |
| 1360 gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), v->GetO
utgoingInterfaceId ()); |
| 1361 NS_LOG_LOGIC ("Node " << node->GetId () << |
| 1362 " add network route to " << tempip << |
| 1363 " using next hop " << v->GetNextHop () << |
| 1364 " via interface " << v->GetOutgoingInterfaceId ()); |
| 1365 } |
| 1366 else |
| 1367 { |
| 1368 NS_LOG_LOGIC ("Node " << node->GetId () << |
| 1369 " NOT able to add network route to " << tempip << |
| 1370 " using next hop " << v->GetNextHop () << |
| 1371 " since outgoing interface id is negative"); |
| 1372 } |
1348 return; | 1373 return; |
1349 } // if | 1374 } // if |
1350 } // for | 1375 } // for |
1351 } | 1376 } |
1352 | 1377 |
1353 // | 1378 // |
1354 // Return the interface index corresponding to a given IP address | 1379 // Return the interface number corresponding to a given IP address and mask |
1355 // This is a wrapper around GetInterfaceByIpv4Address(), but we first | 1380 // This is a wrapper around GetInterfaceForPrefix(), but we first |
1356 // have to find the right node pointer to pass to that function. | 1381 // have to find the right node pointer to pass to that function. |
| 1382 // If no such interface is found, return -1 (note: unit test framework |
| 1383 // for routing assumes -1 to be a legal return value) |
1357 // | 1384 // |
1358 uint32_t | 1385 uint32_t |
1359 GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) | 1386 GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) |
1360 { | 1387 { |
1361 NS_LOG_FUNCTION (a << amask); | 1388 NS_LOG_FUNCTION (a << amask); |
1362 // | 1389 // |
1363 // We have an IP address <a> and a vertex ID of the root of the SPF tree.·· | 1390 // 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. | 1391 // 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 | 1392 // 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 | 1393 // the node corresponding to the vertex ID, find the Ipv4 interface on that |
(...skipping 26 matching lines...) Expand all Loading... |
1393 { | 1420 { |
1394 // | 1421 // |
1395 // This is the node we're building the routing table for. We're going to need | 1422 // 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 | 1423 // 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· | 1424 // is participating in routing IP version 4 packets, it certainly must have· |
1398 // an Ipv4 interface. | 1425 // an Ipv4 interface. |
1399 // | 1426 // |
1400 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); | 1427 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1401 NS_ASSERT_MSG (ipv4,· | 1428 NS_ASSERT_MSG (ipv4,· |
1402 "GlobalRouteManagerImpl::FindOutgoingInterfaceId (): " | 1429 "GlobalRouteManagerImpl::FindOutgoingInterfaceId (): " |
1403 "QI for <Ipv4> interface failed"); | 1430 "GetObject for <Ipv4> interface failed"); |
1404 // | 1431 // |
1405 // Look through the interfaces on this node for one that has the IP address | 1432 // 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 | 1433 // we're looking for. If we find one, return the corresponding interface |
1407 // index. | 1434 // index, or -1 if not found. |
1408 // | 1435 // |
1409 return (ipv4->GetInterfaceByAddress (a, amask) ); | 1436 int32_t interface = ipv4->GetInterfaceForPrefix (a, amask); |
| 1437 |
| 1438 #if 0 |
| 1439 if (interface < 0) |
| 1440 { |
| 1441 NS_FATAL_ERROR ("GlobalRouteManagerImpl::FindOutgoingInterfaceId()
: " |
| 1442 "Expected an interface associated with address a:" << a); |
| 1443 } |
| 1444 #endif· |
| 1445 return interface; |
1410 } | 1446 } |
1411 } | 1447 } |
1412 // | 1448 // |
1413 // Couldn't find it. | 1449 // Couldn't find it. |
1414 // | 1450 // |
1415 return 0; | 1451 NS_LOG_LOGIC ("FindOutgoingInterfaceId():Can't find root node " << routerId); |
| 1452 return -1; |
1416 } | 1453 } |
1417 | 1454 |
1418 // | 1455 // |
1419 // This method is derived from quagga ospf_intra_add_router () | 1456 // This method is derived from quagga ospf_intra_add_router () |
1420 // | 1457 // |
1421 // This is where we are actually going to add the host routes to the routing | 1458 // This is where we are actually going to add the host routes to the routing |
1422 // tables of the individual nodes. | 1459 // tables of the individual nodes. |
1423 // | 1460 // |
1424 // The vertex passed as a parameter has just been added to the SPF tree. | 1461 // 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 | 1462 // This vertex must have a valid m_root_oid, corresponding to the outgoing |
(...skipping 26 matching lines...) Expand all Loading... |
1452 // We need to walk the list of nodes looking for the one that has the router | 1489 // 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 | 1490 // ID corresponding to the root vertex. This is the one we're going to write |
1454 // the routing information to. | 1491 // the routing information to. |
1455 // | 1492 // |
1456 NodeList::Iterator i = NodeList::Begin ();· | 1493 NodeList::Iterator i = NodeList::Begin ();· |
1457 for (; i != NodeList::End (); i++) | 1494 for (; i != NodeList::End (); i++) |
1458 { | 1495 { |
1459 Ptr<Node> node = *i; | 1496 Ptr<Node> node = *i; |
1460 // | 1497 // |
1461 // The router ID is accessible through the GlobalRouter interface, so we need | 1498 // 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 | 1499 // to GetObject for that interface. If there's no GlobalRouter interface, |
1463 // in question cannot be the router we want, so we continue. | 1500 // the node in question cannot be the router we want, so we continue. |
1464 //· | 1501 //· |
1465 Ptr<GlobalRouter> rtr =· | 1502 Ptr<GlobalRouter> rtr =· |
1466 node->GetObject<GlobalRouter> (); | 1503 node->GetObject<GlobalRouter> (); |
1467 | 1504 |
1468 if (rtr == 0) | 1505 if (rtr == 0) |
1469 { | 1506 { |
1470 NS_LOG_LOGIC ("No GlobalRouter interface on node " <<· | 1507 NS_LOG_LOGIC ("No GlobalRouter interface on node " <<· |
1471 node->GetId ()); | 1508 node->GetId ()); |
1472 continue; | 1509 continue; |
1473 } | 1510 } |
1474 // | 1511 // |
1475 // If the router ID of the current node is equal to the router ID of the· | 1512 // 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· | 1513 // root of the SPF tree, then this node is the one for which we need to· |
1477 // write the routing tables. | 1514 // write the routing tables. |
1478 // | 1515 // |
1479 NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); | 1516 NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); |
1480 | 1517 |
1481 if (rtr->GetRouterId () == routerId) | 1518 if (rtr->GetRouterId () == routerId) |
1482 { | 1519 { |
1483 NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); | 1520 NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); |
1484 // | 1521 // |
1485 // Routing information is updated using the Ipv4 interface. We need to QI | 1522 // Routing information is updated using the Ipv4 interface. We need to· |
1486 // for that interface. If the node is acting as an IP version 4 router, it | 1523 // GetObject for that interface. If the node is acting as an IP version 4 |
1487 // should absolutely have an Ipv4 interface. | 1524 // router, it should absolutely have an Ipv4 interface. |
1488 // | 1525 // |
1489 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); | 1526 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1490 NS_ASSERT_MSG (ipv4,· | 1527 NS_ASSERT_MSG (ipv4,· |
1491 "GlobalRouteManagerImpl::SPFIntraAddRouter (): " | 1528 "GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
1492 "QI for <Ipv4> interface failed"); | 1529 "GetObject for <Ipv4> interface failed"); |
1493 // | 1530 // |
1494 // Get the Global Router Link State Advertisement from the vertex we're | 1531 // 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 | 1532 // 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 | 1533 // 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. | 1534 // to be interested in the records corresponding to point-to-point links. |
1498 // | 1535 // |
1499 GlobalRoutingLSA *lsa = v->GetLSA (); | 1536 GlobalRoutingLSA *lsa = v->GetLSA (); |
1500 NS_ASSERT_MSG (lsa,· | 1537 NS_ASSERT_MSG (lsa,· |
1501 "GlobalRouteManagerImpl::SPFIntraAddRouter (): " | 1538 "GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
1502 "Expected valid LSA in SPFVertex* v"); | 1539 "Expected valid LSA in SPFVertex* v"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 // will correspond to a local interface that has an IP address to which | 1572 // 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>· | 1573 // 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· | 1574 // (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 | 1575 // 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. | 1576 // 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 | 1577 // Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
1541 // which the packets should be send for forwarding. | 1578 // which the packets should be send for forwarding. |
1542 // | 1579 // |
1543 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId
()); | 1580 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId
()); |
1544 NS_ASSERT (gr); | 1581 NS_ASSERT (gr); |
1545 gr->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (), | 1582 if (v->GetOutgoingInterfaceId () >= 0) |
1546 v->GetOutgoingInterfaceId ()); | 1583 { |
| 1584 gr->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (), |
| 1585 v->GetOutgoingInterfaceId ()); |
| 1586 NS_LOG_LOGIC ("Node " << node->GetId () << |
| 1587 " adding host route to " << lr->GetLinkData () << |
| 1588 " using next hop " << v->GetNextHop () << |
| 1589 " and outgoing interface " << v->GetOutgoingInterfaceId ()); |
| 1590 } |
| 1591 else |
| 1592 { |
| 1593 NS_LOG_LOGIC ("Node " << node->GetId () << |
| 1594 " NOT able to add host route to " << lr->GetLinkData () << |
| 1595 " using next hop " << v->GetNextHop () << |
| 1596 " since outgoing interface id is negative"); |
| 1597 } |
1547 } | 1598 } |
1548 // | 1599 // |
1549 // Done adding the routes for the selected node. | 1600 // Done adding the routes for the selected node. |
1550 // | 1601 // |
1551 return; | 1602 return; |
1552 } | 1603 } |
1553 } | 1604 } |
1554 } | 1605 } |
1555 void | 1606 void |
1556 GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) | 1607 GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v) |
(...skipping 16 matching lines...) Expand all Loading... |
1573 // We need to walk the list of nodes looking for the one that has the router | 1624 // 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 | 1625 // ID corresponding to the root vertex. This is the one we're going to write |
1575 // the routing information to. | 1626 // the routing information to. |
1576 // | 1627 // |
1577 NodeList::Iterator i = NodeList::Begin ();· | 1628 NodeList::Iterator i = NodeList::Begin ();· |
1578 for (; i != NodeList::End (); i++) | 1629 for (; i != NodeList::End (); i++) |
1579 { | 1630 { |
1580 Ptr<Node> node = *i; | 1631 Ptr<Node> node = *i; |
1581 // | 1632 // |
1582 // The router ID is accessible through the GlobalRouter interface, so we need | 1633 // 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 | 1634 // to GetObject for that interface. If there's no GlobalRouter interface, |
1584 // in question cannot be the router we want, so we continue. | 1635 // the node in question cannot be the router we want, so we continue. |
1585 //· | 1636 //· |
1586 Ptr<GlobalRouter> rtr =· | 1637 Ptr<GlobalRouter> rtr =· |
1587 node->GetObject<GlobalRouter> (); | 1638 node->GetObject<GlobalRouter> (); |
1588 | 1639 |
1589 if (rtr == 0) | 1640 if (rtr == 0) |
1590 { | 1641 { |
1591 NS_LOG_LOGIC ("No GlobalRouter interface on node " <<· | 1642 NS_LOG_LOGIC ("No GlobalRouter interface on node " <<· |
1592 node->GetId ()); | 1643 node->GetId ()); |
1593 continue; | 1644 continue; |
1594 } | 1645 } |
1595 // | 1646 // |
1596 // If the router ID of the current node is equal to the router ID of the· | 1647 // 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· | 1648 // root of the SPF tree, then this node is the one for which we need to· |
1598 // write the routing tables. | 1649 // write the routing tables. |
1599 // | 1650 // |
1600 NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); | 1651 NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); |
1601 | 1652 |
1602 if (rtr->GetRouterId () == routerId) | 1653 if (rtr->GetRouterId () == routerId) |
1603 { | 1654 { |
1604 NS_LOG_LOGIC ("setting routes for node " << node->GetId ()); | 1655 NS_LOG_LOGIC ("setting routes for node " << node->GetId ()); |
1605 // | 1656 // |
1606 // Routing information is updated using the Ipv4 interface. We need to QI | 1657 // Routing information is updated using the Ipv4 interface. We need to· |
1607 // for that interface. If the node is acting as an IP version 4 router, it | 1658 // GetObject for that interface. If the node is acting as an IP version 4 |
1608 // should absolutely have an Ipv4 interface. | 1659 // router, it should absolutely have an Ipv4 interface. |
1609 // | 1660 // |
1610 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); | 1661 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1611 NS_ASSERT_MSG (ipv4,· | 1662 NS_ASSERT_MSG (ipv4,· |
1612 "GlobalRouteManagerImpl::SPFIntraAddTransit (): " | 1663 "GlobalRouteManagerImpl::SPFIntraAddTransit (): " |
1613 "QI for <Ipv4> interface failed"); | 1664 "GetObject for <Ipv4> interface failed"); |
1614 // | 1665 // |
1615 // Get the Global Router Link State Advertisement from the vertex we're | 1666 // 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 | 1667 // 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 | 1668 // 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. | 1669 // to be interested in the records corresponding to point-to-point links. |
1619 // | 1670 // |
1620 GlobalRoutingLSA *lsa = v->GetLSA (); | 1671 GlobalRoutingLSA *lsa = v->GetLSA (); |
1621 NS_ASSERT_MSG (lsa,· | 1672 NS_ASSERT_MSG (lsa,· |
1622 "GlobalRouteManagerImpl::SPFIntraAddTransit (): " | 1673 "GlobalRouteManagerImpl::SPFIntraAddTransit (): " |
1623 "Expected valid LSA in SPFVertex* v"); | 1674 "Expected valid LSA in SPFVertex* v"); |
1624 Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask (); | 1675 Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask (); |
1625 Ipv4Address tempip = lsa->GetLinkStateId (); | 1676 Ipv4Address tempip = lsa->GetLinkStateId (); |
1626 tempip = tempip.CombineMask (tempmask); | 1677 tempip = tempip.CombineMask (tempmask); |
1627 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); | 1678 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
1628 NS_ASSERT (gr); | 1679 NS_ASSERT (gr); |
1629 gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), | 1680 if (v->GetOutgoingInterfaceId () >= 0) |
1630 v->GetOutgoingInterfaceId ()); | 1681 { |
1631 NS_LOG_LOGIC ("Node " << node->GetId () << | 1682 gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), |
1632 " add network route to " << tempip << | 1683 v->GetOutgoingInterfaceId ()); |
1633 " using next hop " << v->GetNextHop () << | 1684 NS_LOG_LOGIC ("Node " << node->GetId () << |
1634 " via interface " << v->GetOutgoingInterfaceId ()); | 1685 " add network route to " << tempip << |
| 1686 " using next hop " << v->GetNextHop () << |
| 1687 " via interface " << v->GetOutgoingInterfaceId ()); |
| 1688 } |
| 1689 else |
| 1690 { |
| 1691 NS_LOG_LOGIC ("Node " << node->GetId () << |
| 1692 " NOT able to add network route to " << tempip << |
| 1693 " using next hop " << v->GetNextHop () << |
| 1694 " since outgoing interface id is negative"); |
| 1695 } |
1635 } | 1696 } |
1636 }· | 1697 }· |
1637 } | 1698 } |
1638 | 1699 |
1639 // Derived from quagga ospf_vertex_add_parents () | 1700 // Derived from quagga ospf_vertex_add_parents () |
1640 // | 1701 // |
1641 // This is a somewhat oddly named method (blame quagga). Although you might | 1702 // 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 | 1703 // expect it to add a parent *to* something, it actually adds a vertex |
1643 // to the list of children *in* each of its parents.· | 1704 // to the list of children *in* each of its parents.· |
1644 // | 1705 // |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 | 1947 |
1887 return ok; | 1948 return ok; |
1888 } | 1949 } |
1889 | 1950 |
1890 // Instantiate this class for the unit tests | 1951 // Instantiate this class for the unit tests |
1891 static GlobalRouteManagerImplTest g_globalRouteManagerTest; | 1952 static GlobalRouteManagerImplTest g_globalRouteManagerTest; |
1892 | 1953 |
1893 } // namespace ns3 | 1954 } // namespace ns3 |
1894 | 1955 |
1895 #endif· | 1956 #endif· |
OLD | NEW |