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
BENCHMARK_LDADD: ${BENCHMARK_LDADD}
BENCHMARK_SOURCE: ${BENCHMARK_SOURCE}
END
+else
+cat >> config.report << END
+Google Benchmark:
+ no
+END
fi
cat >> config.report << END
AM_CPPFLAGS += $(PGSQL_CPPFLAGS)
endif
if HAVE_CQL
-AM_CPPFLAGS += $(CQL_CPPFLAGS)
+AM_CPPFLAGS += $(CQL_CPPFLAGS) $(CRYPTO_INCLUDES)
endif
AM_CXXFLAGS = $(KEA_CXXFLAGS)
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)
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2017 Deutsche Telekom AG.
//
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
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);
hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr();
}
+ /// @brief After benchmark clean-up
void TearDown(::benchmark::State const&) override {
try {
hdsptr_->rollback();
}
};
+// 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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
+// 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);
lmptr_ = &(LeaseMgrFactory::instance());
}
+ /// @brief Cleans up after the benchmark.
void TearDown(::benchmark::State const&) override {
try {
lmptr_->rollback();
}
};
+// 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
+// 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;
}
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);
}
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);
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,
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");
}
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);
}
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2017 Deutsche Telekom AG.
//
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
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
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;
}
}
- 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();
+// 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);
}
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);
}
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);
}
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);
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;
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
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2017 Deutsche Telekom AG.
//
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
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_;
};
#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;
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
(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();
}
}
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)
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);
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
#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);
lmptr_ = &(LeaseMgrFactory::instance());
}
+ /// @brief Cleans up after the test.
void TearDown(::benchmark::State const&) override {
try {
lmptr_->rollback();
}
};
+// 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
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
+// 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/pgsql_schema.h>
+using namespace isc::dhcp::bench;
using isc::dhcp::LeaseMgrFactory;
using isc::dhcp::bench::GenericLeaseMgrBenchmark;
using isc::dhcp::test::createPgSQLSchema;
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);
lmptr_ = &(LeaseMgrFactory::instance());
}
+ /// @brief Cleans up after the test.
void TearDown(::benchmark::State const&) override {
try {
lmptr_->rollback();
}
};
+// 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
#include <benchmark/benchmark.h>
#include <log/logger_support.h>
+/// @brief A simple class that initializes logging.
class Initializer {
public:
Initializer() {
+// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2016-2017 Deutsche Telekom AG.
//
// Author: Andrei Pavel <andrei.pavel@qualitance.com>
/// @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.
/// 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).
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).
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.
///
#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>
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));
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
#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>
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) {
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,
// 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));
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.
// 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);
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
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();
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
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));
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.
// 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());
// 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
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());
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());
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("");
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();
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);
host->getIdentifier().size());
ASSERT_TRUE(from_hds);
- compareHosts(host, from_hds);
+ HostDataSourceUtils::compareHosts(host, from_hds);
}
void
// 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) {
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));
// 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
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));
// 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
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);
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));
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.
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));
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
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));
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));
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));
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);
ASSERT_TRUE(from_hds);
// Check if reservations are the same
- compareReservations6(host->getIPv6Reservations(),
+ HostDataSourceUtils::compareReservations6(host->getIPv6Reservations(),
from_hds->getIPv6Reservations());
}
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);
ASSERT_TRUE(from_hds);
// Check if hosts are the same
- compareHosts(host, from_hds);
+ HostDataSourceUtils::compareHosts(host, from_hds);
}
void
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);
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.
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.
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));
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
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) {
// 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,
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&
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
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) {
// 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,
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&
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
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) {
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
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"));
// 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,
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&
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
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();
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) +
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.
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.
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.
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.
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));
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.
// 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));
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.
// 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.
/// @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
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.
#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>
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));
#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>
<< " 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));
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
--- /dev/null
+// 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();
+ }
+ }
+}
+
+
+}
+}
+}
+
--- /dev/null
+// 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