Kea 2.5.8
isc::dhcp::ClassLeaseCounter Class Reference

Container that maintains counts of leases per class and lease type. More...

#include <memfile_lease_limits.h>

Public Types

typedef std::unordered_map< ClientClass, size_t > ClassCountMap
 Defines ClassCountMap as an unordered map of counts.
 

Public Member Functions

 ClassLeaseCounter ()=default
 Constructor.
 
 ~ClassLeaseCounter ()=default
 Destructor.
 
void addLease (LeasePtr lease)
 Increment the counts for all of a lease's classes by one.
 
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.
 
void clear ()
 Remove all entries.
 
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 removeLease (LeasePtr lease)
 Decrement the counts for all of a lease'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.
 
size_t size (const Lease::Type &ltype=Lease::TYPE_V4) const
 Get the number of entries for a given lease type.
 
void updateLease (LeasePtr new_lease, LeasePtr old_lease)
 Adjust class lease counts given a new and old version of a lease.
 

Static Public Member Functions

static data::ConstElementPtr getLeaseClientClasses (LeasePtr lease)
 Fetches the list of classes from the lease's user-context.
 

Detailed Description

Container that maintains counts of leases per class and lease type.

For methods on this class which accept the lease type as a parameter the value is one of the following Lease::TYPE_V4, Lease::TYPE_NA, Lease::TYPE_PD. Kea does not support Lease::TYPE_TA leases and this value is treated as invalid. Note that for simplicity and performance an instance of container is assumed to be used either only for DHCPv4 processing or DHCPv6 processing but not both concurrently.

Definition at line 30 of file memfile_lease_limits.h.

Member Typedef Documentation

◆ ClassCountMap

typedef std::unordered_map<ClientClass, size_t> isc::dhcp::ClassLeaseCounter::ClassCountMap

Defines ClassCountMap as an unordered map of counts.

Definition at line 33 of file memfile_lease_limits.h.

Constructor & Destructor Documentation

◆ ClassLeaseCounter()

isc::dhcp::ClassLeaseCounter::ClassLeaseCounter ( )
default

Constructor.

◆ ~ClassLeaseCounter()

isc::dhcp::ClassLeaseCounter::~ClassLeaseCounter ( )
default

Destructor.

Member Function Documentation

◆ addLease()

void isc::dhcp::ClassLeaseCounter::addLease ( LeasePtr  lease)

Increment the counts for all of a lease's classes by one.

Function is intended to be whenever a new lease is being added.

Parameters
leaselease whose classes are to be incremented

Definition at line 93 of file memfile_lease_limits.cc.

References adjustClassCounts(), getLeaseClientClasses(), isc_throw, and isc::dhcp::Lease::STATE_DEFAULT.

Referenced by isc::dhcp::Memfile_LeaseMgr::recountClassLeases4(), and isc::dhcp::Memfile_LeaseMgr::recountClassLeases6().

+ Here is the call graph for this function:

◆ adjustClassCount()

void isc::dhcp::ClassLeaseCounter::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.

If no entry exists in container for the class and type, a new one is created.

Parameters
client_classclient class to adjust
offsetsigned amount to add to the current count
ltypelease type for which the count is desired, defaults to Lease::TYPE_V4

Definition at line 37 of file memfile_lease_limits.cc.

Referenced by adjustClassCounts().

◆ adjustClassCounts()

void isc::dhcp::ClassLeaseCounter::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.

Parameters
classeslist of classes to adjust
offsetsigned amount to add the current count
ltypelease type for which the count is desired, defaults to Lease::TYPE_V4

Definition at line 80 of file memfile_lease_limits.cc.

References adjustClassCount().

Referenced by addLease(), removeLease(), and updateLease().

+ Here is the call graph for this function:

◆ clear()

void isc::dhcp::ClassLeaseCounter::clear ( )
inline

◆ getClassCount()

size_t isc::dhcp::ClassLeaseCounter::getClassCount ( const ClientClass client_class,
const Lease::Type ltype = Lease::TYPE_V4 
) const

Fetches the lease count for the given class and lease type.

Parameters
client_classclass for which the count is desired
ltypelease type for which the count is desired, defaults to Lease::TYPE_V4
Returns
Number of leases for the class and lease type. If there is no entry found for the class and lease type, a value of zero is returned.

Definition at line 17 of file memfile_lease_limits.cc.

Referenced by isc::dhcp::Memfile_LeaseMgr::getClassLeaseCount().

◆ getLeaseClientClasses()

ConstElementPtr isc::dhcp::ClassLeaseCounter::getLeaseClientClasses ( LeasePtr  lease)
static

Fetches the list of classes from the lease's user-context.

Parameters
leaselease from which to fetch classes
Returns
ElementPtr to an Element::List containing the client classes or an empty List.

Definition at line 57 of file memfile_lease_limits.cc.

References isc_throw, isc::data::Element::list, and isc::data::prettyPrint().

Referenced by addLease(), removeLease(), and updateLease().

+ Here is the call graph for this function:

◆ removeLease()

void isc::dhcp::ClassLeaseCounter::removeLease ( LeasePtr  lease)

Decrement the counts for all of a lease's classes by one.

Function is intended to be whenever an existing lease is being deleted.

Parameters
leaselease whose classes are to be decremented

Definition at line 144 of file memfile_lease_limits.cc.

References adjustClassCounts(), getLeaseClientClasses(), isc_throw, and isc::dhcp::Lease::STATE_DEFAULT.

+ Here is the call graph for this function:

◆ setClassCount()

void isc::dhcp::ClassLeaseCounter::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.

Parameters
client_classclass for which the count is desired
countnew count value for the class and lease type.
ltypelease type for which the count is desired, defaults to Lease::TYPE_V4

Definition at line 30 of file memfile_lease_limits.cc.

◆ size()

size_t isc::dhcp::ClassLeaseCounter::size ( const Lease::Type ltype = Lease::TYPE_V4) const
inline

Get the number of entries for a given lease type.

Parameters
ltypetype of lease for which the number of entries is desired, defaults to Lease::TYPE_V4
Returns
Number of entries for the lease type

Definition at line 123 of file memfile_lease_limits.h.

References size().

Referenced by size().

+ Here is the call graph for this function:

◆ updateLease()

void isc::dhcp::ClassLeaseCounter::updateLease ( LeasePtr  new_lease,
LeasePtr  old_lease 
)

Adjust class lease counts given a new and old version of a lease.

Function is intended to be used whenever an existing lease is being updated. If, upon comparison of the two leases, either the lease states or the class lists are different then:

  1. Decrement the counts for the old class list if the old lease state is Lease::STATE_DEFAULT
  2. Increment the counts for the new class list if the new lease state is Lease::STATE_DEFAULT
Parameters
new_leasenew version of the lease
old_leaseold version of the lease

Definition at line 110 of file memfile_lease_limits.cc.

References adjustClassCounts(), getLeaseClientClasses(), isc_throw, and isc::dhcp::Lease::STATE_DEFAULT.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: