]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #8389 from idryzhov/route-map-optimization-nb
authorRenato Westphal <renato@opensourcerouting.org>
Tue, 13 Apr 2021 03:26:20 +0000 (00:26 -0300)
committerGitHub <noreply@github.com>
Tue, 13 Apr 2021 03:26:20 +0000 (00:26 -0300)
lib: convert route-map optimization to NB

doc/user/routemap.rst
lib/routemap.c
lib/routemap.h
lib/routemap_cli.c
lib/routemap_northbound.c
vtysh/vtysh_config.c
yang/frr-route-map.yang

index 7f357b09252c8e69ad0eaac987d69fbc68703dd5..3cb83cc6524caf6124c6a328258b61eaff0f8237 100644 (file)
@@ -333,10 +333,10 @@ Route Map Exit Action Command
 Route Map Optimization Command
 ==============================
 
-.. clicmd:: route-map optimization
+.. clicmd:: route-map ROUTE-MAP-NAME optimization
 
-   Enable route-map processing optimization. The optimization is
-   enabled by default.
+   Enable route-map processing optimization for `route-map-name`.
+   The optimization is enabled by default.
    Instead of sequentially passing through all the route-map indexes
    until a match is found, the search for the best-match index will be
    based on a look-up in a prefix-tree. A per-route-map prefix-tree
index 33c65ac33337587bb9f9ae6d501a7435b1e1ec00..b2cb299fd3403cd1b269529cc53966a137fae7bd 100644 (file)
@@ -2906,29 +2906,6 @@ void route_map_notify_dependencies(const char *affected_name,
 }
 
 /* VTY related functions. */
-DEFUN(no_routemap_optimization, no_routemap_optimization_cmd,
-      "no route-map optimization",
-      NO_STR
-      "route-map\n"
-      "optimization\n")
-{
-       VTY_DECLVAR_CONTEXT(route_map_index, index);
-
-       index->map->optimization_disabled = true;
-       return CMD_SUCCESS;
-}
-
-DEFUN(routemap_optimization, routemap_optimization_cmd,
-      "route-map optimization",
-      "route-map\n"
-      "optimization\n")
-{
-       VTY_DECLVAR_CONTEXT(route_map_index, index);
-
-       index->map->optimization_disabled = false;
-       return CMD_SUCCESS;
-}
-
 static void clear_route_map_helper(struct route_map *map)
 {
        struct route_map_index *index;
@@ -3241,8 +3218,5 @@ void route_map_init(void)
        install_element(ENABLE_NODE, &debug_rmap_cmd);
        install_element(ENABLE_NODE, &no_debug_rmap_cmd);
 
-       install_element(RMAP_NODE, &routemap_optimization_cmd);
-       install_element(RMAP_NODE, &no_routemap_optimization_cmd);
-
        install_element(ENABLE_NODE, &show_route_map_pfx_tbl_cmd);
 }
