Kea 2.7.5
multi_threading_config_parser.cc
Go to the documentation of this file.
1// Copyright (C) 2020-2023 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#include <limits>
15
16using namespace isc::data;
17using namespace isc::util;
18
19namespace isc {
20namespace dhcp {
21
22void
24 const ConstElementPtr& value) {
25 if (!value) {
26 return;
27 }
28 if (value->getType() != Element::map) {
29 isc_throw(DhcpConfigError, "multi-threading is supposed to be a map");
30 }
31
32 // enable-multi-threading is mandatory
33 getBoolean(value, "enable-multi-threading");
34
35 // thread-pool-size is not mandatory
36 if (value->get("thread-pool-size")) {
37 auto thread_pool_size = getInteger(value, "thread-pool-size");
38 uint32_t max_size = std::numeric_limits<uint16_t>::max();
39 if (thread_pool_size < 0) {
41 "thread pool size code must not be negative ("
42 << getPosition("thread-pool-size", value) << ")");
43 }
44 if (thread_pool_size > max_size) {
45 isc_throw(DhcpConfigError, "invalid thread pool size '"
46 << thread_pool_size << "', it must not be greater than '"
47 << max_size << "' ("
48 << getPosition("thread-pool-size", value) << ")");
49 }
50 }
51
52 // packet-queue-size is not mandatory
53 if (value->get("packet-queue-size")) {
54 auto packet_queue_size = getInteger(value, "packet-queue-size");
55 uint32_t max_size = std::numeric_limits<uint16_t>::max();
56 if (packet_queue_size < 0) {
58 "packet queue size code must not be negative ("
59 << getPosition("packet-queue-size", value) << ")");
60 }
61 if (packet_queue_size > max_size) {
62 isc_throw(DhcpConfigError, "invalid packet queue size '"
63 << packet_queue_size << "', it must not be greater than '"
64 << max_size << "' ("
65 << getPosition("packet-queue-size", value) << ")");
66 }
67 }
68
69 srv_cfg.setDHCPMultiThreading(value);
70}
71
72} // namespace dhcp
73} // namespace isc
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
To be removed. Please use ConfigError instead.
void parse(SrvConfig &srv_cfg, const isc::data::ConstElementPtr &value)
parses JSON structure.
Specifies current DHCP configuration.
Definition srv_config.h:185
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
Defines the logger used by the top-level component of kea-lfc.