Kea 2.7.6
cfg_expiration.h
Go to the documentation of this file.
1// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef CFG_EXPIRATION_H
8#define CFG_EXPIRATION_H
9
11#include <cc/cfg_to_element.h>
12#include <dhcpsrv/timer_mgr.h>
13#include <boost/shared_ptr.hpp>
14#include <functional>
15#include <stdint.h>
16#include <string>
17
18namespace isc {
19namespace dhcp {
20
62public:
63
68 static const uint16_t DEFAULT_RECLAIM_TIMER_WAIT_TIME;
69
72
74 static const uint32_t DEFAULT_HOLD_RECLAIMED_TIME;
75
77 static const uint32_t DEFAULT_MAX_RECLAIM_LEASES;
78
80 static const uint16_t DEFAULT_MAX_RECLAIM_TIME;
81
83 static const uint16_t DEFAULT_UNWARNED_RECLAIM_CYCLES;
84
86
91 static const uint16_t LIMIT_RECLAIM_TIMER_WAIT_TIME;
92
95
97 static const uint32_t LIMIT_HOLD_RECLAIMED_TIME;
98
100 static const uint32_t LIMIT_MAX_RECLAIM_LEASES;
101
103 static const uint16_t LIMIT_MAX_RECLAIM_TIME;
104
106 static const uint16_t LIMIT_UNWARNED_RECLAIM_CYCLES;
107
109
112
114 static const std::string RECLAIM_EXPIRED_TIMER_NAME;
115
117 static const std::string FLUSH_RECLAIMED_TIMER_NAME;
118
120
129 CfgExpiration(const bool test_mode = false);
130
132 uint16_t getReclaimTimerWaitTime() const {
133 return (reclaim_timer_wait_time_);
134 }
135
139 void setReclaimTimerWaitTime(const int64_t reclaim_timer_wait_time);
140
143 return (flush_reclaimed_timer_wait_time_);
144 }
145
149 void setFlushReclaimedTimerWaitTime(const int64_t flush_reclaimed_wait_time);
150
152 uint32_t getHoldReclaimedTime() const {
153 return (hold_reclaimed_time_);
154 }
155
159 void setHoldReclaimedTime(const int64_t hold_reclaimed_time);
160
162 uint32_t getMaxReclaimLeases() const {
163 return (max_reclaim_leases_);
164 }
165
169 void setMaxReclaimLeases(const int64_t max_reclaim_leases);
170
172 uint16_t getMaxReclaimTime() const {
173 return (max_reclaim_time_);
174 }
175
179 void setMaxReclaimTime(const int64_t max_reclaim_time);
180
182 uint16_t getUnwarnedReclaimCycles() const {
183 return (unwarned_reclaim_cycles_);
184 }
185
189 void setUnwarnedReclaimCycles(const int64_t unwarned_reclaim_cycles);
190
221 template<typename Instance>
222 void setupTimers(void (Instance::*reclaim_fun)(const size_t, const uint16_t,
223 const bool, const uint16_t),
224 void (Instance::*delete_fun)(const uint32_t),
225 Instance* instance_ptr) const;
226
230 virtual isc::data::ElementPtr toElement() const;
231
232private:
233
244 void rangeCheck(const int64_t value, const uint64_t max_value,
245 const std::string& config_parameter_name) const;
246
248 uint16_t reclaim_timer_wait_time_;
249
251 uint16_t flush_reclaimed_timer_wait_time_;
252
254 uint32_t hold_reclaimed_time_;
255
257 uint32_t max_reclaim_leases_;
258
260 uint16_t max_reclaim_time_;
261
263 uint16_t unwarned_reclaim_cycles_;
264
266 TimerMgrPtr timer_mgr_;
267
269 bool test_mode_;
270};
271
275typedef boost::shared_ptr<CfgExpiration> CfgExpirationPtr;
276
278typedef boost::shared_ptr<const CfgExpiration> ConstCfgExpirationPtr;
279
281
282template<typename Instance>
283void
284CfgExpiration::setupTimers(void (Instance::*reclaim_fun)(const size_t,
285 const uint16_t,
286 const bool,
287 const uint16_t),
288 void (Instance::*delete_fun)(const uint32_t),
289 Instance* instance_ptr) const {
290 // One of the parameters passed to the leases' reclamation routine
291 // is a boolean value which indicates if reclaimed leases should
292 // be removed by the leases' reclamation routine. This is the case
293 // when the timer for flushing reclaimed leases is set to 0
294 // (disabled).
295 const bool flush_timer_disabled = (getFlushReclaimedTimerWaitTime() == 0);
296
297 // If the timer interval for the leases reclamation is non-zero
298 // the timer will be scheduled.
299 if (getReclaimTimerWaitTime() > 0) {
300 // In the test mode the interval is expressed in milliseconds.
301 // If this is not the test mode, the interval is in seconds.
302 const long reclaim_interval = test_mode_ ? getReclaimTimerWaitTime() :
304 // Register timer for leases' reclamation routine.
305 timer_mgr_->registerTimer(RECLAIM_EXPIRED_TIMER_NAME,
306 std::bind(reclaim_fun, instance_ptr,
309 flush_timer_disabled,
311 reclaim_interval,
313 timer_mgr_->setup(RECLAIM_EXPIRED_TIMER_NAME);
314 }
315
316 // If the interval for the timer flushing expired-reclaimed leases
317 // is set we will schedule the timer.
318 if (!flush_timer_disabled) {
319 // The interval is specified in milliseconds if we're in the test mode.
320 // It is specified in seconds otherwise.
321 const long flush_interval = test_mode_ ?
324 // Register and setup the timer.
325 timer_mgr_->registerTimer(FLUSH_RECLAIMED_TIMER_NAME,
326 std::bind(delete_fun, instance_ptr,
328 flush_interval,
330 timer_mgr_->setup(FLUSH_RECLAIMED_TIMER_NAME);
331 }
332}
333
334
335} // end of isc::dhcp namespace
336} // end of isc namespace
337
338#endif // CFG_EXPIRATION_H
Holds configuration parameters pertaining to lease expiration and lease affinity.
void setReclaimTimerWaitTime(const int64_t reclaim_timer_wait_time)
Sets reclaim-timer-wait-time.
static const uint16_t LIMIT_FLUSH_RECLAIMED_TIMER_WAIT_TIME
Maximum value for flush-reclaimed-timer-wait-time.
static const std::string FLUSH_RECLAIMED_TIMER_NAME
Name of the timer for flushing reclaimed leases.
void setupTimers(void(Instance::*reclaim_fun)(const size_t, const uint16_t, const bool, const uint16_t), void(Instance::*delete_fun)(const uint32_t), Instance *instance_ptr) const
Setup timers for the reclamation of expired leases according to the configuration parameters.
void setMaxReclaimLeases(const int64_t max_reclaim_leases)
Sets max-reclaim-leases.
void setUnwarnedReclaimCycles(const int64_t unwarned_reclaim_cycles)
Sets unwarned-reclaim-cycles.
static const uint32_t LIMIT_MAX_RECLAIM_LEASES
Maximum value for max-reclaim-leases.
void setHoldReclaimedTime(const int64_t hold_reclaimed_time)
Sets hold-reclaimed-time.
static const uint16_t DEFAULT_RECLAIM_TIMER_WAIT_TIME
Default value for reclaim-timer-wait-time.
uint16_t getFlushReclaimedTimerWaitTime() const
Returns flush-reclaimed-timer-wait-time.
static const uint16_t LIMIT_UNWARNED_RECLAIM_CYCLES
Maximum value for unwarned-reclaim-cycles.
static const uint16_t LIMIT_RECLAIM_TIMER_WAIT_TIME
Maximum value for reclaim-timer-wait-time.
uint32_t getHoldReclaimedTime() const
Returns hold-reclaimed-time.
uint16_t getMaxReclaimTime() const
Returns max-reclaim-time.
static const uint32_t LIMIT_HOLD_RECLAIMED_TIME
Maximum value for hold-reclaimed-time.
CfgExpiration(const bool test_mode=false)
Constructor.
static const uint16_t DEFAULT_UNWARNED_RECLAIM_CYCLES
Default value for unwarned-reclaim-cycles.
void setMaxReclaimTime(const int64_t max_reclaim_time)
Sets max-reclaim-time.
static const uint16_t DEFAULT_FLUSH_RECLAIMED_TIMER_WAIT_TIME
Default value for flush-reclaimed-timer-wait-time.
static const uint16_t DEFAULT_MAX_RECLAIM_TIME
Default value for max-reclaim-time.
uint32_t getMaxReclaimLeases() const
Returns max-reclaim-leases.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
static const uint16_t LIMIT_MAX_RECLAIM_TIME
Default value for max-reclaim-time.
static const std::string RECLAIM_EXPIRED_TIMER_NAME
Name of the timer for reclaiming expired leases.
uint16_t getReclaimTimerWaitTime() const
Returns reclaim-timer-wait-time.
void setFlushReclaimedTimerWaitTime(const int64_t flush_reclaimed_wait_time)
Sets flush-reclaimed-timer-wait-time.
static const uint32_t DEFAULT_HOLD_RECLAIMED_TIME
Default value for hold-reclaimed-time.
uint16_t getUnwarnedReclaimCycles() const
Returns unwarned-reclaim-cycles.
static const uint32_t DEFAULT_MAX_RECLAIM_LEASES
Default value for max-reclaim-leases.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< const CfgExpiration > ConstCfgExpirationPtr
Pointer to the const object.
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
Definition timer_mgr.h:27
boost::shared_ptr< CfgExpiration > CfgExpirationPtr
Pointer to the Non-const object.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.