NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
OSPF_Neighbor.c
1/************************************************************************************
2* Copyright (C) 2023 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "OSPF.h"
16#include "OSPF_Msg.h"
17#include "OSPF_Neighbor.h"
18#include "OSPF_Enum.h"
19#include "OSPF_Interface.h"
20#include "OSPF_List.h"
21
22#define is_neighbor_DR(ospf,neigh) (!OSPFID_COMPARE(ospf->designaterRouter,neigh->neighborId))
23#define is_neighbor_backupDR(ospf, neigh) (!OSPFID_COMPARE(ospf->backupDesignaterRouter,neigh->neighborId))
24
25static void ospf_neighbor_attempt_adjacency(ptrOSPF_NEIGHBOR neigh)
26{
27 if (neigh->DDSeqNo)
28 {
29 neigh->DDSeqNo++;
30 print_ospf_log(OSPF_LOG, "New DD seq no is %d", neigh->DDSeqNo);
31 }
32 else
33 {
34 print_ospf_log(OSPF_LOG, "First time adjacency is attempted. Declaring itself as master.");
35 neigh->isMaster = true;
36 neigh->DDSeqNo = (UINT)(pstruEventDetails->dEventTime / MILLISECOND);
37 print_ospf_log(OSPF_LOG, "New DD seq no is %d", neigh->DDSeqNo);
38 print_ospf_log(OSPF_LOG, "Start sending DD msg");
39 start_sending_dd_msg();
40 }
41}
42
43static void ospf_neighbor_change_state(ptrOSPF_NEIGHBOR neigh,
44 OSPFNEIGHSTATE state)
45{
46 OSPFNEIGHSTATE oldState = neigh->state;
47 print_ospf_log(OSPF_LOG, "Neighbor(%s) state changed to %s from %s",
48 neigh->neighborId->str_ip,
49 strNeighborState[state],
50 strNeighborState[neigh->state]);
51 neigh->state = state;
52
53 // Attempt to form adjacency if new state is S_ExStart
54 if ((oldState != state) && (state == OSPFNEIGHSTATE_ExStart))
55 {
56 {
57 ospf_neighbor_attempt_adjacency(neigh);
58 }
59 }
60
61 if ((oldState == OSPFNEIGHSTATE_Full &&
62 neigh->state != OSPFNEIGHSTATE_Full) ||
63 (oldState != OSPFNEIGHSTATE_Full &&
64 neigh->state == OSPFNEIGHSTATE_Full))
65 {
66 ptrOSPF_PDS ospf = OSPF_PDS_CURRENT();
67 ptrOSPF_IF thisInterface = OSPF_IF_CURRENT();
68 ptrOSPFAREA_DS area = OSPF_AREA_GET_IN(ospf, pstruEventDetails->nInterfaceId);
69 ospf_lsa_schedule_routerLSA(ospf, area, false);
70 if (thisInterface->State == OSPFIFSTATE_DR)
71 {
72 ospf_lsa_scheduleNWLSA(ospf,
73 thisInterface,
74 area,
75 false);
76 }
77 }
78
79 if ((oldState < OSPFNEIGHSTATE_2Way &&
80 state >= OSPFNEIGHSTATE_2Way) ||
81 (oldState >= OSPFNEIGHSTATE_2Way &&
82 state < OSPFNEIGHSTATE_2Way))
83 {
84 ospf_event_add(pstruEventDetails->dEventTime,
85 pstruEventDetails->nDeviceId,
86 pstruEventDetails->nInterfaceId,
87 OSPF_NEIGHBORCHANGE,
88 NULL,
89 neigh);
90 }
91}
92
93ptrOSPF_NEIGHBOR OSPF_NEIGHBOR_FIND(ptrOSPF_IF ospf, OSPFID id)
94{
95 UINT i;
96 for (i = 0; i < ospf->neighborRouterCount; i++)
97 {
98 ptrOSPF_NEIGHBOR neigh = ospf->neighborRouterList[i];
99 if (!OSPFID_COMPARE(neigh->neighborId, id) ||
100 !OSPFID_COMPARE(neigh->neighborIPAddr,id))
101 return neigh;
102 }
103 return NULL;
104}
105
106ptrOSPF_NEIGHBOR OSPF_NEIGHBOR_FIND_BY_IP(ptrOSPF_IF thisInterface, NETSIM_IPAddress ip)
107{
108 UINT i;
109 for (i = 0; i < thisInterface->neighborRouterCount; i++)
110 {
111 ptrOSPF_NEIGHBOR neigh = thisInterface->neighborRouterList[i];
112 if (!IP_COMPARE(neigh->neighborIPAddr, ip))
113 return neigh;
114 }
115 return NULL;
116}
117
118ptrOSPF_NEIGHBOR ospf_neighbor_new(NETSIM_IPAddress ip,
119 OSPFID rid)
120{
121 ptrOSPF_NEIGHBOR neigh;
122 neigh = calloc(1, sizeof* neigh);
123 neigh->devId = fn_NetSim_Stack_GetDeviceId_asIP(rid, &neigh->devInterface);
124 neigh->neighborId = rid;
125 neigh->neighborIPAddr = ip;
126
127 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_DOWN);
128
129 neigh->neighLSReqList = ospf_lsreq_initList();
130 neigh->neighLSRxtList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
131 neigh->neighDBSummaryList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
132 neigh->linkStateSendList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
133
134 return neigh;
135}
136
137void ospf_neighbor_add(ptrOSPF_IF ospf, ptrOSPF_NEIGHBOR neigh)
138{
139 if (ospf->neighborRouterCount)
140 ospf->neighborRouterList = realloc(ospf->neighborRouterList,
141 (ospf->neighborRouterCount + 1) * (sizeof* ospf->neighborRouterList));
142 else
143 ospf->neighborRouterList = calloc(1, sizeof* ospf->neighborRouterList);
144 ospf->neighborRouterList[ospf->neighborRouterCount] = neigh;
145 ospf->neighborRouterCount++;
146}
147
148void ospf_neighbor_remove(ptrOSPF_PDS ospf, ptrOSPF_IF thisInterface, ptrOSPF_NEIGHBOR neigh)
149{
150 ospf;
151 UINT n;
152 bool flag = false;
153 for (n = 0; n < thisInterface->neighborRouterCount; n++)
154 {
155 if (thisInterface->neighborRouterList[n] == neigh)
156 flag = true;
157 if (flag)
158 thisInterface->neighborRouterList[n] = thisInterface->neighborRouterList[n + 1];
159 }
160 if (flag)
161 thisInterface->neighborRouterCount--;
162
163 ospf_list_delete_all(neigh->linkStateSendList);
164 ospf_list_destroy(neigh->linkStateSendList);
165
166 ospf_list_delete_all(neigh->neighDBSummaryList);
167 ospf_list_destroy(neigh->neighDBSummaryList);
168
169 ospf_list_delete_all(neigh->neighLSReqList);
170 ospf_list_destroy(neigh->neighLSReqList);
171
172 ospf_list_delete_all(neigh->neighLSRxtList);
173 ospf_list_destroy(neigh->neighLSRxtList);
174
175 OSPF_HDR_FREE(neigh->lastrecvDDPacket);
176 OSPF_HDR_FREE(neigh->lastSentDDPacket);
177
178 fnDeleteEvent(neigh->inactivityTimerId);
179 neigh->inactivityTimerId = false;
180 free(neigh);
181}
182
183void ospf_neighbor_handle_1way_event()
184{
185 ptrOSPF_NEIGHBOR neigh = pstruEventDetails->szOtherDetails;
186
187 print_ospf_log(OSPF_LOG, "Time %0.4lf, Router %d, Interface %d (%s) 1-way event is triggered for neighbor %s",
188 pstruEventDetails->dEventTime/MILLISECOND,
189 pstruEventDetails->nDeviceId,
190 pstruEventDetails->nInterfaceId,
191 DEVICE_MYIP()->str_ip,
192 neigh->neighborId->str_ip);
193
194 if (neigh->state == OSPFNEIGHSTATE_2Way)
195 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_Init);
196
197 print_ospf_log(OSPF_LOG, "\n");
198}
199
200static bool is_adjacency_should_established(ptrOSPF_IF ospf,
201 ptrOSPF_NEIGHBOR neigh)
202{
203 if (ospf->Type == OSPFIFTYPE_P2P ||
204 ospf->Type == OSPFIFTYPE_P2MP ||
205 ospf->Type == OSPFIFTYPE_VIRTUALLINK)
206 return true;
207
208 if (ospf->State == OSPFIFSTATE_DR)
209 return true;
210
211 if (ospf->State == OSPFIFSTATE_BACKUP)
212 return true;
213
214 if (is_neighbor_DR(ospf, neigh))
215 return true;
216
217 if (is_neighbor_backupDR(ospf, neigh))
218 return true;
219
220 return false;
221}
222
223static void ospf_handle_2wayReceived_event_in_init_state(ptrOSPF_IF ospf,
224 ptrOSPF_NEIGHBOR neigh)
225{
226 print_ospf_log(OSPF_LOG, "Neighbor state is Init");
227
228 bool isAdjacency = is_adjacency_should_established(ospf, neigh);
229 if (isAdjacency)
230 {
231 print_ospf_log(OSPF_LOG, "Adjacency is required");
232 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_ExStart);
233 }
234 else
235 {
236 print_ospf_log(OSPF_LOG, "Adjacency is not required");
237 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_2Way);
238 }
239}
240
241void ospf_neighbor_handle_2wayReceived_event()
242{
243 ptrOSPF_IF ospf = OSPF_IF_CURRENT();
244 ptrOSPF_NEIGHBOR neigh = pstruEventDetails->szOtherDetails;
245
246 print_ospf_log(OSPF_LOG, "Time %0.4lf: Router %d, interface %d (%s) 2-Way received event triggered for neighbor %s",
247 pstruEventDetails->dEventTime / MILLISECOND,
248 pstruEventDetails->nDeviceId,
249 pstruEventDetails->nInterfaceId,
250 DEVICE_MYIP()->str_ip,
251 neigh->neighborId->str_ip);
252
253 if (neigh->state == OSPFNEIGHSTATE_Init)
254 ospf_handle_2wayReceived_event_in_init_state(ospf, neigh);
255 print_ospf_log(OSPF_LOG, "\n");
256}
257
258void ospf_neighbor_handle_helloReceived_event()
259{
260 ptrOSPF_NEIGHBOR neigh = pstruEventDetails->szOtherDetails;
261
262 print_ospf_log(OSPF_LOG, "Time %0.4lf, Router %d, interface %d (%s) HelloReceived event triggered for neighbor %s",
263 pstruEventDetails->dEventTime/MILLISECOND,
264 pstruEventDetails->nDeviceId,
265 pstruEventDetails->nInterfaceId,
266 DEVICE_MYIP()->str_ip,
267 neigh->neighborId->str_ip);
268
269 if (neigh->state == OSPFNEIGHSTATE_DOWN)
270 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_Init);
271
272 neigh->lastHelloRecvTime = OSPF_CURR_TIME();
273 if (!neigh->isInactivityTimerAdded)
274 {
275 ptrOSPF_IF ospf = OSPF_IF_CURRENT();
276
277 double time = pstruEventDetails->dEventTime +
278 ospf->routerDeadInterval*SECOND;
279
280 print_ospf_log(OSPF_LOG, "Adding Inactivity timer at time %0.4lf",
281 time/MILLISECOND);
282
283 neigh->inactivityTimerId = ospf_event_add(time,
284 pstruEventDetails->nDeviceId,
285 pstruEventDetails->nInterfaceId,
286 OSPF_InactivityTimer,
287 NULL,
288 neigh);
289 neigh->isInactivityTimerAdded = true;
290 }
291 print_ospf_log(OSPF_LOG, "\n");
292}
293
294static void ospf_neighbor_addToRxtList(ptrOSPF_PDS ospf,
295 ptrOSPF_IF thisInterface,
296 ptrOSPF_NEIGHBOR neigh,
297 ptrOSPFLSAHDR lsa)
298{
299 lsa = OSPF_LSA_HDR_COPY(lsa);
300
301 lsa->time = OSPF_CURR_TIME();
302 ospf_list_add_mem(neigh->neighLSRxtList, lsa);
303 ospf_lsa_printList(form_dlogId("RXTLIST", ospf->myId), neigh->neighLSRxtList, "add Rxlist");
304 ospf_list_add_mem(neigh->linkStateSendList, OSPF_LSA_HDR_COPY(lsa));
305
306 if (!neigh->LSRxtTimer)
307 {
308 ptrLSRXTTIMERDETAILS detail = calloc(1, sizeof* detail);
309 detail->advertisingRouter = lsa->AdvertisingRouter;
310 detail->msgType = OSPFMSG_LSUPDATE;
311 detail->neighborIP = neigh->neighborIPAddr;
312 detail->rxmtSeqNum = neigh->LSRxtSeqNum;
313 ospf_event_add(OSPF_CURR_TIME() + thisInterface->RxmtInterval*SECOND,
314 ospf->myId,
315 thisInterface->id,
316 OSPF_RXMTTIMER,
317 NULL,
318 detail);
319 neigh->LSRxtTimer = true;
320 }
321}
322
323static void ospf_neighbor_update_DBSummaryList(ptrOSPF_PDS ospf,
324 ptrOSPF_IF thisInterface,
325 ptrOSPF_NEIGHBOR neigh,
326 ptrOSPFLIST list)
327{
328 ptrOSPFLSAHDR lsa = NULL;
329 void* item = ospf_list_newIterator();
330 while ((lsa = ospf_list_iterate_mem(list, item)) != NULL)
331 {
332 // Add to retransmission list if LSAge is MaxAge
333 if (ospf_lsa_maskDoNotAge(ospf, lsa->LSAge) == ospf->LSAMaxAge)
334 {
335 ospf_neighbor_addToRxtList(ospf,
336 thisInterface,
337 neigh,
338 lsa);
339 continue;
340 }
341
342 ptrOSPFLSAHDR cpy = OSPF_LSA_HDR_COPY(lsa);
343 ospf_list_add_mem(neigh->neighDBSummaryList, cpy);
344 }
345 ospf_list_deleteIterator(item);
346}
347
348static void ospf_neighbor_create_DBSummaryList(ptrOSPF_PDS pds,
349 ptrOSPF_IF ospf,
350 ptrOSPF_NEIGHBOR neigh)
351{
352 ptrOSPFAREA_DS area = OSPF_AREA_GET_IN(pds, ospf->id);
353 ospf_neighbor_update_DBSummaryList(pds, ospf, neigh, area->routerLSAList);
354 ospf_neighbor_update_DBSummaryList(pds, ospf, neigh, area->nwLSAList);
355 ospf_neighbor_update_DBSummaryList(pds, ospf, neigh, area->routerSummaryLSAList);
356 ospf_neighbor_update_DBSummaryList(pds, ospf, neigh, area->nwSummaryLSAList);
357}
358
359void ospf_neighbor_handle_negotiationDone_event()
360{
361 ptrOSPF_NEIGHBOR neigh = pstruEventDetails->szOtherDetails;
362 print_ospf_log(OSPF_LOG, "Time %0.4lf, Router %d, Interface %d (%s), %s event is triggered for neighbor %s",
363 pstruEventDetails->dEventTime / MILLISECOND,
364 pstruEventDetails->nDeviceId,
365 pstruEventDetails->nInterfaceId,
366 DEVICE_MYIP()->str_ip,
367 GetStringOSPF_Subevent(pstruEventDetails->nSubEventType),
368 neigh->neighborId->str_ip);
369 print_ospf_log(OSPF_LOG, "Neighbor state is %s",
370 strNeighborState[neigh->state]);
371 if(neigh->state != OSPFNEIGHSTATE_ExStart)
372 return;
373
374 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_Exchange);
375 print_ospf_log(OSPF_LOG, "Creating DB summary list");
376 ospf_neighbor_create_DBSummaryList(OSPF_PDS_CURRENT(),
377 OSPF_IF_CURRENT(),
378 neigh);
379 print_ospf_log(OSPF_LOG, "");
380}
381
382void ospf_neighbor_handle_exchangeDone_event()
383{
384 ptrOSPF_PDS ospf = OSPF_PDS_CURRENT();
385 ptrOSPF_NEIGHBOR neigh = pstruEventDetails->szOtherDetails;
386 print_ospf_log(OSPF_LOG, "Time %0.4lf, Router %d, Interface %d (%s), %s event is triggered for neighbor %s",
387 pstruEventDetails->dEventTime / MILLISECOND,
388 pstruEventDetails->nDeviceId,
389 pstruEventDetails->nInterfaceId,
390 DEVICE_MYIP()->str_ip,
391 GetStringOSPF_Subevent(pstruEventDetails->nSubEventType),
392 neigh->neighborId->str_ip);
393 print_ospf_log(OSPF_LOG, "Neighbor state is %s",
394 strNeighborState[neigh->state]);
395
396 if (neigh->state != OSPFNEIGHSTATE_Exchange)
397 return;
398
399 if (ospf_list_is_empty(neigh->neighLSReqList))
400 {
401 print_ospf_log(OSPF_LOG, "Neighbor LSR list is empty");
402 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_Full);
403 }
404 else
405 {
406 print_ospf_log(OSPF_LOG, "Neighbor LSR is not empty");
407 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_Loading);
408 ospf_lsreq_send(ospf,
409 pstruEventDetails->nInterfaceId,
410 neigh->neighborIPAddr,
411 false);
412 }
413 print_ospf_log(OSPF_LOG, "");
414}
415
416void ospf_neighbor_handle_start_event()
417{
418 //For NBMA network type
419 //Ignore
420}
421
422static void restart_inactivity_timer(ptrOSPF_IF ospf,
423 ptrOSPF_NEIGHBOR neigh)
424{
425 double time = neigh->lastHelloRecvTime +
426 ospf->routerDeadInterval*SECOND;
427
428 print_ospf_log(OSPF_LOG, "Adding Inactivity timer at time %0.4lf",
429 time / MILLISECOND);
430
431 neigh->inactivityTimerId = ospf_event_add(time,
432 pstruEventDetails->nDeviceId,
433 pstruEventDetails->nInterfaceId,
434 OSPF_InactivityTimer,
435 NULL,
436 neigh);
437 neigh->isInactivityTimerAdded = true;
438}
439
440void ospf_neighbor_handle_inactivityTimer_event()
441{
442 ptrOSPF_IF ospf = OSPF_IF_CURRENT();
443 ptrOSPF_NEIGHBOR neigh = pstruEventDetails->szOtherDetails;
444
445 print_ospf_log(OSPF_LOG, "Time %0.4lf, Router %d, Interface %d (%s), "
446 "%s event is triggered for neighbor %s.",
447 pstruEventDetails->dEventTime / MILLISECOND,
448 pstruEventDetails->nDeviceId,
449 pstruEventDetails->nInterfaceId,
450 DEVICE_MYIP()->str_ip,
451 GetStringOSPF_Subevent(pstruEventDetails->nSubEventType),
452 neigh->neighborId->str_ip);
453
454 double lt = neigh->lastHelloRecvTime;
455 if (lt + ospf->routerDeadInterval*SECOND <=
456 pstruEventDetails->dEventTime)
457 {
458 print_ospf_log(OSPF_LOG, "Neighbor is inactive");
459 ospf_neighbor_change_state(neigh, OSPFNEIGHSTATE_DOWN);
460
461 ospf_list_delete_all(neigh->neighLSReqList);
462 ospf_list_destroy(neigh->neighLSReqList);
463 neigh->neighLSReqList = NULL;
464
465 ospf_list_delete_all(neigh->neighDBSummaryList);
466 ospf_list_destroy(neigh->neighDBSummaryList);
467 neigh->neighDBSummaryList = NULL;
468
469 ospf_list_delete_all(neigh->neighLSRxtList);
470 ospf_list_destroy(neigh->neighLSRxtList);
471 neigh->neighLSRxtList = NULL;
472
473 ospf_list_delete_all(neigh->linkStateSendList);
474 ospf_list_destroy(neigh->linkStateSendList);
475 neigh->linkStateSendList = NULL;
476
477 neigh->isInactivityTimerAdded = false;
478
479 OSPF_HDR_FREE(neigh->lastrecvDDPacket);
480 neigh->lastrecvDDPacket = NULL;
481
482 OSPF_HDR_FREE(neigh->lastSentDDPacket);
483 neigh->lastSentDDPacket = NULL;
484
485 neigh->neighborDesignateBackupRouter = NULL;
486 neigh->neighborDesignateRouter = NULL;
487
488 }
489 else
490 {
491 print_ospf_log(OSPF_LOG, "Neighbor is active");
492 restart_inactivity_timer(ospf, neigh); //reduce number of event for faster execution
493 }
494 print_ospf_log(OSPF_LOG, "");
495}
496
497bool ospf_is_router_fullAdjacentWithDR(ptrOSPF_IF ospf)
498{
499 UINT i;
500 for (i = 0; i < ospf->neighborRouterCount; i++)
501 {
502 ptrOSPF_NEIGHBOR neigh = ospf->neighborRouterList[i];
503 if (!OSPFID_COMPARE(neigh->neighborId, ospf->designaterRouter) &&
504 neigh->state == OSPFNEIGHSTATE_Full)
505 return true;
506 }
507 return false;
508}
509
510bool ospf_is_dr_router_fulladjacentwithAnother(ptrOSPF_IF ospf)
511{
512 UINT i;
513 for (i = 0; i < ospf->neighborRouterCount; i++)
514 {
515 ptrOSPF_NEIGHBOR neigh = ospf->neighborRouterList[i];
516 if (neigh->state == OSPFNEIGHSTATE_Full)
517 return true;
518 }
519 return false;
520}
521
522bool ospf_neighbor_isAnyNeighborInExchangeOrLoadingState(ptrOSPF_PDS ospf)
523{
524 UINT i, n;
525 for (i = 0; i < ospf->ifCount; i++)
526 {
527 ptrOSPF_IF thisInterface = ospf->ospfIf[i];
528 ptrOSPF_NEIGHBOR neigh;
529 for (n = 0; n < thisInterface->neighborRouterCount; n++)
530 {
531 neigh = thisInterface->neighborRouterList[n];
532 if (neigh->state == OSPFNEIGHSTATE_Exchange ||
533 neigh->state == OSPFNEIGHSTATE_Loading)
534 return true;
535 }
536 }
537 return false;
538}
539
540ptrOSPFLSAHDR ospf_neighbor_searchSendList(ptrOSPFLIST list,
541 ptrOSPFLSAHDR lsa)
542{
543 ptrOSPFLSAHDR l;
544 void* pass = ospf_list_newIterator();
545 while ((l = ospf_list_iterate_mem(list, pass)) != NULL)
546 {
547 if (l->LSType == lsa->LSType &&
548 !OSPFID_COMPARE(l->AdvertisingRouter, lsa->AdvertisingRouter) &&
549 !OSPFID_COMPARE(l->LinkStateID, lsa->LinkStateID))
550 {
551 ospf_list_deleteIterator(pass);
552 return l;
553 }
554 }
555 ospf_list_deleteIterator(pass);
556 return NULL;
557}
558
559void ospf_neighbor_insertToSendList(ptrOSPFLIST list,
560 ptrOSPFLSAHDR lsa,
561 double time)
562{
563 ptrOSPFLSAHDR s = OSPF_LSA_HDR_COPY(lsa);
564 s->time = time;
565 ospf_list_add_mem(list, s);
566}
567
568NETSIM_ID ospf_neighbor_getInterfaceIdforThisNeighbor(ptrOSPF_PDS ospf,
569 NETSIM_IPAddress neighIPaddr)
570{
571 UINT i;
572 for (i = 0; i < ospf->ifCount; i++)
573 {
574 ptrOSPF_IF thisInterface = ospf->ospfIf[i];
575
576 UINT n;
577 for(n=0;n<thisInterface->neighborRouterCount;n++)
578 {
579 ptrOSPF_NEIGHBOR neigh = thisInterface->neighborRouterList[n];
580 if (!IP_COMPARE(neigh->neighborIPAddr, neighIPaddr))
581 return thisInterface->id;
582 }
583 }
584 return 0;
585}
586
587void ospf_neighbor_handle_LoadingDoneEvent()
588{
589 NETSIM_ID d = pstruEventDetails->nDeviceId;
590 ptrOSPF_NEIGHBOR tempNeighborInfo = pstruEventDetails->szOtherDetails;
591
592 if (tempNeighborInfo->state != OSPFNEIGHSTATE_Loading)
593 return;
594
595 if (tempNeighborInfo->state != OSPFNEIGHSTATE_Full)
596 print_ospf_log(OSPF_LOG, "Router %d, LoadingDone event is triggered"
597 "Neighbor (%s) state move up to Full", d, tempNeighborInfo->neighborId);
598
599 ospf_neighbor_change_state(tempNeighborInfo, OSPFNEIGHSTATE_Full);
600}
601
602void ospf_neighbor_handle_KillNbrEvent()
603{
604 ptrOSPF_PDS ospf = OSPF_PDS_CURRENT();
605 ptrOSPF_IF thisInterface = OSPF_IF_CURRENT();
606 ptrOSPF_NEIGHBOR neighbor = pstruEventDetails->szOtherDetails;
607
608 ospf_neighbor_change_state(neighbor, OSPFNEIGHSTATE_DOWN);
609 ospf_neighbor_remove(ospf, thisInterface, neighbor);
610
611}