Commit 83023a67 authored by Francis Dupont's avatar Francis Dupont
Browse files

[295-min-max-lease-time-configuration-options] Checkpoint: updated MySQL...

[295-min-max-lease-time-configuration-options] Checkpoint: updated MySQL schema and CB hook - tests to add
parent f7f545ae
......@@ -285,6 +285,8 @@ public:
MySqlBinding::createInteger<float>(), // t1_percent
MySqlBinding::createInteger<float>(), // t2_percent
MySqlBinding::createInteger<uint8_t>(), // authoritative
MySqlBinding::createInteger<uint32_t>(), // min_valid_lifetime
MySqlBinding::createInteger<uint32_t>(), // max_valid_lifetime
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
......@@ -324,8 +326,10 @@ public:
auto renew_timer = createTriplet(out_bindings[13]);
// rebind_timer
auto rebind_timer = createTriplet(out_bindings[11]);
// valid_lifetime
auto valid_lifetime = createTriplet(out_bindings[19]);
// valid_lifetime (and {min,max)_valid_lifetime)
auto valid_lifetime = createTriplet(out_bindings[19],
out_bindings[53],
out_bindings[54]);
// Create subnet with basic settings.
last_subnet = Subnet4::create(prefix_pair.first, prefix_pair.second,
......@@ -453,8 +457,10 @@ public:
last_subnet->setAuthoritative(out_bindings[52]->getBool());
}
// {min,max}_valid_lifetime
// server_tag
last_subnet->setServerTag(out_bindings[53]->getString());
last_subnet->setServerTag(out_bindings[55]->getString());
// Subnet ready. Add it to the list.
auto ret = subnets.push_back(last_subnet);
......@@ -819,6 +825,8 @@ public:
shared_network_binding,
createInputContextBinding(subnet),
createBinding(subnet->getValid(Network::Inheritance::NONE)),
createMinBinding(subnet->getValid(Network::Inheritance::NONE)),
createMaxBinding(subnet->getValid(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(subnet->getT1Percent(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)),
......@@ -1033,6 +1041,8 @@ public:
MySqlBinding::createString(BOOT_FILE_NAME_BUF_LENGTH), // boot_file_name
MySqlBinding::createInteger<uint32_t>(), // next_server
MySqlBinding::createString(SERVER_HOSTNAME_BUF_LENGTH), // server_hostname
MySqlBinding::createInteger<uint32_t>(), // min_valid_lifetime
MySqlBinding::createInteger<uint32_t>(), // max_valid_lifetime
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
......@@ -1129,9 +1139,11 @@ public:
last_network->setContext(user_context);
}
// valid_lifetime
// valid_lifetime (and {min,max)_valid_lifetime)
if (!out_bindings[12]->amNull()) {
last_network->setValid(createTriplet(out_bindings[12]));
last_network->setValid(createTriplet(out_bindings[12],
out_bindings[32],
out_bindings[33]));
}
// calculate_tee_times
......@@ -1164,13 +1176,15 @@ public:
last_network->setSiaddr(IOAddress(out_bindings[30]->getInteger<uint32_t>()));
}
// server_hostaname
// server_hostname
if (!out_bindings[31]->amNull()) {
last_network->setSname(out_bindings[31]->getString());
}
// {min,max}_valid_lifetime
// server_tag
last_network->setServerTag(out_bindings[32]->getString());
last_network->setServerTag(out_bindings[34]->getString());
// Add the shared network.
auto ret = shared_networks.push_back(last_network);
......@@ -1301,6 +1315,8 @@ public:
hr_mode_binding,
createInputContextBinding(shared_network),
createBinding(shared_network->getValid(Network::Inheritance::NONE)),
createMinBinding(shared_network->getValid(Network::Inheritance::NONE)),
createMaxBinding(shared_network->getValid(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(shared_network->getCalculateTeeTimes(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(shared_network->getT1Percent(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(shared_network->getT2Percent(Network::Inheritance::NONE)),
......@@ -2049,11 +2065,13 @@ TaggedStatementArray tagged_statements = { {
" shared_network_name,"
" user_context,"
" valid_lifetime,"
" min_valid_lifetime,"
" max_valid_lifetime,"
" calculate_tee_times,"
" t1_percent,"
" t2_percent,"
" authoritative"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the subnet with a server.
......@@ -2081,6 +2099,8 @@ TaggedStatementArray tagged_statements = { {
" reservation_mode,"
" user_context,"
" valid_lifetime,"
" min_valid_lifetime,"
" max_valid_lifetime,"
" calculate_tee_times,"
" t1_percent,"
" t2_percent,"
......@@ -2088,7 +2108,8 @@ TaggedStatementArray tagged_statements = { {
" boot_file_name,"
" next_server,"
" server_hostname"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
" ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the shared network with a server.
{ MySqlConfigBackendDHCPv4Impl::INSERT_SHARED_NETWORK4_SERVER,
......@@ -2143,6 +2164,8 @@ TaggedStatementArray tagged_statements = { {
" shared_network_name = ?,"
" user_context = ?,"
" valid_lifetime = ?,"
" min_valid_lifetime = ?,"
" max_valid_lifetime = ?,"
" calculate_tee_times = ?,"
" t1_percent = ?,"
" t2_percent = ?,"
......@@ -2164,6 +2187,8 @@ TaggedStatementArray tagged_statements = { {
" reservation_mode = ?,"
" user_context = ?,"
" valid_lifetime = ?,"
" min_valid_lifetime = ?,"
" max_valid_lifetime = ?,"
" calculate_tee_times = ?,"
" t1_percent = ?,"
" t2_percent = ?,"
......
......@@ -308,6 +308,10 @@ public:
MySqlBinding::createInteger<float>(), // t1_percent
MySqlBinding::createInteger<float>(), // t2_percent
MySqlBinding::createBlob(INTERFACE_ID_BUF_LENGTH), // interface_id
MySqlBinding::createInteger<uint32_t>(), // min_preferred_lifetime
MySqlBinding::createInteger<uint32_t>(), // max_preferred_lifetime
MySqlBinding::createInteger<uint32_t>(), // min_valid_lifetime
MySqlBinding::createInteger<uint32_t>(), // max_valid_lifetime
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
......@@ -351,8 +355,10 @@ public:
std::string subnet_prefix = out_bindings[1]->getString();
auto prefix_pair = Subnet6::parsePrefix(subnet_prefix);
// preferred_lifetime
auto preferred_lifetime = createTriplet(out_bindings[5]);
// preferred_lifetime (and {min,max)_preferred_lifetime)
auto preferred_lifetime = createTriplet(out_bindings[5],
out_bindings[69],
out_bindings[70]);
// renew_timer
auto renew_timer = createTriplet(out_bindings[9]);
......@@ -360,8 +366,10 @@ public:
// rebind_timer
auto rebind_timer = createTriplet(out_bindings[7]);
// valid_lifetime
auto valid_lifetime = createTriplet(out_bindings[14]);
// valid_lifetime (and {min,max)_valid_lifetime)
auto valid_lifetime = createTriplet(out_bindings[14],
out_bindings[71],
out_bindings[72]);
// Create subnet with basic settings.
last_subnet = Subnet6::create(prefix_pair.first, prefix_pair.second,
......@@ -469,8 +477,12 @@ public:
}
}
// 69 and 70 are {min,max}_preferred_lifetime
// 71 and 72 are {min,max}_valid_lifetime
// server_tag
last_subnet->setServerTag(out_bindings[69]->getString());
last_subnet->setServerTag(out_bindings[73]->getString());
// Subnet ready. Add it to the list.
auto ret = subnets.push_back(last_subnet);
......@@ -947,6 +959,8 @@ public:
MySqlBinding::condCreateString(subnet->getIface(Network::Inheritance::NONE)),
MySqlBinding::createTimestamp(subnet->getModificationTime()),
createBinding(subnet->getPreferred(Network::Inheritance::NONE)),
createMinBinding(subnet->getPreferred(Network::Inheritance::NONE)),
createMaxBinding(subnet->getPreferred(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(subnet->getRapidCommit(Network::Inheritance::NONE)),
createBinding(subnet->getT2(Network::Inheritance::NONE)),
createInputRelayBinding(subnet),
......@@ -956,6 +970,8 @@ public:
shared_network_binding,
createInputContextBinding(subnet),
createBinding(subnet->getValid(Network::Inheritance::NONE)),
createMinBinding(subnet->getValid(Network::Inheritance::NONE)),
createMaxBinding(subnet->getValid(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(subnet->getT1Percent(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)),
......@@ -1224,6 +1240,10 @@ public:
MySqlBinding::createInteger<float>(), // t1_percent
MySqlBinding::createInteger<float>(), // t2_percent
MySqlBinding::createBlob(INTERFACE_ID_BUF_LENGTH), // interface_id
MySqlBinding::createInteger<uint32_t>(), // min_preferred_lifetime
MySqlBinding::createInteger<uint32_t>(), // max_preferred_lifetime
MySqlBinding::createInteger<uint32_t>(), // min_valid_lifetime
MySqlBinding::createInteger<uint32_t>(), // max_valid_lifetime
MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag
};
......@@ -1260,9 +1280,11 @@ public:
// modification_ts
last_network->setModificationTime(out_bindings[4]->getTimestamp());
// preferred_lifetime
// preferred_lifetime (and {min,max)_preferred_lifetime)
if (!out_bindings[5]->amNull()) {
last_network->setPreferred(createTriplet(out_bindings[5]));
last_network->setPreferred(createTriplet(out_bindings[5],
out_bindings[31],
out_bindings[32]));
}
// rapid_commit
......@@ -1325,9 +1347,11 @@ public:
last_network->setContext(user_context);
}
// valid_lifetime
// valid_lifetime (and {min,max)_valid_lifetime)
if (!out_bindings[13]->amNull()) {
last_network->setValid(createTriplet(out_bindings[13]));
last_network->setValid(createTriplet(out_bindings[13],
out_bindings[33],
out_bindings[34]));
}
// calculate_tee_times
......@@ -1355,8 +1379,12 @@ public:
}
}
// {min,max)_preferred_lifetime
// {min,max)_valid_lifetime
// server_tag
last_network->setServerTag(out_bindings[31]->getString());
last_network->setServerTag(out_bindings[35]->getString());
// Add the shared network.
auto ret = shared_networks.push_back(last_network);
......@@ -1491,6 +1519,8 @@ public:
MySqlBinding::condCreateString(shared_network->getIface(Network::Inheritance::NONE)),
MySqlBinding::createTimestamp(shared_network->getModificationTime()),
createBinding(shared_network->getPreferred(Network::Inheritance::NONE)),
createMinBinding(shared_network->getPreferred(Network::Inheritance::NONE)),
createMaxBinding(shared_network->getPreferred(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(shared_network->getRapidCommit(Network::Inheritance::NONE)),
createBinding(shared_network->getT2(Network::Inheritance::NONE)),
createInputRelayBinding(shared_network),
......@@ -1499,6 +1529,8 @@ public:
hr_mode_binding,
createInputContextBinding(shared_network),
createBinding(shared_network->getValid(Network::Inheritance::NONE)),
createMinBinding(shared_network->getValid(Network::Inheritance::NONE)),
createMaxBinding(shared_network->getValid(Network::Inheritance::NONE)),
MySqlBinding::condCreateBool(shared_network->getCalculateTeeTimes(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(shared_network->getT1Percent(Network::Inheritance::NONE)),
MySqlBinding::condCreateFloat(shared_network->getT2Percent(Network::Inheritance::NONE)),
......@@ -2367,6 +2399,8 @@ TaggedStatementArray tagged_statements = { {
" interface,"
" modification_ts,"
" preferred_lifetime,"
" min_preferred_lifetime,"
" max_preferred_lifetime,"
" rapid_commit,"
" rebind_timer,"
" relay,"
......@@ -2376,11 +2410,14 @@ TaggedStatementArray tagged_statements = { {
" shared_network_name,"
" user_context,"
" valid_lifetime,"
" min_valid_lifetime,"
" max_valid_lifetime,"
" calculate_tee_times,"
" t1_percent,"
" t2_percent,"
" interface_id"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
" ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the subnet with a server.
{ MySqlConfigBackendDHCPv6Impl::INSERT_SUBNET6_SERVER,
......@@ -2405,6 +2442,8 @@ TaggedStatementArray tagged_statements = { {
" interface,"
" modification_ts,"
" preferred_lifetime,"
" min_preferred_lifetime,"
" max_preferred_lifetime,"
" rapid_commit,"
" rebind_timer,"
" relay,"
......@@ -2413,11 +2452,14 @@ TaggedStatementArray tagged_statements = { {
" reservation_mode,"
" user_context,"
" valid_lifetime,"
" min_valid_lifetime,"
" max_valid_lifetime,"
" calculate_tee_times,"
" t1_percent,"
" t2_percent,"
" interface_id"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
" ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" },
// Insert association of the shared network with a server.
{ MySqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6_SERVER,
......@@ -2458,6 +2500,8 @@ TaggedStatementArray tagged_statements = { {
" interface = ?,"
" modification_ts = ?,"
" preferred_lifetime = ?,"
" min_preferred_lifetime = ?,"
" max_preferred_lifetime = ?,"
" rapid_commit = ?,"
" rebind_timer = ?,"
" relay = ?,"
......@@ -2467,6 +2511,8 @@ TaggedStatementArray tagged_statements = { {
" shared_network_name = ?,"
" user_context = ?,"
" valid_lifetime = ?,"
" min_valid_lifetime = ?,"
" max_valid_lifetime = ?,"
" calculate_tee_times = ?,"
" t1_percent = ?,"
" t2_percent = ?,"
......@@ -2481,6 +2527,8 @@ TaggedStatementArray tagged_statements = { {
" interface = ?,"
" modification_ts = ?,"
" preferred_lifetime = ?,"
" min_preferred_lifetime = ?,"
" max_preferred_lifetime = ?,"
" rapid_commit = ?,"
" rebind_timer = ?,"
" relay = ?,"
......@@ -2489,6 +2537,8 @@ TaggedStatementArray tagged_statements = { {
" reservation_mode = ?,"
" user_context = ?,"
" valid_lifetime = ?,"
" min_valid_lifetime = ?,"
" max_valid_lifetime = ?,"
" calculate_tee_times = ?,"
" t1_percent = ?,"
" t2_percent = ?,"
......
......@@ -91,6 +91,22 @@ MySqlConfigBackendImpl::createBinding(const Triplet<uint32_t>& triplet) {
return (MySqlBinding::createInteger<uint32_t>(triplet.get()));
}
MySqlBindingPtr
MySqlConfigBackendImpl::createMinBinding(const Triplet<uint32_t>& triplet) {
if (triplet.unspecified() || (triplet.getMin() == triplet.get())) {
return (MySqlBinding::createNull());
}
return (MySqlBinding::createInteger<uint32_t>(triplet.getMin()));
}
MySqlBindingPtr
MySqlConfigBackendImpl::createMaxBinding(const Triplet<uint32_t>& triplet) {
if (triplet.unspecified() || (triplet.getMax() == triplet.get())) {
return (MySqlBinding::createNull());
}
return (MySqlBinding::createInteger<uint32_t>(triplet.getMax()));
}
Triplet<uint32_t>
MySqlConfigBackendImpl::createTriplet(const MySqlBindingPtr& binding) {
if (!binding) {
......@@ -105,6 +121,34 @@ MySqlConfigBackendImpl::createTriplet(const MySqlBindingPtr& binding) {
return (Triplet<uint32_t>(binding->getInteger<uint32_t>()));
}
Triplet<uint32_t>
MySqlConfigBackendImpl::createTriplet(const MySqlBindingPtr& def_binding,
const MySqlBindingPtr& min_binding,
const MySqlBindingPtr& max_binding) {
if (!def_binding || !min_binding || !max_binding) {
isc_throw(Unexpected, "MySQL configuration backend internal error: "
"binding pointer is NULL when creating a triplet value");
}
// This code assumes the database was filled using the API, e.g. it
// is not possible (so not handled) to have only the min_binding not NULL.
if (def_binding->amNull()) {
return (Triplet<uint32_t>());
}
uint32_t value = def_binding->getInteger<uint32_t>();
uint32_t min_value = value;
if (!min_binding->amNull()) {
min_value = min_binding->getInteger<uint32_t>();
}
uint32_t max_value = value;
if (!max_binding->amNull()) {
max_value = max_binding->getInteger<uint32_t>();
}
return (Triplet<uint32_t>(min_value, value, max_value));
}
void
MySqlConfigBackendImpl::createAuditRevision(const int index,
const ServerSelector& server_selector,
......
......@@ -117,6 +117,24 @@ public:
/// otherwise.
static db::MySqlBindingPtr createBinding(const Triplet<uint32_t>& triplet);
/// @brief Creates MySQL binding from a @c Triplet max value.
///
/// @param triplet Triplet value from which the binding should be created.
/// @return Pointer to a null binding if the triplet is "unspecified" or
/// the max value is the same than the default value, or a pointer to
/// a binding representing 32-bit unsigned integer value from the max
/// value otherwise.
static db::MySqlBindingPtr createMaxBinding(const Triplet<uint32_t>& triplet);
/// @brief Creates MySQL binding from a @c Triplet min value.
///
/// @param triplet Triplet value from which the binding should be created.
/// @return Pointer to a null binding if the triplet is "unspecified" or
/// the min value is the same than the default value, or a pointer to
/// a binding representing 32-bit unsigned integer value from the min
/// value otherwise.
static db::MySqlBindingPtr createMinBinding(const Triplet<uint32_t>& triplet);
/// @brief Creates @c Triplet object from MySQL binding.
///
/// @param binding Pointer to the MySQL binding.
......@@ -128,6 +146,22 @@ public:
/// a 32-bit unsigned integer.
static Triplet<uint32_t> createTriplet(const db::MySqlBindingPtr& binding);
/// @brief Creates @c Triplet object from MySQL bindings.
///
/// @param def_binding Pointer to the MySQL binding of the default.
/// @param min_binding Pointer to the MySQL binding of the min value.
/// @param max_binding Pointer to the MySQL binding of the max value.
/// @return Triplet value set to "unspecified" if the MySQL binding
/// represents a NULL value or a Triplet value encapsulating 32-bit
/// unsigned integer if the MySQL represents an integer.
/// When max or max bindings are not NULL their values are used.
/// @throw isc::Unexpected if the provided binding pointer is NULL.
/// @throw isc::InvalidOperation if the binding does not represent
/// a 32-bit unsigned integer.
static Triplet<uint32_t> createTriplet(const db::MySqlBindingPtr& def_binding,
const db::MySqlBindingPtr& min_binding,
const db::MySqlBindingPtr& max_binding);
/// @brief Returns server tags associated with the particular selector.
///
/// @param server_selector Server selector.
......
......@@ -104,6 +104,8 @@ namespace {
" s.t1_percent," \
" s.t2_percent," \
" s.authoritative," \
" s.min_valid_lifetime," \
" s.max_valid_lifetime," \
" srv.tag " \
"FROM dhcp4_subnet AS s " \
"INNER JOIN dhcp4_subnet_server AS a " \
......@@ -189,6 +191,10 @@ namespace {
" s.t1_percent," \
" s.t2_percent," \
" s.interface_id," \
" s.min_preferred_lifetime," \
" s.max_preferred_lifetime," \
" s.min_valid_lifetime," \
" s.max_valid_lifetime," \
" srv.tag " \
"FROM dhcp6_subnet AS s " \
"INNER JOIN dhcp6_subnet_server AS a " \
......@@ -239,6 +245,8 @@ namespace {
" n.boot_file_name," \
" n.next_server," \
" n.server_hostname," \
" n.min_valid_lifetime," \
" n.max_valid_lifetime," \
" s.tag " \
"FROM dhcp4_shared_network AS n " \
"INNER JOIN dhcp4_shared_network_server AS a " \
......@@ -284,6 +292,10 @@ namespace {
" n.t1_percent," \
" n.t2_percent," \
" n.interface_id," \
" n.min_preferred_lifetime," \
" n.max_preferred_lifetime," \
" n.min_valid_lifetime," \
" n.max_valid_lifetime," \
" s.tag " \
"FROM dhcp6_shared_network AS n " \
"INNER JOIN dhcp6_shared_network_server AS a " \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment