From: Marcin Siodelski Date: Thu, 14 Jun 2018 10:04:39 +0000 (+0200) Subject: [5649] Created common header file with control channel timeouts. X-Git-Tag: Kea-1.4.0~1^2~3^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e72a0654e705cc2cdc2f7b8f9cbdcaa92b1815d8;p=thirdparty%2Fkea.git [5649] Created common header file with control channel timeouts. --- diff --git a/src/bin/agent/ca_command_mgr.cc b/src/bin/agent/ca_command_mgr.cc index 37f44372b0..6386527b4c 100644 --- a/src/bin/agent/ca_command_mgr.cc +++ b/src/bin/agent/ca_command_mgr.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -30,14 +31,6 @@ using namespace isc::data; using namespace isc::hooks; using namespace isc::process; -namespace { - -/// @brief Client side connection timeout. -/// @todo Make it configurable. -const long CONNECTION_TIMEOUT = 60000; - -} - namespace isc { namespace agent { @@ -241,7 +234,7 @@ CtrlAgentCommandMgr::forwardCommand(const std::string& service, // Got the IO service so stop IO service. This causes to // stop IO service when all handlers have been invoked. io_service->stopWork(); - }, ClientConnection::Timeout(CONNECTION_TIMEOUT)); + }, ClientConnection::Timeout(TIMEOUT_AGENT_FORWARD_COMMAND)); io_service->run(); if (received_ec) { diff --git a/src/bin/agent/ca_process.cc b/src/bin/agent/ca_process.cc index 2f2e157bba..0e96ceb6d4 100644 --- a/src/bin/agent/ca_process.cc +++ b/src/bin/agent/ca_process.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -13,22 +13,15 @@ #include #include #include +#include #include using namespace isc::asiolink; +using namespace isc::config; using namespace isc::data; using namespace isc::http; using namespace isc::process; -// Temporarily hardcoded configuration. -/// @todo: remove once 5134 is merged. -namespace { - -const long REQUEST_TIMEOUT = 10000; - -const long IDLE_TIMEOUT = 30000; - -} namespace isc { namespace agent { @@ -153,11 +146,11 @@ CtrlAgentProcess::configure(isc::data::ConstElementPtr config_set, // Create http listener. It will open up a TCP socket and be // prepared to accept incoming connection. - HttpListenerPtr - http_listener(new HttpListener(*getIoService(), server_address, - server_port, rcf, - HttpListener::RequestTimeout(REQUEST_TIMEOUT), - HttpListener::IdleTimeout(IDLE_TIMEOUT))); + HttpListenerPtr http_listener + (new HttpListener(*getIoService(), server_address, + server_port, rcf, + HttpListener::RequestTimeout(TIMEOUT_AGENT_RECEIVE_COMMAND), + HttpListener::IdleTimeout(TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT))); // Instruct the http listener to actually open socket, install // callback and start listening. diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 60f41f8768..ab61bf3c85 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -89,9 +90,6 @@ public: using Dhcpv4Srv::network_state_; }; -/// @brief Default control connection timeout. -const size_t DEFAULT_CONNECTION_TIMEOUT = 10; - /// @brief Fixture class intended for testin control channel in the DHCPv4Srv class CtrlChannelDhcpv4SrvTest : public ::testing::Test { public: @@ -122,7 +120,7 @@ public: CommandMgr::instance().closeCommandSocket(); CommandMgr::instance().deregisterAll(); - CommandMgr::instance().setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); + CommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND); server_.reset(); }; @@ -1420,7 +1418,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, connectionTimeoutPartialCommand) { // Set connection timeout to 2s to prevent long waiting time for the // timeout during this test. - const unsigned short timeout = 2; + const unsigned short timeout = 2000; CommandMgr::instance().setConnectionTimeout(timeout); // Server's response will be assigned to this variable. @@ -1474,7 +1472,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, connectionTimeoutNoData) { // Set connection timeout to 2s to prevent long waiting time for the // timeout during this test. - const unsigned short timeout = 2; + const unsigned short timeout = 2000; CommandMgr::instance().setConnectionTimeout(timeout); // Server's response will be assigned to this variable. diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index c11fb801d3..765a9905d8 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -87,7 +87,7 @@ public: }; /// @brief Default control connection timeout. -const size_t DEFAULT_CONNECTION_TIMEOUT = 10; +const size_t DEFAULT_CONNECTION_TIMEOUT = 10000; class CtrlDhcpv6SrvTest : public BaseServerTest { public: @@ -1441,7 +1441,7 @@ TEST_F(CtrlChannelDhcpv6SrvTest, connectionTimeoutPartialCommand) { // Set connection timeout to 2s to prevent long waiting time for the // timeout during this test. - const unsigned short timeout = 2; + const unsigned short timeout = 2000; CommandMgr::instance().setConnectionTimeout(timeout); // Server's response will be assigned to this variable. @@ -1495,7 +1495,7 @@ TEST_F(CtrlChannelDhcpv6SrvTest, connectionTimeoutNoData) { // Set connection timeout to 2s to prevent long waiting time for the // timeout during this test. - const unsigned short timeout = 2; + const unsigned short timeout = 2000; CommandMgr::instance().setConnectionTimeout(timeout); // Server's response will be assigned to this variable. diff --git a/src/lib/config/Makefile.am b/src/lib/config/Makefile.am index b4e65f6978..8b2102dfd2 100644 --- a/src/lib/config/Makefile.am +++ b/src/lib/config/Makefile.am @@ -21,6 +21,7 @@ libkea_cfgclient_la_SOURCES += client_connection.cc client_connection.h libkea_cfgclient_la_SOURCES += command_mgr.cc command_mgr.h libkea_cfgclient_la_SOURCES += config_log.h config_log.cc libkea_cfgclient_la_SOURCES += hooked_command_mgr.cc hooked_command_mgr.h +libkea_cfgclient_la_SOURCES += timeouts.h libkea_cfgclient_la_LIBADD = $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la libkea_cfgclient_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la @@ -52,6 +53,6 @@ libkea_cfgclient_include_HEADERS = \ cmds_impl.h \ command_mgr.h \ config_log.h \ - hooked_command_mgr.h - + hooked_command_mgr.h \ + timeouts.h diff --git a/src/lib/config/command_mgr.cc b/src/lib/config/command_mgr.cc index f4a0a4105c..55f35c80b7 100644 --- a/src/lib/config/command_mgr.cc +++ b/src/lib/config/command_mgr.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -34,9 +35,6 @@ namespace { /// @brief Maximum size of the data chunk sent/received over the socket. const size_t BUF_SIZE = 8192; -/// @brief Default connection timeout in seconds. -const unsigned short DEFAULT_CONNECTION_TIMEOUT = 10; - class ConnectionPool; /// @brief Represents a single connection over control socket. @@ -66,7 +64,7 @@ public: Connection(const IOServicePtr& io_service, const boost::shared_ptr& socket, ConnectionPool& connection_pool, - const unsigned short timeout) + const long timeout) : socket_(socket), timeout_timer_(*io_service), timeout_(timeout), buf_(), response_(), connection_pool_(connection_pool), feed_(), response_in_progress_(false), watch_socket_(new util::WatchSocket()) { @@ -96,7 +94,7 @@ public: /// @brief This method schedules timer or reschedules existing timer. void scheduleTimer() { timeout_timer_.setup(boost::bind(&Connection::timeoutHandler, this), - timeout_ * 1000, IntervalTimer::ONE_SHOT); + timeout_, IntervalTimer::ONE_SHOT); } /// @brief Close current connection. @@ -207,8 +205,8 @@ private: /// @brief Interval timer used to detect connection timeouts. IntervalTimer timeout_timer_; - /// @brief Connection timeout (in seconds) - unsigned short timeout_; + /// @brief Connection timeout (in milliseconds) + long timeout_; /// @brief Buffer used for received data. std::array buf_; @@ -476,7 +474,7 @@ public: /// @brief Constructor. CommandMgrImpl() : io_service_(), acceptor_(), socket_(), socket_name_(), - connection_pool_(), timeout_(DEFAULT_CONNECTION_TIMEOUT) { + connection_pool_(), timeout_(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND) { } /// @brief Opens acceptor service allowing the control clients to connect. @@ -508,7 +506,7 @@ public: ConnectionPool connection_pool_; /// @brief Connection timeout - unsigned short timeout_; + long timeout_; }; void @@ -627,7 +625,7 @@ CommandMgr::setIOService(const IOServicePtr& io_service) { } void -CommandMgr::setConnectionTimeout(const unsigned short timeout) { +CommandMgr::setConnectionTimeout(const long timeout) { impl_->timeout_ = timeout; } diff --git a/src/lib/config/command_mgr.h b/src/lib/config/command_mgr.h index 5eb23015fb..2559d04638 100644 --- a/src/lib/config/command_mgr.h +++ b/src/lib/config/command_mgr.h @@ -56,8 +56,8 @@ public: /// @brief Override default connection timeout. /// - /// @param timeout New connection timeout in seconds. - void setConnectionTimeout(const unsigned short timeout); + /// @param timeout New connection timeout in milliseconds. + void setConnectionTimeout(const long timeout); /// @brief Opens control socket with parameters specified in socket_info /// diff --git a/src/lib/config/timeouts.h b/src/lib/config/timeouts.h new file mode 100644 index 0000000000..d20de9a728 --- /dev/null +++ b/src/lib/config/timeouts.h @@ -0,0 +1,36 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef CONFIG_TIMEOUTS_H +#define CONFIG_TIMEOUTS_H + +namespace isc { +namespace config { + +// All timeouts provided below are in milliseconds. + +/// @brief Timeout for the DHCP server to receive command over the +/// unix domain socket. +constexpr long TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND = 10000; + +/// @brief Timeout for the Control Agent to receive command over the +/// RESTful interface. +constexpr long TIMEOUT_AGENT_RECEIVE_COMMAND = 10000; + +/// @brief Timeout for the idle connection to be closed. +constexpr long TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT = 30000; + +/// @brief Timeout for the Control Agent to forward command to a +/// Kea server, e.g. DHCP server. +/// +/// This value is high to ensure that the server have enough time +/// to generate large responses, e.g. dump whole lease databse. +constexpr long TIMEOUT_AGENT_FORWARD_COMMAND = 60000; + +} // end of namespace isc::config +} // end of namespace isc + +#endif // CONFIG_TIMEOUTS_H