Kea  1.9.9-git
isc::dhcp::PgSqlLeaseMgr Class Reference

PostgreSQL Lease Manager. More...

#include <pgsql_lease_mgr.h>

+ Inheritance diagram for isc::dhcp::PgSqlLeaseMgr:

Public Types

enum  StatementIndex {
  DELETE_LEASE4, DELETE_LEASE4_STATE_EXPIRED, DELETE_LEASE6, DELETE_LEASE6_STATE_EXPIRED,
  GET_LEASE4, GET_LEASE4_ADDR, GET_LEASE4_CLIENTID, GET_LEASE4_CLIENTID_SUBID,
  GET_LEASE4_HWADDR, GET_LEASE4_HWADDR_SUBID, GET_LEASE4_PAGE, GET_LEASE4_SUBID,
  GET_LEASE4_HOSTNAME, GET_LEASE4_EXPIRE, GET_LEASE6, GET_LEASE6_ADDR,
  GET_LEASE6_DUID_IAID, GET_LEASE6_DUID_IAID_SUBID, GET_LEASE6_PAGE, GET_LEASE6_SUBID,
  GET_LEASE6_DUID, GET_LEASE6_HOSTNAME, GET_LEASE6_EXPIRE, INSERT_LEASE4,
  INSERT_LEASE6, UPDATE_LEASE4, UPDATE_LEASE6, ALL_LEASE4_STATS,
  SUBNET_LEASE4_STATS, SUBNET_RANGE_LEASE4_STATS, ALL_LEASE6_STATS, SUBNET_LEASE6_STATS,
  SUBNET_RANGE_LEASE6_STATS, NUM_STATEMENTS
}
 Statement Tags. More...
 

Public Member Functions

 PgSqlLeaseMgr (const db::DatabaseConnection::ParameterMap &parameters)
 Constructor. More...
 
virtual ~PgSqlLeaseMgr ()
 Destructor (closes database) More...
 
virtual bool addLease (const Lease4Ptr &lease)
 Adds an IPv4 lease. More...
 
virtual bool addLease (const Lease6Ptr &lease)
 Adds an IPv6 lease. More...
 
virtual void commit ()
 Commit Transactions. More...
 
PgSqlLeaseContextPtr createContext () const
 Create a new context. More...
 
virtual uint64_t deleteExpiredReclaimedLeases4 (const uint32_t secs)
 Deletes all expired-reclaimed DHCPv4 leases. More...
 
virtual uint64_t deleteExpiredReclaimedLeases6 (const uint32_t secs)
 Deletes all expired-reclaimed DHCPv6 leases. More...
 
virtual bool deleteLease (const Lease4Ptr &lease)
 Deletes an IPv4 lease. More...
 
virtual bool deleteLease (const Lease6Ptr &lease)
 Deletes an IPv6 lease. More...
 
virtual std::string getDescription () const
 Returns description of the backend. More...
 
virtual void getExpiredLeases4 (Lease4Collection &expired_leases, const size_t max_leases) const
 Returns a collection of expired DHCPv4 leases. More...
 
virtual void getExpiredLeases6 (Lease6Collection &expired_leases, const size_t max_leases) const
 Returns a collection of expired DHCPv6 leases. More...
 
virtual Lease4Ptr getLease4 (const isc::asiolink::IOAddress &addr) const
 Returns an IPv4 lease for specified IPv4 address. More...
 
virtual Lease4Collection getLease4 (const isc::dhcp::HWAddr &hwaddr) const
 Returns existing IPv4 leases for specified hardware address. More...
 
virtual Lease4Ptr getLease4 (const isc::dhcp::HWAddr &hwaddr, SubnetID subnet_id) const
 Returns existing IPv4 leases for specified hardware address and a subnet. More...
 
virtual Lease4Collection getLease4 (const ClientId &clientid) const
 Returns existing IPv4 leases for specified client-id. More...
 
virtual Lease4Ptr getLease4 (const ClientId &clientid, SubnetID subnet_id) const
 Returns existing IPv4 lease for specified client-id. More...
 
virtual Lease6Ptr getLease6 (Lease::Type type, const isc::asiolink::IOAddress &addr) const
 Returns existing IPv6 lease for a given IPv6 address. More...
 
virtual Lease4Collection getLeases4 (SubnetID subnet_id) const
 Returns all IPv4 leases for the particular subnet identifier. More...
 
virtual Lease4Collection getLeases4 (const std::string &hostname) const
 Returns all IPv4 leases for the particular hostname. More...
 
virtual Lease4Collection getLeases4 () const
 Returns all IPv4 leases. More...
 
virtual Lease4Collection getLeases4 (const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) const
 Returns range of IPv4 leases using paging. More...
 
virtual Lease6Collection getLeases6 (Lease::Type type, const DUID &duid, uint32_t iaid) const
 Returns existing IPv6 leases for a given DUID+IA combination. More...
 
