Advanced Features

Random Number Generator and Seed Values

NetSim includes protocol and traffic models which include stochastic behavior. Typical examples are a) Wi-Fi node’s random back-off after collisions, and b) packet error decision by comparing a random number chosen between 0 and 1 against the packet error probability.

NetSim uses an in-built prime modulus combined with a linear congruential Random Number Generator (RNG) to generate the randomness. It is a single stream RNG with a period of \(\approx 2 \times 10^{18}\). Two seeds values are used to initialize the RNG. These seeds can be input from NetSim GUI or via the config file. Having the same set of seed values ensures that for a particular network configuration the same output results will be got, irrespective of the system or time at which the simulation is run. This ensures repeatability of experimentation.

Modifying the seed value will lead to the generation of a different stream of random numbers and thereby lead to a different sequence of events in NetSim. Therefore, all simulation results are dependent on the initial seeding of the RNG.

Confidence in simulation results and error bars

Since NetSim’s models include stochastic behavior, results are dependent on the initial seeding of the random number generator. Because a particular random seed selection can potentially result in an anomalous, or non-representative behavior, it is important for each model configuration to be exercised with several random number seeds, to be able to determine standard or typical behavior.

The field of statistics provides methods for calculating confidence in an estimate, based on a trial or series of random trials. To calculate confidence intervals, users can do the following:

  1. Run \(N\) simulations for the same model configuration, with a different initial seed (for the random number generator) for each run.

  2. For any output metric \(X\), calculate the mean (average) \(\overline{X}\) of the \(N\) samples.

\[\overline{X} = \frac{1}{N}\left( X_{1} + X_{2} + \ldots + X_{N} \right)\]
  1. Calculate the standard deviation \(\sigma\) of the \(N\) samples.

\[\sigma = \sqrt{\left( \frac{1}{N - 1} \right) \times \Sigma\ \left( X_{i} - \overline{X} \right)^{2}}\]
  1. Confidence interval limits can be expressed as

\[\Theta_{lower} = \overline{X} - z_{\alpha} \times \left( \frac{\sigma}{\sqrt{(N)}\ } \right),\ {\ \Theta}_{upper} = \overline{X} + z_{\alpha} \times \left( \frac{\sigma}{\sqrt{(N)}\ } \right)\]

This statement can be thought of as assigning a probability to the condition that the true mean \(\mu\) is within a particular distance of the random sample \(\overline{X}\), as shown below

\[Prob\ \left\lbrack \overline{X} - z_{\alpha} \times \left( \frac{\sigma}{\sqrt{(N)}\ } \right) < \mu < \ \overline{X} + z_{\alpha} \times \left( \frac{\sigma}{\sqrt{(N)}\ } \right) \right\rbrack = \alpha\]

Confidence level (\(\mathbf{\alpha)}\)

\[\mathbf{z}_{\mathbf{\alpha}}\]

99%

2.575

98%

2.327

95%

1.960

90%

1.645

80%

1.282

Table-1:Value of Z_α for different confidence intervals

  1. The above expression for confidence assumes the distribution of the output metric is Normal, which is true (from the Central Limit Theorem) if the number of runs N ≥ 30. If the number of repetitions is less than 30 then it is better to use the t-statistic based confidence-interval (details can be found in standard statistics textbooks).

Error bars are plotted as a vertical bar centered at the mean and ending at the upper and lower confidence limits

Interfacing MATLAB with NetSim (Std/Pro versions)

NetSim provides run-time interfacing with MATLAB so that users do not have to rewrite code in C for features that are already available in MATLAB and instead simply reuse MATLAB code. Lot of work related to machine learning, artificial intelligence and specialized mathematical algorithms which can be used for networking research, can be carried out using existing MATLAB code.

_images/Figure-1.png

Figure-1: Interfacing MATLAB with NetSim

This interfacing feature can be used to either replace an existing functionality in NetSim or to incorporate additional functionalities supported by MATLAB. Any existing command /function/algorithm in MATLAB or a MATLAB M-script can be used.

In general, the following are done when a user interfaces NetSim to MATLAB:

  • Initialize a MATLAB engine process in parallel with NetSim,

  • Execute MATLAB workspace commands,

  • Pass parameters to MATLAB workspace,

  • Read parameters from MATLAB workspace,

  • Generate dynamic three-dimensional plots,

  • Make calls to functions that are part of MATLAB M-scripts or .m files, and

  • Terminate the MATLAB engine process at NetSim simulation end.

