|
@@ -0,0 +1,167 @@
|
|
|
|
+// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
+//
|
|
|
|
+// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
+// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
+// copyright notice and this permission notice appear in all copies.
|
|
|
|
+//
|
|
|
|
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
+// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
+
|
|
|
|
+#include <config.h>
|
|
|
|
+#include <asiolink/io_address.h>
|
|
|
|
+#include <cc/data.h>
|
|
|
|
+#include <dhcp/dhcp4.h>
|
|
|
|
+#include <dhcp/tests/iface_mgr_test_config.h>
|
|
|
|
+#include <dhcp4/tests/dhcp4_test_utils.h>
|
|
|
|
+#include <dhcp4/tests/dhcp4_client.h>
|
|
|
|
+#include <boost/shared_ptr.hpp>
|
|
|
|
+
|
|
|
|
+using namespace isc;
|
|
|
|
+using namespace isc::asiolink;
|
|
|
|
+using namespace isc::data;
|
|
|
|
+using namespace isc::dhcp;
|
|
|
|
+using namespace isc::dhcp::test;
|
|
|
|
+
|
|
|
|
+namespace {
|
|
|
|
+
|
|
|
|
+/// @brief Set of JSON configurations used throughout the DORA tests.
|
|
|
|
+///
|
|
|
|
+/// - Configuration 0:
|
|
|
|
+/// - Used for testing direct traffic
|
|
|
|
+/// - 1 subnet: 10.0.0.0/24
|
|
|
|
+/// - 1 pool: 10.0.0.10-10.0.0.100
|
|
|
|
+/// - Router option present: 10.0.0.200 and 10.0.0.201
|
|
|
|
+/// - Domain Name Server option present: 10.0.0.202, 10.0.0.203.
|
|
|
|
+/// - Log Servers option present: 192.0.2.200 and 192.0.2.201
|
|
|
|
+/// - Quotes Servers option present: 192.0.2.202, 192.0.2.203.
|
|
|
|
+///
|
|
|
|
+/// - Configuration 1:
|
|
|
|
+/// - Use for testing relayed messages
|
|
|
|
+/// - 1 subnet: 192.0.2.0/24
|
|
|
|
+/// - Router option present: 192.0.2.200 and 192.0.2.201
|
|
|
|
+/// - Domain Name Server option present: 192.0.2.202, 192.0.2.203.
|
|
|
|
+/// - Log Servers option present: 192.0.2.200 and 192.0.2.201
|
|
|
|
+/// - Quotes Servers option present: 192.0.2.202, 192.0.2.203.
|
|
|
|
+const char* DORA_CONFIGS[] = {
|
|
|
|
+// Configuration 0
|
|
|
|
+ "{ \"interfaces\": [ \"all\" ],"
|
|
|
|
+ "\"valid-lifetime\": 600,"
|
|
|
|
+ "\"subnet4\": [ { "
|
|
|
|
+ " \"subnet\": \"10.0.0.0/24\", "
|
|
|
|
+ " \"pool\": [ \"10.0.0.10-10.0.0.100\" ],"
|
|
|
|
+ " \"option-data\": [ {"
|
|
|
|
+ " \"name\": \"routers\","
|
|
|
|
+ " \"code\": 3,"
|
|
|
|
+ " \"data\": \"10.0.0.200,10.0.0.201\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"domain-name-servers\","
|
|
|
|
+ " \"code\": 6,"
|
|
|
|
+ " \"data\": \"10.0.0.202,10.0.0.203\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"log-servers\","
|
|
|
|
+ " \"code\": 7,"
|
|
|
|
+ " \"data\": \"10.0.0.200,10.0.0.201\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"cookie-servers\","
|
|
|
|
+ " \"code\": 8,"
|
|
|
|
+ " \"data\": \"10.0.0.202,10.0.0.203\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " } ]"
|
|
|
|
+ " } ]"
|
|
|
|
+ "}",
|
|
|
|
+
|
|
|
|
+// Configuration 1
|
|
|
|
+ "{ \"interfaces\": [ \"all\" ],"
|
|
|
|
+ "\"valid-lifetime\": 600,"
|
|
|
|
+ "\"subnet4\": [ { "
|
|
|
|
+ " \"subnet\": \"192.0.2.0/24\", "
|
|
|
|
+ " \"option-data\": [ {"
|
|
|
|
+ " \"name\": \"routers\","
|
|
|
|
+ " \"code\": 3,"
|
|
|
|
+ " \"data\": \"192.0.2.200,192.0.2.201\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"domain-name-servers\","
|
|
|
|
+ " \"code\": 6,"
|
|
|
|
+ " \"data\": \"192.0.2.202,192.0.2.203\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"log-servers\","
|
|
|
|
+ " \"code\": 7,"
|
|
|
|
+ " \"data\": \"10.0.0.200,10.0.0.201\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"cookie-servers\","
|
|
|
|
+ " \"code\": 8,"
|
|
|
|
+ " \"data\": \"10.0.0.202,10.0.0.203\","
|
|
|
|
+ " \"csv-format\": true,"
|
|
|
|
+ " \"space\": \"dhcp4\""
|
|
|
|
+ " } ]"
|
|
|
|
+ " } ]"
|
|
|
|
+ "}"
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+/// @brief Test fixture class for testing 4-way (DORA) exchanges.
|
|
|
|
+class DORATest : public Dhcpv4SrvTest {
|
|
|
|
+public:
|
|
|
|
+
|
|
|
|
+ /// @brief Constructor.
|
|
|
|
+ ///
|
|
|
|
+ /// Sets up fake interfaces.
|
|
|
|
+ DORATest()
|
|
|
|
+ : Dhcpv4SrvTest(),
|
|
|
|
+ iface_mgr_test_config_(true) {
|
|
|
|
+ IfaceMgr::instance().openSockets4();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// @brief Interface Manager's fake configuration control.
|
|
|
|
+ IfaceMgrTestConfig iface_mgr_test_config_;
|
|
|
|
+
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// This test verifies that the client in a SELECTING state can request
|
|
|
|
+// a specific address and that this address will be assigned when
|
|
|
|
+// available.
|
|
|
|
+TEST_F(DORATest, selectingRequestAvailableAddress) {
|
|
|
|
+ Dhcp4Client client(Dhcp4Client::SELECTING);
|
|
|
|
+ // Configure DHCP server.
|
|
|
|
+ configure(DORA_CONFIGS[0], *client.getServer());
|
|
|
|
+
|
|
|
|
+ // Perform 4-way exchange with the server.
|
|
|
|
+ ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("10.0.0.50"))));
|
|
|
|
+
|
|
|
|
+ // 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()));
|
|
|
|
+ // Response must not be relayed.
|
|
|
|
+ EXPECT_FALSE(resp->isRelayed());
|
|
|
|
+ // Make sure that the server id is present.
|
|
|
|
+ EXPECT_EQ("10.0.0.1", client.config_.serverid_.toText());
|
|
|
|
+ // Make sure that the client has got the lease with the requested address.
|
|
|
|
+ EXPECT_EQ("10.0.0.50", client.config_.lease_.addr_.toText());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+} // end of anonymous namespace
|