Kea  1.5.0
adaptor_subnet.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_subnet.h>
8 
9 using namespace std;
10 using namespace isc::data;
11 using namespace isc::dhcp;
12 
13 namespace isc {
14 namespace yang {
15 
16 AdaptorSubnet::AdaptorSubnet() {
17 }
18 
19 AdaptorSubnet::~AdaptorSubnet() {
20 }
21 
22 bool
23 AdaptorSubnet::collectID(ConstElementPtr subnet, SubnetIDSet& set) {
24  ConstElementPtr id = subnet->get("id");
25  if (id) {
26  set.insert(static_cast<SubnetID>(id->intValue()));
27  return (true);
28  }
29  return (false);
30 }
31 
32 void
33 AdaptorSubnet::assignID(ElementPtr subnet, SubnetIDSet& set, SubnetID& next) {
34  ConstElementPtr id = subnet->get("id");
35  if (!id) {
36  // Skip already used.
37  while (set.count(next) > 0) {
38  ++next;
39  }
40  subnet->set("id", Element::create(static_cast<long long>(next)));
41  set.insert(next);
42  ++next;
43  }
44 }
45 
46 void
47 AdaptorSubnet::updateRelay(ElementPtr subnet) {
48  ConstElementPtr relay = subnet->get("relay");
49  if (!relay) {
50  return;
51  }
52  ConstElementPtr addresses = relay->get("ip-addresses");
53  if (!addresses) {
54  ConstElementPtr address = relay->get("ip-address");
55  if (!address) {
56  subnet->remove("relay");
57  return;
58  }
59  ElementPtr addr = Element::create(address->stringValue());
60  ElementPtr addrs = Element::createList();
61  addrs->add(addr);
62  ElementPtr updated = Element::createMap();
63  updated->set("ip-addresses", addrs);
64  subnet->set("relay", updated);
65  } else if (addresses->size() == 0) {
66  subnet->remove("relay");
67  }
68 }
69 
70 }; // end of namespace isc::yang
71 }; // end of namespace isc
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::set< isc::dhcp::SubnetID > SubnetIDSet
Set of SubnetIDs.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24