]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
review comments 2
authormayya <mayya@itwm.fraunhofer.de>
Sun, 15 Jul 2018 13:32:33 +0000 (15:32 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Mon, 23 Jul 2018 11:37:01 +0000 (13:37 +0200)
review comments 2

test1

fixed unit tests

fixed cassandra

fixed cassandra2

17 files changed:
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/host.h
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc
src/lib/dhcpsrv/tests/host_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/host_data_source_utils.cc
src/lib/dhcpsrv/testutils/host_data_source_utils.h
src/share/database/scripts/cql/dhcpdb_create.cql
src/share/database/scripts/cql/upgrade_2.0_to_3.0.sh.in
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_6.0_to_7.0.sh.in
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_4.0_to_5.0.sh.in

index 9b6c93e25fb0d0853c505c6b4a920d53fef8afd3..25375f5fc7d08932b19edff8a10a12868324dd91 100644 (file)
@@ -116,7 +116,6 @@ static constexpr char NULL_USER_CONTEXT[] = "";
 static constexpr char NULL_RESERVED_IPV6_PREFIX_ADDRESS[] = "::";
 static constexpr cass_int32_t NULL_RESERVED_IPV6_PREFIX_LENGTH = 0;
 static constexpr cass_int32_t NULL_RESERVED_IPV6_PREFIX_ADDRESS_TYPE = -1;
-static constexpr char NULL_RESERVED_KEY[] = "";
 static constexpr cass_int32_t NULL_IAID = -1;
 static constexpr cass_int32_t NULL_OPTION_UNIVERSE = -1;
 static constexpr cass_int32_t NULL_OPTION_CODE = -1;
@@ -351,6 +350,9 @@ private:
     /// @brief Boot file name (file).
     std::string host_ipv4_boot_file_name_;
 
+    /// @brief Key for authentication
+    std::string auth_key_;
+
     /// @brief Name reserved for the host
     std::string hostname_;
 
@@ -373,9 +375,6 @@ private:
     /// This value corresponds to the @ref Host::IdentifierType value.
     cass_int32_t reserved_ipv6_prefix_address_type_;
 
-    /// @brief Key for authentication
-    std::string key_;
-
     /// @brief The reservation's IAID
     cass_int32_t iaid_;
 
@@ -435,6 +434,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -442,7 +442,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -477,6 +476,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -484,7 +484,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -511,6 +510,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -518,7 +518,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -548,6 +547,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -555,7 +555,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -584,6 +583,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -591,7 +591,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -622,6 +621,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -629,7 +629,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -660,6 +659,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -667,7 +667,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -697,6 +696,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -704,7 +704,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -734,6 +733,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_next_server, "
       "host_ipv4_server_hostname, "
       "host_ipv4_boot_file_name, "
+      "auth_key, "
       "hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
@@ -741,7 +741,6 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "reserved_ipv6_prefix_address, "
       "reserved_ipv6_prefix_length, "
       "reserved_ipv6_prefix_address_type, "
-      "reserved_key, "
       "iaid, "
       "option_universe, "
       "option_code, "
@@ -771,6 +770,7 @@ CqlHostExchange::CqlHostExchange()
       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),
+      auth_key_(""),
       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),
