NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Stack.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_STACK_H_
25#define _NETSIM_STACK_H_
26#ifdef __cplusplus
27extern "C" {
28#endif
29#include "List.h"
30#include "Wireless.h"
31
32#ifdef _WIN32
33#ifdef _NETSIM_CODE_
34#define EXPORTED _declspec(dllexport)
35#else
36#define EXPORTED _declspec(dllimport)
37#endif
38#ifdef _NETSIM_METRIC_CODE_
39#undef EXPORTED
40#define EXPORTED
41#endif
42#else
43#ifdef _NETSIM_CODE_
44#define EXPORTED
45#else
46#define EXPORTED extern
47#endif
48#ifdef _NETSIM_METRIC_CODE_
49#undef EXPORTED
50#define EXPORTED
51#endif
52
53#endif
54EXPORTED bool isSimulationContinued;
55
56//Time Definition
57#define MICROSECOND (1.0)
58#define NANOSECOND (MICROSECOND/1000.0)
59#define MILLISECOND (1000.0*MICROSECOND)
60#define SECOND (1000.0*MILLISECOND)
61#define MINUTE (60.0*SECOND)
62#define HOUR (60.0*MINUTE)
63
64
65#ifndef INFINITY
66#define INFINITY (0xFFFFFFFF)
67#endif
68#ifndef NEGATIVE_INFINITY
69#define NEGATIVE_INFINITY (-1.0*INFINITY)
70#endif
71
72
73/* Enumeration for flag*/
74enum enum_Flag
75{
76 ZERO,
77 ONE,
78};
79
80typedef enum enum_sim_state
81{
82 SIMSTATE_NOTSTARTED,
83 SIMSTATE_PAUSED,
84 SIMSTATE_RUNNING,
85 SIMSTATE_STOPPED,
86}SIMSTATE;
87_declspec(dllexport) void netsim_set_simstate(SIMSTATE state);
88_declspec(dllexport) SIMSTATE netsim_get_simstate();
89
90/* Enumeration for Layer type*/
91enum enum_LayerType
92{
93 LAYER_NULL=0,
94 PHYSICAL_LAYER = 1, //Interface layer in linux
95 MAC_LAYER, //Protocol layer in linux
96 NETWORK_LAYER, //Socket layer in linux
97 TRANSPORT_LAYER, //Socket layer in linux
98 APPLICATION_LAYER, //Process layer in linux
99};
100/* Enumeration for event type*/
101enum enum_EventType
102{
103 END_EVENT = 0,
104 PHYSICAL_OUT_EVENT = PHYSICAL_LAYER*10+1,
105 PHYSICAL_IN_EVENT = PHYSICAL_LAYER*10+2,
106 MAC_OUT_EVENT = MAC_LAYER*10+1,
107 MAC_IN_EVENT = MAC_LAYER*10+2,
108 NETWORK_OUT_EVENT = NETWORK_LAYER*10+1,
109 NETWORK_IN_EVENT = NETWORK_LAYER*10+2,
110 TRANSPORT_OUT_EVENT = TRANSPORT_LAYER*10+1,
111 TRANSPORT_IN_EVENT = TRANSPORT_LAYER*10+2,
112 APPLICATION_OUT_EVENT = APPLICATION_LAYER*10+1,
113 APPLICATION_IN_EVENT = APPLICATION_LAYER*10+2,
114 TIMER_EVENT = 1,
115 INTERNAL_NETSIM_EVENT=2,
116};
117
118typedef enum enum_common_subevent
119{
120 SUBEVENT_GETLINKQUALITY= TIMER_EVENT*100+1, //Must be provided by link layer protocol to get link quality
121 SUBEVENT_JOIN_MULTICAST_GROUP,
122 SUBEVENT_LINKUP,
123 SUBEVENT_LINKDOWN,
124 SUBEVENT_HWIRECV,
125 SUBEVENT_HWI_CLEANUP,
126 SUBEVENT_PAUSESIMULATION,
127 SUBEVENT_EXECUTECOMMAND,
128 SUBEVNET_LAST,
129}COMMON_SUBEVENT;
130
131static char subeventName[SUBEVNET_LAST][100] = { "GET_LINK_QUALITY",
132"JOIN_MULTICAST_GROUP",
133"LINKUP",
134"LINKDOWN",
135"HWIRECV",
136"HWI_CLEANUP",
137"PAUSE_SIMULATION",
138"EXECUTE_COMMAND"};
139
140///Internal module
141#define PROTOCOL_METRICS 2
142#define PROTOCOL_MOBILITY 3
143#define PROTOCOL_APPLICATION 4
144#define PROTOCOL_LINK 5
145#define PROTOCOL_HWI 6
146#define PROTOCOL_CLI 7
147
148/* Enumeration for Application layer protocol*/
149enum enum_AppProtocol
150{
151 APP_PROTOCOL_NULL = 0,
152
153 // Routing protocol
154 APP_PROTOCOL_RIP = APPLICATION_LAYER*100+1,//=501,
155 APP_PROTOCOL_OSPF,
156
157 //Application
158 APP_PROTOCOL_OPENFLOW,
159 APP_PROTOCOL_RTP,
160
161 //Traffic
162 APP_PROTOCOL_CBR=PROTOCOL_APPLICATION,
163 APP_PROTOCOL_VOICE=PROTOCOL_APPLICATION,
164 APP_PROTOCOL_FTP=PROTOCOL_APPLICATION,
165 APP_PROTOCOL_HTTP=PROTOCOL_APPLICATION,
166 APP_PROTOCOL_BSM=PROTOCOL_APPLICATION,
167 APP_PROTOCOL_COAP=PROTOCOL_APPLICATION,
168 APP_PROTOCOL_DATABASE=PROTOCOL_APPLICATION,
169 APP_PROTOCOL_CUSTOM=PROTOCOL_APPLICATION,
170 APP_PROTOCOL_EMAIL=PROTOCOL_APPLICATION,
171 APP_PROTOCOL_ERLANGCALL=PROTOCOL_APPLICATION,
172 APP_PROTOCOL_VIDEO=PROTOCOL_APPLICATION,
173 APP_PROTOCOL_EMULATION=PROTOCOL_APPLICATION,
174 APP_PROTOCOL_INTERACTIVE_GAMING=PROTOCOL_APPLICATION,
175};
176
177/* Enumeration for transport layer protocol*/
178enum enum_TrxProtocol
179{
180 TX_PROTOCOL_NULL = 0,
181 TX_PROTOCOL_TCP = TRANSPORT_LAYER*100+1,
182 TX_PROTOCOL_UDP,
183 TX_PROTOCOL_WSMP, //IEEE1609.3
184};
185
186/* Enumeration for network layer protocol*/
187enum enum_NWProtocol
188{
189 /* IP protocol*/
190 NW_PROTOCOL_IPV4 = NETWORK_LAYER*100+1,
191 NW_PROTOCOL_IPV6,
192 NW_PROTOCOL_ARP,
193 NW_PROTOCOL_ICMP,
194 NW_PROTOCOL_IGMP,
195
196 /* Routing Protocol*/
197 NW_PROTOCOL_DSR,
198 NW_PROTOCOL_AODV,
199 NW_PROTOCOL_ZRP,
200 NW_PROTOCOL_OLSR,
201 NW_PROTOCOL_RPL, //RFC 6550
202};
203
204/* Enumeration for MAC layer protocol*/
205enum enum_MACProtocol
206{
207 MAC_PROTOCOL_NULL=0,
208 /***WIRELESS***/
209 MAC_PROTOCOL_IEEE802_11 = MAC_LAYER*100+1, //WLAN
210 MAC_PROTOCOL_IEEE802_15_4, //Zigbee
211 MAC_PROTOCOL_IEEE802_22, //Cognitive Radio
212
213 /***WIRED***/
214 MAC_PROTOCOL_IEEE802_3, //Ethernet
215 MAC_PROTOCOL_P2P, //Point to point link
216
217 /***Cellular Protocol***/
218 MAC_PROTOCOL_CDMA, //CDMA
219 MAC_PROTOCOL_GSM, //GSM
220 MAC_PROTOCOL_LTE, //LTE
221 MAC_PROTOCOL_LTE_NR, //LTE-NR (5G)
222
223 /***/
224 MAC_PROTOCOL_TDMA, //TDMA
225 MAC_PROTOCOL_DTDMA, //Dynamic TDMA
226
227 MAC_PROTOCOL_ALOHA,
228 MAC_PROTOCOL_CSMACD,
229 MAC_PROTOCOL_TOKEN_RING_BUS,
230
231 MAC_PROTOCOL_IEEE1609, //IEEE 1609, WAVE, VANET
232
233 MAC_PROTOCOL_UWAN, // Underwater acoutics network. Not really a protocol
234
235 MAC_PROTOCOL_SATELLITE, // Satellite network, Not really a protocol
236};
237
238
239/*Enumeration for physical medium type. Must be compatible with MAC layer*/
240enum enum_PhyMedium
241{
242 PHY_MEDIUM_NULL = 0,
243 PHY_MEDIUM_WIRELESS = 1,
244 PHY_MEDIUM_WIRED = 2,
245};
246
247/*Enumeration for interface type. Must be compatible with network layer, MAC layer and physical medium*/
248enum enum_InterfaceType
249{
250 INTERFACE_NULL=0,
251 INTERFACE_LAN_802_3=1, //Ethernet
252 INTERFACE_LAN_802_11, //WLAN b
253 INTERFACE_LAN_802_15_4, //Zigbee
254 INTERFACE_LAN_802_22, //Cognitive radio
255 INTERFACE_WAN_ROUTER, //WAN
256 INTERFACE_VIRTUAL, //Virtual interface
257 INTERFACE_GSM, //GSM Interface
258 INTERFACE_CDMA, //CDMA Interface
259 INTERFACE_LTE, //LTE Interface
260 INTERFACE_LTE_NR, //LTE-NR Interface
261 INTERFACE_5G = INTERFACE_LTE_NR, //5G interface
262 INTERFACE_NTN = INTERFACE_LTE_NR, //Non Terrestrial Network interface
263 INTERFACE_ALOHA, // Aloha Interface
264 INTERFACE_TOKEN_RING, //Token ring interface
265 INTERFACE_TOKEN_BUS, //Token bus interface
266 INTERFACE_IEEE1609, // WAVE, VANET Interface
267 INTERFACE_P2P, // Point to Point Interface
268};
269
270/* Enumeration for device type*/
271enum enum_DeviceType
272{
273 Not_Device=0,
274 /* Node 5-layer device */
275 NODE=1, //Wired or wireless
276 CPE=1, //Wired
277 MOBILESTATION=1,//Wireless
278 UE=1, //Wireless LTE user equipment
279 SENSOR=1, //Wireless
280 RSU=1, //Road side Unit, wireless
281 SATELLITE_UT=1, //Satellite user terminal
282
283 /***Intermediate Device***/
284 /* 2-layer device*/
285 SWITCH=2, //Wired
286 SATELLITE = 2, //Satellite
287 HUB=3, //Wired
288 CONCENTRATOR=3,
289 BASESTATION=4, //Wireless
290 eNB=4, //Wireless LTE base station
291 gNB=4, //Wireless LTE-NR base station
292 ACCESSPOINT=5, //Wireless
293
294 /*5-Layer routing device*/
295 ROUTER=6, //Wired and/or wireless
296 MME=6, //LTE Mobile management entity
297 HNB_GATEWAY=6, //LTE Femtocell Gateway
298 EPC=6, //Evolved Packet Core (LTE, LTE-NR)
299 SINKNODE = 6, //Wireless
300 PANCOORDINATOR = 6, //Wireless
301 SATELLITE_GW=6, //Satellite gateway
302
303 /* 5 layer device without routing or switching protocol*/
304 _5G_CORE_AMF = 7,
305 _5G_CORE_SMF = 7,
306 _5G_CORE_UPF = 7,
307
308 MSC=8, //Mobile Switching center
309
310 RELAY = 9, //Phy layer device
311};
312
313/* Enumeration for link type */
314enum enum_LinkType
315{
316 LinkType_NULL=0,
317 LinkType_P2P=1, //Point to point
318 LinkType_P2MP=2,//Point to multipoint
319 LinkType_MP2MP=3,//multipoint to multipoint
320};
321
322/* Enumeration for link state */
323enum enum_LinkState
324{
325 LINKSTATE_UP,
326 LINKSTATE_DOWN,
327};
328
329/* Enumerator for link mode */
330enum enum_LinkMode
331{
332 LinkMode_NULL=0,
333 LinkMode_HalfDuplex=1,
334 LinkMode_FullDuplex=2,
335};
336
337/* Enumeration for Simulation exit type*/
338enum enum_SimulationEndType
339{
340 SimEndType_TIME=1, //End simulation after specified time
341};
342
343/*Enumeration for scheduling type*/
344enum enum_SchedulingType
345{
346 SCHEDULING_NONE=0,
347 SCHEDULING_FIFO=1,
348 SCHEDULING_PRIORITY=2,
349 SCHEDULING_ROUNDROBIN=3,
350 SCHEDULING_WFQ=4,
351 SCHEDULING_EDF=5,
352 SCHEDULING_CLASSBASED=6,
353};
354
355typedef enum enum_QueuingTechnique
356{
357 QUEUING_NULL,
358 QUEUING_DROPTAIL,
359 QUEUING_RED,
360 QUEUING_WRED,
361}QUEUINGTECHNIQUE;
362
363enum enum_TransmissionType
364{
365 UNICAST,
366 BROADCAST,
367 MULTICAST,
368};
369
370/* enumeration for wireshark option */
371enum emum_wireshark_option
372{
373 wireshark_disable=0,
374 wireshark_online,
375 wireshark_offline,
376};
377
378/*enumeration for Node action */
379typedef enum enum_NodeAction
380{
381 NOT_CONNECTED,
382 CONNECTED,
383 JOIN,
384 LEAVE,
385}NODE_ACTION;
386
387/* Structure of mac address*/
388typedef struct stru_macaddress
389{
390 unsigned long long int nmacaddress;
391 char szmacaddress[13];
392 char szBinary[50];
393}NETSIM_MACADDRESS,*PNETSIM_MACADDRESS;
394
395EXPORTED PNETSIM_MACADDRESS BROADCAST_MAC;
396
397#ifndef M_PI
398#define M_PI 3.14159265358979323846
399#endif
400#define DegreesToRadians(degree) ((degree) * (M_PI / 180.0))
401#define RadiansToDegrees(radian) ((radian) * (180.0 / M_PI))
402
403/*Coordinate of point in 3-d space*/
404typedef enum enum_refEllipsoid
405{
406 REFERENCEELLIPSOID_SPHERE,
407 REFERENCEELLIPSOID_WGS84,
408 REFERENCEELLIPSOID_GRS80,
409
410 REFERENCEELLIPSOID_COUNT, //keep me at last
411} GEOCORR_REFERENCEELLIPSOID;
412
413typedef enum enum_corrType
414{
415 CORRTYPE_CARTESIAN,
416 CORRTYPE_MAP,
417 CORRTYPE_GEO,
418}NETSIM_COORDINATETYPE;
419
421{
422 NETSIM_COORDINATETYPE corrType;
423
424 //Map or geo
425 double lat;
426 double lon;
427
428 //Geo
429 double altitude;
430 GEOCORR_REFERENCEELLIPSOID refEllipsoid;
431
432 //Cartesian
433 double X;
434 double Y;
435 double Z;
436};
437//Used to convert Lat/Lon to X,Y,Z
438_declspec(dllexport) void fn_NetSim_Coordinate_ConvertMapToCartesian(double lat, double lon, NetSim_COORDINATES* pos);
439_declspec(dllexport) void fn_NetSim_Coordinate_ConvertCartesianToMap(NetSim_COORDINATES* pos);
440
441_declspec(dllexport) void fn_NetSim_Coordinate_ConvertGeoToCartesian(double lat, double lon,
442 double altitude, char* strRefEllipsoid,
443 NetSim_COORDINATES* pos);
444_declspec(dllexport) void fn_NetSim_Coordinate_ConvertCartesianToGeo(NetSim_COORDINATES* pos,
445 GEOCORR_REFERENCEELLIPSOID refEllipsoid);
446
447/*Store the simulation parameter*/
449{
450 SIMULATION_END_TYPE nSimulationExitType;//Simulation exit type
451 double dVal; //Value at which simulation end occurs for a particular simulation end type.
452 //For example Time = 100000 Sec.
453};
454
455/* Socket Interface*/
457{
458 NETSIM_ID applicationId;
459 NETSIM_ID applicationInstance;
460 APPLICATION_LAYER_PROTOCOL appProtocol;
461 TRANSPORT_LAYER_PROTOCOL trxProtocol;
462 UINT16 localPortNumber;
463 UINT16 remotePortNumber;
464 struct stru_NetSim_Device_Buffer* pstruSocketBuffer;
465 struct stru_NetSim_SocketInterface* next;
466}SOCKETINTERFACE, *ptrSOCKETINTERFACE;
467_declspec(dllexport) ptrSOCKETINTERFACE fn_NetSim_Socket_CreateNewSocket(NETSIM_ID deviceId,
468 int appProtocol,
469 TRANSPORT_LAYER_PROTOCOL trxProtocol,
470 UINT16 localPort,
471 UINT16 remotePort);
472_declspec(dllexport) ptrSOCKETINTERFACE fn_NetSim_Socket_GetSocketInterface(NETSIM_ID deviceId,
473 APPLICATION_LAYER_PROTOCOL appProtocol,
474 TRANSPORT_LAYER_PROTOCOL trxProtocol,
475 UINT16 localPort,
476 UINT16 remotePort);
477_declspec(dllexport) void fn_NetSim_Socket_PassPacketToInterface(NETSIM_ID deviceId,
478 NetSim_PACKET* packet,
479 ptrSOCKETINTERFACE socketInterface);
480
481
482/* Stores the application layer of device*/
484{
485 LAYER_TYPE nLayerType; //Layer type
486 UINT nappProtocolCount;
487 UINT* nAppProtocol; //Application layer protocol list
488 void** appVar; //Application protocol variable
489};
490_declspec(dllexport) void* fn_NetSim_Stack_RegisterNewApplicationProtocol(NETSIM_ID deviceId,
491 UINT appProtocol);
492_declspec(dllexport) void* fn_NetSim_Stack_GetAppProtocolData(NETSIM_ID deviceId,
493 UINT appProtocol);
494_declspec(dllexport) void fn_NetSim_Stack_SetAppProtocolData(NETSIM_ID deviceId,
495 UINT appProtocol,
496 void* data);
497_declspec(dllexport) bool fn_NetSim_Socket_GetBufferStatus(ptrSOCKETINTERFACE s);
498_declspec(dllexport) NetSim_PACKET* fn_NetSim_Socket_GetPacketFromInterface(ptrSOCKETINTERFACE s,
499 int moveFlag);
500
501/* Stores the transport layer of device*/
503{
504 unsigned int isTCP:1; //Flag to enable or disable TCP
505 unsigned int isUDP:1; //Flag to enable or disable UDP;
506 TRANSPORT_LAYER_PROTOCOL nTransportLayerProtocol; //Other than TCP and UDP
507 LAYER_TYPE nLayerType; //Layer type
508 double dMSS; //Updated by tx layer protocol
509 void* TCPVar; //Pointer for TCP variable
510 void* UDPVar;//Pointer for UDP variable
511 void* TransportProtocolVar; //Pointer to transport layer protocol
512};
513
514typedef struct stru_ip_wrapper
515{
516 bool isInit;
517 void* handle; //Animation handle
518 void* table; //IP routing tables
519}IP_WRAPPER, *ptrIP_WRAPPER;
520
521/*Stores the network layer of device*/
523{
524 LAYER_TYPE nLayerType; //Layer type
525 NETWORK_LAYER_PROTOCOL nRoutingProtocolId; //Routing protocol id
526 void* RoutingVar; //Routing variable
527 int (*routerFunction)(); //Routing function used by app layer routing protocol
528 // like RIP, OSPF
529 ptrIP_WRAPPER ipWrapper;
530 void* ipVar; //IP configuration variable
531 double dMaxPacketLen;
532};
533
534/*Stores the MAC layer of device*/
536{
537 LAYER_TYPE nLayerType; //Layer type
538 MAC_LAYER_PROTOCOL nMacProtocolId; //Protocol id
539 PNETSIM_MACADDRESS szMacAddress; //MAC address of the device
540 bool isWiresharkWriter;
541 double dFragmentSize; //Updated by mac layer protocol
542 void* MacVar; //MAC protocol variable
543};
544
545/*Stores the physical layer of device*/
547{
548 LAYER_TYPE nLayerType; //Layer type
549 PHYSICAL_LAYER_MEDIUM nPhyMedium; //Physical medium type. Must be compatible with mac layer
550 NETSIM_ID nLinkId; //Connected link id
551 struct stru_NetSim_Links* pstruNetSimLinks; //Pointer to connected link
552 void* phyVar; //Phy layer variable
553 double dLastPacketEndTime; //Last packet end time
554
555 union
556 {
557 //For wireless
558 PHYPROP_WIRELESS wireless;
559 //For Wired
560 struct
561 {
562 int noProperty;
563 }WIRED;
564 }phyProp;
565};
566
567/* Stores the buffer information of device*/
569{
570 NETSIM_ID deviceId;
571 NETSIM_ID interfaceId;
572
573 double dMaxBufferSize; //Max buffer size in bytes
574 double dCurrentBufferSize; //Current buffer size in bytes
575
576 SCHEDULING_TYPE nSchedulingType; //Scheduling type
577 QUEUINGTECHNIQUE queuingTechnique;
578
579 void* schedulingParam;
580 void* queuingParam;
581 bool isPlotEnable;
582 void* netsimPlotVar;
583
584 unsigned int nQueuedPacket;
585 unsigned int nDequeuedPacket;
586 unsigned int nDroppedPacket;
587 struct stru_NetSim_Packet* pstruPacketlist; //Packet list
588 struct stru_NetSim_Packet* last;
589};
590
591/* Stores the MAC-NW interface of device*/
593{
594 struct stru_NetSim_Device_Buffer* pstruAccessBuffer; //MAC-NW buffer
595};
596
597/* structure for node join profile */
599{
600 NETSIM_ID NodeId;
601 double time;
602 NODE_ACTION action;
603 _ele* ele;
604}NODE_JOIN_PROFILE,*PNODE_JOIN_PROFILE;
605#define JOIN_PROFILE_ALLOC() (PNODE_JOIN_PROFILE)list_alloc(sizeof(NODE_JOIN_PROFILE),offsetof(NODE_JOIN_PROFILE,ele))
606#define JOIN_PROFILE_NEXT(profile) profile=(PNODE_JOIN_PROFILE)LIST_NEXT(profile)
607#define JOIN_PROFILE_ADD(lprofile,profile) LIST_ADD_LAST((void**)lprofile,profile)
608
609/* stores the links information*/
611{
612 NETSIM_ID nConfigLinkId; //Link id setted in config file
613 NETSIM_ID nLinkId;
614 LINK_TYPE nLinkType;
615 PHYSICAL_LAYER_MEDIUM nLinkMedium;
616 LINK_MODE nLinkMode;
618 {
620 {
621 double dDistance;
622 double dPropagationDelayUp;
623 double dDataRateUp;
624 double dErrorRateUp;
625 double dPropagationDelayDown;
626 double dDataRateDown;
627 double dErrorRateDown;
628 }pstruWiredLink;
630 {
631 double dDataRateUp;
632 double dDataRateDown;
633 PPROPAGATION propagation;
634 }pstruWirelessLink;
635 }puniMedProp;
637 {
639 {
640 NETSIM_ID nFirstDeviceId;
641 NETSIM_ID nFirstInterfaceId;
642 NETSIM_ID nSecondDeviceId;
643 NETSIM_ID nSecondInterfaceId;
644 }pstruP2P;
646 {
647 NETSIM_ID nConnectedDeviceCount;//Count of connected device through this wireless link
648 NETSIM_ID nCenterDeviceId;
649 NETSIM_ID nCenterInterfaceId;
650 NETSIM_ID* anDevIds; //List of all the device belong to this wireless medium
651 NETSIM_ID* anDevInterfaceIds;
652 }pstrup2MP;
654 {
655 NETSIM_ID nConnectedDeviceCount;//Count of connected device through this wireless link
656 NETSIM_ID* anDevIds; //List of all the device belong to this shared medium
657 NETSIM_ID* anDevInterfaceIds;
658 }pstruMP2MP;
659 }puniDevList;
660 bool isLinkFailureMode;
662 {
663 LINK_STATE linkState;
664 unsigned int nLinkUpCount;
665 double* dLinkUPTime;
666 unsigned int nLinkDownCount;
667 double* dLinkDownTime;
668 int(*fnLinkFailureModelCallBack)(NETSIM_ID, LINK_STATE);
669 }struLinkFailureModel;
670 struct stru_NetSim_Links* pstruNextLink;
671 struct stru_NetSim_Links* pstruPreviousLink;
672};
673
674/*Stores the interface information of device*/
676{
677 NETSIM_ID nInterfaceId; //Interface id. Unique for each interface for a device.
678 NETSIM_ID nConfigInterfaceId;
679 INTERFACE_TYPE nInterfaceType; //Interface type
680 char* szInterfaceName;
681
682 //For virtual interface
683 NETSIM_ID nParentInterfaceId;
684 char* virtualInterfaceName;
685 bool isNwAddressChanged;
686 bool isMACChanged;
687 bool isPhyChanged;
688
689 NETWORK_LAYER_PROTOCOL nProtocolId; //IP protocol id
690 NETSIM_IPAddress szAddress; //IP address of the interface
691 NETSIM_IPAddress publicIP;
692 NETSIM_IPAddress szSubnetMask; //Subnet mask of the interface in case of IPV4
693 unsigned int prefix_len; //Prefix length in case of IPV6
694 NETSIM_IPAddress szDefaultGateWay; //Default gateway
695 void* ipVar;
696 void* interfaceVar; //Variable used to store the common interface variable.
697 NETWORK_LAYER_PROTOCOL nLocalNetworkProtocol;
698 void* localProtocolVar;
699 struct stru_NetSim_Access_Interface* pstruAccessInterface; //Network-MAC interface
700 struct stru_NetSim_MacLayer* pstruMACLayer; //MAC layer of interface
701 struct stru_NetSim_PhysicalLayer* pstruPhysicalLayer; //Physical layer of interface
702 struct stru_NetSim_Interface* pstruNextInterface;
703 struct stru_NetSim_Interface* pstruPrevInterface;
704};
705_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetInterfaceIdByName(NETSIM_ID nDeviceId, const char* szInterfaceName);
706
707#define SEED_COUNT 2
708/* Stores the device information in network*/
710{
711 NETSIM_ID nConfigDeviceId; //Device id setted in the config file
712 NETSIM_ID nDeviceId; //Unique id for all type of device. Auto assigned by backend.This is mapped to device name from front end
713 netsimDEVICE_TYPE nDeviceType; //Type of device
714 NETSIM_Name type;
715 NETSIM_Name szDeviceName; //Name of the device in GUI
716 NETSIM_ID nNumOfInterface; //Number of interface in device
717 unsigned long ulSeed[SEED_COUNT];//Unique seed
718 void* deviceVar; //Variable used to store to device specific variable. Common for all interface
719 struct stru_NetSim_Interface** ppstruInterfaceList; //Interface list
720 struct stru_NetSim_ApplicationLayer* pstruApplicationLayer;//Application layer of device
721 ptrSOCKETINTERFACE pstruSocketInterface; // Socket interface of device
722 struct stru_NetSim_TransportLayer* pstruTransportLayer; //Transport layer of device
723 struct stru_NetSim_NetworkLayer* pstruNetworkLayer; //Network layer of device
724 struct stru_NetSim_Coordinates* pstruDevicePosition; //Position of device in simulation workspace
725 struct stru_NetSim_Mobility* pstruDeviceMobility; //Mobility information of mobile device
726 WIRESHARK_OPTION wireshark_option;
727 PNODE_JOIN_PROFILE node_join_profile;
728 NODE_ACTION node_status;
729 struct stru_NetSim_Device* pstruNextDevice;
730 struct stru_NetSim_Device* pstruPrevDevice;
731};
732
733/* Store the Network structure*/
735{
736 UINT nDeviceCount; //Total number of device
737 UINT nLinkCount; //Total number of links in network
738 UINT nApplicationCount; //Total number of application running
739 struct stru_NetSim_Device** ppstruDeviceList; //List of all device in network
740 struct stru_NetSim_Links** ppstruNetSimLinks;
741 void** appInfo; //Information of application. Refer ../ApplicationDll/Application.h
742 struct stru_NetSim_SimulationParameter* pstruSimulationParameter;//Simulation parameter for end type and value
743};
744EXPORTED struct stru_NetSim_Network* NETWORK;
746{
747 unsigned long long int nEventId; //Unique id of event
748 double dEventTime; //Event time when packet is processed.
749 EVENT_TYPE nEventType; //Type of event
750 NETSIM_ID nProtocolId;
751 netsimDEVICE_TYPE nDeviceType; //Type of device
752 NETSIM_ID nDeviceId; //Unique id of device
753 NETSIM_ID nInterfaceId; //Unique id of interface
754 NETSIM_ID nApplicationId; //Unique id of application
755 double dPacketSize; //Packet size of current event
756 struct stru_NetSim_Packet *pPacket; //Packet for current event
757 long long int nPacketId; //Unique id for packet
758 int nSegmentId;
759 NETSIM_ID nSubEventType; //Sub event type
760 void* szOtherDetails; //Details specific to protocol.
761 unsigned long long int nPrevEventId;
762 int line;
763 char* file;
764 UINT64 executionTime;
765 bool isEmulatedEvent;
766};
767
768/* Stack API */
769
770/*MACROS*/
771#define DEVICE(DeviceId) NETWORK->ppstruDeviceList[DeviceId-1]
772 #ifdef DEVICE_TYPE
773 #undef DEVICE_TYPE
774 #endif
775#define DEVICE_TYPE(DeviceId) DEVICE(DeviceId)->nDeviceType
776#define DEVICE_NAME(DeviceId) DEVICE(DeviceId)->szDeviceName
777#define DEVICE_VAR(DeviceId) DEVICE(DeviceId)->deviceVar
778#define DEVICE_SEED0(DeviceId) &(DEVICE(DeviceId)->ulSeed[0])
779#define DEVICE_SEED1(DeviceId) &(DEVICE(DeviceId)->ulSeed[1])
780#define DEVICE_SEED(DeviceId) DEVICE_SEED0(DeviceId),DEVICE_SEED1(DeviceId)
781#define DEVICE_CONFIGID(DeviceId) DEVICE(DeviceId)->nConfigDeviceId
782#define DEVICE_INTERFACE(DeviceId,InterfaceId) DEVICE(DeviceId)->ppstruInterfaceList[InterfaceId-1]
783#define DEVICE_INTERFACE_CONFIGID(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->nConfigInterfaceId
784#define DEVICE_APPLAYER(DeviceId) DEVICE(DeviceId)->pstruApplicationLayer
785#define DEVICE_APPVAR(DeviceId,protocolId) (fn_NetSim_Stack_GetAppProtocolData(DeviceId,protocolId))
786#define DEVICE_TRXLayer(DeviceId) DEVICE(DeviceId)->pstruTransportLayer
787#define DEVICE_NWLAYER(DeviceId) DEVICE(DeviceId)->pstruNetworkLayer
788#define DEVICE_MACLAYER(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->pstruMACLayer
789#define DEVICE_MACPROTOCOL(DeviceId,InterfaceId) DEVICE_MACLAYER(DeviceId,InterfaceId)->nMacProtocolId
790#define DEVICE_PHYLAYER(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->pstruPhysicalLayer
791#define DEVICE_LINK(DeviceId,InterfaceId) (DEVICE_PHYLAYER(DeviceId,InterfaceId)->pstruNetSimLinks)
792#define DEVICE_POSITION(DeviceId) DEVICE(DeviceId)->pstruDevicePosition
793#define DEVICE_MOBILITY(DeviceId) DEVICE(DeviceId)->pstruDeviceMobility
794#define DEVICE_SOCKETINTERFACE(DeviceId) DEVICE(DeviceId)->pstruSocketInterface
795#define DEVICE_MAC_NW_INTERFACE(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->pstruAccessInterface
796#define DEVICE_ACCESSBUFFER(DeviceId,InterfaceId) DEVICE_MAC_NW_INTERFACE(DeviceId,InterfaceId)->pstruAccessBuffer
797#define DEVICE_MYACCESSBUFFER() DEVICE_ACCESSBUFFER(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)
798#define DEVICE_PHYMEDIUM(DeviceId,InterfaceId) DEVICE_PHYLAYER(DeviceId,InterfaceId)->nPhyMedium
799#define DEVICE_PHYVAR(DeviceId,InterfaceId) DEVICE_PHYLAYER(DeviceId,InterfaceId)->phyVar
800#define DEVICE_MACVAR(DeviceId,InterfaceId) DEVICE_MACLAYER(DeviceId,InterfaceId)->MacVar
801#define DEVICE_HWADDRESS(DeviceId,InterfaceId) DEVICE_MACLAYER(DeviceId,InterfaceId)->szMacAddress
802#define DEVICE_NWROUTINGVAR(DeviceId) DEVICE_NWLAYER(DeviceId)->RoutingVar
803#define IP_WRAPPER_GET(DeviceId) ((ptrIP_WRAPPER)(DEVICE_NWLAYER(DeviceId)->ipWrapper))
804#define IP_TABLE_GET(DeviceId) ((ptrIP_ROUTINGTABLE)(IP_WRAPPER_GET(DeviceId)->table))
805#define PIP_TABLE_GET(DeviceId) (&IP_TABLE_GET(DeviceId))
806#define DEVICE_NWPROTOCOL(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->nProtocolId
807#define DEVICE_NWADDRESS(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->szAddress
808#define DEVICE_MYIP() DEVICE_NWADDRESS(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)
809#define DEVICE_SUBNETMASK(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->szSubnetMask
810#define DEVICE_MYMASK() DEVICE_SUBNETMASK(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId)
811#define DEVICE_PUBLICIP(DeviceId,InterfaceId) DEVICE_INTERFACE(DeviceId,InterfaceId)->publicIP
812#define DEVICE_FIRST_PUBLICIP(DeviceId) DEVICE_PUBLICIP(DeviceId,1)
813#define DEVICE_TCPVAR(DeviceId) DEVICE_TRXLayer(DeviceId)->TCPProtocol
814#define DEVICE_UDPVAR(DeviceId) DEVICE_TRXLayer(DeviceId)->UDPProtocol
815#define DEVICE_APPINFO(DeviceId) DEVICE_APPLAYER(DeviceId)->pstruApplicationInfo
816#define DEVICE_DISTANCE(d1,d2) (fn_NetSim_Utilities_CalculateDistance(DEVICE_POSITION(d1), DEVICE_POSITION(d2)))
817/* Stack API end*/
818
819/*Event API*/
820#define EVENT_TYPE(EventDetails) (EventDetails)->nEventType
821#define EVENT_TIME(EventDetails) (EventDetails)->dEventTime
822#define EVENT_DEVICETYPE(EventDetails) (EventDetails)->nDeviceType
823#define EVENT_DEVICEID(EventDetails) (EventDetails)->nDeviceId
824#define EVENT_INTERFACEID(EventDetails) (EventDetails)->nInterfaceId
825#define EVENT_APPID(EventDetails) (EventDetails)->nApplicationId
826#define EVENT_PACKETSIZE(EventDetails) (EventDetails)->dPacketSize
827#define EVENT_PACKET(EventDetails) (EventDetails)->pPacket
828#define EVENT_PACKETID(EventDetails) (EventDetails)->nPacketId
829#define EVENT_SUBEVENTTYPE(EventDetails) (EventDetails)->nSubEventType
830#define EVENT_OTHERDETAILS(EventDetails) (EventDetails)->szOtherDetails
831/*Event API End*/
832
833//Simulation kernel api
834typedef unsigned long long int (*fn_NetSim_Utilities_AddEvent)(struct stru_NetSim_EventDetails*,int,const char*); /* Add an event to event list.*/
835_declspec(dllexport) int fnDeleteEvent(unsigned long long int nEventId);
836_declspec(dllexport) void set_thread_safe_kernel(bool status);
837
838/* Stack Variable declaration*/
839EXPORTED struct stru_NetSim_EventDetails* pstruEventDetails; //Stores the event details. Only one time memory is allocated. Most used variable
840EXPORTED double ldEventTime; //Stores the current event time
841EXPORTED EVENT_TYPE nEventType; //Stores the current event type
842EXPORTED char* pszAppPath; //Stores the application path
843
844EXPORTED char* pszIOPath; //Stores the I/O path
845EXPORTED char* pszIOLogPath;
846EXPORTED NETSIM_VERSIONTYPE nVersionType; //Stores the version type of netsim
847EXPORTED int nDbgFlag; //Stores the debug flag
848
849EXPORTED int wireshark_flag;
850
851#define NETSIM_RAND_MAX (double)10000000000
852
853_declspec(dllexport) bool isHost(NETSIM_ID d);
854_declspec(dllexport) bool isRouter(NETSIM_ID d);
855_declspec(dllexport) bool isL3Device(NETSIM_ID d);
856
857//Calculate distance
858_declspec(dllexport) double fn_NetSim_Utilities_CalculateDistance(NetSim_COORDINATES* coordinate1,NetSim_COORDINATES* coordinates2);
859//Random Number Generator
860_declspec(dllexport) double fn_NetSim_Utilities_GenerateRandomNo(unsigned long *uSeed, unsigned long *uSeed1);
861#define NETSIM_RAND() fn_NetSim_Utilities_GenerateRandomNo(DEVICE_SEED(1))
862#define NETSIM_RAND_01() (NETSIM_RAND()/NETSIM_RAND_MAX)
863#define NETSIM_RAND_RN(max,min) (min+NETSIM_RAND_01()*(max-min))
864
865//Con cat string
866_declspec(dllexport) int fn_NetSim_Utilities_ConcatString(int num,char* arg1,const char* arg2,...);
867
868
869//Used to generate number based on distribution.
870_declspec(dllexport) int fn_NetSim_Utils_Distribution(int nDistributionType, double *fDistOut,unsigned long *uSeed, unsigned long *uSeed1,double fFirstArg,double fSecondArg);
871
872//return the device id. This function take input as device name and return the device is of the device if found else return 0.
873_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetDeviceId_asName(const char* name);
874
875//Device Id by IP address. This function take input as IP address and return the device id and also update the interface id(passed as reference)
876_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetDeviceId_asIP(NETSIM_IPAddress ip,NETSIM_ID* nInterfaceId);
877
878//Device Id by Mac address. This function take the MAC address as input and return the device id and also update the interface id (Passed as reference)
879_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetDeviceId_asMac(PNETSIM_MACADDRESS mac,NETSIM_ID* nInterfaceId);
880
881//Wireless interface of a device. This function takes the link id and device id as input and return the interface id of wireless port if connected else return 0.
882_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetWirelessInterface(NETSIM_ID nLinkId,NETSIM_ID nDevId);
883
884//Used to get interface id from IP address of a device.
885_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetInterfaceIdFromIP(NETSIM_ID nDeviceId,NETSIM_IPAddress ip);
886
887//Used to get all interface id by running mac protocol. Caller must free return value.
888_declspec(dllexport) NETSIM_ID* fn_NetSim_Stack_GetInterfaceIdbyMacProtocol(NETSIM_ID devId,MAC_LAYER_PROTOCOL protocol,unsigned int* count);
889
890//Used to get all interface id by interface type. Caller must free return value.
891_declspec(dllexport) NETSIM_ID* fn_NetSim_Stack_GetInterfaceIdbyInterfaceType(NETSIM_ID devId,INTERFACE_TYPE ifType,unsigned int* count);
892
893/* Function used to get connection.
894 * Take four parameter
895 * 1. Device id
896 * 2. Interface id
897 * 3. pointer to connected device id
898 * 4. pointer to connected interface id
899 * return link id.
900 * Update connected device id and connected interface id.
901 * return 0 in case of no connection found.
902 */
903_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetConnectedDevice(NETSIM_ID nDeviceId,NETSIM_ID nInterfaceId,NETSIM_ID* nConnectedDevId,NETSIM_ID* nConnectedInterfaceId);
904_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetFirstConnectedDevice(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NETSIM_ID* nConnectedDevId, NETSIM_ID* nConnectedInterfaceId);
905
906// Find the connected device interface id
907_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetConnectedInterface(NETSIM_ID devId,NETSIM_ID ifid,NETSIM_ID conId);
908
909//Used to find the connected device interface id both ways. Return link id. Costly function to use if network size grows.
910_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetConnectedInterface_Both(NETSIM_ID d, NETSIM_ID r, NETSIM_ID* din, NETSIM_ID* rin);
911
912//Used to remove a device from link. Call only for P2MP or MP2MP link
913_declspec(dllexport) NetSim_LINKS* fn_NetSim_Stack_RemoveDeviceFromlink(NETSIM_ID nDeviceId,NETSIM_ID nInterfaceId,NETSIM_ID nLinkId);
914
915//Used to add a device to link. Call only for P2MP or MP2MP link
916_declspec(dllexport) NetSim_LINKS* fn_NetSim_Stack_AddDeviceTolink(NETSIM_ID nDeviceId,NETSIM_ID nInterfaceId,NETSIM_ID nLinkId);
917
918//Used to get the MAC protocol running on interface of a device
919_declspec(dllexport) MAC_LAYER_PROTOCOL fn_NetSim_Stack_GetMacProtocol(NETSIM_ID nDeviceId,NETSIM_ID nInterfaceId);
920//Used to get Network layer protocol running on the device
921_declspec(dllexport) NETWORK_LAYER_PROTOCOL fn_NetSim_Stack_GetNWProtocol(NETSIM_ID nDeviceId);
922//Used to get network layer routing protocol running on device
923_declspec(dllexport) NETWORK_LAYER_PROTOCOL fn_NetSim_Stack_GetNWRoutingProtocol(NETSIM_ID nDeviceId);
924
925/* Configuration API*/
926//Used to get an attributes value from an xml tag
927_declspec (dllexport) char* fn_NetSim_xmlConfig_GetVal(void* xmlNetSimNode,const char* szName,int flag);
928//Used to configure packet trace field
929_declspec (dllexport) char* fn_NetSim_xmlConfigPacketTraceField(const void* xmlNetSimNode,const char* name);
930//Used to write error log in config log file
931_declspec(dllexport) int NetSimxmlError(const char* msg, char* val, const void* xmlNetSimNode);
932
933//Used to get child node of any node
934_declspec(dllexport) void* fn_NetSim_xmlGetChildElement(void* xmlNetSimNode,const char* childName,int count);
935#define fn_NetSim_xmlGetFirstChildElement(xmlNetSimNode,childName) fn_NetSim_xmlGetChildElement(xmlNetSimNode,childName,0)
936_declspec(dllexport) void* fn_NetSim_xmlGetNextChildElement(void* xmlNetSimNode, void* prevChild);
937
938//Used to iterate over child element
939_declspec(dllexport) void fn_NetSim_xmlIterateOverChildElement(void* xmlNetSimNode, const char* childName,
940 int(*fun)(void* childNode, int argc, char* argv[]),
941 int argc,
942 char* argv[]);
943//convert string link type to enum
944_declspec(dllexport) LINK_TYPE fn_NetSim_Config_GetLinkType(const char* value);
945//Covert string suppression model to enum
946_declspec(dllexport) SUPPRESSION_MODEL fn_NetSim_Config_GetSuppressionModel(char* model);
947//Convert string service type to enum
948_declspec(dllexport) SERVICE_TYPE fn_NetSim_Config_GetServiceType(char* type);
949//FConvert string device type to enum
950_declspec(dllexport) netsimDEVICE_TYPE fn_NetSim_Config_GetDeviceType(const char* type);
951//Convert the string distribution to enum
952_declspec(dllexport) DISTRIBUTION fn_NetSim_Config_GetDistribution(const char* szDistribution);
953//Convert the string interface type to enum
954_declspec(dllexport) INTERFACE_TYPE fn_NetSim_Config_GetInterfaceType(const char* value);
955//convert string protocol to enum
956_declspec(dllexport) int fn_NetSim_Config_GetProtocol(const char* value);
957//Convert string propagation model to enum
958_declspec(dllexport) PROPAGATION_MODEL fn_NetSim_Config_GetPropagationModel(char* model);
959_declspec(dllexport) PROP_MEDIUM fn_NetSim_Config_GetPropagationMedium(char* med);
960_declspec(dllexport) SHADOW_MODEL fn_NetSim_Config_GetShadowModel(char* model);
961_declspec(dllexport) FADING_MODEL fn_NetSim_Config_GetFadingModel(char* model);
962_declspec(dllexport) PATHLOSS_MODEL fn_NetSim_Config_GetPathLossModel(char* model);
963
964//Used to get the IP address from name and interface id
965_declspec(dllexport) NETSIM_IPAddress fn_NetSim_Stack_GetIPAddressByName(const NETSIM_Name szDeviceName,NETSIM_ID nInterfaceId);
966//Used to get the mac address from IP address
967_declspec(dllexport) PNETSIM_MACADDRESS fn_NetSim_Stack_GetMacAddressFromIP(const NETSIM_IPAddress szIPAddress);
968//used to get the IP address from MAC address
969_declspec(dllexport) NETSIM_IPAddress fn_NetSim_Stack_GetIPAddressFromMac(const PNETSIM_MACADDRESS szMacAddress);
970//Used to get the first configure interface ip address of a device
971_declspec(dllexport) NETSIM_IPAddress fn_NetSim_Stack_GetFirstIPAddressAsId(NETSIM_ID nDeviceId,unsigned int type);
972//used to get the ip address from device id and interface id
973_declspec(dllexport) NETSIM_IPAddress fn_NetSim_Stack_GetIPAddressAsId(NETSIM_ID nDeviceId,NETSIM_ID nInterfaceId);
974//Used to get the first configured interface ip address of a device
975_declspec(dllexport) NETSIM_IPAddress fn_NetSim_Stack_GetFirstIPAddressByName(const NETSIM_Name szDeviceName);
976//Used to get config id of link by back-end id of link
977_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetConfigIdOfLinkById(NETSIM_ID nLinkId);
978_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetLinkIdByConfigId(NETSIM_ID nLinkId);
979//Used to get config id of device by back-end id of device
980_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetConfigIdOfDeviceById(NETSIM_ID nDeviceId);
981// Used to get the device id from config id
982_declspec (dllexport) NETSIM_ID fn_NetSim_GetDeviceIdByConfigId(NETSIM_ID id);
983
984_declspec(dllexport) bool isIPForSameDevice(NETSIM_IPAddress ip, NETSIM_ID d);
985
986_declspec(dllexport) NETSIM_IPAddress get_ip_from_same_subnet(NETSIM_ID d, NETSIM_IPAddress ip);
987
988//Used to get Application by config id
989_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_GetApplicationIdByConfigId(NETSIM_ID id);
990//Used to get interface id by config id
991_declspec(dllexport) NETSIM_ID fn_NetSim_GetInterfaceIdByConfigId(NETSIM_ID devId,NETSIM_ID id);
992//Convert Connection medium string to enum
993_declspec(dllexport) PHYSICAL_LAYER_MEDIUM fn_NetSim_Cofig_GetConnectionMedium(char* medium);
994//Used to configure protocol
995_declspec(dllexport) int fn_NetSim_xmlConfigureProtocolProperty(void* xmlChildNode, NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, LAYER_TYPE nLayerType, UINT nProtocolId);
996_declspec(dllexport) bool fn_NetSim_Stack_isProtocolConfigured(NETSIM_ID d,
997 LAYER_TYPE layer,
998 UINT protocol);
999/* Metrics */
1000#define fn_NetSim_Metrics_Add(packet) fn_NetSim_Metrics_Add_new(packet,__LINE__,__FILE__,__FUNCTION__)
1001_declspec(dllexport) void fn_NetSim_Metrics_Add_new(const NetSim_PACKET* pPacket, int line, char* file, char* function);
1002
1003#define DEFAULT_MAC_FRAGMENT_SIZE 1500 //Bytes
1004#define DEFAULT_TRX_MSS 1472 //Bytes
1005#define DEFAULT_NW_LAYER_SIZE 1480 //Bytes
1006_declspec(dllexport) double fn_NetSim_Stack_GetMSS(const NetSim_PACKET* pPacket);
1007
1008//Interlayer communication function
1009//Register call back back when an ICMP error arrive
1010_declspec(dllexport) int fn_NetSim_Stack_RegisterICMPCallback(int (*fnCallBack)(NetSim_PACKET* errPacket,NETSIM_ID nDeviceId,unsigned int nICMPErr));
1011//Called by IP layer when an ICMP error arrives
1012_declspec(dllexport) int fn_NetSim_Stack_CallICMPErrorFun(NetSim_PACKET* packet,NETSIM_ID nDeviceId,unsigned int nICMPErr);
1013//Called by upper layer to get link quality from phy layer. Must be implemented by phy layer protocol
1014_declspec(dllexport) double fn_NetSim_stack_get_link_quality(NETSIM_ID trx, NETSIM_ID tri, NETSIM_ID rx, NETSIM_ID ri);
1015
1016//Function pointer called to resolve id to ip
1017typedef NETSIM_IPAddress (*fndns_query)(NETSIM_ID nDeviceId,NETSIM_ID id);
1018EXPORTED fndns_query fnDNS;
1019_declspec(dllexport) NETSIM_IPAddress DNS_QUERY(NETSIM_ID nDeviceId,NETSIM_ID id);
1020
1021//Callback function for mobility. Must include Mobility.lib
1022typedef int (*_fnMobilityCallBack)(NETSIM_ID nDeviceId);
1023_declspec(dllexport) int fnMobilityRegisterCallBackFunction(_fnMobilityCallBack fnCallBack);
1024
1025//Callback function for node join. Must include Mobility.lib
1026typedef int (*_fnNodeJoinCallBack)(NETSIM_ID nDeviceId,double time,NODE_ACTION);
1027_declspec(dllexport) int fnNodeJoinRegisterCallBackFunction(_fnNodeJoinCallBack fnCallBack);
1028
1029//Xml configuration automatic reading
1030typedef enum xmlDataType
1031{
1032 _INT = 1,
1033 _DOUBLE,
1034 _FLOAT,
1035 _STRING,
1036 _BOOL,
1037 _CHAR,
1038 _SHORT,
1039 _UINT,
1040 _UCHAR,
1041 _USHORT,
1042 _UINT8,
1043 _UINT16,
1044 _RATIO, //Double in form of a/b
1045 _SPECIALBOOL, // Enable = true, Disable = false
1046}XMLDATATYPE;
1047_declspec(dllexport) int GetXmlVal(void* var,const char* name,void* xmlNode,int flag, XMLDATATYPE type);
1048#define getXmlVar(var,name,xmlNode,flag,type,protocol) if(!GetXmlVal(var,#name,xmlNode,flag,type)) *(var)= protocol##_##name##_DEFAULT
1049
1050//Default config property reader
1051
1052/**
1053Used to read freqency and bandwidth.
1054/param: XmlNode
1055/Param: name of variable in config file except units. Config file name must be <NAME>_<UNIT>
1056/Param: default value. Units must be same as return units
1057/Param: return unit type. Valid units are- GHz, MHz, kHz,Hz
1058*/
1059_declspec(dllexport) double fn_NetSim_Config_read_Frequency(void* xmlNetSimNode,
1060 const char* name,
1061 double defaultval,
1062 const char* returnUnit);
1063
1064/**
1065Used to read data rate.
1066/param: XmlNode
1067/Param: name of variable in config file except units. Config file name must be <NAME>_<UNIT>
1068/Param: default value. Units must be same as return units
1069/Param: return unit type. Valid units are- gbps,mbps,kbps,bps
1070*/
1071_declspec(dllexport) double fn_NetSim_Config_read_dataRate(void* xmlNetSimNode,
1072 const char* name,
1073 double defaultDataRate,
1074 const char* returnUnit);
1075
1076/**
1077Used to read data rate.
1078/param: XmlNode
1079/Param: name of variable in config file except units. Config file name must be <NAME>_<UNIT>
1080/Param: default value. Units must be same as return units
1081/Param: return unit type. Valid units are- GB,MB,KB,B,bits
1082*/
1083_declspec(dllexport) double fn_NetSim_Config_read_dataLen(void* xmlNetSimNode,
1084 const char* name,
1085 double defaultDataLen,
1086 const char* returnUnit);
1087/**
1088Used to read transmitter power.
1089/param: XmlNode
1090/Param: name of variable in config file except units. Config file name must be <NAME>_<UNIT>
1091/Param: default value. Units must be same as return units
1092/Param: return unit type. Valid units are- mW,W,dBm,dB
1093*/
1094_declspec(dllexport) double fn_NetSim_Config_read_txPower(void* xmlNetSimNode,
1095 const char* name,
1096 double defaultTxPower,
1097 const char* returnUnit);
1098
1099/**
1100Used to read time/duration.
1101/param: XmlNode
1102/Param: name of variable in config file except units. Config file name must be <NAME>_<UNIT>
1103/Param: default value. Units must be same as return units
1104/Param: return unit type. Valid units are- Hr(hour),min(minute),sec(second),ms(millisecond),us(microsecond),ns(nanosecond)
1105*/
1106_declspec(dllexport) double fn_NetSim_Config_read_time(void* xmlNetSimNode,
1107 const char* name,
1108 double defaultTime,
1109 const char* returnUnit);
1110
1111_declspec(dllexport) int fn_NetSim_Config_ConvertStrToEnum(void* xmlNode, const char* attributeName, const char** enumstr, const char* enumName, int length, bool isErrorMsg);
1112#define ConfigReadEnum(xmlNode,attriName,enumName,isErrorMsg) fn_NetSim_Config_ConvertStrToEnum(xmlNode,attriName,(const char**)str ## enumName, #enumName, sizeof(str ## enumName)/sizeof(str ## enumName ## [0]), isErrorMsg)
1113
1114//Mac address API
1115_declspec(dllexport) PNETSIM_MACADDRESS STR_TO_MAC(char* mac);
1116_declspec(dllexport) char* MAC_TO_STR(PNETSIM_MACADDRESS mac);
1117_declspec(dllexport) PNETSIM_MACADDRESS MAC_COPY(PNETSIM_MACADDRESS mac);
1118_declspec(dllexport) int MAC_COMPARE(PNETSIM_MACADDRESS mac1, PNETSIM_MACADDRESS mac2);
1119_declspec(dllexport) void MAC_FREE(PNETSIM_MACADDRESS mac);
1120_declspec(dllexport) void MAC_FREE_ALL();
1121_declspec(dllexport) PNETSIM_MACADDRESS multicastIP_to_Mac(NETSIM_IPAddress multicastIP);
1122_declspec(dllexport) bool isBroadcastMAC(PNETSIM_MACADDRESS mac);
1123_declspec(dllexport) bool isMulticastMAC(PNETSIM_MACADDRESS mac);
1124
1125//Stack Utility
1126_declspec(dllexport) void sim_time_to_string(double time, char* strTime/*Min 256 char*/);
1127
1128//Emulation
1129_declspec(dllexport) void set_emulation(bool isCustom,
1130 int(*load_emulation)(void* emuInterface));
1131
1132// Interface state
1133typedef int(*fun)(NETSIM_ID, NETSIM_ID, bool);
1134_declspec(dllexport) void register_interface_state_change(NETSIM_ID d,
1135 NETSIM_ID in,
1136 fun foo);
1137_declspec(dllexport) void notify_interface_up(NETSIM_ID d, NETSIM_ID in);
1138_declspec(dllexport) void notify_interface_down(NETSIM_ID d, NETSIM_ID in);
1139
1140//Link failure model
1141_declspec(dllexport) int fn_NetSim_Link_RegisterLinkFailureCallback(NETSIM_ID linkId,
1142 int(*fnLinkCallBack)(NETSIM_ID, LINK_STATE));
1143
1144//Fast emulation
1145_declspec(dllexport) bool isFastEmulation();
1146
1147//Virtual Interface
1148_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_CreateVirtualInterface(NETSIM_ID deviceId, NETSIM_ID parentInterfaceId,
1149 char* virtualInterfaceName,
1150 bool isNwChanged, bool isMacChanged, bool isPhyChanged);
1151_declspec(dllexport) NETSIM_ID fn_NetSim_Stack_FindVirtualInterface(NETSIM_ID d, NETSIM_ID parentIf, char* name);
1152_declspec(dllexport) bool isVirtualInterface(NETSIM_ID d, NETSIM_ID in);
1153
1154//Progress report
1155_declspec(dllexport) void netsim_pause_progress();
1156_declspec(dllexport) void netsim_resume_progress();
1157
1158//Timer
1159_declspec(dllexport) UINT64 start_timer(NETSIM_ID d, NETSIM_ID in, UINT eventId, double time, void* data);
1160_declspec(dllexport) void cancel_timer(UINT64 eventId);
1161#ifdef __cplusplus
1162}
1163#endif
1164#endif //_NETSIM_STACK_H_