|
@@ -410,8 +410,195 @@ TEST_F(Dhcp4ParserTest, subnetGlobalDefaults) {
|
|
|
EXPECT_EQ(1000, subnet->getT1());
|
|
|
EXPECT_EQ(2000, subnet->getT2());
|
|
|
EXPECT_EQ(4000, subnet->getValid());
|
|
|
+
|
|
|
+ // Check that subnet-id is 1
|
|
|
+ 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(Dhcp4ParserTest, multipleSubnets) {
|
|
|
+ ConstElementPtr x;
|
|
|
+ string config = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.3.101 - 192.0.3.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.3.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.4.101 - 192.0.4.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.4.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.5.101 - 192.0.5.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.5.0/24\" "
|
|
|
+ " } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ int cnt = 0; // Number of reconfigurations
|
|
|
+
|
|
|
+ do {
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ const Subnet4Collection* subnets = CfgMgr::instance().getSubnets4();
|
|
|
+ ASSERT_TRUE(subnets);
|
|
|
+ ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
|
|
|
+
|
|
|
+ // Check subnet-ids of each subnet (it should be monotonously increasing)
|
|
|
+ EXPECT_EQ(1, subnets->at(0)->getID());
|
|
|
+ EXPECT_EQ(2, subnets->at(1)->getID());
|
|
|
+ EXPECT_EQ(3, subnets->at(2)->getID());
|
|
|
+ EXPECT_EQ(4, subnets->at(3)->getID());
|
|
|
+
|
|
|
+ // Repeat reconfiguration process 10 times and check that the subnet-id
|
|
|
+ // is set to the same value. Technically, just two iterations would be
|
|
|
+ // sufficient, but it's nice to have a test that exercises reconfiguration
|
|
|
+ // a bit.
|
|
|
+ } while (++cnt < 10);
|
|
|
+}
|
|
|
+
|
|
|
+// Goal of this test is to verify that a previously configured subnet can be
|
|
|
+// deleted in subsequent reconfiguration.
|
|
|
+TEST_F(Dhcp4ParserTest, reconfigureRemoveSubnet) {
|
|
|
+ ConstElementPtr x;
|
|
|
+
|
|
|
+ // All four subnets
|
|
|
+ string config4 = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.3.101 - 192.0.3.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.3.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.4.101 - 192.0.4.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.4.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.5.101 - 192.0.5.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.5.0/24\" "
|
|
|
+ " } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ // Three subnets (the last one removed)
|
|
|
+ string config_first3 = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.3.101 - 192.0.3.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.3.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.4.101 - 192.0.4.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.4.0/24\" "
|
|
|
+ " } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ // Second subnet removed
|
|
|
+ string config_second_removed = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.4.101 - 192.0.4.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.4.0/24\" "
|
|
|
+ " },"
|
|
|
+ " {"
|
|
|
+ " \"pool\": [ \"192.0.5.101 - 192.0.5.150\" ],"
|
|
|
+ " \"subnet\": \"192.0.5.0/24\" "
|
|
|
+ " } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ // CASE 1: Configure 4 subnets, then reconfigure and remove the
|
|
|
+ // last one.
|
|
|
+
|
|
|
+ ElementPtr json = Element::fromJSON(config4);
|
|
|
+ EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ const Subnet4Collection* subnets = CfgMgr::instance().getSubnets4();
|
|
|
+ ASSERT_TRUE(subnets);
|
|
|
+ ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
|
|
|
+
|
|
|
+ // Do the reconfiguration (the last subnet is removed)
|
|
|
+ json = Element::fromJSON(config_first3);
|
|
|
+ EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ subnets = CfgMgr::instance().getSubnets4();
|
|
|
+ ASSERT_TRUE(subnets);
|
|
|
+ ASSERT_EQ(3, subnets->size()); // We expect 3 subnets now (4th is removed)
|
|
|
+
|
|
|
+ // Check subnet-ids of each subnet (it should be monotonously increasing)
|
|
|
+ EXPECT_EQ(1, subnets->at(0)->getID());
|
|
|
+ EXPECT_EQ(2, subnets->at(1)->getID());
|
|
|
+ EXPECT_EQ(3, subnets->at(2)->getID());
|
|
|
+
|
|
|
+ /// 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 = configureDhcp4Server(*srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ // Do reconfiguration
|
|
|
+ json = Element::fromJSON(config_second_removed);
|
|
|
+ EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
|
|
|
+ ASSERT_TRUE(x);
|
|
|
+ comment_ = parseAnswer(rcode_, x);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ subnets = CfgMgr::instance().getSubnets4();
|
|
|
+ ASSERT_TRUE(subnets);
|
|
|
+ ASSERT_EQ(3, subnets->size()); // We expect 4 subnets
|
|
|
+
|
|
|
+ EXPECT_EQ(1, subnets->at(0)->getID());
|
|
|
+ // 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
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/// @todo: implement subnet removal test as part of #3281.
|
|
|
+
|
|
|
// Checks if the next-server defined as global parameter is taken into
|
|
|
// consideration.
|
|
|
TEST_F(Dhcp4ParserTest, nextServerGlobal) {
|