|
@@ -411,6 +411,151 @@ TEST_F(Dhcp4ParserTest, subnetGlobalDefaults) {
|
|
|
EXPECT_EQ(4000, subnet->getValid());
|
|
|
}
|
|
|
|
|
|
+// Checks if the next-server defined as global parameter is taken into
|
|
|
+// consideration.
|
|
|
+TEST_F(Dhcp4ParserTest, nextServerGlobal) {
|
|
|
+
|
|
|
+ ConstElementPtr status;
|
|
|
+
|
|
|
+ string config = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"next-server\": \"1.2.3.4\", "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
|
|
|
+
|
|
|
+ // check if returned status is OK
|
|
|
+ checkResult(status, 0);
|
|
|
+
|
|
|
+ // Now check if the configuration was indeed handled and we have
|
|
|
+ // expected pool configured.
|
|
|
+ Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
|
|
|
+ ASSERT_TRUE(subnet);
|
|
|
+ EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if the next-server defined as subnet parameter is taken into
|
|
|
+// consideration.
|
|
|
+TEST_F(Dhcp4ParserTest, nextServerSubnet) {
|
|
|
+
|
|
|
+ ConstElementPtr status;
|
|
|
+
|
|
|
+ string config = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"next-server\": \"1.2.3.4\", "
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
|
|
|
+
|
|
|
+ // check if returned status is OK
|
|
|
+ checkResult(status, 0);
|
|
|
+
|
|
|
+ // Now check if the configuration was indeed handled and we have
|
|
|
+ // expected pool configured.
|
|
|
+ Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
|
|
|
+ ASSERT_TRUE(subnet);
|
|
|
+ EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
|
|
|
+}
|
|
|
+
|
|
|
+// Test checks several negative scenarios for next-server configuration: bogus
|
|
|
+// address, IPv6 adddress and empty string.
|
|
|
+TEST_F(Dhcp4ParserTest, nextServerNegative) {
|
|
|
+
|
|
|
+ ConstElementPtr status;
|
|
|
+
|
|
|
+ // Config with junk instead of next-server address
|
|
|
+ string config_bogus1 = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"rebind-timer\": 2000, "
|
|
|
+ " \"renew-timer\": 1000, "
|
|
|
+ " \"next-server\": \"a.b.c.d\", "
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ // Config with IPv6 next server address
|
|
|
+ string config_bogus2 = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"rebind-timer\": 2000, "
|
|
|
+ " \"renew-timer\": 1000, "
|
|
|
+ " \"next-server\": \"2001:db8::1\", "
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ // Config with empty next server address
|
|
|
+ string config_bogus3 = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"rebind-timer\": 2000, "
|
|
|
+ " \"renew-timer\": 1000, "
|
|
|
+ " \"next-server\": \"\", "
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ ElementPtr json1 = Element::fromJSON(config_bogus1);
|
|
|
+ ElementPtr json2 = Element::fromJSON(config_bogus2);
|
|
|
+ ElementPtr json3 = Element::fromJSON(config_bogus3);
|
|
|
+
|
|
|
+ // check if returned status is always a failure
|
|
|
+ EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json1));
|
|
|
+ checkResult(status, 1);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json2));
|
|
|
+ checkResult(status, 1);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json3));
|
|
|
+ checkResult(status, 0);
|
|
|
+}
|
|
|
+
|
|
|
+// Checks if the next-server defined as global value is overridden by subnet
|
|
|
+// specific value.
|
|
|
+TEST_F(Dhcp4ParserTest, nextServerOverride) {
|
|
|
+
|
|
|
+ ConstElementPtr status;
|
|
|
+
|
|
|
+ string config = "{ \"interfaces\": [ \"*\" ],"
|
|
|
+ "\"rebind-timer\": 2000, "
|
|
|
+ "\"renew-timer\": 1000, "
|
|
|
+ "\"next-server\": \"192.0.0.1\", "
|
|
|
+ "\"subnet4\": [ { "
|
|
|
+ " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
|
|
|
+ " \"next-server\": \"1.2.3.4\", "
|
|
|
+ " \"subnet\": \"192.0.2.0/24\" } ],"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ ElementPtr json = Element::fromJSON(config);
|
|
|
+
|
|
|
+ EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
|
|
|
+
|
|
|
+ // check if returned status is OK
|
|
|
+ checkResult(status, 0);
|
|
|
+
|
|
|
+ // Now check if the configuration was indeed handled and we have
|
|
|
+ // expected pool configured.
|
|
|
+ Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
|
|
|
+ ASSERT_TRUE(subnet);
|
|
|
+ EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
|
|
|
+}
|
|
|
+
|
|
|
// This test checks if it is possible to override global values
|
|
|
// on a per subnet basis.
|
|
|
TEST_F(Dhcp4ParserTest, subnetLocal) {
|