16 #ifndef HAVE_PRE_0_7_6_SYSREPO
23 TranslatorConfig::TranslatorConfig(S_Session session,
const string& model)
54 if (
model_ == IETF_DHCPV6_SERVER) {
56 }
else if (
model_ == KEA_DHCP4_SERVER) {
58 }
else if (
model_ == KEA_DHCP6_SERVER) {
61 }
catch (
const sysrepo_exception& ex) {
65 "getConfig not implemented for the model: " <<
model_);
72 result->set(
"Dhcp6", dhcp6);
73 string xpath =
"/" +
model_ +
":server/server-config";
76 if (ranges && !ranges->empty()) {
77 dhcp6->set(
"subnet6", ranges);
87 result->set(
"Dhcp4", dhcp);
95 result->set(
"Dhcp6", dhcp);
101 const std::string& name) {
104 storage->set(name, x);
110 S_Iter_Value iter =
getIter(xpath +
"/hook-library");
114 const string& lib =
getNext(iter);
121 hook_lib->set(
"library", name);
124 string parameters = params->stringValue();
125 if (!parameters.empty()) {
126 hook_lib->set(
"parameters",
127 Element::fromJSON(parameters));
130 hook_libs->add(hook_lib);
133 if (!hook_libs->empty()) {
144 getParam(expired, xpath,
"reclaim-timer-wait-time");
145 getParam(expired, xpath,
"flush-reclaimed-timer-wait-time");
146 getParam(expired, xpath,
"hold-reclaimed-time");
147 getParam(expired, xpath,
"max-reclaim-leases");
148 getParam(expired, xpath,
"max-reclaim-time");
149 getParam(expired, xpath,
"unwarned-reclaim-cycles");
151 if (!expired->empty()) {
161 getParam(ddns, xpath,
"enable-updates");
162 getParam(ddns, xpath,
"qualifying-suffix");
164 getParam(ddns, xpath,
"server-port");
166 getParam(ddns, xpath,
"sender-port");
167 getParam(ddns, xpath,
"max-queue-size");
168 getParam(ddns, xpath,
"ncr-protocol");
169 getParam(ddns, xpath,
"ncr-format");
170 getParam(ddns, xpath,
"override-no-update");
171 getParam(ddns, xpath,
"override-client-update");
172 getParam(ddns, xpath,
"replace-client-name");
173 getParam(ddns, xpath,
"generated-prefix");
174 getParam(ddns, xpath,
"hostname-char-set");
175 getParam(ddns, xpath,
"hostname-char-replacement");
179 ddns->set(
"user-context", Element::fromJSON(context->stringValue()));
182 if (!ddns->empty()) {
193 ElementPtr config_ctrl = Element::createMap();
194 getParam(config_ctrl, xpath,
"config-fetch-wait-time");
196 if (databases && !databases->empty()) {
197 config_ctrl->set(
"config-databases", databases);
199 if (!config_ctrl->empty()) {
201 return (config_ctrl);
212 getParam(result, xpath,
"valid-lifetime");
213 getParam(result, xpath,
"min-valid-lifetime");
214 getParam(result, xpath,
"max-valid-lifetime");
215 getParam(result, xpath,
"renew-timer");
216 getParam(result, xpath,
"rebind-timer");
217 getParam(result, xpath,
"calculate-tee-times");
218 getParam(result, xpath,
"t1-percent");
219 getParam(result, xpath,
"t2-percent");
220 getParam(result, xpath,
"decline-probation-period");
221 getParam(result, xpath,
"hostname-char-set");
222 getParam(result, xpath,
"hostname-char-replacement");
225 if (networks && !networks->empty()) {
226 result->set(
"shared-networks", networks);
229 if (classes && !classes->empty()) {
230 result->set(
"client-classes", classes);
234 result->set(
"lease-database", database);
237 if (databases && !databases->empty()) {
238 result->set(
"hosts-databases", databases);
241 getItems(xpath +
"/host-reservation-identifiers");
243 result->set(
"host-reservation-identifiers", host_ids);
246 if (defs && !defs->empty()) {
247 result->set(
"option-def", defs);
250 if (options && !options->empty()) {
251 result->set(
"option-data", options);
254 if (hooks && !hooks->empty()) {
255 result->set(
"hooks-libraries", hooks);
260 result->set(
"expired-leases-processing", expired);
262 getParam(result, xpath,
"dhcp4o6-port");
265 result->set(
"control-socket", socket);
269 result->set(
"dhcp-ddns", ddns);
273 result->set(
"user-context", Element::fromJSON(context->stringValue()));
278 sanity->set(
"lease-checks", checks);
279 result->set(
"sanity-checks", sanity);
281 getParam(result, xpath,
"reservation-mode");
283 if (hosts && !hosts->empty()) {
284 result->set(
"reservations", hosts);
289 result->set(
"config-control", config_ctrl);
291 getParam(result, xpath,
"server-tag");
294 result->set(
"dhcp-queue-control",
295 Element::fromJSON(queue_ctrl->stringValue()));
298 if (loggers && !loggers->empty()) {
299 result->set(
"loggers", loggers);
306 string xpath =
"/kea-dhcp4-server:config";
310 if (subnets && !subnets->empty()) {
311 result->set(
"subnet4", subnets);
316 if (ifs && !ifs->empty()) {
317 if_config->set(
"interfaces", ifs);
319 getParam(if_config, xpath +
"/interfaces-config",
"dhcp-socket-type");
320 getParam(if_config, xpath +
"/interfaces-config",
"outbound-interface");
321 getParam(if_config, xpath +
"/interfaces-config",
"re-detect");
323 getItem(xpath +
"/interfaces-config/user-context");
325 if_config->set(
"user-context",
326 Element::fromJSON(context->stringValue()));
328 if (!if_config->empty()) {
329 result->set(
"interfaces-config", if_config);
332 getParam(result, xpath,
"echo-client-id");
333 getParam(result, xpath,
"match-client-id");
334 getParam(result, xpath,
"next-server");
335 getParam(result, xpath,
"server-hostname");
336 getParam(result, xpath,
"boot-file-name");
337 getParam(result, xpath,
"authoritative");
343 string xpath =
"/kea-dhcp6-server:config";
346 getParam(result, xpath,
"data-directory");
347 getParam(result, xpath,
"preferred-lifetime");
348 getParam(result, xpath,
"min-preferred-lifetime");
349 getParam(result, xpath,
"max-preferred-lifetime");
352 if (subnets && !subnets->empty()) {
353 result->set(
"subnet6", subnets);
358 if (ifs && !ifs->empty()) {
359 if_config->set(
"interfaces", ifs);
361 getParam(if_config, xpath +
"/interfaces-config",
"re-detect");
363 getItem(xpath +
"/interfaces-config/user-context");
365 if_config->set(
"user-context",
366 Element::fromJSON(context->stringValue()));
368 if (!if_config->empty()) {
369 result->set(
"interfaces-config", if_config);
374 result->set(
"relay-supplied-options", relay);
378 result->set(
"mac-sources", macs);
383 getParam(server_id, xpath +
"/server-id",
"type");
384 getParam(server_id, xpath +
"/server-id",
"identifier");
385 getParam(server_id, xpath +
"/server-id",
"time");
386 getParam(server_id, xpath +
"/server-id",
"htype");
387 getParam(server_id, xpath +
"/server-id",
"enterprise-id");
388 getParam(server_id, xpath +
"/server-id",
"persist");
389 context =
getItem(xpath +
"/server-id/user-context");
391 server_id->set(
"user-context",
392 Element::fromJSON(context->stringValue()));
394 if (!server_id->empty()) {
395 result->set(
"server-id", server_id);
403 if (
model_ == IETF_DHCPV6_SERVER) {
410 }
else if (
model_ == KEA_DHCP4_SERVER) {
417 }
else if (
model_ == KEA_DHCP6_SERVER) {
426 "setConfig not implemented for the model: " <<
model_);
428 }
catch (
const sysrepo_exception& ex) {
430 "sysrepo error setting config '" << elem->str()
431 <<
"': " << ex.
what());
442 string xpath =
"/" +
model_ +
":server/server-config";
448 if (ranges && !ranges->empty()) {
449 setSubnets(xpath +
"/network-ranges", ranges);
480 setItem(xpath +
"/valid-lifetime", valid, SR_UINT32_T);
484 setItem(xpath +
"/min-valid-lifetime", min_valid, SR_UINT32_T);
488 setItem(xpath +
"/max-valid-lifetime", max_valid, SR_UINT32_T);
492 setItem(xpath +
"/renew-timer", renew, SR_UINT32_T);
496 setItem(xpath +
"/rebind-timer", rebind, SR_UINT32_T);
500 setItem(xpath +
"/calculate-tee-times", calculate, SR_BOOL_T);
504 setItem(xpath +
"/t1-percent", t1_percent, SR_DECIMAL64_T);
508 setItem(xpath +
"/t2-percent", t2_percent, SR_DECIMAL64_T);
512 setItem(xpath +
"/decline-probation-period", period, SR_UINT32_T);
519 if (classes && !classes->empty()) {
527 if (databases && !databases->empty()) {
531 database = elem->get(
"hosts-database");
534 list->add(
copy(database));
541 setItem(xpath +
"/host-reservation-identifiers",
id, SR_ENUM_T);
545 if (defs && !defs->empty()) {
549 if (options && !options->empty()) {
559 ostringstream hook_lib;
560 hook_lib << xpath <<
"/hook-library[library='"
561 << name->stringValue() <<
"']";
564 hook_lib <<
"/parameters";
565 setItem(hook_lib.str(), Element::create(params->str()),
569 setItem(hook_lib.str(), list, SR_LIST_T);
577 setItem(xpath +
"/expired-leases-processing/reclaim-timer-wait-time",
578 reclaim, SR_UINT32_T);
581 expired->get(
"flush-reclaimed-timer-wait-time");
583 setItem(xpath +
"/expired-leases-processing/flush-reclaimed-timer-wait-time",
588 setItem(xpath +
"/expired-leases-processing/hold-reclaimed-time",
593 setItem(xpath +
"/expired-leases-processing/max-reclaim-leases",
594 max_leases, SR_UINT32_T);
598 setItem(xpath +
"/expired-leases-processing/max-reclaim-time",
599 max_time, SR_UINT32_T);
603 setItem(xpath +
"/expired-leases-processing/unwarned-reclaim-cycles",
604 unwarned, SR_UINT32_T);
609 setItem(xpath +
"/dhcp4o6-port", port, SR_UINT16_T);
617 setItem(xpath +
"/hostname-char-set", char_set, SR_STRING_T);
621 setItem(xpath +
"/hostname-char-replacement", char_repl, SR_STRING_T);
627 setItem(xpath +
"/dhcp-ddns/enable-updates", enable, SR_BOOL_T);
631 setItem(xpath +
"/dhcp-ddns/qualifying-suffix", suffix,
636 setItem(xpath +
"/dhcp-ddns/server-ip", server_ip, SR_STRING_T);
640 setItem(xpath +
"/dhcp-ddns/server-port", server_port,
645 setItem(xpath +
"/dhcp-ddns/sender-ip", sender_ip, SR_STRING_T);
649 setItem(xpath +
"/dhcp-ddns/sender-port", sender_port,
654 setItem(xpath +
"/dhcp-ddns/max-queue-size", queue, SR_UINT32_T);
658 setItem(xpath +
"/dhcp-ddns/ncr-protocol", protocol, SR_ENUM_T);
662 setItem(xpath +
"/dhcp-ddns/ncr-format", format, SR_ENUM_T);
666 setItem(xpath +
"/dhcp-ddns/override-no-update", no_up, SR_BOOL_T);
670 setItem(xpath +
"/dhcp-ddns/override-client-update", client,
675 setItem(xpath +
"/dhcp-ddns/replace-client-name", replace,
680 setItem(xpath +
"/dhcp-ddns/generated-prefix", generated,
685 setItem(xpath +
"/dhcp-ddns/hostname-char-set", char_set,
690 setItem(xpath +
"/dhcp-ddns/hostname-char-replacement", char_repl,
696 setItem(xpath +
"/dhcp-ddns/user-context", repr, SR_STRING_T);
702 setItem(xpath +
"/user-context", repr, SR_STRING_T);
708 setItem(xpath +
"/sanity-checks/lease-checks", checks, SR_ENUM_T);
713 setItem(xpath +
"/reservation-mode", hr_mode, SR_ENUM_T);
716 if (hosts && !hosts->empty()) {
720 if (config_ctrl && !config_ctrl->empty()) {
723 setItem(xpath +
"/config-control/config-fetch-wait-time", cfwt,
726 databases = config_ctrl->get(
"config-databases");
727 if (databases && !databases->empty()) {
728 setDatabases(xpath +
"/config-control/config-database", databases);
733 setItem(xpath +
"/server-tag", server_tag, SR_STRING_T);
738 setItem(xpath +
"/dhcp-queue-control", repr, SR_STRING_T);
748 string xpath =
"/kea-dhcp4-server:config";
757 if (ifs && !ifs->empty()) {
759 setItem(xpath +
"/interfaces-config/interfaces",
765 setItem(xpath +
"/interfaces-config/dhcp-socket-type",
770 setItem(xpath +
"/interfaces-config/outbound-interface",
775 setItem(xpath +
"/interfaces-config/re-detect",
776 redetect, SR_BOOL_T);
780 setItem(xpath +
"/interfaces-config/user-context",
781 Element::create(context->str()), SR_STRING_T);
786 setItem(xpath +
"/echo-client-id", echo, SR_BOOL_T);
790 setItem(xpath +
"/match-client-id", match, SR_BOOL_T);
794 setItem(xpath +
"/next-server", next, SR_STRING_T);
798 setItem(xpath +
"/server-hostname", hostname, SR_STRING_T);
802 setItem(xpath +
"/boot-file-name", boot, SR_STRING_T);
806 setItem(xpath +
"/authoritative", auth, SR_BOOL_T);
812 string xpath =
"/kea-dhcp6-server:config";
816 setItem(xpath +
"/data-directory", data_dir, SR_STRING_T);
820 setItem(xpath +
"/preferred-lifetime", preferred, SR_UINT32_T);
824 setItem(xpath +
"/min-preferred-lifetime", min_pref, SR_UINT32_T);
828 setItem(xpath +
"/max-preferred-lifetime", max_pref, SR_UINT32_T);
837 if (ifs && !ifs->empty()) {
839 setItem(xpath +
"/interfaces-config/interfaces",
845 setItem(xpath +
"/interfaces-config/re-detect",
846 redetect, SR_BOOL_T);
850 setItem(xpath +
"/interfaces-config/user-context",
851 Element::create(context->str()), SR_STRING_T);
857 setItem(xpath +
"/relay-supplied-options", addr, SR_STRING_T);
863 setItem(xpath +
"/mac-sources", source, SR_STRING_T);
870 setItem(xpath +
"/server-id/type", id_type, SR_ENUM_T);
874 setItem(xpath +
"/server-id/identifier", id_id, SR_STRING_T);
878 setItem(xpath +
"/server-id/time", id_time, SR_UINT32_T);
882 setItem(xpath +
"/server-id/htype", id_htype, SR_UINT16_T);
886 setItem(xpath +
"/server-id/enterprise-id", id_ent_id,
891 setItem(xpath +
"/server-id/persist", id_persist, SR_BOOL_T);
896 setItem(xpath +
"/server-id/user-context", repr, SR_STRING_T);
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
void setSharedNetworks(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set shared networks from JSON to YANG.
void setConfigKea4(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp[46]-server.
isc::data::ElementPtr getHosts(const std::string &xpath)
Get and translate host reservations from YANG to JSON.
Subnet (aka network range) translation between YANG and JSON.
isc::data::ElementPtr getConfigKea6()
getConfig for kea-dhcp6-server.
A generic exception that is thrown when a function is not implemented.
isc::data::ConstElementPtr getDatabases(const std::string &xpath)
Get and translate database accesses from YANG to JSON.
void setDatabases(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set database accesses from JSON to YANG.
isc::data::ElementPtr getDatabase(const std::string &xpath)
Get and translate a database access from YANG to JSON.
Between YANG and JSON translator class for basic values.
void setConfigIetf6(isc::data::ConstElementPtr elem)
setConfig for ietf-dhcpv6-server.
Currently supports kea-dhcp[46]-server models.
void setServerKeaDhcp4(isc::data::ConstElementPtr elem)
setServer for kea-dhcp4-server:config.
isc::data::ElementPtr getConfigKea4()
getConfig for kea-dhcp4-server.
boost::shared_ptr< Element > ElementPtr
A translator class for converting a pd-pool list between YANG and JSON.
isc::data::ConstElementPtr getLoggers(const std::string &xpath)
Get and translate loggeres from YANG to JSON.
isc::data::ElementPtr getSharedNetworks(const std::string &xpath)
Get and translate shared networks from YANG to JSON.
isc::data::ConstElementPtr getOptionDefList(const std::string &xpath)
Get and translate option definition list from YANG to JSON.
void setConfig(isc::data::ConstElementPtr elem)
Translate and sets the DHCP server configuration from JSON to YANG.
sysrepo::S_Iter_Value getIter(const std::string &xpath)
List iterator methods keeping the session private.
Shared network translation between YANG and JSON.
void getParam(isc::data::ElementPtr &storage, const std::string &xpath, const std::string &name)
Retrieves an item and stores in the specified storage.
void setControlSocket(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control socket from JSON to YANG.
void setConfigKea6(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp6-server.
void setClasses(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set client classes from JSON to YANG.
isc::data::ElementPtr getConfig()
Get and translate the whole DHCP server configuration from YANG to JSON.
#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...
Control socket translation between YANG and JSON.
Client class translation between YANG and JSON.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
void setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
Translation between YANG and JSON for a single host reservation.
A translator class for converting an option data list between YANG and JSON.
isc::data::ElementPtr getSubnets(const std::string &xpath)
Get and translate subnets from YANG to JSON.
std::string model_
The model.
isc::data::ElementPtr getConfigIetf6()
getConfig for ietf-dhcpv6-server.
Database access translation between YANG and JSON.
A translator class for converting a logger list between YANG and JSON.
isc::data::ElementPtr getExpiredKea(const std::string &xpath)
Retrieves expired leases processing parameters from sysrepo.
virtual ~TranslatorConfig()
Destructor.
boost::shared_ptr< const Element > ConstElementPtr
static void preProcess4(isc::data::ConstElementPtr config)
Pre process a DHCPv4 configuration.
std::string getNext(sysrepo::S_Iter_Value iter)
Get xpath of the next YANG list item.
static isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
A translator class for converting a shared network 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::ElementPtr getDdnsKea(const std::string &xpath)
Retrieves DDNS configuration from sysrepo.
void setServerKeaDhcp6(isc::data::ConstElementPtr elem)
setServer for kea-dhcp6-server:config.
A translator class for converting a subnet list between YANG and JSON.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void delConfigIetf6()
delConfig for ietf-dhcpv6-server.
void delItem(const std::string &xpath)
Delete basic value from YANG.
Logger translation between YANG and JSON.
isc::data::ConstElementPtr getClasses(const std::string &xpath)
Get and translate client classes from YANG to JSON.
void setOptionDefList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option definition list from JSON to YANG.
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 setServerKeaDhcpCommon(const std::string &xpath, isc::data::ConstElementPtr elem)
setServer common part for kea-dhcp[46]-server:config.
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.
A translator class for converting a pool between YANG and JSON.
isc::data::ElementPtr getServerKeaDhcp4()
getServer for kea-dhcp4-server:config.
A translator class for converting a database access list between YANG and JSON.
A translator class for converting a client class list between YANG and JSON.
void delConfigKea()
delConfig for kea-dhcp[46]-server.
static void preProcess6(isc::data::ConstElementPtr config)
Pre process a DHCPv6 configuration.
A translator class for converting pools between YANG and JSON.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
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.
isc::data::ElementPtr getConfigControlKea(const std::string &xpath)
Retrieves configuration control from sysrepo.
isc::data::ConstElementPtr getControlSocket(const std::string &xpath)
Get and translate a control socket from YANG to JSON.
isc::data::ElementPtr getServerKeaDhcpCommon(const std::string &xpath)
getServer common part for kea-dhcp[46]-server:config.
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 getHooksKea(const std::string &xpath)
Retrieves hooks configuration from sysrepo.
A translator class for converting host reservations list between YANG and JSON.
Option definition translation between YANG and JSON.
isc::data::ElementPtr getServerKeaDhcp6()
getServer for kea-dhcp6-server:config.
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.