#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
typedef struct
{
uint32_t ctrId;
char ctrName[40];
} ctrIdToStrMap_t;
char *exampleName;
static ctrIdToStrMap_t ctrIdToStr[] =
{
};
#define NUM_COUNTERS (sizeof(ctrIdToStr)/sizeof(ctrIdToStrMap_t))
void printInterfaceStatsAppMenu()
{
printf("\nUsage: %s <test#> <arg1> <arg2> ... \n\n", exampleName);
printf("Test 0: Display interface Name to Interface Number: %s 0 \n", exampleName);
printf("Test 1: Display interface counter through iterative individual counter fetch: %s 1 <ifNum> \n", exampleName);
printf("Test 2: Display interface counter through bulk fetch: %s 2 <ifNum>\n", exampleName);
printf("Test 3: Reset interface counter: %s 3 <ifNum> <counter>\n", exampleName);
printf("Test 4: Reset all counters on interface: %s 4 <ifNum>\n", exampleName);
printf("Test 5: Display time elapsed after interface counter reset: %s 5 <ifNum>\n", exampleName);
}
{
char *ctrArray = NULL;
char linkName[256];
uint32_t i;
uint32_t bufSize;
uint64_t *pCtr;
uint32_t maxCtrIdx;
uint64_t ctrValue;
printf("\n");
{
printf("Error obtaining counter buffer size (rc = %d)\n\n", result);
return;
}
ctrArray = (char *)malloc(bufSize);
if (NULL == ctrArray)
{
printf("Cannot allocate memory for counter collection buffer\n\n");
return;
}
memset(ctrArray, 0, bufSize);
{
printf("Error obtaining counters using bulk get method (rc = %d)\n", result);
free(ctrArray);
return;
}
memset(linkName, 0, sizeof(linkName));
bufd.pstart = linkName;
bufd.size = sizeof(linkName);
{
printf("Bulk statistics for interface %s:\n", linkName);
}
else
{
printf("Interface name retrieval error for ifNum %d\n\n", ifNum);
printf("Bulk statistics for ifNum %u\n", ifNum);
}
printf("\n");
pCtr = (uint64_t *)ctrArray;
maxCtrIdx = (uint32_t)*pCtr++;
for (i = 1; i < NUM_COUNTERS; i++)
{
if (i < maxCtrIdx)
{
ctrValue = *pCtr++;
}
else
{
ctrValue = 0;
}
printf("%-40s - 0x%016llx\n", ctrIdToStr[i].ctrName, ctrValue);
}
printf("\n");
free(ctrArray);
}
{
uint32_t i;
uint32_t ifNum;
char linkName[256];
open_buffdesc linkNameBuff = {.pstart = linkName, .size =
sizeof(linkName)};
printf(" Intf \n");
printf("ifNum Interface Name State \n");
printf("----- -------------------------------- ----- \n");
{
switch (i)
{
break;
break;
break;
break;
default:
continue;
}
{
do
{
printf("%5u ", ifNum);
memset(linkName, 0, sizeof(linkName));
linkNameBuff.size = sizeof(linkName);
printf("%-32s ", (char *)linkNameBuff.pstart);
else
printf("%-32s ", "link name retrieve error");
else
printf("%-5s ", "???");
printf("\n");
printf("\n");
}
}
}
{
char linkName[256] = {0};
open_buffdesc linkNameBuff = {.pstart = linkName, .size =
sizeof(linkName)};
open_buffdesc statValStrBuff = {.pstart = statValStr, .size =
sizeof(statValStr)};
uint64_t ctrValue;
uint32_t i;
printf("\n");
memset(linkName, 0, sizeof(linkName));
linkNameBuff.pstart = linkName;
linkNameBuff.size = sizeof(linkName);
printf("Displaying statistics of %s\n", (char *)linkNameBuff.pstart);
else
printf("link name retrieval error\n");
printf("\n");
for (i = 1; i < NUM_COUNTERS; i++)
{
ctrValue = -1;
rc =
openapiStatGet(clientHandle, ctrIdToStr[i].ctrId, ifNum, &ctrValue);
switch (rc)
{
printf("%-40s - 0x%016llx\n", ctrIdToStr[i].ctrName, ctrValue);
break;
printf("%-40s - Counter unavailable\n", ctrIdToStr[i].ctrName);
break;
default:
printf("%-40s - Counter get failed (rc = %d)\n", ctrIdToStr[i].ctrName, rc);
break;
}
memset(statValStr, 0, sizeof(statValStr));
statValStrBuff.size = sizeof(statValStr);
switch (rc)
{
printf("%-40s - %s\n", ctrIdToStr[i].ctrName, (char *)statValStrBuff.pstart);
break;
printf("%-40s - Counter unavailable\n", ctrIdToStr[i].ctrName);
break;
default:
printf("%-40s - Counter get failed (rc = %d)\n", ctrIdToStr[i].ctrName, rc);
break;
}
}
}
{
printf("Resetting %s on an interface.\n", ctrIdToStr[counter].ctrName);
{
printf("%s Statistics reset successfully on interface %d.\n",
ctrIdToStr[counter].ctrName, ifNum);
}
{
printf("Failed to reset %s statistics on interface %d.\n",
ctrIdToStr[counter].ctrName, ifNum);
}
{
printf("Error resetting stats.\n");
}
else
{
printf("Internal error.\n");
}
printf("\n");
}
{
printf("Resetting all counters on an interface %d.\n", ifNum);
{
printf("Statistics reset successfully on interface %d.\n", ifNum);
}
{
printf("Failed to reset statistics on interface %d.\n", ifNum);
}
{
printf("Error resetting stats.\n");
}
else
{
printf("Internal error.\n");
}
printf("\n");
}
{
uint32_t lastResetSecs;
{
printf("Seconds since stats last reset on interface %d: %8u (after)\n", ifNum, lastResetSecs);
}
else
{
printf("Failed to get last reset time on interface %d.\n", ifNum);
}
printf("\n");
}
int main(int argc, char **argv)
{
uint32_t ifNum;
char linkName[256];
uint32_t testNum;
exampleName = argv[0];
if (argc < 2)
{
printInterfaceStatsAppMenu();
exit(1);
}
testNum = atoi(argv[1]);
l7proc_crashlog_register();
{
printf("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", rc);
exit(1);
}
{
sleep(1);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Starting interface statistics example application");
linkNameBuff.pstart = linkName;
linkNameBuff.size = sizeof(linkName);
printf("\n");
printf("Network OS version = %s\n", (char *) linkNameBuff.pstart);
else
printf("Network OS Version retrieve error\n");
printf("\n");
switch (testNum)
{
case 0:
if (2 != argc)
{
printInterfaceStatsAppMenu();
exit(1);
}
intfStatsNameToNumMapDisplay(&clientHandle);
break;
case 1:
if (3 != argc)
{
printInterfaceStatsAppMenu();
exit(1);
}
ifNum = atoi(argv[2]);
intfStatsIterativeDisplay(&clientHandle, ifNum);
break;
case 2:
if (3 != argc)
{
printInterfaceStatsAppMenu();
exit(1);
}
ifNum = atoi(argv[2]);
intfStatsBulkDisplay(&clientHandle, ifNum);
break;
case 3:
if (4 != argc)
{
printInterfaceStatsAppMenu();
exit(1);
}
ifNum = atoi(argv[2]);
counter = atoi(argv[3]);
intfStatsReset(&clientHandle, ifNum, counter);
break;
case 4:
if (3 != argc)
{
printInterfaceStatsAppMenu();
exit(1);
}
ifNum = atoi(argv[2]);
intfInterfaceStatsReset(&clientHandle, ifNum);
break;
case 5:
if (3 != argc)
{
printInterfaceStatsAppMenu();
exit(1);
}
ifNum = atoi(argv[2]);
intfStatsResetTimeGet(&clientHandle, ifNum);
break;
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping interface statistics example application");
return 0;
}