diff --git a/src/lib/dhcpsrv/network.h b/src/lib/dhcpsrv/network.h index 4eec014736..4a6e67f7ef 100644 --- a/src/lib/dhcpsrv/network.h +++ b/src/lib/dhcpsrv/network.h @@ -221,7 +221,8 @@ public: cache_threshold_(), cache_max_age_(), ddns_update_on_renew_(), ddns_conflict_resolution_mode_(), ddns_ttl_percent_(), ddns_ttl_(), ddns_ttl_min_(), ddns_ttl_max_(), - allocator_type_(), default_allocator_type_() { + allocator_type_(), default_allocator_type_(), + adaptive_lease_time_threshold_() { } /// @brief Virtual destructor. @@ -894,6 +895,25 @@ public: default_allocator_type_ = allocator_type; } + /// @brief Returns percentage of the adaptive lease time threshold, + /// + /// @param inheritance inheritance mode to be used. + util::Optional + getAdaptiveLeaseTimeThreshold(const Inheritance& inheritance = Inheritance::ALL) const { + return (getProperty(&Network::getAdaptiveLeaseTimeThreshold, + adaptive_lease_time_threshold_, + inheritance, + CfgGlobals::ADAPTIVE_LEASE_TIME_THRESHOLD)); + } + + /// @brief Sets new percentage of the adaptive lease time threshold. + /// + /// @param adaptive_lease_time_threshold New percentage to use. + void setAdaptiveLeaseTimeThreshold(const util::Optional& + adaptive_lease_time_threshold) { + adaptive_lease_time_threshold_ = adaptive_lease_time_threshold; + } + /// @brief Unparses network object. /// /// @return A pointer to unparsed network configuration. @@ -1308,6 +1328,11 @@ protected: /// backend internally. util::Optional default_allocator_type_; + /// @brief Percentage of the adaptive lease time threshold. + /// (a lease assignment over the threshold will get minimal or remaining + /// life times). + util::Optional adaptive_lease_time_threshold_; + /// @brief Pointer to another network that this network belongs to. /// /// The most common case is that this instance is a subnet which belongs diff --git a/src/lib/dhcpsrv/parsers/base_network_parser.cc b/src/lib/dhcpsrv/parsers/base_network_parser.cc index 0ca49f0943..3c2caa435a 100644 --- a/src/lib/dhcpsrv/parsers/base_network_parser.cc +++ b/src/lib/dhcpsrv/parsers/base_network_parser.cc @@ -17,7 +17,6 @@ using namespace isc::util; namespace isc { namespace dhcp { - void BaseNetworkParser::parseCommon(const ConstElementPtr& network_data, NetworkPtr& network) { @@ -171,6 +170,24 @@ BaseNetworkParser::parsePdAllocatorParams(const data::ConstElementPtr& network_d } } +void +BaseNetworkParser::parseAdaptiveLeaseTimeParam(const ConstElementPtr& network_data, + NetworkPtr& network) { + if (network_data->contains("adaptive-lease-time-threshold")) { + double adaptive_lease_time_threshold = + getDouble(network_data, "adaptive-lease-time-threshold"); + if ((adaptive_lease_time_threshold <= 0.0) || + (adaptive_lease_time_threshold > 1.0)) { + isc_throw(DhcpConfigError, + "adaptive-lease-time-threshold: " + << adaptive_lease_time_threshold + << " is invalid, it must be greater than 0.0 " + << "and less than or equal to 1.0"); + } + network->setAdaptiveLeaseTimeThreshold(adaptive_lease_time_threshold); + } +} + void BaseNetworkParser::parseOfferLft(const data::ConstElementPtr& network_data, Network4Ptr& network) { @@ -251,6 +268,5 @@ BaseNetworkParser::getClientClassesElem(ConstElementPtr params, } } - } // end of namespace isc::dhcp } // end of namespace isc diff --git a/src/lib/dhcpsrv/parsers/base_network_parser.h b/src/lib/dhcpsrv/parsers/base_network_parser.h index ca283b6d66..d81905eb39 100644 --- a/src/lib/dhcpsrv/parsers/base_network_parser.h +++ b/src/lib/dhcpsrv/parsers/base_network_parser.h @@ -117,6 +117,21 @@ protected: void parsePdAllocatorParams(const data::ConstElementPtr& network_data, Network6Ptr& network); + /// @brief Parses parameter related to adaptive lease time. + /// + /// The parsed parameter is: + /// - adaptive-lease-time-threshold. + /// + /// @param network_data Data element holding network configuration + /// to be parsed. + /// @param [out] network Pointer to a network in which parsed data is + /// to be stored. + /// + /// @throw DhcpConfigError if configuration of this parameter is + /// invalid. + void parseAdaptiveLeaseTimeParam(const data::ConstElementPtr& network_data, + NetworkPtr& network); + /// @brief Parses offer-lifetime parameter (v4 only) /// /// @param network_data Data element holding shared network diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index a0902fecfa..4ce5673b0e 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -972,6 +972,9 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params, // Parse lease cache parameters parseCacheParams(params, network); + // Parse adaptive lease time parameter. + parseAdaptiveLeaseTimeParam(params, network); + // Set the offer_lft value for the subnet. if (params->contains("offer-lifetime")) { uint32_t offer_lft = getInteger(params, "offer-lifetime"); @@ -1441,6 +1444,9 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params, // Parse lease cache parameters parseCacheParams(params, network); + + // Parse adaptive lease time parameter. + parseAdaptiveLeaseTimeParam(params, network); } void diff --git a/src/lib/dhcpsrv/parsers/shared_network_parser.cc b/src/lib/dhcpsrv/parsers/shared_network_parser.cc index 1590e899ed..5b8089db57 100644 --- a/src/lib/dhcpsrv/parsers/shared_network_parser.cc +++ b/src/lib/dhcpsrv/parsers/shared_network_parser.cc @@ -189,6 +189,9 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data, // Parse allocator params. parseAllocatorParams(shared_network_data, network); + // Parse adaptive lease time parameter. + parseAdaptiveLeaseTimeParam(shared_network_data, network); + // Parse offer-lifetime parameter. Network4Ptr network4 = boost::dynamic_pointer_cast(shared_network); parseOfferLft(shared_network_data, network4); @@ -368,6 +371,9 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data, auto network6 = boost::dynamic_pointer_cast(shared_network); parsePdAllocatorParams(shared_network_data, network6); + // Parse adaptive lease time parameter. + parseAdaptiveLeaseTimeParam(shared_network_data, network); + } catch (const std::exception& ex) { isc_throw(DhcpConfigError, ex.what() << " (" << shared_network_data->getPosition() << ")");