delete vertices, fix candidate queue pop/top semantics
authorCraig Dowell <craigdo@ee.washington.edu>
Fri, 13 Jul 2007 12:21:48 -0700
changeset 1085 c12d61407468
parent 1084 0be920a99cc4
child 1086 43ea23238ce8
delete vertices, fix candidate queue pop/top semantics
src/routing/candidate-queue.cc
src/routing/candidate-queue.h
src/routing/static-route-manager.cc
src/routing/static-route-manager.h
--- a/src/routing/candidate-queue.cc	Thu Jul 12 22:15:59 2007 -0700
+++ b/src/routing/candidate-queue.cc	Fri Jul 13 12:21:48 2007 -0700
@@ -41,7 +41,9 @@
 
   while (!m_candidates.empty ())
     {
-      Pop ();
+      SPFVertex *p = Pop ();
+      delete p;
+      p = 0;
     }
 }
 
@@ -63,20 +65,19 @@
   m_candidates.insert(i, vNew);
 }
 
-  void
+  SPFVertex *
 CandidateQueue::Pop (void)
 {
   NS_DEBUG("CandidateQueue::Pop ()");
 
   if (m_candidates.empty ())
     {
-      return;
+      return 0;
     }
 
   SPFVertex *v = m_candidates.front ();
   m_candidates.pop_front ();
-  delete v;
-  v = 0;
+  return v;
 }
 
   SPFVertex *
--- a/src/routing/candidate-queue.h	Thu Jul 12 22:15:59 2007 -0700
+++ b/src/routing/candidate-queue.h	Fri Jul 13 12:21:48 2007 -0700
@@ -77,13 +77,15 @@
    */
   void          Push (SPFVertex *vNew);
   /**
-   * Pop the Shortest Path First Vertex pointer at the top of the queue and
-   * release the resources associated with the vertex.
+   * Pop the Shortest Path First Vertex pointer at the top of the queue.
+   * The caller is given the responsiblity for releasing the resources 
+   * associated with the vertex.
    *
    * @see SPFVertex
    * @see Top ()
+   * @returns The Shortest Path First Vertex pointer at the top of the queue.
    */
-  void          Pop (void);
+  SPFVertex*          Pop (void);
   /**
    * Return the Shortest Path First Vertex pointer at the top of the queue.  
    * This method does not pop the SPFVertex* off of the queue, it simply 
--- a/src/routing/static-route-manager.cc	Thu Jul 12 22:15:59 2007 -0700
+++ b/src/routing/static-route-manager.cc	Fri Jul 13 12:21:48 2007 -0700
@@ -51,9 +51,18 @@
 {
 }
 
-
 SPFVertex::~SPFVertex ()
 {
+  for ( t_listOfSPFVertex::iterator i = m_children.begin ();
+        i != m_children.end (); 
+        i++)
+    {
+      SPFVertex *p = *i;
+      delete p;
+      p = 0;
+      *i = 0;
+    }
+  m_children.clear();
 }
 
 StaticRouteManagerLSDB::~StaticRouteManagerLSDB()
@@ -89,7 +98,7 @@
 void
 StaticRouteManagerLSDB::Insert(Ipv4Address addr, StaticRouterLSA* lsa)
 {
-    m_database.insert(LSDBPair_t(addr, lsa));
+  m_database.insert(LSDBPair_t(addr, lsa));
 }
 
 StaticRouterLSA*
@@ -153,8 +162,7 @@
         {
           StaticRouterLSA* lsa = new StaticRouterLSA ();
           rtr->GetLSA(j, *lsa);
-          NS_DEBUG_UNCOND ("LSA " << j);
-          NS_DEBUG_UNCOND ("----------------------------");
+          NS_DEBUG_UNCOND ("*** LSA " << j);
           NS_DEBUG_UNCOND (*lsa);
           m_lsdb->Insert (lsa->m_linkStateId, lsa); 
         }
@@ -424,8 +432,7 @@
  *                   tree (removing it from the candidate list in the
  *                            process). */
       /* Extract from the candidates the node with the lower key. */
-      v = candidate.Top();
-      candidate.Pop();
+      v = candidate.Pop();
       /* Update stat field in vertex. */
       v->m_lsa->m_stat = StaticRouterLSA::LSA_SPF_IN_SPFTREE;
       SPFVertexAddParent(v);
@@ -448,7 +455,7 @@
   ospf_spf_process_stubs (area, area->spf, new_table);
 #endif
 
-  DeleteSPFVertexChain(m_spfroot);  
+  delete m_spfroot;
   m_spfroot = 0;
 }
 
@@ -508,33 +515,26 @@
             "StaticRouteManager::SPFIntraAddRouter (): "
             "Expected exen number of Link Records");
 
-          for (uint32_t j = 0; j < nLinkRecords; j += 2)
+          for (uint32_t j = 0; j < nLinkRecords; ++j)
             {
-              StaticRouterLinkRecord *lrp2p = lsa->GetLinkRecord (j);
-              NS_ASSERT_MSG(
-                lrp2p->m_linkType == StaticRouterLinkRecord::PointToPoint,
-                "StaticRouteManager::SPFIntraAddRouter (): "
-                "Expected PointToPoint Link Record");
-
-              StaticRouterLinkRecord *lrstub = lsa->GetLinkRecord (j + 1);
-              NS_ASSERT_MSG(
-                lrstub->m_linkType == StaticRouterLinkRecord::StubNetwork,
-                "StaticRouteManager::SPFIntraAddRouter (): "
-                "Expected StubNetwork Link Record");
+              StaticRouterLinkRecord *lr = lsa->GetLinkRecord (j);
+              if (lr->m_linkType != StaticRouterLinkRecord::PointToPoint)
+                {
+                  continue;
+                }
 //
-// BUGBUG
+// BUGBUG This is not right.  Need to find the next hop interface correctly
 //
-// Where does the next hop address come from?
-//
-              NS_ASSERT_MSG(false, "BUGBUG");
+              NS_DEBUG_UNCOND("StaticRouteManager::SPFIntraAddRouter (): "
+                "BUGBUG incorrect next hope calculation");
 
               NS_DEBUG_UNCOND("StaticRouteManager::SPFIntraAddRouter (): "
-                "Add route to " << lrp2p->m_linkData <<
-                " using next hop " << lrp2p->m_linkData <<
+                "Add route to " << lr->m_linkData <<
+                " using next hop " << lr->m_linkData <<
                 " via interface " << v->m_root_oif);
 
-              ipv4->AddHostRouteTo(lrp2p->m_linkData, lrp2p->m_linkData, 
-                v->m_root_oif);
+              ipv4->AddHostRouteTo(lr->m_linkData, 
+                lr->m_linkData, v->m_root_oif);
             }
           break;
         }
@@ -549,15 +549,6 @@
   v->m_parent->m_children.push_back(v);
 }
 
-void
-StaticRouteManager::DeleteSPFVertexChain(SPFVertex* spfroot)
-{
-  // spfroot is the root of all SPFVertex created during the SPF process
-  // each vertex has a list of children
-  // Recursively, delete all of the SPFVertex children of each SPFVertex
-  // then delete root itself
-}
-
 } // namespace ns3
 
 #ifdef RUN_SELF_TESTS
@@ -621,12 +612,13 @@
 
   for (int i = 0; i < 100; ++i)
     {
-      SPFVertex *v = candidate.Top ();
-      candidate.Pop ();
+      SPFVertex *v = candidate.Pop ();
       if (v->m_distanceFromRoot < lastDistance)
         {
           ok = false;
         }
+      delete v;
+      v = 0;
       lastDistance = v->m_distanceFromRoot;
     }
 
--- a/src/routing/static-route-manager.h	Thu Jul 12 22:15:59 2007 -0700
+++ b/src/routing/static-route-manager.h	Fri Jul 13 12:21:48 2007 -0700
@@ -62,7 +62,6 @@
 
   uint32_t m_distanceFromRoot;
   uint32_t m_root_oif;
-
 };
 
 /**