Kea: isc::dhcp::Allocator Class Reference

| Kea 3.2.0-git

isc::dhcp::Allocator Class Referenceabstract

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

`#include <allocator.h>`

Inheritance diagram for isc::dhcp::Allocator:
[legend]

## 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 double | getOccupancyRate (const asiolink::IOAddress &addr, const ClientClasses &client_classes)
| Returns the occupancy rate (v4 addresses).
virtual double | getOccupancyRate (const asiolink::IOAddress &pref, const uint8_t plen, const ClientClasses &client_classes)
| Returns the occupancy rate (v6 prefixes).
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

enum isc::dhcp::Allocator::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

  type | specifies pool type (addresses, temporary addresses or prefixes).
  subnet | weak pointer to the subnet owning the allocator.

Definition at line 17 of file allocator.cc.

References inited_, pool_type_, subnet_, and subnet_id_.

Referenced by isc::dhcp::FreeLeaseQueueAllocator::FreeLeaseQueueAllocator(), isc::dhcp::IterativeAllocator::IterativeAllocator(), isc::dhcp::RandomAllocator::RandomAllocator(), and isc::dhcp::SharedFlqAllocator::SharedFlqAllocator().

## ◆ ~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_, subnet_id_, and isc::dhcp::TrackingLeaseMgr::unregisterCallbacks().

Here is the call graph for this function:

## Member Function Documentation

## ◆ getOccupancyRate() [1/2]

double isc::dhcp::Allocator::getOccupancyRate | ( | const asiolink::IOAddress & | addr,
|  | const ClientClasses & | client_classes )
| virtual

Returns the occupancy rate (v4 addresses).

The method counts the total number and the number of not free addresses in the suitable pools of the subnet, and returns the occupancy rate. If the total number of addresses is over UMAX64 or the address is not from one of these pools, or by default the 0. rate is returned.

Parameters

  addr | the address.
  client_classes | list of classes client belongs to.

Reimplemented in isc::dhcp::FreeLeaseQueueAllocator.

Definition at line 82 of file allocator.cc.

## ◆ getOccupancyRate() [2/2]

double isc::dhcp::Allocator::getOccupancyRate | ( | const asiolink::IOAddress & | pref,
|  | const uint8_t | plen,
|  | const ClientClasses & | client_classes )
| virtual

Returns the occupancy rate (v6 prefixes).

The method counts the total number and the number of not free prefixes in the suitable pools of the subnet, and returns the occupancy rate. If the total number of prefixes is over UMAX64 or the prefix is not from one of these pools, or by default the 0. rate is returned.

Parameters

  pref | the prefix.
  plen | the prefix length.
  client_classes | list of classes client belongs to.

Reimplemented in isc::dhcp::FreeLeaseQueueAllocator.

Definition at line 88 of file allocator.cc.

## ◆ 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, isc::dhcp::RandomAllocator, and isc::dhcp::SharedFlqAllocator.

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 202 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_match | type which indicates the selection criteria for the pools relative to the provided hint prefix length.
  pool | the pool checked for restricted delegated prefix length value.
  hint_prefix_length | The 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_classes | list of classes client belongs to.
  duid | Client's DUID.
  hint | Client'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_classes | list of classes client belongs to.
  pool | the selected pool satisfying all required conditions.
  duid | Client's DUID.
  prefix_length_match | type which indicates the selection criteria for the pools relative to the provided hint prefix length.
  hint | Client's hint.
  hint_prefix_length | the 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 253 of file allocator.h.

Referenced by Allocator(), and initAfterConfigure().

## ◆ mutex_

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

The mutex to protect the allocated lease.

Definition at line 265 of file allocator.h.

Referenced by isc::dhcp::FreeLeaseQueueAllocator::getOccupancyRate(), isc::dhcp::FreeLeaseQueueAllocator::getOccupancyRate(), pickAddress(), and pickPrefix().

## ◆ pool_type_

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

Defines pool type allocation.

Definition at line 256 of file allocator.h.

Referenced by Allocator(), ~Allocator(), isc::dhcp::SharedFlqAllocator::getSubnetState(), and initAfterConfigure().

## ◆ subnet_

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

Weak pointer to the subnet owning the allocator.

Definition at line 262 of file allocator.h.

Referenced by Allocator(), isc::dhcp::SharedFlqAllocator::getSubnetState(), and initAfterConfigure().

## ◆ subnet_id_

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

ID of a subnet to which the allocator belongs.

Definition at line 259 of file allocator.h.

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

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

- allocator.h
- allocator.cc