pimd, pim6d: Using ttable for displaying "show ip/ipv6 pim nexthop" command output

Before:

R4(config)# do show ipv6 pim nexthop
Number of registered addresses: 6
Address         Interface        Nexthop
---------------------------------------------
3700🔢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>
This commit is contained in:
Abhishek N R 2022-11-16 00:08:05 -08:00
parent 2387dca4dc
commit 774d8ad38b

View File

@ -2824,21 +2824,35 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg)
struct nexthop *nh_node = NULL; struct nexthop *nh_node = NULL;
ifindex_t first_ifindex; ifindex_t first_ifindex;
struct interface *ifp = NULL; 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) { for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) {
first_ifindex = nh_node->ifindex; first_ifindex = nh_node->ifindex;
ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id); 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 #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 #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 #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; return CMD_SUCCESS;
} }
@ -2966,8 +2980,6 @@ void pim_show_nexthop(struct pim_instance *pim, struct vty *vty, bool uj)
} else { } else {
vty_out(vty, "Number of registered addresses: %lu\n", vty_out(vty, "Number of registered addresses: %lu\n",
pim->rpf_hash->count); pim->rpf_hash->count);
vty_out(vty, "Address Interface Nexthop\n");
vty_out(vty, "---------------------------------------------\n");
} }
if (uj) { if (uj) {