Commit 91bfb283 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3983] Support for 'decline-probation-period' implemented.

parent e9c58e3d
......@@ -21,6 +21,7 @@
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcp4/json_config_parser.h>
#include <dhcpsrv/defaults.h>
#include <dhcpsrv/option_space_container.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
......@@ -375,7 +376,8 @@ namespace dhcp {
DhcpConfigParser* parser = NULL;
if ((config_id.compare("valid-lifetime") == 0) ||
(config_id.compare("renew-timer") == 0) ||
(config_id.compare("rebind-timer") == 0)) {
(config_id.compare("rebind-timer") == 0) ||
(config_id.compare("decline-probation-period") == 0) ) {
parser = new Uint32Parser(config_id,
globalContext()->uint32_values_);
} else if (config_id.compare("interfaces-config") == 0) {
......@@ -411,7 +413,13 @@ namespace dhcp {
return (parser);
}
void commitGlobalOptions() {
/// @brief Commits global parameters
///
/// Currently this method sets the following global parameters:
///
/// - echo-client-id
/// - decline-probation-period
void commitGlobalParameters4() {
// Although the function is modest for now, it is certain that the number
// of global switches will increase over time, hence the name.
......@@ -423,6 +431,16 @@ void commitGlobalOptions() {
} catch (...) {
// Ignore errors. This flag is optional
}
// Set the probation period for decline handling.
try {
uint32_t probation_period = globalContext()->uint32_values_
->getOptionalParam("decline-probation-period",
DEFAULT_DECLINE_PROBATION_PERIOD);
CfgMgr::instance().getStagingCfg()->setDeclinePeriod(probation_period);
} catch (...) {
// That's not really needed.
}
}
isc::data::ConstElementPtr
......@@ -592,7 +610,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
// CfgMgr::commit() function.
// Apply global options
commitGlobalOptions();
commitGlobalParameters4();
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
......
......@@ -32,6 +32,7 @@
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <dhcpsrv/defaults.h>
#include <hooks/hooks_manager.h>
#include "marker_file.h"
......@@ -3647,4 +3648,49 @@ TEST_F(Dhcp4ParserTest, hostReservationPerSubnet) {
EXPECT_EQ(Subnet::HR_ALL, subnet->getHostReservationMode());
}
/// Check that the decline-probation-period has a default value when not
/// specified.
TEST_F(Dhcp4ParserTest, declineTimerDefault) {
ConstElementPtr status;
string config = "{ " + genIfaceConfig() + "," +
"\"subnet4\": [ ]"
"}";
ElementPtr json = Element::fromJSON(config);
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
// returned value should be 0 (success)
checkResult(status, 0);
// The value of decline-probation-perion must be equal to the
// default value.
EXPECT_EQ(DEFAULT_DECLINE_PROBATION_PERIOD,
CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
}
/// Check that the decline-probation-period value can be set properly.
TEST_F(Dhcp4ParserTest, declineTimer) {
ConstElementPtr status;
string config = "{ " + genIfaceConfig() + "," +
"\"decline-probation-period\": 12345,"
"\"subnet4\": [ ]"
"}";
ElementPtr json = Element::fromJSON(config);
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
// returned value should be 0 (success)
checkResult(status, 0);
// The value of decline-probation-perion must be equal to the
// value specified.
EXPECT_EQ(12345,
CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
}
}
......@@ -27,6 +27,7 @@
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/triplet.h>
#include <dhcpsrv/defaults.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_config_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
......@@ -666,7 +667,8 @@ namespace dhcp {
if ((config_id.compare("preferred-lifetime") == 0) ||
(config_id.compare("valid-lifetime") == 0) ||
(config_id.compare("renew-timer") == 0) ||
(config_id.compare("rebind-timer") == 0)) {
(config_id.compare("rebind-timer") == 0) ||
(config_id.compare("decline-probation-period") == 0) ) {
parser = new Uint32Parser(config_id,
globalContext()->uint32_values_);
} else if (config_id.compare("interfaces-config") == 0) {
......@@ -702,6 +704,24 @@ namespace dhcp {
return (parser);
}
/// @brief Commits global parameters
///
/// Currently this method sets the following global parameters:
///
/// - decline-probation-period
void commitGlobalParameters6() {
// Set the probation period for decline handling.
try {
uint32_t probation_period = globalContext()->uint32_values_
->getOptionalParam("decline-probation-period",
DEFAULT_DECLINE_PROBATION_PERIOD);
CfgMgr::instance().getStagingCfg()->setDeclinePeriod(probation_period);
} catch (...) {
// That's not really needed.
}
}
isc::data::ConstElementPtr
configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
if (!config_set) {
......@@ -870,6 +890,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
subnet_parser->commit();
}
// Commit global options
commitGlobalParameters6();
// No need to commit interface names as this is handled by the
// CfgMgr::commit() function.
......
......@@ -27,6 +27,7 @@
#include <dhcpsrv/addr_utilities.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/defaults.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_selector.h>
#include <dhcpsrv/testutils/config_result_check.h>
......@@ -3982,4 +3983,49 @@ TEST_F(Dhcp6ParserTest, rsooBogusName) {
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
}
/// Check that the decline-probation-period value can be set properly.
TEST_F(Dhcp6ParserTest, declineTimerDefault) {
ConstElementPtr status;
string config_txt = "{ " + genIfaceConfig() + ","
"\"subnet6\": [ ] "
"}";
ElementPtr config = Element::fromJSON(config_txt);
EXPECT_NO_THROW(status = configureDhcp6Server(srv_, config));
// returned value should be 0 (success)
checkResult(status, 0);
// The value of decline-probation-perion must be equal to the
// default value.
EXPECT_EQ(DEFAULT_DECLINE_PROBATION_PERIOD,
CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
}
/// Check that the decline-probation-period value can be set properly.
TEST_F(Dhcp6ParserTest, declineTimer) {
ConstElementPtr status;
string config = "{ " + genIfaceConfig() + "," +
"\"decline-probation-period\": 12345,"
"\"subnet6\": [ ]"
"}";
ElementPtr json = Element::fromJSON(config);
EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
// returned value should be 0 (success)
checkResult(status, 0);
// The value of decline-probation-perion must be equal to the
// value specified.
EXPECT_EQ(12345,
CfgMgr::instance().getStagingCfg()->getDeclinePeriod());
}
};
......@@ -92,6 +92,7 @@ libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h
libkea_dhcpsrv_la_SOURCES += d2_client_cfg.cc d2_client_cfg.h
libkea_dhcpsrv_la_SOURCES += d2_client_mgr.cc d2_client_mgr.h
libkea_dhcpsrv_la_SOURCES += daemon.cc daemon.h
libkea_dhcpsrv_la_SOURCES += defaults.h
libkea_dhcpsrv_la_SOURCES += dhcpsrv_log.cc dhcpsrv_log.h
libkea_dhcpsrv_la_SOURCES += host.cc host.h
libkea_dhcpsrv_la_SOURCES += host_container.h
......
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
/// @file defaults.h
///
/// @brief Contains the default values of the server.
#ifndef DEFAULTS_H
#define DEFAULTS_H
#include <stdint.h>
namespace isc {
namespace dhcp {
/// @brief Number of seconds after declined lease recovers
///
/// This define specifies the default value for decline probation period.
/// Once a lease is declined, it will spend this amount of seconds as
/// being unavailable. This is only the default value. Specific value may
/// be defined in the configuration file. The default is 1 day.
static const uint32_t DEFAULT_DECLINE_PROBATION_PERIOD = 24*3600;
};
};
#endif
......@@ -30,14 +30,16 @@ SrvConfig::SrvConfig()
: sequence_(0), cfg_iface_(new CfgIface()),
cfg_option_def_(new CfgOptionDef()), cfg_option_(new CfgOption()),
cfg_subnets4_(new CfgSubnets4()), cfg_subnets6_(new CfgSubnets6()),
cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()) {
cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()),
decline_timer_(0) {
}
SrvConfig::SrvConfig(const uint32_t sequence)
: sequence_(sequence), cfg_iface_(new CfgIface()),
cfg_option_def_(new CfgOptionDef()), cfg_option_(new CfgOption()),
cfg_subnets4_(new CfgSubnets4()), cfg_subnets6_(new CfgSubnets6()),
cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()) {
cfg_hosts_(new CfgHosts()), cfg_rsoo_(new CfgRSOO()),
decline_timer_(0) {
}
std::string
......
......@@ -376,6 +376,17 @@ public:
/// @ref CfgSubnets6::removeStatistics for details.
void removeStatistics();
/// @brief Sets decline probation-period
/// @param decline_timer number of seconds after declined lease is restored
void setDeclinePeriod(uint32_t decline_timer) {
decline_timer_ = decline_timer;
}
/// @brief
uint32_t getDeclinePeriod() const {
return (decline_timer_);
}
private:
/// @brief Sequence number identifying the configuration.
......@@ -425,6 +436,9 @@ private:
/// @brief Pointer to the control-socket information
isc::data::ConstElementPtr control_socket_;
/// @brief Decline Period time
uint32_t decline_timer_;
};
/// @name Pointers to the @c SrvConfig object.
......
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