}
-AllocEngine::AllocEngine(AllocType engine_type, unsigned int attempts,
+AllocEngine::AllocEngine(AllocType engine_type, uint64_t attempts,
bool ipv6)
- :attempts_(attempts) {
+ : attempts_(attempts) {
// Choose the basic (normal address) lease type
Lease::Type basic_type = ipv6 ? Lease::TYPE_NA : Lease::TYPE_V4;
return (leases);
}
- // Unable to allocate an address, return an empty lease.
- LOG_WARN(alloc_engine_logger, ALLOC_ENGINE_V6_ALLOC_FAIL)
- .arg(ctx.query_->getLabel())
- .arg(attempts_);
} catch (const isc::Exception& e) {
// - we find a free address
// - we find an address for which the lease has expired
// - we exhaust number of tries
- //
- /// @todo: We used to use hardcoded number of attempts (100). Now we dynamically
- /// calculate the number of possible leases in all pools in this subnet and
- /// try that number of times at most. It would be useful to that value if
- /// attempts_, specified by the user could override that value (and keep
- /// dynamic if they're set to 0).
- uint64_t max_attempts = ctx.subnet_->getPoolCapacity(ctx.type_);
+ uint64_t max_attempts = (attempts_ > 0 ? attempts_ :
+ ctx.subnet_->getPoolCapacity(ctx.type_));
for (uint64_t i = 0; i < max_attempts; ++i)
{
IOAddress candidate = allocator->pickAddress(ctx.subnet_, ctx.duid_, hint);
}
}
+ // Unable to allocate an address, return an empty lease.
+ LOG_WARN(alloc_engine_logger, ALLOC_ENGINE_V6_ALLOC_FAIL)
+ .arg(ctx.query_->getLabel())
+ .arg(max_attempts);
+
+
+
// We failed to allocate anything. Let's return empty collection.
return (Lease6Collection());
}
}
new_lease = ctx.fake_allocation_ ? discoverLease4(ctx) : requestLease4(ctx);
- if (!new_lease) {
- // Unable to allocate an address, return an empty lease.
- LOG_WARN(alloc_engine_logger, ALLOC_ENGINE_V4_ALLOC_FAIL)
- .arg(ctx.query_->getLabel())
- .arg(attempts_);
- }
} catch (const isc::Exception& e) {
// Some other error, return an empty lease.
AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) {
Lease4Ptr new_lease;
AllocatorPtr allocator = getAllocator(Lease::TYPE_V4);
- const uint64_t max_attempts = ctx.subnet_->getPoolCapacity(Lease::TYPE_V4);
+ const uint64_t max_attempts = (attempts_ > 0 ? attempts_ :
+ ctx.subnet_->getPoolCapacity(Lease::TYPE_V4));
for (uint64_t i = 0; i < max_attempts; ++i) {
IOAddress candidate = allocator->pickAddress(ctx.subnet_, ctx.clientid_,
ctx.requested_address_);
}
}
+ // Unable to allocate an address, return an empty lease.
+ LOG_WARN(alloc_engine_logger, ALLOC_ENGINE_V4_ALLOC_FAIL)
+ .arg(ctx.query_->getLabel())
+ .arg(max_attempts);
+
return (new_lease);
}
/// @param attempts number of attempts for each lease allocation before
/// we give up (0 means unlimited)
/// @param ipv6 specifies if the engine should work for IPv4 or IPv6
- AllocEngine(AllocType engine_type, unsigned int attempts, bool ipv6 = true);
+ AllocEngine(AllocType engine_type, uint64_t attempts, bool ipv6 = true);
/// @brief Destructor.
virtual ~AllocEngine() { }
std::map<Lease::Type, AllocatorPtr> allocators_;
/// @brief number of attempts before we give up lease allocation (0=unlimited)
- unsigned int attempts_;
+ uint64_t attempts_;
// hook name indexes (used in hooks callouts)
int hook_index_lease4_select_; ///< index for lease4_select hook
// value. This test verifies that the prefix can be allocated in that
// case.
TEST_F(AllocEngine6Test, largePDPool) {
- AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100);
+ AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0);
// Remove the default PD pool.
subnet_->delPools(Lease::TYPE_PD);
// confuse the allocation engine if the number of available addresses
// was larger than 2^32.
TEST_F(AllocEngine6Test, largePoolOver32bits) {
- AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100);
+ AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0);
// Configure 2001:db8::/32 subnet
subnet_.reset(new Subnet6(IOAddress("2001:db8::"), 32, 1, 2, 3, 4));