diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-05-02 17:53:58 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-05-17 02:27:08 +0200 |
commit | 30a1595df8cff4eb66b6dcb8fd4093d04225c13f (patch) | |
tree | 6d30c1befaad5b4847e02aba3d49fab507e4184e /vrrpd | |
parent | vrrpd: fix memleak during config write (diff) | |
download | frr-30a1595df8cff4eb66b6dcb8fd4093d04225c13f.tar.xz frr-30a1595df8cff4eb66b6dcb8fd4093d04225c13f.zip |
vrrpd: add 'show vrrp summary' command
Shows a brief summary table of all VRRP routers
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'vrrpd')
-rw-r--r-- | vrrpd/vrrp_vty.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c index 9cd1be245..b14efc33e 100644 --- a/vrrpd/vrrp_vty.c +++ b/vrrpd/vrrp_vty.c @@ -572,6 +572,23 @@ static void vrrp_show(struct vty *vty, struct vrrp_vrouter *vr) ttable_del(tt); } +/* + * Sort comparator, used when sorting VRRP instances for display purposes. + * + * Sorts by interface name first, then by VRID ascending. + */ +static int vrrp_instance_display_sort_cmp(const void **d1, const void **d2) +{ + const struct vrrp_vrouter *vr1 = *d1; + const struct vrrp_vrouter *vr2 = *d2; + int result; + + result = strcmp(vr1->ifp->name, vr2->ifp->name); + result += !result * (vr1->vrid - vr2->vrid); + + return result; +} + /* clang-format off */ DEFPY(vrrp_vrid_show, @@ -589,6 +606,8 @@ DEFPY(vrrp_vrid_show, struct list *ll = hash_to_list(vrrp_vrouters_hash); struct json_object *j = json_object_new_array(); + list_sort(ll, vrrp_instance_display_sort_cmp); + for (ALL_LIST_ELEMENTS_RO(ll, ln, vr)) { if (ifn && !strmatch(ifn, vr->ifp->name)) continue; @@ -613,6 +632,55 @@ DEFPY(vrrp_vrid_show, return CMD_SUCCESS; } +DEFPY(vrrp_vrid_show_summary, + vrrp_vrid_show_summary_cmd, + "show vrrp [interface INTERFACE$ifn] [(1-255)$vrid] summary", + SHOW_STR + VRRP_STR + INTERFACE_STR + "Only show VRRP instances on this interface\n" + VRRP_VRID_STR + "Summarize all VRRP instances\n") +{ + struct vrrp_vrouter *vr; + struct listnode *ln; + struct list *ll = hash_to_list(vrrp_vrouters_hash); + + list_sort(ll, vrrp_instance_display_sort_cmp); + + struct ttable *tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + + ttable_add_row( + tt, "Interface|VRID|Priority|IPv4|IPv6|State (v4)|State (v6)"); + ttable_rowseps(tt, 0, BOTTOM, true, '-'); + + for (ALL_LIST_ELEMENTS_RO(ll, ln, vr)) { + if (ifn && !strmatch(ifn, vr->ifp->name)) + continue; + if (vrid && ((uint8_t)vrid) != vr->vrid) + continue; + + ttable_add_row( + tt, "%s|%" PRIu8 "|%" PRIu8 "|%d|%d|%s|%s", + vr->ifp->name, vr->vrid, vr->priority, + vr->v4->addrs->count, vr->v6->addrs->count, + vr->v4->fsm.state == VRRP_STATE_MASTER ? "Master" + : "Backup", + vr->v6->fsm.state == VRRP_STATE_MASTER ? "Master" + : "Backup"); + } + + char *table = ttable_dump(tt, "\n"); + + vty_out(vty, "\n%s\n", table); + XFREE(MTYPE_TMP, table); + ttable_del(tt); + + list_delete(&ll); + + return CMD_SUCCESS; +} + DEFPY(debug_vrrp, debug_vrrp_cmd, @@ -667,6 +735,7 @@ void vrrp_vty_init(void) if_cmd_init(); install_element(VIEW_NODE, &vrrp_vrid_show_cmd); + install_element(VIEW_NODE, &vrrp_vrid_show_summary_cmd); install_element(VIEW_NODE, &show_debugging_vrrp_cmd); install_element(VIEW_NODE, &debug_vrrp_cmd); install_element(CONFIG_NODE, &debug_vrrp_cmd); |