VPP-245 Coding standards cleanup for vnet/vnet/cdp

Change-Id: I5253c52eace4b635f7791aa019ab01ec55d7fb4d
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Dave Barach
2016-08-09 08:55:49 -04:00
committed by Dave Wallace
parent d5d5ffa427
commit 861bd216eb
5 changed files with 819 additions and 729 deletions

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@ static vlib_node_registration_t cdp_process_node;
* packet counter strings
* Dump these counters via the "show error" CLI command
*/
static char * cdp_error_strings[] = {
static char *cdp_error_strings[] = {
#define _(sym,string) string,
foreach_cdp_error
#undef _
@ -44,9 +44,10 @@ static char * cdp_error_strings[] = {
* them, so the graph node has only one next-index. The "error-drop"
* node automatically bumps our per-node packet counters for us.
*/
typedef enum {
CDP_INPUT_NEXT_NORMAL,
CDP_INPUT_N_NEXT,
typedef enum
{
CDP_INPUT_NEXT_NORMAL,
CDP_INPUT_N_NEXT,
} cdp_next_t;
/*
@ -55,24 +56,23 @@ typedef enum {
*/
static uword
cdp_node_fn (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
vlib_node_runtime_t * node, vlib_frame_t * frame)
{
u32 n_left_from, * from;
cdp_input_trace_t * t0;
u32 n_left_from, *from;
cdp_input_trace_t *t0;
from = vlib_frame_vector_args (frame); /* array of buffer indices */
n_left_from = frame->n_vectors; /* number of buffer indices */
from = vlib_frame_vector_args (frame); /* array of buffer indices */
n_left_from = frame->n_vectors; /* number of buffer indices */
while (n_left_from > 0)
{
u32 bi0;
vlib_buffer_t * b0;
vlib_buffer_t *b0;
u32 next0, error0;
bi0 = from[0];
b0 = vlib_get_buffer (vm, bi0);
next0 = CDP_INPUT_NEXT_NORMAL;
/* scan this cdp pkt. error0 is the counter index to bump */
@ -80,14 +80,15 @@ cdp_node_fn (vlib_main_t * vm,
b0->error = node->errors[error0];
/* If this pkt is traced, snapshoot the data */
if (b0->flags & VLIB_BUFFER_IS_TRACED) {
int len;
if (b0->flags & VLIB_BUFFER_IS_TRACED)
{
int len;
t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
len = (b0->current_length < sizeof (t0->data))
? b0->current_length : sizeof (t0->data);
t0->len = len;
clib_memcpy (t0->data, vlib_buffer_get_current (b0), len);
}
len = (b0->current_length < sizeof (t0->data))
? b0->current_length : sizeof (t0->data);
t0->len = len;
clib_memcpy (t0->data, vlib_buffer_get_current (b0), len);
}
/* push this pkt to the next graph node, always error-drop */
vlib_set_next_frame_buffer (vm, node, next0, bi0);
@ -101,6 +102,7 @@ cdp_node_fn (vlib_main_t * vm,
/*
* cdp input graph node declaration
*/
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (cdp_input_node, static) = {
.function = cdp_node_fn,
.name = "cdp-input",
@ -109,86 +111,98 @@ VLIB_REGISTER_NODE (cdp_input_node, static) = {
.n_errors = CDP_N_ERROR,
.error_strings = cdp_error_strings,
.format_trace = cdp_input_format_trace,
.n_next_nodes = CDP_INPUT_N_NEXT,
.next_nodes = {
[CDP_INPUT_NEXT_NORMAL] = "error-drop",
[CDP_INPUT_NEXT_NORMAL] = "error-drop",
},
};
/* *INDENT-ON* */
/*
* cdp periodic function
*/
static uword
cdp_process (vlib_main_t * vm,
vlib_node_runtime_t * rt,
vlib_frame_t * f)
cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
{
cdp_main_t * cm = &cdp_main;
f64 poll_time_remaining;
uword event_type, * event_data = 0;
cdp_main_t *cm = &cdp_main;
f64 poll_time_remaining;
uword event_type, *event_data = 0;
/* So we can send events to the cdp process */
cm->cdp_process_node_index = cdp_process_node.index;
/* So we can send events to the cdp process */
cm->cdp_process_node_index = cdp_process_node.index;
/* Dynamically register the cdp input node with the snap classifier */
snap_register_input_protocol (vm, "cdp-input",
0xC /* ieee_oui, Cisco */,
0x2000 /* protocol CDP */,
cdp_input_node.index);
/* Dynamically register the cdp input node with the snap classifier */
snap_register_input_protocol (vm, "cdp-input", 0xC /* ieee_oui, Cisco */ ,
0x2000 /* protocol CDP */ ,
cdp_input_node.index);
snap_register_input_protocol (vm, "cdp-input",
0xC /* ieee_oui, Cisco */,
0x2004 /* protocol CDP */,
cdp_input_node.index);
snap_register_input_protocol (vm, "cdp-input", 0xC /* ieee_oui, Cisco */ ,
0x2004 /* protocol CDP */ ,
cdp_input_node.index);
#if 0 /* retain for reference */
/* with the hdlc classifier */
hdlc_register_input_protocol (vm, HDLC_PROTOCOL_cdp,
cdp_input_node.index);
#if 0 /* retain for reference */
/* with the hdlc classifier */
hdlc_register_input_protocol (vm, HDLC_PROTOCOL_cdp, cdp_input_node.index);
#endif
/* with ethernet input (for SRP) */
ethernet_register_input_type (vm, ETHERNET_TYPE_CDP /* CDP */,
cdp_input_node.index);
/* with ethernet input (for SRP) */
ethernet_register_input_type (vm, ETHERNET_TYPE_CDP /* CDP */ ,
cdp_input_node.index);
poll_time_remaining = 10.0 /* seconds */;
while (1) {
/* sleep until next poll time, or msg serialize event occurs */
poll_time_remaining =
vlib_process_wait_for_event_or_clock (vm, poll_time_remaining);
event_type = vlib_process_get_events (vm, &event_data);
switch (event_type) {
case ~0: /* no events => timeout */
break;
poll_time_remaining = 10.0 /* seconds */ ;
while (1)
{
/* sleep until next poll time, or msg serialize event occurs */
poll_time_remaining =
vlib_process_wait_for_event_or_clock (vm, poll_time_remaining);
default:
clib_warning ("BUG: event type 0x%wx", event_type);
break;
}
if (event_data)
_vec_len (event_data) = 0;
event_type = vlib_process_get_events (vm, &event_data);
switch (event_type)
{
case ~0: /* no events => timeout */
break;
/* peer timeout scan, send announcements */
if (vlib_process_suspend_time_is_zero (poll_time_remaining)) {
cdp_periodic (vm);
poll_time_remaining = 10.0;
}
default:
clib_warning ("BUG: event type 0x%wx", event_type);
break;
}
if (event_data)
_vec_len (event_data) = 0;
/* peer timeout scan, send announcements */
if (vlib_process_suspend_time_is_zero (poll_time_remaining))
{
cdp_periodic (vm);
poll_time_remaining = 10.0;
}
}
return 0;
return 0;
}
/*
* cdp periodic node declaration
*/
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (cdp_process_node, static) = {
.function = cdp_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = "cdp-process",
.function = cdp_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = "cdp-process",
};
/* *INDENT-ON* */
void vnet_cdp_node_reference(void) { }
void
vnet_cdp_node_reference (void)
{
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -27,42 +27,44 @@
#include <vnet/cdp/cdp_protocol.h>
typedef enum {
CDP_PACKET_TEMPLATE_ETHERNET,
CDP_PACKET_TEMPLATE_HDLC,
CDP_PACKET_TEMPLATE_SRP,
CDP_N_PACKET_TEMPLATES,
typedef enum
{
CDP_PACKET_TEMPLATE_ETHERNET,
CDP_PACKET_TEMPLATE_HDLC,
CDP_PACKET_TEMPLATE_SRP,
CDP_N_PACKET_TEMPLATES,
} cdp_packet_template_id_t;
typedef struct {
/* neighbor's vlib software interface index */
u32 sw_if_index;
typedef struct
{
/* neighbor's vlib software interface index */
u32 sw_if_index;
/* Timers */
f64 last_heard;
f64 last_sent;
/* Timers */
f64 last_heard;
f64 last_sent;
/* Neighbor time-to-live (usually 180s) */
u8 ttl_in_seconds;
/* Neighbor time-to-live (usually 180s) */
u8 ttl_in_seconds;
/* "no cdp run" or similar */
u8 disabled;
/* "no cdp run" or similar */
u8 disabled;
/* tx packet template id for this neighbor */
u8 packet_template_index;
/* tx packet template id for this neighbor */
u8 packet_template_index;
/* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
u8 last_packet_signature_valid;
uword last_packet_signature;
/* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
u8 last_packet_signature_valid;
uword last_packet_signature;
/* Info we actually keep about each neighbor */
u8 *device_name;
u8 *version;
u8 *port_id;
u8 *platform;
/* Info we actually keep about each neighbor */
u8 *device_name;
u8 *version;
u8 *port_id;
u8 *platform;
/* last received packet, for the J-hash optimization */
u8 *last_rx_pkt;
/* last received packet, for the J-hash optimization */
u8 *last_rx_pkt;
} cdp_neighbor_t;
#define foreach_neighbor_string_field \
@ -71,25 +73,26 @@ _(version) \
_(port_id) \
_(platform)
typedef struct {
/* pool of cdp neighbors */
cdp_neighbor_t *neighbors;
typedef struct
{
/* pool of cdp neighbors */
cdp_neighbor_t *neighbors;
/* tx pcap debug enable */
u8 tx_pcap_debug;
/* tx pcap debug enable */
u8 tx_pcap_debug;
/* rapidly find a neighbor by vlib software interface index */
uword *neighbor_by_sw_if_index;
/* rapidly find a neighbor by vlib software interface index */
uword *neighbor_by_sw_if_index;
/* Background process node index */
u32 cdp_process_node_index;
/* Background process node index */
u32 cdp_process_node_index;
/* Packet templates for different encap types */
vlib_packet_template_t packet_templates [CDP_N_PACKET_TEMPLATES];
/* Packet templates for different encap types */
vlib_packet_template_t packet_templates[CDP_N_PACKET_TEMPLATES];
/* convenience variables */
vlib_main_t *vlib_main;
vnet_main_t *vnet_main;
/* convenience variables */
vlib_main_t *vlib_main;
vnet_main_t *vnet_main;
} cdp_main_t;
cdp_main_t cdp_main;
@ -103,22 +106,25 @@ _ (PROTOCOL_VERSION, "cdp packets with bad protocol versions") \
_ (CHECKSUM, "cdp packets with bad checksums") \
_ (DISABLED, "cdp packets received on disabled interfaces")
typedef enum {
typedef enum
{
#define _(sym,str) CDP_ERROR_##sym,
foreach_cdp_error
#undef _
CDP_N_ERROR,
CDP_N_ERROR,
} cdp_error_t;
/* cdp packet trace capture */
typedef struct {
u32 len;
u8 data[400];
typedef struct
{
u32 len;
u8 data[400];
} cdp_input_trace_t;
typedef enum {
CDP_EVENT_SEND_NEIGHBOR,
CDP_EVENT_SEND_KEEPALIVE,
typedef enum
{
CDP_EVENT_SEND_NEIGHBOR,
CDP_EVENT_SEND_KEEPALIVE,
} cdp_process_event_t;
@ -126,8 +132,16 @@ cdp_error_t cdp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0);
void cdp_periodic (vlib_main_t * vm);
void cdp_keepalive (cdp_main_t * cm, cdp_neighbor_t * n);
u16 cdp_checksum (void *p, int count);
u8 * cdp_input_format_trace (u8 * s, va_list * args);
u8 *cdp_input_format_trace (u8 * s, va_list * args);
serialize_function_t serialize_cdp_main, unserialize_cdp_main;
#endif /* __included_cdp_node_h__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -20,42 +20,44 @@
#include <vnet/snap/snap.h>
#include <vnet/srp/packet.h>
typedef CLIB_PACKED (struct {
u8 version;
u8 ttl;
u16 checksum; /* 1's complement of the 1's complement sum */
u8 data[0];
}) cdp_hdr_t;
typedef CLIB_PACKED (struct
{
u8 version;
u8 ttl;
u16 checksum; /* 1's complement of the 1's complement sum */
u8 data[0];
}) cdp_hdr_t;
typedef struct {
typedef struct
{
u8 dst_address[6];
u8 src_address[6];
u16 len;
} ethernet_802_3_header_t;
typedef CLIB_PACKED (struct {
ethernet_802_3_header_t ethernet;
llc_header_t llc;
snap_header_t snap;
cdp_hdr_t cdp;
}) ethernet_llc_snap_and_cdp_header_t;
typedef CLIB_PACKED (struct
{
ethernet_802_3_header_t ethernet;
llc_header_t llc; snap_header_t snap; cdp_hdr_t cdp;
}) ethernet_llc_snap_and_cdp_header_t;
typedef CLIB_PACKED (struct {
hdlc_header_t hdlc;
cdp_hdr_t cdp;
}) hdlc_and_cdp_header_t;
typedef CLIB_PACKED (struct
{
hdlc_header_t hdlc; cdp_hdr_t cdp;
}) hdlc_and_cdp_header_t;
typedef CLIB_PACKED (struct {
srp_header_t srp;
ethernet_header_t ethernet;
cdp_hdr_t cdp;
}) srp_and_cdp_header_t;
typedef CLIB_PACKED (struct
{
srp_header_t srp;
ethernet_header_t ethernet; cdp_hdr_t cdp;
}) srp_and_cdp_header_t;
typedef CLIB_PACKED (struct {
u16 t;
u16 l;
u8 v[0];
}) cdp_tlv_t;
typedef CLIB_PACKED (struct
{
u16 t;
u16 l;
u8 v[0];
}) cdp_tlv_t;
/*
* TLV codes.
@ -92,9 +94,10 @@ _(energywise) \
_(unknown_30) \
_(spare_poe)
typedef enum {
typedef enum
{
#define _(t) CDP_TLV_##t,
foreach_cdp_tlv_type
foreach_cdp_tlv_type
#undef _
} cdp_tlv_code_t;
@ -173,3 +176,11 @@ typedef enum {
#define CDP_DUPLEX_TLV_FULL 0x1
#endif /* __included_cdp_protocol_h__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/