diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2018-11-29 03:49:49 +0100 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2018-12-03 16:47:58 +0100 |
commit | 9a12e9e5edb4f119cd794f347581ae3a950f2c15 (patch) | |
tree | c7f26c73fd4c52e444a7c2dc1b032cd7c099544c /ripngd | |
parent | yang, ripngd: add 'frr-ripngd.yang' and associated stub callbacks (diff) | |
download | frr-9a12e9e5edb4f119cd794f347581ae3a950f2c15.tar.xz frr-9a12e9e5edb4f119cd794f347581ae3a950f2c15.zip |
ripngd: retrofit the 'router ripng' command to the new northbound model
* Implement the northbound callbacks associated to the
'/frr-ripngd:ripngd/instance' YANG path (the code is mostly a copy
and paste from the original "router ripng" DEFUNs);
* Move ripng_make_socket() out of ripng_create() since creating a
socket is an error-prone operation and thus needs to be performed
separately during the NB_EV_PREPARE phase;
* On ripng_create(), fetch the defaults from the frr-ripngd YANG
model;
* Convert the "[no] router ripng" CLI commands to be dumb wrappers
around the northbound callbacks;
* On ripng_config_write(), write logic to call all 'cli_show'
northbound callbacks defined under the '/frr-ripngd:ripngd/instance'
YANG path.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'ripngd')
-rw-r--r-- | ripngd/ripng_cli.c | 43 | ||||
-rw-r--r-- | ripngd/ripng_cli.h | 3 | ||||
-rw-r--r-- | ripngd/ripng_northbound.c | 29 | ||||
-rw-r--r-- | ripngd/ripngd.c | 78 | ||||
-rw-r--r-- | ripngd/ripngd.h | 2 |
5 files changed, 97 insertions, 58 deletions
diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c index b033a39ac..7bdc74220 100644 --- a/ripngd/ripng_cli.c +++ b/ripngd/ripng_cli.c @@ -34,6 +34,49 @@ #include "ripngd/ripng_cli_clippy.c" #endif +/* + * XPath: /frr-ripngd:ripngd/instance + */ +DEFPY_NOSH (router_ripng, + router_ripng_cmd, + "router ripng", + "Enable a routing process\n" + "Make RIPng instance command\n") +{ + int ret; + + nb_cli_enqueue_change(vty, "/frr-ripngd:ripngd/instance", NB_OP_CREATE, + NULL); + + ret = nb_cli_apply_changes(vty, NULL); + if (ret == CMD_SUCCESS) + VTY_PUSH_XPATH(RIPNG_NODE, "/frr-ripngd:ripngd/instance"); + + return ret; +} + +DEFPY (no_router_ripng, + no_router_ripng_cmd, + "no router ripng", + NO_STR + "Enable a routing process\n" + "Make RIPng instance command\n") +{ + nb_cli_enqueue_change(vty, "/frr-ripngd:ripngd/instance", NB_OP_DELETE, + NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_router_ripng(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) +{ + vty_out(vty, "!\n"); + vty_out(vty, "router ripng\n"); +} + void ripng_cli_init(void) { + install_element(CONFIG_NODE, &router_ripng_cmd); + install_element(CONFIG_NODE, &no_router_ripng_cmd); } diff --git a/ripngd/ripng_cli.h b/ripngd/ripng_cli.h index a3f29b985..f0ef046f6 100644 --- a/ripngd/ripng_cli.h +++ b/ripngd/ripng_cli.h @@ -21,4 +21,7 @@ #ifndef _FRR_RIPNG_CLI_H_ #define _FRR_RIPNG_CLI_H_ +extern void cli_show_router_ripng(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 84e4bf43e..219d8d1db 100644 --- a/ripngd/ripng_northbound.c +++ b/ripngd/ripng_northbound.c @@ -40,14 +40,38 @@ static int ripngd_instance_create(enum nb_event event, const struct lyd_node *dnode, union nb_resource *resource) { - /* TODO: implement me. */ + int socket; + + switch (event) { + case NB_EV_VALIDATE: + break; + case NB_EV_PREPARE: + socket = ripng_make_socket(); + if (socket < 0) + return NB_ERR_RESOURCE; + resource->fd = socket; + break; + case NB_EV_ABORT: + socket = resource->fd; + close(socket); + break; + case NB_EV_APPLY: + socket = resource->fd; + ripng_create(socket); + break; + } + return NB_OK; } static int ripngd_instance_delete(enum nb_event event, const struct lyd_node *dnode) { - /* TODO: implement me. */ + if (event != NB_EV_APPLY) + return NB_OK; + + ripng_clean(); + return NB_OK; } @@ -484,6 +508,7 @@ const struct frr_yang_module_info frr_ripngd_info = { .xpath = "/frr-ripngd:ripngd/instance", .cbs.create = ripngd_instance_create, .cbs.delete = ripngd_instance_delete, + .cbs.cli_show = cli_show_router_ripng, }, { .xpath = "/frr-ripngd:ripngd/instance/allow-ecmp", diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 2cbbbae7f..634596719 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -36,6 +36,7 @@ #include "if_rmap.h" #include "privs.h" #include "lib_errors.h" +#include "northbound_cli.h" #include "ripngd/ripngd.h" #include "ripngd/ripng_route.h" @@ -87,7 +88,7 @@ void ripng_info_free(struct ripng_info *rinfo) } /* Create ripng socket. */ -static int ripng_make_socket(void) +int ripng_make_socket(void) { int ret; int sock; @@ -1778,7 +1779,7 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, } /* Create new RIPng instance and set it to global variable. */ -static int ripng_create(void) +int ripng_create(int socket) { /* ripng should be NULL. */ assert(ripng == NULL); @@ -1788,10 +1789,15 @@ static int ripng_create(void) /* Default version and timer values. */ ripng->version = RIPNG_V1; - ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT; - ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT; - ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT; - ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT; + ripng->update_time = yang_get_default_uint32( + "%s/timers/update-interval", RIPNG_INSTANCE); + ripng->timeout_time = yang_get_default_uint32( + "%s/timers/holddown-interval", RIPNG_INSTANCE); + ripng->garbage_time = yang_get_default_uint32( + "%s/timers/flush-interval", RIPNG_INSTANCE); + ripng->default_metric = + yang_get_default_uint8("%s/default-metric", RIPNG_INSTANCE); + ripng->ecmp = yang_get_default_bool("%s/allow-ecmp", RIPNG_INSTANCE); /* Make buffer. */ ripng->ibuf = stream_new(RIPNG_MAX_PACKET_SIZE * 5); @@ -1803,9 +1809,7 @@ static int ripng_create(void) ripng->aggregate = agg_table_init(); /* Make socket. */ - ripng->sock = ripng_make_socket(); - if (ripng->sock < 0) - return ripng->sock; + ripng->sock = socket; /* Threads. */ ripng_event(RIPNG_READ, ripng->sock); @@ -2153,41 +2157,6 @@ DEFUN (clear_ipv6_rip, return CMD_SUCCESS; } -DEFUN_NOSH (router_ripng, - router_ripng_cmd, - "router ripng", - "Enable a routing process\n" - "Make RIPng instance command\n") -{ - int ret; - - vty->node = RIPNG_NODE; - - if (!ripng) { - ret = ripng_create(); - - /* Notice to user we couldn't create RIPng. */ - if (ret < 0) { - zlog_warn("can't create RIPng"); - return CMD_WARNING_CONFIG_FAILED; - } - } - - return CMD_SUCCESS; -} - -DEFUN (no_router_ripng, - no_router_ripng_cmd, - "no router ripng", - NO_STR - "Enable a routing process\n" - "Make RIPng instance command\n") -{ - if (ripng) - ripng_clean(); - return CMD_SUCCESS; -} - DEFUN (ripng_route, ripng_route_cmd, "route IPV6ADDR", @@ -2643,15 +2612,14 @@ DEFUN (no_ripng_allow_ecmp, /* RIPng configuration write function. */ static int ripng_config_write(struct vty *vty) { - int ripng_network_write(struct vty *, int); - void ripng_redistribute_write(struct vty *, int); + struct lyd_node *dnode; int write = 0; struct agg_node *rp; - if (ripng) { - - /* RIPng router. */ - vty_out(vty, "router ripng\n"); + dnode = yang_dnode_get(running_config->dnode, + "/frr-ripngd:ripngd/instance"); + if (dnode) { + nb_cli_show_dnode_cmds(vty, dnode, false); if (ripng->default_information) vty_out(vty, " default-information originate\n"); @@ -2705,12 +2673,13 @@ static int ripng_config_write(struct vty *vty) vty_out (vty, " garbage-timer %d\n", ripng->garbage_time); #endif /* 0 */ - write += config_write_distribute(vty); + config_write_distribute(vty); - write += config_write_if_rmap(vty); + config_write_if_rmap(vty); - write++; + write = 1; } + return write; } @@ -2989,9 +2958,6 @@ void ripng_init() install_element(ENABLE_NODE, &clear_ipv6_rip_cmd); - install_element(CONFIG_NODE, &router_ripng_cmd); - install_element(CONFIG_NODE, &no_router_ripng_cmd); - install_default(RIPNG_NODE); install_element(RIPNG_NODE, &ripng_route_cmd); install_element(RIPNG_NODE, &no_ripng_route_cmd); diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index 7d4f822da..de3b2e194 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -410,6 +410,8 @@ extern int ripng_interface_address_add(int command, struct zclient *, extern int ripng_interface_address_delete(int command, struct zclient *, zebra_size_t, vrf_id_t); +extern int ripng_create(int socket); +extern int ripng_make_socket(void); extern int ripng_network_write(struct vty *, int); extern struct ripng_info *ripng_ecmp_add(struct ripng_info *); |