diff options
Diffstat (limited to 'pimd/pim_cmd.c')
| -rw-r--r-- | pimd/pim_cmd.c | 63 |
1 files changed, 41 insertions, 22 deletions
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; + + 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); - show_mroute_count(vrf->info, vty, uj); 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; } |
