BIND 10 trac2404, updated. af71689ee49cd8668dd830e7a90f06c9b7fc7de7 [2404] Add getLease4(const IOAddress&, SubnetId)
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Nov 21 19:51:57 UTC 2012
The branch, trac2404 has been updated
via af71689ee49cd8668dd830e7a90f06c9b7fc7de7 (commit)
via 61071513480693ec4d32a3aa73cd60bf63bbb808 (commit)
via f15be5f7bf0fa3e5381afe4bb820a06af434a5af (commit)
via 01ee67bc74edb15536ae92b558eddd496da13fce (commit)
via d135a0e1f84ed2700d283ce20c7d96e5be614619 (commit)
via b7bce1d66baed1e01a951a6b13151783b2d74444 (commit)
from 504f64b2975180c69805756c4e6997c9dfdf140c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit af71689ee49cd8668dd830e7a90f06c9b7fc7de7
Author: Stephen Morris <stephen at isc.org>
Date: Wed Nov 21 19:38:26 2012 +0000
[2404] Add getLease4(const IOAddress&, SubnetId)
Add ability to select IPv4 leases by address and Subnet ID.
commit 61071513480693ec4d32a3aa73cd60bf63bbb808
Author: Stephen Morris <stephen at isc.org>
Date: Wed Nov 21 12:44:18 2012 +0000
[2404] Basic Lease4 functionality working
commit f15be5f7bf0fa3e5381afe4bb820a06af434a5af
Author: Stephen Morris <stephen at isc.org>
Date: Tue Nov 20 12:49:38 2012 +0000
[2404] lease_time renamed valid_lifetime in lease4 table
Make the names of the columns consistent between the lease4 and
lease6 tables.
commit 01ee67bc74edb15536ae92b558eddd496da13fce
Author: Stephen Morris <stephen at isc.org>
Date: Tue Nov 20 12:47:22 2012 +0000
[2404] Add another Lease4 constructor
This constructore is for use by the MySQL code. By passing buffer
addresses and lengths, the need for the creation of intermediate
std::vectors is avoided.
commit d135a0e1f84ed2700d283ce20c7d96e5be614619
Author: Stephen Morris <stephen at isc.org>
Date: Tue Nov 20 12:45:01 2012 +0000
[2404] Minor changes to make files conform to programming style
commit b7bce1d66baed1e01a951a6b13151783b2d74444
Author: Stephen Morris <stephen at isc.org>
Date: Mon Nov 19 19:37:07 2012 +0000
[2404] Change multiple discrete variables to arrays
... in preparation for adding IPv4 tests
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/duid.cc | 24 +-
src/lib/dhcp/duid.h | 8 +-
src/lib/dhcpsrv/dhcpdb_create.mysql | 4 +-
src/lib/dhcpsrv/lease_mgr.h | 34 +-
src/lib/dhcpsrv/mysql_lease_mgr.cc | 469 ++++++++++++++++----
src/lib/dhcpsrv/mysql_lease_mgr.h | 52 ++-
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc | 42 ++
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc | 483 ++++++++++++++++-----
src/lib/dhcpsrv/tests/schema_copy.h | 2 +-
9 files changed, 890 insertions(+), 228 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/duid.cc b/src/lib/dhcp/duid.cc
index c3f46da..91efe94 100644
--- a/src/lib/dhcp/duid.cc
+++ b/src/lib/dhcp/duid.cc
@@ -33,7 +33,7 @@ DUID::DUID(const std::vector<uint8_t>& duid) {
}
}
-DUID::DUID(const uint8_t * data, size_t len) {
+DUID::DUID(const uint8_t* data, size_t len) {
if (len > MAX_DUID_LEN) {
isc_throw(OutOfRange, "DUID too large");
}
@@ -72,36 +72,36 @@ std::string DUID::toText() const {
return (tmp.str());
}
-bool DUID::operator == (const DUID& other) const {
+bool DUID::operator==(const DUID& other) const {
return (this->duid_ == other.duid_);
}
-bool DUID::operator != (const DUID& other) const {
+bool DUID::operator!=(const DUID& other) const {
return (this->duid_ != other.duid_);
}
-/// constructor based on vector<uint8_t>
+// Constructor based on vector<uint8_t>
ClientId::ClientId(const std::vector<uint8_t>& clientid)
- :DUID(clientid) {
+ : DUID(clientid) {
}
-/// constructor based on C-style data
+// Constructor based on C-style data
ClientId::ClientId(const uint8_t *clientid, size_t len)
- :DUID(clientid, len) {
+ : DUID(clientid, len) {
}
-/// @brief returns a copy of client-id data
+// Returns a copy of client-id data
const std::vector<uint8_t> ClientId::getClientId() const {
return (duid_);
}
-// compares two client-ids
-bool ClientId::operator == (const ClientId& other) const {
+// Compares two client-ids
+bool ClientId::operator==(const ClientId& other) const {
return (this->duid_ == other.duid_);
}
-// compares two client-ids
-bool ClientId::operator != (const ClientId& other) const {
+// Compares two client-ids
+bool ClientId::operator!=(const ClientId& other) const {
return (this->duid_ != other.duid_);
}
diff --git a/src/lib/dhcp/duid.h b/src/lib/dhcp/duid.h
index 001e362..e226216 100644
--- a/src/lib/dhcp/duid.h
+++ b/src/lib/dhcp/duid.h
@@ -49,7 +49,7 @@ class DUID {
DUID(const std::vector<uint8_t>& duid);
/// @brief creates a DUID
- DUID(const uint8_t *duid, size_t len);
+ DUID(const uint8_t* duid, size_t len);
/// @brief returns a const reference to the actual DUID value
///
@@ -90,17 +90,17 @@ class ClientId : DUID {
ClientId(const std::vector<uint8_t>& clientid);
/// constructor based on C-style data
- ClientId(const uint8_t *clientid, size_t len);
+ ClientId(const uint8_t* clientid, size_t len);
/// @brief returns reference to the client-id data
///
const std::vector<uint8_t> getClientId() const;
// compares two client-ids
- bool operator == (const ClientId& other) const;
+ bool operator==(const ClientId& other) const;
// compares two client-ids
- bool operator != (const ClientId& other) const;
+ bool operator!=(const ClientId& other) const;
};
}; // end of isc::dhcp namespace
diff --git a/src/lib/dhcpsrv/dhcpdb_create.mysql b/src/lib/dhcpsrv/dhcpdb_create.mysql
index 7a292ec..777a12f 100644
--- a/src/lib/dhcpsrv/dhcpdb_create.mysql
+++ b/src/lib/dhcpsrv/dhcpdb_create.mysql
@@ -34,7 +34,7 @@ CREATE TABLE lease4 (
address INT UNSIGNED PRIMARY KEY NOT NULL, # IPv4 address
hwaddr VARBINARY(20), # Hardware address
client_id VARBINARY(128), # Client ID
- lease_time INT UNSIGNED, # Length of the lease (seconds)
+ valid_lifetime INT UNSIGNED, # Length of the lease (seconds)
expire TIMESTAMP, # Expiration time of the lease
subnet_id INT UNSIGNED # Subnet identification
) ENGINE = INNODB;
@@ -77,7 +77,7 @@ CREATE TABLE schema_version (
minor INT # Minor version number
);
START TRANSACTION;
-INSERT INTO schema_version VALUES (0, 1);
+INSERT INTO schema_version VALUES (0, 2);
COMMIT;
# Notes:
diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h
index 0e1f8d8..135eb0a 100644
--- a/src/lib/dhcpsrv/lease_mgr.h
+++ b/src/lib/dhcpsrv/lease_mgr.h
@@ -101,6 +101,33 @@ public:
/// would be required. As this is a critical part of the code that will be used
/// extensively, direct access is warranted.
struct Lease4 {
+ /// @brief Constructor
+ ///
+ /// @param addr IPv4 address as unsigned 32-bit integer in network byte
+ /// order.
+ /// @param hwaddr Hardware address buffer
+ /// @param hwaddr_len Length of hardware address buffer
+ /// @param clientid Client identification buffer
+ /// @param clientid_len Length of client identification buffer
+ /// @param valid_lft Lifetime of the lease
+ /// @param cltt Client last transmission time
+ /// @param subnet_id Subnet identification
+ Lease4(uint32_t addr, const uint8_t* hwaddr, size_t hwaddr_len,
+ const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
+ time_t cltt, uint32_t subnet_id)
+ : addr_(addr), ext_(0), hwaddr_(hwaddr, hwaddr + hwaddr_len),
+ client_id_(new ClientId(clientid, clientid_len)), t1_(0), t2_(0),
+ valid_lft_(valid_lft), cltt_(cltt), subnet_id_(subnet_id),
+ fixed_(false), hostname_(), fqdn_fwd_(false), fqdn_rev_(false),
+ comments_()
+ {}
+
+ /// @brief Default Constructor
+ ///
+ /// Initialize fields that don't have a default constructor.
+ Lease4() : addr_(0) {}
+
+
/// IPv4 address
isc::asiolink::IOAddress addr_;
@@ -175,12 +202,6 @@ struct Lease4 {
std::string comments_;
/// @todo: Add DHCPv4 failover related fields here
-
- /// @brief Constructor
- ///
- /// Initialize fields that don't have a default constructor.
- /// @todo Remove this
- Lease4() : addr_(0) {}
};
/// @brief Pointer to a Lease4 structure.
@@ -202,6 +223,7 @@ struct Lease6 {
LEASE_IA_PD /// the lease contains IPv6 prefix (for prefix delegation)
} LeaseType;
+ /// @brief Constructor
Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0);
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc
index a3387ac..c07fad4 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.cc
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc
@@ -41,8 +41,10 @@ namespace {
/// the insertion of a trailing null regardless of whether the data returned
/// contains a trailing null (the documentation is not clear on this point).
-const size_t ADDRESS6_TEXT_MAX_LEN = 42; // Max size of a IPv6 text buffer
-const size_t DUID_MAX_LEN = 128; // Max size of a DUID
+const size_t ADDRESS6_TEXT_MAX_LEN = 42; ///< Max size of a IPv6 text buffer
+const size_t DUID_MAX_LEN = 128; ///< Max size of a DUID
+const size_t HWADDR_MAX_LEN = 128; ///< Max size of a hardware address
+const size_t CLIENT_ID_MAX_LEN = 128; ///< Max size of a client ID
///@}
/// @brief MySQL Selection Statements
@@ -55,8 +57,15 @@ struct TaggedStatement {
};
TaggedStatement tagged_statements[] = {
+ {MySqlLeaseMgr::DELETE_LEASE4,
+ "DELETE FROM lease4 WHERE address = ?"},
{MySqlLeaseMgr::DELETE_LEASE6,
"DELETE FROM lease6 WHERE address = ?"},
+ {MySqlLeaseMgr::GET_LEASE4_ADDR,
+ "SELECT address, hwaddr, client_id, "
+ "valid_lifetime, expire, subnet_id "
+ "FROM lease4 "
+ "WHERE address = ?"},
{MySqlLeaseMgr::GET_LEASE6_ADDR,
"SELECT address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, "
@@ -77,6 +86,10 @@ TaggedStatement tagged_statements[] = {
"WHERE duid = ? AND iaid = ? AND subnet_id = ?"},
{MySqlLeaseMgr::GET_VERSION,
"SELECT version, minor FROM schema_version"},
+ {MySqlLeaseMgr::INSERT_LEASE4,
+ "INSERT INTO lease4(address, hwaddr, client_id, "
+ "valid_lifetime, expire, subnet_id) "
+ "VALUES (?, ?, ?, ?, ?, ?)"},
{MySqlLeaseMgr::INSERT_LEASE6,
"INSERT INTO lease6(address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, "
@@ -97,6 +110,205 @@ TaggedStatement tagged_statements[] = {
namespace isc {
namespace dhcp {
+/// @brief Exchange MySQL and Lease4 Data
+///
+/// On any MySQL operation, arrays of MYSQL_BIND structures must be built to
+/// describe the parameters in the prepared statements. Where information is
+/// inserted or retrieved - INSERT, UPDATE, SELECT - a large amount of that
+/// structure is identical - it defines data values in the Lease4 structure.
+/// This class handles the creation of that array.
+///
+/// Owing to the MySQL API, the process requires some intermediate variables
+/// to hold things like length etc. This object holds the intermediate
+/// variables as well.
+///
+/// @note There are no unit tests for this class. It is tested indirectly
+/// in all MySqlLeaseMgr::xxx4() calls where it is used.
+
+class MySqlLease4Exchange {
+public:
+ /// @brief Constructor
+ ///
+ /// Apart from the initialization of false_ and true_, the initialization
+ /// of addr4_, hwaddr_length_, hwaddr_buffer_, client_id_length_ and
+ /// client_id_buffer_ are to satisfy cppcheck: none are really needed, as
+ /// all variables are initialized/set in the methods.
+ MySqlLease4Exchange() : addr4_(0), hwaddr_length_(0), client_id_length_(0),
+ false_(0), true_(1) {
+ memset(hwaddr_buffer_, 0, sizeof(hwaddr_buffer_));
+ memset(client_id_buffer_, 0, sizeof(client_id_buffer_));
+ }
+
+ /// @brief Create MYSQL_BIND objects for Lease4 Pointer
+ ///
+ /// Fills in the MYSQL_BIND objects for the Lease4 passed to it.
+ ///
+ /// @param lease Lease object to be added to the database.
+ ///
+ /// @return Vector of MySQL BIND objects representing the data to be added.
+ std::vector<MYSQL_BIND> createBindForSend(const Lease4Ptr& lease) {
+ // Store lease object to ensure it remains valid.
+ lease_ = lease;
+
+ // Ensure bind_ array clear for constructing the MYSQL_BIND structures
+ // for this lease.
+ memset(bind_, 0, sizeof(bind_));
+
+ // Address: uint32_t
+ // Address in the Lease structre is an IOAddress object. Convert to
+ // an integer for storage.
+ addr4_ = static_cast<uint32_t>(lease_->addr_);
+ bind_[0].buffer_type = MYSQL_TYPE_LONG;
+ bind_[0].buffer = reinterpret_cast<char*>(&addr4_);
+ bind_[0].is_unsigned = true_;
+
+ // hwaddr: varbinary
+ // For speed, we avoid copying the data into temporary storage and
+ // instead extract it from the lease structure directly.
+ hwaddr_length_ = lease_->hwaddr_.size();
+ bind_[1].buffer_type = MYSQL_TYPE_BLOB;
+ bind_[1].buffer = reinterpret_cast<char*>(&(lease_->hwaddr_[0]));
+ bind_[1].buffer_length = hwaddr_length_;
+ bind_[1].length = &hwaddr_length_;
+
+ // client_id: varbinary
+ client_id_ = lease_->client_id_->getClientId();
+ client_id_length_ = client_id_.size();
+ bind_[2].buffer_type = MYSQL_TYPE_BLOB;
+ bind_[2].buffer = reinterpret_cast<char*>(&client_id_[0]);
+ bind_[2].buffer_length = client_id_length_;
+ bind_[2].length = &client_id_length_;
+
+ // valid lifetime: unsigned int
+ bind_[3].buffer_type = MYSQL_TYPE_LONG;
+ bind_[3].buffer = reinterpret_cast<char*>(&lease_->valid_lft_);
+ bind_[3].is_unsigned = true_;
+
+ // expire: timestamp
+ // The lease structure holds the client last transmission time (cltt_)
+ // For convenience for external tools, this is converted to lease
+ /// expiry time (expire). The relationship is given by:
+ //
+ // expire = cltt_ + valid_lft_
+ //
+ // @TODO Handle overflows
+ MySqlLeaseMgr::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
+ expire_);
+ bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
+ bind_[4].buffer = reinterpret_cast<char*>(&expire_);
+ bind_[4].buffer_length = sizeof(expire_);
+
+ // subnet_id: unsigned int
+ // Can use lease_->subnet_id_ directly as it is of type uint32_t.
+ bind_[5].buffer_type = MYSQL_TYPE_LONG;
+ bind_[5].buffer = reinterpret_cast<char*>(&lease_->subnet_id_);
+ bind_[5].is_unsigned = true_;
+
+ // Add the data to the vector. Note the end element is one after the
+ // end of the array.
+ return (std::vector<MYSQL_BIND>(&bind_[0], &bind_[6]));
+ }
+
+ /// @brief Create BIND array to receive data
+ ///
+ /// Creates a MYSQL_BIND array to receive Lease4 data from the database.
+ /// After data is successfully received, getLeaseData() is used to copy
+ /// it to a Lease6 object.
+ ///
+ /// @return Vector of MySQL BIND objects.
+ std::vector<MYSQL_BIND> createBindForReceive() {
+
+ // Ensure both the array of MYSQL_BIND structures and the error array
+ // are clear.
+ memset(bind_, 0, sizeof(bind_));
+ memset(error_, 0, sizeof(error_));
+
+ // address: uint32_t
+ bind_[0].buffer_type = MYSQL_TYPE_LONG;
+ bind_[0].buffer = reinterpret_cast<char*>(&addr4_);
+ bind_[0].is_unsigned = true_;
+ bind_[0].error = &error_[0];
+
+ // hwaddr: varbinary(20)
+ hwaddr_length_ = sizeof(hwaddr_buffer_);
+ bind_[1].buffer_type = MYSQL_TYPE_BLOB;
+ bind_[1].buffer = reinterpret_cast<char*>(hwaddr_buffer_);
+ bind_[1].buffer_length = hwaddr_length_;
+ bind_[1].length = &hwaddr_length_;
+ bind_[1].error = &error_[1];
+
+ // client_id: varbinary(128)
+ client_id_length_ = sizeof(client_id_buffer_);
+ bind_[2].buffer_type = MYSQL_TYPE_BLOB;
+ bind_[2].buffer = reinterpret_cast<char*>(client_id_buffer_);
+ bind_[2].buffer_length = client_id_length_;
+ bind_[2].length = &client_id_length_;
+ bind_[2].error = &error_[2];
+
+ // lease_time: unsigned int
+ bind_[3].buffer_type = MYSQL_TYPE_LONG;
+ bind_[3].buffer = reinterpret_cast<char*>(&valid_lifetime_);
+ bind_[3].is_unsigned = true_;
+ bind_[3].error = &error_[3];
+
+ // expire: timestamp
+ bind_[4].buffer_type = MYSQL_TYPE_TIMESTAMP;
+ bind_[4].buffer = reinterpret_cast<char*>(&expire_);
+ bind_[4].buffer_length = sizeof(expire_);
+ bind_[4].error = &error_[4];
+
+ // subnet_id: unsigned int
+ bind_[5].buffer_type = MYSQL_TYPE_LONG;
+ bind_[5].buffer = reinterpret_cast<char*>(&subnet_id_);
+ bind_[5].is_unsigned = true_;
+ bind_[5].error = &error_[5];
+
+ // Add the data to the vector. Note the end element is one after the
+ // end of the array.
+ return(std::vector<MYSQL_BIND>(&bind_[0], &bind_[6]));
+ }
+
+ /// @brief Copy Received Data into Lease6 Object
+ ///
+ /// Called after the MYSQL_BIND array created by createBindForReceive()
+ /// has been used, this copies data from the internal member vairables
+ /// into a Lease4 object.
+ ///
+ /// @return Lease6Ptr Pointer to a Lease6 object holding the relevant
+ /// data.
+ ///
+ /// @throw isc::BadValue Unable to convert Lease Type value in database
+ Lease4Ptr getLeaseData() {
+ // Convert times to units for the lease structure
+ time_t cltt = 0;
+ MySqlLeaseMgr::convertFromDatabaseTime(expire_, valid_lifetime_, cltt);
+
+ return (Lease4Ptr(new Lease4(addr4_, hwaddr_buffer_, hwaddr_length_,
+ client_id_buffer_, client_id_length_,
+ valid_lifetime_, cltt, subnet_id_)));
+ }
+
+private:
+ // Note: All array lengths are equal to the corresponding variable in the
+ // schema.
+ // Note: arrays are declared fixed length for speed of creation
+ uint32_t addr4_; ///< IPv4 address
+ MYSQL_BIND bind_[9]; ///< Bind array
+ std::vector<uint8_t> hwaddr_; ///< Hardware address
+ uint8_t hwaddr_buffer_[HWADDR_MAX_LEN]; ///< Hardware address buffer
+ unsigned long hwaddr_length_; ///< Hardware address length
+ std::vector<uint8_t> client_id_; ///< Client identification
+ uint8_t client_id_buffer_[CLIENT_ID_MAX_LEN]; ///< Client ID buffer
+ unsigned long client_id_length_; ///< Client ID address length
+ my_bool error_[6]; ///< For error reporting
+ MYSQL_TIME expire_; ///< Lease expiry time
+ const my_bool false_; ///< "false" for MySql
+ Lease4Ptr lease_; ///< Pointer to lease object
+ uint32_t subnet_id_; ///< Subnet identification
+ const my_bool true_; ///< "true_" for MySql
+ uint32_t valid_lifetime_; ///< Lease time
+};
+
/// @brief Exchange MySQL and Lease6 Data
@@ -177,7 +389,7 @@ public:
// valid lifetime: unsigned int
bind_[2].buffer_type = MYSQL_TYPE_LONG;
- bind_[2].buffer = reinterpret_cast<char*>(&lease->valid_lft_);
+ bind_[2].buffer = reinterpret_cast<char*>(&lease_->valid_lft_);
bind_[2].is_unsigned = true_;
// expire: timestamp
@@ -370,11 +582,12 @@ public:
private:
// Note: All array lengths are equal to the corresponding variable in the
// schema.
+ // Note: arrays are declared fixed length for speed of creation
std::string addr6_; ///< String form of address
char addr6_buffer_[ADDRESS6_TEXT_MAX_LEN]; ///< Character
///< array form of V6 address
unsigned long addr6_length_; ///< Length of the address
- MYSQL_BIND bind_[9]; ///< Static array for speed of access
+ MYSQL_BIND bind_[9]; ///< Bind array
std::vector<uint8_t> duid_; ///< Client identification
uint8_t duid_buffer_[DUID_MAX_LEN]; ///< Buffer form of DUID
unsigned long duid_length_; ///< Length of the DUID
@@ -383,12 +596,12 @@ private:
const my_bool false_; ///< "false" for MySql
uint32_t iaid_; ///< Identity association ID
Lease6Ptr lease_; ///< Pointer to lease object
- uint32_t valid_lifetime_; ///< Lease time
uint8_t lease_type_; ///< Lease type
uint8_t prefixlen_; ///< Prefix length
uint32_t pref_lifetime_; ///< Preferred lifetime
uint32_t subnet_id_; ///< Subnet identification
const my_bool true_; ///< "true_" for MySql
+ uint32_t valid_lifetime_; ///< Lease time
};
@@ -396,7 +609,7 @@ private:
///
/// When a MySQL statement is exected, to fetch the results the function
/// mysql_stmt_fetch() must be called. As well as getting data, this
-/// allocated internal state. Subsequent calls to mysql_stmt_fetch
+/// allocates internal state. Subsequent calls to mysql_stmt_fetch
/// can be made, but when all the data is retrieved, mysql_stmt_free_result
/// must be called to free up the resources allocated.
///
@@ -433,7 +646,7 @@ private:
};
-// MySqlLeaseMgr Methods
+// MySqlLeaseMgr Constructor and Destructor
MySqlLeaseMgr::MySqlLeaseMgr(const LeaseMgr::ParameterMap& parameters)
: LeaseMgr(parameters), mysql_(NULL) {
@@ -457,8 +670,9 @@ MySqlLeaseMgr::MySqlLeaseMgr(const LeaseMgr::ParameterMap& parameters)
// Prepare all statements likely to be used.
prepareStatements();
- // Create the exchange object for use in exchanging data between the
+ // Create the exchange objects for use in exchanging data between the
// program and the database.
+ exchange4_.reset(new MySqlLease4Exchange());
exchange6_.reset(new MySqlLease6Exchange());
}
@@ -535,6 +749,9 @@ MySqlLeaseMgr::convertFromDatabaseTime(const MYSQL_TIME& expire,
}
+
+// Database acess method
+
void
MySqlLeaseMgr::openDatabase() {
@@ -596,7 +813,7 @@ MySqlLeaseMgr::openDatabase() {
// changed and so the "affected rows" (retrievable from MySQL) is zero.
// This makes it hard to distinguish whether the UPDATE changed no rows
// because no row matching the WHERE clause was found, or because a
- // row was found by no data was altered.
+ // row was found but no data was altered.
MYSQL* status = mysql_real_connect(mysql_, host, user, password, name,
0, NULL, CLIENT_FOUND_ROWS);
if (status != mysql_) {
@@ -604,6 +821,12 @@ MySqlLeaseMgr::openDatabase() {
}
}
+// Prepared statement setup. The textual form of the SQL statement is stored
+// in a vector of strings (text_statements_) and is used in the output of
+// error messages. The SQL statement is also compiled into a "prepared
+// statement" (stored in statements_), which avoids the overhead of compilation
+// during use. As these allocate resources, the class destructor explicitly
+// destroys the prepared statements.
void
MySqlLeaseMgr::prepareStatement(StatementIndex index, const char* text) {
@@ -649,20 +872,10 @@ MySqlLeaseMgr::prepareStatements() {
}
-bool
-MySqlLeaseMgr::addLease(const Lease4Ptr& /* lease */) {
- isc_throw(NotImplemented, "MySqlLeaseMgr::addLease(const Lease4Ptr&) "
- "not implemented yet");
- return (false);
-}
-
+// Add leases to the database
bool
-MySqlLeaseMgr::addLease(const Lease6Ptr& lease) {
- const StatementIndex stindex = INSERT_LEASE6;
-
- // Create the MYSQL_BIND array for the lease
- std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
+MySqlLeaseMgr::addLease(StatementIndex stindex, std::vector<MYSQL_BIND>& bind) {
// Bind the parameters to the statement
int status = mysql_stmt_bind_param(statements_[stindex], &bind[0]);
@@ -685,21 +898,126 @@ MySqlLeaseMgr::addLease(const Lease6Ptr& lease) {
return (true);
}
+bool
+MySqlLeaseMgr::addLease(const Lease4Ptr& lease) {
+ // Create the MYSQL_BIND array for the lease
+ std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease);
+
+ // ... and drop to common code.
+ return (addLease(INSERT_LEASE4, bind));
+}
+
+bool
+MySqlLeaseMgr::addLease(const Lease6Ptr& lease) {
+ // Create the MYSQL_BIND array for the lease
+ std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
+
+ // ... and drop to common code.
+ return (addLease(INSERT_LEASE6, bind));
+}
+
+// A convenience function used in the various getLease() methods. It binds
+// the selection parameters to the prepared statement, and binds the variables
+// that will receive the data. These are stored in the MySqlLease6Exchange
+// object associated with the lease manager and converted to a Lease6 object
+// when retrieved.
+template <typename Exchange>
+void
+MySqlLeaseMgr::bindAndExecute(StatementIndex stindex, Exchange& exchange,
+ MYSQL_BIND* inbind) const {
+
+ // Bind the input parameters to the statement
+ int status = mysql_stmt_bind_param(statements_[stindex], inbind);
+ checkError(status, stindex, "unable to bind WHERE clause parameter");
+
+ // Set up the SELECT clause
+ std::vector<MYSQL_BIND> outbind = exchange->createBindForReceive();
+
+ // Bind the output parameters to the statement
+ status = mysql_stmt_bind_result(statements_[stindex], &outbind[0]);
+ checkError(status, stindex, "unable to bind SELECT caluse parameters");
+
+ // Execute the statement
+ status = mysql_stmt_execute(statements_[stindex]);
+ checkError(status, stindex, "unable to execute");
+}
+
+// Extraction of leases from the database. Much the code has common logic
+// with the difference between V4 and V6 being the data types of the
+// objects involved. For this reason, the common logic is inside a
+// template method.
+
+template <typename Exchange, typename LeasePtr>
+void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* inbind,
+ Exchange& exchange, LeasePtr& result) const {
+
+ // Bind the input parameters to the statement and bind the output
+ // to fields in the exchange object, then execute the prepared statement.
+ bindAndExecute(stindex, exchange, inbind);
+
+ // Fetch the data and set up the "free result" object to release associated
+ // resources when this method exits.
+ MySqlFreeResult fetch_release(statements_[stindex]);
+ int status = mysql_stmt_fetch(statements_[stindex]);
+
+ if (status == 0) {
+ try {
+ result = exchange->getLeaseData();
+ } catch (const isc::BadValue& ex) {
+ // Lease type is returned, to rethrow the exception with a bit
+ // more data.
+ isc_throw(BadValue, ex.what() << ". Statement is <" <<
+ text_statements_[stindex] << ">");
+ }
+
+ // As the address is the primary key in the table, we can't return
+ // two rows, so we don't bother checking whether multiple rows have
+ // been returned.
+
+ } else if (status == 1) {
+ checkError(status, stindex, "unable to fetch results");
+
+ } else {
+ // @TODO Handle truncation
+ // We are ignoring truncation for now, so the only other result is
+ // no data was found. In that case, we return a null Lease6 structure.
+ // This has already been set, so no action is needed.
+ }
+}
Lease4Ptr
-MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& /* addr */,
- SubnetID /* subnet_id */) const {
- isc_throw(NotImplemented, "MySqlLeaseMgr::getLease4(const IOAddress&, SubnetID) "
- "not implemented yet");
- return (Lease4Ptr());
+MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const {
+ // Set up the WHERE clause value
+ MYSQL_BIND inbind[1];
+ memset(inbind, 0, sizeof(inbind));
+
+ uint32_t addr4 = static_cast<uint32_t>(addr);
+ inbind[0].buffer_type = MYSQL_TYPE_LONG;
+ inbind[0].buffer = reinterpret_cast<char*>(&addr4);
+ inbind[0].is_unsigned = static_cast<my_bool>(1);
+
+ Lease4Ptr result;
+ getLease(GET_LEASE4_ADDR, inbind, exchange4_, result);
+
+ return (result);
}
Lease4Ptr
-MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& /* addr */) const {
- isc_throw(NotImplemented, "MySqlLeaseMgr::getLease4(const IOAddress&) "
- "not implemented yet");
- return (Lease4Ptr());
+MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr,
+ SubnetID subnet_id) const {
+
+ // As the address is the unique primary key of the lease4 table, there can
+ // only be one lease with a given address. Therefore we will get that
+ // lease and do the filtering on subnet ID here.
+ Lease4Ptr result = getLease4(addr);
+ if (result && (result->subnet_id_ != subnet_id)) {
+
+ // Lease found but IDs do not match. Return null pointer
+ result.reset();
+ }
+
+ return (result);
}
@@ -737,35 +1055,10 @@ MySqlLeaseMgr::getLease4(const ClientId& /* clientid */,
}
-// A convenience function used in the various getLease6() methods. It binds
-// the selection parameters to the prepared statement, and binds the variables
-// that will receive the data. These are stored in the MySqlLease6Exchange
-// object associated with the lease manager and converted to a Lease6 object
-// when retrieved.
-void
-MySqlLeaseMgr::bind6AndExecute(StatementIndex stindex, MYSQL_BIND* inbind) const {
-
- // Bind the input parameters to the statement
- int status = mysql_stmt_bind_param(statements_[stindex], inbind);
- checkError(status, stindex, "unable to bind WHERE clause parameter");
-
- // Set up the SELECT clause
- std::vector<MYSQL_BIND> outbind = exchange6_->createBindForReceive();
-
- // Bind the output parameters to the statement
- status = mysql_stmt_bind_result(statements_[stindex], &outbind[0]);
- checkError(status, stindex, "unable to bind SELECT caluse parameters");
-
- // Execute the statement
- status = mysql_stmt_execute(statements_[stindex]);
- checkError(status, stindex, "unable to execute");
-}
Lease6Ptr
MySqlLeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
- const StatementIndex stindex = GET_LEASE6_ADDR;
-
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
@@ -780,39 +1073,8 @@ MySqlLeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
inbind[0].buffer_length = addr6_length;
inbind[0].length = &addr6_length;
- // Bind the input parameters to the statement and bind the output
- // to fields in the exchange object, then execute the prepared statement.
- bind6AndExecute(stindex, inbind);
-
- // Fetch the data and set up the "release" object to release associated
- // resources when this method exits.
- MySqlFreeResult fetch_release(statements_[stindex]);
- int status = mysql_stmt_fetch(statements_[stindex]);
-
Lease6Ptr result;
- if (status == 0) {
- try {
- result = exchange6_->getLeaseData();
- } catch (const isc::BadValue& ex) {
- // Lease type is returned, to rethrow the exception with a bit
- // more data.
- isc_throw(BadValue, ex.what() << ". Statement is <" <<
- text_statements_[stindex] << ">");
- }
-
- // As the address is the primary key in the table, we can't return
- // two rows, so we don't bother checking whether multiple rows have
- // been returned.
-
- } else if (status == 1) {
- checkError(status, stindex, "unable to fetch results");
-
- } else {
- // @TODO Handle truncation
- // We are ignoring truncation for now, so the only other result is
- // no data was found. In that case, we return a null Lease6 structure.
- // This has already been set, so no action is needed.
- }
+ getLease(GET_LEASE6_ADDR, inbind, exchange6_, result);
return (result);
}
@@ -853,7 +1115,7 @@ MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid) const {
// Bind the input parameters to the statement and bind the output
// to fields in the exchange object, then execute the prepared statement.
- bind6AndExecute(stindex, inbind);
+ bindAndExecute(stindex, exchange6_, inbind);
// Ensure that all the lease information is retrieved in one go to avoid
// overhead of going back and forth between client and server.
@@ -924,7 +1186,7 @@ MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid,
// Bind the input parameters to the statement and bind the output
// to fields in the exchange object, then execute the prepared statement.
- bind6AndExecute(stindex, inbind);
+ bindAndExecute(stindex, exchange6_, inbind);
// Fetch the data and set up the "release" object to release associated
// resources when this method exits then retrieve the data.
@@ -1014,9 +1276,34 @@ MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) {
}
}
-
+// TODO: Replace by deleteLease
bool
-MySqlLeaseMgr::deleteLease4(const isc::asiolink::IOAddress& /* addr */) {
+MySqlLeaseMgr::deleteLease4(const isc::asiolink::IOAddress& addr) {
+ const StatementIndex stindex = DELETE_LEASE4;
+
+ // Set up the WHERE clause value
+ MYSQL_BIND inbind[1];
+ memset(inbind, 0, sizeof(inbind));
+
+ uint32_t addr4 = static_cast<uint32_t>(addr);
+
+ // See the earlier description of the use of "const_cast" when accessing
+ // the address for an explanation of the reason.
+ inbind[0].buffer_type = MYSQL_TYPE_LONG;
+ inbind[0].buffer = reinterpret_cast<char*>(&addr4);
+ inbind[0].is_unsigned = my_bool(1);
+
+ // Bind the input parameters to the statement
+ int status = mysql_stmt_bind_param(statements_[stindex], inbind);
+ checkError(status, stindex, "unable to bind WHERE clause parameter");
+
+ // Execute
+ status = mysql_stmt_execute(statements_[stindex]);
+ checkError(status, stindex, "unable to execute");
+
+ // See how many rows were affected. Note that the statement may delete
+ // multiple rows.
+ return (mysql_stmt_affected_rows(statements_[stindex]) > 0);
isc_throw(NotImplemented, "MySqlLeaseMgr::deleteLease4(const IOAddress&) "
"not implemented yet");
return (false);
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h
index 1884da6..cd6f320 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.h
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.h
@@ -31,8 +31,9 @@ const uint32_t CURRENT_VERSION_VERSION = 0;
const uint32_t CURRENT_VERSION_MINOR = 1;
-// Forward declaration of the Lease6 exchange object. This class is defined
+// Forward declaration of the Lease exchange objects. This class is defined
// in the .cc file.
+class MySqlLease4Exchange;
class MySqlLease6Exchange;
@@ -226,6 +227,10 @@ public:
/// @brief Deletes an IPv4 lease.
///
+ /// @todo Merge with deleteLease6: it is possible to determine whether
+ /// an address is V4 or V6 from the IOAddress argument, so there
+ /// is no need for separate V4 or V6 methods.
+ ///
/// @param addr IPv4 address of the lease to be deleted.
///
/// @return true if deletion was successful, false if no such lease exists
@@ -233,6 +238,10 @@ public:
/// @brief Deletes an IPv6 lease.
///
+ /// @todo Merge with deleteLease4: it is possible to determine whether
+ /// an address is V4 or V6 from the IOAddress argument, so there
+ /// is no need for separate V4 or V6 methods.
+ ///
/// @param addr IPv6 address of the lease to be deleted.
///
/// @return true if deletion was successful, false if no such lease exists
@@ -343,11 +352,14 @@ public:
///
/// The contents of the enum are indexes into the list of SQL statements
enum StatementIndex {
+ DELETE_LEASE4, // Delete from lease4 by address
DELETE_LEASE6, // Delete from lease6 by address
+ GET_LEASE4_ADDR, // Get lease4 by address
GET_LEASE6_ADDR, // Get lease6 by address
GET_LEASE6_DUID_IAID, // Get lease6 by DUID and IAID
GET_LEASE6_DUID_IAID_SUBID, // Get lease6 by DUID, IAID and Subnet ID
GET_VERSION, // Obtain version number
+ INSERT_LEASE4, // Add entry to lease4 table
INSERT_LEASE6, // Add entry to lease6 table
UPDATE_LEASE6, // Update a Lease6 entry
NUM_STATEMENTS // Number of statements
@@ -389,6 +401,34 @@ private:
/// @throw DbOpenError Error opening the database
void openDatabase();
+ /// @brief Add Lease Common Code
+ ///
+ /// This method performs the common actions for both flavours of the
+ /// addLease method.
+ ///
+ /// @param stindex Index of statemnent being executed
+ /// @param bind MYSQL_BIND array that has been created for the type
+ /// of lease in question.
+ ///
+ /// @return true if the lease was added, false if it was not added because
+ /// a lease with that address already exists in the database.
+ ///
+ /// @throw isc::dhcp::DbOperationError An operation on the open database has
+ /// failed.
+ bool addLease(StatementIndex stindex, std::vector<MYSQL_BIND>& bind);
+
+ /// @brief Get Lease Common Code
+ ///
+ /// This method performs the common actions for the getLease methods.
+ ///
+ /// @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 Binds Parameters and Executes
///
/// This method abstracts a lot of common processing from the getXxxx()
@@ -398,16 +438,19 @@ private:
/// statement.
///
/// The data can be retrieved using mysql_stmt_fetch and the getLeaseData()
- /// method on the exchange6 object.
+ /// method on the appropriate exchange object.
///
/// @param stindex Index of prepared statement to be executed
+ /// @param exchange Exchange object to use
/// @param inbind Array of MYSQL_BIND objects representing the parameters.
/// (Note that the number is determined by the number of parameters
/// in the statement.)
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
- void bind6AndExecute(StatementIndex stindex, MYSQL_BIND* inbind) const;
+ template <typename Exchange>
+ void bindAndExecute(StatementIndex stindex, Exchange& exchange,
+ MYSQL_BIND* inbind) const;
/// @brief Check Error and Throw Exception
///
@@ -437,10 +480,11 @@ private:
/// object as its contents may change in "const" calls, while the rest
/// of this object does not. (At alternative would be to declare it as
/// "mutable".)
- boost::scoped_ptr<MySqlLease6Exchange> exchange6_;
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<MySqlLease6Exchange> exchange6_; ///< Exchange object
};
}; // end of isc::dhcp namespace
diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
index 74a0fb4..82600c6 100644
--- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
@@ -22,6 +22,8 @@
#include <iostream>
#include <sstream>
+#include <time.h>
+
using namespace std;
using namespace isc;
using namespace isc::asiolink;
@@ -261,6 +263,46 @@ TEST_F(LeaseMgrTest, getParameter) {
// are purely virtual, so we would only call ConcreteLeaseMgr methods.
// Those methods are just stubs that do not return anything.
+// Lease4 is also defined in lease_mgr.h, so is tested in this file as well.
+// This test checks if the Lease4 structure can be instantiated correctly
+TEST(Lease4, Lease4Constructor) {
+
+ // Random values for the tests
+ const uint8_t HWADDR[] = {0x08, 0x00, 0x2b, 0x02, 0x3f, 0x4e};
+ std::vector<uint8_t> hwaddr(HWADDR, HWADDR + sizeof(HWADDR));
+
+ const uint8_t CLIENTID[] = {0x17, 0x34, 0xe2, 0xff, 0x09, 0x92, 0x54};
+ std::vector<uint8_t> clientid_vec(CLIENTID, CLIENTID + sizeof(CLIENTID));
+ ClientId clientid(clientid_vec);
+
+ // ...and a time
+ const time_t current_time = time(NULL);
+
+ // Other random constants
+ const uint32_t ADDRESS = 103478;
+ const uint32_t VALID_LIFETIME = 10986;
+ const uint32_t SUBNET_ID = 42;
+
+ // Create the lease
+ Lease4 lease(ADDRESS, HWADDR, sizeof(HWADDR), CLIENTID, sizeof(CLIENTID),
+ VALID_LIFETIME, current_time, SUBNET_ID);
+
+ EXPECT_EQ(ADDRESS, static_cast<uint32_t>(lease.addr_));
+ EXPECT_EQ(0, lease.ext_);
+ EXPECT_TRUE(hwaddr == lease.hwaddr_);
+ EXPECT_TRUE(clientid == *lease.client_id_);
+ EXPECT_EQ(0, lease.t1_);
+ EXPECT_EQ(0, lease.t2_);
+ EXPECT_EQ(VALID_LIFETIME, lease.valid_lft_);
+ EXPECT_EQ(current_time, lease.cltt_);
+ EXPECT_EQ(SUBNET_ID, lease.subnet_id_);
+ EXPECT_FALSE(lease.fixed_);
+ EXPECT_TRUE(lease.hostname_.empty());
+ EXPECT_FALSE(lease.fqdn_fwd_);
+ EXPECT_FALSE(lease.fqdn_rev_);
+ EXPECT_TRUE(lease.comments_.empty());
+}
+
// Lease6 is also defined in lease_mgr.h, so is tested in this file as well.
// This test checks if the Lease6 structure can be instantiated correctly
TEST(Lease6, Lease6Constructor) {
diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
index 930bc06..c55bd4b 100644
--- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
@@ -35,15 +35,17 @@ namespace {
// Creation of the schema
#include "schema_copy.h"
-// IPv6 addresseses
-const char* ADDRESS_0 = "2001:db8::0";
-const char* ADDRESS_1 = "2001:db8::1";
-const char* ADDRESS_2 = "2001:db8::2";
-const char* ADDRESS_3 = "2001:db8::3";
-const char* ADDRESS_4 = "2001:db8::4";
-const char* ADDRESS_5 = "2001:db8::5";
-const char* ADDRESS_6 = "2001:db8::6";
-const char* ADDRESS_7 = "2001:db8::7";
+// IPv4 and IPv6 addresseses
+const char* ADDRESS4[] = {
+ "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",
+ NULL
+};
+const char* ADDRESS6[] = {
+ "2001:db8::0", "2001:db8::1", "2001:db8::2", "2001:db8::3",
+ "2001:db8::4", "2001:db8::5", "2001:db8::6", "2001:db8::7",
+ NULL
+};
// Connection strings. Assume:
// Database: keatest
@@ -168,18 +170,25 @@ public:
// @brief Constructor
//
// Deletes everything from the database and opens it.
- MySqlLeaseMgrTest() :
- L0_ADDRESS(ADDRESS_0), L0_IOADDRESS(L0_ADDRESS),
- L1_ADDRESS(ADDRESS_1), L1_IOADDRESS(L1_ADDRESS),
- L2_ADDRESS(ADDRESS_2), L2_IOADDRESS(L2_ADDRESS),
- L3_ADDRESS(ADDRESS_3), L3_IOADDRESS(L3_ADDRESS),
- L4_ADDRESS(ADDRESS_4), L4_IOADDRESS(L4_ADDRESS),
- L5_ADDRESS(ADDRESS_5), L5_IOADDRESS(L5_ADDRESS),
- L6_ADDRESS(ADDRESS_6), L6_IOADDRESS(L6_ADDRESS),
- L7_ADDRESS(ADDRESS_7), L7_IOADDRESS(L7_ADDRESS) {
+ MySqlLeaseMgrTest() {
+ // Initialize address strings and IOAddresses
+ for (int i = 0; ADDRESS4[i] != NULL; ++i) {
+ string addr(ADDRESS4[i]);
+ straddress4_.push_back(addr);
+ IOAddress ioaddr(addr);
+ ioaddress4_.push_back(ioaddr);
+ }
+
+ for (int i = 0; ADDRESS6[i] != NULL; ++i) {
+ string addr(ADDRESS6[i]);
+ straddress6_.push_back(addr);
+ IOAddress ioaddr(addr);
+ ioaddress6_.push_back(ioaddr);
+ }
destroySchema();
createSchema();
+
try {
LeaseMgrFactory::create(validConnectionString());
} catch (...) {
@@ -214,6 +223,119 @@ public:
lmptr_ = &(LeaseMgrFactory::instance());
}
+ // @brief Initialize Lease4 Fields
+ //
+ // Returns a pointer to a Lease4 structure. Different values are put
+ // in the lease according to the address passed.
+ //
+ // This is just a convenience function for the test methods.
+ //
+ // @param address Address to use for the initialization
+ //
+ // @return Lease4Ptr. This will not point to anything if the initialization
+ // failed (e.g. unknown address).
+ Lease4Ptr initializeLease4(std::string address) {
+ Lease4Ptr lease(new Lease4());
+
+ // Set the address of the lease
+ lease->addr_ = IOAddress(address);
+
+ // Initialize unused fields.
+ lease->ext_ = 0; // Not saved
+ lease->t1_ = 0; // Not saved
+ lease->t2_ = 0; // Not saved
+ lease->fixed_ = false; // Unused
+ lease->hostname_ = std::string(""); // Unused
+ lease->fqdn_fwd_ = false; // Unused
+ lease->fqdn_rev_ = false; // Unused
+ lease->comments_ = std::string(""); // Unused
+
+ // Set other parameters. For historical reasons, address 0 is not used.
+ if (address == straddress4_[0]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x08);
+ lease->client_id_ = boost::shared_ptr<ClientId>(
+ new ClientId(vector<uint8_t>(8, 0x77)));
+ lease->valid_lft_ = 8677; // Actual lifetime
+ lease->cltt_ = 168256; // Current time of day
+ lease->subnet_id_ = 23; // Arbitrary number
+
+ } else if (address == straddress4_[1]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x19);
+ lease->client_id_ = boost::shared_ptr<ClientId>(
+ new ClientId(vector<uint8_t>(8, 0x42)));
+ lease->valid_lft_ = 3677; // Actual lifetime
+ lease->cltt_ = 123456; // Current time of day
+ lease->subnet_id_ = 73; // Arbitrary number
+
+ } else if (address == straddress4_[2]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x2a);
+ lease->client_id_ = boost::shared_ptr<ClientId>(
+ new ClientId(vector<uint8_t>(8, 0x3a)));
+ lease->valid_lft_ = 5412; // Actual lifetime
+ lease->cltt_ = 234567; // Current time of day
+ lease->subnet_id_ = 73; // Same as for straddress4_1
+
+ } else if (address == straddress4_[3]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x3b);
+ vector<uint8_t> clientid;
+ for (uint8_t i = 31; i < 126; ++i) {
+ clientid.push_back(i);
+ }
+ lease->client_id_ = boost::shared_ptr<ClientId>
+ (new ClientId(clientid));
+
+ // The times used in the next tests are deliberately restricted - we
+ // should be able to cope with valid lifetimes up to 0xffffffff.
+ // However, this will lead to overflows.
+ // @TODO: test overflow conditions when code has been fixed
+ lease->valid_lft_ = 7000; // Actual lifetime
+ lease->cltt_ = 234567; // Current time of day
+ lease->subnet_id_ = 37; // Different from L1 and L2
+
+ } else if (address == straddress4_[4]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x4c);
+ // Same ClientId as straddr4_[1]
+ lease->client_id_ = boost::shared_ptr<ClientId>(
+ new ClientId(vector<uint8_t>(8, 0x42)));
+ lease->valid_lft_ = 7736; // Actual lifetime
+ lease->cltt_ = 222456; // Current time of day
+ lease->subnet_id_ = 75; // Arbitrary number
+
+ } else if (address == straddress4_[5]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x5d);
+ // Same ClientId and IAID as straddress4_1
+ lease->client_id_ = boost::shared_ptr<ClientId>(
+ new ClientId(vector<uint8_t>(8, 0x42)));
+ lease->valid_lft_ = 7832; // Actual lifetime
+ lease->cltt_ = 227476; // Current time of day
+ lease->subnet_id_ = 175; // Arbitrary number
+
+ } else if (address == straddress4_[6]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x6e);
+ // Same ClientId as straddress4_1
+ lease->client_id_ = boost::shared_ptr<ClientId>(
+ new ClientId(vector<uint8_t>(8, 0x42)));
+ lease->valid_lft_ = 1832; // Actual lifetime
+ lease->cltt_ = 627476; // Current time of day
+ lease->subnet_id_ = 112; // Arbitrary number
+
+ } else if (address == straddress4_[7]) {
+ lease->hwaddr_ = vector<uint8_t>(6, 0x7f);
+ lease->client_id_ = boost::shared_ptr<ClientId>(
+ new ClientId(vector<uint8_t>(8, 0xe5)));
+ lease->valid_lft_ = 7975; // Actual lifetime
+ lease->cltt_ = 213876; // Current time of day
+ lease->subnet_id_ = 19; // Arbitrary number
+
+ } else {
+ // Unknown address, return an empty pointer.
+ lease.reset();
+
+ }
+
+ return (lease);
+ }
+
// @brief Initialize Lease6 Fields
//
// Returns a pointer to a Lease6 structure. Different values are put
@@ -240,8 +362,8 @@ public:
lease->fqdn_rev_ = false; // Unused
lease->comments_ = std::string(""); // Unused
- // Set the other parameters. For historical reasons, L0_ADDRESS is not used.
- if (address == L0_ADDRESS) {
+ // Set other parameters. For historical reasons, address 0 is not used.
+ if (address == straddress6_[0]) {
lease->type_ = Lease6::LEASE_IA_TA;
lease->prefixlen_ = 4;
lease->iaid_ = 142;
@@ -251,7 +373,7 @@ public:
lease->cltt_ = 168256; // Current time of day
lease->subnet_id_ = 23; // Arbitrary number
- } else if (address == L1_ADDRESS) {
+ } else if (address == straddress6_[1]) {
lease->type_ = Lease6::LEASE_IA_TA;
lease->prefixlen_ = 0;
lease->iaid_ = 42;
@@ -261,7 +383,7 @@ public:
lease->cltt_ = 123456; // Current time of day
lease->subnet_id_ = 73; // Arbitrary number
- } else if (address == L2_ADDRESS) {
+ } else if (address == straddress6_[2]) {
lease->type_ = Lease6::LEASE_IA_PD;
lease->prefixlen_ = 7;
lease->iaid_ = 89;
@@ -269,9 +391,9 @@ public:
lease->preferred_lft_ = 1800; // Preferred lifetime
lease->valid_lft_ = 5412; // Actual lifetime
lease->cltt_ = 234567; // Current time of day
- lease->subnet_id_ = 73; // Same as for L1_ADDRESS
+ lease->subnet_id_ = 73; // Same as for straddress6_1
- } else if (address == L3_ADDRESS) {
+ } else if (address == straddress6_[3]) {
lease->type_ = Lease6::LEASE_IA_NA;
lease->prefixlen_ = 28;
lease->iaid_ = 0xfffffffe;
@@ -290,8 +412,8 @@ public:
lease->cltt_ = 234567; // Current time of day
lease->subnet_id_ = 37; // Different from L1 and L2
- } else if (address == L4_ADDRESS) {
- // Same DUID and IAID as L1_ADDRESS
+ } else if (address == straddress6_[4]) {
+ // Same DUID and IAID as straddress6_1
lease->type_ = Lease6::LEASE_IA_PD;
lease->prefixlen_ = 15;
lease->iaid_ = 42;
@@ -301,8 +423,8 @@ public:
lease->cltt_ = 222456; // Current time of day
lease->subnet_id_ = 75; // Arbitrary number
- } else if (address == L5_ADDRESS) {
- // Same DUID and IAID as L1_ADDRESS
+ } else if (address == straddress6_[5]) {
+ // Same DUID and IAID as straddress6_1
lease->type_ = Lease6::LEASE_IA_PD;
lease->prefixlen_ = 24;
lease->iaid_ = 42;
@@ -312,8 +434,8 @@ public:
lease->cltt_ = 227476; // Current time of day
lease->subnet_id_ = 175; // Arbitrary number
- } else if (address == L6_ADDRESS) {
- // Same DUID as L1_ADDRESS
+ } else if (address == straddress6_[6]) {
+ // Same DUID as straddress6_1
lease->type_ = Lease6::LEASE_IA_PD;
lease->prefixlen_ = 24;
lease->iaid_ = 93;
@@ -323,8 +445,8 @@ public:
lease->cltt_ = 627476; // Current time of day
lease->subnet_id_ = 112; // Arbitrary number
- } else if (address == L7_ADDRESS) {
- // Same IAID as L1_ADDRESS
+ } else if (address == straddress6_[7]) {
+ // Same IAID as straddress6_1
lease->type_ = Lease6::LEASE_IA_PD;
lease->prefixlen_ = 24;
lease->iaid_ = 42;
@@ -343,69 +465,78 @@ public:
return (lease);
}
- // @brief Creates Leases for the test
+ // @brief Check Leases Present and Different
//
- // Creates all leases for the test and checks that they are different.
+ // Checks a vector of lease pointers and ensures that all the leases
+ // they point to are present and different. If not, a GTest assertion
+ // will fail.
//
- // @return vector<Lease6Ptr> Vector of pointers to leases
- vector<Lease6Ptr> createLeases6() {
-
- // Create leases
- vector<Lease6Ptr> leases;
- leases.push_back(initializeLease6(L0_ADDRESS));
- leases.push_back(initializeLease6(L1_ADDRESS));
- leases.push_back(initializeLease6(L2_ADDRESS));
- leases.push_back(initializeLease6(L3_ADDRESS));
- leases.push_back(initializeLease6(L4_ADDRESS));
- leases.push_back(initializeLease6(L5_ADDRESS));
- leases.push_back(initializeLease6(L6_ADDRESS));
- leases.push_back(initializeLease6(L7_ADDRESS));
-
- EXPECT_EQ(8, leases.size());
+ // @param leases Vector of pointers to leases
+ template <typename T>
+ void checkLeasesDifferent(const std::vector<T> leases) const {
// Check they were created
for (int i = 0; i < leases.size(); ++i) {
- EXPECT_TRUE(leases[i]);
+ ASSERT_TRUE(leases[i]);
}
// Check they are different
for (int i = 0; i < (leases.size() - 1); ++i) {
for (int j = (i + 1); j < leases.size(); ++j) {
- EXPECT_TRUE(leases[i] != leases[j]);
+ ASSERT_TRUE(leases[i] != leases[j]);
}
}
-
- return (leases);
}
+ // @brief Creates Leases for the test
+ //
+ // Creates all leases for the test and checks that they are different.
+ //
+ // @return vector<Lease4Ptr> Vector of pointers to leases
+ vector<Lease4Ptr> createLeases4() {
- // Member variables
+ // Create leases for each address
+ vector<Lease4Ptr> leases;
+ for (int i = 0; i < straddress4_.size(); ++i) {
+ leases.push_back(initializeLease4(straddress4_[i]));
+ }
+ EXPECT_EQ(8, leases.size());
- LeaseMgr* lmptr_; // Pointer to the lease manager
+ // Check all were created and that they are different.
+ checkLeasesDifferent(leases);
- string L0_ADDRESS; // String form of address 1
- IOAddress L0_IOADDRESS; // IOAddress form of L1_ADDRESS
+ return (leases);
+ }
- string L1_ADDRESS; // String form of address 1
- IOAddress L1_IOADDRESS; // IOAddress form of L1_ADDRESS
+ // @brief Creates Leases for the test
+ //
+ // Creates all leases for the test and checks that they are different.
+ //
+ // @return vector<Lease6Ptr> Vector of pointers to leases
+ vector<Lease6Ptr> createLeases6() {
- string L2_ADDRESS; // String form of address 2
- IOAddress L2_IOADDRESS; // IOAddress form of L2_ADDRESS
+ // Create leases for each address
+ vector<Lease6Ptr> leases;
+ for (int i = 0; i < straddress6_.size(); ++i) {
+ leases.push_back(initializeLease6(straddress6_[i]));
+ }
+ EXPECT_EQ(8, leases.size());
+
+ // Check all were created and that they are different.
+ checkLeasesDifferent(leases);
- string L3_ADDRESS; // String form of address 3
- IOAddress L3_IOADDRESS; // IOAddress form of L3_ADDRESS
+ return (leases);
+ }
- string L4_ADDRESS; // String form of address 4
- IOAddress L4_IOADDRESS; // IOAddress form of L4_ADDRESS
- string L5_ADDRESS; // String form of address 5
- IOAddress L5_IOADDRESS; // IOAddress form of L5_ADDRESS
+ // Member variables
- string L6_ADDRESS; // String form of address 6
- IOAddress L6_IOADDRESS; // IOAddress form of L6_ADDRESS
+ LeaseMgr* lmptr_; // Pointer to the lease manager
- string L7_ADDRESS; // String form of address 7
- IOAddress L7_IOADDRESS; // IOAddress form of L7_ADDRESS
+ vector<string> straddress4_; // String forms of IPv4 addresses
+ vector<IOAddress> ioaddress4_; // IOAddress forms of IPv4 addresses
+ vector<string> straddress6_; // String forms of IPv6 addresses
+ vector<IOAddress> ioaddress6_; // IOAddress forms of IPv6 addresses
};
@@ -538,9 +669,24 @@ TEST_F(MySqlLeaseMgrTest, checkVersion) {
EXPECT_EQ(CURRENT_VERSION_MINOR, version.second);
}
+// @brief Compare two Lease4 structures for equality
+void
+detailCompareLease(const Lease4Ptr& first, const Lease4Ptr& second) {
+ // Compare address strings. Comparison of address objects is not used, as
+ // odd things happen when they are different: the EXPECT_EQ macro appears to
+ // call the operator uint32_t() function, which causes an exception to be
+ // thrown for IPv6 addresses.
+ EXPECT_EQ(first->addr_.toText(), second->addr_.toText());
+ EXPECT_TRUE(first->hwaddr_ == second->hwaddr_);
+ EXPECT_TRUE(*first->client_id_ == *second->client_id_);
+ EXPECT_EQ(first->valid_lft_, second->valid_lft_);
+ EXPECT_EQ(first->cltt_, second->cltt_);
+ EXPECT_EQ(first->subnet_id_, second->subnet_id_);
+}
+
// @brief Compare two Lease6 structures for equality
void
-detailCompareLease6(const Lease6Ptr& first, const Lease6Ptr& second) {
+detailCompareLease(const Lease6Ptr& first, const Lease6Ptr& second) {
EXPECT_EQ(first->type_, second->type_);
// Compare address strings. Comparison of address objects is not used, as
@@ -558,9 +704,64 @@ detailCompareLease6(const Lease6Ptr& first, const Lease6Ptr& second) {
}
+// @brief Basic Lease Checks
+//
+// 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
+// from the database.
+//
+// Tests where a collection of leases can be returned are in the test
+// Lease4Collection.
+//
+// @param leases Vector of leases used in the tests
+// @param ioaddress Vector of IOAddresses used in the tests
+
+TEST_F(MySqlLeaseMgrTest, basicLease4) {
+ // Get the leases to be used for the test.
+ vector<Lease4Ptr> leases = createLeases4();
+
+ // Start the tests. Add three leases to the database, read them back and
+ // check they are what we think they are.
+ EXPECT_TRUE(lmptr_->addLease(leases[1]));
+ EXPECT_TRUE(lmptr_->addLease(leases[2]));
+ EXPECT_TRUE(lmptr_->addLease(leases[3]));
+ lmptr_->commit();
+
+ // Reopen the database to ensure that they actually got stored.
+ reopen();
+
+ Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
+
+ l_returned = lmptr_->getLease4(ioaddress4_[2]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[2], l_returned);
+
+ l_returned = lmptr_->getLease4(ioaddress4_[3]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[3], l_returned);
+
+ // Check that we can't add a second lease with the same address
+ EXPECT_FALSE(lmptr_->addLease(leases[1]));
+
+ // Delete a lease, check that it's gone, and that we can't delete it
+ // a second time.
+ EXPECT_TRUE(lmptr_->deleteLease4(ioaddress4_[1]));
+ l_returned = lmptr_->getLease4(ioaddress4_[1]);
+ EXPECT_FALSE(l_returned);
+ EXPECT_FALSE(lmptr_->deleteLease4(ioaddress4_[1]));
+
+ // Check that the second address is still there.
+ l_returned = lmptr_->getLease4(ioaddress4_[2]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[2], l_returned);
+}
+
+
// @brief Check individual Lease6 methods
//
-// Checks that the add/update/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
// from the database.
//
@@ -580,42 +781,108 @@ TEST_F(MySqlLeaseMgrTest, basicLease6) {
// Reopen the database to ensure that they actually got stored.
reopen();
- Lease6Ptr l_returned = lmptr_->getLease6(L1_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[1], l_returned);
+ Lease6Ptr l_returned = lmptr_->getLease6(ioaddress6_[1]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
- l_returned = lmptr_->getLease6(L2_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[2], l_returned);
+ l_returned = lmptr_->getLease6(ioaddress6_[2]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[2], l_returned);
- l_returned = lmptr_->getLease6(L3_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[3], l_returned);
+ l_returned = lmptr_->getLease6(ioaddress6_[3]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[3], l_returned);
// Check that we can't add a second lease with the same address
EXPECT_FALSE(lmptr_->addLease(leases[1]));
// Delete a lease, check that it's gone, and that we can't delete it
// a second time.
- EXPECT_TRUE(lmptr_->deleteLease6(L1_IOADDRESS));
- l_returned = lmptr_->getLease6(L1_IOADDRESS);
+ EXPECT_TRUE(lmptr_->deleteLease6(ioaddress6_[1]));
+ l_returned = lmptr_->getLease6(ioaddress6_[1]);
EXPECT_FALSE(l_returned);
- EXPECT_FALSE(lmptr_->deleteLease6(L1_IOADDRESS));
+ EXPECT_FALSE(lmptr_->deleteLease6(ioaddress6_[1]));
// Check that the second address is still there.
- l_returned = lmptr_->getLease6(L2_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[2], l_returned);
+ l_returned = lmptr_->getLease6(ioaddress6_[2]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[2], l_returned);
+}
+
+// @brief Check GetLease4 methods - Access by Address and SubnetID
+//
+// Adds leases to the database and checks that they can be accessed via
+// a combination of Address, SubnetID
+TEST_F(MySqlLeaseMgrTest, getLease4AddressSubnetId) {
+ // Get the leases to be used for the test.
+ vector<Lease4Ptr> leases = createLeases4();
+
+ // Add just one to the database.
+ EXPECT_TRUE(lmptr_->addLease(leases[1]));
+
+ // Look for a known lease with a valid Subnet ID
+ Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1], 73);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
+
+ // Look for a lease known to be in the database with an invalid Subnet ID
+ l_returned = lmptr_->getLease4(ioaddress4_[1], 74);
+ EXPECT_FALSE(l_returned);
+
+ // Look for a lease known not to be in the database with a valid Subnet ID
+ l_returned = lmptr_->getLease4(ioaddress4_[2], 73);
+ EXPECT_FALSE(l_returned);
+
+ // Look for a lease known not to be in the database with and invalid
+ l_returned = lmptr_->getLease4(ioaddress4_[2], 74);
+ EXPECT_FALSE(l_returned);
+}
+
+// @brief Check GetLease4 methods - Access by Hardware Address
+//
+// Adds leases to the database and checks that they can be accessed via
+// hardware address
+TEST_F(MySqlLeaseMgrTest, getLease4AddressHwaddr) {
+ FAIL() << "Test not complete";
+/*
+ // Get the leases to be used for the test and add to the database.
+ vector<Lease4Ptr> leases = createLeases4();
+ for (int i = 0; i < leases.size(); ++i) {
+ EXPECT_TRUE(lmptr_->addLease(leases[i]));
+ }
+
+ // Get a known hardware address
+ vector<uint8_t> hwaddr = leases[1]->hwaddr_;
+ EXPECT_FALSE(hwaddr.empty());
+
+ // Look for a lease with a valid hardware address
+ Lease4Ptr l_returned = lmptr_->getLease4(hwaddr);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
+
+ // Look for a lease with an invalid valid hardware address
+ hwaddr[0] += 1;
+ Lease4Ptr l_returned = lmptr_->getLease4(hwaddr);
+ EXPECT_FALSE(l_returned);
+
+ // Check it handles an empty hardware address
+ hwaddr.clear();
+ Lease4Ptr l_returned = lmptr_->getLease4(hwaddr);
+ EXPECT_FALSE(l_returned);
+
+ // Add a lease with an empty hardware address to the database and
+ // check that it find that.
+*/
}
// @brief Check GetLease6 methods - Access by DUID/IAID
//
// Adds leases to the database and checks that they can be accessed via
// a combination of DIUID and IAID.
-TEST_F(MySqlLeaseMgrTest, getLease6Extended1) {
+TEST_F(MySqlLeaseMgrTest, getLease6DuidIaid) {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
- EXPECT_LE(6, leases.size()); // Expect to access leases 0 through 5
+ ASSERT_LE(6, leases.size()); // Expect to access leases 0 through 5
// Add them to the database
for (int i = 0; i < leases.size(); ++i) {
@@ -636,9 +903,9 @@ TEST_F(MySqlLeaseMgrTest, getLease6Extended1) {
addresses.push_back((*i)->addr_.toText());
}
sort(addresses.begin(), addresses.end());
- EXPECT_EQ(L1_ADDRESS, addresses[0]);
- EXPECT_EQ(L4_ADDRESS, addresses[1]);
- EXPECT_EQ(L5_ADDRESS, addresses[2]);
+ EXPECT_EQ(straddress6_[1], addresses[0]);
+ EXPECT_EQ(straddress6_[4], addresses[1]);
+ EXPECT_EQ(straddress6_[5], addresses[2]);
// Check that nothing is returned when either the IAID or DUID match
// nothing.
@@ -659,10 +926,10 @@ TEST_F(MySqlLeaseMgrTest, getLease6Extended1) {
//
// Adds leases to the database and checks that they can be accessed via
// a combination of DIUID and IAID.
-TEST_F(MySqlLeaseMgrTest, getLease6Extended2) {
+TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetId) {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
- EXPECT_LE(6, leases.size()); // Expect to access leases 0 through 5
+ ASSERT_LE(6, leases.size()); // Expect to access leases 0 through 5
// Add them to the database
for (int i = 0; i < leases.size(); ++i) {
@@ -703,16 +970,16 @@ TEST_F(MySqlLeaseMgrTest, getLease6Extended2) {
TEST_F(MySqlLeaseMgrTest, updateLease6) {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
- EXPECT_LE(3, leases.size()); // Expect to access leases 0 through 5
+ ASSERT_LE(3, leases.size()); // Expect to access leases 0 through 2
// Add a lease to the database and check that the lease is there.
EXPECT_TRUE(lmptr_->addLease(leases[1]));
lmptr_->commit();
reopen();
- Lease6Ptr l_returned = lmptr_->getLease6(L1_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[1], l_returned);
+ Lease6Ptr l_returned = lmptr_->getLease6(ioaddress6_[1]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
// Modify some fields in lease 1 (not the address) and update it.
++leases[1]->iaid_;
@@ -724,9 +991,9 @@ TEST_F(MySqlLeaseMgrTest, updateLease6) {
// ... and check what is returned is what is expected.
l_returned.reset();
- l_returned = lmptr_->getLease6(L1_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[1], l_returned);
+ l_returned = lmptr_->getLease6(ioaddress6_[1]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
// Alter the lease again and check.
++leases[1]->iaid_;
@@ -736,16 +1003,16 @@ TEST_F(MySqlLeaseMgrTest, updateLease6) {
lmptr_->updateLease6(leases[1]);
l_returned.reset();
- l_returned = lmptr_->getLease6(L1_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[1], l_returned);
+ l_returned = lmptr_->getLease6(ioaddress6_[1]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
// Check we can do an update without changing data.
lmptr_->updateLease6(leases[1]);
l_returned.reset();
- l_returned = lmptr_->getLease6(L1_IOADDRESS);
- EXPECT_TRUE(l_returned);
- detailCompareLease6(leases[1], l_returned);
+ l_returned = lmptr_->getLease6(ioaddress6_[1]);
+ ASSERT_TRUE(l_returned);
+ detailCompareLease(leases[1], l_returned);
// Try updating a lease not in the database.
EXPECT_THROW(lmptr_->updateLease6(leases[2]), isc::dhcp::NoSuchLease);
diff --git a/src/lib/dhcpsrv/tests/schema_copy.h b/src/lib/dhcpsrv/tests/schema_copy.h
index 1dd796d..3e739da 100644
--- a/src/lib/dhcpsrv/tests/schema_copy.h
+++ b/src/lib/dhcpsrv/tests/schema_copy.h
@@ -44,7 +44,7 @@ const char* create_statement[] = {
"address INT UNSIGNED PRIMARY KEY NOT NULL,"
"hwaddr VARBINARY(20),"
"client_id VARBINARY(128),"
- "lease_time INT UNSIGNED,"
+ "valid_lifetime INT UNSIGNED,"
"expire TIMESTAMP,"
"subnet_id INT UNSIGNED"
") ENGINE = INNODB",
More information about the bind10-changes
mailing list