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