NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
main.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* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14
15#ifndef main_header_
16#define main_header_
17#ifndef _CRT_SECURE_NO_DEPRECATE
18#define _CRT_SECURE_NO_DEPRECATE
19#endif
20#ifndef _CRT_SECURE_NO_WARNINGS
21#define _CRT_SECURE_NO_WARNINGS
22#endif
23#define _LICENSE_CHECK
24#pragma warning(disable:4459)
25#ifndef _DEBUG
26#pragma warning(disable:4100)
27#endif
28/* Macro definition for memory leak testing. Must use visual studio.*/
29# define _NETSIM_MEMORY_LEAK_TEST_ //Uncomment this line for memory leak testing
30# define _CRTDBG_MAP_ALLOC
31# include <stdio.h>
32# include <stdlib.h>
33# include <math.h>
34# include <string.h>
35# include <errno.h>
36# include <stdint.h>
37#include <stdbool.h>
38#include <direct.h>
39#include<malloc.h>
40#include<assert.h>
41#ifdef _WIN32
42#ifdef _DEBUG
43#include<crtdbg.h>
44#endif
45#include <windows.h>
46#include <conio.h>
47#include <process.h>
48#else
49#include <dlfcn.h>
50#include "Linux.h"
51#endif
52#ifndef _NETSIM_MAIN_H_
53#define _NETSIM_MAIN_H_
54#ifdef __cplusplus
55extern "C" {
56#endif
57 /*Global variable specific to OS -- Used for poratability*/
58#ifdef _WIN32
59# include <windows.h>
60#ifndef _MSC_VER
61#define _declspec(dllexport)
62#endif
63# define fnDlError(x,...) ReportError(false,x,__LINE__,__FILE__,1,__VA_ARGS__)
64#define fnSystemError(x,...) ReportError(false,x,__LINE__,__FILE__,1,__VA_ARGS__)
65# define fnNetSimError(x,...) ReportError(false,x,__LINE__,__FILE__,0,__VA_ARGS__)
66#define fnNetSimErrorandStop(x,...) ReportError(true,x,__LINE__,__FILE__,0,__VA_ARGS__)
67 static const char pathSeperator[] = "\\";
68 static const char libext[] = ".dll";
69#ifdef _cplusplus
70# define _declspec(dllexport) extern "C" _declspec(dllexport)
71#endif
72#else
73#include <dlfcn.h>
74#include<errno.h>
75# define HINSTANCE void*
76 static const char libext[] = ".so";
77#endif
78
79#pragma warning(disable:4471)
80
81#ifndef VERSION
82#define VERSION 144
83#endif
84
85#define __CALLBACK__ // Indication of callback function
86#define __IN__ // Indication of Input in function args
87#define __OUT__ // Indication of Output in function args
88
89#include "Memory.h"
90#include "IP_Addressing.h"
91
92#ifndef _NETSIM_IP_ADDRESSING_CODE_
93#pragma comment(lib,"IP_Addressing.lib")
94#endif
95
96 /* Typedef declaration of structure */
97 typedef struct stru_NetSim_SimulationParameter SIMULATIONPARAMETER;
98 typedef struct stru_NetSim_Device NetSim_DEVICE, * ptrNetSim_DEVICE;
99 typedef struct stru_NetSim_Interface NetSIm_DEVICEINTERFACE, * ptrNetSim_DEVICEINTERFACE;
100 typedef struct stru_NetSim_ApplicationLayer NetSim_APPLICATIONLAYER;
101 typedef struct stru_NetSim_SocketInterface NetSim_SOCKETINTERFACE;
102 typedef struct stru_NetSim_TransportLayer NetSim_TRANSPORTLAYER;
103 typedef struct stru_NetSim_Coordinates NetSim_COORDINATES;
104 typedef struct stru_NetSim_NetworkLayer NetSim_NETWORKLAYER;
105 typedef struct stru_NetSim_MAC_NW_Interface NetSim_MAC_NW_INTERFACE;
106 typedef struct stru_NetSim_MacLayer NetSim_MACLAYER;
107 typedef struct stru_NetSim_PhysicalLayer NetSim_PHYSICALLAYER;
108 typedef struct stru_ApplicationInformation NetSim_APPLICATIONINFO;
109 typedef struct stru_NetSim_Device_Buffer NetSim_BUFFER;
110 typedef struct stru_NetSim_Packet NetSim_PACKET;
111 typedef struct stru_NetSim_Packet_PhyLayer NetSim_PACKET_PHYLAYER;
112 typedef struct stru_NetSim_Packet_MACLayer NetSim_PACKET_MACLAYER;
113 typedef struct stru_NetSim_Packet_NetworkLayer NetSim_PACKET_NETWORKLAYER;
114 typedef struct stru_NetSim_Packet_TransportLayer NetSim_PACKET_TRANSPORTLAYER;
115 typedef struct stru_NetSim_Packet_AppLayer NetSim_PACKET_APPLAYER;
116 typedef struct stru_NetSim_EventDetails NetSim_EVENTDETAILS;
117 typedef struct stru_NetSim_Links NetSim_LINKS;
118
119 /* typedef for enumerator */
120 typedef enum enum_Distribution DISTRIBUTION;
121 typedef enum enum_PacketType PACKET_TYPE;
122 typedef enum enum_SuppressionModel SUPPRESSION_MODEL;
123 typedef enum enum_ServiceType SERVICE_TYPE;
124 typedef enum enum_PacketPriority PACKET_PRIORITY;
125 typedef enum enum_Packet_QOS QUALITY_OF_SERVICE;
126 typedef enum enum_PacketStatus PACKET_STATUS;
127 typedef enum enum_Segment PACKET_FRAGMENT;
128 typedef enum enum_EventType EVENT_TYPE;
129 typedef enum enum_AppProtocol APPLICATION_LAYER_PROTOCOL;
130 typedef enum enum_TrxProtocol TRANSPORT_LAYER_PROTOCOL;
131 typedef enum enum_NWProtocol NETWORK_LAYER_PROTOCOL;
132 typedef enum enum_MACProtocol MAC_LAYER_PROTOCOL;
133 typedef enum enum_PhyMedium PHYSICAL_LAYER_MEDIUM;
134 typedef enum enum_LayerType LAYER_TYPE;
135 typedef enum enum_InterfaceType INTERFACE_TYPE;
136 typedef enum enum_DeviceType netsimDEVICE_TYPE; //Because windows.h has already have the definition of DEVICE_TYPE
137 typedef enum enum_LinkType LINK_TYPE;
138 typedef enum enum_LinkMode LINK_MODE;
139 typedef enum enum_LinkState LINK_STATE;
140 typedef enum enum_SimulationEndType SIMULATION_END_TYPE;
141 typedef enum enum_SchedulingType SCHEDULING_TYPE;
142 typedef enum enum_TransmissionType TRANSMISSION_TYPE;
143 typedef enum enum_isConfigured ISCONFIGURED;
144 typedef enum emum_wireshark_option WIRESHARK_OPTION;
145
146 //typedef for netsim special variable type
147#ifndef NETSIM_ID
148 typedef unsigned int NETSIM_ID; //unique id
149#endif
150 typedef char* NETSIM_Name; //Unique name
151 typedef char* string;
152 typedef enum enum_Flag FLAG;
153
154 //Definition of version type
155 typedef enum
156 {
157 NETSIM_PRO = VERSION * 10 + 5,
158 NETSIM_STANDARD = VERSION * 10 + 4,
159 NETSIM_ACEDEMIC = VERSION * 10 + 3,
160 NETSIM_DEMO = VERSION * 10 + 2,
161 NETSIM_COMER = VERSION * 10 + 1,
162 }NETSIM_VERSIONTYPE;
163
164# include "Stack.h"
165# include "Packet.h"
166# include "MetricsWriter.h"
167#define fn_NetSim_LoadAppDllFunction(hsharedlib,path,sharedlibName,funName) fn_NetSim_LoadAppDllFunction_dbg(hsharedlib,path,sharedlibName,funName,__LINE__,__FILE__);
168 _declspec(dllexport) FARPROC fn_NetSim_LoadAppDllFunction_dbg(HINSTANCE* hdll, const char* path, const char* dllName, const char* funName, int line, char* file);
169
170# define fn_NetSim_Utilities_LoadSharedlibFunction(hsharedlib,sharedlibName,funName) fn_NetSim_Utilities_LoadSharedlibFunction_dbg(hsharedlib,sharedlibName,funName,__LINE__,__FILE__)
171 _declspec(dllexport) FARPROC fn_NetSim_Utilities_LoadSharedlibFunction_dbg(HINSTANCE* hsharedlib, const char* sharedlibName, const char* funName, int line, const char* file);
172
173 _declspec(dllexport) int ReportError(bool isStopOnError, const char* msg, int line, const char* file, int flag, ...);
174#pragma warning(disable:4213)
175#define fn_NetSim_Packet_FreePacket(pstruPacket) fn_NetSim_Packet_FreePacket_dbg(&(pstruPacket),__LINE__,__FILE__)
176
177#define fn_NetSim_Packet_AddPacketToList(pstruBuffer,pstruPacket,nInsertionType /* 1- head,2-Tail,3-Order of event time*/) fn_NetSim_Packet_AddPacketToList_dbg(pstruBuffer,pstruPacket,nInsertionType /* 1- head,2-Tail,3-Order of event time*/,__LINE__,__FILE__)
178 _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);
179
180#define fn_NetSim_Packet_CopyPacket(pstruPacket) fn_NetSim_Packet_CopyPacket_dbg(pstruPacket,__LINE__,__FILE__)
181
182#define fn_NetSim_Packet_CopyPacketList(pstruPacket) fn_NetSim_Packet_CopyPacketList_dbg(pstruPacket,__LINE__,__FILE__)
183
184#define fn_NetSim_Packet_CreatePacket(layer) fn_NetSim_Packet_CreatePacket_dbg(layer,__LINE__,__FILE__)
185
186#define fn_NetSim_WritePacketTrace(pstruPacket) fn_NetSim_WritePacketTrace_dbg(pstruPacket,__LINE__,__FILE__)
187
188#ifndef fnpAddEvent
189#define fnpAddEvent(pstruEvent) fnAddEvent_F(pstruEvent,__LINE__,__FILE__)
190#endif
191
192 _declspec(dllexport) unsigned long long int fnAddEvent_F(struct stru_NetSim_EventDetails* pstruEvent, int line, const char* file);
193
194 _declspec(dllexport) bool fn_NetSim_Stack_RegisterCallBackFunction(int nSubeventId, int (*_fnCallBack)());
195
196 _declspec(dllexport) int fn_NetSim_Anim_MoveNode(NETSIM_ID src, double x, double y, double time);
197
198#define ANSI_COLOR_RED "\x1b[31m"
199#define ANSI_COLOR_GREEN "\x1b[32m"
200#define ANSI_COLOR_YELLOW "\x1b[33m"
201#define ANSI_COLOR_BLUE "\x1b[34m"
202#define ANSI_COLOR_MAGENTA "\x1b[35m"
203#define ANSI_COLOR_CYAN "\x1b[36m"
204#define ANSI_COLOR_RESET "\x1b[0m"
205
206#define ANSI_BOLD_TEXT "\x1b[1m"
207
208 _declspec(dllexport) bool CHECK_FOR_USER_DLL(const char* dllName);
209
210#ifdef _WIN32
211#ifndef _NETSIM_CODE_
212#define printf(x,...) {printf("\n%s:%d: ",__FILE__,__LINE__);printf(x,__VA_ARGS__);}
213#endif
214#endif
215#endif
216
217#ifdef __cplusplus
218}
219#endif
220#endif //_NETSIM_MAIN_H_