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 <abnr@vmware.com>
This commit is contained in:
Abhishek N R 2022-09-16 10:37:21 -07:00
parent c3cd01eb06
commit ad994e7a8a

View File

@ -1969,6 +1969,8 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj)
enum json_type type; enum json_type type;
json_object *json = NULL; json_object *json = NULL;
json_object *json_tmp = NULL; json_object *json_tmp = NULL;
struct ttable *tt = NULL;
char *table = NULL;
json = json_object_new_object(); json = json_object_new_object();
@ -1985,8 +1987,12 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj)
if (uj) { if (uj) {
vty_json(vty, json); vty_json(vty, json);
} else { } else {
vty_out(vty, /* Prepare table. */
"Interface Address Source Group Membership\n"); 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 * 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); type = json_object_get_type(if_field_val);
if (type == json_type_object) { if (type == json_type_object) {
vty_out(vty, "%-16s ", key); const char *address, *source,
*localMembership;
json_object_object_get_ex( json_object_object_get_ex(
val, "address", &json_tmp); val, "address", &json_tmp);
vty_out(vty, "%-15s ", address = json_object_get_string(
json_object_get_string( json_tmp);
json_tmp));
json_object_object_get_ex(if_field_val, json_object_object_get_ex(if_field_val,
"source", "source",
&json_tmp); &json_tmp);
vty_out(vty, "%-15s ", source = json_object_get_string(
json_object_get_string( json_tmp);
json_tmp));
/* Group */
vty_out(vty, "%-15s ", if_field_key);
json_object_object_get_ex( json_object_object_get_ex(
if_field_val, "localMembership", if_field_val, "localMembership",
&json_tmp); &json_tmp);
vty_out(vty, "%-10s\n", localMembership =
json_object_get_string( 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); 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);
} }
} }