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