Commit 5cf78daf authored by Marcin Siodelski's avatar Marcin Siodelski

[#451,!227] Store "unspecified" triplets as NULL in the MySQL DB.

parent f09ebc33
...@@ -356,11 +356,11 @@ public: ...@@ -356,11 +356,11 @@ public:
std::string subnet_prefix = out_bindings[1]->getString(); std::string subnet_prefix = out_bindings[1]->getString();
auto prefix_pair = Subnet4::parsePrefix(subnet_prefix); auto prefix_pair = Subnet4::parsePrefix(subnet_prefix);
// renew_timer // renew_timer
uint32_t renew_timer = out_bindings[13]->getIntegerOrDefault<uint32_t>(0); auto renew_timer = createTriplet(out_bindings[13]);
// rebind_timer // rebind_timer
uint32_t rebind_timer = out_bindings[11]->getIntegerOrDefault<uint32_t>(0); auto rebind_timer = createTriplet(out_bindings[11]);
// valid_lifetime // valid_lifetime
uint32_t valid_lifetime = out_bindings[19]->getIntegerOrDefault<uint32_t>(0); auto valid_lifetime = createTriplet(out_bindings[19]);
// Create subnet with basic settings. // Create subnet with basic settings.
last_subnet.reset(new Subnet4(prefix_pair.first, prefix_pair.second, last_subnet.reset(new Subnet4(prefix_pair.first, prefix_pair.second,
...@@ -778,15 +778,15 @@ public: ...@@ -778,15 +778,15 @@ public:
MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(subnet->getMatchClientId())), MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(subnet->getMatchClientId())),
MySqlBinding::createTimestamp(subnet->getModificationTime()), MySqlBinding::createTimestamp(subnet->getModificationTime()),
MySqlBinding::condCreateInteger<uint32_t>(subnet->getSiaddr().toUint32()), MySqlBinding::condCreateInteger<uint32_t>(subnet->getSiaddr().toUint32()),
MySqlBinding::createInteger<uint32_t>(subnet->getT2()), createBinding(subnet->getT2()),
createInputRelayBinding(subnet), createInputRelayBinding(subnet),
MySqlBinding::createInteger<uint32_t>(subnet->getT1()), createBinding(subnet->getT1()),
createInputRequiredClassesBinding(subnet), createInputRequiredClassesBinding(subnet),
MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(subnet->getHostReservationMode())), MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(subnet->getHostReservationMode())),
MySqlBinding::condCreateString(subnet->getSname()), MySqlBinding::condCreateString(subnet->getSname()),
shared_network_binding, shared_network_binding,
createInputContextBinding(subnet), createInputContextBinding(subnet),
MySqlBinding::createInteger<uint32_t>(subnet->getValid()) createBinding(subnet->getValid())
}; };
MySqlTransaction transaction(conn_); MySqlTransaction transaction(conn_);
...@@ -1027,7 +1027,7 @@ public: ...@@ -1027,7 +1027,7 @@ public:
// rebind_timer // rebind_timer
if (!out_bindings[6]->amNull()) { if (!out_bindings[6]->amNull()) {
last_network->setT2(out_bindings[6]->getInteger<uint32_t>()); last_network->setT2(createTriplet(out_bindings[6]));
} }
// relay // relay
...@@ -1048,7 +1048,7 @@ public: ...@@ -1048,7 +1048,7 @@ public:
// renew_timer // renew_timer
if (!out_bindings[8]->amNull()) { if (!out_bindings[8]->amNull()) {
last_network->setT1(out_bindings[8]->getInteger<uint32_t>()); last_network->setT1(createTriplet(out_bindings[8]));
} }
// require_client_classes // require_client_classes
...@@ -1080,7 +1080,7 @@ public: ...@@ -1080,7 +1080,7 @@ public:
// valid_lifetime // valid_lifetime
if (!out_bindings[12]->amNull()) { if (!out_bindings[12]->amNull()) {
last_network->setValid(out_bindings[12]->getInteger<uint32_t>()); last_network->setValid(createTriplet(out_bindings[12]));
} }
shared_networks.push_back(last_network); shared_networks.push_back(last_network);
...@@ -1187,14 +1187,14 @@ public: ...@@ -1187,14 +1187,14 @@ public:
MySqlBinding::condCreateString(shared_network->getIface()), MySqlBinding::condCreateString(shared_network->getIface()),
MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(shared_network->getMatchClientId())), MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(shared_network->getMatchClientId())),
MySqlBinding::createTimestamp(shared_network->getModificationTime()), MySqlBinding::createTimestamp(shared_network->getModificationTime()),
MySqlBinding::condCreateInteger<uint32_t>(shared_network->getT2()), createBinding(shared_network->getT2()),
createInputRelayBinding(shared_network), createInputRelayBinding(shared_network),
MySqlBinding::condCreateInteger<uint32_t>(shared_network->getT1()), createBinding(shared_network->getT1()),
createInputRequiredClassesBinding(shared_network), createInputRequiredClassesBinding(shared_network),
MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t> MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>
(shared_network->getHostReservationMode())), (shared_network->getHostReservationMode())),
createInputContextBinding(shared_network), createInputContextBinding(shared_network),
MySqlBinding::condCreateInteger<uint32_t>(shared_network->getValid()) createBinding(shared_network->getValid())
}; };
MySqlTransaction transaction(conn_); MySqlTransaction transaction(conn_);
......
...@@ -86,6 +86,28 @@ MySqlConfigBackendImpl::~MySqlConfigBackendImpl() { ...@@ -86,6 +86,28 @@ MySqlConfigBackendImpl::~MySqlConfigBackendImpl() {
} }
} }
MySqlBindingPtr
MySqlConfigBackendImpl::createBinding(const Triplet<uint32_t>& triplet) const {
if (triplet.unspecified()) {
return (MySqlBinding::createNull());
}
return (MySqlBinding::createInteger<uint32_t>(triplet.get()));
}
Triplet<uint32_t>
MySqlConfigBackendImpl::createTriplet(const MySqlBindingPtr& binding) const {
if (!binding) {
isc_throw(Unexpected, "MySQL configuration backend internal error: "
"binding is NULL when creating a triplet value");
}
if (binding->amNull()) {
return (Triplet<uint32_t>());
}
return (Triplet<uint32_t>(binding->getInteger<uint32_t>()));
}
void void
MySqlConfigBackendImpl::createAuditRevision(const int index, MySqlConfigBackendImpl::createAuditRevision(const int index,
const ServerSelector& server_selector, const ServerSelector& server_selector,
......
...@@ -106,6 +106,25 @@ public: ...@@ -106,6 +106,25 @@ public:
/// @brief Destructor. /// @brief Destructor.
~MySqlConfigBackendImpl(); ~MySqlConfigBackendImpl();
/// @brief Creates MySQL binding from a @c Triplet.
///
/// @param triplet Triplet value from which the binding should be created.
/// @return Pointer to a null binding if the triplet is "unspecified" or
/// a pointer to a binding representing 32-bit unsigned integer value
/// otherwise.
db::MySqlBindingPtr createBinding(const Triplet<uint32_t>& triplet) const;
/// @brief Creates @c Triplet object from MySQL binding.
///
/// @param binding Pointer to the MySQL binding.
/// @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.
/// @throw isc::Unexpected if the provided binding pointer is NULL.
/// @throw isc::InvalidOperation if the binding does not represent
/// a 32-bit unsigned integer.
Triplet<uint32_t> createTriplet(const db::MySqlBindingPtr& binding) const;
/// @brief Returns server tags associated with the particular selector. /// @brief Returns server tags associated with the particular selector.
/// ///
/// @param server_selector Server selector. /// @param server_selector Server selector.
......
...@@ -152,6 +152,10 @@ public: ...@@ -152,6 +152,10 @@ public:
test_subnets_.push_back(subnet); test_subnets_.push_back(subnet);
subnet.reset(new Subnet4(IOAddress("192.0.3.0"), 24, 20, 30, 40, 2048)); subnet.reset(new Subnet4(IOAddress("192.0.3.0"), 24, 20, 30, 40, 2048));
Triplet<uint32_t> null_timer;
subnet->setT1(null_timer);
subnet->setT2(null_timer);
subnet->setValid(null_timer);
test_subnets_.push_back(subnet); test_subnets_.push_back(subnet);
subnet.reset(new Subnet4(IOAddress("192.0.4.0"), 24, 30, 40, 60, 4096)); subnet.reset(new Subnet4(IOAddress("192.0.4.0"), 24, 30, 40, 60, 4096));
...@@ -200,6 +204,10 @@ public: ...@@ -200,6 +204,10 @@ public:
// Add more shared networks. // Add more shared networks.
shared_network.reset(new SharedNetwork4("level2")); shared_network.reset(new SharedNetwork4("level2"));
Triplet<uint32_t> null_timer;
shared_network->setT1(null_timer);
shared_network->setT2(null_timer);
shared_network->setValid(null_timer);
test_networks_.push_back(shared_network); test_networks_.push_back(shared_network);
shared_network.reset(new SharedNetwork4("level3")); shared_network.reset(new SharedNetwork4("level3"));
......
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