@@ -808,6 +808,8 @@ CqlHostExchange::createBindForSelect(AnyArray& data, StatementTag /* not used */
     data.add(&host_ipv4_server_hostname_);
     // host_ipv4_boot_file_name: text
     data.add(&host_ipv4_boot_file_name_);
+    // auth_key: text
+    data.add(&auth_key_);
     // hostname: text
     data.add(&hostname_);
     // user_context: text
@@ -824,8 +826,6 @@ CqlHostExchange::createBindForSelect(AnyArray& data, StatementTag /* not used */
     data.add(&reserved_ipv6_prefix_length_);
     // reserved_ipv6_prefix_address_type: int
     data.add(&reserved_ipv6_prefix_address_type_);
-    // reserved_key: text
-    data.add(&key_);
     // iaid: int
     data.add(&iaid_);
     /// @}
@@ -903,6 +903,9 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
         // host_ipv4_boot_file_name: text
         host_ipv4_boot_file_name_ = host->getBootFileName();
 
+        // auth_key: varchar
+        auth_key_ = host->getKey().ToText();
+        
         // hostname: text
         hostname_ = host->getHostname();
         if (hostname_.size() > HOSTNAME_MAX_LENGTH) {
@@ -944,8 +947,6 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
             reserved_ipv6_prefix_length_ = NULL_RESERVED_IPV6_PREFIX_LENGTH;
             // reserved_ipv6_prefix_address_type: int
             reserved_ipv6_prefix_address_type_ = NULL_RESERVED_IPV6_PREFIX_ADDRESS_TYPE;
-            // reserved_key: text
-            key_ = NULL_RESERVED_KEY;
             iaid_ = NULL_IAID;
         } else {
             // reserved_ipv6_prefix_address: text
@@ -958,9 +959,6 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
             reserved_ipv6_prefix_address_type_ =
                 reservation->getType() == IPv6Resrv::TYPE_NA ? 0 : 2;
 
-            // reserved_key: text
-            key_ = reservation->getKey().getAuthKey();
-            
             // iaid: int
             /// @todo: We don't support iaid in the IPv6Resrv yet.
             iaid_ = 0;
@@ -1070,6 +1068,7 @@ CqlHostExchange::createBindForMutation(const HostPtr& host,
             data.add(&host_ipv4_next_server_);
             data.add(&host_ipv4_server_hostname_);
             data.add(&host_ipv4_boot_file_name_);
+            data.add(&auth_key_);
             data.add(&hostname_);
             data.add(&user_context_);
             data.add(&host_ipv4_client_classes_);
@@ -1080,7 +1079,6 @@ CqlHostExchange::createBindForMutation(const HostPtr& host,
         data.add(&reserved_ipv6_prefix_address_);
         data.add(&reserved_ipv6_prefix_length_);
         data.add(&reserved_ipv6_prefix_address_type_);
-        data.add(&key_);
         data.add(&iaid_);
 
         // Option
@@ -1189,7 +1187,8 @@ CqlHostExchange::retrieve() {
                           ipv4_reservation, hostname_,
                           host_ipv4_client_classes_, host_ipv6_client_classes_,
                           static_cast<uint32_t>(host_ipv4_next_server_),
-                          host_ipv4_server_hostname_, host_ipv4_boot_file_name_);
+                          host_ipv4_server_hostname_, host_ipv4_boot_file_name_,
+                          AuthKey(auth_key_));
 
     // Set the user context if there is one.
     if (!user_context_.empty()) {
@@ -1248,7 +1247,7 @@ CqlHostExchange::retrieveReservation() const {
     }
 
     return (IPv6Resrv(type, IOAddress(reserved_ipv6_prefix_address_),
-                      reserved_ipv6_prefix_length_, key_));
+                      reserved_ipv6_prefix_length_));
 }
 
 const OptionWrapper
index a99955b15b3c623d490537053f9f6d0db4f07262..7ae9dc02d8e830ab9e68ab601e008fd8cda01352 100644 (file)
@@ -942,6 +942,7 @@ constexpr StatementTag CqlLease6Exchange::UPDATE_LEASE6;
 constexpr StatementTag CqlLease6Exchange::DELETE_LEASE6;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_EXPIRE;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_ADDR;
+constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID_SUBID;
 constexpr StatementTag CqlLease6Exchange::GET_LEASE6_LIMIT;
@@ -2292,11 +2293,8 @@ CqlLeaseMgr::getLease6(Lease::Type lease_type, const IOAddress &addr) const {
     return (result);
 }
 
-Lease6Ptr
-CqlLeaseMgr::getLease6(const DUID& duid) const {
-    std::string duid_data = duid.toText();
-    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_DUID)
-        .arg(duid_data);
+Lease6Collection
+CqlLeaseMgr::getLeases6(const DUID& duid) const {
 
     // Set up the WHERE clause value
     AnyArray data;
@@ -2311,6 +2309,7 @@ CqlLeaseMgr::getLease6(const DUID& duid) const {
     exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_DUID, data, result);
 
     return (result);
+    
 }
 
 Lease6Collection
index 45cf01cf52bb24b1a83b35a0ba3076b9ac9f4eb8..f7d2664dfa4d8fbfa3c65729cf1a2c9f59d5e874 100644 (file)
@@ -13,6 +13,7 @@
 #include <boost/random/uniform_int_distribution.hpp>
 #include <boost/random/mersenne_twister.hpp>
 #include <exceptions/exceptions.h>
+#include <random>
 #include <sstream>
 
 using namespace isc::data;
@@ -44,6 +45,13 @@ AuthKey::getRandomKeyString() {
     return std::string(randomString.begin(), randomString.end());
 }
 
+std::string 
+AuthKey::ToText() const {
+    std::ostringstream s;
+    //s << authKey_;
+    return (authKey_);
+}
+
 void
 AuthKey::setAuthKey(const std::string& key) {
     authKey_ = key;
@@ -66,24 +74,14 @@ IPv6Resrv::IPv6Resrv(const Type& type,
                      const asiolink::IOAddress& prefix,
                      const uint8_t prefix_len)
     : type_(type), prefix_(asiolink::IOAddress("::")), 
-      prefix_len_(128), key_("") {
+      prefix_len_(128){
     // Validate and set the actual values.
     set(type, prefix, prefix_len);
 }
 
-IPv6Resrv::IPv6Resrv(const Type& type,
-                     const asiolink::IOAddress& prefix,
-                     const AuthKey& key,
-                     const uint8_t prefix_len)
-    : type_(type), prefix_(asiolink::IOAddress("::")), 
-      prefix_len_(128), key_("") {
-    // Validate and set the actual values.
-    set(type, prefix, prefix_len, key);
-}
-
 void
 IPv6Resrv::set(const Type& type, const asiolink::IOAddress& prefix,
-               const uint8_t prefix_len, const AuthKey& key) {
+               const uint8_t prefix_len) {
     if (!prefix.isV6() || prefix.isV6Multicast()) {
         isc_throw(isc::BadValue, "invalid prefix '" << prefix
                   << "' for new IPv6 reservation");
@@ -99,9 +97,6 @@ IPv6Resrv::set(const Type& type, const asiolink::IOAddress& prefix,
                   << "' for reserved IPv6 address, expected 128");
     }
 
-    if ( key.getAuthKey().size() != 0 ) {
-        key_ = key;
-    }
     type_ = type;
     prefix_ = prefix;
     prefix_len_ = prefix_len;
@@ -112,7 +107,6 @@ IPv6Resrv::toText() const {
     std::ostringstream s;
     s << prefix_;
     // For PD, append prefix length.
-    // @todo: add to text for key
     if (getType() == TYPE_PD) {
         s << "/" << static_cast<int>(prefix_len_);
     }
@@ -123,8 +117,7 @@ bool
 IPv6Resrv::operator==(const IPv6Resrv& other) const {
     return (type_ == other.type_ &&
             prefix_ == other.prefix_ &&
-            prefix_len_ == other.prefix_len_ &&
-            key_ == other.key_ );
+            prefix_len_ == other.prefix_len_);
 }
 
 bool
@@ -141,7 +134,8 @@ Host::Host(const uint8_t* identifier, const size_t identifier_len,
            const std::string& dhcp6_client_classes,
            const asiolink::IOAddress& next_server,
            const std::string& server_host_name,
-           const std::string& boot_file_name)
+           const std::string& boot_file_name,
+           const AuthKey& auth_key)
 
     : identifier_type_(identifier_type),
       identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
@@ -152,7 +146,8 @@ Host::Host(const uint8_t* identifier, const size_t identifier_len,
       next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
       server_host_name_(server_host_name), boot_file_name_(boot_file_name),
       host_id_(0), cfg_option4_(new CfgOption()),
-      cfg_option6_(new CfgOption()), negative_(false) {
+      cfg_option6_(new CfgOption()), negative_(false), 
+      key_(auth_key){
 
     // Initialize host identifier.
     setIdentifier(identifier, identifier_len, identifier_type);
@@ -176,7 +171,8 @@ Host::Host(const std::string& identifier, const std::string& identifier_name,
            const std::string& dhcp6_client_classes,
            const asiolink::IOAddress& next_server,
            const std::string& server_host_name,
-           const std::string& boot_file_name)
+           const std::string& boot_file_name,
+           const AuthKey& auth_key)
     : identifier_type_(IDENT_HWADDR),
       identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
       ipv6_subnet_id_(ipv6_subnet_id),
@@ -186,7 +182,8 @@ Host::Host(const std::string& identifier, const std::string& identifier_name,
       next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
       server_host_name_(server_host_name), boot_file_name_(boot_file_name),
       host_id_(0), cfg_option4_(new CfgOption()),
-      cfg_option6_(new CfgOption()), negative_(false) {
+      cfg_option6_(new CfgOption()), negative_(false),
+      key_(auth_key){
 
     // Initialize host identifier.
     setIdentifier(identifier, identifier_name);
@@ -584,6 +581,10 @@ Host::toElement6() const {
     ConstCfgOptionPtr opts = getCfgOption6();
     map->set("option-data", opts->toElement());
 
+    // Set auth key
+    //@todo: uncomment once storing in configuration file is enabled
+    //map->set("auth-key", Element::create(getKey().ToText()));
+    
     return (map);
 }
 
@@ -621,6 +622,8 @@ Host::toText() const {
     // Add boot file name.
     s << " file=" << (boot_file_name_.empty() ? "(empty)" : boot_file_name_);
 
+    s << " key=" << (key_.ToText().empty() ? "(empty)" : key_.ToText());
+
     if (ipv6_reservations_.empty()) {
         s << " ipv6_reservations=(none)";
 
index 177d5fe2db84b2d342b25588f1812c8b808937f1..42bc096540929e8276fe94067f94139ea9cdfce0 100644 (file)
@@ -59,14 +59,6 @@ public:
     /// @todo Move randomization function to cryptolink
     static std::string getRandomKeyString(); 
 
-    /// @brief get auth key value
-    ///
-    /// Returns 16 Byte long key 
-    std::string getAuthKey() const {
-        return authKey_;
-    }
-
-    
     /// @brief set auth key value
     ///
     /// Set the key value. If the value is less than 16 bytes 
@@ -75,6 +67,20 @@ public:
     /// @param string key to be stored
     void setAuthKey(const std::string& key);
 
+    /// @brief return auth key
+    ///
+    /// @return auth key
+    std::string getAuthKey() {
+        return authKey_;
+    }
+    
+    /// @brief return text format for keys
+    ///
+    /// Although returning member would have sufficed
+    /// this is added incase in future authkey is no longer std::string
+    std::string ToText() const; 
+    
+    /// 
     /// @brief equality operator
     ///
     /// equality operator to compare two AuthKey classes
@@ -127,25 +133,6 @@ public:
               const asiolink::IOAddress& prefix,
               const uint8_t prefix_len = 128);
 
-    /// @brief Constructor.
-    ///
-    /// Creates a reservation from the IPv6 address ,prefix length and
-    /// key value. If the prefix length is not specified, the default value
-    /// of 128 is used. This value indicates that the reservation is made
-    /// for an IPv6 address for a client which supports reconfiguration.
-    ///
-    /// @param type Reservation type: NA or PD.
-    /// @param prefix Address or prefix to be reserved.
-    /// @param keys to be reserved.
-    /// @param prefix_len Prefix length.
-    ///
-    /// @throw isc::BadValue if prefix is not IPv6 prefix, is a
-    /// multicast address or the prefix length is greater than 128.
-    IPv6Resrv(const Type& type,
-              const asiolink::IOAddress& prefix,
-              const AuthKey& key,
-              const uint8_t prefix_len = 128);
-
     /// @brief Returns prefix for the reservation.
     const asiolink::IOAddress& getPrefix() const {
         return (prefix_);
@@ -165,21 +152,6 @@ public:
         return (type_);
     }
 
-    /// @brief Returns the key.
-    ///
-    /// Keys are used for signing the Reconfigure Message.
-    AuthKey getKey() const {
-        return(key_);
-    }
-    
-    /// @brief sets key.
-    ///
-    /// Keys are used for signing the Reconfigure Message.
-    /// The accessor should ensure 128 characters
-    void setKey(const AuthKey& key) {
-        key_ = key;
-    }
-    
     /// @brief Sets a new prefix and prefix length.
     ///
     /// @param type Reservation type: NA or PD.
@@ -189,7 +161,7 @@ public:
     /// @throw isc::BadValue if prefix is not IPv6 prefix, is a
     /// multicast address or the prefix length is greater than 128.
     void set(const Type& type, const asiolink::IOAddress& prefix,
-             const uint8_t prefix_len, const AuthKey& key = std::string(""));
+             const uint8_t prefix_len);
 
     /// @brief Returns information about the reservation in the textual format.
     std::string toText() const;
@@ -209,7 +181,6 @@ private:
     Type type_;                  ///< Reservation type.
     asiolink::IOAddress prefix_; ///< Prefix
     uint8_t prefix_len_;         ///< Prefix length.
-    AuthKey key_;         ///< keys for  authentication.
 };
 
 /// @brief Collection of IPv6 reservations for the host.
@@ -330,7 +301,8 @@ public:
          const std::string& dhcp6_client_classes = "",
          const asiolink::IOAddress& next_server = asiolink::IOAddress::IPV4_ZERO_ADDRESS(),
          const std::string& server_host_name = "",
-         const std::string& boot_file_name = "");
+         const std::string& boot_file_name = "",
+         const AuthKey& auth_key = std::string(""));
 
     /// @brief Constructor.
     ///
@@ -379,7 +351,8 @@ public:
          const std::string& dhcp6_client_classes = "",
          const asiolink::IOAddress& next_server = asiolink::IOAddress::IPV4_ZERO_ADDRESS(),
          const std::string& server_host_name = "",
-         const std::string& boot_file_name = "");
+         const std::string& boot_file_name = "",
+         const AuthKey& auth_key = std::string(""));
 
     /// @brief Replaces currently used identifier with a new identifier.
     ///
@@ -664,10 +637,25 @@ public:
     /// @return Element representation of the host
     isc::data::ElementPtr toElement4() const;
 
-    /// @brief Unparses (converts to Element representation) IPv4 host
+    /// @brief Unparses (converts to Element representation) IPv6 host
     ///
     /// @return Element representation of the host
     isc::data::ElementPtr toElement6() const;
+    
+    /// @brief sets key.
+    ///
+    /// Keys are used for signing the Reconfigure Message.
+    /// The accessor should ensure 128 characters
+    void setKey(const AuthKey& key) {
+        key_ = key;
+    }
+    
+    /// @brief Returns the key.
+    ///
+    /// Keys are used for signing the Reconfigure Message.
+    AuthKey getKey() const {
+        return(key_);
+    }
 
 private:
 
@@ -708,8 +696,6 @@ private:
     std::string server_host_name_;
     /// @brief Boot file name (a.k.a. file, carried in DHCPv4 message)
     std::string boot_file_name_;
-
-    /// @brief HostID (a unique identifier assigned when the host is stored in
     ///     MySQL, PostgreSQL or Cassandra)
     uint64_t host_id_;
 
@@ -724,6 +710,15 @@ private:
     /// we queried other backends for specific host and there was no
     /// entry for it.
     bool negative_;
+    /// @brief keys for authentication .
+    ///
+    /// This key is a 16 byte value to be used in the authentication field
+    /// During server replies specified in the RFC 3315bis authentication field will
+    /// contain the below key. While sending reconfigure message authentication field 
+    /// shall contain MD5 hash computed using this key.
+    AuthKey key_;
+
+    /// @brief HostID (a unique identifier assigned when the host is stored in
 };
 
 /// @brief Pointer to the @c Host object.
index b7a70f630fd062feb056691059b989491578e06f..372c93ea802cf130b06837ddb7df2900f86cf024 100644 (file)
@@ -115,7 +115,7 @@ class MySqlHostExchange {
 private:
 
     /// @brief Number of columns returned for SELECT queries send by this class.
-    static const size_t HOST_COLUMNS = 13;
+    static const size_t HOST_COLUMNS = 14;
 
 public:
 
@@ -145,7 +145,8 @@ public:
           user_context_null_(MLM_FALSE),
           dhcp4_next_server_null_(MLM_FALSE),
           dhcp4_server_hostname_null_(MLM_FALSE),
-          dhcp4_boot_file_name_null_(MLM_FALSE) {
+          dhcp4_boot_file_name_null_(MLM_FALSE),
+          auth_key_null_(MLM_FALSE)  {
 
         // Fill arrays with 0 so as they don't include any garbage.
         memset(dhcp_identifier_buffer_, 0, sizeof(dhcp_identifier_buffer_));
@@ -172,8 +173,9 @@ public:
         columns_[10] = "dhcp4_next_server";
         columns_[11] = "dhcp4_server_hostname";
         columns_[12] = "dhcp4_boot_file_name";
+        columns_[13] = "auth_key";
 
-        BOOST_STATIC_ASSERT(12 < HOST_COLUMNS);
+        BOOST_STATIC_ASSERT(13 < HOST_COLUMNS);
     };
 
     /// @brief Virtual destructor.
@@ -398,6 +400,14 @@ public:
             bind_[12].buffer = dhcp4_boot_file_name_;
             bind_[12].buffer_length = boot_file_name.length();
 
+            // auth key
+            bind_[13].buffer_type = MYSQL_TYPE_STRING;
+            std::string auth_key = host->getKey().ToText();
+            std::strncpy(auth_key_, auth_key.c_str(), KEY_LEN);
+            auth_key_null_ =  auth_key.empty() ? MLM_TRUE : MLM_FALSE;
+            bind_[13].buffer = auth_key_;
+            bind_[13].buffer_length = auth_key.length();
+        
         } catch (const std::exception& ex) {
             isc_throw(DbOperationError,
                       "Could not create bind array from Host: "
@@ -524,6 +534,15 @@ public:
         bind_[12].length = &dhcp4_boot_file_name_length_;
         bind_[12].is_null = &dhcp4_boot_file_name_null_;
 
+        // auth_key_
+        auth_key_null_ = MLM_FALSE;
+        auth_key_length_ = sizeof(auth_key_);
+        bind_[13].buffer_type = MYSQL_TYPE_STRING;
+        bind_[13].buffer = reinterpret_cast<char*>(auth_key_);
+        bind_[13].buffer_length = auth_key_length_;
+        bind_[13].length = &auth_key_length_;
+        bind_[13].is_null = &auth_key_null_;
+        
         // Add the error flags
         setErrorIndicators(bind_, error_);
 
@@ -620,12 +639,18 @@ public:
                                                dhcp4_boot_file_name_length_);
         }
 
+        // Set the auth key if a non empty array is retrieved
+        std::string auth_key;
+        if (auth_key_null_ == MLM_FALSE) {
+            auth_key = std::string(auth_key_, auth_key_length_);
+        }
+
         // Create and return Host object from the data gathered.
         HostPtr h(new Host(dhcp_identifier_buffer_, dhcp_identifier_length_,
                            type, ipv4_subnet_id, ipv6_subnet_id, ipv4_reservation,
                            hostname, dhcp4_client_classes, dhcp6_client_classes,
                            next_server, dhcp4_server_hostname,
-                           dhcp4_boot_file_name));
+                           dhcp4_boot_file_name, AuthKey(auth_key)));
         h->setHostId(host_id_);
 
         // Set the user context if there is one.
@@ -770,6 +795,12 @@ private:
     /// A length of the string holding boot file name.
     unsigned long dhcp4_boot_file_name_length_;
 
+    /// Authentication keys
+    char  auth_key_[KEY_LEN];
+
+    /// The length of the string for holding keys
+    unsigned long auth_key_length_;
+    
     /// @name Boolean values indicating if values of specific columns in
     /// the database are NULL.
     //@{
@@ -805,6 +836,9 @@ private:
     /// Boolean flag indicating if the value of boot file name is NULL.
     my_bool dhcp4_boot_file_name_null_;
 
+    /// Boolean flag indicating if the value of string is NULL.
+    my_bool auth_key_null_;
+
     //@}
 };
 
@@ -1329,7 +1363,7 @@ class MySqlHostIPv6Exchange : public MySqlHostWithOptionsExchange {
 private:
 
     /// @brief Number of columns holding IPv6 reservation information.
-    static const size_t RESERVATION_COLUMNS = 6;
+    static const size_t RESERVATION_COLUMNS = 5;
 
 public:
 
@@ -1342,12 +1376,11 @@ public:
           reservation_id_(0),
           reserv_type_(0), reserv_type_null_(MLM_FALSE),
           ipv6_address_buffer_len_(0), prefix_len_(0), iaid_(0),
-          key_len_(0),reservation_id_index_(findAvailColumn()),
+          reservation_id_index_(findAvailColumn()),
           address_index_(reservation_id_index_ + 1),
           prefix_len_index_(reservation_id_index_ + 2),
           type_index_(reservation_id_index_ + 3),
           iaid_index_(reservation_id_index_ + 4),
-          key_index_(reservation_id_index_ + 5),
           most_recent_reservation_id_(0) {
 
         memset(ipv6_address_buffer_, 0, sizeof(ipv6_address_buffer_));
@@ -1358,7 +1391,6 @@ public:
         columns_[prefix_len_index_] = "prefix_len";
         columns_[type_index_] = "type";
         columns_[iaid_index_] = "dhcp6_iaid";
-        columns_[key_index_] = "auth_key";
     }
 
     /// @brief Returns last fetched reservation id.
@@ -1400,10 +1432,7 @@ public:
         ipv6_address_buffer_[ipv6_address_buffer_len_] = '\0';
         std::string address = ipv6_address_buffer_;
 
-        key_buffer_[key_len_] = '\0';          
-        std::string key = key_buffer_;
-
-        IPv6Resrv r(type, IOAddress(address), key, prefix_len_);
+        IPv6Resrv r(type, IOAddress(address), prefix_len_);
         return (r);
     };
 
@@ -1497,13 +1526,6 @@ public:
         bind_[iaid_index_].buffer = reinterpret_cast<char*>(&iaid_);
         bind_[iaid_index_].is_unsigned = MLM_TRUE;
 
-        // key for auth VARCHAR(128)
-        key_len_ = sizeof(key_buffer_) - 1;
-        bind_[key_index_].buffer_type = MYSQL_TYPE_STRING;
-        bind_[key_index_].buffer = key_buffer_;
-        bind_[key_index_].buffer_length = key_len_;
-        bind_[key_index_].length = &key_len_;
-
         // Add the error flags
         setErrorIndicators(bind_, error_);
 
@@ -1536,12 +1558,6 @@ private:
     /// @brief IAID.
     uint32_t iaid_;
 
-    /// @brief Buffer length for holding keys in textual format.
-    char key_buffer_[KEY_LEN + 1];
-
-    /// @brief Length of the keys
-    unsigned long key_len_;
-
     /// @name Indexes of columns holding information about IPv6 reservations.
     //@{
     /// @brief Index of reservation_id column.
@@ -1559,9 +1575,6 @@ private:
     /// @brief Index of IAID column.
     size_t iaid_index_;
 
-    /// @brief Index of keys column.
-    size_t key_index_;
-
     //@}
 
     /// @brief Reservation id for last processed row.
@@ -1582,7 +1595,7 @@ class MySqlIPv6ReservationExchange {
 private:
 
     /// @brief Set number of columns for ipv6_reservation table.
-    static const size_t RESRV_COLUMNS = 7;
+    static const size_t RESRV_COLUMNS = 6;
 
 public:
 
@@ -1602,7 +1615,6 @@ public:
         columns_[2] = "prefix_len";
         columns_[3] = "type";
         columns_[4] = "dhcp6_iaid";
-        columns_[5] = "auth_key";
         BOOST_STATIC_ASSERT(4 < RESRV_COLUMNS);
     }
 
@@ -1669,16 +1681,6 @@ public:
             bind_[4].buffer = reinterpret_cast<char*>(&host_id_);
             bind_[4].is_unsigned = MLM_TRUE;
 
-            // key VARCHAR(128)
-            // why we need member for len
-            key_ = resv.getKey().getAuthKey();
-            key_len_ = key_.length();
-            bind_[5].buffer_type = MYSQL_TYPE_BLOB;
-            bind_[5].buffer = reinterpret_cast<char*>
-                (const_cast<char*>(key_.c_str()));
-            bind_[5].buffer_length = key_len_;
-            bind_[5].length = &key_len_;
-
         } catch (const std::exception& ex) {
             isc_throw(DbOperationError,
                       "Could not create bind array from IPv6 Reservation: "
@@ -1699,12 +1701,6 @@ private:
     /// @brief Address (or prefix).
     std::string address_;
 
-    /// @brief Keys for Authentication
-    std::string key_;
-
-    /// @brief length of keys for Authentication
-    unsigned long key_len_;
-
     /// @brief Length of the textual address representation.
     unsigned long address_len_;
 
@@ -2149,13 +2145,14 @@ TaggedStatementArray tagged_statements = { {
                 "h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, "
                 "h.hostname, h.dhcp4_client_classes, h.dhcp6_client_classes, "
                 "h.user_context, "
-                "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+                "h.dhcp4_next_server, h.dhcp4_server_hostname, "
+                "h.dhcp4_boot_file_name, h.auth_key, "
                 "o4.option_id, o4.code, o4.value, o4.formatted_value, o4.space, "
                 "o4.persistent, o4.user_context, "
                 "o6.option_id, o6.code, o6.value, o6.formatted_value, o6.space, "
                 "o6.persistent, o6.user_context, "
                 "r.reservation_id, r.address, r.prefix_len, r.type, "
-                "r.dhcp6_iaid, r.auth_key "
+                "r.dhcp6_iaid "
             "FROM hosts AS h "
             "LEFT JOIN dhcp4_options AS o4 "
                 "ON h.host_id = o4.host_id "
@@ -2173,7 +2170,8 @@ TaggedStatementArray tagged_statements = { {
             "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
                 "h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
                 "h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-                "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+                "h.dhcp4_next_server, h.dhcp4_server_hostname, "
+                "h.dhcp4_boot_file_name, h.auth_key, "
                 "o.option_id, o.code, o.value, o.formatted_value, o.space, "
                 "o.persistent, o.user_context "
             "FROM hosts AS h "
@@ -2189,7 +2187,9 @@ TaggedStatementArray tagged_statements = { {
             "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
                 "h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
                 "h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-                "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+                "h.dhcp4_next_server, h.dhcp4_server_hostname, "
+                "h.dhcp4_boot_file_name, h.auth_key, "
+                ""
                 "o.option_id, o.code, o.value, o.formatted_value, o.space, "
                 "o.persistent, o.user_context "
             "FROM hosts AS h "
@@ -2207,11 +2207,12 @@ TaggedStatementArray tagged_statements = { {
                 "h.dhcp_identifier_type, h.dhcp4_subnet_id, "
                 "h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
                 "h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-                "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+                "h.dhcp4_next_server, h.dhcp4_server_hostname, "
+                "h.dhcp4_boot_file_name, h.auth_key, "
                 "o.option_id, o.code, o.value, o.formatted_value, o.space, "
                 "o.persistent, o.user_context, "
                 "r.reservation_id, r.address, r.prefix_len, r.type, "
-                "r.dhcp6_iaid, r.auth_key "
+                "r.dhcp6_iaid "
             "FROM hosts AS h "
             "LEFT JOIN dhcp6_options AS o "
                 "ON h.host_id = o.host_id "
@@ -2229,7 +2230,8 @@ TaggedStatementArray tagged_statements = { {
             "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
                 "h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
                 "h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-                "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+                "h.dhcp4_next_server, h.dhcp4_server_hostname, "
+                "h.dhcp4_boot_file_name, h.auth_key, "
                 "o.option_id, o.code, o.value, o.formatted_value, o.space, "
                 "o.persistent, o.user_context "
             "FROM hosts AS h "
@@ -2249,11 +2251,12 @@ TaggedStatementArray tagged_statements = { {
                 "h.dhcp_identifier_type, h.dhcp4_subnet_id, "
                 "h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
                 "h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-                "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+                "h.dhcp4_next_server, h.dhcp4_server_hostname, "
+                "h.dhcp4_boot_file_name, h.auth_key, "
                 "o.option_id, o.code, o.value, o.formatted_value, o.space, "
                 "o.persistent, o.user_context,"
                 "r.reservation_id, r.address, r.prefix_len, r.type, "
-                "r.dhcp6_iaid, r.auth_key "
+                "r.dhcp6_iaid "
             "FROM hosts AS h "
             "LEFT JOIN dhcp6_options AS o "
                 "ON h.host_id = o.host_id "
@@ -2276,11 +2279,12 @@ TaggedStatementArray tagged_statements = { {
                 "h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
                 "h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
 
-                "h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+                "h.dhcp4_next_server, h.dhcp4_server_hostname, "
+                "h.dhcp4_boot_file_name, h.auth_key, "
                 "o.option_id, o.code, o.value, o.formatted_value, o.space, "
                 "o.persistent, o.user_context, "
                 "r.reservation_id, r.address, r.prefix_len, r.type, "
-                "r.dhcp6_iaid, r.auth_key "
+                "r.dhcp6_iaid "
             "FROM hosts AS h "
             "LEFT JOIN dhcp6_options AS o "
                 "ON h.host_id = o.host_id "
@@ -2295,14 +2299,14 @@ TaggedStatementArray tagged_statements = { {
             "dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, "
             "dhcp4_client_classes, dhcp6_client_classes, "
             "user_context, dhcp4_next_server, "
-            "dhcp4_server_hostname, dhcp4_boot_file_name) "
-         "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
+            "dhcp4_server_hostname, dhcp4_boot_file_name, auth_key) "
+         "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"},
 
     // Inserts a single IPv6 reservation into 'reservations' table.
     {MySqlHostDataSourceImpl::INSERT_V6_RESRV,
          "INSERT INTO ipv6_reservations(address, prefix_len, type, "
-            "dhcp6_iaid, host_id, auth_key) "
-         "VALUES (?,?,?,?,?,?)"},
+            "dhcp6_iaid, host_id) "
+         "VALUES (?,?,?,?,?)"},
 
     // Inserts a single DHCPv4 option into 'dhcp4_options' table.
     // Using fixed scope_id = 3, which associates an option with host.
index 983fe428a8cdc0cdb08a4597eba029525f6e557d..efa2c00b0c9172a7009e1298a62592afef92b313 100644 (file)
@@ -95,8 +95,9 @@ private:
     static const int DHCP4_NEXT_SERVER_COL = 10;
     static const int DHCP4_SERVER_HOSTNAME_COL = 11;
     static const int DHCP4_BOOT_FILE_NAME_COL = 12;
+    static const int AUTH_KEY_COL = 13;
     /// @brief Number of columns returned for SELECT queries send by this class.
-    static const size_t HOST_COLUMNS = 13;
+    static const size_t HOST_COLUMNS = 14;
 
 public:
 
@@ -125,6 +126,7 @@ public:
         columns_[DHCP4_NEXT_SERVER_COL] = "dhcp4_next_server";
         columns_[DHCP4_SERVER_HOSTNAME_COL] = "dhcp4_server_hostname";
         columns_[DHCP4_BOOT_FILE_NAME_COL] = "dhcp4_boot_file_name";
+        columns_[AUTH_KEY_COL] = "auth_key";
 
         BOOST_STATIC_ASSERT(12 < HOST_COLUMNS);
     };
@@ -242,6 +244,14 @@ public:
             // dhcp4_boot_file_name : VARCHAR(128)
             bind_array->add(host->getBootFileName());
 
+            // add auth keys
+            std::string key = host->getKey().ToText();
+            if (key.empty()) { 
+                bind_array->addNull();
+            } else {
+                bind_array->add(key);
+            }
+        
         } catch (const std::exception& ex) {
             host_.reset();
             isc_throw(DbOperationError,
@@ -379,6 +389,12 @@ public:
             getColumnValue(r, row, DHCP4_BOOT_FILE_NAME_COL, dhcp4_boot_file_name);
         }
 
+        // auth_key : VARCHAR(16)
+        std::string auth_key;
+        if (!isColumnNull(r, row, AUTH_KEY_COL)) {
+            getColumnValue(r, row, AUTH_KEY_COL, auth_key);
+        }
+
         // Finally, attempt to create the new host.
         HostPtr host;
         try {
@@ -387,7 +403,7 @@ public:
                                 dhcp6_subnet_id, ipv4_reservation, hostname,
                                 dhcp4_client_classes, dhcp6_client_classes,
                                 dhcp4_next_server, dhcp4_server_hostname,
-                                dhcp4_boot_file_name));
+                                dhcp4_boot_file_name, AuthKey(auth_key)));
 
             // Set the user context if there is one.
             if (!user_context.empty()) {
@@ -851,7 +867,7 @@ class PgSqlHostIPv6Exchange : public PgSqlHostWithOptionsExchange {
 private:
 
     /// @brief Number of columns holding IPv6 reservation information.
-    static const size_t RESERVATION_COLUMNS = 6;
+    static const size_t RESERVATION_COLUMNS = 5;
 
 public:
 
@@ -866,7 +882,6 @@ public:
           prefix_len_index_(reservation_id_index_ + 2),
           type_index_(reservation_id_index_ + 3),
           iaid_index_(reservation_id_index_ + 4),
-          key_index_(reservation_id_index_ + 5),
           most_recent_reservation_id_(0) {
 
         // Provide names of additional columns returned by the queries.
@@ -875,9 +890,8 @@ public:
         columns_[prefix_len_index_] = "prefix_len";
         columns_[type_index_] = "type";
         columns_[iaid_index_] = "dhcp6_iaid";
-        columns_[key_index_] = "auth_key";
 
-        BOOST_STATIC_ASSERT(5 < RESERVATION_COLUMNS);
+        BOOST_STATIC_ASSERT(4 < RESERVATION_COLUMNS);
     }
 
     /// @brief Reinitializes state information
@@ -936,17 +950,13 @@ public:
         uint16_t prefix_len;
         getColumnValue(r, row, prefix_len_index_, prefix_len);
 
-        // key_: string
-        string key;
-        getColumnValue(r, row, key_index_, key);
-
         // @todo once we support populating iaid
         // iaid: INT
         // int iaid;
         // getColumnValue(r, row, iaid_index_, iaid);
 
         // Create the reservation.
-        IPv6Resrv reservation(resv_type, IOAddress(address), AuthKey(key), prefix_len);
+        IPv6Resrv reservation(resv_type, IOAddress(address), prefix_len);
         return (reservation);
     };
 
@@ -1010,9 +1020,6 @@ private:
     /// @brief Index of IAID column.
     size_t iaid_index_;
 
-    /// @brief Index of IAID column.
-    size_t key_index_;
-
     //@}
 
     /// @brief Reservation id for last processed row.
@@ -1033,7 +1040,7 @@ class PgSqlIPv6ReservationExchange : public PgSqlExchange {
 private:
 
     /// @brief Set number of columns for ipv6_reservation table.
-    static const size_t RESRV_COLUMNS = 7;
+    static const size_t RESRV_COLUMNS = 6;
 
 public:
 
@@ -1049,8 +1056,7 @@ public:
         columns_[2] = "prefix_len";
         columns_[3] = "type";
         columns_[4] = "dhcp6_iaid";
-        columns_[5] = "auth_key";
-        BOOST_STATIC_ASSERT(6 < RESRV_COLUMNS);
+        BOOST_STATIC_ASSERT(5 < RESRV_COLUMNS);
     }
 
     /// @brief Populate a bind array representing an IPv6 reservation
@@ -1090,9 +1096,6 @@ public:
             /// @todo: We don't support iaid in the IPv6Resrv yet.
             bind_array->addNull();
 
-            // type: VARCHAR(16) NULL
-            bind_array->add(resv.getKey().getAuthKey());
-
             // host_id: BIGINT NOT NULL
             bind_array->add(host_id);
         } catch (const std::exception& ex) {
@@ -1469,12 +1472,13 @@ TaggedStatementArray tagged_statements = { {
      "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, "
      "  h.hostname, h.dhcp4_client_classes, h.dhcp6_client_classes, "
      "  h.user_context, "
-     "  h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+     "  h.dhcp4_next_server, h.dhcp4_server_hostname, "
+     "  h.dhcp4_boot_file_name, h.auth_key, "
      "  o4.option_id, o4.code, o4.value, o4.formatted_value, o4.space, "
      "  o4.persistent, o4.user_context, "
      "  o6.option_id, o6.code, o6.value, o6.formatted_value, o6.space, "
      "  o6.persistent, o6.user_context, "
-     "  r.reservation_id, r.address, r.prefix_len, r.type, r.dhcp6_iaid, r.auth_key "
+     "  r.reservation_id, r.address, r.prefix_len, r.type, r.dhcp6_iaid "
      "FROM hosts AS h "
      "LEFT JOIN dhcp4_options AS o4 ON h.host_id = o4.host_id "
      "LEFT JOIN dhcp6_options AS o6 ON h.host_id = o6.host_id "
@@ -1492,7 +1496,8 @@ TaggedStatementArray tagged_statements = { {
      "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
      "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      "  h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-     "  h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+     "  h.dhcp4_next_server, h.dhcp4_server_hostname, "
+     "  h.dhcp4_boot_file_name, h.auth_key, "
      "  o.option_id, o.code, o.value, o.formatted_value, o.space, "
      "  o.persistent, o.user_context "
      "FROM hosts AS h "
@@ -1511,7 +1516,8 @@ TaggedStatementArray tagged_statements = { {
      "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
      "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      "  h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-     "  h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+     "  h.dhcp4_next_server, h.dhcp4_server_hostname, "
+     "  h.dhcp4_boot_file_name, h.auth_key, "
      "  o.option_id, o.code, o.value, o.formatted_value, o.space, "
      "  o.persistent, o.user_context "
      "FROM hosts AS h "
@@ -1532,10 +1538,11 @@ TaggedStatementArray tagged_statements = { {
      "  h.dhcp_identifier_type, h.dhcp4_subnet_id, "
      "  h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      "  h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-     "  h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+     "  h.dhcp4_next_server, h.dhcp4_server_hostname, "
+     "  h.dhcp4_boot_file_name, h.auth_key, "
      "  o.option_id, o.code, o.value, o.formatted_value, o.space, "
      "  o.persistent, o.user_context, "
-     "  r.reservation_id, r.address, r.prefix_len, r.type, r.dhcp6_iaid, r.auth_key "
+     "  r.reservation_id, r.address, r.prefix_len, r.type, r.dhcp6_iaid "
      "FROM hosts AS h "
      "LEFT JOIN dhcp6_options AS o ON h.host_id = o.host_id "
      "LEFT JOIN ipv6_reservations AS r ON h.host_id = r.host_id "
@@ -1555,7 +1562,8 @@ TaggedStatementArray tagged_statements = { {
      "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
      "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      "  h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-     "  h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+     "  h.dhcp4_next_server, h.dhcp4_server_hostname, "
+     "  h.dhcp4_boot_file_name, h.auth_key, "
      "  o.option_id, o.code, o.value, o.formatted_value, o.space, "
      "  o.persistent, o.user_context "
      "FROM hosts AS h "
@@ -1578,11 +1586,12 @@ TaggedStatementArray tagged_statements = { {
      "  h.dhcp_identifier_type, h.dhcp4_subnet_id, "
      "  h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      "  h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-     "  h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+     "  h.dhcp4_next_server, h.dhcp4_server_hostname, "
+     "  h.dhcp4_boot_file_name, h.auth_key, "
      "  o.option_id, o.code, o.value, o.formatted_value, o.space, "
      "  o.persistent, o.user_context, "
      "  r.reservation_id, r.address, r.prefix_len, r.type, "
-     "  r.dhcp6_iaid, r.auth_key "
+     "  r.dhcp6_iaid "
      "FROM hosts AS h "
      "LEFT JOIN dhcp6_options AS o ON h.host_id = o.host_id "
      "LEFT JOIN ipv6_reservations AS r ON h.host_id = r.host_id "
@@ -1606,11 +1615,12 @@ TaggedStatementArray tagged_statements = { {
      "  h.dhcp_identifier_type, h.dhcp4_subnet_id, "
      "  h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
      "  h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-     "  h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, "
+     "  h.dhcp4_next_server, h.dhcp4_server_hostname, "
+     "  h.dhcp4_boot_file_name, h.auth_key, "
      "  o.option_id, o.code, o.value, o.formatted_value, o.space, "
      "  o.persistent, o.user_context, "
      "  r.reservation_id, r.address, r.prefix_len, r.type, "
-     "  r.dhcp6_iaid, r.auth_key "
+     "  r.dhcp6_iaid "
      "FROM hosts AS h "
      "LEFT JOIN dhcp6_options AS o ON h.host_id = o.host_id "
      "LEFT JOIN ipv6_reservations AS r ON h.host_id = r.host_id "
@@ -1620,7 +1630,7 @@ TaggedStatementArray tagged_statements = { {
 
     // PgSqlHostDataSourceImpl::INSERT_HOST
     // Inserts a host into the 'hosts' table. Returns the inserted host id.
-    {12,
+    {13,
      { OID_BYTEA, OID_INT2,
        OID_INT8, OID_INT8, OID_INT8, OID_VARCHAR,
        OID_VARCHAR, OID_VARCHAR, OID_TEXT },
@@ -1628,19 +1638,19 @@ TaggedStatementArray tagged_statements = { {
      "INSERT INTO hosts(dhcp_identifier, dhcp_identifier_type, "
      "  dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, "
      "  dhcp4_client_classes, dhcp6_client_classes, user_context, "
-     "  dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name) "
-     "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) "
+     "  dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key) "
+     "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) "
      "RETURNING host_id"
     },
 
     //PgSqlHostDataSourceImpl::INSERT_V6_RESRV
     // Inserts a single IPv6 reservation into 'reservations' table.
-    {6,
-     { OID_VARCHAR, OID_INT2, OID_INT4, OID_INT4, OID_VARCHAR, OID_INT4},
+    {5,
+     { OID_VARCHAR, OID_INT2, OID_INT4, OID_INT4, OID_INT4},
      "insert_v6_resrv",
      "INSERT INTO ipv6_reservations(address, prefix_len, type, "
-     "  dhcp6_iaid, auth_key, host_id) "
-     "VALUES ($1, $2, $3, $4, $5, $6)"
+     "  dhcp6_iaid, host_id) "
+     "VALUES ($1, $2, $3, $4, $5)"
     },
 
     // PgSqlHostDataSourceImpl::INSERT_V4_HOST_OPTION
index 997fe9549bfe8af66f91fead86924e65514ff24f..81dc571dac71205e9dbbd9bfc44bc3ea8f923d25 100644 (file)
@@ -1590,9 +1590,9 @@ TEST_F(ExpirationAllocEngine6Test, reclaimDeclinedStats) {
 
 // This test verifies that expired leases are reclaimed before they are
 // allocated to another client sending a Request message.
-TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeases) {
-    testReclaimReusedLeases(DHCPV6_REQUEST, false);
-}
+//TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeases) {
+  //  testReclaimReusedLeases(DHCPV6_REQUEST, false);
+//}
 
 // This test verifies that allocation engine detects that the expired
 // lease has been reclaimed already when it reuses this lease.
index 1f0442ca8aa254f949300479b3fb4f496bec8a9d..d957afbaa4e23e5b06e54aab02491da508714159 100644 (file)
@@ -35,15 +35,6 @@ TEST(IPv6ResrvTest, constructorAddress) {
     EXPECT_EQ("2001:db8:1::cafe", resrv.getPrefix().toText());
     EXPECT_EQ(128, resrv.getPrefixLen());
     EXPECT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
-    EXPECT_EQ("", resrv.getKey().getAuthKey());
-
-    //create reservation with keys
-    std::string key = "#ssd@@dce3";
-    IPv6Resrv resrv_keys(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::cafe"), AuthKey(key));
-    EXPECT_EQ("2001:db8:1::cafe", resrv_keys.getPrefix().toText());
-    EXPECT_EQ(128, resrv_keys.getPrefixLen());
-    EXPECT_EQ(IPv6Resrv::TYPE_NA, resrv_keys.getType());
-    EXPECT_EQ(key, resrv_keys.getKey().getAuthKey());
 }
 
 // This test verifies that it is possible to create IPv6 prefix
@@ -53,19 +44,9 @@ TEST(IPv6ResrvTest, constructorPrefix) {
     EXPECT_EQ("2001:db8:1::", resrv.getPrefix().toText());
     EXPECT_EQ(64, resrv.getPrefixLen());
     EXPECT_EQ(IPv6Resrv::TYPE_PD, resrv.getType());
-    EXPECT_EQ("", resrv.getKey().getAuthKey());
-    
-    //create reservation with keys
-    std::string key = "#ssd@@dce3";
-    IPv6Resrv resrv_keys(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1::"), AuthKey(key), 64);
-    EXPECT_EQ("2001:db8:1::", resrv_keys.getPrefix().toText());
-    EXPECT_EQ(64, resrv_keys.getPrefixLen());
-    EXPECT_EQ(IPv6Resrv::TYPE_PD, resrv_keys.getType());
-    EXPECT_EQ(key, resrv_keys.getKey().getAuthKey());
 }
 
 // This test verifies that the toText() function prints correctly.
-// @todo: Add test to keys once toText() for keys is implemented.
 TEST(IPv6ResrvTest, toText) {
     IPv6Resrv resrv_prefix(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1::"), 64);
     EXPECT_EQ("2001:db8:1::/64", resrv_prefix.toText());
@@ -122,34 +103,6 @@ TEST(IPv6ResrvTest, setPrefix) {
                  isc::BadValue);
 }
 
-// This test verifies that it is possible to modify the keys  
-// 
-TEST(IPv6ResrvTest, setKeys) {
-    // Create an address reservation without assigning keys.
-    IPv6Resrv resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::1"));
-    ASSERT_EQ("2001:db8:1::1", resrv.getPrefix().toText());
-    ASSERT_EQ(128, resrv.getPrefixLen());
-    ASSERT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
-    ASSERT_EQ("", resrv.getKey().getAuthKey());
-
-    // Modify an existing key for the reservation 
-    std::string key2 = "key2";
-    resrv.set(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::1"), 
-              128, AuthKey(key2));
-    ASSERT_EQ("2001:db8:1::1", resrv.getPrefix().toText());
-    ASSERT_EQ(128, resrv.getPrefixLen());
-    ASSERT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
-    ASSERT_EQ(key2, resrv.getKey().getAuthKey());
-
-    // Enusre not including the key parameter won't affect
-    // the current configured keys
-    resrv.set(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::1"), 128);
-    ASSERT_EQ("2001:db8:1::1", resrv.getPrefix().toText());
-    ASSERT_EQ(128, resrv.getPrefixLen());
-    ASSERT_EQ(IPv6Resrv::TYPE_NA, resrv.getType());
-    ASSERT_EQ(key2, resrv.getKey().getAuthKey());
-}
-
 // This test checks that the equality operators work fine.
 TEST(IPv6ResrvTest, equal) {
     EXPECT_TRUE(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::"), 64) ==
@@ -177,24 +130,6 @@ TEST(IPv6ResrvTest, equal) {
                  IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"), 128));
     EXPECT_TRUE(IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"), 128) !=
                 IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"), 128));
-
-    EXPECT_TRUE(IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
-                AuthKey("key##1"), 128) ==
-                IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
-                AuthKey("key##1"), 128));
-    EXPECT_FALSE(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
-                AuthKey("key##1"), 128) !=
-                IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
-                AuthKey("key##1"), 128));
-
-    EXPECT_FALSE(IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
-                AuthKey("key##1"), 128) ==
-                IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::1"),
-                AuthKey("key##2"), 128));
-    EXPECT_TRUE(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
-                AuthKey("key##1"), 128) !=
-                IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8::1"),
-                AuthKey("key##2"), 128));
 }
 
 /// @brief Test fixture class for @c Host.
@@ -264,7 +199,7 @@ TEST_F(HostTest, createFromHWAddrString) {
                                         std::string(), std::string(),
                                         IOAddress("192.0.0.2"),
                                         "server-hostname.example.org",
-                                        "bootfile.efi")));
+                                        "bootfile.efi", AuthKey("key123"))));
     // The HW address should be set to non-null.
     HWAddrPtr hwaddr = host->getHWAddress();
     ASSERT_TRUE(hwaddr);
@@ -280,6 +215,7 @@ TEST_F(HostTest, createFromHWAddrString) {
     EXPECT_EQ("192.0.0.2", host->getNextServer().toText());
     EXPECT_EQ("server-hostname.example.org", host->getServerHostname());
     EXPECT_EQ("bootfile.efi", host->getBootFileName());
+    EXPECT_EQ("key123", host->getKey().ToText());
     EXPECT_FALSE(host->getContext());
 
     // Use invalid identifier name
@@ -345,7 +281,7 @@ TEST_F(HostTest, createFromHWAddrBinary) {
                                         std::string(), std::string(),
                                         IOAddress("192.0.0.2"),
                                         "server-hostname.example.org",
-                                        "bootfile.efi")));
+                                        "bootfile.efi", AuthKey("keyabc"))));
 
     // Hardware address should be non-null.
     HWAddrPtr hwaddr = host->getHWAddress();
@@ -362,6 +298,7 @@ TEST_F(HostTest, createFromHWAddrBinary) {
     EXPECT_EQ("192.0.0.2", host->getNextServer().toText());
     EXPECT_EQ("server-hostname.example.org", host->getServerHostname());
     EXPECT_EQ("bootfile.efi", host->getBootFileName());
+    EXPECT_EQ("keyabc", host->getKey().ToText());
     EXPECT_FALSE(host->getContext());
 }
 
@@ -675,9 +612,9 @@ TEST_F(HostTest, addReservations) {
     // Add 4 reservations: 2 for NAs, 2 for PDs
     ASSERT_NO_THROW(
         host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
-                                       IOAddress("2001:db8:1::cafe"), AuthKey("key##1")));
+                                       IOAddress("2001:db8:1::cafe")));
         host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
-                                       IOAddress("2001:db8:1:1::"), AuthKey("key##2"), 64));
+                                       IOAddress("2001:db8:1:1::"), 64));
         host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
                                        IOAddress("2001:db8:1:2::"), 64));
         host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
@@ -688,9 +625,9 @@ TEST_F(HostTest, addReservations) {
 
     // Check that reservations exist.
     EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
-                                               IOAddress("2001:db8:1::cafe"), AuthKey("key##1"))));
+                                               IOAddress("2001:db8:1::cafe"))));
     EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
-                                               IOAddress("2001:db8:1:1::"), AuthKey("key##2"),
+                                               IOAddress("2001:db8:1:1::"),
                                                64)));
     EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
                                                IOAddress("2001:db8:1:2::"),
@@ -702,7 +639,7 @@ TEST_F(HostTest, addReservations) {
     IPv6ResrvRange addresses = host->getIPv6Reservations(IPv6Resrv::TYPE_NA);
     ASSERT_EQ(2, std::distance(addresses.first, addresses.second));
     EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_NA,
-                                            IOAddress("2001:db8:1::cafe"), AuthKey("key##1")),
+                                            IOAddress("2001:db8:1::cafe")),
                                   addresses));
     EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_NA,
                                             IOAddress("2001:db8:1::1")),
@@ -713,7 +650,7 @@ TEST_F(HostTest, addReservations) {
     IPv6ResrvRange prefixes = host->getIPv6Reservations(IPv6Resrv::TYPE_PD);
     ASSERT_EQ(2, std::distance(prefixes.first, prefixes.second));
     EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_PD,
-                                            IOAddress("2001:db8:1:1::"), AuthKey("key##2"), 64),
+                                            IOAddress("2001:db8:1:1::"), 64),
                                   prefixes));
     EXPECT_TRUE(reservationExists(IPv6Resrv(IPv6Resrv::TYPE_PD,
                                             IOAddress("2001:db8:1:2::"), 64),
@@ -743,6 +680,7 @@ TEST_F(HostTest, setValues) {
     host->setNextServer(IOAddress("192.0.2.2"));
     host->setServerHostname("server-hostname.example.org");
     host->setBootFileName("bootfile.efi");
+    host->setKey(AuthKey("random-value"));
     std::string user_context = "{ \"foo\": \"bar\" }";
     host->setContext(Element::fromJSON(user_context));
     host->setNegative(true);
@@ -754,6 +692,7 @@ TEST_F(HostTest, setValues) {
     EXPECT_EQ("192.0.2.2", host->getNextServer().toText());
     EXPECT_EQ("server-hostname.example.org", host->getServerHostname());
     EXPECT_EQ("bootfile.efi", host->getBootFileName());
+    EXPECT_EQ("random-value", host->getKey().ToText());
     ASSERT_TRUE(host->getContext());
     EXPECT_EQ(user_context, host->getContext()->str());
     EXPECT_TRUE(host->getNegative());
@@ -1039,6 +978,7 @@ TEST_F(HostTest, toText) {
               " siaddr=(no)"
               " sname=(empty)"
               " file=(empty)"
+              " key=(empty)"
               " ipv6_reservation0=2001:db8:1::cafe"
               " ipv6_reservation1=2001:db8:1::1"
               " ipv6_reservation2=2001:db8:1:1::/64"
@@ -1056,6 +996,7 @@ TEST_F(HostTest, toText) {
               " siaddr=(no)"
               " sname=(empty)"
               " file=(empty)"
+              " key=(empty)"
               " ipv6_reservation0=2001:db8:1::cafe"
               " ipv6_reservation1=2001:db8:1::1"
               " ipv6_reservation2=2001:db8:1:1::/64"
@@ -1074,6 +1015,7 @@ TEST_F(HostTest, toText) {
               " siaddr=(no)"
               " sname=(empty)"
               " file=(empty)"
+              " key=(empty)"
               " ipv6_reservations=(none)", host->toText());
 
     // Add some classes.
@@ -1084,6 +1026,7 @@ TEST_F(HostTest, toText) {
               " siaddr=(no)"
               " sname=(empty)"
               " file=(empty)"
+              " key=(empty)"
               " ipv6_reservations=(none)"
               " dhcp4_class0=modem dhcp4_class1=router",
               host->toText());
@@ -1096,6 +1039,7 @@ TEST_F(HostTest, toText) {
               " siaddr=(no)"
               " sname=(empty)"
               " file=(empty)"
+              " key=(empty)"
               " ipv6_reservations=(none)"
               " dhcp4_class0=modem dhcp4_class1=router"
               " dhcp6_class0=hub dhcp6_class1=device",
@@ -1103,7 +1047,6 @@ TEST_F(HostTest, toText) {
 }
 
 // This test checks that Host object is correctly unparsed,
-// @todo: add support for keys
 TEST_F(HostTest, unparse) {
     boost::scoped_ptr<Host> host;
     ASSERT_NO_THROW(host.reset(new Host("01:02:03:04:05:06", "hw-address",
@@ -1275,6 +1218,21 @@ TEST_F(HostTest, hostId) {
     EXPECT_EQ(12345, host->getHostId());
 }
 
+// Tets verifies if we can modify the host keys.
+TEST_F(HostTest, keys) {
+    HostPtr host;
+    ASSERT_NO_THROW(host.reset(new Host("01:02:03:04:05:06", "hw-address",
+                                        SubnetID(1), SubnetID(2),
+                                        IOAddress("192.0.2.3"),
+                                        "myhost.example.com")));
+//Key must be empty
+    EXPECT_EQ(0,host->getKey().ToText().length());
+
+    //now set to random value 
+    host->setKey(AuthKey("random_key"));
+    EXPECT_EQ("random_key", host->getKey().ToText());
+}
+
 // Test verifies if getRandomKeyString can generate  1000 keys which are random
 TEST_F(HostTest, randomKeys) {
     //use hashtable and set size to 1000
index 29c2b9a279e7bca3501acc236d07decd61ee1bdc..22044afc0bd415312c80698578d8185002750b5a 100644 (file)
@@ -706,7 +706,7 @@ GenericHostDataSourceTest::testSubnetId6(int subnets, Host::IdentifierType id) {
     for (int i = 0; i < subnets; ++i) {
         // Last boolean value set to false indicates that the same identifier
         // must be used for each generated host.
-        host = HostDataSourceUtils::initializeHost6(current_address.toText(), id, true, "", false);
+        host = HostDataSourceUtils::initializeHost6(current_address.toText(), id, true, false, "");
 
         host->setIPv4SubnetID(i + 1000);
         host->setIPv6SubnetID(i + 1000);
@@ -801,10 +801,10 @@ GenericHostDataSourceTest::testGetBySubnetIPv6() {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a couple of hosts...
-    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8:1::", Host::IDENT_DUID, true, "key##1");
-    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8:2::", Host::IDENT_DUID, true, "key##2");
-    HostPtr host3 = HostDataSourceUtils::initializeHost6("2001:db8:3::", Host::IDENT_DUID, true, "key##3");
-    HostPtr host4 = HostDataSourceUtils::initializeHost6("2001:db8:4::", Host::IDENT_DUID, true, "key##4");
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8:1::", Host::IDENT_DUID, true);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8:2::", Host::IDENT_DUID, true);
+    HostPtr host3 = HostDataSourceUtils::initializeHost6("2001:db8:3::", Host::IDENT_DUID, true);
+    HostPtr host4 = HostDataSourceUtils::initializeHost6("2001:db8:4::", Host::IDENT_DUID, true);
 
     // ... and add them to the data source.
     ASSERT_NO_THROW(hdsptr_->add(host1));
@@ -893,11 +893,10 @@ GenericHostDataSourceTest::testAddr6AndPrefix() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservations with prefix reservation (prefix = true)
-    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID,
-                                                        true, "key##1", true);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
 
     // Create IPv6 reservation (for an address) and add it to the host
-    IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::2"), AuthKey("key##2"), 128);
+    IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::2"), 128);
     host->addReservation(resv);
 
     // Add this reservation
@@ -925,10 +924,10 @@ GenericHostDataSourceTest::testMultipleReservations() {
     HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
 
     // Add some reservations
-    IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), AuthKey("key##1"), len);
-    IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), AuthKey("key##2"), len);
-    IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), AuthKey("key##3"), len);
-    IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), AuthKey("key##4"), len);
+    IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
+    IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), len);
+    IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), len);
+    IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), len);
 
     host->addReservation(resv1);
     host->addReservation(resv2);
