]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: retrofit the 'version' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 9 May 2018 04:35:01 +0000 (01:35 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 27 Oct 2018 18:16:12 +0000 (16:16 -0200)
Trivial conversion.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_cli.c
ripd/rip_cli.h
ripd/rip_northbound.c
ripd/ripd.c

index a89df5b2f121db14e909929e19aa937f58630e7d..6fa21df2ccb93a568d1fe0c5085e2787e5f31da2 100644 (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);
 }
index 1fe13601b69ec5a9d93952d5d76afbc7f4c1ee80..cc4a54240250a0795b2e96b6c0f0ca3f9b797972 100644 (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_ */
index a99a92de9b39e3ab3d6e34fdd215370358f92cdd..f94681700d90e6113b64cbc624389279b8552ec5 100644 (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,
index 411a1ddc8f4ab4fc7e926f039460ea53af7e97ee..9c6681a56e7c72d9807381be1d1dea2417654625 100644 (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();