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
10#include <netconf/netconf.h>
13#include <netconf/netconf_log.h>
14#include <asiolink/io_address.h>
15#include <asiolink/io_error.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
31 const asiolink::IOServicePtr& io_service)
32 : DProcessBase(name, io_service, DCfgMgrBasePtr(new NetconfCfgMgr())) {
33}
34
35void
37}
38
39void
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 }
53
54 } catch (const std::exception& ex) {
56 try {
58 } catch (...) {
59 // Ignore double errors
60 }
62 "Process run method failed: " << ex.what());
63 }
64
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
79 setShutdownFlag(true);
80 return (isc::config::createAnswer(0, "Netconf is shutting down"));
81}
82
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
95 return (boost::dynamic_pointer_cast<NetconfCfgMgr>(getCfgMgr()));
96}
97
98} // namespace isc::netconf
99} // namespace isc
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void init(NetconfCfgMgrPtr cfg_mgr)
Initialization.
Definition: netconf.cc:155
Ctrl Netconf Configuration Manager.
NetconfCfgMgrPtr getNetconfCfgMgr()
Returns a pointer to the configuration manager.
virtual void run()
Implements the process's event loop.
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:24
Application Process Interface.
Definition: d_process.h:81
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:166
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:188
asiolink::IOServicePtr & getIoService()
Fetches the controller's IOService.
Definition: d_process.h:180
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:159
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition: d_process.h:195
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(const int status_code, const std::string &text, const ConstElementPtr &arg)
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
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
const isc::log::MessageID NETCONF_FAILED
isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME)
Base logger for the netconf agent.
Definition: netconf_log.h:49
const isc::log::MessageID NETCONF_STARTED
boost::shared_ptr< NetconfCfgMgr > NetconfCfgMgrPtr
Defines a shared pointer to NetconfCfgMgr.
const isc::log::MessageID NETCONF_RUN_EXIT
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:247
Defines the logger used by the top-level component of kea-lfc.
Contains declarations for loggers used by the Kea netconf agent.