17using namespace libyang;
18using namespace sysrepo;
51 if (
model_ == IETF_DHCPV6_SERVER) {
53 }
else if (
model_ == KEA_DHCP4_SERVER) {
55 }
else if (
model_ == KEA_DHCP6_SERVER) {
58 }
catch (Error
const& ex) {
62 "getConfig not implemented for the model: " <<
model_);
69 result->set(
"Dhcp6", dhcp6);
70 string const xpath(
"/ietf-dhcpv6-server:server");
79 [&](DataNode
const& data_node) ->
ElementPtr const {
91 result->set(
"Dhcp4",
dhcp);
99 result->set(
"Dhcp6",
dhcp);
126 return (result->empty() ?
ElementPtr() : result);
144 return (result->empty() ?
ElementPtr() : result);
152 if (databases && !databases->empty()) {
153 result->set(
"config-databases", databases);
155 return (result->empty() ?
ElementPtr() : result);
161 optional<DataNode>
const& interfaces_config_optional(
config.findPath(
"interfaces-config"));
162 if (interfaces_config_optional) {
163 DataNode
const interfaces_config(*interfaces_config_optional);
170 checkAndGetLeaf(result, interfaces_config,
"service-sockets-max-retries");
171 checkAndGetLeaf(result, interfaces_config,
"service-sockets-require-all");
172 checkAndGetLeaf(result, interfaces_config,
"service-sockets-retry-wait-time");
176 return (result->empty() ?
ElementPtr() : result);
202 checkAndGetLeaf(result, data_node,
"early-global-reservations-lookup");
229 if (classes && !classes->empty()) {
230 result->set(
"client-classes", classes);
234 [&](DataNode
const& node) ->
ElementPtr const {
238 return compatibility;
242 [&](DataNode
const& node) ->
ElementPtr const {
247 if (control_sockets && !control_sockets->empty()) {
248 result->set(
"control-sockets", control_sockets);
251 [&](DataNode
const& node) ->
ElementPtr const {
257 [&](DataNode
const& node) ->
ElementPtr const {
261 checkAndGet(result, data_node,
"expired-leases-processing",
262 [&](DataNode
const& node) ->
ElementPtr const {
268 result->set(
"hooks-libraries",
hooks);
272 if (hosts_databases && !hosts_databases->empty()) {
273 result->set(
"hosts-databases", hosts_databases);
277 [&](DataNode
const& node) ->
ElementPtr const {
282 if (loggers && !loggers->empty()) {
283 result->set(
"loggers", loggers);
287 [&](DataNode
const& node) ->
ElementPtr const {
292 return multi_threading;
297 result->set(
"option-data", options);
302 result->set(
"option-def", defs);
307 result->set(
"reservations", hosts);
312 result->set(
"shared-networks", networks);
316 [&](DataNode
const& node) ->
ElementPtr const {
320 return sanity_checks;
328 string xpath =
"/kea-dhcp4-server:config";
329 optional<DataNode> config_optional;
335 DataNode
const config(*config_optional);
349 [&](DataNode
const& node) ->
ElementPtr const {
353 if (const_compatibility) {
354 compatibility =
copy(const_compatibility);
361 return compatibility;
366 if (interfaces_config) {
367 result->set(
"interfaces-config", interfaces_config);
373 result->set(
"subnet4", subnets);
381 string xpath =
"/kea-dhcp6-server:config";
382 optional<DataNode> config_optional;
388 DataNode
const config(*config_optional);
403 if (interfaces_config) {
404 result->set(
"interfaces-config", interfaces_config);
408 optional<DataNode>
const& server_id_optional(
config.findPath(
"server-id"));
409 if (server_id_optional) {
410 DataNode
const server_id(*server_id_optional);
419 if (!server_id_map->empty()) {
420 result->set(
"server-id", server_id_map);
427 result->set(
"subnet6", subnets);
436 if (
model_ == IETF_DHCPV6_SERVER) {
443 }
else if (
model_ == KEA_DHCP4_SERVER) {
450 }
else if (
model_ == KEA_DHCP6_SERVER) {
459 "setConfig not implemented for the model: " <<
model_);
461 }
catch (Error
const& ex) {
463 "setting config '" << elem->str()
464 <<
"': " << ex.
what());
475 string xpath =
"/" +
model_ +
":server/server-config";
482 if (ranges && !ranges->empty()) {
483 setSubnets(xpath +
"/network-ranges", ranges);
516 checkAndSetLeaf(elem, xpath,
"calculate-tee-times", LeafBaseType::Bool);
517 checkAndSetLeaf(elem, xpath,
"ddns-generated-prefix", LeafBaseType::String);
518 checkAndSetLeaf(elem, xpath,
"ddns-override-client-update", LeafBaseType::Bool);
519 checkAndSetLeaf(elem, xpath,
"ddns-override-no-update", LeafBaseType::Bool);
520 checkAndSetLeaf(elem, xpath,
"ddns-qualifying-suffix", LeafBaseType::String);
521 checkAndSetLeaf(elem, xpath,
"ddns-replace-client-name", LeafBaseType::String);
527 checkAndSetLeaf(elem, xpath,
"ddns-update-on-renew", LeafBaseType::Bool);
528 checkAndSetLeaf(elem, xpath,
"ddns-use-conflict-resolution", LeafBaseType::Bool);
529 checkAndSetLeaf(elem, xpath,
"ddns-conflict-resolution-mode", LeafBaseType::Enum);
531 checkAndSetLeaf(elem, xpath,
"decline-probation-period", LeafBaseType::Uint32);
532 checkAndSetLeaf(elem, xpath,
"early-global-reservations-lookup", LeafBaseType::Bool);
533 checkAndSetLeaf(elem, xpath,
"hostname-char-replacement", LeafBaseType::String);
534 checkAndSetLeaf(elem, xpath,
"hostname-char-set", LeafBaseType::String);
535 checkAndSetLeaf(elem, xpath,
"ip-reservations-unique", LeafBaseType::Bool);
536 checkAndSetLeaf(elem, xpath,
"max-valid-lifetime", LeafBaseType::Uint32);
537 checkAndSetLeaf(elem, xpath,
"min-valid-lifetime", LeafBaseType::Uint32);
538 checkAndSetLeaf(elem, xpath,
"parked-packet-limit", LeafBaseType::Uint32);
541 checkAndSetLeaf(elem, xpath,
"reservations-global", LeafBaseType::Bool);
542 checkAndSetLeaf(elem, xpath,
"reservations-in-subnet", LeafBaseType::Bool);
543 checkAndSetLeaf(elem, xpath,
"reservations-lookup-first", LeafBaseType::Bool);
544 checkAndSetLeaf(elem, xpath,
"reservations-out-of-pool", LeafBaseType::Bool);
546 checkAndSetLeaf(elem, xpath,
"statistic-default-sample-age", LeafBaseType::Uint32);
547 checkAndSetLeaf(elem, xpath,
"statistic-default-sample-count", LeafBaseType::Uint32);
548 checkAndSetLeaf(elem, xpath,
"store-extended-info", LeafBaseType::Bool);
552 checkAndSetLeaf(elem, xpath,
"adaptive-lease-time-threshold", LeafBaseType::Dec64);
561 if (classes && !classes->empty()) {
567 checkAndSetLeaf(compatibility, xpath +
"/compatibility",
"ignore-rai-link-selection", LeafBaseType::Bool);
568 checkAndSetLeaf(compatibility, xpath +
"/compatibility",
"lenient-option-parsing", LeafBaseType::Bool);
572 if (config_ctrl && !config_ctrl->empty()) {
573 checkAndSetLeaf(config_ctrl, xpath +
"/config-control",
"config-fetch-wait-time", LeafBaseType::Uint32);
574 ConstElementPtr config_databases = config_ctrl->get(
"config-databases");
575 if (config_databases && !config_databases->empty()) {
576 setDatabases(xpath +
"/config-control/config-database", config_databases);
581 if (control_sockets && !control_sockets->empty()) {
585 if (control_socket && !control_socket->empty()) {
592 string const ddns_xpath(xpath +
"/dhcp-ddns");
593 checkAndSetLeaf(ddns, ddns_xpath,
"enable-updates", LeafBaseType::Bool);
594 checkAndSetLeaf(ddns, ddns_xpath,
"max-queue-size", LeafBaseType::Uint32);
598 checkAndSetLeaf(ddns, ddns_xpath,
"sender-port", LeafBaseType::Uint16);
600 checkAndSetLeaf(ddns, ddns_xpath,
"server-port", LeafBaseType::Uint16);
606 string const expired_xpath(xpath +
"/expired-leases-processing");
607 checkAndSetLeaf(expired, expired_xpath,
"flush-reclaimed-timer-wait-time", LeafBaseType::Uint32);
608 checkAndSetLeaf(expired, expired_xpath,
"hold-reclaimed-time", LeafBaseType::Uint32);
609 checkAndSetLeaf(expired, expired_xpath,
"max-reclaim-leases", LeafBaseType::Uint32);
610 checkAndSetLeaf(expired, expired_xpath,
"max-reclaim-time", LeafBaseType::Uint32);
611 checkAndSetLeaf(expired, expired_xpath,
"reclaim-timer-wait-time", LeafBaseType::Uint32);
612 checkAndSetLeaf(expired, expired_xpath,
"unwarned-reclaim-cycles", LeafBaseType::Uint32);
617 for (
ElementPtr const& lib : hook_libs->listValue()) {
622 ostringstream hook_lib;
623 hook_lib << xpath <<
"/hook-library[library='"
624 << name->stringValue() <<
"']";
625 string const hook_xpath(hook_lib.str());
632 if (hosts_databases && !hosts_databases->empty()) {
633 setDatabases(xpath +
"/hosts-database", hosts_databases);
637 if (database && !database->empty()) {
638 setDatabase(xpath +
"/lease-database", database,
false);
647 if (multi_threading) {
648 string const mt_xpath(xpath +
"/multi-threading");
649 checkAndSetLeaf(multi_threading, mt_xpath,
"enable-multi-threading", LeafBaseType::Bool);
650 checkAndSetLeaf(multi_threading, mt_xpath,
"packet-queue-size", LeafBaseType::Uint32);
651 checkAndSetLeaf(multi_threading, mt_xpath,
"thread-pool-size", LeafBaseType::Uint32);
655 if (options && !options->empty()) {
660 if (defs && !defs->empty()) {
665 if (hosts && !hosts->empty()) {
671 checkAndSetLeaf(sanity, xpath +
"/sanity-checks",
"extended-info-checks", LeafBaseType::Enum);
672 checkAndSetLeaf(sanity, xpath +
"/sanity-checks",
"lease-checks", LeafBaseType::Enum);
676 if (networks && !networks->empty()) {
683 string xpath =
"/kea-dhcp4-server:config";
694 checkAndSetLeaf(elem, xpath,
"stash-agent-options", LeafBaseType::Bool);
698 checkAndSetLeaf(compatibility, xpath +
"/compatibility",
"exclude-first-last-24", LeafBaseType::Bool);
699 checkAndSetLeaf(compatibility, xpath +
"/compatibility",
"ignore-dhcp-server-identifier", LeafBaseType::Bool);
704 string const if_cfg_xpath(xpath +
"/interfaces-config");
705 checkAndSetLeaf(if_config, if_cfg_xpath,
"dhcp-socket-type", LeafBaseType::Enum);
706 checkAndSetLeaf(if_config, if_cfg_xpath,
"outbound-interface", LeafBaseType::Enum);
707 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-max-retries", LeafBaseType::Uint32);
708 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-require-all", LeafBaseType::Bool);
709 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-retry-wait-time", LeafBaseType::Uint32);
710 checkAndSetLeaf(if_config, if_cfg_xpath,
"re-detect", LeafBaseType::Bool);
723 string xpath =
"/kea-dhcp6-server:config";
728 checkAndSetLeaf(elem, xpath,
"max-preferred-lifetime", LeafBaseType::Uint32);
729 checkAndSetLeaf(elem, xpath,
"min-preferred-lifetime", LeafBaseType::Uint32);
731 checkAndSetLeaf(elem, xpath,
"preferred-lifetime", LeafBaseType::Uint32);
732 checkAndSetLeaf(elem, xpath,
"allow-address-registration", LeafBaseType::Bool);
738 string const if_cfg_xpath(xpath +
"/interfaces-config");
739 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-max-retries", LeafBaseType::Uint32);
740 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-require-all", LeafBaseType::Bool);
741 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-retry-wait-time", LeafBaseType::Uint32);
742 checkAndSetLeaf(if_config, if_cfg_xpath,
"re-detect", LeafBaseType::Bool);
749 string const srv_id_xpath(xpath +
"/server-id");
751 checkAndSetLeaf(server_id, srv_id_xpath,
"identifier", LeafBaseType::String);
752 checkAndSetLeaf(server_id, srv_id_xpath,
"time", LeafBaseType::Uint32);
753 checkAndSetLeaf(server_id, srv_id_xpath,
"htype", LeafBaseType::Uint16);
754 checkAndSetLeaf(server_id, srv_id_xpath,
"enterprise-id", LeafBaseType::Uint32);
755 checkAndSetLeaf(server_id, srv_id_xpath,
"persist", LeafBaseType::Bool);
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
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 preProcess4(isc::data::ElementPtr config)
Pre process a DHCPv4 configuration.
static void preProcess6(isc::data::ElementPtr config)
Pre process a DHCPv6 configuration.
Client class translation between YANG and JSON.
isc::data::ElementPtr getClasses(libyang::DataNode const &data_node)
Translate client classes from YANG to JSON.
void setClasses(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set client classes from JSON to YANG.
TranslatorClasses(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getConfigKea4()
getConfig for kea-dhcp4-server.
isc::data::ElementPtr getHook(libyang::DataNode const &data_node)
void setServerKeaDhcpCommon(const std::string &xpath, isc::data::ConstElementPtr elem)
setServer common part for kea-dhcp[46]-server:config.
void delConfigKea()
delConfig for kea-dhcp[46]-server.
isc::data::ElementPtr getExpiredKea(libyang::DataNode const &data_node)
Retrieves expired leases processing parameters from sysrepo.
isc::data::ElementPtr getServerKeaDhcp4()
getServer for kea-dhcp4-server:config.
void setConfigKea6(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp6-server.
TranslatorConfig(sysrepo::Session session, const std::string &model)
Constructor.
void setConfigIetf6(isc::data::ConstElementPtr elem)
setConfig for ietf-dhcpv6-server.
isc::data::ElementPtr getDdnsKea(libyang::DataNode const &data_node)
Retrieves DDNS configuration from sysrepo.
isc::data::ElementPtr getInterfacesKea(libyang::DataNode const &data_node)
Retrieves interfaces configuration from sysrepo.
void setConfigKea4(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp[46]-server.
void setConfig(isc::data::ElementPtr elem)
Translate and set the DHCP server configuration from JSON to YANG.
isc::data::ElementPtr getConfigControlKea(libyang::DataNode const &data_node)
Retrieves configuration control from sysrepo.
void setServerKeaDhcp6(isc::data::ConstElementPtr elem)
setServer for kea-dhcp6-server:config.
isc::data::ElementPtr getConfigKea6()
getConfig for kea-dhcp6-server.
isc::data::ElementPtr getConfigIetf6()
getConfig for ietf-dhcpv6-server.
void setServerKeaDhcp4(isc::data::ConstElementPtr elem)
setServer for kea-dhcp4-server:config.
isc::data::ElementPtr getServerKeaDhcp6()
getServer for kea-dhcp6-server:config.
void delConfigIetf6()
delConfig for ietf-dhcpv6-server.
isc::data::ElementPtr getConfig()
Translate the whole DHCP server configuration from YANG to JSON.
isc::data::ElementPtr getServerKeaDhcpCommon(libyang::DataNode const &data_node)
getServer common part for kea-dhcp[46]-server:config.
isc::data::ElementPtr getHooksKea(libyang::DataNode const &data_node)
Retrieves hooks configuration from sysrepo.
void setControlSocket(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control socket from JSON to YANG.
TranslatorControlSocket(sysrepo::Session session, const std::string &model)
Constructor.
void setControlSockets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control sockets from JSON to YANG.
isc::data::ElementPtr getControlSocket(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSockets(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
Database access translation between YANG and JSON.
isc::data::ElementPtr getDatabase(libyang::DataNode const &data_node)
Translate a database access from YANG to JSON.
void setDatabase(const std::string &xpath, isc::data::ConstElementPtr elem, bool has_mandatory_key)
Translate and set database access from JSON to YANG.
void setDatabases(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set database accesses from JSON to YANG.
isc::data::ElementPtr getDatabases(libyang::DataNode const &data_node, std::string const &xpath)
Translate database accesses from YANG to JSON.
TranslatorDatabases(sysrepo::Session session, const std::string &model)
Constructor.
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(libyang::DataNode const &data_node)
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.
Logger translation between YANG and JSON.
void setLoggers(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set loggers from JSON to YANG.
isc::data::ConstElementPtr getLoggers(libyang::DataNode const &data_node)
Translate loggers from YANG to JSON.
TranslatorLoggers(sysrepo::Session session, const std::string &model)
Constructor.
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.
Currently supports kea-dhcp[46]-server models.
isc::data::ConstElementPtr getOptionDefList(libyang::DataNode const &data_node)
Translate option definition list from YANG to JSON.
void setOptionDefList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option definition list from JSON to YANG.
Option definition 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.
A translator class for converting a pool between YANG and JSON.
A translator class for converting pools between YANG and JSON.
Shared network translation between YANG and JSON.
TranslatorSharedNetworks(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getSharedNetworks(libyang::DataNode const &data_node)
Translate shared networks from YANG to JSON.
void setSharedNetworks(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set shared networks from JSON to YANG.
Subnet (aka network range) translation between YANG and JSON.
A translator class for converting a subnet list between YANG and JSON.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
isc::data::ElementPtr getSubnets(libyang::DataNode const &data_node)
Get and translate subnets from YANG to JSON.
Between YANG and JSON translator class for basic values.
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.
void checkAndGet(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
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 deleteItem(const std::string &xpath)
Delete basic value from YANG.
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 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.
void checkAndStringifyAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGetDiverging(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &key, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.