]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
Merge remote-tracking branch 'isc-kea/master' into cassandra_improvements
authorRazvan Becheriu <razvan.becheriu@qualitance.com>
Wed, 28 Feb 2018 08:29:23 +0000 (10:29 +0200)
committerRazvan Becheriu <razvan.becheriu@qualitance.com>
Wed, 28 Feb 2018 08:29:23 +0000 (10:29 +0200)
1  2 
configure.ac
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/cql_host_data_source.h
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc

diff --cc configure.ac
Simple merge
index 8e501a365e165e72b4c177016231a79d29ce41f3,e9073848b1b9f02847b0623ac5820911d07cc307..6fab69ab020b860e7f8b9771a9f6cf3330e53d28
@@@ -753,20 -592,11 +745,19 @@@ StatementMap CqlHostExchange::tagged_st
        "ALLOW FILTERING "
       }},
  
 +    {DELETE_HOST,
 +     {DELETE_HOST,
 +      "DELETE FROM host_reservations WHERE id = ? "
 +      "IF EXISTS "
 +     }}
  };
  
- CqlHostExchange::CqlHostExchange(CqlConnection& connection)
-     : host_(NULL), connection_(connection), id_(0), host_identifier_type_(0),
-       host_ipv4_subnet_id_(0), host_ipv6_subnet_id_(0), host_ipv4_address_(0),
-       host_ipv4_next_server_(0),
+ CqlHostExchange::CqlHostExchange()
+     : host_(NULL), id_(0), host_identifier_type_(0), host_ipv4_subnet_id_(0),
 -      host_ipv6_subnet_id_(0), host_ipv4_address_(0),
++      host_ipv6_subnet_id_(0), host_ipv4_address_(0), host_ipv4_next_server_(0),
 +      host_ipv4_server_hostname_(NULL_DHCP4_SERVER_HOSTNAME),
 +      host_ipv4_boot_file_name_(NULL_DHCP4_BOOT_FILE_NAME),
 +      user_context_(NULL_USER_CONTEXT),
        reserved_ipv6_prefix_length_(NULL_RESERVED_IPV6_PREFIX_LENGTH),
        reserved_ipv6_prefix_address_type_(NULL_RESERVED_IPV6_PREFIX_ADDRESS_TYPE),
        iaid_(NULL_IAID), option_universe_(NULL_OPTION_UNIVERSE),
@@@ -1090,84 -855,25 +1081,63 @@@ CqlHostExchange::createBindForMutation(
      }
  }
  
- uint64_t
- md5Hash(const std::string& input) {
-     /// @todo: Convert this code to cryptolink calls and replace the
-     /// direct use fromn md5.
-     // Prepare structures for MD5().
-     const size_t word_size = MD5_DIGEST_LENGTH / sizeof(uint64_t);
-     uint64_t hash[word_size];
-     unsigned char* digest = reinterpret_cast<unsigned char*>(hash);
-     unsigned char* string = reinterpret_cast<unsigned char*>(const_cast<char*>(input.c_str()));
-     std::fill(hash, hash + word_size, 0);
-     // Get MD5 hash value.
-     MD5(string, input.size(), digest);
-     // Return the first part of the hash value which still retains all
-     // properties of the full hash value.
-     return (hash[0]);
- }
 +void
 +CqlHostExchange::createBindForDelete(const HostPtr& host,
 +                                     const OptionalValue<SubnetID>& subnet_id,
 +                                     const IPv6Resrv* const reservation,
 +                                     const std::string& option_space,
 +                                     const OptionDescriptor& option_descriptor,
 +                                     StatementTag statement_tag, AnyArray& data) {
 +    prepareExchange(host, subnet_id, reservation, option_space, option_descriptor);
 +
 +    try {
 +        // Add all parameters to bind array.
 +        data.clear();
 +
 +        if (statement_tag == CqlHostExchange::DELETE_HOST) {
 +            data.add(&id_);
 +        }
 +
 +    } catch (const Exception& ex) {
 +        isc_throw(DbOperationError,
 +                  "CqlHostExchange::createBindForDelete(): "
 +                  "could not create bind array from host "
 +                  << host->getHostname() << ", reason: " << ex.what());
 +    }
 +}
 +
  cass_int64_t
  CqlHostExchange::hashIntoId() const {
-     // Allocates a fixed maximum length in the stringstream for each
-     // aggregated field to avoid collisions between distinct entries.
+     // Add a separator between aggregated field to avoid collisions
+     // between distinct entries.
  
      // Get key.
      std::stringstream key_stream;
 -    key_stream << host_ipv4_subnet_id_ << "-";
 -    key_stream << host_ipv6_subnet_id_ << "-";
 -    key_stream << host_ipv4_address_ << "-";
 -    key_stream << reserved_ipv6_prefix_address_ << "/";
 -    key_stream << reserved_ipv6_prefix_length_ << "-";
 -    key_stream << option_code_ << "-";
 -    key_stream << option_space_;
 +    if (host_ipv4_address_) {
 +        key_stream << std::setw(3 * DUID::MAX_DUID_LEN - 1) << std::setfill('-')
 +                   << "-";
 +        key_stream << std::setw(10) << std::setfill('-') << "-";
 +    } else {
 +        key_stream << std::setw(3 * DUID::MAX_DUID_LEN - 1) << std::setfill('-')
 +                   << DUID(host_identifier_).toText();
 +        key_stream << std::setw(10) << std::setfill('-') << host_identifier_type_;
 +    }
 +    key_stream << std::setw(10) << std::setfill('-') << host_ipv4_subnet_id_;
 +    key_stream << std::setw(10) << std::setfill('-') << host_ipv6_subnet_id_;
 +    key_stream << std::setw(V4ADDRESS_TEXT_MAX_LEN) << std::setfill('-')
 +               << host_ipv4_address_;
 +    key_stream << std::setw(V6ADDRESS_TEXT_MAX_LEN) << std::setfill('-')
 +               << reserved_ipv6_prefix_address_;
 +    key_stream << std::setw(4) << std::setfill('-')
 +               << reserved_ipv6_prefix_length_;
 +    key_stream << std::setw(4) << std::setfill('-') << option_code_;
 +    key_stream << std::setw(OPTION_SPACE_MAX_LENGTH) << std::setfill('-')
 +               << option_space_;
      const std::string key = key_stream.str();
  
-     const cass_int64_t md5 = static_cast<cass_int64_t>(md5Hash(key));
+     const cass_int64_t hash = static_cast<cass_int64_t>(Hash64::hash(key));
  
-     return (md5);
+     return (hash);
  }
  
  boost::any
