namespace dhcp {
FreeLeaseQueue::FreeLeaseQueue()
- : containers_() {
+ : ranges_() {
}
void
FreeLeaseQueue::addRange(const AddressRange& range) {
// If the container with ranges is empty, there are is no need for
// doing any checks. Let's just add the new range.
- if (!containers_.empty()) {
+ if (!ranges_.empty()) {
checkRangeOverlaps(range.start_, range.end_);
}
- containers_.insert(ContainerDescriptor{range.start_, range.end_, 128,
- boost::make_shared<Container>()});
+ ranges_.insert(RangeDescriptor{range.start_, range.end_, 128, boost::make_shared<Leases>()});
}
void
void
FreeLeaseQueue::addRange(const PrefixRange& range) {
- if (!containers_.empty()) {
+ if (!ranges_.empty()) {
auto last_addr = offsetAddress(range.end_, range.delegated_length_ - 1);
checkRangeOverlaps(range.start_, last_addr);
}
- containers_.insert(ContainerDescriptor{range.start_, range.end_, range.delegated_length_,
- boost::make_shared<Container>()});
+ ranges_.insert(RangeDescriptor{range.start_, range.end_, range.delegated_length_,
+ boost::make_shared<Leases>()});
}
void
bool
FreeLeaseQueue::append(const IOAddress& address) {
// If there are no ranges defined, there is nothing to do.
- if (containers_.empty()) {
+ if (ranges_.empty()) {
return (false);
}
// Find the beginning of the range which has the start address
// greater than the address we're appending.
- auto lb = containers_.upper_bound(address);
+ auto lb = ranges_.upper_bound(address);
// If the range we found is the first one in the container
// there is no range matching our address because all existing
// ranges include higher addresses.
- if (lb == containers_.begin()) {
+ if (lb == ranges_.begin()) {
return (false);
}
--lb;
bool
FreeLeaseQueue::append(const IOAddress& prefix, const uint8_t delegated_length) {
// If there are no ranges defined, there is nothing to do.
- if (containers_.empty()) {
+ if (ranges_.empty()) {
return (false);
}
// Find the beginning of the range which has the start address
// greater than the address we're appending.
- auto lb = containers_.upper_bound(prefix);
+ auto lb = ranges_.upper_bound(prefix);
// If the range we found is the first one in the container
// there is no range matching our prefix because all existing
// ranges include higher addresses.
- if (lb == containers_.begin()) {
+ if (lb == ranges_.begin()) {
return (false);
}
--lb;
FreeLeaseQueue::append(const AddressRange& range, const IOAddress& address) {
// Make sure the address is within the range boundaries.
checkRangeBoundaries(range, address);
- auto cont = getContainer(range);
+ auto cont = getLeases(range);
cont->insert(address);
}
void
FreeLeaseQueue::append(const uint64_t range_index, const IOAddress& ip) {
- auto desc = getContainerDescriptor(range_index);
+ auto desc = getRangeDescriptor(range_index);
if ((ip < desc.range_start_) || (desc.range_end_ < ip)) {
isc_throw(BadValue, ip << " is not within the range of " << desc.range_start_
<< ":" << desc.range_end_);
}
- desc.container_->insert(ip);
+ desc.leases_->insert(ip);
}
void
FreeLeaseQueue::append(const PrefixRange& range, const asiolink::IOAddress& prefix) {
checkRangeBoundaries(range, prefix, true);
- auto cont = getContainer(range);
+ auto cont = getLeases(range);
cont->insert(prefix);
}
bool
FreeLeaseQueue::use(const AddressRange& range, const IOAddress& address) {
checkRangeBoundaries(range, address);
- auto cont = getContainer(range);
+ auto cont = getLeases(range);
auto found = cont->find(address);
if (found != cont->end()) {
static_cast<void>(cont->erase(found));
bool
FreeLeaseQueue::use(const PrefixRange& range, const IOAddress& prefix) {
checkRangeBoundaries(range, prefix, true);
- auto cont = getContainer(range);
+ auto cont = getLeases(range);
auto found = cont->find(prefix);
if (found != cont->end()) {
static_cast<void>(cont->erase(found));
// Get the next range in the container relative to the start of the new
// range. The upper_bound returns the range which starts after the start
// of the new range.
- auto next_range = containers_.lower_bound(start);
+ auto next_range = ranges_.lower_bound(start);
// Get the range the range that is before that one. It is also possible that
// there is no previous range in which case we default to end().
- auto previous_range = containers_.end();
+ auto previous_range = ranges_.end();
// If the next range is at the beginning of the container there is no
// previous range.
- if (next_range != containers_.begin()) {
+ if (next_range != ranges_.begin()) {
// This should work fine even if the next range is set to end(). We
// will get the range that is one position before end() and that
// should be the range that goes before the new one.
// are constructed such that the end must be greater or equal the start
// it is sufficient to check that the start of the new range is not lower
// or equal the end of the previous range.
- if ((previous_range != containers_.end()) &&
+ if ((previous_range != ranges_.end()) &&
(start <= previous_range->range_end_)) {
isc_throw(BadValue, "new address range " << start << ":" << end
<< " overlaps with the existing range");
// If the next range exists, let's check that the end of the new range
// is neither within that range nor higher.
- if ((next_range != containers_.end()) &&
+ if ((next_range != ranges_.end()) &&
(next_range->range_start_ <= end)) {
isc_throw(BadValue, "new address range " << start << ":" << end
<< " overlaps with the existing range");
}
-FreeLeaseQueue::ContainerPtr
-FreeLeaseQueue::getContainer(const AddressRange& range) const {
- auto cont = containers_.find(range.start_);
- if (cont == containers_.end()) {
+FreeLeaseQueue::LeasesPtr
+FreeLeaseQueue::getLeases(const AddressRange& range) const {
+ auto cont = ranges_.find(range.start_);
+ if (cont == ranges_.end()) {
isc_throw(BadValue, "conatiner for the specified address range " << range.start_
<< ":" << range.end_ << " does not exist");
}
- return (cont->container_);
+ return (cont->leases_);
}
-FreeLeaseQueue::ContainerPtr
-FreeLeaseQueue::getContainer(const PrefixRange& range) const {
- auto cont = containers_.find(range.start_);
- if (cont == containers_.end()) {
+FreeLeaseQueue::LeasesPtr
+FreeLeaseQueue::getLeases(const PrefixRange& range) const {
+ auto cont = ranges_.find(range.start_);
+ if (cont == ranges_.end()) {
isc_throw(BadValue, "conatiner for the specified prefix " << range.start_
<< " and delegated length of " << static_cast<int>(range.delegated_length_)
<< " does not exist");
}
- return (cont->container_);
+ return (cont->leases_);
}
-FreeLeaseQueue::ContainerDescriptor
-FreeLeaseQueue::getContainerDescriptor(const uint64_t range_index) const {
- if (containers_.get<2>().size() <= range_index) {
+FreeLeaseQueue::RangeDescriptor
+FreeLeaseQueue::getRangeDescriptor(const uint64_t range_index) const {
+ if (ranges_.get<2>().size() <= range_index) {
isc_throw(BadValue, "conatiner for the specified range index " << range_index
<< " does not exist");
}
- auto cont = containers_.get<2>().at(range_index);
+ auto cont = ranges_.get<2>().at(range_index);
return (cont);
}
/// @return true if the range existed and was removed.
template<typename RangeType>
bool removeRange(const RangeType& range) {
- return (containers_.get<1>().erase(range.start_) > 0);
+ return (ranges_.get<1>().erase(range.start_) > 0);
}
/// @brief Appends an address at the end of the queue for a range.
/// @throw BadValue if the range does not exist.
template<typename RangeType>
uint64_t getRangeIndex(const RangeType& range) const {
- auto cont = containers_.get<1>().find(range.start_);
- if (cont == containers_.get<1>().end()) {
+ auto cont = ranges_.get<1>().find(range.start_);
+ if (cont == ranges_.get<1>().end()) {
isc_throw(BadValue, "conatiner for the specified range " << range.start_
<< ":" << range.end_ << " does not exist");
}
- return (std::distance(containers_.get<2>().begin(), containers_.project<2>(cont)));
+ return (std::distance(ranges_.get<2>().begin(), ranges_.project<2>(cont)));
}
private:
>,
boost::multi_index::sequenced<>
>
- > Container;
+ > Leases;
/// Pointer to the container of free leases for a range.
- typedef boost::shared_ptr<Container> ContainerPtr;
+ typedef boost::shared_ptr<Leases> LeasesPtr;
/// @brief Helper structure associating a range with the container of
/// free leases.
- struct ContainerDescriptor {
+ struct RangeDescriptor {
/// Range start.
asiolink::IOAddress range_start_;
/// Range end.
/// Delegated length (used in prefix delegation).
uint8_t delegated_length_;
/// Container holding free addresses for the range.
- ContainerPtr container_;
+ LeasesPtr leases_;
};
/// @brief Collection (container) of containers for various ranges.
/// range start value. The second index is the random access index allowing
/// faster access once the range index is known.
typedef boost::multi_index_container<
- ContainerDescriptor,
+ RangeDescriptor,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
- boost::multi_index::member<ContainerDescriptor, asiolink::IOAddress,
- &ContainerDescriptor::range_start_>
+ boost::multi_index::member<RangeDescriptor, asiolink::IOAddress,
+ &RangeDescriptor::range_start_>
>,
boost::multi_index::hashed_unique<
- boost::multi_index::member<ContainerDescriptor, asiolink::IOAddress,
- &ContainerDescriptor::range_start_>
+ boost::multi_index::member<RangeDescriptor, asiolink::IOAddress,
+ &RangeDescriptor::range_start_>
>,
boost::multi_index::random_access<>
>
- > Containers;
+ > Ranges;
/// @brief Checks if the specified address or delegated prefix is within the
/// range.
/// @param range range for which the container should be returned.
/// @return Pointer to the container (if found).
/// @throw BadValue if the specified range does not exist.
- ContainerPtr getContainer(const AddressRange& range) const;
+ LeasesPtr getContainer(const AddressRange& range) const;
/// @brief Returns container for a given prefix range.
///
/// @param range range for which the container should be returned.
/// @return Pointer to the container (if found).
/// @throw BadValue if the specified range does not exist.
- ContainerPtr getContainer(const PrefixRange& range) const;
+ LeasesPtr getContainer(const PrefixRange& range) const;
/// @brief Returns container descriptor for a given range index.
///
/// returned.
/// @return Range descriptor if found.
/// @throw BadValue if the range with the given index does not exist.
- ContainerDescriptor getContainerDescriptor(const uint64_t range_index) const;
+ RangeDescriptor getContainerDescriptor(const uint64_t range_index) const;
/// @brief This is internal implemenation of the @c next and @c pop
/// methods.
/// @brief Holds a collection of containers with free leases for each
/// address range.
- Containers containers_;
+ Ranges ranges_;
};
} // end of namespace isc::dhcp