Guidelines to interface NetSim with MATLAB

  • Analyze what parameters the function or code in MATLAB expects as input.

  • Identify the relevant variables in NetSim to be passed as input to MATLAB.

  • Make calls from relevant places of NetSim source code to

  • Pass parameters from NetSim to MATLAB.

  • To read computed parameters from MATLAB workspace

  • Identify and update the appropriate simulation variables in NetSim.

NetSim offers Socket interfacing to interact with MATLAB during runtime.

The socket interface that offers simplified NetSim API’s that can be used for interactions with MATLAB. The steps are lot simpler since no additional settings will be required in the source code project settings.

NetSim-MATLAB Socket Interface

NetSim-MATLAB Socket Interface was introduced in NetSim v14.0. It provides several inbuilt APIs that can be called from the underlying protocol C source codes to interact with MATLAB. Following is some of the APIs with syntax and description:

NetSim API’s to interact with MATLAB

Description

netsim_matlab_interface_configure(char* appPath)

Starts a MATLAB engine process and adds the appPath to the top of the search path for current MATLAB session.

netsim_matlab_interface_close();

Sends exit command to MATLAB to terminate the session.

netsim_matlab_send_ascii_command(char* format, ...)

Sends commands, variables and values as string to MATLAB.

netsim_matlab_get_value(char* out, int outLen, char* name, char* type)

Gets the value of a MATLAB variable as a string. Currently supports double data type only.

ptrMXArray netsim_matlab_get_array(char* name)

This function retrieves a MATLAB matrix containing double-precision values specified by the variable name. It returns a pointer to an mxArray structure (ptrMXArray) with the following components:

arr: A flat array containing all entries of the MATLAB matrix, irrespective of its dimensions.

dimn: An array specifying the dimensions of the MATLAB matrix.

shape: An array containing the size of each dimension.

netsim_matlab_send_array

void netsim_matlab_send_array(double* arr, size_t* shape, size_t dimn, char* name)

This function sends a C array of double-precision values to MATLAB and creates an equivalent variable in MATLAB. It takes the following arguments:

arr: The pointer to the C double type array.

shape: An array representing the size of each dimension.

dimn: The dimension of the array.

name: The name of the equivalent MATLAB variable.

Table-2: MATLAB Engine API functions

These functions are defined as part of the NetSim_utility.h file which is part of the Include directory of NetSim Source Codes. This header can be included in the C files where these APIs are to be called from.

Prerequisites for MATLAB Socket Interfacing

  • An installed version of MATLAB R2023(b) or lower version in the same system where NetSim is installed.

Note: Execute the below command in the command prompt where MATLAB_Interface.exe is placed followed by IP address of the system where the NetSim is installed.

_images/Figure-2.png

Figure-2: Command to start the MATLAB interface

  • Registration of MATLAB as a COM server by one of the following methods

    • Start Command Prompt as administrator and execute the following command:

matlab -regserver

Note: If you have multiple versions of MATLAB installed on your computer, the best practice is to run the matlab command from the matlab root folder.

  • Enter the following command in the command line of MATLAB version that you want to interface with NetSim:

matlab -regserver

Implement Weibull Distribution of MATLAB without using .m file

In this example we will replace the default Rayleigh Fading (part of the path loss calculation) used in NetSim, with a Fading Power calculated using the Weibull Distribution from MATLAB Socket Interfacing.

Procedure

  1. Open NetSim Source codes in Visual Studio by going to Your Work -> Open, Reset and Compare option -> Open Code, in the Home Screen of NetSim.

  2. In the Solution Explorer under IEEE802_11 project double click on the IEEE802_11.c file.

_images/Figure-3.png

Figure-3: Solution Explorer double click on the IEEE802_11.c file

  1. The NetSim_utility.h header file is included in IEEE802_11.c

_images/Figure-4.png

Figure-4: NetSim_utility.h file in IEEE802_11.c file

  1. Add a call to netsim_matlab_interface_configure() API, passing pszAppPath as an argument, inside the fn_NetSim_IEEE802_11_Init() function.

_images/Figure-5.png

Figure-5: Adding a call to netsim_matlab_interface_configure API inside the fn_NetSim_IEEE802_11_Init() function

  1. Similarly add a call to netsim_matlab_interface_close(); inside the fn_NetSim_IEEE802_11_

Finish() function.