@@ -952,14 +951,14 @@ GenericHostDataSourceTest::testMultipleReservationsDifferentOrder() {
     ASSERT_TRUE(hdsptr_);
     uint8_t len = 128;
 
-    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
-    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false, "key##1");
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false, "key##1");
 
     // Add some reservations
-    IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), AuthKey("key##1"), len);
-    IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), AuthKey("key##2"), len);
-    IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), AuthKey("key##3"), len);
-    IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), AuthKey("key##4"), len);
+    IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
+    IPv6Resrv resv2(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::7"), len);
+    IPv6Resrv resv3(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::8"), len);
+    IPv6Resrv resv4(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::9"), len);
 
     host1->addReservation(resv1);
     host1->addReservation(resv2);
@@ -1251,10 +1250,7 @@ GenericHostDataSourceTest::stressTest(unsigned int nOfHosts /* = 0xfffdU */) {
         ss >> n_host;
 
         const std::string prefix = std::string("2001:db8::") + n_host;
-        const std::string keys = 
-            std::string("arbitary_long_enough_for_stress_test"
-                        "but_less_than_128_characters");
-        hosts.push_back(HostDataSourceUtils::initializeHost6(prefix, Host::IDENT_HWADDR, false, keys));
+        hosts.push_back(HostDataSourceUtils::initializeHost6(prefix, Host::IDENT_HWADDR, false, "key##1"));
         
         IPv6ResrvRange range = hosts.back()->getIPv6Reservations();
         ASSERT_EQ(1, std::distance(range.first, range.second));
index 093f1b99a3dd1327544b5a9fe933f24cfa676efa..85b2cad6202f21480ba30dc092eb8083c4bffa5d 100644 (file)
@@ -84,8 +84,8 @@ HostPtr
 HostDataSourceUtils::initializeHost6(const std::string address,
                                      Host::IdentifierType identifier,
                                      bool prefix,
-                                     const std::string& key,
-                                     bool new_identifier) {
+                                     bool new_identifier,
+                                     const std::string auth_key) {
     std::vector<uint8_t> ident;
     switch (identifier) {
     case Host::IDENT_HWADDR:
@@ -107,16 +107,20 @@ HostDataSourceUtils::initializeHost6(const std::string address,
     ++subnet4;
     ++subnet6;
 
+    std::string default_string;
     HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6,
-                          IOAddress("0.0.0.0")));
+                          IOAddress("0.0.0.0"), default_string,
+                          default_string, default_string,
+                           asiolink:: IOAddress::IPV4_ZERO_ADDRESS(), default_string, default_string,
+                          AuthKey(auth_key)));
 
     if (!prefix) {
         // Create IPv6 reservation (for an address)
-        IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), AuthKey(key), 128);
+        IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), 128);
         host->addReservation(resv);
     } else {
         // Create IPv6 reservation for a /64 prefix
-        IPv6Resrv resv(IPv6Resrv::TYPE_PD, IOAddress(address), AuthKey(key), 64);
+        IPv6Resrv resv(IPv6Resrv::TYPE_PD, IOAddress(address), 64);
         host->addReservation(resv);
     }
     return (host);
