Kea 3.1.1
isc::host_cache::HostCacheImpl Class Reference

Host Cache hooks library implementation. More...

#include <host_cache_impl.h>

Public Member Functions

 HostCacheImpl ()
 Constructor.
 
virtual ~HostCacheImpl ()
 Destructor.
 
bool add (const dhcp::HostPtr &host)
 Adds a new host to the collection.
 
size_t capacity () const
 Return the maximum number of entries.
 
void clear ()
 Flush all entries.
 
std::string del4 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
 Attempts to delete a host by (subnet-id4, address)
 
std::string 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)
 
std::string del6 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
 Attempts to delete a host by (subnet-id6, address)
 
std::string 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)
 
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.
 
dhcp::ConstHostPtr get4 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address)
 Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.
 
dhcp::ConstHostPtr get4 (const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
 Returns a host connected to the IPv4 subnet.
 
dhcp::ConstHostPtr get6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len)
 Returns a host using the specified IPv6 prefix.
 
dhcp::ConstHostPtr get6 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address)
 Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix.
 
dhcp::ConstHostPtr get6 (const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
 Returns a host connected to the IPv6 subnet.
 
HostContainerSequencedIndex::iterator getHostInternal (const dhcp::SubnetID &subnet_id, const bool subnet6, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier, const size_t identifier_len)
 Returns Host object connected to a subnet.
 
HostContainerSequencedIndex::iterator getHostInternal4 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address)
 Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.
 
dhcp::HostPtr getHostInternal6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len)
 Returns a host using the specified IPv6 prefix.
 
dhcp::HostPtr getHostInternal6 (const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address)
 Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix.
 
size_t getMaximum () const
 Get maximum number of elements.
 
size_t insert (const dhcp::ConstHostPtr &host, bool overwrite)
 Insert a host into the cache.
 
bool insertResv6 (const dhcp::HostPtr &host)
 Insert IPv6 reservations.
 
dhcp::HostPtr relocate (dhcp::HostPtr host)
 Relocate an entry to the end of sequenced index.
 
bool remove (const dhcp::HostPtr &host)
 Remove a host from the cache.
 
void removeResv6 (const dhcp::HostPtr &host)
 Remove IPv6 reservations.
 
void setMaximum (size_t maximum)
 Set maximum number of elements.
 
size_t size () const
 Return the number of entries.
 
data::ElementPtr toElement () const
 Unparse cache content.
 
void update (isc::dhcp::ConstHostPtr const &host)
 Implements isc::dhcp::BaseHostDataSource::update() for HostCacheImpl.
 

Public Attributes

size_t maximum_
 Maximum number of elements (0 means unbound).
 

Detailed Description

Host Cache hooks library implementation.

Definition at line 24 of file host_cache_impl.h.

Constructor & Destructor Documentation

◆ HostCacheImpl()

isc::host_cache::HostCacheImpl::HostCacheImpl ( )

Constructor.

Exceptions
Unexpectedif allocation fails.

Definition at line 24 of file host_cache_impl.cc.

References maximum_.

◆ ~HostCacheImpl()

isc::host_cache::HostCacheImpl::~HostCacheImpl ( )
virtual

Destructor.

Definition at line 27 of file host_cache_impl.cc.

Member Function Documentation

◆ add()

bool isc::host_cache::HostCacheImpl::add ( const dhcp::HostPtr & host)

Adds a new host to the collection.

Parameters
hostPointer to the new Host object being added.
Returns
true if successful, false if there is a conflict and it fails.

Definition at line 390 of file host_cache_impl.cc.

References insert().

+ Here is the call graph for this function:

◆ capacity()

size_t isc::host_cache::HostCacheImpl::capacity ( ) const
inline

Return the maximum number of entries.

Returns
the maximum number of entries, 0 means unbound.

Definition at line 280 of file host_cache_impl.h.

References maximum_.

◆ clear()

void isc::host_cache::HostCacheImpl::clear ( )
inline

Flush all entries.

Definition at line 260 of file host_cache_impl.h.

◆ del4() [1/2]

string isc::host_cache::HostCacheImpl::del4 ( const dhcp::SubnetID & subnet_id,
const asiolink::IOAddress & addr )

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

Parameters
subnet_idsubnet identifier.
addrspecified address.
Returns
deleted host information.

Definition at line 395 of file host_cache_impl.cc.

References removeResv6().

+ Here is the call graph for this function:

◆ del4() [2/2]

string isc::host_cache::HostCacheImpl::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)

Parameters
subnet_idIPv4 Subnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
deleted host information.

Definition at line 432 of file host_cache_impl.cc.

References removeResv6().

+ Here is the call graph for this function:

◆ del6() [1/2]

string isc::host_cache::HostCacheImpl::del6 ( const dhcp::SubnetID & subnet_id,
const asiolink::IOAddress & addr )

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

Parameters
subnet_idsubnet identifier.
addrspecified address.
Returns
deleted host information.

Definition at line 415 of file host_cache_impl.cc.

References remove().

+ Here is the call graph for this function:

◆ del6() [2/2]

string isc::host_cache::HostCacheImpl::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)

Parameters
subnet_idIPv6 Subnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
deleted host information.

Definition at line 457 of file host_cache_impl.cc.

References removeResv6().

+ Here is the call graph for this function:

◆ flush()

void isc::host_cache::HostCacheImpl::flush ( size_t count)

Flush entries.

Parameters
countnumber of entries to remove.

Definition at line 497 of file host_cache_impl.cc.

References removeResv6().

Referenced by insert().

+ Here is the call graph for this function:

◆ get()

ConstHostCollection isc::host_cache::HostCacheImpl::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_typeIdentifier type (ignored).
identifier_beginPointer to a beginning of a buffer containing an identifier (ignored).
identifier_lenIdentifier length.
Returns
Collection of const Host objects.
Todo
Add to the cache_host_data_source.h file.

Definition at line 528 of file host_cache_impl.cc.

◆ get4() [1/2]

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

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

Parameters
subnet_idSubnet identifier.
addressreserved IPv4 address.
Returns
Const Host object using a specified IPv4 address.

Definition at line 131 of file host_cache_impl.cc.

References getHostInternal4().

+ Here is the call graph for this function:

◆ get4() [2/2]

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

Returns a host connected to the IPv4 subnet.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object using the specified identifier.

Definition at line 116 of file host_cache_impl.cc.

References getHostInternal().

+ Here is the call graph for this function:

◆ get6() [1/3]

ConstHostPtr isc::host_cache::HostCacheImpl::get6 ( const asiolink::IOAddress & prefix,
const uint8_t prefix_len )

Returns a host using the specified IPv6 prefix.

Parameters
prefixIPv6 prefix for which the Host object is searched.
prefix_lenIPv6 prefix length.
Returns
Const Host object using a specified prefix.

Definition at line 158 of file host_cache_impl.cc.

References getHostInternal6(), and relocate().

+ Here is the call graph for this function:

◆ get6() [2/3]

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

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

Parameters
subnet_idSubnet identifier.
addressreserved IPv6 address/prefix.
Returns
Const Host object using a specified IPv6 address/prefix.

Definition at line 165 of file host_cache_impl.cc.

References getHostInternal6(), and relocate().

+ Here is the call graph for this function:

◆ get6() [3/3]

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

Returns a host connected to the IPv6 subnet.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object using the specified identifier.

Definition at line 143 of file host_cache_impl.cc.

References getHostInternal().

+ Here is the call graph for this function:

◆ getHostInternal()

HostContainerSequencedIndex::iterator isc::host_cache::HostCacheImpl::getHostInternal ( const dhcp::SubnetID & subnet_id,
const bool subnet6,
const dhcp::Host::IdentifierType & identifier_type,
const uint8_t * identifier,
const size_t identifier_len )

Returns Host object connected to a subnet.

Parameters
subnet_idIPv4 or IPv6 subnet identifier.
subnet6A boolean flag which indicates if the subnet identifier points to a IPv4 (if false) or IPv6 subnet (if true).
identifier_typeIdentifier type.
identifierPointer to a first byte of the buffer holding an identifier.
identifier_lenIdentifier length.
Returns
Iterator to the found host, or end if no host is found.

Definition at line 172 of file host_cache_impl.cc.

Referenced by get4(), get6(), and insert().

◆ getHostInternal4()

HostContainerSequencedIndex::iterator isc::host_cache::HostCacheImpl::getHostInternal4 ( const dhcp::SubnetID & subnet_id,
const asiolink::IOAddress & address )

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

Parameters
subnet_idSubnet identifier.
addressreserved IPv4 address.
Returns
Iterator to the found host, or end if no host is found.

Definition at line 198 of file host_cache_impl.cc.

Referenced by get4(), and insert().

◆ getHostInternal6() [1/2]

HostPtr isc::host_cache::HostCacheImpl::getHostInternal6 ( const asiolink::IOAddress & prefix,
const uint8_t prefix_len )

Returns a host using the specified IPv6 prefix.

Parameters
prefixIPv6 prefix for which the Host object is searched.
prefix_lenIPv6 prefix length.
Returns
Host object using a specified prefix, or NULL if no

