NetSim Source Code Help
Loading...
Searching...
No Matches
RouteError.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#include "main.h"
15#include "DSR.h"
16#include "List.h"
18/**
19This function gets the previous hop to send the route error to.
20*/
22{
24 DSR_SOURCE_ROUTE_OPTION* srcRouteOption = option->options;
25 unsigned int nlength = (srcRouteOption->nOptDataLen-2)/4;
26 if(!srcRouteOption->Address || nlength == 1 || srcRouteOption->nSegsLeft == nlength)
27 return packet->pstruNetworkData->szSourceIP;
28 return srcRouteOption->Address[srcRouteOption->nSegsLeft];
29}
30/**
31This function generates a route error packet.
32*/
34{
35 unsigned int length;
36 unsigned int loop;
37 NETSIM_ID recv;
39 NetSim_PACKET* packet = maintBuffer->packetList;
42 NETSIM_IPAddress nexthop = fnGetPrevHop(packet);
44 maintBuffer->source,
45 maintBuffer->source,
48 DSR_RERR_OPTION* rerrOption=calloc(1,sizeof* rerrOption);
49 option = calloc(1,sizeof* option);
50 rerrPacket->pstruNetworkData->Packet_RoutingProtocol = option;
53 option->options = rerrOption;
54 rerrOption->nErrorType = NODE_UNREACHABLE;
55 rerrOption->errorSourceAddress = IP_COPY(rerrPacket->pstruNetworkData->szSourceIP);
56 rerrOption->errorDestinationAddress = IP_COPY(rerrPacket->pstruNetworkData->szDestIP);
58 rerrOption->nOptDataLen = DSR_RERR_SIZE_FIXED;
59 rerrOption->nOptionType = optType_RouteError;
60 length = (srcRouteOption->nOptDataLen-2)/4-srcRouteOption->nSegsLeft;
61 rerrOption->length = length;
62 rerrOption->nSegsLeft = length;
63 if (length)
64 {
65 rerrOption->Address = calloc(length, sizeof* rerrOption->Address);
66 for (loop = 0; loop < length; loop++)
67 rerrOption->Address[loop] = IP_COPY(srcRouteOption->Address[length - loop - 1]);
68 }
69
71 rerrPacket->pstruNetworkData->nTTL= length +1;
73 rerrPacket->pstruNetworkData->dPacketSize = rerrPacket->pstruNetworkData->dOverhead;
74 rerrPacket->pstruNetworkData->szNextHopIp = IP_COPY(nexthop);
75 rerrPacket->nReceiverId = fn_NetSim_Stack_GetDeviceId_asIP(nexthop,&recv);
76
77 //Add network out event to transmit packet
78 memcpy(&pevent,pstruEventDetails,sizeof* pstruEventDetails);
79 pevent.nApplicationId = 0;
81 pevent.nPacketId = 0;
83 pevent.nSegmentId = 0;
85 pevent.pPacket = rerrPacket;
86 pevent.dPacketSize = rerrPacket->pstruNetworkData->dPacketSize;
87 pevent.szOtherDetails = NULL;
88 fnpAddEvent(&pevent);
89 //Update the metrics
90 DSR_DEV_VAR(pstruEventDetails->nDeviceId)->dsrMetrics.rerrSent++;
91 return 1;
92}
93/**
94This function process the route error that is received. It deletes the entry of the route to
95the target from the route cache and then forwards the Route error to the previous HOP.
96*/
98{
101 DSR_RERR_OPTION* rerr = (DSR_RERR_OPTION*)option->options;
102
103 //Delete entry from route cache
105 rerr->errorSourceAddress,
106 (NETSIM_IPAddress)rerr->TypeSpecificInformation);
108 return 1;
109}
110/**
111This function frees the route error packet if RERR packet reaches the final destination.
112Otherwise, it forwards the REER packet to the previous HOP.
113*/
115{
116 NETSIM_ID interfaceId;
119 DSR_RERR_OPTION* rerr = option->options;
121 if(rerr->nSegsLeft == 0)
122 {
125 return 0;
126 }
127 rerr->nSegsLeft--;
128
129 if(rerr->nSegsLeft)
130 packet->pstruNetworkData->szNextHopIp = IP_COPY(rerr->Address[rerr->nSegsLeft]);
131 else
135 //Add the network out event
139 //update the metrics
140 DSR_DEV_VAR(pstruEventDetails->nDeviceId)->dsrMetrics.rerrForwarded++;
141 return 1;
142}
143
144
145
146
unsigned int NETSIM_ID
Definition: Animation.h:45
#define DSR_DELETE_ENTRY_CACHE(ppcache, ip1, ip2)
Definition: DSR.h:728
@ subevent_PROCESS_RERR
Definition: DSR.h:81
#define DSR_DEV_VAR(dev)
Definition: DSR.h:772
#define DSR_RERR_SIZE_FIXED
Definition: DSR.h:35
@ ctrlPacket_ROUTE_ERROR
Definition: DSR.h:89
#define DSR_OPTION_HEADER_SIZE
Definition: DSR.h:30
NetSim_PACKET * fn_NetSim_DSR_GenerateCtrlPacket(NETSIM_ID src, NETSIM_ID dest, NETSIM_ID recv, double dTime, DSR_CONTROL_PACKET type)
#define NO_NEXT_HEADER
Definition: DSR.h:45
NETSIM_IPAddress dsr_get_curr_ip()
@ optType_RouteError
Definition: DSR.h:98
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
#define calloc(c, s)
Definition: Memory.h:29
int fn_NetSim_DSR_ProcessRerr(NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RouteError.c:97
NETSIM_IPAddress fnGetPrevHop(NetSim_PACKET *packet)
Definition: RouteError.c:21
int fn_NetSim_DSR_GenerateRERR(DSR_MAINT_BUFFER *maintBuffer, NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RouteError.c:33
int fn_NetSim_DSR_ForwardRERR(NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RouteError.c:114
@ NW_PROTOCOL_DSR
Definition: Stack.h:196
@ NETWORK_OUT_EVENT
Definition: Stack.h:108
@ NETWORK_IN_EVENT
Definition: Stack.h:109
NETSIM_IPAddress fn_NetSim_Stack_GetIPAddressAsId(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
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
NetSim_PACKET * packetList
packetList - list of packets sent to the destination
Definition: DSR.h:630
NETSIM_ID source
Definition: DSR.h:628
NETSIM_ID nextHop
Next hop ID of a route.
Definition: DSR.h:627
unsigned int nPayloadLength
Definition: DSR.h:557
void * options
Definition: DSR.h:565
unsigned int nNextHeader
Definition: DSR.h:536
DSR_OPTION_TYPE optType
Definition: DSR.h:558
DSR_OPTION_TYPE nOptionType
Definition: DSR.h:352
void * TypeSpecificInformation
Definition: DSR.h:424
unsigned int nOptDataLen
Definition: DSR.h:357
unsigned int nSegsLeft
Definition: DSR.h:431
NETSIM_IPAddress errorSourceAddress
Definition: DSR.h:409
NETSIM_IPAddress errorDestinationAddress
Definition: DSR.h:415
unsigned int length
Definition: DSR.h:430
enum stru_NetSim_DSR_RERR_Option::@11 nErrorType
NETSIM_IPAddress * Address
Definition: DSR.h:432
NETSIM_IPAddress * Address
Definition: DSR.h:182
NETSIM_ID nApplicationId
Definition: Stack.h:752
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
long long int nPacketId
Definition: Stack.h:755
NETSIM_IPAddress szDestIP
Definition: Packet.h:199
NETSIM_IPAddress szNextHopIp
Definition: Packet.h:201
NETSIM_IPAddress szSourceIP
Definition: Packet.h:198
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
NETSIM_ID nReceiverId
Definition: Packet.h:266
NETSIM_ID nTransmitterId
Definition: Packet.h:265