]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[github36] Large chunk of review work completed:
authorTomek Mrugalski <tomasz@isc.org>
Tue, 13 Feb 2018 12:20:31 +0000 (12:20 +0000)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 13 Feb 2018 12:20:31 +0000 (12:20 +0000)
 - common code extracted to testutils/host_data_source_utils.cc|h
 - doxygen comments written
 - compilation warnings removed
 - each leasemgr benchmark have at least a short description
 - HostDataSource benchmarks partially done, but still WIP
 - overall, the diff is 4k and counting...

25 files changed:
configure.ac
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/benchmarks/Makefile.am
src/lib/dhcpsrv/benchmarks/cql_host_data_source_benchmark.cc
src/lib/dhcpsrv/benchmarks/cql_lease_mgr_benchmark.cc
src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.cc
src/lib/dhcpsrv/benchmarks/generic_host_data_source_benchmark.h
src/lib/dhcpsrv/benchmarks/generic_lease_mgr_benchmark.cc
src/lib/dhcpsrv/benchmarks/generic_lease_mgr_benchmark.h
src/lib/dhcpsrv/benchmarks/memfile_lease_mgr_benchmark.cc
src/lib/dhcpsrv/benchmarks/mysql_host_data_source_benchmark.cc
src/lib/dhcpsrv/benchmarks/mysql_lease_mgr_benchmark.cc
src/lib/dhcpsrv/benchmarks/pgsql_host_data_source_benchmark.cc
src/lib/dhcpsrv/benchmarks/pgsql_lease_mgr_benchmark.cc
src/lib/dhcpsrv/benchmarks/run_benchmarks.cc
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/cql_host_data_source.h
src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/Makefile.am
src/lib/dhcpsrv/testutils/host_data_source_utils.cc [new file with mode: 0644]
src/lib/dhcpsrv/testutils/host_data_source_utils.h [new file with mode: 0644]

index 1e7ed2533f1e7c0c8b5c391db2ccb4652e26a0c3..f932bcea4e19ec21b1915446e10d8509cecfa2c6 100644 (file)
@@ -1634,13 +1634,18 @@ fi
 if test "$enable_gtest" != "no"; then
 cat >> config.report << END
 
-GTest:
+Google Test:
   GTEST_VERSION:   ${GTEST_VERSION}
   GTEST_INCLUDES:  ${GTEST_INCLUDES}
   GTEST_LDFLAGS:   ${GTEST_LDFLAGS}
   GTEST_LDADD:     ${GTEST_LDADD}
   GTEST_SOURCE:    ${GTEST_SOURCE}
 END
+else
+cat >> config.report << END
+Google Test:
+  no
+END
 fi
 
 if test "$enable_benchmark" != "no"; then
@@ -1653,6 +1658,11 @@ Google Benchmark:
   BENCHMARK_LDADD:     ${BENCHMARK_LDADD}
   BENCHMARK_SOURCE:    ${BENCHMARK_SOURCE}
 END
+else
+cat >> config.report << END
+Google Benchmark:
+  no
+END
 fi
 
 cat >> config.report << END
index c2b7f6d2bc58fc552ae12f3c6640c7ba618101aa..5f24324f9b43a8d9501c35f1321705b00e66d63a 100644 (file)
@@ -17,7 +17,7 @@ if HAVE_PGSQL
 AM_CPPFLAGS += $(PGSQL_CPPFLAGS)
 endif
 if HAVE_CQL
-AM_CPPFLAGS += $(CQL_CPPFLAGS)
+AM_CPPFLAGS += $(CQL_CPPFLAGS) $(CRYPTO_INCLUDES)
 endif
 
 AM_CXXFLAGS = $(KEA_CXXFLAGS)
index 364464b24a474d68a6900b15873ecd42e881b55c..005452e231d4878aefa6f5cc046f853c07d4fbed 100644 (file)
@@ -69,14 +69,16 @@ if HAVE_CQL
 run_benchmarks_LDFLAGS += $(CQL_LIBS)
 endif
 
-run_benchmarks_LDADD  = $(BENCHMARK_LDADD)
-run_benchmarks_LDADD += $(LOG4CPLUS_LIBS)
-run_benchmarks_LDADD += $(CRYPTO_LIBS)
-run_benchmarks_LDADD += $(BOOST_LIBS)
+run_benchmarks_LDADD  = $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
 run_benchmarks_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
 run_benchmarks_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 run_benchmarks_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 run_benchmarks_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
+run_benchmarks_LDADD += $(BENCHMARK_LDADD)
+run_benchmarks_LDADD += $(LOG4CPLUS_LIBS)
+run_benchmarks_LDADD += $(CRYPTO_LIBS)
+run_benchmarks_LDADD += $(BOOST_LIBS)
+run_benchmarks_LDADD += $(GTEST_LDADD)
 endif
 
 noinst_PROGRAMS = $(BENCHMARKS)
index 0e42fd51ce4a4cc17bb3bea91491d426ca836b29..a3c93c61a68782d1c380c3f5f48774c9012e8ec7 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -32,8 +33,11 @@ using std::endl;
 
 namespace {
 
+/// @brief Fixture class for benchmarking Cassandra host backend
 class CqlHostDataSourceBenchmark : public GenericHostDataSourceBenchmark {
 public:
+
+    /// @brief Before benchmark setup.
     void SetUp(::benchmark::State const&) override {
         destroyCqlSchema(false, true);
         createCqlSchema(false, true);
@@ -47,6 +51,7 @@ public:
         hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr();
     }
 
+    /// @brief After benchmark clean-up
     void TearDown(::benchmark::State const&) override {
         try {
             hdsptr_->rollback();
@@ -60,26 +65,29 @@ public:
     }
 };
 
+// This benchmark measures insertion of new hosts.
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, insertHosts)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp(state, host_count);
+        setUp(state, host_count);
         insertHosts();
     }
 }
 
+// This benchmark measures update of existing hosts.
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, updateHosts)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         updateHosts();
     }
 }
 
+// This benchmark 
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll2)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll2();
     }
 }
@@ -87,7 +95,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll2)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll3();
     }
 }
@@ -95,7 +103,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll3)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll1)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll1();
     }
 }
@@ -103,7 +111,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, getAll1)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4_3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_3();
     }
 }
@@ -111,7 +119,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4_3)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4_4)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_4();
     }
 }
@@ -119,7 +127,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4_4)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4_2)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_2();
     }
 }
@@ -127,7 +135,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get4_2)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6_3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_3();
     }
 }
@@ -135,7 +143,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6_3)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6_4)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_4();
     }
 }
@@ -143,7 +151,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6_4)(benchmark::State& state)
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6_2_subnetid_address)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_2_subnetid_address();
     }
 }
@@ -151,7 +159,7 @@ BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6_2_subnetid_address)(benchmar
 BENCHMARK_DEFINE_F(CqlHostDataSourceBenchmark, get6_2_prefix_prefixlen)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_2_prefix_prefixlen();
     }
 }
index eb5a71b3d894edbf78731db78c9895ff3dfd36db..eed7ed05837f1b5c49926fe0c56608dd071f3823 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/testutils/cql_schema.h>
 
-using isc::dhcp::LeaseMgrFactory;
-using isc::dhcp::bench::GenericLeaseMgrBenchmark;
-using isc::dhcp::test::createCqlSchema;
-using isc::dhcp::test::destroyCqlSchema;
-using isc::dhcp::test::validCqlConnectionString;
-using std::cerr;
-using std::endl;
+using namespace isc::dhcp;
+using namespace isc::dhcp::test;
+using namespace std;
+using namespace isc::dhcp::bench;
 
 namespace {
 
+/// @brief This is a fixture class used for benchmarking Cassandra lease backend
 class CqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark {
 public:
+
+    /// @brief Prepares the benchmark to run
+    ///
+    /// Destroys and then recreates CQL schema, initializes CQL LeaseMgr.
     void SetUp(::benchmark::State const&) override {
         destroyCqlSchema(false, true);
         createCqlSchema(false, true);
@@ -45,6 +48,7 @@ public:
         lmptr_ = &(LeaseMgrFactory::instance());
     }
 
+    /// @brief Cleans up after the benchmark.
     void TearDown(::benchmark::State const&) override {
         try {
             lmptr_->rollback();
@@ -58,135 +62,196 @@ public:
     }
 };
 
+// Defines a benchmark that measures IPv4 leases insertion.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, insertLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp4(state, lease_count);
+        setUp4(state, lease_count);
         benchInsertLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases update.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, updateLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchUpdateLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by address.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_address();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by hardware address.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_hwaddr)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by hardware address
+// and subnet-id.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr_subnetid();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by client-id.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_clientid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by client-id and
+// subnet-id.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease4_clientid_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid_subnetid();
     }
 }
 
+// Defines a benchmark that measures retrieval of expired IPv4 leases.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getExpiredLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetExpiredLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases insertion.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, insertLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp6(state, lease_count);
+        setUp6(state, lease_count);
         benchInsertLeases6();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases update.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, updateLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchUpdateLeases6();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases retrieval by type and address.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_address();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases retrieval by type, duid and iaid.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid();
     }
 }
 
-BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_type_duid_iaid_subnetid)(benchmark::State& state) {
+// Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid
+// and subnet-id.
+BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
+    (benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid_subnetid();
     }
 }
 
+// Defines a benchmark that measures retrieval of expired IPv6 leases.
 BENCHMARK_DEFINE_F(CqlLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetExpiredLeases6();
     }
 }
 
-constexpr size_t MIN_LEASE_COUNT = 512;
-constexpr size_t MAX_LEASE_COUNT = 0xfffd;
-constexpr benchmark::TimeUnit UNIT = benchmark::kMicrosecond;
-
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_address)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_address)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_type_duid_iaid_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// The following macros define run parameters for previously defined
+/// Cassandra benchmarks.
+
+/// A benchmark that measures IPv4 leases insertion.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 leases update.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by IP address.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_address)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by hardware address.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by hardware address and a
+/// subnet-id.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by client-id.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by client-id and subnet-id.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease4_clientid_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures expired IPv4 leases retrieval.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 leases insertion.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, insertLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 leases update.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, updateLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type and IP address.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_address)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type, duid, iaid and
+/// subnet-id.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures expired IPv6 leases retrieval.
+BENCHMARK_REGISTER_F(CqlLeaseMgrBenchmark, getExpiredLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
 
 }  // namespace
index 4a583309c2372e9ec1d459119ae3d10362af7ccf..31d3fede58e577689c5045fd587188b256982287 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
 #include <dhcp/option_vendor.h>
 #include <dhcpsrv/host_data_source_factory.h>
 #include <dhcpsrv/testutils/schema.h>
+#include <dhcpsrv/testutils/host_data_source_utils.h>
 
 using isc::asiolink::IOAddress;
+using isc::dhcp::test::HostDataSourceUtils;
 using std::cerr;
 using std::endl;
 
@@ -48,8 +51,8 @@ GenericHostDataSourceBenchmark::~GenericHostDataSourceBenchmark() {
 }
 
 void
-GenericHostDataSourceBenchmark::ReentrantSetUp(::benchmark::State& state,
-                                               size_t const& host_count) {
+GenericHostDataSourceBenchmark::setUp(::benchmark::State& state,
+                                      size_t const& host_count) {
     state.PauseTiming();
     SetUp(state);
     prepareHosts(host_count);
@@ -57,8 +60,8 @@ GenericHostDataSourceBenchmark::ReentrantSetUp(::benchmark::State& state,
 }
 
 void
-GenericHostDataSourceBenchmark::ReentrantSetUpWithInserts(::benchmark::State& state,
-                                                          size_t const& host_count) {
+GenericHostDataSourceBenchmark::setUpWithInserts(::benchmark::State& state,
+                                                 size_t const& host_count) {
     state.PauseTiming();
     SetUp(state);
     prepareHosts(host_count);
@@ -66,107 +69,6 @@ GenericHostDataSourceBenchmark::ReentrantSetUpWithInserts(::benchmark::State& st
     state.ResumeTiming();
 }
 
-std::vector<uint8_t>
-GenericHostDataSourceBenchmark::generateHWAddr(const bool new_identifier) {
-    /// @todo: Consider moving this somewhere to lib/testutils.
-
-    // Let's use something that is easily printable. That's convenient
-    // if you need to enter MySQL queries by hand.
-    static uint8_t hwaddr[] = {65, 66, 67, 68, 69, 70};
-
-    if (new_identifier) {
-        // Increase the address for the next time we use it.
-        // This is primitive, but will work for 65k unique addresses.
-        hwaddr[sizeof(hwaddr) - 1]++;
-        if (hwaddr[sizeof(hwaddr) - 1] == 0) {
-            hwaddr[sizeof(hwaddr) - 2]++;
-        }
-    }
-    return std::vector<uint8_t>(hwaddr, hwaddr + sizeof(hwaddr));
-}
-
-std::vector<uint8_t>
-GenericHostDataSourceBenchmark::generateIdentifier(const bool new_identifier) {
-    /// @todo: Consider moving this somewhere to lib/testutils.
-
-    // Let's use something that is easily printable. That's convenient
-    // if you need to enter MySQL queries by hand.
-    static uint8_t ident[] = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74};
-
-    if (new_identifier) {
-        // Increase the identifier for the next time we use it.
-        // This is primitive, but will work for 65k unique identifiers.
-        ident[sizeof(ident) - 1]++;
-        if (ident[sizeof(ident) - 1] == 0) {
-            ident[sizeof(ident) - 2]++;
-        }
-    }
-    return std::vector<uint8_t>(ident, ident + sizeof(ident));
-}
-
-HostPtr
-GenericHostDataSourceBenchmark::initializeHost4(const std::string& address,
-                                                const Host::IdentifierType& id) {
-    std::vector<uint8_t> ident;
-    if (id == Host::IDENT_HWADDR) {
-        ident = generateHWAddr();
-    } else {
-        ident = generateIdentifier();
-    }
-
-    // Let's create ever increasing subnet-ids. Let's keep those different,
-    // so subnet4 != subnet6. Useful for catching cases if the code confuses
-    // subnet4 with subnet6.
-    static SubnetID subnet4 = 0;
-    static SubnetID subnet6 = 100;
-    ++subnet4;
-    ++subnet6;
-
-    IOAddress addr(address);
-    HostPtr host(new Host(&ident[0], ident.size(), id, subnet4, subnet6, addr));
-
-    return host;
-}
-
-HostPtr
-GenericHostDataSourceBenchmark::initializeHost6(std::string address,
-                                                Host::IdentifierType identifier,
-                                                bool prefix, bool new_identifier) {
-    std::vector<uint8_t> ident;
-    switch (identifier) {
-    case Host::IDENT_HWADDR:
-        ident = generateHWAddr(new_identifier);
-        break;
-    case Host::IDENT_DUID:
-        ident = generateIdentifier(new_identifier);
-        break;
-    default:
-        return HostPtr();
-    }
-
-    // Let's create ever increasing subnet-ids. Let's keep those different,
-    // so subnet4 != subnet6. Useful for catching cases if the code confuses
-    // subnet4 with subnet6.
-    static SubnetID subnet4 = 0;
-    static SubnetID subnet6 = 100;
-    subnet4++;
-    subnet6++;
-
-    HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6,
-                          IOAddress("0.0.0.0")));
-
-    if (!prefix) {
-        // Create IPv6 reservation (for an address)
-        IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), 128);
-        host->addReservation(resv);
-    } else {
-        // Create IPv6 reservation for a /64 prefix
-        IPv6Resrv resv(IPv6Resrv::TYPE_PD, IOAddress(address), 64);
-        host->addReservation(resv);
-    }
-    return host;
-}
-
 OptionDescriptor
 GenericHostDataSourceBenchmark::createEmptyOption(const Option::Universe& universe,
                                                   const uint16_t option_type,
@@ -202,35 +104,25 @@ GenericHostDataSourceBenchmark::addTestOptions(const HostPtr& host, const bool f
     if ((added_options == DHCP4_ONLY) || (added_options == DHCP4_AND_DHCP6)) {
         // Add DHCPv4 options.
         CfgOptionPtr opts = host->getCfgOption4();
-        opts->add(createOption<OptionString>(Option::V4, DHO_BOOT_FILE_NAME,
-                                             true, formatted, "my-boot-file"),
-                  DHCP4_OPTION_SPACE);
+        opts->add(createOption<OptionString>(Option::V4, DHO_BOOT_FILE_NAME, true, formatted,
+                                             "my-boot-file"), DHCP4_OPTION_SPACE);
         opts->add(createOption<OptionUint8>(Option::V4, DHO_DEFAULT_IP_TTL,
-                                            false, formatted, 64),
-                  DHCP4_OPTION_SPACE);
-        opts->add(
-            createOption<OptionUint32>(Option::V4, 1, false, formatted, 312131),
-            "vendor-encapsulated-options");
-        opts->add(createAddressOption<Option4AddrLst>(254, false, formatted,
-                                                      "192.0.2.3"),
+                                            false, formatted, 64), DHCP4_OPTION_SPACE);
+        opts->add(createOption<OptionUint32>(Option::V4, 1, false, formatted, 312131),
+                  "vendor-encapsulated-options");
+        opts->add(createAddressOption<Option4AddrLst>(254, false, formatted, "192.0.2.3"),
                   DHCP4_OPTION_SPACE);
         opts->add(createEmptyOption(Option::V4, 1, true), "isc");
-        opts->add(createAddressOption<Option4AddrLst>(
-                      2, false, formatted, "10.0.0.5", "10.0.0.3", "10.0.3.4"),
-                  "isc");
+        opts->add(createAddressOption<Option4AddrLst>(2, false, formatted, "10.0.0.5",
+                                                      "10.0.0.3", "10.0.3.4"), "isc");
 
         // Add definitions for DHCPv4 non-standard options.
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "vendor-encapsulated-1", 1, "uint32")),
-                     "vendor-encapsulated-options");
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "option-254", 254, "ipv4-address", true)),
-                     DHCP4_OPTION_SPACE);
-        defs.addItem(
-            OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "empty")),
-            "isc");
-        defs.addItem(OptionDefinitionPtr(new OptionDefinition(
-                         "isc-2", 2, "ipv4-address", true)),
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("vendor-encapsulated-1", 1,
+                                         "uint32")), "vendor-encapsulated-options");
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("option-254", 254, "ipv4-address",
+                                         true)), DHCP4_OPTION_SPACE);
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-1", 1, "empty")), "isc");
+        defs.addItem(OptionDefinitionPtr(new OptionDefinition("isc-2", 2, "ipv4-address", true)),
                      "isc");
     }
 
