ASSERT_TRUE(pool_state);
EXPECT_FALSE(pool_state->exhausted());
+ double r = alloc.getOccupancyRate(IOAddress("192.0.2.101"), cc_, false);
+ EXPECT_EQ(.5, r);
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.101"), cc_, true);
+ EXPECT_EQ(.6, r);
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.1"), cc_, false);
+ EXPECT_EQ(0., r);
+
std::set<IOAddress> addresses;
for (auto i = 0; i < 5; ++i) {
auto lease = pool_state->offerFreeLease();
IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
EXPECT_TRUE(candidate.isV4Zero());
+ double r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(1., r);
+
auto i = 0;
for (auto const& address_lease : leases) {
if (i % 2) {
++i;
}
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(.5, r);
+
for (auto j = 0; j < 5; ++j) {
candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate));
candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
EXPECT_TRUE(candidate.isV4Zero());
+
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(1., r);
}
// Test allocating IPv4 addresses and re-allocating these that are
IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
EXPECT_TRUE(candidate.isV4Zero());
+ double r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(1., r);
+
auto i = 0;
for (auto const& address_lease : leases) {
if (i % 2) {
}
++i;
}
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(.5, r);
+
for (auto j = 0; j < 5; ++j) {
candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate));
lease->state_ = Lease::STATE_DEFAULT;
EXPECT_NO_THROW(lease_mgr.updateLease4(lease));
}
-
candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
EXPECT_TRUE(candidate.isV4Zero());
+
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(1., r);
}
// Test allocating DHCPv4 leases for many pools in a subnet.
auto& lease_mgr = LeaseMgrFactory::instance();
+ double r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(0., r);
+
std::set<IOAddress> addresses_set;
std::vector<IOAddress> addresses_vector;
std::vector<PoolPtr> pools_vector;
// Make sure that unique addresses have been returned.
EXPECT_EQ(total, addresses_set.size());
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(1., r);
+
// Verify that the addresses are returned in the random order.
// Count how many times we found consecutive addresses. It should
// be 0 or close to 0.
// Test that the allocator returns a zero address when there are no pools
// in a subnet.
TEST_F(FreeLeaseQueueAllocatorTest4, noPools) {
- FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
+ FreeLeaseQueueAllocator alloc(Lease::TYPE_V4, subnet_);
- subnet_->delPools(Lease::TYPE_V4);
+ subnet_->delPools(Lease::TYPE_V4);
- IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
- EXPECT_TRUE(candidate.isV4Zero());
+ IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
+ EXPECT_TRUE(candidate.isV4Zero());
+
+ // rate is 0. because of the address can't be found, not from 0./0....
+ double r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(0., r);
}
// Test that the allocator respects client class guards.
// Simulate client's request belonging to the class bar.
cc_.insert("bar");
+ double r = alloc.getOccupancyRate(IOAddress("192.0.2.120"), cc_, false);
+ EXPECT_EQ(0., r);
for (auto i = 0; i < 20; ++i) {
// Allocate random addresses and make sure they belong to the
// pools associated with the class bar.
}
EXPECT_EQ(20, addresses_set.size());
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.120"), cc_, false);
+ EXPECT_EQ(1., r);
+
addresses_set.clear();
// Simulate the case that the client also belongs to the class foo.
// All pools should now be available.
cc_.insert("foo");
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(.5, r);
for (auto i = 0; i < 20; ++i) {
IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
addresses_set.insert(candidate);
EXPECT_TRUE(subnet_->inRange(candidate));
}
EXPECT_EQ(20, addresses_set.size());
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(1., r);
// When the client does not belong to any client class the allocator
// can't offer any address to the client.
cc_.clear();
IOAddress candidate = alloc.pickAddress(cc_, clientid_, IOAddress("0.0.0.0"));
EXPECT_TRUE(candidate.isV4Zero());
+ r = alloc.getOccupancyRate(IOAddress("192.0.2.100"), cc_, false);
+ EXPECT_EQ(0., r);
}
/// @brief Test fixture class for the DHCPv6 Free Lease Queue allocator.
EXPECT_NO_THROW(alloc.initAfterConfigure());
+ // Address getOccupancyRate is for IPv4 only.
+ double r = alloc.getOccupancyRate(IOAddress("2001:db8:1::10"), cc_, false);
+ EXPECT_EQ(0., r);
+
auto pool_state = boost::dynamic_pointer_cast<PoolFreeLeaseQueueAllocationState>(pool_->getAllocationState());
ASSERT_TRUE(pool_state);
EXPECT_FALSE(pool_state->exhausted());
}
for (auto j = 0; j < 8; ++j) {
- candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
+ candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_));
auto lease = createLease6(Lease::TYPE_NA, candidate, i);
}
for (auto j = 0; j < 8; ++j) {
- candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
+ candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_));
auto lease = lease_mgr.getLease6(Lease::TYPE_NA, candidate);
ASSERT_TRUE(pool_state);
EXPECT_FALSE(pool_state->exhausted());
+ double r = alloc.getOccupancyRate(IOAddress("2001:db8:2::"),
+ 128, cc_, false);
+ EXPECT_EQ(5. / 256., r);
+
std::set<IOAddress> addresses;
for (auto i = 0; i < 256; ++i) {
auto lease = pool_state->offerFreeLease();
}
// The pool comprises 65536 prefixes. All should be returned.
EXPECT_EQ(65536, prefixes.size());
+
+ double r = alloc.getOccupancyRate(IOAddress("2001:db8:1:2::"),
+ 128, cc_, false);
+ EXPECT_EQ(1., r);
}
-// Test allocating IPv6 addresses and re-allocating these that are
+// Test allocating delegated prefixes and re-allocating these that are
// deleted (released).
TEST_F(FreeLeaseQueueAllocatorTest6, singlePdPoolWithAllocations) {
// Remove the default pool because it is too large for this test case.
IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
EXPECT_TRUE(candidate.isV6Zero());
+ double r = alloc.getOccupancyRate(IOAddress("3000::"), 128, cc_, false);
+ EXPECT_EQ(1., r);
auto i = 0;
for (auto const& address_lease : leases) {
}
++i;
}
+ r = alloc.getOccupancyRate(IOAddress("3000::"), 128, cc_, false);
+ EXPECT_EQ(.5, r);
+ r = alloc.getOccupancyRate(IOAddress("3000::"), 128, cc_, true);
+ EXPECT_EQ(129. / 256., r);
for (auto j = 0; j < 128; ++j) {
candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
EXPECT_TRUE(candidate.isV6Zero());
+
+ r = alloc.getOccupancyRate(IOAddress("3000::"), 128, cc_, false);
+ EXPECT_EQ(1., r);
}
-// Test allocating IPv6 addresses and re-allocating these that are
+// Test allocating delegated prefixes and re-allocating these that are
// reclaimed.
TEST_F(FreeLeaseQueueAllocatorTest6, singlePdPoolWithReclamations) {
// Remove the default pool because it is too large for this test case.
IOAddress candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
EXPECT_TRUE(candidate.isV6Zero());
+ double r = alloc.getOccupancyRate(IOAddress("3000::"), 128, cc_, false);
+ EXPECT_EQ(1., r);
auto i = 0;
for (auto const& address_lease : leases) {
}
++i;
}
+ r = alloc.getOccupancyRate(IOAddress("3000::"), 128, cc_, false);
+ EXPECT_EQ(.5, r);
for (auto j = 0; j < 128; ++j) {
candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 0);
EXPECT_TRUE(candidate.isV6Zero());
-}
+ r = alloc.getOccupancyRate(IOAddress("3000::"), 128, cc_, false);
+ EXPECT_EQ(1., r);
+}
// Test allocating delegated prefixes from multiple pools.
TEST_F(FreeLeaseQueueAllocatorTest6, manyPdPools) {
}
// Make sure that unique prefixes have been returned.
EXPECT_EQ(total, prefixes.size());
+
+ double r = alloc.getOccupancyRate(IOAddress("3001::"), 128, cc_, false);
+ EXPECT_EQ(1., r);
}
// Test allocating delegated prefixes from multiple pools.
ASSERT_NO_THROW(alloc.initAfterConfigure());
auto& lease_mgr = LeaseMgrFactory::instance();
-
Pool6Ptr pool;
std::set<IOAddress> prefixes;
}
// Make sure that unique prefixes have been returned.
EXPECT_EQ(total, prefixes.size());
+
+ double r = alloc.getOccupancyRate(IOAddress("2001:db8:1:2::"),
+ 120, cc_, false);
+ EXPECT_EQ(1., r);
+ r = alloc.getOccupancyRate(IOAddress("2001:db8:1:2::"), 128, cc_, false);
+ EXPECT_EQ(65536. / 68096., r);
+ r = alloc.getOccupancyRate(IOAddress("2001:db8:1:2::"), 64, cc_, false);
+ EXPECT_EQ(0., r);
}
// Test allocating delegated prefixes from multiple pools.
}
// Make sure that unique prefixes have been returned.
EXPECT_EQ(total, prefixes.size());
+ double r = alloc.getOccupancyRate(IOAddress("3001::"), 128, cc_, false);
+ EXPECT_EQ(2560. / 68096., r);
}
// Test allocating delegated prefixes from multiple pools.
}
// Make sure that unique prefixes have been returned.
EXPECT_EQ(total, prefixes.size());
+ double r = alloc.getOccupancyRate(IOAddress("3001::"), 128, cc_, false);
+ EXPECT_EQ(2560. / 68096., r);
}
// Test that the allocator respects client class guards.
candidate = alloc.pickPrefix(cc_, pool, duid_, Allocator::PREFIX_LEN_HIGHER, IOAddress("::"), 64);
EXPECT_TRUE(candidate.isV6Zero());
-}
+ double r = alloc.getOccupancyRate(IOAddress("3000:1::"), 128, cc_, false);
+ EXPECT_EQ(1., r);
+ cc_.insert("foo");
+ r = alloc.getOccupancyRate(IOAddress("3000:1::"), 128, cc_, false);
+ EXPECT_EQ(256. / 65792., r);
+ cc_.clear();
+ r = alloc.getOccupancyRate(IOAddress("3000:1::"), 128, cc_, false);
+ EXPECT_EQ(0., r);
+}
} // end of isc::dhcp::test namespace
} // end of isc::dhcp namespace