summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChirag Shah <chirag@cumulusnetworks.com>2018-01-19 18:17:53 -0800
committerChirag Shah <chirag@cumulusnetworks.com>2018-01-20 19:30:59 -0800
commit2bc7673f110a92c7a20f170daf9b34d8c8190f8a (patch)
tree7464fddff1091feaece4468d6507536b60a5ade6
parent4ff9eb721d5b089a86070f03282c3d0843194504 (diff)
ospfd: show ip ospf neighbor json output format
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>
-rw-r--r--ospfd/ospf_interface.c22
-rw-r--r--ospfd/ospf_interface.h2
-rw-r--r--ospfd/ospf_vty.c19
3 files changed, 38 insertions, 5 deletions
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index e8700e7eb0..c8f758525e 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -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 */
diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h
index 829a3f4297..ab02444f7d 100644
--- a/ospfd/ospf_interface.h
+++ b/ospfd/ospf_interface.h
@@ -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. */
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index e2aa445572..6681473153 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -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)