ripd: retrofit the 'version' command to the new northbound model

Trivial conversion.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2018-05-09 01:35:01 -03:00
parent b745780b5f
commit 90eff9dafe
4 changed files with 84 additions and 43 deletions

View file

@ -712,6 +712,72 @@ void cli_show_rip_timers(struct vty *vty, struct lyd_node *dnode,
yang_dnode_get_string(dnode, "./flush-interval"));
}
/*
* XPath: /frr-ripd:ripd/instance/version
*/
DEFPY (rip_version,
rip_version_cmd,
"version (1-2)",
"Set routing protocol version\n"
"version\n")
{
struct cli_config_change changes[] = {
{
.xpath = "./version/receive",
.operation = NB_OP_MODIFY,
.value = version_str,
},
{
.xpath = "./version/send",
.operation = NB_OP_MODIFY,
.value = version_str,
},
};
return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
}
DEFPY (no_rip_version,
no_rip_version_cmd,
"no version [(1-2)]",
NO_STR
"Set routing protocol version\n"
"version\n")
{
struct cli_config_change changes[] = {
{
.xpath = "./version/receive",
.operation = NB_OP_MODIFY,
},
{
.xpath = "./version/send",
.operation = NB_OP_MODIFY,
},
};
return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
}
void cli_show_rip_version(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
/*
* We have only one "version" command and three possible combinations of
* send/receive values.
*/
switch (yang_dnode_get_enum(dnode, "./receive")) {
case RI_RIP_VERSION_1:
vty_out(vty, " version 1\n");
break;
case RI_RIP_VERSION_2:
vty_out(vty, " version 2\n");
break;
case RI_RIP_VERSION_1_AND_2:
vty_out(vty, " no version\n");
break;
}
}
void rip_cli_init(void)
{
install_element(CONFIG_NODE, &router_rip_cmd);
@ -737,4 +803,6 @@ void rip_cli_init(void)
install_element(RIP_NODE, &rip_route_cmd);
install_element(RIP_NODE, &rip_timers_cmd);
install_element(RIP_NODE, &no_rip_timers_cmd);
install_element(RIP_NODE, &rip_version_cmd);
install_element(RIP_NODE, &no_rip_version_cmd);
}

View file

@ -59,5 +59,7 @@ extern void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
extern void cli_show_rip_timers(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
extern void cli_show_rip_version(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
#endif /* _FRR_RIP_CLI_H_ */

View file

@ -755,7 +755,11 @@ static int ripd_instance_version_receive_modify(enum nb_event event,
const struct lyd_node *dnode,
union nb_resource *resource)
{
/* TODO: implement me. */
if (event != NB_EV_APPLY)
return NB_OK;
rip->version_recv = yang_dnode_get_enum(dnode, NULL);
return NB_OK;
}
@ -766,7 +770,11 @@ static int ripd_instance_version_send_modify(enum nb_event event,
const struct lyd_node *dnode,
union nb_resource *resource)
{
/* TODO: implement me. */
if (event != NB_EV_APPLY)
return NB_OK;
rip->version_send = yang_dnode_get_enum(dnode, NULL);
return NB_OK;
}
@ -1166,6 +1174,10 @@ const struct frr_yang_module_info frr_ripd_info = {
.xpath = "/frr-ripd:ripd/instance/timers/update-interval",
.cbs.modify = ripd_instance_timers_update_interval_modify,
},
{
.xpath = "/frr-ripd:ripd/instance/version",
.cbs.cli_show = cli_show_rip_version,
},
{
.xpath = "/frr-ripd:ripd/instance/version/receive",
.cbs.modify = ripd_instance_version_receive_modify,

View file

@ -2799,40 +2799,6 @@ void rip_event(enum rip_event event, int sock)
}
}
DEFUN (rip_version,
rip_version_cmd,
"version (1-2)",
"Set routing protocol version\n"
"version\n")
{
int idx_number = 1;
int version;
version = atoi(argv[idx_number]->arg);
if (version != RIPv1 && version != RIPv2) {
vty_out(vty, "invalid rip version %d\n", version);
return CMD_WARNING_CONFIG_FAILED;
}
rip->version_send = version;
rip->version_recv = version;
return CMD_SUCCESS;
}
DEFUN (no_rip_version,
no_rip_version_cmd,
"no version [(1-2)]",
NO_STR
"Set routing protocol version\n"
"Version\n")
{
/* Set RIP version to the default. */
rip->version_send = RI_RIP_VERSION_2;
rip->version_recv = RI_RIP_VERSION_1_AND_2;
return CMD_SUCCESS;
}
#if 0
static void
rip_update_default_metric (void)
@ -3247,11 +3213,6 @@ static int config_write_rip(struct vty *vty)
nb_cli_show_dnode_cmds(vty, dnode, false);
/* RIP version statement. Default is RIP version 2. */
if (rip->version_send != RI_RIP_VERSION_2
|| rip->version_recv != RI_RIP_VERSION_1_AND_2)
vty_out(vty, " version %d\n", rip->version_send);
/* Distribute configuration. */
write += config_write_distribute(vty);
@ -3520,8 +3481,6 @@ void rip_init(void)
install_element(VIEW_NODE, &show_ip_rip_status_cmd);
install_default(RIP_NODE);
install_element(RIP_NODE, &rip_version_cmd);
install_element(RIP_NODE, &no_rip_version_cmd);
/* Debug related init. */
rip_debug_init();