static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
struct ospf_interface *oi,
struct ospf_neighbor *nbr,
+ struct ospf_neighbor *prev_nbr,
json_object *json, bool use_json)
{
char timebuf[OSPF_TIME_DUMP_SIZE];
- json_object *json_sub = NULL;
+ json_object *json_neigh = NULL, *json_neigh_array = NULL;
+ char neigh_str[INET_ADDRSTRLEN] = {0};
- if (use_json)
- json_sub = json_object_new_object();
- else {
+ if (use_json) {
+ if (prev_nbr &&
+ !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
+ json_neigh_array = NULL;
+ }
+
+ if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
+ strlcpy(neigh_str, "noNbrId", sizeof(neigh_str));
+ else
+ strlcpy(neigh_str, inet_ntoa(nbr->router_id),
+ sizeof(neigh_str));
+
+ json_object_object_get_ex(json, neigh_str, &json_neigh_array);
+
+ if (!json_neigh_array) {
+ json_neigh_array = json_object_new_array();
+ json_object_object_add(json, neigh_str,
+ json_neigh_array);
+ }
+
+ json_neigh = json_object_new_object();
+
+ } else {
/* Show neighbor ID. */
if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
vty_out(vty, " Neighbor %s,", "-");
/* Show interface address. */
if (use_json)
- json_object_string_add(json_sub, "ifaceAddress",
+ json_object_string_add(json_neigh, "ifaceAddress",
inet_ntoa(nbr->address.u.prefix4));
else
vty_out(vty, " interface address %s\n",
/* Show Area ID. */
if (use_json) {
- json_object_string_add(json_sub, "areaId",
+ json_object_string_add(json_neigh, "areaId",
ospf_area_desc_string(oi->area));
- json_object_string_add(json_sub, "ifaceName", oi->ifp->name);
+ json_object_string_add(json_neigh, "ifaceName", oi->ifp->name);
} else
vty_out(vty, " In the area %s via interface %s\n",
ospf_area_desc_string(oi->area), oi->ifp->name);
/* Show neighbor priority and state. */
if (use_json) {
- json_object_int_add(json_sub, "nbrPriority", nbr->priority);
+ json_object_int_add(json_neigh, "nbrPriority", nbr->priority);
json_object_string_add(
- json_sub, "nbrState",
+ json_neigh, "nbrState",
lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
} else
vty_out(vty, " Neighbor priority is %d, State is %s,",
/* Show state changes. */
if (use_json)
- json_object_int_add(json_sub, "stateChangeCounter",
+ json_object_int_add(json_neigh, "stateChangeCounter",
nbr->state_change);
else
vty_out(vty, " %d state changes\n", nbr->state_change);
time_store =
monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
if (use_json) {
- json_object_int_add(json_sub, "lastPrgrsvChangeMsec",
+ json_object_int_add(json_neigh, "lastPrgrsvChangeMsec",
time_store);
} else {
vty_out(vty,
time_store =
monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
if (use_json) {
- json_object_int_add(json_sub,
+ json_object_int_add(json_neigh,
"lastRegressiveChangeMsec",
time_store);
if (nbr->last_regress_str)
json_object_string_add(
- json_sub, "lastRegressiveChangeReason",
+ json_neigh,
+ "lastRegressiveChangeReason",
nbr->last_regress_str);
} else {
vty_out(vty,
/* Show Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_sub, "routerDesignatedId",
+ json_object_string_add(json_neigh, "routerDesignatedId",
inet_ntoa(nbr->d_router));
else
vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router));
/* Show Backup Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_sub, "routerDesignatedBackupId",
+ json_object_string_add(json_neigh, "routerDesignatedBackupId",
inet_ntoa(nbr->bd_router));
else
vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router));
/* Show options. */
if (use_json) {
- json_object_int_add(json_sub, "optionsCounter", nbr->options);
- json_object_string_add(json_sub, "optionsList",
+ json_object_int_add(json_neigh, "optionsCounter", nbr->options);
+ json_object_string_add(json_neigh, "optionsList",
ospf_options_dump(nbr->options));
} else
vty_out(vty, " Options %d %s\n", nbr->options,
time_store = monotime_until(&nbr->t_inactivity->u.sands,
NULL)
/ 1000LL;
- json_object_int_add(json_sub,
+ json_object_int_add(json_neigh,
"routerDeadIntervalTimerDueMsec",
time_store);
} else
json_object_int_add(
- json_sub, "routerDeadIntervalTimerDueMsec", -1);
+ json_neigh,
+ "routerDeadIntervalTimerDueMsec", -1);
} else
vty_out(vty, " Dead timer due in %s\n",
ospf_timer_dump(nbr->t_inactivity, timebuf,
/* Show Database Summary list. */
if (use_json)
- json_object_int_add(json_sub, "databaseSummaryListCounter",
+ json_object_int_add(json_neigh, "databaseSummaryListCounter",
ospf_db_summary_count(nbr));
else
vty_out(vty, " Database Summary List %d\n",
/* Show Link State Request list. */
if (use_json)
- json_object_int_add(json_sub, "linkStateRequestListCounter",
+ json_object_int_add(json_neigh, "linkStateRequestListCounter",
ospf_ls_request_count(nbr));
else
vty_out(vty, " Link State Request List %ld\n",
/* Show Link State Retransmission list. */
if (use_json)
- json_object_int_add(json_sub,
+ json_object_int_add(json_neigh,
"linkStateRetransmissionListCounter",
ospf_ls_retransmit_count(nbr));
else
/* Show inactivity timer thread. */
if (use_json) {
if (nbr->t_inactivity != NULL)
- json_object_string_add(json_sub,
+ json_object_string_add(json_neigh,
"threadInactivityTimer", "on");
} else
vty_out(vty, " Thread Inactivity Timer %s\n",
if (use_json) {
if (nbr->t_db_desc != NULL)
json_object_string_add(
- json_sub,
+ json_neigh,
"threadDatabaseDescriptionRetransmission",
"on");
} else
if (use_json) {
if (nbr->t_ls_req != NULL)
json_object_string_add(
- json_sub,
+ json_neigh,
"threadLinkStateRequestRetransmission", "on");
} else
vty_out(vty,
if (use_json) {
if (nbr->t_ls_upd != NULL)
json_object_string_add(
- json_sub, "threadLinkStateUpdateRetransmission",
+ json_neigh,
+ "threadLinkStateUpdateRetransmission",
"on");
} else
vty_out(vty,
" Thread Link State Update Retransmission %s\n\n",
nbr->t_ls_upd != NULL ? "on" : "off");
- if (use_json) {
- if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
- json_object_object_add(json, "noNbrId", json_sub);
- else
- json_object_object_add(json, inet_ntoa(nbr->router_id),
- json_sub);
- }
+ ospf_bfd_show_info(vty, nbr->bfd_info, json_neigh, use_json, 0);
+
+ if (use_json)
+ json_object_array_add(json_neigh_array, json_neigh);
- ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0);
}
static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) {
- show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json,
- use_json);
+ show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
+ json, use_json);
}
}
struct ospf_interface *oi;
struct listnode *node;
json_object *json_vrf = 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_sub = json_object_new_object();
}
+
if (ospf->instance) {
if (use_json)
- json_object_int_add(json_vrf, "ospfInstance",
+ json_object_int_add(json, "ospfInstance",
ospf->instance);
else
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
struct route_node *rn;
- struct ospf_neighbor *nbr;
+ struct ospf_neighbor *nbr, *prev_nbr = NULL;
for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
if ((nbr = rn->info)) {
if (nbr != oi->nbr_self) {
if (nbr->state != NSM_Down) {
show_ip_ospf_neighbor_detail_sub(
- vty, oi, nbr, json_vrf,
- use_json);
+ vty, oi, nbr, prev_nbr,
+ json_nbr_sub, use_json);
}
}
+ prev_nbr = nbr;
}
}
}
if (use_json) {
+ json_object_object_add(json_vrf, "neighbors",
+ json_nbr_sub);
if (use_vrf) {
if (ospf->vrf_id == VRF_DEFAULT)
json_object_object_add(json, "default",
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
struct route_node *rn;
- struct ospf_neighbor *nbr;
+ struct ospf_neighbor *nbr, *prev_nbr = NULL;
struct ospf_nbr_nbma *nbr_nbma;
- for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
- if ((nbr = rn->info))
+ for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
+ if ((nbr = rn->info)) {
if (nbr != oi->nbr_self)
if (nbr->state != NSM_Down)
show_ip_ospf_neighbor_detail_sub(
vty, oi, rn->info,
+ prev_nbr,
json_vrf, use_json);
+ prev_nbr = nbr;
+ }
+ }
if (oi->type == OSPF_IFTYPE_NBMA) {
struct listnode *nd;
if (nbr->state != NSM_Down)
show_ip_ospf_neighbor_detail_sub(
vty, oi, nbr,
+ NULL,
json, use_json);
}
}
if (!ospf->oi_running)
continue;
ospf_output = true;
- ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
+ ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4,
argv, uj);
}