@@ -287,7 +179,7 @@ GenericHostDataSourceBenchmark::prepareHosts(size_t const& host_count) {
         ss >> n_host;
 
         const std::string prefix = std::string("2001:db8::") + n_host;
-        HostPtr host = initializeHost6(prefix, Host::IDENT_HWADDR, false);
+        HostPtr host = HostDataSourceUtils::initializeHost6(prefix, Host::IDENT_HWADDR, false);
         addTestOptions(host, false, DHCP4_AND_DHCP6);
         hosts_.push_back(host);
     }
index 6612c75ec2411920134dc0a8a8faa2363714c4f1..c38f0b8d1f9d8abeb36fed83ae3d9a793894d692 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -26,34 +27,56 @@ namespace isc {
 namespace dhcp {
 namespace bench {
 
+    /// @brief Base fixture class for benchmarking host bakcends.
 class GenericHostDataSourceBenchmark : public ::benchmark::Fixture {
 public:
+
+    /// @brief Defines universe (IPv4 or IPv6)
     enum Universe { V4, V6 };
-    enum AddedOptions { DHCP4_ONLY, DHCP6_ONLY, DHCP4_AND_DHCP6 };
 
+    /// @brief Defines what kind of options should be added for a host
+    enum AddedOptions {
+        DHCP4_ONLY,      ///< DHCPv4-only options
+        DHCP6_ONLY,      ///< DHCPv6-only options
+        DHCP4_AND_DHCP6  ///< Both DHCPv4 and DHCPv6 options
+    };
+
+    /// @brief Constructor
+    ///
+    /// Clears runtime option definitions.
     GenericHostDataSourceBenchmark();
-    virtual ~GenericHostDataSourceBenchmark();
 
-    HostPtr initializeHost4(const std::string& address,
-                            const Host::IdentifierType& id);
-    HostPtr initializeHost6(std::string address,
-                            Host::IdentifierType id,
-                            bool prefix,
-                            bool new_identifier = true);
-    std::vector<uint8_t> generateHWAddr(const bool new_identifier = true);
-    std::vector<uint8_t> generateIdentifier(const bool new_identifier = true);
+    /// @brief Destructor
+    ///
+    /// Clears runtime option definitions and clears hdsptr_ pointer.
+    virtual ~GenericHostDataSourceBenchmark();
 
+    /// @brief Creates a generic option with specific parameters.
+    ///
+    /// @param universe (v4 or v6)
+    /// @param option_type code of the option
+    /// @param persist whether the option should always be included (yes) or not (no)
+    /// @return the option created wrapped in an option descriptor structure
     OptionDescriptor createEmptyOption(const Option::Universe& universe,
                                        const uint16_t option_type,
                                        const bool persist) const;
+
+    /// @brief Creates an option of specified type and avalue
+    ///
+    /// @tparam OptionType Option class to be instantiated
+    /// @tparam DataType type of parameter to be passed to OptionType constructor
+    /// @param universe (v4 or v6)
+    /// @param option_type code of the option
+    /// @param persist whether the option should always be included (yes) or not (no)
+    /// @param formatted whether the value passed to description should be converted to text
+    /// @return the option created wrapped in an option descriptor structure
     template <typename OptionType, typename DataType>
     OptionDescriptor createOption(const Option::Universe& universe,
                                   const uint16_t option_type,
                                   const bool persist,
                                   const bool formatted,
                                   const DataType& value) const {
-        boost::shared_ptr<OptionType> option(
-            new OptionType(universe, option_type, value));
+        boost::shared_ptr<Option> option(new OptionType(universe, option_type, value));
         std::ostringstream s;
         if (formatted) {
             // Using formatted option value. Convert option value to a
@@ -63,32 +86,23 @@ public:
         OptionDescriptor desc(option, persist, s.str());
         return desc;
     }
-    template <typename OptionType, typename DataType>
-    OptionDescriptor createOption(const uint16_t option_type,
-                                  const bool persist,
-                                  const bool formatted,
-                                  const DataType& value) const {
-        boost::shared_ptr<OptionType> option(
-            new OptionType(option_type, value));
-
-        std::ostringstream s;
-        if (formatted) {
-            // Using formatted option value. Convert option value to a
-            // textual format.
-            s << value;
-        }
 
-        OptionDescriptor desc(option, persist, s.str());
-        return desc;
-    }
+    /// @brief Creates an option with addresses
+    ///
+    /// @tparam OptionType specifies a class to be instantiated
+    /// @param option_type code of the option
+    /// @param formatted whether the value passed to description should be converted to text
+    /// @param address1 first address to be used (optional)
+    /// @param address2 second address to be used (optional)
+    /// @param address3 third address to be used (optional)
+    /// @return the option created wrapped in an option descriptor structure
     template <typename OptionType>
     OptionDescriptor
-    createAddressOption(const uint16_t option_type,
-                        const bool persist,
-                        const bool formatted,
-                        const std::string& address1 = "",
+    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 {
+
         std::ostringstream s;
         // First address.
         typename OptionType::AddressContainer addresses;
@@ -119,21 +133,34 @@ public:
             }
         }
 
-        boost::shared_ptr<OptionType> option(
-            new OptionType(option_type, addresses));
+        boost::shared_ptr<OptionType> option(new OptionType(option_type, addresses));
         OptionDescriptor desc(option, persist, s.str());
         return desc;
     }
+
+    /// @brief creates a vendor-option
+    ///
+    /// @param universe (v4 or v6)
+    /// @param persist whether the option should always be included
+    /// @param formatted whether the value passed to description should be
+    ///        converted to text
+    /// @param vendor_it 32-unsigned bit enterprise-id
+    /// @return the option created wrapped in an option descriptor structure
     OptionDescriptor createVendorOption(const Option::Universe& universe,
                                         const bool persist,
                                         const bool formatted,
                                         const uint32_t vendor_id) const;
-    void addTestOptions(const HostPtr& host,
-                        const bool formatted,
+
+    /// @brief Adds several v4 and/or v6 options to the host
+    ///
+    /// @param host host reservation to be extended with options
+    /// @param formatted whether to generate text representation
+    /// @param added_options v4, v6 or both
+    void addTestOptions(const HostPtr& host,const bool formatted,
                         const AddedOptions& added_options) const;
 
-    void ReentrantSetUp(::benchmark::State& state, size_t const& host_count);
-    void ReentrantSetUpWithInserts(::benchmark::State& state,
+    void setUp(::benchmark::State& state, size_t const& host_count);
+    void setUpWithInserts(::benchmark::State& state,
                                    size_t const& host_count);
     void prepareHosts(size_t const& lease_count);
     void insertHosts();
index 3cf7a530c68669f1f6672fc23df132f764eacf58..941aa6570e786535ac7b2b22971a7567e834262e 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
 #include <iomanip>
 #include <iostream>
 #include <string>
+#include <vector>
 
-using isc::asiolink::IOAddress;
-using isc::dhcp::test::createCqlSchema;
-using isc::dhcp::test::destroyCqlSchema;
-using isc::dhcp::test::validCqlConnectionString;
-
-using std::chrono::duration;
-using std::chrono::duration_cast;
-using std::chrono::high_resolution_clock;
-using std::cerr;
-using std::cout;
-using std::endl;
-using std::setprecision;
-using std::string;
-using std::stringstream;
-using std::to_string;
-using std::vector;
+using namespace isc::asiolink;
+using namespace isc::dhcp::test;
+using namespace std;
+using namespace std::chrono;
 
 namespace isc {
 namespace dhcp {
 namespace bench {
 
-GenericLeaseMgrBenchmark::GenericLeaseMgrBenchmark() : lmptr_(NULL) {
+GenericLeaseMgrBenchmark::GenericLeaseMgrBenchmark()
+    : lmptr_(NULL) {
 }
 
 GenericLeaseMgrBenchmark::~GenericLeaseMgrBenchmark() {
 }
 
 void
-GenericLeaseMgrBenchmark::ReentrantSetUp4(::benchmark::State& state,
-                                              size_t const& lease_count) {
+GenericLeaseMgrBenchmark::setUp4(::benchmark::State& state, size_t const& lease_count) {
     state.PauseTiming();
     SetUp(state);
     prepareLeases4(lease_count);
@@ -63,8 +53,7 @@ GenericLeaseMgrBenchmark::ReentrantSetUp4(::benchmark::State& state,
 }
 
 void
-GenericLeaseMgrBenchmark::ReentrantSetUpWithInserts4(
-    ::benchmark::State& state, size_t const& lease_count) {
+GenericLeaseMgrBenchmark::setUpWithInserts4(::benchmark::State& state, size_t const& lease_count) {
     state.PauseTiming();
     SetUp(state);
     prepareLeases4(lease_count);
@@ -73,8 +62,7 @@ GenericLeaseMgrBenchmark::ReentrantSetUpWithInserts4(
 }
 
 void
-GenericLeaseMgrBenchmark::ReentrantSetUp6(::benchmark::State& state,
-                                              size_t const& lease_count) {
+GenericLeaseMgrBenchmark::setUp6(::benchmark::State& state, size_t const& lease_count) {
     state.PauseTiming();
     SetUp(state);
     prepareLeases6(lease_count);
@@ -82,8 +70,7 @@ GenericLeaseMgrBenchmark::ReentrantSetUp6(::benchmark::State& state,
 }
 
 void
-GenericLeaseMgrBenchmark::ReentrantSetUpWithInserts6(
-    ::benchmark::State& state, size_t const& lease_count) {
+GenericLeaseMgrBenchmark::setUpWithInserts6(::benchmark::State& state, size_t const& lease_count) {
     state.PauseTiming();
     SetUp(state);
     prepareLeases6(lease_count);
@@ -98,8 +85,7 @@ GenericLeaseMgrBenchmark::prepareLeases4(size_t const& lease_count) {
         Lease4Ptr lease(new Lease4());
         lease->addr_ = IOAddress(i);
         lease->hwaddr_.reset(new HWAddr(vector<uint8_t>(6, i), HTYPE_ETHER));
-        lease->client_id_ =
-            ClientIdPtr(new ClientId(vector<uint8_t>(8, 2 * i)));
+        lease->client_id_ = ClientIdPtr(new ClientId(vector<uint8_t>(8, 2 * i)));
         lease->valid_lft_ = i;
         lease->cltt_ = i;
         lease->subnet_id_ = i;
@@ -247,12 +233,10 @@ GenericLeaseMgrBenchmark::benchGetExpiredLeases6() {
     lmptr_->getExpiredLeases6(expired_leases, leases6_.size());
 }
 
-/*
- *   Calls that aren't measured:
- *      * deleteLease(const Lease4Ptr& lease);
- *      * deleteLease(const Lease6Ptr& lease);
- *      * deleteExpiredReclaimedLeases6(const uint32_t secs);
- */
+/// @todo: Calls that aren't measured:
+/// - deleteLease(const Lease4Ptr& lease);
+/// - deleteLease(const Lease6Ptr& lease);
+/// - deleteExpiredReclaimedLeases6(const uint32_t secs);
 
 }  // namespace bench
 }  // namespace dhcp
index 774ee8d15656783a722dcf143fe788a101207cdc..5b3356260d95069be0c4a6435e7a21027d403884 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -25,40 +26,123 @@ namespace isc {
 namespace dhcp {
 namespace bench {
 
+/// @defgroup memfile_params Benchmark parameters that define boundary values
+///           for benchmarks.
+///
+/// The range is defined as 512..65533. Google benchmark will pick a few specifc
+/// values: 512, 4096, 32768, 65533.
+
+/// @{
+
+/// @brief A minimum number of leases used in a benchmark
+constexpr size_t MIN_LEASE_COUNT = 512;
+/// @brief A maximum number of leases used in a benchmark
+constexpr size_t MAX_LEASE_COUNT = 0xfffd;
+/// @brief A time unit used - all results to be expressed in us (microseconds)
+constexpr benchmark::TimeUnit UNIT = benchmark::kMicrosecond;
+
+/// @}
+
+/// @brief A base class for a fixture for specific lease manager benchmarks
 class GenericLeaseMgrBenchmark : public benchmark::Fixture {
 public:
+
+    /// Specifies the IP protocol family to be bested.
     enum Universe { V4, V6 };
 
+    /// Constructor
     GenericLeaseMgrBenchmark();
+
+    /// Virtual destructor
     virtual ~GenericLeaseMgrBenchmark();
 
-    void ReentrantSetUp4(::benchmark::State& state, size_t const& lease_count);
-    void ReentrantSetUpWithInserts4(::benchmark::State& state,
-                                    size_t const& lease_count);
-    void ReentrantSetUp6(::benchmark::State& state, size_t const& lease_count);
-    void ReentrantSetUpWithInserts6(::benchmark::State& state,
-                                    size_t const& lease_count);
+    /// @brief set up code for initializing IPv4 version of a benchmark
+    ///
+    /// @param state state to be passed to SetUp
+    /// @param lease_count number of leases to be tested
+    void setUp4(::benchmark::State& state, size_t const& lease_count);
+
+    /// @brief set up code (with lease preinsertion) for initializing IPv4
+    /// version of a benchmark.
+    ///
+    /// @param state state to be passed to SetUp
+    /// @param lease_count number of leases to be tested
+    void setUpWithInserts4(::benchmark::State& state, size_t const& lease_count);
+
+    /// @brief set up code for initializing IPv6 version of a benchmark
+    ///
+    /// @param state state to be passed to SetUp
+    /// @param lease_count number of leases to be tested
+    void setUp6(::benchmark::State& state, size_t const& lease_count);
+
+    /// @brief set up code (with lease preinsertion) for initializing IPv6
+    /// version of a benchmark.
+    ///
+    /// @param state state to be passed to SetUp
+    /// @param lease_count number of leases to be tested
+    void setUpWithInserts6(::benchmark::State& state, size_t const& lease_count);
+
+    /// @brief Prepares specified number of IPv4 leases
+    ///
+    /// The leases are stored in leases4_ container.
+    /// @param lease_count specifies the number of leases to be created.
     void prepareLeases4(size_t const& lease_count);
 
+    /// @brief This step inserts all IPv4 leases stored in lease4_ into the LeaseMgr.
     void benchInsertLeases4();
+
+    /// @brief This step updates all IPv4 leases stored in lease4_ in the LeaseMgr.
     void benchUpdateLeases4();
+
+    /// @brief This step retrieves IPv4 leases by IP address.
     void benchGetLease4_address();
+
+    /// @brief This step retrieves IPv4 leases by hardware address.
     void benchGetLease4_hwaddr();
+
+    /// @brief This step retrieves IPv4 leases by (hwaddr, subnet-id) tuple.
     void benchGetLease4_hwaddr_subnetid();
+
+    /// @brief This step retrieves IPv4 leases by client-id.
     void benchGetLease4_clientid();
+
+    /// @brief This step retrieves IPv4 leases by (client-id, subnet-id) tuple.
     void benchGetLease4_clientid_subnetid();
+
+    /// @brief This step retrieves all expired IPv4 leases.
     void benchGetExpiredLeases4();
 
+    /// @brief Prepares specified number of IPv6 leases
+    ///
+    /// The leases are stored in leases6_ container.
+    /// @param lease_count specifies the number of leases to be created.
     void prepareLeases6(size_t const& lease_count);
+
+    /// @brief This step inserts all IPv6 leases stored in lease6_ into the LeaseMgr.
     void benchInsertLeases6();
+
+    /// @brief This step updates all IPv6 leases stored in lease6_ in the LeaseMgr.
     void benchUpdateLeases6();
+
+    /// @brief This step retrieves IPv6 leases by IP address.
     void benchGetLease6_type_address();
+
+    /// @brief This step retrieves IPv6 leases by (type, duid, iaid) tuple.
     void benchGetLease6_type_duid_iaid();
+
+    /// @brief This step retrieves IPv6 leases by (type, duid, iaid, subnet-id) tuple.
     void benchGetLease6_type_duid_iaid_subnetid();
+
+    /// @brief This step retrieves all expired IPv6 leases.
     void benchGetExpiredLeases6();
 
+    /// Pointer to the lease manager being under evaluation.
     LeaseMgr* lmptr_;
+
+    /// List of IPv4 leases (useful during benchmarks)
     Lease4Collection leases4_;
+
+    /// List of IPv6 leases (useful during benchmarks)
     Lease6Collection leases6_;
 };
 
index ac3f78e6f56a7f7e34dacdc6354ac23540d49da2..8d61a10742f66b90127ae39e10bfd5e107e7cdcc 100644 (file)
@@ -11,8 +11,9 @@
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/testutils/lease_file_io.h>
 
-using namespace isc::dhcp::test;
 using namespace isc::dhcp;
+using namespace isc::dhcp::test;
+using namespace isc::dhcp::bench;
 using isc::dhcp::LeaseMgrFactory;
 using isc::dhcp::bench::GenericLeaseMgrBenchmark;
 
@@ -145,7 +146,7 @@ public:
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, insertLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp4(state, lease_count);
+        setUp4(state, lease_count);
         benchInsertLeases4();
     }
 }
@@ -154,7 +155,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, insertLeases4)(benchmark::State& st
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, updateLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchUpdateLeases4();
     }
 }
@@ -163,7 +164,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, updateLeases4)(benchmark::State& st
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_address();
     }
 }
@@ -172,7 +173,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_address)(benchmark::State
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr();
     }
 }
@@ -182,7 +183,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr)(benchmark::State&
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr_subnetid();
     }
 }
@@ -191,7 +192,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_hwaddr_subnetid)(benchmar
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_clientid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid();
     }
 }
@@ -201,7 +202,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_clientid)(benchmark::Stat
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_clientid_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid_subnetid();
     }
 }
@@ -210,7 +211,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease4_clientid_subnetid)(benchm
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getExpiredLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetExpiredLeases4();
     }
 }
@@ -219,7 +220,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getExpiredLeases4)(benchmark::State
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, insertLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp6(state, lease_count);
+        setUp6(state, lease_count);
         benchInsertLeases6();
     }
 }
@@ -228,7 +229,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, insertLeases6)(benchmark::State& st
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, updateLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchUpdateLeases6();
     }
 }
