Skip to content

Commit

Permalink
Merge pull request FRRouting#7967 from ton31337/feature/show_bgp_summ…
Browse files Browse the repository at this point in the history
…ary_wide

bgpd: Add `show bgp summary wide` command
  • Loading branch information
donaldsharp authored Jan 28, 2021
2 parents 0c6ac26 + 749d0f2 commit 1e1d6a8
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 54 deletions.
27 changes: 17 additions & 10 deletions bgpd/bgp_evpn_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions bgpd/bgp_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
112 changes: 73 additions & 39 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -10968,6 +10975,11 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
peer->domainname);

json_object_int_add(json_peer, "remoteAs", peer->as);
json_object_int_add(
json_peer, "localAs",
peer->change_local_as
? peer->change_local_as
: peer->local_as);
json_object_int_add(json_peer, "version", 4);
json_object_int_add(json_peer, "msgRcvd",
PEER_TOTAL_RX(peer));
Expand Down Expand Up @@ -11124,14 +11136,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]) {
Expand All @@ -11149,7 +11180,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
[afi]
[pfx_rcd_safi]);
} else {
vty_out(vty, " NoNeg");
vty_out(vty, " NoNeg");
}

if (paf && PAF_SUBGRP(paf)) {
Expand All @@ -11166,6 +11197,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
(PAF_SUBGRP(
paf))
->scount);
} else {
vty_out(vty, " NoNeg");
}
} else {
if (CHECK_FLAG(peer->flags,
Expand All @@ -11187,7 +11220,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");
Expand Down Expand Up @@ -11227,14 +11261,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");
Expand Down Expand Up @@ -11272,8 +11306,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)
Expand All @@ -11295,14 +11328,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");
Expand All @@ -11325,8 +11357,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)
Expand All @@ -11336,16 +11367,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);
Expand All @@ -11360,17 +11390,15 @@ 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;
}
}

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");
Expand All @@ -11385,7 +11413,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 [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [json$uj]",
"show [ip] bgp [<view|vrf> 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
Expand All @@ -11396,13 +11424,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;

Expand All @@ -11423,12 +11451,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)
Expand Down
9 changes: 7 additions & 2 deletions bgpd/bgp_vty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 22 additions & 3 deletions doc/user/bgp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3329,8 +3329,8 @@ Some other commands provide additional options for filtering the output.
This command displays BGP routes using AS path regular expression
(:ref:`bgp-regular-expressions`).

.. index:: show [ip] bgp [all] summary [json]
.. clicmd:: show [ip] bgp [all] summary [json]
.. index:: show [ip] bgp [all] summary [wide] [json]
.. clicmd:: show [ip] bgp [all] summary [wide] [json]

Show a bgp peer summary for the specified address family.

Expand All @@ -3339,6 +3339,25 @@ and should no longer be used. In order to reach the other BGP routing tables
other than the IPv6 routing table given by :clicmd:`show bgp`, the new command
structure is extended with :clicmd:`show bgp [afi] [safi]`.

``wide`` option gives more output like ``LocalAS`` and extended ``Desc`` to
64 characters.

.. code-block:: frr
exit1# show ip bgp summary wide
IPv4 Unicast Summary:
BGP router identifier 192.168.100.1, local AS number 65534 vrf-id 0
BGP table version 3
RIB entries 5, using 920 bytes of memory
Peers 1, using 27 KiB of memory
Neighbor V AS LocalAS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc
192.168.0.2 4 65030 123 15 22 0 0 0 00:07:00 0 1 us-east1-rs1.frrouting.org
Total number of neighbors 1
exit1#
.. index:: show bgp [afi] [safi] [all] [wide|json]
.. clicmd:: show bgp [afi] [safi] [all] [wide|json]

Expand Down Expand Up @@ -3471,7 +3490,7 @@ attribute.

If ``json`` option is specified, output is displayed in JSON format.

.. index:: show bgp labelpool <chunks|inuse|ledger|requests|summary> [json]
.. index:: show bgp labelpool <chunks|inuse|ledger|requests|summary> [json]
.. clicmd:: show bgp labelpool <chunks|inuse|ledger|requests|summary> [json]

These commands display information about the BGP labelpool used for
Expand Down

0 comments on commit 1e1d6a8

Please sign in to comment.