]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5649] Created common header file with control channel timeouts.
authorMarcin Siodelski <marcin@isc.org>
Thu, 14 Jun 2018 10:04:39 +0000 (12:04 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 14 Jun 2018 10:04:39 +0000 (12:04 +0200)
src/bin/agent/ca_command_mgr.cc
src/bin/agent/ca_process.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/lib/config/Makefile.am
src/lib/config/command_mgr.cc
src/lib/config/command_mgr.h
src/lib/config/timeouts.h [new file with mode: 0644]

index 37f44372b0bf73469d6404e3aaf3a63f25bb265d..6386527b4cb038c6981edfc365d6a84dfbb41342 100644 (file)
@@ -18,6 +18,7 @@
 #include <cc/data.h>
 #include <cc/json_feed.h>
 #include <config/client_connection.h>
+#include <config/timeouts.h>
 #include <boost/pointer_cast.hpp>
 #include <iterator>
 #include <sstream>
@@ -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) {
index 2f2e157bbaed361a44c217bc0d12f02a5eeb81a0..0e96ceb6d40b6aa9f9cd77f482f8036b82baf1d3 100644 (file)
@@ -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
 #include <asiolink/io_address.h>
 #include <asiolink/io_error.h>
 #include <cc/command_interpreter.h>
+#include <config/timeouts.h>
 #include <boost/pointer_cast.hpp>
 
 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.
index 60f41f87684a1f84b33d8e8462be43b28f6382ed..ab61bf3c856524a531d58c77dd6994a2d9fe33b8 100644 (file)
@@ -10,6 +10,7 @@
 #include <asiolink/io_service.h>
 #include <cc/command_interpreter.h>
 #include <config/command_mgr.h>
+#include <config/timeouts.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
@@ -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.
index c11fb801d3ce792c3d0c30d4bb4990dda1d6686e..765a9905d84bac3674d22cd4020940fd43b9edd4 100644 (file)
@@ -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.
index b4e65f69784b152fc57c1b5573ac24d2bdda061f..8b2102dfd208fe535b15fd925e6517d27482938a 100644 (file)
@@ -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
 
index f4a0a4105c7ea6361dd870f21df5b352a642f2e4..55f35c80b7188dc8d6f1b855d76ce74d1a5b3be4 100644 (file)
@@ -18,6 +18,7 @@
 #include <cc/json_feed.h>
 #include <dhcp/iface_mgr.h>
 #include <config/config_log.h>
+#include <config/timeouts.h>
 #include <util/watch_socket.h>
 #include <boost/bind.hpp>
 #include <boost/enable_shared_from_this.hpp>
@@ -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<UnixDomainSocket>& 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<char, BUF_SIZE> 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;
 }
 
index 5eb23015fbd3476f73ecfcdc518a779ca0e6bdb5..2559d04638d1a576a924ed905abf0a36b88fe643 100644 (file)
@@ -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 (file)
index 0000000..d20de9a
--- /dev/null
@@ -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