Kea 2.5.9
isc::yang::TranslatorPool Class Reference

A translator class for converting a pool between YANG and JSON. More...

#include <translator_pool.h>

+ Inheritance diagram for isc::yang::TranslatorPool:

Public Member Functions

 TranslatorPool (sysrepo::Session session, const std::string &model)
 Constructor.
 
virtual ~TranslatorPool ()=default
 Destructor.
 
isc::data::ElementPtr getPool (libyang::DataNode const &data_node)
 Translate a pool from YANG to JSON.
 
isc::data::ElementPtr getPoolFromAbsoluteXpath (std::string const &xpath)
 Translate a pool from YANG to JSON.
 
void setPool (const std::string &xpath, isc::data::ConstElementPtr elem)
 Translate and set (address) pool from JSON to YANG.
 
- Public Member Functions inherited from isc::yang::TranslatorOptionDataList
 TranslatorOptionDataList (sysrepo::Session session, const std::string &model)
 Constructor.
 
virtual ~TranslatorOptionDataList ()=default
 Destructor.
 
isc::data::ConstElementPtr getOptionDataList (libyang::DataNode const &data_node)
 Translate option data list from YANG to JSON.
 
isc::data::ConstElementPtr getOptionDataListFromAbsoluteXpath (std::string const &xpath)
 Translate option data list from YANG to JSON.
 
void setOptionDataList (const std::string &xpath, isc::data::ConstElementPtr elem)
 Translate and set option data list from JSON to YANG.
 
- Public Member Functions inherited from isc::yang::TranslatorOptionData
 TranslatorOptionData (sysrepo::Session session, const std::string &model)
 Constructor.
 
virtual ~TranslatorOptionData ()=default
 Destructor.
 
isc::data::ElementPtr getOptionData (libyang::DataNode const &data_node)
 Translate an option data from YANG to JSON.
 
isc::data::ElementPtr getOptionDataFromAbsoluteXpath (std::string const &xpath)
 Translate an option data from YANG to JSON.
 
void setOptionData (const std::string &xpath, isc::data::ConstElementPtr elem)
 Translate and set option data 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.
 

Static Public Member Functions

static void getAddresses (const std::string &prefix, std::string &start_address, std::string &end_address)
 Get start and end addresses from prefix.
 
- 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 Member Functions

isc::data::ElementPtr getPoolIetf6 (libyang::DataNode const &data_node)
 getPool for ietf-dhcpv6-server.
 
isc::data::ElementPtr getPoolKea (libyang::DataNode const &data_node)
 getPool for kea-dhcp[46]-server.
 
void setPoolIetf6 (const std::string &xpath, isc::data::ConstElementPtr elem)
 setPool for ietf-dhcpv6-server.
 
void setPoolKea (const std::string &xpath, isc::data::ConstElementPtr elem)
 setPool for kea-dhcp[46]-server.
 
- Protected Member Functions inherited from isc::yang::TranslatorOptionDataList
isc::data::ConstElementPtr getOptionDataListKea (libyang::DataNode const &data_node)
 getOptionDataList for kea-dhcp[46].
 
void setOptionDataListKea (const std::string &xpath, isc::data::ConstElementPtr elem)
 setOptionDataList for kea-dhcp[46].
 
- Protected Member Functions inherited from isc::yang::TranslatorOptionData
isc::data::ElementPtr getOptionDataKea (libyang::DataNode const &data_node)
 getOptionData JSON for kea-dhcp[46].
 
void setOptionDataKea (const std::string &xpath, isc::data::ConstElementPtr elem)
 setOptionData for kea-dhcp[46].
 

Additional Inherited Members

- Protected Types inherited from isc::yang::Translator
using Deserializer = std::unordered_map< libyang::LeafBaseType, std::function< isc::data::ElementPtr const (std::string const &)> >
 Maps YANG types to functions that transform a YANG type into an ElementPtr.
 
using Serializer = std::unordered_map< libyang::LeafBaseType, std::function< std::string const (std::string const &)> >
 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

A translator class for converting a pool between YANG and JSON.

Currently supports on kea-dhcp[46]-server and partially ietf-dhcpv6-server.

JSON syntax for both kea-dhcp4 and kea-dhcp6 is:

{
"pool": "<pool prefix or start - end addresses>",
"option-data": [ <list of option data> ],
"client-class": "<guard class name>",
"require-client-classes": [ <list of required class names> ],
"user-context": { <json map> },
"comment": "<comment>"
}

