]>
Commit | Line | Data |
---|---|---|
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 |
54 | static bool |
55 | bfd_cli_is_single_hop(struct vty *vty) | |
56 | { | |
57 | return strstr(VTY_CURR_XPATH, "/single-hop") != NULL; | |
58 | } | |
adc26455 | 59 | |
17cb53af IR |
60 | static bool |
61 | bfd_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 | 69 | DEFPY_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 | 84 | DEFUN_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 |
94 | void 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 | ||
101 | void bfd_cli_show_header_end(struct vty *vty, | |
102 | struct lyd_node *dnode __attribute__((__unused__))) | |
103 | { | |
104 | vty_out(vty, "!\n"); | |
105 | } | |
106 | ||
ca77b518 | 107 | DEFPY_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 | 168 | DEFPY_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 |
216 | static 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 | ||
242 | void 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 | ||
249 | void 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 | ||
256 | void bfd_cli_show_peer_end(struct vty *vty, | |
257 | struct lyd_node *dnode __attribute__((__unused__))) | |
258 | { | |
259 | vty_out(vty, " !\n"); | |
260 | } | |
261 | ||
ca77b518 | 262 | DEFPY_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 |
273 | void bfd_cli_show_shutdown(struct vty *vty, struct lyd_node *dnode, |
274 | bool show_defaults) | |
275 | { | |
276 | if (show_defaults) | |
59dad813 | 277 | vty_out(vty, " no shutdown\n"); |
0287a64a RZ |
278 | else |
279 | vty_out(vty, " %sshutdown\n", | |
280 | yang_dnode_get_bool(dnode, NULL) ? "" : "no "); | |
281 | } | |
282 | ||
1a2e2fff RZ |
283 | DEFPY_YANG( |
284 | bfd_peer_passive, bfd_peer_passive_cmd, | |
285 | "[no] passive-mode", | |
286 | NO_STR | |
287 | "Don't attempt to start sessions\n") | |
288 | { | |
289 | nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, | |
290 | no ? "false" : "true"); | |
291 | return nb_cli_apply_changes(vty, NULL); | |
292 | } | |
293 | ||
294 | void bfd_cli_show_passive(struct vty *vty, struct lyd_node *dnode, | |
295 | bool show_defaults) | |
296 | { | |
297 | if (show_defaults) | |
298 | vty_out(vty, " no passive-mode\n"); | |
299 | else | |
300 | vty_out(vty, " %spassive-mode\n", | |
301 | yang_dnode_get_bool(dnode, NULL) ? "" : "no "); | |
302 | } | |
303 | ||
262e1d25 RZ |
304 | DEFPY_YANG( |
305 | bfd_peer_minimum_ttl, bfd_peer_minimum_ttl_cmd, | |
306 | "[no] minimum-ttl (1-254)$ttl", | |
307 | NO_STR | |
308 | "Expect packets with at least this TTL\n" | |
309 | "Minimum TTL expected\n") | |
310 | { | |
7d2de131 RZ |
311 | if (bfd_cli_is_single_hop(vty)) { |
312 | vty_out(vty, "%% Minimum TTL is only available for multi hop sessions.\n"); | |
313 | return CMD_WARNING_CONFIG_FAILED; | |
314 | } | |
315 | ||
262e1d25 RZ |
316 | if (no) |
317 | nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_DESTROY, | |
318 | NULL); | |
319 | else | |
320 | nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_MODIFY, | |
321 | ttl_str); | |
322 | return nb_cli_apply_changes(vty, NULL); | |
323 | } | |
324 | ||
325 | DEFPY_YANG( | |
326 | no_bfd_peer_minimum_ttl, no_bfd_peer_minimum_ttl_cmd, | |
327 | "no minimum-ttl", | |
328 | NO_STR | |
329 | "Expect packets with at least this TTL\n") | |
330 | { | |
331 | nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_DESTROY, NULL); | |
332 | return nb_cli_apply_changes(vty, NULL); | |
333 | } | |
334 | ||
335 | void bfd_cli_show_minimum_ttl(struct vty *vty, struct lyd_node *dnode, | |
336 | bool show_defaults) | |
337 | { | |
338 | if (show_defaults) | |
339 | vty_out(vty, " minimum-ttl 254\n"); | |
340 | else | |
341 | vty_out(vty, " minimum-ttl %s\n", | |
342 | yang_dnode_get_string(dnode, NULL)); | |
343 | } | |
344 | ||
ca77b518 | 345 | DEFPY_YANG( |
adc26455 RZ |
346 | bfd_peer_mult, bfd_peer_mult_cmd, |
347 | "detect-multiplier (2-255)$multiplier", | |
348 | "Configure peer detection multiplier\n" | |
349 | "Configure peer detection multiplier value\n") | |
350 | { | |
351 | nb_cli_enqueue_change(vty, "./detection-multiplier", NB_OP_MODIFY, | |
352 | multiplier_str); | |
353 | return nb_cli_apply_changes(vty, NULL); | |
354 | } | |
355 | ||
0287a64a RZ |
356 | void bfd_cli_show_mult(struct vty *vty, struct lyd_node *dnode, |
357 | bool show_defaults) | |
358 | { | |
359 | if (show_defaults) | |
360 | vty_out(vty, " detect-multiplier %d\n", | |
361 | BFD_DEFDETECTMULT); | |
362 | else | |
363 | vty_out(vty, " detect-multiplier %s\n", | |
364 | yang_dnode_get_string(dnode, NULL)); | |
365 | } | |
366 | ||
ca77b518 | 367 | DEFPY_YANG( |
adc26455 RZ |
368 | bfd_peer_rx, bfd_peer_rx_cmd, |
369 | "receive-interval (10-60000)$interval", | |
370 | "Configure peer receive interval\n" | |
371 | "Configure peer receive interval value in milliseconds\n") | |
372 | { | |
8a676ce6 RZ |
373 | char value[32]; |
374 | ||
375 | snprintf(value, sizeof(value), "%ld", interval * 1000); | |
adc26455 | 376 | nb_cli_enqueue_change(vty, "./required-receive-interval", NB_OP_MODIFY, |
8a676ce6 RZ |
377 | value); |
378 | ||
adc26455 RZ |
379 | return nb_cli_apply_changes(vty, NULL); |
380 | } | |
381 | ||
0287a64a RZ |
382 | void bfd_cli_show_rx(struct vty *vty, struct lyd_node *dnode, |
383 | bool show_defaults) | |
384 | { | |
8a676ce6 RZ |
385 | uint32_t value; |
386 | ||
0287a64a RZ |
387 | if (show_defaults) |
388 | vty_out(vty, " receive-interval %d\n", | |
389 | BFD_DEFREQUIREDMINRX); | |
8a676ce6 RZ |
390 | else { |
391 | value = yang_dnode_get_uint32(dnode, NULL); | |
6cde4b45 | 392 | vty_out(vty, " receive-interval %u\n", value / 1000); |
8a676ce6 | 393 | } |
0287a64a RZ |
394 | } |
395 | ||
ca77b518 | 396 | DEFPY_YANG( |
adc26455 RZ |
397 | bfd_peer_tx, bfd_peer_tx_cmd, |
398 | "transmit-interval (10-60000)$interval", | |
399 | "Configure peer transmit interval\n" | |
400 | "Configure peer transmit interval value in milliseconds\n") | |
401 | { | |
8a676ce6 RZ |
402 | char value[32]; |
403 | ||
404 | snprintf(value, sizeof(value), "%ld", interval * 1000); | |
adc26455 | 405 | nb_cli_enqueue_change(vty, "./desired-transmission-interval", |
8a676ce6 RZ |
406 | NB_OP_MODIFY, value); |
407 | ||
adc26455 RZ |
408 | return nb_cli_apply_changes(vty, NULL); |
409 | } | |
410 | ||
0287a64a RZ |
411 | void bfd_cli_show_tx(struct vty *vty, struct lyd_node *dnode, |
412 | bool show_defaults) | |
413 | { | |
8a676ce6 RZ |
414 | uint32_t value; |
415 | ||
0287a64a RZ |
416 | if (show_defaults) |
417 | vty_out(vty, " transmit-interval %d\n", | |
418 | BFD_DEFDESIREDMINTX); | |
8a676ce6 RZ |
419 | else { |
420 | value = yang_dnode_get_uint32(dnode, NULL); | |
6cde4b45 | 421 | vty_out(vty, " transmit-interval %u\n", value / 1000); |
8a676ce6 | 422 | } |
0287a64a RZ |
423 | } |
424 | ||
ca77b518 | 425 | DEFPY_YANG( |
adc26455 RZ |
426 | bfd_peer_echo, bfd_peer_echo_cmd, |
427 | "[no] echo-mode", | |
428 | NO_STR | |
429 | "Configure echo mode\n") | |
430 | { | |
17cb53af | 431 | if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) { |
7d2de131 RZ |
432 | vty_out(vty, "%% Echo mode is only available for single hop sessions.\n"); |
433 | return CMD_WARNING_CONFIG_FAILED; | |
434 | } | |
435 | ||
f1825d57 IR |
436 | if (!no && !bglobal.bg_use_dplane) { |
437 | vty_out(vty, "%% Current implementation of echo mode works only when the peer is also FRR.\n"); | |
438 | } | |
439 | ||
adc26455 RZ |
440 | nb_cli_enqueue_change(vty, "./echo-mode", NB_OP_MODIFY, |
441 | no ? "false" : "true"); | |
442 | return nb_cli_apply_changes(vty, NULL); | |
443 | } | |
444 | ||
0287a64a RZ |
445 | void bfd_cli_show_echo(struct vty *vty, struct lyd_node *dnode, |
446 | bool show_defaults) | |
447 | { | |
448 | if (show_defaults) | |
449 | vty_out(vty, " no echo-mode\n"); | |
450 | else | |
451 | vty_out(vty, " %secho-mode\n", | |
452 | yang_dnode_get_bool(dnode, NULL) ? "" : "no "); | |
453 | } | |
454 | ||
ca77b518 | 455 | DEFPY_YANG( |
adc26455 RZ |
456 | bfd_peer_echo_interval, bfd_peer_echo_interval_cmd, |
457 | "echo-interval (10-60000)$interval", | |
4df3e31c IR |
458 | "Configure peer echo intervals\n" |
459 | "Configure peer echo rx/tx intervals value in milliseconds\n") | |
adc26455 | 460 | { |
8a676ce6 RZ |
461 | char value[32]; |
462 | ||
17cb53af | 463 | if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) { |
7d2de131 RZ |
464 | vty_out(vty, "%% Echo mode is only available for single hop sessions.\n"); |
465 | return CMD_WARNING_CONFIG_FAILED; | |
466 | } | |
467 | ||
8a676ce6 | 468 | snprintf(value, sizeof(value), "%ld", interval * 1000); |
adc26455 | 469 | nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval", |
8a676ce6 | 470 | NB_OP_MODIFY, value); |
4df3e31c IR |
471 | nb_cli_enqueue_change(vty, "./required-echo-receive-interval", |
472 | NB_OP_MODIFY, value); | |
473 | ||
474 | return nb_cli_apply_changes(vty, NULL); | |
475 | } | |
476 | ||
477 | DEFPY_YANG( | |
478 | bfd_peer_echo_transmit_interval, bfd_peer_echo_transmit_interval_cmd, | |
479 | "echo transmit-interval (10-60000)$interval", | |
480 | "Configure peer echo intervals\n" | |
481 | "Configure desired transmit interval\n" | |
482 | "Configure interval value in milliseconds\n") | |
483 | { | |
484 | char value[32]; | |
485 | ||
486 | if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) { | |
487 | vty_out(vty, "%% Echo mode is only available for single hop sessions.\n"); | |
488 | return CMD_WARNING_CONFIG_FAILED; | |
489 | } | |
490 | ||
491 | snprintf(value, sizeof(value), "%ld", interval * 1000); | |
492 | nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval", | |
493 | NB_OP_MODIFY, value); | |
494 | ||
495 | return nb_cli_apply_changes(vty, NULL); | |
496 | } | |
497 | ||
498 | void bfd_cli_show_desired_echo_transmission_interval(struct vty *vty, | |
499 | struct lyd_node *dnode, bool show_defaults) | |
500 | { | |
501 | uint32_t value; | |
502 | ||
503 | if (show_defaults) | |
504 | vty_out(vty, " echo transmit-interval %d\n", | |
505 | BFD_DEF_DES_MIN_ECHO_TX); | |
506 | else { | |
507 | value = yang_dnode_get_uint32(dnode, NULL); | |
508 | vty_out(vty, " echo transmit-interval %u\n", value / 1000); | |
509 | } | |
510 | } | |
511 | ||
512 | DEFPY_YANG( | |
513 | bfd_peer_echo_receive_interval, bfd_peer_echo_receive_interval_cmd, | |
514 | "echo receive-interval <disabled$disabled|(10-60000)$interval>", | |
515 | "Configure peer echo intervals\n" | |
516 | "Configure required receive interval\n" | |
517 | "Disable echo packets receive\n" | |
518 | "Configure interval value in milliseconds\n") | |
519 | { | |
520 | char value[32]; | |
521 | ||
522 | if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) { | |
523 | vty_out(vty, "%% Echo mode is only available for single hop sessions.\n"); | |
524 | return CMD_WARNING_CONFIG_FAILED; | |
525 | } | |
526 | ||
527 | if (disabled) | |
528 | snprintf(value, sizeof(value), "0"); | |
529 | else | |
530 | snprintf(value, sizeof(value), "%ld", interval * 1000); | |
531 | ||
532 | nb_cli_enqueue_change(vty, "./required-echo-receive-interval", | |
533 | NB_OP_MODIFY, value); | |
8a676ce6 | 534 | |
adc26455 RZ |
535 | return nb_cli_apply_changes(vty, NULL); |
536 | } | |
537 | ||
4df3e31c IR |
538 | void bfd_cli_show_required_echo_receive_interval(struct vty *vty, |
539 | struct lyd_node *dnode, bool show_defaults) | |
0287a64a | 540 | { |
8a676ce6 RZ |
541 | uint32_t value; |
542 | ||
0287a64a | 543 | if (show_defaults) |
4df3e31c IR |
544 | vty_out(vty, " echo receive-interval %d\n", |
545 | BFD_DEF_REQ_MIN_ECHO_RX); | |
8a676ce6 RZ |
546 | else { |
547 | value = yang_dnode_get_uint32(dnode, NULL); | |
4df3e31c IR |
548 | if (value) |
549 | vty_out(vty, " echo receive-interval %u\n", | |
550 | value / 1000); | |
551 | else | |
552 | vty_out(vty, " echo receive-interval disabled\n"); | |
8a676ce6 | 553 | } |
0287a64a RZ |
554 | } |
555 | ||
d40d6c22 RZ |
556 | /* |
557 | * Profile commands. | |
558 | */ | |
ca77b518 | 559 | DEFPY_YANG_NOSH(bfd_profile, bfd_profile_cmd, |
0a01b0f4 | 560 | "profile BFDPROF$name", |
d40d6c22 RZ |
561 | BFD_PROFILE_STR |
562 | BFD_PROFILE_NAME_STR) | |
563 | { | |
ccc9ada8 RZ |
564 | char xpath[XPATH_MAXLEN]; |
565 | int rv; | |
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_CREATE, NULL); | |
571 | ||
572 | /* Apply settings immediately. */ | |
573 | rv = nb_cli_apply_changes(vty, NULL); | |
574 | if (rv == CMD_SUCCESS) | |
575 | VTY_PUSH_XPATH(BFD_PROFILE_NODE, xpath); | |
576 | ||
d40d6c22 RZ |
577 | return CMD_SUCCESS; |
578 | } | |
579 | ||
ca77b518 | 580 | DEFPY_YANG(no_bfd_profile, no_bfd_profile_cmd, |
d40d6c22 RZ |
581 | "no profile BFDPROF$name", |
582 | NO_STR | |
583 | BFD_PROFILE_STR | |
584 | BFD_PROFILE_NAME_STR) | |
585 | { | |
ccc9ada8 RZ |
586 | char xpath[XPATH_MAXLEN]; |
587 | ||
588 | snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/profile[name='%s']", | |
589 | name); | |
590 | ||
591 | nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); | |
592 | ||
593 | /* Apply settings immediately. */ | |
594 | return nb_cli_apply_changes(vty, NULL); | |
595 | } | |
596 | ||
597 | void bfd_cli_show_profile(struct vty *vty, struct lyd_node *dnode, | |
598 | bool show_defaults) | |
599 | { | |
600 | vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, "./name")); | |
601 | } | |
602 | ||
ca77b518 | 603 | ALIAS_YANG(bfd_peer_mult, bfd_profile_mult_cmd, |
ccc9ada8 RZ |
604 | "detect-multiplier (2-255)$multiplier", |
605 | "Configure peer detection multiplier\n" | |
606 | "Configure peer detection multiplier value\n") | |
607 | ||
ca77b518 | 608 | ALIAS_YANG(bfd_peer_tx, bfd_profile_tx_cmd, |
ccc9ada8 RZ |
609 | "transmit-interval (10-60000)$interval", |
610 | "Configure peer transmit interval\n" | |
611 | "Configure peer transmit interval value in milliseconds\n") | |
612 | ||
ca77b518 | 613 | ALIAS_YANG(bfd_peer_rx, bfd_profile_rx_cmd, |
ccc9ada8 RZ |
614 | "receive-interval (10-60000)$interval", |
615 | "Configure peer receive interval\n" | |
616 | "Configure peer receive interval value in milliseconds\n") | |
617 | ||
ca77b518 | 618 | ALIAS_YANG(bfd_peer_shutdown, bfd_profile_shutdown_cmd, |
ccc9ada8 RZ |
619 | "[no] shutdown", |
620 | NO_STR | |
621 | "Disable BFD peer\n") | |
622 | ||
1a2e2fff RZ |
623 | ALIAS_YANG(bfd_peer_passive, bfd_profile_passive_cmd, |
624 | "[no] passive-mode", | |
625 | NO_STR | |
626 | "Don't attempt to start sessions\n") | |
627 | ||
262e1d25 RZ |
628 | ALIAS_YANG(bfd_peer_minimum_ttl, bfd_profile_minimum_ttl_cmd, |
629 | "[no] minimum-ttl (1-254)$ttl", | |
630 | NO_STR | |
631 | "Expect packets with at least this TTL\n" | |
632 | "Minimum TTL expected\n") | |
633 | ||
634 | ALIAS_YANG(no_bfd_peer_minimum_ttl, no_bfd_profile_minimum_ttl_cmd, | |
635 | "no minimum-ttl", | |
636 | NO_STR | |
637 | "Expect packets with at least this TTL\n") | |
638 | ||
ca77b518 | 639 | ALIAS_YANG(bfd_peer_echo, bfd_profile_echo_cmd, |
ccc9ada8 RZ |
640 | "[no] echo-mode", |
641 | NO_STR | |
642 | "Configure echo mode\n") | |
643 | ||
ca77b518 | 644 | ALIAS_YANG(bfd_peer_echo_interval, bfd_profile_echo_interval_cmd, |
ccc9ada8 RZ |
645 | "echo-interval (10-60000)$interval", |
646 | "Configure peer echo interval\n" | |
647 | "Configure peer echo interval value in milliseconds\n") | |
648 | ||
4df3e31c IR |
649 | ALIAS_YANG( |
650 | bfd_peer_echo_transmit_interval, bfd_profile_echo_transmit_interval_cmd, | |
651 | "echo transmit-interval (10-60000)$interval", | |
652 | "Configure peer echo intervals\n" | |
653 | "Configure desired transmit interval\n" | |
654 | "Configure interval value in milliseconds\n") | |
655 | ||
656 | ALIAS_YANG( | |
657 | bfd_peer_echo_receive_interval, bfd_profile_echo_receive_interval_cmd, | |
658 | "echo receive-interval <disabled$disabled|(10-60000)$interval>", | |
659 | "Configure peer echo intervals\n" | |
660 | "Configure required receive interval\n" | |
661 | "Disable echo packets receive\n" | |
662 | "Configure interval value in milliseconds\n") | |
663 | ||
ca77b518 | 664 | DEFPY_YANG(bfd_peer_profile, bfd_peer_profile_cmd, |
ccc9ada8 RZ |
665 | "[no] profile BFDPROF$pname", |
666 | NO_STR | |
667 | "Use BFD profile settings\n" | |
668 | BFD_PROFILE_NAME_STR) | |
669 | { | |
670 | if (no) | |
671 | nb_cli_enqueue_change(vty, "./profile", NB_OP_DESTROY, NULL); | |
672 | else | |
673 | nb_cli_enqueue_change(vty, "./profile", NB_OP_MODIFY, pname); | |
674 | ||
675 | return nb_cli_apply_changes(vty, NULL); | |
676 | } | |
677 | ||
678 | void bfd_cli_peer_profile_show(struct vty *vty, struct lyd_node *dnode, | |
679 | bool show_defaults) | |
680 | { | |
681 | vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, NULL)); | |
d40d6c22 RZ |
682 | } |
683 | ||
684 | struct cmd_node bfd_profile_node = { | |
685 | .name = "bfd profile", | |
686 | .node = BFD_PROFILE_NODE, | |
687 | .parent_node = BFD_NODE, | |
688 | .prompt = "%s(config-bfd-profile)# ", | |
689 | }; | |
690 | ||
ccc9ada8 RZ |
691 | static void bfd_profile_var(vector comps, struct cmd_token *token) |
692 | { | |
693 | extern struct bfdproflist bplist; | |
694 | struct bfd_profile *bp; | |
695 | ||
696 | TAILQ_FOREACH (bp, &bplist, entry) { | |
697 | vector_set(comps, XSTRDUP(MTYPE_COMPLETION, bp->name)); | |
698 | } | |
699 | } | |
700 | ||
701 | static const struct cmd_variable_handler bfd_vars[] = { | |
702 | {.tokenname = "BFDPROF", .completions = bfd_profile_var}, | |
703 | {.completions = NULL} | |
704 | }; | |
705 | ||
adc26455 RZ |
706 | void |
707 | bfdd_cli_init(void) | |
708 | { | |
fdf8ac87 | 709 | install_element(CONFIG_NODE, &bfd_enter_cmd); |
2a573ff6 RZ |
710 | install_element(CONFIG_NODE, &bfd_config_reset_cmd); |
711 | ||
adc26455 RZ |
712 | install_element(BFD_NODE, &bfd_peer_enter_cmd); |
713 | install_element(BFD_NODE, &bfd_no_peer_cmd); | |
714 | ||
715 | install_element(BFD_PEER_NODE, &bfd_peer_shutdown_cmd); | |
716 | install_element(BFD_PEER_NODE, &bfd_peer_mult_cmd); | |
717 | install_element(BFD_PEER_NODE, &bfd_peer_rx_cmd); | |
718 | install_element(BFD_PEER_NODE, &bfd_peer_tx_cmd); | |
719 | install_element(BFD_PEER_NODE, &bfd_peer_echo_cmd); | |
720 | install_element(BFD_PEER_NODE, &bfd_peer_echo_interval_cmd); | |
4df3e31c IR |
721 | install_element(BFD_PEER_NODE, &bfd_peer_echo_transmit_interval_cmd); |
722 | install_element(BFD_PEER_NODE, &bfd_peer_echo_receive_interval_cmd); | |
ccc9ada8 | 723 | install_element(BFD_PEER_NODE, &bfd_peer_profile_cmd); |
1a2e2fff | 724 | install_element(BFD_PEER_NODE, &bfd_peer_passive_cmd); |
262e1d25 RZ |
725 | install_element(BFD_PEER_NODE, &bfd_peer_minimum_ttl_cmd); |
726 | install_element(BFD_PEER_NODE, &no_bfd_peer_minimum_ttl_cmd); | |
d40d6c22 RZ |
727 | |
728 | /* Profile commands. */ | |
ccc9ada8 RZ |
729 | cmd_variable_handler_register(bfd_vars); |
730 | ||
d40d6c22 RZ |
731 | install_node(&bfd_profile_node); |
732 | install_default(BFD_PROFILE_NODE); | |
733 | ||
734 | install_element(BFD_NODE, &bfd_profile_cmd); | |
735 | install_element(BFD_NODE, &no_bfd_profile_cmd); | |
ccc9ada8 RZ |
736 | |
737 | install_element(BFD_PROFILE_NODE, &bfd_profile_mult_cmd); | |
738 | install_element(BFD_PROFILE_NODE, &bfd_profile_tx_cmd); | |
739 | install_element(BFD_PROFILE_NODE, &bfd_profile_rx_cmd); | |
740 | install_element(BFD_PROFILE_NODE, &bfd_profile_shutdown_cmd); | |
741 | install_element(BFD_PROFILE_NODE, &bfd_profile_echo_cmd); | |
742 | install_element(BFD_PROFILE_NODE, &bfd_profile_echo_interval_cmd); | |
4df3e31c IR |
743 | install_element(BFD_PROFILE_NODE, &bfd_profile_echo_transmit_interval_cmd); |
744 | install_element(BFD_PROFILE_NODE, &bfd_profile_echo_receive_interval_cmd); | |
1a2e2fff | 745 | install_element(BFD_PROFILE_NODE, &bfd_profile_passive_cmd); |
262e1d25 RZ |
746 | install_element(BFD_PROFILE_NODE, &bfd_profile_minimum_ttl_cmd); |
747 | install_element(BFD_PROFILE_NODE, &no_bfd_profile_minimum_ttl_cmd); | |
adc26455 | 748 | } |