ospfd: Option to query specific neighbor in VRF

Added VRF option to
"show ip ospf [vrf NAME] neighbor X.X.X.X [detail] [json]"
command so that the user can query information regarding a
specific neighbor within a VRF.

r1# show ip ospf vrf default neighbor 10.0.255.2
10.0.255.2        1 Full/-          33m10s             9.891s 10.0.3.2        r1-eth1:10.0.3.4                     0     0     0

r1# show ip ospf vrf default neighbor 10.0.255.2 json
    {
      "10.0.255.2":[
        {
          "priority":1,
          "state":"Full/-",
          "nbrPriority":1,
          "nbrState":"Full/-",
          "converged":"Full",
          "role":"DROther",
          "upTimeInMsec":13877947,
          "deadTimeMsecs":9498,
          "routerDeadIntervalTimerDueMsec":9498,
          "upTime":"3h51m17s",
          "deadTime":"9.498s",
          "address":"10.0.3.2",
          "ifaceAddress":"10.0.3.2",
          "ifaceName":"r1-eth1:10.0.3.4",
          "retransmitCounter":0,
          "linkStateRetransmissionListCounter":0,
          "requestCounter":0,
          "linkStateRequestListCounter":0,
          "dbSummaryCounter":0,
          "databaseSummaryListCounter":0
        }
      ]
    }
r1# show ip ospf vrf default neighbor 10.0.255.2 detail
     Neighbor 10.0.255.2, interface address 10.0.3.2
        In the area 0.0.0.0 via interface r1-eth1 local interface IP 10.0.3.4
        Neighbor priority is 1, State is Full/-, Role is DROther, 5 state changes
        Most recent state change statistics:
          Progressive change 3h51m27s ago
        DR is 0.0.0.0, BDR is 0.0.0.0
        Options 2 *|-|-|-|-|-|E|-
        Dead timer due in 8.458s
        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

r1# show ip ospf vrf default neighbor 10.0.255.2 detail json
    {
      "10.0.255.2":[
        {
          "ifaceAddress":"10.0.3.2",
          "areaId":"0.0.0.0",
          "ifaceName":"r1-eth1",
          "localIfaceAddress":"10.0.3.4",
          "nbrPriority":1,
          "nbrState":"Full/-",
          "role":"DROther",
          "stateChangeCounter":5,
          "lastPrgrsvChangeMsec":13889856,
          "routerDesignatedId":"0.0.0.0",
          "routerDesignatedBackupId":"0.0.0.0",
          "optionsCounter":2,
          "optionsList":"*|-|-|-|-|-|E|-",
          "routerDeadIntervalTimerDueMsec":9715,
          "databaseSummaryListCounter":0,
          "linkStateRequestListCounter":0,
          "linkStateRetransmissionListCounter":0,
          "threadInactivityTimer":"on",
          "threadLinkStateRequestRetransmission":"on",
          "threadLinkStateUpdateRetransmission":"on",
          "grHelperStatus":"None"
        }
      ]
    }
r1#

Signed-off-by: Pooja Jagadeesh Doijode <pdoijode@nvidia.com>
This commit is contained in:
Pooja Jagadeesh Doijode 2023-02-07 15:29:31 -08:00
parent 6333c54822
commit a8e6c2c6d0

View File

@ -5401,7 +5401,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 is_detail)
bool is_detail,
json_object *json_vrf)
{
struct listnode *node;
struct ospf_neighbor *nbr;
@ -5435,6 +5436,14 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
use_json);
}
if (json_vrf && use_json) {
json_object_object_add(
json_vrf,
(ospf->vrf_id == VRF_DEFAULT) ? "default" : ospf->name,
json);
return CMD_SUCCESS;
}
if (use_json)
vty_json(vty, json);
else
@ -5443,23 +5452,51 @@ 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 [detail$detail] [json$json]",
SHOW_STR IP_STR
DEFPY(show_ip_ospf_neighbor_id,
show_ip_ospf_neighbor_id_cmd,
"show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
SHOW_STR
IP_STR
"OSPF information\n"
VRF_CMD_HELP_STR
"Neighbor list\n"
"Neighbor ID\n"
"Detailed output\n" JSON_STR)
"Detailed output\n"
JSON_STR)
{
struct ospf *ospf;
struct listnode *node;
int ret = CMD_SUCCESS;
int inst = 0;
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id,
!!json, 0, !!detail);
if (vrf_name && !strmatch(vrf_name, "all")) {
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
if (!json)
vty_out(vty,
"%% OSPF is not enabled in vrf %s\n",
vrf_name);
else
vty_json_empty(vty);
return CMD_SUCCESS;
}
ret = show_ip_ospf_neighbor_id_common(
vty, ospf, &router_id, !!json, 0, !!detail, NULL);
} else {
json_object *json_vrf = NULL;
if (json)
json_vrf = json_object_new_object();
for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
if (!ospf->oi_running)
continue;
ret = show_ip_ospf_neighbor_id_common(
vty, ospf, &router_id, !!json, 0, !!detail,
json_vrf);
}
if (json)
vty_json(vty, json_vrf);
}
return ret;
@ -5484,7 +5521,7 @@ DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd,
return CMD_SUCCESS;
return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0,
!!detail);
!!detail, NULL);
}
static int show_ip_ospf_neighbor_detail_common(struct vty *vty,