]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2843] Added more test cases
authorMarcin Siodelski <marcin@isc.org>
Mon, 8 May 2023 08:49:01 +0000 (10:49 +0200)
committerMarcin Siodelski <marcin@isc.org>
Fri, 12 May 2023 11:02:03 +0000 (13:02 +0200)
src/bin/dhcp4/tests/shared_network_unittest.cc
src/bin/dhcp6/tests/shared_network_unittest.cc

index 05e1aaab4965fbd2f0577c7b92418e005ead832a..35e10ccf5621ddc23dac32a83075b1bb31e8404b 100644 (file)
@@ -1092,6 +1092,44 @@ const char* NETWORKS_CONFIG[] = {
     "            ]"
     "        }"
     "    ]"
+    "}",
+// Configuration #22
+// - a shared network with two subnets
+// - first subnet uses the random allocator
+// - second subnet uses the FLQ allocator
+    "{"
+    "    \"interfaces-config\": {"
+    "        \"interfaces\": [ \"*\" ]"
+    "    },"
+    "    \"valid-lifetime\": 600,"
+    "    \"shared-networks\": ["
+    "        {"
+    "            \"name\": \"frog\","
+    "            \"relay\": {"
+    "                \"ip-address\": \"192.3.5.6\""
+    "            },"
+    "            \"subnet4\": ["
+    "                {"
+    "                    \"subnet\": \"192.0.2.0/24\","
+    "                    \"allocator\": \"random\","
+    "                    \"pools\": ["
+    "                        {"
+    "                            \"pool\": \"192.0.2.1 - 192.0.2.10\""
+    "                        }"
+    "                    ]"
+    "                },"
+    "                {"
+    "                    \"subnet\": \"192.0.3.0/24\","
+    "                    \"allocator\": \"flq\","
+    "                    \"pools\": ["
+    "                        {"
+    "                            \"pool\": \"192.0.3.1 - 192.0.3.10\""
+    "                        }"
+    "                    ]"
+    "                }"
+    "            ]"
+    "        }"
+    "    ]"
     "}"
 };
 
@@ -1398,6 +1436,48 @@ public:
         return (cfg);
     }
 
