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");
137 pool_foreach (key, bm->auth_keys) {
138 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
139 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");
150 pool_foreach (bs, bm->sessions) {
151 s = format (s, "%U", format_bfd_session_cli, vm, bs);
153 vlib_cli_output (vm, "%v", s);
155 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
156 (u64) pool_elts (bm->sessions));
158 else if (unformat (line_input, "echo-source"))
166 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
167 &have_usable_ip6, &ip6);
170 vnet_sw_interface_t *sw_if =
171 vnet_get_sw_interface_or_null (&vnet_main, sw_if_index);
172 vnet_hw_interface_t *hw_if =
173 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
174 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
175 s = format (s, "IPv4 address usable as echo source: ");
178 s = format (s, "%U\n", format_ip4_address, &ip4);
182 s = format (s, "none\n");
184 s = format (s, "IPv6 address usable as echo source: ");
187 s = format (s, "%U\n", format_ip6_address, &ip6);
191 s = format (s, "none\n");
193 vlib_cli_output (vm, "%v", s);
198 vlib_cli_output (vm, "UDP echo source is not set.\n");
203 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
204 (u64) pool_elts (bm->sessions));
205 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
206 (u64) pool_elts (bm->auth_keys));
211 VLIB_CLI_COMMAND (show_bfd_command, static) = {
213 .short_help = "show bfd [keys|sessions|echo-source]",
214 .function = show_bfd,
217 static clib_error_t *
218 bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
219 CLIB_UNUSED (vlib_cli_command_t * lmd))
221 clib_error_t *ret = NULL;
224 u8 *vec_auth_type = NULL;
225 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
227 unformat_input_t _line_input, *line_input = &_line_input;
228 static const u8 keyed_sha1[] = "keyed-sha1";
229 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
231 /* Get a line of input. */
232 if (!unformat_user (input, unformat_line_input, line_input))
235 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
237 if (unformat (line_input, "conf-key-id %u", &key_id))
241 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
244 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
245 0 == memcmp (vec_auth_type, keyed_sha1,
246 sizeof (keyed_sha1) - 1))
248 auth_type = BFD_AUTH_TYPE_keyed_sha1;
250 else if (vec_len (vec_auth_type) ==
251 sizeof (meticulous_keyed_sha1) - 1 &&
252 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
253 sizeof (meticulous_keyed_sha1) - 1))
255 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
259 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
264 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
266 /* nothing to do here */
270 ret = clib_error_return (0, "Unknown input `%U'",
271 format_unformat_error, line_input);
279 clib_error_return (0, "required parameter missing: `conf-key-id'");
284 ret = clib_error_return (0, "required parameter missing: `type'");
289 ret = clib_error_return (0, "required parameter missing: `secret'");
293 vnet_api_error_t rv =
294 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
298 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
299 (int) rv, format_vnet_api_errno, rv);
303 vec_free (vec_auth_type);
307 VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
308 .path = "bfd key set",
309 .short_help = "bfd key set"
311 " type <keyed-sha1|meticulous-keyed-sha1> "
313 .function = bfd_cli_key_add,
316 static clib_error_t *
317 bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
318 CLIB_UNUSED (vlib_cli_command_t * lmd))
320 clib_error_t *ret = NULL;
322 unformat_input_t _line_input, *line_input = &_line_input;
324 /* Get a line of input. */
325 if (!unformat_user (input, unformat_line_input, line_input))
328 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
330 if (!unformat (line_input, "conf-key-id %u", &key_id))
332 ret = clib_error_return (0, "Unknown input `%U'",
333 format_unformat_error, line_input);
338 vnet_api_error_t rv = bfd_auth_del_key (key_id);
342 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
343 (int) rv, format_vnet_api_errno, rv);
350 VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
351 .path = "bfd key del",
352 .short_help = "bfd key del conf-key-id <id>",
353 .function = bfd_cli_key_del,
356 #define INTERFACE_STR "interface"
357 #define LOCAL_ADDR_STR "local-addr"
358 #define PEER_ADDR_STR "peer-addr"
359 #define CONF_KEY_ID_STR "conf-key-id"
360 #define BFD_KEY_ID_STR "bfd-key-id"
361 #define DESIRED_MIN_TX_STR "desired-min-tx"
362 #define REQUIRED_MIN_RX_STR "required-min-rx"
363 #define DETECT_MULT_STR "detect-mult"
364 #define ADMIN_STR "admin"
365 #define DELAYED_STR "delayed"
367 static const unsigned mandatory = 1;
368 static const unsigned optional = 0;
370 #define DECLARE(t, n, s, r, ...) \
374 #define UNFORMAT(t, n, s, r, ...) \
375 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
377 something_parsed = 1; \
381 #define CHECK_MANDATORY(t, n, s, r, ...) \
382 WARN_OFF(tautological-compare) \
383 if (mandatory == r && !have_##n) \
385 WARN_ON(tautological-compare) \
386 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
391 bfd_cli_unformat_ip46_address (unformat_input_t *input, va_list *args)
393 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
394 return unformat_user (input, unformat_ip46_address, ip46, IP46_TYPE_ANY);
397 static clib_error_t *
398 bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
399 CLIB_UNUSED (vlib_cli_command_t * lmd))
401 clib_error_t *ret = NULL;
402 unformat_input_t _line_input, *line_input = &_line_input;
403 #define foreach_bfd_cli_udp_session_add_cli_param(F) \
404 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
405 unformat_vnet_sw_interface, &vnet_main) \
406 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
407 bfd_cli_unformat_ip46_address) \
408 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
409 bfd_cli_unformat_ip46_address) \
410 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
411 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
412 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
413 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
414 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
416 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
418 /* Get a line of input. */
419 if (!unformat_user (input, unformat_line_input, line_input))
422 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
424 int something_parsed = 0;
425 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
427 if (!something_parsed)
429 ret = clib_error_return (0, "Unknown input `%U'",
430 format_unformat_error, line_input);
435 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
437 if (1 == have_conf_key_id + have_bfd_key_id)
439 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
440 "and `%s' must be either both specified or none",
441 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
445 if (detect_mult > 255)
447 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
448 DETECT_MULT_STR, detect_mult);
452 if (have_bfd_key_id && bfd_key_id > 255)
454 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
455 BFD_KEY_ID_STR, bfd_key_id);
459 vnet_api_error_t rv =
460 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
462 detect_mult, have_conf_key_id, conf_key_id,
467 clib_error_return (0,
468 "`bfd_add_add_session' API call failed, rv=%d:%U",
469 (int) rv, format_vnet_api_errno, rv);
477 VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
478 .path = "bfd udp session add",
479 .short_help = "bfd udp session add"
480 " interface <interface>"
481 " local-addr <local-address>"
482 " peer-addr <peer-address>"
483 " desired-min-tx <desired min tx interval>"
484 " required-min-rx <required min rx interval>"
485 " detect-mult <detect multiplier> "
487 " conf-key-id <config key ID>"
488 " bfd-key-id <BFD key ID>"
490 .function = bfd_cli_udp_session_add,
493 static clib_error_t *
494 bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
495 CLIB_UNUSED (vlib_cli_command_t * lmd))
497 clib_error_t *ret = NULL;
498 unformat_input_t _line_input, *line_input = &_line_input;
499 #define foreach_bfd_cli_udp_session_mod_cli_param(F) \
500 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
501 unformat_vnet_sw_interface, &vnet_main) \
502 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
503 bfd_cli_unformat_ip46_address) \
504 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
505 bfd_cli_unformat_ip46_address) \
506 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
507 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
508 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
510 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
512 /* Get a line of input. */
513 if (!unformat_user (input, unformat_line_input, line_input))
516 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
518 int something_parsed = 0;
519 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
521 if (!something_parsed)
523 ret = clib_error_return (0, "Unknown input `%U'",
524 format_unformat_error, line_input);
529 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
531 if (detect_mult > 255)
533 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
534 DETECT_MULT_STR, detect_mult);
538 vnet_api_error_t rv =
539 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
540 desired_min_tx, required_min_rx, detect_mult);
544 clib_error_return (0,
545 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
546 (int) rv, format_vnet_api_errno, rv);
554 VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
555 .path = "bfd udp session mod",
556 .short_help = "bfd udp session mod interface"
557 " <interface> local-addr"
558 " <local-address> peer-addr"
559 " <peer-address> desired-min-tx"
560 " <desired min tx interval> required-min-rx"
561 " <required min rx interval> detect-mult"
562 " <detect multiplier> ",
563 .function = bfd_cli_udp_session_mod,
566 static clib_error_t *
567 bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
568 CLIB_UNUSED (vlib_cli_command_t * lmd))
570 clib_error_t *ret = NULL;
571 unformat_input_t _line_input, *line_input = &_line_input;
572 #define foreach_bfd_cli_udp_session_del_cli_param(F) \
573 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
574 unformat_vnet_sw_interface, &vnet_main) \
575 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
576 bfd_cli_unformat_ip46_address) \
577 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
578 bfd_cli_unformat_ip46_address)
580 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
582 /* Get a line of input. */
583 if (!unformat_user (input, unformat_line_input, line_input))
586 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
588 int something_parsed = 0;
589 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
591 if (!something_parsed)
593 ret = clib_error_return (0, "Unknown input `%U'",
594 format_unformat_error, line_input);
599 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
601 vnet_api_error_t rv =
602 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
606 clib_error_return (0,
607 "`bfd_udp_del_session' API call failed, rv=%d:%U",
608 (int) rv, format_vnet_api_errno, rv);
616 VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
617 .path = "bfd udp session del",
618 .short_help = "bfd udp session del interface"
619 " <interface> local-addr"
620 " <local-address> peer-addr"
622 .function = bfd_cli_udp_session_del,
625 static clib_error_t *
626 bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
627 CLIB_UNUSED (vlib_cli_command_t * lmd))
629 clib_error_t *ret = NULL;
630 unformat_input_t _line_input, *line_input = &_line_input;
631 #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
632 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
633 unformat_vnet_sw_interface, &vnet_main) \
634 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
635 bfd_cli_unformat_ip46_address) \
636 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
637 bfd_cli_unformat_ip46_address) \
638 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
639 &admin_up_down_token)
641 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
643 /* Get a line of input. */
644 if (!unformat_user (input, unformat_line_input, line_input))
647 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
649 int something_parsed = 0;
650 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
652 if (!something_parsed)
654 ret = clib_error_return (0, "Unknown input `%U'",
655 format_unformat_error, line_input);
660 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
663 static const char up[] = "up";
664 static const char down[] = "down";
665 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
669 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
676 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
677 ADMIN_STR, admin_up_down_token);
680 vnet_api_error_t rv =
681 bfd_udp_session_set_flags (vm, sw_if_index, &local_addr,
682 &peer_addr, admin_up_down);
686 clib_error_return (0,
687 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
688 (int) rv, format_vnet_api_errno, rv);
696 VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
697 .path = "bfd udp session set-flags",
698 .short_help = "bfd udp session set-flags"
699 " interface <interface>"
700 " local-addr <local-address>"
701 " peer-addr <peer-address>"
703 .function = bfd_cli_udp_session_set_flags,
706 static clib_error_t *
707 bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
708 unformat_input_t * input,
709 CLIB_UNUSED (vlib_cli_command_t * lmd))
711 clib_error_t *ret = NULL;
712 unformat_input_t _line_input, *line_input = &_line_input;
713 #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
714 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
715 unformat_vnet_sw_interface, &vnet_main) \
716 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
717 bfd_cli_unformat_ip46_address) \
718 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
719 bfd_cli_unformat_ip46_address) \
720 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
721 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
722 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
724 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
726 /* Get a line of input. */
727 if (!unformat_user (input, unformat_line_input, line_input))
730 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
732 int something_parsed = 0;
733 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
735 if (!something_parsed)
737 ret = clib_error_return (0, "Unknown input `%U'",
738 format_unformat_error, line_input);
743 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
746 if (have_delayed_token)
748 static const char yes[] = "yes";
749 static const char no[] = "no";
750 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
754 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
761 clib_error_return (0,
762 "Unrecognized value for `%s' parameter: `%v'",
763 DELAYED_STR, delayed_token);
768 if (have_bfd_key_id && bfd_key_id > 255)
770 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
771 BFD_KEY_ID_STR, bfd_key_id);
775 vnet_api_error_t rv =
776 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
777 bfd_key_id, is_delayed);
781 clib_error_return (0,
782 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
783 (int) rv, format_vnet_api_errno, rv);
791 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
792 .path = "bfd udp session auth activate",
793 .short_help = "bfd udp session auth activate"
794 " interface <interface>"
795 " local-addr <local-address>"
796 " peer-addr <peer-address>"
797 " conf-key-id <config key ID>"
798 " bfd-key-id <BFD key ID>"
799 " [ delayed <yes|no> ]",
800 .function = bfd_cli_udp_session_auth_activate,
803 static clib_error_t *
804 bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
805 CLIB_UNUSED (vlib_cli_command_t *lmd))
807 clib_error_t *ret = NULL;
808 unformat_input_t _line_input, *line_input = &_line_input;
809 #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
810 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
811 unformat_vnet_sw_interface, &vnet_main) \
812 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
813 bfd_cli_unformat_ip46_address) \
814 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
815 bfd_cli_unformat_ip46_address) \
816 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
818 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
820 /* Get a line of input. */
821 if (!unformat_user (input, unformat_line_input, line_input))
824 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
826 int something_parsed = 0;
827 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
829 if (!something_parsed)
831 ret = clib_error_return (0, "Unknown input `%U'",
832 format_unformat_error, input);
837 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
840 if (have_delayed_token)
842 static const char yes[] = "yes";
843 static const char no[] = "no";
844 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
848 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
854 ret = clib_error_return (
855 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
861 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
862 &peer_addr, is_delayed);
865 ret = clib_error_return (
866 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
867 format_vnet_api_errno, rv);
875 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
876 .path = "bfd udp session auth deactivate",
877 .short_help = "bfd udp session auth deactivate"
878 " interface <interface>"
879 " local-addr <local-address>"
880 " peer-addr <peer-address>"
881 "[ delayed <yes|no> ]",
882 .function = bfd_cli_udp_session_auth_deactivate,
885 static clib_error_t *
886 bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
887 CLIB_UNUSED (vlib_cli_command_t * lmd))
889 clib_error_t *ret = NULL;
890 unformat_input_t _line_input, *line_input = &_line_input;
891 #define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
892 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
893 unformat_vnet_sw_interface, &vnet_main)
895 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
897 /* Get a line of input. */
898 if (!unformat_user (input, unformat_line_input, line_input))
901 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
903 int something_parsed = 0;
904 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
906 if (!something_parsed)
908 ret = clib_error_return (0, "Unknown input `%U'",
909 format_unformat_error, line_input);
914 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
916 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
920 clib_error_return (0,
921 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
922 (int) rv, format_vnet_api_errno, rv);
930 VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
931 .path = "bfd udp echo-source set",
932 .short_help = "bfd udp echo-source set interface <interface>",
933 .function = bfd_cli_udp_set_echo_source,
936 static clib_error_t *
937 bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
938 CLIB_UNUSED (vlib_cli_command_t * lmd))
940 vnet_api_error_t rv = bfd_udp_del_echo_source ();
943 return clib_error_return (0,
944 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
945 (int) rv, format_vnet_api_errno, rv);
951 VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
952 .path = "bfd udp echo-source del",
953 .short_help = "bfd udp echo-source del",
954 .function = bfd_cli_udp_del_echo_source,
958 * fd.io coding-style-patch-verification: ON
961 * eval: (c-set-style "gnu")