Initialize LSDB for SPF runs

This commit is contained in:
Tom Henderson
2007-07-10 13:34:23 -07:00
parent 0fc2f3d86d
commit 42019fca7c
2 changed files with 31 additions and 5 deletions

View File

@@ -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<int, vector<int>, less<int> > pq;
//priority_queue<SPFVertex*, vector<SPFVertex*>, less<int> > 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();

View File

@@ -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<Ipv4Address, SPFVertex*> LSDBMap_t;
typedef std::pair<Ipv4Address, SPFVertex*> LSDBPair_t;