From b10355c846476624088a60ed4329f9635d4eec44 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Tue, 10 Jul 2007 13:01:43 -0700 Subject: [PATCH] made GetNumLSAs cheap, added DiscoverLSAs as expensive call. --- src/routing/static-route-manager.cc | 8 ++++++-- src/routing/static-router.cc | 20 ++++++++++++++------ src/routing/static-router.h | 24 +++++++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/routing/static-route-manager.cc b/src/routing/static-route-manager.cc index 867baeadd..cecd0d9cf 100644 --- a/src/routing/static-route-manager.cc +++ b/src/routing/static-route-manager.cc @@ -102,8 +102,12 @@ StaticRouteManager::BuildStaticRoutingDatabase () Ptr rtr = node->QueryInterface (StaticRouter::iid); NS_ASSERT_MSG(rtr, "QI for interface failed"); - - uint32_t numLSAs = rtr->GetNumLSAs(); +// +// Should call DiscoverLSAs () before trying to use any routing info or to +// update LSAs. Subsequently you may use GetNumLSAs(). If you call +// GetNumLSAs () before calling DiscoverLSAs () will get zero as the number. +// + uint32_t numLSAs = rtr->DiscoverLSAs(); NS_DEBUG_UNCOND ("Found " << numLSAs << " LSAs"); for (uint32_t j = 0; j < numLSAs; ++j) diff --git a/src/routing/static-router.cc b/src/routing/static-router.cc index 6f1fd245b..f8ff27657 100644 --- a/src/routing/static-router.cc +++ b/src/routing/static-router.cc @@ -184,12 +184,13 @@ StaticRouter::ClearLSAs () } // -// Return the number of Link State Advertisements this node has to advertise. +// Go out and discover any adjacent routers and build the Link State +// Advertisements that reflect them and their associated networks. // uint32_t -StaticRouter::GetNumLSAs (void) +StaticRouter::DiscoverLSAs (void) { - NS_DEBUG("StaticRouter::GetNumLSAs ()"); + NS_DEBUG("StaticRouter::DiscoverLSAs ()"); NS_ASSERT_MSG(m_node, " interface not set"); ClearLSAs (); // @@ -208,7 +209,7 @@ StaticRouter::GetNumLSAs (void) // a point-to-point channel. // uint32_t numDevices = m_node->GetNDevices(); - NS_DEBUG("StaticRouter::GetNumLSAs (): numDevices = " << numDevices); + NS_DEBUG("StaticRouter::DiscoverLSAs (): numDevices = " << numDevices); // // Loop through the devices looking for those connected to a point-to-point // channel. @@ -219,11 +220,11 @@ StaticRouter::GetNumLSAs (void) if (!ndLocal->IsPointToPoint ()) { - NS_DEBUG("StaticRouter::GetNumLSAs (): non-point-to-point device"); + NS_DEBUG("StaticRouter::DiscoverLSAs (): non-point-to-point device"); continue; } - NS_DEBUG("StaticRouter::GetNumLSAs (): Point-to-point device"); + NS_DEBUG("StaticRouter::DiscoverLSAs (): Point-to-point device"); // // Now, we have to find the Ipv4 interface whose netdevice is the one we // just found. This is still the IP on the local side of the channel. There @@ -304,6 +305,13 @@ StaticRouter::GetNumLSAs (void) return m_LSAs.size (); } + uint32_t +StaticRouter::GetNumLSAs (void) +{ + NS_DEBUG("StaticRouter::GetNumLSAs ()"); + return m_LSAs.size (); +} + // // Get the nth link state advertisement from this router. // diff --git a/src/routing/static-router.h b/src/routing/static-router.h index 0d0cd09ac..f3273c311 100644 --- a/src/routing/static-router.h +++ b/src/routing/static-router.h @@ -185,7 +185,7 @@ public: * Create a Static Router class and aggregate its interface onto the Node * provided. * - * @param lsa The existing Node onto which this router will be aggregated. + * @param node The existing Node onto which this router will be aggregated. */ StaticRouter (Ptr node); /** @@ -198,21 +198,35 @@ public: */ Ipv4Address GetRouterId(void); /** - * Get the Number of Static Router Link State Advertisements that this - * router can export. + * Walk the connected channels, discover the adjacent routers and build + * the associated number of Static Router Link State Advertisements that + * this router can export. * * This is a fairly expensive operation in that every time it is called * the current list of LSAs is built by walking connected point-to-point * channels and peeking into adjacent IPV4 stacks to get address information. * This is done to allow for limited dymanics of the Static Routing * environment. By that we mean that you can discover new link state - * advertisements after a network topology change by calling GetNumLSAs and - * then by reading those advertisements. + * advertisements after a network topology change by calling DiscoverLSAs + * and then by reading those advertisements. * * @see StaticRouterLSA * @see StaticRouter::GetLSA () * @returns The number of Static Router Link State Advertisements. */ + uint32_t DiscoverLSAs (void); + /** + * Get the Number of Static Router Link State Advertisements that this + * router can export. To get meaningful information you must have + * previously called DiscoverLSAs. After you know how many LSAs are + * present in the router, you may call GetLSA () to retrieve the actual + * advertisement. + * + * @see StaticRouterLSA + * @see StaticRouter::DiscoverLSAs () + * @see StaticRouter::GetLSA () + * @returns The number of Static Router Link State Advertisements. + */ uint32_t GetNumLSAs (void); /** * Get a Static Router Link State Advertisements that this router has said