_images/Figure-6.png

Figure-6: Adding a call to netsim_matlab_interface_close() API inside the fn_NetSim_IEEE802_11_Finish() function

  1. In the Solution Explorer under expand the Medium project and double click on the Medium.c file.

  2. Add a line in the beginning of the file to include the NetSim_utility.h header file.

_images/Figure-7.png

Figure-7: Including the NetSim_utility.h file in Medium.c file

  1. Define a new function static double matlab_calculate_fadingloss() above the existing static void medium_mark_packet_error(ptrPACKETINFO info) function.

static double matlab_calculate_fadingloss()

{

char buf[BUFSIZ];

double result;

int weibull_noncentrality = 1, weibull_scale = 2;

//use ProbDistUnivParam() function for matlab 2016 or lower

//sprintf_s(buf, BUFSIZ, "h=ProbDistUnivParam('weibull',[%d %d])",

//weibull_noncentrality, weibull_scale);//

//use makedist() function for matlab 2017 or Higher

sprintf_s(buf, BUFSIZ, "h=makedist('weibull',%d,%d)", weibull_noncentrality, weibull_scale);

netsim_matlab_send_ascii_command(buf);

sprintf_s(buf, BUFSIZ, "i=random(h)");//

netsim_matlab_send_ascii_command(buf);

netsim_matlab_get_value(buf, BUFSIZ, "i", "double");

result = atof(buf);

return result;

}

_images/Figure-8.png

Figure-8: Defining a new function matlab_calculate_facingloss() in the Medium.c file

  1. Inside medium_mark_packet_error() function comment the lines,

double f = _propagation_calculate_fadingloss(dm->propagationinfo_find(

info->txId, info->txIf,

info->rxId, info->rxIf));

  1. Make a call to the fn_netsim_matlab_run() function by adding the following line,

    double f = matlab_calculate_fadingloss();

_images/Figure-9.png

Figure-9: Call to the matlab_caculate_fadingloss() function

Note: In MATLAB Socket Interfacing, compilation of MATLAB Engine is not required since the MATLAB APIs are already called in function.

  1. Now rebuild the IEEE802_11 and Medium source code projects one after the other, by right clicking on the project and selecting Rebuild option.

  2. Upon successful build, NetSim automatically takes care of updating the binaries of IEEE802_11 and Medium source code projects which will be used for further simulations.

  3. Run NetSim in Administrative mode. Create a Network scenario involving IEEE802_11 say MANET, right click on the Adhoc link and select properties. Make sure that the Channel Characteristics is set to PathLoss and Fading and Shadowing. Perform the simulation.

_images/Figure-10.png

Figure-10: Wireless Link Properties Window in MANET

  1. If MATLAB is installed in the same system where NetSim is installed. MATLAB Interface process can be initiated directly from the design window of NetSim.

  • Go to “Options” in design window and select the Open MATLAB Interface option as shown below:

_images/Figure-11.png

Figure-11: Option to open MATLAB Interface

  • Click on the OK when the below window is displayed. This opens the MATLAB Session.

_images/Figure-12.png

Figure-12: NetSim MATLAB Interfacing warning message

  1. After clicking on “OK”, MATLAB interface will get initiated. MATLAB Command window will open as shown below

_images/Figure-13a.png
  1. Click on run simulation ,after which the simulation NetSim starts to simulate. During the simulation communication between MATLAB and NetSim will be established as shown below

_images/Figure-13.png

Figure-13: NetSim Simulation console for MATLAB Interface process to connect

  1. The dFading power value will be displayed in the MATLAB Console window as below. At simulation end the MATLAB Interface process will get terminated.

_images/Figure-14.png

Figure-14: Runtime MATLAB interfacing window with I value

Debug and understand communication between NetSim and MATLAB

  1. In the Solution Explorer under Medium project double click on Medium.c file and place a breakpoint inside the matlab_calculate_fadingloss() function before the return statement.

_images/Figure-15.png

Figure-15: Placing a breakpoint inside matlab_calculate_fadingloss() function

  1. Now run the NetSim Scenario. The simulation window stops for user interrupt.

  2. In Visual studio, go to Debug =>Attach to Process.

  3. From the list of Processes select NetSimCore.exe and click on Attach.

_images/Figure-16.png

