]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#93,!35] Shared network name is now associated with subnet.
authorMarcin Siodelski <marcin@isc.org>
Fri, 5 Oct 2018 20:24:19 +0000 (22:24 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 8 Oct 2018 14:39:22 +0000 (16:39 +0200)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/lib/dhcpsrv/subnet.h

index af2512412d2c47289fda33a9f9f4494d9c80e548..bb3790c335323c3a5cf21fcc28d2bd3dbdb8f50a 100644 (file)
@@ -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) {
index 868ce8f43778634c89fd3c1335c11f444a17aba5..cd13eaffbe612854fec444e8974b722335ae0281 100644 (file)
@@ -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.
index 25af5ddeeddc0088fbb6ae807ee695c401003dfc..308c673b30e0fe0564d420126adf60c5205223df 100644 (file)
@@ -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