author | Craig Dowell <craigdo@ee.washington.edu> |
Fri, 13 Jul 2007 14:05:12 -0700 | |
changeset 1089 | 5ad63c15b7e4 |
parent 1088 | 488db5bf22c0 |
child 1092 | a5d807363dec |
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" |
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
23 |
#include "ns3/ipv4.h" |
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
|
24 |
#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
|
25 |
#include "static-route-manager.h" |
1077
ee75a75b51b3
Replace SPFVertexPriorityQueue with CandidateQueue
Tom Henderson <tomh@tomh.org>
parents:
1076
diff
changeset
|
26 |
#include "candidate-queue.h" |
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
|
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 |
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
|
29 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
namespace ns3 { |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
31 |
|
1062 | 32 |
SPFVertex::SPFVertex () : |
33 |
m_vertexType(VertexUnknown), |
|
34 |
m_vertexId("255.255.255.255"), |
|
35 |
m_lsa(0), |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
36 |
m_parent(0), |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
37 |
m_children(), |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
38 |
m_distanceFromRoot(SPF_INFINITY), |
1086 | 39 |
m_rootOif(SPF_INFINITY), |
40 |
m_nextHop("0.0.0.0") |
|
1062 | 41 |
{ |
42 |
} |
|
43 |
||
1079
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
44 |
SPFVertex::SPFVertex (StaticRouterLSA* lsa) : |
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
45 |
m_vertexType(VertexRouter), |
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
46 |
m_vertexId(lsa->m_linkStateId), |
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
47 |
m_lsa(lsa), |
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
48 |
m_parent(0), |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
49 |
m_children(), |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
50 |
m_distanceFromRoot(SPF_INFINITY), |
1086 | 51 |
m_rootOif(SPF_INFINITY), |
52 |
m_nextHop("0.0.0.0") |
|
1079
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
53 |
{ |
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
54 |
} |
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
55 |
|
1086 | 56 |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
57 |
SPFVertex::~SPFVertex () |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
58 |
{ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
59 |
} |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
60 |
|
1053 | 61 |
StaticRouteManagerLSDB::~StaticRouteManagerLSDB() |
62 |
{ |
|
1055 | 63 |
NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB ()"); |
1053 | 64 |
|
1055 | 65 |
LSDBMap_t::iterator i; |
66 |
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
|
67 |
{ |
1076
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
68 |
NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB():free LSA"); |
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
69 |
StaticRouterLSA* temp = i->second; |
1055 | 70 |
delete temp; |
1053 | 71 |
} |
1055 | 72 |
NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB (): clear map"); |
73 |
m_database.clear(); |
|
1053 | 74 |
} |
75 |
||
76 |
void |
|
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
77 |
StaticRouteManagerLSDB::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 |
NS_DEBUG("StaticRouteManagerLSDB::Initialize ()"); |
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 |
LSDBMap_t::iterator i; |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
82 |
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
|
83 |
{ |
1076
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
84 |
StaticRouterLSA* temp = i->second; |
1086 | 85 |
temp->m_stat = StaticRouterLSA::LSA_SPF_NOT_EXPLORED; |
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
86 |
} |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
87 |
} |
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
88 |
|
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
89 |
void |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
90 |
StaticRouteManagerLSDB::Insert(Ipv4Address addr, StaticRouterLSA* lsa) |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
91 |
{ |
1086 | 92 |
NS_DEBUG("StaticRouteManagerLSDB::Insert ()"); |
1085
c12d61407468
delete vertices, fix candidate queue pop/top semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
1084
diff
changeset
|
93 |
m_database.insert(LSDBPair_t(addr, lsa)); |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
94 |
} |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
95 |
|
1076
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
96 |
StaticRouterLSA* |
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
97 |
StaticRouteManagerLSDB::GetLSA (Ipv4Address addr) |
1053 | 98 |
{ |
1086 | 99 |
NS_DEBUG("StaticRouteManagerLSDB::GetLSA ()"); |
1053 | 100 |
// Look up an LSA by its address |
101 |
LSDBMap_t::iterator i; |
|
102 |
for (i= m_database.begin(); i!= m_database.end(); i++) |
|
103 |
{ |
|
104 |
if (i->first == addr) |
|
105 |
{ |
|
106 |
return i->second; |
|
107 |
} |
|
108 |
} |
|
109 |
return 0; |
|
110 |
} |
|
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
|
111 |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
112 |
StaticRouteManager::StaticRouteManager () : m_spfroot(0) |
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
|
113 |
{ |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
114 |
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
|
115 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
116 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
117 |
StaticRouteManager::~StaticRouteManager () |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
118 |
{ |
1086 | 119 |
NS_DEBUG("StaticRouteManager::~StaticRouteManager ()"); |
120 |
||
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
121 |
if (m_lsdb) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
122 |
delete m_lsdb; |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
123 |
} |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
124 |
|
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
125 |
void |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
126 |
StaticRouteManager::DebugUseLsdb (StaticRouteManagerLSDB* lsdb) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
127 |
{ |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
128 |
if (m_lsdb) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
129 |
delete m_lsdb; |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
130 |
m_lsdb = lsdb; |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
131 |
} |
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
|
132 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
{ |
1086 | 136 |
NS_DEBUG("StaticRouteManager::BuildStaticRoutingDatabase()"); |
137 |
||
138 |
// Walk the list of nodes. QI for StaticRouter interface. |
|
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
|
139 |
// 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
|
140 |
// 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
|
141 |
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
|
142 |
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
|
143 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
144 |
Ptr<Node> node = *i; |
1048 | 145 |
|
146 |
Ptr<StaticRouter> rtr = |
|
147 |
node->QueryInterface<StaticRouter> (StaticRouter::iid); |
|
148 |
NS_ASSERT_MSG(rtr, "QI for <StaticRouter> interface failed"); |
|
1086 | 149 |
|
150 |
// You must call DiscoverLSAs () before trying to use any |
|
151 |
// routing info or to update LSAs. Subsequently you may use |
|
152 |
// GetNumLSAs(). If you call GetNumLSAs () before calling |
|
153 |
// DiscoverLSAs () will get zero as the number. |
|
1061
007ef746ec4d
made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents:
1059
diff
changeset
|
154 |
uint32_t numLSAs = rtr->DiscoverLSAs(); |
1086 | 155 |
NS_DEBUG ("Discover LSAs: Found " << numLSAs << " LSAs"); |
1056 | 156 |
|
157 |
for (uint32_t j = 0; j < numLSAs; ++j) |
|
158 |
{ |
|
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
159 |
StaticRouterLSA* lsa = new StaticRouterLSA (); |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
160 |
rtr->GetLSA(j, *lsa); |
1086 | 161 |
NS_DEBUG ("LSA " << j); |
162 |
NS_DEBUG ("----------------------------"); |
|
163 |
NS_DEBUG (*lsa); |
|
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
164 |
m_lsdb->Insert (lsa->m_linkStateId, lsa); |
1056 | 165 |
} |
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
|
166 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
167 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
168 |
|
1086 | 169 |
// For each node that is a static router (which can be determined by |
170 |
// the presence of StaticRouter interface), run Dijkstra SPF calculation |
|
171 |
// on the database rooted at that router, and populate the node |
|
172 |
// forwarding tables |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
173 |
void |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
174 |
StaticRouteManager::InitializeRoutes () |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
175 |
{ |
1086 | 176 |
NS_DEBUG("StaticRouteManager::InitializeRoutes ()"); |
177 |
// This function parallels RFC2328, Section 16.1.1, and quagga ospfd |
|
178 |
// |
|
179 |
// This calculation yields the set of intra-area routes associated |
|
180 |
// with an area (called hereafter Area A). A router calculates the |
|
181 |
// shortest-path tree using itself as the root. The formation |
|
182 |
// of the shortest path tree is done here in two stages. In the |
|
183 |
// first stage, only links between routers and transit networks are |
|
184 |
// considered. Using the Dijkstra algorithm, a tree is formed from |
|
185 |
// this subset of the link state database. In the second stage, |
|
186 |
// leaves are added to the tree by considering the links to stub |
|
187 |
// networks. |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
188 |
|
1086 | 189 |
// The area's link state database is represented as a directed graph. |
190 |
// The graph's vertices are routers, transit networks and stub networks. |
|
191 |
// The first stage of the procedure (i.e., the Dijkstra algorithm) |
|
192 |
// can now be summarized as follows. At each iteration of the |
|
193 |
// algorithm, there is a list of candidate vertices. Paths from |
|
194 |
// the root to these vertices have been found, but not necessarily |
|
195 |
// the shortest ones. However, the paths to the candidate vertex |
|
196 |
// that is closest to the root are guaranteed to be shortest; this |
|
197 |
// vertex is added to the shortest-path tree, removed from the |
|
198 |
// candidate list, and its adjacent vertices are examined for |
|
199 |
// possible addition to/modification of the candidate list. The |
|
200 |
// algorithm then iterates again. It terminates when the candidate |
|
201 |
// list becomes empty. |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
202 |
|
1086 | 203 |
// Iterate for each node that is a router in the topology |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
204 |
typedef std::vector < Ptr<Node> >::iterator Iterator; |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
205 |
for (Iterator i = NodeList::Begin(); i != NodeList::End(); i++) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
206 |
{ |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
207 |
Ptr<Node> node = *i; |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
208 |
|
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
209 |
Ptr<StaticRouter> rtr = |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
210 |
node->QueryInterface<StaticRouter> (StaticRouter::iid); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
211 |
NS_ASSERT_MSG(rtr, "QI for <StaticRouter> interface failed"); |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
212 |
if (rtr && rtr->GetNumLSAs () ) |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
213 |
{ |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
214 |
SPFCalculate(rtr->GetRouterId ()); |
1058
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 |
} |
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
|
217 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
218 |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
219 |
|
1086 | 220 |
// Derived from quagga ospf_spf_next() |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
221 |
// RFC2328 Section 16.1 (2). |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
222 |
// v is on the SPF tree. Examine the links in v's LSA. Update the list |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
223 |
// of candidates with any vertices not already on the list. If a lower-cost |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
224 |
// path is found to a vertex already on the candidate list, store the new cost. |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
225 |
void |
1077
ee75a75b51b3
Replace SPFVertexPriorityQueue with CandidateQueue
Tom Henderson <tomh@tomh.org>
parents:
1076
diff
changeset
|
226 |
StaticRouteManager::SPFNext(SPFVertex* v, CandidateQueue& candidate) |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
227 |
{ |
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
228 |
SPFVertex* w = 0; |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
229 |
StaticRouterLSA* w_lsa = 0; |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
230 |
uint32_t distance = 0; |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
231 |
|
1086 | 232 |
NS_DEBUG("StaticRouteManager::SPFNext ()"); |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
233 |
if (v->m_vertexType == SPFVertex::VertexRouter) |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
234 |
{ |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
235 |
// Always true for now, since all our LSAs are RouterLSAs |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
236 |
if (true) |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
237 |
{ |
1086 | 238 |
NS_DEBUG ("SPFNext: Examining " << v->m_vertexId << "'s " << |
239 |
v->m_lsa->m_linkRecords.size() << " link records"); |
|
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
240 |
for ( StaticRouterLSA::ListOfLinkRecords_t::iterator i = |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
241 |
v->m_lsa->m_linkRecords.begin(); |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
242 |
i != v->m_lsa->m_linkRecords.end(); |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
243 |
i++ ) |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
244 |
{ |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
245 |
// (a) If this is a link to a stub network, examine the next |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
246 |
// link in V's LSA. Links to stub networks will be |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
247 |
// considered in the second stage of the shortest path |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
248 |
// calculation. |
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
249 |
StaticRouterLinkRecord* l = *i; |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
250 |
if (l->m_linkType == StaticRouterLinkRecord::StubNetwork) |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
251 |
{ |
1086 | 252 |
NS_DEBUG("SPFNext: Found a Stub record to " |
253 |
<< l->m_linkId); |
|
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
254 |
continue; |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
255 |
} |
1069 | 256 |
// (b) Otherwise, W is a transit vertex (router or transit |
257 |
// network). Look up the vertex W's LSA (router-LSA or |
|
258 |
// network-LSA) in Area A's link state database. |
|
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
259 |
if (l->m_linkType == StaticRouterLinkRecord::PointToPoint) |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
260 |
{ |
1078 | 261 |
// Lookup the vertex W's LSA |
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
262 |
w_lsa = m_lsdb->GetLSA(l->m_linkId); |
1076
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
263 |
NS_ASSERT(w_lsa); |
1086 | 264 |
NS_DEBUG("SPFNext: Found a P2P record from " << |
1076
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
265 |
v->m_vertexId << " to " << w_lsa->m_linkStateId); |
1069 | 266 |
// (c) If vertex W is already on the shortest-path tree, |
267 |
// examine the next link in the LSA. |
|
1078 | 268 |
if (w_lsa->m_stat == StaticRouterLSA::LSA_SPF_IN_SPFTREE) |
1069 | 269 |
{ |
1086 | 270 |
NS_DEBUG("SPFNext: Skipping-> LSA "<< |
271 |
w_lsa->m_linkStateId << " already in SPF tree"); |
|
1069 | 272 |
continue; |
273 |
} |
|
274 |
// (d) Calculate the link state cost D of the resulting path |
|
275 |
// from the root to vertex W. D is equal to the sum of |
|
276 |
// the link state cost of the (already calculated) |
|
277 |
// shortest path to vertex V and the advertised cost of |
|
278 |
// the link between vertices V and W. |
|
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
279 |
distance = v->m_distanceFromRoot + l->m_metric; |
1069 | 280 |
|
1086 | 281 |
NS_DEBUG("SPFNext: Considering w_lsa " << |
282 |
w_lsa->m_linkStateId); |
|
1069 | 283 |
// Here, W is either already in candidate list or not |
1078 | 284 |
if (w_lsa->m_stat == StaticRouterLSA::LSA_SPF_NOT_EXPLORED) |
285 |
{ |
|
1086 | 286 |
w = new SPFVertex(w_lsa); |
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
287 |
// Calculate nexthop to W |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
288 |
if (SPFNexthopCalculation(v, w, l, distance)) |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
289 |
{ |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
290 |
w_lsa->m_stat = StaticRouterLSA::LSA_SPF_CANDIDATE; |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
291 |
candidate.Push(w); |
1086 | 292 |
NS_DEBUG("SPFNext: Pushing " << w->m_vertexId |
293 |
<< ", parent vertexId: " << v->m_vertexId); |
|
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
294 |
} |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
295 |
} |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
296 |
} else if (w_lsa->m_stat == |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
297 |
StaticRouterLSA::LSA_SPF_CANDIDATE) |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
298 |
{ |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
299 |
//Get the vertex from candidates |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
300 |
w = candidate.Find(w_lsa->m_linkStateId); |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
301 |
if (w->m_distanceFromRoot < distance) |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
302 |
{ |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
303 |
continue; // not a shorter path |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
304 |
} |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
305 |
// equal to |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
306 |
else if (w->m_distanceFromRoot == distance) |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
307 |
{ |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
308 |
// Do nothing-- not doing equal-cost multipath |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
309 |
} |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
310 |
else |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
311 |
{ |
1086 | 312 |
// Found a lower-cost path to W. |
313 |
// nexthop_calculation is conditional, if it finds |
|
314 |
// valid nexthop it will call spf_add_parents, which |
|
315 |
// will flush the old parents |
|
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
316 |
if (SPFNexthopCalculation(v, w, l, distance)) |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
317 |
{ |
1086 | 318 |
// Decrease the key of the node in the heap, |
319 |
// re-sort the heap. |
|
320 |
candidate.Reorder(); |
|
321 |
} |
|
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
322 |
} |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
323 |
} // point-to-point |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
324 |
} // for loop |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
325 |
} |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
326 |
} |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
327 |
} |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
328 |
|
1086 | 329 |
// Derived from quagga ospf_next_hop_calculation() |
330 |
// 16.1.1. Calculate nexthop from root through V (parent) to |
|
331 |
// vertex W (destination), with given distance from root->W. |
|
332 |
// |
|
333 |
// For now, this is greatly simplified from the quagga code |
|
334 |
// |
|
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
335 |
int |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
336 |
StaticRouteManager::SPFNexthopCalculation ( |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
337 |
SPFVertex* v, |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
338 |
SPFVertex* w, |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
339 |
StaticRouterLinkRecord* l, |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
340 |
uint32_t distance) |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
341 |
{ |
1086 | 342 |
NS_DEBUG("StaticRouteManager::SPFNexthopCalculation ()"); |
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
343 |
if (v == m_spfroot) |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
344 |
{ |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
345 |
// parent of w is the root itself |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
346 |
// calculate the interfaceid of the router that corresponds |
1086 | 347 |
// to link l between v and w and store it in w->m_rootOif |
348 |
// This rootOif is then used when installing host routes for the |
|
349 |
// destinations covered by this vertex. Store also the next hop |
|
350 |
// IP address. |
|
1083 | 351 |
// |
352 |
// Find the outgoing interface on v corresponding to the link l |
|
353 |
// between v and w |
|
1086 | 354 |
if (w->m_vertexType == SPFVertex::VertexRouter) |
355 |
{ |
|
356 |
// l is a link from v to w |
|
357 |
// l2 will be a link from w to v |
|
358 |
StaticRouterLinkRecord *l2 = 0; |
|
359 |
l2 = SPFGetNextLink(w,v,l2); |
|
360 |
w->m_nextHop = l2->m_linkData; |
|
361 |
// Find interface corresponding to link's IP address |
|
362 |
w->m_rootOif = FindOutgoingInterfaceId(l->m_linkData); |
|
363 |
||
364 |
NS_DEBUG("SPFNexthopCalculation: Next hop from " << |
|
365 |
v->m_vertexId << " to " << w->m_vertexId << |
|
366 |
" goes through next hop " << w->m_nextHop << |
|
367 |
" via outgoing interface " << w->m_rootOif); |
|
368 |
} |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
369 |
} |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
370 |
else |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
371 |
{ |
1086 | 372 |
// Inherit the rootOif and nextHop from the current parent |
373 |
w->m_rootOif = v->m_rootOif; |
|
374 |
w->m_nextHop = v->m_nextHop; |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
375 |
} |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
376 |
w->m_distanceFromRoot = distance; |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
377 |
w->m_parent = v; |
1080
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
378 |
return 1; |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
379 |
} |
82a244f82f80
finish SPFNext logic; add declaration for NexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1079
diff
changeset
|
380 |
|
1086 | 381 |
// Derived from quagga ospf_get_next_link |
382 |
// Find the next link after prev_link from v to w. If prev_link is |
|
383 |
// NULL, return the first link from v to w. Ignore stub and virtual links; |
|
384 |
// these link types will never be returned. |
|
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
385 |
// |
1086 | 386 |
StaticRouterLinkRecord* |
387 |
StaticRouteManager::SPFGetNextLink( |
|
1083 | 388 |
SPFVertex* v, |
389 |
SPFVertex* w, |
|
1086 | 390 |
StaticRouterLinkRecord* prev_link |
1083 | 391 |
) |
392 |
{ |
|
1086 | 393 |
NS_DEBUG("StaticRouteManager::SPFGetNextLink ()"); |
394 |
bool skip = true; |
|
395 |
StaticRouterLinkRecord* l; |
|
396 |
if (prev_link == 0) |
|
397 |
{ |
|
398 |
skip = false; |
|
399 |
} |
|
400 |
||
401 |
for ( StaticRouterLSA::ListOfLinkRecords_t::iterator i = |
|
402 |
v->m_lsa->m_linkRecords.begin(); |
|
403 |
i != v->m_lsa->m_linkRecords.end(); |
|
404 |
i++ ) |
|
405 |
{ |
|
406 |
l = *i; |
|
407 |
if (l->m_linkType != StaticRouterLinkRecord::PointToPoint) |
|
408 |
{ |
|
409 |
continue; |
|
410 |
} |
|
411 |
if (l->m_linkId == w->m_vertexId) { |
|
412 |
NS_DEBUG("SPFGetNextLink: Found matching link l: linkId=" << |
|
413 |
l->m_linkId << " linkData=" << l->m_linkData); |
|
414 |
if (skip == false) |
|
415 |
{ |
|
416 |
NS_DEBUG("SPFGetNextLink: Returning the found link"); |
|
417 |
return l; |
|
418 |
} |
|
419 |
else |
|
420 |
{ |
|
421 |
NS_DEBUG("SPFGetNextLink: Skipping the found link"); |
|
422 |
skip = false; |
|
423 |
continue; |
|
424 |
} |
|
425 |
} |
|
426 |
} |
|
1083 | 427 |
return 0; |
428 |
} |
|
429 |
||
430 |
||
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
431 |
// quagga ospf_spf_calculate |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
432 |
void |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
433 |
StaticRouteManager::DebugSPFCalculate(Ipv4Address root) |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
434 |
{ |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
435 |
SPFCalculate(root); |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
436 |
} |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
437 |
|
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
438 |
// quagga ospf_spf_calculate |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
439 |
void |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
440 |
StaticRouteManager::SPFCalculate(Ipv4Address root) |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
441 |
{ |
1086 | 442 |
NS_DEBUG("StaticRouteManager::SPFCalculate ()"); |
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
443 |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
444 |
SPFVertex *v; |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
445 |
|
1086 | 446 |
m_lsdb->Initialize (); |
1063
98fe4e27c65a
Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents:
1062
diff
changeset
|
447 |
|
1072
7002990baec9
Add candidate list (priority queue)
Tom Henderson <tomh@tomh.org>
parents:
1069
diff
changeset
|
448 |
// The candidate queue is a priority queue of SPFVertex objects, with |
7002990baec9
Add candidate list (priority queue)
Tom Henderson <tomh@tomh.org>
parents:
1069
diff
changeset
|
449 |
// the top of the queue being the closest vertex in terms of |
7002990baec9
Add candidate list (priority queue)
Tom Henderson <tomh@tomh.org>
parents:
1069
diff
changeset
|
450 |
// distanceFromRoot. Initially, this queue is empty. |
1064 | 451 |
// |
1077
ee75a75b51b3
Replace SPFVertexPriorityQueue with CandidateQueue
Tom Henderson <tomh@tomh.org>
parents:
1076
diff
changeset
|
452 |
CandidateQueue candidate; |
ee75a75b51b3
Replace SPFVertexPriorityQueue with CandidateQueue
Tom Henderson <tomh@tomh.org>
parents:
1076
diff
changeset
|
453 |
NS_ASSERT(candidate.Size() == 0); |
1064 | 454 |
// |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
455 |
// 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
|
456 |
// calculation. |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
457 |
// |
1079
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
458 |
v= new SPFVertex(m_lsdb->GetLSA(root)); |
89b08d079fb6
Non-default constructor for SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1078
diff
changeset
|
459 |
// This vertex is the root of the SPF tree |
1064 | 460 |
v->m_distanceFromRoot = 0; |
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
461 |
m_spfroot= v; |
1086 | 462 |
v->m_lsa->m_stat = StaticRouterLSA::LSA_SPF_IN_SPFTREE; |
1067
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
463 |
|
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
464 |
for (;;) |
704eb2583865
Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents:
1066
diff
changeset
|
465 |
{ |
1069 | 466 |
// RFC2328 16.1. (2). |
1072
7002990baec9
Add candidate list (priority queue)
Tom Henderson <tomh@tomh.org>
parents:
1069
diff
changeset
|
467 |
SPFNext(v , candidate); |
1086 | 468 |
|
469 |
// RFC2328 16.1. (3). |
|
470 |
// If at this step the candidate list is empty, the shortest- |
|
471 |
// path tree (of transit vertices) has been completely built and |
|
472 |
// this stage of the procedure terminates. |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
473 |
if (candidate.Size() == 0) |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
474 |
break; |
1086 | 475 |
// Otherwise, choose the vertex belonging to the candidate list |
476 |
// that is closest to the root, and add it to the shortest-path |
|
477 |
// tree (removing it from the candidate list in the |
|
478 |
// process). |
|
479 |
// Extract from the candidates the node with the lower key. |
|
1089
5ad63c15b7e4
fix merge problem that lost candidate queue changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
1088
diff
changeset
|
480 |
v = candidate.Pop(); |
1086 | 481 |
// Update stat field in vertex. |
482 |
NS_DEBUG("SPFCalculate: Popping vertex" << v->m_vertexId); |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
483 |
v->m_lsa->m_stat = StaticRouterLSA::LSA_SPF_IN_SPFTREE; |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
484 |
SPFVertexAddParent(v); |
1086 | 485 |
// Note that when there is a choice of vertices closest to the |
486 |
// root, network vertices must be chosen before router vertices |
|
487 |
// in order to necessarily find all equal-cost paths. |
|
488 |
// We don't do this at this moment, we should add the treatment |
|
489 |
// above codes. -- kunihiro. |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
490 |
|
1086 | 491 |
// RFC2328 16.1. (4). |
1083 | 492 |
SPFIntraAddRouter (v); |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
493 |
|
1086 | 494 |
// RFC2328 16.1. (5). |
495 |
// Iterate the algorithm by returning to Step 2. |
|
496 |
} // end loop until no more candidate vertices |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
497 |
|
1086 | 498 |
// Second stage of SPF calculation procedure's |
499 |
// NOTYET: ospf_spf_process_stubs (area, area->spf, new_table); |
|
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
500 |
|
1086 | 501 |
DeleteSPFVertexChain(m_spfroot); |
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
502 |
m_spfroot = 0; |
1058
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
503 |
} |
de579b1ff195
convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents:
1057
diff
changeset
|
504 |
|
1086 | 505 |
// XXX this should probably be a method on Ipv4 |
506 |
uint32_t |
|
507 |
StaticRouteManager::FindOutgoingInterfaceId(Ipv4Address a) |
|
508 |
{ |
|
509 |
||
510 |
Ipv4Address routerId = m_spfroot->m_vertexId; |
|
511 |
||
512 |
std::vector<Ptr<Node> >::iterator i = NodeList::Begin(); |
|
513 |
for (; i != NodeList::End(); i++) |
|
514 |
{ |
|
515 |
Ptr<Node> node = *i; |
|
516 |
||
517 |
Ptr<StaticRouter> rtr = |
|
518 |
node->QueryInterface<StaticRouter> (StaticRouter::iid); |
|
519 |
NS_ASSERT_MSG(rtr, |
|
1087 | 520 |
"StaticRouteManager::FindOutgoingInterfaceId (): " |
1086 | 521 |
"QI for <StaticRouter> interface failed"); |
522 |
if (rtr->GetRouterId () == routerId) |
|
523 |
{ |
|
524 |
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid); |
|
525 |
NS_ASSERT_MSG(ipv4, |
|
1087 | 526 |
"StaticRouteManager::FindOutgoingInterfaceId (): " |
1086 | 527 |
"QI for <Ipv4> interface failed"); |
528 |
for (uint32_t i = 0; i < ipv4->GetNInterfaces(); i++) |
|
529 |
{ |
|
530 |
if (ipv4->GetAddress (i) == a) { |
|
531 |
NS_DEBUG("FindOutgoingInterfaceId: Interface match for " << a); |
|
532 |
return i; |
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
536 |
} |
|
537 |
return 0; |
|
538 |
} |
|
539 |
||
540 |
// derived from quagga ospf_intra_add_router() |
|
541 |
// |
|
542 |
// This is where we add host routes to the routing tables |
|
1083 | 543 |
void |
544 |
StaticRouteManager::SPFIntraAddRouter(SPFVertex* v) |
|
545 |
{ |
|
546 |
// This vertex has just been added to the SPF tree |
|
547 |
// - the vertex should have a valid m_root_oid corresponding |
|
548 |
// to the outgoing interface on the root router of the tree |
|
549 |
// that corresponds to the path to it |
|
550 |
// - the vertex has an m_lsa field that has a number of link |
|
551 |
// records. For each point to point record, the m_linkData |
|
552 |
// is a destination IP address to which we add a host route |
|
553 |
// |
|
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
554 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
555 |
NS_ASSERT_MSG(m_spfroot, |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
556 |
"StaticRouteManager::SPFIntraAddRouter (): Root pointer not set"); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
557 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
558 |
Ipv4Address routerId = m_spfroot->m_vertexId; |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
559 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
560 |
std::vector<Ptr<Node> >::iterator i = NodeList::Begin(); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
561 |
for (; i != NodeList::End(); i++) |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
562 |
{ |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
563 |
Ptr<Node> node = *i; |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
564 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
565 |
Ptr<StaticRouter> rtr = |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
566 |
node->QueryInterface<StaticRouter> (StaticRouter::iid); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
567 |
NS_ASSERT_MSG(rtr, |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
568 |
"StaticRouteManager::SPFIntraAddRouter (): " |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
569 |
"QI for <StaticRouter> interface failed"); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
570 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
571 |
if (rtr->GetRouterId () == routerId) |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
572 |
{ |
1086 | 573 |
NS_DEBUG("StaticRouteManager::SPFIntraAddRouter (): " |
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
574 |
"setting routes for node " << node->GetId ()); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
575 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
576 |
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
577 |
NS_ASSERT_MSG(ipv4, |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
578 |
"StaticRouteManager::SPFIntraAddRouter (): " |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
579 |
"QI for <Ipv4> interface failed"); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
580 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
581 |
StaticRouterLSA *lsa = v->m_lsa; |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
582 |
NS_ASSERT_MSG(lsa, |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
583 |
"StaticRouteManager::SPFIntraAddRouter (): " |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
584 |
"Expected valid LSA in SPFVertex* v"); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
585 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
586 |
uint32_t nLinkRecords = lsa->GetNLinkRecords (); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
587 |
|
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
588 |
NS_ASSERT_MSG((nLinkRecords & 1) == 0, |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
589 |
"StaticRouteManager::SPFIntraAddRouter (): " |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
590 |
"Expected exen number of Link Records"); |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
591 |
|
1086 | 592 |
for (uint32_t j = 0; j < nLinkRecords; j += 2) |
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
593 |
{ |
1087 | 594 |
StaticRouterLinkRecord *lr = lsa->GetLinkRecord (j); |
595 |
if (lr->m_linkType != StaticRouterLinkRecord::PointToPoint) |
|
596 |
{ |
|
597 |
continue; |
|
598 |
} |
|
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
599 |
|
1088
488db5bf22c0
remove debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1087
diff
changeset
|
600 |
NS_DEBUG("StaticRouteManager::SPFIntraAddRouter (): " |
1087 | 601 |
"Add route to " << lr->m_linkData << |
1086 | 602 |
" using next hop " << v->m_nextHop << |
603 |
" via interface " << v->m_rootOif); |
|
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
604 |
|
1087 | 605 |
ipv4->AddHostRouteTo(lr->m_linkData, v->m_nextHop, |
1086 | 606 |
v->m_rootOif); |
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
607 |
} |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
608 |
} |
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
609 |
} |
1083 | 610 |
} |
611 |
||
1086 | 612 |
// Derived from quagga ospf_vertex_add_parents() |
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
613 |
// Add a vertex to the list of children in each of its parents. |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
614 |
void |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
615 |
StaticRouteManager::SPFVertexAddParent(SPFVertex* v) |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
616 |
{ |
1083 | 617 |
// For now, only one parent (not doing equal-cost multipath) |
618 |
v->m_parent->m_children.push_back(v); |
|
1082
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
619 |
} |
a4ab78763094
Initial logic for SPFNexthopCalculation
Tom Henderson <tomh@tomh.org>
parents:
1080
diff
changeset
|
620 |
|
1086 | 621 |
void |
622 |
StaticRouteManager::DeleteSPFVertexChain(SPFVertex* spfroot) |
|
623 |
{ |
|
624 |
// spfroot is the root of all SPFVertex created during the SPF process |
|
625 |
// each vertex has a list of children |
|
626 |
// Recursively, delete all of the SPFVertex children of each SPFVertex |
|
627 |
// then delete root itself |
|
628 |
} |
|
629 |
||
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
|
630 |
} // 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
|
631 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
632 |
#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
|
633 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
634 |
#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
|
635 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
636 |
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
|
637 |
|
1066
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
638 |
class StaticRouterTestNode : public Node |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
639 |
{ |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
640 |
public: |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
641 |
StaticRouterTestNode(); |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
642 |
|
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
643 |
private: |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
644 |
virtual void DoAddDevice (Ptr<NetDevice> device) const {}; |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
645 |
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
646 |
}; |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
647 |
|
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
648 |
StaticRouterTestNode::StaticRouterTestNode () |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
649 |
{ |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
650 |
// Ptr<Ipv4L3Protocol> ipv4 = Create<Ipv4L3Protocol> (this); |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
651 |
} |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
652 |
|
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
653 |
TraceResolver* |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
654 |
StaticRouterTestNode::DoCreateTraceResolver (TraceContext const &context) |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
655 |
{ |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
656 |
return 0; |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
657 |
} |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
658 |
|
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
659 |
|
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
|
660 |
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
|
661 |
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
|
662 |
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
|
663 |
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
|
664 |
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
|
665 |
}; |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
666 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
667 |
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
|
668 |
: 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
|
669 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
670 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
671 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
672 |
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
|
673 |
{} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
674 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
675 |
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
|
676 |
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
|
677 |
{ |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
678 |
bool ok = true; |
1049 | 679 |
|
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
680 |
CandidateQueue candidate; |
1068
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
681 |
|
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
682 |
for (int i = 0; i < 100; ++i) |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
683 |
{ |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
684 |
SPFVertex *v = new SPFVertex; |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
685 |
v->m_distanceFromRoot = rand () % 100; |
1084
0be920a99cc4
implement SPFIntraAddRouter
Craig Dowell <craigdo@ee.washington.edu>
parents:
1083
diff
changeset
|
686 |
candidate.Push (v); |
1068
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
687 |
} |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
688 |
|
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
689 |
uint32_t lastDistance = 0; |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
690 |
|
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
691 |
for (int i = 0; i < 100; ++i) |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
692 |
{ |
1089
5ad63c15b7e4
fix merge problem that lost candidate queue changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
1088
diff
changeset
|
693 |
SPFVertex *v = candidate.Pop (); |
1068
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
694 |
if (v->m_distanceFromRoot < lastDistance) |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
695 |
{ |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
696 |
ok = false; |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
697 |
} |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
698 |
lastDistance = v->m_distanceFromRoot; |
1089
5ad63c15b7e4
fix merge problem that lost candidate queue changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
1088
diff
changeset
|
699 |
delete v; |
5ad63c15b7e4
fix merge problem that lost candidate queue changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
1088
diff
changeset
|
700 |
v = 0; |
1068
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
701 |
} |
019229673fb4
SPFVertex Priority Queue
Craig Dowell <craigdo@ee.washington.edu>
parents:
1067
diff
changeset
|
702 |
|
1049 | 703 |
// Build fake link state database; four routers (0-3), 3 point-to-point |
704 |
// links |
|
705 |
// |
|
706 |
// n0 |
|
707 |
// \ link 0 |
|
708 |
// \ link 2 |
|
709 |
// n2 -------------------------n3 |
|
710 |
// / |
|
711 |
// / link 1 |
|
712 |
// n1 |
|
713 |
// |
|
714 |
// link0: 10.1.1.1/30, 10.1.1.2/30 |
|
715 |
// link1: 10.1.2.1/30, 10.1.2.2/30 |
|
716 |
// link2: 10.1.3.1/30, 10.1.3.2/30 |
|
717 |
// |
|
718 |
// Router 0 |
|
719 |
StaticRouterLinkRecord* lr0 = new StaticRouterLinkRecord(); |
|
720 |
lr0->m_linkId.Set(2); // router ID 0.0.0.2 |
|
721 |
lr0->m_linkData.Set("10.1.1.1"); |
|
722 |
lr0->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
723 |
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
|
724 |
StaticRouterLinkRecord* lr1 = new StaticRouterLinkRecord(); |
1049 | 725 |
lr1->m_linkId.Set("10.1.1.1"); |
726 |
lr1->m_linkData.Set("255.255.255.252"); |
|
727 |
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
|
728 |
lr1->m_metric = 1; |
1049 | 729 |
StaticRouterLSA* lsa0 = new StaticRouterLSA(); |
1055 | 730 |
lsa0->m_linkStateId.Set("0.0.0.0"); |
731 |
lsa0->m_advertisingRtr.Set("0.0.0.0"); |
|
1049 | 732 |
lsa0->AddLinkRecord(lr0); |
733 |
lsa0->AddLinkRecord(lr1); |
|
734 |
||
735 |
// Router 1 |
|
736 |
StaticRouterLinkRecord* lr2 = new StaticRouterLinkRecord(); |
|
737 |
lr2->m_linkId.Set(2); // router ID 0.0.0.2 |
|
738 |
lr2->m_linkData.Set("10.1.2.1"); |
|
739 |
lr2->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
740 |
lr2->m_metric = 1; |
|
741 |
StaticRouterLinkRecord* lr3 = new StaticRouterLinkRecord(); |
|
742 |
lr3->m_linkId.Set("10.1.2.1"); |
|
743 |
lr3->m_linkData.Set("255.255.255.252"); |
|
744 |
lr3->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
745 |
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
|
746 |
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
|
747 |
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
|
748 |
lsa1->m_advertisingRtr.Set(1); |
1049 | 749 |
lsa1->AddLinkRecord(lr2); |
750 |
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
|
751 |
|
1049 | 752 |
// Router 2 |
753 |
StaticRouterLinkRecord* lr4 = new StaticRouterLinkRecord(); |
|
754 |
lr4->m_linkId.Set("0.0.0.0"); |
|
755 |
lr4->m_linkData.Set("10.1.1.2"); |
|
756 |
lr4->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
757 |
lr4->m_metric = 1; |
|
758 |
StaticRouterLinkRecord* lr5 = new StaticRouterLinkRecord(); |
|
759 |
lr5->m_linkId.Set("10.1.1.2"); |
|
760 |
lr5->m_linkData.Set("255.255.255.252"); |
|
761 |
lr5->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
762 |
lr5->m_metric = 1; |
|
763 |
StaticRouterLinkRecord* lr6 = new StaticRouterLinkRecord(); |
|
764 |
lr6->m_linkId.Set(1); |
|
765 |
lr6->m_linkData.Set("10.1.2.2"); |
|
766 |
lr6->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
767 |
lr6->m_metric = 1; |
|
768 |
StaticRouterLinkRecord* lr7 = new StaticRouterLinkRecord(); |
|
769 |
lr7->m_linkId.Set("10.1.2.2"); |
|
770 |
lr7->m_linkData.Set("255.255.255.252"); |
|
771 |
lr7->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
772 |
lr7->m_metric = 1; |
|
773 |
StaticRouterLinkRecord* lr8 = new StaticRouterLinkRecord(); |
|
774 |
lr8->m_linkId.Set(3); |
|
775 |
lr8->m_linkData.Set("10.1.3.2"); |
|
776 |
lr8->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
777 |
lr8->m_metric = 1; |
|
778 |
StaticRouterLinkRecord* lr9 = new StaticRouterLinkRecord(); |
|
779 |
lr9->m_linkId.Set("10.1.3.2"); |
|
780 |
lr9->m_linkData.Set("255.255.255.252"); |
|
781 |
lr9->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
782 |
lr9->m_metric = 1; |
|
783 |
StaticRouterLSA* lsa2 = new StaticRouterLSA(); |
|
784 |
lsa2->m_linkStateId.Set(2); |
|
785 |
lsa2->m_advertisingRtr.Set(2); |
|
786 |
lsa2->AddLinkRecord(lr4); |
|
787 |
lsa2->AddLinkRecord(lr5); |
|
788 |
lsa2->AddLinkRecord(lr6); |
|
789 |
lsa2->AddLinkRecord(lr7); |
|
790 |
lsa2->AddLinkRecord(lr8); |
|
791 |
lsa2->AddLinkRecord(lr9); |
|
792 |
||
793 |
// Router 3 |
|
794 |
StaticRouterLinkRecord* lr10 = new StaticRouterLinkRecord(); |
|
795 |
lr10->m_linkId.Set(2); // router ID 0.0.0.2 |
|
796 |
lr10->m_linkData.Set("10.1.2.1"); |
|
797 |
lr10->m_linkType = StaticRouterLinkRecord::PointToPoint; |
|
798 |
lr10->m_metric = 1; |
|
799 |
StaticRouterLinkRecord* lr11 = new StaticRouterLinkRecord(); |
|
800 |
lr11->m_linkId.Set("10.1.2.1"); |
|
801 |
lr11->m_linkData.Set("255.255.255.252"); |
|
802 |
lr11->m_linkType = StaticRouterLinkRecord::StubNetwork; |
|
803 |
lr11->m_metric = 1; |
|
804 |
StaticRouterLSA* lsa3 = new StaticRouterLSA(); |
|
805 |
lsa3->m_linkStateId.Set(3); |
|
806 |
lsa3->m_advertisingRtr.Set(3); |
|
807 |
lsa3->AddLinkRecord(lr2); |
|
808 |
lsa3->AddLinkRecord(lr3); |
|
809 |
||
1053 | 810 |
// Test the database |
811 |
StaticRouteManagerLSDB* srmlsdb = new StaticRouteManagerLSDB(); |
|
1076
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
812 |
srmlsdb->Insert(lsa0->m_linkStateId, lsa0); |
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
813 |
srmlsdb->Insert(lsa1->m_linkStateId, lsa1); |
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
814 |
srmlsdb->Insert(lsa2->m_linkStateId, lsa2); |
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
815 |
srmlsdb->Insert(lsa3->m_linkStateId, lsa3); |
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
816 |
NS_ASSERT(lsa2 == srmlsdb->GetLSA(lsa2->m_linkStateId)); |
1049 | 817 |
|
1066
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
818 |
// We need a dummy node to populate the routing tables |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
819 |
Ptr<StaticRouterTestNode> n2 = Create<StaticRouterTestNode> (); |
f19baa3a0cb5
Dummy test node for unit testing
Tom Henderson <tomh@tomh.org>
parents:
1065
diff
changeset
|
820 |
|
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
821 |
// XXX next, calculate routes based on the manually created LSDB |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
822 |
StaticRouteManager* srm = new StaticRouteManager(); |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
823 |
srm->DebugUseLsdb (srmlsdb); |
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
824 |
srm->DebugSPFCalculate(lsa0->m_linkStateId); // node n0 |
1055 | 825 |
|
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
826 |
// This delete clears the srm, which deletes the LSDB, which clears |
1076
1fa07692b5ca
Make LSDB back into a storage for LSAs
Tom Henderson <tomh@tomh.org>
parents:
1072
diff
changeset
|
827 |
// all of the LSAs, which each destroys the attached LinkRecords. |
1059
2ebd3bb3da3e
more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents:
1058
diff
changeset
|
828 |
delete srm; |
1049 | 829 |
|
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
|
830 |
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
|
831 |
} |
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
832 |
|
1055 | 833 |
// 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
|
834 |
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
|
835 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
836 |
} // 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
|
837 |
|
c2c43e021fb7
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
838 |
#endif |