17using namespace libyang;
 
   18using namespace sysrepo;
 
   38        if (
model_ == IETF_DHCPV6_SERVER) {
 
   40        } 
else if ((
model_ == KEA_DHCP4_SERVER) ||
 
   41                   (
model_ == KEA_DHCP6_SERVER)) {
 
   44    } 
catch (Error 
const& ex) {
 
   50              "getSubnet not implemented for the model: " << 
model_);
 
 
   69                         [&](DataNode 
const& node) -> 
ElementPtr const {
 
   74                [&](DataNode 
const& node) -> 
ElementPtr const {
 
   81        context->set(
"description", description);
 
   82        result->set(
"user-context", context);
 
   85    if (result->get(
"pools")) {
 
   93    return (result->empty() ? 
ElementPtr() : result);
 
 
  143        result->set(
"option-data", options);
 
  148        result->set(
"pools", pools);
 
  152                [&](DataNode 
const& node) -> 
ElementPtr const {
 
  160        result->set(
"reservations", hosts);
 
  163    if (
model_ == KEA_DHCP6_SERVER) {
 
  173            result->set(
"pd-pools", pd_pools);
 
  175    } 
else if (
model_ == KEA_DHCP4_SERVER) {
 
  188    return (result->empty() ? 
ElementPtr() : result);
 
 
  194        if (
model_ == IETF_DHCPV6_SERVER) {
 
  196        } 
else if ((
model_ == KEA_DHCP4_SERVER) ||
 
  197                   (
model_ == KEA_DHCP6_SERVER)) {
 
  201                      "setSubnet not implemented for the model: " << 
model_);
 
  203    } 
catch (Error 
const& ex) {
 
  205                  "setting subnet '" << elem->str()
 
  206                  << 
"' : " << ex.
what());
 
 
  222    if (context && context->contains(
"description")) {
 
  225            setItem(xpath + 
"/network-description", description, LeafBaseType::String);
 
  232    setItem(xpath + 
"/network-prefix", subnet, LeafBaseType::String);
 
  234    if (pools && !pools->empty()) {
 
  235        setPools(xpath + 
"/address-pools", pools);
 
  237    pools = elem->get(
"pd-pools");
 
  238    if (pools && !pools->empty()) {
 
 
  258    setItem(xpath + 
"/subnet", subnet, LeafBaseType::String);
 
  263    checkAndSetLeaf(elem, xpath, 
"calculate-tee-times", LeafBaseType::Bool);
 
  265    checkAndSetLeaf(elem, xpath, 
"ddns-generated-prefix", LeafBaseType::String);
 
  266    checkAndSetLeaf(elem, xpath, 
"ddns-override-client-update", LeafBaseType::Bool);
 
  267    checkAndSetLeaf(elem, xpath, 
"ddns-override-no-update", LeafBaseType::Bool);
 
  268    checkAndSetLeaf(elem, xpath, 
"ddns-qualifying-suffix", LeafBaseType::String);
 
  269    checkAndSetLeaf(elem, xpath, 
"ddns-replace-client-name", LeafBaseType::String);
 
  275    checkAndSetLeaf(elem, xpath, 
"ddns-update-on-renew", LeafBaseType::Bool);
 
  276    checkAndSetLeaf(elem, xpath, 
"ddns-use-conflict-resolution", LeafBaseType::Bool);
 
  277    checkAndSetLeaf(elem, xpath, 
"ddns-conflict-resolution-mode", LeafBaseType::Enum);
 
  278    checkAndSetLeaf(elem, xpath, 
"hostname-char-replacement", LeafBaseType::String);
 
  279    checkAndSetLeaf(elem, xpath, 
"hostname-char-set", LeafBaseType::String);
 
  281    checkAndSetLeaf(elem, xpath, 
"max-valid-lifetime", LeafBaseType::Uint32);
 
  282    checkAndSetLeaf(elem, xpath, 
"min-valid-lifetime", LeafBaseType::Uint32);
 
  285    checkAndSetLeaf(elem, xpath, 
"reservations-global", LeafBaseType::Bool);
 
  286    checkAndSetLeaf(elem, xpath, 
"reservations-in-subnet", LeafBaseType::Bool);
 
  287    checkAndSetLeaf(elem, xpath, 
"reservations-out-of-pool", LeafBaseType::Bool);
 
  288    checkAndSetLeaf(elem, xpath, 
"store-extended-info", LeafBaseType::Bool);
 
  297    if (options && !options->empty()) {
 
  301    if (pools && !pools->empty()) {
 
  307        if (addresses && !addresses->empty()) {
 
  308            for (
ElementPtr const& addr : addresses->listValue()) {
 
  309                setItem(xpath + 
"/relay/ip-addresses", addr, LeafBaseType::String);
 
  314    if (hosts && !hosts->empty()) {
 
  318    if (
model_ == KEA_DHCP6_SERVER) {
 
  320        checkAndSetLeaf(elem, xpath, 
"max-preferred-lifetime", LeafBaseType::Uint32);
 
  321        checkAndSetLeaf(elem, xpath, 
"min-preferred-lifetime", LeafBaseType::Uint32);
 
  323        checkAndSetLeaf(elem, xpath, 
"preferred-lifetime", LeafBaseType::Uint32);
 
  326        pools = elem->get(
"pd-pools");
 
  327        if (pools && !pools->empty()) {
 
 
  361        if (
model_ == IETF_DHCPV6_SERVER) {
 
  363        } 
else if (
model_ == KEA_DHCP4_SERVER) {
 
  365        } 
else if (
model_ == KEA_DHCP6_SERVER) {
 
  368    } 
catch (Error 
const& ex) {
 
  374              "getSubnets not implemented for the model: " << 
model_);
 
 
  388                                    string const& subsel) {
 
 
  396        if (
model_ == IETF_DHCPV6_SERVER) {
 
  398        } 
else if (
model_ == KEA_DHCP4_SERVER) {
 
  400        } 
else if (
model_ == KEA_DHCP6_SERVER) {
 
  404                      "setSubnets not implemented for the model: " << 
model_);
 
  406    } 
catch (Error 
const& ex) {
 
  408                  "setting subnets '" << elem->str()
 
  409                  << 
"' : " << ex.
what());
 
 
  415    for (
size_t i = 0; i < elem->size(); ++i) {
 
  418        range << xpath << 
"/network-range[network-range-id='";
 
  423        range << 
id->intValue() << 
"']";
 
 
  430                                 string const& subsel) {
 
  431    for (
size_t i = 0; i < elem->size(); ++i) {
 
  433        if (!subnet->contains(
"id")) {
 
  436        ostringstream prefix;
 
  437        prefix << xpath << 
"/" << subsel << 
"[id='" 
  438               << subnet->get(
"id")->intValue() << 
"']";
 
 
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
static void toSubnet(const std::string &model, isc::data::ElementPtr subnet, isc::data::ConstElementPtr pools)
Move parameters from pools to the subnet.
static void fromSubnet(const std::string &model, isc::data::ConstElementPtr subnet, isc::data::ConstElementPtr pools)
Moves parameters from subnets to pools.
Translation between YANG and JSON for a single host reservation.
A translator class for converting host reservations list between YANG and JSON.
isc::data::ElementPtr getHosts(libyang::DataNode const &data_node)
Translate host reservations from YANG to JSON.
TranslatorHosts(sysrepo::Session session, const std::string &model)
Constructor.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.
A translator class for converting an option data list between YANG and JSON.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
isc::data::ConstElementPtr getOptionDataList(libyang::DataNode const &data_node)
Translate option data list from YANG to JSON.
Option data translation between YANG and JSON.
Prefix delegation pool translation between YANG and JSON.
A translator class for converting a pd-pool list between YANG and JSON.
TranslatorPdPools(sysrepo::Session session, const std::string &model)
Constructor.
void setPdPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pools from JSON to YANG.
isc::data::ElementPtr getPdPools(libyang::DataNode const &data_node)
Translate pd-pools from YANG to JSON.
A translator class for converting a pool between YANG and JSON.
A translator class for converting pools between YANG and JSON.
TranslatorPools(sysrepo::Session session, const std::string &model)
Constructor.
void setPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pools from JSON to YANG.
isc::data::ElementPtr getPools(libyang::DataNode const &data_node)
Translate pools from YANG to JSON.
isc::data::ElementPtr getSubnet(libyang::DataNode const &data_node)
Get and translate a subnet from YANG to JSON.
void setSubnetIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for ietf-dhcpv6-server.
void setSubnet(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnet from JSON to YANG.
isc::data::ElementPtr getSubnetIetf6(libyang::DataNode const &data_node)
getSubnet for ietf-dhcpv6-server.
isc::data::ElementPtr getSubnetFromAbsoluteXpath(std::string const &xpath)
Get and translate a subnet from YANG to JSON.
TranslatorSubnet(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getSubnetKea(libyang::DataNode const &data_node)
getSubnet for kea-dhcp[46]-server.
void setSubnetKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for kea-dhcp[46]-server.
isc::data::ElementPtr getSubnetsCommon(libyang::DataNode const &data_node, const std::string &subsel)
getSubnets common part.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
void setSubnetsKea(const std::string &xpath, isc::data::ConstElementPtr elem, const std::string &subsel)
setSubnets for kea-dhcp[46]-server.
isc::data::ElementPtr getSubnets(libyang::DataNode const &data_node)
Get and translate subnets from YANG to JSON.
isc::data::ElementPtr getSubnetsFromAbsoluteXpath(std::string const &xpath)
Get and translate subnets from YANG to JSON.
void setSubnetsIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnets for ietf-dhcpv6-server.
TranslatorSubnets(sysrepo::Session session, const std::string &model)
Constructor.
Between YANG and JSON translator class for basic values.
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...
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 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.
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...
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 {st...
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.
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
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 sto...
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 sto...
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 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 sto...
void setItem(const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
Translate and set basic value from JSON to YANG.
std::string model_
The model.
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 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,...
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 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 {st...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.