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>
This commit is contained in:
Chirag Shah 2018-01-19 18:17:53 -08:00
parent 4ff9eb721d
commit 2bc7673f11
3 changed files with 38 additions and 5 deletions

View 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_add, (struct ospf_vl_data * vd), (vd))
DEFINE_HOOK(ospf_vl_delete, (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) int ospf_if_get_output_cost(struct ospf_interface *oi)
{ {
/* If all else fails, use default OSPF cost */ /* If all else fails, use default OSPF cost */

View 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 struct crypt_key *ospf_crypt_key_new(void);
extern void ospf_crypt_key_add(struct list *, struct crypt_key *); extern void ospf_crypt_key_add(struct list *, struct crypt_key *);
extern int ospf_crypt_key_delete(struct list *, u_char); extern int ospf_crypt_key_delete(struct list *, u_char);
extern u_char ospf_default_iftype(struct interface *ifp); 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 /* Set all multicast memberships appropriately based on the type and
state of the interface. */ state of the interface. */

View File

@ -4300,13 +4300,15 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
{ {
struct ospf_interface *oi; struct ospf_interface *oi;
struct listnode *node; 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_json) {
if (use_vrf) if (use_vrf)
json_vrf = json_object_new_object(); json_vrf = json_object_new_object();
else else
json_vrf = json; json_vrf = json;
json_nbr_array = json_object_new_array();
} }
if (ospf->instance) { 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); ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
if (!use_json) if (!use_json)
show_ip_ospf_neighbour_header(vty); 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)) for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); 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_json) {
if (use_vrf) { 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); 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); ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
if (!ifp) { if (!ifp) {
if (use_json) if (use_json)