Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: CLI Changes #17553

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions bgpd/bgp_evpn_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2832,6 +2832,67 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp,
bgp_dest_unlock_node(dest);
}

/*
* Display BGP EVPN routing table -- for specific RD and prefix
* (vty handler). By definition, only matching type-5 route will be
* displayed.
*/
static void evpn_show_route_rd_prefix(struct vty *vty, struct bgp *bgp,
struct prefix_rd *prd,
struct prefix *ip_prefix,
json_object *json)
{
struct prefix_evpn p;
struct bgp_dest *dest;
struct bgp_path_info *pi;
afi_t afi;
safi_t safi;
uint32_t path_cnt = 0;
json_object *json_paths = NULL;
char prefix_str[BUFSIZ];

afi = AFI_L2VPN;
safi = SAFI_EVPN;

/* Build type-5 prefix. */
build_type5_prefix_from_ip_prefix(&p, ip_prefix);

/* See if route exists. */
dest = bgp_safi_node_lookup(bgp->rib[afi][safi], safi,
(struct prefix *)&p, prd);
if (!dest || !bgp_dest_has_bgp_path_info_data(dest)) {
if (!json)
vty_out(vty, "%% Network not in table\n");
return;
}

prefix2str((struct prefix_evpn *)&p, prefix_str,
sizeof(prefix_str));

/* Prefix and num paths displayed once per prefix. */
route_vty_out_detail_header(vty, bgp, dest, bgp_dest_get_prefix(dest), prd,
afi, safi, json, false, false);

if (json)
json_paths = json_object_new_array();

/* Display each path for this prefix. */
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), pi,
afi, safi, RPKI_NOT_BEING_USED, json_paths);
path_cnt++;
}

if (json && path_cnt) {
if (path_cnt)
json_object_object_add(json, "paths", json_paths);
json_object_int_add(json, "numPaths", path_cnt);
} else {
vty_out(vty, "\nDisplayed %u paths for requested prefix\n",
path_cnt);
}
}

