From 90eff9dafe8f6985d77db9db8a1b48e159ed046c Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 9 May 2018 01:35:01 -0300 Subject: [PATCH] ripd: retrofit the 'version' command to the new northbound model Trivial conversion. Signed-off-by: Renato Westphal --- ripd/rip_cli.c | 68 +++++++++++++++++++++++++++++++++++++++++++ ripd/rip_cli.h | 2 ++ ripd/rip_northbound.c | 16 ++++++++-- ripd/ripd.c | 41 -------------------------- 4 files changed, 84 insertions(+), 43 deletions(-) diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c index a89df5b2f1..6fa21df2cc 100644 --- a/ripd/rip_cli.c +++ b/ripd/rip_cli.c @@ -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); } diff --git a/ripd/rip_cli.h b/ripd/rip_cli.h index 1fe13601b6..cc4a542402 100644 --- a/ripd/rip_cli.h +++ b/ripd/rip_cli.h @@ -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_ */ diff --git a/ripd/rip_northbound.c b/ripd/rip_northbound.c index a99a92de9b..f94681700d 100644 --- a/ripd/rip_northbound.c +++ b/ripd/rip_northbound.c @@ -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, diff --git a/ripd/ripd.c b/ripd/ripd.c index 411a1ddc8f..9c6681a56e 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -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(); -- 2.39.5