From: Marcin Siodelski Date: Thu, 19 May 2016 13:20:09 +0000 (+0200) Subject: [4318] Added unit tests for reservations by DUID in DHCPv4. X-Git-Tag: trac4106_update_base~7^2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32227e09339085955a36cd4972dd269b59abb128;p=thirdparty%2Fkea.git [4318] Added unit tests for reservations by DUID in DHCPv4. --- diff --git a/src/bin/dhcp4/tests/dora_unittest.cc b/src/bin/dhcp4/tests/dora_unittest.cc index 3ee053f248..f8e980d281 100644 --- a/src/bin/dhcp4/tests/dora_unittest.cc +++ b/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\", " @@ -727,6 +756,38 @@ TEST_F(DORATest, reservation) { ASSERT_TRUE(subnet->inPool(Lease::TYPE_V4, clientB.config_.lease_.addr_)); } +// 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(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) { @@ -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(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