Browse Source

[3148] Implemented getLeases6 methods which take lease type into account.

Marcin Siodelski 11 years ago
parent
commit
43fc427118

+ 3 - 3
src/lib/dhcpsrv/dhcpsrv_messages.mes

@@ -236,7 +236,7 @@ address.
 A debug message issued when the server is attempting to obtain an IPv4
 A debug message issued when the server is attempting to obtain an IPv4
 lease from the memory file database for the specified address.
 lease from the memory file database for the specified address.
 
 
-% DHCPSRV_MEMFILE_GET_ADDR6 obtaining IPv6 lease for address %1
+% DHCPSRV_MEMFILE_GET_ADDR6 obtaining IPv6 lease for address %1 and lease type %2
 A debug message issued when the server is attempting to obtain an IPv6
 A debug message issued when the server is attempting to obtain an IPv6
 lease from the memory file database for the specified address.
 lease from the memory file database for the specified address.
 
 
@@ -255,12 +255,12 @@ A debug message issued when the server is attempting to obtain a set of
 IPv4 leases from the memory file database for a client with the specified
 IPv4 leases from the memory file database for a client with the specified
 hardware address.
 hardware address.
 
 
-% DHCPSRV_MEMFILE_GET_IAID_DUID obtaining IPv6 leases for IAID %1 and DUID %2
+% DHCPSRV_MEMFILE_GET_IAID_DUID obtaining IPv6 leases for IAID %1 and DUID %2 and lease type %3
 A debug message issued when the server is attempting to obtain a set of
 A debug message issued when the server is attempting to obtain a set of
 IPv6 lease from the memory file database for a client with the specified
 IPv6 lease from the memory file database for a client with the specified
 IAID (Identity Association ID) and DUID (DHCP Unique Identifier).
 IAID (Identity Association ID) and DUID (DHCP Unique Identifier).
 
 
-% DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID obtaining IPv6 leases for IAID %1, Subnet ID %2 and DUID %3
+% DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID obtaining IPv6 leases for IAID %1, Subnet ID %2, DUID %3 and lease type %4
 A debug message issued when the server is attempting to obtain an IPv6
 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
 lease from the memory file database for a client with the specified IAID
 (Identity Association ID), Subnet ID and DUID (DHCP Unique Identifier).
 (Identity Association ID), Subnet ID and DUID (DHCP Unique Identifier).

+ 36 - 22
src/lib/dhcpsrv/memfile_lease_mgr.cc

@@ -235,13 +235,14 @@ Memfile_LeaseMgr::getLease4(const ClientId& client_id,
 }
 }
 
 
 Lease6Ptr
 Lease6Ptr
-Memfile_LeaseMgr::getLease6(Lease::Type /* not used yet */,
+Memfile_LeaseMgr::getLease6(Lease::Type type,
                             const isc::asiolink::IOAddress& addr) const {
                             const isc::asiolink::IOAddress& addr) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
-              DHCPSRV_MEMFILE_GET_ADDR6).arg(addr.toText());
-
+              DHCPSRV_MEMFILE_GET_ADDR6)
+        .arg(addr.toText())
+        .arg(Lease::typeToText(type));
     Lease6Storage::iterator l = storage6_.find(addr);
     Lease6Storage::iterator l = storage6_.find(addr);
-    if (l == storage6_.end()) {
+    if (l == storage6_.end() || !(*l) || ((*l)->type_ != type)) {
         return (Lease6Ptr());
         return (Lease6Ptr());
     } else {
     } else {
         return (Lease6Ptr(new Lease6(**l)));
         return (Lease6Ptr(new Lease6(**l)));
@@ -249,42 +250,55 @@ Memfile_LeaseMgr::getLease6(Lease::Type /* not used yet */,
 }
 }
 
 
 Lease6Collection
 Lease6Collection
-Memfile_LeaseMgr::getLeases6(Lease::Type /* not used yet */,
+Memfile_LeaseMgr::getLeases6(Lease::Type type,
                             const DUID& duid, uint32_t iaid) const {
                             const DUID& duid, uint32_t iaid) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
-              DHCPSRV_MEMFILE_GET_IAID_DUID).arg(iaid).arg(duid.toText());
+              DHCPSRV_MEMFILE_GET_IAID_DUID)
+        .arg(iaid)
+        .arg(duid.toText())
+        .arg(Lease::typeToText(type));
 
 
-    /// @todo Not implemented.
+    // We are going to use index #1 of the multi index container.
+    typedef Lease6Storage::nth_index<1>::type SearchIndex;
+    // Get the index.
+    const SearchIndex& idx = storage6_.get<1>();
+    // Try to get the lease using the DUID, IAID and lease type.
+    std::pair<SearchIndex::iterator, SearchIndex::iterator> l =
+        idx.equal_range(boost::make_tuple(duid.getDuid(), iaid, type));
+    Lease6Collection collection;
+    for(SearchIndex::iterator lease = l.first; lease != l.second; ++lease) {
+        collection.push_back(Lease6Ptr(new Lease6(**lease)));
+    }
 
 
-    return (Lease6Collection());
+    return (collection);
 }
 }
 
 
 Lease6Collection
 Lease6Collection