@@ -237,16 +238,16 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, updateLeases6)(benchmark::State& st
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_address();
     }
 }
 
-// Defines a benchmark that measures IPv6 leases retrieval by type,duid and iaid.
+// Defines a benchmark that measures IPv6 leases retrieval by type, duid and iaid.
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid();
     }
 }
@@ -257,7 +258,7 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
                   (benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid_subnetid();
     }
 }
@@ -266,31 +267,13 @@ BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
 BENCHMARK_DEFINE_F(MemfileLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetExpiredLeases6();
     }
 }
 
-/// @defgroup memfile_params Benchmark parameters that define boundary values
-///           for benchmarks.
-///
-/// @{
-
-/// @brief A minimum number of leases used in a benchmark
-constexpr size_t MIN_LEASE_COUNT = 512;
-/// @brief A maximum number of leases used in a benchmark
-constexpr size_t MAX_LEASE_COUNT = 0xfffd;
-/// @brief A time unit used - all results to be expressed in us (microseconds)
-constexpr benchmark::TimeUnit UNIT = benchmark::kMicrosecond;
-
-/// @}
-
-
-/// @defgroup memfile_benchmarks This set of macros define the actual memfile
-///           benchmarks to be used.
-///
-/// The range is defined as 512..65533. Google benchmark will pick a few specifc
-/// values: 512, 4096, 32768, 65533.
+/// The following macros define run parameters for previously defined
+/// memfile benchmarks.
 
 /// A benchmark that measures IPv4 leases insertion.
 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, insertLeases4)
@@ -346,7 +329,7 @@ BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid)
 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
     ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
 
-/// A benchmark that measures expired IPv4 leases retrieval.
+/// A benchmark that measures expired IPv6 leases retrieval.
 BENCHMARK_REGISTER_F(MemfileLeaseMgrBenchmark, getExpiredLeases6)
     ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
 
index b7ae7c56fe8c65efab8f0b2a26e828e23eb9020a..e65cfc69d0660f5a0cf3ee0f120a3a32fec3fcab 100644 (file)
@@ -63,7 +63,7 @@ public:
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, insertHosts)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp(state, host_count);
+        setUp(state, host_count);
         insertHosts();
     }
 }
@@ -71,7 +71,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, insertHosts)(benchmark::State&
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, updateHosts)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         updateHosts();
     }
 }
@@ -79,7 +79,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, updateHosts)(benchmark::State&
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAll2)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll2();
     }
 }
@@ -87,7 +87,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAll2)(benchmark::State& stat
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAll3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll3();
     }
 }
@@ -95,7 +95,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAll3)(benchmark::State& stat
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAll1)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll1();
     }
 }
@@ -103,7 +103,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, getAll1)(benchmark::State& stat
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4_3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_3();
     }
 }
@@ -111,7 +111,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4_3)(benchmark::State& state
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4_4)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_4();
     }
 }
@@ -119,7 +119,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4_4)(benchmark::State& state
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4_2)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_2();
     }
 }
@@ -127,7 +127,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get4_2)(benchmark::State& state
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6_3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_3();
     }
 }
@@ -135,7 +135,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6_3)(benchmark::State& state
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6_4)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_4();
     }
 }
@@ -143,7 +143,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6_4)(benchmark::State& state
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6_2_subnetid_address)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_2_subnetid_address();
     }
 }
@@ -151,7 +151,7 @@ BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6_2_subnetid_address)(benchm
 BENCHMARK_DEFINE_F(MySqlHostDataSourceBenchmark, get6_2_prefix_prefixlen)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_2_prefix_prefixlen();
     }
 }
index d81a0426594b89a08ffa01e45c21a269e9ff17ba..1bbe6151fee15427cc5d66a798845b918c25ce33 100644 (file)
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/testutils/mysql_schema.h>
 
+using namespace isc::dhcp::bench;
+using namespace isc::dhcp::test;
+using namespace std;
 using isc::dhcp::LeaseMgrFactory;
-using isc::dhcp::bench::GenericLeaseMgrBenchmark;
-using isc::dhcp::test::createMySQLSchema;
-using isc::dhcp::test::destroyMySQLSchema;
-using isc::dhcp::test::validMySQLConnectionString;
-using std::cerr;
-using std::endl;
+//using isc::dhcp::bench::GenericLeaseMgrBenchmark;
 
 namespace {
 
+/// @brief This is a fixture class used for benchmarking MySQL lease backend
 class MySqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark {
 public:
+    /// @brief Setup routine.
+    ///
+    /// It cleans up schema and recreates tables, then instantiates LeaseMgr
     void SetUp(::benchmark::State const&) override {
         destroyMySQLSchema(false);
         createMySQLSchema(false);
@@ -45,6 +47,7 @@ public:
         lmptr_ = &(LeaseMgrFactory::instance());
     }
 
+    /// @brief Cleans up after the test.
     void TearDown(::benchmark::State const&) override {
         try {
             lmptr_->rollback();
@@ -58,136 +61,197 @@ public:
     }
 };
 
+// Defines a benchmark that measures IPv4 leases insertion.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, insertLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp4(state, lease_count);
+        setUp4(state, lease_count);
         benchInsertLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases update.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, updateLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchUpdateLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by address.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease4_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_address();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by hardware address
+// and subnet-id.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by hardware address
+// and subnet-id.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr_subnetid();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by client-id.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease4_clientid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by client-id and
+// subnet-id.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease4_clientid_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid_subnetid();
     }
 }
 
+// Defines a benchmark that measures retrieval of expired IPv4 leases.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getExpiredLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetExpiredLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases insertion.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, insertLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp6(state, lease_count);
+        setUp6(state, lease_count);
         benchInsertLeases6();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases update.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, updateLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchUpdateLeases6();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases retrieval by type and address.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease6_type_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_address();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases retrieval by type, duid and iaid.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid();
     }
 }
 
-BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease6_type_type_duid_iaid_subnetid)
+// Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid
+// and subnet-id.
+BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
     (benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid_subnetid();
     }
 }
 
+// Defines a benchmark that measures retrieval of expired IPv6 leases.
 BENCHMARK_DEFINE_F(MySqlLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetExpiredLeases6();
     }
 }
 
-constexpr size_t MIN_LEASE_COUNT = 512;
-constexpr size_t MAX_LEASE_COUNT = 0xfffd;
-constexpr benchmark::TimeUnit UNIT = benchmark::kMicrosecond;
-
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, insertLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, updateLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_address)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_clientid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_clientid_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getExpiredLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, insertLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, updateLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_address)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_type_duid_iaid_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getExpiredLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+/// The following macros define run parameters for previously defined
+/// MySQL benchmarks.
+
+
+/// A benchmark that measures IPv4 leases insertion.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, insertLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 leases update.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, updateLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by IP address.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_address)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by hardware address.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by hardware address and a
+/// subnet-id.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by client-id.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_clientid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by client-id and subnet-id.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease4_clientid_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures expired IPv4 leases retrieval.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getExpiredLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 leases insertion.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, insertLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 leases update.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, updateLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type and IP address.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_address)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type, duid, iaid and
+/// subnet-id.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures expired IPv6 leases retrieval.
+BENCHMARK_REGISTER_F(MySqlLeaseMgrBenchmark, getExpiredLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
 
 }  // namespace
index 589479724b65527050ce125a6788181bad00a595..7b7b245f9a62ff20660394f87325e4304b0bafe5 100644 (file)
@@ -63,7 +63,7 @@ public:
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, insertHosts)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp(state, host_count);
+        setUp(state, host_count);
         insertHosts();
     }
 }
@@ -71,7 +71,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, insertHosts)(benchmark::State&
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, updateHosts)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         updateHosts();
     }
 }
@@ -79,7 +79,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, updateHosts)(benchmark::State&
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll2)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll2();
     }
 }
@@ -87,7 +87,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll2)(benchmark::State& stat
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll3();
     }
 }
@@ -95,7 +95,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll3)(benchmark::State& stat
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll1)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         getAll1();
     }
 }
@@ -103,7 +103,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, getAll1)(benchmark::State& stat
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4_3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_3();
     }
 }
@@ -111,7 +111,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4_3)(benchmark::State& state
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4_4)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_4();
     }
 }
@@ -119,7 +119,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4_4)(benchmark::State& state
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4_2)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get4_2();
     }
 }
@@ -127,7 +127,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get4_2)(benchmark::State& state
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6_3)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_3();
     }
 }
@@ -135,7 +135,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6_3)(benchmark::State& state
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6_4)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_4();
     }
 }
@@ -143,7 +143,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6_4)(benchmark::State& state
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6_2_subnetid_address)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_2_subnetid_address();
     }
 }
@@ -151,7 +151,7 @@ BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6_2_subnetid_address)(benchm
 BENCHMARK_DEFINE_F(PgSqlHostDataSourceBenchmark, get6_2_prefix_prefixlen)(benchmark::State& state) {
     const size_t host_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts(state, host_count);
+        setUpWithInserts(state, host_count);
         get6_2_prefix_prefixlen();
     }
 }
index 315e1ad8df4d17913f4746a42ed16cd7b2b5a947..d73c1b5abe1a7ee8c2dee3584ca350b974227a92 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2017 Deutsche Telekom AG.
 //
 // Authors: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -20,6 +21,7 @@
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/testutils/pgsql_schema.h>
 
+using namespace isc::dhcp::bench;
 using isc::dhcp::LeaseMgrFactory;
 using isc::dhcp::bench::GenericLeaseMgrBenchmark;
 using isc::dhcp::test::createPgSQLSchema;
@@ -30,8 +32,12 @@ using std::endl;
 
 namespace {
 
+/// @brief This is a fixture class used for benchmarking Postgres lease backend
 class PgSqlLeaseMgrBenchmark : public GenericLeaseMgrBenchmark {
 public:
+    /// @brief Setup routine.
+    ///
+    /// It cleans up schema and recreates tables, then instantiates LeaseMgr
     void SetUp(::benchmark::State const&) override {
         destroyPgSQLSchema(false);
         createPgSQLSchema(false);
@@ -45,6 +51,7 @@ public:
         lmptr_ = &(LeaseMgrFactory::instance());
     }
 
+    /// @brief Cleans up after the test.
     void TearDown(::benchmark::State const&) override {
         try {
             lmptr_->rollback();
@@ -58,135 +65,193 @@ public:
     }
 };
 
+// Defines a benchmark that measures IPv4 leases insertion.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, insertLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp4(state, lease_count);
+        setUp4(state, lease_count);
         benchInsertLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases update.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, updateLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchUpdateLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by address.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease4_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_address();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by hardware address.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by hardware address
+// and subnet-id.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_hwaddr_subnetid();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by client-id.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease4_clientid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid();
     }
 }
 
+// Defines a benchmark that measures IPv4 leases retrieval by client-id and
+// subnet-id.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease4_clientid_subnetid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetLease4_clientid_subnetid();
     }
 }
 
+// Defines a benchmark that measures retrieval of expired IPv4 leases.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getExpiredLeases4)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts4(state, lease_count);
+        setUpWithInserts4(state, lease_count);
         benchGetExpiredLeases4();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases insertion.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, insertLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUp6(state, lease_count);
+        setUp6(state, lease_count);
         benchInsertLeases6();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases update.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, updateLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchUpdateLeases6();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases retrieval by type and address.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease6_type_address)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_address();
     }
 }
 
