From: Tomek Mrugalski Date: Sat, 17 Mar 2018 15:05:06 +0000 (+0000) Subject: initial makefiles and some skeleton code for kea-netconf X-Git-Tag: gitlab29-base~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6abb5e174a374807dcfa5bca951dfd520dca5ab0;p=thirdparty%2Fkea.git initial makefiles and some skeleton code for kea-netconf --- diff --git a/configure.ac b/configure.ac index dfa0b66459..cfc5b3b9ff 100644 --- a/configure.ac +++ b/configure.ac @@ -1414,6 +1414,8 @@ AC_CONFIG_FILES([Makefile src/bin/keactrl/tests/keactrl_tests.sh src/bin/lfc/Makefile src/bin/lfc/tests/Makefile + src/bin/netconf/Makefile + src/bin/netconf/tests/Makefile src/bin/perfdhcp/Makefile src/bin/perfdhcp/tests/Makefile src/bin/perfdhcp/tests/testdata/Makefile diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 67bd58a5c4..5201690172 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -1,5 +1,5 @@ # The following build order must be maintained. -SUBDIRS = dhcp4 dhcp6 d2 agent perfdhcp admin lfc keactrl +SUBDIRS = dhcp4 dhcp6 netconf d2 agent perfdhcp admin lfc keactrl if KEA_SHELL SUBDIRS += shell diff --git a/src/bin/netconf/Makefile.am b/src/bin/netconf/Makefile.am new file mode 100644 index 0000000000..0cd10c7c53 --- /dev/null +++ b/src/bin/netconf/Makefile.am @@ -0,0 +1,108 @@ + +SUBDIRS = . tests + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin +AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src +AM_CPPFLAGS += $(BOOST_INCLUDES) $(NETCONF_INCLUDES) + +AM_CXXFLAGS = $(KEA_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +CLEANFILES = *.gcno *.gcda netconf_messages.h netconf_messages.cc s-messages + +man_MANS = kea-netconf.8 +DISTCLEANFILES = $(man_MANS) +EXTRA_DIST = $(man_MANS) kea-netconf.xml +#EXTRA_DIST += netconf.dox netconf_hooks.dox netconfo6.dox +#EXTRA_DIST += netconf_parser.yy + +if GENERATE_DOCS +kea-netconf.8: kea-netconf.xml + @XSLTPROC@ --novalid --xinclude --nonet -o $@ \ + http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl \ + $(srcdir)/kea-netconf.xml + +else + +$(man_MANS): + @echo Man generation disabled. Creating dummy $@. Configure with --enable-generate-docs to enable it. + @echo Man generation disabled. Remove this file, configure with --enable-generate-docs, and rebuild Kea > $@ + +endif + +netconf_messages.h netconf_messages.cc: s-messages + +s-messages: netconf_messages.mes + $(top_builddir)/src/lib/log/compiler/kea-msg-compiler $(top_srcdir)/src/bin/netconf/netconf_messages.mes + touch $@ + +BUILT_SOURCES = netconf_messages.h netconf_messages.cc + +# convenience archive + +noinst_LTLIBRARIES = libnetconf.la + +libnetconf_la_SOURCES = +libnetconf_la_SOURCES += agent.cc agent.h +libnetconf_la_SOURCES += translator.cc translator.h +libnetconf_la_SOURCES += netconf_log.cc netconf_log.h + +nodist_libnetconf_la_SOURCES = netconf_messages.h netconf_messages.cc +EXTRA_DIST += netconf_messages.mes + +sbin_PROGRAMS = kea-netconf + +kea_netconf_SOURCES = main.cc + +kea_netconf_LDADD = libnetconf.la +kea_netconf_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la +kea_netconf_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la +kea_netconf_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la +kea_netconf_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la +kea_netconf_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la +kea_netconf_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la +kea_netconf_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +kea_netconf_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +kea_netconf_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la +kea_netconf_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la +kea_netconf_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la +kea_netconf_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +kea_netconf_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +kea_netconf_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la +kea_netconf_LDADD += $(top_builddir)/src/lib/util/libkea-util.la +kea_netconf_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +kea_netconf_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS) $(BOOST_LIBS) + + +kea_netconfdir = $(pkgdatadir) + +if GENERATE_PARSER + +#parser: netconf_lexer.cc location.hh position.hh stack.hh netconf_parser.cc netconf_parser.h +# @echo "Flex/bison files regenerated" + +# --- Flex/Bison stuff below -------------------------------------------------- +# When debugging grammar issues, it's useful to add -v to bison parameters. +# bison will generate parser.output file that explains the whole grammar. +# It can be used to manually follow what's going on in the parser. +# This is especially useful if yydebug_ is set to 1 as that variable +# will cause parser to print out its internal state. +# Call flex with -s to check that the default rule can be suppressed +# Call bison with -W to get warnings like unmarked empty rules +# Note C++11 deprecated register still used by flex < 2.6.0 +location.hh position.hh stack.hh netconf_parser.cc netconf_parser.h: netconf_parser.yy + $(YACC) --defines=netconf_parser.h --report=all --report-file=netconf_parser.report -o netconf_parser.cc netconf_parser.yy + +netconf_lexer.cc: netconf_lexer.ll + $(LEX) --prefix netconf_ -o netconf_lexer.cc netconf_lexer.ll + +else + +parser location.hh position.hh stack.hh netconf_parser.cc netconf_parser.h netconf_lexer.cc: + @echo Parser generation disabled. Configure with --enable-generate-parser to enable it. + +endif diff --git a/src/bin/netconf/agent.cc b/src/bin/netconf/agent.cc new file mode 100644 index 0000000000..70f6e4db78 --- /dev/null +++ b/src/bin/netconf/agent.cc @@ -0,0 +1,62 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include +#include + + + +namespace isc { +namespace netconf { + +bool NetconfAgent::run() { + + // We need to establish connection to the sysrepo first. + if (!connectSysrepo()) { + return (false); + } + + // Second, we need to establish connection to Kea control socket. + if (!connectControlSocket()) { + return (false); + } + + while (!shutdown_) { + try { + run_one(); + io_service_->poll(); + } catch (const std::exception& e) { + // General catch-all exception that are not caught by more specific + // catches. This one is for exceptions derived from std::exception. + LOG_ERROR(netconf_logger, NETCONF_EXCEPTION) + .arg(e.what()); + } + } + + return (true); +} + +bool NetconfAgent::connectSysrepo() { + // Connect to sysrepo + + // Establish session + + // Register callbacks for event changes. + + + // Once implemented, change this to true. + return (false); +} + +bool NetconfAgent::connectControlSocket() { + // Establish connection to Kea control socket. + + // Once implemented, change this to true. + return (false); +} + +}; +}; diff --git a/src/bin/netconf/agent.h b/src/bin/netconf/agent.h new file mode 100644 index 0000000000..92d3417237 --- /dev/null +++ b/src/bin/netconf/agent.h @@ -0,0 +1,47 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef NETCONF_AGENT_H +#define NETCONF_AGENT_H + +#include +#include +#include + +namespace isc { +namespace netconf { + + class NetconfAgent : public isc::dhcp::Daemon { + public: + NetconfAgent() + :verbose_(false) { + + }; + + bool run(); + + void setVerbose(bool verbose) { + verbose_ = verbose; + } + + +private: + + bool connectSysrepo(); + + bool connectControlSocket(); + + /// @brief IOService object, used for all ASIO operations. + isc::asiolink::IOService io_service_; + +}; + +}; +}; + + +#endif + diff --git a/src/bin/netconf/kea-netconf.xml b/src/bin/netconf/kea-netconf.xml new file mode 100644 index 0000000000..6b3b33e30d --- /dev/null +++ b/src/bin/netconf/kea-netconf.xml @@ -0,0 +1,222 @@ + + + + + + ISC Kea + Oct. 27, 2017 + 1.3.0 + + The Kea software has been written by a number of + engineers working for ISC: Tomek Mrugalski, Stephen Morris, Marcin + Siodelski, Thomas Markwalder, Francis Dupont, Jeremy C. Reed, + Wlodek Wencel and Shawn Routhier. That list is roughly in the + chronological order in which the authors made their first + contribution. For a complete list of authors and + contributors, see AUTHORS file.Internet Systems Consortium, Inc. + + + + kea-netconf + 8 + Kea + + + + kea-dhcp4 + DHCPv4 server in Kea + + + + + 2011-2017 + Internet Systems Consortium, Inc. ("ISC") + + + + + + kea-dhcp4 + + + + + + + + + + + + DESCRIPTION + + The kea-dhcp4 daemon provides the + DHCPv4 server implementation. + + + + + + ARGUMENTS + + The arguments are as follows: + + + + + + + Display the version. + + + + + + + Display the extended version. + + + + + + + Display the configuration report. + + + + + + + Enable the debug mode with extra verbosity. + + + + + + + Configuration file including the configuration for DHCPv4 server. + It may also contain configuration entries for other Kea services. + + + + + + Check the configuration file + and report the first error if any. Note + that not all parameters are completely checked, in + particular, service and control channel sockets + are not opened, and hook libraries are not loaded. + + + + + + + Port number (1-65535) on which the server listens. This is useful + for testing purposes only. + + + + + + + + DOCUMENTATION + Kea comes with an extensive Kea User's Guide documentation + that covers all aspects of running the Kea software - + compilation, installation, configuration, configuration examples + and many more. Kea also features a Kea Messages Manual, which + lists all possible messages Kea can print with a brief + description for each of them. Both documents are typically + available in various formats (txt, html, pdf) with your Kea + distribution. The on-line version is available at + http://kea.isc.org/docs/. + + Kea source code is documented in the Kea Developer's Guide. It's + on-line version is available at http://kea.isc.org. Please + follow Developer's Guide link. + + + Kea project website is available at: http://kea.isc.org. + + + + + MAILING LISTS AND SUPPORT + + There are two mailing lists available for Kea project. kea-users + (kea-users at lists.isc.org) is intended for Kea users, while kea-dev + (kea-dev at lists.isc.org) is intended for Kea developers, prospective + contributors and other advanced users. Both lists are available at + http://lists.isc.org. The community provides best effort type of support + on both of those lists. + + + ISC provides professional support for Kea services. See + https://www.isc.org/kea/ for details. + + + + + HISTORY + + The b10-dhcp4 daemon was first coded in + November 2011 by Tomek Mrugalski. + + + In the mid 2014 Kea was decoupled from the BIND10 framework and became a + standalone DHCP server. The DHCPv4 server binary was renamed to + kea-dhcp4. Kea 1.0.0 was released in December 2015. + + + + + SEE ALSO + + + kea-dhcp6 + 8 + , + + + kea-dhcp-ddns + 8 + , + + + kea-ctrl-agent + 8 + , + + + kea-admin + 8 + , + + + keactrl + 8 + , + + + perfdhcp + 8 + , + + + kea-lfc + 8 + , + + Kea Administrator's Guide. + + + + + diff --git a/src/bin/netconf/main.cc b/src/bin/netconf/main.cc new file mode 100644 index 0000000000..ebc04c4f9d --- /dev/null +++ b/src/bin/netconf/main.cc @@ -0,0 +1,110 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include + +int main( + + /// @brief Prints Kea Usage and exits +/// +/// Note: This function never returns. It terminates the process. +void +usage() { + cerr << "Kea netconf daemon, version " << VERSION << endl; + cerr << endl; + cerr << "Usage: " << + << " -c: config-file" << endl; + cerr << " -v: print version number and exit" << endl; + cerr << " -V: print extended version and exit" << endl; + exit(EXIT_FAILURE); +} +} // end of anonymous namespace + +int +main(int argc, char* argv[]) { + // The standard config file + std::string config_file(""); + + while ((ch = getopt(argc, argv, "vVc:")) != -1) { + switch (ch) { + case 'v': + cout << Dhcpv4Srv::getVersion(false) << endl; + return (EXIT_SUCCESS); + + case 'V': + cout << Dhcpv4Srv::getVersion(true) << endl; + return (EXIT_SUCCESS); + + case 'c': // config file + config_file = optarg; + break; + default: + usage(); + } + } + + // Check for extraneous parameters. + if (argc > optind) { + usage(); + } + + // Configuration file is required. + if (config_file.empty()) { + cerr << "Configuration file not specified." << endl; + usage(); + } + + //CfgMgr::instance().setFamily(AF_INET); + + int ret = EXIT_SUCCESS; + try { + // It is important that we set a default logger name because this name + // will be used when the user doesn't provide the logging configuration + // in the Kea configuration file. + CfgMgr::instance().setDefaultLoggerName(KEA_NETCONF_LOGGER_NAME); + + // Initialize logging. If verbose, we'll use maximum verbosity. + bool verbose_mode = true; + Daemon::loggerInit(KEA_NETCONF_LOGGER_NAME, verbose_mode); + LOG_INFO(netconf_logger, NETCONF_AGENT_STARTING).arg(VERSION).arg(getpid()); + + // Create the server instance. + NetconfAgent agent; + + // Remember verbose-mode + agent.setVerbose(verbose_mode); + + // Create our PID file. + //server.setProcName(DHCP4_NAME); + //server.setConfigFile(config_file); + //server.createPIDFile(); + + try { + // Initialize the server. + server.init(config_file); + } catch (const std::exception& ex) { + cerr << "Failed to initialize server: " << ex.what() << endl; + return (EXIT_FAILURE); + } + + // Tell the admin we are ready to process packets + LOG_INFO(netconf_logger, NETCONF_AGENT_STATED).arg(VERSION); + + // And run the main loop of the server. + agent.run(); + + LOG_INFO(netconf_logger, NETCONF_SHUTDOWN); + + } catch (const isc::exception& ex) { + // First, we parint the error on stderr (that should always work) + cerr "ERROR:" << ex.what() << endl; + + } + + return (ret); +} diff --git a/src/bin/netconf/tests/Makefile.am b/src/bin/netconf/tests/Makefile.am new file mode 100644 index 0000000000..63ab0ca16f --- /dev/null +++ b/src/bin/netconf/tests/Makefile.am @@ -0,0 +1,65 @@ +SHTESTS = + +# test using command-line arguments, so use check-local target instead of TESTS +check-local: + for shtest in $(SHTESTS) ; do \ + echo Running test: $$shtest ; \ + export KEA_LOCKFILE_DIR=$(abs_top_builddir); \ + export KEA_PIDFILE_DIR=$(abs_top_builddir); \ + ${SHELL} $(abs_builddir)/$$shtest || exit ; \ + done + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src +AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin +AM_CPPFLAGS += $(BOOST_INCLUDES) + +CLEANFILES += *.json *.log + +AM_CXXFLAGS = $(KEA_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +TESTS_ENVIRONMENT = \ + $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND) + +TESTS = +if HAVE_GTEST + +TESTS += netconf_unittests + +netconf_unittests_SOURCES = netconf_unittest.cc + +netconf_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) +netconf_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) + + +netconf_unittests_LDADD = $(top_builddir)/src/bin/netconf/libnetconf.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcp/tests/libdhcptest.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la +#netconf_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +netconf_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +netconf_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la +netconf_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la +netconf_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +netconf_unittests_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS) +netconf_unittests_LDADD += $(BOOST_LIBS) $(GTEST_LDADD) +endif + +noinst_EXTRA_DIST = configs-list.txt + +noinst_PROGRAMS = $(TESTS) diff --git a/src/bin/netconf/tests/run_unittests.cc b/src/bin/netconf/tests/run_unittests.cc new file mode 100644 index 0000000000..172768f2e7 --- /dev/null +++ b/src/bin/netconf/tests/run_unittests.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include +#include +#include + +int +main(int argc, char* argv[]) { + + ::testing::InitGoogleTest(&argc, argv); + + // See the documentation of the KEA_* environment variables in + // src/lib/log/README for info on how to tweak logging + isc::log::initLogger(); + + setenv("KEA_PIDFILE_DIR", TEST_DATA_BUILDDIR, 1); + int result = RUN_ALL_TESTS(); + + return (result); +} diff --git a/src/bin/netconf/translator.cc b/src/bin/netconf/translator.cc new file mode 100644 index 0000000000..7e7bd41dbd --- /dev/null +++ b/src/bin/netconf/translator.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + +#include +#include + +namespace isc { +namespace netconf { + +Translator::Translator(const std::string& xpath) + :xpath_(xpath), netconf_data_(0) { + +}; + +std::string Translator::getXPath() { + return (xpath_); +} + +isc::data::ElementPtr Translator::getJSON() { + return (json_); +} + +}; +}; diff --git a/src/bin/netconf/translator.h b/src/bin/netconf/translator.h new file mode 100644 index 0000000000..754a6dad1f --- /dev/null +++ b/src/bin/netconf/translator.h @@ -0,0 +1,47 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include + +namespace isc { +namespace netconf { + +/// @brief This represents a base class for all translators +/// +/// Translator is an object that receives callback notification +/// from sysrepo (in YANG format) and converts it to appropriate +/// JSON that can be sent over control channel and understood by Kea +class Translator { + public: + // Constructor (requires xpath to install a callback) + Translator(const std::string& xpath); + + virtual std::string getXPath(); + + // This method will be called when the callback returns. + // Need to figure out the type used. + void setYangData(void* data); + + // This method translates Netconf data to JSON format + // understood by Kea. + void translate() = 0; + + // Once setYangData is called, + isc::data::ElementPtr getJSON(); + protected: + + std::string xpath_; + + void * netconf_data_; + + isc::data::ElementPtr json_; +}; + + +}; +};