]> git.puffer.fish Git - mirror/frr.git/commitdiff
ripd: retrofit the 'timer basic' 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. Use the northbound 'apply_finish()' callback so
we'll call rip_event() only once even if we change the three RIP timers
at the same time.

Convert the timers to uint32_t to match their representation in the
YANG model.

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 00608b0266cf128ae40b85393561c41fefd3c818..a89df5b2f121db14e909929e19aa937f58630e7d 100644 (file)
@@ -639,6 +639,79 @@ void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode,
        vty_out(vty, " route %s\n", yang_dnode_get_string(dnode, NULL));
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/timers
+ */
+DEFPY (rip_timers,
+       rip_timers_cmd,
+       "timers basic (5-2147483647)$update (5-2147483647)$timeout (5-2147483647)$garbage",
+       "Adjust routing timers\n"
+       "Basic routing protocol update timers\n"
+       "Routing table update timer value in second. Default is 30.\n"
+       "Routing information timeout timer. Default is 180.\n"
+       "Garbage collection timer. Default is 120.\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./timers/update-interval",
+                       .operation = NB_OP_MODIFY,
+                       .value = update_str,
+               },
+               {
+                       .xpath = "./timers/holddown-interval",
+                       .operation = NB_OP_MODIFY,
+                       .value = timeout_str,
+               },
+               {
+                       .xpath = "./timers/flush-interval",
+                       .operation = NB_OP_MODIFY,
+                       .value = garbage_str,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+DEFPY (no_rip_timers,
+       no_rip_timers_cmd,
+       "no timers basic [(5-2147483647) (5-2147483647) (5-2147483647)]",
+       NO_STR
+       "Adjust routing timers\n"
+       "Basic routing protocol update timers\n"
+       "Routing table update timer value in second. Default is 30.\n"
+       "Routing information timeout timer. Default is 180.\n"
+       "Garbage collection timer. Default is 120.\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./timers/update-interval",
+                       .operation = NB_OP_MODIFY,
+                       .value =  NULL,
+               },
+               {
+                       .xpath = "./timers/holddown-interval",
+                       .operation = NB_OP_MODIFY,
+                       .value =  NULL,
+               },
+               {
+                       .xpath = "./timers/flush-interval",
+                       .operation = NB_OP_MODIFY,
+                       .value =  NULL,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_timers(struct vty *vty, struct lyd_node *dnode,
+                        bool show_defaults)
+{
+       vty_out(vty, " timers basic %s %s %s\n",
+               yang_dnode_get_string(dnode, "./update-interval"),
+               yang_dnode_get_string(dnode, "./holddown-interval"),
+               yang_dnode_get_string(dnode, "./flush-interval"));
+}
+
 void rip_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_rip_cmd);
@@ -662,4 +735,6 @@ void rip_cli_init(void)
        install_element(RIP_NODE, &rip_redistribute_cmd);
        install_element(RIP_NODE, &no_rip_redistribute_cmd);
        install_element(RIP_NODE, &rip_route_cmd);
+       install_element(RIP_NODE, &rip_timers_cmd);
+       install_element(RIP_NODE, &no_rip_timers_cmd);
 }
index 3d06cc7a432ca429a751eb22d7aac9b7c86e0adc..1fe13601b69ec5a9d93952d5d76afbc7f4c1ee80 100644 (file)
@@ -57,5 +57,7 @@ extern void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode,
                                      bool show_defaults);
 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);
 
 #endif /* _FRR_RIP_CLI_H_ */
index ffb4a10c9e6287cf4d3fa2db09a6890f0c0a52c8..a99a92de9b39e3ab3d6e34fdd215370358f92cdd 100644 (file)
@@ -691,6 +691,15 @@ static int ripd_instance_static_route_delete(enum nb_event event,
        return NB_OK;
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/timers/
+ */
+static void ripd_instance_timers_apply_finish(const struct lyd_node *dnode)
+{
+       /* Reset update timer thread. */
+       rip_event(RIP_UPDATE_EVENT, 0);
+}
+
 /*
  * XPath: /frr-ripd:ripd/instance/timers/flush-interval
  */
@@ -699,7 +708,11 @@ ripd_instance_timers_flush_interval_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->garbage_time = yang_dnode_get_uint32(dnode, NULL);
+
        return NB_OK;
 }
 
