#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
#define STRNCAT(_dst, _src) \
strncat((_dst), (_src), sizeof((_dst))-strlen((_dst))-1)
{
char str[256];
memset(&hashMode, 0, sizeof(hashMode));
{
printf("Bad return code trying to get non unicast hash mode. (result = %d)\n", result);
}
else
{
memset(&str, 0, sizeof(str));
{
STRNCAT(str, " Source Port");
}
{
STRNCAT(str, " Source MAC/IP");
}
{
STRNCAT(str, " Destination MAC/IP");
}
str[sizeof(str) - 1] = '\0';
printf("Global Load Balance Option:%s.\n", str);
}
return;
}
{
memset(&testHashMode, 0, sizeof(testHashMode));
lagNonUnicastGlobalHashModeGet(clientHandle);
{
printf("Bad return code trying to set non unicast hash mode. (result = %d)\n", result);
}
else
{
printf("Setting LAG non unicast hash mode successful.\n");
lagNonUnicastGlobalHashModeGet(clientHandle);
}
return;
}
{
uint32_t ifNum;
{
printf("Failed to verify parameter error while setting global Auto-LAG mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while setting global Auto-LAG mode. \n");
}
{
printf("Failed to verify parameter error while getting global Auto-LAG mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while getting global Auto-LAG mode. \n");
}
{
printf("Failed to verify parameter error while getting global Auto-LAG mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while getting global Auto-LAG mode. \n");
}
{
printf("Failed to verify parameter error while setting global Auto-LAG hash mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while setting global Auto-LAG hash mode. \n");
}
{
printf("Failed to verify parameter error while getting global Auto-LAG hash mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while getting global Auto-LAG hash mode. \n");
}
{
printf("Failed to verify parameter error while getting global Auto-LAG hash mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while getting global Auto-LAG hash mode. \n");
}
{
printf("Failed to verify parameter error while setting global Auto-LAG AVB profile mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while setting global Auto-LAG AVB profile mode. \n");
}
{
printf("Failed to verify parameter error while getting global Auto-LAG AVB profile mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while getting global Auto-LAG AVB profile mode. \n");
}
{
printf("Failed to verify parameter error while getting global Auto-LAG AVB profile mode. (result = %d)\n", result);
}
else
{
printf("Successfully verified parameter error while getting global Auto-LAG AVB profile mode. \n");
}
{
printf("Bad return code trying to enable Auto-LAG. (result = %d)\n", result);
}
else
{
printf("Successfully set global Auto-LAG mode to enable. \n");
}
{
printf("Successfully verified that global Auto-LAG mode is enabled. \n");
}
else
{
printf("Bad return code trying to get global Auto-LAG mode. (result = %d)\n", result);
}
{
printf("Bad return code trying to disable Auto-LAG. (result = %d)\n", result);
}
else
{
printf("Successfully set global Auto-LAG mode to disable. \n");
}
{
printf("Successfully verified that global Auto-LAG mode is disabled. \n");
}
else
{
printf("Bad return code trying to get global Auto-LAG mode. (result = %d)\n", result);
}
printf("Successfully configured and verified global Auto-LAG mode \n");
{
}
else
{
printf("Successfully set global Auto-LAG hash mode to enable. \n");
}
{
printf("Successfully verified that global Auto-LAG hash mode is set. \n");
}
else
{
printf("Bad return code trying to get global Auto-LAG hash mode. (result = %d)\n", result);
}
{
}
else
{
printf("Successfully set global Auto-LAG hash mode to enable. \n");
}
printf("Successfully configured and verified global Auto-LAG hash mode \n");
{
printf("Bad return code trying to enable Auto-LAG. (result = %d)\n", result);
}
else
{
printf("Successfully set global Auto-LAG mode to enable. \n");
}
{
printf("Successfully verified that global Auto-LAG AVB profile mode is enabled. \n");
}
else
{
printf("Bad return code trying to get global Auto-LAG AVB profile mode. (result = %d)\n", result);
}
{
printf("Bad return code trying to disable Auto-LAG AVB profile mode. (result = %d)\n", result);
}
else
{
printf("Successfully set global Auto-LAG AVB profile mode to disable. \n");
}
{
printf("Successfully verified that global Auto-LAG AVB profile mode is disabled. \n");
}
else
{
printf("Bad return code trying to get global Auto-LAG AVB profile mode. (result = %d)\n", result);
}
printf("Successfully configured and verified global Auto-LAG AVB profile mode \n");
{
printf(" Bad return code trying to get first physical interface. (result = %d)\n",result);
}
printf("Using LAG interface %d\n", ifNum);
{
printf("Successfully fetched the operational auto-LAG AVB profile mode on interface %d. \n", ifNum);
}
else
{
printf("Bad return code trying to fetch the operational auto-LAG AVB profile mode on interface %d. (result = %d)\n", ifNum, result);
}
printf("Successfully fetched the operational auto-LAG AVB profile mode \n");
{
printf("Successfully fetched the operational auto-LAG mode on interface %d. \n", ifNum);
}
else
{
printf("Bad return code trying to fetch the operational auto-LAG mode on interface %d. (result = %d)\n", ifNum, result);
}
printf("Successfully fetched the operational auto-LAG AVB profile mode \n");
return;
}
int
main (int argc, char **argv)
{
uint32_t ifNum, minlinks, maxMem, lagIfNum, intIfNum, val;
char switch_os_revision_string[100];
char portChannelMembersListStr[32];
char buf[20];
uint32_t count = 0, mode;
uint32_t minThreshold, maxThreshold;
uint32_t *portChannelMembers;
bool bTmp = false;
l7proc_crashlog_register ();
if ((result =
{
printf ("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
exit (2);
}
{
sleep (1);
}
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Starting LAG 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");
do
{
printf("Testing the maximum number of members per LAG supported on the platform\n");
{
printf ("Failed to get the maximum number of member ports \n");
}
else
{
printf("Maximum of [ %u ] member ports supported on this platform\n", maxMem);
}
printf ("Press enter to continue...\n");
getchar ();
printf("Attempting to get the first LAG interface to ADD members to it.\n");
{
printf(" Bad return code trying to get first LAG interface. (result = %d)\n", result);
break;
}
printf ("Using the first LAG interface %d\n", lagIfNum);
printf ("Adding ports from 1 to %d to LAG interface %d.\n", maxMem, lagIfNum);
for (ifNum = 1; ifNum < (maxMem + 1); ifNum++)
{
{
printf ("Failed to add interface %u to LAG interface %d\n", ifNum, lagIfNum);
break;
}
else
{
if (bTmp == false)
{
bTmp = true;
intIfNum = ifNum;
}
}
}
printf("\nTesting openapiLagPortChannelIdGet():\n");
printf(" Port channel ID of the interface: %d is %u \n\n", ifNum, val);
printf ("Getting the members list on LAG interface %d after ADD\n", lagIfNum);
memset(portChannelMembersListStr, 0, sizeof(portChannelMembersListStr));
portChannelMembersList.pstart = portChannelMembersListStr;
portChannelMembersList.size = sizeof(portChannelMembersListStr);
count = maxMem;
{
printf ("Failed to get the member ports for the LAG interface %d\n", lagIfNum);
}
else
{
memcpy(portChannelMembersListStr, portChannelMembersList.pstart, portChannelMembersList.size);
printf ("Comma delimited list of member ports for LAG interface %d (%d) (%s):\n", lagIfNum, count, portChannelMembersListStr);
}
count = maxMem;
portChannelMembers = (uint32_t *) malloc(maxMem * (sizeof(uint32_t)));
if (!portChannelMembers)
{
printf("Failed to allocate memory\n");
break;
}
portChannelMembersDesc.pstart = (char *) portChannelMembers;
portChannelMembersDesc.size = (maxMem * (sizeof(uint32_t)));
{
printf ("Failed to get the member ports for the LAG interface %d\n", lagIfNum);
}
else
{
printf ("List of member ports for LAG interface %d :\n", lagIfNum);
for (ifNum = 0; ifNum < count; ifNum++)
{
printf ("port : %d \n", portChannelMembers[ifNum]);
}
}
count = maxMem;
portChannelMembersDesc.pstart = (char *) portChannelMembers;
portChannelMembersDesc.size = (maxMem * (sizeof(uint32_t)));
printf ("Getting the active members list on LAG interface %d\n", lagIfNum);
{
printf("Failed to get the active member ports for the LAG interface %d\n", lagIfNum);
}
else
{
if (count == 0)
{
printf ("LAG interface %d does not have any ACTIVE members...\n", lagIfNum);
}
else
{
printf ("List of active member ports for LAG interface %d : \n", lagIfNum);
for (ifNum = 0; ifNum < count; ifNum++)
{
printf ("port : %d \n", portChannelMembers[ifNum]);
}
}
}
printf ("Deleting port 1 to %d from LAG interface %d\n", maxMem, lagIfNum);
for (ifNum = 1; ifNum < (maxMem + 1); ifNum++)
{
{
printf("Failed to delete interface %u from LAG inaterface %d\n", ifNum, lagIfNum);
break;
}
}
printf ("Getting the members list on LAG interface %d after DELETE\n", lagIfNum);
count = maxMem;
portChannelMembersDesc.pstart = (char *) portChannelMembers;
portChannelMembersDesc.size = (maxMem * (sizeof(uint32_t)));
{
printf("Failed to get the member ports for the LAG interface %d \n", lagIfNum);
}
else
{
if (count == 0)
{
printf ("LAG interface %d does not have any members...\n", lagIfNum);
}
else
{
printf ("List of member ports for LAG interface %d :\n", lagIfNum);
for (ifNum = 0; ifNum < count; ifNum++)
{
printf ("port : %d \n", portChannelMembers[ifNum]);
}
}
}
printf ("Press enter to continue...\n");
getchar ();
printf ("Testing LAG static mode set/get APIs\n");
printf ("Getting the current LAG interface %d static mode\n", lagIfNum);
{
printf ("Failed to get the static mode for the LAG interface: %d\n", lagIfNum);
break;
}
else
{
if (mode == 1)
{
sprintf (buf, "STATIC");
}
else
{
sprintf (buf, "DYNAMIC");
}
printf ("LAG interface %u is %s\n", lagIfNum, buf);
}
if (mode == 0)
{
mode = 1;
sprintf (buf, "STATIC");
}
else
{
mode = 0;
sprintf (buf, "DYNAMIC");
}
printf ("Now Setting the LAG interface %d static mode to %s\n", lagIfNum, buf);
{
printf ("Failed to set the LAG interface [%u] mode to %s\n", lagIfNum, buf);
break;
}
printf ("Verifying the LAG interface %d mode after SET\n", lagIfNum);
{
printf ("Failed to get the static mode for the LAG interface %d\n", lagIfNum);
break;
}
else
{
if (mode == 1)
{
sprintf (buf, "STATIC");
}
else
{
sprintf (buf, "DYNAMIC");
}
printf ("LAG interface %u is %s\n", lagIfNum, buf);
}
printf ("Press enter to continue...\n");
getchar ();
printf ("Testing LAG name set/get APIs\n");
printf ("Getting the current LAG name config\n");
memset (buf, 0, sizeof (buf));
name.pstart = buf;
name.size = sizeof (buf);
{
printf ("Failed to get the name for the LAG interface %d\n",
lagIfNum);
break;
}
else
{
printf ("LAG interface %u name %s\n", lagIfNum, (char *)name.pstart);
}
printf("Setting the LAG names to 'TEST123' LAG interface %d\n", lagIfNum);
memset (buf, 0, sizeof (buf));
sprintf (buf, "TEST123");
name.pstart = buf;
name.size = sizeof (buf);
{
printf ("Failed to set the LAG interface [%u] name to 'TEST123'\n", lagIfNum);
break;
}
printf ("Verifying the LAG interface %d name after SET \n", lagIfNum);
{
printf ("Failed to get the name for the LAG interface %d\n", lagIfNum);
break;
}
else
{
printf ("LAG interface %u name %s\n", lagIfNum, (char *) name.pstart);
}
printf ("Press enter to continue...\n");
getchar ();
printf ("Testing LAG hashmode set/get APIs\n");
printf ("Getting the current hashmode for LAg interface %d\n", lagIfNum);
{
printf ("Failed to get the hashmode for the LAG interface %d\n", lagIfNum);
break;
}
else
{
printf ("LAG interface %u hashmode %d\n", lagIfNum, hashmode);
}
printf ("Setting the LAG hashmode to 6 for LAG interface %d\n", lagIfNum);
hashmode = 6;
{
printf ("Failed to set the LAG interface [%u] hashmode to '6'\n", lagIfNum);
break;
}
printf ("Verifying the LAG interface %d hashmode after SET \n", lagIfNum);
{
printf ("Failed to get the hashmode for the LAG interface %d\n", lagIfNum);
break;
}
else
{
printf ("LAG interface %u hashmode %d\n", lagIfNum, hashmode);
}
printf ("Press enter to continue...\n");
getchar ();
printf ("Testing LAG minimum uplinks set/get APIs\n");
{
printf("Failed to get the Threshold minimum and maximum ranges values\n");
break;
}
else
{
printf ("LAG Threshold ranges are %d - %d\n", minThreshold, maxThreshold);
}
printf ("Getting the minimum uplinks for LAG interface %d\n", lagIfNum);
{
printf("Failed to get the minimum uplinks for the LAG interface %d\n", lagIfNum);
break;
}
else
{
printf ("LAG interface %u minimum uplinks %d\n", lagIfNum, minlinks);
}
printf ("Setting the LAG minimum uplinks to '8' for LAG interface %d\n", lagIfNum);
minlinks = 8;
{
printf ("Failed to set the LAG interface [%u] minimum uplinks to '8'\n", lagIfNum);
break;
}
printf("Verifying the minimum uplinks for LAG interface %d after SET \n", lagIfNum);
{
printf ("Failed to get the minimum uplinks for LAG interface %d\n", lagIfNum);
break;
}
else
{
printf ("LAG interface %u minimum uplinks %d\n", lagIfNum, minlinks);
}
printf("Getting the port LACP mode for interface : 1\n");
{
printf("Failed to get the port LACP mode for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP mode : %s \n",(lacpMode ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
printf(
" Setting port LACP mode of interface : 1 to : %s\n",(lacpMode !=
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
{
printf("Failed to set the port LACP mode for interface : 1 \n");
break;
}
else
{
printf("Getting the port LACP mode after set...\n");
{
printf("Failed to get the port LACP mode for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP mode : %s \n",(lacpMode ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
}
printf("Getting the port LACP actor admin state for interface : 1\n");
{
printf("Failed to get the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP actor admin state 'aggregation' : %s \n",(state ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
printf(
" Setting LACP actor admin state 'aggregation' of interface : 1 to : %s\n",(state !=
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
{
printf("Failed to set the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf("Getting the LACP actor admin state 'aggregation' after set...\n");
{
printf("Failed to get the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP actor admin state 'aggregation' : %s \n",(state ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
}
{
printf("Failed to get the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP actor admin state 'short timeout' : %s \n",(state ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
printf(
" Setting LACP actor admin state 'short timeout' of interface : 1 to : %s\n",(state !=
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
{
printf("Failed to set the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf("Getting the LACP actor admin state 'short timeout' after set...\n");
{
printf("Failed to get the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP actor admin state 'short timeout' : %s \n",(state ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
}
{
printf("Failed to get the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP actor admin state 'active' : %s \n",(state ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
printf(
" Setting LACP actor admin state 'active' of interface : 1 to : %s\n",(state !=
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
{
printf("Failed to set the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf("Getting the LACP actor admin state 'active' after set...\n");
{
printf("Failed to get the LACP actor admin state for interface : 1 \n");
break;
}
else
{
printf(
" interface : 1 LACP actor admin state 'active' : %s \n",(state ==
OPEN_ENABLE) ?
"ENABLE" :
"DISABLE");
}
}
printf ("Press enter to continue...\n");
getchar ();
printf("Getting the LAG admin mode...\n");
{
printf("Failed to get the LAG admin mode for interface : %d \n", lagIfNum);
break;
}
else
{
printf(" interface : %d LAG mode : %s \n", lagIfNum,
}
printf(" Setting LAG admin mode of interface :%d to : %s\n", lagIfNum,
{
printf("Failed to set LAG admin mode for interface : %d \n", lagIfNum);
break;
}
else
{
printf("Getting the LAG admin mode after set...\n");
{
printf("Failed to get the LAG admin mode for interface : %d \n", lagIfNum);
break;
}
else
{
printf(" interface : %d LAG mode : %s \n", lagIfNum,
}
}
printf("\nTesting openapiLagLinkTrapGet():\n");
printf(" interface : %d LAG link trap mode: %s \n", lagIfNum,
printf("Testing openapiLagLinkTrapSet() with val %s...\n",
printf("Verifying link trap mode after set:\n");
printf(" interface : %d LAG link trap mode: %s \n", lagIfNum,
printf("\nTesting openapiLagAggPortActorSystemPriorityGet():\n");
printf(" LAG port actor system priority: %d \n", val);
val = (val == OPEN_LAG_PORT_ACTOR_SYSTEM_PRIORITY_DEFAULT) ?
(OPEN_LAG_PORT_ACTOR_SYSTEM_PRIORITY_MAX) :
OPEN_LAG_PORT_ACTOR_SYSTEM_PRIORITY_DEFAULT;
printf("Testing openapiLagAggPortActorSystemPrioritySet() with val %d...\n", val);
printf("Verifying port actor system priority after set:\n");
printf(" LAG port actor system priority: %d \n", val);
printf("\nTesting openapiLagAggPortActorPortPriorityGet():\n");
printf(" interface : %d LAG port actor port priority: %d \n", intIfNum, val);
val = (val == OPEN_LAG_PORT_ACTOR_PORT_PRIORITY_DEFAULT) ?
OPEN_LAG_PORT_ACTOR_PORT_PRIORITY_DEFAULT;
printf("Testing openapiLagAggPortActorPortPrioritySet() with val %d...\n", val);
printf("Verifying port actor port priority after set:\n");
printf(" interface : %d LAG port actor port priority: %d \n", intIfNum, val);
printf("\nTesting openapiLagCountGet():\n");
printf(" Count of all the LAGs on the device: %d \n", val);
printf("\nTesting openapiLagIfIndexGetFirst():\n");
printf(" Interface index of the first LAG interface: %d \n", val);
printf("\nTesting openapiLagIfIndexGetNext():\n");
printf(" Interface index of the next LAG interface: %d \n", val);
}
while (0);
if (portChannelMembers)
{
free (portChannelMembers);
}
autoLAGConfigAndVerify(&clientHandle);
lagNonUnicastGlobalHashModeSetGetVerify(&clientHandle);
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Stopping LAG API example application");
return 0;
}