virtual Lease6Collection getLeases6 (Lease::Type type, const DUID &duid, uint32_t iaid, SubnetID subnet_id) const
 Returns existing IPv6 lease for a given DUID+IA combination. More...
 
virtual Lease6Collection getLeases6 (SubnetID subnet_id) const
 Returns all IPv6 leases for the particular subnet identifier. More...
 
virtual Lease6Collection getLeases6 (const std::string &hostname) const
 Returns all IPv6 leases for the particular hostname. More...
 
virtual Lease6Collection getLeases6 () const
 Returns all IPv6 leases. More...
 
virtual Lease6Collection getLeases6 (const DUID &duid) const
 Returns all IPv6 leases for the DUID. More...
 
virtual Lease6Collection getLeases6 (const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) const
 Returns range of IPv6 leases using paging. More...
 
virtual std::string getName () const
 Returns backend name. More...
 
virtual std::string getType () const
 Return backend type. More...
 
virtual std::pair< uint32_t, uint32_t > getVersion () const
 Returns backend version. More...
 
virtual void rollback ()
 Rollback Transactions. More...
 
virtual LeaseStatsQueryPtr startLeaseStatsQuery4 ()
 Creates and runs the IPv4 lease stats query. More...
 
virtual LeaseStatsQueryPtr startLeaseStatsQuery6 ()
 Creates and runs the IPv6 lease stats query. More...
 
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4 (const SubnetID &subnet_id)
 Creates and runs the IPv4 lease stats query for a single subnet. More...
 
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6 (const SubnetID &subnet_id)
 Creates and runs the IPv6 lease stats query for a single subnet. More...
 
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4 (const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
 Creates and runs the IPv4 lease stats query for a single subnet. More...
 
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6 (const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
 Creates and runs the IPv6 lease stats query for a single subnet. More...
 
virtual void updateLease4 (const Lease4Ptr &lease4)
 Updates IPv4 lease. More...
 
virtual void updateLease6 (const Lease6Ptr &lease6)
 Updates IPv6 lease. More...
 
virtual size_t wipeLeases4 (const SubnetID &subnet_id)
 Removes specified IPv4 leases. More...
 
virtual size_t wipeLeases6 (const SubnetID &subnet_id)
 Removed specified IPv6 leases. More...
 
- Public Member Functions inherited from isc::dhcp::LeaseMgr
 LeaseMgr ()
 Constructor. More...
 
virtual ~LeaseMgr ()
 Destructor. More...
 
Lease6Ptr getLease6 (Lease::Type type, const DUID &duid, uint32_t iaid, SubnetID subnet_id) const
 returns zero or one IPv6 lease for a given duid+iaid+subnet_id More...
 
void recountLeaseStats4 ()
 Recalculates per-subnet and global stats for IPv4 leases. More...
 
void recountLeaseStats6 ()
 Recalculates per-subnet and global stats for IPv6 leases. More...
 

Static Public Member Functions

static bool dbReconnect (db::ReconnectCtlPtr db_reconnect_ctl)
 Attempts to reconnect the server to the lease DB backend manager. More...
 
static std::string getDBVersion ()
 Local version of getDBVersion() class method. More...
 
- Static Public Member Functions inherited from isc::dhcp::LeaseMgr
static std::string getDBVersion ()
 Class method to return extended version info This class method must be redeclared and redefined in derived classes. More...
 
static isc::asiolink::IOServicePtrgetIOService ()
 Returns pointer to the IO service. More...
 
static void setIOService (const isc::asiolink::IOServicePtr &io_service)
 Sets IO service to be used by the Lease Manager. More...
 

Detailed Description

PostgreSQL Lease Manager.

This class provides the isc::dhcp::LeaseMgr interface to the PostgreSQL database. Use of this backend presupposes that a PostgreSQL database is available and that the Kea schema has been created within it.

Definition at line 91 of file pgsql_lease_mgr.h.

Member Enumeration Documentation

Statement Tags.

The contents of the enum are indexes into the list of compiled SQL statements

Enumerator
DELETE_LEASE4 
DELETE_LEASE4_STATE_EXPIRED 
DELETE_LEASE6 
DELETE_LEASE6_STATE_EXPIRED 
GET_LEASE4 
GET_LEASE4_ADDR 
GET_LEASE4_CLIENTID 
GET_LEASE4_CLIENTID_SUBID 
GET_LEASE4_HWADDR 
GET_LEASE4_HWADDR_SUBID 
GET_LEASE4_PAGE 
GET_LEASE4_SUBID 
GET_LEASE4_HOSTNAME 
GET_LEASE4_EXPIRE 
GET_LEASE6 
GET_LEASE6_ADDR 
GET_LEASE6_DUID_IAID 
GET_LEASE6_DUID_IAID_SUBID 
GET_LEASE6_PAGE 
GET_LEASE6_SUBID 
GET_LEASE6_DUID 
GET_LEASE6_HOSTNAME 
GET_LEASE6_EXPIRE 
INSERT_LEASE4 
INSERT_LEASE6 
UPDATE_LEASE4 
UPDATE_LEASE6 
ALL_LEASE4_STATS 
SUBNET_LEASE4_STATS 
SUBNET_RANGE_LEASE4_STATS 
ALL_LEASE6_STATS 
SUBNET_LEASE6_STATS 
SUBNET_RANGE_LEASE6_STATS 
NUM_STATEMENTS 

Definition at line 668 of file pgsql_lease_mgr.h.

Constructor & Destructor Documentation

isc::dhcp::PgSqlLeaseMgr::PgSqlLeaseMgr ( const db::DatabaseConnection::ParameterMap parameters)

Constructor.

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

  • name - Name of the database to which to connect (mandatory)
  • host - Host to which to connect (optional, defaults to "localhost")
  • user - Username under which to connect (optional)
  • password - Password for "user" on the database (optional)

Check the schema version and create an initial context.

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

Definition at line 1217 of file pgsql_lease_mgr.cc.

References createContext(), getVersion(), isc_throw, isc::db::PG_SCHEMA_VERSION_MAJOR, and isc::db::PG_SCHEMA_VERSION_MINOR.

+ Here is the call graph for this function:

isc::dhcp::PgSqlLeaseMgr::~PgSqlLeaseMgr ( )
virtual

Destructor (closes database)

Definition at line 1242 of file pgsql_lease_mgr.cc.

Member Function Documentation

bool isc::dhcp::PgSqlLeaseMgr::addLease ( const Lease4Ptr lease)
virtual

Adds an IPv4 lease.

Parameters
leaselease to be added
Returns
true if the lease was added, false if not (because a lease with the same address was already there).
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1382 of file pgsql_lease_mgr.cc.

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

bool isc::dhcp::PgSqlLeaseMgr::addLease ( const Lease6Ptr lease)
virtual

Adds an IPv6 lease.

Parameters
leaselease to be added
Returns
true if the lease was added, false if not (because a lease with the same address was already there).
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1402 of file pgsql_lease_mgr.cc.

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

void isc::dhcp::PgSqlLeaseMgr::commit ( )
virtual

Commit Transactions.

Commits all pending database operations. On databases that don't support transactions, this is a no-op.

PostgreSQL supports transactions but this manager does not use them.

Implements isc::dhcp::LeaseMgr.

Definition at line 2348 of file pgsql_lease_mgr.cc.

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

PgSqlLeaseContextPtr isc::dhcp::PgSqlLeaseMgr::createContext ( ) const

Create a new context.

The database is opened with all the SQL commands pre-compiled.

Returns
A new (never null) context.
Exceptions
isc::dhcp::NoDatabaseNameMandatory database name not given.
isc::db::DbOperationErrorAn operation on the open database has failed.

Definition at line 1316 of file pgsql_lease_mgr.cc.

References dbReconnect(), isc::dhcp::LeaseMgr::getIOService(), isc_throw, and NUM_STATEMENTS.

Referenced by PgSqlLeaseMgr().

+ Here is the call graph for this function:

bool isc::dhcp::PgSqlLeaseMgr::dbReconnect ( db::ReconnectCtlPtr  db_reconnect_ctl)
static

Attempts to reconnect the server to the lease DB backend manager.

This is a self-rescheduling function that attempts to reconnect to the server's lease DB backends after connectivity to one or more have been lost. Upon entry it will attempt to reconnect via LeaseMgrFactory::create. If this is successful, DHCP servicing is re-enabled and server returns to normal operation.

If reconnection fails and the maximum number of retries has not been exhausted, it will schedule a call to itself to occur at the configured retry interval. DHCP service remains disabled.

If the maximum number of retries has been exhausted an error is logged and the server shuts down.

This function is passed to the connection recovery mechanism. It will be invoked when a connection loss is detected.

Parameters
db_reconnect_ctlpointer to the ReconnectCtl containing the configured reconnect parameters.
Returns
true if connection has been recovered, false otherwise.

Definition at line 1246 of file pgsql_lease_mgr.cc.

References isc::dhcp::LeaseMgrFactory::create(), isc::dhcp::LeaseMgrFactory::destroy(), isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED, isc::dhcp::DHCPSRV_PGSQL_LEASE_DB_RECONNECT_ATTEMPT_SCHEDULE, isc::dhcp::DHCPSRV_PGSQL_LEASE_DB_RECONNECT_FAILED, isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::TimerMgr::instance(), isc::dhcp::CfgMgr::instance(), isc::db::DatabaseConnection::invokeDbFailedCallback(), isc::db::DatabaseConnection::invokeDbLostCallback(), isc::db::DatabaseConnection::invokeDbRecoveredCallback(), LOG_ERROR, LOG_INFO, and isc::asiolink::IntervalTimer::ONE_SHOT.

Referenced by createContext().

+ Here is the call graph for this function:

uint64_t isc::dhcp::PgSqlLeaseMgr::deleteExpiredReclaimedLeases4 ( const uint32_t  secs)
virtual

Deletes all expired-reclaimed DHCPv4 leases.

Parameters
secsNumber of seconds since expiration of leases before they can be removed. Leases which have expired later than this time will not be deleted.
Returns
Number of leases deleted.

Implements isc::dhcp::LeaseMgr.

Definition at line 2193 of file pgsql_lease_mgr.cc.

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

uint64_t isc::dhcp::PgSqlLeaseMgr::deleteExpiredReclaimedLeases6 ( const uint32_t  secs)
virtual

Deletes all expired-reclaimed DHCPv6 leases.

Parameters
secsNumber of seconds since expiration of leases before they can be removed. Leases which have expired later than this time will not be deleted.
Returns
Number of leases deleted.

Implements isc::dhcp::LeaseMgr.

Definition at line 2200 of file pgsql_lease_mgr.cc.

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

bool isc::dhcp::PgSqlLeaseMgr::deleteLease ( const Lease4Ptr lease)
virtual

Deletes an IPv4 lease.

Parameters
leaseIPv4 lease being deleted.
Returns
true if deletion was successful, false if no such lease exists.
Note
The current_cltt_ and current_valid_lft_ are used to maximize the chance that only one thread or process performs an update or delete operation on the lease by matching these values with the expiration time data in the database.
The DELETE query uses WHERE expire = ? to delete the lease only if the value matches the one received on the SELECT query, effectively enforcing no update on the lease between SELECT and DELETE with different expiration time.

Implements isc::dhcp::LeaseMgr.

Definition at line 2124 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::db::PgSqlExchange::convertToDatabaseTime(), DELETE_LEASE4, isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_DELETE_ADDR, isc_throw, LOG_DEBUG, isc::asiolink::IOAddress::toText(), and isc::asiolink::IOAddress::toUint32().

+ Here is the call graph for this function:

bool isc::dhcp::PgSqlLeaseMgr::deleteLease ( const Lease6Ptr lease)
virtual

Deletes an IPv6 lease.

Parameters
leaseIPv6 lease being deleted.
Returns
true if deletion was successful, false if no such lease exists.
Note
The current_cltt_ and current_valid_lft_ are used to maximize the chance that only one thread or process performs an update or delete operation on the lease by matching these values with the expiration time data in the database.
The DELETE query uses WHERE expire = ? to delete the lease only if the value matches the one received on the SELECT query, effectively enforcing no update on the lease between SELECT and DELETE with different expiration time.

Implements isc::dhcp::LeaseMgr.

Definition at line 2158 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::db::PgSqlExchange::convertToDatabaseTime(), DELETE_LEASE6, isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_DELETE_ADDR, isc_throw, LOG_DEBUG, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

std::string isc::dhcp::PgSqlLeaseMgr::getDBVersion ( )
static
std::string isc::dhcp::PgSqlLeaseMgr::getDescription ( ) const
virtual

Returns description of the backend.

This description may be multiline text that describes the backend.

Returns
Description of the backend.

Implements isc::dhcp::LeaseMgr.

Definition at line 2336 of file pgsql_lease_mgr.cc.

void isc::dhcp::PgSqlLeaseMgr::getExpiredLeases4 ( Lease4Collection expired_leases,
const size_t  max_leases 
) const
virtual

Returns a collection of expired DHCPv4 leases.

This method returns at most max_leases expired leases. The leases returned haven't been reclaimed, i.e. the database query must exclude reclaimed leases from the results returned.

Parameters
[out]expired_leasesA container to which expired leases returned by the database backend are added.
max_leasesA maximum number of leases to be returned. If this value is set to 0, all expired (but not reclaimed) leases are returned.

Implements isc::dhcp::LeaseMgr.

Definition at line 1965 of file pgsql_lease_mgr.cc.

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

void isc::dhcp::PgSqlLeaseMgr::getExpiredLeases6 ( Lease6Collection expired_leases,
const size_t  max_leases 
) const
virtual

Returns a collection of expired DHCPv6 leases.

This method returns at most max_leases expired leases. The leases returned haven't been reclaimed, i.e. the database query must exclude reclaimed leases from the results returned.

Parameters
[out]expired_leasesA container to which expired leases returned by the database backend are added.
max_leasesA maximum number of leases to be returned. If this value is set to 0, all expired (but not reclaimed) leases are returned.

Implements isc::dhcp::LeaseMgr.

Definition at line 1973 of file pgsql_lease_mgr.cc.

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

Lease4Ptr isc::dhcp::PgSqlLeaseMgr::getLease4 ( const isc::asiolink::IOAddress addr) const
virtual

Returns an IPv4 lease for specified IPv4 address.

This method return a lease that is associated with a given address. For other query types (by hardware addr, by Client ID) there can be several leases in different subnets (e.g. for mobile clients that got address in different subnets). However, for a single address there can be only one lease, so this method returns a pointer to a single lease, not a container of leases.

Parameters
addraddress of the searched lease
Returns
smart pointer to the lease (or NULL if a lease is not found)
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1495 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_ADDR4, GET_LEASE4_ADDR, LOG_DEBUG, isc::asiolink::IOAddress::toText(), and isc::asiolink::IOAddress::toUint32().

+ Here is the call graph for this function:

Lease4Collection isc::dhcp::PgSqlLeaseMgr::getLease4 ( const isc::dhcp::HWAddr hwaddr) const
virtual

Returns existing IPv4 leases for specified hardware address.

Although in the usual case there will be only one lease, for mobile clients or clients with multiple static/fixed/reserved leases there can be more than one. Thus return type is a container, not a single pointer.

Parameters
hwaddrhardware address of the client
Returns
lease collection
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1519 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_HWADDR, GET_LEASE4_HWADDR, isc::dhcp::HWAddr::hwaddr_, LOG_DEBUG, and isc::dhcp::HWAddr::toText().

+ Here is the call graph for this function:

Lease4Ptr isc::dhcp::PgSqlLeaseMgr::getLease4 ( const isc::dhcp::HWAddr hwaddr,
SubnetID  subnet_id 
) const
virtual

Returns existing IPv4 leases for specified hardware address and a subnet.

There can be at most one lease for a given HW address in a single pool, so this method with either return a single lease or NULL.

Parameters
hwaddrhardware address of the client
subnet_ididentifier of the subnet that lease must belong to
Returns
a pointer to the lease (or NULL if a lease is not found)
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1546 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_SUBID_HWADDR, GET_LEASE4_HWADDR_SUBID, isc::dhcp::HWAddr::hwaddr_, LOG_DEBUG, and isc::dhcp::HWAddr::toText().

+ Here is the call graph for this function:

Lease4Collection isc::dhcp::PgSqlLeaseMgr::getLease4 ( const ClientId clientid) const
virtual

Returns existing IPv4 leases for specified client-id.

Although in the usual case there will be only one lease, for mobile clients or clients with multiple static/fixed/reserved leases there can be more than one. Thus return type is a container, not a single pointer.

Parameters
clientidclient identifier
Returns
lease collection
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1578 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_CLIENTID, GET_LEASE4_CLIENTID, isc::dhcp::ClientId::getClientId(), LOG_DEBUG, and isc::dhcp::ClientId::toText().

+ Here is the call graph for this function:

Lease4Ptr isc::dhcp::PgSqlLeaseMgr::getLease4 ( const ClientId clientid,
SubnetID  subnet_id 
) const
virtual

Returns existing IPv4 lease for specified client-id.

There can be at most one lease for a given HW address in a single pool, so this method with either return a single lease or NULL.

Parameters
clientidclient identifier
subnet_ididentifier of the subnet that lease must belong to
Returns
a pointer to the lease (or NULL if a lease is not found)
Exceptions
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1601 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_SUBID_CLIENTID, GET_LEASE4_CLIENTID_SUBID, isc::dhcp::ClientId::getClientId(), LOG_DEBUG, and isc::dhcp::ClientId::toText().

+ Here is the call graph for this function:

Lease6Ptr isc::dhcp::PgSqlLeaseMgr::getLease6 ( Lease::Type  type,
const isc::asiolink::IOAddress addr 
) const
virtual

Returns existing IPv6 lease for a given IPv6 address.

For a given address, we assume that there will be only one lease. The assumption here is that there will not be site or link-local addresses used, so there is no way of having address duplication.

Parameters
typespecifies lease type: (NA, TA or PD)
addraddress of the searched lease
Returns
smart pointer to the lease (or NULL if a lease is not found)
Exceptions
isc::BadValuerecord retrieved from database had an invalid lease type field.
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1731 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_ADDR6, GET_LEASE6_ADDR, LOG_DEBUG, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

Lease4Collection isc::dhcp::PgSqlLeaseMgr::getLeases4 ( SubnetID  subnet_id) const
virtual

Returns all IPv4 leases for the particular subnet identifier.

Parameters
subnet_idsubnet identifier.
Returns
Lease collection (may be empty if no IPv4 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1629 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_SUBID4, GET_LEASE4_SUBID, and LOG_DEBUG.

+ Here is the call graph for this function:

Lease4Collection isc::dhcp::PgSqlLeaseMgr::getLeases4 ( const std::string &  hostname) const
virtual

Returns all IPv4 leases for the particular hostname.

Parameters
hostnamehostname in lower case.
Returns
Lease collection (may be empty if no IPv4 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1653 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_HOSTNAME4, GET_LEASE4_HOSTNAME, and LOG_DEBUG.

+ Here is the call graph for this function:

Lease4Collection isc::dhcp::PgSqlLeaseMgr::getLeases4 ( ) const
virtual

Returns all IPv4 leases.

Returns
Lease collection (may be empty if no IPv4 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1676 of file pgsql_lease_mgr.cc.

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

Lease4Collection isc::dhcp::PgSqlLeaseMgr::getLeases4 ( const asiolink::IOAddress lower_bound_address,
const LeasePageSize page_size 
) const
virtual

Returns range of IPv4 leases using paging.

This method implements paged browsing of the lease database. The first parameter specifies a page size. The second parameter is optional and specifies the starting address of the range. This address is excluded from the returned range. The IPv4 zero address (default) denotes that the first page should be returned. There is no guarantee about the order of returned leases.

The typical usage of this method is as follows:

  • Get the first page of leases by specifying IPv4 zero address as the beginning of the range.
  • Last address of the returned range should be used as a starting address for the next page in the subsequent call.
  • If the number of leases returned is lower than the page size, it indicates that the last page has been retrieved.
  • If there are no leases returned it indicates that the previous page was the last page.
Parameters
lower_bound_addressIPv4 address used as lower bound for the returned range.
page_sizemaximum size of the page returned.
Returns
Lease collection (may be empty if no IPv4 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1694 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_PAGE4, GET_LEASE4_PAGE, isc_throw, isc::asiolink::IOAddress::isV4(), LOG_DEBUG, isc::dhcp::LeasePageSize::page_size_, isc::asiolink::IOAddress::toText(), and isc::asiolink::IOAddress::toUint32().

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::PgSqlLeaseMgr::getLeases6 ( Lease::Type  type,
const DUID duid,
uint32_t  iaid 
) const
virtual

Returns existing IPv6 leases for a given DUID+IA combination.

Although in the usual case there will be only one lease, for mobile clients or clients with multiple static/fixed/reserved leases there can be more than one. Thus return type is a container, not a single pointer.

Parameters
typespecifies lease type: (NA, TA or PD)
duidclient DUID
iaidIA identifier
Returns
smart pointer to the lease (or NULL if a lease is not found)
Exceptions
isc::BadValuerecord retrieved from database had an invalid lease type field.
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1761 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::PgSqlLease6Exchange::Uiaid::dbInputString(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_IAID_DUID, GET_LEASE6_DUID_IAID, isc::dhcp::DUID::getDuid(), LOG_DEBUG, and isc::dhcp::DUID::toText().

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::PgSqlLeaseMgr::getLeases6 ( Lease::Type  type,
const DUID duid,
uint32_t  iaid,
SubnetID  subnet_id 
) const
virtual

Returns existing IPv6 lease for a given DUID+IA combination.

Parameters
typespecifies lease type: (NA, TA or PD)
duidclient DUID
iaidIA identifier
subnet_idsubnet id of the subnet the lease belongs to
Returns
lease collection (may be empty if no lease is found)
Exceptions
isc::BadValuerecord retrieved from database had an invalid lease type field.
isc::db::DbOperationErrorAn operation on the open database has failed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1795 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::PgSqlLease6Exchange::Uiaid::dbInputString(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_IAID_SUBID_DUID, GET_LEASE6_DUID_IAID_SUBID, isc::dhcp::DUID::getDuid(), LOG_DEBUG, and isc::dhcp::DUID::toText().

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::PgSqlLeaseMgr::getLeases6 ( SubnetID  subnet_id) const
virtual

Returns all IPv6 leases for the particular subnet identifier.

Parameters
subnet_idsubnet identifier.
Returns
Lease collection (may be empty if no IPv6 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1834 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_SUBID6, GET_LEASE6_SUBID, and LOG_DEBUG.

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::PgSqlLeaseMgr::getLeases6 ( const std::string &  hostname) const
virtual

Returns all IPv6 leases for the particular hostname.

Parameters
hostnamehostname in lower case.
Returns
Lease collection (may be empty if no IPv6 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1880 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_HOSTNAME6, GET_LEASE6_HOSTNAME, and LOG_DEBUG.

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::PgSqlLeaseMgr::getLeases6 ( ) const
virtual

Returns all IPv6 leases.

Returns
Lease collection (may be empty if no IPv6 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1903 of file pgsql_lease_mgr.cc.

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

Lease6Collection isc::dhcp::PgSqlLeaseMgr::getLeases6 ( const DUID duid) const
virtual

Returns all IPv6 leases for the DUID.

Todo:
: implement an optimised of the query using index.
Returns
Lease collection (may be empty if no IPv6 lease found) for the DUID.

Implements isc::dhcp::LeaseMgr.

Definition at line 1858 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_DUID, GET_LEASE6_DUID, isc::dhcp::DUID::getDuid(), LOG_DEBUG, and isc::dhcp::DUID::toText().

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::PgSqlLeaseMgr::getLeases6 ( const asiolink::IOAddress lower_bound_address,
const LeasePageSize page_size 
) const
virtual

Returns range of IPv6 leases using paging.

This method implements paged browsing of the lease database. The first parameter specifies a page size. The second parameter is optional and specifies the starting address of the range. This address is excluded from the returned range. The IPv6 zero address (default) denotes that the first page should be returned. There is no guarantee about the order of returned leases.

The typical usage of this method is as follows:

  • Get the first page of leases by specifying IPv6 zero address as the beginning of the range.
  • Last address of the returned range should be used as a starting address for the next page in the subsequent call.
  • If the number of leases returned is lower than the page size, it indicates that the last page has been retrieved.
  • If there are no leases returned it indicates that the previous page was the last page.
Parameters
lower_bound_addressIPv6 address used as lower bound for the returned range.
page_sizemaximum size of the page returned.
Returns
Lease collection (may be empty if no IPv6 lease found).

Implements isc::dhcp::LeaseMgr.

Definition at line 1921 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_PAGE6, GET_LEASE6_PAGE, isc_throw, isc::asiolink::IOAddress::isV6(), isc::asiolink::IOAddress::isV6Zero(), LOG_DEBUG, isc::dhcp::LeasePageSize::page_size_, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

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

Returns backend name.

Each backend have specific name.

Returns
Name of the backend.

Implements isc::dhcp::LeaseMgr.

Definition at line 2321 of file pgsql_lease_mgr.cc.

virtual std::string isc::dhcp::PgSqlLeaseMgr::getType ( ) const
inlinevirtual

Return backend type.

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

Returns
Type of the backend.

Implements isc::dhcp::LeaseMgr.

Definition at line 621 of file pgsql_lease_mgr.h.

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

Returns backend version.

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

Implements isc::dhcp::LeaseMgr.

Definition at line 2341 of file pgsql_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_GET_VERSION, isc::db::PgSqlConnection::getVersion(), and LOG_DEBUG.

Referenced by PgSqlLeaseMgr().

+ Here is the call graph for this function:

void isc::dhcp::PgSqlLeaseMgr::rollback ( )
virtual

Rollback Transactions.

Rolls back all pending database operations. On databases that don't support transactions, this is a no-op.

PostgreSQL supports transactions but this manager does not use them.

Implements isc::dhcp::LeaseMgr.

Definition at line 2353 of file pgsql_lease_mgr.cc.

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

LeaseStatsQueryPtr isc::dhcp::PgSqlLeaseMgr::startLeaseStatsQuery4 ( )
virtual

Creates and runs the IPv4 lease stats query.

It creates an instance of a PgSqlLeaseStatsQuery4 and then invokes its start method, which fetches its statistical data result set by executing the ALL_LEASE_STATS4 query. The query object is then returned.

Returns
The populated query as a pointer to an LeaseStatsQuery

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 2225 of file pgsql_lease_mgr.cc.

References ALL_LEASE4_STATS.

LeaseStatsQueryPtr isc::dhcp::PgSqlLeaseMgr::startLeaseStatsQuery6 ( )
virtual

Creates and runs the IPv6 lease stats query.

It creates an instance of a PgSqlLeaseStatsQuery and then invokes its start method, which fetches its statistical data result set by executing the ALL_LEASE_STATS6 query. The query object is then returned.

Returns
The populated query as a pointer to an LeaseStatsQuery

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 2268 of file pgsql_lease_mgr.cc.

References ALL_LEASE6_STATS.

LeaseStatsQueryPtr isc::dhcp::PgSqlLeaseMgr::startSubnetLeaseStatsQuery4 ( const SubnetID subnet_id)
virtual

Creates and runs the IPv4 lease stats query for a single subnet.

It creates an instance of a PgSqlLeaseStatsQuery4 for a single subnet query and then invokes its start method in which the query constructs its statistical data result set. The query object is then returned.

Parameters
subnet_idid of the subnet for which stats are desired
Returns
A populated LeaseStatsQuery

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 2238 of file pgsql_lease_mgr.cc.

References SUBNET_LEASE4_STATS.

LeaseStatsQueryPtr isc::dhcp::PgSqlLeaseMgr::startSubnetLeaseStatsQuery6 ( const SubnetID subnet_id)
virtual

Creates and runs the IPv6 lease stats query for a single subnet.

It creates an instance of a PgSqlLeaseStatsQuery6 for a single subnet query and then invokes its start method in which the query constructs its statistical data result set. The query object is then returned.

Parameters
subnet_idid of the subnet for which stats are desired
Returns
A populated LeaseStatsQuery

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 2281 of file pgsql_lease_mgr.cc.

References SUBNET_LEASE6_STATS.

LeaseStatsQueryPtr isc::dhcp::PgSqlLeaseMgr::startSubnetRangeLeaseStatsQuery4 ( const SubnetID first_subnet_id,
const SubnetID last_subnet_id 
)
virtual

Creates and runs the IPv4 lease stats query for a single subnet.

It creates an instance of a PgSqlLeaseStatsQuery4 for a subnet range query and then invokes its start method in which the query constructs its statistical data result set. The query object is then returned.

Parameters
first_subnet_idfirst subnet in the range of subnets
last_subnet_idlast subnet in the range of subnets
Returns
A populated LeaseStatsQuery

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 2252 of file pgsql_lease_mgr.cc.

References SUBNET_RANGE_LEASE4_STATS.

LeaseStatsQueryPtr isc::dhcp::PgSqlLeaseMgr::startSubnetRangeLeaseStatsQuery6 ( const SubnetID first_subnet_id,
const SubnetID last_subnet_id 
)
virtual

Creates and runs the IPv6 lease stats query for a single subnet.

It creates an instance of a PgSqlLeaseStatsQuery6 for a subnet range query and then invokes its start method in which the query constructs its statistical data result set. The query object is then returned.

Parameters
first_subnet_idfirst subnet in the range of subnets
last_subnet_idlast subnet in the range of subnets
Returns
A populated LeaseStatsQuery

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 2295 of file pgsql_lease_mgr.cc.

References SUBNET_RANGE_LEASE6_STATS.

void isc::dhcp::PgSqlLeaseMgr::updateLease4 ( const Lease4Ptr lease4)
virtual

Updates IPv4 lease.

Updates the record of the lease in the database (as identified by the address) with the data in the passed lease object.

Parameters
lease4The lease to be updated.
Exceptions
isc::dhcp::NoSuchLeaseAttempt to update a lease that did not exist.
isc::db::DbOperationErrorAn operation on the open database has failed.
Note
The current_cltt_ and current_valid_lft_ are used to maximize the chance that only one thread or process performs an update or delete operation on the lease by matching these values with the expiration time data in the database.
The UPDATE query uses WHERE expire = ? to update the lease only if the value matches the one received on the SELECT query, effectively enforcing no update on the lease between SELECT and UPDATE with different expiration time.

Implements isc::dhcp::LeaseMgr.

Definition at line 2044 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::db::PgSqlExchange::convertToDatabaseTime(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_UPDATE_ADDR4, LOG_DEBUG, and UPDATE_LEASE4.

+ Here is the call graph for this function:

void isc::dhcp::PgSqlLeaseMgr::updateLease6 ( const Lease6Ptr lease6)
virtual

Updates IPv6 lease.

Updates the record of the lease in the database (as identified by the address) with the data in the passed lease object.

Parameters
lease6The lease to be updated.
Exceptions
isc::dhcp::NoSuchLeaseAttempt to update a lease that did not exist.
isc::db::DbOperationErrorAn operation on the open database has failed.
Note
The current_cltt_ and current_valid_lft_ are used to maximize the chance that only one thread or process performs an update or delete operation on the lease by matching these values with the expiration time data in the database.
The UPDATE query uses WHERE expire = ? to update the lease only if the value matches the one received on the SELECT query, effectively enforcing no update on the lease between SELECT and UPDATE with different expiration time.

Implements isc::dhcp::LeaseMgr.

Definition at line 2074 of file pgsql_lease_mgr.cc.

References isc::db::PsqlBindArray::add(), isc::db::PgSqlExchange::convertToDatabaseTime(), isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_PGSQL_UPDATE_ADDR6, LOG_DEBUG, isc::db::PsqlBindArray::toText(), and UPDATE_LEASE6.

+ Here is the call graph for this function:

size_t isc::dhcp::PgSqlLeaseMgr::wipeLeases4 ( const SubnetID subnet_id)
virtual

Removes specified IPv4 leases.

This rather dangerous method is able to remove all leases from specified subnet.

Todo:
: Not implemented yet.
Parameters
subnet_ididentifier of the subnet
Returns
number of leases removed.

Implements isc::dhcp::LeaseMgr.

Definition at line 2311 of file pgsql_lease_mgr.cc.

References isc_throw.

size_t isc::dhcp::PgSqlLeaseMgr::wipeLeases6 ( const SubnetID subnet_id)
virtual

Removed specified IPv6 leases.

This rather dangerous method is able to remove all leases from specified subnet.

Todo:
: Not implemented yet.
Parameters
subnet_ididentifier of the subnet
Returns
number of leases removed.

Implements isc::dhcp::LeaseMgr.

Definition at line 2316 of file pgsql_lease_mgr.cc.

References isc_throw.


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