From 52c021ee0b0c6ad2128ed550c694aad0d11d4c3f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 16:53:22 +0200 Subject: Adding upstream version 2.5.7. Signed-off-by: Daniel Baumann --- src/lib/yang/adaptor_pool.cc | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/lib/yang/adaptor_pool.cc (limited to 'src/lib/yang/adaptor_pool.cc') 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 + +#include +#include + +#include + +using namespace std; +using namespace isc::data; + +namespace isc { +namespace yang { + +void +AdaptorPool::canonizePool(ElementPtr pool) { + const string& orig = pool->get("pool")->stringValue(); + vector 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 -- cgit v1.2.3