From 85eeb0291554d3cbe0f4844406abc7f17bfd5ed9 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 28 Jan 2021 13:00:40 +0200 Subject: [PATCH] bgpd: Add `show bgp summary wide` command Add LocalAS into wide output and extend Desc to 64 chars instead of 20. Signed-off-by: Donatas Abraitis --- bgpd/bgp_evpn_vty.c | 27 +++++++----- bgpd/bgp_route.h | 2 + bgpd/bgp_vty.c | 103 ++++++++++++++++++++++++++++---------------- bgpd/bgp_vty.h | 9 +++- 4 files changed, 91 insertions(+), 50 deletions(-) diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 4dc670a24d..5b0b3bb6e5 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -4100,7 +4100,7 @@ DEFPY(show_bgp_l2vpn_evpn_es_vrf, show_bgp_l2vpn_evpn_es_vrf_cmd, */ DEFUN(show_bgp_l2vpn_evpn_summary, show_bgp_l2vpn_evpn_summary_cmd, - "show bgp [vrf VRFNAME] l2vpn evpn summary [established|failed] [json]", + "show bgp [vrf VRFNAME] l2vpn evpn summary [established|failed] [wide] [json]", SHOW_STR BGP_STR "bgp vrf\n" @@ -4110,23 +4110,30 @@ DEFUN(show_bgp_l2vpn_evpn_summary, "Summary of BGP neighbor status\n" "Show only sessions in Established state\n" "Show only sessions not in Established state\n" + "Increase table width for longer output\n" JSON_STR) { int idx_vrf = 0; - bool uj = use_json(argc, argv); + int idx = 0; char *vrf = NULL; - bool show_failed = false; - bool show_established = false; + uint8_t show_flags = 0; if (argv_find(argv, argc, "vrf", &idx_vrf)) vrf = argv[++idx_vrf]->arg; - if (argv_find(argv, argc, "failed", &idx_vrf)) - show_failed = true; - if (argv_find(argv, argc, "established", &idx_vrf)) - show_established = true; - return bgp_show_summary_vty(vty, vrf, AFI_L2VPN, SAFI_EVPN, show_failed, - show_established, uj); + if (argv_find(argv, argc, "failed", &idx)) + SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED); + + if (argv_find(argv, argc, "established", &idx)) + SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED); + + if (argv_find(argv, argc, "wide", &idx)) + SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE); + + if (use_json(argc, argv)) + SET_FLAG(show_flags, BGP_SHOW_OPT_JSON); + + return bgp_show_summary_vty(vty, vrf, AFI_L2VPN, SAFI_EVPN, show_flags); } int bgp_evpn_cli_parse_type(int *type, struct cmd_token **argv, int argc) diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index bdbf4743ab..1060d2e60d 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -558,6 +558,8 @@ DECLARE_HOOK(bgp_process, #define BGP_SHOW_OPT_AFI_ALL (1 << 2) #define BGP_SHOW_OPT_AFI_IP (1 << 3) #define BGP_SHOW_OPT_AFI_IP6 (1 << 4) +#define BGP_SHOW_OPT_ESTABLISHED (1 << 5) +#define BGP_SHOW_OPT_FAILED (1 << 6) /* Prototypes. */ extern void bgp_rib_remove(struct bgp_dest *dest, struct bgp_path_info *pi, diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index a8256d165e..cd044bcb4b 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -10612,8 +10612,7 @@ static char *bgp_peer_description_stripped(char *desc, uint32_t size) /* Show BGP peer's summary information. */ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, - bool show_failed, bool show_established, - bool use_json) + uint8_t show_flags) { struct peer *peer; struct listnode *node, *nnode; @@ -10629,6 +10628,11 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, json_object *json_peers = NULL; struct peer_af *paf; struct bgp_filter *filter; + bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON); + bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED); + bool show_established = + CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED); + bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE); /* labeled-unicast routes are installed in the unicast table so in order * to @@ -10925,10 +10929,13 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, vty_out(vty, "%*s", max_neighbor_width - 8, " "); if (show_failed) - vty_out(vty, "EstdCnt DropCnt ResetTime Reason\n"); + vty_out(vty, + BGP_SHOW_SUMMARY_HEADER_FAILED); else vty_out(vty, - "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n"); + show_wide + ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE + : BGP_SHOW_SUMMARY_HEADER_ALL); } } @@ -11124,14 +11131,33 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, &peer->ibuf->count, memory_order_relaxed); - vty_out(vty, - "4 %10u %9u %9u %8" PRIu64" %4zu %4zu %8s", - peer->as, PEER_TOTAL_RX(peer), - PEER_TOTAL_TX(peer), - peer->version[afi][safi], inq_count, - outq_count, - peer_uptime(peer->uptime, timebuf, - BGP_UPTIME_LEN, 0, NULL)); + if (show_wide) + vty_out(vty, + "4 %10u %10u %9u %9u %8" PRIu64 + " %4zu %4zu %8s", + peer->as, + peer->change_local_as + ? peer->change_local_as + : peer->local_as, + PEER_TOTAL_RX(peer), + PEER_TOTAL_TX(peer), + peer->version[afi][safi], + inq_count, outq_count, + peer_uptime(peer->uptime, + timebuf, + BGP_UPTIME_LEN, 0, + NULL)); + else + vty_out(vty, "4 %10u %9u %9u %8" PRIu64 + " %4zu %4zu %8s", + peer->as, PEER_TOTAL_RX(peer), + PEER_TOTAL_TX(peer), + peer->version[afi][safi], + inq_count, outq_count, + peer_uptime(peer->uptime, + timebuf, + BGP_UPTIME_LEN, 0, + NULL)); if (peer->status == Established) { if (peer->afc_recv[afi][safi]) { @@ -11187,7 +11213,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, if (peer->desc) vty_out(vty, " %s", bgp_peer_description_stripped( - peer->desc, 20)); + peer->desc, + show_wide ? 64 : 20)); else vty_out(vty, " N/A"); vty_out(vty, "\n"); @@ -11227,14 +11254,14 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, } static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, - int safi, bool show_failed, - bool show_established, bool use_json) + int safi, uint8_t show_flags) { int is_first = 1; int afi_wildcard = (afi == AFI_MAX); int safi_wildcard = (safi == SAFI_MAX); int is_wildcard = (afi_wildcard || safi_wildcard); bool nbr_output = false; + bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON); if (use_json && is_wildcard) vty_out(vty, "{\n"); @@ -11272,8 +11299,7 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, } } bgp_show_summary(vty, bgp, afi, safi, - show_failed, show_established, - use_json); + show_flags); } safi++; if (!safi_wildcard) @@ -11295,14 +11321,13 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, } static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, - safi_t safi, bool show_failed, - bool show_established, - bool use_json) + safi_t safi, uint8_t show_flags) { struct listnode *node, *nnode; struct bgp *bgp; int is_first = 1; bool nbr_output = false; + bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON); if (use_json) vty_out(vty, "{\n"); @@ -11325,8 +11350,7 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, ? VRF_DEFAULT_NAME : bgp->name); } - bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed, - show_established, use_json); + bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags); } if (use_json) @@ -11336,16 +11360,15 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, } int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, - safi_t safi, bool show_failed, bool show_established, - bool use_json) + safi_t safi, uint8_t show_flags) { struct bgp *bgp; + bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON); if (name) { if (strmatch(name, "all")) { - bgp_show_all_instances_summary_vty( - vty, afi, safi, show_failed, show_established, - use_json); + bgp_show_all_instances_summary_vty(vty, afi, safi, + show_flags); return CMD_SUCCESS; } else { bgp = bgp_lookup_by_name(name); @@ -11360,8 +11383,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, } bgp_show_summary_afi_safi(vty, bgp, afi, safi, - show_failed, show_established, - use_json); + show_flags); return CMD_SUCCESS; } } @@ -11369,8 +11391,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, bgp = bgp_get_default(); if (bgp) - bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed, - show_established, use_json); + bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags); else { if (use_json) vty_out(vty, "{}\n"); @@ -11385,7 +11406,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, /* `show [ip] bgp summary' commands. */ DEFPY (show_ip_bgp_summary, show_ip_bgp_summary_cmd, - "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]", + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [wide] [json$uj]", SHOW_STR IP_STR BGP_STR @@ -11396,13 +11417,13 @@ DEFPY (show_ip_bgp_summary, "Summary of BGP neighbor status\n" "Show only sessions in Established state\n" "Show only sessions not in Established state\n" + "Increase table width for longer output\n" JSON_STR) { char *vrf = NULL; afi_t afi = AFI_MAX; safi_t safi = SAFI_MAX; - bool show_failed = false; - bool show_established = false; + uint8_t show_flags = 0; int idx = 0; @@ -11423,12 +11444,18 @@ DEFPY (show_ip_bgp_summary, } if (argv_find(argv, argc, "failed", &idx)) - show_failed = true; + SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED); + if (argv_find(argv, argc, "established", &idx)) - show_established = true; + SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED); + + if (argv_find(argv, argc, "wide", &idx)) + SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE); + + if (argv_find(argv, argc, "json", &idx)) + SET_FLAG(show_flags, BGP_SHOW_OPT_JSON); - return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, - show_established, uj); + return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags); } const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json) diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 07f61ab0ea..85619dd074 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -53,6 +53,12 @@ struct bgp; " Helper - GR Mode-Helper,\n" \ " Disable - GR Mode-Disable.\n\n" +#define BGP_SHOW_SUMMARY_HEADER_ALL \ + "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n" +#define BGP_SHOW_SUMMARY_HEADER_ALL_WIDE \ + "V AS LocalAS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc\n" +#define BGP_SHOW_SUMMARY_HEADER_FAILED "EstdCnt DropCnt ResetTime Reason\n" + #define BGP_SHOW_PEER_GR_CAPABILITY( \ vty, p, use_json, json) \ do { \ @@ -178,8 +184,7 @@ extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, int bgp_vty_find_and_parse_bgp(struct vty *vty, struct cmd_token **argv, int argc, struct bgp **bgp, bool use_json); extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, - safi_t safi, bool show_failed, - bool show_established, bool use_json); + safi_t safi, uint8_t show_flags); extern int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len); extern int bgp_clear_star_soft_out(const char *name, char *errmsg, -- 2.39.5