Figure-16: Select NetSimCore.exe in Attach to Process Window

  1. Now go to the Simulation window and press Enter. Simulation will pause at Waiting for matlab interface to connect, go to Design window/GUI -> Options -> Open MATLAB interface ->click on OK

  2. MATLAB Command Window will start and breakpoint in Visual Studio gets triggered.

_images/Figure-17.png

Figure-17: Breakpoint getting triggered in Visual Studio.

  1. Now place another breakpoint after the line double f = matlab_calculate_fadingloss(); in the function medium_mark_packet_error() function and press continue or F5 key.

_images/Figure-18.png

Figure-18: Adding Breakpoint under in the medium_mark_packet_error() function

  1. Once the second breakpoint gets triggered, add the variable f which stores the fadingloss value, in Medium.c file, to watch. For this, right click on the variable f and select “Add Watch” option. You will find a watch window containing the variable name and its value in the bottom left corner.

_images/Figure-19.png

Figure-19: Right Clicking on the variable f and adding it to Watch

  1. Now when debugging (say by pressing F5 each time) you will find that the watch window displays the value of f whenever the control reaches the recently set breakpoint. You will also find that the value of f shown in the Visual Studio Watch window and the value of i in the MATLAB Console window are similar.

_images/Figure-20.png

Figure-20: The Visual Studio Watch window variable f and the value of i in the MATLABInterface window are similar

Implement Weibull Distribution of MATLAB in NetSim using .m file

Procedure:

  1. Create a file weibull_distribution.m file with the following code:

function out= weibull_distribution(noncentrality,scale)

%use ProbDistUnivParam() function for matlab 2016

%h=ProbDistUnivParam('weibull',[noncentrality,scale]);

%use makedist() function for matlab 2017

h=makedist('weibull',noncentrality,scale);

i=random(h,1);

out=i;

end

  1. Create matlab folder inside the bin_x64 directory of the current workspace

_images/Figure-21.png

Figure-21: Bin folder of x64 of current workspace

  1. Place the weibull_distribution.m file inside matlab folder.

_images/Figure-22.png

Figure-22: Place Weibull_distribution.m file inside matlab folder

  1. Modify the function static double matlab_calculate_fadingloss() that we previously created in the Medium.c file to call the newly created Weibull_distribution.m

static double matlab_calculate_fadingloss()

{

char buf[BUFSIZ];

double result;

int weibull_noncentrality = 1, weibull_scale = 2;

//use ProbDistUnivParam() function for matlab 2016 or lower

//sprintf_s(buf, BUFSIZ, "h=ProbDistUnivParam('weibull',[%d %d])",

//weibull_noncentrality, weibull_scale);//

//use makedist() function for matlab 2017 or Higher

sprintf_s(buf, BUFSIZ, "k=weibull_distribution(%d,%d)", weibull_noncentrality, weibull_scale);

netsim_matlab_send_ascii_command(buf);

netsim_matlab_get_value(buf, BUFSIZ, "k", "double");

netsim_matlab_send_ascii_command(buf);

result = atof(buf);

return result;

}

  1. Right click on the Medium source code project and select Rebuild.

  2. Proceed to run simulation as explained in the previous sections.

  3. You will find that once the Simulation is run MATLAB Command Window starts to execute and fadngloss value will be printed based on the call to weibull_distribution.m file.

_images/Figure-23.png

Figure-23: Runtime MATLAB interfacing window with k value

Interfacing Python with NetSim

What is a tail command?

The tail command is a command-line utility for outputting the last part of files given to it via standard input. It writes results to standard output. By default, tail returns the last ten lines of each file that it is given. It may also be used to follow a file in real-time and watch as new lines are written to it.

PART 1:

Tail options

  • The following command is used to log the file.

tail " path_to_file " -f

where -f option is used to watch a file for changes with the tail command pass the -f option. This will show the last ten lines of a file and will update when new lines are added. This is commonly used to watch log files in real-time. As new lines are written to the log the console will update will new lines.

  • If users do not want the last ten lines of the file, then use the following command.

tail -n 0 " path_to_file " –f

where –n option is used to show the last n number of lines.

  • If you want to open more than 1 file then use the following command

tail –n 0 " path_to_file " " path_to_file " –f

PART 2:

Steps to log NetSim files using tail console

Note: Before Executing below steps, User need to generate/Simulate a scenario of a network with specific network logs enabled to which tail command is being executed.

  • Open command window from Install directory path of Netsim (<C:Program FilesNetSimPro_v14_4bin) which contains tail.exe

  • Type the following command to open ospf_hello.log.txt file and press enter.

