bfdd: Adding new CLI, show bfd peers brief

Added new CLI to display all BFD peer in brief format

Signed-off-by: Sayed Mohd Saquib <sayed.saquib@broadcom.com>
This commit is contained in:
SumitAgarwal123 2019-09-19 00:35:17 -07:00 committed by Donald Sharp
parent d679003308
commit fa6e709f3f
3 changed files with 98 additions and 1 deletions

View File

@ -1852,3 +1852,8 @@ void bfd_session_update_vrf_name(struct bfd_session *bs, struct vrf *vrf)
strlcpy(bs->key.vrfname, vrf->name, sizeof(bs->key.vrfname));
hash_get(bfd_key_hash, bs, hash_alloc_intern);
}
unsigned long bfd_get_session_count(void)
{
return bfd_key_hash->count;
}

View File

@ -567,6 +567,8 @@ typedef void (*hash_iter_func)(struct hash_bucket *hb, void *arg);
void bfd_id_iterate(hash_iter_func hif, void *arg);
void bfd_key_iterate(hash_iter_func hif, void *arg);
unsigned long bfd_get_session_count(void);
/* Export callback functions for `event.c`. */
extern struct thread_master *master;

View File

@ -260,7 +260,7 @@ static void _display_peer_json(struct vty *vty, struct bfd_session *bs)
}
struct bfd_vrf_tuple {
char *vrfname;
const char *vrfname;
struct vty *vty;
struct json_object *jo;
};
@ -451,6 +451,81 @@ static void _clear_peer_counter(struct bfd_session *bs)
bs->stats.tx_echo_pkt = 0;
}
static void _display_peer_brief(struct vty *vty, struct bfd_session *bs)
{
char addr_buf[INET6_ADDRSTRLEN];
if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_MH)) {
vty_out(vty, "%-10u", bs->discrs.my_discr);
inet_ntop(bs->key.family, &bs->key.local, addr_buf, sizeof(addr_buf));
vty_out(vty, " %-40s", addr_buf);
inet_ntop(bs->key.family, &bs->key.peer, addr_buf, sizeof(addr_buf));
vty_out(vty, " %-40s", addr_buf);
vty_out(vty, "%-15s\n", state_list[bs->ses_state].str);
} else {
vty_out(vty, "%-10u", bs->discrs.my_discr);
vty_out(vty, " %-40s", satostr(&bs->local_address));
inet_ntop(bs->key.family, &bs->key.peer, addr_buf, sizeof(addr_buf));
vty_out(vty, " %-40s", addr_buf);
vty_out(vty, "%-15s\n", state_list[bs->ses_state].str);
}
}
static void _display_peer_brief_iter(struct hash_backet *hb, void *arg)
{
struct bfd_vrf_tuple *bvt = arg;
struct vty *vty;
struct bfd_session *bs = hb->data;
if (!bvt)
return;
vty = bvt->vty;
if (bvt->vrfname) {
if (!bs->key.vrfname[0] ||
!strmatch(bs->key.vrfname, bvt->vrfname))
return;
}
_display_peer_brief(vty, bs);
}
static void _display_peers_brief(struct vty *vty, const char *vrfname, bool use_json)
{
struct json_object *jo;
struct bfd_vrf_tuple bvt;
memset(&bvt, 0, sizeof(struct bfd_vrf_tuple));
bvt.vrfname = vrfname;
if (use_json == false) {
bvt.vty = vty;
vty_out(vty, "Session count: %lu\n", bfd_get_session_count());
vty_out(vty, "%-10s", "SessionId");
vty_out(vty, " %-40s", "LocalAddress");
vty_out(vty, " %-40s", "PeerAddress");
vty_out(vty, "%-15s\n", "Status");
vty_out(vty, "%-10s", "=========");
vty_out(vty, " %-40s", "============");
vty_out(vty, " %-40s", "===========");
vty_out(vty, "%-15s\n", "======");
bfd_id_iterate(_display_peer_brief_iter, &bvt);
return;
}
jo = json_object_new_array();
bvt.jo = jo;
bfd_id_iterate(_display_peer_json_iter, &bvt);
vty_out(vty, "%s\n", json_object_to_json_string_ext(jo, 0));
json_object_free(jo);
}
static struct bfd_session *
_find_peer_or_error(struct vty *vty, int argc, struct cmd_token **argv,
const char *label, const char *peer_str,
@ -642,6 +717,20 @@ DEFPY(bfd_clear_peer_counters, bfd_clear_peer_counters_cmd,
return CMD_SUCCESS;
}
DEFPY(bfd_show_peers_brief, bfd_show_peers_brief_cmd,
"show bfd [vrf <NAME$vrfname>] peers brief [json]",
SHOW_STR
"Bidirection Forwarding Detection\n"
VRF_CMD_HELP_STR
"BFD peers status\n"
"Show BFD peer information in tabular form\n"
JSON_STR)
{
_display_peers_brief(vty, vrfname, use_json(argc, argv));
return CMD_SUCCESS;
}
/*
* Function definitions.
*/
@ -783,6 +872,7 @@ void bfdd_vty_init(void)
install_element(ENABLE_NODE, &bfd_clear_peer_counters_cmd);
install_element(ENABLE_NODE, &bfd_show_peers_cmd);
install_element(ENABLE_NODE, &bfd_show_peer_cmd);
install_element(ENABLE_NODE, &bfd_show_peers_brief_cmd);
install_element(ENABLE_NODE, &show_debugging_bfd_cmd);
/* Install BFD node and commands. */