Kea 2.5.8
translator_config.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
11#include <yang/yang_models.h>
12
13#include <sstream>
14
15using namespace std;
16using namespace isc::data;
17using namespace libyang;
18using namespace sysrepo;
19
20namespace isc {
21namespace yang {
22
23TranslatorConfig::TranslatorConfig(Session session, const string& model)
24 : Translator(session, model),
25 TranslatorControlSocket(session, model),
26 TranslatorDatabase(session, model),
27 TranslatorDatabases(session, model),
28 TranslatorOptionData(session, model),
29 TranslatorOptionDataList(session, model),
30 TranslatorOptionDef(session, model),
31 TranslatorOptionDefList(session, model),
32 TranslatorClass(session, model),
33 TranslatorClasses(session, model),
34 TranslatorPool(session, model),
35 TranslatorPools(session, model),
36 TranslatorPdPool(session, model),
37 TranslatorPdPools(session, model),
38 TranslatorHost(session, model),
39 TranslatorHosts(session, model),
40 TranslatorSubnet(session, model),
41 TranslatorSubnets(session, model),
42 TranslatorSharedNetwork(session, model),
43 TranslatorSharedNetworks(session, model),
44 TranslatorLogger(session, model),
45 TranslatorLoggers(session, model) {
46}
47
50 try {
51 if (model_ == IETF_DHCPV6_SERVER) {
52 return (getConfigIetf6());
53 } else if (model_ == KEA_DHCP4_SERVER) {
54 return (getConfigKea4());
55 } else if (model_ == KEA_DHCP6_SERVER) {
56 return (getConfigKea6());
57 }
58 } catch (Error const& ex) {
59 isc_throw(NetconfError, "getting config: " << ex.what());
60 }
62 "getConfig not implemented for the model: " << model_);
63}
64
69 result->set("Dhcp6", dhcp6);
70 string const xpath("/ietf-dhcpv6-server:server");
71 optional<DataNode> config;
72 try {
73 config = findXPath(xpath);
74 } catch (NetconfError const&) {
75 return result;
76 }
77
78 checkAndGetDiverging(dhcp6, *config, "subnet6", "server-config/network-ranges",
79 [&](DataNode const& data_node) -> ElementPtr const {
80 return getSubnets(data_node);
81 });
82
83 // Skip everything else.
84 return (result);
85}
86
91 result->set("Dhcp4", dhcp);
92 return (result);
93}
94
99 result->set("Dhcp6", dhcp);
100 return (result);
101}
102
103ElementPtr TranslatorConfig::getHook(DataNode const& data_node) {
104 ElementPtr hook_library(Element::createMap());
105 checkAndGetLeaf(hook_library, data_node, "library");
106 checkAndGetAndJsonifyLeaf(hook_library, data_node, "parameters");
107 return hook_library;
108}
109
111TranslatorConfig::getHooksKea(DataNode const& data_node) {
112 return getList(data_node, "hook-library", *this, &TranslatorConfig::getHook);
113}
114
116TranslatorConfig::getExpiredKea(DataNode const& data_node) {
118
119 checkAndGetLeaf(result, data_node, "flush-reclaimed-timer-wait-time");
120 checkAndGetLeaf(result, data_node, "hold-reclaimed-time");
121 checkAndGetLeaf(result, data_node, "max-reclaim-leases");
122 checkAndGetLeaf(result, data_node, "max-reclaim-time");
123 checkAndGetLeaf(result, data_node, "reclaim-timer-wait-time");
124 checkAndGetLeaf(result, data_node, "unwarned-reclaim-cycles");
125
126 return (result->empty() ? ElementPtr() : result);
127}
128
130TranslatorConfig::getDdnsKea(DataNode const& data_node) {
132
133 checkAndGetLeaf(result, data_node, "enable-updates");
134 checkAndGetLeaf(result, data_node, "generated-prefix");
135 checkAndGetLeaf(result, data_node, "hostname-char-replacement");
136 checkAndGetLeaf(result, data_node, "hostname-char-set");
137 checkAndGetLeaf(result, data_node, "max-queue-size");
138 checkAndGetLeaf(result, data_node, "ncr-format");
139 checkAndGetLeaf(result, data_node, "ncr-protocol");
140 checkAndGetLeaf(result, data_node, "qualifying-suffix");
141 checkAndGetLeaf(result, data_node, "override-client-update");
142 checkAndGetLeaf(result, data_node, "override-no-update");
143 checkAndGetLeaf(result, data_node, "replace-client-name");
144 checkAndGetLeaf(result, data_node, "sender-ip");
145 checkAndGetLeaf(result, data_node, "sender-port");
146 checkAndGetLeaf(result, data_node, "server-ip");
147 checkAndGetLeaf(result, data_node, "server-port");
148
149 checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
150
151 return (result->empty() ? ElementPtr() : result);
152}
153
155TranslatorConfig::getConfigControlKea(DataNode const& data_node) {
157 checkAndGetLeaf(result, data_node, "config-fetch-wait-time");
158 ConstElementPtr databases = getDatabases(data_node, "config-database");
159 if (databases && !databases->empty()) {
160 result->set("config-databases", databases);
161 }
162 return (result->empty() ? ElementPtr() : result);
163}
164
166TranslatorConfig::getInterfacesKea(DataNode const& config) {
167 ElementPtr result;
168 optional<DataNode> const& interfaces_config_optional(config.findPath("interfaces-config"));
169 if (interfaces_config_optional) {
170 DataNode const interfaces_config(*interfaces_config_optional);
171 result = Element::createMap();
172
173 checkAndGetLeaf(result, interfaces_config, "dhcp-socket-type");
174 checkAndGetLeaf(result, interfaces_config, "interfaces");
175 checkAndGetLeaf(result, interfaces_config, "outbound-interface");
176 checkAndGetLeaf(result, interfaces_config, "re-detect");
177 checkAndGetLeaf(result, interfaces_config, "service-sockets-max-retries");
178 checkAndGetLeaf(result, interfaces_config, "service-sockets-require-all");
179 checkAndGetLeaf(result, interfaces_config, "service-sockets-retry-wait-time");
180
181 checkAndGetAndJsonifyLeaf(result, interfaces_config, "user-context");
182 }
183 return (result->empty() ? ElementPtr() : result);
184}
185
189
190 checkAndGetLeaf(result, data_node, "allocator");
191 checkAndGetLeaf(result, data_node, "cache-max-age");
192 checkAndGetLeaf(result, data_node, "cache-threshold");
193 checkAndGetLeaf(result, data_node, "calculate-tee-times");
194 checkAndGetLeaf(result, data_node, "dhcp4o6-port");
195 checkAndGetLeaf(result, data_node, "ddns-generated-prefix");
196 checkAndGetLeaf(result, data_node, "ddns-override-client-update");
197 checkAndGetLeaf(result, data_node, "ddns-override-no-update");
198 checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix");
199 checkAndGetLeaf(result, data_node, "ddns-replace-client-name");
200 checkAndGetLeaf(result, data_node, "ddns-send-updates");
201 checkAndGetLeaf(result, data_node, "ddns-ttl-percent");
202 checkAndGetLeaf(result, data_node, "ddns-update-on-renew");
203 checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution");
204 checkAndGetLeaf(result, data_node, "decline-probation-period");
205 checkAndGetLeaf(result, data_node, "early-global-reservations-lookup");
206 checkAndGetLeaf(result, data_node, "host-reservation-identifiers");
207 checkAndGetLeaf(result, data_node, "hostname-char-replacement");
208 checkAndGetLeaf(result, data_node, "hostname-char-set");
209 checkAndGetLeaf(result, data_node, "ip-reservations-unique");
210 checkAndGetLeaf(result, data_node, "max-valid-lifetime");
211 checkAndGetLeaf(result, data_node, "min-valid-lifetime");
212 checkAndGetLeaf(result, data_node, "parked-packet-limit");
213 checkAndGetLeaf(result, data_node, "rebind-timer");
214 checkAndGetLeaf(result, data_node, "renew-timer");
215 checkAndGetLeaf(result, data_node, "reservation-mode");
216 checkAndGetLeaf(result, data_node, "reservations-global");
217 checkAndGetLeaf(result, data_node, "reservations-in-subnet");
218 checkAndGetLeaf(result, data_node, "reservations-lookup-first");
219 checkAndGetLeaf(result, data_node, "reservations-out-of-pool");
220 checkAndGetLeaf(result, data_node, "server-tag");
221 checkAndGetLeaf(result, data_node, "statistic-default-sample-age");
222 checkAndGetLeaf(result, data_node, "statistic-default-sample-count");
223 checkAndGetLeaf(result, data_node, "store-extended-info");
224 checkAndGetLeaf(result, data_node, "t1-percent");
225 checkAndGetLeaf(result, data_node, "t2-percent");
226 checkAndGetLeaf(result, data_node, "valid-lifetime");
227
228 checkAndGetAndJsonifyLeaf(result, data_node, "dhcp-queue-control");
229 checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
230
231 ConstElementPtr classes = getClasses(data_node);
232 if (classes && !classes->empty()) {
233 result->set("client-classes", classes);
234 }
235
236 checkAndGet(result, data_node, "compatibility",
237 [&](DataNode const& node) -> ElementPtr const {
238 ElementPtr compatibility(Element::createMap());
239 checkAndGetLeaf(compatibility, node, "ignore-rai-link-selection");
240 checkAndGetLeaf(compatibility, node, "lenient-option-parsing");
241 return compatibility;
242 });
243
244 checkAndGet(result, data_node, "config-control",
245 [&](DataNode const& node) -> ElementPtr const {
246 return getConfigControlKea(node);
247 });
248
249 checkAndGet(result, data_node, "control-socket",
250 [&](DataNode const& node) -> ElementPtr const {
251 return getControlSocket(node);
252 });
253
254 checkAndGet(result, data_node, "dhcp-ddns",
255 [&](DataNode const& node) -> ElementPtr const {
256 return getDdnsKea(node);
257 });
258
259 checkAndGet(result, data_node, "expired-leases-processing",
260 [&](DataNode const& node) -> ElementPtr const {
261 return getExpiredKea(node);
262 });
263
264 ConstElementPtr hooks = getHooksKea(data_node);
265 if (hooks && !hooks->empty()) {
266 result->set("hooks-libraries", hooks);
267 }
268
269 ConstElementPtr const& hosts_databases(getDatabases(data_node, "hosts-database"));
270 if (hosts_databases && !hosts_databases->empty()) {
271 result->set("hosts-databases", hosts_databases);
272 }
273
274 checkAndGet(result, data_node, "lease-database",
275 [&](DataNode const& node) -> ElementPtr const {
276 return getDatabase(node);
277 });
278
279 ConstElementPtr loggers = getLoggers(data_node);
280 if (loggers && !loggers->empty()) {
281 result->set("loggers", loggers);
282 }
283
284 checkAndGet(result, data_node, "multi-threading",
285 [&](DataNode const& node) -> ElementPtr const {
286 ElementPtr multi_threading(Element::createMap());
287 checkAndGetLeaf(multi_threading, node, "enable-multi-threading");
288 checkAndGetLeaf(multi_threading, node, "packet-queue-size");
289 checkAndGetLeaf(multi_threading, node, "thread-pool-size");
290 return multi_threading;
291 });
292
293 ConstElementPtr options = getOptionDataList(data_node);
294 if (options) {
295 result->set("option-data", options);
296 }
297
298 ConstElementPtr defs = getOptionDefList(data_node);
299 if (defs) {
300 result->set("option-def", defs);
301 }
302
303 ConstElementPtr hosts = getHosts(data_node);
304 if (hosts) {
305 result->set("reservations", hosts);
306 }
307
308 ConstElementPtr networks = getSharedNetworks(data_node);
309 if (networks) {
310 result->set("shared-networks", networks);
311 }
312
313 checkAndGet(result, data_node, "sanity-checks",
314 [&](DataNode const& node) -> ElementPtr const {
315 ElementPtr sanity_checks = Element::createMap();
316 checkAndGetLeaf(sanity_checks, node, "extended-info-checks");
317 checkAndGetLeaf(sanity_checks, node, "lease-checks");
318 return sanity_checks;
319 });
320
321 return (result);
322}
323
326 string xpath = "/kea-dhcp4-server:config";
327 optional<DataNode> config_optional;
328 try {
329 config_optional = findXPath(xpath);
330 } catch (NetconfError const&) {
331 return ElementPtr();
332 }
333 DataNode const config(*config_optional);
334 ElementPtr result = getServerKeaDhcpCommon(config);
335
336 // Handle DHCPv4 specific global parameters.
337 checkAndGetLeaf(result, config, "authoritative");
338 checkAndGetLeaf(result, config, "boot-file-name");
339 checkAndGetLeaf(result, config, "echo-client-id");
340 checkAndGetLeaf(result, config, "match-client-id");
341 checkAndGetLeaf(result, config, "next-server");
342 checkAndGetLeaf(result, config, "offer-lifetime");
343 checkAndGetLeaf(result, config, "server-hostname");
344
345 checkAndGet(result, config, "compatibility",
346 [&](DataNode const& node) -> ElementPtr const {
347 // If it exists, add to the existing compatibility map created in getServerKeaDhcpCommon.
348 ConstElementPtr const_compatibility(result->get("compatibility"));
349 ElementPtr compatibility;
350 if (const_compatibility) {
351 compatibility = copy(const_compatibility);
352 } else {
353 compatibility = Element::createMap();
354 }
355
356 checkAndGetLeaf(compatibility, node, "exclude-first-last-24");
357 checkAndGetLeaf(compatibility, node, "ignore-dhcp-server-identifier");
358 return compatibility;
359 });
360
361 // Handle interfaces.
362 ElementPtr interfaces_config(getInterfacesKea(config));
363 if (interfaces_config) {
364 result->set("interfaces-config", interfaces_config);
365 }
366
367 // Handle subnets.
368 ConstElementPtr subnets = getSubnets(config);
369 if (subnets) {
370 result->set("subnet4", subnets);
371 }
372
373 return (result);
374}
375
378 string xpath = "/kea-dhcp6-server:config";
379 optional<DataNode> config_optional;
380 try {
381 config_optional = findXPath(xpath);
382 } catch (NetconfError const&) {
383 return ElementPtr();
384 }
385 DataNode const config(*config_optional);
386 ElementPtr result = getServerKeaDhcpCommon(config);
387
388 // Handle DHCPv6 specific global parameters.
389 checkAndGetLeaf(result, config, "data-directory");
390 checkAndGetLeaf(result, config, "mac-sources");
391 checkAndGetLeaf(result, config, "max-preferred-lifetime");
392 checkAndGetLeaf(result, config, "min-preferred-lifetime");
393 checkAndGetLeaf(result, config, "pd-allocator");
394 checkAndGetLeaf(result, config, "preferred-lifetime");
395 checkAndGetLeaf(result, config, "relay-supplied-options");
396
397 // Handle interfaces.
398 ElementPtr interfaces_config(getInterfacesKea(config));
399 if (interfaces_config) {
400 result->set("interfaces-config", interfaces_config);
401 }
402
403 // Handle server-id.
404 optional<DataNode> const& server_id_optional(config.findPath("server-id"));
405 if (server_id_optional) {
406 DataNode const server_id(*server_id_optional);
407 ElementPtr server_id_map(Element::createMap());
408 checkAndGetLeaf(server_id_map, server_id, "type");
409 checkAndGetLeaf(server_id_map, server_id, "identifier");
410 checkAndGetLeaf(server_id_map, server_id, "time");
411 checkAndGetLeaf(server_id_map, server_id, "htype");
412 checkAndGetLeaf(server_id_map, server_id, "enterprise-id");
413 checkAndGetLeaf(server_id_map, server_id, "persist");
414 checkAndGetAndJsonifyLeaf(server_id_map, server_id, "user-context");
415 if (!server_id_map->empty()) {
416 result->set("server-id", server_id_map);
417 }
418 }
419
420 // Handle subnets.
421 ConstElementPtr subnets = getSubnets(config);
422 if (subnets) {
423 result->set("subnet6", subnets);
424 }
425
426 return (result);
427}
428
429void
431 try {
432 if (model_ == IETF_DHCPV6_SERVER) {
433 if (elem) {
435 setConfigIetf6(elem);
436 } else {
438 }
439 } else if (model_ == KEA_DHCP4_SERVER) {
440 if (elem) {
442 setConfigKea4(elem);
443 } else {
444 delConfigKea();
445 }
446 } else if (model_ == KEA_DHCP6_SERVER) {
447 if (elem) {
449 setConfigKea6(elem);
450 } else {
451 delConfigKea();
452 }
453 } else {
455 "setConfig not implemented for the model: " << model_);
456 }
457 } catch (Error const& ex) {
459 "setting config '" << elem->str()
460 << "': " << ex.what());
461 }
462}
463
464void
466 deleteItem("/" + model_ + ":server");
467}
468
469void
471 string xpath = "/" + model_ + ":server/server-config";
472 ConstElementPtr dhcp6 = elem->get("Dhcp6");
473 if (!dhcp6) {
474 isc_throw(BadValue, "no Dhcp6 entry in " << elem->str());
475 }
476
477 ConstElementPtr ranges = dhcp6->get("subnet6");
478 if (ranges && !ranges->empty()) {
479 setSubnets(xpath + "/network-ranges", ranges);
480 }
481
482 // Skip everything else.
483}
484
485void
487 deleteItem("/" + model_ + ":config");
488}
489
490void
492 ConstElementPtr dhcp = elem->get("Dhcp4");
493 if (dhcp) {
494 setServerKeaDhcp4(dhcp);
495 }
496}
497
498void
500 ConstElementPtr dhcp = elem->get("Dhcp6");
501 if (dhcp) {
502 setServerKeaDhcp6(dhcp);
503 }
504}
505
506void
508 ConstElementPtr elem) {
509 checkAndSetLeaf(elem, xpath, "allocator", LeafBaseType::String);
510 checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
511 checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
512 checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool);
513 checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String);
514 checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool);
515 checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool);
516 checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String);
517 checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String);
518 checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool);
519 checkAndSetLeaf(elem, xpath, "ddns-ttl-percent", LeafBaseType::Dec64);
520 checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool);
521 checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool);
522 checkAndSetLeaf(elem, xpath, "dhcp4o6-port", LeafBaseType::Uint16);
523 checkAndSetLeaf(elem, xpath, "decline-probation-period", LeafBaseType::Uint32);
524 checkAndSetLeaf(elem, xpath, "early-global-reservations-lookup", LeafBaseType::Bool);
525 checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
526 checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
527 checkAndSetLeaf(elem, xpath, "ip-reservations-unique", LeafBaseType::Bool);
528 checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
529 checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
530 checkAndSetLeaf(elem, xpath, "parked-packet-limit", LeafBaseType::Uint32);
531 checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
532 checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
533 checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum);
534 checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
535 checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
536 checkAndSetLeaf(elem, xpath, "reservations-lookup-first", LeafBaseType::Bool);
537 checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
538 checkAndSetLeaf(elem, xpath, "server-tag", LeafBaseType::String);
539 checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", LeafBaseType::Uint32);
540 checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", LeafBaseType::Uint32);
541 checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
542 checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64);
543 checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64);
544 checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
545
546 checkAndSetLeafList(elem, xpath, "host-reservation-identifiers", LeafBaseType::Enum);
547
548 checkAndStringifyAndSetLeaf(elem, xpath, "dhcp-queue-control");
549
550 checkAndSetUserContext(elem, xpath);
551
552 ConstElementPtr classes = elem->get("client-classes");
553 if (classes && !classes->empty()) {
554 setClasses(xpath, classes);
555 }
556
557 ConstElementPtr compatibility(elem->get("compatibility"));
558 if (compatibility) {
559 checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-rai-link-selection", LeafBaseType::Bool);
560 checkAndSetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing", LeafBaseType::Bool);
561 }
562
563 ConstElementPtr config_ctrl = elem->get("config-control");
564 if (config_ctrl && !config_ctrl->empty()) {
565 checkAndSetLeaf(config_ctrl, xpath + "/config-control", "config-fetch-wait-time", LeafBaseType::Uint32);
566 ConstElementPtr config_databases = config_ctrl->get("config-databases");
567 if (config_databases && !config_databases->empty()) {
568 setDatabases(xpath + "/config-control/config-database", config_databases);
569 }
570 }
571
572 ConstElementPtr socket = elem->get("control-socket");
573 if (socket && !socket->empty()) {
574 setControlSocket(xpath + "/control-socket", socket);
575 }
576
577 ConstElementPtr ddns = elem->get("dhcp-ddns");
578 if (ddns) {
579 string const ddns_xpath(xpath + "/dhcp-ddns");
580 checkAndSetLeaf(ddns, ddns_xpath, "enable-updates", LeafBaseType::Bool);
581 checkAndSetLeaf(ddns, ddns_xpath, "generated-prefix", LeafBaseType::String);
582 checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-replacement", LeafBaseType::String);
583 checkAndSetLeaf(ddns, ddns_xpath, "hostname-char-set", LeafBaseType::String);
584 checkAndSetLeaf(ddns, ddns_xpath, "max-queue-size", LeafBaseType::Uint32);
585 checkAndSetLeaf(ddns, ddns_xpath, "ncr-format", LeafBaseType::Enum);
586 checkAndSetLeaf(ddns, ddns_xpath, "ncr-protocol", LeafBaseType::Enum);
587 checkAndSetLeaf(ddns, ddns_xpath, "override-client-update", LeafBaseType::Bool);
588 checkAndSetLeaf(ddns, ddns_xpath, "override-no-update", LeafBaseType::Bool);
589 checkAndSetLeaf(ddns, ddns_xpath, "qualifying-suffix", LeafBaseType::String);
590 checkAndSetLeaf(ddns, ddns_xpath, "replace-client-name", LeafBaseType::Enum);
591 checkAndSetLeaf(ddns, ddns_xpath, "sender-ip", LeafBaseType::String);
592 checkAndSetLeaf(ddns, ddns_xpath, "sender-port", LeafBaseType::Uint16);
593 checkAndSetLeaf(ddns, ddns_xpath, "server-ip", LeafBaseType::String);
594 checkAndSetLeaf(ddns, ddns_xpath, "server-port", LeafBaseType::Uint16);
595 checkAndSetUserContext(ddns, ddns_xpath);
596 }
597
598 ConstElementPtr expired = elem->get("expired-leases-processing");
599 if (expired) {
600 string const expired_xpath(xpath + "/expired-leases-processing");
601 checkAndSetLeaf(expired, expired_xpath, "flush-reclaimed-timer-wait-time", LeafBaseType::Uint32);
602 checkAndSetLeaf(expired, expired_xpath, "hold-reclaimed-time", LeafBaseType::Uint32);
603 checkAndSetLeaf(expired, expired_xpath, "max-reclaim-leases", LeafBaseType::Uint32);
604 checkAndSetLeaf(expired, expired_xpath, "max-reclaim-time", LeafBaseType::Uint32);
605 checkAndSetLeaf(expired, expired_xpath, "reclaim-timer-wait-time", LeafBaseType::Uint32);
606 checkAndSetLeaf(expired, expired_xpath, "unwarned-reclaim-cycles", LeafBaseType::Uint32);
607 }
608
609 ConstElementPtr hook_libs = elem->get("hooks-libraries");
610 if (hook_libs) {
611 for (ElementPtr const& lib : hook_libs->listValue()) {
612 ConstElementPtr name = lib->get("library");
613 if (!name) {
614 continue;
615 }
616 ostringstream hook_lib;
617 hook_lib << xpath << "/hook-library[library='"
618 << name->stringValue() << "']";
619 string const hook_xpath(hook_lib.str());
620 setItem(hook_xpath, ElementPtr(), LeafBaseType::Unknown);
621 checkAndStringifyAndSetLeaf(lib, hook_xpath, "parameters");
622 }
623 }
624
625 ConstElementPtr hosts_databases = elem->get("hosts-databases");
626 if (hosts_databases && !hosts_databases->empty()) {
627 setDatabases(xpath + "/hosts-database", hosts_databases);
628 }
629
630 ConstElementPtr database = elem->get("lease-database");
631 if (database && !database->empty()) {
632 setDatabase(xpath + "/lease-database", database);
633 }
634
635 ConstElementPtr loggers = elem->get("loggers");
636 if (loggers) {
637 setLoggers(xpath, loggers);
638 }
639
640 ConstElementPtr multi_threading(elem->get("multi-threading"));
641 if (multi_threading) {
642 string const mt_xpath(xpath + "/multi-threading");
643 checkAndSetLeaf(multi_threading, mt_xpath, "enable-multi-threading", LeafBaseType::Bool);
644 checkAndSetLeaf(multi_threading, mt_xpath, "packet-queue-size", LeafBaseType::Uint32);
645 checkAndSetLeaf(multi_threading, mt_xpath, "thread-pool-size", LeafBaseType::Uint32);
646 }
647
648 ConstElementPtr options = elem->get("option-data");
649 if (options && !options->empty()) {
650 setOptionDataList(xpath, options);
651 }
652
653 ConstElementPtr defs = elem->get("option-def");
654 if (defs && !defs->empty()) {
655 setOptionDefList(xpath, defs);
656 }
657
658 ConstElementPtr hosts = elem->get("reservations");
659 if (hosts && !hosts->empty()) {
660 setHosts(xpath, hosts);
661 }
662
663 ConstElementPtr sanity = elem->get("sanity-checks");
664 if (sanity) {
665 checkAndSetLeaf(sanity, xpath + "/sanity-checks", "extended-info-checks", LeafBaseType::Enum);
666 checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", LeafBaseType::Enum);
667 }
668
669 ConstElementPtr networks = elem->get("shared-networks");
670 if (networks && !networks->empty()) {
671 setSharedNetworks(xpath, networks);
672 }
673}
674
675void
677 string xpath = "/kea-dhcp4-server:config";
678
679 setServerKeaDhcpCommon(xpath, elem);
680
681 checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool);
682 checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
683 checkAndSetLeaf(elem, xpath, "echo-client-id", LeafBaseType::Bool);
684 checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool);
685 checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
686 checkAndSetLeaf(elem, xpath, "offer-lifetime", LeafBaseType::Uint32);
687 checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
688
689 ConstElementPtr compatibility(elem->get("compatibility"));
690 if (compatibility) {
691 checkAndSetLeaf(compatibility, xpath + "/compatibility", "exclude-first-last-24", LeafBaseType::Bool);
692 checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-dhcp-server-identifier", LeafBaseType::Bool);
693 }
694
695 ConstElementPtr if_config = elem->get("interfaces-config");
696 if (if_config) {
697 string const if_cfg_xpath(xpath + "/interfaces-config");
698 checkAndSetLeaf(if_config, if_cfg_xpath, "dhcp-socket-type", LeafBaseType::Enum);
699 checkAndSetLeaf(if_config, if_cfg_xpath, "outbound-interface", LeafBaseType::Enum);
700 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
701 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
702 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
703 checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
704 checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
705 checkAndSetUserContext(if_config, if_cfg_xpath);
706 }
707
708 ConstElementPtr subnets = elem->get("subnet4");
709 if (subnets) {
710 setSubnets(xpath, subnets);
711 }
712}
713
714void
716 string xpath = "/kea-dhcp6-server:config";
717
718 setServerKeaDhcpCommon(xpath, elem);
719
720 checkAndSetLeaf(elem, xpath, "data-directory", LeafBaseType::String);
721 checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
722 checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
723 checkAndSetLeaf(elem, xpath, "pd-allocator", LeafBaseType::String);
724 checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
725
726 checkAndSetLeafList(elem, xpath, "mac-sources", LeafBaseType::String);
727 checkAndSetLeafList(elem, xpath, "relay-supplied-options", LeafBaseType::String);
728
729 ConstElementPtr if_config = elem->get("interfaces-config");
730 if (if_config) {
731 string const if_cfg_xpath(xpath + "/interfaces-config");
732 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
733 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
734 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
735 checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
736 checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
737 checkAndSetUserContext(if_config, if_cfg_xpath);
738 }
739
740 ConstElementPtr server_id = elem->get("server-id");
741 if (server_id) {
742 string const srv_id_xpath(xpath + "/server-id");
743 checkAndSetLeaf(server_id, srv_id_xpath, "type", LeafBaseType::Enum);
744 checkAndSetLeaf(server_id, srv_id_xpath, "identifier", LeafBaseType::String);
745 checkAndSetLeaf(server_id, srv_id_xpath, "time", LeafBaseType::Uint32);
746 checkAndSetLeaf(server_id, srv_id_xpath, "htype", LeafBaseType::Uint16);
747 checkAndSetLeaf(server_id, srv_id_xpath, "enterprise-id", LeafBaseType::Uint32);
748 checkAndSetLeaf(server_id, srv_id_xpath, "persist", LeafBaseType::Bool);
749 checkAndSetUserContext(server_id, srv_id_xpath);
750 }
751
752 ConstElementPtr subnets = elem->get("subnet6");
753 if (subnets) {
754 setSubnets(xpath, subnets);
755 }
756}
757
758} // namespace yang
759} // namespace isc
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 ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:304
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.
A translator class for converting a client class list 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.
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.
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::ElementPtr getControlSocket(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 skip=false)
Translate and set database access from JSON to YANG.
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::ElementPtr getDatabases(libyang::DataNode const &data_node, std::string const &xpath)
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(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.
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 loggers from JSON to YANG.
isc::data::ConstElementPtr getLoggers(libyang::DataNode const &data_node)
Translate loggers from YANG to JSON.
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.
A translator class for converting a shared network list between YANG and JSON.
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.
Definition: translator.h:23
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.
Definition: translator.h:274
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.
Definition: translator.cc:63
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...
Definition: translator.h:44
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
Definition: translator.cc:132
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...
Definition: translator.cc:32
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.
Definition: translator.cc:99
void deleteItem(const std::string &xpath)
Delete basic value from YANG.
Definition: translator.cc:120
void setItem(const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
Translate and set basic value from JSON to YANG.
Definition: translator.cc:231
std::string model_
The model.
Definition: translator.h:427
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,...
Definition: translator.cc:53
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.
Definition: translator.cc:86
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.
Definition: translator.cc:109
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...
Definition: translator.h:71
#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.
Definition: data.cc:1420
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
boost::shared_ptr< Element > ElementPtr
Definition: data.h:28
Defines the logger used by the top-level component of kea-lfc.
Generic NETCONF error.
Definition: netconf_error.h:30