Kea 2.5.8
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
11#include <limits>
12
13using namespace isc::data;
14
15namespace isc {
16namespace dhcp {
17
18// Default values
25
26// Maximum values.
28 std::numeric_limits<uint16_t>::max();
30 std::numeric_limits<uint16_t>::max();
32 std::numeric_limits<uint32_t>::max();
34 std::numeric_limits<uint32_t>::max();
35const uint16_t CfgExpiration::LIMIT_MAX_RECLAIM_TIME = 10000;
37 std::numeric_limits<uint16_t>::max();
38
39// Timers' names
41 "reclaim-expired-leases";
42
44 "flush-reclaimed-leases";
45
46CfgExpiration::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
57void
58CfgExpiration::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
64void
65CfgExpiration::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
71void
72CfgExpiration::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
77void
78CfgExpiration::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
83void
84CfgExpiration::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
89void
90CfgExpiration::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
96void
97CfgExpiration::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
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}
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:249
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:304
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 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
static const uint16_t LIMIT_UNWARNED_RECLAIM_CYCLES
Maximum value for unwarned-reclaim-cycles.
static const uint16_t LIMIT_RECLAIM_TIMER_WAIT_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.
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.
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.
static const uint32_t DEFAULT_MAX_RECLAIM_LEASES
Default value for max-reclaim-leases.
Manages a pool of asynchronous interval timers.
Definition: timer_mgr.h:62
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:28
Defines the logger used by the top-level component of kea-lfc.