12#include <boost/lexical_cast.hpp>
17using namespace sysrepo;
34 if (
model_ == IETF_DHCPV6_SERVER) {
36 }
else if (
model_ == KEA_DHCP6_SERVER) {
39 }
catch (
const sysrepo_exception& ex) {
41 "sysrepo error getting pd-pool at '" << xpath
42 <<
"': " << ex.
what());
45 "getPdPool not implemented for the model: " <<
model_);
55 const string& prefix = pref->stringValue();
56 size_t slash = prefix.find(
"/");
57 if (slash == string::npos) {
59 "getPdPoolIetf6: no '/' in prefix '" << prefix <<
"'");
61 const string& address = prefix.substr(0, slash);
62 if (address.empty()) {
64 "getPdPoolIetf6: malformed prefix '" << prefix <<
"'");
66 result->set(
"prefix", Element::create(address));
72 result->set(
"prefix-len", preflen);
75 result->set(
"valid-lifetime", valid_lifetime);
78 getItem(xpath +
"/preferred-lifetime");
79 if (preferred_lifetime) {
80 result->set(
"preferred-lifetime", preferred_lifetime);
84 result->set(
"renew-timer", renew_time);
88 result->set(
"rebind-timer", rebind_time);
93 result->set(
"client-class", guard);
108 const string& prefix = pref->stringValue();
109 size_t slash = prefix.find(
"/");
110 if (slash == string::npos) {
112 "getPdPoolKea: no '/' in prefix '" << prefix <<
"'");
114 const string& address = prefix.substr(0, slash);
115 const string& length = prefix.substr(slash + 1, string::npos);
116 if (address.empty() || length.empty()) {
118 "getPdPoolKea: malformed prefix '" << prefix <<
"'");
120 result->set(
"prefix", Element::create(address));
122 unsigned len = boost::lexical_cast<unsigned>(length);
123 result->set(
"prefix-len", Element::create(
static_cast<int>(len)));
124 }
catch (
const boost::bad_lexical_cast&) {
126 "getPdPoolKea: bad prefix length in '" << prefix <<
"'");
131 const string& xprefix = xpref->stringValue();
132 size_t xslash = xprefix.find(
"/");
133 if (xslash == string::npos) {
135 "getPdPoolKea: no '/' in excluded prefix '"
138 const string& xaddress = xprefix.substr(0, xslash);
139 const string& xlength = xprefix.substr(xslash + 1, string::npos);
140 if (xaddress.empty() || xlength.empty()) {
142 "getPdPoolKea: malformed excluded prefix '"
145 result->set(
"excluded-prefix", Element::create(xaddress));
147 unsigned xlen = boost::lexical_cast<unsigned>(xlength);
148 result->set(
"excluded-prefix-len",
149 Element::create(
static_cast<int>(xlen)));
150 }
catch (
const boost::bad_lexical_cast&) {
152 "getPdPoolKea: bad excluded prefix length in '"
159 result->set(
"delegated-len", delegated);
162 if (options && (options->size() > 0)) {
163 result->set(
"option-data", options);
167 result->set(
"client-class", guard);
170 if (required && (required->size() > 0)) {
171 result->set(
"require-client-classes", required);
175 result->set(
"user-context", Element::fromJSON(context->stringValue()));
183 if (
model_ == IETF_DHCPV6_SERVER) {
185 }
else if (
model_ == KEA_DHCP6_SERVER) {
189 "setPdPool not implemented for the model: " <<
model_);
191 }
catch (
const sysrepo_exception& ex) {
193 "sysrepo error setting pd-pool '" << elem->str()
194 <<
"' at '" << xpath <<
"': " << ex.
what());
202 if (!base || !length) {
204 "setPdPoolIetf6 requires prefix and prefix length: "
207 ostringstream prefix;
208 prefix << base->stringValue() <<
"/" << length->intValue();
209 setItem(xpath +
"/prefix", Element::create(prefix.str()), SR_STRING_T);
210 setItem(xpath +
"/prefix-length", length, SR_UINT8_T);
212 if (valid_lifetime) {
213 setItem(xpath +
"/valid-lifetime", valid_lifetime, SR_UINT32_T);
216 if (preferred_lifetime) {
217 setItem(xpath +
"/preferred-lifetime",
218 preferred_lifetime, SR_UINT32_T);
222 setItem(xpath +
"/renew-time", renew_timer, SR_UINT32_T);
226 setItem(xpath +
"/rebind-time", rebind_timer, SR_UINT32_T);
231 setItem(xpath +
"/client-class", guard, SR_STRING_T);
234 setItem(xpath +
"/max-pd-space-utilization",
235 Element::create(
string(
"disabled")),
243 bool created =
false;
246 setItem(xpath +
"/delegated-len", delegated, SR_UINT8_T);
250 if (xprefix && xlen) {
252 xpref << xprefix->stringValue() <<
"/" << xlen->intValue();
253 setItem(xpath +
"/excluded-prefix", Element::create(xpref.str()),
258 if (options && (options->size() > 0)) {
264 setItem(xpath +
"/client-class", guard, SR_STRING_T);
268 if (required && (required->size() > 0)) {
270 setItem(xpath +
"/require-client-classes", rclass, SR_STRING_T);
276 setItem(xpath +
"/user-context", Element::create(context->str()),
283 setItem(xpath, list, SR_LIST_T);
300 if ((
model_ == IETF_DHCPV6_SERVER) ||
301 (
model_ == KEA_DHCP6_SERVER)) {
304 }
catch (
const sysrepo_exception& ex) {
306 "sysrepo error getting pd-pools at '" << xpath
307 <<
"': " << ex.
what());
310 "getPdPools not implemented for the model: " <<
model_);
315 return getList<TranslatorPdPool>(xpath +
"/pd-pool", *
this,
322 if (
model_ == IETF_DHCPV6_SERVER) {
324 }
else if (
model_ == KEA_DHCP6_SERVER) {
328 "setPdPools not implemented for the model: " <<
model_);
330 }
catch (
const sysrepo_exception& ex) {
332 "sysrepo error setting pools '" << elem->str()
333 <<
"' at '" << xpath <<
"': " << ex.
what());
339 for (
size_t i = 0; i < elem->size(); ++i) {
341 ostringstream prefix;
342 prefix << xpath <<
"/pd-pool[pool-id='" << i <<
"']";
350 for (
size_t i = 0; i < elem->size(); ++i) {
352 if (!pool->contains(
"prefix") || !pool->contains(
"prefix-len")) {
356 ostringstream prefix;
357 prefix << xpath <<
"/pd-pool[prefix='"
358 << pool->get(
"prefix")->stringValue() <<
"/"
359 << 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 isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
Between YANG and JSON translator class for basic values.
isc::data::ElementPtr getItem(const std::string &xpath)
Get and translate basic value from YANG to JSON.
std::string model_
The model.
void setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
A translator class for converting an option data list between YANG and JSON.
isc::data::ConstElementPtr getOptionDataList(const std::string &xpath)
Get and 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.
Option data translation between YANG and JSON.
Prefix delegation pool translation between YANG and JSON.
TranslatorPdPool(sysrepo::S_Session session, const std::string &model)
Constructor.
void setPdPoolIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPool for ietf-dhcpv6-server.
virtual ~TranslatorPdPool()
Destructor.
isc::data::ElementPtr getPdPool(const std::string &xpath)
Get and translate a pd-pool from YANG to JSON.
isc::data::ElementPtr getPdPoolKea(const std::string &xpath)
getPdPool for kea-dhcp6-server.
void setPdPool(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pool from JSON to YANG.
void setPdPoolKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPool for kea-dhcp6-server.
isc::data::ElementPtr getPdPoolIetf6(const std::string &xpath)
getPdPool for ietf-dhcpv6-server.
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.
void setPdPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pools from JSON to YANG.
isc::data::ElementPtr getPdPoolsCommon(const std::string &xpath)
getPdPools common part.
isc::data::ElementPtr getPdPools(const std::string &xpath)
Get and translate pd-pools from YANG to JSON.
virtual ~TranslatorPdPools()
Destructor.
TranslatorPdPools(sysrepo::S_Session session, const std::string &model)
Constructor.
#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.