#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: Gets current active Template Id: %s 1 <templateId>\n", name);
printf("Test 2: Sets active template id: %s 2 <templateId>\n", name);
printf("Test 3: Get the first valid template ID: %s 3 \n", name);
printf("Test 4: Get the next valid template ID: %s 4 <currentTemplateId>\n", name);
printf("Test 5: Gets name and description of specific template id: %s 5 <templateId>\n", name);
printf("Test 6: Sets(Revert to) Default template: %s 6 \n", name);
printf("Test 7: Print all STMs: %s 7 \n", name);
printf("Test 8: Run API sanity checks: %s 8 \n", name);
return;
}
{
uint32_t firstTemplateId;
uint32_t nextTemplateId=0;
uint32_t currentTemplateId=0;
uint32_t templateId;
char buffer[128];
badBufdescPointer.
pstart = (
void *) NULL;
badBufdescPointer.
size =
sizeof(buffer);
badBufdescPointer.size = 0;
zeroLenBuf.pstart = buffer;
zeroLenBuf.size = 0;
printf("Testing STM Template OpEN APIs sanity:\n");
printf("Testing openapiStmActiveTemplateIdGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiStmFirstTemplateIdGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiStmNextTemplateIdGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiStmTemplateNameDescriptionGet():\n");
printf("NULL client handle:(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);
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);
printf("Testing openapiStmTemplateRevertToDefault():\n");
printf("NULL client handle:(result = %d)\n", result);
return;
}
{
uint32_t templateId;
{
printf("Bad return code trying to gets current active Template Id. (result = %d)\n", result);
}
else
{
printf("Current active template ID is %d\n", templateId);
}
return;
}
{
{
{
printf("Template ID:%d is arleady configured\n", templateId);
}
{
printf("Template ID:%d is not supported\n", templateId);
}
else
{
printf("Bad return code trying to set active template ID:%d. (result = %d)\n",
templateId, result);
}
}
else
{
printf("Active template id is set to %d\n", templateId);
}
return;
}
{
uint32_t firstTemplateId;
{
printf("Bad return code trying to get the first valid template ID. (result = %d)\n", result);
}
else
{
printf("First template ID:%d\n", firstTemplateId);
}
return;
}
{
uint32_t nextTemplateId;
{
printf("Bad return code trying to get the next valid template ID. (result = %d)\n", result);
}
else
{
printf("Current template ID:%d Next template ID:%d\n",
currentTemplateId, nextTemplateId);
}
return;
}
{
char tempName[100], tempDesc[100];
templateName.pstart = tempName;
templateName.size = OPEN_STM_TEMPLATE_NAME_SIZE;
templateDesc.pstart = tempDesc;
templateDesc.size = OPEN_STM_TEMPLATE_DESCRIPTION_SIZE ;
{
printf("Bad return code trying to get name and description of specific "
"template id (result = %d)\n", result);
}
else
{
printf("Template ID:%d Template Name:%s Template Description:%s\n",
templateId, tempName, tempDesc);
}
return;
}
{
{
printf("Bad return code trying to set(Revert to) Default template. "
"(result = %d)\n", result);
}
else
{
printf("Unable to revert to default template.\n");
}
return;
}
{
uint32_t first = 0, next = 0;
char tempName[OPEN_STM_TEMPLATE_NAME_SIZE], tempDesc[OPEN_STM_TEMPLATE_DESCRIPTION_SIZE];
templName.pstart = tempName;
templName.size = OPEN_STM_TEMPLATE_NAME_SIZE;
templDesc.pstart = tempDesc;
templDesc.size = OPEN_STM_TEMPLATE_DESCRIPTION_SIZE;
{
printf("\n Unable to get first template details, return \n");
return;
}
next = first;
do
{
first = next;
templName.size = OPEN_STM_TEMPLATE_NAME_SIZE;
templDesc.size = OPEN_STM_TEMPLATE_DESCRIPTION_SIZE;
&templName, &templDesc))
{
printf("\n Template ID:%d Template Name:%s Template Description:%s\n",
first, (char *)templName.pstart, (char *)templDesc.pstart);
}
else
{
printf("\n Unable to get template details for template ID:%d\n", first);
}
}
int main(int argc, char **argv)
{
uint32_t testNum, templateId;
char switch_os_revision_string[100];
int show_help = 1;
if (argc < 2)
{
printAppMenu(argv[0]);
return -1;
}
testNum = atoi(argv[1]);
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 STM Template 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)
{
stmActiveTemplateIdGet(&clientHandle);
show_help = 0;
}
break;
case 2:
if (argc == 3)
{
templateId = atoi(argv[2]);
stmActiveTemplateIdSet(&clientHandle, templateId);
show_help = 0;
}
break;
case 3:
if (argc == 2)
{
stmFirstTemplateIdGet(&clientHandle);
show_help = 0;
}
break;
case 4:
if (argc == 3)
{
templateId = atoi(argv[2]);
stmNextTemplateIdGet(&clientHandle, templateId);
show_help = 0;
}
break;
case 5:
if (argc == 3)
{
templateId = atoi(argv[2]);
stmTemplateNameDescriptionGet(&clientHandle, templateId);
show_help = 0;
}
break;
case 6:
if (argc == 2)
{
stmTemplateRevertToDefault(&clientHandle);
show_help = 0;
}
break;
case 7:
if (argc == 2)
{
printStms(&clientHandle);
show_help = 0;
}
break;
case 8:
if (argc == 2)
{
runSanity(&clientHandle);
show_help = 0;
}
break;
default:
break;
}
if (show_help == 1)
{
printAppMenu(argv[0]);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping STM Template API example application");
return 0;
}