Kea  1.5.0
isc::dhcp::CqlHostDataSource Class Reference

Cassandra host data source. More...

#include <cql_host_data_source.h>

+ Inheritance diagram for isc::dhcp::CqlHostDataSource:

Public Member Functions

 CqlHostDataSource (const db::DatabaseConnection::ParameterMap &parameters)
 Constructor. More...
 
virtual ~CqlHostDataSource ()
 Virtual destructor. More...
 
virtual void add (const HostPtr &host) override
 Adds a new host to the collection. More...
 
virtual void commit () override
 Commit Transactions. More...
 
virtual bool del (const SubnetID &subnet_id, const asiolink::IOAddress &addr) override
 Attempts to delete a host by (subnet-id, address) More...
 
virtual bool del4 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) override
 Attempts to delete a host by (subnet-id4, identifier-type, identifier). More...
 
virtual bool del6 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) override
 Attempts to delete a host by (subnet-id6, identifier-type, identifier). More...
 
virtual ConstHostPtr get4 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const override
 Retrieves a Host connected to an IPv4 subnet. More...
 
virtual ConstHostPtr get4 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const override
 Retrieves a Host connected to an IPv4 subnet. More...
 
virtual ConstHostPtr get6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len) const override
 Returns a Host with the specified reservation prefix. More...
 
virtual ConstHostPtr get6 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const override
 Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or prefix. More...
 
virtual ConstHostPtr get6 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const override
 Returns a Host connected to an IPv6 subnet. More...
 
virtual ConstHostCollection getAll (const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const override
 Return all hosts connected to any subnet for which reservations have been made using a specified identifier. More...
 
virtual ConstHostCollection getAll4 (const asiolink::IOAddress &address) const override
 Returns a collection of hosts using the specified IPv4 address. More...
 
virtual ConstHostCollection getAllHosts () const
 Returns a collection of all the hosts. More...
 
virtual std::string getDescription () const
 Returns textual description of the backend. More...
 
virtual std::string getName () const
 Returns the name of the database. More...
 
virtual std::string getType () const override
 Return backend type. More...
 
virtual db::VersionPair getVersion () const
 Retrieves schema version from the DB. More...
 
virtual void rollback () override
 Rollback Transactions. More...
 
- Public Member Functions inherited from isc::dhcp::BaseHostDataSource
virtual ~BaseHostDataSource ()
 Default destructor implementation. More...
 

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

Cassandra host data source.

Implements isc::dhcp::BaseHostDataSource interface customized to Cassandra. Use of this backend implies that a Cassandra database is available and that the Kea schema has been created within it.

The database schema is radically different than the MySQL and the PostgreSQL schemas. Rather than creating a different table for hosts, reservations, DHCPv4 options and DHCPv6 options respectively, the data is denormalized into a single table to benefit from Cassandra's non-relational nature. To make up for the lack of relations, on insertion, the reservations and options are matched against hosts on the server and merged into database entries. When retrieving, each database row is split into the corresponding host, reservation and options.

There can be an inconsistency in the database due to the order of the changes e.g. if you insert a host with no reservations and no options followed by the same host with one reservation will result in 2 entries versus inserting the host with reservation from the beginning which will result in a single entry. In spite of this, retrieving the host will give you the attached reservation in both cases.

Definition at line 56 of file cql_host_data_source.h.

Constructor & Destructor Documentation

◆ CqlHostDataSource()

isc::dhcp::CqlHostDataSource::CqlHostDataSource ( const db::DatabaseConnection::ParameterMap parameters)
explicit

Constructor.

Uses the following keywords in the parameters passed to it to connect to the database:

  • keyspace
  • host
  • user
  • password
  • contact-points
  • reconnect-wait-time
  • connect-timeout
  • request-timeout
  • tcp-keepalive
  • tcp-nodelay

For details regarding those paraemters, see isc::db::CqlConnection::openDatabase.

Finally, all the CQL commands are pre-compiled.

Parameters
parametersa data structure relating keywords and values concerned with the database.
Exceptions
isc::db::NoDatabaseNameMandatory database name not given
isc::db::DbOpenErrorError opening the database or if the schema version is invalid.
isc::db::DbOperationErrorAn operation on the open database has failed.

Definition at line 2053 of file cql_host_data_source.cc.

◆ ~CqlHostDataSource()

isc::dhcp::CqlHostDataSource::~CqlHostDataSource ( )
virtual

Virtual destructor.

Releases prepared CQL statements used by the backend.

Definition at line 2057 of file cql_host_data_source.cc.

Member Function Documentation

◆ add()

void isc::dhcp::CqlHostDataSource::add ( const HostPtr host)
overridevirtual

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 HWAddr and SubnetID is added twice, add() should throw a db::DuplicateEntry exception. Note, that usually it is impossible to guard against adding duplicated Host, where one instance is identified by different identifier types.

Parameters
hostpointer to the new Host being added.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2062 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::insertOrDelete(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ commit()

void isc::dhcp::CqlHostDataSource::commit ( )
overridevirtual

Commit Transactions.

Commits all pending database operations (no-op for Cassandra)

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 2182 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, and LOG_DEBUG.

◆ del()

bool isc::dhcp::CqlHostDataSource::del ( const SubnetID subnet_id,
const asiolink::IOAddress addr 
)
overridevirtual

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

This method supports both v4 and v6.

Parameters
subnet_idsubnet identfier.
addrspecified address.
Returns
true if deletion was successful, false if the host was not there.
Exceptions
variousexceptions in case of errors

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2069 of file cql_host_data_source.cc.

References isc::dhcp::CqlHostDataSourceImpl::get4(), and isc::dhcp::CqlHostDataSourceImpl::insertOrDelete().

+ Here is the call graph for this function:

◆ del4()

bool isc::dhcp::CqlHostDataSource::del4 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
)
overridevirtual

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

This method supports v4 hosts only.

Parameters
subnet_idIPv4 Subnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
true if deletion was successful, false if the host was not there.
Exceptions
variousexceptions in case of errors

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2076 of file cql_host_data_source.cc.

References isc::dhcp::CqlHostDataSourceImpl::get4(), and isc::dhcp::CqlHostDataSourceImpl::insertOrDelete().

+ Here is the call graph for this function:

◆ del6()

bool isc::dhcp::CqlHostDataSource::del6 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
)
overridevirtual

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