+// Defines a benchmark that measures IPv6 leases retrieval by type, duid and iaid.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid();
     }
 }
 
-BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease6_type_type_duid_iaid_subnetid)(benchmark::State& state) {
+// Defines a benchmark that measures IPv6 leases retrieval by lease type, duid, iaid
+// and subnet-id.
+BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
+                  (benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetLease6_type_duid_iaid_subnetid();
     }
 }
 
+// Defines a benchmark that measures retrieval of expired IPv6 leases.
 BENCHMARK_DEFINE_F(PgSqlLeaseMgrBenchmark, getExpiredLeases6)(benchmark::State& state) {
     const size_t lease_count = state.range(0);
     while (state.KeepRunning()) {
-        ReentrantSetUpWithInserts6(state, lease_count);
+        setUpWithInserts6(state, lease_count);
         benchGetExpiredLeases6();
     }
 }
 
-constexpr size_t MIN_LEASE_COUNT = 512;
-constexpr size_t MAX_LEASE_COUNT = 0xfffd;
-constexpr benchmark::TimeUnit UNIT = benchmark::kMicrosecond;
-
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, insertLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, updateLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_address)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_clientid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_clientid_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getExpiredLeases4)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, insertLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, updateLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_address)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_type_duid_iaid_subnetid)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
-BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getExpiredLeases6)->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+/// The following macros define run parameters for previously defined
+/// Postgres benchmarks.
 
+/// A benchmark that measures IPv4 leases insertion.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, insertLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 leases update.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, updateLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by IP address.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_address)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by hardware address.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by hardware address and a
+/// subnet-id.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_hwaddr_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by client-id.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_clientid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv4 lease retrieval by client-id and subnet-id.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease4_clientid_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures expired IPv4 leases retrieval.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getExpiredLeases4)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 leases insertion.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, insertLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 leases update.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, updateLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type and IP address.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_address)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures IPv6 lease retrieval by lease type, duid and iaid.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getLease6_type_duid_iaid_subnetid)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
+
+/// A benchmark that measures expired IPv4 leases retrieval.
+BENCHMARK_REGISTER_F(PgSqlLeaseMgrBenchmark, getExpiredLeases6)
+    ->Range(MIN_LEASE_COUNT, MAX_LEASE_COUNT)->Unit(UNIT);
 }  // namespace
index 6ec19d24912dedeb5321762b15db04570480e2b1..bcc4a536a900913bf4f2aad9041ed279b000d365 100644 (file)
@@ -19,6 +19,7 @@
 #include <benchmark/benchmark.h>
 #include <log/logger_support.h>
 
+/// @brief A simple class that initializes logging.
 class Initializer {
 public:
     Initializer() {
index 13c1a594cc063697401c272116e5207310447d4b..7aa5eb7ddfe373bb2fa0978b3bfee4ea2332ff3a 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
 // Copyright (C) 2016-2017 Deutsche Telekom AG.
 //
 // Author: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -159,8 +160,7 @@ public:
     /// @param statement_tag prepared statement being executed; defaults to an
     ///     invalid statement
     virtual void
-    createBindForSelect(AnyArray& data,
-                        StatementTag statement_tag = NULL) override;
+    createBindForSelect(AnyArray& data, StatementTag statement_tag = NULL) override;
 
     /// @brief Binds @ref Host to data array to send data to the Cassandra
     ///     database.
index 60ea0a805c965b687d314d3dae1ec6e363384694..808697e21c425b46ab002f33b220981f17d5267b 100644 (file)
@@ -274,7 +274,7 @@ public:
     ///     there.
     /// @throw various exceptions in case of errors
     virtual bool del(const SubnetID& subnet_id,
-                     const asiolink::IOAddress& addr);
+                     const asiolink::IOAddress& addr) override;
 
     /// @brief Attempts to delete a host by (subnet-id4, identifier-type,
     /// identifier).
@@ -292,7 +292,7 @@ public:
     virtual bool del4(const SubnetID& subnet_id,
                       const Host::IdentifierType& identifier_type,
                       const uint8_t* identifier_begin,
-                      const size_t identifier_len);
+                      const size_t identifier_len) override;
 
     /// @brief Attempts to delete a host by (subnet-id6, identifier-type,
     /// identifier).
@@ -310,7 +310,7 @@ public:
     virtual bool del6(const SubnetID& subnet_id,
                       const Host::IdentifierType& identifier_type,
                       const uint8_t* identifier_begin,
-                      const size_t identifier_len);
+                      const size_t identifier_len) override;
 
     /// @brief Returns textual description of the backend.
     ///
index 1882e9fae6660f846c7e9489cd7203f4358ac70f..cf6e8a948f70c698fcd09e798d1ab966ceb39157 100644 (file)
@@ -15,6 +15,7 @@
 #include <dhcpsrv/tests/generic_host_data_source_unittest.h>
 #include <dhcpsrv/tests/test_utils.h>
 #include <dhcpsrv/testutils/cql_schema.h>
+#include <dhcpsrv/testutils/host_data_source_utils.h>
 #include <exceptions/exceptions.h>
 
 #include <gtest/gtest.h>
@@ -489,7 +490,7 @@ TEST_F(CqlHostDataSourceTest, testAddRollback) {
     destroyCqlSchema(false, true);
 
     // Create a host with a reservation.
-    HostPtr host = initializeHost6("2001:db8:1::1", Host::IDENT_HWADDR, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8:1::1", Host::IDENT_HWADDR, false);
     // Let's assign some DHCPv4 subnet to the host, because we will use the
     // DHCPv4 subnet to try to retrieve the host after failed insertion.
     host->setIPv4SubnetID(SubnetID(4));
@@ -573,14 +574,4 @@ TEST_F(CqlHostDataSourceTest, DISABLED_testMultipleHosts6) {
     testMultipleHosts6();
 }
 
-TEST_F(CqlHostDataSourceTest, DISABLED_stressTest) {
-    // Run with 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4092, 8192,
-    // 16384 & 32768 hosts.
-    for (unsigned int i = 0X0001U; i < 0xfffdU; i <<= 1) {
-        initializeTest();
-        stressTest(i);
-        destroyTest();
-    }
-}
-
 }  // namespace
index 27c48bb3c2c5c965bcb77b4164e88b8cc00d95cf..745fd7f612bcaef64621fac3696e6e80b05e00d6 100644 (file)
@@ -20,6 +20,7 @@
 #include <dhcpsrv/tests/generic_host_data_source_unittest.h>
 #include <dhcpsrv/tests/test_utils.h>
 #include <dhcpsrv/testutils/schema.h>
+#include <dhcpsrv/testutils/host_data_source_utils.h>
 #include <gtest/gtest.h>
 #include <util/buffer.h>
 
@@ -48,240 +49,6 @@ GenericHostDataSourceTest::~GenericHostDataSourceTest() {
     hdsptr_.reset();
 }
 
-std::vector<uint8_t>
-GenericHostDataSourceTest::generateHWAddr(const bool new_identifier) {
-    /// @todo: Consider moving this somewhere to lib/testutils.
-
-    // Let's use something that is easily printable. That's convenient
-    // if you need to enter MySQL queries by hand.
-    static uint8_t hwaddr[] = {65, 66, 67, 68, 69, 70};
-
-    if (new_identifier) {
-        // Increase the address for the next time we use it.
-        // This is primitive, but will work for 65k unique
-        // addresses.
-        hwaddr[sizeof(hwaddr) - 1]++;
-        if (hwaddr[sizeof(hwaddr) - 1] == 0) {
-            hwaddr[sizeof(hwaddr) - 2]++;
-        }
-    }
-    return (std::vector<uint8_t>(hwaddr, hwaddr + sizeof(hwaddr)));
-}
-
-std::vector<uint8_t>
-GenericHostDataSourceTest::generateIdentifier(const bool new_identifier) {
-    /// @todo: Consider moving this somewhere to lib/testutils.
-
-    // Let's use something that is easily printable. That's convenient
-    // if you need to enter MySQL queries by hand.
-    static uint8_t ident[] = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74};
-
-    if (new_identifier) {
-        // Increase the identifier for the next time we use it.
-        // This is primitive, but will work for 65k unique identifiers.
-        ident[sizeof(ident) - 1]++;
-        if (ident[sizeof(ident) - 1] == 0) {
-            ident[sizeof(ident) - 2]++;
-        }
-    }
-    return (std::vector<uint8_t>(ident, ident + sizeof(ident)));
-}
-
-HostPtr
-GenericHostDataSourceTest::initializeHost4(const std::string& address,
-                                           const Host::IdentifierType& id) {
-    std::vector<uint8_t> ident;
-    if (id == Host::IDENT_HWADDR) {
-        ident = generateHWAddr();
-    } else {
-        ident = generateIdentifier();
-    }
-
-    // Let's create ever increasing subnet-ids. Let's keep those different,
-    // so subnet4 != subnet6. Useful for catching cases if the code confuses
-    // subnet4 with subnet6.
-    static SubnetID subnet4 = 0;
-    static SubnetID subnet6 = 100;
-    ++subnet4;
-    ++subnet6;
-
-    IOAddress addr(address);
-    HostPtr host(new Host(&ident[0], ident.size(), id, subnet4, subnet6, addr));
-
-    return (host);
-}
-
-HostPtr
-GenericHostDataSourceTest::initializeHost6(std::string address,
-                                           Host::IdentifierType identifier,
-                                           bool prefix,
-                                           bool new_identifier) {
-    std::vector<uint8_t> ident;
-    switch (identifier) {
-    case Host::IDENT_HWADDR:
-        ident = generateHWAddr(new_identifier);
-        break;
-    case Host::IDENT_DUID:
-        ident = generateIdentifier(new_identifier);
-        break;
-    default:
-        ADD_FAILURE() << "Unknown IdType: " << identifier;
-        return HostPtr();
-    }
-
-    // Let's create ever increasing subnet-ids. Let's keep those different,
-    // so subnet4 != subnet6. Useful for catching cases if the code confuses
-    // subnet4 with subnet6.
-    static SubnetID subnet4 = 0;
-    static SubnetID subnet6 = 100;
-    subnet4++;
-    subnet6++;
-
-    HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6,
-                          IOAddress("0.0.0.0")));
-
-    if (!prefix) {
-        // Create IPv6 reservation (for an address)
-        IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), 128);
-        host->addReservation(resv);
-    } else {
-        // Create IPv6 reservation for a /64 prefix
-        IPv6Resrv resv(IPv6Resrv::TYPE_PD, IOAddress(address), 64);
-        host->addReservation(resv);
-    }
-    return (host);
-}
-
-bool
-GenericHostDataSourceTest::reservationExists(const IPv6Resrv& resrv,
-                                             const IPv6ResrvRange& range) {
-    for (IPv6ResrvIterator it = range.first; it != range.second; ++it) {
-        if (resrv == it->second) {
-            return true;
-        }
-    }
-    return false;
-}
-
-void
-GenericHostDataSourceTest::compareHwaddrs(const ConstHostPtr& host1,
-                                          const ConstHostPtr& host2,
-                                          bool expect_match) {
-    ASSERT_TRUE(host1);
-    ASSERT_TRUE(host2);
-
-    // Compare if both have or have not HWaddress set.
-    if ((host1->getHWAddress() && !host2->getHWAddress()) ||
-        (!host1->getHWAddress() && host2->getHWAddress())) {
-        // One host has hardware address set while the other has not.
-        // Let's see if it's a problem.
-        if (expect_match) {
-            ADD_FAILURE() << "Host comparison failed: host1 hwaddress="
-                          << host1->getHWAddress()
-                          << ", host2 hwaddress=" << host2->getHWAddress();
-        }
-        return;
-    }
-
-    // Now we know that either both or neither have hw address set.
-    // If host1 has it, we can proceed to value comparison.
-    if (host1->getHWAddress()) {
-        if (expect_match) {
-            // Compare the actual address if they match.
-            EXPECT_TRUE(*host1->getHWAddress() == *host2->getHWAddress());
-        } else {
-            EXPECT_FALSE(*host1->getHWAddress() == *host2->getHWAddress());
-        }
-        if (*host1->getHWAddress() != *host2->getHWAddress()) {
-            cout << host1->getHWAddress()->toText(true) << endl;
-            cout << host2->getHWAddress()->toText(true) << endl;
-        }
-    }
-}
-
-void
-GenericHostDataSourceTest::compareDuids(const ConstHostPtr& host1,
-                                        const ConstHostPtr& host2,
-                                        bool expect_match) {
-    ASSERT_TRUE(host1);
-    ASSERT_TRUE(host2);
-
-    // compare if both have or have not DUID set
-    if ((host1->getDuid() && !host2->getDuid()) ||
-        (!host1->getDuid() && host2->getDuid())) {
-        // One host has a DUID and the other doesn't.
-        // Let's see if it's a problem.
-        if (expect_match) {
-            ADD_FAILURE() << "DUID comparison failed: host1 duid="
-                          << host1->getDuid()
-                          << ", host2 duid=" << host2->getDuid();
-        }
-        return;
-    }
-
-    // Now we know that either both or neither have DUID set.
-    // If host1 has it, we can proceed to value comparison.
-    if (host1->getDuid()) {
-        if (expect_match) {
-            EXPECT_TRUE(*host1->getDuid() == *host2->getDuid());
-        } else {
-            EXPECT_FALSE(*host1->getDuid() == *host2->getDuid());
-        }
-        if (*host1->getDuid() != *host2->getDuid()) {
-            cout << host1->getDuid()->toText() << endl;
-            cout << host2->getDuid()->toText() << endl;
-        }
-    }
-}
-
-void
-GenericHostDataSourceTest::compareHosts(const ConstHostPtr& host1,
-                                        const ConstHostPtr& host2) {
-    // Let's compare HW addresses and expect match.
-    compareHwaddrs(host1, host2, true);
-
-    // Now compare DUIDs
-    compareDuids(host1, host2, true);
-
-    // Now check that the identifiers returned as vectors are the same
-    EXPECT_EQ(host1->getIdentifierType(), host2->getIdentifierType());
-    EXPECT_TRUE(host1->getIdentifier() == host2->getIdentifier());
-
-    // Check host parameters
-    EXPECT_EQ(host1->getIPv4SubnetID(), host2->getIPv4SubnetID());
-    EXPECT_EQ(host1->getIPv6SubnetID(), host2->getIPv6SubnetID());
-    EXPECT_EQ(host1->getIPv4Reservation(), host2->getIPv4Reservation());
-    EXPECT_EQ(host1->getHostname(), host2->getHostname());
-    EXPECT_EQ(host1->getNextServer(), host2->getNextServer());
-    EXPECT_EQ(host1->getServerHostname(), host2->getServerHostname());
-    EXPECT_EQ(host1->getBootFileName(), host2->getBootFileName());
-    ConstElementPtr ctx1 = host1->getContext();
-    ConstElementPtr ctx2 = host2->getContext();
-    if (ctx1) {
-        EXPECT_TRUE(ctx2);
-        if (ctx2) {
-            EXPECT_EQ(*ctx1, *ctx2);
-        }
-    } else {
-        EXPECT_FALSE(ctx2);
-    }
-
-    // Compare IPv6 reservations
-    compareReservations6(host1->getIPv6Reservations(),
-                         host2->getIPv6Reservations());
-
-    // Compare client classification details
-    compareClientClasses(host1->getClientClasses4(),
-                         host2->getClientClasses4());
-
-    compareClientClasses(host1->getClientClasses6(),
-                         host2->getClientClasses6());
-
-    // Compare DHCPv4 and DHCPv6 options.
-    compareOptions(host1->getCfgOption4(), host2->getCfgOption4());
-    compareOptions(host1->getCfgOption6(), host2->getCfgOption6());
-}
-
 bool
 GenericHostDataSourceTest::compareHostsForSort4(const ConstHostPtr& host1,
                                                 const ConstHostPtr& host2) {
@@ -318,149 +85,6 @@ GenericHostDataSourceTest::DuidToHWAddr(const DuidPtr& duid) {
     return (HWAddrPtr(new HWAddr(duid->getDuid(), HTYPE_ETHER)));
 }
 
-void
-GenericHostDataSourceTest::compareReservations6(IPv6ResrvRange resrv1,
-                                                IPv6ResrvRange resrv2) {
-    // Compare number of reservations for both hosts
-    if (std::distance(resrv1.first, resrv1.second) !=
-        std::distance(resrv2.first, resrv2.second)) {
-        ADD_FAILURE() << "Reservation comparison failed, "
-                         "hosts got different number of reservations.";
-        return;
-    }
-
-    // Iterate over the range of reservations to find a match in the
-    // reference range.
-    for (IPv6ResrvIterator r1 = resrv1.first; r1 != resrv1.second; ++r1) {
-        IPv6ResrvIterator r2 = resrv2.first;
-        for (; r2 != resrv2.second; ++r2) {
-            // IPv6Resrv object implements equality operator.
-            if (r1->second == r2->second) {
-                break;
-            }
-        }
-        // If r2 iterator reached the end of the range it means that there
-        // is no match.
-        if (r2 == resrv2.second) {
-            ADD_FAILURE() << "No match found for reservation: "
-                          << resrv1.first->second.getPrefix().toText();
-        }
-    }
-
-    if (std::distance(resrv1.first, resrv1.second) > 0) {
-        for (; resrv1.first != resrv1.second; resrv1.first++) {
-            IPv6ResrvIterator iter = resrv2.first;
-            while (iter != resrv2.second) {
-                if ((resrv1.first->second.getType() ==
-                     iter->second.getType()) &&
-                    (resrv1.first->second.getPrefixLen() ==
-                     iter->second.getPrefixLen()) &&
-                    (resrv1.first->second.getPrefix() ==
-                     iter->second.getPrefix())) {
-                    break;
-                }
-                iter++;
-                if (iter == resrv2.second) {
-                    ADD_FAILURE() << "Reservation comparison failed, "
-                                     "no match for reservation: "
-                                  << resrv1.first->second.getPrefix().toText();
-                }
-            }
-        }
-    }
-}
-
-void
-GenericHostDataSourceTest::compareClientClasses(const ClientClasses& classes1,
-                                                const ClientClasses& classes2) {
-    EXPECT_TRUE(std::equal(classes1.begin(), classes1.end(), classes2.begin()));
-}
-
-void
-GenericHostDataSourceTest::compareOptions(const ConstCfgOptionPtr& cfg1,
-                                          const ConstCfgOptionPtr& cfg2) const {
-    ASSERT_TRUE(cfg1);
-    ASSERT_TRUE(cfg2);
-
-    // Combine option space names with vendor space names in a single list.
-    std::list<std::string> option_spaces = cfg2->getOptionSpaceNames();
-    std::list<std::string> vendor_spaces = cfg2->getVendorIdsSpaceNames();
-    option_spaces.insert(option_spaces.end(), vendor_spaces.begin(),
-                         vendor_spaces.end());
-
-    // Make sure that the number of option spaces is equal in both
-    // configurations.
-    EXPECT_EQ(option_spaces.size(), cfg1->getOptionSpaceNames().size());
-    EXPECT_EQ(vendor_spaces.size(), cfg1->getVendorIdsSpaceNames().size());
-
-    // Iterate over all option spaces existing in cfg2.
-    BOOST_FOREACH (std::string space, option_spaces) {
-        // Retrieve options belonging to the current option space.
-        OptionContainerPtr options1 = cfg1->getAll(space);
-        OptionContainerPtr options2 = cfg2->getAll(space);
-        ASSERT_TRUE(options1) << "failed for option space " << space;
-        ASSERT_TRUE(options2) << "failed for option space " << space;
-
-        // If number of options doesn't match, the test fails.
-        ASSERT_EQ(options1->size(), options2->size())
-            << "failed for option space " << space;
-
-        // Iterate over all options within this option space.
-        BOOST_FOREACH (OptionDescriptor desc1, *options1) {
-            OptionDescriptor desc2 = cfg2->get(space, desc1.option_->getType());
-            // Compare persistent flag.
-            EXPECT_EQ(desc1.persistent_, desc2.persistent_)
-                << "failed for option " << space << "."
-                << desc1.option_->getType();
-            // Compare formatted value.
-            EXPECT_EQ(desc1.formatted_value_, desc2.formatted_value_)
-                << "failed for option " << space << "."
-                << desc1.option_->getType();
-
-            // Compare user context.
-            ConstElementPtr ctx1 = desc1.getContext();
-            ConstElementPtr ctx2 = desc2.getContext();
-            if (ctx1) {
-                EXPECT_TRUE(ctx2);
-                if (ctx2) {
-                    EXPECT_EQ(*ctx1, *ctx2)
-                        << "failed for option " << space << "." << desc1.option_->getType();
-                }
-            } else {
-                EXPECT_FALSE(ctx2);
-            }
-
-            // Retrieve options.
-            Option* option1 = desc1.option_.get();
-            Option* option2 = desc2.option_.get();
-
-            // Options must be represented by the same C++ class derived from
-            // the Option class.
-            EXPECT_TRUE(typeid(*option1) == typeid(*option2))
-                << "Compared DHCP options, having option code "
-                << desc1.option_->getType() << " and belonging to the " << space
-                << " option space, are represented "
-                   "by different C++ classes: "
-                << typeid(*option1).name() << " vs " << typeid(*option2).name();
-
-            // Because we use different C++ classes to represent different
-            // options, the simplest way to make sure that the options are
-            // equal is to simply compare them in wire format.
-            OutputBuffer buf1(option1->len());
-            ASSERT_NO_THROW(option1->pack(buf1));
-            OutputBuffer buf2(option2->len());
-            ASSERT_NO_THROW(option2->pack(buf2));
-
-            ASSERT_EQ(buf1.getLength(), buf2.getLength())
-                << "failed for option " << space << "."
-                << desc1.option_->getType();
-            EXPECT_EQ(0,
-                      memcmp(buf1.getData(), buf2.getData(), buf1.getLength()))
-                << "failed for option " << space << "."
-                << desc1.option_->getType();
-        }
-    }
-}
 
 OptionDescriptor
 GenericHostDataSourceTest::createEmptyOption(const Option::Universe& universe,
@@ -569,7 +193,7 @@ GenericHostDataSourceTest::testReadOnlyDatabase(const char* valid_db_type) {
 
     // The database is initially opened in "read-write" mode. We can
     // insert some data to the database.
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
     ASSERT_TRUE(host);
     ASSERT_NO_THROW(hdsptr_->add(host));
 
@@ -582,7 +206,7 @@ GenericHostDataSourceTest::testReadOnlyDatabase(const char* valid_db_type) {
         hdsptr_->get6(subnet_id, host->getIdentifierType(),
                       &host->getIdentifier()[0], host->getIdentifier().size());
     ASSERT_TRUE(host_by_id);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_id));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
 
     // Close the database connection and reopen in "read-only" mode as
     // specified by the "VALID_READONLY_DB" parameter.
@@ -595,7 +219,7 @@ GenericHostDataSourceTest::testReadOnlyDatabase(const char* valid_db_type) {
 
     // Check that an attempt to insert new host would result in
     // exception.
-    HostPtr host2 = initializeHost6("2001:db8::2", Host::IDENT_DUID, false);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::2", Host::IDENT_DUID, false);
     ASSERT_TRUE(host2);
     ASSERT_THROW(hdsptr_->add(host2), ReadOnlyDb);
     ASSERT_THROW(hdsptr_->commit(), ReadOnlyDb);
@@ -606,7 +230,7 @@ GenericHostDataSourceTest::testReadOnlyDatabase(const char* valid_db_type) {
         hdsptr_->get6(subnet_id, host->getIdentifierType(),
                       &host->getIdentifier()[0], host->getIdentifier().size());
     ASSERT_TRUE(host_by_id);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_id));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
 }
 
 void
@@ -615,7 +239,7 @@ GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservation.
-    HostPtr host = initializeHost4("192.0.2.1", id);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", id);
     ASSERT_TRUE(host);  // Make sure the host is generate properly.
     SubnetID subnet = host->getIPv4SubnetID();
 
@@ -631,7 +255,7 @@ GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) {
     ASSERT_TRUE(from_hds);
 
     // Finally, let's check if what we got makes any sense.
-    compareHosts(host, from_hds);
+    HostDataSourceUtils::compareHosts(host, from_hds);
 }
 
 void
@@ -640,10 +264,10 @@ GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a couple of hosts...
-    HostPtr host1 = initializeHost4("192.0.2.1", id);
-    HostPtr host2 = initializeHost4("192.0.2.2", id);
-    HostPtr host3 = initializeHost4("192.0.2.3", id);
-    HostPtr host4 = initializeHost4("192.0.2.4", id);
+    HostPtr host1 = HostDataSourceUtils::initializeHost4("192.0.2.1", id);
+    HostPtr host2 = HostDataSourceUtils::initializeHost4("192.0.2.2", id);
+    HostPtr host3 = HostDataSourceUtils::initializeHost4("192.0.2.3", id);
+    HostPtr host4 = HostDataSourceUtils::initializeHost4("192.0.2.4", id);
 
     // ... and add them to the data source.
     ASSERT_NO_THROW(hdsptr_->add(host1));
@@ -669,10 +293,10 @@ GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
     ASSERT_TRUE(from_hds4);
 
     // Then let's check that what we got seems correct.
-    compareHosts(host1, from_hds1);
-    compareHosts(host2, from_hds2);
-    compareHosts(host3, from_hds3);
-    compareHosts(host4, from_hds4);
+    HostDataSourceUtils::compareHosts(host1, from_hds1);
+    HostDataSourceUtils::compareHosts(host2, from_hds2);
+    HostDataSourceUtils::compareHosts(host3, from_hds3);
+    HostDataSourceUtils::compareHosts(host4, from_hds4);
 
     // Ok, finally let's check that getting by a different address
     // will not work.
@@ -685,8 +309,8 @@ GenericHostDataSourceTest::testGet4ByIdentifier(
     // Make sure we have a pointer to the host data source.
     ASSERT_TRUE(hdsptr_);
 
-    HostPtr host1 = initializeHost4("192.0.2.1", identifier_type);
-    HostPtr host2 = initializeHost4("192.0.2.2", identifier_type);
+    HostPtr host1 = HostDataSourceUtils::initializeHost4("192.0.2.1", identifier_type);
+    HostPtr host2 = HostDataSourceUtils::initializeHost4("192.0.2.2", identifier_type);
 
     // Sanity check: make sure the hosts have different identifiers..
     ASSERT_FALSE(host1->getIdentifier() == host2->getIdentifier());
@@ -709,8 +333,8 @@ GenericHostDataSourceTest::testGet4ByIdentifier(
     // Now let's check if we got what we expected.
     ASSERT_TRUE(from_hds1);
     ASSERT_TRUE(from_hds2);
-    compareHosts(host1, from_hds1);
-    compareHosts(host2, from_hds2);
+    HostDataSourceUtils::compareHosts(host1, from_hds1);
+    HostDataSourceUtils::compareHosts(host2, from_hds2);
 }
 
 void
@@ -719,7 +343,7 @@ GenericHostDataSourceTest::testHWAddrNotClientId() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host with HW address
-    HostPtr host = initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
     ASSERT_TRUE(host->getHWAddress());
     ASSERT_FALSE(host->getDuid());
 
@@ -751,7 +375,7 @@ GenericHostDataSourceTest::testClientIdNotHWAddr() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host with client-id
-    HostPtr host = initializeHost4("192.0.2.1", Host::IDENT_DUID);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_DUID);
     ASSERT_FALSE(host->getHWAddress());
     ASSERT_TRUE(host->getDuid());
 
