]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: retrofit the 'allow-ecmp' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 9 May 2018 04:34:58 +0000 (01:34 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 27 Oct 2018 18:16:12 +0000 (16:16 -0200)
Trivial conversion. The rip->ecmp variable was converted to a boolean to
match the way it's defined in the YANG module.

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 684fbd300aa6ad1d46ec8093f46a47b63182b994..e3b15047b20f48f47855ab72b345e4cab4969d0c 100644 (file)
@@ -85,8 +85,39 @@ void cli_show_router_rip(struct vty *vty, struct lyd_node *dnode,
        vty_out(vty, "router rip\n");
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/allow-ecmp
+ */
+DEFPY (rip_allow_ecmp,
+       rip_allow_ecmp_cmd,
+       "[no] allow-ecmp",
+       NO_STR
+       "Allow Equal Cost MultiPath\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./allow-ecmp",
+                       .operation = NB_OP_MODIFY,
+                       .value = no ? "false" : "true",
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
+                            bool show_defaults)
+{
+       if (!yang_dnode_get_bool(dnode, NULL))
+               vty_out(vty, " no");
+
+       vty_out(vty, " allow-ecmp\n");
+}
+
 void rip_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_rip_cmd);
        install_element(CONFIG_NODE, &no_router_rip_cmd);
+
+       install_element(RIP_NODE, &rip_allow_ecmp_cmd);
 }
index b8997e8805127bf7e840185b70eec35d38bc2a45..259a78d8ec15587c9c33d41d461a4fc08d2086d2 100644 (file)
@@ -23,5 +23,7 @@
 
 extern void cli_show_router_rip(struct vty *vty, struct lyd_node *dnode,
                                bool show_defaults);
+extern void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
+                                   bool show_defaults);
 
 #endif /* _FRR_RIP_CLI_H_ */
index e780bc5e116e6623a105f268e37fac5b5f8492be..76b154d309e2c8ff73122b4e4c1a540cc7d5919f 100644 (file)
@@ -81,7 +81,13 @@ static int ripd_instance_allow_ecmp_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->ecmp = yang_dnode_get_bool(dnode, NULL);
+       if (!rip->ecmp)
+               rip_ecmp_disable();
+
        return NB_OK;
 }
 
@@ -722,6 +728,7 @@ const struct frr_yang_module_info frr_ripd_info = {
                {
                        .xpath = "/frr-ripd:ripd/instance/allow-ecmp",
                        .cbs.modify = ripd_instance_allow_ecmp_modify,
+                       .cbs.cli_show = cli_show_rip_allow_ecmp,
                },
                {
                        .xpath = "/frr-ripd:ripd/instance/default-information-originate",
index 9cb1ae8cfbc7cf749e2f980bc1e2841c5940d06f..ca2bad6de15ebcb1c264f8d4cf1652348b406ea7 100644 (file)
@@ -3290,7 +3290,7 @@ DEFUN (no_rip_distance_source_access_list,
 }
 
 /* Update ECMP routes to zebra when ECMP is disabled. */
-static void rip_ecmp_disable(void)
+void rip_ecmp_disable(void)
 {
        struct route_node *rp;
        struct rip_info *rinfo, *tmp_rinfo;
@@ -3327,38 +3327,6 @@ static void rip_ecmp_disable(void)
                }
 }
 
-DEFUN (rip_allow_ecmp,
-       rip_allow_ecmp_cmd,
-       "allow-ecmp",
-       "Allow Equal Cost MultiPath\n")
-{
-       if (rip->ecmp) {
-               vty_out(vty, "ECMP is already enabled.\n");
-               return CMD_WARNING;
-       }
-
-       rip->ecmp = 1;
-       zlog_info("ECMP is enabled.");
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_rip_allow_ecmp,
-       no_rip_allow_ecmp_cmd,
-       "no allow-ecmp",
-       NO_STR
-       "Allow Equal Cost MultiPath\n")
-{
-       if (!rip->ecmp) {
-               vty_out(vty, "ECMP is already disabled.\n");
-               return CMD_WARNING;
-       }
-
-       rip->ecmp = 0;
-       zlog_info("ECMP is disabled.");
-       rip_ecmp_disable();
-       return CMD_SUCCESS;
-}
-
 /* Print out routes update time. */
 static void rip_vty_out_uptime(struct vty *vty, struct rip_info *rinfo)
 {
@@ -3684,10 +3652,6 @@ static int config_write_rip(struct vty *vty)
                                                ? rdistance->access_list
                                                : "");
 
-               /* ECMP configuration. */
-               if (rip->ecmp)
-                       vty_out(vty, " allow-ecmp\n");
-
                /* RIP static route configuration. */
                for (rn = route_top(rip->route); rn; rn = route_next(rn))
                        if (rn->info)
@@ -3982,8 +3946,6 @@ void rip_init(void)
        install_element(RIP_NODE, &no_rip_distance_source_cmd);
        install_element(RIP_NODE, &rip_distance_source_access_list_cmd);
        install_element(RIP_NODE, &no_rip_distance_source_access_list_cmd);
-       install_element(RIP_NODE, &rip_allow_ecmp_cmd);
-       install_element(RIP_NODE, &no_rip_allow_ecmp_cmd);
 
        /* Debug related init. */
        rip_debug_init();
index 8e34939f2e5055b5e344ac6ce10f3575f921787b..68b302e87843c08b0c743999903e4e69ec05c24e 100644 (file)
@@ -151,7 +151,7 @@ struct rip {
        struct route_table *distance_table;
 
        /* RIP ECMP flag */
-       unsigned int ecmp;
+       bool ecmp;
 
        /* For redistribute route map. */
        struct {
@@ -389,6 +389,8 @@ extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t,
                            struct connected *);
 extern int rip_neighbor_lookup(struct sockaddr_in *);
 
+extern void rip_ecmp_disable(void);
+
 extern int rip_create_socket(void);
 
 extern int rip_redistribute_check(int);