Kea  1.9.9-git
multi_threading_config_parser.cc
Go to the documentation of this file.
1 // Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <cc/data.h>
10 #include <dhcpsrv/srv_config.h>
13 
14 using namespace isc::data;
15 using namespace isc::util;
16 
17 namespace isc {
18 namespace dhcp {
19 
20 void
21 MultiThreadingConfigParser::parse(SrvConfig& srv_cfg,
22  const ConstElementPtr& value) {
23  if (!value) {
24  return;
25  }
26  if (value->getType() != Element::map) {
27  isc_throw(DhcpConfigError, "multi-threading is supposed to be a map");
28  }
29 
30  // enable-multi-threading is mandatory
31  auto enabled = getBoolean(value, "enable-multi-threading");
32 
33  // thread-pool-size is not mandatory
34  if (value->get("thread-pool-size")) {
35  auto thread_pool_size = getInteger(value, "thread-pool-size");
36  uint32_t max_size = std::numeric_limits<uint16_t>::max();
37  if (thread_pool_size < 0) {
39  "thread pool size code must not be negative ("
40  << getPosition("thread-pool-size", value) << ")");
41  }
42  if (thread_pool_size > max_size) {
43  isc_throw(DhcpConfigError, "invalid thread pool size '"
44  << thread_pool_size << "', it must not be greater than '"
45  << max_size << "' ("
46  << getPosition("thread-pool-size", value) << ")");
47  }
48  }
49 
50  // packet-queue-size is not mandatory
51  if (value->get("packet-queue-size")) {
52  auto packet_queue_size = getInteger(value, "packet-queue-size");
53  uint32_t max_size = std::numeric_limits<uint16_t>::max();
54  if (packet_queue_size < 0) {
56  "packet queue size code must not be negative ("
57  << getPosition("packet-queue-size", value) << ")");
58  }
59  if (packet_queue_size > max_size) {
60  isc_throw(DhcpConfigError, "invalid packet queue size '"
61  << packet_queue_size << "', it must not be greater than '"
62  << max_size << "' ("
63  << getPosition("packet-queue-size", value) << ")");
64  }
65  }
66 
67  srv_cfg.setDHCPMultiThreading(value);
68  MultiThreadingMgr::instance().setMode(enabled);
69 }
70 
71 } // namespace dhcp
72 } // namespace isc
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: edns.h:19
To be removed. Please use ConfigError instead.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
Specifies current DHCP configuration.
Definition: srv_config.h:167
Defines the logger used by the top-level component of kea-dhcp-ddns.
void setDHCPMultiThreading(const isc::data::ConstElementPtr dhcp_multi_threading)
Sets information about the dhcp multi threading.
Definition: srv_config.h:506