Running NetSim via Command Line Interface (CLI)

NetSim provides options to run simulations via the GUI or via CLI. The CLI mode is preferred for automated execution (batch processing) of simulations. This feature is available from v7 onwards. In v7, NetSim can be run via CLI for Internetworks, Advanced Wireless Networks – MANET, Wireless Sensor Networks, Personal Area Networks and Cognitive Radio Networks only. For other networks NetSim v7 can only be run via GUI

Prior to running NetSim through command line interface (CLI), users must understand the following –
Step 1: App Path
App path is the file location in the system in which the NetSim7.0 has been installed.
The app path can be found out by right clicking the NetSim Shortcut in the desktop and selecting Open file location (In Vista and Windows 7) or Find Target (In Windows XP). The app path will be something like “C:\Program Files\NetSim Standard\bin”, depending on where NetSim is installed. The path to the bin folder of NetSim is termed as the app path.
Step 2: IO Path
IO path (Input/output Path) is the path where the input and output files of an application is
written. This is similar to the temp path of windows OS. For NetSim, the iopath is
%temp%/NetSim.  The Configuration.xml file for the scenrio to be simulated should be kept here prior to running the simulation. Note that the IO path must have write permission.
Step 3: Running NetSim through command line for Simulation
To run NetSim through command line, copy the app path where NetSimCore.exe is present and paste it in the command prompt. For floating/roaming licenses, type the following in the command prompt

>NetSimCore.exe<space> -apppath<space><app path><space>-iopath<space><io path><space> -license<space>5053@<Server IP Address>

Where,
<app path> contains all files of NetSim including NetSimCore.exe
<iopath> contains Configuration.xml and Configuration.xsd file
5053 is the port number through which the system communicates with the license server i.e  the system in which the dongle is running (for floating license users)
<Server IP Address> is the IP address of the system where NetSim license server (dongle) is running.

Sample configuration.xml files are available for Internetworks and Cognitive Radio Networks in the <apppath>/Docs/Sample_Configurations folder of the NetSim install directory. Rename the sample file as “Configuration.xml” before running NetSim through CLI. Depending on your system setting, the extension (.xml) might be implicitly present and not visible. In such cases do not add the extension, as that will cause the file to be named as configuration.xml.xml.

For node-locked licenses, type the following in the command prompt

>NetSimCore.exe<space> -apppath<space><app path><space>-iopath<space><io path><space>

Once Simulation is completed successfully and the metircs files that are requested by the end user in Configuration.xml will be written in the iopath. If any of the folder names contains white space, then mention the folder path within double quotes while specifying the folder name in the command prompt.

To know more about the options that are available to run NetSim via CLI, type the following in the command prompt.
>cd <app path>
>NetSimCore.exe -h

Adding Metric Variables in NetSim

There are two ways for you to get new Metrics in NetSim.

Option 1 (Easy): To get a “derived metric” from the existing NetSim output variables, then enable the packet trace & event trace and save them as XL files. Then use the XL UI or write VB scripts to get your derived metrics.

Option 2 (Hard): To get a completely new metric code will need to added in NetSim. An example is given below where new metrics have been added for LEACH (a new modification on the original DSR and code is available in a earlier blog entry) code,

Data_Packet_Received_PL is a new variable that has been defined in 802.15.4.h

#else

_declspec(dllimport) POWER** pstruDevicePower;

//For LEACH/Data Metrics
// Array size is 101 since maximum number of sensors is 100 and 1 for sink

_declspec(dllimport) int Data_Packet_Sent_NWL[101] ;
_declspec(dllimport) int Data_Packet_Received_NWL[10] ;
_declspec(dllimport) int Data_Packet_Sent_PL[101] ;
_declspec(dllimport) int Data_Packet_Received_PL[101] ;
_declspec(dllimport) double Lifetime[101];
#endif

This is used in packetprocessing.c in the section

#ifdef _LEACH
fn_NetSim_LEACH_GetNextHop(pstruEventDetails);
if(pstruEventDetails->nDeviceId == pstruEventDetails->pPacket->nSourceId)
Data_Packet_Sent_NWL[pstruEventDetails->nDeviceId-1] += 1;
return 1;
#endif
#ifdef _LEACH

This variable after having been updated during the simulation in the section above, is finally printed in DSR.c as shown below

_declspec(dllexport) int fn_NetSim_DSR_Metrics(char* filename)
{
//This #ifdef…..#endif block defines the LEACH Metrics, which shows the packets
//sent and received by the Network Layer and the Physicaal Layer
//To enable LEACH, uncomment the line “#define _LEACH” in DSR.h
#ifdef _LEACH
FILE* fp;
int i;
fp=fopen(filename,”a+”);
fprintf(fp,”#LEACH Metrics\n”);
fprintf(fp,”DeviceID\tData Sent(Network Layer)\tData Sent(Physical Layer)\tData Received(Network Layer)\tData Received(Physical Layer)\tLifetime(sec)\n”);
for(i=0; i<NETWORK->nDeviceCount; i++)
{
fprintf(fp,”%d\t%d\t%d\t%d\t%d\t%f\n”,NETWORK->ppstruDeviceList[i]->nDeviceId,Data_Packet_Sent_NWL[NETWORK->ppstruDeviceList[i]->nDeviceId-1],Data_Packet_Sent_PL[NETWORK->ppstruDeviceList[i]->nDeviceId-1],Data_Packet_Received_NWL[NETWORK->ppstruDeviceList[i]->nDeviceId-1],Data_Packet_Received_PL[NETWORK->ppstruDeviceList[i]->nDeviceId-1],Lifetime[NETWORK->ppstruDeviceList[i]->nDeviceId-1]/1000000);
}
fclose(fp);
#endif
return fn_NetSim_DSR_Metrics_F(filename);
}

If you face difficulty debugging code, please read the section in NetSim Help “Debugging when running NetSim via CLI (Only for Internetworks, Cognitive Radio
networks, MANET, Wireless Sensor Networks and Personal Area Network)”. Also ensure you are running as Visual studio in the administrator mode