Initialize LSDB for SPF runs
authorTom Henderson <tomh@tomh.org>
Tue, 10 Jul 2007 13:34:23 -0700
changeset 1063 98fe4e27c65a
parent 1062 ea9b7839421d
child 1064 25e962f8ac4c
Initialize LSDB for SPF runs
src/routing/static-route-manager.cc
src/routing/static-route-manager.h
--- a/src/routing/static-route-manager.cc	Tue Jul 10 13:28:07 2007 -0700
+++ b/src/routing/static-route-manager.cc	Tue Jul 10 13:34:23 2007 -0700
@@ -41,6 +41,14 @@
   delete m_lsa;
 }
 
+void
+SPFVertex::Initialize ()
+{
+  m_distanceFromRoot = SPF_INFINITY;
+  m_stat = false;
+  // XXX previous = 0
+}
+
 
 StaticRouteManagerLSDB::~StaticRouteManagerLSDB()
 {
@@ -48,7 +56,7 @@
 
   LSDBMap_t::iterator i;
   for (i= m_database.begin(); i!= m_database.end(); i++)
-  {
+    {
       NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB():free vertex");
       SPFVertex* temp = i->second;
       delete temp;
@@ -58,6 +66,19 @@
 }
 
 void
+StaticRouteManagerLSDB::Initialize()
+{
+  NS_DEBUG("StaticRouteManagerLSDB::Initialize ()");
+
+  LSDBMap_t::iterator i;
+  for (i= m_database.begin(); i!= m_database.end(); i++)
+    {
+      SPFVertex* temp = i->second;
+      temp->Initialize();
+    }
+}
+
+void
 StaticRouteManagerLSDB::Insert(Ipv4Address addr, SPFVertex* vertex)
 {
     m_database.insert(LSDBPair_t(addr, vertex));
@@ -201,6 +222,10 @@
 StaticRouteManager::SPFCalculate(Ipv4Address root)
 {
   NS_DEBUG("StaticRouteManager::SPFCalculate ()");
+
+  // The SPFVertex objects may have state from a previous computation
+  m_lsdb->Initialize();
+
    // Make a priority queue of int using a vector container
    //    priority_queue<int, vector<int>, less<int> > pq;
   //priority_queue<SPFVertex*, vector<SPFVertex*>, less<int> > candidate;
@@ -420,19 +445,15 @@
   SPFVertex* v0 = new SPFVertex ();
   v0->m_lsa = lsa0;
   v0->m_vertexType = SPFVertex::VertexRouter;
-  v0->m_distanceFromRoot = 0xffffffff;
   SPFVertex* v1 = new SPFVertex ();
   v1->m_lsa = lsa1;
   v0->m_vertexType = SPFVertex::VertexRouter;
-  v0->m_distanceFromRoot = 0xffffffff;
   SPFVertex* v2 = new SPFVertex ();
   v2->m_lsa = lsa2;
   v0->m_vertexType = SPFVertex::VertexRouter;
-  v0->m_distanceFromRoot = 0xffffffff;
   SPFVertex* v3 = new SPFVertex ();
   v3->m_lsa = lsa3;
   v0->m_vertexType = SPFVertex::VertexRouter;
-  v0->m_distanceFromRoot = 0xffffffff;
   
   // Test the database 
   StaticRouteManagerLSDB* srmlsdb = new StaticRouteManagerLSDB();
--- a/src/routing/static-route-manager.h	Tue Jul 10 13:28:07 2007 -0700
+++ b/src/routing/static-route-manager.h	Tue Jul 10 13:34:23 2007 -0700
@@ -38,6 +38,7 @@
 public:
   SPFVertex();
   ~SPFVertex();
+  void Initialize ();
 
   enum VertexType {
     VertexUnknown = 0,
@@ -68,6 +69,10 @@
   ~StaticRouteManagerLSDB ();
   void Insert(Ipv4Address addr, SPFVertex* vertex);
   SPFVertex* GetVertex (Ipv4Address addr);
+  /**
+   * \brief Set all SPFVertex to an initialized state, for SPF computation
+   */
+  void Initialize ();
 
   typedef std::map<Ipv4Address, SPFVertex*> LSDBMap_t;
   typedef std::pair<Ipv4Address, SPFVertex*> LSDBPair_t;