22int fn_NetSim_AODV_GenerateRREP(NetSim_EVENTDETAILS* pstruEventDetails)
25 NetSim_EVENTDETAILS pevent;
26 AODV_RREQ* rreq = (AODV_RREQ*)pstruEventDetails->pPacket->pstruNetworkData->Packet_RoutingProtocol;
27 NetSim_PACKET* packet = fn_NetSim_AODV_GenerateCtrlPacket(pstruEventDetails->nDeviceId,
28 fn_NetSim_Stack_GetDeviceId_asIP(rreq->OriginatorIPAddress,&
id),
29 fn_NetSim_Stack_GetDeviceId_asIP(rreq->LastAddress,&
id),
30 pstruEventDetails->dEventTime,
32 AODV_RREP* rrep = (AODV_RREP*)calloc(1,
sizeof* rrep);
33 packet->pstruNetworkData->Packet_RoutingProtocol = rrep;
34 packet->pstruNetworkData->dPacketSize = AODV_RREP_SIZE(pstruEventDetails->nDeviceId);
35 packet->pstruNetworkData->dOverhead = AODV_RREP_SIZE(pstruEventDetails->nDeviceId);
36 packet->pstruNetworkData->nTTL = rreq->HopCount+2;
37 rrep->DestinationIPaddress = IP_COPY(rreq->DestinationIPAddress);
40 rrep->
Lifetime = (UINT)AODV_MY_ROUTE_TIMEOUT;
44 rrep->LastAddress = aodv_get_curr_ip();
46 memcpy(&pevent,pstruEventDetails,
sizeof pevent);
47 pevent.dPacketSize = AODV_RREP_SIZE(pstruEventDetails->nDeviceId);
48 pevent.nEventType = NETWORK_OUT_EVENT;
49 pevent.nSubEventType = 0;
50 pevent.pPacket = packet;
51 pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp=NULL;
54 AODV_METRICS_VAR(pstruEventDetails->nDeviceId).rrepSent++;
64int fn_NetSim_AODV_ProcessRREP(NetSim_EVENTDETAILS* pstruEventDetails)
66 AODV_RREP* rrep = (AODV_RREP*)pstruEventDetails->pPacket->pstruNetworkData->Packet_RoutingProtocol;
68 if(rrep->DestinationIPaddress == aodv_get_curr_ip())
71 AODV_INSERT_ROUTE_TABLE(rrep->DestinationIPaddress,
75 pstruEventDetails->dEventTime+AODV_ACTIVE_ROUTE_TIMEOUT);
77 AODV_TRANSMIT_FIFO(AODV_DEV_VAR(pstruEventDetails->nDeviceId));
79 AODV_INSERT_PRECURSOR(rrep->LastAddress);
80 sprintf(comment,
"Received RREP as Intermediate");
81 AODV_UPDATE_ROUTE_TABLE(rrep->LastAddress,rrep->
Lifetime);
85 AODV_RREQ_SENT_TABLE* table = AODV_DEV_VAR(pstruEventDetails->nDeviceId)->rreqSentTable;
88 if(!IP_COMPARE(table->
DestAddress,rrep->DestinationIPaddress))
91 LIST_FREE((
void**)&AODV_DEV_VAR(pstruEventDetails->nDeviceId)->rreqSentTable,table);
94 table = (AODV_RREQ_SENT_TABLE*)LIST_NEXT(table);
96 sprintf(comment,
"Received RREP as Source");
98 fn_NetSim_Packet_FreePacket(pstruEventDetails->pPacket);
102 if (pstruEventDetails->pPacket->szPacketType &&
103 _stricmp(pstruEventDetails->pPacket->szPacketType,
"AODV_RREP(HELLO)") == 0)
104 sprintf(comment,
"Received Hello");
106 sprintf(comment,
"Received RREP as Intermediate");
110 AODV_UPDATE_ROUTE_TABLE(rrep->LastAddress, rrep->
Lifetime);
117int fn_NetSim_AODV_ForwardRREP(NetSim_EVENTDETAILS* pstruEventDetails)
119 AODV_RREP* rrep = (AODV_RREP*)pstruEventDetails->pPacket->pstruNetworkData->Packet_RoutingProtocol;
121 !isBroadcastPacket(pstruEventDetails->pPacket))
123 NetSim_EVENTDETAILS pevent;
125 NETSIM_IPAddress nextHop = IP_COPY(AODV_FIND_NEXT_HOP(AODV_DEV_VAR(pstruEventDetails->nDeviceId),rrep->
OriginatorIPaddress));
127 rrep->LastAddress = aodv_get_curr_ip();
128 pstruEventDetails->pPacket->nReceiverId = fn_NetSim_Stack_GetDeviceId_asIP(nextHop,&port);
129 pstruEventDetails->pPacket->nTransmitterId = pstruEventDetails->nDeviceId;
130 pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp = (nextHop);
132 memcpy(&pevent,pstruEventDetails,
sizeof pevent);
133 pevent.nEventType = NETWORK_OUT_EVENT;
134 pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp=NULL;
135 fnpAddEvent(&pevent);
137 if(pevent.pPacket->pstruNetworkData->nTTL>1)
138 AODV_METRICS_VAR(pevent.nDeviceId).rrepForwarded++;
141 fn_NetSim_Packet_FreePacket(pstruEventDetails->pPacket);
148int fn_NetSim_AODV_GenerateRREPByIntermediate(NetSim_EVENTDETAILS* pstruEventDetails)
151 NetSim_EVENTDETAILS pevent;
152 AODV_RREQ* rreq = (AODV_RREQ*)pstruEventDetails->pPacket->pstruNetworkData->Packet_RoutingProtocol;
153 AODV_ROUTETABLE* table = fnFindRouteTable(AODV_DEV_VAR(pstruEventDetails->nDeviceId)->routeTable,rreq->DestinationIPAddress);
154 NetSim_PACKET* packet = fn_NetSim_AODV_GenerateCtrlPacket(pstruEventDetails->nDeviceId,
155 fn_NetSim_Stack_GetDeviceId_asIP(rreq->OriginatorIPAddress,&
id),
156 fn_NetSim_Stack_GetDeviceId_asIP(rreq->LastAddress,&
id),
157 pstruEventDetails->dEventTime,
158 AODVctrlPacket_RREP);
159 AODV_RREP* rrep = (AODV_RREP*)calloc(1,
sizeof* rrep);
161 if(!IP_COMPARE(table->NextHop,rreq->LastAddress))
167 packet->pstruNetworkData->Packet_RoutingProtocol = rrep;
168 packet->pstruNetworkData->dPacketSize = AODV_RREP_SIZE(pstruEventDetails->nDeviceId);
169 packet->pstruNetworkData->dOverhead = AODV_RREP_SIZE(pstruEventDetails->nDeviceId);
170 packet->pstruNetworkData->nTTL = AODV_NET_DIAMETER;
171 rrep->DestinationIPaddress = IP_COPY(rreq->DestinationIPAddress);
173 rreq->DestinationIPAddress);
175 rrep->
Lifetime = (
unsigned int)(table->Lifetime-pstruEventDetails->dEventTime);
179 rrep->LastAddress = aodv_get_curr_ip();
181 memcpy(&pevent,pstruEventDetails,
sizeof pevent);
182 pevent.dPacketSize = AODV_RREP_SIZE(pstruEventDetails->nDeviceId);
183 pevent.nEventType = NETWORK_OUT_EVENT;
184 pevent.nSubEventType = 0;
185 pevent.pPacket = packet;
186 pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp=NULL;
187 fnpAddEvent(&pevent);
189 AODV_METRICS_VAR(pevent.nDeviceId).rrepSent++;
NETSIM_IPAddress DestAddress
Destination IP Address.
NETSIM_IPAddress OriginatorIPaddress
The IP address of the node which originated the RREQ for which the route is supplied.
unsigned int DestinationSequenceNumber
The destination sequence number associated to the route.
unsigned int Lifetime
The time in milliseconds for which nodes receiving the RREP consider the route to be valid.