Applicable Versions | NetSim Standard | NetSim Pro |
Applicable Releases | v11.1 | V12 |
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.
This function will return the string to write packet trace heading.
*/
_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 "";
}
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 "";
}
Adding RSSI to packet trace log file:
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-