20int fn_NetSim_AODV_GenerateRERR(NETSIM_ID nDeviceId,
21 NETSIM_IPAddress UnreachableIP,
22 NetSim_EVENTDETAILS* pstruEventDetails)
25 NETSIM_IPAddress* DestinationList=NULL;
26 unsigned int* DestinationSequence=NULL;
27 AODV_DEVICE_VAR* pstruDeviceVar = AODV_DEV_VAR(nDeviceId);
28 AODV_ROUTETABLE* routeTable = pstruDeviceVar->routeTable;
29 AODV_PRECURSORS_LIST* precursorList = pstruDeviceVar->precursorsList;
32 if(!IP_COMPARE(routeTable->NextHop,UnreachableIP))
34 routeTable->routingFlags = AODV_RoutingFlag_InValid;
35 routeTable->Lifetime = pstruEventDetails->dEventTime+AODV_DELETE_PERIOD;
37 DestinationList = realloc(DestinationList,DestCount*(
sizeof* DestinationList));
38 DestinationSequence = realloc(DestinationSequence,DestCount*(
sizeof* DestinationSequence));
39 DestinationList[DestCount-1] = IP_COPY(routeTable->DestinationIPAddress);
40 DestinationSequence[DestCount-1] = routeTable->DestinationSequenceNumber;
42 routeTable = LIST_NEXT(routeTable);
44 if(precursorList->count)
48 for(loop=0;loop<precursorList->count;loop++)
50 if(!IP_COMPARE(precursorList->list[loop],UnreachableIP))
52 IP_FREE(precursorList->list[loop]);
53 precursorList->count--;
57 precursorList->list[loop] = precursorList->list[loop+1];
62 NetSim_EVENTDETAILS pevent;
64 NetSim_PACKET* packet = fn_NetSim_AODV_GenerateCtrlPacket(nDeviceId,
66 pstruEventDetails->dEventTime,
68 if(DEVICE_NWPROTOCOL(pstruEventDetails->nDeviceId,1) == NW_PROTOCOL_IPV4)
70 packet->pstruNetworkData->dOverhead = AODV_RERR_SIZE_FIXED+8*DestCount;
71 packet->pstruNetworkData->dPacketSize = AODV_RERR_SIZE_FIXED+8*DestCount;
75 packet->pstruNetworkData->dOverhead = AODV_RERR_SIZE_FIXED+20*DestCount;
76 packet->pstruNetworkData->dPacketSize = AODV_RERR_SIZE_FIXED+20*DestCount;
78 packet->pstruNetworkData->nTTL = AODV_NET_DIAMETER;
79 rerr = calloc(1,
sizeof* rerr);
80 packet->pstruNetworkData->Packet_RoutingProtocol = rerr;
87 memcpy(&pevent,pstruEventDetails,
sizeof pevent);
88 pevent.dPacketSize = packet->pstruNetworkData->dPacketSize;
89 pevent.nApplicationId = 0;
90 pevent.nEventType = NETWORK_OUT_EVENT;
92 pevent.nProtocolId = NW_PROTOCOL_AODV;
93 pevent.nSegmentId = 0;
94 pevent.nSubEventType = 0;
95 pevent.pPacket = packet;
96 pevent.szOtherDetails = NULL;
97 pevent.pPacket->pstruNetworkData->szNextHopIp=NULL;
100 AODV_METRICS_VAR(pevent.nDeviceId).rerrSent++;
101 AODV_METRICS_VAR(pevent.nDeviceId).routeBreak++;
109int fn_NetSim_AODV_ProcessRERR(NetSim_EVENTDETAILS* pstruEventDetails)
112 NETSIM_IPAddress nextHop = pstruEventDetails->pPacket->pstruNetworkData->szSourceIP;
113 AODV_RERR* rerr = (AODV_RERR*)pstruEventDetails->pPacket->pstruNetworkData->Packet_RoutingProtocol;
114 AODV_ROUTETABLE* routeTable = AODV_DEV_VAR(pstruEventDetails->nDeviceId)->routeTable;
121 !IP_COMPARE(nextHop,routeTable->NextHop))
124 routeTable->routingFlags = AODV_RoutingFlag_InValid;
125 routeTable->Lifetime = pstruEventDetails->dEventTime + AODV_DELETE_PERIOD;
130 routeTable = LIST_NEXT(routeTable);
134 IP_FREE(pstruEventDetails->pPacket->pstruNetworkData->szSourceIP);
135 pstruEventDetails->pPacket->pstruNetworkData->szSourceIP = aodv_get_curr_ip();
136 pstruEventDetails->nEventType = NETWORK_OUT_EVENT;
137 fnpAddEvent(pstruEventDetails);
138 AODV_METRICS_VAR(pstruEventDetails->nDeviceId).rerrForwarded++;
unsigned int * UnreachableDestinationSequenceNumber
NETSIM_IPAddress * UnreachableDestinationIPAddress