|
@@ -124,7 +124,8 @@ TEST(Subnet4Test, matchClientId) {
|
|
|
EXPECT_TRUE(subnet.getMatchClientId());
|
|
|
}
|
|
|
|
|
|
-TEST(Subnet4Test, Pool4InSubnet4) {
|
|
|
+// Checks that it is possible to add and retrieve multiple pools.
|
|
|
+TEST(Subnet4Test, pool4InSubnet4) {
|
|
|
|
|
|
Subnet4Ptr subnet(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3));
|
|
|
|
|
@@ -132,15 +133,16 @@ TEST(Subnet4Test, Pool4InSubnet4) {
|
|
|
PoolPtr pool2(new Pool4(IOAddress("192.1.2.128"), 26));
|
|
|
PoolPtr pool3(new Pool4(IOAddress("192.1.2.192"), 30));
|
|
|
|
|
|
- EXPECT_NO_THROW(subnet->addPool(pool1));
|
|
|
+ // Add pools in reverse order to make sure that they get ordered by
|
|
|
+ // first address.
|
|
|
+ EXPECT_NO_THROW(subnet->addPool(pool3));
|
|
|
|
|
|
// If there's only one pool, get that pool
|
|
|
PoolPtr mypool = subnet->getAnyPool(Lease::TYPE_V4);
|
|
|
- EXPECT_EQ(mypool, pool1);
|
|
|
-
|
|
|
+ EXPECT_EQ(mypool, pool3);
|
|
|
|
|
|
EXPECT_NO_THROW(subnet->addPool(pool2));
|
|
|
- EXPECT_NO_THROW(subnet->addPool(pool3));
|
|
|
+ EXPECT_NO_THROW(subnet->addPool(pool1));
|
|
|
|
|
|
// If there are more than one pool and we didn't provide hint, we
|
|
|
// should get the first pool
|
|
@@ -149,11 +151,30 @@ TEST(Subnet4Test, Pool4InSubnet4) {
|
|
|
EXPECT_EQ(mypool, pool1);
|
|
|
|
|
|
// If we provide a hint, we should get a pool that this hint belongs to
|
|
|
- EXPECT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4,
|
|
|
+ ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4,
|
|
|
IOAddress("192.1.2.195")));
|
|
|
-
|
|
|
EXPECT_EQ(mypool, pool3);
|
|
|
|
|
|
+ ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4,
|
|
|
+ IOAddress("192.1.2.129")));
|
|
|
+ EXPECT_EQ(mypool, pool2);
|
|
|
+
|
|
|
+ ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4,
|
|
|
+ IOAddress("192.1.2.64")));
|
|
|
+ EXPECT_EQ(mypool, pool1);
|
|
|
+
|
|
|
+ // Specify addresses which don't belong to any existing pools. The
|
|
|
+ // third parameter prevents it from returning "any" available
|
|
|
+ // pool if a good match is not found.
|
|
|
+ ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4,
|
|
|
+ IOAddress("192.1.2.200"),
|
|
|
+ false));
|
|
|
+ EXPECT_FALSE(mypool);
|
|
|
+
|
|
|
+ ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4,
|
|
|
+ IOAddress("192.1.1.254"),
|
|
|
+ false));
|
|
|
+ EXPECT_FALSE(mypool);
|
|
|
}
|
|
|
|
|
|
// Check if it's possible to get specified number of possible leases for
|
|
@@ -182,22 +203,69 @@ TEST(Subnet4Test, getCapacity) {
|
|
|
EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4));
|
|
|
}
|
|
|
|
|
|
-TEST(Subnet4Test, Subnet4_Pool4_checks) {
|
|
|
+// Checks that it is not allowed to add invalid pools.
|
|
|
+TEST(Subnet4Test, pool4Checks) {
|
|
|
|
|
|
Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 8, 1, 2, 3));
|
|
|
|
|
|
// this one is in subnet
|
|
|
- Pool4Ptr pool1(new Pool4(IOAddress("192.255.0.0"), 16));
|
|
|
+ Pool4Ptr pool1(new Pool4(IOAddress("192.254.0.0"), 16));
|
|
|
subnet->addPool(pool1);
|
|
|
|
|
|
// this one is larger than the subnet!
|
|
|
Pool4Ptr pool2(new Pool4(IOAddress("193.0.0.0"), 24));
|
|
|
|
|
|
- EXPECT_THROW(subnet->addPool(pool2), BadValue);
|
|
|
+ ASSERT_THROW(subnet->addPool(pool2), BadValue);
|
|
|
|
|
|
// this one is totally out of blue
|
|
|
Pool4Ptr pool3(new Pool4(IOAddress("1.2.3.4"), 16));
|
|
|
- EXPECT_THROW(subnet->addPool(pool3), BadValue);
|
|
|
+ ASSERT_THROW(subnet->addPool(pool3), BadValue);
|
|
|
+
|
|
|
+ // This pool should be added just fine.
|
|
|
+ Pool4Ptr pool4(new Pool4(IOAddress("192.0.2.10"),
|
|
|
+ IOAddress("192.0.2.20")));
|
|
|
+ ASSERT_NO_THROW(subnet->addPool(pool4));
|
|
|
+
|
|
|
+ // This one overlaps with the previous pool.
|
|
|
+ Pool4Ptr pool5(new Pool4(IOAddress("192.0.2.1"),
|
|
|
+ IOAddress("192.0.2.15")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool5), BadValue);
|
|
|
+
|
|
|
+ // This one also overlaps.
|
|
|
+ Pool4Ptr pool6(new Pool4(IOAddress("192.0.2.20"),
|
|
|
+ IOAddress("192.0.2.30")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool6), BadValue);
|
|
|
+
|
|
|
+ // This one "surrounds" the other pool.
|
|
|
+ Pool4Ptr pool7(new Pool4(IOAddress("192.0.2.8"),
|
|
|
+ IOAddress("192.0.2.23")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool7), BadValue);
|
|
|
+
|
|
|
+ // This one does not overlap.
|
|
|
+ Pool4Ptr pool8(new Pool4(IOAddress("192.0.2.30"),
|
|
|
+ IOAddress("192.0.2.40")));
|
|
|
+ ASSERT_NO_THROW(subnet->addPool(pool8));
|
|
|
+
|
|
|
+ // This one has a lower bound in the pool of 192.0.2.10-20.
|
|
|
+ Pool4Ptr pool9(new Pool4(IOAddress("192.0.2.18"),
|
|
|
+ IOAddress("192.0.2.30")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool9), BadValue);
|
|
|
+
|
|
|
+ // This one has an upper bound in the pool of 192.0.2.30-40.
|
|
|
+ Pool4Ptr pool10(new Pool4(IOAddress("192.0.2.25"),
|
|
|
+ IOAddress("192.0.2.32")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool10), BadValue);
|
|
|
+
|
|
|
+ // Add a pool with a single address.
|
|
|
+ Pool4Ptr pool11(new Pool4(IOAddress("192.255.0.50"),
|
|
|
+ IOAddress("192.255.0.50")));
|
|
|
+ ASSERT_NO_THROW(subnet->addPool(pool11));
|
|
|
+
|
|
|
+ // Now we're going to add the same pool again. This is an interesting
|
|
|
+ // case because we're checking if the code is properly using upper_bound
|
|
|
+ // function, which returns a pool that has an address greater than the
|
|
|
+ // specified one.
|
|
|
+ ASSERT_THROW(subnet->addPool(pool11), BadValue);
|
|
|
}
|
|
|
|
|
|
// Tests whether Subnet4 object is able to store and process properly
|
|
@@ -721,27 +789,78 @@ TEST(Subnet6Test, clientClassesMultiple) {
|
|
|
EXPECT_TRUE(subnet->clientSupported(bar_class));
|
|
|
}
|
|
|
|
|
|
-TEST(Subnet6Test, Subnet6_Pool6_checks) {
|
|
|
+// Checks that it is not allowed to add invalid pools.
|
|
|
+TEST(Subnet6Test, pool6Checks) {
|
|
|
|
|
|
Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
|
|
|
|
|
|
// this one is in subnet
|
|
|
Pool6Ptr pool1(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:1::"), 64));
|
|
|
- subnet->addPool(pool1);
|
|
|
+ ASSERT_NO_THROW(subnet->addPool(pool1));
|
|
|
|
|
|
// this one is larger than the subnet!
|
|
|
Pool6Ptr pool2(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8::"), 48));
|
|
|
|
|
|
- EXPECT_THROW(subnet->addPool(pool2), BadValue);
|
|
|
-
|
|
|
+ ASSERT_THROW(subnet->addPool(pool2), BadValue);
|
|
|
|
|
|
// this one is totally out of blue
|
|
|
Pool6Ptr pool3(new Pool6(Lease::TYPE_NA, IOAddress("3000::"), 16));
|
|
|
- EXPECT_THROW(subnet->addPool(pool3), BadValue);
|
|
|
-
|
|
|
+ ASSERT_THROW(subnet->addPool(pool3), BadValue);
|
|
|
|
|
|
Pool6Ptr pool4(new Pool6(Lease::TYPE_NA, IOAddress("4001:db8:1::"), 80));
|
|
|
- EXPECT_THROW(subnet->addPool(pool4), BadValue);
|
|
|
+ ASSERT_THROW(subnet->addPool(pool4), BadValue);
|
|
|
+
|
|
|
+ // This pool should be added just fine.
|
|
|
+ Pool6Ptr pool5(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:2::100"),
|
|
|
+ IOAddress("2001:db8:1:2::200")));
|
|
|
+ ASSERT_NO_THROW(subnet->addPool(pool5));
|
|
|
+
|
|
|
+ // This pool overlaps with a previously added pool.
|
|
|
+ Pool6Ptr pool6(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:2::1"),
|
|
|
+ IOAddress("2001:db8:1:2::150")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool6), BadValue);
|
|
|
+
|
|
|
+ // This pool also overlaps
|
|
|
+ Pool6Ptr pool7(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:2::150"),
|
|
|
+ IOAddress("2001:db8:1:2::300")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool7), BadValue);
|
|
|
+
|
|
|
+ // This one "surrounds" the other pool.
|
|
|
+ Pool6Ptr pool8(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:2::50"),
|
|
|
+ IOAddress("2001:db8:1:2::250")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool8), BadValue);
|
|
|
+
|
|
|
+ // This one does not overlap.
|
|
|
+ Pool6Ptr pool9(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:2::300"),
|
|
|
+ IOAddress("2001:db8:1:2::400")));
|
|
|
+ ASSERT_NO_THROW(subnet->addPool(pool9));
|
|
|
+
|
|
|
+ // This one has a lower bound in the pool of 2001:db8:1::100-200.
|
|
|
+ Pool6Ptr pool10(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:2::200"),
|
|
|
+ IOAddress("2001:db8:1:2::225")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool10), BadValue);
|
|
|
+
|
|
|
+ // This one has an upper bound in the pool of 2001:db8:1::300-400.
|
|
|
+ Pool6Ptr pool11(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:2::250"),
|
|
|
+ IOAddress("2001:db8:1:2::300")));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool11), BadValue);
|
|
|
+
|
|
|
+ // Add a pool with a single address.
|
|
|
+ Pool6Ptr pool12(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:3::250"),
|
|
|
+ IOAddress("2001:db8:1:3::250")));
|
|
|
+ ASSERT_NO_THROW(subnet->addPool(pool12));
|
|
|
+
|
|
|
+ // Now we're going to add the same pool again. This is an interesting
|
|
|
+ // case because we're checking if the code is properly using upper_bound
|
|
|
+ // function, which returns a pool that has an address greater than the
|
|
|
+ // specified one.
|
|
|
+ ASSERT_THROW(subnet->addPool(pool12), BadValue);
|
|
|
+
|
|
|
+ // Prefix pool overlaps with the pool1. We can't hand out addresses and
|
|
|
+ // prefixes from the same range.
|
|
|
+ Pool6Ptr pool13(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:1:1:2::"),
|
|
|
+ 80, 96));
|
|
|
+ ASSERT_THROW(subnet->addPool(pool13), BadValue);
|
|
|
}
|
|
|
|
|
|
TEST(Subnet6Test, addOptions) {
|