diff options
author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2022-02-11 06:53:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-11 06:53:02 +0100 |
commit | f7d86983137ab0d6809c3df111e0064083edd0a1 (patch) | |
tree | 4e1bef772523b04bb8dc9dec24c5009ddcbeed99 | |
parent | Merge pull request #8890 from rameshabhinay/ospf6_auth_trailer (diff) | |
parent | pimd: json support added for command "show ip igmp sources" (diff) | |
download | frr-f7d86983137ab0d6809c3df111e0064083edd0a1.tar.xz frr-f7d86983137ab0d6809c3df111e0064083edd0a1.zip |
Merge pull request #9697 from SaiGomathiN/igmp-sources
pimd: json support added
-rw-r--r-- | doc/user/pim.rst | 2 | ||||
-rw-r--r-- | pimd/pim_cmd.c | 89 |
2 files changed, 77 insertions, 14 deletions
diff --git a/doc/user/pim.rst b/doc/user/pim.rst index 306feec0f..5a009eda6 100644 --- a/doc/user/pim.rst +++ b/doc/user/pim.rst @@ -393,7 +393,7 @@ cause great confusion. Display IGMP group retransmission information. -.. clicmd:: show ip igmp sources +.. clicmd:: show ip igmp [vrf NAME] sources [json] Display IGMP sources information. diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 2baaca1c9..61d4f22e9 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3488,15 +3488,24 @@ static void igmp_show_group_retransmission(struct pim_instance *pim, } /* scan interfaces */ } -static void igmp_show_sources(struct pim_instance *pim, struct vty *vty) +static void igmp_show_sources(struct pim_instance *pim, struct vty *vty, + bool uj) { struct interface *ifp; time_t now; + json_object *json = NULL; + json_object *json_iface = NULL; + json_object *json_group = NULL; + json_object *json_source = NULL; + json_object *json_sources = NULL; now = pim_time_monotonic_sec(); - vty_out(vty, - "Interface Group Source Timer Fwd Uptime \n"); + if (uj) + json = json_object_new_object(); + else + vty_out(vty, + "Interface Address Group Source Timer Fwd Uptime \n"); /* scan interfaces */ FOR_ALL_INTERFACES (pim->vrf, ifp) { @@ -3533,17 +3542,70 @@ static void igmp_show_sources(struct pim_instance *pim, struct vty *vty) pim_time_uptime(uptime, sizeof(uptime), now - src->source_creation); - vty_out(vty, "%-16s %-15s %-15s %5s %3s %8s\n", - ifp->name, group_str, source_str, mmss, - IGMP_SOURCE_TEST_FORWARDING( - src->source_flags) - ? "Y" - : "N", - uptime); + if (uj) { + json_object_object_get_ex( + json, ifp->name, &json_iface); + if (!json_iface) { + json_iface = + json_object_new_object(); + json_object_string_add( + json_iface, "name", + ifp->name); + json_object_object_add( + json, ifp->name, + json_iface); + } + json_object_object_get_ex(json_iface, + group_str, + &json_group); + + if (!json_group) { + json_group = + json_object_new_object(); + json_object_string_add( + json_group, "group", + group_str); + json_object_object_add( + json_iface, group_str, + json_group); + json_sources = + json_object_new_array(); + json_object_object_add( + json_group, "sources", + json_sources); + } + json_source = json_object_new_object(); + json_object_string_add(json_source, + "source", + source_str); + json_object_string_add(json_source, + "timer", mmss); + json_object_boolean_add( + json_source, "forwarded", + IGMP_SOURCE_TEST_FORWARDING( + src->source_flags)); + json_object_string_add( + json_source, "uptime", uptime); + json_object_array_add(json_sources, + json_source); + + } else { + vty_out(vty, + "%-16s %-15s %-15s %5s %3s %8s\n", + ifp->name, group_str, + source_str, mmss, + IGMP_SOURCE_TEST_FORWARDING( + src->source_flags) + ? "Y" + : "N", + uptime); + } } /* scan group sources */ } /* scan igmp groups */ } /* scan interfaces */ + if (uj) + vty_json(vty, json); } static void igmp_show_source_retransmission(struct pim_instance *pim, @@ -4189,12 +4251,13 @@ DEFUN (show_ip_igmp_groups_retransmissions, DEFUN (show_ip_igmp_sources, show_ip_igmp_sources_cmd, - "show ip igmp [vrf NAME] sources", + "show ip igmp [vrf NAME] sources [json]", SHOW_STR IP_STR IGMP_STR VRF_CMD_HELP_STR - IGMP_SOURCE_STR) + IGMP_SOURCE_STR + JSON_STR) { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); @@ -4202,7 +4265,7 @@ DEFUN (show_ip_igmp_sources, if (!vrf) return CMD_WARNING; - igmp_show_sources(vrf->info, vty); + igmp_show_sources(vrf->info, vty, use_json(argc, argv)); return CMD_SUCCESS; } |