Kea 1.5.0
netconf_process.cc
Go to the documentation of this file.
1// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
9#include <netconf/netconf.h>
12#include <netconf/netconf_log.h>
13#include <asiolink/io_address.h>
14#include <asiolink/io_error.h>
16#include <config/timeouts.h>
17#include <util/threads/thread.h>
18#include <boost/pointer_cast.hpp>
19
20using namespace isc::asiolink;
21using namespace isc::config;
22using namespace isc::data;
23using namespace isc::http;
24using namespace isc::process;
25using namespace isc::util::thread;
26
27namespace isc {
28namespace netconf {
29
30bool NetconfProcess::shut_down = false;
31
33 const asiolink::IOServicePtr& io_service)
34 : DProcessBase(name, io_service, DCfgMgrBasePtr(new NetconfCfgMgr())) {
35}
36
38}
39
40void
42}
43
44void
46 LOG_INFO(netconf_logger, NETCONF_STARTED).arg(VERSION);
47
48 try {
49 // Initialize netconf agent in a thread.
50 Thread th([this]() {
51 if (shouldShutdown()) {
52 return;
53 }
54 // Initialize sysrepo.
55 agent_.initSysrepo();
56 if (shouldShutdown()) {
57 return;
58 }
59
60 // Get the configuration manager.
61 NetconfCfgMgrPtr cfg_mgr;
62 if (shouldShutdown()) {
63 return;
64 } else {
65 cfg_mgr = getNetconfCfgMgr();
66 }
67
68 // Call init.
69 agent_.init(cfg_mgr);
70 });
71
72 // Let's process incoming data or expiring timers in a loop until
73 // shutdown condition is detected.
74 while (!shouldShutdown()) {
75 runIO();
76 }
78 } catch (const std::exception& ex) {
79 LOG_FATAL(netconf_logger, NETCONF_FAILED).arg(ex.what());
80 try {
82 } catch (...) {
83 // Ignore double errors
84 }
86 "Process run method failed: " << ex.what());
87 }
88
90}
91
92size_t
93NetconfProcess::runIO() {
94 size_t cnt = getIoService()->get_io_service().poll();
95 if (!cnt) {
96 cnt = getIoService()->get_io_service().run_one();
97 }
98 return (cnt);
99}
100
103 shut_down = true;
104 setShutdownFlag(true);
105 return (isc::config::createAnswer(0, "Netconf is shutting down"));
106}
107
110 bool check_only) {
111 ConstElementPtr answer =
112 getCfgMgr()->simpleParseConfig(config_set, check_only);
113 int rcode = 0;
114 config::parseAnswer(rcode, answer);
115 return (answer);
116}
117
120 return (boost::dynamic_pointer_cast<NetconfCfgMgr>(getCfgMgr()));
121}
122
123} // namespace isc::netconf
124} // namespace isc
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void initSysrepo()
Initialize sysrepo sessions.
Definition: netconf.cc:278
void init(NetconfCfgMgrPtr cfg_mgr)
Initialization.
Definition: netconf.cc:136
Ctrl Netconf Configuration Manager.
virtual ~NetconfProcess()
Destructor.
NetconfCfgMgrPtr getNetconfCfgMgr()
Returns a pointer to the configuration manager.
virtual void run()
Implements the process's event loop.
static bool shut_down
Global (globally visible) shutdown flag.
virtual void init()
Initialize the Netconf process.
NetconfProcess(const char *name, const asiolink::IOServicePtr &io_service)
Constructor.
virtual isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false)
Processes the given configuration.
virtual isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args)
Initiates the process's shutdown process.
Exception thrown if the process encountered an operational error.
Definition: d_process.h:22
Application Process Interface.
Definition: d_process.h:67
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:152
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:174
asiolink::IOServicePtr & getIoService()
Fetches the controller's IOService.
Definition: d_process.h:166
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:145
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition: d_process.h:181
A separate thread.
Definition: thread.h:36
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Definition: macros.h:38
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition: macros.h:14
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
const int DBGLVL_START_SHUT
This is given a value of 0 as that is the level selected if debugging is enabled without giving a lev...
Definition: log_dbglevels.h:50
isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME)
Base logger for the netconf agent.
Definition: netconf_log.h:49
boost::shared_ptr< NetconfCfgMgr > NetconfCfgMgrPtr
Defines a shared pointer to NetconfCfgMgr.
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:219
Wrappers for thread related functionality.
Definition: sync.cc:24
Defines the logger used by the top-level component of kea-dhcp-ddns.
Contains declarations for loggers used by the Kea netconf agent.