23static FILE* AODV_log_fp = NULL;
25int fn_NetSim_AODV_InsertInRouteTable(NETSIM_IPAddress ip,
26 unsigned int seqNumber,
27 unsigned int hopCount,
28 NETSIM_IPAddress nextHop,
30 NetSim_EVENTDETAILS* pstruEventDetails)
32 AODV_DEVICE_VAR* devVar = AODV_DEV_VAR(pstruEventDetails->nDeviceId);
33 AODV_ROUTETABLE* table = devVar->routeTable;
34 double AODV_log_lifetime = 0;
38 if(!IP_COMPARE(table->DestinationIPAddress,ip)
41 if(table->ValidDestinationSequenceNumberflag ==
false)
43 if(table->DestinationSequenceNumber < seqNumber)
45 if(table->DestinationSequenceNumber > seqNumber)
47 if(hopCount+1<table->HopCount || table->routingFlags==AODV_RoutingFlag_InValid)
52 table = LIST_NEXT(table);
56 NetSim_EVENTDETAILS pevent;
58 table = ROUTETABLE_ALLOC();
59 table->Lifetime = pstruEventDetails->dEventTime+AODV_ACTIVE_ROUTE_TIMEOUT;
60 LIST_ADD_LAST(&AODV_DEV_VAR(pstruEventDetails->nDeviceId)->routeTable,table);
62 pevent.dEventTime = pstruEventDetails->dEventTime+AODV_ACTIVE_ROUTE_TIMEOUT;
63 pevent.dPacketSize = 0;
64 pevent.nApplicationId = 0;
65 pevent.nDeviceId = pstruEventDetails->nDeviceId;
66 pevent.nDeviceType = pstruEventDetails->nDeviceType;
67 pevent.nEventType = TIMER_EVENT;
68 pevent.nInterfaceId = pstruEventDetails->nInterfaceId;
70 pevent.nPrevEventId = pstruEventDetails->nPrevEventId;
71 pevent.nProtocolId = NW_PROTOCOL_AODV;
72 pevent.nSegmentId = 0;
73 pevent.nSubEventType = AODVsubevent_ACTIVE_ROUTE_TIMEOUT;
74 pevent.pPacket = NULL;
75 pevent.szOtherDetails = IP_COPY(ip);
79 if(!table->DestinationIPAddress)
80 table->DestinationIPAddress = IP_COPY(ip);
81 table->DestinationSequenceNumber = seqNumber;
82 table->HopCount= hopCount;
83 AODV_log_lifetime = table->Lifetime;
84 table->Lifetime = max(table->Lifetime,lifeTime);
85 table->ListofPrecursors = devVar->precursorsList;
86 table->NetworkInterface = 1;
88 IP_FREE(table->NextHop);
89 table->NextHop = IP_COPY(nextHop);
90 table->routingFlags = AODV_RoutingFlag_Valid;
91 if(table->DestinationSequenceNumber)
92 table->ValidDestinationSequenceNumberflag =
true;
95 fn_NetSim_AODV_Route_Table_Log_Update(pstruEventDetails->nDeviceId,
"New Entry");
97 if (AODV_log_lifetime < lifeTime)
98 fn_NetSim_AODV_Route_Table_Log_Update(pstruEventDetails->nDeviceId,
"Lifetime extended");
104int fn_NetSim_AODV_InsertInPrecursorsList(NETSIM_IPAddress ip,NetSim_EVENTDETAILS* pstruEventDetails)
107 AODV_PRECURSORS_LIST* precursorsList = AODV_DEV_VAR(pstruEventDetails->nDeviceId)->precursorsList;
110 precursorsList = calloc(1,
sizeof* precursorsList);
111 AODV_DEV_VAR(pstruEventDetails->nDeviceId)->precursorsList = precursorsList;
113 for(loop=0;loop<precursorsList->count;loop++)
115 if(!IP_COMPARE(precursorsList->list[loop],ip))
118 if(!precursorsList->count)
119 precursorsList->list = calloc(1,
sizeof* precursorsList->list);
121 precursorsList->list = realloc(precursorsList->list,(precursorsList->count+1)*(
sizeof* precursorsList->list));
122 precursorsList->list[precursorsList->count] = IP_COPY(ip);
123 precursorsList->count++;
129NETSIM_IPAddress fn_NetSim_AODV_FindNextHop(AODV_DEVICE_VAR* devVar,
130 NETSIM_IPAddress dest,
131 NetSim_EVENTDETAILS* pstruEventDetails)
133 AODV_ROUTETABLE* table=devVar->routeTable;
136 if(!IP_COMPARE(table->DestinationIPAddress,dest) &&
137 table->routingFlags == AODV_RoutingFlag_Valid)
138 return table->NextHop;
139 table = LIST_NEXT(table);
146AODV_ROUTETABLE* fnFindRouteTable(AODV_ROUTETABLE* table,NETSIM_IPAddress dest)
150 if(!IP_COMPARE(table->DestinationIPAddress,dest))
154 table = LIST_NEXT(table);
161int fn_NetSim_AODV_UpdateRouteTable(NETSIM_IPAddress ip,
163 NetSim_EVENTDETAILS* pstruEventDetails)
166 double AODV_log_lifetime = 0;
168 AODV_ROUTETABLE* table = AODV_DEV_VAR(pstruEventDetails->nDeviceId)->routeTable;
171 if(!IP_COMPARE(table->NextHop,ip) || !IP_COMPARE(table->DestinationIPAddress,ip))
174 AODV_log_lifetime = table->Lifetime;
176 table->Lifetime = max(table->Lifetime,lifetime);
178 table=LIST_NEXT(table);
181 if (AODV_log_lifetime < lifetime)
182 fn_NetSim_AODV_Route_Table_Log_Update(pstruEventDetails->nDeviceId,
"Lifetime Extended");
188int fn_NetSim_AODV_ActiveRouteTimeout(NetSim_EVENTDETAILS* pstruEventDetails)
191 NETSIM_IPAddress dest = (NETSIM_IPAddress)pstruEventDetails->szOtherDetails;
192 AODV_ROUTETABLE* table = AODV_DEV_VAR(pstruEventDetails->nDeviceId)->routeTable;
195 if(!IP_COMPARE(table->DestinationIPAddress,dest))
197 if(table->Lifetime <= pstruEventDetails->dEventTime)
199 AODV_ROUTETABLE* temp = LIST_NEXT(table);
200 IP_FREE(table->DestinationIPAddress);
201 IP_FREE(table->NextHop);
202 LIST_FREE(&AODV_DEV_VAR(pstruEventDetails->nDeviceId)->routeTable,table);
209 pstruEventDetails->dEventTime = table->Lifetime;
210 pstruEventDetails->szOtherDetails = dest;
211 fnpAddEvent(pstruEventDetails);
215 table=(AODV_ROUTETABLE*)LIST_NEXT(table);
220 sprintf(comment,
"AODV active route timed out");
221 fn_NetSim_AODV_Route_Table_Log_Update(pstruEventDetails->nDeviceId,
"Entry Deleted");
227int fn_NetSim_AODV_Route_Table_Log_Init()
229 if (!AODV_LOG_ENABLED())
232 char AODV_Log_filename[BUFSIZ];
234 sprintf(AODV_Log_filename,
"%s\\AODV_Route_Table_log.csv", pszIOLogPath);
236 AODV_log_fp = fopen(AODV_Log_filename,
"w");
239 fnSystemError(
"Unable to open %s file", AODV_Log_filename);
240 perror(AODV_Log_filename);
244 fprintf(AODV_log_fp,
"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
"Time(MicroSeconds)",
"Device Name",
"DestinationIPAddress",
245 "DestinationSequenceNumber",
"NetworkInterface",
"HopCount",
"NextHop",
246 "Lifetime(Microseconds)",
"Event",
"Comments");
248 fprintf(AODV_log_fp,
"\n");
249 if (nDbgFlag) fflush(AODV_log_fp);
253int fn_NetSim_AODV_Route_Table_Log_Update(NETSIM_ID devid,
char* msg)
256 if (!AODV_LOG_ENABLED())
261 AODV_ROUTETABLE* table = AODV_DEV_VAR(devid)->routeTable;
264 (table->DestinationIPAddress)->str_ip;
265 fprintf(AODV_log_fp,
"%lf,%s,%s, %d,%d,%d,%s,%f,%s,%s", pstruEventDetails->dEventTime,
266 DEVICE_NAME(devid), (table->DestinationIPAddress)->str_ip,
267 table->DestinationSequenceNumber, table->NetworkInterface, table->HopCount,
268 (table->NextHop)->str_ip, table->Lifetime, msg, comment);
270 fprintf(AODV_log_fp,
"\n");
271 if (nDbgFlag) fflush(AODV_log_fp);
273 table = (AODV_ROUTETABLE*)LIST_NEXT(table);
280void fn_NetSim_AODV_Route_Table_Log_Finish()