]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: new vty command to dump all bgp per vrf statistics
authorPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 14 Feb 2020 13:40:57 +0000 (14:40 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 31 Mar 2020 12:38:15 +0000 (14:38 +0200)
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 <philippe.guibert@6wind.com>
bgpd/bgp_route.c
bgpd/bgp_vty.h

index 687f969c3f91d2da947bb194bbf2b8270fb0ac31..a691299ab2f6abaeabbabe686c7a19ce1129b51a 100644 (file)
@@ -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 [<view|vrf> 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);
index fa7b96d87bd38d17175dadf469a67dbd1f1a1b14..3f06584cc7221cd6152cad43577eced591fce36c 100644 (file)
@@ -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);