Merge pull request #11844 from SaiGomathiN/ttable-1

pimd, pim6d: Using ttable for displaying show CLIs
This commit is contained in:
Donatas Abraitis 2022-08-26 11:48:18 +03:00 committed by GitHub
commit 5e48498795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1827,11 +1827,12 @@ void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg,
} }
} }
static void pim_show_jp_agg_helper(struct vty *vty, struct interface *ifp, static void pim_show_jp_agg_helper(struct interface *ifp,
struct pim_neighbor *neigh, struct pim_neighbor *neigh,
struct pim_upstream *up, int is_join) struct pim_upstream *up, int is_join,
struct ttable *tt)
{ {
vty_out(vty, "%-16s %-15pPAs %-15pPAs %-15pPAs %5s\n", ifp->name, ttable_add_row(tt, "%s|%pPAs|%pPAs|%pPAs|%s", ifp->name,
&neigh->source_addr, &up->sg.src, &up->sg.grp, &neigh->source_addr, &up->sg.src, &up->sg.grp,
is_join ? "J" : "P"); is_join ? "J" : "P");
} }
@ -1869,9 +1870,15 @@ void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty)
struct pim_jp_agg_group *jag; struct pim_jp_agg_group *jag;
struct listnode *js_node; struct listnode *js_node;
struct pim_jp_sources *js; struct pim_jp_sources *js;
struct ttable *tt;
char *table;
vty_out(vty, /* Prepare table. */
"Interface RPF Nbr Source Group State\n"); tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
ttable_add_row(tt, "Interface|RPF Nbr|Source|Group|State");
tt->style.cell.rpad = 2;
tt->style.corner = '+';
ttable_restyle(tt);
FOR_ALL_INTERFACES (pim->vrf, ifp) { FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info; pim_ifp = ifp->info;
@ -1884,13 +1891,19 @@ void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty)
jag_node, jag)) { jag_node, jag)) {
for (ALL_LIST_ELEMENTS_RO(jag->sources, js_node, for (ALL_LIST_ELEMENTS_RO(jag->sources, js_node,
js)) { js)) {
pim_show_jp_agg_helper(vty, ifp, neigh, pim_show_jp_agg_helper(ifp, neigh,
js->up, js->up,
js->is_join); js->is_join, tt);
} }
} }
} }
} }
/* Dump the generated table. */
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
XFREE(MTYPE_TMP, table);
ttable_del(tt);
} }
int pim_show_membership_cmd_helper(const char *vrf, struct vty *vty, bool uj) int pim_show_membership_cmd_helper(const char *vrf, struct vty *vty, bool uj)
@ -2025,10 +2038,10 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj)
} }
} }
static void pim_show_channel_helper(struct pim_instance *pim, struct vty *vty, static void pim_show_channel_helper(struct pim_instance *pim,
struct pim_interface *pim_ifp, struct pim_interface *pim_ifp,
struct pim_ifchannel *ch, json_object *json, struct pim_ifchannel *ch, json_object *json,
bool uj) bool uj, struct ttable *tt)
{ {
struct pim_upstream *up = ch->upstream; struct pim_upstream *up = ch->upstream;
json_object *json_group = NULL; json_object *json_group = NULL;
@ -2071,8 +2084,7 @@ static void pim_show_channel_helper(struct pim_instance *pim, struct vty *vty,
&up->sg.src); &up->sg.src);
} else { } else {
vty_out(vty, ttable_add_row(tt, "%s|%pPAs|%pPAs|%s|%s|%s|%s|%s",
"%-16s %-15pPAs %-15pPAs %-10s %-5s %-10s %-11s %-6s\n",
ch->interface->name, &up->sg.src, &up->sg.grp, ch->interface->name, &up->sg.src, &up->sg.grp,
pim_macro_ch_lost_assert(ch) ? "yes" : "no", pim_macro_ch_lost_assert(ch) ? "yes" : "no",
pim_macro_chisin_joins(ch) ? "yes" : "no", pim_macro_chisin_joins(ch) ? "yes" : "no",
@ -2080,7 +2092,8 @@ static void pim_show_channel_helper(struct pim_instance *pim, struct vty *vty,
PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up->flags) PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up->flags)
? "yes" ? "yes"
: "no", : "no",
pim_upstream_evaluate_join_desired(pim, up) ? "yes" pim_upstream_evaluate_join_desired(pim, up)
? "yes"
: "no"); : "no");
} }
} }
@ -2090,14 +2103,22 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj)
struct pim_interface *pim_ifp; struct pim_interface *pim_ifp;
struct pim_ifchannel *ch; struct pim_ifchannel *ch;
struct interface *ifp; struct interface *ifp;
struct ttable *tt = NULL;
json_object *json = NULL; json_object *json = NULL;
char *table = NULL;
if (uj) if (uj)
json = json_object_new_object(); json = json_object_new_object();
else else {
vty_out(vty, /* Prepare table. */
"Interface Source Group LostAssert Joins PimInclude JoinDesired EvalJD\n"); tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
ttable_add_row(
tt,
"Interface|Source|Group|LostAssert|Joins|PimInclude|JoinDesired|EvalJD");
tt->style.cell.rpad = 2;
tt->style.corner = '+';
ttable_restyle(tt);
}
/* scan per-interface (S,G) state */ /* scan per-interface (S,G) state */
FOR_ALL_INTERFACES (pim->vrf, ifp) { FOR_ALL_INTERFACES (pim->vrf, ifp) {
@ -2105,16 +2126,21 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj)
if (!pim_ifp) if (!pim_ifp)
continue; continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) { RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
/* scan all interfaces */ /* scan all interfaces */
pim_show_channel_helper(pim, vty, pim_ifp, ch, json, pim_show_channel_helper(pim, pim_ifp, ch, json, uj, tt);
uj);
} }
} }
if (uj) if (uj)
vty_json(vty, json); vty_json(vty, json);
else {
/* Dump the generated table. */
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
XFREE(MTYPE_TMP, table);
ttable_del(tt);
}
} }
int pim_show_channel_cmd_helper(const char *vrf, struct vty *vty, bool uj) int pim_show_channel_cmd_helper(const char *vrf, struct vty *vty, bool uj)