Skip to content

Commit

Permalink
bfdd: Adding new CLI, show bfd peers brief
Browse files Browse the repository at this point in the history
Added new CLI to display all BFD peer in brief format

Signed-off-by: Sayed Mohd Saquib <sayed.saquib@broadcom.com>
  • Loading branch information
SumitAgarwal123 authored and donaldsharp committed Dec 4, 2019
1 parent d679003 commit fa6e709
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bfdd/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions bfdd/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
92 changes: 91 additions & 1 deletion bfdd/bfdd_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit fa6e709

Please sign in to comment.