Commit e72a0654 authored by Marcin Siodelski's avatar Marcin Siodelski

[5649] Created common header file with control channel timeouts.

parent f7b8869b
......@@ -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) {
......
// 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 <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.
......
......@@ -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.
......
......@@ -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.
......
......@@ -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
......@@ -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;
}
......
......@@ -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
///
......
// 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
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