]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2585] Checkpoint: tests to add
authorFrancis Dupont <fdupont@isc.org>
Fri, 14 Oct 2022 00:27:32 +0000 (02:27 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 18 Oct 2022 17:28:45 +0000 (19:28 +0200)
16 files changed:
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/lib/dhcpsrv/cfg_db_access.cc
src/lib/dhcpsrv/cfg_db_access.h
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/lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc

index b068d3863e51514c5584ff73094c8ca8bf442d6d..afabc41851943467440db22eab57a43428224d79 100644 (file)
@@ -918,6 +918,9 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
 
         CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
         cfg_db->setAppendedParameters("universe=4");
+        if (cfg_db->getExtendedInfoEnabled()) {
+            cfg_db->setAppendedParameters("extended-info-tables=true");
+        }
         cfg_db->createManagers();
         // Reset counters related to connections as all managers have been recreated.
         srv->getNetworkState()->reset(NetworkState::Origin::DB_CONNECTION);
index 48e63333f78683bbcd90de8b305844613e02d624..0f8819ec33d8eb46a5c56f9bb8ed57f0f64df195 100644 (file)
@@ -922,6 +922,9 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
 
         CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
         cfg_db->setAppendedParameters("universe=6");
+        if (cfg_db->getExtendedInfoEnabled()) {
+            cfg_db->setAppendedParameters("extended-info-tables=true");
+        }
         cfg_db->createManagers();
         // Reset counters related to connections as all managers have been recreated.
         srv->getNetworkState()->reset(NetworkState::Origin::DB_CONNECTION);
index dd843a97c455df572a2f653765cdff15e1f5b010..0e1deacb3ffb7e637d5caeb66ad4174b2207ea98 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2022 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -23,7 +23,8 @@ namespace dhcp {
 
 CfgDbAccess::CfgDbAccess()
     : appended_parameters_(), lease_db_access_("type=memfile"),
-      host_db_access_(), ip_reservations_unique_(true) {
+      host_db_access_(), ip_reservations_unique_(true),
+      extended_info_enabled_(false) {
 }
 
 std::string
index 6d7bf01629c839177f0a094ad81bc02bfcf915f4..e04a851f3316ad639d8ca1546c05d4a44e3ab46f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2022 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -100,6 +100,23 @@ public:
         return (ip_reservations_unique_);
     }
 
+    /// @brief Modifies the setting whether the lease extended info tables
+    /// are enabled.
+    ///
+    /// @param enabled new setting to be used by @c LeaseMgr.
+    void setExtendedInfoEnabled(const bool enabled) {
+        extended_info_enabled_ = enabled;
+    }
+
+    /// @brief Returns the setting indicating if lease extended info tables
+    /// are enabled.
+    ///
+    /// @return true if lease extended info tables are enabled or false
+    /// if they are disabled.
+    bool getExtendedInfoEnabled() const {
+        return (extended_info_enabled_);
+    }
+
     /// @brief Creates instance of lease manager and host data sources
     /// according to the configuration specified.
     void createManagers() const;
@@ -124,6 +141,10 @@ protected:
     /// @brief Holds the setting whether IP reservations should be unique
     /// or can be non-unique.
     bool ip_reservations_unique_;
+
+    /// @brief Holds the setting whether the lease extended info tables
+    /// are enabled or disabled. The default is disabled.
+    bool extended_info_enabled_;
 };
 
 /// @brief A pointer to the @c CfgDbAccess.
index 79932603f638ed462e8d23fe226ccc509e6239c7..4b314ae2ea6869deaaebe554015d50e30802204b 100644 (file)
@@ -224,7 +224,7 @@ class LeaseMgr {
 public:
     /// @brief Constructor
     ///
-    LeaseMgr()
+    LeaseMgr() : extended_info_enabled_(false)
     {}
 
     /// @brief Destructor
@@ -924,6 +924,56 @@ public:
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) = 0;
 
+    /// @brief Delete lease6 extended info from tables.
+    ///
+    /// @param addr The address of the lease.
+    virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) = 0;
+
+    /// @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<uint8_t>& 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<uint8_t>& 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;
+
+    /// @brief Modifies the setting whether the lease extended info tables
+    /// are enabled.
+    ///
+    /// @note This method is virtual so backend doing specific action
+    /// on value changes can intercept it by redefining it.
+    ///
+    /// @param enabled new setting.
+    virtual void setExtendedInfoEnabled(const bool enabled) {
+        extended_info_enabled_ = enabled;
+    }
+
+    /// @brief Returns the setting indicating if lease extended info tables
+    /// are enabled.
+    ///
+    /// @return true if lease extended info tables are enabled or false
+    /// if they are disabled.
+    bool getExtendedInfoEnabled() const {
+        return (extended_info_enabled_);
+    }
+
     /// @brief Write V4 leases to a file.
     ///
     /// @param filename File name to write leases.
