From 6d1bd8c28a7b8df89420c5819bd1224d55895811 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Wed, 8 Jun 2022 22:49:16 -0700 Subject: [PATCH 01/13] pim6d: Moving resuable code to common api for "show pim rpf" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 48 ++------------------------------------ pimd/pim_cmd.c | 48 ++------------------------------------ pimd/pim_cmd_common.c | 54 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 2 ++ 4 files changed, 60 insertions(+), 92 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 77844988ea..f86f3375d5 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -879,31 +879,7 @@ DEFPY (show_ipv6_pim_rpf, "PIM cached source rpf information\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - pim_show_rpf(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_rpf_helper(vrf, vty, !!json); } DEFPY (show_ipv6_pim_rpf_vrf_all, @@ -916,27 +892,7 @@ DEFPY (show_ipv6_pim_rpf_vrf_all, "PIM cached source rpf information\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_show_rpf(vrf->info, vty, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_rpf_vrf_all_helper(vty, !!json); } DEFPY (show_ipv6_pim_secondary, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 2d6ce24381..53ea54e906 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3343,31 +3343,7 @@ DEFPY (show_ip_pim_rpf, "PIM cached source rpf information\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - pim_show_rpf(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_rpf_helper(vrf, vty, !!json); } DEFPY (show_ip_pim_rpf_vrf_all, @@ -3380,27 +3356,7 @@ DEFPY (show_ip_pim_rpf_vrf_all, "PIM cached source rpf information\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_show_rpf(vrf->info, vty, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_rpf_vrf_all_helper(vty, !!json); } DEFPY (show_ip_pim_nexthop, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 668853e988..2807762175 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3737,3 +3737,57 @@ int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins, return CMD_SUCCESS; } + +int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json) +{ + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (json) + json_parent = json_object_new_object(); + + pim_show_rpf(pim, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json) +{ + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + pim_show_rpf(vrf->info, vty, json_vrf); + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 9644f84e0c..ce81473eb4 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -131,6 +131,8 @@ int pim_debug_pim_packets_cmd(const char *hello, const char *joins, const char *registers, struct vty *vty); int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins, const char *registers, struct vty *vty); +int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json); +int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json); /* * Special Macro to allow us to get the correct pim_instance; From e21c4e907540714cba39d5421699e5726911bec4 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 00:49:38 -0700 Subject: [PATCH 02/13] pim6d: Moving resuable code to common api for "show pim rp-info" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 68 +++------------------------------------ pimd/pim_cmd.c | 68 +++------------------------------------ pimd/pim_cmd_common.c | 74 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 4 +++ 4 files changed, 86 insertions(+), 128 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index f86f3375d5..1b83d38b91 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -790,40 +790,8 @@ DEFPY (show_ipv6_pim_rp, "Multicast Group range\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - struct prefix *range = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (group_str) { - range = prefix_new(); - prefix_copy(range, group); - apply_mask(range); - } - - if (json) - json_parent = json_object_new_object(); - - pim_rp_show_information(pim, range, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - prefix_free(&range); - - return CMD_SUCCESS; + return pim_show_rp_helper(vrf, vty, group_str, (struct prefix *)group, + !!json); } DEFPY (show_ipv6_pim_rp_vrf_all, @@ -837,36 +805,8 @@ DEFPY (show_ipv6_pim_rp_vrf_all, "Multicast Group range\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - struct prefix *range = NULL; - - if (group_str) { - range = prefix_new(); - prefix_copy(range, group); - apply_mask(range); - } - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_rp_show_information(vrf->info, range, vty, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - prefix_free(&range); - - return CMD_SUCCESS; + return pim_show_rp_vrf_all_helper(vty, group_str, + (struct prefix *)group, !!json); } DEFPY (show_ipv6_pim_rpf, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 53ea54e906..b67bc23523 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3254,40 +3254,8 @@ DEFPY (show_ip_pim_rp, "Multicast Group range\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - struct prefix *range = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (group_str) { - range = prefix_new(); - prefix_copy(range, group); - apply_mask(range); - } - - if (json) - json_parent = json_object_new_object(); - - pim_rp_show_information(pim, range, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - prefix_free(&range); - - return CMD_SUCCESS; + return pim_show_rp_helper(vrf, vty, group_str, (struct prefix *)group, + !!json); } DEFPY (show_ip_pim_rp_vrf_all, @@ -3301,36 +3269,8 @@ DEFPY (show_ip_pim_rp_vrf_all, "Multicast Group range\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - struct prefix *range = NULL; - - if (group_str) { - range = prefix_new(); - prefix_copy(range, group); - apply_mask(range); - } - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_rp_show_information(vrf->info, range, vty, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - prefix_free(&range); - - return CMD_SUCCESS; + return pim_show_rp_vrf_all_helper(vty, group_str, + (struct prefix *)group, !!json); } DEFPY (show_ip_pim_rpf, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 2807762175..3bc7381e0d 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3791,3 +3791,77 @@ int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json) return CMD_SUCCESS; } + +int pim_show_rp_helper(const char *vrf, struct vty *vty, const char *group_str, + const struct prefix *group, bool json) +{ + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + struct prefix *range = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (group_str) { + range = prefix_new(); + prefix_copy(range, group); + apply_mask(range); + } + + if (json) + json_parent = json_object_new_object(); + + pim_rp_show_information(pim, range, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + + prefix_free(&range); + + return CMD_SUCCESS; +} + +int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str, + const struct prefix *group, bool json) +{ + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + struct prefix *range = NULL; + + if (group_str) { + range = prefix_new(); + prefix_copy(range, group); + apply_mask(range); + } + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + pim_rp_show_information(vrf->info, range, vty, json_vrf); + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + if (json) + vty_json(vty, json_parent); + + prefix_free(&range); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index ce81473eb4..baea749778 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -133,6 +133,10 @@ int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins, const char *registers, struct vty *vty); int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json); int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json); +int pim_show_rp_helper(const char *vrf, struct vty *vty, const char *group_str, + const struct prefix *group, bool json); +int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str, + const struct prefix *group, bool json); /* * Special Macro to allow us to get the correct pim_instance; From 5e52c8d5c84e35cc5bbddeb79929ba38324b0204 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 01:33:01 -0700 Subject: [PATCH 03/13] pim6d: Moving reusable code to common api for "show pim secondary" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 19 +------------------ pimd/pim_cmd.c | 19 +------------------ pimd/pim_cmd_common.c | 22 ++++++++++++++++++++++ pimd/pim_cmd_common.h | 1 + 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 1b83d38b91..2f07392213 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -844,24 +844,7 @@ DEFPY (show_ipv6_pim_secondary, VRF_CMD_HELP_STR "PIM neighbor addresses\n") { - struct pim_instance *pim; - struct vrf *v; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_show_neighbors_secondary(pim, vty); - - return CMD_SUCCESS; + return pim_show_secondary_helper(vrf, vty); } DEFPY (show_ipv6_pim_statistics, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index b67bc23523..f8d0cf7eaf 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -2980,24 +2980,7 @@ DEFPY (show_ip_pim_secondary, VRF_CMD_HELP_STR "PIM neighbor addresses\n") { - struct pim_instance *pim; - struct vrf *v; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_show_neighbors_secondary(pim, vty); - - return CMD_SUCCESS; + return pim_show_secondary_helper(vrf, vty); } DEFPY (show_ip_pim_state, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 3bc7381e0d..303c9abe13 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3865,3 +3865,25 @@ int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str, return CMD_SUCCESS; } + +int pim_show_secondary_helper(const char *vrf, struct vty *vty) +{ + struct pim_instance *pim; + struct vrf *v; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + pim_show_neighbors_secondary(pim, vty); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index baea749778..c88dd48fe6 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -137,6 +137,7 @@ int pim_show_rp_helper(const char *vrf, struct vty *vty, const char *group_str, const struct prefix *group, bool json); int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str, const struct prefix *group, bool json); +int pim_show_secondary_helper(const char *vrf, struct vty *vty); /* * Special Macro to allow us to get the correct pim_instance; From 19296b58e4ceb9539a20e08777f90cea7a49c77e Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 01:59:58 -0700 Subject: [PATCH 04/13] pim6d: Moving reusable code to common api for "show pim statistics" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 23 +---------------------- pimd/pim_cmd.c | 23 +---------------------- pimd/pim_cmd_common.c | 26 ++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 2 ++ 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 2f07392213..74a9fd490a 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -859,28 +859,7 @@ DEFPY (show_ipv6_pim_statistics, "PIM interface\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - bool uj = !!json; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (word) - pim_show_statistics(pim, vty, word, uj); - else - pim_show_statistics(pim, vty, NULL, uj); - - return CMD_SUCCESS; + return pim_show_statistics_helper(vrf, vty, word, !!json); } DEFPY (show_ipv6_pim_upstream, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index f8d0cf7eaf..1bdd68bf4a 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3442,28 +3442,7 @@ DEFPY (show_ip_pim_statistics, "PIM interface\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - bool uj = !!json; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (word) - pim_show_statistics(pim, vty, word, uj); - else - pim_show_statistics(pim, vty, NULL, uj); - - return CMD_SUCCESS; + return pim_show_statistics_helper(vrf, vty, word, !!json); } DEFPY (show_ip_multicast, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 303c9abe13..46f48e91a1 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3887,3 +3887,29 @@ int pim_show_secondary_helper(const char *vrf, struct vty *vty) return CMD_SUCCESS; } + +int pim_show_statistics_helper(const char *vrf, struct vty *vty, + const char *word, bool uj) +{ + struct pim_instance *pim; + struct vrf *v; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (word) + pim_show_statistics(pim, vty, word, uj); + else + pim_show_statistics(pim, vty, NULL, uj); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index c88dd48fe6..4d5284b40b 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -138,6 +138,8 @@ int pim_show_rp_helper(const char *vrf, struct vty *vty, const char *group_str, int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str, const struct prefix *group, bool json); int pim_show_secondary_helper(const char *vrf, struct vty *vty); +int pim_show_statistics_helper(const char *vrf, struct vty *vty, + const char *word, bool uj); /* * Special Macro to allow us to get the correct pim_instance; From 9aa0569d6e7d59e097e9739fd757c8f4fe817279 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 02:40:21 -0700 Subject: [PATCH 05/13] pim6d: Moving reusable code to common api for "show pim upstream" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 61 ++------------------------------------- pimd/pim_cmd.c | 60 ++------------------------------------ pimd/pim_cmd_common.c | 67 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 3 ++ 4 files changed, 74 insertions(+), 117 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 74a9fd490a..446395272e 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -874,42 +874,7 @@ DEFPY (show_ipv6_pim_upstream, "The Group\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct vrf *v; - bool uj = !!json; - struct pim_instance *pim; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) { - vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf); - return CMD_WARNING; - } - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (uj) - json_parent = json_object_new_object(); - - if (!pim_addr_is_any(s_or_g)) { - if (!pim_addr_is_any(g)) { - sg.src = s_or_g; - sg.grp = g; - } else - sg.grp = s_or_g; - } - - pim_show_upstream(pim, vty, &sg, json_parent); - - if (uj) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_upstream_helper(vrf, vty, s_or_g, g, !!json); } DEFPY (show_ipv6_pim_upstream_vrf_all, @@ -922,29 +887,7 @@ DEFPY (show_ipv6_pim_upstream_vrf_all, "PIM upstream information\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_show_upstream(vrf->info, vty, &sg, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_upstream_vrf_all_helper(vty, !!json); } DEFPY (show_ipv6_pim_upstream_join_desired, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 1bdd68bf4a..ac16fd1b7f 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3069,41 +3069,7 @@ DEFPY (show_ip_pim_upstream, "The Group\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct vrf *v; - bool uj = !!json; - struct pim_instance *pim; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) { - vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf); - return CMD_WARNING; - } - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (uj) - json_parent = json_object_new_object(); - - if (s_or_g.s_addr != INADDR_ANY) { - if (g.s_addr != INADDR_ANY) { - sg.src = s_or_g; - sg.grp = g; - } else - sg.grp = s_or_g; - } - pim_show_upstream(pim, vty, &sg, json_parent); - - if (uj) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_upstream_helper(vrf, vty, s_or_g, g, !!json); } DEFPY (show_ip_pim_upstream_vrf_all, @@ -3116,29 +3082,7 @@ DEFPY (show_ip_pim_upstream_vrf_all, "PIM upstream information\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_show_upstream(vrf->info, vty, &sg, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_upstream_vrf_all_helper(vty, !!json); } DEFPY (show_ip_pim_channel, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 46f48e91a1..1159ebd3dd 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3913,3 +3913,70 @@ int pim_show_statistics_helper(const char *vrf, struct vty *vty, return CMD_SUCCESS; } + +int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, + pim_addr g, bool json) +{ + pim_sgaddr sg = {0}; + struct vrf *v; + struct pim_instance *pim; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) { + vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf); + return CMD_WARNING; + } + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (json) + json_parent = json_object_new_object(); + + if (!pim_addr_is_any(s_or_g)) { + if (!pim_addr_is_any(g)) { + sg.src = s_or_g; + sg.grp = g; + } else + sg.grp = s_or_g; + } + + pim_show_upstream(pim, vty, &sg, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json) +{ + pim_sgaddr sg = {0}; + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + pim_show_upstream(vrf->info, vty, &sg, json_vrf); + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 4d5284b40b..013db79599 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -140,6 +140,9 @@ int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str, int pim_show_secondary_helper(const char *vrf, struct vty *vty); int pim_show_statistics_helper(const char *vrf, struct vty *vty, const char *word, bool uj); +int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, + pim_addr g, bool json); +int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json); /* * Special Macro to allow us to get the correct pim_instance; From 622da92f356a5cda26d994ba260b107da5abd921 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 02:57:49 -0700 Subject: [PATCH 06/13] pim6d: Moving reusable code to common api for "show pim upstream join desired" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 20 +------------------- pimd/pim_cmd.c | 20 +------------------- pimd/pim_cmd_common.c | 23 +++++++++++++++++++++++ pimd/pim_cmd_common.h | 2 ++ 4 files changed, 27 insertions(+), 38 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 446395272e..998e0d1d74 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -900,25 +900,7 @@ DEFPY (show_ipv6_pim_upstream_join_desired, "PIM upstream join-desired\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - bool uj = !!json; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_show_join_desired(pim, vty, uj); - - return CMD_SUCCESS; + return pim_show_upstream_join_desired_helper(vrf, vty, !!json); } DEFPY (show_ipv6_pim_upstream_rpf, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index ac16fd1b7f..54e1aae4d1 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3118,25 +3118,7 @@ DEFPY (show_ip_pim_upstream_join_desired, "PIM upstream join-desired\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - bool uj = !!json; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_show_join_desired(pim, vty, uj); - - return CMD_SUCCESS; + return pim_show_upstream_join_desired_helper(vrf, vty, !!json); } DEFPY (show_ip_pim_upstream_rpf, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 1159ebd3dd..26a6e8a1c3 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3980,3 +3980,26 @@ int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json) return CMD_SUCCESS; } + +int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty, + bool uj) +{ + struct pim_instance *pim; + struct vrf *v; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + pim_show_join_desired(pim, vty, uj); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 013db79599..038f7f4d7f 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -143,6 +143,8 @@ int pim_show_statistics_helper(const char *vrf, struct vty *vty, int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, pim_addr g, bool json); int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json); +int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty, + bool uj); /* * Special Macro to allow us to get the correct pim_instance; From c630970866da41b90e3276ed5e8eeb52ccdda0ab Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 03:10:21 -0700 Subject: [PATCH 07/13] pim6d: Moving reusable code to common api for "show pim upstream rpf" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 20 +------------------- pimd/pim_cmd.c | 20 +------------------- pimd/pim_cmd_common.c | 22 ++++++++++++++++++++++ pimd/pim_cmd_common.h | 1 + 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 998e0d1d74..7f057dd509 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -913,25 +913,7 @@ DEFPY (show_ipv6_pim_upstream_rpf, "PIM upstream source rpf\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - bool uj = !!json; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_show_upstream_rpf(pim, vty, uj); - - return CMD_SUCCESS; + return pim_show_upstream_rpf_helper(vrf, vty, !!json); } DEFPY (show_ipv6_pim_state, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 54e1aae4d1..225d79c2e1 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3131,25 +3131,7 @@ DEFPY (show_ip_pim_upstream_rpf, "PIM upstream source rpf\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - bool uj = !!json; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_show_upstream_rpf(pim, vty, uj); - - return CMD_SUCCESS; + return pim_show_upstream_rpf_helper(vrf, vty, !!json); } DEFPY (show_ip_pim_rp, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 26a6e8a1c3..4c0a126225 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4003,3 +4003,25 @@ int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty, return CMD_SUCCESS; } + +int pim_show_upstream_rpf_helper(const char *vrf, struct vty *vty, bool uj) +{ + struct pim_instance *pim; + struct vrf *v; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + pim_show_upstream_rpf(pim, vty, uj); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 038f7f4d7f..0ce62d82dc 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -145,6 +145,7 @@ int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json); int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty, bool uj); +int pim_show_upstream_rpf_helper(const char *vrf, struct vty *vty, bool uj); /* * Special Macro to allow us to get the correct pim_instance; From e7c01c676950b0fe48ab44310a65e22cbcc5d0ee Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 03:29:02 -0700 Subject: [PATCH 08/13] pim6d: Moving reusable code to common api for "show pim state" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 48 ++----------------------------------- pimd/pim_cmd.c | 48 ++----------------------------------- pimd/pim_cmd_common.c | 56 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 4 ++++ 4 files changed, 64 insertions(+), 92 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 7f057dd509..0cdbb73c19 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -928,31 +928,7 @@ DEFPY (show_ipv6_pim_state, "Multicast address\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - pim_show_state(pim, vty, s_or_g_str, g_str, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_state_helper(vrf, vty, s_or_g_str, g_str, !!json); } DEFPY (show_ipv6_pim_state_vrf_all, @@ -967,27 +943,7 @@ DEFPY (show_ipv6_pim_state_vrf_all, "Multicast address\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_show_state(vrf->info, vty, s_or_g_str, g_str, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_state_vrf_all_helper(vty, s_or_g_str, g_str, !!json); } DEFPY (show_ipv6_pim_channel, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 225d79c2e1..6cd9e5fbd7 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -2995,31 +2995,7 @@ DEFPY (show_ip_pim_state, "Multicast address\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - pim_show_state(pim, vty, s_or_g_str, g_str, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_state_helper(vrf, vty, s_or_g_str, g_str, !!json); } DEFPY (show_ip_pim_state_vrf_all, @@ -3034,27 +3010,7 @@ DEFPY (show_ip_pim_state_vrf_all, "Multicast address\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - pim_show_state(vrf->info, vty, s_or_g_str, g_str, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_state_vrf_all_helper(vty, s_or_g_str, g_str, !!json); } DEFPY (show_ip_pim_upstream, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 4c0a126225..a2a0891779 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4025,3 +4025,59 @@ int pim_show_upstream_rpf_helper(const char *vrf, struct vty *vty, bool uj) return CMD_SUCCESS; } + +int pim_show_state_helper(const char *vrf, struct vty *vty, + const char *s_or_g_str, const char *g_str, bool json) +{ + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (json) + json_parent = json_object_new_object(); + + pim_show_state(pim, vty, s_or_g_str, g_str, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str, + const char *g_str, bool json) +{ + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + pim_show_state(vrf->info, vty, s_or_g_str, g_str, json_vrf); + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 0ce62d82dc..981e6dc88f 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -146,6 +146,10 @@ int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json); int pim_show_upstream_join_desired_helper(const char *vrf, struct vty *vty, bool uj); int pim_show_upstream_rpf_helper(const char *vrf, struct vty *vty, bool uj); +int pim_show_state_helper(const char *vrf, struct vty *vty, + const char *s_or_g_str, const char *g_str, bool json); +int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str, + const char *g_str, bool json); /* * Special Macro to allow us to get the correct pim_instance; From 8e15c9aa064d92f290ace12d578274a3c575a98e Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 03:51:41 -0700 Subject: [PATCH 09/13] pim6d: Moving reusable code to common api for "show ip/ipv6 multicast" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 28 ++-------------------------- pimd/pim_cmd.c | 28 ++-------------------------- pimd/pim_cmd_common.c | 34 ++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 2 ++ 4 files changed, 40 insertions(+), 52 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 0cdbb73c19..e9d90b104d 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1329,24 +1329,7 @@ DEFPY (show_ipv6_multicast, "Multicast global information\n" VRF_CMD_HELP_STR) { - struct vrf *v; - struct pim_instance *pim; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_cmd_show_ip_multicast_helper(pim, vty); - - return CMD_SUCCESS; + return pim_show_multicast_helper(vrf, vty); } DEFPY (show_ipv6_multicast_vrf_all, @@ -1357,14 +1340,7 @@ DEFPY (show_ipv6_multicast_vrf_all, "Multicast global information\n" VRF_CMD_HELP_STR) { - struct vrf *vrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - vty_out(vty, "VRF: %s\n", vrf->name); - pim_cmd_show_ip_multicast_helper(vrf->info, vty); - } - - return CMD_SUCCESS; + return pim_show_multicast_vrf_all_helper(vty); } DEFPY (show_ipv6_multicast_count, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 6cd9e5fbd7..1766bd1fae 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3317,24 +3317,7 @@ DEFPY (show_ip_multicast, "Multicast global information\n" VRF_CMD_HELP_STR) { - struct vrf *v; - struct pim_instance *pim; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - pim_cmd_show_ip_multicast_helper(pim, vty); - - return CMD_SUCCESS; + return pim_show_multicast_helper(vrf, vty); } DEFPY (show_ip_multicast_vrf_all, @@ -3345,14 +3328,7 @@ DEFPY (show_ip_multicast_vrf_all, "Multicast global information\n" VRF_CMD_HELP_STR) { - struct vrf *vrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - vty_out(vty, "VRF: %s\n", vrf->name); - pim_cmd_show_ip_multicast_helper(vrf->info, vty); - } - - return CMD_SUCCESS; + return pim_show_multicast_vrf_all_helper(vty); } DEFPY (show_ip_multicast_count, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index a2a0891779..7a05118677 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4081,3 +4081,37 @@ int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str, return CMD_SUCCESS; } + +int pim_show_multicast_helper(const char *vrf, struct vty *vty) +{ + struct vrf *v; + struct pim_instance *pim; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + pim_cmd_show_ip_multicast_helper(pim, vty); + + return CMD_SUCCESS; +} + +int pim_show_multicast_vrf_all_helper(struct vty *vty) +{ + struct vrf *vrf; + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + vty_out(vty, "VRF: %s\n", vrf->name); + pim_cmd_show_ip_multicast_helper(vrf->info, vty); + } + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 981e6dc88f..ceba2f2b41 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -150,6 +150,8 @@ int pim_show_state_helper(const char *vrf, struct vty *vty, const char *s_or_g_str, const char *g_str, bool json); int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str, const char *g_str, bool json); +int pim_show_multicast_helper(const char *vrf, struct vty *vty); +int pim_show_multicast_vrf_all_helper(struct vty *vty); /* * Special Macro to allow us to get the correct pim_instance; From 334d2f8c3d30ef565fde12f0bd76d08aecb4e837 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 04:04:14 -0700 Subject: [PATCH 10/13] pim6d: Moving reusable code to common api for "show ip/ipv6 multicast count" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 49 ++------------------------------------ pimd/pim_cmd.c | 49 ++------------------------------------ pimd/pim_cmd_common.c | 55 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 3 +++ 4 files changed, 62 insertions(+), 94 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index e9d90b104d..4476b8b103 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1353,31 +1353,7 @@ DEFPY (show_ipv6_multicast_count, VRF_CMD_HELP_STR JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - show_multicast_interfaces(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_multicast_count_helper(vrf, vty, !!json); } DEFPY (show_ipv6_multicast_count_vrf_all, @@ -1390,28 +1366,7 @@ DEFPY (show_ipv6_multicast_count_vrf_all, VRF_CMD_HELP_STR JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - - show_multicast_interfaces(vrf->info, vty, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_multicast_count_vrf_all_helper(vty, !!json); } DEFPY (show_ipv6_mroute, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 1766bd1fae..dc36471f69 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3341,31 +3341,7 @@ DEFPY (show_ip_multicast_count, VRF_CMD_HELP_STR JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - show_multicast_interfaces(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_multicast_count_helper(vrf, vty, !!json); } DEFPY (show_ip_multicast_count_vrf_all, @@ -3378,28 +3354,7 @@ DEFPY (show_ip_multicast_count_vrf_all, VRF_CMD_HELP_STR JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - - show_multicast_interfaces(vrf->info, vty, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_multicast_count_vrf_all_helper(vty, !!json); } DEFPY (show_ip_mroute, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 7a05118677..e5052dfe9a 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4115,3 +4115,58 @@ int pim_show_multicast_vrf_all_helper(struct vty *vty) return CMD_SUCCESS; } + +int pim_show_multicast_count_helper(const char *vrf, struct vty *vty, bool json) +{ + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (json) + json_parent = json_object_new_object(); + + show_multicast_interfaces(pim, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json) +{ + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + + show_multicast_interfaces(vrf->info, vty, json_vrf); + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index ceba2f2b41..a7fbefb862 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -152,6 +152,9 @@ int pim_show_state_vrf_all_helper(struct vty *vty, const char *s_or_g_str, const char *g_str, bool json); int pim_show_multicast_helper(const char *vrf, struct vty *vty); int pim_show_multicast_vrf_all_helper(struct vty *vty); +int pim_show_multicast_count_helper(const char *vrf, struct vty *vty, + bool json); +int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json); /* * Special Macro to allow us to get the correct pim_instance; From 4f1f8ff9aa2ee0b944f43453879e93e70e44d598 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 04:27:20 -0700 Subject: [PATCH 11/13] pim6d: Moving reusable code to common api for "show ip/ipv6 mroute" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 58 ++------------------------------------ pimd/pim_cmd.c | 58 ++------------------------------------ pimd/pim_cmd_common.c | 65 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 3 ++ 4 files changed, 72 insertions(+), 112 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 4476b8b103..1d5764a4fe 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1381,40 +1381,7 @@ DEFPY (show_ipv6_mroute, "Fill in Assumed data\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - if (!pim_addr_is_any(s_or_g)) { - if (!pim_addr_is_any(g)) { - sg.src = s_or_g; - sg.grp = g; - } else - sg.grp = s_or_g; - } - - show_mroute(pim, vty, &sg, !!fill, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_helper(vrf, vty, s_or_g, g, !!fill, !!json); } DEFPY (show_ipv6_mroute_vrf_all, @@ -1427,28 +1394,7 @@ DEFPY (show_ipv6_mroute_vrf_all, "Fill in Assumed data\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - show_mroute(vrf->info, vty, &sg, !!fill, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_vrf_all_helper(vty, !!fill, !!json); } DEFPY (show_ipv6_mroute_count, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index dc36471f69..411963b03d 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3369,40 +3369,7 @@ DEFPY (show_ip_mroute, "Fill in Assumed data\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - if (s_or_g.s_addr != INADDR_ANY) { - if (g.s_addr != INADDR_ANY) { - sg.src = s_or_g; - sg.grp = g; - } else - sg.grp = s_or_g; - } - - show_mroute(pim, vty, &sg, !!fill, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_helper(vrf, vty, s_or_g, g, !!fill, !!json); } DEFPY (show_ip_mroute_vrf_all, @@ -3415,28 +3382,7 @@ DEFPY (show_ip_mroute_vrf_all, "Fill in Assumed data\n" JSON_STR) { - pim_sgaddr sg = {0}; - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - show_mroute(vrf->info, vty, &sg, !!fill, json_vrf); - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_vrf_all_helper(vty, !!fill, !!json); } DEFPY (clear_ip_mroute_count, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index e5052dfe9a..c1f67d7b3b 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4170,3 +4170,68 @@ int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json) return CMD_SUCCESS; } + +int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, + pim_addr g, bool fill, bool json) +{ + pim_sgaddr sg = {0}; + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (json) + json_parent = json_object_new_object(); + + if (!pim_addr_is_any(s_or_g)) { + if (!pim_addr_is_any(g)) { + sg.src = s_or_g; + sg.grp = g; + } else + sg.grp = s_or_g; + } + + show_mroute(pim, vty, &sg, fill, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json) +{ + pim_sgaddr sg = {0}; + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + show_mroute(vrf->info, vty, &sg, fill, json_vrf); + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index a7fbefb862..161e30ee85 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -155,6 +155,9 @@ int pim_show_multicast_vrf_all_helper(struct vty *vty); int pim_show_multicast_count_helper(const char *vrf, struct vty *vty, bool json); int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json); +int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, + pim_addr g, bool fill, bool json); +int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json); /* * Special Macro to allow us to get the correct pim_instance; From 1c1077c200ae5b917dcea1439087013a1d5791b7 Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 04:43:28 -0700 Subject: [PATCH 12/13] pim6d: Moving reusable code to common api for "show ip/ipv6 mroute count" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 50 ++------------------------------------ pimd/pim_cmd.c | 50 ++------------------------------------ pimd/pim_cmd_common.c | 56 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 2 ++ 4 files changed, 62 insertions(+), 96 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 1d5764a4fe..192c62044b 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1407,31 +1407,7 @@ DEFPY (show_ipv6_mroute_count, "Route and packet count data\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - show_mroute_count(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_count_helper(vrf, vty, !!json); } DEFPY (show_ipv6_mroute_count_vrf_all, @@ -1444,29 +1420,7 @@ DEFPY (show_ipv6_mroute_count_vrf_all, "Route and packet count data\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - show_mroute_count(vrf->info, vty, json_vrf); - - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_count_vrf_all_helper(vty, !!json); } DEFPY (show_ipv6_mroute_summary, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 411963b03d..3442f83156 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3407,31 +3407,7 @@ DEFPY (show_ip_mroute_count, "Route and packet count data\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - show_mroute_count(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_count_helper(vrf, vty, !!json); } DEFPY (show_ip_mroute_count_vrf_all, @@ -3444,29 +3420,7 @@ DEFPY (show_ip_mroute_count_vrf_all, "Route and packet count data\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - - show_mroute_count(vrf->info, vty, json_vrf); - - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_count_vrf_all_helper(vty, !!json); } DEFPY (show_ip_mroute_summary, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index c1f67d7b3b..c298c60c75 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4235,3 +4235,59 @@ int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json) return CMD_SUCCESS; } + +int pim_show_mroute_count_helper(const char *vrf, struct vty *vty, bool json) +{ + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (json) + json_parent = json_object_new_object(); + + show_mroute_count(pim, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json) +{ + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + + show_mroute_count(vrf->info, vty, json_vrf); + + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 161e30ee85..79783ca409 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -158,6 +158,8 @@ int pim_show_multicast_count_vrf_all_helper(struct vty *vty, bool json); int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, pim_addr g, bool fill, bool json); int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json); +int pim_show_mroute_count_helper(const char *vrf, struct vty *vty, bool json); +int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json); /* * Special Macro to allow us to get the correct pim_instance; From 789d0ec4def92ec1fe6a0d24d5eefe7ba8f0fd0f Mon Sep 17 00:00:00 2001 From: Abhishek N R Date: Thu, 9 Jun 2022 04:53:12 -0700 Subject: [PATCH 13/13] pim6d: Moving reusable code to common api for "show mroute summary" command Signed-off-by: Abhishek N R --- pimd/pim6_cmd.c | 51 ++------------------------------------ pimd/pim_cmd.c | 51 ++------------------------------------ pimd/pim_cmd_common.c | 57 +++++++++++++++++++++++++++++++++++++++++++ pimd/pim_cmd_common.h | 2 ++ 4 files changed, 63 insertions(+), 98 deletions(-) diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 192c62044b..0cf7a2f347 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1433,31 +1433,7 @@ DEFPY (show_ipv6_mroute_summary, "Summary of all mroutes\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - show_mroute_summary(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_summary_helper(vrf, vty, !!json); } DEFPY (show_ipv6_mroute_summary_vrf_all, @@ -1470,30 +1446,7 @@ DEFPY (show_ipv6_mroute_summary_vrf_all, "Summary of all mroutes\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - - show_mroute_summary(vrf->info, vty, json_vrf); - - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_summary_vrf_all_helper(vty, !!json); } DEFPY (clear_ipv6_pim_statistics, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 3442f83156..9abd5a3b76 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3433,31 +3433,7 @@ DEFPY (show_ip_mroute_summary, "Summary of all mroutes\n" JSON_STR) { - struct pim_instance *pim; - struct vrf *v; - json_object *json_parent = NULL; - - v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); - - if (!v) - return CMD_WARNING; - - pim = pim_get_pim_instance(v->vrf_id); - - if (!pim) { - vty_out(vty, "%% Unable to find pim instance\n"); - return CMD_WARNING; - } - - if (json) - json_parent = json_object_new_object(); - - show_mroute_summary(pim, vty, json_parent); - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_summary_helper(vrf, vty, !!json); } DEFPY (show_ip_mroute_summary_vrf_all, @@ -3470,30 +3446,7 @@ DEFPY (show_ip_mroute_summary_vrf_all, "Summary of all mroutes\n" JSON_STR) { - struct vrf *vrf; - json_object *json_parent = NULL; - json_object *json_vrf = NULL; - - if (json) - json_parent = json_object_new_object(); - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!json) - vty_out(vty, "VRF: %s\n", vrf->name); - else - json_vrf = json_object_new_object(); - - show_mroute_summary(vrf->info, vty, json_vrf); - - if (json) - json_object_object_add(json_parent, vrf->name, - json_vrf); - } - - if (json) - vty_json(vty, json_parent); - - return CMD_SUCCESS; + return pim_show_mroute_summary_vrf_all_helper(vty, !!json); } DEFUN (show_ip_rib, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index c298c60c75..bc3d8d0fca 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4291,3 +4291,60 @@ int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json) return CMD_SUCCESS; } + +int pim_show_mroute_summary_helper(const char *vrf, struct vty *vty, bool json) +{ + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (json) + json_parent = json_object_new_object(); + + show_mroute_summary(pim, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_mroute_summary_vrf_all_helper(struct vty *vty, bool json) +{ + struct vrf *vrf; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); + + show_mroute_summary(vrf->info, vty, json_vrf); + + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); + } + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 79783ca409..437d92897f 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -160,6 +160,8 @@ int pim_show_mroute_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, int pim_show_mroute_vrf_all_helper(struct vty *vty, bool fill, bool json); int pim_show_mroute_count_helper(const char *vrf, struct vty *vty, bool json); int pim_show_mroute_count_vrf_all_helper(struct vty *vty, bool json); +int pim_show_mroute_summary_helper(const char *vrf, struct vty *vty, bool json); +int pim_show_mroute_summary_vrf_all_helper(struct vty *vty, bool json); /* * Special Macro to allow us to get the correct pim_instance;