summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2021-04-01 19:28:24 +0300
committerIgor Ryzhov <iryzhov@nfware.com>2021-04-06 19:00:21 +0300
commit3ebeec9446e4bcc29f477c778ff2b4fa276df7d3 (patch)
treee08b6047835b93fe96f8941872c7f4441e8887b8
parentd6cfe1b8840fa75ee0e617f28b32eccc60fd715e (diff)
lib: convert route-map optimization to NB
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
-rw-r--r--lib/routemap.c26
-rw-r--r--lib/routemap_cli.c29
-rw-r--r--lib/routemap_northbound.c30
-rw-r--r--yang/frr-route-map.yang5
4 files changed, 64 insertions, 26 deletions
diff --git a/lib/routemap.c b/lib/routemap.c
index 33c65ac333..b2cb299fd3 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -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);
}
diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c
index 9a53c11a4c..c93e59e99b 100644
--- a/lib/routemap_cli.c
+++ b/lib/routemap_cli.c
@@ -1396,6 +1396,33 @@ 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(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];
+
+ 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;
@@ -1513,4 +1540,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);
}
diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c
index 410eb51f5e..64be8ad6b0 100644
--- a/lib/routemap_northbound.c
+++ b/lib/routemap_northbound.c
@@ -141,6 +141,30 @@ static int lib_route_map_destroy(struct nb_cb_destroy_args *args)
}
/*
+ * 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
*/
static int lib_route_map_entry_create(struct nb_cb_create_args *args)
@@ -1198,6 +1222,12 @@ const struct frr_yang_module_info frr_route_map_info = {
}
},
{
+ .xpath = "/frr-route-map:lib/route-map/optimization-disabled",
+ .cbs = {
+ .modify = lib_route_map_optimization_disabled_modify,
+ }
+ },
+ {
.xpath = "/frr-route-map:lib/route-map/entry",
.cbs = {
.create = lib_route_map_entry_create,
diff --git a/yang/frr-route-map.yang b/yang/frr-route-map.yang
index 6ed3dadaae..c4eb78608b 100644
--- a/yang/frr-route-map.yang
+++ b/yang/frr-route-map.yang
@@ -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";