]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#226] Added set/getAdaptiveLeaseTimeThreshold
authorFrancis Dupont <fdupont@isc.org>
Thu, 7 Aug 2025 14:24:15 +0000 (16:24 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 20 Aug 2025 15:39:15 +0000 (17:39 +0200)
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/parsers/base_network_parser.cc
src/lib/dhcpsrv/parsers/base_network_parser.h
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/shared_network_parser.cc

index 4eec014736b4198fb40a99df6c9403db07183ca3..4a6e67f7ef0fae77ad3dc9c87e0c1a96effd1b19 100644 (file)
@@ -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<double>
+    getAdaptiveLeaseTimeThreshold(const Inheritance& inheritance = Inheritance::ALL) const {
+        return (getProperty<Network>(&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<double>&
+                                       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<std::string> 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<double> 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
index 0ca49f0943763511b64aad258eb40f7c650e6a4f..3c2caa435a5a249c4a0b0d7a5159070c67757a65 100644 (file)
@@ -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
index ca283b6d663bf05106be03311f70a8f2dc136c8a..d81905eb3911b503cafadbdba78cd1f24e9e87af 100644 (file)
@@ -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
index a0902fecfa9a4716fdf15889b2e06c295f047cf6..4ce5673b0eedc0ad28525509583230b3cb14a5a4 100644 (file)
@@ -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
index 1590e899ed20432573f8ea877aadb2a5cef12734..5b8089db5722e0e1af88b240a33782244ba80f3f 100644 (file)
@@ -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<Network4>(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<Network6>(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() << ")");