]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: show ip ospf neighbor json output format
authorChirag Shah <chirag@cumulusnetworks.com>
Sat, 20 Jan 2018 02:17:53 +0000 (18:17 -0800)
committerChirag Shah <chirag@cumulusnetworks.com>
Sun, 21 Jan 2018 03:30:59 +0000 (19:30 -0800)
Current json output does not differentiate start of
neighbor ip object. Adding "neighbors" keyword at the
beginning of neighbor list. This is useful when
displaying vrf level output along with neighbors
list.

Ticket:CM-19097
Testing Done:
show ip ospf neighbor json
show ip ospf vrf all neighbor json

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

index e8700e7eb062611385170dd92bd40582912a52d2..c8f758525ed07a66378d4bb3141a4bd6c54f7996 100644 (file)
@@ -51,6 +51,28 @@ DEFINE_QOBJ_TYPE(ospf_interface)
 DEFINE_HOOK(ospf_vl_add, (struct ospf_vl_data * vd), (vd))
 DEFINE_HOOK(ospf_vl_delete, (struct ospf_vl_data * vd), (vd))
 
+int ospf_interface_neighbor_count(struct ospf_interface *oi)
+{
+       int count = 0;
+       struct route_node *rn;
+       struct ospf_neighbor *nbr = NULL;
+
+       for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
+               nbr = rn->info;
+               if (nbr) {
+                       /* Do not show myself. */
+                       if (nbr == oi->nbr_self)
+                               continue;
+                       /* Down state is not shown. */
+                       if (nbr->state == NSM_Down)
+                               continue;
+                       count++;
+               }
+       }
+
+       return count;
+}
+
 int ospf_if_get_output_cost(struct ospf_interface *oi)
 {
        /* If all else fails, use default OSPF cost */
index 829a3f4297985f172b5c14448a7742c23df50f83..ab02444f7d82228f5e694af46391929e7986a3c1 100644 (file)
@@ -314,8 +314,8 @@ extern struct crypt_key *ospf_crypt_key_lookup(struct list *, u_char);
 extern struct crypt_key *ospf_crypt_key_new(void);
 extern void ospf_crypt_key_add(struct list *, struct crypt_key *);
 extern int ospf_crypt_key_delete(struct list *, u_char);
-
 extern u_char ospf_default_iftype(struct interface *ifp);
+extern int ospf_interface_neighbor_count(struct ospf_interface *oi);
 
 /* Set all multicast memberships appropriately based on the type and
    state of the interface. */
index e2aa445572c51dc4436d3f3a6c7db9df0f217d9a..6681473153f3fd06a05763f711de76e6d0fd0b8c 100644 (file)
@@ -4300,13 +4300,15 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
 {
        struct ospf_interface *oi;
        struct listnode *node;
-       json_object *json_vrf = NULL;
+       json_object *json_vrf = NULL, *json_nbr_array = NULL;
+       json_object *json_nbr_sub = NULL;
 
        if (use_json) {
                if (use_vrf)
                        json_vrf = json_object_new_object();
                else
                        json_vrf = json;
+               json_nbr_array = json_object_new_array();
        }
 
        if (ospf->instance) {
@@ -4320,9 +4322,19 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
        ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
        if (!use_json)
                show_ip_ospf_neighbour_header(vty);
+       else
+               json_object_object_add(json_vrf, "neighbors",
+                                      json_nbr_array);
 
-       for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
-               show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
+       for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
+               if (ospf_interface_neighbor_count(oi) == 0)
+                       continue;
+               if (use_json) {
+                       json_nbr_sub = json_object_new_object();
+                       json_object_array_add(json_nbr_array, json_nbr_sub);
+               }
+               show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
+       }
 
        if (use_json) {
                if (use_vrf) {
@@ -4698,7 +4710,6 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
 
        ospf_show_vrf_name(ospf, vty, json, use_vrf);
 
-       /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/
        ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
        if (!ifp) {
                if (use_json)