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])
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
#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>
#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>
#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>
#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>
class NakedControlledDhcpv4Srv: public ControlledDhcpv4Srv {
// "Naked" DHCPv4 server, exposes internal fields
public:
- NakedControlledDhcpv4Srv():ControlledDhcpv4Srv(0) {
+ NakedControlledDhcpv4Srv() : ControlledDhcpv4Srv(0) {
CfgMgr::instance().setFamily(AF_INET);
}
/// @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";
socket_path_ = sandbox.join("kea4.sock");
}
reset();
+ IfaceMgr::instance().setTestMode(false);
+ IfaceMgr::instance().setDetectCallback(isc::dhcp::IfaceMgr::DetectCallback());
}
/// @brief Destructor
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.
std::string header =
"{"
" \"interfaces-config\": {"
- " \"interfaces\": [ \"*\" ]"
+ " \"interfaces\": [";
+
+ std::string body = "]"
" },"
" \"expired-leases-processing\": {"
" \"reclaim-timer-wait-time\": 60,"
// 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;
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
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
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
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
sendUnixCommand("{ \"command\": \"config-write\", "
"\"arguments\": { \"filename\": \"test2.json\" } }", response);
+
checkConfigWrite(response, CONTROL_RESULT_SUCCESS, "test2.json");
::remove("test2.json");
}
// 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
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
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
#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>
#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>
#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>
#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>
#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>
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);
}
reset();
};
-
/// @brief Reset hooks data
///
/// Resets the data for the hooks-related portion of the test by ensuring
/// @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";
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.
std::string header =
"{"
" \"interfaces-config\": {"
- " \"interfaces\": [ \"*\" ]"
+ " \"interfaces\": [";
+
+ std::string body = "]"
" },"
" \"expired-leases-processing\": {"
" \"reclaim-timer-wait-time\": 60,"
// 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;
sendUnixCommand("{ \"command\": \"config-write\", "
"\"arguments\": { \"filename\": \"test2.json\" } }", response);
+
checkConfigWrite(response, CONTROL_RESULT_SUCCESS, "test2.json");
::remove("test2.json");
}
::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) {
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
// 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>
#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>
#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>
// 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>
#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>
#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>
#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>
-SUBDIRS = . tests
+SUBDIRS = . testutils tests
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
// 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");
}
}
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,
/// @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.
/// @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.
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
/// @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_;
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
/// @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_;
/// 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;
}
/// 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;
}
/// 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;
}
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
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
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
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
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
#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>
#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>
#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>
#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>
#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>
#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>
--- /dev/null
+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
#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>
}
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;
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);
return (false);
}
-}
-}
-}
+} // end of namespace isc::dhcp::test
+} // end of namespace isc::dhcp
+} // end of namespace isc
/// - 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();
/// @param iface_name Interface name.
bool unicastOpen(const std::string& iface_name) const;
-
private:
/// @brief Currently used packet filter for DHCPv4.
PktFilterPtr packet_filter4_;
PktFilter6Ptr packet_filter6_;
};
-};
-};
-};
+} // end of namespace isc::dhcp::test
+} // end of namespace isc::dhcp
+} // end of namespace isc
#endif // IFACE_MGR_TEST_CONFIG_H
// 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
///
// 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
#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 {
#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 {
if (element.first == "interfaces") {
parseInterfacesList(cfg, element.second);
continue;
-
}
if (element.first == "dhcp-socket-type") {
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
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>
#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>