Accessing protocol metrics when writing custom code in NetSim

Given below is a brief example of how users can access NetSim protocol / device metrics when writing custom code. This example is based on DSR protocol in NetSim v7.1

The various DSR metrics are available in the DSR.h file, under the following structures –

struct stru_DSR_DeviceVar
{
unsigned int nRREQIdentification;
struct stru_DSR_RouteCache* pstruRouteCache;
struct stru_DSR_SendBuffer* pstruSendBuffer;
struct stru_DSR_RouteRequestTable* pstruRREQTable;
enum
{
LINK_LAYER_ACK,
NETWORK_LAYER_ACK,
}AckType;
DSR_MAINT_BUFFER* pstruMaintBuffer;
struct stru_DSR_Metrics dsrMetrics;   // This structure is defined below
};

struct stru_DSR_Metrics
{
unsigned int rreqSent;
unsigned int rreqForwarded;
unsigned int rrepSent;
unsigned int rrepForwarded;
unsigned int rerrSent;
unsigned int rerrForwarded;
unsigned int routeBreak;
unsigned int packetTransmitted;
unsigned int packetOrginated;
unsigned int packetReceived;
unsigned int packetDropped;
};

These have been type def’ed for ease of use and you can add the following code in DSR.c in fn_NetSim_DSR_Run() to get packets received

// CODE TO BE ADDED

DSR_DEVICE_VAR* device1 =  DSR_DEV_VAR(1)

/* Enter the device ID whose metrics you need. The ID of present device being executed can be got by pstruEventDetails>nDeviceID */

printf(“%d”,device1->dsrMetrics.packetReceived);

/* Similarly you can access different metrics for each of the devices */

// END OF CODE

Note that

printf(“%d\n”,devVar1->dsrMetrics.rreqSent);  //  Writes to log file available in the I/O path where the configuration file is present

fprintf(stderr,”%d\n”,devVar1->dsrMetrics.rreqSent); // Writes to command prompt.