@@ -792,7 +416,7 @@ GenericHostDataSourceTest::testHostname(std::string name, int num) {
     for (int i = 0; i < num; ++i) {
         addr = IOAddress::increase(addr);
 
-        HostPtr host = initializeHost4(addr.toText(), Host::IDENT_DUID);
+        HostPtr host = HostDataSourceUtils::initializeHost4(addr.toText(), Host::IDENT_DUID);
 
         stringstream hostname;
         hostname.str("");
@@ -832,7 +456,7 @@ GenericHostDataSourceTest::testUserContext(ConstElementPtr user_context) {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservation.
-    HostPtr host = initializeHost4("192.0.2.1", Host::IDENT_DUID);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_DUID);
     ASSERT_TRUE(host); // Make sure the host is generated properly.
     host->setContext(user_context);
     SubnetID subnet = host->getIPv4SubnetID();
@@ -845,10 +469,10 @@ GenericHostDataSourceTest::testUserContext(ConstElementPtr user_context) {
     ASSERT_TRUE(from_hds);
 
     // Finally, let's check if what we got makes any sense.
-    compareHosts(host, from_hds);
+    HostDataSourceUtils::compareHosts(host, from_hds);
 
     // Retry with IPv6
-    host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
+    host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
     ASSERT_TRUE(host);
     ASSERT_TRUE(host->getHWAddress());
     host->setContext(user_context);
@@ -862,7 +486,7 @@ GenericHostDataSourceTest::testUserContext(ConstElementPtr user_context) {
                              host->getIdentifier().size());
     ASSERT_TRUE(from_hds);
 
-    compareHosts(host, from_hds);
+    HostDataSourceUtils::compareHosts(host, from_hds);
 }
 
 void
@@ -871,7 +495,7 @@ GenericHostDataSourceTest::testMultipleSubnets(int subnets,
     // Make sure we have a pointer to the host data source.
     ASSERT_TRUE(hdsptr_);
 
-    HostPtr host = initializeHost4("192.0.2.1", id);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", id);
     host->setIPv6SubnetID(0);
 
     for (int i = 0; i < subnets; ++i) {
@@ -942,14 +566,14 @@ GenericHostDataSourceTest::testGet6ByHWAddr() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservations.
-    HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
-    HostPtr host2 = initializeHost6("2001:db8::2", Host::IDENT_HWADDR, false);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::2", Host::IDENT_HWADDR, false);
 
     // Sanity check: make sure the hosts have different HW addresses.
     ASSERT_TRUE(host1->getHWAddress());
     ASSERT_TRUE(host2->getHWAddress());
 
-    compareHwaddrs(host1, host2, false);
+    HostDataSourceUtils::compareHwaddrs(host1, host2, false);
 
     // Try to add both of them to the host data source.
     ASSERT_NO_THROW(hdsptr_->add(host1));
@@ -969,8 +593,8 @@ GenericHostDataSourceTest::testGet6ByHWAddr() {
     // Now let's check if we got what we expected.
     ASSERT_TRUE(from_hds1);
     ASSERT_TRUE(from_hds2);
-    compareHosts(host1, from_hds1);
-    compareHosts(host2, from_hds2);
+    HostDataSourceUtils::compareHosts(host1, from_hds1);
+    HostDataSourceUtils::compareHosts(host2, from_hds2);
 }
 
 void
@@ -979,14 +603,14 @@ GenericHostDataSourceTest::testGet6ByClientId() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservations.
-    HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
-    HostPtr host2 = initializeHost6("2001:db8::2", Host::IDENT_DUID, false);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::2", Host::IDENT_DUID, false);
 
     // Sanity check: make sure the hosts have different HW addresses.
     ASSERT_TRUE(host1->getDuid());
     ASSERT_TRUE(host2->getDuid());
 
-    compareDuids(host1, host2, false);
+    HostDataSourceUtils::compareDuids(host1, host2, false);
 
     // Try to add both of them to the host data source.
     ASSERT_NO_THROW(hdsptr_->add(host1));
@@ -1006,8 +630,8 @@ GenericHostDataSourceTest::testGet6ByClientId() {
     // Now let's check if we got what we expected.
     ASSERT_TRUE(from_hds1);
     ASSERT_TRUE(from_hds2);
-    compareHosts(host1, from_hds1);
-    compareHosts(host2, from_hds2);
+    HostDataSourceUtils::compareHosts(host1, from_hds1);
+    HostDataSourceUtils::compareHosts(host2, from_hds2);
 }
 
 void
@@ -1020,7 +644,7 @@ GenericHostDataSourceTest::testSubnetId6(int subnets, Host::IdentifierType id) {
     for (int i = 0; i < subnets; ++i) {
         // Last boolean value set to false indicates that the same identifier
         // must be used for each generated host.
-        host = initializeHost6(current_address.toText(), id, true, false);
+        host = HostDataSourceUtils::initializeHost6(current_address.toText(), id, true, false);
 
         host->setIPv4SubnetID(i + 1000);
         host->setIPv6SubnetID(i + 1000);
@@ -1068,10 +692,10 @@ GenericHostDataSourceTest::testGetByIPv6(Host::IdentifierType id, bool prefix) {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a couple of hosts...
-    HostPtr host1 = initializeHost6("2001:db8::1", id, prefix);
-    HostPtr host2 = initializeHost6("2001:db8::2", id, prefix);
-    HostPtr host3 = initializeHost6("2001:db8::3", id, prefix);
-    HostPtr host4 = initializeHost6("2001:db8::4", id, prefix);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", id, prefix);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::2", id, prefix);
+    HostPtr host3 = HostDataSourceUtils::initializeHost6("2001:db8::3", id, prefix);
+    HostPtr host4 = HostDataSourceUtils::initializeHost6("2001:db8::4", id, prefix);
 
     // ... and add them to the data source.
     ASSERT_NO_THROW(hdsptr_->add(host1));
@@ -1095,10 +719,10 @@ GenericHostDataSourceTest::testGetByIPv6(Host::IdentifierType id, bool prefix) {
     ASSERT_TRUE(from_hds4);
 
     // Then let's check that what we got seems correct.
-    compareHosts(host1, from_hds1);
-    compareHosts(host2, from_hds2);
-    compareHosts(host3, from_hds3);
-    compareHosts(host4, from_hds4);
+    HostDataSourceUtils::compareHosts(host1, from_hds1);
+    HostDataSourceUtils::compareHosts(host2, from_hds2);
+    HostDataSourceUtils::compareHosts(host3, from_hds3);
+    HostDataSourceUtils::compareHosts(host4, from_hds4);
 
     // Ok, finally let's check that getting by a different address
     // will not work.
@@ -1111,10 +735,10 @@ GenericHostDataSourceTest::testGetBySubnetIPv6() {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a couple of hosts...
-    HostPtr host1 = initializeHost6("2001:db8:1::", Host::IDENT_DUID, true);
-    HostPtr host2 = initializeHost6("2001:db8:2::", Host::IDENT_DUID, true);
-    HostPtr host3 = initializeHost6("2001:db8:3::", Host::IDENT_DUID, true);
-    HostPtr host4 = initializeHost6("2001:db8:4::", Host::IDENT_DUID, true);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8:1::", Host::IDENT_DUID, true);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8:2::", Host::IDENT_DUID, true);
+    HostPtr host3 = HostDataSourceUtils::initializeHost6("2001:db8:3::", Host::IDENT_DUID, true);
+    HostPtr host4 = HostDataSourceUtils::initializeHost6("2001:db8:4::", Host::IDENT_DUID, true);
 
     // ... and add them to the data source.
     ASSERT_NO_THROW(hdsptr_->add(host1));
@@ -1135,10 +759,10 @@ GenericHostDataSourceTest::testGetBySubnetIPv6() {
     ASSERT_TRUE(from_hds4);
 
     // Then let's check that what we got seems correct.
-    compareHosts(host1, from_hds1);
-    compareHosts(host2, from_hds2);
-    compareHosts(host3, from_hds3);
-    compareHosts(host4, from_hds4);
+    HostDataSourceUtils::compareHosts(host1, from_hds1);
+    HostDataSourceUtils::compareHosts(host2, from_hds2);
+    HostDataSourceUtils::compareHosts(host3, from_hds3);
+    HostDataSourceUtils::compareHosts(host4, from_hds4);
 }
 
 void
@@ -1147,7 +771,7 @@ GenericHostDataSourceTest::testAddDuplicate6WithSameDUID() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservations.
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
 
     // Add this reservation once.
     ASSERT_NO_THROW(hdsptr_->add(host));
@@ -1162,7 +786,7 @@ GenericHostDataSourceTest::testAddDuplicate6WithSameHWAddr() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservations.
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, true);
 
     // Add this reservation once.
     ASSERT_NO_THROW(hdsptr_->add(host));
@@ -1177,7 +801,7 @@ GenericHostDataSourceTest::testAddDuplicate4() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservations.
-    HostPtr host = initializeHost4("192.0.2.1", Host::IDENT_DUID);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_DUID);
 
     // Add this reservation once.
     ASSERT_NO_THROW(hdsptr_->add(host));
@@ -1203,7 +827,7 @@ GenericHostDataSourceTest::testAddr6AndPrefix() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host reservations with prefix reservation (prefix = true)
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, true);
 
     // Create IPv6 reservation (for an address) and add it to the host
     IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::2"), 128);
@@ -1221,7 +845,7 @@ GenericHostDataSourceTest::testAddr6AndPrefix() {
     ASSERT_TRUE(from_hds);
 
     // Check if reservations are the same
-    compareReservations6(host->getIPv6Reservations(),
+    HostDataSourceUtils::compareReservations6(host->getIPv6Reservations(),
                          from_hds->getIPv6Reservations());
 }
 
@@ -1231,7 +855,7 @@ GenericHostDataSourceTest::testMultipleReservations() {
     ASSERT_TRUE(hdsptr_);
     uint8_t len = 128;
 
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
 
     // Add some reservations
     IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
@@ -1252,7 +876,7 @@ GenericHostDataSourceTest::testMultipleReservations() {
     ASSERT_TRUE(from_hds);
 
     // Check if hosts are the same
-    compareHosts(host, from_hds);
+    HostDataSourceUtils::compareHosts(host, from_hds);
 }
 
 void
@@ -1261,8 +885,8 @@ GenericHostDataSourceTest::testMultipleReservationsDifferentOrder() {
     ASSERT_TRUE(hdsptr_);
     uint8_t len = 128;
 
-    HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
-    HostPtr host2 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
 
     // Add some reservations
     IPv6Resrv resv1(IPv6Resrv::TYPE_NA, IOAddress("2001:db8::6"), len);
@@ -1281,13 +905,13 @@ GenericHostDataSourceTest::testMultipleReservationsDifferentOrder() {
     host2->addReservation(resv1);
 
     // Check if reservations are the same
-    compareReservations6(host1->getIPv6Reservations(),
-                         host2->getIPv6Reservations());
+    HostDataSourceUtils::compareReservations6(host1->getIPv6Reservations(),
+                                              host2->getIPv6Reservations());
 }
 
 void GenericHostDataSourceTest::testOptionsReservations4(const bool formatted,
                                                          ConstElementPtr user_context) {
-    HostPtr host = initializeHost4("192.0.2.5", Host::IDENT_HWADDR);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.5", Host::IDENT_HWADDR);
     // Add a bunch of DHCPv4 and DHCPv6 options for the host.
     ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP4_ONLY, user_context));
     // Insert host and the options into respective tables.
@@ -1299,23 +923,23 @@ void GenericHostDataSourceTest::testOptionsReservations4(const bool formatted,
     ConstHostCollection hosts_by_addr =
         hdsptr_->getAll4(host->getIPv4Reservation());
     ASSERT_EQ(1, hosts_by_addr.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_addr.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_addr.begin()));
 
     // get4(subnet_id, identifier_type, identifier, identifier_size)
     ConstHostPtr host_by_id =
         hdsptr_->get4(subnet_id, host->getIdentifierType(),
                       &host->getIdentifier()[0], host->getIdentifier().size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_id));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
 
     // get4(subnet_id, address)
     ConstHostPtr host_by_addr =
         hdsptr_->get4(subnet_id, IOAddress("192.0.2.5"));
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_addr));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_addr));
 }
 
 void GenericHostDataSourceTest::testOptionsReservations6(const bool formatted,
                                                          ConstElementPtr user_context) {
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
     // Add a bunch of DHCPv4 and DHCPv6 options for the host.
     ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP6_ONLY, user_context));
     // Insert host, options and IPv6 reservations into respective tables.
@@ -1327,16 +951,16 @@ void GenericHostDataSourceTest::testOptionsReservations6(const bool formatted,
     ConstHostPtr host_by_id =
         hdsptr_->get6(subnet_id, host->getIdentifierType(),
                       &host->getIdentifier()[0], host->getIdentifier().size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_id));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
 
     // get6(address, prefix_len)
     ConstHostPtr host_by_addr = hdsptr_->get6(IOAddress("2001:db8::1"), 128);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, host_by_addr));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_addr));
 }
 
 void
 GenericHostDataSourceTest::testOptionsReservations46(const bool formatted) {
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
 
     // Add a bunch of DHCPv4 and DHCPv6 options for the host.
     ASSERT_NO_THROW(addTestOptions(host, formatted, DHCP4_AND_DHCP6));
@@ -1348,7 +972,7 @@ GenericHostDataSourceTest::testOptionsReservations46(const bool formatted) {
         hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
                         host->getIdentifier().size());
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 }
 
 void
