#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: Create a new row in the Service Table for the specified interface and direction: %s 1 <intIfNum><ifDir><activateRow>\n", name);
printf("Test 2: Delete a row from the Service Table for the specified interface and direction: %s 2 <intIfNum><ifDir>\n", name);
printf("Test 3: Gets a row from the Service Table for the specified interface and direction: %s 3 <intIfNum><ifDir>\n", name);
printf("Test 4: Determine next sequential row in the Service Table: %s 4 <intIfNum><ifDir>\n", name);
printf("Test 5: Set the policy index attached to the specified interface and direction: %s 5 <intIfNum><ifDir><policyIndex>\n", name);
printf("Test 6: Get the policy index attached to the specified interface and direction: %s 6 <intIfNum><ifDir>\n", name);
printf("Test 7: Get the service interface operational status for the specified Service Table row: %s 7 <intIfNum><ifDir>\n", name);
printf("Test 8: Check if the specified internal interface number is in use by the ACL component: %s 8 <intIfNum><ifDir>\n", name);
printf("Test 9: Set the given status for the specified Service Table row: %s 9 <intIfNum><ifDir><status>\n", name);
printf("Test 10: Get the current status for the specified Service Table row: %s 10 <intIfNum><ifDir>\n", name);
printf("Test 11: Verifies the current status for the specified Service Table row: %s 11 <intIfNum><ifDir><status>\n", name);
printf("Test 12: Get the inbound offered packets count for the specified policy class instance: %s 12 <policyIndex><policyInstIndex><intIfNum>\n", name);
printf("Test 13: Get the outbound offered packets count for the specified policy class instance: %s 13 <policyIndex><policyInstIndex><intIfNum>\n", name);
printf("Test 14: Get the inbound discarded packet count for the specified policy class instance: %s 14 <policyIndex><policyInstIndex><intIfNum>\n", name);
printf("Test 15: Get the outbound discarded packet count for the specified policy class instance: %s 15 <policyIndex><policyInstIndex><intIfNum>\n", name);
printf("Test 16: Run API sanity checks: %s 16 \n", name);
return;
}
{
uint32_t policyIndex=1;
uint32_t policyInstIndex=1;
uint32_t intIfNum=1;
uint32_t nxtIntIfNum;
uint64_t packtCount;
printf("Testing diffServ_serv OpEN APIs sanity:\n");
printf("Testing openapiDiffServServiceGetNext():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 5:(result = %d)\n", result);
printf("NULL argument 5:(result = %d)\n", result);
printf("Testing openapiDiffServServicePolicyIndexGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 4:(result = %d)\n", result);
printf("Testing openapiDiffServServiceIfOperStatusGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 4:(result = %d)\n", result);
printf("Testing openapiDiffServIsAclIntfInUse():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 4:(result = %d)\n", result);
printf("Testing openapiDiffServServiceRowStatusGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 4:(result = %d)\n", result);
printf("Testing openapiDiffServPolicyPerfInOfferedPacketsGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 5:(result = %d)\n", result);
printf("Testing openapiDiffServPolicyPerfOutOfferedPacketsGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 5:(result = %d)\n", result);
printf("Testing openapiDiffServPolicyPerfInDiscardedPacketsGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 5:(result = %d)\n", result);
printf("Testing openapiDiffServPolicyPerfOutDiscardedPacketsGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 5:(result = %d)\n", result);
return;
}
{
{
printf("Bad return code trying to create a new row in the Service Table for the specified interface and direction. (result = %d)\n", result);
}
else
{
printf("Successfully created a new row in service table for interface %d of direction %d and row activation status %d. \n",
intIfNum, ifDir, activateRow);
}
return;
}
{
{
printf("Bad return code trying to delete a row from the Service Table for the specified interface and direction. (result = %d)\n", result);
}
else
{
printf("Deleted row in service table for interface %d of direction %d. \n",
intIfNum, ifDir);
}
return;
}
{
{
printf("Bad return code trying to fetch row from the Service Table for the specified interface and direction. (result = %d)\n", result);
}
else
{
printf("Successfully fetch row in service table for interface %d of direction %d. \n",
intIfNum, ifDir);
}
return;
}
{
{
printf("Bad return code trying to determine next sequential row in the Service Table. (result = %d)\n", result);
}
else
{
printf("Next sequential row in the Service Table for given[interface %d and direction %d] is"
"interface %d and direction %d. \n", intIfNum, ifDir, *nxtIntIfNum, *nxtIfDir);
}
return;
}
{
{
printf("Bad return code trying to set the policy index attached to the specified interface and direction. (result = %d)\n", result);
}
else
{
printf("Successfuly set policy index %d attached to the interface %d and direction %d.\n",
policyIndex, intIfNum, ifDir);
}
return;
}
{
{
printf("Bad return code trying to get the policy index attached to the specified interface and direction. (result = %d)\n", result);
}
else
{
printf("Fetched policy index information for interface %d and direction %d is %d.\n",
intIfNum, ifDir, *pPolicyIndex);
}
return;
}
{
{
printf("Bad return code trying to get the service interface operational status for the specified Service Table row. (result = %d)\n", result);
}
else
{
printf("Operational status of service table row for interface %d direction %d is %d.\n",
intIfNum, ifDir, *pIfOperStatus);
}
return;
}
{
{
printf("Bad return code trying to check if the specified internal interface number is in use by the ACL component. (result = %d)\n", result);
}
else
{
printf("Interface %d of direction %d is %s by the ACL component.\n", intIfNum, ifDir,
(
OPEN_TRUE == *pIsAclIntfInUse) ?
"in use" :
"unused");
}
return;
}
{
{
printf("Bad return code trying to set the given status for the specified Service Table row. (result = %d)\n", result);
}
else
{
printf("Row status is successfully set to %d for interface %d and direction %d.\n", status, intIfNum, ifDir);
}
return;
}
{
{
printf("Bad return code trying to get the current status for the specified Service Table row. (result = %d)\n", result);
}
else
{
printf("Status for the specified Service Table row with interface %d and direction %d is %d.\n",
intIfNum, ifDir, *pStatus);
}
return;
}
{
{
printf("Bad return code trying to verifies the current status for the specified Service Table row. (result = %d)\n", result);
}
else
{
printf("Successfully verified status for the specified Service Table row with interface %d , direction %d and row status %d.\n",
intIfNum, ifDir, status);
}
return;
}
void diffServPolicyPerfInOfferedPacketsGet(
openapiClientHandle_t *pClientHandle, uint32_t policyIndex, uint32_t policyInstIndex, uint32_t intIfNum, uint64_t *pPacktCount)
{
{
printf("Bad return code trying to get the inbound offered packets count for the specified policy class instance. (result = %d)\n", result);
}
else
{
printf("Inbound offered packet count for policy class instance(policy index:%d policy instance index:%d) on interface %d is %lu. \n",
policyIndex, policyInstIndex, intIfNum, *pPacktCount);
}
return;
}
void diffServPolicyPerfOutOfferedPacketsGet(
openapiClientHandle_t *pClientHandle, uint32_t policyIndex, uint32_t policyInstIndex, uint32_t intIfNum, uint64_t *pPacktCount)
{
{
printf("Bad return code trying to get the outbound offered packets count for the specified policy class instance. (result = %d)\n", result);
}
else
{
printf("Outbound offered packet count for policy class instance(policy index:%d policy instance index:%d) on interface %d is %lu. \n",
policyIndex, policyInstIndex, intIfNum, *pPacktCount);
}
return;
}
void diffServPolicyPerfInDiscardedPacketsGet(
openapiClientHandle_t *pClientHandle, uint32_t policyIndex, uint32_t policyInstIndex, uint32_t intIfNum, uint64_t *pPacktCount)
{
{
printf("Bad return code trying to get the inbound discarded packet count for the specified policy class instance. (result = %d)\n", result);
}
else
{
printf("Inbound discarded packet count for policy class instance(policy index:%d policy instance index:%d) on interface %d is %lu. \n",
policyIndex, policyInstIndex, intIfNum, *pPacktCount);
}
return;
}
void diffServPolicyPerfOutDiscardedPacketsGet(
openapiClientHandle_t *pClientHandle, uint32_t policyIndex, uint32_t policyInstIndex, uint32_t intIfNum, uint64_t *pPacktCount)
{
{
printf("Bad return code trying to get the outbound discarded packet count for the specified policy class instance. (result = %d)\n", result);
}
else
{
printf("Outbound discarded packet count for policy class instance(policy index:%d policy instance index:%d) on interface %d is %lu. \n",
policyIndex, policyInstIndex, intIfNum, *pPacktCount);
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum;
char switch_os_revision_string[100];
int show_help = 1;
uint32_t intIfNum, nxtIntIfNum;
uint32_t policyIndex;
uint32_t policyInstIndex;
uint64_t packtCount;
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 diffServ_serv 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 == 5)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
activateRow = atoi(argv[4]);
diffServServiceCreate(&client_handle, intIfNum, ifDir, activateRow);
show_help = 0;
}
break;
case 2:
if (argc == 4)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
diffServServiceDelete(&client_handle, intIfNum, ifDir);
show_help = 0;
}
break;
case 3:
if (argc == 4)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
diffServServiceGet(&client_handle, intIfNum, ifDir);
show_help = 0;
}
break;
case 4:
if (argc == 4)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
diffServServiceGetNext(&client_handle, intIfNum, ifDir, &nxtIntIfNum, &nxtIfDir);
show_help = 0;
}
break;
case 5:
if (argc == 5)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
policyIndex = atoi(argv[4]);
diffServServicePolicyIndexSet(&client_handle, intIfNum, ifDir, policyIndex);
show_help = 0;
}
break;
case 6:
if (argc == 4)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
diffServServicePolicyIndexGet(&client_handle, intIfNum, ifDir, &policyIndex);
show_help = 0;
}
break;
case 7:
if (argc == 4)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
diffServServiceIfOperStatusGet(&client_handle, intIfNum, ifDir, &ifOperStatus);
show_help = 0;
}
break;
case 8:
if (argc == 4)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
diffServIsAclIntfInUse(&client_handle, intIfNum, ifDir, &isAclIntfInUse);
show_help = 0;
}
break;
case 9:
if (argc == 5)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
status = atoi(argv[4]);
diffServServiceRowStatusSet(&client_handle, intIfNum, ifDir, status);
show_help = 0;
}
break;
case 10:
if (argc == 4)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
diffServServiceRowStatusGet(&client_handle, intIfNum, ifDir, &status);
show_help = 0;
}
break;
case 11:
if (argc == 5)
{
intIfNum = atoi(argv[2]);
ifDir = atoi(argv[3]);
status = atoi(argv[4]);
diffServServiceRowStatusVerify(&client_handle, intIfNum, ifDir, status);
show_help = 0;
}
break;
case 12:
if (argc == 5)
{
policyIndex = atoi(argv[2]);
policyInstIndex = atoi(argv[3]);
intIfNum = atoi(argv[4]);
diffServPolicyPerfInOfferedPacketsGet(&client_handle, policyIndex, policyInstIndex, intIfNum, &packtCount);
show_help = 0;
}
break;
case 13:
if (argc == 5)
{
policyIndex = atoi(argv[2]);
policyInstIndex = atoi(argv[3]);
intIfNum = atoi(argv[4]);
diffServPolicyPerfOutOfferedPacketsGet(&client_handle, policyIndex, policyInstIndex, intIfNum, &packtCount);
show_help = 0;
}
break;
case 14:
if (argc == 5)
{
policyIndex = atoi(argv[2]);
policyInstIndex = atoi(argv[3]);
intIfNum = atoi(argv[4]);
diffServPolicyPerfInDiscardedPacketsGet(&client_handle, policyIndex, policyInstIndex, intIfNum, &packtCount);
show_help = 0;
}
break;
case 15:
if (argc == 5)
{
policyIndex = atoi(argv[2]);
policyInstIndex = atoi(argv[3]);
intIfNum = atoi(argv[4]);
diffServPolicyPerfOutDiscardedPacketsGet(&client_handle, policyIndex, policyInstIndex, intIfNum, &packtCount);
show_help = 0;
}
break;
case 16:
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 diffServ_serv API example application");
return 0;
}