Commit 888121a1 authored by Francis Dupont's avatar Francis Dupont

[153-netconf-agent] Added netconf agent code from kea-yang

parent b9fe00fc
......@@ -48,6 +48,7 @@ libnetconf_la_SOURCES = control_socket.cc control_socket.h
libnetconf_la_SOURCES += http_control_socket.cc http_control_socket.h
libnetconf_la_SOURCES += stdout_control_socket.cc stdout_control_socket.h
libnetconf_la_SOURCES += unix_control_socket.cc unix_control_socket.h
libnetconf_la_SOURCES += netconf.cc netconf.h
libnetconf_la_SOURCES += netconf_cfg_mgr.cc netconf_cfg_mgr.h
libnetconf_la_SOURCES += netconf_config.cc netconf_config.h
libnetconf_la_SOURCES += netconf_controller.cc netconf_controller.h
......
This diff is collapsed.
// 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.h
#ifndef NETCONF_H
#define NETCONF_H
#include <netconf/netconf_cfg_mgr.h>
#include <netconf/control_socket.h>
#include <netconf/http_control_socket.h>
#include <netconf/stdout_control_socket.h>
#include <netconf/unix_control_socket.h>
#include <sysrepo-cpp/Session.h>
#include <map>
namespace isc {
namespace netconf {
/// @brief Forward declaration to the @c NetconfAgent.
class NetconfAgent;
/// @brief Type definition for the pointer to the @c NetconfAgent.
typedef boost::shared_ptr<NetconfAgent> NetconfAgentPtr;
/// @brief Netconf agent.
///
/// Service performed by the Netconf agent:
/// - at boot get and display Kea server configurations.
/// - load Kea server configurations from YANG datastore.
/// - validate YANG datastore changes using Kea configuration test.
/// - load updated Kea server configurations from YANG datastore.
/// - on shutdown close subscriptions.
class NetconfAgent {
public:
/// @brief Constructor.
NetconfAgent();
/// @brief Destructor (call clear).
virtual ~NetconfAgent();
/// @brief Initialize sysrepo sessions.
///
/// Must be called before init.
void initSysrepo();
/// @brief Initialization.
///
/// Get and display Kea server configurations.
/// Load Kea server configurations from YANG datastore.
/// Subscribe changes in YANG datastore.
///
/// @param cfg_mgr The configuration manager.
void init(NetconfCfgMgrPtr cfg_mgr);
/// @brief Clear.
///
/// Close subscriptions and sysrepo.
void clear();
/// @brief Validate.
///
/// Validate YANG datastore changes using Kea configuration test.
///
/// @param sess The sysrepo running datastore session.
/// @param service_pair The service name and configuration pair.
/// @return return code for sysrepo.
static int validate(S_Session sess, const CfgServersMapPair& service_pair);
/// @brief Update.
///
/// Update a Kea configuration from YANG datastore changes.
///
/// @param sess The sysrepo running datastore session.
/// @param service_pair The service name and configuration pair.
/// @return return code for sysrepo.
static int update(S_Session sess, const CfgServersMapPair& service_pair);
/// @brief Print changes.
///
/// @param sess The sysrepo running datastore session.
/// @param model The model name.
static void logChanges(S_Session sess, const std::string& model);
/// @brief Cancel flag.
bool cancel_;
protected:
/// @brief Get and display Kea server configuration.
///
/// @param service_pair The service name and configuration pair.
void keaConfig(const CfgServersMapPair& service_pair);
/// @brief Kea server configuration from YANG datastore.
///
/// @param service_pair The service name and configuration pair.
void yangConfig(const CfgServersMapPair& service_pair);
/// @brief Subscribe changes for a module in YANG datastore.
///
/// @param service_pair The service name and configuration pair.
void subscribe(const CfgServersMapPair& service_pair);
/// @brief Sysrepo connection.
S_Connection conn_;
/// @brief Sysrepo startup datastore session.
S_Session startup_sess_;
/// @brief Sysrepo running datastore session.
S_Session running_sess_;
/// @brief Subscription map.
std::map<const std::string, S_Subscribe> subscriptions_;
};
} // namespace netconf
} // namespace isc
#endif // NETCONF_H
......@@ -17,6 +17,31 @@
namespace isc {
namespace netconf {
///@{
/// \brief Netconf agent logging levels.
///
/// Defines the levels used to output debug messages in the Netconf agent.
/// Note that higher numbers equate to more verbose (and detailed) output.
/// @brief Traces normal operations.
///
/// E.g. sending a command to a server etc.
const int NETCONF_DBG_TRACE = isc::log::DBGLVL_TRACE_BASIC;
/// @brief Records the results of the commands.
///
/// Using the example of tracing commands to a server, this will just record
/// the summary results.
const int NETCONF_DBG_RESULTS = isc::log::DBGLVL_TRACE_BASIC_DATA;
/// @brief Additional information.
///
/// Record detailed tracing. This is generally reserved for tracing
/// configurations from or to a server.
const int NETCONF_DBG_TRACE_DETAIL_DATA = isc::log::DBGLVL_TRACE_DETAIL_DATA;
///@}
/// @brief Defines the name of the root level (default) logger.
extern const char* NETCONF_LOGGER_NAME;
......
......@@ -6,6 +6,15 @@
$NAMESPACE isc::netconf
% NETCONF_CONFIG_CHANGE_EVENT Received YANG configuration change %1 event
This informational message is issued when Netconf receives an YANG
configuration change even.t. The type of event is printed.
% NETCONF_CONFIG_CHANGED_DETAIL YANG configuration changed: %1
This debug message indicates a YANG configuration change. The format
is the change operation (created, modified, deleted or moved) followed
by xpaths and values of old and new nodes.
% NETCONF_CONFIG_CHECK_FAIL Netconf configuration check failed: %1
This error message indicates that Netconf had failed configuration
check. Details are provided. Additional details may be available
......@@ -18,13 +27,81 @@ in earlier log entries, possibly on lower levels.
% NETCONF_FAILED application experienced a fatal error: %1
This is a fatal error message issued when the Netconf application
encounters an unrecoverable error from within the event loop.
got an unrecoverable error from within the event loop.
% NETCONF_GET_CONFIG getting configuration from %1 server
This debug message indicates that Netconf is trying to get the
configuration from a Kea server.
% NETCONF_GET_CONFIG_CONFIG got configuration from %1 server: %2
This debug message indicates that Netconf got the configuration from a
Kea server. The server name and the retrieved configuration are printed.
% NETCONF_GET_CONFIG_FAILED getting configuration from %1 server failed: %2
The error message indicates that Netconf got an error getting the
configuration from a Kea server. The name of the server and the error
are printed.
% NETCONF_LOG_CHANGE_FAIL Netconf configuration change logging failed: %1
The warning message indicates that the configuration change logging
encountered a not expected condition.
% NETCONF_RUN_EXIT application is exiting the event loop
This is a debug message issued when the Netconf application exits its
event loop.
% NETCONF_SET_CONFIG setting configuration to %1 server
This debug message indicates that Netconf is trying to set the
configuration to a Kea server.
% NETCONF_SET_CONFIG_CONFIG set configuration to %1 server: %2
This debug message indicates that Netconf set the configuration to a
Kea server. The server name and the applied configuration are printed.
% NETCONF_SET_CONFIG_FAILED setting configuration to %1 server: %2
The error message indicates that Netconf got an error setting the
configuration to a Kea server. The name of the server and the error
are printed.
% NETCONF_STARTED Netconf (version %1) started
This informational message indicates that Netconf has processed
all configuration information and is ready to begin processing.
The version is also printed.
% NETCONF_SUBSCRIBE subscribing configuration changes for %1 server with %2 module
This debug message indicates that Netconf is trying to subscribe
configuration changes for a Kea server. The names of the server and
the module are printed.
% NETCONF_SUBSCRIBE_FAILED subscribe configuration changes for %1 server with %2 module failed: %3
The error message indicates that Netconf got an error subscribing
configuration changes for a Kea server. The names of the server and
the module, and the error are printed.
% NETCONF_VALIDATE_CONFIG validating configuration for %1 server
This debug message indicates that Netconf is trying to validate the
configuration with a Kea server.
% NETCONF_VALIDATE_CONFIG_CONFIG validate configuration with %1 server: %2
This debug message indicates that Netconf validate the configuration
with a Kea server. The server name and the validated configuration are
printed.
% NETCONF_VALIDATE_CONFIG_FAILED validating configuration with %1 server: %2
The error message indicates that Netconf got an error validating the
configuration with a Kea server. The name of the server and the error
are printed.
% NETCONF_UPDATE_CONFIG updating configuration for %1 server
This debug message indicates that Netconf is trying to update the
configuration of a Kea server.
% NETCONF_UPDATE_CONFIG_CONFIG update configuration with %1 server: %2
This debug message indicates that Netconf update the configuration
of a Kea server. The server name and the updated configuration are
printed.
% NETCONF_UPDATE_CONFIG_FAILED updating configuration with %1 server: %2
The error message indicates that Netconf got an error updating the
configuration of a Kea server. The name of the server and the error
are printed.
......@@ -6,6 +6,7 @@
#include <config.h>
#include <asiolink/asio_wrapper.h>
#include <netconf/netconf.h>
#include <netconf/netconf_process.h>
#include <netconf/netconf_controller.h>
#include <netconf/netconf_log.h>
......@@ -13,6 +14,7 @@
#include <asiolink/io_error.h>
#include <cc/command_interpreter.h>
#include <config/timeouts.h>
#include <util/threads/thread.h>
#include <boost/pointer_cast.hpp>
using namespace isc::asiolink;
......@@ -20,11 +22,13 @@ using namespace isc::config;
using namespace isc::data;
using namespace isc::http;
using namespace isc::process;
using namespace isc::util::thread;
namespace isc {
namespace netconf {
bool NetconfProcess::global_shut_down_flag = false;
NetconfProcess::NetconfProcess(const char* name,
const asiolink::IOServicePtr& io_service)
: DProcessBase(name, io_service, DCfgMgrBasePtr(new NetconfCfgMgr())) {
......@@ -42,6 +46,12 @@ NetconfProcess::run() {
LOG_INFO(netconf_logger, NETCONF_STARTED).arg(VERSION);
try {
// Initialize sysrepo.
agent_.initSysrepo();
// Initialize netconf agent in a thread.
Thread th([this]() { agent_.init(getNetconfCfgMgr()); });
// Let's process incoming data or expiring timers in a loop until
// shutdown condition is detected.
while (!shouldShutdown()) {
......@@ -73,6 +83,7 @@ NetconfProcess::runIO() {
isc::data::ConstElementPtr
NetconfProcess::shutdown(isc::data::ConstElementPtr /*args*/) {
global_shut_down_flag = true;
setShutdownFlag(true);
return (isc::config::createAnswer(0, "Netconf is shutting down"));
}
......
......@@ -7,8 +7,7 @@
#ifndef NETCONF_PROCESS_H
#define NETCONF_PROCESS_H
#include <netconf/netconf_cfg_mgr.h>
#include <http/listener.h>
#include <netconf/netconf.h>
#include <process/d_process.h>
#include <vector>
......@@ -85,6 +84,9 @@ public:
/// @brief Returns a pointer to the configuration manager.
NetconfCfgMgrPtr getNetconfCfgMgr();
/// @brief Global (globally visible) shutdown flag.
static bool global_shut_down_flag;
private:
/// @brief Polls all ready handlers and then runs one handler if none
......@@ -92,6 +94,9 @@ private:
///
/// @return Number of executed handlers.
size_t runIO();
/// @brief Netconf agent.
NetconfAgent agent_;
};
/// @brief Defines a shared pointer to NetconfProcess.
......
......@@ -49,6 +49,7 @@ netconf_unittests_SOURCES += get_config_unittest.cc
netconf_unittests_SOURCES += netconf_cfg_mgr_unittests.cc
netconf_unittests_SOURCES += netconf_controller_unittests.cc
netconf_unittests_SOURCES += netconf_process_unittests.cc
netconf_unittests_SOURCES += netconf_unittests.cc
netconf_unittests_SOURCES += parser_unittests.cc
netconf_unittests_SOURCES += run_unittests.cc
......@@ -65,7 +66,7 @@ netconf_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.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/yang/testutils/libyangtest.la
netconf_unittests_LDADD += $(top_builddir)/src/lib/yang/testutils/libyangtest.la
netconf_unittests_LDADD += $(top_builddir)/src/lib/yang/libkea-yang.la
#netconf_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
netconf_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment