From 42019fca7cd22d6e662865b92f82d0ee25d62fc3 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 10 Jul 2007 13:34:23 -0700 Subject: [PATCH] Initialize LSDB for SPF runs --- src/routing/static-route-manager.cc | 31 ++++++++++++++++++++++++----- src/routing/static-route-manager.h | 5 +++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/routing/static-route-manager.cc b/src/routing/static-route-manager.cc index b7bb13f3f..ed8c68c3d 100644 --- a/src/routing/static-route-manager.cc +++ b/src/routing/static-route-manager.cc @@ -41,6 +41,14 @@ SPFVertex::~SPFVertex () delete m_lsa; } +void +SPFVertex::Initialize () +{ + m_distanceFromRoot = SPF_INFINITY; + m_stat = false; + // XXX previous = 0 +} + StaticRouteManagerLSDB::~StaticRouteManagerLSDB() { @@ -48,7 +56,7 @@ StaticRouteManagerLSDB::~StaticRouteManagerLSDB() 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; @@ -57,6 +65,19 @@ StaticRouteManagerLSDB::~StaticRouteManagerLSDB() m_database.clear(); } +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) { @@ -201,6 +222,10 @@ void 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, less > pq; //priority_queue, less > candidate; @@ -420,19 +445,15 @@ StaticRouteManagerTest::RunTests (void) 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(); diff --git a/src/routing/static-route-manager.h b/src/routing/static-route-manager.h index 861da5c13..84b1a2e29 100644 --- a/src/routing/static-route-manager.h +++ b/src/routing/static-route-manager.h @@ -38,6 +38,7 @@ class SPFVertex public: SPFVertex(); ~SPFVertex(); + void Initialize (); enum VertexType { VertexUnknown = 0, @@ -68,6 +69,10 @@ public: ~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 LSDBMap_t; typedef std::pair LSDBPair_t;