]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib : basic-routing backend configuration northbound code
authorvdhingra <vdhingra@vmware.com>
Fri, 24 Apr 2020 12:37:36 +0000 (05:37 -0700)
committervdhingra <vdhingra@vmware.com>
Thu, 16 Jul 2020 15:33:00 +0000 (08:33 -0700)
Signed-off-by: VishalDhingra <vdhingra@vmware.com>
lib/routing_nb.c [new file with mode: 0644]
lib/routing_nb.h [new file with mode: 0644]
lib/routing_nb_config.c [new file with mode: 0644]
lib/subdir.am

diff --git a/lib/routing_nb.c b/lib/routing_nb.c
new file mode 100644 (file)
index 0000000..7a6754b
--- /dev/null
@@ -0,0 +1,22 @@
+#include "northbound.h"
+#include "libfrr.h"
+#include "routing_nb.h"
+
+
+
+/* clang-format off */
+const struct frr_yang_module_info frr_routing_info = {
+       .name = "frr-routing",
+       .nodes = {
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol",
+                       .cbs = {
+                               .create = routing_control_plane_protocols_control_plane_protocol_create,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_destroy,
+                       }
+               },
+               {
+                       .xpath = NULL,
+               },
+       }
+};
diff --git a/lib/routing_nb.h b/lib/routing_nb.h
new file mode 100644 (file)
index 0000000..d1b59ea
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef _FRR_ROUTING_NB_H_
+#define _FRR_ROUTING_NB_H_
+
+extern const struct frr_yang_module_info frr_routing_info;
+
+/* Mandatory callbacks. */
+int routing_control_plane_protocols_control_plane_protocol_create(
+       struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_destroy(
+       struct nb_cb_destroy_args *args);
+
+#define FRR_ROUTING_XPATH                                                      \
+       "/frr-routing:routing/control-plane-protocols/control-plane-protocol"
+
+#define FRR_ROUTING_KEY_XPATH                                                  \
+       "/frr-routing:routing/control-plane-protocols/"                        \
+       "control-plane-protocol[type='%s'][name='%s'][vrf='%s']"
+/*
+ * callbacks for routing to handle configuration events
+ * based on the control plane protocol
+ */
+DECLARE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args))
+
+#endif /* _FRR_ROUTING_NB_H_ */
diff --git a/lib/routing_nb_config.c b/lib/routing_nb_config.c
new file mode 100644 (file)
index 0000000..b789e84
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018        Vmware
+ *                           Vishal Dhingra
+ *
+ * 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 "northbound.h"
+#include "libfrr.h"
+#include "vrf.h"
+#include "lib_errors.h"
+#include "routing_nb.h"
+
+
+DEFINE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args))
+
+/*
+ * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
+ */
+
+int routing_control_plane_protocols_control_plane_protocol_create(
+       struct nb_cb_create_args *args)
+{
+       struct vrf *vrf;
+       const char *vrfname;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+               if (hook_call(routing_conf_event, args))
+                       return NB_ERR_VALIDATION;
+               break;
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               vrfname = yang_dnode_get_string(args->dnode, "./vrf");
+               vrf = vrf_lookup_by_name(vrfname);
+               vrf = vrf ? vrf : vrf_get(VRF_UNKNOWN, vrfname);
+               if (!vrf) {
+                       flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+                                 "vrf creation %s failed", vrfname);
+                       return NB_ERR;
+               }
+               nb_running_set_entry(args->dnode, vrf);
+               break;
+       };
+
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       struct vrf *vrf __attribute__((unused));
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_unset_entry(args->dnode);
+
+       return NB_OK;
+}
index 57b2cea832f3fd42e231ae962ba309ef779b775c..f185841c76268e6d1f0078a97c73987bc106da8e 100644 (file)
@@ -108,6 +108,8 @@ lib_libfrr_la_SOURCES = \
        lib/printf/printf-pos.c \
        lib/printf/vfprintf.c \
        lib/printf/glue.c \
+       lib/routing_nb.c \
+       lib/routing_nb_config.c \
        # end
 
 nodist_lib_libfrr_la_SOURCES = \
@@ -117,6 +119,7 @@ nodist_lib_libfrr_la_SOURCES = \
        yang/frr-route-types.yang.c \
        yang/frr-vrf.yang.c \
        yang/frr-routing.yang.c \
+       yang/frr-nexthop.yang.c \
        yang/ietf/ietf-routing-types.yang.c \
        yang/ietf/ietf-interfaces.yang.c \
        yang/frr-module-translator.yang.c \
@@ -266,6 +269,7 @@ pkginclude_HEADERS += \
        lib/zlog.h \
        lib/zlog_targets.h \
        lib/pbr.h \
+       lib/routing_nb.h \
        # end