@@ -937,6 +987,10 @@ public:
 private:
     /// The IOService object, used for all ASIO operations.
     static isc::asiolink::IOServicePtr io_service_;
+
+    /// @brief Holds the setting whether the lease extended info tables
+    /// are enabled or disabled. The default is disabled.
+    bool extended_info_enabled_;
 };
 
 }  // namespace dhcp
index 6cb209445d6b6edc4bc8067081b00080364085de..7215c237ee70e60ec5cce52b7d03700da93ae246 100644 (file)
@@ -638,6 +638,19 @@ Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& param
     : LeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new std::mutex) {
     bool conversion_needed = false;
 
+    // Check if the extended info tables are enabled.
+    bool extended_info_enabled = false;
+    std::string extended_info_tables;
+    try {
+        extended_info_tables = conn_.getParameter("extended-info-tables");
+    } catch (const Exception&) {
+        extended_info_tables = "false";
+    }
+    // If extended_info_tables is 'true' we will enable them.
+    if (extended_info_tables == "true") {
+        setExtendedInfoEnabled(true);
+    }
+
     // Check the universe and use v4 file or v6 file.
     std::string universe = conn_.getParameter("universe");
     if (universe == "4") {
@@ -1831,13 +1844,19 @@ Memfile_LeaseMgr::loadLeasesFromFiles(const std::string& filename,
         // Ignore and default to 0.
     }
 
-    uint32_t max_row_errors = 0;
+    int64_t max_row_errors64;
     try {
-        max_row_errors = boost::lexical_cast<uint32_t>(max_row_errors_str);
+        max_row_errors64 = boost::lexical_cast<int64_t>(max_row_errors_str);
     } catch (const boost::bad_lexical_cast&) {
         isc_throw(isc::BadValue, "invalid value of the max-row-errors "
                   << max_row_errors_str << " specified");
     }
+    if ((max_row_errors64 < 0) ||
+        (max_row_errors64 > std::numeric_limits<uint32_t>::max())) {
+        isc_throw(isc::BadValue, "invalid value of the max-row-errors "
+                  << max_row_errors_str << " specified");
+    }
+    uint32_t max_row_errors = static_cast<uint32_t>(max_row_errors64);
 
     // Load the leasefile.completed, if exists.
     bool conversion_needed = false;
@@ -2406,26 +2425,186 @@ Memfile_LeaseMgr::getLeases4ByRemoteId(const OptionBuffer& /* remote_id */,
 }
 
 Lease6Collection
-Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& /* relay_id */,
-                                      const IOAddress& /* link_addr */,
-                                      const IOAddress& /* lower_bound_address */,
-                                      const LeasePageSize& /* page_size */) {
-    isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases6ByRelayId not implemented");
+Memfile_LeaseMgr::getLeases6ByRelayId(const DUID& relay_id,
+                                      const IOAddress& link_addr,
+                                      const IOAddress& lower_bound_address,
+                                      const LeasePageSize& page_size) {
+    const std::vector<uint8_t>& relay_id_data = relay_id.getDuid();
+    Lease6Collection collection;
+    if (link_addr.isV6Zero()) {
+        const RelayIdIndex& idx = relay_id6_.get<RelayIdIndexTag>();
+        RelayIdIndex::const_iterator lb =
+            idx.lower_bound(boost::make_tuple(relay_id_data,
+                                              lower_bound_address));
+
+        // 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) {
+                // Already seen: skip it.
+                continue;
+            }
+            last_addr = (*lb)->lease_addr_;
+            Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr);
+            if (lease) {
+                collection.push_back(lease);
+                if (collection.size() >= page_size.page_size_) {
+                    break;
+                }
+            }
+        }
+    } else {
+        const RelayIdLinkAddressIndex& idx =
+            relay_id6_.get<RelayIdLinkAddressIndexTag>();
+        RelayIdLinkAddressIndex::const_iterator lb =
+            idx.lower_bound(boost::make_tuple(relay_id_data,
+                                              link_addr,
+                                              lower_bound_address));
+
+        // 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) {
+                // Already seen: skip it.
+                continue;
+            }
+            last_addr = (*lb)->lease_addr_;
+            Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr);
+            if (lease) {
+                collection.push_back(lease);
+                if (collection.size() >= page_size.page_size_) {
+                    break;
+                }
+            }
+        }
+    }
+    return (collection);
 }
 
 Lease6Collection
-Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& /* remote_id */,
-                                       const IOAddress& /* link_addr */,
-                                       const IOAddress& /* lower_bound_address */,
-                                       const LeasePageSize& /* page_size*/) {
-    isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases6ByRemoteId not implemented");
+Memfile_LeaseMgr::getLeases6ByRemoteId(const OptionBuffer& remote_id,
+                                       const IOAddress& link_addr,
+                                       const IOAddress& lower_bound_address,
+                                       const LeasePageSize& page_size) {
+    Lease6Collection collection;
+    std::set<IOAddress> sorted;
+    if (link_addr.isV6Zero()) {
+        const RemoteIdIndex& idx = remote_id6_.get<RemoteIdIndexTag>();
+        RemoteIdIndexRange er = idx.equal_range(remote_id);
+
+        // Store all addresses greater than lower_bound_address.
+        for (auto it = er.first; it != er.second; ++it) {
+            const IOAddress& addr = (*it)->lease_addr_;
+            if (addr <= lower_bound_address) {
+                continue;
+            }
+            static_cast<void>(sorted.insert(addr));
+        }
+
+        // Return all leases being within the page size.
+        for (const IOAddress& addr : sorted) {
+            Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, addr);
+            if (lease) {
+                collection.push_back(lease);
+                if (collection.size() >= page_size.page_size_) {
+                    break;
+                }
+            }
+        }
+    } else {
+        const RemoteIdLinkAddressIndex& idx =
+            remote_id6_.get<RemoteIdLinkAddressIndexTag>();
+        RemoteIdLinkAddressRange er =
+            idx.equal_range(boost::make_tuple(remote_id, link_addr));
+
+        // Store all addresses greater than lower_bound_address.
+        for (auto it = er.first; it != er.second; ++it) {
+            const IOAddress& addr = (*it)->lease_addr_;
+            if (addr <= lower_bound_address) {
+                continue;
+            }
+            static_cast<void>(sorted.insert(addr));
+        }
+
+        // Return all leases being within the page size.
+        for (const IOAddress& addr : sorted) {
+            Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, addr);
+            if (lease) {
+                collection.push_back(lease);
+                if (collection.size() >= page_size.page_size_) {
+                    break;
+                }
+            }
+        }
+    }
+    return (collection);
 }
 
 Lease6Collection
-Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */,
-                                   const IOAddress& /* lower_bound_address */,
-                                   const LeasePageSize& /* page_size */) {
-    isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases6ByLink not implemented");
+Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& link_addr,
+                                   const IOAddress& lower_bound_address,
+                                   const LeasePageSize& page_size) {
+    Lease6Collection collection;
+    const LinkAddressIndex& idx = link_addr6_.get<LinkAddressIndexTag>();
+    LinkAddressIndex::const_iterator lb =
+        idx.lower_bound(boost::make_tuple(link_addr, lower_bound_address));
+
+    // 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) {
+            // Already seen: skip it.
+            continue;
+        }
+        last_addr = (*lb)->lease_addr_;
+        Lease6Ptr lease = getLease6Internal(Lease::TYPE_NA, last_addr);
+        if (lease) {
+            collection.push_back(lease);
+            if (collection.size() >= page_size.page_size_) {
+                break;
+            }
+        }
+    }
+    return (collection);
+}
+
+void
+Memfile_LeaseMgr::deleteExtendedInfo6(const IOAddress& addr) {
+    LeaseAddressRelayIdIndex& relay_id_idx =
+        relay_id6_.get<LeaseAddressIndexTag>();
+    static_cast<void>(relay_id_idx.erase(addr));
+    LeaseAddressRemoteIdIndex& remote_id_idx =
+        remote_id6_.get<LeaseAddressIndexTag>();
+    static_cast<void>(remote_id_idx.erase(addr));
+    LeaseAddressLinkAddressIndex& link_addr_idx =
+        link_addr6_.get<LeaseAddressIndexTag>();
+    static_cast<void>(link_addr_idx.erase(addr));
+}
+
+void
+Memfile_LeaseMgr::addRelayId6(const IOAddress& lease_addr,
+                              const IOAddress& link_addr,
+                              const std::vector<uint8_t>& relay_id) {
+    Lease6ExtendedInfoPtr ex_info;
+    ex_info.reset(new Lease6ExtendedInfo(lease_addr, link_addr, relay_id));
+    relay_id6_.insert(ex_info);
+}
+
+void
+Memfile_LeaseMgr::addRemoteId6(const IOAddress& lease_addr,
+                               const IOAddress& link_addr,
+                               const std::vector<uint8_t>& remote_id) {
+    Lease6ExtendedInfoPtr ex_info;
+    ex_info.reset(new Lease6ExtendedInfo(lease_addr, link_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
index 6d119c707656e9fad661fba3b333e75d16418593..16d098c9745c8a2e82ccbb4bf1b2c2bb15d0610a 100644 (file)
@@ -1066,6 +1066,15 @@ private:
     /// @brief stores IPv6 leases
     Lease6Storage storage6_;
 
+    /// @brief stores IPv6 by-relay-id cross-reference table
+    Lease6ExtendedInfoRelayIdTable relay_id6_;
+
+    /// @brief stores IPv6 by-remote-id cross-reference table
+    Lease6ExtendedInfoRemoteIdTable remote_id6_;
+
+    /// @brief stores IPv6 by-link-addr cross-reference table
+    Lease6SimpleExtendedInfoLinkAddrTable link_addr6_;
+
 protected:
     /// @brief Holds the pointer to the DHCPv4 lease file IO.
     boost::shared_ptr<CSVLeaseFile4> lease_file4_;
@@ -1358,6 +1367,36 @@ public:
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) override;
 
+    /// @brief Delete lease6 extended info from tables.
+    ///
+    /// @param addr The address of the lease.
+    virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override;
+
+    /// @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<uint8_t>& 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<uint8_t>& 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;
+
     /// @brief Write V4 leases to a file.
     ///
     /// @param filename File name to write leases.
index 33380b0a6dc60e8d0053f648ecc04b32400d5176..f4544c317baef4127057ff1dd32d60790bc39ac2 100644 (file)
@@ -19,6 +19,7 @@
 #include <boost/multi_index_container.hpp>
 #include <boost/multi_index/composite_key.hpp>
 
+#include <functional>
 #include <vector>
 
 namespace isc {
@@ -330,9 +331,10 @@ 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.
-/// - using relay id.
-/// - using lease address.
+/// - 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.
 ///
 /// The choice of binary trees was governed by the fact a large number of
 /// clients can be behind a relay.
@@ -344,7 +346,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 and link address.
+        // First index is by relay id, link and lease addresses.
         boost::multi_index::ordered_non_unique<
             boost::multi_index::tag<RelayIdLinkAddressIndexTag>,
             boost::multi_index::composite_key<
@@ -354,16 +356,25 @@ typedef boost::multi_index_container<
                                            &Lease6ExtendedInfo::id_>,
                 boost::multi_index::member<Lease6ExtendedInfo,
                                            isc::asiolink::IOAddress,
-                                           &Lease6ExtendedInfo::link_addr_>
+                                           &Lease6ExtendedInfo::link_addr_>,
+                boost::multi_index::member<Lease6ExtendedInfo,
+                                           isc::asiolink::IOAddress,
+                                           &Lease6ExtendedInfo::lease_addr_>
             >
         >,
 
-        // Second index is by relay id.
+        // Second index is by relay id and lease address.
         boost::multi_index::ordered_non_unique<
             boost::multi_index::tag<RelayIdIndexTag>,
-            boost::multi_index::member<Lease6ExtendedInfo,
-                                       std::vector<uint8_t>,
-                                       &Lease6ExtendedInfo::id_>
+            boost::multi_index::composite_key<
+                Lease6ExtendedInfo,
+                boost::multi_index::member<Lease6ExtendedInfo,
+                                           std::vector<uint8_t>,
+                                           &Lease6ExtendedInfo::id_>,
+                boost::multi_index::member<Lease6ExtendedInfo,
+                                           isc::asiolink::IOAddress,
+                                           &Lease6ExtendedInfo::lease_addr_>
+            >
         >,
 
         // Last index is by lease address.
@@ -381,7 +392,7 @@ typedef boost::multi_index_container<
 /// 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.
+/// - using lease address for deletes.
 ///
 /// The internal layout of remote id is not used. The choice of hash tables
 /// was governed by the fact a small number of clients should share the same
@@ -426,6 +437,39 @@ typedef boost::multi_index_container<
     >
 > Lease6ExtendedInfoRemoteIdTable;
 
+/// @brief Lease6 extended information by relay id and link address index.
+typedef Lease6ExtendedInfoRelayIdTable::index<RelayIdLinkAddressIndexTag>::type
+    RelayIdLinkAddressIndex;
+
+/// @brief Lease6 extended information by relay id index.
+typedef Lease6ExtendedInfoRelayIdTable::index<RelayIdIndexTag>::type
+    RelayIdIndex;
+
+/// @brief Lease6 extended information by lease address index of by relay id table.
+typedef Lease6ExtendedInfoRelayIdTable::index<LeaseAddressIndexTag>::type
+    LeaseAddressRelayIdIndex;
+
+/// @brief Lease6 extended information by remote id and link address index.
+typedef Lease6ExtendedInfoRemoteIdTable::index<RemoteIdLinkAddressIndexTag>::type
+    RemoteIdLinkAddressIndex;
+
+/// @brief Lease6 extended information by remote id index.
+typedef Lease6ExtendedInfoRemoteIdTable::index<RemoteIdIndexTag>::type
+    RemoteIdIndex;
+
+/// @brief Lease6 extended information by remote id and link address range.
+typedef std::pair<RemoteIdLinkAddressIndex::const_iterator,
+                  RemoteIdLinkAddressIndex::const_iterator>
+    RemoteIdLinkAddressRange;
+
+/// @brief Lease6 extended information by remote id range.
+typedef std::pair<RemoteIdIndex::const_iterator, RemoteIdIndex::const_iterator>
+    RemoteIdIndexRange;
+
+/// @brief Lease6 extended information by lease address index of by remote id table.
+typedef Lease6ExtendedInfoRemoteIdTable::index<LeaseAddressIndexTag>::type
+    LeaseAddressRemoteIdIndex;
+
 /// @brief Lease6 extended informations for Bulk Lease Query,
 /// simpler version (2 fields vs 3) for by link address table.
 class Lease6SimpleExtendedInfo {
@@ -456,8 +500,9 @@ struct LinkAddressIndexTag { };
 /// for by link address.
 ///
 /// The lease6 extended info may be accessed using different indexes:
-/// - using a composite index: link and lease addresses.
-/// - using lease address.
+/// - 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.
@@ -493,6 +538,14 @@ typedef boost::multi_index_container<
     >
 > Lease6SimpleExtendedInfoLinkAddrTable;
 
+/// @brief Lease6 extended information by link address.
+typedef Lease6SimpleExtendedInfoLinkAddrTable::index<LinkAddressIndexTag>::type
+    LinkAddressIndex;
+
+/// @brief Lease6 extended information by lease address index of by link address table.
+typedef Lease6SimpleExtendedInfoLinkAddrTable::index<LeaseAddressIndexTag>::type
+    LeaseAddressLinkAddressIndex;
+
 //@}
 
 } // end of isc::dhcp namespace
index 70438a7afc95ac05529c3704c900e55dc44b4dae..7377017c614893a3c910c3034a0e7f78f1732c98 100644 (file)
@@ -1799,6 +1799,18 @@ MySqlLeaseMgr::MySqlLeaseContextAlloc::~MySqlLeaseContextAlloc() {
 MySqlLeaseMgr::MySqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
     : parameters_(parameters), timer_name_("") {
 
+    // Check if the extended info tables are enabled.
+    std::string extended_info_tables;
+    try {
+        extended_info_tables = parameters_.at("extended-info-tables");
+    } catch (const exception&) {
+        extended_info_tables = "false";
+    }
+    // If extended_info_tables is 'true' we will enable them.
+    if (extended_info_tables == "true") {
+        setExtendedInfoEnabled(true);
+    }
+
     // Create unique timer name per instance.
     timer_name_ = "MySqlLeaseMgr[";
     timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
@@ -3362,6 +3374,31 @@ MySqlLeaseMgr::checkError(MySqlLeaseContextPtr& ctx,
     ctx->conn_.checkError(status, index, what);
 }
 
+void
+MySqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) {
+    isc_throw(NotImplemented, "MySqlLeaseMgr::deleteExtendedInfo6 not implemented");
+}
+
+void
+MySqlLeaseMgr::addRelayId6(const IOAddress& /* lease_addr */,
+                           const IOAddress& /* link_addr */,
+                           const vector<uint8_t>& relay_id) {
+    isc_throw(NotImplemented, "MySqlLeaseMgr::addRelayId6 not implemented");
+}
+
+void
+MySqlLeaseMgr::addRemoteId6(const IOAddress& /* lease_addr */,
+                            const IOAddress& /* link_addr */,
+                            const vector<uint8_t>& 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 */,
index 15e08286d023c51c13b29f1df398966cf8441455..ff62eadab52e897d3516fd5fe3b737abd1901694 100644 (file)
@@ -1103,6 +1103,48 @@ private:
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) override;
 
+    /// @brief Delete lease6 extended info from tables.
+    ///
+    /// @param addr The address of the lease.
+    virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override;
+
+    /// @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<uint8_t>& 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<uint8_t>& 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;
+
+    /// @brief Modifies the setting whether the lease extended info tables
+    /// are enabled.
+    ///
+    /// Transient redefine to refuse the enable setting.
+    /// @param enabled new setting.
+    virtual void setExtendedInfoEnabled(const bool enabled) override {
+        if (enabled) {
+            isc_throw(isc::NotImplemented,
+                      "extended info tables are not yet supported by mysql");
+        }
+    }
+
     /// @brief Context RAII Allocator.
     class MySqlLeaseContextAlloc {
     public:
index 611fcbcc6ecdb3b7709958c32a69ec2ddf7eb8f2..b324b86ae6f1dfeb1c228ca7bcacbe8f51b07668 100644 (file)
@@ -1255,6 +1255,18 @@ PgSqlLeaseMgr::PgSqlLeaseContextAlloc::~PgSqlLeaseContextAlloc() {
 PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
     : parameters_(parameters), timer_name_("") {
 
+    // Check if the extended info tables are enabled.
+    std::string extended_info_tables;
+    try {
+        extended_info_tables = parameters_.at("extended-info-tables");
+    } catch (const exception&) {
+        extended_info_tables = "false";
+    }
+    // If extended_info_tables is 'true' we will enable them.
+    if (extended_info_tables == "true") {
+        setExtendedInfoEnabled(true);
+    }
+
     // Create unique timer name per instance.
     timer_name_ = "PgSqlLeaseMgr[";
     timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
@@ -2556,6 +2568,31 @@ PgSqlLeaseMgr::rollback() {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_ROLLBACK);
 }
 
+void
+PgSqlLeaseMgr::deleteExtendedInfo6(const IOAddress& /* addr */) {
+    isc_throw(NotImplemented, "PgSqlLeaseMgr::deleteExtendedInfo6 not implemented");
+}
+
+void
+PgSqlLeaseMgr::addRelayId6(const IOAddress& /* lease_addr */,
+                           const IOAddress& /* link_addr */,
+                           const vector<uint8_t>& relay_id) {
+    isc_throw(NotImplemented, "PgSqlLeaseMgr::addRelayId6 not implemented");
+}
+
+void
+PgSqlLeaseMgr::addRemoteId6(const IOAddress& /* lease_addr */,
+                            const IOAddress& /* link_addr */,
+                            const vector<uint8_t>& 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 */,
index 999c58d7bdafd3d3fb8b1fd490ec4edf590d09a6..afb0082f3444526ec86a2eebf4a408bd768515a0 100644 (file)
@@ -1056,12 +1056,54 @@ private:
                      const asiolink::IOAddress& lower_bound_address,
                      const LeasePageSize& page_size) override;
 
+    /// @brief Delete lease6 extended info from tables.
+    ///
+    /// @param addr The address of the lease.
+    virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress& addr) override;
+
+    /// @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<uint8_t>& 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<uint8_t>& 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;
+
     /// @brief Write V4 leases to a file.
     virtual void writeLeases4(const std::string& /*filename*/) override;
 
     /// @brief Write V6 leases to a file.
     virtual void writeLeases6(const std::string& /*filename*/) override;
 
+    /// @brief Modifies the setting whether the lease extended info tables
+    /// are enabled.
+    ///
+    /// Transient redefine to refuse the enable setting.
+    /// @param enabled new setting.
+    virtual void setExtendedInfoEnabled(const bool enabled) override {
+        if (enabled) {
+            isc_throw(isc::NotImplemented,
+                      "extended info tables are not yet supported by postgresql");
+        }
+    }
+
     /// @brief Context RAII Allocator.
     class PgSqlLeaseContextAlloc {
     public:
index 328d78915fdee407de502088abe95b4bc9cea708..8414ca5aca86da89979d190574e12b41528ff274 100644 (file)
@@ -397,6 +397,35 @@ public:
         isc_throw(NotImplemented, "ConcreteLeaseMgr::clearClassLeaseCounts() not implemented");
     }
 
+    /// @brief Stub implementation.
+    void
+    deleteExtendedInfo6(const IOAddress& /* addr */) override {
+        isc_throw(NotImplemented, "ConcreteLeaseMgr::deleteExtendedInfo6 not implemented");
+    }
+
+    /// @brief Stub implementation.
+    void
+    addRelayId6(const IOAddress& /* lease_addr */,
+                const IOAddress& /* link_addr */,
+                const vector<uint8_t>& relay_id) override {
+        isc_throw(NotImplemented, "ConcreteLeaseMgr::addRelayId6 not implemented");
+    }
+
+    /// @brief Stub implementation.
+    void
+    addRemoteId6(const IOAddress& /* lease_addr */,
+                 const IOAddress& /* link_addr */,
+                 const vector<uint8_t>& 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 */,
index 0c923a66028dbf6683c8473b1fa8651d70af3fc6..102896b1dab95684d515d2a56b093542928ca265 100644 (file)
@@ -400,16 +400,19 @@ TEST_F(MemfileLeaseMgrTest, constructor) {
 
     EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
 
-    pmap["lfc-interval"] = "10";
-    pmap["persist"] = "true";
-    pmap["name"] = getLeaseFilePath("leasefile4_1.csv");
-    pmap["max-row-errors"] = "5";
+    // Check the extended info enable flag.
+    EXPECT_FALSE(lease_mgr->getExtendedInfoEnabled());
+    pmap["extended-info-tables"] = "true";
     EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
+    EXPECT_TRUE(lease_mgr->getExtendedInfoEnabled());
 
     // Expecting that persist parameter is yes or no. Everything other than
     // that is wrong.
-    pmap["persist"] = "bogus";
+    pmap["lfc-interval"] = "10";
+    pmap["name"] = getLeaseFilePath("leasefile4_1.csv");
+    pmap["max-row-errors"] = "5";
     pmap["name"] = getLeaseFilePath("leasefile4_1.csv");
+    pmap["persist"] = "bogus";
     EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
 
     // The lfc-interval must be an integer.
@@ -418,14 +421,17 @@ TEST_F(MemfileLeaseMgrTest, constructor) {
     EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
 
     // The max-row-errors must be an integer.
-    pmap["persist"] = "true";
+    pmap["lfc-interval"] = "10";
     pmap["max-row-errors"] = "bogus";
     EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
 
     // The max-row-errors must be >= 0.
-    pmap["persist"] = "true";
     pmap["max-row-errors"] = "-1";
     EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
+
+    // Moved to the end as it can leave the timer registered.
+    pmap["max-row-errors"] = "5";
+    EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
 }
 
 /// @brief Checks if there is no lease manager NoLeaseManager is thrown.
index 0b4f839abf47ff4cfa3f9428a904d9052b3f1592..66473b2331e1013f171f99ce001b619acc1b3e9d 100644 (file)
@@ -126,6 +126,8 @@ TEST(MySqlOpenTest, OpenDatabase) {
     try {
         LeaseMgrFactory::create(validMySQLConnectionString());
         EXPECT_NO_THROW((void)LeaseMgrFactory::instance());
+        EXPECT_THROW(LeaseMgrFactory::instance().setExtendedInfoEnabled(true),
+                     NotImplemented);
         LeaseMgrFactory::destroy();
     } catch (const isc::Exception& ex) {
         FAIL() << "*** ERROR: unable to open database, reason:\n"
index 84d8d204163fb296e628faa368389b44bda55c14..8233cd0b5d93a672c652160bede3bf2c360ff4d5 100644 (file)
@@ -126,6 +126,8 @@ TEST(PgSqlOpenTest, OpenDatabase) {
     try {
         LeaseMgrFactory::create(validPgSQLConnectionString());
         EXPECT_NO_THROW((void)LeaseMgrFactory::instance());
+        EXPECT_THROW(LeaseMgrFactory::instance().setExtendedInfoEnabled(true),
+                     NotImplemented);
         LeaseMgrFactory::destroy();
     } catch (const isc::Exception& ex) {
         FAIL() << "*** ERROR: unable to open database, reason:\n"