]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: show ip ospf interface json output format
authorChirag Shah <chirag@cumulusnetworks.com>
Sat, 30 Dec 2017 05:01:07 +0000 (21:01 -0800)
committerChirag Shah <chirag@cumulusnetworks.com>
Tue, 16 Jan 2018 20:49:31 +0000 (12:49 -0800)
Current json output does not differentiate start of
interface objects. Adding "interfaces" keyword at the
beginning of the interface list. This is useful
when displaying vrf level output along with interface list.

Ticket:CM-19115
Testing Done:
show ip ospf vrf all interface json
show ip ospf vrf all interface <specific intf> json
show ip ospf interface json
show ip ospf interface <specific intf> json

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
ospfd/ospf_vty.c

index a1384eebddb1dcafc7cd47a02b9a3e763aef08d9..80758212c4534ce688fc3883bc65a260f4666a79 100644 (file)
@@ -3693,14 +3693,15 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
 {
        struct interface *ifp;
        struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
-       json_object *json_vrf = NULL;
-       json_object *json_interface_sub = NULL;
+       json_object *json_vrf = NULL, *json_intf_array = NULL;
+       json_object *json_interface_sub = NULL, *json_interface = NULL;
 
        if (use_json) {
                if (use_vrf)
                        json_vrf = json_object_new_object();
                else
                        json_vrf = json;
+               json_intf_array = json_object_new_array();
        }
 
        if (ospf->instance) {
@@ -3714,21 +3715,29 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
        ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
 
        if (intf_name == NULL) {
+               if (use_json)
+                       json_object_object_add(json_vrf, "interfaces",
+                                      json_intf_array);
                /* Show All Interfaces.*/
                FOR_ALL_INTERFACES (vrf, ifp) {
                        if (ospf_oi_count(ifp)) {
-                               if (use_json)
+                               if (use_json) {
+                                       json_interface =
+                                               json_object_new_object();
                                        json_interface_sub =
                                                json_object_new_object();
-
+                               }
                                show_ip_ospf_interface_sub(vty, ospf, ifp,
                                                           json_interface_sub,
                                                           use_json);
 
-                               if (use_json)
+                               if (use_json) {
+                                       json_object_array_add(json_intf_array,
+                                                             json_interface);
                                        json_object_object_add(
-                                               json_vrf, ifp->name,
+                                               json_interface, ifp->name,
                                                json_interface_sub);
+                               }
                        }
                }
        } else {
@@ -3741,15 +3750,23 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
                        else
                                vty_out(vty, "No such interface name\n");
                } else {
-                       if (use_json)
+                       if (use_json) {
                                json_interface_sub = json_object_new_object();
+                               json_interface = json_object_new_object();
+                               json_object_object_add(json_vrf, "interfaces",
+                                                      json_intf_array);
+                       }
 
                        show_ip_ospf_interface_sub(
                                vty, ospf, ifp, json_interface_sub, use_json);
 
-                       if (use_json)
-                               json_object_object_add(json_vrf, ifp->name,
+                       if (use_json) {
+                               json_object_array_add(json_intf_array,
+                                                     json_interface);
+                               json_object_object_add(json_interface,
+                                                      ifp->name,
                                                       json_interface_sub);
+                       }
                }
        }