Kea  2.5.2
netconf.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2022 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 
8 
9 #ifndef NETCONF_H
10 #define NETCONF_H
11 
12 #include <netconf/control_socket.h>
17 
18 #include <sysrepo-cpp/Session.hpp>
19 
20 #include <map>
21 
22 namespace isc {
23 namespace netconf {
24 
26 class NetconfAgent;
27 
29 using NetconfAgentPtr = std::shared_ptr<NetconfAgent>;
30 
39 class NetconfAgent {
40 public:
42  virtual ~NetconfAgent();
43 
48  void initSysrepo();
49 
58  void init(NetconfCfgMgrPtr cfg_mgr);
59 
63  void clear();
64 
72  static sysrepo::ErrorCode
73  change(sysrepo::Session sess, const CfgServersMapPair& service_pair);
74 
83  static sysrepo::ErrorCode
84  done(sysrepo::Session sess, const CfgServersMapPair& service_pair);
85 
94  static void logChanges(sysrepo::Session sess, std::string_view const& model);
95 
96 protected:
104  void keaConfig(const CfgServersMapPair& service_pair);
105 
113  bool checkModule(const std::string& module_name) const;
114 
119  void getModules();
120 
132  void checkModules(CfgServersMapPtr const& servers = {}) const;
133 
145  void yangConfig(const CfgServersMapPair& service_pair);
146 
150  void subscribeToDataChanges(const CfgServersMapPair& service_pair);
151 
155  void subscribeToNotifications(const CfgServersMapPair& service_pair);
156 
159  void announceShutdown() const;
160 
162  bool shouldShutdown() const;
163 
165  std::optional<sysrepo::Session> startup_sess_;
166 
168  std::optional<sysrepo::Session> running_sess_;
169 
171  std::map<const std::string, const std::string> modules_;
172 
174  std::map<const std::string, sysrepo::Subscription> subscriptions_;
175 }; // NetconfAgent
176 
177 } // namespace netconf
178 } // namespace isc
179 
180 #endif // NETCONF_H
Netconf agent.
Definition: netconf.h:39
void subscribeToDataChanges(const CfgServersMapPair &service_pair)
Subscribe changes for a module in YANG datastore.
Definition: netconf.cc:423
std::optional< sysrepo::Session > running_sess_
Sysrepo running datastore session.
Definition: netconf.h:168
void getModules()
Retrieve names and revisions of installed modules through the sysrepo API.
Definition: netconf.cc:260
static void logChanges(sysrepo::Session sess, std::string_view const &model)
Log changes.
Definition: netconf.cc:682
void yangConfig(const CfgServersMapPair &service_pair)
Retrieve Kea server configuration from the YANG startup datastore and applies it to servers.
Definition: netconf.cc:338
virtual ~NetconfAgent()
Destructor (call clear).
Definition: netconf.cc:145
void initSysrepo()
Initialize sysrepo sessions.
Definition: netconf.cc:245
void keaConfig(const CfgServersMapPair &service_pair)
Get and display Kea server configuration.
Definition: netconf.cc:185
void announceShutdown() const
Set the shutdown flag of the process to true so that it can exit at the earliest convenient time.
Definition: netconf.cc:729
void checkModules(CfgServersMapPtr const &servers={}) const
Check module availability.
Definition: netconf.cc:306
std::map< const std::string, sysrepo::Subscription > subscriptions_
Subscription map.
Definition: netconf.h:174
bool shouldShutdown() const
Check the shutdown flag of the process.
Definition: netconf.cc:738
static sysrepo::ErrorCode change(sysrepo::Session sess, const CfgServersMapPair &service_pair)
Event::Change callback.
Definition: netconf.cc:505
std::optional< sysrepo::Session > startup_sess_
Sysrepo startup datastore session.
Definition: netconf.h:165
static sysrepo::ErrorCode done(sysrepo::Session sess, const CfgServersMapPair &service_pair)
Event::Done callback.
Definition: netconf.cc:589
void init(NetconfCfgMgrPtr cfg_mgr)
Initialization.
Definition: netconf.cc:150
void subscribeToNotifications(const CfgServersMapPair &service_pair)
Subscribe to notifications for a given YANG module.
Definition: netconf.cc:467
bool checkModule(const std::string &module_name) const
Check essential module availability.
Definition: netconf.cc:281
std::map< const std::string, const std::string > modules_
Available modules and revisions in Sysrepo.
Definition: netconf.h:171
Contains declarations for control socket communication.
Contains declarations for HTTP control socket communication.
std::shared_ptr< CfgServersMap > CfgServersMapPtr
Defines a pointer to map of CfgServers.
std::shared_ptr< NetconfAgent > NetconfAgentPtr
Type definition for the pointer to the NetconfAgent.
Definition: netconf.h:29
std::pair< std::string, CfgServerPtr > CfgServersMapPair
Defines a iterator pairing of name and CfgServer.
boost::shared_ptr< NetconfCfgMgr > NetconfCfgMgrPtr
Defines a shared pointer to NetconfCfgMgr.
Defines the logger used by the top-level component of kea-lfc.
Contains declarations for stdout control socket communication.
Contains declarations for UNIX control socket communication.