@@@ -2104,42 -1728,27 +2069,42 @@@ CqlHostDataSourceImpl::getHostCollectio
      return (result_collection);
  }
  
 -void
 -CqlHostDataSourceImpl::insertHost(const HostPtr& host,
 -                                  const OptionalValue<SubnetID>& subnet_id,
 -                                  const IPv6Resrv* const reservation,
 -                                  const std::string& option_space,
 -                                  const OptionDescriptor& option_descriptor) {
 +bool
 +CqlHostDataSourceImpl::insertOrDeleteHost(bool insert,
 +                                          const HostPtr& host,
 +                                          const OptionalValue<SubnetID>& subnet_id,
 +                                          const IPv6Resrv* const reservation,
 +                                          const std::string& option_space,
 +                                          const OptionDescriptor& option_descriptor) {
      AnyArray assigned_values;
  
-     std::unique_ptr<CqlHostExchange> host_exchange(new CqlHostExchange(dbconn_));
+     std::unique_ptr<CqlHostExchange> host_exchange(new CqlHostExchange());
  
      try {
 -        host_exchange->createBindForMutation(
 -            host, subnet_id, reservation, option_space, option_descriptor,
 -            CqlHostExchange::INSERT_HOST, assigned_values);
 +        if (insert) {
 +            host_exchange->createBindForMutation(
 +                host, subnet_id, reservation, option_space, option_descriptor,
 +                CqlHostExchange::INSERT_HOST, assigned_values);
  
  
 -        host_exchange->executeMutation(dbconn_, assigned_values,
 -                                       CqlHostExchange::INSERT_HOST);
 +            host_exchange->executeMutation(dbconn_, assigned_values, CqlHostExchange::INSERT_HOST);
 +        } else {
 +            host_exchange->createBindForDelete(
 +                host, subnet_id, reservation, option_space, option_descriptor,
 +                CqlHostExchange::DELETE_HOST, assigned_values);
 +
 +
 +            host_exchange->executeMutation(dbconn_, assigned_values, CqlHostExchange::DELETE_HOST);
 +        }
      } catch (const StatementNotApplied& exception) {
 -        isc_throw(DuplicateEntry, exception.what());
 +        if (insert) {
 +            isc_throw(DuplicateEntry, exception.what());
 +        } else {
 +            return (false);
 +        }
      }
 +
 +    return (true);
  }
  
  void
Simple merge
Simple merge
Simple merge
index 0d1a0bf036741c3480c27b00d8824d52ca4b1de5,4e559c75ccd1bfbf78b1d853247f9a8cfcdb3ccc..a38ef0b45ac00868e60338da96b4eb164f8626e4
@@@ -741,10 -720,13 +742,8 @@@ TEST_F(CqlLeaseMgrTest, deleteExpiredRe
      testDeleteExpiredReclaimedLeases6();
  }
  
- // Verifies that IPv4 lease statistics can be recalculated.
- /// @todo: uncomment this once stats recalculation is implemented
- /// for Cassandra (see #5487)
- TEST_F(CqlLeaseMgrTest, DISABLED_recountLeaseStats4) {
 -/// @brief Check that expired reclaimed DHCPv4 leases are removed.
 -TEST_F(CqlLeaseMgrTest, deleteExpiredReclaimedLeases4) {
 -    testDeleteExpiredReclaimedLeases4();
 -}
 -
+ /// @brief Verifies that IPv4 lease statistics can be recalculated.
+ TEST_F(CqlLeaseMgrTest, recountLeaseStats4) {
      testRecountLeaseStats4();
  }