Applicable VersionsNetSim StandardNetSim Pro



Applicable Releases
v12v13


Code Modification

Follow the steps given below to obtain a log file containing the position of nodes along with timestamp: 


Step 1: Go to Your Work > Workspace Options > Open Code


Step 2: Open Mobility.c file in the Mobility project from the list of projects displayed in the Solution Explorer.


Step 3: Add the following lines at the beginning of the Mobility.c file 


FILE* fp;
int i = 0;
char dip[_NETSIM_IP_LEN];
char s[BUFSIZ];

Step 4: Go to fn_NetSim_Mobility_Init() function and add following lines into Mobility.c file: 


// Code modification for printing co-ordinates
sprintf(s, "%s\\%s", pszIOLogPath, "Node_Coordinates.csv");
FILE* fp = fopen(s, "w+");
if (fp)
{
fprintf(fp, "Device Id,IP Address,X(m),Y(m),Time (micro sec)\n");
fclose(fp);
}
//code modification ends here


Step 5: Go to fn_NetSim_Mobility_Run() function and perform the following modifications:

// Code modification for printing coordinates
fp = fopen(s, "a+");
i = pstruEventDetails->nDeviceId;
IP_TO_STR(fn_NetSim_Stack_GetFirstIPAddressAsId(i, 0), dip);
fprintf(fp, "%u,%s,%lf,%lf,%.2f\n", fn_NetSim_Stack_GetConfigIdOfDeviceById(i), dip,
NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDevicePosition->X,
NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDevicePosition->Y, pstruEventDetails->dEventTime);
fclose(fp);
// Code modification ends here

Step 6:  After performing the modifications, right-click on Mobility project and select Rebuild.


Step 7: Now create a NetSim scenario in MANET, Wireless Sensor Network, IoT, etc.

Step 8: Run the scenario

Step 9: Open Node_Coordinates.csv from Result Dashboard > Log > Node_Coordinates.csv

Node_Coordinates.csv file containing ID, IP address, X and Y Coordinates and time


 

Applicable Releases
v11.1 and older


 Follow the steps given below to obtain a log file containing the position of nodes by IP Address along with time stamp:

    1. Open NetSim.sln file from <NetSim Installation Directory>\src\Simulation  folder.

    2. Open Mobility.c file in the Mobility project from the list of projects displayed in the Solution Explorer.

    3. Go to fn_NetSim_Mobility_Run() function and perform the following modifications(lines shown in red):


_declspec(dllexport) int fn_NetSim_Mobility_Run()

{

.

.

.

.

.

.


else

{

add_mobility_animation(pstruEventDetails->nDeviceId,

pstruEventDetails->dEventTime,

NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDevicePosition->X,

NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDevicePosition->Y,

0);

}

//Add event for next point

pstruEventDetails->dEventTime += pstruMobilityVar->dCalculationInterval;

fnpAddEvent(pstruEventDetails);

pstruEventDetails->dEventTime -= pstruMobilityVar->dCalculationInterval;

}


fp = fopen("PrintDetails.txt", "a+");

i = pstruEventDetails->nDeviceId;

IP_TO_STR(fn_NetSim_Stack_GetFirstIPAddressAsId(i, 0), dip);

fprintf(fp, "%u\t\t\t%s\t%lf\t%lf\t\t%.2f\n", fn_NetSim_Stack_GetConfigIdOfDeviceById(i), dip,
NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDevicePosition->X,
NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId - 1]->pstruDevicePosition->Y,pstruEventDetails->dEventTime);

fclose(fp);


//call all the callback function

for(nLoop=0;nLoop<nCallBackCount;nLoop++)

{

fnMobilityCallBack[nLoop](pstruEventDetails->nDeviceId);

}

}

break;

}

return 1;

};


    4.Go to fn_NetSim_Mobility_Init() function and add following lines into Mobility.c file (highlighted in red):

_declspec(dllexport) int fn_NetSim_Mobility_Init(struct stru_NetSim_Network *NETWORK_Formal,
NetSim_EVENTDETAILS *pstruEventDetails_Formal,
char *pszAppPath_Formal,
char *pszWritePath_Formal,
int nVersion_Type,
void **fnPointer)
{
fp = fopen("PrintDetails.txt", "w+");
fprintf(fp, "Device Id \t\t IP Address \t X(m) \t\t Y(m) \t\t Time (micro sec)\n");
fclose(fp);

NETSIM_ID nLoop;
NETWORK = NETWORK_Formal;//Get the Network structure from NetworkStack
pstruEventDetails=pstruEventDetails_Formal;//Get the Eventdetails from NetworkStack
pszAppPath=pszAppPath_Formal;//Get the application path from NetworkStack
pszIOPath=pszWritePath_Formal;//Get the write path from NetworkStack
nVersion_Type = nVersion_Type; //Get the version type from NetworkStack


    5. Add the following lines at the beginning of Mobility.c file

FILE *fp;

int i=0;

char dip[_NETSIM_IP_LEN];


    6. After performing the modifications, right click on Mobility project and select Rebuild.

    7.Replace the newly built libMobility.dll in <NetSim Installation Directory>\bin folder after renaming the original libMobility.dll.

    8.Now create a NetSim scenario in MANET, Wireless Sensor Network, IoT etc.

    9.Run the scenario.


After simulation, a text will be created inside bin folder of NetSim i.e. PrintDetails.txt.



A sample Mobility.c file related to NetSim v10.2, which contains the modifications explained above is attached herewith.