summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ospfd/ospf_main.c2
-rw-r--r--ospfd/ospf_routemap.c25
-rw-r--r--ospfd/ospf_routemap_nb.c39
-rw-r--r--ospfd/ospf_routemap_nb.h37
-rw-r--r--ospfd/ospf_routemap_nb_config.c63
-rw-r--r--ospfd/ospfd.h1
-rw-r--r--ospfd/subdir.am7
7 files changed, 167 insertions, 7 deletions
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index d23dea0ca1..91ba3044fe 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -56,6 +56,7 @@
#include "ospfd/ospf_bfd.h"
#include "ospfd/ospf_errors.h"
#include "ospfd/ospf_ldp_sync.h"
+#include "ospfd/ospf_routemap_nb.h"
/* ospfd privileges */
zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
@@ -134,6 +135,7 @@ static const struct frr_yang_module_info *const ospfd_yang_modules[] = {
&frr_interface_info,
&frr_route_map_info,
&frr_vrf_info,
+ &frr_ospf_route_map_info,
};
FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c
index bdc65d23bf..d3b114840e 100644
--- a/ospfd/ospf_routemap.c
+++ b/ospfd/ospf_routemap.c
@@ -33,6 +33,7 @@
#include "plist.h"
#include "vrf.h"
#include "frrstr.h"
+#include "northbound_cli.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_asbr.h"
@@ -534,7 +535,7 @@ static const struct route_map_rule_cmd route_set_tag_cmd = {
route_map_rule_tag_free,
};
-DEFUN (set_metric_type,
+DEFUN_YANG (set_metric_type,
set_metric_type_cmd,
"set metric-type <type-1|type-2>",
SET_STR
@@ -543,11 +544,19 @@ DEFUN (set_metric_type,
"OSPF[6] external type 2 metric\n")
{
char *ext = argv[2]->text;
- return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index),
- "metric-type", ext);
+
+ const char *xpath =
+ "./set-action[action='frr-ospf-route-map:metric-type']";
+ char xpath_value[XPATH_MAXLEN];
+
+ nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
+ snprintf(xpath_value, sizeof(xpath_value),
+ "%s/rmap-set-action/frr-ospf-route-map:metric-type", xpath);
+ nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, ext);
+ return nb_cli_apply_changes(vty, NULL);
}
-DEFUN (no_set_metric_type,
+DEFUN_YANG (no_set_metric_type,
no_set_metric_type_cmd,
"no set metric-type [<type-1|type-2>]",
NO_STR
@@ -556,9 +565,11 @@ DEFUN (no_set_metric_type,
"OSPF[6] external type 1 metric\n"
"OSPF[6] external type 2 metric\n")
{
- char *ext = (argc == 4) ? argv[3]->text : NULL;
- return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index),
- "metric-type", ext);
+ const char *xpath =
+ "./set-action[action='frr-ospf-route-map:metric-type']";
+
+ nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
+ return nb_cli_apply_changes(vty, NULL);
}
/* Route-map init */
diff --git a/ospfd/ospf_routemap_nb.c b/ospfd/ospf_routemap_nb.c
new file mode 100644
index 0000000000..1f6b0ef78c
--- /dev/null
+++ b/ospfd/ospf_routemap_nb.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 Vmware
+ * Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "lib/northbound.h"
+#include "lib/routemap.h"
+#include "ospf_routemap_nb.h"
+
+/* clang-format off */
+const struct frr_yang_module_info frr_ospf_route_map_info = {
+ .name = "frr-ospf-route-map",
+ .nodes = {
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf-route-map:metric-type",
+ .cbs = {
+ .modify = lib_route_map_entry_set_action_rmap_set_action_metric_type_modify,
+ .destroy = lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy,
+ }
+ },
+ {
+ .xpath = NULL,
+ },
+ }
+};
diff --git a/ospfd/ospf_routemap_nb.h b/ospfd/ospf_routemap_nb.h
new file mode 100644
index 0000000000..17bcb4f5c3
--- /dev/null
+++ b/ospfd/ospf_routemap_nb.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 Vmware
+ * Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _FRR_OSPF_ROUTEMAP_NB_H_
+#define _FRR_OSPF_ROUTEMAP_NB_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const struct frr_yang_module_info frr_ospf_route_map_info;
+
+/* prototypes */
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy(struct nb_cb_destroy_args *args);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/ospfd/ospf_routemap_nb_config.c b/ospfd/ospf_routemap_nb_config.c
new file mode 100644
index 0000000000..bfb18c5e08
--- /dev/null
+++ b/ospfd/ospf_routemap_nb_config.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2020 Vmware
+ * Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "lib/command.h"
+#include "lib/log.h"
+#include "lib/northbound.h"
+#include "lib/routemap.h"
+#include "ospf_routemap_nb.h"
+
+/*
+ * XPath:
+ * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf-route-map:metric-type
+ */
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct routemap_hook_context *rhc;
+ const char *type;
+ int rv;
+
+ if (args->event != NB_EV_APPLY)
+ return NB_OK;
+
+ /* Add configuration. */
+ rhc = nb_running_get_entry(args->dnode, NULL, true);
+ type = yang_dnode_get_string(args->dnode, NULL);
+
+ /* Set destroy information. */
+ rhc->rhc_shook = generic_set_delete;
+ rhc->rhc_rule = "metric-type";
+ rhc->rhc_event = RMAP_EVENT_SET_DELETED;
+
+ rv = generic_set_add(rhc->rhc_rmi, "metric-type", type,
+ args->errmsg, args->errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_mhook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+
+ return NB_OK;
+}
+
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ return lib_route_map_entry_set_destroy(args);
+}
diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h
index 7463e069ad..2093eb2e42 100644
--- a/ospfd/ospfd.h
+++ b/ospfd/ospfd.h
@@ -732,4 +732,5 @@ extern int p_spaces_compare_func(const struct p_space *a,
const struct p_space *b);
extern int q_spaces_compare_func(const struct q_space *a,
const struct q_space *b);
+
#endif /* _ZEBRA_OSPFD_H */
diff --git a/ospfd/subdir.am b/ospfd/subdir.am
index 25ddef358f..63610e38d8 100644
--- a/ospfd/subdir.am
+++ b/ospfd/subdir.am
@@ -51,6 +51,8 @@ ospfd_libfrrospf_a_SOURCES = \
ospfd/ospf_ri.c \
ospfd/ospf_route.c \
ospfd/ospf_routemap.c \
+ ospfd/ospf_routemap_nb.c \
+ ospfd/ospf_routemap_nb_config.c \
ospfd/ospf_spf.c \
ospfd/ospf_ti_lfa.c \
ospfd/ospf_sr.c \
@@ -100,6 +102,7 @@ noinst_HEADERS += \
ospfd/ospf_packet.h \
ospfd/ospf_ri.h \
ospfd/ospf_route.h \
+ ospfd/ospf_routemap_nb.h \
ospfd/ospf_spf.h \
ospfd/ospf_ti_lfa.h \
ospfd/ospf_sr.h \
@@ -120,3 +123,7 @@ ospfd_ospfd_snmp_la_LIBADD = lib/libfrrsnmp.la
EXTRA_DIST += \
ospfd/ChangeLog.opaque.txt \
# end
+
+nodist_ospfd_ospfd_SOURCES = \
+ yang/frr-ospf-route-map.yang.c \
+ # end