From 83856649b35f45243205420aac515b635e712323 Mon Sep 17 00:00:00 2001 From: Karl Quan Date: Tue, 14 Feb 2023 07:54:59 -0800 Subject: [PATCH] bgpd: BGP troubleshooting - Add a keyword self-originate to display only self-originated prefixes when looking at the BGP table for a given address-family Add a keyword self-originate" to extend current CLI commands to filter out self-originated routes only a\) CLI to show ipv4/ipv6 self-originated routes "show [ip] bgp [afi] [safi] [all] self-originate [wide|json]" b\) CLI to show evpn self-originated routes "show bgp l2vpn evpn route [detail] [type ] self-originate [json]" Signed-off-by: Karl Quan --- bgpd/bgp_evpn_vty.c | 19 ++++++++++++++----- bgpd/bgp_route.c | 10 ++++++++++ bgpd/bgp_route.h | 1 + bgpd/bgp_vty.h | 3 +++ doc/user/bgp.rst | 13 +++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 6b63c6e3aa..df1a1dd11a 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -3023,7 +3023,7 @@ static void evpn_show_route_rd_all_macip(struct vty *vty, struct bgp *bgp, * If 'type' is non-zero, only routes matching that type are shown. */ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, - json_object *json, int detail) + json_object *json, int detail, bool self_orig) { struct bgp_dest *rd_dest; struct bgp_table *table; @@ -3081,6 +3081,9 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, pi = bgp_dest_get_bgp_path_info(dest); if (pi) { + if (self_orig && (pi->peer != bgp->peer_self)) + continue; + /* Overall header/legend displayed once. */ if (header) { bgp_evpn_show_route_header(vty, bgp, @@ -3200,7 +3203,7 @@ int bgp_evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, if (use_json) json = json_object_new_object(); - evpn_show_all_routes(vty, bgp, type, json, detail); + evpn_show_all_routes(vty, bgp, type, json, detail, false); if (use_json) vty_json(vty, json); @@ -4773,7 +4776,7 @@ int bgp_evpn_cli_parse_type(int *type, struct cmd_token **argv, int argc) */ DEFUN(show_bgp_l2vpn_evpn_route, show_bgp_l2vpn_evpn_route_cmd, - "show bgp l2vpn evpn route [detail] [type "EVPN_TYPE_ALL_LIST"] [json]", + "show bgp l2vpn evpn route [detail] [type "EVPN_TYPE_ALL_LIST"] ["BGP_SELF_ORIG_CMD_STR"] [json]", SHOW_STR BGP_STR L2VPN_HELP_STR @@ -4782,12 +4785,15 @@ DEFUN(show_bgp_l2vpn_evpn_route, "Display Detailed Information\n" EVPN_TYPE_HELP_STR EVPN_TYPE_ALL_LIST_HELP_STR + BGP_SELF_ORIG_HELP_STR JSON_STR) { struct bgp *bgp; int detail = 0; int type = 0; bool uj = false; + int arg_idx = 0; + bool self_orig = false; json_object *json = NULL; uj = use_json(argc, argv); @@ -4805,7 +4811,10 @@ DEFUN(show_bgp_l2vpn_evpn_route, if (argv_find(argv, argc, "detail", &detail)) detail = 1; - evpn_show_all_routes(vty, bgp, type, json, detail); + if (argv_find(argv, argc, BGP_SELF_ORIG_CMD_STR, &arg_idx)) + self_orig = true; + + evpn_show_all_routes(vty, bgp, type, json, detail, self_orig); /* * This is an extremely expensive operation at scale @@ -4871,7 +4880,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd, return CMD_WARNING; if (rd_all) - evpn_show_all_routes(vty, bgp, type, json, 1); + evpn_show_all_routes(vty, bgp, type, json, 1, false); else evpn_show_route_rd(vty, bgp, &prd, type, json); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 23e6195d34..963a06fa0c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11458,6 +11458,10 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, || CHECK_FLAG(pi->flags, BGP_PATH_HISTORY)) continue; } + if (type == bgp_show_type_self_originated) { + if (pi->peer != bgp->peer_self) + continue; + } if (!use_json && header) { vty_out(vty, @@ -12610,6 +12614,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, |alias ALIAS_NAME\ |A.B.C.D/M longer-prefixes\ |X:X::X:X/M longer-prefixes\ + |"BGP_SELF_ORIG_CMD_STR"\ |detail-routes$detail_routes\ ] [json$uj [detail$detail_json] | wide$wide]", SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR @@ -12659,6 +12664,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, "Display route and more specific routes\n" "IPv6 prefix\n" "Display route and more specific routes\n" + BGP_SELF_ORIG_HELP_STR "Display detailed version of all routes\n" JSON_STR "Display detailed version of JSON output\n" @@ -12853,6 +12859,10 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, output_arg = &p; } + /* self originated only */ + if (argv_find(argv, argc, BGP_SELF_ORIG_CMD_STR, &idx)) + sh_type = bgp_show_type_self_originated; + if (!all) { /* show bgp: AFI_IP6, show ip bgp: AFI_IP */ if (community) diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 452282926f..33255924ba 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -61,6 +61,7 @@ enum bgp_show_type { bgp_show_type_detail, bgp_show_type_rpki, bgp_show_type_prefix_version, + bgp_show_type_self_originated, }; enum bgp_show_adj_route_type { diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 019789dff8..e3e3c0d884 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -43,6 +43,9 @@ struct bgp; BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR \ BGP_AF_MODIFIER_STR BGP_AF_MODIFIER_STR +#define BGP_SELF_ORIG_CMD_STR "self-originate" +#define BGP_SELF_ORIG_HELP_STR "Display only self-originated routes\n" + #define SHOW_GR_HEADER \ "Codes: GR - Graceful Restart," \ " * - Inheriting Global GR Config,\n" \ diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index b17442f641..dc0e96abd0 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -3887,6 +3887,10 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`. EVPN prefixes can also be filtered by EVPN route type. +.. clicmd:: show bgp l2vpn evpn route [detail] [type ] self-originate [json] + + Display self-originated EVPN prefixes which can also be filtered by EVPN route type. + .. clicmd:: show bgp vni [vtep VTEP] [type ] [] Display per-VNI EVPN routing table in bgp. Filter route-type, vtep, or VNI. @@ -4043,6 +4047,15 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`. If the ``json`` option is specified, output is displayed in JSON format. +.. clicmd:: show [ip] bgp [afi] [safi] [all] self-originate [wide|json] + + Display self-originated routes. + + If ``wide`` option is specified, then the prefix table's width is increased + to fully display the prefix and the nexthop. + + If the ``json`` option is specified, output is displayed in JSON format. + .. clicmd:: show [ip] bgp [afi] [safi] [all] neighbors A.B.C.D [advertised-routes|received-routes|filtered-routes] [ | detail] [json|wide] Display the routes advertised to a BGP neighbor or received routes