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

Concrete implementation of a lease database backend using flat file. More...

#include <memfile_lease_mgr.h>

+ Inheritance diagram for isc::dhcp::Memfile_LeaseMgr:

Public Types

enum  Universe { V4, V6 }
 Specifies universe (V4, V6) More...
 

Public Member Functions

virtual void commit ()
 Commit Transactions. More...
 
virtual std::string getDescription () const
 Returns description of the backend. 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...
 
Miscellaneous public convenience methods.

The following methods allow for retrieving useful information about the state of the backend.

std::string getDefaultLeaseFilePath (Universe u) const
 Returns default path to the lease file. More...
 
std::string getLeaseFilePath (Universe u) const
 Returns an absolute path to the lease file. More...
 
bool persistLeases (Universe u) const
 Specifies whether or not leases are written to disk. More...
 
Public methods to retrieve information about the LFC process state.

These methods are meant to be used by unit tests to retrieve the state of the spawned LFC process before validating the result of the lease file cleanup.

bool isLFCRunning () const
 Checks if the process performing lease file cleanup is running. More...
 
int getLFCExitStatus () const
 Returns the status code returned by the last executed LFC process. 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 Attributes

static const int MAJOR_VERSION = 2
 
static const int MINOR_VERSION = 1
 Defines minor version of the memfile backend. More...
 

Protected Member Functions

Protected methods used for Lease File Cleanup.

The following methods are protected so as they can be accessed and tested by unit tests.

virtual void lfcCallback ()
 A callback function triggering Lease File Cleanup (LFC). More...
 

Methods implementing the API of the lease database backend.

The following methods are implementing the API of the LeaseMgr to manage leases.

 Memfile_LeaseMgr (const db::DatabaseConnection::ParameterMap &parameters)
 The sole lease manager constructor. More...
 
virtual ~Memfile_LeaseMgr ()
 Destructor (closes file) More...
 
virtual bool addLease (const Lease4Ptr &lease)
 Adds an IPv4 lease. More...
 
virtual bool addLease (const Lease6Ptr &lease)
 Adds an IPv6 lease. More...
 
virtual Lease4Ptr getLease4 (const isc::asiolink::IOAddress &addr) const
 Returns existing 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 HWAddr &hwaddr, SubnetID subnet_id) const
 Returns existing IPv4 lease for specified hardware address and a subnet. More...
 
virtual Lease4Collection getLease4 (const ClientId &client_id) const
 Returns existing IPv4 lease 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 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 Lease6Ptr getLease6 (Lease::Type type, const isc::asiolink::IOAddress &addr) const
 Returns existing IPv6 lease for a given IPv6 address. More...
 
virtual Lease6Collection getLeases6 (Lease::Type type, const DUID &duid, uint32_t iaid) const
 Returns existing IPv6 lease for a given DUID + IA + lease type 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 + subnet-id + lease type 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 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 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 void updateLease4 (const Lease4Ptr &lease4)
 Updates IPv4 lease. More...
 
virtual void updateLease6 (const Lease6Ptr &lease6)
 Updates IPv6 lease. More...
 
virtual bool deleteLease (const Lease4Ptr &lease)
 Deletes an IPv4 lease. More...
 
virtual bool deleteLease (const Lease6Ptr &lease)
 Deletes an IPv6 lease. 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 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...
 
static std::string getDBVersion ()
 Local version of getDBVersion() class method. More...
 

Public type and method used to determine file names for LFC.

enum  LFCFileType {
  FILE_CURRENT, FILE_INPUT, FILE_PREVIOUS, FILE_OUTPUT,
  FILE_FINISH, FILE_PID
}
 Types of the lease files used by the Lease File Cleanup. More...
 
static std::string appendSuffix (const std::string &file_name, const LFCFileType &file_type)
 Appends appropriate suffix to the file name. More...
 

Additional Inherited Members

- 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

Concrete implementation of a lease database backend using flat file.

This class implements a lease database backend using CSV files to store DHCPv4 and DHCPv6 leases on disk. The format of the files is determined by the CSVLeaseFile4 and CSVLeaseFile6 classes.

In order to obtain good performance, the backend stores leases incrementally, i.e. updates to leases are appended at the end of the lease file. To record the deletion of a lease, the lease record is appended to the lease file with the valid lifetime set to 0. However, this may result in a significant growth of the lease file size over time, because the lease file will contain many entries for each lease. In order to mitigate this problem, the backend implements the Lease File Cleanup mechanism which is described on the Kea wiki: https://gitlab.isc.org/isc-projects/kea/wikis/designs/Lease-File-Cleanup-design.

