|
@@ -34,13 +34,25 @@ namespace {
|
|
// empty class for now, but may be extended once Addr6 becomes bigger
|
|
// empty class for now, but may be extended once Addr6 becomes bigger
|
|
class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
|
|
class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
|
|
public:
|
|
public:
|
|
|
|
+
|
|
|
|
+ /// @brief memfile lease mgr test constructor
|
|
|
|
+ ///
|
|
|
|
+ /// Creates memfile and stores it in lmptr_ pointer
|
|
MemfileLeaseMgrTest() {
|
|
MemfileLeaseMgrTest() {
|
|
const LeaseMgr::ParameterMap pmap;
|
|
const LeaseMgr::ParameterMap pmap;
|
|
lmptr_ = new Memfile_LeaseMgr(pmap);
|
|
lmptr_ = new Memfile_LeaseMgr(pmap);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ virtual void reopen() {
|
|
|
|
+ /// @todo: write lease to disk, flush, read file from disk
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// @brief destructor
|
|
|
|
+ ///
|
|
|
|
+ /// destroys lease manager backend.
|
|
virtual ~MemfileLeaseMgrTest() {
|
|
virtual ~MemfileLeaseMgrTest() {
|
|
delete lmptr_;
|
|
delete lmptr_;
|
|
|
|
+ lmptr_ = 0;
|
|
}
|
|
}
|
|
|
|
|
|
};
|
|
};
|
|
@@ -57,91 +69,21 @@ TEST_F(MemfileLeaseMgrTest, constructor) {
|
|
|
|
|
|
// Checks if the getType() and getName() methods both return "memfile".
|
|
// Checks if the getType() and getName() methods both return "memfile".
|
|
TEST_F(MemfileLeaseMgrTest, getTypeAndName) {
|
|
TEST_F(MemfileLeaseMgrTest, getTypeAndName) {
|
|
- const LeaseMgr::ParameterMap pmap; // Empty parameter map
|
|
|
|
- boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
|
|
|
|
-
|
|
|
|
- EXPECT_EQ(std::string("memfile"), lease_mgr->getType());
|
|
|
|
- EXPECT_EQ(std::string("memory"), lease_mgr->getName());
|
|
|
|
|
|
+ EXPECT_EQ(std::string("memfile"), lmptr_->getType());
|
|
|
|
+ EXPECT_EQ(std::string("memory"), lmptr_->getName());
|
|
}
|
|
}
|
|
|
|
|
|
// Checks that adding/getting/deleting a Lease6 object works.
|
|
// Checks that adding/getting/deleting a Lease6 object works.
|
|
TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
|
|
TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
|
|
- const LeaseMgr::ParameterMap pmap; // Empty parameter map
|
|
|
|
- boost::scoped_ptr<LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
|
|
|
|
-
|
|
|
|
- IOAddress addr("2001:db8:1::456");
|
|
|
|
-
|
|
|
|
- uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
|
|
|
|
- DuidPtr duid(new DUID(llt, sizeof(llt)));
|
|
|
|
-
|
|
|
|
- uint32_t iaid = 7; // just a number
|
|
|
|
-
|
|
|
|
- SubnetID subnet_id = 8; // just another number
|
|
|
|
-
|
|
|
|
- Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr,
|
|
|
|
- duid, iaid, 100, 200, 50, 80,
|
|
|
|
- subnet_id));
|
|
|
|
-
|
|
|
|
- EXPECT_TRUE(lease_mgr->addLease(lease));
|
|
|
|
-
|
|
|
|
- // should not be allowed to add a second lease with the same address
|
|
|
|
- EXPECT_FALSE(lease_mgr->addLease(lease));
|
|
|
|
-
|
|
|
|
- Lease6Ptr x = lease_mgr->getLease6(Lease::TYPE_NA,
|
|
|
|
- IOAddress("2001:db8:1::234"));
|
|
|
|
- EXPECT_EQ(Lease6Ptr(), x);
|
|
|
|
-
|
|
|
|
- x = lease_mgr->getLease6(Lease::TYPE_NA,
|
|
|
|
- IOAddress("2001:db8:1::456"));
|
|
|
|
- ASSERT_TRUE(x);
|
|
|
|
-
|
|
|
|
- EXPECT_EQ(x->addr_, addr);
|
|
|
|
- EXPECT_TRUE(*x->duid_ == *duid);
|
|
|
|
- EXPECT_EQ(x->iaid_, iaid);
|
|
|
|
- EXPECT_EQ(x->subnet_id_, subnet_id);
|
|
|
|
-
|
|
|
|
- // These are not important from lease management perspective, but
|
|
|
|
- // let's check them anyway.
|
|
|
|
- EXPECT_EQ(x->type_, Lease::TYPE_NA);
|
|
|
|
- EXPECT_EQ(x->preferred_lft_, 100);
|
|
|
|
- EXPECT_EQ(x->valid_lft_, 200);
|
|
|
|
- EXPECT_EQ(x->t1_, 50);
|
|
|
|
- EXPECT_EQ(x->t2_, 80);
|
|
|
|
-
|
|
|
|
- // Test getLease6(duid, iaid, subnet_id) - positive case
|
|
|
|
- Lease6Ptr y = lease_mgr->getLease6(Lease::TYPE_NA, *duid, iaid,
|
|
|
|
- subnet_id);
|
|
|
|
- ASSERT_TRUE(y);
|
|
|
|
- EXPECT_TRUE(*y->duid_ == *duid);
|
|
|
|
- EXPECT_EQ(y->iaid_, iaid);
|
|
|
|
- EXPECT_EQ(y->addr_, addr);
|
|
|
|
-
|
|
|
|
- // Test getLease6(duid, iaid, subnet_id) - wrong iaid
|
|
|
|
- uint32_t invalid_iaid = 9; // no such iaid
|
|
|
|
- y = lease_mgr->getLease6(Lease::TYPE_NA, *duid, invalid_iaid,
|
|
|
|
- subnet_id);
|
|
|
|
- EXPECT_FALSE(y);
|
|
|
|
-
|
|
|
|
- uint32_t invalid_subnet_id = 999;
|
|
|
|
- y = lease_mgr->getLease6(Lease::TYPE_NA, *duid, iaid,
|
|
|
|
- invalid_subnet_id);
|
|
|
|
- EXPECT_FALSE(y);
|
|
|
|
-
|
|
|
|
- // truncated duid
|
|
|
|
- DuidPtr invalid_duid(new DUID(llt, sizeof(llt) - 1));
|
|
|
|
- y = lease_mgr->getLease6(Lease::TYPE_NA, *invalid_duid, iaid,
|
|
|
|
- subnet_id);
|
|
|
|
- EXPECT_FALSE(y);
|
|
|
|
-
|
|
|
|
- // should return false - there's no such address
|
|
|
|
- EXPECT_FALSE(lease_mgr->deleteLease(IOAddress("2001:db8:1::789")));
|
|
|
|
-
|
|
|
|
- // this one should succeed
|
|
|
|
- EXPECT_TRUE(lease_mgr->deleteLease(IOAddress("2001:db8:1::456")));
|
|
|
|
|
|
+ testAddGetDelete6(true);
|
|
|
|
+}
|
|
|
|
|
|
- // after the lease is deleted, it should really be gone
|
|
|
|
- x = lease_mgr->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::456"));
|
|
|
|
- EXPECT_EQ(Lease6Ptr(), x);
|
|
|
|
|
|
+/// @brief Basic Lease4 Checks
|
|
|
|
+///
|
|
|
|
+/// Checks that the addLease, getLease4 (by address) and deleteLease (with an
|
|
|
|
+/// IPv4 address) works.
|
|
|
|
+TEST_F(MemfileLeaseMgrTest, basicLease4) {
|
|
|
|
+ testBasicLease4();
|
|
}
|
|
}
|
|
|
|
|
|
/// @todo Write more memfile tests
|
|
/// @todo Write more memfile tests
|