Kea  1.5.0
isc::dhcp::MySqlHostDataSourceImpl Class Reference

Implementation of the MySqlHostDataSource. More...

Public Types

enum  StatementIndex {
  GET_HOST_DHCPID, GET_HOST_ADDR, GET_HOST_SUBID4_DHCPID, GET_HOST_SUBID6_DHCPID,
  GET_HOST_SUBID_ADDR, GET_HOST_PREFIX, GET_HOST_SUBID6_ADDR, INSERT_HOST,
  INSERT_V6_RESRV, INSERT_V4_OPTION, INSERT_V6_OPTION, DEL_HOST_ADDR4,
  DEL_HOST_SUBID4_ID, DEL_HOST_SUBID6_ID, NUM_STATEMENTS
}
 Statement Tags. More...
 

Public Member Functions

 MySqlHostDataSourceImpl (const MySqlConnection::ParameterMap &parameters)
 Constructor. More...
 
 ~MySqlHostDataSourceImpl ()
 Destructor. More...
 
void addOption (const MySqlHostDataSourceImpl::StatementIndex &stindex, const OptionDescriptor &opt_desc, const std::string &opt_space, const OptionalValue< SubnetID > &subnet_id, const HostID &host_id)
 Inserts a single DHCP option into the database. More...
 
void addOptions (const StatementIndex &stindex, const ConstCfgOptionPtr &options_cfg, const uint64_t host_id)
 Inserts multiple options into the database. More...
 
void addResv (const IPv6Resrv &resv, const HostID &id)
 Inserts IPv6 Reservation into ipv6_reservation table. More...
 
void addStatement (MySqlHostDataSourceImpl::StatementIndex stindex, std::vector< MYSQL_BIND > &bind)
 Executes statements which inserts a row into one of the tables. More...
 
void checkError (const int status, const StatementIndex index, const char *what) const
 Check Error and Throw Exception. More...
 
void checkReadOnly () const
 Throws exception if database is read only. More...
 
bool delStatement (StatementIndex stindex, MYSQL_BIND *bind)
 Executes statements that delete records. More...
 
ConstHostPtr getHost (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, StatementIndex stindex, boost::shared_ptr< MySqlHostExchange > exchange) const
 Retrieves a host by subnet and client's unique identifier. More...
 
void getHostCollection (StatementIndex stindex, MYSQL_BIND *bind, boost::shared_ptr< MySqlHostExchange > exchange, ConstHostCollection &result, bool single) const
 Creates collection of Host objects with associated information such as IPv6 reservations and/or DHCP options. More...
 
std::pair< uint32_t, uint32_t > getVersion () const
 Returns backend version. More...
 

Public Attributes

MySqlConnection conn_
 MySQL connection. More...
 
boost::shared_ptr< MySqlHostWithOptionsExchange > host_exchange_
 Pointer to the object representing an exchange which can be used to retrieve hosts and DHCPv4 options. More...
 
boost::shared_ptr< MySqlHostIPv6Exchange > host_ipv46_exchange_
 Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv4 and DHCPv6 options, and IPv6 reservations using a single query. More...
 
boost::shared_ptr< MySqlHostIPv6Exchange > host_ipv6_exchange_
 Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv6 options and IPv6 reservations. More...
 
boost::shared_ptr< MySqlIPv6ReservationExchange > host_ipv6_reservation_exchange_
 Pointer to an object representing an exchange which can be used to insert new IPv6 reservation. More...
 
boost::shared_ptr< MySqlOptionExchange > host_option_exchange_
 Pointer to an object representing an exchange which can be used to insert DHCPv4 or DHCPv6 option into dhcp4_options or dhcp6_options table. More...
 
bool is_readonly_
 Indicates if the database is opened in read only mode. More...
 

Static Public Attributes

static const StatementIndex WRITE_STMTS_BEGIN = INSERT_HOST
 Index of first statement performing write to the database. More...
 

Detailed Description

Implementation of the MySqlHostDataSource.

Definition at line 1930 of file mysql_host_data_source.cc.