@@ -1356,7 +980,7 @@ GenericHostDataSourceTest::testMultipleClientClasses4() {
     ASSERT_TRUE(hdsptr_);
 
     // Create the Host object.
-    HostPtr host = initializeHost4("192.0.2.5", Host::IDENT_HWADDR);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.5", Host::IDENT_HWADDR);
 
     // Add v4 classes to the host.
     for (int i = 0; i < 4; ++i) {
@@ -1375,7 +999,7 @@ GenericHostDataSourceTest::testMultipleClientClasses4() {
     // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
     ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // Fetch the host via:
     // getAll(const Host::IdentifierType, const uint8_t* identifier_begin,
@@ -1384,20 +1008,20 @@ GenericHostDataSourceTest::testMultipleClientClasses4() {
         hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
                         host->getIdentifier().size());
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // Fetch the host via
     // getAll4(const asiolink::IOAddress& address) const;
     hosts_by_id = hdsptr_->getAll4(IOAddress("192.0.2.5"));
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // Fetch the host via
     // get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
     //     const DuidPtr& duid = DuidPtr()) const;
     ConstHostPtr from_hds = hdsptr_->get4(subnet_id, host->getHWAddress());
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 
     // Fetch the host via
     // get4(const SubnetID& subnet_id, const Host::IdentifierType&
@@ -1407,13 +1031,13 @@ GenericHostDataSourceTest::testMultipleClientClasses4() {
         hdsptr_->get4(subnet_id, host->getIdentifierType(),
                       &host->getIdentifier()[0], host->getIdentifier().size());
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 
     // Fetch the host via:
     // get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
     from_hds = hdsptr_->get4(subnet_id, IOAddress("192.0.2.5"));
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 }
 
 void
@@ -1421,7 +1045,7 @@ GenericHostDataSourceTest::testMultipleClientClasses6() {
     ASSERT_TRUE(hdsptr_);
 
     // Create the Host object.
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
 
     // Add v6 classes to the host.
     for (int i = 0; i < 4; ++i) {
@@ -1440,7 +1064,7 @@ GenericHostDataSourceTest::testMultipleClientClasses6() {
     // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
     ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // getAll(const Host::IdentifierType& identifier_type,
     //        const uint8_t* identifier_begin,
@@ -1449,14 +1073,14 @@ GenericHostDataSourceTest::testMultipleClientClasses6() {
         hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
                         host->getIdentifier().size());
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // get6(const SubnetID& subnet_id, const DuidPtr& duid,
     //      const HWAddrPtr& hwaddr = HWAddrPtr()) const;
     ConstHostPtr from_hds =
         hdsptr_->get6(subnet_id, DuidPtr(), host->getHWAddress());
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 
     // Fetch the host via:
     // get6(const SubnetID& subnet_id, const Host::IdentifierType&
@@ -1466,13 +1090,13 @@ GenericHostDataSourceTest::testMultipleClientClasses6() {
         hdsptr_->get6(subnet_id, Host::IDENT_HWADDR, &host->getIdentifier()[0],
                       host->getIdentifier().size());
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 
     // Fetch the host via:
     // get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
     from_hds = hdsptr_->get6(IOAddress("2001:db8::1"), 128);
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 }
 
 void
@@ -1483,7 +1107,7 @@ GenericHostDataSourceTest::testMultipleClientClassesBoth() {
     ASSERT_TRUE(hdsptr_);
 
     // Create the Host object.
-    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
 
     // Add v4 classes to the host.
     for (int i = 0; i < 4; ++i) {
@@ -1512,7 +1136,7 @@ GenericHostDataSourceTest::testMultipleClientClassesBoth() {
     ASSERT_TRUE(from_hds);
 
     // Verify they match.
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 }
 
 void
@@ -1520,7 +1144,7 @@ GenericHostDataSourceTest::testMessageFields4() {
     ASSERT_TRUE(hdsptr_);
 
     // Create the Host object.
-    HostPtr host = initializeHost4("192.0.2.5", Host::IDENT_HWADDR);
+    HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.5", Host::IDENT_HWADDR);
     // And assign values for DHCPv4 message fields.
     ASSERT_NO_THROW({
         host->setNextServer(IOAddress("10.1.1.1"));
@@ -1538,7 +1162,7 @@ GenericHostDataSourceTest::testMessageFields4() {
     // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
     ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // Fetch the host via:
     // getAll(const Host::IdentifierType, const uint8_t* identifier_begin,
@@ -1547,20 +1171,20 @@ GenericHostDataSourceTest::testMessageFields4() {
         hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
                         host->getIdentifier().size());
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // Fetch the host via
     // getAll4(const asiolink::IOAddress& address) const;
     hosts_by_id = hdsptr_->getAll4(IOAddress("192.0.2.5"));
     ASSERT_EQ(1, hosts_by_id.size());
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, *hosts_by_id.begin()));
 
     // Fetch the host via
     // get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
     //     const DuidPtr& duid = DuidPtr()) const;
     ConstHostPtr from_hds = hdsptr_->get4(subnet_id, host->getHWAddress());
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 
     // Fetch the host via
     // get4(const SubnetID& subnet_id, const Host::IdentifierType&
@@ -1570,13 +1194,13 @@ GenericHostDataSourceTest::testMessageFields4() {
         hdsptr_->get4(subnet_id, host->getIdentifierType(),
                       &host->getIdentifier()[0], host->getIdentifier().size());
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 
     // Fetch the host via:
     // get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
     from_hds = hdsptr_->get4(subnet_id, IOAddress("192.0.2.5"));
     ASSERT_TRUE(from_hds);
-    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, from_hds));
 }
 
 void
@@ -1599,11 +1223,11 @@ GenericHostDataSourceTest::stressTest(unsigned int nOfHosts /* = 0xfffdU */) {
         ss >> n_host;
 
         const std::string prefix = std::string("2001:db8::") + n_host;
-        hosts.push_back(initializeHost6(prefix, Host::IDENT_HWADDR, false));
+        hosts.push_back(HostDataSourceUtils::initializeHost6(prefix, Host::IDENT_HWADDR, false));
         IPv6ResrvRange range = hosts.back()->getIPv6Reservations();
         ASSERT_EQ(1, std::distance(range.first, range.second));
-        EXPECT_TRUE(reservationExists(
-            IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress(prefix)), range));
+        EXPECT_TRUE(HostDataSourceUtils::reservationExists
+                    (IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress(prefix)), range));
     }
     const size_t hosts_size = hosts.size();
 
@@ -1638,7 +1262,7 @@ GenericHostDataSourceTest::stressTest(unsigned int nOfHosts /* = 0xfffdU */) {
         ConstHostPtr from_hds =
             hdsptr_->get6(range.first->second.getPrefix(), 128);
         ASSERT_TRUE(from_hds);
-        compareHosts(*it, from_hds);
+        HostDataSourceUtils::compareHosts(*it, from_hds);
     }
     clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
     s = static_cast<double>(end.tv_sec - start.tv_sec) +
@@ -1654,7 +1278,7 @@ void GenericHostDataSourceTest::testDeleteByAddr4() {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a v4 host...
-    HostPtr host1 = initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
+    HostPtr host1 = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
     SubnetID subnet1 = host1->getIPv4SubnetID();
 
     // ... and add it to the data source.
@@ -1681,7 +1305,7 @@ void GenericHostDataSourceTest::testDeleteById4() {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a v4 host...
-    HostPtr host1 = initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
+    HostPtr host1 = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
     SubnetID subnet1 = host1->getIPv4SubnetID();
 
     // ... and add it to the data source.
@@ -1718,7 +1342,7 @@ void GenericHostDataSourceTest::testDeleteById4Options() {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a v4 host...
-    HostPtr host1 = initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
+    HostPtr host1 = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
     // Add a bunch of DHCPv4 and DHCPv6 options for the host.
     ASSERT_NO_THROW(addTestOptions(host1, true, DHCP4_ONLY));
     // Insert host and the options into respective tables.
@@ -1763,7 +1387,7 @@ void GenericHostDataSourceTest::testDeleteById6() {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a v6 host...
-    HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
     SubnetID subnet1 = host1->getIPv6SubnetID();
 
     // ... and add it to the data source.
@@ -1798,7 +1422,7 @@ void GenericHostDataSourceTest::testDeleteById6Options() {
     ASSERT_TRUE(hdsptr_);
 
     // Let's create a v6 host...
-    HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
     SubnetID subnet1 = host1->getIPv6SubnetID();
     ASSERT_NO_THROW(addTestOptions(host1, true, DHCP6_ONLY));
 
@@ -1847,7 +1471,7 @@ GenericHostDataSourceTest::testMultipleHostsNoAddress4() {
     ASSERT_TRUE(hdsptr_);
 
     // Create a host with zero IPv4 address.
-    HostPtr host1 = initializeHost4("0.0.0.0", Host::IDENT_HWADDR);
+    HostPtr host1 = HostDataSourceUtils::initializeHost4("0.0.0.0", Host::IDENT_HWADDR);
     host1->setIPv4SubnetID(1);
     host1->setIPv6SubnetID(0);
     // Add the host to the database.
@@ -1860,7 +1484,7 @@ GenericHostDataSourceTest::testMultipleHostsNoAddress4() {
     // Create another host with zero IPv4 address. Adding this host to the
     // database should be successful because zero addresses are not counted
     // in the unique index.
-    HostPtr host2 = initializeHost4("0.0.0.0", Host::IDENT_HWADDR);
+    HostPtr host2 = HostDataSourceUtils::initializeHost4("0.0.0.0", Host::IDENT_HWADDR);
     host2->setIPv4SubnetID(1);
     host2->setIPv6SubnetID(0);
     ASSERT_NO_THROW(hdsptr_->add(host2));
@@ -1872,7 +1496,7 @@ GenericHostDataSourceTest::testMultipleHosts6() {
     ASSERT_TRUE(hdsptr_);
 
     // Create first host.
-    HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+    HostPtr host1 = HostDataSourceUtils::initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
     host1->setIPv4SubnetID(0);
     host1->setIPv6SubnetID(1);
     // Add the host to the database.
@@ -1882,7 +1506,7 @@ GenericHostDataSourceTest::testMultipleHosts6() {
     // duplication.
     ASSERT_THROW(hdsptr_->add(host1), DuplicateEntry);
 
-    HostPtr host2 = initializeHost6("2001:db8::2", Host::IDENT_DUID, false);
+    HostPtr host2 = HostDataSourceUtils::initializeHost6("2001:db8::2", Host::IDENT_DUID, false);
     host2->setIPv4SubnetID(0);
     host2->setIPv6SubnetID(1);
     // Add the host to the database.
index 81338b47f04f00b985a821bbf1f9a23f261b7d94..9a507cdc1b6f887fc00dc80bd92a0fb4aed20a49 100644 (file)
@@ -51,82 +51,6 @@ public:
     /// @brief Virtual destructor.
     virtual ~GenericHostDataSourceTest();
 
-    /// @brief Creates a host reservation for specified IPv4 address.
-    ///
-    /// @param address IPv4 address to be set
-    /// @param id Identifier type.
-    ///
-    /// @return generated Host object
-    HostPtr initializeHost4(const std::string& address,
-                            const Host::IdentifierType& id);
-
-    /// @brief Creates a host reservation for specified IPv6 address.
-    ///
-    /// @param address IPv6 address to be reserved
-    /// @param id type of identifier (IDENT_DUID or IDENT_HWADDR are supported)
-    /// @param prefix reservation type (true = prefix, false = address)
-    /// @param new_identifier Boolean value indicating if new host
-    /// identifier should be generated or the same as previously.
-    ///
-    /// @return generated Host object
-    HostPtr initializeHost6(std::string address, Host::IdentifierType id,
-                            bool prefix, bool new_identifier = true);
-
-    /// @brief Generates a hardware address in text version.
-    ///
-    /// @param increase A boolean value indicating if new address (increased)
-    /// must be generated or the same address as previously.
-    /// @return HW address in textual form acceptable by Host constructor
-    std::vector<uint8_t> generateHWAddr(const bool new_identifier = true);
-
-    /// @brief Generates a host identifier in a textual form..
-    ///
-    /// @param increase A boolean value indicating if new identifier (increased)
-    /// must be generated or the same identifier as previously.
-    /// @return Identifier in textual form acceptable by Host constructor
-    std::vector<uint8_t> generateIdentifier(const bool new_identifier = true);
-
-    /// @brief Checks if the reservation is in the range of reservations.
-    ///
-    /// @param resrv Reservation to be searched for.
-    /// @param range Range of reservations returned by the @c Host object
-    /// in which the reservation will be searched
-    bool reservationExists(const IPv6Resrv& resrv, const IPv6ResrvRange& range);
-
-    /// @brief Compares hardware addresses of the two hosts.
-    ///
-    /// This method compares two hardware address and uses gtest
-    /// macros to signal unexpected (mismatch if expect_match is true;
-    /// match if expect_match is false) values.
-    ///
-    /// @param host1 first host to be compared
-    /// @param host2 second host to be compared
-    /// @param expect_match true = HW addresses expected to be the same,
-    ///                     false = HW addresses expected to be different
-    void compareHwaddrs(const ConstHostPtr& host1, const ConstHostPtr& host2,
-                        bool expect_match);
-
-    /// @brief Compares DUIDs of the two hosts.
-    ///
-    /// This method compares two DUIDs (client-ids) and uses gtest
-    /// macros to signal unexpected (mismatch if expect_match is true;
-    /// match if expect_match is false) values.
-    ///
-    /// @param host1 first host to be compared
-    /// @param host2 second host to be compared
-    /// @param expect_match true = DUIDs expected to be the same,
-    ///                     false = DUIDs expected to be different
-    void compareDuids(const ConstHostPtr& host1, const ConstHostPtr& host2,
-                      bool expect_match);
-
-    /// @brief Compares two hosts
-    ///
-    /// This method uses gtest macros to signal errors.
-    ///
-    /// @param host1 first host to compare
-    /// @param host2 second host to compare
-    void compareHosts(const ConstHostPtr& host1, const ConstHostPtr& host2);
-
     /// @brief Used to sort a host collection by IPv4 subnet id.
     /// @param host1 first host to be compared
     /// @param host2 second host to be compared
@@ -139,32 +63,6 @@ public:
     static bool compareHostsForSort6(const ConstHostPtr& host1,
                                      const ConstHostPtr& host2);
 
-    /// @brief Compares two IPv6 reservation lists.
-    ///
-    /// This method uses gtest macros to signal errors.
-    ///
-    /// @param resv1 first IPv6 reservations list
-    /// @param resv2 second IPv6 reservations list
-    void compareReservations6(IPv6ResrvRange resv1, IPv6ResrvRange resv2);
-
-    /// @brief Compares two client classes
-    ///
-    /// This method uses gtest macros to signal errors.
-    ///
-    /// @param classes1 first list of client classes
-    /// @param classes2 second list of client classes
-    void compareClientClasses(const ClientClasses& classes1,
-                              const ClientClasses& classes2);
-
-    /// @brief Compares options within two configurations.
-    ///
-    /// This method uses gtest macros to signal errors.
-    ///
-    /// @param cfg1 First configuration.
-    /// @param cfg2 Second configuration.
-    void compareOptions(const ConstCfgOptionPtr& cfg1,
-                        const ConstCfgOptionPtr& cfg2) const;
-
     /// @brief Creates an option descriptor holding an empty option.
     ///
     /// @param universe V4 or V6.
index 63a81b45393eb4f308ef01a596a8a32f99aad3dc..e40d965c07cf2f7012aab9ed8c34ed6130938731 100644 (file)
@@ -14,6 +14,7 @@
 #include <dhcpsrv/mysql_host_data_source.h>
 #include <dhcpsrv/tests/generic_host_data_source_unittest.h>
 #include <dhcpsrv/testutils/mysql_schema.h>
+#include <dhcpsrv/testutils/host_data_source_utils.h>
 #include <dhcpsrv/host_data_source_factory.h>
 
 #include <gtest/gtest.h>
@@ -560,7 +561,7 @@ TEST_F(MySqlHostDataSourceTest, testAddRollback) {
     ASSERT_EQ(0, status) << mysql_error(conn.mysql_);
 
     // Create a host with a reservation.
-    HostPtr host = initializeHost6("2001:db8:1::1", Host::IDENT_HWADDR, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8:1::1", Host::IDENT_HWADDR, false);
     // Let's assign some DHCPv4 subnet to the host, because we will use the
     // DHCPv4 subnet to try to retrieve the host after failed insertion.
     host->setIPv4SubnetID(SubnetID(4));
index 269fe77e954c67706be57384b5a2d5c0933fbcf9..f575f5f50cc6ab0bbd9096068c6f4d19831fe426 100644 (file)
@@ -14,6 +14,7 @@
 #include <dhcpsrv/pgsql_host_data_source.h>
 #include <dhcpsrv/tests/generic_host_data_source_unittest.h>
 #include <dhcpsrv/testutils/pgsql_schema.h>
+#include <dhcpsrv/testutils/host_data_source_utils.h>
 #include <dhcpsrv/host_data_source_factory.h>
 
 #include <gtest/gtest.h>
@@ -517,7 +518,7 @@ TEST_F(PgSqlHostDataSourceTest, testAddRollback) {
                  << " drop command failed :" << PQerrorMessage(conn);
 
     // Create a host with a reservation.
-    HostPtr host = initializeHost6("2001:db8:1::1", Host::IDENT_HWADDR, false);
+    HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8:1::1", Host::IDENT_HWADDR, false);
     // Let's assign some DHCPv4 subnet to the host, because we will use the
     // DHCPv4 subnet to try to retrieve the host after failed insertion.
     host->setIPv4SubnetID(SubnetID(4));
index a6b16b8d43902baf16a7f7275930b3a2793514d8..1ad1df791f9893973de49be006b9cab7c17037d0 100644 (file)
@@ -14,12 +14,10 @@ noinst_LTLIBRARIES = libdhcpsrvtest.la
 
 libdhcpsrvtest_la_SOURCES  = config_result_check.cc config_result_check.h
 libdhcpsrvtest_la_SOURCES += dhcp4o6_test_ipc.cc dhcp4o6_test_ipc.h
-
+libdhcpsrvtest_la_SOURCES += host_data_source_utils.cc host_data_source_utils.h
 libdhcpsrvtest_la_SOURCES += schema.cc schema.h
-
 libdhcpsrvtest_la_SOURCES += lease_file_io.cc lease_file_io.h
 
-
 if HAVE_MYSQL
 libdhcpsrvtest_la_SOURCES += mysql_schema.cc mysql_schema.h
 endif
diff --git a/src/lib/dhcpsrv/testutils/host_data_source_utils.cc b/src/lib/dhcpsrv/testutils/host_data_source_utils.cc
new file mode 100644 (file)
index 0000000..8ad892e
--- /dev/null
@@ -0,0 +1,400 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <dhcpsrv/testutils/host_data_source_utils.h>
+#include <asiolink/io_address.h>
+#include <boost/foreach.hpp>
+#include <cc/data.h>
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::asiolink;
+using namespace isc::util;
+
+namespace isc {
+namespace dhcp {
+namespace test {
+
+std::vector<uint8_t>
+HostDataSourceUtils::generateHWAddr(const bool new_identifier) {
+    // Let's use something that is easily printable. That's convenient
+    // if you need to enter MySQL queries by hand.
+    static uint8_t hwaddr[] = {65, 66, 67, 68, 69, 70};
+
+    if (new_identifier) {
+        // Increase the address for the next time we use it.
+        // This is primitive, but will work for 65k unique
+        // addresses.
+        hwaddr[sizeof(hwaddr) - 1]++;
+        if (hwaddr[sizeof(hwaddr) - 1] == 0) {
+            hwaddr[sizeof(hwaddr) - 2]++;
+        }
+    }
+    return (std::vector<uint8_t>(hwaddr, hwaddr + sizeof(hwaddr)));
+}
+
+std::vector<uint8_t>
+HostDataSourceUtils::generateIdentifier(const bool new_identifier) {
+    // Let's use something that is easily printable. That's convenient
+    // if you need to enter MySQL queries by hand.
+    static uint8_t ident[] = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74};
+
+    if (new_identifier) {
+        // Increase the identifier for the next time we use it.
+        // This is primitive, but will work for 65k unique identifiers.
+        ident[sizeof(ident) - 1]++;
+        if (ident[sizeof(ident) - 1] == 0) {
+            ident[sizeof(ident) - 2]++;
+        }
+    }
+    return (std::vector<uint8_t>(ident, ident + sizeof(ident)));
+}
+
+HostPtr
+HostDataSourceUtils::initializeHost4(const std::string& address,
+                                           const Host::IdentifierType& id) {
+    std::vector<uint8_t> ident;
+    if (id == Host::IDENT_HWADDR) {
+        ident = generateHWAddr();
+    } else {
+        ident = generateIdentifier();
+    }
+
+    // Let's create ever increasing subnet-ids. Let's keep those different,
+    // so subnet4 != subnet6. Useful for catching cases if the code confuses
+    // subnet4 with subnet6.
+    static SubnetID subnet4 = 0;
+    static SubnetID subnet6 = 100;
+    ++subnet4;
+    ++subnet6;
+
+    IOAddress addr(address);
+    HostPtr host(new Host(&ident[0], ident.size(), id, subnet4, subnet6, addr));
+
+    return (host);
+}
+
+HostPtr
+HostDataSourceUtils::initializeHost6(std::string address,
+                                           Host::IdentifierType identifier,
+                                           bool prefix,
+                                           bool new_identifier) {
+    std::vector<uint8_t> ident;
+    switch (identifier) {
+    case Host::IDENT_HWADDR:
+        ident = generateHWAddr(new_identifier);
+        break;
+    case Host::IDENT_DUID:
+        ident = generateIdentifier(new_identifier);
+        break;
+    default:
+        ADD_FAILURE() << "Unknown IdType: " << identifier;
+        return HostPtr();
+    }
+
+    // Let's create ever increasing subnet-ids. Let's keep those different,
+    // so subnet4 != subnet6. Useful for catching cases if the code confuses
+    // subnet4 with subnet6.
+    static SubnetID subnet4 = 0;
+    static SubnetID subnet6 = 100;
+    subnet4++;
+    subnet6++;
+
+    HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6,
+                          IOAddress("0.0.0.0")));
+
+    if (!prefix) {
+        // Create IPv6 reservation (for an address)
+        IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), 128);
+        host->addReservation(resv);
+    } else {
+        // Create IPv6 reservation for a /64 prefix
+        IPv6Resrv resv(IPv6Resrv::TYPE_PD, IOAddress(address), 64);
+        host->addReservation(resv);
+    }
+    return (host);
+}
+
+bool
+HostDataSourceUtils::reservationExists(const IPv6Resrv& resrv,
+                                             const IPv6ResrvRange& range) {
+    for (IPv6ResrvIterator it = range.first; it != range.second; ++it) {
+        if (resrv == it->second) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void
+HostDataSourceUtils::compareHwaddrs(const ConstHostPtr& host1,
+                                          const ConstHostPtr& host2,
+                                          bool expect_match) {
+    ASSERT_TRUE(host1);
+    ASSERT_TRUE(host2);
+
+    // Compare if both have or have not HWaddress set.
+    if ((host1->getHWAddress() && !host2->getHWAddress()) ||
+        (!host1->getHWAddress() && host2->getHWAddress())) {
+        // One host has hardware address set while the other has not.
+        // Let's see if it's a problem.
+        if (expect_match) {
+            ADD_FAILURE() << "Host comparison failed: host1 hwaddress="
+                          << host1->getHWAddress()
+                          << ", host2 hwaddress=" << host2->getHWAddress();
+        }
+        return;
+    }
+
+    // Now we know that either both or neither have hw address set.
+    // If host1 has it, we can proceed to value comparison.
+    if (host1->getHWAddress()) {
+        if (expect_match) {
+            // Compare the actual address if they match.
+            EXPECT_TRUE(*host1->getHWAddress() == *host2->getHWAddress());
+        } else {
+            EXPECT_FALSE(*host1->getHWAddress() == *host2->getHWAddress());
+        }
+        if (*host1->getHWAddress() != *host2->getHWAddress()) {
+            cout << host1->getHWAddress()->toText(true) << endl;
+            cout << host2->getHWAddress()->toText(true) << endl;
+        }
+    }
+}
+
+void
+HostDataSourceUtils::compareDuids(const ConstHostPtr& host1,
+                                        const ConstHostPtr& host2,
+                                        bool expect_match) {
+    ASSERT_TRUE(host1);
+    ASSERT_TRUE(host2);
+
+    // compare if both have or have not DUID set
+    if ((host1->getDuid() && !host2->getDuid()) ||
+        (!host1->getDuid() && host2->getDuid())) {
+        // One host has a DUID and the other doesn't.
+        // Let's see if it's a problem.
+        if (expect_match) {
+            ADD_FAILURE() << "DUID comparison failed: host1 duid="
+                          << host1->getDuid()
+                          << ", host2 duid=" << host2->getDuid();
+        }
+        return;
+    }
+
+    // Now we know that either both or neither have DUID set.
+    // If host1 has it, we can proceed to value comparison.
+    if (host1->getDuid()) {
+        if (expect_match) {
+            EXPECT_TRUE(*host1->getDuid() == *host2->getDuid());
+        } else {
+            EXPECT_FALSE(*host1->getDuid() == *host2->getDuid());
+        }
+        if (*host1->getDuid() != *host2->getDuid()) {
+            cout << host1->getDuid()->toText() << endl;
+            cout << host2->getDuid()->toText() << endl;
+        }
+    }
+}
+
+void
+HostDataSourceUtils::compareHosts(const ConstHostPtr& host1,
+                                        const ConstHostPtr& host2) {
+    // Let's compare HW addresses and expect match.
+    compareHwaddrs(host1, host2, true);
+
+    // Now compare DUIDs
+    compareDuids(host1, host2, true);
+
+    // Now check that the identifiers returned as vectors are the same
+    EXPECT_EQ(host1->getIdentifierType(), host2->getIdentifierType());
+    EXPECT_TRUE(host1->getIdentifier() == host2->getIdentifier());
+
+    // Check host parameters
+    EXPECT_EQ(host1->getIPv4SubnetID(), host2->getIPv4SubnetID());
+    EXPECT_EQ(host1->getIPv6SubnetID(), host2->getIPv6SubnetID());
+    EXPECT_EQ(host1->getIPv4Reservation(), host2->getIPv4Reservation());
+    EXPECT_EQ(host1->getHostname(), host2->getHostname());
+    EXPECT_EQ(host1->getNextServer(), host2->getNextServer());
+    EXPECT_EQ(host1->getServerHostname(), host2->getServerHostname());
+    EXPECT_EQ(host1->getBootFileName(), host2->getBootFileName());
+    ConstElementPtr ctx1 = host1->getContext();
+    ConstElementPtr ctx2 = host2->getContext();
+    if (ctx1) {
+        EXPECT_TRUE(ctx2);
+        if (ctx2) {
+            EXPECT_EQ(*ctx1, *ctx2);
+        }
+    } else {
+        EXPECT_FALSE(ctx2);
+    }
+
+    // Compare IPv6 reservations
+    compareReservations6(host1->getIPv6Reservations(),
+                         host2->getIPv6Reservations());
+
+    // Compare client classification details
+    compareClientClasses(host1->getClientClasses4(),
+                         host2->getClientClasses4());
+
+    compareClientClasses(host1->getClientClasses6(),
+                         host2->getClientClasses6());
+
+    // Compare DHCPv4 and DHCPv6 options.
+    compareOptions(host1->getCfgOption4(), host2->getCfgOption4());
+    compareOptions(host1->getCfgOption6(), host2->getCfgOption6());
+}
+
+void
+HostDataSourceUtils::compareReservations6(IPv6ResrvRange resrv1,
+                                                IPv6ResrvRange resrv2) {
+    // Compare number of reservations for both hosts
+    if (std::distance(resrv1.first, resrv1.second) !=
+        std::distance(resrv2.first, resrv2.second)) {
+        ADD_FAILURE() << "Reservation comparison failed, "
+                         "hosts got different number of reservations.";
+        return;
+    }
+
+    // Iterate over the range of reservations to find a match in the
+    // reference range.
+    for (IPv6ResrvIterator r1 = resrv1.first; r1 != resrv1.second; ++r1) {
+        IPv6ResrvIterator r2 = resrv2.first;
+        for (; r2 != resrv2.second; ++r2) {
+            // IPv6Resrv object implements equality operator.
+            if (r1->second == r2->second) {
+                break;
+            }
+        }
+        // If r2 iterator reached the end of the range it means that there
+        // is no match.
+        if (r2 == resrv2.second) {
+            ADD_FAILURE() << "No match found for reservation: "
+                          << resrv1.first->second.getPrefix().toText();
+        }
+    }
+
+    if (std::distance(resrv1.first, resrv1.second) > 0) {
+        for (; resrv1.first != resrv1.second; resrv1.first++) {
+            IPv6ResrvIterator iter = resrv2.first;
+            while (iter != resrv2.second) {
+                if ((resrv1.first->second.getType() ==
+                     iter->second.getType()) &&
+                    (resrv1.first->second.getPrefixLen() ==
+                     iter->second.getPrefixLen()) &&
+                    (resrv1.first->second.getPrefix() ==
+                     iter->second.getPrefix())) {
+                    break;
+                }
+                iter++;
+                if (iter == resrv2.second) {
+                    ADD_FAILURE() << "Reservation comparison failed, "
+                                     "no match for reservation: "
+                                  << resrv1.first->second.getPrefix().toText();
+                }
+            }
+        }
+    }
+}
+
+void
+HostDataSourceUtils::compareClientClasses(const ClientClasses& classes1,
+                                                const ClientClasses& classes2) {
+    EXPECT_TRUE(std::equal(classes1.begin(), classes1.end(), classes2.begin()));
+}
+
+void
+HostDataSourceUtils::compareOptions(const ConstCfgOptionPtr& cfg1,
+                                          const ConstCfgOptionPtr& cfg2) {
+    ASSERT_TRUE(cfg1);
+    ASSERT_TRUE(cfg2);
+
+    // Combine option space names with vendor space names in a single list.
+    std::list<std::string> option_spaces = cfg2->getOptionSpaceNames();
+    std::list<std::string> vendor_spaces = cfg2->getVendorIdsSpaceNames();
+    option_spaces.insert(option_spaces.end(), vendor_spaces.begin(),
+                         vendor_spaces.end());
+
+    // Make sure that the number of option spaces is equal in both
+    // configurations.
+    EXPECT_EQ(option_spaces.size(), cfg1->getOptionSpaceNames().size());
+    EXPECT_EQ(vendor_spaces.size(), cfg1->getVendorIdsSpaceNames().size());
+
+    // Iterate over all option spaces existing in cfg2.
+    BOOST_FOREACH (std::string space, option_spaces) {
+        // Retrieve options belonging to the current option space.
+        OptionContainerPtr options1 = cfg1->getAll(space);
+        OptionContainerPtr options2 = cfg2->getAll(space);
+        ASSERT_TRUE(options1) << "failed for option space " << space;
+        ASSERT_TRUE(options2) << "failed for option space " << space;
+
+        // If number of options doesn't match, the test fails.
+        ASSERT_EQ(options1->size(), options2->size())
+            << "failed for option space " << space;
+
+        // Iterate over all options within this option space.
+        BOOST_FOREACH (OptionDescriptor desc1, *options1) {
+            OptionDescriptor desc2 = cfg2->get(space, desc1.option_->getType());
+            // Compare persistent flag.
+            EXPECT_EQ(desc1.persistent_, desc2.persistent_)
+                << "failed for option " << space << "."
+                << desc1.option_->getType();
+            // Compare formatted value.
+            EXPECT_EQ(desc1.formatted_value_, desc2.formatted_value_)
+                << "failed for option " << space << "."
+                << desc1.option_->getType();
+
+            // Compare user context.
+            ConstElementPtr ctx1 = desc1.getContext();
+            ConstElementPtr ctx2 = desc2.getContext();
+            if (ctx1) {
+                EXPECT_TRUE(ctx2);
+                if (ctx2) {
+                    EXPECT_EQ(*ctx1, *ctx2)
+                        << "failed for option " << space << "." << desc1.option_->getType();
+                }
+            } else {
+                EXPECT_FALSE(ctx2);
+            }
+
+            // Retrieve options.
+            Option* option1 = desc1.option_.get();
+            Option* option2 = desc2.option_.get();
+
+            // Options must be represented by the same C++ class derived from
+            // the Option class.
+            EXPECT_TRUE(typeid(*option1) == typeid(*option2))
+                << "Compared DHCP options, having option code "
+                << desc1.option_->getType() << " and belonging to the " << space
+                << " option space, are represented "
+                   "by different C++ classes: "
+                << typeid(*option1).name() << " vs " << typeid(*option2).name();
+
+            // Because we use different C++ classes to represent different
+            // options, the simplest way to make sure that the options are
+            // equal is to simply compare them in wire format.
+            OutputBuffer buf1(option1->len());
+            ASSERT_NO_THROW(option1->pack(buf1));
+            OutputBuffer buf2(option2->len());
+            ASSERT_NO_THROW(option2->pack(buf2));
+
+            ASSERT_EQ(buf1.getLength(), buf2.getLength())
+                << "failed for option " << space << "."
+                << desc1.option_->getType();
+            EXPECT_EQ(0,
+                      memcmp(buf1.getData(), buf2.getData(), buf1.getLength()))
+                << "failed for option " << space << "."
+                << desc1.option_->getType();
+        }
+    }
+}
+
+
+}
+}
+}
+
diff --git a/src/lib/dhcpsrv/testutils/host_data_source_utils.h b/src/lib/dhcpsrv/testutils/host_data_source_utils.h
new file mode 100644 (file)
index 0000000..f46906f
--- /dev/null
@@ -0,0 +1,130 @@
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef HOST_DATA_SOURCE_UTILS_H
+#define HOST_DATA_SOURCE_UTILS_H
+
+#include <config.h>
+#include <dhcpsrv/host.h>
+#include <vector>
+
+namespace isc {
+namespace dhcp {
+namespace test {
+
+/// @brief A helper class for manipulating hosts
+///
+/// Intended to be used in tests and benchmarks.
+class HostDataSourceUtils {
+public:
+        /// @brief Creates a host reservation for specified IPv4 address.
+    ///
+    /// @param address IPv4 address to be set
+    /// @param id Identifier type.
+    ///
+    /// @return generated Host object
+    static isc::dhcp::HostPtr initializeHost4(const std::string& address,
+                                       const Host::IdentifierType& id);
+
+    /// @brief Creates a host reservation for specified IPv6 address.
+    ///
+    /// @param address IPv6 address to be reserved
+    /// @param id type of identifier (IDENT_DUID or IDENT_HWADDR are supported)
+    /// @param prefix reservation type (true = prefix, false = address)
+    /// @param new_identifier Boolean value indicating if new host
+    /// identifier should be generated or the same as previously.
+    ///
+    /// @return generated Host object
+    static HostPtr initializeHost6(std::string address, Host::IdentifierType id,
+                                   bool prefix, bool new_identifier = true);
+
+    /// @brief Generates a hardware address in text version.
+    ///
+    /// @param increase A boolean value indicating if new address (increased)
+    /// must be generated or the same address as previously.
+    /// @return HW address in textual form acceptable by Host constructor
+    static std::vector<uint8_t> generateHWAddr(const bool new_identifier = true);
+
+    /// @brief Generates a host identifier in a textual form..
+    ///
+    /// @param increase A boolean value indicating if new identifier (increased)
+    /// must be generated or the same identifier as previously.
+    /// @return Identifier in textual form acceptable by Host constructor
+    static std::vector<uint8_t> generateIdentifier(const bool new_identifier = true);
+
+    /// @brief Checks if the reservation is in the range of reservations.
+    ///
+    /// @param resrv Reservation to be searched for.
+    /// @param range Range of reservations returned by the @c Host object
+    /// in which the reservation will be searched
+    static bool reservationExists(const IPv6Resrv& resrv, const IPv6ResrvRange& range);
+
+    /// @brief Compares hardware addresses of the two hosts.
+    ///
+    /// This method compares two hardware address and uses gtest
+    /// macros to signal unexpected (mismatch if expect_match is true;
+    /// match if expect_match is false) values.
+    ///
+    /// @param host1 first host to be compared
+    /// @param host2 second host to be compared
+    /// @param expect_match true = HW addresses expected to be the same,
+    ///                     false = HW addresses expected to be different
+    static void compareHwaddrs(const ConstHostPtr& host1, const ConstHostPtr& host2,
+                               bool expect_match);
+
+    /// @brief Compares DUIDs of the two hosts.
+    ///
+    /// This method compares two DUIDs (client-ids) and uses gtest
+    /// macros to signal unexpected (mismatch if expect_match is true;
+    /// match if expect_match is false) values.
+    ///
+    /// @param host1 first host to be compared
+    /// @param host2 second host to be compared
+    /// @param expect_match true = DUIDs expected to be the same,
+    ///                     false = DUIDs expected to be different
+    static void compareDuids(const ConstHostPtr& host1, const ConstHostPtr& host2,
+                             bool expect_match);
+
+    /// @brief Compares two hosts
+    ///
+    /// This method uses gtest macros to signal errors.
+    ///
+    /// @param host1 first host to compare
+    /// @param host2 second host to compare
+    static void compareHosts(const isc::dhcp::ConstHostPtr& host1, const ConstHostPtr& host2);
+
+    /// @brief Compares two IPv6 reservation lists.
+    ///
+    /// This method uses gtest macros to signal errors.
+    ///
+    /// @param resv1 first IPv6 reservations list
+    /// @param resv2 second IPv6 reservations list
+    static void compareReservations6(IPv6ResrvRange resv1, IPv6ResrvRange resv2);
+
+    /// @brief Compares two client classes
+    ///
+    /// This method uses gtest macros to signal errors.
+    ///
+    /// @param classes1 first list of client classes
+    /// @param classes2 second list of client classes
+    static void compareClientClasses(const ClientClasses& classes1,
+                                     const ClientClasses& classes2);
+
+    /// @brief Compares options within two configurations.
+    ///
+    /// This method uses gtest macros to signal errors.
+    ///
+    /// @param cfg1 First configuration.
+    /// @param cfg2 Second configuration.
+    static void compareOptions(const ConstCfgOptionPtr& cfg1,
+                               const ConstCfgOptionPtr& cfg2);
+};
+
+}
+}
+}
+
+#endif