count=$(echo "${OUTPUT}" | grep -Fci reservation) || true
assert_eq 0 "${count}" "dhcp6_subnet has still reservation_mode column. (returned count %d, expected %d)"
+ # table: dhcp4_shared_network new cache_threshold and cache_max_age columns
+ qry="select cache_threshold, cache_max_age from dhcp4_shared_network"
+ run_statement "dhcp4_shared_network" "$qry"
+
+ # table: dhcp4_subnet new cache_threshold and cache_max_age columns
+ qry="select cache_threshold, cache_max_age from dhcp4_subnet"
+ run_statement "dhcp4_shared_network" "$qry"
+
+ # table: dhcp6_shared_network new cache_threshold and cache_max_age columns
+ qry="select cache_threshold, cache_max_age from dhcp6_shared_network"
+ run_statement "dhcp6_shared_network" "$qry"
+
+ # table: dhcp6_subnet new cache_threshold and cache_max_age columns
+ qry="select cache_threshold, cache_max_age from dhcp6_subnet"
+ run_statement "dhcp6_shared_network" "$qry"
+
# Verify upgraded schema reports version 9.5
version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "9.5" "${version}" "Expected kea-admin to return %s, returned value was %s"
MySqlBinding::createString(DNS_NAME_BUF_LENGTH), // ddns_qualifying_suffix
MySqlBinding::createInteger<uint8_t>(), // reservations_in_subnet
MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
+ MySqlBinding::createInteger<float>(), // cache_threshold
+ MySqlBinding::createInteger<uint32_t>(), // cache_max_age
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
last_subnet->setReservationsOutOfPool(out_bindings[65]->getBool());
}
- // server_tag at 66.
+ // cache_threshold at 66.
+ if (!out_bindings[66]->amNull()) {
+ last_subnet->setCacheThreshold(out_bindings[66]->getFloat());
+ }
+
+ // cache_max_age at 67.
+ if (!out_bindings[67]->amNull()) {
+ last_subnet->setCacheMaxAge(out_bindings[67]->getInteger<uint32_t>());
+ }
+
+ // server_tag at 68.
// Subnet ready. Add it to the list.
auto ret = subnets.insert(last_subnet);
}
}
- // Check for new server tags at 66.
- if (!out_bindings[66]->amNull() &&
- (last_tag != out_bindings[66]->getString())) {
- last_tag = out_bindings[66]->getString();
+ // Check for new server tags at 68.
+ if (!out_bindings[68]->amNull() &&
+ (last_tag != out_bindings[68]->getString())) {
+ last_tag = out_bindings[68]->getString();
if (!last_tag.empty() && !last_subnet->hasServerTag(ServerTag(last_tag))) {
last_subnet->setServerTag(last_tag);
}
MySqlBinding::condCreateString(subnet->getDdnsGeneratedPrefix(Network::Inheritance::NONE)),
MySqlBinding::condCreateString(subnet->getDdnsQualifyingSuffix(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(subnet->getReservationsInSubnet(Network::Inheritance::NONE)),
- MySqlBinding::condCreateBool(subnet->getReservationsOutOfPool(Network::Inheritance::NONE))
+ MySqlBinding::condCreateBool(subnet->getReservationsOutOfPool(Network::Inheritance::NONE)),
+ MySqlBinding::condCreateFloat(subnet->getCacheThreshold(Network::Inheritance::NONE)),
+ condCreateInteger<uint32_t>(subnet->getCacheMaxAge(Network::Inheritance::NONE))
};
MySqlTransaction transaction(conn_);
MySqlBinding::createString(DNS_NAME_BUF_LENGTH), // ddns_qualifying_suffix
MySqlBinding::createInteger<uint8_t>(), // reservations_in_subnet
MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
+ MySqlBinding::createInteger<float>(), // cache_threshold
+ MySqlBinding::createInteger<uint32_t>(), // cache_max_age
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
last_network->setReservationsOutOfPool(out_bindings[41]->getBool());
}
- // server_tag at 42.
+ // cache_threshold at 42.
+ if (!out_bindings[42]->amNull()) {
+ last_network->setCacheThreshold(out_bindings[42]->getFloat());
+ }
+
+ // cache_max_age at 43.
+ if (!out_bindings[43]->amNull()) {
+ last_network->setCacheMaxAge(out_bindings[43]->getInteger<uint32_t>());
+ }
+
+ // server_tag at 44.
// Add the shared network.
auto ret = shared_networks.push_back(last_network);
}
// Check for new server tags.
- if (!out_bindings[42]->amNull() &&
- (last_tag != out_bindings[42]->getString())) {
- last_tag = out_bindings[42]->getString();
+ if (!out_bindings[44]->amNull() &&
+ (last_tag != out_bindings[44]->getString())) {
+ last_tag = out_bindings[44]->getString();
if (!last_tag.empty() && !last_network->hasServerTag(ServerTag(last_tag))) {
last_network->setServerTag(last_tag);
}
MySqlBinding::condCreateString(shared_network->getDdnsGeneratedPrefix(Network::Inheritance::NONE)),
MySqlBinding::condCreateString(shared_network->getDdnsQualifyingSuffix(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(shared_network->getReservationsInSubnet(Network::Inheritance::NONE)),
- MySqlBinding::condCreateBool(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE))
+ MySqlBinding::condCreateBool(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE)),
+ MySqlBinding::condCreateFloat(shared_network->getCacheThreshold(Network::Inheritance::NONE)),
+ condCreateInteger<uint32_t>(shared_network->getCacheMaxAge(Network::Inheritance::NONE))
};
MySqlTransaction transaction(conn_);
" ddns_generated_prefix,"
" ddns_qualifying_suffix,"
" reservations_in_subnet,"
- " reservations_out_of_pool"
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
- "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
+ " reservations_out_of_pool,"
+ " cache_threshold,"
+ " cache_max_age"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the subnet with a server.
{ MySqlConfigBackendDHCPv4Impl::INSERT_SUBNET4_SERVER,
" ddns_generated_prefix,"
" ddns_qualifying_suffix,"
" reservations_in_subnet,"
- " reservations_out_of_pool"
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
+ " reservations_out_of_pool,"
+ " cache_threshold,"
+ " cache_max_age"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
" ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the shared network with a server.
" ddns_generated_prefix = ?,"
" ddns_qualifying_suffix = ?,"
" reservations_in_subnet = ?,"
- " reservations_out_of_pool = ? "
+ " reservations_out_of_pool = ?,"
+ " cache_threshold = ?,"
+ " cache_max_age = ? "
"WHERE subnet_id = ? OR subnet_prefix = ?" },
// Update existing shared network.
" ddns_generated_prefix = ?,"
" ddns_qualifying_suffix = ?,"
" reservations_in_subnet = ?,"
- " reservations_out_of_pool = ? "
+ " reservations_out_of_pool = ?,"
+ " cache_threshold = ?,"
+ " cache_max_age = ? "
"WHERE name = ?" },
// Update existing option definition.
MySqlBinding::createString(DNS_NAME_BUF_LENGTH), // ddns_qualifying_suffix
MySqlBinding::createInteger<uint8_t>(), // reservations_in_subnet
MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
+ MySqlBinding::createInteger<float>(), // cache_threshold
+ MySqlBinding::createInteger<uint32_t>(), // cache_max_age
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
last_subnet->setReservationsOutOfPool(out_bindings[88]->getBool());
}
- // server_tag (89 / last)
+ // cache_threshold (89)
+ if (!out_bindings[89]->amNull()) {
+ last_subnet->setCacheThreshold(out_bindings[89]->getFloat());
+ }
+
+ // cache_max_age (90)
+ if (!out_bindings[90]->amNull()) {
+ last_subnet->setCacheMaxAge(out_bindings[90]->getInteger<uint32_t>());
+ }
+
+ // server_tag (91 / last)
// Subnet ready. Add it to the list.
auto ret = subnets.insert(last_subnet);
}
// Check for new server tags.
- if (!out_bindings[89]->amNull() &&
- (last_tag != out_bindings[89]->getString())) {
- last_tag = out_bindings[89]->getString();
+ if (!out_bindings[91]->amNull() &&
+ (last_tag != out_bindings[91]->getString())) {
+ last_tag = out_bindings[91]->getString();
if (!last_tag.empty() && !last_subnet->hasServerTag(ServerTag(last_tag))) {
last_subnet->setServerTag(last_tag);
}
MySqlBinding::condCreateString(subnet->getDdnsGeneratedPrefix(Network::Inheritance::NONE)),
MySqlBinding::condCreateString(subnet->getDdnsQualifyingSuffix(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(subnet->getReservationsInSubnet(Network::Inheritance::NONE)),
- MySqlBinding::condCreateBool(subnet->getReservationsOutOfPool(Network::Inheritance::NONE))
+ MySqlBinding::condCreateBool(subnet->getReservationsOutOfPool(Network::Inheritance::NONE)),
+ MySqlBinding::condCreateFloat(subnet->getCacheThreshold(Network::Inheritance::NONE)),
+ condCreateInteger<uint32_t>(subnet->getCacheMaxAge(Network::Inheritance::NONE))
};
MySqlTransaction transaction(conn_);
MySqlBinding::createString(DNS_NAME_BUF_LENGTH), // ddns_qualifying_suffix
MySqlBinding::createInteger<uint8_t>(), // reservations_in_subnet
MySqlBinding::createInteger<uint8_t>(), // reservations_out_of_pool
+ MySqlBinding::createInteger<float>(), // cache_threshold
+ MySqlBinding::createInteger<uint32_t>(), // cache_max_age
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
last_network->setReservationsOutOfPool(out_bindings[42]->getBool());
}
- // server_tag at 43.
+ // cache_threshold at 43.
+ if (!out_bindings[43]->amNull()) {
+ last_network->setCacheThreshold(out_bindings[43]->getFloat());
+ }
+
+ // cache_max_age at 44.
+ if (!out_bindings[44]->amNull()) {
+ last_network->setCacheMaxAge(out_bindings[44]->getInteger<uint32_t>());
+ }
+
+ // server_tag at 45.
// Add the shared network.
auto ret = shared_networks.push_back(last_network);
}
// Check for new server tags.
- if (!out_bindings[43]->amNull() &&
- (last_tag != out_bindings[43]->getString())) {
- last_tag = out_bindings[43]->getString();
+ if (!out_bindings[45]->amNull() &&
+ (last_tag != out_bindings[45]->getString())) {
+ last_tag = out_bindings[45]->getString();
if (!last_tag.empty() && !last_network->hasServerTag(ServerTag(last_tag))) {
last_network->setServerTag(last_tag);
}
MySqlBinding::condCreateString(shared_network->getDdnsGeneratedPrefix(Network::Inheritance::NONE)),
MySqlBinding::condCreateString(shared_network->getDdnsQualifyingSuffix(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(shared_network->getReservationsInSubnet(Network::Inheritance::NONE)),
- MySqlBinding::condCreateBool(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE))
+ MySqlBinding::condCreateBool(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE)),
+ MySqlBinding::condCreateFloat(shared_network->getCacheThreshold(Network::Inheritance::NONE)),
+ condCreateInteger<uint32_t>(shared_network->getCacheMaxAge(Network::Inheritance::NONE))
};
MySqlTransaction transaction(conn_);
" ddns_generated_prefix,"
" ddns_qualifying_suffix,"
" reservations_in_subnet,"
- " reservations_out_of_pool"
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
+ " reservations_out_of_pool,"
+ " cache_threshold,"
+ " cache_max_age"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
" ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the subnet with a server.
" ddns_generated_prefix,"
" ddns_qualifying_suffix,"
" reservations_in_subnet,"
- " reservations_out_of_pool"
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
+ " reservations_out_of_pool,"
+ " cache_threshold,"
+ " cache_max_age"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
" ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the shared network with a server.
" ddns_generated_prefix = ?,"
" ddns_qualifying_suffix = ?,"
" reservations_in_subnet = ?,"
- " reservations_out_of_pool = ? "
+ " reservations_out_of_pool = ?,"
+ " cache_threshold = ?,"
+ " cache_max_age = ? "
"WHERE subnet_id = ? OR subnet_prefix = ?" },
// Update existing shared network.
" ddns_generated_prefix = ?,"
" ddns_qualifying_suffix = ?,"
" reservations_in_subnet = ?,"
- " reservations_out_of_pool = ? "
+ " reservations_out_of_pool = ?,"
+ " cache_threshold = ?,"
+ " cache_max_age = ? "
"WHERE name = ?" },
// Update existing option definition.
/// @brief Destructor.
virtual ~MySqlConfigBackendImpl();
+ /// @brief Creates MySQL binding from an integer.
+ ///
+ /// @tparam T Numeric type corresponding to the binding type, e.g.
+ /// @c uint8_t, @c uint16_t etc.
+ /// @param value Optional integet of type T.
+ /// @return Pointer to a null binding if the value is "unspecified" or
+ /// a pointer to a binding representing integer value.
+ template<typename T>
+ static db::MySqlBindingPtr condCreateInteger(const util::Optional<T>& value) {
+ if (value.unspecified()) {
+ return (db::MySqlBinding::createNull());
+ }
+ return (db::MySqlBinding::createInteger(value));
+ }
+
/// @brief Creates MySQL binding from a @c Triplet.
///
/// @param triplet Triplet value from which the binding should be created.
" s.ddns_qualifying_suffix," \
" s.reservations_in_subnet," \
" s.reservations_out_of_pool," \
+ " s.cache_threshold," \
+ " s.cache_max_age," \
" srv.tag " \
"FROM dhcp4_subnet AS s " \
server_join \
" s.ddns_qualifying_suffix," \
" s.reservations_in_subnet," \
" s.reservations_out_of_pool," \
+ " s.cache_threshold," \
+ " s.cache_max_age," \
" srv.tag " \
"FROM dhcp6_subnet AS s " \
server_join \
" n.ddns_qualifying_suffix," \
" n.reservations_in_subnet," \
" n.reservations_out_of_pool," \
+ " n.cache_threshold," \
+ " n.cache_max_age," \
" s.tag " \
"FROM dhcp4_shared_network AS n " \
server_join \
" n.ddns_qualifying_suffix," \
" n.reservations_in_subnet," \
" n.reservations_out_of_pool," \
+ " n.cache_threshold," \
+ " n.cache_max_age," \
" s.tag " \
"FROM dhcp6_shared_network AS n " \
server_join \
}
// Got a lease for a reservation in this IA.
- return(true);
+ return;
}
}
uint32_t valid = 500;
subnet_->setValid(valid);
- // Set the threshold to 25%.
- subnet_->setCacheThreshold(.25);
+ // Set the threshold to 10%.
+ subnet_->setCacheThreshold(.10);
IOAddress addr("192.0.2.105");
time_t now = time(NULL) - 100; // Allocated 100 seconds ago.
uint32_t valid = 500;
subnet_->setValid(valid);
- // Set the threshold to 10%.
- subnet_->setCacheThreshold(.1);
+ // Set the threshold to 25%.
+ subnet_->setCacheThreshold(.25);
// Set the max age to 200.
subnet_->setCacheMaxAge(200);
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
// We're going to rollback the clock a little so we can verify a renewal.
- // We verify the "time" change in case the lease returned to us
- // by expectOneLease ever becomes a copy and not what is in the lease mgr.
--lease->cltt_;
- lease->updateCurrentExpirationTime();
- Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(lease->type_,
- lease->addr_);
- ASSERT_TRUE(from_mgr);
- EXPECT_EQ(from_mgr->cltt_, lease->cltt_);
+ EXPECT_NO_THROW(LeaseMgrFactory::instance().updateLease6(lease));
// This is what the client will send in his renew message.
AllocEngine::HintContainer hints;
EXPECT_EQ("2001:db8:1:2::", lease->addr_.toText());
// We're going to rollback the clock a little so we can verify a renewal.
- // We verify the "time" change in case the lease returned to us
- // by expectOneLease ever becomes a copy and not what is in the lease mgr.
--lease->cltt_;
- lease->updateCurrentExpirationTime();
- Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(lease->type_,
- lease->addr_);
- ASSERT_TRUE(from_mgr);
- EXPECT_EQ(from_mgr->cltt_, lease->cltt_);
+ EXPECT_NO_THROW(LeaseMgrFactory::instance().updateLease6(lease));
// This is what the client will send in his renew message.
AllocEngine::HintContainer hints;
EXPECT_EQ("2001:db8:1::1c", lease->addr_.toText());
// We're going to rollback the clock a little so we can verify a renewal.
- // We verify the "time" change in case the lease returned to us
- // by expectOneLease ever becomes a copy and not what is in the lease mgr.
--lease->cltt_;
- lease->updateCurrentExpirationTime();
- Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(lease->type_,
- lease->addr_);
- ASSERT_TRUE(from_mgr);
- EXPECT_EQ(from_mgr->cltt_, lease->cltt_);
+ EXPECT_NO_THROW(LeaseMgrFactory::instance().updateLease6(lease));
// This is what the client will send in his renew message.
AllocEngine::HintContainer hints;
EXPECT_EQ("2001:db8:1:2::", lease->addr_.toText());
// We're going to rollback the clock a little so we can verify a renewal.
- // We verify the "time" change in case the lease returned to us
- // by expectOneLease ever becomes a copy and not what is in the lease mgr.
--lease->cltt_;
- lease->updateCurrentExpirationTime();
- Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(lease->type_,
- lease->addr_);
- ASSERT_TRUE(from_mgr);
- EXPECT_EQ(from_mgr->cltt_, lease->cltt_);
+ EXPECT_NO_THROW(LeaseMgrFactory::instance().updateLease6(lease));
// This is what the client will send in his renew message.
AllocEngine::HintContainer hints;
ALTER TABLE dhcp6_subnet DROP COLUMN reservation_mode;
ALTER TABLE dhcp6_shared_network DROP COLUMN reservation_mode;
+# Add new lease cache parameters.
+ALTER TABLE dhcp4_subnet
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
+ALTER TABLE dhcp4_shared_network
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
+ALTER TABLE dhcp6_subnet
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
+ALTER TABLE dhcp6_shared_network
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '5';
# Enable audit in this session
SET @disable_audit = 0;
+# Add new lease cache parameters.
+ALTER TABLE dhcp4_subnet
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
+ALTER TABLE dhcp4_shared_network
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
+ALTER TABLE dhcp6_subnet
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
+ALTER TABLE dhcp6_shared_network
+ ADD COLUMN cache_threshold FLOAT DEFAULT NULL,
+ ADD COLUMN cache_max_age INT(10) DEFAULT NULL;
+
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '5';