17using namespace sysrepo;
40 if (
model_ == IETF_DHCPV6_SERVER) {
42 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
43 (
model_ == KEA_DHCP6_SERVER)) {
46 }
catch (
const sysrepo_exception& ex) {
48 "sysrepo error getting subnet at '" << xpath
49 <<
"': " << ex.
what());
52 "getSubnet not implemented for the model: " <<
model_);
63 result->set(
"pools", pools);
66 if (pools && (pools->size() > 0)) {
67 result->set(
"pd-pools", pools);
73 result->set(
"subnet", subnet);
78 result->set(
"id",
id);
85 context->set(
"description", description);
86 result->set(
"user-context", context);
89 if (result->get(
"pools")) {
98 if (
model_ == KEA_DHCP6_SERVER) {
101 result->set(
"preferred-lifetime", preferred);
105 result->set(
"min-preferred-lifetime", min_pref);
109 result->set(
"max-preferred-lifetime", max_pref);
114 result->set(
"valid-lifetime", valid);
118 result->set(
"min-valid-lifetime", min_valid);
122 result->set(
"max-valid-lifetime", max_valid);
127 result->set(
"renew-timer", renew);
131 result->set(
"rebind-timer", rebind);
135 result->set(
"calculate-tee-times", calculate);
139 result->set(
"t1-percent", t1_percent);
143 result->set(
"t2-percent", t2_percent);
146 if (options && (options->size() > 0)) {
147 result->set(
"option-data", options);
150 if (pools && (pools->size() > 0)) {
151 result->set(
"pools", pools);
153 if (
model_ == KEA_DHCP6_SERVER) {
155 if (pools && (pools->size() > 0)) {
156 result->set(
"pd-pools", pools);
163 result->set(
"subnet", subnet);
166 result->set(
"interface", interface);
168 if (
model_ == KEA_DHCP6_SERVER) {
171 result->set(
"interface-id", interface_id);
178 result->set(
"id",
id);
179 if (
model_ == KEA_DHCP6_SERVER) {
182 result->set(
"rapid-commit", rapid_commit);
187 result->set(
"client-class", guard);
190 if (required && (required->size() > 0)) {
191 result->set(
"require-client-classes", required);
194 if (hosts && (hosts->size() > 0)) {
195 result->set(
"reservations", hosts);
199 result->set(
"reservation-mode", mode);
202 if (relay && (relay->size() > 0)) {
204 relay_map->set(
"ip-addresses", relay);
205 result->set(
"relay", relay_map);
207 if (
model_ == KEA_DHCP4_SERVER) {
210 result->set(
"match-client-id", match);
214 result->set(
"authoritative", auth);
218 result->set(
"next-server", next);
222 result->set(
"server-hostname", hostname);
226 result->set(
"boot-file-name", boot);
230 result->set(
"4o6-interface", s4o6_if);
234 result->set(
"4o6-interface-id", s4o6_id);
238 result->set(
"4o6-subnet", s4o6_sub);
243 result->set(
"user-context", Element::fromJSON(context->stringValue()));
251 if (
model_ == IETF_DHCPV6_SERVER) {
253 }
else if ((
model_ == KEA_DHCP4_SERVER) ||
254 (
model_ == KEA_DHCP6_SERVER)) {
258 "setSubnet not implemented for the model: " <<
model_);
260 }
catch (
const sysrepo_exception& ex) {
262 "sysrepo error setting subnet '" << elem->str()
263 <<
"' at '" << xpath <<
"': " << ex.
what());
272 if (context && context->contains(
"description")) {
274 if (description->getType() == Element::string) {
275 setItem(xpath +
"/network-description", description, SR_STRING_T);
282 setItem(xpath +
"/network-prefix", subnet, SR_STRING_T);
285 if (pools && (pools->size() > 0)) {
286 setPools(xpath +
"/address-pools", pools);
288 pools = elem->get(
"pd-pools");
289 if (pools && (pools->size() > 0)) {
298 if (
model_ == KEA_DHCP6_SERVER) {
301 setItem(xpath +
"/preferred-lifetime", preferred, SR_UINT32_T);
305 setItem(xpath +
"/min-preferred-lifetime", min_pref, SR_UINT32_T);
309 setItem(xpath +
"/max-preferred-lifetime", max_pref, SR_UINT32_T);
314 setItem(xpath +
"/valid-lifetime", valid, SR_UINT32_T);
318 setItem(xpath +
"/min-valid-lifetime", min_valid, SR_UINT32_T);
322 setItem(xpath +
"/max-valid-lifetime", max_valid, SR_UINT32_T);
326 setItem(xpath +
"/renew-timer", renew, SR_UINT32_T);
330 setItem(xpath +
"/rebind-timer", rebind, SR_UINT32_T);
334 setItem(xpath +
"/calculate-tee-times", calculate, SR_BOOL_T);
338 setItem(xpath +
"/t1-percent", t1_percent, SR_DECIMAL64_T);
342 setItem(xpath +
"/t2-percent", t2_percent, SR_DECIMAL64_T);
345 if (options && (options->size() > 0)) {
349 if (pools && (pools->size() > 0)) {
352 if (
model_ == KEA_DHCP6_SERVER) {
353 pools = elem->get(
"pd-pools");
354 if (pools && (pools->size() > 0)) {
362 setItem(xpath +
"/subnet", subnet, SR_STRING_T);
365 setItem(xpath +
"/interface", interface, SR_STRING_T);
367 if (
model_ == KEA_DHCP6_SERVER) {
370 setItem(xpath +
"/interface-id", interface_id, SR_STRING_T);
373 if (
model_ == KEA_DHCP6_SERVER) {
376 setItem(xpath +
"/rapid-commit", rapid_commit, SR_BOOL_T);
381 setItem(xpath +
"/client-class", guard, SR_STRING_T);
384 if (required && (required->size() > 0)) {
386 setItem(xpath +
"/require-client-classes", rclass, SR_STRING_T);
390 if (hosts && (hosts->size() > 0)) {
395 setItem(xpath +
"/reservation-mode", mode, SR_ENUM_T);
402 setItem(xpath +
"/relay/ip-addresses", address, SR_STRING_T);
403 }
else if (addresses && (addresses->size() > 0)) {
405 setItem(xpath +
"/relay/ip-addresses", addr, SR_STRING_T);
410 if (
model_ == KEA_DHCP4_SERVER) {
413 setItem(xpath +
"/match-client-id", match, SR_BOOL_T);
417 setItem(xpath +
"/authoritative", auth, SR_BOOL_T);
421 setItem(xpath +
"/next-server", next, SR_STRING_T);
425 setItem(xpath +
"/server-hostname", hostname, SR_STRING_T);
429 setItem(xpath +
"/boot-file-name", boot, SR_STRING_T);
433 setItem(xpath +
"/subnet-4o6-interface", s4o6_if, SR_STRING_T);
437 setItem(xpath +
"/subnet-4o6-interface-id", s4o6_id, SR_STRING_T);
441 setItem(xpath +
"/subnet-4o6-subnet", s4o6_subnet, SR_STRING_T);
447 setItem(xpath +
"/user-context", repr, SR_STRING_T);
470 if (
model_ == IETF_DHCPV6_SERVER) {
472 }
else if (
model_ == KEA_DHCP4_SERVER) {
474 }
else if (
model_ == KEA_DHCP6_SERVER) {
477 }
catch (
const sysrepo_exception& ex) {
479 "sysrepo error getting subnets at '" << xpath
480 <<
"': " << ex.
what());
483 "getSubnets not implemented for the model: " <<
model_);
488 const std::string& subsel) {
489 return getList<TranslatorSubnet>(xpath +
"/" + subsel, *
this,
496 if (
model_ == IETF_DHCPV6_SERVER) {
498 }
else if (
model_ == KEA_DHCP4_SERVER) {
500 }
else if (
model_ == KEA_DHCP6_SERVER) {
504 "setSubnets not implemented for the model: " <<
model_);
506 }
catch (
const sysrepo_exception& ex) {
508 "sysrepo error setting subnets '" << elem->str()
509 <<
"' at '" << xpath <<
"': " << ex.
what());
515 for (
size_t i = 0; i < elem->size(); ++i) {
518 range << xpath <<
"/network-range[network-range-id='";
523 range <<
id->intValue() <<
"']";
530 const std::string& subsel) {
531 for (
size_t i = 0; i < elem->size(); ++i) {
533 if (!subnet->contains(
"id")) {
536 ostringstream prefix;
537 prefix << xpath <<
"/" << subsel <<
"[id='"
538 << subnet->get(
"id")->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 void toSubnet(const std::string &model, isc::data::ElementPtr subnet, isc::data::ConstElementPtr pools)
Move parameters from pools to the subnet.
static void fromSubnet(const std::string &model, isc::data::ConstElementPtr subnet, isc::data::ConstElementPtr pools)
Moves parameters from subnets to pools.
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.
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, sr_type_t const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
Translation between YANG and JSON for a single host reservation.
A translator class for converting host reservations list between YANG and JSON.
isc::data::ElementPtr getHosts(const std::string &xpath)
Get and translate host reservations from YANG to JSON.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.
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.
A translator class for converting a pd-pool list between YANG and JSON.
void setPdPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set pd-pools from JSON to YANG.
isc::data::ElementPtr getPdPools(const std::string &xpath)
Get and translate pd-pools from YANG to JSON.
A translator class for converting a pool between YANG and JSON.
A translator class for converting pools between YANG and JSON.
isc::data::ElementPtr getPools(const std::string &xpath)
Get and translate pools from YANG to JSON.
void setPools(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) pools from JSON to YANG.
Subnet (aka network range) translation between YANG and JSON.
virtual ~TranslatorSubnet()
Destructor.
void setSubnetIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for ietf-dhcpv6-server.
TranslatorSubnet(sysrepo::S_Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getSubnet(const std::string &xpath)
Get and translate a subnet from YANG to JSON.
void setSubnet(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnet from JSON to YANG.
isc::data::ElementPtr getSubnetIetf6(const std::string &xpath)
getSubnet for ietf-dhcpv6-server.
void setSubnetKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnet for kea-dhcp[46]-server.
isc::data::ElementPtr getSubnetKea(const std::string &xpath)
getSubnet for kea-dhcp[46]-server.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
void setSubnetsKea(const std::string &xpath, isc::data::ConstElementPtr elem, const std::string &subsel)
setSubnets for kea-dhcp[46]-server.
isc::data::ElementPtr getSubnets(const std::string &xpath)
Get and translate subnets from YANG to JSON.
void setSubnetsIetf6(const std::string &xpath, isc::data::ConstElementPtr elem)
setSubnets for ietf-dhcpv6-server.
TranslatorSubnets(sysrepo::S_Session session, const std::string &model)
Constructor.
virtual ~TranslatorSubnets()
Destructor.
isc::data::ElementPtr getSubnetsCommon(const std::string &xpath, const std::string &subsel)
getSubnets common part.
#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.