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")));
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.
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)
///
/// @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