#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
typedef struct
{
uint32_t vlan_exists;
uint32_t staticVlan;
} vlan_entry_t;
vlan_entry_t *vlan_table;
void vlan_status_show ()
{
uint32_t i;
printf ("\n\nThe following VLAN IDs are in the switch's VLAN databas:\n");
for (i = 0; i < 4096; i++)
{
if (!vlan_table[i].vlan_exists)
{
continue;
}
printf ("VLAN: %d is %s\n", i, vlan_table[i].staticVlan ? "Static":"Dynamic");
}
}
{
uint32_t vlan_num;
vlan_table = malloc(sizeof(vlan_entry_t) * 4096);
printf ("Created VLAN Table.\n");
openapiEventListClear (&open_event);
openapiEventSet (&open_event, OPEN_EVENT_VLAN);
{
printf ("Failed to register for OPEN_EVENT_VLAN events.\n");
abort ();
}
for (vlan_num = 0; vlan_num < 4096; vlan_num++)
{
{
vlan_table[vlan_num].vlan_exists = 1;
}
else
{
vlan_table[vlan_num].vlan_exists = 0;
vlan_table[vlan_num].staticVlan = 0;
}
}
vlan_num = 0;
{
vlan_table[vlan_num].vlan_exists = 1;
}
}
{
uint32_t vlan_num;
for (vlan_num = 0; vlan_num < 4096; vlan_num++)
{
if (!vlan_table[vlan_num].vlan_exists)
{
continue;
}
{
}
else
{
vlan_table[vlan_num].vlan_exists = 0;
vlan_table[vlan_num].staticVlan = 0;
}
}
}
{
struct timespec start_time, current_time;
uint32_t vlan_num, delete_pending;
int notify_fd;
struct timeval tv;
fd_set rcv_set;
int rc;
char buf[1];
if (clock_gettime (CLOCK_MONOTONIC, &start_time))
{
perror("Can't get start time.\n");
abort ();
}
if (notify_fd == 0)
{
perror("Invalid notify_fd retrieved.\n");
abort();
}
do
{
FD_ZERO (&rcv_set);
FD_SET (notify_fd, &rcv_set);
tv.tv_sec = 5;
tv.tv_usec = 0;
rc = select(notify_fd + 1, &rcv_set, 0, 0, &tv);
if (rc > 0)
{
do
{
rc = recvfrom (notify_fd, buf, sizeof(buf), MSG_DONTWAIT, 0, 0);
} while ((rc >= 0) || (EINTR == errno));
{
{
printf ("Got Purge event for OPEN_EVENT_VLAN\n");
vlan_table_validate (client);
}
{
printf ("Got Change Pending event for OPEN_EVENT_VLAN\n");
}
}
vlan_num = 0;
{
if (delete_pending)
{
printf ("Deleting VLAN ID: %d\n", vlan_num);
vlan_table[vlan_num].vlan_exists = 0;
vlan_table[vlan_num].staticVlan = 0;
}
else
{
printf ("Change event received for VLAN ID: %d\n", vlan_num);
{
vlan_table[vlan_num].vlan_exists = 1;
}
else
{
vlan_table[vlan_num].vlan_exists = 0;
vlan_table[vlan_num].staticVlan = 0;
}
}
}
}
if (clock_gettime (CLOCK_MONOTONIC, ¤t_time))
{
perror ("Can't get current time.\n");
abort ();
}
} while ((current_time.tv_sec - start_time.tv_sec) < monitor_duration);
}
int main(int argc, char **argv)
{
char switch_os_revision_string[100];
uint32_t monitor_duration = 60;
if ((argc != 1) && (argc != 2))
{
printf("Usage: %s [monitor-duration-seconds]\n", argv[0]);
exit(1);
}
if (argc == 2)
{
monitor_duration = atoi(argv[1]);
}
printf ("Monitoring VLAN Status for %d seconds.\n", monitor_duration);
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 Status Monitor 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");
vlan_table_create(&clientHandle);
vlan_status_show();
vlan_table_monitor(&clientHandle, monitor_duration);
vlan_status_show();
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping VLAN Status example application");
return 0;
}