]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: retrofit the 'default-metric' 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.

rip->default_metric was converted to an uint8_t to match the way it's
defined in the YANG module.

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

index 9193c089a84da07ecd89111563123279bf9f8b35..d374ea64f07fa208cdac103204938d830a7a1d1c 100644 (file)
@@ -145,6 +145,51 @@ void cli_show_rip_default_information_originate(struct vty *vty,
        vty_out(vty, " default-information originate\n");
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/default-metric
+ */
+DEFPY (rip_default_metric,
+       rip_default_metric_cmd,
+       "default-metric (1-16)",
+       "Set a metric of redistribute routes\n"
+       "Default metric\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./default-metric",
+                       .operation = NB_OP_MODIFY,
+                       .value = default_metric_str,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+DEFPY (no_rip_default_metric,
+       no_rip_default_metric_cmd,
+       "no default-metric [(1-16)]",
+       NO_STR
+       "Set a metric of redistribute routes\n"
+       "Default metric\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./default-metric",
+                       .operation = NB_OP_MODIFY,
+                       .value = NULL,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode,
+                                bool show_defaults)
+{
+       vty_out(vty, " default-metric %s\n",
+               yang_dnode_get_string(dnode, NULL));
+}
+
 void rip_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_rip_cmd);
@@ -152,4 +197,6 @@ void rip_cli_init(void)
 
        install_element(RIP_NODE, &rip_allow_ecmp_cmd);
        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);
 }
index d63f02dd96d51f8be244b1302fcdc1033bbd6bf6..3e60ae8f93d4f45b28911c4b38b0d2b915862f3d 100644 (file)
@@ -28,5 +28,7 @@ extern void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
 extern void cli_show_rip_default_information_originate(struct vty *vty,
                                                       struct lyd_node *dnode,
                                                       bool show_defaults);
+extern void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode,
+                                       bool show_defaults);
 
 #endif /* _FRR_RIP_CLI_H_ */
index 884e2a83d105dc5ac9de974a301453574d7e2094..67719cb2549401716494a6cebf87321529a2dcea 100644 (file)
@@ -131,7 +131,12 @@ static int ripd_instance_default_metric_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->default_metric = yang_dnode_get_uint8(dnode, NULL);
+       /* rip_update_default_metric (); */
+
        return NB_OK;
 }
 
@@ -759,6 +764,7 @@ const struct frr_yang_module_info frr_ripd_info = {
                {
                        .xpath = "/frr-ripd:ripd/instance/default-metric",
                        .cbs.modify = ripd_instance_default_metric_modify,
+                       .cbs.cli_show = cli_show_rip_default_metric,
                },
                {
                        .xpath = "/frr-ripd:ripd/instance/distance/default",
index 7dfabc623d2514027e3cbd8edff7087200fffc07..1ae1d29eb45ae42fbf73e832bed51823e9e4d817 100644 (file)
@@ -2926,35 +2926,6 @@ rip_update_default_metric (void)
 }
 #endif
 
-DEFUN (rip_default_metric,
-       rip_default_metric_cmd,
-       "default-metric (1-16)",
-       "Set a metric of redistribute routes\n"
-       "Default metric\n")
-{
-       int idx_number = 1;
-       if (rip) {
-               rip->default_metric = atoi(argv[idx_number]->arg);
-               /* rip_update_default_metric (); */
-       }
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_rip_default_metric,
-       no_rip_default_metric_cmd,
-       "no default-metric [(1-16)]",
-       NO_STR
-       "Set a metric of redistribute routes\n"
-       "Default metric\n")
-{
-       if (rip) {
-               rip->default_metric = RIP_DEFAULT_METRIC_DEFAULT;
-               /* rip_update_default_metric (); */
-       }
-       return CMD_SUCCESS;
-}
-
-
 DEFUN (rip_timers,
        rip_timers_cmd,
        "timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
@@ -3500,7 +3471,7 @@ DEFUN (show_ip_rip_status,
        config_show_distribute(vty);
 
        /* Default metric information. */
-       vty_out(vty, "  Default redistribution metric is %d\n",
+       vty_out(vty, "  Default redistribution metric is %u\n",
                rip->default_metric);
 
        /* Redistribute information. */
@@ -3614,11 +3585,6 @@ static int config_write_rip(struct vty *vty)
                /* RIP enabled network and interface configuration. */
                config_write_rip_network(vty, 1);
 
-               /* RIP default metric configuration */
-               if (rip->default_metric != RIP_DEFAULT_METRIC_DEFAULT)
-                       vty_out(vty, " default-metric %d\n",
-                               rip->default_metric);
-
                /* Distribute configuration. */
                write += config_write_distribute(vty);
 
@@ -3919,8 +3885,6 @@ void rip_init(void)
        install_default(RIP_NODE);
        install_element(RIP_NODE, &rip_version_cmd);
        install_element(RIP_NODE, &no_rip_version_cmd);
-       install_element(RIP_NODE, &rip_default_metric_cmd);
-       install_element(RIP_NODE, &no_rip_default_metric_cmd);
        install_element(RIP_NODE, &rip_timers_cmd);
        install_element(RIP_NODE, &no_rip_timers_cmd);
        install_element(RIP_NODE, &rip_route_cmd);
index c2e39f1a71af594e5071953a0a18d491c9de8e56..1ecedf3680f03e9546802056d2db64718e87f0b7 100644 (file)
@@ -140,7 +140,7 @@ struct rip {
        unsigned long garbage_time;
 
        /* RIP default metric. */
-       int default_metric;
+       uint8_t default_metric;
 
        /* RIP default distance. */
        uint8_t distance;
@@ -346,9 +346,6 @@ struct rip_md5_data {
 /* N.B. stuff will break if
        (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
 
-/* Default value for "default-metric" command. */
-#define RIP_DEFAULT_METRIC_DEFAULT         1
-
 /* RIP event. */
 enum rip_event {
        RIP_READ,