Restructure and more generic plugin API for backend
This commit is contained in:
parent
7fbd95d491
commit
b9a54f07f3
19 changed files with 570 additions and 629 deletions
|
|
@ -45,11 +45,12 @@ CFLAGS = @CFLAGS@ -rdynamic -fPIC
|
|||
INCLUDES = -I$(includedir) @INCLUDES@
|
||||
|
||||
BE_PLUGIN = $(APPNAME)_backend.so
|
||||
BE2_PLUGIN = $(APPNAME)_backend_secondary.so
|
||||
CLI_PLUGIN = $(APPNAME)_cli.so
|
||||
NETCONF_PLUGIN = $(APPNAME)_netconf.so
|
||||
RESTCONF_PLUGIN = $(APPNAME)_restconf.so
|
||||
|
||||
PLUGINS = $(BE_PLUGIN) $(CLI_PLUGIN) $(NETCONF_PLUGIN) $(RESTCONF_PLUGIN)
|
||||
PLUGINS = $(BE_PLUGIN) $(BE2_PLUGIN) $(CLI_PLUGIN) $(NETCONF_PLUGIN) $(RESTCONF_PLUGIN)
|
||||
|
||||
all: $(PLUGINS)
|
||||
|
||||
|
|
@ -74,6 +75,12 @@ BE_OBJ = $(BE_SRC:%.c=%.o)
|
|||
$(BE_PLUGIN): $(BE_OBJ)
|
||||
$(CC) -Wall -shared -o $@ -lc $<
|
||||
|
||||
# Secondary backend plugin
|
||||
BE2_SRC = $(APPNAME)_backend_secondary.c
|
||||
BE2_OBJ = $(BE2_SRC:%.c=%.o)
|
||||
$(BE2_PLUGIN): $(BE2_OBJ)
|
||||
$(CC) -Wall -shared -o $@ -lc $<
|
||||
|
||||
# CLI frontend plugin
|
||||
CLI_SRC = $(APPNAME)_cli.c
|
||||
CLI_OBJ = $(CLI_SRC:%.c=%.o)
|
||||
|
|
@ -92,8 +99,8 @@ RESTCONF_OBJ = $(RESTCONF_SRC:%.c=%.o)
|
|||
$(RESTCONF_PLUGIN): $(RESTCONF_OBJ)
|
||||
$(CC) -Wall -shared -o $@ -lc $^
|
||||
|
||||
SRC = $(BE_SRC) $(CLI_SRC) $(NETCONF_SRC) $(RESTCONF_SRC)
|
||||
OBJS = $(BE_OBJ) $(CLI_OBJ) $(NETCONF_OBJ) $(RESTCONF_OBJ)
|
||||
SRC = $(BE_SRC) $(BE2_SRC) $(CLI_SRC) $(NETCONF_SRC) $(RESTCONF_SRC)
|
||||
OBJS = $(BE_OBJ) $(BE2_OBJ) $(CLI_OBJ) $(NETCONF_OBJ) $(RESTCONF_OBJ)
|
||||
|
||||
clean:
|
||||
rm -f $(PLUGINS) $(OBJS)
|
||||
|
|
@ -103,7 +110,7 @@ distclean: clean
|
|||
rm -f Makefile *~ .depend
|
||||
(cd docker && $(MAKE) $(MFLAGS) $@)
|
||||
|
||||
install: $(YANGSPECS) $(CLISPECS) $(BE_PLUGIN) $(CLI_PLUGIN) $(NETCONF_PLUGIN) $(RESTCONF_PLUGIN) $(APPNAME).xml
|
||||
install: $(YANGSPECS) $(CLISPECS) $(BE_PLUGIN) $(BE2_PLUGIN) $(CLI_PLUGIN) $(NETCONF_PLUGIN) $(RESTCONF_PLUGIN) $(APPNAME).xml
|
||||
install -d $(DESTDIR)$(clixon_SYSCONFDIR)
|
||||
install $(APPNAME).xml $(DESTDIR)$(clixon_SYSCONFDIR)
|
||||
install -d $(DESTDIR)$(clixon_DBSPECDIR)/yang
|
||||
|
|
@ -111,7 +118,7 @@ install: $(YANGSPECS) $(CLISPECS) $(BE_PLUGIN) $(CLI_PLUGIN) $(NETCONF_PLUGIN) $
|
|||
install -d $(DESTDIR)$(clixon_LIBDIR)/cli
|
||||
install $(CLI_PLUGIN) $(DESTDIR)$(clixon_LIBDIR)/cli;
|
||||
install -d $(DESTDIR)$(clixon_LIBDIR)/backend
|
||||
install $(BE_PLUGIN) $(DESTDIR)$(clixon_LIBDIR)/backend;
|
||||
install $(BE_PLUGIN) $(BE2_PLUGIN) $(DESTDIR)$(clixon_LIBDIR)/backend;
|
||||
install -d $(DESTDIR)$(clixon_LIBDIR)/netconf
|
||||
install $(NETCONF_PLUGIN) $(DESTDIR)$(clixon_LIBDIR)/netconf;
|
||||
install -d $(DESTDIR)$(clixon_LIBDIR)/restconf
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ routing example. It contains the following files:
|
|||
* notification,
|
||||
* rpc handler
|
||||
* state-data handler, ie non-config data
|
||||
* example_backend_secondary.c Secondary backend plugin. Plugins are loaded alphabetically.
|
||||
* example_restconf.c Restconf callback plugin containing an HTTP basic authentication callback
|
||||
* example_netconf.c Netconf callback plugin
|
||||
* Makefile.in Example makefile where plugins are built and installed
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ transaction_commit(clicon_handle h,
|
|||
int i;
|
||||
size_t len;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
/* Get all added i/fs */
|
||||
if (xpath_vec_flag(target, "//interface", XML_FLAG_ADD, &vec, &len) < 0)
|
||||
return -1;
|
||||
|
|
@ -191,39 +192,6 @@ plugin_statedata(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Plugin initialization. Create rpc callbacks
|
||||
* plugin_init is called as soon as the plugin has been loaded and is
|
||||
* assumed initialize the plugin's internal state if any as well as register
|
||||
* any callbacks, configuration dependencies.
|
||||
*/
|
||||
int
|
||||
plugin_init(clicon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
if (notification_timer_setup(h) < 0)
|
||||
goto done;
|
||||
/* Register callback for routing rpc calls */
|
||||
if (backend_rpc_cb_register(h, fib_route,
|
||||
NULL,
|
||||
"fib-route"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
if (backend_rpc_cb_register(h, route_count,
|
||||
NULL,
|
||||
"route-count"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
if (backend_rpc_cb_register(h, empty,
|
||||
NULL,
|
||||
"empty"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Plugin state reset. Add xml or set state in backend machine.
|
||||
* Called in each backend plugin. plugin_reset is called after all plugins
|
||||
* have been initialized. This give the application a chance to reset
|
||||
|
|
@ -279,3 +247,54 @@ plugin_start(clicon_handle h,
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static clixon_plugin_api api = {
|
||||
"example", /* name */
|
||||
clixon_plugin_init, /* init */
|
||||
plugin_start, /* start */
|
||||
NULL, /* exit */
|
||||
NULL, /* auth */
|
||||
plugin_reset, /* reset */
|
||||
plugin_statedata, /* statedata */
|
||||
NULL, /* trans begin */
|
||||
transaction_validate,/* trans validate */
|
||||
NULL, /* trans complete */
|
||||
transaction_commit, /* trans commit */
|
||||
NULL, /* trans end */
|
||||
NULL /* trans abort */
|
||||
};
|
||||
|
||||
/*! Backend plugin initialization
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
clicon_debug(1, "%s backend", __FUNCTION__);
|
||||
if (notification_timer_setup(h) < 0)
|
||||
goto done;
|
||||
/* Register callback for routing rpc calls */
|
||||
if (backend_rpc_cb_register(h, fib_route,
|
||||
NULL,
|
||||
"fib-route"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
if (backend_rpc_cb_register(h, route_count,
|
||||
NULL,
|
||||
"route-count"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
if (backend_rpc_cb_register(h, empty,
|
||||
NULL,
|
||||
"empty"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
return &api;
|
||||
done:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
102
example/example_backend_secondary.c
Normal file
102
example/example_backend_secondary.c
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2018 Olof Hagsand and Benny Holmgren
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of
|
||||
the GNU General Public License Version 3 or later (the "GPL"),
|
||||
in which case the provisions of the GPL are applicable instead
|
||||
of those above. If you wish to allow use of your version of this file only
|
||||
under the terms of the GPL, and not to allow others to
|
||||
use your version of this file under the terms of Apache License version 2, indicate
|
||||
your decision by deleting the provisions above and replace them with the
|
||||
notice and other provisions required by the GPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the Apache License version 2 or the GPL.
|
||||
|
||||
***** END LICENSE BLOCK *****
|
||||
|
||||
*
|
||||
* IETF yang routing example
|
||||
* Secondary backend for testing more than one backend plugin
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* clicon */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* Clicon library functions. */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
/* These include signatures for plugin and transaction callbacks. */
|
||||
#include <clixon/clixon_backend.h>
|
||||
|
||||
|
||||
int
|
||||
transaction_commit_2(clicon_handle h,
|
||||
transaction_data td)
|
||||
{
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
plugin_start_2(clicon_handle h,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static clixon_plugin_api api = {
|
||||
"secondary", /* name */
|
||||
clixon_plugin_init, /* init */
|
||||
plugin_start_2, /* start */
|
||||
NULL, /* exit */
|
||||
NULL, /* auth */
|
||||
NULL, /* reset */
|
||||
NULL, /* statedata */
|
||||
NULL, /* trans begin */
|
||||
NULL, /* trans validate */
|
||||
NULL, /* trans complete */
|
||||
transaction_commit_2,/* trans commit */
|
||||
NULL, /* trans end */
|
||||
NULL /* trans abort */
|
||||
};
|
||||
|
||||
/*! Backend plugin initialization
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
clicon_debug(1, "%s backend secondary", __FUNCTION__);
|
||||
return &api;
|
||||
}
|
||||
|
|
@ -64,19 +64,23 @@ plugin_exit(clicon_handle h)
|
|||
|
||||
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static const struct clixon_plugin_api api = {
|
||||
"example",
|
||||
clixon_plugin_init,
|
||||
plugin_start,
|
||||
plugin_exit,
|
||||
NULL
|
||||
static struct clixon_plugin_api api = {
|
||||
"example", /* name */
|
||||
clixon_plugin_init, /* init */
|
||||
plugin_start, /* start */
|
||||
plugin_exit, /* exit */
|
||||
NULL /* auth */
|
||||
};
|
||||
|
||||
/*! Netconf plugin initialization
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
return (void*)&api;
|
||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||
return &api;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -269,19 +269,22 @@ plugin_credentials(clicon_handle h,
|
|||
|
||||
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static const struct clixon_plugin_api api = {
|
||||
"example",
|
||||
clixon_plugin_init,
|
||||
NULL,
|
||||
NULL,
|
||||
plugin_credentials,
|
||||
static clixon_plugin_api api = {
|
||||
"example", /* name */
|
||||
clixon_plugin_init, /* init */
|
||||
NULL, /* start */
|
||||
NULL, /* exit */
|
||||
plugin_credentials /* auth */
|
||||
};
|
||||
|
||||
/*! Restconf plugin initialization
|
||||
* @param[in] h Clixon handle
|
||||
* @retval NULL Error with clicon_err set
|
||||
* @retval api Pointer to API struct
|
||||
*/
|
||||
clixon_plugin_api *
|
||||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||
return (void*)&api;
|
||||
return &api;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue