summaryrefslogtreecommitdiffstats
path: root/src/lib/yang/adaptor_pool.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 14:53:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 14:53:22 +0000
commit52c021ee0b0c6ad2128ed550c694aad0d11d4c3f (patch)
tree83cf8627b94336cf4bee7479b9749263bbfd3a06 /src/lib/yang/adaptor_pool.cc
parentInitial commit. (diff)
downloadisc-kea-upstream.tar.xz
isc-kea-upstream.zip
Adding upstream version 2.5.7.upstream/2.5.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/yang/adaptor_pool.cc')
-rw-r--r--src/lib/yang/adaptor_pool.cc83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/lib/yang/adaptor_pool.cc b/src/lib/yang/adaptor_pool.cc
new file mode 100644
index 0000000..c6a8572
--- /dev/null
+++ b/src/lib/yang/adaptor_pool.cc
@@ -0,0 +1,83 @@
+// Copyright (C) 2018-2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <yang/adaptor_pool.h>
+#include <yang/yang_models.h>
+
+#include <vector>
+
+using namespace std;
+using namespace isc::data;
+
+namespace isc {
+namespace yang {
+
+void
+AdaptorPool::canonizePool(ElementPtr pool) {
+ const string& orig = pool->get("pool")->stringValue();
+ vector<char> v;
+ for (auto ch : orig) {
+ if ((ch == ' ') || (ch == '\t') || (ch == '\n')) {
+ continue;
+ } else if (ch == '-') {
+ v.push_back(' ');
+ v.push_back(ch);
+ v.push_back(' ');
+ } else {
+ v.push_back(ch);
+ }
+ }
+ string canon;
+ canon.assign(v.begin(), v.end());
+ if (orig != canon) {
+ pool->set("pool", Element::create(canon));
+ }
+}
+
+void
+AdaptorPool::fromSubnet(const string& model, ConstElementPtr subnet,
+ ConstElementPtr pools) {
+ if (model == IETF_DHCPV6_SERVER) {
+ fromSubnetIetf6(subnet, pools);
+ } else if ((model != KEA_DHCP4_SERVER) &&
+ (model != KEA_DHCP6_SERVER)) {
+ isc_throw(NotImplemented,
+ "fromSubnet not implemented for the model: " << model);
+ }
+}
+
+void
+AdaptorPool::fromSubnetIetf6(ConstElementPtr subnet, ConstElementPtr pools) {
+ Adaptor::fromParent("valid-lifetime", subnet, pools);
+ Adaptor::fromParent("preferred-lifetime", subnet, pools);
+ Adaptor::fromParent("renew-timer", subnet, pools);
+ Adaptor::fromParent("rebind-timer", subnet, pools);
+}
+
+void
+AdaptorPool::toSubnet(const string& model, ElementPtr subnet,
+ ConstElementPtr pools) {
+ if (model == IETF_DHCPV6_SERVER) {
+ toSubnetIetf6(subnet, pools);
+ } else if ((model != KEA_DHCP4_SERVER) &&
+ (model != KEA_DHCP6_SERVER)) {
+ isc_throw(NotImplemented,
+ "toSubnet not implemented for the model: " << model);
+ }
+}
+
+void
+AdaptorPool::toSubnetIetf6(ElementPtr subnet, ConstElementPtr pools) {
+ Adaptor::toParent("valid-lifetime", subnet, pools);
+ Adaptor::toParent("preferred-lifetime", subnet, pools);
+ Adaptor::toParent("renew-timer", subnet, pools);
+ Adaptor::toParent("rebind-timer", subnet, pools);
+}
+
+} // namespace yang
+} // namespace isc