| Kea 3.0.2-git

isc::netconf::NetconfAgent Class Reference

Netconf agent. More...

`#include <netconf.h>`

## Public Member Functions
virtual | ~NetconfAgent ()
| Destructor (call clear).
void | clear ()
| Clear.
void | init (NetconfCfgMgrPtr cfg_mgr)
| Initialization.
void | initSysrepo ()
| Initialize sysrepo sessions.

## Static Public Member Functions
static sysrepo::ErrorCode | change (sysrepo::Session sess, const CfgServersMapPair &service_pair)
| Event::Change callback.
static sysrepo::ErrorCode | done (sysrepo::Session sess, const CfgServersMapPair &service_pair)
| Event::Done callback.
static void | logChanges (sysrepo::Session sess, std::string_view const &model)
| Log changes.

## Protected Member Functions
void | announceShutdown () const
| Set the shutdown flag of the process to true so that it can exit at the earliest convenient time.
bool | checkModule (const std::string &module_name) const
| Check essential module availability.
void | checkModules (CfgServersMapPtr const &servers={}) const
| Check module availability.
void | getModules ()
| Retrieve names and revisions of installed modules through the sysrepo API.
void | keaConfig (const CfgServersMapPair &service_pair)
| Get and display Kea server configuration.
bool | shouldShutdown () const
| Check the shutdown flag of the process.
void | subscribeToDataChanges (const CfgServersMapPair &service_pair)
| Subscribe changes for a module in YANG datastore.
void | subscribeToNotifications (const CfgServersMapPair &service_pair)
| Subscribe to notifications for a given YANG module.
void | yangConfig (const CfgServersMapPair &service_pair)
| Retrieve Kea server configuration from the YANG startup datastore and applies it to servers.

## Protected Attributes
std::map< const std::string, const std::string > | modules_
| Available modules and revisions in Sysrepo.
std::optional< sysrepo::Session > | running_sess_
| Sysrepo running datastore session.
std::optional< sysrepo::Session > | startup_sess_
| Sysrepo startup datastore session.
std::map< const std::string, sysrepo::Subscription > | subscriptions_
| Subscription map.

## Detailed Description

Netconf agent.

Service performed by the Netconf agent:

- at boot get and display Kea server configurations.
- load Kea server configurations from YANG datastore.
- validate YANG datastore changes using Kea configuration test.
- load updated Kea server configurations from YANG datastore.
- on shutdown close subscriptions.

Definition at line 39 of file netconf.h.

## Constructor & Destructor Documentation

## ◆ ~NetconfAgent()

isc::netconf::NetconfAgent::~NetconfAgent | ( |  | ) |
| virtual

Destructor (call clear).

Definition at line 150 of file netconf.cc.

References clear().

Here is the call graph for this function:

## Member Function Documentation

## ◆ announceShutdown()

void isc::netconf::NetconfAgent::announceShutdown | ( |  | ) | const
| protected

Set the shutdown flag of the process to true so that it can exit at the earliest convenient time.

Definition at line 746 of file netconf.cc.

References isc::netconf::NetconfController::instance().

Here is the call graph for this function:

## ◆ change()

sysrepo::ErrorCode isc::netconf::NetconfAgent::change | ( | sysrepo::Session | sess,
|  | const CfgServersMapPair & | service_pair )
| static

Event::Change callback.

Validate YANG datastore changes using Kea configuration test.

Parameters

  sess | The sysrepo running datastore session.
  service_pair | The service name and configuration pair.

Returns
  return code for sysrepo.

Definition at line 522 of file netconf.cc.

