|
@@ -35,7 +35,14 @@ namespace {
|
|
class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
|
|
class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
|
|
public:
|
|
public:
|
|
MemfileLeaseMgrTest() {
|
|
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
|
|
// This test checks if the LeaseMgr can be instantiated and that it
|
|
@@ -141,115 +148,22 @@ TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
|
|
|
|
|
|
// Simple test about lease4 retrieval through client id method
|
|
// Simple test about lease4 retrieval through client id method
|
|
TEST_F(MemfileLeaseMgrTest, getLease4ClientId) {
|
|
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
|
|
// Checks that lease4 retrieval client id is null is working
|
|
TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
|
|
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
|
|
// Checks lease4 retrieval through HWAddr
|
|
TEST_F(MemfileLeaseMgrTest, getLease4HWAddr) {
|
|
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
|
|
// Checks lease4 retrieval with clientId, HWAddr and subnet_id
|
|
TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
|
|
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
|
|
}; // end of anonymous namespace
|