26 #ifndef ETHER_ADDR_LEN 48 u8 ** mgmt_ip6,
u8 ** mgmt_oid,
int enable)
78 if (port_desc && *port_desc)
84 if (mgmt_ip4 && *mgmt_ip4)
90 if (mgmt_ip6 && *mgmt_ip6)
96 if (mgmt_oid && *mgmt_oid)
126 u8 *port_desc = NULL;
127 u8 *mgmt_ip4 = NULL, *mgmt_ip6 = NULL, *mgmt_oid = NULL;
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));
581 s = format(s,
"Interface/peer state: interface down\n" 582 "Last packet sent: %U\n",
583 format_time_ago, n->last_sent, now);
585 else if (now < n->last_heard + n->
ttl)
588 "Interface/peer state: active\n" 589 "Peer chassis ID: %U\nRemote port ID: %U\n" 590 "Last packet sent: %U\nLast packet received: %U\n",
591 format_lldp_chassis_id, n->chassis_id_subtype,
592 n->chassis_id, vec_len(n->chassis_id), 1,
593 format_lldp_port_id, n->port_id_subtype, n->port_id,
594 vec_len(n->port_id), 1, format_time_ago, n->last_sent,
595 now, format_time_ago, n->last_heard, now);
600 "Interface/peer state: inactive(timeout)\n" 601 "Last known peer chassis ID: %U\n" 602 "Last known peer port ID: %U\nLast packet sent: %U\n" 603 "Last packet received: %U\n",
604 format_lldp_chassis_id, n->chassis_id_subtype,
605 n->chassis_id, vec_len(n->chassis_id), 1,
606 format_lldp_port_id, n->port_id_subtype, n->port_id,
607 vec_len(n->port_id), 1, format_time_ago, n->last_sent,
608 now, format_time_ago, n->last_heard, now);
620 const int detail = va_arg (*va,
int);
630 s =
format (s,
"%-25s %-25s %-25s %=15s %=15s %=10s\n",
"Local interface",
631 "Peer chassis ID",
"Remote port ID",
"Last heard",
"Last sent",
637 const vnet_hw_interface_t *hw =
638 vnet_get_hw_interface(vnm, n->hw_if_index);
639 const vnet_sw_interface_t *sw =
640 vnet_get_sw_interface(lm->vnet_main, hw->sw_if_index);
642 if (!(sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
644 if (now < n->last_heard + n->ttl)
646 s = format(s,
"%-25s %-25U %-25U %=15U %=15U %=10s\n", hw->name,
647 format_lldp_chassis_id, n->chassis_id_subtype,
648 n->chassis_id, vec_len(n->chassis_id), 0,
649 format_lldp_port_id, n->port_id_subtype, n->port_id,
650 vec_len(n->port_id), 0, format_time_ago, n->last_heard,
651 now, format_time_ago, n->last_sent, now,
"active");
655 s = format(s,
"%-25s %-25s %-25s %=15U %=15U %=10s\n", hw->name,
656 "",
"", format_time_ago, n->last_heard, now,
657 format_time_ago, n->last_sent, now,
"inactive");
684 .short_help =
"show lldp [detail]",
701 const lldp_tlv_t *tlv;
706 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
#define clib_memcpy(d, s, n)
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.
vl_api_interface_index_t sw_if_index
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)
vnet_sw_interface_flags_t flags
#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 pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
#define VLIB_CLI_COMMAND(x,...)
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)
u8 * format_mac_address(u8 *s, va_list *args)
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,...)