24 #ifndef ETHER_ADDR_LEN 113 static lldp_cfg_err_t
168 if (
unformat (input,
"system-name %s", &host))
171 else if (
unformat (input,
"tx-hold %d", &hold_time))
177 "invalid tx-hold `%d' (out of range <%d,%d>)",
183 else if (
unformat (input,
"tx-interval %d", &tx_interval))
190 "invalid tx-interval `%d' (out of range <%d,%d>)",
212 .path =
"set interface lldp",
213 .short_help =
"set interface lldp <interface> (enable | disable) ",
219 .short_help =
"set lldp [system-name <string>] [tx-hold <value>] " 220 "[tx-interval <value>]",
230 #define F(num, val, str) \ 236 return "unknown chassis subtype";
244 #define F(num, val, str) \ 250 return "unknown port subtype";
265 const u8 *
id = va_arg (*va,
u8 *);
266 const unsigned len = va_arg (*va,
unsigned);
267 const int detail = va_arg (*va,
int);
292 if (ETHER_ADDR_LEN == len)
338 const u8 *
id = va_arg (*va,
u8 *);
339 const unsigned len = va_arg (*va,
unsigned);
340 const int detail = va_arg (*va,
int);
367 if (ETHER_ADDR_LEN == len)
412 return "unknown lldp tlv";
424 const lldp_tlv_t *tlv = va_arg (*va, lldp_tlv_t *);
434 ((lldp_chassis_id_tlv_t *) tlv)->subtype,
435 ((lldp_chassis_id_tlv_t *) tlv)->
id,
440 ((lldp_port_id_tlv_t *) tlv)->subtype,
441 ((lldp_port_id_tlv_t *) tlv)->
id,
445 s =
format (s,
"%d", ntohs (((lldp_ttl_tlv_t *) tlv)->ttl));
462 f64 ago = va_arg (*va,
double);
463 f64 now = va_arg (*va,
double);
466 return format (s,
"never");
468 return format (s,
"%.1fs ago", now - ago);
478 s =
format (s,
"LLDP configuration:\n");
486 s =
format (s,
"\nLLDP-enabled interface table:\n");
492 hw = vnet_get_hw_interface(vnm, n->hw_if_index);
493 sw = vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
495 if (!(sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
497 s = format(s,
"\nInterface name: %s\nInterface/peer state: " 498 "interface down\nLast packet sent: %U\n",
499 hw->name, format_time_ago, n->last_sent, now);
501 else if (now < n->last_heard + n->
ttl)
504 "\nInterface name: %s\nInterface/peer state: " 505 "active\nPeer chassis ID: %U\nRemote port ID: %U\nLast " 506 "packet sent: %U\nLast packet received: %U\n",
507 hw->name, format_lldp_chassis_id, n->chassis_id_subtype,
508 n->chassis_id, vec_len(n->chassis_id), 1,
509 format_lldp_port_id, n->port_id_subtype, n->port_id,
510 vec_len(n->port_id), 1, format_time_ago, n->last_sent,
511 now, format_time_ago, n->last_heard, now);
515 s = format(s,
"\nInterface name: %s\nInterface/peer state: " 516 "inactive(timeout)\nLast known peer chassis ID: " 517 "%U\nLast known peer port ID: %U\nLast packet sent: " 518 "%U\nLast packet received: %U\n",
519 hw->name, format_lldp_chassis_id, n->chassis_id_subtype,
520 n->chassis_id, vec_len(n->chassis_id), 1,
521 format_lldp_port_id, n->port_id_subtype, n->port_id,
522 vec_len(n->port_id), 1, format_time_ago, n->last_sent,
523 now, format_time_ago, n->last_heard, now);
535 const int detail = va_arg (*va,
int);
545 s =
format (s,
"%-25s %-25s %-25s %=15s %=15s %=10s\n",
"Local interface",
546 "Peer chassis ID",
"Remote port ID",
"Last heard",
"Last sent",
552 const vnet_hw_interface_t *hw =
553 vnet_get_hw_interface(vnm, n->hw_if_index);
554 const vnet_sw_interface_t *sw =
555 vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
557 if (!(sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
559 if (now < n->last_heard + n->ttl)
561 s = format(s,
"%-25s %-25U %-25U %=15U %=15U %=10s\n", hw->name,
562 format_lldp_chassis_id, n->chassis_id_subtype,
563 n->chassis_id, vec_len(n->chassis_id), 0,
564 format_lldp_port_id, n->port_id_subtype, n->port_id,
565 vec_len(n->port_id), 0, format_time_ago, n->last_heard,
566 now, format_time_ago, n->last_sent, now,
"active");
570 s = format(s,
"%-25s %-25s %-25s %=15U %=15U %=10s\n", hw->name,
571 "",
"", format_time_ago, n->last_heard, now,
572 format_time_ago, n->last_sent, now,
"inactive");
599 .short_help =
"show lldp [detail]",
616 const lldp_tlv_t *tlv;
621 tlv = (lldp_tlv_t *) cur;
unformat_function_t unformat_vnet_hw_interface
#define LLDP_CHASS_ID_SUBTYPE_NAME(t)
lldp_chassis_id_subtype_t
static const char * lldp_tlv_code_str(lldp_tlv_code_t t)
static lldp_cfg_err_t lldp_cfg_intf_set(u32 hw_if_index, int enable)
static f64 vlib_time_now(vlib_main_t *vm)
void lldp_schedule_intf(lldp_main_t *lm, lldp_intf_t *n)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static lldp_cfg_err_t lldp_cfg_set(u8 **host, int hold_time, int tx_interval)
static u8 * format_lldp_intfs_detail(u8 *s, vlib_main_t *vm, const lldp_main_t *lm)
#define LLDP_MAX_TX_INTERVAL
u8 * format_lldp_tlv(u8 *s, va_list *va)
ethernet_main_t ethernet_main
u8 * format_lldp_chassis_id(u8 *s, va_list *va)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
u8 * format_mac_address(u8 *s, va_list *args)
u8 * lldp_input_format_trace(u8 *s, va_list *args)
void lldp_delete_intf(lldp_main_t *lm, lldp_intf_t *n)
#define LLDP_MIN_TX_INTERVAL
static clib_error_t * show_lldp(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static clib_error_t * lldp_intf_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define LLDP_PORT_ID_SUBTYPE_NAME(t)
static u8 * format_time_ago(u8 *s, va_list *va)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static vlib_cli_command_t show_lldp_command
(constructor) VLIB_CLI_COMMAND (show_lldp_command)
static const char * lldp_chassis_id_subtype_str(lldp_chassis_id_subtype_t t)
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * lldp_cfg_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static const char * lldp_port_id_subtype_str(lldp_port_id_subtype_t t)
#define VLIB_CLI_COMMAND(x,...)
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
static clib_error_t * lldp_cfg_err_to_clib_err(lldp_cfg_err_t e)
u32 lldp_process_node_index
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
enum lldp_cfg_err lldp_cfg_err_t
static u8 * format_lldp_intfs(u8 *s, va_list *va)
LLDP global declarations.
#define STRUCT_SIZE_OF(t, f)
u8 * format_lldp_port_id(u8 *s, va_list *va)
#define clib_error_return(e, args...)