+    // @brief Test that different allocator types can be used within a shared network.
+    //
+    // All available addresses should be assigned from the subnets belonging to
+    // the shared network.
+    //
+    /// @param config server configuration that should contain a shared network with
+    /// two subnets. Each subnet should contain an address pool with 10 addresses.
+    void testDifferentAllocatorsInNetwork(const std::string& config) {
+        // Create the base client and server configuration.
+        Dhcp4Client client(Dhcp4Client::SELECTING);
+        configure(config, *client.getServer());
+
+        // Record what addresses have been allocated.
+        std::set<std::string> allocated_set;
+
+        // Simulate allocations from different clients.
+        for (auto i = 0; i < 20; ++i) {
+            // Create a client from the base client.
+            Dhcp4Client next_client(client.getServer(), Dhcp4Client::SELECTING);
+            next_client.useRelay(true, IOAddress("192.3.5.6"), IOAddress("10.0.0.2"));
+            // Run 4-way exchange.
+            ASSERT_NO_THROW(next_client.doDORA());
+            // Make sure that the server responded.
+            ASSERT_TRUE(next_client.getContext().response_);
+            // Make sure that the server has responded with DHCPACK.
+            ASSERT_EQ(DHCPACK, static_cast<int>(next_client.getContext().response_->getType()));
+            // Make sure that the address is not zero.
+            ASSERT_FALSE(next_client.config_.lease_.addr_.isV4Zero());
+            // Remember allocated address uniqueness.
+            allocated_set.insert(next_client.config_.lease_.addr_.toText());
+        }
+        // Make sure that we have 20 distinct allocations.
+        ASSERT_EQ(20, allocated_set.size());
+
+        // Try one more time. This time no leases should be allocated because
+        // the pools are exhausted.
+        Dhcp4Client next_client(client.getServer(), Dhcp4Client::SELECTING);
+        next_client.useRelay(true, IOAddress("192.3.5.6"), IOAddress("10.0.0.2"));
+        ASSERT_NO_THROW(next_client.doDiscover());
+        EXPECT_FALSE(next_client.getContext().response_);
+    }
+
     /// @brief Destructor.
     virtual ~Dhcpv4SharedNetworkTest() {
         StatsMgr::instance().removeAll();
@@ -2913,34 +2993,17 @@ TEST_F(Dhcpv4SharedNetworkTest, authoritative) {
 }
 
 // Test that different allocator types can be used within a shared network.
-// All available addresses should be assigned from the subnets belonging to
-// the shared network.
+// The first subnet uses the random allocator. The second subnet uses the FLQ
+// allocator.
 TEST_F(Dhcpv4SharedNetworkTest, randomAndFlqAllocation) {
-    // Create the base client and server configuration.
-    Dhcp4Client client(Dhcp4Client::SELECTING);
-    configure(NETWORKS_CONFIG[21], *client.getServer());
-
-    // Record what addresses have been allocated.
-    std::set<std::string> allocated_set;
+    testDifferentAllocatorsInNetwork(NETWORKS_CONFIG[21]);
+}
 
-    // Simulate allocations from different clients.
-    for (auto i = 0; i < 20; ++i) {
-        // Create a client from the base client.
-        Dhcp4Client next_client(client.getServer(), Dhcp4Client::SELECTING);
-        next_client.useRelay(true, IOAddress("192.3.5.6"), IOAddress("10.0.0.2"));
-        // Run 4-way exchange.
-        ASSERT_NO_THROW(next_client.doDORA());
-        // Make sure that the server responded.
-        ASSERT_TRUE(next_client.getContext().response_);
-        // Make sure that the server has responded with DHCPACK.
-        ASSERT_EQ(DHCPACK, static_cast<int>(next_client.getContext().response_->getType()));
-        // Make sure that the address is not zero.
-        ASSERT_FALSE(next_client.config_.lease_.addr_.isV4Zero());
-        // Remember allocated address uniqueness.
-        allocated_set.insert(next_client.config_.lease_.addr_.toText());
-    }
-    // Make sure that we have 20 distinct allocations.
-    ASSERT_EQ(20, allocated_set.size());
+// Test that different allocator types can be used within a shared network.
+// The first subnet uses the FLQ allocator. The second subnet uses the random
+// allocator.
+TEST_F(Dhcpv4SharedNetworkTest, flqAndRandomAllocation) {
+    testDifferentAllocatorsInNetwork(NETWORKS_CONFIG[22]);
 }
 
 } // end of anonymous namespace
index 17c09b9cacc643ed0dafc830a4de79ab68453faf..81e8db37e09c2f596f2d11d754fbafbbe25f9ec1 100644 (file)
@@ -1138,6 +1138,42 @@ const char* NETWORKS_CONFIG[] = {
     "            ]"
     "        }"
     "    ]"
+    "}",
+// Configuration #24.
+// - a shared network with two subnets
+// - first subnet uses the random allocator
+// - second subnet uses the FLQ allocator
+    "{"
+    "    \"shared-networks\": ["
+    "        {"
+    "            \"name\": \"frog\","
+    "            \"interface\": \"eth1\","
+    "            \"subnet6\": ["
+    "                {"
+    "                    \"subnet\": \"2001:db8:1::/64\","
+    "                    \"pd-allocator\": \"random\","
+    "                    \"pd-pools\": ["
+    "                        {"
+    "                            \"prefix\": \"2001:db8:1::\","
+    "                            \"prefix-len\": 64,"
+    "                            \"delegated-len\": 68"
+    "                        }"
+    "                    ]"
+    "                },"
+    "                {"
+    "                    \"subnet\": \"2001:db8:2::/64\","
+    "                    \"pd-allocator\": \"flq\","
+    "                    \"pd-pools\": ["
+    "                        {"
+    "                            \"prefix\": \"2001:db8:2::\","
+    "                            \"prefix-len\": 64,"
+    "                            \"delegated-len\": 68"
+    "                        }"
+    "                    ]"
+    "                }"
+    "            ]"
+    "        }"
+    "    ]"
     "}"
 };
 
@@ -1525,6 +1561,52 @@ public:
         EXPECT_EQ(ns_address, addrs[0].toText());
     }
 
