mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 15:35:17 +00:00
[2404] Tidying up and refactoring the code
This commit is contained in:
@@ -31,13 +31,13 @@ using namespace std;
|
|||||||
|
|
||||||
using namespace isc::dhcp;
|
using namespace isc::dhcp;
|
||||||
|
|
||||||
Lease6::Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
|
Lease6::Lease6(LeaseType type, const isc::asiolink::IOAddress& addr,
|
||||||
uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
|
DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
|
||||||
uint32_t t2, SubnetID subnet_id, uint8_t prefixlen)
|
uint32_t t1, uint32_t t2, SubnetID subnet_id, uint8_t prefixlen)
|
||||||
:type_(type), addr_(addr), prefixlen_(prefixlen), iaid_(iaid), duid_(duid),
|
: addr_(addr), type_(type), prefixlen_(prefixlen), iaid_(iaid), duid_(duid),
|
||||||
preferred_lft_(preferred), valid_lft_(valid), t1_(t1), t2_(t2),
|
preferred_lft_(preferred), valid_lft_(valid), t1_(t1), t2_(t2),
|
||||||
subnet_id_(subnet_id), fixed_(false), fqdn_fwd_(false),
|
subnet_id_(subnet_id), fixed_(false), fqdn_fwd_(false),
|
||||||
fqdn_rev_(false) {
|
fqdn_rev_(false) {
|
||||||
if (!duid) {
|
if (!duid) {
|
||||||
isc_throw(InvalidOperation, "DUID must be specified for a lease");
|
isc_throw(InvalidOperation, "DUID must be specified for a lease");
|
||||||
}
|
}
|
||||||
|
@@ -87,6 +87,13 @@ public:
|
|||||||
isc::Exception(file, line, what) {}
|
isc::Exception(file, line, what) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief Multiple lease records found where one expected
|
||||||
|
class MultipleRecords : public Exception {
|
||||||
|
public:
|
||||||
|
MultipleRecords(const char* file, size_t line, const char* what) :
|
||||||
|
isc::Exception(file, line, what) {}
|
||||||
|
};
|
||||||
|
|
||||||
/// @brief Attempt to update lease that was not there
|
/// @brief Attempt to update lease that was not there
|
||||||
class NoSuchLease : public Exception {
|
class NoSuchLease : public Exception {
|
||||||
public:
|
public:
|
||||||
@@ -101,6 +108,7 @@ public:
|
|||||||
/// would be required. As this is a critical part of the code that will be used
|
/// would be required. As this is a critical part of the code that will be used
|
||||||
/// extensively, direct access is warranted.
|
/// extensively, direct access is warranted.
|
||||||
struct Lease4 {
|
struct Lease4 {
|
||||||
|
|
||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
///
|
///
|
||||||
/// @param addr IPv4 address as unsigned 32-bit integer in network byte
|
/// @param addr IPv4 address as unsigned 32-bit integer in network byte
|
||||||
@@ -133,69 +141,78 @@ struct Lease4 {
|
|||||||
|
|
||||||
/// @brief Address extension
|
/// @brief Address extension
|
||||||
///
|
///
|
||||||
/// It is envisaged that in some cases IPv4 address will be accompanied with some
|
/// It is envisaged that in some cases IPv4 address will be accompanied
|
||||||
/// additional data. One example of such use are Address + Port solutions (or
|
/// with some additional data. One example of such use are Address + Port
|
||||||
/// Port-restricted Addresses), where several clients may get the same address, but
|
/// solutions (or Port-restricted Addresses), where several clients may get
|
||||||
/// different port ranges. This feature is not expected to be widely used.
|
/// the same address, but different port ranges. This feature is not
|
||||||
/// Under normal circumstances, the value should be 0.
|
/// expected to be widely used. Under normal circumstances, the value
|
||||||
|
/// should be 0.
|
||||||
uint32_t ext_;
|
uint32_t ext_;
|
||||||
|
|
||||||
/// @brief hardware address
|
/// @brief Hardware address
|
||||||
std::vector<uint8_t> hwaddr_;
|
std::vector<uint8_t> hwaddr_;
|
||||||
|
|
||||||
/// @brief client identifier
|
/// @brief Client identifier
|
||||||
|
///
|
||||||
|
/// @todo Should this be a pointer to a client ID or the ID itself?
|
||||||
|
/// Compare with the DUID in the Lease6 structure.
|
||||||
boost::shared_ptr<ClientId> client_id_;
|
boost::shared_ptr<ClientId> client_id_;
|
||||||
|
|
||||||
/// @brief renewal timer
|
/// @brief Renewal timer
|
||||||
///
|
///
|
||||||
/// Specifies renewal time. Although technically it is a property of IA container,
|
/// Specifies renewal time. Although technically it is a property of the
|
||||||
/// not the address itself, since our data model does not define separate IA
|
/// IA container and not the address itself, since our data model does not
|
||||||
/// entity, we are keeping it in the lease. In case of multiple addresses/prefixes
|
/// define a separate IA entity, we are keeping it in the lease. In the
|
||||||
/// for the same IA, each must have consistent T1 and T2 values. Specified in
|
/// case of multiple addresses/prefixes for the same IA, each must have
|
||||||
/// seconds since cltt.
|
/// consistent T1 and T2 values. This is specified in seconds since cltt.
|
||||||
uint32_t t1_;
|
uint32_t t1_;
|
||||||
|
|
||||||
/// @brief rebinding timer
|
/// @brief Rebinding timer
|
||||||
///
|
///
|
||||||
/// Specifies rebinding time. Although technically it is a property of IA container,
|
/// Specifies rebinding time. Although technically it is a property of the
|
||||||
/// not the address itself, since our data model does not define separate IA
|
/// IA container and not the address itself, since our data model does not
|
||||||
/// entity, we are keeping it in the lease. In case of multiple addresses/prefixes
|
/// define a separate IA entity, we are keeping it in the lease. In the
|
||||||
/// for the same IA, each must have consistent T1 and T2 values. Specified in
|
/// case of multiple addresses/prefixes for the same IA, each must have
|
||||||
/// seconds since cltt.
|
/// consistent T1 and T2 values. This is pecified in seconds since cltt.
|
||||||
uint32_t t2_;
|
uint32_t t2_;
|
||||||
|
|
||||||
/// @brief valid lifetime
|
/// @brief Ralid lifetime
|
||||||
///
|
///
|
||||||
/// Expressed as number of seconds since cltt
|
/// Expressed as number of seconds since cltt.
|
||||||
uint32_t valid_lft_;
|
uint32_t valid_lft_;
|
||||||
|
|
||||||
/// @brief client last transmission time
|
/// @brief Client last transmission time
|
||||||
///
|
///
|
||||||
/// Specifies a timestamp, when last transmission from a client was received.
|
/// Specifies a timestamp giving the time when the last transmission from a
|
||||||
|
/// client was received.
|
||||||
time_t cltt_;
|
time_t cltt_;
|
||||||
|
|
||||||
/// @brief Subnet identifier
|
/// @brief Subnet identifier
|
||||||
///
|
///
|
||||||
/// Specifies subnet-id of the subnet that the lease belongs to
|
/// Specifies the identification of the subnet to which the lease belongs.
|
||||||
SubnetID subnet_id_;
|
SubnetID subnet_id_;
|
||||||
|
|
||||||
/// @brief Is this a fixed lease?
|
/// @brief Fixed lease?
|
||||||
///
|
///
|
||||||
/// Fixed leases are kept after they are released/expired.
|
/// Fixed leases are kept after they are released/expired.
|
||||||
bool fixed_;
|
bool fixed_;
|
||||||
|
|
||||||
/// @brief client hostname
|
/// @brief Client hostname
|
||||||
///
|
///
|
||||||
/// This field may be empty
|
/// This field may be empty
|
||||||
std::string hostname_;
|
std::string hostname_;
|
||||||
|
|
||||||
/// @brief did we update AAAA record for this lease?
|
/// @brief Forward zone updated?
|
||||||
|
///
|
||||||
|
/// Set true if the DNS AAAA record for this lease has been updated.
|
||||||
bool fqdn_fwd_;
|
bool fqdn_fwd_;
|
||||||
|
|
||||||
/// @brief did we update PTR record for this lease?
|
/// @brief Reverse zone updated?
|
||||||
|
///
|
||||||
|
/// Set true if the DNS PTR record for this lease has been updated.
|
||||||
bool fqdn_rev_;
|
bool fqdn_rev_;
|
||||||
|
|
||||||
/// @brief Lease comments.
|
/// @brief Lease comments
|
||||||
///
|
///
|
||||||
/// Currently not used. It may be used for keeping comments made by the
|
/// Currently not used. It may be used for keeping comments made by the
|
||||||
/// system administrator.
|
/// system administrator.
|
||||||
@@ -210,13 +227,16 @@ typedef boost::shared_ptr<Lease4> Lease4Ptr;
|
|||||||
/// @brief A collection of IPv4 leases.
|
/// @brief A collection of IPv4 leases.
|
||||||
typedef std::vector<Lease4Ptr> Lease4Collection;
|
typedef std::vector<Lease4Ptr> Lease4Collection;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief Structure that holds a lease for IPv6 address and/or prefix
|
/// @brief Structure that holds a lease for IPv6 address and/or prefix
|
||||||
///
|
///
|
||||||
/// For performance reasons it is a simple structure, not a class. Had we chose to
|
/// For performance reasons it is a simple structure, not a class. If we chose
|
||||||
/// make it a class, all fields would have to be made private and getters/setters
|
/// make it a class, all fields would have to made private and getters/setters
|
||||||
/// would be required. As this is a critical part of the code that will be used
|
/// would be required. As this is a critical part of the code that will be used
|
||||||
/// extensively, direct access rather than through getters/setters is warranted.
|
|
||||||
struct Lease6 {
|
struct Lease6 {
|
||||||
|
|
||||||
|
/// @brief Type of lease contents
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LEASE_IA_NA, /// the lease contains non-temporary IPv6 address
|
LEASE_IA_NA, /// the lease contains non-temporary IPv6 address
|
||||||
LEASE_IA_TA, /// the lease contains temporary IPv6 address
|
LEASE_IA_TA, /// the lease contains temporary IPv6 address
|
||||||
@@ -228,86 +248,96 @@ struct Lease6 {
|
|||||||
uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
|
uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
|
||||||
uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0);
|
uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0);
|
||||||
|
|
||||||
/// @brief specifies lease type (normal addr, temporary addr, prefix)
|
/// @brief IPv6 address
|
||||||
LeaseType type_;
|
|
||||||
|
|
||||||
/// IPv6 address
|
|
||||||
isc::asiolink::IOAddress addr_;
|
isc::asiolink::IOAddress addr_;
|
||||||
|
|
||||||
/// IPv6 prefix length (used only for PD)
|
/// @brief Lease type
|
||||||
|
///
|
||||||
|
/// One of normal address, temporary address, or prefix.
|
||||||
|
LeaseType type_;
|
||||||
|
|
||||||
|
/// @brief IPv6 prefix length
|
||||||
|
///
|
||||||
|
/// This is used only for prefix delegations and is ignored otherwise.
|
||||||
uint8_t prefixlen_;
|
uint8_t prefixlen_;
|
||||||
|
|
||||||
/// @brief IAID
|
/// @brief Identity Association Identifier (IAID)
|
||||||
///
|
///
|
||||||
/// Identity Association IDentifier. DHCPv6 stores all addresses and prefixes
|
/// DHCPv6 stores all addresses and prefixes in IA containers (IA_NA,
|
||||||
/// in IA containers (IA_NA, IA_TA, IA_PD). Most containers may appear more
|
/// IA_TA, IA_PD). Most containers may appear more than once in a message.
|
||||||
/// than once in a message. To differentiate between them, IAID field is present
|
/// To differentiate between them, the IAID field is present
|
||||||
uint32_t iaid_;
|
uint32_t iaid_;
|
||||||
|
|
||||||
/// @brief client identifier
|
/// @brief Client identifier
|
||||||
boost::shared_ptr<DUID> duid_;
|
boost::shared_ptr<DUID> duid_;
|
||||||
|
|
||||||
/// @brief preferred lifetime
|
/// @brief preferred lifetime
|
||||||
///
|
///
|
||||||
/// This parameter specifies preferred lifetime since the lease was assigned/renewed
|
/// This parameter specifies the preferred lifetime since the lease was
|
||||||
/// (cltt), expressed in seconds.
|
/// assigned or renewed (cltt), expressed in seconds.
|
||||||
uint32_t preferred_lft_;
|
uint32_t preferred_lft_;
|
||||||
|
|
||||||
/// @brief valid lifetime
|
/// @brief valid lifetime
|
||||||
///
|
///
|
||||||
/// This parameter specified valid lifetime since the lease was assigned/renewed
|
/// This parameter specifies the valid lifetime since the lease waa
|
||||||
/// (cltt), expressed in seconds.
|
/// assigned/renewed (cltt), expressed in seconds.
|
||||||
uint32_t valid_lft_;
|
uint32_t valid_lft_;
|
||||||
|
|
||||||
/// @brief T1 timer
|
/// @brief T1 timer
|
||||||
///
|
///
|
||||||
/// Specifies renewal time. Although technically it is a property of IA container,
|
/// Specifies renewal time. Although technically it is a property of the
|
||||||
/// not the address itself, since our data model does not define separate IA
|
/// IA container and not the address itself, since our data model does not
|
||||||
/// entity, we are keeping it in the lease. In case of multiple addresses/prefixes
|
/// define a separate IA entity, we are keeping it in the lease. In the
|
||||||
/// for the same IA, each must have consistent T1 and T2 values. Specified in
|
/// case of multiple addresses/prefixes for the same IA, each must have
|
||||||
/// seconds since cltt.
|
/// consistent T1 and T2 values. This is specified in seconds since cltt.
|
||||||
/// This value will also be useful for failover to calculate the next expected
|
/// The value will also be useful for failover to calculate the next
|
||||||
/// client transmission time.
|
/// expected client transmission time.
|
||||||
uint32_t t1_;
|
uint32_t t1_;
|
||||||
|
|
||||||
/// @brief T2 timer
|
/// @brief T2 timer
|
||||||
///
|
///
|
||||||
/// Specifies rebinding time. Although technically it is a property of IA container,
|
/// Specifies rebinding time. Although technically it is a property of the
|
||||||
/// not the address itself, since our data model does not define separate IA
|
/// IA container and not the address itself, since our data model does not
|
||||||
/// entity, we are keeping it in the lease. In case of multiple addresses/prefixes
|
/// define a separate IA entity, we are keeping it in the lease. In the
|
||||||
/// for the same IA, each must have consistent T1 and T2 values. Specified in
|
/// case of multiple addresses/prefixes for the same IA, each must have
|
||||||
/// seconds since cltt.
|
/// consistent T1 and T2 values. This is specified in seconds since cltt.
|
||||||
uint32_t t2_;
|
uint32_t t2_;
|
||||||
|
|
||||||
/// @brief client last transmission time
|
/// @brief Client last transmission time
|
||||||
///
|
///
|
||||||
/// Specifies a timestamp, when last transmission from a client was received.
|
/// Specifies a timestamp giving the time when the last transmission from a
|
||||||
|
/// client was received.
|
||||||
time_t cltt_;
|
time_t cltt_;
|
||||||
|
|
||||||
/// @brief Subnet identifier
|
/// @brief Subnet identifier
|
||||||
///
|
///
|
||||||
/// Specifies subnet-id of the subnet that the lease belongs to
|
/// Specifies the identification of the subnet to which the lease belongs.
|
||||||
SubnetID subnet_id_;
|
SubnetID subnet_id_;
|
||||||
|
|
||||||
/// @brief Is this a fixed lease?
|
/// @brief Fixed lease?
|
||||||
///
|
///
|
||||||
/// Fixed leases are kept after they are released/expired.
|
/// Fixed leases are kept after they are released/expired.
|
||||||
bool fixed_;
|
bool fixed_;
|
||||||
|
|
||||||
/// @brief client hostname
|
/// @brief Client hostname
|
||||||
///
|
///
|
||||||
/// This field may be empty
|
/// This field may be empty
|
||||||
std::string hostname_;
|
std::string hostname_;
|
||||||
|
|
||||||
/// @brief did we update AAAA record for this lease?
|
/// @brief Forward zone updated?
|
||||||
|
///
|
||||||
|
/// Set true if the DNS AAAA record for this lease has been updated.
|
||||||
bool fqdn_fwd_;
|
bool fqdn_fwd_;
|
||||||
|
|
||||||
/// @brief did we update PTR record for this lease?
|
/// @brief Reverse zone updated?
|
||||||
|
///
|
||||||
|
/// Set true if the DNS PTR record for this lease has been updated.
|
||||||
bool fqdn_rev_;
|
bool fqdn_rev_;
|
||||||
|
|
||||||
/// @brief Lease comments
|
/// @brief Lease comments
|
||||||
///
|
///
|
||||||
/// This field is currently not used.
|
/// Currently not used. It may be used for keeping comments made by the
|
||||||
|
/// system administrator.
|
||||||
std::string comments_;
|
std::string comments_;
|
||||||
|
|
||||||
/// @todo: Add DHCPv6 failover related fields here
|
/// @todo: Add DHCPv6 failover related fields here
|
||||||
@@ -357,7 +387,7 @@ typedef std::vector<Lease6Ptr> Lease6Collection;
|
|||||||
/// see the documentation of those classes for details.
|
/// see the documentation of those classes for details.
|
||||||
class LeaseMgr {
|
class LeaseMgr {
|
||||||
public:
|
public:
|
||||||
/// Client Hardware address
|
/// Client hardware address
|
||||||
typedef std::vector<uint8_t> HWAddr;
|
typedef std::vector<uint8_t> HWAddr;
|
||||||
|
|
||||||
/// Database configuration parameter map
|
/// Database configuration parameter map
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@ namespace dhcp {
|
|||||||
// Define the current database schema values
|
// Define the current database schema values
|
||||||
|
|
||||||
const uint32_t CURRENT_VERSION_VERSION = 0;
|
const uint32_t CURRENT_VERSION_VERSION = 0;
|
||||||
const uint32_t CURRENT_VERSION_MINOR = 1;
|
const uint32_t CURRENT_VERSION_MINOR = 2;
|
||||||
|
|
||||||
|
|
||||||
// Forward declaration of the Lease exchange objects. This class is defined
|
// Forward declaration of the Lease exchange objects. This class is defined
|
||||||
@@ -69,7 +69,7 @@ public:
|
|||||||
/// @brief Destructor (closes database)
|
/// @brief Destructor (closes database)
|
||||||
virtual ~MySqlLeaseMgr();
|
virtual ~MySqlLeaseMgr();
|
||||||
|
|
||||||
/// @brief Adds an IPv4 lease.
|
/// @brief Adds an IPv4 lease
|
||||||
///
|
///
|
||||||
/// @param lease lease to be added
|
/// @param lease lease to be added
|
||||||
///
|
///
|
||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
/// failed.
|
/// failed.
|
||||||
virtual bool addLease(const Lease4Ptr& lease);
|
virtual bool addLease(const Lease4Ptr& lease);
|
||||||
|
|
||||||
/// @brief Adds an IPv6 lease.
|
/// @brief Adds an IPv6 lease
|
||||||
///
|
///
|
||||||
/// @param lease lease to be added
|
/// @param lease lease to be added
|
||||||
///
|
///
|
||||||
@@ -210,13 +210,22 @@ public:
|
|||||||
|
|
||||||
/// @brief Updates IPv4 lease.
|
/// @brief 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.
|
||||||
|
///
|
||||||
/// @param lease4 The lease to be updated.
|
/// @param lease4 The lease to be updated.
|
||||||
///
|
///
|
||||||
/// If no such lease is present, an exception will be thrown.
|
/// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
|
||||||
|
/// exist.
|
||||||
|
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||||
|
/// failed.
|
||||||
virtual void updateLease4(const Lease4Ptr& lease4);
|
virtual void updateLease4(const Lease4Ptr& lease4);
|
||||||
|
|
||||||
/// @brief Updates IPv6 lease.
|
/// @brief 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.
|
||||||
|
///
|
||||||
/// @param lease6 The lease to be updated.
|
/// @param lease6 The lease to be updated.
|
||||||
///
|
///
|
||||||
/// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
|
/// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
|
||||||
@@ -234,6 +243,9 @@ public:
|
|||||||
/// @param addr IPv4 address of the lease to be deleted.
|
/// @param addr IPv4 address of the lease to be deleted.
|
||||||
///
|
///
|
||||||
/// @return true if deletion was successful, false if no such lease exists
|
/// @return true if deletion was successful, false if no such lease exists
|
||||||
|
///
|
||||||
|
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||||
|
/// failed.
|
||||||
virtual bool deleteLease4(const isc::asiolink::IOAddress& addr);
|
virtual bool deleteLease4(const isc::asiolink::IOAddress& addr);
|
||||||
|
|
||||||
/// @brief Deletes an IPv6 lease.
|
/// @brief Deletes an IPv6 lease.
|
||||||
@@ -409,7 +421,8 @@ private:
|
|||||||
/// @brief Add Lease Common Code
|
/// @brief Add Lease Common Code
|
||||||
///
|
///
|
||||||
/// This method performs the common actions for both flavours of the
|
/// This method performs the common actions for both flavours of the
|
||||||
/// addLease method.
|
/// addLease method. It binds the contents of the lease object to
|
||||||
|
/// the prepated statement and adds it to the database.
|
||||||
///
|
///
|
||||||
/// @param stindex Index of statemnent being executed
|
/// @param stindex Index of statemnent being executed
|
||||||
/// @param bind MYSQL_BIND array that has been created for the type
|
/// @param bind MYSQL_BIND array that has been created for the type
|
||||||
@@ -422,33 +435,6 @@ private:
|
|||||||
/// failed.
|
/// failed.
|
||||||
bool addLease(StatementIndex stindex, std::vector<MYSQL_BIND>& bind);
|
bool addLease(StatementIndex stindex, std::vector<MYSQL_BIND>& bind);
|
||||||
|
|
||||||
/// @brief Get Lease Common Code
|
|
||||||
///
|
|
||||||
/// This method performs the common actions for obtaining a single lease
|
|
||||||
/// from the database.
|
|
||||||
///
|
|
||||||
/// @param stindex Index of statement being executed
|
|
||||||
/// @param inbind MYSQL_BIND array for input parameters
|
|
||||||
/// @param exchange Exchange object to use
|
|
||||||
/// @param lease Lease object returned
|
|
||||||
template <typename Exchange, typename LeasePtr>
|
|
||||||
void getLease(StatementIndex stindex, MYSQL_BIND* inbind,
|
|
||||||
Exchange& exchange, LeasePtr& result) const;
|
|
||||||
|
|
||||||
/// @brief Get Lease Collection Common Code
|
|
||||||
///
|
|
||||||
/// This method performs the common actions for obtaining multiple leases
|
|
||||||
/// from the database.
|
|
||||||
///
|
|
||||||
/// @param stindex Index of statement being executed
|
|
||||||
/// @param inbind MYSQL_BIND array for input parameters
|
|
||||||
/// @param exchange Exchange object to use
|
|
||||||
/// @param lease LeaseCollection object returned. Note that any data in
|
|
||||||
/// the collection is cleared before new data is added.
|
|
||||||
template <typename Exchange, typename LeaseCollection>
|
|
||||||
void getLeaseCollection(StatementIndex stindex, MYSQL_BIND* inbind,
|
|
||||||
Exchange& exchange, LeaseCollection& result) const;
|
|
||||||
|
|
||||||
/// @brief Binds Parameters and Executes
|
/// @brief Binds Parameters and Executes
|
||||||
///
|
///
|
||||||
/// This method abstracts a lot of common processing from the getXxxx()
|
/// This method abstracts a lot of common processing from the getXxxx()
|
||||||
@@ -472,6 +458,132 @@ private:
|
|||||||
void bindAndExecute(StatementIndex stindex, Exchange& exchange,
|
void bindAndExecute(StatementIndex stindex, Exchange& exchange,
|
||||||
MYSQL_BIND* inbind) const;
|
MYSQL_BIND* inbind) const;
|
||||||
|
|
||||||
|
/// @brief Get Lease Collection Common Code
|
||||||
|
///
|
||||||
|
/// This method performs the common actions for obtaining multiple leases
|
||||||
|
/// from the database.
|
||||||
|
///
|
||||||
|
/// @param stindex Index of statement being executed
|
||||||
|
/// @param inbind MYSQL_BIND array for input parameters
|
||||||
|
/// @param exchange Exchange object to use
|
||||||
|
/// @param lease LeaseCollection object returned. Note that any data in
|
||||||
|
/// the collection is cleared before new data is added.
|
||||||
|
/// @param single If true, only a single data item is to be retrieved.
|
||||||
|
/// If more than one is present, a MultipleRecords exception will
|
||||||
|
/// be thrown.
|
||||||
|
///
|
||||||
|
/// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
|
||||||
|
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||||
|
/// failed.
|
||||||
|
/// @throw isc::dhcp::MultipleRecords Multiple records were retrieved
|
||||||
|
/// from the database where only one was expected.
|
||||||
|
template <typename Exchange, typename LeaseCollection>
|
||||||
|
void getLeaseCollection(StatementIndex stindex, MYSQL_BIND* inbind,
|
||||||
|
Exchange& exchange, LeaseCollection& result,
|
||||||
|
bool single = false) const;
|
||||||
|
|
||||||
|
/// @brief Get Lease Collection
|
||||||
|
///
|
||||||
|
/// Gets a collection of Lease4 objects. This is just an interface to
|
||||||
|
/// the get lease collection common code.
|
||||||
|
///
|
||||||
|
/// @param stindex Index of statement being executed
|
||||||
|
/// @param inbind MYSQL_BIND array for input parameters
|
||||||
|
/// @param lease LeaseCollection object returned. Note that any data in
|
||||||
|
/// the collection is cleared before new data is added.
|
||||||
|
///
|
||||||
|
/// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
|
||||||
|
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||||
|
/// failed.
|
||||||
|
/// @throw isc::dhcp::MultipleRecords Multiple records were retrieved
|
||||||
|
/// from the database where only one was expected.
|
||||||
|
void getLeaseCollection(StatementIndex stindex, MYSQL_BIND* inbind,
|
||||||
|
Lease4Collection& result) const {
|
||||||
|
getLeaseCollection(stindex, inbind, exchange4_, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Get Lease Collection
|
||||||
|
///
|
||||||
|
/// Gets a collection of Lease6 objects. This is just an interface to
|
||||||
|
/// the get lease collection common code.
|
||||||
|
///
|
||||||
|
/// @param stindex Index of statement being executed
|
||||||
|
/// @param inbind MYSQL_BIND array for input parameters
|
||||||
|
/// @param lease LeaseCollection object returned. Note that any data in
|
||||||
|
/// the collection is cleared before new data is added.
|
||||||
|
///
|
||||||
|
/// @throw isc::dhcp::BadValue Data retrieved from the database was invalid.
|
||||||
|
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||||
|
/// failed.
|
||||||
|
/// @throw isc::dhcp::MultipleRecords Multiple records were retrieved
|
||||||
|
/// from the database where only one was expected.
|
||||||
|
void getLeaseCollection(StatementIndex stindex, MYSQL_BIND* inbind,
|
||||||
|
Lease6Collection& result) const {
|
||||||
|
getLeaseCollection(stindex, inbind, exchange6_, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Get Lease6 Common Code
|
||||||
|
///
|
||||||
|
/// This method performs the common actions for the various getLease4()
|
||||||
|
/// methods. It acts as an interface to the getLeaseCollection() method,
|
||||||
|
/// but retrieveing only a single lease.
|
||||||
|
///
|
||||||
|
/// @param stindex Index of statement being executed
|
||||||
|
/// @param inbind MYSQL_BIND array for input parameters
|
||||||
|
/// @param lease Lease4 object returned
|
||||||
|
void getLease(StatementIndex stindex, MYSQL_BIND* inbind,
|
||||||
|
Lease4Ptr& result) const;
|
||||||
|
|
||||||
|
/// @brief Get Lease4 Common Code
|
||||||
|
///
|
||||||
|
/// This method performs the common actions for the various getLease4()
|
||||||
|
/// methods. It acts as an interface to the getLeaseCollection() method,
|
||||||
|
/// but retrieveing only a single lease.
|
||||||
|
///
|
||||||
|
/// @param stindex Index of statement being executed
|
||||||
|
/// @param inbind MYSQL_BIND array for input parameters
|
||||||
|
/// @param lease Lease6 object returned
|
||||||
|
void getLease(StatementIndex stindex, MYSQL_BIND* inbind,
|
||||||
|
Lease6Ptr& result) const;
|
||||||
|
|
||||||
|
/// @brief Update lease common code
|
||||||
|
///
|
||||||
|
/// Holds the common code for updating a lease. It binds the parameters
|
||||||
|
/// to the prepared statement, executes it, then checks how many rows
|
||||||
|
/// were affected.
|
||||||
|
///
|
||||||
|
/// @param stindex Index of prepared statement to be executed
|
||||||
|
/// @param bind Array of MYSQL_BIND objects representing the parameters.
|
||||||
|
/// (Note that the number is determined by the number of parameters
|
||||||
|
/// in the statement.)
|
||||||
|
/// @param lease Pointer to the lease object whose record is being updated.
|
||||||
|
///
|
||||||
|
/// @throw NoSuchLease Could not update a lease because no lease matches
|
||||||
|
/// the address given.
|
||||||
|
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||||
|
/// failed.
|
||||||
|
template <typename LeasePtr>
|
||||||
|
void updateLease(StatementIndex stindex, MYSQL_BIND* bind,
|
||||||
|
const LeasePtr& lease);
|
||||||
|
|
||||||
|
/// @brief Delete lease common code
|
||||||
|
///
|
||||||
|
/// Holds the common code for deleting a lease. It binds the parameters
|
||||||
|
/// to the prepared statement, executes the statement and checks to
|
||||||
|
/// see how many rows were deleted.
|
||||||
|
///
|
||||||
|
/// @param stindex Index of prepared statement to be executed
|
||||||
|
/// @param bind Array of MYSQL_BIND objects representing the parameters.
|
||||||
|
/// (Note that the number is determined by the number of parameters
|
||||||
|
/// in the statement.)
|
||||||
|
///
|
||||||
|
/// @return true if one or more rows were deleted, false if none were
|
||||||
|
/// deleted.
|
||||||
|
///
|
||||||
|
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||||
|
/// failed.
|
||||||
|
bool deleteLease(StatementIndex stindex, MYSQL_BIND* bind);
|
||||||
|
|
||||||
/// @brief Check Error and Throw Exception
|
/// @brief Check Error and Throw Exception
|
||||||
///
|
///
|
||||||
/// Virtually all MySQL functions return a status which, if non-zero,
|
/// Virtually all MySQL functions return a status which, if non-zero,
|
||||||
@@ -496,15 +608,15 @@ private:
|
|||||||
|
|
||||||
// Members
|
// Members
|
||||||
|
|
||||||
/// Used for transfer of data to/from the database. This is a pointed-to
|
/// The exchange objects are used for transfer of data to/from the database.
|
||||||
/// object as its contents may change in "const" calls, while the rest
|
/// They are pointed-to objects as the contents may change in "const" calls,
|
||||||
/// of this object does not. (At alternative would be to declare it as
|
/// while the rest of this object does not. (At alternative would be to
|
||||||
/// "mutable".)
|
/// declare them as "mutable".)
|
||||||
MYSQL* mysql_; ///< MySQL context object
|
|
||||||
std::vector<std::string> text_statements_; ///< Raw text of statements
|
|
||||||
std::vector<MYSQL_STMT*> statements_; ///< Prepared statements
|
|
||||||
boost::scoped_ptr<MySqlLease4Exchange> exchange4_; ///< Exchange object
|
boost::scoped_ptr<MySqlLease4Exchange> exchange4_; ///< Exchange object
|
||||||
boost::scoped_ptr<MySqlLease6Exchange> exchange6_; ///< Exchange object
|
boost::scoped_ptr<MySqlLease6Exchange> exchange6_; ///< Exchange object
|
||||||
|
MYSQL* mysql_; ///< MySQL context object
|
||||||
|
std::vector<MYSQL_STMT*> statements_; ///< Prepared statements
|
||||||
|
std::vector<std::string> text_statements_; ///< Raw text of statements
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // end of isc::dhcp namespace
|
}; // end of isc::dhcp namespace
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
|
||||||
//
|
//
|
||||||
// Permission to use, copy, modify, and/or distribute this software for any
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -32,10 +32,10 @@ using namespace std;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Creation of the schema
|
// This holds statements to create and destroy the schema.
|
||||||
#include "schema_copy.h"
|
#include "schema_copy.h"
|
||||||
|
|
||||||
// IPv4 and IPv6 addresseses
|
// IPv4 and IPv6 addresses used in the tests
|
||||||
const char* ADDRESS4[] = {
|
const char* ADDRESS4[] = {
|
||||||
"192.0.2.0", "192.0.2.1", "192.0.2.2", "192.0.2.3",
|
"192.0.2.0", "192.0.2.1", "192.0.2.2", "192.0.2.3",
|
||||||
"192.0.2.4", "192.0.2.5", "192.0.2.6", "192.0.2.7",
|
"192.0.2.4", "192.0.2.5", "192.0.2.6", "192.0.2.7",
|
||||||
@@ -47,8 +47,9 @@ const char* ADDRESS6[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connection strings. Assume:
|
// Connection strings.
|
||||||
// Database: keatest
|
// Database: keatest
|
||||||
|
// Host: localhost
|
||||||
// Username: keatest
|
// Username: keatest
|
||||||
// Password: keatest
|
// Password: keatest
|
||||||
const char* VALID_TYPE = "type=mysql";
|
const char* VALID_TYPE = "type=mysql";
|
||||||
@@ -71,8 +72,7 @@ string connectionString(const char* type, const char* name, const char* host,
|
|||||||
if (type != NULL) {
|
if (type != NULL) {
|
||||||
result += string(type);
|
result += string(type);
|
||||||
}
|
}
|
||||||
|
if (name != NULL) {
|
||||||
if (name != NULL) {
|
|
||||||
if (! result.empty()) {
|
if (! result.empty()) {
|
||||||
result += space;
|
result += space;
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ validConnectionString() {
|
|||||||
// @brief Clear everything from the database
|
// @brief Clear everything from the database
|
||||||
//
|
//
|
||||||
// There is no error checking in this code: if something fails, one of the
|
// There is no error checking in this code: if something fails, one of the
|
||||||
// tests will fall over.
|
// tests will (should) fall over.
|
||||||
void destroySchema() {
|
void destroySchema() {
|
||||||
// Initialise
|
// Initialise
|
||||||
MYSQL handle;
|
MYSQL handle;
|
||||||
@@ -147,7 +147,7 @@ void createSchema() {
|
|||||||
(void) mysql_real_connect(&handle, "localhost", "keatest",
|
(void) mysql_real_connect(&handle, "localhost", "keatest",
|
||||||
"keatest", "keatest", 0, NULL, 0);
|
"keatest", "keatest", 0, NULL, 0);
|
||||||
|
|
||||||
// Get rid of everything in it.
|
// Execute creation statements.
|
||||||
for (int i = 0; create_statement[i] != NULL; ++i) {
|
for (int i = 0; create_statement[i] != NULL; ++i) {
|
||||||
(void) mysql_query(&handle, create_statement[i]);
|
(void) mysql_query(&handle, create_statement[i]);
|
||||||
}
|
}
|
||||||
@@ -156,20 +156,16 @@ void createSchema() {
|
|||||||
(void) mysql_close(&handle);
|
(void) mysql_close(&handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Doxygen "///" not used - even though Doxygen is used to
|
/// @brief Test fixture class for testing MySQL Lease Manager
|
||||||
// document class and methods - to avoid the comments appearing
|
///
|
||||||
// in the programming manual.
|
/// Opens the database prior to each test and closes it afterwards.
|
||||||
|
/// All pending transactions are deleted prior to closure.
|
||||||
// @brief Test Fixture Class
|
|
||||||
//
|
|
||||||
// Opens the database prior to each test and closes it afterwards.
|
|
||||||
// All pending transactions are deleted prior to closure.
|
|
||||||
|
|
||||||
class MySqlLeaseMgrTest : public ::testing::Test {
|
class MySqlLeaseMgrTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
// @brief Constructor
|
/// @brief Constructor
|
||||||
//
|
///
|
||||||
// Deletes everything from the database and opens it.
|
/// Deletes everything from the database and opens it.
|
||||||
MySqlLeaseMgrTest() {
|
MySqlLeaseMgrTest() {
|
||||||
// Initialize address strings and IOAddresses
|
// Initialize address strings and IOAddresses
|
||||||
for (int i = 0; ADDRESS4[i] != NULL; ++i) {
|
for (int i = 0; ADDRESS4[i] != NULL; ++i) {
|
||||||
@@ -202,38 +198,38 @@ public:
|
|||||||
lmptr_ = &(LeaseMgrFactory::instance());
|
lmptr_ = &(LeaseMgrFactory::instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Destructor
|
/// @brief Destructor
|
||||||
//
|
///
|
||||||
// Rolls back all pending transactions. The deletion of the
|
/// Rolls back all pending transactions. The deletion of the
|
||||||
// lmptr_ member variable will close the database. Then
|
/// lmptr_ member variable will close the database. Then
|
||||||
// reopen it and delete everything created by the test.
|
/// reopen it and delete everything created by the test.
|
||||||
virtual ~MySqlLeaseMgrTest() {
|
virtual ~MySqlLeaseMgrTest() {
|
||||||
lmptr_->rollback();
|
lmptr_->rollback();
|
||||||
LeaseMgrFactory::destroy();
|
LeaseMgrFactory::destroy();
|
||||||
destroySchema();
|
destroySchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Reopen the database
|
/// @brief Reopen the database
|
||||||
//
|
///
|
||||||
// Closes the database and re-open it. Anything committed should be
|
/// Closes the database and re-open it. Anything committed should be
|
||||||
// visible.
|
/// visible.
|
||||||
void reopen() {
|
void reopen() {
|
||||||
LeaseMgrFactory::destroy();
|
LeaseMgrFactory::destroy();
|
||||||
LeaseMgrFactory::create(validConnectionString());
|
LeaseMgrFactory::create(validConnectionString());
|
||||||
lmptr_ = &(LeaseMgrFactory::instance());
|
lmptr_ = &(LeaseMgrFactory::instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Initialize Lease4 Fields
|
/// @brief Initialize Lease4 Fields
|
||||||
//
|
///
|
||||||
// Returns a pointer to a Lease4 structure. Different values are put
|
/// Returns a pointer to a Lease4 structure. Different values are put
|
||||||
// in the lease according to the address passed.
|
/// in the lease according to the address passed.
|
||||||
//
|
///
|
||||||
// This is just a convenience function for the test methods.
|
/// This is just a convenience function for the test methods.
|
||||||
//
|
///
|
||||||
// @param address Address to use for the initialization
|
/// @param address Address to use for the initialization
|
||||||
//
|
///
|
||||||
// @return Lease4Ptr. This will not point to anything if the initialization
|
/// @return Lease4Ptr. This will not point to anything if the initialization
|
||||||
// failed (e.g. unknown address).
|
/// failed (e.g. unknown address).
|
||||||
Lease4Ptr initializeLease4(std::string address) {
|
Lease4Ptr initializeLease4(std::string address) {
|
||||||
Lease4Ptr lease(new Lease4());
|
Lease4Ptr lease(new Lease4());
|
||||||
|
|
||||||
@@ -332,17 +328,17 @@ public:
|
|||||||
return (lease);
|
return (lease);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Initialize Lease6 Fields
|
/// @brief Initialize Lease6 Fields
|
||||||
//
|
///
|
||||||
// Returns a pointer to a Lease6 structure. Different values are put
|
/// Returns a pointer to a Lease6 structure. Different values are put
|
||||||
// in the lease according to the address passed.
|
/// in the lease according to the address passed.
|
||||||
//
|
///
|
||||||
// This is just a convenience function for the test methods.
|
/// This is just a convenience function for the test methods.
|
||||||
//
|
///
|
||||||
// @param address Address to use for the initialization
|
/// @param address Address to use for the initialization
|
||||||
//
|
///
|
||||||
// @return Lease6Ptr. This will not point to anything if the initialization
|
/// @return Lease6Ptr. This will not point to anything if the initialization
|
||||||
// failed (e.g. unknown address).
|
/// failed (e.g. unknown address).
|
||||||
Lease6Ptr initializeLease6(std::string address) {
|
Lease6Ptr initializeLease6(std::string address) {
|
||||||
Lease6Ptr lease(new Lease6());
|
Lease6Ptr lease(new Lease6());
|
||||||
|
|
||||||
@@ -363,31 +359,34 @@ public:
|
|||||||
lease->type_ = Lease6::LEASE_IA_TA;
|
lease->type_ = Lease6::LEASE_IA_TA;
|
||||||
lease->prefixlen_ = 4;
|
lease->prefixlen_ = 4;
|
||||||
lease->iaid_ = 142;
|
lease->iaid_ = 142;
|
||||||
lease->duid_ = boost::shared_ptr<DUID>(new DUID(vector<uint8_t>(8, 0x77)));
|
lease->duid_ = boost::shared_ptr<DUID>(
|
||||||
lease->preferred_lft_ = 900; // Preferred lifetime
|
new DUID(vector<uint8_t>(8, 0x77)));
|
||||||
lease->valid_lft_ = 8677; // Actual lifetime
|
lease->preferred_lft_ = 900;
|
||||||
lease->cltt_ = 168256; // Current time of day
|
lease->valid_lft_ = 8677;
|
||||||
lease->subnet_id_ = 23; // Arbitrary number
|
lease->cltt_ = 168256;
|
||||||
|
lease->subnet_id_ = 23;
|
||||||
|
|
||||||
} else if (address == straddress6_[1]) {
|
} else if (address == straddress6_[1]) {
|
||||||
lease->type_ = Lease6::LEASE_IA_TA;
|
lease->type_ = Lease6::LEASE_IA_TA;
|
||||||
lease->prefixlen_ = 0;
|
lease->prefixlen_ = 0;
|
||||||
lease->iaid_ = 42;
|
lease->iaid_ = 42;
|
||||||
lease->duid_ = boost::shared_ptr<DUID>(new DUID(vector<uint8_t>(8, 0x42)));
|
lease->duid_ = boost::shared_ptr<DUID>(
|
||||||
lease->preferred_lft_ = 3600; // Preferred lifetime
|
new DUID(vector<uint8_t>(8, 0x42)));
|
||||||
lease->valid_lft_ = 3677; // Actual lifetime
|
lease->preferred_lft_ = 3600;
|
||||||
lease->cltt_ = 123456; // Current time of day
|
lease->valid_lft_ = 3677;
|
||||||
lease->subnet_id_ = 73; // Arbitrary number
|
lease->cltt_ = 123456;
|
||||||
|
lease->subnet_id_ = 73;
|
||||||
|
|
||||||
} else if (address == straddress6_[2]) {
|
} else if (address == straddress6_[2]) {
|
||||||
lease->type_ = Lease6::LEASE_IA_PD;
|
lease->type_ = Lease6::LEASE_IA_PD;
|
||||||
lease->prefixlen_ = 7;
|
lease->prefixlen_ = 7;
|
||||||
lease->iaid_ = 89;
|
lease->iaid_ = 89;
|
||||||
lease->duid_ = boost::shared_ptr<DUID>(new DUID(vector<uint8_t>(8, 0x3a)));
|
lease->duid_ = boost::shared_ptr<DUID>(
|
||||||
lease->preferred_lft_ = 1800; // Preferred lifetime
|
new DUID(vector<uint8_t>(8, 0x3a)));
|
||||||
lease->valid_lft_ = 5412; // Actual lifetime
|
lease->preferred_lft_ = 1800;
|
||||||
lease->cltt_ = 234567; // Current time of day
|
lease->valid_lft_ = 5412;
|
||||||
lease->subnet_id_ = 73; // Same as for straddress6_1
|
lease->cltt_ = 234567;
|
||||||
|
lease->subnet_id_ = 73; // Same as lease 1
|
||||||
|
|
||||||
} else if (address == straddress6_[3]) {
|
} else if (address == straddress6_[3]) {
|
||||||
lease->type_ = Lease6::LEASE_IA_NA;
|
lease->type_ = Lease6::LEASE_IA_NA;
|
||||||
@@ -403,54 +402,58 @@ public:
|
|||||||
// should be able to cope with valid lifetimes up to 0xffffffff.
|
// should be able to cope with valid lifetimes up to 0xffffffff.
|
||||||
// However, this will lead to overflows.
|
// However, this will lead to overflows.
|
||||||
// @TODO: test overflow conditions when code has been fixed
|
// @TODO: test overflow conditions when code has been fixed
|
||||||
lease->preferred_lft_ = 7200; // Preferred lifetime
|
lease->preferred_lft_ = 7200;
|
||||||
lease->valid_lft_ = 7000; // Actual lifetime
|
lease->valid_lft_ = 7000;
|
||||||
lease->cltt_ = 234567; // Current time of day
|
lease->cltt_ = 234567;
|
||||||
lease->subnet_id_ = 37; // Different from L1 and L2
|
lease->subnet_id_ = 37;
|
||||||
|
|
||||||
} else if (address == straddress6_[4]) {
|
} else if (address == straddress6_[4]) {
|
||||||
// Same DUID and IAID as straddress6_1
|
// Same DUID and IAID as straddress6_1
|
||||||
lease->type_ = Lease6::LEASE_IA_PD;
|
lease->type_ = Lease6::LEASE_IA_PD;
|
||||||
lease->prefixlen_ = 15;
|
lease->prefixlen_ = 15;
|
||||||
lease->iaid_ = 42;
|
lease->iaid_ = 42;
|
||||||
lease->duid_ = boost::shared_ptr<DUID>(new DUID(vector<uint8_t>(8, 0x42)));
|
lease->duid_ = boost::shared_ptr<DUID>(
|
||||||
lease->preferred_lft_ = 4800; // Preferred lifetime
|
new DUID(vector<uint8_t>(8, 0x42)));
|
||||||
lease->valid_lft_ = 7736; // Actual lifetime
|
lease->preferred_lft_ = 4800;
|
||||||
lease->cltt_ = 222456; // Current time of day
|
lease->valid_lft_ = 7736;
|
||||||
lease->subnet_id_ = 75; // Arbitrary number
|
lease->cltt_ = 222456;
|
||||||
|
lease->subnet_id_ = 671;
|
||||||
|
|
||||||
} else if (address == straddress6_[5]) {
|
} else if (address == straddress6_[5]) {
|
||||||
// Same DUID and IAID as straddress6_1
|
// Same DUID and IAID as straddress6_1
|
||||||
lease->type_ = Lease6::LEASE_IA_PD;
|
lease->type_ = Lease6::LEASE_IA_PD;
|
||||||
lease->prefixlen_ = 24;
|
lease->prefixlen_ = 24;
|
||||||
lease->iaid_ = 42;
|
lease->iaid_ = 42; // Same as lease 4
|
||||||
lease->duid_ = boost::shared_ptr<DUID>(new DUID(vector<uint8_t>(8, 0x42)));
|
lease->duid_ = boost::shared_ptr<DUID>(
|
||||||
lease->preferred_lft_ = 5400; // Preferred lifetime
|
new DUID(vector<uint8_t>(8, 0x42))); // Same as lease 4
|
||||||
lease->valid_lft_ = 7832; // Actual lifetime
|
lease->preferred_lft_ = 5400;
|
||||||
lease->cltt_ = 227476; // Current time of day
|
lease->valid_lft_ = 7832;
|
||||||
lease->subnet_id_ = 175; // Arbitrary number
|
lease->cltt_ = 227476;
|
||||||
|
lease->subnet_id_ = 175;
|
||||||
|
|
||||||
} else if (address == straddress6_[6]) {
|
} else if (address == straddress6_[6]) {
|
||||||
// Same DUID as straddress6_1
|
// Same DUID as straddress6_1
|
||||||
lease->type_ = Lease6::LEASE_IA_PD;
|
lease->type_ = Lease6::LEASE_IA_PD;
|
||||||
lease->prefixlen_ = 24;
|
lease->prefixlen_ = 24;
|
||||||
lease->iaid_ = 93;
|
lease->iaid_ = 93;
|
||||||
lease->duid_ = boost::shared_ptr<DUID>(new DUID(vector<uint8_t>(8, 0x42)));
|
lease->duid_ = boost::shared_ptr<DUID>(
|
||||||
lease->preferred_lft_ = 5400; // Preferred lifetime
|
new DUID(vector<uint8_t>(8, 0x42))); // Same as lease 4
|
||||||
lease->valid_lft_ = 1832; // Actual lifetime
|
lease->preferred_lft_ = 5400;
|
||||||
lease->cltt_ = 627476; // Current time of day
|
lease->valid_lft_ = 1832;
|
||||||
lease->subnet_id_ = 112; // Arbitrary number
|
lease->cltt_ = 627476;
|
||||||
|
lease->subnet_id_ = 112;
|
||||||
|
|
||||||
} else if (address == straddress6_[7]) {
|
} else if (address == straddress6_[7]) {
|
||||||
// Same IAID as straddress6_1
|
// Same IAID as straddress6_1
|
||||||
lease->type_ = Lease6::LEASE_IA_PD;
|
lease->type_ = Lease6::LEASE_IA_PD;
|
||||||
lease->prefixlen_ = 24;
|
lease->prefixlen_ = 24;
|
||||||
lease->iaid_ = 42;
|
lease->iaid_ = 42;
|
||||||
lease->duid_ = boost::shared_ptr<DUID>(new DUID(vector<uint8_t>(8, 0xe5)));
|
lease->duid_ = boost::shared_ptr<DUID>(
|
||||||
lease->preferred_lft_ = 5600; // Preferred lifetime
|
new DUID(vector<uint8_t>(8, 0xe5)));
|
||||||
lease->valid_lft_ = 7975; // Actual lifetime
|
lease->preferred_lft_ = 5600;
|
||||||
lease->cltt_ = 213876; // Current time of day
|
lease->valid_lft_ = 7975;
|
||||||
lease->subnet_id_ = 19; // Arbitrary number
|
lease->cltt_ = 213876;
|
||||||
|
lease->subnet_id_ = 19;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Unknown address, return an empty pointer.
|
// Unknown address, return an empty pointer.
|
||||||
@@ -461,13 +464,13 @@ public:
|
|||||||
return (lease);
|
return (lease);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Check Leases Present and Different
|
/// @brief Check Leases present and different
|
||||||
//
|
///
|
||||||
// Checks a vector of lease pointers and ensures that all the leases
|
/// Checks a vector of lease pointers and ensures that all the leases
|
||||||
// they point to are present and different. If not, a GTest assertion
|
/// they point to are present and different. If not, a GTest assertion
|
||||||
// will fail.
|
/// will fail.
|
||||||
//
|
///
|
||||||
// @param leases Vector of pointers to leases
|
/// @param leases Vector of pointers to leases
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void checkLeasesDifferent(const std::vector<T> leases) const {
|
void checkLeasesDifferent(const std::vector<T> leases) const {
|
||||||
|
|
||||||
@@ -484,11 +487,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Creates Leases for the test
|
/// @brief Creates leases for the test
|
||||||
//
|
///
|
||||||
// Creates all leases for the test and checks that they are different.
|
/// Creates all leases for the test and checks that they are different.
|
||||||
//
|
///
|
||||||
// @return vector<Lease4Ptr> Vector of pointers to leases
|
/// @return vector<Lease4Ptr> Vector of pointers to leases
|
||||||
vector<Lease4Ptr> createLeases4() {
|
vector<Lease4Ptr> createLeases4() {
|
||||||
|
|
||||||
// Create leases for each address
|
// Create leases for each address
|
||||||
@@ -504,11 +507,11 @@ public:
|
|||||||
return (leases);
|
return (leases);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Creates Leases for the test
|
/// @brief Creates leases for the test
|
||||||
//
|
///
|
||||||
// Creates all leases for the test and checks that they are different.
|
/// Creates all leases for the test and checks that they are different.
|
||||||
//
|
///
|
||||||
// @return vector<Lease6Ptr> Vector of pointers to leases
|
/// @return vector<Lease6Ptr> Vector of pointers to leases
|
||||||
vector<Lease6Ptr> createLeases6() {
|
vector<Lease6Ptr> createLeases6() {
|
||||||
|
|
||||||
// Create leases for each address
|
// Create leases for each address
|
||||||
@@ -527,21 +530,20 @@ public:
|
|||||||
|
|
||||||
// Member variables
|
// Member variables
|
||||||
|
|
||||||
LeaseMgr* lmptr_; // Pointer to the lease manager
|
LeaseMgr* lmptr_; ///< Pointer to the lease manager
|
||||||
|
vector<string> straddress4_; ///< String forms of IPv4 addresses
|
||||||
vector<string> straddress4_; // String forms of IPv4 addresses
|
vector<IOAddress> ioaddress4_; ///< IOAddress forms of IPv4 addresses
|
||||||
vector<IOAddress> ioaddress4_; // IOAddress forms of IPv4 addresses
|
vector<string> straddress6_; ///< String forms of IPv6 addresses
|
||||||
vector<string> straddress6_; // String forms of IPv6 addresses
|
vector<IOAddress> ioaddress6_; ///< IOAddress forms of IPv6 addresses
|
||||||
vector<IOAddress> ioaddress6_; // IOAddress forms of IPv6 addresses
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// @brief Check that Database Can Be Opened
|
/// @brief Check that database can be opened
|
||||||
//
|
///
|
||||||
// This test checks if the MySqlLeaseMgr can be instantiated. This happens
|
/// This test checks if the MySqlLeaseMgr can be instantiated. This happens
|
||||||
// only if the database can be opened. Note that this is not part of the
|
/// only if the database can be opened. Note that this is not part of the
|
||||||
// MySqlLeaseMgr test fixure set. This test checks that the database can be
|
/// MySqlLeaseMgr test fixure set. This test checks that the database can be
|
||||||
// opened: the fixtures assume that and check basic operations.
|
/// opened: the fixtures assume that and check basic operations.
|
||||||
|
|
||||||
TEST(MySqlOpenTest, OpenDatabase) {
|
TEST(MySqlOpenTest, OpenDatabase) {
|
||||||
|
|
||||||
@@ -599,25 +601,25 @@ TEST(MySqlOpenTest, OpenDatabase) {
|
|||||||
destroySchema();
|
destroySchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Check the getType() method
|
/// @brief Check the getType() method
|
||||||
//
|
///
|
||||||
// getType() returns a string giving the type of the backend, which should
|
/// getType() returns a string giving the type of the backend, which should
|
||||||
// always be "mysql".
|
/// always be "mysql".
|
||||||
TEST_F(MySqlLeaseMgrTest, getType) {
|
TEST_F(MySqlLeaseMgrTest, getType) {
|
||||||
EXPECT_EQ(std::string("mysql"), lmptr_->getType());
|
EXPECT_EQ(std::string("mysql"), lmptr_->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Check conversion functions
|
/// @brief Check conversion functions
|
||||||
//
|
///
|
||||||
// The server works using cltt and valid_filetime. In the database, the
|
/// The server works using cltt and valid_filetime. In the database, the
|
||||||
// information is stored as expire_time and valid-lifetime, which are
|
/// information is stored as expire_time and valid-lifetime, which are
|
||||||
// related by
|
/// related by
|
||||||
//
|
///
|
||||||
// expire_time = cltt + valid_lifetime
|
/// expire_time = cltt + valid_lifetime
|
||||||
//
|
///
|
||||||
// This test checks that the conversion is correct. It does not check that the
|
/// This test checks that the conversion is correct. It does not check that the
|
||||||
// data is entered into the database correctly, only that the MYSQL_TIME
|
/// data is entered into the database correctly, only that the MYSQL_TIME
|
||||||
// structure used for the entry is correctly set up.
|
/// structure used for the entry is correctly set up.
|
||||||
TEST_F(MySqlLeaseMgrTest, checkTimeConversion) {
|
TEST_F(MySqlLeaseMgrTest, checkTimeConversion) {
|
||||||
const time_t cltt = time(NULL);
|
const time_t cltt = time(NULL);
|
||||||
const uint32_t valid_lft = 86400; // 1 day
|
const uint32_t valid_lft = 86400; // 1 day
|
||||||
@@ -649,14 +651,14 @@ TEST_F(MySqlLeaseMgrTest, checkTimeConversion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @brief Check getName() returns correct database name
|
/// @brief Check getName() returns correct database name
|
||||||
TEST_F(MySqlLeaseMgrTest, getName) {
|
TEST_F(MySqlLeaseMgrTest, getName) {
|
||||||
EXPECT_EQ(std::string("keatest"), lmptr_->getName());
|
EXPECT_EQ(std::string("keatest"), lmptr_->getName());
|
||||||
|
|
||||||
// @TODO: check for the negative
|
// @TODO: check for the negative
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Check that getVersion() returns the expected version
|
/// @brief Check that getVersion() returns the expected version
|
||||||
TEST_F(MySqlLeaseMgrTest, checkVersion) {
|
TEST_F(MySqlLeaseMgrTest, checkVersion) {
|
||||||
// Check version
|
// Check version
|
||||||
pair<uint32_t, uint32_t> version;
|
pair<uint32_t, uint32_t> version;
|
||||||
@@ -665,7 +667,7 @@ TEST_F(MySqlLeaseMgrTest, checkVersion) {
|
|||||||
EXPECT_EQ(CURRENT_VERSION_MINOR, version.second);
|
EXPECT_EQ(CURRENT_VERSION_MINOR, version.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Compare two Lease4 structures for equality
|
/// @brief Compare two Lease4 structures for equality
|
||||||
void
|
void
|
||||||
detailCompareLease(const Lease4Ptr& first, const Lease4Ptr& second) {
|
detailCompareLease(const Lease4Ptr& first, const Lease4Ptr& second) {
|
||||||
// Compare address strings. Comparison of address objects is not used, as
|
// Compare address strings. Comparison of address objects is not used, as
|
||||||
@@ -680,7 +682,7 @@ detailCompareLease(const Lease4Ptr& first, const Lease4Ptr& second) {
|
|||||||
EXPECT_EQ(first->subnet_id_, second->subnet_id_);
|
EXPECT_EQ(first->subnet_id_, second->subnet_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Compare two Lease6 structures for equality
|
/// @brief Compare two Lease6 structures for equality
|
||||||
void
|
void
|
||||||
detailCompareLease(const Lease6Ptr& first, const Lease6Ptr& second) {
|
detailCompareLease(const Lease6Ptr& first, const Lease6Ptr& second) {
|
||||||
EXPECT_EQ(first->type_, second->type_);
|
EXPECT_EQ(first->type_, second->type_);
|
||||||
@@ -700,17 +702,17 @@ detailCompareLease(const Lease6Ptr& first, const Lease6Ptr& second) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @brief Basic Lease Checks
|
/// @brief Basic Lease Checks
|
||||||
//
|
///
|
||||||
// Checks that the add/get/delete works. All are done within one
|
/// Checks that the add/get/delete works. All are done within one
|
||||||
// test so that "rollback" can be used to remove trace of the tests
|
/// test so that "rollback" can be used to remove trace of the tests
|
||||||
// from the database.
|
/// from the database.
|
||||||
//
|
///
|
||||||
// Tests where a collection of leases can be returned are in the test
|
/// Tests where a collection of leases can be returned are in the test
|
||||||
// Lease4Collection.
|
/// Lease4Collection.
|
||||||
//
|
///
|
||||||
// @param leases Vector of leases used in the tests
|
/// @param leases Vector of leases used in the tests
|
||||||
// @param ioaddress Vector of IOAddresses used in the tests
|
/// @param ioaddress Vector of IOAddresses used in the tests
|
||||||
|
|
||||||
TEST_F(MySqlLeaseMgrTest, basicLease4) {
|
TEST_F(MySqlLeaseMgrTest, basicLease4) {
|
||||||
// Get the leases to be used for the test.
|
// Get the leases to be used for the test.
|
||||||
@@ -755,14 +757,14 @@ TEST_F(MySqlLeaseMgrTest, basicLease4) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @brief Check individual Lease6 methods
|
/// @brief Check individual Lease6 methods
|
||||||
//
|
///
|
||||||
// Checks that the add/get/delete works. All are done within one
|
/// Checks that the add/get/delete works. All are done within one
|
||||||
// test so that "rollback" can be used to remove trace of the tests
|
/// test so that "rollback" can be used to remove trace of the tests
|
||||||
// from the database.
|
/// from the database.
|
||||||
//
|
///
|
||||||
// Tests where a collection of leases can be returned are in the test
|
/// Tests where a collection of leases can be returned are in the test
|
||||||
// Lease6Collection.
|
/// Lease6Collection.
|
||||||
TEST_F(MySqlLeaseMgrTest, basicLease6) {
|
TEST_F(MySqlLeaseMgrTest, basicLease6) {
|
||||||
// Get the leases to be used for the test.
|
// Get the leases to be used for the test.
|
||||||
vector<Lease6Ptr> leases = createLeases6();
|
vector<Lease6Ptr> leases = createLeases6();
|
||||||
@@ -805,10 +807,10 @@ TEST_F(MySqlLeaseMgrTest, basicLease6) {
|
|||||||
detailCompareLease(leases[2], l_returned);
|
detailCompareLease(leases[2], l_returned);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @brief Check GetLease4 methods - Access by Address and SubnetID
|
/// @brief Check GetLease4 methods - access by Address and SubnetID
|
||||||
//
|
///
|
||||||
// Adds leases to the database and checks that they can be accessed via
|
/// Adds leases to the database and checks that they can be accessed via
|
||||||
// a the hardware address
|
/// a the hardware address
|
||||||
TEST_F(MySqlLeaseMgrTest, getLease4AddressSubnetId) {
|
TEST_F(MySqlLeaseMgrTest, getLease4AddressSubnetId) {
|
||||||
// Get the leases to be used for the test.
|
// Get the leases to be used for the test.
|
||||||
vector<Lease4Ptr> leases = createLeases4();
|
vector<Lease4Ptr> leases = createLeases4();
|
||||||
@@ -835,10 +837,10 @@ TEST_F(MySqlLeaseMgrTest, getLease4AddressSubnetId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @brief Check GetLease4 methods - Access by Hardware Address
|
/// @brief Check GetLease4 methods - access by Hardware Address
|
||||||
//
|
///
|
||||||
// Adds leases to the database and checks that they can be accessed via
|
/// Adds leases to the database and checks that they can be accessed via
|
||||||
// a combination of DIUID and IAID.
|
/// a combination of DIUID and IAID.
|
||||||
TEST_F(MySqlLeaseMgrTest, getLease4Hwaddr) {
|
TEST_F(MySqlLeaseMgrTest, getLease4Hwaddr) {
|
||||||
// Get the leases to be used for the test and add to the database
|
// Get the leases to be used for the test and add to the database
|
||||||
vector<Lease4Ptr> leases = createLeases4();
|
vector<Lease4Ptr> leases = createLeases4();
|
||||||
@@ -888,11 +890,10 @@ TEST_F(MySqlLeaseMgrTest, getLease4Hwaddr) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @brief Check GetLease4 methods - Access by Hardware Address & Subnet ID
|
/// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
|
||||||
//
|
///
|
||||||
// Adds leases to the database and checks that they can be accessed via
|
/// Adds leases to the database and checks that they can be accessed via
|
||||||
// a combination of hardware address and subnet ID
|
/// a combination of hardware address and subnet ID
|
||||||
|
|
||||||
TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetId) {
|
TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetId) {
|
||||||
// Get the leases to be used for the test and add to the database
|
// Get the leases to be used for the test and add to the database
|
||||||
vector<Lease4Ptr> leases = createLeases4();
|
vector<Lease4Ptr> leases = createLeases4();
|
||||||
@@ -925,13 +926,25 @@ TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetId) {
|
|||||||
returned = lmptr_->getLease4(invalid_hwaddr,
|
returned = lmptr_->getLease4(invalid_hwaddr,
|
||||||
leases[1]->subnet_id_ + 1);
|
leases[1]->subnet_id_ + 1);
|
||||||
EXPECT_FALSE(returned);
|
EXPECT_FALSE(returned);
|
||||||
|
|
||||||
|
// Add a second lease with the same values as the first and check that
|
||||||
|
// an attempt to access the database by these parameters throws a
|
||||||
|
// "multiple records" exception. (We expect there to be only one record
|
||||||
|
// with that combination, so getting them via getLeaseX() (as opposed
|
||||||
|
// to getLeaseXCollection() should throw an exception.)
|
||||||
|
EXPECT_TRUE(lmptr_->deleteLease4(leases[2]->addr_));
|
||||||
|
leases[1]->addr_ = leases[2]->addr_;
|
||||||
|
EXPECT_TRUE(lmptr_->addLease(leases[1]));
|
||||||
|
EXPECT_THROW(returned = lmptr_->getLease4(leases[1]->hwaddr_,
|
||||||
|
leases[1]->subnet_id_),
|
||||||
|
isc::dhcp::MultipleRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @brief Check GetLease4 methods - Access by Client ID
|
/// @brief Check GetLease4 methods - access by Client ID
|
||||||
//
|
///
|
||||||
// Adds leases to the database and checks that they can be accessed via
|
/// Adds leases to the database and checks that they can be accessed via
|
||||||
// the Client ID
|
/// the Client ID.
|
||||||
TEST_F(MySqlLeaseMgrTest, getLease4ClientId) {
|
TEST_F(MySqlLeaseMgrTest, getLease4ClientId) {
|
||||||
// Get the leases to be used for the test and add to the database
|
// Get the leases to be used for the test and add to the database
|
||||||
vector<Lease4Ptr> leases = createLeases4();
|
vector<Lease4Ptr> leases = createLeases4();
|
||||||
@@ -976,11 +989,10 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @brief Check GetLease4 methods - Access by Client ID & Subnet ID
|
/// @brief Check GetLease4 methods - access by Client ID & Subnet ID
|
||||||
//
|
///
|
||||||
// Adds leases to the database and checks that they can be accessed via
|
/// Adds leases to the database and checks that they can be accessed via
|
||||||
// a combination of client and subnet IDs.
|
/// a combination of client and subnet IDs.
|
||||||
|
|
||||||
TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSubnetId) {
|
TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSubnetId) {
|
||||||
// Get the leases to be used for the test and add to the database
|
// Get the leases to be used for the test and add to the database
|
||||||
vector<Lease4Ptr> leases = createLeases4();
|
vector<Lease4Ptr> leases = createLeases4();
|
||||||
@@ -1015,10 +1027,10 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSubnetId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @brief Check GetLease6 methods - Access by DUID/IAID
|
/// @brief Check GetLease6 methods - access by DUID/IAID
|
||||||
//
|
///
|
||||||
// Adds leases to the database and checks that they can be accessed via
|
/// Adds leases to the database and checks that they can be accessed via
|
||||||
// a combination of DIUID and IAID.
|
/// a combination of DIUID and IAID.
|
||||||
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaid) {
|
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaid) {
|
||||||
// Get the leases to be used for the test.
|
// Get the leases to be used for the test.
|
||||||
vector<Lease6Ptr> leases = createLeases6();
|
vector<Lease6Ptr> leases = createLeases6();
|
||||||
@@ -1062,10 +1074,10 @@ TEST_F(MySqlLeaseMgrTest, getLease6DuidIaid) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @brief Check GetLease6 methods - Access by DUID/IAID/SubnetID
|
/// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
|
||||||
//
|
///
|
||||||
// Adds leases to the database and checks that they can be accessed via
|
/// Adds leases to the database and checks that they can be accessed via
|
||||||
// a combination of DIUID and IAID.
|
/// a combination of DIUID and IAID.
|
||||||
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetId) {
|
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetId) {
|
||||||
// Get the leases to be used for the test and add them to the database.
|
// Get the leases to be used for the test and add them to the database.
|
||||||
vector<Lease6Ptr> leases = createLeases6();
|
vector<Lease6Ptr> leases = createLeases6();
|
||||||
@@ -1100,8 +1112,9 @@ TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update lease4 tests
|
/// @brief Lease4 update tests
|
||||||
|
///
|
||||||
|
/// Checks that we are able to update a lease in the database.
|
||||||
TEST_F(MySqlLeaseMgrTest, updateLease4) {
|
TEST_F(MySqlLeaseMgrTest, updateLease4) {
|
||||||
// Get the leases to be used for the test and add them to the database.
|
// Get the leases to be used for the test and add them to the database.
|
||||||
vector<Lease4Ptr> leases = createLeases4();
|
vector<Lease4Ptr> leases = createLeases4();
|
||||||
@@ -1144,10 +1157,9 @@ TEST_F(MySqlLeaseMgrTest, updateLease4) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Lease6 update tests
|
||||||
// @brief Lease6 Update Tests
|
///
|
||||||
//
|
/// Checks that we are able to update a lease in the database.
|
||||||
// Checks that we are able to update a lease in the database.
|
|
||||||
TEST_F(MySqlLeaseMgrTest, updateLease6) {
|
TEST_F(MySqlLeaseMgrTest, updateLease6) {
|
||||||
// Get the leases to be used for the test.
|
// Get the leases to be used for the test.
|
||||||
vector<Lease6Ptr> leases = createLeases6();
|
vector<Lease6Ptr> leases = createLeases6();
|
||||||
@@ -1157,7 +1169,6 @@ TEST_F(MySqlLeaseMgrTest, updateLease6) {
|
|||||||
EXPECT_TRUE(lmptr_->addLease(leases[1]));
|
EXPECT_TRUE(lmptr_->addLease(leases[1]));
|
||||||
lmptr_->commit();
|
lmptr_->commit();
|
||||||
|
|
||||||
reopen();
|
|
||||||
Lease6Ptr l_returned = lmptr_->getLease6(ioaddress6_[1]);
|
Lease6Ptr l_returned = lmptr_->getLease6(ioaddress6_[1]);
|
||||||
ASSERT_TRUE(l_returned);
|
ASSERT_TRUE(l_returned);
|
||||||
detailCompareLease(leases[1], l_returned);
|
detailCompareLease(leases[1], l_returned);
|
||||||
@@ -1168,7 +1179,6 @@ TEST_F(MySqlLeaseMgrTest, updateLease6) {
|
|||||||
leases[1]->valid_lft_ *= 2;
|
leases[1]->valid_lft_ *= 2;
|
||||||
lmptr_->updateLease6(leases[1]);
|
lmptr_->updateLease6(leases[1]);
|
||||||
lmptr_->commit();
|
lmptr_->commit();
|
||||||
reopen();
|
|
||||||
|
|
||||||
// ... and check what is returned is what is expected.
|
// ... and check what is returned is what is expected.
|
||||||
l_returned.reset();
|
l_returned.reset();
|
||||||
|
@@ -75,7 +75,7 @@ const char* create_statement[] = {
|
|||||||
"minor INT"
|
"minor INT"
|
||||||
")",
|
")",
|
||||||
|
|
||||||
"INSERT INTO schema_version VALUES (0, 1)",
|
"INSERT INTO schema_version VALUES (0, 2)",
|
||||||
|
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user