#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
int
main (int argc, char **argv)
{
uint32_t ifNum, minlinks, maxMem, lagIfNum;
char switch_os_revision_string[100];
char portChannelMembersListStr[32];
char buf[20];
uint32_t count = 0, mode;
uint32_t minThreshold, maxThreshold;
uint32_t *portChannelMembers;
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;
}
}
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,
}
}
}
while (0);
if (portChannelMembers)
{
free (portChannelMembers);
}
L7PROC_LOGF (L7PROC_LOG_SEVERITY_INFO, 0, "Stopping LAG API example application");
return 0;
}