23 generator_.seed(rd());
27RandomAllocator::pickAddressInternal(
const ClientClasses& client_classes,
31 auto const& pools = subnet->getPools(
pool_type_);
37 std::vector<uint64_t> available;
38 std::vector<uint64_t> exhausted;
39 for (
auto i = 0; i < pools.size(); ++i) {
41 if (pools[i]->clientSupported(client_classes)) {
43 auto state = getPoolState(pools[i]);
44 if (state->getPermutation()->exhausted()) {
49 exhausted.push_back(i);
53 available.push_back(i);
59 if (!available.empty()) {
62 pool = pools[available[getRandomNumber(available.size() - 1)]];
64 }
else if (!exhausted.empty()) {
68 for (
auto const& e : exhausted) {
69 getPoolState(pools[e])->getPermutation()->reset();
72 pool = pools[exhausted[getRandomNumber(exhausted.size() - 1)]];
78 return (getPoolState(pool)->getPermutation()->next(done));
87RandomAllocator::pickPrefixInternal(
const ClientClasses& client_classes,
90 PrefixLenMatchType prefix_length_match,
92 uint8_t hint_prefix_length) {
94 auto const& pools = subnet->getPools(
pool_type_);
100 std::vector<uint64_t> available;
101 std::vector<uint64_t> exhausted;
102 for (
auto i = 0; i < pools.size(); ++i) {
104 if (pools[i]->clientSupported(client_classes)) {
106 hint_prefix_length)) {
110 auto state = getPoolState(pools[i]);
111 if (state->getPermutation()->exhausted()) {
116 exhausted.push_back(i);
120 available.push_back(i);
126 if (!available.empty()) {
129 pool = pools[available[getRandomNumber(available.size() - 1)]];
131 }
else if (!exhausted.empty()) {
135 for (
auto const& e : exhausted) {
136 getPoolState(pools[e])->getPermutation()->reset();
139 pool = pools[exhausted[getRandomNumber(exhausted.size() - 1)]];
145 pool6 = boost::dynamic_pointer_cast<Pool6>(pool);
153 return (getPoolState(pool)->getPermutation()->next(done));
162RandomAllocator::getPoolState(
const PoolPtr& pool)
const {
163 if (!pool->getAllocationState()) {
166 return (boost::dynamic_pointer_cast<PoolRandomAllocationState>(pool->getAllocationState()));
170RandomAllocator::getRandomNumber(uint64_t limit) {
175 std::uniform_int_distribution<uint64_t> dist(0, limit);
176 return (dist(generator_));
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
Base class for all address/prefix allocation algorithms.
Lease::Type pool_type_
Defines pool type allocation.
WeakSubnetPtr subnet_
Weak pointer to the subnet owning the allocator.
static bool isValidPrefixPool(Allocator::PrefixLenMatchType prefix_length_match, PoolPtr pool, uint8_t hint_prefix_length)
Check if the pool matches the selection criteria relative to the provided hint prefix length.
Container for storing client class names.
static PoolRandomAllocationStatePtr create(const PoolPtr &pool)
Factory function creating the state instance from pool.
RandomAllocator(Lease::Type type, const WeakSubnetPtr &subnet)
Constructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< PoolRandomAllocationState > PoolRandomAllocationStatePtr
Type of the pointer to the PoolRandomAllocationState.
boost::weak_ptr< Subnet > WeakSubnetPtr
Weak pointer to the Subnet.
boost::shared_ptr< IdentifierBaseType > IdentifierBaseTypePtr
Shared pointer to a IdentifierType.
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Defines the logger used by the top-level component of kea-lfc.
Type
Type of lease or pool.