index 6385193bbf88854a7d2df944bcf7d238d1bb9e24..5b6b64eaebba560c8f0f84204e17922424a1c995 100644 (file)
@@ -902,6 +902,9 @@ extern void route_map_call_show(struct vty *vty, struct lyd_node *dnode,
 extern void route_map_description_show(struct vty *vty,
                                       struct lyd_node *dnode,
                                       bool show_defaults);
+extern void route_map_optimization_disabled_show(struct vty *vty,
+                                                struct lyd_node *dnode,
+                                                bool show_defaults);
 extern void route_map_cli_init(void);
 
 #ifdef __cplusplus
index 9a53c11a4cf8e3374da94f2b30702882b8ad41e7..e11b9eea7416cc5d8d45ad55e34220fb35fa88ca 100644 (file)
@@ -1396,6 +1396,74 @@ void route_map_description_show(struct vty *vty, struct lyd_node *dnode,
        vty_out(vty, " description %s\n", yang_dnode_get_string(dnode, NULL));
 }
 
+DEFPY_YANG(
+       route_map_optimization, route_map_optimization_cmd,
+       "[no] route-map WORD$name optimization",
+       NO_STR
+       ROUTE_MAP_CMD_STR
+       "Configure route-map optimization\n")
+{
+       char xpath[XPATH_MAXLEN];
+
+       snprintf(xpath, sizeof(xpath),
+                "/frr-route-map:lib/route-map[name='%s']", name);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
+
+       snprintf(
+               xpath, sizeof(xpath),
+               "/frr-route-map:lib/route-map[name='%s']/optimization-disabled",
+               name);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, no ? "true" : "false");
+
+       return nb_cli_apply_changes(vty, NULL);
+}
+
+void route_map_optimization_disabled_show(struct vty *vty,
+                                         struct lyd_node *dnode,
+                                         bool show_defaults)
+{
+       const char *name = yang_dnode_get_string(dnode, "../name");
+       const bool disabled = yang_dnode_get_bool(dnode, NULL);
+
+       vty_out(vty, "%sroute-map %s optimization\n", disabled ? "no " : "",
+               name);
+}
+
+#if CONFDATE > 20220409
+CPP_NOTICE("Time to remove old route-map optimization command")
+#endif
+
+DEFPY_HIDDEN(
+       routemap_optimization, routemap_optimization_cmd,
+       "[no] route-map optimization",
+       NO_STR
+       "route-map\n"
+       "optimization\n")
+{
+       const struct lyd_node *rmi_dnode;
+       const char *rm_name;
+       char xpath[XPATH_MAXLEN];
+
+       vty_out(vty,
+               "%% This command is deprecated. Please, use `route-map NAME optimization` from the config node.\n");
+
+       rmi_dnode =
+               yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
+       if (!rmi_dnode) {
+               vty_out(vty, "%% Failed to get RMI dnode in candidate DB\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
+       rm_name = yang_dnode_get_string(rmi_dnode, "../name");
+
+       snprintf(
+               xpath, sizeof(xpath),
+               "/frr-route-map:lib/route-map[name='%s']/optimization-disabled",
+               rm_name);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, no ? "true" : "false");
+       return nb_cli_apply_changes(vty, NULL);
+}
+
 static int route_map_config_write(struct vty *vty)
 {
        struct lyd_node *dnode;
@@ -1447,6 +1515,7 @@ void route_map_cli_init(void)
        install_element(CONFIG_NODE, &route_map_cmd);
        install_element(CONFIG_NODE, &no_route_map_cmd);
        install_element(CONFIG_NODE, &no_route_map_all_cmd);
+       install_element(CONFIG_NODE, &route_map_optimization_cmd);
 
        /* Install the on-match stuff */
        install_element(RMAP_NODE, &rmap_onmatch_next_cmd);
@@ -1513,4 +1582,6 @@ void route_map_cli_init(void)
 
        install_element(RMAP_NODE, &set_srte_color_cmd);
        install_element(RMAP_NODE, &no_set_srte_color_cmd);
+
+       install_element(RMAP_NODE, &routemap_optimization_cmd);
 }
index 410eb51f5e1712b6be6400a1cb747eb33590453b..db06e9caac75653dc80b1810ff808f1d09da408e 100644 (file)
@@ -140,6 +140,30 @@ static int lib_route_map_destroy(struct nb_cb_destroy_args *args)
        return NB_OK;
 }
 
+/*
+ * XPath: /frr-route-map:lib/route-map/optimization-disabled
+ */
+static int
+lib_route_map_optimization_disabled_modify(struct nb_cb_modify_args *args)
+{
+       struct route_map *rm;
+       bool disabled = yang_dnode_get_bool(args->dnode, NULL);
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               /* NOTHING */
+               break;
+       case NB_EV_APPLY:
+               rm = nb_running_get_entry(args->dnode, NULL, true);
+               rm->optimization_disabled = disabled;
+               break;
+       }
+
+       return NB_OK;
+}
+
 /*
  * XPath: /frr-route-map:lib/route-map/entry
  */
@@ -1197,6 +1221,13 @@ const struct frr_yang_module_info frr_route_map_info = {
                                .destroy = lib_route_map_destroy,
                        }
                },
+               {
+                       .xpath = "/frr-route-map:lib/route-map/optimization-disabled",
+                       .cbs = {
+                               .modify = lib_route_map_optimization_disabled_modify,
+                               .cli_show = route_map_optimization_disabled_show,
+                       }
+               },
                {
                        .xpath = "/frr-route-map:lib/route-map/entry",
                        .cbs = {
index 498d3e5f67328be753cf874f6abb2e3952b9f438..3414c764ce39783c5902e8663db87ef2e96c6487 100644 (file)
@@ -342,6 +342,9 @@ void vtysh_config_parse_line(void *arg, const char *line)
                        config = config_get(OPENFABRIC_NODE, line);
                else if (strncmp(line, "route-map", strlen("route-map")) == 0)
                        config = config_get(RMAP_NODE, line);
+               else if (strncmp(line, "no route-map", strlen("no route-map"))
+                        == 0)
+                       config = config_get(RMAP_NODE, line);
                else if (strncmp(line, "pbr-map", strlen("pbr-map")) == 0)
                        config = config_get(PBRMAP_NODE, line);
                else if (strncmp(line, "access-list", strlen("access-list"))
index 6ed3dadaae5addc4b4c3a92397e11c8043b922c1..c4eb78608b85fa3e1d3bcbbbadfbfd602733e2a9 100644 (file)
@@ -364,6 +364,11 @@ module frr-route-map {
         description
           "Route map instance name";
       }
+      leaf optimization-disabled {
+        type boolean;
+        default false;
+        description "Disables or enables the optimization";
+      }
 
       list entry {
         key "sequence";