]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd, pim6d: Using ttable for displaying "show ip/ipv6 pim nexthop" command output
authorAbhishek N R <abnr@vmware.com>
Wed, 16 Nov 2022 08:08:05 +0000 (00:08 -0800)
committerAbhishek N R <abnr@vmware.com>
Wed, 23 Nov 2022 06:59:30 +0000 (22:59 -0800)
Before:

R4(config)# do show ipv6 pim nexthop
Number of registered addresses: 6
Address         Interface        Nexthop
---------------------------------------------
3700:1234:1234:1234:1234:1234:1234:1234 ens161           fe80::250:56ff:feb7:d8d5
5101::10        ens224.51        5101::10
3300::5555      ens161           fe80::250:56ff:feb7:d8d5
4400::1         ens161           fe80::250:56ff:feb7:d8d5
1020::10        ens257           1020::10
3000::1         ens192.4010      fe80::250:56ff:feb7:493b
3000::1         ens193.4015      fe80::250:56ff:feb7:b12a

After:

frr# show ipv6 pim nexthop
Number of registered addresses: 2
Address         Interface        Nexthop
---------------------------------------------
105::105        lo               105::105
12::1           ens192           fe80::250:56ff:feb7:38de

Issue: #11246

Signed-off-by: Abhishek N R <abnr@vmware.com>
pimd/pim_cmd_common.c

index b39f688cdb9d828a063c1b9f30b7f6517d2bcc51..a04573b3028b45ddfa6f9d3f7d9b52e4e435abaf 100644 (file)
@@ -2824,21 +2824,35 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg)
        struct nexthop *nh_node = NULL;
        ifindex_t first_ifindex;
        struct interface *ifp = NULL;
+       struct ttable *tt = NULL;
+       char *table = NULL;
+
+       /* Prepare table. */
+       tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
+       ttable_add_row(
+               tt,
+               "Address|Interface|Nexthop");
+       tt->style.cell.rpad = 2;
+       tt->style.corner = '+';
+       ttable_restyle(tt);
 
        for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) {
                first_ifindex = nh_node->ifindex;
 
                ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id);
 
-               vty_out(vty, "%-15pPA ", &pnc->rpf.rpf_addr);
-               vty_out(vty, "%-16s ", ifp ? ifp->name : "NULL");
 #if PIM_IPV == 4
-               vty_out(vty, "%pI4 ", &nh_node->gate.ipv4);
+               ttable_add_row(tt, "%pPA|%s|%pI4", &pnc->rpf.rpf_addr, ifp ? ifp->name : "NULL", &nh_node->gate.ipv4);
 #else
-               vty_out(vty, "%pI6 ", &nh_node->gate.ipv6);
+               ttable_add_row(tt, "%pPA|%s|%pI6", &pnc->rpf.rpf_addr, ifp ? ifp->name : "NULL", &nh_node->gate.ipv6);
 #endif
-               vty_out(vty, "\n");
        }
+       /* Dump the generated table. */
+       table = ttable_dump(tt, "\n");
+       vty_out(vty, "%s\n", table);
+       XFREE(MTYPE_TMP, table);
+       ttable_del(tt);
+
        return CMD_SUCCESS;
 }
 
@@ -2966,8 +2980,6 @@ void pim_show_nexthop(struct pim_instance *pim, struct vty *vty, bool uj)
        } else {
                vty_out(vty, "Number of registered addresses: %lu\n",
                        pim->rpf_hash->count);
-               vty_out(vty, "Address         Interface        Nexthop\n");
-               vty_out(vty, "---------------------------------------------\n");
        }
 
        if (uj) {