17#include "OSPF_Neighbor.h"
20#include "OSPF_Interface.h"
22#include "OSPF_RoutingTable.h"
24static ptrOSPFVERTEX OSPF_SPF_COPY_VERTEX(ptrOSPFVERTEX vertex)
26 ptrOSPFVERTEX v = calloc(1,
sizeof* v);
27 memcpy(v, vertex,
sizeof* v);
28 v->nextHopList = ospf_list_copyAll(vertex->nextHopList);
32static void OSPF_SPF_FREE_VERTEX(ptrOSPFVERTEX vertex)
34 ospf_list_delete_all(vertex->nextHopList);
39static void ospf_spf_printVertexList(ptrOSPF_PDS ospf, ptrOSPFLIST shortestPathList)
42 void* pass = ospf_list_newIterator();
43 while ((entry = ospf_list_iterate_mem(shortestPathList,pass)) != NULL)
45 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tVertex Id = %s", entry->vertexId->str_ip);
46 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tVertex Type = %s",strOSPFVERTEXTYPE[entry->vertexType]);
47 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tMetric = %d", entry->distance);
49 ptrOSPFNEXTHOPLISTITEM nextHopItem;
50 void* npass = ospf_list_newIterator();
52 while ((nextHopItem = ospf_list_iterate_mem(entry->nextHopList, npass)) != NULL)
54 if(nextHopItem->nextHop)
55 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tNext Hop[%d] = %s",
57 nextHopItem->nextHop->str_ip);
59 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tNext Hop[%d] = Directly connected",
63 ospf_list_deleteIterator(npass);
65 ospf_list_deleteIterator(pass);
68static void ospf_spf_printShortestpath(ptrOSPF_PDS ospf,
71 ptrOSPFLIST shortestPathList = area->shortestPathList;
72 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"Shortest path list for router %u, area %s",
74 area->areaId->str_ip);
75 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
" size = %d", ospf_list_get_size(shortestPathList));
77 ospf_spf_printVertexList(ospf, shortestPathList);
80void ospf_spf_scheduleCalculation(ptrOSPF_PDS ospf)
82 if (ospf->SPFTimer > pstruEventDetails->dEventTime)
84 double t = pstruEventDetails->dEventTime;
85 t += ospf->spfCalcDelay*NETSIM_RAND_01();
88 pstruEventDetails->nDeviceId,
95static void ospf_spf_invalidateRoutingTable(ptrOSPF_PDS ospf)
97 ptrOSPFROUTINGTABLEROW* rowPtr = ospf->routingTable->rows;
99 for (i = 0; i < ospf->routingTable->numRow; i++)
101 rowPtr[i]->flag = OSPFROUTEFLAG_INVALID;
105static void ospf_spf_updateCandidateListUsingNWLSA(ptrOSPF_PDS ospf,
107 ptrOSPFLIST candidateList,
108 ptrOSPFVERTEX vertex)
114 fnNetSimError(
"Implement after NWLSA implementation");
115#pragma message(__LOC__"Implement after NWLSA implementation")
118static bool ospf_spf_isInShortestPathList(ptrOSPF_PDS ospf,
119 ptrOSPFLIST shortestPathList,
120 OSPFVERTEXTYPE vertexType,
121 NETSIM_IPAddress vertexId)
125 ptrOSPFVERTEX vertex;
126 void* pass = ospf_list_newIterator();
127 while ((vertex = ospf_list_iterate_mem(shortestPathList, pass)) != NULL)
130 if (vertex->vertexType == vertexType &&
131 !IP_COMPARE(vertex->vertexId, vertexId))
133 ospf_list_deleteIterator(pass);
137 ospf_list_deleteIterator(pass);
141static ptrOSPFVERTEX ospf_spf_findCandidate(ptrOSPF_PDS ospf,
142 ptrOSPFLIST candidateList,
143 OSPFVERTEXTYPE vertexType,
144 NETSIM_IPAddress vertexId)
148 ptrOSPFVERTEX vertex;
149 void* pass = ospf_list_newIterator();
150 while ((vertex = ospf_list_iterate_mem(candidateList, pass)) != NULL)
152 if (vertex->vertexType == vertexType &&
153 !IP_COMPARE(vertex->vertexId, vertexId))
155 ospf_list_deleteIterator(pass);
159 ospf_list_deleteIterator(pass);
163static NETSIM_IPAddress ospf_spf_getLinkDataForThisVertex(ptrOSPF_PDS ospf,
164 ptrOSPFVERTEX vertex,
165 ptrOSPFVERTEX parent)
169 ptrOSPFLSAHDR lsa = parent->lsa;
170 ptrOSPFRLSA rtrLSA = lsa->lsaInfo;
173 for (i = 0; i < rtrLSA->linksCount; i++)
175 ptrOSPFRLSALINK link = rtrLSA->rlsaLink[i];
176 if (link->type != OSPFLINKTYPE_STUB &&
177 !IP_COMPARE(link->linkId, vertex->vertexId))
178 return link->linkData;
181 fnNetSimError(
"Not get link data from the associated link "
182 "for this vertex %s\n",
183 vertex->vertexId->str_ip);
187static bool ospf_spf_haveLinkWithNetworkVertex(ptrOSPF_PDS ospf,
188 ptrOSPFVERTEX vertex)
190 NETSIM_ID d = ospf->myId;
192 for (i = 0; i < ospf->ifCount; i++)
194 ptrOSPF_IF thisInterface = ospf->ospfIf[i];
195 NETSIM_ID in = thisInterface->id;
196 NETSIM_IPAddress subnetMask = DEVICE_SUBNETMASK(d, in);
197 NETSIM_IPAddress netAddr = DEVICE_NWADDRESS(d, in);
199 if (IP_IS_IN_SAME_NETWORK_IPV4(vertex->vertexId,
202 thisInterface->State != OSPFIFSTATE_DOWN)
208static bool ospf_spf_isPresentinNextHopList(ptrOSPFLIST nextHopList,
209 ptrOSPFNEXTHOPLISTITEM item)
211 ptrOSPFNEXTHOPLISTITEM i;
212 void* pass = ospf_list_newIterator();
213 while ((i = ospf_list_iterate_mem(nextHopList,pass)) != NULL)
217 ospf_list_deleteIterator(pass);
221 ospf_list_deleteIterator(pass);
225static bool ospf_spf_setNextHopForThisVertex(ptrOSPF_PDS ospf,
226 ptrOSPFVERTEX vertex,
227 ptrOSPFVERTEX parent)
229 ptrOSPFNEXTHOPLISTITEM nextHopItem;
230 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"Parent = %s, Vertex = %s",
231 parent->vertexId->str_ip,
232 vertex->vertexId->str_ip);
233 if (parent->vertexType == OSPFVERTEXTYPE_ROUTER &&
234 !IP_COMPARE(parent->vertexId, ospf->routerId))
236 NETSIM_IPAddress linkData = NULL;
237 NETSIM_ID interfaceId;
239 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"Parent is ROOT");
240 linkData = ospf_spf_getLinkDataForThisVertex(ospf, vertex, parent);
241 interfaceId = fn_NetSim_Stack_GetInterfaceIdFromIP(ospf->myId, linkData);
243 ptrOSPF_IF thisInterface = OSPF_IF_GET(ospf, interfaceId);
244 if (thisInterface->State == OSPFIFSTATE_DOWN)
247 nextHopItem = calloc(1,
sizeof* nextHopItem);
248 nextHopItem->outIntf = interfaceId;
250 if (vertex->vertexType == OSPFVERTEXTYPE_ROUTER)
253 ptrOSPF_NEIGHBOR neigh;
254 NETSIM_IPAddress nbrIPAddress = NULL;
256 in = fn_NetSim_Stack_GetInterfaceIdFromIP(ospf->myId, linkData);
257 ptrOSPF_IF cif = OSPF_IF_GET(ospf, in);
258 neigh = OSPF_NEIGHBOR_FIND(cif, vertex->vertexId);
267 nbrIPAddress = neigh->neighborIPAddr;
269 nextHopItem->nextHop = nbrIPAddress;
274 nextHopItem->nextHop = NULL;
277 if (!ospf_spf_isPresentinNextHopList(vertex->nextHopList, nextHopItem))
279 ospf_list_add_mem(vertex->nextHopList, nextHopItem);
287 else if (parent->vertexType == OSPFVERTEXTYPE_NETWORK &&
288 ospf_spf_haveLinkWithNetworkVertex(ospf, parent))
294 NETSIM_IPAddress linkData = NULL;
295 NETSIM_ID interfaceId;
297 linkData = ospf_spf_getLinkDataForThisVertex(ospf, vertex, parent);
298 interfaceId = fn_NetSim_Stack_GetInterfaceIdFromIP(ospf->myId,
304 ptrOSPF_IF thisInterface = OSPF_IF_GET(ospf, interfaceId);
305 if (thisInterface->State == OSPFIFSTATE_DOWN)
308 nextHopItem = calloc(1,
sizeof* nextHopItem);
309 nextHopItem->nextHop = linkData;
310 nextHopItem->outIntf = interfaceId;
312 if (!ospf_spf_isPresentinNextHopList(vertex->nextHopList, nextHopItem))
314 ospf_list_add_mem(vertex->nextHopList, nextHopItem);
326 bool inserted =
false;
328 ptrOSPFNEXTHOPLISTITEM listItem;
329 void* pass = ospf_list_newIterator();
330 while ((listItem=ospf_list_iterate_mem(parent->nextHopList,pass))!=NULL)
332 nextHopItem = calloc(1,
sizeof* nextHopItem);
333 memcpy(nextHopItem, listItem,
sizeof* nextHopItem);
335 if (!ospf_spf_isPresentinNextHopList(vertex->nextHopList,
338 ospf_list_add_mem(vertex->nextHopList, nextHopItem);
346 ospf_list_deleteIterator(pass);
352static void ospf_spf_updateCandidateListUsingRouterLSA(ptrOSPF_PDS ospf,
354 ptrOSPFLIST candidateList,
355 ptrOSPFVERTEX vertex)
357 ptrOSPFRLSA vlsa = vertex->lsa->lsaInfo;
360 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tLooking for vertex %s from router LSA",
361 vertex->vertexId->str_ip);
364 for (i = 0; i < vlsa->linksCount; i++)
366 OSPFVERTEXTYPE newVertexType;
367 NETSIM_IPAddress newVertexId;
368 UINT newVertexDistance;
369 ptrOSPFVERTEX candidateListItem = NULL;
370 ptrOSPFRLSALINK link = vlsa->rlsaLink[i];
371 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tExamine link %s, link type %s",
372 link->linkId->str_ip, strOSPFLINKTYPE[link->type]);
374 if (link->type == OSPFLINKTYPE_POINT_TO_POINT)
376 wlsa = ospf_lsdb_lookup_lsaList(area->routerLSAList,
380 newVertexType = OSPFVERTEXTYPE_ROUTER;
382 else if (link->type == OSPFLINKTYPE_TRANSIT)
384 wlsa = ospf_lsdb_lookup_lsaListByID(area->nwLSAList, link->linkId);
385 newVertexType = OSPFVERTEXTYPE_NETWORK;
394 ospf_lsa_hasMaxAge(ospf, wlsa) ||
396 ospf_spf_isInShortestPathList(ospf,
397 area->shortestPathList,
402 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\twlsa is NULL");
403 else if (ospf_lsa_hasMaxAge(ospf, wlsa))
404 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tWLSA has MAX AGE");
405 else if (!ospf_rlsa_hasLink(ospf, wlsa, vertex->lsa))
406 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tNo Link between wLSA and vLSA");
410 newVertexId = wlsa->LinkStateID;
411 newVertexDistance = vertex->distance + link->metric;
413 candidateListItem = ospf_spf_findCandidate(ospf,
417 if (!candidateListItem)
420 candidateListItem = calloc(1,
sizeof* candidateListItem);
422 candidateListItem->vertexId = newVertexId;
423 candidateListItem->vertexType = newVertexType;
424 candidateListItem->lsa = wlsa;
425 candidateListItem->distance = newVertexDistance;
426 candidateListItem->nextHopList = ospf_list_init(NULL, NULL);
427 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\n\tPossible new candidate is %s", newVertexId->str_ip);
428 if (ospf_spf_setNextHopForThisVertex(ospf,candidateListItem,vertex))
430 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tInserting new vertex %s\n", newVertexId->str_ip);
431 ospf_list_add_mem(candidateList, candidateListItem);
435 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"\tSet next hop is FALSE for candidate %s\n", newVertexId->str_ip);
436 ospf_list_delete_all(candidateListItem->nextHopList);
437 free(candidateListItem);
440 else if (candidateListItem->distance > newVertexDistance)
443 candidateListItem->distance = newVertexDistance;
446 ospf_list_delete_all(candidateListItem->nextHopList);
447 ospf_spf_setNextHopForThisVertex(ospf, candidateListItem, vertex);
449 else if (candidateListItem->distance == newVertexDistance)
452 ospf_spf_setNextHopForThisVertex(ospf, candidateListItem, vertex);
462static void ospf_spf_updateCandidateList(ptrOSPF_PDS ospf,
464 ptrOSPFLIST candidateList,
465 ptrOSPFVERTEX vertex)
467 if (vertex->vertexType == OSPFVERTEXTYPE_NETWORK)
468 ospf_spf_updateCandidateListUsingNWLSA(ospf, area, candidateList, vertex);
470 ospf_spf_updateCandidateListUsingRouterLSA(ospf, area, candidateList, vertex);
473static void ospf_spf_updateIntraAreaRoute(ptrOSPF_PDS ospf,
475 ptrOSPFVERTEX vertex)
477 OSPFROUTINGTABLEROW newRow;
478 ptrOSPFNEXTHOPLISTITEM nextHopItem = NULL;
479 ptrOSPF_IF thisInterface = NULL;
480 if (!ospf_list_is_empty(vertex->nextHopList))
482 nextHopItem = ospf_list_get_headptr(vertex->nextHopList);
483 thisInterface = OSPF_IF_GET(ospf, nextHopItem->outIntf);
487 if (vertex->vertexType == OSPFVERTEXTYPE_ROUTER)
489 ptrOSPFLSAHDR lsa = vertex->lsa;
490 ptrOSPFRLSA routerLSA = vertex->lsa->lsaInfo;
492 if(Ospf_rlsa_getASBRouter(routerLSA->VEB) ||
493 Ospf_rlsa_getABRouter(routerLSA->VEB))
496 if (Ospf_rlsa_getABRouter(routerLSA->VEB) &&
497 Ospf_rlsa_getASBRouter(routerLSA->VEB))
498 newRow.destType = OSPFDESTTYPE_ABR_ASBR;
499 else if(Ospf_rlsa_getABRouter(routerLSA->VEB))
500 newRow.destType = OSPFDESTTYPE_ABR;
502 newRow.destType = OSPFDESTTYPE_ASBR;
504 newRow.destAddr = vertex->vertexId;
505 newRow.addrMask = ANY_DEST;
507 newRow.option = lsa->Options;
509 newRow.areaId = area->areaId;
510 newRow.pathType = OSPFPATHTYPE_INTRA_AREA;
511 newRow.metric = vertex->distance;
512 newRow.type2Metric = 0;
513 newRow.LSOrigin = (
void*)vertex->lsa;
514 newRow.advertisingRouter = lsa->AdvertisingRouter;
517 newRow.nextHop = nextHopItem->nextHop;
518 newRow.outInterface = DEVICE_NWADDRESS(ospf->myId, nextHopItem->outIntf);
519 newRow.outInterfaceId = nextHopItem->outIntf;
522 ospf_rtTable_addRoute(ospf, &newRow);
526 else if (nextHopItem != NULL &&
527 thisInterface->includeSubnetRts)
529 fnNetSimError(
"Reserved for future use. This will work after network LSA implementation.\n");
530#pragma message(__LOC__"Implement after network LSA implementation")
534static ptrOSPFVERTEX ospf_spf_updateShortestPathList(ptrOSPF_PDS ospf,
536 ptrOSPFLIST candidateList)
538 UINT lowestMetric = OSPF_LS_INFINITY;
539 ptrOSPFVERTEX candidateEntry;
540 ptrOSPFVERTEX closestCandidate = NULL;
541 void* pass = ospf_list_newIterator();
544 while ((candidateEntry = ospf_list_iterate_mem(candidateList, pass)) != NULL)
546 if (candidateEntry->distance < lowestMetric)
548 lowestMetric = candidateEntry->distance;
551 closestCandidate = candidateEntry;
554 else if (candidateEntry->distance == lowestMetric &&
556 closestCandidate->vertexType == OSPFVERTEXTYPE_ROUTER &&
557 candidateEntry->vertexType == OSPFVERTEXTYPE_NETWORK)
561 closestCandidate = candidateEntry;
564 ospf_list_deleteIterator(pass);
566 ptrOSPFVERTEX shortestPathListItem = closestCandidate;
569 ospf_list_add_mem(area->shortestPathList, shortestPathListItem);
572 ospf_list_remove_mem(candidateList, closestCandidate, NULL);
575 ospf_spf_updateIntraAreaRoute(ospf, area, shortestPathListItem);
577 return shortestPathListItem;
580static bool ospf_spf_removeLSAFromShortestPathList(ptrOSPF_PDS ospf,
581 ptrOSPFLIST shortestPathList,
586 ptrOSPFVERTEX vertex = NULL;
587 void* pass = ospf_list_newIterator();
588 while ((vertex = ospf_list_iterate_mem(shortestPathList, pass)) != NULL)
590 if (lsa == vertex->lsa)
592 if (vertex->nextHopList)
593 ospf_list_delete_all(vertex->nextHopList);
594 ospf_list_remove_mem(shortestPathList, lsa, pass);
595 ospf_list_deleteIterator(pass);
599 ospf_list_deleteIterator(pass);
603static void ospf_spf_addStubRouteToshortestPath(ptrOSPF_PDS ospf,
604 ptrOSPFAREA_DS thisArea)
607 ptrOSPFVERTEX tempV = NULL;
610 void* pass = ospf_list_newIterator();
611 while ((tempV = ospf_list_iterate_mem(thisArea->shortestPathList, pass)) != NULL)
614 if (tempV->vertexType != OSPFVERTEXTYPE_ROUTER)
617 ptrOSPFLSAHDR lsaHdr = tempV->lsa;
618 ptrOSPFRLSA rlsa = lsaHdr->lsaInfo;
621 if (ospf_lsa_maskDoNotAge(ospf, lsaHdr->LSAge) >= ospf->LSAMaxAge)
624 for (i = 0; i < rlsa->linksCount; i++)
626 ptrOSPFRLSALINK link = rlsa->rlsaLink[i];
629 if (link->type != OSPFLINKTYPE_STUB)
633 if (ospf_isMyAddr(ospf->myId, link->linkId))
635 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"%s is my address. Not processing this link", link->linkId->str_ip);
640 distance = link->metric + tempV->distance;
642 ptrOSPFROUTINGTABLEROW rowPtr;
645 if (!IP_COMPARE(link->linkData, ANY_DEST))
646 rowPtr = ospf_rtTable_getValidHostRoute(ospf,
648 OSPFDESTTYPE_NETWORK);
650 rowPtr = ospf_rtTable_getValidRoute(ospf,
652 OSPFDESTTYPE_NETWORK);
654 OSPFROUTINGTABLEROW newRow;
661 if (distance >= rowPtr->metric)
664 ospf_rtTable_freeRoute(ospf, rowPtr);
668 newRow.destType = OSPFDESTTYPE_NETWORK;
669 newRow.destAddr = link->linkId;
670 newRow.addrMask = link->linkData;
672 newRow.areaId = thisArea->areaId;
673 newRow.pathType = OSPFPATHTYPE_INTRA_AREA;
674 newRow.metric = distance;
675 newRow.type2Metric = 0;
676 newRow.LSOrigin = (
void*)tempV->lsa;
677 newRow.advertisingRouter = lsaHdr->AdvertisingRouter;
680 if (!OSPFID_COMPARE(tempV->vertexId, ospf->routerId))
685 if (link->linkData->int_ip[0] != 0xffffffff)
687 intfId = ospf_neighbor_getInterfaceIdforThisNeighbor(ospf,
692 intfId = ospf_getInterfaceIdForNextHop(ospf->myId,
698 ptrOSPFLSAHDR LSHeader = NULL;
700 LSHeader = ospf_lsdb_lookup_lsaList(thisArea->routerLSAList,
706 ospf_lsdb_removeLSA(ospf,
710 ospf_spf_removeLSAFromShortestPathList(ospf,
711 thisArea->shortestPathList,
718 newRow.outInterface = DEVICE_NWADDRESS(ospf->myId, intfId);
719 newRow.outInterfaceId = intfId;
720 newRow.nextHop = NULL;
724 if (!tempV->nextHopList)
727 if (ospf_list_is_empty(tempV->nextHopList))
730 ptrOSPFNEXTHOPLISTITEM nextHopItem = ospf_list_get_headptr(tempV->nextHopList);
731 newRow.nextHop = nextHopItem->nextHop;
732 newRow.outInterface = DEVICE_NWADDRESS(ospf->myId, nextHopItem->outIntf);
733 newRow.outInterfaceId = nextHopItem->outIntf;
737 ospf_rtTable_addRoute(ospf, &newRow);
740 ospf_list_deleteIterator(pass);
743static void ospf_spf_printCandidateList(ptrOSPF_PDS ospf,
744 ptrOSPFLIST candidateList)
746 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"Candidate list for router %d", ospf->myId);
747 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
" size = %d", ospf_list_get_size(candidateList));
749 ospf_spf_printVertexList(ospf, candidateList);
752static void ospf_spf_findShrotestPathForThisArea(ptrOSPF_PDS ospf,
755 ptrOSPFLIST candidateList = ospf_list_init(OSPF_SPF_FREE_VERTEX, OSPF_SPF_COPY_VERTEX);
756 ptrOSPFVERTEX tempV = calloc(1,
sizeof* tempV);
758 area->shortestPathList = ospf_list_init(OSPF_SPF_FREE_VERTEX, OSPF_SPF_COPY_VERTEX);
760 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"Calculating shortest path for area %s",
761 area->areaId->str_ip);
764 tempV->vertexId = ospf->routerId;
765 tempV->vertexType = OSPFVERTEXTYPE_ROUTER;
766 tempV->lsa = ospf_lsdb_lookup_lsaList(area->routerLSAList,
771 ospf_lsa_hasMaxAge(ospf, tempV->lsa))
774 ospf_list_delete_all(candidateList);
775 ospf_list_delete_all(area->shortestPathList);
778 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"Examine LSA of type %s, Id %s, seq num %u",
779 strLSTYPE[tempV->lsa->LSType],
780 tempV->lsa->LinkStateID->str_ip,
781 tempV->lsa->LSSequenceNumber - OSPF_INITIAL_SEQUENCE_NUMBER);
783 tempV->nextHopList = ospf_list_init(NULL, NULL);
786 ospf_list_add_mem(area->shortestPathList, tempV);
789 ospf_spf_updateCandidateList(ospf, area, candidateList, tempV);
791 ospf_spf_printCandidateList(ospf, candidateList);
794 while (!ospf_list_is_empty(candidateList))
798 tempV = ospf_spf_updateShortestPathList(ospf, area, candidateList);
800 ospf_spf_printShortestpath(ospf, area);
803 ospf_spf_updateCandidateList(ospf, area, candidateList, tempV);
805 ospf_spf_printCandidateList(ospf, candidateList);
809 ospf_spf_addStubRouteToshortestPath(ospf, area);
811 ospf_spf_printShortestpath(ospf, area);
813 ospf_list_delete_all(area->shortestPathList);
814 ospf_list_delete_all(candidateList);
817static void ospf_spf_findInterAreaPath(ptrOSPF_PDS ospf)
821 fnNetSimError(
"Implement %s after area implementation -- 22645", __FUNCTION__);
822#pragma message("Implement %s after area implementation -- 22645")
825static void ospf_spf_findShortestPath(ptrOSPF_PDS ospf)
827 ospf_spf_invalidateRoutingTable(ospf);
830 for (i = 0; i < ospf->areaCount; i++)
832 ptrOSPFAREA_DS area = ospf->areaDS[i];
833 ospf_spf_findShrotestPathForThisArea(ospf, area);
837 if (ospf->isPartitionedIntoArea)
838 ospf_spf_findInterAreaPath(ospf);
841 if (ospf->isPartitionedIntoArea == TRUE &&
842 ospf->routerType == OSPFRTYPE_ABR)
843 ospf_area_handleABRTask(ospf);
845 ospf_rtTable_freeAllInvalidRoute(ospf);
848 ospf_rtTable_updateIPTable(ospf);
851void ospf_spf_handleCalculateSPFEvent()
853 ptrOSPF_PDS ospf = OSPF_PDS_CURRENT();
854 ospf->SPFTimer = OSPF_CURR_TIME();
855 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"Calculating shortest path for router %d at time %0.3lf",
856 ospf->myId, ospf->SPFTimer / MILLISECOND);
857 ospf_spf_findShortestPath(ospf);
858#pragma message(__LOC__"Uncomment after bug correction of link failure.")
859 iptable_delete_by_type(IP_WRAPPER_GET(ospf->myId),
"OSPF");
860 ptrOSPF_COST_LIST ospf_cost_list = NULL;
861 ospf_cost_list = fn_NetSim_App_Routing_Init(ospf->myId, ospf_cost_list);
862 ospf_Table_updateIPTable_Dijkstra(ospf,ospf_cost_list);
864 ptrOSPF_PATH temp_ospf_path = ospf_cost_list->path;
865 ptrOSPF_PATH prev_temp_ospf_path;
866 while (temp_ospf_path)
868 prev_temp_ospf_path = temp_ospf_path;
869 prev_temp_ospf_path->next = NULL;
870 temp_ospf_path = temp_ospf_path->next;
871 free(prev_temp_ospf_path);
873 ospf_cost_list->path = NULL;
875 while (ospf_cost_list) {
876 ptrOSPF_COST_LIST temp = ospf_cost_list;
877 ospf_cost_list = ospf_cost_list->next;
881 print_ospf_Dlog(form_dlogId(
"OSPFSPF", ospf->myId),
"");