Definition at line 215 of file host_cache_impl.cc.

Referenced by get6(), get6(), and insert().

◆ getHostInternal6() [2/2]

HostPtr isc::host_cache::HostCacheImpl::getHostInternal6 ( const dhcp::SubnetID & subnet_id,
const asiolink::IOAddress & address )

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

Parameters
subnet_idSubnet identifier.
addressreserved IPv6 address/prefix.
Returns
Const Host object using a specified IPv6 address/prefix, or NULL if no host is found.

Definition at line 231 of file host_cache_impl.cc.

◆ getMaximum()

size_t isc::host_cache::HostCacheImpl::getMaximum ( ) const
inline

Get maximum number of elements.

Definition at line 43 of file host_cache_impl.h.

References maximum_.

◆ insert()

size_t isc::host_cache::HostCacheImpl::insert ( const dhcp::ConstHostPtr & host,
bool overwrite )

Insert a host into the cache.

Does the same than add() but with a different purpose.

Parameters
hostPointer to the new Host object being inserted.
overwritefalse 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.

Definition at line 248 of file host_cache_impl.cc.

References flush(), getHostInternal(), getHostInternal4(), getHostInternal6(), insertResv6(), isc::asiolink::IOAddress::isV4Zero(), maximum_, remove(), removeResv6(), isc::dhcp::IPv6Resrv::TYPE_NA, and isc::dhcp::IPv6Resrv::TYPE_PD.

Referenced by add(), and update().

+ Here is the call graph for this function:

◆ insertResv6()

bool isc::host_cache::HostCacheImpl::insertResv6 ( const dhcp::HostPtr & host)

Insert IPv6 reservations.

Parameters
hosthost with the IPv6 reservations to insert.
Returns
true if succeed.

Definition at line 31 of file host_cache_impl.cc.

Referenced by insert().

◆ relocate()

HostPtr isc::host_cache::HostCacheImpl::relocate ( dhcp::HostPtr host)

Relocate an entry to the end of sequenced index.

Used to implement least-recently-used, called to return get*() results.

Parameters
hosthost to relocate.
Returns
host itself.

Definition at line 100 of file host_cache_impl.cc.

References removeResv6().

Referenced by get6(), and get6().

+ Here is the call graph for this function:

◆ remove()

bool isc::host_cache::HostCacheImpl::remove ( const dhcp::HostPtr & host)

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
hostPointer to the existing Host object being removed.
Returns
true when found and removed.

Definition at line 483 of file host_cache_impl.cc.

References removeResv6().

Referenced by del6(), and insert().

+ Here is the call graph for this function:

◆ removeResv6()

void isc::host_cache::HostCacheImpl::removeResv6 ( const dhcp::HostPtr & host)

Remove IPv6 reservations.

Parameters
hosthost with the IPv6 reservations to remove.

Definition at line 51 of file host_cache_impl.cc.

References isc::dhcp::IPv6Resrv::TYPE_NA, and isc::dhcp::IPv6Resrv::TYPE_PD.

Referenced by del4(), del4(), del6(), flush(), insert(), relocate(), and remove().

◆ setMaximum()

void isc::host_cache::HostCacheImpl::setMaximum ( size_t maximum)
inline

Set maximum number of elements.

Definition at line 38 of file host_cache_impl.h.

References maximum_.

◆ size()

size_t isc::host_cache::HostCacheImpl::size ( ) const
inline

Return the number of entries.

Returns
the current number of active entries in the cache.

Definition at line 273 of file host_cache_impl.h.

◆ toElement()

ElementPtr isc::host_cache::HostCacheImpl::toElement ( ) const

Unparse cache content.

Returns
a pointer to unparsed content

Definition at line 513 of file host_cache_impl.cc.

References Element::createList(), and isc::host_cache::toElement().

+ Here is the call graph for this function:

◆ update()

void isc::host_cache::HostCacheImpl::update ( isc::dhcp::ConstHostPtr const & host)

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

Attempts to update an existing host entry.

Parameters
hostthe host up to date with the requested changes

This is not an upsert, so if the host doesn't exist yet, throw an error.

Todo
: If this function ever ends up being used, this brute force search should be replaced with a host ID index.

Definition at line 359 of file host_cache_impl.cc.

References insert(), and isc_throw.

+ Here is the call graph for this function:

Member Data Documentation

◆ maximum_

size_t isc::host_cache::HostCacheImpl::maximum_

Maximum number of elements (0 means unbound).

Definition at line 35 of file host_cache_impl.h.

Referenced by HostCacheImpl(), capacity(), getMaximum(), insert(), and setMaximum().


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