]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pimd: json support added for command "show ip igmp sources"
authorSai Gomathi <nsaigomathi@vmware.com>
Fri, 5 Nov 2021 11:19:35 +0000 (04:19 -0700)
committerSai Gomathi <nsaigomathi@vmware.com>
Tue, 25 Jan 2022 14:29:37 +0000 (06:29 -0800)
Add JSON support in the show command
“show ip igmp sources” with proper formatting.

Signed-off-by: Sai Gomathi <nsaigomathi@vmware.com>
doc/user/pim.rst
pimd/pim_cmd.c

index 899a6b007874aea3fc9288b59207b8672cc88e4c..432d0bf0a459cfd7fd083521ddabebea4657d432 100644 (file)
@@ -377,7 +377,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.
 
index c0401b83ce3392ba2d92bc50009032da035ebbea..aeb3565ea20e8abbc39d54c3b4ac8114d0bb71ce 100644 (file)
@@ -3555,15 +3555,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) {
@@ -3600,17 +3609,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,
@@ -4259,12 +4321,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);
@@ -4272,7 +4335,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;
 }