25 #ifndef ETHER_ADDR_LEN 69 if (port_desc && *port_desc)
98 u32 sw_if_index = (
u32) ~ 0;
104 if (
unformat (input,
"sw_if_index %d", &sw_if_index))
109 else if (
unformat (input,
"disable"))
111 else if (
unformat (input,
"port-desc %s", &port_desc))
117 if (sw_if_index == (
u32) ~ 0)
121 &port_desc, enable));
179 if (
unformat (input,
"system-name %s", &host))
182 else if (
unformat (input,
"tx-hold %d", &hold_time))
188 "invalid tx-hold `%d' (out of range <%d,%d>)",
194 else if (
unformat (input,
"tx-interval %d", &tx_interval))
201 "invalid tx-interval `%d' (out of range <%d,%d>)",
221 .path =
"set interface lldp",
222 .short_help =
"set interface lldp <interface> | sw_if_index <idx>" 223 " [port-desc <string>] [disable]",
229 .short_help =
"set lldp [system-name <string>] [tx-hold <value>] " 230 "[tx-interval <value>]",
240 #define F(num, val, str) \ 246 return "unknown chassis subtype";
254 #define F(num, val, str) \ 260 return "unknown port subtype";
275 const u8 *
id = va_arg (*va,
u8 *);
276 const unsigned len = va_arg (*va,
unsigned);
277 const int detail = va_arg (*va,
int);
302 if (ETHER_ADDR_LEN == len)
348 const u8 *
id = va_arg (*va,
u8 *);
349 const unsigned len = va_arg (*va,
unsigned);
350 const int detail = va_arg (*va,
int);
377 if (ETHER_ADDR_LEN == len)
422 return "unknown lldp tlv";
434 const lldp_tlv_t *tlv = va_arg (*va, lldp_tlv_t *);
444 ((lldp_chassis_id_tlv_t *) tlv)->subtype,
445 ((lldp_chassis_id_tlv_t *) tlv)->
id,
450 ((lldp_port_id_tlv_t *) tlv)->subtype,
451 ((lldp_port_id_tlv_t *) tlv)->
id,
455 s =
format (s,
"%d", ntohs (((lldp_ttl_tlv_t *) tlv)->ttl));
472 f64 ago = va_arg (*va,
double);
473 f64 now = va_arg (*va,
double);
476 return format (s,
"never");
478 return format (s,
"%.1fs ago", now - ago);
488 s =
format (s,
"LLDP configuration:\n");
496 s =
format (s,
"\nLLDP-enabled interface table:\n");
502 hw = vnet_get_hw_interface(vnm, n->hw_if_index);
503 sw = vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
505 if (!(sw->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP |
506 VNET_SW_INTERFACE_FLAG_BOND_SLAVE)))
508 s = format(s,
"\nInterface name: %s\nInterface/peer state: " 509 "interface down\nLast packet sent: %U\n",
510 hw->name, format_time_ago, n->last_sent, now);
512 else if (now < n->last_heard + n->
ttl)
515 "\nInterface name: %s\nPort Desc: %s\nInterface/peer " 516 "state: active\nPeer chassis ID: %U\nRemote port ID:" 517 " %U\nLast packet sent: %U\nLast packet received: %U\n",
518 hw->name, n->port_desc, format_lldp_chassis_id,
519 n->chassis_id_subtype, n->chassis_id,
520 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);
528 "\nInterface name: %s\nPort Desc: %s\nInterface/peer " 529 "state: inactive(timeout)\nLast known peer chassis ID:" 530 "%U\nLast known peer port ID: %U\nLast packet sent: " 531 "%U\nLast packet received: %U\n",
532 hw->name, n->port_desc, format_lldp_chassis_id,
533 n->chassis_id_subtype, n->chassis_id,
534 vec_len(n->chassis_id), 1,
535 format_lldp_port_id, n->port_id_subtype, n->port_id,
536 vec_len(n->port_id), 1, format_time_ago, n->last_sent,
537 now, format_time_ago, n->last_heard, now);
549 const int detail = va_arg (*va,
int);
559 s =
format (s,
"%-25s %-25s %-25s %=15s %=15s %=10s\n",
"Local interface",
560 "Peer chassis ID",
"Remote port ID",
"Last heard",
"Last sent",
566 const vnet_hw_interface_t *hw =
567 vnet_get_hw_interface(vnm, n->hw_if_index);
568 const vnet_sw_interface_t *sw =
569 vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
571 if (!(sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
573 if (now < n->last_heard + n->ttl)
575 s = format(s,
"%-25s %-25U %-25U %=15U %=15U %=10s\n", hw->name,
576 format_lldp_chassis_id, n->chassis_id_subtype,
577 n->chassis_id, vec_len(n->chassis_id), 0,
578 format_lldp_port_id, n->port_id_subtype, n->port_id,
579 vec_len(n->port_id), 0, format_time_ago, n->last_heard,
580 now, format_time_ago, n->last_sent, now,
"active");
584 s = format(s,
"%-25s %-25s %-25s %=15U %=15U %=10s\n", hw->name,
585 "",
"", format_time_ago, n->last_heard, now,
586 format_time_ago, n->last_sent, now,
"inactive");
613 .short_help =
"show lldp [detail]",
630 const lldp_tlv_t *tlv;
635 tlv = (lldp_tlv_t *) cur;
#define LLDP_CHASS_ID_SUBTYPE_NAME(t)
lldp_chassis_id_subtype_t
static const char * lldp_tlv_code_str(lldp_tlv_code_t t)
lldp_cfg_err_t lldp_cfg_set(u8 **host, int hold_time, int tx_interval)
enum lldp_cfg_err lldp_cfg_err_t
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)
unformat_function_t unformat_vnet_sw_interface
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 clib_error_return(e, args...)
#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 VNET_SW_INTERFACE_FLAG_BOND_SLAVE
#define LLDP_PORT_ID_SUBTYPE_NAME(t)
static u8 * format_time_ago(u8 *s, va_list *va)
LLDP external definition.
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)
lldp_cfg_err_t lldp_cfg_intf_set(u32 hw_if_index, u8 **port_desc, int enable)
#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)
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)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)