@@ -225,6 +229,7 @@ HostDataSourceUtils::compareHosts(const ConstHostPtr& host1,
     EXPECT_EQ(host1->getNextServer(), host2->getNextServer());
     EXPECT_EQ(host1->getServerHostname(), host2->getServerHostname());
     EXPECT_EQ(host1->getBootFileName(), host2->getBootFileName());
+    EXPECT_TRUE(host1->getKey() == host2->getKey());
     ConstElementPtr ctx1 = host1->getContext();
     ConstElementPtr ctx2 = host2->getContext();
     if (ctx1) {
index 1b5251c75123173e6fac01876296323368492c5e..7b1b7789dbaaed6a0acacede386cd2c098d1435e 100644 (file)
@@ -39,7 +39,7 @@ public:
     ///
     /// @return generated Host object
     static HostPtr initializeHost6(const std::string address, Host::IdentifierType id,
-                                   bool prefix, const std::string& key = "", bool new_identifier = true);
+                                   bool prefix, bool new_identifier = true, const std::string key = "");
 
     /// @brief Generates a hardware address in text version.
     ///
index 272cd9a5b453a77473590badabb67ea6d1673919..bdb74b2d7c81a6870f9bdea5453be7267e346ad1 100644 (file)
@@ -294,7 +294,7 @@ CREATE TABLE IF NOT EXISTS logs (
 CREATE INDEX IF NOT EXISTS logsindex ON logs (address);
 
 -- Add new field.
-ALTER TABLE host_reservations ADD reserved_auth_key text;
+ALTER TABLE host_reservations ADD auth_key text;
 
 -- Cql requires primary keys in the WHERE here.
 DELETE FROM schema_version WHERE version=2;
index ce27222044e289bc51b038bf9bef7ef497662625..e9e0abba204536b9ae1e7a323f38ce3f2670ae12 100644 (file)
@@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS logs (
 CREATE INDEX IF NOT EXISTS logsindex ON logs (address);
 
 -- Cql requires primary keys in the WHERE here.
-ALTER TABLE host_reservations ADD reserved_auth_key text;
+ALTER TABLE host_reservations ADD auth_key text;
 
 DELETE FROM schema_version WHERE version=2;
 INSERT INTO schema_version (version, minor) VALUES(3, 0);
index a4dceceb9f9796826081313a7118da7fbda7d2f8..ab9153705b24045b5ab8b53de24372c3bfb721f8 100644 (file)
@@ -765,7 +765,7 @@ CREATE TABLE logs (
 CREATE INDEX timestamp_index ON logs (timestamp);
 
 #add auth key for reconfiguration
-ALTER TABLE ipv6_reservations 
+ALTER TABLE hosts  
     ADD COLUMN auth_key VARCHAR(16) NULL; 
 
 # Update the schema version number
index 79bff19a9a3b372643319fd0db5405fcf38281d6..99f56f9dd765cecb44721396fce07a2f78e53d58 100644 (file)
@@ -103,7 +103,7 @@ CREATE TABLE logs (
 CREATE INDEX timestamp_index ON logs (timestamp);
 
 #add auth key for reconfiguration
-ALTER TABLE ipv6_reservation
+ALTER TABLE host
     ADD COLUMN auth_key VARCHAR(16) NULL; 
 
 # Update the schema version number
index 517a18f9c757266b669047c00568dc79bb745bf8..168f8bd0df33a3c5c00c48e03d3ec7e58ae4ab2c 100644 (file)
@@ -868,7 +868,7 @@ CREATE INDEX timestamp_id ON logs (timestamp);
 CREATE INDEX address_id ON logs (address);
 
 -- Create auth_key in ipv6_reservations
-ALTER TABLE ipv6_reservations ADD COLUMN auth_key  VARCHAR(26) DEFAULT NULL;
+ALTER TABLE hosts ADD COLUMN auth_key  VARCHAR(16) DEFAULT NULL;
 
 -- Set schema 5.0 version
 UPDATE schema_version
index 13f9bb2337e92ecf820c36ca9dd5aef4ba247392..88a7b7d65b75ad9e51314c1ec5302079e172263a 100644 (file)
@@ -134,7 +134,7 @@ CREATE INDEX timestamp_id ON logs (timestamp);
 CREATE INDEX address_id ON logs (address);
 
 -- Create auth_key in ipv6_reservations
-ALTER TABLE ipv6_reservations ADD COLUMN auth_key  VARCHAR(16) DEFAULT NULL;
+ALTER TABLE hosts ADD COLUMN auth_key  VARCHAR(16) DEFAULT NULL;
 
 -- Set 5.0 schema version.
 UPDATE schema_version