Skip to content

Commit

Permalink
Merge pull request FRRouting#12380 from chiragshah6/zdev
Browse files Browse the repository at this point in the history
ospfd: json support for show ip ospf border-routers
  • Loading branch information
ton31337 authored Dec 19, 2022
2 parents 6a2c7a5 + 33d7e50 commit 4f4728b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 21 deletions.
7 changes: 7 additions & 0 deletions doc/user/ospfd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,13 @@ Showing Information
Show the OSPF routing table, as determined by the most recent SPF
calculation.

.. clicmd:: show ip ospf [vrf <NAME|all>] border-routers [json]

Show the list of ABR and ASBR border routers summary learnt via
OSPFv2 Type-3 (Summary LSA) and Type-4 (Summary ASBR LSA).
User can get that information as JSON format when ``json`` keyword
at the end of cli is presented.

.. clicmd:: show ip ospf (1-65535) route orr [NAME]

.. clicmd:: show ip ospf [vrf <NAME|all>] route orr [NAME]
Expand Down
97 changes: 76 additions & 21 deletions ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -11209,38 +11209,73 @@ DEFUN (show_ip_ospf_instance_reachable_routers,

static int show_ip_ospf_border_routers_common(struct vty *vty,
struct ospf *ospf,
uint8_t use_vrf)
uint8_t use_vrf,
json_object *json)
{
if (ospf->instance)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
json_object *json_vrf = NULL;
json_object *json_router = NULL;

ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
if (json) {
if (use_vrf)
json_vrf = json_object_new_object();
else
json_vrf = json;
json_router = json_object_new_object();
}

if (ospf->instance) {
if (!json)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
else
json_object_int_add(json_vrf, "ospfInstance",
ospf->instance);
}

ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);

if (ospf->new_table == NULL) {
vty_out(vty, "No OSPF routing information exist\n");
if (!json)
vty_out(vty, "No OSPF routing information exist\n");
else {
json_object_free(json_router);
json_object_free(json_vrf);
}
return CMD_SUCCESS;
}

/* Show Network routes.
show_ip_ospf_route_network (vty, ospf->new_table); */

/* Show Router routes. */
show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL);
show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_router);

vty_out(vty, "\n");
if (json) {
json_object_object_add(json_vrf, "routers", json_router);
if (use_vrf) {
if (ospf->vrf_id == VRF_DEFAULT)
json_object_object_add(json, "default",
json_vrf);
else
json_object_object_add(json, ospf->name,
json_vrf);
}
} else {
vty_out(vty, "\n");
}

return CMD_SUCCESS;
}

DEFUN (show_ip_ospf_border_routers,
DEFPY (show_ip_ospf_border_routers,
show_ip_ospf_border_routers_cmd,
"show ip ospf [vrf <NAME|all>] border-routers",
"show ip ospf [vrf <NAME|all>] border-routers [json]",
SHOW_STR
IP_STR
"OSPF information\n"
VRF_CMD_HELP_STR
"All VRFs\n"
"Show all the ABR's and ASBR's\n")
"Show all the ABR's and ASBR's\n"
JSON_STR)
{
struct ospf *ospf = NULL;
struct listnode *node = NULL;
Expand All @@ -11250,6 +11285,11 @@ DEFUN (show_ip_ospf_border_routers,
int inst = 0;
int idx_vrf = 0;
uint8_t use_vrf = 0;
bool uj = use_json(argc, argv);
json_object *json = NULL;

if (uj)
json = json_object_new_object();

OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);

Expand All @@ -11265,32 +11305,47 @@ DEFUN (show_ip_ospf_border_routers,

ospf_output = true;
ret = show_ip_ospf_border_routers_common(
vty, ospf, use_vrf);
vty, ospf, use_vrf, json);
}

if (!ospf_output)
if (uj)
vty_json(vty, json);
else if (!ospf_output)
vty_out(vty, "%% OSPF is not enabled\n");

return ret;
} else {
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
vty_out(vty,
"%% OSPF is not enabled in vrf %s\n",
vrf_name);
if (uj)
vty_json(vty, json);
else
vty_out(vty,
"%% OSPF is not enabled in vrf %s\n",
vrf_name);

return CMD_SUCCESS;
}

ret = show_ip_ospf_border_routers_common(vty, ospf,
use_vrf);
}
} else {
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
vty_out(vty, "%% OSPF is not enabled in vrf default\n");
if (uj)
vty_json(vty, json);
else
vty_out(vty,
"%% OSPF is not enabled in vrf default\n");

return CMD_SUCCESS;
}
}

ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf);
if (ospf) {
ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf,
json);
if (uj)
vty_json(vty, json);
}

return ret;
Expand All @@ -11317,7 +11372,7 @@ DEFUN (show_ip_ospf_instance_border_routers,
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;

return show_ip_ospf_border_routers_common(vty, ospf, 0);
return show_ip_ospf_border_routers_common(vty, ospf, 0, NULL);
}

static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
Expand Down

0 comments on commit 4f4728b

Please sign in to comment.