References isc::config::answerToText(), isc::netconf::ControlSocketBase::configTest(), isc::config::CONTROL_RESULT_SUCCESS, isc::netconf::controlSocketFactory(), isc::netconf::CfgServer::getCfgControlSocket(), isc::yang::TranslatorConfig::getConfig(), isc::netconf::CfgServer::getModel(), isc::netconf::CfgServer::getSubscribeChanges(), isc::netconf::CfgServer::getValidateChanges(), LOG_DEBUG, LOG_ERROR, LOG_INFO, isc::netconf::NETCONF_DBG_TRACE_DETAIL_DATA, isc::netconf::netconf_logger, isc::netconf::NETCONF_VALIDATE_CONFIG, isc::netconf::NETCONF_VALIDATE_CONFIG_COMPLETED, isc::netconf::NETCONF_VALIDATE_CONFIG_FAILED, isc::netconf::NETCONF_VALIDATE_CONFIG_REJECTED, isc::netconf::NETCONF_VALIDATE_CONFIG_STARTED, isc::config::parseAnswer(), and isc::data::prettyPrint().

Referenced by logChanges().

Here is the call graph for this function:

## ◆ checkModule()

bool isc::netconf::NetconfAgent::checkModule | ( | const std::string & | module_name | ) | const
| protected

Check essential module availability.

Emit a fatal error if an essential one (i.e. required in a further phase) is missing or does not have the expected revision.

Parameters

  module_name | The module name.

Returns
  true if available, false if not.

Definition at line 285 of file netconf.cc.

References LOG_ERROR, modules_, isc::netconf::netconf_logger, isc::netconf::NETCONF_MODULE_MISSING_ERR, and isc::netconf::NETCONF_MODULE_REVISION_ERR.

Referenced by checkModules().

## ◆ checkModules()

void isc::netconf::NetconfAgent::checkModules | ( | CfgServersMapPtr const & | servers = {} | ) | const
| protected

Check module availability.

Emit a warning if a module is missing or does not have the expected revision.

Parameters

  servers | the configured servers to check against YANG_REVISIONS. Is empty by default for when the caller only wants to check installed modules.

Exceptions

  Unexpected | if a module from YANG_REVISIONS is not installed or has the wrong revision.

Definition at line 310 of file netconf.cc.

References checkModule(), isc_throw, LOG_WARN, modules_, isc::netconf::netconf_logger, isc::netconf::NETCONF_MODULE_MISSING_WARN, and isc::netconf::NETCONF_MODULE_REVISION_WARN.

Referenced by init().

Here is the call graph for this function:

## ◆ clear()

void isc::netconf::NetconfAgent::clear | ( |  | ) |

Clear.

Close subscriptions and sysrepo.

Definition at line 183 of file netconf.cc.

References running_sess_, startup_sess_, and subscriptions_.

Referenced by ~NetconfAgent().

## ◆ done()

sysrepo::ErrorCode isc::netconf::NetconfAgent::done | ( | sysrepo::Session | sess,
|  | const CfgServersMapPair & | service_pair )
| static

Event::Done callback.

Get notified that a Kea configuration has been written to the YANG datastore.

Parameters

  sess | The sysrepo running datastore session.
  service_pair | The service name and configuration pair.

Returns
  return code for sysrepo.

Definition at line 606 of file netconf.cc.

References isc::config::answerToText(), isc::netconf::ControlSocketBase::configSet(), isc::config::CONTROL_RESULT_SUCCESS, isc::netconf::controlSocketFactory(), isc::netconf::CfgServer::getCfgControlSocket(), isc::yang::TranslatorConfig::getConfig(), isc::netconf::CfgServer::getModel(), isc::netconf::CfgServer::getSubscribeChanges(), LOG_DEBUG, LOG_ERROR, LOG_INFO, isc::netconf::NETCONF_DBG_TRACE_DETAIL_DATA, isc::netconf::netconf_logger, isc::netconf::NETCONF_UPDATE_CONFIG, isc::netconf::NETCONF_UPDATE_CONFIG_COMPLETED, isc::netconf::NETCONF_UPDATE_CONFIG_FAILED, isc::netconf::NETCONF_UPDATE_CONFIG_STARTED, isc::config::parseAnswer(), and isc::data::prettyPrint().

Here is the call graph for this function:

## ◆ getModules()

void isc::netconf::NetconfAgent::getModules | ( |  | ) |
| protected

Retrieve names and revisions of installed modules through the sysrepo API.

Exceptions

  Unexpected | if module information cannot be retrieved from sysrepo

Definition at line 265 of file netconf.cc.

References isc_throw, modules_, running_sess_, and isc::Exception::what().

Referenced by initSysrepo().

Here is the call graph for this function:

## ◆ init()

void isc::netconf::NetconfAgent::init | ( | NetconfCfgMgrPtr | cfg_mgr | ) |

Initialization.

Check available modules / revisions. Get and display Kea server configurations. Load Kea server configurations from YANG datastore. Subscribe configuration changes in YANG datastore.

Parameters

  cfg_mgr | The configuration manager (can be null).

Definition at line 155 of file netconf.cc.

References checkModules(), initSysrepo(), isc_throw, keaConfig(), subscribeToDataChanges(), subscribeToNotifications(), and yangConfig().

Here is the call graph for this function:

## ◆ initSysrepo()

void isc::netconf::NetconfAgent::initSysrepo | ( |  | ) |

Initialize sysrepo sessions.

Must be called before init. Collect the list of available modules with their revisions.

Definition at line 250 of file netconf.cc.

References getModules(), isc_throw, running_sess_, and startup_sess_.

Referenced by init().

Here is the call graph for this function:

## ◆ keaConfig()

void isc::netconf::NetconfAgent::keaConfig | ( | const CfgServersMapPair & | service_pair | ) |
| protected

Get and display Kea server configuration.

Retrieves current configuration via control socket (unix or http) from a running Kea server. If boot-update is set to false, this operation is a no-op.

Parameters

  service_pair | The service name and configuration pair.

Definition at line 190 of file netconf.cc.

References isc::config::answerToText(), isc::netconf::ControlSocketBase::configGet(), isc::config::CONTROL_RESULT_SUCCESS, isc::netconf::controlSocketFactory(), isc::netconf::CfgServer::getBootUpdate(), isc::netconf::CfgServer::getCfgControlSocket(), LOG_DEBUG, LOG_ERROR, LOG_INFO, isc::netconf::NETCONF_DBG_TRACE_DETAIL_DATA, isc::netconf::NETCONF_GET_CONFIG, isc::netconf::NETCONF_GET_CONFIG_FAILED, isc::netconf::NETCONF_GET_CONFIG_STARTED, isc::netconf::netconf_logger, isc::config::parseAnswer(), and isc::data::prettyPrint().

Referenced by init().

Here is the call graph for this function:

## ◆ logChanges()

void isc::netconf::NetconfAgent::logChanges | ( | sysrepo::Session | sess,
|  | std::string_view const & | model )
| static

Log changes.

Iterate on changes logging them. Sysrepo changes are an operation (created, modified, deleted or moved) with old and new values (cf sr_change_oper_e sysrepo documentation).

Parameters

  sess | The sysrepo running datastore session.
  model | The model name.

Definition at line 699 of file netconf.cc.

References change(), LOG_DEBUG, isc::netconf::NETCONF_CONFIG_CHANGED_DETAIL, isc::netconf::NETCONF_DBG_TRACE_DETAIL_DATA, isc::netconf::netconf_logger, isc::yang::Translator::translateFromYang(), and isc::yang::Translator::translateToYang().

Here is the call graph for this function:

## ◆ shouldShutdown()

bool isc::netconf::NetconfAgent::shouldShutdown | ( |  | ) | const
| protected

Check the shutdown flag of the process.

Definition at line 756 of file netconf.cc.

References isc::netconf::NetconfController::instance().

Here is the call graph for this function:

## ◆ subscribeToDataChanges()

void isc::netconf::NetconfAgent::subscribeToDataChanges | ( | const CfgServersMapPair & | service_pair | ) |
| protected

Subscribe changes for a module in YANG datastore.

Parameters

  service_pair | The service name and configuration pair.

Definition at line 427 of file netconf.cc.

