NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
PacketProcessing.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 "DSR.h"
16#include "List.h"
17/**
18This function is called in the Network Out Event for routing of the packet.<br/>
19
20Whenever a packet is to be routed to a destination and the device route cache doesnt have
21a route to the target, the Packet is added to the Send buffer and a Route Discovery is
22iitiated.<br/>
23
24If the Device route cache has a route to the target, then the packet is added to the Maintanence
25Buffer and the count of packets originated is incremented.
26
27*/
28int fn_NetSim_DSR_GeneralPacketProcessing(NetSim_EVENTDETAILS* pstruEventDetails)
29{
30 NETSIM_IPAddress nextHop;
31 NETSIM_ID nInterface;
32 DSR_ROUTE_CACHE* cache=NULL;
33 DSR_DEVICE_VAR* pstruDevVar = DSR_DEV_VAR(pstruEventDetails->nDeviceId);
34 pstruEventDetails->pPacket->pstruNetworkData->szGatewayIP = IP_COPY(dsr_get_curr_ip());
35 if(DSR_CHECK_ROUTE_FOUND(pstruEventDetails->pPacket->pstruNetworkData->szDestIP,
36 pstruDevVar,&nextHop,pstruEventDetails->dEventTime,&cache))
37 {
38 //Route found
39 DSR_ADD_SRC_ROUTE(pstruEventDetails->pPacket,cache);
40 DSR_ADD_ACK_REQUEST(pstruEventDetails->pPacket);
41 IP_FREE(pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp);
42 pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp = IP_COPY(nextHop);
43 pstruEventDetails->pPacket->pstruNetworkData->szGatewayIP = IP_COPY(dsr_get_curr_ip());
44 pstruEventDetails->pPacket->nTransmitterId = pstruEventDetails->nDeviceId;
45 pstruEventDetails->pPacket->nReceiverId = fn_NetSim_Stack_GetDeviceId_asIP(nextHop,&nInterface);
46 DSR_ADD_TO_MAINT_BUFFER(pstruEventDetails->nDeviceId,pstruEventDetails->pPacket,pstruEventDetails->dEventTime);
47 DSR_DEV_VAR(pstruEventDetails->nDeviceId)->dsrMetrics.packetTransmitted++;
48 if(pstruEventDetails->pPacket->nSourceId == pstruEventDetails->nDeviceId)
49 DSR_DEV_VAR(pstruEventDetails->nDeviceId)->dsrMetrics.packetOrginated++;
50 if(DSR_DEV_VAR(pstruEventDetails->nDeviceId)->AckType == LINK_LAYER_ACK)
51 pstruEventDetails->pPacket->ReceiveAckNotification = fn_NetSim_DSR_LinkLayerAck;
52 }
53 else
54 {
55 //Add packet to send buffer
56 if(DSR_ADD_TO_SEND_BUFFER(&pstruDevVar->pstruSendBuffer,
57 pstruEventDetails->pPacket,
58 pstruEventDetails->dEventTime))
59 {
60 //Initiate Route discovery process
61 NetSim_PACKET* packet = DSR_INIT_RREQ(pstruEventDetails->pPacket->pstruNetworkData->szDestIP,
62 &pstruDevVar->pstruRREQTable,
63 pstruEventDetails->nDeviceId,
64 pstruEventDetails->dEventTime);
65 pstruEventDetails->pPacket = packet;
66 pstruEventDetails->dPacketSize = packet->pstruNetworkData->dPacketSize;
67 pstruEventDetails->nApplicationId = 0;
68 pstruEventDetails->nPacketId = 0;
69 }
70 else
71 {
72 //RREQ already sent
73 pstruEventDetails->pPacket = NULL;//Don't transmit the packet
74 }
75 }
76 return 1;
77}
struct stru_DSR_SendBuffer * pstruSendBuffer
Buffer in which packets are added if route to target is not known.
Definition DSR.h:658
struct stru_DSR_RouteRequestTable * pstruRREQTable
A table in which entry of RREQ initiated is made.
Definition DSR.h:659