7#ifndef PGSQL_LEASE_MGR_H
8#define PGSQL_LEASE_MGR_H
17#include <boost/scoped_ptr.hpp>
18#include <boost/utility.hpp>
28class PgSqlLease4Exchange;
29class PgSqlLease6Exchange;
76 std::vector<PgSqlLeaseContextPtr>
pool_;
338 uint32_t iaid)
const;
354 uint32_t iaid,
SubnetID subnet_id)
const;
421 const size_t max_leases)
const;
434 const size_t max_leases)
const;
622 return (std::string(
"postgresql"));
630 virtual std::string
getName()
const;
646 virtual std::pair<uint32_t, uint32_t>
getVersion()
const;
748 template <
typename Exchange,
typename LeaseCollection>
752 Exchange& exchange, LeaseCollection& result,
753 bool single =
false)
const;
776 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange4_, result);
799 getLeaseCollection(ctx, stindex, bind_array, ctx->exchange6_, result);
814 db::PsqlBindArray& bind_array,
829 db::PsqlBindArray& bind_array,
846 template<
typename LeaseCollection>
847 void getExpiredLeasesCommon(LeaseCollection& expired_leases,
848 const size_t max_leases,
867 template <
typename LeasePtr>
870 db::PsqlBindArray& bind_array,
888 db::PsqlBindArray& bind_array);
899 uint64_t deleteExpiredReclaimedLeasesCommon(
const uint32_t secs,
903 class PgSqlLeaseContextAlloc {
917 ~PgSqlLeaseContextAlloc();
939 std::string timer_name_;
The IOAddress class represents an IP addresses (version agnostic)
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Common PgSql Connector Pool.
Holds Client identifier or client IPv4 address.
Holds DUID (DHCPv6 Unique Identifier)
Wraps value holding size of the page with leases.
PostgreSQL Lease Context Pool.
std::vector< PgSqlLeaseContextPtr > pool_
The vector of available contexts.
std::mutex mutex_
The mutex to protect pool access.
PostgreSQL Lease Context.
PgSqlLeaseContext(const db::DatabaseConnection::ParameterMap ¶meters, db::IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback)
Constructor.
boost::scoped_ptr< PgSqlLease4Exchange > exchange4_
The exchange objects are used for transfer of data to/from the database.
db::PgSqlConnection conn_
PostgreSQL connection.
boost::scoped_ptr< PgSqlLease6Exchange > exchange6_
Exchange object.
PostgreSQL Lease Manager.
virtual std::string getName() const
Returns backend name.
virtual std::string getType() const
Return backend type.
virtual bool addLease(const Lease4Ptr &lease)
Adds an IPv4 lease.
virtual Lease6Collection getLeases6() const
Returns all IPv6 leases.
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.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const
Returns an IPv4 lease for specified IPv4 address.
virtual void rollback()
Rollback Transactions.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const
Returns existing IPv6 lease for a given IPv6 address.
PgSqlLeaseContextPtr createContext() const
Create a new context.
virtual bool deleteLease(const Lease4Ptr &lease)
Deletes an IPv4 lease.
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.
static std::string getDBVersion()
Local version of getDBVersion() class method.
virtual Lease4Collection getLeases4() const
Returns all IPv4 leases.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs)
Deletes all expired-reclaimed DHCPv4 leases.
virtual void updateLease4(const Lease4Ptr &lease4)
Updates IPv4 lease.
virtual size_t wipeLeases4(const SubnetID &subnet_id)
Removes specified IPv4 leases.
virtual std::pair< uint32_t, uint32_t > getVersion() const
Returns backend version.
virtual void updateLease6(const Lease6Ptr &lease6)
Updates IPv6 lease.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs)
Deletes all expired-reclaimed DHCPv6 leases.
virtual std::string getDescription() const
Returns description of the backend.
StatementIndex
Statement Tags.
@ SUBNET_RANGE_LEASE4_STATS
@ SUBNET_RANGE_LEASE6_STATS
@ GET_LEASE6_DUID_IAID_SUBID
@ GET_LEASE4_HWADDR_SUBID
@ GET_LEASE4_CLIENTID_SUBID
@ DELETE_LEASE6_STATE_EXPIRED
@ DELETE_LEASE4_STATE_EXPIRED
virtual void commit()
Commit Transactions.
PgSqlLeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
Constructor.
virtual size_t wipeLeases6(const SubnetID &subnet_id)
Removed specified IPv6 leases.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv6 leases.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query.
static bool dbReconnect(db::ReconnectCtlPtr db_reconnect_ctl)
Attempts to reconnect the server to the lease DB backend manager.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
virtual ~PgSqlLeaseMgr()
Destructor (closes database)
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv4 leases.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
An abstract API for lease database.
std::function< bool(ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
boost::shared_ptr< PgSqlLeaseContext > PgSqlLeaseContextPtr
Type of pointers to contexts.
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
boost::shared_ptr< PgSqlLeaseContextPool > PgSqlLeaseContextPoolPtr
Type of pointers to context pools.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Defines the logger used by the top-level component of kea-lfc.
Hardware type that represents information from DHCPv4 packet.
Type
Type of lease or pool.