]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3017] added testing framework for using dummy test interfaces
authorRazvan Becheriu <razvan@isc.org>
Fri, 13 Oct 2023 22:56:20 +0000 (01:56 +0300)
committerAndrei Pavel <andrei@isc.org>
Tue, 17 Oct 2023 09:35:55 +0000 (12:35 +0300)
83 files changed:
configure.ac
src/bin/dhcp4/tests/Makefile.am
src/bin/dhcp4/tests/classify_unittest.cc
src/bin/dhcp4/tests/config_backend_unittest.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/decline_unittest.cc
src/bin/dhcp4/tests/dhcp4_client.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/dhcp4_test_utils.cc
src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc
src/bin/dhcp4/tests/direct_client_unittest.cc
src/bin/dhcp4/tests/dora_unittest.cc
src/bin/dhcp4/tests/fqdn_unittest.cc
src/bin/dhcp4/tests/get_config_unittest.cc
src/bin/dhcp4/tests/get_config_unittest.cc.skel
src/bin/dhcp4/tests/hooks_unittest.cc
src/bin/dhcp4/tests/host_options_unittest.cc
src/bin/dhcp4/tests/host_unittest.cc
src/bin/dhcp4/tests/inform_unittest.cc
src/bin/dhcp4/tests/out_of_range_unittest.cc
src/bin/dhcp4/tests/release_unittest.cc
src/bin/dhcp4/tests/shared_network_unittest.cc
src/bin/dhcp4/tests/vendor_opts_unittest.cc
src/bin/dhcp6/tests/Makefile.am
src/bin/dhcp6/tests/classify_unittests.cc
src/bin/dhcp6/tests/config_backend_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/confirm_unittest.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/decline_unittest.cc
src/bin/dhcp6/tests/dhcp6_client.cc
src/bin/dhcp6/tests/dhcp6_message_test.h
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_test_utils.cc
src/bin/dhcp6/tests/dhcp6_test_utils.h
src/bin/dhcp6/tests/dhcp6to4_ipc_unittest.cc
src/bin/dhcp6/tests/fqdn_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc.skel
src/bin/dhcp6/tests/hooks_unittest.cc
src/bin/dhcp6/tests/host_unittest.cc
src/bin/dhcp6/tests/infrequest_unittest.cc
src/bin/dhcp6/tests/rebind_unittest.cc
src/bin/dhcp6/tests/renew_unittest.cc
src/bin/dhcp6/tests/sarr_unittest.cc
src/bin/dhcp6/tests/shared_network_unittest.cc
src/bin/dhcp6/tests/tee_times_unittest.cc
src/bin/dhcp6/tests/vendor_opts_unittest.cc
src/lib/dhcp/Makefile.am
src/lib/dhcp/duid_factory.cc
src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/iface_mgr.h
src/lib/dhcp/iface_mgr_bsd.cc
src/lib/dhcp/iface_mgr_linux.cc
src/lib/dhcp/iface_mgr_sun.cc
src/lib/dhcp/tests/Makefile.am
src/lib/dhcp/tests/duid_factory_unittest.cc
src/lib/dhcp/tests/iface_mgr_unittest.cc
src/lib/dhcp/tests/pkt4_unittest.cc
src/lib/dhcp/tests/pkt6_unittest.cc
src/lib/dhcp/testutils/Makefile.am [new file with mode: 0644]
src/lib/dhcp/testutils/iface_mgr_test_config.cc [moved from src/lib/dhcp/tests/iface_mgr_test_config.cc with 91% similarity]
src/lib/dhcp/testutils/iface_mgr_test_config.h [moved from src/lib/dhcp/tests/iface_mgr_test_config.h with 96% similarity]
src/lib/dhcp/testutils/pkt_captures.h [moved from src/lib/dhcp/tests/pkt_captures.h with 100% similarity]
src/lib/dhcp/testutils/pkt_captures4.cc [moved from src/lib/dhcp/tests/pkt_captures4.cc with 99% similarity]
src/lib/dhcp/testutils/pkt_captures6.cc [moved from src/lib/dhcp/tests/pkt_captures6.cc with 99% similarity]
src/lib/dhcp/testutils/pkt_filter6_test_stub.cc [moved from src/lib/dhcp/tests/pkt_filter6_test_stub.cc with 95% similarity]
src/lib/dhcp/testutils/pkt_filter6_test_stub.h [moved from src/lib/dhcp/tests/pkt_filter6_test_stub.h with 100% similarity]
src/lib/dhcp/testutils/pkt_filter_test_stub.cc [moved from src/lib/dhcp/tests/pkt_filter_test_stub.cc with 96% similarity]
src/lib/dhcp/testutils/pkt_filter_test_stub.h [moved from src/lib/dhcp/tests/pkt_filter_test_stub.h with 100% similarity]
src/lib/dhcpsrv/parsers/ifaces_config_parser.cc
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/cfg_iface_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc
src/lib/dhcpsrv/tests/cfgmgr_unittest.cc
src/lib/dhcpsrv/tests/dhcp4o6_ipc_unittest.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
src/lib/dhcpsrv/tests/ifaces_config_parser_unittest.cc
src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc
src/lib/dhcpsrv/tests/shared_networks_list_parser_unittest.cc
src/lib/dhcpsrv/tests/srv_config_unittest.cc

index 4d554da8e9ea746ac77162470af4ea96eac9ed1c..f3d804857eeaf2bc4a5755a3989187fa73613e91 100644 (file)
@@ -1606,6 +1606,7 @@ AC_CONFIG_FILES([src/lib/database/Makefile])
 AC_CONFIG_FILES([src/lib/database/tests/Makefile])
 AC_CONFIG_FILES([src/lib/database/testutils/Makefile])
 AC_CONFIG_FILES([src/lib/dhcp/Makefile])
+AC_CONFIG_FILES([src/lib/dhcp/testutils/Makefile])
 AC_CONFIG_FILES([src/lib/dhcp/tests/Makefile])
 AC_CONFIG_FILES([src/lib/dhcp_ddns/Makefile])
 AC_CONFIG_FILES([src/lib/dhcp_ddns/tests/Makefile])
index 8a2c084089679c0c8f0395f73e0d30810413f695..b4c4c2db63aeb27ba7c4b2582b0c1d4abfde49dd 100644 (file)
@@ -120,7 +120,7 @@ dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
-dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp/tests/libdhcptest.la
+dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp/testutils/libdhcptest.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
 
index 2d06a4985e348f94178054a44d24075bbcba47eb..cf9dbb7c8ac432728fa599d359e270bedac5dc8d 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 #include <asiolink/io_address.h>
 #include <dhcp/dhcp4.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <dhcp/option_int.h>
 #include <stats/stats_mgr.h>
index f3aa486976318f49257ec4f6a264a483c4d0a2d7..50101778717611ba4b536d28b47b16533dc2d9f7 100644 (file)
@@ -10,7 +10,7 @@
 #include <gtest/gtest.h>
 
 #include <database/backend_selector.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp4/dhcp4_srv.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
 #include <dhcp4/json_config_parser.h>
index 3cdcf86f8d6b444eda63278582deb26e2b706bc0..a0dde7828d5b582670d0641c6a382ceea17446d8 100644 (file)
@@ -18,7 +18,7 @@
 #include <dhcp/option_int.h>
 #include <dhcp/docsis3_option_defs.h>
 #include <dhcp/classify.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_expiration.h>
index e9fdcc072eb4bbca1f72c5b132ad11e690e392a2..a47ca2c58197e72d8541fbf5673577546d50c982 100644 (file)
@@ -13,7 +13,7 @@
 #include <config/timeouts.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/libdhcp++.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
@@ -86,7 +86,7 @@ private:
 class NakedControlledDhcpv4Srv: public ControlledDhcpv4Srv {
     // "Naked" DHCPv4 server, exposes internal fields
 public:
-    NakedControlledDhcpv4Srv():ControlledDhcpv4Srv(0) {
+    NakedControlledDhcpv4Srv() : ControlledDhcpv4Srv(0) {
         CfgMgr::instance().setFamily(AF_INET);
     }
 
@@ -103,13 +103,16 @@ public:
     /// @brief Path to the UNIX socket being used to communicate with the server
     std::string socket_path_;
 
+    /// @brief List of interfaces (defaults to "*").
+    std::string interfaces_;
+
     /// @brief Pointer to the tested server object
     boost::shared_ptr<NakedControlledDhcpv4Srv> server_;
 
     /// @brief Default constructor
     ///
     /// Sets socket path to its default value.
-    CtrlChannelDhcpv4SrvTest() {
+    CtrlChannelDhcpv4SrvTest() : interfaces_("\"*\"") {
         const char* env = getenv("KEA_SOCKET_TEST_DIR");
         if (env) {
             socket_path_ = string(env) + "/kea4.sock";
@@ -117,6 +120,8 @@ public:
             socket_path_ = sandbox.join("kea4.sock");
         }
         reset();
+        IfaceMgr::instance().setTestMode(false);
+        IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
     }
 
     /// @brief Destructor
@@ -129,6 +134,11 @@ public:
         CommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
 
         server_.reset();
+        IfaceMgr::instance().setTestMode(false);
+        IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
+        IfaceMgr::instance().clearIfaces();
+        IfaceMgr::instance().closeSockets();
+        IfaceMgr::instance().detectIfaces();
     };
 
     /// @brief Returns pointer to the server's IO service.
@@ -147,7 +157,9 @@ public:
         std::string header =
             "{"
             "    \"interfaces-config\": {"
-            "        \"interfaces\": [ \"*\" ]"
+            "        \"interfaces\": [";
+
+        std::string body = "]"
             "    },"
             "    \"expired-leases-processing\": {"
             "         \"reclaim-timer-wait-time\": 60,"
@@ -175,8 +187,7 @@ public:
 
         // Fill in the socket-name value with socket_path_  to
         // make the actual configuration text.
-        std::string config_txt = header + socket_path_  + footer;
-
+        std::string config_txt = header + interfaces_ + body + socket_path_  + footer;
         ASSERT_NO_THROW(server_.reset(new NakedControlledDhcpv4Srv()));
 
         ConstElementPtr config;
@@ -210,7 +221,6 @@ public:
         ASSERT_GT(isc::config::CommandMgr::instance().getControlSocketFD(), -1);
     }
 
-
     /// @brief Reset hooks data
     ///
     /// Resets the data for the hooks-related portion of the test by ensuring
@@ -817,7 +827,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configSet) {
     sendUnixCommand(os.str(), response);
 
     // Verify the configuration was successful. The config contains random
-    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // socket name (/tmp/kea-<value-changing-each-time>/kea4.sock), so the
     // hash will be different each time. As such, we can do simplified checks:
     // - verify the "result": 0 is there
     // - verify the "text": "Configuration successful." is there
@@ -885,7 +895,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configSet) {
     EXPECT_FALSE(fileExists(socket_path_));
 
     // With no command channel, should still receive the response. The config contains random
-    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // socket name (/tmp/kea-<value-changing-each-time>/kea4.sock), so the
     // hash will be different each time. As such, we can do simplified checks:
     // - verify the "result": 0 is there
     // - verify the "text": "Configuration successful." is there
@@ -1030,7 +1040,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configTest) {
     sendUnixCommand(os.str(), response);
 
     // Verify the configuration was successful. The config contains random
-    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // socket name (/tmp/kea-<value-changing-each-time>/kea4.sock), so the
     // hash will be different each time. As such, we can do simplified checks:
     // - verify the "result": 0 is there
     // - verify the "text": "Configuration successful." is there
@@ -1508,6 +1518,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configWriteFilename) {
 
     sendUnixCommand("{ \"command\": \"config-write\", "
                     "\"arguments\": { \"filename\": \"test2.json\" } }", response);
+
     checkConfigWrite(response, CONTROL_RESULT_SUCCESS, "test2.json");
     ::remove("test2.json");
 }
@@ -1591,8 +1602,83 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configReloadValid) {
 
     // This command should reload test8.json config.
     sendUnixCommand("{ \"command\": \"config-reload\" }", response);
+
+    // Verify the configuration was successful. The config contains random
+    // socket name (/tmp/kea-<value-changing-each-time>/kea4.sock), so the
+    // hash will be different each time. As such, we can do simplified checks:
+    // - verify the "result": 0 is there
+    // - verify the "text": "Configuration successful." is there
+    EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
+
+    // Check that the config was indeed applied.
+    const Subnet4Collection* subnets =
+        CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
+    EXPECT_EQ(2, subnets->size());
+
+    ::remove("test8.json");
+}
+
+// Tests if config-reload attempts to reload a file and reports that the
+// file is loaded correctly.
+TEST_F(CtrlChannelDhcpv4SrvTest, configReloadDetectInterfaces) {
+    interfaces_ = "\"eth0\"";
+    IfacePtr eth0 = IfaceMgrTestConfig::createIface("eth0", 0);
+    auto detectIfaces = [&](bool update_only) {
+        if (!update_only) {
+            eth0->addAddress(IOAddress("10.0.0.1"));
+            eth0->addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
+            eth0->addAddress(IOAddress("2001:db8:1::1"));
+            IfaceMgr::instance().addInterface(eth0);
+        }
+        return (false);
+    };
+    IfaceMgr::instance().setDetectCallback(detectIfaces);
+    IfaceMgr::instance().clearIfaces();
+    IfaceMgr::instance().closeSockets();
+    IfaceMgr::instance().detectIfaces();
+    createUnixChannelServer();
+    std::string response;
+
+    // This is normally set to whatever value is passed to -c when the server is
+    // started, but we're not starting it that way, so need to set it by hand.
+    server_->setConfigFile("test8.json");
+
+    // Ok, enough fooling around. Let's create a valid config.
+    const std::string cfg_txt =
+        "{ \"Dhcp4\": {"
+        "    \"interfaces-config\": {"
+        "        \"interfaces\": [ \"eth1\" ]"
+        "    },"
+        "    \"subnet4\": ["
+        "        { \"id\": 1, \"subnet\": \"192.0.2.0/24\" },"
+        "        { \"id\": 2, \"subnet\": \"192.0.3.0/24\" }"
+        "     ],"
+        "    \"valid-lifetime\": 4000,"
+        "    \"lease-database\": {"
+        "       \"type\": \"memfile\", \"persist\": false }"
+        "} }";
+    ofstream f("test8.json", ios::trunc);
+    f << cfg_txt;
+    f.close();
+
+    IfacePtr eth1 = IfaceMgrTestConfig::createIface("eth1", 1);
+    auto detectUpdateIfaces = [&](bool update_only) {
+        if (!update_only) {
+            eth1->addAddress(IOAddress("192.0.2.3"));
+            eth1->addAddress(IOAddress("fe80::3a60:77ff:fed5:abcd"));
+            eth1->addAddress(IOAddress("3001:db8:100::1"));
+            IfaceMgr::instance().addInterface(eth1);
+        }
+        return (false);
+    };
+    IfaceMgr::instance().setDetectCallback(detectUpdateIfaces);
+
+    // This command should reload test8.json config.
+    sendUnixCommand("{ \"command\": \"config-reload\" }", response);
+
     // Verify the configuration was successful. The config contains random
-    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // socket name (/tmp/kea-<value-changing-each-time>/kea4.sock), so the
     // hash will be different each time. As such, we can do simplified checks:
     // - verify the "result": 0 is there
     // - verify the "text": "Configuration successful." is there
index ef3bc1d8da54cb4a1223a1332d548e5f9ab65451..782b3aaf65c7a7fd38f43bb4537e9521ff56d828 100644 (file)
@@ -9,7 +9,7 @@
 #include <asiolink/io_address.h>
 #include <cc/data.h>
 #include <dhcp/dhcp4.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/subnet_id.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
index b054a0d2aa881bca3cc82f34d8400671aede9941..151c23229b7683b875775892665a7b78c6d0bd1e 100644 (file)
@@ -9,7 +9,7 @@
 #include <dhcp/option.h>
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_vendor.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/lease.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <util/multi_threading_mgr.h>
index 7a1c4604a2c97e622260b459264667ce051c1308..5917972ec8a6e35deb791258c36142949036fc4b 100644 (file)
@@ -15,7 +15,7 @@
 #include <dhcp4/json_config_parser.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp4/tests/dhcp4_client.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp/libdhcp++.h>
@@ -26,7 +26,7 @@
 #include <dhcp/option_int_array.h>
 #include <dhcp/pkt_filter.h>
 #include <dhcp/pkt_filter_inet.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
index 045fe6fb677b5c8ede40ebbe242671f637de1d31..c3aa7c44c89530d4dbb04f22c834713f8d53467a 100644 (file)
@@ -17,8 +17,8 @@
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_custom.h>
 #include <dhcp/iface_mgr.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcpsrv/cfg_db_access.h>
 #include <dhcpsrv/cfg_multi_threading.h>
 #include <dhcpsrv/cfgmgr.h>
index 2a47d718219306a0ea5ad066e73093993c99cb1c..b59d825f5850af555844b43b6ed021435678077c 100644 (file)
@@ -9,7 +9,7 @@
 #include <asiolink/io_address.h>
 #include <dhcp/pkt4o6.h>
 #include <dhcp/pkt6.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
 #include <dhcp4/dhcp4to6_ipc.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
index 27439e2baa2c4b563e7a4849973f44f29802d628..913885ea63823f0b0bf016bdf0264f84b31b1937 100644 (file)
@@ -8,7 +8,7 @@
 #include <dhcp/iface_mgr.h>
 #include <dhcp/pkt4.h>
 #include <dhcp/classify.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_subnets4.h>
 #include <dhcpsrv/lease_mgr_factory.h>
index be2c7cf25a3482973234560aa30295740ca2cfba..9520f14d2b26c7d255c8e08d78fed21bc7a7c75f 100644 (file)
@@ -8,7 +8,7 @@
 #include <asiolink/io_address.h>
 #include <cc/data.h>
 #include <dhcp/dhcp4.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/host.h>
 #include <dhcpsrv/host_mgr.h>
index a030d8846f673320dabf6cc4278a5ff43dfc9471..d7e92bcb6b9b4595df5d25850eddd047ad18274b 100644 (file)
@@ -9,7 +9,7 @@
 #include <dhcp/option4_client_fqdn.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_int_array.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp_ddns/ncr_msg.h>
index e67c5a13c396b3469f19e02c0e0f68687db4762e..575caabae5f8121f0ae3aff92bfcf33c5883c0ff 100644 (file)
@@ -11,7 +11,7 @@
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
 #include <testutils/user_context_utils.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/parsers/simple_parser4.h>
 #include <dhcp4/dhcp4_srv.h>
index a25a5abbbb5cb941326ddcdb6757f697bfb926dd..b30ba0b0586788bea23c28d985a703bbe413a0a3 100644 (file)
@@ -11,7 +11,7 @@
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
 #include <testutils/user_context_utils.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/parsers/simple_parser4.h>
 #include <dhcp4/dhcp4_srv.h>
index 474f1ca34103ab0433f14efe72a4e5c7b12f1db3..27746cb6cf8af5e33f4350d39ceb7d8712d1cc1f 100644 (file)
@@ -10,7 +10,7 @@
 #include <asiolink/io_service.h>
 #include <cc/command_interpreter.h>
 #include <config/command_mgr.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp/option.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
index db6ccb1bff38af36c220fcc505a8bbdc4c9db132..ae6cbe6964e59f6a3c73618e9297a4aeb9eeaa99 100644 (file)
@@ -10,7 +10,7 @@
 #include <dhcp/docsis3_option_defs.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_vendor.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <stats/stats_mgr.h>
index 5a39c85b948e1b4b46aed4c4409477ea7ca9c856..3eb81b897f86a3bc82be7a2a728500cc4a28b37e 100644 (file)
@@ -8,7 +8,7 @@
 #include <asiolink/io_address.h>
 #include <cc/data.h>
 #include <dhcp/dhcp4.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/host.h>
 #include <dhcpsrv/host_mgr.h>
index ed3114f0c5c733c7f4ae2aa9db57506ba527ab16..50697d57178cea13a5c5c4d1c38047a9d65b9289 100644 (file)
@@ -9,7 +9,7 @@
 #include <cc/data.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/libdhcp++.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <stats/stats_mgr.h>
index b0dba8d44e1f773636bf0be23e9edc61449eb50a..8b86d596191bd03e182ab0021a06a8a5d98c177b 100644 (file)
@@ -9,7 +9,7 @@
 #include <cc/data.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp_ddns/ncr_msg.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/subnet_id.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
index c59bd45d86db8a6160ba9f1b63dce0e45b4d4973..8acc433843252657f0f86db1917284676b5024aa 100644 (file)
@@ -8,7 +8,7 @@
 #include <asiolink/io_address.h>
 #include <cc/data.h>
 #include <dhcp/dhcp4.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/subnet_id.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
index a5cefbe90af47e1e9b225ad8349cdc1a905e54ba..67bac00040593201ce3bf5aa9d04d61eaddaa64b 100644 (file)
@@ -8,7 +8,7 @@
 #include <asiolink/io_address.h>
 #include <cc/data.h>
 #include <dhcp/dhcp4.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp/option.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_string.h>
index cf38afcf7038d2ffddc534421e459c0f361b4df2..44553b5a93b7dac326baab922d2b00e87b88c397 100644 (file)
 #include <dhcp4/dhcp4_srv.h>
 #include <dhcp4/json_config_parser.h>
 #include <dhcp4/tests/dhcp4_client.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
 #include <dhcp/option_vendor_class.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcp/docsis3_option_defs.h>
 #include <dhcp/dhcp4.h>
 #include <dhcpsrv/cfg_multi_threading.h>
index 35e16918e4f30c3fdafa5c19354da9fe939cc44c..f7853b32e1aa9aec01997931f2ee96d4dd05bf7e 100644 (file)
@@ -124,7 +124,7 @@ dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
-dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/tests/libdhcptest.la
+dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/testutils/libdhcptest.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
 
index fdc82cab8d3406db0efed3fca5a32bc00a7a638f..c04c58a94443332c49f03bcd4d151cba704f6c16 100644 (file)
 #include <dhcp/option_int.h>
 #include <dhcp/option_int_array.h>
 #include <dhcp/pkt6.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp/opaque_data_tuple.h>
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor_class.h>
 #include <dhcp/option6_addrlst.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/tests/dhcp6_client.h>
index e2d87762d23d0fde1a3e9647fdb8f5af58ebc5b0..f1427ce5f8ed759c61dd0fe4ac2fa07846483153 100644 (file)
@@ -12,7 +12,7 @@
 #include <database/backend_selector.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_string.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/dhcp6_srv.h>
 #include <dhcp6/ctrl_dhcp6_srv.h>
 #include <dhcp6/json_config_parser.h>
index dcc5b609a9e8dd2d26d4146a60758204e3ebade2..8ef97b887b107715099cd8fda6a6fe22068c3dbb 100644 (file)
@@ -14,7 +14,7 @@
 #include <dhcp/option_custom.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option6_addrlst.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/dhcp6_srv.h>
 #include <dhcp6/ctrl_dhcp6_srv.h>
index f100c2ba62bb86210292cda26c7ef9cb08f01b1f..4776714a9bb35556843d052d1b80900ccfcb5161 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 #include <asiolink/io_address.h>
 #include <cc/data.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_message_test.h>
 #include <dhcpsrv/utils.h>
index 0b981e86f3539cda9f6c6872ed8997f17e6728d0..46372e8ccb84193558922c7e0db3e3a866703ab5 100644 (file)
@@ -10,7 +10,7 @@
 #include <cc/command_interpreter.h>
 #include <config/command_mgr.h>
 #include <dhcp/libdhcp++.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
@@ -86,7 +86,7 @@ private:
 class NakedControlledDhcpv6Srv: public ControlledDhcpv6Srv {
     // "Naked" DHCPv6 server, exposes internal fields
 public:
-    NakedControlledDhcpv6Srv():ControlledDhcpv6Srv(DHCP6_SERVER_PORT + 10000) {
+    NakedControlledDhcpv6Srv() : ControlledDhcpv6Srv(DHCP6_SERVER_PORT + 10000) {
         CfgMgr::instance().setFamily(AF_INET6);
     }
 
@@ -114,7 +114,6 @@ public:
         reset();
     };
 
-
     /// @brief Reset hooks data
     ///
     /// Resets the data for the hooks-related portion of the test by ensuring
@@ -139,13 +138,16 @@ public:
     /// @brief Path to the UNIX socket being used to communicate with the server
     std::string socket_path_;
 
+    /// @brief List of interfaces (defaults to "*").
+    std::string interfaces_;
+
     /// @brief Pointer to the tested server object
     boost::shared_ptr<NakedControlledDhcpv6Srv> server_;
 
     /// @brief Default constructor
     ///
     /// Sets socket path to its default value.
-    CtrlChannelDhcpv6SrvTest() {
+    CtrlChannelDhcpv6SrvTest() : interfaces_("\"*\"") {
         const char* env = getenv("KEA_SOCKET_TEST_DIR");
         if (env) {
             socket_path_ = string(env) + "/kea6.sock";
@@ -153,12 +155,19 @@ public:
             socket_path_ = sandbox.join("/kea6.sock");
         }
         reset();
+        IfaceMgr::instance().setTestMode(false);
+        IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
     }
 
     /// @brief Destructor
     ~CtrlChannelDhcpv6SrvTest() {
         server_.reset();
         reset();
+        IfaceMgr::instance().setTestMode(false);
+        IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
+        IfaceMgr::instance().clearIfaces();
+        IfaceMgr::instance().closeSockets();
+        IfaceMgr::instance().detectIfaces();
     };
 
     /// @brief Returns pointer to the server's IO service.
@@ -177,7 +186,9 @@ public:
         std::string header =
             "{"
             "    \"interfaces-config\": {"
-            "        \"interfaces\": [ \"*\" ]"
+            "        \"interfaces\": [";
+
+        std::string body = "]"
             "    },"
             "    \"expired-leases-processing\": {"
             "         \"reclaim-timer-wait-time\": 60,"
@@ -205,8 +216,7 @@ public:
 
         // Fill in the socket-name value with socket_path_  to
         // make the actual configuration text.
-        std::string config_txt = header + socket_path_  + footer;
-
+        std::string config_txt = header + interfaces_ + body + socket_path_  + footer;
         ASSERT_NO_THROW(server_.reset(new NakedControlledDhcpv6Srv()));
 
         ConstElementPtr config;
@@ -1541,6 +1551,7 @@ TEST_F(CtrlChannelDhcpv6SrvTest, configWriteFilename) {
 
     sendUnixCommand("{ \"command\": \"config-write\", "
                     "\"arguments\": { \"filename\": \"test2.json\" } }", response);
+
     checkConfigWrite(response, CONTROL_RESULT_SUCCESS, "test2.json");
     ::remove("test2.json");
 }
@@ -1640,6 +1651,79 @@ TEST_F(CtrlChannelDhcpv6SrvTest, configReloadValid) {
     ::remove("test8.json");
 }
 
+// Tests if config-reload attempts to reload a file and reports that the
+// file is loaded correctly.
+TEST_F(CtrlChannelDhcpv6SrvTest, configReloadDetectInterfaces) {
+    interfaces_ = "\"eth0\"";
+    IfacePtr eth0 = IfaceMgrTestConfig::createIface("eth0", 0);
+    auto detectIfaces = [&](bool update_only) {
+        if (!update_only) {
+            eth0->addAddress(IOAddress("10.0.0.1"));
+            eth0->addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
+            eth0->addAddress(IOAddress("2001:db8:1::1"));
+            IfaceMgr::instance().addInterface(eth0);
+        }
+        return (false);
+    };
+    IfaceMgr::instance().setDetectCallback(detectIfaces);
+    IfaceMgr::instance().clearIfaces();
+    IfaceMgr::instance().closeSockets();
+    IfaceMgr::instance().detectIfaces();
+    createUnixChannelServer();
+    std::string response;
+
+    // This is normally set to whatever value is passed to -c when the server is
+    // started, but we're not starting it that way, so need to set it by hand.
+    server_->setConfigFile("test8.json");
+
+    // Ok, enough fooling around. Let's create a valid config.
+    const std::string cfg_txt =
+        "{ \"Dhcp6\": {"
+        "    \"interfaces-config\": {"
+        "        \"interfaces\": [ \"eth1\" ]"
+        "    },"
+        "    \"subnet6\": ["
+        "        { \"subnet\": \"2001:db8:1::/64\", \"id\": 1 },"
+        "        { \"subnet\": \"2001:db8:2::/64\", \"id\": 2 }"
+        "     ],"
+        "    \"lease-database\": {"
+        "       \"type\": \"memfile\", \"persist\": false }"
+        "} }";
+    ofstream f("test8.json", ios::trunc);
+    f << cfg_txt;
+    f.close();
+
+    IfacePtr eth1 = IfaceMgrTestConfig::createIface("eth1", ETH1_INDEX);
+    auto detectUpdateIfaces = [&](bool update_only) {
+        if (!update_only) {
+            eth1->addAddress(IOAddress("192.0.2.3"));
+            eth1->addAddress(IOAddress("fe80::3a60:77ff:fed5:abcd"));
+            eth1->addAddress(IOAddress("3001:db8:100::1"));
+            IfaceMgr::instance().addInterface(eth1);
+        }
+        return (false);
+    };
+    IfaceMgr::instance().setDetectCallback(detectUpdateIfaces);
+
+    // This command should reload test8.json config.
+    sendUnixCommand("{ \"command\": \"config-reload\" }", response);
+
+    // Verify the configuration was successful. The config contains random
+    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // hash will be different each time. As such, we can do simplified checks:
+    // - verify the "result": 0 is there
+    // - verify the "text": "Configuration successful." is there
+    EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
+
+    // Check that the config was indeed applied.
+    const Subnet6Collection* subnets =
+        CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
+    EXPECT_EQ(2, subnets->size());
+
+    ::remove("test8.json");
+}
+
 // This test verifies that disable DHCP service command performs sanity check on
 // parameters.
 TEST_F(CtrlChannelDhcpv6SrvTest, dhcpDisableBadParam) {
index b3db3adbcddc3a9da75c482b62d8468714cc505b..92f511d7c2e22cbdf73ef6f5deea25279ce4bda4 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 #include <asiolink/io_address.h>
 #include <cc/data.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_message_test.h>
 #include <dhcpsrv/lease.h>
index 7021176bf4b6fadeeed8606add24c4fa91500cd4..2ab1c9d227497e7f84b5d2ffe14f2024c34f5344 100644 (file)
@@ -15,7 +15,7 @@
 #include <dhcp/option6_iaaddr.h>
 #include <dhcp/option6_status_code.h>
 #include <dhcp/pkt6.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/pool.h>
index 0b7e7adabe95ba4f5306e7d2a95be694d209382b..911f0e54a014715f227975199106ef6871e751a0 100644 (file)
@@ -8,7 +8,7 @@
 #define DHCP6_MESSAGE_TEST_H
 
 #include <asiolink/io_address.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/tests/dhcp6_client.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
 
index 40ee751caecc37f5034496a24c559ea406eb4833..d3d587a86828a5f1344acfed17c61029c6659c9e 100644 (file)
@@ -13,7 +13,7 @@
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/tests/dhcp6_client.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/duid.h>
 #include <dhcp/option.h>
@@ -25,7 +25,7 @@
 #include <dhcp/option_string.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp/docsis3_option_defs.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
index 212a4d769d7ed9dd6092956e273b04650b56f964..a2f9acff6145e923e3623286e1984fe7bf798d33 100644 (file)
@@ -8,7 +8,7 @@
 #include <gtest/gtest.h>
 #include <cc/command_interpreter.h>
 #include <dhcp/option6_status_code.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcpsrv/cfg_multi_threading.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/json_config_parser.h>
index b5c1d7befe7e8962e90184812c466f17de506d50..202bd8e2f4e7d5f6242607c2488208108da97a66 100644 (file)
@@ -24,7 +24,7 @@
 #include <dhcp/option_custom.h>
 #include <dhcp/option.h>
 #include <dhcp/iface_mgr.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
index ce7e077f7c6dfc704252e34b9970103a46a45130..0ff86b4bdbe9f6bc9c5680f0b1329c570af66da9 100644 (file)
@@ -9,8 +9,8 @@
 #include <asiolink/io_address.h>
 #include <dhcp/pkt6.h>
 #include <dhcp/iface_mgr.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
-#include <dhcp/tests/pkt_filter6_test_stub.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
+#include <dhcp/testutils/pkt_filter6_test_stub.h>
 #include <dhcp6/dhcp6to4_ipc.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/testutils/dhcp4o6_test_ipc.h>
index c10c3497572336ad2a609c41ded342dffae2aa87..f3b93930d367f4f8a7e60189337296097764a738 100644 (file)
@@ -16,7 +16,7 @@
 #include <dhcp/option6_iaaddr.h>
 #include <dhcp/option6_status_code.h>
 #include <dhcp/option_int_array.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/ncr_generator.h>
index d5691841d70271ab7de962230ce5075c802559e2..2a931f3b2da8aad30f8e0a9147a8c065cf5ab4df 100644 (file)
@@ -11,7 +11,7 @@
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
 #include <testutils/user_context_utils.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/parsers/simple_parser6.h>
 #include <dhcp6/dhcp6_srv.h>
index 44f3f1e6c0e3fce40e8eda942519efa01a643fe4..e9bd4a7fb79a09a0ad24222523ca1c1238134106 100644 (file)
@@ -11,7 +11,7 @@
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
 #include <testutils/user_context_utils.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/parsers/simple_parser6.h>
 #include <dhcp6/dhcp6_srv.h>
index c34aa763c695292ebd86060fc31f4970cfccc8b6..bdf876d0f24274f30679f484c7e63cc3a1415a92 100644 (file)
@@ -12,8 +12,8 @@
 #include <config/command_mgr.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/duid.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
index efc3f463d05a096c0e6cb9ebc7db51a0dff8f537..8f887f6aa388706c2edefa04cb6ed5a6191d27ec 100644 (file)
@@ -10,7 +10,7 @@
 #include <dhcp/option6_addrlst.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_vendor.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/tests/dhcp6_client.h>
 #include <boost/algorithm/string/join.hpp>
index df3ac76c69183777114b44aa1517f9a573b0e675..38cce54bdd28d5fa9ffe34ebfd7fcaa7d21d4857 100644 (file)
@@ -5,7 +5,7 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/tests/dhcp6_client.h>
 #include <dhcp/option6_addrlst.h>
index 48801e6d96d9223c3ea4f702b0cc44bf64dab206..0c37370da2478f4ac4356cd9fb7ba5b19d4f2551 100644 (file)
@@ -10,7 +10,7 @@
 #include <dhcp/docsis3_option_defs.h>
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_message_test.h>
 #include <dhcpsrv/utils.h>
index 644bc970b77f813a9a254461e1e76c8450ac351e..e20867b18301dea8779b7efae9ec75452fcec8bc 100644 (file)
@@ -11,7 +11,7 @@
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
 #include <dhcp/option6_pdexclude.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_message_test.h>
 #include <boost/pointer_cast.hpp>
index 2d379bedfc8cbf101f3b346a9dbb78e3f8799613..055ddd07290946d5c2ae1ad1aadd9c7d2054b83e 100644 (file)
@@ -5,7 +5,7 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp/option6_client_fqdn.h>
 #include <dhcp/option6_pdexclude.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
index aaa7ff10f547124836cef04323f49724f34fc184..02a8283e74b34fca552f88d3c1d7a589249b5835 100644 (file)
@@ -10,7 +10,7 @@
 #include <dhcp/option_int.h>
 #include <dhcp/option6_client_fqdn.h>
 #include <dhcp/option6_addrlst.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfg_subnets6.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
index 1caec5a7b2f8e8393c3fadc37f4f5f920a522da7..95ace971cccc19588c2e257fb1860c4f086b89c9 100644 (file)
@@ -8,7 +8,7 @@
 #include <asiolink/io_address.h>
 #include <cc/data.h>
 #include <dhcp/option_string.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_message_test.h>
 #include <dhcpsrv/utils.h>
index 92234def27f09380dd814cef5d511a2d6b625fe0..0cbc224752e5da81c8a76e90ba5e9b1284890e5e 100644 (file)
@@ -23,9 +23,9 @@
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/tests/dhcp6_client.h>
 #include <dhcp6/json_config_parser.h>
-#include <dhcp/tests/pkt_captures.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcp/docsis3_option_defs.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcp/option_string.h>
 #include <cc/command_interpreter.h>
 
index 4213c449e86a7a5bc63e11270e495d837f6803d1..2f4053a6b1ef7b90fab6f7252485b99cf9469556 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . testutils tests
 
 AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
index 9b34d15d796966be9bf4687ef64bf2908578ffbe..1a023445bd2eb99601167663b516b6f13c3e85f3 100644 (file)
@@ -296,7 +296,7 @@ DUIDFactory::createLinkLayerId(std::vector<uint8_t>& identifier,
     // used for generating DUID-LLT.
     if (identifier.empty()) {
         isc_throw(Unexpected, "unable to find suitable interface for "
-                  " generating a DUID-LLT");
+                  "generating a DUID-LLT");
     }
 }
 
index 6bf1a0853f5c9438aafd9cffcda0bfb6e5bc3a3e..11f6e2f143074873ee5ef1f03ea09260e3dcac93 100644 (file)
@@ -477,44 +477,6 @@ IfaceMgr::hasOpenSocket(const IOAddress& addr) const {
     return (false);
 }
 
-void IfaceMgr::stubDetectIfaces() {
-    string ifaceName;
-    const string v4addr("127.0.0.1"), v6addr("::1");
-
-    // This is a stub implementation for interface detection. Actual detection
-    // is faked by detecting loopback interface (lo or lo0). It will eventually
-    // be removed once we have actual implementations for all supported systems.
-
-    if (if_nametoindex("lo") > 0) {
-        ifaceName = "lo";
-        // this is Linux-like OS
-    } else if (if_nametoindex("lo0") > 0) {
-        ifaceName = "lo0";
-        // this is BSD-like OS
-    } else {
-        // we give up. What OS is this, anyway? Solaris? Hurd?
-        isc_throw(NotImplemented,
-                  "Interface detection on this OS is not supported.");
-    }
-
-    IfacePtr iface(new Iface(ifaceName, if_nametoindex(ifaceName.c_str())));
-    iface->flag_up_ = true;
-    iface->flag_running_ = true;
-
-    // Note that we claim that this is not a loopback. iface_mgr tries to open a
-    // socket on all interfaces that are up, running and not loopback. As this is
-    // the only interface we were able to detect, let's pretend this is a normal
-    // interface.
-    iface->flag_loopback_ = false;
-    iface->flag_multicast_ = true;
-    iface->flag_broadcast_ = true;
-    iface->setHWType(HWTYPE_ETHERNET);
-
-    iface->addAddress(IOAddress(v4addr));
-    iface->addAddress(IOAddress(v6addr));
-    addInterface(iface);
-}
-
 bool
 IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
                        IfaceMgrErrorMsgCallback error_handler,
index bccfeee01cb36d8d5d96a18a22bb67f10b51dd29..a3b0596ec7af0da450371e3b88fa8baefddd3a84 100644 (file)
@@ -659,6 +659,14 @@ public:
     /// @param fd socket descriptor of the ready socket
     typedef std::function<void (int fd)> SocketCallback;
 
+    /// Defines callback used when detecting interfaces.
+    /// @param update_only Only add interfaces that do not exist and update
+    /// existing interfaces.
+    ///
+    /// @return true if callback exited with no issue and @ref detectIfaces
+    /// should continue with specific system calls, false otherwise.
+    typedef std::function<bool (bool)> DetectCallback;
+
     /// Keeps callback information for external sockets.
     struct SocketCallbackInfo {
         /// Socket descriptor of the external socket.
@@ -788,11 +796,18 @@ public:
     /// @c PktFilter class to mimic socket operation on these interfaces.
     void clearIfaces();
 
+    /// @brief Set a callback to perform operations before executing specific
+    /// system calls.
+    ///
+    /// @param cb The callback used before executing specific system calls.
+    void setDetectCallback(const DetectCallback& cb) {
+        detect_callback_ = cb;
+    }
+
     /// @brief Detects network interfaces.
     ///
-    /// This method will eventually detect available interfaces. For now
-    /// it offers stub implementation. First interface name and link-local
-    /// IPv6 address is read from interfaces.txt file.
+    /// If the @ref detect_callback_ returns true, the specific system calls are
+    /// executed, otherwise the @ref detectIfaces will return immediately.
     ///
     /// @param update_only Only add interfaces that do not exist and update
     /// existing interfaces.
@@ -973,7 +988,6 @@ public:
     int openSocketFromRemoteAddress(const isc::asiolink::IOAddress& remote_addr,
                                     const uint16_t port);
 
-
     /// @brief Opens IPv6 sockets on detected interfaces.
     ///
     /// This method opens sockets only on interfaces which have the
@@ -1444,15 +1458,6 @@ protected:
     /// @return Pkt6 object representing received packet (or null)
     Pkt6Ptr receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec = 0);
 
-
-    /// @brief Stub implementation of network interface detection.
-    ///
-    /// This implementations reads a single line from interfaces.txt file
-    /// and pretends to detect such interface. First interface name and
-    /// link-local IPv6 address or IPv4 address is read from the
-    /// interfaces.txt file.
-    void stubDetectIfaces();
-
     /// @brief List of available interfaces
     IfaceCollection ifaces_;
 
@@ -1488,7 +1493,6 @@ private:
     getLocalAddress(const isc::asiolink::IOAddress& remote_addr,
                     const uint16_t port);
 
-
     /// @brief Open an IPv6 socket with multicast support.
     ///
     /// This function opens a socket capable of receiving messages sent to
@@ -1586,6 +1590,13 @@ private:
     /// @brief Indicates if the IfaceMgr is in the test mode.
     bool test_mode_;
 
+    /// @brief Detect callback used to perform action before system dependent
+    /// function calls. Currently this function is used in unittests only.
+    ///
+    /// If the @ref detect_callback_ returns true, the specific system calls are
+    /// executed, otherwise the @ref detectIfaces will return immediately.
+    DetectCallback detect_callback_;
+
     /// @brief Allows to use loopback
     bool allow_loopback_;
 
index bc77d967f1f7a9bc481f96a5f5edf722e350a0b4..3b328cb7814f8878390c6ce90eed2b0ca83822a0 100644 (file)
@@ -31,6 +31,12 @@ namespace dhcp {
 /// This is a BSD specific interface detection method.
 void
 IfaceMgr::detectIfaces(bool update_only) {
+    if (detect_callback_) {
+        if (!detect_callback_(update_only)) {
+            return;
+        }
+    }
+
     if (isTestMode() && update_only) {
         return;
     }
index 4821da64b6058db10ede0316d41623be66387ea8..222e3d648fa04194c9c2c113e8bcd90170d93111 100644 (file)
@@ -414,6 +414,12 @@ namespace dhcp {
 /// Uses the socket-based netlink protocol to retrieve the list of interfaces
 /// from the Linux kernel.
 void IfaceMgr::detectIfaces(bool update_only) {
+    if (detect_callback_) {
+        if (!detect_callback_(update_only)) {
+            return;
+        }
+    }
+
     if (isTestMode() && update_only) {
         return;
     }
index 56b36e027fca7887c8ee5e8059e3fb6e853a135f..c7d7e461aeced7549293789455af150b31fb9f2b 100644 (file)
@@ -31,6 +31,12 @@ namespace dhcp {
 /// only, as earlier versions did not support getifaddrs() API.
 void
 IfaceMgr::detectIfaces(bool update_only) {
+    if (detect_callback_) {
+        if (!detect_callback_(update_only)) {
+            return;
+        }
+    }
+
     if (isTestMode() && update_only) {
         return;
     }
index 23d2f422757fc8616e0744b12f94a235a8e21074..87416b823636386eaec70dc58fdbafb74858467d 100644 (file)
@@ -18,25 +18,6 @@ TESTS_ENVIRONMENT = $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
 TESTS =
 if HAVE_GTEST
 
-# Creates a library which is shared by various unit tests which require
-# configuration of fake interfaces.
-# The libdhcp++ does not link with this library because this would cause
-# build failures being a result of concurrency between build of this
-# library and the unit tests when make -j option was used, as they
-# are built out of the same makefile. Instead, the libdhcp++ tests link to
-# files belonging to this library, directly.
-noinst_LTLIBRARIES = libdhcptest.la
-
-libdhcptest_la_SOURCES  = iface_mgr_test_config.cc iface_mgr_test_config.h
-libdhcptest_la_SOURCES  += pkt_filter_test_stub.cc pkt_filter_test_stub.h
-libdhcptest_la_SOURCES  += pkt_filter6_test_stub.cc pkt_filter6_test_stub.h
-libdhcptest_la_SOURCES  += pkt_captures4.cc pkt_captures6.cc pkt_captures.h
-libdhcptest_la_SOURCES  += packet_queue_testutils.h
-libdhcptest_la_CXXFLAGS  = $(AM_CXXFLAGS)
-libdhcptest_la_CPPFLAGS  = $(AM_CPPFLAGS)
-libdhcptest_la_LDFLAGS   = $(AM_LDFLAGS)
-libdhcptest_la_LIBADD    = $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
-
 TESTS += libdhcp++_unittests
 
 libdhcp___unittests_SOURCES  = run_unittests.cc
@@ -44,7 +25,6 @@ libdhcp___unittests_SOURCES += classify_unittest.cc
 libdhcp___unittests_SOURCES += duid_factory_unittest.cc
 libdhcp___unittests_SOURCES += hwaddr_unittest.cc
 libdhcp___unittests_SOURCES += iface_mgr_unittest.cc
-libdhcp___unittests_SOURCES += iface_mgr_test_config.cc iface_mgr_test_config.h
 libdhcp___unittests_SOURCES += libdhcp++_unittest.cc
 libdhcp___unittests_SOURCES += opaque_data_tuple_unittest.cc
 libdhcp___unittests_SOURCES += option4_addrlst_unittest.cc
@@ -71,7 +51,6 @@ libdhcp___unittests_SOURCES += option_space_unittest.cc
 libdhcp___unittests_SOURCES += option_string_unittest.cc
 libdhcp___unittests_SOURCES += option_vendor_unittest.cc
 libdhcp___unittests_SOURCES += option_vendor_class_unittest.cc
-libdhcp___unittests_SOURCES += pkt_captures4.cc pkt_captures6.cc pkt_captures.h
 libdhcp___unittests_SOURCES += packet_queue4_unittest.cc
 libdhcp___unittests_SOURCES += packet_queue6_unittest.cc
 libdhcp___unittests_SOURCES += packet_queue_mgr4_unittest.cc
@@ -83,8 +62,6 @@ libdhcp___unittests_SOURCES += pkt4o6_unittest.cc
 libdhcp___unittests_SOURCES += pkt_filter_unittest.cc
 libdhcp___unittests_SOURCES += pkt_filter_inet_unittest.cc
 libdhcp___unittests_SOURCES += pkt_filter_inet6_unittest.cc
-libdhcp___unittests_SOURCES += pkt_filter_test_stub.cc pkt_filter_test_stub.h
-libdhcp___unittests_SOURCES += pkt_filter6_test_stub.cc pkt_filter_test_stub.h
 libdhcp___unittests_SOURCES += pkt_filter_test_utils.h pkt_filter_test_utils.cc
 libdhcp___unittests_SOURCES += pkt_filter6_test_utils.h pkt_filter6_test_utils.cc
 
@@ -107,7 +84,8 @@ libdhcp___unittests_LDFLAGS  = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)
 
 libdhcp___unittests_CXXFLAGS = $(AM_CXXFLAGS)
 
-libdhcp___unittests_LDADD  = $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+libdhcp___unittests_LDADD  = $(top_builddir)/src/lib/dhcp/testutils/libdhcptest.la
+libdhcp___unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 libdhcp___unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
 libdhcp___unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
 libdhcp___unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
index 1669983d5d215219f1eb4ea466129070fba9e13f..c5b54f62f004c9ae0ee96ff2d873f99e345e39c5 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/duid_factory.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <testutils/io_utils.h>
 #include <util/encode/hex.h>
 #include <util/range_utilities.h>
index 2761319b30f1b9a7e91f2cf3c9f08a19a2f5693b..ec411a87a087ae271a4654aa258b9233c7137d34 100644 (file)
@@ -12,7 +12,7 @@
 #include <dhcp/option.h>
 #include <dhcp/pkt6.h>
 #include <dhcp/pkt_filter.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp/tests/pkt_filter6_test_utils.h>
 #include <dhcp/tests/packet_queue_testutils.h>
 #include <testutils/gtest_utils.h>
index 70bc624d6b5200c9bca131a1d3ddd9648ea2c53b..bed3f860e58746f36baddf36feb620f15c347313 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <asiolink/io_address.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/libdhcp++.h>
 #include <dhcp/docsis3_option_defs.h>
@@ -19,7 +20,6 @@
 #include <testutils/gtest_utils.h>
 #include <util/buffer.h>
 #include <util/encode/hex.h>
-#include <pkt_captures.h>
 
 #include <boost/shared_array.hpp>
 #include <boost/shared_ptr.hpp>
index 616b89482e829fd04673a5eda1ee89dce87b5cfd..c626d05e73263056cce7f17cbddb6b4e7d411be5 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <asiolink/io_address.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/option.h>
 #include <dhcp/option_custom.h>
@@ -21,7 +22,6 @@
 #include <dhcp/pkt6.h>
 #include <dhcp/hwaddr.h>
 #include <dhcp/docsis3_option_defs.h>
-#include <dhcp/tests/pkt_captures.h>
 #include <testutils/gtest_utils.h>
 #include <util/range_utilities.h>
 #include <boost/date_time/posix_time/posix_time.hpp>
diff --git a/src/lib/dhcp/testutils/Makefile.am b/src/lib/dhcp/testutils/Makefile.am
new file mode 100644 (file)
index 0000000..ae75a27
--- /dev/null
@@ -0,0 +1,25 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+if HAVE_GTEST
+
+noinst_LTLIBRARIES = libdhcptest.la
+
+libdhcptest_la_SOURCES  = iface_mgr_test_config.cc iface_mgr_test_config.h
+libdhcptest_la_SOURCES += pkt_filter_test_stub.cc pkt_filter_test_stub.h
+libdhcptest_la_SOURCES += pkt_filter6_test_stub.cc pkt_filter6_test_stub.h
+libdhcptest_la_SOURCES += pkt_captures4.cc pkt_captures6.cc pkt_captures.h
+
+libdhcptest_la_CXXFLAGS = $(AM_CXXFLAGS)
+libdhcptest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+
+libdhcptest_la_LIBADD  =
+libdhcptest_la_LIBADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+
+endif
similarity index 91%
rename from src/lib/dhcp/tests/iface_mgr_test_config.cc
rename to src/lib/dhcp/testutils/iface_mgr_test_config.cc
index a36786734c7250f9babdcc6cb1ee27c1860c3471..5532fec2557f7c36cbc77791c460769d86308327 100644 (file)
@@ -9,9 +9,9 @@
 #include <dhcp/pkt_filter.h>
 #include <dhcp/pkt_filter_inet.h>
 #include <dhcp/pkt_filter_inet6.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
-#include <dhcp/tests/pkt_filter_test_stub.h>
-#include <dhcp/tests/pkt_filter6_test_stub.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
+#include <dhcp/testutils/pkt_filter_test_stub.h>
+#include <dhcp/testutils/pkt_filter6_test_stub.h>
 
 #include <boost/foreach.hpp>
 
@@ -67,12 +67,15 @@ IfaceMgrTestConfig::addIface(const IfacePtr& iface) {
 }
 
 void
-IfaceMgrTestConfig::addIface(const std::string& name, const unsigned int ifindex) {
+IfaceMgrTestConfig::addIface(const std::string& name,
+                             const unsigned int ifindex) {
     IfaceMgr::instance().addInterface(createIface(name, ifindex));
 }
 
 IfacePtr
-IfaceMgrTestConfig::createIface(const std::string &name, const unsigned int ifindex) {
+IfaceMgrTestConfig::createIface(const std::string& name,
+                                const unsigned int ifindex,
+                                const std::string& mac) {
     IfacePtr iface(new Iface(name, ifindex));
     if (name == "lo") {
         iface->flag_loopback_ = true;
@@ -93,8 +96,9 @@ IfaceMgrTestConfig::createIface(const std::string &name, const unsigned int ifin
     iface->flag_up_ = true;
     iface->flag_running_ = true;
 
-    // Set MAC address to 08:08:08:08:08:08.
-    std::vector<uint8_t> mac_vec(6, 8);
+    // Set MAC address.
+    HWAddr hwaddr = HWAddr::fromText(mac);
+    std::vector<uint8_t> mac_vec = hwaddr.hwaddr_;
     iface->setMac(&mac_vec[0], mac_vec.size());
     iface->setHWType(HTYPE_ETHER);
 
@@ -202,6 +206,6 @@ IfaceMgrTestConfig::unicastOpen(const std::string& iface_name) const {
     return (false);
 }
 
-}
-}
-}
+} // end of namespace isc::dhcp::test
+} // end of namespace isc::dhcp
+} // end of namespace isc
similarity index 96%
rename from src/lib/dhcp/tests/iface_mgr_test_config.h
rename to src/lib/dhcp/testutils/iface_mgr_test_config.h
index 108aca67b8a778011fe236e2a64c247e7bc6281c..2839e4e987d369be787edf6da9716c32c8c349a7 100644 (file)
@@ -191,14 +191,14 @@ public:
     /// - multicast always to true
     /// - broadcast always to false
     ///
-    /// If one needs to modify the default flag settings, the setIfaceFlags
-    /// function should be used.
-    ///
     /// @param name A name of the interface to be created.
     /// @param ifindex An index of the interface to be created.
+    /// @param mac The mac of the interface.
     ///
     /// @return An object representing interface.
-    static IfacePtr createIface(const std::string& name, const unsigned int ifindex);
+    static IfacePtr createIface(const std::string& name,
+                                const unsigned int ifindex,
+                                const std::string& mac = "08:08:08:08:08:08");
 
     /// @brief Creates a default (example) set of fake interfaces.
     void createIfaces();
@@ -258,7 +258,6 @@ public:
     /// @param iface_name Interface name.
     bool unicastOpen(const std::string& iface_name) const;
 
-
 private:
     /// @brief Currently used packet filter for DHCPv4.
     PktFilterPtr packet_filter4_;
@@ -267,8 +266,8 @@ private:
     PktFilter6Ptr packet_filter6_;
 };
 
-};
-};
-};
+} // end of namespace isc::dhcp::test
+} // end of namespace isc::dhcp
+} // end of namespace isc
 
 #endif // IFACE_MGR_TEST_CONFIG_H
similarity index 99%
rename from src/lib/dhcp/tests/pkt_captures4.cc
rename to src/lib/dhcp/testutils/pkt_captures4.cc
index 018506ed43f185bf3b6f34081c0009fab7582f6c..348a17fa6b601b814d3546285c0cb887e651df82 100644 (file)
@@ -5,12 +5,14 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
-#include <dhcp/tests/pkt_captures.h>
-#include <string>
+
 #include <asiolink/io_address.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <util/encode/hex.h>
 
-/// @file   wireshark.cc
+#include <string>
+
+/// @file   pkt_captures.cc
 ///
 /// @brief  contains packet captures imported from Wireshark
 ///
similarity index 99%
rename from src/lib/dhcp/tests/pkt_captures6.cc
rename to src/lib/dhcp/testutils/pkt_captures6.cc
index d1fa4165b649d1991db1d2f1ee2f10d62965db2f..3dee2245551724ebe4928659ab9c1bcca8c1a812 100644 (file)
@@ -5,9 +5,11 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
+
 #include <dhcp/pkt6.h>
+#include <dhcp/testutils/pkt_captures.h>
 #include <util/encode/hex.h>
-#include <dhcp/tests/pkt_captures.h>
+
 #include <string>
 
 /// @file   pkt_captures6.cc
similarity index 95%
rename from src/lib/dhcp/tests/pkt_filter6_test_stub.cc
rename to src/lib/dhcp/testutils/pkt_filter6_test_stub.cc
index b582cc44638cef5700dc8bf8da602b73cddf1eed..e556fa36cfb72a90bf3fd1f09a73e0c5e1c446ce 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 #include <fcntl.h>
 
-#include <dhcp/tests/pkt_filter6_test_stub.h>
+#include <dhcp/testutils/pkt_filter6_test_stub.h>
 
 namespace isc {
 namespace dhcp {
similarity index 96%
rename from src/lib/dhcp/tests/pkt_filter_test_stub.cc
rename to src/lib/dhcp/testutils/pkt_filter_test_stub.cc
index 7e87af504e78ef66d7e9bd994a60b29d10693dc6..a7e17b3897ba1af9e017d788885a87ac205958d2 100644 (file)
@@ -9,7 +9,7 @@
 #include <fcntl.h>
 #include <string.h>
 
-#include <dhcp/tests/pkt_filter_test_stub.h>
+#include <dhcp/testutils/pkt_filter_test_stub.h>
 
 namespace isc {
 namespace dhcp {
index adc821f2d62077a8ce44d8ed20e7dfc2f7e5ce30..77a23c281fdc8054838a38ab6e57ba8ddc514bbe 100644 (file)
@@ -59,7 +59,6 @@ IfacesConfigParser::parse(const CfgIfacePtr& cfg,
             if (element.first == "interfaces") {
                 parseInterfacesList(cfg, element.second);
                 continue;
-
             }
 
             if (element.first == "dhcp-socket-type") {
index a73d0f34a74b493b649f370d1d4cdf1e5ede3e88..c59b10374b7940e505e94adf1e44740e950d3b10 100644 (file)
@@ -166,7 +166,7 @@ libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
-libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/dhcp/tests/libdhcptest.la
+libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/dhcp/testutils/libdhcptest.la
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
 
index 03591c01047c97e4998a1b28cfd53941579fb159..be0856ee057aeddb6f3f57faa8d5b9c6c8c1f46a 100644 (file)
@@ -6,9 +6,9 @@
 
 #include <config.h>
 #include <dhcp/dhcp4.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
-#include <dhcp/tests/pkt_filter_test_stub.h>
-#include <dhcp/tests/pkt_filter6_test_stub.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
+#include <dhcp/testutils/pkt_filter_test_stub.h>
+#include <dhcp/testutils/pkt_filter6_test_stub.h>
 #include <dhcpsrv/cfg_iface.h>
 #include <asiolink/io_service.h>
 #include <asiolink/asio_wrapper.h>
index 73c36a7260d1a83dec086b9239b3229a03287217..f1472e645cc8216289e347ff878c0e4a8c1f5428 100644 (file)
@@ -13,7 +13,7 @@
 #include <dhcp/option_definition.h>
 #include <dhcp/option_space.h>
 #include <dhcp/option_string.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/parsers/dhcp_parsers.h>
index ece583fb0712f2a3fc6566654ce0f8bedb96dec2..83fad92123eba396112e911610eccc20c2257d36 100644 (file)
@@ -11,7 +11,7 @@
 #include <dhcp/dhcp6.h>
 #include <dhcp/option.h>
 #include <dhcp/option_string.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_shared_networks.h>
 #include <dhcpsrv/cfg_subnets6.h>
index 47f9cff104f74ff58dc29009e0d8272602498417..1be8c6845624e615122ddc7e5d2e7f439f8411ef 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <exceptions/exceptions.h>
 #include <dhcp/dhcp6.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/subnet_id.h>
index 192bb63d547e3f4ebf11b445ad1ee6b0fae7bc62..4a327cde13bf5764d95df00693f02119325f3f7a 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <dhcp/iface_mgr.h>
 #include <dhcp/pkt6.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp/option6_addrlst.h>
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
index 3a8bb7ca5d99254a61a04d97270734a0d2bf770f..e893ce75792eee8f619c8ca0f3d3a8bfeaa22c50 100644 (file)
@@ -14,7 +14,7 @@
 #include <dhcp/option_string.h>
 #include <dhcp/option4_addrlst.h>
 #include <dhcp/option6_addrlst.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/cfg_mac_source.h>
index 9e6546246bc351543aae59e10a3a6827bfffb848..aec05d9e90dc83bb73f48fd53d63dbfc5ff89afa 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 
 #include <cc/data.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/parsers/ifaces_config_parser.h>
 #include <testutils/test_to_element.h>
index ea2f3b3af9744b905be2c5a0eaef75b9e53d5bb0..3472e0f19018457f18c08b7edd51047541876aa0 100644 (file)
@@ -12,7 +12,7 @@
 #include <dhcp/option.h>
 #include <dhcp/option4_addrlst.h>
 #include <dhcp/option6_addrlst.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/parsers/shared_network_parser.h>
 #include <testutils/gtest_utils.h>
index cf7516f4f15233ca1a67b68f0b0dc1ec606e027a..9aa886dfcc9aaef7090a160d14201632227a08c6 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <config.h>
 #include <cc/data.h>
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfg_shared_networks.h>
 #include <dhcpsrv/shared_network.h>
 #include <dhcpsrv/parsers/shared_networks_list_parser.h>
index b5545a626434ea91c24ca2ad322b3b2dc1a0d80b..3cf7032c41d0c50c59e54ffeb231b43a052f7eb3 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <config.h>
 
-#include <dhcp/tests/iface_mgr_test_config.h>
+#include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/client_class_def.h>
 #include <dhcpsrv/srv_config.h>