/*
* Display BGP EVPN routing table -- for specific RD (vty handler)
* If 'type' is non-zero, only routes matching that type are shown.
Expand Down Expand Up @@ -5118,6 +5179,71 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd_macip,
return CMD_SUCCESS;
}

/*
* Display global EVPN routing table for specific RD and prefix (type-5).
*/
DEFUN(show_bgp_l2vpn_evpn_route_rd_prefix,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFPY, please.

show_bgp_l2vpn_evpn_route_rd_prefix_cmd,
"show bgp l2vpn evpn route rd ASN:NN_OR_IP-ADDRESS:NN prefix <A.B.C.D/M|X:X::X:X/M> [json]",
SHOW_STR
BGP_STR
L2VPN_HELP_STR
EVPN_HELP_STR
"EVPN route information\n"
"Route Distinguisher\n"
"ASN:XX or A.B.C.D:XX\n"
"prefix\n"
"IP prefix\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe IPv4 prefix?

"IPv6 prefix\n"
JSON_STR)
{
struct bgp *bgp;
int ret;
int idx = 0;
struct prefix_rd prd;
struct prefix ip_prefix;
bool uj = false;
json_object *json = NULL;

bgp = bgp_get_evpn();
if (!bgp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be consistent and return an empty JSON in such a case also if the user expects a JSON output?

return CMD_WARNING;

/* check if we need json output */
uj = use_json(argc, argv);
if (uj)
json = json_object_new_object();

/* get the prd */
if (argv_find(argv, argc, "rd", &idx)) {
ret = str2prefix_rd(argv[idx + 1]->arg, &prd);
if (!ret) {
vty_out(vty, "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, and everywhere else returning a warning. We have already some patterns when handling similar cases, e.g.:

json_object_string_add(
					json_no, "warning",
					"No such neighbor or address family");

}
}

/* get the prefix */
if (argv_find(argv, argc, "prefix", &idx)) {
ret = str2prefix(argv[idx + 1]->arg, &ip_prefix);
if (!ret) {
vty_out(vty, "prefix is malformed\n");
return CMD_WARNING;
}
} else
return CMD_WARNING;

evpn_show_route_rd_prefix(vty, bgp, &prd, &ip_prefix, json);

if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}

return CMD_SUCCESS;
}

/* Display per ESI routing table */
DEFUN(show_bgp_l2vpn_evpn_route_esi,
show_bgp_l2vpn_evpn_route_esi_cmd,
Expand Down Expand Up @@ -6135,6 +6261,20 @@ ALIAS_HIDDEN(
"IP\n"
"IP address (IPv4 or IPv6)\n")

ALIAS_HIDDEN(
show_bgp_l2vpn_evpn_route_rd_prefix, show_bgp_evpn_route_rd_prefix_cmd,
"show bgp evpn route rd ASN:NN_OR_IP-ADDRESS:NN prefix <A.B.C.D/M|X:X::X:X/M> [json]",
SHOW_STR
BGP_STR
EVPN_HELP_STR
"EVPN route information\n"
"Route Distinguisher\n"
"ASN:XX or A.B.C.D:XX\n"
"prefix\n"
"IP prefix\n"
"IPv6 prefix\n"
JSON_STR)

ALIAS_HIDDEN(
show_bgp_l2vpn_evpn_route_vni, show_bgp_evpn_route_vni_cmd,
"show bgp evpn route vni " CMD_VNI_RANGE " [<type <macip|2|multicast|3> | vtep A.B.C.D>]",
Expand Down Expand Up @@ -7566,6 +7706,7 @@ void bgp_ethernetvpn_init(void)
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_route_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_route_rd_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_route_rd_macip_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_route_rd_prefix_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_route_esi_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_route_vni_cmd);
install_element(VIEW_NODE,
Expand Down Expand Up @@ -7599,6 +7740,7 @@ void bgp_ethernetvpn_init(void)
install_element(VIEW_NODE, &show_bgp_evpn_route_cmd);
install_element(VIEW_NODE, &show_bgp_evpn_route_rd_cmd);
install_element(VIEW_NODE, &show_bgp_evpn_route_rd_macip_cmd);
install_element(VIEW_NODE, &show_bgp_evpn_route_rd_prefix_cmd);
install_element(VIEW_NODE, &show_bgp_evpn_route_vni_cmd);
install_element(VIEW_NODE, &show_bgp_evpn_route_vni_multicast_cmd);
install_element(VIEW_NODE, &show_bgp_evpn_route_vni_macip_cmd);
Expand Down
30 changes: 16 additions & 14 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -13229,9 +13229,9 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
*/
if (CHECK_FLAG(peer->flags,
PEER_FLAG_GRACEFUL_RESTART)) {
json_object_int_add(json_timer,
"selectionDeferralTimer",
peer->bgp->stalepath_time);
json_object_int_add(
json_timer, "selectionDeferralTimer",
peer->bgp->select_defer_time);
}

if (peer->bgp->gr_info[afi][safi].t_select_deferral !=
Expand Down Expand Up @@ -16914,20 +16914,22 @@ DEFUN (show_bgp_instance_all_ipv6_updgrps,
return CMD_SUCCESS;
}

DEFUN (show_bgp_l2vpn_evpn_updgrps,
show_bgp_l2vpn_evpn_updgrps_cmd,
"show [ip] bgp l2vpn evpn update-groups",
SHOW_STR
IP_STR
BGP_STR
"l2vpn address family\n"
"evpn sub-address family\n"
"Detailed info about dynamic update groups\n")
DEFPY(show_bgp_l2vpn_evpn_updgrps,
show_bgp_l2vpn_evpn_updgrps_cmd,
"show [ip] bgp l2vpn evpn update-groups [(1-1000)$subgrpid] [json$json]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add documentation for this command too (since you touch it)?

Also... to me, it sounds like Show EVPN update-groups with an update-group id instead of subgroup-id. I think telling explicitly that we want a subgroup-id would be better (e.g.: show bgp l2vpn evpn update-group [subgroup-id (1-1000)...), no?

SHOW_STR
IP_STR
BGP_STR
"l2vpn address family\n"
"evpn sub-address family\n"
"Detailed info about dynamic update groups\n"
"Specific subgroup to display detailed info\n"
JSON_STR)
{
char *vrf = NULL;
uint64_t subgrp_id = 0;
bool uj = !!json;

bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id, 0);
bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrpid, uj);
return CMD_SUCCESS;
}

Expand Down
Loading