]> git.puffer.fish Git - mirror/frr.git/commitdiff
ripd: retrofit the 'distance' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 9 May 2018 04:34:59 +0000 (01:34 -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 d374ea64f07fa208cdac103204938d830a7a1d1c..b9824d352fb09f59c64998daec8f7a22f66410cf 100644 (file)
@@ -190,6 +190,50 @@ void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode,
                yang_dnode_get_string(dnode, NULL));
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/distance/default
+ */
+DEFPY (rip_distance,
+       rip_distance_cmd,
+       "distance (1-255)",
+       "Administrative distance\n"
+       "Distance value\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./distance/default",
+                       .operation = NB_OP_MODIFY,
+                       .value = distance_str,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+DEFPY (no_rip_distance,
+       no_rip_distance_cmd,
+       "no distance [(1-255)]",
+       NO_STR
+       "Administrative distance\n"
+       "Distance value\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./distance/default",
+                       .operation = NB_OP_MODIFY,
+                       .value = NULL,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_distance(struct vty *vty, struct lyd_node *dnode,
+                          bool show_defaults)
+{
+       vty_out(vty, " distance %s\n", yang_dnode_get_string(dnode, NULL));
+}
+
 void rip_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_rip_cmd);
@@ -199,4 +243,6 @@ void rip_cli_init(void)
        install_element(RIP_NODE, &rip_default_information_originate_cmd);
        install_element(RIP_NODE, &rip_default_metric_cmd);
        install_element(RIP_NODE, &no_rip_default_metric_cmd);
+       install_element(RIP_NODE, &rip_distance_cmd);
+       install_element(RIP_NODE, &no_rip_distance_cmd);
 }
index 3e60ae8f93d4f45b28911c4b38b0d2b915862f3d..1e2faac7f873f1400eeae8c27d86f9b1ea01e86b 100644 (file)
@@ -30,5 +30,7 @@ extern void cli_show_rip_default_information_originate(struct vty *vty,
                                                       bool show_defaults);
 extern void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode,
                                        bool show_defaults);
+extern void cli_show_rip_distance(struct vty *vty, struct lyd_node *dnode,
+                                 bool show_defaults);
 
 #endif /* _FRR_RIP_CLI_H_ */
index 67719cb2549401716494a6cebf87321529a2dcea..79b3d252e1eea4944de55014519e6574a8455048 100644 (file)
@@ -147,7 +147,11 @@ static int ripd_instance_distance_default_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->distance = yang_dnode_get_uint8(dnode, NULL);
+
        return NB_OK;
 }
 
@@ -769,6 +773,7 @@ const struct frr_yang_module_info frr_ripd_info = {
                {
                        .xpath = "/frr-ripd:ripd/instance/distance/default",
                        .cbs.modify = ripd_instance_distance_default_modify,
+                       .cbs.cli_show = cli_show_rip_distance,
                },
                {
                        .xpath = "/frr-ripd:ripd/instance/distance/source",
index 1ae1d29eb45ae42fbf73e832bed51823e9e4d817..d85ebcc5343c40eef81b6ec1f5cfeca800d67f58 100644 (file)
@@ -3157,7 +3157,7 @@ static void rip_distance_show(struct vty *vty)
        int header = 1;
        char buf[BUFSIZ];
 
-       vty_out(vty, "  Distance: (default is %d)\n",
+       vty_out(vty, "  Distance: (default is %u)\n",
                rip->distance ? rip->distance : ZEBRA_RIP_DISTANCE_DEFAULT);
 
        for (rn = route_top(rip_distance_table); rn; rn = route_next(rn))
@@ -3176,28 +3176,6 @@ static void rip_distance_show(struct vty *vty)
                }
 }
 
-DEFUN (rip_distance,
-       rip_distance_cmd,
-       "distance (1-255)",
-       "Administrative distance\n"
-       "Distance value\n")
-{
-       int idx_number = 1;
-       rip->distance = atoi(argv[idx_number]->arg);
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_rip_distance,
-       no_rip_distance_cmd,
-       "no distance (1-255)",
-       NO_STR
-       "Administrative distance\n"
-       "Distance value\n")
-{
-       rip->distance = 0;
-       return CMD_SUCCESS;
-}
-
 DEFUN (rip_distance_source,
        rip_distance_source_cmd,
        "distance (1-255) A.B.C.D/M",
@@ -3591,10 +3569,6 @@ static int config_write_rip(struct vty *vty)
                /* Interface routemap configuration */
                write += config_write_if_rmap(vty);
 
-               /* Distance configuration. */
-               if (rip->distance)
-                       vty_out(vty, " distance %d\n", rip->distance);
-
                /* RIP source IP prefix distance configuration. */
                for (rn = route_top(rip_distance_table); rn;
                     rn = route_next(rn))
@@ -3889,8 +3863,6 @@ void rip_init(void)
        install_element(RIP_NODE, &no_rip_timers_cmd);
        install_element(RIP_NODE, &rip_route_cmd);
        install_element(RIP_NODE, &no_rip_route_cmd);
-       install_element(RIP_NODE, &rip_distance_cmd);
-       install_element(RIP_NODE, &no_rip_distance_cmd);
        install_element(RIP_NODE, &rip_distance_source_cmd);
        install_element(RIP_NODE, &no_rip_distance_source_cmd);
        install_element(RIP_NODE, &rip_distance_source_access_list_cmd);