#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>
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) {
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.
} 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
// 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
#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"
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());
+}
+
+
}
#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>
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) {
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) {
subnet_parser->commit();
}
+ // Commit global options
+ commitGlobalParameters6();
+
// No need to commit interface names as this is handled by the
// CfgMgr::commit() function.
#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>
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());
+}
+
+
+
};
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
--- /dev/null
+// 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
: 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
/// @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.
/// @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.