44 generator_.seed(rd());
50 auto const& pools = subnet->getPools(
pool_type_);
59 for (
const auto& pool : pools) {
63 pool->getLastAddress(),
64 subnet->getID(),
false);
68 pool->getLastAddress(),
70 subnet->getID(),
false);
73 auto pdpool = boost::dynamic_pointer_cast<Pool6>(pool);
75 pool->getLastAddress(),
77 subnet->getID(),
false);
87SharedFlqAllocator::pickAddressInternal(
const ClientClasses& client_classes,
93 auto const& pools = subnet->getPools(
pool_type_);
94 std::vector<PoolPtr> available;
95 for (
auto const& pool : pools) {
97 if (pool->clientSupported(client_classes)) {
98 available.push_back(pool);
103 while (available.size()) {
105 auto offset = getRandomNumber(available.size() - 1);
106 PoolPtr const pool = available[offset];
112 pool->getLastAddress());
113 if (!free_lease.isV4Zero()) {
123 pool->getLastAddress());
124 if (!free_lease.isV6Zero()) {
132 isc_throw(Unexpected,
"pickAddressInternal called for Lease::TYPE_PD");
140 available.erase(available.begin() + offset);
149SharedFlqAllocator::pickPrefixInternal(
const ClientClasses& client_classes,
152 PrefixLenMatchType prefix_length_match,
154 uint8_t hint_prefix_length) {
158 auto const& pools = subnet->getPools(
pool_type_);
159 std::vector<PoolPtr> available;
160 for (
auto const& pool : pools) {
162 if (pool->clientSupported(client_classes)) {
164 hint_prefix_length)) {
168 available.push_back(pool);
173 while (available.size()) {
175 auto offset = getRandomNumber(available.size() - 1);
176 PoolPtr const pool = available[offset];
179 isc_throw(Unexpected,
"pickPrefixInternal called for Lease::TYPE_V4");
182 isc_throw(Unexpected,
"pickPrefixInternal called for Lease::TYPE_NA");
188 pool->getLastAddress());
189 if (!free_lease.isV6Zero()) {
201 available.erase(available.begin() + offset);
209SharedFlqAllocator::getRandomNumber(uint64_t limit) {
214 std::uniform_int_distribution<uint64_t> dist(0, limit);
215 return (dist(generator_));
221 if (!subnet->getAllocationState(
pool_type_)) {
223 boost::make_shared<SubnetSflqAllocationState>());
227 state = boost::dynamic_pointer_cast<SubnetSflqAllocationState>
239 auto const& capacity(pool->getCapacity());
243 <<
" for shared-flq allocator on V4 pool "
251 if (subnet->getAllocatorType() ==
"shared-flq") {
253 auto const& capacity(pool->getCapacity());
257 <<
" for shared-flq allocator on V6 pool "
263 if (subnet->getPdAllocatorType() ==
"shared-flq") {
265 auto const& capacity(pool->getCapacity());
269 <<
" for shared-flq allocator on V6 pool "
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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.
virtual void initAfterConfigureInternal()
Allocator-specific initialization function.
Lease::Type pool_type_
Defines pool type allocation.
Allocator(Lease::Type type, const WeakSubnetPtr &subnet)
Constructor.
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 TrackingLeaseMgr & instance()
Return current lease manager.
virtual asiolink::IOAddress sflqPickFreeLease4(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V4 address within the given pool range.
virtual bool sflqCreateFlqPool4(asiolink::IOAddress start_address, asiolink::IOAddress end_address, SubnetID subnet_id, bool recreate=false)
Creates a v4 SFLQ Pool.
virtual asiolink::IOAddress sflqPickFreeLease6(asiolink::IOAddress start_address, asiolink::IOAddress end_address)
Finds a free V6 address/prefix within the given pool range.
virtual bool sflqCreateFlqPool6(asiolink::IOAddress start_address, asiolink::IOAddress end_address, Lease::Type lease_type, uint8_t delegated_len, SubnetID subnet_id, bool recreate=false)
Calls stored procedure to create an SFLQ pool for v6.
static void setInUse(bool in_use)
Sets the global in-use flag.
static bool inUse()
Returns the global in-use flag.
static void sanityChecksSflqAllocator6(Subnet6Ptr subnet)
Sanity checks the subnet and pool configuration for use with SFLQ.
static void sanityChecksSflqAllocator4(Subnet4Ptr subnet)
Sanity checks the subnet and pool configuration for use with SFLQ.
SubnetSflqAllocationStatePtr getSubnetState() const
Returns the allocation state for the subnet pool_type;.
static constexpr size_t MAX_V6_POOL_SIZE
Maximum capacity of a V6 pool supported by SFLQ.
SharedFlqAllocator(Lease::Type type, const WeakSubnetPtr &subnet)
Constructor.
static constexpr size_t MAX_V4_POOL_SIZE
Maximum capacity of a V4 pool supported by SFLQ.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
boost::weak_ptr< Subnet > WeakSubnetPtr
Weak pointer to the Subnet.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
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< SubnetSflqAllocationState > SubnetSflqAllocationStatePtr
Type of the pointer to the SubnetSflqAllocationState.
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.
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address