Adding Custom Performance Metrics

In Performance Metrics, users have the latitude of adding their own customized metric variables by editing the source code of the protocol of that specific networking technology. The following example provides a better understanding of how to implement it.

For illustration, an example regarding Wireless Sensor Network is provided. In this example, users will print Sensor Node Name, Residual Energy, State (On/Off) and turn–off time in the performance metrics

STEP 1: Copy the provided code at the top in 802_15_4.h file

include "string.h"

double NetSim_Residual_Energy[100];

string NetSim_Node_name[100];

double NetSim_Off_Time[100];

string NetSim_Node_state[100];

STEP 2:

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

_declspec(dllexport) int fn_NetSim_Zigbee_Metrics(char* szMetrics)

{

FILE* fp;

int i;

NETSIM_ID nDeviceCount = NETWORK->nDeviceCount;

fp=fopen(szMetrics,"a+");

fprintf (fp,"#Custom WSN Metrics\n");

fprintf (fp,"Node Name\tStatus\tTime\tResidual_Energy\n");

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

{

NetSim_Residual_Energy[i-1]=pstruDevicePower[i-1]->dRemainingPower;

fprintf(fp,"%s\t%s\t%lf\t%lf\n",NetSim_Node_name[i-1], NetSim_Node_state[i-1], NetSim_Off_Time[i-1], NetSim_Residual_Energy[i-1]);

}

fclose(fp);

return fn_NetSim_Zigbee_Metrics_F(szMetrics);

}

STEP 3:

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

if(nStatus)

{

WSN_PHY(nDeviceId)->nOldState = nOldState;

WSN_PHY(nDeviceId)->nRadioState = nNewState;

NetSim_Node_state[nDeviceId-1]= "ON"; NetSim_Node_name[nDeviceId-1]= NETWORK->ppstruDeviceList[nDeviceId-1]->szDeviceName;

return nStatus;

}

else

{

WSN_PHY(nDeviceId)->nRadioState = RX_OFF;

WSN_MAC(nDeviceId)->nNodeStatus = OFF;

NetSim_Off_Time[nDeviceId-1] = ldEventTime;

NetSim_Node_state[nDeviceId-1]= "OFF";

NetSim_Node_name[nDeviceId-1]= NETWORK->ppstruDeviceList[nDeviceId-1]->szDeviceName;

return nStatus;

}

STEP 4:

Build DLL with the modified code and run a Wireless Sensor Network scenario.

After Simulation, user will notice a new Performance metrics named “Custom WSN Metrics” is added.

results matching ""

    No results matching ""