#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
void printStormControlAppMenu()
{
printf("Usage: storm_control_example <test#> <arg1> <arg2> ... \n");
printf("Test 1: Set the global storm control mode state: storm_control_example 1 <storm-control mode> <state> \n");
printf("Test 2: Get the global storm control mode state: storm_control_example 2 <storm-control mode> \n");
printf("Test 3: Set the global storm control rate unit and threshold: storm_control_example 3 <storm-control mode> <rate-unit> <threshold> \n");
printf("Test 4: Set the global storm control rate unit and threshold to default: storm_control_example 4 <storm-control mode> \n");
printf("Test 5: Get the global storm control rate unit and threshold: storm_control_example 5 <storm-control mode> \n");
printf("Test 6: Set the storm control mode state on an interface: storm_control_example 6 <storm-control mode> <interface> <state> \n");
printf("Test 7: Get the storm control mode state on an interface: storm_control_example 7 <storm-control mode> <interface> \n");
printf("Test 8: Set the storm control rate unit and threshold on an interface: storm_control_example 8 <storm-control mode> <interface> <rate-unit> <threshold> \n");
printf("Test 9: Set the storm control rate unit and threshold to default on an interface: storm_control_example 9 <storm-control mode> <interface> \n");
printf("Test 10: Get the storm control rate unit and threshold on an interface: storm_control_example 10 <storm-control mode> <interface> \n");
printf("Test 11: Set the global storm control action: storm_control_example 11 <storm-control mode> <action> \n");
printf("Test 12: Get the global storm control action: storm_control_example 12 <storm-control mode> \n");
printf("Test 13: Storm Control OpEN APIs Sanity: storm_control_example 13 \n");
return;
}
{
{
printf("Bad return code trying to set global storm control mode. (result = %d) \n", result);
}
else
{
printf("Storm control mode %d is set successfully. result = %d) \n", mode, result);
}
return;
}
{
{
printf("Bad return code trying to get global storm control mode. (result = %d) \n", result);
}
else
{
printf("Storm control mode %d state: %d result = %d) \n", mode, state, result);
}
return;
}
uint32_t threshold)
{
uint32_t minVal, maxVal;
{
if ((threshold < minVal) || (threshold > maxVal))
{
printf("Invalid Threshold value. The allowable range is %d - %d.\n", minVal, maxVal);
}
}
{
{
printf("Bad return code trying to set global storm control rate unit and threshold. (result = %d) \n", result);
}
else
{
printf("Storm control rate unit and threshold for mode %d is set successfully. result = %d) \n", mode, result);
}
}
return;
}
{
{
printf("Bad return code trying to set global storm control rate unit and threshold to default. (result = %d) \n", result);
}
else
{
printf("Storm control rate unit and threshold for mode %d is set to default successfully. result = %d) \n", mode, result);
}
return;
}
{
uint32_t threshold;
{
printf("Bad return code trying to get global storm control rate unit and threshold for mode. (result = %d) \n", result);
}
else
{
printf("Storm Control Mode: ");
{
printf("Unicast\n");
}
{
printf("Broadcast\n");
}
{
printf("Multicast\n");
}
printf("Threshold: %d ", threshold);
{
printf("percent\n");
}
else
{
printf("pps\n");
}
}
return;
}
uint32_t interface,
{
{
printf("Bad return code trying to set storm control mode on an interface. (result = %d) \n", result);
}
else
{
printf("Storm Control mode %d is set successfully on interface %d. (result = %d) \n", mode, interface, result);
}
return;
}
uint32_t interface)
{
{
printf("Bad return code trying to get storm control mode on an interface. (result = %d) \n", result);
}
else
{
printf("State of Storm Control mode %d on interface %d: %d. (result = %d) \n", mode, interface, state, result);
}
return;
}
uint32_t interface,
uint32_t threshold)
{
uint32_t minVal, maxVal;
{
if ((threshold < minVal) || (threshold > maxVal))
{
printf("Invalid Threshold value. The allowable range is %d - %d.\n", minVal, maxVal);
}
}
{
{
printf("Bad return code trying to set storm control rate unit and threshold on an interface. (result = %d) \n", result);
}
else
{
printf("Storm Control rate unit and threshold for mode %d on interface %d is set successfully. (result = %d) \n", mode, interface, result);
}
}
return;
}
uint32_t interface)
{
{
printf("Bad return code trying to set storm control rate unit and threshold to default on an interface. (result = %d) \n", result);
}
else
{
printf("Storm Control rate unit and threshold for mode %d on interface %d is set to default successfully. (result = %d) \n", mode, interface, result);
}
return;
}
uint32_t interface)
{
uint32_t threshold = 0;
{
printf("Bad return code trying to get storm control rate unit and threshold on an interface for mode %d. (result = %d) \n", mode, result);
}
else
{
printf("Interface: %d\n", interface);
printf("Storm Control Mode: ");
{
printf("Unicast\n");
}
{
printf("Broadcast\n");
}
{
printf("Multicast\n");
}
printf("Threshold: %d ", threshold);
{
printf("percent\n");
}
else
{
printf("pps\n");
}
}
return;
}
{
{
printf("Bad return code trying to set global storm control action. (result = %d) \n", result);
}
else
{
printf("Storm control action set successfully. result = %d) \n", result);
}
return;
}
{
{
printf("Bad return code trying to get global storm control action. (result = %d) \n", result);
}
else
{
switch (action)
{
printf("Storm control action : Shutdown\n");
break;
printf("Storm control action : Rate Limit\n");
break;
printf("Storm control action : Trap\n");
break;
case OPEN_POLICY_PORT_ACTION_NONE:
default:
printf("Storm control action : None\n");
break;
}
}
return;
}
{
uint32_t threshold = 0;
uint32_t interface = 1;
printf("\nTesting openapiStormControlModeSet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid storm control mode state. (result = %d)\n", result);
printf("openapiStormControlModeSet() sanity successful.\n");
printf("\nTesting openapiStormControlModeGet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("NULL storm control mode. (result = %d)\n", result);
printf("openapiStormControlModeGet() sanity successful.\n");
printf("\nTesting openapiStormControlThresholdSet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid storm control rate. (result = %d)\n", result);
printf("Invalid threshold value for rate unit OPEN_RATE_UNIT_PERCENT. (result = %d)\n", result);
printf("Invalid threshold value for rate unit OPEN_RATE_UNIT_PPS. (result = %d)\n", result);
printf("openapiStormControlThresholdSet() sanity successful.\n");
printf("\nTesting openapiStormControlThresholdDefaultSet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("openapiStormControlThresholdDefaultSet() sanity successful.\n");
printf("\nTesting openapiStormControlThresholdGet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("NULL storm control rate. (result = %d)\n", result);
printf("NULL storm control threshold. (result = %d)\n", result);
printf("openapiStormControlThresholdGet() sanity successful.\n");
printf("\nTesting openapiStormControlIntfModeSet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid interface. (result = %d)\n", result);
printf("Invalid storm control mode state. (result = %d)\n", result);
printf("openapiStormControlIntfModeSet() sanity successful.\n");
printf("\nTesting openapiStormControlIntfModeGet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid interface. (result = %d)\n", result);
printf("NULL storm control mode state. (result = %d)\n", result);
printf("openapiStormControlIntfModeGet() sanity successful.\n");
printf("\nTesting openapiStormControlIntfThresholdSet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid interface. (result = %d)\n", result);
printf("Invalid storm control rate unit. (result = %d)\n", result);
printf("Invalid storm control threshold for rate unit OPEN_RATE_UNIT_PERCENT. (result = %d)\n", result);
printf("Invalid storm control threshold for rate unit OPEN_RATE_UNIT_PPS. (result = %d)\n", result);
printf("openapiStormControlIntfThresholdSet() sanity successful.\n");
printf("\nTesting openapiStormControlIntfThresholdDefaultSet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid interface. (result = %d)\n", result);
printf("openapiStormControlIntfThresholdDefaultSet() sanity successful.\n");
printf("\nTesting openapiStormControlIntfThresholdGet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid interface. (result = %d)\n", result);
printf("NULL storm control rate unit. (result = %d)\n", result);
printf("NULL storm control threshold. (result = %d)\n", result);
printf("openapiStormControlIntfThresholdGet() sanity successful.\n");
printf("\nTesting openapiStormControlActionSet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("Invalid storm control action. (result = %d)\n", result);
printf("openapiStormControlActionSet() sanity successful.\n");
printf("\nTesting openapiStormControlActionGet(): \n");
printf("NULL client handle. (result = %d)\n", result);
printf("Invalid storm control mode. (result = %d)\n", result);
printf("NULL storm control action. (result = %d)\n", result);
printf("openapiStormControlActionGet() sanity successful.\n");
return;
}
int main(int argc, char **argv)
{
uint32_t testNum;
char switch_os_revision_string[100];
uint32_t arg1, arg2, arg3, arg4;
if (argc < 2)
{
printStormControlAppMenu();
exit(1);
}
testNum = atoi(argv[1]);
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 Storm Control 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 != 4)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
stormControlModeSet(&clientHandle, arg1, arg2);
break;
case 2:
if (argc != 3)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
stormControlModeGet(&clientHandle, arg1);
break;
case 3:
if (argc != 5)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
arg3 = atoi(argv[4]);
stormControlThresholdSet(&clientHandle, arg1, arg2, arg3);
break;
case 4:
if (argc != 3)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
stormControlThresholdDefaultSet(&clientHandle, arg1);
break;
case 5:
if (argc != 3)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
stormControlThresholdGet(&clientHandle, arg1);
break;
case 6:
if (argc != 5)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
arg3 = atoi(argv[4]);
stormControlIntfModeSet(&clientHandle, arg1, arg2, arg3);
break;
case 7:
if (argc != 4)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
stormControlIntfModeGet(&clientHandle, arg1, arg2);
break;
case 8:
if (argc != 6)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
arg3 = atoi(argv[4]);
arg4 = atoi(argv[5]);
stormControlIntfThresholdSet(&clientHandle, arg1, arg2, arg3, arg4);
break;
case 9:
if (argc != 4)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
stormControlIntfThresholdDefaultSet(&clientHandle, arg1, arg2);
break;
case 10:
if (argc != 4)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
stormControlIntfThresholdGet(&clientHandle, arg1, arg2);
break;
case 11:
if (argc != 4)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
stormControlActionSet(&clientHandle, arg1, arg2);
break;
case 12:
if (argc != 3)
{
printStormControlAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
stormControlActionGet(&clientHandle, arg1);
break;
case 13:
if (argc != 2)
{
printStormControlAppMenu();
exit(1);
}
stormControlOpENAPIsSanity(&clientHandle);
break;
default:
printStormControlAppMenu();
break;
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Storm Control API example application");
return 0;
}