Applicable VersionsNetSim Standard NetSim Pro  


Applicable Releasesv11.1V12


NetSim Packet Trace log file provides abundant information about each packet as it flows through the network. Users can add extra columns to the packet trace log file to log additional information.


NetSim Standard and Professional versions come with the underlying C source codes of all the algorithms and protocols that are implemented. 


As you can see in the screenshot below, the source codes of each layer/protocol is available as a separate project containing the associated C and Header files.



Each project consists of a main C and Header file, for example TCP project will contain a TCP.c and TCP.h file as part of it.


In the main C file of any protocol source codes project, you will find the following functions which are related to the packet trace log file:


fn_NetSim_ConfigPacketTrace() - The heading of the new column can be added in this function.

fn_NetSim_WritePacketTrace() - The value for the column can be added in this function.


For example, TCP.c file will have the following functions:

fn_NetSim_TCP_ConfigPacketTrace()

fn_NetSim_TCP_WritePacketTrace()


Procedure to add a new column and value to the packet trace log file:


In this example we will consider RPL protocol, and see how we can add a new column which contains the RPL neighbor count of the source device.


In order to add a new column with information about the number of neighbors of a source node in NetSim's packet trace, the RPL.c file needs to be modified.

The heading of the new column needs can be added in the function fn_NetSim_RPL_ConfigPacketTrace() and 
The value for this column can be added using the function fn_NetSim_RPL_WritePacketTrace().

Modify both the functions as explained in the example below(changes are highlighted in red):


/**
This function will return the string to write packet trace heading.
*/
char pszTrace[BUFSIZ];
_declspec(dllexport) char* fn_NetSim_RPL_ConfigPacketTrace()
{
*pszTrace = 0;
strcat(pszTrace, "RPL_NEIGHBOUR_COUNT,");
//return "";
return pszTrace;

}

/**
This function will return the string to write packet trace.
*/
_declspec(dllexport) char* fn_NetSim_RPL_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace)
{
*pszTrace = 0;
*ppszTrace = calloc(BUFSIZ, sizeof(char));

PRPL_NODE rpl = GET_RPL_NODE(pstruPacket->nSourceId);
if(rpl)
sprintf(pszTrace, "%s%d,", pszTrace, rpl->neighbor_count);
else
sprintf(pszTrace, "%sN/A,", pszTrace);
strcpy(*ppszTrace, pszTrace);


return "";
}

Rebuild the source codes of RPL project. 

Upon successful build, running any IoT network simulation with RPL protocol and packet trace enabled will generate a packet trace log file with a new column RPL_NEIGHBOUR_COUNT as shown below:



The new column information added to the packet trace log file can also be viewed in the packet animation window as shown below:



Adding multiple columns to the packet trace log file:


Similar to the example discussed above, we will be modifying RPL project to add a column in addition to RPL_NEIGHBOUR_COUNT.


/**
This function will return the string to write packet trace heading.
*/
char pszTrace[BUFSIZ];
_declspec(dllexport) char* fn_NetSim_RPL_ConfigPacketTrace()
{
*pszTrace = 0;
//column 1 header
strcat(pszTrace, "RPL_NEIGHBOUR_COUNT,");
//column 2 header
strcat(pszTrace, "RPL_RANK,");
//return "";
 return pszTrace;

}

/**
This function will return the string to write packet trace.
*/
_declspec(dllexport) char* fn_NetSim_RPL_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace)
{
*pszTrace = 0;
*ppszTrace = calloc(BUFSIZ, sizeof(char));

 PRPL_NODE rpl = GET_RPL_NODE(pstruPacket->nSourceId);


//COLUMN 1 VALUE
if (rpl)
sprintf(pszTrace, "%s%d,", pszTrace, rpl->neighbor_count);
else
sprintf(pszTrace, "%sN/A,", pszTrace);
strcpy(*ppszTrace, pszTrace);

//COLUMN 2 VALUE
if (rpl)

{

if (rpl->joined_dodag != NULL)
{
PRPL_DODAG dodag = rpl->joined_dodag;
sprintf(pszTrace, "%s%d,", pszTrace, dodag->rank); // Source
 
Rak
 }

else

sprintf(pszTrace, "%sN/A,", pszTrace);

}
else
sprintf(pszTrace, "%sN/A,", pszTrace);
strcpy(*ppszTrace, pszTrace);

 return "";

}


Rebuild the source codes of RPL project. 

Upon successful build, running any IoT network simulation with RPL protocol and packet trace enabled will generate a packet trace log file with a new columns RPL_NEIGHBOUR_COUNT and RPL_RANK as shown below:



Adding RSSI to packet trace log file:


The API's GET_RX_POWER_dbm(tx, rx, time) and GET_RX_POWER_mw(tx,rx,time) which are defined in the 802.15.4.h file can be used to calculate RSSI.

To add this value to the packet trace log file, you can modify the functions fn_NetSim_Zigbee_ConfigPacketTrace() and fn_NetSim_Zigbee_WritePacketTrace() that are part of the 802.15.4.c file as explained in the above examples.


Related article:

how-to-obtain-a-log-of-rssi-sinr-and-ber-in-802-15-4-

how-to-implement-objective-function-zero-for-rpl-protocol-in-netsim-iot-

how-to-implement-objective-function-one-mrhof-for-rpl-protocol-in-netsim-iot-

how-ranks-are-distributed-in-rpl-implemented-on-netsim-

how-to-view-a-node’s-rank-parent-and-sibling-in-rpl-based-iot-simulations-