25 #ifndef ETHER_ADDR_LEN 47 u8 ** mgmt_ip6,
u8 ** mgmt_oid,
int enable)
77 if (port_desc && *port_desc)
83 if (mgmt_ip4 && *mgmt_ip4)
89 if (mgmt_ip6 && *mgmt_ip6)
95 if (mgmt_oid && *mgmt_oid)
124 u32 sw_if_index = (
u32) ~ 0;
133 if (
unformat (input,
"sw_if_index %d", &sw_if_index))
138 else if (
unformat (input,
"disable"))
140 else if (
unformat (input,
"port-desc %s", &port_desc))
154 else if (
unformat (input,
"mgmt-oid %s", &mgmt_oid))
160 if (sw_if_index == (
u32) ~ 0)
164 &port_desc, &mgmt_ip4,
165 &mgmt_ip6, &mgmt_oid,
229 if (
unformat (input,
"system-name %s", &host))
232 else if (
unformat (input,
"tx-hold %d", &hold_time))
238 "invalid tx-hold `%d' (out of range <%d,%d>)",
244 else if (
unformat (input,
"tx-interval %d", &tx_interval))
251 "invalid tx-interval `%d' (out of range <%d,%d>)",
271 .path =
"set interface lldp",
272 .short_help =
"set interface lldp <interface> | sw_if_index <idx>" 273 " [port-desc <string>] [mgmt-ip4 <string>]" 274 " [mgmt-ip6 <string>] [mgmt-oid <string>] [disable]",
280 .short_help =
"set lldp [system-name <string>] [tx-hold <value>] " 281 "[tx-interval <value>]",
291 #define F(num, val, str) \ 297 return "unknown chassis subtype";
305 #define F(num, val, str) \ 311 return "unknown port subtype";
326 const u8 *
id = va_arg (*va,
u8 *);
327 const unsigned len = va_arg (*va,
unsigned);
328 const int detail = va_arg (*va,
int);
353 if (ETHER_ADDR_LEN == len)
399 const u8 *
id = va_arg (*va,
u8 *);
400 const unsigned len = va_arg (*va,
unsigned);
401 const int detail = va_arg (*va,
int);
428 if (ETHER_ADDR_LEN == len)
473 return "unknown lldp tlv";
485 const lldp_tlv_t *tlv = va_arg (*va, lldp_tlv_t *);
495 ((lldp_chassis_id_tlv_t *) tlv)->subtype,
496 ((lldp_chassis_id_tlv_t *) tlv)->
id,
501 ((lldp_port_id_tlv_t *) tlv)->subtype,
502 ((lldp_port_id_tlv_t *) tlv)->
id,
506 s =
format (s,
"%d", ntohs (((lldp_ttl_tlv_t *) tlv)->ttl));
523 f64 ago = va_arg (*va,
double);
524 f64 now = va_arg (*va,
double);
527 return format (s,
"never");
529 return format (s,
"%.1fs ago", now - ago);
539 s =
format (s,
"LLDP configuration:\n");
548 s =
format (s,
"\nLLDP-enabled interface table:\n");
554 hw = vnet_get_hw_interface(vnm, n->hw_if_index);
555 sw = vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
557 s = format(s,
"\nLocal Interface name: %s\n" 558 "Local Port Description: %s\n",
559 hw->name, n->port_desc);
562 s = format (s,
"Local Management address: %U\n",
563 format_ip4_address, n->mgmt_ip4, vec_len (n->mgmt_ip4));
568 s = format (s,
"Local Management address IPV6: %U\n",
569 format_ip6_address, n->mgmt_ip6, vec_len (n->mgmt_ip6));
574 s = format (s,
"Local Management address OID: %U\n",
575 format_ascii_bytes, n->mgmt_oid, vec_len (n->mgmt_oid));
582 s = format(s,
"Interface/peer state: interface down\n" 583 "Last packet sent: %U\n",
584 format_time_ago, n->last_sent, now);
586 else if (now < n->last_heard + n->
ttl)
589 "Interface/peer state: active\n" 590 "Peer chassis ID: %U\nRemote port ID: %U\n" 591 "Last packet sent: %U\nLast packet received: %U\n",
592 format_lldp_chassis_id, n->chassis_id_subtype,
593 n->chassis_id, vec_len(n->chassis_id), 1,
594 format_lldp_port_id, n->port_id_subtype, n->port_id,
595 vec_len(n->port_id), 1, format_time_ago, n->last_sent,
596 now, format_time_ago, n->last_heard, now);
601 "Interface/peer state: inactive(timeout)\n" 602 "Last known peer chassis ID: %U\n" 603 "Last known peer port ID: %U\nLast packet sent: %U\n" 604 "Last packet received: %U\n",
605 format_lldp_chassis_id, n->chassis_id_subtype,
606 n->chassis_id, vec_len(n->chassis_id), 1,
607 format_lldp_port_id, n->port_id_subtype, n->port_id,
608 vec_len(n->port_id), 1, format_time_ago, n->last_sent,
609 now, format_time_ago, n->last_heard, now);
621 const int detail = va_arg (*va,
int);
631 s =
format (s,
"%-25s %-25s %-25s %=15s %=15s %=10s\n",
"Local interface",
632 "Peer chassis ID",
"Remote port ID",
"Last heard",
"Last sent",
638 const vnet_hw_interface_t *hw =
639 vnet_get_hw_interface(vnm, n->hw_if_index);
640 const vnet_sw_interface_t *sw =
641 vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
643 if (!(sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
645 if (now < n->last_heard + n->ttl)
647 s = format(s,
"%-25s %-25U %-25U %=15U %=15U %=10s\n", hw->name,
648 format_lldp_chassis_id, n->chassis_id_subtype,
649 n->chassis_id, vec_len(n->chassis_id), 0,
650 format_lldp_port_id, n->port_id_subtype, n->port_id,
651 vec_len(n->port_id), 0, format_time_ago, n->last_heard,
652 now, format_time_ago, n->last_sent, now,
"active");
656 s = format(s,
"%-25s %-25s %-25s %=15U %=15U %=10s\n", hw->name,
657 "",
"", format_time_ago, n->last_heard, now,
658 format_time_ago, n->last_sent, now,
"inactive");
685 .short_help =
"show lldp [detail]",
702 const lldp_tlv_t *tlv;
707 tlv = (lldp_tlv_t *) cur;
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#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
vnet_interface_main_t interface_main
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
vnet_hw_interface_t * hw_interfaces
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)
lldp_cfg_err_t lldp_cfg_intf_set(u32 hw_if_index, u8 **port_desc, u8 **mgmt_ip4, u8 **mgmt_ip6, u8 **mgmt_oid, int enable)
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 clib_memcpy(a, b, c)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
#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,...)