@@ -711,7 +724,11 @@ ripd_instance_timers_holddown_interval_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->timeout_time = yang_dnode_get_uint32(dnode, NULL);
+
        return NB_OK;
 }
 
@@ -723,7 +740,11 @@ ripd_instance_timers_update_interval_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->update_time = yang_dnode_get_uint32(dnode, NULL);
+
        return NB_OK;
 }
 
@@ -1128,6 +1149,11 @@ const struct frr_yang_module_info frr_ripd_info = {
                        .cbs.delete = ripd_instance_static_route_delete,
                        .cbs.cli_show = cli_show_rip_route,
                },
+               {
+                       .xpath = "/frr-ripd:ripd/instance/timers",
+                       .cbs.apply_finish = ripd_instance_timers_apply_finish,
+                       .cbs.cli_show = cli_show_rip_timers,
+               },
                {
                        .xpath = "/frr-ripd:ripd/instance/timers/flush-interval",
                        .cbs.modify = ripd_instance_timers_flush_interval_modify,
index 806d55eb3c2f0ff32879abc217dfa878ed6bd236..411a1ddc8f4ab4fc7e926f039460ea53af7e97ee 100644 (file)
@@ -65,7 +65,6 @@ long rip_global_route_changes = 0;
 long rip_global_queries = 0;
 
 /* Prototypes. */
-static void rip_event(enum rip_event, int);
 static void rip_output_process(struct connected *, struct sockaddr_in *, int,
                               uint8_t);
 static int rip_triggered_update(struct thread *);
@@ -2851,78 +2850,6 @@ rip_update_default_metric (void)
 }
 #endif
 
