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_session_t *bs = va_arg (*args, bfd_session_t *);
34 switch (bs->transport)
36 case BFD_TRANSPORT_UDP4:
37 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv4 address",
38 format_ip4_address, bs->udp.key.local_addr.ip4.as_u8,
39 format_ip4_address, bs->udp.key.peer_addr.ip4.as_u8);
41 case BFD_TRANSPORT_UDP6:
42 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv6 address",
43 format_ip6_address, &bs->udp.key.local_addr.ip6,
44 format_ip6_address, &bs->udp.key.peer_addr.ip6);
47 s = format (s, "%10s %-32s %20s %20s\n", "", "Session state",
48 bfd_state_string (bs->local_state),
49 bfd_state_string (bs->remote_state));
50 s = format (s, "%10s %-32s %20s %20s\n", "", "Diagnostic code",
51 bfd_diag_code_string (bs->local_diag),
52 bfd_diag_code_string (bs->remote_diag));
53 s = format (s, "%10s %-32s %20u %20u\n", "", "Detect multiplier",
54 bs->local_detect_mult, bs->remote_detect_mult);
55 s = format (s, "%10s %-32s %20u %20llu\n", "",
56 "Required Min Rx Interval (usec)",
57 bs->config_required_min_rx_usec, bs->remote_min_rx_usec);
58 s = format (s, "%10s %-32s %20u %20u\n", "",
59 "Desired Min Tx Interval (usec)",
60 bs->config_desired_min_tx_usec,
61 bfd_nsec_to_usec (bs->remote_desired_min_tx_nsec));
63 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
64 bfd_nsec_to_usec (bs->transmit_interval_nsec));
65 u64 now = clib_cpu_time_now ();
67 if (bs->last_tx_nsec > 0)
69 tmp = format (tmp, "%.2fs ago", (now - bs->last_tx_nsec) *
70 vm->clib_time.seconds_per_clock);
71 s = format (s, "%10s %-32s %20v\n", "", "Last control frame tx", tmp);
72 vec_reset_length (tmp);
76 tmp = format (tmp, "%.2fs ago", (now - bs->last_rx_nsec) *
77 vm->clib_time.seconds_per_clock);
78 s = format (s, "%10s %-32s %20v\n", "", "Last control frame rx", tmp);
79 vec_reset_length (tmp);
82 format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)",
83 1, bs->remote_min_echo_rx_usec);
87 format (s, "%10s %-32s %20u\n", "", "Echo transmit interval",
88 bfd_nsec_to_usec (bs->echo_transmit_interval_nsec));
90 format (tmp, "%.2fs ago",
92 bs->echo_last_tx_nsec) * vm->clib_time.seconds_per_clock);
93 s = format (s, "%10s %-32s %20v\n", "", "Last echo frame tx", tmp);
94 vec_reset_length (tmp);
95 tmp = format (tmp, "%.6fs",
96 (bs->echo_last_rx_nsec - bs->echo_last_tx_nsec) *
97 vm->clib_time.seconds_per_clock);
99 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
104 s = format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no",
105 bs->remote_demand ? "yes" : "no");
106 s = format (s, "%10s %-32s %20s\n", "", "Poll state",
107 bfd_poll_state_string (bs->poll_state));
108 if (bs->auth.curr_key)
110 s = format (s, "%10s %-32s %20u\n", "", "Authentication config key ID",
111 bs->auth.curr_key->conf_key_id);
112 s = format (s, "%10s %-32s %20u\n", "", "Authentication BFD key ID",
113 bs->auth.curr_bfd_key_id);
114 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
115 bs->auth.local_seq_number, bs->auth.remote_seq_number);
120 static clib_error_t *
121 show_bfd (vlib_main_t * vm, unformat_input_t * input,
122 CLIB_UNUSED (vlib_cli_command_t * lmd))
124 bfd_main_t *bm = &bfd_main;
125 bfd_session_t *bs = NULL;
126 unformat_input_t _line_input, *line_input = &_line_input;
128 /* Get a line of input. */
129 if (!unformat_user (input, unformat_line_input, line_input))
132 if (unformat (line_input, "keys"))
134 bfd_auth_key_t *key = NULL;
135 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
136 "Type", "Use Count");
138 pool_foreach (key, bm->auth_keys) {
139 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
140 bfd_auth_type_str (key->auth_type), key->use_count);
143 vlib_cli_output (vm, "%v\n", s);
145 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
146 (u64) pool_elts (bm->auth_keys));
148 else if (unformat (line_input, "sessions"))
150 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
151 "Local value", "Remote value");
153 pool_foreach (bs, bm->sessions) {
154 s = format (s, "%U", format_bfd_session_cli, vm, bs);
157 vlib_cli_output (vm, "%v", s);
159 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
160 (u64) pool_elts (bm->sessions));
162 else if (unformat (line_input, "echo-source"))
170 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
171 &have_usable_ip6, &ip6);
174 vnet_sw_interface_t *sw_if =
175 vnet_get_sw_interface_or_null (&vnet_main, sw_if_index);
176 vnet_hw_interface_t *hw_if =
177 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
178 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
179 s = format (s, "IPv4 address usable as echo source: ");
182 s = format (s, "%U\n", format_ip4_address, &ip4);
186 s = format (s, "none\n");
188 s = format (s, "IPv6 address usable as echo source: ");
191 s = format (s, "%U\n", format_ip6_address, &ip6);
195 s = format (s, "none\n");
197 vlib_cli_output (vm, "%v", s);
202 vlib_cli_output (vm, "UDP echo source is not set.\n");
207 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
208 (u64) pool_elts (bm->sessions));
209 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
210 (u64) pool_elts (bm->auth_keys));
216 VLIB_CLI_COMMAND (show_bfd_command, static) = {
218 .short_help = "show bfd [keys|sessions|echo-source]",
219 .function = show_bfd,
223 static clib_error_t *
224 bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
225 CLIB_UNUSED (vlib_cli_command_t * lmd))
227 clib_error_t *ret = NULL;
230 u8 *vec_auth_type = NULL;
231 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
233 unformat_input_t _line_input, *line_input = &_line_input;
234 static const u8 keyed_sha1[] = "keyed-sha1";
235 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
237 /* Get a line of input. */
238 if (!unformat_user (input, unformat_line_input, line_input))
241 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
243 if (unformat (line_input, "conf-key-id %u", &key_id))
247 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
250 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
251 0 == memcmp (vec_auth_type, keyed_sha1,
252 sizeof (keyed_sha1) - 1))
254 auth_type = BFD_AUTH_TYPE_keyed_sha1;
256 else if (vec_len (vec_auth_type) ==
257 sizeof (meticulous_keyed_sha1) - 1 &&
258 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
259 sizeof (meticulous_keyed_sha1) - 1))
261 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
265 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
270 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
272 /* nothing to do here */
276 ret = clib_error_return (0, "Unknown input `%U'",
277 format_unformat_error, line_input);
285 clib_error_return (0, "required parameter missing: `conf-key-id'");
290 ret = clib_error_return (0, "required parameter missing: `type'");
295 ret = clib_error_return (0, "required parameter missing: `secret'");
299 vnet_api_error_t rv =
300 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
304 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
305 (int) rv, format_vnet_api_errno, rv);
309 vec_free (vec_auth_type);
314 VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
315 .path = "bfd key set",
316 .short_help = "bfd key set"
318 " type <keyed-sha1|meticulous-keyed-sha1> "
320 .function = bfd_cli_key_add,
324 static clib_error_t *
325 bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
326 CLIB_UNUSED (vlib_cli_command_t * lmd))
328 clib_error_t *ret = NULL;
330 unformat_input_t _line_input, *line_input = &_line_input;
332 /* Get a line of input. */
333 if (!unformat_user (input, unformat_line_input, line_input))
336 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
338 if (!unformat (line_input, "conf-key-id %u", &key_id))
340 ret = clib_error_return (0, "Unknown input `%U'",
341 format_unformat_error, line_input);
346 vnet_api_error_t rv = bfd_auth_del_key (key_id);
350 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
351 (int) rv, format_vnet_api_errno, rv);
359 VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
360 .path = "bfd key del",
361 .short_help = "bfd key del conf-key-id <id>",
362 .function = bfd_cli_key_del,
366 #define INTERFACE_STR "interface"
367 #define LOCAL_ADDR_STR "local-addr"
368 #define PEER_ADDR_STR "peer-addr"
369 #define CONF_KEY_ID_STR "conf-key-id"
370 #define BFD_KEY_ID_STR "bfd-key-id"
371 #define DESIRED_MIN_TX_STR "desired-min-tx"
372 #define REQUIRED_MIN_RX_STR "required-min-rx"
373 #define DETECT_MULT_STR "detect-mult"
374 #define ADMIN_STR "admin"
375 #define DELAYED_STR "delayed"
377 static const unsigned mandatory = 1;
378 static const unsigned optional = 0;
380 #define DECLARE(t, n, s, r, ...) \
384 #define UNFORMAT(t, n, s, r, ...) \
385 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
387 something_parsed = 1; \
391 #define CHECK_MANDATORY(t, n, s, r, ...) \
392 WARN_OFF(tautological-compare) \
393 if (mandatory == r && !have_##n) \
395 WARN_ON(tautological-compare) \
396 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
401 bfd_cli_unformat_ip46_address (unformat_input_t *input, va_list *args)
403 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
404 return unformat_user (input, unformat_ip46_address, ip46, IP46_TYPE_ANY);
407 static clib_error_t *
408 bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
409 CLIB_UNUSED (vlib_cli_command_t * lmd))
411 clib_error_t *ret = NULL;
412 unformat_input_t _line_input, *line_input = &_line_input;
413 #define foreach_bfd_cli_udp_session_add_cli_param(F) \
414 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
415 unformat_vnet_sw_interface, &vnet_main) \
416 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
417 bfd_cli_unformat_ip46_address) \
418 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
419 bfd_cli_unformat_ip46_address) \
420 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
421 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
422 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
423 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
424 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
426 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
428 /* Get a line of input. */
429 if (!unformat_user (input, unformat_line_input, line_input))
432 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
434 int something_parsed = 0;
435 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
437 if (!something_parsed)
439 ret = clib_error_return (0, "Unknown input `%U'",
440 format_unformat_error, line_input);
445 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
447 if (1 == have_conf_key_id + have_bfd_key_id)
449 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
450 "and `%s' must be either both specified or none",
451 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
455 if (detect_mult > 255)
457 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
458 DETECT_MULT_STR, detect_mult);
462 if (have_bfd_key_id && bfd_key_id > 255)
464 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
465 BFD_KEY_ID_STR, bfd_key_id);
469 vnet_api_error_t rv =
470 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
472 detect_mult, have_conf_key_id, conf_key_id,
477 clib_error_return (0,
478 "`bfd_add_add_session' API call failed, rv=%d:%U",
479 (int) rv, format_vnet_api_errno, rv);
488 VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
489 .path = "bfd udp session add",
490 .short_help = "bfd udp session add"
491 " interface <interface>"
492 " local-addr <local-address>"
493 " peer-addr <peer-address>"
494 " desired-min-tx <desired min tx interval>"
495 " required-min-rx <required min rx interval>"
496 " detect-mult <detect multiplier> "
498 " conf-key-id <config key ID>"
499 " bfd-key-id <BFD key ID>"
501 .function = bfd_cli_udp_session_add,
505 static clib_error_t *
506 bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
507 CLIB_UNUSED (vlib_cli_command_t * lmd))
509 clib_error_t *ret = NULL;
510 unformat_input_t _line_input, *line_input = &_line_input;
511 #define foreach_bfd_cli_udp_session_mod_cli_param(F) \
512 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
513 unformat_vnet_sw_interface, &vnet_main) \
514 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
515 bfd_cli_unformat_ip46_address) \
516 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
517 bfd_cli_unformat_ip46_address) \
518 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
519 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
520 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
522 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
524 /* Get a line of input. */
525 if (!unformat_user (input, unformat_line_input, line_input))
528 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
530 int something_parsed = 0;
531 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
533 if (!something_parsed)
535 ret = clib_error_return (0, "Unknown input `%U'",
536 format_unformat_error, line_input);
541 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
543 if (detect_mult > 255)
545 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
546 DETECT_MULT_STR, detect_mult);
550 vnet_api_error_t rv =
551 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
552 desired_min_tx, required_min_rx, detect_mult);
556 clib_error_return (0,
557 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
558 (int) rv, format_vnet_api_errno, rv);
567 VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
568 .path = "bfd udp session mod",
569 .short_help = "bfd udp session mod interface"
570 " <interface> local-addr"
571 " <local-address> peer-addr"
572 " <peer-address> desired-min-tx"
573 " <desired min tx interval> required-min-rx"
574 " <required min rx interval> detect-mult"
575 " <detect multiplier> ",
576 .function = bfd_cli_udp_session_mod,
580 static clib_error_t *
581 bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
582 CLIB_UNUSED (vlib_cli_command_t * lmd))
584 clib_error_t *ret = NULL;
585 unformat_input_t _line_input, *line_input = &_line_input;
586 #define foreach_bfd_cli_udp_session_del_cli_param(F) \
587 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
588 unformat_vnet_sw_interface, &vnet_main) \
589 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
590 bfd_cli_unformat_ip46_address) \
591 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
592 bfd_cli_unformat_ip46_address)
594 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
596 /* Get a line of input. */
597 if (!unformat_user (input, unformat_line_input, line_input))
600 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
602 int something_parsed = 0;
603 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
605 if (!something_parsed)
607 ret = clib_error_return (0, "Unknown input `%U'",
608 format_unformat_error, line_input);
613 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
615 vnet_api_error_t rv =
616 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
620 clib_error_return (0,
621 "`bfd_udp_del_session' API call failed, rv=%d:%U",
622 (int) rv, format_vnet_api_errno, rv);
631 VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
632 .path = "bfd udp session del",
633 .short_help = "bfd udp session del interface"
634 " <interface> local-addr"
635 " <local-address> peer-addr"
637 .function = bfd_cli_udp_session_del,
641 static clib_error_t *
642 bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
643 CLIB_UNUSED (vlib_cli_command_t * lmd))
645 clib_error_t *ret = NULL;
646 unformat_input_t _line_input, *line_input = &_line_input;
647 #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
648 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
649 unformat_vnet_sw_interface, &vnet_main) \
650 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
651 bfd_cli_unformat_ip46_address) \
652 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
653 bfd_cli_unformat_ip46_address) \
654 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
655 &admin_up_down_token)
657 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
659 /* Get a line of input. */
660 if (!unformat_user (input, unformat_line_input, line_input))
663 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
665 int something_parsed = 0;
666 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
668 if (!something_parsed)
670 ret = clib_error_return (0, "Unknown input `%U'",
671 format_unformat_error, line_input);
676 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
679 static const char up[] = "up";
680 static const char down[] = "down";
681 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
685 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
692 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
693 ADMIN_STR, admin_up_down_token);
696 vnet_api_error_t rv =
697 bfd_udp_session_set_flags (vm, sw_if_index, &local_addr,
698 &peer_addr, admin_up_down);
702 clib_error_return (0,
703 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
704 (int) rv, format_vnet_api_errno, rv);
713 VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
714 .path = "bfd udp session set-flags",
715 .short_help = "bfd udp session set-flags"
716 " interface <interface>"
717 " local-addr <local-address>"
718 " peer-addr <peer-address>"
720 .function = bfd_cli_udp_session_set_flags,
724 static clib_error_t *
725 bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
726 unformat_input_t * input,
727 CLIB_UNUSED (vlib_cli_command_t * lmd))
729 clib_error_t *ret = NULL;
730 unformat_input_t _line_input, *line_input = &_line_input;
731 #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
732 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
733 unformat_vnet_sw_interface, &vnet_main) \
734 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
735 bfd_cli_unformat_ip46_address) \
736 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
737 bfd_cli_unformat_ip46_address) \
738 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
739 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
740 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
742 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
744 /* Get a line of input. */
745 if (!unformat_user (input, unformat_line_input, line_input))
748 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
750 int something_parsed = 0;
751 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
753 if (!something_parsed)
755 ret = clib_error_return (0, "Unknown input `%U'",
756 format_unformat_error, line_input);
761 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
764 if (have_delayed_token)
766 static const char yes[] = "yes";
767 static const char no[] = "no";
768 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
772 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
779 clib_error_return (0,
780 "Unrecognized value for `%s' parameter: `%v'",
781 DELAYED_STR, delayed_token);
786 if (have_bfd_key_id && bfd_key_id > 255)
788 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
789 BFD_KEY_ID_STR, bfd_key_id);
793 vnet_api_error_t rv =
794 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
795 bfd_key_id, is_delayed);
799 clib_error_return (0,
800 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
801 (int) rv, format_vnet_api_errno, rv);
810 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
811 .path = "bfd udp session auth activate",
812 .short_help = "bfd udp session auth activate"
813 " interface <interface>"
814 " local-addr <local-address>"
815 " peer-addr <peer-address>"
816 " conf-key-id <config key ID>"
817 " bfd-key-id <BFD key ID>"
818 " [ delayed <yes|no> ]",
819 .function = bfd_cli_udp_session_auth_activate,
822 static clib_error_t *
823 bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
824 CLIB_UNUSED (vlib_cli_command_t *lmd))
826 clib_error_t *ret = NULL;
827 unformat_input_t _line_input, *line_input = &_line_input;
828 #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
829 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
830 unformat_vnet_sw_interface, &vnet_main) \
831 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
832 bfd_cli_unformat_ip46_address) \
833 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
834 bfd_cli_unformat_ip46_address) \
835 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
837 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
839 /* Get a line of input. */
840 if (!unformat_user (input, unformat_line_input, line_input))
843 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
845 int something_parsed = 0;
846 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
848 if (!something_parsed)
850 ret = clib_error_return (0, "Unknown input `%U'",
851 format_unformat_error, input);
856 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
859 if (have_delayed_token)
861 static const char yes[] = "yes";
862 static const char no[] = "no";
863 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
867 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
873 ret = clib_error_return (
874 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
880 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
881 &peer_addr, is_delayed);
884 ret = clib_error_return (
885 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
886 format_vnet_api_errno, rv);
895 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
896 .path = "bfd udp session auth deactivate",
897 .short_help = "bfd udp session auth deactivate"
898 " interface <interface>"
899 " local-addr <local-address>"
900 " peer-addr <peer-address>"
901 "[ delayed <yes|no> ]",
902 .function = bfd_cli_udp_session_auth_deactivate,
906 static clib_error_t *
907 bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
908 CLIB_UNUSED (vlib_cli_command_t * lmd))
910 clib_error_t *ret = NULL;
911 unformat_input_t _line_input, *line_input = &_line_input;
912 #define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
913 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
914 unformat_vnet_sw_interface, &vnet_main)
916 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
918 /* Get a line of input. */
919 if (!unformat_user (input, unformat_line_input, line_input))
922 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
924 int something_parsed = 0;
925 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
927 if (!something_parsed)
929 ret = clib_error_return (0, "Unknown input `%U'",
930 format_unformat_error, line_input);
935 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
937 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
941 clib_error_return (0,
942 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
943 (int) rv, format_vnet_api_errno, rv);
952 VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
953 .path = "bfd udp echo-source set",
954 .short_help = "bfd udp echo-source set interface <interface>",
955 .function = bfd_cli_udp_set_echo_source,
959 static clib_error_t *
960 bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
961 CLIB_UNUSED (vlib_cli_command_t * lmd))
963 vnet_api_error_t rv = bfd_udp_del_echo_source ();
966 return clib_error_return (0,
967 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
968 (int) rv, format_vnet_api_errno, rv);
975 VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
976 .path = "bfd udp echo-source del",
977 .short_help = "bfd udp echo-source del",
978 .function = bfd_cli_udp_del_echo_source,
983 * fd.io coding-style-patch-verification: ON
986 * eval: (c-set-style "gnu")