From 4265b26111b162f1504c32430d3c15635e372c1b Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 14 Feb 2020 14:40:57 +0100 Subject: [PATCH] bgpd: new vty command to dump all bgp per vrf statistics this command is a shortcut to facilitate the extraction of statistics for all afi/safi related to one bgp instance. the command is: show bgp [vrf XX] statistics-all [json] Signed-off-by: Philippe Guibert --- bgpd/bgp_route.c | 39 +++++++++++++++++++++++++++++++++++++++ bgpd/bgp_vty.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 687f969c3f..a691299ab2 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -10554,6 +10554,44 @@ DEFUN (show_ip_bgp_large_community, static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct json_object *json); + +DEFUN (show_ip_bgp_statistics_all, + show_ip_bgp_statistics_all_cmd, + "show [ip] bgp [ VIEWVRFNAME] statistics-all [json]", + SHOW_STR + IP_STR + BGP_STR + BGP_INSTANCE_HELP_STR + "Display number of prefixes for all afi/safi\n" + JSON_STR) +{ + bool uj = use_json(argc, argv); + struct bgp *bgp = NULL; + safi_t safi; + afi_t afi; + int idx = 0; + struct json_object *json = NULL; + + bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi, + &bgp, false); + if (!idx) + return CMD_WARNING; + if (uj) + json = json_object_new_array(); + + for (afi = AFI_IP; afi < AFI_MAX; ++afi) { + for (safi = SAFI_UNICAST; + safi < SAFI_MAX; safi++) + bgp_table_stats(vty, bgp, afi, safi, json); + } + if (json) { + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + return CMD_SUCCESS; +} + /* BGP route print out function without JSON */ DEFUN (show_ip_bgp_afi_safi_statistics, show_ip_bgp_afi_safi_statistics_cmd, @@ -13282,6 +13320,7 @@ void bgp_route_init(void) install_element(VIEW_NODE, &show_ip_bgp_json_cmd); install_element(VIEW_NODE, &show_ip_bgp_route_cmd); install_element(VIEW_NODE, &show_ip_bgp_regexp_cmd); + install_element(VIEW_NODE, &show_ip_bgp_statistics_all_cmd); install_element(VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd); diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index fa7b96d87b..3f06584cc7 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -175,6 +175,9 @@ extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, int argc, int *idx, afi_t *afi, safi_t *safi, struct bgp **bgp, bool use_json); +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); -- 2.39.5