#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
#define VLAN_ID_MIN 1
#define VLAN_ID_MAX 1024
#define IF_PRIORITY 3
#define RETRY_COUNT 10
#define RETRY_INTERVAL_MSEC 100000
{
uint32_t i;
uint32_t vlanNameLen;
char *vlanName = NULL;
{
printf(" Bad return code trying to create VLAN %u. (result = %d)\n", vlanId, result);
}
else
{
for (i=0; i < RETRY_COUNT; i++)
{
{
break;
}
else
{
usleep(RETRY_INTERVAL_MSEC);
}
}
{
{
printf(" Bad return code trying to get VLAN Name Length. (result = %d)\n", result);
}
else
{
vlanName = (char*)malloc(vlanNameLen);
if (vlanName == NULL)
{
printf(" Could not allocate memory for VLAN name.\n");
}
else
{
memset(vlanName, 0, vlanNameLen);
sprintf(vlanName, "vlanName%u", vlanId);
vlanNameDesc.
pstart = vlanName;
vlanNameDesc.
size = strlen(vlanName) + 1;
{
printf(" Bad return code trying to set VLAN %u name. (result = %d)\n", vlanId, result);
}
else
{
memset(vlanName, 0, vlanNameLen);
vlanNameDesc.size = vlanNameLen;
{
printf(" Bad return code trying to get VLAN %u name. (result = %d)\n", vlanId, result);
}
else
{
printf(" VLAN %u name = %s\n", vlanId, vlanName);
}
}
}
}
}
else
{
printf(" Could not verify that VLAN %u is created. (result = %d)\n", vlanId, result);
}
}
if (vlanName)
{
free(vlanName);
}
return(result);
}
{
uint32_t i;
{
printf(" Bad return code trying to create VLAN %u. (result = %d)\n", vlanId, result);
}
else
{
for (i=0; i < RETRY_COUNT; i++)
{
{
break;
}
else
{
usleep(RETRY_INTERVAL_MSEC);
}
}
}
{
}
return(result);
}
uint32_t ifNum,
{
uint32_t newType;
uint32_t i;
{
printf(" Bad return code trying to set Accept Frame Type. (result = %d)\n", result);
}
else
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf(" Bad return code trying to get Accept Frame Type. (result = %d)\n", result);
break;
}
else
{
if (newType != type)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (newType != type)
{
}
}
return(result);
}
{
uint32_t newVlanId;
uint32_t i;
{
printf(" Bad return code trying to set PVID. (result = %d)\n", result);
}
else
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf(" Bad return code trying to get PVID. (result = %d)\n", result);
break;
}
else
{
if (newVlanId != vlanId)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (newVlanId != vlanId)
{
}
}
return(result);
}
{
uint32_t i;
{
printf(" Bad return code trying to set VLAN participation configuration. (result = %d, ifNum = %u, partStatus = %u)\n", result, ifNum, partStatus);
}
else
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf(" Bad return code trying to get VLAN participation configuration. (result = %d, ifNum = %u, partStatus = %u)\n", result, ifNum, partStatus);
break;
}
else
{
if (newPartStatus != partStatus)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (newPartStatus != partStatus)
{
}
}
return(result);
}
{
uint32_t i;
{
printf(" Bad return code trying to set VLAN tagging configuration. (result = %d, ifNum = %u, taggingMode = %u)\n", result, ifNum, taggingMode);
}
else
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf(" Bad return code trying to get VLAN tagging configuration. (result = %d, ifNum = %u, taggingMode = %u)\n", result, ifNum, taggingMode);
break;
}
else
{
if (newTaggingMode != taggingMode)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (newTaggingMode != taggingMode)
{
}
}
return(result);
}
uint32_t priority)
{
uint32_t i;
uint32_t numTrafficClasses;
uint32_t newPriority;
{
printf(" Bad return code trying to the number of traffic classes supported. (result = %d, ifNum = %u)\n", result, ifNum);
}
if (priority > numTrafficClasses)
{
printf(" Parameter value for priority out of accepted range. (priority = %u, numTrafficClasses = %u)\n", priority, numTrafficClasses);
}
{
printf(" Bad return code trying to set user priority. (result = %d, ifNum = %u, priority = %u)\n", result, ifNum, priority);
}
else
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf(" Bad return code trying to get user priority. (result = %d, ifNum = %u)\n", result, ifNum);
break;
}
else
{
if (newPriority != priority)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (newPriority != priority)
{
}
}
return(result);
}
uint32_t primary_vlan,
uint32_t isolated_vlan,
uint32_t community_vlan)
{
OPEN_DOT1Q_PVLAN_TYPE_t pvlanType, tmpVal;
uint32_t i;
{
printf("Bad return code trying to create VLAN %u. (result = %d)\n", primary_vlan, result);
}
else
{
pvlanType = OPEN_PRIVATE_VLAN_PRIMARY;
{
printf("Bad return code trying to configure a VLAN as Primary VLAN %u. (result = %d)\n", primary_vlan, result);
}
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf("Bad return code trying to get Type for VLAN %u. (result = %d)\n", primary_vlan, result);
}
else
{
if (tmpVal != pvlanType)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (tmpVal != pvlanType)
{
printf("Failure configuring Primary VLAN %u. \n", primary_vlan);
}
else
{
printf("Successfully configured and verified Primary VLAN %u. \n", primary_vlan);
}
}
}
{
printf("Bad return code trying to create VLAN %u. (result = %d)\n", isolated_vlan, result);
}
else
{
pvlanType = OPEN_PRIVATE_VLAN_SECONDARY_ISOLATED;
{
printf("Bad return code trying to configure a VLAN as Isolated VLAN %u. (result = %d)\n", isolated_vlan, result);
}
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf("Bad return code trying to get Type for VLAN %u. (result = %d)\n", isolated_vlan, result);
}
else
{
if (tmpVal != pvlanType)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (tmpVal != pvlanType)
{
printf("Failure configuring Isolated VLAN %u. \n", isolated_vlan);
}
else
{
printf("Successfully configured and verified Isolated VLAN %u. \n", isolated_vlan);
}
}
}
{
printf("Bad return code trying to create VLAN %u. (result = %d)\n", community_vlan, result);
}
else
{
pvlanType = OPEN_PRIVATE_VLAN_SECONDARY_COMMUNITY;
{
printf("Bad return code trying to configure a VLAN as Community VLAN %u. (result = %d)\n", community_vlan, result);
}
{
for (i=0; i < RETRY_COUNT; i++)
{
{
printf("Bad return code trying to get Type for VLAN %u. (result = %d)\n", community_vlan, result);
}
else
{
if (tmpVal != pvlanType)
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
if (tmpVal != pvlanType)
{
printf("Failure configuring Community VLAN %u. \n", community_vlan);
}
else
{
printf("Successfully configured and verified Community VLAN %u. \n", community_vlan);
}
}
}
memset(&vidList, 0, sizeof(vidList));
vidList.
ids[0] = isolated_vlan;
vidList.
ids[1] = community_vlan;
{
printf("Bad return code trying to associate VLANs with Primary VLAN %u. (result = %d)\n", primary_vlan, result);
}
else
{
memset(&tmpList, 0, sizeof(tmpList));
{
printf("Bad return code trying to get associated VLANs with Primary VLAN %u. (result = %d)\n", primary_vlan, result);
}
else
{
printf("VLAN list set: ");
{
printf(
"%d", vidList.
ids[i]);
{
printf(", ");
}
}
printf("\n");
printf("VLAN list retrieved: ");
{
printf(
"%d", tmpList.
ids[i]);
{
printf(", ");
}
}
printf("\n");
}
{
printf("Bad return code trying to remove VLANs associated with Primary VLAN %u. (result = %d)\n", primary_vlan, result);
}
else
{
printf("Successfully removed VLANs associated with Primary VLAN %u. \n", primary_vlan);
}
}
printf("Successfully configured and verified VLAN association with Primary VLAN. \n");
return;
}
uint32_t ifNum,
uint32_t primary_vlan,
uint32_t secondary_vlan)
{
uint32_t tmpVal1, tmpVal2;
{
printf("Bad return code trying to bind VLANs for Private VLAN interface %u. (result = %d)\n", ifNum, result);
}
else
{
printf("Successfully set VLAN bindings for Private VLAN interface %u. \n", ifNum);
}
{
printf("Bad return code trying to get VLAN bindings for Private VLAN interface %u. (result = %d)\n", ifNum, result);
}
else
{
if (tmpVal1 == primary_vlan)
{
printf("Successfully binded Primary VLAN to Private VLAN interface %u. \n", ifNum);
}
if (tmpVal2 == secondary_vlan)
{
printf("Successfully binded Secondary VLAN to Private VLAN interface %u. \n", ifNum);
}
}
{
printf("Bad return code trying to remove VLAN bindings for Private VLAN interface %u. (result = %d)\n", ifNum, result);
}
else
{
printf("Successfully removed VLAN bindings on interface %u \n", ifNum);
}
printf("Successfully configured and verified VLAN bindings for Private VLAN interface %u \n", ifNum);
return;
}
uint32_t ifNum,
uint32_t primary_vlan,
{
uint32_t tmpVal, i = 0;
{
printf("Bad return code trying to bind VLANs for Private VLAN interface %u. (result = %d)\n", ifNum, result);
}
else
{
printf("Successfully set VLAN bindings for Private VLAN interface %u. \n", ifNum);
}
{
printf("Bad return code trying to get VLAN bindings for Private VLAN interface %u. (result = %d)\n", ifNum, result);
}
else
{
if (tmpVal == primary_vlan)
{
printf("Successfully binded Primary VLAN to Private VLAN interface %u. \n", ifNum);
}
printf("VLAN list set: ");
{
printf(
"%d", tmpList.
ids[i]);
{
printf(", ");
}
}
printf("\n");
}
{
printf("Bad return code trying to remove VLAN bindings for Private VLAN interface %u. (result = %d)\n", ifNum, result);
}
else
{
printf("Successfully removed VLAN bindings on interface %u \n", ifNum);
}
printf("Successfully configured and verified VLAN bindings for Private VLAN interface %u \n", ifNum);
return;
}
int main(int argc, char **argv)
{
uint32_t ifNum, i;
char switch_os_revision_string[100];
uint32_t partStatus;
uint32_t vlanId, nextVlanId;
uint32_t vlanFlag = 0;
uint32_t vlanId1 = 0, vlanId2 = 0, vlanId3 = 0;
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 VLAN 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
{
for (vlanId = VLAN_ID_MIN; vlanId < VLAN_ID_MAX; vlanId++)
{
{
break;
}
}
if (vlanId >= VLAN_ID_MAX)
{
printf(" Could not find an unused VLAN to configure.\n");
break;
}
printf("Using VLAN ID %u.\n", vlanId);
printf("\n");
printf("Testing VLAN create/delete/check APIs.\n");
printf("Attempting to create VLAN %u.\n", vlanId);
if (vlanCreateAndVerify(&clientHandle, vlanId) !=
OPEN_E_NONE)
{
printf(" Failure creating VLAN %u.\n", vlanId);
break;
}
printf(" Successfully created VLAN %u.\n", vlanId);
printf("Attempting to delete VLAN %u.\n", vlanId);
if (vlanDeleteAndVerify(&clientHandle, vlanId) !=
OPEN_E_NONE)
{
printf(" Failure deleting VLAN %u.\n", vlanId);
break;
}
printf(" Successfully deleted VLAN %u.\n", vlanId);
printf("\n");
printf("Testing PVID set/get APIs.\n");
printf("Attempting to create VLAN %u.\n", vlanId);
if (vlanCreateAndVerify(&clientHandle, vlanId) !=
OPEN_E_NONE)
{
printf(" Failure creating VLAN %u.\n", vlanId);
break;
}
printf(" Successfully created VLAN %u.\n", vlanId);
printf("Attempting to set the first physical interface to participate in VLAN %u.\n", vlanId);
{
printf(" Bad return code trying to get first physical interface. (result = %d)\n", result);
break;
}
printf("Using physical interface with ifNum = %u.\n", ifNum);
printf("\n");
{
printf(" Failure setting Acceptable Frame Type for ifNum %u.\n", ifNum);
break;
}
printf(" Successfully set Acceptable Frame Type for ifNum %u.\n", ifNum);
printf("\n");
printf("Attempting to set PVID for interface to %u.\n", vlanId);
if (interfacePvidSetAndVerify(&clientHandle, ifNum, vlanId) !=
OPEN_E_NONE)
{
printf(" Failure setting PVID for ifNum %u to VLAN %u.\n", ifNum, vlanId);
break;
}
printf(" Successfully set PVID for ifNum %u to VLAN %u.\n", ifNum, vlanId);
printf("\n");
printf("Attempting to set participation mode for interface %u on VLAN %u to INCLUDE.\n", ifNum, vlanId);
{
printf(" Failure setting VLAN participation mode for ifNum %u on VLAN %u.\n", ifNum, vlanId);
break;
}
printf(" Successfully set VLAN participation mode for ifNum %u on VLAN %u.\n", ifNum, vlanId);
printf("Attempting to get the VLAN participation status.\n");
for (i=0; i < RETRY_COUNT; i++)
{
{
break;
}
else
{
{
usleep(RETRY_INTERVAL_MSEC);
}
else
{
break;
}
}
}
{
printf(" Bad return code trying to get participation status. (result = %d)\n", result);
break;
}
else
{
printf(" Successfully retrieved participation status for ifNum = %u. - ", ifNum);
printf(
"This is %sas expected.\n", (partStatus ==
OPEN_ENABLE) ?
"":
"NOT ");
}
printf("\n");
printf("Attempting to set tagging mode for interface %u on VLAN %u to ENABLE.\n", ifNum, vlanId);
{
printf(" Failure setting VLAN tagging mode for ifNum %u on VLAN %u.\n", ifNum, vlanId);
break;
}
printf(" Successfully set VLAN tagging mode for ifNum %u on VLAN %u.\n", ifNum, vlanId);
printf("Attempting to set tagging mode for interface %u on VLAN %u to DISABLE.\n", ifNum, vlanId);
{
printf(" Failure setting VLAN tagging mode for ifNum %u on VLAN %u.\n", ifNum, vlanId);
break;
}
printf(" Successfully set VLAN tagging mode for ifNum %u on VLAN %u.\n", ifNum, vlanId);
printf("\n");
printf("Attempting to delete VLAN %u.\n", vlanId);
if (vlanDeleteAndVerify(&clientHandle, vlanId) !=
OPEN_E_NONE)
{
printf(" Failure deleting VLAN %u.\n", vlanId);
break;
}
printf(" Successfully deleted VLAN %u.\n", vlanId);
printf("\n");
printf("Attempting to set default priority for interface %u to %u.\n", ifNum, IF_PRIORITY);
if (interfacePrioritySetAndVerify(&clientHandle, ifNum, IF_PRIORITY) !=
OPEN_E_NONE)
{
printf(" Failure setting default priority for interface %u.\n", ifNum);
break;
}
printf(" Successfully set default priority for interface %u.\n", ifNum);
} while (0);
printf("\n");
printf("Testing vlan get next API.\n");
printf("Attempting to check if there are any vlans.\n");
for (vlanId = VLAN_ID_MIN+1; vlanId < VLAN_ID_MAX; vlanId++)
{
{
vlanFlag = 1;
break;
}
}
if (!vlanFlag)
{
printf(" Creating vlans as there are no vlans other than default vlan.\n");
for (vlanId = VLAN_ID_MIN+1; vlanId <= 10; vlanId++)
{
if ((result = vlanCreateAndVerify(&clientHandle, vlanId)) !=
OPEN_E_NONE)
{
printf(" Bad return code trying to create VLAN %u. (result = %d)\n", vlanId, result);
break;
}
}
}
{
printf(" Vlans present: ");
}
else
{
printf(" Failed to get next vlan.(result = %d)\n", result);
}
{
printf(" %u", nextVlanId);
}
printf("\n\n");
if (!vlanFlag)
{
printf("Attempting to delete created vlans.\n");
nextVlanId = VLAN_ID_MIN;
{
{
printf(" Bad return code trying to delete VLAN %u. (result = %d)\n", nextVlanId, result);
break;
}
}
{
printf(" Successfully deleted the created vlans.\n");
}
}
vlanId1 = 10;
vlanId2 = 20;
vlanId3 = 30;
privateVlanCreateAndVerify(&clientHandle, vlanId1, vlanId2, vlanId3);
ifNum = 5;
interfaceHostPrivateVlanCreateAndVerify(&clientHandle, ifNum, vlanId1, vlanId2);
ifNum = 6;
interfacePromiscPrivateVlanCreateAndVerify(&clientHandle, ifNum, vlanId1, vidList);
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping VLAN API example application");
return 0;
}