tail -n 0 “<NetSim_IOPath>logospf_hello.log” -f

For example,

tail -n 0 "C:UsersALICEAppDataLocalTempNetSimpro_14.4loglogospf_hello.log" -f

_images/Figure-24.png

Figure-24: Enter the ospf_hello.log.txt file path is Command Prompt

  • Open solution file and add the following line in fn_NetSim_OSPF_Init() function in ospf.c file present inside OSPF project

_images/Figure-25.png

Figure-25: Add the following line in fn_NetSim_OSPF_Init() function in ospf.c file present inside OSPF project

  • Rebuild the project.

  • Upon rebuilding, libOSPF.dll will get created in the bin folder of NetSim’s current workspace path <C:UsersPCDocumentsNetSimWorkspaces<Your default workspace>bin_x64 > for 64-bit

  • Create a scenario in NetSim as per the screenshot below and run simulation.

_images/Figure-26.png

Figure-26: Network Topology

  • In the console window user would get a warning message shown in the below screenshot Figure-27 (because of changed DLL) and then the simulation will pause for user input (because of _getch() added in the init function)

_images/Figure-27.png

Figure-27: Modified Project DLL Warning Message in NetSim Console

  • In Visual Studio, put break point inside all the functions in OSPF_Hello.c file present inside OSPF project.

  • Go to “Debug->Attach to Process” in Visual studio and attach to NetSimCore.exe.

  • Press enter in the command window. Then control goes to the project and stops at the break point in the source code as shown below Figure-28.

_images/Figure-28.png

Figure-28: Control goes to the project and stops at the break point in the source code.

  • Once after pressing enter in command window, check the tail console to watch the ospf_hello.log would look like the following screenshot Figure-29.

  • Below Screenshot shows that scheduling time of hello interval for each Routers connected in Network.

_images/Figure-29.png

Figure-29: Scheduling hello interval for Routers.

_images/Figure-30.png

Figure-30: Adding new neighbor and terminating process if it is 1-way event

  • Above Screenshot shows of adding neighbor to hello message, at Time 0.0101 ms, Router 5 interface 1 (11.4.1.2) received hello msg from neighbor 11.2.1.1.

_images/Figure-31.png

Figure-31: Adding Neighbor and Performing 2-way Event if neighbor is present in Router’s list.

Above Screenshot indicates the Router 2’s interface 1 (11.2.1.2) has received hello message from neighbor 11.2.1.1, if neighbor is present in Router’s list 2-way event will be performed.

  • Similarly, users can debug the code and observe how the OSPF tables get filled.

  • Users can also open multiple files by using the command given in Part 1.

Adding Custom Performance Metrics

NetSim allows users to add additional metrics tables to the Simulation Results window in addition to the default set of tables that are available at the end of any simulation. This can be achieved by editing the source codes of the respective protocol.

General format to add custom metrics in Result window:

Every protocol has a main C file which contains a Metrics () function. For E.g., TCP project will have a TCP.c file, UDP will have an UDP.c file etc. In the following example we have added a new table as part of TCP protocol. TCP.c file contains fn_NetSim_TCP_Metrics() function where code related to custom metrics is added as shown below:

_declspec(dllexport) int fn_NetSim_TCP_Metrics(PMETRICSWRITER metricsWriter)

{

//CUSTOM METRICS

//Set table name

PMETRICSNODE table = init_metrics_node(MetricsNode_Table, "CUSTOM METRICS", NULL);

//set table headers

add_table_heading(table, "COLUMN_HEADER_1", true, 0);

add_table_heading(table, "COLUMN_HEADER_2", false, 0);

//Add table data

add_table_row_formatted(false, table, "%s,%s,", "ROW_DATA1","ROW_DATA2");

PMETRICSNODE menu = init_metrics_node(MetricsNode_Menu,"CUSTOM_METRICS", NULL);

//Add table to menu

add_node_to_menu(menu, table);

//Write to Metrics file

write_metrics_node(metricsWriter, WriterPosition_Current, NULL, menu);

delete_metrics_node(menu);

//CUSTOM METRICS

return fn_NetSim_TCP_Metrics_F(metricsWriter);

}

_images/Figure-32.png

Figure-32: Added Custom metrics table to the Additional metrics window.

For illustration, an example regarding Wireless Sensor Network is provided. In this example, parameters such as Sensor Node Name, Residual Energy, State (On/Off) and turn–off time are tracked and added to a new table in the Simulation Results window.

