16using namespace sysrepo;
52 if (
model_ == IETF_DHCPV6_SERVER) {
54 }
else if (
model_ == KEA_DHCP4_SERVER) {
56 }
else if (
model_ == KEA_DHCP6_SERVER) {
59 }
catch (
const sysrepo_exception& ex) {
63 "getConfig not implemented for the model: " <<
model_);
70 result->set(
"Dhcp6", dhcp6);
71 string xpath =
"/" +
model_ +
":server/server-config";
74 if (ranges && !ranges->empty()) {
75 dhcp6->set(
"subnet6", ranges);
85 result->set(
"Dhcp4", dhcp);
93 result->set(
"Dhcp6", dhcp);
98 ElementPtr const& hook_library(Element::createMap());
101 hook_library->set(
"library", name);
104 hook_library->set(
"parameters",
105 Element::fromJSON(parameters->stringValue()));
127 if (!expired->empty()) {
155 ddns->set(
"user-context", Element::fromJSON(context->stringValue()));
158 if (!ddns->empty()) {
169 ElementPtr config_ctrl = Element::createMap();
172 if (databases && !databases->empty()) {
173 config_ctrl->set(
"config-databases", databases);
175 if (!config_ctrl->empty()) {
177 return (config_ctrl);
201 if (networks && !networks->empty()) {
202 result->set(
"shared-networks", networks);
205 if (classes && !classes->empty()) {
206 result->set(
"client-classes", classes);
210 result->set(
"lease-database", database);
213 if (databases && !databases->empty()) {
214 result->set(
"hosts-databases", databases);
217 getItems(xpath +
"/host-reservation-identifiers");
219 result->set(
"host-reservation-identifiers", host_ids);
222 if (defs && !defs->empty()) {
223 result->set(
"option-def", defs);
226 if (options && !options->empty()) {
227 result->set(
"option-data", options);
230 if (hooks && !hooks->empty()) {
231 result->set(
"hooks-libraries", hooks);
236 result->set(
"expired-leases-processing", expired);
241 result->set(
"control-socket", socket);
245 result->set(
"dhcp-ddns", ddns);
249 result->set(
"user-context", Element::fromJSON(context->stringValue()));
254 sanity->set(
"lease-checks", checks);
255 result->set(
"sanity-checks", sanity);
259 if (hosts && !hosts->empty()) {
260 result->set(
"reservations", hosts);
265 result->set(
"config-control", config_ctrl);
270 result->set(
"dhcp-queue-control",
271 Element::fromJSON(queue_ctrl->stringValue()));
274 if (loggers && !loggers->empty()) {
275 result->set(
"loggers", loggers);
279 ElementPtr compatibility = Element::createMap();
280 checkAndGetLeaf(compatibility, xpath +
"/compatibility",
"lenient-option-parsing");
281 if (!compatibility->empty()) {
282 result->set(
"compatibility", compatibility);
295 ElementPtr multi_threading = Element::createMap();
296 string mt_xpath = xpath +
"/multi-threading";
300 if (!multi_threading->empty()) {
301 result->set(
"multi-threading", multi_threading);
315 string xpath =
"/kea-dhcp4-server:config";
319 if (subnets && !subnets->empty()) {
320 result->set(
"subnet4", subnets);
325 if (ifs && !ifs->empty()) {
326 if_config->set(
"interfaces", ifs);
328 string if_cfg_xpath = xpath +
"/interfaces-config";
331 checkAndGetLeaf(if_config, if_cfg_xpath,
"service-sockets-require-all");
332 checkAndGetLeaf(if_config, if_cfg_xpath,
"service-sockets-max-retries");
333 checkAndGetLeaf(if_config, if_cfg_xpath,
"service-sockets-retry-wait-time");
336 getItem(xpath +
"/interfaces-config/user-context");
338 if_config->set(
"user-context",
339 Element::fromJSON(context->stringValue()));
341 if (!if_config->empty()) {
342 result->set(
"interfaces-config", if_config);
356 string xpath =
"/kea-dhcp6-server:config";
365 if (subnets && !subnets->empty()) {
366 result->set(
"subnet6", subnets);
371 if (ifs && !ifs->empty()) {
372 if_config->set(
"interfaces", ifs);
374 string if_cfg_xpath = xpath +
"/interfaces-config";
375 checkAndGetLeaf(if_config, if_cfg_xpath,
"service-sockets-require-all");
376 checkAndGetLeaf(if_config, if_cfg_xpath,
"service-sockets-max-retries");
377 checkAndGetLeaf(if_config, if_cfg_xpath,
"service-sockets-retry-wait-time");
380 getItem(xpath +
"/interfaces-config/user-context");
382 if_config->set(
"user-context",
383 Element::fromJSON(context->stringValue()));
385 if (!if_config->empty()) {
386 result->set(
"interfaces-config", if_config);
391 result->set(
"relay-supplied-options", relay);
395 result->set(
"mac-sources", macs);
400 string srv_id_xpath = xpath +
"/server-id";
407 context =
getItem(xpath +
"/server-id/user-context");
409 server_id->set(
"user-context",
410 Element::fromJSON(context->stringValue()));
412 if (!server_id->empty()) {
413 result->set(
"server-id", server_id);
421 if (
model_ == IETF_DHCPV6_SERVER) {
428 }
else if (
model_ == KEA_DHCP4_SERVER) {
435 }
else if (
model_ == KEA_DHCP6_SERVER) {
444 "setConfig not implemented for the model: " <<
model_);
446 }
catch (
const sysrepo_exception& ex) {
448 "sysrepo error setting config '" << elem->str()
449 <<
"': " << ex.
what());
460 string xpath =
"/" +
model_ +
":server/server-config";
466 if (ranges && !ranges->empty()) {
467 setSubnets(xpath +
"/network-ranges", ranges);
510 if (classes && !classes->empty()) {
518 if (databases && !databases->empty()) {
522 database = elem->get(
"hosts-database");
525 list->add(
copy(database));
532 setItem(xpath +
"/host-reservation-identifiers",
id, SR_ENUM_T);
536 if (defs && !defs->empty()) {
540 if (options && !options->empty()) {
550 ostringstream hook_lib;
551 hook_lib << xpath <<
"/hook-library[library='"
552 << name->stringValue() <<
"']";
555 hook_lib <<
"/parameters";
556 setItem(hook_lib.str(), Element::create(params->str()),
560 setItem(hook_lib.str(), list, SR_LIST_T);
566 string expired_xpath = xpath +
"/expired-leases-processing";
567 checkAndSetLeaf(expired, expired_xpath,
"reclaim-timer-wait-time", SR_UINT32_T);
568 checkAndSetLeaf(expired, expired_xpath,
"flush-reclaimed-timer-wait-time", SR_UINT32_T);
569 checkAndSetLeaf(expired, expired_xpath,
"hold-reclaimed-time", SR_UINT32_T);
570 checkAndSetLeaf(expired, expired_xpath,
"max-reclaim-leases", SR_UINT32_T);
571 checkAndSetLeaf(expired, expired_xpath,
"max-reclaim-time", SR_UINT32_T);
572 checkAndSetLeaf(expired, expired_xpath,
"unwarned-reclaim-cycles", SR_UINT32_T);
580 checkAndSetLeaf(elem, xpath,
"hostname-char-replacement", SR_STRING_T);
583 string ddns_xpath = xpath +
"/dhcp-ddns";
594 checkAndSetLeaf(ddns, ddns_xpath,
"override-client-update", SR_BOOL_T);
598 checkAndSetLeaf(ddns, ddns_xpath,
"hostname-char-replacement", SR_STRING_T);
602 setItem(xpath +
"/dhcp-ddns/user-context", repr, SR_STRING_T);
608 setItem(xpath +
"/user-context", repr, SR_STRING_T);
612 checkAndSetLeaf(sanity, xpath +
"/sanity-checks",
"lease-checks", SR_ENUM_T);
616 if (hosts && !hosts->empty()) {
620 if (config_ctrl && !config_ctrl->empty()) {
621 checkAndSetLeaf(config_ctrl, xpath +
"/config-control",
"config-fetch-wait-time", SR_UINT32_T);
622 databases = config_ctrl->get(
"config-databases");
623 if (databases && !databases->empty()) {
624 setDatabases(xpath +
"/config-control/config-database", databases);
631 setItem(xpath +
"/dhcp-queue-control", repr, SR_STRING_T);
641 checkAndSetLeaf(compatibility, xpath +
"/compatibility",
"lenient-option-parsing", SR_BOOL_T);
644 checkAndSetLeaf(elem, xpath,
"ddns-override-client-update", SR_BOOL_T);
650 checkAndSetLeaf(elem, xpath,
"ddns-use-conflict-resolution", SR_BOOL_T);
652 checkAndSetLeaf(elem, xpath,
"early-global-reservations-lookup", SR_BOOL_T);
655 if (multi_threading) {
656 string mt_xpath = xpath +
"/multi-threading";
657 checkAndSetLeaf(multi_threading, mt_xpath,
"enable-multi-threading", SR_BOOL_T);
658 checkAndSetLeaf(multi_threading, mt_xpath,
"packet-queue-size", SR_UINT32_T);
659 checkAndSetLeaf(multi_threading, mt_xpath,
"thread-pool-size", SR_UINT32_T);
665 checkAndSetLeaf(elem, xpath,
"statistic-default-sample-age", SR_UINT32_T);
666 checkAndSetLeaf(elem, xpath,
"statistic-default-sample-count", SR_UINT32_T);
672 string xpath =
"/kea-dhcp4-server:config";
681 if (ifs && !ifs->empty()) {
683 setItem(xpath +
"/interfaces-config/interfaces",
687 string if_cfg_xpath = xpath +
"/interfaces-config";
688 checkAndSetLeaf(if_config, if_cfg_xpath,
"dhcp-socket-type", SR_ENUM_T);
689 checkAndSetLeaf(if_config, if_cfg_xpath,
"outbound-interface", SR_ENUM_T);
690 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-require-all", SR_BOOL_T);
691 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-max-retries", SR_UINT32_T);
692 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-retry-wait-time", SR_UINT32_T);
696 setItem(xpath +
"/interfaces-config/user-context",
697 Element::create(context->str()), SR_STRING_T);
710 string xpath =
"/kea-dhcp6-server:config";
723 if (ifs && !ifs->empty()) {
725 setItem(xpath +
"/interfaces-config/interfaces",
729 string if_cfg_xpath = xpath +
"/interfaces-config";
730 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-require-all", SR_BOOL_T);
731 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-max-retries", SR_UINT32_T);
732 checkAndSetLeaf(if_config, if_cfg_xpath,
"service-sockets-retry-wait-time", SR_UINT32_T);
736 setItem(xpath +
"/interfaces-config/user-context",
737 Element::create(context->str()), SR_STRING_T);
743 setItem(xpath +
"/relay-supplied-options", addr, SR_STRING_T);
749 setItem(xpath +
"/mac-sources", source, SR_STRING_T);
754 string srv_id_xpath = xpath +
"/server-id";
759 checkAndSetLeaf(server_id, srv_id_xpath,
"enterprise-id", SR_UINT32_T);
764 setItem(xpath +
"/server-id/user-context", repr, SR_STRING_T);
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::ConstElementPtr config)
Pre process a DHCPv4 configuration.
static void preProcess6(isc::data::ConstElementPtr config)
Pre process a DHCPv6 configuration.
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 checkAndGetLeaf(isc::data::ElementPtr &storage, const std::string &xpath, const std::string &name)
Retrieves an item and stores it in the specified storage.
isc::data::ElementPtr getList(std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(std::string const &xpath))
Retrieve a list as ElementPtr from sysrepo from a certain xpath.
void delItem(const std::string &xpath)
Delete basic value from YANG.
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.
Client class translation between YANG and JSON.
A translator class for converting a client class list between YANG and JSON.
isc::data::ConstElementPtr getClasses(const std::string &xpath)
Get and 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.
isc::data::ElementPtr getConfigKea4()
getConfig for kea-dhcp4-server.
isc::data::ElementPtr getExpiredKea(const std::string &xpath)
Retrieves expired leases processing parameters from sysrepo.
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 getServerKeaDhcp4()
getServer for kea-dhcp4-server:config.
void setConfigKea6(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp6-server.
isc::data::ElementPtr getHooksKea(const std::string &xpath)
Retrieves hooks configuration from sysrepo.
isc::data::ElementPtr getServerKeaDhcpCommon(const std::string &xpath)
getServer common part for kea-dhcp[46]-server:config.
void setConfigIetf6(isc::data::ConstElementPtr elem)
setConfig for ietf-dhcpv6-server.
isc::data::ElementPtr getDdnsKea(const std::string &xpath)
Retrieves DDNS configuration from sysrepo.
void setConfigKea4(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp[46]-server.
isc::data::ElementPtr getConfigControlKea(const std::string &xpath)
Retrieves configuration control from sysrepo.
void setServerKeaDhcp6(isc::data::ConstElementPtr elem)
setServer for kea-dhcp6-server:config.
void setConfig(isc::data::ConstElementPtr elem)
Translate and sets the DHCP server configuration from JSON to YANG.
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.
TranslatorConfig(sysrepo::S_Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getServerKeaDhcp6()
getServer for kea-dhcp6-server:config.
isc::data::ElementPtr getHook(const std::string &xpath)
void delConfigIetf6()
delConfig for ietf-dhcpv6-server.
virtual ~TranslatorConfig()
Destructor.
isc::data::ElementPtr getConfig()
Get and translate the whole DHCP server configuration from YANG to JSON.
Control socket translation between YANG and JSON.
void setControlSocket(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control socket from JSON to YANG.
isc::data::ConstElementPtr getControlSocket(const std::string &xpath)
Get and translate a control socket from YANG to JSON.
Database access translation between YANG and JSON.
void setDatabase(const std::string &xpath, isc::data::ConstElementPtr elem, bool skip=false)
Translate and set database access from JSON to YANG.
isc::data::ElementPtr getDatabase(const std::string &xpath)
Get and translate a database access from YANG to JSON.
A translator class for converting a database access list between YANG and JSON.
void setDatabases(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set database accesses from JSON to YANG.
isc::data::ConstElementPtr getDatabases(const std::string &xpath)
Get and translate database accesses from YANG to JSON.
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.
Logger translation between YANG and JSON.
A translator class for converting a logger list between YANG and JSON.
void setLoggers(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set loggeres from JSON to YANG.
isc::data::ConstElementPtr getLoggers(const std::string &xpath)
Get and translate loggeres 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.
Currently supports kea-dhcp[46]-server models.
void setOptionDefList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option definition list from JSON to YANG.
isc::data::ConstElementPtr getOptionDefList(const std::string &xpath)
Get and translate option definition list from YANG to JSON.
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.
A translator class for converting a shared network list between YANG and JSON.
isc::data::ElementPtr getSharedNetworks(const std::string &xpath)
Get and 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(const std::string &xpath)
Get and translate subnets from YANG to JSON.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, int 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.