diff options
Diffstat (limited to 'src/lib/dhcpsrv')
-rw-r--r-- | src/lib/dhcpsrv/memfile_lease_mgr.cc | 104 | ||||
-rw-r--r-- | src/lib/dhcpsrv/memfile_lease_storage.h | 4 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc | 490 |
3 files changed, 174 insertions, 424 deletions
diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 4a0dc246a3..02e6e5b801 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -2487,6 +2487,17 @@ Memfile_LeaseMgr::getLeases4ByRelayId(const OptionBuffer& relay_id, << lower_bound_address); } + // Catch 2038 bug with 32 bit time_t. + if ((qry_start_time < 0) || (qry_end_time < 0)) { + isc_throw(BadValue, "negative time value"); + } + + // Start time must be before end time. + if ((qry_start_time > 0) && (qry_end_time > 0) && + (qry_start_time > qry_end_time)) { + isc_throw(BadValue, "start time must be before end time"); + } + LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_RELAYID4) .arg(page_size.page_size_) @@ -2512,12 +2523,41 @@ Memfile_LeaseMgr::getLeases4ByRelayId(const OptionBuffer& relay_id, } Lease4Collection -Memfile_LeaseMgr::getLeases4ByRelayIdInternal(const OptionBuffer&, - const IOAddress&, - const LeasePageSize&, - const time_t&, - const time_t&) { - isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases4ByRelayId not implemented"); +Memfile_LeaseMgr::getLeases4ByRelayIdInternal(const OptionBuffer& relay_id, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size, + const time_t& qry_start_time, + const time_t& qry_end_time) { + Lease4Collection collection; + const Lease4StorageRelayIdIndex& idx = storage4_.get<RelayIdIndexTag>(); + Lease4StorageRelayIdIndex::const_iterator lb = + idx.lower_bound(boost::make_tuple(relay_id, lower_bound_address)); + // Return all convenient leases being within the page size. + IOAddress last_addr = lower_bound_address; + for (; lb != idx.end(); ++lb) { + if ((*lb)->addr_ == last_addr) { + // Already seen: skip it. + continue; + } + if ((*lb)->relay_id_ != relay_id) { + // Gone after the relay id index. + break; + } + last_addr = (*lb)->addr_; + if ((qry_start_time > 0) && ((*lb)->cltt_ < qry_start_time)) { + // Too old. + continue; + } + if ((qry_end_time > 0) && ((*lb)->cltt_ < qry_end_time)) { + // Too young. + continue; + } + collection.push_back(Lease4Ptr(new Lease4(**lb))); + if (collection.size() >= page_size.page_size_) { + break; + } + } + return (collection); } Lease4Collection @@ -2533,6 +2573,17 @@ Memfile_LeaseMgr::getLeases4ByRemoteId(const OptionBuffer& remote_id, << lower_bound_address); } + // Catch 2038 bug with 32 bit time_t. + if ((qry_start_time < 0) || (qry_end_time < 0)) { + isc_throw(BadValue, "negative time value"); + } + + // Start time must be before end time. + if ((qry_start_time > 0) && (qry_end_time > 0) && + (qry_start_time > qry_end_time)) { + isc_throw(BadValue, "start time must be before end time"); + } + LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_REMOTEID4) .arg(page_size.page_size_) @@ -2558,12 +2609,41 @@ Memfile_LeaseMgr::getLeases4ByRemoteId(const OptionBuffer& remote_id, } Lease4Collection -Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(const OptionBuffer&, - const IOAddress&, - const LeasePageSize&, - const time_t&, - const time_t&) { - isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases4ByRemoteId not implemented"); +Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(const OptionBuffer& remote_id, + const IOAddress& lower_bound_address, + const LeasePageSize& page_size, + const time_t& qry_start_time, + const time_t& qry_end_time) { + Lease4Collection collection; + std::map<IOAddress, Lease4Ptr> sorted; + const Lease4StorageRemoteIdIndex& idx = storage4_.get<RemoteIdIndexTag>(); + Lease4StorageRemoteIdRange er = idx.equal_range(remote_id); + // Store all convenient leases being within the page size. + for (auto it = er.first; it != er.second; ++it) { + const IOAddress& addr = (*it)->addr_; + if (addr <= lower_bound_address) { + // Not greater than lower_bound_address. + continue; + } + if ((qry_start_time > 0) && ((*it)->cltt_ < qry_start_time)) { + // Too old. + continue; + } + if ((qry_end_time > 0) && ((*it)->cltt_ < qry_end_time)) { + // Too young. + continue; + } + sorted[addr] = *it; + } + + // Return all leases being within the page size. + for (auto it : sorted) { + collection.push_back(Lease4Ptr(new Lease4(*it.second))); + if (collection.size() >= page_size.page_size_) { + break; + } + } + return (collection); } Lease6Collection diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index bfff724ac4..285be092c6 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -323,6 +323,10 @@ typedef Lease4Storage::index<HostnameIndexTag>::type Lease4StorageHostnameIndex; /// @brief DHCPv4 lease storage index by remote identifier. typedef Lease4Storage::index<RemoteIdIndexTag>::type Lease4StorageRemoteIdIndex; +/// @brief DHCPv4 lease storage range by remote identifier. +typedef std::pair<Lease4StorageRemoteIdIndex::const_iterator, + Lease4StorageRemoteIdIndex::const_iterator> Lease4StorageRemoteIdRange; + /// @brief DHCPv4 lease storage index by relay identifier. typedef Lease4Storage::index<RelayIdIndexTag>::type Lease4StorageRelayIdIndex; diff --git a/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc index aac944cdc1..8c04c13f67 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc @@ -26,6 +26,12 @@ using namespace std; namespace { +/// @brief IPv4 addresses used in the tests. +const vector<string> 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" +}; + /// @brief IPv6 addresses used in the tests. const vector<string> ADDRESS6 = { "2001:db8::0", "2001:db8::1", "2001:db8::2", "2001:db8::3", @@ -33,7 +39,7 @@ const vector<string> ADDRESS6 = { }; /// @brief DUIDs used in the tests. -const vector<string> DUID6 = { +const vector<string> DUIDS = { "wwwwwwww", "BBBBBBBB", "::::::::", "0123456789acdef", "BBBBBBBB", "$$$$$$$$", "^^^^^^^^", "\xe5\xe5\xe5\xe5\xe5\xe5\xe5\xe5" }; @@ -73,6 +79,7 @@ public: MemfileExtendedInfoTest() { pmap_.clear(); lease_mgr_.reset(); + leases4.clear(); leases6.clear(); MultiThreadingMgr::instance().setMode(false); } @@ -81,6 +88,7 @@ public: ~MemfileExtendedInfoTest() { pmap_.clear(); lease_mgr_.reset(); + leases4.clear(); leases6.clear(); MultiThreadingMgr::instance().setMode(false); } @@ -100,10 +108,10 @@ public: /// @brief Create and set v6 leases. void initLease6() { - ASSERT_EQ(ADDRESS6.size(), DUID6.size()); + ASSERT_EQ(ADDRESS6.size(), DUIDS.size()); for (size_t i = 0; i < ADDRESS6.size(); ++i) { Lease6Ptr lease; - vector<uint8_t> duid_data = createFromString(DUID6[i]); + vector<uint8_t> duid_data = createFromString(DUIDS[i]); DuidPtr duid(new DUID(duid_data)); IOAddress addr(ADDRESS6[i]); ASSERT_NO_THROW(lease.reset(new Lease6(((i % 2) ? Lease::TYPE_NA : Lease::TYPE_PD), addr, duid, @@ -126,12 +134,27 @@ public: return (v); } + /// @brief Test initLease6. + void testInitLease6(); + + /// @brief Test getLeases6ByRelayId. + void testGetLeases6ByRelayId(); + + /// @brief Test getLeases6ByRemoteId. + void testGetLeases6ByRemoteId(); + + /// @brief Test getLeases6ByLink. + void testGetLeases6ByLink(); + /// @brief Parameter map. DatabaseConnection::ParameterMap pmap_; /// @brief Lease manager. NakedMemfileLeaseMgrPtr lease_mgr_; + /// @brief V4 leases. + Lease4Collection leases4; + /// @brief V6 leases. Lease6Collection leases6; }; @@ -159,7 +182,8 @@ TEST_F(MemfileExtendedInfoTest, startV6MultiThreading) { } /// @brief Verifies that the lease manager can add the v6 leases. -TEST_F(MemfileExtendedInfoTest, initLease6) { +void +MemfileExtendedInfoTest::testInitLease6() { start(Memfile_LeaseMgr::V6); initLease6(); EXPECT_EQ(8, leases6.size()); @@ -176,23 +200,13 @@ TEST_F(MemfileExtendedInfoTest, initLease6) { } } -/// @brief Verifies that the lease manager can add the v6 leases with MT. +TEST_F(MemfileExtendedInfoTest, initLease6) { + testInitLease6(); +} + TEST_F(MemfileExtendedInfoTest, initLease6MultiThreading) { MultiThreadingTest mt(true); - start(Memfile_LeaseMgr::V6); - initLease6(); - EXPECT_EQ(8, leases6.size()); - Lease6Collection got; - EXPECT_NO_THROW(got = lease_mgr_->getLeases6()); - ASSERT_EQ(leases6.size(), got.size()); - for (size_t i = 0; i < leases6.size(); ++i) { - ConstElementPtr expected = leases6[i]->toElement(); - LeasePtr lease = got[i]; - ASSERT_TRUE(lease); - EXPECT_TRUE(expected->equals(*lease->toElement())) - << "expected: " << expected->str() << "\n" - << "got: " << lease->toElement()->str() << "\n"; - } + testInitLease6(); } /// @brief Verifies that add and delete work on the by relay id table. @@ -206,8 +220,8 @@ TEST_F(MemfileExtendedInfoTest, relayIdTable6) { IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); IOAddress other_lease_addr("2001:db8:1::4"); - vector<uint8_t> relay_id0 = createFromString(DUID6[0]); - vector<uint8_t> relay_id1 = createFromString(DUID6[1]); + vector<uint8_t> relay_id0 = createFromString(DUIDS[0]); + vector<uint8_t> relay_id1 = createFromString(DUIDS[1]); // Fill the table. EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id0)); @@ -250,8 +264,8 @@ TEST_F(MemfileExtendedInfoTest, remoteIdTable6) { IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); IOAddress other_lease_addr("2001:db8:1::4"); - vector<uint8_t> remote_id0 = createFromString(DUID6[0]); - vector<uint8_t> remote_id1 = createFromString(DUID6[1]); + vector<uint8_t> remote_id0 = createFromString(DUIDS[0]); + vector<uint8_t> remote_id1 = createFromString(DUIDS[1]); // Fill the table. EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id0)); @@ -284,7 +298,8 @@ TEST_F(MemfileExtendedInfoTest, remoteIdTable6) { } /// @brief Verifies that getLeases6ByRelayId works as expected. -TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { +void +MemfileExtendedInfoTest::testGetLeases6ByRelayId() { // Lease manager is created with empty tables. start(Memfile_LeaseMgr::V6); initLease6(); @@ -297,11 +312,11 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { IOAddress link_addr(ADDRESS6[4]); IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - vector<uint8_t> relay_id_data0 = createFromString(DUID6[0]); + vector<uint8_t> relay_id_data0 = createFromString(DUIDS[0]); DUID relay_id0(relay_id_data0); - vector<uint8_t> relay_id_data1 = createFromString(DUID6[1]); + vector<uint8_t> relay_id_data1 = createFromString(DUIDS[1]); DUID relay_id1(relay_id_data1); - vector<uint8_t> relay_id_data2 = createFromString(DUID6[2]); + vector<uint8_t> relay_id_data2 = createFromString(DUIDS[2]); DUID relay_id2(relay_id_data2); // Fill the table. @@ -440,166 +455,18 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { EXPECT_EQ(0, got.size()); } -/// @brief Verifies that getLeases6ByRelayId works as expected with MT. +TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { + testGetLeases6ByRelayId(); +} + TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { MultiThreadingTest mt(true); - // Lease manager is created with empty tables. - start(Memfile_LeaseMgr::V6); - initLease6(); - EXPECT_EQ(0, lease_mgr_->relay_id6_.size()); - - // Create parameter values. - IOAddress lease_addr0(ADDRESS6[0]); - IOAddress lease_addr1(ADDRESS6[1]); - IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr(ADDRESS6[4]); - IOAddress other_link_addr("2001:db8:1::4"); - IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - vector<uint8_t> relay_id_data0 = createFromString(DUID6[0]); - DUID relay_id0(relay_id_data0); - vector<uint8_t> relay_id_data1 = createFromString(DUID6[1]); - DUID relay_id1(relay_id_data1); - vector<uint8_t> relay_id_data2 = createFromString(DUID6[2]); - DUID relay_id2(relay_id_data2); - - // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id_data1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, relay_id_data1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr2, relay_id_data1)); - EXPECT_EQ(6, lease_mgr_->relay_id6_.size()); - - Lease6Collection got; - // Unknown relay id #2, no link: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id2, - zero, - 0, - zero, - LeasePageSize(100))); - EXPECT_EQ(0, got.size()); - - // Unknown relay id #2, link: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id2, - link_addr, - 64, - zero, - LeasePageSize(100))); - EXPECT_EQ(0, got.size()); - - // Relay id #0, other link: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id0, - other_link_addr, - 64, - zero, - LeasePageSize(100))); - EXPECT_EQ(0, got.size()); - - // Relay id #0, no link: 3 entries but 2 addresses. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id0, - zero, - 0, - zero, - LeasePageSize(100))); - ASSERT_EQ(2, got.size()); - Lease6Ptr lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - lease = got[1]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - - // Relay id #1, no link, partial: 2 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - zero, - 0, - zero, - LeasePageSize(2))); - ASSERT_EQ(2, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - lease = got[1]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - - // Relay id #1, no link, partial from previous: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - zero, - 0, - lease->addr_, - LeasePageSize(2))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, lease->addr_); - - // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id_data1)); - EXPECT_EQ(7, lease_mgr_->relay_id6_.size()); - - // Relay id #1, link: 3 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr, - 64, - zero, - LeasePageSize(100))); - ASSERT_EQ(3, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - lease = got[1]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - lease = got[2]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, lease->addr_); - - // Relay id #1, link, initial partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr, - 64, - zero, - LeasePageSize(1))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - - // Relay id #1, link, next partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr, - 64, - lease->addr_, - LeasePageSize(1))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - - // Relay id #1, link, next partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr, - 64, - lease->addr_, - LeasePageSize(1))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, lease->addr_); - - // Relay id #1, link, final partial: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr, - 64, - lease->addr_, - LeasePageSize(1))); - EXPECT_EQ(0, got.size()); + testGetLeases6ByRelayId(); } /// @brief Verifies that getLeases6ByRemoteId works as expected. -TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { +void +MemfileExtendedInfoTest::testGetLeases6ByRemoteId() { // Lease manager is created with empty tables. start(Memfile_LeaseMgr::V6); initLease6(); @@ -612,9 +479,9 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { IOAddress link_addr(ADDRESS6[4]); IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - vector<uint8_t> remote_id0 = createFromString(DUID6[0]); - vector<uint8_t> remote_id1 = createFromString(DUID6[1]); - vector<uint8_t> remote_id2 = createFromString(DUID6[2]); + vector<uint8_t> remote_id0 = createFromString(DUIDS[0]); + vector<uint8_t> remote_id1 = createFromString(DUIDS[1]); + vector<uint8_t> remote_id2 = createFromString(DUIDS[2]); // Fill the table. EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id0)); @@ -752,163 +619,18 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { EXPECT_EQ(0, got.size()); } -/// @brief Verifies that getLeases6ByRemoteId works as expected with MT. +TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { + testGetLeases6ByRemoteId(); +} + TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteIdMultiThreading) { MultiThreadingTest mt(true); - // Lease manager is created with empty tables. - start(Memfile_LeaseMgr::V6); - initLease6(); - EXPECT_EQ(0, lease_mgr_->remote_id6_.size()); - - // Create parameter values. - IOAddress lease_addr0(ADDRESS6[0]); - IOAddress lease_addr1(ADDRESS6[1]); - IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr(ADDRESS6[4]); - IOAddress other_link_addr("2001:db8:1::4"); - IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - vector<uint8_t> remote_id0 = createFromString(DUID6[0]); - vector<uint8_t> remote_id1 = createFromString(DUID6[1]); - vector<uint8_t> remote_id2 = createFromString(DUID6[2]); - - // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr2, remote_id1)); - EXPECT_EQ(6, lease_mgr_->remote_id6_.size()); - - Lease6Collection got; - // Unknown remote id #2, no link: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id2, - zero, - 0, - zero, - LeasePageSize(10))); - EXPECT_EQ(0, got.size()); - - // Unknown remote id #2, link: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id2, - link_addr, - 64, - zero, - LeasePageSize(10))); - EXPECT_EQ(0, got.size()); - - // Remote id #0, other link: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id0, - other_link_addr, - 64, - zero, - LeasePageSize(10))); - EXPECT_EQ(0, got.size()); - - // Remote id #0, no link: 3 entries but 2 addresses. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id0, - zero, - 0, - zero, - LeasePageSize(10))); - ASSERT_EQ(2, got.size()); - Lease6Ptr lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - lease = got[1]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - - // Remote id #1, no link, partial: 2 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - zero, - 0, - zero, - LeasePageSize(2))); - ASSERT_EQ(2, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - lease = got[1]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - - // Remote id #1, no link, partial from previous: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - zero, - 0, - lease->addr_, - LeasePageSize(2))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, lease->addr_); - - // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id1)); - EXPECT_EQ(7, lease_mgr_->remote_id6_.size()); - - // Remote id #1, link: 3 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr, - 64, - zero, - LeasePageSize(10))); - ASSERT_EQ(3, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - lease = got[1]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - lease = got[2]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, lease->addr_); - - // Remote id #1, link, initial partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr, - 64, - zero, - LeasePageSize(1))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, lease->addr_); - - // Remote id #1, link, next partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr, - 64, - lease->addr_, - LeasePageSize(1))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr1, lease->addr_); - - // Remote id #1, link, next partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr, - 64, - lease->addr_, - LeasePageSize(1))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, lease->addr_); - - // Remote id #1, link, final partial: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr, - 64, - lease->addr_, - LeasePageSize(1))); - EXPECT_EQ(0, got.size()); + testGetLeases6ByRemoteId(); } /// @brief Verifies that getLeases6ByLink works as expected. -TEST_F(MemfileExtendedInfoTest, getLeases6ByLink) { +void +MemfileExtendedInfoTest::testGetLeases6ByLink() { // Lease manager is created with empty tables. start(Memfile_LeaseMgr::V6); initLease6(); @@ -972,69 +694,13 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByLink) { EXPECT_EQ(0, got.size()); } -/// @brief Verifies that getLeases6ByLink works as expected with MT. +TEST_F(MemfileExtendedInfoTest, getLeases6ByLink) { + testGetLeases6ByLink(); +} + TEST_F(MemfileExtendedInfoTest, getLeases6ByLinkMultiThreading) { MultiThreadingTest mt(true); - start(Memfile_LeaseMgr::V6); - initLease6(); - - // Create parameter values. - IOAddress link_addr(ADDRESS6[4]); - IOAddress other_link_addr("2001:db8:1::4"); - IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - - Lease6Collection got; - // Other link: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(other_link_addr, - 64, - zero, - LeasePageSize(10))); - EXPECT_EQ(0, got.size()); - - // Link: 8 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, - 64, - zero, - LeasePageSize(10))); - - ASSERT_EQ(8, got.size()); - Lease6Ptr lease; - for (size_t i = 0; i < 8; ++i) { - lease = got[i]; - ASSERT_TRUE(lease); - EXPECT_EQ(IOAddress(ADDRESS6[i]), lease->addr_); - } - - // Link: initial partial: 4 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, - 64, - zero, - LeasePageSize(4))); - ASSERT_EQ(4, got.size()); - for (size_t i = 0; i < 4; ++i) { - lease = got[i]; - ASSERT_TRUE(lease); - EXPECT_EQ(IOAddress(ADDRESS6[i]), lease->addr_); - } - - // Link: next partial: 4 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, - 64, - lease->addr_, - LeasePageSize(4))); - ASSERT_EQ(4, got.size()); - for (size_t i = 0; i < 4; ++i) { - lease = got[i]; - ASSERT_TRUE(lease); - EXPECT_EQ(IOAddress(ADDRESS6[i + 4]), lease->addr_); - } - - // Link: further partial: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, - 64, - lease->addr_, - LeasePageSize(4))); - EXPECT_EQ(0, got.size()); + testGetLeases6ByLink(); } /// @brief Verifies that v6 deleteLease removes references from extended @@ -1046,10 +712,10 @@ TEST_F(MemfileExtendedInfoTest, deleteLease6) { // Create parameter values. IOAddress lease_addr(ADDRESS6[0]); - vector<uint8_t> relay_id = createFromString(DUID6[0]); - vector<uint8_t> remote_id = createFromString(DUID6[1]); - vector<uint8_t> relay_id2 = createFromString(DUID6[2]); - vector<uint8_t> remote_id2 = createFromString(DUID6[3]); + vector<uint8_t> relay_id = createFromString(DUIDS[0]); + vector<uint8_t> remote_id = createFromString(DUIDS[1]); + vector<uint8_t> relay_id2 = createFromString(DUIDS[2]); + vector<uint8_t> remote_id2 = createFromString(DUIDS[3]); // Fill the table. EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr, relay_id)); @@ -1092,8 +758,8 @@ TEST_F(MemfileExtendedInfoTest, deleteLease6disabled) { // Create parameter values. IOAddress lease_addr(ADDRESS6[0]); - vector<uint8_t> relay_id = createFromString(DUID6[0]); - vector<uint8_t> remote_id = createFromString(DUID6[1]); + vector<uint8_t> relay_id = createFromString(DUIDS[0]); + vector<uint8_t> remote_id = createFromString(DUIDS[1]); // Fill the table. EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr, relay_id)); @@ -1126,7 +792,7 @@ TEST_F(MemfileExtendedInfoTest, addLease6) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); @@ -1177,7 +843,7 @@ TEST_F(MemfileExtendedInfoTest, addLease6disabled) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); @@ -1208,7 +874,7 @@ TEST_F(MemfileExtendedInfoTest, updateLease6ignore) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); @@ -1254,7 +920,7 @@ TEST_F(MemfileExtendedInfoTest, updateLease6delete) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); @@ -1295,7 +961,7 @@ TEST_F(MemfileExtendedInfoTest, updateLease6deleteDisabled) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); @@ -1341,7 +1007,7 @@ TEST_F(MemfileExtendedInfoTest, updateLease6update) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); @@ -1401,7 +1067,7 @@ TEST_F(MemfileExtendedInfoTest, updateLease6updateDisabled) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); @@ -1443,7 +1109,7 @@ TEST_F(MemfileExtendedInfoTest, updateLease6update2) { // Create parameter values. Lease6Ptr lease; IOAddress lease_addr(ADDRESS6[1]); - vector<uint8_t> duid_data = createFromString(DUID6[0]); + vector<uint8_t> duid_data = createFromString(DUIDS[0]); DuidPtr duid(new DUID(duid_data)); ASSERT_NO_THROW(lease.reset(new Lease6(Lease::TYPE_NA, lease_addr, duid, 123, 1000, 2000, 1))); |