*** helper/ipv4-global-routing-helper.h~ Mon Jul 13 14:07:56 2009 --- helper/ipv4-global-routing-helper.h Mon Jul 13 14:07:36 2009 *************** *** 22,27 **** --- 22,28 ---- #include "node-container.h" #include "ipv4-routing-helper.h" + #include "ns3/ipv4-global-routing.h" namespace ns3 { *************** *** 63,68 **** --- 64,71 ---- * */ static void RecomputeRoutingTables (void); + + static Ptr GetGlobalRouting (Ptr ipv4); }; } // namespace ns3 *** helper/ipv4-global-routing-helper.cc~ Mon Jul 13 14:07:57 2009 --- helper/ipv4-global-routing-helper.cc Mon Jul 13 14:07:36 2009 *************** *** 45,50 **** --- 45,80 ---- return globalRouting; } + Ptr + Ipv4GlobalRoutingHelper::GetGlobalRouting (Ptr ipv4) + { + Ptr ipv4rp = ipv4->GetRoutingProtocol (); + NS_ASSERT_MSG (ipv4rp, "No routing protocol associated with Ipv4"); + if (DynamicCast (ipv4rp)) + { + NS_LOG_LOGIC ("Global routing found as the main IPv4 routing protocol."); + return DynamicCast (ipv4rp); + } + if (DynamicCast (ipv4rp)) + { + Ptr lrp = DynamicCast (ipv4rp); + int16_t priority; + for (uint32_t i = 0; i < lrp->GetNRoutingProtocols (); i++) + { + NS_LOG_LOGIC ("Searching for global routing in list"); + Ptr temp = lrp->GetRoutingProtocol (i, priority); + if (DynamicCast (temp)) + { + NS_LOG_LOGIC ("Found global routing in list"); + return DynamicCast (temp); + } + } + } + NS_LOG_LOGIC ("Global routing not found"); + return 0; + } + + void Ipv4GlobalRoutingHelper::PopulateRoutingTables (void) { diff -crB routing/global-routing-old/global-route-manager-impl.cc routing/global-routing/global-route-manager-impl.cc *** routing/global-routing-old/global-route-manager-impl.cc Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-route-manager-impl.cc Mon Jul 13 13:59:37 2009 *************** *** 243,248 **** --- 243,257 ---- return m_vertexProcessed; } + void + SPFVertex::ClearVertexProcessed (void) + { + for (uint32_t i = 0; i < this->GetNChildren (); i++) + { + this->GetChild (i)->ClearVertexProcessed (); + } + this->SetVertexProcessed (false); + } // --------------------------------------------------------------------------- // *************** *** 252,258 **** GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () : ! m_database () { NS_LOG_FUNCTION_NOARGS (); } --- 261,268 ---- GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () : ! m_database (), ! m_extdatabase () { NS_LOG_FUNCTION_NOARGS (); } *************** *** 267,272 **** --- 277,288 ---- GlobalRoutingLSA* temp = i->second; delete temp; } + for (uint32_t j=0; jGetLSType() == GlobalRoutingLSA::ASExternalLSAs) { ! m_extdatabase.push_back (lsa); ! } else ! { ! m_database.insert (LSDBPair_t (addr, lsa)); ! } ! } ! ! GlobalRoutingLSA* ! GlobalRouteManagerLSDB::GetExtLSA (uint32_t index) const ! { ! return m_extdatabase.at (index); ! } ! ! uint32_t ! GlobalRouteManagerLSDB::GetNumExtLSAs () const ! { ! return m_extdatabase.size (); } GlobalRoutingLSA* *************** *** 438,444 **** // DiscoverLSAs () will get zero as the number since no routes have been // found. // ! uint32_t numLSAs = rtr->DiscoverLSAs (); NS_LOG_LOGIC ("Found " << numLSAs << " LSAs"); for (uint32_t j = 0; j < numLSAs; ++j) --- 470,477 ---- // DiscoverLSAs () will get zero as the number since no routes have been // found. // ! Ptr grouting = rtr->GetRoutingProtocol (); ! uint32_t numLSAs = rtr->DiscoverLSAs (grouting->GetInjectedRoutes ()); NS_LOG_LOGIC ("Found " << numLSAs << " LSAs"); for (uint32_t j = 0; j < numLSAs; ++j) *************** *** 824,830 **** " via outgoing interface " << w->GetOutgoingInterfaceId () << " with distance " << distance); } // end W is a router vertes ! else { NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork); // W is a directly connected network; no next hop is required --- 857,863 ---- " via outgoing interface " << w->GetOutgoingInterfaceId () << " with distance " << distance); } // end W is a router vertes ! else { NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork); // W is a directly connected network; no next hop is required *************** *** 1237,1242 **** --- 1270,1283 ---- // Second stage of SPF calculation procedure SPFProcessStubs (m_spfroot); + for (uint32_t i = 0;iGetNumExtLSAs ();i++) + { + m_spfroot->ClearVertexProcessed (); + GlobalRoutingLSA *extlsa = m_lsdb->GetExtLSA (i); + NS_LOG_LOGIC ("Processing External LSA with id " << extlsa->GetLinkStateId ()); + ProcessASExternals (m_spfroot, extlsa); + } + // // We're all done setting the routing information for the node at the root of // the SPF tree. Delete all of the vertices and corresponding resources. Go *************** *** 1246,1251 **** --- 1287,1449 ---- m_spfroot = 0; } + void + GlobalRouteManagerImpl::ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa) + { + NS_LOG_FUNCTION_NOARGS (); + NS_LOG_LOGIC ("Processing external for destination " << + extlsa->GetLinkStateId () << + ", for router " << v->GetVertexId () << + ", advertised by " << extlsa->GetAdvertisingRouter ()); + if (v->GetVertexType () == SPFVertex::VertexRouter) + { + GlobalRoutingLSA *rlsa = v->GetLSA (); + NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ()); + if ((rlsa->GetLinkStateId ()) == (extlsa->GetAdvertisingRouter ())) + { + NS_LOG_LOGIC ("Found advertising router to destination"); + SPFAddASExternal(extlsa,v); + } + } + for (uint32_t i = 0; i < v->GetNChildren (); i++) + { + if (!v->GetChild (i)->IsVertexProcessed ()) + { + NS_LOG_LOGIC ("Vertex's child " << i << " not yet processed, processing..."); + ProcessASExternals (v->GetChild (i), extlsa); + v->GetChild (i)->SetVertexProcessed (true); + } + } + } + + // + // Adding external routes to routing table - modeled after + // SPFAddIntraAddStub() + // + + void + GlobalRouteManagerImpl::SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v) + { + NS_LOG_FUNCTION_NOARGS (); + + NS_ASSERT_MSG (m_spfroot, + "GlobalRouteManagerImpl::SPFAddASExternal (): Root pointer not set"); + // Two cases to consider: We are advertising the external ourselves + // => No need to add anything + // OR find best path to the advertising router + if (v->GetVertexId () == m_spfroot->GetVertexId ()) + { + NS_LOG_LOGIC ("External is on local host: " + << v->GetVertexId () << "; returning"); + return; + } + NS_LOG_LOGIC ("External is on remote host: " + << extlsa->GetAdvertisingRouter () << "; installing"); + + Ipv4Address routerId = m_spfroot->GetVertexId (); + + NS_LOG_LOGIC ("Vertex ID = " << routerId); + // + // We need to walk the list of nodes looking for the one that has the router + // ID corresponding to the root vertex. This is the one we're going to write + // the routing information to. + // + NodeList::Iterator i = NodeList::Begin (); + for (; i != NodeList::End (); i++) + { + Ptr node = *i; + // + // The router ID is accessible through the GlobalRouter interface, so we need + // to QI for that interface. If there's no GlobalRouter interface, the node + // in question cannot be the router we want, so we continue. + // + Ptr rtr = + node->GetObject (); + + if (rtr == 0) + { + NS_LOG_LOGIC ("No GlobalRouter interface on node " << + node->GetId ()); + continue; + } + // + // If the router ID of the current node is equal to the router ID of the + // root of the SPF tree, then this node is the one for which we need to + // write the routing tables. + // + NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); + + if (rtr->GetRouterId () == routerId) + { + NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); + // + // Routing information is updated using the Ipv4 interface. We need to QI + // for that interface. If the node is acting as an IP version 4 router, it + // should absolutely have an Ipv4 interface. + // + Ptr ipv4 = node->GetObject (); + NS_ASSERT_MSG (ipv4, + "GlobalRouteManagerImpl::SPFIntraAddRouter (): " + "QI for interface failed"); + // + // Get the Global Router Link State Advertisement from the vertex we're + // adding the routes to. The LSA will have a number of attached Global Router + // Link Records corresponding to links off of that vertex / node. We're going + // to be interested in the records corresponding to point-to-point links. + // + NS_ASSERT_MSG (v->GetLSA (), + "GlobalRouteManagerImpl::SPFIntraAddRouter (): " + "Expected valid LSA in SPFVertex* v"); + Ipv4Mask tempmask = extlsa->GetNetworkLSANetworkMask(); + Ipv4Address tempip = extlsa->GetLinkStateId (); + tempip = tempip.CombineMask (tempmask); + + NS_LOG_LOGIC (" Node " << node->GetId () << + " add route to " << tempip << + " with mask " << tempmask << + " using next hop " << v->GetNextHop () << + " via interface " << v->GetOutgoingInterfaceId ()); + // + // Here's why we did all of that work. We're going to add a host route to the + // host address found in the m_linkData field of the point-to-point link + // record. In the case of a point-to-point link, this is the local IP address + // of the node connected to the link. Each of these point-to-point links + // will correspond to a local interface that has an IP address to which + // the node at the root of the SPF tree can send packets. The vertex + // (corresponding to the node that has these links and interfaces) has + // an m_nextHop address precalculated for us that is the address to which the + // root node should send packets to be forwarded to these IP addresses. + // Similarly, the vertex has an m_rootOif (outbound interface index) to + // which the packets should be send for forwarding. + // + Ptr router = node->GetObject (); + if (router == 0) + { + continue; + } + Ptr gr = router->GetRoutingProtocol (); + NS_ASSERT (gr); + if (v->GetOutgoingInterfaceId () >= 0) + { + gr->AddASExternalRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingInterfaceId ()); + NS_LOG_LOGIC ("Node " << node->GetId () << + " add network route to " << tempip << + " using next hop " << v->GetNextHop () << + " via interface " << v->GetOutgoingInterfaceId ()); + } + else + { + NS_LOG_LOGIC ("Node " << node->GetId () << + " NOT able to add network route to " << tempip << + " using next hop " << v->GetNextHop () << + " since outgoing interface id is negative"); + } + return; + } // if + } // for + } + + // Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs () // stub link records will exist for point-to-point interfaces and for // broadcast interfaces for which no neighboring router can be found diff -crB routing/global-routing-old/global-route-manager-impl.cc.orig routing/global-routing/global-route-manager-impl.cc.orig *** routing/global-routing-old/global-route-manager-impl.cc.orig Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-route-manager-impl.cc.orig Mon Jul 13 13:41:44 2009 *************** *** 243,257 **** return m_vertexProcessed; } - void - SPFVertex::ClearVertexProcessed (void) - { - for (uint32_t i = 0; i < this->GetNChildren (); i++) - { - this->GetChild(i)->ClearVertexProcessed(); - } - this->SetVertexProcessed (false); - } // --------------------------------------------------------------------------- // --- 243,248 ---- *************** *** 261,268 **** GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () : ! m_database (), ! m_extdatabase () { NS_LOG_FUNCTION_NOARGS (); } --- 252,258 ---- GlobalRouteManagerLSDB::GlobalRouteManagerLSDB () : ! m_database () { NS_LOG_FUNCTION_NOARGS (); } *************** *** 277,288 **** GlobalRoutingLSA* temp = i->second; delete temp; } - for (uint32_t j=0; jGetLSType() == GlobalRoutingLSA::ASExternalLSAs) { ! m_extdatabase.push_back (lsa); ! } else ! { ! m_database.insert (LSDBPair_t (addr, lsa)); ! } ! } ! ! GlobalRoutingLSA* ! GlobalRouteManagerLSDB::GetExtLSA (uint32_t index) const ! { ! return m_extdatabase.at(index); ! } ! ! uint32_t ! GlobalRouteManagerLSDB::GetNumExtLSAs () const ! { ! return m_extdatabase.size(); } GlobalRoutingLSA* --- 287,293 ---- GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa) { NS_LOG_FUNCTION (addr << lsa); ! m_database.insert (LSDBPair_t (addr, lsa)); } GlobalRoutingLSA* *************** *** 471,478 **** // DiscoverLSAs () will get zero as the number since no routes have been // found. // ! Ptr grouting = rtr->GetRoutingProtocol (); ! uint32_t numLSAs = rtr->DiscoverLSAs (grouting->GetInjectedRoutes()); NS_LOG_LOGIC ("Found " << numLSAs << " LSAs"); for (uint32_t j = 0; j < numLSAs; ++j) --- 438,444 ---- // DiscoverLSAs () will get zero as the number since no routes have been // found. // ! uint32_t numLSAs = rtr->DiscoverLSAs (); NS_LOG_LOGIC ("Found " << numLSAs << " LSAs"); for (uint32_t j = 0; j < numLSAs; ++j) *************** *** 858,864 **** " via outgoing interface " << w->GetOutgoingInterfaceId () << " with distance " << distance); } // end W is a router vertes ! else { NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork); // W is a directly connected network; no next hop is required --- 824,830 ---- " via outgoing interface " << w->GetOutgoingInterfaceId () << " with distance " << distance); } // end W is a router vertes ! else { NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork); // W is a directly connected network; no next hop is required *************** *** 1271,1284 **** // Second stage of SPF calculation procedure SPFProcessStubs (m_spfroot); - for (uint32_t i = 0;iGetNumExtLSAs();i++) - { - m_spfroot->ClearVertexProcessed(); - GlobalRoutingLSA *extlsa = m_lsdb->GetExtLSA(i); - NS_LOG_LOGIC ("Processing External LSA with id " << extlsa->GetLinkStateId()); - ProcessASExternals (m_spfroot, extlsa); - } - // // We're all done setting the routing information for the node at the root of // the SPF tree. Delete all of the vertices and corresponding resources. Go --- 1237,1242 ---- *************** *** 1288,1450 **** m_spfroot = 0; } - void - GlobalRouteManagerImpl::ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa) - { - NS_LOG_FUNCTION_NOARGS (); - NS_LOG_LOGIC ("Processing external for destination " << extlsa->GetLinkStateId () << - ", for router " << v->GetVertexId () << - ", advertised by " << extlsa->GetAdvertisingRouter()); - if (v->GetVertexType () == SPFVertex::VertexRouter) - { - GlobalRoutingLSA *rlsa = v->GetLSA (); - NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ()); - // for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++) - // { - // NS_LOG_LOGIC ("Examining link " << i << " of " << - // v->GetVertexId () << "'s " << - // v->GetLSA ()->GetNLinkRecords () << " link records"); - if ((rlsa->GetLinkStateId()) == (extlsa->GetAdvertisingRouter())) - { - NS_LOG_LOGIC ("Found advertising router to destination"); - SPFAddASExternal(extlsa,v); - } - // } - } - for (uint32_t i = 0; i < v->GetNChildren (); i++) - { - if (!v->GetChild (i)->IsVertexProcessed ()) - { - NS_LOG_LOGIC ("Vertex's child " << i << " not yet processed, processing..."); - ProcessASExternals (v->GetChild (i), extlsa); - v->GetChild (i)->SetVertexProcessed (true); - } - } - } - - void - GlobalRouteManagerImpl::SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v) - { - NS_LOG_FUNCTION_NOARGS (); - - NS_ASSERT_MSG (m_spfroot, - "GlobalRouteManagerImpl::SPFAddASExternal (): Root pointer not set"); - // Two cases to consider: We are advertising the external ourselves - // => No need to add anything - // OR find best path to the advertising router - if (v->GetVertexId () == m_spfroot->GetVertexId ()) - { - NS_LOG_LOGIC ("External is on local host: " - << v->GetVertexId () << "; returning"); - return; - } - NS_LOG_LOGIC ("External is on remote host: " - << extlsa->GetAdvertisingRouter () << "; installing"); - - Ipv4Address routerId = m_spfroot->GetVertexId (); - - NS_LOG_LOGIC ("Vertex ID = " << routerId); - // We need to walk the list of nodes looking for the one that has the router - // ID corresponding to the root vertex. This is the one we're going to write - // the routing information to. - // - NodeList::Iterator i = NodeList::Begin (); - for (; i != NodeList::End (); i++) - { - Ptr node = *i; - // - // The router ID is accessible through the GlobalRouter interface, so we need - // to QI for that interface. If there's no GlobalRouter interface, the node - // in question cannot be the router we want, so we continue. - // - Ptr rtr = - node->GetObject (); - - if (rtr == 0) - { - NS_LOG_LOGIC ("No GlobalRouter interface on node " << - node->GetId ()); - continue; - } - // - // If the router ID of the current node is equal to the router ID of the - // root of the SPF tree, then this node is the one for which we need to - // write the routing tables. - // - NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); - - if (rtr->GetRouterId () == routerId) - { - NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); - // - // Routing information is updated using the Ipv4 interface. We need to QI - // for that interface. If the node is acting as an IP version 4 router, it - // should absolutely have an Ipv4 interface. - // - Ptr ipv4 = node->GetObject (); - NS_ASSERT_MSG (ipv4, - "GlobalRouteManagerImpl::SPFIntraAddRouter (): " - "QI for interface failed"); - // - // Get the Global Router Link State Advertisement from the vertex we're - // adding the routes to. The LSA will have a number of attached Global Router - // Link Records corresponding to links off of that vertex / node. We're going - // to be interested in the records corresponding to point-to-point links. - // - NS_ASSERT_MSG (v->GetLSA (), - "GlobalRouteManagerImpl::SPFIntraAddRouter (): " - "Expected valid LSA in SPFVertex* v"); - Ipv4Mask tempmask = extlsa->GetNetworkLSANetworkMask(); - Ipv4Address tempip = extlsa->GetLinkStateId (); - tempip = tempip.CombineMask (tempmask); - - NS_LOG_LOGIC (" Node " << node->GetId () << - " add route to " << tempip << - " with mask " << tempmask << - " using next hop " << v->GetNextHop () << - " via interface " << v->GetOutgoingInterfaceId ()); - // - // Here's why we did all of that work. We're going to add a host route to the - // host address found in the m_linkData field of the point-to-point link - // record. In the case of a point-to-point link, this is the local IP address - // of the node connected to the link. Each of these point-to-point links - // will correspond to a local interface that has an IP address to which - // the node at the root of the SPF tree can send packets. The vertex - // (corresponding to the node that has these links and interfaces) has - // an m_nextHop address precalculated for us that is the address to which the - // root node should send packets to be forwarded to these IP addresses. - // Similarly, the vertex has an m_rootOif (outbound interface index) to - // which the packets should be send for forwarding. - // - - Ptr router = node->GetObject (); - if (router == 0) - { - continue; - } - Ptr gr = router->GetRoutingProtocol (); - NS_ASSERT (gr); - if (v->GetOutgoingInterfaceId () >= 0) - { - gr->AddASExternalRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingInterfaceId ()); - NS_LOG_LOGIC ("Node " << node->GetId () << - " add network route to " << tempip << - " using next hop " << v->GetNextHop () << - " via interface " << v->GetOutgoingInterfaceId ()); - } - else - { - NS_LOG_LOGIC ("Node " << node->GetId () << - " NOT able to add network route to " << tempip << - " using next hop " << v->GetNextHop () << - " since outgoing interface id is negative"); - } - return; - } // if - } // for - } - - // Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs () // stub link records will exist for point-to-point interfaces and for // broadcast interfaces for which no neighboring router can be found --- 1246,1251 ---- diff -crB routing/global-routing-old/global-route-manager-impl.h routing/global-routing/global-route-manager-impl.h *** routing/global-routing-old/global-route-manager-impl.h Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-route-manager-impl.h Mon Jul 13 13:43:22 2009 *************** *** 26,31 **** --- 26,32 ---- #include #include #include + #include #include "ns3/object.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" *************** *** 76,82 **** enum VertexType { VertexUnknown = 0, /**< Uninitialized Link Record */ VertexRouter, /**< Vertex representing a router in the topology */ ! VertexNetwork /**< Vertex representing a network in the topology */ }; /** --- 77,83 ---- enum VertexType { VertexUnknown = 0, /**< Uninitialized Link Record */ VertexRouter, /**< Vertex representing a router in the topology */ ! VertexNetwork /**< Vertex representing a network in the topology */ }; /** *************** *** 563,568 **** --- 564,572 ---- * @returns value of underlying flag */ bool IsVertexProcessed (void) const; + + void ClearVertexProcessed (void); + private: VertexType m_vertexType; Ipv4Address m_vertexId; *************** *** 683,694 **** --- 687,704 ---- * @see SPFVertex */ void Initialize (); + + GlobalRoutingLSA* GetExtLSA (uint32_t index) const; + uint32_t GetNumExtLSAs () const; + private: typedef std::map LSDBMap_t; typedef std::pair LSDBPair_t; LSDBMap_t m_database; + std::vector m_extdatabase; + /** * @brief GlobalRouteManagerLSDB copy construction is disallowed. There's no * need for it and a compiler provided shallow copy would be wrong. *************** *** 775,780 **** --- 785,791 ---- bool CheckForStubNode (Ipv4Address root); void SPFCalculate (Ipv4Address root); void SPFProcessStubs (SPFVertex* v); + void ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa); void SPFNext (SPFVertex*, CandidateQueue&); int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, GlobalRoutingLinkRecord* l, uint32_t distance); *************** *** 784,789 **** --- 795,801 ---- void SPFIntraAddRouter (SPFVertex* v); void SPFIntraAddTransit (SPFVertex* v); void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v); + void SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v); int32_t FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255")); }; diff -crB routing/global-routing-old/global-route-manager-impl.h.orig routing/global-routing/global-route-manager-impl.h.orig *** routing/global-routing-old/global-route-manager-impl.h.orig Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-route-manager-impl.h.orig Mon Jul 13 13:41:44 2009 *************** *** 26,32 **** #include #include #include - #include #include "ns3/object.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" --- 26,31 ---- *************** *** 77,83 **** enum VertexType { VertexUnknown = 0, /**< Uninitialized Link Record */ VertexRouter, /**< Vertex representing a router in the topology */ ! VertexNetwork /**< Vertex representing a network in the topology */ }; /** --- 76,82 ---- enum VertexType { VertexUnknown = 0, /**< Uninitialized Link Record */ VertexRouter, /**< Vertex representing a router in the topology */ ! VertexNetwork /**< Vertex representing a network in the topology */ }; /** *************** *** 564,572 **** * @returns value of underlying flag */ bool IsVertexProcessed (void) const; - - void ClearVertexProcessed (void); - private: VertexType m_vertexType; Ipv4Address m_vertexId; --- 563,568 ---- *************** *** 687,704 **** * @see SPFVertex */ void Initialize (); - - GlobalRoutingLSA* GetExtLSA (uint32_t index) const; - uint32_t GetNumExtLSAs () const; - private: typedef std::map LSDBMap_t; typedef std::pair LSDBPair_t; LSDBMap_t m_database; - std::vector m_extdatabase; - /** * @brief GlobalRouteManagerLSDB copy construction is disallowed. There's no * need for it and a compiler provided shallow copy would be wrong. --- 683,694 ---- *************** *** 785,791 **** bool CheckForStubNode (Ipv4Address root); void SPFCalculate (Ipv4Address root); void SPFProcessStubs (SPFVertex* v); - void ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa); void SPFNext (SPFVertex*, CandidateQueue&); int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, GlobalRoutingLinkRecord* l, uint32_t distance); --- 775,780 ---- *************** *** 795,801 **** void SPFIntraAddRouter (SPFVertex* v); void SPFIntraAddTransit (SPFVertex* v); void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v); - void SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v); int32_t FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255")); }; --- 784,789 ---- diff -crB routing/global-routing-old/global-router-interface.cc routing/global-routing/global-router-interface.cc *** routing/global-routing-old/global-router-interface.cc Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-router-interface.cc Mon Jul 13 13:59:37 2009 *************** *** 413,418 **** --- 413,422 ---- { os << " (GlobalRoutingLSA::NetworkLSA)"; } + else if (m_lsType == GlobalRoutingLSA::ASExternalLSAs) + { + os << " (GlobalRoutingLSA::ASExternalLSA)"; + } else { os << "(Unknown LSType)"; *************** *** 474,479 **** --- 478,489 ---- } os << "---------- End NetworkLSA Link Record ----------" << std::endl; } + else if (m_lsType == GlobalRoutingLSA::ASExternalLSAs) + { + os << "---------- ASExternalLSA Link Record --------" << std::endl; + os << "m_linkStateId = " << m_linkStateId << std::endl; + os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl; + } else { NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType); *************** *** 568,575 **** // and build the Link State Advertisements that reflect them and their associated // networks. // ! uint32_t ! GlobalRouter::DiscoverLSAs (void) { NS_LOG_FUNCTION_NOARGS (); Ptr node = GetObject (); --- 578,585 ---- // and build the Link State Advertisements that reflect them and their associated // networks. // ! uint32_t ! GlobalRouter::DiscoverLSAs (std::list injectedRoutes) { NS_LOG_FUNCTION_NOARGS (); Ptr node = GetObject (); *************** *** 696,701 **** --- 706,727 ---- BuildNetworkLSAs (c); } + // + // Build injected route LSAs as external routes + // RFC 2328, section 12.4.4 + // + for (std::list::iterator i = injectedRoutes.begin(); + i != injectedRoutes.end(); + i++) + { + GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; + pLSA->SetLSType (GlobalRoutingLSA::ASExternalLSAs); + pLSA->SetLinkStateId ((*i)->GetDestNetwork ()); + pLSA->SetAdvertisingRouter (m_routerId); + pLSA->SetNetworkLSANetworkMask ((*i)->GetDestNetworkMask ()); + pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); + m_LSAs.push_back (pLSA); + } return m_LSAs.size (); } diff -crB routing/global-routing-old/global-router-interface.cc.orig routing/global-routing/global-router-interface.cc.orig *** routing/global-routing-old/global-router-interface.cc.orig Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-router-interface.cc.orig Mon Jul 13 13:41:44 2009 *************** *** 413,422 **** { os << " (GlobalRoutingLSA::NetworkLSA)"; } - else if (m_lsType == GlobalRoutingLSA::ASExternalLSAs) - { - os << " (GlobalRoutingLSA::ASExternalLSA)"; - } else { os << "(Unknown LSType)"; --- 413,418 ---- *************** *** 478,489 **** } os << "---------- End NetworkLSA Link Record ----------" << std::endl; } - else if (m_lsType == GlobalRoutingLSA::ASExternalLSAs) - { - os << "---------- ASExternalLSA Link Record --------" << std::endl; - os << "m_linkStateId = " << m_linkStateId << std::endl; - os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl; - } else { NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType); --- 474,479 ---- *************** *** 578,585 **** // and build the Link State Advertisements that reflect them and their associated // networks. // ! uint32_t ! GlobalRouter::DiscoverLSAs (std::list injectedRoutes) { NS_LOG_FUNCTION_NOARGS (); Ptr node = GetObject (); --- 568,575 ---- // and build the Link State Advertisements that reflect them and their associated // networks. // ! uint32_t ! GlobalRouter::DiscoverLSAs (void) { NS_LOG_FUNCTION_NOARGS (); Ptr node = GetObject (); *************** *** 706,727 **** BuildNetworkLSAs (c); } - // - // Build injected route LSAs as external routes - // RFC 2328, section 12.4.4 - // - for (std::list::iterator i = injectedRoutes.begin(); - i != injectedRoutes.end(); - i++) - { - GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; - pLSA->SetLSType (GlobalRoutingLSA::ASExternalLSAs); - pLSA->SetLinkStateId ((*i)->GetDestNetwork()); - pLSA->SetAdvertisingRouter (m_routerId); - pLSA->SetNetworkLSANetworkMask ((*i)->GetDestNetworkMask()); - pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); - m_LSAs.push_back (pLSA); - } return m_LSAs.size (); } --- 696,701 ---- diff -crB routing/global-routing-old/global-router-interface.h routing/global-routing/global-router-interface.h *** routing/global-routing-old/global-router-interface.h Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-router-interface.h Mon Jul 13 13:43:22 2009 *************** *** 32,37 **** --- 32,38 ---- #include "ns3/net-device-container.h" #include "ns3/bridge-net-device.h" #include "ns3/global-route-manager.h" + #include "ns3/ipv4-routing-table-entry.h" namespace ns3 { *************** *** 614,624 **** * advertisements after a network topology change by calling DiscoverLSAs * and then by reading those advertisements. * * @see GlobalRoutingLSA * @see GlobalRouter::GetLSA () * @returns The number of Global Routing Link State Advertisements. */ ! uint32_t DiscoverLSAs (void); /** * @brief Get the Number of Global Routing Link State Advertisements that this --- 615,627 ---- * advertisements after a network topology change by calling DiscoverLSAs * and then by reading those advertisements. * + * \param List of routing table entries of external routes to be injected. + * * @see GlobalRoutingLSA * @see GlobalRouter::GetLSA () * @returns The number of Global Routing Link State Advertisements. */ ! uint32_t DiscoverLSAs (std::list injectedRoutes); /** * @brief Get the Number of Global Routing Link State Advertisements that this diff -crB routing/global-routing-old/global-router-interface.h.orig routing/global-routing/global-router-interface.h.orig *** routing/global-routing-old/global-router-interface.h.orig Mon Jul 13 13:42:54 2009 --- routing/global-routing/global-router-interface.h.orig Mon Jul 13 13:41:44 2009 *************** *** 32,38 **** #include "ns3/net-device-container.h" #include "ns3/bridge-net-device.h" #include "ns3/global-route-manager.h" - #include "ns3/ipv4-routing-table-entry.h" namespace ns3 { --- 32,37 ---- *************** *** 615,627 **** * advertisements after a network topology change by calling DiscoverLSAs * and then by reading those advertisements. * - * \param List of routing table entries of external routes to be injected. - * * @see GlobalRoutingLSA * @see GlobalRouter::GetLSA () * @returns The number of Global Routing Link State Advertisements. */ ! uint32_t DiscoverLSAs (std::list injectedRoutes); /** * @brief Get the Number of Global Routing Link State Advertisements that this --- 614,624 ---- * advertisements after a network topology change by calling DiscoverLSAs * and then by reading those advertisements. * * @see GlobalRoutingLSA * @see GlobalRouter::GetLSA () * @returns The number of Global Routing Link State Advertisements. */ ! uint32_t DiscoverLSAs (void); /** * @brief Get the Number of Global Routing Link State Advertisements that this diff -crB routing/global-routing-old/ipv4-global-routing.cc routing/global-routing/ipv4-global-routing.cc *** routing/global-routing-old/ipv4-global-routing.cc Mon Jul 13 13:42:54 2009 --- routing/global-routing/ipv4-global-routing.cc Mon Jul 13 14:17:37 2009 *************** *** 98,107 **** --- 98,124 ---- m_networkRoutes.push_back (route); } + void + Ipv4GlobalRouting::AddASExternalRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + Ipv4Address forwardingRouter, + uint32_t interface) + { + NS_LOG_FUNCTION (network << networkMask << forwardingRouter); + Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry (); + *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network, + networkMask, + forwardingRouter, + interface); + m_ASexternalRoutes.push_back (route); + } + + Ptr Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest) { NS_LOG_FUNCTION_NOARGS (); + NS_LOG_LOGIC ("Looking for route for destination " << dest); Ptr rtentry = 0; bool found = false; Ipv4RoutingTableEntry* route = 0; *************** *** 137,142 **** --- 154,176 ---- } } } + if (found == false) + { + for (ASExternalRoutesI k = m_ASexternalRoutes.begin (); + k != m_ASexternalRoutes.end (); + k++) + { + Ipv4Mask mask = (*k)->GetDestNetworkMask (); + Ipv4Address entry = (*k)->GetDestNetwork (); + if (mask.IsMatch (dest, entry)) + { + NS_LOG_LOGIC ("Found external route" << *k); + route = (*k); + found = true; + break; + } + } + } if (found == true) { rtentry = Create (); *************** *** 161,166 **** --- 195,201 ---- uint32_t n = 0; n += m_hostRoutes.size (); n += m_networkRoutes.size (); + n += m_ASexternalRoutes.size (); return n; } *************** *** 184,199 **** } index -= m_hostRoutes.size (); uint32_t tmp = 0; ! for (NetworkRoutesI j = m_networkRoutes.begin (); ! j != m_networkRoutes.end (); ! j++) { ! if (tmp == index) { ! return *j; } - tmp++; } NS_ASSERT (false); // quiet compiler. return 0; --- 219,249 ---- } index -= m_hostRoutes.size (); uint32_t tmp = 0; ! if (index < m_networkRoutes.size()) { ! for (NetworkRoutesI j = m_networkRoutes.begin (); ! j != m_networkRoutes.end (); ! j++) { ! if (tmp == index) ! { ! return *j; ! } ! tmp++; } } + index -= m_networkRoutes.size(); + tmp = 0; + for (ASExternalRoutesI k = m_ASexternalRoutes.begin (); + k != m_ASexternalRoutes.end (); + k++) + { + if (tmp == index) + { + return *k; + } + tmp++; + } NS_ASSERT (false); // quiet compiler. return 0; *************** *** 236,241 **** --- 286,307 ---- } tmp++; } + index -= m_networkRoutes.size (); + tmp = 0; + for (ASExternalRoutesI k = m_ASexternalRoutes.begin (); + k != m_ASexternalRoutes.end (); + k++) + { + if (tmp == index) + { + NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_ASexternalRoutes.size()); + delete *k; + m_ASexternalRoutes.erase (k); + NS_LOG_LOGIC ("Done removing network route " << index << "; network route remaining size = " << m_networkRoutes.size()); + return; + } + tmp++; + } NS_ASSERT (false); } *************** *** 255,263 **** --- 321,363 ---- { delete (*j); } + for (InjectedRoutesI k = m_injectedRoutes.begin (); + k != m_injectedRoutes.end (); + k = m_injectedRoutes.erase (k)) + { + delete (*k); + } + for (ASExternalRoutesI l = m_ASexternalRoutes.begin (); + l != m_ASexternalRoutes.end (); + l = m_ASexternalRoutes.erase (l)) + { + delete (*l); + } + Ipv4RoutingProtocol::DoDispose (); } + void + Ipv4GlobalRouting::InjectRoute (Ipv4Address network, + Ipv4Mask networkMask) + { + NS_LOG_FUNCTION (network << networkMask); + Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry (); + // + // Interface number does not matter here, using 1. + // + *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network, + networkMask, + 1); + m_injectedRoutes.push_back (route); + } + + std::list + Ipv4GlobalRouting::GetInjectedRoutes () + { + return m_injectedRoutes; + } + Ptr Ipv4GlobalRouting::RouteOutput (Ptr p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr) { diff -crB routing/global-routing-old/ipv4-global-routing.h routing/global-routing/ipv4-global-routing.h *** routing/global-routing-old/ipv4-global-routing.h Mon Jul 13 13:42:54 2009 --- routing/global-routing/ipv4-global-routing.h Mon Jul 13 13:43:22 2009 *************** *** 146,151 **** --- 146,166 ---- Ipv4Mask networkMask, uint32_t interface); + /** + * \brief Add a network route to the global routing table. + * + * \param network The Ipv4Address network for this route. + * \param networkMask The Ipv4Mask to extract the network. + * \param interface The network interface index used to send packets to the + * destination. + * + * \see Ipv4Address + */ + void AddASExternalRouteTo (Ipv4Address network, + Ipv4Mask networkMask, + Ipv4Address forwardingRouter, + uint32_t interface); + /** * \brief Get the number of individual unicast routes that have been added * to the routing table. *************** *** 194,199 **** --- 209,237 ---- */ void RemoveRoute (uint32_t i); + /** + * \brief Inject a route to the global routing protocol as an external route + * + * Using AddNetworkRouteTo and similar functions only change the table on single node. + * Changes made here propagate throughout the GlobalRouting cloud. + * After packet reaches the local node, other routing protocol should be able to + * handle it, or the packets will be null-routed (discarded). + * + * \param Network The Network to inject + * \param Mask The Network Mask to inject + * + */ + void InjectRoute (Ipv4Address network, + Ipv4Mask networkMask); + + /** + * \brief Request a list of Injected Routes. Used by Global-route-manager. + * + * Obtain the list of routes injected with InjectRoute method. + * + */ + std::list GetInjectedRoutes (); + protected: void DoDispose (void); *************** *** 204,215 **** typedef std::list NetworkRoutes; typedef std::list::const_iterator NetworkRoutesCI; typedef std::list::iterator NetworkRoutesI; Ptr LookupGlobal (Ipv4Address dest); HostRoutes m_hostRoutes; NetworkRoutes m_networkRoutes; ! Ptr m_ipv4; }; --- 242,262 ---- typedef std::list NetworkRoutes; typedef std::list::const_iterator NetworkRoutesCI; typedef std::list::iterator NetworkRoutesI; + typedef std::list InjectedRoutes; + typedef std::list::const_iterator InjectedRoutesCI; + typedef std::list::iterator InjectedRoutesI; + typedef std::list ASExternalRoutes; + typedef std::list::const_iterator ASExternalRoutesCI; + typedef std::list::iterator ASExternalRoutesI; + Ptr LookupGlobal (Ipv4Address dest); HostRoutes m_hostRoutes; NetworkRoutes m_networkRoutes; ! InjectedRoutes m_injectedRoutes; // Routes we are exporting ! ASExternalRoutes m_ASexternalRoutes; // External routes imported ! Ptr m_ipv4; };