NetSim Source Code Help
Loading...
Searching...
No Matches
ARP.h
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020
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
43//Typedef declaration of enumaration
50typedef enum enum_Transmission_Type ARP_FRAME_TX_FLAG;
53
54/** Enumeration for Sub event Type */
56{
62 };
63 /** Enumeration for Operation code to specify Packet Type*/
65{
68};
69/** Enumeration for Ethernet frame type */
71 {
72 ADDRESS_RESOLUTION = 0x8060
73 };
74 /** Enumeration for hardware type */
76 {
77 ETHERNET = 0x0001,
78 IEEE802 = 0x0006
79 };
80 /** Enumeration for protocol type */
82 {
83 ARP_TO_RESOLVE_IP = 0x8000
84 };
85 /** Enumeration for ARP control packet type */
87{
90};
91 /** Enumeration for ARP Table entries type */
93{
96};
97/** Enumeration for static ARP status */
99{
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
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.
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.
157 ARP_METRICS *pstruArpMetrics; ///< NetSim specific ARP metrics structure.
158
159};
160/// Structure for Static ARP Table configuration
162{
164 char* pszFilePath; ///< Stores File path
165 char* pszFileName; ///< Stores File Name
166};
167
169
170/* NetSim specific global variable for configuration and metrics */
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)
177/// Function to Copy the ARP_TABLE from source to destination. Returm destination ARP Table head pointer reference.
179/// Function to Delete/ deallocate the memory assigned to the 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
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);
196/// Function for Intializing ARP protocol
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();
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
210/// Function to copy the ARP packet from source to destination
213/// Function to write ARP Metrics into Metrics.txt
214_declspec(dllexport) int fn_NetSim_ARP_Metrics(char* );
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
229#ifdef __cplusplus
230}
231#endif
232#endif /* _ARP_H_*/
int fn_NetSim_ARP_FreePacket_F(NetSim_PACKET *)
enum_Static_Arp_Status
Definition: ARP.h:99
@ ENABLE
Definition: ARP.h:101
@ DISABLE
Definition: ARP.h:100
int fn_NetSim_ARP_Metrics_F(char *)
ARP_TABLE * fn_Netsim_CopyArpTable(ARP_TABLE *)
Function to Copy the ARP_TABLE from source to destination. Returm destination ARP Table head pointer ...
char * fn_NetSim_ARP_Trace(int nSubEvent)
Return the subevent name with respect to the subevent number for writting event trace.
Definition: Arp.c:120
NETSIM_IPAddress szBroadcastIPaddress
Definition: ARP.h:168
enum enum_Transmission_Type ARP_FRAME_TX_FLAG
Definition: ARP.h:50
int fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(ARP_TABLE **, NETSIM_IPAddress, PNETSIM_MACADDRESS, int)
Function to add the new entry to the ARP_TABLE(IP add, MAC add and Type)
int fn_Netsim_ARP_CheckDestinationDevice(NetSim_EVENTDETAILS *, struct stru_NetSim_Network *)
Definition: Arp.c:176
int fn_NetSim_Generate_ARP_Reply(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK)
int fn_NetSim_Update_ARP_Table_ForwardPacket(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK)
STATIC_TABLE_CONFIG * g_pstruStaticTableConfig
Definition: ARP.h:171
int fn_NetSim_ARP_Run()
Function to run ARP protocol.
Definition: Arp.c:22
int fn_NetSim_ARP_CopyPacket_F(NetSim_PACKET *, NetSim_PACKET *)
int fn_NetSim_ARP_Metrics(char *)
Function to write ARP Metrics into Metrics.txt.
int fn_NetSim_ARP_Init_F(struct stru_NetSim_Network *, NetSim_EVENTDETAILS *, char *, char *, int, void **fnPointer)
enum enum_ARP_PrptocolType PROTOCOLTYPE
Definition: ARP.h:48
char * fn_NetSim_ARP_ConfigPacketTrace()
Definition: Arp.c:157
int fn_NetSim_ARP_Finish()
Function to free the ARP protocol variable and Unload the primitives.
Definition: Arp.c:111
enum enum_ArpControlPacket_Type ARP_CONTROL_PACKET
Definition: ARP.h:49
enum_ARP_EthernetFrameType
Definition: ARP.h:71
@ ADDRESS_RESOLUTION
Definition: ARP.h:72
int fn_NetSim_ARP_Finish_F()
int fn_NetSim_ARP_Configure(void **var)
Function for configuring ARP parameters.
Definition: Arp.c:128
char * fn_NetSim_ARP_WritePacketTrace(NetSim_PACKET *pstruPacket, char **ppszTrace)
Definition: Arp.c:164
enum enum_ARP_HardwareType HARDWARETYPE
Definition: ARP.h:47
int fn_NetSim_ARP_Request_Timeout(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK)
int fn_NetSim_Arp_Drop_Buffered_Packet(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NETSIM_IPAddress szDestIPadd, int *nPacketDropCount)
enum_ARP_HardwareType
Definition: ARP.h:76
@ ETHERNET
Definition: ARP.h:77
@ IEEE802
Definition: ARP.h:78
int fn_NetSim_StaticArpTable_Read(char *pszARPstasticTablePath)
Function to Read the static table and assign to the ARP_TABLE.
enum_ArpControlPacket_Type
Definition: ARP.h:87
@ REPLY_PACKET
Definition: ARP.h:89
@ REQUEST_PACKET
Definition: ARP.h:88
enum enum_ARP_Subevent_Type SUB_EVENT
Definition: ARP.h:44
int fn_NetSim_ARP_FreePacket(NetSim_PACKET *)
Function to free the allocated memory for the ARP packet.
Definition: Arp.c:135
enum enum_Static_Arp_Status STATIC_ARP_STATUS
Definition: ARP.h:52
int fn_NetSim_Add_PacketTo_Buffer(NETSIM_ID nDeviceId, NetSim_PACKET *pstruNewPacket, NETSIM_IPAddress szDestIPadd, NETSIM_ID nInterfaceId)
enum enum_ARP_opcode OPCODE
Definition: ARP.h:45
enum_ARP_Subevent_Type
Definition: ARP.h:56
@ READ_ARP_TABLE
Definition: ARP.h:57
@ GENERATE_ARP_REPLY
Definition: ARP.h:59
@ ARP_REQUEST_TIMEOUT
Definition: ARP.h:61
@ GENERATE_ARP_REQUEST
Definition: ARP.h:58
@ UPDATE_ARP_TABLE_FWD_PKT
Definition: ARP.h:60
int fn_NetSim_ARP_Configure_F(void **var)
int fn_NetSim_ipv4_network_check(char *, char *, char *)
Function used to check the destination is in the same subnet or not from IPV4.lib.
enum_ARP_Table_Entries_Type
Definition: ARP.h:93
@ DYNAMIC
Definition: ARP.h:95
@ STATIC
Definition: ARP.h:94
int fn_NetSim_Generate_ARP_Request(NetSim_EVENTDETAILS *pstruEventDetails, struct stru_NetSim_Network *NETWORK)
char * fn_NetSim_ARP_Trace_F(int nSubEvent)
enum_ARP_opcode
Definition: ARP.h:65
@ ares_opSREQUEST
Definition: ARP.h:66
@ ares_opSREPLY
Definition: ARP.h:67
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)
Function for Intializing ARP protocol.
Definition: Arp.c:99
enum_ARP_PrptocolType
Definition: ARP.h:82
@ ARP_TO_RESOLVE_IP
Definition: ARP.h:83
void fn_NetSim_DeleteArpTable(ARP_TABLE **)
Function to Delete/ deallocate the memory assigned to the ARP_TABLE.
enum enum_ARP_EthernetFrameType ETHERNET_TYPE
Definition: ARP.h:46
enum enum_ARP_Table_Entries_Type ENTRY_TYPE
Definition: ARP.h:51
int fn_NetSim_ARP_CopyPacket(NetSim_PACKET *, NetSim_PACKET *)
Function to copy the ARP packet from source to destination.
Definition: Arp.c:143
unsigned int NETSIM_ID
Definition: Animation.h:45
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
NetSim_EVENTDETAILS * pstruEventDetails_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char * pszAppPath_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char char int nVersion_Type
Definition: RIP.h:178
NetSim_EVENTDETAILS char char * pszWritePath_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char char int void ** fnPointer
Definition: RIP.h:178
int fn_NetSim_Read_ARP_Table()
Definition: ReadArpTable.c:61
@ NW_PROTOCOL_ARP
Definition: Stack.h:191
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
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
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
ARP_TABLE * pstruArpTable
Definition: ARP.h:150
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
int nPacketDropCount
Definition: ARP.h:144
Structure for Static ARP Table configuration.
Definition: ARP.h:162
STATIC_ARP_STATUS nStaticArpFlag
Definition: ARP.h:163
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
struct stru_ArpDataPacket_Buffer * pstruNextBuffer
Definition: ARP.h:135
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