diff options
Diffstat (limited to 'pimd/pim_cmd_common.c')
| -rw-r--r-- | pimd/pim_cmd_common.c | 123 |
1 files changed, 83 insertions, 40 deletions
diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 45726b4e56..1d3f5f430a 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) @@ -3412,6 +3427,8 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, struct listnode *node; struct channel_oil *c_oil; struct static_route *s_route; + struct ttable *tt = NULL; + char *table = NULL; time_t now; json_object *json_group = NULL; json_object *json_source = NULL; @@ -3434,8 +3451,14 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, vty_out(vty, "Flags: S - Sparse, C - Connected, P - Pruned\n"); vty_out(vty, " R - SGRpt Pruned, F - Register flag, T - SPT-bit set\n"); - vty_out(vty, - "\nSource Group Flags Proto Input Output TTL Uptime\n"); + + /* Prepare table. */ + tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + ttable_add_row( + tt, "Source|Group|Flags|Proto|Input|Output|TTL|Uptime"); + tt->style.cell.rpad = 2; + tt->style.corner = '+'; + ttable_restyle(tt); } now = pim_time_monotonic_sec(); @@ -3639,11 +3662,10 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, strlcpy(proto, "STAR", sizeof(proto)); } - vty_out(vty, - "%-15s %-15s %-8s %-6s %-16s %-16s %-3d %8s\n", - src_str, grp_str, state_str, proto, - in_ifname, out_ifname, ttl, - mroute_uptime); + ttable_add_row(tt, "%s|%s|%s|%s|%s|%s|%d|%s", + src_str, grp_str, state_str, + proto, in_ifname, out_ifname, + ttl, mroute_uptime); if (first) { src_str[0] = '\0'; @@ -3657,11 +3679,10 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, } if (!json && !found_oif) { - vty_out(vty, - "%-15pPAs %-15pPAs %-8s %-6s %-16s %-16s %-3d %8s\n", - oil_origin(c_oil), oil_mcastgrp(c_oil), - state_str, "none", in_ifname, "none", 0, - "--:--:--"); + ttable_add_row(tt, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s", + oil_origin(c_oil), oil_mcastgrp(c_oil), + state_str, "none", in_ifname, "none", 0, + "--:--:--"); } } @@ -3765,8 +3786,8 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, json_object_object_add(json_oil, out_ifname, json_ifp_out); } else { - vty_out(vty, - "%-15pPAs %-15pPAs %-8s %-6s %-16s %-16s %-3d %8s\n", + ttable_add_row( + tt, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s", &s_route->source, &s_route->group, "-", proto, in_ifname, out_ifname, ttl, oif_uptime); @@ -3780,17 +3801,24 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, } if (!json && !found_oif) { - vty_out(vty, - "%-15pPAs %-15pPAs %-8s %-6s %-16s %-16s %-3d %8s\n", - &s_route->source, &s_route->group, "-", proto, - in_ifname, "none", 0, "--:--:--"); + ttable_add_row(tt, "%pPAs|%pPAs|%s|%s|%s|%s|%d|%s", + &s_route->source, &s_route->group, "-", + proto, in_ifname, "none", 0, "--:--:--"); } } + /* Dump the generated table. */ + if (!json) { + table = ttable_dump(tt, "\n"); + vty_out(vty, "%s\n", table); + XFREE(MTYPE_TMP, table); + ttable_del(tt); + } } static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, json_object *json, - struct vty *vty) + struct vty *vty, + struct ttable *tt) { json_object *json_group = NULL; json_object *json_source = NULL; @@ -3825,12 +3853,12 @@ static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, json_object_int_add(json_source, "wrongIf", c_oil->cc.wrong_if); } else { - vty_out(vty, "%-15pPAs %-15pPAs %-8llu %-7ld %-10ld %-7ld\n", - oil_origin(c_oil), oil_mcastgrp(c_oil), - c_oil->cc.lastused / 100, - c_oil->cc.pktcnt - c_oil->cc.origpktcnt, - c_oil->cc.bytecnt - c_oil->cc.origbytecnt, - c_oil->cc.wrong_if - c_oil->cc.origwrong_if); + ttable_add_row(tt, "%pPAs|%pPAs|%llu|%ld|%ld|%ld", + oil_origin(c_oil), oil_mcastgrp(c_oil), + c_oil->cc.lastused / 100, + c_oil->cc.pktcnt - c_oil->cc.origpktcnt, + c_oil->cc.bytecnt - c_oil->cc.origbytecnt, + c_oil->cc.wrong_if - c_oil->cc.origwrong_if); } } @@ -3840,20 +3868,35 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty, struct listnode *node; struct channel_oil *c_oil; struct static_route *sr; + struct ttable *tt = NULL; + char *table = NULL; if (!json) { vty_out(vty, "\n"); - vty_out(vty, - "Source Group LastUsed Packets Bytes WrongIf \n"); + /* Prepare table. */ + tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + ttable_add_row(tt, + "Source|Group|LastUsed|Packets|Bytes|WrongIf"); + tt->style.cell.rpad = 2; + tt->style.corner = '+'; + ttable_restyle(tt); } /* Print PIM and IGMP route counts */ frr_each (rb_pim_oil, &pim->channel_oil_head, c_oil) - show_mroute_count_per_channel_oil(c_oil, json, vty); + show_mroute_count_per_channel_oil(c_oil, json, vty, tt); for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, sr)) - show_mroute_count_per_channel_oil(&sr->c_oil, json, vty); + show_mroute_count_per_channel_oil(&sr->c_oil, json, vty, tt); + + /* 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 show_mroute_summary(struct pim_instance *pim, struct vty *vty, |