-Memfile_LeaseMgr::getLeases6(Lease::Type /* not used yet */,
+Memfile_LeaseMgr::getLeases6(Lease::Type type,
                              const DUID& duid, uint32_t iaid,
                              const DUID& duid, uint32_t iaid,
                              SubnetID subnet_id) const {
                              SubnetID subnet_id) const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
               DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID)
               DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID)
-              .arg(iaid).arg(subnet_id).arg(duid.toText());
+        .arg(iaid)
+        .arg(subnet_id)
+        .arg(duid.toText())
+        .arg(Lease::typeToText(type));
 
 
     // We are going to use index #1 of the multi index container.
     // We are going to use index #1 of the multi index container.
-    // We define SearchIndex locally in this function because
-    // currently only this function uses this index.
     typedef Lease6Storage::nth_index<1>::type SearchIndex;
     typedef Lease6Storage::nth_index<1>::type SearchIndex;
     // Get the index.
     // Get the index.
     const SearchIndex& idx = storage6_.get<1>();
     const SearchIndex& idx = storage6_.get<1>();
-    // Try to get the lease using the DUID, IAID and Subnet ID.
-    SearchIndex::const_iterator lease =
-        idx.find(boost::make_tuple(duid.getDuid(), iaid, subnet_id));
-    // Lease was not found. Return empty pointer.
-    if (lease == idx.end()) {
-        return (Lease6Collection());
+    // Try to get the lease using the DUID, IAID and lease type.
+    std::pair<SearchIndex::iterator, SearchIndex::iterator> l =
+        idx.equal_range(boost::make_tuple(duid.getDuid(), iaid, type));
+    Lease6Collection collection;
+    for(SearchIndex::iterator lease = l.first; lease != l.second; ++lease) {
+        // Filter out the leases which subnet id doesn't match.
+        if((*lease)->subnet_id_ == subnet_id) {
+            collection.push_back(Lease6Ptr(new Lease6(**lease)));
+        }
     }
     }
 
 
-    // Lease was found, return it to the caller.
-    /// @todo: allow multiple leases for a single duid+iaid+subnet_id tuple
-    Lease6Collection collection;
-    collection.push_back(Lease6Ptr(new Lease6(**lease)));
     return (collection);
     return (collection);
 }
 }
 
 

+ 10 - 11
src/lib/dhcpsrv/memfile_lease_mgr.h

@@ -190,9 +190,8 @@ public:
     virtual Lease6Ptr getLease6(Lease::Type type,
     virtual Lease6Ptr getLease6(Lease::Type type,
                                 const isc::asiolink::IOAddress& addr) const;
                                 const isc::asiolink::IOAddress& addr) const;
 
 
-    /// @brief Returns existing IPv6 lease for a given DUID+IA combination
-    ///
-    /// @todo Not implemented yet
+    /// @brief Returns existing IPv6 lease for a given DUID + IA + lease type
+    /// combination
     ///
     ///
     /// @param type specifies lease type: (NA, TA or PD)
     /// @param type specifies lease type: (NA, TA or PD)
     /// @param duid client DUID
     /// @param duid client DUID
@@ -202,7 +201,8 @@ public:
     virtual Lease6Collection getLeases6(Lease::Type type,
     virtual Lease6Collection getLeases6(Lease::Type type,
                                         const DUID& duid, uint32_t iaid) const;
                                         const DUID& duid, uint32_t iaid) const;
 
 
-    /// @brief Returns existing IPv6 lease for a given DUID/IA/subnet-id tuple
+    /// @brief Returns existing IPv6 lease for a given DUID + IA + subnet-id +
+    /// lease type combination.
     ///
     ///
     /// This function returns a copy of the lease. The modification in the
     /// This function returns a copy of the lease. The modification in the
     /// return lease does not affect the instance held in the lease storage.
     /// return lease does not affect the instance held in the lease storage.
@@ -214,7 +214,8 @@ public:
     ///
     ///
     /// @return lease collection (may be empty if no lease is found)
     /// @return lease collection (may be empty if no lease is found)
     virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
     virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
