Kea  1.9.9-git
generic_host_data_source_benchmark.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 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:
34  enum Universe { V4, V6 };
35 
37  enum AddedOptions {
41  };
42 
47 
52 
60  const uint16_t option_type,
61  const bool persist) const;
62 
73  template <typename OptionType, typename DataType>
75  const uint16_t option_type,
76  const bool persist,
77  const bool formatted,
78  const DataType& value) const {
79  boost::shared_ptr<Option> option(new OptionType(universe, option_type, value));
80  std::ostringstream s;
81  if (formatted) {
82  // Using formatted option value. Convert option value to a
83  // textual format.
84  s << value;
85  }
86  OptionDescriptor desc(option, persist, s.str());
87  return desc;
88  }
89 
100  template <typename OptionType>
101  OptionDescriptor createAddressOption(const uint16_t option_type,
102  const bool persist,
103  const bool formatted,
104  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,
162  const bool formatted,
163  const AddedOptions& added_options) const;
164 
169  void setUp(::benchmark::State& state, size_t const& host_count);
170 
175  void setUpWithInserts(::benchmark::State& state, size_t const& host_count);
176 
180  void prepareHosts(size_t const& host_count);
181 
183  void insertHosts();
184 
187  void benchGetAll();
188 
191  void getAllv4Resv();
192 
196 
200 
204 
207  void benchGet6SubnetIdAddr();
208 
211  void benchGet6Prefix();
212 
215 
218 };
219 
220 } // namespace bench
221 } // namespace dhcp
222 } // namespace isc
223 
224 #endif
Option descriptor.
Definition: cfg_option.h:42
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.
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.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
void benchGetAll()
Essential steps required to benchmark the getAll(identifier-type, identifier) call.
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:82
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:794
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.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
HostDataSourcePtr hdsptr_
Pointer to the host backend being benchmarked.
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.
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.
Base fixture class for benchmarking host backends.
void getAllv4Resv()
Essential steps required to benchmark host reservation retrieval using getAll(ipv4-reservation) 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, len) call.