From c3cd01eb06b50986448c6ae4322c7f09cb5d82e4 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Fri, 16 Sep 2022 10:11:09 -0700 Subject: [PATCH] pimd, pim6d: Using ttable for displaying "show ip/ipv6 pim neighbor" command output. Before: frr# show ipv6 pim neighbor Interface Neighbor Uptime Holdtime DR Pri ens192 fe80::250:56ff:feb7:38de 00:10:47 00:01:28 1 ens224 fe80::250:56ff:feb7:4bad 00:10:47 00:01:28 1 After: frr# sh ipv6 pim neighbor Interface Neighbor Uptime Holdtime DR Pri ens192 fe80::250:56ff:feb7:38de 00:00:12 00:01:32 1 ens224 fe80::250:56ff:feb7:4bad 00:00:12 00:01:32 1 Signed-off-by: Abhishek N R --- pimd/pim_cmd_common.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 0ddce4200..4798f3b3e 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3195,6 +3195,8 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, struct interface *ifp; struct pim_interface *pim_ifp; struct pim_neighbor *neigh; + struct ttable *tt = NULL; + char *table = NULL; time_t now; char uptime[10]; char expire[10]; @@ -3205,8 +3207,12 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, now = pim_time_monotonic_sec(); if (!json) { - vty_out(vty, - "Interface Neighbor Uptime Holdtime DR Pri\n"); + /* Prepare table. */ + tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + ttable_add_row(tt, "Interface|Neighbor|Uptime|Holdtime|DR Pri"); + tt->style.cell.rpad = 2; + tt->style.corner = '+'; + ttable_restyle(tt); } FOR_ALL_INTERFACES (pim->vrf, ifp) { @@ -3248,9 +3254,10 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, neigh_src_str, json_row); } else { - vty_out(vty, "%-16s %15s %8s %8s %6d\n", - ifp->name, neigh_src_str, uptime, - expire, neigh->dr_priority); + ttable_add_row(tt, "%s|%pPAs|%s|%s|%d", + ifp->name, &neigh->source_addr, + uptime, expire, + neigh->dr_priority); } } @@ -3259,6 +3266,13 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, json_ifp_rows = NULL; } } + /* Dump the generated table. */ + if (!json) { + table = ttable_dump(tt, "\n"); + vty_out(vty, "%s\n", table); + XFREE(MTYPE_TMP, table); + ttable_del(tt); + } } int gm_process_query_max_response_time_cmd(struct vty *vty, -- 2.39.2