Commit e8632125 authored by Thomas Markwalder's avatar Thomas Markwalder

[#365,!296] Addressed review comments.

parent 9c8ca39b
1566. [func] tmark
kea-dhcp6 can now be configured to calculate values to
send to clients for for T1 and T2 times. Prior to this
send to clients for T1 and T2 times. Prior to this
it was only possibly to specify explicit values.
(Gitlab #365,!296, git TBD)
......
// This is an example configuration file for DHCPv6 server in Kea.
// It's a basic scenario with three IPv6 subnets use different
// methods for determining T1 and T2 values.
{ "Dhcp6":
{
// Kea is told to listen on ethX interface only.
"interfaces-config": {
"interfaces": [ "ethX" ]
},
// We need to specify the the database used to store leases. As of
// September 2016, four database backends are supported: MySQL,
// PostgreSQL, Cassandra, and the in-memory database, Memfile.
// We'll use memfile because it doesn't require any prior set up.
"lease-database": {
"type": "memfile"
},
// Addresses will be assigned with preferred and valid lifetimes
// being 3000 and 4000, respectively. By default calculate-tee-times
// is true with values of .5 and .8 for t1-percent and t2-percent
// respectively. Since some of our subnets will use calculated values and
// we must NOT specify global values for renew-timer and rebind-timer.
"preferred-lifetime": 3000,
"valid-lifetime": 4000,
// The following list defines subnets. Each subnet consists of at
// least subnet and pool entries.
"subnet6": [
{
// This subnet use default calculation
"subnet": "2001:db8:1::/64",
"pools": [ { "pool": "2001:db8:1::/80" } ]
},
{
// This subnet will use explicit values. Explict
// values override calculation.
"subnet": "2001:db8:2::/64",
"pools": [ { "pool": "2001:db8:2::/80" } ],
"renew-timer": 1000,
"rebind-timer": 2000
},
{
// This subnet will use custom percents
"subnet": "2001:db8:3::/64",
"pools": [ { "pool": "2001:db8:3::/80" } ],
"t1-percent": .45,
"t2-percent": .7
}]
},
// The following configures logging. It assumes that messages with at
// least informational level (info, warn, error and fatal) should be
// logged to stdout.
"Logging": {
"loggers": [
{
"name": "kea-dhcp6",
"output_options": [
{
"output": "stdout"
}
],
"debuglevel": 0,
"severity": "INFO"
}
]
}
}
......@@ -2047,13 +2047,13 @@ should include options from the new option space:
<section xml:id="dhcp6-t1-t2-times">
<title>Controlling the Values Sent for T1 and T2 Times</title>
According to <link xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="http://tools.ietf.org/html/rfc3315">RFC 3315</link>,
xlink:href="http://tools.ietf.org/html/rfc8415">RFC 8415, section 21.4</link>,
servers should send values for T1 and T2 that are 50% and 80%
of the lease life time, repsectively. By default, kea-dhcp6 will
send zero for both values. It can be configured to send values that
are specified explicitly or that are calculated as percentages of
the valid lease time. The server's behavior is governed by combination of
configuration parameters, two of which have already been mentioned.
of the preferred lease time, repsectively. Kea can be configured
to send values that are specified explicitly or that are calculated as
percentages of the valid lease time. The server's behavior is governed
by combination of configuration parameters, two of which have already been
mentioned.
<para>
To send specific, fixed values use the following two parameters:
<itemizedlist>
......@@ -2068,9 +2068,9 @@ should include options from the new option space:
</simpara>
</listitem>
</itemizedlist>
The server will only send T2 if it is less than valid lease time. T1 will
only be sent if a: T2 is being sent and T1 is less than T2 or b: T2 is not being
sent and T1 is less than the valid lease time.
The server will only use T2 if it is less than valid lease time, otherwise it will
be set to 0. T1 will only be use if it is less than T2, otherwise it will be
set to 0.
</para>
<para>
Calculating the values is controlled by the following three parameters.
......@@ -2078,7 +2078,7 @@ should include options from the new option space:
<listitem>
<simpara>
<command>calculate-tee-times</command> - when true, T1 and T2 will be
calculated as percentages of the valid lease time. It defaults to false.
calculated as percentages of the valid lease time. It defaults to true.
</simpara>
</listitem>
<listitem>
......
......@@ -1926,7 +1926,7 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, const Pkt6Ptr& /*answer*/,
l != leases.end(); ++l) {
// Check for new minimum lease time
if (min_valid_lft > (*l)->valid_lft_) {
if (((*l)->valid_lft_ > 0) && (min_valid_lft > (*l)->valid_lft_)) {
min_valid_lft = (*l)->valid_lft_;
}
......@@ -2077,7 +2077,7 @@ Dhcpv6Srv::extendIA_NA(const Pkt6Ptr& query, const Pkt6Ptr& answer,
ia_rsp->addOption(iaaddr);
// Check for new minimum lease time
if ((*l)->valid_lft_ < min_valid_lft) {
if (((*l)->valid_lft_ > 0) && (min_valid_lft > (*l)->valid_lft_)) {
min_valid_lft = (*l)->valid_lft_;
}
......
This diff is collapsed.
......@@ -121,7 +121,7 @@ public:
// Now try to get the element being checked
ConstElementPtr elem = map->get(param_name);
ASSERT_FALSE(elem) << "param was found found: " << param_name;
ASSERT_FALSE(elem) << "param was found but not expected: " << param_name;
}
};
......@@ -139,7 +139,7 @@ TEST_F(SimpleParser6Test, globalDefaults6) {
checkIntegerValue(empty, "valid-lifetime", 7200);
checkIntegerValue(empty, "preferred-lifetime", 3600);
checkBoolValue(empty, "calculate-tee-times", false);
checkBoolValue(empty, "calculate-tee-times", true);
checkDoubleValue(empty, "t1-percent", 0.5);
checkDoubleValue(empty, "t2-percent", 0.8);
......
......@@ -30,10 +30,7 @@ namespace {
///
const char* TEE_CONFIGS[] = {
// Configuration 0, Timers explicitly set
"{ \n"
" \"interfaces-config\": { \n"
" \"interfaces\": [ \"*\" ] \n"
" }, \n"
"{ \n"
" \"renew-timer\": 1000, \n"
" \"rebind-timer\": 2000, \n"
" \"preferred-lifetime\": 3000, \n"
......@@ -51,11 +48,7 @@ const char* TEE_CONFIGS[] = {
" }] \n"
"} \n"
, // Configuration 1, Calculate default timers
"{ \n"
" \"interfaces-config\": { \n"
" \"interfaces\": [ \"*\" ] \n"
" }, \n"
" \"calculate-tee-times\": true, \n"
"{ \n"
" \"preferred-lifetime\": 3000, \n"
" \"valid-lifetime\": 4000, \n"
" \"subnet6\": [ { \n"
......@@ -70,6 +63,24 @@ const char* TEE_CONFIGS[] = {
" }] \n"
" }] \n"
"} \n"
, // Configuration 2, Calculate custom timers
"{ \n"
" \"preferred-lifetime\": 3000, \n"
" \"valid-lifetime\": 4000, \n"
" \"t1-percent\": .45, \n"
" \"t2-percent\": .70, \n"
" \"subnet6\": [ { \n"
" \"interface\": \"eth0\", \n"
" \"subnet\": \"2001:db8:1::/48\", \n"
" \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ], \n"
" \"pd-pools\": [ \n"
" { \n"
" \"prefix\": \"3000::\", \n "
" \"prefix-len\": 72, \n"
" \"delegated-len\": 80 \n"
" }] \n"
" }] \n"
"} \n"
};
/// @brief Test fixture class for testing Rebind.
......@@ -83,7 +94,7 @@ public:
: Dhcpv6MessageTest() {
}
void genRequest(const std::string& config, Dhcp6Client& client,
void genRequest(const std::string& config, Dhcp6Client& client,
uint32_t exp_leases) {
// Configure the server.
ASSERT_NO_THROW(configure(config, *client.getServer()));
......@@ -99,6 +110,8 @@ public:
}
};
// This test verifies that explict values for renew-timer and
// rebind-timer are used when given.
TEST_F(TeeTest, explicitTimers) {
Dhcp6Client client;
......@@ -139,7 +152,10 @@ TEST_F(TeeTest, explicitTimers) {
EXPECT_EQ(2000, actual_t2);
}
TEST_F(TeeTest, calculateTimers) {
// This test verifies that T1 and T2 are calculated by
// default when explicit values for renew-timer
// and rebind-timer are not present.
TEST_F(TeeTest, defaultTimers) {
Dhcp6Client client;
uint32_t na_iaid = 2222;
......@@ -179,5 +195,48 @@ TEST_F(TeeTest, calculateTimers) {
EXPECT_EQ(3200, actual_t2);
}
// This test verifies that custom percentags for T1 and T2
// can be used for calculation.
TEST_F(TeeTest, calculateTimers) {
Dhcp6Client client;
uint32_t na_iaid = 2222;
client.requestAddress(na_iaid);
uint32_t pd_iaid = 3333;
client.requestPrefix(pd_iaid);
uint32_t exp_leases = 2;
// Configure client to request IA_NA.
// Make 4-way exchange to get the lease.
ASSERT_NO_FATAL_FAILURE(genRequest(TEE_CONFIGS[2], client, exp_leases));
// Make sure the timers are right for both IAs
uint32_t actual_t1;
uint32_t actual_t2;
ASSERT_TRUE(client.getTeeTimes(na_iaid, actual_t1, actual_t2));
EXPECT_EQ(1800, actual_t1);
EXPECT_EQ(2800, actual_t2);
ASSERT_TRUE(client.getTeeTimes(pd_iaid, actual_t1, actual_t2));
EXPECT_EQ(1800, actual_t1);
EXPECT_EQ(2800, actual_t2);
// Let's renew the leases.
ASSERT_NO_THROW(client.doRenew());
// Now check the timers again.
ASSERT_TRUE(client.getTeeTimes(na_iaid, actual_t1, actual_t2));
EXPECT_EQ(1800, actual_t1);
EXPECT_EQ(2800, actual_t2);
ASSERT_TRUE(client.getTeeTimes(pd_iaid, actual_t1, actual_t2));
EXPECT_EQ(1800, actual_t1);
EXPECT_EQ(2800, actual_t2);
}
} // end of anonymous namespace
......@@ -1176,9 +1176,8 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params,
std::ostringstream output;
output << addr << "/" << static_cast<int>(len)
<< " with params t1=" << subnet6->getT1().get()
<< ", t2=" << subnet6->getT2().get()
<< ", preferred-lifetime=" << pref.get()
<< " with params "
<< " preferred-lifetime=" << pref.get()
<< ", valid-lifetime=" << subnet6->getValid().get()
<< ", rapid-commit is " << (rapid_commit ? "enabled" : "disabled");
......
......@@ -106,7 +106,7 @@ const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = {
{ "dhcp4o6-port", Element::integer, "0" },
{ "server-tag", Element::string, "" },
{ "reservation-mode", Element::string, "all" },
{ "calculate-tee-times", Element::boolean, "false" },
{ "calculate-tee-times", Element::boolean, "true" },
{ "t1-percent", Element::real, ".50" },
{ "t2-percent", Element::real, ".80" }
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment