NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
ARP.h
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 * Author: Basamma YB *
11 * ---------------------------------------------------------------------------------*/
12#ifndef _ARP_H_
13#define _ARP_H_
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include "NetSim_utility.h"
19
20#define DEFAULT_ARP_RETRY_INTERVAL 10 // secs
21#define DEFAULT_ARP_RETRY_LIMIT 3 //Retry count
22
23
24#define HARDWARE_ADDRESS_LENGTH 6 ///< Lenghth of 48 bit MAC address in bytes
25#define ARP_ETHERNET_HEADER_LENGTH 14 ///< Bytes :6(Dest Mac add)+6(src Mac add)+2(frame type).
26#define IPV4_PROTOCOL_ADDREES_LENGTH 4 ///< Length of 32 bit IP address in bytes.
27#define IPV4_ARP_PACKET_SIZE 28 ///< Bytes:2(H/Wtype)+2(ProtocolType)+1(H/Wlength)+1(ProtocolLength)+ 2(opcode)+6(srcMac)+4(srcIP)+6(TargetMac)+4(TargetIP).
28#define IPV4_ARP_PACKET_SIZE_WITH_ETH_HEADER 42 ///< ARP frame size in Bytes: 28 + 14
29#define IPV4_NETWORK_OVERHEADS 20 ///< In bytes for IPV4.
30#define IPV6_PROTOCOL_ADDREES_LENGTH 16 ///< Length of 128 bit IP address in bytes.
31#define IPV6_ARP_PACKET_SIZE 52 ///< bytes:2(H/Wtype)+2(ProtocolType)+1(H/Wlength)+1(ProtocolLength)+ 2(opcode)+6(srcMac)+16(srcIP)+6(TargetMac)+16(TargetIP).
32#define IPV6_ARP_PACKET_SIZE_WITH_ETH_HEADER 66 ///< ARP frame size in Bytes: 52 + 14.
33#define IPV6_NETWORK_OVERHEADS 40 ///< In bytes for IPV6 (320 bits).
34
35
36//Typedef declaration of structure
37typedef struct stru_ARP_Table ARP_TABLE;
38typedef struct stru_Arp_Packet ARP_PACKET;
39typedef struct stru_ARP_Interface_Variables ARP_VARIABLES;
40typedef struct stru_ArpDataPacket_Buffer ARP_BUFFER;
41typedef struct stru_ARP_Metrics ARP_METRICS;
42typedef struct stru_ARP_Static_Table_Configuration STATIC_TABLE_CONFIG;
43//Typedef declaration of enumaration
44typedef enum enum_ARP_Subevent_Type SUB_EVENT;
45typedef enum enum_ARP_opcode OPCODE;
46typedef enum enum_ARP_EthernetFrameType ETHERNET_TYPE;
47typedef enum enum_ARP_HardwareType HARDWARETYPE;
48typedef enum enum_ARP_PrptocolType PROTOCOLTYPE;
49typedef enum enum_ArpControlPacket_Type ARP_CONTROL_PACKET;
50typedef enum enum_Transmission_Type ARP_FRAME_TX_FLAG;
51typedef enum enum_ARP_Table_Entries_Type ENTRY_TYPE;
52typedef enum enum_Static_Arp_Status STATIC_ARP_STATUS;
53
54/** Enumeration for Sub event Type */
55 enum enum_ARP_Subevent_Type
56{
57 READ_ARP_TABLE = NW_PROTOCOL_ARP*100+1,
58 GENERATE_ARP_REQUEST,
59 GENERATE_ARP_REPLY,
60 UPDATE_ARP_TABLE_FWD_PKT,
61 ARP_REQUEST_TIMEOUT,
62 };
63 /** Enumeration for Operation code to specify Packet Type*/
64enum enum_ARP_opcode
65{
66 ares_opSREQUEST=1,
67 ares_opSREPLY,
68};
69/** Enumeration for Ethernet frame type */
70 enum enum_ARP_EthernetFrameType
71 {
72 ADDRESS_RESOLUTION = 0x8060
73 };
74 /** Enumeration for hardware type */
75 enum enum_ARP_HardwareType
76 {
77 ETHERNET = 0x0001,
78 IEEE802 = 0x0006
79 };
80 /** Enumeration for protocol type */
81 enum enum_ARP_PrptocolType
82 {
83 ARP_TO_RESOLVE_IP = 0x8000
84 };
85 /** Enumeration for ARP control packet type */
86 enum enum_ArpControlPacket_Type
87{
88 REQUEST_PACKET = NW_PROTOCOL_ARP*100+1,
89 REPLY_PACKET,
90};
91 /** Enumeration for ARP Table entries type */
92enum enum_ARP_Table_Entries_Type
93{
94 STATIC,
95 DYNAMIC,
96};
97/** Enumeration for static ARP status */
98enum enum_Static_Arp_Status
99{
100 DISABLE,
101 ENABLE
102};
103/// This Arp packet structure is according to RFC 826.
105{ // Ethernet Header
106 PNETSIM_MACADDRESS szDestMac; ///< Destination MAC address.
107 PNETSIM_MACADDRESS szSrcMac; ///< Source MAC address.
108 ETHERNET_TYPE nEther_type; ///<Ethernet Type
109 // ARP Packet DATA
110 HARDWARETYPE n_ar$hrd; ///< Hardware Type 2 bytes.
111 PROTOCOLTYPE n_ar$pro; ///< Protocol Type 2 bytes.
112 unsigned short int usn_ar$hln; ///< H/W address length 1 byte ,specifies the sizes of the H/W address in bytes.
113 unsigned short int usn_ar$pln; ///< Protocol address length 1 byte,specifies the sizes of the protocol address in bytes.
114 OPCODE n_ar$op; ///< Operation REQUEST/REPLY 2 bytes.
115 PNETSIM_MACADDRESS sz_ar$sha; ///< Hardware address of the sender.
116 NETSIM_IPAddress sz_ar$spa; ///< Protocol address of the sender.
117 PNETSIM_MACADDRESS sz_ar$tha; ///< Hardware address of target (if know) otherwise empty 6 bytes.
118 NETSIM_IPAddress sz_ar$tpa; ///< Protocol address of target.
119};
120
121/** Structure for ARP Table */
123{
124 NETSIM_IPAddress szIPAddress; ///< IP address of the deivce
125 PNETSIM_MACADDRESS szMACAddress; ///< MAC address or Hardware address of the device
126 ENTRY_TYPE nType; ///< 0-Static,1-Dynamic.
127 struct stru_ARP_Table *pstruNextEntry; ///< Next entry pointer
128};
129/** Structure to buffer the packet */
131{
132 NETSIM_IPAddress szDestAdd; ///< Store the destination IP address.
133 NETSIM_ID nBufferInterfaceID; ///< Store the InterfaceId while buffering the packet.
134 NetSim_PACKET *pstruPacket; ///< Store the packet
135 struct stru_ArpDataPacket_Buffer *pstruNextBuffer;
136};
137/** Structure to to store the ARP metrics */
139{
140 int nArpRequestSentCount; ///< Number of requests sent from the source
141 int nArpReplyReceivedCount; ///< Number of replies received from destination
142 int nArpReplySentCount; ///< Number of replies sent from the destination
143 int nPacketsInBuffer; ///< Number of packets in the buffer
144 int nPacketDropCount; /// Number of packets droped in the buffer
145};
146/** Structure to to store the ARP variables */
148{
149 int nStaticTableFlag; ///< Check ARP_TABLE intialized by static table or not.
150 ARP_TABLE *pstruArpTable;
151 int nArpRetryLimit; ///< Store the ARP_RETRY_LIMIT from the config file.
152 int nArpRetryInterval; ///< Store the ARP_RETRY_INTERVAL from the config file
153 int *pnArpRequestFlag; ///< Set when generate Request.
154 int *pnArpReplyFlag; ///< Set when receive the Reply.
155 int *pnArpRetryCount; ///< To keep track of number of retries.
156 ARP_BUFFER *pstruPacketBuffer;
157 ARP_METRICS *pstruArpMetrics; ///< NetSim specific ARP metrics structure.
158
159};
160/// Structure for Static ARP Table configuration
162{
163 STATIC_ARP_STATUS nStaticArpFlag;
164 char* pszFilePath; ///< Stores File path
165 char* pszFileName; ///< Stores File Name
166};
167
168NETSIM_IPAddress szBroadcastIPaddress;
169
170/* NetSim specific global variable for configuration and metrics */
171STATIC_TABLE_CONFIG *g_pstruStaticTableConfig;
172// ************ Other Functions in ARP **********************************************************
173/// Function to Read the static table and assign to the ARP_TABLE
174int fn_NetSim_StaticArpTable_Read(char* pszARPstasticTablePath);
175/// Function to add the new entry to the ARP_TABLE(IP add, MAC add and Type)
176int fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(ARP_TABLE** ,NETSIM_IPAddress , PNETSIM_MACADDRESS , int );
177/// Function to Copy the ARP_TABLE from source to destination. Returm destination ARP Table head pointer reference.
178ARP_TABLE* fn_Netsim_CopyArpTable(ARP_TABLE* );
179/// Function to Delete/ deallocate the memory assigned to the ARP_TABLE
180void fn_NetSim_DeleteArpTable(ARP_TABLE** );
181// Function to add the data packet and interface Id to the ARP_BUFFER
182//int fn_NetSim_Add_PacketTo_Buffer(ARP_BUFFER** ,NetSim_PACKET* ,NETSIM_IPAddress , NETSIM_ID );
183// Function to delete/ deallocate data packet from the ARP_BUFFER
184//void fn_NetSim_Arp_Drop_Buffered_Packet(ARP_BUFFER** , NETSIM_IPAddress , int * );
185// Function to check the destination device IP address to generate the ARP REPLY
186int fn_Netsim_ARP_CheckDestinationDevice(NetSim_EVENTDETAILS* ,struct stru_NetSim_Network*);
187int fn_NetSim_Arp_Drop_Buffered_Packet(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId,NETSIM_IPAddress szDestIPadd, int *nPacketDropCount);
188int fn_NetSim_Add_PacketTo_Buffer(NETSIM_ID nDeviceId, NetSim_PACKET* pstruNewPacket,NETSIM_IPAddress szDestIPadd, NETSIM_ID nInterfaceId);
189
190
191
192/****************** NetWorkStack DLL functions declarations *****************************************/
193/// Function for configuring ARP parameters
194_declspec(dllexport) int fn_NetSim_ARP_Configure(void** var);
195int fn_NetSim_ARP_Configure_F(void** var);
196/// Function for Intializing ARP protocol
197_declspec (dllexport) int fn_NetSim_ARP_Init(struct stru_NetSim_Network *NETWORK_Formal,NetSim_EVENTDETAILS *pstruEventDetails_Formal,char *pszAppPath_Formal,char *pszWritePath_Formal,int nVersion_Type,void **fnPointer);
198int fn_NetSim_ARP_Init_F(struct stru_NetSim_Network *,NetSim_EVENTDETAILS *,char *,char *,int ,void **fnPointer);
199/// Function to run ARP protocol
200_declspec (dllexport) int fn_NetSim_ARP_Run();
201/// Function to free the ARP protocol variable and Unload the primitives
202_declspec(dllexport) int fn_NetSim_ARP_Finish();
203int fn_NetSim_ARP_Finish_F();
204/// Return the subevent name with respect to the subevent number for writting event trace
205_declspec (dllexport) char *fn_NetSim_ARP_Trace(int nSubEvent);
206char *fn_NetSim_ARP_Trace_F(int nSubEvent);
207/// Function to free the allocated memory for the ARP packet
208_declspec(dllexport) int fn_NetSim_ARP_FreePacket(NetSim_PACKET*);
209int fn_NetSim_ARP_FreePacket_F(NetSim_PACKET* );
210/// Function to copy the ARP packet from source to destination
211_declspec(dllexport) int fn_NetSim_ARP_CopyPacket(NetSim_PACKET* ,NetSim_PACKET* );
212int fn_NetSim_ARP_CopyPacket_F(NetSim_PACKET* ,NetSim_PACKET* );
213/// Function to write ARP Metrics into Metrics.txt
214_declspec(dllexport) int fn_NetSim_ARP_Metrics(char* );
215int fn_NetSim_ARP_Metrics_F(char* );
216_declspec(dllexport) char* fn_NetSim_ARP_ConfigPacketTrace();
217
218_declspec(dllexport) char* fn_NetSim_ARP_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace);
219
220
221/// Function used to check the destination is in the same subnet or not from IPV4.lib
222int fn_NetSim_ipv4_network_check(char* ,char* ,char* );
223
224int fn_NetSim_Generate_ARP_Request(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK);
225int fn_NetSim_Read_ARP_Table(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK);
226int fn_NetSim_ARP_Request_Timeout(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK);
227int fn_NetSim_Generate_ARP_Reply(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK);
228int fn_NetSim_Update_ARP_Table_ForwardPacket(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK);
229#ifdef __cplusplus
230}
231#endif
232#endif /* _ARP_H_*/
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
int nStaticTableFlag
Check ARP_TABLE intialized by static table or not.
Definition ARP.h:149
ARP_METRICS * pstruArpMetrics
NetSim specific ARP metrics structure.
Definition ARP.h:157
int nArpRetryInterval
Store the ARP_RETRY_INTERVAL from the config file.
Definition ARP.h:152
int * pnArpReplyFlag
Set when receive the Reply.
Definition ARP.h:154
int nArpRequestSentCount
Number of requests sent from the source.
Definition ARP.h:140
int nPacketsInBuffer
Number of packets in the buffer.
Definition ARP.h:143
int nArpReplyReceivedCount
Number of replies received from destination.
Definition ARP.h:141
int nArpReplySentCount
Number of replies sent from the destination.
Definition ARP.h:142
Structure for Static ARP Table configuration.
Definition ARP.h:162
char * pszFilePath
Stores File path.
Definition ARP.h:164
char * pszFileName
Stores File Name.
Definition ARP.h:165
PNETSIM_MACADDRESS szMACAddress
MAC address or Hardware address of the device.
Definition ARP.h:125
ENTRY_TYPE nType
0-Static,1-Dynamic.
Definition ARP.h:126
struct stru_ARP_Table * pstruNextEntry
Next entry pointer.
Definition ARP.h:127
NETSIM_IPAddress szIPAddress
IP address of the deivce.
Definition ARP.h:124
This Arp packet structure is according to RFC 826.
Definition ARP.h:105
PNETSIM_MACADDRESS szDestMac
Destination MAC address.
Definition ARP.h:106
unsigned short int usn_ar$pln
Protocol address length 1 byte,specifies the sizes of the protocol address in bytes.
Definition ARP.h:113
ETHERNET_TYPE nEther_type
Ethernet Type.
Definition ARP.h:108
NETSIM_IPAddress sz_ar$spa
Protocol address of the sender.
Definition ARP.h:116
PNETSIM_MACADDRESS sz_ar$tha
Hardware address of target (if know) otherwise empty 6 bytes.
Definition ARP.h:117
OPCODE n_ar$op
Operation REQUEST/REPLY 2 bytes.
Definition ARP.h:114
unsigned short int usn_ar$hln
H/W address length 1 byte ,specifies the sizes of the H/W address in bytes.
Definition ARP.h:112
HARDWARETYPE n_ar$hrd
Hardware Type 2 bytes.
Definition ARP.h:110
PNETSIM_MACADDRESS sz_ar$sha
Hardware address of the sender.
Definition ARP.h:115
PNETSIM_MACADDRESS szSrcMac
Source MAC address.
Definition ARP.h:107
PROTOCOLTYPE n_ar$pro
Protocol Type 2 bytes.
Definition ARP.h:111
NETSIM_IPAddress sz_ar$tpa
Protocol address of target.
Definition ARP.h:118
NETSIM_IPAddress szDestAdd
Store the destination IP address.
Definition ARP.h:132
NetSim_PACKET * pstruPacket
Store the packet.
Definition ARP.h:134
NETSIM_ID nBufferInterfaceID
Store the InterfaceId while buffering the packet.
Definition ARP.h:133