From 7dab10ce944919ba4588063ce3b5adc84fc78842 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Fri, 29 Dec 2017 21:01:07 -0800 Subject: [PATCH] ospfd: show ip ospf interface json output format 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 json show ip ospf interface json show ip ospf interface json Signed-off-by: Chirag Shah --- ospfd/ospf_vty.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index a1384eebdd..80758212c4 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -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); + } } } -- 2.39.5