Member Enumeration Documentation

◆ StatementIndex

Statement Tags.

The contents of the enum are indexes into the list of SQL statements. It is assumed that the order is such that the indices of statements reading the database are less than those of statements modifying the database.

Enumerator
GET_HOST_DHCPID 
GET_HOST_ADDR 
GET_HOST_SUBID4_DHCPID 
GET_HOST_SUBID6_DHCPID 
GET_HOST_SUBID_ADDR 
GET_HOST_PREFIX 
GET_HOST_SUBID6_ADDR 
INSERT_HOST 
INSERT_V6_RESRV 
INSERT_V4_OPTION 
INSERT_V6_OPTION 
DEL_HOST_ADDR4 
DEL_HOST_SUBID4_ID 
DEL_HOST_SUBID6_ID 
NUM_STATEMENTS 

Definition at line 1939 of file mysql_host_data_source.cc.

Constructor & Destructor Documentation

◆ MySqlHostDataSourceImpl()

isc::dhcp::MySqlHostDataSourceImpl::MySqlHostDataSourceImpl ( const MySqlConnection::ParameterMap &  parameters)

◆ ~MySqlHostDataSourceImpl()

isc::dhcp::MySqlHostDataSourceImpl::~MySqlHostDataSourceImpl ( )

Destructor.

Definition at line 2396 of file mysql_host_data_source.cc.

References conn_, and isc::db::MySqlConnection::statements_.

Member Function Documentation

◆ addOption()

void isc::dhcp::MySqlHostDataSourceImpl::addOption ( const MySqlHostDataSourceImpl::StatementIndex stindex,
const OptionDescriptor opt_desc,
const std::string &  opt_space,
const OptionalValue< SubnetID > &  subnet_id,
const HostID host_id 
)

Inserts a single DHCP option into the database.

Parameters
stindexIndex of a statement being executed.
opt_descOption descriptor holding information about an option to be inserted into the database.
opt_spaceOption space name.
subnet_idSubnet identifier.
host_idHost identifier.

Definition at line 2521 of file mysql_host_data_source.cc.

References addStatement(), and host_option_exchange_.

Referenced by addOptions().

+ Here is the call graph for this function:

◆ addOptions()

void isc::dhcp::MySqlHostDataSourceImpl::addOptions ( const StatementIndex stindex,
const ConstCfgOptionPtr options_cfg,
const uint64_t  host_id 
)

Inserts multiple options into the database.

Parameters
stindexIndex of a statement being executed.
options_cfgAn object holding a collection of options to be inserted into the database.
host_idHost identifier retrieved using mysql_insert_id.

Definition at line 2534 of file mysql_host_data_source.cc.

References addOption().

Referenced by isc::dhcp::MySqlHostDataSource::add().

+ Here is the call graph for this function:

◆ addResv()

void isc::dhcp::MySqlHostDataSourceImpl::addResv ( const IPv6Resrv resv,
const HostID id 
)

Inserts IPv6 Reservation into ipv6_reservation table.

Parameters
resvIPv6 Reservation to be added
idID of a host owning this reservation

Definition at line 2512 of file mysql_host_data_source.cc.

References addStatement(), host_ipv6_reservation_exchange_, and INSERT_V6_RESRV.

Referenced by isc::dhcp::MySqlHostDataSource::add().

+ Here is the call graph for this function:

◆ addStatement()

void isc::dhcp::MySqlHostDataSourceImpl::addStatement ( MySqlHostDataSourceImpl::StatementIndex  stindex,
std::vector< MYSQL_BIND > &  bind 
)

Executes statements which inserts a row into one of the tables.

Parameters
stindexIndex of a statement being executed.
bindVector of MYSQL_BIND objects to be used when making the query.
Exceptions
isc::db::DuplicateEntryDatabase throws duplicate entry error

Definition at line 2473 of file mysql_host_data_source.cc.

References checkError(), conn_, isc_throw, isc::db::MySqlConnection::mysql_, and isc::db::MySqlConnection::statements_.