YANG syntax is for ietf-dhcpv6-server is with pool-id as the key:

+--rw pool-id uint32
+--rw pool-prefix inet:ipv6-prefix
+--rw start-address inet:ipv6-address-no-zone
+--rw end-address inet:ipv6-address-no-zone
+--rw valid-lifetime yang:timeticks
+--rw renew-time yang:timeticks
+--rw rebind-time yang:timeticks
+--rw preferred-lifetime yang:timeticks
+--rw rapid-commit? boolean
+--rw client-class? string
+--rw max-address-count threshold
+--rw option-set-id
/server/server-config/option-sets/option-set/option-set-id

YANG syntax for kea-dhcp[46] is with start-address and end-address as the keys:

+--rw pool* [start-address end-address]
+--rw prefix? inet:ipv[46]-prefix
+--rw start-address inet:ipv[46]-address
+--rw end-address inet:ipv[46]-address
+--rw option-data* [code space]
+--rw client-class? string
+--rw require-client-classes* string
+--rw user-context? user-context

An example in JSON and YANG formats for the IETF model:

[
{
"pool": "2001:db8::/112"
}
]
/ietf-dhcpv6-server:server (container)
/ietf-dhcpv6-server:server/server-config (container)
/ietf-dhcpv6-server:server/server-config/network-ranges (container)
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111'] (list instance)
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/network-range-id = 111
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/network-prefix = 2001:db8::/48
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/address-pools (container)
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/address-pools/
address-pool[pool-id='0'] (list instance)
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/address-pools/
address-pool[pool-id='0']/pool-id = 0
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/address-pools/
address-pool[pool-id='0']/pool-prefix = 2001:db8::1:0/112
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/address-pools/
address-pool[pool-id='0']/start-address = 2001:db8::1:0
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/address-pools/
address-pool[pool-id='0']/end-address = 2001:db8::1:ffff
/ietf-dhcpv6-server:server/server-config/network-ranges/
network-range[network-range-id='111']/address-pools/
address-pool[pool-id='0']/max-address-count = disabled

An example in JSON and YANG formats for the Kea model:

[
{
"pool": "2001:db8::1 - 2001:db8::100"
}
]
/kea-dhcp6-server:config (container)
/kea-dhcp6-server:config/subnet6[id='111'] (list instance)
/kea-dhcp6-server:config/subnet6[id='111']/id = 111
/kea-dhcp6-server:config/subnet6[id='111']/subnet = 2001:db8::/48
/kea-dhcp6-server:config/subnet6[id='111']/
pool[start-address='2001:db8::1'][end-address='2001:db8::100']
(list instance)
/kea-dhcp6-server:config/subnet6[id='111']/
pool[start-address='2001:db8::1'][end-address='2001:db8::100']/
start-address = 2001:db8::1
/kea-dhcp6-server:config/subnet6[id='111']/
pool[start-address='2001:db8::1'][end-address='2001:db8::100']/
end-address = 2001:db8::100

Definition at line 124 of file translator_pool.h.

Constructor & Destructor Documentation

◆ TranslatorPool()

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

Constructor.

Parameters
sessionSysrepo session.
modelModel name.

Definition at line 27 of file translator_pool.cc.

◆ ~TranslatorPool()

virtual isc::yang::TranslatorPool::~TranslatorPool ( )
virtualdefault

Destructor.

Member Function Documentation

◆ getAddresses()

void isc::yang::TranslatorPool::getAddresses ( const std::string &  prefix,
std::string &  start_address,
std::string &  end_address 
)
static

Get start and end addresses from prefix.

Parameters
prefixThe prefix string.
start_addressThe reference to the start_address.
end_addressThe reference to the end_address.
Exceptions
BadValuewhen the prefix is not correctly formed.

Definition at line 215 of file translator_pool.cc.

References isc::asiolink::firstAddrInPrefix(), isc_throw, isc::asiolink::lastAddrInPrefix(), and isc::asiolink::IOAddress::toText().

Referenced by setPoolKea(), and isc::yang::TranslatorPools::setPoolsByAddresses().

+ Here is the call graph for this function:

◆ getPool()

ElementPtr isc::yang::TranslatorPool::getPool ( libyang::DataNode const &  data_node)

Translate a pool from YANG to JSON.

