11 #include <boost/make_shared.hpp>
22 FreeLeaseQueue::FreeLeaseQueue()
30 if (!ranges_.empty()) {
33 ranges_.insert(RangeDescriptor{range.
start_, range.
end_, 128, boost::make_shared<Leases>()});
43 if (!ranges_.empty()) {
45 checkRangeOverlaps(range.
start_, last_addr);
48 boost::make_shared<Leases>()});
53 const uint8_t delegated_length) {
60 if (ranges_.empty()) {
65 auto lb = ranges_.upper_bound(address);
69 if (lb == ranges_.begin()) {
74 if ((lb->range_end_ < address) || (address < lb->range_start_)) {
88 if (ranges_.empty()) {
93 auto lb = ranges_.upper_bound(prefix);
97 if (lb == ranges_.begin()) {
102 if ((lb->range_end_ < prefix) || (prefix < lb->range_start_) ||
103 (delegated_length != lb->delegated_length_)) {
107 PrefixRange range(lb->range_start_, lb->range_end_, lb->delegated_length_);
117 checkRangeBoundaries(range, address);
118 auto cont = getLeases(range);
119 cont->insert(address);
124 auto desc = getRangeDescriptor(range_index);
125 if ((ip < desc.range_start_) || (desc.range_end_ < ip)) {
127 <<
":" << desc.range_end_);
129 desc.leases_->insert(ip);
134 checkRangeBoundaries(range, prefix,
true);
135 auto cont = getLeases(range);
136 cont->insert(prefix);
141 checkRangeBoundaries(range, address);
142 auto cont = getLeases(range);
143 auto found = cont->find(address);
144 if (found != cont->end()) {
145 static_cast<void>(cont->erase(found));
153 checkRangeBoundaries(range, prefix,
true);
154 auto cont = getLeases(range);
155 auto found = cont->find(prefix);
156 if (found != cont->end()) {
157 static_cast<void>(cont->erase(found));
163 template<
typename RangeType>
165 FreeLeaseQueue::checkRangeBoundaries(
const RangeType& range,
const IOAddress& ip,
166 const bool prefix)
const {
167 if ((ip < range.start_) || (range.end_ < ip)) {
168 isc_throw(
BadValue, (prefix ?
"prefix " :
"address ") << ip <<
" is not within the range of "
169 << range.start_ <<
":" << range.end_);
174 FreeLeaseQueue::checkRangeOverlaps(
const IOAddress& start,
const IOAddress& end)
const {
178 auto next_range = ranges_.lower_bound(start);
181 auto previous_range = ranges_.end();
184 if (next_range != ranges_.begin()) {
188 auto it = next_range;
201 if ((previous_range != ranges_.end()) &&
202 (start <= previous_range->range_end_)) {
203 isc_throw(BadValue,
"new address range " << start <<
":" << end
204 <<
" overlaps with the existing range");
209 if ((next_range != ranges_.end()) &&
210 (next_range->range_start_ <= end)) {
211 isc_throw(BadValue,
"new address range " << start <<
":" << end
212 <<
" overlaps with the existing range");
217 FreeLeaseQueue::LeasesPtr
218 FreeLeaseQueue::getLeases(
const AddressRange& range)
const {
219 auto cont = ranges_.find(range.start_);
220 if (cont == ranges_.end()) {
221 isc_throw(BadValue,
"container for the specified address range " << range.start_
222 <<
":" << range.end_ <<
" does not exist");
224 return (cont->leases_);
227 FreeLeaseQueue::LeasesPtr
228 FreeLeaseQueue::getLeases(
const PrefixRange& range)
const {
229 auto cont = ranges_.find(range.start_);
230 if (cont == ranges_.end()) {
231 isc_throw(BadValue,
"container for the specified prefix " << range.start_
232 <<
" and delegated length of " << static_cast<int>(range.delegated_length_)
233 <<
" does not exist");
235 return (cont->leases_);
238 FreeLeaseQueue::RangeDescriptor
239 FreeLeaseQueue::getRangeDescriptor(
const uint64_t range_index)
const {
240 if (ranges_.get<2>().size() <= range_index) {
241 isc_throw(BadValue,
"container for the specified range index " << range_index
242 <<
" does not exist");
244 auto cont = ranges_.get<2>().at(range_index);
Structure representing delegated prefix range.
asiolink::IOAddress end_
IP address denoting the end of the address range.
void addRange(const AddressRange &range)
Adds new address range to the queue.
bool use(const AddressRange &range, const asiolink::IOAddress &address)
Removes the specified address from the free addresses.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Defines the logger used by the top-level component of kea-dhcp-ddns.
bool append(const asiolink::IOAddress &address)
Appends an address to the end of the queue for a range.
asiolink::IOAddress end_
IP address denoting the first address within the last prefix in the prefix range. ...
Structure representing IP address range.
asiolink::IOAddress start_
IP address denoting the start of the address range.
IOAddress offsetAddress(const IOAddress &addr, uint64_t offset)
Finds the address increased by offset.
asiolink::IOAddress start_
IP address denoting the start of the prefix range.
The IOAddress class represents an IP addresses (version agnostic)
uint8_t delegated_length_
Delegated prefix length.