bgpd: add "json" option to "show ip bgp ... dampening parameters"

Also:
* rename show_ip_bgp_cmd to show_ip_bgp_dampening_params_cmd;
* rename show_ip_bgp_json_cmd to show_ip_bgp_cmd.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2021-07-27 22:29:43 -03:00
parent 39c3c7364d
commit fe0f234d13
3 changed files with 66 additions and 33 deletions

View File

@ -653,21 +653,42 @@ const char *bgp_damp_reuse_time_vty(struct vty *vty, struct bgp_path_info *path,
} }
static int bgp_print_dampening_parameters(struct bgp *bgp, struct vty *vty, static int bgp_print_dampening_parameters(struct bgp *bgp, struct vty *vty,
afi_t afi, safi_t safi) afi_t afi, safi_t safi, bool use_json)
{ {
if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)) { if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)) {
vty_out(vty, "Half-life time: %lld min\n", struct bgp_damp_config *bdc = &damp[afi][safi];
(long long)damp[afi][safi].half_life / 60);
vty_out(vty, "Reuse penalty: %d\n", if (use_json) {
damp[afi][safi].reuse_limit); json_object *json = json_object_new_object();
vty_out(vty, "Suppress penalty: %d\n",
damp[afi][safi].suppress_value); json_object_int_add(json, "halfLifeSecs",
vty_out(vty, "Max suppress time: %lld min\n", bdc->half_life);
(long long)damp[afi][safi].max_suppress_time / 60); json_object_int_add(json, "reusePenalty",
vty_out(vty, "Max suppress penalty: %u\n", bdc->reuse_limit);
damp[afi][safi].ceiling); json_object_int_add(json, "suppressPenalty",
vty_out(vty, "\n"); bdc->suppress_value);
} else json_object_int_add(json, "maxSuppressTimeSecs",
bdc->max_suppress_time);
json_object_int_add(json, "maxSuppressPenalty",
bdc->ceiling);
vty_out(vty, "%s\n",
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
vty_out(vty, "Half-life time: %lld min\n",
(long long)bdc->half_life / 60);
vty_out(vty, "Reuse penalty: %d\n", bdc->reuse_limit);
vty_out(vty, "Suppress penalty: %d\n",
bdc->suppress_value);
vty_out(vty, "Max suppress time: %lld min\n",
(long long)bdc->max_suppress_time / 60);
vty_out(vty, "Max suppress penalty: %u\n",
bdc->ceiling);
vty_out(vty, "\n");
}
} else if (!use_json)
vty_out(vty, "dampening not enabled for %s\n", vty_out(vty, "dampening not enabled for %s\n",
get_afi_safi_str(afi, safi, false)); get_afi_safi_str(afi, safi, false));
@ -678,6 +699,8 @@ int bgp_show_dampening_parameters(struct vty *vty, afi_t afi, safi_t safi,
uint16_t show_flags) uint16_t show_flags)
{ {
struct bgp *bgp; struct bgp *bgp;
bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
bgp = bgp_get_default(); bgp = bgp_get_default();
if (bgp == NULL) { if (bgp == NULL) {
@ -686,7 +709,8 @@ int bgp_show_dampening_parameters(struct vty *vty, afi_t afi, safi_t safi,
} }
if (!CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_ALL)) if (!CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_ALL))
return bgp_print_dampening_parameters(bgp, vty, afi, safi); return bgp_print_dampening_parameters(bgp, vty, afi, safi,
use_json);
if (CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP) if (CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP)
|| CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6)) { || CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6)) {
@ -697,11 +721,12 @@ int bgp_show_dampening_parameters(struct vty *vty, afi_t afi, safi_t safi,
"Unknown")) "Unknown"))
continue; continue;
if (!CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON)) if (!use_json)
vty_out(vty, "\nFor address family: %s\n\n", vty_out(vty, "\nFor address family: %s\n\n",
get_afi_safi_str(afi, safi, false)); get_afi_safi_str(afi, safi, false));
bgp_print_dampening_parameters(bgp, vty, afi, safi); bgp_print_dampening_parameters(bgp, vty, afi, safi,
use_json);
} }
} else { } else {
FOREACH_AFI_SAFI (afi, safi) { FOREACH_AFI_SAFI (afi, safi) {
@ -709,11 +734,12 @@ int bgp_show_dampening_parameters(struct vty *vty, afi_t afi, safi_t safi,
"Unknown")) "Unknown"))
continue; continue;
if (!CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON)) if (!use_json)
vty_out(vty, "\nFor address family: %s\n", vty_out(vty, "\nFor address family: %s\n",
get_afi_safi_str(afi, safi, false)); get_afi_safi_str(afi, safi, false));
bgp_print_dampening_parameters(bgp, vty, afi, safi); bgp_print_dampening_parameters(bgp, vty, afi, safi,
use_json);
} }
} }
return CMD_SUCCESS; return CMD_SUCCESS;

View File

@ -11997,22 +11997,28 @@ DEFUN(show_ip_bgp_afi_safi_statistics, show_ip_bgp_afi_safi_statistics_cmd,
return ret; return ret;
} }
/* BGP route print out function without JSON */ DEFPY(show_ip_bgp_dampening_params, show_ip_bgp_dampening_params_cmd,
DEFPY(show_ip_bgp, 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
"]] [all$all] dampening parameters", "]] [all$all] dampening parameters [json]",
SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR BGP_SAFI_WITH_LABEL_HELP_STR
"Display the entries for all address families\n" "Display the entries for all address families\n"
"Display detailed information about dampening\n" "Display detailed information about dampening\n"
"Display detail of configured dampening parameters\n") "Display detail of configured dampening parameters\n"
JSON_STR)
{ {
afi_t afi = AFI_IP6; afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST; safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL; struct bgp *bgp = NULL;
int idx = 0; int idx = 0;
uint16_t show_flags = 0; uint16_t show_flags = 0;
bool uj = use_json(argc, argv);
if (uj) {
argc--;
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
}
/* [<ipv4|ipv6> [all]] */ /* [<ipv4|ipv6> [all]] */
if (all) { if (all) {
@ -12029,17 +12035,11 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd,
if (!idx) if (!idx)
return CMD_WARNING; return CMD_WARNING;
if (argv_find(argv, argc, "dampening", &idx)) { return bgp_show_dampening_parameters(vty, afi, safi, show_flags);
if (argv_find(argv, argc, "parameters", &idx))
return bgp_show_dampening_parameters(vty, afi, safi,
show_flags);
}
return CMD_WARNING;
} }
/* BGP route print out function with JSON */ /* BGP route print out function */
DEFPY(show_ip_bgp_json, show_ip_bgp_json_cmd, DEFPY(show_ip_bgp, 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
"]]\ "]]\
@ -15026,10 +15026,10 @@ void bgp_route_init(void)
install_element(BGP_IPV4L_NODE, &aggregate_addressv4_cmd); install_element(BGP_IPV4L_NODE, &aggregate_addressv4_cmd);
install_element(VIEW_NODE, &show_ip_bgp_instance_all_cmd); install_element(VIEW_NODE, &show_ip_bgp_instance_all_cmd);
install_element(VIEW_NODE, &show_ip_bgp_cmd);
install_element(VIEW_NODE, &show_ip_bgp_afi_safi_statistics_cmd); install_element(VIEW_NODE, &show_ip_bgp_afi_safi_statistics_cmd);
install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_statistics_cmd); install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_statistics_cmd);
install_element(VIEW_NODE, &show_ip_bgp_json_cmd); install_element(VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
install_element(VIEW_NODE, &show_ip_bgp_cmd);
install_element(VIEW_NODE, &show_ip_bgp_route_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_regexp_cmd);
install_element(VIEW_NODE, &show_ip_bgp_statistics_all_cmd); install_element(VIEW_NODE, &show_ip_bgp_statistics_all_cmd);

View File

@ -3553,6 +3553,13 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`.
Display flap statistics of routes of the selected afi and safi selected. Display flap statistics of routes of the selected afi and safi selected.
.. clicmd:: show bgp [afi] [safi] [all] dampening parameters [json]
Display details of configured dampening parameters of the selected afi and
safi.
If the ``json`` option is specified, output is displayed in JSON format.
.. clicmd:: show bgp [afi] [safi] [all] version (1-4294967295) [wide|json] .. clicmd:: show bgp [afi] [safi] [all] version (1-4294967295) [wide|json]
Display prefixes with matching version numbers. The version number and Display prefixes with matching version numbers. The version number and