Kea 2.7.5
memfile_lease_limits.h
Go to the documentation of this file.
1// Copyright (C) 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 MEMFILE_LEASE_LIMITS_H
8#define MEMFILE_LEASE_LIMITS_H
9
10#include <asiolink/io_address.h>
11#include <cc/data.h>
12#include <dhcp/classify.h>
13#include <dhcpsrv/lease.h>
14#include <dhcpsrv/subnet_id.h>
15#include <stats/stats_mgr.h>
16
17#include <unordered_map>
18
19namespace isc {
20namespace dhcp {
21
31public:
33 typedef std::unordered_map<ClientClass, size_t> ClassCountMap;
34
36 ClassLeaseCounter() = default;
37
39 ~ClassLeaseCounter() = default;
40
49 size_t getClassCount(const ClientClass& client_class,
50 const Lease::Type& ltype = Lease::TYPE_V4) const;
51
58 void setClassCount(const ClientClass& client_class, size_t count,
59 const Lease::Type& ltype = Lease::TYPE_V4);
60
69 void adjustClassCount(const ClientClass& client_class, int offset,
70 const Lease::Type& ltype = Lease::TYPE_V4);
71
79 void adjustClassCounts(data::ConstElementPtr classes, int offset,
80 const Lease::Type& ltype = Lease::TYPE_V4);
81
87 void addLease(LeasePtr lease);
88
102 void updateLease(LeasePtr new_lease, LeasePtr old_lease);
103
109 void removeLease(LeasePtr lease);
110
112 void clear() {
113 addresses_by_class_.clear();
114 pds_by_class_.clear();
115 }
116
123 size_t size(const Lease::Type& ltype = Lease::TYPE_V4) const {
124 return (getConstCountMap(ltype).size());
125 }
126
133
134private:
141 ClassCountMap& getCountMap(const Lease::Type& ltype = Lease::TYPE_V4) {
142 return (ltype == Lease::TYPE_PD ? pds_by_class_ : addresses_by_class_);
143 }
144
145 const ClassCountMap& getConstCountMap(const Lease::Type& ltype = Lease::TYPE_V4) const {
146 return (ltype == Lease::TYPE_PD ? pds_by_class_ : addresses_by_class_);
147 }
148
152 ClassCountMap addresses_by_class_;
153
156 ClassCountMap pds_by_class_;
157};
158
159} // namespace dhcp
160} // namespace isc
161
162#endif // MEMFILE_LEASE_LIMITS_H
Defines elements for storing the names of client classes.
Container that maintains counts of leases per class and lease type.
size_t size(const Lease::Type &ltype=Lease::TYPE_V4) const
Get the number of entries for a given lease type.
void adjustClassCounts(data::ConstElementPtr classes, int offset, const Lease::Type &ltype=Lease::TYPE_V4)
Adjust the count for a list of classes for a lease type by a signed offset.
void addLease(LeasePtr lease)
Increment the counts for all of a lease's classes by one.
void clear()
Remove all entries.
void removeLease(LeasePtr lease)
Decrement the counts for all of a lease's classes by one.
static data::ConstElementPtr getLeaseClientClasses(LeasePtr lease)
Fetches the list of classes from the lease's user-context.
void updateLease(LeasePtr new_lease, LeasePtr old_lease)
Adjust class lease counts given a new and old version of a lease.
void setClassCount(const ClientClass &client_class, size_t count, const Lease::Type &ltype=Lease::TYPE_V4)
Sets the lease count for the given class and lease type to a value.
~ClassLeaseCounter()=default
Destructor.
size_t getClassCount(const ClientClass &client_class, const Lease::Type &ltype=Lease::TYPE_V4) const
Fetches the lease count for the given class and lease type.
void adjustClassCount(const ClientClass &client_class, int offset, const Lease::Type &ltype=Lease::TYPE_V4)
Adjust the count for a given class and lease type by a signed offset.
std::unordered_map< ClientClass, size_t > ClassCountMap
Defines ClassCountMap as an unordered map of counts.
ClassLeaseCounter()=default
Constructor.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
std::string ClientClass
Defines a single class name.
Definition classify.h:42
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition lease.h:25
Defines the logger used by the top-level component of kea-lfc.
Type
Type of lease or pool.
Definition lease.h:46
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
@ TYPE_V4
IPv4 lease.
Definition lease.h:50