#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
void printAccountingAppMenu()
{
printf("Usage: accounting_example <test#> <arg1> <arg2> ... \n");
printf("Test 1: Create accounting list name: accounting_example 1 <accounting-type> <record-type> <list-name>\n");
printf("Test 2: Add methods to accounting list: accounting_example 2 <accounting-type> <list-name> <method1> <method2> <method3> .... \n");
printf("Test 3: Get accounting list names and configured methods of an access acctType: accounting_example 3 <accounting-type>\n");
printf("Test 4: Set accounting list to an access line: accounting_example 4 <access-line> <accounting-type> <list-name> \n");
printf("Test 5: Get accounting list name applied to access line: accounting_example 5 <access-line> <accounting-type> \n");
printf("Test 6: Delete accounting list applied to the access-line: accounting_example 6 <access-line> <accounting-type> \n");
printf("Test 7: Delete accounting list created: accounting_example 7 <accounting-type> <list-name> \n");
printf("Test 8: Accounting OpEN APIs sanity: accounting_example 8 \n");
return;
}
{
char str[100];
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.
size = strlen(str)+1;
{
{
printf("Bad return code trying to create accounting list name for acctType %d. (result = %d) \n", acctType, result);
}
else
{
printf("Accounting list name %s created successfully. \n", str);
}
}
else
{
printf("Accounting list name is too long or contains invalid characters. \n");
}
return;
}
{
char str[100];
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.pstart = str;
buffDesc.size = strlen(str)+1;
{
printf("Bad return code trying to add methods to accounting list for acctType %d. (result = %d) \n", acctType, result);
}
else
{
printf("Methods added to accounting list successfully. \n");
}
return;
}
{
uint32_t acctListNameSize;
uint32_t maxAcctMethods;
uint32_t i = 0;
char *str;
char *methodStr;
{
printf("Bad return code trying to get accounting list name size. (result = %d)", result);
return;
}
{
printf("Bad return code trying to get maximum accounting methods supported. (result = %d) \n", result);
}
if ((str = (char *)malloc(acctListNameSize)) == NULL)
{
printf("Could not allocate memory.\n");
return;
}
if ((methodStr = (char *)malloc(maxAcctMethods)) == NULL)
{
printf("Could not allocate memory.\n");
free(str);
return;
}
memset(str, 0, acctListNameSize);
listName.pstart = str;
listName.size = acctListNameSize;
memset(methodStr, 0, maxAcctMethods);
methodList.pstart = methodStr;
methodList.size = maxAcctMethods;
printf("Getting the first accounting list name. \n");
{
printf("Bad return code trying to get first accounting list name for acctType: %d (result = %d) \n", acctType, result);
free(methodStr);
free(str);
return;
}
printf("Acct_list_name Record Type Methods\n");
do
{
printf("%-15s ", str);
{
switch (recordType)
{
printf("start-stop ");
break;
printf("stop-only ");
break;
printf("None ");
break;
default:
printf(" ");
break;
}
}
else
{
printf("Record Type get failed. (result = %d)", result);
}
{
for (i = 0; i < methodList.size; i++)
{
switch ((methodStr[i]-'0'))
{
printf("Tacacs ");
break;
printf("Radius ");
break;
default:
break;
}
}
}
else
{
printf("Method list get failed. (result = %d) \n", result);
}
printf("\n");
listName.size = acctListNameSize;
methodList.size = maxAcctMethods;
free(str);
free(methodStr);
return;
}
{
char str[100];
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.pstart = str;
buffDesc.size = strlen(str)+1;
{
printf("Bad return code trying to apply accounting list name to access line %d. (result = %d) \n", accessLine, result);
}
else
{
printf("Accounting list name applied to access line successfully \n");
}
return;
}
{
char *str;
uint32_t acctListNameSize;
{
printf("Bad return code trying to get accounting list name size. (result = %d)", result);
return;
}
if ((str = (char *)malloc(acctListNameSize)) == NULL)
{
printf("Could not allocate memory.\n");
return;
}
memset(str, 0, acctListNameSize);
listName.pstart = str;
listName.size = acctListNameSize;
printf(" Getting the accounting list name applied to access line %d\n", accessLine);
{
printf("Bad return code while getting accounting list name applied to access line. (result = %d) \n", result);
}
else
{
printf("Accounting list name: %s \n", str);
}
free(str);
return;
}
{
printf("Deleting accounting list applied to access line %d. \n", accessLine);
{
printf("Bad return code trying to delete accounting list name applied to access line. (result = %d) \n", result);
}
else
{
printf("Deleted the accounting list name from the access line %d successfully. \n", accessLine);
}
return;
}
{
char str[100];
printf("Deleting the accounting list %s \n", listName);
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.pstart = str;
buffDesc.size = strlen(str)+1;
{
printf("Bad return code trying to delete accounting list. (result = %d) \n", result);
}
else
{
printf("Accounting list %s deleted successfully. \n", (char *)buffDesc.pstart);
}
return;
}
{
uint32_t acctListNameSize = 0, maxAcctMethods =0;
char *str, *str1;
printf("\nTesting accounting OpEN APIs sanity\n");
{
printf("Bad return code trying to get accounting name size. (result = %d) \n", result);
return;
}
{
printf("Bad return code trying to get maximum accounting methods supported. (result = %d) \n", result);
return;
}
if ((str = (char *)malloc(acctListNameSize)) == NULL)
{
printf("Could not allocate memory\n");
return;
}
memset(str, 0, acctListNameSize);
buffDesc1.pstart = str;
buffDesc1.size = acctListNameSize;
if ((str1 = (char *)malloc(maxAcctMethods)) == NULL)
{
printf("Could not allocate memory\n");
free(str);
return;
}
memset(str1, 0, maxAcctMethods);
buffDesc2.pstart = str1;
buffDesc2.size = maxAcctMethods;
printf("\nTesting openapiAccountingListNameSizeGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("NULL string length. (result = %d)\n", result);
printf("openapiAccountingListNameSizeGet() sanity successful.\n");
printf("\nTesting openapiAccountingMethodsMaxGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("NULL parameter that gets max accounting methods. (result = %d)\n", result);
printf("openapiAccountingMethodsMaxGet() sanity successful.\n");
printf("\nTesting openapiAccountingListCreate(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("Invalid accounting record acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("openapiAccountingListCreate() sanity successful.\n");
printf("\nTesting openapiAccountingMethodsAdd(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("NULL buff descriptor to accounting methods. (result = %d)\n", result);
printf("openapiAccountingMethodsAdd() sanity successful.\n");
printf("\nTesting openapiAccountingMethodListGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("NULL buff descriptor to accounting methods. (result = %d)\n", result);
printf("openapiAccountingMethodListGet() sanity successful.\n");
printf("\nTesting openapiAccountingListRecordTypeGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("NULL record acctType. (result = %d)\n", result);
printf("openapiAccountingListRecordTypeGet() sanity successful.\n");
printf("\nTesting openapiAccountingListFirstGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("openapiAccountingListFirstGet() sanity successful.\n");
printf("\nTesting openapiAccountingListNextGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to previous accounting list name. (result = %d)\n", result);
printf("NULL buff descriptor to next accounting list name. (result = %d)\n", result);
printf("openapiAccountingListNextGet() sanity successful.\n");
printf("\nTesting openapiAccountingListDelete(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("openapiAccountingListDelete() sanity successful.\n");
printf("\nTesting openapiAccountingListLineSet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access line. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("openapiAccountingListLineSet() sanity successful.\n");
printf("\nTesting openapiAccountingListLineGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access line. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("NULL buff descriptor to accounting list name. (result = %d)\n", result);
printf("openapiAccountingListLineGet() sanity successful.\n");
printf("\nTesting openapiAccountingListLineDelete(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access line. (result = %d)\n", result);
printf("Invalid accounting acctType. (result = %d)\n", result);
printf("openapiAccountingListLineDelete() sanity successful.\n");
free(str);
free(str1);
return;
}
int main(int argc, char **argv)
{
uint32_t testNum, arg1, arg2;
char switch_os_revision_string[100];
char str[100];
uint32_t i = 0;
if (argc < 2)
{
printAccountingAppMenu();
exit(1);
}
testNum = atoi(argv[1]);
l7proc_crashlog_register();
{
printf("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
exit(2);
}
{
sleep(1);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Starting Accounting 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)
{
printAccountingAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
accountingListCreate(&clientHandle, arg1, arg2, argv[4]);
break;
case 2:
if (argc < 5)
{
printAccountingAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
memset(str, 0, sizeof(str));
for (i = 4; i < argc; i++)
{
strncat(str, argv[i], strlen(argv[i]));
}
acctMethods.pstart = str;
acctMethods.size = strlen(str)+1;
accountingMethodsAdd(&clientHandle, arg1, argv[3], &acctMethods);
break;
case 3:
if (argc != 3)
{
printAccountingAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
accountingInfoGet(&clientHandle, arg1);
break;
case 4:
if (argc != 5)
{
printAccountingAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
accountingListLineApply(&clientHandle, arg1, arg2, argv[4]);
break;
case 5:
if (argc != 4)
{
printAccountingAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
accountingListLineGet(&clientHandle, arg1, arg2);
break;
case 6:
if (argc != 4)
{
printAccountingAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
accountingListLineDelete(&clientHandle, arg1, arg2);
break; case 7:
if (argc != 4)
{
printAccountingAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
accountingListDelete(&clientHandle, arg1, argv[3]);
break;
case 8:
if (argc != 2)
{
printAccountingAppMenu();
exit(1);
}
accountingOpENAPIsSanity(&clientHandle);
break;
default:
printAccountingAppMenu();
break;
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Accounting API example application");
return 0;
}