using Dhcpv4Srv::receivePacket;
};
+/// @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:
CommandMgr::instance().closeCommandSocket();
CommandMgr::instance().deregisterAll();
+ CommandMgr::instance().setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
server_.reset();
};
TEST_F(CtrlChannelDhcpv4SrvTest, connectionTimeout) {
createUnixChannelServer();
+ // Set connection timeout to 2s to prevent long waiting time for the
+ // timeout during this test.
+ const unsigned short timeout = 2;
+ CommandMgr::instance().setConnectionTimeout(timeout);
+
// Server's response will be assigned to this variable.
std::string response;
std::string command = "{ \"command\": \"foo\" ";
ASSERT_TRUE(client->sendCommand(command));
- // Let's wait up to 10s for the server's response. The response
+ // Let's wait up to 15s for the server's response. The response
// should arrive sooner assuming that the timeout mechanism for
// the server is working properly.
- const unsigned int timeout = 10;
- ASSERT_TRUE(client->getResponse(response, 10));
+ const unsigned int timeout = 15;
+ ASSERT_TRUE(client->getResponse(response, timeout));
// Explicitly close the client's connection.
client->disconnectFromServer();
using Dhcpv6Srv::receivePacket;
};
+/// @brief Default control connection timeout.
+const size_t DEFAULT_CONNECTION_TIMEOUT = 10;
+
class CtrlDhcpv6SrvTest : public BaseServerTest {
public:
CtrlDhcpv6SrvTest()
virtual ~CtrlDhcpv6SrvTest() {
LeaseMgrFactory::destroy();
StatsMgr::instance().removeAll();
+ CommandMgr::instance().setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
+
reset();
};
TEST_F(CtrlChannelDhcpv6SrvTest, connectionTimeout) {
createUnixChannelServer();
+ // Set connection timeout to 2s to prevent long waiting time for the
+ // timeout during this test.
+ const unsigned short timeout = 2;
+ CommandMgr::instance().setConnectionTimeout(timeout);
+
// Server's response will be assigned to this variable.
std::string response;
std::string command = "{ \"command\": \"foo\" ";
ASSERT_TRUE(client->sendCommand(command));
- // Let's wait up to 10s for the server's response. The response
+ // Let's wait up to 15s for the server's response. The response
// should arrive sooner assuming that the timeout mechanism for
// the server is working properly.
- const unsigned int timeout = 10;
- ASSERT_TRUE(client->getResponse(response, 10));
+ const unsigned int timeout = 15;
+ ASSERT_TRUE(client->getResponse(response, timeout));
// Explicitly close the client's connection.
client->disconnectFromServer();
/// @brief Maximum size of the data chunk sent/received over the socket.
const size_t BUF_SIZE = 8192;
-/// @brief Specifies connection timeout in milliseconds.
-///
-/// @todo Make it configurable.
-const unsigned CONNECTION_TIMEOUT = 5000;
+/// @brief Default connection timeout in seconds.
+const unsigned short DEFAULT_CONNECTION_TIMEOUT = 10;
class ConnectionPool;
/// for data transmission.
/// @param connection_pool Reference to the connection pool to which this
/// connection belongs.
+ /// @param timeout Connection timeout.
Connection(const IOServicePtr& io_service,
const boost::shared_ptr<UnixDomainSocket>& socket,
- ConnectionPool& connection_pool)
- : socket_(socket), timeout_timer_(*io_service), buf_(), response_(),
- connection_pool_(connection_pool), feed_(),
+ ConnectionPool& connection_pool,
+ const unsigned short timeout)
+ : socket_(socket), timeout_timer_(*io_service), timeout_(timeout),
+ buf_(), response_(), connection_pool_(connection_pool), feed_(),
response_in_progress_(false) {
LOG_INFO(command_logger, COMMAND_SOCKET_CONNECTION_OPENED)
// Start timer for detecting timeouts.
timeout_timer_.setup(boost::bind(&Connection::timeoutHandler, this),
- CONNECTION_TIMEOUT, IntervalTimer::ONE_SHOT);
+ timeout_ * 1000, IntervalTimer::ONE_SHOT);
}
/// @brief Destructor.
/// @brief Interval timer used to detect connection timeouts.
IntervalTimer timeout_timer_;
+ /// @brief Connection timeout.
+ unsigned short timeout_;
+
/// @brief Buffer used for received data.
std::array<char, BUF_SIZE> buf_;
/// @brief Constructor.
CommandMgrImpl()
: io_service_(), acceptor_(), socket_(), socket_name_(),
- connection_pool_() {
+ connection_pool_(), timeout_(DEFAULT_CONNECTION_TIMEOUT) {
}
/// @brief Opens acceptor service allowing the control clients to connect.
/// @brief Pool of connections.
ConnectionPool connection_pool_;
+
+ /// @brief Connection timeout
+ unsigned short timeout_;
};
void
if (!ec) {
// New connection is arriving. Start asynchronous transmission.
ConnectionPtr connection(new Connection(io_service_, socket_,
- connection_pool_));
+ connection_pool_,
+ timeout_));
connection_pool_.start(connection);
} else if (ec.value() != boost::asio::error::operation_aborted) {
impl_->io_service_ = io_service;
}
+void
+CommandMgr::setConnectionTimeout(const unsigned short timeout) {
+ impl_->timeout_ = timeout;
+}
+
+
}; // end of isc::config
}; // end of isc
/// @param io_service Pointer to the IO service.
void setIOService(const asiolink::IOServicePtr& io_service);
+ /// @brief Override default connection timeout.
+ ///
+ /// @param timeout New connection timeout in seconds.
+ void setConnectionTimeout(const unsigned short timeout);
+
/// @brief Opens control socket with parameters specified in socket_info
///
/// Currently supported types are: