]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripngd: retrofit the 'timer basic' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 29 Nov 2018 13:21:13 +0000 (11:21 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 3 Dec 2018 15:47:58 +0000 (13:47 -0200)
Trivial conversion. Use the northbound 'apply_finish()' callback
so we'll call ripng_event() only once even if we change the three
RIPng timers at the same time.

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

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripngd/ripng_cli.c
ripngd/ripng_cli.h
ripngd/ripng_northbound.c
ripngd/ripngd.c
ripngd/ripngd.h

index e6daa62980e9909e3104afe217e8dbdb3eb7508f..2d5c9850452d319df6b3943cd1f51cd0f724a5cc 100644 (file)
@@ -358,6 +358,54 @@ void cli_show_ripng_aggregate_address(struct vty *vty, struct lyd_node *dnode,
                yang_dnode_get_string(dnode, NULL));
 }
 
+/*
+ * XPath: /frr-ripngd:ripngd/instance/timers
+ */
+DEFPY (ripng_timers,
+       ripng_timers_cmd,
+       "timers basic (1-65535)$update (1-65535)$timeout (1-65535)$garbage",
+       "RIPng timers setup\n"
+       "Basic timer\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")
+{
+       nb_cli_enqueue_change(vty, "./update-interval", NB_OP_MODIFY,
+                             update_str);
+       nb_cli_enqueue_change(vty, "./holddown-interval", NB_OP_MODIFY,
+                             timeout_str);
+       nb_cli_enqueue_change(vty, "./flush-interval", NB_OP_MODIFY,
+                             garbage_str);
+
+       return nb_cli_apply_changes(vty, "./timers");
+}
+
+DEFPY (no_ripng_timers,
+       no_ripng_timers_cmd,
+       "no timers basic [(1-65535) (1-65535) (1-65535)]",
+       NO_STR
+       "RIPng timers setup\n"
+       "Basic timer\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")
+{
+       nb_cli_enqueue_change(vty, "./update-interval", NB_OP_MODIFY, NULL);
+       nb_cli_enqueue_change(vty, "./holddown-interval", NB_OP_MODIFY, NULL);
+       nb_cli_enqueue_change(vty, "./flush-interval", NB_OP_MODIFY, NULL);
+
+       return nb_cli_apply_changes(vty, "./timers");
+}
+
+void cli_show_ripng_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 ripng_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_ripng_cmd);
@@ -374,4 +422,6 @@ void ripng_cli_init(void)
        install_element(RIPNG_NODE, &ripng_redistribute_cmd);
        install_element(RIPNG_NODE, &ripng_route_cmd);
        install_element(RIPNG_NODE, &ripng_aggregate_address_cmd);
+       install_element(RIPNG_NODE, &ripng_timers_cmd);
+       install_element(RIPNG_NODE, &no_ripng_timers_cmd);
 }
index 1eafd69f9e62fb9803e836f7f5f8c11a21077c1d..99a67667e7fc1fdf83319f8861928b85b6f14888 100644 (file)
@@ -49,5 +49,7 @@ extern void cli_show_ripng_route(struct vty *vty, struct lyd_node *dnode,
 extern void cli_show_ripng_aggregate_address(struct vty *vty,
                                             struct lyd_node *dnode,
                                             bool show_defaults);
+extern void cli_show_ripng_timers(struct vty *vty, struct lyd_node *dnode,
+                                 bool show_defaults);
 
 #endif /* _FRR_RIPNG_CLI_H_ */
index 163baecc95267dacacbf6f8d3249add97802eb79..4d1a945b6aa6b249376f9e0f86e372a99ed079a4 100644 (file)
@@ -514,6 +514,15 @@ ripngd_instance_aggregate_address_delete(enum nb_event event,
        return NB_OK;
 }
 
+/*
+ * XPath: /frr-ripngd:ripngd/instance/timers
+ */
+static void ripngd_instance_timers_apply_finish(const struct lyd_node *dnode)
+{
+       /* Reset update timer thread. */
+       ripng_event(RIPNG_UPDATE_EVENT, 0);
+}
+
 /*
  * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval
  */
@@ -522,7 +531,11 @@ ripngd_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;
+
+       ripng->garbage_time = yang_dnode_get_uint16(dnode, NULL);
+
        return NB_OK;
 }
 
@@ -534,7 +547,11 @@ ripngd_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;
+
+       ripng->timeout_time = yang_dnode_get_uint16(dnode, NULL);
+
        return NB_OK;
 }
 
@@ -546,7 +563,11 @@ ripngd_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;
+
+       ripng->update_time = yang_dnode_get_uint16(dnode, NULL);
+
        return NB_OK;
 }
 
@@ -798,6 +819,11 @@ const struct frr_yang_module_info frr_ripngd_info = {
                        .cbs.delete = ripngd_instance_aggregate_address_delete,
                        .cbs.cli_show = cli_show_ripng_aggregate_address,
                },
