From 4db17a95e5997d4b0dd8e93c853f7c3f53e5d0f8 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 8 Nov 2022 21:32:32 +0100 Subject: [PATCH] [#2630] Removed link-addr from relay --- src/lib/dhcpsrv/dhcpsrv_messages.cc | 6 +- src/lib/dhcpsrv/dhcpsrv_messages.mes | 14 +- src/lib/dhcpsrv/lease_mgr.h | 27 +- src/lib/dhcpsrv/memfile_lease_mgr.cc | 135 ++-- src/lib/dhcpsrv/memfile_lease_mgr.h | 44 +- src/lib/dhcpsrv/memfile_lease_storage.h | 140 +--- src/lib/dhcpsrv/mysql_lease_mgr.cc | 11 +- src/lib/dhcpsrv/mysql_lease_mgr.h | 27 +- src/lib/dhcpsrv/pgsql_lease_mgr.cc | 11 +- src/lib/dhcpsrv/pgsql_lease_mgr.h | 27 +- src/lib/dhcpsrv/tests/lease_mgr_unittest.cc | 12 +- .../memfile_lease_extended_info_unittest.cc | 686 ++++++++---------- 12 files changed, 461 insertions(+), 679 deletions(-) diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.cc b/src/lib/dhcpsrv/dhcpsrv_messages.cc index aaf9b1c286..f16d1a4267 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.cc +++ b/src/lib/dhcpsrv/dhcpsrv_messages.cc @@ -339,13 +339,13 @@ const char* values[] = { "DHCPSRV_MEMFILE_GET_HWADDR", "obtaining IPv4 leases for hardware address %1", "DHCPSRV_MEMFILE_GET_IAID_DUID", "obtaining IPv6 leases for IAID %1 and DUID %2 and lease type %3", "DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID", "obtaining IPv6 leases for IAID %1, Subnet ID %2, DUID %3 and lease type %4", - "DHCPSRV_MEMFILE_GET_LINKADDR6", "obtaining at most %1 IPv6 leases starting from address %2 with link address %3", + "DHCPSRV_MEMFILE_GET_LINKADDR6", "obtaining at most %1 IPv6 leases starting from address %2 with link %3/%4", "DHCPSRV_MEMFILE_GET_PAGE4", "obtaining at most %1 IPv4 leases starting from address %2", "DHCPSRV_MEMFILE_GET_PAGE6", "obtaining at most %1 IPv6 leases starting from address %2", "DHCPSRV_MEMFILE_GET_RELAYID4", "obtaining at most %1 IPv4 leases starting from address %2 with relay id %3 and cltt between %4 and %5", - "DHCPSRV_MEMFILE_GET_RELAYID6", "obtaining at most %1 IPv6 leases starting from address %2 with relay id %3 and link address %4", + "DHCPSRV_MEMFILE_GET_RELAYID6", "obtaining at most %1 IPv6 leases starting from address %2 with relay id %3 and link %4/%5", "DHCPSRV_MEMFILE_GET_REMOTEID4", "obtaining at most %1 IPv4 leases starting from address %2 with remote id %3 and cltt between %4 and %5", - "DHCPSRV_MEMFILE_GET_REMOTEID6", "obtaining at most %1 IPv6 leases starting from address %2 with remote id %3 and link address %4", + "DHCPSRV_MEMFILE_GET_REMOTEID6", "obtaining at most %1 IPv6 leases starting from address %2 with remote id %3 and link %4/%5", "DHCPSRV_MEMFILE_GET_SUBID4", "obtaining IPv4 leases for subnet ID %1", "DHCPSRV_MEMFILE_GET_SUBID6", "obtaining IPv6 leases for subnet ID %1", "DHCPSRV_MEMFILE_GET_SUBID_CLIENTID", "obtaining IPv4 lease for subnet ID %1 and client ID %2", diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.mes b/src/lib/dhcpsrv/dhcpsrv_messages.mes index 2dcd42454f..0dda18e70c 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.mes +++ b/src/lib/dhcpsrv/dhcpsrv_messages.mes @@ -489,9 +489,9 @@ A debug message issued when the server is attempting to obtain an IPv6 lease from the memory file database for a client with the specified IAID (Identity Association ID), Subnet ID and DUID (DHCP Unique Identifier). -% DHCPSRV_MEMFILE_GET_LINKADDR6 obtaining at most %1 IPv6 leases starting from address %2 with link address %3 +% DHCPSRV_MEMFILE_GET_LINKADDR6 obtaining at most %1 IPv6 leases starting from address %2 with link %3/%4 A debug message issued when the server is attempting to obtain a page of -IPv6 leases beginning with the specified address with a link address. +IPv6 leases beginning with the specified address within a link. % DHCPSRV_MEMFILE_GET_PAGE4 obtaining at most %1 IPv4 leases starting from address %2 A debug message issued when the server is attempting to obtain a page @@ -506,20 +506,18 @@ A debug message issued when the server is attempting to obtain a page of IPv4 leases beginning with the specified address with a relay id and client transaction time between start and end dates. -% DHCPSRV_MEMFILE_GET_RELAYID6 obtaining at most %1 IPv6 leases starting from address %2 with relay id %3 and link address %4 +% DHCPSRV_MEMFILE_GET_RELAYID6 obtaining at most %1 IPv6 leases starting from address %2 with relay id %3 and link %4/%5 A debug message issued when the server is attempting to obtain a page of -IPv6 leases beginning with the specified address with a relay id and -a link address. +IPv6 leases beginning with the specified address with a relay id and a link. % DHCPSRV_MEMFILE_GET_REMOTEID4 obtaining at most %1 IPv4 leases starting from address %2 with remote id %3 and cltt between %4 and %5 A debug message issued when the server is attempting to obtain a page of IPv4 leases beginning with the specified address with a remote id and client transaction time between start and end dates. -% DHCPSRV_MEMFILE_GET_REMOTEID6 obtaining at most %1 IPv6 leases starting from address %2 with remote id %3 and link address %4 +% DHCPSRV_MEMFILE_GET_REMOTEID6 obtaining at most %1 IPv6 leases starting from address %2 with remote id %3 and link %4/%5 A debug message issued when the server is attempting to obtain a page of -IPv6 leases beginning with the specified address with a remote id and -a link address. +IPv6 leases beginning with the specified address with a remote id and a link. % DHCPSRV_MEMFILE_GET_SUBID4 obtaining IPv4 leases for subnet ID %1 A debug message issued when the server is attempting to obtain all IPv4 diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index ea783a0775..9ed82c631a 100644 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -895,8 +895,9 @@ public: /// @brief Returns existing IPv6 leases with a given relay-id. /// - /// @param relay_id DUID for relay_id of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param relay_id DUID for relay_id of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -905,13 +906,15 @@ public: virtual Lease6Collection getLeases6ByRelayId(const DUID& relay_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) = 0; /// @brief Returns existing IPv6 leases with a given remote-id. /// - /// @param remote_id remote-id option data of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param remote_id remote-id option data of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -920,12 +923,14 @@ public: virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer& remote_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) = 0; /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -933,6 +938,7 @@ public: /// @return collection of IPv6 leases virtual Lease6Collection getLeases6ByLink(const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) = 0; @@ -986,28 +992,17 @@ protected: /// @brief Add lease6 extended info into by-relay-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the relay header. /// @param relay_id The relay id from the relay header options. virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& relay_id) = 0; /// @brief Add lease6 extended info into by-remote-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. /// @param remote_id The remote id from the relay header options. virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& remote_id) = 0; - /// @brief Add lease6 extended info into by-link-addr table. - /// - /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. - virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr) = 0; - private: /// The IOService object, used for all ASIO operations. static isc::asiolink::IOServicePtr io_service_; diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index c62fe59610..5fab3d5059 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -2510,14 +2511,19 @@ Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(const OptionBuffer&, Lease6Collection Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& relay_id, const IOAddress& link_addr, + uint8_t link_len, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { - // Expecting IPv6 addresses. + // Expecting IPv6 valid prefix and address. if (!link_addr.isV6()) { isc_throw(InvalidAddressFamily, "expected IPv6 address while " "retrieving leases from the lease database, got " << link_addr); } + if (link_len > 128) { + isc_throw(OutOfRange, "invalid IPv6 prefix length " + << static_cast(link_len)); + } if (!lower_bound_address.isV6()) { isc_throw(InvalidAddressFamily, "expected IPv6 address while " "retrieving leases from the lease database, got " @@ -2529,17 +2535,20 @@ Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& relay_id, .arg(page_size.page_size_) .arg(lower_bound_address.toText()) .arg(relay_id.toText()) - .arg(link_addr.toText()); + .arg(link_addr.toText()) + .arg(static_cast(link_len)); if (MultiThreadingMgr::instance().getMode()) { std::lock_guard lock(*mutex_); return (getLeases6ByRelayIdInternal(relay_id, link_addr, + link_len, lower_bound_address, page_size)); } else { return (getLeases6ByRelayIdInternal(relay_id, link_addr, + link_len, lower_bound_address, page_size)); } @@ -2548,12 +2557,13 @@ Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& relay_id, Lease6Collection Memfile_LeaseMgr::getLeases6ByRelayIdInternal(const DUID& relay_id, const IOAddress& link_addr, + uint8_t link_len, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { const std::vector& relay_id_data = relay_id.getDuid(); Lease6Collection collection; - if (link_addr.isV6Zero()) { - const RelayIdIndex& idx = relay_id6_.get(); + const RelayIdIndex& idx = relay_id6_.get(); + if (!link_len) { RelayIdIndex::const_iterator lb = idx.lower_bound(boost::make_tuple(relay_id_data, lower_bound_address)); @@ -2579,30 +2589,24 @@ Memfile_LeaseMgr::getLeases6ByRelayIdInternal(const DUID& relay_id, } } } else { - const RelayIdLinkAddressIndex& idx = - relay_id6_.get(); - RelayIdLinkAddressIndex::const_iterator lb = - idx.lower_bound(boost::make_tuple(relay_id_data, - link_addr, - lower_bound_address)); + const IOAddress& first_addr = firstAddrInPrefix(link_addr, link_len); + const IOAddress& last_addr = lastAddrInPrefix(link_addr, link_len); + const IOAddress& start_addr = + (lower_bound_address < first_addr ? first_addr : lower_bound_address); + RelayIdIndex::const_iterator lb = + idx.lower_bound(boost::make_tuple(relay_id_data, start_addr)); + RelayIdIndex::const_iterator ub = + idx.upper_bound(boost::make_tuple(relay_id_data, last_addr)); // Return all leases being within the page size. - IOAddress last_addr = lower_bound_address; - for (; lb != idx.end(); ++lb) { - if ((*lb)->lease_addr_ == last_addr) { + IOAddress last_seen_addr = lower_bound_address; + for (auto it = lb; it != ub; ++it) { + if ((*it)->lease_addr_ == last_seen_addr) { // Already seen: skip it. continue; } - if ((*lb)->link_addr_ != link_addr) { - // Gone after the link address. - break; - } - if ((*lb)->id_ != relay_id_data) { - // Gone after the relay id index. - break; - } - last_addr = (*lb)->lease_addr_; - Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr); + last_seen_addr = (*it)->lease_addr_; + Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_seen_addr); if (lease) { collection.push_back(lease); if (collection.size() >= page_size.page_size_) { @@ -2617,14 +2621,19 @@ Memfile_LeaseMgr::getLeases6ByRelayIdInternal(const DUID& relay_id, Lease6Collection Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id, const IOAddress& link_addr, + uint8_t link_len, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { - // Expecting IPv6 addresses. + // Expecting IPv6 valid prefix and address. if (!link_addr.isV6()) { isc_throw(InvalidAddressFamily, "expected IPv6 address while " "retrieving leases from the lease database, got " << link_addr); } + if (link_len > 128) { + isc_throw(OutOfRange, "invalid IPv6 prefix length " + << static_cast(link_len)); + } if (!lower_bound_address.isV6()) { isc_throw(InvalidAddressFamily, "expected IPv6 address while " "retrieving leases from the lease database, got " @@ -2636,17 +2645,20 @@ Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id, .arg(page_size.page_size_) .arg(lower_bound_address.toText()) .arg(idtoText(remote_id)) - .arg(link_addr.toText()); + .arg(link_addr.toText()) + .arg(static_cast(link_len)); if (MultiThreadingMgr::instance().getMode()) { std::lock_guard lock(*mutex_); return (getLeases6ByRemoteIdInternal(remote_id, link_addr, + link_len, lower_bound_address, page_size)); } else { return (getLeases6ByRemoteIdInternal(remote_id, link_addr, + link_len, lower_bound_address, page_size)); } @@ -2655,14 +2667,14 @@ Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id, Lease6Collection Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, const IOAddress& link_addr, + uint8_t link_len, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { Lease6Collection collection; std::set sorted; - if (link_addr.isV6Zero()) { - const RemoteIdIndex& idx = remote_id6_.get(); - RemoteIdIndexRange er = idx.equal_range(remote_id); - + const RemoteIdIndex& idx = remote_id6_.get(); + RemoteIdIndexRange er = idx.equal_range(remote_id); + if (!link_len) { // Store all addresses greater than lower_bound_address. for (auto it = er.first; it != er.second; ++it) { const IOAddress& addr = (*it)->lease_addr_; @@ -2683,17 +2695,18 @@ Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, } } } else { - const RemoteIdLinkAddressIndex& idx = - remote_id6_.get(); - RemoteIdLinkAddressRange er = - idx.equal_range(boost::make_tuple(remote_id, link_addr)); + const IOAddress& first_addr = firstAddrInPrefix(link_addr, link_len); + const IOAddress& last_addr = lastAddrInPrefix(link_addr, link_len); - // Store all addresses greater than lower_bound_address. + // Store all addresses greater than lower_bound_address in the link. for (auto it = er.first; it != er.second; ++it) { const IOAddress& addr = (*it)->lease_addr_; if (addr <= lower_bound_address) { continue; } + if ((addr < first_addr) || (last_addr < addr)) { + continue; + } static_cast(sorted.insert(addr)); } @@ -2713,14 +2726,19 @@ Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, Lease6Collection Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr, + uint8_t link_len, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { - // Expecting IPv6 addresses. + // Expecting IPv6 valid prefix and address. if (!link_addr.isV6()) { isc_throw(InvalidAddressFamily, "expected IPv6 address while " "retrieving leases from the lease database, got " << link_addr); } + if ((link_len == 0) || (link_len > 128)) { + isc_throw(OutOfRange, "invalid IPv6 prefix length " + << static_cast(link_len)); + } if (!lower_bound_address.isV6()) { isc_throw(InvalidAddressFamily, "expected IPv6 address while " "retrieving leases from the lease database, got " @@ -2731,15 +2749,18 @@ Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr, DHCPSRV_MEMFILE_GET_LINKADDR6) .arg(page_size.page_size_) .arg(lower_bound_address.toText()) - .arg(link_addr.toText()); + .arg(link_addr.toText()) + .arg(static_cast(link_len)); if (MultiThreadingMgr::instance().getMode()) { std::lock_guard lock(*mutex_); return (getLeases6ByLinkInternal(link_addr, + link_len, lower_bound_address, page_size)); } else { return (getLeases6ByLinkInternal(link_addr, + link_len, lower_bound_address, page_size)); } @@ -2747,26 +2768,27 @@ Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr, Lease6Collection Memfile_LeaseMgr::getLeases6ByLinkInternal(const IOAddress& link_addr, + uint8_t link_len, const IOAddress& lower_bound_address, const LeasePageSize& page_size) { + const IOAddress& first_addr = firstAddrInPrefix(link_addr, link_len); + const IOAddress& last_addr = lastAddrInPrefix(link_addr, link_len); + const IOAddress& start_addr = + (lower_bound_address < first_addr ? first_addr : lower_bound_address); Lease6Collection collection; - const LinkAddressIndex& idx = link_addr6_.get(); - LinkAddressIndex::const_iterator lb = - idx.lower_bound(boost::make_tuple(link_addr, lower_bound_address)); + const Lease6StorageAddressIndex& idx = storage6_.get(); + Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(start_addr); + Lease6StorageAddressIndex::const_iterator eb = idx.upper_bound(last_addr); // Return all leases being within the page size. - IOAddress last_addr = lower_bound_address; - for (; lb != idx.end(); ++lb) { - if ((*lb)->lease_addr_ == last_addr) { + IOAddress last_seen_addr = lower_bound_address; + for (auto it = lb; it != eb; ++it) { + if ((*it)->addr_ == last_seen_addr) { // Already seen: skip it. continue; } - if ((*lb)->link_addr_ != link_addr) { - // Gone after the link address. - break; - } - last_addr = (*lb)->lease_addr_; - Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr); + last_seen_addr = (*it)->addr_; + Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_seen_addr); if (lease) { collection.push_back(lease); if (collection.size() >= page_size.page_size_) { @@ -2785,37 +2807,24 @@ Memfile_LeaseMgr::deleteExtendedInfo6(const IOAddress& addr) { LeaseAddressRemoteIdIndex& remote_id_idx = remote_id6_.get(); static_cast(remote_id_idx.erase(addr)); - LeaseAddressLinkAddressIndex& link_addr_idx = - link_addr6_.get(); - static_cast(link_addr_idx.erase(addr)); } void Memfile_LeaseMgr::addRelayId6(const IOAddress& lease_addr, - const IOAddress& link_addr, const std::vector& relay_id) { Lease6ExtendedInfoPtr ex_info; - ex_info.reset(new Lease6ExtendedInfo(lease_addr, link_addr, relay_id)); + ex_info.reset(new Lease6ExtendedInfo(lease_addr, relay_id)); relay_id6_.insert(ex_info); } void Memfile_LeaseMgr::addRemoteId6(const IOAddress& lease_addr, - const IOAddress& link_addr, const std::vector& remote_id) { Lease6ExtendedInfoPtr ex_info; - ex_info.reset(new Lease6ExtendedInfo(lease_addr, link_addr, remote_id)); + ex_info.reset(new Lease6ExtendedInfo(lease_addr, remote_id)); remote_id6_.insert(ex_info); } -void -Memfile_LeaseMgr::addLinkAddr6(const IOAddress& lease_addr, - const IOAddress& link_addr) { - Lease6SimpleExtendedInfoPtr ex_info; - ex_info.reset(new Lease6SimpleExtendedInfo(lease_addr, link_addr)); - link_addr6_.insert(ex_info); -} - void Memfile_LeaseMgr::writeLeases4(const std::string& filename) { if (MultiThreadingMgr::instance().getMode()) { diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 7128fb6b1f..1dab64b61c 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -1073,9 +1073,6 @@ protected: /// @brief stores IPv6 by-remote-id cross-reference table Lease6ExtendedInfoRemoteIdTable remote_id6_; - /// @brief stores IPv6 by-link-addr cross-reference table - Lease6SimpleExtendedInfoLinkAddrTable link_addr6_; - /// @brief Holds the pointer to the DHCPv4 lease file IO. boost::shared_ptr lease_file4_; @@ -1326,8 +1323,9 @@ public: /// @brief Returns existing IPv6 leases with a given relay-id. /// - /// @param relay_id DUID for relay_id of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param relay_id DUID for relay_id of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1336,13 +1334,15 @@ public: virtual Lease6Collection getLeases6ByRelayId(const DUID& relay_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; /// @brief Returns existing IPv6 leases with a given remote-id. /// /// @param remote_id remote-id option data of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1351,12 +1351,14 @@ public: virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer& remote_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1364,6 +1366,7 @@ public: /// @return collection of IPv6 leases virtual Lease6Collection getLeases6ByLink(const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; @@ -1409,8 +1412,9 @@ private: /// @brief Returns existing IPv6 leases with a given relay-id. /// - /// @param relay_id DUID for relay_id of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param relay_id DUID for relay_id of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1419,13 +1423,15 @@ private: Lease6Collection getLeases6ByRelayIdInternal(const DUID& relay_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size); /// @brief Returns existing IPv6 leases with a given remote-id. /// - /// @param remote_id remote-id option data of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param remote_id remote-id option data of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1434,12 +1440,14 @@ private: Lease6Collection getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size); /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1447,6 +1455,7 @@ private: /// @return collection of IPv6 leases Lease6Collection getLeases6ByLinkInternal(const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size); @@ -1474,28 +1483,17 @@ protected: /// @brief Add lease6 extended info into by-relay-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the relay header. /// @param relay_id The relay id from the relay header options. virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& relay_id) override; /// @brief Add lease6 extended info into by-remote-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. /// @param remote_id The remote id from the relay header options. virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& remote_id) override; - /// @brief Add lease6 extended info into by-link-addr table. - /// - /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. - virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr) override; - private: /// @brief Write V4 leases to a file. /// diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index f4544c317b..693bccf278 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -292,20 +292,15 @@ public: /// @brief Constructor. /// /// @param lease_addr Lease address. - /// @param link_addr Link address. /// @param id Identifier. Lease6ExtendedInfo(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& id) - : lease_addr_(lease_addr), link_addr_(link_addr), id_(id) { + : lease_addr_(lease_addr), id_(id) { } /// @brief Lease address. isc::asiolink::IOAddress lease_addr_; - /// @brief Link address. - isc::asiolink::IOAddress link_addr_; - /// @brief Remote or relay opaque identifier. std::vector id_; }; @@ -316,23 +311,15 @@ typedef boost::shared_ptr Lease6ExtendedInfoPtr; /// @brief Tag for indexes by lease address. struct LeaseAddressIndexTag { }; -/// @brief Tag for indexes by relay id and link address. -struct RelayIdLinkAddressIndexTag { }; - /// @brief Tag for index using relay id. struct RelayIdIndexTag { }; -/// @brief Tag for indexes by remote id and link address. -struct RemoteIdLinkAddressIndexTag { }; - /// @brief Tag for index using remote id. struct RemoteIdIndexTag { }; /// @brief A multi index container holding lease6 extended info for by relay id. /// /// The lease6 extended info may be accessed using different indexes: -/// - using a composite index: relay id and link address, and lease address -/// for getting lower bounds. /// - using relay id, and lease address for getting lower bounds. /// - using lease address for deletes. /// @@ -346,24 +333,7 @@ typedef boost::multi_index_container< // It holds pointers to lease6 extended info. Lease6ExtendedInfoPtr, boost::multi_index::indexed_by< - // First index is by relay id, link and lease addresses. - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - boost::multi_index::composite_key< - Lease6ExtendedInfo, - boost::multi_index::member, - &Lease6ExtendedInfo::id_>, - boost::multi_index::member, - boost::multi_index::member - > - >, - - // Second index is by relay id and lease address. + // First index is by relay id and lease address. boost::multi_index::ordered_non_unique< boost::multi_index::tag, boost::multi_index::composite_key< @@ -390,7 +360,6 @@ typedef boost::multi_index_container< /// @brief A multi index container holding lease6 extended info for by remote id. /// /// The lease6 extended info may be accessed using different indexes: -/// - using a composite index: remote id and link address. /// - using remote id. /// - using lease address for deletes. /// @@ -405,21 +374,7 @@ typedef boost::multi_index_container< // It holds pointers to lease6 extended info. Lease6ExtendedInfoPtr, boost::multi_index::indexed_by< - // First index is by remote id and link address. - boost::multi_index::hashed_non_unique< - boost::multi_index::tag, - boost::multi_index::composite_key< - Lease6ExtendedInfo, - boost::multi_index::member, - &Lease6ExtendedInfo::id_>, - boost::multi_index::member - > - >, - - // Second index is by remote id. + // First index is by remote id. boost::multi_index::hashed_non_unique< boost::multi_index::tag, boost::multi_index::member > Lease6ExtendedInfoRemoteIdTable; -/// @brief Lease6 extended information by relay id and link address index. -typedef Lease6ExtendedInfoRelayIdTable::index::type - RelayIdLinkAddressIndex; - /// @brief Lease6 extended information by relay id index. typedef Lease6ExtendedInfoRelayIdTable::index::type RelayIdIndex; @@ -449,19 +400,10 @@ typedef Lease6ExtendedInfoRelayIdTable::index::type typedef Lease6ExtendedInfoRelayIdTable::index::type LeaseAddressRelayIdIndex; -/// @brief Lease6 extended information by remote id and link address index. -typedef Lease6ExtendedInfoRemoteIdTable::index::type - RemoteIdLinkAddressIndex; - /// @brief Lease6 extended information by remote id index. typedef Lease6ExtendedInfoRemoteIdTable::index::type RemoteIdIndex; -/// @brief Lease6 extended information by remote id and link address range. -typedef std::pair - RemoteIdLinkAddressRange; - /// @brief Lease6 extended information by remote id range. typedef std::pair RemoteIdIndexRange; @@ -470,82 +412,6 @@ typedef std::pair typedef Lease6ExtendedInfoRemoteIdTable::index::type LeaseAddressRemoteIdIndex; -/// @brief Lease6 extended informations for Bulk Lease Query, -/// simpler version (2 fields vs 3) for by link address table. -class Lease6SimpleExtendedInfo { -public: - /// @brief Constructor. - /// - /// @param lease_addr Lease address. - /// @param link_addr Link address. - Lease6SimpleExtendedInfo(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr) - : lease_addr_(lease_addr), link_addr_(link_addr) { - } - - /// @brief Lease address. - isc::asiolink::IOAddress lease_addr_; - - /// @brief Link address. - isc::asiolink::IOAddress link_addr_; -}; - -/// @brief Pointer to a Lease6SimpleExtendedInfo object. -typedef boost::shared_ptr Lease6SimpleExtendedInfoPtr; - -/// @brief Tag for indexes by link address. -struct LinkAddressIndexTag { }; - -/// @brief A multi index container holding lease6 extended info -/// for by link address. -/// -/// The lease6 extended info may be accessed using different indexes: -/// - using a composite index: link and lease addresses, the second for -/// getting lower bounds. -/// - using lease address for deletes. -/// -/// The choice of a binary tree was governed by the fact no hypothesis can -/// be done on the number of clients. -/// -/// Indexes can be accessed using the index number (from 0 to 5) or a -/// name tag. It is recommended to use the tags to access indexes as -/// they do not depend on the order of indexes in the container. -typedef boost::multi_index_container< - // It holds pointers to lease6 extended info. - Lease6SimpleExtendedInfoPtr, - boost::multi_index::indexed_by< - // First index is by link and lease addresses. - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - boost::multi_index::composite_key< - Lease6SimpleExtendedInfo, - boost::multi_index::member, - boost::multi_index::member - > - >, - - // Last index is by lease address. - boost::multi_index::hashed_non_unique< - boost::multi_index::tag, - boost::multi_index::member - > - > -> Lease6SimpleExtendedInfoLinkAddrTable; - -/// @brief Lease6 extended information by link address. -typedef Lease6SimpleExtendedInfoLinkAddrTable::index::type - LinkAddressIndex; - -/// @brief Lease6 extended information by lease address index of by link address table. -typedef Lease6SimpleExtendedInfoLinkAddrTable::index::type - LeaseAddressLinkAddressIndex; - //@} } // end of isc::dhcp namespace diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 162ef82e2c..52bdeb97d0 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -3377,24 +3377,16 @@ MySqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) { void MySqlLeaseMgr::addRelayId6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */, const vector& /* relay_id */) { isc_throw(NotImplemented, "MySqlLeaseMgr::addRelayId6 not implemented"); } void MySqlLeaseMgr::addRemoteId6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */, const vector& /* remote_id */) { isc_throw(NotImplemented, "MySqlLeaseMgr::addRemoteId6 not implemented"); } -void -MySqlLeaseMgr::addLinkAddr6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */) { - isc_throw(NotImplemented, "MySqlLeaseMgr::addLinkAddr6 not implemented"); -} - Lease4Collection MySqlLeaseMgr::getLeases4ByRelayId(const OptionBuffer& /* relay_id */, const IOAddress& /* lower_bound_address */, @@ -3416,6 +3408,7 @@ MySqlLeaseMgr::getLeases4ByRemoteId(const OptionBuffer& /* remote_id */, Lease6Collection MySqlLeaseMgr::getLeases6ByRelayId(const DUID& /* relay_id */, const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size */) { isc_throw(NotImplemented, "MySqlLeaseMgr::getLeases6ByRelayId not implemented"); @@ -3424,6 +3417,7 @@ MySqlLeaseMgr::getLeases6ByRelayId(const DUID& /* relay_id */, Lease6Collection MySqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */, const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size*/) { isc_throw(NotImplemented, "MySqlLeaseMgr::getLeases6ByRemoteId not implemented"); @@ -3431,6 +3425,7 @@ MySqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */, Lease6Collection MySqlLeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size */) { isc_throw(NotImplemented, "MySqlLeaseMgr::getLeases6ByLink not implemented"); diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h index 92a8f00c19..4749ab359a 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.h +++ b/src/lib/dhcpsrv/mysql_lease_mgr.h @@ -1062,8 +1062,9 @@ private: /// @brief Returns existing IPv6 leases with a given relay-id. /// - /// @param relay_id DUID for relay_id of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param relay_id DUID for relay_id of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1072,13 +1073,15 @@ private: virtual Lease6Collection getLeases6ByRelayId(const DUID& relay_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; /// @brief Returns existing IPv6 leases with a given remote-id. /// - /// @param remote_id remote-id option data of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param remote_id remote-id option data of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1087,12 +1090,14 @@ private: virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer& remote_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1100,6 +1105,7 @@ private: /// @return collection of IPv6 leases virtual Lease6Collection getLeases6ByLink(const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; @@ -1161,28 +1167,17 @@ protected: /// @brief Add lease6 extended info into by-relay-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the relay header. /// @param relay_id The relay id from the relay header options. virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& relay_id) override; /// @brief Add lease6 extended info into by-remote-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. /// @param remote_id The remote id from the relay header options. virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& remote_id) override; - /// @brief Add lease6 extended info into by-link-addr table. - /// - /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. - virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr) override; - private: // Members diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index dfa1963cc7..96bf15a826 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -2571,24 +2571,16 @@ PgSqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) { void PgSqlLeaseMgr::addRelayId6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */, const vector& /* relay_id */) { isc_throw(NotImplemented, "PgSqlLeaseMgr::addRelayId6 not implemented"); } void PgSqlLeaseMgr::addRemoteId6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */, const vector& /* remote_id */) { isc_throw(NotImplemented, "PgSqlLeaseMgr::addRemoteId6 not implemented"); } -void -PgSqlLeaseMgr::addLinkAddr6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */) { - isc_throw(NotImplemented, "PgSqlLeaseMgr::addLinkAddr6 not implemented"); -} - Lease4Collection PgSqlLeaseMgr::getLeases4ByRelayId(const OptionBuffer& /* relay_id */, const IOAddress& /* lower_bound_address */, @@ -2610,6 +2602,7 @@ PgSqlLeaseMgr::getLeases4ByRemoteId(const OptionBuffer& /* remote_id */, Lease6Collection PgSqlLeaseMgr::getLeases6ByRelayId(const DUID& /* relay_id */, const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size */) { isc_throw(NotImplemented, "PgSqlLeaseMgr::getLeases6ByRelayId not implemented"); @@ -2618,6 +2611,7 @@ PgSqlLeaseMgr::getLeases6ByRelayId(const DUID& /* relay_id */, Lease6Collection PgSqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */, const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size*/) { isc_throw(NotImplemented, "PgSqlLeaseMgr::getLeases6ByRemoteId not implemented"); @@ -2625,6 +2619,7 @@ PgSqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */, Lease6Collection PgSqlLeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size */) { isc_throw(NotImplemented, "PgSqlLeaseMgr::getLeases6ByLink not implemented"); diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.h b/src/lib/dhcpsrv/pgsql_lease_mgr.h index 24e2ec58af..373f84fa04 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.h +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.h @@ -1015,8 +1015,9 @@ private: /// @brief Returns existing IPv6 leases with a given relay-id. /// - /// @param relay_id DUID for relay_id of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param relay_id DUID for relay_id of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1025,13 +1026,15 @@ private: virtual Lease6Collection getLeases6ByRelayId(const DUID& relay_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; /// @brief Returns existing IPv6 leases with a given remote-id. /// - /// @param remote_id remote-id option data of interest - /// @param link_addr limit results to leases on this link when not :: + /// @param remote_id remote-id option data of interest. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1040,12 +1043,14 @@ private: virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer& remote_id, const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; /// @brief Returns existing IPv6 leases with on a given link. /// - /// @param link_addr limit results to leases on this link. + /// @param link_addr limit results to leases on this link (prefix). + /// @param link_len limit results to leases on this link (length). /// @param lower_bound_address IPv4 address used as lower bound for the /// returned range. /// @param page_size maximum size of the page returned. @@ -1053,6 +1058,7 @@ private: /// @return collection of IPv6 leases virtual Lease6Collection getLeases6ByLink(const asiolink::IOAddress& link_addr, + uint8_t link_len, const asiolink::IOAddress& lower_bound_address, const LeasePageSize& page_size) override; @@ -1120,28 +1126,17 @@ protected: /// @brief Add lease6 extended info into by-relay-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the relay header. /// @param relay_id The relay id from the relay header options. virtual void addRelayId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& relay_id) override; /// @brief Add lease6 extended info into by-remote-id table. /// /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. /// @param remote_id The remote id from the relay header options. virtual void addRemoteId6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr, const std::vector& remote_id) override; - /// @brief Add lease6 extended info into by-link-addr table. - /// - /// @param lease_addr The address of the lease. - /// @param link_addr The link address from the remote header. - virtual void addLinkAddr6(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr) override; - private: // Members diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc index cb187cb53c..0a3a7e97c8 100644 --- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc @@ -406,7 +406,6 @@ public: /// @brief Stub implementation. void addRelayId6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */, const vector& /* relay_id */) override { isc_throw(NotImplemented, "ConcreteLeaseMgr::addRelayId6 not implemented"); } @@ -414,18 +413,10 @@ public: /// @brief Stub implementation. void addRemoteId6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */, const vector& /* remote_id */) override { isc_throw(NotImplemented, "ConcreteLeaseMgr::addRemoteId6 not implemented"); } - /// @brief Stub implementation. - void - addLinkAddr6(const IOAddress& /* lease_addr */, - const IOAddress& /* link_addr */) override { - isc_throw(NotImplemented, "ConcreteLeaseMgr::addLinkAddr6 not implemented"); - } - /// @brief Stub implementation. Lease4Collection getLeases4ByRelayId(const OptionBuffer& /* relay_id */, @@ -450,6 +441,7 @@ public: Lease6Collection getLeases6ByRelayId(const DUID& /* relay_id */, const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size */) override { isc_throw(NotImplemented, "ConcreteLeaseMgr::getLeases6ByRelayId not implemented"); @@ -459,6 +451,7 @@ public: Lease6Collection getLeases6ByRemoteId(const OptionBuffer& /* remote_id */, const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size*/) override { isc_throw(NotImplemented, "ConcreteLeaseMgr::getLeases6ByRemoteId not implemented"); @@ -467,6 +460,7 @@ public: /// @brief Stub implementation. Lease6Collection getLeases6ByLink(const IOAddress& /* link_addr */, + uint8_t /* link_len */, const IOAddress& /* lower_bound_address */, const LeasePageSize& /* page_size */) override { isc_throw(NotImplemented, "ConcreteLeaseMgr::getLeases6ByLink not implemented"); 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 98f50f883d..5d71a1a542 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc @@ -57,11 +57,9 @@ public: /// @brief Exposes protected methods and members. using Memfile_LeaseMgr::relay_id6_; using Memfile_LeaseMgr::remote_id6_; - using Memfile_LeaseMgr::link_addr6_; using Memfile_LeaseMgr::deleteExtendedInfo6; using Memfile_LeaseMgr::addRelayId6; using Memfile_LeaseMgr::addRemoteId6; - using Memfile_LeaseMgr::addLinkAddr6; }; /// @brief Type of unique pointers to naked lease manager. @@ -205,24 +203,21 @@ TEST_F(MemfileExtendedInfoTest, relayIdTable6) { IOAddress lease_addr0(ADDRESS6[0]); IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); - IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); + IOAddress other_lease_addr("2001:db8:1::4"); vector relay_id0 = createFromString(DUID6[0]); vector relay_id1 = createFromString(DUID6[1]); // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, link_addr4, relay_id0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, link_addr5, relay_id0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, zero, relay_id1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, link_addr6, relay_id0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, link_addr6, relay_id1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr2, link_addr4, relay_id1)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id0)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id0)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id1)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, relay_id0)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, relay_id1)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr2, relay_id1)); // Check delete. EXPECT_EQ(6, lease_mgr_->relay_id6_.size()); - EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(link_addr6)); + EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(other_lease_addr)); // No match so doing nothing. EXPECT_EQ(6, lease_mgr_->relay_id6_.size()); @@ -252,24 +247,21 @@ TEST_F(MemfileExtendedInfoTest, remoteIdTable6) { IOAddress lease_addr0(ADDRESS6[0]); IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); - IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); + IOAddress other_lease_addr("2001:db8:1::4"); vector remote_id0 = createFromString(DUID6[0]); vector remote_id1 = createFromString(DUID6[1]); // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, link_addr4, remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, link_addr5, remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, zero, remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, link_addr6, remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, link_addr6, remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr2, link_addr4, remote_id1)); + 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)); // Check delete. EXPECT_EQ(6, lease_mgr_->remote_id6_.size()); - EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(link_addr6)); + EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(other_lease_addr)); // No match so doing nothing. EXPECT_EQ(6, lease_mgr_->remote_id6_.size()); @@ -289,51 +281,6 @@ TEST_F(MemfileExtendedInfoTest, remoteIdTable6) { EXPECT_EQ(0, lease_mgr_->remote_id6_.size()); } -/// @brief Verifies that add and delete work on the by link address table. -TEST_F(MemfileExtendedInfoTest, linkAddressTable) { - // Lease manager is created with empty tables. - start(Memfile_LeaseMgr::V6); - EXPECT_EQ(0, lease_mgr_->link_addr6_.size()); - - // Create parameter values. - IOAddress lease_addr0(ADDRESS6[0]); - IOAddress lease_addr1(ADDRESS6[1]); - IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); - IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - - // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr4)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr5)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, zero)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr1, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr1, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr2, link_addr4)); - - // Check delete. - EXPECT_EQ(6, lease_mgr_->link_addr6_.size()); - EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(link_addr6)); - // No match so doing nothing. - EXPECT_EQ(6, lease_mgr_->link_addr6_.size()); - - EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(lease_addr0)); - // Removed 3 entries. - EXPECT_EQ(3, lease_mgr_->link_addr6_.size()); - EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(lease_addr0)); - // Already removed: doing nothing again. - EXPECT_EQ(3, lease_mgr_->link_addr6_.size()); - - EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(lease_addr1)); - // Removed 2 entries. - EXPECT_EQ(1, lease_mgr_->link_addr6_.size()); - - EXPECT_NO_THROW(lease_mgr_->deleteExtendedInfo6(lease_addr2)); - // Removed last entry. - EXPECT_EQ(0, lease_mgr_->link_addr6_.size()); -} - /// @brief Verifies that getLeases6ByRelayId works as expected. TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { // Lease manager is created with empty tables. @@ -345,9 +292,8 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { IOAddress lease_addr0(ADDRESS6[0]); IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); + IOAddress link_addr(ADDRESS6[4]); + IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); vector relay_id_data0 = createFromString(DUID6[0]); DUID relay_id0(relay_id_data0); @@ -357,44 +303,43 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { DUID relay_id2(relay_id_data2); // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - link_addr4, - relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - link_addr5, - relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - zero, - relay_id_data1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, - link_addr6, - relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, - link_addr6, - relay_id_data1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr2, - link_addr4, - relay_id_data1)); + 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 address: nothing. + // 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 address #4: nothing. + // Unknown relay id #2, link: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id2, - link_addr4, + link_addr, + 64, zero, LeasePageSize(100))); EXPECT_EQ(0, got.size()); - // Relay id #0, no link address: 3 entries but 2 addresses. + // 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()); @@ -405,9 +350,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Relay id #1, no link address, partial: 2 entries. + // 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()); @@ -418,9 +364,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Relay id #1, no link address, partial from previous: 1 entry. + // 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()); @@ -429,27 +376,30 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { EXPECT_EQ(lease_addr2, lease->addr_); // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - link_addr4, - relay_id_data1)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id_data1)); EXPECT_EQ(7, lease_mgr_->relay_id6_.size()); - // Relay id #1, link address #4: 2 entries. + // Relay id #1, link: 3 entries. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(100))); - ASSERT_EQ(2, got.size()); + 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 address #4, initial partial: 1 entry. + // Relay id #1, link, initial partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(1))); ASSERT_EQ(1, got.size()); @@ -457,9 +407,21 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr0, lease->addr_); - // Relay id #1, link address #4, next partial: 1 entry. + // Relay id #1, link, next partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + 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()); @@ -467,9 +429,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr2, lease->addr_); - // Relay id #1, link address #4, final partial: nothing. + // Relay id #1, link, final partial: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + link_addr, + 64, lease->addr_, LeasePageSize(1))); EXPECT_EQ(0, got.size()); @@ -487,9 +450,8 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { IOAddress lease_addr0(ADDRESS6[0]); IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); + IOAddress link_addr(ADDRESS6[4]); + IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); vector relay_id_data0 = createFromString(DUID6[0]); DUID relay_id0(relay_id_data0); @@ -499,44 +461,43 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { DUID relay_id2(relay_id_data2); // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - link_addr4, - relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - link_addr5, - relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - zero, - relay_id_data1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, - link_addr6, - relay_id_data0)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr1, - link_addr6, - relay_id_data1)); - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr2, - link_addr4, - relay_id_data1)); + 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 address: nothing. + // 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 address #4: nothing. + // Unknown relay id #2, link: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id2, - link_addr4, + link_addr, + 64, zero, LeasePageSize(100))); EXPECT_EQ(0, got.size()); - // Relay id #0, no link address: 3 entries but 2 addresses. + // 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()); @@ -547,9 +508,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Relay id #1, no link address, partial: 2 entries. + // 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()); @@ -560,9 +522,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Relay id #1, no link address, partial from previous: 1 entry. + // 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()); @@ -571,27 +534,30 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { EXPECT_EQ(lease_addr2, lease->addr_); // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, - link_addr4, - relay_id_data1)); + EXPECT_NO_THROW(lease_mgr_->addRelayId6(lease_addr0, relay_id_data1)); EXPECT_EQ(7, lease_mgr_->relay_id6_.size()); - // Relay id #1, link address #4: 2 entries. + // Relay id #1, link: 3 entries. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(100))); - ASSERT_EQ(2, got.size()); + 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 address #4, initial partial: 1 entry. + // Relay id #1, link, initial partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(1))); ASSERT_EQ(1, got.size()); @@ -599,9 +565,21 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr0, lease->addr_); - // Relay id #1, link address #4, next partial: 1 entry. + // Relay id #1, link, next partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + 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()); @@ -609,9 +587,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRelayIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr2, lease->addr_); - // Relay id #1, link address #4, final partial: nothing. + // Relay id #1, link, final partial: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRelayId(relay_id1, - link_addr4, + link_addr, + 64, lease->addr_, LeasePageSize(1))); EXPECT_EQ(0, got.size()); @@ -628,53 +607,51 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { IOAddress lease_addr0(ADDRESS6[0]); IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); + IOAddress link_addr(ADDRESS6[4]); + IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); vector remote_id0 = createFromString(DUID6[0]); vector remote_id1 = createFromString(DUID6[1]); vector remote_id2 = createFromString(DUID6[2]); // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - link_addr4, - remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - link_addr5, - remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - zero, - remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, - link_addr6, - remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, - link_addr6, - remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr2, - link_addr4, - remote_id1)); + 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 address: nothing. + // 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 address #4: nothing. + // Unknown remote id #2, link: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id2, - link_addr4, + link_addr, + 64, zero, LeasePageSize(10))); EXPECT_EQ(0, got.size()); - // Remote id #0, no link address: 3 entries but 2 addresses. + // 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()); @@ -685,9 +662,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Remote id #1, no link address, partial: 2 entries. + // 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()); @@ -698,9 +676,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Remote id #1, no link address, partial from previous: 1 entry. + // 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()); @@ -709,27 +688,30 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { EXPECT_EQ(lease_addr2, lease->addr_); // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - link_addr4, - remote_id1)); + EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id1)); EXPECT_EQ(7, lease_mgr_->remote_id6_.size()); - // Remote id #1, link address #4: 2 entries. + // Remote id #1, link: 3 entries. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(10))); - ASSERT_EQ(2, got.size()); + 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 address #4, initial partial: 1 entry. + // Remote id #1, link, initial partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(1))); ASSERT_EQ(1, got.size()); @@ -737,9 +719,21 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr0, lease->addr_); - // Remote id #1, link address #4, next partial: 1 entry. + // Remote id #1, link, next partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + 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()); @@ -747,9 +741,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteId) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr2, lease->addr_); - // Remote id #1, link address #4, final partial: nothing. + // Remote id #1, link, final partial: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + link_addr, + 64, lease->addr_, LeasePageSize(1))); EXPECT_EQ(0, got.size()); @@ -767,53 +762,51 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteIdMultiThreading) { IOAddress lease_addr0(ADDRESS6[0]); IOAddress lease_addr1(ADDRESS6[1]); IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); + IOAddress link_addr(ADDRESS6[4]); + IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); vector remote_id0 = createFromString(DUID6[0]); vector remote_id1 = createFromString(DUID6[1]); vector remote_id2 = createFromString(DUID6[2]); // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - link_addr4, - remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - link_addr5, - remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - zero, - remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, - link_addr6, - remote_id0)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr1, - link_addr6, - remote_id1)); - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr2, - link_addr4, - remote_id1)); + 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 address: nothing. + // 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 address #4: nothing. + // Unknown remote id #2, link: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id2, - link_addr4, + link_addr, + 64, zero, LeasePageSize(10))); EXPECT_EQ(0, got.size()); - // Remote id #0, no link address: 3 entries but 2 addresses. + // 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()); @@ -824,9 +817,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Remote id #1, no link address, partial: 2 entries. + // 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()); @@ -837,9 +831,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr1, lease->addr_); - // Remote id #1, no link address, partial from previous: 1 entry. + // 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()); @@ -848,27 +843,30 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteIdMultiThreading) { EXPECT_EQ(lease_addr2, lease->addr_); // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, - link_addr4, - remote_id1)); + EXPECT_NO_THROW(lease_mgr_->addRemoteId6(lease_addr0, remote_id1)); EXPECT_EQ(7, lease_mgr_->remote_id6_.size()); - // Remote id #1, link address #4: 2 entries. + // Remote id #1, link: 3 entries. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(10))); - ASSERT_EQ(2, got.size()); + 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 address #4, initial partial: 1 entry. + // Remote id #1, link, initial partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + link_addr, + 64, zero, LeasePageSize(1))); ASSERT_EQ(1, got.size()); @@ -876,9 +874,21 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr0, lease->addr_); - // Remote id #1, link address #4, next partial: 1 entry. + // Remote id #1, link, next partial: 1 entry. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + 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()); @@ -886,9 +896,10 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByRemoteIdMultiThreading) { ASSERT_TRUE(lease); EXPECT_EQ(lease_addr2, lease->addr_); - // Remote id #1, link address #4, final partial: nothing. + // Remote id #1, link, final partial: nothing. EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByRemoteId(remote_id1, - link_addr4, + link_addr, + 64, lease->addr_, LeasePageSize(1))); EXPECT_EQ(0, got.size()); @@ -899,197 +910,128 @@ TEST_F(MemfileExtendedInfoTest, getLeases6ByLink) { // Lease manager is created with empty tables. start(Memfile_LeaseMgr::V6); initLease6(); - EXPECT_EQ(0, lease_mgr_->link_addr6_.size()); // Create parameter values. - IOAddress lease_addr0(ADDRESS6[0]); - IOAddress lease_addr1(ADDRESS6[1]); - IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); - IOAddress link_addr7(ADDRESS6[7]); + IOAddress link_addr(ADDRESS6[4]); + IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr4)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr5)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr1, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr1, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr2, link_addr4)); - EXPECT_EQ(6, lease_mgr_->link_addr6_.size()); - Lease6Collection got; - // Unknown link address #7: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr7, + // Other link: nothing. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(other_link_addr, + 64, zero, LeasePageSize(10))); EXPECT_EQ(0, got.size()); - // Link address #4: 2 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr4, + // Link: 8 entries. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, 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_addr2, lease->addr_); + 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 address #5: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr5, + // Link: initial partial: 4 entries. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, zero, - LeasePageSize(10))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, 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]), lease->addr_); + } - // Link address #6: 3 entries but 2 addresses. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, - zero, - LeasePageSize(10))); - 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_); - - // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr2, link_addr6)); - EXPECT_EQ(7, lease_mgr_->link_addr6_.size()); - - // Link address #6: initial partial: 2 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, - 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_); - - // Link address #6: next partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, + // Link: next partial: 4 entries. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, lease->addr_, - LeasePageSize(2))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, 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 address #6: further partial: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, + // Link: further partial: nothing. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, lease->addr_, - LeasePageSize(2))); + LeasePageSize(4))); EXPECT_EQ(0, got.size()); } /// @brief Verifies that getLeases6ByLink works as expected with MT. TEST_F(MemfileExtendedInfoTest, getLeases6ByLinkMultiThreading) { MultiThreadingTest mt(true); - // Lease manager is created with empty tables. start(Memfile_LeaseMgr::V6); initLease6(); - EXPECT_EQ(0, lease_mgr_->link_addr6_.size()); // Create parameter values. - IOAddress lease_addr0(ADDRESS6[0]); - IOAddress lease_addr1(ADDRESS6[1]); - IOAddress lease_addr2(ADDRESS6[2]); - IOAddress link_addr4(ADDRESS6[4]); - IOAddress link_addr5(ADDRESS6[5]); - IOAddress link_addr6(ADDRESS6[6]); - IOAddress link_addr7(ADDRESS6[7]); + IOAddress link_addr(ADDRESS6[4]); + IOAddress other_link_addr("2001:db8:1::4"); IOAddress zero = IOAddress::IPV6_ZERO_ADDRESS(); - // Fill the table. - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr4)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr5)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr0, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr1, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr1, link_addr6)); - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr2, link_addr4)); - EXPECT_EQ(6, lease_mgr_->link_addr6_.size()); - Lease6Collection got; - // Unknown link address #7: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr7, + // Other link: nothing. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(other_link_addr, + 64, zero, LeasePageSize(10))); EXPECT_EQ(0, got.size()); - // Link address #4: 2 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr4, + // Link: 8 entries. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, 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_addr2, lease->addr_); + 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 address #5: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr5, + // Link: initial partial: 4 entries. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, zero, - LeasePageSize(10))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr0, 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]), lease->addr_); + } - // Link address #6: 3 entries but 2 addresses. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, - zero, - LeasePageSize(10))); - 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_); - - // Add another entry for last tests. - EXPECT_NO_THROW(lease_mgr_->addLinkAddr6(lease_addr2, link_addr6)); - EXPECT_EQ(7, lease_mgr_->link_addr6_.size()); - - // Link address #6: initial partial: 2 entries. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, - 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_); - - // Link address #6: next partial: 1 entry. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, + // Link: next partial: 4 entries. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, lease->addr_, - LeasePageSize(2))); - ASSERT_EQ(1, got.size()); - lease = got[0]; - ASSERT_TRUE(lease); - EXPECT_EQ(lease_addr2, 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 address #6: further partial: nothing. - EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr6, + // Link: further partial: nothing. + EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr, + 64, lease->addr_, - LeasePageSize(2))); + LeasePageSize(4))); EXPECT_EQ(0, got.size()); }