References isc::netconf::CfgServer::getModel(), isc::netconf::CfgServer::getSubscribeChanges(), isc::netconf::CfgServer::getValidateChanges(), LOG_ERROR, LOG_INFO, isc::netconf::netconf_logger, isc::netconf::NETCONF_MODULE_CHANGE_INTERNAL_ERROR, isc::netconf::NETCONF_SUBSCRIBE_CONFIG, isc::netconf::NETCONF_SUBSCRIBE_CONFIG_FAILED, running_sess_, and subscriptions_.

Referenced by init().

Here is the call graph for this function:

## ◆ subscribeToNotifications()

void isc::netconf::NetconfAgent::subscribeToNotifications | ( | const CfgServersMapPair & | service_pair | ) |
| protected

Subscribe to notifications for a given YANG module.

Parameters

  service_pair | the service name and configuration pair

Definition at line 476 of file netconf.cc.

References isc::netconf::CfgServer::getModel(), isc::netconf::CfgServer::getSubscribeNotifications(), LOG_ERROR, LOG_INFO, LOG_WARN, isc::netconf::netconf_logger, isc::netconf::NETCONF_NOT_SUBSCRIBED_TO_NOTIFICATIONS, isc::netconf::NETCONF_NOTIFICATION_INTERNAL_ERROR, isc::netconf::NETCONF_SUBSCRIBE_NOTIFICATIONS, running_sess_, and subscriptions_.

Referenced by init().

Here is the call graph for this function:

## ◆ yangConfig()

void isc::netconf::NetconfAgent::yangConfig | ( | const CfgServersMapPair & | service_pair | ) |
| protected

Retrieve Kea server configuration from the YANG startup datastore and applies it to servers.

This method retrieves the configuation from sysrepo first, then established control socket connection to Kea servers (currently dhcp4 and/or dhcp6) and then attempts to send configuration using config-set.

If boot-update is set to false, this operation is a no-op.

Parameters

  service_pair | The service name and configuration pair.

Definition at line 342 of file netconf.cc.

References isc::config::answerToText(), isc::netconf::ControlSocketBase::configSet(), isc::config::CONTROL_RESULT_SUCCESS, isc::netconf::controlSocketFactory(), isc::netconf::CfgServer::getBootUpdate(), isc::netconf::CfgServer::getCfgControlSocket(), isc::yang::TranslatorConfig::getConfig(), isc::netconf::CfgServer::getModel(), LOG_DEBUG, LOG_ERROR, LOG_INFO, isc::netconf::NETCONF_BOOT_UPDATE_COMPLETED, isc::netconf::NETCONF_DBG_TRACE_DETAIL_DATA, isc::netconf::netconf_logger, isc::netconf::NETCONF_SET_CONFIG, isc::netconf::NETCONF_SET_CONFIG_FAILED, isc::netconf::NETCONF_SET_CONFIG_STARTED, isc::config::parseAnswer(), isc::data::prettyPrint(), and startup_sess_.

Referenced by init().

Here is the call graph for this function:

## Member Data Documentation

## ◆ modules_

std::map<const std::string, const std::string> isc::netconf::NetconfAgent::modules_
| protected

Available modules and revisions in Sysrepo.

Definition at line 169 of file netconf.h.

Referenced by checkModule(), checkModules(), and getModules().

## ◆ running_sess_

std::optional<sysrepo::Session> isc::netconf::NetconfAgent::running_sess_
| protected

Sysrepo running datastore session.

Definition at line 166 of file netconf.h.

Referenced by clear(), getModules(), initSysrepo(), subscribeToDataChanges(), and subscribeToNotifications().

## ◆ startup_sess_

std::optional<sysrepo::Session> isc::netconf::NetconfAgent::startup_sess_
| protected

Sysrepo startup datastore session.

Definition at line 163 of file netconf.h.

Referenced by clear(), initSysrepo(), and yangConfig().

## ◆ subscriptions_

std::map<const std::string, sysrepo::Subscription> isc::netconf::NetconfAgent::subscriptions_
| protected

Subscription map.

Definition at line 172 of file netconf.h.

Referenced by clear(), subscribeToDataChanges(), and subscribeToNotifications().

The documentation for this class was generated from the following files:

- netconf.h
- netconf.cc