Kea 1.5.0
generic_host_data_source_benchmark.cc
Go to the documentation of this file.
1// Copyright (C) 2018 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 <dhcp/dhcp6.h>
24#include <dhcp/libdhcp++.h>
27#include <dhcp/option_int.h>
28#include <dhcp/option_string.h>
29#include <dhcp/option_vendor.h>
31#include <dhcpsrv/testutils/schema.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
44 : hdsptr_() {
46}
47
50 hdsptr_.reset();
51}
52
53void
54GenericHostDataSourceBenchmark::setUp(::benchmark::State& state,
55 size_t const& host_count) {
56 state.PauseTiming();
57 SetUp(state);
58 prepareHosts(host_count);
59 state.ResumeTiming();
60}
61
62void
64 size_t const& host_count) {
65 state.PauseTiming();
66 SetUp(state);
67 prepareHosts(host_count);
69 state.ResumeTiming();
70}
71
74 const uint16_t option_type,
75 const bool persist) const {
76 OptionPtr option(new Option(universe, option_type));
77 OptionDescriptor desc(option, persist);
78 return desc;
79}
80
83 const bool persist,
84 const bool formatted,
85 const uint32_t vendor_id) const {
86 OptionVendorPtr option(new OptionVendor(universe, vendor_id));
87
88 std::ostringstream s;
89 if (formatted) {
90 // Vendor id comprises vendor-id field, for which we need to
91 // assign a value in the textual (formatted) format.
92 s << vendor_id;
93 }
94
95 OptionDescriptor desc(option, persist, s.str());
96 return desc;
97}
98
99void
101 const AddedOptions& added_options) const {
103
104 if ((added_options == DHCP4_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
105 // Add DHCPv4 options.
106 CfgOptionPtr opts = host->getCfgOption4();
107 opts->add(createOption<OptionString>(Option::V4, DHO_BOOT_FILE_NAME, true, formatted,
108 "my-boot-file"), DHCP4_OPTION_SPACE);
109 opts->add(createOption<OptionUint8>(Option::V4, DHO_DEFAULT_IP_TTL,
110 false, formatted, 64), DHCP4_OPTION_SPACE);
111 opts->add(createOption<OptionUint32>(Option::V4, 1, false, formatted, 312131),
112 "vendor-encapsulated-options");
113 opts->add(createAddressOption<Option4AddrLst>(254, false, formatted, "192.0.2.3"),
115 opts->add(createEmptyOption(Option::V4, 1, true), "isc");
116 opts->add(createAddressOption<Option4AddrLst>(2, false, formatted, "10.0.0.5",
117 "10.0.0.3", "10.0.3.4"), "isc");
118
119 // Add definitions for DHCPv4 non-standard options.
120 defs.addItem(OptionDefinitionPtr(new OptionDefinition("vendor-encapsulated-1", 1,
121 "uint32")), "vendor-encapsulated-options");
122 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-254", 254, "ipv4-address",
123 true)), DHCP4_OPTION_SPACE);
124 defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "empty")), "isc");
125 defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-2", 2, "ipv4-address", true)),
126 "isc");
127 }
128
129 if ((added_options == DHCP6_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
130 // Add DHCPv6 options.
131 CfgOptionPtr opts = host->getCfgOption6();
132 opts->add(createOption<OptionString>(Option::V6, D6O_BOOTFILE_URL, true,
133 formatted, "my-boot-file"), DHCP6_OPTION_SPACE);
134 opts->add(createOption<OptionUint32>(Option::V6, D6O_INFORMATION_REFRESH_TIME,
135 false, formatted, 3600), DHCP6_OPTION_SPACE);
136 opts->add(createVendorOption(Option::V6, false, formatted, 2495), DHCP6_OPTION_SPACE);
137 opts->add(createAddressOption<Option6AddrLst>(1024, false, formatted, "2001:db8:1::1"),
139 opts->add(createEmptyOption(Option::V6, 1, true), "isc2");
140 opts->add(createAddressOption<Option6AddrLst>(2, false, formatted, "3000::1", "3000::2",
141 "3000::3"), "isc2");
142
143 // Add definitions for DHCPv6 non-standard options.
144 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1024", 1024, "ipv6-address",
145 true)), DHCP6_OPTION_SPACE);
146 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-1", 1, "empty")), "isc2");
147 defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-2", 2, "ipv6-address",
148 true)), "isc2");
149 }
150
151 // Register created "runtime" option definitions. They will be used by a
152 // host data source to convert option data into the appropriate option
153 // classes when the options are retrieved.
155}
156
157void
159 if (host_count > 0xfffdu) {
160 cerr << "host_count <= 0xfffd or change address xgeneration in "
161 "GenericLeaseMgrBenchmark::prepareLeases6()"
162 << endl;
163 }
164 hosts_.clear();
165 for (size_t i = 0x0001u; i < 0x0001u + host_count; ++i) {
166 std::stringstream ss;
167 std::string n_host;
168 ss << std::hex << i;
169 ss >> n_host;
170
171 const std::string prefix = std::string("2001:db8::") + n_host;
172 HostPtr host = HostDataSourceUtils::initializeHost6(prefix, Host::IDENT_HWADDR, false);
173 addTestOptions(host, false, DHCP4_AND_DHCP6);
174 hosts_.push_back(host);
175 }
176}
177
178void
180 for (HostPtr host : hosts_) {
181 hdsptr_->add(host);
182 }
183}
184
185void
187 for (HostPtr host : hosts_) {
188 hdsptr_->add(host);
189 }
190}
191
192void
194 for (HostPtr host : hosts_) {
195 ConstHostCollection from_hds =
196 hdsptr_->getAll(host->getHWAddress(), host->getDuid());
197 }
198}
199
200void
202 for (HostPtr host : hosts_) {
203 std::vector<uint8_t> hwaddr = host->getIdentifier();
204 hdsptr_->getAll(host->getIdentifierType(), &hwaddr[0], hwaddr.size());
205 }
206}
207
208void
210 for (HostPtr host : hosts_) {
211 hdsptr_->getAll4(host->getIPv4Reservation());
212 }
213}
214
215void
217 for (HostPtr host : hosts_) {
218 std::vector<uint8_t> hwaddr = host->getIdentifier();
219 hdsptr_->get4(host->getIPv4SubnetID(), HWAddrPtr(new HWAddr(hwaddr,
220 host->getIdentifierType())), host->getDuid());
221 }
222}
223
224void
226 for (HostPtr host : hosts_) {
227 std::vector<uint8_t> hwaddr = host->getIdentifier();
228 hdsptr_->get4(host->getIPv4SubnetID(), host->getIdentifierType(),
229 &hwaddr[0], hwaddr.size());
230 }
231}
232
233void
235 for (HostPtr host : hosts_) {
236 hdsptr_->get4(host->getIPv4SubnetID(), host->getIPv4Reservation());
237 }
238}
239
240void
242 for (HostPtr host : hosts_) {
243 hdsptr_->get6(host->getIPv6SubnetID(), host->getDuid(),
244 host->getHWAddress());
245 }
246}
247
248void
250 for (HostPtr host : hosts_) {
251 std::vector<uint8_t> hwaddr = host->getIdentifier();
252 hdsptr_->get6(host->getIPv6SubnetID(), host->getIdentifierType(),
253 &hwaddr[0], hwaddr.size());
254 }
255}
256
257void
259 for (HostPtr host : hosts_) {
260 const IPv6ResrvRange range = host->getIPv6Reservations();
261 hdsptr_->get6(host->getIPv6SubnetID(), range.first->second.getPrefix());
262 }
263}
264
265void
267 for (HostPtr host : hosts_) {
268 const IPv6ResrvRange range = host->getIPv6Reservations();
269 hdsptr_->get6(range.first->second.getPrefix(),
270 range.first->second.getPrefixLen());
271 }
272}
273
274} // namespace bench
275} // namespace dhcp
276} // namespace isc
@ IDENT_HWADDR
Definition: host.h:253
static void setRuntimeOptionDefs(const OptionDefSpaceContainer &defs)
Copies option definitions created at runtime.
Definition: libdhcp++.cc:234
static void clearRuntimeOptionDefs()
Removes runtime option definitions.
Definition: libdhcp++.cc:250
Base class representing a DHCP option definition.
Option descriptor.
Definition: cfg_option.h:35
void addItem(const ItemType &item, const Selector &option_space)
Adds a new item to the option_space.
This class represents vendor-specific information option.
Definition: option_vendor.h:30
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:67
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 benchGet4BySubnetHWAddrDuid()
Essential steps requires to benchmark host reservation retrieval using getAll(hw-addr,...
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.
void benchGet6SubnetIdDuidHWAddr()
Essential steps requires to benchmark host reservation retrieval using get6(subnet-id,...
OptionDescriptor createVendorOption(const Option::Universe &universe, const bool persist, const bool formatted, const uint32_t vendor_id) const
creates a vendor-option
void updateHosts()
Updates all hosts stored in hosts_ in the benchmarked host backend.
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:497
@ 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:725
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:731
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition: host.h:188
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< Option > OptionPtr
Definition: option.h:38
Defines the logger used by the top-level component of kea-dhcp-ddns.
#define DHCP4_OPTION_SPACE
Definition: option_space.h:16
#define DHCP6_OPTION_SPACE
Definition: option_space.h:17
Hardware type that represents information from DHCPv4 packet.
Definition: hwaddr.h:20