Kea: isc::yang::TranslatorControlSocket Class Reference

| Kea 3.2.0-git

isc::yang::TranslatorControlSocket Class Reference

Control socket translation between YANG and JSON. More...

`#include <translator_control_socket.h>`

Inheritance diagram for isc::yang::TranslatorControlSocket:
[legend]

## Public Member Functions
| TranslatorControlSocket (sysrepo::Session session, const std::string &model)
| Constructor.
virtual | ~TranslatorControlSocket ()=default
| Destructor.
isc::data::ElementPtr | getControlSocket (libyang::DataNode const &data_node)
| Translate a control socket from YANG to JSON.
isc::data::ElementPtr | getControlSocketFromAbsoluteXpath (std::string const &xpath)
| Translate a control socket from YANG to JSON.
isc::data::ElementPtr | getControlSockets (libyang::DataNode const &data_node)
| Translate a control socket from YANG to JSON.
void | setControlSocket (const std::string &xpath, isc::data::ConstElementPtr elem)
| Translate and set control socket from JSON to YANG.
void | setControlSockets (const std::string &xpath, isc::data::ConstElementPtr elem)
| Translate and set control sockets from JSON to YANG.
Public Member Functions inherited from isc::yang::Translator
| Translator (sysrepo::Session session, const std::string &model)
| Constructor.
virtual | ~Translator ()=default
| Destructor.
template<typename T>
void | checkAndGet (isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &xpath, T translate) const
| Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {storage} with the {xpath} key.
void | checkAndGetAndJsonifyLeaf (isc::data::ElementPtr &storage, libyang::DataNode const &data_node, const std::string &name) const
| Retrieves a child YANG data node identified by name from the given parent YANG container node, converts it from string to JSON and stores it in the specified storage.
template<typename T>
void | checkAndGetDiverging (isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &key, std::string const &xpath, T translate) const
| Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {storage} with the {key} key.
void | checkAndGetDivergingLeaf (isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
| Retrieves a child YANG data node identified by name from the given parent YANG container node and stores it in the specified storage.
void | checkAndGetLeaf (isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
| Retrieves a child YANG data node identified by name from the given parent YANG container node and stores it in the specified storage.
void | checkAndSetDivergingLeaf (isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, std::string const &yang_name, libyang::LeafBaseType const type)
| Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void | checkAndSetLeaf (isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
| Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void | checkAndSetLeafList (isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
| Get an element from given ElementPtr node and set it in sysrepo at given xpath as a leaf-list.
void | checkAndSetUserContext (isc::data::ConstElementPtr const &from, std::string const &xpath)
| Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void | checkAndStringifyAndSetLeaf (isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name)
| Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void | deleteItem (const std::string &xpath)
| Delete basic value from YANG.
libyang::DataNode | findXPath (std::string const &xpath) const
| Retrieves a YANG data node by xpath.
template<typename functor_t>
void | forAll (std::string const &xpath, functor_t f) const
| Run a function for a node and all its children.
std::optional< libyang::DataNode > | getData (std::string const &xpath) const
| Get a YANG data node found at the given absolute xpath.
isc::data::ElementPtr | getItem (libyang::DataNode const &data_node, std::string const &xpath) const
| Translate a basic value from YANG to JSON for a given xpath that is relative to the given source node.
isc::data::ElementPtr | getItemFromAbsoluteXpath (std::string const &xpath) const
| Translate a basic value from YANG to JSON for a given absolute xpath.
template<typename T>
isc::data::ElementPtr | getList (libyang::DataNode const &data_node, std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(libyang::DataNode const &)) const
| Retrieve a list as ElementPtr from sysrepo from a certain xpath.
void | getMandatoryDivergingLeaf (isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
| Retrieves a child YANG data node identified by one name from the given parent YANG container node and stores it in the specified storage under a different name.
void | getMandatoryLeaf (isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
| Retrieves a child YANG data node identified by name from the given parent YANG container node and stores it in the specified storage.
bool | schemaNodeExists (std::string const &xpath) const
| Checks whether a YANG node exists in the schema.
void | setItem (const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
| Translate and set basic value from JSON to YANG.
void | setMandatoryDivergingLeaf (isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, std::string const &yang_name, libyang::LeafBaseType const type)
| Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void | setMandatoryLeaf (isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
| Get an element from given ElementPtr node and set it in sysrepo at given xpath.

## Protected Member Functions
isc::data::ElementPtr | getControlSocketAuthenticationClient (libyang::DataNode const &data_node)
| getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr | getControlSocketAuthenticationClients (libyang::DataNode const &data_node)
| getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr | getControlSocketHttpHeader (libyang::DataNode const &data_node)
| getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr | getControlSocketHttpHeaders (libyang::DataNode const &data_node)
| getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr | getControlSocketKea (libyang::DataNode const &data_node)
| getControlSocket JSON for kea models.
isc::data::ElementPtr | getControlSocketsKea (libyang::DataNode const &data_node)
| getControlSocket JSON for kea models.
void | setControlSocketAuthenticationClient (const std::string &xpath, isc::data::ConstElementPtr elem)
| setControlSocketAuthenticationClient for kea models.
void | setControlSocketAuthenticationClients (const std::string &xpath, isc::data::ConstElementPtr elem)
| setControlSocketAuthenticationClients for kea models.
void | setControlSocketHttpHeader (const std::string &xpath, isc::data::ConstElementPtr elem)
| setControlSocketHttpHeader for kea models.
void | setControlSocketHttpHeaders (const std::string &xpath, isc::data::ConstElementPtr elem)
| setControlSocketHttpHeaders for kea models.
void | setControlSocketKea (const std::string &xpath, isc::data::ConstElementPtr elem, bool has_mandatory_key)
| setControlSocket for kea models.
void | setControlSocketsKea (const std::string &xpath, isc::data::ConstElementPtr elem)
| setControlSocket for kea models.

## Additional Inherited Members
Static Public Member Functions inherited from isc::yang::Translator
static isc::data::ElementPtr | translateFromYang (std::optional< libyang::DataNode > data_node)
| Translate basic value from the given YANG data node to JSON element.
static std::optional< std::string > | translateToYang (isc::data::ConstElementPtr const &elem, libyang::LeafBaseType const type)
| Translate basic value from JSON to YANG.
Protected Types inherited from isc::yang::Translator
using | Deserializer
| Maps YANG types to functions that transform a YANG type into an ElementPtr.
using | Serializer
| Maps YANG types to functions that transform the string representation of an Element into a string that can be passed into Session::setItem().
Static Protected Member Functions inherited from isc::yang::Translator
static std::string | decode64 (std::string const &input)
| Decode a YANG element of binary type to a string that can be stored in an Element::string JSON.
static std::string | encode64 (std::string const &input)
| Encode a string such that it can be stored in a YANG element of binary type.
static Deserializer | initializeDeserializer ()
| Initializes the deserializer which is used to translate a YANG node to an ElementPtr.
static Serializer | initializeSerializer ()
| Initializes the serializer which is used to translate the string value of an Element to a string that can be passed into Session::setItem().
Protected Attributes inherited from isc::yang::Translator
std::string | model_
| The model.
sysrepo::Session | session_
| The sysrepo session.

## Detailed Description

Control socket translation between YANG and JSON.

JSON syntax for all Kea servers with command channel is:

"control-sockets": [ {
"socket-type": "<socket type>",
"socket-name": "<socket name>",
"user-context": { <json map> },
"comment": "<comment>"
} ]

YANG syntax is:

+--rw control-socket!
+--rw control-sockets*
+--rw socket-name string
+--rw socket-type enumeration
+--rw user-context? user-context

An example in JSON and YANG formats:

{
"socket-name": "kea.sock",
"socket-type": "unix",
"user-context": { "foo": 1 }
}

A translator class for converting a control socket between YANG and JSON.

Supports the following models:

- kea-dhcp4-server
- kea-dhcp6-server
- kea-dhcp-ddns

Definition at line 52 of file translator_control_socket.h.

## Constructor & Destructor Documentation

## ◆ TranslatorControlSocket()

isc::yang::TranslatorControlSocket::TranslatorControlSocket | ( | sysrepo::Session | session,
|  | const std::string & | model )

Constructor.

Parameters

  session | Sysrepo session.
  model | Model name.

Definition at line 22 of file translator_control_socket.cc.

References isc::yang::Translator::Translator().

Referenced by isc::yang::TranslatorConfig::TranslatorConfig().

Here is the call graph for this function:

## ◆ ~TranslatorControlSocket()

virtual isc::yang::TranslatorControlSocket::~TranslatorControlSocket | ( |  | ) |
| virtualdefault

Destructor.

## Member Function Documentation

## ◆ getControlSocket()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocket | ( | libyang::DataNode const & | data_node | ) |

Translate a control socket from YANG to JSON.

Parameters

  data_node | the YANG node representing the control socket

Returns
  the JSON representation of the control socket

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 43 of file translator_control_socket.cc.

References getControlSocketKea(), isc_throw, isc::yang::Translator::model_, and isc::Exception::what().

Referenced by getControlSocketFromAbsoluteXpath(), and isc::yang::TranslatorConfig::getServerKeaDhcpCommon().

Here is the call graph for this function:

## ◆ getControlSocketAuthenticationClient()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocketAuthenticationClient | ( | libyang::DataNode const & | data_node | ) |
| protected

getControlSocketsAuthenticationClients JSON for kea models.

Parameters

  data_node | the YANG node representing the control socket

Returns
  JSON representation of the control socket.

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 125 of file translator_control_socket.cc.

References isc::yang::Translator::checkAndGetAndJsonifyLeaf(), Element::createMap(), and isc::yang::Translator::getMandatoryLeaf().

Referenced by getControlSocketAuthenticationClients().

Here is the call graph for this function:

## ◆ getControlSocketAuthenticationClients()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocketAuthenticationClients | ( | libyang::DataNode const & | data_node | ) |
| protected

getControlSocketsAuthenticationClients JSON for kea models.

Parameters

  data_node | the YANG node representing the control socket

Returns
  JSON representation of the control socket.

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 119 of file translator_control_socket.cc.

References getControlSocketAuthenticationClient(), and isc::yang::Translator::getList().

Referenced by getControlSocketKea().

Here is the call graph for this function:

## ◆ getControlSocketFromAbsoluteXpath()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocketFromAbsoluteXpath | ( | std::string const & | xpath | ) |

Translate a control socket from YANG to JSON.

Note
  This is a computationally expensive operation that makes a lookup in the sysrepo datastore by calling Session::getData(). It should be used sparingly in production code, mainly to get an initial data node to work with. It may be used at will in unit tests. Use getControlSocket(libyang::DataNode) as a scalable alternative.

Parameters

  xpath | The xpath of the control socket.

Returns
  JSON representation of the control socket

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 148 of file translator_control_socket.cc.

References isc::yang::Translator::findXPath(), and getControlSocket().

Here is the call graph for this function:

## ◆ getControlSocketHttpHeader()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocketHttpHeader | ( | libyang::DataNode const & | data_node | ) |
| protected

getControlSocketsAuthenticationClients JSON for kea models.

Parameters

  data_node | the YANG node representing the control socket

Returns
  JSON representation of the control socket.

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 110 of file translator_control_socket.cc.

References isc::yang::Translator::checkAndGetAndJsonifyLeaf(), isc::yang::Translator::checkAndGetLeaf(), and Element::createMap().

Referenced by getControlSocketHttpHeaders().

Here is the call graph for this function:

## ◆ getControlSocketHttpHeaders()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocketHttpHeaders | ( | libyang::DataNode const & | data_node | ) |
| protected

getControlSocketsAuthenticationClients JSON for kea models.

Parameters

  data_node | the YANG node representing the control socket

Returns
  JSON representation of the control socket.

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 104 of file translator_control_socket.cc.

References getControlSocketHttpHeader(), and isc::yang::Translator::getList().

Referenced by getControlSocketKea().

Here is the call graph for this function:

## ◆ getControlSocketKea()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocketKea | ( | libyang::DataNode const & | data_node | ) |
| protected

getControlSocket JSON for kea models.

Parameters

  data_node | the YANG node representing the control socket

Returns
  JSON representation of the control socket.

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 64 of file translator_control_socket.cc.

References isc::yang::Translator::checkAndGet(), isc::yang::Translator::checkAndGetAndJsonifyLeaf(), isc::yang::Translator::checkAndGetDivergingLeaf(), isc::yang::Translator::checkAndGetLeaf(), isc::data::copy(), Element::createMap(), getControlSocketAuthenticationClients(), and getControlSocketHttpHeaders().

Referenced by getControlSocket(), and getControlSocketsKea().

Here is the call graph for this function:

## ◆ getControlSockets()

ElementPtr isc::yang::TranslatorControlSocket::getControlSockets | ( | libyang::DataNode const & | data_node | ) |

Translate a control socket from YANG to JSON.

Parameters

  data_node | the YANG node representing the control sockets

Returns
  the JSON representation of the control socket

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 27 of file translator_control_socket.cc.

References getControlSocketsKea(), isc_throw, isc::yang::Translator::model_, and isc::Exception::what().

Referenced by isc::yang::TranslatorConfig::getServerKeaDhcpCommon().

Here is the call graph for this function:

## ◆ getControlSocketsKea()

ElementPtr isc::yang::TranslatorControlSocket::getControlSocketsKea | ( | libyang::DataNode const & | data_node | ) |
| protected

getControlSocket JSON for kea models.

Parameters

  data_node | the YANG node representing the control socket

Returns
  JSON representation of the control socket.

Exceptions

  NetconfError | when sysrepo raises an error.

Definition at line 59 of file translator_control_socket.cc.

References getControlSocketKea(), and isc::yang::Translator::getList().

Referenced by getControlSockets().

Here is the call graph for this function:

## ◆ setControlSocket()

void isc::yang::TranslatorControlSocket::setControlSocket | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem )

Translate and set control socket from JSON to YANG.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.

Definition at line 177 of file translator_control_socket.cc.

References isc_throw, isc::yang::Translator::model_, and setControlSocketKea().

Referenced by isc::yang::TranslatorConfig::setServerKeaDhcpCommon().

Here is the call graph for this function:

## ◆ setControlSocketAuthenticationClient()

void isc::yang::TranslatorControlSocket::setControlSocketAuthenticationClient | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem )
| protected

setControlSocketAuthenticationClient for kea models.

Null elem argument removes the container. Required parameters passed in elem are: socket-name, socket-type. Optional parameters are: user-context.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.

Exceptions

  BadValue | on control socket without socket type or name.

Definition at line 292 of file translator_control_socket.cc.

References isc::yang::Translator::checkAndSetUserContext(), and isc::yang::Translator::setItem().

Referenced by setControlSocketAuthenticationClients().

Here is the call graph for this function:

## ◆ setControlSocketAuthenticationClients()

void isc::yang::TranslatorControlSocket::setControlSocketAuthenticationClients | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem )
| protected

setControlSocketAuthenticationClients for kea models.

Null elem argument removes the container. Required parameters passed in elem are: socket-name, socket-type. Optional parameters are: user-context.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.

Exceptions

  BadValue | on control socket without socket type or name.

Definition at line 255 of file translator_control_socket.cc.

References isc::yang::Translator::deleteItem(), and setControlSocketAuthenticationClient().

Referenced by setControlSocketKea().

Here is the call graph for this function:

## ◆ setControlSocketHttpHeader()

void isc::yang::TranslatorControlSocket::setControlSocketHttpHeader | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem )
| protected

setControlSocketHttpHeader for kea models.

Null elem argument removes the container. Required parameters passed in elem are: socket-name, socket-type. Optional parameters are: user-context.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.

Exceptions

  BadValue | on control socket without socket type or name.

Definition at line 317 of file translator_control_socket.cc.

References isc::yang::Translator::checkAndSetLeaf(), isc::yang::Translator::checkAndSetUserContext(), and isc::yang::Translator::setItem().

Referenced by setControlSocketHttpHeaders().

Here is the call graph for this function:

## ◆ setControlSocketHttpHeaders()

void isc::yang::TranslatorControlSocket::setControlSocketHttpHeaders | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem )
| protected

setControlSocketHttpHeaders for kea models.

Null elem argument removes the container. Required parameters passed in elem are: socket-name, socket-type. Optional parameters are: user-context.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.

Exceptions

  BadValue | on control socket without socket type or name.

Definition at line 299 of file translator_control_socket.cc.

References isc::yang::Translator::deleteItem(), isc_throw, and setControlSocketHttpHeader().

Referenced by setControlSocketKea().

Here is the call graph for this function:

## ◆ setControlSocketKea()

void isc::yang::TranslatorControlSocket::setControlSocketKea | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem,
|  | bool | has_mandatory_key )
| protected

setControlSocket for kea models.

Null elem argument removes the container. Required parameters passed in elem are: socket-name, socket-type. Optional parameters are: user-context.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.
  has_mandatory_key | Whether this specific database instance has a mandatory key.

Exceptions

  BadValue | on control socket without socket type or name.

Definition at line 216 of file translator_control_socket.cc.

References isc::yang::Translator::checkAndSetLeaf(), isc::yang::Translator::checkAndSetUserContext(), isc::yang::Translator::deleteItem(), setControlSocketAuthenticationClients(), setControlSocketHttpHeaders(), isc::yang::Translator::setItem(), and isc::yang::Translator::setMandatoryDivergingLeaf().

Referenced by setControlSocket(), and setControlSocketsKea().

Here is the call graph for this function:

## ◆ setControlSockets()

void isc::yang::TranslatorControlSocket::setControlSockets | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem )

Translate and set control sockets from JSON to YANG.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.

Definition at line 157 of file translator_control_socket.cc.

References isc_throw, isc::yang::Translator::model_, and setControlSocketsKea().

Referenced by isc::yang::TranslatorConfig::setServerKeaDhcpCommon().

Here is the call graph for this function:

## ◆ setControlSocketsKea()

void isc::yang::TranslatorControlSocket::setControlSocketsKea | ( | const std::string & | xpath,
|  | isc::data::ConstElementPtr | elem )
| protected

setControlSocket for kea models.

Null elem argument removes the container. Required parameters passed in elem are: socket-name, socket-type. Optional parameters are: user-context.

Parameters

  xpath | The xpath of the control socket.
  elem | The JSON element.

Exceptions

  BadValue | on control socket without socket type or name.

Definition at line 197 of file translator_control_socket.cc.

References isc::yang::Translator::deleteItem(), isc_throw, and setControlSocketKea().

Referenced by setControlSockets().

Here is the call graph for this function:

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

- translator_control_socket.h
- translator_control_socket.cc