Browse Source

[master] Merge branch 'trac5366'

# Conflicts:
#	src/bin/dhcp6/tests/shared_network_unittest.cc
Marcin Siodelski 7 years ago
parent
commit
112addd461
1 changed files with 123 additions and 4 deletions
  1. 123 4
      src/bin/dhcp6/tests/shared_network_unittest.cc

+ 123 - 4
src/bin/dhcp6/tests/shared_network_unittest.cc

@@ -831,7 +831,65 @@ const char* NETWORKS_CONFIG[] = {
     "    ]"
     "}",
 
-// Configuration #16
+// Configuration #16.
+// - one shared network with three subnets, each with different option value
+    "{"
+    "    \"shared-networks\": ["
+    "        {"
+    "            \"name\": \"frog\","
+    "            \"interface\": \"eth1\","
+    "            \"subnet6\": ["
+    "                {"
+    "                    \"subnet\": \"2001:db8:1::/64\","
+    "                    \"id\": 10,"
+    "                    \"option-data\": ["
+    "                        {"
+    "                            \"name\": \"dns-servers\","
+    "                            \"data\": \"4004::22\""
+    "                        }"
+    "                    ],"
+    "                    \"pools\": ["
+    "                        {"
+    "                            \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
+    "                        }"
+    "                    ]"
+    "                },"
+    "                {"
+    "                    \"subnet\": \"2001:db8:2::/64\","
+    "                    \"id\": 100,"
+    "                    \"option-data\": ["
+    "                        {"
+    "                            \"name\": \"dns-servers\","
+    "                            \"data\": \"5555::33\""
+    "                        }"
+    "                    ],"
+    "                    \"pools\": ["
+    "                        {"
+    "                            \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
+    "                        }"
+    "                    ]"
+    "                },"
+    "                {"
+    "                    \"subnet\": \"2001:db8:3::/64\","
+    "                    \"id\": 1000,"
+    "                    \"option-data\": ["
+    "                        {"
+    "                            \"name\": \"dns-servers\","
+    "                            \"data\": \"1234::23\""
+    "                        }"
+    "                    ],"
+    "                    \"pools\": ["
+    "                        {"
+    "                            \"pool\": \"2001:db8:3::20 - 2001:db8:3::20\""
+    "                        }"
+    "                    ]"
+    "                }"
+    "            ]"
+    "        }"
+    "    ]"
+    "}",
+
+// Configuration #17.
 // - one shared network with two subnets, both have rapid-commit enabled
     "{"
     "    \"shared-networks\": ["
@@ -865,7 +923,7 @@ const char* NETWORKS_CONFIG[] = {
     "}",
 
 
-// Configuration #17:
+// Configuration #18.
 // - one shared network with rapid-commit enabled
 // - two subnets (which should derive the rapid-commit setting)
     "{"
@@ -1678,6 +1736,67 @@ TEST_F(Dhcpv6SharedNetworkTest, optionsDerivation) {
     ASSERT_TRUE(client3.hasOptionWithAddress(D6O_NISP_SERVERS, "4000::5"));
 }
 
+// The same option is specified differently for each subnet belonging to the
+// same shared network.
+TEST_F(Dhcpv6SharedNetworkTest, optionsFromSelectedSubnet) {
+    // Create a client.
+    Dhcp6Client client;
+    client.setInterface("eth1");
+
+    // Create configuration with one shared network including three subnets with
+    // the same option having different values.
+    ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[16], *client.getServer()));
+
+    // Client provides no hint and any subnet can be picked from the shared network.
+    ASSERT_NO_THROW(client.requestAddress(0xabca));
+
+    // Request Name Servers option.
+    ASSERT_NO_THROW(client.requestOption(D6O_NAME_SERVERS));
+
+    // Send solicit without a hint. The client should be offerred an address from the
+    // shared network. Depending on the subnet from which the address has been allocated
+    // a specific value of the Name Servers option should be returned.
+    testAssigned([this, &client] {
+        ASSERT_NO_THROW(client.doSolicit(true));
+    });
+
+    if (client.hasLeaseForAddress(IOAddress("2001:db8:1::20"))) {
+        ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "4004::22"));
+
+    } else if (client.hasLeaseForAddress(IOAddress("2001:db8:2::20"))) {
+        ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
+
+    } else if (client.hasLeaseForAddress(IOAddress("2001:db8:3::20"))) {
+        ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "1234::23"));
+    }
+
+    // This time let's provide a hint.
+    client.clearRequestedIAs();
+    client.requestAddress(0xabca, IOAddress("2001:db8:2::20"));
+
+    testAssigned([this, &client] {
+        ASSERT_NO_THROW(client.doSolicit(true));
+    });
+
+    ASSERT_TRUE(client.hasLeaseForAddress(IOAddress("2001:db8:2::20")));
+    ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
+
+    // This time, let's do the 4-way exchange.
+    testAssigned([this, &client] {
+        ASSERT_NO_THROW(client.doSARR());
+    });
+
+    ASSERT_TRUE(client.hasLeaseForAddress(IOAddress("2001:db8:2::20")));
+    ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
+
+    // And renew the lease.
+    testAssigned([this, &client] {
+        ASSERT_NO_THROW(client.doRenew());
+    });
+    ASSERT_TRUE(client.hasLeaseForAddress(IOAddress("2001:db8:2::20")));
+    ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
+}
+
 // Different shared network is selected for different local interface.
 TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectionByInterface) {
     // Create client #1. The server receives requests from this client
@@ -2027,14 +2146,14 @@ TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectedByInterfaceIdInSubnet) {
 // Check that the rapid-commit works with shared networks. Rapid-commit
 // enabled on each subnet separately.
 TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkRapidCommit1) {
-    testRapidCommit(NETWORKS_CONFIG[16], true, "2001:db8:1::20", "2001:db8:2::20");
+    testRapidCommit(NETWORKS_CONFIG[17], true, "2001:db8:1::20", "2001:db8:2::20");
 }
 
 // Check that the rapid-commit works with shared networks. Rapid-commit
 // enabled for the whole shared network. This should be applied to both
 // subnets.
 TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkRapidCommit2) {
-    testRapidCommit(NETWORKS_CONFIG[17], true, "2001:db8:1::20", "2001:db8:2::20");
+    testRapidCommit(NETWORKS_CONFIG[18], true, "2001:db8:1::20", "2001:db8:2::20");
 }
 
 // Check that the rapid-commit is disabled by default.