diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 7f7c3979c7..185ec33f9c 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1615,6 +1615,77 @@ DEFPY (show_ipv6_multicast_vrf_all, return CMD_SUCCESS; } +DEFPY (show_ipv6_multicast_count, + show_ipv6_multicast_count_cmd, + "show ipv6 multicast count [vrf NAME] [json$json]", + SHOW_STR + IPV6_STR + "Multicast global information\n" + "Data packet count\n" + 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; +} + +DEFPY (show_ipv6_multicast_count_vrf_all, + show_ipv6_multicast_count_vrf_all_cmd, + "show ipv6 multicast count vrf all [json$json]", + SHOW_STR + IPV6_STR + "Multicast global information\n" + "Data packet count\n" + 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; +} + void pim_cmd_init(void) { if_cmd_init(pim_interface_config_write); @@ -1713,4 +1784,6 @@ void pim_cmd_init(void) install_element(VIEW_NODE, &show_ipv6_pim_nexthop_lookup_cmd); install_element(VIEW_NODE, &show_ipv6_multicast_cmd); install_element(VIEW_NODE, &show_ipv6_multicast_vrf_all_cmd); + install_element(VIEW_NODE, &show_ipv6_multicast_count_cmd); + install_element(VIEW_NODE, &show_ipv6_multicast_count_vrf_all_cmd); } diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index f723536469..0a90d625c2 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3695,56 +3695,73 @@ DEFPY (show_ip_multicast_vrf_all, return CMD_SUCCESS; } -DEFUN(show_ip_multicast_count, - show_ip_multicast_count_cmd, - "show ip multicast count [vrf NAME] [json]", - SHOW_STR IP_STR - "Multicast global information\n" - "Data packet count\n" - VRF_CMD_HELP_STR JSON_STR) +DEFPY (show_ip_multicast_count, + show_ip_multicast_count_cmd, + "show ip multicast count [vrf NAME] [json$json]", + SHOW_STR + IP_STR + "Multicast global information\n" + "Data packet count\n" + VRF_CMD_HELP_STR + JSON_STR) { - int idx = 3; - struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - bool uj = use_json(argc, argv); + struct pim_instance *pim; + struct vrf *v; + json_object *json_parent = NULL; - if (!vrf) + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) return CMD_WARNING; - show_multicast_interfaces(vrf->info, vty, uj); + 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; } -DEFUN(show_ip_multicast_count_vrf_all, - show_ip_multicast_count_vrf_all_cmd, - "show ip multicast count vrf all [json]", - SHOW_STR IP_STR - "Multicast global information\n" - "Data packet count\n" - VRF_CMD_HELP_STR JSON_STR) +DEFPY (show_ip_multicast_count_vrf_all, + show_ip_multicast_count_vrf_all_cmd, + "show ip multicast count vrf all [json$json]", + SHOW_STR + IP_STR + "Multicast global information\n" + "Data packet count\n" + VRF_CMD_HELP_STR + JSON_STR) { - bool uj = use_json(argc, argv); struct vrf *vrf; - bool first = true; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; - if (uj) - vty_out(vty, "{ "); + if (json) + json_parent = json_object_new_object(); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (uj) { - if (!first) - vty_out(vty, ", "); - - vty_out(vty, " \"%s\": ", vrf->name); - first = false; - } else + if (!json) vty_out(vty, "VRF: %s\n", vrf->name); + else + json_vrf = json_object_new_object(); - show_multicast_interfaces(vrf->info, vty, uj); + show_multicast_interfaces(vrf->info, vty, json_vrf); + if (json) + json_object_object_add(json_parent, vrf->name, + json_vrf); } - - if (uj) - vty_out(vty, "}\n"); + if (json) + vty_json(vty, json_parent); return CMD_SUCCESS; } diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 784ef2e311..5bcde48e2e 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -2882,17 +2882,14 @@ static void show_scan_oil_stats(struct pim_instance *pim, struct vty *vty, } void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, - bool uj) + json_object *json) { struct interface *ifp; - json_object *json = NULL; json_object *json_row = NULL; vty_out(vty, "\n"); - if (uj) - json = json_object_new_object(); - else + if (!json) vty_out(vty, "Interface Address ifi Vif PktsIn PktsOut BytesIn BytesOut\n"); @@ -2930,7 +2927,7 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, } #endif - if (uj) { + if (json) { json_row = json_object_new_object(); json_object_string_add(json_row, "name", ifp->name); json_object_string_add(json_row, "state", @@ -2960,9 +2957,6 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, (unsigned long)vreq.obytes); } } - - if (uj) - vty_json(vty, json); } void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty) @@ -3011,5 +3005,5 @@ void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty) show_scan_oil_stats(pim, vty, now); - show_multicast_interfaces(pim, vty, false); + show_multicast_interfaces(pim, vty, NULL); } diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 5f7021280e..9fac2c111b 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -107,7 +107,7 @@ int pim_process_ssmpingd_cmd(struct vty *vty, enum nb_operation operation, void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty); void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, - bool uj); + json_object *json); /* * Special Macro to allow us to get the correct pim_instance;