made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
authorCraig Dowell <craigdo@ee.washington.edu>
Tue, 10 Jul 2007 13:01:43 -0700
changeset 1061 007ef746ec4d
parent 1060 78028417caeb
child 1065 4850d9e9badd
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
src/routing/static-route-manager.cc
src/routing/static-router.cc
src/routing/static-router.h
--- a/src/routing/static-route-manager.cc	Tue Jul 10 12:38:51 2007 -0700
+++ b/src/routing/static-route-manager.cc	Tue Jul 10 13:01:43 2007 -0700
@@ -102,8 +102,12 @@
       Ptr<StaticRouter> rtr = 
         node->QueryInterface<StaticRouter> (StaticRouter::iid);
       NS_ASSERT_MSG(rtr, "QI for <StaticRouter> 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)
--- a/src/routing/static-router.cc	Tue Jul 10 12:38:51 2007 -0700
+++ b/src/routing/static-router.cc	Tue Jul 10 13:01:43 2007 -0700
@@ -184,12 +184,13 @@
 }
 
 //
-// 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, "<Node> interface not set");
   ClearLSAs ();
 //
@@ -208,7 +209,7 @@
 // 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 @@
 
       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 @@
   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.
 //
--- a/src/routing/static-router.h	Tue Jul 10 12:38:51 2007 -0700
+++ b/src/routing/static-router.h	Tue Jul 10 13:01:43 2007 -0700
@@ -185,7 +185,7 @@
    * 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> node);
   /**
@@ -198,21 +198,35 @@
    */
   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