]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[gitlab3] Implemented bare skeleton for kea-netconf
authorTomek Mrugalski <tomasz@isc.org>
Fri, 10 Aug 2018 17:03:13 +0000 (19:03 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 21 Aug 2018 10:18:56 +0000 (12:18 +0200)
src/bin/netconf/Makefile.am
src/bin/netconf/agent.cc [deleted file]
src/bin/netconf/agent.h [deleted file]
src/bin/netconf/main.cc
src/bin/netconf/netconf_log.cc [new file with mode: 0644]
src/bin/netconf/netconf_log.h [new file with mode: 0644]
src/bin/netconf/netconf_messages.mes [new file with mode: 0644]

index 84189b3fb3543d34c093852bdcc5b40b305e5cbb..e45829389e7e3f8a37a0e985e8bba1a8a97af020 100644 (file)
@@ -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 (file)
index 70f6e4d..0000000
+++ /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 <config.h>
-#include <netconf/agent.h>
-
-
-
-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 (file)
index 92d3417..0000000
+++ /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 <dhcpsrv/daemon.h>
-#include <asiolink/asio_wrapper.h>
-#include <asiolink/asiolink.h>
-
-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
-
index 623859075ce5e48b46f47128069db71b9762af80..515651be0e436241f8e8d83402d1dd5300b41a91 100644 (file)
@@ -6,42 +6,47 @@
 
 #include <config.h>
 
-#include <netconf/agent.h>
 #include <netconf/netconf_log.h>
-#include <dhcpsrv/cfgmgr.h>
 #include <exceptions/exceptions.h>
+#include <dhcpsrv/daemon.h>
 #include <iostream>
 
-int main(
+#include <sysrepo-cpp/Session.h>
 
-         /// @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 (file)
index 0000000..f4b9f49
--- /dev/null
@@ -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 <config.h>
+
+#include <netconf/netconf_log.h>
+
+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 (file)
index 0000000..5758a51
--- /dev/null
@@ -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 <log/logger_support.h>
+#include <log/macros.h>
+#include <netconf/netconf_messages.h>
+
+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 (file)
index 0000000..d7ef00d
--- /dev/null
@@ -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.