]> git.proxmox.com Git - mirror_frr.git/blame - bfdd/bfdd_cli.c
Merge pull request #13578 from opensourcerouting/fix/ripd_argv_find
[mirror_frr.git] / bfdd / bfdd_cli.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
adc26455
RZ
2/*
3 * BFD daemon CLI implementation.
4 *
5 * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
6 * Rafael Zalamena
adc26455
RZ
7 */
8
8e0c84ff
RZ
9#include <zebra.h>
10
adc26455
RZ
11#include "lib/command.h"
12#include "lib/log.h"
13#include "lib/northbound_cli.h"
14
adc26455 15#include "bfdd/bfdd_cli_clippy.c"
adc26455
RZ
16
17#include "bfd.h"
6c574029 18#include "bfdd_nb.h"
adc26455
RZ
19
20/*
21 * Definitions.
22 */
23#define PEER_STR "Configure peer\n"
24#define INTERFACE_NAME_STR "Configure interface name to use\n"
25#define PEER_IPV4_STR "IPv4 peer address\n"
26#define PEER_IPV6_STR "IPv6 peer address\n"
27#define MHOP_STR "Configure multihop\n"
28#define LOCAL_STR "Configure local address\n"
29#define LOCAL_IPV4_STR "IPv4 local address\n"
30#define LOCAL_IPV6_STR "IPv6 local address\n"
31#define LOCAL_INTF_STR "Configure local interface name to use\n"
32#define VRF_STR "Configure VRF\n"
33#define VRF_NAME_STR "Configure VRF name\n"
34
35/*
36 * Prototypes.
37 */
7d2de131
RZ
38static bool
39bfd_cli_is_single_hop(struct vty *vty)
40{
41 return strstr(VTY_CURR_XPATH, "/single-hop") != NULL;
42}
adc26455 43
17cb53af
IR
44static bool
45bfd_cli_is_profile(struct vty *vty)
46{
47 return strstr(VTY_CURR_XPATH, "/bfd/profile") != NULL;
48}
49
adc26455
RZ
50/*
51 * Functions.
52 */
ca77b518 53DEFPY_YANG_NOSH(
fdf8ac87
RZ
54 bfd_enter, bfd_enter_cmd,
55 "bfd",
56 "Configure BFD peers\n")
57{
58 int ret;
59
60 nb_cli_enqueue_change(vty, "/frr-bfdd:bfdd/bfd", NB_OP_CREATE, NULL);
61 ret = nb_cli_apply_changes(vty, NULL);
62 if (ret == CMD_SUCCESS)
63 VTY_PUSH_XPATH(BFD_NODE, "/frr-bfdd:bfdd/bfd");
64
65 return ret;
66}
67
ca77b518 68DEFUN_YANG(
2a573ff6
RZ
69 bfd_config_reset, bfd_config_reset_cmd,
70 "no bfd",
71 NO_STR
72 "Configure BFD peers\n")
73{
74 nb_cli_enqueue_change(vty, "/frr-bfdd:bfdd/bfd", NB_OP_DESTROY, NULL);
75 return nb_cli_apply_changes(vty, NULL);
76}
77
0287a64a 78void bfd_cli_show_header(struct vty *vty,
25605051
IR
79 const struct lyd_node *dnode
80 __attribute__((__unused__)),
0287a64a
RZ
81 bool show_defaults __attribute__((__unused__)))
82{
83 vty_out(vty, "!\nbfd\n");
84}
85
25605051
IR
86void bfd_cli_show_header_end(struct vty *vty, const struct lyd_node *dnode
87 __attribute__((__unused__)))
0287a64a 88{
07679ad9 89 vty_out(vty, "exit\n");
0287a64a
RZ
90 vty_out(vty, "!\n");
91}
92
ca77b518 93DEFPY_YANG_NOSH(
adc26455
RZ
94 bfd_peer_enter, bfd_peer_enter_cmd,
95 "peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]",
96 PEER_STR
97 PEER_IPV4_STR
98 PEER_IPV6_STR
99 MHOP_STR
100 LOCAL_STR
101 LOCAL_IPV4_STR
102 LOCAL_IPV6_STR
103 INTERFACE_STR
104 LOCAL_INTF_STR
105 VRF_STR
106 VRF_NAME_STR)
107{
108 int ret, slen;
e6426ace 109 char source_str[INET6_ADDRSTRLEN + 32];
284062bf 110 char xpath[XPATH_MAXLEN], xpath_srcaddr[XPATH_MAXLEN + 32];
adc26455 111
4cce733f
IR
112 if (multihop) {
113 if (!local_address_str) {
874ca769
IR
114 vty_out(vty,
115 "%% local-address is required when using multihop\n");
116 return CMD_WARNING_CONFIG_FAILED;
117 }
118 if (ifname) {
119 vty_out(vty,
120 "%% interface is prohibited when using multihop\n");
4cce733f
IR
121 return CMD_WARNING_CONFIG_FAILED;
122 }
adc26455
RZ
123 snprintf(source_str, sizeof(source_str), "[source-addr='%s']",
124 local_address_str);
4cce733f 125 } else
adc26455
RZ
126 source_str[0] = 0;
127
128 slen = snprintf(xpath, sizeof(xpath),
129 "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']",
130 multihop ? "multi-hop" : "single-hop", source_str,
131 peer_str);
132 if (ifname)
133 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
134 "[interface='%s']", ifname);
874ca769 135 else if (!multihop)
adc26455 136 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
4ec8e74b 137 "[interface='*']");
adc26455
RZ
138 if (vrf)
139 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf);
140 else
141 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']",
142 VRF_DEFAULT_NAME);
143
144 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
284062bf
RZ
145 if (multihop == NULL && local_address_str != NULL) {
146 snprintf(xpath_srcaddr, sizeof(xpath_srcaddr),
147 "%s/source-addr", xpath);
148 nb_cli_enqueue_change(vty, xpath_srcaddr, NB_OP_MODIFY,
149 local_address_str);
150 }
adc26455 151
fdf8ac87 152 /* Apply settings immediately. */
adc26455
RZ
153 ret = nb_cli_apply_changes(vty, NULL);
154 if (ret == CMD_SUCCESS)
155 VTY_PUSH_XPATH(BFD_PEER_NODE, xpath);
156
157 return ret;
158}
159
ca77b518 160DEFPY_YANG(
adc26455
RZ
161 bfd_no_peer, bfd_no_peer_cmd,
162 "no peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]",
163 NO_STR
164 PEER_STR
165 PEER_IPV4_STR
166 PEER_IPV6_STR
167 MHOP_STR
168 LOCAL_STR
169 LOCAL_IPV4_STR
170 LOCAL_IPV6_STR
171 INTERFACE_STR
172 LOCAL_INTF_STR
173 VRF_STR
174 VRF_NAME_STR)
175{
176 int slen;
177 char xpath[XPATH_MAXLEN];
e6426ace 178 char source_str[INET6_ADDRSTRLEN + 32];
adc26455 179
874ca769
IR
180 if (multihop) {
181 if (!local_address_str) {
182 vty_out(vty,
183 "%% local-address is required when using multihop\n");
184 return CMD_WARNING_CONFIG_FAILED;
185 }
186 if (ifname) {
187 vty_out(vty,
188 "%% interface is prohibited when using multihop\n");
189 return CMD_WARNING_CONFIG_FAILED;
190 }
adc26455
RZ
191 snprintf(source_str, sizeof(source_str), "[source-addr='%s']",
192 local_address_str);
874ca769 193 } else
adc26455
RZ
194 source_str[0] = 0;
195
196 slen = snprintf(xpath, sizeof(xpath),
197 "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']",
198 multihop ? "multi-hop" : "single-hop", source_str,
199 peer_str);
200 if (ifname)
201 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
202 "[interface='%s']", ifname);
874ca769 203 else if (!multihop)
adc26455 204 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
4ec8e74b 205 "[interface='*']");
adc26455
RZ
206 if (vrf)
207 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf);
208 else
209 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']",
210 VRF_DEFAULT_NAME);
211
212 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
213
214 /* Apply settings immediatly. */
215 return nb_cli_apply_changes(vty, NULL);
216}
217
25605051 218static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode,
0287a64a
RZ
219 bool show_defaults __attribute__((__unused__)),
220 bool mhop)
221{
222 const char *vrf = yang_dnode_get_string(dnode, "./vrf");
0287a64a
RZ
223
224 vty_out(vty, " peer %s",
225 yang_dnode_get_string(dnode, "./dest-addr"));
226
227 if (mhop)
228 vty_out(vty, " multihop");
229
230 if (yang_dnode_exists(dnode, "./source-addr"))
231 vty_out(vty, " local-address %s",
232 yang_dnode_get_string(dnode, "./source-addr"));
233
234 if (strcmp(vrf, VRF_DEFAULT_NAME))
235 vty_out(vty, " vrf %s", vrf);
236
874ca769
IR
237 if (!mhop) {
238 const char *ifname =
239 yang_dnode_get_string(dnode, "./interface");
240 if (strcmp(ifname, "*"))
241 vty_out(vty, " interface %s", ifname);
242 }
0287a64a
RZ
243
244 vty_out(vty, "\n");
245}
246
25605051 247void bfd_cli_show_single_hop_peer(struct vty *vty, const struct lyd_node *dnode,
0287a64a
RZ
248 bool show_defaults)
249{
250 _bfd_cli_show_peer(vty, dnode, show_defaults, false);
251}
252
25605051
IR
253void bfd_cli_show_multi_hop_peer(struct vty *vty, const struct lyd_node *dnode,
254 bool show_defaults)
0287a64a
RZ
255{
256 _bfd_cli_show_peer(vty, dnode, show_defaults, true);
257}
258
25605051
IR
259void bfd_cli_show_peer_end(struct vty *vty, const struct lyd_node *dnode
260 __attribute__((__unused__)))
0287a64a 261{
07679ad9 262 vty_out(vty, " exit\n");
0287a64a
RZ
263 vty_out(vty, " !\n");
264}
265
ca77b518 266DEFPY_YANG(
adc26455
RZ
267 bfd_peer_shutdown, bfd_peer_shutdown_cmd,
268 "[no] shutdown",
269 NO_STR
7818c5fb 270 "Disable BFD peer\n")
adc26455
RZ
271{
272 nb_cli_enqueue_change(vty, "./administrative-down", NB_OP_MODIFY,
273 no ? "false" : "true");
274 return nb_cli_apply_changes(vty, NULL);
275}
276
25605051 277void bfd_cli_show_shutdown(struct vty *vty, const struct lyd_node *dnode,
0287a64a
RZ
278 bool show_defaults)
279{
613bcbc5
IR
280 vty_out(vty, " %sshutdown\n",
281 yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
0287a64a
RZ
282}
283
1a2e2fff
RZ
284DEFPY_YANG(
285 bfd_peer_passive, bfd_peer_passive_cmd,
286 "[no] passive-mode",
287 NO_STR
288 "Don't attempt to start sessions\n")
289{
290 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY,
291 no ? "false" : "true");
292 return nb_cli_apply_changes(vty, NULL);
293}
294
25605051 295void bfd_cli_show_passive(struct vty *vty, const struct lyd_node *dnode,
1a2e2fff
RZ
296 bool show_defaults)
297{
613bcbc5
IR
298 vty_out(vty, " %spassive-mode\n",
299 yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
1a2e2fff
RZ
300}
301
262e1d25
RZ
302DEFPY_YANG(
303 bfd_peer_minimum_ttl, bfd_peer_minimum_ttl_cmd,
304 "[no] minimum-ttl (1-254)$ttl",
305 NO_STR
306 "Expect packets with at least this TTL\n"
307 "Minimum TTL expected\n")
308{
7d2de131
RZ
309 if (bfd_cli_is_single_hop(vty)) {
310 vty_out(vty, "%% Minimum TTL is only available for multi hop sessions.\n");
311 return CMD_WARNING_CONFIG_FAILED;
312 }
313
262e1d25
RZ
314 if (no)
315 nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_DESTROY,
316 NULL);
317 else
318 nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_MODIFY,
319 ttl_str);
320 return nb_cli_apply_changes(vty, NULL);
321}
322
323DEFPY_YANG(
324 no_bfd_peer_minimum_ttl, no_bfd_peer_minimum_ttl_cmd,
325 "no minimum-ttl",
326 NO_STR
327 "Expect packets with at least this TTL\n")
328{
329 nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_DESTROY, NULL);
330 return nb_cli_apply_changes(vty, NULL);
331}
332
25605051 333void bfd_cli_show_minimum_ttl(struct vty *vty, const struct lyd_node *dnode,
262e1d25
RZ
334 bool show_defaults)
335{
613bcbc5 336 vty_out(vty, " minimum-ttl %s\n", yang_dnode_get_string(dnode, NULL));
262e1d25
RZ
337}
338
ca77b518 339DEFPY_YANG(
adc26455
RZ
340 bfd_peer_mult, bfd_peer_mult_cmd,
341 "detect-multiplier (2-255)$multiplier",
342 "Configure peer detection multiplier\n"
343 "Configure peer detection multiplier value\n")
344{
345 nb_cli_enqueue_change(vty, "./detection-multiplier", NB_OP_MODIFY,
346 multiplier_str);
347 return nb_cli_apply_changes(vty, NULL);
348}
349
25605051 350void bfd_cli_show_mult(struct vty *vty, const struct lyd_node *dnode,
0287a64a
RZ
351 bool show_defaults)
352{
613bcbc5
IR
353 vty_out(vty, " detect-multiplier %s\n",
354 yang_dnode_get_string(dnode, NULL));
0287a64a
RZ
355}
356
ca77b518 357DEFPY_YANG(
adc26455
RZ
358 bfd_peer_rx, bfd_peer_rx_cmd,
359 "receive-interval (10-60000)$interval",
360 "Configure peer receive interval\n"
361 "Configure peer receive interval value in milliseconds\n")
362{
8a676ce6
RZ
363 char value[32];
364
365 snprintf(value, sizeof(value), "%ld", interval * 1000);
adc26455 366 nb_cli_enqueue_change(vty, "./required-receive-interval", NB_OP_MODIFY,
8a676ce6
RZ
367 value);
368
adc26455
RZ
369 return nb_cli_apply_changes(vty, NULL);
370}
371
25605051 372void bfd_cli_show_rx(struct vty *vty, const struct lyd_node *dnode,
0287a64a
RZ
373 bool show_defaults)
374{
613bcbc5 375 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
8a676ce6 376
613bcbc5 377 vty_out(vty, " receive-interval %u\n", value / 1000);
0287a64a
RZ
378}
379
ca77b518 380DEFPY_YANG(
adc26455
RZ
381 bfd_peer_tx, bfd_peer_tx_cmd,
382 "transmit-interval (10-60000)$interval",
383 "Configure peer transmit interval\n"
384 "Configure peer transmit interval value in milliseconds\n")
385{
8a676ce6
RZ
386 char value[32];
387
388 snprintf(value, sizeof(value), "%ld", interval * 1000);
adc26455 389 nb_cli_enqueue_change(vty, "./desired-transmission-interval",
8a676ce6
RZ
390 NB_OP_MODIFY, value);
391
adc26455
RZ
392 return nb_cli_apply_changes(vty, NULL);
393}
394
25605051 395void bfd_cli_show_tx(struct vty *vty, const struct lyd_node *dnode,
0287a64a
RZ
396 bool show_defaults)
397{
613bcbc5 398 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
8a676ce6 399
613bcbc5 400 vty_out(vty, " transmit-interval %u\n", value / 1000);
0287a64a
RZ
401}
402
ca77b518 403DEFPY_YANG(
adc26455
RZ
404 bfd_peer_echo, bfd_peer_echo_cmd,
405 "[no] echo-mode",
406 NO_STR
407 "Configure echo mode\n")
408{
17cb53af 409 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
57485b0b 410 vty_out(vty,
411 "%% Echo mode is only available for single hop sessions.\n");
7d2de131
RZ
412 return CMD_WARNING_CONFIG_FAILED;
413 }
414
f1825d57 415 if (!no && !bglobal.bg_use_dplane) {
57485b0b 416#ifdef BFD_LINUX
417 vty_out(vty,
418 "%% Echo mode works correctly for IPv4, but only works when the peer is also FRR for IPv6.\n");
419#else
420 vty_out(vty,
421 "%% Current implementation of echo mode works only when the peer is also FRR.\n");
422#endif /* BFD_LINUX */
f1825d57
IR
423 }
424
adc26455
RZ
425 nb_cli_enqueue_change(vty, "./echo-mode", NB_OP_MODIFY,
426 no ? "false" : "true");
427 return nb_cli_apply_changes(vty, NULL);
428}
429
25605051
IR
430void bfd_cli_show_echo(struct vty *vty, const struct lyd_node *dnode,
431 bool show_defaults)
0287a64a 432{
613bcbc5
IR
433 vty_out(vty, " %secho-mode\n",
434 yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
0287a64a
RZ
435}
436
ca77b518 437DEFPY_YANG(
adc26455
RZ
438 bfd_peer_echo_interval, bfd_peer_echo_interval_cmd,
439 "echo-interval (10-60000)$interval",
4df3e31c
IR
440 "Configure peer echo intervals\n"
441 "Configure peer echo rx/tx intervals value in milliseconds\n")
adc26455 442{
8a676ce6
RZ
443 char value[32];
444
17cb53af 445 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
7d2de131
RZ
446 vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
447 return CMD_WARNING_CONFIG_FAILED;
448 }
449
8a676ce6 450 snprintf(value, sizeof(value), "%ld", interval * 1000);
adc26455 451 nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval",
8a676ce6 452 NB_OP_MODIFY, value);
4df3e31c
IR
453 nb_cli_enqueue_change(vty, "./required-echo-receive-interval",
454 NB_OP_MODIFY, value);
455
456 return nb_cli_apply_changes(vty, NULL);
457}
458
459DEFPY_YANG(
460 bfd_peer_echo_transmit_interval, bfd_peer_echo_transmit_interval_cmd,
461 "echo transmit-interval (10-60000)$interval",
462 "Configure peer echo intervals\n"
463 "Configure desired transmit interval\n"
464 "Configure interval value in milliseconds\n")
465{
466 char value[32];
467
468 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
469 vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
470 return CMD_WARNING_CONFIG_FAILED;
471 }
472
473 snprintf(value, sizeof(value), "%ld", interval * 1000);
474 nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval",
475 NB_OP_MODIFY, value);
476
477 return nb_cli_apply_changes(vty, NULL);
478}
479
25605051
IR
480void bfd_cli_show_desired_echo_transmission_interval(
481 struct vty *vty, const struct lyd_node *dnode, bool show_defaults)
4df3e31c 482{
613bcbc5 483 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
4df3e31c 484
613bcbc5 485 vty_out(vty, " echo transmit-interval %u\n", value / 1000);
4df3e31c
IR
486}
487
488DEFPY_YANG(
489 bfd_peer_echo_receive_interval, bfd_peer_echo_receive_interval_cmd,
490 "echo receive-interval <disabled$disabled|(10-60000)$interval>",
491 "Configure peer echo intervals\n"
492 "Configure required receive interval\n"
493 "Disable echo packets receive\n"
494 "Configure interval value in milliseconds\n")
495{
496 char value[32];
497
498 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
499 vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
500 return CMD_WARNING_CONFIG_FAILED;
501 }
502
503 if (disabled)
504 snprintf(value, sizeof(value), "0");
505 else
506 snprintf(value, sizeof(value), "%ld", interval * 1000);
507
508 nb_cli_enqueue_change(vty, "./required-echo-receive-interval",
509 NB_OP_MODIFY, value);
8a676ce6 510
adc26455
RZ
511 return nb_cli_apply_changes(vty, NULL);
512}
513
4df3e31c 514void bfd_cli_show_required_echo_receive_interval(struct vty *vty,
25605051
IR
515 const struct lyd_node *dnode,
516 bool show_defaults)
0287a64a 517{
613bcbc5
IR
518 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
519
520 if (value)
521 vty_out(vty, " echo receive-interval %u\n", value / 1000);
522 else
523 vty_out(vty, " echo receive-interval disabled\n");
0287a64a
RZ
524}
525
d40d6c22
RZ
526/*
527 * Profile commands.
528 */
ca77b518 529DEFPY_YANG_NOSH(bfd_profile, bfd_profile_cmd,
0a01b0f4 530 "profile BFDPROF$name",
d40d6c22
RZ
531 BFD_PROFILE_STR
532 BFD_PROFILE_NAME_STR)
533{
ccc9ada8
RZ
534 char xpath[XPATH_MAXLEN];
535 int rv;
536
537 snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/profile[name='%s']",
538 name);
539
540 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
541
542 /* Apply settings immediately. */
543 rv = nb_cli_apply_changes(vty, NULL);
544 if (rv == CMD_SUCCESS)
545 VTY_PUSH_XPATH(BFD_PROFILE_NODE, xpath);
546
d40d6c22
RZ
547 return CMD_SUCCESS;
548}
549
ca77b518 550DEFPY_YANG(no_bfd_profile, no_bfd_profile_cmd,
d40d6c22
RZ
551 "no profile BFDPROF$name",
552 NO_STR
553 BFD_PROFILE_STR
554 BFD_PROFILE_NAME_STR)
555{
ccc9ada8
RZ
556 char xpath[XPATH_MAXLEN];
557
558 snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/profile[name='%s']",
559 name);
560
561 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
562
563 /* Apply settings immediately. */
564 return nb_cli_apply_changes(vty, NULL);
565}
566
25605051 567void bfd_cli_show_profile(struct vty *vty, const struct lyd_node *dnode,
ccc9ada8
RZ
568 bool show_defaults)
569{
570 vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, "./name"));
571}
572
ca77b518 573ALIAS_YANG(bfd_peer_mult, bfd_profile_mult_cmd,
ccc9ada8
RZ
574 "detect-multiplier (2-255)$multiplier",
575 "Configure peer detection multiplier\n"
576 "Configure peer detection multiplier value\n")
577
ca77b518 578ALIAS_YANG(bfd_peer_tx, bfd_profile_tx_cmd,
ccc9ada8
RZ
579 "transmit-interval (10-60000)$interval",
580 "Configure peer transmit interval\n"
581 "Configure peer transmit interval value in milliseconds\n")
582
ca77b518 583ALIAS_YANG(bfd_peer_rx, bfd_profile_rx_cmd,
ccc9ada8
RZ
584 "receive-interval (10-60000)$interval",
585 "Configure peer receive interval\n"
586 "Configure peer receive interval value in milliseconds\n")
587
ca77b518 588ALIAS_YANG(bfd_peer_shutdown, bfd_profile_shutdown_cmd,
ccc9ada8
RZ
589 "[no] shutdown",
590 NO_STR
591 "Disable BFD peer\n")
592
1a2e2fff
RZ
593ALIAS_YANG(bfd_peer_passive, bfd_profile_passive_cmd,
594 "[no] passive-mode",
595 NO_STR
596 "Don't attempt to start sessions\n")
597
262e1d25
RZ
598ALIAS_YANG(bfd_peer_minimum_ttl, bfd_profile_minimum_ttl_cmd,
599 "[no] minimum-ttl (1-254)$ttl",
600 NO_STR
601 "Expect packets with at least this TTL\n"
602 "Minimum TTL expected\n")
603
604ALIAS_YANG(no_bfd_peer_minimum_ttl, no_bfd_profile_minimum_ttl_cmd,
605 "no minimum-ttl",
606 NO_STR
607 "Expect packets with at least this TTL\n")
608
ca77b518 609ALIAS_YANG(bfd_peer_echo, bfd_profile_echo_cmd,
ccc9ada8
RZ
610 "[no] echo-mode",
611 NO_STR
612 "Configure echo mode\n")
613
ca77b518 614ALIAS_YANG(bfd_peer_echo_interval, bfd_profile_echo_interval_cmd,
ccc9ada8
RZ
615 "echo-interval (10-60000)$interval",
616 "Configure peer echo interval\n"
617 "Configure peer echo interval value in milliseconds\n")
618
4df3e31c
IR
619ALIAS_YANG(
620 bfd_peer_echo_transmit_interval, bfd_profile_echo_transmit_interval_cmd,
621 "echo transmit-interval (10-60000)$interval",
622 "Configure peer echo intervals\n"
623 "Configure desired transmit interval\n"
624 "Configure interval value in milliseconds\n")
625
626ALIAS_YANG(
627 bfd_peer_echo_receive_interval, bfd_profile_echo_receive_interval_cmd,
628 "echo receive-interval <disabled$disabled|(10-60000)$interval>",
629 "Configure peer echo intervals\n"
630 "Configure required receive interval\n"
631 "Disable echo packets receive\n"
632 "Configure interval value in milliseconds\n")
633
ca77b518 634DEFPY_YANG(bfd_peer_profile, bfd_peer_profile_cmd,
ccc9ada8
RZ
635 "[no] profile BFDPROF$pname",
636 NO_STR
637 "Use BFD profile settings\n"
638 BFD_PROFILE_NAME_STR)
639{
640 if (no)
641 nb_cli_enqueue_change(vty, "./profile", NB_OP_DESTROY, NULL);
642 else
643 nb_cli_enqueue_change(vty, "./profile", NB_OP_MODIFY, pname);
644
645 return nb_cli_apply_changes(vty, NULL);
646}
647
25605051 648void bfd_cli_peer_profile_show(struct vty *vty, const struct lyd_node *dnode,
ccc9ada8
RZ
649 bool show_defaults)
650{
651 vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, NULL));
d40d6c22
RZ
652}
653
654struct cmd_node bfd_profile_node = {
655 .name = "bfd profile",
656 .node = BFD_PROFILE_NODE,
657 .parent_node = BFD_NODE,
658 .prompt = "%s(config-bfd-profile)# ",
659};
660
ccc9ada8
RZ
661static void bfd_profile_var(vector comps, struct cmd_token *token)
662{
663 extern struct bfdproflist bplist;
664 struct bfd_profile *bp;
665
666 TAILQ_FOREACH (bp, &bplist, entry) {
667 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, bp->name));
668 }
669}
670
671static const struct cmd_variable_handler bfd_vars[] = {
672 {.tokenname = "BFDPROF", .completions = bfd_profile_var},
673 {.completions = NULL}
674};
675
adc26455
RZ
676void
677bfdd_cli_init(void)
678{
fdf8ac87 679 install_element(CONFIG_NODE, &bfd_enter_cmd);
2a573ff6
RZ
680 install_element(CONFIG_NODE, &bfd_config_reset_cmd);
681
adc26455
RZ
682 install_element(BFD_NODE, &bfd_peer_enter_cmd);
683 install_element(BFD_NODE, &bfd_no_peer_cmd);
684
685 install_element(BFD_PEER_NODE, &bfd_peer_shutdown_cmd);
686 install_element(BFD_PEER_NODE, &bfd_peer_mult_cmd);
687 install_element(BFD_PEER_NODE, &bfd_peer_rx_cmd);
688 install_element(BFD_PEER_NODE, &bfd_peer_tx_cmd);
689 install_element(BFD_PEER_NODE, &bfd_peer_echo_cmd);
690 install_element(BFD_PEER_NODE, &bfd_peer_echo_interval_cmd);
4df3e31c
IR
691 install_element(BFD_PEER_NODE, &bfd_peer_echo_transmit_interval_cmd);
692 install_element(BFD_PEER_NODE, &bfd_peer_echo_receive_interval_cmd);
ccc9ada8 693 install_element(BFD_PEER_NODE, &bfd_peer_profile_cmd);
1a2e2fff 694 install_element(BFD_PEER_NODE, &bfd_peer_passive_cmd);
262e1d25
RZ
695 install_element(BFD_PEER_NODE, &bfd_peer_minimum_ttl_cmd);
696 install_element(BFD_PEER_NODE, &no_bfd_peer_minimum_ttl_cmd);
d40d6c22
RZ
697
698 /* Profile commands. */
ccc9ada8
RZ
699 cmd_variable_handler_register(bfd_vars);
700
d40d6c22
RZ
701 install_node(&bfd_profile_node);
702 install_default(BFD_PROFILE_NODE);
703
704 install_element(BFD_NODE, &bfd_profile_cmd);
705 install_element(BFD_NODE, &no_bfd_profile_cmd);
ccc9ada8
RZ
706
707 install_element(BFD_PROFILE_NODE, &bfd_profile_mult_cmd);
708 install_element(BFD_PROFILE_NODE, &bfd_profile_tx_cmd);
709 install_element(BFD_PROFILE_NODE, &bfd_profile_rx_cmd);
710 install_element(BFD_PROFILE_NODE, &bfd_profile_shutdown_cmd);
711 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_cmd);
712 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_interval_cmd);
4df3e31c
IR
713 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_transmit_interval_cmd);
714 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_receive_interval_cmd);
1a2e2fff 715 install_element(BFD_PROFILE_NODE, &bfd_profile_passive_cmd);
262e1d25
RZ
716 install_element(BFD_PROFILE_NODE, &bfd_profile_minimum_ttl_cmd);
717 install_element(BFD_PROFILE_NODE, &no_bfd_profile_minimum_ttl_cmd);
adc26455 718}