testOption(*range2.first, 23, foo2_expected, sizeof(foo2_expected));
}
+// This test verifies that it is possible to specify options on
+// pool levels.
+TEST_F(Dhcp4ParserTest, optionDataSinglePool) {
+ ConstElementPtr x;
+ string config = "{ " + genIfaceConfig() + ","
+ "\"rebind-timer\": 2000, "
+ "\"renew-timer\": 1000, "
+ "\"subnet4\": [ { "
+ " \"pools\": [ { "
+ " \"pool\": \"192.0.2.1 - 192.0.2.100\","
+ " \"option-data\": [ {"
+ " \"name\": \"dhcp-message\","
+ " \"data\": \"ABCDEF0105\","
+ " \"csv-format\": false"
+ " },"
+ " {"
+ " \"name\": \"default-ip-ttl\","
+ " \"data\": \"01\","
+ " \"csv-format\": false"
+ " } ]"
+ " } ],"
+ " \"subnet\": \"192.0.2.0/24\""
+ " } ],"
+ "\"valid-lifetime\": 4000 }";
+
+ ConstElementPtr json;
+ ASSERT_NO_THROW(json = parseDHCP4(config));
+ extractConfig(config);
+
+ EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
+ checkResult(x, 0);
+
+ Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->
+ selectSubnet(IOAddress("192.0.2.24"), classify_);
+ ASSERT_TRUE(subnet);
+
+ PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.24"), false);
+ ASSERT_TRUE(pool);
+ Pool4Ptr pool4 = boost::dynamic_pointer_cast<Pool4>(pool);
+ ASSERT_TRUE(pool4);
+
+ OptionContainerPtr options = pool4->getCfgOption()->getAll("dhcp4");
+ ASSERT_EQ(2, options->size());
+
+ // Get the search index. Index #1 is to search using option code.
+ const OptionContainerTypeIndex& idx = options->get<1>();
+
+ // Get the options for specified index. Expecting one option to be
+ // returned but in theory we may have multiple options with the same
+ // code so we get the range.
+ std::pair<OptionContainerTypeIndex::const_iterator,
+ OptionContainerTypeIndex::const_iterator> range =
+ idx.equal_range(56);
+ // Expect a single option with the code equal to 100.
+ ASSERT_EQ(1, std::distance(range.first, range.second));
+ const uint8_t foo_expected[] = {
+ 0xAB, 0xCD, 0xEF, 0x01, 0x05
+ };
+ // Check if option is valid in terms of code and carried data.
+ testOption(*range.first, 56, foo_expected, sizeof(foo_expected));
+
+ range = idx.equal_range(23);
+ ASSERT_EQ(1, std::distance(range.first, range.second));
+ // Do another round of testing with second option.
+ const uint8_t foo2_expected[] = {
+ 0x01
+ };
+ testOption(*range.first, 23, foo2_expected, sizeof(foo2_expected));
+}
+
+TEST_F(Dhcp4ParserTest, optionDataMultiplePools) {
+ ConstElementPtr x;
+ string config = "{ " + genIfaceConfig() + ","
+ "\"rebind-timer\": 2000, "
+ "\"renew-timer\": 1000, "
+ "\"subnet4\": [ { "
+ " \"pools\": [ { "
+ " \"pool\": \"192.0.2.1 - 192.0.2.100\","
+ " \"option-data\": [ {"
+ " \"name\": \"dhcp-message\","
+ " \"data\": \"ABCDEF0105\","
+ " \"csv-format\": false"
+ " } ]"
+ " },"
+ " {"
+ " \"pool\": \"192.0.2.200 - 192.0.2.250\","
+ " \"option-data\": [ {"
+ " \"name\": \"default-ip-ttl\","
+ " \"data\": \"01\","
+ " \"csv-format\": false"
+ " } ]"
+ " } ],"
+ " \"subnet\": \"192.0.2.0/24\""
+ " } ],"
+ "\"valid-lifetime\": 4000 }";
+
+ ConstElementPtr json;
+ ASSERT_NO_THROW(json = parseDHCP4(config));
+ extractConfig(config);
+
+ EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
+ checkResult(x, 0);
+
+ Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->
+ selectSubnet(IOAddress("192.0.2.24"), classify_);
+ ASSERT_TRUE(subnet);
+
+ PoolPtr pool1 = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.24"), false);
+ ASSERT_TRUE(pool1);
+ Pool4Ptr pool41 = boost::dynamic_pointer_cast<Pool4>(pool1);
+ ASSERT_TRUE(pool41);
+
+ OptionContainerPtr options1 = pool41->getCfgOption()->getAll("dhcp4");
+ ASSERT_EQ(1, options1->size());
+
+ // Get the search index. Index #1 is to search using option code.
+ const OptionContainerTypeIndex& idx1 = options1->get<1>();
+
+ // Get the options for specified index. Expecting one option to be
+ // returned but in theory we may have multiple options with the same
+ // code so we get the range.
+ std::pair<OptionContainerTypeIndex::const_iterator,
+ OptionContainerTypeIndex::const_iterator> range1 =
+ idx1.equal_range(56);
+ // Expect a single option with the code equal to 100.
+ ASSERT_EQ(1, std::distance(range1.first, range1.second));
+ const uint8_t foo_expected[] = {
+ 0xAB, 0xCD, 0xEF, 0x01, 0x05
+ };
+ // Check if option is valid in terms of code and carried data.
+ testOption(*range1.first, 56, foo_expected, sizeof(foo_expected));
+
+ // Test another pool in the same way.
+ PoolPtr pool2 = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.240"), false);
+ ASSERT_TRUE(pool2);
+ Pool4Ptr pool42 = boost::dynamic_pointer_cast<Pool4>(pool2);
+ ASSERT_TRUE(pool42);
+
+ OptionContainerPtr options2 = pool42->getCfgOption()->getAll("dhcp4");
+ ASSERT_EQ(1, options2->size());
+
+ const OptionContainerTypeIndex& idx2 = options2->get<1>();
+ std::pair<OptionContainerTypeIndex::const_iterator,
+ OptionContainerTypeIndex::const_iterator> range2 =
+ idx2.equal_range(23);
+ ASSERT_EQ(1, std::distance(range2.first, range2.second));
+ const uint8_t foo2_expected[] = {
+ 0x01
+ };
+ testOption(*range2.first, 23, foo2_expected, sizeof(foo2_expected));
+}
// Verify that empty option name is rejected in the configuration.
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" },\n"
+" \"rebind-timer\": 2000,\n"
+" \"renew-timer\": 1000,\n"
+" \"subnet4\": [\n"
+" {\n"
+" \"pools\": [\n"
+" {\n"
+" \"option-data\": [\n"
+" {\n"
+" \"csv-format\": false,\n"
+" \"data\": \"ABCDEF0105\",\n"
+" \"name\": \"dhcp-message\"\n"
+" },\n"
+" {\n"
+" \"csv-format\": false,\n"
+" \"data\": \"01\",\n"
+" \"name\": \"default-ip-ttl\"\n"
+" }\n"
+" ],\n"
+" \"pool\": \"192.0.2.1 - 192.0.2.100\"\n"
+" }\n"
+" ],\n"
+" \"subnet\": \"192.0.2.0/24\"\n"
+" }\n"
+" ],\n"
+" \"valid-lifetime\": 4000\n"
+" }\n",
+ // CONFIGURATION 31
+"{\n"
+" \"interfaces-config\": {\n"
+" \"interfaces\": [ \"*\" ]\n"
+" },\n"
+" \"rebind-timer\": 2000,\n"
+" \"renew-timer\": 1000,\n"
+" \"subnet4\": [\n"
+" {\n"
+" \"pools\": [\n"
+" {\n"
+" \"option-data\": [\n"
+" {\n"
+" \"csv-format\": false,\n"
+" \"data\": \"ABCDEF0105\",\n"
+" \"name\": \"dhcp-message\"\n"
+" }\n"
+" ],\n"
+" \"pool\": \"192.0.2.1 - 192.0.2.100\"\n"
+" },\n"
+" {\n"
+" \"option-data\": [\n"
+" {\n"
+" \"csv-format\": false,\n"
+" \"data\": \"01\",\n"
+" \"name\": \"default-ip-ttl\"\n"
+" }\n"
+" ],\n"
+" \"pool\": \"192.0.2.200 - 192.0.2.250\"\n"
+" }\n"
+" ],\n"
+" \"subnet\": \"192.0.2.0/24\"\n"
+" }\n"
+" ],\n"
+" \"valid-lifetime\": 4000\n"
+" }\n",
+ // CONFIGURATION 32
+"{\n"
+" \"interfaces-config\": {\n"
+" \"interfaces\": [ \"*\" ]\n"
+" },\n"
" \"option-data\": [\n"
" {\n"
" \"data\": \"1234\",\n"
" \"renew-timer\": 1000,\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 31
+ // CONFIGURATION 33
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 3000\n"
" }\n",
- // CONFIGURATION 32
+ // CONFIGURATION 34
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 33
+ // CONFIGURATION 35
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 34
+ // CONFIGURATION 36
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"eth0\", \"eth1\" ]\n"
" \"renew-timer\": 1000,\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 35
+ // CONFIGURATION 37
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"eth0\", \"*\", \"eth1\" ]\n"
" \"renew-timer\": 1000,\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 36
+ // CONFIGURATION 38
"{\n"
" \"dhcp-ddns\": {\n"
" \"always-include-fqdn\": true,\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 37
+ // CONFIGURATION 39
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 38
+ // CONFIGURATION 40
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 39
+ // CONFIGURATION 41
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 40
+ // CONFIGURATION 42
"{\n"
" \"rebind-timer\": 2000,\n"
" \"renew-timer\": 1000,\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 41
+ // CONFIGURATION 43
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" },\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 42
+ // CONFIGURATION 44
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" },\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 43
+ // CONFIGURATION 45
"{\n"
" \"decline-probation-period\": 12345,\n"
" \"interfaces-config\": {\n"
" },\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 44
+ // CONFIGURATION 46
"{\n"
" \"expired-leases-processing\": {\n"
" \"flush-reclaimed-timer-wait-time\": 35,\n"
" },\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 45
+ // CONFIGURATION 47
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 46
+ // CONFIGURATION 48
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 47
+ // CONFIGURATION 49
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 48
+ // CONFIGURATION 50
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 49
+ // CONFIGURATION 51
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 50
+ // CONFIGURATION 52
"{\n"
" \"client-classes\": [\n"
" {\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 51
+ // CONFIGURATION 53
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 52
+ // CONFIGURATION 54
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 53
+ // CONFIGURATION 55
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" ],\n"
" \"valid-lifetime\": 4000\n"
" }\n",
- // CONFIGURATION 54
+ // CONFIGURATION 56
"{\n"
" \"interfaces-config\": {\n"
" \"interfaces\": [ \"*\" ]\n"
" \"lease-database\": {\n"
" \"type\": \"memfile\"\n"
" },\n"
+" \"option-data\": [ ],\n"
+" \"option-def\": [ ],\n"
+" \"subnet4\": [\n"
+" {\n"
+" \"4o6-interface\": \"\",\n"
+" \"4o6-interface-id\": \"\",\n"
+" \"4o6-subnet\": \"\",\n"
+" \"id\": 1,\n"
+" \"interface\": \"\",\n"
+" \"match-client-id\": true,\n"
+" \"next-server\": \"0.0.0.0\",\n"
+" \"option-data\": [ ],\n"
+" \"pools\": [\n"
+" {\n"
+" \"pool\": \"192.0.2.1-192.0.2.100\"\n"
+" }\n"
+" ],\n"
+" \"rebind-timer\": 2000,\n"
+" \"relay\": {\n"
+" \"ip-address\": \"0.0.0.0\"\n"
+" },\n"
+" \"renew-timer\": 1000,\n"
+" \"reservation-mode\": \"all\",\n"
+" \"reservations\": [ ],\n"
+" \"subnet\": \"192.0.2.0/24\",\n"
+" \"valid-lifetime\": 4000\n"
+" }\n"
+" ]\n"
+" }\n",
+ // CONFIGURATION 31
+"{\n"
+" \"decline-probation-period\": 86400,\n"
+" \"dhcp-ddns\": {\n"
+" \"always-include-fqdn\": false,\n"
+" \"enable-updates\": false,\n"
+" \"generated-prefix\": \"myhost\",\n"
+" \"max-queue-size\": 1024,\n"
+" \"ncr-format\": \"JSON\",\n"
+" \"ncr-protocol\": \"UDP\",\n"
+" \"override-client-update\": false,\n"
+" \"override-no-update\": false,\n"
+" \"qualifying-suffix\": \"\",\n"
+" \"replace-client-name\": \"never\",\n"
+" \"sender-ip\": \"0.0.0.0\",\n"
+" \"sender-port\": 0,\n"
+" \"server-ip\": \"127.0.0.1\",\n"
+" \"server-port\": 53001\n"
+" },\n"
+" \"dhcp4o6-port\": 0,\n"
+" \"echo-client-id\": true,\n"
+" \"expired-leases-processing\": {\n"
+" \"flush-reclaimed-timer-wait-time\": 25,\n"
+" \"hold-reclaimed-time\": 3600,\n"
+" \"max-reclaim-leases\": 100,\n"
+" \"max-reclaim-time\": 250,\n"
+" \"reclaim-timer-wait-time\": 10,\n"
+" \"unwarned-reclaim-cycles\": 5\n"
+" },\n"
+" \"hooks-libraries\": [ ],\n"
+" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n"
+" \"interfaces-config\": {\n"
+" \"interfaces\": [ \"*\" ]\n"
+" },\n"
+" \"lease-database\": {\n"
+" \"type\": \"memfile\"\n"
+" },\n"
+" \"option-data\": [ ],\n"
+" \"option-def\": [ ],\n"
+" \"subnet4\": [\n"
+" {\n"
+" \"4o6-interface\": \"\",\n"
+" \"4o6-interface-id\": \"\",\n"
+" \"4o6-subnet\": \"\",\n"
+" \"id\": 1,\n"
+" \"interface\": \"\",\n"
+" \"match-client-id\": true,\n"
+" \"next-server\": \"0.0.0.0\",\n"
+" \"option-data\": [ ],\n"
+" \"pools\": [\n"
+" {\n"
+" \"pool\": \"192.0.2.1-192.0.2.100\"\n"
+" },\n"
+" {\n"
+" \"pool\": \"192.0.2.200-192.0.2.250\"\n"
+" }\n"
+" ],\n"
+" \"rebind-timer\": 2000,\n"
+" \"relay\": {\n"
+" \"ip-address\": \"0.0.0.0\"\n"
+" },\n"
+" \"renew-timer\": 1000,\n"
+" \"reservation-mode\": \"all\",\n"
+" \"reservations\": [ ],\n"
+" \"subnet\": \"192.0.2.0/24\",\n"
+" \"valid-lifetime\": 4000\n"
+" }\n"
+" ]\n"
+" }\n",
+ // CONFIGURATION 32
+"{\n"
+" \"decline-probation-period\": 86400,\n"
+" \"dhcp-ddns\": {\n"
+" \"always-include-fqdn\": false,\n"
+" \"enable-updates\": false,\n"
+" \"generated-prefix\": \"myhost\",\n"
+" \"max-queue-size\": 1024,\n"
+" \"ncr-format\": \"JSON\",\n"
+" \"ncr-protocol\": \"UDP\",\n"
+" \"override-client-update\": false,\n"
+" \"override-no-update\": false,\n"
+" \"qualifying-suffix\": \"\",\n"
+" \"replace-client-name\": \"never\",\n"
+" \"sender-ip\": \"0.0.0.0\",\n"
+" \"sender-port\": 0,\n"
+" \"server-ip\": \"127.0.0.1\",\n"
+" \"server-port\": 53001\n"
+" },\n"
+" \"dhcp4o6-port\": 0,\n"
+" \"echo-client-id\": true,\n"
+" \"expired-leases-processing\": {\n"
+" \"flush-reclaimed-timer-wait-time\": 25,\n"
+" \"hold-reclaimed-time\": 3600,\n"
+" \"max-reclaim-leases\": 100,\n"
+" \"max-reclaim-time\": 250,\n"
+" \"reclaim-timer-wait-time\": 10,\n"
+" \"unwarned-reclaim-cycles\": 5\n"
+" },\n"
+" \"hooks-libraries\": [ ],\n"
+" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n"
+" \"interfaces-config\": {\n"
+" \"interfaces\": [ \"*\" ]\n"
+" },\n"
+" \"lease-database\": {\n"
+" \"type\": \"memfile\"\n"
+" },\n"
" \"option-data\": [\n"
" {\n"
" \"code\": 1,\n"
" ],\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 31
+ // CONFIGURATION 33
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 32
+ // CONFIGURATION 34
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 33
+ // CONFIGURATION 35
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 34
+ // CONFIGURATION 36
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" \"option-def\": [ ],\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 35
+ // CONFIGURATION 37
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" \"option-def\": [ ],\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 36
+ // CONFIGURATION 38
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 37
+ // CONFIGURATION 39
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 38
+ // CONFIGURATION 40
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 39
+ // CONFIGURATION 41
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 40
+ // CONFIGURATION 42
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 41
+ // CONFIGURATION 43
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" \"option-def\": [ ],\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 42
+ // CONFIGURATION 44
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" \"option-def\": [ ],\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 43
+ // CONFIGURATION 45
"{\n"
" \"decline-probation-period\": 12345,\n"
" \"dhcp-ddns\": {\n"
" \"option-def\": [ ],\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 44
+ // CONFIGURATION 46
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" \"option-def\": [ ],\n"
" \"subnet4\": [ ]\n"
" }\n",
- // CONFIGURATION 45
+ // CONFIGURATION 47
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 46
+ // CONFIGURATION 48
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 47
+ // CONFIGURATION 49
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 48
+ // CONFIGURATION 50
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 49
+ // CONFIGURATION 51
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 50
+ // CONFIGURATION 52
"{\n"
" \"client-classes\": [\n"
" {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 51
+ // CONFIGURATION 53
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 52
+ // CONFIGURATION 54
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 53
+ // CONFIGURATION 55
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
" }\n"
" ]\n"
" }\n",
- // CONFIGURATION 54
+ // CONFIGURATION 56
"{\n"
" \"decline-probation-period\": 86400,\n"
" \"dhcp-ddns\": {\n"
EXPECT_EQ("type=V4, 192.0.2.128-192.0.2.143", pool2.toText());
}
+// This test checks that it is possible to specify pool specific options.
+TEST(Pool4Test, addOptions) {
+ // Create a pool to add options to it.
+ Pool4Ptr pool(new Pool4(IOAddress("192.0.2.0"),
+ IOAddress("192.0.2.255")));
+
+ // Differentiate options by their codes (100-109)
+ for (uint16_t code = 100; code < 110; ++code) {
+ OptionPtr option(new Option(Option::V4, code, OptionBuffer(10, 0xFF)));
+ ASSERT_NO_THROW(pool->getCfgOption()->add(option, false, "dhcp4"));
+ }
+
+ // Add 7 options to another option space. The option codes partially overlap
+ // with option codes that we have added to dhcp4 option space.
+ for (uint16_t code = 105; code < 112; ++code) {
+ OptionPtr option(new Option(Option::V6, code, OptionBuffer(10, 0xFF)));
+ ASSERT_NO_THROW(pool->getCfgOption()->add(option, false, "isc"));
+ }
+
+ // Get options from the pool and check if all 10 are there.
+ OptionContainerPtr options = pool->getCfgOption()->getAll("dhcp4");
+ ASSERT_TRUE(options);
+ ASSERT_EQ(10, options->size());
+
+ // Validate codes of options added to dhcp4 option space.
+ uint16_t expected_code = 100;
+ for (OptionContainer::const_iterator option_desc = options->begin();
+ option_desc != options->end(); ++option_desc) {
+ ASSERT_TRUE(option_desc->option_);
+ EXPECT_EQ(expected_code, option_desc->option_->getType());
+ ++expected_code;
+ }
+
+ options = pool->getCfgOption()->getAll("isc");
+ ASSERT_TRUE(options);
+ ASSERT_EQ(7, options->size());
+
+ // Validate codes of options added to isc option space.
+ expected_code = 105;
+ for (OptionContainer::const_iterator option_desc = options->begin();
+ option_desc != options->end(); ++option_desc) {
+ ASSERT_TRUE(option_desc->option_);
+ EXPECT_EQ(expected_code, option_desc->option_->getType());
+ ++expected_code;
+ }
+
+ // Try to get options from a non-existing option space.
+ options = pool->getCfgOption()->getAll("abcd");
+ ASSERT_TRUE(options);
+ EXPECT_TRUE(options->empty());
+}
+
TEST(Pool6Test, constructor_first_last) {
// let's construct 2001:db8:1:: - 2001:db8:1::ffff:ffff:ffff:ffff pool
}
// Simple check if toText returns reasonable values
-TEST(Pool6Test,toText) {
+TEST(Pool6Test, toText) {
Pool6 pool1(Lease::TYPE_NA, IOAddress("2001:db8::1"),
IOAddress("2001:db8::2"));
EXPECT_EQ("type=IA_NA, 2001:db8::1-2001:db8::2, delegated_len=128",