#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
static void printAppMenu(char *name)
{
printf("Usage: %s <test#> <arg1> <arg2> ... \n", name);
printf("Test 1: Get the number of license files in the system: %s 1 \n", name);
printf("Test 2: Get the first license index in the system: %s 2 \n", name);
printf("Test 3: Get the next license index in the system: %s 3 <currentIndex>\n", name);
printf("Test 4: Get the type of license: %s 4 <licenseIndex> \n", name);
printf("Test 5: Get the status of license in the system: %s 5 <licenseIndex> \n", name);
printf("Test 6: Get the parameter value of license file in the system: %s 6 <licenseIndex><paramType>\n", name);
printf("Test 7: Get the version number of license file in the system: %s 7 <licenseIndex>\n", name);
printf("Test 8: Get the key of license file in the system: %s 8 <licenseIndex>\n", name);
printf("Test 9: Get the model name of license file: %s 9 <licenseIndex>\n", name);
printf("Test 10: Get the serial number of license file: %s 10 <licenseIndex>\n", name);
printf("Test 11: Delete a license file: %s 11 <licenseIndex>\n", name);
printf("Test 12: Delete all license files in the system: %s 12 \n", name);
printf("Test 13: Run API sanity checks: %s 13 \n", name);
return;
}
{
uint32_t firstLicenseIndex;
uint32_t numOfLicenses;
uint32_t nextLicenseIndex;
uint32_t licenseIndex;
char buffer[128];
badBufdescPointer.
pstart = (
void *) NULL;
badBufdescPointer.
size =
sizeof(buffer);
badBufdescLen.pstart = buffer;
badBufdescPointer.size = 0;
buf.pstart = buffer;
buf.size = sizeof(buffer);
zeroLenBuf.pstart = buffer;
zeroLenBuf.size = 0;
printf("Testing Capability_licensing OpEN APIs sanity:\n");
printf("Testing openapiCapabLicenseCountGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiCapabLicenseFirstIndexGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiCapabLicenseNextIndexGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiCapabLicenseTypeGet():\n");
licenseIndex = 1;
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiCapabLicenseStatusGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiCapabLicenseParamGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("NULL argument 4:(result = %d)\n", result);
printf("NULL buffdesc pstart argument 4:(result = %d)\n", result);
printf("buffdesc 0 length size argument 4:(result = %d)\n", result);
badBufdescLen.size = OPEN_CAPAB_LIC_MAX_FILE_PARAM_VAL_LEN - 1;
printf("not equal to required value argument 4:(result = %d)\n", result);
printf("Testing openapiCapabLicenseVersionGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("NULL buffdesc pstart argument 3:(result = %d)\n", result);
printf("buffdesc 0 length size argument 3:(result = %d)\n", result);
badBufdescLen.size = OPEN_CAPAB_LIC_MAX_VER_LEN - 1;
printf("not equal to required value argument 3:(result = %d)\n", result);
printf("Testing openapiCapabLicenseKeyGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("NULL buffdesc pstart argument 3:(result = %d)\n", result);
printf("buffdesc 0 length size argument 3:(result = %d)\n", result);
badBufdescLen.size = OPEN_CAPAB_LIC_MAX_KEY_LEN - 1;
printf("not equal to required value argument 3:(result = %d)\n", result);
printf("Testing openapiCapabLicenseModelGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("NULL buffdesc pstart argument 3:(result = %d)\n", result);
printf("buffdesc 0 length size argument 3:(result = %d)\n", result);
badBufdescLen.size = OPEN_CAPAB_LIC_MAX_MODEL_LEN - 1;
printf("not equal to required value argument 3:(result = %d)\n", result);
printf("Testing openapiCapabLicenseSerialNumberGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("NULL buffdesc pstart argument 3:(result = %d)\n", result);
printf("buffdesc 0 length size argument 3:(result = %d)\n", result);
badBufdescLen.size = OPEN_CAPAB_LIC_MAX_SERIAL_LEN - 1;
printf("not equal to required value argument 3:(result = %d)\n", result);
printf("Testing openapiCapabLicenseLicenseRemove():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("less than minimum value argument 3:(result = %d)\n", result);
printf("greater than maximum value argument 3:(result = %d)\n", result);
printf("Testing openapiCapabLicenseLicenseRemoveAll():\n");
printf("NULL client handle:(result = %d)\n", result);
return;
}
{
{
printf("Bad return code trying to get the number of license files in the system (result = %d)\n", result);
}
else
{
printf("Number of licenses in the system is %d. \n", *numOfLicenses);
}
return;
}
{
{
printf("Bad return code trying to get the first license index in the system. (result = %d)\n", result);
}
else
{
printf("First license index in the system is %d. \n", *firstLicenseIndex);
}
return;
}
uint32_t *nextLicenseIndex)
{
{
printf("Bad return code trying to get the next license index in the system. (result = %d)\n", result);
}
else
{
printf("Next license index in the system is %d. \n", *nextLicenseIndex);
}
return;
}
{
{
printf("Bad return code trying to get the type of license. (result = %d)\n", result);
}
else
{
printf("License type at license index %d is %d \n", licenseIndex, *type);
}
return;
}
{
{
printf("Bad return code trying to get the status of license in the system. (result = %d)\n", result);
}
else
{
printf("License status at license index %d is %d \n", licenseIndex, *status);
}
return;
}
{
{
printf("Bad return code trying to get the parameter value of license file in the system. (result = %d)\n", result);
}
else
{
printf("License param value for license file %d param type %d is %s\n",
licenseIndex, paramType, (char *)paramValue->pstart);
}
return;
}
{
{
printf("Bad return code trying to get the version number of license file in the system. (result = %d)\n", result);
}
else
{
printf("License version for license file %d is %s \n", licenseIndex, (char *)version->pstart);
}
return;
}
{
{
printf("Bad return code trying to get the key of license file in the system. (result = %d)\n", result);
}
else
{
printf("License key for license file %d is %s \n", licenseIndex, (char *)key->pstart);
}
return;
}
{
{
printf("Bad return code trying to get the model name of license file. (result = %d)\n", result);
}
else
{
printf("License model for license file %d is %s \n", licenseIndex, (char *)model->pstart);
}
return;
}
{
{
printf("Bad return code trying to get the serial number of license file. (result = %d)\n", result);
}
else
{
printf("Serial number of the license file %d is %s \n", licenseIndex, (char *)serialNum->pstart);
}
return;
}
{
{
printf("Bad return code while removing license file. (result = %d)\n", result);
}
else
{
printf("Removed %d license file \n", licenseIndex);
}
return;
}
{
{
printf("Bad return code while removing all license files from system.(result = %d)\n", result);
}
else
{
printf("\nAll license files removed \n");
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum, numOfLicenses = 0;
uint32_t firstLicenseIndex = 0, licenseIndex = 0, nextLicenseIndex = 0;
char switch_os_revision_string[100];
int show_help = 1;
unsigned char paramValue[OPEN_CAPAB_LIC_MAX_FILE_PARAM_VAL_LEN+1];
unsigned char version[OPEN_CAPAB_LIC_MAX_VER_LEN+1];
unsigned char key[OPEN_CAPAB_LIC_MAX_KEY_LEN+1];
unsigned char model[OPEN_CAPAB_LIC_MAX_MODEL_LEN+1];
unsigned char serialNum[OPEN_CAPAB_LIC_MAX_SERIAL_LEN+1];
if (argc < 2)
{
printAppMenu(argv[0]);
return -1;
}
testNum = atoi(argv[1]);
if (argc > 2)
{
licenseIndex = atoi(argv[2]);
}
l7proc_crashlog_register();
{
printf("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
return -1;
}
{
sleep(1);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Starting Capability_licensing API example application");
printf("\n");
switch_os_revision.pstart = switch_os_revision_string;
switch_os_revision.size = sizeof(switch_os_revision_string);
printf("Network OS version = %s\n", switch_os_revision_string);
else
printf("Network OS version retrieve error\n");
printf("\n");
switch (testNum)
{
case 1:
if (argc == 2)
{
capabLicenseCountGet(&client_handle, &numOfLicenses);
show_help = 0;
}
break;
case 2:
if (argc == 2)
{
capabLicenseFirstIndexGet(&client_handle, &firstLicenseIndex);
show_help = 0;
}
break;
case 3:
if (argc == 3)
{
capabLicenseNextIndexGet(&client_handle, licenseIndex, &nextLicenseIndex);
show_help = 0;
}
break;
case 4:
if (argc == 3)
{
capabLicenseTypeGet(&client_handle, licenseIndex, &type);
show_help = 0;
}
break;
case 5:
if (argc == 3)
{
capabLicenseStatusGet(&client_handle, licenseIndex, &status);
show_help = 0;
}
break;
case 6:
if (argc == 4)
{
paramType = atoi(argv[3]);
buf.pstart = paramValue;
buf.size = sizeof(paramValue);
capabLicenseParamGet(&client_handle, licenseIndex, paramType, &buf);
show_help = 0;
}
break;
case 7:
if (argc == 3)
{
buf.pstart = version;
buf.size = sizeof(version);
capabLicenseVersionGet(&client_handle, licenseIndex, &buf);
show_help = 0;
}
break;
case 8:
if (argc == 3)
{
buf.pstart = key;
buf.size = sizeof(key);
capabLicenseKeyGet(&client_handle, licenseIndex, &buf);
show_help = 0;
}
break;
case 9:
if (argc == 3)
{
buf.pstart = model;
buf.size = sizeof(model);
capabLicenseModelGet(&client_handle, licenseIndex, &buf);
show_help = 0;
}
break;
case 10:
if (argc == 3)
{
buf.pstart = serialNum;
buf.size = sizeof(serialNum);
capabLicenseSerialNumberGet(&client_handle, licenseIndex, &buf);
show_help = 0;
}
break;
case 11:
if (argc == 3)
{
capabLicenseDelete(&client_handle, licenseIndex);
show_help = 0;
}
break;
case 12:
if (argc == 2)
{
capabLicenseDeleteAll(&client_handle);
show_help = 0;
}
break;
case 13:
if (argc == 2)
{
runSanity(&client_handle);
show_help = 0;
}
break;
default:
break;
}
if (show_help == 1)
{
printAppMenu(argv[0]);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Capability_licensing API example application");
return 0;
}