From f8981ec5963576270e6a6c25149c84aac6b4f457 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 29 Nov 2018 11:21:13 -0200 Subject: [PATCH] ripngd: retrofit the 'timer basic' command to the new northbound model 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 --- ripngd/ripng_cli.c | 50 +++++++++++++++++++++++++ ripngd/ripng_cli.h | 2 + ripngd/ripng_northbound.c | 32 ++++++++++++++-- ripngd/ripngd.c | 77 ++------------------------------------- ripngd/ripngd.h | 11 ++---- 5 files changed, 87 insertions(+), 85 deletions(-) diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c index e6daa62980..2d5c985045 100644 --- a/ripngd/ripng_cli.c +++ b/ripngd/ripng_cli.c @@ -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); } diff --git a/ripngd/ripng_cli.h b/ripngd/ripng_cli.h index 1eafd69f9e..99a67667e7 100644 --- a/ripngd/ripng_cli.h +++ b/ripngd/ripng_cli.h @@ -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_ */ diff --git a/ripngd/ripng_northbound.c b/ripngd/ripng_northbound.c index 163baecc95..4d1a945b6a 100644 --- a/ripngd/ripng_northbound.c +++ b/ripngd/ripng_northbound.c @@ -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, diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index dfa75361a2..3cdf5b03e3 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -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); diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index 4863d22069..a7453d1a1a 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -43,11 +43,6 @@ #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; -- 2.39.5