The backend installs an asiolink::IntervalTimer to periodically execute the Memfile_LeaseMgr::lfcCallback. This callback function controls the startup of the background process which removes redundant information from the lease file(s).

When the backend is starting up, it reads leases from the lease file (one by one) and adds them to the in-memory container as follows:

  • if the lease record being parsed identifies a lease which is not present in the container, and the lease has valid lifetime greater than 0, the lease is added to the container,
  • if the lease record being parsed identifies a lease which is present in the container, and the valid lifetime of the lease record being parsed is greater than 0, the lease in the container is updated
  • if the lease record being parsed has valid lifetime equal to 0, and the corresponding lease exists in the container, the lease is removed from the container.

After the container holding leases is initialized, each subsequent update, removal or addition of the lease is appended to the lease file synchronously.

Originally, the Memfile backend didn't write leases to disk. This was particularly useful for testing server performance in non-disk bound conditions. In order to preserve this capability, the new parameter "persist=true|false" has been introduced in the database access string. For example, database access string: "type=memfile persist=true" enables writes of leases to a disk.

The lease file locations can be specified with the "name=[path]" parameter in the database access string. The [path] is the absolute path to the file (including file name). If this parameter is not specified, the default location in the installation directory is used: <install-dir>/var/lib/kea/kea-leases4.csv and <install-dir>/var/lib/kea/kea-leases6.csv.

Definition at line 79 of file memfile_lease_mgr.h.

Member Enumeration Documentation

Types of the lease files used by the Lease File Cleanup.

This enumeration is used by a method which appends the appropriate suffix to the lease file name.

Enumerator
FILE_CURRENT 

Lease File

FILE_INPUT 

Lease File Copy

FILE_PREVIOUS 

Previous Lease File.

FILE_OUTPUT 

LFC Output File.

FILE_FINISH 

LFC Finish File.

FILE_PID 

PID File.

Definition at line 849 of file memfile_lease_mgr.h.

Specifies universe (V4, V6)

This enumeration is used by various functions in Memfile Lease Manager, to identify the lease type referred to. In particular, it is used by functions operating on the lease files to distinguish between lease files for DHCPv4 and DHCPv6.

Enumerator
V4 
V6 

Definition at line 106 of file memfile_lease_mgr.h.

Constructor & Destructor Documentation

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

The sole lease manager constructor.

This method:

  • Initializes the new instance based on the parameters given
  • Loads (or creates) the appropriate lease file(s)
  • Initiates the periodic scheduling of the LFC (if enabled)

If any of the files loaded require conversion to the current schema (upgrade or downgrade), lfcSetup() will be invoked with its run_once_now parameter set to true. This causes lfcSetup() to invoke the LFC process immediately regardless of whether LFC is enabled. This ensures that any files which need conversion are converted automatically.

dbconfig is a generic way of passing parameters. Parameters are passed in the "name=value" format, separated by spaces. Values may be enclosed in double quotes, if needed.

Parameters
parametersA data structure relating keywords and values concerned with the database.

Definition at line 631 of file memfile_lease_mgr.cc.

References isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_CONVERTING_LEASE_FILES, isc::dhcp::DHCPSRV_MEMFILE_NO_STORAGE, isc::db::DatabaseConnection::getParameter(), LOG_WARN, MAJOR_VERSION, MINOR_VERSION, persistLeases(), V4, and V6.

+ Here is the call graph for this function:

isc::dhcp::Memfile_LeaseMgr::~Memfile_LeaseMgr ( )
virtual

Destructor (closes file)

Definition at line 670 of file memfile_lease_mgr.cc.

Member Function Documentation

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

Adds an IPv4 lease.

Parameters
leaselease to be added
Returns
true if the lease was added, false if not

Implements isc::dhcp::LeaseMgr.

Definition at line 713 of file memfile_lease_mgr.cc.

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

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

Adds an IPv6 lease.

Parameters
leaselease to be added
Returns
true if the lease was added, false if not

Implements isc::dhcp::LeaseMgr.

Definition at line 749 of file memfile_lease_mgr.cc.

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

std::string isc::dhcp::Memfile_LeaseMgr::appendSuffix ( const std::string &  file_name,
const LFCFileType file_type 
)
static

Appends appropriate suffix to the file name.