+               {
+                       .xpath = "/frr-ripngd:ripngd/instance/timers",
+                       .cbs.apply_finish = ripngd_instance_timers_apply_finish,
+                       .cbs.cli_show = cli_show_ripng_timers,
+               },
                {
                        .xpath = "/frr-ripngd:ripngd/instance/timers/flush-interval",
                        .cbs.modify = ripngd_instance_timers_flush_interval_modify,
index dfa75361a2afedaafb1397ead45e16ba7ddf84bf..3cdf5b03e333572584228e32d6e3318c96d785ff 100644 (file)
@@ -2062,12 +2062,12 @@ DEFUN (show_ipv6_ripng_status,
                return CMD_SUCCESS;
 
        vty_out(vty, "Routing Protocol is \"RIPng\"\n");
-       vty_out(vty, "  Sending updates every %ld seconds with +/-50%%,",
+       vty_out(vty, "  Sending updates every %u seconds with +/-50%%,",
                ripng->update_time);
        vty_out(vty, " next due in %lu seconds\n",
                thread_timer_remain_second(ripng->t_update));
-       vty_out(vty, "  Timeout after %ld seconds,", ripng->timeout_time);
-       vty_out(vty, " garbage collect after %ld seconds\n",
+       vty_out(vty, "  Timeout after %u seconds,", ripng->timeout_time);
+       vty_out(vty, " garbage collect after %u seconds\n",
                ripng->garbage_time);
 
        /* Filtering status show. */
@@ -2258,58 +2258,6 @@ DEFUN (no_ripng_garbage_timer,
 }
 #endif /* 0 */
 
-DEFUN (ripng_timers,
-       ripng_timers_cmd,
-       "timers basic (0-65535) (0-65535) (0-65535)",
-       "RIPng timers setup\n"
-       "Basic timer\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;
-
-       update = strtoul(argv[idx_number]->arg, NULL, 10);
-       timeout = strtoul(argv[idx_number_2]->arg, NULL, 10);
-       garbage = strtoul(argv[idx_number_3]->arg, NULL, 10);
-
-       /* Set each timer value. */
-       ripng->update_time = update;
-       ripng->timeout_time = timeout;
-       ripng->garbage_time = garbage;
-
-       /* Reset update timer thread. */
-       ripng_event(RIPNG_UPDATE_EVENT, 0);
-
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_ripng_timers,
-       no_ripng_timers_cmd,
-       "no timers basic [(0-65535) (0-65535) (0-65535)]",
-       NO_STR
-       "RIPng timers setup\n"
-       "Basic timer\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. */
-       ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
-       ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
-       ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
-
-       /* Reset update timer thread. */
-       ripng_event(RIPNG_UPDATE_EVENT, 0);
-
-       return CMD_SUCCESS;
-}
-
 #if 0
 DEFUN (show_ipv6_protocols,
        show_ipv6_protocols_cmd,
@@ -2386,23 +2334,6 @@ static int ripng_config_write(struct vty *vty)
        if (dnode) {
                nb_cli_show_dnode_cmds(vty, dnode, false);
 
-               /* RIPng timers configuration. */
-               if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT
-                   || ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT
-                   || ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT) {
-                       vty_out(vty, " timers basic %ld %ld %ld\n",
-                               ripng->update_time, ripng->timeout_time,
-                               ripng->garbage_time);
-               }
-#if 0
-      if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT)
-       vty_out (vty, " update-timer %d\n", ripng->update_time);
-      if (ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT)
-       vty_out (vty, " timeout-timer %d\n", ripng->timeout_time);
-      if (ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT)
-       vty_out (vty, " garbage-timer %d\n", ripng->garbage_time);
-#endif /* 0 */
-
                config_write_distribute(vty);
 
                config_write_if_rmap(vty);
@@ -2672,8 +2603,6 @@ void ripng_init()
 
        install_default(RIPNG_NODE);
 
-       install_element(RIPNG_NODE, &ripng_timers_cmd);
-       install_element(RIPNG_NODE, &no_ripng_timers_cmd);
 #if 0
   install_element (VIEW_NODE, &show_ipv6_protocols_cmd);
   install_element (RIPNG_NODE, &ripng_update_timer_cmd);
index 4863d22069003f87043a62bf492e92bc91874ba6..a7453d1a1adc2163d4e65000a62b5f33aa14fcdf 100644 (file)
 #define RIPNG_METRIC_NEXTHOP          0xff
 #define RIPNG_GROUP              "ff02::9"
 
-/* RIPng timers. */
-#define RIPNG_UPDATE_TIMER_DEFAULT      30
-#define RIPNG_TIMEOUT_TIMER_DEFAULT    180
-#define RIPNG_GARBAGE_TIMER_DEFAULT    120
-
 /* RIPng peer timeout value. */
 #define RIPNG_PEER_TIMER_DEFAULT       180
 
@@ -98,9 +93,9 @@ struct ripng {
        /* RIPng Parameters.*/
        uint8_t command;
        uint8_t version;
-       unsigned long update_time;
-       unsigned long timeout_time;
-       unsigned long garbage_time;
+       uint16_t update_time;
+       uint16_t timeout_time;
+       uint16_t garbage_time;
        int max_mtu;
        uint8_t default_metric;