From: Tomek Mrugalski Date: Fri, 10 Aug 2018 17:03:13 +0000 (+0200) Subject: [gitlab3] Implemented bare skeleton for kea-netconf X-Git-Tag: gitlab29-base~13 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=3aae164d4d3961cf9ea98a109977f313be5c6cdf;p=thirdparty%2Fkea.git [gitlab3] Implemented bare skeleton for kea-netconf --- diff --git a/src/bin/netconf/Makefile.am b/src/bin/netconf/Makefile.am index 84189b3fb3..e45829389e 100644 --- a/src/bin/netconf/Makefile.am +++ b/src/bin/netconf/Makefile.am @@ -46,9 +46,7 @@ BUILT_SOURCES = netconf_messages.h netconf_messages.cc noinst_LTLIBRARIES = libnetconf.la -libnetconf_la_SOURCES = agent.cc agent.h -libnetconf_la_SOURCES += translator.cc translator.h -libnetconf_la_SOURCES += netconf_log.cc netconf_log.h +libnetconf_la_SOURCES = netconf_log.cc netconf_log.h nodist_libnetconf_la_SOURCES = netconf_messages.h netconf_messages.cc @@ -59,21 +57,21 @@ 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/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/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/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) $(SYSREPO_LIBS) diff --git a/src/bin/netconf/agent.cc b/src/bin/netconf/agent.cc deleted file mode 100644 index 70f6e4db78..0000000000 --- a/src/bin/netconf/agent.cc +++ /dev/null @@ -1,62 +0,0 @@ -// 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 deleted file mode 100644 index 92d3417237..0000000000 --- a/src/bin/netconf/agent.h +++ /dev/null @@ -1,47 +0,0 @@ -// 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/main.cc b/src/bin/netconf/main.cc index 623859075c..515651be0e 100644 --- a/src/bin/netconf/main.cc +++ b/src/bin/netconf/main.cc @@ -6,42 +6,47 @@ #include -#include #include -#include #include +#include #include -int main( +#include - /// @brief Prints Kea Usage and exits +using namespace std; +using namespace isc; +using namespace isc::netconf; + +/// @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; + cerr << "Kea netconf daemon, version " << VERSION << endl + << endl + << "Usage: " << endl + << " -c: config-file" << endl + << " -d: debug mode (maximum verbosity)" << endl + << " -v: print version number and exit" << endl + << " -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(""); + int ch; while ((ch = getopt(argc, argv, "vVc:")) != -1) { switch (ch) { case 'v': - cout << Dhcpv4Srv::getVersion(false) << endl; + cout << string(PACKAGE_VERSION) << endl; return (EXIT_SUCCESS); case 'V': - cout << Dhcpv4Srv::getVersion(true) << endl; + cout << string(PACKAGE_VERSION) << endl; + cout << "git " << EXTENDED_VERSION << endl; return (EXIT_SUCCESS); case 'c': // config file @@ -63,51 +68,36 @@ main(int argc, char* argv[]) { 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); + //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); - } + isc::dhcp::Daemon::loggerInit(NETCONF_LOGGER_NAME, verbose_mode); + LOG_INFO(netconf_logger, NETCONF_STARTING).arg(VERSION).arg(getpid()); + Connection conn("kea-netconf"); + // Tell the admin we are ready to process packets - LOG_INFO(netconf_logger, NETCONF_AGENT_STATED).arg(VERSION); + LOG_INFO(netconf_logger, NETCONF_STATED).arg(VERSION); // And run the main loop of the server. - agent.run(); + while (true) { + cout << "Dummy kea-netconf running. Press ctrl-c to terminate." + << endl; + sleep(1); + } LOG_INFO(netconf_logger, NETCONF_SHUTDOWN); - } catch (const isc::exception& ex) { + } catch (const isc::Exception& ex) { // First, we parint the error on stderr (that should always work) - cerr "ERROR:" << ex.what() << endl; - + cerr << "ERROR:" << ex.what() << endl; + ret = EXIT_FAILURE; } return (ret); diff --git a/src/bin/netconf/netconf_log.cc b/src/bin/netconf/netconf_log.cc new file mode 100644 index 0000000000..f4b9f497b9 --- /dev/null +++ b/src/bin/netconf/netconf_log.cc @@ -0,0 +1,23 @@ +// 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/. + +/// @file netconf_log.cc +/// Contains the loggers used by the netconf agent. + +#include + +#include + +namespace isc { +namespace netconf { + +const char* NETCONF_LOGGER_NAME = "netconf"; + +isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME); + +} // namespace netconf +} // namespace isc + diff --git a/src/bin/netconf/netconf_log.h b/src/bin/netconf/netconf_log.h new file mode 100644 index 0000000000..5758a51b8c --- /dev/null +++ b/src/bin/netconf/netconf_log.h @@ -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/. + +/// @file netconf_log.h +/// Contains declarations for loggers used by the Kea netconf agent. + +#ifndef NETCONF_LOG_H +#define NETCONF_LOG_H + +#include +#include +#include + +namespace isc { +namespace netconf { + +/// @brief Defines the name of the root level (default) logger. +extern const char* NETCONF_LOGGER_NAME; + +/// @brief Base logger for the netconf agent +extern isc::log::Logger netconf_logger; + +} // namespace netconf +} // namespace isc + +#endif // NETCONF_LOG_H diff --git a/src/bin/netconf/netconf_messages.mes b/src/bin/netconf/netconf_messages.mes new file mode 100644 index 0000000000..d7ef00d6d1 --- /dev/null +++ b/src/bin/netconf/netconf_messages.mes @@ -0,0 +1,19 @@ +# Copyright (C) 2012-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/. + +$NAMESPACE isc::netconf + +% NETCONF_STARTING Kea-netconf agent (version %1) is starting with process-id %2 +Describe it later. + +% NETCONF_STATED Kea-netconf agent (version %1) started +Describe it later. + +% NETCONF_SHUTDOWN Kea-netconf agent shutting down. +Describe it later. + +% NETCONF_EXCEPTION Exception encountered: %1 +Oops.