NetSim Source Code Help
Loading...
Searching...
No Matches
RREP.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
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
15#include "main.h"
16#include "AODV.h"
17#include "List.h"
18
19/**
20This function generates a route reply
21*/
23{
24 NETSIM_ID id;
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;
39 rrep->HopCount = 1;
42 rrep->PrefixSz = 0;
43 rrep->Type = 2;
45 //Add network out event
46 memcpy(&pevent,pstruEventDetails,sizeof pevent);
49 pevent.nSubEventType = 0;
50 pevent.pPacket = packet;
52 fnpAddEvent(&pevent);
53 //Update the metrics
55 return 1;
56}
57/**
58This function processes a route reply.
59It adds the entry of the next hop in Route Table, transmits the packets in FIFO Buffer and
60inserts precursor.
61Deletes the RREQ entry from sent table and forwards the rrep if the device is not
62the source node.
63*/
65{
67 //Update the routing table
69 return 0;
70
73 rrep->HopCount,
74 rrep->LastAddress,
76 //Transmit the buffer
78 //Update the precursor list
82 {
83 //Delete entry from sent table
85 while(table)
86 {
88 {
89 IP_FREE(table->DestAddress);
90 LIST_FREE((void**)&AODV_DEV_VAR(pstruEventDetails->nDeviceId)->rreqSentTable,table);
91 break;
92 }
93 table = (AODV_RREQ_SENT_TABLE*)LIST_NEXT(table);
94 }
95 //Drop the packet
97 }
98 else
99 {
100 //Forward the route reply
102 }
103 return 1;
104}
105/**
106This functiopn is used to forward the RREP packet to the previous hop, else the
107packet is freed.
108*/
110{
113 !isBroadcastPacket(pstruEventDetails->pPacket)/*For hello packet*/)
114 {
115 NetSim_EVENTDETAILS pevent;
116 NETSIM_ID port;
118 rrep->HopCount+=1;
123 //Add network out event to transmit RREP
124 memcpy(&pevent,pstruEventDetails,sizeof pevent);
127 fnpAddEvent(&pevent);
128 //Update the metrics
129 if(pevent.pPacket->pstruNetworkData->nTTL>1)
130 AODV_METRICS_VAR(pevent.nDeviceId).rrepForwarded++;
131 }
132 else
134 return 1;
135}
136/**
137This function generates a RREP by an intermediate node if the intermediate node has
138a route to the target entered in the route table.
139*/
141{
142 NETSIM_ID id;
143 NetSim_EVENTDETAILS pevent;
151 AODV_RREP* rrep = (AODV_RREP*)calloc(1,sizeof* rrep);
152
153 if(!IP_COMPARE(table->NextHop,rreq->LastAddress))
154 {
156 return 0;
157 }
158
166 rrep->HopCount = table->HopCount;
167 rrep->Lifetime = (unsigned int)(table->Lifetime-pstruEventDetails->dEventTime);
169 rrep->PrefixSz = 0;
170 rrep->Type = 2;
172 //Add network out event
173 memcpy(&pevent,pstruEventDetails,sizeof pevent);
176 pevent.nSubEventType = 0;
177 pevent.pPacket = packet;
179 fnpAddEvent(&pevent);
180 //Update the metrics
181 AODV_METRICS_VAR(pevent.nDeviceId).rrepSent++;
182 return 1;
183}
184
#define AODV_ACTIVE_ROUTE_TIMEOUT
Definition: AODV.h:26
unsigned int fnFindSequenceNumber(AODV_DEVICE_VAR *devVar, NETSIM_IPAddress ip)
NetSim_PACKET * fn_NetSim_AODV_GenerateCtrlPacket(NETSIM_ID src, NETSIM_ID dest, NETSIM_ID recv, double dTime, AODV_CONTROL_PACKET type)
#define AODV_FIND_NEXT_HOP(devVar, dest)
Definition: AODV.h:404
@ AODVctrlPacket_RREP
Definition: AODV.h:79
AODV_ROUTETABLE * fnFindRouteTable(AODV_ROUTETABLE *table, NETSIM_IPAddress dest)
Definition: RouteTable.c:132
#define AODV_INSERT_ROUTE_TABLE(ip, seq, hopcount, nexthop, lifeTime)
Definition: AODV.h:397
#define AODV_NET_DIAMETER
Definition: AODV.h:36
#define AODV_UPDATE_ROUTE_TABLE(ip, lifetime)
Definition: AODV.h:407
#define AODV_INSERT_PRECURSOR(ip)
Definition: AODV.h:398
NETSIM_IPAddress aodv_get_curr_ip()
#define AODV_MY_ROUTE_TIMEOUT
Definition: AODV.h:35
#define AODV_TRANSMIT_FIFO(devVar)
Definition: AODV.h:401
#define AODV_METRICS_VAR(devId)
Definition: AODV.h:414
#define AODV_RREP_SIZE(dev)
Definition: AODV.h:56
#define AODV_CHECK_ROUTE_FOUND(destIP)
Definition: AODV.h:392
#define AODV_FORWARD_RREP()
Definition: AODV.h:403
#define AODV_FORWARD_RREQ()
Definition: AODV.h:399
#define AODV_DEV_VAR(devId)
Definition: AODV.h:413
unsigned int NETSIM_ID
Definition: Animation.h:45
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
void IP_FREE(NETSIM_IPAddress ip)
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
#define UINT
Definition: Linux.h:38
#define LIST_NEXT(ls)
Definition: List.h:29
#define LIST_FREE(ls, mem)
Definition: List.h:32
#define calloc(c, s)
Definition: Memory.h:29
bool isBroadcastPacket(NetSim_PACKET *packet)
int fn_NetSim_AODV_GenerateRREP(NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RREP.c:22
int fn_NetSim_AODV_ProcessRREP(NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RREP.c:64
int fn_NetSim_AODV_GenerateRREPByIntermediate(NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RREP.c:140
int fn_NetSim_AODV_ForwardRREP(NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RREP.c:109
@ NETWORK_OUT_EVENT
Definition: Stack.h:108
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
NETSIM_ID fn_NetSim_Stack_GetDeviceId_asIP(NETSIM_IPAddress ip, NETSIM_ID *nInterfaceId)
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
Structure of RREQ sent Table in which entry of RREQ sent is made.
Definition: AODV.h:349
NETSIM_IPAddress DestAddress
Destination IP Address.
Definition: AODV.h:350
unsigned int HopCount
Definition: AODV.h:195
NETSIM_IPAddress OriginatorIPaddress
The IP address of the node which originated the RREQ for which the route is supplied.
Definition: AODV.h:203
unsigned int PrefixSz
Definition: AODV.h:189
unsigned int DestinationSequenceNumber
The destination sequence number associated to the route.
Definition: AODV.h:202
unsigned int Type
Definition: AODV.h:180
unsigned int Lifetime
The time in milliseconds for which nodes receiving the RREP consider the route to be valid.
Definition: AODV.h:204
NETSIM_IPAddress LastAddress
Definition: AODV.h:205
NETSIM_IPAddress DestinationIPaddress
Definition: AODV.h:201
unsigned int HopCount
Definition: AODV.h:134
NETSIM_IPAddress DestinationIPAddress
Definition: AODV.h:143
NETSIM_IPAddress OriginatorIPAddress
Definition: AODV.h:148
NETSIM_IPAddress LastAddress
Definition: AODV.h:154
EVENT_TYPE nEventType
Definition: Stack.h:747
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
NETSIM_IPAddress szNextHopIp
Definition: Packet.h:201
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
NETSIM_ID nReceiverId
Definition: Packet.h:266
NETSIM_ID nTransmitterId
Definition: Packet.h:265