bgpd: take into account code style recommendations.

take into account polychaeta tips ono code style.
also, take into account miscellaneous code style recommandations like
braces usage.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2020-03-11 08:58:51 +01:00
parent 1471864374
commit 9ab0cf5830
2 changed files with 198 additions and 184 deletions

View File

@ -10555,15 +10555,10 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi, struct json_object *json); safi_t safi, struct json_object *json);
DEFUN (show_ip_bgp_statistics_all, DEFUN(show_ip_bgp_statistics_all, show_ip_bgp_statistics_all_cmd,
show_ip_bgp_statistics_all_cmd, "show [ip] bgp [<view|vrf> VIEWVRFNAME] statistics-all [json]",
"show [ip] bgp [<view|vrf> VIEWVRFNAME] statistics-all [json]", SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
SHOW_STR "Display number of prefixes for all afi/safi\n" JSON_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); bool uj = use_json(argc, argv);
struct bgp *bgp = NULL; struct bgp *bgp = NULL;
@ -10575,43 +10570,38 @@ DEFUN (show_ip_bgp_statistics_all,
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi, bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false); &bgp, false);
if (!idx) if (!bgp)
return CMD_WARNING; return CMD_WARNING;
if (uj) if (uj)
json_all = json_object_new_object(); json_all = json_object_new_object();
for (afi = AFI_IP; afi < AFI_MAX; afi++) { FOREACH_AFI_SAFI (afi, safi) {
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { /*
/* * So limit output to those afi/safi pairs that
* So limit output to those afi/safi * actually have something interesting in them
* pairs that */
* actualy have something interesting in if (strmatch(get_afi_safi_str(afi, safi, true),
* them "Unknown")) {
*/ continue;
if (strmatch(get_afi_safi_str(afi, safi, true),
"Unknown")) {
continue;
}
if (uj)
json_afi_safi = json_object_new_array();
else
json_afi_safi = NULL;
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);
} }
if (uj) {
json_afi_safi = json_object_new_array();
json_object_object_add(
json_all,
get_afi_safi_str(afi, safi, true),
json_afi_safi);
} else {
json_afi_safi = NULL;
}
bgp_table_stats(vty, bgp, afi, safi, json_afi_safi);
} }
if (uj) { if (uj) {
vty_out(vty, "%s", json_object_to_json_string_ext( vty_out(vty, "%s",
json_all, JSON_C_TO_STRING_PRETTY)); json_object_to_json_string_ext(
json_all, JSON_C_TO_STRING_PRETTY));
json_object_free(json_all); json_object_free(json_all);
} }
@ -10621,7 +10611,7 @@ DEFUN (show_ip_bgp_statistics_all,
/* BGP route print out function without JSON */ /* BGP route print out function without JSON */
DEFUN (show_ip_bgp_l2vpn_evpn_statistics, DEFUN (show_ip_bgp_l2vpn_evpn_statistics,
show_ip_bgp_l2vpn_evpn_statistics_cmd, show_ip_bgp_l2vpn_evpn_statistics_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] [l2vpn [evpn]] statistics [json]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] l2vpn evpn statistics [json]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -10631,8 +10621,8 @@ DEFUN (show_ip_bgp_l2vpn_evpn_statistics,
"BGP RIB advertisement statistics\n" "BGP RIB advertisement statistics\n"
JSON_STR) JSON_STR)
{ {
afi_t afi = AFI_L2VPN; afi_t afi;
safi_t safi = SAFI_EVPN; safi_t safi;
struct bgp *bgp = NULL; struct bgp *bgp = NULL;
int idx = 0, ret; int idx = 0, ret;
bool uj = use_json(argc, argv); bool uj = use_json(argc, argv);
@ -10662,21 +10652,17 @@ DEFUN (show_ip_bgp_l2vpn_evpn_statistics,
} }
/* BGP route print out function without JSON */ /* BGP route print out function without JSON */
DEFUN (show_ip_bgp_afi_safi_statistics, DEFUN(show_ip_bgp_afi_safi_statistics, show_ip_bgp_afi_safi_statistics_cmd,
show_ip_bgp_afi_safi_statistics_cmd, "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]\ " [" BGP_SAFI_WITH_LABEL_CMD_STR
"]]\
statistics [json]", statistics [json]",
SHOW_STR SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
IP_STR BGP_SAFI_WITH_LABEL_HELP_STR
BGP_STR "BGP RIB advertisement statistics\n" JSON_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; afi_t afi;
safi_t safi = SAFI_UNICAST; safi_t safi;
struct bgp *bgp = NULL; struct bgp *bgp = NULL;
int idx = 0, ret; int idx = 0, ret;
bool uj = use_json(argc, argv); bool uj = use_json(argc, argv);
@ -10698,18 +10684,19 @@ DEFUN (show_ip_bgp_afi_safi_statistics,
json = json_object_new_object(); json = json_object_new_object();
json_object_object_add(json, get_afi_safi_str(afi, safi, true), json_object_object_add(json, get_afi_safi_str(afi, safi, true),
json_afi_safi); json_afi_safi);
vty_out(vty, "%s", json_object_to_json_string_ext( vty_out(vty, "%s",
json, JSON_C_TO_STRING_PRETTY)); json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json); json_object_free(json);
} }
return ret; return ret;
} }
/* BGP route print out function without JSON */ /* BGP route print out function without JSON */
DEFUN (show_ip_bgp, DEFUN(show_ip_bgp, show_ip_bgp_cmd,
show_ip_bgp_cmd, "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]\ " [" BGP_SAFI_WITH_LABEL_CMD_STR
"]]\
<dampening <parameters>\ <dampening <parameters>\
|route-map WORD\ |route-map WORD\
|prefix-list WORD\ |prefix-list WORD\
@ -10718,28 +10705,24 @@ DEFUN (show_ip_bgp,
|A.B.C.D/M longer-prefixes\ |A.B.C.D/M longer-prefixes\
|X:X::X:X/M longer-prefixes\ |X:X::X:X/M longer-prefixes\
>", >",
SHOW_STR SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
IP_STR BGP_SAFI_WITH_LABEL_HELP_STR
BGP_STR "Display detailed information about dampening\n"
BGP_INSTANCE_HELP_STR "Display detail of configured dampening parameters\n"
BGP_AFI_HELP_STR "Display routes matching the route-map\n"
BGP_SAFI_WITH_LABEL_HELP_STR "A route-map to match on\n"
"Display detailed information about dampening\n" "Display routes conforming to the prefix-list\n"
"Display detail of configured dampening parameters\n" "Prefix-list name\n"
"Display routes matching the route-map\n" "Display routes conforming to the filter-list\n"
"A route-map to match on\n" "Regular expression access list name\n"
"Display routes conforming to the prefix-list\n" "Display routes matching the community-list\n"
"Prefix-list name\n" "community-list number\n"
"Display routes conforming to the filter-list\n" "community-list name\n"
"Regular expression access list name\n" "Exact match of the communities\n"
"Display routes matching the community-list\n" "IPv4 prefix\n"
"community-list number\n" "Display route and more specific routes\n"
"community-list name\n" "IPv6 prefix\n"
"Exact match of the communities\n" "Display route and more specific routes\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; afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST; safi_t safi = SAFI_UNICAST;
@ -11174,32 +11157,32 @@ enum bgp_stats {
BGP_STATS_MAX, BGP_STATS_MAX,
}; };
#define TABLE_STATS_IDX_VTY 0 #define TABLE_STATS_IDX_VTY 0
#define TABLE_STATS_IDX_JSON 1 #define TABLE_STATS_IDX_JSON 1
static const char *table_stats_strs[][2] = { static const char *table_stats_strs[][2] = {
[BGP_STATS_PREFIXES] = {"Total Prefixes", "totalPrefixes"}, [BGP_STATS_PREFIXES] = {"Total Prefixes", "totalPrefixes"},
[BGP_STATS_TOTPLEN] = {"Average prefix length", "averagePrefixLength"}, [BGP_STATS_TOTPLEN] = {"Average prefix length", "averagePrefixLength"},
[BGP_STATS_RIB] = {"Total Advertisements", "totalAdvertisements"}, [BGP_STATS_RIB] = {"Total Advertisements", "totalAdvertisements"},
[BGP_STATS_UNAGGREGATEABLE] = [BGP_STATS_UNAGGREGATEABLE] = {"Unaggregateable prefixes",
{"Unaggregateable prefixes", "unaggregateablePrefixes"}, "unaggregateablePrefixes"},
[BGP_STATS_MAX_AGGREGATEABLE] = [BGP_STATS_MAX_AGGREGATEABLE] = {"Maximum aggregateable prefixes",
{"Maximum aggregateable prefixes", "maximumAggregateablePrefixes"}, "maximumAggregateablePrefixes"},
[BGP_STATS_AGGREGATES] = [BGP_STATS_AGGREGATES] = {"BGP Aggregate advertisements",
{"BGP Aggregate advertisements", "bgpAggregateAdvertisements"}, "bgpAggregateAdvertisements"},
[BGP_STATS_SPACE] = {"Address space advertised", [BGP_STATS_SPACE] = {"Address space advertised",
"addressSpaceAdvertised"}, "addressSpaceAdvertised"},
[BGP_STATS_ASPATH_COUNT] = [BGP_STATS_ASPATH_COUNT] = {"Advertisements with paths",
{"Advertisements with paths", "advertisementsWithPaths"}, "advertisementsWithPaths"},
[BGP_STATS_ASPATH_MAXHOPS] = [BGP_STATS_ASPATH_MAXHOPS] = {"Longest AS-Path (hops)",
{"Longest AS-Path (hops)", "longestAsPath"}, "longestAsPath"},
[BGP_STATS_ASPATH_MAXSIZE] = [BGP_STATS_ASPATH_MAXSIZE] = {"Largest AS-Path (bytes)",
{"Largest AS-Path (bytes)","largestAsPath"}, "largestAsPath"},
[BGP_STATS_ASPATH_TOTHOPS] = [BGP_STATS_ASPATH_TOTHOPS] = {"Average AS-Path length (hops)",
{"Average AS-Path length (hops)", "averageAsPathLengthHops"}, "averageAsPathLengthHops"},
[BGP_STATS_ASPATH_TOTSIZE] = [BGP_STATS_ASPATH_TOTSIZE] = {"Average AS-Path size (bytes)",
{"Average AS-Path size (bytes)", "averageAsPathSizeBytes"}, "averageAsPathSizeBytes"},
[BGP_STATS_ASN_HIGHEST] = {"Highest public ASN","highestPublicAsn"}, [BGP_STATS_ASN_HIGHEST] = {"Highest public ASN", "highestPublicAsn"},
[BGP_STATS_MAX] = {NULL, NULL} [BGP_STATS_MAX] = {NULL, NULL}
}; };
@ -11325,9 +11308,9 @@ static int bgp_table_stats_walker(struct thread *t)
ts->counts[BGP_STATS_MAXBITLEN] = space; ts->counts[BGP_STATS_MAXBITLEN] = space;
for (rn = top; rn; rn = bgp_route_next(rn)) { for (rn = top; rn; rn = bgp_route_next(rn)) {
if (ts->table->safi == SAFI_MPLS_VPN || if (ts->table->safi == SAFI_MPLS_VPN
ts->table->safi == SAFI_ENCAP || || ts->table->safi == SAFI_ENCAP
ts->table->safi == SAFI_EVPN) { || ts->table->safi == SAFI_EVPN) {
struct bgp_table *table; struct bgp_table *table;
table = bgp_node_get_bgp_table_info(rn); table = bgp_node_get_bgp_table_info(rn);
@ -11362,14 +11345,13 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
char warning_msg[50]; char warning_msg[50];
snprintf(warning_msg, sizeof(warning_msg), snprintf(warning_msg, sizeof(warning_msg),
"%% No RIB exist's for the AFI(%d)/SAFI(%d)", "%% No RIB exist's for the AFI(%d)/SAFI(%d)", afi,
afi, safi); safi);
if (!json) if (!json)
vty_out(vty, "%s\n", warning_msg); vty_out(vty, "%s\n", warning_msg);
else else
json_object_string_add(json, "warning", json_object_string_add(json, "warning", warning_msg);
warning_msg);
ret = CMD_WARNING; ret = CMD_WARNING;
goto end_table_stats; goto end_table_stats;
@ -11388,8 +11370,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); thread_execute(bm->master, bgp_table_stats_walker, &ts, 0);
for (i = 0; i < BGP_STATS_MAX; i++) { for (i = 0; i < BGP_STATS_MAX; i++) {
if ((!json && !table_stats_strs[i][TABLE_STATS_IDX_VTY]) || if ((!json && !table_stats_strs[i][TABLE_STATS_IDX_VTY])
(json && !table_stats_strs[i][TABLE_STATS_IDX_JSON])) || (json && !table_stats_strs[i][TABLE_STATS_IDX_JSON]))
continue; continue;
switch (i) { switch (i) {
@ -11405,111 +11387,140 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
case BGP_STATS_ASPATH_TOTHOPS: case BGP_STATS_ASPATH_TOTHOPS:
case BGP_STATS_ASPATH_TOTSIZE: case BGP_STATS_ASPATH_TOTSIZE:
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), "%12.2f", snprintf(
ts.counts[i] ? (float)ts.counts[i] / temp_buf, sizeof(temp_buf), "%12.2f",
(float)ts.counts[BGP_STATS_ASPATH_COUNT] ts.counts[i]
: 0); ? (float)ts.counts[i]
/ (float)ts.counts
[BGP_STATS_ASPATH_COUNT]
: 0);
vty_out(vty, "%-30s: %s", vty_out(vty, "%-30s: %s",
table_stats_strs[i][TABLE_STATS_IDX_VTY], table_stats_strs[i]
[TABLE_STATS_IDX_VTY],
temp_buf); temp_buf);
} else } else {
json_object_double_add(json, json_object_double_add(
table_stats_strs[i][TABLE_STATS_IDX_JSON], json,
ts.counts[i] ? (double)ts.counts[i] / table_stats_strs[i]
(double)ts.counts[BGP_STATS_ASPATH_COUNT] [TABLE_STATS_IDX_JSON],
: 0); ts.counts[i]
? (double)ts.counts[i]
/ (double)ts.counts
[BGP_STATS_ASPATH_COUNT]
: 0);
}
break; break;
case BGP_STATS_TOTPLEN: case BGP_STATS_TOTPLEN:
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), "%12.2f", snprintf(
ts.counts[i] ? (float)ts.counts[i] / temp_buf, sizeof(temp_buf), "%12.2f",
(float)ts.counts[BGP_STATS_PREFIXES] ts.counts[i]
: 0); ? (float)ts.counts[i]
/ (float)ts.counts
[BGP_STATS_PREFIXES]
: 0);
vty_out(vty, "%-30s: %s", vty_out(vty, "%-30s: %s",
table_stats_strs[i][TABLE_STATS_IDX_VTY], table_stats_strs[i]
[TABLE_STATS_IDX_VTY],
temp_buf); temp_buf);
} else } else {
json_object_double_add(json, json_object_double_add(
table_stats_strs[i][TABLE_STATS_IDX_JSON], json,
ts.counts[i] ? (double)ts.counts[i] / table_stats_strs[i]
(double)ts.counts[BGP_STATS_PREFIXES] : 0); [TABLE_STATS_IDX_JSON],
ts.counts[i]
? (double)ts.counts[i]
/ (double)ts.counts
[BGP_STATS_PREFIXES]
: 0);
}
break; break;
case BGP_STATS_SPACE: case BGP_STATS_SPACE:
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), "%12g", snprintf(temp_buf, sizeof(temp_buf), "%12g",
ts.total_space); ts.total_space);
vty_out(vty, "%-30s: %s\n", vty_out(vty, "%-30s: %s\n",
table_stats_strs[i][TABLE_STATS_IDX_VTY], table_stats_strs[i]
[TABLE_STATS_IDX_VTY],
temp_buf); temp_buf);
} else } else {
json_object_double_add(json, json_object_double_add(
table_stats_strs[i][TABLE_STATS_IDX_JSON], json,
(double)ts.total_space); table_stats_strs[i]
[TABLE_STATS_IDX_JSON],
(double)ts.total_space);
}
if (afi == AFI_IP6) { if (afi == AFI_IP6) {
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), snprintf(temp_buf, sizeof(temp_buf),
"%12g", ts.total_space * "%12g",
pow(2.0, -128 + 32)); ts.total_space
* pow(2.0, -128 + 32));
vty_out(vty, "%30s: %s\n", vty_out(vty, "%30s: %s\n",
"/32 equivalent %s\n", "/32 equivalent %s\n",
temp_buf); temp_buf);
} else } else {
json_object_double_add(json, json_object_double_add(
"/32equivalent", json, "/32equivalent",
(double)(ts.total_space * (double)(ts.total_space
pow(2.0, -128 + 32))); * pow(2.0,
-128 + 32)));
}
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), snprintf(temp_buf, sizeof(temp_buf),
"%12g", ts.total_space * "%12g",
pow(2.0, -128 + 48)); ts.total_space
* pow(2.0, -128 + 48));
vty_out(vty, "%30s: %s\n", vty_out(vty, "%30s: %s\n",
"/48 equivalent %s\n", "/48 equivalent %s\n",
temp_buf); temp_buf);
} else } else {
json_object_double_add(json, json_object_double_add(
"/48equivalent", json, "/48equivalent",
(double)(ts.total_space * (double)(ts.total_space
pow(2.0, -128 + 48))); * pow(2.0,
-128 + 48)));
}
} else { } else {
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), snprintf(temp_buf, sizeof(temp_buf),
"%12.2f", "%12.2f",
ts.total_space * 100. * ts.total_space * 100.
pow(2.0, -32)); * pow(2.0, -32));
vty_out(vty, "%30s: %s\n", vty_out(vty, "%30s: %s\n",
"% announced ", "% announced ", temp_buf);
temp_buf); } else {
} else json_object_double_add(
json_object_double_add(json, json, "%announced",
"%announced", (double)(ts.total_space * 100.
(double)(ts.total_space * * pow(2.0, -32)));
100. * }
pow(2.0, -32)));
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), snprintf(temp_buf, sizeof(temp_buf),
"%12.2f", "%12.2f",
ts.total_space * ts.total_space
pow(2.0, -32 + 8)); * pow(2.0, -32 + 8));
vty_out(vty, "%30s: %s\n", vty_out(vty, "%30s: %s\n",
"/8 equivalent ", temp_buf); "/8 equivalent ", temp_buf);
} else } else {
json_object_double_add(json, json_object_double_add(
"/8equivalent", json, "/8equivalent",
(double)(ts.total_space * (double)(ts.total_space
pow(2.0, -32 + 8))); * pow(2.0, -32 + 8)));
}
if (!json) { if (!json) {
snprintf(temp_buf, sizeof(temp_buf), snprintf(temp_buf, sizeof(temp_buf),
"%12.2f", "%12.2f",
ts.total_space * ts.total_space
pow(2.0, -32 + 24)); * pow(2.0, -32 + 24));
vty_out(vty, "%30s: %s\n", vty_out(vty, "%30s: %s\n",
"/24 equivalent ", "/24 equivalent ", temp_buf);
temp_buf); } else {
} else json_object_double_add(
json_object_double_add(json, json, "/24equivalent",
"/24equivalent", (double)(ts.total_space
(double)(ts.total_space * * pow(2.0, -32 + 24)));
pow(2.0, -32 + 24))); }
} }
break; break;
default: default:
@ -11517,17 +11528,21 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
snprintf(temp_buf, sizeof(temp_buf), "%12llu", snprintf(temp_buf, sizeof(temp_buf), "%12llu",
ts.counts[i]); ts.counts[i]);
vty_out(vty, "%-30s: %s", vty_out(vty, "%-30s: %s",
table_stats_strs[i][TABLE_STATS_IDX_VTY], table_stats_strs[i]
temp_buf); [TABLE_STATS_IDX_VTY],
} else temp_buf);
json_object_int_add(json, } else {
table_stats_strs[i][TABLE_STATS_IDX_JSON], json_object_int_add(
ts.counts[i]); json,
table_stats_strs[i]
[TABLE_STATS_IDX_JSON],
ts.counts[i]);
}
} }
if (!json) if (!json)
vty_out(vty, "\n"); vty_out(vty, "\n");
} }
end_table_stats: end_table_stats:
if (json) if (json)
json_object_array_add(json_array, json); json_object_array_add(json_array, json);
return ret; return ret;

View File

@ -175,9 +175,8 @@ extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
int argc, int *idx, afi_t *afi, int argc, int *idx, afi_t *afi,
safi_t *safi, struct bgp **bgp, safi_t *safi, struct bgp **bgp,
bool use_json); bool use_json);
int bgp_vty_find_and_parse_bgp(struct vty *vty, int bgp_vty_find_and_parse_bgp(struct vty *vty, struct cmd_token **argv,
struct cmd_token **argv, int argc, int argc, struct bgp **bgp, bool use_json);
struct bgp **bgp, bool use_json);
extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
safi_t safi, bool show_failed, bool use_json); safi_t safi, bool show_failed, bool use_json);