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