Kea 2.0.1
generic_host_data_source_benchmark.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC")
2// Copyright (C) 2017 Deutsche Telekom AG.
3//
4// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18#include <config.h>
19
21
22#include <asiolink/io_address.h>
23#include <database/testutils/schema.h>
24#include <dhcp/dhcp6.h>
25#include <dhcp/libdhcp++.h>
28#include <dhcp/option_int.h>
29#include <dhcp/option_string.h>
30#include <dhcp/option_vendor.h>
32#include <dhcpsrv/testutils/host_data_source_utils.h>
33
35using isc::dhcp::test::HostDataSourceUtils;
36using std::cerr;
37using std::endl;
38
39namespace isc {
40namespace dhcp {
41namespace bench {
42
45}
46
49 hdsptr_.reset();
50}
51
52void
53GenericHostDataSourceBenchmark::setUp(::benchmark::State& state, size_t const& host_count) {
54 state.PauseTiming();
55 SetUp(state);
56 prepareHosts(host_count);
57 state.ResumeTiming();
58}
59
60void
62 size_t const& host_count) {
63 state.PauseTiming();
64 SetUp(state);
65 prepareHosts(host_count);
67 state.ResumeTiming();
68}
69
72 const uint16_t option_type,
73 const bool persist) const {
74 OptionPtr option(new Option(universe, option_type));
75 OptionDescriptor desc(option, persist);
76 return desc;
77}
78
81 const bool persist,
82 const bool formatted,
83 const uint32_t vendor_id) const {
84 OptionVendorPtr option(new OptionVendor(universe, vendor_id));
85
86 std::ostringstream s;
87 if (formatted) {
88 // Vendor id comprises vendor-id field, for which we need to
89 // assign a value in the textual (formatted) format.
90 s << vendor_id;
91 }
92
93 OptionDescriptor desc(option, persist, s.str());
94 return desc;
95}
96
97void
99 const bool formatted,
100 const AddedOptions& added_options) const {
102
103 if ((added_options == DHCP4_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
104 // Add DHCPv4 options.
105 CfgOptionPtr opts = host->getCfgOption4();
106 opts->add(createOption<OptionString>(Option::V4, DHO_BOOT_FILE_NAME,
107 true, formatted, "my-boot-file"),
109 opts->add(createOption<OptionUint8>(Option::V4, DHO_DEFAULT_IP_TTL,
110 false, formatted, 64),
112 opts->add(createOption<OptionUint32>(Option::V4, 1, false, formatted, 312131),
113 "vendor-encapsulated-options");
114 opts->add(createAddressOption<Option4AddrLst>(254, false, formatted, "192.0.2.3"),
116 opts->add(createEmptyOption(Option::V4, 1, true), "isc");
117 opts->add(createAddressOption<Option4AddrLst>(2, false, formatted,
118 "10.0.0.5", "10.0.0.3",
119 "10.0.3.4"), "isc");
120
121 // Add definitions for DHCPv4 non-standard options.
122 defs.addItem(OptionDefinitionPtr(new OptionDefinition("vendor-encapsulated-1",
123 1, "vendor-encapsulated-options", "uint32")));
124 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-254", 254,
125 DHCP4_OPTION_SPACE, "ipv4-address", true)));
126 defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "isc", "empty")));
127 defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-2", 2,
128 "isc", "ipv4-address", true)));
129 }
130
131 if ((added_options == DHCP6_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
132 // Add DHCPv6 options.
133 CfgOptionPtr opts = host->getCfgOption6();
134 opts->add(createOption<OptionString>(Option::V6, D6O_BOOTFILE_URL,
135 true, formatted, "my-boot-file"),
137 opts->add(createOption<OptionUint32>(Option::V6, D6O_INFORMATION_REFRESH_TIME,
138 false, formatted, 3600),
140 opts->add(createVendorOption(Option::V6, false, formatted, 2495),
142 opts->add(createAddressOption<Option6AddrLst>(1024, false, formatted, "2001:db8:1::1"),
144 opts->add(createEmptyOption(Option::V6, 1, true), "isc2");
145 opts->add(createAddressOption<Option6AddrLst>(2, false, formatted,
146 "3000::1", "3000::2",
147 "3000::3"), "isc2");
148
149 // Add definitions for DHCPv6 non-standard options.
150 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1024", 1024,
151 DHCP6_OPTION_SPACE, "ipv6-address", true)));
152 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1", 1, "isc2", "empty")));
153 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-2", 2,
154 "isc2", "ipv6-address", true)));
155 }
156
157 // Register created "runtime" option definitions. They will be used by a
158 // host data source to convert option data into the appropriate option
159 // classes when the options are retrieved.
161}
162
163void
165 if (host_count > 0xfffdu) {
166 cerr << "host_count <= 0xfffd or change address xgeneration in "
167 "GenericLeaseMgrBenchmark::prepareLeases6()"
168 << endl;
169 }
170 hosts_.clear();
171 for (size_t i = 0x0001u; i < 0x0001u + host_count; ++i) {
172 std::stringstream ss;
173 std::string n_host;
174 ss << std::hex << i;
175 ss >> n_host;
176
177 const std::string prefix = std::string("2001:db8::") + n_host;
178 HostPtr host = HostDataSourceUtils::initializeHost6(prefix, Host::IDENT_HWADDR, false);
179 addTestOptions(host, false, DHCP4_AND_DHCP6);
180 hosts_.push_back(host);
181 }
182}
183
184void
186 for (HostPtr host : hosts_) {
187 hdsptr_->add(host);
188 }
189}
190
191void
193 for (HostPtr host : hosts_) {
194 std::vector<uint8_t> hwaddr = host->getIdentifier();
195 hdsptr_->getAll(host->getIdentifierType(), &hwaddr[0], hwaddr.size());
196 }
197}
198
199void
201 for (HostPtr host : hosts_) {
202 hdsptr_->getAll4(host->getIPv4Reservation());
203 }
204}
205
206void
208 for (HostPtr host : hosts_) {
209 std::vector<uint8_t> hwaddr = host->getIdentifier();
210 hdsptr_->get4(host->getIPv4SubnetID(), host->getIdentifierType(),
211 &hwaddr[0], hwaddr.size());
212 }
213}
214
215void
217 for (HostPtr host : hosts_) {
218 hdsptr_->get4(host->getIPv4SubnetID(), host->getIPv4Reservation());
219 }
220}
221
222void
224 for (HostPtr host : hosts_) {
225 std::vector<uint8_t> hwaddr = host->getIdentifier();
226 hdsptr_->get6(host->getIPv6SubnetID(), host->getIdentifierType(),
227 &hwaddr[0], hwaddr.size());
228 }
229}
230
231void
233 for (HostPtr host : hosts_) {
234 const IPv6ResrvRange range = host->getIPv6Reservations();
235 hdsptr_->get6(host->getIPv6SubnetID(), range.first->second.getPrefix());
236 }
237}
238
239void
241 for (HostPtr host : hosts_) {
242 const IPv6ResrvRange range = host->getIPv6Reservations();
243 hdsptr_->get6(range.first->second.getPrefix(),
244 range.first->second.getPrefixLen());
245 }
246}
247
248} // namespace bench
249} // namespace dhcp
250} // namespace isc
@ IDENT_HWADDR
Definition: host.h:308
static void setRuntimeOptionDefs(const OptionDefSpaceContainer &defs)
Copies option definitions created at runtime.
Definition: libdhcp++.cc:214
static void clearRuntimeOptionDefs()
Removes runtime option definitions.
Definition: libdhcp++.cc:230
Class of option definition space container.
void addItem(const OptionDefinitionPtr &def)
Adds a new option definition to the container.
Base class representing a DHCP option definition.
Option descriptor.
Definition: cfg_option.h:42
This class represents vendor-specific information option.
Definition: option_vendor.h:30
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:82
void setUpWithInserts(::benchmark::State &state, size_t const &host_count)
Sets up the benchmark with specified number of hosts.
HostCollection hosts_
Store hosts being used during benchmark.
void prepareHosts(size_t const &host_count)
Creates specified number of hosts and stores them in hosts_.
void benchGetAll()
Essential steps required to benchmark the getAll(identifier-type, identifier) call.
void setUp(::benchmark::State &state, size_t const &host_count)
Sets up timers, creates and inserts hosts.
void benchGet6Prefix()
Essential steps requires to benchmark host reservation retrieval using get6(prefix,...
void addTestOptions(const HostPtr &host, const bool formatted, const AddedOptions &added_options) const
Adds several v4 and/or v6 options to the host.
void benchGet4SubnetIdv4Resrv()
Essential steps requires to benchmark host reservation retrieval using getAll(v4-reservation) call.
HostDataSourcePtr hdsptr_
Pointer to the host backend being benchmarked.
AddedOptions
Defines what kind of options should be added for a host.
void benchGet6IdentifierSubnetId()
Essential steps requires to benchmark host reservation retrieval using get6(identifier-type,...
void benchGet4IdentifierSubnetId()
Essential steps requires to benchmark host reservation retrieval using getAll(identifier-type,...
void getAllv4Resv()
Essential steps required to benchmark host reservation retrieval using getAll(ipv4-reservation) call.
OptionDescriptor createVendorOption(const Option::Universe &universe, const bool persist, const bool formatted, const uint32_t vendor_id) const
creates a vendor-option
void insertHosts()
Inserts all hosts stored in hosts_ into the benchmarked host backend.
OptionDescriptor createEmptyOption(const Option::Universe &universe, const uint16_t option_type, const bool persist) const
Creates a generic option with specific parameters.
void benchGet6SubnetIdAddr()
Essential steps requires to benchmark host reservation retrieval using get6(ip-addr,...
@ D6O_INFORMATION_REFRESH_TIME
Definition: dhcp6.h:52
@ D6O_BOOTFILE_URL
Definition: dhcp6.h:79
boost::shared_ptr< OptionVendor > OptionVendorPtr
Pointer to a vendor option.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:706
@ DHO_BOOT_FILE_NAME
Definition: dhcp4.h:136
@ DHO_DEFAULT_IP_TTL
Definition: dhcp4.h:92
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition: host.h:243
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
Defines the logger used by the top-level component of kea-lfc.
#define DHCP4_OPTION_SPACE
global std option spaces
#define DHCP6_OPTION_SPACE