/// @brief Deletes a lease.
///
- /// @param addr IPv4 address of the lease to be deleted.
+ /// @param addr Address of the lease to be deleted. (This can be IPv4 or
+ /// IPv6.)
///
/// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease4(const isc::asiolink::IOAddress& addr) = 0;
-
- /// @brief Deletes a lease.
- ///
- /// @param addr IPv6 address of the lease to be deleted.
- ///
- /// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease6(const isc::asiolink::IOAddress& addr) = 0;
+ virtual bool deleteLease(const isc::asiolink::IOAddress& addr) = 0;
/// @brief Return backend type
///
}
-bool Memfile_LeaseMgr::deleteLease4(const isc::asiolink::IOAddress&) {
- return (false);
-}
-
-bool Memfile_LeaseMgr::deleteLease6(const isc::asiolink::IOAddress& addr) {
- Lease6Storage::iterator l = storage6_.find(addr);
- if (l == storage6_.end()) {
- // no such lease
+bool Memfile_LeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
+ if (addr.isV4()) {
+ // V4 not implemented yet
return (false);
+
} else {
- storage6_.erase(l);
- return (true);
+ // V6 lease
+ Lease6Storage::iterator l = storage6_.find(addr);
+ if (l == storage6_.end()) {
+ // No such lease
+ return (false);
+ } else {
+ storage6_.erase(l);
+ return (true);
+ }
}
}
/// @brief Deletes a lease.
///
- /// @param addr IPv4 address of the lease to be deleted.
+ /// @param addr Address of the lease to be deleted. (This can be IPv4 or
+ /// IPv6.)
///
/// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease4(const isc::asiolink::IOAddress& addr);
-
- /// @brief Deletes a lease.
- ///
- /// @param addr IPv4 address of the lease to be deleted.
- ///
- /// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease6(const isc::asiolink::IOAddress& addr);
+ virtual bool deleteLease(const isc::asiolink::IOAddress& addr);
/// @brief Return backend type
///
updateLeaseCommon(stindex, &bind[0], lease);
}
-// Delete lease methods. As with other groups of methods, these comprise
-// a per-type method that sets up the relevant MYSQL_BIND array and a
-// common method than handles the common processing.
+// Delete lease methods. Similar to other groups of methods, these comprise
+// a per-type method that sets up the relevant MYSQL_BIND array (in this
+// case, a single method for both V4 and V6 addresses) and a common method that
+// handles the common processing.
bool
-MySqlLeaseMgr::deleteLease(StatementIndex stindex, MYSQL_BIND* bind) {
+MySqlLeaseMgr::deleteLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind) {
// Bind the input parameters to the statement
int status = mysql_stmt_bind_param(statements_[stindex], bind);
bool
-MySqlLeaseMgr::deleteLease4(const isc::asiolink::IOAddress& addr) {
+MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
// 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 = MLM_TRUE;
-
- return (deleteLease(DELETE_LEASE4, inbind));
-}
+ if (addr.isV4()) {
+ 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 = MLM_TRUE;
-bool
-MySqlLeaseMgr::deleteLease6(const isc::asiolink::IOAddress& addr) {
-
- // Set up the WHERE clause value
- MYSQL_BIND inbind[1];
- memset(inbind, 0, sizeof(inbind));
+ return (deleteLeaseCommon(DELETE_LEASE4, inbind));
- std::string addr6 = addr.toText();
- unsigned long addr6_length = addr6.size();
+ } else {
+ std::string addr6 = addr.toText();
+ unsigned long addr6_length = addr6.size();
- // 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_STRING;
- inbind[0].buffer = const_cast<char*>(addr6.c_str());
- inbind[0].buffer_length = addr6_length;
- inbind[0].length = &addr6_length;
+ // 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_STRING;
+ inbind[0].buffer = const_cast<char*>(addr6.c_str());
+ inbind[0].buffer_length = addr6_length;
+ inbind[0].length = &addr6_length;
- return (deleteLease(DELETE_LEASE6, inbind));
+ return (deleteLeaseCommon(DELETE_LEASE6, inbind));
+ }
}
// Miscellaneous database methods.
/// failed.
virtual void updateLease6(const Lease6Ptr& lease6);
- /// @brief Deletes an IPv4 lease.
+ /// @brief Deletes a 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
- ///
- /// @throw isc::dhcp::DbOperationError An operation on the open database has
- /// failed.
- virtual bool deleteLease4(const isc::asiolink::IOAddress& addr);
-
- /// @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.
+ /// @param addr Address of the lease to be deleted. This can be an IPv4
+ /// address or an IPv6 address.
///
/// @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 deleteLease6(const isc::asiolink::IOAddress& addr);
+ virtual bool deleteLease(const isc::asiolink::IOAddress& addr);
/// @brief Return backend type
///
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
- bool deleteLease(StatementIndex stindex, MYSQL_BIND* bind);
+ bool deleteLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind);
/// @brief Check Error and Throw Exception
///
/// @brief Deletes a lease.
///
- /// @param addr IPv4 address of the lease to be deleted.
+ /// @param addr Address of the lease to be deleted. (This can be either
+ /// a V4 address or a V6 address.)
///
/// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease4(const isc::asiolink::IOAddress&) {
- return (false);
- }
-
- /// @brief Deletes a lease.
- ///
- /// @param addr IPv4 address of the lease to be deleted.
- ///
- /// @return true if deletion was successful, false if no such lease exists
- virtual bool deleteLease6(const isc::asiolink::IOAddress&) {
+ virtual bool deleteLease(const isc::asiolink::IOAddress&) {
return (false);
}
EXPECT_FALSE(y);
// should return false - there's no such address
- EXPECT_FALSE(lease_mgr->deleteLease6(IOAddress("2001:db8:1::789")));
+ EXPECT_FALSE(lease_mgr->deleteLease(IOAddress("2001:db8:1::789")));
// this one should succeed
- EXPECT_TRUE(lease_mgr->deleteLease6(IOAddress("2001:db8:1::456")));
+ EXPECT_TRUE(lease_mgr->deleteLease(IOAddress("2001:db8:1::456")));
// after the lease is deleted, it should really be gone
x = lease_mgr->getLease6(IOAddress("2001:db8:1::456"));
/// @brief Basic Lease4 Checks
///
-/// Checks that the addLease, getLease4 (by address) and deleteLease4 works.
+/// Checks that the addLease, getLease4 (by address) and deleteLease (with an
+/// IPv4 address) works.
TEST_F(MySqlLeaseMgrTest, basicLease4) {
// Get the leases to be used for the test.
vector<Lease4Ptr> leases = createLeases4();
// Delete a lease, check that it's gone, and that we can't delete it
// a second time.
- EXPECT_TRUE(lmptr_->deleteLease4(ioaddress4_[1]));
+ EXPECT_TRUE(lmptr_->deleteLease(ioaddress4_[1]));
l_returned = lmptr_->getLease4(ioaddress4_[1]);
EXPECT_FALSE(l_returned);
- EXPECT_FALSE(lmptr_->deleteLease4(ioaddress4_[1]));
+ EXPECT_FALSE(lmptr_->deleteLease(ioaddress4_[1]));
// Check that the second address is still there.
l_returned = lmptr_->getLease4(ioaddress4_[2]);
/// @brief Basic Lease6 Checks
///
-/// Checks that the addLease, getLease6 (by address) and deleteLease6 works.
+/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
+/// IPv6 address) works.
TEST_F(MySqlLeaseMgrTest, basicLease6) {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
// Delete a lease, check that it's gone, and that we can't delete it
// a second time.
- EXPECT_TRUE(lmptr_->deleteLease6(ioaddress6_[1]));
+ EXPECT_TRUE(lmptr_->deleteLease(ioaddress6_[1]));
l_returned = lmptr_->getLease6(ioaddress6_[1]);
EXPECT_FALSE(l_returned);
- EXPECT_FALSE(lmptr_->deleteLease6(ioaddress6_[1]));
+ EXPECT_FALSE(lmptr_->deleteLease(ioaddress6_[1]));
// Check that the second address is still there.
l_returned = lmptr_->getLease6(ioaddress6_[2]);
Lease4Collection returned = lmptr_->getLease4(leases[1]->hwaddr_);
ASSERT_EQ(1, returned.size());
detailCompareLease(leases[1], *returned.begin());
- (void) lmptr_->deleteLease4(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Expect some problem when accessing a lease that had too long a hardware
// "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_));
+ EXPECT_TRUE(lmptr_->deleteLease(leases[2]->addr_));
leases[1]->addr_ = leases[2]->addr_;
EXPECT_TRUE(lmptr_->addLease(leases[1]));
EXPECT_THROW(returned = lmptr_->getLease4(leases[1]->hwaddr_,
// Delete all leases in the database
for (int i = 0; ADDRESS4[i] != NULL; ++i) {
IOAddress addr(ADDRESS4[i]);
- (void) lmptr_->deleteLease4(addr);
+ (void) lmptr_->deleteLease(addr);
}
}
leases[1]->subnet_id_);
ASSERT_TRUE(returned);
detailCompareLease(leases[1], returned);
- (void) lmptr_->deleteLease4(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Expect some error when getting a lease with too long a hardware
Lease4Collection returned = lmptr_->getLease4(*leases[1]->client_id_);
ASSERT_TRUE(returned.size() == 1);
detailCompareLease(leases[1], *returned.begin());
- (void) lmptr_->deleteLease4(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Don't bother to check client IDs longer than the maximum -
leases[1]->iaid_);
EXPECT_EQ(1, returned.size());
detailCompareLease(leases[1], *returned.begin());
- (void) lmptr_->deleteLease6(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Don't bother to check DUIDs longer than the maximum - these cannot be
leases[1]->subnet_id_);
ASSERT_TRUE(returned);
detailCompareLease(leases[1], returned);
- (void) lmptr_->deleteLease6(leases[1]->addr_);
+ (void) lmptr_->deleteLease(leases[1]->addr_);
}
// Don't bother to check DUIDs longer than the maximum - these cannot be
detailCompareLease(leases[1], l_returned);
// Try updating a lease not in the database.
- lmptr_->deleteLease4(ioaddress4_[2]);
+ lmptr_->deleteLease(ioaddress4_[2]);
EXPECT_THROW(lmptr_->updateLease4(leases[2]), isc::dhcp::NoSuchLease);
}