Commit 578bf4d0 authored by Marcin Siodelski's avatar Marcin Siodelski

[3512] Renamed IfaceCfg to CfgIface as suggested in the review.

parent dddc0834
......@@ -177,7 +177,7 @@ void ControlledDhcpv4Srv::init(const std::string& config_file) {
// Configuration may disable or enable interfaces so we have to
// reopen sockets according to new configuration.
CfgMgr::instance().getConfiguration()->iface_cfg_
CfgMgr::instance().getConfiguration()->cfg_iface_
.openSockets(getPort(), useBroadcast());
} catch (const std::exception& ex) {
......
......@@ -149,7 +149,7 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
// safe and we really don't want to emit exceptions to whoever called this
// method. Instead, catch an exception and create appropriate answer.
try {
CfgMgr::instance().getConfiguration()->iface_cfg_
CfgMgr::instance().getConfiguration()->cfg_iface_
.openSockets(srv->getPort(), getInstance()->useBroadcast());
} catch (std::exception& ex) {
......
......@@ -2917,7 +2917,7 @@ TEST_F(Dhcp4ParserTest, selectedInterfaces) {
ASSERT_TRUE(status);
checkResult(status, 0);
CfgMgr::instance().getConfiguration()->iface_cfg_.openSockets(10000);
CfgMgr::instance().getConfiguration()->cfg_iface_.openSockets(10000);
// eth0 and eth1 were explicitly selected. eth2 was not.
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET));
......@@ -2952,7 +2952,7 @@ TEST_F(Dhcp4ParserTest, allInterfaces) {
ASSERT_TRUE(status);
checkResult(status, 0);
CfgMgr::instance().getConfiguration()->iface_cfg_.openSockets(10000);
CfgMgr::instance().getConfiguration()->cfg_iface_.openSockets(10000);
// All interfaces should be now active.
ASSERT_TRUE(test_config.socketOpen("eth0", AF_INET));
......
......@@ -45,7 +45,7 @@ Dhcpv4SrvTest::Dhcpv4SrvTest()
pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.100"), IOAddress("192.0.2.110")));
subnet_->addPool(pool_);
CfgMgr::instance().getConfiguration()->iface_cfg_.reset();
CfgMgr::instance().getConfiguration()->cfg_iface_.reset();
CfgMgr::instance().deleteSubnets4();
CfgMgr::instance().addSubnet4(subnet_);
......@@ -58,7 +58,7 @@ Dhcpv4SrvTest::Dhcpv4SrvTest()
Dhcpv4SrvTest::~Dhcpv4SrvTest() {
// Make sure that we revert to default value
CfgMgr::instance().getConfiguration()->iface_cfg_.reset();
CfgMgr::instance().getConfiguration()->cfg_iface_.reset();
CfgMgr::instance().echoClientId(true);
}
......
......@@ -183,7 +183,10 @@ ControlledDhcpv6Srv::init(const std::string& config_file) {
// Configuration may disable or enable interfaces so we have to
// reopen sockets according to new configuration.
openActiveSockets(getPort());
// Configuration may disable or enable interfaces so we have to
// reopen sockets according to new configuration.
CfgMgr::instance().getConfiguration()->cfg_iface_
.openSockets(getPort(), useBroadcast());
} catch (const std::exception& ex) {
LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL).arg(ex.what());
......
......@@ -144,7 +144,7 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
// safe and we really don't want to emit exceptions to the callback caller.
// Instead, catch an exception and create appropriate answer.
try {
CfgMgr::instance().getConfiguration()->iface_cfg_
CfgMgr::instance().getConfiguration()->cfg_iface_
.openSockets(srv->getPort());
} catch (const std::exception& ex) {
......
......@@ -154,7 +154,7 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
// domain, so as the IPv6 sockets are opened rather than IPv4 sockets
// which are the default.
CfgMgr::instance().getConfiguration()
->iface_cfg_.setFamily(IfaceCfg::V6);
->cfg_iface_.setFamily(CfgIface::V6);
/// @todo call loadLibraries() when handling configuration changes
......
......@@ -359,9 +359,9 @@ public:
// properly test interface configuration we disable listening on
// all interfaces before each test and later check that this setting
// has been overriden by the configuration used in the test.
CfgMgr::instance().getConfiguration()->iface_cfg_.reset();
CfgMgr::instance().getConfiguration()->cfg_iface_.reset();
CfgMgr::instance().getConfiguration()->
iface_cfg_.setFamily(IfaceCfg::V6);
cfg_iface_.setFamily(CfgIface::V6);
// Create fresh context.
globalContext()->copyContext(ParserContext(Option::V6));
}
......@@ -3057,7 +3057,7 @@ TEST_F(Dhcp6ParserTest, selectedInterfaces) {
// as the pool does not belong to that subnet
checkResult(status, 0);
CfgMgr::instance().getConfiguration()->iface_cfg_.openSockets(10000);
CfgMgr::instance().getConfiguration()->cfg_iface_.openSockets(10000);
// eth0 and eth1 were explicitly selected. eth2 was not.
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET6));
......@@ -3090,7 +3090,7 @@ TEST_F(Dhcp6ParserTest, allInterfaces) {
EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
checkResult(status, 0);
CfgMgr::instance().getConfiguration()->iface_cfg_.openSockets(10000);
CfgMgr::instance().getConfiguration()->cfg_iface_.openSockets(10000);
// All interfaces should be now active.
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET6));
......
......@@ -55,7 +55,7 @@ libkea_dhcpsrv_la_SOURCES += dhcpsrv_log.cc dhcpsrv_log.h
libkea_dhcpsrv_la_SOURCES += cfgmgr.cc cfgmgr.h
libkea_dhcpsrv_la_SOURCES += dhcp_config_parser.h
libkea_dhcpsrv_la_SOURCES += dhcp_parsers.cc dhcp_parsers.h
libkea_dhcpsrv_la_SOURCES += iface_cfg.cc iface_cfg.h
libkea_dhcpsrv_la_SOURCES += cfg_iface.cc cfg_iface.h
libkea_dhcpsrv_la_SOURCES += key_from_key.h
libkea_dhcpsrv_la_SOURCES += lease.cc lease.h
libkea_dhcpsrv_la_SOURCES += lease_mgr.cc lease_mgr.h
......
......@@ -14,7 +14,7 @@
#include <dhcp/iface_mgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/iface_cfg.h>
#include <dhcpsrv/cfg_iface.h>
#include <util/strutil.h>
#include <boost/bind.hpp>
......@@ -23,20 +23,20 @@ using namespace isc::asiolink;
namespace isc {
namespace dhcp {
const char* IfaceCfg::ALL_IFACES_KEYWORD = "*";
const char* CfgIface::ALL_IFACES_KEYWORD = "*";
IfaceCfg::IfaceCfg(Family family)
CfgIface::CfgIface(Family family)
: family_(family),
wildcard_used_(false) {
}
void
IfaceCfg::closeSockets() {
CfgIface::closeSockets() {
IfaceMgr::instance().closeSockets();
}
void
IfaceCfg::openSockets(const uint16_t port, const bool use_bcast) {
CfgIface::openSockets(const uint16_t port, const bool use_bcast) {
// If wildcard interface '*' was not specified, set all interfaces to
// inactive state. We will later enable them selectively using the
// interface names specified by the user. If wildcard interface was
......@@ -93,7 +93,7 @@ IfaceCfg::openSockets(const uint16_t port, const bool use_bcast) {
// for some specific interface. This callback will simply log a
// warning message.
IfaceMgrErrorMsgCallback error_callback =
boost::bind(&IfaceCfg::socketOpenErrorHandler, _1);
boost::bind(&CfgIface::socketOpenErrorHandler, _1);
bool sopen;
if (getFamily() == V4) {
sopen = IfaceMgr::instance().openSockets4(port, use_bcast,
......@@ -111,13 +111,13 @@ IfaceCfg::openSockets(const uint16_t port, const bool use_bcast) {
}
void
IfaceCfg::reset() {
CfgIface::reset() {
wildcard_used_ = false;
iface_set_.clear();
}
void
IfaceCfg::setState(const bool inactive, const bool loopback_inactive) {
CfgIface::setState(const bool inactive, const bool loopback_inactive) {
IfaceMgr::IfaceCollection ifaces = IfaceMgr::instance().getIfaces();
for (IfaceMgr::IfaceCollection::iterator iface = ifaces.begin();
iface != ifaces.end(); ++iface) {
......@@ -133,12 +133,12 @@ IfaceCfg::setState(const bool inactive, const bool loopback_inactive) {
}
void
IfaceCfg::socketOpenErrorHandler(const std::string& errmsg) {
CfgIface::socketOpenErrorHandler(const std::string& errmsg) {
LOG_WARN(dhcpsrv_logger, DHCPSRV_OPEN_SOCKET_FAIL).arg(errmsg);
}
void
IfaceCfg::use(const std::string& iface_name) {
CfgIface::use(const std::string& iface_name) {
// The interface name specified may have two formats, e.g.:
// - eth0
// - eth0/2001:db8:1::1.
......
......@@ -63,8 +63,8 @@ public:
/// instructs the server to listen on all available interfaces.
///
/// Once interfaces have been specified the sockets (either IPv4 or IPv6)
/// can be opened by calling @c IfaceCfg::openSockets function.
class IfaceCfg {
/// can be opened by calling @c CfgIface::openSockets function.
class CfgIface {
public:
/// @brief Keyword used to enable all interfaces.
///
......@@ -83,12 +83,12 @@ public:
/// @brief Constructor.
///
/// @param family Protocol family (default is V4).
IfaceCfg(Family family = V4);
CfgIface(Family family = V4);
/// @brief Convenience function which closes all open sockets.
void closeSockets();
/// @brief Returns protocol family used by the @c IfaceCfg.
/// @brief Returns protocol family used by the @c CfgIface.
Family getFamily() const {
return (family_);
}
......@@ -96,7 +96,7 @@ public:
/// @brief Tries to open sockets on selected interfaces.
///
/// This function opens sockets bound to link-local address as well as
/// sockets bound to unicast address. See @c IfaceCfg::use function
/// sockets bound to unicast address. See @c CfgIface::use function
/// documentation for details how to specify interfaces and unicast
/// addresses to bind the sockets to.
///
......@@ -147,7 +147,7 @@ public:
/// to the interface.
/// @throw DuplicateIfaceName If the interface is already selected, i.e.
/// @throw IOError when specified unicast address is invalid.
/// @c IfaceCfg::use has been already called for this interface.
/// @c CfgIface::use has been already called for this interface.
void use(const std::string& iface_name);
private:
......
......@@ -15,7 +15,7 @@
#ifndef DHCPSRV_CONFIGURATION_H
#define DHCPSRV_CONFIGURATION_H
#include <dhcpsrv/iface_cfg.h>
#include <dhcpsrv/cfg_iface.h>
#include <log/logger_level.h>
#include <boost/shared_ptr.hpp>
#include <vector>
......@@ -90,7 +90,7 @@ struct Configuration {
///
/// Used to select interfaces on which the DHCP server will listen to
/// queries.
IfaceCfg iface_cfg_;
CfgIface cfg_iface_;
};
......
......@@ -190,11 +190,11 @@ InterfaceListConfigParser(const std::string& param_name)
void
InterfaceListConfigParser::build(ConstElementPtr value) {
ConfigurationPtr config = CfgMgr::instance().getConfiguration();
config->iface_cfg_.reset();
config->cfg_iface_.reset();
BOOST_FOREACH(ConstElementPtr iface, value->listValue()) {
std::string iface_name = iface->stringValue();
try {
config->iface_cfg_.use(iface_name);
config->cfg_iface_.use(iface_name);
} catch (const std::exception& ex) {
isc_throw(DhcpConfigError, "Failed to select interface: "
......
......@@ -63,7 +63,7 @@ libdhcpsrv_unittests_SOURCES += d2_client_unittest.cc
libdhcpsrv_unittests_SOURCES += d2_udp_unittest.cc
libdhcpsrv_unittests_SOURCES += daemon_unittest.cc
libdhcpsrv_unittests_SOURCES += dbaccess_parser_unittest.cc
libdhcpsrv_unittests_SOURCES += iface_cfg_unittest.cc
libdhcpsrv_unittests_SOURCES += cfg_iface_unittest.cc
libdhcpsrv_unittests_SOURCES += lease_file_io.cc lease_file_io.h
libdhcpsrv_unittests_SOURCES += lease_unittest.cc
libdhcpsrv_unittests_SOURCES += lease_mgr_factory_unittest.cc
......
......@@ -15,7 +15,7 @@
#include <config.h>
#include <dhcp/dhcp4.h>
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcpsrv/iface_cfg.h>
#include <dhcpsrv/cfg_iface.h>
#include <gtest/gtest.h>
using namespace isc;
......@@ -24,15 +24,15 @@ using namespace isc::dhcp::test;
namespace {
/// @brief Test fixture class for testing the @c IfaceCfg class.
class IfaceCfgTest : public ::testing::Test {
/// @brief Test fixture class for testing the @c CfgIface class.
class CfgIfaceTest : public ::testing::Test {
public:
/// @brief Constructor.
///
/// By initializing the @c IfaceMgrTestConfig object it creates a set of
/// fake interfaces: lo, eth0, eth1.
IfaceCfgTest() :
CfgIfaceTest() :
iface_mgr_test_config_(true) {
}
......@@ -53,19 +53,19 @@ public:
};
bool
IfaceCfgTest::socketOpen(const std::string& iface_name,
CfgIfaceTest::socketOpen(const std::string& iface_name,
const int family) const {
return (iface_mgr_test_config_.socketOpen(iface_name, family));
}
bool
IfaceCfgTest::unicastOpen(const std::string& iface_name) const {
CfgIfaceTest::unicastOpen(const std::string& iface_name) const {
return (iface_mgr_test_config_.unicastOpen(iface_name));
}
// This test checks that the interface names can be explicitly selected
// by their names and IPv4 sockets are opened on these interfaces.
TEST_F(IfaceCfgTest, explicitNamesV4) {
IfaceCfg cfg(IfaceCfg::V4);
TEST_F(CfgIfaceTest, explicitNamesV4) {
CfgIface cfg(CfgIface::V4);
// Specify valid interface names. There should be no error.
ASSERT_NO_THROW(cfg.use("eth0"));
ASSERT_NO_THROW(cfg.use("eth1"));
......@@ -104,8 +104,8 @@ TEST_F(IfaceCfgTest, explicitNamesV4) {
// This test checks that the interface names can be explicitly selected
// by their names and IPv6 sockets are opened on these interfaces.
TEST_F(IfaceCfgTest, explicitNamesV6) {
IfaceCfg cfg(IfaceCfg::V6);
TEST_F(CfgIfaceTest, explicitNamesV6) {
CfgIface cfg(CfgIface::V6);
// Specify valid interface names. There should be no error.
ASSERT_NO_THROW(cfg.use("eth0"));
ASSERT_NO_THROW(cfg.use("eth1"));
......@@ -144,9 +144,9 @@ TEST_F(IfaceCfgTest, explicitNamesV6) {
// This test checks that the wildcard interface name can be specified to
// select all interfaces to open IPv4 sockets.
TEST_F(IfaceCfgTest, wildcardV4) {
IfaceCfg cfg(IfaceCfg::V4);
ASSERT_NO_THROW(cfg.use(IfaceCfg::ALL_IFACES_KEYWORD));
TEST_F(CfgIfaceTest, wildcardV4) {
CfgIface cfg(CfgIface::V4);
ASSERT_NO_THROW(cfg.use(CfgIface::ALL_IFACES_KEYWORD));
cfg.openSockets(DHCP4_SERVER_PORT);
......@@ -163,9 +163,9 @@ TEST_F(IfaceCfgTest, wildcardV4) {
// This test checks that the wildcard interface name can be specified to
// select all interfaces to open IPv6 sockets.
TEST_F(IfaceCfgTest, wildcardV6) {
IfaceCfg cfg(IfaceCfg::V6);
ASSERT_NO_THROW(cfg.use(IfaceCfg::ALL_IFACES_KEYWORD));
TEST_F(CfgIfaceTest, wildcardV6) {
CfgIface cfg(CfgIface::V6);
ASSERT_NO_THROW(cfg.use(CfgIface::ALL_IFACES_KEYWORD));
cfg.openSockets(DHCP4_SERVER_PORT);
......@@ -183,8 +183,8 @@ TEST_F(IfaceCfgTest, wildcardV6) {
// Test that unicast address can be specified for the socket to be opened on
// the interface on which the socket bound to link local address is also
// opened.
TEST_F(IfaceCfgTest, validUnicast) {
IfaceCfg cfg(IfaceCfg::V6);
TEST_F(CfgIfaceTest, validUnicast) {
CfgIface cfg(CfgIface::V6);
// One socket will be opened on link-local address, one on unicast but
// on the same interface.
......@@ -198,8 +198,8 @@ TEST_F(IfaceCfgTest, validUnicast) {
}
// Test that when invalid interface names are specified an exception is thrown.
TEST_F(IfaceCfgTest, invalidValues) {
IfaceCfg cfg(IfaceCfg::V4);
TEST_F(CfgIfaceTest, invalidValues) {
CfgIface cfg(CfgIface::V4);
ASSERT_THROW(cfg.use(""), InvalidIfaceName);
ASSERT_THROW(cfg.use(" "), InvalidIfaceName);
ASSERT_THROW(cfg.use("bogus"), NoSuchIface);
......@@ -209,7 +209,7 @@ TEST_F(IfaceCfgTest, invalidValues) {
ASSERT_THROW(cfg.use("eth0/2001:db8:1::1"), InvalidIfaceName);
cfg.setFamily(IfaceCfg::V6);
cfg.setFamily(CfgIface::V6);
ASSERT_THROW(cfg.use("eth0/"), InvalidIfaceName);
ASSERT_THROW(cfg.use("/2001:db8:1::1"), InvalidIfaceName);
......@@ -219,8 +219,8 @@ TEST_F(IfaceCfgTest, invalidValues) {
ASSERT_THROW(cfg.use("eth0/fe80::3a60:77ff:fed5:cdef"), InvalidIfaceName);
ASSERT_THROW(cfg.use("eth0/2001:db8:1::2"), NoSuchAddress);
ASSERT_NO_THROW(cfg.use(IfaceCfg::ALL_IFACES_KEYWORD));
ASSERT_THROW(cfg.use(IfaceCfg::ALL_IFACES_KEYWORD), DuplicateIfaceName);
ASSERT_NO_THROW(cfg.use(CfgIface::ALL_IFACES_KEYWORD));
ASSERT_THROW(cfg.use(CfgIface::ALL_IFACES_KEYWORD), DuplicateIfaceName);
}
} // end of anonymous namespace
......@@ -59,8 +59,8 @@ public:
/// @brief Resets selection of the interfaces from previous tests.
void resetIfaceCfg() {
CfgMgr::instance().getConfiguration()->iface_cfg_.closeSockets();
CfgMgr::instance().getConfiguration()->iface_cfg_.reset();
CfgMgr::instance().getConfiguration()->cfg_iface_.closeSockets();
CfgMgr::instance().getConfiguration()->cfg_iface_.reset();
}
};
......@@ -241,7 +241,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) {
// eth2 was not added.
ConfigurationPtr cfg = CfgMgr::instance().getConfiguration();
ASSERT_TRUE(cfg);
ASSERT_NO_THROW(cfg->iface_cfg_.openSockets(10000));
ASSERT_NO_THROW(cfg->cfg_iface_.openSockets(10000));
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET));
EXPECT_FALSE(test_config.socketOpen("eth1", AF_INET));
......@@ -253,11 +253,11 @@ TEST_F(DhcpParserTest, interfaceListParserTest) {
// Reset parser and configuration.
parser.reset(new InterfaceListConfigParser(name));
cfg->iface_cfg_.closeSockets();
cfg->iface_cfg_.reset();
cfg->cfg_iface_.closeSockets();
cfg->cfg_iface_.reset();
parser->build(list_element);
ASSERT_NO_THROW(cfg->iface_cfg_.openSockets(10000));
ASSERT_NO_THROW(cfg->cfg_iface_.openSockets(10000));
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET));
EXPECT_TRUE(test_config.socketOpen("eth1", AF_INET));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment