Kea: isc::host_cache::HostCache Class Reference

| Kea 3.0.0

isc::host_cache::HostCache Class Reference

Host Cache implementation. More...

`#include <host_cache.h>`

Inheritance diagram for isc::host_cache::HostCache:
[legend]

## Public Member Functions
| HostCache ()
| Constructor.
virtual | ~HostCache ()
| Destructor.
virtual void | add (const dhcp::HostPtr &host)
| Adds a new host to the collection.
int | cacheClearHandler (hooks::CalloutHandle &handle)
| cache-clear command handler.
int | cacheFlushHandler (hooks::CalloutHandle &handle)
| cache-flush command handler.
int | cacheGetByIdHandler (hooks::CalloutHandle &handle)
| cache-get-by-id command handler.
int | cacheGetHandler (hooks::CalloutHandle &handle)
| cache-get command handler.
int | cacheInsertHandler (hooks::CalloutHandle &handle)
| cache-insert command handler.
int | cacheLoadHandler (hooks::CalloutHandle &handle)
| cache-load command handler.
int | cacheRemoveHandler (hooks::CalloutHandle &handle)
| cache-remove command handler.
int | cacheSizeHandler (hooks::CalloutHandle &handle)
| Command handlers.
int | cacheWriteHandler (hooks::CalloutHandle &handle)
| cache-write command handler.
virtual size_t | capacity () const
| Return the maximum number of entries.
virtual void | configure (const data::ConstElementPtr &config)
| Parses configuration.
virtual bool | del (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
| Attempts to delete a host by (subnet-id, address)
virtual bool | del4 (const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
| Attempts to delete a host by (subnet-id4, identifier, identifier-type)
virtual bool | del6 (const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
| Attempts to delete a host by (subnet-id6, identifier, identifier-type)
virtual void | flush (size_t count)
| Flush entries.
virtual dhcp::ConstHostCollection | get (const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
| Return all hosts connected to any subnet for which reservations have been made using a specified identifier.
virtual dhcp::ConstHostPtr | get4 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address) const
| Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.
virtual dhcp::ConstHostPtr | get4 (const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
| Returns a host connected to the IPv4 subnet.
virtual dhcp::ConstHostPtr | get6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len) const
| Returns a host using the specified IPv6 prefix.
virtual dhcp::ConstHostPtr | get6 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address) const
| Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix.
virtual dhcp::ConstHostPtr | get6 (const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
| Returns a host connected to the IPv6 subnet.
virtual dhcp::ConstHostCollection | getAll (const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
| BaseHostDataSource methods.
virtual dhcp::ConstHostCollection | getAll4 (const asiolink::IOAddress &address) const
| Returns a collection of hosts using the specified IPv4 address.
virtual dhcp::ConstHostCollection | getAll4 (const dhcp::SubnetID &subnet_id) const
| Return all hosts in a DHCPv4 subnet.
virtual dhcp::ConstHostCollection | getAll4 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address) const
| Returns all hosts connected to the IPv4 subnet and having a reservation for a specified address.
virtual dhcp::ConstHostCollection | getAll6 (const asiolink::IOAddress &address) const
| Returns a collection of hosts using the specified IPv6 address.
virtual dhcp::ConstHostCollection | getAll6 (const dhcp::SubnetID &subnet_id) const
| Return all hosts in a DHCPv6 subnet.
virtual dhcp::ConstHostCollection | getAll6 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address) const
| Returns all hosts connected to the IPv6 subnet and having a reservation for a specified address or delegated prefix (lease).
virtual dhcp::ConstHostCollection | getAllbyHostname (const std::string &hostname) const
| Return all hosts with a hostname.
virtual dhcp::ConstHostCollection | getAllbyHostname4 (const std::string &hostname, const dhcp::SubnetID &subnet_id) const
| Return all hosts with a hostname in a DHCPv4 subnet.
virtual dhcp::ConstHostCollection | getAllbyHostname6 (const std::string &hostname, const dhcp::SubnetID &subnet_id) const
| Return all hosts with a hostname in a DHCPv6 subnet.
virtual size_t | getMaximum () const
| Get maximum number of cached hosts.
virtual dhcp::ConstHostCollection | getPage4 (const dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
| Return range of hosts in a DHCPv4 subnet.
virtual dhcp::ConstHostCollection | getPage4 (size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
| Return range of hosts.
virtual dhcp::ConstHostCollection | getPage6 (const dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
| Return range of hosts in a DHCPv6 subnet.
virtual dhcp::ConstHostCollection | getPage6 (size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
| Return range of hosts.
virtual std::string | getType () const
| Return backend type.
virtual size_t | insert (const dhcp::ConstHostPtr &host, bool overwrite)
| Insert a host into the cache.
virtual bool | remove (const dhcp::HostPtr &host)
| Remove a host from the cache.
virtual bool | setIPReservationsUnique (const bool unique)
| Controls whether IP reservations are unique or non-unique.
virtual void | setMaximum (size_t maximum)
| Set maximum number of cached hosts (0 means unbound).
virtual size_t | size () const
| Return the number of entries.
virtual data::ElementPtr | toElement () const
| Returns the whole content of the cache as Element tree.
void | update (isc::dhcp::HostPtr const &host)
| Implements isc::dhcp::BaseHostDataSource::update() for HostCache.
Public Member Functions inherited from isc::dhcp::CacheHostDataSource
virtual | ~CacheHostDataSource ()
| Default destructor implementation.
Public Member Functions inherited from isc::dhcp::BaseHostDataSource
virtual | ~BaseHostDataSource ()
| Default destructor implementation.
virtual void | commit ()
| Commit Transactions.
virtual isc::db::DatabaseConnection::ParameterMap | getParameters () const
| Return backend parameters.
virtual bool | isUnusable ()
| Flag which indicates if the host manager has at least one unusable connection.
virtual void | rollback ()
| Rollback Transactions.

## Protected Attributes
boost::shared_ptr< HostCacheImpl > | impl_
| Implementation.
boost::scoped_ptr< std::mutex > | mutex_
| mutex

## Additional Inherited Members
Public Types inherited from isc::dhcp::BaseHostDataSource
enum | IdType { ID_HWADDR = 0 , ID_DUID = 1 }
| Specifies the type of an identifier. More...

## Detailed Description

Host Cache implementation.

This Host cache provides Host backend that is able to cache hosts. Support for both positive (there is an entry for given host) and negative (there is no such entry) can be cached. Host collections (returned by getAll*() methods) are not handled.

Definition at line 34 of file host_cache.h.

## Constructor & Destructor Documentation

## ◆ HostCache()

isc::host_cache::HostCache::HostCache | ( |  | ) |

Constructor.

Exceptions

  Unexpected | if allocation fails.

Definition at line 33 of file host_cache.cc.

References impl_, and mutex_.

## ◆ ~HostCache()

isc::host_cache::HostCache::~HostCache | ( |  | ) |
| virtual

Destructor.

Definition at line 36 of file host_cache.cc.

References impl_.

## Member Function Documentation

## ◆ add()

void isc::host_cache::HostCache::add | ( | const dhcp::HostPtr & | host | ) |
| virtual

Adds a new host to the collection.

The implementations of this method should guard against duplicate reservations for the same host, where possible. For example, when the reservation for the same HW address and subnet id is added twice, the implementation should throw an exception. Note, that usually it is impossible to guard against adding duplicated host, where one instance is identified by HW address, another one by DUID.

Parameters

  host | Pointer to the new `Host` object being added.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 278 of file host_cache.cc.

References isc::host_cache::HOST_CACHE_ADD, isc::host_cache::HOST_CACHE_ADD_DUPLICATE, isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::host_cache_logger, impl_, isc_throw, LOG_DEBUG, and mutex_.

## ◆ cacheClearHandler()

int isc::host_cache::HostCache::cacheClearHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-clear command handler.

This command cleares the host cache.

No parameter taken.

Example command clearing the whole cache. { "command": "cache-clear" }

Parameters

  handle | Callout context - which is expected to contain the clear command JSON text in the "command" argument

Returns
  result of the operation

Definition at line 473 of file host_cache.cc.

References isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_CLEAR, isc::host_cache::HOST_CACHE_COMMAND_CLEAR_FAILED, isc::host_cache::host_cache_logger, impl_, LOG_ERROR, LOG_INFO, isc::config::CmdsImpl::setErrorResponse(), and isc::config::CmdsImpl::setSuccessResponse().

Here is the call graph for this function:

## ◆ cacheFlushHandler()

int isc::host_cache::HostCache::cacheFlushHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-flush command handler.

This command flushes the host cache.

Parameter is the number of entries to flush (must be > 0) or the string 'all'.

Example command flushing at most 5 entries { "command": "cache-flush", "arguments": 5 }

Example command flush the whole cache { "command": "cache-flush", "arguments": "all" }

Parameters

  handle | Callout context - which is expected to contain the flush command JSON text in the "command" argument

Returns
  result of the operation

Definition at line 493 of file host_cache.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_FLUSH, isc::host_cache::HOST_CACHE_COMMAND_FLUSH_FAILED, isc::host_cache::host_cache_logger, impl_, isc_throw, LOG_ERROR, LOG_INFO, isc::host_cache::HCConfigParser::MAXIMUM, isc::config::CmdsImpl::setErrorResponse(), and isc::config::CmdsImpl::setSuccessResponse().

Here is the call graph for this function:

## ◆ cacheGetByIdHandler()

int isc::host_cache::HostCache::cacheGetByIdHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-get-by-id command handler.

This command retrieves the host cache entries matching the given identifier.

Parameters are an identifier-type and an identifier.

Example command getting the specified entries. { "command": "cache-get-by-id", "arguments": { "hw-address": "01:02:03:04:05:06" } }

The result is a list of modified host reservations:

- client-classes for DHCPv4 and DHCPv6 are returned in client-classes4 and client-classes6 entries
- option-data for DHCPv4 and DHCPv6 are returned in option-data4 and option-data6 entries
- IPv4 subnet-id is added in the subnet-id4 entry
- IPv6 subnet-id is added in the subnet-id6 entry
- internal host-id is added in the host-id entry

Parameters

  handle | Callout context - which is expected to contain the get command JSON text in the "command" argument

Returns
  result of the operation

Definition at line 571 of file host_cache.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), Element::createList(), isc::util::str::decodeFormattedHexString(), isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_GET_BY_ID, isc::host_cache::HOST_CACHE_COMMAND_GET_BY_ID_FAILED, isc::host_cache::host_cache_logger, isc::dhcp::Host::IDENT_CIRCUIT_ID, isc::dhcp::Host::IDENT_CLIENT_ID, isc::dhcp::Host::IDENT_DUID, isc::dhcp::Host::IDENT_FLEX, isc::dhcp::Host::IDENT_HWADDR, impl_, isc_throw, LOG_ERROR, LOG_INFO, Element::map, mutex_, isc::util::str::quotedStringToBinary(), isc::config::CmdsImpl::setErrorResponse(), isc::config::CmdsImpl::setResponse(), and isc::host_cache::toElement().

Here is the call graph for this function:

## ◆ cacheGetHandler()

int isc::host_cache::HostCache::cacheGetHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-get command handler.

This command retrieves the host cache content.

No parameter taken.

Example command dumping the whole cache { "command": "cache-get", }

The result is a list of modified host reservations:

- client-classes for DHCPv4 and DHCPv6 are returned in client-classes4 and client-classes6 entries
- option-data for DHCPv4 and DHCPv6 are returned in option-data4 and option-data6 entries
- IPv4 subnet-id is added in the subnet-id4 entry
- IPv6 subnet-id is added in the subnet-id6 entry
- internal host-id is added in the host-id entry The list is ordered is decreasing last used time, i.e. the first host is the oldest and the last the newest. This operation is the main debug tool.

Parameters

  handle | Callout context - which is expected to contain the get command JSON text in the "command" argument

Returns
  result of the operation

Definition at line 542 of file host_cache.cc.

References isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_GET, isc::host_cache::HOST_CACHE_COMMAND_GET_FAILED, isc::host_cache::host_cache_logger, impl_, LOG_ERROR, LOG_INFO, isc::config::CmdsImpl::setErrorResponse(), and isc::config::CmdsImpl::setResponse().

Here is the call graph for this function:

## ◆ cacheInsertHandler()

int isc::host_cache::HostCache::cacheInsertHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-insert command handler.

This command inserts entries into the host cache.

Parameter is either one entry, or a list of entries in the format described for cache-get.

Example command { "command": "cache-insert", "arguments": { host1, host2 } }

Parameters

  handle | Callout context - which is expected to contain the insert command JSON text in the "command" argument and entry/entries in the "arguments" one.

Returns
  result of the operation

Definition at line 670 of file host_cache.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_INSERT, isc::host_cache::HOST_CACHE_COMMAND_INSERT_FAILED, isc::host_cache::host_cache_logger, impl_, isc_throw, LOG_ERROR, LOG_INFO, Element::map, mutex_, isc::host_cache::HCEntryListParser::parse(), isc::host_cache::HCEntryParser::parse(), isc::config::CmdsImpl::setErrorResponse(), and isc::config::CmdsImpl::setSuccessResponse().

Here is the call graph for this function:

## ◆ cacheLoadHandler()

int isc::host_cache::HostCache::cacheLoadHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-load command handler.

This command loads the cache content from disk.

Parameter is the path of the file where to read the host cache content, i.e. the cache-write opposite operation. When two entries conflict the most recent one is kept and the previous/older one is removed.

Parameters

  handle | Callout context - which is expected to contain the flush command JSON text in the "command" argument

Returns
  result of the operation

Definition at line 787 of file host_cache.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CmdsImpl::extractCommand(), Element::fromJSONFile(), isc::host_cache::HOST_CACHE_COMMAND_LOAD, isc::host_cache::HOST_CACHE_COMMAND_LOAD_FAILED, isc::host_cache::host_cache_logger, impl_, isc_throw, LOG_ERROR, LOG_INFO, isc::host_cache::HCEntryListParser::parse(), isc::config::CmdsImpl::setErrorResponse(), isc::config::CmdsImpl::setSuccessResponse(), and Element::string.

Here is the call graph for this function:

## ◆ cacheRemoveHandler()

int isc::host_cache::HostCache::cacheRemoveHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-remove command handler.

This command removes entries into the host cache.

Parameters are either a subnet-id and an ip-address, or an identifier-type, an identifier and subnet-id4 or subnet-id6.

Example command with an address { "command": "cache-remove", "arguments": { "subnet-id": 123, "ip-address": "192.0.0.2" } }

Example command with an identifier { "command": "cache-remove", "arguments": { "subnet-id6": 10, "hw-address": "01:02:03:04:05:06" } }

Parameters

  handle | Callout context - which is expected to contain the remove command JSON text in the "command" argument and entry/entries in the "arguments" one.

Returns
  result of the operation

Definition at line 849 of file host_cache.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CONTROL_RESULT_EMPTY, isc::util::str::decodeFormattedHexString(), isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_REMOVE, isc::host_cache::HOST_CACHE_COMMAND_REMOVE_FAILED, isc::host_cache::host_cache_logger, isc::dhcp::Host::IDENT_CIRCUIT_ID, isc::dhcp::Host::IDENT_CLIENT_ID, isc::dhcp::Host::IDENT_DUID, isc::dhcp::Host::IDENT_FLEX, isc::dhcp::Host::IDENT_HWADDR, impl_, isc_throw, isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::isV4Zero(), isc::asiolink::IOAddress::isV6(), isc::asiolink::IOAddress::isV6Zero(), LOG_ERROR, LOG_INFO, Element::map, mutex_, isc::util::str::quotedStringToBinary(), isc::config::CmdsImpl::setErrorResponse(), and isc::config::CmdsImpl::setSuccessResponse().

Here is the call graph for this function:

## ◆ cacheSizeHandler()

int isc::host_cache::HostCache::cacheSizeHandler | ( | hooks::CalloutHandle & | handle | ) |

Command handlers.

cache-size command handler.

This command returns the size of the host cache.

No parameter taken.

Example command returning the cache size. { "command": "cache-size" }

The result is the size of the cache.

Parameters

  handle | Callout context - which is expected to contain the size command JSON text in the "command" argument

Returns
  result of the operation

Definition at line 446 of file host_cache.cc.

References isc::config::CONTROL_RESULT_SUCCESS, Element::create(), isc::config::createAnswer(), Element::createMap(), isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_SIZE, isc::host_cache::HOST_CACHE_COMMAND_SIZE_FAILED, isc::host_cache::host_cache_logger, impl_, LOG_ERROR, LOG_INFO, mutex_, isc::config::CmdsImpl::setErrorResponse(), and isc::config::CmdsImpl::setResponse().

Here is the call graph for this function:

## ◆ cacheWriteHandler()

int isc::host_cache::HostCache::cacheWriteHandler | ( | hooks::CalloutHandle & | handle | ) |

cache-write command handler.

This command writes the host cache content to disk.

Parameter is the path of the file where to write the host cache content as a JSON list of entries in the format described for cache-get.

Example command { "command": "cache-write", "arguments": "cache.dump" }

Parameters

  handle | Callout context - which is expected to contain the write command JSON text in the "command" argument

Returns
  result of the operation

Definition at line 733 of file host_cache.cc.

References isc::config::CmdsImpl::cmd_args_, isc::config::CmdsImpl::extractCommand(), isc::host_cache::HOST_CACHE_COMMAND_WRITE, isc::host_cache::HOST_CACHE_COMMAND_WRITE_FAILED, isc::host_cache::host_cache_logger, impl_, isc::dhcp::CfgMgr::instance(), isc_throw, LOG_ERROR, LOG_INFO, isc::data::prettyPrint(), isc::config::CmdsImpl::setErrorResponse(), isc::config::CmdsImpl::setSuccessResponse(), Element::string, and isc::dhcp::CfgMgr::validatePath().

Here is the call graph for this function:

## ◆ capacity()

size_t isc::host_cache::HostCache::capacity | ( |  | ) | const
| virtual

Return the maximum number of entries.

Returns
  the maximum number of entries, 0 means unbound.

Implements isc::dhcp::CacheHostDataSource.

Definition at line 432 of file host_cache.cc.

References impl_, and mutex_.

## ◆ configure()

void isc::host_cache::HostCache::configure | ( | const data::ConstElementPtr & | config | ) |
| virtual

Parses configuration.

Parameters

  config | Configuration specified for the hooks library.

Exceptions

  ConfigError | when configuration fails.

Definition at line 40 of file host_cache.cc.

References isc::host_cache::HCConfigParser::parse().

Here is the call graph for this function:

## ◆ del()

bool isc::host_cache::HostCache::del | ( | const dhcp::SubnetID & | subnet_id,
|  | const asiolink::IOAddress & | addr )
| virtual

Attempts to delete a host by (subnet-id, address)

This method supports both v4 and v6.

Parameters

  subnet_id | subnet identifier.
  addr | specified address.

Returns
  always false.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 306 of file host_cache.cc.

References isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DEL_SUBNET_ID_ADDRESS4, isc::host_cache::HOST_CACHE_DEL_SUBNET_ID_ADDRESS6, isc::host_cache::host_cache_logger, impl_, isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::isV6(), LOG_DEBUG, mutex_, and isc::asiolink::IOAddress::toText().

Here is the call graph for this function:

## ◆ del4()

bool isc::host_cache::HostCache::del4 | ( | const dhcp::SubnetID & | subnet_id,
|  | const dhcp::Host::IdentifierType & | identifier_type,
|  | const uint8_t * | identifier_begin,
|  | const size_t | identifier_len )
| virtual

Attempts to delete a host by (subnet-id4, identifier, identifier-type)

This method supports v4 hosts only.

Parameters

  subnet_id | IPv4 Subnet identifier.
  identifier_type | Identifier type.
  identifier_begin | Pointer to a beginning of a buffer containing an identifier.
  identifier_len | Identifier length.

Returns
  always false.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 337 of file host_cache.cc.

References isc::dhcp::Host::getIdentifierAsText(), isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DEL_SUBNET_ID_IDENTIFIER4, isc::host_cache::host_cache_logger, impl_, LOG_DEBUG, and mutex_.

Here is the call graph for this function:

## ◆ del6()

bool isc::host_cache::HostCache::del6 | ( | const dhcp::SubnetID & | subnet_id,
|  | const dhcp::Host::IdentifierType & | identifier_type,
|  | const uint8_t * | identifier_begin,
|  | const size_t | identifier_len )
| virtual

Attempts to delete a host by (subnet-id6, identifier, identifier-type)

This method supports v6 hosts only.

Parameters

  subnet_id | IPv6 Subnet identifier.
  identifier_type | Identifier type.
  identifier_begin | Pointer to a beginning of a buffer containing an identifier.
  identifier_len | Identifier length.

Returns
  always false.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 360 of file host_cache.cc.

References isc::dhcp::Host::getIdentifierAsText(), isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DEL_SUBNET_ID_IDENTIFIER6, isc::host_cache::host_cache_logger, impl_, LOG_DEBUG, and mutex_.

Here is the call graph for this function:

## ◆ flush()

void isc::host_cache::HostCache::flush | ( | size_t | count | ) |
| virtual

Flush entries.

Parameters

  count | number of entries to remove, 0 means all.

Implements isc::dhcp::CacheHostDataSource.

Definition at line 416 of file host_cache.cc.

References impl_, and mutex_.

## ◆ get()

ConstHostCollection isc::host_cache::HostCache::get | ( | const dhcp::Host::IdentifierType & | identifier_type,
|  | const uint8_t * | identifier_begin,
|  | const size_t | identifier_len ) const
| virtual

Return all hosts connected to any subnet for which reservations have been made using a specified identifier.

This method returns all `Host` objects which represent reservations for a specified identifier. This method may return multiple hosts because a particular client may have reservations in multiple subnets.

Parameters

  identifier_type | Identifier type (ignored).
  identifier_begin | Pointer to a beginning of a buffer containing an identifier (ignored).
  identifier_len | Identifier length.

Returns
  Collection of const `Host` objects.

Todo
  Add to the cache_host_data_source.h file.

Definition at line 438 of file host_cache.cc.

References impl_, and mutex_.

## ◆ get4() [1/2]

ConstHostPtr isc::host_cache::HostCache::get4 | ( | const dhcp::SubnetID & | subnet_id,
|  | const asiolink::IOAddress & | address ) const
| virtual

Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.

One of the use cases for this method is to detect collisions between dynamically allocated addresses and reserved addresses. When the new address is assigned to a client, the allocation mechanism should check if this address is not reserved for some other host and do not allocate this address if reservation is present.

Implementations of this method should guard against invalid addresses, such as IPv6 address.

Parameters

  subnet_id | Subnet identifier.
  address | reserved IPv4 address.

Returns
  Const `Host` object using a specified IPv4 address.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 154 of file host_cache.cc.

References isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DBG_TRACE, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS4, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS4_HOST, isc::host_cache::host_cache_logger, impl_, isc::asiolink::IOAddress::isV4(), LOG_DEBUG, mutex_, and isc::asiolink::IOAddress::toText().

Here is the call graph for this function:

## ◆ get4() [2/2]

ConstHostPtr isc::host_cache::HostCache::get4 | ( | const dhcp::SubnetID & | subnet_id,
|  | const dhcp::Host::IdentifierType & | identifier_type,
|  | const uint8_t * | identifier_begin,
|  | const size_t | identifier_len ) const
| virtual

Returns a host connected to the IPv4 subnet.

Parameters

  subnet_id | Subnet identifier.
  identifier_type | Identifier type.
  identifier_begin | Pointer to a beginning of a buffer containing an identifier.
  identifier_len | Identifier length.

Returns
  Const `Host` object for which reservation has been made using the specified identifier.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 125 of file host_cache.cc.

References isc::dhcp::Host::getIdentifierAsText(), isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DBG_TRACE, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_IDENTIFIER, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_IDENTIFIER_HOST, isc::host_cache::host_cache_logger, impl_, LOG_DEBUG, and mutex_.

Here is the call graph for this function:

## ◆ get6() [1/3]

ConstHostPtr isc::host_cache::HostCache::get6 | ( | const asiolink::IOAddress & | prefix,
|  | const uint8_t | prefix_len ) const
| virtual

Returns a host using the specified IPv6 prefix.

Parameters

  prefix | IPv6 prefix for which the `Host` object is searched.
  prefix_len | IPv6 prefix length.

Returns
  Const `Host` object using a specified IPv6 prefix.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 216 of file host_cache.cc.

References isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DBG_TRACE, isc::host_cache::HOST_CACHE_GET_ONE_PREFIX, isc::host_cache::HOST_CACHE_GET_ONE_PREFIX_HOST, isc::host_cache::host_cache_logger, impl_, LOG_DEBUG, mutex_, and isc::asiolink::IOAddress::toText().

Here is the call graph for this function:

## ◆ get6() [2/3]

ConstHostPtr isc::host_cache::HostCache::get6 | ( | const dhcp::SubnetID & | subnet_id,
|  | const asiolink::IOAddress & | address ) const
| virtual

Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix.

Parameters

  subnet_id | Subnet identifier.
  address | reserved IPv6 address/prefix.

Returns
  Const `Host` object using a specified IPv6 address/prefix.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 239 of file host_cache.cc.

References isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DBG_TRACE, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS6, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_ADDRESS6_HOST, isc::host_cache::host_cache_logger, impl_, isc::asiolink::IOAddress::isV6(), LOG_DEBUG, mutex_, and isc::asiolink::IOAddress::toText().

Here is the call graph for this function:

## ◆ get6() [3/3]

ConstHostPtr isc::host_cache::HostCache::get6 | ( | const dhcp::SubnetID & | subnet_id,
|  | const dhcp::Host::IdentifierType & | identifier_type,
|  | const uint8_t * | identifier_begin,
|  | const size_t | identifier_len ) const
| virtual

Returns a host connected to the IPv6 subnet.

Parameters

  subnet_id | Subnet identifier.
  identifier_type | Identifier type.
  identifier_begin | Pointer to a beginning of a buffer containing an identifier.
  identifier_len | Identifier length.

Returns
  Const `Host` object for which reservation has been made using the specified identifier.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 187 of file host_cache.cc.

References isc::dhcp::Host::getIdentifierAsText(), isc::host_cache::HOST_CACHE_DBG_RESULTS, isc::host_cache::HOST_CACHE_DBG_TRACE, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_IDENTIFIER, isc::host_cache::HOST_CACHE_GET_ONE_SUBNET_ID_IDENTIFIER_HOST, isc::host_cache::host_cache_logger, impl_, LOG_DEBUG, and mutex_.

Here is the call graph for this function:

## ◆ getAll()

ConstHostCollection isc::host_cache::HostCache::getAll | ( | const dhcp::Host::IdentifierType & | identifier_type,
|  | const uint8_t * | identifier_begin,
|  | const size_t | identifier_len ) const
| virtual

BaseHostDataSource methods.

Note
  Methods returning collections must return empty collections and not throw because the host cache is an individual object cache so is transparent for these methods. Beware that these methods simply merge results without checking if an entry is already present too.

Return all hosts connected to any subnet for which reservations have been made using a specified identifier.

This method returns all `Host` objects which represent reservations for a specified identifier. This method may return multiple hosts because a particular client may have reservations in multiple subnets.

Parameters

  identifier_type | Identifier type (ignored).
  identifier_begin | Pointer to a beginning of a buffer containing an identifier (ignored).
  identifier_len | Identifier length.

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 56 of file host_cache.cc.

## ◆ getAll4() [1/3]

ConstHostCollection isc::host_cache::HostCache::getAll4 | ( | const asiolink::IOAddress & | address | ) | const
| virtual

Returns a collection of hosts using the specified IPv4 address.

This method may return multiple `Host` objects if they are connected to different subnets.

Parameters

  address | IPv4 address for which the `Host` object is searched (ignored).

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 120 of file host_cache.cc.

## ◆ getAll4() [2/3]

ConstHostCollection isc::host_cache::HostCache::getAll4 | ( | const dhcp::SubnetID & | subnet_id | ) | const
| virtual

Return all hosts in a DHCPv4 subnet.

This method returns all `Host` objects which represent reservations in a specified subnet.

Parameters

  subnet_id | Subnet identifier.

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 63 of file host_cache.cc.

## ◆ getAll4() [3/3]

ConstHostCollection isc::host_cache::HostCache::getAll4 | ( | const dhcp::SubnetID & | subnet_id,
|  | const asiolink::IOAddress & | address ) const
| virtual

Returns all hosts connected to the IPv4 subnet and having a reservation for a specified address.

Parameters

  subnet_id | Subnet identifier.
  address | reserved IPv4 address.

Returns
  Empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 181 of file host_cache.cc.

## ◆ getAll6() [1/3]

ConstHostCollection isc::host_cache::HostCache::getAll6 | ( | const asiolink::IOAddress & | address | ) | const
| virtual

Returns a collection of hosts using the specified IPv6 address.

This method may return multiple `Host` objects if they are connected to different subnets.

Parameters

  address | IPv6 address for which the `Host` object is searched.

Returns
  Empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 273 of file host_cache.cc.

## ◆ getAll6() [2/3]

ConstHostCollection isc::host_cache::HostCache::getAll6 | ( | const dhcp::SubnetID & | subnet_id | ) | const
| virtual

Return all hosts in a DHCPv6 subnet.

This method returns all `Host` objects which represent reservations in a specified subnet.

Parameters

  subnet_id | Subnet identifier.

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 68 of file host_cache.cc.

## ◆ getAll6() [3/3]

ConstHostCollection isc::host_cache::HostCache::getAll6 | ( | const dhcp::SubnetID & | subnet_id,
|  | const asiolink::IOAddress & | address ) const
| virtual

Returns all hosts connected to the IPv6 subnet and having a reservation for a specified address or delegated prefix (lease).

Parameters

  subnet_id | Subnet identifier.
  address | reserved IPv6 address/prefix.

Returns
  Empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 267 of file host_cache.cc.

## ◆ getAllbyHostname()

ConstHostCollection isc::host_cache::HostCache::getAllbyHostname | ( | const std::string & | hostname | ) | const
| virtual

Return all hosts with a hostname.

This method returns all `Host` objects which represent reservations using a specified hostname.

Parameters

  hostname | The lower case hostname.

Returns
  Collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 73 of file host_cache.cc.

## ◆ getAllbyHostname4()

ConstHostCollection isc::host_cache::HostCache::getAllbyHostname4 | ( | const std::string & | hostname,
|  | const dhcp::SubnetID & | subnet_id ) const
| virtual

Return all hosts with a hostname in a DHCPv4 subnet.

This method returns all `Host` objects which represent reservations using a specified hostname in a specified subnet.

Parameters

  hostname | The lower case hostname.
  subnet_id | Subnet identifier.

Returns
  Collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 78 of file host_cache.cc.

## ◆ getAllbyHostname6()

ConstHostCollection isc::host_cache::HostCache::getAllbyHostname6 | ( | const std::string & | hostname,
|  | const dhcp::SubnetID & | subnet_id ) const
| virtual

Return all hosts with a hostname in a DHCPv6 subnet.

This method returns all `Host` objects which represent reservations using a specified hostname in a specified subnet.

Parameters

  hostname | The lower case hostname.
  subnet_id | Subnet identifier.

Returns
  Collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 84 of file host_cache.cc.

## ◆ getMaximum()

size_t isc::host_cache::HostCache::getMaximum | ( |  | ) | const
| virtual

Get maximum number of cached hosts.

Definition at line 50 of file host_cache.cc.

References impl_, and mutex_.

## ◆ getPage4() [1/2]

dhcp::ConstHostCollection isc::host_cache::HostCache::getPage4 | ( | const dhcp::SubnetID & | subnet_id,
|  | size_t & | source_index,
|  | uint64_t | lower_host_id,
|  | const dhcp::HostPageSize & | page_size ) const
| virtual

Return range of hosts in a DHCPv4 subnet.

This method returns a page of `Host` objects which represent reservations in a specified subnet.

Parameters

  subnet_id | Subnet identifier.
  source_index | Index of the source (unused).
  lower_host_id | Host identifier used as lower bound for the returned range.
  page_size | maximum size of the page returned.

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 90 of file host_cache.cc.

## ◆ getPage4() [2/2]

dhcp::ConstHostCollection isc::host_cache::HostCache::getPage4 | ( | size_t & | source_index,
|  | uint64_t | lower_host_id,
|  | const dhcp::HostPageSize & | page_size ) const
| virtual

Return range of hosts.

This method returns a page of `Host` objects which represent reservations.

Parameters

  source_index | Index of the source (unused).
  lower_host_id | Host identifier used as lower bound for the returned range.
  page_size | maximum size of the page returned.

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 106 of file host_cache.cc.

## ◆ getPage6() [1/2]

dhcp::ConstHostCollection isc::host_cache::HostCache::getPage6 | ( | const dhcp::SubnetID & | subnet_id,
|  | size_t & | source_index,
|  | uint64_t | lower_host_id,
|  | const dhcp::HostPageSize & | page_size ) const
| virtual

Return range of hosts in a DHCPv6 subnet.

This method returns a page of `Host` objects which represent reservations in a specified subnet.

Parameters

  subnet_id | Subnet identifier.
  source_index | Index of the source (unused).
  lower_host_id | Host identifier used as lower bound for the returned range.
  page_size | maximum size of the page returned.

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 98 of file host_cache.cc.

## ◆ getPage6() [2/2]

dhcp::ConstHostCollection isc::host_cache::HostCache::getPage6 | ( | size_t & | source_index,
|  | uint64_t | lower_host_id,
|  | const dhcp::HostPageSize & | page_size ) const
| virtual

Return range of hosts.

This method returns a page of `Host` objects which represent reservations.

Parameters

  source_index | Index of the source (unused).
  lower_host_id | Host identifier used as lower bound for the returned range.
  page_size | maximum size of the page returned.

Returns
  Always returns an empty collection of const `Host` objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 113 of file host_cache.cc.

## ◆ getType()

virtual std::string isc::host_cache::HostCache::getType | ( |  | ) | const
| inlinevirtual

Return backend type.

Returns the type of the backend (e.g. "mysql", "memfile" etc.)

Returns
  "cache" string.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 394 of file host_cache.h.

## ◆ insert()

size_t isc::host_cache::HostCache::insert | ( | const dhcp::ConstHostPtr & | host,
|  | bool | overwrite )
| virtual

Insert a host into the cache.

Similar to `add()` but with a different purpose.

Parameters

  host | Pointer to the new `Host` object being inserted.
  overwrite | false if doing nothing in case of conflicts (and returning 1), true if removing conflicting entries (and returning their number).

Returns
  number of conflicts limited to one if overwrite is false.

Implements isc::dhcp::CacheHostDataSource.

Definition at line 404 of file host_cache.cc.

References impl_, and mutex_.

## ◆ remove()

bool isc::host_cache::HostCache::remove | ( | const dhcp::HostPtr & | host | ) |
| virtual

Remove a host from the cache.

Does the same than `del`, `del4` or `del6` but with a more uniform interface and a different purpose.

Note
  A pointer to a copy does not remove the object.

Parameters

  host | Pointer to the existing `Host` object being removed.

Returns
  true when found and removed.

Implements isc::dhcp::CacheHostDataSource.

Definition at line 410 of file host_cache.cc.

References impl_, and mutex_.

## ◆ setIPReservationsUnique()

bool isc::host_cache::HostCache::setIPReservationsUnique | ( | const bool | unique | ) |
| virtual

Controls whether IP reservations are unique or non-unique.

In a typical case, the IP reservations are unique and backends verify prior to adding a host reservation to the database that the reservation for a given IP address/subnet does not exist. In some cases it may be required to allow non-unique IP reservations, e.g. in the case when a host has several interfaces and independently of which interface is used by this host to communicate with the DHCP server the same IP address should be assigned. In this case the `unique` value should be set to false to disable the checks for uniqueness on the backend side.

Parameters

  unique | boolean flag indicating if the IP reservations must be unique within the subnet or can be non-unique.

Returns
  true when addresses must be unique, false otherwise because this backend does not support specifying the same IP address in multiple host reservations.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 389 of file host_cache.cc.

## ◆ setMaximum()

void isc::host_cache::HostCache::setMaximum | ( | size_t | maximum | ) |
| virtual

Set maximum number of cached hosts (0 means unbound).

Definition at line 45 of file host_cache.cc.

References impl_, and mutex_.

Referenced by isc::host_cache::HCConfigParser::parse().

## ◆ size()

size_t isc::host_cache::HostCache::size | ( |  | ) | const
| virtual

Return the number of entries.

Returns
  the current number of active entries in the cache.

Implements isc::dhcp::CacheHostDataSource.

Definition at line 426 of file host_cache.cc.

References impl_, and mutex_.

## ◆ toElement()

ElementPtr isc::host_cache::HostCache::toElement | ( |  | ) | const
| virtual

Returns the whole content of the cache as Element tree.

Returns
  a pointer to unparsed content

Definition at line 398 of file host_cache.cc.

References impl_, and mutex_.

## ◆ update()

void isc::host_cache::HostCache::update | ( | isc::dhcp::HostPtr const & | host | ) |
| virtual

Implements isc::dhcp::BaseHostDataSource::update() for HostCache.

Attempts to update an existing host entry.

Parameters

  host | the host up to date with the requested changes

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 383 of file host_cache.cc.

References impl_, and mutex_.

## Member Data Documentation

## ◆ impl_

boost::shared_ptr<HostCacheImpl> isc::host_cache::HostCache::impl_
| protected

Implementation.

Definition at line 674 of file host_cache.h.

Referenced by HostCache(), ~HostCache(), add(), cacheClearHandler(), cacheFlushHandler(), cacheGetByIdHandler(), cacheGetHandler(), cacheInsertHandler(), cacheLoadHandler(), cacheRemoveHandler(), cacheSizeHandler(), cacheWriteHandler(), capacity(), del(), del4(), del6(), flush(), get(), get4(), get4(), get6(), get6(), get6(), getMaximum(), insert(), remove(), setMaximum(), size(), toElement(), and update().

## ◆ mutex_

boost::scoped_ptr<std::mutex> isc::host_cache::HostCache::mutex_
| protected

mutex

Definition at line 677 of file host_cache.h.

Referenced by HostCache(), add(), cacheGetByIdHandler(), cacheInsertHandler(), cacheRemoveHandler(), cacheSizeHandler(), capacity(), del(), del4(), del6(), flush(), get(), get4(), get4(), get6(), get6(), get6(), getMaximum(), insert(), remove(), setMaximum(), size(), toElement(), and update().

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

- host_cache.h
- host_cache.cc