diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index e69e76a5cb..b0be4390bf 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1768,6 +1768,78 @@ DEFPY (show_ipv6_mroute_vrf_all, return CMD_SUCCESS; } +DEFPY (show_ipv6_mroute_count, + show_ipv6_mroute_count_cmd, + "show ipv6 mroute [vrf NAME] count [json$json]", + SHOW_STR + IPV6_STR + MROUTE_STR + VRF_CMD_HELP_STR + "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; +} + +DEFPY (show_ipv6_mroute_count_vrf_all, + show_ipv6_mroute_count_vrf_all_cmd, + "show ipv6 mroute vrf all count [json$json]", + SHOW_STR + IPV6_STR + MROUTE_STR + VRF_CMD_HELP_STR + "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; +} + void pim_cmd_init(void) { if_cmd_init(pim_interface_config_write); @@ -1870,4 +1942,6 @@ void pim_cmd_init(void) install_element(VIEW_NODE, &show_ipv6_multicast_count_vrf_all_cmd); install_element(VIEW_NODE, &show_ipv6_mroute_cmd); install_element(VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd); + install_element(VIEW_NODE, &show_ipv6_mroute_count_cmd); + install_element(VIEW_NODE, &show_ipv6_mroute_count_vrf_all_cmd); } diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 6f862c74f6..db6945a624 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3891,9 +3891,9 @@ DEFUN (clear_ip_mroute_count, return CMD_SUCCESS; } -DEFUN (show_ip_mroute_count, +DEFPY (show_ip_mroute_count, show_ip_mroute_count_cmd, - "show ip mroute [vrf NAME] count [json]", + "show ip mroute [vrf NAME] count [json$json]", SHOW_STR IP_STR MROUTE_STR @@ -3901,20 +3901,36 @@ DEFUN (show_ip_mroute_count, "Route and packet count data\n" JSON_STR) { - int idx = 2; - bool uj = use_json(argc, argv); - struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); + 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_mroute_count(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_mroute_count(pim, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + return CMD_SUCCESS; } -DEFUN (show_ip_mroute_count_vrf_all, +DEFPY (show_ip_mroute_count_vrf_all, show_ip_mroute_count_vrf_all_cmd, - "show ip mroute vrf all count [json]", + "show ip mroute vrf all count [json$json]", SHOW_STR IP_STR MROUTE_STR @@ -3922,24 +3938,27 @@ DEFUN (show_ip_mroute_count_vrf_all, "Route and packet count data\n" 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 (json) + json_parent = json_object_new_object(); - if (uj) - vty_out(vty, "{ "); 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); - show_mroute_count(vrf->info, vty, uj); + 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 (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 4c570c351c..197b9b8d5e 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -3391,13 +3391,10 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, } } -#if PIM_IPV == 4 static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, json_object *json, struct vty *vty) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; json_object *json_group = NULL; json_object *json_source = NULL; @@ -3406,12 +3403,15 @@ static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, pim_mroute_update_counters(c_oil); - pim_inet4_dump("", c_oil->oil.mfcc_mcastgrp, group_str, - sizeof(group_str)); - pim_inet4_dump("", c_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); - if (json) { + char group_str[PIM_ADDRSTRLEN]; + char source_str[PIM_ADDRSTRLEN]; + + snprintfrr(group_str, sizeof(group_str), "%pPAs", + oil_mcastgrp(c_oil)); + snprintfrr(source_str, sizeof(source_str), "%pPAs", + oil_origin(c_oil)); + json_object_object_get_ex(json, group_str, &json_group); if (!json_group) { @@ -3428,8 +3428,9 @@ static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, json_object_int_add(json_source, "wrongIf", c_oil->cc.wrong_if); } else { - vty_out(vty, "%-15s %-15s %-8llu %-7ld %-10ld %-7ld\n", - source_str, group_str, c_oil->cc.lastused / 100, + vty_out(vty, "%-15pPAs %-15pPAs %-8llu %-7ld %-10ld %-7ld\n", + oil_origin(c_oil), oil_mcastgrp(c_oil), + c_oil->cc.lastused / 100, c_oil->cc.pktcnt - c_oil->cc.origpktcnt, c_oil->cc.bytecnt - c_oil->cc.origbytecnt, c_oil->cc.wrong_if - c_oil->cc.origwrong_if); @@ -3437,16 +3438,13 @@ static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, } void show_mroute_count(struct pim_instance *pim, struct vty *vty, - bool uj) + json_object *json) { struct listnode *node; struct channel_oil *c_oil; struct static_route *sr; - json_object *json = NULL; - if (uj) - json = json_object_new_object(); - else { + if (!json) { vty_out(vty, "\n"); vty_out(vty, @@ -3459,11 +3457,9 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty, for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, sr)) show_mroute_count_per_channel_oil(&sr->c_oil, json, vty); - - if (uj) - vty_json(vty, json); } +#if PIM_IPV == 4 void show_mroute_summary(struct pim_instance *pim, struct vty *vty, json_object *json) { diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 0a5760cc30..0d2c0c1efb 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -111,7 +111,7 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, bool fill, json_object *json); void show_mroute_count(struct pim_instance *pim, struct vty *vty, - bool uj); + json_object *json); void show_mroute_summary(struct pim_instance *pim, struct vty *vty, json_object *json);