2 * BFD daemon CLI implementation.
4 * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
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.
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.
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
25 #include "lib/command.h"
27 #include "lib/northbound_cli.h"
29 #ifndef VTYSH_EXTRACT_PL
30 #include "bfdd/bfdd_cli_clippy.c"
31 #endif /* VTYSH_EXTRACT_PL */
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"
59 bfd_enter
, bfd_enter_cmd
,
61 "Configure BFD peers\n")
65 nb_cli_enqueue_change(vty
, "/frr-bfdd:bfdd/bfd", NB_OP_CREATE
, NULL
);
66 ret
= nb_cli_apply_changes(vty
, NULL
);
67 if (ret
== CMD_SUCCESS
)
68 VTY_PUSH_XPATH(BFD_NODE
, "/frr-bfdd:bfdd/bfd");
74 bfd_config_reset
, bfd_config_reset_cmd
,
77 "Configure BFD peers\n")
79 nb_cli_enqueue_change(vty
, "/frr-bfdd:bfdd/bfd", NB_OP_DESTROY
, NULL
);
80 return nb_cli_apply_changes(vty
, NULL
);
83 void bfd_cli_show_header(struct vty
*vty
,
84 struct lyd_node
*dnode
__attribute__((__unused__
)),
85 bool show_defaults
__attribute__((__unused__
)))
87 vty_out(vty
, "!\nbfd\n");
90 void bfd_cli_show_header_end(struct vty
*vty
,
91 struct lyd_node
*dnode
__attribute__((__unused__
)))
97 bfd_peer_enter
, bfd_peer_enter_cmd
,
98 "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}]",
112 char source_str
[INET6_ADDRSTRLEN
];
113 char xpath
[XPATH_MAXLEN
], xpath_srcaddr
[XPATH_MAXLEN
+ 32];
116 snprintf(source_str
, sizeof(source_str
), "[source-addr='%s']",
121 slen
= snprintf(xpath
, sizeof(xpath
),
122 "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']",
123 multihop
? "multi-hop" : "single-hop", source_str
,
126 slen
+= snprintf(xpath
+ slen
, sizeof(xpath
) - slen
,
127 "[interface='%s']", ifname
);
129 slen
+= snprintf(xpath
+ slen
, sizeof(xpath
) - slen
,
132 snprintf(xpath
+ slen
, sizeof(xpath
) - slen
, "[vrf='%s']", vrf
);
134 snprintf(xpath
+ slen
, sizeof(xpath
) - slen
, "[vrf='%s']",
137 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
138 if (multihop
== NULL
&& local_address_str
!= NULL
) {
139 snprintf(xpath_srcaddr
, sizeof(xpath_srcaddr
),
140 "%s/source-addr", xpath
);
141 nb_cli_enqueue_change(vty
, xpath_srcaddr
, NB_OP_MODIFY
,
145 /* Apply settings immediately. */
146 ret
= nb_cli_apply_changes(vty
, NULL
);
147 if (ret
== CMD_SUCCESS
)
148 VTY_PUSH_XPATH(BFD_PEER_NODE
, xpath
);
154 bfd_no_peer
, bfd_no_peer_cmd
,
155 "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}]",
170 char xpath
[XPATH_MAXLEN
];
171 char source_str
[INET6_ADDRSTRLEN
];
174 snprintf(source_str
, sizeof(source_str
), "[source-addr='%s']",
179 slen
= snprintf(xpath
, sizeof(xpath
),
180 "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']",
181 multihop
? "multi-hop" : "single-hop", source_str
,
184 slen
+= snprintf(xpath
+ slen
, sizeof(xpath
) - slen
,
185 "[interface='%s']", ifname
);
187 slen
+= snprintf(xpath
+ slen
, sizeof(xpath
) - slen
,
190 snprintf(xpath
+ slen
, sizeof(xpath
) - slen
, "[vrf='%s']", vrf
);
192 snprintf(xpath
+ slen
, sizeof(xpath
) - slen
, "[vrf='%s']",
195 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
197 /* Apply settings immediatly. */
198 return nb_cli_apply_changes(vty
, NULL
);
201 static void _bfd_cli_show_peer(struct vty
*vty
, struct lyd_node
*dnode
,
202 bool show_defaults
__attribute__((__unused__
)),
205 const char *vrf
= yang_dnode_get_string(dnode
, "./vrf");
206 const char *ifname
= yang_dnode_get_string(dnode
, "./interface");
208 vty_out(vty
, " peer %s",
209 yang_dnode_get_string(dnode
, "./dest-addr"));
212 vty_out(vty
, " multihop");
214 if (yang_dnode_exists(dnode
, "./source-addr"))
215 vty_out(vty
, " local-address %s",
216 yang_dnode_get_string(dnode
, "./source-addr"));
218 if (strcmp(vrf
, VRF_DEFAULT_NAME
))
219 vty_out(vty
, " vrf %s", vrf
);
222 vty_out(vty
, " interface %s", ifname
);
227 void bfd_cli_show_single_hop_peer(struct vty
*vty
,
228 struct lyd_node
*dnode
,
231 _bfd_cli_show_peer(vty
, dnode
, show_defaults
, false);
234 void bfd_cli_show_multi_hop_peer(struct vty
*vty
,
235 struct lyd_node
*dnode
,
238 _bfd_cli_show_peer(vty
, dnode
, show_defaults
, true);
241 void bfd_cli_show_peer_end(struct vty
*vty
,
242 struct lyd_node
*dnode
__attribute__((__unused__
)))
244 vty_out(vty
, " !\n");
248 bfd_peer_shutdown
, bfd_peer_shutdown_cmd
,
251 "Disable BFD peer\n")
253 nb_cli_enqueue_change(vty
, "./administrative-down", NB_OP_MODIFY
,
254 no
? "false" : "true");
255 return nb_cli_apply_changes(vty
, NULL
);
258 void bfd_cli_show_shutdown(struct vty
*vty
, struct lyd_node
*dnode
,
262 vty_out(vty
, " shutdown\n");
264 vty_out(vty
, " %sshutdown\n",
265 yang_dnode_get_bool(dnode
, NULL
) ? "" : "no ");
269 bfd_peer_mult
, bfd_peer_mult_cmd
,
270 "detect-multiplier (2-255)$multiplier",
271 "Configure peer detection multiplier\n"
272 "Configure peer detection multiplier value\n")
274 nb_cli_enqueue_change(vty
, "./detection-multiplier", NB_OP_MODIFY
,
276 return nb_cli_apply_changes(vty
, NULL
);
279 void bfd_cli_show_mult(struct vty
*vty
, struct lyd_node
*dnode
,
283 vty_out(vty
, " detect-multiplier %d\n",
286 vty_out(vty
, " detect-multiplier %s\n",
287 yang_dnode_get_string(dnode
, NULL
));
291 bfd_peer_rx
, bfd_peer_rx_cmd
,
292 "receive-interval (10-60000)$interval",
293 "Configure peer receive interval\n"
294 "Configure peer receive interval value in milliseconds\n")
298 snprintf(value
, sizeof(value
), "%ld", interval
* 1000);
299 nb_cli_enqueue_change(vty
, "./required-receive-interval", NB_OP_MODIFY
,
302 return nb_cli_apply_changes(vty
, NULL
);
305 void bfd_cli_show_rx(struct vty
*vty
, struct lyd_node
*dnode
,
311 vty_out(vty
, " receive-interval %d\n",
312 BFD_DEFREQUIREDMINRX
);
314 value
= yang_dnode_get_uint32(dnode
, NULL
);
315 vty_out(vty
, " receive-interval %" PRIu32
"\n", value
/ 1000);
320 bfd_peer_tx
, bfd_peer_tx_cmd
,
321 "transmit-interval (10-60000)$interval",
322 "Configure peer transmit interval\n"
323 "Configure peer transmit interval value in milliseconds\n")
327 snprintf(value
, sizeof(value
), "%ld", interval
* 1000);
328 nb_cli_enqueue_change(vty
, "./desired-transmission-interval",
329 NB_OP_MODIFY
, value
);
331 return nb_cli_apply_changes(vty
, NULL
);
334 void bfd_cli_show_tx(struct vty
*vty
, struct lyd_node
*dnode
,
340 vty_out(vty
, " transmit-interval %d\n",
341 BFD_DEFDESIREDMINTX
);
343 value
= yang_dnode_get_uint32(dnode
, NULL
);
344 vty_out(vty
, " transmit-interval %" PRIu32
"\n", value
/ 1000);
349 bfd_peer_echo
, bfd_peer_echo_cmd
,
352 "Configure echo mode\n")
354 nb_cli_enqueue_change(vty
, "./echo-mode", NB_OP_MODIFY
,
355 no
? "false" : "true");
356 return nb_cli_apply_changes(vty
, NULL
);
359 void bfd_cli_show_echo(struct vty
*vty
, struct lyd_node
*dnode
,
363 vty_out(vty
, " no echo-mode\n");
365 vty_out(vty
, " %secho-mode\n",
366 yang_dnode_get_bool(dnode
, NULL
) ? "" : "no ");
370 bfd_peer_echo_interval
, bfd_peer_echo_interval_cmd
,
371 "echo-interval (10-60000)$interval",
372 "Configure peer echo interval\n"
373 "Configure peer echo interval value in milliseconds\n")
377 snprintf(value
, sizeof(value
), "%ld", interval
* 1000);
378 nb_cli_enqueue_change(vty
, "./desired-echo-transmission-interval",
379 NB_OP_MODIFY
, value
);
381 return nb_cli_apply_changes(vty
, NULL
);
384 void bfd_cli_show_echo_interval(struct vty
*vty
, struct lyd_node
*dnode
,
390 vty_out(vty
, " echo-interval %d\n",
391 BFD_DEF_REQ_MIN_ECHO
);
393 value
= yang_dnode_get_uint32(dnode
, NULL
);
394 vty_out(vty
, " echo-interval %" PRIu32
"\n", value
/ 1000);
401 install_element(CONFIG_NODE
, &bfd_enter_cmd
);
402 install_element(CONFIG_NODE
, &bfd_config_reset_cmd
);
404 install_element(BFD_NODE
, &bfd_peer_enter_cmd
);
405 install_element(BFD_NODE
, &bfd_no_peer_cmd
);
407 install_element(BFD_PEER_NODE
, &bfd_peer_shutdown_cmd
);
408 install_element(BFD_PEER_NODE
, &bfd_peer_mult_cmd
);
409 install_element(BFD_PEER_NODE
, &bfd_peer_rx_cmd
);
410 install_element(BFD_PEER_NODE
, &bfd_peer_tx_cmd
);
411 install_element(BFD_PEER_NODE
, &bfd_peer_echo_cmd
);
412 install_element(BFD_PEER_NODE
, &bfd_peer_echo_interval_cmd
);