Referenced by isc::dhcp::MySqlHostDataSource::add(), addOption(), and addResv().

+ Here is the call graph for this function:

◆ checkError()

void isc::dhcp::MySqlHostDataSourceImpl::checkError ( const int  status,
const StatementIndex  index,
const char *  what 
) const

Check Error and Throw Exception.

This method invokes db::MySqlConnection::checkError.

Parameters
statusStatus code: non-zero implies an error
indexIndex of statement that caused the error
whatHigh-level description of the error
Exceptions
isc::dhcp::DbOperationErrorAn operation on the open database has failed.

Definition at line 2560 of file mysql_host_data_source.cc.

References isc::db::MySqlConnection::checkError(), and conn_.

Referenced by addStatement(), delStatement(), and getHostCollection().

+ Here is the call graph for this function:

◆ checkReadOnly()

void isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly ( ) const

Throws exception if database is read only.

This method should be called by the methods which write to the database. If the backend is operating in read-only mode this method will throw exception.

Exceptions
DbReadOnlyif backend is operating in read only mode.

Definition at line 2673 of file mysql_host_data_source.cc.

References is_readonly_, and isc_throw.

Referenced by isc::dhcp::MySqlHostDataSource::add(), isc::dhcp::MySqlHostDataSource::commit(), isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::MySqlHostDataSource::del4(), isc::dhcp::MySqlHostDataSource::del6(), and isc::dhcp::MySqlHostDataSource::rollback().

◆ delStatement()

bool isc::dhcp::MySqlHostDataSourceImpl::delStatement ( StatementIndex  stindex,
MYSQL_BIND *  bind 
)

Executes statements that delete records.

Parameters
stindexIndex of a statement being executed.
bindVector of MYSQL_BIND objects to be used when making the query.
Returns
true if any records were deleted, false otherwise

Definition at line 2493 of file mysql_host_data_source.cc.

References checkError(), conn_, and isc::db::MySqlConnection::statements_.

Referenced by isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::MySqlHostDataSource::del4(), and isc::dhcp::MySqlHostDataSource::del6().

+ Here is the call graph for this function:

◆ getHost()

ConstHostPtr isc::dhcp::MySqlHostDataSourceImpl::getHost ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len,
StatementIndex  stindex,
boost::shared_ptr< MySqlHostExchange >  exchange 
) const

Retrieves a host by subnet and client's unique identifier.

This method is used by both MySqlHostDataSource::get4 and MySqlHOstDataSource::get6 methods.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
stindexStatement index.
exchangePointer to the exchange object used for the particular query.
Returns
Pointer to const instance of Host or null pointer if no host found.

Definition at line 2629 of file mysql_host_data_source.cc.

References getHostCollection(), and isc::db::MLM_TRUE.

Referenced by isc::dhcp::MySqlHostDataSource::get4(), and isc::dhcp::MySqlHostDataSource::get6().

+ Here is the call graph for this function:

◆ getHostCollection()

void isc::dhcp::MySqlHostDataSourceImpl::getHostCollection ( StatementIndex  stindex,
MYSQL_BIND *  bind,
boost::shared_ptr< MySqlHostExchange >  exchange,
ConstHostCollection result,
bool  single 
) const

Creates collection of Host objects with associated information such as IPv6 reservations and/or DHCP options.

This method performs a query which returns host information from the 'hosts' table. The query may also use LEFT JOIN clause to retrieve information from other tables, e.g. ipv6_reservations, dhcp4_options and dhcp6_options. Whether IPv6 reservations and/or options are assigned to the Host objects depends on the type of the exchange object.

Parameters
stindexStatement index.
bindPointer to an array of MySQL bindings.
exchangePointer to the exchange object used for the particular query.
[out]resultReference to the collection of hosts returned.
singleA boolean value indicating if a single host is expected to be returned, or multiple hosts.

Definition at line 2567 of file mysql_host_data_source.cc.

