Lines 53-59
SPFVertex::SPFVertex () :
|
Link Here
|
---|
|
53 |
m_rootOif (SPF_INFINITY), |
53 |
m_rootOif (SPF_INFINITY), |
54 |
m_nextHop ("0.0.0.0"), |
54 |
m_nextHop ("0.0.0.0"), |
55 |
m_parent (0), |
55 |
m_parent (0), |
56 |
m_children () |
56 |
m_children (), |
|
|
57 |
m_vertexProcessed (false) |
57 |
{ |
58 |
{ |
58 |
NS_LOG_FUNCTION_NOARGS (); |
59 |
NS_LOG_FUNCTION_NOARGS (); |
59 |
} |
60 |
} |
Lines 65-71
SPFVertex::SPFVertex (GlobalRoutingLSA*
|
Link Here
|
---|
|
65 |
m_rootOif (SPF_INFINITY), |
66 |
m_rootOif (SPF_INFINITY), |
66 |
m_nextHop ("0.0.0.0"), |
67 |
m_nextHop ("0.0.0.0"), |
67 |
m_parent (0), |
68 |
m_parent (0), |
68 |
m_children () |
69 |
m_children (), |
|
|
70 |
m_vertexProcessed (false) |
69 |
{ |
71 |
{ |
70 |
NS_LOG_FUNCTION_NOARGS (); |
72 |
NS_LOG_FUNCTION_NOARGS (); |
71 |
if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) |
73 |
if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) |
Lines 226-231
SPFVertex::AddChild (SPFVertex* child)
|
Link Here
|
---|
|
226 |
m_children.push_back (child); |
228 |
m_children.push_back (child); |
227 |
return m_children.size (); |
229 |
return m_children.size (); |
228 |
} |
230 |
} |
|
|
231 |
|
232 |
void |
233 |
SPFVertex::SetVertexProcessed (bool value) |
234 |
{ |
235 |
m_vertexProcessed = value; |
236 |
} |
237 |
|
238 |
bool |
239 |
SPFVertex::IsVertexProcessed (void) const |
240 |
{ |
241 |
return m_vertexProcessed; |
242 |
} |
243 |
|
229 |
|
244 |
|
230 |
// --------------------------------------------------------------------------- |
245 |
// --------------------------------------------------------------------------- |
231 |
// |
246 |
// |
Lines 1174-1184
GlobalRouteManagerImpl::SPFCalculate (Ip
|
Link Here
|
---|
|
1174 |
// |
1189 |
// |
1175 |
// Iterate the algorithm by returning to Step 2 until there are no more |
1190 |
// Iterate the algorithm by returning to Step 2 until there are no more |
1176 |
// candidate vertices. |
1191 |
// candidate vertices. |
1177 |
// |
1192 |
|
1178 |
} |
1193 |
} // end for loop |
1179 |
// |
1194 |
|
1180 |
// Second stage of SPF calculation procedure's |
1195 |
// Second stage of SPF calculation procedure |
1181 |
// NOTYET: ospf_spf_process_stubs (area, area->spf, new_table); |
1196 |
SPFProcessStubs (m_spfroot); |
1182 |
// |
1197 |
// |
1183 |
// We're all done setting the routing information for the node at the root of |
1198 |
// We're all done setting the routing information for the node at the root of |
1184 |
// the SPF tree. Delete all of the vertices and corresponding resources. Go |
1199 |
// the SPF tree. Delete all of the vertices and corresponding resources. Go |
Lines 1186-1191
GlobalRouteManagerImpl::SPFCalculate (Ip
|
Link Here
|
---|
|
1186 |
// |
1201 |
// |
1187 |
delete m_spfroot; |
1202 |
delete m_spfroot; |
1188 |
m_spfroot = 0; |
1203 |
m_spfroot = 0; |
|
|
1204 |
} |
1205 |
|
1206 |
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs () |
1207 |
// stub link records will exist for point-to-point interfaces and for |
1208 |
// broadcast interfaces for which no neighboring router can be found |
1209 |
void |
1210 |
GlobalRouteManagerImpl::SPFProcessStubs (SPFVertex* v) |
1211 |
{ |
1212 |
NS_LOG_FUNCTION_NOARGS (); |
1213 |
NS_LOG_LOGIC ("Processing stubs for " << v->GetVertexId ()); |
1214 |
if (v->GetVertexType () == SPFVertex::VertexRouter) |
1215 |
{ |
1216 |
GlobalRoutingLSA *rlsa = v->GetLSA (); |
1217 |
NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ()); |
1218 |
for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++) |
1219 |
{ |
1220 |
NS_LOG_LOGIC ("Examining link " << i << " of " << |
1221 |
v->GetVertexId () << "'s " << |
1222 |
v->GetLSA ()->GetNLinkRecords () << " link records"); |
1223 |
GlobalRoutingLinkRecord *l = v->GetLSA ()->GetLinkRecord (i); |
1224 |
if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork) |
1225 |
{ |
1226 |
NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ()); |
1227 |
SPFIntraAddStub (l, v); |
1228 |
continue; |
1229 |
} |
1230 |
} |
1231 |
} |
1232 |
for (uint32_t i = 0; i < v->GetNChildren (); i++) |
1233 |
{ |
1234 |
if (!v->GetChild (i)->IsVertexProcessed ()) |
1235 |
{ |
1236 |
SPFProcessStubs (v->GetChild (i)); |
1237 |
v->GetChild (i)->SetVertexProcessed (true); |
1238 |
} |
1239 |
} |
1240 |
} |
1241 |
|
1242 |
// RFC2328 16.1. second stage. |
1243 |
void |
1244 |
GlobalRouteManagerImpl::SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v) |
1245 |
{ |
1246 |
NS_LOG_FUNCTION_NOARGS (); |
1247 |
|
1248 |
NS_ASSERT_MSG (m_spfroot, |
1249 |
"GlobalRouteManagerImpl::SPFIntraAddStub (): Root pointer not set"); |
1250 |
|
1251 |
// XXX simplifed logic for the moment. There are two cases to consider: |
1252 |
// 1) the stub network is on this router; do nothing for now |
1253 |
// (already handled above) |
1254 |
// 2) the stub network is on a remote router, so I should use the |
1255 |
// same next hop that I use to get to vertex v |
1256 |
if (v->GetVertexId () == m_spfroot->GetVertexId ()) |
1257 |
{ |
1258 |
NS_LOG_LOGIC ("Stub is on local host: " << v->GetVertexId () << "; returning"); |
1259 |
return; |
1260 |
} |
1261 |
NS_LOG_LOGIC ("Stub is on remote host: " << v->GetVertexId () << "; installing"); |
1262 |
// |
1263 |
// The root of the Shortest Path First tree is the router to which we are |
1264 |
// going to write the actual routing table entries. The vertex corresponding |
1265 |
// to this router has a vertex ID which is the router ID of that node. We're |
1266 |
// going to use this ID to discover which node it is that we're actually going |
1267 |
// to update. |
1268 |
// |
1269 |
Ipv4Address routerId = m_spfroot->GetVertexId (); |
1270 |
|
1271 |
NS_LOG_LOGIC ("Vertex ID = " << routerId); |
1272 |
// |
1273 |
// We need to walk the list of nodes looking for the one that has the router |
1274 |
// ID corresponding to the root vertex. This is the one we're going to write |
1275 |
// the routing information to. |
1276 |
// |
1277 |
NodeList::Iterator i = NodeList::Begin (); |
1278 |
for (; i != NodeList::End (); i++) |
1279 |
{ |
1280 |
Ptr<Node> node = *i; |
1281 |
// |
1282 |
// The router ID is accessible through the GlobalRouter interface, so we need |
1283 |
// to QI for that interface. If there's no GlobalRouter interface, the node |
1284 |
// in question cannot be the router we want, so we continue. |
1285 |
// |
1286 |
Ptr<GlobalRouter> rtr = |
1287 |
node->GetObject<GlobalRouter> (); |
1288 |
|
1289 |
if (rtr == 0) |
1290 |
{ |
1291 |
NS_LOG_LOGIC ("No GlobalRouter interface on node " << |
1292 |
node->GetId ()); |
1293 |
continue; |
1294 |
} |
1295 |
// |
1296 |
// If the router ID of the current node is equal to the router ID of the |
1297 |
// root of the SPF tree, then this node is the one for which we need to |
1298 |
// write the routing tables. |
1299 |
// |
1300 |
NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ()); |
1301 |
|
1302 |
if (rtr->GetRouterId () == routerId) |
1303 |
{ |
1304 |
NS_LOG_LOGIC ("Setting routes for node " << node->GetId ()); |
1305 |
// |
1306 |
// Routing information is updated using the Ipv4 interface. We need to QI |
1307 |
// for that interface. If the node is acting as an IP version 4 router, it |
1308 |
// should absolutely have an Ipv4 interface. |
1309 |
// |
1310 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
1311 |
NS_ASSERT_MSG (ipv4, |
1312 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
1313 |
"QI for <Ipv4> interface failed"); |
1314 |
// |
1315 |
// Get the Global Router Link State Advertisement from the vertex we're |
1316 |
// adding the routes to. The LSA will have a number of attached Global Router |
1317 |
// Link Records corresponding to links off of that vertex / node. We're going |
1318 |
// to be interested in the records corresponding to point-to-point links. |
1319 |
// |
1320 |
GlobalRoutingLSA *lsa = v->GetLSA (); |
1321 |
NS_ASSERT_MSG (lsa, |
1322 |
"GlobalRouteManagerImpl::SPFIntraAddRouter (): " |
1323 |
"Expected valid LSA in SPFVertex* v"); |
1324 |
//Address tempaddr = Address (l->GetLinkData); |
1325 |
Ipv4Mask tempmask ("255.255.255.0"); |
1326 |
Ipv4Address tempip = l->GetLinkId (); |
1327 |
tempip = tempip.CombineMask (tempmask); |
1328 |
|
1329 |
NS_LOG_LOGIC (" Node " << node->GetId () << |
1330 |
" add route to " << tempip << |
1331 |
" with mask " << tempmask << |
1332 |
" using next hop " << v->GetNextHop () << |
1333 |
" via interface " << v->GetOutgoingTypeId ()); |
1334 |
// |
1335 |
// Here's why we did all of that work. We're going to add a host route to the |
1336 |
// host address found in the m_linkData field of the point-to-point link |
1337 |
// record. In the case of a point-to-point link, this is the local IP address |
1338 |
// of the node connected to the link. Each of these point-to-point links |
1339 |
// will correspond to a local interface that has an IP address to which |
1340 |
// the node at the root of the SPF tree can send packets. The vertex <v> |
1341 |
// (corresponding to the node that has these links and interfaces) has |
1342 |
// an m_nextHop address precalculated for us that is the address to which the |
1343 |
// root node should send packets to be forwarded to these IP addresses. |
1344 |
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to |
1345 |
// which the packets should be send for forwarding. |
1346 |
// |
1347 |
Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ()); |
1348 |
NS_ASSERT (gr); |
1349 |
gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingTypeId ()); |
1350 |
return; |
1351 |
} // if |
1352 |
} // for |
1189 |
} |
1353 |
} |
1190 |
|
1354 |
|
1191 |
// |
1355 |
// |