Kea  2.1.7-git
cfg_expiration.cc
Go to the documentation of this file.
1 // Copyright (C) 2015,2017 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 #include <config.h>
8 
10 #include <exceptions/exceptions.h>
11 #include <limits>
12 
13 using namespace isc::data;
14 
15 namespace isc {
16 namespace dhcp {
17 
18 // Default values
19 const uint16_t CfgExpiration::DEFAULT_RECLAIM_TIMER_WAIT_TIME = 10;
20 const uint16_t CfgExpiration::DEFAULT_FLUSH_RECLAIMED_TIMER_WAIT_TIME = 25;
21 const uint32_t CfgExpiration::DEFAULT_HOLD_RECLAIMED_TIME = 3600;
22 const uint32_t CfgExpiration::DEFAULT_MAX_RECLAIM_LEASES = 100;
23 const uint16_t CfgExpiration::DEFAULT_MAX_RECLAIM_TIME = 250;
24 const uint16_t CfgExpiration::DEFAULT_UNWARNED_RECLAIM_CYCLES = 5;
25 
26 // Maximum values.
27 const uint16_t CfgExpiration::LIMIT_RECLAIM_TIMER_WAIT_TIME =
28  std::numeric_limits<uint16_t>::max();
29 const uint16_t CfgExpiration::LIMIT_FLUSH_RECLAIMED_TIMER_WAIT_TIME =
30  std::numeric_limits<uint16_t>::max();
31 const uint32_t CfgExpiration::LIMIT_HOLD_RECLAIMED_TIME =
32  std::numeric_limits<uint32_t>::max();
33 const uint32_t CfgExpiration::LIMIT_MAX_RECLAIM_LEASES =
34  std::numeric_limits<uint32_t>::max();
35 const uint16_t CfgExpiration::LIMIT_MAX_RECLAIM_TIME = 10000;
36 const uint16_t CfgExpiration::LIMIT_UNWARNED_RECLAIM_CYCLES =
37  std::numeric_limits<uint16_t>::max();
38 
39 // Timers' names
40 const std::string CfgExpiration::RECLAIM_EXPIRED_TIMER_NAME =
41  "reclaim-expired-leases";
42 
43 const std::string CfgExpiration::FLUSH_RECLAIMED_TIMER_NAME =
44  "flush-reclaimed-leases";
45 
46 CfgExpiration::CfgExpiration(const bool test_mode)
47  : reclaim_timer_wait_time_(DEFAULT_RECLAIM_TIMER_WAIT_TIME),
48  flush_reclaimed_timer_wait_time_(DEFAULT_FLUSH_RECLAIMED_TIMER_WAIT_TIME),
49  hold_reclaimed_time_(DEFAULT_HOLD_RECLAIMED_TIME),
50  max_reclaim_leases_(DEFAULT_MAX_RECLAIM_LEASES),
51  max_reclaim_time_(DEFAULT_MAX_RECLAIM_TIME),
52  unwarned_reclaim_cycles_(DEFAULT_UNWARNED_RECLAIM_CYCLES),
53  timer_mgr_(TimerMgr::instance()),
54  test_mode_(test_mode) {
55 }
56 
57 void
58 CfgExpiration::setReclaimTimerWaitTime(const int64_t reclaim_timer_wait_time) {
59  rangeCheck(reclaim_timer_wait_time, LIMIT_RECLAIM_TIMER_WAIT_TIME,
60  "reclaim-timer-wait-time");
61  reclaim_timer_wait_time_ = reclaim_timer_wait_time;
62 }
63 
64 void
65 CfgExpiration::setFlushReclaimedTimerWaitTime(const int64_t flush_reclaimed_wait_time) {
66  rangeCheck(flush_reclaimed_wait_time, LIMIT_FLUSH_RECLAIMED_TIMER_WAIT_TIME,
67  "flush-reclaimed-timer-wait-time");
68  flush_reclaimed_timer_wait_time_ = flush_reclaimed_wait_time;
69 }
70 
71 void
72 CfgExpiration::setHoldReclaimedTime(const int64_t hold_reclaimed_time) {
73  rangeCheck(hold_reclaimed_time, LIMIT_HOLD_RECLAIMED_TIME, "hold-reclaimed-time");
74  hold_reclaimed_time_ = hold_reclaimed_time;
75 }
76 
77 void
78 CfgExpiration::setMaxReclaimLeases(const int64_t max_reclaim_leases) {
79  rangeCheck(max_reclaim_leases, LIMIT_MAX_RECLAIM_LEASES, "max-reclaim-leases");
80  max_reclaim_leases_ = max_reclaim_leases;
81 }
82 
83 void
84 CfgExpiration::setMaxReclaimTime(const int64_t max_reclaim_time) {
85  rangeCheck(max_reclaim_time, LIMIT_MAX_RECLAIM_TIME, "max-reclaim-time");
86  max_reclaim_time_ = max_reclaim_time;
87 }
88 
89 void
90 CfgExpiration::setUnwarnedReclaimCycles(const int64_t unwarned_reclaim_cycles) {
91  rangeCheck(unwarned_reclaim_cycles, LIMIT_UNWARNED_RECLAIM_CYCLES,
92  "unwarned-reclaim-cycles");
93  unwarned_reclaim_cycles_ = unwarned_reclaim_cycles;
94 }
95 
96 void
97 CfgExpiration::rangeCheck(const int64_t value, const uint64_t max_value,
98  const std::string& config_parameter_name) const {
99  if (value < 0) {
100  isc_throw(OutOfRange, "value for configuration parameter '"
101  << config_parameter_name << "' must not be negative");
102 
103  } else if (value > max_value) {
104  isc_throw(OutOfRange, "out range value '" << value << "' for configuration"
105  " parameter '" << config_parameter_name << "', expected maximum"
106  " value of '" << max_value << "'");
107  }
108 }
109 
112  ElementPtr result = Element::createMap();
113  // Set reclaim-timer-wait-time
114  result->set("reclaim-timer-wait-time",
115  Element::create(static_cast<long long>
116  (reclaim_timer_wait_time_)));
117  // Set flush-reclaimed-timer-wait-time
118  result->set("flush-reclaimed-timer-wait-time",
119  Element::create(static_cast<long long>
120  (flush_reclaimed_timer_wait_time_)));
121  // Set hold-reclaimed-time
122  result->set("hold-reclaimed-time",
123  Element::create(static_cast<long long>
124  (hold_reclaimed_time_)));
125  // Set max-reclaim-leases
126  result->set("max-reclaim-leases",
127  Element::create(static_cast<long long>
128  (max_reclaim_leases_)));
129  // Set max-reclaim-time
130  result->set("max-reclaim-time",
131  Element::create(static_cast<long long>
132  (max_reclaim_time_)));
133  // Set unwarned-reclaim-cycles
134  result->set("unwarned-reclaim-cycles",
135  Element::create(static_cast<long long>
136  (unwarned_reclaim_cycles_)));
137  return (result);
138 }
139 
140 }
141 }
void setMaxReclaimLeases(const int64_t max_reclaim_leases)
Sets max-reclaim-leases.
static const uint16_t LIMIT_FLUSH_RECLAIMED_TIMER_WAIT_TIME
Maximum value for flush-reclaimed-timer-wait-time.
Manages a pool of asynchronous interval timers.
Definition: timer_mgr.h:62
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
static const uint32_t LIMIT_HOLD_RECLAIMED_TIME
Maximum value for hold-reclaimed-time.
static const uint16_t LIMIT_MAX_RECLAIM_TIME
Default value for max-reclaim-time.
void setUnwarnedReclaimCycles(const int64_t unwarned_reclaim_cycles)
Sets unwarned-reclaim-cycles.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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.
Defines the logger used by the top-level component of kea-lfc.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
static const uint16_t LIMIT_UNWARNED_RECLAIM_CYCLES
Maximum value for unwarned-reclaim-cycles.
void setFlushReclaimedTimerWaitTime(const int64_t flush_reclaimed_wait_time)
Sets flush-reclaimed-timer-wait-time.
void setReclaimTimerWaitTime(const int64_t reclaim_timer_wait_time)
Sets reclaim-timer-wait-time.
static const uint16_t LIMIT_RECLAIM_TIMER_WAIT_TIME
Maximum value for reclaim-timer-wait-time.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
void setMaxReclaimTime(const int64_t max_reclaim_time)
Sets max-reclaim-time.