Commit 0f4cd4d6 authored by Marcin Siodelski's avatar Marcin Siodelski

[#93,!35] Shared network name is now associated with subnet.

parent 3c33e8db
......@@ -232,6 +232,8 @@ public:
(out_bindings[15]->getIntegerOrDefault<uint8_t>(Subnet4::HR_ALL)));
// server_hostname
last_subnet->setSname(out_bindings[16]->getStringOrDefault(""));
// shared_network_name
last_subnet->setSharedNetworkName(out_bindings[17]->getStringOrDefault(""));
// user_context
ElementPtr user_context = out_bindings[18]->getJSON();
if (user_context) {
......
......@@ -88,7 +88,6 @@ public:
subnet->setHostReservationMode(Subnet4::HR_DISABLED);
subnet->setSname("server-hostname");
subnet->setContext(user_context);
// shared-network?
subnet->setValid(555555);
Pool4Ptr pool1(new Pool4(IOAddress("192.0.2.10"), IOAddress("192.0.2.20")));
......@@ -231,6 +230,35 @@ TEST_F(MySqlConfigBackendDHCPv4Test, getSubnet4) {
EXPECT_EQ(subnet2->toElement()->str(), returned_subnet->toElement()->str());
}
// Test that subnet can be associated with a shared network.
TEST_F(MySqlConfigBackendDHCPv4Test, getSubnet4SharedNetwork) {
Subnet4Ptr subnet = test_subnets_[0];
SharedNetwork4Ptr shared_network = test_networks_[0];
// Add subnet to a shared network.
shared_network->add(subnet);
// Store shared network in the database.
cbptr_->createUpdateSharedNetwork4(ServerSelector::UNASSIGNED(),
shared_network);
// Store subnet associated with the shared network in the database.
cbptr_->createUpdateSubnet4(ServerSelector::UNASSIGNED(), subnet);
// Fetch this subnet by subnet identifier.
Subnet4Ptr returned_subnet = cbptr_->getSubnet4(ServerSelector::UNASSIGNED(),
test_subnets_[0]->getID());
ASSERT_TRUE(returned_subnet);
// The easiest way to verify whether the returned subnet matches the inserted
// subnet is to convert both to text.
EXPECT_EQ(subnet->toElement()->str(), returned_subnet->toElement()->str());
// However, the check above doesn't verify whether shared network name was
// correctly returned from the database.
EXPECT_EQ(shared_network->getName(), returned_subnet->getSharedNetworkName());
}
// Test that subnet can be fetched by prefix.
TEST_F(MySqlConfigBackendDHCPv4Test, getSubnet4ByPrefix) {
// Insert subnet to the database.
......
......@@ -267,6 +267,29 @@ private:
shared_network_ = shared_network;
}
public:
/// @brief Returns shared network name.
std::string getSharedNetworkName() const {
return (shared_network_name_);
}
/// @brief Sets new shared network name.
///
/// In certain cases the subnet must be associated with the shared network
/// but the shared network object is not available. In particular, subnets
/// are returned from the configuration database with only names of the
/// shared networks. The actual shared networks must be fetched from the
/// database using a separate query. In order to not loose associations
/// of subnets with shared networks, the configuration backends will use
/// this method to store the shared network names. The servers will later
/// use those names to associate subnets with shared network instances.
///
/// @param shared_network_name New shared network name.
void setSharedNetworkName(const std::string& shared_network_name) {
shared_network_name_ = shared_network_name;
}
protected:
/// @brief Returns all pools (non-const variant)
///
......@@ -423,6 +446,9 @@ protected:
/// @brief Pointer to a shared network that subnet belongs to.
WeakNetworkPtr shared_network_;
/// @brief Shared network name.
std::string shared_network_name_;
};
/// @brief A generic pointer to either Subnet4 or Subnet6 object
......
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