12 #include <boost/lexical_cast.hpp>
17 #ifndef HAVE_PRE_0_7_6_SYSREPO
24 TranslatorPdPool::TranslatorPdPool(S_Session session,
const string& model)
36 if (
model_ == IETF_DHCPV6_SERVER) {
38 }
else if (
model_ == KEA_DHCP6_SERVER) {
41 }
catch (
const sysrepo_exception& ex) {
43 "sysrepo error getting pd-pool at '" << xpath
44 <<
"': " << ex.
what());
47 "getPdPool not implemented for the model: " <<
model_);
57 const string& prefix = pref->stringValue();
58 size_t slash = prefix.find(
"/");
59 if (slash == string::npos) {
61 "getPdPoolIetf6: no '/' in prefix '" << prefix <<
"'");
63 const string& address = prefix.substr(0, slash);
64 if (address.empty()) {
66 "getPdPoolIetf6: malformed prefix '" << prefix <<
"'");
68 result->set(
"prefix", Element::create(address));
74 result->set(
"prefix-len", preflen);
77 result->set(
"valid-lifetime", valid_lifetime);
80 getItem(xpath +
"/preferred-lifetime");
81 if (preferred_lifetime) {
82 result->set(
"preferred-lifetime", preferred_lifetime);
86 result->set(
"renew-timer", renew_time);
90 result->set(
"rebind-timer", rebind_time);
95 result->set(
"client-class", guard);
110 const string& prefix = pref->stringValue();
111 size_t slash = prefix.find(
"/");
112 if (slash == string::npos) {
114 "getPdPoolKea: no '/' in prefix '" << prefix <<
"'");
116 const string& address = prefix.substr(0, slash);
117 const string& length = prefix.substr(slash + 1, string::npos);
118 if (address.empty() || length.empty()) {
120 "getPdPoolKea: malformed prefix '" << prefix <<
"'");
122 result->set(
"prefix", Element::create(address));
124 unsigned len = boost::lexical_cast<
unsigned>(length);
125 result->set(
"prefix-len", Element::create(static_cast<int>(len)));
126 }
catch (
const boost::bad_lexical_cast&) {
128 "getPdPoolKea: bad prefix length in '" << prefix <<
"'");
133 const string& xprefix = xpref->stringValue();
134 size_t xslash = xprefix.find(
"/");
135 if (xslash == string::npos) {
137 "getPdPoolKea: no '/' in excluded prefix '"
140 const string& xaddress = xprefix.substr(0, xslash);
141 const string& xlength = xprefix.substr(xslash + 1, string::npos);
142 if (xaddress.empty() || xlength.empty()) {
144 "getPdPoolKea: malformed excluded prefix '"
147 result->set(
"excluded-prefix", Element::create(xaddress));
149 unsigned xlen = boost::lexical_cast<
unsigned>(xlength);
150 result->set(
"excluded-prefix-len",
151 Element::create(static_cast<int>(xlen)));
152 }
catch (
const boost::bad_lexical_cast&) {
154 "getPdPoolKea: bad excluded prefix length in '"
161 result->set(
"delegated-len", delegated);
164 if (options && (options->size() > 0)) {
165 result->set(
"option-data", options);
169 result->set(
"client-class", guard);
172 if (required && (required->size() > 0)) {
173 result->set(
"require-client-classes", required);
177 result->set(
"user-context", Element::fromJSON(context->stringValue()));
185 if (
model_ == IETF_DHCPV6_SERVER) {
187 }
else if (
model_ == KEA_DHCP6_SERVER) {
191 "setPdPool not implemented for the model: " <<
model_);
193 }
catch (
const sysrepo_exception& ex) {
195 "sysrepo error setting pd-pool '" << elem->str()
196 <<
"' at '" << xpath <<
"': " << ex.
what());
204 if (!base || !length) {
206 "setPdPoolIetf6 requires prefix and prefix length: "
209 ostringstream prefix;
210 prefix << base->stringValue() <<
"/" << length->intValue();
211 setItem(xpath +
"/prefix", Element::create(prefix.str()), SR_STRING_T);
212 setItem(xpath +
"/prefix-length", length, SR_UINT8_T);
214 if (valid_lifetime) {
215 setItem(xpath +
"/valid-lifetime", valid_lifetime, SR_UINT32_T);
218 if (preferred_lifetime) {
219 setItem(xpath +
"/preferred-lifetime",
220 preferred_lifetime, SR_UINT32_T);
224 setItem(xpath +
"/renew-time", renew_timer, SR_UINT32_T);
228 setItem(xpath +
"/rebind-time", rebind_timer, SR_UINT32_T);
233 setItem(xpath +
"/client-class", guard, SR_STRING_T);
236 setItem(xpath +
"/max-pd-space-utilization",
237 Element::create(
string(
"disabled")),
245 bool created =
false;
248 setItem(xpath +
"/delegated-len", delegated, SR_UINT8_T);
252 if (xprefix && xlen) {
254 xpref << xprefix->stringValue() <<
"/" << xlen->intValue();
255 setItem(xpath +
"/excluded-prefix", Element::create(xpref.str()),
260 if (options && (options->size() > 0)) {
266 setItem(xpath +
"/client-class", guard, SR_STRING_T);
270 if (required && (required->size() > 0)) {
272 setItem(xpath +
"/require-client-classes", rclass, SR_STRING_T);
278 setItem(xpath +
"/user-context", Element::create(context->str()),
285 setItem(xpath, list, SR_LIST_T);
302 if ((
model_ == IETF_DHCPV6_SERVER) ||
303 (
model_ == KEA_DHCP6_SERVER)) {
306 }
catch (
const sysrepo_exception& ex) {
308 "sysrepo error getting pd-pools at '" << xpath
309 <<
"': " << ex.
what());
312 "getPdPools not implemented for the model: " <<
model_);
318 S_Iter_Value iter =
getIter(xpath +
"/pd-pool");
324 const string& pool =
getNext(iter);
336 if (
model_ == IETF_DHCPV6_SERVER) {
338 }
else if (
model_ == KEA_DHCP6_SERVER) {
342 "setPdPools not implemented for the model: " <<
model_);
344 }
catch (
const sysrepo_exception& ex) {
346 "sysrepo error setting pools '" << elem->str()
347 <<
"' at '" << xpath <<
"': " << ex.
what());
353 for (
size_t i = 0; i < elem->size(); ++i) {
355 ostringstream prefix;
356 prefix << xpath <<
"/pd-pool[pool-id='" << i <<
"']";
364 for (
size_t i = 0; i < elem->size(); ++i) {
366 if (!pool->contains(
"prefix") || !pool->contains(
"prefix-len")) {
370 ostringstream prefix;
371 prefix << xpath <<
"/pd-pool[prefix='"
372 << pool->get(
"prefix")->stringValue() <<
"/"
373 << pool->get(
"prefix-len")->intValue() <<
"']";
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
A generic exception that is thrown when a function is not implemented.
isc::data::ElementPtr getPdPoolsCommon(const std::string &xpath)
getPdPools common part.
Between YANG and JSON translator class for basic values.
void setPdPool(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pool from JSON to YANG.
boost::shared_ptr< Element > ElementPtr
TranslatorPdPools(sysrepo::S_Session session, const std::string &model)
Constructor.
virtual ~TranslatorPdPool()
Destructor.
virtual ~TranslatorPdPools()
Destructor.
isc::data::ElementPtr getPdPools(const std::string &xpath)
Get and translate pd-pools from YANG to JSON.
sysrepo::S_Iter_Value getIter(const std::string &xpath)
List iterator methods keeping the session private.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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 getPdPoolIetf6(const std::string &xpath)
getPdPool for ietf-dhcpv6-server.
A translator class for converting an option data list between YANG and JSON.
A generic exception that is thrown when an unexpected error condition occurs.
std::string model_
The model.
isc::data::ElementPtr getPdPool(const std::string &xpath)
Get and translate a pd-pool from YANG to JSON.
boost::shared_ptr< const Element > ConstElementPtr
std::string getNext(sysrepo::S_Iter_Value iter)
Get xpath of the next YANG list item.
void setPdPoolsId(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPools using pool-id.
void setPdPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pools from JSON to YANG.
static isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Defines the logger used by the top-level component of kea-dhcp-ddns.
isc::data::ConstElementPtr getOptionDataList(const std::string &xpath)
Get and translate option data list from YANG to JSON.
void setPdPoolIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPool for ietf-dhcpv6-server.
isc::data::ElementPtr getItem(const std::string &xpath)
Get and translate basic value from YANG to JSON.
Prefix delegation pool translation between YANG and JSON.
isc::data::ElementPtr getPdPoolKea(const std::string &xpath)
getPdPool for kea-dhcp6-server.
Option data translation between YANG and JSON.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
void setPdPoolsPrefix(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPools using prefix.
void setPdPoolKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setPdPool for kea-dhcp6-server.