NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
GeneralPacketProcessing.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
15#include "main.h"
16#include "AODV.h"
17#include "List.h"
18_declspec(dllexport) int fn_NetSim_AODV_PacketDropNotification(NetSim_PACKET* packet);
19/**
20This function is called in the Network Out Event for routing of the packet.
21
22If the Device route table has a route to the target, then the packet is added to sent to the
23next hop ip
24
25Whenever a packet is to be routed to a destination and the device route cache doesnt have
26a route to the target, the Packet is added to the FIFO and a Route Discovery is
27iitiated if not already.
28
29*/
30int fn_NetSim_AODV_GeneralPacketProcessing(NetSim_EVENTDETAILS* pstruEventDetails)
31{
32 NETSIM_IPAddress destIP = pstruEventDetails->pPacket->pstruNetworkData->szDestIP;
33 pstruEventDetails->pPacket->pstruNetworkData->szGatewayIP = IP_COPY(aodv_get_curr_ip());
34 if(AODV_CHECK_ROUTE_FOUND(destIP))
35 {
36 NETSIM_ID port;
37 //Route found
38 NETSIM_IPAddress nextHop = IP_COPY(AODV_FIND_NEXT_HOP(AODV_DEV_VAR(pstruEventDetails->nDeviceId),destIP));
39 pstruEventDetails->pPacket->nTransmitterId = pstruEventDetails->nDeviceId;
40 pstruEventDetails->pPacket->nReceiverId = fn_NetSim_Stack_GetDeviceId_asIP(nextHop,&port);
41 pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp = nextHop;
42 pstruEventDetails->pPacket->pstruNetworkData->nTTL = AODV_NET_DIAMETER;
43 pstruEventDetails->pPacket->DropNotification = fn_NetSim_AODV_PacketDropNotification;
44 sprintf(comment, "Sending Data Packet using an existing route");
45 ///Update the life time
46 AODV_UPDATE_ROUTE_TABLE(destIP,
47 pstruEventDetails->dEventTime+AODV_ACTIVE_ROUTE_TIMEOUT);
48 ///Update the metrics
49 if(pstruEventDetails->nDeviceId == pstruEventDetails->pPacket->nSourceId)
50 AODV_METRICS_VAR(pstruEventDetails->nDeviceId).packetOrginated++;
51 AODV_METRICS_VAR(pstruEventDetails->nDeviceId).packetTransmitted++;
52 }
53 else if(AODV_ADD_TO_FIFO(pstruEventDetails->pPacket,&AODV_DEV_VAR(pstruEventDetails->nDeviceId)->fifo,pstruEventDetails->dEventTime))
54 {
55 ///No route found but RREQ is already sent
56 pstruEventDetails->pPacket = NULL;
57 }
58 else
59 {
60 ///No route found. generate RREQ
61 pstruEventDetails->pPacket = AODV_GEN_RREQ();
62 }
63 return 1;
64}