From ad994e7a8a89a3723105cfa6959e7f4b33cd9375 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Fri, 16 Sep 2022 10:37:21 -0700 Subject: [PATCH] pimd, pim6d: Using ttable for displaying "show ip/ipv6 pim local-membership" command output Before: frr# sh ipv6 pim local-membership Interface Address Source Group Membership ens224 fe80::250:56ff:feb7:9091 * ff08::1 NOINFO After: frr# sh ipv6 pim local-membership Interface Address Source Group Membership ens224 fe80::250:56ff:feb7:9091 * ff08::1 NOINFO Signed-off-by: Abhishek N R --- pimd/pim_cmd_common.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 4798f3b3ef..afb360f9b5 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -1969,6 +1969,8 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj) enum json_type type; json_object *json = NULL; json_object *json_tmp = NULL; + struct ttable *tt = NULL; + char *table = NULL; json = json_object_new_object(); @@ -1985,8 +1987,12 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj) if (uj) { vty_json(vty, json); } else { - vty_out(vty, - "Interface Address Source Group Membership\n"); + /* Prepare table. */ + tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + ttable_add_row(tt, "Interface|Address|Source|Group|Membership"); + tt->style.cell.rpad = 2; + tt->style.corner = '+'; + ttable_restyle(tt); /* * Example of the json data we are traversing @@ -2023,34 +2029,40 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj) type = json_object_get_type(if_field_val); if (type == json_type_object) { - vty_out(vty, "%-16s ", key); + const char *address, *source, + *localMembership; json_object_object_get_ex( val, "address", &json_tmp); - vty_out(vty, "%-15s ", - json_object_get_string( - json_tmp)); + address = json_object_get_string( + json_tmp); json_object_object_get_ex(if_field_val, "source", &json_tmp); - vty_out(vty, "%-15s ", - json_object_get_string( - json_tmp)); - - /* Group */ - vty_out(vty, "%-15s ", if_field_key); + source = json_object_get_string( + json_tmp); json_object_object_get_ex( if_field_val, "localMembership", &json_tmp); - vty_out(vty, "%-10s\n", + localMembership = json_object_get_string( - json_tmp)); + json_tmp); + + ttable_add_row(tt, "%s|%s|%s|%s|%s", + key, address, source, + if_field_key, + localMembership); } } } json_object_free(json); + /* Dump the generated table. */ + table = ttable_dump(tt, "\n"); + vty_out(vty, "%s\n", table); + XFREE(MTYPE_TMP, table); + ttable_del(tt); } } -- 2.39.5