map->set("allocator", Element::create(allocator_type_));
}
+ if (!adaptive_lease_time_threshold_.unspecified()) {
+ map->set("adaptive-lease-time-threshold",
+ Element::create(adaptive_lease_time_threshold_));
+ }
+
return (map);
}
network1->setHostnameCharReplacement("x");
network1->setCacheThreshold(.20);
network1->setOfferLft(77);
+ network1->setAdaptiveLeaseTimeThreshold(.90);
network2->setIface("eth1");
network2->setT1(Triplet<uint32_t>(100));
" \"cache-max-age\": 50\n"
" },\n"
" {\n"
+ " \"adaptive-lease-time-threshold\": .90,\n"
" \"calculate-tee-times\": true,\n"
" \"ddns-generated-prefix\": \"prefix\",\n"
" \"ddns-override-no-update\": true,\n"
subnet1->setT1Percent(0.45);
subnet1->setT2Percent(0.70);
subnet1->setCacheThreshold(0.20);
+ subnet1->setAdaptiveLeaseTimeThreshold(.90);
subnet2->setIface("lo");
subnet2->addRelayAddress(IOAddress("10.0.0.1"));
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
+ " \"adaptive-lease-time-threshold\": .90,\n"
" \"option-data\": [ ],\n"
" \"pools\": [ ],\n"
" \"user-context\": { \"comment\": \"foo\" }\n"
{"too big", 1.05,
"subnet configuration failed: cache-threshold:"
" 1.05 is invalid, it must be greater than or equal to 0.0 and less than 1.0"
+ },
+ {"excluded", 1.0,
+ "subnet configuration failed: cache-threshold:"
+ " 1 is invalid, it must be greater than or equal to 0.0 and less than 1.0"
}
};
" \"4o6-subnet\": \"\" \n"
" }";
-
data::ElementPtr elems;
ASSERT_NO_THROW(elems = data::Element::fromJSON(json))
<< "invalid JSON:" << json << "\n test is broken";
}
}
+// This test verifies the Subnet4 parser's validation logic for
+// adaptive lease time parameter.
+TEST(CfgSubnets4Test, AdaptiveLeaseTimeParamValidation) {
+
+ // Describes a single test scenario.
+ struct Scenario {
+ std::string label; // label used for logging test failures
+ double threshold; // value of adaptive-lease-time-threshold
+ std::string error_message; // expected error message is parsing should fail
+ };
+
+ // Test Scenarios.
+ std::vector<Scenario> tests = {
+ {"valid", .25, ""},
+ {"valid", 1.0, ""},
+ {"negative", -.25,
+ "subnet configuration failed: adaptive-lease-time-threshold:"
+ " -0.25 is invalid, it must be greater than 0.0 and less than or equal to 1.0"
+ },
+ {"excluded", 0.,
+ "subnet configuration failed: adaptive-lease-time-threshold:"
+ " 0 is invalid, it must be greater than 0.0 and less than or equal to 1.0"
+ },
+ {"too big", 1.05,
+ "subnet configuration failed: adaptive-lease-time-threshold:"
+ " 1.05 is invalid, it must be greater than 0.0 and less than or equal to 1.0"
+ }
+ };
+
+ // First we create a set of elements that provides all
+ // required for a Subnet4.
+ std::string json =
+ " {"
+ " \"id\": 1,\n"
+ " \"subnet\": \"10.1.2.0/24\", \n"
+ " \"interface\": \"\", \n"
+ " \"renew-timer\": 100, \n"
+ " \"rebind-timer\": 200, \n"
+ " \"valid-lifetime\": 300, \n"
+ " \"match-client-id\": false, \n"
+ " \"authoritative\": false, \n"
+ " \"next-server\": \"\", \n"
+ " \"server-hostname\": \"\", \n"
+ " \"boot-file-name\": \"\", \n"
+ " \"client-classes\": [], \n"
+ " \"evaluate-additional-classes\": [], \n"
+ " \"reservations-global\": false, \n"
+ " \"reservations-in-subnet\": true, \n"
+ " \"reservations-out-of-pool\": false, \n"
+ " \"4o6-interface\": \"\", \n"
+ " \"4o6-interface-id\": \"\", \n"
+ " \"4o6-subnet\": \"\" \n"
+ " }";
+
+ data::ElementPtr elems;
+ ASSERT_NO_THROW(elems = data::Element::fromJSON(json))
+ << "invalid JSON:" << json << "\n test is broken";
+
+ // Iterate over the test scenarios, verifying each prescribed
+ // outcome.
+ for (auto const& test : tests) {
+ {
+ SCOPED_TRACE("test: " + test.label);
+
+ // Set this scenario's configuration parameters
+ elems->set("adaptive-lease-time-threshold",
+ data::Element::create(test.threshold));
+
+ Subnet4Ptr subnet;
+ try {
+ // Attempt to parse the configuration.
+ Subnet4ConfigParser parser;
+ subnet = parser.parse(elems);
+ } catch (const std::exception& ex) {
+ if (!test.error_message.empty()) {
+ // We expected a failure, did we fail the correct way?
+ EXPECT_EQ(test.error_message, ex.what());
+ } else {
+ // Should not have failed.
+ ADD_FAILURE() << "Scenario should not have failed: " << ex.what();
+ }
+
+ // Either way we're done with this scenario.
+ continue;
+ }
+
+ // We parsed correctly, make sure the values are right.
+ EXPECT_TRUE(util::areDoublesEquivalent(test.threshold,
+ subnet->getAdaptiveLeaseTimeThreshold()));
+ }
+ }
+}
+
// This test verifies that the optional interface check works as expected.
TEST(CfgSubnets4Test, iface) {
// Create a configuration.
subnet1->setT1Percent(0.45);
subnet1->setT2Percent(0.70);
subnet1->setCacheThreshold(0.20);
+ subnet1->setAdaptiveLeaseTimeThreshold(.90);
subnet2->setIface("lo");
subnet2->addRelayAddress(IOAddress("2001:db8:ff::2"));
" \"valid-lifetime\": 4,\n"
" \"min-valid-lifetime\": 4,\n"
" \"max-valid-lifetime\": 4,\n"
+ " \"adaptive-lease-time-threshold\": .90,\n"
" \"client-classes\": [ \"foo\", \"bar\" ],\n"
" \"pools\": [ ],\n"
" \"pd-pools\": [ ],\n"
{"too big", 1.05,
"subnet configuration failed: cache-threshold:"
" 1.05 is invalid, it must be greater than or equal to 0.0 and less than 1.0"
+ },
+ {"excluded", 1.0,
+ "subnet configuration failed: cache-threshold:"
+ " 1 is invalid, it must be greater than or equal to 0.0 and less than 1.0"
}
};
}
}
+// This test verifies the Subnet6 parser's validation logic for
+// adaptive lease time parameter.
+TEST(CfgSubnets6Test, AdaptiveLeaseTimeParamValidation) {
+
+ // Describes a single test scenario.
+ struct Scenario {
+ std::string label; // label used for logging test failures
+ double threshold; // value of adaptive-lease-time-threshold
+ std::string error_message; // expected error message is parsing should fail
+ };
+
+ // Test Scenarios.
+ std::vector<Scenario> tests = {
+ {"valid", .25, ""},
+ {"valid", 1.0, ""},
+ {"negative", -.25,
+ "subnet configuration failed: adaptive-lease-time-threshold:"
+ " -0.25 is invalid, it must be greater than 0.0 and less than or equal to 1.0"
+ },
+ {"excluded", 0.,
+ "subnet configuration failed: adaptive-lease-time-threshold:"
+ " 0 is invalid, it must be greater than 0.0 and less than or equal to 1.0"
+ },
+ {"too big", 1.05,
+ "subnet configuration failed: adaptive-lease-time-threshold:"
+ " 1.05 is invalid, it must be greater than 0.0 and less than or equal to 1.0"
+ }
+ };
+
+ // First we create a set of elements that provides all
+ // required for a Subnet6.
+ std::string json =
+ " {"
+ " \"id\": 1,\n"
+ " \"subnet\": \"2001:db8:1::/64\", \n"
+ " \"interface\": \"\", \n"
+ " \"renew-timer\": 100, \n"
+ " \"rebind-timer\": 200, \n"
+ " \"valid-lifetime\": 300, \n"
+ " \"client-classes\": [], \n"
+ " \"evaluate-additional-classes\": [], \n"
+ " \"reservations-global\": false, \n"
+ " \"reservations-in-subnet\": true, \n"
+ " \"reservations-out-of-pool\": false \n"
+ " }";
+
+ data::ElementPtr elems;
+ ASSERT_NO_THROW(elems = data::Element::fromJSON(json))
+ << "invalid JSON:" << json << "\n test is broken";
+
+ // Iterate over the test scenarios, verifying each prescribed
+ // outcome.
+ for (auto const& test : tests) {
+ {
+ SCOPED_TRACE("test: " + test.label);
+
+ // Set this scenario's configuration parameters
+ elems->set("adaptive-lease-time-threshold",
+ data::Element::create(test.threshold));
+
+ Subnet6Ptr subnet;
+ try {
+ // Attempt to parse the configuration.
+ Subnet6ConfigParser parser;
+ subnet = parser.parse(elems);
+ } catch (const std::exception& ex) {
+ if (!test.error_message.empty()) {
+ // We expected a failure, did we fail the correct way?
+ EXPECT_EQ(test.error_message, ex.what());
+ } else {
+ // Should not have failed.
+ ADD_FAILURE() << "Scenario should not have failed: " << ex.what();
+ }
+
+ // Either way we're done with this scenario.
+ continue;
+ }
+
+ // We parsed correctly, make sure the values are right.
+ EXPECT_TRUE(util::areDoublesEquivalent(test.threshold,
+ subnet->getAdaptiveLeaseTimeThreshold()));
+ }
+ }
+}
+
// This test verifies that the optional interface check works as expected.
TEST(CfgSubnets6Test, iface) {
// Create a configuration.
globals_->set("ddns-ttl", Element::create(400));
globals_->set("ddns-ttl-min", Element::create(200));
globals_->set("ddns-ttl-max", Element::create(600));
+ globals_->set("adaptive-lease-time-threshold", Element::create(.90));
// For each parameter for which inheritance is supported run
// the test that checks if the values are inherited properly.
&Network::setDdnsTtlMax,
500, 600);
}
+ {
+ SCOPED_TRACE("adaptive-lease-time-threshold");
+ testNetworkInheritance<TestNetwork4>(&Network::getAdaptiveLeaseTimeThreshold,
+ &Network::setAdaptiveLeaseTimeThreshold,
+ .80, .90);
+ }
}
// This test verifies that the inheritance is supported for DHCPv6
globals_->set("ddns-ttl-max", Element::create(600));
globals_->set("cache-threshold", Element::create(.35));
globals_->set("cache-max-age", Element::create(20));
+ globals_->set("adaptive-lease-time-threshold", Element::create(.90));
// For each parameter for which inheritance is supported run
// the test that checks if the values are inherited properly.
&Network::setCacheMaxAge,
10, 20);
}
+ {
+ SCOPED_TRACE("adaptive-lease-time-threshold");
+ testNetworkInheritance<TestNetwork4>(&Network::getAdaptiveLeaseTimeThreshold,
+ &Network::setAdaptiveLeaseTimeThreshold,
+ .80, .90);
+ }
// Interface-id requires special type of test.
boost::shared_ptr<TestNetwork6> net_child(new TestNetwork6());
" \"store-extended-info\": true,"
" \"cache-threshold\": 0.123,"
" \"cache-max-age\": 123,"
+ " \"adaptive-lease-time-threshold\": .90,"
" \"offer-lifetime\": 777,"
" \"ddns-update-on-renew\": true,"
" \"option-data\": ["
" \"hostname-char-set\": \"\","
" \"cache-threshold\": .20,"
" \"cache-max-age\": 50,"
- " \"allocator\": \"random\""
+ " \"allocator\": \"random\","
+ " \"adaptive-lease-time-threshold\": .80"
" },"
" {"
" \"id\": 2,"
" \"t1-percent\": .40,"
" \"t2-percent\": .80,"
" \"cache-threshold\": 0.0,"
- " \"cache-max-age\": 0"
+ " \"cache-max-age\": 0,"
+ " \"adaptive-lease-time-threshold\": .70"
" }"
" ]"
"}";
EXPECT_EQ(777, network->getOfferLft().get());
EXPECT_TRUE(network->getDdnsUpdateOnRenew().get());
EXPECT_EQ("iterative", network->getAllocatorType().get());
+ EXPECT_EQ(.90, network->getAdaptiveLeaseTimeThreshold().get());
// Relay information.
auto relay_info = network->getRelayInfo();
" \"ddns-update-on-renew\": true,"
" \"allocator\": \"random\","
" \"pd-allocator\": \"iterative\","
+ " \"adaptive-lease-time-threshold\": .90,"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
EXPECT_TRUE(network->getDdnsUpdateOnRenew().get());
EXPECT_EQ("random", network->getAllocatorType().get());
EXPECT_EQ("iterative", network->getPdAllocatorType().get());
+ EXPECT_EQ(.90, network->getAdaptiveLeaseTimeThreshold().get());
// Relay information.
auto relay_info = network->getRelayInfo();