Kea 2.7.4
translator_config.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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, "max-queue-size");
135 checkAndGetLeaf(result, data_node, "ncr-format");
136 checkAndGetLeaf(result, data_node, "ncr-protocol");
137 checkAndGetLeaf(result, data_node, "sender-ip");
138 checkAndGetLeaf(result, data_node, "sender-port");
139 checkAndGetLeaf(result, data_node, "server-ip");
140 checkAndGetLeaf(result, data_node, "server-port");
141
142 checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
143
144 return (result->empty() ? ElementPtr() : result);
145}
146
148TranslatorConfig::getConfigControlKea(DataNode const& data_node) {
150 checkAndGetLeaf(result, data_node, "config-fetch-wait-time");
151 ConstElementPtr databases = getDatabases(data_node, "config-database");
152 if (databases && !databases->empty()) {
153 result->set("config-databases", databases);
154 }
155 return (result->empty() ? ElementPtr() : result);
156}
157
159TranslatorConfig::getInterfacesKea(DataNode const& config) {
160 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);
164 result = Element::createMap();
165
166 checkAndGetLeaf(result, interfaces_config, "dhcp-socket-type");
167 checkAndGetLeaf(result, interfaces_config, "interfaces");
168 checkAndGetLeaf(result, interfaces_config, "outbound-interface");
169 checkAndGetLeaf(result, interfaces_config, "re-detect");
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");
173
174 checkAndGetAndJsonifyLeaf(result, interfaces_config, "user-context");
175 }
176 return (result->empty() ? ElementPtr() : result);
177}
178
182
183 checkAndGetLeaf(result, data_node, "allocator");
184 checkAndGetLeaf(result, data_node, "cache-max-age");
185 checkAndGetLeaf(result, data_node, "cache-threshold");
186 checkAndGetLeaf(result, data_node, "calculate-tee-times");
187 checkAndGetLeaf(result, data_node, "dhcp4o6-port");
188 checkAndGetLeaf(result, data_node, "ddns-generated-prefix");
189 checkAndGetLeaf(result, data_node, "ddns-override-client-update");
190 checkAndGetLeaf(result, data_node, "ddns-override-no-update");
191 checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix");
192 checkAndGetLeaf(result, data_node, "ddns-replace-client-name");
193 checkAndGetLeaf(result, data_node, "ddns-send-updates");
194 checkAndGetLeaf(result, data_node, "ddns-ttl-percent");
195 checkAndGetLeaf(result, data_node, "ddns-update-on-renew");
196 checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution");
197 checkAndGetLeaf(result, data_node, "ddns-conflict-resolution-mode");
198 checkAndGetLeaf(result, data_node, "decline-probation-period");
199 checkAndGetLeaf(result, data_node, "early-global-reservations-lookup");
200 checkAndGetLeaf(result, data_node, "host-reservation-identifiers");
201 checkAndGetLeaf(result, data_node, "hostname-char-replacement");
202 checkAndGetLeaf(result, data_node, "hostname-char-set");
203 checkAndGetLeaf(result, data_node, "ip-reservations-unique");
204 checkAndGetLeaf(result, data_node, "max-valid-lifetime");
205 checkAndGetLeaf(result, data_node, "min-valid-lifetime");
206 checkAndGetLeaf(result, data_node, "parked-packet-limit");
207 checkAndGetLeaf(result, data_node, "rebind-timer");
208 checkAndGetLeaf(result, data_node, "renew-timer");
209 checkAndGetLeaf(result, data_node, "reservations-global");
210 checkAndGetLeaf(result, data_node, "reservations-in-subnet");
211 checkAndGetLeaf(result, data_node, "reservations-lookup-first");
212 checkAndGetLeaf(result, data_node, "reservations-out-of-pool");
213 checkAndGetLeaf(result, data_node, "server-tag");
214 checkAndGetLeaf(result, data_node, "statistic-default-sample-age");
215 checkAndGetLeaf(result, data_node, "statistic-default-sample-count");
216 checkAndGetLeaf(result, data_node, "store-extended-info");
217 checkAndGetLeaf(result, data_node, "t1-percent");
218 checkAndGetLeaf(result, data_node, "t2-percent");
219 checkAndGetLeaf(result, data_node, "valid-lifetime");
220
221 checkAndGetAndJsonifyLeaf(result, data_node, "dhcp-queue-control");
222 checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
223
224 ConstElementPtr classes = getClasses(data_node);
225 if (classes && !classes->empty()) {
226 result->set("client-classes", classes);
227 }
228
229 checkAndGet(result, data_node, "compatibility",
230 [&](DataNode const& node) -> ElementPtr const {
231 ElementPtr compatibility(Element::createMap());
232 checkAndGetLeaf(compatibility, node, "ignore-rai-link-selection");
233 checkAndGetLeaf(compatibility, node, "lenient-option-parsing");
234 return compatibility;
235 });
236
237 checkAndGet(result, data_node, "config-control",
238 [&](DataNode const& node) -> ElementPtr const {
239 return getConfigControlKea(node);
240 });
241
242 checkAndGet(result, data_node, "control-socket",
243 [&](DataNode const& node) -> ElementPtr const {
244 return getControlSocket(node);
245 });
246
247 checkAndGet(result, data_node, "dhcp-ddns",
248 [&](DataNode const& node) -> ElementPtr const {
249 return getDdnsKea(node);
250 });
251
252 checkAndGet(result, data_node, "expired-leases-processing",
253 [&](DataNode const& node) -> ElementPtr const {
254 return getExpiredKea(node);
255 });
256
257 ConstElementPtr hooks = getHooksKea(data_node);
258 if (hooks && !hooks->empty()) {
259 result->set("hooks-libraries", hooks);
260 }
261
262 ConstElementPtr const& hosts_databases(getDatabases(data_node, "hosts-database"));
263 if (hosts_databases && !hosts_databases->empty()) {
264 result->set("hosts-databases", hosts_databases);
265 }
266
267 checkAndGet(result, data_node, "lease-database",
268 [&](DataNode const& node) -> ElementPtr const {
269 return getDatabase(node);
270 });
271
272 ConstElementPtr loggers = getLoggers(data_node);
273 if (loggers && !loggers->empty()) {
274 result->set("loggers", loggers);
275 }
276
277 checkAndGet(result, data_node, "multi-threading",
278 [&](DataNode const& node) -> ElementPtr const {
279 ElementPtr multi_threading(Element::createMap());
280 checkAndGetLeaf(multi_threading, node, "enable-multi-threading");
281 checkAndGetLeaf(multi_threading, node, "packet-queue-size");
282 checkAndGetLeaf(multi_threading, node, "thread-pool-size");
283 return multi_threading;
284 });
285
286 ConstElementPtr options = getOptionDataList(data_node);
287 if (options) {
288 result->set("option-data", options);
289 }
290
291 ConstElementPtr defs = getOptionDefList(data_node);
292 if (defs) {
293 result->set("option-def", defs);
294 }
295
296 ConstElementPtr hosts = getHosts(data_node);
297 if (hosts) {
298 result->set("reservations", hosts);
299 }
300
301 ConstElementPtr networks = getSharedNetworks(data_node);
302 if (networks) {
303 result->set("shared-networks", networks);
304 }
305
306 checkAndGet(result, data_node, "sanity-checks",
307 [&](DataNode const& node) -> ElementPtr const {
308 ElementPtr sanity_checks = Element::createMap();
309 checkAndGetLeaf(sanity_checks, node, "extended-info-checks");
310 checkAndGetLeaf(sanity_checks, node, "lease-checks");
311 return sanity_checks;
312 });
313
314 return (result);
315}
316
319 string xpath = "/kea-dhcp4-server:config";
320 optional<DataNode> config_optional;
321 try {
322 config_optional = findXPath(xpath);
323 } catch (NetconfError const&) {
324 return ElementPtr();
325 }
326 DataNode const config(*config_optional);
327 ElementPtr result = getServerKeaDhcpCommon(config);
328
329 // Handle DHCPv4 specific global parameters.
330 checkAndGetLeaf(result, config, "authoritative");
331 checkAndGetLeaf(result, config, "boot-file-name");
332 checkAndGetLeaf(result, config, "echo-client-id");
333 checkAndGetLeaf(result, config, "match-client-id");
334 checkAndGetLeaf(result, config, "next-server");
335 checkAndGetLeaf(result, config, "offer-lifetime");
336 checkAndGetLeaf(result, config, "server-hostname");
337 checkAndGetLeaf(result, config, "stash-agent-options");
338
339 checkAndGet(result, config, "compatibility",
340 [&](DataNode const& node) -> ElementPtr const {
341 // If it exists, add to the existing compatibility map created in getServerKeaDhcpCommon.
342 ConstElementPtr const_compatibility(result->get("compatibility"));
343 ElementPtr compatibility;
344 if (const_compatibility) {
345 compatibility = copy(const_compatibility);
346 } else {
347 compatibility = Element::createMap();
348 }
349
350 checkAndGetLeaf(compatibility, node, "exclude-first-last-24");
351 checkAndGetLeaf(compatibility, node, "ignore-dhcp-server-identifier");
352 return compatibility;
353 });
354
355 // Handle interfaces.
356 ElementPtr interfaces_config(getInterfacesKea(config));
357 if (interfaces_config) {
358 result->set("interfaces-config", interfaces_config);
359 }
360
361 // Handle subnets.
362 ConstElementPtr subnets = getSubnets(config);
363 if (subnets) {
364 result->set("subnet4", subnets);
365 }
366
367 return (result);
368}
369
372 string xpath = "/kea-dhcp6-server:config";
373 optional<DataNode> config_optional;
374 try {
375 config_optional = findXPath(xpath);
376 } catch (NetconfError const&) {
377 return ElementPtr();
378 }
379 DataNode const config(*config_optional);
380 ElementPtr result = getServerKeaDhcpCommon(config);
381
382 // Handle DHCPv6 specific global parameters.
383 checkAndGetLeaf(result, config, "data-directory");
384 checkAndGetLeaf(result, config, "mac-sources");
385 checkAndGetLeaf(result, config, "max-preferred-lifetime");
386 checkAndGetLeaf(result, config, "min-preferred-lifetime");
387 checkAndGetLeaf(result, config, "pd-allocator");
388 checkAndGetLeaf(result, config, "preferred-lifetime");
389 checkAndGetLeaf(result, config, "relay-supplied-options");
390
391 // Handle interfaces.
392 ElementPtr interfaces_config(getInterfacesKea(config));
393 if (interfaces_config) {
394 result->set("interfaces-config", interfaces_config);
395 }
396
397 // Handle server-id.
398 optional<DataNode> const& server_id_optional(config.findPath("server-id"));
399 if (server_id_optional) {
400 DataNode const server_id(*server_id_optional);
401 ElementPtr server_id_map(Element::createMap());
402 checkAndGetLeaf(server_id_map, server_id, "type");
403 checkAndGetLeaf(server_id_map, server_id, "identifier");
404 checkAndGetLeaf(server_id_map, server_id, "time");
405 checkAndGetLeaf(server_id_map, server_id, "htype");
406 checkAndGetLeaf(server_id_map, server_id, "enterprise-id");
407 checkAndGetLeaf(server_id_map, server_id, "persist");
408 checkAndGetAndJsonifyLeaf(server_id_map, server_id, "user-context");
409 if (!server_id_map->empty()) {
410 result->set("server-id", server_id_map);
411 }
412 }
413
414 // Handle subnets.
415 ConstElementPtr subnets = getSubnets(config);
416 if (subnets) {
417 result->set("subnet6", subnets);
418 }
419
420 return (result);
421}
422
423void
425 try {
426 if (model_ == IETF_DHCPV6_SERVER) {
427 if (elem) {
429 setConfigIetf6(elem);
430 } else {
432 }
433 } else if (model_ == KEA_DHCP4_SERVER) {
434 if (elem) {
436 setConfigKea4(elem);
437 } else {
438 delConfigKea();
439 }
440 } else if (model_ == KEA_DHCP6_SERVER) {
441 if (elem) {
443 setConfigKea6(elem);
444 } else {
445 delConfigKea();
446 }
447 } else {
449 "setConfig not implemented for the model: " << model_);
450 }
451 } catch (Error const& ex) {
453 "setting config '" << elem->str()
454 << "': " << ex.what());
455 }
456}
457
458void
460 deleteItem("/" + model_ + ":server");
461}
462
463void
465 string xpath = "/" + model_ + ":server/server-config";
466 ConstElementPtr dhcp6 = elem->get("Dhcp6");
467 if (!dhcp6) {
468 isc_throw(BadValue, "no Dhcp6 entry in " << elem->str());
469 }
470
471 ConstElementPtr ranges = dhcp6->get("subnet6");
472 if (ranges && !ranges->empty()) {
473 setSubnets(xpath + "/network-ranges", ranges);
474 }
475
476 // Skip everything else.
477}
478
479void
481 deleteItem("/" + model_ + ":config");
482}
483
484void
486 ConstElementPtr dhcp = elem->get("Dhcp4");
487 if (dhcp) {
488 setServerKeaDhcp4(dhcp);
489 }
490}
491
492void
494 ConstElementPtr dhcp = elem->get("Dhcp6");
495 if (dhcp) {
496 setServerKeaDhcp6(dhcp);
497 }
498}
499
500void
502 ConstElementPtr elem) {
503 checkAndSetLeaf(elem, xpath, "allocator", LeafBaseType::String);
504 checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
505 checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
506 checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool);
507 checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String);
508 checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool);
509 checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool);
510 checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String);
511 checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String);
512 checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool);
513 checkAndSetLeaf(elem, xpath, "ddns-ttl-percent", LeafBaseType::Dec64);
514 checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool);
515 checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool);
516 checkAndSetLeaf(elem, xpath, "ddns-conflict-resolution-mode", LeafBaseType::Enum);
517 checkAndSetLeaf(elem, xpath, "dhcp4o6-port", LeafBaseType::Uint16);
518 checkAndSetLeaf(elem, xpath, "decline-probation-period", LeafBaseType::Uint32);
519 checkAndSetLeaf(elem, xpath, "early-global-reservations-lookup", LeafBaseType::Bool);
520 checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
521 checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
522 checkAndSetLeaf(elem, xpath, "ip-reservations-unique", LeafBaseType::Bool);
523 checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
524 checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
525 checkAndSetLeaf(elem, xpath, "parked-packet-limit", LeafBaseType::Uint32);
526 checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
527 checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
528 checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
529 checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
530 checkAndSetLeaf(elem, xpath, "reservations-lookup-first", LeafBaseType::Bool);
531 checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
532 checkAndSetLeaf(elem, xpath, "server-tag", LeafBaseType::String);
533 checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", LeafBaseType::Uint32);
534 checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", LeafBaseType::Uint32);
535 checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
536 checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64);
537 checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64);
538 checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
539
540 checkAndSetLeafList(elem, xpath, "host-reservation-identifiers", LeafBaseType::Enum);
541
542 checkAndStringifyAndSetLeaf(elem, xpath, "dhcp-queue-control");
543
544 checkAndSetUserContext(elem, xpath);
545
546 ConstElementPtr classes = elem->get("client-classes");
547 if (classes && !classes->empty()) {
548 setClasses(xpath, classes);
549 }
550
551 ConstElementPtr compatibility(elem->get("compatibility"));
552 if (compatibility) {
553 checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-rai-link-selection", LeafBaseType::Bool);
554 checkAndSetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing", LeafBaseType::Bool);
555 }
556
557 ConstElementPtr config_ctrl = elem->get("config-control");
558 if (config_ctrl && !config_ctrl->empty()) {
559 checkAndSetLeaf(config_ctrl, xpath + "/config-control", "config-fetch-wait-time", LeafBaseType::Uint32);
560 ConstElementPtr config_databases = config_ctrl->get("config-databases");
561 if (config_databases && !config_databases->empty()) {
562 setDatabases(xpath + "/config-control/config-database", config_databases);
563 }
564 }
565
566 ConstElementPtr socket = elem->get("control-socket");
567 if (socket && !socket->empty()) {
568 setControlSocket(xpath + "/control-socket", socket);
569 }
570
571 ConstElementPtr ddns = elem->get("dhcp-ddns");
572 if (ddns) {
573 string const ddns_xpath(xpath + "/dhcp-ddns");
574 checkAndSetLeaf(ddns, ddns_xpath, "enable-updates", LeafBaseType::Bool);
575 checkAndSetLeaf(ddns, ddns_xpath, "max-queue-size", LeafBaseType::Uint32);
576 checkAndSetLeaf(ddns, ddns_xpath, "ncr-format", LeafBaseType::Enum);
577 checkAndSetLeaf(ddns, ddns_xpath, "ncr-protocol", LeafBaseType::Enum);
578 checkAndSetLeaf(ddns, ddns_xpath, "sender-ip", LeafBaseType::String);
579 checkAndSetLeaf(ddns, ddns_xpath, "sender-port", LeafBaseType::Uint16);
580 checkAndSetLeaf(ddns, ddns_xpath, "server-ip", LeafBaseType::String);
581 checkAndSetLeaf(ddns, ddns_xpath, "server-port", LeafBaseType::Uint16);
582 checkAndSetUserContext(ddns, ddns_xpath);
583 }
584
585 ConstElementPtr expired = elem->get("expired-leases-processing");
586 if (expired) {
587 string const expired_xpath(xpath + "/expired-leases-processing");
588 checkAndSetLeaf(expired, expired_xpath, "flush-reclaimed-timer-wait-time", LeafBaseType::Uint32);
589 checkAndSetLeaf(expired, expired_xpath, "hold-reclaimed-time", LeafBaseType::Uint32);
590 checkAndSetLeaf(expired, expired_xpath, "max-reclaim-leases", LeafBaseType::Uint32);
591 checkAndSetLeaf(expired, expired_xpath, "max-reclaim-time", LeafBaseType::Uint32);
592 checkAndSetLeaf(expired, expired_xpath, "reclaim-timer-wait-time", LeafBaseType::Uint32);
593 checkAndSetLeaf(expired, expired_xpath, "unwarned-reclaim-cycles", LeafBaseType::Uint32);
594 }
595
596 ConstElementPtr hook_libs = elem->get("hooks-libraries");
597 if (hook_libs) {
598 for (ElementPtr const& lib : hook_libs->listValue()) {
599 ConstElementPtr name = lib->get("library");
600 if (!name) {
601 continue;
602 }
603 ostringstream hook_lib;
604 hook_lib << xpath << "/hook-library[library='"
605 << name->stringValue() << "']";
606 string const hook_xpath(hook_lib.str());
607 setItem(hook_xpath, ElementPtr(), LeafBaseType::Unknown);
608 checkAndStringifyAndSetLeaf(lib, hook_xpath, "parameters");
609 }
610 }
611
612 ConstElementPtr hosts_databases = elem->get("hosts-databases");
613 if (hosts_databases && !hosts_databases->empty()) {
614 setDatabases(xpath + "/hosts-database", hosts_databases);
615 }
616
617 ConstElementPtr database = elem->get("lease-database");
618 if (database && !database->empty()) {
619 setDatabase(xpath + "/lease-database", database);
620 }
621
622 ConstElementPtr loggers = elem->get("loggers");
623 if (loggers) {
624 setLoggers(xpath, loggers);
625 }
626
627 ConstElementPtr multi_threading(elem->get("multi-threading"));
628 if (multi_threading) {
629 string const mt_xpath(xpath + "/multi-threading");
630 checkAndSetLeaf(multi_threading, mt_xpath, "enable-multi-threading", LeafBaseType::Bool);
631 checkAndSetLeaf(multi_threading, mt_xpath, "packet-queue-size", LeafBaseType::Uint32);
632 checkAndSetLeaf(multi_threading, mt_xpath, "thread-pool-size", LeafBaseType::Uint32);
633 }
634
635 ConstElementPtr options = elem->get("option-data");
636 if (options && !options->empty()) {
637 setOptionDataList(xpath, options);
638 }
639
640 ConstElementPtr defs = elem->get("option-def");
641 if (defs && !defs->empty()) {
642 setOptionDefList(xpath, defs);
643 }
644
645 ConstElementPtr hosts = elem->get("reservations");
646 if (hosts && !hosts->empty()) {
647 setHosts(xpath, hosts);
648 }
649
650 ConstElementPtr sanity = elem->get("sanity-checks");
651 if (sanity) {
652 checkAndSetLeaf(sanity, xpath + "/sanity-checks", "extended-info-checks", LeafBaseType::Enum);
653 checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", LeafBaseType::Enum);
654 }
655
656 ConstElementPtr networks = elem->get("shared-networks");
657 if (networks && !networks->empty()) {
658 setSharedNetworks(xpath, networks);
659 }
660}
661
662void
664 string xpath = "/kea-dhcp4-server:config";
665
666 setServerKeaDhcpCommon(xpath, elem);
667
668 checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool);
669 checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
670 checkAndSetLeaf(elem, xpath, "echo-client-id", LeafBaseType::Bool);
671 checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool);
672 checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
673 checkAndSetLeaf(elem, xpath, "offer-lifetime", LeafBaseType::Uint32);
674 checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
675 checkAndSetLeaf(elem, xpath, "stash-agent-options", LeafBaseType::Bool);
676
677 ConstElementPtr compatibility(elem->get("compatibility"));
678 if (compatibility) {
679 checkAndSetLeaf(compatibility, xpath + "/compatibility", "exclude-first-last-24", LeafBaseType::Bool);
680 checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-dhcp-server-identifier", LeafBaseType::Bool);
681 }
682
683 ConstElementPtr if_config = elem->get("interfaces-config");
684 if (if_config) {
685 string const if_cfg_xpath(xpath + "/interfaces-config");
686 checkAndSetLeaf(if_config, if_cfg_xpath, "dhcp-socket-type", LeafBaseType::Enum);
687 checkAndSetLeaf(if_config, if_cfg_xpath, "outbound-interface", LeafBaseType::Enum);
688 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
689 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
690 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
691 checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
692 checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
693 checkAndSetUserContext(if_config, if_cfg_xpath);
694 }
695
696 ConstElementPtr subnets = elem->get("subnet4");
697 if (subnets) {
698 setSubnets(xpath, subnets);
699 }
700}
701
702void
704 string xpath = "/kea-dhcp6-server:config";
705
706 setServerKeaDhcpCommon(xpath, elem);
707
708 checkAndSetLeaf(elem, xpath, "data-directory", LeafBaseType::String);
709 checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
710 checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
711 checkAndSetLeaf(elem, xpath, "pd-allocator", LeafBaseType::String);
712 checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
713
714 checkAndSetLeafList(elem, xpath, "mac-sources", LeafBaseType::String);
715 checkAndSetLeafList(elem, xpath, "relay-supplied-options", LeafBaseType::String);
716
717 ConstElementPtr if_config = elem->get("interfaces-config");
718 if (if_config) {
719 string const if_cfg_xpath(xpath + "/interfaces-config");
720 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
721 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
722 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
723 checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
724 checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
725 checkAndSetUserContext(if_config, if_cfg_xpath);
726 }
727
728 ConstElementPtr server_id = elem->get("server-id");
729 if (server_id) {
730 string const srv_id_xpath(xpath + "/server-id");
731 checkAndSetLeaf(server_id, srv_id_xpath, "type", LeafBaseType::Enum);
732 checkAndSetLeaf(server_id, srv_id_xpath, "identifier", LeafBaseType::String);
733 checkAndSetLeaf(server_id, srv_id_xpath, "time", LeafBaseType::Uint32);
734 checkAndSetLeaf(server_id, srv_id_xpath, "htype", LeafBaseType::Uint16);
735 checkAndSetLeaf(server_id, srv_id_xpath, "enterprise-id", LeafBaseType::Uint32);
736 checkAndSetLeaf(server_id, srv_id_xpath, "persist", LeafBaseType::Bool);
737 checkAndSetUserContext(server_id, srv_id_xpath);
738 }
739
740 ConstElementPtr subnets = elem->get("subnet6");
741 if (subnets) {
742 setSubnets(xpath, subnets);
743 }
744}
745
746} // namespace yang
747} // 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.
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.
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.
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.
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.