Kea 2.7.5
isc::dhcp::Allocator Class Referenceabstract

Base class for all address/prefix allocation algorithms. More...

#include <allocator.h>

+ Inheritance diagram for isc::dhcp::Allocator:

Public Types

enum  PrefixLenMatchType { PREFIX_LEN_EQUAL , PREFIX_LEN_LOWER , PREFIX_LEN_HIGHER }
 Type of preferred PD-pool prefix length selection criteria. More...
 

Public Member Functions

 Allocator (Lease::Type type, const WeakSubnetPtr &subnet)
 Constructor.
 
virtual ~Allocator ()
 Virtual destructor.
 
virtual std::string getType () const =0
 Returns allocator type string.
 
void initAfterConfigure ()
 Performs allocator initialization after server's reconfiguration.
 
virtual isc::asiolink::IOAddress pickAddress (const ClientClasses &client_classes, const IdentifierBaseTypePtr &duid, const asiolink::IOAddress &hint)
 Picks an address.
 
virtual isc::asiolink::IOAddress pickPrefix (const ClientClasses &client_classes, Pool6Ptr &pool, const IdentifierBaseTypePtr &duid, PrefixLenMatchType prefix_length_match, const asiolink::IOAddress &hint, uint8_t hint_prefix_length)
 Picks a delegated prefix.
 

Static Public Member Functions

static bool isValidPrefixPool (Allocator::PrefixLenMatchType prefix_length_match, PoolPtr pool, uint8_t hint_prefix_length)
 Check if the pool matches the selection criteria relative to the provided hint prefix length.
 

Protected Member Functions

virtual void initAfterConfigureInternal ()
 Allocator-specific initialization function.
 

Protected Attributes

bool inited_
 Indicates if the allocator has been initialized.
 
std::mutex mutex_
 The mutex to protect the allocated lease.
 
Lease::Type pool_type_
 Defines pool type allocation.
 
WeakSubnetPtr subnet_
 Weak pointer to the subnet owning the allocator.
 
SubnetID subnet_id_
 ID of a subnet to which the allocator belongs.
 

Detailed Description

Base class for all address/prefix allocation algorithms.

This is an abstract class that should not be used directly, but rather specialized implementations should be used instead.

This class holds a weak pointer to the subnet owning it because it must not exist without the subnet. Also, it can't hold a shared pointer to the subnet because it would cause a circular dependency between the two.

Definition at line 57 of file allocator.h.

Member Enumeration Documentation

◆ PrefixLenMatchType

Type of preferred PD-pool prefix length selection criteria.

Enumerator
PREFIX_LEN_EQUAL 
PREFIX_LEN_LOWER 
PREFIX_LEN_HIGHER 

Definition at line 61 of file allocator.h.

Constructor & Destructor Documentation

◆ Allocator()

isc::dhcp::Allocator::Allocator ( Lease::Type type,
const WeakSubnetPtr & subnet )

Constructor.

Specifies which type of leases this allocator will assign.

Parameters
typespecifies pool type (addresses, temporary addresses or prefixes).
subnetweak pointer to the subnet owning the allocator.

Definition at line 17 of file allocator.cc.

References subnet_, and subnet_id_.

◆ ~Allocator()

isc::dhcp::Allocator::~Allocator ( )
virtual

Virtual destructor.

Removes all LeaseMgr callbacks it installed.

Definition at line 27 of file allocator.cc.

References isc::dhcp::LeaseMgrFactory::haveInstance(), isc::dhcp::LeaseMgrFactory::instance(), pool_type_, and subnet_id_.

+ Here is the call graph for this function:

Member Function Documentation

◆ getType()

virtual std::string isc::dhcp::Allocator::getType ( ) const
pure virtual

Returns allocator type string.

Returns
allocator-specific type string.

Implemented in isc::dhcp::FreeLeaseQueueAllocator, isc::dhcp::IterativeAllocator, and isc::dhcp::RandomAllocator.

Referenced by initAfterConfigure().

◆ initAfterConfigure()

void isc::dhcp::Allocator::initAfterConfigure ( )

Performs allocator initialization after server's reconfiguration.

Some allocators install callbacks in the lease manager to keep track of the lease allocations. These callbacks may only be installed when the lease manager instance is available (i.e., when the server finishes the reconfiguration). Such callbacks can be installed in this function.

In this function, the allocators can also re-build their allocation states.

Definition at line 68 of file allocator.cc.

