double
Allocator::getOccupancyRate(const asiolink::IOAddress&,
- const ClientClasses&) const {
+ const ClientClasses&) {
return (0.);
}
double
Allocator::getOccupancyRate(const asiolink::IOAddress&,
const uint8_t,
- const ClientClasses&) const {
+ const ClientClasses&) {
return (0.);
}
/// @param client_classes list of classes client belongs to.
virtual double
getOccupancyRate(const asiolink::IOAddress& addr,
- const ClientClasses& client_classes) const;
+ const ClientClasses& client_classes);
/// @brief Returns the occupancy rate (v6 prefixes).
///
virtual double
getOccupancyRate(const asiolink::IOAddress& pref,
const uint8_t plen,
- const ClientClasses& client_classes) const;
+ const ClientClasses& client_classes);
/// @brief Check if the pool matches the selection criteria relative to the
/// provided hint prefix length.
double
FreeLeaseQueueAllocator::getOccupancyRate(const IOAddress& addr,
- const ClientClasses& client_classes) const {
+ const ClientClasses& client_classes) {
+ MultiThreadingLock lock(mutex_);
+ return (getOccupancyRateInternal(addr, client_classes));
+}
+
+double
+FreeLeaseQueueAllocator::getOccupancyRateInternal(const IOAddress& addr,
+ const ClientClasses& client_classes) {
// Sanity.
if (!addr.isV4()) {
return (0.);
double
FreeLeaseQueueAllocator::getOccupancyRate(const IOAddress& pref,
const uint8_t plen,
- const ClientClasses& client_classes) const {
+ const ClientClasses& client_classes) {
+ MultiThreadingLock lock(mutex_);
+ return (getOccupancyRateInternal(pref, plen, client_classes));
+}
+
+double
+FreeLeaseQueueAllocator::getOccupancyRateInternal(const IOAddress& pref,
+ const uint8_t plen,
+ const ClientClasses& client_classes) {
// Sanity.
if (!pref.isV6()) {
return (0.);
/// @param client_classes list of classes client belongs to.
virtual double
getOccupancyRate(const asiolink::IOAddress& addr,
- const ClientClasses& client_classes) const;
+ const ClientClasses& client_classes);
/// @brief Returns the occupancy rate (v6 prefixes).
///
virtual double
getOccupancyRate(const asiolink::IOAddress& pref,
const uint8_t plen,
- const ClientClasses& client_classes) const;
+ const ClientClasses& client_classes);
private:
const isc::asiolink::IOAddress& hint,
uint8_t hint_prefix_length);
+ /// @brief Returns the occupancy rate (v4 addresses).
+ ///
+ /// Internal thread-unsafe implementation.
+ ///
+ /// The method counts the total number and the number of not free
+ /// addresses in the suitable pools of the subnet, and returns the
+ /// occupancy rate. If the total number of addresses is over UMAX64
+ /// or the address is not from one of these pools, or by default
+ /// the 0. rate is returned.
+ ///
+ /// @param addr the address.
+ /// @param client_classes list of classes client belongs to.
+ virtual double
+ getOccupancyRateInternal(const asiolink::IOAddress& addr,
+ const ClientClasses& client_classes);
+
+ /// @brief Returns the occupancy rate (v6 prefixes).
+ ///
+ /// Internal thread-unsafe implementation.
+ ///
+ /// The method counts the total number and the number of not free
+ /// prefixes in the suitable pools of the subnet, and returns the
+ /// occupancy rate. If the total number of prefixes is over UMAX64
+ /// or the prefix is not from one of these pools, or by default
+ /// the 0. rate is returned.
+ ///
+ /// @param pref the prefix.
+ /// @param plen the prefix length.
+ /// @param client_classes list of classes client belongs to.
+ virtual double
+ getOccupancyRateInternal(const asiolink::IOAddress& pref,
+ const uint8_t plen,
+ const ClientClasses& client_classes);
+
/// @brief Convenience function returning pool allocation state instance.
///
/// It creates a new pool state instance and assigns it to the pool
Pool6Ptr pool;
std::set<IOAddress> prefixes;
+ bool assigned = false;
for (size_t i = 0; i < total; ++i) {
IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 64);
EXPECT_FALSE(candidate.isV6Zero());
prefixes.insert(candidate);
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_PD, candidate, cc_));
+ if (candidate == IOAddress("3001::")) {
+ assigned = true;
+ }
}
// Make sure that unique prefixes have been returned.
EXPECT_EQ(total, prefixes.size());
double r = alloc.getOccupancyRate(IOAddress("3001::"), 128, cc_);
- EXPECT_EQ(2560. / 68096., r);
+ // getOccupancyRate argument is always considered as not free.
+ EXPECT_EQ((assigned ? 2560. : 2561.) / 68096., r);
}
// Test that the allocator respects client class guards.