X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fbfd%2Fbfd_cli.c;h=a6953bd2687c91623ea88b879b843a24717172a2;hb=a316744bc5e003d0fa4c8aff82c619b300115f02;hp=a3736d98b3c717f5a54f15d9ea36a73f6b456b02;hpb=738844871220f853629504f61c248f0c9402dc77;p=vpp.git diff --git a/src/vnet/bfd/bfd_cli.c b/src/vnet/bfd/bfd_cli.c index a3736d98b3c..a6953bd2687 100644 --- a/src/vnet/bfd/bfd_cli.c +++ b/src/vnet/bfd/bfd_cli.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -28,7 +29,7 @@ static u8 * format_bfd_session_cli (u8 * s, va_list * args) { - bfd_main_t *bm = va_arg (*args, bfd_main_t *); + vlib_main_t *vm = va_arg (*args, vlib_main_t *); bfd_session_t *bs = va_arg (*args, bfd_session_t *); switch (bs->transport) { @@ -51,28 +52,67 @@ format_bfd_session_cli (u8 * s, va_list * args) bfd_diag_code_string (bs->remote_diag)); s = format (s, "%10s %-32s %20u %20u\n", "", "Detect multiplier", bs->local_detect_mult, bs->remote_detect_mult); - s = format (s, "%10s %-32s %20u %20u\n", "", + s = format (s, "%10s %-32s %20u %20llu\n", "", "Required Min Rx Interval (usec)", bs->config_required_min_rx_usec, bs->remote_min_rx_usec); s = format (s, "%10s %-32s %20u %20u\n", "", "Desired Min Tx Interval (usec)", - bs->config_desired_min_tx_usec, bfd_clocks_to_usec (bm, - bs->remote_desired_min_tx_clocks)); + bs->config_desired_min_tx_usec, + bfd_nsec_to_usec (bs->remote_desired_min_tx_nsec)); s = format (s, "%10s %-32s %20u\n", "", "Transmit interval", - bfd_clocks_to_usec (bm, bs->transmit_interval_clocks)); - s = - format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no", - bs->remote_demand ? "yes" : "no"); + bfd_nsec_to_usec (bs->transmit_interval_nsec)); + u64 now = clib_cpu_time_now (); + u8 *tmp = NULL; + if (bs->last_tx_nsec > 0) + { + tmp = format (tmp, "%.2fs ago", (now - bs->last_tx_nsec) * + vm->clib_time.seconds_per_clock); + s = format (s, "%10s %-32s %20v\n", "", "Last control frame tx", tmp); + vec_reset_length (tmp); + } + if (bs->last_rx_nsec) + { + tmp = format (tmp, "%.2fs ago", (now - bs->last_rx_nsec) * + vm->clib_time.seconds_per_clock); + s = format (s, "%10s %-32s %20v\n", "", "Last control frame rx", tmp); + vec_reset_length (tmp); + } s = - format (s, "%10s %-32s %20s\n", "", "Poll state", - bfd_poll_state_string (bs->poll_state)); + format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)", + 1, bs->remote_min_echo_rx_usec); + if (bs->echo) + { + s = + format (s, "%10s %-32s %20u\n", "", "Echo transmit interval", + bfd_nsec_to_usec (bs->echo_transmit_interval_nsec)); + tmp = + format (tmp, "%.2fs ago", + (now - + bs->echo_last_tx_nsec) * vm->clib_time.seconds_per_clock); + s = format (s, "%10s %-32s %20v\n", "", "Last echo frame tx", tmp); + vec_reset_length (tmp); + tmp = format (tmp, "%.6fs", + (bs->echo_last_rx_nsec - bs->echo_last_tx_nsec) * + vm->clib_time.seconds_per_clock); + s = + format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time", + tmp); + } + vec_free (tmp); + tmp = NULL; + s = format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no", + bs->remote_demand ? "yes" : "no"); + s = format (s, "%10s %-32s %20s\n", "", "Poll state", + bfd_poll_state_string (bs->poll_state)); if (bs->auth.curr_key) { s = format (s, "%10s %-32s %20u\n", "", "Authentication config key ID", bs->auth.curr_key->conf_key_id); s = format (s, "%10s %-32s %20u\n", "", "Authentication BFD key ID", bs->auth.curr_bfd_key_id); + s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number", + bs->auth.local_seq_number, bs->auth.remote_seq_number); } return s; } @@ -83,8 +123,13 @@ show_bfd (vlib_main_t * vm, unformat_input_t * input, { bfd_main_t *bm = &bfd_main; bfd_session_t *bs = NULL; + unformat_input_t _line_input, *line_input = &_line_input; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; - if (unformat (input, "keys")) + if (unformat (line_input, "keys")) { bfd_auth_key_t *key = NULL; u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID", @@ -96,23 +141,25 @@ show_bfd (vlib_main_t * vm, unformat_input_t * input, }); /* *INDENT-ON* */ vlib_cli_output (vm, "%v\n", s); + vec_free (s); vlib_cli_output (vm, "Number of configured BFD keys: %lu\n", (u64) pool_elts (bm->auth_keys)); } - else if (unformat (input, "sessions")) + else if (unformat (line_input, "sessions")) { u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property", "Local value", "Remote value"); /* *INDENT-OFF* */ - pool_foreach (bs, bm->sessions, - { s = format (s, "%U", format_bfd_session_cli, bm, bs); }); + pool_foreach (bs, bm->sessions, { + s = format (s, "%U", format_bfd_session_cli, vm, bs); + }); /* *INDENT-ON* */ vlib_cli_output (vm, "%v", s); vec_free (s); vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n", (u64) pool_elts (bm->sessions)); } - else if (unformat (input, "echo-source")) + else if (unformat (line_input, "echo-source")) { int is_set; u32 sw_if_index; @@ -125,7 +172,7 @@ show_bfd (vlib_main_t * vm, unformat_input_t * input, if (is_set) { vnet_sw_interface_t *sw_if = - vnet_get_sw_interface_safe (&vnet_main, sw_if_index); + vnet_get_sw_interface_or_null (&vnet_main, sw_if_index); vnet_hw_interface_t *hw_if = vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index); u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name); @@ -173,22 +220,6 @@ VLIB_CLI_COMMAND (show_bfd_command, static) = { }; /* *INDENT-ON* */ -static u8 * -format_vnet_api_errno (u8 * s, va_list * args) -{ - vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t); -#define _(a, b, c) \ - case b: \ - s = format (s, "%s", c); \ - break; - switch (api_error) - { - foreach_vnet_api_error default:s = format (s, "UNKNOWN"); - break; - } - return s; -} - static clib_error_t * bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input, CLIB_UNUSED (vlib_cli_command_t * lmd)) @@ -199,16 +230,21 @@ bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input, u8 *vec_auth_type = NULL; bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved; u8 *secret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; static const u8 keyed_sha1[] = "keyed-sha1"; static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1"; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "conf-key-id %u", &key_id)) + if (unformat (line_input, "conf-key-id %u", &key_id)) { have_key_id = 1; } - else if (unformat (input, "type %U", unformat_token, "a-zA-Z0-9-", + else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-", &vec_auth_type)) { if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 && @@ -230,14 +266,15 @@ bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input, goto out; } } - else if (unformat (input, "secret %U", unformat_hex_string, &secret)) + else + if (unformat (line_input, "secret %U", unformat_hex_string, &secret)) { /* nothing to do here */ } else { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } } @@ -290,13 +327,18 @@ bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input, { clib_error_t *ret = NULL; u32 key_id = 0; + unformat_input_t _line_input, *line_input = &_line_input; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (!unformat (input, "conf-key-id %u", &key_id)) + if (!unformat (line_input, "conf-key-id %u", &key_id)) { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } } @@ -340,16 +382,18 @@ static const unsigned optional = 0; t n; #define UNFORMAT(t, n, s, r, ...) \ - if (unformat (input, s " " __VA_ARGS__, &n)) \ + if (unformat (line_input, s " " __VA_ARGS__, &n)) \ { \ something_parsed = 1; \ have_##n = 1; \ } #define CHECK_MANDATORY(t, n, s, r, ...) \ +WARN_OFF(tautological-compare) \ if (mandatory == r && !have_##n) \ { \ - ret = clib_error_return (0, "Required parameter `%s' missing.", n); \ + WARN_ON(tautological-compare) \ + ret = clib_error_return (0, "Required parameter `%s' missing.", s); \ goto out; \ } @@ -358,6 +402,7 @@ bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input, CLIB_UNUSED (vlib_cli_command_t * lmd)) { clib_error_t *ret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_add_cli_param(F) \ F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ @@ -373,7 +418,11 @@ bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input, foreach_bfd_cli_udp_session_add_cli_param (DECLARE); - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { int something_parsed = 0; foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT); @@ -381,7 +430,7 @@ bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input, if (!something_parsed) { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } } @@ -451,6 +500,7 @@ bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input, CLIB_UNUSED (vlib_cli_command_t * lmd)) { clib_error_t *ret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_mod_cli_param(F) \ F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ @@ -464,7 +514,11 @@ bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input, foreach_bfd_cli_udp_session_mod_cli_param (DECLARE); - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { int something_parsed = 0; foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT); @@ -472,7 +526,7 @@ bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input, if (!something_parsed) { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } } @@ -521,6 +575,7 @@ bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input, CLIB_UNUSED (vlib_cli_command_t * lmd)) { clib_error_t *ret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_del_cli_param(F) \ F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ @@ -531,7 +586,11 @@ bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input, foreach_bfd_cli_udp_session_del_cli_param (DECLARE); - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { int something_parsed = 0; foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT); @@ -539,7 +598,7 @@ bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input, if (!something_parsed) { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } } @@ -577,6 +636,7 @@ bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input, CLIB_UNUSED (vlib_cli_command_t * lmd)) { clib_error_t *ret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \ F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ @@ -589,7 +649,11 @@ bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input, foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE); - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { int something_parsed = 0; foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT); @@ -597,7 +661,7 @@ bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input, if (!something_parsed) { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } } @@ -622,8 +686,9 @@ bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input, ADMIN_STR, admin_up_down_token); goto out; } - vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr, - &peer_addr, admin_up_down); + vnet_api_error_t rv = + bfd_udp_session_set_flags (vm, sw_if_index, &local_addr, + &peer_addr, admin_up_down); if (rv) { ret = @@ -650,10 +715,12 @@ VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = { /* *INDENT-ON* */ static clib_error_t * -bfd_cli_udp_session_auth_activate (vlib_main_t * vm, unformat_input_t * input, +bfd_cli_udp_session_auth_activate (vlib_main_t * vm, + unformat_input_t * input, CLIB_UNUSED (vlib_cli_command_t * lmd)) { clib_error_t *ret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \ F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ @@ -667,7 +734,11 @@ bfd_cli_udp_session_auth_activate (vlib_main_t * vm, unformat_input_t * input, foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE); - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { int something_parsed = 0; foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT); @@ -675,7 +746,7 @@ bfd_cli_udp_session_auth_activate (vlib_main_t * vm, unformat_input_t * input, if (!something_parsed) { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } } @@ -737,7 +808,7 @@ VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = { " peer-addr " " conf-key-id " " bfd-key-id " - " [ delayed ]", + " [ delayed ]", .function = bfd_cli_udp_session_auth_activate, }; @@ -746,6 +817,7 @@ bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED (vlib_cli_command_t *lmd)) { clib_error_t *ret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \ F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ unformat_vnet_sw_interface, &vnet_main) \ @@ -757,7 +829,11 @@ bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input, foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE); - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { int something_parsed = 0; foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT); @@ -815,7 +891,7 @@ VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = { " interface " " local-addr " " peer-addr " - "[ delayed ]", + "[ delayed ]", .function = bfd_cli_udp_session_auth_deactivate, }; /* *INDENT-ON* */ @@ -825,13 +901,18 @@ bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input, CLIB_UNUSED (vlib_cli_command_t * lmd)) { clib_error_t *ret = NULL; + unformat_input_t _line_input, *line_input = &_line_input; #define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \ F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \ unformat_vnet_sw_interface, &vnet_main) foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE); - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { int something_parsed = 0; foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT); @@ -839,7 +920,7 @@ bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input, if (!something_parsed) { ret = clib_error_return (0, "Unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); goto out; } }