Add candidate list (priority queue)
authorTom Henderson <tomh@tomh.org>
Tue, 10 Jul 2007 23:10:18 -0700
changeset 1072 7002990baec9
parent 1070 fa5ec2180ec4
child 1073 2dc7d2dfd6a4
Add candidate list (priority queue)
src/routing/static-route-manager.cc
src/routing/static-route-manager.h
--- a/src/routing/static-route-manager.cc	Tue Jul 10 17:59:11 2007 -0700
+++ b/src/routing/static-route-manager.cc	Tue Jul 10 23:10:18 2007 -0700
@@ -32,7 +32,7 @@
   m_vertexId("255.255.255.255"), 
   m_lsa(0),
   m_distanceFromRoot(SPF_INFINITY), 
-  m_stat(false)
+  m_stat(LSA_SPF_NOT_EXPLORED)
 {
 }
 
@@ -45,7 +45,7 @@
 SPFVertex::Initialize ()
 {
   m_distanceFromRoot = SPF_INFINITY;
-  m_stat = false;
+  m_stat = LSA_SPF_NOT_EXPLORED;
   // XXX previous = 0
 }
 
@@ -223,7 +223,7 @@
 //
 //
 void
-StaticRouteManager::SPFNext(SPFVertex* v /*,candidate */)
+StaticRouteManager::SPFNext(SPFVertex* v, SPFVertexPriorityQueue& candidate)
 {
   if (v->m_vertexType == SPFVertex::VertexRouter) 
     {
@@ -258,7 +258,7 @@
                     v->m_vertexId << " to " << w->m_vertexId);
                   // (c) If vertex W is already on the shortest-path tree, 
                   //  examine the next link in the LSA. 
-                  if (w->m_stat == true) 
+                  if (w->m_stat == LSA_SPF_IN_SPFTREE) 
                     {
                       continue;
                     }
@@ -268,7 +268,7 @@
                   // shortest path to vertex V and the advertised cost of 
                   // the link between vertices V and W.  
                   
-//                  uint32_t distance = v->m_distanceFromRoot + temp->m_metric;
+                  //uint32_t distance = v->m_distanceFromRoot + temp->m_metric;
 
                   // Here, W is either already in candidate list or not
 
@@ -315,10 +315,12 @@
   m_lsdb->Initialize();
   SPFVertex* v;
 
-  // Make a priority queue of int using a vector container
-  //    priority_queue<int, vector<int>, less<int> > pq;
+  // The candidate queue is a priority queue of SPFVertex objects, with
+  // the top of the queue being the closest vertex in terms of 
+  // distanceFromRoot.  Initially, this queue is empty.
   //
-  //priority_queue<SPFVertex*> candidate;
+  SPFVertexPriorityQueue candidate;
+  NS_ASSERT(candidate.size() == 0);
   //
   // Initialize the shortest-path tree to only the router doing the 
   // calculation.
@@ -328,16 +330,12 @@
   // spanning tree. 
   NS_ASSERT(v);
   v->m_distanceFromRoot = 0;
-  v->m_stat = true;
+  v->m_stat = LSA_SPF_IN_SPFTREE;
 
-  // Add all other vertices to the candidate list
-  // XXX todo
-  
   for (;;)
     {
       // RFC2328 16.1. (2). 
-      SPFNext(v /*,candidate */);
-
+      SPFNext(v , candidate);
 #if 0
       /* RFC2328 16.1. (3). */
       /* If at this step the candidate list is empty, the shortest-
--- a/src/routing/static-route-manager.h	Tue Jul 10 17:59:11 2007 -0700
+++ b/src/routing/static-route-manager.h	Tue Jul 10 23:10:18 2007 -0700
@@ -29,6 +29,8 @@
 
 const uint32_t SPF_INFINITY = 0xffffffff;
 
+const int LSA_SPF_NOT_EXPLORED = -1;
+const int LSA_SPF_IN_SPFTREE = -2;
 /**
  * \brief Vertex used in shortest path first (SPF) computations
  *
@@ -51,6 +53,8 @@
 
   StaticRouterLSA* m_lsa;  // This pointer owns LSA for mem. mgmt purposes
 
+  // XXX not sure exactly what data structure is needed here
+  // need to keep track of previous vertex
   typedef std::list<SPFVertex> type_listOfSPFVertex;
   type_listOfSPFVertex m_parents;
   type_listOfSPFVertex m_children;
@@ -58,7 +62,8 @@
 
   uint32_t m_distanceFromRoot;
 
-  bool m_stat;  // true if LSA is in SPF tree already
+  // If stat >= 0, stat is LSA position in candidates heap
+  int m_stat;  
 
   struct Greater : public std::binary_function< SPFVertex*, SPFVertex*, bool>
   {
@@ -136,7 +141,7 @@
 private:
   StaticRouteManagerLSDB* m_lsdb;
   void SPFCalculate (Ipv4Address root);
-  void SPFNext (SPFVertex*/*,candidate */);
+  void SPFNext (SPFVertex*, SPFVertexPriorityQueue&);
 };
 
 } // namespace ns3