Kea: cfg_expiration.cc Source File

| Kea 2.2.0

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
9#include <dhcpsrv/cfg_expiration.h>
10#include <exceptions/exceptions.h>
11#include <limits>
12
13using namespace isc::data;
14
15namespace isc {
16namespace dhcp {
17
18// Default values
19const uint16_t CfgExpiration::DEFAULT_RECLAIM_TIMER_WAIT_TIME = 10;
20const uint16_t CfgExpiration::DEFAULT_FLUSH_RECLAIMED_TIMER_WAIT_TIME = 25;
21const uint32_t CfgExpiration::DEFAULT_HOLD_RECLAIMED_TIME = 3600;
22const uint32_t CfgExpiration::DEFAULT_MAX_RECLAIM_LEASES = 100;
23const uint16_t CfgExpiration::DEFAULT_MAX_RECLAIM_TIME = 250;
24const uint16_t CfgExpiration::DEFAULT_UNWARNED_RECLAIM_CYCLES = 5;
25
26// Maximum values.
27const uint16_t CfgExpiration::LIMIT_RECLAIM_TIMER_WAIT_TIME =
28 std::numeric_limits<uint16_t>::max();
29const uint16_t CfgExpiration::LIMIT_FLUSH_RECLAIMED_TIMER_WAIT_TIME =
30 std::numeric_limits<uint16_t>::max();
31const uint32_t CfgExpiration::LIMIT_HOLD_RECLAIMED_TIME =
32 std::numeric_limits<uint32_t>::max();
33const uint32_t CfgExpiration::LIMIT_MAX_RECLAIM_LEASES =
34 std::numeric_limits<uint32_t>::max();
35const uint16_t CfgExpiration::LIMIT_MAX_RECLAIM_TIME = 10000;
36const uint16_t CfgExpiration::LIMIT_UNWARNED_RECLAIM_CYCLES =
37 std::numeric_limits<uint16_t>::max();
38
39// Timers' names
40const std::string CfgExpiration::RECLAIM_EXPIRED_TIMER_NAME =
41 "reclaim-expired-leases";
42
43const std::string CfgExpiration::FLUSH_RECLAIMED_TIMER_NAME =
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
110 ElementPtr
111CfgExpiration::toElement() const {
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}
cfg_expiration.h
isc::OutOfRange
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Definition: exceptions/exceptions.h:115
isc::data::Element::create
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:241
isc::data::Element::createMap
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:291
isc::dhcp::CfgExpiration::setReclaimTimerWaitTime
void setReclaimTimerWaitTime(const int64_t reclaim_timer_wait_time)
Sets reclaim-timer-wait-time.
Definition: cfg_expiration.cc:58
isc::dhcp::CfgExpiration::LIMIT_FLUSH_RECLAIMED_TIMER_WAIT_TIME
static const uint16_t LIMIT_FLUSH_RECLAIMED_TIMER_WAIT_TIME
Maximum value for flush-reclaimed-timer-wait-time.
Definition: cfg_expiration.h:94
isc::dhcp::CfgExpiration::FLUSH_RECLAIMED_TIMER_NAME
static const std::string FLUSH_RECLAIMED_TIMER_NAME
Name of the timer for flushing reclaimed leases.
Definition: cfg_expiration.h:117
isc::dhcp::CfgExpiration::setMaxReclaimLeases
void setMaxReclaimLeases(const int64_t max_reclaim_leases)
Sets max-reclaim-leases.
Definition: cfg_expiration.cc:78
isc::dhcp::CfgExpiration::setUnwarnedReclaimCycles
void setUnwarnedReclaimCycles(const int64_t unwarned_reclaim_cycles)
Sets unwarned-reclaim-cycles.
Definition: cfg_expiration.cc:90
isc::dhcp::CfgExpiration::LIMIT_MAX_RECLAIM_LEASES
static const uint32_t LIMIT_MAX_RECLAIM_LEASES
Maximum value for max-reclaim-leases.
Definition: cfg_expiration.h:100
isc::dhcp::CfgExpiration::setHoldReclaimedTime
void setHoldReclaimedTime(const int64_t hold_reclaimed_time)
Sets hold-reclaimed-time.
Definition: cfg_expiration.cc:72
isc::dhcp::CfgExpiration::DEFAULT_RECLAIM_TIMER_WAIT_TIME
static const uint16_t DEFAULT_RECLAIM_TIMER_WAIT_TIME
Definition: cfg_expiration.h:68
isc::dhcp::CfgExpiration::LIMIT_UNWARNED_RECLAIM_CYCLES
static const uint16_t LIMIT_UNWARNED_RECLAIM_CYCLES
Maximum value for unwarned-reclaim-cycles.
Definition: cfg_expiration.h:106
isc::dhcp::CfgExpiration::LIMIT_RECLAIM_TIMER_WAIT_TIME
static const uint16_t LIMIT_RECLAIM_TIMER_WAIT_TIME
Definition: cfg_expiration.h:91
isc::dhcp::CfgExpiration::LIMIT_HOLD_RECLAIMED_TIME
static const uint32_t LIMIT_HOLD_RECLAIMED_TIME
Maximum value for hold-reclaimed-time.
Definition: cfg_expiration.h:97
isc::dhcp::CfgExpiration::CfgExpiration
CfgExpiration(const bool test_mode=false)
Constructor.
Definition: cfg_expiration.cc:46
isc::dhcp::CfgExpiration::DEFAULT_UNWARNED_RECLAIM_CYCLES
static const uint16_t DEFAULT_UNWARNED_RECLAIM_CYCLES
Default value for unwarned-reclaim-cycles.
Definition: cfg_expiration.h:83
isc::dhcp::CfgExpiration::setMaxReclaimTime
void setMaxReclaimTime(const int64_t max_reclaim_time)
Sets max-reclaim-time.
Definition: cfg_expiration.cc:84
isc::dhcp::CfgExpiration::DEFAULT_FLUSH_RECLAIMED_TIMER_WAIT_TIME
static const uint16_t DEFAULT_FLUSH_RECLAIMED_TIMER_WAIT_TIME
Default value for flush-reclaimed-timer-wait-time.
Definition: cfg_expiration.h:71
isc::dhcp::CfgExpiration::DEFAULT_MAX_RECLAIM_TIME
static const uint16_t DEFAULT_MAX_RECLAIM_TIME
Default value for max-reclaim-time.
Definition: cfg_expiration.h:80
isc::dhcp::CfgExpiration::toElement
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: cfg_expiration.cc:111
isc::dhcp::CfgExpiration::LIMIT_MAX_RECLAIM_TIME
static const uint16_t LIMIT_MAX_RECLAIM_TIME
Default value for max-reclaim-time.
Definition: cfg_expiration.h:103
isc::dhcp::CfgExpiration::RECLAIM_EXPIRED_TIMER_NAME
static const std::string RECLAIM_EXPIRED_TIMER_NAME
Name of the timer for reclaiming expired leases.
Definition: cfg_expiration.h:114
isc::dhcp::CfgExpiration::setFlushReclaimedTimerWaitTime
void setFlushReclaimedTimerWaitTime(const int64_t flush_reclaimed_wait_time)
Sets flush-reclaimed-timer-wait-time.
Definition: cfg_expiration.cc:65
isc::dhcp::CfgExpiration::DEFAULT_HOLD_RECLAIMED_TIME
static const uint32_t DEFAULT_HOLD_RECLAIMED_TIME
Default value for hold-reclaimed-time.
Definition: cfg_expiration.h:74
isc::dhcp::CfgExpiration::DEFAULT_MAX_RECLAIM_LEASES
static const uint32_t DEFAULT_MAX_RECLAIM_LEASES
Default value for max-reclaim-leases.
Definition: cfg_expiration.h:77
isc::dhcp::TimerMgr
Manages a pool of asynchronous interval timers.
Definition: timer_mgr.h:62
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:210
isc::data
Definition: base_stamped_element.cc:12
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143