/// @return lease collection
virtual Lease4Collection getLease4(const ClientId& clientid) const = 0;
+ /// @brief Returns existing IPv4 lease for a given client identifier,
+ /// HW address and subnet identifier.
+ ///
+ /// @todo Consider whether this function is needed or not. In the basic
+ /// DHCPv4 server implementation it is not used by the allocation engine.
+ ///
+ /// @param client_id A client identifier.
+ /// @param hwaddr Hardware address.
+ /// @param subnet_id A subnet identifier.
+ ///
+ /// @return A pointer to the lease or NULL if the lease is not found.
+ virtual Lease4Ptr getLease4(const ClientId& clientid, const HWAddr& hwaddr,
+ SubnetID subnet_id) const = 0;
+
/// @brief Returns existing IPv4 lease for specified client-id
///
/// There can be at most one lease for a given HW address in a single
return (result);
}
+Lease4Ptr
+MySqlLeaseMgr::getLease4(const ClientId&, const HWAddr&, SubnetID) const {
+ /// This function is currently not implemented because allocation engine
+ /// searches for the lease using HW address or client identifier.
+ /// It never uses both parameters in the same time. We need to
+ /// consider if this function is needed at all.
+ isc_throw(NotImplemented, "The MySqlLeaseMgr::getLease4 function was"
+ " called, but it is not implemented");
+}
Lease4Ptr
MySqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const {
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
/// failed.
virtual Lease4Collection getLease4(const ClientId& clientid) const;
+ /// @brief Returns IPv4 lease for the specified client identifier, HW
+ /// address and subnet identifier.
+ ///
+ /// @param client_id A client identifier.
+ /// @param hwaddr Hardware address.
+ /// @param subnet_id A subnet identifier.
+ ///
+ /// @return A pointer to the lease or NULL if the lease is not found.
+ /// @throw isc::NotImplemented On every call as this function is currently
+ /// not implemented for the MySQL backend.
+ virtual Lease4Ptr getLease4(const ClientId& client_id, const HWAddr& hwaddr,
+ SubnetID subnet_id) const;
+
/// @brief Returns existing IPv4 lease for specified client-id
///
/// There can be at most one lease for a given HW address in a single
return (Lease4Collection());
}
+ /// @brief Returns existing IPv4 lease for specified client identifier,
+ /// HW address and subnet identifier.
+ ///
+ /// @param client_id Aclient identifier
+ /// @param hwaddr A HW address.
+ /// @param subnet_id A subnet identifier.
+ ///
+ /// @return A pointer to an existing lease or NULL if lease not found.
+ virtual Lease4Ptr
+ getLease4(const ClientId&, const HWAddr&, SubnetID) const {
+ return (Lease4Ptr());
+ }
+
/// @brief Returns existing IPv4 lease for specified client-id
///
/// There can be at most one lease for a given HW address in a single
class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
public:
MemfileLeaseMgrTest() {
+ const LeaseMgr::ParameterMap pmap;
+ lmptr_ = new Memfile_LeaseMgr(pmap);
}
+
+ virtual ~MemfileLeaseMgrTest() {
+ delete lmptr_;
+ }
+
};
// This test checks if the LeaseMgr can be instantiated and that it
// Simple test about lease4 retrieval through client id method
TEST_F(MemfileLeaseMgrTest, getLease4ClientId) {
- const LeaseMgr::ParameterMap pmap;
- boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
- // Let's initialize a specific lease ...
- Lease4Ptr lease = initializeLease4(straddress4_[1]);
- EXPECT_TRUE(lease_mgr->addLease(lease));
- Lease4Collection returned = lease_mgr->getLease4(*lease->client_id_);
-
- ASSERT_EQ(1, returned.size());
- // We should retrieve our lease...
- detailCompareLease(lease, *returned.begin());
- lease = initializeLease4(straddress4_[2]);
- returned = lease_mgr->getLease4(*lease->client_id_);
-
- ASSERT_EQ(0, returned.size());
+ testGetLease4ClientId();
}
// Checks that lease4 retrieval client id is null is working
TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
- const LeaseMgr::ParameterMap pmap;
- boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
- // Let's initialize a specific lease ... But this time
- // We keep its client id for further lookup and
- // We clearly 'reset' it ...
- Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
- ClientIdPtr client_id = leaseA->client_id_;
- leaseA->client_id_ = ClientIdPtr();
- ASSERT_TRUE(lease_mgr->addLease(leaseA));
-
- Lease4Collection returned = lease_mgr->getLease4(*client_id);
- // Shouldn't have our previous lease ...
- ASSERT_TRUE(returned.empty());
-
- // Add another lease with the non-NULL client id, and make sure that the
- // lookup will not break due to existence of both leases with non-NULL and
- // NULL client ids.
- Lease4Ptr leaseB = initializeLease4(straddress4_[0]);
- // Shouldn't throw any null pointer exception
- ASSERT_TRUE(lease_mgr->addLease(leaseB));
- // Try to get the lease.
- returned = lease_mgr->getLease4(*client_id);
- ASSERT_TRUE(returned.empty());
-
- // Let's make it more interesting and add another lease with NULL client id.
- Lease4Ptr leaseC = initializeLease4(straddress4_[5]);
- leaseC->client_id_.reset();
- ASSERT_TRUE(lease_mgr->addLease(leaseC));
- returned = lease_mgr->getLease4(*client_id);
- ASSERT_TRUE(returned.empty());
-
- // But getting the lease with non-NULL client id should be successful.
- returned = lease_mgr->getLease4(*leaseB->client_id_);
- ASSERT_EQ(1, returned.size());
+ testGetLease4NullClientId();
}
// Checks lease4 retrieval through HWAddr
TEST_F(MemfileLeaseMgrTest, getLease4HWAddr) {
- const LeaseMgr::ParameterMap pmap;
- boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
- // Let's initialize two different leases 4 and just add the first ...
- Lease4Ptr leaseA = initializeLease4(straddress4_[5]);
- HWAddr hwaddrA(leaseA->hwaddr_, HTYPE_ETHER);
- HWAddr hwaddrB(vector<uint8_t>(6, 0x80), HTYPE_ETHER);
-
- EXPECT_TRUE(lease_mgr->addLease(leaseA));
-
- // we should not have a lease, with this MAC Addr
- Lease4Collection returned = lease_mgr->getLease4(hwaddrB);
- ASSERT_EQ(0, returned.size());
-
- // But with this one
- returned = lease_mgr->getLease4(hwaddrA);
- ASSERT_EQ(1, returned.size());
+ testGetLease4HWAddr();
}
// Checks lease4 retrieval with clientId, HWAddr and subnet_id
TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
- const LeaseMgr::ParameterMap pmap;
- boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
-
- Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
- Lease4Ptr leaseB = initializeLease4(straddress4_[5]);
- Lease4Ptr leaseC = initializeLease4(straddress4_[6]);
- // Set NULL client id for one of the leases. This is to make sure that such
- // a lease may coexist with other leases with non NULL client id.
- leaseC->client_id_.reset();
-
- HWAddr hwaddrA(leaseA->hwaddr_, HTYPE_ETHER);
- HWAddr hwaddrB(leaseB->hwaddr_, HTYPE_ETHER);
- HWAddr hwaddrC(leaseC->hwaddr_, HTYPE_ETHER);
- EXPECT_TRUE(lease_mgr->addLease(leaseA));
- EXPECT_TRUE(lease_mgr->addLease(leaseB));
- EXPECT_TRUE(lease_mgr->addLease(leaseC));
- // First case we should retrieve our lease
- Lease4Ptr lease = lease_mgr->getLease4(*leaseA->client_id_, hwaddrA, leaseA->subnet_id_);
- detailCompareLease(lease, leaseA);
- // Retrieve the other lease.
- lease = lease_mgr->getLease4(*leaseB->client_id_, hwaddrB, leaseB->subnet_id_);
- detailCompareLease(lease, leaseB);
- // The last lease has NULL client id so we will use a different getLease4 function
- // which doesn't require client id (just a hwaddr and subnet id).
- lease = lease_mgr->getLease4(hwaddrC, leaseC->subnet_id_);
- detailCompareLease(lease, leaseC);
-
- // An attempt to retrieve the lease with non matching lease parameters should
- // result in NULL pointer being returned.
- lease = lease_mgr->getLease4(*leaseA->client_id_, hwaddrB, leaseA->subnet_id_);
- EXPECT_FALSE(lease);
- lease = lease_mgr->getLease4(*leaseA->client_id_, hwaddrA, leaseB->subnet_id_);
- EXPECT_FALSE(lease);
+ testGetLease4ClientIdHWAddrSubnetId();
}
}; // end of anonymous namespace
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
EXPECT_EQ(first->hostname_, second->hostname_);
}
-
GenericLeaseMgrTest::GenericLeaseMgrTest()
- :lmptr_(NULL) {
+ : lmptr_(NULL) {
// Initialize address strings and IOAddresses
for (int i = 0; ADDRESS4[i] != NULL; ++i) {
string addr(ADDRESS4[i]);
}
}
+GenericLeaseMgrTest::~GenericLeaseMgrTest() {
+ // Does nothing. The derived classes are expected to clean up, i.e.
+ // remove the lmptr_ pointer.
+}
+
/// @brief Initialize Lease4 Fields
///
/// Returns a pointer to a Lease4 structure. Different values are put into
return (leases);
}
+void
+GenericLeaseMgrTest::testGetLease4ClientId() {
+ // Let's initialize a specific lease ...
+ Lease4Ptr lease = initializeLease4(straddress4_[1]);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+ Lease4Collection returned = lmptr_->getLease4(*lease->client_id_);
+
+ ASSERT_EQ(1, returned.size());
+ // We should retrieve our lease...
+ detailCompareLease(lease, *returned.begin());
+ lease = initializeLease4(straddress4_[2]);
+ returned = lmptr_->getLease4(*lease->client_id_);
+
+ ASSERT_EQ(0, returned.size());
+}
+
+void
+GenericLeaseMgrTest::testGetLease4NullClientId() {
+ // Let's initialize a specific lease ... But this time
+ // We keep its client id for further lookup and
+ // We clearly 'reset' it ...
+ Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
+ ClientIdPtr client_id = leaseA->client_id_;
+ leaseA->client_id_ = ClientIdPtr();
+ ASSERT_TRUE(lmptr_->addLease(leaseA));
+
+ Lease4Collection returned = lmptr_->getLease4(*client_id);
+ // Shouldn't have our previous lease ...
+ ASSERT_TRUE(returned.empty());
+
+ // Add another lease with the non-NULL client id, and make sure that the
+ // lookup will not break due to existence of both leases with non-NULL and
+ // NULL client ids.
+ Lease4Ptr leaseB = initializeLease4(straddress4_[0]);
+ // Shouldn't throw any null pointer exception
+ ASSERT_TRUE(lmptr_->addLease(leaseB));
+ // Try to get the lease.
+ returned = lmptr_->getLease4(*client_id);
+ ASSERT_TRUE(returned.empty());
+
+ // Let's make it more interesting and add another lease with NULL client id.
+ Lease4Ptr leaseC = initializeLease4(straddress4_[5]);
+ leaseC->client_id_.reset();
+ ASSERT_TRUE(lmptr_->addLease(leaseC));
+ returned = lmptr_->getLease4(*client_id);
+ ASSERT_TRUE(returned.empty());
+
+ // But getting the lease with non-NULL client id should be successful.
+ returned = lmptr_->getLease4(*leaseB->client_id_);
+ ASSERT_EQ(1, returned.size());
+}
+
+void
+GenericLeaseMgrTest::testGetLease4HWAddr() {
+ const LeaseMgr::ParameterMap pmap;
+ // Let's initialize two different leases 4 and just add the first ...
+ Lease4Ptr leaseA = initializeLease4(straddress4_[5]);
+ HWAddr hwaddrA(leaseA->hwaddr_, HTYPE_ETHER);
+ HWAddr hwaddrB(vector<uint8_t>(6, 0x80), HTYPE_ETHER);
+
+ EXPECT_TRUE(lmptr_->addLease(leaseA));
+
+ // we should not have a lease, with this MAC Addr
+ Lease4Collection returned = lmptr_->getLease4(hwaddrB);
+ ASSERT_EQ(0, returned.size());
+
+ // But with this one
+ returned = lmptr_->getLease4(hwaddrA);
+ ASSERT_EQ(1, returned.size());
+}
+
+void
+GenericLeaseMgrTest::testLease4ClientIdHWAddrSubnetId() {
+ Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
+ Lease4Ptr leaseB = initializeLease4(straddress4_[5]);
+ Lease4Ptr leaseC = initializeLease4(straddress4_[6]);
+ // Set NULL client id for one of the leases. This is to make sure that such
+ // a lease may coexist with other leases with non NULL client id.
+ leaseC->client_id_.reset();
+
+ HWAddr hwaddrA(leaseA->hwaddr_, HTYPE_ETHER);
+ HWAddr hwaddrB(leaseB->hwaddr_, HTYPE_ETHER);
+ HWAddr hwaddrC(leaseC->hwaddr_, HTYPE_ETHER);
+ EXPECT_TRUE(lmptr_->addLease(leaseA));
+ EXPECT_TRUE(lmptr_->addLease(leaseB));
+ EXPECT_TRUE(lmptr_->addLease(leaseC));
+ // First case we should retrieve our lease
+ Lease4Ptr lease = lmptr_->getLease4(*leaseA->client_id_, hwaddrA, leaseA->subnet_id_);
+ detailCompareLease(lease, leaseA);
+ // Retrieve the other lease.
+ lease = lmptr_->getLease4(*leaseB->client_id_, hwaddrB, leaseB->subnet_id_);
+ detailCompareLease(lease, leaseB);
+ // The last lease has NULL client id so we will use a different getLease4 function
+ // which doesn't require client id (just a hwaddr and subnet id).
+ lease = lmptr_->getLease4(hwaddrC, leaseC->subnet_id_);
+ detailCompareLease(lease, leaseC);
+
+ // An attempt to retrieve the lease with non matching lease parameters should
+ // result in NULL pointer being returned.
+ lease = lmptr_->getLease4(*leaseA->client_id_, hwaddrB, leaseA->subnet_id_);
+ EXPECT_FALSE(lease);
+ lease = lmptr_->getLease4(*leaseA->client_id_, hwaddrA, leaseB->subnet_id_);
+ EXPECT_FALSE(lease);
+}
+
+
};
};
};
-// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
/// All concrete LeaseMgr test classes should be derived from it.
class GenericLeaseMgrTest : public ::testing::Test {
public:
+
+ /// @brief Default constructor.
GenericLeaseMgrTest();
+ /// @brief Virtual destructor.
+ virtual ~GenericLeaseMgrTest();
+
/// @brief Initialize Lease4 Fields
///
/// Returns a pointer to a Lease4 structure. Different values are put into
///
/// @param leases Vector of pointers to leases
template <typename T>
- void checkLeasesDifferent(const std::vector<T>& leases) const;
+ void checkLeasesDifferent(const std::vector<T>& leases) const;
/// @brief Creates leases for the test
///
/// @return vector<Lease6Ptr> Vector of pointers to leases
std::vector<Lease6Ptr> createLeases6();
+ /// @brief Test lease retrieval using client id.
+ void testGetLease4ClientId();
+
+ /// @brief Test lease retrieval when leases with NULL client id are present.
+ void testGetLease4NullClientId();
+
+ /// @brief Test lease retrieval using HW address.
+ void testGetLease4HWAddr();
+
+ /// @brief Test lease retrieval using client id, HW address and subnet id.
+ void testLease4ClientIdHWAddrSubnetId();
+
// Member variables
std::vector<std::string> straddress4_; ///< String forms of IPv4 addresses
std::vector<isc::asiolink::IOAddress> ioaddress4_; ///< IOAddress forms of IPv4 addresses
std::vector<Lease::Type> leasetype6_; ///< Lease types
std::vector<isc::asiolink::IOAddress> ioaddress6_; ///< IOAddress forms of IPv6 addresses
- LeaseMgr* lmptr_; ///< Pointer to the lease manager
+ LeaseMgr* lmptr_; ///< Pointer to the lease manager
};
};