aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/lldp/lldp_cli.c
diff options
context:
space:
mode:
authorSteve Shin <jonshin@cisco.com>2017-07-01 04:16:20 +0000
committerNeale Ranns <nranns@cisco.com>2017-07-08 12:34:04 +0000
commit262ca683be45ea6278ede2693d8832939b9dce14 (patch)
tree0a4ece9b522eb0f7eccba5ba2d08563eef9cfaa0 /src/vnet/lldp/lldp_cli.c
parent6922bd37be2c38d1c37b47855bb920c79b891027 (diff)
Add API support for LLDP config/interface set
Add API methods to configure LLDP and set interface to enable/disable. Also add port description TLV for LLDP. Change-Id: Ib959d488c2ab8a0069f143558871f41fcc43a5d3 Signed-off-by: Steve Shin <jonshin@cisco.com> (cherry picked from commit 99a0e60eb6f6acd7eabd5a4cb7ded1e0419ccd54)
Diffstat (limited to 'src/vnet/lldp/lldp_cli.c')
-rw-r--r--src/vnet/lldp/lldp_cli.c86
1 files changed, 50 insertions, 36 deletions
diff --git a/src/vnet/lldp/lldp_cli.c b/src/vnet/lldp/lldp_cli.c
index 45f688c58b4..4a7ca683e1e 100644
--- a/src/vnet/lldp/lldp_cli.c
+++ b/src/vnet/lldp/lldp_cli.c
@@ -19,19 +19,13 @@
*
*/
#include <vnet/lisp-cp/lisp_types.h>
+#include <vnet/lldp/lldp.h>
#include <vnet/lldp/lldp_node.h>
#ifndef ETHER_ADDR_LEN
#include <net/ethernet.h>
#endif
-typedef enum lldp_cfg_err
-{
- lldp_ok,
- lldp_not_supported,
- lldp_invalid_arg,
-} lldp_cfg_err_t;
-
static clib_error_t *
lldp_cfg_err_to_clib_err (lldp_cfg_err_t e)
{
@@ -48,8 +42,8 @@ lldp_cfg_err_to_clib_err (lldp_cfg_err_t e)
return 0;
}
-static lldp_cfg_err_t
-lldp_cfg_intf_set (u32 hw_if_index, int enable)
+lldp_cfg_err_t
+lldp_cfg_intf_set (u32 hw_if_index, u8 ** port_desc, int enable)
{
lldp_main_t *lm = &lldp_main;
vnet_main_t *vnm = lm->vnet_main;
@@ -68,9 +62,16 @@ lldp_cfg_intf_set (u32 hw_if_index, int enable)
if (n)
{
/* already enabled */
- return 0;
+ return lldp_ok;
}
n = lldp_create_intf (lm, hw_if_index);
+
+ if (port_desc && *port_desc)
+ {
+ n->port_desc = *port_desc;
+ *port_desc = NULL;
+ }
+
const vnet_sw_interface_t *sw =
vnet_get_sw_interface (lm->vnet_main, hi->sw_if_index);
if (sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
@@ -84,7 +85,7 @@ lldp_cfg_intf_set (u32 hw_if_index, int enable)
lldp_delete_intf (lm, n);
}
- return 0;
+ return lldp_ok;
}
static clib_error_t *
@@ -93,24 +94,33 @@ lldp_intf_cmd (vlib_main_t * vm, unformat_input_t * input,
{
lldp_main_t *lm = &lldp_main;
vnet_main_t *vnm = lm->vnet_main;
- u32 hw_if_index;
- int enable = 0;
+ u32 sw_if_index = (u32) ~ 0;
+ int enable = 1;
+ u8 *port_desc = NULL;
- if (unformat (input, "%U %U", unformat_vnet_hw_interface, vnm, &hw_if_index,
- unformat_vlib_enable_disable, &enable))
- {
- return
- lldp_cfg_err_to_clib_err (lldp_cfg_intf_set (hw_if_index, enable));
- }
- else
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ if (unformat (input, "sw_if_index %d", &sw_if_index))
+ ;
+ if (unformat
+ (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
+ ;
+ else if (unformat (input, "disable"))
+ enable = 0;
+ else if (unformat (input, "port-desc %s", &port_desc))
+ ;
+ else
+ break;
}
- return 0;
+
+ if (sw_if_index == (u32) ~ 0)
+ return clib_error_return (0, "Interface name is invalid!");
+
+ return lldp_cfg_err_to_clib_err (lldp_cfg_intf_set (sw_if_index,
+ &port_desc, enable));
}
-static lldp_cfg_err_t
+lldp_cfg_err_t
lldp_cfg_set (u8 ** host, int hold_time, int tx_interval)
{
lldp_main_t *lm = &lldp_main;
@@ -210,7 +220,8 @@ out:
/* *INDENT-OFF* */
VLIB_CLI_COMMAND(set_interface_lldp_cmd, static) = {
.path = "set interface lldp",
- .short_help = "set interface lldp <interface> (enable | disable) ",
+ .short_help = "set interface lldp <interface> | sw_if_index <idx>"
+ " [port-desc <string>] [disable]",
.function = lldp_intf_cmd,
};
@@ -501,23 +512,26 @@ format_lldp_intfs_detail (u8 * s, vlib_main_t * vm, const lldp_main_t * lm)
else if (now < n->last_heard + n->ttl)
{
s = format(s,
- "\nInterface name: %s\nInterface/peer state: "
- "active\nPeer chassis ID: %U\nRemote port ID: %U\nLast "
- "packet sent: %U\nLast packet received: %U\n",
- hw->name, format_lldp_chassis_id, n->chassis_id_subtype,
- n->chassis_id, vec_len(n->chassis_id), 1,
+ "\nInterface name: %s\nPort Desc: %s\nInterface/peer "
+ "state: active\nPeer chassis ID: %U\nRemote port ID:"
+ " %U\nLast packet sent: %U\nLast packet received: %U\n",
+ hw->name, n->port_desc, format_lldp_chassis_id,
+ n->chassis_id_subtype, n->chassis_id,
+ vec_len(n->chassis_id), 1,
format_lldp_port_id, n->port_id_subtype, n->port_id,
vec_len(n->port_id), 1, format_time_ago, n->last_sent,
now, format_time_ago, n->last_heard, now);
}
else
{
- s = format(s, "\nInterface name: %s\nInterface/peer state: "
- "inactive(timeout)\nLast known peer chassis ID: "
- "%U\nLast known peer port ID: %U\nLast packet sent: "
- "%U\nLast packet received: %U\n",
- hw->name, format_lldp_chassis_id, n->chassis_id_subtype,
- n->chassis_id, vec_len(n->chassis_id), 1,
+ s = format(s,
+ "\nInterface name: %s\nPort Desc: %s\nInterface/peer "
+ "state: inactive(timeout)\nLast known peer chassis ID:"
+ "%U\nLast known peer port ID: %U\nLast packet sent: "
+ "%U\nLast packet received: %U\n",
+ hw->name, n->port_desc, format_lldp_chassis_id,
+ n->chassis_id_subtype, n->chassis_id,
+ vec_len(n->chassis_id), 1,
format_lldp_port_id, n->port_id_subtype, n->port_id,
vec_len(n->port_id), 1, format_time_ago, n->last_sent,
now, format_time_ago, n->last_heard, now);