-                                        uint32_t iaid, SubnetID subnet_id) const;
+                                        uint32_t iaid,
+                                        SubnetID subnet_id) const;
 
 
     /// @brief Updates IPv4 lease.
     /// @brief Updates IPv4 lease.
     ///
     ///
@@ -372,8 +373,6 @@ protected:
     /// will not be written to disk.
     /// will not be written to disk.
     ///
     ///
     /// @param u Universe (v4 or v6)
     /// @param u Universe (v4 or v6)
-    /// @param parameters Map holding parameters of the Lease Manager, passed to
-    /// the constructor.
     ///
     ///
     /// @return The location of the lease file that should be assigned to the
     /// @return The location of the lease file that should be assigned to the
     /// lease_file4_ or lease_file6_, depending on the universe specified as an
     /// lease_file4_ or lease_file6_, depending on the universe specified as an
@@ -394,9 +393,9 @@ protected:
             >,
             >,
 
 
             // Specification of the second index starts here.
             // Specification of the second index starts here.
-            boost::multi_index::ordered_unique<
+            boost::multi_index::ordered_non_unique<
                 // This is a composite index that will be used to search for
                 // This is a composite index that will be used to search for
-                // the lease using three attributes: DUID, IAID, Subnet Id.
+                // the lease using three attributes: DUID, IAID and lease type.
                 boost::multi_index::composite_key<
                 boost::multi_index::composite_key<
                     Lease6,
                     Lease6,
                     // The DUID can be retrieved from the Lease6 object using
                     // The DUID can be retrieved from the Lease6 object using
@@ -404,9 +403,9 @@ protected:
                     boost::multi_index::const_mem_fun<Lease6, const std::vector<uint8_t>&,
                     boost::multi_index::const_mem_fun<Lease6, const std::vector<uint8_t>&,
                                                       &Lease6::getDuidVector>,
                                                       &Lease6::getDuidVector>,
                     // The two other ingredients of this index are IAID and
                     // The two other ingredients of this index are IAID and
-                    // subnet id.
+                    // lease type.
                     boost::multi_index::member<Lease6, uint32_t, &Lease6::iaid_>,
                     boost::multi_index::member<Lease6, uint32_t, &Lease6::iaid_>,
-                    boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>
+                    boost::multi_index::member<Lease6, Lease::Type, &Lease6::type_>
                 >
                 >
             >
             >
         >
         >

+ 3 - 3
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc

@@ -319,7 +319,7 @@ TEST_F(MemfileLeaseMgrTest, basicLease6) {
 /// a combination of DUID and IAID.
 /// a combination of DUID and IAID.
 /// @todo: test disabled, because Memfile_LeaseMgr::getLeases6(Lease::Type,
 /// @todo: test disabled, because Memfile_LeaseMgr::getLeases6(Lease::Type,
 /// const DUID& duid, uint32_t iaid) const is not implemented yet.
 /// const DUID& duid, uint32_t iaid) const is not implemented yet.
-TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidIaid) {
+TEST_F(MemfileLeaseMgrTest, getLeases6DuidIaid) {
     startBackend(V6);
     startBackend(V6);
     testGetLeases6DuidIaid();
     testGetLeases6DuidIaid();
 }
 }
@@ -328,7 +328,7 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidIaid) {
 
 
 /// @todo: test disabled, because Memfile_LeaseMgr::getLeases6(Lease::Type,
 /// @todo: test disabled, because Memfile_LeaseMgr::getLeases6(Lease::Type,
 /// const DUID& duid, uint32_t iaid) const is not implemented yet.
 /// const DUID& duid, uint32_t iaid) const is not implemented yet.
-TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidSize) {
+TEST_F(MemfileLeaseMgrTest, getLeases6DuidSize) {
     startBackend(V6);
     startBackend(V6);
     testGetLeases6DuidSize();
     testGetLeases6DuidSize();
 }
 }
@@ -341,7 +341,7 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidSize) {
 /// discriminate between the leases based on lease type alone.
 /// discriminate between the leases based on lease type alone.
 /// @todo: Disabled, because type parameter in Memfile_LeaseMgr::getLease6
 /// @todo: Disabled, because type parameter in Memfile_LeaseMgr::getLease6
 /// (Lease::Type, const isc::asiolink::IOAddress& addr) const is not used.
 /// (Lease::Type, const isc::asiolink::IOAddress& addr) const is not used.
-TEST_F(MemfileLeaseMgrTest, DISABLED_lease6LeaseTypeCheck) {
+TEST_F(MemfileLeaseMgrTest, lease6LeaseTypeCheck) {
     startBackend(V6);
     startBackend(V6);
     testLease6LeaseTypeCheck();
     testLease6LeaseTypeCheck();
 }
 }