Parameters
data_nodethe YANG node representing the pool
Returns
the JSON representation of the pool
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 34 of file translator_pool.cc.

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

Referenced by getPoolFromAbsoluteXpath(), isc::yang::TranslatorPools::getPoolsIetf(), and isc::yang::TranslatorPools::getPoolsKea().

+ Here is the call graph for this function:

◆ getPoolFromAbsoluteXpath()

ElementPtr isc::yang::TranslatorPool::getPoolFromAbsoluteXpath ( std::string const &  xpath)

Translate a pool from YANG to JSON.

Parameters
xpathThe xpath of the pool.
Returns
JSON representation of the pool.
Exceptions
NetconfErrorwhen sysrepo raises an error.

Definition at line 52 of file translator_pool.cc.

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

+ Here is the call graph for this function:

◆ getPoolIetf6()

ElementPtr isc::yang::TranslatorPool::getPoolIetf6 ( libyang::DataNode const &  data_node)
protected

getPool for ietf-dhcpv6-server.

Parameters
data_nodethe YANG node representing the pool configuration
Returns
JSON representation of the pool.
Exceptions
BadValueon pool without prefix.

Definition at line 61 of file translator_pool.cc.

References isc::yang::Translator::checkAndGetDivergingLeaf(), isc::yang::Translator::checkAndGetLeaf(), isc::data::Element::createMap(), and isc::yang::Translator::getMandatoryDivergingLeaf().

Referenced by getPool().

+ Here is the call graph for this function:

◆ getPoolKea()

ElementPtr isc::yang::TranslatorPool::getPoolKea ( libyang::DataNode const &  data_node)
protected

getPool for kea-dhcp[46]-server.

Parameters
data_nodethe YANG node representing the pool configuration
Returns
JSON representation of the pool.
Exceptions
BadValueon a pool without prefix and start or end address.

Definition at line 85 of file translator_pool.cc.

References isc::yang::Translator::checkAndGetAndJsonifyLeaf(), isc::yang::Translator::checkAndGetLeaf(), isc::data::Element::create(), isc::data::Element::createMap(), isc::yang::Translator::getItem(), isc::yang::TranslatorOptionDataList::getOptionDataList(), and isc_throw.

Referenced by getPool().

+ Here is the call graph for this function:

◆ setPool()

void isc::yang::TranslatorPool::setPool ( const std::string &  xpath,
isc::data::ConstElementPtr  elem 
)

Translate and set (address) pool from JSON to YANG.

Parameters
xpathThe xpath of the pool.
elemThe JSON element.

Definition at line 118 of file translator_pool.cc.

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

Referenced by isc::yang::TranslatorPools::setPoolsByAddresses(), and isc::yang::TranslatorPools::setPoolsById().

+ Here is the call graph for this function:

◆ setPoolIetf6()

void isc::yang::TranslatorPool::setPoolIetf6 ( const std::string &  xpath,
isc::data::ConstElementPtr  elem 
)
protected

setPool for ietf-dhcpv6-server.

Parameters
xpathThe xpath of the pool.
elemThe JSON element.
Exceptions
BadValueon pool without prefix and with a range which is not a prefix.

Definition at line 137 of file translator_pool.cc.

References isc::yang::Translator::checkAndSetDivergingLeaf(), isc::yang::Translator::checkAndSetLeaf(), isc::data::Element::create(), isc::asiolink::firstAddrInPrefix(), isc_throw, isc::asiolink::lastAddrInPrefix(), and isc::yang::Translator::setItem().

Referenced by setPool().

+ Here is the call graph for this function:

◆ setPoolKea()

void isc::yang::TranslatorPool::setPoolKea ( const std::string &  xpath,
isc::data::ConstElementPtr  elem 
)
protected

setPool for kea-dhcp[46]-server.

Parameters
xpathThe xpath of the pool.
elemThe JSON element.
Exceptions
BadValueon a pool without a well formed prefix.

Definition at line 178 of file translator_pool.cc.

References isc::yang::Translator::checkAndSetLeaf(), isc::yang::Translator::checkAndSetLeafList(), isc::yang::Translator::checkAndSetUserContext(), getAddresses(), isc_throw, isc::yang::Translator::setItem(), and isc::yang::TranslatorOptionDataList::setOptionDataList().

Referenced by setPool().

+ Here is the call graph for this function:

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