|
|
| 374 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
374 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
| 375 |
{ |
375 |
{ |
| 376 |
Ptr<Node> node = *i; |
376 |
Ptr<Node> node = *i; |
| 377 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
377 |
Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> (); |
|
|
378 |
if (router == 0) |
| 379 |
{ |
| 380 |
continue; |
| 381 |
} |
| 382 |
Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol (); |
| 378 |
uint32_t j = 0; |
383 |
uint32_t j = 0; |
| 379 |
uint32_t nRoutes = gr->GetNRoutes (); |
384 |
uint32_t nRoutes = gr->GetNRoutes (); |
| 380 |
NS_LOG_LOGIC ("Deleting " << gr->GetNRoutes ()<< " routes from node " << node->GetId ()); |
385 |
NS_LOG_LOGIC ("Deleting " << gr->GetNRoutes ()<< " routes from node " << node->GetId ()); |
|
|
| 397 |
} |
402 |
} |
| 398 |
|
403 |
|
| 399 |
// |
404 |
// |
| 400 |
// In order to build the routing database, we need at least one of the nodes |
|
|
| 401 |
// to participate as a router. This is a convenience function that makes |
| 402 |
// all nodes routers. We do this by walking the list of nodes in the system |
| 403 |
// and aggregating a Global Router Interface to each of the nodes. |
| 404 |
// |
| 405 |
void |
| 406 |
GlobalRouteManagerImpl::SelectRouterNodes () |
| 407 |
{ |
| 408 |
NS_LOG_FUNCTION_NOARGS (); |
| 409 |
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) |
| 410 |
{ |
| 411 |
Ptr<Node> node = *i; |
| 412 |
NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ()); |
| 413 |
|
| 414 |
Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); |
| 415 |
node->AggregateObject (globalRouter); |
| 416 |
|
| 417 |
NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); |
| 418 |
Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); |
| 419 |
// Here, we check whether there is an existing Ipv4RoutingProtocol object |
| 420 |
// to add this protocol to. |
| 421 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 422 |
NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): GetObject for <Ipv4> interface failed"); |
| 423 |
// Now, we add this to an Ipv4ListRouting object. |
| 424 |
// XXX in the future, we may want to allow this to be added to Ipv4 |
| 425 |
// directly |
| 426 |
Ptr<Ipv4ListRouting> ipv4ListRouting = DynamicCast<Ipv4ListRouting> (ipv4->GetRoutingProtocol ()); |
| 427 |
NS_ASSERT_MSG (ipv4ListRouting, "GlobalRouteManagerImpl::SelectRouterNodes (): Ipv4ListRouting not found"); |
| 428 |
// This is the object that will keep the global routes. We insert it |
| 429 |
// at slightly higher priority than static routing (which is at zero). |
| 430 |
// This means that global routes (e.g. host routes) will be consulted |
| 431 |
// before static routes |
| 432 |
// XXX make the below priority value an attribute |
| 433 |
ipv4ListRouting->AddRoutingProtocol (globalRouting, 3); |
| 434 |
// Locally cache the globalRouting pointer; we'll need it later |
| 435 |
// when we add routes |
| 436 |
AddGlobalRoutingProtocol (node->GetId (), globalRouting); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
void |
| 441 |
GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c) |
| 442 |
{ |
| 443 |
NS_LOG_FUNCTION (&c); |
| 444 |
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) |
| 445 |
{ |
| 446 |
Ptr<Node> node = *i; |
| 447 |
NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << |
| 448 |
node->GetId ()); |
| 449 |
|
| 450 |
Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> (); |
| 451 |
node->AggregateObject (globalRouter); |
| 452 |
|
| 453 |
NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ()); |
| 454 |
Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> (); |
| 455 |
// This is the object that will keep the global routes. We insert it |
| 456 |
// at slightly higher priority than static routing (which is at zero). |
| 457 |
// This means that global routes (e.g. host routes) will be consulted |
| 458 |
// before static routes |
| 459 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 460 |
NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): " |
| 461 |
"GetObject for <Ipv4> interface failed"); |
| 462 |
Ptr<Ipv4ListRouting> ipv4ListRouting = DynamicCast<Ipv4ListRouting> (ipv4->GetRoutingProtocol ()); |
| 463 |
NS_ASSERT_MSG (ipv4ListRouting, "GlobalRouteManagerImpl::SelectRouterNodes (): Ipv4ListRouting not found"); |
| 464 |
// XXX make the below priority value an attribute |
| 465 |
ipv4ListRouting->AddRoutingProtocol (globalRouting, 3); |
| 466 |
// Locally cache the globalRouting pointer; we'll need it later |
| 467 |
// when we add routes |
| 468 |
AddGlobalRoutingProtocol (node->GetId (), globalRouting); |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
// |
| 473 |
// In order to build the routing database, we need to walk the list of nodes |
405 |
// In order to build the routing database, we need to walk the list of nodes |
| 474 |
// in the system and look for those that support the GlobalRouter interface. |
406 |
// in the system and look for those that support the GlobalRouter interface. |
| 475 |
// These routers will export a number of Link State Advertisements (LSAs) |
407 |
// These routers will export a number of Link State Advertisements (LSAs) |
|
|
| 1352 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
1284 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
| 1353 |
// which the packets should be send for forwarding. |
1285 |
// which the packets should be send for forwarding. |
| 1354 |
// |
1286 |
// |
| 1355 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
1287 |
|
|
|
1288 |
Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> (); |
| 1289 |
if (router == 0) |
| 1290 |
{ |
| 1291 |
continue; |
| 1292 |
} |
| 1293 |
Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol (); |
| 1356 |
NS_ASSERT (gr); |
1294 |
NS_ASSERT (gr); |
| 1357 |
if (v->GetOutgoingInterfaceId () >= 0) |
1295 |
if (v->GetOutgoingInterfaceId () >= 0) |
| 1358 |
{ |
1296 |
{ |
|
|
| 1576 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
1514 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
| 1577 |
// which the packets should be send for forwarding. |
1515 |
// which the packets should be send for forwarding. |
| 1578 |
// |
1516 |
// |
| 1579 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
1517 |
Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> (); |
|
|
1518 |
if (router == 0) |
| 1519 |
{ |
| 1520 |
continue; |
| 1521 |
} |
| 1522 |
Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol (); |
| 1580 |
NS_ASSERT (gr); |
1523 |
NS_ASSERT (gr); |
| 1581 |
if (v->GetOutgoingInterfaceId () >= 0) |
1524 |
if (v->GetOutgoingInterfaceId () >= 0) |
| 1582 |
{ |
1525 |
{ |
|
|
| 1674 |
Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask (); |
1617 |
Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask (); |
| 1675 |
Ipv4Address tempip = lsa->GetLinkStateId (); |
1618 |
Ipv4Address tempip = lsa->GetLinkStateId (); |
| 1676 |
tempip = tempip.CombineMask (tempmask); |
1619 |
tempip = tempip.CombineMask (tempmask); |
| 1677 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
1620 |
Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> (); |
|
|
1621 |
if (router == 0) |
| 1622 |
{ |
| 1623 |
continue; |
| 1624 |
} |
| 1625 |
Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol (); |
| 1678 |
NS_ASSERT (gr); |
1626 |
NS_ASSERT (gr); |
| 1679 |
if (v->GetOutgoingInterfaceId () >= 0) |
1627 |
if (v->GetOutgoingInterfaceId () >= 0) |
| 1680 |
{ |
1628 |
{ |
|
|
| 1714 |
v->GetParent ()->AddChild (v); |
1662 |
v->GetParent ()->AddChild (v); |
| 1715 |
} |
1663 |
} |
| 1716 |
|
1664 |
|
| 1717 |
void |
|
|
| 1718 |
GlobalRouteManagerImpl::AddGlobalRoutingProtocol (uint32_t nodeId, Ptr<Ipv4GlobalRouting> proto) |
| 1719 |
{ |
| 1720 |
NS_LOG_FUNCTION (nodeId); |
| 1721 |
m_routingProtocols.push_back |
| 1722 |
(std::pair<uint32_t, Ptr<Ipv4GlobalRouting> > (nodeId, proto)); |
| 1723 |
m_routingProtocols.sort (); |
| 1724 |
} |
| 1725 |
|
| 1726 |
Ptr<Ipv4GlobalRouting> |
| 1727 |
GlobalRouteManagerImpl::GetGlobalRoutingProtocol (uint32_t nodeId) |
| 1728 |
{ |
| 1729 |
for (Ipv4GlobalRoutingList::const_iterator rprotoIter = m_routingProtocols.begin (); rprotoIter != m_routingProtocols.end (); rprotoIter++) |
| 1730 |
{ |
| 1731 |
if ((*rprotoIter).first == nodeId) |
| 1732 |
{ |
| 1733 |
return (*rprotoIter).second; |
| 1734 |
} |
| 1735 |
} |
| 1736 |
return 0; |
| 1737 |
} |
| 1738 |
|
| 1739 |
|
| 1740 |
} // namespace ns3 |
1665 |
} // namespace ns3 |
| 1741 |
|
1666 |
|
| 1742 |
#ifdef RUN_SELF_TESTS |
1667 |
#ifdef RUN_SELF_TESTS |