References isc::dhcp::DHCPSRV_CFGMGR_USE_ALLOCATOR, isc::dhcp::dhcpsrv_logger, getType(), initAfterConfigureInternal(), inited_, LOG_INFO, pool_type_, subnet_, and isc::dhcp::Lease::typeToText().

+ Here is the call graph for this function:

◆ initAfterConfigureInternal()

virtual void isc::dhcp::Allocator::initAfterConfigureInternal ( )
inlineprotectedvirtual

Allocator-specific initialization function.

It is called by the initAfterConfigure and can be overridden in the derived allocators.

Definition at line 172 of file allocator.h.

Referenced by initAfterConfigure().

◆ isValidPrefixPool()

bool isc::dhcp::Allocator::isValidPrefixPool ( Allocator::PrefixLenMatchType prefix_length_match,
PoolPtr pool,
uint8_t hint_prefix_length )
static

Check if the pool matches the selection criteria relative to the provided hint prefix length.

Parameters
prefix_length_matchtype which indicates the selection criteria for the pools relative to the provided hint prefix length.
poolthe pool checked for restricted delegated prefix length value.
hint_prefix_lengthThe hint prefix length that the client provided. The 0 value means that there is no hint and that any pool will suffice.

Definition at line 38 of file allocator.cc.

References PREFIX_LEN_EQUAL, PREFIX_LEN_HIGHER, and PREFIX_LEN_LOWER.

Referenced by isc::dhcp::Subnet::sumPoolCapacity().

◆ pickAddress()

virtual isc::asiolink::IOAddress isc::dhcp::Allocator::pickAddress ( const ClientClasses & client_classes,
const IdentifierBaseTypePtr & duid,
const asiolink::IOAddress & hint )
inlinevirtual

Picks an address.

This method returns one address from the available pools in the specified subnet. It should not check if the address is used or reserved - AllocEngine will check that and will call pickAddress again if necessary. The number of times this method is called will increase as the number of available leases will decrease.

Pools which are not allowed for client classes are skipped.

Parameters
client_classeslist of classes client belongs to.
duidClient's DUID.
hintClient's hint.
Returns
the next address.

Definition at line 102 of file allocator.h.

References mutex_.

◆ pickPrefix()

virtual isc::asiolink::IOAddress isc::dhcp::Allocator::pickPrefix ( const ClientClasses & client_classes,
Pool6Ptr & pool,
const IdentifierBaseTypePtr & duid,
PrefixLenMatchType prefix_length_match,
const asiolink::IOAddress & hint,
uint8_t hint_prefix_length )
inlinevirtual

Picks a delegated prefix.

This method returns one prefix from the available pools in the specified subnet. It should not check if the prefix is used or reserved - AllocEngine will check that and will call pickPrefix again if necessary. The number of times this method is called will increase as the number of available leases will decrease.

Pools which are not allowed for client classes are skipped.

Parameters
client_classeslist of classes client belongs to.
poolthe selected pool satisfying all required conditions.
duidClient's DUID.
prefix_length_matchtype which indicates the selection criteria for the pools relative to the provided hint prefix length.
hintClient's hint.
hint_prefix_lengththe hint prefix length that the client provided. The 0 value means that there is no hint and that any pool will suffice.
Returns
the next prefix.

Definition at line 131 of file allocator.h.

References mutex_.

Member Data Documentation

◆ inited_

bool isc::dhcp::Allocator::inited_
protected

Indicates if the allocator has been initialized.

It is set to true when initAfterConfigure has been called. It prevents initializing the allocator several times.

Definition at line 223 of file allocator.h.

Referenced by initAfterConfigure().

◆ mutex_

std::mutex isc::dhcp::Allocator::mutex_
protected

The mutex to protect the allocated lease.

Definition at line 235 of file allocator.h.

Referenced by pickAddress(), and pickPrefix().

◆ pool_type_

Lease::Type isc::dhcp::Allocator::pool_type_
protected

Defines pool type allocation.

Definition at line 226 of file allocator.h.

Referenced by ~Allocator(), and initAfterConfigure().

◆ subnet_

WeakSubnetPtr isc::dhcp::Allocator::subnet_
protected

Weak pointer to the subnet owning the allocator.

Definition at line 232 of file allocator.h.

Referenced by Allocator(), and initAfterConfigure().

◆ subnet_id_

SubnetID isc::dhcp::Allocator::subnet_id_
protected

ID of a subnet to which the allocator belongs.

Definition at line 229 of file allocator.h.

Referenced by Allocator(), and ~Allocator().


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