diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2020-07-09 20:32:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-09 20:32:27 -0400 |
| commit | 49d5fcc2b186ce8ad4f16efdac880531d4ae8683 (patch) | |
| tree | 260ad138dfd5ec3c8db1d4bbac627b9f01e1917e | |
| parent | eb94db103c541c90b8ce342ce463a719f72a5d17 (diff) | |
| parent | 1c02726773a7ee93f7e18174c28289f5adb74ed1 (diff) | |
Merge pull request #6702 from ton31337/feature/bgp_show_only_established_sessions
bgpd: Add command to show only established sessions
| -rw-r--r-- | bgpd/bgp_evpn_vty.c | 11 | ||||
| -rw-r--r-- | bgpd/bgp_vty.c | 43 | ||||
| -rw-r--r-- | bgpd/bgp_vty.h | 3 | ||||
| -rw-r--r-- | doc/user/bgp.rst | 6 |
4 files changed, 47 insertions, 16 deletions
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index d2257b0126..1a0e5c0cd3 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -4075,7 +4075,7 @@ DEFUN(show_bgp_l2vpn_evpn_es, */ DEFUN(show_bgp_l2vpn_evpn_summary, show_bgp_l2vpn_evpn_summary_cmd, - "show bgp [vrf VRFNAME] l2vpn evpn summary [failed] [json]", + "show bgp [vrf VRFNAME] l2vpn evpn summary [established|failed] [json]", SHOW_STR BGP_STR "bgp vrf\n" @@ -4083,6 +4083,7 @@ DEFUN(show_bgp_l2vpn_evpn_summary, L2VPN_HELP_STR EVPN_HELP_STR "Summary of BGP neighbor status\n" + "Show only sessions in Established state\n" "Show only sessions not in Established state\n" JSON_STR) { @@ -4090,13 +4091,17 @@ DEFUN(show_bgp_l2vpn_evpn_summary, bool uj = use_json(argc, argv); char *vrf = NULL; bool show_failed = false; + bool show_established = false; if (argv_find(argv, argc, "vrf", &idx_vrf)) vrf = argv[++idx_vrf]->arg; if (argv_find(argv, argc, "failed", &idx_vrf)) show_failed = true; - return bgp_show_summary_vty(vty, vrf, AFI_L2VPN, SAFI_EVPN, - show_failed, uj); + 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); } /* diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 449dab12b0..c38db2eb67 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -8861,7 +8861,8 @@ static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp, /* 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 use_json) + bool show_failed, bool show_established, + bool use_json) { struct peer *peer; struct listnode *node, *nnode; @@ -9194,6 +9195,10 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, bgp_show_failed_summary(vty, bgp, peer, json_peer, 0, use_json); } else if (!show_failed) { + if (show_established + && bgp_has_peer_failed(peer, afi, safi)) + continue; + json_peer = json_object_new_object(); if (peer_dynamic_neighbor(peer)) { json_object_boolean_true_add(json_peer, @@ -9283,6 +9288,10 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, max_neighbor_width, use_json); } else if (!show_failed) { + if (show_established + && bgp_has_peer_failed(peer, afi, safi)) + continue; + memset(dn_flag, '\0', sizeof(dn_flag)); if (peer_dynamic_neighbor(peer)) { dn_flag[0] = '*'; @@ -9405,7 +9414,8 @@ 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 use_json) + int safi, bool show_failed, + bool show_established, bool use_json) { int is_first = 1; int afi_wildcard = (afi == AFI_MAX); @@ -9448,7 +9458,8 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, false)); } } - bgp_show_summary(vty, bgp, afi, safi, show_failed, + bgp_show_summary(vty, bgp, afi, safi, + show_failed, show_established, use_json); } safi++; @@ -9472,6 +9483,7 @@ 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) { struct listnode *node, *nnode; @@ -9501,7 +9513,7 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, : bgp->name); } bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed, - use_json); + show_established, use_json); } if (use_json) @@ -9511,15 +9523,16 @@ 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 use_json) + safi_t safi, bool show_failed, bool show_established, + bool use_json) { struct bgp *bgp; if (name) { if (strmatch(name, "all")) { - bgp_show_all_instances_summary_vty(vty, afi, safi, - show_failed, - use_json); + bgp_show_all_instances_summary_vty( + vty, afi, safi, show_failed, show_established, + use_json); return CMD_SUCCESS; } else { bgp = bgp_lookup_by_name(name); @@ -9534,7 +9547,8 @@ 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, use_json); + show_failed, show_established, + use_json); return CMD_SUCCESS; } } @@ -9543,7 +9557,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, if (bgp) bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed, - use_json); + show_established, use_json); else { if (use_json) vty_out(vty, "{}\n"); @@ -9558,7 +9572,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, /* `show [ip] bgp summary' commands. */ DEFUN (show_ip_bgp_summary, show_ip_bgp_summary_cmd, - "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]", + "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [established|failed] [json]", SHOW_STR IP_STR BGP_STR @@ -9566,6 +9580,7 @@ DEFUN (show_ip_bgp_summary, BGP_AFI_HELP_STR BGP_SAFI_WITH_LABEL_HELP_STR "Summary of BGP neighbor status\n" + "Show only sessions in Established state\n" "Show only sessions not in Established state\n" JSON_STR) { @@ -9573,6 +9588,7 @@ DEFUN (show_ip_bgp_summary, afi_t afi = AFI_MAX; safi_t safi = SAFI_MAX; bool show_failed = false; + bool show_established = false; int idx = 0; @@ -9594,10 +9610,13 @@ DEFUN (show_ip_bgp_summary, if (argv_find(argv, argc, "failed", &idx)) show_failed = true; + if (argv_find(argv, argc, "established", &idx)) + show_established = true; bool uj = use_json(argc, argv); - return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj); + return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, + show_established, uj); } 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 d6ca198d09..95eefbc36f 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -178,6 +178,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 use_json); + safi_t safi, bool show_failed, + bool show_established, bool use_json); #endif /* _QUAGGA_BGP_VTY_H */ diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index 388d479bab..8b56834d80 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -2731,6 +2731,12 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`. Show a bgp peer summary for peers that are not succesfully exchanging routes for the specified address family, and subsequent address-family. +.. index:: show bgp [afi] [safi] summary established [json] +.. clicmd:: show bgp [afi] [safi] summary established [json] + + Show a bgp peer summary for peers that are succesfully exchanging routes + for the specified address family, and subsequent address-family. + .. index:: show bgp [afi] [safi] neighbor [PEER] .. clicmd:: show bgp [afi] [safi] neighbor [PEER] |
