|
@@ -569,11 +569,10 @@ TEST_F(Dhcp6ParserTest, subnetGlobalDefaults) {
|
|
|
EXPECT_EQ(1, subnet->getID());
|
|
|
}
|
|
|
|
|
|
-// Goal of this test is to verify that multiple subnets get unique
|
|
|
-// subnet-ids. Also, test checks that it's possible to do reconfiguration
|
|
|
-// multiple times.
|
|
|
TEST_F(Dhcp6ParserTest, multipleSubnets) {
|
|
|
ConstElementPtr x;
|
|
|
+ // Collection of four subnets for which ids should be autogenerated
|
|
|
+ // - ids are unspecified or set to 0.
|
|
|
string config = "{ \"interfaces\": [ \"*\" ],"
|
|
|
"\"preferred-lifetime\": 3000,"
|
|
|
"\"rebind-timer\": 2000, "
|
|
@@ -584,7 +583,8 @@ TEST_F(Dhcp6ParserTest, multipleSubnets) {
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:2::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:2::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:2::/64\", "
|
|
|
+ " \"id\": 0"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:3::/80\" ],"
|
|
@@ -598,9 +598,9 @@ TEST_F(Dhcp6ParserTest, multipleSubnets) {
|
|
|
|
|
|
int cnt = 0; // Number of reconfigurations
|
|
|
|
|
|
- do {
|
|
|
- ElementPtr json = Element::fromJSON(config);
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
|
|
|
+ do {
|
|
|
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
|
|
|
ASSERT_TRUE(x);
|
|
|
comment_ = parseAnswer(rcode_, x);
|
|
@@ -623,6 +623,100 @@ TEST_F(Dhcp6ParserTest, multipleSubnets) {
|
|
|
} while (++cnt < 10);
|
|
|
}
|
|
|
|
|
|
+// This checks that it is possible to assign arbitrary ids for subnets.
|
|
|
+TEST_F(Dhcp6ParserTest, multipleSubnetsExplicitIDs) {
|
|
|
+ ConstElementPtr x;
|
|
|
+ // Four subnets with arbitrary subnet ids.
|
|
|
+ string config = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"preferred-lifetime\": 3000,"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet6\": [ { "
|
|
|
+ " \"pool\": [ \"2001:db8:1::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:1::/64\", "
|
|
|
+ " \"id\": 1024"
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"2001:db8:2::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:2::/64\", "
|
|
|
+ " \"id\": 100"
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"2001:db8:3::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:3::/64\", "
|
|
|
+ " \"id\": 1"
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"2001:db8:4::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:4::/64\", "
|
|
|
+ " \"id\": 34"
|
|
|
+ " } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ int cnt = 0; // Number of reconfigurations
|
|
|
+
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
+
|
|
|
+ do {
|
|
|
+ EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
|
|
|
+ ASSERT_TRUE(subnets);
|
|
|
+ ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
|
|
|
+
|
|
|
+ // Check that subnet ids are as expected.
|
|
|
+ EXPECT_EQ(1024, subnets->at(0)->getID());
|
|
|
+ EXPECT_EQ(100, subnets->at(1)->getID());
|
|
|
+ EXPECT_EQ(1, subnets->at(2)->getID());
|
|
|
+ EXPECT_EQ(34, subnets->at(3)->getID());
|
|
|
+
|
|
|
+ // Repeat reconfiguration process 10 times and check that the subnet-id
|
|
|
+ // is set to the same value.
|
|
|
+ } while (++cnt < 3);
|
|
|
+}
|
|
|
+
|
|
|
+// CHeck that the configuration with two subnets having the same id is rejected.
|
|
|
+TEST_F(Dhcp6ParserTest, multipleSubnetsOverlapingIDs) {
|
|
|
+ ConstElementPtr x;
|
|
|
+ // Four subnets, two of them have the same id.
|
|
|
+ string config = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"preferred-lifetime\": 3000,"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet6\": [ { "
|
|
|
+ " \"pool\": [ \"2001:db8:1::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:1::/64\", "
|
|
|
+ " \"id\": 1024"
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"2001:db8:2::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:2::/64\", "
|
|
|
+ " \"id\": 100"
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"2001:db8:3::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:3::/64\", "
|
|
|
+ " \"id\": 1024"
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"2001:db8:4::/80\" ],"
|
|
|
+ " \"subnet\": \"2001:db8:4::/64\", "
|
|
|
+ " \"id\": 34"
|
|
|
+ " } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_NE(rcode_, 0);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// Goal of this test is to verify that a previously configured subnet can be
|
|
|
// deleted in subsequent reconfiguration.
|
|
|
TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
|
|
@@ -635,19 +729,23 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
|
|
|
"\"renew-timer\": 1000, "
|
|
|
"\"subnet6\": [ { "
|
|
|
" \"pool\": [ \"2001:db8:1::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:1::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:1::/64\", "
|
|
|
+ " \"id\": 1"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:2::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:2::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:2::/64\", "
|
|
|
+ " \"id\": 2"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:3::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:3::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:3::/64\", "
|
|
|
+ " \"id\": 3"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:4::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:4::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:4::/64\", "
|
|
|
+ " \"id\": 4"
|
|
|
" } ],"
|
|
|
"\"valid-lifetime\": 4000 }";
|
|
|
|
|
@@ -658,15 +756,18 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
|
|
|
"\"renew-timer\": 1000, "
|
|
|
"\"subnet6\": [ { "
|
|
|
" \"pool\": [ \"2001:db8:1::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:1::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:1::/64\", "
|
|
|
+ " \"id\": 1"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:2::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:2::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:2::/64\", "
|
|
|
+ " \"id\": 2"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:3::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:3::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:3::/64\", "
|
|
|
+ " \"id\": 3"
|
|
|
" } ],"
|
|
|
"\"valid-lifetime\": 4000 }";
|
|
|
|
|
@@ -677,15 +778,18 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
|
|
|
"\"renew-timer\": 1000, "
|
|
|
"\"subnet6\": [ { "
|
|
|
" \"pool\": [ \"2001:db8:1::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:1::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:1::/64\", "
|
|
|
+ " \"id\": 1"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:3::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:3::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:3::/64\", "
|
|
|
+ " \"id\": 3"
|
|
|
" },"
|
|
|
" {"
|
|
|
" \"pool\": [ \"2001:db8:4::/80\" ],"
|
|
|
- " \"subnet\": \"2001:db8:4::/64\" "
|
|
|
+ " \"subnet\": \"2001:db8:4::/64\", "
|
|
|
+ " \"id\": 4"
|
|
|
" } ],"
|
|
|
"\"valid-lifetime\": 4000 }";
|
|
|
|
|
@@ -720,8 +824,6 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
|
|
|
/// CASE 2: Configure 4 subnets, then reconfigure and remove one
|
|
|
/// from in between (not first, not last)
|
|
|
|
|
|
-#if 0
|
|
|
- /// @todo: Uncomment subnet removal test as part of #3281.
|
|
|
json = Element::fromJSON(config4);
|
|
|
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
|
|
|
ASSERT_TRUE(x);
|
|
@@ -743,7 +845,6 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
|
|
|
// The second subnet (with subnet-id = 2) is no longer there
|
|
|
EXPECT_EQ(3, subnets->at(1)->getID());
|
|
|
EXPECT_EQ(4, subnets->at(2)->getID());
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
|