The suffix is selected using the LFC file type specified as a parameter. Each file type uses a unique suffix or no suffix:

  • Current File: no suffix
  • Lease File Copy or Input File: ".1"
  • Previous File: ".2"
  • LFC Output File: ".output"
  • LFC Finish File: ".completed"
  • LFC PID File: ".pid"

See https://gitlab.isc.org/isc-projects/kea/wikis/designs/Lease-File-Cleanup-design for details.

Parameters
file_nameA base file name to which suffix is appended.
file_typeAn LFC file type.
Returns
A lease file name with a suffix appended.

Definition at line 1670 of file memfile_lease_mgr.cc.

References FILE_FINISH, FILE_INPUT, FILE_OUTPUT, FILE_PID, and FILE_PREVIOUS.

Referenced by isc::dhcp::LFCSetup::setup().

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

Commit Transactions.

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

Implements isc::dhcp::LeaseMgr.

Definition at line 1659 of file memfile_lease_mgr.cc.

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

uint64_t isc::dhcp::Memfile_LeaseMgr::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 1555 of file memfile_lease_mgr.cc.

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

uint64_t isc::dhcp::Memfile_LeaseMgr::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 1573 of file memfile_lease_mgr.cc.

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

bool isc::dhcp::Memfile_LeaseMgr::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.
For test purposes only, when persistence is disabled, the deletion of the lease is performed 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 1500 of file memfile_lease_mgr.cc.

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

Referenced by wipeLeases4(), and wipeLeases6().

bool isc::dhcp::Memfile_LeaseMgr::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.
For test purposes only, when persistence is disabled, the deletion of the lease is performed 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 1542 of file memfile_lease_mgr.cc.

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

std::string isc::dhcp::Memfile_LeaseMgr::getDBVersion ( )
static

Local version of getDBVersion() class method.

Definition at line 682 of file memfile_lease_mgr.cc.

References MAJOR_VERSION, and MINOR_VERSION.

Referenced by isc::dhcp::Dhcpv6Srv::getVersion(), and isc::dhcp::Dhcpv4Srv::getVersion().

std::string isc::dhcp::Memfile_LeaseMgr::getDefaultLeaseFilePath ( Universe  u) const

Returns default path to the lease file.

Parameters
uUniverse (V4 or V6).

Definition at line 1698 of file memfile_lease_mgr.cc.

References isc::dhcp::CfgMgr::getDataDir(), isc::dhcp::CfgMgr::instance(), and V4.

+ Here is the call graph for this function:

std::string isc::dhcp::Memfile_LeaseMgr::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 1654 of file memfile_lease_mgr.cc.

void isc::dhcp::Memfile_LeaseMgr::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 1327 of file memfile_lease_mgr.cc.

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

void isc::dhcp::Memfile_LeaseMgr::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 1363 of file memfile_lease_mgr.cc.

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

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

Returns existing IPv4 lease for specified IPv4 address.

This function returns a copy of the lease. The modification in the return lease does not affect the instance held in the lease storage.

Parameters
addrAn address of the searched lease.
Returns
a pointer to the lease (or NULL if a lease is not found)

Implements isc::dhcp::LeaseMgr.

Definition at line 773 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_ADDR4, LOG_DEBUG, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

Lease4Collection isc::dhcp::Memfile_LeaseMgr::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

Implements isc::dhcp::LeaseMgr.

Definition at line 802 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_HWADDR, LOG_DEBUG, and isc::dhcp::HWAddr::toText().

+ Here is the call graph for this function:

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

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

This function returns a copy of the lease. The modification in the return lease does not affect the instance held in the lease storage.

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)

Implements isc::dhcp::LeaseMgr.

Definition at line 836 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_SUBID_HWADDR, LOG_DEBUG, and isc::dhcp::HWAddr::toText().

+ Here is the call graph for this function:

Lease4Collection isc::dhcp::Memfile_LeaseMgr::getLease4 ( const ClientId client_id) const
virtual

Returns existing IPv4 lease for specified client-id.

Parameters
client_idclient identifier
Returns
lease collection

Implements isc::dhcp::LeaseMgr.

Definition at line 867 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_CLIENTID, LOG_DEBUG, and isc::dhcp::ClientId::toText().

+ Here is the call graph for this function:

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

Returns existing IPv4 lease for specified client-id.

This function returns a copy of the lease. The modification in the return lease does not affect the instance held in the lease storage.

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)

Implements isc::dhcp::LeaseMgr.

