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