diff options
author | rgirada <rgirada@vmware.com> | 2022-06-19 20:04:39 +0200 |
---|---|---|
committer | rgirada <rgirada@vmware.com> | 2022-06-22 17:40:24 +0200 |
commit | e8a8b11610bbc0671a50ca799d378039ae41270f (patch) | |
tree | 4b6e6e8bff0923fcfd7171bd66eb463ed624ba2b /ospfd/ospf_vty.c | |
parent | Merge pull request #11146 from NicolasDichtel/master (diff) | |
download | frr-e8a8b11610bbc0671a50ca799d378039ae41270f.tar.xz frr-e8a8b11610bbc0671a50ca799d378039ae41270f.zip |
ospfd: Fixing "show ip ospf neighbour <nbrid>" command
Description:
"show ip ospf neighbour [nbrid] [json]" is expected to give brief output
of the specific neighbour. But it gives the detailed output without
the detail keyword.
"show ip ospf neighbour [nbrid] [deatil] [json]" command is failed to
fetch the ecpected o/p. Corrected it.
Ex o/p:
frr(config-if)# do show ip ospf neighbor
Neighbor ID Pri State Up Time Dead Time Address Interface RXmtL RqstL DBsmL
8.8.8.8 1 Full/DR 17m03s 31.192s 20.1.1.194 ens192:20.1.1.220 0 0 0
30.1.1.100 1 Full/DR 56.229s 32.000s 30.1.1.100 ens224:30.1.1.220 0 0 0
frr(config-if)#
frr(config-if)#
frr(config-if)# do show ip ospf neighbor 8.8.8.8
Neighbor 8.8.8.8, interface address 20.1.1.194
In the area 0.0.0.0 via interface ens192
Neighbor priority is 1, State is Full/DR, 6 state changes
Most recent state change statistics:
Progressive change 17m18s ago
DR is 20.1.1.194, BDR is 20.1.1.220
Options 2 *|-|-|-|-|-|E|-
Dead timer due in 35.833s
Database Summary List 0
Link State Request List 0
Link State Retransmission List 0
Thread Inactivity Timer on
Thread Database Description Retransmision off
Thread Link State Request Retransmission on
Thread Link State Update Retransmission on
Graceful restart Helper info:
Graceful Restart HELPER Status : None
frr(config-if)# do show ip ospf neighbor 8.8.8.8 detail
No such interface.
frr(config-if)# do show ip ospf neighbor 8.8.8.8 detail json
{}
frr(config-if)#
Signed-off-by: Rajesh Girada <rgirada@vmware.com>
Diffstat (limited to '')
-rw-r--r-- | ospfd/ospf_vty.c | 344 |
1 files changed, 157 insertions, 187 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index ee665cd25..747643465 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -4335,190 +4335,159 @@ static void show_ip_ospf_neighbour_header(struct vty *vty) "Address", "Interface", "RXmtL", "RqstL", "DBsmL"); } -static void show_ip_ospf_neighbor_sub(struct vty *vty, - struct ospf_interface *oi, - json_object *json, bool use_json) +static void show_ip_ospf_neighbour_brief(struct vty *vty, + struct ospf_neighbor *nbr, + struct ospf_neighbor *prev_nbr, + json_object *json, bool use_json) { - struct route_node *rn; - struct ospf_neighbor *nbr, *prev_nbr = NULL; char msgbuf[16]; char timebuf[OSPF_TIME_DUMP_SIZE]; json_object *json_neighbor = NULL, *json_neigh_array = NULL; - struct timeval res = {.tv_sec = 0, .tv_usec = 0}; + struct timeval res; long time_val = 0; char uptime[OSPF_TIME_DUMP_SIZE]; - for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { - if ((nbr = rn->info)) { - /* Do not show myself. */ - if (nbr == oi->nbr_self) - continue; - /* Down state is not shown. */ - if (nbr->state == NSM_Down) - continue; - - if (nbr->ts_last_progress.tv_sec - || nbr->ts_last_progress.tv_usec) - time_val = monotime_since( - &nbr->ts_last_progress, &res) - / 1000LL; + if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) + time_val = + monotime_since(&nbr->ts_last_progress, &res) / 1000LL; - if (use_json) { - char neigh_str[INET_ADDRSTRLEN]; + if (use_json) { + char neigh_str[INET_ADDRSTRLEN]; - if (prev_nbr - && !IPV4_ADDR_SAME(&prev_nbr->src, - &nbr->src)) { - /* Start new neigh list */ - json_neigh_array = NULL; - } + if (prev_nbr && !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { + /* Start new neigh list */ + json_neigh_array = NULL; + } - if (nbr->state == NSM_Attempt - && nbr->router_id.s_addr == INADDR_ANY) - strlcpy(neigh_str, "neighbor", - sizeof(neigh_str)); - else - inet_ntop(AF_INET, &nbr->router_id, - neigh_str, sizeof(neigh_str)); + if (nbr->state == NSM_Attempt && + nbr->router_id.s_addr == INADDR_ANY) + strlcpy(neigh_str, "neighbor", sizeof(neigh_str)); + else + inet_ntop(AF_INET, &nbr->router_id, neigh_str, + sizeof(neigh_str)); - json_object_object_get_ex(json, neigh_str, - &json_neigh_array); + 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); - } + if (!json_neigh_array) { + json_neigh_array = json_object_new_array(); + json_object_object_add(json, neigh_str, + json_neigh_array); + } - json_neighbor = json_object_new_object(); + json_neighbor = json_object_new_object(); - ospf_nbr_ism_state_message(nbr, msgbuf, - sizeof(msgbuf)); + ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf)); #if CONFDATE > 20230321 -CPP_NOTICE("Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter") + CPP_NOTICE( + "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter") #endif - json_object_int_add(json_neighbor, "priority", - nbr->priority); - json_object_string_add(json_neighbor, "state", - msgbuf); - json_object_int_add(json_neighbor, - "nbrPriority", - nbr->priority); - json_object_string_add(json_neighbor, - "nbrState", msgbuf); + json_object_int_add(json_neighbor, "priority", nbr->priority); + json_object_string_add(json_neighbor, "state", msgbuf); + json_object_int_add(json_neighbor, "nbrPriority", + nbr->priority); + json_object_string_add(json_neighbor, "nbrState", msgbuf); - json_object_string_add( - json_neighbor, "converged", - lookup_msg(ospf_nsm_state_msg, - nbr->state, NULL)); - json_object_string_add( - json_neighbor, "role", - lookup_msg(ospf_ism_state_msg, - ospf_nbr_ism_state(nbr), - NULL)); - - if (nbr->t_inactivity) { - long time_store; - - time_store = monotime_until( - &nbr->t_inactivity - ->u.sands, - NULL) - / 1000LL; - json_object_int_add(json_neighbor, - "upTimeInMsec", - time_val); - json_object_int_add(json_neighbor, - "deadTimeMsecs", - time_store); - json_object_int_add( - json_neighbor, - "routerDeadIntervalTimerDueMsec", - time_store); - json_object_string_add( - json_neighbor, "upTime", - ospf_timeval_dump( - &res, uptime, - sizeof(uptime))); - json_object_string_add( - json_neighbor, "deadTime", - ospf_timer_dump( - nbr->t_inactivity, - timebuf, - sizeof(timebuf))); - } else { - json_object_string_add(json_neighbor, - "deadTimeMsecs", - "inactive"); - json_object_string_add( - json_neighbor, - "routerDeadIntervalTimerDueMsec", - "inactive"); - } - json_object_string_addf(json_neighbor, - "address", "%pI4", - &nbr->src); - json_object_string_addf(json_neighbor, - "ifaceAddress", "%pI4", - &nbr->src); - json_object_string_add(json_neighbor, - "ifaceName", - IF_NAME(oi)); - json_object_int_add( - json_neighbor, "retransmitCounter", - ospf_ls_retransmit_count(nbr)); - json_object_int_add( - json_neighbor, - "linkStateRetransmissionListCounter", - ospf_ls_retransmit_count(nbr)); - json_object_int_add(json_neighbor, - "requestCounter", - ospf_ls_request_count(nbr)); - json_object_int_add( - json_neighbor, - "linkStateRequestListCounter", - ospf_ls_request_count(nbr)); - json_object_int_add(json_neighbor, - "dbSummaryCounter", - ospf_db_summary_count(nbr)); - json_object_int_add( - json_neighbor, - "databaseSummaryListCounter", - ospf_db_summary_count(nbr)); + json_object_string_add( + json_neighbor, "converged", + lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); + json_object_string_add(json_neighbor, "role", + lookup_msg(ospf_ism_state_msg, + ospf_nbr_ism_state(nbr), + NULL)); + if (nbr->t_inactivity) { + long time_store; - json_object_array_add(json_neigh_array, - json_neighbor); - } else { - ospf_nbr_ism_state_message(nbr, msgbuf, - sizeof(msgbuf)); + time_store = monotime_until(&nbr->t_inactivity->u.sands, + NULL) / + 1000LL; + json_object_int_add(json_neighbor, "upTimeInMsec", + time_val); + json_object_int_add(json_neighbor, "deadTimeMsecs", + time_store); + json_object_int_add(json_neighbor, + "routerDeadIntervalTimerDueMsec", + time_store); + json_object_string_add( + json_neighbor, "upTime", + ospf_timeval_dump(&res, uptime, + sizeof(uptime))); + json_object_string_add( + json_neighbor, "deadTime", + ospf_timer_dump(nbr->t_inactivity, timebuf, + sizeof(timebuf))); + } else { + json_object_string_add(json_neighbor, "deadTimeMsecs", + "inactive"); + json_object_string_add(json_neighbor, + "routerDeadIntervalTimerDueMsec", + "inactive"); + } + json_object_string_addf(json_neighbor, "address", "%pI4", + &nbr->src); + json_object_string_addf(json_neighbor, "ifaceAddress", "%pI4", + &nbr->src); + json_object_string_add(json_neighbor, "ifaceName", + IF_NAME(nbr->oi)); + json_object_int_add(json_neighbor, "retransmitCounter", + ospf_ls_retransmit_count(nbr)); + json_object_int_add(json_neighbor, + "linkStateRetransmissionListCounter", + ospf_ls_retransmit_count(nbr)); + json_object_int_add(json_neighbor, "requestCounter", + ospf_ls_request_count(nbr)); + json_object_int_add(json_neighbor, + "linkStateRequestListCounter", + ospf_ls_request_count(nbr)); + json_object_int_add(json_neighbor, "dbSummaryCounter", + ospf_db_summary_count(nbr)); + json_object_int_add(json_neighbor, "databaseSummaryListCounter", + ospf_db_summary_count(nbr)); - if (nbr->state == NSM_Attempt - && nbr->router_id.s_addr == INADDR_ANY) - vty_out(vty, "%-15s %3d %-15s ", "-", - nbr->priority, msgbuf); - else - vty_out(vty, "%-15pI4 %3d %-15s ", - &nbr->router_id, nbr->priority, - msgbuf); + json_object_array_add(json_neigh_array, json_neighbor); + } else { + ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf)); - vty_out(vty, "%-15s ", - ospf_timeval_dump(&res, uptime, - sizeof(uptime))); + if (nbr->state == NSM_Attempt && + nbr->router_id.s_addr == INADDR_ANY) + vty_out(vty, "%-15s %3d %-15s ", "-", nbr->priority, + msgbuf); + else + vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id, + nbr->priority, msgbuf); + + vty_out(vty, "%-15s ", + ospf_timeval_dump(&res, uptime, sizeof(uptime))); + + vty_out(vty, "%9s ", + ospf_timer_dump(nbr->t_inactivity, timebuf, + sizeof(timebuf))); + vty_out(vty, "%-15pI4 ", &nbr->src); + vty_out(vty, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr->oi), + ospf_ls_retransmit_count(nbr), + ospf_ls_request_count(nbr), ospf_db_summary_count(nbr)); + } +} + +static void show_ip_ospf_neighbor_sub(struct vty *vty, + struct ospf_interface *oi, + json_object *json, bool use_json) +{ + struct route_node *rn; + struct ospf_neighbor *nbr, *prev_nbr = NULL; + + for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { + if ((nbr = rn->info)) { + /* Do not show myself. */ + if (nbr == oi->nbr_self) + continue; + /* Down state is not shown. */ + if (nbr->state == NSM_Down) + continue; - vty_out(vty, "%9s ", - ospf_timer_dump(nbr->t_inactivity, - timebuf, - sizeof(timebuf))); - vty_out(vty, "%-15pI4 ", &nbr->src); - vty_out(vty, "%-32s %5ld %5ld %5d\n", - IF_NAME(oi), - ospf_ls_retransmit_count(nbr), - ospf_ls_request_count(nbr), - ospf_db_summary_count(nbr)); - } prev_nbr = nbr; + + show_ip_ospf_neighbour_brief(vty, nbr, prev_nbr, json, + use_json); } } } @@ -5411,7 +5380,8 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, struct in_addr *router_id, - bool use_json, uint8_t use_vrf) + bool use_json, uint8_t use_vrf, + bool is_detail) { struct listnode *node; struct ospf_neighbor *nbr; @@ -5433,8 +5403,12 @@ 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, NULL, - json, use_json); + if (is_detail) + show_ip_ospf_neighbor_detail_sub( + vty, oi, nbr, NULL, json, use_json); + else + show_ip_ospf_neighbour_brief(vty, nbr, NULL, + json, use_json); } } @@ -5446,15 +5420,13 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, return CMD_SUCCESS; } -DEFPY (show_ip_ospf_neighbor_id, - show_ip_ospf_neighbor_id_cmd, - "show ip ospf neighbor A.B.C.D$router_id [json$json]", - SHOW_STR - IP_STR - "OSPF information\n" - "Neighbor list\n" - "Neighbor ID\n" - JSON_STR) +DEFPY(show_ip_ospf_neighbor_id, show_ip_ospf_neighbor_id_cmd, + "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]", + SHOW_STR IP_STR + "OSPF information\n" + "Neighbor list\n" + "Neighbor ID\n" + "Detailed output\n" JSON_STR) { struct ospf *ospf; struct listnode *node; @@ -5464,22 +5436,20 @@ DEFPY (show_ip_ospf_neighbor_id, if (!ospf->oi_running) continue; ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, - !!json, 0); + !!json, 0, !!detail); } return ret; } -DEFPY (show_ip_ospf_instance_neighbor_id, - show_ip_ospf_instance_neighbor_id_cmd, - "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", - SHOW_STR - IP_STR - "OSPF information\n" - "Instance ID\n" - "Neighbor list\n" - "Neighbor ID\n" - JSON_STR) +DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd, + "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]", + SHOW_STR IP_STR + "OSPF information\n" + "Instance ID\n" + "Neighbor list\n" + "Neighbor ID\n" + "Detailed output\n" JSON_STR) { struct ospf *ospf; @@ -5490,8 +5460,8 @@ DEFPY (show_ip_ospf_instance_neighbor_id, if (!ospf || !ospf->oi_running) return CMD_SUCCESS; - return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, - 0); + return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0, + !!detail); } static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |