Kea  1.9.9-git
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>
26 #include <dhcp/option4_addrlst.h>
27 #include <dhcp/option6_addrlst.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 
35 using isc::dhcp::test::HostDataSourceUtils;
36 using std::cerr;
37 using std::endl;
38 
39 namespace isc {
40 namespace dhcp {
41 namespace bench {
42 
45 }
46 
49  hdsptr_.reset();
50 }
51 
52 void
53 GenericHostDataSourceBenchmark::setUp(::benchmark::State& state, size_t const& host_count) {
54  state.PauseTiming();
55  SetUp(state);
56  prepareHosts(host_count);
57  state.ResumeTiming();
58 }
59 
60 void
62  size_t const& host_count) {
63  state.PauseTiming();
64  SetUp(state);
65  prepareHosts(host_count);
66  insertHosts();
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 
97 void
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 
163 void
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 
184 void
186  for (HostPtr host : hosts_) {
187  hdsptr_->add(host);
188  }
189 }
190 
191 void
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 
199 void
201  for (HostPtr host : hosts_) {
202  hdsptr_->getAll4(host->getIPv4Reservation());
203  }
204 }
205 
206 void
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 
215 void
217  for (HostPtr host : hosts_) {
218  hdsptr_->get4(host->getIPv4SubnetID(), host->getIPv4Reservation());
219  }
220 }
221 
222 void
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 
231 void
233  for (HostPtr host : hosts_) {
234  const IPv6ResrvRange range = host->getIPv6Reservations();
235  hdsptr_->get6(host->getIPv6SubnetID(), range.first->second.getPrefix());
236  }
237 }
238 
239 void
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
Option descriptor.
Definition: cfg_option.h:42
static void clearRuntimeOptionDefs()
Removes runtime option definitions.
Definition: libdhcp++.cc:230
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:706
Base class representing a DHCP option definition.
void addItem(const OptionDefinitionPtr &def)
Adds a new option definition to the container.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
void benchGetAll()
Essential steps required to benchmark the getAll(identifier-type, identifier) call.
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:82
static void setRuntimeOptionDefs(const OptionDefSpaceContainer &defs)
Copies option definitions created at runtime.
Definition: libdhcp++.cc:214
void benchGet4SubnetIdv4Resrv()
Essential steps requires to benchmark host reservation retrieval using getAll(v4-reservation) call...
AddedOptions
Defines what kind of options should be added for a host.
HostDataSourcePtr hdsptr_
Pointer to the host backend being benchmarked.
Class of option definition space container.
OptionDescriptor createVendorOption(const Option::Universe &universe, const bool persist, const bool formatted, const uint32_t vendor_id) const
creates a vendor-option
void setUpWithInserts(::benchmark::State &state, size_t const &host_count)
Sets up the benchmark with specified number of hosts.
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition: host.h:243
void benchGet4IdentifierSubnetId()
Essential steps requires to benchmark host reservation retrieval using getAll(identifier-type, identifier, subnet-id) call.
OptionDescriptor createEmptyOption(const Option::Universe &universe, const uint16_t option_type, const bool persist) const
Creates a generic option with specific parameters.
void prepareHosts(size_t const &host_count)
Creates specified number of hosts and stores them in hosts_.
void insertHosts()
Inserts all hosts stored in hosts_ into the benchmarked host backend.
void benchGet6IdentifierSubnetId()
Essential steps requires to benchmark host reservation retrieval using get6(identifier-type, identifier, subnet-id) call.
void addTestOptions(const HostPtr &host, const bool formatted, const AddedOptions &added_options) const
Adds several v4 and/or v6 options to the host.
HostCollection hosts_
Store hosts being used during benchmark.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void benchGet6SubnetIdAddr()
Essential steps requires to benchmark host reservation retrieval using get6(ip-addr, subnet-id) call.
#define DHCP6_OPTION_SPACE
#define DHCP4_OPTION_SPACE
global std option spaces
void getAllv4Resv()
Essential steps required to benchmark host reservation retrieval using getAll(ipv4-reservation) call...
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< OptionVendor > OptionVendorPtr
Pointer to a vendor option.
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, len) call.
This class represents vendor-specific information option.
Definition: option_vendor.h:30