author | Tom Henderson <tomh@tomh.org> |
Tue, 10 Jul 2007 13:40:36 -0700 | |
changeset 1065 | 4850d9e9badd |
parent 1064 | 25e962f8ac4c |
parent 1061 | 007ef746ec4d |
child 1066 | f19baa3a0cb5 |
permissions | -rw-r--r-- |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
/* |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
* |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
* |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
*/ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
#include <utility> |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
#include <vector> |
1062 | 18 |
#include <queue> |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
#include "ns3/assert.h" |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
#include "ns3/fatal-error.h" |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
#include "ns3/debug.h" |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
#include "ns3/node-list.h" |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
#include "static-router.h" |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
#include "static-route-manager.h" |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
NS_DEBUG_COMPONENT_DEFINE ("StaticRouteManager"); |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
namespace ns3 { |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
29 |
|
1062 | 30 |
SPFVertex::SPFVertex () : |
31 |
m_vertexType(VertexUnknown), |
|
32 |
m_vertexId("255.255.255.255"), |
|
33 |
m_lsa(0), |
|
34 |
m_distanceFromRoot(SPF_INFINITY), |
|
35 |
m_stat(false) |
|
36 |
{ |
|
37 |
} |
|
38 |
||
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
39 |
SPFVertex::~SPFVertex () |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
40 |
{ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
41 |
delete m_lsa; |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
42 |
} |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
43 |
|
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
44 |
void |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
45 |
SPFVertex::Initialize () |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
46 |
{ |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
47 |
m_distanceFromRoot = SPF_INFINITY; |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
48 |
m_stat = false; |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
49 |
// XXX previous = 0 |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
50 |
} |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
51 |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
52 |
|
1053 | 53 |
StaticRouteManagerLSDB::~StaticRouteManagerLSDB() |
54 |
{ |
|
1055 | 55 |
NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB ()"); |
1053 | 56 |
|
1055 | 57 |
LSDBMap_t::iterator i; |
58 |
for (i= m_database.begin(); i!= m_database.end(); i++) |
|
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
59 |
{ |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
60 |
NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB():free vertex"); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
61 |
SPFVertex* temp = i->second; |
1055 | 62 |
delete temp; |
1053 | 63 |
} |
1055 | 64 |
NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB (): clear map"); |
65 |
m_database.clear(); |
|
1053 | 66 |
} |
67 |
||
68 |
void |
|
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
69 |
StaticRouteManagerLSDB::Initialize() |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
70 |
{ |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
71 |
NS_DEBUG("StaticRouteManagerLSDB::Initialize ()"); |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
72 |
|
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
73 |
LSDBMap_t::iterator i; |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
74 |
for (i= m_database.begin(); i!= m_database.end(); i++) |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
75 |
{ |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
76 |
SPFVertex* temp = i->second; |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
77 |
temp->Initialize(); |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
78 |
} |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
79 |
} |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
80 |
|
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
81 |
void |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
82 |
StaticRouteManagerLSDB::Insert(Ipv4Address addr, SPFVertex* vertex) |
1053 | 83 |
{ |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
84 |
m_database.insert(LSDBPair_t(addr, vertex)); |
1053 | 85 |
} |
86 |
||
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
87 |
SPFVertex* |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
88 |
StaticRouteManagerLSDB::GetVertex (Ipv4Address addr) |
1053 | 89 |
{ |
90 |
// Look up an LSA by its address |
|
91 |
LSDBMap_t::iterator i; |
|
92 |
for (i= m_database.begin(); i!= m_database.end(); i++) |
|
93 |
{ |
|
94 |
if (i->first == addr) |
|
95 |
{ |
|
96 |
return i->second; |
|
97 |
} |
|
98 |
} |
|
99 |
return 0; |
|
100 |
} |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
101 |
|
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
102 |
StaticRouteManager::StaticRouteManager () |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
103 |
{ |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
104 |
m_lsdb = new StaticRouteManagerLSDB (); |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
105 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
107 |
StaticRouteManager::~StaticRouteManager () |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
108 |
{ |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
109 |
if (m_lsdb) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
110 |
delete m_lsdb; |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
111 |
} |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
112 |
|
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
113 |
void |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
114 |
StaticRouteManager::DebugUseLsdb (StaticRouteManagerLSDB* lsdb) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
115 |
{ |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
116 |
if (m_lsdb) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
117 |
delete m_lsdb; |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
118 |
m_lsdb = lsdb; |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
119 |
} |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
120 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
121 |
void |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
122 |
StaticRouteManager::BuildStaticRoutingDatabase () |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
123 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
124 |
// walk list of nodes. QI for StaticRouter interface. |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
125 |
// if node has a StaticRouter interface, grab the LSAs |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
126 |
// from it and stick them in the LSDB |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
127 |
typedef std::vector < Ptr<Node> >::iterator Iterator; |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
128 |
for (Iterator i = NodeList::Begin(); i != NodeList::End(); i++) |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
129 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
130 |
Ptr<Node> node = *i; |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
131 |
NS_DEBUG_UNCOND ("node="<< node->GetId () ); |
1048 | 132 |
|
133 |
Ptr<StaticRouter> rtr = |
|
134 |
node->QueryInterface<StaticRouter> (StaticRouter::iid); |
|
135 |
NS_ASSERT_MSG(rtr, "QI for <StaticRouter> interface failed"); |
|
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1059
diff
changeset
|
136 |
// |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1059
diff
changeset
|
137 |
// Should call DiscoverLSAs () before trying to use any routing info or to |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1059
diff
changeset
|
138 |
// update LSAs. Subsequently you may use GetNumLSAs(). If you call |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1059
diff
changeset
|
139 |
// GetNumLSAs () before calling DiscoverLSAs () will get zero as the number. |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1059
diff
changeset
|
140 |
// |
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1059
diff
changeset
|
141 |
uint32_t numLSAs = rtr->DiscoverLSAs(); |
1056 | 142 |
NS_DEBUG_UNCOND ("Found " << numLSAs << " LSAs"); |
143 |
||
144 |
for (uint32_t j = 0; j < numLSAs; ++j) |
|
145 |
{ |
|
146 |
StaticRouterLSA lsa; |
|
147 |
rtr->GetLSA(j, lsa); |
|
148 |
NS_DEBUG_UNCOND ("LSA " << j); |
|
1057
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
149 |
NS_DEBUG_UNCOND ("----------------------------"); |
2620020dc72c
first working router
Craig Dowell <craigdo@ee.washington.edu>
parents:
1056
diff
changeset
|
150 |
NS_DEBUG_UNCOND(lsa); |
1056 | 151 |
} |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
152 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
153 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
154 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
155 |
// For each node that is a static router (which can be determined by |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
156 |
// the presence of StaticRouter interface), run Dijkstra SPF calculation |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
157 |
// on the database rooted at that router, and populate the node |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
158 |
// forwarding tables |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
159 |
// |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
160 |
void |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
161 |
StaticRouteManager::InitializeRoutes () |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
162 |
{ |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
163 |
NS_DEBUG_UNCOND("StaticRouteManager::InitializeRoutes ()"); |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
164 |
// This function parallels RFC2328, Section 16.1.1, and quagga ospfd |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
165 |
// |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
166 |
// This calculation yields the set of intra-area routes associated |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
167 |
// with an area (called hereafter Area A). A router calculates the |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
168 |
// shortest-path tree using itself as the root. The formation |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
169 |
// of the shortest path tree is done here in two stages. In the |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
170 |
// first stage, only links between routers and transit networks are |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
171 |
// considered. Using the Dijkstra algorithm, a tree is formed from |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
172 |
// this subset of the link state database. In the second stage, |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
173 |
// leaves are added to the tree by considering the links to stub |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
174 |
// networks. |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
175 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
176 |
// The area's link state database is represented as a directed graph. |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
177 |
// The graph's vertices are routers, transit networks and stub networks. |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
178 |
// The first stage of the procedure (i.e., the Dijkstra algorithm) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
179 |
// can now be summarized as follows. At each iteration of the |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
180 |
// algorithm, there is a list of candidate vertices. Paths from |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
181 |
// the root to these vertices have been found, but not necessarily |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
182 |
// the shortest ones. However, the paths to the candidate vertex |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
183 |
// that is closest to the root are guaranteed to be shortest; this |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
184 |
// vertex is added to the shortest-path tree, removed from the |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
185 |
// candidate list, and its adjacent vertices are examined for |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
186 |
// possible addition to/modification of the candidate list. The |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
187 |
// algorithm then iterates again. It terminates when the candidate |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
188 |
// list becomes empty. |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
189 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
190 |
// For each node that is a router in the topology |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
191 |
typedef std::vector < Ptr<Node> >::iterator Iterator; |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
192 |
for (Iterator i = NodeList::Begin(); i != NodeList::End(); i++) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
193 |
{ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
194 |
Ptr<Node> node = *i; |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
195 |
NS_DEBUG_UNCOND ("node="<< node->GetId () ); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
196 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
197 |
Ptr<StaticRouter> rtr = |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
198 |
node->QueryInterface<StaticRouter> (StaticRouter::iid); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
199 |
NS_ASSERT_MSG(rtr, "QI for <StaticRouter> interface failed"); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
200 |
if (rtr && rtr->GetNumLSAs () ) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
201 |
{ |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
202 |
SPFCalculate(rtr->GetRouterId ()); |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
203 |
} |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
204 |
} |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
205 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
206 |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
207 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
208 |
// quagga ospf_spf_next |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
209 |
void |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
210 |
StaticRouteManager::SPFNext() |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
211 |
{ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
212 |
// if LSA == Router_LSA, examine links |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
213 |
// a) if link to stub, skip |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
214 |
// b) W is transit |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
215 |
} |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
216 |
|
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
217 |
// quagga ospf_spf_calculate |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
218 |
void |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
219 |
StaticRouteManager::DebugSPFCalculate(Ipv4Address root) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
220 |
{ |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
221 |
SPFCalculate(root); |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
222 |
} |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
223 |
|
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
224 |
// quagga ospf_spf_calculate |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
225 |
void |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
226 |
StaticRouteManager::SPFCalculate(Ipv4Address root) |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
227 |
{ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
228 |
NS_DEBUG("StaticRouteManager::SPFCalculate ()"); |
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
229 |
|
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
230 |
// The SPFVertex objects may have state from a previous computation |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
231 |
m_lsdb->Initialize(); |
1064 | 232 |
SPFVertex* v; |
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
233 |
|
1064 | 234 |
// Make a priority queue of int using a vector container |
235 |
// priority_queue<int, vector<int>, less<int> > pq; |
|
236 |
// |
|
237 |
//priority_queue<SPFVertex*> candidate; |
|
238 |
// |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
239 |
// Initialize the shortest-path tree to only the router doing the |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
240 |
// calculation. |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
241 |
// |
1064 | 242 |
v= m_lsdb->GetVertex(root); |
243 |
// Set LSA position to LSA_SPF_IN_SPFTREE. This vertex is the root of the |
|
244 |
// spanning tree. |
|
245 |
v->m_distanceFromRoot = 0; |
|
246 |
v->m_stat = true; |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
247 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
248 |
#if 0 |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
249 |
for (;;) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
250 |
{ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
251 |
/* RFC2328 16.1. (2). */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
252 |
ospf_spf_next (v, area, candidate); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
253 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
254 |
/* RFC2328 16.1. (3). */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
255 |
/* If at this step the candidate list is empty, the shortest- |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
256 |
* path tree (of transit vertices) has been completely built and |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
257 |
* this stage of the procedure terminates. */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
258 |
if (candidate->size == 0) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
259 |
break; |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
260 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
261 |
/* Otherwise, choose the vertex belonging to the candidate list |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
262 |
* that is closest to the root, and add it to the shortest-path |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
263 |
* tree (removing it from the candidate list in the |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
264 |
* process). */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
265 |
/* Extract from the candidates the node with the lower key. */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
266 |
v = (struct vertex *) pqueue_dequeue (candidate); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
267 |
/* Update stat field in vertex. */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
268 |
*(v->stat) = LSA_SPF_IN_SPFTREE; |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
269 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
270 |
ospf_vertex_add_parent (v); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
271 |
/* Note that when there is a choice of vertices closest to the |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
272 |
* root, network vertices must be chosen before router vertices |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
273 |
* in order to necessarily find all equal-cost paths. */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
274 |
/* We don't do this at this moment, we should add the treatment |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
275 |
* above codes. -- kunihiro. */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
276 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
277 |
/* RFC2328 16.1. (4). */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
278 |
if (v->type == OSPF_VERTEX_ROUTER) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
279 |
ospf_intra_add_router (new_rtrs, v, area); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
280 |
else |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
281 |
ospf_intra_add_transit (new_table, v, area); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
282 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
283 |
/* RFC2328 16.1. (5). */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
284 |
/* Iterate the algorithm by returning to Step 2. */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
285 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
286 |
} /* end loop until no more candidate vertices */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
287 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
288 |
/* Second stage of SPF calculation procedure's */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
289 |
ospf_spf_process_stubs (area, area->spf, new_table); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
290 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
291 |
/* Free candidate queue. */ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
292 |
pqueue_delete (candidate); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
293 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
294 |
#endif |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
295 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
296 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
297 |
} |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
298 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
299 |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
300 |
} // namespace ns3 |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
301 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
302 |
#ifdef RUN_SELF_TESTS |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
303 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
304 |
#include "ns3/test.h" |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
305 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
306 |
namespace ns3 { |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
307 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
308 |
class StaticRouteManagerTest : public Test { |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
309 |
public: |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
310 |
StaticRouteManagerTest (); |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
311 |
virtual ~StaticRouteManagerTest (); |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
312 |
virtual bool RunTests (void); |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
313 |
}; |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
314 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
315 |
StaticRouteManagerTest::StaticRouteManagerTest () |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
316 |
: Test ("StaticRouteManager") |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
317 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
318 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
319 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
320 |
StaticRouteManagerTest::~StaticRouteManagerTest () |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
321 |
{} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
322 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
323 |
bool |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
324 |
StaticRouteManagerTest::RunTests (void) |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
325 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
326 |
bool ok = true; |
1049 | 327 |
|
328 |
// Build fake link state database; four routers (0-3), 3 point-to-point |
|
329 |
// links |
|
330 |
// |
|
331 |
// n0 |
|
332 |
// \ link 0 |
|
333 |
// \ link 2 |
|
334 |
// n2 -------------------------n3 |
|
335 |
// / |
|
336 |
// / link 1 |
|
337 |
// n1 |
|
338 |
// |
|
339 |
// link0: 10.1.1.1/30, 10.1.1.2/30 |
|
340 |
// link1: 10.1.2.1/30, 10.1.2.2/30 |
|
341 |
// link2: 10.1.3.1/30, 10.1.3.2/30 |
|
342 |
// |
|
343 |
// Router 0 |
|
344 |
StaticRouterLinkRecord* lr0 = new StaticRouterLinkRecord(); |
|
345 |
lr0->m_linkId.Set(2); // router ID 0.0.0.2 |
|
346 |
lr0->m_linkData.Set("10.1.1.1"); |
|
347 |
lr0->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
348 |
lr0->m_metric = 1; |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
349 |
StaticRouterLinkRecord* lr1 = new StaticRouterLinkRecord(); |
1049 | 350 |
lr1->m_linkId.Set("10.1.1.1"); |
351 |
lr1->m_linkData.Set("255.255.255.252"); |
|
352 |
lr1->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
353 |
lr1->m_metric = 1; |
1049 | 354 |
StaticRouterLSA* lsa0 = new StaticRouterLSA(); |
1055 | 355 |
lsa0->m_linkStateId.Set("0.0.0.0"); |
356 |
lsa0->m_advertisingRtr.Set("0.0.0.0"); |
|
1049 | 357 |
lsa0->AddLinkRecord(lr0); |
358 |
lsa0->AddLinkRecord(lr1); |
|
359 |
||
360 |
// Router 1 |
|
361 |
StaticRouterLinkRecord* lr2 = new StaticRouterLinkRecord(); |
|
362 |
lr2->m_linkId.Set(2); // router ID 0.0.0.2 |
|
363 |
lr2->m_linkData.Set("10.1.2.1"); |
|
364 |
lr2->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
365 |
lr2->m_metric = 1; |
|
366 |
StaticRouterLinkRecord* lr3 = new StaticRouterLinkRecord(); |
|
367 |
lr3->m_linkId.Set("10.1.2.1"); |
|
368 |
lr3->m_linkData.Set("255.255.255.252"); |
|
369 |
lr3->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
370 |
lr3->m_metric = 1; |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
371 |
StaticRouterLSA* lsa1 = new StaticRouterLSA(); |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
372 |
lsa1->m_linkStateId.Set(1); |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
373 |
lsa1->m_advertisingRtr.Set(1); |
1049 | 374 |
lsa1->AddLinkRecord(lr2); |
375 |
lsa1->AddLinkRecord(lr3); |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
376 |
|
1049 | 377 |
// Router 2 |
378 |
StaticRouterLinkRecord* lr4 = new StaticRouterLinkRecord(); |
|
379 |
lr4->m_linkId.Set("0.0.0.0"); |
|
380 |
lr4->m_linkData.Set("10.1.1.2"); |
|
381 |
lr4->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
382 |
lr4->m_metric = 1; |
|
383 |
StaticRouterLinkRecord* lr5 = new StaticRouterLinkRecord(); |
|
384 |
lr5->m_linkId.Set("10.1.1.2"); |
|
385 |
lr5->m_linkData.Set("255.255.255.252"); |
|
386 |
lr5->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
387 |
lr5->m_metric = 1; |
|
388 |
StaticRouterLinkRecord* lr6 = new StaticRouterLinkRecord(); |
|
389 |
lr6->m_linkId.Set(1); |
|
390 |
lr6->m_linkData.Set("10.1.2.2"); |
|
391 |
lr6->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
392 |
lr6->m_metric = 1; |
|
393 |
StaticRouterLinkRecord* lr7 = new StaticRouterLinkRecord(); |
|
394 |
lr7->m_linkId.Set("10.1.2.2"); |
|
395 |
lr7->m_linkData.Set("255.255.255.252"); |
|
396 |
lr7->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
397 |
lr7->m_metric = 1; |
|
398 |
StaticRouterLinkRecord* lr8 = new StaticRouterLinkRecord(); |
|
399 |
lr8->m_linkId.Set(3); |
|
400 |
lr8->m_linkData.Set("10.1.3.2"); |
|
401 |
lr8->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
402 |
lr8->m_metric = 1; |
|
403 |
StaticRouterLinkRecord* lr9 = new StaticRouterLinkRecord(); |
|
404 |
lr9->m_linkId.Set("10.1.3.2"); |
|
405 |
lr9->m_linkData.Set("255.255.255.252"); |
|
406 |
lr9->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
407 |
lr9->m_metric = 1; |
|
408 |
StaticRouterLSA* lsa2 = new StaticRouterLSA(); |
|
409 |
lsa2->m_linkStateId.Set(2); |
|
410 |
lsa2->m_advertisingRtr.Set(2); |
|
411 |
lsa2->AddLinkRecord(lr4); |
|
412 |
lsa2->AddLinkRecord(lr5); |
|
413 |
lsa2->AddLinkRecord(lr6); |
|
414 |
lsa2->AddLinkRecord(lr7); |
|
415 |
lsa2->AddLinkRecord(lr8); |
|
416 |
lsa2->AddLinkRecord(lr9); |
|
417 |
||
418 |
// Router 3 |
|
419 |
StaticRouterLinkRecord* lr10 = new StaticRouterLinkRecord(); |
|
420 |
lr10->m_linkId.Set(2); // router ID 0.0.0.2 |
|
421 |
lr10->m_linkData.Set("10.1.2.1"); |
|
422 |
lr10->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
423 |
lr10->m_metric = 1; |
|
424 |
StaticRouterLinkRecord* lr11 = new StaticRouterLinkRecord(); |
|
425 |
lr11->m_linkId.Set("10.1.2.1"); |
|
426 |
lr11->m_linkData.Set("255.255.255.252"); |
|
427 |
lr11->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
428 |
lr11->m_metric = 1; |
|
429 |
StaticRouterLSA* lsa3 = new StaticRouterLSA(); |
|
430 |
lsa3->m_linkStateId.Set(3); |
|
431 |
lsa3->m_advertisingRtr.Set(3); |
|
432 |
lsa3->AddLinkRecord(lr2); |
|
433 |
lsa3->AddLinkRecord(lr3); |
|
434 |
||
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
435 |
// Create four vertices to store these four LSAs |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
436 |
SPFVertex* v0 = new SPFVertex (); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
437 |
v0->m_lsa = lsa0; |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
438 |
v0->m_vertexType = SPFVertex::VertexRouter; |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
439 |
SPFVertex* v1 = new SPFVertex (); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
440 |
v1->m_lsa = lsa1; |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
441 |
v0->m_vertexType = SPFVertex::VertexRouter; |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
442 |
SPFVertex* v2 = new SPFVertex (); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
443 |
v2->m_lsa = lsa2; |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
444 |
v0->m_vertexType = SPFVertex::VertexRouter; |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
445 |
SPFVertex* v3 = new SPFVertex (); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
446 |
v3->m_lsa = lsa3; |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
447 |
v0->m_vertexType = SPFVertex::VertexRouter; |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
448 |
|
1053 | 449 |
// Test the database |
450 |
StaticRouteManagerLSDB* srmlsdb = new StaticRouteManagerLSDB(); |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
451 |
srmlsdb->Insert(lsa0->m_linkStateId, v0); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
452 |
srmlsdb->Insert(lsa1->m_linkStateId, v1); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
453 |
srmlsdb->Insert(lsa2->m_linkStateId, v2); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
454 |
srmlsdb->Insert(lsa3->m_linkStateId, v3); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
455 |
NS_ASSERT(v2 == srmlsdb->GetVertex(lsa2->m_linkStateId)); |
1049 | 456 |
|
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
457 |
// XXX next, calculate routes based on the manually created LSDB |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
458 |
StaticRouteManager* srm = new StaticRouteManager(); |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
459 |
srm->DebugUseLsdb (srmlsdb); |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
460 |
srm->DebugSPFCalculate(lsa0->m_linkStateId); // node n0 |
1055 | 461 |
|
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
462 |
// This delete clears the srm, which deletes the LSDB, which clears |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
463 |
// all of the vertices, which each destroy the matching LSAs, which each |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
464 |
// destroys the attached LinkRecords. |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
465 |
delete srm; |
1049 | 466 |
|
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
467 |
return ok; |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
468 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
469 |
|
1055 | 470 |
// Instantiate this class for the unit tests |
1045
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
471 |
static StaticRouteManagerTest g_staticRouteManagerTest; |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
472 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
473 |
} // namespace ns3 |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
474 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
475 |
#endif |