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,
222 format_vnet_api_errno (u8 * s, va_list * args)
224 vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t);
227 s = format (s, "%s", c); \
231 foreach_vnet_api_error default:s = format (s, "UNKNOWN");
237 static clib_error_t *
238 bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
239 CLIB_UNUSED (vlib_cli_command_t * lmd))
241 clib_error_t *ret = NULL;
244 u8 *vec_auth_type = NULL;
245 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
247 unformat_input_t _line_input, *line_input = &_line_input;
248 static const u8 keyed_sha1[] = "keyed-sha1";
249 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
251 /* Get a line of input. */
252 if (!unformat_user (input, unformat_line_input, line_input))
255 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
257 if (unformat (line_input, "conf-key-id %u", &key_id))
261 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
264 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
265 0 == memcmp (vec_auth_type, keyed_sha1,
266 sizeof (keyed_sha1) - 1))
268 auth_type = BFD_AUTH_TYPE_keyed_sha1;
270 else if (vec_len (vec_auth_type) ==
271 sizeof (meticulous_keyed_sha1) - 1 &&
272 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
273 sizeof (meticulous_keyed_sha1) - 1))
275 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
279 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
284 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
286 /* nothing to do here */
290 ret = clib_error_return (0, "Unknown input `%U'",
291 format_unformat_error, line_input);
299 clib_error_return (0, "required parameter missing: `conf-key-id'");
304 ret = clib_error_return (0, "required parameter missing: `type'");
309 ret = clib_error_return (0, "required parameter missing: `secret'");
313 vnet_api_error_t rv =
314 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
318 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
319 (int) rv, format_vnet_api_errno, rv);
323 vec_free (vec_auth_type);
328 VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
329 .path = "bfd key set",
330 .short_help = "bfd key set"
332 " type <keyed-sha1|meticulous-keyed-sha1> "
334 .function = bfd_cli_key_add,
338 static clib_error_t *
339 bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
340 CLIB_UNUSED (vlib_cli_command_t * lmd))
342 clib_error_t *ret = NULL;
344 unformat_input_t _line_input, *line_input = &_line_input;
346 /* Get a line of input. */
347 if (!unformat_user (input, unformat_line_input, line_input))
350 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
352 if (!unformat (line_input, "conf-key-id %u", &key_id))
354 ret = clib_error_return (0, "Unknown input `%U'",
355 format_unformat_error, line_input);
360 vnet_api_error_t rv = bfd_auth_del_key (key_id);
364 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
365 (int) rv, format_vnet_api_errno, rv);
373 VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
374 .path = "bfd key del",
375 .short_help = "bfd key del conf-key-id <id>",
376 .function = bfd_cli_key_del,
380 #define INTERFACE_STR "interface"
381 #define LOCAL_ADDR_STR "local-addr"
382 #define PEER_ADDR_STR "peer-addr"
383 #define CONF_KEY_ID_STR "conf-key-id"
384 #define BFD_KEY_ID_STR "bfd-key-id"
385 #define DESIRED_MIN_TX_STR "desired-min-tx"
386 #define REQUIRED_MIN_RX_STR "required-min-rx"
387 #define DETECT_MULT_STR "detect-mult"
388 #define ADMIN_STR "admin"
389 #define DELAYED_STR "delayed"
391 static const unsigned mandatory = 1;
392 static const unsigned optional = 0;
394 #define DECLARE(t, n, s, r, ...) \
398 #define UNFORMAT(t, n, s, r, ...) \
399 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
401 something_parsed = 1; \
405 #define CHECK_MANDATORY(t, n, s, r, ...) \
406 WARN_OFF(tautological-compare) \
407 if (mandatory == r && !have_##n) \
409 WARN_ON(tautological-compare) \
410 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
414 static clib_error_t *
415 bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
416 CLIB_UNUSED (vlib_cli_command_t * lmd))
418 clib_error_t *ret = NULL;
419 unformat_input_t _line_input, *line_input = &_line_input;
420 #define foreach_bfd_cli_udp_session_add_cli_param(F) \
421 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
422 unformat_vnet_sw_interface, &vnet_main) \
423 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
424 unformat_ip46_address) \
425 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
426 unformat_ip46_address) \
427 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
428 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
429 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
430 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
431 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
433 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
435 /* Get a line of input. */
436 if (!unformat_user (input, unformat_line_input, line_input))
439 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
441 int something_parsed = 0;
442 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
444 if (!something_parsed)
446 ret = clib_error_return (0, "Unknown input `%U'",
447 format_unformat_error, line_input);
452 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
454 if (1 == have_conf_key_id + have_bfd_key_id)
456 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
457 "and `%s' must be either both specified or none",
458 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
462 if (detect_mult > 255)
464 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
465 DETECT_MULT_STR, detect_mult);
469 if (have_bfd_key_id && bfd_key_id > 255)
471 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
472 BFD_KEY_ID_STR, bfd_key_id);
476 vnet_api_error_t rv =
477 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
479 detect_mult, have_conf_key_id, conf_key_id,
484 clib_error_return (0,
485 "`bfd_add_add_session' API call failed, rv=%d:%U",
486 (int) rv, format_vnet_api_errno, rv);
495 VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
496 .path = "bfd udp session add",
497 .short_help = "bfd udp session add"
498 " interface <interface>"
499 " local-addr <local-address>"
500 " peer-addr <peer-address>"
501 " desired-min-tx <desired min tx interval>"
502 " required-min-rx <required min rx interval>"
503 " detect-mult <detect multiplier> "
505 " conf-key-id <config key ID>"
506 " bfd-key-id <BFD key ID>"
508 .function = bfd_cli_udp_session_add,
512 static clib_error_t *
513 bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
514 CLIB_UNUSED (vlib_cli_command_t * lmd))
516 clib_error_t *ret = NULL;
517 unformat_input_t _line_input, *line_input = &_line_input;
518 #define foreach_bfd_cli_udp_session_mod_cli_param(F) \
519 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
520 unformat_vnet_sw_interface, &vnet_main) \
521 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
522 unformat_ip46_address) \
523 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
524 unformat_ip46_address) \
525 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
526 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
527 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
529 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
531 /* Get a line of input. */
532 if (!unformat_user (input, unformat_line_input, line_input))
535 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
537 int something_parsed = 0;
538 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
540 if (!something_parsed)
542 ret = clib_error_return (0, "Unknown input `%U'",
543 format_unformat_error, line_input);
548 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
550 if (detect_mult > 255)
552 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
553 DETECT_MULT_STR, detect_mult);
557 vnet_api_error_t rv =
558 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
559 desired_min_tx, required_min_rx, detect_mult);
563 clib_error_return (0,
564 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
565 (int) rv, format_vnet_api_errno, rv);
574 VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
575 .path = "bfd udp session mod",
576 .short_help = "bfd udp session mod interface"
577 " <interface> local-addr"
578 " <local-address> peer-addr"
579 " <peer-address> desired-min-tx"
580 " <desired min tx interval> required-min-rx"
581 " <required min rx interval> detect-mult"
582 " <detect multiplier> ",
583 .function = bfd_cli_udp_session_mod,
587 static clib_error_t *
588 bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
589 CLIB_UNUSED (vlib_cli_command_t * lmd))
591 clib_error_t *ret = NULL;
592 unformat_input_t _line_input, *line_input = &_line_input;
593 #define foreach_bfd_cli_udp_session_del_cli_param(F) \
594 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
595 unformat_vnet_sw_interface, &vnet_main) \
596 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
597 unformat_ip46_address) \
598 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
599 unformat_ip46_address)
601 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
603 /* Get a line of input. */
604 if (!unformat_user (input, unformat_line_input, line_input))
607 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
609 int something_parsed = 0;
610 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
612 if (!something_parsed)
614 ret = clib_error_return (0, "Unknown input `%U'",
615 format_unformat_error, line_input);
620 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
622 vnet_api_error_t rv =
623 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
627 clib_error_return (0,
628 "`bfd_udp_del_session' API call failed, rv=%d:%U",
629 (int) rv, format_vnet_api_errno, rv);
638 VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
639 .path = "bfd udp session del",
640 .short_help = "bfd udp session del interface"
641 " <interface> local-addr"
642 " <local-address> peer-addr"
644 .function = bfd_cli_udp_session_del,
648 static clib_error_t *
649 bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
650 CLIB_UNUSED (vlib_cli_command_t * lmd))
652 clib_error_t *ret = NULL;
653 unformat_input_t _line_input, *line_input = &_line_input;
654 #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
655 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
656 unformat_vnet_sw_interface, &vnet_main) \
657 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
658 unformat_ip46_address) \
659 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
660 unformat_ip46_address) \
661 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
662 &admin_up_down_token)
664 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
666 /* Get a line of input. */
667 if (!unformat_user (input, unformat_line_input, line_input))
670 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
672 int something_parsed = 0;
673 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
675 if (!something_parsed)
677 ret = clib_error_return (0, "Unknown input `%U'",
678 format_unformat_error, line_input);
683 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
686 static const char up[] = "up";
687 static const char down[] = "down";
688 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
692 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
699 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
700 ADMIN_STR, admin_up_down_token);
703 vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr,
704 &peer_addr, admin_up_down);
708 clib_error_return (0,
709 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
710 (int) rv, format_vnet_api_errno, rv);
719 VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
720 .path = "bfd udp session set-flags",
721 .short_help = "bfd udp session set-flags"
722 " interface <interface>"
723 " local-addr <local-address>"
724 " peer-addr <peer-address>"
726 .function = bfd_cli_udp_session_set_flags,
730 static clib_error_t *
731 bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
732 unformat_input_t * input,
733 CLIB_UNUSED (vlib_cli_command_t * lmd))
735 clib_error_t *ret = NULL;
736 unformat_input_t _line_input, *line_input = &_line_input;
737 #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
738 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
739 unformat_vnet_sw_interface, &vnet_main) \
740 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
741 unformat_ip46_address) \
742 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
743 unformat_ip46_address) \
744 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
745 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
746 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
748 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
750 /* Get a line of input. */
751 if (!unformat_user (input, unformat_line_input, line_input))
754 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
756 int something_parsed = 0;
757 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
759 if (!something_parsed)
761 ret = clib_error_return (0, "Unknown input `%U'",
762 format_unformat_error, line_input);
767 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
770 if (have_delayed_token)
772 static const char yes[] = "yes";
773 static const char no[] = "no";
774 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
778 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
785 clib_error_return (0,
786 "Unrecognized value for `%s' parameter: `%v'",
787 DELAYED_STR, delayed_token);
792 if (have_bfd_key_id && bfd_key_id > 255)
794 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
795 BFD_KEY_ID_STR, bfd_key_id);
799 vnet_api_error_t rv =
800 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
801 bfd_key_id, is_delayed);
805 clib_error_return (0,
806 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
807 (int) rv, format_vnet_api_errno, rv);
816 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
817 .path = "bfd udp session auth activate",
818 .short_help = "bfd udp session auth activate"
819 " interface <interface>"
820 " local-addr <local-address>"
821 " peer-addr <peer-address>"
822 " conf-key-id <config key ID>"
823 " bfd-key-id <BFD key ID>"
824 " [ delayed <yes|no> ]",
825 .function = bfd_cli_udp_session_auth_activate,
828 static clib_error_t *
829 bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
830 CLIB_UNUSED (vlib_cli_command_t *lmd))
832 clib_error_t *ret = NULL;
833 unformat_input_t _line_input, *line_input = &_line_input;
834 #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
835 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
836 unformat_vnet_sw_interface, &vnet_main) \
837 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
838 unformat_ip46_address) \
839 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
840 unformat_ip46_address) \
841 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
843 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
845 /* Get a line of input. */
846 if (!unformat_user (input, unformat_line_input, line_input))
849 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
851 int something_parsed = 0;
852 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
854 if (!something_parsed)
856 ret = clib_error_return (0, "Unknown input `%U'",
857 format_unformat_error, input);
862 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
865 if (have_delayed_token)
867 static const char yes[] = "yes";
868 static const char no[] = "no";
869 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
873 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
879 ret = clib_error_return (
880 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
886 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
887 &peer_addr, is_delayed);
890 ret = clib_error_return (
891 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
892 format_vnet_api_errno, rv);
901 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
902 .path = "bfd udp session auth deactivate",
903 .short_help = "bfd udp session auth deactivate"
904 " interface <interface>"
905 " local-addr <local-address>"
906 " peer-addr <peer-address>"
907 "[ delayed <yes|no> ]",
908 .function = bfd_cli_udp_session_auth_deactivate,
912 static clib_error_t *
913 bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
914 CLIB_UNUSED (vlib_cli_command_t * lmd))
916 clib_error_t *ret = NULL;
917 unformat_input_t _line_input, *line_input = &_line_input;
918 #define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
919 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
920 unformat_vnet_sw_interface, &vnet_main)
922 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
924 /* Get a line of input. */
925 if (!unformat_user (input, unformat_line_input, line_input))
928 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
930 int something_parsed = 0;
931 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
933 if (!something_parsed)
935 ret = clib_error_return (0, "Unknown input `%U'",
936 format_unformat_error, line_input);
941 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
943 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
947 clib_error_return (0,
948 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
949 (int) rv, format_vnet_api_errno, rv);
958 VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
959 .path = "bfd udp echo-source set",
960 .short_help = "bfd udp echo-source set interface <interface>",
961 .function = bfd_cli_udp_set_echo_source,
965 static clib_error_t *
966 bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
967 CLIB_UNUSED (vlib_cli_command_t * lmd))
969 vnet_api_error_t rv = bfd_udp_del_echo_source ();
972 return clib_error_return (0,
973 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
974 (int) rv, format_vnet_api_errno, rv);
981 VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
982 .path = "bfd udp echo-source del",
983 .short_help = "bfd udp echo-source del",
984 .function = bfd_cli_udp_del_echo_source,
989 * fd.io coding-style-patch-verification: ON
992 * eval: (c-set-style "gnu")