]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3149] Rewrote getLeases6ByLink
authorFrancis Dupont <fdupont@isc.org>
Thu, 14 Dec 2023 14:21:15 +0000 (15:21 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 17 Jan 2024 10:06:16 +0000 (11:06 +0100)
14 files changed:
src/lib/dhcpsrv/dhcpsrv_messages.cc
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/memfile_lease_storage.h
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/pgsql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_lease_mgr.h
src/lib/dhcpsrv/tests/memfile_lease_extended_info_unittest.cc
src/lib/dhcpsrv/testutils/concrete_lease_mgr.cc
src/lib/dhcpsrv/testutils/concrete_lease_mgr.h
src/lib/dhcpsrv/testutils/generic_lease_extended_info_unittest.h

index 42b228140af4b321bcc2be8dc179a675a79b0f33..7ec251da82d4e74f3acac09e5eb2c69ad8be6f70 100644 (file)
@@ -400,7 +400,7 @@ 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 %3/%4",
+    "DHCPSRV_MEMFILE_GET_LINKADDR6", "obtaining at most %1 IPv6 leases starting from address %2 with link %3",
     "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",
@@ -458,7 +458,7 @@ const char* values[] = {
     "DHCPSRV_MYSQL_GET_HWADDR", "obtaining IPv4 leases for hardware address %1",
     "DHCPSRV_MYSQL_GET_IAID_DUID", "obtaining IPv6 leases for IAID %1, DUID %2, lease type %3",
     "DHCPSRV_MYSQL_GET_IAID_SUBID_DUID", "obtaining IPv6 leases for IAID %1, Subnet ID %2, DUID %3, lease type %4",
-    "DHCPSRV_MYSQL_GET_LINKADDR6", "obtaining at most %1 IPv6 leases starting from address %2 with link %3/%4",
+    "DHCPSRV_MYSQL_GET_LINKADDR6", "obtaining at most %1 IPv6 leases starting from address %2 with link %3",
     "DHCPSRV_MYSQL_GET_PAGE4", "obtaining at most %1 IPv4 leases starting from address %2",
     "DHCPSRV_MYSQL_GET_PAGE6", "obtaining at most %1 IPv6 leases starting from address %2",
     "DHCPSRV_MYSQL_GET_RELAYID4", "obtaining at most %1 IPv4 leases starting from address %2 with relay id %3 and cltt between %4 and %5",
@@ -518,7 +518,7 @@ const char* values[] = {
     "DHCPSRV_PGSQL_GET_HWADDR", "obtaining IPv4 leases for hardware address %1",
     "DHCPSRV_PGSQL_GET_IAID_DUID", "obtaining IPv4 leases for IAID %1 and DUID %2, lease type %3",
     "DHCPSRV_PGSQL_GET_IAID_SUBID_DUID", "obtaining IPv4 leases for IAID %1, Subnet ID %2, DUID %3, and lease type %4",
-    "DHCPSRV_PGSQL_GET_LINKADDR6", "obtaining at most %1 IPv6 leases starting from address %2 with link %3/%4",
+    "DHCPSRV_PGSQL_GET_LINKADDR6", "obtaining at most %1 IPv6 leases starting from address %2 with link %3",
     "DHCPSRV_PGSQL_GET_PAGE4", "obtaining at most %1 IPv4 leases starting from address %2",
     "DHCPSRV_PGSQL_GET_PAGE6", "obtaining at most %1 IPv6 leases starting from address %2",
     "DHCPSRV_PGSQL_GET_RELAYID4", "obtaining at most %1 IPv4 leases starting from address %2 with relay id %3 and cltt between %4 and %5",
index d8b42888ad38a49c597c29076eb77fb979a563d6..8ccce896994ca7805c028a1874b9cc7afd84a01a 100644 (file)
@@ -599,7 +599,7 @@ 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 %3/%4
+% DHCPSRV_MEMFILE_GET_LINKADDR6 obtaining at most %1 IPv6 leases starting from address %2 with link %3
 A debug message issued when the server is attempting to obtain a page of
 IPv6 leases beginning with the specified address within a link.
 
@@ -887,7 +887,7 @@ A debug message issued when the server is attempting to obtain an IPv6
 lease from the MySQL database for a client with the specified IAID
 (Identity Association ID), Subnet ID and DUID (DHCP Unique Identifier).
 
-% DHCPSRV_MYSQL_GET_LINKADDR6 obtaining at most %1 IPv6 leases starting from address %2 with link %3/%4
+% DHCPSRV_MYSQL_GET_LINKADDR6 obtaining at most %1 IPv6 leases starting from address %2 with link %3
 A debug message issued when the server is attempting to obtain a page of
 IPv6 leases beginning with the specified address within a link.
 
@@ -1167,7 +1167,7 @@ A debug message issued when the server is attempting to obtain an IPv6
 lease from the PostgreSQL database for a client with the specified IAID
 (Identity Association ID), Subnet ID and DUID (DHCP Unique Identifier).
 
-% DHCPSRV_PGSQL_GET_LINKADDR6 obtaining at most %1 IPv6 leases starting from address %2 with link %3/%4
+% DHCPSRV_PGSQL_GET_LINKADDR6 obtaining at most %1 IPv6 leases starting from address %2 with link %3
 A debug message issued when the server is attempting to obtain a page of
 IPv6 leases beginning with the specified address within a link.
 
index b3ac56bc079e10bc58d7b07419e4b483ad43e209..d61155ce655cd9272e4a7d8912055217bf507256 100644 (file)
@@ -967,16 +967,14 @@ public:
 
     /// @brief Returns existing IPv6 leases with on a given link.
     ///
-    /// @param link_addr limit results to leases on this link (prefix).
-    /// @param link_len limit results to leases on this link (length).
+    /// @param subnet_id subnet identifier.
     /// @param lower_bound_address IPv6 address used as lower bound for the
     /// returned range.
     /// @param page_size maximum size of the page returned.
     ///
     /// @return collection of IPv6 leases
     virtual Lease6Collection
-    getLeases6ByLink(const asiolink::IOAddress& link_addr,
-                     uint8_t link_len,
+    getLeases6ByLink(SubnetID subnet_id,
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) = 0;
 
index 3c634226196d63b6fd62a98657b03a487932dfbf..eb4ab394084a6c35f1c8c2af0ce5aa95339c33b3 100644 (file)
@@ -3172,27 +3172,16 @@ Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(const OptionBuffer& remote_id,
 }
 
 Lease6Collection
-Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
-                                   uint8_t link_len,
+Memfile_LeaseMgr::getLeases6ByLink(SubnetID subnet_id,
                                    const IOAddress& lower_bound_address,
                                    const LeasePageSize& page_size) {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
               DHCPSRV_MEMFILE_GET_LINKADDR6)
         .arg(page_size.page_size_)
         .arg(lower_bound_address.toText())
-        .arg(link_addr.toText())
-        .arg(static_cast<unsigned>(link_len));
+        .arg(subnet_id);
 
-    // 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<unsigned>(link_len));
-    }
+    // Expecting IPv6 valid address.
     if (!lower_bound_address.isV6()) {
         isc_throw(InvalidAddressFamily, "expected IPv6 address while "
                   "retrieving leases from the lease database, got "
@@ -3201,46 +3190,40 @@ Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
 
     if (MultiThreadingMgr::instance().getMode()) {
         std::lock_guard<std::mutex> lock(*mutex_);
-        return (getLeases6ByLinkInternal(link_addr,
-                                         link_len,
+        return (getLeases6ByLinkInternal(subnet_id,
                                          lower_bound_address,
                                          page_size));
     } else {
-        return (getLeases6ByLinkInternal(link_addr,
-                                         link_len,
+        return (getLeases6ByLinkInternal(subnet_id,
                                          lower_bound_address,
                                          page_size));
     }
 }
 
 Lease6Collection
-Memfile_LeaseMgr::getLeases6ByLinkInternal(const IOAddress& link_addr,
-                                           uint8_t link_len,
+Memfile_LeaseMgr::getLeases6ByLinkInternal(SubnetID subnet_id,
                                            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 Lease6StorageAddressIndex& idx = storage6_.get<AddressIndexTag>();
-    Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(start_addr);
-    Lease6StorageAddressIndex::const_iterator eb = idx.upper_bound(last_addr);
+    const Lease6StorageSubnetIdIndex& idx = storage6_.get<SubnetIdIndexTag>();
+    Lease6StorageSubnetIdIndex::const_iterator lb =
+        idx.lower_bound(boost::make_tuple(subnet_id, lower_bound_address));
 
     // Return all leases being within the page size.
-    IOAddress last_seen_addr = lower_bound_address;
-    for (auto it = lb; it != eb; ++it) {
-        if ((*it)->addr_ == last_seen_addr) {
+    IOAddress last_addr = lower_bound_address;
+    for (auto it = lb; it != idx.end(); ++it) {
+        if ((*it)->addr_ == last_addr) {
             // Already seen: skip it.
             continue;
         }
-        last_seen_addr = (*it)->addr_;
-        Lease6Ptr lease = getAnyLease6Internal(last_seen_addr);
-        if (lease) {
-            collection.push_back(lease);
-            if (collection.size() >= page_size.page_size_) {
-                break;
-            }
+        if ((*it)->subnet_id_ != subnet_id) {
+            // Gone after the subnet id index.
+            break;
+        }
+        last_addr = (*it)->addr_;
+        collection.push_back(Lease6Ptr(new Lease6(**it)));
+        if (collection.size() >= page_size.page_size_) {
+            break;
         }
     }
     return (collection);
index 896bdc2ed0ab44d8a68f0d220beb0f03d781d526..1d1f3412c720909aafc5c49d8c5f7bda3645c266 100644 (file)
@@ -1385,16 +1385,14 @@ public:
 
     /// @brief Returns existing IPv6 leases with on a given link.
     ///
-    /// @param link_addr limit results to leases on this link (prefix).
-    /// @param link_len limit results to leases on this link (length).
+    /// @param subnet_id subnet identifier.
     /// @param lower_bound_address IPv4 address used as lower bound for the
     /// returned range.
     /// @param page_size maximum size of the page returned.
     ///
     /// @return collection of IPv6 leases
     virtual Lease6Collection
-    getLeases6ByLink(const asiolink::IOAddress& link_addr,
-                     uint8_t link_len,
+    getLeases6ByLink(SubnetID subnet_id,
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) override;
 
@@ -1496,16 +1494,14 @@ private:
 
     /// @brief Returns existing IPv6 leases with on a given link.
     ///
-    /// @param link_addr limit results to leases on this link (prefix).
-    /// @param link_len limit results to leases on this link (length).
+    /// @param subnet_id subnet identifier.
     /// @param lower_bound_address IPv4 address used as lower bound for the
     /// returned range.
     /// @param page_size maximum size of the page returned.
     ///
     /// @return collection of IPv6 leases
     Lease6Collection
-    getLeases6ByLinkInternal(const asiolink::IOAddress& link_addr,
-                             uint8_t link_len,
+    getLeases6ByLinkInternal(SubnetID subnet_id,
                              const asiolink::IOAddress& lower_bound_address,
                              const LeasePageSize& page_size);
 public:
index 174dff49d6b32ca697d2e1f80371e699ef38b6cf..96dda3815c77515a8194249f01ddb8325f87a5f1 100644 (file)
@@ -40,7 +40,7 @@ struct HWAddressSubnetIdIndexTag { };
 /// @brief Tag for indexes by client-id, subnet-id tuple.
 struct ClientIdSubnetIdIndexTag { };
 
-/// @brief Tag for indexes by subnet-id.
+/// @brief Tag for indexes by subnet-id (and address for v6).
 struct SubnetIdIndexTag { };
 
 /// @brief Tag for indexes by subnet-id and pool-id.
@@ -124,11 +124,20 @@ typedef boost::multi_index_container<
         >,
 
         // Specification of the fourth index starts here.
-        // This index sorts leases by SubnetID.
+        // This index sorts leases by SubnetID and address.
         boost::multi_index::ordered_non_unique<
             boost::multi_index::tag<SubnetIdIndexTag>,
-            boost::multi_index::member<Lease, isc::dhcp::SubnetID,
-            &Lease::subnet_id_>
+            boost::multi_index::composite_key<
+                Lease6,
+                // Subnet id.
+                boost::multi_index::member<Lease,
+                                           isc::dhcp::SubnetID,
+                                           &Lease::subnet_id_>,
+                // Address.
+                boost::multi_index::member<Lease,
+                                           isc::asiolink::IOAddress,
+                                           &Lease::addr_>
+            >
         >,
 
         // Specification of the fifth index starts here
index 6edbd6c3ae4eb38ac30f6902eecd497a90cf2af8..c4c4197509df57a132dcbd36b47862697344c84a 100644 (file)
@@ -398,7 +398,7 @@ tagged_statements = { {
                         "hwaddr, hwtype, hwaddr_source, "
                         "state, user_context, pool_id "
                             "FROM lease6 "
-                            "WHERE address BETWEEN ? AND ? "
+                            "WHERE subnet_id = ? AND address > ? "
                             "ORDER BY address "
                             "LIMIT ?"},
     {MySqlLeaseMgr::INSERT_LEASE4,
@@ -4468,27 +4468,16 @@ MySqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id,
 }
 
 Lease6Collection
-MySqlLeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
-                                uint8_t link_len,
+MySqlLeaseMgr::getLeases6ByLink(SubnetID subnet_id,
                                 const IOAddress& lower_bound_address,
                                 const LeasePageSize& page_size) {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
               DHCPSRV_MYSQL_GET_LINKADDR6)
         .arg(page_size.page_size_)
         .arg(lower_bound_address.toText())
-        .arg(link_addr.toText())
-        .arg(static_cast<unsigned>(link_len));
+        .arg(subnet_id);
 
-    // Expecting IPv6 valid prefix and address.
-    if (!link_addr.isV6()) {
-        isc_throw(InvalidAddressFamily, "expected IPv6 link 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<unsigned>(link_len));
-    }
+    // Expecting IPv6 valid address.
     if (!lower_bound_address.isV6()) {
         isc_throw(InvalidAddressFamily, "expected IPv6 start address while "
                   "retrieving leases from the lease database, got "
@@ -4496,44 +4485,25 @@ MySqlLeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
     }
 
     Lease6Collection result;
-    const IOAddress& first_addr = firstAddrInPrefix(link_addr, link_len);
-    const IOAddress& last_addr = lastAddrInPrefix(link_addr, link_len);
-    IOAddress start_addr = lower_bound_address;
-    if (lower_bound_address < first_addr) {
-        start_addr = first_addr;
-    } else if (last_addr <= lower_bound_address) {
-        // Range was already done.
-        return (result);
-    } else {
-        // The lower bound address is from the last call so skip it.
-        start_addr = IOAddress::increase(lower_bound_address);
-    }
-
     // Prepare WHERE clause
     MYSQL_BIND inbind[3];
     memset(inbind, 0, sizeof(inbind));
 
-    // Bind start address
-    std::vector<uint8_t> start_addr_data = start_addr.toBytes();
-    if (start_addr_data.size() != 16) {
-        isc_throw(DbOperationError, "start address is not 16 bytes long");
-    }
-    unsigned long start_addr_size = 16;
-    inbind[0].buffer_type = MYSQL_TYPE_BLOB;
-    inbind[0].buffer = reinterpret_cast<char*>(&start_addr_data[0]);
-    inbind[0].buffer_length = 16;
-    inbind[0].length = &start_addr_size;
+    // Bind the subnet id.
+    inbind[0].buffer_type = MYSQL_TYPE_LONG;
+    inbind[0].buffer = reinterpret_cast<char*>(&subnet_id);
+    inbind[0].is_unsigned = MLM_TRUE;
 
-    // Bind last address
-    std::vector<uint8_t> last_addr_data = last_addr.toBytes();
-    if (last_addr_data.size() != 16) {
-        isc_throw(DbOperationError, "last address is not 16 bytes long");
+    // Bind the lower bound address.
+    std::vector<uint8_t> lb_addr_data = lower_bound_address.toBytes();
+    unsigned long lb_addr_size = lb_addr_data.size();
+    if (lb_addr_size != 16) {
+        isc_throw(DbOperationError, "lower bound address is not 16 bytes long");
     }
-    unsigned long last_addr_size = 16;
     inbind[1].buffer_type = MYSQL_TYPE_BLOB;
-    inbind[1].buffer = reinterpret_cast<char*>(&last_addr_data[0]);
-    inbind[1].buffer_length = 16;
-    inbind[1].length = &last_addr_size;
+    inbind[1].buffer = reinterpret_cast<char*>(&lb_addr_data[0]);
+    inbind[1].buffer_length = lb_addr_size;
+    inbind[1].length = &lb_addr_size;
 
     // Bind page size value
     uint32_t ps = static_cast<uint32_t>(page_size.page_size_);
index b0b6b37348bd9c012b3199e0dc0663493e2e04c8..4fe8a185a9e8ea28bdc30565e4255d113e283b90 100644 (file)
@@ -1141,16 +1141,14 @@ public:
 
     /// @brief Returns existing IPv6 leases with on a given link.
     ///
-    /// @param link_addr limit results to leases on this link (prefix).
-    /// @param link_len limit results to leases on this link (length).
+    /// @param subnet_id subnet identifier.
     /// @param lower_bound_address IPv4 address used as lower bound for the
     /// returned range.
     /// @param page_size maximum size of the page returned.
     ///
     /// @return collection of IPv6 leases
     virtual Lease6Collection
-    getLeases6ByLink(const asiolink::IOAddress& link_addr,
-                     uint8_t link_len,
+    getLeases6ByLink(SubnetID subnet_id,
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) override;
 
index 97c0973ed573110b730f4af4cbe5f65764c80fb7..d9e80283a321ec44dfdd0155c2dea05544ae4550 100644 (file)
@@ -409,7 +409,7 @@ PgSqlTaggedStatement tagged_statements[] = {
       "LIMIT $3" },
 
     // GET_LEASE6_LINK
-    { 3, { OID_VARCHAR, OID_VARCHAR, OID_INT8 },
+    { 3, { OID_INT8, OID_VARCHAR, OID_INT8 },
       "get_lease6_link",
       "SELECT host(address), duid, valid_lifetime, "
         "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
@@ -417,7 +417,7 @@ PgSqlTaggedStatement tagged_statements[] = {
         "hwaddr, hwtype, hwaddr_source, "
         "state, user_context, pool_id "
       "FROM lease6 "
-      "WHERE address BETWEEN cast($1 as inet) and cast($2 as inet) "
+      "WHERE subnet_id = $1 AND address > cast($2 as inet) "
       "ORDER BY address "
       "LIMIT $3" },
 
@@ -3530,29 +3530,16 @@ PgSqlLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id,
 }
 
 Lease6Collection
-PgSqlLeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
-                                uint8_t link_len,
+PgSqlLeaseMgr::getLeases6ByLink(SubnetID subnet_id,
                                 const IOAddress& lower_bound_address,
                                 const LeasePageSize& page_size) {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
               DHCPSRV_PGSQL_GET_LINKADDR6)
         .arg(page_size.page_size_)
         .arg(lower_bound_address.toText())
-        .arg(link_addr.toText())
-        .arg(static_cast<unsigned>(link_len));
-
-    // Expecting IPv6 valid prefix and address.
-    if (!link_addr.isV6()) {
-        isc_throw(InvalidAddressFamily, "expected IPv6 link 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<unsigned>(link_len));
-    }
+        .arg(subnet_id);
 
+    // Expecting IPv6 valid address.
     if (!lower_bound_address.isV6()) {
         isc_throw(InvalidAddressFamily, "expected IPv6 start address while "
                   "retrieving leases from the lease database, got "
@@ -3560,29 +3547,16 @@ PgSqlLeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
     }
 
     Lease6Collection result;
-    const IOAddress& first_addr = firstAddrInPrefix(link_addr, link_len);
-    const IOAddress& last_addr = lastAddrInPrefix(link_addr, link_len);
-    IOAddress start_addr = lower_bound_address;
-    if (lower_bound_address < first_addr) {
-        start_addr = first_addr;
-    } else if (last_addr <= lower_bound_address) {
-        // Range was already done.
-        return (result);
-    } else {
-        // The lower bound address is from the last call so skip it.
-        start_addr = IOAddress::increase(lower_bound_address);
-    }
-
     // Prepare WHERE clause
     PsqlBindArray bind_array;
 
-    // Bind start address
-    std::string start_addr_str = start_addr.toText();
-    bind_array.add(start_addr_str);
+    // Bind subnet id.
+    std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
+    bind_array.add(subnet_id_str);
 
-    // Bind last address
-    std::string last_addr_str = last_addr.toText();
-    bind_array.add(last_addr_str);
+    // Bind lower bound address
+    std::string lb_address_str = lower_bound_address.toText();
+    bind_array.add(lb_address_str);
 
     // Bind page size value
     std::string page_size_data =
index dd461b1945c3ddf7ae7a0f421344eccc32aba470..5617f058c73d17b6b16056ac61d17753a3146f92 100644 (file)
@@ -1095,16 +1095,14 @@ public:
 
     /// @brief Returns existing IPv6 leases with on a given link.
     ///
-    /// @param link_addr limit results to leases on this link (prefix).
-    /// @param link_len limit results to leases on this link (length).
+    /// @param subnet_id subnet identifier.
     /// @param lower_bound_address IPv4 address used as lower bound for the
     /// returned range.
     /// @param page_size maximum size of the page returned.
     ///
     /// @return collection of IPv6 leases
     virtual Lease6Collection
-    getLeases6ByLink(const asiolink::IOAddress& link_addr,
-                     uint8_t link_len,
+    getLeases6ByLink(SubnetID subnet_id,
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) override;
 
index a5116835840981d10ffb7e557e1ac8105847cf26..27813a89a7011a690ac2c48023cffc527ec8f95d 100644 (file)
@@ -994,23 +994,25 @@ MemfileExtendedInfoTest::testGetLeases6ByLink() {
     start(Memfile_LeaseMgr::V6);
     initLease6();
 
+    // Put leases in the subnet 1.
+    for (size_t i = 0; i < leases6.size(); ++i) {
+        Lease6Ptr lease(new Lease6(*leases6[i]));
+        leases6[i] = lease;
+        lease->subnet_id_ = 1;
+        EXPECT_NO_THROW(lease_mgr_->updateLease6(leases6[i]));
+    }
+
     // 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,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(10, zero,
                                                        LeasePageSize(10)));
     EXPECT_EQ(0, got.size());
 
     // Link: 8 entries.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       zero,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, zero,
                                                        LeasePageSize(10)));
 
     ASSERT_EQ(8, got.size());
@@ -1022,9 +1024,7 @@ MemfileExtendedInfoTest::testGetLeases6ByLink() {
     }
 
     // Link: initial partial: 4 entries.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       zero,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, zero,
                                                        LeasePageSize(4)));
     ASSERT_EQ(4, got.size());
     for (size_t i = 0; i < 4; ++i) {
@@ -1034,9 +1034,7 @@ MemfileExtendedInfoTest::testGetLeases6ByLink() {
     }
 
     // Link: next partial: 4 entries.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       lease->addr_,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, lease->addr_,
                                                        LeasePageSize(4)));
     ASSERT_EQ(4, got.size());
     for (size_t i = 0; i < 4; ++i) {
@@ -1046,9 +1044,7 @@ MemfileExtendedInfoTest::testGetLeases6ByLink() {
     }
 
     // Link: further partial: nothing.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       lease->addr_,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, lease->addr_,
                                                        LeasePageSize(4)));
     EXPECT_EQ(0, got.size());
 }
index 6a99637c0a8791eb4b8afd1c6e7bc72dae069630..0c162c7b78d86d82d5754432bd3a8a847d330b23 100644 (file)
@@ -280,8 +280,7 @@ ConcreteLeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */,
 }
 
 Lease6Collection
-ConcreteLeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */,
-                                   uint8_t /* link_len */,
+ConcreteLeaseMgr::getLeases6ByLink(SubnetID /* subnet_id */,
                                    const IOAddress& /* lower_bound_address */,
                                    const LeasePageSize& /* page_size */) {
     isc_throw(NotImplemented, "ConcreteLeaseMgr::getLeases6ByLink not implemented");
index d1ec4bb286763c20f6833701603bba02f903be5d..caab063290bc701bd665164cce615ab86b6b3129 100644 (file)
@@ -368,8 +368,7 @@ public:
 
     /// @brief Stub implementation.
     Lease6Collection
-    getLeases6ByLink(const asiolink::IOAddress& /* link_addr */,
-                     uint8_t /* link_len */,
+    getLeases6ByLink(SubnetID /* subnet_id */,
                      const asiolink::IOAddress& /* lower_bound_address */,
                      const LeasePageSize& /* page_size */) override;
 
index c78558174096c44cb5cbd534d43553789331d1ad..45f41ca64e3f553cd0f547ebec72ff2bb4ae5855 100644 (file)
@@ -1215,23 +1215,25 @@ GenericExtendedInfoTest<NakedLeaseMgrType>::testGetLeases6ByLink() {
     start(false);
     initLease6();
 
+    // Put leases in the subnet 1.
+    for (size_t i = 0; i < leases6.size(); ++i) {
+        Lease6Ptr lease(new Lease6(*leases6[i]));
+        leases6[i] = lease;
+        lease->subnet_id_ = 1;
+        EXPECT_NO_THROW(lease_mgr_->updateLease6(leases6[i]));
+    }
+
     // Create parameter values.
-    asiolink::IOAddress link_addr(ADDRESS6[4]);
-    asiolink::IOAddress other_link_addr("2001:db8:1::4");
     asiolink::IOAddress zero = asiolink::IOAddress::IPV6_ZERO_ADDRESS();
 
     Lease6Collection got;
     // Other link: nothing.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(other_link_addr,
-                                                       64,
-                                                       zero,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(100, zero,
                                                        LeasePageSize(10)));
     EXPECT_EQ(0, got.size());
 
     // Link: 8 entries.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       zero,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, zero,
                                                        LeasePageSize(10)));
 
     ASSERT_EQ(8, got.size());
@@ -1243,9 +1245,7 @@ GenericExtendedInfoTest<NakedLeaseMgrType>::testGetLeases6ByLink() {
     }
 
     // Link: initial partial: 4 entries.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       zero,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, zero,
                                                        LeasePageSize(4)));
     ASSERT_EQ(4, got.size());
     for (size_t i = 0; i < 4; ++i) {
@@ -1255,9 +1255,7 @@ GenericExtendedInfoTest<NakedLeaseMgrType>::testGetLeases6ByLink() {
     }
 
     // Link: next partial: 4 entries.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       lease->addr_,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, lease->addr_,
                                                        LeasePageSize(4)));
     ASSERT_EQ(4, got.size());
     for (size_t i = 0; i < 4; ++i) {
@@ -1267,9 +1265,7 @@ GenericExtendedInfoTest<NakedLeaseMgrType>::testGetLeases6ByLink() {
     }
 
     // Link: further partial: nothing.
-    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(link_addr,
-                                                       64,
-                                                       lease->addr_,
+    EXPECT_NO_THROW(got = lease_mgr_->getLeases6ByLink(1, lease->addr_,
                                                        LeasePageSize(4)));
     EXPECT_EQ(0, got.size());
 }