References checkError(), conn_, isc_throw, isc::db::MLM_MYSQL_FETCH_FAILURE, isc::db::MLM_MYSQL_FETCH_SUCCESS, isc::db::MySqlConnection::statements_, isc::db::MySqlConnection::text_statements_, and isc::Exception::what().

Referenced by isc::dhcp::MySqlHostDataSource::get4(), isc::dhcp::MySqlHostDataSource::get6(), isc::dhcp::MySqlHostDataSource::getAll(), isc::dhcp::MySqlHostDataSource::getAll4(), and getHost().

+ Here is the call graph for this function:

◆ getVersion()

std::pair< uint32_t, uint32_t > isc::dhcp::MySqlHostDataSourceImpl::getVersion ( ) const

Returns backend version.

The method is called by the constructor after opening the database but prior to preparing SQL statements, to verify that the schema version is correct. Thus it must not rely on a pre-prepared statement or formal statement execution error checking.

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

Definition at line 2412 of file mysql_host_data_source.cc.

References conn_, isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc_throw, LOG_DEBUG, and isc::db::MySqlConnection::mysql_.

Referenced by isc::dhcp::MySqlHostDataSource::getVersion(), and MySqlHostDataSourceImpl().

Member Data Documentation

◆ conn_

◆ host_exchange_

boost::shared_ptr<MySqlHostWithOptionsExchange> isc::dhcp::MySqlHostDataSourceImpl::host_exchange_

Pointer to the object representing an exchange which can be used to retrieve hosts and DHCPv4 options.

Definition at line 2104 of file mysql_host_data_source.cc.

Referenced by isc::dhcp::MySqlHostDataSource::add(), isc::dhcp::MySqlHostDataSource::get4(), and isc::dhcp::MySqlHostDataSource::getAll4().

◆ host_ipv46_exchange_

boost::shared_ptr<MySqlHostIPv6Exchange> isc::dhcp::MySqlHostDataSourceImpl::host_ipv46_exchange_

Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv4 and DHCPv6 options, and IPv6 reservations using a single query.

Definition at line 2113 of file mysql_host_data_source.cc.

Referenced by isc::dhcp::MySqlHostDataSource::getAll().

◆ host_ipv6_exchange_

boost::shared_ptr<MySqlHostIPv6Exchange> isc::dhcp::MySqlHostDataSourceImpl::host_ipv6_exchange_

Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv6 options and IPv6 reservations.

Definition at line 2108 of file mysql_host_data_source.cc.

Referenced by isc::dhcp::MySqlHostDataSource::get6().

◆ host_ipv6_reservation_exchange_

boost::shared_ptr<MySqlIPv6ReservationExchange> isc::dhcp::MySqlHostDataSourceImpl::host_ipv6_reservation_exchange_

Pointer to an object representing an exchange which can be used to insert new IPv6 reservation.

Definition at line 2117 of file mysql_host_data_source.cc.

Referenced by addResv().

◆ host_option_exchange_

boost::shared_ptr<MySqlOptionExchange> isc::dhcp::MySqlHostDataSourceImpl::host_option_exchange_

Pointer to an object representing an exchange which can be used to insert DHCPv4 or DHCPv6 option into dhcp4_options or dhcp6_options table.

Definition at line 2122 of file mysql_host_data_source.cc.

Referenced by addOption().

◆ is_readonly_

bool isc::dhcp::MySqlHostDataSourceImpl::is_readonly_

Indicates if the database is opened in read only mode.

Definition at line 2128 of file mysql_host_data_source.cc.

Referenced by checkReadOnly(), and MySqlHostDataSourceImpl().

◆ WRITE_STMTS_BEGIN

const StatementIndex isc::dhcp::MySqlHostDataSourceImpl::WRITE_STMTS_BEGIN = INSERT_HOST
static

Index of first statement performing write to the database.

This value is used to mark border line between queries and other statements and statements performing write operation on the database, such as INSERT, DELETE, UPDATE.

Definition at line 1962 of file mysql_host_data_source.cc.

Referenced by MySqlHostDataSourceImpl().


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