NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Application.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_APPLICATION_H_
25#define _NETSIM_APPLICATION_H_
26
27//#define AES_ENCRYPT
28//#define DES_ENCRYPT
29
30#include "main.h"
31#include "Stack.h"
32#define roundoff(d) ((long)(d+0.5))
33#define MAX_TTL 255
34#define MAX_PORT 65535
35
36#define VANET_APP_RANDOM_WAIT_TIME_DEFAULT 5*MILLISECOND // SAE j2735
37#define RANDOM_STARTUP_DELAY 0.1*SECOND
38
39unsigned int nApplicationCount;
40
41typedef struct stru_Application_DataInfo APP_DATA_INFO;
42typedef struct stru_Application_VoiceInfo APP_VOICE_INFO;
43typedef struct stru_Application_VideoInfo APP_VIDEO_INFO;
44typedef struct stru_Application_HTTPInfo APP_HTTP_INFO;
45typedef struct stru_Application_InteractiveGamingInfo APP_GAMING_INFO;//Interactive Gaming
46typedef struct stru_Application_EMAILInfo APP_EMAIL_INFO;
47typedef struct stru_Application_P2PInfo APP_P2P_INFO;
48typedef struct stru_Application_CallInfo APP_CALL_INFO;
49typedef struct stru_Application_EmulationInfo APP_EMULATION_INFO;
50typedef struct stru_Application_COAPInfo APP_COAP_INFO;
51/// Enumeration for application events
52typedef enum
53{
54 event_APP_START = PROTOCOL_APPLICATION * 100 + 1,
55 event_APP_END,
56 event_APP_RESTART,
57}APP_EVENT;
58
59typedef enum
60{
61 Encryption_None,
62 Encryption_XOR,
63 Encryption_TEA,
64 Encryption_AES,
65 Encryption_DES,
66}ENCRYPTION;
67
68/// Enumeration for application control packets
69typedef enum
70{
71 packet_HTTP_REQUEST = PROTOCOL_APPLICATION * 100 + 1,
72 packet_COAP_REQUEST = PROTOCOL_APPLICATION * 100 + 2,
73}APP_CONTROL_PACKET;
74
75/// Enumeration for application state.
76typedef enum
77{
78 appState_Started,
79 appState_Paused,
80 appState_Terminated,
81}APP_STATE;
82
83/// Structure to store socket information
85{
86 NETSIM_ID nSourceId;
87 UINT destCount;
88 NETSIM_ID* nDestinationId;
89 NETSIM_ID nSourcePort;
90 NETSIM_ID nDestPort;
91 ptrSOCKETINTERFACE s;
92 _ele* ele;
93};
94#define SOCKETINFO_ALLOC() (struct stru_SocketInfo*)list_alloc(sizeof(struct stru_SocketInfo),offsetof(struct stru_SocketInfo,ele))
95/// Structure to store application information
97{
98 //config variable
99 NETSIM_ID id;
100 NETSIM_ID nConfigId;
101 TRANSMISSION_TYPE nTransmissionType;
102 APPLICATION_TYPE nAppType;
103 unsigned int nSourceCount;
104 unsigned int nDestCount;
105 NETSIM_ID* sourceList;
106 NETSIM_ID* destList;
107 double dStartTime;
108 double dEndTime;
109 double* dGenerationRate;
110 char* name;
111 QUALITY_OF_SERVICE qos;
112 TRANSPORT_LAYER_PROTOCOL trxProtocol;
113 APPLICATION_LAYER_PROTOCOL protocol;
114 NETSIM_ID applicationInstanceCount;
115
116 unsigned long long int nPacketId;
117 UINT16 sourcePort;
118 UINT16 destPort;
119 APP_STATE nAppState;
120 void* appMetrics;
121 void* appData;
122
123 ENCRYPTION encryption;
124 struct stru_SocketInfo* socketInfo;
125
126 //Broadcast Application
127 NETSIM_ID* recvList;
128 unsigned int* recvPort;
129
130 //Startup delay
131 bool isStartupDelay;
132
133 //Application Packet Logs
135 {
136 double prevPacketLatency;
137 double prevStartTime;
138 double prevEndTime;
139 UINT64 firstPacketReceived;
140 }uplink, downlink;
141
142 // Application Generation Logs
144 {
145 double lastPacketTime;
146 double lastPacketSize;
147 double prevLastPacketTime;
148 }ul, dl;
149
150 //Multicast application
151 NETSIM_IPAddress multicastDestIP;
152}APPLICATION_INFO, * ptrAPPLICATION_INFO;
153ptrAPPLICATION_INFO* applicationInfo;
154
155/// Structure for Data information such as packet size and inter arrival time,this is applicable for custom,FTP,Database Traffic
157{
158 DISTRIBUTION packetSizeDistribution;
159 double* dPacketSize;
160 DISTRIBUTION IATDistribution;
161 double* dIAT;
162};
163
164/// Structure for Data information such as packet size and inter arrival time,this is applicable for Vanet application
166{
167 DISTRIBUTION packetSizeDistribution;
168 double* dPacketSize;
169 DISTRIBUTION IATDistribution;
170 double* dIAT;
171 double dRandomWaitTime;
172}APP_BSM_INFO, * PAPP_BSM_INFO;
173
174/// Structure for voice information such as packet size, inter arrival time and service type,this is applicable for voice traffic
176{
177 DISTRIBUTION packetSizeDistribution;
178 double dPacketSize;
179 DISTRIBUTION IATDistribution;
180 double dIAT;
181 SERVICE_TYPE nServiceType;
182 SUPPRESSION_MODEL nSuppressionModel;
183 /*for Deterministic*/
184 int nSuccessRatio;
185 /*For Markov*/
186 int nTSL;//Talk spurt length
187 double dSAF;//Speech activity factor
188};
189
190/* Enumerator for video model*/
191typedef enum
192{
193 VidModel_NULL = 0,
194 VidModel_INDEPENDENT_GAUSSIAN = 1,
195 VidModel_FIRST_ORDER_DEPENDENT_GAUSSIAN,
196 VidModel_H_261,
197 VidModel_H_263,
198 VidModel_MPEG1_Low_Res,
199 VidModel_MPEG1_High_Res,
200 VidModel_MPEG2_Low_Res,
201 VidModel_MPEG2_High_Res,
202 VidModel_BUFFERED_VIDEO_STREAMING_1,
203 VidModel_BUFFERED_VIDEO_STREAMING_2,
204 VidModel_BUFFERED_VIDEO_STREAMING_3,
205 VidModel_BUFFERED_VIDEO_STREAMING_4,
206 VidModel_BUFFERED_VIDEO_STREAMING_5,
207 VidModel_BUFFERED_VIDEO_STREAMING_6,
208 VidModel_LAST,
209}VIDEOMODEL;
210static const char* strVIDEOMODEL[] = { "","INDEPENDENT_GAUSSIAN",
211"FIRST_ORDER_DEPENDENT_GAUSSIAN", "H_261", "H_263","MPEG1_Low_Res",
212"MPEG1_High_Res","MPEG2_Low_Res","MPEG2_High_Res","BUFFERED_VIDEO_STREAMING_1",
213"BUFFERED_VIDEO_STREAMING_2","BUFFERED_VIDEO_STREAMING_3",
214"BUFFERED_VIDEO_STREAMING_4","BUFFERED_VIDEO_STREAMING_5",
215"BUFFERED_VIDEO_STREAMING_6","Unknown" };
216
217/// structure to store the video application information
219{
220 VIDEOMODEL nVidModel;
221 int fps;
222 int ppf;
223 double mu;
224 double sigma;
225 double const_a;
226 double const_b;
227 double eta;
228
229 DISTRIBUTION packetSizeDistribution;
230 double* dPacketSizeArgs; /* Mean packet size for Exponential and constant distribution
231 * Scale and Shape parameter for Weibull distrinution
232 */
233
234 DISTRIBUTION IATDistribution;
235 double dIATArgs; // Mean IAT for Exponential and constant distribution
236};
237///Structure to store the emulation application information
239{
240 bool isMulticast;
241 bool isBroadcast;
242 UINT count;
243 NETSIM_ID nDestinationId;
244 NETSIM_ID* nSourceId;
245 NETSIM_ID nSourcePort;
246 NETSIM_ID nDestinationPort;
247 NETSIM_IPAddress* realSourceIP;
248 NETSIM_IPAddress realDestIP;
249 NETSIM_IPAddress* simSourceIP;
250 NETSIM_IPAddress simDestIP;
251
252 //Only for fast emulation
253 char* protocol;
254 char* filterString;
255 UINT priority;
256};
257/// Structure to store the HTTP application information
259{
260 double pageIAT;
261 DISTRIBUTION pageIATDistribution;
262 unsigned int pageCount;
263 double pageSize;
264 DISTRIBUTION pageSizeDistribution;
265};
266
267/// Structure to store the Interactive Gaming application information
269{
270 double ul_a_size;
271 double ul_b_size;
272 double ul_b_IAT;
273 double dl_a_size;
274 double dl_b_size;
275 double dl_a_IAT;
276 double dl_b_IAT;
277 UINT64 ul_id;
278 UINT64 dl_id;
279};
280
281/// Structure to store the COAP application information
282
284{
285 double pageIAT;
286 DISTRIBUTION pageIATDistribution;
287 double pageSize;
288 DISTRIBUTION pageSizeDistribution;
289 bool ackRequired;
290 bool multicastResponse;
291 int variableResponseTime; //in miliseconds
292 int piggybackedTime; //in miliseconds
293 int ackResponseTime; //in milliseconds
294 int ackTimeOut; //in milliseconds
295 double ackRandomFactor;
296 int maxRetransmit;
297 int nstart;
298 int defaultLeisure;
299 int probingRate;
300 struct stru_NetSim_COAP_data* pCOAPData;
301};
302
303/// Structure to store email application information
305{
307 {
308 double dDuration;
309 DISTRIBUTION durationDistribution;
310 double dEmailSize;
311 DISTRIBUTION sizeDistribution;
312 }SEND, RECEIVE;
313};
314
315/// Structure for Seeder list of peer_to_peer traffic
317{
318 NetSim_PACKET* packet;
319 unsigned int nSeederCount;
320 NETSIM_ID* nDeviceIds;
321}SEEDER_LIST;
322/// Structure for peer list of peer_to_peer traffic
324{
325 NETSIM_ID nDeviceId;
326 unsigned int yetToReceiveCount;
327 unsigned int* flag;
328}PEER_LIST;
329/// Structure fot peer_to_peer application
331{
332 double dFileSize;
333 DISTRIBUTION fizeSizeDistribution;
334 double dPiecesSize;
335
336 unsigned int nPieceCount; //Pieces count
337 NetSim_PACKET** pieceList; //Pieces
338 SEEDER_LIST** seederList; //For each pieces
339 PEER_LIST** peerList; //For each peers
340};
341/// Structure for Erlang_call application
343{
344 DISTRIBUTION callDurationDistribution;
345 double dCallDuration;
346 DISTRIBUTION callIATDistribution;
347 double dCallIAT;
348 int** nCallStatus;
349 double** dCallEndTime;
350 NetSim_PACKET*** nextPacket;
351 APP_VOICE_INFO VoiceInfo;
352
353 unsigned long long int** nEventId;
354 unsigned long long int** nAppoutevent;
355 int(*fn_BlockCall)(ptrAPPLICATION_INFO appInfo, NETSIM_ID nSourceId, NETSIM_ID nDestinationId, double time);
356};
357
358//For Email.c
359typedef struct stru_email_detail
360{
361 int type;
362 ptrAPPLICATION_INFO appInfo;
363}DETAIL;
364
365#include "NetSim_Plot.h"
366//Statistics
367bool nApplicationThroughputPlotFlag;
368char* szApplicationThroughputPlotVal;
369bool nApplicationThroughputPlotRealTime;
370PNETSIMPLOT* applicationThroughputPlots;
371bool* nAppPlotFlag;
372
373NetSim_PACKET* fn_NetSim_Application_GeneratePacket(ptrAPPLICATION_INFO info,
374 double ldArrivalTime,
375 NETSIM_ID nSourceId,
376 UINT destCount,
377 NETSIM_ID* nDestination,
378 unsigned long long int nPacketId,
379 APPLICATION_TYPE nAppType,
380 QUALITY_OF_SERVICE nQOS,
381 unsigned int sourcePort,
382 unsigned int destPort);
383
384int fn_NetSim_Application_GenerateNextPacket(ptrAPPLICATION_INFO appInfo,
385 NETSIM_ID nSource,
386 UINT destCount,
387 NETSIM_ID* nDestination,
388 double time);
389
390/* Distribution Function */
391_declspec(dllexport) int fnDistribution(DISTRIBUTION nDistributionType, double* fDistOut,
392 unsigned long* uSeed, unsigned long* uSeed1, double* args);
393
394/* Random number generator */
395_declspec(dllexport) int fnRandomNo(long lm, double* fRandNo, unsigned long* uSeed, unsigned long* uSeed1);
396
397/* HTTP Application */
398int fn_NetSim_Application_StartHTTPAPP(ptrAPPLICATION_INFO appInfo, double time);
399int fn_NetSim_Application_ConfigureHTTPTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
400int fn_NetSim_Application_HTTP_ProcessRequest(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* pstruPacket);
401
402/*Interactive Gaming Application*/
403int fn_NetSim_Application_ConfigureInteractiveGamingTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
404int fn_NetSim_Application_StartInteractiveGamingULAPP(ptrAPPLICATION_INFO appInfo, double time);
405int fn_NetSim_Application_StartInteractiveGamingDLAPP(ptrAPPLICATION_INFO appInfo, double time);
406int fn_NetSim_Application_InteractiveGamingUL_GenerateNextPacket(ptrAPPLICATION_INFO appInfo, NetSim_PACKET* pstruPacket, double time);
407int fn_NetSim_Application_InteractiveGamingDL_GenerateNextPacket(ptrAPPLICATION_INFO appInfo, NetSim_PACKET* pstruPacket, double time);
408
409/* COAP Application*/
410int fn_NetSim_Application_StartCOAPAPP(ptrAPPLICATION_INFO appInfo, double time);
411int fn_NetSim_Application_ConfigureCOAPTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
412int fn_NetSim_Application_COAP_ProcessRequest(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* pstruPacket);
413
414/* Video Application */
415int fn_NetSim_Application_StartVideoAPP(ptrAPPLICATION_INFO appInfo, double time);
416int fn_NetSim_Application_ConfigureVideoTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
417_declspec(dllexport) int fn_NetSim_TrafficGenerator_Video(APP_VIDEO_INFO* info,
418 double* fPacketSize,
419 double* ldArrival,
420 unsigned long* uSeed,
421 unsigned long* uSeed1);
422//Functions for Video Models H_261, H_263, MPEG1_M, MPEG1_H, MPEG2_M, MPEG2_H
423
424int fn_NetSim_TrafficGenerator_MPEGVideo(APP_VIDEO_INFO* info,
425 double* fPacketSize,
426 double* ldArrival,
427 unsigned long* uSeed,
428 unsigned long* uSeed1);
429int fn_NetSim_Application_ConfigureMPEGVideo(APP_VIDEO_INFO* info, void* xmlNetSimNode);
430
431/* Voice Application */
432int fn_NetSim_Application_StartVoiceAPP(ptrAPPLICATION_INFO appInfo, double time);
433int fn_NetSim_Application_ConfigureVoiceTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
434_declspec(dllexport) int fn_NetSim_TrafficGenerator_Voice(APP_VOICE_INFO* info,
435 double* fSize,
436 double* ldArrival,
437 unsigned long* uSeed,
438 unsigned long* uSeed1);
439
440/* Peer To Peer Application */
441int fn_NetSim_Application_P2P_GenerateFile(ptrAPPLICATION_INFO appInfo);
442int fn_NetSim_Application_P2P_InitSeederList(ptrAPPLICATION_INFO appInfo);
443int fn_NetSim_Application_P2P_InitPeers(ptrAPPLICATION_INFO appInfo);
444int fn_NetSim_Application_P2P_SendNextPiece(ptrAPPLICATION_INFO appInfo, NETSIM_ID destination, double time);
445int fn_NetSim_Application_StartP2PAPP(ptrAPPLICATION_INFO appInfo, double time);
446int fn_NetSim_Application_ConfigureP2PTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
447int fn_NetSim_Application_P2P_MarkReceivedPacket(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* pstruPacket);
448
449/* Email Application */
450int fn_NetSim_Application_StartEmailAPP(ptrAPPLICATION_INFO appInfo, double time);
451int fn_NetSim_Application_ConfigureEmailTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
452ptrAPPLICATION_INFO fn_NetSim_Application_Email_GenerateNextPacket(DETAIL* detail, NETSIM_ID nSourceId, NETSIM_ID nDestinationId, double time);
453ptrAPPLICATION_INFO get_email_app_info(void* detail);
454
455/* Custom, FTP, Database Application */
456int fn_NetSim_Application_StartDataAPP(ptrAPPLICATION_INFO appInfo, double time);
457int fn_NetSim_Application_ConfigureDataTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
458int fn_NetSim_Application_ConfigureDatabaseTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
459int fn_NetSim_Application_ConfigureFTPTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
460_declspec(dllexport) int fn_NetSim_TrafficGenerator_Custom(APP_DATA_INFO* info,
461 double* fSize,
462 double* ldArrival,
463 unsigned long* uSeed,
464 unsigned long* uSeed1,
465 unsigned long* uSeed2,
466 unsigned long* uSeed3);
467
468/* Erlang Call */
469int fn_NetSim_Application_ErlangCall_StartCall(NetSim_EVENTDETAILS* pstruEventDetails);
470int fn_NetSim_Application_ErlangCall_EndCall(NetSim_EVENTDETAILS* pstruEventDetails);
471int fn_NetSim_Application_StartErlangCallAPP(ptrAPPLICATION_INFO appInfo, double time);
472int fn_NetSim_Application_ConfigureErlangCallTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
473
474/* Emulation */
475int fn_NetSim_Application_ConfigureEmulationTraffic(ptrAPPLICATION_INFO appInfo, void* xmlNetSimNode);
476void fn_NetSim_Emulation_StartApplication(ptrAPPLICATION_INFO appInfo);
477
478/* Vanet Application*/
479int fn_NetSim_Application_StartBSM(ptrAPPLICATION_INFO appInfo, double time);
480int fn_NetSim_Application_BSM(PAPP_BSM_INFO info,
481 double* fSize,
482 double* ldArrival,
483 unsigned long* uSeed,
484 unsigned long* uSeed1,
485 unsigned long* uSeed2,
486 unsigned long* uSeed3);
487bool add_sae_j2735_payload(NetSim_PACKET* packet, ptrAPPLICATION_INFO info);
488void process_saej2735_packet(NetSim_PACKET* packet);
489
490//Multicast
491void add_multicast_route(ptrAPPLICATION_INFO info);
492void join_multicast_group(ptrAPPLICATION_INFO info, double time);
493
494/* Application API's */
495_declspec(dllexport) int fn_NetSim_Application_Init_F();
496_declspec(dllexport) int fn_NetSim_Application_Configure_F(void** var);
497_declspec(dllexport) int fn_NetSim_Application_Metrics_F(PMETRICSWRITER metricsWriter);
498int fn_NetSim_App_RestartApplication();
499_declspec(dllexport) int fn_NetSim_Application_Plot(NetSim_PACKET* pstruPacket);
500PACKET_TYPE fn_NetSim_Application_GetPacketTypeBasedOnApplicationType(APPLICATION_TYPE nAppType);
501ptrSOCKETINTERFACE fnGetSocket(NETSIM_ID nAppId,
502 NETSIM_ID nSourceId,
503 NETSIM_ID nSourcePort,
504 NETSIM_ID nDestPort);
505
506//Application metrics
507void free_app_metrics(ptrAPPLICATION_INFO appInfo);
508void appmetrics_src_add(ptrAPPLICATION_INFO appInfo, _In_ NetSim_PACKET* packet);
509void appmetrics_dest_add(ptrAPPLICATION_INFO appInfo, NetSim_PACKET* packet, NETSIM_ID dest);
510int fn_NetSim_Application_Metrics_F(PMETRICSWRITER metricsWriter);
511
512//Application Interface function
513void fnCreatePort(ptrAPPLICATION_INFO info);
514int fnCreateSocketBuffer(ptrAPPLICATION_INFO appInfo);
515void P2P_create_socket(ptrAPPLICATION_INFO appInfo, NETSIM_ID src, NETSIM_ID dest);
516void Interactive_Gaming_createUL_socket(ptrAPPLICATION_INFO appInfo, NETSIM_ID src, NETSIM_ID dest);
517void Interactive_Gaming_createDL_socket(ptrAPPLICATION_INFO appInfo, NETSIM_ID src, NETSIM_ID dest);
518
519int fn_NetSim_Add_DummyPayload(NetSim_PACKET* packet, ptrAPPLICATION_INFO);
520
521//Encryption
522char xor_encrypt(char ch, long key);
523int aes256(char* str, int* len);
524int des(char* buf, int* len);
525
526//Application event handler
527void handle_app_out();
528
529//Application Packet Log
530void init_application_log();
531void print_application_log(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* pstruPacket);
532void close_application_log();
533bool get_protocol_log_status(char* logname);
534void update_latency();
535
536// Generation Logs
537void init_application_generation_log();
538double get_generation_rate(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* packet);
539void close_application_generation_log();
540void print_application_generation_log(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* packet);
541double calculate_generation_rate(ptrAPPLICATION_INFO pstruappinfo, NetSim_PACKET* packet);
542#endif
Structure for Data information such as packet size and inter arrival time,this is applicable for Vane...
Structure to store the COAP application information.
Structure for Erlang_call application.
Structure for Data information such as packet size and inter arrival time,this is applicable for cust...
Structure to store email application information.
Structure to store the emulation application information.
Structure to store the HTTP application information.
Structure to store application information.
Definition Application.h:97
Structure to store the Interactive Gaming application information.
Structure for Seeder list of peer_to_peer traffic.
Structure fot peer_to_peer application.
structure to store the video application information
Structure for voice information such as packet size, inter arrival time and service type,...
Structure for peer list of peer_to_peer traffic.
Structure to store socket information.
Definition Application.h:85