bfdd: implement write_config using northbound

Move all the `show running-config` logic to the new northbound
implementation.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
This commit is contained in:
Rafael Zalamena 2019-05-25 11:36:46 -03:00
parent adc26455bf
commit 0287a64a6e
4 changed files with 176 additions and 77 deletions

View file

@ -596,6 +596,29 @@ void bfdd_vty_init(void);
*/ */
void bfdd_cli_init(void); void bfdd_cli_init(void);
void bfd_cli_show_header(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_header_end(struct vty *vty, struct lyd_node *dnode);
void bfd_cli_show_single_hop_peer(struct vty *vty,
struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_multi_hop_peer(struct vty *vty,
struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_peer_end(struct vty *vty, struct lyd_node *dnode);
void bfd_cli_show_mult(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_tx(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_rx(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_shutdown(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_echo(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
void bfd_cli_show_echo_interval(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
/* /*
* ptm_adapter.c * ptm_adapter.c

View file

@ -52,6 +52,19 @@
/* /*
* Functions. * Functions.
*/ */
void bfd_cli_show_header(struct vty *vty,
struct lyd_node *dnode __attribute__((__unused__)),
bool show_defaults __attribute__((__unused__)))
{
vty_out(vty, "!\nbfd\n");
}
void bfd_cli_show_header_end(struct vty *vty,
struct lyd_node *dnode __attribute__((__unused__)))
{
vty_out(vty, "!\n");
}
DEFPY_NOSH( DEFPY_NOSH(
bfd_peer_enter, bfd_peer_enter_cmd, bfd_peer_enter, bfd_peer_enter_cmd,
"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}]", "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}]",
@ -151,6 +164,52 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
static void _bfd_cli_show_peer(struct vty *vty, struct lyd_node *dnode,
bool show_defaults __attribute__((__unused__)),
bool mhop)
{
const char *vrf = yang_dnode_get_string(dnode, "./vrf");
const char *ifname = yang_dnode_get_string(dnode, "./interface");
vty_out(vty, " peer %s",
yang_dnode_get_string(dnode, "./dest-addr"));
if (mhop)
vty_out(vty, " multihop");
if (yang_dnode_exists(dnode, "./source-addr"))
vty_out(vty, " local-address %s",
yang_dnode_get_string(dnode, "./source-addr"));
if (strcmp(vrf, VRF_DEFAULT_NAME))
vty_out(vty, " vrf %s", vrf);
if (ifname[0])
vty_out(vty, " interface %s", ifname);
vty_out(vty, "\n");
}
void bfd_cli_show_single_hop_peer(struct vty *vty,
struct lyd_node *dnode,
bool show_defaults)
{
_bfd_cli_show_peer(vty, dnode, show_defaults, false);
}
void bfd_cli_show_multi_hop_peer(struct vty *vty,
struct lyd_node *dnode,
bool show_defaults)
{
_bfd_cli_show_peer(vty, dnode, show_defaults, true);
}
void bfd_cli_show_peer_end(struct vty *vty,
struct lyd_node *dnode __attribute__((__unused__)))
{
vty_out(vty, " !\n");
}
DEFPY( DEFPY(
bfd_peer_shutdown, bfd_peer_shutdown_cmd, bfd_peer_shutdown, bfd_peer_shutdown_cmd,
"[no] shutdown", "[no] shutdown",
@ -162,6 +221,16 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
void bfd_cli_show_shutdown(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
if (show_defaults)
vty_out(vty, " shutdown\n");
else
vty_out(vty, " %sshutdown\n",
yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
}
DEFPY( DEFPY(
bfd_peer_mult, bfd_peer_mult_cmd, bfd_peer_mult, bfd_peer_mult_cmd,
"detect-multiplier (2-255)$multiplier", "detect-multiplier (2-255)$multiplier",
@ -173,6 +242,17 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
void bfd_cli_show_mult(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
if (show_defaults)
vty_out(vty, " detect-multiplier %d\n",
BFD_DEFDETECTMULT);
else
vty_out(vty, " detect-multiplier %s\n",
yang_dnode_get_string(dnode, NULL));
}
DEFPY( DEFPY(
bfd_peer_rx, bfd_peer_rx_cmd, bfd_peer_rx, bfd_peer_rx_cmd,
"receive-interval (10-60000)$interval", "receive-interval (10-60000)$interval",
@ -184,6 +264,17 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
void bfd_cli_show_rx(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
if (show_defaults)
vty_out(vty, " receive-interval %d\n",
BFD_DEFREQUIREDMINRX);
else
vty_out(vty, " receive-interval %s\n",
yang_dnode_get_string(dnode, NULL));
}
DEFPY( DEFPY(
bfd_peer_tx, bfd_peer_tx_cmd, bfd_peer_tx, bfd_peer_tx_cmd,
"transmit-interval (10-60000)$interval", "transmit-interval (10-60000)$interval",
@ -195,6 +286,17 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
void bfd_cli_show_tx(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
if (show_defaults)
vty_out(vty, " transmit-interval %d\n",
BFD_DEFDESIREDMINTX);
else
vty_out(vty, " transmit-interval %s\n",
yang_dnode_get_string(dnode, NULL));
}
DEFPY( DEFPY(
bfd_peer_echo, bfd_peer_echo_cmd, bfd_peer_echo, bfd_peer_echo_cmd,
"[no] echo-mode", "[no] echo-mode",
@ -206,6 +308,16 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
void bfd_cli_show_echo(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
if (show_defaults)
vty_out(vty, " no echo-mode\n");
else
vty_out(vty, " %secho-mode\n",
yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
}
DEFPY( DEFPY(
bfd_peer_echo_interval, bfd_peer_echo_interval_cmd, bfd_peer_echo_interval, bfd_peer_echo_interval_cmd,
"echo-interval (10-60000)$interval", "echo-interval (10-60000)$interval",
@ -217,6 +329,17 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL); return nb_cli_apply_changes(vty, NULL);
} }
void bfd_cli_show_echo_interval(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
if (show_defaults)
vty_out(vty, " echo-interval %d\n",
BFD_DEF_REQ_MIN_ECHO);
else
vty_out(vty, " echo-interval %s\n",
yang_dnode_get_string(dnode, NULL));
}
void void
bfdd_cli_init(void) bfdd_cli_init(void)
{ {

View file

@ -839,6 +839,8 @@ const struct frr_yang_module_info frr_bfdd_info = {
.cbs.get_next = bfdd_bfd_sessions_single_hop_get_next, .cbs.get_next = bfdd_bfd_sessions_single_hop_get_next,
.cbs.get_keys = bfdd_bfd_sessions_single_hop_get_keys, .cbs.get_keys = bfdd_bfd_sessions_single_hop_get_keys,
.cbs.lookup_entry = bfdd_bfd_sessions_single_hop_lookup_entry, .cbs.lookup_entry = bfdd_bfd_sessions_single_hop_lookup_entry,
.cbs.cli_show = bfd_cli_show_single_hop_peer,
.cbs.cli_show_end = bfd_cli_show_peer_end,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/source-addr", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/source-addr",
@ -848,26 +850,32 @@ const struct frr_yang_module_info frr_bfdd_info = {
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/detection-multiplier", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/detection-multiplier",
.cbs.modify = bfdd_bfd_sessions_single_hop_detection_multiplier_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_detection_multiplier_modify,
.cbs.cli_show = bfd_cli_show_mult,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/desired-transmission-interval", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/desired-transmission-interval",
.cbs.modify = bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify,
.cbs.cli_show = bfd_cli_show_tx,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/required-receive-interval", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/required-receive-interval",
.cbs.modify = bfdd_bfd_sessions_single_hop_required_receive_interval_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_required_receive_interval_modify,
.cbs.cli_show = bfd_cli_show_rx,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/administrative-down", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/administrative-down",
.cbs.modify = bfdd_bfd_sessions_single_hop_administrative_down_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_administrative_down_modify,
.cbs.cli_show = bfd_cli_show_shutdown,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/echo-mode", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/echo-mode",
.cbs.modify = bfdd_bfd_sessions_single_hop_echo_mode_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_echo_mode_modify,
.cbs.cli_show = bfd_cli_show_echo,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/desired-echo-transmission-interval", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/desired-echo-transmission-interval",
.cbs.modify = bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify,
.cbs.cli_show = bfd_cli_show_echo_interval,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-discriminator", .xpath = "/frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-discriminator",
@ -956,22 +964,28 @@ const struct frr_yang_module_info frr_bfdd_info = {
.cbs.get_next = bfdd_bfd_sessions_multi_hop_get_next, .cbs.get_next = bfdd_bfd_sessions_multi_hop_get_next,
.cbs.get_keys = bfdd_bfd_sessions_multi_hop_get_keys, .cbs.get_keys = bfdd_bfd_sessions_multi_hop_get_keys,
.cbs.lookup_entry = bfdd_bfd_sessions_multi_hop_lookup_entry, .cbs.lookup_entry = bfdd_bfd_sessions_multi_hop_lookup_entry,
.cbs.cli_show = bfd_cli_show_multi_hop_peer,
.cbs.cli_show_end = bfd_cli_show_peer_end,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/detection-multiplier", .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/detection-multiplier",
.cbs.modify = bfdd_bfd_sessions_single_hop_detection_multiplier_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_detection_multiplier_modify,
.cbs.cli_show = bfd_cli_show_mult,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/desired-transmission-interval", .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/desired-transmission-interval",
.cbs.modify = bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_desired_transmission_interval_modify,
.cbs.cli_show = bfd_cli_show_tx,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/required-receive-interval", .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/required-receive-interval",
.cbs.modify = bfdd_bfd_sessions_single_hop_required_receive_interval_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_required_receive_interval_modify,
.cbs.cli_show = bfd_cli_show_rx,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/administrative-down", .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/administrative-down",
.cbs.modify = bfdd_bfd_sessions_single_hop_administrative_down_modify, .cbs.modify = bfdd_bfd_sessions_single_hop_administrative_down_modify,
.cbs.cli_show = bfd_cli_show_shutdown,
}, },
{ {
.xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/local-discriminator", .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/stats/local-discriminator",

View file

@ -23,6 +23,7 @@
#include "lib/command.h" #include "lib/command.h"
#include "lib/json.h" #include "lib/json.h"
#include "lib/log.h" #include "lib/log.h"
#include "lib/northbound_cli.h"
#include "lib/vty.h" #include "lib/vty.h"
#include "bfd.h" #include "bfd.h"
@ -45,10 +46,6 @@
/* /*
* Prototypes * Prototypes
*/ */
static int bfdd_write_config(struct vty *vty);
static int bfdd_peer_write_config(struct vty *vty);
static void _bfdd_peer_write_config(struct vty *vty, struct bfd_session *bs);
static void _bfdd_peer_write_config_iter(struct hash_bucket *hb, void *arg);
static int bfd_configure_peer(struct bfd_peer_cfg *bpc, bool mhop, static int bfd_configure_peer(struct bfd_peer_cfg *bpc, bool mhop,
const struct sockaddr_any *peer, const struct sockaddr_any *peer,
const struct sockaddr_any *local, const struct sockaddr_any *local,
@ -707,60 +704,6 @@ static int bfd_configure_peer(struct bfd_peer_cfg *bpc, bool mhop,
return 0; return 0;
} }
static int bfdd_write_config(struct vty *vty)
{
vty_out(vty, "bfd\n");
vty_out(vty, "!\n");
return 0;
}
static void _bfdd_peer_write_config(struct vty *vty, struct bfd_session *bs)
{
char addr_buf[INET6_ADDRSTRLEN];
vty_out(vty, " peer %s",
inet_ntop(bs->key.family, &bs->key.peer, addr_buf,
sizeof(addr_buf)));
if (bs->key.mhop)
vty_out(vty, " multihop");
if (memcmp(&bs->key.local, &zero_addr, sizeof(bs->key.local)))
vty_out(vty, " local-address %s",
inet_ntop(bs->key.family, &bs->key.local, addr_buf,
sizeof(addr_buf)));
if (bs->key.vrfname[0])
vty_out(vty, " vrf %s", bs->key.vrfname);
if (bs->key.ifname[0])
vty_out(vty, " interface %s", bs->key.ifname);
vty_out(vty, "\n");
if (bs->sock == -1)
vty_out(vty,
" ! vrf, interface or local-address doesn't exist\n");
if (bs->detect_mult != BPC_DEF_DETECTMULTIPLIER)
vty_out(vty, " detect-multiplier %d\n", bs->detect_mult);
if (bs->timers.required_min_rx != (BPC_DEF_RECEIVEINTERVAL * 1000))
vty_out(vty, " receive-interval %" PRIu32 "\n",
bs->timers.required_min_rx / 1000);
if (bs->timers.desired_min_tx != (BPC_DEF_TRANSMITINTERVAL * 1000))
vty_out(vty, " transmit-interval %" PRIu32 "\n",
bs->timers.desired_min_tx / 1000);
if (bs->timers.required_min_echo != (BPC_DEF_ECHOINTERVAL * 1000))
vty_out(vty, " echo-interval %" PRIu32 "\n",
bs->timers.required_min_echo / 1000);
if (bs->pl)
vty_out(vty, " label %s\n", bs->pl->pl_label);
if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
vty_out(vty, " echo-mode\n");
vty_out(vty, " %sshutdown\n",
BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ? "" : "no ");
vty_out(vty, " !\n");
}
DEFUN_NOSH(show_debugging_bfd, DEFUN_NOSH(show_debugging_bfd,
show_debugging_bfd_cmd, show_debugging_bfd_cmd,
@ -774,24 +717,6 @@ DEFUN_NOSH(show_debugging_bfd,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
static void _bfdd_peer_write_config_iter(struct hash_bucket *hb, void *arg)
{
struct vty *vty = arg;
struct bfd_session *bs = hb->data;
if (!BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG))
return;
_bfdd_peer_write_config(vty, bs);
}
static int bfdd_peer_write_config(struct vty *vty)
{
bfd_id_iterate(_bfdd_peer_write_config_iter, vty);
return 1;
}
struct cmd_node bfd_node = { struct cmd_node bfd_node = {
BFD_NODE, BFD_NODE,
"%s(config-bfd)# ", "%s(config-bfd)# ",
@ -804,6 +729,20 @@ struct cmd_node bfd_peer_node = {
1, 1,
}; };
static int bfdd_write_config(struct vty *vty)
{
struct lyd_node *dnode;
int written = 0;
dnode = yang_dnode_get(running_config->dnode, "/frr-bfdd:bfdd");
if (dnode) {
nb_cli_show_dnode_cmds(vty, dnode, false);
written = 1;
}
return written;
}
void bfdd_vty_init(void) void bfdd_vty_init(void)
{ {
install_element(ENABLE_NODE, &bfd_show_peers_counters_cmd); install_element(ENABLE_NODE, &bfd_show_peers_counters_cmd);
@ -818,7 +757,7 @@ void bfdd_vty_init(void)
install_default(BFD_NODE); install_default(BFD_NODE);
/* Install BFD peer node. */ /* Install BFD peer node. */
install_node(&bfd_peer_node, bfdd_peer_write_config); install_node(&bfd_peer_node, NULL);
install_default(BFD_PEER_NODE); install_default(BFD_PEER_NODE);
bfdd_cli_init(); bfdd_cli_init();