14#include <boost/lexical_cast.hpp> 
   21using namespace libyang;
 
   22using namespace sysrepo;
 
   36        if (
model_ == IETF_DHCPV6_SERVER) {
 
   38        } 
else if ((
model_ == KEA_DHCP4_SERVER) ||
 
   39                   (
model_ == KEA_DHCP6_SERVER)) {
 
   42    } 
catch (Error 
const& ex) {
 
   48              "getPool not implemented for the model: " << 
model_);
 
 
   81    return (result->empty() ? 
ElementPtr() : result);
 
 
   89        result->set(
"pool", prefix);
 
   93        if (!start_addr || !end_addr) {
 
   95                      "both start and end addresses");
 
   98        range << start_addr->stringValue() << 
" - " 
   99              << end_addr->stringValue();
 
  104        result->set(
"option-data", options);
 
  130    return (result->empty() ? 
ElementPtr() : result);
 
 
  136        if (
model_ == IETF_DHCPV6_SERVER) {
 
  138        } 
else if ((
model_ == KEA_DHCP4_SERVER) ||
 
  139                   (
model_ == KEA_DHCP6_SERVER)) {
 
  143                      "setPool not implemented for the model: " << 
model_);
 
  145    } 
catch (Error 
const& ex) {
 
  147                  "setting pool '" << elem->str()
 
  148                  << 
"' : " << ex.
what());
 
 
  158    string prefix = pool->stringValue();
 
  159    if (prefix.find(
"/") == string::npos) {
 
  161                  "setPoolIetf only supports pools in prefix (vs range) " 
  162                  "format and was called with '" << prefix << 
"'");
 
  164    setItem(xpath + 
"/pool-prefix", pool, LeafBaseType::String);
 
  165    string addr = prefix.substr(0, prefix.find_first_of(
" /"));
 
  166    uint8_t plen = boost::lexical_cast<unsigned>
 
  167        (prefix.substr(prefix.find_last_of(
" /") + 1, string::npos));
 
  169    setItem(xpath + 
"/start-address",
 
  171            LeafBaseType::String);
 
  172    setItem(xpath + 
"/end-address",
 
  174            LeafBaseType::String);
 
  177    checkAndSetLeaf(elem, xpath, 
"preferred-lifetime", LeafBaseType::Uint32);
 
  184    setItem(xpath + 
"/max-address-count",
 
 
  209    checkAndSetLeaf(elem, xpath, 
"ddns-generated-prefix", LeafBaseType::String);
 
  210    checkAndSetLeaf(elem, xpath, 
"ddns-override-client-update", LeafBaseType::Bool);
 
  211    checkAndSetLeaf(elem, xpath, 
"ddns-override-no-update", LeafBaseType::Bool);
 
  212    checkAndSetLeaf(elem, xpath, 
"ddns-qualifying-suffix", LeafBaseType::String);
 
  213    checkAndSetLeaf(elem, xpath, 
"ddns-replace-client-name", LeafBaseType::String);
 
  219    checkAndSetLeaf(elem, xpath, 
"ddns-update-on-renew", LeafBaseType::Bool);
 
  220    checkAndSetLeaf(elem, xpath, 
"ddns-use-conflict-resolution", LeafBaseType::Bool);
 
  221    checkAndSetLeaf(elem, xpath, 
"ddns-conflict-resolution-mode", LeafBaseType::Enum);
 
  222    checkAndSetLeaf(elem, xpath, 
"hostname-char-replacement", LeafBaseType::String);
 
  223    checkAndSetLeaf(elem, xpath, 
"hostname-char-set", LeafBaseType::String);
 
  233    string prefix = pool->stringValue();
 
  237    if (prefix.find(
"/") != string::npos) {
 
  238        setItem(xpath + 
"/prefix", pool, LeafBaseType::String);
 
  241    if (options && !options->empty()) {
 
 
  248                             string& start_address, 
string& end_address) {
 
  249    size_t slash = prefix.find(
"/");
 
  250    if (slash != string::npos) {
 
  251        string addr = prefix.substr(0, prefix.find_first_of(
" /"));
 
  252        uint8_t plen = boost::lexical_cast<unsigned>
 
  253            (prefix.substr(prefix.find_last_of(
" /") + 1, string::npos));
 
  258    size_t dash = prefix.find(
"-");
 
  259    if (dash == string::npos) {
 
  261                  "getAddresses called with invalid prefix: " << prefix);
 
  263    start_address = prefix.substr(0, prefix.find_first_of(
" -"));
 
  264    end_address = prefix.substr(prefix.find_last_of(
" -") + 1, string::npos);
 
 
  277        if (
model_ == IETF_DHCPV6_SERVER) {
 
  279        } 
else if ((
model_ == KEA_DHCP4_SERVER) ||
 
  280                   (
model_ == KEA_DHCP6_SERVER)) {
 
  283    } 
catch (Error 
const& ex) {
 
  289              "getPools not implemented for the model: " << 
model_);
 
 
  316        if (
model_ == IETF_DHCPV6_SERVER) {
 
  318        } 
else if ((
model_ == KEA_DHCP4_SERVER) ||
 
  319                   (
model_ == KEA_DHCP6_SERVER)) {
 
  323                      "setPools not implemented for the model: " << 
model_);
 
  325    } 
catch (Error 
const& ex) {
 
  327                  "setting pools '" << elem->str()
 
  328                  << 
"' : " << ex.
what());
 
 
  334    for (
size_t i = 0; i < elem->size(); ++i) {
 
  336        ostringstream prefix;
 
  337        prefix << xpath << 
"/address-pool[pool-id='" << i << 
"']";
 
 
  345    for (
size_t i = 0; i < elem->size(); ++i) {
 
  347        if (!pool->contains(
"pool")) {
 
  351        string pref = pool->get(
"pool")->stringValue();
 
  355        ostringstream prefix;
 
  356        prefix << xpath << 
"/pool[start-address='" << start_addr
 
  357               << 
"'][end-address='" << end_addr << 
"']";
 
 
static ElementPtr create(const Position &pos=ZERO_POSITION())
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.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
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.
TranslatorOptionDataList(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ConstElementPtr getOptionDataList(libyang::DataNode const &data_node)
Translate option data list from YANG to JSON.
Option data translation between YANG and JSON.
void setPool(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pool from JSON to YANG.
void setPoolKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setPool for kea-dhcp[46]-server.
isc::data::ElementPtr getPoolIetf6(libyang::DataNode const &data_node)
getPool for ietf-dhcpv6-server.
isc::data::ElementPtr getPool(libyang::DataNode const &data_node)
Translate a pool from YANG to JSON.
isc::data::ElementPtr getPoolKea(libyang::DataNode const &data_node)
getPool for kea-dhcp[46]-server.
TranslatorPool(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getPoolFromAbsoluteXpath(std::string const &xpath)
Translate a pool from YANG to JSON.
static void getAddresses(const std::string &prefix, std::string &start_address, std::string &end_address)
Get start and end addresses from prefix.
void setPoolIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setPool for ietf-dhcpv6-server.
void setPoolsByAddresses(const std::string &xpath, isc::data::ConstElementPtr elem)
setPools using address pair.
void setPoolsById(const std::string &xpath, isc::data::ConstElementPtr elem)
setPools using pool-id.
isc::data::ElementPtr getPoolsKea(libyang::DataNode const &data_node)
getPools for kea-dhcp[46]-server.
isc::data::ElementPtr getPoolsFromAbsoluteXpath(std::string const &xpath)
Translate pools from YANG to 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 getPoolsIetf(libyang::DataNode const &data_node)
getPools for ietf-dhcpv6-server.
isc::data::ElementPtr getPools(libyang::DataNode const &data_node)
Translate pools from YANG to JSON.
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...
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.