Definition at line 900 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_SUBID_CLIENTID, LOG_DEBUG, and isc::dhcp::ClientId::toText().

+ Here is the call graph for this function:

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

Returns existing IPv6 lease for a given IPv6 address.

This function returns a copy of the lease. The modification in the return lease does not affect the instance held in the lease storage.

Parameters
typespecifies lease type: (NA, TA or PD)
addrAn address of the searched lease.
Returns
a pointer to the lease (or NULL if a lease is not found)

Implements isc::dhcp::LeaseMgr.

Definition at line 1051 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_ADDR6, LOG_DEBUG, isc::asiolink::IOAddress::toText(), and isc::dhcp::Lease::typeToText().

+ Here is the call graph for this function:

std::string isc::dhcp::Memfile_LeaseMgr::getLeaseFilePath ( Universe  u) const

Returns an absolute path to the lease file.

Parameters
uUniverse (V4 or V6).
Returns
Absolute path to the lease file or empty string if no lease file is used.

Definition at line 1707 of file memfile_lease_mgr.cc.

References V4.

Lease4Collection isc::dhcp::Memfile_LeaseMgr::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 928 of file memfile_lease_mgr.cc.

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

Lease4Collection isc::dhcp::Memfile_LeaseMgr::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 957 of file memfile_lease_mgr.cc.

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

Lease4Collection isc::dhcp::Memfile_LeaseMgr::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 980 of file memfile_lease_mgr.cc.

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

Lease4Collection isc::dhcp::Memfile_LeaseMgr::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 1015 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_PAGE4, isc_throw, isc::asiolink::IOAddress::isV4(), LOG_DEBUG, isc::dhcp::LeasePageSize::page_size_, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

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

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

Parameters
typespecifies lease type: (NA, TA or PD)
duidclient DUID
iaidIA identifier
Returns
collection of IPv6 leases

Implements isc::dhcp::LeaseMgr.

Definition at line 1085 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_IAID_DUID, LOG_DEBUG, isc::dhcp::DUID::toText(), and isc::dhcp::Lease::typeToText().

+ Here is the call graph for this function:

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

Returns existing IPv6 lease for a given DUID + IA + subnet-id + lease type combination.

This function returns a copy of the lease. The modification in the return lease does not affect the instance held in the lease storage.

Parameters
typespecifies lease type: (NA, TA or PD)
duidclient DUID
iaidIA identifier
subnet_ididentifier of the subnet the lease must belong to
Returns
lease collection (may be empty if no lease is found)

Implements isc::dhcp::LeaseMgr.

Definition at line 1128 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID, LOG_DEBUG, isc::dhcp::DUID::toText(), and isc::dhcp::Lease::typeToText().

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::Memfile_LeaseMgr::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 1164 of file memfile_lease_mgr.cc.

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

Lease6Collection isc::dhcp::Memfile_LeaseMgr::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 1193 of file memfile_lease_mgr.cc.

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

Lease6Collection isc::dhcp::Memfile_LeaseMgr::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 1216 of file memfile_lease_mgr.cc.

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

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

Returns IPv6 leases for the DUID.

Parameters
duidclient DUID

Implements isc::dhcp::LeaseMgr.

Definition at line 1244 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET6_DUID, LOG_DEBUG, and isc::dhcp::DUID::toText().

+ Here is the call graph for this function:

Lease6Collection isc::dhcp::Memfile_LeaseMgr::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 1280 of file memfile_lease_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_GET_PAGE6, isc_throw, isc::asiolink::IOAddress::isV6(), LOG_DEBUG, isc::dhcp::LeasePageSize::page_size_, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

int isc::dhcp::Memfile_LeaseMgr::getLFCExitStatus ( ) const

Returns the status code returned by the last executed LFC process.

Definition at line 1836 of file memfile_lease_mgr.cc.

virtual std::string isc::dhcp::Memfile_LeaseMgr::getName ( ) const
inlinevirtual

Returns backend name.

For now, memfile can only store data in memory.

Returns
Name of the backend.

Implements isc::dhcp::LeaseMgr.

Definition at line 809 of file memfile_lease_mgr.h.

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

Return backend type.

Returns the type of the backend.

Returns
Type of the backend.

Implements isc::dhcp::LeaseMgr.

Definition at line 800 of file memfile_lease_mgr.h.

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

Returns backend version.

Returns
Version number as a pair of unsigned integers. "first" is the major version number, "second" the minor number.

Implements isc::dhcp::LeaseMgr.

