ospfd: OSPFv2 VRF abstact api

Create an api to display vrf name in vty or json format.
Use VRF Name for vtysh and vrfName for json output.

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
This commit is contained in:
Chirag Shah 2017-10-06 15:32:25 -07:00
parent 87bd50e857
commit 52d0c099a0

View File

@ -171,6 +171,18 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
return ospf; return ospf;
} }
static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
json_object *json)
{
if (ospf->name) {
if (json)
json_object_string_add(json, "vrfName", ospf->name);
else
vty_out(vty, "VRF Name: %s\n", ospf->name);
}
}
#ifndef VTYSH_EXTRACT_PL #ifndef VTYSH_EXTRACT_PL
#include "ospf_vty_clippy.c" #include "ospf_vty_clippy.c"
#endif #endif
@ -2890,12 +2902,7 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
} }
} }
if (ospf->name) { ospf_show_vrf_name(ospf, vty, json);
if (use_json)
json_object_string_add(json, "vrfName", ospf->name);
else
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
}
/* Show Router ID. */ /* Show Router ID. */
if (use_json) { if (use_json) {
@ -3864,12 +3871,7 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
} }
if (ospf->name) { ospf_show_vrf_name(ospf, vty, json);
if (use_json)
json_object_string_add(json, "vrfName", ospf->name);
else
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
}
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, use_json); show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
@ -4160,12 +4162,7 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
} }
if (ospf->name) { ospf_show_vrf_name(ospf, vty, json);
if (use_json)
json_object_string_add(json, "vrfName", ospf->name);
else
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
}
/*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/ /*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);
@ -4579,12 +4576,7 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
} }
if (ospf->name) { ospf_show_vrf_name(ospf, vty, json);
if (use_json)
json_object_string_add(json, "vrfName", ospf->name);
else
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
}
ret = inet_aton(argv[arg_base]->arg, &router_id); ret = inet_aton(argv[arg_base]->arg, &router_id);
if (!ret) { if (!ret) {
@ -4685,12 +4677,7 @@ static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
} }
if (ospf->name) { ospf_show_vrf_name(ospf, vty, json);
if (use_json)
json_object_string_add(json, "vrfName", ospf->name);
else
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
}
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
struct route_node *rn; struct route_node *rn;
@ -4816,12 +4803,7 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
} }
if (ospf->name) { ospf_show_vrf_name(ospf, vty, json);
if (use_json)
json_object_string_add(json, "vrfName", ospf->name);
else
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
}
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
struct route_node *rn; struct route_node *rn;
@ -5633,8 +5615,7 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
if (ospf->instance) if (ospf->instance)
vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
if (ospf->name) ospf_show_vrf_name(ospf, vty, NULL);
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
vty_out(vty, "\n OSPF Router with ID (%s)\n\n", vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
inet_ntoa(ospf->router_id)); inet_ntoa(ospf->router_id));
@ -5857,8 +5838,7 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
if (ospf->instance) if (ospf->instance)
vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
if (ospf->name) ospf_show_vrf_name(ospf, vty, NULL);
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
vty_out(vty, "\n OSPF Router with ID (%s)\n\n", vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
inet_ntoa(ospf->router_id)); inet_ntoa(ospf->router_id));
@ -8416,8 +8396,7 @@ static int show_ip_ospf_border_routers_common(struct vty *vty,
if (ospf->instance) if (ospf->instance)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
if (ospf->name) ospf_show_vrf_name(ospf, vty, NULL);
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
if (ospf->new_table == NULL) { if (ospf->new_table == NULL) {
vty_out(vty, "No OSPF routing information exist\n"); vty_out(vty, "No OSPF routing information exist\n");
@ -8511,8 +8490,7 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf)
if (ospf->instance) if (ospf->instance)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
if (ospf->name) ospf_show_vrf_name(ospf, vty, NULL);
vty_out(vty, "OSPF vrfName: %s\n", ospf->name);
if (ospf->new_table == NULL) { if (ospf->new_table == NULL) {
vty_out(vty, "No OSPF routing information exist\n"); vty_out(vty, "No OSPF routing information exist\n");