NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Packet.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* *
11* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24#ifndef _NETSIM_PACKET_H_
25#define _NETSIM_PACKET_H_
26#ifdef __cplusplus
27extern "C" {
28#endif
29 /* Enumerator for Suppression model*/
30 enum enum_SuppressionModel
31 {
32 SuppModel_NULL = 0,
33 SuppModel_Deterministics = 1,
34 SuppModel_MarkovChain,
35 };
36 /* Enumeration for Distribution*/
37 enum enum_Distribution
38 {
39 Distribution_NULL = 0,
40 Distribution_Exponential = 1,
41 Distribution_Uniform,
42 Distribution_Triangular,
43 Distribution_Weibull,
44 Distribution_Constant,
45 Distribution_Backlog,
46 Distribution_Normal,
47 Distribution_Gamma,
48 };
49 /* Enumeration for packet type*/
50 enum enum_PacketType
51 {
52 PacketType_NULL = 0,
53 PacketType_Voice = 1,
54 PacketType_CBR,
55 PacketType_Custom,
56 PacketType_DataBase,
57 PacketType_Video,
58 PacketType_FTP,
59 PacketType_HTTP,
60 PacketType_EMAIL,
61 PacketType_Peer_to_Peer,
62 PacketType_Erlang_Call,
63 PacketType_Emulation,
64 PacketType_Sensing,
65 PacketType_BSM,
66 PacketType_COAP,
67 PacketType_Interactive_Gaming,
68 PacketType_Control,
69 PacketType_LAST, //Keep me at last
70 };
71 static const char* strPacketType[] = { "NULL","Voice","CBR","Custom","Database","Video","FTP",
72 "HTTP","E-Mail","Peer-to-Peer","Erlang Call","Emulation","Sensing","Basic Safety Message","COAP","Interactive Gaming","Control_Packet","Unknown" };
73
74 /* Enumeration for Service type*/
75 enum enum_ServiceType
76 {
77 ServiceType_NULL = 0,
78 ServiceType_CBR = 1,
79 ServiceType_VBR = 2,
80 };
81
82 /* Enumeration for packet priority */
83 enum enum_PacketPriority
84 {
85 Priority_Low = 2,
86 Priority_Normal = 4,
87 Priority_Medium = 6,
88 Priority_High = 8,
89 };
90
91 /* Enumeration for QOS class */
92 enum enum_Packet_QOS
93 {
94 QOS_UGS = 1,
95 QOS_rtPS,
96 QOS_ertPS,
97 QOS_nrtPS,
98 QOS_BE,
99
100 //LTE QoS class
101 QOS_GBR = QOS_UGS,
102 QOS_NONGBR = QOS_BE,
103 };
104 /* Enumeration for packet status */
105 enum enum_PacketStatus
106 {
107 PacketStatus_NoError = 0,
108 PacketStatus_Error = 1,
109 PacketStatus_Collided = 2,
110 PacketStatus_Buffer_Dropped = 3,
111 PacketStatus_TTL_Expired = 4,
112 PacketStatus_Dropped = 5,
113 PacketStatus_MAC_Lifetime_Expired = 6,
114 PacketStatus_Dropped_Below_Rx_Sensitivity = 7,
115 PacketStatus_LAST, //Keep me at last
116 };
117 static const char* strPacketStatus[] =
118 { "Successful","Errored","Collided","Buffer_Dropped","IP_TTL_Expired","Dropped","MAC_Lifetime_Expired","Below_Rx_sensitivity","Unknown"};
119 _declspec(dllexport) char* fn_NetSim_Config_GetPacketStatusAsString(PACKET_STATUS nStatus, char* buf);
120
121 /* Enumeration for fragment */
122 enum enum_Segment
123 {
124 Segment_FirstSegment = 10,
125 Segment_ContinuingFragment = 11,
126 Segment_LastFragment = 01,
127 Segment_Unfragment = 00,
128 };
129 /* Enumerator for Buffer status */
130 enum enum_BUFFER
131 {
132 Buffer_Underflow,
133 Buffer_Overflow,
134 };
135
136 typedef enum
137 {
138 IPPROTOCOL_NULL = 0x00,
139 IPPROTOCOL_ICMP = 0x01,
140 IPPROTOCOL_IGMP = 0x02,
141 IPPROTOCOL_TCP = 0x06,
142 IPPROTOCOL_UDP = 0x11,
143 IPPROTOCOL_DSR = 0x30,
144 IPPROTOCOL_OSPF = 0x59,
145 IPPROTOCOL_PIM = 0x67,
146 }IP_PROTOCOL_NUMBER;
147
148 /*Enumeration for traffic type*/
149 typedef enum enum_ApplicationType
150 {
151 TRAFFIC_NULL = 0,
152 TRAFFIC_DATA = 1,
153 TRAFFIC_CBR,
154 TRAFFIC_VOICE,
155 TRAFFIC_VIDEO,
156 TRAFFIC_FTP,
157 TRAFFIC_HTTP,
158 TRAFFIC_DATABASE,
159 TRAFFIC_CUSTOM,
160 TRAFFIC_EMAIL,
161 TRAFFIC_PEER_TO_PEER,
162 TRAFFIC_ERLANG_CALL,
163 TRAFFIC_EMULATION,
164 TRAFFIC_SENSING,
165 TRAFFIC_BSM_APP,
166 TRAFFIC_SENSOR_EMULATION,
167 TRAFFIC_COAP,
168 TRAFFIC_INTERACTIVE_GAMING,
169 }APPLICATION_TYPE;
170
171 /* App layer of packet*/
173 {
174 int nSegmentId;//Unique id of segment
175 NETSIM_ID nApplicationId; //Unique id of application
176 PACKET_FRAGMENT nPacketFragment; //Fragment
177 double dArrivalTime; //Arrival time in application layer
178 double dStartTime; //Start time in application layer
179 double dEndTime; //End time in application layer
180 double dPacketSize; //Packet in app layer
181 double dPayload; //Payload in app layer
182 double dOverhead; //Overhead due to app layer
183 int nAppEndFlag; // 1 for last packet of the application
184 APPLICATION_TYPE nAppType;
185 APPLICATION_LAYER_PROTOCOL nApplicationProtocol; //App layer protocol
186 void* Packet_AppProtocol; //Pointer to app layer protocol overhead
187 };
188 /* Transport layer of packet*/
190 {
191 double dArrivalTime; //Arrival time in transport layer
192 double dStartTime; //Start time from transport layer
193 double dEndTime; //End time from transport layer
194 double dPacketSize; //packet size in transport layer
195 double dPayload; //Payload in transport layer
196 double dOverhead; //Overhead due to transport layer
197 unsigned short int nSourcePort; //Source port
198 unsigned short int nDestinationPort; //Destination port
199 TRANSPORT_LAYER_PROTOCOL nTransportProtocol; //Transport layer protocol id
200 void* Packet_TransportProtocol; //Pointer to transport layer overhead
201 };
202 /* Network layer of packet*/
204 {
205 double dArrivalTime; //Arrival time in network layer
206 double dStartTime; //Start time from network layer
207 double dEndTime; //End time from network layer
208 double dPacketSize; //Packet size in network layer
209 double dPayload;//Payload in network layer
210 double dOverhead; //Overhead due to network layer
211 NETSIM_IPAddress szSourceIP;//IP address of source device
212 NETSIM_IPAddress szDestIP;//IP address of dest device
213 NETSIM_IPAddress szGatewayIP; //IP address of the gate way
214 NETSIM_IPAddress szNextHopIp;//IP address of next hop
215 unsigned int nTTL : 8; //Time to live
216 IP_PROTOCOL_NUMBER IPProtocol;
217 NETWORK_LAYER_PROTOCOL nNetworkProtocol; //Network layer protocol id
218 NETWORK_LAYER_PROTOCOL nRoutingProtocol; //Network layer routing protocol
219 void* Packet_NetworkProtocol; //Pointer to network layer overhead
220 void* Packet_RoutingProtocol; //Pointer to routing layer overhead
221 unsigned int nPacketFlag;
223 };
224 /* Mac layer of packet*/
226 {
227 double dArrivalTime; //Arrival time in Mac layer
228 double dStartTime; //Start time from Mac layer
229 double dEndTime; //End time from Mac layer
230 double dPacketSize; //Packet size in Mac layer
231 double dPayload;//payload in Mac layer
232 double dOverhead; //Overhead dur to Mac layer
233 PNETSIM_MACADDRESS szSourceMac;//MAC address of source device
234 PNETSIM_MACADDRESS szDestMac;//MAC address of dest device
235 PNETSIM_MACADDRESS szNextHopMac;//MAC address of next hop
236 MAC_LAYER_PROTOCOL nMACProtocol; //Mac layer protocol id
237 void* Packet_MACProtocol; //Pointer to Mac layer overhead
238 bool dontFree; // Signal other protocol to don't free mac overhead or change
239 };
240 /* Physical layer of packet*/
242 {
243 double dArrivalTime; //Arrival time in Phy layer
244 double dStartTime; //Start time from Phy layer
245 double dEndTime; //End time from Phy layer
246 double dPacketSize; //Packet size in Phy layer
247 double dPayload;//Payload in phy layer
248 double dOverhead; //Overhead due to Phy layer
249 PACKET_STATUS nPacketErrorFlag;
250 PHYSICAL_LAYER_MEDIUM nPhyMedium; //Phy layer medium
251 void* Packet_PhyData; //Pointer to phy layer overhead
252 };
253
254#define MAXBUF 0x800
255 typedef struct stru_packet_info
256 {
257 unsigned char packet[MAXBUF];
258 unsigned int packet_len;
259 void* addr;
260 int flag;
261 long long int captureTime;
262 long long int reinjectTime;
263 }PACKET_INFO, * PPACKET_INFO;
264
265#define MAX_PACKET_TYPE_LEN 100
266 /* Structure for packet*/
268 {
269 long long int nPacketId; //Unique id of packet
270 PACKET_TYPE nPacketType; //Packet type
271 unsigned int nControlDataType; //Control packet type
272 SERVICE_TYPE nServiceType; //Service type
273 PACKET_PRIORITY nPacketPriority; //Packet priority
274 QUALITY_OF_SERVICE nQOS; //Quality of service
275 double dEventTime; //event time
276 NETSIM_ID nSourceId; //Unique id of source
277 void* destInfo;
278 NETSIM_ID nTransmitterId; //Unique id of transmitter (As per IEEE802.11b)
279 NETSIM_ID nReceiverId; //Unique id of receiver (As per IEEE802.11b)
280 //Next hop in Routing (RIP)
281 //Address[n] in DSR
282 PPACKET_INFO szPayload;//Actual payload of packet.
283 void* szOverhead;//Actual overhead of packet.
284 char szPacketType[MAX_PACKET_TYPE_LEN];
285 PACKET_STATUS nPacketStatus; //0 - No error, 1- Error, 2- collided, 3- Dropped
286 struct stru_NetSim_Packet_AppLayer* pstruAppData; //App layer details
287 struct stru_NetSim_Packet_TransportLayer* pstruTransportData; //Transport layer details
288 struct stru_NetSim_Packet_NetworkLayer* pstruNetworkData; //Network layer details
289 struct stru_NetSim_Packet_MACLayer* pstruMacData; //MAC layer details
290 struct stru_NetSim_Packet_PhyLayer* pstruPhyData; //Physical layer details
291 struct stru_NetSim_Packet* pstruNextPacket; //Pointer to next packet
292
293 //Function pointer for notification used for lower layer to higher layer notification
294 int (*DropNotification)(struct stru_NetSim_Packet* packet);
295 int (*ReceiveAckNotification)(struct stru_NetSim_Packet* ack);
296 };
297
298 /* PACKET API*/
299 /*MACROS*/
300# define PACKET_ID(pPacket) (pPacket)->nPacketId
301# define PACKET_SERVICETYPE(pPacket) (pPacket)->nServiceType
302# define PACKET_EVENTTIME(pPacket) (pPacket)->dEventTime
303# define PACKET_SOURCE(pPacket) (pPacket)->nSourceId
304# define PACKET_DESTINATION(pPacket) (pPacket)->nDestinationId
305# define PACKET_TRANSMITTER(pPacket) (pPacket)->nTransmitterId
306# define PACKET_RECEIVER(pPacket) (pPacket)->nReceiverId
307# define PACKET_APPDATA(pPacket) (pPacket)->pstruAppData
308# define PACKET_TRXDATA(pPacket) (pPacket)->pstruTransportData
309# define PACKET_NWDATA(pPacket) (pPacket)->pstruNetworkData
310# define PACKET_MACDATA(pPacket) (pPacket)->pstruMacData
311# define PACKET_PHYDATA(pPacket) (pPacket)->pstruPhyData
312# define PACKET_PHYPROTOCOLDATA(pPacket) PACKET_PHYDATA(pPacket)->Packet_PhyData
313# define PACKET_MACPROTOCOLDATA(pPacket) PACKET_MACDATA(pPacket)->Packet_MACProtocol
314# define PACKET_NWPROTOCOLDATA(pPacket) PACKET_NWDATA(pPacket)->Packet_NetworkProtocol
315# define PACKET_TRXPROTOCOLDATA(pPacket) PACKET_TRXDATA(pPacket)->Packet_TransportProtocol
316# define PACKET_APPPROTOCOLDATA(pPacket) PACKET_APPDATA(pPacket)->Packet_AppProtocol
317# define PACKET_NEXTPACKET(pPacket) (pPacket)->pstruNextPacket
318
319/* PACKET API */
320//Used to create a new packet of any layer
321 _declspec(dllexport) NetSim_PACKET* fn_NetSim_Packet_CreatePacket_dbg(int nLayer, int line, const char* file);
322 //Used to free mac layer protocol data
323 _declspec(dllexport) int fn_NetSim_Packet_FreeMacProtocolData(NetSim_PACKET* pstruPacket);
324 //Used to free the packet
325 _declspec(dllexport) int fn_NetSim_Packet_FreePacket_dbg(NetSim_PACKET** pstruPacket, int line, const char* file);
326 //Used to add the packet to list
327 _declspec(dllexport) int fn_NetSim_Packet_AddPacketToList_dbg(NetSim_BUFFER* pstruBuffer, NetSim_PACKET* pstruPacket, int nInsertionType /* 1- head,2-Tail,3-Order of event time*/, int line, const char* file);
328
329 /** Used to check whether any packet is there in buffer or not
330 * Return true if there is a packet in buffer
331 * Return false if there is no packet in buffer
332 */
333 _declspec(dllexport) bool fn_NetSim_GetBufferStatus(NetSim_BUFFER* pstruBuffer);
334
335 /** Used to get a packet from list
336 * pass nFlag = 1 if want to move buffer
337 * pass nFlag = 0 if don't want to move buffer
338 */
339 _declspec(dllexport) NetSim_PACKET* fn_NetSim_Packet_GetPacketFromBuffer(NetSim_BUFFER* pstruBuffer, int nFlag);
340
341 //Used to create error in packet
342 _declspec(dllexport) PACKET_STATUS fn_NetSim_Packet_DecideError(double dBER, long double dPacketSize);
343 //Used to copy a packet into a new packet
344 _declspec(dllexport) NetSim_PACKET* fn_NetSim_Packet_CopyPacket_dbg(const NetSim_PACKET* pstruPacket, int line, const char* file);
345 //Used to copy a list of packet
346 _declspec(dllexport) NetSim_PACKET* fn_NetSim_Packet_CopyPacketList_dbg(const NetSim_PACKET* pstruPacket, int line, const char* file);
347 _declspec(dllexport) int fn_NetSim_Packet_CopyPhyData(NetSim_PACKET* pstruDestPacket, const NetSim_PACKET* pstruSrcPacket, int, const char*);
348 //Used to copy mac/data link layer data of a packet to another packet
349 _declspec(dllexport) int fn_NetSim_Packet_CopyMacData(NetSim_PACKET* pstruDestPacket, const NetSim_PACKET* pstruSrcPacket, int, const char*);
350 //Used to copy network layer data of a packet to another packet
351 _declspec(dllexport) int fn_NetSim_Packet_CopyNWData(NetSim_PACKET* pstruDestPacket, NetSim_PACKET* pstruSrcPacket);
352 //Used to copy transport layer data of a packet to another packet
353 _declspec(dllexport) int fn_NetSim_Packet_CopyTransportData(NetSim_PACKET* pstruDestPacket, const NetSim_PACKET* pstruSrcPacket, int, const char*);
354 //Used to copy application layer data of a packet to another packet
355 _declspec(dllexport) int fn_NetSim_Packet_CopyAppData(NetSim_PACKET* pstruDestPacket, const NetSim_PACKET* pstruSrcPacket, int, const char*);
356 //Used to write packet trace
357 _declspec(dllexport) int fn_NetSim_WritePacketTrace_dbg(const NetSim_PACKET* pstruPacket, int line, const char* file);
358 //Used to validate a packet
359 _declspec(dllexport) int fnValidatePacket(const NetSim_PACKET* pstruPacket);
360 //Used to fragment the packet
361 _declspec(dllexport) int fn_NetSim_Stack_FragmentPacket(NetSim_PACKET* pstruPacket, int nMSS);
362 //Used to get packet size
363 _declspec(dllexport) double fnGetPacketSize(NetSim_PACKET* pstruData);
364 //Get packet type as string
365 _declspec(dllexport) char* fn_NetSim_Config_GetPacketTypeAsString(PACKET_TYPE nPacketType, char* buffer);
366 _declspec(dllexport) char* fn_NetSim_Config_GetControlPacketType(const NetSim_PACKET*, char* type);
367
368 _declspec(dllexport) int fn_NetSim_Dispatch_to_emulator(NetSim_PACKET* packet);
369 _declspec(dllexport) unsigned int getPacketInfoSize();
370
371 //Destination
372 _declspec(dllexport) void add_dest_to_packet(NetSim_PACKET* packet, NETSIM_ID dest);
373 _declspec(dllexport) void add_destlist_to_packet(NetSim_PACKET* packet, NETSIM_ID* destlist, UINT count);
374 _declspec(dllexport) NETSIM_ID* get_dest_from_packet(NetSim_PACKET* packet, UINT* count);
375 _declspec(dllexport) NETSIM_ID get_first_dest_from_packet(NetSim_PACKET* packet);
376 _declspec(dllexport) void remove_dest_from_packet(NetSim_PACKET* packet, NETSIM_ID dest);
377 _declspec(dllexport) bool isDestFoundinPacket(NetSim_PACKET* packet, NETSIM_ID dest);
378 _declspec(dllexport) bool isBroadcastPacket(NetSim_PACKET* packet);
379 _declspec(dllexport) bool isMulticastPacket(NetSim_PACKET* packet);
380
381 // Send to HWI
382 _declspec(dllexport) bool fn_NetSim_HWI_Send(NetSim_PACKET* packet);
383#ifdef __cplusplus
384}
385#endif
386#endif
387