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