NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
RequestTimeOut.c
1/************************************************************************************
2 * Copyright (C) 2023
3 *
4 * TETCOS, Bangalore. India *
5
6 * Tetcos owns the intellectual property rights in the Product and its content. *
7 * The copying, redistribution, reselling or publication of any or all of the *
8 * Product or its content without express prior written consent of Tetcos is *
9 * prohibited. Ownership and / or any other right relating to the software and all *
10 * intellectual property rights therein shall remain at all times with Tetcos. *
11
12 * Author: Basamma YB
13 * Date :
14 ************************************************************************************/
15
16#define _CRT_SECURE_NO_DEPRECATE
17#include "main.h"
18#include "ARP.h"
19/**
20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21Function: ARP Request Timeout
22When we generate Arp Request, we will add the Timeout event with the present
23event time + ARP_RETRY_INTERVAL. At that time this function is called.
24Do the following to generate Request
251. Check the destination entry present in the table and set nDestinationPresentFlag.
262. if nDestinationPresentFlag =0 Check RetryCont<RetryLimit.
273. if true generate ARP request, reset pnArpRequestFlag, increament nArpRequestSentCount.
284. else drop the buffered packets and reset the RetryCount and RequestFlag.
293. if nDestinationPresentFlag set,drop temp packet and reset RetryCount and RequestFlag
30~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31*/
32int fn_NetSim_ARP_Request_Timeout(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK)
33{
34 NETSIM_ID nDeviceId;
35 NETSIM_ID nInterfaceId;
36 NETSIM_ID nDestinationId,i;
37 NETSIM_IPAddress szDestIPadd;
38
39 int nPktDropCount=0;
40 int nDestinationPresentFlag = 0;
41
42 NetSim_PACKET *pstruTemp_Data; // store the packet from the event details
43 ARP_VARIABLES *pstruArpVariables; //type casting Arp variables
44 ARP_BUFFER *pstruPacketBuffer; //type casting Arp buffer
45 ARP_TABLE *pstruTableHead, *pstruCurrentTable; //Type casting ARP table
46
47 pstruTemp_Data = pstruEventDetails->pPacket; //Get the packet from the event
48 nDeviceId = pstruEventDetails->nDeviceId; // Get the deviceID
49 nInterfaceId = pstruEventDetails->nInterfaceId; // Get the interfaceId
50
51
52 //Shashi kant
53 szDestIPadd = IP_COPY(pstruTemp_Data->pstruNetworkData->szNextHopIp);
54 // Get the source and destination IP address from the packet
55 //szSrcIPadd = IP_COPY(pstruTemp_Data->pstruNetworkData->szSourceIP);
56 //szDestIPadd = IP_COPY(pstruTemp_Data->pstruNetworkData->szDestIP);
57 //szNextHopIp = pstruTemp_Data->pstruNetworkData->szNextHopIp;
58 //if(IP_COMPARE(szSrcIPadd,DEVICE_INTERFACE(nDeviceId,nInterfaceId)->szAddress) != 0)
59 //{
60 // szSrcIPadd = IP_COPY(DEVICE_INTERFACE(nDeviceId,nInterfaceId)->szAddress);
61 //}
62 ///*if(szNextHopIp)
63 // szDestIPadd = szNextHopIp;*/
64 //szSubnetMaskAdd = IP_COPY(DEVICE_INTERFACE(nDeviceId,nInterfaceId)->szSubnetMask);
65 //// Call the IPV4 function to check Destination MAC in the same subnet/LAN
66 //nCheckSubnet = IP_IS_IN_SAME_NETWORK(szSrcIPadd,szDestIPadd,szSubnetMaskAdd);
67 //// Get the Arp variables from device ipVar
68 pstruArpVariables = DEVICE_INTERFACE(nDeviceId,nInterfaceId)->ipVar;
69 pstruTableHead = pstruArpVariables->pstruArpTable;
70 // switch(nCheckSubnet)
71 // {
72 // case 1: // Destination in the same LAN
73 // nDestinationId = pstruEventDetails->pPacket->nDestinationId;
74 // //szDestIPadd = _strdup(pstruTemp_Data->pstruNetworkData->szDestIP);
75 // break;
76 // case 2:// Destination in the different LAN
77 // nDestinationId = 0; // for the Default Gateway
78 // szDestIPadd = IP_COPY(DEVICE_INTERFACE(nDeviceId,nInterfaceId)->szDefaultGateWay);
79 // break;
80 // default:
81 // fnNetSimError("Invalid Data From IPV4 in Read ARP Table function");
82 // return 0;
83 // break;
84 // }//switch end
85
86
87
88
89
90 // Check the destination entry in the table
91 pstruCurrentTable = pstruTableHead;
92 while(pstruCurrentTable != 0)
93 {
94 if(IP_COMPARE(pstruCurrentTable->szIPAddress,szDestIPadd)== 0)
95 {
96 nDestinationPresentFlag = 1; //Entry exist in the table
97 break;
98 }
99 else
100 pstruCurrentTable = pstruCurrentTable->pstruNextEntry;
101 }
102 nDestinationId = fn_NetSim_Stack_GetDeviceId_asIP(pstruEventDetails->pPacket->pstruNetworkData->szNextHopIp,&i);
103 if(!nDestinationPresentFlag)
104 {
105
106 // If RetryCont<RetryLimit, generate ARP request, else drop the buffered packets
107 if(pstruArpVariables->pnArpRetryCount[nDestinationId] < pstruArpVariables->nArpRetryLimit)
108 { // Write to Log file
109 printf("\n%s\n","ARP---Reply not received with in the ARP_RETRY_INTERVAL, send request once again");
110 pstruArpVariables->pnArpRequestFlag[nDestinationId] = 0; // Reset the flag
111 pstruEventDetails->nSubEventType = GENERATE_ARP_REQUEST;
112 fnpAddEvent(pstruEventDetails);
113 }
114 else
115 { // Drop the buffered packets
116 char ipstr[_NETSIM_IP_LEN];
117 pstruPacketBuffer = pstruArpVariables->pstruPacketBuffer;
118 IP_TO_STR(pstruPacketBuffer->pstruPacket->pstruNetworkData->szGatewayIP,ipstr);
119 nPktDropCount = 0;
120 fn_NetSim_Arp_Drop_Buffered_Packet(nDeviceId,nInterfaceId,szDestIPadd,&nPktDropCount);
121 pstruPacketBuffer = pstruArpVariables->pstruPacketBuffer;
122 // update the packet count in the buffer
123 pstruArpVariables->pstruArpMetrics->nPacketDropCount+= nPktDropCount;
124 pstruArpVariables->pstruArpMetrics->nPacketsInBuffer-= nPktDropCount;
125 // Reset the RetryCount and RequestFlag
126 pstruArpVariables->pnArpRetryCount[nDestinationId] = 0;
127 pstruArpVariables->pnArpRequestFlag[nDestinationId] = 0;
128
129 // Write to Log file
130 printf("\n%s\n","ARP---Request reached the ARP_RETRY_LIMIT, drop the packet");
131 printf("ARP---Packets Dropped at\tEventTime:%0.3lf\tSrcIP:%s\tDropCount:%d\n",pstruEventDetails->dEventTime,ipstr,nPktDropCount);
132
133 }
134 }
135 else
136 { // Reset the RetryCount and RequestFlag
137 pstruArpVariables->pnArpRetryCount[nDestinationId] = 0;
138 pstruArpVariables->pnArpRequestFlag[nDestinationId] = 0;
139 // free the packet
140 fn_NetSim_Packet_FreePacket(pstruTemp_Data);
141 pstruEventDetails->pPacket = NULL;
142 }
143
144
145 //shashi kant
146 /*IP_FREE(szSubnetMaskAdd);
147 IP_FREE(szSrcIPadd);
148 IP_FREE(szDestIPadd); */
149 return 0;
150}
int * pnArpRequestFlag
Set when generate Request.
Definition ARP.h:153
int * pnArpRetryCount
To keep track of number of retries.
Definition ARP.h:155
int nArpRetryLimit
Store the ARP_RETRY_LIMIT from the config file.
Definition ARP.h:151
ARP_METRICS * pstruArpMetrics
NetSim specific ARP metrics structure.
Definition ARP.h:157
int nPacketsInBuffer
Number of packets in the buffer.
Definition ARP.h:143
struct stru_ARP_Table * pstruNextEntry
Next entry pointer.
Definition ARP.h:127
NETSIM_IPAddress szIPAddress
IP address of the deivce.
Definition ARP.h:124
NetSim_PACKET * pstruPacket
Store the packet.
Definition ARP.h:134