Iterate link records (16.1(2))
authorTom Henderson <tomh@tomh.org>
Tue, 10 Jul 2007 15:03:39 -0700
changeset 1067 704eb2583865
parent 1066 f19baa3a0cb5
child 1068 019229673fb4
Iterate link records (16.1(2))
src/routing/static-route-manager.cc
src/routing/static-route-manager.h
src/routing/static-router.cc
--- a/src/routing/static-route-manager.cc	Tue Jul 10 13:58:13 2007 -0700
+++ b/src/routing/static-route-manager.cc	Tue Jul 10 15:03:39 2007 -0700
@@ -79,6 +79,16 @@
 }
 
 void
+StaticRouteManagerLSDB::Insert(Ipv4Address addr, StaticRouterLSA* lsa)
+{
+    SPFVertex* temp = new SPFVertex ();
+    temp->m_lsa = lsa;
+    temp->m_vertexType = SPFVertex::VertexRouter;
+    temp->m_vertexId = lsa->m_linkStateId;
+    m_database.insert(LSDBPair_t(addr, temp));
+}
+
+void
 StaticRouteManagerLSDB::Insert(Ipv4Address addr, SPFVertex* vertex)
 {
     m_database.insert(LSDBPair_t(addr, vertex));
@@ -143,11 +153,12 @@
 
       for (uint32_t j = 0; j < numLSAs; ++j)
         {
-          StaticRouterLSA lsa;
-          rtr->GetLSA(j, lsa);
+          StaticRouterLSA* lsa = new StaticRouterLSA ();
+          rtr->GetLSA(j, *lsa);
           NS_DEBUG_UNCOND ("LSA " << j);
           NS_DEBUG_UNCOND ("----------------------------");
-          NS_DEBUG_UNCOND(lsa);
+          NS_DEBUG_UNCOND (*lsa);
+          m_lsdb->Insert (lsa->m_linkStateId, lsa); 
         }
     }
 }
