#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: Check if the PTP TC is supported: %s 1 \n", name);
printf("Test 2: Check if the unit is valid for PTP TC: %s 2 <unit>\n", name);
printf("Test 3: Get PTP TC admin mode: %s 3 \n", name);
printf("Test 4: Set PTP TC admin mode: %s 4 <adminMode 1-Enable,0-disable>\n", name);
printf("Test 5: Determine if interface configuration can be applied in hardware: %s 5 <intfNum>\n", name);
printf("Test 6: Get PTP TC mode on the specified interface: %s 6 <intfNum>\n", name);
printf("Test 7: Set PTP TC mode on the specified interface: %s 6 <intfNum> <adminMode 1-Enable,0-disable>\n", name);
printf("Test 8: Gets PTP TC operational mode on the specified interface: %s 7 <intfNum>\n", name);
printf("Test 9: Check if the interface is valid for PTP TC: %s 8 <intfNum>\n", name);
printf("Test 10: Run API sanity checks: %s 9 \n", name);
return;
}
{
uint32_t intfNum;
uint32_t unit;
printf("Testing ptptc OpEN APIs sanity:\n");
printf("Testing openapiPtpTcIsSupportedGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiPtpTcIsValidUnitGet():\n");
unit = 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 openapiPtpTcAdminModeGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiPtpTcIntfHwConfigAllowedGet():\n");
intfNum = 1;
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiPtpTcIntfAdminModeGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiPtpTcIntfAdminModeSet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("Testing openapiPtpTcIntfOperAdminModeGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
printf("Testing openapiPtpTcIsValidIntfGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 3:(result = %d)\n", result);
return;
}
{
{
printf("Bad return code trying to check if PTP TC is supported. (result = %d)\n", result);
}
else
{
{
printf("\n PTP TC is supported\n");
}
else
{
printf("\n PTP TC is not supported\n");
}
}
return;
}
{
{
printf("Bad return code trying to check if the unit is valid for PTP TC. (result = %d)\n", result);
}
else
{
{
printf("\n This unit is valid for PTP TC\n");
}
else
{
printf("\n This unit is not valid for PTP TC\n");
}
}
return;
}
{
{
printf("Bad return code trying to get PTP TC admin mode. (result = %d)\n", result);
}
else
{
{
printf("\n PTP TC is enabled.\n");
}
else
{
printf("\n PTP TC is disabled.\n");
}
}
return;
}
{
{
printf("Bad return code trying to set PTP TC admin mode. (result = %d)\n", result);
}
else
{
printf("\n PTP TC admin mode is set.\n");
}
return;
}
{
{
printf("Bad return code trying to determine if interface configuration can be applied in hardware. (result = %d)\n", result);
}
else
{
{
printf("\nPTP TC Hardware configuration is allowed on interface %u.\n",intfNum);
}
else
{
printf("\nPTP TC Hardware configuration is not allowed on interface %u.\n", intfNum);
}
}
return;
}
{
{
printf("Bad return code trying to get PTP TC mode on the specified interface. (result = %d)\n", result);
}
else
{
{
printf("\n PTP TC is admin enabled on interface %u.\n", intfNum);
}
else
{
printf("\n PTP TC is admin disabled on interface %u.\n", intfNum);
}
}
return;
}
{
{
printf("Bad return code trying to set PTP TC mode on the specified interface. (result = %d)\n", result);
}
printf("\n PTP TC is admin mode is set on interface %u.\n", intfNum);
return;
}
{
{
printf("Bad return code trying to gets PTP TC operational mode on the specified interface. (result = %d)\n", result);
}
else
{
{
printf("\n PTP TC is operational enabled on interface %u.\n", intfNum);
}
else
{
printf("\n PTP TC is operational disabled on interface %u.\n", intfNum);
}
}
return;
}
{
{
printf("Bad return code trying to check if the interface is valid for PTP TC. (result = %d)\n", result);
}
else
{
{
printf("\n Interface %u is valid for PTP TC.\n", intfNum);
}
else
{
printf("\n Interface %u is not valid for PTP TC.\n",intfNum);
}
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum;
char switch_os_revision_string[100];
int show_help = 1;
uint32_t intfNum;
uint32_t unit;
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 ptptc 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)
{
ptpTcIsSupportedGet(&client_handle, &isSupported);
show_help = 0;
}
break;
case 2:
if (argc == 3)
{
unit = atoi(argv[2]);
ptpTcIsValidUnitGet(&client_handle, unit, &isValid);
show_help = 0;
}
break;
case 3:
if (argc == 2)
{
ptpTcAdminModeGet(&client_handle, &adminMode);
show_help = 0;
}
break;
case 4:
if (argc == 3)
{
adminMode = atoi(argv[2]);
ptpTcAdminModeSet(&client_handle, adminMode);
show_help = 0;
}
break;
case 5:
if (argc == 3)
{
intfNum = atoi(argv[2]);
ptpTcIntfHwConfigAllowedGet(&client_handle, intfNum, &isAllowed);
show_help = 0;
}
break;
case 6:
if (argc == 3)
{
intfNum = atoi(argv[2]);
ptpTcIntfAdminModeGet(&client_handle, intfNum, &adminMode);
show_help = 0;
}
break;
case 7:
if (argc == 4)
{
intfNum = atoi(argv[2]);
adminMode = atoi(argv[3]);
ptpTcIntfAdminModeSet(&client_handle, intfNum, adminMode);
show_help = 0;
}
break;
case 8:
if (argc == 3)
{
intfNum = atoi(argv[2]);
ptpTcIntfOperAdminModeGet(&client_handle, intfNum, &mode);
show_help = 0;
}
break;
case 9:
if (argc == 3)
{
intfNum = atoi(argv[2]);
ptpTcIsValidIntfGet(&client_handle, intfNum, &isValid);
show_help = 0;
}
break;
case 10:
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 ptptc API example application");
return 0;
}