#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
#define GARP_LEAVE_TIMER_MIN_VAL 20
#define GARP_LEAVE_TIMER_MAX_VAL 600
#define GARP_LEAVEALL_TIMER_MIN_VAL 200
#define GARP_LEAVEALL_TIMER_MAX_VAL 6000
#define GARP_JOIN_TIMER_MIN_VAL 10
#define GARP_JOIN_TIMER_MAX_VAL 100
static void printAppMenu(char *name)
{
printf("Usage: %s <test#> <arg1> <arg2> ... \n", name);
printf("Test 1: Get the GMRP global status: %s 1 \n", name);
printf("Test 2: Set the GMRP global status. enable(1) and disable (0): %s 2 <globalGmrpStatus>\n", name);
printf("Test 3: Get the GMRP interface status: %s 3 <ifNum>\n", name);
printf("Test 4: Set the GMRP interface status. enable(1) and disable (0): %s 4 <ifNum><intfGmrpStatus>\n", name);
printf("Test 5: Get the GVRP global status: %s 5 \n", name);
printf("Test 6: Set the GVRP global status. enable(1) and disable (0): %s 6 <globalGvrpStatus>\n", name);
printf("Test 7: Get the GVRP interface status: %s 7 <ifNum>\n", name);
printf("Test 8: Set the GVRP interface status. enable(1) and disable (0): %s 8 <ifNum><intfGvrpStatus>\n", name);
printf("Test 9: Get the GARP Join Time: %s 9 <ifNum>\n", name);
printf("Test 10: Set the GARP Join Time: %s 10 <ifNum><joinTime>\n", name);
printf("Test 11: Get the GARP Leave Time: %s 11 <ifNum>\n", name);
printf("Test 12: Set the GARP Leave Time: %s 12 <ifNum><leaveTime>\n", name);
printf("Test 13: Get the GARP Leave All Time: %s 13 <ifNum>\n", name);
printf("Test 14: Set the GARP Leave All Time: %s 14 <ifNum><leaveAllTime>\n", name);
printf("Test 15: Run API sanity checks: %s 15 \n", name);
return;
}
{
uint32_t ifNum = 2, joinTime = 25;
printf("Testing GARP OpEN APIs sanity:\n");
printf("Testing openapiGarpJoinTimeSet():\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 openapiGarpLeaveTimeSet():\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 openapiGarpLeaveAllTimeSet():\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);
return;
}
{
{
printf("Bad return code trying to get the GMRP global status. (result = %d)\n", result);
}
else
{
printf("GMRP global status is %u.\n", globalGmrpStatus);
}
return;
}
{
{
printf("Bad return code trying to set the GMRP global status. (result = %d)\n", result);
}
else
{
printf("GMRP global status set successfully.\n");
}
return;
}
{
{
printf("Bad return code trying to get the GMRP interface status. (result = %d)\n", result);
}
else
{
printf("GMRP interface status is %u.\n", intfGmrpStatus);
}
return;
}
{
{
printf("Bad return code trying to set the GMRP interface status. (result = %d)\n", result);
}
else
{
printf("GMRP interface status set successfully.\n");
}
return;
}
{
{
printf("Bad return code trying to get the GVRP global status. (result = %d)\n", result);
}
else
{
printf("GVRP global status is %u.\n", globalGvrpStatus);
}
return;
}
{
{
printf("Bad return code trying to set the GVRP global status. (result = %d)\n", result);
}
else
{
printf("GVRP global status set successfully.\n");
}
return;
}
{
{
printf("Bad return code trying to get the GVRP interface status. (result = %d)\n", result);
}
else
{
printf("GVRP interface status is %u\n", intfGvrpStatus);
}
return;
}
{
{
printf("Bad return code trying to set the GVRP interface status. (result = %d)\n", result);
}
else
{
printf("GVRP interface status set successfully.\n");
}
return;
}
{
uint32_t joinTime;
{
printf("Bad return code trying to get the GARP Join Time. (result = %d)\n", result);
}
else
{
printf("GARP join time is %u.\n", joinTime);
}
return;
}
{
{
printf("Bad return code trying to set the GARP Join Time. (result = %d)\n", result);
}
else
{
printf("GARP join time set successfully.\n");
}
return;
}
{
uint32_t leaveTime;
{
printf("Bad return code trying to get the GARP Leave Time. (result = %d)\n", result);
}
else
{
printf("GARP leave time is %u.\n", leaveTime);
}
return;
}
{
{
printf("Bad return code trying to set the GARP Leave Time. (result = %d)\n", result);
}
else
{
printf("GARP leave time set successfully.\n");
}
return;
}
{
uint32_t leaveAllTime;
{
printf("Bad return code trying to get the GARP Leave All Time. (result = %d)\n", result);
}
else
{
printf("GARP leave all time is %u.\n", leaveAllTime);
}
return;
}
{
{
printf("Bad return code trying to set the GARP Leave All Time. (result = %d)\n", result);
}
else
{
printf("GARP leave all time set successfully.\n");
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum;
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 GARP 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)
{
garpGmrpEnableGet(&client_handle);
show_help = 0;
}
break;
case 2:
if (argc == 3)
{
garpGmrpEnableSet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 3:
if (argc == 3)
{
garpGmrpPortEnableGet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 4:
if (argc == 4)
{
garpGmrpPortEnableSet(&client_handle, atoi(argv[2]), atoi(argv[3]));
show_help = 0;
}
break;
case 5:
if (argc == 2)
{
garpGvrpEnableGet(&client_handle);
show_help = 0;
}
break;
case 6:
if (argc == 3)
{
garpGvrpEnableSet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 7:
if (argc == 3)
{
garpGvrpPortEnableGet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 8:
if (argc == 4)
{
garpGvrpPortEnableSet(&client_handle, atoi(argv[2]), atoi(argv[3]));
show_help = 0;
}
break;
case 9:
if (argc == 3)
{
garpJoinTimeGet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 10:
if (argc == 4)
{
garpJoinTimeSet(&client_handle, atoi(argv[2]), atoi(argv[3]));
show_help = 0;
}
break;
case 11:
if (argc == 3)
{
garpLeaveTimeGet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 12:
if (argc == 4)
{
garpLeaveTimeSet(&client_handle, atoi(argv[2]), atoi(argv[3]));
show_help = 0;
}
break;
case 13:
if (argc == 3)
{
garpLeaveAllTimeGet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 14:
if (argc == 4)
{
garpLeaveAllTimeSet(&client_handle, atoi(argv[2]), atoi(argv[3]));
show_help = 0;
}
break;
case 15:
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 GARP API example application");
return 0;
}