Created
February 25, 2020 09:31
-
-
Save polychaeta/3e76a3cb97713e97a3757f26de9ae5de to your computer and use it in GitHub Desktop.
FRRouting/frr #5812
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c | |
index a808c1b53..d9c370d05 100644 | |
--- a/bgpd/bgp_route.c | |
+++ b/bgpd/bgp_route.c | |
@@ -10495,15 +10495,10 @@ 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) | |
+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; | |
@@ -10544,10 +10539,10 @@ DEFUN (show_ip_bgp_statistics_all, | |
bgp_table_stats(vty, bgp, afi, safi, json_afi_safi); | |
if (uj) | |
- json_object_object_add(json_all, | |
- get_afi_safi_str(afi, | |
- safi, true), | |
- json_afi_safi); | |
+ json_object_object_add( | |
+ json_all, | |
+ get_afi_safi_str(afi, safi, true), | |
+ json_afi_safi); | |
safi++; | |
} | |
@@ -10555,8 +10550,9 @@ DEFUN (show_ip_bgp_statistics_all, | |
} | |
if (uj) { | |
- vty_out(vty, "%s", json_object_to_json_string_ext( | |
- json_all, JSON_C_TO_STRING_PRETTY)); | |
+ vty_out(vty, "%s", | |
+ json_object_to_json_string_ext( | |
+ json_all, JSON_C_TO_STRING_PRETTY)); | |
json_object_free(json_all); | |
} | |
@@ -10564,17 +10560,10 @@ DEFUN (show_ip_bgp_statistics_all, | |
} | |
/* BGP route print out function without JSON */ | |
-DEFUN (show_ip_bgp_l2vpn_evpn_statistics, | |
- show_ip_bgp_l2vpn_evpn_statistics_cmd, | |
- "show [ip] bgp [<view|vrf> VIEWVRFNAME] [l2vpn [evpn]] statistics [json]", | |
- SHOW_STR | |
- IP_STR | |
- BGP_STR | |
- BGP_INSTANCE_HELP_STR | |
- L2VPN_HELP_STR | |
- EVPN_HELP_STR | |
- "BGP RIB advertisement statistics\n" | |
- JSON_STR) | |
+DEFUN(show_ip_bgp_l2vpn_evpn_statistics, show_ip_bgp_l2vpn_evpn_statistics_cmd, | |
+ "show [ip] bgp [<view|vrf> VIEWVRFNAME] [l2vpn [evpn]] statistics [json]", | |
+ SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR L2VPN_HELP_STR EVPN_HELP_STR | |
+ "BGP RIB advertisement statistics\n" JSON_STR) | |
{ | |
afi_t afi = AFI_L2VPN; | |
safi_t safi = SAFI_EVPN; | |
@@ -10599,26 +10588,23 @@ DEFUN (show_ip_bgp_l2vpn_evpn_statistics, | |
json = json_object_new_object(); | |
json_object_object_add(json, get_afi_safi_str(afi, safi, true), | |
json_afi_safi); | |
- vty_out(vty, "%s", json_object_to_json_string_ext( | |
- json, JSON_C_TO_STRING_PRETTY)); | |
+ vty_out(vty, "%s", | |
+ json_object_to_json_string_ext( | |
+ json, JSON_C_TO_STRING_PRETTY)); | |
json_object_free(json); | |
} | |
return ret; | |
} | |
/* BGP route print out function without JSON */ | |
-DEFUN (show_ip_bgp_afi_safi_statistics, | |
- show_ip_bgp_afi_safi_statistics_cmd, | |
- "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]\ | |
+DEFUN(show_ip_bgp_afi_safi_statistics, show_ip_bgp_afi_safi_statistics_cmd, | |
+ "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR | |
+ " [" BGP_SAFI_WITH_LABEL_CMD_STR | |
+ "]]\ | |
statistics [json]", | |
- SHOW_STR | |
- IP_STR | |
- BGP_STR | |
- BGP_INSTANCE_HELP_STR | |
- BGP_AFI_HELP_STR | |
- BGP_SAFI_WITH_LABEL_HELP_STR | |
- "BGP RIB advertisement statistics\n" | |
- JSON_STR) | |
+ SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR | |
+ BGP_SAFI_WITH_LABEL_HELP_STR | |
+ "BGP RIB advertisement statistics\n" JSON_STR) | |
{ | |
afi_t afi = AFI_IP6; | |
safi_t safi = SAFI_UNICAST; | |
@@ -10643,18 +10629,19 @@ DEFUN (show_ip_bgp_afi_safi_statistics, | |
json = json_object_new_object(); | |
json_object_object_add(json, get_afi_safi_str(afi, safi, true), | |
json_afi_safi); | |
- vty_out(vty, "%s", json_object_to_json_string_ext( | |
- json, JSON_C_TO_STRING_PRETTY)); | |
+ vty_out(vty, "%s", | |
+ json_object_to_json_string_ext( | |
+ json, JSON_C_TO_STRING_PRETTY)); | |
json_object_free(json); | |
} | |
return ret; | |
- | |
} | |
/* BGP route print out function without JSON */ | |
-DEFUN (show_ip_bgp, | |
- show_ip_bgp_cmd, | |
- "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]\ | |
+DEFUN(show_ip_bgp, show_ip_bgp_cmd, | |
+ "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR | |
+ " [" BGP_SAFI_WITH_LABEL_CMD_STR | |
+ "]]\ | |
<dampening <parameters>\ | |
|route-map WORD\ | |
|prefix-list WORD\ | |
@@ -10663,28 +10650,24 @@ DEFUN (show_ip_bgp, | |
|A.B.C.D/M longer-prefixes\ | |
|X:X::X:X/M longer-prefixes\ | |
>", | |
- SHOW_STR | |
- IP_STR | |
- BGP_STR | |
- BGP_INSTANCE_HELP_STR | |
- BGP_AFI_HELP_STR | |
- BGP_SAFI_WITH_LABEL_HELP_STR | |
- "Display detailed information about dampening\n" | |
- "Display detail of configured dampening parameters\n" | |
- "Display routes matching the route-map\n" | |
- "A route-map to match on\n" | |
- "Display routes conforming to the prefix-list\n" | |
- "Prefix-list name\n" | |
- "Display routes conforming to the filter-list\n" | |
- "Regular expression access list name\n" | |
- "Display routes matching the community-list\n" | |
- "community-list number\n" | |
- "community-list name\n" | |
- "Exact match of the communities\n" | |
- "IPv4 prefix\n" | |
- "Display route and more specific routes\n" | |
- "IPv6 prefix\n" | |
- "Display route and more specific routes\n") | |
+ SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR | |
+ BGP_SAFI_WITH_LABEL_HELP_STR | |
+ "Display detailed information about dampening\n" | |
+ "Display detail of configured dampening parameters\n" | |
+ "Display routes matching the route-map\n" | |
+ "A route-map to match on\n" | |
+ "Display routes conforming to the prefix-list\n" | |
+ "Prefix-list name\n" | |
+ "Display routes conforming to the filter-list\n" | |
+ "Regular expression access list name\n" | |
+ "Display routes matching the community-list\n" | |
+ "community-list number\n" | |
+ "community-list name\n" | |
+ "Exact match of the communities\n" | |
+ "IPv4 prefix\n" | |
+ "Display route and more specific routes\n" | |
+ "IPv6 prefix\n" | |
+ "Display route and more specific routes\n") | |
{ | |
afi_t afi = AFI_IP6; | |
safi_t safi = SAFI_UNICAST; | |
@@ -11119,34 +11102,33 @@ enum bgp_stats { | |
BGP_STATS_MAX, | |
}; | |
-#define TABLE_STATS_IDX_VTY 0 | |
+#define TABLE_STATS_IDX_VTY 0 | |
#define TABLE_STATS_IDX_JSON 1 | |
static const char *table_stats_strs[][2] = { | |
[BGP_STATS_PREFIXES] = {"Total Prefixes", "totalPrefixes"}, | |
[BGP_STATS_TOTPLEN] = {"Average prefix length", "averagePrefixLength"}, | |
[BGP_STATS_RIB] = {"Total Advertisements", "totalAdvertisements"}, | |
- [BGP_STATS_UNAGGREGATEABLE] = | |
- {"Unaggregateable prefixes", "unaggregateablePrefixes"}, | |
- [BGP_STATS_MAX_AGGREGATEABLE] = | |
- {"Maximum aggregateable prefixes", "maximumAggregateablePrefixes"}, | |
- [BGP_STATS_AGGREGATES] = | |
- {"BGP Aggregate advertisements", "bgpAggregateAdvertisements"}, | |
+ [BGP_STATS_UNAGGREGATEABLE] = {"Unaggregateable prefixes", | |
+ "unaggregateablePrefixes"}, | |
+ [BGP_STATS_MAX_AGGREGATEABLE] = {"Maximum aggregateable prefixes", | |
+ "maximumAggregateablePrefixes"}, | |
+ [BGP_STATS_AGGREGATES] = {"BGP Aggregate advertisements", | |
+ "bgpAggregateAdvertisements"}, | |
[BGP_STATS_SPACE] = {"Address space advertised", | |
"addressSpaceAdvertised"}, | |
- [BGP_STATS_ASPATH_COUNT] = | |
- {"Advertisements with paths", "advertisementsWithPaths"}, | |
- [BGP_STATS_ASPATH_MAXHOPS] = | |
- {"Longest AS-Path (hops)", "longestAsPath"}, | |
- [BGP_STATS_ASPATH_MAXSIZE] = | |
- {"Largest AS-Path (bytes)","largestAsPath"}, | |
- [BGP_STATS_ASPATH_TOTHOPS] = | |
- {"Average AS-Path length (hops)", "averageAsPathLengthHops"}, | |
- [BGP_STATS_ASPATH_TOTSIZE] = | |
- {"Average AS-Path size (bytes)", "averageAsPathSizeBytes"}, | |
- [BGP_STATS_ASN_HIGHEST] = {"Highest public ASN","highestPublicAsn"}, | |
- [BGP_STATS_MAX] = {NULL, NULL} | |
-}; | |
+ [BGP_STATS_ASPATH_COUNT] = {"Advertisements with paths", | |
+ "advertisementsWithPaths"}, | |
+ [BGP_STATS_ASPATH_MAXHOPS] = {"Longest AS-Path (hops)", | |
+ "longestAsPath"}, | |
+ [BGP_STATS_ASPATH_MAXSIZE] = {"Largest AS-Path (bytes)", | |
+ "largestAsPath"}, | |
+ [BGP_STATS_ASPATH_TOTHOPS] = {"Average AS-Path length (hops)", | |
+ "averageAsPathLengthHops"}, | |
+ [BGP_STATS_ASPATH_TOTSIZE] = {"Average AS-Path size (bytes)", | |
+ "averageAsPathSizeBytes"}, | |
+ [BGP_STATS_ASN_HIGHEST] = {"Highest public ASN", "highestPublicAsn"}, | |
+ [BGP_STATS_MAX] = {NULL, NULL}}; | |
struct bgp_table_stats { | |
struct bgp_table *table; | |
@@ -11268,9 +11250,9 @@ static int bgp_table_stats_walker(struct thread *t) | |
ts->counts[BGP_STATS_MAXBITLEN] = space; | |
for (rn = top; rn; rn = bgp_route_next(rn)) { | |
- if (ts->table->safi == SAFI_MPLS_VPN || | |
- ts->table->safi == SAFI_ENCAP || | |
- ts->table->safi == SAFI_EVPN) { | |
+ if (ts->table->safi == SAFI_MPLS_VPN | |
+ || ts->table->safi == SAFI_ENCAP | |
+ || ts->table->safi == SAFI_EVPN) { | |
struct bgp_table *table; | |
table = bgp_node_get_bgp_table_info(rn); | |
@@ -11305,14 +11287,13 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, | |
char warning_msg[100]; | |
snprintf(warning_msg, sizeof(warning_msg), | |
- "%% No RIB exist's for the AFI(%d)/SAFI(%d)", | |
- afi, safi); | |
+ "%% No RIB exist's for the AFI(%d)/SAFI(%d)", afi, | |
+ safi); | |
if (!json) | |
vty_out(vty, "%s\n", warning_msg); | |
else | |
- json_object_string_add(json, "warning", | |
- warning_msg); | |
+ json_object_string_add(json, "warning", warning_msg); | |
ret = CMD_WARNING; | |
goto end_table_stats; | |
@@ -11331,8 +11312,8 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, | |
thread_execute(bm->master, bgp_table_stats_walker, &ts, 0); | |
for (i = 0; i < BGP_STATS_MAX; i++) { | |
- if ((!json && !table_stats_strs[i][TABLE_STATS_IDX_VTY]) || | |
- (json && !table_stats_strs[i][TABLE_STATS_IDX_JSON])) | |
+ if ((!json && !table_stats_strs[i][TABLE_STATS_IDX_VTY]) | |
+ || (json && !table_stats_strs[i][TABLE_STATS_IDX_JSON])) | |
continue; | |
switch (i) { | |
@@ -11348,111 +11329,132 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, | |
case BGP_STATS_ASPATH_TOTHOPS: | |
case BGP_STATS_ASPATH_TOTSIZE: | |
if (!json) { | |
- snprintf(temp_buf, sizeof(temp_buf), "%12.2f", | |
- ts.counts[i] ? (float)ts.counts[i] / | |
- (float)ts.counts[BGP_STATS_ASPATH_COUNT] | |
- : 0); | |
+ snprintf( | |
+ temp_buf, sizeof(temp_buf), "%12.2f", | |
+ ts.counts[i] | |
+ ? (float)ts.counts[i] | |
+ / (float)ts.counts | |
+ [BGP_STATS_ASPATH_COUNT] | |
+ : 0); | |
vty_out(vty, "%-30s: %s", | |
- table_stats_strs[i][TABLE_STATS_IDX_VTY], | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_VTY], | |
temp_buf); | |
} else | |
- json_object_double_add(json, | |
- table_stats_strs[i][TABLE_STATS_IDX_JSON], | |
- ts.counts[i] ? (double)ts.counts[i] / | |
- (double)ts.counts[BGP_STATS_ASPATH_COUNT] | |
- : 0); | |
+ json_object_double_add( | |
+ json, | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_JSON], | |
+ ts.counts[i] | |
+ ? (double)ts.counts[i] | |
+ / (double)ts.counts | |
+ [BGP_STATS_ASPATH_COUNT] | |
+ : 0); | |
break; | |
case BGP_STATS_TOTPLEN: | |
if (!json) { | |
- snprintf(temp_buf, sizeof(temp_buf), "%12.2f", | |
- ts.counts[i] ? (float)ts.counts[i] / | |
- (float)ts.counts[BGP_STATS_PREFIXES] | |
- : 0); | |
+ snprintf( | |
+ temp_buf, sizeof(temp_buf), "%12.2f", | |
+ ts.counts[i] | |
+ ? (float)ts.counts[i] | |
+ / (float)ts.counts | |
+ [BGP_STATS_PREFIXES] | |
+ : 0); | |
vty_out(vty, "%-30s: %s", | |
- table_stats_strs[i][TABLE_STATS_IDX_VTY], | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_VTY], | |
temp_buf); | |
} else | |
- json_object_double_add(json, | |
- table_stats_strs[i][TABLE_STATS_IDX_JSON], | |
- ts.counts[i] ? (double)ts.counts[i] / | |
- (double)ts.counts[BGP_STATS_PREFIXES] : 0); | |
+ json_object_double_add( | |
+ json, | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_JSON], | |
+ ts.counts[i] | |
+ ? (double)ts.counts[i] | |
+ / (double)ts.counts | |
+ [BGP_STATS_PREFIXES] | |
+ : 0); | |
break; | |
case BGP_STATS_SPACE: | |
if (!json) { | |
snprintf(temp_buf, sizeof(temp_buf), "%12g", | |
ts.total_space); | |
vty_out(vty, "%-30s: %s\n", | |
- table_stats_strs[i][TABLE_STATS_IDX_VTY], | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_VTY], | |
temp_buf); | |
} else | |
- json_object_double_add(json, | |
- table_stats_strs[i][TABLE_STATS_IDX_JSON], | |
- (double)ts.total_space); | |
+ json_object_double_add( | |
+ json, | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_JSON], | |
+ (double)ts.total_space); | |
if (afi == AFI_IP6) { | |
if (!json) { | |
snprintf(temp_buf, sizeof(temp_buf), | |
- "%12g", ts.total_space * | |
- pow(2.0, -128 + 32)); | |
+ "%12g", | |
+ ts.total_space | |
+ * pow(2.0, -128 + 32)); | |
vty_out(vty, "%30s: %s\n", | |
"/32 equivalent %s\n", | |
temp_buf); | |
} else | |
- json_object_double_add(json, | |
- "/32equivalent", | |
- (double)(ts.total_space * | |
- pow(2.0, -128 + 32))); | |
+ json_object_double_add( | |
+ json, "/32equivalent", | |
+ (double)(ts.total_space | |
+ * pow(2.0, | |
+ -128 + 32))); | |
if (!json) { | |
snprintf(temp_buf, sizeof(temp_buf), | |
- "%12g", ts.total_space * | |
- pow(2.0, -128 + 48)); | |
+ "%12g", | |
+ ts.total_space | |
+ * pow(2.0, -128 + 48)); | |
vty_out(vty, "%30s: %s\n", | |
"/48 equivalent %s\n", | |
temp_buf); | |
} else | |
- json_object_double_add(json, | |
- "/48equivalent", | |
- (double)(ts.total_space * | |
- pow(2.0, -128 + 48))); | |
+ json_object_double_add( | |
+ json, "/48equivalent", | |
+ (double)(ts.total_space | |
+ * pow(2.0, | |
+ -128 + 48))); | |
} else { | |
if (!json) { | |
snprintf(temp_buf, sizeof(temp_buf), | |
"%12.2f", | |
- ts.total_space * 100. * | |
- pow(2.0, -32)); | |
+ ts.total_space * 100. | |
+ * pow(2.0, -32)); | |
vty_out(vty, "%30s: %s\n", | |
- "% announced ", | |
- temp_buf); | |
+ "% announced ", temp_buf); | |
} else | |
- json_object_double_add(json, | |
- "%announced", | |
- (double)(ts.total_space * | |
- 100. * | |
- pow(2.0, -32))); | |
+ json_object_double_add( | |
+ json, "%announced", | |
+ (double)(ts.total_space * 100. | |
+ * pow(2.0, -32))); | |
if (!json) { | |
snprintf(temp_buf, sizeof(temp_buf), | |
"%12.2f", | |
- ts.total_space * | |
- pow(2.0, -32 + 8)); | |
+ ts.total_space | |
+ * pow(2.0, -32 + 8)); | |
vty_out(vty, "%30s: %s\n", | |
"/8 equivalent ", temp_buf); | |
} else | |
- json_object_double_add(json, | |
- "/8equivalent", | |
- (double)(ts.total_space * | |
- pow(2.0, -32 + 8))); | |
+ json_object_double_add( | |
+ json, "/8equivalent", | |
+ (double)(ts.total_space | |
+ * pow(2.0, -32 + 8))); | |
if (!json) { | |
snprintf(temp_buf, sizeof(temp_buf), | |
"%12.2f", | |
- ts.total_space * | |
- pow(2.0, -32 + 24)); | |
+ ts.total_space | |
+ * pow(2.0, -32 + 24)); | |
vty_out(vty, "%30s: %s\n", | |
- "/24 equivalent ", | |
- temp_buf); | |
+ "/24 equivalent ", temp_buf); | |
} else | |
- json_object_double_add(json, | |
- "/24equivalent", | |
- (double)(ts.total_space * | |
- pow(2.0, -32 + 24))); | |
+ json_object_double_add( | |
+ json, "/24equivalent", | |
+ (double)(ts.total_space | |
+ * pow(2.0, -32 + 24))); | |
} | |
break; | |
default: | |
@@ -11460,17 +11462,20 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, | |
snprintf(temp_buf, sizeof(temp_buf), "%12llu", | |
ts.counts[i]); | |
vty_out(vty, "%-30s: %s", | |
- table_stats_strs[i][TABLE_STATS_IDX_VTY], | |
- temp_buf); | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_VTY], | |
+ temp_buf); | |
} else | |
- json_object_int_add(json, | |
- table_stats_strs[i][TABLE_STATS_IDX_JSON], | |
- ts.counts[i]); | |
+ json_object_int_add( | |
+ json, | |
+ table_stats_strs[i] | |
+ [TABLE_STATS_IDX_JSON], | |
+ ts.counts[i]); | |
} | |
if (!json) | |
vty_out(vty, "\n"); | |
} | |
- end_table_stats: | |
+end_table_stats: | |
if (json) | |
json_object_array_add(json_array, json); | |
return ret; | |
diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h | |
index 3f06584cc..d6ca198d0 100644 | |
--- a/bgpd/bgp_vty.h | |
+++ b/bgpd/bgp_vty.h | |
@@ -175,9 +175,8 @@ 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); | |
+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); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment