Browse Source

[4318] Added unit tests for reservations by DUID in DHCPv4.

Marcin Siodelski 9 years ago
parent
commit
32227e0933
1 changed files with 83 additions and 2 deletions
  1. 83 2
      src/bin/dhcp4/tests/dora_unittest.cc

+ 83 - 2
src/bin/dhcp4/tests/dora_unittest.cc

@@ -62,6 +62,9 @@ namespace {
 ///   - The same as configuration 2, but using different values in
 ///     'host-reservation-identifiers'
 ///
+/// - Configuration 5:
+///   - The same as configuration 4, but using different values in
+///     'host-reservation-identifiers'
 const char* DORA_CONFIGS[] = {
 // Configuration 0
     "{ \"interfaces-config\": {"
@@ -164,7 +167,33 @@ const char* DORA_CONFIGS[] = {
     "{ \"interfaces-config\": {"
         "      \"interfaces\": [ \"*\" ]"
         "},"
-        "\"host-reservation-identifiers\": [ \"circuit-id\", \"hw-address\" ],"
+        "\"host-reservation-identifiers\": [ \"circuit-id\", \"hw-address\", \"duid\" ],"
+        "\"valid-lifetime\": 600,"
+        "\"subnet4\": [ { "
+        "    \"subnet\": \"10.0.0.0/24\", "
+        "    \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],"
+        "    \"reservations\": [ "
+        "       {"
+        "         \"hw-address\": \"aa:bb:cc:dd:ee:ff\","
+        "         \"ip-address\": \"10.0.0.7\""
+        "       },"
+        "       {"
+        "         \"duid\": \"01:02:03:04:05\","
+        "         \"ip-address\": \"10.0.0.8\""
+        "       },"
+        "       {"
+        "         \"circuit-id\": \"'charter950'\","
+        "         \"ip-address\": \"10.0.0.9\""
+        "       }"
+        "    ]"
+        "} ]"
+    "}",
+
+    // Configuration 5
+    "{ \"interfaces-config\": {"
+        "      \"interfaces\": [ \"*\" ]"
+        "},"
+        "\"host-reservation-identifiers\": [ \"duid\", \"circuit-id\", \"hw-address\" ],"
         "\"valid-lifetime\": 600,"
         "\"subnet4\": [ { "
         "    \"subnet\": \"10.0.0.0/24\", "
@@ -728,6 +757,38 @@ TEST_F(DORATest, reservation) {
 }
 
 // This test checks that it is possible to make a reservation by
+// DUID carried in the Client Identifier option.
+TEST_F(DORATest, reservationByDUID) {
+    Dhcp4Client client(Dhcp4Client::SELECTING);
+    // Use relay agent so as the circuit-id can be inserted.
+    client.useRelay(true, IOAddress("10.0.0.1"), IOAddress("10.0.0.2"));
+    // Modify HW address so as the server doesn't assign reserved
+    // address by HW address.
+    client.modifyHWAddr();
+    // Specify DUID for which address 10.0.0.8 is reserved.
+    // The value specified as client id includes:
+    // - FF is a client identifier type for DUID,
+    // - 45454545 - represents 4 bytes for IAID
+    // - 01:02:03:04:05 - is an actual DUID for which there is a
+    //   reservation.
+    client.includeClientId("FF:45:45:45:45:01:02:03:04:05");
+
+    // Configure DHCP server.
+    configure(DORA_CONFIGS[2], *client.getServer());
+    // Client A performs 4-way exchange and should obtain a reserved
+    // address.
+    ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<
+                                  IOAddress>(new IOAddress("0.0.0.0"))));
+    // Make sure that the server responded.
+    ASSERT_TRUE(client.getContext().response_);
+    Pkt4Ptr resp = client.getContext().response_;
+    // Make sure that the server has responded with DHCPACK.
+    ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+    // Make sure that the client has got the lease for the reserved address.
+    ASSERT_EQ("10.0.0.8", client.config_.lease_.addr_.toText());
+}
+
+// This test checks that it is possible to make a reservation by
 // circuit-id inserted by the relay agent.
 TEST_F(DORATest, reservationByCircuitId) {
     Dhcp4Client client(Dhcp4Client::SELECTING);
@@ -758,6 +819,13 @@ TEST_F(DORATest, hostIdentifiersOrder) {
     client.setHWAddress("aa:bb:cc:dd:ee:ff");
     // Use relay agent so as the circuit-id can be inserted.
     client.useRelay(true, IOAddress("10.0.0.1"), IOAddress("10.0.0.2"));
+    // Specify DUID for which address 10.0.0.8 is reserved.
+    // The value specified as client id includes:
+    // - FF is a client identifier type for DUID,
+    // - 45454545 - represents 4 bytes for IAID
+    // - 01:02:03:04:05 - is an actual DUID for which there is a
+    //   reservation.
+    client.includeClientId("FF:45:45:45:45:01:02:03:04:05");
     // Specify circuit-id.
     client.setCircuitId("charter950");
 
@@ -778,7 +846,7 @@ TEST_F(DORATest, hostIdentifiersOrder) {
 
     // Reconfigure the server to change the preference order of the
     // host identifiers. The 'circuit-id' should now take precedence over
-    // the hw-address.
+    // the hw-address and duid.
     configure(DORA_CONFIGS[4], *client.getServer());
     ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<
                                   IOAddress>(new IOAddress("0.0.0.0"))));
@@ -790,6 +858,19 @@ TEST_F(DORATest, hostIdentifiersOrder) {
     // Make sure that the client has got the lease for the reserved address.
     ASSERT_EQ("10.0.0.9", client.config_.lease_.addr_.toText());
 
+    // Reconfigure the server to change the preference order of the
+    // host identifiers. The 'duid' should now take precedence over
+    // the hw-address and circuit-id
+    configure(DORA_CONFIGS[5], *client.getServer());
+    ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<
+                                  IOAddress>(new IOAddress("0.0.0.0"))));
+    // Make sure that the server responded.
+    ASSERT_TRUE(client.getContext().response_);
+    resp = client.getContext().response_;
+    // Make sure that the server has responded with DHCPACK.
+    ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+    // Make sure that the client has got the lease for the reserved address.
+    ASSERT_EQ("10.0.0.8", client.config_.lease_.addr_.toText());
 }
 
 // This test checks that setting the match-client-id value to false causes