14#include <boost/lexical_cast.hpp>
20using namespace sysrepo;
37 if (
model_ == IETF_DHCPV6_SERVER) {
39 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
40 (
model_ == KEA_DHCP6_SERVER)) {
43 }
catch (
const sysrepo_exception& ex) {
45 "sysrepo error getting pool at '" << xpath
46 <<
"': " << ex.
what());
49 "getPool not implemented for the model: " <<
model_);
60 result->set(
"pool", pool);
64 result->set(
"client-class", guard);
68 result->set(
"valid-lifetime", valid_lifetime);
71 getItem(xpath +
"/preferred-lifetime");
72 if (preferred_lifetime) {
73 result->set(
"preferred-lifetime", preferred_lifetime);
77 result->set(
"renew-timer", renew_time);
81 result->set(
"rebind-timer", rebind_time);
87 if (result->empty()) {
98 result->set(
"pool", prefix);
102 if (!start_addr || !end_addr) {
104 "both start and end addresses at " << xpath);
107 range << start_addr->stringValue() <<
" - "
108 << end_addr->stringValue();
109 result->set(
"pool", Element::create(range.str()));
112 if (options && (options->size() > 0)) {
113 result->set(
"option-data", options);
117 result->set(
"client-class", guard);
120 if (required && (required->size() > 0)) {
121 result->set(
"require-client-classes", required);
125 result->set(
"user-context", Element::fromJSON(context->stringValue()));
133 if (
model_ == IETF_DHCPV6_SERVER) {
135 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
136 (
model_ == KEA_DHCP6_SERVER)) {
140 "setPool not implemented for the model: " <<
model_);
142 }
catch (
const sysrepo_exception& ex) {
144 "sysrepo error setting pool '" << elem->str()
145 <<
"' at '" << xpath <<
"': " << ex.
what());
155 string prefix = pool->stringValue();
156 if (prefix.find(
"/") == string::npos) {
158 "setPoolIetf only supports pools in prefix (vs range) "
159 "format and was called with '" << prefix <<
"'");
161 setItem(xpath +
"/pool-prefix", pool, SR_STRING_T);
162 string addr = prefix.substr(0, prefix.find_first_of(
" /"));
163 uint8_t plen = boost::lexical_cast<unsigned>
164 (prefix.substr(prefix.find_last_of(
" /") + 1, string::npos));
166 setItem(xpath +
"/start-address",
169 setItem(xpath +
"/end-address",
173 if (valid_lifetime) {
174 setItem(xpath +
"/valid-lifetime", valid_lifetime, SR_UINT32_T);
177 if (preferred_lifetime) {
178 setItem(xpath +
"/preferred-lifetime",
179 preferred_lifetime, SR_UINT32_T);
183 setItem(xpath +
"/renew-time", renew_timer, SR_UINT32_T);
187 setItem(xpath +
"/rebind-time", rebind_timer, SR_UINT32_T);
192 setItem(xpath +
"/client-class", guard, SR_STRING_T);
197 setItem(xpath +
"/max-address-count",
198 Element::create(
string(
"disabled")),
208 bool created =
false;
209 string prefix = pool->stringValue();
213 if (prefix.find(
"/") != string::npos) {
214 setItem(xpath +
"/prefix", pool, SR_STRING_T);
219 if (options && (options->size() > 0)) {
225 setItem(xpath +
"/client-class", guard, SR_STRING_T);
229 if (required && (required->size() > 0)) {
231 setItem(xpath +
"/require-client-classes", rclass, SR_STRING_T);
237 setItem(xpath +
"/user-context", Element::create(context->str()),
244 setItem(xpath, list, SR_LIST_T);
250 string& start_address,
string& end_address) {
251 size_t slash = prefix.find(
"/");
252 if (slash != string::npos) {
253 string addr = prefix.substr(0, prefix.find_first_of(
" /"));
254 uint8_t plen = boost::lexical_cast<unsigned>
255 (prefix.substr(prefix.find_last_of(
" /") + 1, string::npos));
260 size_t dash = prefix.find(
"-");
261 if (dash == string::npos) {
263 "getAddresses called with invalid prefix: " << prefix);
265 start_address = prefix.substr(0, prefix.find_first_of(
" -"));
266 end_address = prefix.substr(prefix.find_last_of(
" -") + 1, string::npos);
282 if (
model_ == IETF_DHCPV6_SERVER) {
284 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
285 (
model_ == KEA_DHCP6_SERVER)) {
288 }
catch (
const sysrepo_exception& ex) {
290 "sysrepo error getting pools at '" << xpath
291 <<
"': " << ex.
what());
294 "getPools not implemented for the model: " <<
model_);
299 return getList<TranslatorPool>(xpath +
"/address-pool", *
this,
305 return getList<TranslatorPool>(xpath +
"/pool", *
this,
312 if (
model_ == IETF_DHCPV6_SERVER) {
314 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
315 (
model_ == KEA_DHCP6_SERVER)) {
319 "setPools not implemented for the model: " <<
model_);
321 }
catch (
const sysrepo_exception& ex) {
323 "sysrepo error setting pools '" << elem->str()
324 <<
"' at '" << xpath <<
"': " << ex.
what());
330 for (
size_t i = 0; i < elem->size(); ++i) {
332 ostringstream prefix;
333 prefix << xpath <<
"/address-pool[pool-id='" << i <<
"']";
341 for (
size_t i = 0; i < elem->size(); ++i) {
343 if (!pool->contains(
"pool")) {
347 string pref = pool->get(
"pool")->stringValue();
351 ostringstream prefix;
352 prefix << xpath <<
"/pool[start-address='" << start_addr
353 <<
"'][end-address='" << end_addr <<
"']";
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.
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.
A translator class for converting a pool 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 getPool(const std::string &xpath)
Get and translate a pool from YANG to JSON.
virtual ~TranslatorPool()
Destructor.
TranslatorPool(sysrepo::S_Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getPoolKea(const std::string &xpath)
getPool for kea-dhcp[46]-server.
isc::data::ElementPtr getPoolIetf6(const std::string &xpath)
getPool for ietf-dhcpv6-server.
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.
isc::data::ElementPtr getPools(const std::string &xpath)
Get and translate pools from YANG to JSON.
void setPoolsByAddresses(const std::string &xpath, isc::data::ConstElementPtr elem)
setPools using address pair.
virtual ~TranslatorPools()
Destructor.
void setPoolsById(const std::string &xpath, isc::data::ConstElementPtr elem)
setPools using pool-id.
TranslatorPools(sysrepo::S_Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getPoolsKea(const std::string &xpath)
getPools for kea-dhcp[46]-server.
void setPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pools from JSON to YANG.
isc::data::ElementPtr getPoolsIetf(const std::string &xpath)
getPools for ietf-dhcpv6-server.
#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.