12#include <boost/lexical_cast.hpp>
18using namespace libyang;
19using namespace sysrepo;
33 if (
model_ == IETF_DHCPV6_SERVER) {
35 }
else if (
model_ == KEA_DHCP6_SERVER) {
38 }
catch (Error
const& ex) {
44 "getPdPool not implemented for the model: " <<
model_);
64 const string& prefix = pref->stringValue();
65 size_t slash = prefix.find(
"/");
66 if (slash == string::npos) {
68 "getPdPoolIetf6: no '/' in prefix '" << prefix <<
"'");
70 const string& address = prefix.substr(0, slash);
71 if (address.empty()) {
73 "getPdPoolIetf6: malformed prefix '" << prefix <<
"'");
92 return (result->empty() ?
ElementPtr() : result);
102 const string& prefix = pref->stringValue();
103 size_t slash = prefix.find(
"/");
104 if (slash == string::npos) {
106 "getPdPoolKea: no '/' in prefix '" << prefix <<
"'");
108 const string& address = prefix.substr(0, slash);
109 const string& length = prefix.substr(slash + 1, string::npos);
110 if (address.empty() || length.empty()) {
112 "getPdPoolKea: malformed prefix '" << prefix <<
"'");
116 unsigned len = boost::lexical_cast<unsigned>(length);
118 }
catch (
const boost::bad_lexical_cast&) {
120 "getPdPoolKea: bad prefix length in '" << prefix <<
"'");
124 const string& xprefix = xpref->stringValue();
125 size_t xslash = xprefix.find(
"/");
126 if (xslash == string::npos) {
128 "getPdPoolKea: no '/' in excluded prefix '"
131 const string& xaddress = xprefix.substr(0, xslash);
132 const string& xlength = xprefix.substr(xslash + 1, string::npos);
133 if (xaddress.empty() || xlength.empty()) {
135 "getPdPoolKea: malformed excluded prefix '"
140 unsigned xlen = boost::lexical_cast<unsigned>(xlength);
141 result->set(
"excluded-prefix-len",
143 }
catch (
const boost::bad_lexical_cast&) {
145 "getPdPoolKea: bad excluded prefix length in '"
160 result->set(
"option-data", options);
163 return (result->empty() ?
ElementPtr() : result);
169 if (
model_ == IETF_DHCPV6_SERVER) {
171 }
else if (
model_ == KEA_DHCP6_SERVER) {
175 "setPdPool not implemented for the model: " <<
model_);
177 }
catch (Error
const& ex) {
179 "setting pd-pool '" << elem->str()
180 <<
"' : " << ex.
what());
188 if (!base || !length) {
190 "setPdPoolIetf6 requires prefix and prefix length: "
193 ostringstream prefix;
194 prefix << base->stringValue() <<
"/" << length->intValue();
196 setItem(xpath +
"/prefix-length", length, LeafBaseType::Uint8);
199 checkAndSetLeaf(elem, xpath,
"preferred-lifetime", LeafBaseType::Uint32);
229 if (xprefix && xlen) {
231 xpref << xprefix->stringValue() <<
"/" << xlen->intValue();
235 if (options && !options->empty()) {
250 if ((
model_ == IETF_DHCPV6_SERVER) ||
251 (
model_ == KEA_DHCP6_SERVER)) {
254 }
catch (Error
const& ex) {
260 "getPdPools not implemented for the model: " <<
model_);
281 if (
model_ == IETF_DHCPV6_SERVER) {
283 }
else if (
model_ == KEA_DHCP6_SERVER) {
287 "setPdPools not implemented for the model: " <<
model_);
289 }
catch (Error
const& ex) {
291 "setting pools '" << elem->str()
292 <<
"' : " << ex.
what());
298 for (
size_t i = 0; i < elem->size(); ++i) {
300 ostringstream prefix;
301 prefix << xpath <<
"/pd-pool[pool-id='" << i <<
"']";
309 for (
size_t i = 0; i < elem->size(); ++i) {
311 if (!pool->contains(
"prefix") || !pool->contains(
"prefix-len")) {
315 ostringstream prefix;
316 prefix << xpath <<
"/pd-pool[prefix='"
317 << pool->get(
"prefix")->stringValue() <<
"/"
318 << pool->get(
"prefix-len")->intValue() <<
"']";
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 ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
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.
void setPdPoolIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPool for ietf-dhcpv6-server.
isc::data::ElementPtr getPdPoolKea(libyang::DataNode const &data_node)
getPdPool for kea-dhcp6-server.
isc::data::ElementPtr getPdPoolFromAbsoluteXpath(std::string const &xpath)
Translate a pd-pool from YANG to JSON.
void setPdPool(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pool from JSON to YANG.
isc::data::ElementPtr getPdPoolIetf6(libyang::DataNode const &data_node)
getPdPool for ietf-dhcpv6-server.
void setPdPoolKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPool for kea-dhcp6-server.
isc::data::ElementPtr getPdPool(libyang::DataNode const &data_node)
Translate a pd-pool from YANG to JSON.
TranslatorPdPool(sysrepo::Session session, const std::string &model)
Constructor.
void setPdPoolsId(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPools using pool-id.
void setPdPoolsPrefix(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPools using prefix.
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 getPdPoolsFromAbsoluteXpath(std::string const &xpath)
Translate pd-pools from YANG to JSON.
isc::data::ElementPtr getPdPools(libyang::DataNode const &data_node)
Translate pd-pools from YANG to JSON.
isc::data::ElementPtr getPdPoolsCommon(libyang::DataNode const &data_node)
getPdPools common part.
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.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.