NetSim Source Code Help
Loading...
Searching...
No Matches
RequestTimeOut.c
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020
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*/
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 }
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
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);
142 }
143
144
145 //shashi kant
146 /*IP_FREE(szSubnetMaskAdd);
147 IP_FREE(szSrcIPadd);
148 IP_FREE(szDestIPadd); */
149 return 0;
150}
int fn_NetSim_Arp_Drop_Buffered_Packet(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NETSIM_IPAddress szDestIPadd, int *nPacketDropCount)
@ GENERATE_ARP_REQUEST
Definition: ARP.h:58
unsigned int NETSIM_ID
Definition: Animation.h:45
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
#define _NETSIM_IP_LEN
Definition: IP_Addressing.h:29
#define IP_TO_STR(ip, ipstr)
Definition: IP_Addressing.h:71
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
int fn_NetSim_ARP_Request_Timeout(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK)
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define DEVICE_INTERFACE(DeviceId, InterfaceId)
Definition: Stack.h:780
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
int * pnArpRequestFlag
Set when generate Request.
Definition: ARP.h:153
ARP_BUFFER * pstruPacketBuffer
Definition: ARP.h:156
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
ARP_TABLE * pstruArpTable
Definition: ARP.h:150
int nPacketsInBuffer
Number of packets in the buffer
Definition: ARP.h:143
int nPacketDropCount
Definition: ARP.h:144
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
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
NETSIM_ID nInterfaceId
Definition: Stack.h:751
NETSIM_IPAddress szGatewayIP
Definition: Packet.h:200
NETSIM_IPAddress szNextHopIp
Definition: Packet.h:201
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275