2 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * @brief BFD CLI implementation
20 #include <vlib/vlib.h>
22 #include <vppinfra/format.h>
23 #include <vppinfra/warnings.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/ip/format.h>
26 #include <vnet/bfd/bfd_api.h>
27 #include <vnet/bfd/bfd_main.h>
30 format_bfd_session_cli (u8 * s, va_list * args)
32 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
33 bfd_main_t *bm = va_arg (*args, bfd_main_t *);
34 bfd_session_t *bs = va_arg (*args, bfd_session_t *);
35 switch (bs->transport)
37 case BFD_TRANSPORT_UDP4:
38 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv4 address",
39 format_ip4_address, bs->udp.key.local_addr.ip4.as_u8,
40 format_ip4_address, bs->udp.key.peer_addr.ip4.as_u8);
42 case BFD_TRANSPORT_UDP6:
43 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv6 address",
44 format_ip6_address, &bs->udp.key.local_addr.ip6,
45 format_ip6_address, &bs->udp.key.peer_addr.ip6);
48 s = format (s, "%10s %-32s %20s %20s\n", "", "Session state",
49 bfd_state_string (bs->local_state),
50 bfd_state_string (bs->remote_state));
51 s = format (s, "%10s %-32s %20s %20s\n", "", "Diagnostic code",
52 bfd_diag_code_string (bs->local_diag),
53 bfd_diag_code_string (bs->remote_diag));
54 s = format (s, "%10s %-32s %20u %20u\n", "", "Detect multiplier",
55 bs->local_detect_mult, bs->remote_detect_mult);
56 s = format (s, "%10s %-32s %20u %20llu\n", "",
57 "Required Min Rx Interval (usec)",
58 bs->config_required_min_rx_usec, bs->remote_min_rx_usec);
59 s = format (s, "%10s %-32s %20u %20u\n", "",
60 "Desired Min Tx Interval (usec)",
61 bs->config_desired_min_tx_usec, bfd_clocks_to_usec (bm,
62 bs->remote_desired_min_tx_clocks));
64 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
65 bfd_clocks_to_usec (bm, bs->transmit_interval_clocks));
66 u64 now = clib_cpu_time_now ();
68 if (bs->last_tx_clocks > 0)
70 tmp = format (tmp, "%.2fs ago", (now - bs->last_tx_clocks) *
71 vm->clib_time.seconds_per_clock);
72 s = format (s, "%10s %-32s %20v\n", "", "Last control frame tx", tmp);
73 vec_reset_length (tmp);
75 if (bs->last_rx_clocks)
77 tmp = format (tmp, "%.2fs ago", (now - bs->last_rx_clocks) *
78 vm->clib_time.seconds_per_clock);
79 s = format (s, "%10s %-32s %20v\n", "", "Last control frame rx", tmp);
80 vec_reset_length (tmp);
83 format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)",
84 1, bs->remote_min_echo_rx_usec);
87 s = format (s, "%10s %-32s %20u\n", "", "Echo transmit interval",
88 bfd_clocks_to_usec (bm, bs->echo_transmit_interval_clocks));
89 tmp = format (tmp, "%.2fs ago", (now - bs->echo_last_tx_clocks) *
90 vm->clib_time.seconds_per_clock);
91 s = format (s, "%10s %-32s %20v\n", "", "Last echo frame tx", tmp);
92 vec_reset_length (tmp);
93 tmp = format (tmp, "%.6fs",
94 (bs->echo_last_rx_clocks - bs->echo_last_tx_clocks) *
95 vm->clib_time.seconds_per_clock);
97 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
102 s = format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no",
103 bs->remote_demand ? "yes" : "no");
104 s = format (s, "%10s %-32s %20s\n", "", "Poll state",
105 bfd_poll_state_string (bs->poll_state));
106 if (bs->auth.curr_key)
108 s = format (s, "%10s %-32s %20u\n", "", "Authentication config key ID",
109 bs->auth.curr_key->conf_key_id);
110 s = format (s, "%10s %-32s %20u\n", "", "Authentication BFD key ID",
111 bs->auth.curr_bfd_key_id);
112 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
113 bs->auth.local_seq_number, bs->auth.remote_seq_number);
118 static clib_error_t *
119 show_bfd (vlib_main_t * vm, unformat_input_t * input,
120 CLIB_UNUSED (vlib_cli_command_t * lmd))
122 bfd_main_t *bm = &bfd_main;
123 bfd_session_t *bs = NULL;
124 unformat_input_t _line_input, *line_input = &_line_input;
126 /* Get a line of input. */
127 if (!unformat_user (input, unformat_line_input, line_input))
130 if (unformat (line_input, "keys"))
132 bfd_auth_key_t *key = NULL;
133 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
134 "Type", "Use Count");
136 pool_foreach (key, bm->auth_keys, {
137 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
138 bfd_auth_type_str (key->auth_type), key->use_count);
141 vlib_cli_output (vm, "%v\n", s);
143 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
144 (u64) pool_elts (bm->auth_keys));
146 else if (unformat (line_input, "sessions"))
148 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
149 "Local value", "Remote value");
151 pool_foreach (bs, bm->sessions, {
152 s = format (s, "%U", format_bfd_session_cli, vm, bm, bs);
155 vlib_cli_output (vm, "%v", s);
157 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
158 (u64) pool_elts (bm->sessions));
160 else if (unformat (line_input, "echo-source"))
168 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
169 &have_usable_ip6, &ip6);
172 vnet_sw_interface_t *sw_if =
173 vnet_get_sw_interface_safe (&vnet_main, sw_if_index);
174 vnet_hw_interface_t *hw_if =
175 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
176 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
177 s = format (s, "IPv4 address usable as echo source: ");
180 s = format (s, "%U\n", format_ip4_address, &ip4);
184 s = format (s, "none\n");
186 s = format (s, "IPv6 address usable as echo source: ");
189 s = format (s, "%U\n", format_ip6_address, &ip6);
193 s = format (s, "none\n");
195 vlib_cli_output (vm, "%v", s);
200 vlib_cli_output (vm, "UDP echo source is not set.\n");
205 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
206 (u64) pool_elts (bm->sessions));
207 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
208 (u64) pool_elts (bm->auth_keys));
214 VLIB_CLI_COMMAND (show_bfd_command, static) = {
216 .short_help = "show bfd [keys|sessions|echo-source]",
217 .function = show_bfd,
221 static clib_error_t *
222 bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
223 CLIB_UNUSED (vlib_cli_command_t * lmd))
225 clib_error_t *ret = NULL;
228 u8 *vec_auth_type = NULL;
229 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
231 unformat_input_t _line_input, *line_input = &_line_input;
232 static const u8 keyed_sha1[] = "keyed-sha1";
233 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
235 /* Get a line of input. */
236 if (!unformat_user (input, unformat_line_input, line_input))
239 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
241 if (unformat (line_input, "conf-key-id %u", &key_id))
245 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
248 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
249 0 == memcmp (vec_auth_type, keyed_sha1,
250 sizeof (keyed_sha1) - 1))
252 auth_type = BFD_AUTH_TYPE_keyed_sha1;
254 else if (vec_len (vec_auth_type) ==
255 sizeof (meticulous_keyed_sha1) - 1 &&
256 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
257 sizeof (meticulous_keyed_sha1) - 1))
259 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
263 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
268 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
270 /* nothing to do here */
274 ret = clib_error_return (0, "Unknown input `%U'",
275 format_unformat_error, line_input);
283 clib_error_return (0, "required parameter missing: `conf-key-id'");
288 ret = clib_error_return (0, "required parameter missing: `type'");
293 ret = clib_error_return (0, "required parameter missing: `secret'");
297 vnet_api_error_t rv =
298 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
302 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
303 (int) rv, format_vnet_api_errno, rv);
307 vec_free (vec_auth_type);
312 VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
313 .path = "bfd key set",
314 .short_help = "bfd key set"
316 " type <keyed-sha1|meticulous-keyed-sha1> "
318 .function = bfd_cli_key_add,
322 static clib_error_t *
323 bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
324 CLIB_UNUSED (vlib_cli_command_t * lmd))
326 clib_error_t *ret = NULL;
328 unformat_input_t _line_input, *line_input = &_line_input;
330 /* Get a line of input. */
331 if (!unformat_user (input, unformat_line_input, line_input))
334 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
336 if (!unformat (line_input, "conf-key-id %u", &key_id))
338 ret = clib_error_return (0, "Unknown input `%U'",
339 format_unformat_error, line_input);
344 vnet_api_error_t rv = bfd_auth_del_key (key_id);
348 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
349 (int) rv, format_vnet_api_errno, rv);
357 VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
358 .path = "bfd key del",
359 .short_help = "bfd key del conf-key-id <id>",
360 .function = bfd_cli_key_del,
364 #define INTERFACE_STR "interface"
365 #define LOCAL_ADDR_STR "local-addr"
366 #define PEER_ADDR_STR "peer-addr"
367 #define CONF_KEY_ID_STR "conf-key-id"
368 #define BFD_KEY_ID_STR "bfd-key-id"
369 #define DESIRED_MIN_TX_STR "desired-min-tx"
370 #define REQUIRED_MIN_RX_STR "required-min-rx"
371 #define DETECT_MULT_STR "detect-mult"
372 #define ADMIN_STR "admin"
373 #define DELAYED_STR "delayed"
375 static const unsigned mandatory = 1;
376 static const unsigned optional = 0;
378 #define DECLARE(t, n, s, r, ...) \
382 #define UNFORMAT(t, n, s, r, ...) \
383 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
385 something_parsed = 1; \
389 #define CHECK_MANDATORY(t, n, s, r, ...) \
390 WARN_OFF(tautological-compare) \
391 if (mandatory == r && !have_##n) \
393 WARN_ON(tautological-compare) \
394 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
398 static clib_error_t *
399 bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
400 CLIB_UNUSED (vlib_cli_command_t * lmd))
402 clib_error_t *ret = NULL;
403 unformat_input_t _line_input, *line_input = &_line_input;
404 #define foreach_bfd_cli_udp_session_add_cli_param(F) \
405 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
406 unformat_vnet_sw_interface, &vnet_main) \
407 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
408 unformat_ip46_address) \
409 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
410 unformat_ip46_address) \
411 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
412 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
413 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
414 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
415 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
417 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
419 /* Get a line of input. */
420 if (!unformat_user (input, unformat_line_input, line_input))
423 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
425 int something_parsed = 0;
426 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
428 if (!something_parsed)
430 ret = clib_error_return (0, "Unknown input `%U'",
431 format_unformat_error, line_input);
436 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
438 if (1 == have_conf_key_id + have_bfd_key_id)
440 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
441 "and `%s' must be either both specified or none",
442 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
446 if (detect_mult > 255)
448 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
449 DETECT_MULT_STR, detect_mult);
453 if (have_bfd_key_id && bfd_key_id > 255)
455 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
456 BFD_KEY_ID_STR, bfd_key_id);
460 vnet_api_error_t rv =
461 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
463 detect_mult, have_conf_key_id, conf_key_id,
468 clib_error_return (0,
469 "`bfd_add_add_session' API call failed, rv=%d:%U",
470 (int) rv, format_vnet_api_errno, rv);
479 VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
480 .path = "bfd udp session add",
481 .short_help = "bfd udp session add"
482 " interface <interface>"
483 " local-addr <local-address>"
484 " peer-addr <peer-address>"
485 " desired-min-tx <desired min tx interval>"
486 " required-min-rx <required min rx interval>"
487 " detect-mult <detect multiplier> "
489 " conf-key-id <config key ID>"
490 " bfd-key-id <BFD key ID>"
492 .function = bfd_cli_udp_session_add,
496 static clib_error_t *
497 bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
498 CLIB_UNUSED (vlib_cli_command_t * lmd))
500 clib_error_t *ret = NULL;
501 unformat_input_t _line_input, *line_input = &_line_input;
502 #define foreach_bfd_cli_udp_session_mod_cli_param(F) \
503 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
504 unformat_vnet_sw_interface, &vnet_main) \
505 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
506 unformat_ip46_address) \
507 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
508 unformat_ip46_address) \
509 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
510 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
511 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
513 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
515 /* Get a line of input. */
516 if (!unformat_user (input, unformat_line_input, line_input))
519 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
521 int something_parsed = 0;
522 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
524 if (!something_parsed)
526 ret = clib_error_return (0, "Unknown input `%U'",
527 format_unformat_error, line_input);
532 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
534 if (detect_mult > 255)
536 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
537 DETECT_MULT_STR, detect_mult);
541 vnet_api_error_t rv =
542 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
543 desired_min_tx, required_min_rx, detect_mult);
547 clib_error_return (0,
548 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
549 (int) rv, format_vnet_api_errno, rv);
558 VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
559 .path = "bfd udp session mod",
560 .short_help = "bfd udp session mod interface"
561 " <interface> local-addr"
562 " <local-address> peer-addr"
563 " <peer-address> desired-min-tx"
564 " <desired min tx interval> required-min-rx"
565 " <required min rx interval> detect-mult"
566 " <detect multiplier> ",
567 .function = bfd_cli_udp_session_mod,
571 static clib_error_t *
572 bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
573 CLIB_UNUSED (vlib_cli_command_t * lmd))
575 clib_error_t *ret = NULL;
576 unformat_input_t _line_input, *line_input = &_line_input;
577 #define foreach_bfd_cli_udp_session_del_cli_param(F) \
578 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
579 unformat_vnet_sw_interface, &vnet_main) \
580 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
581 unformat_ip46_address) \
582 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
583 unformat_ip46_address)
585 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
587 /* Get a line of input. */
588 if (!unformat_user (input, unformat_line_input, line_input))
591 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
593 int something_parsed = 0;
594 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
596 if (!something_parsed)
598 ret = clib_error_return (0, "Unknown input `%U'",
599 format_unformat_error, line_input);
604 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
606 vnet_api_error_t rv =
607 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
611 clib_error_return (0,
612 "`bfd_udp_del_session' API call failed, rv=%d:%U",
613 (int) rv, format_vnet_api_errno, rv);
622 VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
623 .path = "bfd udp session del",
624 .short_help = "bfd udp session del interface"
625 " <interface> local-addr"
626 " <local-address> peer-addr"
628 .function = bfd_cli_udp_session_del,
632 static clib_error_t *
633 bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
634 CLIB_UNUSED (vlib_cli_command_t * lmd))
636 clib_error_t *ret = NULL;
637 unformat_input_t _line_input, *line_input = &_line_input;
638 #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
639 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
640 unformat_vnet_sw_interface, &vnet_main) \
641 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
642 unformat_ip46_address) \
643 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
644 unformat_ip46_address) \
645 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
646 &admin_up_down_token)
648 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
650 /* Get a line of input. */
651 if (!unformat_user (input, unformat_line_input, line_input))
654 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
656 int something_parsed = 0;
657 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
659 if (!something_parsed)
661 ret = clib_error_return (0, "Unknown input `%U'",
662 format_unformat_error, line_input);
667 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
670 static const char up[] = "up";
671 static const char down[] = "down";
672 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
676 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
683 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
684 ADMIN_STR, admin_up_down_token);
687 vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr,
688 &peer_addr, admin_up_down);
692 clib_error_return (0,
693 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
694 (int) rv, format_vnet_api_errno, rv);
703 VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
704 .path = "bfd udp session set-flags",
705 .short_help = "bfd udp session set-flags"
706 " interface <interface>"
707 " local-addr <local-address>"
708 " peer-addr <peer-address>"
710 .function = bfd_cli_udp_session_set_flags,
714 static clib_error_t *
715 bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
716 unformat_input_t * input,
717 CLIB_UNUSED (vlib_cli_command_t * lmd))
719 clib_error_t *ret = NULL;
720 unformat_input_t _line_input, *line_input = &_line_input;
721 #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
722 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
723 unformat_vnet_sw_interface, &vnet_main) \
724 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
725 unformat_ip46_address) \
726 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
727 unformat_ip46_address) \
728 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
729 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
730 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
732 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
734 /* Get a line of input. */
735 if (!unformat_user (input, unformat_line_input, line_input))
738 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
740 int something_parsed = 0;
741 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
743 if (!something_parsed)
745 ret = clib_error_return (0, "Unknown input `%U'",
746 format_unformat_error, line_input);
751 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
754 if (have_delayed_token)
756 static const char yes[] = "yes";
757 static const char no[] = "no";
758 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
762 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
769 clib_error_return (0,
770 "Unrecognized value for `%s' parameter: `%v'",
771 DELAYED_STR, delayed_token);
776 if (have_bfd_key_id && bfd_key_id > 255)
778 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
779 BFD_KEY_ID_STR, bfd_key_id);
783 vnet_api_error_t rv =
784 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
785 bfd_key_id, is_delayed);
789 clib_error_return (0,
790 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
791 (int) rv, format_vnet_api_errno, rv);
800 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
801 .path = "bfd udp session auth activate",
802 .short_help = "bfd udp session auth activate"
803 " interface <interface>"
804 " local-addr <local-address>"
805 " peer-addr <peer-address>"
806 " conf-key-id <config key ID>"
807 " bfd-key-id <BFD key ID>"
808 " [ delayed <yes|no> ]",
809 .function = bfd_cli_udp_session_auth_activate,
812 static clib_error_t *
813 bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
814 CLIB_UNUSED (vlib_cli_command_t *lmd))
816 clib_error_t *ret = NULL;
817 unformat_input_t _line_input, *line_input = &_line_input;
818 #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
819 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
820 unformat_vnet_sw_interface, &vnet_main) \
821 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
822 unformat_ip46_address) \
823 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
824 unformat_ip46_address) \
825 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
827 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
829 /* Get a line of input. */
830 if (!unformat_user (input, unformat_line_input, line_input))
833 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
835 int something_parsed = 0;
836 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
838 if (!something_parsed)
840 ret = clib_error_return (0, "Unknown input `%U'",
841 format_unformat_error, input);
846 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
849 if (have_delayed_token)
851 static const char yes[] = "yes";
852 static const char no[] = "no";
853 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
857 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
863 ret = clib_error_return (
864 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
870 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
871 &peer_addr, is_delayed);
874 ret = clib_error_return (
875 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
876 format_vnet_api_errno, rv);
885 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
886 .path = "bfd udp session auth deactivate",
887 .short_help = "bfd udp session auth deactivate"
888 " interface <interface>"
889 " local-addr <local-address>"
890 " peer-addr <peer-address>"
891 "[ delayed <yes|no> ]",
892 .function = bfd_cli_udp_session_auth_deactivate,
896 static clib_error_t *
897 bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
898 CLIB_UNUSED (vlib_cli_command_t * lmd))
900 clib_error_t *ret = NULL;
901 unformat_input_t _line_input, *line_input = &_line_input;
902 #define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
903 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
904 unformat_vnet_sw_interface, &vnet_main)
906 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
908 /* Get a line of input. */
909 if (!unformat_user (input, unformat_line_input, line_input))
912 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
914 int something_parsed = 0;
915 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
917 if (!something_parsed)
919 ret = clib_error_return (0, "Unknown input `%U'",
920 format_unformat_error, line_input);
925 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
927 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
931 clib_error_return (0,
932 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
933 (int) rv, format_vnet_api_errno, rv);
942 VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
943 .path = "bfd udp echo-source set",
944 .short_help = "bfd udp echo-source set interface <interface>",
945 .function = bfd_cli_udp_set_echo_source,
949 static clib_error_t *
950 bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
951 CLIB_UNUSED (vlib_cli_command_t * lmd))
953 vnet_api_error_t rv = bfd_udp_del_echo_source ();
956 return clib_error_return (0,
957 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
958 (int) rv, format_vnet_api_errno, rv);
965 VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
966 .path = "bfd udp echo-source del",
967 .short_help = "bfd udp echo-source del",
968 .function = bfd_cli_udp_del_echo_source,
973 * fd.io coding-style-patch-verification: ON
976 * eval: (c-set-style "gnu")