NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
AODV_RouteError.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 "AODV.h"
16#include "List.h"
17/**
18This function Generates a route error and sends it to the previous HOP.
19*/
20int fn_NetSim_AODV_GenerateRERR(NETSIM_ID nDeviceId,
21 NETSIM_IPAddress UnreachableIP,
22 NetSim_EVENTDETAILS* pstruEventDetails)
23{
24 int DestCount=0;
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;
30 while(routeTable)
31 {
32 if(!IP_COMPARE(routeTable->NextHop,UnreachableIP))
33 {
34 routeTable->routingFlags = AODV_RoutingFlag_InValid;
35 routeTable->Lifetime = pstruEventDetails->dEventTime+AODV_DELETE_PERIOD;
36 DestCount++;
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;
41 }
42 routeTable = LIST_NEXT(routeTable);
43 }
44 if(precursorList->count)
45 {
46 int loop;
47 bool flag=false;
48 for(loop=0;loop<precursorList->count;loop++)
49 {
50 if(!IP_COMPARE(precursorList->list[loop],UnreachableIP))
51 {
52 IP_FREE(precursorList->list[loop]);
53 precursorList->count--;
54 flag = true;
55 }
56 if(flag)
57 precursorList->list[loop] = precursorList->list[loop+1];
58 }
59 }
60 if(DestCount)
61 {
62 NetSim_EVENTDETAILS pevent;
63 AODV_RERR* rerr;
64 NetSim_PACKET* packet = fn_NetSim_AODV_GenerateCtrlPacket(nDeviceId,
65 0,0,
66 pstruEventDetails->dEventTime,
67 AODVctrlPacket_RERR);
68 if(DEVICE_NWPROTOCOL(pstruEventDetails->nDeviceId,1) == NW_PROTOCOL_IPV4)
69 {
70 packet->pstruNetworkData->dOverhead = AODV_RERR_SIZE_FIXED+8*DestCount;
71 packet->pstruNetworkData->dPacketSize = AODV_RERR_SIZE_FIXED+8*DestCount;
72 }
73 else
74 {
75 packet->pstruNetworkData->dOverhead = AODV_RERR_SIZE_FIXED+20*DestCount;
76 packet->pstruNetworkData->dPacketSize = AODV_RERR_SIZE_FIXED+20*DestCount;
77 }
78 packet->pstruNetworkData->nTTL = AODV_NET_DIAMETER;
79 rerr = calloc(1,sizeof* rerr);
80 packet->pstruNetworkData->Packet_RoutingProtocol = rerr;
81 rerr->DestCount = DestCount;
82 rerr->Type = 3;
83 rerr->UnreachableDestinationIPAddress = DestinationList;
84 rerr->UnreachableDestinationSequenceNumber = DestinationSequence;
85
86 //Add Network out event to transmit packet
87 memcpy(&pevent,pstruEventDetails,sizeof pevent);
88 pevent.dPacketSize = packet->pstruNetworkData->dPacketSize;
89 pevent.nApplicationId = 0;
90 pevent.nEventType = NETWORK_OUT_EVENT;
91 pevent.nPacketId = 0;
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;
98 fnpAddEvent(&pevent);
99 //update the metrics
100 AODV_METRICS_VAR(pevent.nDeviceId).rerrSent++;
101 AODV_METRICS_VAR(pevent.nDeviceId).routeBreak++;
102 }
103 return 1;
104}
105/**
106This function Processess a route error. It deletes the entry to the target in the Route Table
107and forwards the REER packet to previous HOP if any.
108*/
109int fn_NetSim_AODV_ProcessRERR(NetSim_EVENTDETAILS* pstruEventDetails)
110{
111 bool flag = false;
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;
115 while(routeTable)
116 {
117 unsigned int loop;
118 for(loop=0;loop<rerr->DestCount;loop++)
119 {
120 if(!IP_COMPARE(rerr->UnreachableDestinationIPAddress[loop],routeTable->DestinationIPAddress) &&
121 !IP_COMPARE(nextHop,routeTable->NextHop))
122 {
123 flag = true; //Forward the rerr packet
124 routeTable->routingFlags = AODV_RoutingFlag_InValid;
125 routeTable->Lifetime = pstruEventDetails->dEventTime + AODV_DELETE_PERIOD;
126 break;
127 }
128
129 }
130 routeTable = LIST_NEXT(routeTable);
131 }
132 if(flag)
133 {
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++;
139 }
140 return 1;
141}
unsigned int * UnreachableDestinationSequenceNumber
Definition AODV.h:249
unsigned int DestCount
Definition AODV.h:239
NETSIM_IPAddress * UnreachableDestinationIPAddress
Definition AODV.h:244