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