#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
#define OPENAPI_TITLE "Static Filter"
#define MAC_STRING_SIZE 18
#define INTF_LIST_STR_SIZE ((4 * 1024) +1)
static void printAppMenu(char *name)
{
printf("Usage: %s <test#> <arg1> <arg2> ... \n", name);
printf("Test 1: Sets the static MAC filter admin mode: %s 1 <adminMode>\n", name);
printf("Test 2: Gets the static MAC filter admin mode: %s 2 \n", name);
printf("Test 3: Creates a static MAC filter: %s 3 <macAddr> <vlanId>\n", name);
printf("Test 4: Deletes a static MAC filter: %s 4 <macAddr> <vlanId>\n", name);
printf("Test 5: Apply a comma separated source interface list to the static MAC filter: %s 5 "
"<macAddr> <vlanId> <srcIntfList>\n", name);
printf("Test 6: Adds a source interface to the static MAC filter: %s 6 "
"<macAddr> <vlanId> <ifNum>\n", name);
printf("Test 7: Deletes a source interface from the source interface list of "
"the static MAC filter: %s 7 <macAddr> <vlanId> <ifNum>\n", name);
printf("Test 8: Adds a destination interface to the static MAC filter: %s 8 "
"<macAddr> <vlanId> <ifNum>\n", name);
printf("Test 9: Deletes a destination interface from the destination interface"
" list of the static MAC filter: %s 9 <macAddr> <vlanId> <ifNum>\n", name);
printf("Test 10: Adds a comma separated destination interface list to the "
"static MAC filter: %s 10 <macAddr> <vlanId> <ifNum> <fwdIntfList> "
"<filterList>\n", name);
printf("Test 11: Deletes a comma separated destination interface list from "
"the static MAC filter: %s 11 <macAddr> <vlanId> <ifNum> <fwdIntfList>"
" <filterList>\n", name);
printf("Test 12: Gets the first configured MAC static filter: %s 12 \n", name);
printf("Test 13: Gets the next configured MAC static filter: %s 13 <macAddr> "
"<vlanId> \n", name);
printf("Test 14: Gets list of source interfaces for a MAC static filter: %s 14 "
"<macAddr> <vlanId> \n", name);
printf("Test 15: Gets list of destination interfaces for a MAC static filter: %s"
" 15 <macAddr> <vlanId> \n", name);
printf("Test 16: Gets the number of MAC static filters configured: %s 16 \n", name);
printf("Test 17: Gets the number of total, multicast and unicast MAC static filters"
" configured: %s 17 \n", name);
printf("Test 18: Checks to see if a MAC filter is configured or not: %s 18 <macAddr>"
" <vlanId> \n", name);
printf("Test 19: Gets the buffer size used by filtering component for the bit mask:"
" %s 19 \n", name);
printf("Test 20: Checks if a particular interface is present in any MAC filter: "
"%s 20 <ifNum>\n", name);
printf("Test 21: Check to see if the port is the appropriate type on which the"
" param can be set: %s 21 <ifNum> \n", name);
printf("Test 22: Checks to see the mac address type, unicast or multicast: %s "
"22 <macAddr>\n", name);
printf("Test 23: Set multicast address filtering configuration for all vlans: "
"%s 23 <mode>\n", name);
printf("Test 24: Sets multicast address filtering configuration for the "
"specified vlan: %s 24 <vlanId> <mode>\n", name);
printf("Test 25: Gets multicast address filtering configuration for the "
"specified vlan: %s 25 <vlanId> \n", name);
printf("Test 26: Checks if the interface is valid for filtering: %s 26 "
"<ifNum> \n", name);
printf("Test 27: Sets the stream id of an existing macfilter with given MAC"
" address and vlan id: %s 27 <macAddr> <vlanId> <streamId>\n", name);
printf("Test 28: Gets the configured stream id: %s 28 <macAddr> <vlanId> \n",
name);
printf("Test 29: Gets list of destination filter interfaces for a MAC "
"static filter: %s 29 <macAddr> <vlanId> \n", name);
return;
}
{
{
printf("Bad return code trying to sets the static MAC filter admin "
"mode. (result = %d)\n", result);
}
else
{
printf("Static MAC filter admin mode set successfully.\n");
}
return;
}
{
{
printf("Bad return code trying to gets the static MAC filter "
"admin mode. (result = %d)\n", result);
}
else
{
printf("Static MAC filter admin mode is %u.\n", *adminMode);
}
return;
}
uint32_t vlanID)
{
buffDesc.
pstart = macStr;
buffDesc.
size = (OPEN_MAC_ADDR_LEN*3);
{
printf("Bad return code trying to create a MAC Static Filter. "
"(result = %d)\n", result);
}
else
{
printf("%s mac=%s vlan=%u created. (result = %d)\n",
OPENAPI_TITLE, macStr, vlanID, result);
}
return;
}
uint32_t vlanID)
{
buffDesc.pstart = macStr;
buffDesc.size = (OPEN_MAC_ADDR_LEN*3);
{
printf("Bad return code trying to remove a configured MAC "
"Static Filter. (result = %d)\n", result);
}
else
{
printf("%s mac=%s vlan=%u removed. (result = %d)\n",
OPENAPI_TITLE, macStr, vlanID, result);
}
return;
}
char *macAddr, uint32_t vlanId,
char *srcIntfList)
{
char mac[MAC_STRING_SIZE] = "";
char intfStr[INTF_LIST_STR_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
strncpy(intfStr, srcIntfList, INTF_LIST_STR_SIZE-1);
intfList.pstart = intfStr;
intfList.size = strlen (intfStr);
vlanId, &intfList))
{
printf("Bad return code trying to apply a source interface List to "
"the static MAC filter. (result = %d)\n", result);
}
else
{
printf("List of source interface(s) applied successfully to static MAC"
" filter.\n");
}
return;
}
char *macAddr, uint32_t vlanId, uint32_t ifNum)
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to adds a source interface to the static "
"MAC filter. (result = %d)\n", result);
}
else
{
printf("Source interface addition to static MAC filter was successful.\n");
}
return;
}
char *macAddr, uint32_t vlanId,
uint32_t ifNum)
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to deletes a source interface from the source "
"interface list of the static MAC filter. (result = %d)\n", result);
}
else
{
printf("Source interface deletion from static MAC filter was successful.\n");
}
return;
}
char *macAddr, uint32_t vlanId, uint32_t ifNum)
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to adds a destination interface to the static"
" MAC filter. (result = %d)\n", result);
}
else
{
printf("Destination interface addition to static MAC filter was successful.\n");
}
return;
}
char *macAddr, uint32_t vlanId,
uint32_t ifNum)
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to deletes a destination interface from"
" the destination interface list of the static MAC filter. (result = %d)\n",
result);
}
else
{
printf("Destination interface deletion from static MAC filter was successful.\n");
}
return;
}
char *macAddr, uint32_t vlanId,
uint32_t ifNum, char *fwdIntfList,
char *filterIntfList)
{
char mac[MAC_STRING_SIZE] = "";
char intfStr[INTF_LIST_STR_SIZE] = "";
char filtIntfStr[INTF_LIST_STR_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
strncpy(intfStr, fwdIntfList, INTF_LIST_STR_SIZE-1);
intfList.pstart = intfStr;
intfList.size = strlen (intfStr);
strncpy(filtIntfStr, filterIntfList, INTF_LIST_STR_SIZE-1);
filIntfList.pstart = filtIntfStr;
filIntfList.size = strlen (filtIntfStr);
ifNum, &intfList, &filIntfList))
{
printf("Bad return code trying to adds destination interfaces to the "
"static MAC filter. (result = %d)\n", result);
}
else
{
printf("Addition of destination interface(s) to static MAC filter was "
"successful.\n");
}
return;
}
char *macAddr, uint32_t vlanId,
uint32_t ifNum, char *fwdIntfList,
char *filterIntfList)
{
char mac[MAC_STRING_SIZE] = "";
char intfStr[INTF_LIST_STR_SIZE] = "";
char filtIntfStr[INTF_LIST_STR_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
strncpy(intfStr, fwdIntfList, INTF_LIST_STR_SIZE-1);
intfList.pstart = intfStr;
intfList.size = strlen (intfStr);
strncpy(filtIntfStr, filterIntfList, INTF_LIST_STR_SIZE-1);
filIntfList.pstart = filtIntfStr;
filIntfList.size = strlen (filtIntfStr);
ifNum, &intfList, &filIntfList))
{
printf("Bad return code trying to adds destination interfaces to the "
"static MAC filter. (result = %d)\n", result);
}
else
{
printf("Deletion of destination interface(s) from static MAC filter was "
"successful.\n");
}
return;
}
{
char mac[MAC_STRING_SIZE] = "";
uint32_t vlanId;
bufId.pstart = mac;
bufId.size = MAC_STRING_SIZE;
{
printf("Bad return code trying to gets the first configured MAC "
"static filter. (result = %d)\n", result);
}
else
{
printf("First filter's MAC : %s, vlanId : %u.\n", mac, vlanId);
}
return;
}
char *macAddr, uint32_t vlanId)
{
char mac[MAC_STRING_SIZE] = "";
char nextMacStr[MAC_STRING_SIZE] = "";
uint32_t nextVlanId;
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
nextMac.pstart = nextMacStr;
nextMac.size = MAC_STRING_SIZE;
{
printf("Bad return code trying to gets the next configured MAC static "
"filter. (result = %d)\n", result);
}
else
{
printf("Next filter's MAC : %s, vlanId : %u.\n", nextMacStr, nextVlanId);
}
return;
}
char *macAddr, uint32_t vlanId)
{
char mac[MAC_STRING_SIZE] = "";
char intfStr[INTF_LIST_STR_SIZE] = "";
uint32_t numOfSrcIntf;
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
intfList.pstart = intfStr;
intfList.size = INTF_LIST_STR_SIZE;
&numOfSrcIntf, &intfList))
{
printf("Bad return code trying to gets list of source interfaces for a"
" MAC static filter. (result = %d)\n", result);
}
else
{
printf("List of source interfaces for a filter is:\n%s\n", intfStr);
}
return;
}
char *macAddr, uint32_t vlanId)
{
char mac[MAC_STRING_SIZE] = "";
char intfStr[INTF_LIST_STR_SIZE] = "";
uint32_t numOfDstIntf;
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
intfList.pstart = intfStr;
intfList.size = INTF_LIST_STR_SIZE;
&numOfDstIntf, &intfList))
{
printf("Bad return code trying to gets list of source interfaces for a"
" MAC static filter. (result = %d)\n", result);
}
else
{
printf("List of destination interfaces for a filter is:\n%s\n", intfStr);
}
return;
}
{
{
printf("Bad return code trying to gets the number of MAC static filters "
"configured. (result = %d)\n", result);
}
else
{
printf("Number of MAC static filters : %u\n", *count);
}
return;
}
{
uint32_t totalCount, multicastFiltCount, unicastFiltCount;
&multicastFiltCount, &unicastFiltCount))
{
printf("Bad return code trying to gets the number of total, multicast and "
"unicast MAC static filters configured. (result = %d)\n", result);
}
else
{
printf("Total number of MAC static filters : %u \n", totalCount);
printf("Number of multicast MAC static filters : %u \n", multicastFiltCount);
printf("Number of unicast MAC static filters : %u \n", unicastFiltCount);
}
return;
}
char *macAddr, uint32_t vlanId,
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to checks to see if a MAC filter is "
"configured or not. (result = %d)\n", result);
}
else
{
printf(
"MAC filter is %sconfigured.\n", (*status ==
OPEN_TRUE) ?
"" :
"not ");
}
return;
}
{
{
printf("Bad return code trying to gets the buffer size used by "
"filtering component for the bit mask. (result = %d)\n", result);
}
else
{
printf("Buffer size used by filtering component : %u.\n", *size);
}
return;
}
{
{
printf("Bad return code trying to checks if a particular interface is "
"present in any MAC filter. (result = %d)\n", result);
}
else
{
printf("Interface %u is %sconfigured in MAC filter.\n", ifNum,
}
return;
}
{
{
printf("Bad return code trying to check to see if the port is the "
"appropriate type on which the parm can be set. (result = %d)\n",
result);
}
else
{
printf("Interface %u is %sappropriate to configure MAC filter parameters.\n",
ifNum, (*status ==
OPEN_TRUE) ?
"" :
"not ");
}
return;
}
char *macAddr,
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to checks to see the mac address type, "
"unicast or multicast. (result = %d)\n", result);
}
else
{
printf("MAC address %s is %s.\n", macAddr,
(*status ==
OPEN_TRUE) ?
"multicast" :
"unicast");
}
return;
}
OPEN_FILTER_VLAN_FILTER_MODE_t mode)
{
{
printf("Bad return code trying to set multicast address filtering"
" configuration for all vlans. (result = %d)\n", result);
}
else
{
printf("Multicast address filtering configuration for all vlans is"
" successful.\n");
}
return;
}
uint32_t vlanId,
OPEN_FILTER_VLAN_FILTER_MODE_t mode)
{
{
printf("Bad return code trying to sets multicast address filtering "
"configuration for the specified vlan. (result = %d)\n", result);
}
else
{
printf("Multicast vlan filtering mode is successful.\n");
}
return;
}
uint32_t vlanId,
OPEN_FILTER_VLAN_FILTER_MODE_t *mode)
{
{
printf("Bad return code trying to gets multicast address filtering "
"configuration for the specified vlan. (result = %d)\n", result);
}
else
{
printf("Multicast vlan filtering mode is %u.\n", *mode);
}
return;
}
{
{
printf("Bad return code trying to checks if the interface is valid"
" for filtering. (result = %d)\n", result);
}
else
{
printf("Interface %u is %svalid MAC filter interafce.\n", ifNum,
}
return;
}
uint32_t vlanId, uint32_t streamId)
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to sets the stream id of an existing macfilter "
"with given MAC address and vlan id. (result = %d)\n", result);
}
else
{
printf("Filter stream set successfully.\n");
}
return;
}
char *macAddr, uint32_t vlanId,
uint32_t *streamId)
{
char mac[MAC_STRING_SIZE] = "";
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
{
printf("Bad return code trying to gets the configured stream id."
" (result = %d)\n", result);
}
else
{
printf("Filter stream ID is %u.\n", *streamId);
}
return;
}
char *macAddr, uint32_t vlanId)
{
char mac[MAC_STRING_SIZE] = "";
char intfStr[INTF_LIST_STR_SIZE] = "";
uint32_t numOfDstFiltIntf;
strncpy(mac, macAddr, MAC_STRING_SIZE-1);
bufId.pstart = mac;
bufId.size = strlen (mac);
intfList.pstart = intfStr;
intfList.size = INTF_LIST_STR_SIZE;
&numOfDstFiltIntf, &intfList))
{
printf("Bad return code trying to gets list of source interfaces for a"
" MAC static filter. (result = %d)\n", result);
}
else
{
printf("List of destination filter interfaces for a filter is:\n%s\n",
intfStr);
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum, val;
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 Static Filter 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 == 3)
{
filterAdminModeSet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 2:
if (argc == 2)
{
filterAdminModeGet(&client_handle, &val);
show_help = 0;
}
break;
case 3:
if (argc == 4)
{
filterCreate(&client_handle, argv[2], atoi(argv[3]));
show_help = 0;
}
break;
case 4:
if (argc == 4)
{
filterRemove(&client_handle, argv[2], atoi(argv[3]));
show_help = 0;
}
break;
case 5:
if (argc == 5)
{
filterSrcIntfListModify(&client_handle, argv[2], atoi(argv[3]),
argv[4]);
show_help = 0;
}
break;
case 6:
if (argc == 5)
{
filterSrcIntfAdd(&client_handle, argv[2], atoi(argv[3]), atoi(argv[4]));
show_help = 0;
}
break;
case 7:
if (argc == 5)
{
filterSrcIntfDelete(&client_handle, argv[2], atoi(argv[3]), atoi(argv[4]));
show_help = 0;
}
break;
case 8:
if (argc == 5)
{
filterDstIntfAdd(&client_handle, argv[2], atoi(argv[3]), atoi(argv[4]));
show_help = 0;
}
break;
case 9:
if (argc == 5)
{
filterDstIntfDelete(&client_handle, argv[2], atoi(argv[3]), atoi(argv[4]));
show_help = 0;
}
break;
case 10:
if (argc == 7)
{
filterDstIntfListAdd(&client_handle, argv[2], atoi(argv[3]), atoi(argv[4]),
argv[5], argv[6]);
show_help = 0;
}
break;
case 11:
if (argc == 7)
{
filterDstIntfListDelete(&client_handle, argv[2], atoi(argv[3]),
atoi(argv[4]), argv[5], argv[6]);
show_help = 0;
}
break;
case 12:
if (argc == 2)
{
filterFirstGet(&client_handle);
show_help = 0;
}
break;
case 13:
if (argc == 4)
{
filterNextGet(&client_handle, argv[2], atoi(argv[3]));
show_help = 0;
}
break;
case 14:
if (argc == 4)
{
filterSrcIntfListGet(&client_handle, argv[2], atoi(argv[3]));
show_help = 0;
}
break;
case 15:
if (argc == 4)
{
filterDstIntfListGet(&client_handle, argv[2], atoi(argv[3]));
show_help = 0;
}
break;
case 16:
if (argc == 2)
{
filterCountGet(&client_handle, &val);
show_help = 0;
}
break;
case 17:
if (argc == 2)
{
filterCountersGet(&client_handle);
show_help = 0;
}
break;
case 18:
if (argc == 4)
{
filterIsConfigured(&client_handle, argv[2], atoi(argv[3]), &val);
show_help = 0;
}
break;
case 19:
if (argc == 2)
{
filterSizeGet(&client_handle, &val);
show_help = 0;
}
break;
case 20:
if (argc == 3)
{
filterIsIntfInAnyFilter(&client_handle, atoi(argv[2]), &val);
show_help = 0;
}
break;
case 21:
if (argc == 3)
{
filterPortParmCanSet(&client_handle, atoi(argv[2]), &val);
show_help = 0;
}
break;
case 22:
if (argc == 3)
{
filterCheckMacAddrTypeMulticast(&client_handle, argv[2], &val);
show_help = 0;
}
break;
case 23:
if (argc == 3)
{
filterFilteringModeSet(&client_handle, atoi(argv[2]));
show_help = 0;
}
break;
case 24:
if (argc == 4)
{
filterVlanFilteringModeSet(&client_handle, atoi(argv[2]), atoi(argv[3]));
show_help = 0;
}
break;
case 25:
if (argc == 3)
{
filterVlanFilteringModeGet(&client_handle, atoi(argv[2]), &val);
show_help = 0;
}
break;
case 26:
if (argc == 3)
{
filterIsValidIntf(&client_handle, atoi(argv[2]), &val);
show_help = 0;
}
break;
case 27:
if (argc == 5)
{
filterStreamSet(&client_handle, argv[2], atoi(argv[3]), atoi(argv[4]));
show_help = 0;
}
break;
case 28:
if (argc == 4)
{
filterStreamGet(&client_handle, argv[2], atoi(argv[3]), &val);
show_help = 0;
}
break;
case 29:
if (argc == 4)
{
filterDstFiltIntfListGet(&client_handle, argv[2], atoi(argv[3]));
show_help = 0;
}
break;
default:
break;
}
if (show_help == 1)
{
printAppMenu(argv[0]);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Static Filter API example "
"application");
return 0;
}