Kea  2.1.7-git
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>
16 #include <cc/command_interpreter.h>
17 #include <config/timeouts.h>
18 
19 #include <boost/pointer_cast.hpp>
20 
21 using namespace isc::asiolink;
22 using namespace isc::config;
23 using namespace isc::data;
24 using namespace isc::http;
25 using namespace isc::process;
26 
27 namespace isc {
28 namespace netconf {
29 
30 NetconfProcess::NetconfProcess(const char* name,
31  const asiolink::IOServicePtr& io_service)
32  : DProcessBase(name, io_service, DCfgMgrBasePtr(new NetconfCfgMgr())) {
33 }
34 
35 void
37 }
38 
39 void
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  }
62  "Process run method failed: " << ex.what());
63  }
64 
66 }
67 
68 size_t
69 NetconfProcess::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 isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false)
Processes the given configuration.
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:166
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:247
const isc::log::MessageID NETCONF_STARTED
const isc::log::MessageID NETCONF_FAILED
virtual void init()
Initialize the Netconf process.
Ctrl Netconf Configuration Manager.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
DCfgMgrBasePtr & getCfgMgr()
Fetches the process&#39;s configuration manager.
Definition: d_process.h:195
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
virtual isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args)
Initiates the process&#39;s shutdown process.
const isc::log::MessageID NETCONF_RUN_EXIT
isc::log::Logger netconf_logger(NETCONF_LOGGER_NAME)
Base logger for the netconf agent.
Definition: netconf_log.h:49
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:188
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Defines the logger used by the top-level component of kea-lfc.
boost::shared_ptr< NetconfCfgMgr > NetconfCfgMgrPtr
Defines a shared pointer to NetconfCfgMgr.
This file contains several functions and constants that are used for handling commands and responses ...
asiolink::IOServicePtr & getIoService()
Fetches the controller&#39;s IOService.
Definition: d_process.h:180
Exception thrown if the process encountered an operational error.
Definition: d_process.h:24
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition: macros.h:14
Contains declarations for loggers used by the Kea netconf agent.
Application Process Interface.
Definition: d_process.h:81
NetconfCfgMgrPtr getNetconfCfgMgr()
Returns a pointer to the configuration manager.
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Definition: macros.h:38
void init(NetconfCfgMgrPtr cfg_mgr)
Initialization.
Definition: netconf.cc:155
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
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:159
virtual void run()
Implements the process&#39;s event loop.