blob: 33492ca85005ee79f9a2c6ab611cfa6004fe5d90 [file] [log] [blame]
Klement Sekera73884482017-02-23 09:26:30 +01001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15/**
16 * @file
17 * @brief BFD CLI implementation
18 */
19
20#include <vlib/vlib.h>
21#include <vlib/cli.h>
22#include <vppinfra/format.h>
Gabriel Gannebeb85cc2017-11-07 14:24:56 +010023#include <vppinfra/warnings.h>
Klement Sekera73884482017-02-23 09:26:30 +010024#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>
28
29static u8 *
30format_bfd_session_cli (u8 * s, va_list * args)
31{
Klement Sekerae50e8562017-04-04 16:19:48 +020032 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
Klement Sekera73884482017-02-23 09:26:30 +010033 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)
36 {
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);
41 break;
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);
46 break;
47 }
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);
Klement Sekerae50e8562017-04-04 16:19:48 +020056 s = format (s, "%10s %-32s %20u %20llu\n", "",
Klement Sekera73884482017-02-23 09:26:30 +010057 "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));
63 s =
64 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
65 bfd_clocks_to_usec (bm, bs->transmit_interval_clocks));
Klement Sekerae50e8562017-04-04 16:19:48 +020066 u64 now = clib_cpu_time_now ();
67 u8 *tmp = NULL;
68 if (bs->last_tx_clocks > 0)
69 {
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);
74 }
75 if (bs->last_rx_clocks)
76 {
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);
81 }
Klement Sekera73884482017-02-23 09:26:30 +010082 s =
Klement Sekerae50e8562017-04-04 16:19:48 +020083 format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)",
84 1, bs->remote_min_echo_rx_usec);
85 if (bs->echo)
86 {
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);
96 s =
97 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
98 tmp);
99 }
100 vec_free (tmp);
101 tmp = NULL;
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));
Klement Sekera73884482017-02-23 09:26:30 +0100106 if (bs->auth.curr_key)
107 {
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);
Klement Sekerae50e8562017-04-04 16:19:48 +0200112 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
113 bs->auth.local_seq_number, bs->auth.remote_seq_number);
Klement Sekera73884482017-02-23 09:26:30 +0100114 }
115 return s;
116}
117
118static clib_error_t *
119show_bfd (vlib_main_t * vm, unformat_input_t * input,
120 CLIB_UNUSED (vlib_cli_command_t * lmd))
121{
122 bfd_main_t *bm = &bfd_main;
123 bfd_session_t *bs = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100124 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100125
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100126 /* Get a line of input. */
127 if (!unformat_user (input, unformat_line_input, line_input))
128 return 0;
129
130 if (unformat (line_input, "keys"))
Klement Sekera73884482017-02-23 09:26:30 +0100131 {
132 bfd_auth_key_t *key = NULL;
133 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
134 "Type", "Use Count");
135 /* *INDENT-OFF* */
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);
139 });
140 /* *INDENT-ON* */
141 vlib_cli_output (vm, "%v\n", s);
Klement Sekerae50e8562017-04-04 16:19:48 +0200142 vec_free (s);
Klement Sekera73884482017-02-23 09:26:30 +0100143 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
144 (u64) pool_elts (bm->auth_keys));
145 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100146 else if (unformat (line_input, "sessions"))
Klement Sekera73884482017-02-23 09:26:30 +0100147 {
148 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
149 "Local value", "Remote value");
150 /* *INDENT-OFF* */
Klement Sekerae50e8562017-04-04 16:19:48 +0200151 pool_foreach (bs, bm->sessions, {
152 s = format (s, "%U", format_bfd_session_cli, vm, bm, bs);
153 });
Klement Sekera73884482017-02-23 09:26:30 +0100154 /* *INDENT-ON* */
155 vlib_cli_output (vm, "%v", s);
156 vec_free (s);
157 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
158 (u64) pool_elts (bm->sessions));
159 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100160 else if (unformat (line_input, "echo-source"))
Klement Sekera73884482017-02-23 09:26:30 +0100161 {
162 int is_set;
163 u32 sw_if_index;
164 int have_usable_ip4;
165 ip4_address_t ip4;
166 int have_usable_ip6;
167 ip6_address_t ip6;
168 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
169 &have_usable_ip6, &ip6);
170 if (is_set)
171 {
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: ");
178 if (have_usable_ip4)
179 {
180 s = format (s, "%U\n", format_ip4_address, &ip4);
181 }
182 else
183 {
184 s = format (s, "none\n");
185 }
186 s = format (s, "IPv6 address usable as echo source: ");
187 if (have_usable_ip6)
188 {
189 s = format (s, "%U\n", format_ip6_address, &ip6);
190 }
191 else
192 {
193 s = format (s, "none\n");
194 }
195 vlib_cli_output (vm, "%v", s);
196 vec_free (s);
197 }
198 else
199 {
200 vlib_cli_output (vm, "UDP echo source is not set.\n");
201 }
202 }
203 else
204 {
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));
209 }
210 return 0;
211}
212
213/* *INDENT-OFF* */
214VLIB_CLI_COMMAND (show_bfd_command, static) = {
215 .path = "show bfd",
216 .short_help = "show bfd [keys|sessions|echo-source]",
217 .function = show_bfd,
218};
219/* *INDENT-ON* */
220
221static u8 *
222format_vnet_api_errno (u8 * s, va_list * args)
223{
224 vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t);
225#define _(a, b, c) \
226 case b: \
227 s = format (s, "%s", c); \
228 break;
229 switch (api_error)
230 {
231 foreach_vnet_api_error default:s = format (s, "UNKNOWN");
232 break;
233 }
234 return s;
235}
236
237static clib_error_t *
238bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
239 CLIB_UNUSED (vlib_cli_command_t * lmd))
240{
241 clib_error_t *ret = NULL;
242 int have_key_id = 0;
243 u32 key_id = 0;
244 u8 *vec_auth_type = NULL;
245 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
246 u8 *secret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100247 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100248 static const u8 keyed_sha1[] = "keyed-sha1";
249 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
250
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100251 /* Get a line of input. */
252 if (!unformat_user (input, unformat_line_input, line_input))
253 return 0;
254
255 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100256 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100257 if (unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100258 {
259 have_key_id = 1;
260 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100261 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
Klement Sekera73884482017-02-23 09:26:30 +0100262 &vec_auth_type))
263 {
264 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
265 0 == memcmp (vec_auth_type, keyed_sha1,
266 sizeof (keyed_sha1) - 1))
267 {
268 auth_type = BFD_AUTH_TYPE_keyed_sha1;
269 }
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))
274 {
275 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
276 }
277 else
278 {
279 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
280 goto out;
281 }
282 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100283 else
284 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
Klement Sekera73884482017-02-23 09:26:30 +0100285 {
286 /* nothing to do here */
287 }
288 else
289 {
290 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100291 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100292 goto out;
293 }
294 }
295
296 if (!have_key_id)
297 {
298 ret =
299 clib_error_return (0, "required parameter missing: `conf-key-id'");
300 goto out;
301 }
302 if (!vec_auth_type)
303 {
304 ret = clib_error_return (0, "required parameter missing: `type'");
305 goto out;
306 }
307 if (!secret)
308 {
309 ret = clib_error_return (0, "required parameter missing: `secret'");
310 goto out;
311 }
312
313 vnet_api_error_t rv =
314 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
315 if (rv)
316 {
317 ret =
318 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
319 (int) rv, format_vnet_api_errno, rv);
320 }
321
322out:
323 vec_free (vec_auth_type);
324 return ret;
325}
326
327/* *INDENT-OFF* */
328VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
329 .path = "bfd key set",
330 .short_help = "bfd key set"
331 " conf-key-id <id>"
332 " type <keyed-sha1|meticulous-keyed-sha1> "
333 " secret <secret>",
334 .function = bfd_cli_key_add,
335};
336/* *INDENT-ON* */
337
338static clib_error_t *
339bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
340 CLIB_UNUSED (vlib_cli_command_t * lmd))
341{
342 clib_error_t *ret = NULL;
343 u32 key_id = 0;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100344 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100345
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100346 /* Get a line of input. */
347 if (!unformat_user (input, unformat_line_input, line_input))
348 return 0;
349
350 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100351 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100352 if (!unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100353 {
354 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100355 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100356 goto out;
357 }
358 }
359
360 vnet_api_error_t rv = bfd_auth_del_key (key_id);
361 if (rv)
362 {
363 ret =
364 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
365 (int) rv, format_vnet_api_errno, rv);
366 }
367
368out:
369 return ret;
370}
371
372/* *INDENT-OFF* */
373VLIB_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,
377};
378/* *INDENT-ON* */
379
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"
390
391static const unsigned mandatory = 1;
392static const unsigned optional = 0;
393
394#define DECLARE(t, n, s, r, ...) \
395 int have_##n = 0; \
396 t n;
397
398#define UNFORMAT(t, n, s, r, ...) \
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100399 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
Klement Sekera73884482017-02-23 09:26:30 +0100400 { \
401 something_parsed = 1; \
402 have_##n = 1; \
403 }
404
405#define CHECK_MANDATORY(t, n, s, r, ...) \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100406WARN_OFF(tautological-compare) \
Klement Sekera73884482017-02-23 09:26:30 +0100407 if (mandatory == r && !have_##n) \
408 { \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100409 WARN_ON(tautological-compare) \
Klement Sekerae50e8562017-04-04 16:19:48 +0200410 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
Klement Sekera73884482017-02-23 09:26:30 +0100411 goto out; \
412 }
413
414static clib_error_t *
415bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
416 CLIB_UNUSED (vlib_cli_command_t * lmd))
417{
418 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100419 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100420#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")
432
433 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
434
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100435 /* Get a line of input. */
436 if (!unformat_user (input, unformat_line_input, line_input))
437 return 0;
438
439 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100440 {
441 int something_parsed = 0;
442 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
443
444 if (!something_parsed)
445 {
446 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100447 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100448 goto out;
449 }
450 }
451
452 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
453
454 if (1 == have_conf_key_id + have_bfd_key_id)
455 {
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);
459 goto out;
460 }
461
462 if (detect_mult > 255)
463 {
464 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
465 DETECT_MULT_STR, detect_mult);
466 goto out;
467 }
468
469 if (have_bfd_key_id && bfd_key_id > 255)
470 {
471 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
472 BFD_KEY_ID_STR, bfd_key_id);
473 goto out;
474 }
475
476 vnet_api_error_t rv =
477 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
478 required_min_rx,
479 detect_mult, have_conf_key_id, conf_key_id,
480 bfd_key_id);
481 if (rv)
482 {
483 ret =
484 clib_error_return (0,
485 "`bfd_add_add_session' API call failed, rv=%d:%U",
486 (int) rv, format_vnet_api_errno, rv);
487 goto out;
488 }
489
490out:
491 return ret;
492}
493
494/* *INDENT-OFF* */
495VLIB_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> "
504 "["
505 " conf-key-id <config key ID>"
506 " bfd-key-id <BFD key ID>"
507 "]",
508 .function = bfd_cli_udp_session_add,
509};
510/* *INDENT-ON* */
511
512static clib_error_t *
513bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
514 CLIB_UNUSED (vlib_cli_command_t * lmd))
515{
516 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100517 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100518#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")
528
529 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
530
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100531 /* Get a line of input. */
532 if (!unformat_user (input, unformat_line_input, line_input))
533 return 0;
534
535 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100536 {
537 int something_parsed = 0;
538 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
539
540 if (!something_parsed)
541 {
542 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100543 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100544 goto out;
545 }
546 }
547
548 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
549
550 if (detect_mult > 255)
551 {
552 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
553 DETECT_MULT_STR, detect_mult);
554 goto out;
555 }
556
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);
560 if (rv)
561 {
562 ret =
563 clib_error_return (0,
564 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
565 (int) rv, format_vnet_api_errno, rv);
566 goto out;
567 }
568
569out:
570 return ret;
571}
572
573/* *INDENT-OFF* */
574VLIB_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,
584};
585/* *INDENT-ON* */
586
587static clib_error_t *
588bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
589 CLIB_UNUSED (vlib_cli_command_t * lmd))
590{
591 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100592 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100593#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)
600
601 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
602
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100603 /* Get a line of input. */
604 if (!unformat_user (input, unformat_line_input, line_input))
605 return 0;
606
607 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100608 {
609 int something_parsed = 0;
610 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
611
612 if (!something_parsed)
613 {
614 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100615 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100616 goto out;
617 }
618 }
619
620 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
621
622 vnet_api_error_t rv =
623 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
624 if (rv)
625 {
626 ret =
627 clib_error_return (0,
628 "`bfd_udp_del_session' API call failed, rv=%d:%U",
629 (int) rv, format_vnet_api_errno, rv);
630 goto out;
631 }
632
633out:
634 return ret;
635}
636
637/* *INDENT-OFF* */
638VLIB_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"
643 "<peer-address> ",
644 .function = bfd_cli_udp_session_del,
645};
646/* *INDENT-ON* */
647
648static clib_error_t *
649bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
650 CLIB_UNUSED (vlib_cli_command_t * lmd))
651{
652 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100653 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100654#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)
663
664 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
665
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100666 /* Get a line of input. */
667 if (!unformat_user (input, unformat_line_input, line_input))
668 return 0;
669
670 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100671 {
672 int something_parsed = 0;
673 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
674
675 if (!something_parsed)
676 {
677 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100678 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100679 goto out;
680 }
681 }
682
683 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
684
685 u8 admin_up_down;
686 static const char up[] = "up";
687 static const char down[] = "down";
688 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
689 {
690 admin_up_down = 1;
691 }
692 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
693 {
694 admin_up_down = 0;
695 }
696 else
697 {
698 ret =
699 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
700 ADMIN_STR, admin_up_down_token);
701 goto out;
702 }
703 vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr,
704 &peer_addr, admin_up_down);
705 if (rv)
706 {
707 ret =
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);
711 goto out;
712 }
713
714out:
715 return ret;
716}
717
718/* *INDENT-OFF* */
719VLIB_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>"
725 " admin <up|down>",
726 .function = bfd_cli_udp_session_set_flags,
727};
728/* *INDENT-ON* */
729
730static clib_error_t *
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100731bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
732 unformat_input_t * input,
Klement Sekera73884482017-02-23 09:26:30 +0100733 CLIB_UNUSED (vlib_cli_command_t * lmd))
734{
735 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100736 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100737#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")
747
748 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
749
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100750 /* Get a line of input. */
751 if (!unformat_user (input, unformat_line_input, line_input))
752 return 0;
753
754 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100755 {
756 int something_parsed = 0;
757 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
758
759 if (!something_parsed)
760 {
761 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100762 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100763 goto out;
764 }
765 }
766
767 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
768
769 u8 is_delayed = 0;
770 if (have_delayed_token)
771 {
772 static const char yes[] = "yes";
773 static const char no[] = "no";
774 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
775 {
776 is_delayed = 1;
777 }
778 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
779 {
780 is_delayed = 0;
781 }
782 else
783 {
784 ret =
785 clib_error_return (0,
786 "Unrecognized value for `%s' parameter: `%v'",
787 DELAYED_STR, delayed_token);
788 goto out;
789 }
790 }
791
792 if (have_bfd_key_id && bfd_key_id > 255)
793 {
794 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
795 BFD_KEY_ID_STR, bfd_key_id);
796 goto out;
797 }
798
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);
802 if (rv)
803 {
804 ret =
805 clib_error_return (0,
806 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
807 (int) rv, format_vnet_api_errno, rv);
808 goto out;
809 }
810
811out:
812 return ret;
813}
814
815/* *INDENT-OFF* */
816VLIB_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>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100824 " [ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100825 .function = bfd_cli_udp_session_auth_activate,
826};
827
828static clib_error_t *
829bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
830 CLIB_UNUSED (vlib_cli_command_t *lmd))
831{
832 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100833 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100834#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")
842
843 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
844
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100845 /* Get a line of input. */
846 if (!unformat_user (input, unformat_line_input, line_input))
847 return 0;
848
849 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100850 {
851 int something_parsed = 0;
852 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
853
854 if (!something_parsed)
855 {
856 ret = clib_error_return (0, "Unknown input `%U'",
857 format_unformat_error, input);
858 goto out;
859 }
860 }
861
862 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
863
864 u8 is_delayed = 0;
865 if (have_delayed_token)
866 {
867 static const char yes[] = "yes";
868 static const char no[] = "no";
869 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
870 {
871 is_delayed = 1;
872 }
873 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
874 {
875 is_delayed = 0;
876 }
877 else
878 {
879 ret = clib_error_return (
880 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
881 delayed_token);
882 goto out;
883 }
884 }
885
886 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
887 &peer_addr, is_delayed);
888 if (rv)
889 {
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);
893 goto out;
894 }
895
896out:
897 return ret;
898}
899
900/* *INDENT-OFF* */
901VLIB_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>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100907 "[ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100908 .function = bfd_cli_udp_session_auth_deactivate,
909};
910/* *INDENT-ON* */
911
912static clib_error_t *
913bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
914 CLIB_UNUSED (vlib_cli_command_t * lmd))
915{
916 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100917 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100918#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)
921
922 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
923
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100924 /* Get a line of input. */
925 if (!unformat_user (input, unformat_line_input, line_input))
926 return 0;
927
928 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100929 {
930 int something_parsed = 0;
931 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
932
933 if (!something_parsed)
934 {
935 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100936 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100937 goto out;
938 }
939 }
940
941 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
942
943 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
944 if (rv)
945 {
946 ret =
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);
950 goto out;
951 }
952
953out:
954 return ret;
955}
956
957/* *INDENT-OFF* */
958VLIB_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,
962};
963/* *INDENT-ON* */
964
965static clib_error_t *
966bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
967 CLIB_UNUSED (vlib_cli_command_t * lmd))
968{
969 vnet_api_error_t rv = bfd_udp_del_echo_source ();
970 if (rv)
971 {
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);
975 }
976
977 return 0;
978}
979
980/* *INDENT-OFF* */
981VLIB_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,
985};
986/* *INDENT-ON* */
987
988/*
989 * fd.io coding-style-patch-verification: ON
990 *
991 * Local Variables:
992 * eval: (c-set-style "gnu")
993 * End:
994 */