Kea  2.3.5-git
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 
19 namespace isc {
20 namespace dhcp {
21 
31 public:
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 
134 private:
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
size_t size(const Lease::Type &ltype=Lease::TYPE_V4) const
Get the number of entries for a given lease type.
void removeLease(LeasePtr lease)
Decrement the counts for all of a lease&#39;s classes by one.
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.
void updateLease(LeasePtr new_lease, LeasePtr old_lease)
Adjust class lease counts given a new and old version of a lease.
Defines elements for storing the names of client classes.
static data::ConstElementPtr getLeaseClientClasses(LeasePtr lease)
Fetches the list of classes from the lease&#39;s user-context.
std::unordered_map< ClientClass, size_t > ClassCountMap
Defines ClassCountMap as an unordered map of counts.
the lease contains IPv6 prefix (for prefix delegation)
Definition: lease.h:49
~ClassLeaseCounter()=default
Destructor.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition: lease.h:22
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.
IPv4 lease.
Definition: lease.h:50
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
void addLease(LeasePtr lease)
Increment the counts for all of a lease&#39;s classes by one.
Defines the logger used by the top-level component of kea-lfc.
void clear()
Remove all entries.
Container that maintains counts of leases per class and lease type.
Type
Type of lease or pool.
Definition: lease.h:46
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.
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.
ClassLeaseCounter()=default
Constructor.
std::string ClientClass
Defines a single class name.
Definition: classify.h:42