General cleanup -- const correctness, encapsulation, documentation, etc.
This commit is contained in:
@@ -81,7 +81,7 @@ CandidateQueue::Pop (void)
|
||||
}
|
||||
|
||||
SPFVertex *
|
||||
CandidateQueue::Top (void)
|
||||
CandidateQueue::Top (void) const
|
||||
{
|
||||
NS_DEBUG("CandidateQueue::Top ()");
|
||||
|
||||
@@ -94,7 +94,7 @@ CandidateQueue::Top (void)
|
||||
}
|
||||
|
||||
bool
|
||||
CandidateQueue::Empty (void)
|
||||
CandidateQueue::Empty (void) const
|
||||
{
|
||||
NS_DEBUG("CandidateQueue::Empty ()");
|
||||
|
||||
@@ -102,7 +102,7 @@ CandidateQueue::Empty (void)
|
||||
}
|
||||
|
||||
uint32_t
|
||||
CandidateQueue::Size (void)
|
||||
CandidateQueue::Size (void) const
|
||||
{
|
||||
NS_DEBUG("CandidateQueue::Size ()");
|
||||
|
||||
@@ -110,11 +110,11 @@ CandidateQueue::Size (void)
|
||||
}
|
||||
|
||||
SPFVertex *
|
||||
CandidateQueue::Find (const Ipv4Address addr)
|
||||
CandidateQueue::Find (const Ipv4Address addr) const
|
||||
{
|
||||
NS_DEBUG("CandidateQueue::Find ()");
|
||||
|
||||
CandidateList_t::iterator i = m_candidates.begin ();
|
||||
CandidateList_t::const_iterator i = m_candidates.begin ();
|
||||
|
||||
for (; i != m_candidates.end (); i++)
|
||||
{
|
||||
|
||||
@@ -95,13 +95,13 @@ public:
|
||||
* @see Pop ()
|
||||
* @returns The Shortest Path First Vertex pointer at the top of the queue.
|
||||
*/
|
||||
SPFVertex* Top (void);
|
||||
SPFVertex* Top (void) const;
|
||||
/**
|
||||
* Test the Candidate Queue to determine if it is empty.
|
||||
*
|
||||
* @returns True if the queue is empty, false otherwise.
|
||||
*/
|
||||
bool Empty (void);
|
||||
bool Empty (void) const;
|
||||
/**
|
||||
* Return the number of Shortest Path First Vertex pointers presently
|
||||
* stored in the Candidate Queue.
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
* @see SPFVertex
|
||||
* @returns The number of SPFVertex* pointers in the Candidate Queue.
|
||||
*/
|
||||
uint32_t Size (void);
|
||||
uint32_t Size (void) const;
|
||||
/**
|
||||
* Searches the Candidate Queue for a Shortest Path First Vertex pointer
|
||||
* that points to a vertex having the given IP address.
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
* @param addr The IP address to search for.
|
||||
* @returns The SPFVertex* pointer corresponding to the given IP address.
|
||||
*/
|
||||
SPFVertex* Find (const Ipv4Address addr);
|
||||
SPFVertex* Find (const Ipv4Address addr) const;
|
||||
/**
|
||||
* Reorders the Candidate Queue according to the priority scheme. On
|
||||
* completion, the top of the queue will hold the Shortest Path First
|
||||
|
||||
@@ -44,7 +44,7 @@ SPFVertex::SPFVertex () :
|
||||
|
||||
SPFVertex::SPFVertex (StaticRouterLSA* lsa) :
|
||||
m_vertexType (VertexRouter),
|
||||
m_vertexId (lsa->m_linkStateId),
|
||||
m_vertexId (lsa->GetLinkStateId ()),
|
||||
m_lsa (lsa),
|
||||
m_parent (0),
|
||||
m_children (),
|
||||
@@ -92,7 +92,7 @@ StaticRouteManagerLSDB::Initialize ()
|
||||
for (i= m_database.begin (); i!= m_database.end (); i++)
|
||||
{
|
||||
StaticRouterLSA* temp = i->second;
|
||||
temp->m_stat = StaticRouterLSA::LSA_SPF_NOT_EXPLORED;
|
||||
temp->SetStatus (StaticRouterLSA::LSA_SPF_NOT_EXPLORED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ StaticRouteManager::BuildStaticRoutingDatabase ()
|
||||
//
|
||||
// Write the newly discovered link state advertisement to the database.
|
||||
//
|
||||
m_lsdb->Insert (lsa->m_linkStateId, lsa);
|
||||
m_lsdb->Insert (lsa->GetLinkStateId (), lsa);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,26 +291,23 @@ StaticRouteManager::SPFNext (SPFVertex* v, CandidateQueue& candidate)
|
||||
if (true)
|
||||
{
|
||||
NS_DEBUG ("SPFNext: Examining " << v->m_vertexId << "'s " <<
|
||||
v->m_lsa->m_linkRecords.size () << " link records");
|
||||
v->m_lsa->GetNLinkRecords () << " link records");
|
||||
//
|
||||
// Walk the list of link records in the link state advertisement associated
|
||||
// with the "current" router (represented by vertex <v>).
|
||||
//
|
||||
for (StaticRouterLSA::ListOfLinkRecords_t::iterator i =
|
||||
v->m_lsa->m_linkRecords.begin ();
|
||||
i != v->m_lsa->m_linkRecords.end ();
|
||||
i++)
|
||||
for (uint32_t i = 0; i < v->m_lsa->GetNLinkRecords (); ++i)
|
||||
{
|
||||
//
|
||||
// (a) If this is a link to a stub network, examine the next link in V's LSA.
|
||||
// Links to stub networks will be considered in the second stage of the
|
||||
// shortest path calculation.
|
||||
//
|
||||
StaticRouterLinkRecord* l = *i;
|
||||
if (l->m_linkType == StaticRouterLinkRecord::StubNetwork)
|
||||
StaticRouterLinkRecord *l = v->m_lsa->GetLinkRecord (i);
|
||||
if (l->GetLinkType () == StaticRouterLinkRecord::StubNetwork)
|
||||
{
|
||||
NS_DEBUG ("SPFNext: Found a Stub record to "
|
||||
<< l->m_linkId);
|
||||
NS_DEBUG ("SPFNext: Found a Stub record to " <<
|
||||
l->GetLinkId ());
|
||||
continue;
|
||||
}
|
||||
//
|
||||
@@ -318,16 +315,16 @@ StaticRouteManager::SPFNext (SPFVertex* v, CandidateQueue& candidate)
|
||||
// the vertex W's LSA (router-LSA or network-LSA) in Area A's link state
|
||||
// database.
|
||||
//
|
||||
if (l->m_linkType == StaticRouterLinkRecord::PointToPoint)
|
||||
if (l->GetLinkType () == StaticRouterLinkRecord::PointToPoint)
|
||||
{
|
||||
//
|
||||
// Lookup the link state advertisement of the new link -- we call it <w> in
|
||||
// the link state database.
|
||||
//
|
||||
w_lsa = m_lsdb->GetLSA (l->m_linkId);
|
||||
w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
|
||||
NS_ASSERT (w_lsa);
|
||||
NS_DEBUG ("SPFNext: Found a P2P record from " <<
|
||||
v->m_vertexId << " to " << w_lsa->m_linkStateId);
|
||||
v->m_vertexId << " to " << w_lsa->GetLinkStateId ());
|
||||
//
|
||||
// (c) If vertex W is already on the shortest-path tree, examine the next
|
||||
// link in the LSA.
|
||||
@@ -335,10 +332,11 @@ StaticRouteManager::SPFNext (SPFVertex* v, CandidateQueue& candidate)
|
||||
// If the link is to a router that is already in the shortest path first tree
|
||||
// then we have it covered -- ignore it.
|
||||
//
|
||||
if (w_lsa->m_stat == StaticRouterLSA::LSA_SPF_IN_SPFTREE)
|
||||
if (w_lsa->GetStatus () ==
|
||||
StaticRouterLSA::LSA_SPF_IN_SPFTREE)
|
||||
{
|
||||
NS_DEBUG ("SPFNext: Skipping-> LSA "<<
|
||||
w_lsa->m_linkStateId << " already in SPF tree");
|
||||
w_lsa->GetLinkStateId () << " already in SPF tree");
|
||||
continue;
|
||||
}
|
||||
//
|
||||
@@ -349,12 +347,13 @@ StaticRouteManager::SPFNext (SPFVertex* v, CandidateQueue& candidate)
|
||||
// calculated) shortest path to vertex V and the advertised cost of the link
|
||||
// between vertices V and W.
|
||||
//
|
||||
distance = v->m_distanceFromRoot + l->m_metric;
|
||||
distance = v->m_distanceFromRoot + l->GetMetric ();
|
||||
|
||||
NS_DEBUG ("SPFNext: Considering w_lsa " <<
|
||||
w_lsa->m_linkStateId);
|
||||
w_lsa->GetLinkStateId ());
|
||||
|
||||
if (w_lsa->m_stat == StaticRouterLSA::LSA_SPF_NOT_EXPLORED)
|
||||
if (w_lsa->GetStatus () ==
|
||||
StaticRouterLSA::LSA_SPF_NOT_EXPLORED)
|
||||
{
|
||||
//
|
||||
// If we havent yet considered the link represented by <w> we have to create
|
||||
@@ -369,7 +368,8 @@ StaticRouteManager::SPFNext (SPFVertex* v, CandidateQueue& candidate)
|
||||
//
|
||||
if (SPFNexthopCalculation (v, w, l, distance))
|
||||
{
|
||||
w_lsa->m_stat = StaticRouterLSA::LSA_SPF_CANDIDATE;
|
||||
w_lsa->SetStatus (
|
||||
StaticRouterLSA::LSA_SPF_CANDIDATE);
|
||||
//
|
||||
// Push this new vertex onto the priority queue (ordered by distance from the
|
||||
// root node).
|
||||
@@ -379,8 +379,8 @@ StaticRouteManager::SPFNext (SPFVertex* v, CandidateQueue& candidate)
|
||||
<< ", parent vertexId: " << v->m_vertexId);
|
||||
}
|
||||
}
|
||||
} else if (w_lsa->m_stat ==
|
||||
StaticRouterLSA::LSA_SPF_CANDIDATE)
|
||||
} else if (w_lsa->GetStatus () ==
|
||||
StaticRouterLSA::LSA_SPF_CANDIDATE)
|
||||
{
|
||||
//
|
||||
// We have already considered the link represented by <w>. What wse have to
|
||||
@@ -389,7 +389,7 @@ StaticRouteManager::SPFNext (SPFVertex* v, CandidateQueue& candidate)
|
||||
//
|
||||
// So, locate the vertex in the candidate queue and take a look at the
|
||||
// distance.
|
||||
w = candidate.Find (w_lsa->m_linkStateId);
|
||||
w = candidate.Find (w_lsa->GetLinkStateId ());
|
||||
if (w->m_distanceFromRoot < distance)
|
||||
{
|
||||
//
|
||||
@@ -507,13 +507,13 @@ StaticRouteManager::SPFNexthopCalculation (
|
||||
// from the root node to the host represented by vertex <w>, you have to send
|
||||
// the packet to the next hop address specified in w->m_nextHop.
|
||||
//
|
||||
w->m_nextHop = linkRemote->m_linkData;
|
||||
w->m_nextHop = linkRemote->GetLinkData ();
|
||||
//
|
||||
// Now find the outgoing interface corresponding to the point to point link
|
||||
// from the perspective of <v> -- remember that <l> is the link "from"
|
||||
// <v> "to" <w>.
|
||||
//
|
||||
w->m_rootOif = FindOutgoingInterfaceId (l->m_linkData);
|
||||
w->m_rootOif = FindOutgoingInterfaceId (l->GetLinkData ());
|
||||
|
||||
NS_DEBUG ("SPFNexthopCalculation: Next hop from " <<
|
||||
v->m_vertexId << " to " << w->m_vertexId <<
|
||||
@@ -587,13 +587,10 @@ StaticRouteManager::SPFGetNextLink (
|
||||
// <v> looking for records representing the point-to-point links off of this
|
||||
// vertex.
|
||||
//
|
||||
for ( StaticRouterLSA::ListOfLinkRecords_t::iterator i =
|
||||
v->m_lsa->m_linkRecords.begin ();
|
||||
i != v->m_lsa->m_linkRecords.end ();
|
||||
i++ )
|
||||
for (uint32_t i = 0; i < v->m_lsa->GetNLinkRecords (); ++i)
|
||||
{
|
||||
l = *i;
|
||||
if (l->m_linkType != StaticRouterLinkRecord::PointToPoint)
|
||||
l = v->m_lsa->GetLinkRecord (i);
|
||||
if (l->GetLinkType () != StaticRouterLinkRecord::PointToPoint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -605,9 +602,9 @@ StaticRouteManager::SPFGetNextLink (
|
||||
// We're just checking to see if the link <l> is actually the link from <v> to
|
||||
// <w>.
|
||||
//
|
||||
if (l->m_linkId == w->m_vertexId) {
|
||||
NS_DEBUG ("SPFGetNextLink: Found matching link l: linkId=" <<
|
||||
l->m_linkId << " linkData=" << l->m_linkData);
|
||||
if (l->GetLinkId () == w->m_vertexId) {
|
||||
NS_DEBUG ("SPFGetNextLink: Found matching link l: linkId = " <<
|
||||
l->GetLinkId () << " linkData = " << l->GetLinkData ());
|
||||
//
|
||||
// If skip is false, don't (not too surprisingly) skip the link found -- it's
|
||||
// the one we're interested in. That's either because we didn't pass in a
|
||||
@@ -676,7 +673,7 @@ StaticRouteManager::SPFCalculate (Ipv4Address root)
|
||||
//
|
||||
m_spfroot= v;
|
||||
v->m_distanceFromRoot = 0;
|
||||
v->m_lsa->m_stat = StaticRouterLSA::LSA_SPF_IN_SPFTREE;
|
||||
v->m_lsa->SetStatus (StaticRouterLSA::LSA_SPF_IN_SPFTREE);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@@ -721,7 +718,7 @@ StaticRouteManager::SPFCalculate (Ipv4Address root)
|
||||
// Update the status field of the vertex to indicate that it is in the SPF
|
||||
// tree.
|
||||
//
|
||||
v->m_lsa->m_stat = StaticRouterLSA::LSA_SPF_IN_SPFTREE;
|
||||
v->m_lsa->SetStatus (StaticRouterLSA::LSA_SPF_IN_SPFTREE);
|
||||
//
|
||||
// The current vertex has a parent pointer. By calling this rather oddly
|
||||
// named method (blame quagga) we add the current vertex to the list of
|
||||
@@ -950,14 +947,14 @@ StaticRouteManager::SPFIntraAddRouter (SPFVertex* v)
|
||||
// We are only concerned about point-to-point links
|
||||
//
|
||||
StaticRouterLinkRecord *lr = lsa->GetLinkRecord (j);
|
||||
if (lr->m_linkType != StaticRouterLinkRecord::PointToPoint)
|
||||
if (lr->GetLinkType () != StaticRouterLinkRecord::PointToPoint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
NS_DEBUG ("StaticRouteManager::SPFIntraAddRouter (): "
|
||||
" Node " << node->GetId () <<
|
||||
" add route to " << lr->m_linkData <<
|
||||
" add route to " << lr->GetLinkData () <<
|
||||
" using next hop " << v->m_nextHop <<
|
||||
" via interface " << v->m_rootOif);
|
||||
//
|
||||
@@ -973,7 +970,7 @@ StaticRouteManager::SPFIntraAddRouter (SPFVertex* v)
|
||||
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
|
||||
// which the packets should be send for forwarding.
|
||||
//
|
||||
ipv4->AddHostRouteTo (lr->m_linkData, v->m_nextHop,
|
||||
ipv4->AddHostRouteTo (lr->GetLinkData (), v->m_nextHop,
|
||||
v->m_rootOif);
|
||||
}
|
||||
}
|
||||
@@ -1089,73 +1086,83 @@ StaticRouteManagerTest::RunTests (void)
|
||||
// link2: 10.1.3.1/30, 10.1.3.2/30
|
||||
//
|
||||
// Router 0
|
||||
StaticRouterLinkRecord* lr0 = new StaticRouterLinkRecord ();
|
||||
lr0->m_linkId.Set (2); // router ID 0.0.0.2
|
||||
lr0->m_linkData.Set ("10.1.1.1");
|
||||
lr0->m_linkType = StaticRouterLinkRecord::PointToPoint;
|
||||
lr0->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr1 = new StaticRouterLinkRecord ();
|
||||
lr1->m_linkId.Set ("10.1.1.1");
|
||||
lr1->m_linkData.Set ("255.255.255.252");
|
||||
lr1->m_linkType = StaticRouterLinkRecord::StubNetwork;
|
||||
lr1->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr0 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::PointToPoint,
|
||||
"0.0.0.2", // router ID 0.0.0.2
|
||||
"10.1.1.1", // local ID
|
||||
1); // metric
|
||||
|
||||
StaticRouterLinkRecord* lr1 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::StubNetwork,
|
||||
"10.1.1.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
StaticRouterLSA* lsa0 = new StaticRouterLSA ();
|
||||
lsa0->m_linkStateId.Set ("0.0.0.0");
|
||||
lsa0->m_advertisingRtr.Set ("0.0.0.0");
|
||||
lsa0->SetLinkStateId ("0.0.0.0");
|
||||
lsa0->SetAdvertisingRouter ("0.0.0.0");
|
||||
lsa0->AddLinkRecord (lr0);
|
||||
lsa0->AddLinkRecord (lr1);
|
||||
|
||||
// Router 1
|
||||
StaticRouterLinkRecord* lr2 = new StaticRouterLinkRecord ();
|
||||
lr2->m_linkId.Set (2); // router ID 0.0.0.2
|
||||
lr2->m_linkData.Set ("10.1.2.1");
|
||||
lr2->m_linkType = StaticRouterLinkRecord::PointToPoint;
|
||||
lr2->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr3 = new StaticRouterLinkRecord ();
|
||||
lr3->m_linkId.Set ("10.1.2.1");
|
||||
lr3->m_linkData.Set ("255.255.255.252");
|
||||
lr3->m_linkType = StaticRouterLinkRecord::StubNetwork;
|
||||
lr3->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr2 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::PointToPoint,
|
||||
"0.0.0.2",
|
||||
"10.1.2.1",
|
||||
1);
|
||||
|
||||
StaticRouterLinkRecord* lr3 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::StubNetwork,
|
||||
"10.1.2.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
StaticRouterLSA* lsa1 = new StaticRouterLSA ();
|
||||
lsa1->m_linkStateId.Set (1);
|
||||
lsa1->m_advertisingRtr.Set (1);
|
||||
lsa1->SetLinkStateId ("0.0.0.1");
|
||||
lsa1->SetAdvertisingRouter ("0.0.0.1");
|
||||
lsa1->AddLinkRecord (lr2);
|
||||
lsa1->AddLinkRecord (lr3);
|
||||
|
||||
// Router 2
|
||||
StaticRouterLinkRecord* lr4 = new StaticRouterLinkRecord ();
|
||||
lr4->m_linkId.Set ("0.0.0.0");
|
||||
lr4->m_linkData.Set ("10.1.1.2");
|
||||
lr4->m_linkType = StaticRouterLinkRecord::PointToPoint;
|
||||
lr4->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr5 = new StaticRouterLinkRecord ();
|
||||
lr5->m_linkId.Set ("10.1.1.2");
|
||||
lr5->m_linkData.Set ("255.255.255.252");
|
||||
lr5->m_linkType = StaticRouterLinkRecord::StubNetwork;
|
||||
lr5->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr6 = new StaticRouterLinkRecord ();
|
||||
lr6->m_linkId.Set (1);
|
||||
lr6->m_linkData.Set ("10.1.2.2");
|
||||
lr6->m_linkType = StaticRouterLinkRecord::PointToPoint;
|
||||
lr6->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr7 = new StaticRouterLinkRecord ();
|
||||
lr7->m_linkId.Set ("10.1.2.2");
|
||||
lr7->m_linkData.Set ("255.255.255.252");
|
||||
lr7->m_linkType = StaticRouterLinkRecord::StubNetwork;
|
||||
lr7->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr8 = new StaticRouterLinkRecord ();
|
||||
lr8->m_linkId.Set (3);
|
||||
lr8->m_linkData.Set ("10.1.3.2");
|
||||
lr8->m_linkType = StaticRouterLinkRecord::PointToPoint;
|
||||
lr8->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr9 = new StaticRouterLinkRecord ();
|
||||
lr9->m_linkId.Set ("10.1.3.2");
|
||||
lr9->m_linkData.Set ("255.255.255.252");
|
||||
lr9->m_linkType = StaticRouterLinkRecord::StubNetwork;
|
||||
lr9->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr4 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::PointToPoint,
|
||||
"0.0.0.0",
|
||||
"10.1.1.2",
|
||||
1);
|
||||
|
||||
StaticRouterLinkRecord* lr5 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::StubNetwork,
|
||||
"10.1.1.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
StaticRouterLinkRecord* lr6 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::PointToPoint,
|
||||
"0.0.0.1",
|
||||
"10.1.2.2",
|
||||
1);
|
||||
|
||||
StaticRouterLinkRecord* lr7 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::StubNetwork,
|
||||
"10.1.2.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
StaticRouterLinkRecord* lr8 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::PointToPoint,
|
||||
"0.0.0.3",
|
||||
"10.1.3.2",
|
||||
1);
|
||||
|
||||
StaticRouterLinkRecord* lr9 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::StubNetwork,
|
||||
"10.1.3.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
StaticRouterLSA* lsa2 = new StaticRouterLSA ();
|
||||
lsa2->m_linkStateId.Set (2);
|
||||
lsa2->m_advertisingRtr.Set (2);
|
||||
lsa2->SetLinkStateId ("0.0.0.2");
|
||||
lsa2->SetAdvertisingRouter ("0.0.0.2");
|
||||
lsa2->AddLinkRecord (lr4);
|
||||
lsa2->AddLinkRecord (lr5);
|
||||
lsa2->AddLinkRecord (lr6);
|
||||
@@ -1164,36 +1171,38 @@ StaticRouteManagerTest::RunTests (void)
|
||||
lsa2->AddLinkRecord (lr9);
|
||||
|
||||
// Router 3
|
||||
StaticRouterLinkRecord* lr10 = new StaticRouterLinkRecord ();
|
||||
lr10->m_linkId.Set (2); // router ID 0.0.0.2
|
||||
lr10->m_linkData.Set ("10.1.2.1");
|
||||
lr10->m_linkType = StaticRouterLinkRecord::PointToPoint;
|
||||
lr10->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr11 = new StaticRouterLinkRecord ();
|
||||
lr11->m_linkId.Set ("10.1.2.1");
|
||||
lr11->m_linkData.Set ("255.255.255.252");
|
||||
lr11->m_linkType = StaticRouterLinkRecord::StubNetwork;
|
||||
lr11->m_metric = 1;
|
||||
StaticRouterLinkRecord* lr10 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::PointToPoint,
|
||||
"0.0.0.2",
|
||||
"10.1.2.1",
|
||||
1);
|
||||
|
||||
StaticRouterLinkRecord* lr11 = new StaticRouterLinkRecord (
|
||||
StaticRouterLinkRecord::StubNetwork,
|
||||
"10.1.2.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
StaticRouterLSA* lsa3 = new StaticRouterLSA ();
|
||||
lsa3->m_linkStateId.Set (3);
|
||||
lsa3->m_advertisingRtr.Set (3);
|
||||
lsa3->AddLinkRecord (lr2);
|
||||
lsa3->AddLinkRecord (lr3);
|
||||
lsa3->SetLinkStateId ("0.0.0.3");
|
||||
lsa3->SetAdvertisingRouter ("0.0.0.3");
|
||||
lsa3->AddLinkRecord (lr10);
|
||||
lsa3->AddLinkRecord (lr11);
|
||||
|
||||
// Test the database
|
||||
StaticRouteManagerLSDB* srmlsdb = new StaticRouteManagerLSDB ();
|
||||
srmlsdb->Insert (lsa0->m_linkStateId, lsa0);
|
||||
srmlsdb->Insert (lsa1->m_linkStateId, lsa1);
|
||||
srmlsdb->Insert (lsa2->m_linkStateId, lsa2);
|
||||
srmlsdb->Insert (lsa3->m_linkStateId, lsa3);
|
||||
NS_ASSERT (lsa2 == srmlsdb->GetLSA (lsa2->m_linkStateId));
|
||||
srmlsdb->Insert (lsa0->GetLinkStateId (), lsa0);
|
||||
srmlsdb->Insert (lsa1->GetLinkStateId (), lsa1);
|
||||
srmlsdb->Insert (lsa2->GetLinkStateId (), lsa2);
|
||||
srmlsdb->Insert (lsa3->GetLinkStateId (), lsa3);
|
||||
NS_ASSERT (lsa2 == srmlsdb->GetLSA (lsa2->GetLinkStateId ()));
|
||||
|
||||
// XXX next, calculate routes based on the manually created LSDB
|
||||
StaticRouteManager* srm = new StaticRouteManager ();
|
||||
srm->DebugUseLsdb (srmlsdb); // manually add in an LSDB
|
||||
// Note-- this will succeed without any nodes in the topology
|
||||
// because the NodeList is empty
|
||||
srm->DebugSPFCalculate (lsa0->m_linkStateId); // node n0
|
||||
srm->DebugSPFCalculate (lsa0->GetLinkStateId ()); // node n0
|
||||
|
||||
// This delete clears the srm, which deletes the LSDB, which clears
|
||||
// all of the LSAs, which each destroys the attached LinkRecords.
|
||||
|
||||
@@ -26,19 +26,120 @@ NS_DEBUG_COMPONENT_DEFINE ("StaticRouter");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
StaticRouterLinkRecord::StaticRouterLinkRecord ()
|
||||
:
|
||||
m_linkId ("0.0.0.0"),
|
||||
m_linkData ("0.0.0.0"),
|
||||
m_linkType (Unknown),
|
||||
m_metric (0)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::StaticRouterLinkRecord ()");
|
||||
}
|
||||
|
||||
StaticRouterLinkRecord::StaticRouterLinkRecord (
|
||||
LinkType linkType,
|
||||
Ipv4Address linkId,
|
||||
Ipv4Address linkData,
|
||||
uint32_t metric)
|
||||
:
|
||||
m_linkId (linkId),
|
||||
m_linkData (linkData),
|
||||
m_linkType (linkType),
|
||||
m_metric (metric)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::StaticRouterLinkRecord (" <<
|
||||
linkType << ", " << linkId << ", " << linkData << ", " << metric << ")");
|
||||
}
|
||||
|
||||
StaticRouterLinkRecord::~StaticRouterLinkRecord ()
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::~StaticRouterLinkRecord ()");
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
StaticRouterLinkRecord::GetLinkId (void) const
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::GetLinkId ()");
|
||||
return m_linkId;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLinkRecord::SetLinkId (Ipv4Address addr)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::SetLinkId ()");
|
||||
m_linkId = addr;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
StaticRouterLinkRecord::GetLinkData (void) const
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::GetLinkData ()");
|
||||
return m_linkData;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLinkRecord::SetLinkData (Ipv4Address addr)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::SetLinkData ()");
|
||||
m_linkData = addr;
|
||||
}
|
||||
|
||||
StaticRouterLinkRecord::LinkType
|
||||
StaticRouterLinkRecord::GetLinkType (void) const
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::GetLinkType ()");
|
||||
return m_linkType;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLinkRecord::SetLinkType (
|
||||
StaticRouterLinkRecord::LinkType linkType)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::SetLinkType ()");
|
||||
m_linkType = linkType;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
StaticRouterLinkRecord::GetMetric (void) const
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::GetMetric ()");
|
||||
return m_metric;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLinkRecord::SetMetric (uint32_t metric)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLinkRecord::SetMetric ()");
|
||||
m_metric = metric;
|
||||
}
|
||||
|
||||
StaticRouterLSA::StaticRouterLSA()
|
||||
:
|
||||
m_linkStateId("0.0.0.0"),
|
||||
m_advertisingRtr("0.0.0.0"),
|
||||
m_linkRecords(),
|
||||
m_stat(StaticRouterLSA::LSA_SPF_NOT_EXPLORED)
|
||||
m_status(StaticRouterLSA::LSA_SPF_NOT_EXPLORED)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLSA::StaticRouterLSA ()");
|
||||
}
|
||||
|
||||
StaticRouterLSA::StaticRouterLSA (
|
||||
StaticRouterLSA::SPFStatus status,
|
||||
Ipv4Address linkStateId,
|
||||
Ipv4Address advertisingRtr)
|
||||
:
|
||||
m_linkStateId(linkStateId),
|
||||
m_advertisingRtr(advertisingRtr),
|
||||
m_linkRecords(),
|
||||
m_status(status)
|
||||
{
|
||||
NS_DEBUG("StaticRouterLSA::StaticRouterLSA (" << status << ", " <<
|
||||
linkStateId << ", " << advertisingRtr << ")");
|
||||
}
|
||||
|
||||
StaticRouterLSA::StaticRouterLSA (StaticRouterLSA& lsa)
|
||||
: m_linkStateId(lsa.m_linkStateId), m_advertisingRtr(lsa.m_advertisingRtr),
|
||||
m_stat(lsa.m_stat)
|
||||
m_status(lsa.m_status)
|
||||
{
|
||||
NS_ASSERT_MSG(IsEmpty(),
|
||||
"StaticRouterLSA::StaticRouterLSA (): Non-empty LSA in constructor");
|
||||
@@ -46,11 +147,11 @@ StaticRouterLSA::StaticRouterLSA (StaticRouterLSA& lsa)
|
||||
}
|
||||
|
||||
StaticRouterLSA&
|
||||
StaticRouterLSA::operator= (StaticRouterLSA& lsa)
|
||||
StaticRouterLSA::operator= (const StaticRouterLSA& lsa)
|
||||
{
|
||||
m_linkStateId = lsa.m_linkStateId;
|
||||
m_advertisingRtr = lsa.m_advertisingRtr;
|
||||
m_stat = lsa.m_stat;
|
||||
m_status = lsa.m_status;
|
||||
|
||||
ClearLinkRecords ();
|
||||
CopyLinkRecords (lsa);
|
||||
@@ -58,17 +159,19 @@ StaticRouterLSA::operator= (StaticRouterLSA& lsa)
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLSA::CopyLinkRecords (StaticRouterLSA& lsa)
|
||||
StaticRouterLSA::CopyLinkRecords (const StaticRouterLSA& lsa)
|
||||
{
|
||||
for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin ();
|
||||
i != lsa.m_linkRecords.end ();
|
||||
i++)
|
||||
for (ListOfLinkRecords_t::const_iterator i = lsa.m_linkRecords.begin ();
|
||||
i != lsa.m_linkRecords.end ();
|
||||
i++)
|
||||
{
|
||||
StaticRouterLinkRecord *pSrc = *i;
|
||||
StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord;
|
||||
pDst->m_linkId = pSrc->m_linkId;
|
||||
pDst->m_linkData = pSrc->m_linkData;
|
||||
pDst->m_linkType = pSrc->m_linkType;
|
||||
|
||||
pDst->SetLinkType (pSrc->GetLinkType ());
|
||||
pDst->SetLinkId (pSrc->GetLinkId ());
|
||||
pDst->SetLinkData (pSrc->GetLinkData ());
|
||||
|
||||
m_linkRecords.push_back(pDst);
|
||||
pDst = 0;
|
||||
}
|
||||
@@ -107,16 +210,16 @@ StaticRouterLSA::AddLinkRecord (StaticRouterLinkRecord* lr)
|
||||
}
|
||||
|
||||
uint32_t
|
||||
StaticRouterLSA::GetNLinkRecords (void)
|
||||
StaticRouterLSA::GetNLinkRecords (void) const
|
||||
{
|
||||
return m_linkRecords.size ();
|
||||
}
|
||||
|
||||
StaticRouterLinkRecord *
|
||||
StaticRouterLSA::GetLinkRecord (uint32_t n)
|
||||
StaticRouterLSA::GetLinkRecord (uint32_t n) const
|
||||
{
|
||||
uint32_t j = 0;
|
||||
for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin ();
|
||||
for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin ();
|
||||
i != m_linkRecords.end ();
|
||||
i++, j++)
|
||||
{
|
||||
@@ -129,27 +232,62 @@ StaticRouterLSA::GetLinkRecord (uint32_t n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
StaticRouterLSA::IsEmpty (void)
|
||||
StaticRouterLSA::IsEmpty (void) const
|
||||
{
|
||||
return m_linkRecords.size () == 0;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
StaticRouterLSA::GetLinkStateId (void) const
|
||||
{
|
||||
return m_linkStateId;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLSA::SetLinkStateId (Ipv4Address addr)
|
||||
{
|
||||
m_linkStateId = addr;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
StaticRouterLSA::GetAdvertisingRouter (void) const
|
||||
{
|
||||
return m_advertisingRtr;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLSA::SetAdvertisingRouter (Ipv4Address addr)
|
||||
{
|
||||
m_advertisingRtr = addr;
|
||||
}
|
||||
|
||||
StaticRouterLSA::SPFStatus
|
||||
StaticRouterLSA::GetStatus (void) const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLSA::SetStatus (StaticRouterLSA::SPFStatus status)
|
||||
{
|
||||
m_status = status;
|
||||
}
|
||||
|
||||
void
|
||||
StaticRouterLSA::Print (std::ostream &os)
|
||||
StaticRouterLSA::Print (std::ostream &os) const
|
||||
{
|
||||
os << "m_linkStateId = " << m_linkStateId << std::endl <<
|
||||
"m_advertisingRtr = " << m_advertisingRtr << std::endl;
|
||||
|
||||
for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin ();
|
||||
for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin ();
|
||||
i != m_linkRecords.end ();
|
||||
i++)
|
||||
{
|
||||
StaticRouterLinkRecord *p = *i;
|
||||
os << "----------" << std::endl;
|
||||
os << "m_linkId = " << p->m_linkId << std::endl;
|
||||
os << "m_linkData = " << p->m_linkData << std::endl;
|
||||
os << "m_linkId = " << p->GetLinkId () << std::endl;
|
||||
os << "m_linkData = " << p->GetLinkData () << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +336,7 @@ StaticRouter::ClearLSAs ()
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
StaticRouter::GetRouterId (void)
|
||||
StaticRouter::GetRouterId (void) const
|
||||
{
|
||||
return m_routerId;
|
||||
}
|
||||
@@ -230,9 +368,9 @@ StaticRouter::DiscoverLSAs (void)
|
||||
// return exactly one.
|
||||
//
|
||||
StaticRouterLSA *pLSA = new StaticRouterLSA;
|
||||
pLSA->m_linkStateId = m_routerId;
|
||||
pLSA->m_advertisingRtr = m_routerId;
|
||||
pLSA->m_stat = StaticRouterLSA::LSA_SPF_NOT_EXPLORED;
|
||||
pLSA->SetLinkStateId (m_routerId);
|
||||
pLSA->SetAdvertisingRouter (m_routerId);
|
||||
pLSA->SetStatus (StaticRouterLSA::LSA_SPF_NOT_EXPLORED);
|
||||
//
|
||||
// We need to ask the node for the number of net devices attached. This isn't
|
||||
// necessarily equal to the number of links to adjacent nodes (other routers)
|
||||
@@ -315,16 +453,16 @@ StaticRouter::DiscoverLSAs (void)
|
||||
// the second is a stub network record with the network number.
|
||||
//
|
||||
StaticRouterLinkRecord *plr = new StaticRouterLinkRecord;
|
||||
plr->m_linkType = StaticRouterLinkRecord::PointToPoint;
|
||||
plr->m_linkId = rtrIdRemote;
|
||||
plr->m_linkData = addrLocal;
|
||||
plr->SetLinkType (StaticRouterLinkRecord::PointToPoint);
|
||||
plr->SetLinkId (rtrIdRemote);
|
||||
plr->SetLinkData (addrLocal);
|
||||
pLSA->AddLinkRecord(plr);
|
||||
plr = 0;
|
||||
|
||||
plr = new StaticRouterLinkRecord;
|
||||
plr->m_linkType = StaticRouterLinkRecord::StubNetwork;
|
||||
plr->m_linkId = addrRemote;
|
||||
plr->m_linkData.Set(maskRemote.GetHostOrder()); // Frown
|
||||
plr->SetLinkType (StaticRouterLinkRecord::StubNetwork);
|
||||
plr->SetLinkId (addrRemote);
|
||||
plr->SetLinkData (Ipv4Address(maskRemote.GetHostOrder())); // Frown
|
||||
pLSA->AddLinkRecord(plr);
|
||||
plr = 0;
|
||||
}
|
||||
@@ -337,7 +475,7 @@ StaticRouter::DiscoverLSAs (void)
|
||||
}
|
||||
|
||||
uint32_t
|
||||
StaticRouter::GetNumLSAs (void)
|
||||
StaticRouter::GetNumLSAs (void) const
|
||||
{
|
||||
NS_DEBUG("StaticRouter::GetNumLSAs ()");
|
||||
return m_LSAs.size ();
|
||||
@@ -347,7 +485,7 @@ StaticRouter::GetNumLSAs (void)
|
||||
// Get the nth link state advertisement from this router.
|
||||
//
|
||||
bool
|
||||
StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa)
|
||||
StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa) const
|
||||
{
|
||||
NS_ASSERT_MSG(lsa.IsEmpty(), "StaticRouter::GetLSA (): Must pass empty LSA");
|
||||
//
|
||||
@@ -355,7 +493,7 @@ StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa)
|
||||
// walk the list of link state advertisements created there and return the
|
||||
// one the client is interested in.
|
||||
//
|
||||
ListOfLSAs_t::iterator i = m_LSAs.begin ();
|
||||
ListOfLSAs_t::const_iterator i = m_LSAs.begin ();
|
||||
uint32_t j = 0;
|
||||
|
||||
for (; i != m_LSAs.end (); i++, j++)
|
||||
@@ -376,7 +514,7 @@ StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa)
|
||||
// other end. This only makes sense with a point-to-point channel.
|
||||
//
|
||||
Ptr<NetDevice>
|
||||
StaticRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch)
|
||||
StaticRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const
|
||||
{
|
||||
//
|
||||
// Double-check that channel agrees with device that it's a point-to-point
|
||||
@@ -417,7 +555,7 @@ StaticRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch)
|
||||
// corresponds to that net device.
|
||||
//
|
||||
uint32_t
|
||||
StaticRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd)
|
||||
StaticRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const
|
||||
{
|
||||
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
|
||||
NS_ASSERT_MSG(ipv4, "QI for <Ipv4> interface failed");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -34,42 +35,163 @@ namespace ns3 {
|
||||
* The StaticRouterLinkRecord is modeled after the OSPF link record field of
|
||||
* a Link State Advertisement. Right now we will only see two types of link
|
||||
* records corresponding to a stub network and a point-to-point link (channel).
|
||||
*
|
||||
* For Type 3 link (Stub),
|
||||
*/
|
||||
class StaticRouterLinkRecord
|
||||
{
|
||||
public:
|
||||
//
|
||||
// For Type 1 link (PointToPoint), set m_linkId to Router ID of
|
||||
// neighboring router.
|
||||
//
|
||||
// For Type 3 link (Stub), set m_linkId to neighbor's IP address
|
||||
//
|
||||
Ipv4Address m_linkId;
|
||||
//
|
||||
// For Type 1 link (PointToPoint), set m_linkData to local IP address
|
||||
//
|
||||
// For Type 3 link (Stub), set m_linkData to mask 0xffffffff
|
||||
//
|
||||
Ipv4Address m_linkData; // for links to RouterLSA,
|
||||
/**
|
||||
* Enumeration of the possible types of Static Router Link Records. These
|
||||
* are defined in the OSPF spec. We currently only use PointToPoint and
|
||||
* StubNetwork types.
|
||||
*/
|
||||
enum LinkType {
|
||||
PointToPoint = 1, /**< Record representing a point to point channel */
|
||||
Unknown = 0, /**< Uninitialized Link Record */
|
||||
PointToPoint, /**< Record representing a point to point channel */
|
||||
TransitNetwork, /**< Unused -- for future OSPF compatibility */
|
||||
StubNetwork, /**< Record represents a leaf node network */
|
||||
VirtualLink /**< Unused -- for future OSPF compatibility */
|
||||
} m_linkType;
|
||||
};
|
||||
/**
|
||||
* An abstract cost associated with forwarding a packet across a link.
|
||||
* A sum of metrics must have a well-defined meaning. That is, you shouldn't
|
||||
* use bandwidth as a metric (how does the sum of the bandwidth of two hops
|
||||
* relate to the cost of sending a packet); rather you should use something
|
||||
* like delay.
|
||||
* Construct an empty ("uninitialized") Static Router Link Record.
|
||||
*
|
||||
* The Link ID and Link Data Ipv4 addresses are set to "0.0.0.0";
|
||||
* The Link Type is set to Unknown;
|
||||
* The metric is set to 0.
|
||||
*/
|
||||
StaticRouterLinkRecord ();
|
||||
/**
|
||||
* Construct a fully uninitialized Static Router Link Record.
|
||||
*
|
||||
* @param linkType The type of link record to construct.
|
||||
* @param linkId The link ID for the record.
|
||||
* @param linkData The link data field for the record.
|
||||
* @param metric The metric field for the record.
|
||||
* @see LinkType
|
||||
* @see SetLinkId
|
||||
* @see SetLinkData
|
||||
*/
|
||||
StaticRouterLinkRecord (
|
||||
LinkType linkType,
|
||||
Ipv4Address linkId,
|
||||
Ipv4Address linkData,
|
||||
uint32_t metric);
|
||||
/**
|
||||
* Destroy a Static Router Link Record.
|
||||
*
|
||||
* Currently does nothing. Here as a placeholder only.
|
||||
*/
|
||||
~StaticRouterLinkRecord ();
|
||||
/**
|
||||
* Get the Link ID field of the Static Router Link Record.
|
||||
*
|
||||
* For an OSPF type 1 link (PointToPoint) the Link ID will be the Router ID
|
||||
* of the neighboring router.
|
||||
*
|
||||
* For an OSPF type 3 link (StubNetwork), the Link ID will be the adjacent
|
||||
* neighbor's IP address
|
||||
*/
|
||||
Ipv4Address GetLinkId(void) const;
|
||||
/**
|
||||
* Set the Link ID field of the Static Router Link Record.
|
||||
*
|
||||
* For an OSPF type 1 link (PointToPoint) the Link ID must be the Router ID
|
||||
* of the neighboring router.
|
||||
*
|
||||
* For an OSPF type 3 link (StubNetwork), the Link ID must be the adjacent
|
||||
* neighbor's IP address
|
||||
*/
|
||||
void SetLinkId(Ipv4Address addr);
|
||||
/**
|
||||
* Get the Link Data field of the Static Router Link Record.
|
||||
*
|
||||
* For an OSPF type 1 link (PointToPoint) the Link Data will be the IP
|
||||
* address of the node of the local side of the link.
|
||||
*
|
||||
* For an OSPF type 3 link (StubNetwork), the Link Data will be the
|
||||
* network mask
|
||||
*/
|
||||
Ipv4Address GetLinkData(void) const;
|
||||
/**
|
||||
* Set the Link Data field of the Static Router Link Record.
|
||||
*
|
||||
* For an OSPF type 1 link (PointToPoint) the Link Data must be the IP
|
||||
* address of the node of the local side of the link.
|
||||
*
|
||||
* For an OSPF type 3 link (StubNetwork), the Link Data must be set to the
|
||||
* network mask
|
||||
*/
|
||||
void SetLinkData(Ipv4Address addr);
|
||||
/**
|
||||
* Get the Link Type field of the Static Router Link Record.
|
||||
*
|
||||
* The Link Type describes the kind of link a given record represents. The
|
||||
* values are defined by OSPF.
|
||||
*
|
||||
* @see LinkType
|
||||
*/
|
||||
LinkType GetLinkType(void) const;
|
||||
/**
|
||||
* Set the Link Type field of the Static Router Link Record.
|
||||
*
|
||||
* The Link Type describes the kind of link a given record represents. The
|
||||
* values are defined by OSPF.
|
||||
*
|
||||
* @see LinkType
|
||||
*/
|
||||
void SetLinkType(LinkType linkType);
|
||||
/**
|
||||
* Get the Metric Data field of the Static Router Link Record.
|
||||
*
|
||||
* The metric is an abstract cost associated with forwarding a packet across
|
||||
* a link. A sum of metrics must have a well-defined meaning. That is, you
|
||||
* shouldn't use bandwidth as a metric (how does the sum of the bandwidth of
|
||||
* two hops relate to the cost of sending a packet); rather you should use
|
||||
* something like delay.
|
||||
*/
|
||||
uint32_t GetMetric(void) const;
|
||||
/**
|
||||
* Set the Metric Data field of the Static Router Link Record.
|
||||
*
|
||||
* The metric is an abstract cost associated with forwarding a packet across
|
||||
* a link. A sum of metrics must have a well-defined meaning. That is, you
|
||||
* shouldn't use bandwidth as a metric (how does the sum of the bandwidth of
|
||||
* two hops relate to the cost of sending a packet); rather you should use
|
||||
* something like delay.
|
||||
*/
|
||||
void SetMetric(uint32_t metric);
|
||||
|
||||
private:
|
||||
/**
|
||||
* m_linkId and m_linkData are defined by OSPF to have different meanings
|
||||
* depending on the type of link a given link records represents. They work
|
||||
* together.
|
||||
*
|
||||
* For Type 1 link (PointToPoint), set m_linkId to Router ID of
|
||||
* neighboring router.
|
||||
*
|
||||
* For Type 3 link (Stub), set m_linkId to neighbor's IP address
|
||||
*/
|
||||
Ipv4Address m_linkId;
|
||||
/**
|
||||
* m_linkId and m_linkData are defined by OSPF to have different meanings
|
||||
* depending on the type of link a given link records represents. They work
|
||||
* together.
|
||||
*
|
||||
* For Type 1 link (PointToPoint), set m_linkData to local IP address
|
||||
*
|
||||
* For Type 3 link (Stub), set m_linkData to mask
|
||||
*/
|
||||
Ipv4Address m_linkData; // for links to RouterLSA,
|
||||
|
||||
LinkType m_linkType;
|
||||
/**
|
||||
* The metric for a given link.
|
||||
*
|
||||
* A metric is abstract cost associated with forwarding a packet across a
|
||||
* link. A sum of metrics must have a well-defined meaning. That is, you
|
||||
* shouldn't use bandwidth as a metric (how does the sum of the bandwidth
|
||||
* of two hops relate to the cost of sending a packet); rather you should
|
||||
* use something like delay.
|
||||
*/
|
||||
uint32_t m_metric;
|
||||
};
|
||||
@@ -84,110 +206,189 @@ public:
|
||||
class StaticRouterLSA
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create a blank Static Router Link State Advertisement. On completion,
|
||||
* any Ipv4Address variables initialized to 0.0.0.0 and the list of Link
|
||||
* State Records is empty.
|
||||
*/
|
||||
StaticRouterLSA();
|
||||
/**
|
||||
* Copy constructor for a Static Router Link State Advertisement.
|
||||
* Takes a piece of memory and constructs a semantically identical copy of
|
||||
* the given LSA.
|
||||
*
|
||||
* @param lsa The existing LSA to be used as the source.
|
||||
*/
|
||||
StaticRouterLSA (StaticRouterLSA& lsa);
|
||||
/**
|
||||
* Destroy an existing Static Router Link State Advertisement. Any Static
|
||||
* router Link Records present in the list are freed.
|
||||
*/
|
||||
~StaticRouterLSA();
|
||||
/**
|
||||
* Assignment operator for a Static Router Link State Advertisement.
|
||||
* Takes an existing Static Router Link State Advertisement and overwrites
|
||||
* it to make a semantically identical copy of a given prototype LSA.
|
||||
*
|
||||
* If there are any Static Router Link Records present in the existing
|
||||
* LSA, they are freed before the assignment happens.
|
||||
*
|
||||
* @param lsa The existing LSA to be used as the source.
|
||||
* @returns Reference to the overwritten LSA.
|
||||
*/
|
||||
StaticRouterLSA& operator= (StaticRouterLSA& lsa);
|
||||
/**
|
||||
* Copy any Static Router Link Records in a given Static Router Link
|
||||
* State Advertisement to the current LSA. Existing Link Records are not
|
||||
* deleted -- this is a concatenation of Link Records.
|
||||
*
|
||||
* @see ClearLinkRecords ()
|
||||
* @param lsa The LSA to copy the Link Records from.
|
||||
*/
|
||||
void CopyLinkRecords (StaticRouterLSA& lsa);
|
||||
/**
|
||||
* Add a given Static Router Link Record to the LSA.
|
||||
*
|
||||
* @param lr The Static Router Link Record to be added.
|
||||
* @returns The number of link records in the list.
|
||||
*/
|
||||
uint32_t AddLinkRecord (StaticRouterLinkRecord* lr);
|
||||
/**
|
||||
* Return the number of Static Router Link Records in the LSA.
|
||||
*
|
||||
* @returns The number of link records in the list.
|
||||
*/
|
||||
uint32_t GetNLinkRecords (void);
|
||||
/**
|
||||
* Return a pointer to the specified Static Router Link Record.
|
||||
*
|
||||
* @param n The LSA number desired.
|
||||
* @returns The number of link records in the list.
|
||||
*/
|
||||
StaticRouterLinkRecord* GetLinkRecord (uint32_t n);
|
||||
/**
|
||||
* Release all of the Static Router Link Records present in the Static
|
||||
* Router Link State Advertisement and make the list of link records empty.
|
||||
*/
|
||||
void ClearLinkRecords(void);
|
||||
/**
|
||||
* Check to see of the list of Static Router Link Records present in the
|
||||
* Static Router Link State Advertisement is empty.
|
||||
*
|
||||
* @returns True if the list is empty, false otherwise.
|
||||
*/
|
||||
bool IsEmpty(void);
|
||||
/**
|
||||
* Print the contents of the Static Router Link State Advertisement and
|
||||
* any Static Router Link Records present in the list. Quite verbose.
|
||||
*/
|
||||
void Print (std::ostream &os);
|
||||
/**
|
||||
* The Link State ID is defined by the OSPF spec. We always set it to the
|
||||
* router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
*/
|
||||
Ipv4Address m_linkStateId;
|
||||
/**
|
||||
* The Advertising Router is defined by the OSPF spec. We always set it to
|
||||
* the router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
*/
|
||||
Ipv4Address m_advertisingRtr;
|
||||
|
||||
typedef std::list<StaticRouterLinkRecord*> ListOfLinkRecords_t;
|
||||
ListOfLinkRecords_t m_linkRecords;
|
||||
|
||||
// this is a tristate flag used internally in the SPF computation
|
||||
/**
|
||||
* Enumeration of the possible values of the status flag in the Router Link
|
||||
* State Advertisements.
|
||||
*/
|
||||
enum SPFStatus {
|
||||
LSA_SPF_NOT_EXPLORED = 0,
|
||||
LSA_SPF_CANDIDATE,
|
||||
LSA_SPF_IN_SPFTREE
|
||||
} m_stat;
|
||||
LSA_SPF_NOT_EXPLORED = 0, /**< New vertex not yet considered */
|
||||
LSA_SPF_CANDIDATE, /**< Vertex is in the SPF candidate queue */
|
||||
LSA_SPF_IN_SPFTREE /**< Vertex is in the SPF tree */
|
||||
};
|
||||
/**
|
||||
* Create a blank Static Router Link State Advertisement. On completion,
|
||||
* any Ipv4Address variables initialized to 0.0.0.0 and the list of Link
|
||||
* State Records is empty.
|
||||
*/
|
||||
StaticRouterLSA();
|
||||
/**
|
||||
* Create an initialized Static Router Link State Advertisement. On
|
||||
* completion the list of Link State Records is empty.
|
||||
*
|
||||
* @param status The status to of the new LSA.
|
||||
* @param linkStateId The Ipv4Address for the link state ID field.
|
||||
* @param advertisingRouter The Ipv4Address for the advertising router field.
|
||||
*/
|
||||
StaticRouterLSA(SPFStatus status, Ipv4Address linkStateId,
|
||||
Ipv4Address advertisingRtr);
|
||||
/**
|
||||
* Copy constructor for a Static Router Link State Advertisement.
|
||||
* Takes a piece of memory and constructs a semantically identical copy of
|
||||
* the given LSA.
|
||||
*
|
||||
* @param lsa The existing LSA to be used as the source.
|
||||
*/
|
||||
StaticRouterLSA (StaticRouterLSA& lsa);
|
||||
/**
|
||||
* Destroy an existing Static Router Link State Advertisement. Any Static
|
||||
* router Link Records present in the list are freed.
|
||||
*/
|
||||
~StaticRouterLSA();
|
||||
/**
|
||||
* Assignment operator for a Static Router Link State Advertisement.
|
||||
* Takes an existing Static Router Link State Advertisement and overwrites
|
||||
* it to make a semantically identical copy of a given prototype LSA.
|
||||
*
|
||||
* If there are any Static Router Link Records present in the existing
|
||||
* LSA, they are freed before the assignment happens.
|
||||
*
|
||||
* @param lsa The existing LSA to be used as the source.
|
||||
* @returns Reference to the overwritten LSA.
|
||||
*/
|
||||
StaticRouterLSA& operator= (const StaticRouterLSA& lsa);
|
||||
/**
|
||||
* Copy any Static Router Link Records in a given Static Router Link
|
||||
* State Advertisement to the current LSA. Existing Link Records are not
|
||||
* deleted -- this is a concatenation of Link Records.
|
||||
*
|
||||
* @see ClearLinkRecords ()
|
||||
* @param lsa The LSA to copy the Link Records from.
|
||||
*/
|
||||
void CopyLinkRecords (const StaticRouterLSA& lsa);
|
||||
/**
|
||||
* Add a given Static Router Link Record to the LSA.
|
||||
*
|
||||
* @param lr The Static Router Link Record to be added.
|
||||
* @returns The number of link records in the list.
|
||||
*/
|
||||
uint32_t AddLinkRecord (StaticRouterLinkRecord* lr);
|
||||
/**
|
||||
* Return the number of Static Router Link Records in the LSA.
|
||||
*
|
||||
* @returns The number of link records in the list.
|
||||
*/
|
||||
uint32_t GetNLinkRecords (void) const;
|
||||
/**
|
||||
* Return a pointer to the specified Static Router Link Record.
|
||||
*
|
||||
* @param n The LSA number desired.
|
||||
* @returns The number of link records in the list.
|
||||
*/
|
||||
StaticRouterLinkRecord* GetLinkRecord (uint32_t n) const;
|
||||
/**
|
||||
* Release all of the Static Router Link Records present in the Static
|
||||
* Router Link State Advertisement and make the list of link records empty.
|
||||
*/
|
||||
void ClearLinkRecords(void);
|
||||
/**
|
||||
* Check to see of the list of Static Router Link Records present in the
|
||||
* Static Router Link State Advertisement is empty.
|
||||
*
|
||||
* @returns True if the list is empty, false otherwise.
|
||||
*/
|
||||
bool IsEmpty(void) const;
|
||||
/**
|
||||
* Print the contents of the Static Router Link State Advertisement and
|
||||
* any Static Router Link Records present in the list. Quite verbose.
|
||||
*/
|
||||
void Print (std::ostream &os) const;
|
||||
/**
|
||||
* Get the Link State ID as defined by the OSPF spec. We always set it to
|
||||
* the router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
* @returns The Ipv4Address stored as the link state ID.
|
||||
*/
|
||||
Ipv4Address GetLinkStateId (void) const;
|
||||
/**
|
||||
* Set the Link State ID is defined by the OSPF spec. We always set it to
|
||||
* the router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
*/
|
||||
void SetLinkStateId (Ipv4Address addr);
|
||||
/**
|
||||
* Get the Advertising Router as defined by the OSPF spec. We always set
|
||||
* it to the router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
* @returns The Ipv4Address stored as the advetising router.
|
||||
*/
|
||||
Ipv4Address GetAdvertisingRouter (void) const;
|
||||
/**
|
||||
* Set the Advertising Router as defined by the OSPF spec. We always set
|
||||
* it to the router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
*/
|
||||
void SetAdvertisingRouter (Ipv4Address rtr);
|
||||
/**
|
||||
* Get the SPF status of the advertisement.
|
||||
*
|
||||
* @see SPFStatus
|
||||
* @returns The SPFStatus of the LSA.
|
||||
*/
|
||||
SPFStatus GetStatus (void) const;
|
||||
/**
|
||||
* Set the SPF status of the advertisement
|
||||
*
|
||||
* @see SPFStatus
|
||||
*/
|
||||
void SetStatus (SPFStatus status);
|
||||
|
||||
private:
|
||||
/**
|
||||
* The Link State ID is defined by the OSPF spec. We always set it to the
|
||||
* router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
*/
|
||||
Ipv4Address m_linkStateId;
|
||||
/**
|
||||
* The Advertising Router is defined by the OSPF spec. We always set it to
|
||||
* the router ID of the router making the advertisement.
|
||||
*
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @see StaticRouter::GetRouterId ()
|
||||
*/
|
||||
Ipv4Address m_advertisingRtr;
|
||||
/**
|
||||
* A convenience typedef to avoid too much writers cramp.
|
||||
*/
|
||||
typedef std::list<StaticRouterLinkRecord*> ListOfLinkRecords_t;
|
||||
/**
|
||||
* Each Link State Advertisement contains a number of Link Records that
|
||||
* describe the kinds of links that are attached to a given node. We
|
||||
* consider PointToPoint and StubNetwork links.
|
||||
*
|
||||
* m_linkRecords is an STL list container to hold the Link Records that have
|
||||
* been discovered and prepared for the advertisement.
|
||||
*
|
||||
* @see StaticRouter::DiscoverLSAs ()
|
||||
*/
|
||||
ListOfLinkRecords_t m_linkRecords;
|
||||
/**
|
||||
* This is a tristate flag used internally in the SPF computation to mark
|
||||
* if an SPFVertex (a data structure representing a vertex in the SPF tree
|
||||
* -- a router) is new, is a candidate for a shortest path, or is in its
|
||||
* proper position in the tree.
|
||||
*/
|
||||
SPFStatus m_status;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, StaticRouterLSA& lsa);
|
||||
@@ -225,7 +426,7 @@ public:
|
||||
* @see RoutingEnvironment::AllocateRouterId ()
|
||||
* @returns The Router ID associated with the Static Router.
|
||||
*/
|
||||
Ipv4Address GetRouterId(void);
|
||||
Ipv4Address GetRouterId (void) const;
|
||||
/**
|
||||
* Walk the connected channels, discover the adjacent routers and build
|
||||
* the associated number of Static Router Link State Advertisements that
|
||||
@@ -256,7 +457,7 @@ public:
|
||||
* @see StaticRouter::GetLSA ()
|
||||
* @returns The number of Static Router Link State Advertisements.
|
||||
*/
|
||||
uint32_t GetNumLSAs (void);
|
||||
uint32_t GetNumLSAs (void) const;
|
||||
/**
|
||||
* Get a Static Router Link State Advertisements that this router has said
|
||||
* that it can export.
|
||||
@@ -277,14 +478,14 @@ public:
|
||||
* @param lsa The StaticRouterLSA class to receive the LSA information.
|
||||
* @returns The number of Static Router Link State Advertisements.
|
||||
*/
|
||||
bool GetLSA (uint32_t n, StaticRouterLSA &lsa);
|
||||
bool GetLSA (uint32_t n, StaticRouterLSA &lsa) const;
|
||||
|
||||
protected:
|
||||
virtual ~StaticRouter ();
|
||||
void ClearLSAs (void);
|
||||
|
||||
Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch);
|
||||
uint32_t FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd);
|
||||
Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
|
||||
uint32_t FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const;
|
||||
|
||||
Ptr<Node> m_node;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user