Kea  1.9.9-git
adaptor_pool.cc
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 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 
9 #include <yang/adaptor_pool.h>
10 #include <yang/yang_models.h>
11 
12 using namespace std;
13 using namespace isc::data;
14 
15 namespace isc {
16 namespace yang {
17 
18 AdaptorPool::AdaptorPool() {
19 }
20 
21 AdaptorPool::~AdaptorPool() {
22 }
23 
24 void
25 AdaptorPool::canonizePool(ElementPtr pool) {
26  const string& orig = pool->get("pool")->stringValue();
27  vector<char> v;
28  for (char ch : orig) {
29  if ((ch == ' ') || (ch == '\t') || (ch == '\n')) {
30  continue;
31  } else if (ch == '-') {
32  v.push_back(' ');
33  v.push_back(ch);
34  v.push_back(' ');
35  } else {
36  v.push_back(ch);
37  }
38  }
39  string canon;
40  canon.assign(v.begin(), v.end());
41  if (orig != canon) {
42  pool->set("pool", Element::create(canon));
43  }
44 }
45 
46 void
47 AdaptorPool::fromSubnet(const string& model, ConstElementPtr subnet,
48  ConstElementPtr pools) {
49  if (model == IETF_DHCPV6_SERVER) {
50  fromSubnetIetf6(subnet, pools);
51  } else if ((model != KEA_DHCP4_SERVER) &&
52  (model != KEA_DHCP6_SERVER)) {
54  "fromSubnet not implemented for the model: " << model);
55  }
56 }
57 
58 void
59 AdaptorPool::fromSubnetIetf6(ConstElementPtr subnet, ConstElementPtr pools) {
60  Adaptor::fromParent("valid-lifetime", subnet, pools);
61  Adaptor::fromParent("preferred-lifetime", subnet, pools);
62  Adaptor::fromParent("renew-timer", subnet, pools);
63  Adaptor::fromParent("rebind-timer", subnet, pools);
64 }
65 
66 void
67 AdaptorPool::toSubnet(const string& model, ElementPtr subnet,
68  ConstElementPtr pools) {
69  if (model == IETF_DHCPV6_SERVER) {
70  toSubnetIetf6(subnet, pools);
71  } else if ((model != KEA_DHCP4_SERVER) &&
72  (model != KEA_DHCP6_SERVER)) {
74  "toSubnet not implemented for the model: " << model);
75  }
76 }
77 
78 void
79 AdaptorPool::toSubnetIetf6(ElementPtr subnet, ConstElementPtr pools) {
80  Adaptor::toParent("valid-lifetime", subnet, pools);
81  Adaptor::toParent("preferred-lifetime", subnet, pools);
82  Adaptor::toParent("renew-timer", subnet, pools);
83  Adaptor::toParent("rebind-timer", subnet, pools);
84 }
85 
86 }; // end of namespace isc::yang
87 }; // end of namespace isc
A generic exception that is thrown when a function is not implemented.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
STL namespace.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
Defines the logger used by the top-level component of kea-dhcp-ddns.