@@ -192,7 +203,6 @@
   for (Iterator i = NodeList::Begin(); i != NodeList::End(); i++)
     {
       Ptr<Node> node = *i;
-      NS_DEBUG_UNCOND ("node="<< node->GetId () );
       
       Ptr<StaticRouter> rtr = 
         node->QueryInterface<StaticRouter> (StaticRouter::iid);
@@ -206,12 +216,49 @@
 
 
 // quagga ospf_spf_next
+// RFC2328 Section 16.1 (2).
+// v is on the SPF tree.  Examine the links in v's LSA.  Update the list
+// of candidates with any vertices not already on the list.  If a lower-cost
+// path is found to a vertex already on the candidate list, store the new cost.
+// 
+//
+//
 void
-StaticRouteManager::SPFNext()
+StaticRouteManager::SPFNext(SPFVertex* v /*,candidate */)
 {
-  // if LSA == Router_LSA, examine links
-  // a) if link to stub, skip
-  // b) W is transit
+  if (v->m_vertexType == SPFVertex::VertexRouter) 
+    {
+      // Always true for now, since all our LSAs are RouterLSAs
+      if (true)
+        {
+          NS_DEBUG_UNCOND("Examining " << v->m_vertexId << "'s link records");
+          for ( StaticRouterLSA::ListOfLinkRecords_t::iterator i = 
+                v->m_lsa->m_linkRecords.begin();
+                i != v->m_lsa->m_linkRecords.end();
+                i++ )
+            {
+              // (a) If this is a link to a stub network, examine the next
+              // link in V's LSA.  Links to stub networks will be
+              // considered in the second stage of the shortest path
+              // calculation. 
+              StaticRouterLinkRecord* temp = *i;
+              if (temp->m_linkType == StaticRouterLinkRecord::StubNetwork)
+                {
+                  NS_DEBUG_UNCOND("Found a Stub record to " << temp->m_linkId);
+                  continue;
+                }
+              if (temp->m_linkType == StaticRouterLinkRecord::PointToPoint)
+                {
+                  // Lookup the LSA (vertex) for the neighbor
+                  SPFVertex* w = m_lsdb->GetVertex(temp->m_linkId);
+                  NS_DEBUG_UNCOND("Found a P2P record from " << 
+                    v->m_vertexId << " to " << w->m_vertexId);
+                  continue;
+                }
+            }
+        } 
+     }
+     NS_DEBUG_UNCOND("");
 }
 
 // quagga ospf_spf_calculate
@@ -225,7 +272,7 @@
 void
 StaticRouteManager::SPFCalculate(Ipv4Address root)
 {
-  NS_DEBUG("StaticRouteManager::SPFCalculate ()");
+  NS_DEBUG_UNCOND("StaticRouteManager::SPFCalculate ()");
 
   // The SPFVertex objects may have state from a previous computation
   m_lsdb->Initialize();
@@ -242,11 +289,18 @@
   v= m_lsdb->GetVertex(root);
   // Set LSA position to LSA_SPF_IN_SPFTREE. This vertex is the root of the
   // spanning tree. 
+  NS_ASSERT(v);
   v->m_distanceFromRoot = 0;
   v->m_stat = true;
+
+  // Add all other vertices to the candidate list
   
+  for (;;)
+    {
+       SPFNext(v /*,candidate */);
+       break;
+    }
 #if 0
-  for (;;)
     {
       /* RFC2328 16.1. (2). */
       ospf_spf_next (v, area, candidate);
@@ -458,15 +512,19 @@
   SPFVertex* v0 = new SPFVertex ();
   v0->m_lsa = lsa0;
   v0->m_vertexType = SPFVertex::VertexRouter;
+  v0->m_vertexId = lsa0->m_linkStateId;
   SPFVertex* v1 = new SPFVertex ();
   v1->m_lsa = lsa1;
-  v0->m_vertexType = SPFVertex::VertexRouter;
+  v1->m_vertexType = SPFVertex::VertexRouter;
+  v1->m_vertexId = lsa1->m_linkStateId;
   SPFVertex* v2 = new SPFVertex ();
   v2->m_lsa = lsa2;
-  v0->m_vertexType = SPFVertex::VertexRouter;
+  v2->m_vertexType = SPFVertex::VertexRouter;
+  v2->m_vertexId = lsa2->m_linkStateId;
   SPFVertex* v3 = new SPFVertex ();
   v3->m_lsa = lsa3;
-  v0->m_vertexType = SPFVertex::VertexRouter;
+  v3->m_vertexType = SPFVertex::VertexRouter;
+  v3->m_vertexId = lsa3->m_linkStateId;
   
   // Test the database 
   StaticRouteManagerLSDB* srmlsdb = new StaticRouteManagerLSDB();
--- a/src/routing/static-route-manager.h	Tue Jul 10 13:58:13 2007 -0700
+++ b/src/routing/static-route-manager.h	Tue Jul 10 15:03:39 2007 -0700
@@ -68,6 +68,7 @@
 public:
   ~StaticRouteManagerLSDB ();
   void Insert(Ipv4Address addr, SPFVertex* vertex);
+  void Insert(Ipv4Address addr, StaticRouterLSA* lsa);
   SPFVertex* GetVertex (Ipv4Address addr);
   /**
    * \brief Set all SPFVertex to an initialized state, for SPF computation
@@ -116,12 +117,13 @@
   void DebugSPFCalculate (Ipv4Address root);
 
   virtual ~StaticRouteManager ();
+
 protected:
 
 private:
   StaticRouteManagerLSDB* m_lsdb;
   void SPFCalculate (Ipv4Address root);
-  void SPFNext ();
+  void SPFNext (SPFVertex*/*,candidate */);
 };
 
 } // namespace ns3
--- a/src/routing/static-router.cc	Tue Jul 10 13:58:13 2007 -0700
+++ b/src/routing/static-router.cc	Tue Jul 10 15:03:39 2007 -0700
@@ -49,6 +49,7 @@
       StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord;
       pDst->m_linkId = pSrc->m_linkId;
       pDst->m_linkData = pSrc->m_linkData;
+      pDst->m_linkType = pSrc->m_linkType;
       m_linkRecords.push_back(pDst);
       pDst = 0;
     }
@@ -71,6 +72,7 @@
       StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord;
       pDst->m_linkId = pSrc->m_linkId;
       pDst->m_linkData = pSrc->m_linkData;
+      pDst->m_linkType = pSrc->m_linkType;
       m_linkRecords.push_back(pDst);
       pDst = 0;
     }