2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[#3017] added testing framework for using dummy test interfaces

This commit is contained in:
Razvan Becheriu 2023-10-14 01:56:20 +03:00 committed by Andrei Pavel
parent 530e4ef280
commit 34e98d10f6
83 changed files with 363 additions and 192 deletions

View 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])

View 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

View 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>

View 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>

View 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>

View 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>/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_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>/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

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View File

@ -27,13 +27,13 @@
#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>

View 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

View File

@ -10,12 +10,12 @@
#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>

View 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>

View 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>

View 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>

View 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) {

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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)

View 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");
}
}

View 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,

View 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_;

View 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;
}

View 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;
}

View 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;
}

View 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

View 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>

View 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>

View 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>

View 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>

View File

@ -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

View 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

View 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

View 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
///

View 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

View 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 {

View 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 {

View 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") {

View 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

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>

View 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>