]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripngd: retrofit the 'router ripng' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 29 Nov 2018 02:49:49 +0000 (00:49 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 3 Dec 2018 15:47:58 +0000 (13:47 -0200)
* 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>
ripngd/ripng_cli.c
ripngd/ripng_cli.h
ripngd/ripng_northbound.c
ripngd/ripngd.c
ripngd/ripngd.h

index b033a39ac6218d09052ff9e12bda228f6c4aad02..7bdc7422070157763291f8369ed6a630f2ac091e 100644 (file)
 #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);
 }
index a3f29b985985a2e7e2d5c913b13d460173691f9e..f0ef046f6a72c0ae21a2234d50e79d43913f1343 100644 (file)
@@ -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_ */
index 84e4bf43e77375fc150d97c1ccf8dffbc1cbf08b..219d8d1db7244f0bf2de604f3446d85e74f488c4 100644 (file)
@@ -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",
index 2cbbbae7f547faf5f29d2413802f519e6fdbc522..634596719c592fc9ed13b85c954819611c1d8a76 100644 (file)
@@ -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);
index 7d4f822da4a9a818f11a04e843a9af449012a376..de3b2e194735b570f6fd285fe045031593f01154 100644 (file)
@@ -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 *);