]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Add `show bgp summary wide` command
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 28 Jan 2021 11:00:40 +0000 (13:00 +0200)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 28 Jan 2021 14:35:16 +0000 (16:35 +0200)
Add LocalAS into wide output and extend Desc to 64 chars instead of 20.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
bgpd/bgp_evpn_vty.c
bgpd/bgp_route.h
bgpd/bgp_vty.c
bgpd/bgp_vty.h

index 4dc670a24dc61476da22bd8803599291a6a8e424..5b0b3bb6e5c1438e0ec5eb25b63692c609f0b4e6 100644 (file)
@@ -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)
index bdbf4743ab595940c7da450d734716c8ed48c2f5..1060d2e60da28c01402c995fdaa3cce4e43a0b18 100644 (file)
@@ -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,
index a8256d165e5c654ad6a5c3974131abf582d65d4a..cd044bcb4b6255bb4d734c67ddf16a0365624e3d 100644 (file)
@@ -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 [<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
@@ -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)
index 07f61ab0ea2051ec8095a7536b5b1c2992b5bbae..85619dd074dbac774476aadfaae7b0e547bdd6df 100644 (file)
@@ -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,