2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 14:05:33 +00:00

[#969] Removed duplicated tests

This commit is contained in:
Marcin Siodelski
2023-01-05 22:08:24 +01:00
parent eb79d24d49
commit 3a5af2be2a

View File

@@ -285,541 +285,6 @@ TEST_F(AllocEngine6Test, allocateAddress6Nulls) {
EXPECT_EQ(0, getStatistics("v6-allocation-fail-classes", 1));
}
// This test verifies that the allocator picks addresses that belong to the
// pool
TEST_F(AllocEngine6Test, IterativeAllocator) {
boost::scoped_ptr<Allocator> alloc(new NakedIterativeAllocator(Lease::TYPE_NA, subnet_));
for (int i = 0; i < 1000; ++i) {
IOAddress candidate = alloc->pickAddress(cc_, duid_, IOAddress("::"));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate));
}
}
// This test verifies that the allocator picks addresses that belong to the
// pool using classification
TEST_F(AllocEngine6Test, IterativeAllocator_class) {
boost::scoped_ptr<Allocator> alloc(new NakedIterativeAllocator(Lease::TYPE_NA, subnet_));
// Restrict pool_ to the foo class. Add a second pool with bar class.
pool_->allowClientClass("foo");
Pool6Ptr pool(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::100"),
IOAddress("2001:db8:1::109")));
pool->allowClientClass("bar");
subnet_->addPool(pool);
// Clients are in bar
cc_.insert("bar");
for (int i = 0; i < 1000; ++i) {
IOAddress candidate = alloc->pickAddress(cc_, duid_, IOAddress("::"));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_));
}
}
TEST_F(AllocEngine6Test, IterativeAllocatorAddrStep) {
subnet_->delPools(Lease::TYPE_NA); // Get rid of default pool
Pool6Ptr pool1(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
IOAddress("2001:db8:1::5")));
Pool6Ptr pool2(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::100"),
IOAddress("2001:db8:1::100")));
Pool6Ptr pool3(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::105"),
IOAddress("2001:db8:1::106")));
subnet_->addPool(pool1);
subnet_->addPool(pool2);
subnet_->addPool(pool3);
NakedIterativeAllocator alloc(Lease::TYPE_NA, subnet_);
// Let's check the first pool (5 addresses here)
EXPECT_EQ("2001:db8:1::1",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::2",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::3",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::4",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::5",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// The second pool is easy - only one address here
EXPECT_EQ("2001:db8:1::100",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// This is the third and last pool, with 2 addresses in it
EXPECT_EQ("2001:db8:1::105",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::106",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// We iterated over all addresses and reached to the end of the last pool.
// Let's wrap around and start from the beginning
EXPECT_EQ("2001:db8:1::1",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::2",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
TEST_F(AllocEngine6Test, IterativeAllocatorAddrStepInClass) {
subnet_->delPools(Lease::TYPE_NA); // Get rid of default pool
Pool6Ptr pool1(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
IOAddress("2001:db8:1::5")));
Pool6Ptr pool2(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::100"),
IOAddress("2001:db8:1::100")));
Pool6Ptr pool3(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::105"),
IOAddress("2001:db8:1::106")));
// Set pool1 and pool3 but not pool2 in foo class
pool1->allowClientClass("foo");
pool3->allowClientClass("foo");
subnet_->addPool(pool1);
subnet_->addPool(pool2);
subnet_->addPool(pool3);
NakedIterativeAllocator alloc(Lease::TYPE_NA, subnet_);
// Clients are in foo
cc_.insert("foo");
// Let's check the first pool (5 addresses here)
EXPECT_EQ("2001:db8:1::1",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::2",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::3",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::4",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::5",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// The second pool is easy - only one address here
EXPECT_EQ("2001:db8:1::100",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// This is the third and last pool, with 2 addresses in it
EXPECT_EQ("2001:db8:1::105",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::106",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// We iterated over all addresses and reached to the end of the last pool.
// Let's wrap around and start from the beginning
EXPECT_EQ("2001:db8:1::1",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::2",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
TEST_F(AllocEngine6Test, IterativeAllocatorAddrStepOutClass) {
subnet_->delPools(Lease::TYPE_NA); // Get rid of default pool
Pool6Ptr pool1(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"),
IOAddress("2001:db8:1::5")));
Pool6Ptr pool2(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::100"),
IOAddress("2001:db8:1::100")));
Pool6Ptr pool3(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::105"),
IOAddress("2001:db8:1::106")));
// Set pool2 in foo
pool2->allowClientClass("foo");
subnet_->addPool(pool1);
subnet_->addPool(pool2);
subnet_->addPool(pool3);
NakedIterativeAllocator alloc(Lease::TYPE_NA, subnet_);
// Let's check the first pool (5 addresses here)
EXPECT_EQ("2001:db8:1::1",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::2",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::3",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::4",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::5",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// The second pool is skipped
// This is the third and last pool, with 2 addresses in it
EXPECT_EQ("2001:db8:1::105",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::106",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// We iterated over all addresses and reached to the end of the last pool.
// Let's wrap around and start from the beginning
EXPECT_EQ("2001:db8:1::1",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:1::2",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStep) {
subnet_ = Subnet6::create(IOAddress("2001:db8::"), 32, 1, 2, 3, 4);
Pool6Ptr pool1(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8::"), 56, 60));
Pool6Ptr pool2(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:1::"), 48, 48));
Pool6Ptr pool3(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:2::"), 56, 64));
subnet_->addPool(pool1);
subnet_->addPool(pool2);
subnet_->addPool(pool3);
NakedIterativeAllocator alloc(Lease::TYPE_PD, subnet_);
// We have a 2001:db8::/48 subnet that has 3 pools defined in it:
// 2001:db8::/56 split into /60 prefixes (16 leases) (or 2001:db8:0:X0::)
// 2001:db8:1::/48 split into a single /48 prefix (just 1 lease)
// 2001:db8:2::/56 split into /64 prefixes (256 leases) (or 2001:db8:2:XX::)
// First pool check (Let's check over all 16 leases)
EXPECT_EQ("2001:db8::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:10::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:20::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:30::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:40::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:50::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:60::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:70::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:80::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:90::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:a0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:b0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:c0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:d0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:e0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:f0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// Second pool (just one lease here)
EXPECT_EQ("2001:db8:1::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// Third pool (256 leases, let's check first and last explicitly and the
// rest over in a pool
EXPECT_EQ("2001:db8:2::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
for (int i = 1; i < 255; i++) {
stringstream exp;
exp << "2001:db8:2:" << hex << i << dec << "::";
EXPECT_EQ(exp.str(),
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
EXPECT_EQ("2001:db8:2:ff::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// Ok, we've iterated over all prefixes in all pools. We now wrap around.
// We're looping over now (iterating over first pool again)
EXPECT_EQ("2001:db8::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:10::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStepInClass) {
subnet_ = Subnet6::create(IOAddress("2001:db8::"), 32, 1, 2, 3, 4);
Pool6Ptr pool1(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8::"), 56, 60));
Pool6Ptr pool2(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:1::"), 48, 48));
Pool6Ptr pool3(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:2::"), 56, 64));
// Set pool1 and pool3 but not pool2 in foo class
pool1->allowClientClass("foo");
pool3->allowClientClass("foo");
subnet_->addPool(pool1);
subnet_->addPool(pool2);
subnet_->addPool(pool3);
NakedIterativeAllocator alloc(Lease::TYPE_PD, subnet_);
// Clients are in foo
cc_.insert("foo");
// We have a 2001:db8::/48 subnet that has 3 pools defined in it:
// 2001:db8::/56 split into /60 prefixes (16 leases) (or 2001:db8:0:X0::)
// 2001:db8:1::/48 split into a single /48 prefix (just 1 lease)
// 2001:db8:2::/56 split into /64 prefixes (256 leases) (or 2001:db8:2:XX::)
// First pool check (Let's check over all 16 leases)
EXPECT_EQ("2001:db8::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:10::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:20::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:30::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:40::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:50::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:60::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:70::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:80::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:90::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:a0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:b0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:c0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:d0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:e0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:f0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// Second pool (just one lease here)
EXPECT_EQ("2001:db8:1::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// Third pool (256 leases, let's check first and last explicitly and the
// rest over in a pool
EXPECT_EQ("2001:db8:2::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
for (int i = 1; i < 255; i++) {
stringstream exp;
exp << "2001:db8:2:" << hex << i << dec << "::";
EXPECT_EQ(exp.str(),
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
EXPECT_EQ("2001:db8:2:ff::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// Ok, we've iterated over all prefixes in all pools. We now wrap around.
// We're looping over now (iterating over first pool again)
EXPECT_EQ("2001:db8::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:10::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStepOutClass) {
subnet_ = Subnet6::create(IOAddress("2001:db8::"), 32, 1, 2, 3, 4);
Pool6Ptr pool1(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8::"), 56, 60));
Pool6Ptr pool2(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:1::"), 48, 48));
Pool6Ptr pool3(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:2::"), 56, 64));
// Set pool2 in foo
pool2->allowClientClass("foo");
subnet_->addPool(pool1);
subnet_->addPool(pool2);
subnet_->addPool(pool3);
NakedIterativeAllocator alloc(Lease::TYPE_PD, subnet_);
// We have a 2001:db8::/48 subnet that has 3 pools defined in it:
// 2001:db8::/56 split into /60 prefixes (16 leases) (or 2001:db8:0:X0::)
// 2001:db8:1::/48 split into a single /48 prefix (just 1 lease)
// 2001:db8:2::/56 split into /64 prefixes (256 leases) (or 2001:db8:2:XX::)
// First pool check (Let's check over all 16 leases)
EXPECT_EQ("2001:db8::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:10::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:20::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:30::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:40::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:50::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:60::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:70::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:80::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:90::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:a0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:b0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:c0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:d0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:e0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:f0::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// The second pool is skipped
// Third pool (256 leases, let's check first and last explicitly and the
// rest over in a pool
EXPECT_EQ("2001:db8:2::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
for (int i = 1; i < 255; i++) {
stringstream exp;
exp << "2001:db8:2:" << hex << i << dec << "::";
EXPECT_EQ(exp.str(),
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
EXPECT_EQ("2001:db8:2:ff::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
// Ok, we've iterated over all prefixes in all pools. We now wrap around.
// We're looping over now (iterating over first pool again)
EXPECT_EQ("2001:db8::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
EXPECT_EQ("2001:db8:0:10::",
alloc.pickAddress(cc_, duid_, IOAddress("::")).toText());
}
// This test verifies that the iterative allocator can step over addresses
TEST_F(AllocEngine6Test, IterativeAllocatorAddressIncrease) {
NakedIterativeAllocator alloc(Lease::TYPE_NA, subnet_);
// Let's pick the first address
IOAddress addr1 = alloc.pickAddress(cc_, duid_, IOAddress("2001:db8:1::10"));
// Check that we can indeed pick the first address from the pool
EXPECT_EQ("2001:db8:1::10", addr1.toText());
// Check that addresses can be increased properly
checkAddrIncrease(alloc, "2001:db8::9", "2001:db8::a");
checkAddrIncrease(alloc, "2001:db8::f", "2001:db8::10");
checkAddrIncrease(alloc, "2001:db8::10", "2001:db8::11");
checkAddrIncrease(alloc, "2001:db8::ff", "2001:db8::100");
checkAddrIncrease(alloc, "2001:db8::ffff", "2001:db8::1:0");
checkAddrIncrease(alloc, "::", "::1");
checkAddrIncrease(alloc, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "::");
}
// This test verifies that the allocator can step over prefixes
TEST_F(AllocEngine6Test, IterativeAllocatorPrefixIncrease) {
NakedIterativeAllocator alloc(Lease::TYPE_PD, subnet_);
// For /128 prefix, increasePrefix should work the same as addressIncrease
checkPrefixIncrease(alloc, "2001:db8::9", 128, "2001:db8::a");
checkPrefixIncrease(alloc, "2001:db8::f", 128, "2001:db8::10");
checkPrefixIncrease(alloc, "2001:db8::10", 128, "2001:db8::11");
checkPrefixIncrease(alloc, "2001:db8::ff", 128, "2001:db8::100");
checkPrefixIncrease(alloc, "2001:db8::ffff", 128, "2001:db8::1:0");
checkPrefixIncrease(alloc, "::", 128, "::1");
checkPrefixIncrease(alloc, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128, "::");
// Check that /64 prefixes can be generated
checkPrefixIncrease(alloc, "2001:db8::", 64, "2001:db8:0:1::");
// Check that prefix length not divisible by 8 are working
checkPrefixIncrease(alloc, "2001:db8::", 128, "2001:db8::1");
checkPrefixIncrease(alloc, "2001:db8::", 127, "2001:db8::2");
checkPrefixIncrease(alloc, "2001:db8::", 126, "2001:db8::4");
checkPrefixIncrease(alloc, "2001:db8::", 125, "2001:db8::8");
checkPrefixIncrease(alloc, "2001:db8::", 124, "2001:db8::10");
checkPrefixIncrease(alloc, "2001:db8::", 123, "2001:db8::20");
checkPrefixIncrease(alloc, "2001:db8::", 122, "2001:db8::40");
checkPrefixIncrease(alloc, "2001:db8::", 121, "2001:db8::80");
checkPrefixIncrease(alloc, "2001:db8::", 120, "2001:db8::100");
// These are not really useful cases, because there are bits set
// int the last (128 - prefix_len) bits. Nevertheless, it shows
// that the algorithm is working even in such cases
checkPrefixIncrease(alloc, "2001:db8::1", 128, "2001:db8::2");
checkPrefixIncrease(alloc, "2001:db8::1", 127, "2001:db8::3");
checkPrefixIncrease(alloc, "2001:db8::1", 126, "2001:db8::5");
checkPrefixIncrease(alloc, "2001:db8::1", 125, "2001:db8::9");
checkPrefixIncrease(alloc, "2001:db8::1", 124, "2001:db8::11");
checkPrefixIncrease(alloc, "2001:db8::1", 123, "2001:db8::21");
checkPrefixIncrease(alloc, "2001:db8::1", 122, "2001:db8::41");
checkPrefixIncrease(alloc, "2001:db8::1", 121, "2001:db8::81");
checkPrefixIncrease(alloc, "2001:db8::1", 120, "2001:db8::101");
// Let's try out couple real life scenarios
checkPrefixIncrease(alloc, "2001:db8:1:abcd::", 64, "2001:db8:1:abce::");
checkPrefixIncrease(alloc, "2001:db8:1:abcd::", 60, "2001:db8:1:abdd::");
checkPrefixIncrease(alloc, "2001:db8:1:abcd::", 56, "2001:db8:1:accd::");
checkPrefixIncrease(alloc, "2001:db8:1:abcd::", 52, "2001:db8:1:bbcd::");
// And now let's try something over the top
checkPrefixIncrease(alloc, "::", 1, "8000::");
}
// This test verifies that the iterative allocator really walks over all addresses
// in all pools in specified subnet. It also must not pick the same address twice
// unless it runs out of pool space and must start over.
TEST_F(AllocEngine6Test, IterativeAllocator_manyPools6) {
NakedIterativeAllocator alloc(Lease::TYPE_NA, subnet_);
// let's start from 2, as there is 2001:db8:1::10 - 2001:db8:1::20 pool already.
for (int i = 2; i < 10; ++i) {
stringstream min, max;
min << "2001:db8:1::" << hex << i*16 + 1;
max << "2001:db8:1::" << hex << i*16 + 9;
Pool6Ptr pool(new Pool6(Lease::TYPE_NA, IOAddress(min.str()),
IOAddress(max.str())));
subnet_->addPool(pool);
}
int total = 17 + 8 * 9; // First pool (::10 - ::20) has 17 addresses in it,
// there are 8 extra pools with 9 addresses in each.
// Let's keep picked addresses here and check their uniqueness.
std::set<IOAddress> generated_addrs;
int cnt = 0;
while (++cnt) {
IOAddress candidate = alloc.pickAddress(cc_, duid_, IOAddress("::"));
EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate));
// One way to easily verify that the iterative allocator really works is
// to uncomment the following line and observe its output that it
// covers all defined pools.
// cout << candidate.toText() << endl;
if (generated_addrs.find(candidate) == generated_addrs.end()) {
// We haven't had this.
generated_addrs.insert(candidate);
} else {
// We have seen this address before. That should mean that we
// iterated over all addresses.
if (generated_addrs.size() == total) {
// We have exactly the number of address in all pools.
break;
}
ADD_FAILURE() << "Too many or not enough unique addresses generated.";
break;
}
if ( cnt>total ) {
ADD_FAILURE() << "Too many unique addresses generated.";
break;
}
}
}
// This test checks if really small pools are working
TEST_F(AllocEngine6Test, smallPool6) {
boost::scoped_ptr<AllocEngine> engine;