]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospfd: North-bound implementation for ospfd rmaps
authorSarita Patra <saritap@vmware.com>
Fri, 30 Oct 2020 07:44:04 +0000 (00:44 -0700)
committerIgor Ryzhov <iryzhov@nfware.com>
Tue, 30 Mar 2021 19:59:30 +0000 (22:59 +0300)
This commit introduces the implementation for the north-bound
callbacks for the ospfd-specific route-map match and set clauses.

Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
Signed-off-by: Sarita Patra <saritap@vmware.com>
ospfd/ospf_main.c
ospfd/ospf_routemap.c
ospfd/ospf_routemap_nb.c [new file with mode: 0644]
ospfd/ospf_routemap_nb.h [new file with mode: 0644]
ospfd/ospf_routemap_nb_config.c [new file with mode: 0644]
ospfd/ospfd.h
ospfd/subdir.am

index d23dea0ca1506f1d472f0b76bce71327781267a2..91ba3044fe5fe018ed9bab7cc1586fbc942b4453 100644 (file)
@@ -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,
index bdc65d23bf64ccffdb930c28e8c39ddfd1c14761..d3b114840ee2e38a1d0cb5ce43a6bd836cbc53c3 100644 (file)
@@ -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 (file)
index 0000000..1f6b0ef
--- /dev/null
@@ -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 (file)
index 0000000..17bcb4f
--- /dev/null
@@ -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 (file)
index 0000000..bfb18c5
--- /dev/null
@@ -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);
+}
index 7463e069ad080922f30a064f0be44a8bd341b219..2093eb2e4202afaf05db071dc696cdd233a28d16 100644 (file)
@@ -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 */
index 25ddef358f860905c1c6458dbd5274f78eea04a2..63610e38d8d980bd3e5fb4713596b90e681ed52e 100644 (file)
@@ -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