This method supports v6 hosts only.

Parameters
subnet_idIPv6 Subnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
true if deletion was successful, false if the host was not there.
Exceptions
variousexceptions in case of errors

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2085 of file cql_host_data_source.cc.

References isc::dhcp::CqlHostDataSourceImpl::get6(), and isc::dhcp::CqlHostDataSourceImpl::insertOrDelete().

+ Here is the call graph for this function:

◆ get4() [1/2]

ConstHostPtr isc::dhcp::CqlHostDataSource::get4 ( const SubnetID subnet_id,
const asiolink::IOAddress address 
) const
overridevirtual

Retrieves a Host connected to an IPv4 subnet.

The host is identifier by specified IPv4 address.

Parameters
subnet_idSubnet identifier.
addressreserved IPv4 address.
Returns
Const Host object
Exceptions
BadValueif address in not a valid IPv4address

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2121 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::get4(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ get4() [2/2]

ConstHostPtr isc::dhcp::CqlHostDataSource::get4 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
overridevirtual

Retrieves a Host connected to an IPv4 subnet.

The host is identified by specific identifier.

Parameters
subnet_idsubnet identifier to filter by
identifier_typeidentifier type to filter by
identifier_beginpointer to the beginning of a buffer containing a host identifier to filter by
identifier_lenlength of the host identifier buffer
Returns
Host object for which a reservation has been made using the specified identifier

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2110 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::get4(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ get6() [1/3]

ConstHostPtr isc::dhcp::CqlHostDataSource::get6 ( const asiolink::IOAddress prefix,
const uint8_t  prefix_len 
) const
overridevirtual

Returns a Host with the specified reservation prefix.

Parameters
prefixIPv6 prefix for which the Host object is searched.
prefix_lenIPv6 prefix length.
Returns
Const Host object using a specified IPv6 prefix.
Exceptions
MultipleRecordsif two or more rows are returned from the Cassandra database

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2139 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::get6(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ get6() [2/3]

ConstHostPtr isc::dhcp::CqlHostDataSource::get6 ( const SubnetID subnet_id,
const asiolink::IOAddress address 
) const
overridevirtual

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.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2147 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::get6(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ get6() [3/3]

ConstHostPtr isc::dhcp::CqlHostDataSource::get6 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
overridevirtual

Returns a Host connected to an IPv6 subnet.

Parameters
subnet_idsubnet identifier to filter by
identifier_typeidentifier type to filter by
identifier_beginpointer to the beginning of a buffer containing a host identifier to filter by
identifier_lenlength of the host identifier buffer
Returns
Const Host object for which reservation has been made using the specified identifier.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2129 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::get6(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ getAll()

ConstHostCollection isc::dhcp::CqlHostDataSource::getAll ( const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
overridevirtual

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.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2094 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::getAll(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ getAll4()

ConstHostCollection isc::dhcp::CqlHostDataSource::getAll4 ( const asiolink::IOAddress address) const
overridevirtual

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
addressIPv4 address for which the Host object is searched.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2103 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::getAll4(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ getAllHosts()

ConstHostCollection isc::dhcp::CqlHostDataSource::getAllHosts ( ) const
virtual

Returns a collection of all the hosts.

This method may return multiple Host objects. It is only used in testing. It may be very slow when running on a production server with lots of hosts.

Returns
Collection of const Host objects.

Definition at line 2155 of file cql_host_data_source.cc.

References isc::dhcp::CqlHostDataSourceImpl::getAllHosts().

+ Here is the call graph for this function:

◆ getDescription()

std::string isc::dhcp::CqlHostDataSource::getDescription ( ) const
virtual

Returns textual description of the backend.

Returns
Description of the backend.

Definition at line 2170 of file cql_host_data_source.cc.

◆ getName()

std::string isc::dhcp::CqlHostDataSource::getName ( ) const
virtual

Returns the name of the database.

Returns
database name

Definition at line 2165 of file cql_host_data_source.cc.

References isc::dhcp::CqlHostDataSourceImpl::getName().

+ Here is the call graph for this function:

◆ getType()

std::string isc::dhcp::CqlHostDataSource::getType ( ) const
overridevirtual

Return backend type.

Returns
backend type "cql"

Implements isc::dhcp::BaseHostDataSource.

Definition at line 2160 of file cql_host_data_source.cc.

◆ getVersion()

VersionPair isc::dhcp::CqlHostDataSource::getVersion ( ) const
virtual

Retrieves schema version from the DB.

Returns
Version number stored in the database, as a pair of unsigned integers. "first" is the major version number, "second" is the minor version number.
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Definition at line 2175 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::CqlHostDataSourceImpl::getVersion(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ rollback()

void isc::dhcp::CqlHostDataSource::rollback ( )
overridevirtual

Rollback Transactions.

Rolls back all pending database operations (no-op for Cassandra)

Reimplemented from isc::dhcp::BaseHostDataSource.

Definition at line 2187 of file cql_host_data_source.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, and LOG_DEBUG.


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