22using namespace boost::asio;
61 value = advanced->get(
"active-query-enabled");
69 value = advanced->get(
"extended-info-tables-enabled");
76 value = advanced->get(
"lease-query-ip");
78 std::string addr = value->stringValue();
81 }
catch (
const std::exception& ex) {
83 << addr <<
"': " << ex.what());
87 << (
family_ == AF_INET ?
"IPv4" :
"IPv6")
92 value = advanced->get(
"lease-query-tcp-port");
94 int64_t port = value->intValue();
95 if ((port <= 0) || (port > std::numeric_limits<uint16_t>::max())) {
102 value = advanced->get(
"max-bulk-query-threads");
104 int64_t val = value->intValue();
112 value = advanced->get(
"max-requester-connections");
114 int64_t val = value->intValue();
122 value = advanced->get(
"max-concurrent-queries");
124 int64_t val = value->intValue();
132 value = advanced->get(
"max-requester-idle-time");
134 int64_t val = value->intValue();
135 if ((val <= 0) || (val * 1000 > std::numeric_limits<int32_t>::max())) {
142 value = advanced->get(
"max-leases-per-fetch");
147 int64_t val = value->intValue();
165 : impl_(impl), config_(
config) {
171 bool dhcp_mt_enabled =
false;
172 uint32_t dhcp_threads = 0;
173 uint32_t dummy_queue_size = 0;
176 if (!dhcp_mt_enabled) {
177 isc_throw(
BadValue,
"BulkLeaseQuery requires Kea multi-threading to be enabled");
190 if (!thread_pool_size) {
193 thread_pool_size = dhcp_threads;
214BulkLeaseQueryService::getBulkLeaseQueryServicePtr() {
221 getBulkLeaseQueryServicePtr().reset();
226 return (getBulkLeaseQueryServicePtr());
232 isc_throw(
BadValue,
"BulkLeaseQueryService::create: no lease query implementation");
235 if (!advanced && mgr) {
242 mgr.reset(
new BulkLeaseQueryService(impl,
config));
247 if (!max_requester_connections) {
250 config_.max_requester_connections_ = max_requester_connections;
255 if (!max_leases_per_fetch) {
258 config_.max_leases_per_fetch_ = max_leases_per_fetch;
263 if (mt_listener_mgr_) {
270 mt_listener_mgr_->start();
282 if (!mt_listener_mgr_) {
287 mt_listener_mgr_->checkPermissions();
294 }
catch (
const std::exception& ex) {
306 if (!mt_listener_mgr_) {
311 mt_listener_mgr_->pause();
312 }
catch (
const std::exception& ex) {
323 if (!mt_listener_mgr_) {
328 mt_listener_mgr_->resume();
329 }
catch (std::exception& ex) {
337 if (mt_listener_mgr_) {
340 mt_listener_mgr_->stop();
352 if (!blq_srv || !blq_srv->mt_listener_mgr_ ||
358 std::string reason =
"no reason";
360 if (!blq_srv->impl_ || !blq_srv->impl_->isRequester(peer)) {
361 reason =
"not a valid requester";
364 size_t max_conn = blq_srv->getMaxRequesterConnections();
365 TcpListenerPtr listener = blq_srv->mt_listener_mgr_->getTcpListener();
371 size_t total_cnt = 0;
372 size_t used_cnt = listener->usedByRemoteIp(peer, total_cnt);
375 if (total_cnt >= max_conn + 2) {
377 reason =
"too many connections";
378 }
else if ((max_conn + 1 - total_cnt) > 0) {
381 }
else if ((max_conn <= 1) ||
382 (blq_srv->impl_->getNumRequesters() <= 1)) {
385 }
else if (used_cnt + 1 < total_cnt) {
389 reason =
"last free slot reserved for another requester";
405 }
catch (
const std::exception& ex) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown when a worker thread is trying to stop or pause the respective thread pool (which wo...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
static void extract(data::ConstElementPtr value, bool &enabled, uint32_t &thread_count, uint32_t &queue_size)
Extract multi-threading parameters from a given configuration.
Manages (advanced) configuration.
bool bulk_query_enabled_
Bulk query flag (default false).
size_t max_concurrent_queries_
Maximum number of concurrent queries per connection.
size_t max_leases_per_fetch_
Maximum number of leases per fetch (default 100).
size_t max_bulk_query_threads_
Maximum number of bulk query processing threads (default 0).
isc::asiolink::IOAddress lease_query_ip_
Lease query IP (default 127.0.0.1 or ::1).
long max_requester_idle_time_
Maximum requester idle time (default 300 seconds).
bool extended_info_tables_enabled_
Extended info tables flag (default same as Bulk query).
bool active_query_enabled_
Active query flag (always false).
static const isc::data::SimpleKeywords CONFIG_KEYWORDS
Keywords for advanced configuration.
size_t max_requester_connections_
Maximum number of requester connections (default 10).
void parse(isc::data::ConstElementPtr advanced)
Parse the advanced argument.
uint16_t lease_query_tcp_port_
Lease query TCP port (default 67 or 547).
uint16_t family_
Protocol family of the list (AF_INET or AF_INET6).
bool getBulkQueryEnabled() const
Returns the bulk query enabled flag.
void checkListenerPausePermission()
Check listener current thread permissions to perform thread pool state transition.
const isc::asiolink::IOAddress & getLeaseQueryIp() const
Returns the lease query IP address.
virtual ~BulkLeaseQueryService()
Destructor.
uint16_t getLeaseQueryTcpPort() const
Returns the lease query TCP port.
static bool acceptFilter(const boost::asio::ip::tcp::endpoint &endpoint)
TCP connection accept filter.
void pauseListener()
Pauses listener thread pool operations.
static BulkLeaseQueryServicePtr instance()
Returns a pointer to the sole instance of the BulkLeaseQueryService, can return null.
size_t getMaxBulkQueryThreads() const
Returns the maximum number of bulk query processing threads.
uint16_t getFamily() const
Configuration set/get methods.
static void reset()
Reset the sole instance of BulkLeaseQueryService.
void stopListener()
Stop the listener instance.
size_t getMaxConcurrentQueries() const
Returns the maximum number of concurrent queries per connection.
long getMaxRequesterIdleTime() const
Returns the maximum requester idle time.
void resumeListener()
Resumes listener thread pool operations.
void setMaxRequesterConnections(size_t max_requester_connections)
Sets the maximum number of requester connections.
static void create(LeaseQueryImpl *impl, isc::data::ConstElementPtr advanced)
Create a new instance of the BulkLeaseQueryService.
void setMaxLeasePerFetch(size_t max_leases_per_fetch)
Sets the maximum number of leases per fetch.
void startListener()
Start the listener instance.
static void doStartListener()
Start the listener.
Provides configuration and control flow for processing queries.
static bool terminated_
Terminated flag.
static size_t PageSize
Page size to commands.
static const boost::asio::ip::tcp::endpoint & NO_ENDPOINT()
Returns an empty end point.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
void removeCriticalSectionCallbacks(const std::string &name)
Removes the set of callbacks associated with a given name from the list of CriticalSection callbacks.
static uint32_t detectThreadCount()
The system current detected hardware concurrency thread count.
void addCriticalSectionCallbacks(const std::string &name, const CSCallbackSet::Callback &check_cb, const CSCallbackSet::Callback &entry_cb, const CSCallbackSet::Callback &exit_cb)
Adds a set of callbacks to the list of CriticalSection callbacks.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
boost::shared_ptr< const Element > ConstElementPtr
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
const isc::log::MessageID BULK_LEASE_QUERY_LISTENER_START_FAILED
const isc::log::MessageID BULK_LEASE_QUERY_PAUSE_LISTENER_FAILED
const isc::log::MessageID BULK_LEASE_QUERY_PAUSE_CHECK_PERMISSIONS_FAILED
const isc::log::MessageID BULK_LEASE_QUERY_REJECTED_CONNECTION
const isc::log::MessageID BULK_LEASE_QUERY_PAUSE_LISTENER_ILLEGAL
boost::shared_ptr< BulkLeaseQueryService > BulkLeaseQueryServicePtr
Defines a shared pointer to BulkLeaseQueryService.
const isc::log::MessageID BULK_LEASE_QUERY_RESUME_LISTENER_FAILED
isc::log::Logger lease_query_logger("lease-query-hooks")
boost::shared_ptr< TcpListener > TcpListenerPtr
Pointer to a TcpListener.
Defines the logger used by the top-level component of kea-lfc.