Refer Section 9.1 on writing your own code, for more information.

After loading the source codes in Visual Studio, perform the following modifications:

Step 1: Copy the provided code at the top in 802_15_4.h file present in Zigbee project.

double NetSim_Off_Time[100]; //Supports upto Device ID 100. Array size can be increased for higher number of Devices/Device ID's

Step 2:

Add the header file in 802_15_4.c file.

#include "../BatteryModel/BatteryModel.h"

Step 3:

Copy the below code (in red colour) in 802_15_4.c file (inside fn_NetSim_Zigbee_Metrics() function)

/This function write the metrics in metrics.txt/

_declspec(dllexport) int fn_NetSim_Zigbee_Metrics(PMETRICSWRITERmetricsWriter)

{

//CUSTOM METRICS

ptrIEEE802_15_4_PHY_VAR phy;

ptrBATTERY battery;

char radiostate[BUFSIZ];

NETSIM_ID nDeviceCount = NETWORK->nDeviceCount;

//Set table name

PMETRICSNODE table = init_metrics_node(MetricsNode_Table, "NODE_FAILURE_METRICS", NULL);

//set table headers

add_table_heading(table, "Node Name", true, 0);

add_table_heading(table, "Status(ON/OFF)", true, 0);

add_table_heading(table, "Residual_Energy (mJ)", true, 0);

add_table_heading(table, "Time - Turned OFF (microseconds)", false, 0);

for (int i = 1; i <= nDeviceCount; i++)

{

sprintf(radiostate, "ON");

phy = WSN_PHY(i);

if (strcmp(DEVICE(i)->type, "SENSOR"))

continue;

if (WSN_MAC(i)->nNodeStatus == 5 || phy->nRadioState==RX_OFF)

sprintf(radiostate, "OFF");

//Add table data

if(phy->battery)

add_table_row_formatted(false, table, "%s,%s,%.2lf,%.2lf,", DEVICE_NAME(i), radiostate, battery_get_remaining_energy((ptrBATTERY)phy->battery), NetSim_Off_Time[i]);

}

PMETRICSNODE menu = init_metrics_node(MetricsNode_Menu, "CUSTOM_METRICS", NULL);

add_node_to_menu(menu, table);

write_metrics_node(metricsWriter, WriterPosition_Current, NULL, menu);

delete_metrics_node(menu);

//CUSTOM METRICS

return fn_NetSim_Zigbee_Metrics_F(metricsWriter);

}

Step 4:

Copy the below code (in red colour) at the end of ChangeRadioState.c file.

if(isChange)

{

phy->nOldState = nOldState;

phy->nRadioState = nNewState;

}

else

{

phy->nRadioState = RX_OFF;

WSN_MAC(nDeviceId)->nNodeStatus = OFF;

NetSim_Off_Time[nDeviceId] = ldEventTime;

}

return isChange;

}

Step 5:

Build DLL with the modified code and run a Wireless Sensor Network scenario by considering power source as battery model. After Simulation, user will notice a new Performance metrics named “Custom Metrics” is added. The newly added NODE_FAILURE_METRICS table is shown below Figure-33.

_images/Figure-33.png

Figure-33: Added Custom metrics table to the Additional metrics window.

Simulation Time and its relation to Real Time (Wall clock)

