Kea: netconf_process.cc Source File

| Kea 2.2.0

netconf_process.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2021 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>
8
9#include <asiolink/asio_wrapper.h>
10#include <netconf/netconf.h>
11#include <netconf/netconf_process.h>
12#include <netconf/netconf_controller.h>
13#include <netconf/netconf_log.h>
14#include <asiolink/io_address.h>
15#include <asiolink/io_error.h>
16#include <cc/command_interpreter.h>
17#include <config/timeouts.h>
18
19#include <boost/pointer_cast.hpp>
20
21using namespace isc::asiolink;
22using namespace isc::config;
23using namespace isc::data;
24using namespace isc::http;
25using namespace isc::process;
26
27namespace isc {
28namespace netconf {
29
30NetconfProcess::NetconfProcess(const char* name,
31 const asiolink::IOServicePtr& io_service)
32 : DProcessBase(name, io_service, DCfgMgrBasePtr(new NetconfCfgMgr())) {
33}
34
35void
36NetconfProcess::init() {
37}
38
39void
40NetconfProcess::run() {
41 LOG_INFO(netconf_logger, NETCONF_STARTED).arg(VERSION);
42
43 try {
44 // Call init.
45 agent_.init(getNetconfCfgMgr());
46
47 // Let's process incoming data or expiring timers in a loop until
48 // shutdown condition is detected.
49 while (!shouldShutdown()) {
50 runIO();
51 }
52 stopIOService();
53
54 } catch (const std::exception& ex) {
55 LOG_FATAL(netconf_logger, NETCONF_FAILED).arg(ex.what());
56 try {
57 stopIOService();
58 } catch (...) {
59 // Ignore double errors
60 }
61 isc_throw(DProcessBaseError,
62 "Process run method failed: " << ex.what());
63 }
64
65 LOG_DEBUG(netconf_logger, isc::log::DBGLVL_START_SHUT, NETCONF_RUN_EXIT);
66}
67
68size_t
69NetconfProcess::runIO() {
70 size_t cnt = getIoService()->get_io_service().poll();
71 if (!cnt) {
72 cnt = getIoService()->get_io_service().run_one();
73 }
74 return (cnt);
75}
76
77 isc::data::ConstElementPtr
78NetconfProcess::shutdown(isc::data::ConstElementPtr /*args*/) {
79 setShutdownFlag(true);
80 return (isc::config::createAnswer(0, "Netconf is shutting down"));
81}
82
83 isc::data::ConstElementPtr
84NetconfProcess::configure(isc::data::ConstElementPtr config_set,
85 bool check_only) {
86 ConstElementPtr answer =
87 getCfgMgr()->simpleParseConfig(config_set, check_only);
88 int rcode = 0;
89 config::parseAnswer(rcode, answer);
90 return (answer);
91}
92
93 NetconfCfgMgrPtr
94NetconfProcess::getNetconfCfgMgr() {
95 return (boost::dynamic_pointer_cast<NetconfCfgMgr>(getCfgMgr()));
96}
97
98} // namespace isc::netconf
99} // namespace isc
asio_wrapper.h
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::netconf::NetconfAgent::init
void init(NetconfCfgMgrPtr cfg_mgr)
Initialization.
Definition: netconf.cc:155
isc::netconf::NetconfCfgMgr
Ctrl Netconf Configuration Manager.
Definition: netconf_cfg_mgr.h:124
isc::netconf::NetconfProcess::getNetconfCfgMgr
NetconfCfgMgrPtr getNetconfCfgMgr()
Returns a pointer to the configuration manager.
Definition: netconf_process.cc:94
isc::netconf::NetconfProcess::run
virtual void run()
Implements the process's event loop.
Definition: netconf_process.cc:40
isc::netconf::NetconfProcess::init
virtual void init()
Initialize the Netconf process.
Definition: netconf_process.cc:36
isc::netconf::NetconfProcess::NetconfProcess
NetconfProcess(const char *name, const asiolink::IOServicePtr &io_service)
Constructor.
Definition: netconf_process.cc:30
isc::netconf::NetconfProcess::configure
virtual isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false)
Processes the given configuration.
Definition: netconf_process.cc:84
isc::netconf::NetconfProcess::shutdown
virtual isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args)
Initiates the process's shutdown process.
Definition: netconf_process.cc:78
isc::process::DProcessBaseError
Exception thrown if the process encountered an operational error.
Definition: d_process.h:24
isc::process::DProcessBase
Application Process Interface.
Definition: d_process.h:81
isc::process::DProcessBase::setShutdownFlag
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:166
isc::process::DProcessBase::stopIOService
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:188
isc::process::DProcessBase::getIoService
asiolink::IOServicePtr & getIoService()
Fetches the controller's IOService.
Definition: d_process.h:180
isc::process::DProcessBase::shouldShutdown
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:159
isc::process::DProcessBase::getCfgMgr
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition: d_process.h:195
command_interpreter.h
This file contains several functions and constants that are used for handling commands and responses ...
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:210
io_address.h
io_error.h
LOG_INFO
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
LOG_FATAL
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Definition: macros.h:38
LOG_DEBUG
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition: macros.h:14
isc::asiolink
Definition: addr_utilities.cc:170
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition: io_service.h:110
isc::config
Definition: command_interpreter.cc:23
isc::config::createAnswer
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
Definition: command_interpreter.cc:34
isc::config::parseAnswer
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Definition: command_interpreter.cc:69
isc::data
Definition: base_stamped_element.cc:12
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
isc::http
Definition: auth_config.h:19
isc::log::DBGLVL_START_SHUT
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::netconf::NETCONF_FAILED
const isc::log::MessageID NETCONF_FAILED
Definition: netconf_messages.h:17
isc::netconf::netconf_logger
isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME)
Base logger for the netconf agent.
Definition: netconf_log.h:49
isc::netconf::NETCONF_STARTED
const isc::log::MessageID NETCONF_STARTED
Definition: netconf_messages.h:31
isc::netconf::NetconfCfgMgrPtr
boost::shared_ptr< NetconfCfgMgr > NetconfCfgMgrPtr
Defines a shared pointer to NetconfCfgMgr.
Definition: netconf_cfg_mgr.h:181
isc::netconf::NETCONF_RUN_EXIT
const isc::log::MessageID NETCONF_RUN_EXIT
Definition: netconf_messages.h:27
isc::process
Definition: cb_ctl_base.h:20
isc::process::DCfgMgrBasePtr
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:247
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
netconf.h
netconf_controller.h
netconf_log.h
Contains declarations for loggers used by the Kea netconf agent.
netconf_process.h
timeouts.h