Kea  1.5.0
generic_host_data_source_benchmark.h
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 #ifndef GENERIC_HOST_DATA_SOURCE_UNITTEST_H
19 #define GENERIC_HOST_DATA_SOURCE_UNITTEST_H
20 
21 #include <benchmark/benchmark.h>
22 
24 #include <dhcpsrv/host.h>
25 
26 namespace isc {
27 namespace dhcp {
28 namespace bench {
29 
31 class GenericHostDataSourceBenchmark : public ::benchmark::Fixture {
32 public:
33 
35  enum Universe { V4, V6 };
36 
38  enum AddedOptions {
42  };
43 
48 
53 
61  const uint16_t option_type,
62  const bool persist) const;
63 
74  template <typename OptionType, typename DataType>
76  const uint16_t option_type,
77  const bool persist,
78  const bool formatted,
79  const DataType& value) const {
80  boost::shared_ptr<Option> option(new OptionType(universe, option_type, value));
81  std::ostringstream s;
82  if (formatted) {
83  // Using formatted option value. Convert option value to a
84  // textual format.
85  s << value;
86  }
87  OptionDescriptor desc(option, persist, s.str());
88  return desc;
89  }
90 
101  template <typename OptionType>
103  createAddressOption(const uint16_t option_type, const bool persist,
104  const bool formatted, const std::string& address1 = "",
105  const std::string& address2 = "",
106  const std::string& address3 = "") const {
107 
108  std::ostringstream s;
109  // First address.
110  typename OptionType::AddressContainer addresses;
111  if (!address1.empty()) {
112  addresses.push_back(asiolink::IOAddress(address1));
113  if (formatted) {
114  s << address1;
115  }
116  }
117  // Second address.
118  if (!address2.empty()) {
119  addresses.push_back(asiolink::IOAddress(address2));
120  if (formatted) {
121  if (s.tellp() != std::streampos(0)) {
122  s << ",";
123  }
124  s << address2;
125  }
126  }
127  // Third address.
128  if (!address3.empty()) {
129  addresses.push_back(asiolink::IOAddress(address3));
130  if (formatted) {
131  if (s.tellp() != std::streampos(0)) {
132  s << ",";
133  }
134  s << address3;
135  }
136  }
137 
138  boost::shared_ptr<OptionType> option(new OptionType(option_type, addresses));
139  OptionDescriptor desc(option, persist, s.str());
140  return desc;
141  }
142 
152  const bool persist,
153  const bool formatted,
154  const uint32_t vendor_id) const;
155 
161  void addTestOptions(const HostPtr& host,const bool formatted,
162  const AddedOptions& added_options) const;
163 
168  void setUp(::benchmark::State& state, size_t const& host_count);
169 
174  void setUpWithInserts(::benchmark::State& state, size_t const& host_count);
175 
179  void prepareHosts(size_t const& host_count);
180 
182  void insertHosts();
183 
185  void updateHosts();
186 
188 
191  void benchGetAll();
192 
195  void getAllv4Resv();
196 
200 
204 
208 
212 
216 
219  void benchGet6SubnetIdAddr();
220 
223  void benchGet6Prefix();
224 
227 
230 };
231 
232 } // namespace bench
233 } // namespace dhcp
234 } // namespace isc
235 
236 #endif
host.h
isc::dhcp::bench::GenericHostDataSourceBenchmark::hosts_
HostCollection hosts_
Store hosts being used during benchmark.
Definition: generic_host_data_source_benchmark.h:229
isc::dhcp::bench::GenericHostDataSourceBenchmark::DHCP6_ONLY
@ DHCP6_ONLY
DHCPv6-only options.
Definition: generic_host_data_source_benchmark.h:40
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGetAllByHWAddrDuid
void benchGetAllByHWAddrDuid()
Definition: generic_host_data_source_benchmark.cc:193
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGet4BySubnetHWAddrDuid
void benchGet4BySubnetHWAddrDuid()
Essential steps requires to benchmark host reservation retrieval using getAll(hw-addr,...
Definition: generic_host_data_source_benchmark.cc:216
isc::dhcp::bench::GenericHostDataSourceBenchmark::createOption
OptionDescriptor createOption(const Option::Universe &universe, const uint16_t option_type, const bool persist, const bool formatted, const DataType &value) const
Creates an option of specified type and value.
Definition: generic_host_data_source_benchmark.h:75
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGet6SubnetIdDuidHWAddr
void benchGet6SubnetIdDuidHWAddr()
Essential steps requires to benchmark host reservation retrieval using get6(subnet-id,...
Definition: generic_host_data_source_benchmark.cc:241
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGetAll
void benchGetAll()
Essential steps required to benchmark the getAll(identifier-type, identifier) call.
Definition: generic_host_data_source_benchmark.cc:201
isc::dhcp::bench::GenericHostDataSourceBenchmark::V4
@ V4
Definition: generic_host_data_source_benchmark.h:35
isc::dhcp::bench::GenericHostDataSourceBenchmark::setUpWithInserts
void setUpWithInserts(::benchmark::State &state, size_t const &host_count)
Sets up the benchmark with specified number of hosts.
Definition: generic_host_data_source_benchmark.cc:63
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGet6IdentifierSubnetId
void benchGet6IdentifierSubnetId()
Essential steps requires to benchmark host reservation retrieval using get6(identifier-type,...
Definition: generic_host_data_source_benchmark.cc:249
isc::dhcp::bench::GenericHostDataSourceBenchmark::updateHosts
void updateHosts()
Updates all hosts stored in hosts_ in the benchmarked host backend.
Definition: generic_host_data_source_benchmark.cc:186
isc::dhcp::bench::GenericHostDataSourceBenchmark::insertHosts
void insertHosts()
Inserts all hosts stored in hosts_ into the benchmarked host backend.
Definition: generic_host_data_source_benchmark.cc:179
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
isc::dhcp::bench::GenericHostDataSourceBenchmark::createVendorOption
OptionDescriptor createVendorOption(const Option::Universe &universe, const bool persist, const bool formatted, const uint32_t vendor_id) const
creates a vendor-option
Definition: generic_host_data_source_benchmark.cc:82
isc::dhcp::bench::GenericHostDataSourceBenchmark
Base fixture class for benchmarking host backends.
Definition: generic_host_data_source_benchmark.h:31
isc::dhcp::bench::GenericHostDataSourceBenchmark::DHCP4_AND_DHCP6
@ DHCP4_AND_DHCP6
Both DHCPv4 and DHCPv6 options.
Definition: generic_host_data_source_benchmark.h:41
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
base_host_data_source.h
isc::dhcp::bench::GenericHostDataSourceBenchmark::prepareHosts
void prepareHosts(size_t const &host_count)
Creates specified number of hosts and stores them in hosts_.
Definition: generic_host_data_source_benchmark.cc:158
isc::dhcp::bench::GenericHostDataSourceBenchmark::createAddressOption
OptionDescriptor createAddressOption(const uint16_t option_type, const bool persist, const bool formatted, const std::string &address1="", const std::string &address2="", const std::string &address3="") const
Creates an option with addresses.
Definition: generic_host_data_source_benchmark.h:103
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGet6SubnetIdAddr
void benchGet6SubnetIdAddr()
Essential steps requires to benchmark host reservation retrieval using get6(ip-addr,...
Definition: generic_host_data_source_benchmark.cc:258
isc::dhcp::bench::GenericHostDataSourceBenchmark::Universe
Universe
Defines universe (IPv4 or IPv6)
Definition: generic_host_data_source_benchmark.h:35
isc::dhcp::bench::GenericHostDataSourceBenchmark::DHCP4_ONLY
@ DHCP4_ONLY
DHCPv4-only options.
Definition: generic_host_data_source_benchmark.h:39
isc::dhcp::bench::GenericHostDataSourceBenchmark::getAllv4Resv
void getAllv4Resv()
Essential steps required to benchmark host reservation retrieval using getAll(ipv4-reservation) call.
Definition: generic_host_data_source_benchmark.cc:209
isc::dhcp::bench::GenericHostDataSourceBenchmark::AddedOptions
AddedOptions
Defines what kind of options should be added for a host.
Definition: generic_host_data_source_benchmark.h:38
isc::dhcp::bench::GenericHostDataSourceBenchmark::hdsptr_
HostDataSourcePtr hdsptr_
Pointer to the host backend being benchmarked.
Definition: generic_host_data_source_benchmark.h:226
isc::dhcp::bench::GenericHostDataSourceBenchmark::addTestOptions
void addTestOptions(const HostPtr &host, const bool formatted, const AddedOptions &added_options) const
Adds several v4 and/or v6 options to the host.
Definition: generic_host_data_source_benchmark.cc:100
isc::dhcp::HostDataSourcePtr
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
Definition: base_host_data_source.h:251
isc::dhcp::bench::GenericHostDataSourceBenchmark::V6
@ V6
Definition: generic_host_data_source_benchmark.h:35
isc::dhcp::bench::GenericHostDataSourceBenchmark::createEmptyOption
OptionDescriptor createEmptyOption(const Option::Universe &universe, const uint16_t option_type, const bool persist) const
Creates a generic option with specific parameters.
Definition: generic_host_data_source_benchmark.cc:73
isc::dhcp::OptionDescriptor
Option descriptor.
Definition: cfg_option.h:35
isc::dhcp::bench::GenericHostDataSourceBenchmark::setUp
void setUp(::benchmark::State &state, size_t const &host_count)
Sets up timers, creates and inserts hosts.
Definition: generic_host_data_source_benchmark.cc:54
isc::dhcp::Option::Universe
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:67
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGet4SubnetIdv4Resrv
void benchGet4SubnetIdv4Resrv()
Essential steps requires to benchmark host reservation retrieval using getAll(v4-reservation) call.
Definition: generic_host_data_source_benchmark.cc:234
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGet6Prefix
void benchGet6Prefix()
Essential steps requires to benchmark host reservation retrieval using get6(prefix,...
Definition: generic_host_data_source_benchmark.cc:266
isc::dhcp::bench::GenericHostDataSourceBenchmark::benchGet4IdentifierSubnetId
void benchGet4IdentifierSubnetId()
Essential steps requires to benchmark host reservation retrieval using getAll(identifier-type,...
Definition: generic_host_data_source_benchmark.cc:225
isc::dhcp::bench::GenericHostDataSourceBenchmark::~GenericHostDataSourceBenchmark
virtual ~GenericHostDataSourceBenchmark()
Destructor.
Definition: generic_host_data_source_benchmark.cc:48
isc::dhcp::bench::GenericHostDataSourceBenchmark::GenericHostDataSourceBenchmark
GenericHostDataSourceBenchmark()
Constructor.
Definition: generic_host_data_source_benchmark.cc:43
isc::dhcp::HostCollection
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:734