Kea: isc::dhcp::LeaseMgrFactory Class Reference

| Kea 3.2.0-git

isc::dhcp::LeaseMgrFactory Class Reference

Lease Manager Factory. More...

`#include <lease_mgr_factory.h>`

## Public Types
typedef std::function< std::string()> | DBVersion
| Type of lease mgr version.
typedef std::function< TrackingLeaseMgrPtr(const db::DatabaseConnection::ParameterMap &)> | Factory
| Type of lease mgr factory.

## Public Member Functions
| ~LeaseMgrFactory ()

## Static Public Member Functions
static void | create (const std::string &dbaccess)
| Create an instance of a lease manager.
static bool | deregisterFactory (const std::string &db_type, bool no_log=false)
| Deregister a lease mgr factory.
static void | destroy ()
| Destroy lease manager.
static std::list< std::string > | getDBVersions ()
| Return extended version info for registered backends.
static bool | haveInstance ()
| Indicates if the lease manager has been instantiated.
static void | initAllocators (bool use_staging=false)
| Initializes the lease allocators for all subnets.
static TrackingLeaseMgr & | instance ()
| Return current lease manager.
static void | logRegistered ()
| Logs out all registered backends.
static void | recreate (const std::string &dbaccess, bool preserve_callbacks=true)
| Recreate an instance of a lease manager with optionally preserving registered callbacks.
static bool | registeredFactory (const std::string &db_type)
| Check if a lease mgr factory was registered.
static bool | registerFactory (const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
| Register a lease mgr factory.

## Static Public Attributes
static bool | init_allocators_ = false
| Flag which indicates if allocators must be initialized.

## Detailed Description

Lease Manager Factory.

This class comprises nothing but static methods used to create a lease manager. It analyzes the database information passed to the creation function and instantiates an appropriate lease manager based on the type requested.

Strictly speaking these functions could be stand-alone functions. However, it is convenient to encapsulate them in a class for naming purposes.

Definition at line 40 of file lease_mgr_factory.h.

## Member Typedef Documentation

## ◆ DBVersion

typedef std::function<std::string ()> isc::dhcp::LeaseMgrFactory::DBVersion

Type of lease mgr version.

Definition at line 113 of file lease_mgr_factory.h.

## ◆ Factory

typedef std::function<TrackingLeaseMgrPtr (const db::DatabaseConnection::ParameterMap&)> isc::dhcp::LeaseMgrFactory::Factory

Type of lease mgr factory.

A factory takes a parameter map and returns a pointer to a lease mgr. In case of failure it must throw and not return null.

Definition at line 110 of file lease_mgr_factory.h.

## Constructor & Destructor Documentation

## ◆ ~LeaseMgrFactory()

isc::dhcp::LeaseMgrFactory::~LeaseMgrFactory | ( |  | ) |
| inline

Definition at line 42 of file lease_mgr_factory.h.

References destroy().

Here is the call graph for this function:

## Member Function Documentation

## ◆ create()

void isc::dhcp::LeaseMgrFactory::create | ( | const std::string & | dbaccess | ) |
| static

Create an instance of a lease manager.

Each database backend has its own lease manager type. This static method sets the "current" lease manager to be a manager of the appropriate type. The actual lease manager is returned by the "instance" method.

Note
  When called, the current lease manager is always destroyed and a new one created - even if the parameters are the same.

dbaccess is a generic way of passing parameters. Parameters are passed in the "name=value" format, separated by spaces. The data MUST include a keyword/value pair of the form "type=dbtype" giving the database type, e.q. "mysql" or "sqlite3".

Parameters

  dbaccess | Database access parameters. These are in the form of "keyword=value" pairs, separated by spaces. They are backend-specific, although must include the "type" keyword which gives the backend in use.

Exceptions

  isc::InvalidParameter | dbaccess string does not contain the "type" keyword.
  isc::dhcp::InvalidType | The "type" keyword in dbaccess does not identify a supported backend.

Definition at line 61 of file lease_mgr_factory.cc.

References isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_NOTYPE_DB, isc::dhcp::DHCPSRV_UNKNOWN_DB, isc_throw, LOG_ERROR, isc::db::DatabaseConnection::parse(), and isc::db::DatabaseConnection::redactedAccessString().

Referenced by recreate().

Here is the call graph for this function:

## ◆ deregisterFactory()

bool isc::dhcp::LeaseMgrFactory::deregisterFactory | ( | const std::string & | db_type,
|  | bool | no_log = false )
| static

Deregister a lease mgr factory.

Disassociate the factory to a database type in the map. The no_log is to avoid logging during global object deinitialization.

Parameters

  db_type | database type
  no_log | do not log (default false)

Returns
  true if the factory was successfully removed from the map, false if it was not found.

Definition at line 187 of file lease_mgr_factory.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::DHCPSRV_LEASE_MGR_BACKEND_DEREGISTER, isc::dhcp::dhcpsrv_logger, and LOG_DEBUG.

Referenced by isc::dhcp::MemfileLeaseMgrInit::~MemfileLeaseMgrInit().

## ◆ destroy()

void isc::dhcp::LeaseMgrFactory::destroy | ( |  | ) |
| static

Destroy lease manager.

Destroys the current lease manager object. This should have the effect of closing the database connection. The method is a no-op if no lease manager is available.

Definition at line 107 of file lease_mgr_factory.cc.

References isc::dhcp::DHCPSRV_CLOSE_DB, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, and LOG_DEBUG.

Referenced by isc::dhcp::ControlledDhcpv4Srv::~ControlledDhcpv4Srv(), isc::dhcp::ControlledDhcpv6Srv::~ControlledDhcpv6Srv(), isc::dhcp::Dhcpv4Srv::~Dhcpv4Srv(), isc::dhcp::Dhcpv6Srv::~Dhcpv6Srv(), ~LeaseMgrFactory(), isc::dhcp::configureDhcp4Server(), isc::dhcp::configureDhcp6Server(), and recreate().

## ◆ getDBVersions()

std::list< std::string > isc::dhcp::LeaseMgrFactory::getDBVersions | ( |  | ) |
| static

Return extended version info for registered backends.

Definition at line 224 of file lease_mgr_factory.cc.

References version().

Referenced by isc::dhcp::Dhcpv4Srv::getVersion(), and isc::dhcp::Dhcpv6Srv::getVersion().

Here is the call graph for this function:

## ◆ haveInstance()

bool isc::dhcp::LeaseMgrFactory::haveInstance | ( |  | ) |
| static

Indicates if the lease manager has been instantiated.

Returns
  True if the lease manager instance exists, false otherwise.

Definition at line 143 of file lease_mgr_factory.cc.

Referenced by isc::dhcp::Allocator::~Allocator(), isc::dhcp::ControlledDhcpv4Srv::commandConfigSetHandler(), isc::dhcp::ControlledDhcpv6Srv::commandConfigSetHandler(), isc::dhcp::ControlledDhcpv4Srv::commandLfcStartHandler(), isc::dhcp::ControlledDhcpv6Srv::commandLfcStartHandler(), isc::dhcp::ControlledDhcpv4Srv::commandStatusGetHandler(), isc::dhcp::ControlledDhcpv6Srv::commandStatusGetHandler(), isc::limits::LimitManager::dhcp_srv_configured(), recreate(), isc::limits::unload(), and isc::dhcp::SrvConfig::updateStatistics().

## ◆ initAllocators()

void isc::dhcp::LeaseMgrFactory::initAllocators | ( | bool | use_staging = false | ) |
| static

Initializes the lease allocators for all subnets.

Parameters

  use_staging | Use the staging configuration when true, otherwise use the current configuration. Defaults to false.

Definition at line 46 of file lease_mgr_factory.cc.

References isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::CfgMgr::getStagingCfg(), init_allocators_, and isc::dhcp::CfgMgr::instance().

Referenced by recreate().

Here is the call graph for this function:

## ◆ instance()

TrackingLeaseMgr & isc::dhcp::LeaseMgrFactory::instance | ( |  | ) |
| static

Return current lease manager.

Returns an instance of the "current" lease manager. An exception will be thrown if none is available.

Exceptions

  isc::dhcp::NoLeaseManager | No lease manager is available: use create() to create one before calling this method.

Definition at line 148 of file lease_mgr_factory.cc.

References isc_throw.

Referenced by isc::dhcp::Allocator::~Allocator(), isc::lease_cmds::LeaseCmdsImpl::addOrUpdate4(), isc::lease_cmds::LeaseCmdsImpl::addOrUpdate6(), isc::dhcp::AllocEngine::allocateLeases6(), isc::dhcp::Dhcpv4Srv::assignLease(), isc::lease_query::BulkLeaseQuery4::bulkQueryByClientId(), isc::lease_query::BulkLeaseQuery4::bulkQueryByHWAddr(), isc::lease_query::BulkLeaseQuery6::bulkQueryByLinkAddress(), isc::lease_query::BulkLeaseQuery4::bulkQueryByRelayId(), isc::lease_query::BulkLeaseQuery6::bulkQueryByRelayId(), isc::lease_query::BulkLeaseQuery4::bulkQueryByRemoteId(), isc::lease_query::BulkLeaseQuery6::bulkQueryByRemoteId(), isc::dhcp::Dhcpv6Srv::checkPostAssignmentChanges(), isc::dhcp::ControlledDhcpv4Srv::commandConfigSetHandler(), isc::dhcp::ControlledDhcpv6Srv::commandConfigSetHandler(), isc::dhcp::ControlledDhcpv4Srv::commandLfcStartHandler(), isc::dhcp::ControlledDhcpv6Srv::commandLfcStartHandler(), isc::dhcp::ControlledDhcpv4Srv::commandStatusGetHandler(), isc::dhcp::ControlledDhcpv6Srv::commandStatusGetHandler(), isc::dhcp::Dhcpv6Srv::declineIA(), isc::dhcp::Dhcpv4Srv::declineLease(), isc::dhcp::Dhcpv6Srv::declineLease(), isc::dhcp::deleteAssignedLease(), isc::dhcp::AllocEngine::deleteExpiredReclaimedLeases4(), isc::dhcp::AllocEngine::deleteExpiredReclaimedLeases6(), isc::lease_cmds::LeaseCmdsImpl::getIPv6LeaseForDelete(), isc::lease_cmds::LeaseCmdsImpl::lease4DelHandler(), isc::lease_cmds::LeaseCmdsImpl::lease4Offer(), isc::lease_cmds::LeaseCmdsImpl::lease4ResendDdnsHandler(), isc::lease_cmds::LeaseCmdsImpl::lease4WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6BulkApplyHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6DelHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6ResendDdnsHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseAddHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetAllHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetByClientIdHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetByDuidHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetByHostnameHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetByHwAddressHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetByStateHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseGetPageHandler(), isc::lease_cmds::LeaseCmdsImpl::leases4Committed(), isc::lease_cmds::LeaseCmdsImpl::leases6Committed(), isc::lease_cmds::LeaseCmdsImpl::leaseWriteHandler(), isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet4(), isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet6(), isc::dhcp::Dhcpv4Srv::postAllocateNameUpdate(), isc::dhcp::Dhcpv6Srv::processAddrRegInform(), isc::dhcp::Dhcpv4Srv::processDecline(), isc::dhcp::Dhcpv4Srv::processRelease(), isc::lease_query::LeaseQueryImpl4::queryByClientId(), isc::lease_query::LeaseQueryImpl6::queryByClientId(), isc::lease_query::LeaseQueryImpl4::queryByHWAddr(), isc::lease_query::LeaseQueryImpl4::queryByIpAddress(), isc::lease_query::LeaseQueryImpl6::queryByIpAddress(), isc::lease_query::LeaseQueryImpl6::queryByLinkNext(), isc::lease_query::LeaseQueryImpl6::queryByLinkStart(), isc::lease_query::LeaseQueryImpl6::queryByRelayIdNext(), isc::lease_query::LeaseQueryImpl6::queryByRelayIdStart(), isc::lease_query::LeaseQueryImpl6::queryByRemoteIdNext(), isc::lease_query::LeaseQueryImpl6::queryByRemoteIdStart(), isc::dhcp::AllocEngine::reclaimExpiredLeases4Internal(), isc::dhcp::AllocEngine::reclaimExpiredLeases6Internal(), isc::dhcp::Dhcpv4Srv::recoverStashedAgentOption(), recreate(), isc::dhcp::Dhcpv6Srv::releaseIA_NA(), isc::dhcp::Dhcpv6Srv::releaseIA_PD(), isc::dhcp::AllocEngine::renewLeases6(), isc::dhcp::Dhcpv4Srv::serverDecline(), isc::lease_cmds::SflqCmdsImpl::sflqPool4RebuildHandler(), isc::lease_cmds::SflqCmdsImpl::sflqPool6RebuildHandler(), isc::limits::unload(), isc::dhcp::CfgSubnets4::updateStatistics(), isc::dhcp::CfgSubnets6::updateStatistics(), isc::lease_query::LeaseQueryImpl4::upgradeHandler(), and isc::lease_query::LeaseQueryImpl6::upgradeHandler().

## ◆ logRegistered()

void isc::dhcp::LeaseMgrFactory::logRegistered | ( |  | ) |
| static

Logs out all registered backends.

We need a dedicated method for this, because we sometimes can't log the backend type when doing early initialization for backends initialized statically.

Definition at line 209 of file lease_mgr_factory.cc.

References isc::dhcp::DHCPSRV_LEASE_MGR_BACKENDS_REGISTERED, isc::dhcp::dhcpsrv_logger, and LOG_INFO.

Referenced by isc::dhcp::configureDhcp4Server(), and isc::dhcp::configureDhcp6Server().

## ◆ recreate()

void isc::dhcp::LeaseMgrFactory::recreate | ( | const std::string & | dbaccess,
|  | bool | preserve_callbacks = true )
| static

Recreate an instance of a lease manager with optionally preserving registered callbacks.

Parameters

  dbaccess | Database access parameters. These are in the form of "keyword=value" pairs, separated by spaces. They are backend-specific, although must include the "type" keyword which gives the backend in use.
  preserve_callbacks | a boolean flag indicating if all registered `TrackingLeaseMgr` callbacks should be copied to the new instance.

Definition at line 118 of file lease_mgr_factory.cc.

References isc::dhcp::TrackingLeaseMgr::callbacks_, create(), destroy(), haveInstance(), initAllocators(), and instance().

Referenced by isc::dhcp::CfgDbAccess::createManagers().

Here is the call graph for this function:

## ◆ registeredFactory()

bool isc::dhcp::LeaseMgrFactory::registeredFactory | ( | const std::string & | db_type | ) |
| static

Check if a lease mgr factory was registered.

Parameters

  db_type | database type

Returns
  true if a factory was registered for db_type, false if not.

Definition at line 203 of file lease_mgr_factory.cc.

## ◆ registerFactory()

bool isc::dhcp::LeaseMgrFactory::registerFactory | ( | const std::string & | db_type,
|  | const Factory & | factory,
|  | bool | no_log = false,
|  | DBVersion | db_version = DBVersion() )
| static

Register a lease mgr factory.

Associate the factory to a database type in the map. The no_log is to avoid logging before the logger is initialized as when called at global object initialization.

Parameters

  db_type | database type
  factory | lease mgr factory
  no_log | do not log (default false)
  db_version | lease mgr version

Returns
  true if the factory was successfully added to the map, false if it already exists.

Definition at line 157 of file lease_mgr_factory.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::DHCPSRV_LEASE_MGR_BACKEND_REGISTER, isc::dhcp::dhcpsrv_logger, and LOG_DEBUG.

Referenced by isc::dhcp::MemfileLeaseMgrInit::MemfileLeaseMgrInit().

## Member Data Documentation

## ◆ init_allocators_

bool isc::dhcp::LeaseMgrFactory::init_allocators_ = false
| static

Flag which indicates if allocators must be initialized.

Definition at line 166 of file lease_mgr_factory.h.

Referenced by initAllocators(), isc::dhcp::ControlledDhcpv4Srv::processConfig(), and isc::dhcp::ControlledDhcpv6Srv::processConfig().

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

- lease_mgr_factory.h
- lease_mgr_factory.cc