-DEFUN (rip_timers,
-       rip_timers_cmd,
-       "timers basic (5-2147483647) (5-2147483647) (5-2147483647)",
-       "Adjust routing timers\n"
-       "Basic routing protocol update timers\n"
-       "Routing table update timer value in second. Default is 30.\n"
-       "Routing information timeout timer. Default is 180.\n"
-       "Garbage collection timer. Default is 120.\n")
-{
-       int idx_number = 2;
-       int idx_number_2 = 3;
-       int idx_number_3 = 4;
-       unsigned long update;
-       unsigned long timeout;
-       unsigned long garbage;
-       char *endptr = NULL;
-       unsigned long RIP_TIMER_MAX = 2147483647;
-       unsigned long RIP_TIMER_MIN = 5;
-
-       update = strtoul(argv[idx_number]->arg, &endptr, 10);
-       if (update > RIP_TIMER_MAX || update < RIP_TIMER_MIN
-           || *endptr != '\0') {
-               vty_out(vty, "update timer value error\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       timeout = strtoul(argv[idx_number_2]->arg, &endptr, 10);
-       if (timeout > RIP_TIMER_MAX || timeout < RIP_TIMER_MIN
-           || *endptr != '\0') {
-               vty_out(vty, "timeout timer value error\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       garbage = strtoul(argv[idx_number_3]->arg, &endptr, 10);
-       if (garbage > RIP_TIMER_MAX || garbage < RIP_TIMER_MIN
-           || *endptr != '\0') {
-               vty_out(vty, "garbage timer value error\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       /* Set each timer value. */
-       rip->update_time = update;
-       rip->timeout_time = timeout;
-       rip->garbage_time = garbage;
-
-       /* Reset update timer thread. */
-       rip_event(RIP_UPDATE_EVENT, 0);
-
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_rip_timers,
-       no_rip_timers_cmd,
-       "no timers basic [(0-65535) (0-65535) (0-65535)]",
-       NO_STR
-       "Adjust routing timers\n"
-       "Basic routing protocol update timers\n"
-       "Routing table update timer value in second. Default is 30.\n"
-       "Routing information timeout timer. Default is 180.\n"
-       "Garbage collection timer. Default is 120.\n")
-{
-       /* Set each timer value to the default. */
-       rip->update_time = RIP_UPDATE_TIMER_DEFAULT;
-       rip->timeout_time = RIP_TIMEOUT_TIMER_DEFAULT;
-       rip->garbage_time = RIP_GARBAGE_TIMER_DEFAULT;
-
-       /* Reset update timer thread. */
-       rip_event(RIP_UPDATE_EVENT, 0);
-
-       return CMD_SUCCESS;
-}
-
 
 struct route_table *rip_distance_table;
 
@@ -3219,12 +3146,12 @@ DEFUN (show_ip_rip_status,
                return CMD_SUCCESS;
 
        vty_out(vty, "Routing Protocol is \"rip\"\n");
-       vty_out(vty, "  Sending updates every %ld seconds with +/-50%%,",
+       vty_out(vty, "  Sending updates every %u seconds with +/-50%%,",
                rip->update_time);
        vty_out(vty, " next due in %lu seconds\n",
                thread_timer_remain_second(rip->t_update));
-       vty_out(vty, "  Timeout after %ld seconds,", rip->timeout_time);
-       vty_out(vty, " garbage collect after %ld seconds\n", rip->garbage_time);
+       vty_out(vty, "  Timeout after %u seconds,", rip->timeout_time);
+       vty_out(vty, " garbage collect after %u seconds\n", rip->garbage_time);
 
        /* Filtering status show. */
        config_show_distribute(vty);
@@ -3325,14 +3252,6 @@ static int config_write_rip(struct vty *vty)
                    || rip->version_recv != RI_RIP_VERSION_1_AND_2)
                        vty_out(vty, " version %d\n", rip->version_send);
 
-               /* RIP timer configuration. */
-               if (rip->update_time != RIP_UPDATE_TIMER_DEFAULT
-                   || rip->timeout_time != RIP_TIMEOUT_TIMER_DEFAULT
-                   || rip->garbage_time != RIP_GARBAGE_TIMER_DEFAULT)
-                       vty_out(vty, " timers basic %lu %lu %lu\n",
-                               rip->update_time, rip->timeout_time,
-                               rip->garbage_time);
-
                /* Distribute configuration. */
                write += config_write_distribute(vty);
 
@@ -3603,8 +3522,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_timers_cmd);
-       install_element(RIP_NODE, &no_rip_timers_cmd);
 
        /* Debug related init. */
        rip_debug_init();
index 5ac2be9abb84a39f0c6670b4792fffb90f719997..c8bc68c09f36a4b6a2da894cbca08960c47d6c14 100644 (file)
 #define INADDR_RIP_GROUP        0xe0000009    /* 224.0.0.9 */
 #endif
 
-/* RIP timers */
-#define RIP_UPDATE_TIMER_DEFAULT        30
-#define RIP_TIMEOUT_TIMER_DEFAULT      180
-#define RIP_GARBAGE_TIMER_DEFAULT      120
-
 /* RIP peer timeout value. */
 #define RIP_PEER_TIMER_DEFAULT         180
 
@@ -132,9 +127,9 @@ struct rip {
        struct thread *t_triggered_interval;
 
        /* RIP timer values. */
-       unsigned long update_time;
-       unsigned long timeout_time;
-       unsigned long garbage_time;
+       uint32_t update_time;
+       uint32_t timeout_time;
+       uint32_t garbage_time;
 
        /* RIP default metric. */
        uint8_t default_metric;
@@ -412,6 +407,7 @@ extern int rip_enable_network_delete(struct prefix *p);
 extern int rip_enable_if_add(const char *ifname);
 extern int rip_enable_if_delete(const char *ifname);
 
+extern void rip_event(enum rip_event, int);
 extern void rip_ecmp_disable(void);
 
 extern int rip_create_socket(void);