Definition at line 824 of file memfile_lease_mgr.h.

bool isc::dhcp::Memfile_LeaseMgr::isLFCRunning ( ) const

Checks if the process performing lease file cleanup is running.

Returns
true if the process performing lease file cleanup is running.

Definition at line 1831 of file memfile_lease_mgr.cc.

void isc::dhcp::Memfile_LeaseMgr::lfcCallback ( )
protectedvirtual

A callback function triggering Lease File Cleanup (LFC).

This method is executed periodically to start the lease file cleanup. It checks whether the file is a DHCPv4 lease file or DHCPv6 lease file and executes the Memfile_LeaseMgr::lfcExecute private method with the appropriate parameters.

This method is virtual so as it can be overridden and customized in the unit tests. In particular, the unit test which checks that the callback function has been executed would override this function to increase the execution counter each time it is executed.

Definition at line 1841 of file memfile_lease_mgr.cc.

References isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_LFC_START, and LOG_INFO.

bool isc::dhcp::Memfile_LeaseMgr::persistLeases ( Universe  u) const

Specifies whether or not leases are written to disk.

It is possible that leases for DHCPv4 are written to disk whereas leases for DHCPv6 are not; or vice versa. The argument of the method specifies the type of lease in that respect.

Parameters
uUniverse (V4 or V6).
Returns
true if leases are written to lease file; if false is returned, leases will be held in memory and will be lost upon server shut down.

Definition at line 1716 of file memfile_lease_mgr.cc.

References V4, and V6.

Referenced by Memfile_LeaseMgr().

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

Rollback Transactions.

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

Implements isc::dhcp::LeaseMgr.

Definition at line 1664 of file memfile_lease_mgr.cc.

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

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

Creates and runs the IPv4 lease stats query.

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

Returns
The populated query as a pointer to an LeaseStatsQuery

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 1939 of file memfile_lease_mgr.cc.

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

Creates and runs the IPv6 lease stats query.

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

Returns
The populated query as a pointer to an LeaseStatsQuery.

Reimplemented from isc::dhcp::LeaseMgr.

Definition at line 1962 of file memfile_lease_mgr.cc.

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

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

It creates an instance of a MemfileLeaseStatsQuery4 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 1946 of file memfile_lease_mgr.cc.

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

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

It creates an instance of a MemfileLeaseStatsQuery6 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 1969 of file memfile_lease_mgr.cc.

LeaseStatsQueryPtr isc::dhcp::Memfile_LeaseMgr::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 MemfileLeaseStatsQuery4 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 1953 of file memfile_lease_mgr.cc.

LeaseStatsQueryPtr isc::dhcp::Memfile_LeaseMgr::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 MemfileLeaseStatsQuery6 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 1976 of file memfile_lease_mgr.cc.

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

Updates IPv4 lease.

Warning
This function does not validate the pointer to the lease. It is caller's responsibility to pass the valid pointer.
Parameters
lease4The lease to be updated.
Exceptions
NoSuchLeaseif there is no such lease to be updated.
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.
For test purposes only, when persistence is disabled, the update of the lease is performed 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 1411 of file memfile_lease_mgr.cc.

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

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

Updates IPv6 lease.

Warning
This function does not validate the pointer to the lease. It is caller's responsibility to pass the valid pointer.
Parameters
lease6The lease to be updated.
Exceptions
NoSuchLeaseif there is no such lease to be updated.
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.
For test purposes only, when persistence is disabled, the update of the lease is performed 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 1458 of file memfile_lease_mgr.cc.

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

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

Removes specified IPv4 leases.

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

Parameters
subnet_ididentifier of the subnet
Returns
number of leases removed.

Implements isc::dhcp::LeaseMgr.

Definition at line 1985 of file memfile_lease_mgr.cc.

References deleteLease(), isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_WIPE_LEASES4, isc::dhcp::DHCPSRV_MEMFILE_WIPE_LEASES4_FINISHED, and LOG_INFO.

+ Here is the call graph for this function:

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

Removed specified IPv6 leases.

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

Parameters
subnet_ididentifier of the subnet
Returns
number of leases removed.

Implements isc::dhcp::LeaseMgr.

Definition at line 2014 of file memfile_lease_mgr.cc.

References deleteLease(), isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_WIPE_LEASES6, isc::dhcp::DHCPSRV_MEMFILE_WIPE_LEASES6_FINISHED, and LOG_INFO.

+ Here is the call graph for this function:


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