The notion of time in a simulation is not directly related to the actual time that it takes to run a simulation (as measured by a wall-clock or the computer's own clock), but is a variable maintained by the simulation program. NetSim uses a virtual clock which ticks virtual time. Virtual time starts from zero progresses as a positive real number.

Time is as a global parameter. All components of the network share the same time throughout the simulation independently of where they are physically located or how they are logically connected to the network. There are not differences among the local time of the communication network components.

This virtual time is referred to as simulation time to clearly distinguish it from real (wall-clock) time. NetSim is a discrete event simulator (DES), and in any DES, the progression of the model over simulation time is decomposed into individual events where change can take place. The flow of time is only between events and is not continuous. Therefore, simulation time is not allowed to progress during an event, but only between events. In fact, the simulation time is always equal to the time at which the current event occurs. Thus, simulation time can be viewed as a variable that "jumps" to track the time specified for each new event.

The answer to the question "Will NetSim run for 10 seconds if Simulation time is set to 10 sec?" is, the simulation may take more than 10 seconds (Wall clock) if the network scenario is very large and heavy traffic load. It may take a much shorter time (wall clock) for small networks with low traffic loads.

Note that when running in "Emulation mode" simulation time and wall clock will be exactly synchronized since it involves the transfer of real packets across the virtual network in NetSim.

In NetSim, the current simulation time can be got using -pstruEventDetails->dEventTime

Environment Variables in NetSim

  1. NETSIM_PACKET_FILTER = <filter_string> //used by NetSim developers to debug. Emulator code to passes filter string to windivert. See windivert doc for more information.

  2. NETSIM_EMULATOR_LOG = <log_file_path> // Used by Real time sync function to log get event and add event. Used by NetSim developers to debug.

  3. NETSIM_EMULATOR = 1 // Set by application DLL or user to notify NetSim internal modules to run in emulation mode

  4. NETSIM_CUSTOM_EMULATOR = 1 // To notify NetworkStack to not load emulation DLL and to only do time sync.

  5. NETSIM_SIM_AREA_X = <int> // Area used by Mobility functions for movement of device. Set by config file parser or user.

  6. NETSIM_SIM_AREA_Y = <int> // Same as above

  7. NETSIM_ERROR_MODE = 1 // if set then windows won't popup gui screen for error reporting on exception.

  8. NETSIM_BREAK = <int> // Event id at which simulation will break and wait for user input.

  9. Equivalent to -d command in CLI mode.

  10. NETSIM_IO_PATH = <path> // IO path of NetSim from where it will read Config file and write output file. Equivalent to -IOPATH command in CLI mode.

  11. NETSIM_MAP = 1 // Set by Networkstack to inform other modules that simulation is running per map view.

  12. NETSIM_ADVANCE_METRIC // If set, NetSim provides a set of extra metrics.

  13. In application metrics, you can see duplicate packets received.

  14. NETSIM_CONFIG_NAME = <FILE NAME> // Config file name. This file must present in IOPath. If not set default value is Configuration.netsim

  15. NETSIM_NEG_ID = 1 // If set, then control packets will have negative id.

  16. NETSIM_PACKET_DBG = 1 // If set, then Simulation engine will log the packet creation and freeing

  17. NETSIM_MEMCHECK = 1 // If set, then simulation will enable memory check.

  18. NETSIM_MEMCHECK_1 = x // Lower event id

  19. NETSIM_MEMCHECK_2 = x // Upper event id

Best practices for running large scale simulations

As we scale simulations, the number of events processed and the memory consumed increase. Simulation scale can be defined in terms of: 1. Number of Nodes

  • End nodes

  • Intermediate devices

  1. Total traffic in the network

  • Number of traffic sources

  • Average generation rate per source

  1. Simulation time

The simulators performance is additionally affected by:

  • Protocols running

  • Network Parameters such as Topology, Mobility, Wireless Channel etc.

  • Enabling/Disabling - Plots, Traces and Logs

  • External Interfacing – MATLAB, Wireshark, SUMO

NetSim GUI limitation on total number of Nodes is as follows:

  • NetSim Academic:

  • Intermediate devices: 20

  • End nodes: 100

  • NetSim Standard:

  • Intermediate devices: 100

  • End nodes: 500

  • NetSim Professional :

  • Intermediate devices: 500

  • End nodes: 2500

Recommended best practices for running large scale simulations are:

  • Run 64-bit Build of NetSim

  • Use the latest Windows 10 Build.

  • Use a system running a high-end processor with minimum 32 GB RAM

  • Disable plots, traces and logs to speed up the simulation.

  • NetSim writes one packet trace and one event trace file per simulation. If users wish to open this file in MS-Excel, please note Excel’s limit of 1 Million rows.

  • Packet trace and Event trace can be disabled to speed up the simulation.

  • Running simulations via CLI mode will save memory.

Batch experimentation and automated simulations

NetSim Batch Automation allows users to execute a series of simulations without manual intervention. Consider a requirement, where a user wishes to create and simulate hundreds of network scenarios and store and analyse the performance metrics of each simulation run. It is impossible to do this manually using the GUI. This requirement can be met using NetSim Batch Automation script which runs NetSim via CLI.

A related requirement of advanced simulation users is a multi-parameter sweep. When you sweep one or more parameters, you change their values between simulation runs, and compare and analyze the performance metrics from each run.

The documentation and codes for batch experimentation script is available TETCOS - https://www.tetcos.com/file-exchange.html