From 7f0dc57f8ef8691f556bb9d43186d450bef2824f Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Wed, 10 Aug 2022 02:04:04 -0700 Subject: [PATCH] pimd, pim6d: Using ttable for displaying "show ip/ipv6 multicast count" command. Signed-off-by: Abhishek N R --- pimd/pim_cmd_common.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 45726b4e56..2eeecb5a28 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3285,13 +3285,22 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, json_object *json) { struct interface *ifp; + struct ttable *tt = NULL; + char *table = NULL; json_object *json_row = NULL; vty_out(vty, "\n"); - if (!json) - vty_out(vty, - "Interface Address ifi Vif PktsIn PktsOut BytesIn BytesOut\n"); + if (!json) { + /* Prepare table. */ + tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + ttable_add_row( + tt, + "Interface|Address|ifi|Vif|PktsIn|PktsOut|BytesIn|BytesOut"); + tt->style.cell.rpad = 2; + tt->style.corner = '+'; + ttable_restyle(tt); + } FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp; @@ -3347,16 +3356,22 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, (unsigned long)vreq.obytes); json_object_object_add(json, ifp->name, json_row); } else { - vty_out(vty, - "%-16s %-15pPAs %3d %3d %7lu %7lu %10lu %10lu\n", - ifp->name, &pim_ifp->primary_address, - ifp->ifindex, pim_ifp->mroute_vif_index, - (unsigned long)vreq.icount, - (unsigned long)vreq.ocount, - (unsigned long)vreq.ibytes, - (unsigned long)vreq.obytes); + ttable_add_row(tt, "%s|%pPAs|%d|%d|%lu|%lu|%lu|%lu", + ifp->name, &pim_ifp->primary_address, + ifp->ifindex, pim_ifp->mroute_vif_index, + (unsigned long)vreq.icount, + (unsigned long)vreq.ocount, + (unsigned long)vreq.ibytes, + (unsigned long)vreq.obytes); } } + /* Dump the generated table. */ + if (!json) { + table = ttable_dump(tt, "\n"); + vty_out(vty, "%s\n", table); + XFREE(MTYPE_TMP, table); + ttable_del(tt); + } } void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty) -- 2.39.5