+    // @brief Test that different allocator types can be used within a shared network.
+    //
+    // All available prefixes should be delegated from the subnets belonging to
+    // the shared network.
+    //
+    /// @param config server configuration that should contain a shared network with
+    /// two subnets. Each subnet should contain a prefix pool with 16 prefixes.
+    void testDifferentAllocatorsInNetwork(const std::string& config) {
+        // Create the base client and server configuration.
+        Dhcp6Client client;
+        ASSERT_NO_FATAL_FAILURE(configure(config, *client.getServer()));
+
+        // Record what prefixes have been allocated.
+        std::set<std::string> allocated_set;
+
+        // Simulate allocations from different clients.
+        for (auto i = 0; i < 32; ++i) {
+            // Create a client from the base client.
+            Dhcp6Client next_client(client.getServer());
+            next_client.setInterface("eth1");
+            next_client.requestPrefix();
+            // Run 4-way exchange.
+            ASSERT_NO_THROW(next_client.doSARR());
+            // Make sure that the server responded.
+            ASSERT_TRUE(next_client.getContext().response_);
+            auto leases = next_client.getLeasesByType(Lease::TYPE_PD);
+            ASSERT_EQ(1, leases.size());
+            // Make sure that the prefix is not zero.
+            ASSERT_FALSE(leases[0].addr_.isV6Zero());
+            // Remember the allocated prefix uniqueness.
+            allocated_set.insert(leases[0].addr_.toText());
+        }
+        // Make sure that we have 32 distinct allocations.
+        ASSERT_EQ(32, allocated_set.size());
+
+        // Try one more time. This time no leases should be allocated because
+        // the pools are exhausted.
+        Dhcp6Client next_client(client.getServer());
+        next_client.setInterface("eth1");
+        next_client.requestPrefix();
+        ASSERT_NO_THROW(next_client.doSARR());
+        ASSERT_TRUE(next_client.getContext().response_);
+        auto leases = next_client.getLeasesByType(Lease::TYPE_PD);
+        EXPECT_TRUE(leases.empty());
+    }
+
     /// @brief Destructor.
     virtual ~Dhcpv6SharedNetworkTest() {
         StatsMgr::instance().removeAll();
@@ -2534,37 +2616,18 @@ TEST_F(Dhcpv6SharedNetworkTest, poolInSubnetSelectedByClass) {
 }
 
 // Test that different allocator types can be used within a shared network.
-// All available prefixes should be delegated from the subnets belonging to
-// the shared network.
+// The first subnet uses the random allocator. The second subnet uses the FLQ
+// allocator.
 TEST_F(Dhcpv6SharedNetworkTest, randomAndFlqAllocation) {
-    // Create the base client and server configuration.
-    Dhcp6Client client;
-    ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[23], *client.getServer()));
-
-    // Record what prefixes have been allocated.
-    std::set<std::string> allocated_set;
-
-    // Simulate allocations from different clients.
-    for (auto i = 0; i < 32; ++i) {
-        // Create a client from the base client.
-        Dhcp6Client next_client(client.getServer());
-        next_client.setInterface("eth1");
-        next_client.requestPrefix();
-        // Run 4-way exchange.
-        ASSERT_NO_THROW(next_client.doSARR());
-        // Make sure that the server responded.
-        ASSERT_TRUE(next_client.getContext().response_);
-        auto leases = next_client.getLeasesByType(Lease::TYPE_PD);
-        ASSERT_EQ(1, leases.size());
-        // Make sure that the prefix is not zero.
-        ASSERT_FALSE(leases[0].addr_.isV6Zero());
-        // Remember the allocated prefix uniqueness.
-        allocated_set.insert(leases[0].addr_.toText());
-    }
-    // Make sure that we have 32 distinct allocations.
-    ASSERT_EQ(32, allocated_set.size());
+    testDifferentAllocatorsInNetwork(NETWORKS_CONFIG[23]);
 }
 
+// Test that different allocator types can be used within a shared network.
+// The first subnet uses the FLQ allocator. The second subnet uses the random
+// allocator.
+TEST_F(Dhcpv6SharedNetworkTest, flqAndRandomAllocation) {
+    testDifferentAllocatorsInNetwork(NETWORKS_CONFIG[24]);
+}
 
 // Verify option processing precedence
 // Order is global < class < shared-network < subnet < pools < host reservation