Kea  2.1.7-git
translator_config.cc
Go to the documentation of this file.
1 // Copyright (C) 2018-2021 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 
10 #include <yang/adaptor_config.h>
11 #include <yang/yang_models.h>
12 #include <sstream>
13 
14 using namespace std;
15 using namespace isc::data;
16 using namespace sysrepo;
17 
18 namespace isc {
19 namespace yang {
20 
21 TranslatorConfig::TranslatorConfig(S_Session session, const string& model)
22  : TranslatorBasic(session, model),
23  TranslatorControlSocket(session, model),
24  TranslatorDatabase(session, model),
25  TranslatorDatabases(session, model),
26  TranslatorOptionData(session, model),
27  TranslatorOptionDataList(session, model),
28  TranslatorOptionDef(session, model),
29  TranslatorOptionDefList(session, model),
30  TranslatorClass(session, model),
31  TranslatorClasses(session, model),
32  TranslatorPool(session, model),
33  TranslatorPools(session, model),
34  TranslatorPdPool(session, model),
35  TranslatorPdPools(session, model),
36  TranslatorHost(session, model),
37  TranslatorHosts(session, model),
38  TranslatorSubnet(session, model),
39  TranslatorSubnets(session, model),
40  TranslatorSharedNetwork(session, model),
41  TranslatorSharedNetworks(session, model),
42  TranslatorLogger(session, model),
43  TranslatorLoggers(session, model) {
44 }
45 
47 }
48 
51  try {
52  if (model_ == IETF_DHCPV6_SERVER) {
53  return (getConfigIetf6());
54  } else if (model_ == KEA_DHCP4_SERVER) {
55  return (getConfigKea4());
56  } else if (model_ == KEA_DHCP6_SERVER) {
57  return (getConfigKea6());
58  }
59  } catch (const sysrepo_exception& ex) {
60  isc_throw(SysrepoError, "sysrepo error getting config: " << ex.what());
61  }
63  "getConfig not implemented for the model: " << model_);
64 }
65 
68  ElementPtr result = Element::createMap();
69  ElementPtr dhcp6 = Element::createMap();
70  result->set("Dhcp6", dhcp6);
71  string xpath = "/" + model_ + ":server/server-config";
72  ConstElementPtr ranges =
73  getSubnets(xpath + "/network-ranges");
74  if (ranges && !ranges->empty()) {
75  dhcp6->set("subnet6", ranges);
76  }
77  // Skip everything else.
78  return (result);
79 }
80 
83  ElementPtr result = Element::createMap();
85  result->set("Dhcp4", dhcp);
86  return (result);
87 }
88 
91  ElementPtr result = Element::createMap();
93  result->set("Dhcp6", dhcp);
94  return (result);
95 }
96 
97 ElementPtr TranslatorConfig::getHook(string const& xpath) {
98  ElementPtr const& hook_library(Element::createMap());
99  ElementPtr const& name(getItem(xpath + "/library"));
100  if (name) {
101  hook_library->set("library", name);
102  ElementPtr const& parameters(getItem(xpath + "/parameters"));
103  if (parameters) {
104  hook_library->set("parameters",
105  Element::fromJSON(parameters->stringValue()));
106  }
107  }
108  return hook_library;
109 }
110 
112 TranslatorConfig::getHooksKea(const std::string& xpath) {
113  return getList(xpath + "/hook-library", *this, &TranslatorConfig::getHook);
114 }
115 
117 TranslatorConfig::getExpiredKea(const std::string& xpath) {
118  ElementPtr expired = Element::createMap();
119 
120  checkAndGetLeaf(expired, xpath, "reclaim-timer-wait-time");
121  checkAndGetLeaf(expired, xpath, "flush-reclaimed-timer-wait-time");
122  checkAndGetLeaf(expired, xpath, "hold-reclaimed-time");
123  checkAndGetLeaf(expired, xpath, "max-reclaim-leases");
124  checkAndGetLeaf(expired, xpath, "max-reclaim-time");
125  checkAndGetLeaf(expired, xpath, "unwarned-reclaim-cycles");
126 
127  if (!expired->empty()) {
128  return (expired);
129  }
130 
131  return (ElementPtr());
132 }
133 
135 TranslatorConfig::getDdnsKea(const std::string& xpath) {
136  ElementPtr ddns = Element::createMap();
137  checkAndGetLeaf(ddns, xpath, "enable-updates");
138  checkAndGetLeaf(ddns, xpath, "qualifying-suffix");
139  checkAndGetLeaf(ddns, xpath, "server-ip");
140  checkAndGetLeaf(ddns, xpath, "server-port");
141  checkAndGetLeaf(ddns, xpath, "sender-ip");
142  checkAndGetLeaf(ddns, xpath, "sender-port");
143  checkAndGetLeaf(ddns, xpath, "max-queue-size");
144  checkAndGetLeaf(ddns, xpath, "ncr-protocol");
145  checkAndGetLeaf(ddns, xpath, "ncr-format");
146  checkAndGetLeaf(ddns, xpath, "override-no-update");
147  checkAndGetLeaf(ddns, xpath, "override-client-update");
148  checkAndGetLeaf(ddns, xpath, "replace-client-name");
149  checkAndGetLeaf(ddns, xpath, "generated-prefix");
150  checkAndGetLeaf(ddns, xpath, "hostname-char-set");
151  checkAndGetLeaf(ddns, xpath, "hostname-char-replacement");
152 
153  ConstElementPtr context = getItem(xpath + "/user-context");
154  if (context) {
155  ddns->set("user-context", Element::fromJSON(context->stringValue()));
156  }
157 
158  if (!ddns->empty()) {
159  // If there's something to return, use it.
160  return (ddns);
161  }
162 
163  // If not, return null.
164  return (ElementPtr());
165 }
166 
169  ElementPtr config_ctrl = Element::createMap();
170  checkAndGetLeaf(config_ctrl, xpath, "config-fetch-wait-time");
171  ConstElementPtr databases = getDatabases(xpath + "/config-database");
172  if (databases && !databases->empty()) {
173  config_ctrl->set("config-databases", databases);
174  }
175  if (!config_ctrl->empty()) {
176  // If there's something to return, use it.
177  return (config_ctrl);
178  }
179 
180  // If not, return null.
181  return (ElementPtr());
182 }
183 
186  ElementPtr result = Element::createMap();
187 
188  checkAndGetLeaf(result, xpath, "valid-lifetime");
189  checkAndGetLeaf(result, xpath, "min-valid-lifetime");
190  checkAndGetLeaf(result, xpath, "max-valid-lifetime");
191  checkAndGetLeaf(result, xpath, "renew-timer");
192  checkAndGetLeaf(result, xpath, "rebind-timer");
193  checkAndGetLeaf(result, xpath, "calculate-tee-times");
194  checkAndGetLeaf(result, xpath, "t1-percent");
195  checkAndGetLeaf(result, xpath, "t2-percent");
196  checkAndGetLeaf(result, xpath, "decline-probation-period");
197  checkAndGetLeaf(result, xpath, "hostname-char-set");
198  checkAndGetLeaf(result, xpath, "hostname-char-replacement");
199 
200  ConstElementPtr networks = getSharedNetworks(xpath);
201  if (networks && !networks->empty()) {
202  result->set("shared-networks", networks);
203  }
204  ConstElementPtr classes = getClasses(xpath);
205  if (classes && !classes->empty()) {
206  result->set("client-classes", classes);
207  }
208  ConstElementPtr database = getDatabase(xpath + "/lease-database");
209  if (database) {
210  result->set("lease-database", database);
211  }
212  ConstElementPtr databases = getDatabases(xpath + "/hosts-database");
213  if (databases && !databases->empty()) {
214  result->set("hosts-databases", databases);
215  }
216  ConstElementPtr host_ids =
217  getItems(xpath + "/host-reservation-identifiers");
218  if (host_ids) {
219  result->set("host-reservation-identifiers", host_ids);
220  }
221  ConstElementPtr defs = getOptionDefList(xpath);
222  if (defs && !defs->empty()) {
223  result->set("option-def", defs);
224  }
225  ConstElementPtr options = getOptionDataList(xpath);
226  if (options && !options->empty()) {
227  result->set("option-data", options);
228  }
229  ConstElementPtr hooks = getHooksKea(xpath);
230  if (hooks && !hooks->empty()) {
231  result->set("hooks-libraries", hooks);
232  }
233  ConstElementPtr expired =
234  getExpiredKea(xpath + "/expired-leases-processing");
235  if (expired) {
236  result->set("expired-leases-processing", expired);
237  }
238  checkAndGetLeaf(result, xpath, "dhcp4o6-port");
239  ConstElementPtr socket = getControlSocket(xpath + "/control-socket");
240  if (socket) {
241  result->set("control-socket", socket);
242  }
243  ConstElementPtr ddns = getDdnsKea(xpath + "/dhcp-ddns");
244  if (ddns) {
245  result->set("dhcp-ddns", ddns);
246  }
247  ConstElementPtr context = getItem(xpath + "/user-context");
248  if (context) {
249  result->set("user-context", Element::fromJSON(context->stringValue()));
250  }
251  ConstElementPtr checks = getItem(xpath + "/sanity-checks/lease-checks");
252  if (checks) {
253  ElementPtr sanity = Element::createMap();
254  sanity->set("lease-checks", checks);
255  result->set("sanity-checks", sanity);
256  }
257  checkAndGetLeaf(result, xpath, "reservation-mode");
258  ConstElementPtr hosts = getHosts(xpath);
259  if (hosts && !hosts->empty()) {
260  result->set("reservations", hosts);
261  }
262  ConstElementPtr config_ctrl =
263  getConfigControlKea(xpath + "/config-control");
264  if (config_ctrl) {
265  result->set("config-control", config_ctrl);
266  }
267  checkAndGetLeaf(result, xpath, "server-tag");
268  ConstElementPtr queue_ctrl = getItem(xpath + "/dhcp-queue-control");
269  if (queue_ctrl) {
270  result->set("dhcp-queue-control",
271  Element::fromJSON(queue_ctrl->stringValue()));
272  }
273  ConstElementPtr loggers = getLoggers(xpath);
274  if (loggers && !loggers->empty()) {
275  result->set("loggers", loggers);
276  }
277  checkAndGetLeaf(result, xpath, "cache-max-age");
278  checkAndGetLeaf(result, xpath, "cache-threshold");
279  ElementPtr compatibility = Element::createMap();
280  checkAndGetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing");
281  if (!compatibility->empty()) {
282  result->set("compatibility", compatibility);
283  }
284  checkAndGetLeaf(result, xpath, "ddns-generated-prefix");
285  checkAndGetLeaf(result, xpath, "ddns-override-client-update");
286  checkAndGetLeaf(result, xpath, "ddns-override-no-update");
287  checkAndGetLeaf(result, xpath, "ddns-qualifying-suffix");
288  checkAndGetLeaf(result, xpath, "ddns-replace-client-name");
289  checkAndGetLeaf(result, xpath, "ddns-send-updates");
290  checkAndGetLeaf(result, xpath, "ddns-update-on-renew");
291  checkAndGetLeaf(result, xpath, "ddns-use-conflict-resolution");
292  checkAndGetLeaf(result, xpath, "ip-reservations-unique");
293  ElementPtr multi_threading = Element::createMap();
294  checkAndGetLeaf(multi_threading, xpath + "/multi-threading", "enable-multi-threading");
295  checkAndGetLeaf(multi_threading, xpath + "/multi-threading", "packet-queue-size");
296  checkAndGetLeaf(multi_threading, xpath + "/multi-threading", "thread-pool-size");
297  if (!multi_threading->empty()) {
298  result->set("multi-threading", multi_threading);
299  }
300  checkAndGetLeaf(result, xpath, "parked-packet-limit");
301  checkAndGetLeaf(result, xpath, "reservations-global");
302  checkAndGetLeaf(result, xpath, "reservations-in-subnet");
303  checkAndGetLeaf(result, xpath, "reservations-out-of-pool");
304  checkAndGetLeaf(result, xpath, "statistic-default-sample-age");
305  checkAndGetLeaf(result, xpath, "statistic-default-sample-count");
306  checkAndGetLeaf(result, xpath, "store-extended-info");
307  return (result);
308 }
309 
312  string xpath = "/kea-dhcp4-server:config";
313  ElementPtr result = getServerKeaDhcpCommon(xpath);
314  // Handle subnets.
315  ConstElementPtr subnets = getSubnets(xpath);
316  if (subnets && !subnets->empty()) {
317  result->set("subnet4", subnets);
318  }
319  // Handle interfaces.
320  ElementPtr if_config = Element::createMap();
321  ConstElementPtr ifs = getItems(xpath + "/interfaces-config/interfaces");
322  if (ifs && !ifs->empty()) {
323  if_config->set("interfaces", ifs);
324  }
325  checkAndGetLeaf(if_config, xpath + "/interfaces-config", "dhcp-socket-type");
326  checkAndGetLeaf(if_config, xpath + "/interfaces-config", "outbound-interface");
327  checkAndGetLeaf(if_config, xpath + "/interfaces-config", "re-detect");
328  ConstElementPtr context =
329  getItem(xpath + "/interfaces-config/user-context");
330  if (context) {
331  if_config->set("user-context",
332  Element::fromJSON(context->stringValue()));
333  }
334  if (!if_config->empty()) {
335  result->set("interfaces-config", if_config);
336  }
337  // Handle DHCPv4 specific global parameters.
338  checkAndGetLeaf(result, xpath, "echo-client-id");
339  checkAndGetLeaf(result, xpath, "match-client-id");
340  checkAndGetLeaf(result, xpath, "next-server");
341  checkAndGetLeaf(result, xpath, "server-hostname");
342  checkAndGetLeaf(result, xpath, "boot-file-name");
343  checkAndGetLeaf(result, xpath, "authoritative");
344  return (result);
345 }
346 
349  string xpath = "/kea-dhcp6-server:config";
350  ElementPtr result = getServerKeaDhcpCommon(xpath);
351  // Handle DHCPv6 specific global parameters.
352  checkAndGetLeaf(result, xpath, "data-directory");
353  checkAndGetLeaf(result, xpath, "preferred-lifetime");
354  checkAndGetLeaf(result, xpath, "min-preferred-lifetime");
355  checkAndGetLeaf(result, xpath, "max-preferred-lifetime");
356  // Handle subnets.
357  ConstElementPtr subnets = getSubnets(xpath);
358  if (subnets && !subnets->empty()) {
359  result->set("subnet6", subnets);
360  }
361  // Handle interfaces.
362  ElementPtr if_config = Element::createMap();
363  ConstElementPtr ifs = getItems(xpath + "/interfaces-config/interfaces");
364  if (ifs && !ifs->empty()) {
365  if_config->set("interfaces", ifs);
366  }
367  checkAndGetLeaf(if_config, xpath + "/interfaces-config", "re-detect");
368  ConstElementPtr context =
369  getItem(xpath + "/interfaces-config/user-context");
370  if (context) {
371  if_config->set("user-context",
372  Element::fromJSON(context->stringValue()));
373  }
374  if (!if_config->empty()) {
375  result->set("interfaces-config", if_config);
376  }
377  // Handle DHCPv6 specific global entries.
378  ConstElementPtr relay = getItems(xpath + "/relay-supplied-options");
379  if (relay) {
380  result->set("relay-supplied-options", relay);
381  }
382  ConstElementPtr macs = getItems(xpath + "/mac-sources");
383  if (macs) {
384  result->set("mac-sources", macs);
385  }
386  // Handle server-id.
387  // @todo: move to a DUID translator.
388  ElementPtr server_id = Element::createMap();
389  checkAndGetLeaf(server_id, xpath + "/server-id", "type");
390  checkAndGetLeaf(server_id, xpath + "/server-id", "identifier");
391  checkAndGetLeaf(server_id, xpath + "/server-id", "time");
392  checkAndGetLeaf(server_id, xpath + "/server-id", "htype");
393  checkAndGetLeaf(server_id, xpath + "/server-id", "enterprise-id");
394  checkAndGetLeaf(server_id, xpath + "/server-id", "persist");
395  context = getItem(xpath + "/server-id/user-context");
396  if (context) {
397  server_id->set("user-context",
398  Element::fromJSON(context->stringValue()));
399  }
400  if (!server_id->empty()) {
401  result->set("server-id", server_id);
402  }
403  return (result);
404 }
405 
406 void
408  try {
409  if (model_ == IETF_DHCPV6_SERVER) {
410  if (elem) {
412  setConfigIetf6(elem);
413  } else {
414  delConfigIetf6();
415  }
416  } else if (model_ == KEA_DHCP4_SERVER) {
417  if (elem) {
419  setConfigKea4(elem);
420  } else {
421  delConfigKea();
422  }
423  } else if (model_ == KEA_DHCP6_SERVER) {
424  if (elem) {
426  setConfigKea6(elem);
427  } else {
428  delConfigKea();
429  }
430  } else {
432  "setConfig not implemented for the model: " << model_);
433  }
434  } catch (const sysrepo_exception& ex) {
436  "sysrepo error setting config '" << elem->str()
437  << "': " << ex.what());
438  }
439 }
440 
441 void
443  delItem("/" + model_ + ":server");
444 }
445 
446 void
448  string xpath = "/" + model_ + ":server/server-config";
449  ConstElementPtr dhcp6 = elem->get("Dhcp6");
450  if (!dhcp6) {
451  isc_throw(BadValue, "no Dhcp6 entry in " << elem->str());
452  }
453  ConstElementPtr ranges = dhcp6->get("subnet6");
454  if (ranges && !ranges->empty()) {
455  setSubnets(xpath + "/network-ranges", ranges);
456  }
457  // Skip everything else.
458 }
459 
460 void
462  delItem("/" + model_ + ":config");
463 }
464 
465 void
467  ConstElementPtr dhcp = elem->get("Dhcp4");
468  if (dhcp) {
469  setServerKeaDhcp4(dhcp);
470  }
471 }
472 
473 void
475  ConstElementPtr dhcp = elem->get("Dhcp6");
476  if (dhcp) {
477  setServerKeaDhcp6(dhcp);
478  }
479 }
480 
481 void
483  ConstElementPtr elem) {
484  ConstElementPtr valid = elem->get("valid-lifetime");
485  if (valid) {
486  setItem(xpath + "/valid-lifetime", valid, SR_UINT32_T);
487  }
488  ConstElementPtr min_valid = elem->get("min-valid-lifetime");
489  if (min_valid) {
490  setItem(xpath + "/min-valid-lifetime", min_valid, SR_UINT32_T);
491  }
492  ConstElementPtr max_valid = elem->get("max-valid-lifetime");
493  if (max_valid) {
494  setItem(xpath + "/max-valid-lifetime", max_valid, SR_UINT32_T);
495  }
496  ConstElementPtr renew = elem->get("renew-timer");
497  if (renew) {
498  setItem(xpath + "/renew-timer", renew, SR_UINT32_T);
499  }
500  ConstElementPtr rebind = elem->get("rebind-timer");
501  if (rebind) {
502  setItem(xpath + "/rebind-timer", rebind, SR_UINT32_T);
503  }
504  ConstElementPtr calculate = elem->get("calculate-tee-times");
505  if (calculate) {
506  setItem(xpath + "/calculate-tee-times", calculate, SR_BOOL_T);
507  }
508  ConstElementPtr t1_percent = elem->get("t1-percent");
509  if (t1_percent) {
510  setItem(xpath + "/t1-percent", t1_percent, SR_DECIMAL64_T);
511  }
512  ConstElementPtr t2_percent = elem->get("t2-percent");
513  if (t2_percent) {
514  setItem(xpath + "/t2-percent", t2_percent, SR_DECIMAL64_T);
515  }
516  ConstElementPtr period = elem->get("decline-probation-period");
517  if (period) {
518  setItem(xpath + "/decline-probation-period", period, SR_UINT32_T);
519  }
520  ConstElementPtr networks = elem->get("shared-networks");
521  if (networks) {
522  setSharedNetworks(xpath, networks);
523  }
524  ConstElementPtr classes = elem->get("client-classes");
525  if (classes && !classes->empty()) {
526  setClasses(xpath, classes);
527  }
528  ConstElementPtr database = elem->get("lease-database");
529  if (database) {
530  setDatabase(xpath + "/lease-database", database);
531  }
532  ConstElementPtr databases = elem->get("hosts-databases");
533  if (databases && !databases->empty()) {
534  setDatabases(xpath + "/hosts-database", databases);
535  } else {
536  // Reuse of database from lease-database.
537  database = elem->get("hosts-database");
538  if (database) {
539  ElementPtr list = Element::createList();
540  list->add(copy(database));
541  setDatabases(xpath + "/hosts-database", list);
542  }
543  }
544  ConstElementPtr host_ids = elem->get("host-reservation-identifiers");
545  if (host_ids) {
546  for (ConstElementPtr id : host_ids->listValue()) {
547  setItem(xpath + "/host-reservation-identifiers", id, SR_ENUM_T);
548  }
549  }
550  ConstElementPtr defs = elem->get("option-def");
551  if (defs && !defs->empty()) {
552  setOptionDefList(xpath, defs);
553  }
554  ConstElementPtr options = elem->get("option-data");
555  if (options && !options->empty()) {
556  setOptionDataList(xpath, options);
557  }
558  ConstElementPtr hook_libs = elem->get("hooks-libraries");
559  if (hook_libs) {
560  for (ConstElementPtr lib : hook_libs->listValue()) {
561  ConstElementPtr name = lib->get("library");
562  if (!name) {
563  continue;
564  }
565  ostringstream hook_lib;
566  hook_lib << xpath << "/hook-library[library='"
567  << name->stringValue() << "']";
568  ConstElementPtr params = lib->get("parameters");
569  if (params) {
570  hook_lib << "/parameters";
571  setItem(hook_lib.str(), Element::create(params->str()),
572  SR_STRING_T);
573  } else {
574  ConstElementPtr list = Element::createList();
575  setItem(hook_lib.str(), list, SR_LIST_T);
576  }
577  }
578  }
579  ConstElementPtr expired = elem->get("expired-leases-processing");
580  if (expired) {
581  ConstElementPtr reclaim = expired->get("reclaim-timer-wait-time");
582  if (reclaim) {
583  setItem(xpath + "/expired-leases-processing/reclaim-timer-wait-time",
584  reclaim, SR_UINT32_T);
585  }
586  ConstElementPtr flush =
587  expired->get("flush-reclaimed-timer-wait-time");
588  if (flush) {
589  setItem(xpath + "/expired-leases-processing/flush-reclaimed-timer-wait-time",
590  flush, SR_UINT32_T);
591  }
592  ConstElementPtr hold = expired->get("hold-reclaimed-time");
593  if (hold) {
594  setItem(xpath + "/expired-leases-processing/hold-reclaimed-time",
595  hold, SR_UINT32_T);
596  }
597  ConstElementPtr max_leases = expired->get("max-reclaim-leases");
598  if (max_leases) {
599  setItem(xpath + "/expired-leases-processing/max-reclaim-leases",
600  max_leases, SR_UINT32_T);
601  }
602  ConstElementPtr max_time = expired->get("max-reclaim-time");
603  if (max_time) {
604  setItem(xpath + "/expired-leases-processing/max-reclaim-time",
605  max_time, SR_UINT32_T);
606  }
607  ConstElementPtr unwarned = expired->get("unwarned-reclaim-cycles");
608  if (unwarned) {
609  setItem(xpath + "/expired-leases-processing/unwarned-reclaim-cycles",
610  unwarned, SR_UINT32_T);
611  }
612  }
613  ConstElementPtr port = elem->get("dhcp4o6-port");
614  if (port) {
615  setItem(xpath + "/dhcp4o6-port", port, SR_UINT16_T);
616  }
617  ConstElementPtr socket = elem->get("control-socket");
618  if (socket) {
619  setControlSocket(xpath + "/control-socket", socket);
620  }
621  ConstElementPtr char_set = elem->get("hostname-char-set");
622  if (char_set) {
623  setItem(xpath + "/hostname-char-set", char_set, SR_STRING_T);
624  }
625  ConstElementPtr char_repl = elem->get("hostname-char-replacement");
626  if (char_repl) {
627  setItem(xpath + "/hostname-char-replacement", char_repl, SR_STRING_T);
628  }
629  ConstElementPtr ddns = elem->get("dhcp-ddns");
630  if (ddns) {
631  ConstElementPtr enable = ddns->get("enable-updates");
632  if (enable) {
633  setItem(xpath + "/dhcp-ddns/enable-updates", enable, SR_BOOL_T);
634  }
635  ConstElementPtr suffix = ddns->get("qualifying-suffix");
636  if (suffix) {
637  setItem(xpath + "/dhcp-ddns/qualifying-suffix", suffix,
638  SR_STRING_T);
639  }
640  ConstElementPtr server_ip = ddns->get("server-ip");
641  if (server_ip) {
642  setItem(xpath + "/dhcp-ddns/server-ip", server_ip, SR_STRING_T);
643  }
644  ConstElementPtr server_port = ddns->get("server-port");
645  if (server_port) {
646  setItem(xpath + "/dhcp-ddns/server-port", server_port,
647  SR_UINT16_T);
648  }
649  ConstElementPtr sender_ip = ddns->get("sender-ip");
650  if (sender_ip) {
651  setItem(xpath + "/dhcp-ddns/sender-ip", sender_ip, SR_STRING_T);
652  }
653  ConstElementPtr sender_port = ddns->get("sender-port");
654  if (sender_port) {
655  setItem(xpath + "/dhcp-ddns/sender-port", sender_port,
656  SR_UINT16_T);
657  }
658  ConstElementPtr queue = ddns->get("max-queue-size");
659  if (queue) {
660  setItem(xpath + "/dhcp-ddns/max-queue-size", queue, SR_UINT32_T);
661  }
662  ConstElementPtr protocol = ddns->get("ncr-protocol");
663  if (protocol) {
664  setItem(xpath + "/dhcp-ddns/ncr-protocol", protocol, SR_ENUM_T);
665  }
666  ConstElementPtr format = ddns->get("ncr-format");
667  if (format) {
668  setItem(xpath + "/dhcp-ddns/ncr-format", format, SR_ENUM_T);
669  }
670  ConstElementPtr no_up = ddns->get("override-no-update");
671  if (no_up) {
672  setItem(xpath + "/dhcp-ddns/override-no-update", no_up, SR_BOOL_T);
673  }
674  ConstElementPtr client = ddns->get("override-client-update");
675  if (client) {
676  setItem(xpath + "/dhcp-ddns/override-client-update", client,
677  SR_BOOL_T);
678  }
679  ConstElementPtr replace = ddns->get("replace-client-name");
680  if (replace) {
681  setItem(xpath + "/dhcp-ddns/replace-client-name", replace,
682  SR_ENUM_T);
683  }
684  ConstElementPtr generated = ddns->get("generated-prefix");
685  if (generated) {
686  setItem(xpath + "/dhcp-ddns/generated-prefix", generated,
687  SR_STRING_T);
688  }
689  ConstElementPtr char_set = ddns->get("hostname-char-set");
690  if (char_set) {
691  setItem(xpath + "/dhcp-ddns/hostname-char-set", char_set,
692  SR_STRING_T);
693  }
694  ConstElementPtr char_repl = ddns->get("hostname-char-replacement");
695  if (char_repl) {
696  setItem(xpath + "/dhcp-ddns/hostname-char-replacement", char_repl,
697  SR_STRING_T);
698  }
699  ConstElementPtr context = Adaptor::getContext(ddns);
700  if (context) {
701  ConstElementPtr repr = Element::create(context->str());
702  setItem(xpath + "/dhcp-ddns/user-context", repr, SR_STRING_T);
703  }
704  }
705  ConstElementPtr context = Adaptor::getContext(elem);
706  if (context) {
707  ConstElementPtr repr = Element::create(context->str());
708  setItem(xpath + "/user-context", repr, SR_STRING_T);
709  }
710  ConstElementPtr sanity = elem->get("sanity-checks");
711  if (sanity) {
712  ConstElementPtr checks = sanity->get("lease-checks");
713  if (checks) {
714  setItem(xpath + "/sanity-checks/lease-checks", checks, SR_ENUM_T);
715  }
716  }
717  ConstElementPtr hr_mode = elem->get("reservation-mode");
718  if (hr_mode) {
719  setItem(xpath + "/reservation-mode", hr_mode, SR_ENUM_T);
720  }
721  ConstElementPtr hosts = elem->get("reservations");
722  if (hosts && !hosts->empty()) {
723  setHosts(xpath, hosts);
724  }
725  ConstElementPtr config_ctrl = elem->get("config-control");
726  if (config_ctrl && !config_ctrl->empty()) {
727  ConstElementPtr cfwt = config_ctrl->get("config-fetch-wait-time");
728  if (cfwt) {
729  setItem(xpath + "/config-control/config-fetch-wait-time", cfwt,
730  SR_UINT32_T);
731  }
732  databases = config_ctrl->get("config-databases");
733  if (databases && !databases->empty()) {
734  setDatabases(xpath + "/config-control/config-database", databases);
735  }
736  }
737  ConstElementPtr server_tag = elem->get("server-tag");
738  if (server_tag) {
739  setItem(xpath + "/server-tag", server_tag, SR_STRING_T);
740  }
741  ConstElementPtr queue_ctrl = elem->get("dhcp-queue-control");
742  if (queue_ctrl) {
743  ConstElementPtr repr = Element::create(queue_ctrl->str());
744  setItem(xpath + "/dhcp-queue-control", repr, SR_STRING_T);
745  }
746  ConstElementPtr loggers = elem->get("loggers");
747  if (loggers) {
748  setLoggers(xpath, loggers);
749  }
750  checkAndSetLeaf(elem, xpath, "cache-max-age", SR_UINT32_T);
751  checkAndSetLeaf(elem, xpath, "cache-threshold", SR_DECIMAL64_T);
752  ConstElementPtr compatibility(elem->get("compatibility"));
753  if (compatibility) {
754  checkAndSetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing", SR_BOOL_T);
755  }
756  checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", SR_STRING_T);
757  checkAndSetLeaf(elem, xpath, "ddns-override-client-update", SR_BOOL_T);
758  checkAndSetLeaf(elem, xpath, "ddns-override-no-update", SR_BOOL_T);
759  checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", SR_STRING_T);
760  checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", SR_STRING_T);
761  checkAndSetLeaf(elem, xpath, "ddns-send-updates", SR_BOOL_T);
762  checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", SR_BOOL_T);
763  checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", SR_BOOL_T);
764  checkAndSetLeaf(elem, xpath, "ip-reservations-unique", SR_BOOL_T);
765  ConstElementPtr multi_threading(elem->get("multi-threading"));
766  if (multi_threading) {
767  checkAndSetLeaf(multi_threading, xpath + "/multi-threading", "enable-multi-threading", SR_BOOL_T);
768  checkAndSetLeaf(multi_threading, xpath + "/multi-threading", "packet-queue-size", SR_UINT32_T);
769  checkAndSetLeaf(multi_threading, xpath + "/multi-threading", "thread-pool-size", SR_UINT32_T);
770  }
771  checkAndSetLeaf(elem, xpath, "parked-packet-limit", SR_UINT32_T);
772  checkAndSetLeaf(elem, xpath, "reservations-global", SR_BOOL_T);
773  checkAndSetLeaf(elem, xpath, "reservations-in-subnet", SR_BOOL_T);
774  checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", SR_BOOL_T);
775  checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", SR_UINT32_T);
776  checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", SR_UINT32_T);
777  checkAndSetLeaf(elem, xpath, "store-extended-info", SR_BOOL_T);
778 }
779 
780 void
782  string xpath = "/kea-dhcp4-server:config";
783  setServerKeaDhcpCommon(xpath, elem);
784  ConstElementPtr subnets = elem->get("subnet4");
785  if (subnets) {
786  setSubnets(xpath, subnets);
787  }
788  ConstElementPtr if_config = elem->get("interfaces-config");
789  if (if_config) {
790  ConstElementPtr ifs = if_config->get("interfaces");
791  if (ifs && !ifs->empty()) {
792  for (ConstElementPtr intf : ifs->listValue()) {
793  setItem(xpath + "/interfaces-config/interfaces",
794  intf, SR_STRING_T);
795  }
796  }
797  ConstElementPtr ds_type = if_config->get("dhcp-socket-type");
798  if (ds_type) {
799  setItem(xpath + "/interfaces-config/dhcp-socket-type",
800  ds_type, SR_ENUM_T);
801  }
802  ConstElementPtr out_if = if_config->get("outbound-interface");
803  if (out_if) {
804  setItem(xpath + "/interfaces-config/outbound-interface",
805  out_if, SR_ENUM_T);
806  }
807  ConstElementPtr redetect = if_config->get("re-detect");
808  if (redetect) {
809  setItem(xpath + "/interfaces-config/re-detect",
810  redetect, SR_BOOL_T);
811  }
812  ConstElementPtr context = Adaptor::getContext(if_config);
813  if (context) {
814  setItem(xpath + "/interfaces-config/user-context",
815  Element::create(context->str()), SR_STRING_T);
816  }
817  }
818  ConstElementPtr echo = elem->get("echo-client-id");
819  if (echo) {
820  setItem(xpath + "/echo-client-id", echo, SR_BOOL_T);
821  }
822  ConstElementPtr match = elem->get("match-client-id");
823  if (match) {
824  setItem(xpath + "/match-client-id", match, SR_BOOL_T);
825  }
826  ConstElementPtr next = elem->get("next-server");
827  if (next) {
828  setItem(xpath + "/next-server", next, SR_STRING_T);
829  }
830  ConstElementPtr hostname = elem->get("server-hostname");
831  if (hostname) {
832  setItem(xpath + "/server-hostname", hostname, SR_STRING_T);
833  }
834  ConstElementPtr boot = elem->get("boot-file-name");
835  if (boot) {
836  setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
837  }
838  ConstElementPtr auth = elem->get("authoritative");
839  if (auth) {
840  setItem(xpath + "/authoritative", auth, SR_BOOL_T);
841  }
842 }
843 
844 void
846  string xpath = "/kea-dhcp6-server:config";
847  setServerKeaDhcpCommon(xpath, elem);
848  ConstElementPtr data_dir = elem->get("data-directory");
849  if (data_dir) {
850  setItem(xpath + "/data-directory", data_dir, SR_STRING_T);
851  }
852  ConstElementPtr preferred = elem->get("preferred-lifetime");
853  if (preferred) {
854  setItem(xpath + "/preferred-lifetime", preferred, SR_UINT32_T);
855  }
856  ConstElementPtr min_pref = elem->get("min-preferred-lifetime");
857  if (min_pref) {
858  setItem(xpath + "/min-preferred-lifetime", min_pref, SR_UINT32_T);
859  }
860  ConstElementPtr max_pref = elem->get("max-preferred-lifetime");
861  if (max_pref) {
862  setItem(xpath + "/max-preferred-lifetime", max_pref, SR_UINT32_T);
863  }
864  ConstElementPtr subnets = elem->get("subnet6");
865  if (subnets) {
866  setSubnets(xpath, subnets);
867  }
868  ConstElementPtr if_config = elem->get("interfaces-config");
869  if (if_config) {
870  ConstElementPtr ifs = if_config->get("interfaces");
871  if (ifs && !ifs->empty()) {
872  for (ConstElementPtr intf : ifs->listValue()) {
873  setItem(xpath + "/interfaces-config/interfaces",
874  intf, SR_STRING_T);
875  }
876  }
877  ConstElementPtr redetect = if_config->get("re-detect");
878  if (redetect) {
879  setItem(xpath + "/interfaces-config/re-detect",
880  redetect, SR_BOOL_T);
881  }
882  ConstElementPtr context = Adaptor::getContext(if_config);
883  if (context) {
884  setItem(xpath + "/interfaces-config/user-context",
885  Element::create(context->str()), SR_STRING_T);
886  }
887  }
888  ConstElementPtr relay = elem->get("relay-supplied-options");
889  if (relay) {
890  for (ConstElementPtr addr : relay->listValue()) {
891  setItem(xpath + "/relay-supplied-options", addr, SR_STRING_T);
892  }
893  }
894  ConstElementPtr macs = elem->get("mac-sources");
895  if (macs) {
896  for (ConstElementPtr source : macs->listValue()) {
897  setItem(xpath + "/mac-sources", source, SR_STRING_T);
898  }
899  }
900  ConstElementPtr server_id = elem->get("server-id");
901  if (server_id) {
902  ConstElementPtr id_type = server_id->get("type");
903  if (id_type) {
904  setItem(xpath + "/server-id/type", id_type, SR_ENUM_T);
905  }
906  ConstElementPtr id_id = server_id->get("identifier");
907  if (id_id) {
908  setItem(xpath + "/server-id/identifier", id_id, SR_STRING_T);
909  }
910  ConstElementPtr id_time = server_id->get("time");
911  if (id_time) {
912  setItem(xpath + "/server-id/time", id_time, SR_UINT32_T);
913  }
914  ConstElementPtr id_htype = server_id->get("htype");
915  if (id_htype) {
916  setItem(xpath + "/server-id/htype", id_htype, SR_UINT16_T);
917  }
918  ConstElementPtr id_ent_id = server_id->get("enterprise-id");
919  if (id_ent_id) {
920  setItem(xpath + "/server-id/enterprise-id", id_ent_id,
921  SR_UINT32_T);
922  }
923  ConstElementPtr id_persist = server_id->get("persist");
924  if (id_persist) {
925  setItem(xpath + "/server-id/persist", id_persist, SR_BOOL_T);
926  }
927  ConstElementPtr context = Adaptor::getContext(server_id);
928  if (context) {
929  ConstElementPtr repr = Element::create(context->str());
930  setItem(xpath + "/server-id/user-context", repr, SR_STRING_T);
931  }
932  }
933 }
934 
935 } // namespace yang
936 } // namespace isc
isc::data::ElementPtr getItems(const std::string &xpath)
Get and translate a list of basic values from YANG to JSON.
Definition: translator.cc:124
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.
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, sr_type_t const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
Definition: translator.cc:283
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.
Definition: translator.h:19
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
Definition: data.h:24
STL namespace.
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.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Shared network translation between YANG and JSON.
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.
Definition: data.cc:1152
void setItem(const std::string &xpath, isc::data::ConstElementPtr elem, sr_type_t type)
Translate and set basic value from JSON to YANG.
Definition: translator.cc:260
Translation between YANG and JSON for a single host reservation.
isc::data::ElementPtr getHook(const std::string &xpath)
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.
Definition: translator.h:171
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
Definition: data.h:27
static void preProcess4(isc::data::ConstElementPtr config)
Pre process a DHCPv4 configuration.
static isc::data::ConstElementPtr getContext(isc::data::ConstElementPtr parent)
Get user context.
Definition: adaptor.cc:27
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.
void delConfigIetf6()
delConfig for ietf-dhcpv6-server.
void delItem(const std::string &xpath)
Delete basic value from YANG.
Definition: translator.cc:294
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-lfc.
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.
Definition: translator.cc:105
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.
void checkAndGetLeaf(isc::data::ElementPtr &storage, const std::string &xpath, const std::string &name)
Retrieves an item and stores it in the specified storage.
Definition: translator.cc:274
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.
isc::data::ElementPtr getList(std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(std::string const &xpath))
Retrieve a list as ElementPtr from sysrepo from a certain xpath.
Definition: translator.h:147
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.
Definition: strutil.cc:157
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.