Bug Summary

File:home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmp_xzd2v8m/../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
Warning:line 4251, column 5
Value stored to 'ret' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name alloc_engine4_unittest.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmp_xzd2v8m -fcoverage-compilation-dir=/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmp_xzd2v8m -resource-dir /usr/bin/../lib/clang/22 -I src/lib/dhcpsrv/tests/kea-dhcpsrv-tests.p -I src/lib/dhcpsrv/tests -I ../../../src/lib/dhcpsrv/tests -I . -I ../../.. -I src -I ../../../src -I src/bin -I ../../../src/bin -I src/lib -I ../../../src/lib -I /usr/src/googletest/googletest -I /usr/src/googletest/googletest/include -I /usr/include -D _GLIBCXX_ASSERTIONS=1 -D _FILE_OFFSET_BITS=64 -D BOOST_ALL_NO_LIB -D TEST_DATA_BUILDDIR="/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmp_xzd2v8m/src/lib/dhcpsrv/tests" -D DHCP_DATA_DIR="/usr/local/var/lib/kea" -D KEA_LFC_EXECUTABLE="/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmp_xzd2v8m/src/bin/lfc/kea-lfc" -D DEFAULT_HOOKS_PATH="/usr/local/lib64/kea/hooks" -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/backward -internal-isystem /usr/bin/../lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-missing-field-initializers -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-logs/scanbuild/2026-08-13-132751-4729-1 -x c++ ../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
1// Copyright (C) 2015-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8#include <dhcp/pkt4.h>
9#include <dhcp/dhcp4.h>
10#include <dhcp/option_custom.h>
11#include <dhcp/option_int.h>
12#include <dhcpsrv/shared_network.h>
13#include <dhcpsrv/host_mgr.h>
14#include <dhcpsrv/parsers/client_class_def_parser.h>
15#include <dhcpsrv/testutils/alloc_engine_utils.h>
16#include <dhcpsrv/testutils/test_utils.h>
17#include <eval/eval_context.h>
18#include <hooks/hooks_manager.h>
19#include <hooks/callout_handle.h>
20#include <stats/stats_mgr.h>
21#include <testutils/gtest_utils.h>
22#include <util/str.h>
23#include <boost/pointer_cast.hpp>
24
25using namespace std;
26using namespace isc::hooks;
27using namespace isc::asiolink;
28using namespace isc::data;
29using namespace isc::stats;
30using namespace isc::util;
31
32namespace isc {
33namespace dhcp {
34namespace test {
35
36// This test checks if the v4 Allocation Engine can be instantiated, parses
37// parameters string and allocators are created.
38TEST_F(AllocEngine4Test, constructor)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("constructor") > 1, "test_name must not be empty"
); class AllocEngine4Test_constructor_Test : public AllocEngine4Test
{ public: AllocEngine4Test_constructor_Test() = default; ~AllocEngine4Test_constructor_Test
() override = default; AllocEngine4Test_constructor_Test (const
AllocEngine4Test_constructor_Test &) = delete; AllocEngine4Test_constructor_Test
& operator=( const AllocEngine4Test_constructor_Test &
) = delete; AllocEngine4Test_constructor_Test (AllocEngine4Test_constructor_Test
&&) noexcept = delete; AllocEngine4Test_constructor_Test
& operator=( AllocEngine4Test_constructor_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_constructor_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "constructor", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 38
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 38), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 38), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_constructor_Test
>); void AllocEngine4Test_constructor_Test::TestBody()
{
39 boost::scoped_ptr<AllocEngine> x;
40
41 // Create V4 (ipv6=false) Allocation Engine that will try at most
42 // 100 attempts to pick up a lease
43 ASSERT_NO_THROW(x.reset(new AllocEngine(100)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
x.reset(new AllocEngine(100)); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_43
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_43
; } } else gtest_label_testnothrow_43 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 43, ("Expected: " "x.reset(new AllocEngine(100))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
44}
45
46// This test checks if two simple IPv4 allocations succeed and that the
47// statistics is properly updated. Prior to the second allocation it
48// resets the pointer to the last allocated address within the address
49// pool. This causes the engine to walk over the already allocated
50// address and then pick the first available address for the second
51// allocation. Because the allocation engine checks the callouts next
52// step status after each attempt to allocate an address, this test
53// also sets this status to non-default value prior to the second
54// allocation attempt, to make sure that this unexpected status will
55// not interfere with the allocation.
56TEST_F(AllocEngine4Test, simpleAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("simpleAlloc4") > 1, "test_name must not be empty"
); class AllocEngine4Test_simpleAlloc4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_simpleAlloc4_Test() = default; ~AllocEngine4Test_simpleAlloc4_Test
() override = default; AllocEngine4Test_simpleAlloc4_Test (const
AllocEngine4Test_simpleAlloc4_Test &) = delete; AllocEngine4Test_simpleAlloc4_Test
& operator=( const AllocEngine4Test_simpleAlloc4_Test &
) = delete; AllocEngine4Test_simpleAlloc4_Test (AllocEngine4Test_simpleAlloc4_Test
&&) noexcept = delete; AllocEngine4Test_simpleAlloc4_Test
& operator=( AllocEngine4Test_simpleAlloc4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_simpleAlloc4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "simpleAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 56
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 56), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 56), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4_Test
>); void AllocEngine4Test_simpleAlloc4_Test::TestBody()
{
57 boost::scoped_ptr<AllocEngine> engine;
58 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_58
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_58
; } } else gtest_label_testnothrow_58 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 58, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
59 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 59, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
60
61 // Assigned addresses should be zero.
62 EXPECT_TRUE(testStatistics("assigned-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 62, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0)", "false", "true"
) .c_str()) = ::testing::Message()
;
63 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 63, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
64
65 // Get the cumulative count of assigned addresses.
66 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
67 subnet_->getID());
68
69 int64_t glbl_assigned = getStatistics("assigned-addresses");
70 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
71
72 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
73 false, true, "somehost.example.com.", false);
74 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
75
76 Lease4Ptr lease = engine->allocateLease4(ctx);
77 // The new lease has been allocated, so the old lease should not exist.
78 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 78, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
79
80 // Check that we got a lease
81 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 81, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
82
83 // Do all checks on the lease
84 checkLease4(lease);
85
86 // Check that the lease is indeed in LeaseMgr
87 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
88 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 88, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
89
90 // Now check that the lease in LeaseMgr has the same parameters
91 detailCompareLease(lease, from_mgr);
92
93 // Assigned addresses should have incremented.
94 EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 94, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
95 cumulative += 1;
96 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 97, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
97 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 97, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
98 glbl_assigned += 1;
99 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 99, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
100 glbl_cumulative += 1;
101 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 101, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
102
103 // Second allocation starts here.
104 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
105 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
106 AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, IOAddress("0.0.0.0"),
107 false, true, "anotherhost.example.com.",
108 false);
109 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
110
111 // Set the next step to non-default value to verify that it doesn't
112 // affect the allocation.
113 ctx2.callout_handle_ = HooksManager::createCalloutHandle();
114 ctx2.callout_handle_->setStatus(CalloutHandle::NEXT_STEP_SKIP);
115
116 // Set the last allocated to the beginning of the pool. The allocation
117 // engine should detect that the first address is already allocated and
118 // assign the first available one.
119 auto allocation_state = boost::dynamic_pointer_cast<PoolIterativeAllocationState>(pool_->getAllocationState());
120 allocation_state->resetLastAllocated();
121
122 lease = engine->allocateLease4(ctx2);
123
124 // The new lease has been allocated, so the old lease should not exist.
125 ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 125, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
126
127 // Check that we got a lease
128 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 128, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
129
130 // Check that the lease is indeed in LeaseMgr
131 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
132 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 132, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
133
134 // Now check that the lease in LeaseMgr has the same parameters
135 detailCompareLease(lease, from_mgr);
136
137 // Assigned addresses should have incremented.
138 EXPECT_TRUE(testStatistics("assigned-addresses", 2, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 2, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 138, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 2, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
139 cumulative += 1;
140 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 141, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
141 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 141, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
142 glbl_assigned += 1;
143 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 143, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
144 glbl_cumulative += 1;
145 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 145, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
146}
147
148// This test checks that simple allocation uses the default valid lifetime.
149TEST_F(AllocEngine4Test, defaultAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("defaultAlloc4") > 1, "test_name must not be empty"
); class AllocEngine4Test_defaultAlloc4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_defaultAlloc4_Test() = default; ~
AllocEngine4Test_defaultAlloc4_Test() override = default; AllocEngine4Test_defaultAlloc4_Test
(const AllocEngine4Test_defaultAlloc4_Test &) = delete; AllocEngine4Test_defaultAlloc4_Test
& operator=( const AllocEngine4Test_defaultAlloc4_Test &
) = delete; AllocEngine4Test_defaultAlloc4_Test (AllocEngine4Test_defaultAlloc4_Test
&&) noexcept = delete; AllocEngine4Test_defaultAlloc4_Test
& operator=( AllocEngine4Test_defaultAlloc4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_defaultAlloc4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "defaultAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 149
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 149), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 149), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultAlloc4_Test
>); void AllocEngine4Test_defaultAlloc4_Test::TestBody()
{
150 boost::scoped_ptr<AllocEngine> engine;
151 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_151
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_151
; } } else gtest_label_testnothrow_151 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 151, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
152 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 152, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
153
154 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
155 false, true, "somehost.example.com.", false);
156 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
157 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
158
159 Lease4Ptr lease = engine->allocateLease4(ctx);
160 // The new lease has been allocated, so the old lease should not exist.
161 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 161, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
162
163 // Check that we got a lease
164 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 164, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
165
166 // Do all checks on the lease
167 checkLease4(lease);
168
169 // Check the valid lifetime has the default.
170 EXPECT_EQ(subnet_->getValid(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid()"
, "lease->valid_lft_", subnet_->getValid(), lease->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 170, gtest_ar.failure_message()) = ::testing::Message()
;
171
172 // Check that the lease is indeed in LeaseMgr
173 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
174 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 174, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
175
176 // Now check that the lease in LeaseMgr has the same parameters
177 detailCompareLease(lease, from_mgr);
178}
179
180// This test checks that simple allocation uses the specified valid lifetime.
181TEST_F(AllocEngine4Test, hintAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("hintAlloc4") > 1, "test_name must not be empty"
); class AllocEngine4Test_hintAlloc4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_hintAlloc4_Test() = default; ~AllocEngine4Test_hintAlloc4_Test
() override = default; AllocEngine4Test_hintAlloc4_Test (const
AllocEngine4Test_hintAlloc4_Test &) = delete; AllocEngine4Test_hintAlloc4_Test
& operator=( const AllocEngine4Test_hintAlloc4_Test &
) = delete; AllocEngine4Test_hintAlloc4_Test (AllocEngine4Test_hintAlloc4_Test
&&) noexcept = delete; AllocEngine4Test_hintAlloc4_Test
& operator=( AllocEngine4Test_hintAlloc4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_hintAlloc4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "hintAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 181
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 181), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 181), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintAlloc4_Test
>); void AllocEngine4Test_hintAlloc4_Test::TestBody()
{
182 boost::scoped_ptr<AllocEngine> engine;
183 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_183
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_183
; } } else gtest_label_testnothrow_183 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 183, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
184 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 184, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
185
186 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
187 false, true, "somehost.example.com.", false);
188 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
189 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
190
191 // Specify the valid lifetime we want.
192 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4));
193 ctx.query_->addOption(opt);
194
195 Lease4Ptr lease = engine->allocateLease4(ctx);
196 // The new lease has been allocated, so the old lease should not exist.
197 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 197, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
198
199 // Check that we got a lease
200 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 200, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
201
202 // Do all checks on the lease
203 checkLease4(lease);
204
205 // Check the valid lifetime has the wanted value.
206 EXPECT_EQ(opt->getValue(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("opt->getValue()"
, "lease->valid_lft_", opt->getValue(), lease->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 206, gtest_ar.failure_message()) = ::testing::Message()
;
207
208 // Check that the lease is indeed in LeaseMgr
209 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
210 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 210, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
211
212 // Now check that the lease in LeaseMgr has the same parameters
213 detailCompareLease(lease, from_mgr);
214}
215
216// This test checks that simple allocation uses the min valid lifetime.
217TEST_F(AllocEngine4Test, minAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("minAlloc4") > 1, "test_name must not be empty"
); class AllocEngine4Test_minAlloc4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_minAlloc4_Test() = default; ~AllocEngine4Test_minAlloc4_Test
() override = default; AllocEngine4Test_minAlloc4_Test (const
AllocEngine4Test_minAlloc4_Test &) = delete; AllocEngine4Test_minAlloc4_Test
& operator=( const AllocEngine4Test_minAlloc4_Test &
) = delete; AllocEngine4Test_minAlloc4_Test (AllocEngine4Test_minAlloc4_Test
&&) noexcept = delete; AllocEngine4Test_minAlloc4_Test
& operator=( AllocEngine4Test_minAlloc4_Test &&)
noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_minAlloc4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "minAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 217
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 217), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 217), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minAlloc4_Test
>); void AllocEngine4Test_minAlloc4_Test::TestBody()
{
218 boost::scoped_ptr<AllocEngine> engine;
219 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_219
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_219
; } } else gtest_label_testnothrow_219 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 219, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
220 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 220, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
221
222 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
223 false, true, "somehost.example.com.", false);
224 subnet_->setValid(Triplet<uint32_t>(2, 3, 5));
225 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
226
227 // Specify the valid lifetime we want, as it is lower than the min value
228 // we'll get this min value instead.
229 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1));
230 ctx.query_->addOption(opt);
231
232 Lease4Ptr lease = engine->allocateLease4(ctx);
233 // The new lease has been allocated, so the old lease should not exist.
234 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 234, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
235
236 // Check that we got a lease
237 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 237, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
238
239 // Do all checks on the lease
240 checkLease4(lease);
241
242 // Check the valid lifetime has the wanted value.
243 EXPECT_EQ(subnet_->getValid().getMin(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMin()"
, "lease->valid_lft_", subnet_->getValid().getMin(), lease
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 243, gtest_ar.failure_message()) = ::testing::Message()
;
244
245 // Check that the lease is indeed in LeaseMgr
246 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
247 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 247, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
248
249 // Now check that the lease in LeaseMgr has the same parameters
250 detailCompareLease(lease, from_mgr);
251}
252
253// This test checks that simple allocation uses the max valid lifetime.
254TEST_F(AllocEngine4Test, maxAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("maxAlloc4") > 1, "test_name must not be empty"
); class AllocEngine4Test_maxAlloc4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_maxAlloc4_Test() = default; ~AllocEngine4Test_maxAlloc4_Test
() override = default; AllocEngine4Test_maxAlloc4_Test (const
AllocEngine4Test_maxAlloc4_Test &) = delete; AllocEngine4Test_maxAlloc4_Test
& operator=( const AllocEngine4Test_maxAlloc4_Test &
) = delete; AllocEngine4Test_maxAlloc4_Test (AllocEngine4Test_maxAlloc4_Test
&&) noexcept = delete; AllocEngine4Test_maxAlloc4_Test
& operator=( AllocEngine4Test_maxAlloc4_Test &&)
noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_maxAlloc4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "maxAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 254
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 254), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 254), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxAlloc4_Test
>); void AllocEngine4Test_maxAlloc4_Test::TestBody()
{
255 boost::scoped_ptr<AllocEngine> engine;
256 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_256
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_256
; } } else gtest_label_testnothrow_256 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 256, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
257 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 257, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
258
259 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
260 false, true, "somehost.example.com.", false);
261 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
262 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
263
264 // Specify the valid lifetime we want, as it is greater than the max value
265 // we'll get this max value instead.
266 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6));
267 ctx.query_->addOption(opt);
268
269 Lease4Ptr lease = engine->allocateLease4(ctx);
270 // The new lease has been allocated, so the old lease should not exist.
271 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 271, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
272
273 // Check that we got a lease
274 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 274, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
275
276 // Do all checks on the lease
277 checkLease4(lease);
278
279 // Check the valid lifetime has the wanted value.
280 EXPECT_EQ(subnet_->getValid().getMax(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMax()"
, "lease->valid_lft_", subnet_->getValid().getMax(), lease
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 280, gtest_ar.failure_message()) = ::testing::Message()
;
281
282 // Check that the lease is indeed in LeaseMgr
283 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
284 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 284, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
285
286 // Now check that the lease in LeaseMgr has the same parameters
287 detailCompareLease(lease, from_mgr);
288}
289
290// This test checks that simple allocation handles BOOTP queries.
291TEST_F(AllocEngine4Test, bootpAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("bootpAlloc4") > 1, "test_name must not be empty"
); class AllocEngine4Test_bootpAlloc4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_bootpAlloc4_Test() = default; ~AllocEngine4Test_bootpAlloc4_Test
() override = default; AllocEngine4Test_bootpAlloc4_Test (const
AllocEngine4Test_bootpAlloc4_Test &) = delete; AllocEngine4Test_bootpAlloc4_Test
& operator=( const AllocEngine4Test_bootpAlloc4_Test &
) = delete; AllocEngine4Test_bootpAlloc4_Test (AllocEngine4Test_bootpAlloc4_Test
&&) noexcept = delete; AllocEngine4Test_bootpAlloc4_Test
& operator=( AllocEngine4Test_bootpAlloc4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_bootpAlloc4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "bootpAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 291
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 291), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 291), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpAlloc4_Test
>); void AllocEngine4Test_bootpAlloc4_Test::TestBody()
{
292 boost::scoped_ptr<AllocEngine> engine;
293 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_293
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_293
; } } else gtest_label_testnothrow_293 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 293, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
294 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 294, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
295
296 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
297 false, true, "somehost.example.com.", false);
298 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
299 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
300
301 // Make the query a BOOTP one.
302 ctx.query_->addClass("BOOTP");
303
304 Lease4Ptr lease = engine->allocateLease4(ctx);
305 // The new lease has been allocated, so the old lease should not exist.
306 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 306, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
307
308 // Check that we got a lease
309 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 309, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
310
311 // Check that is belongs to the right subnet and client.
312 EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet_->getID()", lease->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 312, gtest_ar.failure_message()) = ::testing::Message()
;
313 EXPECT_TRUE(subnet_->inRange(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease
->addr_))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 313, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
314 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 314, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
315 ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->client_id_)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 315, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
316 EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 316, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
317 ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 317, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
318 EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 318, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
319
320 // Check the valid lifetime is infinite.
321 uint32_t infinity_lft = Lease::INFINITY_LFT;
322 EXPECT_EQ(infinity_lft, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("infinity_lft"
, "lease->valid_lft_", infinity_lft, lease->valid_lft_)
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 322, gtest_ar.failure_message()) = ::testing::Message()
;
323
324 // Check that the lease is indeed in LeaseMgr
325 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
326 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 326, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
327
328 // Now check that the lease in LeaseMgr has the same parameters
329 detailCompareLease(lease, from_mgr);
330}
331
332// This test checks if the fake allocation (for DHCPDISCOVER) can succeed
333TEST_F(AllocEngine4Test, fakeAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("fakeAlloc4") > 1, "test_name must not be empty"
); class AllocEngine4Test_fakeAlloc4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_fakeAlloc4_Test() = default; ~AllocEngine4Test_fakeAlloc4_Test
() override = default; AllocEngine4Test_fakeAlloc4_Test (const
AllocEngine4Test_fakeAlloc4_Test &) = delete; AllocEngine4Test_fakeAlloc4_Test
& operator=( const AllocEngine4Test_fakeAlloc4_Test &
) = delete; AllocEngine4Test_fakeAlloc4_Test (AllocEngine4Test_fakeAlloc4_Test
&&) noexcept = delete; AllocEngine4Test_fakeAlloc4_Test
& operator=( AllocEngine4Test_fakeAlloc4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_fakeAlloc4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "fakeAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 333
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 333), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 333), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4_Test
>); void AllocEngine4Test_fakeAlloc4_Test::TestBody()
{
334 boost::scoped_ptr<AllocEngine> engine;
335 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_335
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_335
; } } else gtest_label_testnothrow_335 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 335, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
336 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 336, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
337
338 // Assigned addresses should be zero.
339 EXPECT_TRUE(testStatistics("assigned-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 339, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0)", "false", "true"
) .c_str()) = ::testing::Message()
;
340 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 340, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
341
342 // Get the cumulative count of assigned addresses.
343 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
344 subnet_->getID());
345
346 int64_t glbl_assigned = getStatistics("assigned-addresses");
347 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
348
349 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
350 IOAddress("0.0.0.0"), false, true,
351 "host.example.com.", true);
352 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
353
354 Lease4Ptr lease = engine->allocateLease4(ctx);
355
356 // The new lease has been allocated, so the old lease should not exist.
357 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 357, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
358
359 // Check that we got a lease
360 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 360, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
361
362 // Do all checks on the lease
363 checkLease4(lease);
364
365 // Check that the lease is NOT in LeaseMgr
366 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
367 ASSERT_FALSE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 367, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "true", "false") .c_str()) = ::testing::Message
()
;
368
369 // Assigned addresses should still be zero.
370 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 370, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
371 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
372 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
373 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 373, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
374 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 374, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
375}
376
377// This test checks if the allocation with a hint that is valid (in range,
378// in pool and free) can succeed
379TEST_F(AllocEngine4Test, allocWithValidHint4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("allocWithValidHint4") > 1, "test_name must not be empty"
); class AllocEngine4Test_allocWithValidHint4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_allocWithValidHint4_Test() = default
; ~AllocEngine4Test_allocWithValidHint4_Test() override = default
; AllocEngine4Test_allocWithValidHint4_Test (const AllocEngine4Test_allocWithValidHint4_Test
&) = delete; AllocEngine4Test_allocWithValidHint4_Test &
operator=( const AllocEngine4Test_allocWithValidHint4_Test &
) = delete; AllocEngine4Test_allocWithValidHint4_Test (AllocEngine4Test_allocWithValidHint4_Test
&&) noexcept = delete; AllocEngine4Test_allocWithValidHint4_Test
& operator=( AllocEngine4Test_allocWithValidHint4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_allocWithValidHint4_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "allocWithValidHint4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 379), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 379), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 379), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocWithValidHint4_Test
>); void AllocEngine4Test_allocWithValidHint4_Test::TestBody
()
{
380 boost::scoped_ptr<AllocEngine> engine;
381 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_381
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_381
; } } else gtest_label_testnothrow_381 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 381, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
382 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 382, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
383
384 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
385 IOAddress("192.0.2.105"), true, true,
386 "host.example.com.", false);
387 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
388 Lease4Ptr lease = engine->allocateLease4(ctx);
389
390 // Check that we got a lease
391 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 391, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
392
393 // We have allocated the new lease, so the old lease should not exist.
394 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 394, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
395
396 // We should get what we asked for
397 EXPECT_EQ(lease->addr_.toText(), "192.0.2.105")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->addr_.toText()"
, "\"192.0.2.105\"", lease->addr_.toText(), "192.0.2.105")
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 397, gtest_ar.failure_message()) = ::testing::Message()
;
398
399 // Do all checks on the lease
400 checkLease4(lease);
401
402 // Check that the lease is indeed in LeaseMgr
403 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
404 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 404, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
405
406 // Now check that the lease in LeaseMgr has the same parameters
407 detailCompareLease(lease, from_mgr);
408}
409
410// This test checks if the allocation with a hint that is in range,
411// in pool, but is currently used can succeed
412TEST_F(AllocEngine4Test, allocWithUsedHint4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("allocWithUsedHint4") > 1, "test_name must not be empty"
); class AllocEngine4Test_allocWithUsedHint4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_allocWithUsedHint4_Test() = default
; ~AllocEngine4Test_allocWithUsedHint4_Test() override = default
; AllocEngine4Test_allocWithUsedHint4_Test (const AllocEngine4Test_allocWithUsedHint4_Test
&) = delete; AllocEngine4Test_allocWithUsedHint4_Test &
operator=( const AllocEngine4Test_allocWithUsedHint4_Test &
) = delete; AllocEngine4Test_allocWithUsedHint4_Test (AllocEngine4Test_allocWithUsedHint4_Test
&&) noexcept = delete; AllocEngine4Test_allocWithUsedHint4_Test
& operator=( AllocEngine4Test_allocWithUsedHint4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_allocWithUsedHint4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "allocWithUsedHint4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 412), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 412), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 412), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocWithUsedHint4_Test
>); void AllocEngine4Test_allocWithUsedHint4_Test::TestBody
()
{
413 boost::scoped_ptr<AllocEngine> engine;
414 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_414
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_414
; } } else gtest_label_testnothrow_414 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 414, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
415 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 415, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
416
417 // Let's create a lease and put it in the LeaseMgr
418 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
419 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
420 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
421 time_t now = time(NULL__null);
422 Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2,
423 clientid2, sizeof(clientid2), 1, now, subnet_->getID()));
424 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(used))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 424, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(used)", "false", "true"
) .c_str()) = ::testing::Message()
;
425
426 // Another client comes in and request an address that is in pool, but
427 // unfortunately it is used already. The same address must not be allocated
428 // twice.
429 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
430 IOAddress("192.0.2.106"), false, false,
431 "", true);
432 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
433 Lease4Ptr lease = engine->allocateLease4(ctx);
434
435 // New lease has been allocated, so the old lease should not exist.
436 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 436, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
437
438 // Check that we got a lease
439 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 439, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
440
441 // Allocated address must be different
442 EXPECT_NE(used->addr_, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("used->addr_"
, "lease->addr_", used->addr_, lease->addr_))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 442, gtest_ar.failure_message()) = ::testing::Message()
;
443
444 // We should NOT get what we asked for, because it is used already
445 EXPECT_NE("192.0.2.106", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("\"192.0.2.106\""
, "lease->addr_.toText()", "192.0.2.106", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 445, gtest_ar.failure_message()) = ::testing::Message()
;
446
447 // Do all checks on the lease
448 checkLease4(lease);
449
450 // The lease should not be in the LeaseMgr because it was a failed allocation.
451 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
452 ASSERT_FALSE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 452, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "true", "false") .c_str()) = ::testing::Message
()
;
453}
454
455// This test checks if an allocation with a hint that is out of the blue
456// can succeed. The invalid hint should be ignored completely.
457TEST_F(AllocEngine4Test, allocBogusHint4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("allocBogusHint4") > 1, "test_name must not be empty"
); class AllocEngine4Test_allocBogusHint4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_allocBogusHint4_Test() = default;
~AllocEngine4Test_allocBogusHint4_Test() override = default;
AllocEngine4Test_allocBogusHint4_Test (const AllocEngine4Test_allocBogusHint4_Test
&) = delete; AllocEngine4Test_allocBogusHint4_Test &
operator=( const AllocEngine4Test_allocBogusHint4_Test &
) = delete; AllocEngine4Test_allocBogusHint4_Test (AllocEngine4Test_allocBogusHint4_Test
&&) noexcept = delete; AllocEngine4Test_allocBogusHint4_Test
& operator=( AllocEngine4Test_allocBogusHint4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_allocBogusHint4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "allocBogusHint4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 457
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 457), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 457), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocBogusHint4_Test
>); void AllocEngine4Test_allocBogusHint4_Test::TestBody()
{
458 boost::scoped_ptr<AllocEngine> engine;
459 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_459
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_459
; } } else gtest_label_testnothrow_459 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 459, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
460 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 460, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
461
462 // Client would like to get a 10.1.1.1 lease, which does not belong to any
463 // supported lease. Allocation engine should ignore it and carry on
464 // with the normal allocation
465 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
466 IOAddress("10.1.1.1"), false, false,
467 "", true);
468 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
469 Lease4Ptr lease = engine->allocateLease4(ctx);
470 // Check that we got a lease
471 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 471, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
472
473 // We have allocated a new lease, so the old lease should not exist.
474 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 474, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
475
476 // We should NOT get what we asked for, because it is used already
477 EXPECT_NE("10.1.1.1", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("\"10.1.1.1\"",
"lease->addr_.toText()", "10.1.1.1", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 477, gtest_ar.failure_message()) = ::testing::Message()
;
478
479 // Do all checks on the lease
480 checkLease4(lease);
481
482 // Check that the lease is not in the LeaseMgr as it is a fake allocation.
483 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
484 EXPECT_FALSE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "true", "false") .c_str()) = ::testing::Message
()
;
485}
486
487// This test checks that NULL values are handled properly
488TEST_F(AllocEngine4Test, allocateLease4Nulls)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("allocateLease4Nulls") > 1, "test_name must not be empty"
); class AllocEngine4Test_allocateLease4Nulls_Test : public AllocEngine4Test
{ public: AllocEngine4Test_allocateLease4Nulls_Test() = default
; ~AllocEngine4Test_allocateLease4Nulls_Test() override = default
; AllocEngine4Test_allocateLease4Nulls_Test (const AllocEngine4Test_allocateLease4Nulls_Test
&) = delete; AllocEngine4Test_allocateLease4Nulls_Test &
operator=( const AllocEngine4Test_allocateLease4Nulls_Test &
) = delete; AllocEngine4Test_allocateLease4Nulls_Test (AllocEngine4Test_allocateLease4Nulls_Test
&&) noexcept = delete; AllocEngine4Test_allocateLease4Nulls_Test
& operator=( AllocEngine4Test_allocateLease4Nulls_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_allocateLease4Nulls_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "allocateLease4Nulls", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 488), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 488), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 488), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocateLease4Nulls_Test
>); void AllocEngine4Test_allocateLease4Nulls_Test::TestBody
()
{
489 boost::scoped_ptr<AllocEngine> engine;
490 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_490
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_490
; } } else gtest_label_testnothrow_490 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 490, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
491 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 491, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
492
493 // Allocations without subnet are not allowed
494 AllocEngine::ClientContext4 ctx1(Subnet4Ptr(), clientid_, hwaddr_,
495 IOAddress("0.0.0.0"), false, false,
496 "", false);
497 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
498 Lease4Ptr lease = engine->allocateLease4(ctx1);
499
500 ASSERT_FALSE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 500, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
501
502 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
502, gtest_ar.failure_message()) = ::testing::Message()
;
503 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 503, gtest_ar.failure_message()) = ::testing::Message()
;
504 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
504, gtest_ar.failure_message()) = ::testing::Message()
;
505 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
505, gtest_ar.failure_message()) = ::testing::Message()
;
506 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
506, gtest_ar.failure_message()) = ::testing::Message()
;
507
508 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 508, gtest_ar.failure_message()) = ::testing::Message()
;
509 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 509, gtest_ar.failure_message()) = ::testing::Message()
;
510 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 510, gtest_ar.failure_message()) = ::testing::Message()
;
511 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 511, gtest_ar.failure_message()) = ::testing::Message()
;
512 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 512, gtest_ar.failure_message()) = ::testing::Message()
;
513
514 // Allocations without HW address are not allowed
515 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, HWAddrPtr(),
516 IOAddress("0.0.0.0"), false, false,
517 "", false);
518 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
519 lease = engine->allocateLease4(ctx2);
520 ASSERT_FALSE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 520, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
521 ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 521, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
522
523 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
523, gtest_ar.failure_message()) = ::testing::Message()
;
524 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 524, gtest_ar.failure_message()) = ::testing::Message()
;
525 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
525, gtest_ar.failure_message()) = ::testing::Message()
;
526 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
526, gtest_ar.failure_message()) = ::testing::Message()
;
527 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
527, gtest_ar.failure_message()) = ::testing::Message()
;
528
529 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 529, gtest_ar.failure_message()) = ::testing::Message()
;
530 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 530, gtest_ar.failure_message()) = ::testing::Message()
;
531 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 531, gtest_ar.failure_message()) = ::testing::Message()
;
532 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 532, gtest_ar.failure_message()) = ::testing::Message()
;
533 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 533, gtest_ar.failure_message()) = ::testing::Message()
;
534
535 // Allocations without client-id are allowed
536 clientid_.reset();
537 AllocEngine::ClientContext4 ctx3(subnet_, ClientIdPtr(), hwaddr_,
538 IOAddress("0.0.0.0"), false, false,
539 "", false);
540 ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234));
541 lease = engine->allocateLease4(ctx3);
542
543 // Check that we got a lease
544 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 544, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
545 // New lease has been allocated, so the old lease should not exist.
546 ASSERT_FALSE(ctx3.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx3.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 546, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx3.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
547
548 // Do all checks on the lease
549 checkLease4(lease);
550
551 // Check that the lease is indeed in LeaseMgr
552 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
553 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 553, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
554
555 // Now check that the lease in LeaseMgr has the same parameters
556 detailCompareLease(lease, from_mgr);
557}
558
559// This test checks if a returning client can renew an
560// an existing lease and assigned-leases increments accordingly
561TEST_F(AllocEngine4Test, simpleRenew4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("simpleRenew4") > 1, "test_name must not be empty"
); class AllocEngine4Test_simpleRenew4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_simpleRenew4_Test() = default; ~AllocEngine4Test_simpleRenew4_Test
() override = default; AllocEngine4Test_simpleRenew4_Test (const
AllocEngine4Test_simpleRenew4_Test &) = delete; AllocEngine4Test_simpleRenew4_Test
& operator=( const AllocEngine4Test_simpleRenew4_Test &
) = delete; AllocEngine4Test_simpleRenew4_Test (AllocEngine4Test_simpleRenew4_Test
&&) noexcept = delete; AllocEngine4Test_simpleRenew4_Test
& operator=( AllocEngine4Test_simpleRenew4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_simpleRenew4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "simpleRenew4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 561
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 561), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 561), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleRenew4_Test
>); void AllocEngine4Test_simpleRenew4_Test::TestBody()
{
562 boost::scoped_ptr<AllocEngine> engine;
563 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_563
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_563
; } } else gtest_label_testnothrow_563 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 563, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
564 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
565
566 EXPECT_TRUE(testStatistics("assigned-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 566, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0)", "false", "true"
) .c_str()) = ::testing::Message()
;
567 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 567, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
568 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
569 subnet_->getID());
570
571 int64_t glbl_assigned = getStatistics("assigned-addresses");
572 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
573
574 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
575 false, true, "somehost.example.com.", false);
576 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
577
578 Lease4Ptr lease = engine->allocateLease4(ctx);
579
580 // Check that we got a lease and it's sane
581 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 581, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
582 checkLease4(lease);
583
584 // The new lease has been allocated, so the old lease should not exist.
585 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
586
587 // We should have incremented assigned-addresses
588 EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
589 cumulative += 1;
590 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 591, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
591 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 591, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
592 glbl_assigned += 1;
593 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 593, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
594 glbl_cumulative += 1;
595 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
596
597 // Do it again, this should amount to the renew of an existing lease
598 Lease4Ptr lease2 = engine->allocateLease4(ctx);
599
600 // Check that we got a lease and it's sane
601 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 601, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
602 checkLease4(lease2);
603
604 // Lease already existed, so old_lease should be set.
605 EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 605, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
606
607 // Should NOT have bumped assigned-addresses
608 EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 608, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
609 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
610 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
611 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 611, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
612 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 612, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
613}
614
615// This test checks simple renewal uses the default valid lifetime.
616TEST_F(AllocEngine4Test, defaultRenew4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("defaultRenew4") > 1, "test_name must not be empty"
); class AllocEngine4Test_defaultRenew4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_defaultRenew4_Test() = default; ~
AllocEngine4Test_defaultRenew4_Test() override = default; AllocEngine4Test_defaultRenew4_Test
(const AllocEngine4Test_defaultRenew4_Test &) = delete; AllocEngine4Test_defaultRenew4_Test
& operator=( const AllocEngine4Test_defaultRenew4_Test &
) = delete; AllocEngine4Test_defaultRenew4_Test (AllocEngine4Test_defaultRenew4_Test
&&) noexcept = delete; AllocEngine4Test_defaultRenew4_Test
& operator=( AllocEngine4Test_defaultRenew4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_defaultRenew4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "defaultRenew4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 616
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 616), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 616), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultRenew4_Test
>); void AllocEngine4Test_defaultRenew4_Test::TestBody()
{
617 boost::scoped_ptr<AllocEngine> engine;
618 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_618
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_618
; } } else gtest_label_testnothrow_618 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 618, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
619 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 619, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
620
621 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
622 false, true, "somehost.example.com.", false);
623 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
624 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
625
626 Lease4Ptr lease = engine->allocateLease4(ctx);
627
628 // Check that we got a lease and it's sane
629 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 629, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
630 checkLease4(lease);
631
632 // Check the valid lifetime has the default.
633 EXPECT_EQ(subnet_->getValid(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid()"
, "lease->valid_lft_", subnet_->getValid(), lease->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 633, gtest_ar.failure_message()) = ::testing::Message()
;
634
635 // The new lease has been allocated, so the old lease should not exist.
636 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 636, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
637
638 // Do it again, this should amount to the renew of an existing lease
639 Lease4Ptr lease2 = engine->allocateLease4(ctx);
640
641 // Check that we got a lease and it's sane
642 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 642, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
643 checkLease4(lease2);
644
645 // Lease already existed, so old_lease should be set.
646 EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 646, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
647
648 // Check the renewed valid lifetime has the default.
649 EXPECT_EQ(subnet_->getValid(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid()"
, "lease2->valid_lft_", subnet_->getValid(), lease2->
valid_lft_))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 649, gtest_ar.failure_message()) = ::testing::Message()
;
650}
651
652// This test checks simple renewal uses the specified valid lifetime.
653TEST_F(AllocEngine4Test, hintRenew4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("hintRenew4") > 1, "test_name must not be empty"
); class AllocEngine4Test_hintRenew4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_hintRenew4_Test() = default; ~AllocEngine4Test_hintRenew4_Test
() override = default; AllocEngine4Test_hintRenew4_Test (const
AllocEngine4Test_hintRenew4_Test &) = delete; AllocEngine4Test_hintRenew4_Test
& operator=( const AllocEngine4Test_hintRenew4_Test &
) = delete; AllocEngine4Test_hintRenew4_Test (AllocEngine4Test_hintRenew4_Test
&&) noexcept = delete; AllocEngine4Test_hintRenew4_Test
& operator=( AllocEngine4Test_hintRenew4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_hintRenew4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "hintRenew4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 653
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 653), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 653), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintRenew4_Test
>); void AllocEngine4Test_hintRenew4_Test::TestBody()
{
654 boost::scoped_ptr<AllocEngine> engine;
655 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_655
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_655
; } } else gtest_label_testnothrow_655 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 655, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
656 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
657
658 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
659 false, true, "somehost.example.com.", false);
660 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
661 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
662
663 // Specify the valid lifetime we want.
664 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4));
665 ctx.query_->addOption(opt);
666
667 Lease4Ptr lease = engine->allocateLease4(ctx);
668
669 // Check that we got a lease and it's sane
670 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 670, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
671 checkLease4(lease);
672
673 // Check the valid lifetime has the wanted value.
674 EXPECT_EQ(opt->getValue(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("opt->getValue()"
, "lease->valid_lft_", opt->getValue(), lease->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 674, gtest_ar.failure_message()) = ::testing::Message()
;
675
676 // The new lease has been allocated, so the old lease should not exist.
677 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 677, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
678
679 // Do it again, this should amount to the renew of an existing lease
680 Lease4Ptr lease2 = engine->allocateLease4(ctx);
681
682 // Check that we got a lease and it's sane
683 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 683, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
684 checkLease4(lease2);
685
686 // Lease already existed, so old_lease should be set.
687 EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 687, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
688
689 // Check the renewed valid lifetime has the wanted value.
690 EXPECT_EQ(opt->getValue(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("opt->getValue()"
, "lease2->valid_lft_", opt->getValue(), lease2->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 690, gtest_ar.failure_message()) = ::testing::Message()
;
691}
692
693// This test checks simple renewal uses the min valid lifetime.
694TEST_F(AllocEngine4Test, minRenew4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("minRenew4") > 1, "test_name must not be empty"
); class AllocEngine4Test_minRenew4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_minRenew4_Test() = default; ~AllocEngine4Test_minRenew4_Test
() override = default; AllocEngine4Test_minRenew4_Test (const
AllocEngine4Test_minRenew4_Test &) = delete; AllocEngine4Test_minRenew4_Test
& operator=( const AllocEngine4Test_minRenew4_Test &
) = delete; AllocEngine4Test_minRenew4_Test (AllocEngine4Test_minRenew4_Test
&&) noexcept = delete; AllocEngine4Test_minRenew4_Test
& operator=( AllocEngine4Test_minRenew4_Test &&)
noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_minRenew4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "minRenew4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 694
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 694), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 694), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minRenew4_Test
>); void AllocEngine4Test_minRenew4_Test::TestBody()
{
695 boost::scoped_ptr<AllocEngine> engine;
696 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_696
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_696
; } } else gtest_label_testnothrow_696 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 696, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
697 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 697, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
698
699 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
700 false, true, "somehost.example.com.", false);
701 subnet_->setValid(Triplet<uint32_t>(2, 3, 5));
702 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
703
704 // Specify the valid lifetime we want, as it is lower than the min value
705 // we'll get this min value instead.
706 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1));
707 ctx.query_->addOption(opt);
708
709 Lease4Ptr lease = engine->allocateLease4(ctx);
710
711 // Check that we got a lease and it's sane
712 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 712, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
713 checkLease4(lease);
714
715 // Check the valid lifetime has the min value.
716 EXPECT_EQ(subnet_->getValid().getMin(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMin()"
, "lease->valid_lft_", subnet_->getValid().getMin(), lease
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 716, gtest_ar.failure_message()) = ::testing::Message()
;
717
718 // The new lease has been allocated, so the old lease should not exist.
719 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 719, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
720
721 // Do it again, this should amount to the renew of an existing lease
722 Lease4Ptr lease2 = engine->allocateLease4(ctx);
723
724 // Check that we got a lease and it's sane
725 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 725, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
726 checkLease4(lease2);
727
728 // Lease already existed, so old_lease should be set.
729 EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 729, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
730
731 // Check the renewed valid lifetime has the min value.
732 EXPECT_EQ(subnet_->getValid().getMin(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMin()"
, "lease2->valid_lft_", subnet_->getValid().getMin(), lease2
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 732, gtest_ar.failure_message()) = ::testing::Message()
;
733}
734
735// This test checks simple renewal uses the max valid lifetime.
736TEST_F(AllocEngine4Test, maxRenew4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("maxRenew4") > 1, "test_name must not be empty"
); class AllocEngine4Test_maxRenew4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_maxRenew4_Test() = default; ~AllocEngine4Test_maxRenew4_Test
() override = default; AllocEngine4Test_maxRenew4_Test (const
AllocEngine4Test_maxRenew4_Test &) = delete; AllocEngine4Test_maxRenew4_Test
& operator=( const AllocEngine4Test_maxRenew4_Test &
) = delete; AllocEngine4Test_maxRenew4_Test (AllocEngine4Test_maxRenew4_Test
&&) noexcept = delete; AllocEngine4Test_maxRenew4_Test
& operator=( AllocEngine4Test_maxRenew4_Test &&)
noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_maxRenew4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "maxRenew4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 736
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 736), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 736), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxRenew4_Test
>); void AllocEngine4Test_maxRenew4_Test::TestBody()
{
737 boost::scoped_ptr<AllocEngine> engine;
738 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_738
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_738
; } } else gtest_label_testnothrow_738 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 738, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
739 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 739, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
740
741 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
742 false, true, "somehost.example.com.", false);
743 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
744 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
745
746 // Specify the valid lifetime we want, as it is greater than the max value
747 // we'll get this max value instead.
748 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6));
749 ctx.query_->addOption(opt);
750
751 Lease4Ptr lease = engine->allocateLease4(ctx);
752
753 // Check that we got a lease and it's sane
754 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 754, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
755 checkLease4(lease);
756
757 // Check the valid lifetime has the max value.
758 EXPECT_EQ(subnet_->getValid().getMax(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMax()"
, "lease->valid_lft_", subnet_->getValid().getMax(), lease
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 758, gtest_ar.failure_message()) = ::testing::Message()
;
759
760 // The new lease has been allocated, so the old lease should not exist.
761 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 761, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
762
763 // Do it again, this should amount to the renew of an existing lease
764 Lease4Ptr lease2 = engine->allocateLease4(ctx);
765
766 // Check that we got a lease and it's sane
767 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 767, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
768 checkLease4(lease2);
769
770 // Lease already existed, so old_lease should be set.
771 EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 771, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
772
773 // Check the renewed valid lifetime has the max value.
774 EXPECT_EQ(subnet_->getValid().getMax(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMax()"
, "lease2->valid_lft_", subnet_->getValid().getMax(), lease2
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 774, gtest_ar.failure_message()) = ::testing::Message()
;
775}
776
777// This test checks simple renewal handles BOOTP queries.
778TEST_F(AllocEngine4Test, bootpRenew4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("bootpRenew4") > 1, "test_name must not be empty"
); class AllocEngine4Test_bootpRenew4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_bootpRenew4_Test() = default; ~AllocEngine4Test_bootpRenew4_Test
() override = default; AllocEngine4Test_bootpRenew4_Test (const
AllocEngine4Test_bootpRenew4_Test &) = delete; AllocEngine4Test_bootpRenew4_Test
& operator=( const AllocEngine4Test_bootpRenew4_Test &
) = delete; AllocEngine4Test_bootpRenew4_Test (AllocEngine4Test_bootpRenew4_Test
&&) noexcept = delete; AllocEngine4Test_bootpRenew4_Test
& operator=( AllocEngine4Test_bootpRenew4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_bootpRenew4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "bootpRenew4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 778
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 778), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 778), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpRenew4_Test
>); void AllocEngine4Test_bootpRenew4_Test::TestBody()
{
779 boost::scoped_ptr<AllocEngine> engine;
780 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_780
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_780
; } } else gtest_label_testnothrow_780 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 780, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
781 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 781, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
782
783 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
784 false, true, "somehost.example.com.", false);
785 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
786 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
787
788 // Make the query a BOOTP one.
789 ctx.query_->addClass("BOOTP");
790
791 Lease4Ptr lease = engine->allocateLease4(ctx);
792
793 // Check that we got a lease.
794 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 794, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
795
796 // Check that is belongs to the right subnet and client.
797 EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet_->getID()", lease->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 797, gtest_ar.failure_message()) = ::testing::Message()
;
798 EXPECT_TRUE(subnet_->inRange(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease
->addr_))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 798, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
799 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 799, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
800 ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->client_id_)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
801 EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 801, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
802 ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 802, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
803 EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
804
805 // Check the valid lifetime is infinite.
806 uint32_t infinity_lft = Lease::INFINITY_LFT;
807 EXPECT_EQ(infinity_lft, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("infinity_lft"
, "lease->valid_lft_", infinity_lft, lease->valid_lft_)
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 807, gtest_ar.failure_message()) = ::testing::Message()
;
808
809 // The new lease has been allocated, so the old lease should not exist.
810 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 810, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
811
812 // Do it again, this should amount to the renew of an existing lease
813 Lease4Ptr lease2 = engine->allocateLease4(ctx);
814
815 // Check that we got a lease.
816 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 816, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
817
818 // Check that is belongs to the right subnet and client.
819 EXPECT_EQ(lease2->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease2->subnet_id_"
, "subnet_->getID()", lease2->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 819, gtest_ar.failure_message()) = ::testing::Message()
;
820 EXPECT_TRUE(subnet_->inRange(lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease2
->addr_))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 820, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease2->addr_)", "false", "true") .
c_str()) = ::testing::Message()
;
821 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, lease2->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 821, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, lease2->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
822 ASSERT_TRUE(lease2->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2->client_id_
)) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 822, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
823 EXPECT_TRUE(*lease2->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease2->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 823, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease2->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
824 ASSERT_TRUE(lease2->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 824, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
825 EXPECT_TRUE(*lease2->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease2->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 825, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease2->hwaddr_ == *hwaddr_", "false", "true") .c_str(
)) = ::testing::Message()
;
826
827 // Lease already existed, so old_lease should be set.
828 EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
829
830 // Check the renewed valid lifetime has the max value.
831 EXPECT_EQ(infinity_lft, lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("infinity_lft"
, "lease2->valid_lft_", infinity_lft, lease2->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 831, gtest_ar.failure_message()) = ::testing::Message()
;
832}
833
834// This test checks if really small pools are working
835TEST_F(AllocEngine4Test, smallPool4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("smallPool4") > 1, "test_name must not be empty"
); class AllocEngine4Test_smallPool4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_smallPool4_Test() = default; ~AllocEngine4Test_smallPool4_Test
() override = default; AllocEngine4Test_smallPool4_Test (const
AllocEngine4Test_smallPool4_Test &) = delete; AllocEngine4Test_smallPool4_Test
& operator=( const AllocEngine4Test_smallPool4_Test &
) = delete; AllocEngine4Test_smallPool4_Test (AllocEngine4Test_smallPool4_Test
&&) noexcept = delete; AllocEngine4Test_smallPool4_Test
& operator=( AllocEngine4Test_smallPool4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_smallPool4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "smallPool4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 835
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 835), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 835), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_smallPool4_Test
>); void AllocEngine4Test_smallPool4_Test::TestBody()
{
836 boost::scoped_ptr<AllocEngine> engine;
837 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_837
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_837
; } } else gtest_label_testnothrow_837 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 837, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
838 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 838, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
839
840 IOAddress addr("192.0.2.17");
841 CfgMgr& cfg_mgr = CfgMgr::instance();
842
843 // Get rid of the default subnet configuration.
844 cfg_mgr.clear();
845
846 // Create configuration similar to other tests, but with a single address pool
847 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
848 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
849 subnet_->addPool(pool_);
850 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
851
852 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
853 IOAddress("0.0.0.0"), false, false,
854 "host.example.com.", false);
855 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
856 Lease4Ptr lease = engine->allocateLease4(ctx);
857
858 // Check that we got that single lease
859 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
860
861 // We have allocated new lease, so the old lease should not exist.
862 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 862, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
863
864 EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\""
, "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 864, gtest_ar.failure_message()) = ::testing::Message()
;
865
866 // Do all checks on the lease
867 checkLease4(lease);
868
869 // Check that the lease is indeed in LeaseMgr
870 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
871 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 871, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
872
873 // Now check that the lease in LeaseMgr has the same parameters
874 detailCompareLease(lease, from_mgr);
875}
876
877// This test checks if all addresses in a pool are currently used, the attempt
878// to find out a new lease fails.
879TEST_F(AllocEngine4Test, outOfAddresses4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("outOfAddresses4") > 1, "test_name must not be empty"
); class AllocEngine4Test_outOfAddresses4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_outOfAddresses4_Test() = default;
~AllocEngine4Test_outOfAddresses4_Test() override = default;
AllocEngine4Test_outOfAddresses4_Test (const AllocEngine4Test_outOfAddresses4_Test
&) = delete; AllocEngine4Test_outOfAddresses4_Test &
operator=( const AllocEngine4Test_outOfAddresses4_Test &
) = delete; AllocEngine4Test_outOfAddresses4_Test (AllocEngine4Test_outOfAddresses4_Test
&&) noexcept = delete; AllocEngine4Test_outOfAddresses4_Test
& operator=( AllocEngine4Test_outOfAddresses4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_outOfAddresses4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "outOfAddresses4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 879
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 879), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 879), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_outOfAddresses4_Test
>); void AllocEngine4Test_outOfAddresses4_Test::TestBody()
{
880 boost::scoped_ptr<AllocEngine> engine;
881 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_881
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_881
; } } else gtest_label_testnothrow_881 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 881, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
882 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 882, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
883
884 IOAddress addr("192.0.2.17");
885 CfgMgr& cfg_mgr = CfgMgr::instance();
886 // Get rid of the default test configuration.
887 cfg_mgr.clear();
888
889 // Create configuration similar to other tests, but with a single address pool
890 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
891 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
892 subnet_->addPool(pool_);
893 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
894
895 // Just a different hw/client-id for the second client
896 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
897 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
898 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
899 time_t now = time(NULL__null);
900 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2,
901 sizeof(clientid2), 501, now,
902 subnet_->getID()));
903 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
904 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 904, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
905
906 // There is just a single address in the pool and allocated it to someone
907 // else, so the allocation should fail
908
909 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
910 IOAddress("0.0.0.0"), false, false,
911 "host.example.com.", false);
912 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
913 Lease4Ptr lease2 = engine->allocateLease4(ctx);
914 ASSERT_FALSE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease2))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 914, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "true", "false") .c_str()) = ::testing::Message()
;
915 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 915, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
916
917 EXPECT_EQ(1, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\")"
, 1, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
917, gtest_ar.failure_message()) = ::testing::Message()
;
918 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 918, gtest_ar.failure_message()) = ::testing::Message()
;
919 EXPECT_EQ(1, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-subnet\")"
, 1, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
919, gtest_ar.failure_message()) = ::testing::Message()
;
920 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
920, gtest_ar.failure_message()) = ::testing::Message()
;
921 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
921, gtest_ar.failure_message()) = ::testing::Message()
;
922
923 EXPECT_EQ(1, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 1, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 923, gtest_ar.failure_message()) = ::testing::Message()
;
924 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 924, gtest_ar.failure_message()) = ::testing::Message()
;
925 EXPECT_EQ(1, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 1, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 925, gtest_ar.failure_message()) = ::testing::Message()
;
926 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 926, gtest_ar.failure_message()) = ::testing::Message()
;
927 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 927, gtest_ar.failure_message()) = ::testing::Message()
;
928}
929
930/// @brief This test class is dedicated to testing shared networks
931///
932/// It uses one common configuration:
933/// 1 shared network with 2 subnets:
934/// - 192.0.2.0/24 subnet with a small pool of single address: 192.0.2.17
935/// - 10.1.2.0/24 subnet with pool with 96 addresses.
936class SharedNetworkAlloc4Test : public AllocEngine4Test {
937public:
938
939 /// @brief Initializes configuration (2 subnets, 1 shared network)
940 SharedNetworkAlloc4Test() : engine_(0) {
941 // Create two subnets, each with a single address pool. The first subnet
942 // has only one address in its address pool to make it easier to simulate
943 // address exhaustion.
944 subnet1_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
945 subnet2_ = Subnet4::create(IOAddress("10.1.2.0"), 24, 1, 2, 3, SubnetID(20));
946 pool1_.reset(new Pool4(IOAddress("192.0.2.17"), IOAddress("192.0.2.17")));
947 pool2_.reset(new Pool4(IOAddress("10.1.2.5"), IOAddress("10.1.2.100")));
948
949 subnet1_->addPool(pool1_);
950 subnet2_->addPool(pool2_);
951
952 // Both subnets belong to the same network so they can be used
953 // interchangeably.
954 network_.reset(new SharedNetwork4("test_network"));
955 network_->add(subnet1_);
956 network_->add(subnet2_);
957
958 std::vector<uint8_t> hwaddr_vec = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
959 hwaddr2_.reset(new HWAddr(hwaddr_vec, HTYPE_ETHER));
960 }
961
962 /// @brief Inserts a new lease for specified address
963 ///
964 /// Creates a new lease for specified address and subnet-id and inserts
965 /// it into database. This is not particularly fancy method, it is used
966 /// just to mark existing addresses as used. It uses hwaddr2_ to allocate
967 /// the lease.
968 ///
969 /// @param addr text representation of the address
970 /// @param subnet_id ID of the subnet
971 /// @param return pointer to the lease
972 Lease4Ptr
973 insertLease(std::string addr, SubnetID subnet_id) {
974 Lease4Ptr lease(new Lease4(IOAddress(addr), hwaddr2_, ClientIdPtr(),
975 501, time(NULL__null), subnet_id));
976 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
977 if (!LeaseMgrFactory::instance().addLease(lease)) {
978 ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 978, "Failed") = ::testing::Message()
<< "Attempt to add a lease for IP " << addr
979 << " in subnet " << subnet_id << " failed";
980 }
981
982 return (lease);
983 }
984
985 /// @brief Test host order of precedence in shared-network
986 ///
987 /// Creates global and shared-network subnet host reservations,
988 /// with or without addresses, and attempts to allocate a lease.
989 /// The resultant lease is then tested to have the expected subnet
990 /// and address.
991 ///
992 ///
993 /// @param include_global_host create a global host when true
994 /// @param global_host_address address to use in the global host reservation or
995 /// none if it is IPV4_ZERO_ADDRESS.
996 /// @param include_subnet_host create a subnet host when true
997 /// @param subnet_host_subnet_id id of the subnet to which the subnet host should
998 /// be added.
999 /// @param subnet_host_address address to use in the subnet host reservation or
1000 /// none if it is IPV4_ZERO_ADDRESS.
1001 /// @param exp_subnet expected subnet of the resultant lease.
1002 /// @param exp_address expected address of the resultant lease.
1003 /// @param fake_allocation tests the DISCOVER code path when true, REQUEST when
1004 /// false.
1005 void globalResVsSubnetRes(bool include_global_host, IOAddress global_host_address,
1006 bool include_subnet_host, SubnetID subnet_host_subnet_id,
1007 IOAddress subnet_host_address, SubnetID exp_subnet,
1008 IOAddress exp_address, bool fake_allocation = true) {
1009 EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance()
.getDisableSingleQuery()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1009, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1010
1011 HostPtr global_host;
1012 if (include_global_host) {
1013 // Create global reservation for the client in subnet2.
1014 global_host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1015 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
1016 SUBNET_ID_UNUSED, global_host_address));
1017
1018 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(global_host);
1019 }
1020
1021 // Create subnet reservation for the client in subnet2.
1022 HostPtr subnet_host;
1023 if (include_subnet_host) {
1024 subnet_host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1025 Host::IDENT_HWADDR, subnet_host_subnet_id,
1026 SUBNET_ID_UNUSED, subnet_host_address));
1027
1028 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(subnet_host);
1029 }
1030
1031 CfgMgr::instance().commit();
1032
1033 subnet1_->setReservationsGlobal(true);
1034 subnet1_->setReservationsInSubnet(true);
1035 subnet2_->setReservationsGlobal(true);
1036 subnet2_->setReservationsInSubnet(true);
1037
1038 // Start allocation from subnet1.
1039 AllocEngine::ClientContext4
1040 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1041 false, false, "host.example.com.", true);
1042
1043 ctx.fake_allocation_ = fake_allocation;
1044 if (fake_allocation) {
1045 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1046 } else {
1047 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1048 }
1049
1050 AllocEngine::findReservation(ctx);
1051 Lease4Ptr lease = engine_.allocateLease4(ctx);
1052 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1052, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1053 EXPECT_EQ(exp_subnet, lease->subnet_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("exp_subnet"
, "lease->subnet_id_", exp_subnet, lease->subnet_id_)))
; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1053, gtest_ar.failure_message()) = ::testing::Message()
;
1054 EXPECT_EQ(exp_address, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("exp_address"
, "lease->addr_", exp_address, lease->addr_))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
1054, gtest_ar.failure_message()) = ::testing::Message()
;
1055
1056 if (!fake_allocation) {
1057 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1057, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1058 }
1059 }
1060
1061 /// Convenience pointers to configuration elements. These are initialized
1062 /// in the constructor and are used throughout the tests.
1063 AllocEngine engine_;
1064 Subnet4Ptr subnet1_;
1065 Subnet4Ptr subnet2_;
1066 Pool4Ptr pool1_;
1067 Pool4Ptr pool2_;
1068 SharedNetwork4Ptr network_;
1069
1070 HWAddrPtr hwaddr2_; // Note there's hwaddr_ already defined in base class.
1071};
1072
1073// This test verifies that the server can offer an address from a
1074// subnet and the introduction of shared network doesn't break anything here.
1075TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkSimple)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetworkSimple") > 1
, "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
(const SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
(SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test &&
) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetworkSimple", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1075), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1075), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1075), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
::TestBody()
{
1076
1077 // Create context which will be used to try to allocate leases from the
1078 // shared network. The context points to subnet1, which address space
1079 // is exhausted. We expect the allocation engine to find another subnet
1080 // within the same shared network and offer an address from there.
1081 AllocEngine::ClientContext4
1082 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1083 false, false, "host.example.com.", true);
1084 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1085 Lease4Ptr lease = engine_.allocateLease4(ctx);
1086
1087 // The allocation engine should have assigned an address from the first
1088 // subnet.
1089 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1089, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1090 EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\""
, "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1090, gtest_ar.failure_message()) = ::testing::Message()
;
1091
1092 // Make sure the lease is not in the lease mgr (this is only
1093 // discover).
1094 ASSERT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1094, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
1095}
1096
1097// This test verifies that the server will pick a second subnet out of two
1098// shared subnets if there is a hint for the second subnet.
1099TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkHint)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetworkHint") > 1, "test_name must not be empty"
); class SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
(const SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
(SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test &&
) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetworkHint", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1099), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1099), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1099), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
::TestBody()
{
1100
1101 // Create context which will be used to try to allocate leases from the
1102 // shared network. The context points to subnet1, which address space
1103 // is exhausted. We expect the allocation engine to find another subnet
1104 // within the same shared network and offer an address from there.
1105
1106 AllocEngine::ClientContext4
1107 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress("10.1.2.25"),
1108 false, false, "host.example.com.", true);
1109 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1110 Lease4Ptr lease = engine_.allocateLease4(ctx);
1111
1112 // The allocation engine should have assigned an address from the second
1113 // subnet, because that's what the hint requested.
1114 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1114, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1115 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1115, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1116}
1117
1118// This test verifies that the server can offer an address from a
1119// different subnet than orginally selected, when the address pool in
1120// the first subnet is exhausted.
1121TEST_F(SharedNetworkAlloc4Test, discoverSharedNetwork)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetwork") > 1, "test_name must not be empty"
); class SharedNetworkAlloc4Test_discoverSharedNetwork_Test :
public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetwork_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetwork_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetwork_Test
(const SharedNetworkAlloc4Test_discoverSharedNetwork_Test &
) = delete; SharedNetworkAlloc4Test_discoverSharedNetwork_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetwork_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetwork_Test
(SharedNetworkAlloc4Test_discoverSharedNetwork_Test &&
) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetwork_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetwork_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetwork_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetwork", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1121), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1121), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1121), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetwork_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetwork_Test
::TestBody()
{
1122 // Create a lease for a single address in the first address pool. The
1123 // pool is now exhausted.
1124 Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID());
1125
1126 // Create context which will be used to try to allocate leases from the
1127 // shared network. The context points to subnet1, which address space
1128 // is exhausted. We expect the allocation engine to find another subnet
1129 // within the same shared network and offer an address from there.
1130 AllocEngine::ClientContext4
1131 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1132 false, false, "host.example.com.", true);
1133 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1134 Lease4Ptr lease2 = engine_.allocateLease4(ctx);
1135 // The allocation engine should have assigned an address from the second
1136 // subnet. We could guess that this is 10.1.2.5, being the first address
1137 // in the address pool, but to make the test more generic, we merely
1138 // verify that the address is in the given address pool.
1139 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1140 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease2->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1140, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1141
1142 // The client should also be offered a lease when it specifies a hint
1143 // that doesn't match the subnet from which the lease is offered. The
1144 // engine should check alternative subnets to match the hint to
1145 // a subnet. The requested lease is available, so it should be offered.
1146 ctx.subnet_ = subnet1_;
1147 ctx.requested_address_ = IOAddress("10.1.2.25");
1148 lease2 = engine_.allocateLease4(ctx);
1149 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1149, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1150 EXPECT_EQ("10.1.2.25", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.25\""
, "lease2->addr_.toText()", "10.1.2.25", lease2->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1150, gtest_ar.failure_message()) = ::testing::Message()
;
1151
1152 // The returning client (the one that has a lease) should also be able
1153 // to renew its lease regardless of a subnet it begins with. So, it has
1154 // an address assigned from subnet1, but we use subnet2 as a selected
1155 // subnet.
1156 AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_,
1157 IOAddress("0.0.0.0"), false, false,
1158 "host.example.com.", true);
1159 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1160 lease2 = engine_.allocateLease4(ctx2);
1161 // The existing lease should be returned.
1162 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1162, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1163 EXPECT_EQ("192.0.2.17", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\""
, "lease2->addr_.toText()", "192.0.2.17", lease2->addr_
.toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1163, gtest_ar.failure_message()) = ::testing::Message()
;
1164}
1165
1166// This test verifies that the server can offer an address from a
1167// different subnet than orginally selected, when the address pool in
1168// the first subnet is exhausted.
1169TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkClassification)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetworkClassification"
) > 1, "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
(const SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
(SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetworkClassification", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1169), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1169), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1169), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
::TestBody()
{
1170
1171 // Try to offer address from subnet1. There is one address available
1172 // so it should be offered.
1173 AllocEngine::ClientContext4
1174 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1175 false, false, "host.example.com.", true);
1176 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1177 Lease4Ptr lease = engine_.allocateLease4(ctx);
1178 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1178, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1179 EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1179, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1180
1181 // Apply restrictions on the subnet1. This should be only assigned
1182 // to clients belonging to cable-modem class.
1183 subnet1_->allowClientClass("cable-modem");
1184
1185 // The allocation engine should determine that the subnet1 is not
1186 // available for the client not belonging to the cable-modem class.
1187 // Instead, it should offer an address from subnet2 that belongs
1188 // to the same shared network.
1189 ctx.subnet_ = subnet1_;
1190 lease = engine_.allocateLease4(ctx);
1191 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1191, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1192 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1192, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1193
1194 // Create reservation for the client in subnet1. Because this subnet is
1195 // not allowed for the client the client should still be offered a
1196 // lease from subnet2.
1197 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1198 Host::IDENT_HWADDR, subnet1_->getID(),
1199 SUBNET_ID_UNUSED, IOAddress("192.0.2.17")));
1200 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1201 CfgMgr::instance().commit();
1202 AllocEngine::findReservation(ctx);
1203
1204 ctx.subnet_ = subnet1_;
1205 lease = engine_.allocateLease4(ctx);
1206 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1206, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1207 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1207, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1208
1209 // Assign cable-modem class and try again. This time, we should
1210 // offer an address from the subnet1.
1211 ctx.query_->addClass(ClientClass("cable-modem"));
1212
1213 ctx.subnet_ = subnet1_;
1214 lease = engine_.allocateLease4(ctx);
1215 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1215, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1216 EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\""
, "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1216, gtest_ar.failure_message()) = ::testing::Message()
;
1217}
1218
1219// This test verifies that the server can offer an address from a
1220// different subnet than orginally selected, when the address pool in
1221// the first subnet requires another class.
1222TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkPoolClassification)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetworkPoolClassification"
) > 1, "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
(const SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
(SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetworkPoolClassification", nullptr, nullptr
, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1222), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1222), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1222), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
::TestBody()
{
1223
1224 // Try to offer address from subnet1. There is one address available
1225 // so it should be offered.
1226 AllocEngine::ClientContext4
1227 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1228 false, false, "host.example.com.", true);
1229 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1230 Lease4Ptr lease = engine_.allocateLease4(ctx);
1231 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1231, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1232 EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1232, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1233
1234 // Apply restrictions on the pool1. This should be only assigned
1235 // to clients belonging to cable-modem class.
1236 pool1_->allowClientClass("cable-modem");
1237
1238 // The allocation engine should determine that the pool1 is not
1239 // available for the client not belonging to the cable-modem class.
1240 // Instead, it should offer an address from subnet2 that belongs
1241 // to the same shared network.
1242 ctx.subnet_ = subnet1_;
1243 lease = engine_.allocateLease4(ctx);
1244 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1244, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1245 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1245, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1246
1247 // Assign cable-modem class and try again. This time, we should
1248 // offer an address from the pool1.
1249 ctx.query_->addClass(ClientClass("cable-modem"));
1250
1251 // Restrict access to pool2 for this client, to make sure that the
1252 // server doesn't accidentally get an address from this pool.
1253 pool2_->allowClientClass("telephone");
1254
1255 ctx.subnet_ = subnet1_;
1256 lease = engine_.allocateLease4(ctx);
1257 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1257, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1258 EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\""
, "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1258, gtest_ar.failure_message()) = ::testing::Message()
;
1259}
1260
1261// Test that global reservations within shared network take precedence over the
1262// existing leases regardless in which subnet belonging to a shared network
1263// reservations belong.
1264TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkReservationsGlobal)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetworkReservationsGlobal"
) > 1, "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
(const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
(SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetworkReservationsGlobal", nullptr, nullptr
, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1264), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1264), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1264), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
::TestBody()
{
1265
1266 EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance()
.getDisableSingleQuery()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1266, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1267
1268 // Create reservation for the client.
1269 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1270 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
1271 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1272 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1273 CfgMgr::instance().commit();
1274
1275 subnet1_->setReservationsGlobal(true);
1276 subnet1_->setReservationsInSubnet(true);
1277 subnet2_->setReservationsGlobal(true);
1278 subnet2_->setReservationsInSubnet(true);
1279
1280 // Start allocation from subnet1. The engine should determine that the
1281 // client has global reservations within subnet2 and should rather
1282 // assign reserved addresses.
1283 AllocEngine::ClientContext4
1284 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1285 false, false, "host.example.com.", true);
1286 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1287 AllocEngine::findReservation(ctx);
1288 Lease4Ptr lease = engine_.allocateLease4(ctx);
1289 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1289, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1290 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1290, gtest_ar.failure_message()) = ::testing::Message()
;
1291 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1291, gtest_ar.failure_message()) = ::testing::Message()
;
1292
1293 // Let's create a lease for the client to make sure the lease is not
1294 // renewed but a reserved lease is offered.
1295 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1296 501, time(NULL__null), subnet1_->getID()));
1297 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1298 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1299 ctx.subnet_ = subnet1_;
1300 ctx.hosts_.clear();
1301 AllocEngine::findReservation(ctx);
1302 lease = engine_.allocateLease4(ctx);
1303 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1303, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1304 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1304, gtest_ar.failure_message()) = ::testing::Message()
;
1305 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1305, gtest_ar.failure_message()) = ::testing::Message()
;
1306}
1307
1308
1309// Test that reservations within shared network take precedence over the
1310// existing leases regardless in which subnet belonging to a shared network
1311// reservations belong.
1312TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkReservations)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetworkReservations") >
1, "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
(const SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
(SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetworkReservations", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1312), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1312), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1312), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
::TestBody()
{
1313
1314 EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance()
.getDisableSingleQuery()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1314, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1315
1316 // Create reservation for the client.
1317 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1318 Host::IDENT_HWADDR, subnet2_->getID(),
1319 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1320 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1321 CfgMgr::instance().commit();
1322
1323 // Start allocation from subnet1. The engine should determine that the
1324 // client has reservations in subnet2 and should rather assign reserved
1325 // addresses.
1326 AllocEngine::ClientContext4
1327 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1328 false, false, "host.example.com.", true);
1329 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1330 AllocEngine::findReservation(ctx);
1331 Lease4Ptr lease = engine_.allocateLease4(ctx);
1332 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1332, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1333 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1333, gtest_ar.failure_message()) = ::testing::Message()
;
1334 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1334, gtest_ar.failure_message()) = ::testing::Message()
;
1335
1336 // Let's create a lease for the client in subnet1 to make sure the lease
1337 // is not renewed but a reserved lease is offered.
1338 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1339 501, time(NULL__null), subnet1_->getID()));
1340 lease2->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1341 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1341, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1342 ctx.subnet_ = subnet1_;
1343 ctx.hosts_.clear();
1344 AllocEngine::findReservation(ctx);
1345 lease = engine_.allocateLease4(ctx);
1346 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1346, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1347 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1347, gtest_ar.failure_message()) = ::testing::Message()
;
1348 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1348, gtest_ar.failure_message()) = ::testing::Message()
;
1349
1350 // Let's create a lease for the client in subnet2 to make sure the lease
1351 // is not renewed but a reserved lease is offered.
1352 Lease4Ptr lease3(new Lease4(IOAddress("10.1.2.55"), hwaddr_, ClientIdPtr(),
1353 501, time(NULL__null), subnet2_->getID()));
1354 lease3->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1355 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease3))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease3))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1355, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease3)", "false", "true"
) .c_str()) = ::testing::Message()
;
1356 ctx.subnet_ = subnet1_;
1357 ctx.hosts_.clear();
1358 AllocEngine::findReservation(ctx);
1359 lease = engine_.allocateLease4(ctx);
1360 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1360, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1361 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1361, gtest_ar.failure_message()) = ::testing::Message()
;
1362 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1362, gtest_ar.failure_message()) = ::testing::Message()
;
1363}
1364
1365
1366// Test that reservations within shared network take precedence over the
1367// existing leases regardless in which subnet belonging to a shared network
1368// reservations belong. Host lookups returning a collection are disabled.
1369// As it is only an optimization the behavior (so the test) must stay
1370// unchanged.
1371TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkReservationsNoColl)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverSharedNetworkReservationsNoColl"
) > 1, "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
() = default; ~SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
() override = default; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
(const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
& operator=( const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
&) = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
(SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
& operator=( SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverSharedNetworkReservationsNoColl", nullptr, nullptr
, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1371), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1371), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1371), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
::TestBody()
{
1372
1373 // Disable host lookups returning a collection.
1374 ASSERT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance()
.getDisableSingleQuery()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1374, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1375 HostMgr::instance().setDisableSingleQuery(true);
1376
1377 // Create reservation for the client.
1378 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1379 Host::IDENT_HWADDR, subnet2_->getID(),
1380 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1381 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1382 CfgMgr::instance().commit();
1383
1384 subnet1_->setReservationsGlobal(true);
1385 subnet1_->setReservationsInSubnet(true);
1386 subnet2_->setReservationsGlobal(true);
1387 subnet2_->setReservationsInSubnet(true);
1388
1389 // Start allocation from subnet1. The engine should determine that the
1390 // client has reservations in subnet2 and should rather assign reserved
1391 // addresses.
1392 AllocEngine::ClientContext4
1393 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1394 false, false, "host.example.com.", true);
1395 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1396 AllocEngine::findReservation(ctx);
1397 Lease4Ptr lease = engine_.allocateLease4(ctx);
1398 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1398, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1399 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1399, gtest_ar.failure_message()) = ::testing::Message()
;
1400 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1400, gtest_ar.failure_message()) = ::testing::Message()
;
1401
1402 // Let's create a lease for the client to make sure the lease is not
1403 // renewed but a reserved lease is offered.
1404 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1405 501, time(NULL__null), subnet1_->getID()));
1406 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1407 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1407, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1408 ctx.subnet_ = subnet1_;
1409 ctx.hosts_.clear();
1410 AllocEngine::findReservation(ctx);
1411 lease = engine_.allocateLease4(ctx);
1412 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1412, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1413 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1413, gtest_ar.failure_message()) = ::testing::Message()
;
1414 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1414, gtest_ar.failure_message()) = ::testing::Message()
;
1415}
1416
1417// This test verifies that the server can offer an address from a shared
1418// subnet if there's at least 1 address left there, but will not offer
1419// anything if both subnets are completely full.
1420TEST_F(SharedNetworkAlloc4Test, runningOut)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("runningOut") > 1, "test_name must not be empty"
); class SharedNetworkAlloc4Test_runningOut_Test : public SharedNetworkAlloc4Test
{ public: SharedNetworkAlloc4Test_runningOut_Test() = default
; ~SharedNetworkAlloc4Test_runningOut_Test() override = default
; SharedNetworkAlloc4Test_runningOut_Test (const SharedNetworkAlloc4Test_runningOut_Test
&) = delete; SharedNetworkAlloc4Test_runningOut_Test &
operator=( const SharedNetworkAlloc4Test_runningOut_Test &
) = delete; SharedNetworkAlloc4Test_runningOut_Test (SharedNetworkAlloc4Test_runningOut_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_runningOut_Test
& operator=( SharedNetworkAlloc4Test_runningOut_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const SharedNetworkAlloc4Test_runningOut_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "runningOut", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 1420
), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1420), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1420), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_runningOut_Test
>); void SharedNetworkAlloc4Test_runningOut_Test::TestBody
()
{
1421
1422 // Allocate everything in subnet1
1423 insertLease("192.0.2.17", subnet1_->getID());
1424
1425 // Allocate everything, except one address in subnet2.
1426 for (int i = 5; i < 100; i++) {
1427 stringstream tmp;
1428 tmp << "10.1.2." << i;
1429 insertLease(tmp.str(), subnet2_->getID());
1430 }
1431
1432 // Create context which will be used to try to allocate leases from the
1433 // shared network. The context points to subnet1, which address space
1434 // is exhausted. We expect the allocation engine to find another subnet
1435 // within the same shared network and offer an address from there.
1436 AllocEngine::ClientContext4
1437 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1438 false, false, "host.example.com.", true);
1439 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1440 Lease4Ptr lease = engine_.allocateLease4(ctx);
1441 EXPECT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
1441, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1442
1443 // Now allocate the last address. Now both subnets are exhausted.
1444 insertLease("10.1.2.100", subnet2_->getID());
1445
1446 // Ok, we're out. We should not get anything now.
1447 lease = engine_.allocateLease4(ctx);
1448 ASSERT_FALSE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1448, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
1449
1450 EXPECT_EQ(1, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\")"
, 1, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
1450, gtest_ar.failure_message()) = ::testing::Message()
;
1451 EXPECT_EQ(1, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 1, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1451, gtest_ar.failure_message()) = ::testing::Message()
;
1452 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
1452, gtest_ar.failure_message()) = ::testing::Message()
;
1453 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
1453, gtest_ar.failure_message()) = ::testing::Message()
;
1454 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
1454, gtest_ar.failure_message()) = ::testing::Message()
;
1455
1456 EXPECT_EQ(1, getStatistics("v4-allocation-fail", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\", subnet1_->getID())"
, 1, getStatistics("v4-allocation-fail", subnet1_->getID()
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1456, gtest_ar.failure_message()) = ::testing::Message()
;
1457 EXPECT_EQ(1, getStatistics("v4-allocation-fail-shared-network", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-shared-network\", subnet1_->getID())"
, 1, getStatistics("v4-allocation-fail-shared-network", subnet1_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1457, gtest_ar.failure_message()) = ::testing::Message()
;
1458 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet1_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet1_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1458, gtest_ar.failure_message()) = ::testing::Message()
;
1459 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet1_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet1_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1459, gtest_ar.failure_message()) = ::testing::Message()
;
1460 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet1_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet1_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1460, gtest_ar.failure_message()) = ::testing::Message()
;
1461}
1462
1463// This test verifies that the server can offer an address from a
1464// subnet and the introduction of shared network doesn't break anything here.
1465TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkSimple)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestSharedNetworkSimple") > 1,
"test_name must not be empty"); class SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
() = default; ~SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
() override = default; SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
(const SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
& operator=( const SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
(SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test &&
) noexcept = delete; SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
& operator=( SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "requestSharedNetworkSimple", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1465), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1465), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1465), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
::TestBody()
{
1466
1467 // Create context which will be used to try to allocate leases from the
1468 // shared network. The context points to subnet1, which address space
1469 // is exhausted. We expect the allocation engine to find another subnet
1470 // within the same shared network and offer an address from there.
1471 AllocEngine::ClientContext4
1472 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1473 false, false, "host.example.com.", false);
1474 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1475 Lease4Ptr lease = engine_.allocateLease4(ctx);
1476
1477 // The allocation engine should have assigned an address from the first
1478 // subnet.
1479 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1479, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1480 EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\""
, "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1480, gtest_ar.failure_message()) = ::testing::Message()
;
1481
1482 // Make sure the lease is in the lease mgr.
1483 ASSERT_TRUE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().getLease4(lease->addr_))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1483, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1484}
1485
1486// This test verifies that the server can allocate an address from a
1487// different subnet than orginally selected, when the address pool in
1488// the first subnet is exhausted.
1489TEST_F(SharedNetworkAlloc4Test, requestSharedNetwork)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestSharedNetwork") > 1, "test_name must not be empty"
); class SharedNetworkAlloc4Test_requestSharedNetwork_Test : public
SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestSharedNetwork_Test
() = default; ~SharedNetworkAlloc4Test_requestSharedNetwork_Test
() override = default; SharedNetworkAlloc4Test_requestSharedNetwork_Test
(const SharedNetworkAlloc4Test_requestSharedNetwork_Test &
) = delete; SharedNetworkAlloc4Test_requestSharedNetwork_Test
& operator=( const SharedNetworkAlloc4Test_requestSharedNetwork_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetwork_Test
(SharedNetworkAlloc4Test_requestSharedNetwork_Test &&
) noexcept = delete; SharedNetworkAlloc4Test_requestSharedNetwork_Test
& operator=( SharedNetworkAlloc4Test_requestSharedNetwork_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetwork_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "requestSharedNetwork", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1489), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1489), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1489), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetwork_Test
>); void SharedNetworkAlloc4Test_requestSharedNetwork_Test
::TestBody()
{
1490
1491 // Create a lease for a single address in the first address pool. The
1492 // pool is now exhausted.
1493 Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID());
1494
1495 // Create context which will be used to try to allocate leases from the
1496 // shared network. The context points to subnet1, which address space
1497 // is exhausted. We expect the allocation engine to find another subnet
1498 // within the same shared network and offer an address from there.
1499 AllocEngine::ClientContext4
1500 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1501 false, false, "host.example.com.", false);
1502 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1503 Lease4Ptr lease2 = engine_.allocateLease4(ctx);
1504 // The allocation engine should have assigned an address from the second
1505 // subnet. We could guess that this is 10.1.2.5, being the first address
1506 // in the address pool, but to make the test more generic, we merely
1507 // verify that the address is in the given address pool.
1508 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1508, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1509 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease2->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1509, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1510
1511 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1511, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease2)", "false",
"true") .c_str()) = ::testing::Message()
;
1512
1513 // The client should also be assigned a lease when it specifies a hint
1514 // that doesn't match the subnet from which the lease is offered. The
1515 // engine should check alternative subnets to match the hint to
1516 // a subnet. The requested lease is available, so it should be offered.
1517 ctx.subnet_ = subnet1_;
1518 ctx.requested_address_ = IOAddress("10.1.2.25");
1519 lease2 = engine_.allocateLease4(ctx);
1520 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1520, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1521 EXPECT_EQ("10.1.2.25", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.25\""
, "lease2->addr_.toText()", "10.1.2.25", lease2->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1521, gtest_ar.failure_message()) = ::testing::Message()
;
1522
1523 // The returning client (the one that has a lease) should also be able
1524 // to renew its lease regardless of a subnet it begins with. So, it has
1525 // an address assigned from subnet1, but we use subnet2 as a selected
1526 // subnet.
1527 AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_,
1528 IOAddress("0.0.0.0"), false, false,
1529 "host.example.com.", false);
1530 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1531 lease2 = engine_.allocateLease4(ctx2);
1532 // The existing lease should be returned.
1533 ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1533, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1534 EXPECT_EQ("192.0.2.17", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\""
, "lease2->addr_.toText()", "192.0.2.17", lease2->addr_
.toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1534, gtest_ar.failure_message()) = ::testing::Message()
;
1535}
1536
1537// This test verifies that the server can assign an address from a
1538// different subnet than orginally selected, when the address pool in
1539// the first subnet is exhausted.
1540TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkClassification)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestSharedNetworkClassification")
> 1, "test_name must not be empty"); class SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
() = default; ~SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
() override = default; SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
(const SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
& operator=( const SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
(SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
& operator=( SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "requestSharedNetworkClassification", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1540), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1540), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1540), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
::TestBody()
{
1541 // Try to offer address from subnet1. There is one address available
1542 // so it should be offered.
1543 AllocEngine::ClientContext4
1544 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1545 false, false, "host.example.com.", false);
1546 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1547 Lease4Ptr lease = engine_.allocateLease4(ctx);
1548 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1548, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1549 EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1549, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1550
1551 // Remove the lease so as we can start over.
1552 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1552, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1553
1554 // Apply restrictions on the subnet1. This should be only assigned
1555 // to clients belonging to cable-modem class.
1556 subnet1_->allowClientClass("cable-modem");
1557
1558 // The allocation engine should determine that the subnet1 is not
1559 // available for the client not belonging to the cable-modem class.
1560 // Instead, it should assign an address from subnet2 that belongs
1561 // to the same shared network.
1562 ctx.subnet_ = subnet1_;
1563 lease = engine_.allocateLease4(ctx);
1564 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1565 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1565, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1566
1567 // Remove the lease so as we can start over.
1568 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1569
1570 // Assign cable-modem class and try again. This time, we should
1571 // offer an address from the subnet1.
1572 ctx.query_->addClass(ClientClass("cable-modem"));
1573
1574 ctx.subnet_ = subnet1_;
1575 lease = engine_.allocateLease4(ctx);
1576 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1576, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1577 EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1578
1579 // Let's now remove the client from the cable-modem class and try
1580 // to renew the address. The engine should determine that the
1581 // client doesn't have access to the subnet1 pools anymore and
1582 // assign an address from unrestricted subnet.
1583 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1584 ctx.subnet_ = subnet1_;
1585 lease = engine_.allocateLease4(ctx);
1586 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1587 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1587, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1588}
1589
1590// This test verifies that the server can assign an address from a
1591// different subnet than orginally selected, when the address pool in
1592// the first subnet requires another class.
1593TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkPoolClassification)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestSharedNetworkPoolClassification"
) > 1, "test_name must not be empty"); class SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
() = default; ~SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
() override = default; SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
(const SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
& operator=( const SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
(SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
& operator=( SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "requestSharedNetworkPoolClassification", nullptr, nullptr,
::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1593), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1593), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1593), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
::TestBody()
{
1594 // Try to offer address from subnet1. There is one address available
1595 // so it should be offered.
1596 AllocEngine::ClientContext4
1597 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1598 false, false, "host.example.com.", false);
1599 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1600 Lease4Ptr lease = engine_.allocateLease4(ctx);
1601 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1601, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1602 EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1602, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1603
1604 // Remove the lease so as we can start over.
1605 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1605, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1606
1607 // Apply restrictions on the pool1. This should be only assigned
1608 // to clients belonging to cable-modem class.
1609 pool1_->allowClientClass("cable-modem");
1610
1611 // The allocation engine should determine that the pool1 is not
1612 // available for the client not belonging to the cable-modem class.
1613 // Instead, it should assign an address from subnet2 that belongs
1614 // to the same shared network.
1615 ctx.subnet_ = subnet1_;
1616 lease = engine_.allocateLease4(ctx);
1617 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1617, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1618 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1618, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1619
1620 // Remove the lease so as we can start over.
1621 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1621, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1622
1623 // Assign cable-modem class and try again. This time, we should
1624 // offer an address from the pool1.
1625 ctx.query_->addClass(ClientClass("cable-modem"));
1626
1627 // Restrict access to pool2 for this client, to make sure that the
1628 // server doesn't accidentally get an address from this pool.
1629 pool2_->allowClientClass("telephone");
1630
1631 ctx.subnet_ = subnet1_;
1632 lease = engine_.allocateLease4(ctx);
1633 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1633, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1634 EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1634, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1635
1636 // Let's now remove the client from the cable-modem class and try
1637 // to renew the address. The engine should determine that the
1638 // client doesn't have access to the pool1 anymore and
1639 // assign an address from another pool.
1640 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1641 ctx.query_->addClass(ClientClass("telephone"));
1642 ctx.subnet_ = subnet1_;
1643 lease = engine_.allocateLease4(ctx);
1644 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1644, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1645 EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1645, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1646}
1647
1648// Test that reservations within shared network take precedence over the
1649// existing leases regardless in which subnet belonging to a shared network
1650// reservations belong (DHCPREQUEST case).
1651TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkReservations)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestSharedNetworkReservations") >
1, "test_name must not be empty"); class SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
() = default; ~SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
() override = default; SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
(const SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
& operator=( const SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
(SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
& operator=( SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "requestSharedNetworkReservations", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1651), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1651), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1651), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
::TestBody()
{
1652
1653 EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance()
.getDisableSingleQuery()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1653, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1654
1655 // Create reservation for the client.
1656 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1657 Host::IDENT_HWADDR, subnet2_->getID(),
1658 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1659 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1660 CfgMgr::instance().commit();
1661
1662 // Start allocation from subnet1. The engine should determine that the
1663 // client has reservations in subnet2 and should rather assign reserved
1664 // addresses.
1665 AllocEngine::ClientContext4
1666 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1667 false, false, "host.example.com.", false);
1668 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1669 AllocEngine::findReservation(ctx);
1670 Lease4Ptr lease = engine_.allocateLease4(ctx);
1671 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1671, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1672 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1672, gtest_ar.failure_message()) = ::testing::Message()
;
1673 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1673, gtest_ar.failure_message()) = ::testing::Message()
;
1674
1675 // Remove the lease for another test below.
1676 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1676, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1677
1678 // Let's create a lease for the client to make sure the lease is not
1679 // renewed but a reserved lease is allocated again.
1680 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1681 501, time(NULL__null), subnet1_->getID()));
1682 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1683 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1683, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1684 ctx.subnet_ = subnet1_;
1685 ctx.hosts_.clear();
1686 AllocEngine::findReservation(ctx);
1687 lease = engine_.allocateLease4(ctx);
1688 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1688, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1689 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1689, gtest_ar.failure_message()) = ::testing::Message()
;
1690 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1690, gtest_ar.failure_message()) = ::testing::Message()
;
1691}
1692
1693// Test that reservations within shared network take precedence over the
1694// existing leases regardless in which subnet belonging to a shared network
1695// reservations belong (DHCPREQUEST case). Host lookups returning a collection
1696// are disabled. As it is only an optimization the behavior (so the test)
1697// must stay unchanged.
1698TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkReservationsNoColl)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestSharedNetworkReservationsNoColl"
) > 1, "test_name must not be empty"); class SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
() = default; ~SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
() override = default; SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
(const SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
& operator=( const SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
&) = delete; SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
(SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
&&) noexcept = delete; SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
& operator=( SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "requestSharedNetworkReservationsNoColl", nullptr, nullptr,
::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1698), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1698), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1698), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
::TestBody()
{
1699
1700 // Disable host lookups returning a collection.
1701 ASSERT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance()
.getDisableSingleQuery()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1701, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1702 HostMgr::instance().setDisableSingleQuery(true);
1703
1704 // Create reservation for the client.
1705 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1706 Host::IDENT_HWADDR, subnet2_->getID(),
1707 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1708 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1709 CfgMgr::instance().commit();
1710
1711 // Start allocation from subnet1. The engine should determine that the
1712 // client has reservations in subnet2 and should rather assign reserved
1713 // addresses.
1714 AllocEngine::ClientContext4
1715 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1716 false, false, "host.example.com.", false);
1717 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1718 AllocEngine::findReservation(ctx);
1719 Lease4Ptr lease = engine_.allocateLease4(ctx);
1720 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1720, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1721 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1721, gtest_ar.failure_message()) = ::testing::Message()
;
1722 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1722, gtest_ar.failure_message()) = ::testing::Message()
;
1723
1724 // Remove the lease for another test below.
1725 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1725, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1726
1727 // Let's create a lease for the client to make sure the lease is not
1728 // renewed but a reserved lease is allocated again.
1729 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1730 501, time(NULL__null), subnet1_->getID()));
1731 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1732 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1732, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1733 ctx.subnet_ = subnet1_;
1734 ctx.hosts_.clear();
1735 AllocEngine::findReservation(ctx);
1736 lease = engine_.allocateLease4(ctx);
1737 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1737, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1738 EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\""
, "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1738, gtest_ar.failure_message()) = ::testing::Message()
;
1739 EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet2_->getID()", lease->subnet_id_, subnet2_->
getID()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1739, gtest_ar.failure_message()) = ::testing::Message()
;
1740}
1741
1742// This test checks if an expired lease can be reused in DHCPDISCOVER (fake
1743// allocation)
1744TEST_F(AllocEngine4Test, discoverReuseExpiredLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverReuseExpiredLease4") > 1,
"test_name must not be empty"); class AllocEngine4Test_discoverReuseExpiredLease4_Test
: public AllocEngine4Test { public: AllocEngine4Test_discoverReuseExpiredLease4_Test
() = default; ~AllocEngine4Test_discoverReuseExpiredLease4_Test
() override = default; AllocEngine4Test_discoverReuseExpiredLease4_Test
(const AllocEngine4Test_discoverReuseExpiredLease4_Test &
) = delete; AllocEngine4Test_discoverReuseExpiredLease4_Test &
operator=( const AllocEngine4Test_discoverReuseExpiredLease4_Test
&) = delete; AllocEngine4Test_discoverReuseExpiredLease4_Test
(AllocEngine4Test_discoverReuseExpiredLease4_Test &&
) noexcept = delete; AllocEngine4Test_discoverReuseExpiredLease4_Test
& operator=( AllocEngine4Test_discoverReuseExpiredLease4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseExpiredLease4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverReuseExpiredLease4", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1744), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1744), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1744), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseExpiredLease4_Test
>); void AllocEngine4Test_discoverReuseExpiredLease4_Test::
TestBody()
{
1745 boost::scoped_ptr<AllocEngine> engine;
1746 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1746
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1746
; } } else gtest_label_testnothrow_1746 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1746, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1747 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1747, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1748
1749 IOAddress addr("192.0.2.15");
1750 CfgMgr& cfg_mgr = CfgMgr::instance();
1751 // Get rid of the default test configuration.
1752 cfg_mgr.clear();
1753
1754 // Create configuration similar to other tests, but with a single address pool
1755 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1756 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1757 subnet_->addPool(pool_);
1758 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1759
1760 // Just a different hw/client-id for the second client
1761 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
1762 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
1763 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
1764 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
1765 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
1766 495, now, subnet_->getID()));
1767 // Copy the lease, so as it can be compared with the old lease returned
1768 // by the allocation engine.
1769 Lease4 original_lease(*lease);
1770
1771 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
1772 // is expired already
1773 ASSERT_TRUE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->expired()))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1773, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
1774 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1774, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1775
1776 // CASE 1: Asking for any address
1777 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
1778 IOAddress("0.0.0.0"), false, false,
1779 "", true);
1780 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1781 lease = engine->allocateLease4(ctx1);
1782 // Check that we got that single lease
1783 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1783, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1784 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1784, gtest_ar.failure_message()) = ::testing::Message()
;
1785
1786 // We are reusing expired lease, the old (expired) instance should be
1787 // returned. The returned instance should be the same as the original
1788 // lease.
1789 ASSERT_TRUE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx1.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1789, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
1790 EXPECT_TRUE(original_lease == *ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(original_lease == *ctx1
.old_lease_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1790, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *ctx1.old_lease_", "false", "true") .c_str
()) = ::testing::Message()
;
1791
1792 // Do all checks on the lease (if subnet-id, preferred/valid times are ok etc.)
1793 checkLease4(lease);
1794
1795 // CASE 2: Asking specifically for this address
1796 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
1797 IOAddress(addr), false, false,
1798 "", true);
1799 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1800 lease = engine->allocateLease4(ctx2);
1801 // Check that we got that single lease
1802 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1802, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1803 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1803, gtest_ar.failure_message()) = ::testing::Message()
;
1804
1805 // We are updating expired lease. The copy of the old lease should be
1806 // returned and it should be equal to the original lease.
1807 ASSERT_TRUE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx2.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1807, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
1808 EXPECT_TRUE(*ctx2.old_lease_ == original_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*ctx2.old_lease_ == original_lease
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1808, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*ctx2.old_lease_ == original_lease", "false", "true") .c_str
()) = ::testing::Message()
;
1809}
1810
1811// This test checks if an expired lease can be reused in REQUEST (actual allocation)
1812TEST_F(AllocEngine4Test, requestReuseExpiredLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestReuseExpiredLease4") > 1, "test_name must not be empty"
); class AllocEngine4Test_requestReuseExpiredLease4_Test : public
AllocEngine4Test { public: AllocEngine4Test_requestReuseExpiredLease4_Test
() = default; ~AllocEngine4Test_requestReuseExpiredLease4_Test
() override = default; AllocEngine4Test_requestReuseExpiredLease4_Test
(const AllocEngine4Test_requestReuseExpiredLease4_Test &
) = delete; AllocEngine4Test_requestReuseExpiredLease4_Test &
operator=( const AllocEngine4Test_requestReuseExpiredLease4_Test
&) = delete; AllocEngine4Test_requestReuseExpiredLease4_Test
(AllocEngine4Test_requestReuseExpiredLease4_Test &&)
noexcept = delete; AllocEngine4Test_requestReuseExpiredLease4_Test
& operator=( AllocEngine4Test_requestReuseExpiredLease4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestReuseExpiredLease4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestReuseExpiredLease4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1812), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1812), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1812), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseExpiredLease4_Test
>); void AllocEngine4Test_requestReuseExpiredLease4_Test::
TestBody()
{
1813 boost::scoped_ptr<AllocEngine> engine;
1814 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1814
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1814
; } } else gtest_label_testnothrow_1814 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1814, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1815 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1815, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1816
1817 IOAddress addr("192.0.2.105");
1818
1819 EXPECT_TRUE(testStatistics("assigned-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1819, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0)", "false", "true"
) .c_str()) = ::testing::Message()
;
1820 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1820, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1821 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
1822 subnet_->getID());
1823
1824 int64_t glbl_assigned = getStatistics("assigned-addresses");
1825 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
1826
1827 EXPECT_TRUE(testStatistics("reclaimed-leases", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1827, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0)", "false", "true")
.c_str()) = ::testing::Message()
;
1828 EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1829
1830 // Just a different hw/client-id for the second client
1831 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
1832 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
1833 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
1834 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
1835
1836 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
1837 495, now, subnet_->getID()));
1838 // Make a copy of the lease, so as we can compare that with the old lease
1839 // instance returned by the allocation engine.
1840 Lease4 original_lease(*lease);
1841
1842 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
1843 // is expired already
1844 ASSERT_TRUE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->expired()))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1844, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
1845 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1845, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1846
1847 // A client comes along, asking specifically for this address
1848 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
1849 IOAddress(addr), false, false,
1850 "host.example.com.", false);
1851 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1852 lease = engine->allocateLease4(ctx);
1853
1854 // Check that he got that single lease
1855 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1855, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1856 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1856, gtest_ar.failure_message()) = ::testing::Message()
;
1857
1858 // Check that the lease is indeed updated in LeaseMgr
1859 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
1860 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1860, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
1861
1862 // Now check that the lease in LeaseMgr has the same parameters
1863 detailCompareLease(lease, from_mgr);
1864
1865 // The allocation engine should return a copy of the old lease. This
1866 // lease should be equal to the original lease.
1867 ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1867, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
1868 EXPECT_TRUE(*ctx.old_lease_ == original_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*ctx.old_lease_ == original_lease
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1868, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*ctx.old_lease_ == original_lease", "false", "true") .c_str
()) = ::testing::Message()
;
1869
1870 // Check that the stats declined stats were modified correctly. Note, because
1871 // added the lease directly, assigned-leases never bumped to one, so when we
1872 // reclaim it gets decremented to -1, then on assignment back to 0.
1873 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1873, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1874 cumulative += 1;
1875 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1876, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
1876 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1876, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1877 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1877, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
1878 glbl_cumulative += 1;
1879 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1879, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
1880 EXPECT_TRUE(testStatistics("reclaimed-leases", 1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1)", "false", "true")
.c_str()) = ::testing::Message()
;
1881 EXPECT_TRUE(testStatistics("reclaimed-leases", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1881, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1882}
1883
1884// This test checks if an expired declined lease can be reused when responding
1885// to DHCPDISCOVER (fake allocation)
1886TEST_F(AllocEngine4Test, discoverReuseDeclinedLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverReuseDeclinedLease4") > 1
, "test_name must not be empty"); class AllocEngine4Test_discoverReuseDeclinedLease4_Test
: public AllocEngine4Test { public: AllocEngine4Test_discoverReuseDeclinedLease4_Test
() = default; ~AllocEngine4Test_discoverReuseDeclinedLease4_Test
() override = default; AllocEngine4Test_discoverReuseDeclinedLease4_Test
(const AllocEngine4Test_discoverReuseDeclinedLease4_Test &
) = delete; AllocEngine4Test_discoverReuseDeclinedLease4_Test
& operator=( const AllocEngine4Test_discoverReuseDeclinedLease4_Test
&) = delete; AllocEngine4Test_discoverReuseDeclinedLease4_Test
(AllocEngine4Test_discoverReuseDeclinedLease4_Test &&
) noexcept = delete; AllocEngine4Test_discoverReuseDeclinedLease4_Test
& operator=( AllocEngine4Test_discoverReuseDeclinedLease4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseDeclinedLease4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverReuseDeclinedLease4", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1886), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1886), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1886), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4_Test
>); void AllocEngine4Test_discoverReuseDeclinedLease4_Test
::TestBody()
{
1887
1888 AllocEnginePtr engine(new AllocEngine(0));
1889 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1889, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1890
1891 // Now prepare a configuration with single address pool.
1892 IOAddress addr("192.0.2.15");
1893 CfgMgr& cfg_mgr = CfgMgr::instance();
1894 cfg_mgr.clear();
1895 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1896 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1897 subnet_->addPool(pool_);
1898 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1899
1900 // Now create a declined lease, decline it and rewind its cltt, so it
1901 // is expired.
1902 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
1903
1904 // CASE 1: Ask for any address
1905 Lease4Ptr assigned;
1906 testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned);
1907
1908 // Check that we got that single lease
1909 ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1909, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
1910 EXPECT_EQ(addr, assigned->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "assigned->addr_"
, addr, assigned->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1910, gtest_ar.failure_message()) = ::testing::Message()
;
1911
1912 // CASE 2: Asking specifically for this address
1913 testReuseLease4(engine, declined, "192.0.2.15", true, SHOULD_PASS, assigned);
1914
1915 // Check that we get it again
1916 ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1916, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
1917 EXPECT_EQ(addr, assigned->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "assigned->addr_"
, addr, assigned->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1917, gtest_ar.failure_message()) = ::testing::Message()
;
1918}
1919
1920// This test checks if statistics are not updated when expired declined lease
1921// is reused when responding to DHCPDISCOVER (fake allocation)
1922TEST_F(AllocEngine4Test, discoverReuseDeclinedLease4Stats)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverReuseDeclinedLease4Stats") >
1, "test_name must not be empty"); class AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
: public AllocEngine4Test { public: AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
() = default; ~AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
() override = default; AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
(const AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
&) = delete; AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
& operator=( const AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
&) = delete; AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
(AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test &&
) noexcept = delete; AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
& operator=( AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverReuseDeclinedLease4Stats", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1922), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1922), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1922), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
>); void AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
::TestBody()
{
1923
1924 // Now prepare for DISCOVER processing
1925 AllocEnginePtr engine(new AllocEngine(0));
1926 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1926, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1927
1928 // Now prepare a configuration with single address pool.
1929 IOAddress addr("192.0.2.15");
1930 CfgMgr& cfg_mgr = CfgMgr::instance();
1931 cfg_mgr.clear();
1932 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1933 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1934 subnet_->addPool(pool_);
1935 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1936 cfg_mgr.commit(); // so we will recalc stats
1937 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
1938 subnet_->getID());
1939
1940 int64_t glbl_assigned = getStatistics("assigned-addresses");
1941 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
1942
1943 // Now create a declined lease, decline it and rewind its cltt, so it
1944 // is expired.
1945 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
1946
1947 // Ask for any address. There's only one address in the pool, so it doesn't
1948 // matter much.
1949 Lease4Ptr assigned;
1950 testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned);
1951
1952 // Check that the stats declined stats were not modified
1953 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1953, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1954 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1955, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
1955 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1955, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1956 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1956, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
1957 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1957, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
1958 EXPECT_TRUE(testStatistics("declined-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1958, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", 0)", "false", "true"
) .c_str()) = ::testing::Message()
;
1959 EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1959, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 0)", "false"
, "true") .c_str()) = ::testing::Message()
;
1960 EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1960, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1961 EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1961, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1962}
1963
1964// This test checks if an expired declined lease can be reused when responding
1965// to REQUEST (actual allocation)
1966TEST_F(AllocEngine4Test, requestReuseDeclinedLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestReuseDeclinedLease4") > 1,
"test_name must not be empty"); class AllocEngine4Test_requestReuseDeclinedLease4_Test
: public AllocEngine4Test { public: AllocEngine4Test_requestReuseDeclinedLease4_Test
() = default; ~AllocEngine4Test_requestReuseDeclinedLease4_Test
() override = default; AllocEngine4Test_requestReuseDeclinedLease4_Test
(const AllocEngine4Test_requestReuseDeclinedLease4_Test &
) = delete; AllocEngine4Test_requestReuseDeclinedLease4_Test &
operator=( const AllocEngine4Test_requestReuseDeclinedLease4_Test
&) = delete; AllocEngine4Test_requestReuseDeclinedLease4_Test
(AllocEngine4Test_requestReuseDeclinedLease4_Test &&
) noexcept = delete; AllocEngine4Test_requestReuseDeclinedLease4_Test
& operator=( AllocEngine4Test_requestReuseDeclinedLease4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestReuseDeclinedLease4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestReuseDeclinedLease4", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1966), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1966), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1966), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4_Test
>); void AllocEngine4Test_requestReuseDeclinedLease4_Test::
TestBody()
{
1967
1968 AllocEnginePtr engine(new AllocEngine(0));
1969 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1969, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1970
1971 // Now prepare a configuration with single address pool.
1972 IOAddress addr("192.0.2.15");
1973 CfgMgr& cfg_mgr = CfgMgr::instance();
1974 cfg_mgr.clear();
1975 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1976 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1977 subnet_->addPool(pool_);
1978 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1979
1980 // Now create a declined lease, decline it and rewind its cltt, so it
1981 // is expired.
1982 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
1983
1984 // Asking specifically for this address
1985 Lease4Ptr assigned;
1986 testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned);
1987 // Check that we got it.
1988 ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1988, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
1989 EXPECT_EQ(addr, assigned->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "assigned->addr_"
, addr, assigned->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1989, gtest_ar.failure_message()) = ::testing::Message()
;
1990
1991 // Check that the lease is indeed updated in LeaseMgr
1992 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
1993 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1993, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
1994
1995 // Now check that the lease in LeaseMgr has the same parameters
1996 detailCompareLease(assigned, from_mgr);
1997}
1998
1999// This test checks if statistics are not updated when expired declined lease
2000// is reused when responding to DHCPREQUEST (actual allocation)
2001TEST_F(AllocEngine4Test, requestReuseDeclinedLease4Stats)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestReuseDeclinedLease4Stats") >
1, "test_name must not be empty"); class AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
: public AllocEngine4Test { public: AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
() = default; ~AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
() override = default; AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
(const AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
&) = delete; AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
& operator=( const AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
&) = delete; AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
(AllocEngine4Test_requestReuseDeclinedLease4Stats_Test &&
) noexcept = delete; AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
& operator=( AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestReuseDeclinedLease4Stats", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2001), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2001), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2001), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
>); void AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
::TestBody()
{
2002
2003 AllocEnginePtr engine(new AllocEngine(0));
2004 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2004, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
2005
2006 // Now prepare a configuration with single address pool.
2007 IOAddress addr("192.0.2.15");
2008 CfgMgr& cfg_mgr = CfgMgr::instance();
2009 cfg_mgr.clear();
2010 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
2011 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
2012 subnet_->addPool(pool_);
2013 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
2014 cfg_mgr.commit();
2015 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
2016 subnet_->getID());
2017
2018 int64_t glbl_assigned = getStatistics("assigned-addresses");
2019 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
2020
2021 // Now create a declined lease, decline it and rewind its cltt, so it
2022 // is expired.
2023 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
2024
2025 // Asking specifically for this address
2026 Lease4Ptr assigned;
2027 testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned);
2028 // Check that we got it.
2029 ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2029, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
2030
2031 // Check that the stats are correct. Note that assigned-addresses does
2032 // not get decremented when a lease is declined, ergo not incremented
2033 // when it is reused. Declined address stats will be -1 since
2034 // lease was created as declined which does not increment the stat.
2035 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2035, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2036 cumulative += 1;
2037 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
2038 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2039 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2039, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
2040 glbl_cumulative += 1;
2041 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2041, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
2042 EXPECT_TRUE(testStatistics("declined-addresses", -1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses"
, -1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2042, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", -1)", "false", "true"
) .c_str()) = ::testing::Message()
;
2043 EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses"
, 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2043, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 1)", "false"
, "true") .c_str()) = ::testing::Message()
;
2044 EXPECT_TRUE(testStatistics("declined-addresses", -1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses"
, -1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2044, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", -1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2045 EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses"
, 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2045, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2046}
2047
2048// This test checks if a released lease can be reused in REQUEST (actual allocation)
2049TEST_F(AllocEngine4Test, requestReuseReleasedLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestReuseReleasedLease4") > 1,
"test_name must not be empty"); class AllocEngine4Test_requestReuseReleasedLease4_Test
: public AllocEngine4Test { public: AllocEngine4Test_requestReuseReleasedLease4_Test
() = default; ~AllocEngine4Test_requestReuseReleasedLease4_Test
() override = default; AllocEngine4Test_requestReuseReleasedLease4_Test
(const AllocEngine4Test_requestReuseReleasedLease4_Test &
) = delete; AllocEngine4Test_requestReuseReleasedLease4_Test &
operator=( const AllocEngine4Test_requestReuseReleasedLease4_Test
&) = delete; AllocEngine4Test_requestReuseReleasedLease4_Test
(AllocEngine4Test_requestReuseReleasedLease4_Test &&
) noexcept = delete; AllocEngine4Test_requestReuseReleasedLease4_Test
& operator=( AllocEngine4Test_requestReuseReleasedLease4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestReuseReleasedLease4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestReuseReleasedLease4", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2049), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2049), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2049), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseReleasedLease4_Test
>); void AllocEngine4Test_requestReuseReleasedLease4_Test::
TestBody()
{
2050 boost::scoped_ptr<AllocEngine> engine;
2051 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2051
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2051
; } } else gtest_label_testnothrow_2051 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2051, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
2052 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2052, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
2053
2054 IOAddress addr("192.0.2.105");
2055
2056 EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2056, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2057 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
2058 subnet_->getID());
2059
2060 int64_t glbl_assigned = getStatistics("assigned-addresses");
2061 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
2062
2063 EXPECT_TRUE(testStatistics("reclaimed-leases", 0))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2063, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0)", "false", "true")
.c_str()) = ::testing::Message()
;
2064 EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2065
2066 // Just a different hw/client-id for the second client
2067 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
2068 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
2069 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
2070 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
2071
2072 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
2073 495, now, subnet_->getID()));
2074 lease->state_ = Lease4::STATE_RELEASED;
2075 // Make a copy of the lease, so as we can compare that with the old lease
2076 // instance returned by the allocation engine.
2077 Lease4 original_lease(*lease);
2078
2079 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
2080 // is expired already
2081 ASSERT_TRUE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->expired()))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2081, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
2082 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2082, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
2083
2084 // A client comes along, asking specifically for this address
2085 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2086 IOAddress(addr), false, false,
2087 "host.example.com.", false);
2088 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2089 lease = engine->allocateLease4(ctx);
2090
2091 // Check that he got that single lease
2092 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2092, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2093 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2093, gtest_ar.failure_message()) = ::testing::Message()
;
2094
2095 // Check that the lease is indeed updated in LeaseMgr
2096 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
2097 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2097, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2098
2099 // Now check that the lease in LeaseMgr has the same parameters
2100 detailCompareLease(lease, from_mgr);
2101
2102 // The allocation engine should return a copy of the old lease. This
2103 // lease should be equal to the original lease.
2104 ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2104, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2105 EXPECT_TRUE(*ctx.old_lease_ == original_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*ctx.old_lease_ == original_lease
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2105, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*ctx.old_lease_ == original_lease", "false", "true") .c_str
()) = ::testing::Message()
;
2106
2107 EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2107, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2108 cumulative += 1;
2109 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2110, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
2110 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2110, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2111 glbl_assigned += 1;
2112 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2112, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
2113 glbl_cumulative += 1;
2114 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2114, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
2115 EXPECT_TRUE(testStatistics("reclaimed-leases", 1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2115, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1)", "false", "true")
.c_str()) = ::testing::Message()
;
2116 EXPECT_TRUE(testStatistics("reclaimed-leases", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases"
, 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2116, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2117}
2118
2119// This test checks that the Allocation Engine correctly identifies the
2120// existing client's lease in the lease database, using the client
2121// identifier and HW address.
2122TEST_F(AllocEngine4Test, identifyClientLease)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("identifyClientLease") > 1, "test_name must not be empty"
); class AllocEngine4Test_identifyClientLease_Test : public AllocEngine4Test
{ public: AllocEngine4Test_identifyClientLease_Test() = default
; ~AllocEngine4Test_identifyClientLease_Test() override = default
; AllocEngine4Test_identifyClientLease_Test (const AllocEngine4Test_identifyClientLease_Test
&) = delete; AllocEngine4Test_identifyClientLease_Test &
operator=( const AllocEngine4Test_identifyClientLease_Test &
) = delete; AllocEngine4Test_identifyClientLease_Test (AllocEngine4Test_identifyClientLease_Test
&&) noexcept = delete; AllocEngine4Test_identifyClientLease_Test
& operator=( AllocEngine4Test_identifyClientLease_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_identifyClientLease_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "identifyClientLease", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2122), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2122), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2122), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_identifyClientLease_Test
>); void AllocEngine4Test_identifyClientLease_Test::TestBody
()
{
2123 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, clientid_,
2124 100, time(NULL__null), subnet_->getID()));
2125 LeaseMgrFactory::instance().addLease(lease);
2126
2127 AllocEngine engine(0);
2128 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2129 IOAddress::IPV4_ZERO_ADDRESS(),
2130 false, false, "", true);
2131 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2132
2133 Lease4Ptr identified_lease = engine.allocateLease4(ctx);
2134 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2134, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2135 EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "identified_lease->addr_.toText()", "192.0.2.101", identified_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2135, gtest_ar.failure_message()) = ::testing::Message()
;
2136
2137 ctx.hwaddr_ = hwaddr2_;
2138 ctx.clientid_ = clientid_;
2139 identified_lease = engine.allocateLease4(ctx);
2140 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2140, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2141 EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "identified_lease->addr_.toText()", "192.0.2.101", identified_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2141, gtest_ar.failure_message()) = ::testing::Message()
;
2142
2143 ctx.hwaddr_ = hwaddr_;
2144 ctx.clientid_ = clientid2_;
2145 identified_lease = engine.allocateLease4(ctx);
2146 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2146, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2147 EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("identified_lease->addr_.toText()"
, "\"192.0.2.101\"", identified_lease->addr_.toText(), "192.0.2.101"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2147, gtest_ar.failure_message()) = ::testing::Message()
;
2148
2149 ctx.hwaddr_ = hwaddr_;
2150 ctx.clientid_.reset();
2151 identified_lease = engine.allocateLease4(ctx);
2152 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2152, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2153 EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "identified_lease->addr_.toText()", "192.0.2.101", identified_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2153, gtest_ar.failure_message()) = ::testing::Message()
;
2154
2155 ctx.hwaddr_ = hwaddr2_;
2156 ctx.clientid_.reset();
2157 identified_lease = engine.allocateLease4(ctx);
2158 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2158, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2159 EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("identified_lease->addr_.toText()"
, "\"192.0.2.101\"", identified_lease->addr_.toText(), "192.0.2.101"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2159, gtest_ar.failure_message()) = ::testing::Message()
;
2160
2161 lease->client_id_.reset();
2162 ASSERT_NO_THROW(LeaseMgrFactory::instance().updateLease4(lease))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
LeaseMgrFactory::instance().updateLease4(lease); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2162; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2162; } } else gtest_label_testnothrow_2162
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2162, ("Expected: " "LeaseMgrFactory::instance().updateLease4(lease)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2163
2164 ctx.hwaddr_ = hwaddr_;
2165 ctx.clientid_ = clientid_;
2166 identified_lease = engine.allocateLease4(ctx);
2167 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2167, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2168 EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "identified_lease->addr_.toText()", "192.0.2.101", identified_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2168, gtest_ar.failure_message()) = ::testing::Message()
;
2169
2170 ctx.hwaddr_ = hwaddr_;
2171 ctx.clientid_.reset();
2172 identified_lease = engine.allocateLease4(ctx);
2173 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2173, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2174 EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "identified_lease->addr_.toText()", "192.0.2.101", identified_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2174, gtest_ar.failure_message()) = ::testing::Message()
;
2175
2176 ctx.hwaddr_ = hwaddr2_;
2177 ctx.clientid_ = clientid_;
2178 identified_lease = engine.allocateLease4(ctx);
2179 ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2179, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2180 EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("identified_lease->addr_.toText()"
, "\"192.0.2.101\"", identified_lease->addr_.toText(), "192.0.2.101"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2180, gtest_ar.failure_message()) = ::testing::Message()
;
2181}
2182
2183// This test checks that when the client requests the address which belongs
2184// to another client, the allocation engine returns NULL (for the
2185// DHCPREQUEST case) or a lease for the address which belongs to this
2186// client (DHCPDISCOVER case).
2187TEST_F(AllocEngine4Test, requestOtherClientLease)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestOtherClientLease") > 1, "test_name must not be empty"
); class AllocEngine4Test_requestOtherClientLease_Test : public
AllocEngine4Test { public: AllocEngine4Test_requestOtherClientLease_Test
() = default; ~AllocEngine4Test_requestOtherClientLease_Test(
) override = default; AllocEngine4Test_requestOtherClientLease_Test
(const AllocEngine4Test_requestOtherClientLease_Test &) =
delete; AllocEngine4Test_requestOtherClientLease_Test & operator
=( const AllocEngine4Test_requestOtherClientLease_Test &)
= delete; AllocEngine4Test_requestOtherClientLease_Test (AllocEngine4Test_requestOtherClientLease_Test
&&) noexcept = delete; AllocEngine4Test_requestOtherClientLease_Test
& operator=( AllocEngine4Test_requestOtherClientLease_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestOtherClientLease_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestOtherClientLease", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2187), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2187), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2187), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestOtherClientLease_Test
>); void AllocEngine4Test_requestOtherClientLease_Test::TestBody
()
{
2188 // Create the first lease.
2189 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2190 &clientid_->getClientId()[0],
2191 clientid_->getClientId().size(),
2192 100, time(NULL__null), subnet_->getID(),
2193 false, false, ""));
2194 // Create the second lease. Note that we use the same client id here and
2195 // we expect that the allocation engine will figure out that the hardware
2196 // address is different.
2197 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr2_,
2198 &clientid_->getClientId()[0],
2199 clientid_->getClientId().size(),
2200 100, time(NULL__null), subnet_->getID(),
2201 false, false, ""));
2202 // Add leases for both clients to the Lease Manager.
2203 LeaseMgrFactory::instance().addLease(lease);
2204 LeaseMgrFactory::instance().addLease(lease2);
2205
2206 AllocEngine engine(0);
2207
2208 // First client requests the lease which belongs to the second client.
2209 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"),
2210 false, false, "", false);
2211 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2212 Lease4Ptr new_lease = engine.allocateLease4(ctx);
2213 // Allocation engine should return NULL.
2214 ASSERT_FALSE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(new_lease))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2214, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "true", "false") .c_str()) = ::testing::Message
()
;
2215
2216 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2216, gtest_ar.failure_message()) = ::testing::Message()
;
2217 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2217, gtest_ar.failure_message()) = ::testing::Message()
;
2218 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2218, gtest_ar.failure_message()) = ::testing::Message()
;
2219 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2219, gtest_ar.failure_message()) = ::testing::Message()
;
2220 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2220, gtest_ar.failure_message()) = ::testing::Message()
;
2221
2222 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2222, gtest_ar.failure_message()) = ::testing::Message()
;
2223 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2223, gtest_ar.failure_message()) = ::testing::Message()
;
2224 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2224, gtest_ar.failure_message()) = ::testing::Message()
;
2225 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2225, gtest_ar.failure_message()) = ::testing::Message()
;
2226 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2226, gtest_ar.failure_message()) = ::testing::Message()
;
2227
2228 // Now simulate the DHCPDISCOVER case when the provided address is
2229 // treated as a hint. The engine should return a lease for a
2230 // different address than requested.
2231 ctx.fake_allocation_ = true;
2232 new_lease = engine.allocateLease4(ctx);
2233 ASSERT_TRUE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(new_lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2233, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "false", "true") .c_str()) = ::testing::Message
()
;
2234 EXPECT_EQ("192.0.2.101", new_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "new_lease->addr_.toText()", "192.0.2.101", new_lease->
addr_.toText()))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2234, gtest_ar.failure_message()) = ::testing::Message()
;
2235}
2236
2237// Allocation engine should remove a pre-existing lease
2238// and renew the temporary lease when offer-lifetime > 0.
2239// This can happen when a client gets a lease which is
2240// later rendered invalid by the creation of host reservation,
2241// either for the lease address or for the client with
2242// a different address.
2243TEST_F(AllocEngine4Test, existingLeasePlusTemporary)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("existingLeasePlusTemporary") > 1,
"test_name must not be empty"); class AllocEngine4Test_existingLeasePlusTemporary_Test
: public AllocEngine4Test { public: AllocEngine4Test_existingLeasePlusTemporary_Test
() = default; ~AllocEngine4Test_existingLeasePlusTemporary_Test
() override = default; AllocEngine4Test_existingLeasePlusTemporary_Test
(const AllocEngine4Test_existingLeasePlusTemporary_Test &
) = delete; AllocEngine4Test_existingLeasePlusTemporary_Test &
operator=( const AllocEngine4Test_existingLeasePlusTemporary_Test
&) = delete; AllocEngine4Test_existingLeasePlusTemporary_Test
(AllocEngine4Test_existingLeasePlusTemporary_Test &&
) noexcept = delete; AllocEngine4Test_existingLeasePlusTemporary_Test
& operator=( AllocEngine4Test_existingLeasePlusTemporary_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_existingLeasePlusTemporary_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "existingLeasePlusTemporary", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2243), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2243), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2243), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_existingLeasePlusTemporary_Test
>); void AllocEngine4Test_existingLeasePlusTemporary_Test::
TestBody()
{
2244 // Create the first lease.
2245 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2246 &clientid_->getClientId()[0],
2247 clientid_->getClientId().size(),
2248 100, time(NULL__null), subnet_->getID(),
2249 false, false, ""));
2250
2251 // Create the second lease.
2252 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr_,
2253 &clientid_->getClientId()[0],
2254 clientid_->getClientId().size(),
2255 100, time(NULL__null), subnet_->getID(),
2256 false, false, ""));
2257 // Add leases for both clients to the Lease Manager.
2258 LeaseMgrFactory::instance().addLease(lease);
2259 LeaseMgrFactory::instance().addLease(lease2);
2260
2261 // When temporary allocations are off and client requests the
2262 // second lease, the engine should not return a lease.
2263 AllocEngine engine(0);
2264 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"),
2265 false, false, "", false);
2266 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2267 Lease4Ptr new_lease = engine.allocateLease4(ctx);
2268
2269 ASSERT_FALSE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(new_lease))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2269, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "true", "false") .c_str()) = ::testing::Message
()
;
2270
2271 // Both leases should still be in the lease back end.
2272 ASSERT_TRUE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().getLease4(lease->addr_))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2272, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
2273 ASSERT_TRUE(LeaseMgrFactory::instance().getLease4(lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().getLease4(lease2->addr_))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2273, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease2->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
2274
2275 // Now enable temporary allocations by setting offer lifetime > 0.
2276 subnet_->setOfferLft(120);
2277
2278 // Client requests the second lease.
2279 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"),
2280 false, false, "", false);
2281 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2282 new_lease = engine.allocateLease4(ctx2);
2283
2284 // Allocation should return the second lease and remove the original lease.
2285 ASSERT_TRUE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(new_lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2285, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "false", "true") .c_str()) = ::testing::Message
()
;
2286 EXPECT_EQ("192.0.2.102", new_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.102\""
, "new_lease->addr_.toText()", "192.0.2.102", new_lease->
addr_.toText()))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2286, gtest_ar.failure_message()) = ::testing::Message()
;
2287
2288 // Original lease should have been deleted from lease back.
2289 ASSERT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2289, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2290}
2291
2292// This test checks the behavior of the allocation engine in the following
2293// scenario:
2294// - Client has no lease in the database.
2295// - Client has a reservation.
2296// - Client sends DHCPREQUEST without requested IP Address, nor ciaddr.
2297// - Client is allocated a reserved address.
2298//
2299// Note that client must normally include a requested IP address or ciaddr
2300// in its message. But, we still want to provision clients that don't do that.
2301// The server simply picks reserved address or any other available one if there
2302// is no reservation.
2303TEST_F(AllocEngine4Test, reservedAddressNoHint)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressNoHint") > 1, "test_name must not be empty"
); class AllocEngine4Test_reservedAddressNoHint_Test : public
AllocEngine4Test { public: AllocEngine4Test_reservedAddressNoHint_Test
() = default; ~AllocEngine4Test_reservedAddressNoHint_Test() override
= default; AllocEngine4Test_reservedAddressNoHint_Test (const
AllocEngine4Test_reservedAddressNoHint_Test &) = delete;
AllocEngine4Test_reservedAddressNoHint_Test & operator=(
const AllocEngine4Test_reservedAddressNoHint_Test &) = delete
; AllocEngine4Test_reservedAddressNoHint_Test (AllocEngine4Test_reservedAddressNoHint_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressNoHint_Test
& operator=( AllocEngine4Test_reservedAddressNoHint_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressNoHint_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressNoHint", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2303), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2303), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2303), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHint_Test
>); void AllocEngine4Test_reservedAddressNoHint_Test::TestBody
()
{
2304 // Create reservation for the client.
2305 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2306 Host::IDENT_HWADDR, subnet_->getID(),
2307 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2308 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2309 CfgMgr::instance().commit();
2310
2311 AllocEngine engine(0);
2312
2313 // Try to allocate a lease without specifying a hint. This is actually
2314 // incorrect behavior of the client to not send an address it wants to
2315 // obtain but the server should handle this gracefully.
2316 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2317 IOAddress("0.0.0.0"), false, false,
2318 "", false);
2319 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2320 AllocEngine::findReservation(ctx);
2321 Lease4Ptr lease = engine.allocateLease4(ctx);
2322
2323 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2324 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2324, gtest_ar.failure_message()) = ::testing::Message()
;
2325
2326 // Make sure that the lease has been committed to the lease database.
2327 // And that the committed lease is equal to the one returned.
2328 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2329 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2329, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2330 detailCompareLease(lease, from_mgr);
2331
2332 // Initially, there was no lease for this client, so the returned old
2333 // lease should be NULL.
2334 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2334, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
2335}
2336
2337// This test checks behavior of the allocation engine in the following scenario:
2338// - Client has no lease in the database.
2339// - Client has a reservation.
2340// - Client sends DHCPDISCOVER without requested IP Address.
2341// - Server returns DHCPOFFER with the reserved address.
2342TEST_F(AllocEngine4Test, reservedAddressNoHintFakeAllocation)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressNoHintFakeAllocation"
) > 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
() = default; ~AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
() override = default; AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
(const AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
& operator=( const AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
(AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
& operator=( AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressNoHintFakeAllocation", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2342), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2342), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2342), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
::TestBody()
{
2343 // Create reservation for the client.
2344 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2345 Host::IDENT_HWADDR, subnet_->getID(),
2346 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2347 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2348 CfgMgr::instance().commit();
2349
2350 AllocEngine engine(0);
2351
2352 // Query allocation engine for the lease to be assigned to this
2353 // client without specifying the address to be assigned.
2354 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2355 IOAddress("0.0.0.0"), false, false,
2356 "", true);
2357 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2358 AllocEngine::findReservation(ctx);
2359 Lease4Ptr lease = engine.allocateLease4(ctx);
2360
2361 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2361, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2362 // The allocation engine should return a reserved address.
2363 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2363, gtest_ar.failure_message()) = ::testing::Message()
;
2364
2365 // This is a "fake" allocation so the returned lease should not be committed
2366 // to the lease database.
2367 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2367, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2368
2369 // Client had no lease in the database, so the old lease returned should
2370 // be NULL.
2371 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2371, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
2372}
2373
2374// This test checks the behavior of the allocation engine in the following
2375// scenario:
2376// - Client has no lease in the database.
2377// - Client has a reservation.
2378// - Client sends DHCPREQUEST with a requested IP address
2379// - Server returns DHCPNAK when requested IP address is different than
2380// the reserved address. Note that the allocation engine returns NULL
2381// to indicate to the server that it should send DHCPNAK.
2382// - Server allocates a reserved address to the client when the client requests
2383// this address using requested IP address option.
2384TEST_F(AllocEngine4Test, reservedAddressHint)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressHint") > 1, "test_name must not be empty"
); class AllocEngine4Test_reservedAddressHint_Test : public AllocEngine4Test
{ public: AllocEngine4Test_reservedAddressHint_Test() = default
; ~AllocEngine4Test_reservedAddressHint_Test() override = default
; AllocEngine4Test_reservedAddressHint_Test (const AllocEngine4Test_reservedAddressHint_Test
&) = delete; AllocEngine4Test_reservedAddressHint_Test &
operator=( const AllocEngine4Test_reservedAddressHint_Test &
) = delete; AllocEngine4Test_reservedAddressHint_Test (AllocEngine4Test_reservedAddressHint_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressHint_Test
& operator=( AllocEngine4Test_reservedAddressHint_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_reservedAddressHint_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressHint", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2384), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2384), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2384), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHint_Test
>); void AllocEngine4Test_reservedAddressHint_Test::TestBody
()
{
2385 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2386 Host::IDENT_HWADDR, subnet_->getID(),
2387 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2388 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2389 CfgMgr::instance().commit();
2390
2391 AllocEngine engine(0);
2392
2393 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2394 IOAddress("192.0.2.234"), false, false,
2395 "", false);
2396 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2397 AllocEngine::findReservation(ctx1);
2398 Lease4Ptr lease = engine.allocateLease4(ctx1);
2399
2400 // The client requested a different address than reserved, so
2401 // the allocation engine should return NULL lease. When the server
2402 // receives a NULL lease for the client, it will send a DHCPNAK.
2403 ASSERT_FALSE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2403, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
2404 ASSERT_FALSE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx1.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2404, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2405
2406 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2406, gtest_ar.failure_message()) = ::testing::Message()
;
2407 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2407, gtest_ar.failure_message()) = ::testing::Message()
;
2408 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2408, gtest_ar.failure_message()) = ::testing::Message()
;
2409 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2409, gtest_ar.failure_message()) = ::testing::Message()
;
2410 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2410, gtest_ar.failure_message()) = ::testing::Message()
;
2411
2412 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2412, gtest_ar.failure_message()) = ::testing::Message()
;
2413 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2413, gtest_ar.failure_message()) = ::testing::Message()
;
2414 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2414, gtest_ar.failure_message()) = ::testing::Message()
;
2415 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2415, gtest_ar.failure_message()) = ::testing::Message()
;
2416 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2416, gtest_ar.failure_message()) = ::testing::Message()
;
2417
2418 // Now, request a correct address. The client should obtain it.
2419 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2420 IOAddress("192.0.2.123"), false, false,
2421 "", false);
2422 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2423 AllocEngine::findReservation(ctx2);
2424 lease = engine.allocateLease4(ctx2);
2425 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2425, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2426 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2426, gtest_ar.failure_message()) = ::testing::Message()
;
2427
2428 // Make sure that the lease has been committed to the lease database.
2429 // And that the committed lease is equal to the one returned.
2430 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2431 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2431, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2432 detailCompareLease(lease, from_mgr);
2433
2434 ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2434, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2435}
2436
2437// This test checks the behavior of the allocation engine in the following
2438// scenario:
2439// - Client has no lease in the database.
2440// - Client has a reservation.
2441// - Client sends DHCPDISCOVER with a requested IP address as a hint.
2442// - Server offers a reserved address, even though it is different than the
2443// requested address.
2444TEST_F(AllocEngine4Test, reservedAddressHintFakeAllocation)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressHintFakeAllocation") >
1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressHintFakeAllocation_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressHintFakeAllocation_Test
() = default; ~AllocEngine4Test_reservedAddressHintFakeAllocation_Test
() override = default; AllocEngine4Test_reservedAddressHintFakeAllocation_Test
(const AllocEngine4Test_reservedAddressHintFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressHintFakeAllocation_Test
& operator=( const AllocEngine4Test_reservedAddressHintFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressHintFakeAllocation_Test
(AllocEngine4Test_reservedAddressHintFakeAllocation_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressHintFakeAllocation_Test
& operator=( AllocEngine4Test_reservedAddressHintFakeAllocation_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHintFakeAllocation_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressHintFakeAllocation", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2444), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2444), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2444), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressHintFakeAllocation_Test
::TestBody()
{
2445 // Create a reservation for the client.
2446 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2447 Host::IDENT_HWADDR, subnet_->getID(),
2448 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2449 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2450 CfgMgr::instance().commit();
2451
2452 AllocEngine engine(0);
2453
2454 // Query the allocation engine for the lease to be assigned to the client
2455 // and specify a hint being a different address than the reserved one.
2456 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2457 IOAddress("192.0.2.234"), false, false,
2458 "", true);
2459 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2460 AllocEngine::findReservation(ctx);
2461 Lease4Ptr lease = engine.allocateLease4(ctx);
2462
2463 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2463, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2464 // Allocation engine should return reserved address.
2465 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2465, gtest_ar.failure_message()) = ::testing::Message()
;
2466
2467 // This is a "fake" allocation so the returned lease should not be committed
2468 // to the lease database.
2469 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2469, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2470
2471 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2471, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
2472}
2473
2474// This test checks that the behavior of the allocation engine in the following
2475// scenario:
2476// - Client has a lease for the address from the dynamic pool in the database.
2477// - Client has a reservation for a different address than the one for which
2478// the client has a lease.
2479// - Client sends DHCPREQUEST, asking for the reserved address (as it has been
2480// offered to it when it sent DHCPDISCOVER).
2481// - Server allocates a reserved address and removes the lease for the address
2482// previously allocated to the client.
2483TEST_F(AllocEngine4Test, reservedAddressExistingLease)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressExistingLease") > 1
, "test_name must not be empty"); class AllocEngine4Test_reservedAddressExistingLease_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressExistingLease_Test
() = default; ~AllocEngine4Test_reservedAddressExistingLease_Test
() override = default; AllocEngine4Test_reservedAddressExistingLease_Test
(const AllocEngine4Test_reservedAddressExistingLease_Test &
) = delete; AllocEngine4Test_reservedAddressExistingLease_Test
& operator=( const AllocEngine4Test_reservedAddressExistingLease_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLease_Test
(AllocEngine4Test_reservedAddressExistingLease_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressExistingLease_Test
& operator=( AllocEngine4Test_reservedAddressExistingLease_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLease_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressExistingLease", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2483), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2483), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2483), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLease_Test
>); void AllocEngine4Test_reservedAddressExistingLease_Test
::TestBody()
{
2484 // Create the reservation for the client.
2485 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2486 Host::IDENT_HWADDR, subnet_->getID(),
2487 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2488 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2489 CfgMgr::instance().commit();
2490
2491 // Create a lease for the client with a different address than the reserved
2492 // one.
2493 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2494 &clientid_->getClientId()[0],
2495 clientid_->getClientId().size(),
2496 100, time(NULL__null), subnet_->getID(),
2497 false, false, ""));
2498 LeaseMgrFactory::instance().addLease(lease);
2499
2500 AllocEngine engine(0);
2501
2502 // Request allocation of the reserved address.
2503 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2504 IOAddress("192.0.2.123"), false, false,
2505 "", false);
2506 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2507 AllocEngine::findReservation(ctx);
2508 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
2509
2510 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2510, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2511 // The engine should have allocated the reserved address.
2512 EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "allocated_lease->addr_.toText()", "192.0.2.123", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2512, gtest_ar.failure_message()) = ::testing::Message()
;
2513
2514 // Make sure that the lease has been committed to the lease database.
2515 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_);
2516 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2516, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2517 detailCompareLease(allocated_lease, from_mgr);
2518
2519 // The previous lease should have been replaced by a new one. The previous
2520 // lease should be returned by the allocation engine to the caller.
2521 ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2521, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2522 EXPECT_EQ("192.0.2.101", ctx.old_lease_->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "ctx.old_lease_->addr_.toText()", "192.0.2.101", ctx.old_lease_
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2522, gtest_ar.failure_message()) = ::testing::Message()
;
2523 detailCompareLease(ctx.old_lease_, lease);
2524}
2525
2526// This test checks that the behavior of the allocation engine in the following
2527// scenario:
2528// - Client A has a lease in the database.
2529// - Client B has a reservation for the address in use by client A.
2530// - Client B sends a DHCPREQUEST requesting the allocation of the reserved
2531// lease (in use by client A).
2532// - Server determines that the reserved address is in use by a different client
2533// and returns DHCPNAK to client B.
2534TEST_F(AllocEngine4Test, reservedAddressHijacked)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressHijacked") > 1, "test_name must not be empty"
); class AllocEngine4Test_reservedAddressHijacked_Test : public
AllocEngine4Test { public: AllocEngine4Test_reservedAddressHijacked_Test
() = default; ~AllocEngine4Test_reservedAddressHijacked_Test(
) override = default; AllocEngine4Test_reservedAddressHijacked_Test
(const AllocEngine4Test_reservedAddressHijacked_Test &) =
delete; AllocEngine4Test_reservedAddressHijacked_Test & operator
=( const AllocEngine4Test_reservedAddressHijacked_Test &)
= delete; AllocEngine4Test_reservedAddressHijacked_Test (AllocEngine4Test_reservedAddressHijacked_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressHijacked_Test
& operator=( AllocEngine4Test_reservedAddressHijacked_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHijacked_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressHijacked", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2534), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2534), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2534), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijacked_Test
>); void AllocEngine4Test_reservedAddressHijacked_Test::TestBody
()
{
2535 // Create host reservation for the client B.
2536 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2537 Host::IDENT_HWADDR, subnet_->getID(),
2538 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2539 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2540 CfgMgr::instance().commit();
2541
2542 // Allocate a lease for the client A for the same address as reserved
2543 // for the client B.
2544 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0,
2545 100, time(NULL__null), subnet_->getID(),
2546 false, false, ""));
2547 LeaseMgrFactory::instance().addLease(lease);
2548
2549 AllocEngine engine(0);
2550
2551 // Try to allocate the reserved lease to client B.
2552 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2553 IOAddress("192.0.2.123"), false, false,
2554 "", false);
2555 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2556 AllocEngine::findReservation(ctx1);
2557 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2558 // The lease is allocated to someone else, so the allocation should not
2559 // succeed.
2560 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2560, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2561 ASSERT_FALSE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx1.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2561, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2562
2563 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2563, gtest_ar.failure_message()) = ::testing::Message()
;
2564 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2564, gtest_ar.failure_message()) = ::testing::Message()
;
2565 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2565, gtest_ar.failure_message()) = ::testing::Message()
;
2566 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2566, gtest_ar.failure_message()) = ::testing::Message()
;
2567 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2567, gtest_ar.failure_message()) = ::testing::Message()
;
2568
2569 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2569, gtest_ar.failure_message()) = ::testing::Message()
;
2570 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2570, gtest_ar.failure_message()) = ::testing::Message()
;
2571 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2571, gtest_ar.failure_message()) = ::testing::Message()
;
2572 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2572, gtest_ar.failure_message()) = ::testing::Message()
;
2573 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2573, gtest_ar.failure_message()) = ::testing::Message()
;
2574
2575 // Make sure that the allocation engine didn't modify the lease of the
2576 // client A.
2577 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2578 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2578, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2579 detailCompareLease(lease, from_mgr);
2580
2581 // Try doing the same thing, but this time do not request any specific
2582 // address. It should have the same effect.
2583 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2584 IOAddress("0.0.0.0"), false, false,
2585 "", false);
2586 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2587 AllocEngine::findReservation(ctx2);
2588 allocated_lease = engine.allocateLease4(ctx2);
2589 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2589, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2590 ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2590, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2591
2592 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2592, gtest_ar.failure_message()) = ::testing::Message()
;
2593 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2593, gtest_ar.failure_message()) = ::testing::Message()
;
2594 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2594, gtest_ar.failure_message()) = ::testing::Message()
;
2595 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2595, gtest_ar.failure_message()) = ::testing::Message()
;
2596 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2596, gtest_ar.failure_message()) = ::testing::Message()
;
2597
2598 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2598, gtest_ar.failure_message()) = ::testing::Message()
;
2599 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2599, gtest_ar.failure_message()) = ::testing::Message()
;
2600 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2600, gtest_ar.failure_message()) = ::testing::Message()
;
2601 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2601, gtest_ar.failure_message()) = ::testing::Message()
;
2602 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2602, gtest_ar.failure_message()) = ::testing::Message()
;
2603
2604 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2605 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2605, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2606 detailCompareLease(lease, from_mgr);
2607}
2608
2609// This test checks that the behavior of the allocation engine in the following
2610// scenario:
2611// - Client A has a lease in the database.
2612// - Client B has a reservation for the address in use by client A.
2613// - Client B sends a DHCPDISCOVER.
2614// - Server determines that the reserved address is in use by a different client
2615// so it offers an address from the dynamic pool.
2616TEST_F(AllocEngine4Test, reservedAddressHijackedFakeAllocation)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressHijackedFakeAllocation"
) > 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
() = default; ~AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
() override = default; AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
(const AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
& operator=( const AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
(AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
& operator=( AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressHijackedFakeAllocation", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2616), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2616), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2616), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
::TestBody()
{
2617 // Create a reservation for the client B.
2618 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2619 Host::IDENT_HWADDR, subnet_->getID(),
2620 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2621 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2622 CfgMgr::instance().commit();
2623
2624 // Create a lease for the client A.
2625 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0,
2626 100, time(NULL__null), subnet_->getID(),
2627 false, false, ""));
2628 LeaseMgrFactory::instance().addLease(lease);
2629
2630 AllocEngine engine(0);
2631
2632 // Query allocation engine for the lease to be allocated to the client B.
2633 // The allocation engine is not able to allocate the lease to the client
2634 // B, because the address is in use by client A.
2635 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2636 IOAddress("192.0.2.123"), false, false,
2637 "", true);
2638 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2639 AllocEngine::findReservation(ctx1);
2640 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2641
2642 // The allocation engine should return a lease but for a different address
2643 // than requested because this address is in use.
2644 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2644, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2645 ASSERT_FALSE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx1.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2645, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2646 EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.123")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("allocated_lease->addr_.toText()"
, "\"192.0.2.123\"", allocated_lease->addr_.toText(), "192.0.2.123"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2646, gtest_ar.failure_message()) = ::testing::Message()
;
2647 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, allocated_lease->addr_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)"
, "false", "true") .c_str()) = ::testing::Message()
;
2648
2649 // Do the same test. But, this time do not specify any address to be
2650 // allocated.
2651 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2652 IOAddress("0.0.0.0"), false, false,
2653 "", true);
2654 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2655 AllocEngine::findReservation(ctx2);
2656 allocated_lease = engine.allocateLease4(ctx2);
2657
2658 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2658, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2659 EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.123")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("allocated_lease->addr_.toText()"
, "\"192.0.2.123\"", allocated_lease->addr_.toText(), "192.0.2.123"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2659, gtest_ar.failure_message()) = ::testing::Message()
;
2660 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, allocated_lease->addr_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2660, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)"
, "false", "true") .c_str()) = ::testing::Message()
;
2661 ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2661, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2662}
2663
2664// This test checks that the behavior of the allocation engine in the following
2665// scenario:
2666// - Client A has an expired lease in the database.
2667// - Client B has a reservation for the address in use by client A.
2668// - Client B sends a DHCPDISCOVER.
2669// - Server determines that the reserved address is in use by a different client
2670// but it is expired and tries to reuse it and fails. It can not allocate a
2671// new lease either as if there is a limit in place.
2672TEST_F(AllocEngine4Test, reservedAddressHijackedFakeAllocationSelectLeaseSkip)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressHijackedFakeAllocationSelectLeaseSkip"
) > 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
() = default; ~AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
() override = default; AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
(const AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
&) = delete; AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
& operator=( const AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
&) = delete; AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
(AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
& operator=( AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressHijackedFakeAllocationSelectLeaseSkip", nullptr
, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2672), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2672), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2672), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
>); void AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
::TestBody()
{
2673 // Create a reservation for the client B.
2674 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2675 Host::IDENT_HWADDR, subnet_->getID(),
2676 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2677 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2678 CfgMgr::instance().commit();
2679
2680 // Create a lease for the client A (which is expired).
2681 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0,
2682 100, time(NULL__null) - 200, subnet_->getID(),
2683 false, false, ""));
2684 LeaseMgrFactory::instance().addLease(lease);
2685
2686 AllocEngine engine(0);
2687
2688 // Create callout which sets NEXT_STEP_SKIP flag.
2689 auto callback = [](CalloutHandle& callout_handle) -> int {
2690 callout_handle.setStatus(CalloutHandle::NEXT_STEP_SKIP);
2691
2692 return (0);
2693 };
2694
2695 // Register the callout for the "lease4_select" hook point.
2696 HooksManager::preCalloutsLibraryHandle().registerCallout("lease4_select", callback);
2697
2698 // Query allocation engine for the lease to be allocated to the client B.
2699 // The allocation engine is not able to allocate the lease to the client
2700 // B, because the address is in use by client A.
2701 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2702 IOAddress("192.0.2.123"), false, false,
2703 "", true);
2704
2705 ctx1.callout_handle_ = HooksManager::createCalloutHandle();
2706
2707 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2708 AllocEngine::findReservation(ctx1);
2709 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2710
2711 // The allocation engine should not return any address as it
2712 // can neither reuse the lease or allocate a new lease.
2713 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2713, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2714 ASSERT_TRUE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx1.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2714, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2715
2716 // Do the same test. But, this time do not specify any address to be
2717 // allocated.
2718 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2719 IOAddress("0.0.0.0"), false, false,
2720 "", true);
2721
2722 ctx2.callout_handle_ = HooksManager::createCalloutHandle();
2723
2724 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2725 AllocEngine::findReservation(ctx2);
2726 allocated_lease = engine.allocateLease4(ctx2);
2727
2728 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2728, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2729 ASSERT_TRUE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx2.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2729, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2730}
2731
2732// This test checks that the behavior of the allocation engine in the following
2733// scenario:
2734// - Client has a reservation.
2735// - Client has a lease in the database for a different address than reserved.
2736// - Client sends a DHCPREQUEST and asks for a different address than reserved,
2737// and different than it has in a database.
2738// - Server doesn't allocate the reserved address to the client because the
2739// client asked for the different address.
2740//
2741// Note that in this case the client should get the DHCPNAK and should fall back
2742// to the DHCPDISCOVER.
2743TEST_F(AllocEngine4Test, reservedAddressExistingLeaseInvalidHint)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressExistingLeaseInvalidHint"
) > 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
() = default; ~AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
() override = default; AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
(const AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
& operator=( const AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
(AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
& operator=( AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressExistingLeaseInvalidHint", nullptr, nullptr
, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2743), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2743), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2743), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
::TestBody()
{
2744 // Create a reservation for the client.
2745 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2746 Host::IDENT_HWADDR, subnet_->getID(),
2747 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2748 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2749 CfgMgr::instance().commit();
2750
2751 // Create a lease for the client for a different address than reserved.
2752 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, ClientIdPtr(),
2753 100, time(NULL__null), subnet_->getID(),
2754 false, false, ""));
2755 LeaseMgrFactory::instance().addLease(lease);
2756
2757 AllocEngine engine(0);
2758
2759 // Try to allocate a lease and specify a different address than reserved
2760 // and different from the one that client is currently using.
2761 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2762 IOAddress("192.0.2.102"), false, false,
2763 "", false);
2764 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2765 AllocEngine::findReservation(ctx1);
2766 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2767 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2767, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2768 ASSERT_FALSE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx1.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2769
2770 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2770, gtest_ar.failure_message()) = ::testing::Message()
;
2771 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2771, gtest_ar.failure_message()) = ::testing::Message()
;
2772 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2772, gtest_ar.failure_message()) = ::testing::Message()
;
2773 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2773, gtest_ar.failure_message()) = ::testing::Message()
;
2774 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2774, gtest_ar.failure_message()) = ::testing::Message()
;
2775
2776 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2776, gtest_ar.failure_message()) = ::testing::Message()
;
2777 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2777, gtest_ar.failure_message()) = ::testing::Message()
;
2778 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2778, gtest_ar.failure_message()) = ::testing::Message()
;
2779 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2779, gtest_ar.failure_message()) = ::testing::Message()
;
2780 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2780, gtest_ar.failure_message()) = ::testing::Message()
;
2781
2782 // Repeat the test, but this time ask for the address that the client
2783 // has allocated.
2784 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2785 IOAddress("192.0.2.101"), false, false,
2786 "", false);
2787 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2788 AllocEngine::findReservation(ctx2);
2789 allocated_lease = engine.allocateLease4(ctx2);
2790 // The client has reservation so the server wants to allocate a
2791 // reserved address and doesn't want to renew the address that the
2792 // client is currently using. This is equivalent of the case when
2793 // the client tries to renew the lease but there is a new reservation
2794 // for this client. The server doesn't allow for the renewal and
2795 // responds with DHCPNAK to force the client to return to the
2796 // DHCP server discovery.
2797 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2797, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2798 ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2798, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2799
2800 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2800, gtest_ar.failure_message()) = ::testing::Message()
;
2801 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2801, gtest_ar.failure_message()) = ::testing::Message()
;
2802 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2802, gtest_ar.failure_message()) = ::testing::Message()
;
2803 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2803, gtest_ar.failure_message()) = ::testing::Message()
;
2804 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2804, gtest_ar.failure_message()) = ::testing::Message()
;
2805
2806 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2806, gtest_ar.failure_message()) = ::testing::Message()
;
2807 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2807, gtest_ar.failure_message()) = ::testing::Message()
;
2808 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2808, gtest_ar.failure_message()) = ::testing::Message()
;
2809 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2809, gtest_ar.failure_message()) = ::testing::Message()
;
2810 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2810, gtest_ar.failure_message()) = ::testing::Message()
;
2811}
2812
2813// This test checks that the behavior of the allocation engine in the following
2814// scenario:
2815// - Client has a lease in the database.
2816// - Client has a reservation for a different address than the one for which it
2817// has a lease.
2818// - Client sends a DHCPDISCOVER and asks for a different address than reserved
2819// and different from which it has a lease for.
2820// - Server ignores the client's hint and offers a reserved address.
2821TEST_F(AllocEngine4Test, reservedAddressExistingLeaseFakeAllocation)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressExistingLeaseFakeAllocation"
) > 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
() = default; ~AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
() override = default; AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
(const AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
& operator=( const AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
(AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
& operator=( AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressExistingLeaseFakeAllocation", nullptr, nullptr
, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2821), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2821), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2821), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
::TestBody()
{
2822 // Create a reservation for the client.
2823 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2824 Host::IDENT_HWADDR, subnet_->getID(),
2825 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2826 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2827 CfgMgr::instance().commit();
2828
2829 // Create a lease for a different address than reserved.
2830 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2831 &clientid_->getClientId()[0],
2832 clientid_->getClientId().size(),
2833 100, time(NULL__null), subnet_->getID(),
2834 false, false, ""));
2835 LeaseMgrFactory::instance().addLease(lease);
2836
2837 AllocEngine engine(0);
2838
2839 // Try to allocate a lease and use a completely different address
2840 // as a hint.
2841 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2842 IOAddress("192.0.2.102"), false, false,
2843 "", true);
2844 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2845 AllocEngine::findReservation(ctx1);
2846 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2847
2848 // Server should offer a lease for a reserved address.
2849 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2849, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2850 EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "allocated_lease->addr_.toText()", "192.0.2.123", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2850, gtest_ar.failure_message()) = ::testing::Message()
;
2851
2852 // The lease should not be allocated until the client sends a DHCPREQUEST.
2853 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(allocated_lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(allocated_lease->addr_)))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2853, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)"
, "true", "false") .c_str()) = ::testing::Message()
;
2854
2855 // Old lease should contain the currently used lease.
2856 ASSERT_TRUE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx1.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2856, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2857 EXPECT_EQ("192.0.2.101", ctx1.old_lease_->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "ctx1.old_lease_->addr_.toText()", "192.0.2.101", ctx1.old_lease_
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2857, gtest_ar.failure_message()) = ::testing::Message()
;
2858
2859 // Repeat the test but this time ask for the address for which the
2860 // client has a lease.
2861 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2862 IOAddress("192.0.2.101"), false, false,
2863 "", true);
2864 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2865 AllocEngine::findReservation(ctx2);
2866 allocated_lease = engine.allocateLease4(ctx2);
2867
2868 // The server should offer the lease, but not for the address that
2869 // the client requested. The server should offer a reserved address.
2870 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2870, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2871 EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "allocated_lease->addr_.toText()", "192.0.2.123", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2871, gtest_ar.failure_message()) = ::testing::Message()
;
2872
2873 // Old lease should contain the currently used lease.
2874 ASSERT_TRUE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx2.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2874, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2875 EXPECT_EQ("192.0.2.101", ctx2.old_lease_->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "ctx2.old_lease_->addr_.toText()", "192.0.2.101", ctx2.old_lease_
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2875, gtest_ar.failure_message()) = ::testing::Message()
;
2876}
2877
2878// This test checks that the behavior of the allocation engine in the following
2879// scenario:
2880// - Client has a reservation.
2881// - Client has a lease for a different address than reserved.
2882// - Client sends a DHCPREQUEST to allocate a lease.
2883// - The server determines that the client has a reservation for the
2884// different address than it is currently using and should assign
2885// a reserved address and remove the previous lease.
2886TEST_F(AllocEngine4Test, reservedAddressExistingLeaseNoHint)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressExistingLeaseNoHint")
> 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
() = default; ~AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
() override = default; AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
(const AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
& operator=( const AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
(AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
& operator=( AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressExistingLeaseNoHint", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2886), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2886), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2886), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
::TestBody()
{
2887 // Create a reservation.
2888 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2889 Host::IDENT_HWADDR, subnet_->getID(),
2890 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2891 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2892 CfgMgr::instance().commit();
2893
2894 // Create a lease for a different address than reserved.
2895 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2896 &clientid_->getClientId()[0],
2897 clientid_->getClientId().size(),
2898 100, time(NULL__null), subnet_->getID(),
2899 false, false, ""));
2900 LeaseMgrFactory::instance().addLease(lease);
2901
2902 AllocEngine engine(0);
2903
2904 // Try to allocate a lease with providing no hint.
2905 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2906 IOAddress("0.0.0.0"), false, false,
2907 "", false);
2908 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2909 AllocEngine::findReservation(ctx);
2910 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
2911
2912 // The reserved address should be allocated.
2913 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2913, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2914 EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "allocated_lease->addr_.toText()", "192.0.2.123", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2914, gtest_ar.failure_message()) = ::testing::Message()
;
2915
2916 // The previous lease should be removed.
2917 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2917, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2918
2919 // Make sure that the allocated lease is committed in the lease database.
2920 Lease4Ptr from_mgr =
2921 LeaseMgrFactory::instance().getLease4(allocated_lease->addr_);
2922 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2922, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2923 detailCompareLease(allocated_lease, from_mgr);
2924
2925 // Old lease should be returned.
2926 ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2926, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2927 detailCompareLease(lease, ctx.old_lease_);
2928}
2929
2930// This test checks that the behavior of the allocation engine in the following
2931// scenario:
2932// - Client has a reservation.
2933// - Client has a lease for a different address than reserved.
2934// - Client sends a DHCPDISCOVER with no hint.
2935// - Server determines that there is a reservation for the client and that
2936// the reserved address should be offered when the client sends a
2937// DHCPDISCOVER.
2938TEST_F(AllocEngine4Test, reservedAddressExistingLeaseNoHintFakeAllocation)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressExistingLeaseNoHintFakeAllocation"
) > 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
() = default; ~AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
() override = default; AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
(const AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
& operator=( const AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
(AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
&&) noexcept = delete; AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
& operator=( AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressExistingLeaseNoHintFakeAllocation", nullptr
, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2938), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2938), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2938), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
::TestBody()
{
2939 // Create a reservation.
2940 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2941 Host::IDENT_HWADDR, subnet_->getID(),
2942 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2943 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2944 CfgMgr::instance().commit();
2945
2946 // Create a lease for a different address than reserved.
2947 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2948 &clientid_->getClientId()[0],
2949 clientid_->getClientId().size(),
2950 100, time(NULL__null), subnet_->getID(),
2951 false, false, ""));
2952 LeaseMgrFactory::instance().addLease(lease);
2953
2954 AllocEngine engine(0);
2955
2956 // Query the allocation engine for the lease to be allocated for the
2957 // client.
2958 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2959 IOAddress("0.0.0.0"), false, false,
2960 "", true);
2961 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2962 AllocEngine::findReservation(ctx);
2963 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
2964
2965 // The server should offer the reserved address.
2966 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2966, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2967 EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "allocated_lease->addr_.toText()", "192.0.2.123", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2967, gtest_ar.failure_message()) = ::testing::Message()
;
2968
2969 // The lease should not be committed to the lease database until the
2970 // client sends a DHCPREQUEST.
2971 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(allocated_lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(allocated_lease->addr_)))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
2971, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)"
, "true", "false") .c_str()) = ::testing::Message()
;
2972
2973 // The old lease should reflect what is in the database.
2974 ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2974, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2975 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2976 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2976, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2977 detailCompareLease(lease, from_mgr);
2978}
2979
2980// This test checks that the behavior of the allocation engine in the following
2981// scenario:
2982// - Client A has a lease for the address.
2983// - Client B has a reservation for the same address that the Client A is using.
2984// - Client B requests allocation of the reserved address.
2985// - Server returns DHCPNAK to the client to indicate that the requested address
2986// can't be allocated.
2987// - Client A renews the lease.
2988// - Server determines that the lease that the Client A is trying to renew
2989// is for the address reserved for Client B. Therefore, the server returns
2990// DHCPNAK to force the client to return to the server discovery.
2991// - The Client A sends DHCPDISCOVER.
2992// - The server offers an address to the Client A, which is different than
2993// the address reserved for Client B.
2994// - The Client A requests allocation of the offered address.
2995// - The server allocates the new address to Client A.
2996// - The Client B sends DHCPDISCOVER to the server.
2997// - The server offers a reserved address to the Client B.
2998// - The Client B requests the offered address.
2999// - The server allocates the reserved address to the Client B.
3000TEST_F(AllocEngine4Test, reservedAddressConflictResolution)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressConflictResolution") >
1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressConflictResolution_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressConflictResolution_Test
() = default; ~AllocEngine4Test_reservedAddressConflictResolution_Test
() override = default; AllocEngine4Test_reservedAddressConflictResolution_Test
(const AllocEngine4Test_reservedAddressConflictResolution_Test
&) = delete; AllocEngine4Test_reservedAddressConflictResolution_Test
& operator=( const AllocEngine4Test_reservedAddressConflictResolution_Test
&) = delete; AllocEngine4Test_reservedAddressConflictResolution_Test
(AllocEngine4Test_reservedAddressConflictResolution_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressConflictResolution_Test
& operator=( AllocEngine4Test_reservedAddressConflictResolution_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressConflictResolution_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressConflictResolution", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3000), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3000), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3000), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressConflictResolution_Test
>); void AllocEngine4Test_reservedAddressConflictResolution_Test
::TestBody()
{
3001 // Create a reservation for client B.
3002 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(),
3003 Host::IDENT_HWADDR, subnet_->getID(),
3004 SUBNET_ID_UNUSED, IOAddress("192.0.2.101")));
3005 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3006 CfgMgr::instance().commit();
3007
3008 // Create a lease for Client A.
3009 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
3010 &clientid_->getClientId()[0],
3011 clientid_->getClientId().size(),
3012 100, time(NULL__null), subnet_->getID(),
3013 false, false, ""));
3014 LeaseMgrFactory::instance().addLease(lease);
3015
3016 AllocEngine engine(0);
3017
3018 // Client B sends a DHCPREQUEST to allocate a reserved lease. The
3019 // allocation engine can't allocate a reserved lease for this client
3020 // because this specific address is in use by the Client A.
3021 AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr2_,
3022 IOAddress("192.0.2.101"), false, false,
3023 "", false);
3024 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3025 AllocEngine::findReservation(ctx1);
3026 Lease4Ptr offered_lease = engine.allocateLease4(ctx1);
3027 ASSERT_FALSE(offered_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(offered_lease))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3027, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "offered_lease", "true", "false") .c_str()) = ::testing::Message
()
;
3028
3029 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3029, gtest_ar.failure_message()) = ::testing::Message()
;
3030 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3030, gtest_ar.failure_message()) = ::testing::Message()
;
3031 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3031, gtest_ar.failure_message()) = ::testing::Message()
;
3032 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3032, gtest_ar.failure_message()) = ::testing::Message()
;
3033 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3033, gtest_ar.failure_message()) = ::testing::Message()
;
3034
3035 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3035, gtest_ar.failure_message()) = ::testing::Message()
;
3036 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3036, gtest_ar.failure_message()) = ::testing::Message()
;
3037 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3037, gtest_ar.failure_message()) = ::testing::Message()
;
3038 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3038, gtest_ar.failure_message()) = ::testing::Message()
;
3039 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3039, gtest_ar.failure_message()) = ::testing::Message()
;
3040
3041 // Client A tries to renew the lease. The renewal should fail because
3042 // server detects that Client A doesn't have reservation for this
3043 // address.
3044 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
3045 IOAddress("192.0.2.101"), false, false,
3046 "", false);
3047 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3048 AllocEngine::findReservation(ctx2);
3049 ASSERT_FALSE(engine.allocateLease4(ctx2))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(engine.allocateLease4
(ctx2)))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3049, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine.allocateLease4(ctx2)", "true", "false") .c_str()) =
::testing::Message()
;
3050 ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3050, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
3051
3052 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3052, gtest_ar.failure_message()) = ::testing::Message()
;
3053 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3053, gtest_ar.failure_message()) = ::testing::Message()
;
3054 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3054, gtest_ar.failure_message()) = ::testing::Message()
;
3055 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3055, gtest_ar.failure_message()) = ::testing::Message()
;
3056 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3056, gtest_ar.failure_message()) = ::testing::Message()
;
3057
3058 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3058, gtest_ar.failure_message()) = ::testing::Message()
;
3059 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3059, gtest_ar.failure_message()) = ::testing::Message()
;
3060 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3060, gtest_ar.failure_message()) = ::testing::Message()
;
3061 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3061, gtest_ar.failure_message()) = ::testing::Message()
;
3062 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3062, gtest_ar.failure_message()) = ::testing::Message()
;
3063
3064 // Client A returns to DHCPDISCOVER and should be offered a lease.
3065 // The offered lease address must be different than the one the
3066 // Client B has reservation for.
3067 AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_,
3068 IOAddress("192.0.2.101"), false, false,
3069 "", true);
3070 ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3071 AllocEngine::findReservation(ctx3);
3072 offered_lease = engine.allocateLease4(ctx3);
3073 ASSERT_TRUE(offered_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(offered_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3073, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "offered_lease", "false", "true") .c_str()) = ::testing::Message
()
;
3074 EXPECT_NE(offered_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("offered_lease->addr_.toText()"
, "\"192.0.2.101\"", offered_lease->addr_.toText(), "192.0.2.101"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3074, gtest_ar.failure_message()) = ::testing::Message()
;
3075
3076 // Client A tries to acquire the lease. It should succeed. At this point
3077 // the previous lease should be released and become available for the
3078 // Client B.
3079 AllocEngine::ClientContext4 ctx4(subnet_, clientid_, hwaddr_,
3080 offered_lease->addr_, false, false,
3081 "", false);
3082 ctx4.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3083 AllocEngine::findReservation(ctx4);
3084 Lease4Ptr allocated_lease = engine.allocateLease4(ctx4);
3085
3086 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3086, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3087 EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("allocated_lease->addr_.toText()"
, "\"192.0.2.101\"", allocated_lease->addr_.toText(), "192.0.2.101"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3087, gtest_ar.failure_message()) = ::testing::Message()
;
3088
3089 // Client B tries to get the lease again. It should be offered
3090 // a reserved lease.
3091 AllocEngine::ClientContext4 ctx5(subnet_, ClientIdPtr(), hwaddr2_,
3092 IOAddress("0.0.0.0"), false, false,
3093 "", true);
3094 ctx5.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3095 AllocEngine::findReservation(ctx5);
3096 offered_lease = engine.allocateLease4(ctx5);
3097
3098 ASSERT_TRUE(offered_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(offered_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3098, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "offered_lease", "false", "true") .c_str()) = ::testing::Message
()
;
3099 EXPECT_EQ("192.0.2.101", offered_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "offered_lease->addr_.toText()", "192.0.2.101", offered_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3099, gtest_ar.failure_message()) = ::testing::Message()
;
3100
3101 // Client B requests allocation of the lease and it should succeed.
3102 AllocEngine::ClientContext4 ctx6(subnet_, ClientIdPtr(), hwaddr2_,
3103 offered_lease->addr_, false, false,
3104 "", false);
3105 ctx6.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3106 allocated_lease = engine.allocateLease4(ctx6);
3107
3108 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3108, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3109 EXPECT_EQ("192.0.2.101", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\""
, "allocated_lease->addr_.toText()", "192.0.2.101", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3109, gtest_ar.failure_message()) = ::testing::Message()
;
3110}
3111
3112// This test checks that the address is not assigned from the dynamic
3113// pool if it has been reserved for another client.
3114TEST_F(AllocEngine4Test, reservedAddressVsDynamicPool)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressVsDynamicPool") > 1
, "test_name must not be empty"); class AllocEngine4Test_reservedAddressVsDynamicPool_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressVsDynamicPool_Test
() = default; ~AllocEngine4Test_reservedAddressVsDynamicPool_Test
() override = default; AllocEngine4Test_reservedAddressVsDynamicPool_Test
(const AllocEngine4Test_reservedAddressVsDynamicPool_Test &
) = delete; AllocEngine4Test_reservedAddressVsDynamicPool_Test
& operator=( const AllocEngine4Test_reservedAddressVsDynamicPool_Test
&) = delete; AllocEngine4Test_reservedAddressVsDynamicPool_Test
(AllocEngine4Test_reservedAddressVsDynamicPool_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressVsDynamicPool_Test
& operator=( AllocEngine4Test_reservedAddressVsDynamicPool_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressVsDynamicPool_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressVsDynamicPool", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3114), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3114), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3114), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressVsDynamicPool_Test
>); void AllocEngine4Test_reservedAddressVsDynamicPool_Test
::TestBody()
{
3115 // Create a reservation for the client.
3116 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3117 Host::IDENT_HWADDR, subnet_->getID(),
3118 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3119 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3120 CfgMgr::instance().commit();
3121
3122 AllocEngine engine(0);
3123
3124 // Different client tries to allocate a lease. Note, that we're using
3125 // an iterative allocator which would pick the first address from the
3126 // dynamic pool, i.e. 192.0.2.100. This address is reserved so we expect
3127 // that a different address will be allocated.
3128 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
3129 IOAddress("0.0.0.0"), false, false,
3130 "", false);
3131 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3132 AllocEngine::findReservation(ctx);
3133 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
3134
3135 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3135, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3136 EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("allocated_lease->addr_.toText()"
, "\"192.0.2.100\"", allocated_lease->addr_.toText(), "192.0.2.100"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3136, gtest_ar.failure_message()) = ::testing::Message()
;
3137
3138 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_);
3139 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3140 detailCompareLease(allocated_lease, from_mgr);
3141}
3142
3143// This test checks that the client requesting an address which is
3144// reserved for another client will get no lease or a different
3145// address will be assigned if the client is sending a DHCPDISCOVER.
3146TEST_F(AllocEngine4Test, reservedAddressHintUsedByOtherClient)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressHintUsedByOtherClient"
) > 1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
() = default; ~AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
() override = default; AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
(const AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
&) = delete; AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
& operator=( const AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
&) = delete; AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
(AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
& operator=( AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressHintUsedByOtherClient", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3146), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3146), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3146), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
>); void AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
::TestBody()
{
3147 // Create a reservation for the client.
3148 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3149 Host::IDENT_HWADDR, subnet_->getID(),
3150 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3151 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3152 CfgMgr::instance().commit();
3153
3154 AllocEngine engine(0);
3155
3156 // Different client is requesting this address.
3157 AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_,
3158 IOAddress("192.0.2.100"), false, false,
3159 "", false);
3160 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3161 AllocEngine::findReservation(ctx1);
3162 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
3163
3164 // The client should get no lease (DHCPNAK).
3165 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3165, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
3166
3167 EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")"
, 0, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3167, gtest_ar.failure_message()) = ::testing::Message()
;
3168 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3168, gtest_ar.failure_message()) = ::testing::Message()
;
3169 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")"
, 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3169, gtest_ar.failure_message()) = ::testing::Message()
;
3170 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3170, gtest_ar.failure_message()) = ::testing::Message()
;
3171 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3171, gtest_ar.failure_message()) = ::testing::Message()
;
3172
3173 EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3173, gtest_ar.failure_message()) = ::testing::Message()
;
3174 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3174, gtest_ar.failure_message()) = ::testing::Message()
;
3175 EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3175, gtest_ar.failure_message()) = ::testing::Message()
;
3176 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3176, gtest_ar.failure_message()) = ::testing::Message()
;
3177 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3177, gtest_ar.failure_message()) = ::testing::Message()
;
3178
3179 // The same client should get a different lease than requested if
3180 // if is sending a DHCPDISCOVER (fake allocation is true).
3181 AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_,
3182 IOAddress("192.0.2.100"), false, false,
3183 "", true);
3184 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3185 AllocEngine::findReservation(ctx2);
3186 allocated_lease = engine.allocateLease4(ctx2);
3187
3188 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3188, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3189 // Make sure the lease obtained is for a different address.
3190 EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100")switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("allocated_lease->addr_.toText()"
, "\"192.0.2.100\"", allocated_lease->addr_.toText(), "192.0.2.100"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3190, gtest_ar.failure_message()) = ::testing::Message()
;
3191}
3192
3193// This test checks that the allocation engine refuses to allocate an
3194// address when the pool is exhausted, and the only available
3195// address is reserved for a different client.
3196TEST_F(AllocEngine4Test, reservedAddressShortPool)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressShortPool") > 1, "test_name must not be empty"
); class AllocEngine4Test_reservedAddressShortPool_Test : public
AllocEngine4Test { public: AllocEngine4Test_reservedAddressShortPool_Test
() = default; ~AllocEngine4Test_reservedAddressShortPool_Test
() override = default; AllocEngine4Test_reservedAddressShortPool_Test
(const AllocEngine4Test_reservedAddressShortPool_Test &)
= delete; AllocEngine4Test_reservedAddressShortPool_Test &
operator=( const AllocEngine4Test_reservedAddressShortPool_Test
&) = delete; AllocEngine4Test_reservedAddressShortPool_Test
(AllocEngine4Test_reservedAddressShortPool_Test &&) noexcept
= delete; AllocEngine4Test_reservedAddressShortPool_Test &
operator=( AllocEngine4Test_reservedAddressShortPool_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_reservedAddressShortPool_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressShortPool", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3196), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3196), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3196), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressShortPool_Test
>); void AllocEngine4Test_reservedAddressShortPool_Test::TestBody
()
{
3197 AllocEngine engine(0);
3198
3199 // Create short pool with only one address.
3200 initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100"));
3201 // Reserve the address for a different client.
3202 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(),
3203 Host::IDENT_HWADDR, subnet_->getID(),
3204 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3205 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3206 CfgMgr::instance().commit();
3207
3208 // Allocation engine should determine that the available address is
3209 // reserved for someone else and not allocate it.
3210 AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_,
3211 IOAddress("0.0.0.0"), false, false,
3212 "", false);
3213 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3214 AllocEngine::findReservation(ctx1);
3215 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
3216
3217 ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3217, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
3218
3219 EXPECT_EQ(1, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\")"
, 1, getStatistics("v4-allocation-fail")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3219, gtest_ar.failure_message()) = ::testing::Message()
;
3220 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")"
, 0, getStatistics("v4-allocation-fail-shared-network")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3220, gtest_ar.failure_message()) = ::testing::Message()
;
3221 EXPECT_EQ(1, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-subnet\")"
, 1, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3221, gtest_ar.failure_message()) = ::testing::Message()
;
3222 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")"
, 0, getStatistics("v4-allocation-fail-no-pools")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3222, gtest_ar.failure_message()) = ::testing::Message()
;
3223 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")"
, 0, getStatistics("v4-allocation-fail-classes")))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3223, gtest_ar.failure_message()) = ::testing::Message()
;
3224
3225 EXPECT_EQ(1, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\", subnet_->getID())"
, 1, getStatistics("v4-allocation-fail", subnet_->getID())
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3225, gtest_ar.failure_message()) = ::testing::Message()
;
3226 EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-shared-network", subnet_
->getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3226, gtest_ar.failure_message()) = ::testing::Message()
;
3227 EXPECT_EQ(1, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())"
, 1, getStatistics("v4-allocation-fail-subnet", subnet_->getID
())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3227, gtest_ar.failure_message()) = ::testing::Message()
;
3228 EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-no-pools", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3228, gtest_ar.failure_message()) = ::testing::Message()
;
3229 EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())"
, 0, getStatistics("v4-allocation-fail-classes", subnet_->
getID())))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3229, gtest_ar.failure_message()) = ::testing::Message()
;
3230
3231 // Now, let's remove the reservation.
3232 initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100"));
3233 CfgMgr::instance().commit();
3234
3235 // Address should be successfully allocated.
3236 AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_,
3237 IOAddress("0.0.0.0"), false, false,
3238 "", false);
3239 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3240 AllocEngine::findReservation(ctx2);
3241 allocated_lease = engine.allocateLease4(ctx2);
3242
3243 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3243, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3244 EXPECT_EQ("192.0.2.100", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.100\""
, "allocated_lease->addr_.toText()", "192.0.2.100", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3244, gtest_ar.failure_message()) = ::testing::Message()
;
3245}
3246
3247// This test checks that the AllocEngine allocates an address from the
3248// dynamic pool if the client's reservation is made for a hostname but
3249// not for an address.
3250TEST_F(AllocEngine4Test, reservedHostname)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedHostname") > 1, "test_name must not be empty"
); class AllocEngine4Test_reservedHostname_Test : public AllocEngine4Test
{ public: AllocEngine4Test_reservedHostname_Test() = default
; ~AllocEngine4Test_reservedHostname_Test() override = default
; AllocEngine4Test_reservedHostname_Test (const AllocEngine4Test_reservedHostname_Test
&) = delete; AllocEngine4Test_reservedHostname_Test &
operator=( const AllocEngine4Test_reservedHostname_Test &
) = delete; AllocEngine4Test_reservedHostname_Test (AllocEngine4Test_reservedHostname_Test
&&) noexcept = delete; AllocEngine4Test_reservedHostname_Test
& operator=( AllocEngine4Test_reservedHostname_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_reservedHostname_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedHostname", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3250), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3250), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3250), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedHostname_Test
>); void AllocEngine4Test_reservedHostname_Test::TestBody(
)
{
3251 AllocEngine engine(0);
3252
3253 // Create a reservation for a hostname. Address is set to 0 which
3254 // indicates that there is no reservation.
3255 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3256 Host::IDENT_HWADDR, subnet_->getID(),
3257 SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(),
3258 "foo.example.org"));
3259 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3260 CfgMgr::instance().commit();
3261
3262 // Try to allocate a lease.
3263 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
3264 IOAddress("192.0.2.109"), false, false,
3265 "foo.example.org", true);
3266 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3267 AllocEngine::findReservation(ctx);
3268 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
3269 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3269, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3270 ASSERT_FALSE(allocated_lease->addr_.isV4Zero())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(allocated_lease->
addr_.isV4Zero()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3270, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease->addr_.isV4Zero()", "true", "false") .c_str
()) = ::testing::Message()
;
3271 ASSERT_EQ("192.0.2.109", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.109\""
, "allocated_lease->addr_.toText()", "192.0.2.109", allocated_lease
->addr_.toText()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3271, gtest_ar.failure_message()) = ::testing::Message()
;
3272
3273 ctx.requested_address_ = allocated_lease->addr_;
3274 ctx.fake_allocation_ = false;
3275 allocated_lease = engine.allocateLease4(ctx);
3276 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3276, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3277 EXPECT_EQ("192.0.2.109", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.109\""
, "allocated_lease->addr_.toText()", "192.0.2.109", allocated_lease
->addr_.toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3277, gtest_ar.failure_message()) = ::testing::Message()
;
3278}
3279
3280// This test checks that the AllocEngine::findReservation method finds
3281// and returns host reservation for the DHCPv4 client using the data from
3282// the client context. If the host reservation can't be found, it sets
3283// the value of NULL in the host_ field of the client context.
3284TEST_F(AllocEngine4Test, findReservation)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("findReservation") > 1, "test_name must not be empty"
); class AllocEngine4Test_findReservation_Test : public AllocEngine4Test
{ public: AllocEngine4Test_findReservation_Test() = default;
~AllocEngine4Test_findReservation_Test() override = default;
AllocEngine4Test_findReservation_Test (const AllocEngine4Test_findReservation_Test
&) = delete; AllocEngine4Test_findReservation_Test &
operator=( const AllocEngine4Test_findReservation_Test &
) = delete; AllocEngine4Test_findReservation_Test (AllocEngine4Test_findReservation_Test
&&) noexcept = delete; AllocEngine4Test_findReservation_Test
& operator=( AllocEngine4Test_findReservation_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_findReservation_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "findReservation", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 3284
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3284), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3284), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_findReservation_Test
>); void AllocEngine4Test_findReservation_Test::TestBody()
{
3285 // Create the instance of the allocation engine.
3286 AllocEngine engine(0);
3287
3288 // Context is required to call the AllocEngine::findReservation.
3289 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3290 IOAddress("0.0.0.0"), false, false,
3291 "", false);
3292 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3293 ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_);
3294 ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getClientId());
3295
3296 // There is no reservation in the database so no host should be returned.
3297 ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.findReservation(ctx); } else static_assert(true, "");
} catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3297
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3297
; } } else gtest_label_testnothrow_3297 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3297, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3298 EXPECT_FALSE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.currentHost()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3299
3300 // Create a reservation for the client.
3301 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3302 Host::IDENT_HWADDR, subnet_->getID(),
3303 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3304 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3305 CfgMgr::instance().commit();
3306
3307 // This time the reservation should be returned.
3308 ctx.hosts_.clear();
3309 ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.findReservation(ctx); } else static_assert(true, "");
} catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3309
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3309
; } } else gtest_label_testnothrow_3309 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3309, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3310 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3310, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3311 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3311, gtest_ar.failure_message()) = ::testing::Message()
;
3312
3313 // It shouldn't be returned when reservations-in-subnet is disabled.
3314 subnet_->setReservationsInSubnet(false);
3315 ctx.hosts_.clear();
3316 ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.findReservation(ctx); } else static_assert(true, "");
} catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3316
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3316
; } } else gtest_label_testnothrow_3316 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3316, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3317 EXPECT_FALSE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.currentHost()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3317, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3318
3319 // Check the reservations-in-subnet and reservations-out-of-pool flags.
3320 subnet_->setReservationsInSubnet(true);
3321 subnet_->setReservationsOutOfPool(true);
3322 ctx.hosts_.clear();
3323 ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.findReservation(ctx); } else static_assert(true, "");
} catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3323
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3323
; } } else gtest_label_testnothrow_3323 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3323, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3324 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3324, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3325 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3325, gtest_ar.failure_message()) = ::testing::Message()
;
3326
3327 // This time use the client identifier to search for the host.
3328 host.reset(new Host(&clientid_->getClientId()[0],
3329 clientid_->getClientId().size(),
3330 Host::IDENT_DUID, subnet_->getID(),
3331 SUBNET_ID_UNUSED, IOAddress("192.0.2.101")));
3332 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3333 CfgMgr::instance().commit();
3334
3335 ctx.hosts_.clear();
3336 ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.findReservation(ctx); } else static_assert(true, "");
} catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3336
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3336
; } } else gtest_label_testnothrow_3336 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3336, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3337 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3337, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3338 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3338, gtest_ar.failure_message()) = ::testing::Message()
;
3339
3340 // Remove the subnet. Subnet id is required to find host reservations, so
3341 // if it is set to NULL, no reservation should be returned
3342 ctx.subnet_.reset();
3343 ctx.hosts_.clear();
3344 ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.findReservation(ctx); } else static_assert(true, "");
} catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3344
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3344
; } } else gtest_label_testnothrow_3344 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3344, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3345 EXPECT_FALSE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.currentHost()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3345, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3346
3347 // The same if there is a mismatch of the subnet id between the reservation
3348 // and the context.
3349 ctx.subnet_ = subnet_;
3350 host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3351 Host::IDENT_HWADDR, subnet_->getID() + 1,
3352 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3353 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3354 CfgMgr::instance().commit();
3355
3356 ctx.hosts_.clear();
3357 ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.findReservation(ctx); } else static_assert(true, "");
} catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3357
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3357
; } } else gtest_label_testnothrow_3357 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3357, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3358 EXPECT_FALSE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.currentHost()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3358, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3359}
3360
3361// This test checks if the simple IPv4 allocation can succeed and that
3362// statistic for allocated addresses is increased appropriately.
3363TEST_F(AllocEngine4Test, simpleAlloc4Stats)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("simpleAlloc4Stats") > 1, "test_name must not be empty"
); class AllocEngine4Test_simpleAlloc4Stats_Test : public AllocEngine4Test
{ public: AllocEngine4Test_simpleAlloc4Stats_Test() = default
; ~AllocEngine4Test_simpleAlloc4Stats_Test() override = default
; AllocEngine4Test_simpleAlloc4Stats_Test (const AllocEngine4Test_simpleAlloc4Stats_Test
&) = delete; AllocEngine4Test_simpleAlloc4Stats_Test &
operator=( const AllocEngine4Test_simpleAlloc4Stats_Test &
) = delete; AllocEngine4Test_simpleAlloc4Stats_Test (AllocEngine4Test_simpleAlloc4Stats_Test
&&) noexcept = delete; AllocEngine4Test_simpleAlloc4Stats_Test
& operator=( AllocEngine4Test_simpleAlloc4Stats_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_simpleAlloc4Stats_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "simpleAlloc4Stats", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3363), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3363), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3363), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4Stats_Test
>); void AllocEngine4Test_simpleAlloc4Stats_Test::TestBody
()
{
3364 boost::scoped_ptr<AllocEngine> engine;
3365 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3365
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3365
; } } else gtest_label_testnothrow_3365 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3365, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3366 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3366, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
3367
3368 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
3369 false, true, "somehost.example.com.", false);
3370 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3371
3372 // Let's pretend 100 addresses were allocated already
3373 string name = StatsMgr::generateName("subnet", subnet_->getID(),
3374 "assigned-addresses");
3375 StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
3376 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
3377 subnet_->getID());
3378
3379 int64_t glbl_assigned = getStatistics("assigned-addresses");
3380 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
3381
3382 Lease4Ptr lease = engine->allocateLease4(ctx);
3383 // The new lease has been allocated, so the old lease should not exist.
3384 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3384, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3385
3386 // Check that we got a lease
3387 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3387, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3388
3389 // The statistic should be there and it should be increased by 1 (to 101).
3390 ObservationPtr stat = StatsMgr::instance().getObservation(name);
3391 ASSERT_TRUE(stat)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(stat)) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3391, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "stat", "false", "true") .c_str()) = ::testing::Message()
;
3392 EXPECT_EQ(101, stat->getInteger().first)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("101", "stat->getInteger().first"
, 101, stat->getInteger().first))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3392, gtest_ar.failure_message()) = ::testing::Message()
;
3393 cumulative += 1;
3394 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3395, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
3395 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3395, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
3396 glbl_assigned += 1;
3397 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3397, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
3398 glbl_cumulative += 1;
3399 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3399, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
3400}
3401
3402// This test checks if the fake allocation (for DHCPDISCOVER) can succeed
3403// and that it doesn't increase allocated-addresses statistic.
3404TEST_F(AllocEngine4Test, fakeAlloc4Stat)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("fakeAlloc4Stat") > 1, "test_name must not be empty"
); class AllocEngine4Test_fakeAlloc4Stat_Test : public AllocEngine4Test
{ public: AllocEngine4Test_fakeAlloc4Stat_Test() = default; ~
AllocEngine4Test_fakeAlloc4Stat_Test() override = default; AllocEngine4Test_fakeAlloc4Stat_Test
(const AllocEngine4Test_fakeAlloc4Stat_Test &) = delete;
AllocEngine4Test_fakeAlloc4Stat_Test & operator=( const AllocEngine4Test_fakeAlloc4Stat_Test
&) = delete; AllocEngine4Test_fakeAlloc4Stat_Test (AllocEngine4Test_fakeAlloc4Stat_Test
&&) noexcept = delete; AllocEngine4Test_fakeAlloc4Stat_Test
& operator=( AllocEngine4Test_fakeAlloc4Stat_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_fakeAlloc4Stat_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "fakeAlloc4Stat", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 3404
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3404), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3404), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4Stat_Test
>); void AllocEngine4Test_fakeAlloc4Stat_Test::TestBody()
{
3405 boost::scoped_ptr<AllocEngine> engine;
3406 ASSERT_NO_THROW(engine.reset(new AllocEngine(100)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(100)); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3406
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3406
; } } else gtest_label_testnothrow_3406 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3406, ("Expected: " "engine.reset(new AllocEngine(100))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3407 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3407, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
3408
3409 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3410 IOAddress("0.0.0.0"), false, true,
3411 "host.example.com.", true);
3412 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3413
3414 // Let's pretend 100 addresses were allocated already
3415 string name = StatsMgr::generateName("subnet", subnet_->getID(),
3416 "assigned-addresses");
3417 StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
3418 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
3419 subnet_->getID());
3420
3421 int64_t glbl_assigned = getStatistics("assigned-addresses");
3422 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
3423
3424 Lease4Ptr lease = engine->allocateLease4(ctx);
3425
3426 // The new lease has been allocated, so the old lease should not exist.
3427 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3427, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3428
3429 // Check that we got a lease
3430 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3430, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3431
3432 // The statistic should be there and it should not be increased
3433 // (should be still equal to 100).
3434 ObservationPtr stat = StatsMgr::instance().getObservation(name);
3435 ASSERT_TRUE(stat)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(stat)) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3435, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "stat", "false", "true") .c_str()) = ::testing::Message()
;
3436 EXPECT_EQ(100, stat->getInteger().first)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("100", "stat->getInteger().first"
, 100, stat->getInteger().first))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3436, gtest_ar.failure_message()) = ::testing::Message()
;
3437 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3438, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
3438 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3438, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
3439 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3439, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
3440 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3440, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
3441}
3442
3443// This test checks that the allocated-addresses statistic is decreased when
3444// the client has a lease and a reservation for a different address is
3445// available.
3446TEST_F(AllocEngine4Test, reservedAddressExistingLeaseStat)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("reservedAddressExistingLeaseStat") >
1, "test_name must not be empty"); class AllocEngine4Test_reservedAddressExistingLeaseStat_Test
: public AllocEngine4Test { public: AllocEngine4Test_reservedAddressExistingLeaseStat_Test
() = default; ~AllocEngine4Test_reservedAddressExistingLeaseStat_Test
() override = default; AllocEngine4Test_reservedAddressExistingLeaseStat_Test
(const AllocEngine4Test_reservedAddressExistingLeaseStat_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseStat_Test
& operator=( const AllocEngine4Test_reservedAddressExistingLeaseStat_Test
&) = delete; AllocEngine4Test_reservedAddressExistingLeaseStat_Test
(AllocEngine4Test_reservedAddressExistingLeaseStat_Test &&
) noexcept = delete; AllocEngine4Test_reservedAddressExistingLeaseStat_Test
& operator=( AllocEngine4Test_reservedAddressExistingLeaseStat_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseStat_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "reservedAddressExistingLeaseStat", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3446), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3446), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3446), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseStat_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseStat_Test
::TestBody()
{
3447 // Create the reservation for the client.
3448 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3449 Host::IDENT_HWADDR, subnet_->getID(),
3450 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
3451 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3452 CfgMgr::instance().commit();
3453
3454 // Create a lease for the client with a different address than the reserved
3455 // one.
3456 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
3457 &clientid_->getClientId()[0],
3458 clientid_->getClientId().size(),
3459 100, time(NULL__null), subnet_->getID(),
3460 false, false, ""));
3461 LeaseMgrFactory::instance().addLease(lease);
3462
3463 AllocEngine engine(100);
3464
3465 // Let's pretend 100 addresses were allocated already
3466 string name = StatsMgr::generateName("subnet", subnet_->getID(),
3467 "assigned-addresses");
3468 StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
3469 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
3470 subnet_->getID());
3471
3472 int64_t glbl_assigned = getStatistics("assigned-addresses");
3473 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
3474
3475 // Request allocation of the reserved address.
3476 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3477 IOAddress("192.0.2.123"), false, false,
3478 "", false);
3479 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3480 AllocEngine::findReservation(ctx);
3481
3482 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
3483
3484 ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3485
3486 // The statistic should be still at 100. Note that it was decreased
3487 // (because old lease was removed), but also increased (because the
3488 // new lease was immediately allocated).
3489 ObservationPtr stat = StatsMgr::instance().getObservation(name);
3490 ASSERT_TRUE(stat)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(stat)) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
3490, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "stat", "false", "true") .c_str()) = ::testing::Message()
;
3491 EXPECT_EQ(100, stat->getInteger().first)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("100", "stat->getInteger().first"
, 100, stat->getInteger().first))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3491, gtest_ar.failure_message()) = ::testing::Message()
;
3492 cumulative += 1;
3493 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3494, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
3494 cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, cumulative, subnet_->getID()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3494, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
3495 EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses"
, glbl_assigned))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3495, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
3496 glbl_cumulative += 1;
3497 EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses"
, glbl_cumulative))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3497, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
3498 // Lets' double check that the actual allocation took place.
3499 EXPECT_FALSE(ctx.fake_allocation_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.fake_allocation_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3499, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.fake_allocation_", "true", "false") .c_str()) = ::testing
::Message()
;
3500}
3501
3502// This test checks the behavior of the allocation engine in the following
3503// scenario:
3504// - Client has no lease in the database.
3505// - Client has a global reservation outside of the subnet.
3506// - Client sends DISCOVER
3507// - Client is allocated an address within the subnet.
3508// - Lease is not added to the lease database
3509TEST_F(AllocEngine4Test, globalReservationReservedNonMatchingAddressDiscover)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("globalReservationReservedNonMatchingAddressDiscover"
) > 1, "test_name must not be empty"); class AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
: public AllocEngine4Test { public: AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
() = default; ~AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
() override = default; AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
(const AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
&) = delete; AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
& operator=( const AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
&) = delete; AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
(AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
&&) noexcept = delete; AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
& operator=( AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "globalReservationReservedNonMatchingAddressDiscover", nullptr
, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3509), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3509), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3509), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
>); void AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
::TestBody()
{
3510 // Create reservation for the client.
3511 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3512 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3513 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3514 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3515 CfgMgr::instance().commit();
3516
3517 AllocEngine engine(0);
3518
3519 subnet_->setReservationsGlobal(true);
3520
3521 // Query allocation engine for the lease to be assigned to this
3522 // client without specifying the address to be assigned.
3523 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3524 IOAddress("0.0.0.0"), false, false,
3525 "", true);
3526 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3527
3528 // Look up the host.
3529 AllocEngine::findReservation(ctx);
3530
3531 // We should have the correct current host
3532 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3532, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3533 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3533, gtest_ar.failure_message()) = ::testing::Message()
;
3534 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3534, gtest_ar.failure_message()) = ::testing::Message()
;
3535
3536 // We should allocate an address in the subnet
3537 Lease4Ptr lease = engine.allocateLease4(ctx);
3538 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3538, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3539 EXPECT_TRUE(subnet_->inRange(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease
->addr_))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3539, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
3540
3541 // This is a "fake" allocation so the returned lease should not be committed
3542 // to the lease database.
3543 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3543, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3544
3545 // Client had no lease in the database, so the old lease returned should
3546 // be NULL.
3547 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3547, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3548}
3549
3550// This test checks the behavior of the allocation engine in the following
3551// scenario:
3552// - Client has no lease in the database.
3553// - Client has a global reservation matching the current subnet.
3554// - Client sends DISCOVER
3555// - Client is allocated the reserved address.
3556// - Lease is not added to the lease database
3557TEST_F(AllocEngine4Test, globalReservationReservedMatchingAddressDiscover)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("globalReservationReservedMatchingAddressDiscover"
) > 1, "test_name must not be empty"); class AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
: public AllocEngine4Test { public: AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
() = default; ~AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
() override = default; AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
(const AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
&) = delete; AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
& operator=( const AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
&) = delete; AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
(AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
&&) noexcept = delete; AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
& operator=( AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "globalReservationReservedMatchingAddressDiscover", nullptr
, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3557), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3557), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3557), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
>); void AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
::TestBody()
{
3558 // Create reservation for the client.
3559 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3560 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3561 SUBNET_ID_UNUSED, IOAddress("192.0.2.10")));
3562 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3563 CfgMgr::instance().commit();
3564
3565 AllocEngine engine(0);
3566
3567 subnet_->setReservationsGlobal(true);
3568
3569 // Query allocation engine for the lease to be assigned to this
3570 // client without specifying the address to be assigned.
3571 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3572 IOAddress("0.0.0.0"), false, false,
3573 "", true);
3574 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3575
3576 // Look up the host.
3577 AllocEngine::findReservation(ctx);
3578
3579 // We should have the correct current host
3580 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3580, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3581 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3581, gtest_ar.failure_message()) = ::testing::Message()
;
3582 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3582, gtest_ar.failure_message()) = ::testing::Message()
;
3583
3584 // We should allocate the reserved address.
3585 Lease4Ptr lease = engine.allocateLease4(ctx);
3586 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3587 EXPECT_EQ("192.0.2.10", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.10\""
, "lease->addr_.toText()", "192.0.2.10", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3587, gtest_ar.failure_message()) = ::testing::Message()
;
3588
3589 // This is a "fake" allocation so the returned lease should not be committed
3590 // to the lease database.
3591 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3591, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3592
3593 // Client had no lease in the database, so the old lease returned should
3594 // be NULL.
3595 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3596}
3597
3598// This test checks the behavior of the allocation engine in the following
3599// scenario:
3600// - Client has no lease in the database.
3601// - Client has a global reservation outside the current subnet.
3602// - Client sends REQUEST
3603// - Client is allocated a dynamic address.
3604// - Lease is added to the lease database
3605TEST_F(AllocEngine4Test, globalReservationReservedNonMatchingAddressRequest)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("globalReservationReservedNonMatchingAddressRequest"
) > 1, "test_name must not be empty"); class AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
: public AllocEngine4Test { public: AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
() = default; ~AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
() override = default; AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
(const AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
&) = delete; AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
& operator=( const AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
&) = delete; AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
(AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
&&) noexcept = delete; AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
& operator=( AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "globalReservationReservedNonMatchingAddressRequest", nullptr
, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3605), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3605), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3605), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
>); void AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
::TestBody()
{
3606 // Create reservation for the client.
3607 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3608 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3609 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3610 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3611 CfgMgr::instance().commit();
3612
3613 AllocEngine engine(0);
3614
3615 subnet_->setReservationsGlobal(true);
3616
3617 // Query allocation engine for the lease to be assigned to this
3618 // client without specifying the address to be assigned.
3619 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3620 IOAddress("0.0.0.0"), false, false,
3621 "", false);
3622 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3623
3624 // Look up the host.
3625 AllocEngine::findReservation(ctx);
3626
3627 // We should have the correct current host
3628 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3628, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3629 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3629, gtest_ar.failure_message()) = ::testing::Message()
;
3630 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3630, gtest_ar.failure_message()) = ::testing::Message()
;
3631
3632 // We should allocate the reserved address.
3633 Lease4Ptr lease = engine.allocateLease4(ctx);
3634 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3634, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3635 ASSERT_NE("192.0.77.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("\"192.0.77.123\""
, "lease->addr_.toText()", "192.0.77.123", lease->addr_
.toText()))) ; else return ::testing::internal::AssertHelper(
::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3635, gtest_ar.failure_message()) = ::testing::Message()
;
3636 EXPECT_TRUE(subnet_->inRange(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease
->addr_))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3636, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
3637
3638 // Check that the lease is indeed in LeaseMgr
3639 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3640 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3640, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3641
3642 // Now check that the lease in LeaseMgr has the same parameters
3643 detailCompareLease(lease, from_mgr);
3644
3645 // Client had no lease in the database, so the old lease returned should
3646 // be NULL.
3647 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3648}
3649
3650// This test checks the behavior of the allocation engine in the following
3651// scenario:
3652// - Client has no lease in the database.
3653// - Client has a global reservation matching the current subnet.
3654// - Client sends REQUEST
3655// - Client is allocated the reserved address.
3656// - Lease is added to the lease database
3657TEST_F(AllocEngine4Test, globalReservationReservedMatchingAddressRequest)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("globalReservationReservedMatchingAddressRequest"
) > 1, "test_name must not be empty"); class AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
: public AllocEngine4Test { public: AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
() = default; ~AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
() override = default; AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
(const AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
&) = delete; AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
& operator=( const AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
&) = delete; AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
(AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
&&) noexcept = delete; AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
& operator=( AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "globalReservationReservedMatchingAddressRequest", nullptr,
nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3657), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3657), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3657), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
>); void AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
::TestBody()
{
3658 // Create reservation for the client.
3659 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3660 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3661 SUBNET_ID_UNUSED, IOAddress("192.0.2.10")));
3662 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3663 CfgMgr::instance().commit();
3664
3665 AllocEngine engine(0);
3666
3667 subnet_->setReservationsGlobal(true);
3668
3669 // Query allocation engine for the lease to be assigned to this
3670 // client without specifying the address to be assigned.
3671 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3672 IOAddress("0.0.0.0"), false, false,
3673 "", false);
3674 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3675
3676 // Look up the host.
3677 AllocEngine::findReservation(ctx);
3678
3679 // We should have the correct current host
3680 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3680, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3681 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3681, gtest_ar.failure_message()) = ::testing::Message()
;
3682 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3682, gtest_ar.failure_message()) = ::testing::Message()
;
3683
3684 // We should allocate the reserved address.
3685 Lease4Ptr lease = engine.allocateLease4(ctx);
3686 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3686, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3687 EXPECT_EQ("192.0.2.10", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.10\""
, "lease->addr_.toText()", "192.0.2.10", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3687, gtest_ar.failure_message()) = ::testing::Message()
;
3688
3689 // Check that the lease is indeed in LeaseMgr
3690 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3691 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3691, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3692
3693 // Now check that the lease in LeaseMgr has the same parameters
3694 detailCompareLease(lease, from_mgr);
3695
3696 // Client had no lease in the database, so the old lease returned should
3697 // be NULL.
3698 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3698, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3699}
3700
3701// This test checks the behavior of the allocation engine in the following
3702// scenario:
3703// - Client has no lease in the database.
3704// - Client has a global reservation.
3705// - Client sends DISCOVER
3706// - Client is allocated a dynamic address from matched subnet
3707// - Lease is not added to the lease database
3708TEST_F(AllocEngine4Test, globalReservationDynamicDiscover)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("globalReservationDynamicDiscover") >
1, "test_name must not be empty"); class AllocEngine4Test_globalReservationDynamicDiscover_Test
: public AllocEngine4Test { public: AllocEngine4Test_globalReservationDynamicDiscover_Test
() = default; ~AllocEngine4Test_globalReservationDynamicDiscover_Test
() override = default; AllocEngine4Test_globalReservationDynamicDiscover_Test
(const AllocEngine4Test_globalReservationDynamicDiscover_Test
&) = delete; AllocEngine4Test_globalReservationDynamicDiscover_Test
& operator=( const AllocEngine4Test_globalReservationDynamicDiscover_Test
&) = delete; AllocEngine4Test_globalReservationDynamicDiscover_Test
(AllocEngine4Test_globalReservationDynamicDiscover_Test &&
) noexcept = delete; AllocEngine4Test_globalReservationDynamicDiscover_Test
& operator=( AllocEngine4Test_globalReservationDynamicDiscover_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationDynamicDiscover_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "globalReservationDynamicDiscover", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3708), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3708), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3708), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicDiscover_Test
>); void AllocEngine4Test_globalReservationDynamicDiscover_Test
::TestBody()
{
3709 // Create reservation for the client.
3710 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3711 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3712 SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(),
3713 "foo.example.org"));
3714 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3715 CfgMgr::instance().commit();
3716
3717 AllocEngine engine(0);
3718
3719 subnet_->setReservationsGlobal(true);
3720
3721 // Query allocation engine for the lease to be assigned to this
3722 // client without specifying the address to be assigned.
3723 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3724 IOAddress("0.0.0.0"), false, false,
3725 "", true);
3726 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3727
3728 // Look up the host.
3729 AllocEngine::findReservation(ctx);
3730
3731 // We should have the correct current host
3732 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3732, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3733 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3733, gtest_ar.failure_message()) = ::testing::Message()
;
3734 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3734, gtest_ar.failure_message()) = ::testing::Message()
;
3735
3736 // We should allocate a dynamic address.
3737 Lease4Ptr lease = engine.allocateLease4(ctx);
3738 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3738, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3739 EXPECT_EQ("192.0.2.100", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.100\""
, "lease->addr_.toText()", "192.0.2.100", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3739, gtest_ar.failure_message()) = ::testing::Message()
;
3740
3741 // This is a "fake" allocation so the returned lease should not be committed
3742 // to the lease database.
3743 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3743, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3744
3745 // Client had no lease in the database, so the old lease returned should
3746 // be NULL.
3747 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3747, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3748}
3749
3750// This test checks the behavior of the allocation engine in the following
3751// scenario:
3752// - Client has no lease in the database.
3753// - Client has a global reservation.
3754// - Client sends REQUEST
3755// - Client is allocated a dynamic address from matched subnet
3756// - Lease is added to the lease database
3757TEST_F(AllocEngine4Test, globalReservationDynamicRequest)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("globalReservationDynamicRequest") >
1, "test_name must not be empty"); class AllocEngine4Test_globalReservationDynamicRequest_Test
: public AllocEngine4Test { public: AllocEngine4Test_globalReservationDynamicRequest_Test
() = default; ~AllocEngine4Test_globalReservationDynamicRequest_Test
() override = default; AllocEngine4Test_globalReservationDynamicRequest_Test
(const AllocEngine4Test_globalReservationDynamicRequest_Test
&) = delete; AllocEngine4Test_globalReservationDynamicRequest_Test
& operator=( const AllocEngine4Test_globalReservationDynamicRequest_Test
&) = delete; AllocEngine4Test_globalReservationDynamicRequest_Test
(AllocEngine4Test_globalReservationDynamicRequest_Test &&
) noexcept = delete; AllocEngine4Test_globalReservationDynamicRequest_Test
& operator=( AllocEngine4Test_globalReservationDynamicRequest_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationDynamicRequest_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "globalReservationDynamicRequest", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3757), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3757), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3757), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicRequest_Test
>); void AllocEngine4Test_globalReservationDynamicRequest_Test
::TestBody()
{
3758 // Create reservation for the client.
3759 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3760 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3761 SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(),
3762 "foo.example.org"));
3763 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3764 CfgMgr::instance().commit();
3765
3766 AllocEngine engine(0);
3767
3768 subnet_->setReservationsGlobal(true);
3769
3770 // Query allocation engine for the lease to be assigned to this
3771 // client without specifying the address to be assigned.
3772 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3773 IOAddress("0.0.0.0"), false, false,
3774 "", false);
3775 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3776
3777 // Look up the host.
3778 AllocEngine::findReservation(ctx);
3779
3780 // We should have the correct current host
3781 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3781, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3782 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3782, gtest_ar.failure_message()) = ::testing::Message()
;
3783 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3783, gtest_ar.failure_message()) = ::testing::Message()
;
3784
3785 // We should allocate a dynamic address.
3786 Lease4Ptr lease = engine.allocateLease4(ctx);
3787 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3787, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3788 EXPECT_EQ("192.0.2.100", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.100\""
, "lease->addr_.toText()", "192.0.2.100", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3788, gtest_ar.failure_message()) = ::testing::Message()
;
3789
3790 // Check that the lease is indeed in LeaseMgr
3791 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3792 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3792, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3793
3794 // Now check that the lease in LeaseMgr has the same parameters
3795 detailCompareLease(lease, from_mgr);
3796
3797 // Client had no lease in the database, so the old lease returned should
3798 // be NULL.
3799 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3799, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3800}
3801
3802// This test checks the behavior of the allocation engine in the following
3803// scenario:
3804// - Client has no lease in the database.
3805// - Client has a subnet reservation.
3806// - Client sends DISCOVER
3807// - Client is allocated the reserved address.
3808// - Lease is not added to the lease database
3809TEST_F(AllocEngine4Test, mixedReservationReservedAddressDiscover)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("mixedReservationReservedAddressDiscover"
) > 1, "test_name must not be empty"); class AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
: public AllocEngine4Test { public: AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
() = default; ~AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
() override = default; AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
(const AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
&) = delete; AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
& operator=( const AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
&) = delete; AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
(AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
&&) noexcept = delete; AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
& operator=( AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "mixedReservationReservedAddressDiscover", nullptr, nullptr
, ::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3809), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3809), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3809), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
>); void AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
::TestBody()
{
3810 // Create reservation for the client.
3811 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3812 Host::IDENT_HWADDR, subnet_->getID(),
3813 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3814 "foo.example.org"));
3815 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3816 CfgMgr::instance().commit();
3817
3818 AllocEngine engine(0);
3819
3820 subnet_->setReservationsGlobal(true);
3821 subnet_->setReservationsInSubnet(true);
3822
3823 // Query allocation engine for the lease to be assigned to this
3824 // client without specifying the address to be assigned.
3825 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3826 IOAddress("0.0.0.0"), false, false,
3827 "", true);
3828 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3829
3830 // Look up the host.
3831 AllocEngine::findReservation(ctx);
3832
3833 // We should have the correct current host
3834 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3834, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3835 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3835, gtest_ar.failure_message()) = ::testing::Message()
;
3836 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3836, gtest_ar.failure_message()) = ::testing::Message()
;
3837
3838 // We should allocate the reserved address.
3839 Lease4Ptr lease = engine.allocateLease4(ctx);
3840 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3840, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3841 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3841, gtest_ar.failure_message()) = ::testing::Message()
;
3842
3843 // This is a "fake" allocation so the returned lease should not be committed
3844 // to the lease database.
3845 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3845, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3846
3847 // Client had no lease in the database, so the old lease returned should
3848 // be NULL.
3849 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3849, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3850}
3851
3852// This test checks the behavior of the allocation engine in the following
3853// scenario:
3854// - Client has no lease in the database.
3855// - Client has a subnet reservation.
3856// - Client sends REQUEST
3857// - Client is allocated the reserved address.
3858// - Lease is added to the lease database
3859TEST_F(AllocEngine4Test, mixedReservationReservedAddressRequest)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("mixedReservationReservedAddressRequest"
) > 1, "test_name must not be empty"); class AllocEngine4Test_mixedReservationReservedAddressRequest_Test
: public AllocEngine4Test { public: AllocEngine4Test_mixedReservationReservedAddressRequest_Test
() = default; ~AllocEngine4Test_mixedReservationReservedAddressRequest_Test
() override = default; AllocEngine4Test_mixedReservationReservedAddressRequest_Test
(const AllocEngine4Test_mixedReservationReservedAddressRequest_Test
&) = delete; AllocEngine4Test_mixedReservationReservedAddressRequest_Test
& operator=( const AllocEngine4Test_mixedReservationReservedAddressRequest_Test
&) = delete; AllocEngine4Test_mixedReservationReservedAddressRequest_Test
(AllocEngine4Test_mixedReservationReservedAddressRequest_Test
&&) noexcept = delete; AllocEngine4Test_mixedReservationReservedAddressRequest_Test
& operator=( AllocEngine4Test_mixedReservationReservedAddressRequest_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_mixedReservationReservedAddressRequest_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "mixedReservationReservedAddressRequest", nullptr, nullptr,
::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3859), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3859), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3859), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressRequest_Test
>); void AllocEngine4Test_mixedReservationReservedAddressRequest_Test
::TestBody()
{
3860 // Create reservation for the client.
3861 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3862 Host::IDENT_HWADDR, subnet_->getID(),
3863 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3864 "foo.example.org"));
3865 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3866 CfgMgr::instance().commit();
3867
3868 AllocEngine engine(0);
3869
3870 subnet_->setReservationsGlobal(true);
3871 subnet_->setReservationsInSubnet(true);
3872
3873 // Query allocation engine for the lease to be assigned to this
3874 // client without specifying the address to be assigned.
3875 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3876 IOAddress("0.0.0.0"), false, false,
3877 "", false);
3878 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3879
3880 // Look up the host.
3881 AllocEngine::findReservation(ctx);
3882
3883 // We should have the correct current host
3884 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3884, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3885 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3885, gtest_ar.failure_message()) = ::testing::Message()
;
3886 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3886, gtest_ar.failure_message()) = ::testing::Message()
;
3887
3888 // We should allocate the reserved address.
3889 Lease4Ptr lease = engine.allocateLease4(ctx);
3890 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3890, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3891 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3891, gtest_ar.failure_message()) = ::testing::Message()
;
3892
3893 // Check that the lease is indeed in LeaseMgr
3894 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3895 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3895, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3896
3897 // Now check that the lease in LeaseMgr has the same parameters
3898 detailCompareLease(lease, from_mgr);
3899
3900 // Client had no lease in the database, so the old lease returned should
3901 // be NULL.
3902 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3902, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3903}
3904
3905// This test checks the behavior of the allocation engine in the following
3906// scenario:
3907// - Client has no lease in the database.
3908// - Client has a global and a subnet reservation.
3909// - Client sends DISCOVER
3910// - Client is allocated the reserved address.
3911// - Lease is not added to the lease database
3912TEST_F(AllocEngine4Test, bothReservationReservedAddressDiscover)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("bothReservationReservedAddressDiscover"
) > 1, "test_name must not be empty"); class AllocEngine4Test_bothReservationReservedAddressDiscover_Test
: public AllocEngine4Test { public: AllocEngine4Test_bothReservationReservedAddressDiscover_Test
() = default; ~AllocEngine4Test_bothReservationReservedAddressDiscover_Test
() override = default; AllocEngine4Test_bothReservationReservedAddressDiscover_Test
(const AllocEngine4Test_bothReservationReservedAddressDiscover_Test
&) = delete; AllocEngine4Test_bothReservationReservedAddressDiscover_Test
& operator=( const AllocEngine4Test_bothReservationReservedAddressDiscover_Test
&) = delete; AllocEngine4Test_bothReservationReservedAddressDiscover_Test
(AllocEngine4Test_bothReservationReservedAddressDiscover_Test
&&) noexcept = delete; AllocEngine4Test_bothReservationReservedAddressDiscover_Test
& operator=( AllocEngine4Test_bothReservationReservedAddressDiscover_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_bothReservationReservedAddressDiscover_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "bothReservationReservedAddressDiscover", nullptr, nullptr,
::testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3912), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3912), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3912), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressDiscover_Test
>); void AllocEngine4Test_bothReservationReservedAddressDiscover_Test
::TestBody()
{
3913 // Create reservations for the client.
3914 HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3915 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3916 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3917 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost);
3918 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3919 Host::IDENT_HWADDR, subnet_->getID(),
3920 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3921 "foo.example.org"));
3922 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3923 CfgMgr::instance().commit();
3924
3925 AllocEngine engine(0);
3926
3927 subnet_->setReservationsGlobal(true);
3928 subnet_->setReservationsInSubnet(true);
3929
3930 // Query allocation engine for the lease to be assigned to this
3931 // client without specifying the address to be assigned.
3932 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3933 IOAddress("0.0.0.0"), false, false,
3934 "", true);
3935 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3936
3937 // Look up the host.
3938 AllocEngine::findReservation(ctx);
3939
3940 // We should have the correct current host
3941 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3941, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3942 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3942, gtest_ar.failure_message()) = ::testing::Message()
;
3943 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3943, gtest_ar.failure_message()) = ::testing::Message()
;
3944
3945 // We should allocate the reserved address.
3946 Lease4Ptr lease = engine.allocateLease4(ctx);
3947 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3947, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3948 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3948, gtest_ar.failure_message()) = ::testing::Message()
;
3949
3950 // This is a "fake" allocation so the returned lease should not be committed
3951 // to the lease database.
3952 EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance
().getLease4(lease->addr_)))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3952, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3953
3954 // Client had no lease in the database, so the old lease returned should
3955 // be NULL.
3956 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3956, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3957}
3958
3959// This test checks the behavior of the allocation engine in the following
3960// scenario:
3961// - Client has no lease in the database.
3962// - Client has a global and a subnet reservation.
3963// - Client sends REQUEST
3964// - Client is allocated the reserved address.
3965// - Lease is added to the lease database
3966TEST_F(AllocEngine4Test, bothReservationReservedAddressRequest)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("bothReservationReservedAddressRequest"
) > 1, "test_name must not be empty"); class AllocEngine4Test_bothReservationReservedAddressRequest_Test
: public AllocEngine4Test { public: AllocEngine4Test_bothReservationReservedAddressRequest_Test
() = default; ~AllocEngine4Test_bothReservationReservedAddressRequest_Test
() override = default; AllocEngine4Test_bothReservationReservedAddressRequest_Test
(const AllocEngine4Test_bothReservationReservedAddressRequest_Test
&) = delete; AllocEngine4Test_bothReservationReservedAddressRequest_Test
& operator=( const AllocEngine4Test_bothReservationReservedAddressRequest_Test
&) = delete; AllocEngine4Test_bothReservationReservedAddressRequest_Test
(AllocEngine4Test_bothReservationReservedAddressRequest_Test
&&) noexcept = delete; AllocEngine4Test_bothReservationReservedAddressRequest_Test
& operator=( AllocEngine4Test_bothReservationReservedAddressRequest_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_bothReservationReservedAddressRequest_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "bothReservationReservedAddressRequest", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3966), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3966), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3966), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressRequest_Test
>); void AllocEngine4Test_bothReservationReservedAddressRequest_Test
::TestBody()
{
3967 // Create reservations for the client.
3968 HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3969 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3970 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3971 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost);
3972 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3973 Host::IDENT_HWADDR, subnet_->getID(),
3974 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3975 "foo.example.org"));
3976 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3977 CfgMgr::instance().commit();
3978
3979 AllocEngine engine(0);
3980
3981 subnet_->setReservationsGlobal(true);
3982 subnet_->setReservationsInSubnet(true);
3983
3984 // Query allocation engine for the lease to be assigned to this
3985 // client without specifying the address to be assigned.
3986 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3987 IOAddress("0.0.0.0"), false, false,
3988 "", false);
3989 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3990
3991 // Look up the host.
3992 AllocEngine::findReservation(ctx);
3993
3994 // We should have the correct current host
3995 EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3995, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3996 EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()"
, "host->getHostname()", ctx.currentHost()->getHostname
(), host->getHostname()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3996, gtest_ar.failure_message()) = ::testing::Message()
;
3997 EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()"
, "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation
(), host->getIPv4Reservation()))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3997, gtest_ar.failure_message()) = ::testing::Message()
;
3998
3999 // We should allocate the reserved address.
4000 Lease4Ptr lease = engine.allocateLease4(ctx);
4001 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4001, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4002 EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\""
, "lease->addr_.toText()", "192.0.2.123", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4002, gtest_ar.failure_message()) = ::testing::Message()
;
4003
4004 // Check that the lease is indeed in LeaseMgr
4005 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
4006 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4006, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4007
4008 // Now check that the lease in LeaseMgr has the same parameters
4009 detailCompareLease(lease, from_mgr);
4010
4011 // Client had no lease in the database, so the old lease returned should
4012 // be NULL.
4013 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4013, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
4014}
4015
4016// Exercises AllocEnginer4Test::updateExtendedInfo4() through various
4017// permutations of client packet content.
4018TEST_F(AllocEngine4Test, updateExtendedInfo4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("updateExtendedInfo4") > 1, "test_name must not be empty"
); class AllocEngine4Test_updateExtendedInfo4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_updateExtendedInfo4_Test() = default
; ~AllocEngine4Test_updateExtendedInfo4_Test() override = default
; AllocEngine4Test_updateExtendedInfo4_Test (const AllocEngine4Test_updateExtendedInfo4_Test
&) = delete; AllocEngine4Test_updateExtendedInfo4_Test &
operator=( const AllocEngine4Test_updateExtendedInfo4_Test &
) = delete; AllocEngine4Test_updateExtendedInfo4_Test (AllocEngine4Test_updateExtendedInfo4_Test
&&) noexcept = delete; AllocEngine4Test_updateExtendedInfo4_Test
& operator=( AllocEngine4Test_updateExtendedInfo4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_updateExtendedInfo4_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "updateExtendedInfo4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4018), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4018), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4018), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_updateExtendedInfo4_Test
>); void AllocEngine4Test_updateExtendedInfo4_Test::TestBody
()
{
4019
4020 // Structure that defines a test scenario.
4021 struct Scenario {
4022 std::string description_; // test description
4023 std::string orig_context_json_; // user context the lease begins with
4024 std::string rai_data_; // RAI option the client packet contains
4025 std::string exp_context_json_; // expected user context on the lease
4026 bool exp_ret; // expected returned value
4027 };
4028
4029 // Test scenarios.
4030 std::vector<Scenario> scenarios {
4031 {
4032 "no context, no rai",
4033 "",
4034 "",
4035 "",
4036 false
4037 },
4038 {
4039 "some original context, no rai",
4040 "{\"foo\": 123}",
4041 "",
4042 "{\"foo\": 123}",
4043 false
4044 },
4045 {
4046 "no original context, rai",
4047 "",
4048 "0x52060104aabbccdd",
4049 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4050 " \"0x0104AABBCCDD\" } } }",
4051 true
4052 },
4053 {
4054 "no original context, rai, remote and relay ids",
4055 "",
4056 "0x520a02030102030c03aabbcc",
4057 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4058 " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\","
4059 " \"relay-id\": \"AABBCC\" } } }",
4060 true
4061 },
4062 {
4063 "some original context, rai",
4064 "{\"foo\": 123, \"ISC\":{\"bar\": 456}}",
4065 "0x52060104aabbccdd",
4066 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4067 " \"0x0104AABBCCDD\" }, \"bar\": 456 }, \"foo\": 123 }",
4068 true
4069 },
4070 {
4071 "bad original context, rai",
4072 "[\"foo\"]",
4073 "0x52060104aabbccdd",
4074 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4075 " \"0x0104AABBCCDD\" } } }",
4076 true
4077 },
4078 {
4079 "some original context with bad isc entry, rai",
4080 "{\"foo\": 123, \"ISC\":[\"bar\"]}",
4081 "0x52060104aabbccdd",
4082 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4083 " \"0x0104AABBCCDD\" } }, \"foo\": 123 }",
4084 true
4085 },
4086 {
4087 "some original context, rai, remote and relay ids",
4088 "{\"foo\": 123, \"ISC\":{ \"bar\": 456}}",
4089 "0x520a02030102030c03aabbcc",
4090 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4091 " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\","
4092 " \"relay-id\": \"AABBCC\" }, \"bar\": 456 }, \"foo\": 123 }",
4093 true
4094 },
4095 {
4096 "original rai context, no rai",
4097 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4098 " \"0x0104AABBCCDD\" } } }",
4099 "",
4100 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4101 " \"0x0104AABBCCDD\" } } }",
4102 false
4103 },
4104 {
4105 "original rai context, different rai",
4106 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4107 " \"0x0104AABBCCDD\" } } }",
4108 "0x52060104ddeeffaa",
4109 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4110 " \"0x0104DDEEFFAA\" } } }",
4111 true
4112 },
4113 {
4114 "original rai context, different rai, remote and relay ids",
4115 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4116 " \"0x0104AABBCCDD\" } } }",
4117 "0x520a02030102030c03aabbcc",
4118 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4119 " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\","
4120 " \"relay-id\": \"AABBCC\" } } }",
4121 true
4122 }};
4123
4124 // Create the allocation engine, context and lease.
4125 NakedAllocEngine engine(0);
4126
4127 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
4128 IOAddress::IPV4_ZERO_ADDRESS(),
4129 false, false, "", true);
4130
4131 // All scenarios require storage to be enabled.
4132 subnet_->setStoreExtendedInfo(true);
4133
4134 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4135 Lease4Ptr lease = engine.allocateLease4(ctx);
4136 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4136, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4137 EXPECT_EQ("192.0.2.100", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.100\""
, "lease->addr_.toText()", "192.0.2.100", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4137, gtest_ar.failure_message()) = ::testing::Message()
;
4138
4139 // Verify that the lease begins with no user context.
4140 ConstElementPtr user_context = lease->getContext();
4141 ASSERT_FALSE(user_context)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(user_context))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4141, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "true", "false") .c_str()) = ::testing::Message
()
;
4142
4143 // Iterate over the test scenarios.
4144 ElementPtr orig_context;
4145 ElementPtr exp_context;
4146 for (auto const& scenario : scenarios) {
4147 SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4147( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4147, (scenario.description_))
;
4148
4149 // Create the original user context from JSON.
4150 if (scenario.orig_context_json_.empty()) {
4151 orig_context.reset();
4152 } else {
4153 ASSERT_NO_THROW(orig_context = Element::fromJSON(scenario.orig_context_json_))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
orig_context = Element::fromJSON(scenario.orig_context_json_
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4153; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4153
; } } else gtest_label_testnothrow_4153 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4153, ("Expected: " "orig_context = Element::fromJSON(scenario.orig_context_json_)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4154 << "invalid orig_context_json_, test is broken";
4155 }
4156
4157 // Create the expected user context from JSON.
4158 if (scenario.exp_context_json_.empty()) {
4159 exp_context.reset();
4160 } else {
4161 ASSERT_NO_THROW(exp_context = Element::fromJSON(scenario.exp_context_json_))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
exp_context = Element::fromJSON(scenario.exp_context_json_);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4161; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4161
; } } else gtest_label_testnothrow_4161 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4161, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4162 << "invalid exp_context_json_, test is broken";
4163 }
4164
4165 // Initialize lease's user context.
4166 lease->setContext(orig_context);
4167 if (!orig_context) {
4168 ASSERT_FALSE(lease->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->getContext
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4168, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4169 } else {
4170 ASSERT_TRUE(lease->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->getContext(
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4170, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "false", "true") .c_str()) = ::testing
::Message()
;
4171 ASSERT_TRUE(orig_context->equals(*(lease->getContext())))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(orig_context->equals
(*(lease->getContext())))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4171, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "orig_context->equals(*(lease->getContext()))", "false"
, "true") .c_str()) = ::testing::Message()
;
4172 }
4173
4174 // Create the client packet and the add RAI option (if one).
4175 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4176 if (!scenario.rai_data_.empty()) {
4177 std::vector<uint8_t> opt_data;
4178 ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
util::str::decodeFormattedHexString(scenario.rai_data_, opt_data
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4178; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4178
; } } else gtest_label_testnothrow_4178 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4178, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4179 << "scenario.rai_data_ is invalid, test is broken";
4180 const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF();
4181 ASSERT_GT(opt_data.size(), 2U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("opt_data.size()"
, "2U", opt_data.size(), 2U))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4181, gtest_ar.failure_message()) = ::testing::Message()
;
4182 ASSERT_EQ(DHO_DHCP_AGENT_OPTIONS, opt_data[0])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("DHO_DHCP_AGENT_OPTIONS"
, "opt_data[0]", DHO_DHCP_AGENT_OPTIONS, opt_data[0]))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4182, gtest_ar.failure_message()) = ::testing::Message()
;
4183 ASSERT_EQ(opt_data[1] + 2U, opt_data.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("opt_data[1] + 2U"
, "opt_data.size()", opt_data[1] + 2U, opt_data.size()))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4183, gtest_ar.failure_message()) = ::testing::Message()
;
4184 std::vector<uint8_t> rai_data(opt_data.cbegin() + 2,
4185 opt_data.cend());
4186 OptionCustomPtr rai;
4187 ASSERT_NO_THROW(rai.reset(new OptionCustom(rai_def, Option::V4,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rai.reset(new OptionCustom(rai_def, Option::V4, rai_data)); }
else static_assert(true, ""); } catch (std::exception const&
e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4188; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4188; } } else gtest_label_testnothrow_4188
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4188, ("Expected: " "rai.reset(new OptionCustom(rai_def, Option::V4, rai_data))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4188 rai_data)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rai.reset(new OptionCustom(rai_def, Option::V4, rai_data)); }
else static_assert(true, ""); } catch (std::exception const&
e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4188; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4188; } } else gtest_label_testnothrow_4188
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4188, ("Expected: " "rai.reset(new OptionCustom(rai_def, Option::V4, rai_data))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4189 << "could not create rai option, test is broken";
4190 ctx.query_->addOption(rai);
4191 }
4192
4193 // Call AllocEngine::updateLease4ExtendeInfo().
4194 bool ret = false;
4195 ASSERT_NO_THROW_LOG(ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)){ try { ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)
; } catch (const std::exception& ex) { return ::testing::
internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4195, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw type: " << typeid(ex).name() <<
", what: " << ex.what(); } catch (...) { return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4195, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4196 ASSERT_EQ(scenario.exp_ret, ret)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("scenario.exp_ret"
, "ret", scenario.exp_ret, ret))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4196, gtest_ar.failure_message()) = ::testing::Message()
;
4197
4198 // Verify the lease has the expected user context content.
4199 if (!exp_context) {
4200 ASSERT_FALSE(lease->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->getContext
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4200, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4201 } else {
4202 ASSERT_TRUE(lease->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->getContext(
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4202, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "false", "true") .c_str()) = ::testing
::Message()
;
4203 ASSERT_TRUE(exp_context->equals(*(lease->getContext())))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(exp_context->equals
(*(lease->getContext())))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4203, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "exp_context->equals(*(lease->getContext()))", "false"
, "true") .c_str()) = ::testing::Message()
4204 << "expected: " << *(exp_context) << std::endl
4205 << " actual: " << *(lease->getContext()) << std::endl;
4206 }
4207 }
4208}
4209
4210// Verifies that recovered stashed RAI is not saved in extended info.
4211TEST_F(AllocEngine4Test, stashAgentOptions)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("stashAgentOptions") > 1, "test_name must not be empty"
); class AllocEngine4Test_stashAgentOptions_Test : public AllocEngine4Test
{ public: AllocEngine4Test_stashAgentOptions_Test() = default
; ~AllocEngine4Test_stashAgentOptions_Test() override = default
; AllocEngine4Test_stashAgentOptions_Test (const AllocEngine4Test_stashAgentOptions_Test
&) = delete; AllocEngine4Test_stashAgentOptions_Test &
operator=( const AllocEngine4Test_stashAgentOptions_Test &
) = delete; AllocEngine4Test_stashAgentOptions_Test (AllocEngine4Test_stashAgentOptions_Test
&&) noexcept = delete; AllocEngine4Test_stashAgentOptions_Test
& operator=( AllocEngine4Test_stashAgentOptions_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_stashAgentOptions_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "stashAgentOptions", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4211), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4211), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4211), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_stashAgentOptions_Test
>); void AllocEngine4Test_stashAgentOptions_Test::TestBody
()
{
4212 // Create the allocation engine, context and lease.
4213 NakedAllocEngine engine(0);
4214
4215 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
4216 IOAddress::IPV4_ZERO_ADDRESS(),
4217 false, false, "", true);
4218 subnet_->setStoreExtendedInfo(true);
4219 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4220 Lease4Ptr lease = engine.allocateLease4(ctx);
4221 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4221, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4222 EXPECT_EQ("192.0.2.100", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.100\""
, "lease->addr_.toText()", "192.0.2.100", lease->addr_.
toText()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4222, gtest_ar.failure_message()) = ::testing::Message()
;
4223
4224 // Verify that the lease begins with no user context.
4225 ConstElementPtr user_context = lease->getContext();
4226 ASSERT_FALSE(user_context)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(user_context))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4226, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "true", "false") .c_str()) = ::testing::Message
()
;
4227
4228 // Add a RAI in the query.
4229 std::string rai_str = "0104aabbccdd";
4230 std::vector<uint8_t> rai_data;
4231 ASSERT_NO_THROW(util::str::decodeFormattedHexString(rai_str, rai_data))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
util::str::decodeFormattedHexString(rai_str, rai_data); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4231; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4231; } } else gtest_label_testnothrow_4231
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4231, ("Expected: " "util::str::decodeFormattedHexString(rai_str, rai_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4232 const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF();
4233 OptionCustomPtr rai;
4234 ASSERT_NO_THROW(rai.reset(new OptionCustom(rai_def, Option::V4, rai_data)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rai.reset(new OptionCustom(rai_def, Option::V4, rai_data)); }
else static_assert(true, ""); } catch (std::exception const&
e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4234; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4234; } } else gtest_label_testnothrow_4234
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4234, ("Expected: " "rai.reset(new OptionCustom(rai_def, Option::V4, rai_data))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4235 ctx.query_->addOption(rai);
4236
4237 // Verifies that the RAI is saved into lease extended info.
4238 bool ret = false;
4239 ASSERT_NO_THROW_LOG(ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)){ try { ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)
; } catch (const std::exception& ex) { return ::testing::
internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4239, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw type: " << typeid(ex).name() <<
", what: " << ex.what(); } catch (...) { return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4239, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4240 EXPECT_TRUE(ret)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ret)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4240, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ret", "false", "true") .c_str()) = ::testing::Message()
;
4241 user_context = lease->getContext();
4242 EXPECT_TRUE(user_context)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(user_context)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4242, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "false", "true") .c_str()) = ::testing::Message
()
;
4243 lease->setContext(ElementPtr());
4244
4245 // Set stash-agent-options to true.
4246 CfgMgr::instance().getStagingCfg()->
4247 addConfiguredGlobal("stash-agent-options", Element::create(true));
4248 CfgMgr::instance().commit();
4249
4250 // Verifies that the RAI is saved into lease extended info.
4251 ret = false;
Value stored to 'ret' is never read
4252 ASSERT_NO_THROW_LOG(ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)){ try { ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)
; } catch (const std::exception& ex) { return ::testing::
internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4252, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw type: " << typeid(ex).name() <<
", what: " << ex.what(); } catch (...) { return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4252, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4253 EXPECT_TRUE(ret)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ret)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4253, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ret", "false", "true") .c_str()) = ::testing::Message()
;
4254 user_context = lease->getContext();
4255 EXPECT_TRUE(user_context)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(user_context)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4255, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "false", "true") .c_str()) = ::testing::Message
()
;
4256 lease->setContext(ElementPtr());
4257
4258 // Put the query in the STASH_AGENT_OPTIONS class.
4259 ctx.query_->addClass("STASH_AGENT_OPTIONS");
4260
4261 // Verifies that the RAI is not saved into lease extended info.
4262 ret = false;
4263 ASSERT_NO_THROW_LOG(ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)){ try { ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)
; } catch (const std::exception& ex) { return ::testing::
internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4263, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw type: " << typeid(ex).name() <<
", what: " << ex.what(); } catch (...) { return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4263, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4264 EXPECT_FALSE(ret)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ret))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
4264, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ret", "true", "false") .c_str()) = ::testing::Message()
;
4265 user_context = lease->getContext();
4266 EXPECT_FALSE(user_context)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(user_context))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4266, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "true", "false") .c_str()) = ::testing::Message
()
;
4267}
4268
4269// Verifies that the extended data (e.g. RAI option for now) is
4270// added to a V4 lease when leases are created and/or renewed,
4271// when store-extended-info is true.
4272TEST_F(AllocEngine4Test, storeExtendedInfoEnabled4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("storeExtendedInfoEnabled4") > 1, "test_name must not be empty"
); class AllocEngine4Test_storeExtendedInfoEnabled4_Test : public
AllocEngine4Test { public: AllocEngine4Test_storeExtendedInfoEnabled4_Test
() = default; ~AllocEngine4Test_storeExtendedInfoEnabled4_Test
() override = default; AllocEngine4Test_storeExtendedInfoEnabled4_Test
(const AllocEngine4Test_storeExtendedInfoEnabled4_Test &
) = delete; AllocEngine4Test_storeExtendedInfoEnabled4_Test &
operator=( const AllocEngine4Test_storeExtendedInfoEnabled4_Test
&) = delete; AllocEngine4Test_storeExtendedInfoEnabled4_Test
(AllocEngine4Test_storeExtendedInfoEnabled4_Test &&)
noexcept = delete; AllocEngine4Test_storeExtendedInfoEnabled4_Test
& operator=( AllocEngine4Test_storeExtendedInfoEnabled4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_storeExtendedInfoEnabled4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "storeExtendedInfoEnabled4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4272), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4272), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4272), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoEnabled4_Test
>); void AllocEngine4Test_storeExtendedInfoEnabled4_Test::
TestBody()
{
4273
4274 // Structure that defines a test scenario.
4275 struct Scenario {
4276 std::string description_; // test description
4277 std::vector<uint8_t> mac_; // MAC address
4278 std::string rai_data_; // RAI option the client packet contains
4279 std::string exp_context_json_; // expected user context on the lease
4280 std::string exp_address_; // expected lease address
4281 };
4282
4283 std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 };
4284 std::string mac1_addr = "192.0.2.100";
4285
4286 std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 };
4287 std::string mac2_addr = "192.0.2.101";
4288
4289 // Test scenarios.
4290 std::vector<Scenario> scenarios {
4291 {
4292 "create client one without rai",
4293 mac1,
4294 "",
4295 "",
4296 mac1_addr
4297 },
4298 {
4299 "renew client one without rai",
4300 {},
4301 "",
4302 "",
4303 mac1_addr
4304 },
4305 {
4306 "create client two with rai",
4307 mac2,
4308 "0x52050104a1b1c1d1",
4309 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4310 " \"0x52050104A1B1C1D1\" } } }",
4311 mac2_addr
4312 },
4313 {
4314 "renew client two without rai",
4315 {},
4316 "",
4317 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4318 " \"0x52050104A1B1C1D1\" } } }",
4319 mac2_addr
4320 }};
4321
4322 // Create the allocation engine, context and lease.
4323 NakedAllocEngine engine(0);
4324
4325 // All of the scenarios require storage to be enabled.
4326 subnet_->setStoreExtendedInfo(true);
4327
4328 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
4329 IOAddress::IPV4_ZERO_ADDRESS(),
4330 false, false, "", false);
4331
4332 // Iterate over the test scenarios.
4333 for (auto const& scenario : scenarios) {
4334 SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4334( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4334, (scenario.description_))
;
4335
4336 ElementPtr exp_context;
4337 // Create the expected user context from JSON.
4338 if (!scenario.exp_context_json_.empty()) {
4339 ASSERT_NO_THROW(exp_context = Element::fromJSON(scenario.exp_context_json_))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
exp_context = Element::fromJSON(scenario.exp_context_json_);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4339; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4339
; } } else gtest_label_testnothrow_4339 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4339, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4340 << "invalid exp_context_json_, test is broken";
4341 }
4342
4343 // If we have a MAC address this scenario is for a new client.
4344 if (!scenario.mac_.empty()) {
4345 ASSERT_NO_THROW(ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER)); }
else static_assert(true, ""); } catch (std::exception const&
e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4345; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4345; } } else gtest_label_testnothrow_4345
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4345, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4346 << "invalid MAC address, test is broken";
4347 }
4348
4349 // Create the client packet and the add RAI option (if one).
4350 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4351 if (!scenario.rai_data_.empty()) {
4352 std::vector<uint8_t> opt_data;
4353 ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
util::str::decodeFormattedHexString(scenario.rai_data_, opt_data
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4353; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4353
; } } else gtest_label_testnothrow_4353 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4353, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4354 << "scenario.rai_data_ is invalid, test is broken";
4355 OptionPtr rai;
4356 ASSERT_NO_THROW(rai.reset(new Option(Option::V4, 0x52, opt_data)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rai.reset(new Option(Option::V4, 0x52, opt_data)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4356; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4356; } } else gtest_label_testnothrow_4356
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4356, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4357 << "could not create rai option, test is broken";
4358
4359 ctx.query_->addOption(rai);
4360 }
4361
4362 // Create or renew the lease.
4363 Lease4Ptr lease = engine.allocateLease4(ctx);
4364 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4364, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4365 EXPECT_EQ(scenario.exp_address_, lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("scenario.exp_address_"
, "lease->addr_.toText()", scenario.exp_address_, lease->
addr_.toText()))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4365, gtest_ar.failure_message()) = ::testing::Message()
;
4366
4367 // Verify the lease has the expected user context content.
4368 if (!exp_context) {
4369 ASSERT_FALSE(lease->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->getContext
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4369, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4370 } else {
4371 ASSERT_TRUE(lease->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->getContext(
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4371, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "false", "true") .c_str()) = ::testing
::Message()
;
4372 ASSERT_TRUE(exp_context->equals(*(lease->getContext())))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(exp_context->equals
(*(lease->getContext())))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "exp_context->equals(*(lease->getContext()))", "false"
, "true") .c_str()) = ::testing::Message()
4373 << "expected: " << *(exp_context) << std::endl
4374 << " actual: " << *(lease->getContext()) << std::endl;
4375 }
4376 }
4377}
4378
4379// Verifies that the extended data (e.g. RAI option for now) is
4380// not added to a V4 lease when leases are created and/or renewed,
4381// when store-extended-info is false.
4382TEST_F(AllocEngine4Test, storeExtendedInfoDisabled4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("storeExtendedInfoDisabled4") > 1,
"test_name must not be empty"); class AllocEngine4Test_storeExtendedInfoDisabled4_Test
: public AllocEngine4Test { public: AllocEngine4Test_storeExtendedInfoDisabled4_Test
() = default; ~AllocEngine4Test_storeExtendedInfoDisabled4_Test
() override = default; AllocEngine4Test_storeExtendedInfoDisabled4_Test
(const AllocEngine4Test_storeExtendedInfoDisabled4_Test &
) = delete; AllocEngine4Test_storeExtendedInfoDisabled4_Test &
operator=( const AllocEngine4Test_storeExtendedInfoDisabled4_Test
&) = delete; AllocEngine4Test_storeExtendedInfoDisabled4_Test
(AllocEngine4Test_storeExtendedInfoDisabled4_Test &&
) noexcept = delete; AllocEngine4Test_storeExtendedInfoDisabled4_Test
& operator=( AllocEngine4Test_storeExtendedInfoDisabled4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_storeExtendedInfoDisabled4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "storeExtendedInfoDisabled4", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4382), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4382), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4382), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoDisabled4_Test
>); void AllocEngine4Test_storeExtendedInfoDisabled4_Test::
TestBody()
{
4383
4384 // Structure that defines a test scenario.
4385 struct Scenario {
4386 std::string description_; // test description
4387 std::vector<uint8_t> mac_; // MAC address
4388 std::string rai_data_; // RAI option the client packet contains
4389 std::string exp_address_; // expected lease address
4390 };
4391
4392 std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 };
4393 std::string mac1_addr = "192.0.2.100";
4394
4395 std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 };
4396 std::string mac2_addr = "192.0.2.101";
4397
4398 // Test scenarios.
4399 std::vector<Scenario> scenarios {
4400 {
4401 "create client one without rai",
4402 mac1,
4403 "",
4404 mac1_addr
4405 },
4406 {
4407 "renew client one without rai",
4408 {},
4409 "",
4410 mac1_addr
4411 },
4412 {
4413 "create client two with rai",
4414 mac2,
4415 "0x52050104a1b1c1d1",
4416 mac2_addr
4417 },
4418 {
4419 "renew client two with rai",
4420 {},
4421 "0x52050104a1b1c1d1",
4422 mac2_addr
4423 }};
4424
4425 // Create the allocation engine, context and lease.
4426 NakedAllocEngine engine(0);
4427
4428 // All of the scenarios require storage to be disabled.
4429 subnet_->setStoreExtendedInfo(false);
4430
4431 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
4432 IOAddress::IPV4_ZERO_ADDRESS(),
4433 false, false, "", false);
4434
4435 // Iterate over the test scenarios.
4436 for (auto const& scenario : scenarios) {
4437 SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4437( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4437, (scenario.description_))
;
4438
4439 // If we have a MAC address this scenario is for a new client.
4440 if (!scenario.mac_.empty()) {
4441 ASSERT_NO_THROW(ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER)); }
else static_assert(true, ""); } catch (std::exception const&
e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4441; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4441; } } else gtest_label_testnothrow_4441
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4441, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4442 << "invalid MAC address, test is broken";
4443 }
4444
4445 // Create the client packet and the add RAI option (if one).
4446 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4447 if (!scenario.rai_data_.empty()) {
4448 std::vector<uint8_t> opt_data;
4449 ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
util::str::decodeFormattedHexString(scenario.rai_data_, opt_data
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4449; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4449
; } } else gtest_label_testnothrow_4449 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4449, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4450 << "scenario.rai_data_ is invalid, test is broken";
4451 OptionPtr rai;
4452 ASSERT_NO_THROW(rai.reset(new Option(Option::V4, 0x52, opt_data)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rai.reset(new Option(Option::V4, 0x52, opt_data)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4452; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4452; } } else gtest_label_testnothrow_4452
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4452, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4453 << "could not create rai option, test is broken";
4454
4455 ctx.query_->addOption(rai);
4456 }
4457
4458 // Create or renew the lease.
4459 Lease4Ptr lease = engine.allocateLease4(ctx);
4460 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4460, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4461 EXPECT_EQ(scenario.exp_address_, lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("scenario.exp_address_"
, "lease->addr_.toText()", scenario.exp_address_, lease->
addr_.toText()))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4461, gtest_ar.failure_message()) = ::testing::Message()
;
4462
4463 // Verify the lease does not have user context content.
4464 ASSERT_FALSE(lease->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->getContext
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4464, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4465 }
4466}
4467
4468// This test checks if a lease can be reused in DHCPDISCOVER (fake allocation)
4469// using cache threshold.
4470TEST_F(AllocEngine4Test, discoverCacheThreshold4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverCacheThreshold4") > 1, "test_name must not be empty"
); class AllocEngine4Test_discoverCacheThreshold4_Test : public
AllocEngine4Test { public: AllocEngine4Test_discoverCacheThreshold4_Test
() = default; ~AllocEngine4Test_discoverCacheThreshold4_Test(
) override = default; AllocEngine4Test_discoverCacheThreshold4_Test
(const AllocEngine4Test_discoverCacheThreshold4_Test &) =
delete; AllocEngine4Test_discoverCacheThreshold4_Test & operator
=( const AllocEngine4Test_discoverCacheThreshold4_Test &)
= delete; AllocEngine4Test_discoverCacheThreshold4_Test (AllocEngine4Test_discoverCacheThreshold4_Test
&&) noexcept = delete; AllocEngine4Test_discoverCacheThreshold4_Test
& operator=( AllocEngine4Test_discoverCacheThreshold4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheThreshold4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverCacheThreshold4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4470), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4470), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4470), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheThreshold4_Test
>); void AllocEngine4Test_discoverCacheThreshold4_Test::TestBody
()
{
4471 boost::scoped_ptr<AllocEngine> engine;
4472 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4472
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4472
; } } else gtest_label_testnothrow_4472 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4472, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4473 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4473, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4474
4475 // Set valid lifetime to 500.
4476 uint32_t valid = 500;
4477 subnet_->setValid(valid);
4478
4479 // Set the threshold to 25%.
4480 subnet_->setCacheThreshold(.25);
4481
4482 IOAddress addr("192.0.2.105");
4483 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4484 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4485 valid, now, subnet_->getID()));
4486 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4486, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4487 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4487, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4488
4489 // Create a context for fake allocation.
4490 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4491 false, false, "", true);
4492
4493 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4494 lease = engine->allocateLease4(ctx);
4495 // Check that we got that single lease.
4496 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4496, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4497 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4497, gtest_ar.failure_message()) = ::testing::Message()
;
4498
4499 // The lease was reused.
4500 time_t age = lease->cltt_ - now;
4501 EXPECT_GE(age, 100)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("age", "100", age
, 100))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4501, gtest_ar.failure_message()) = ::testing::Message()
;
4502 EXPECT_LE(age, 110)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("age", "110", age
, 110))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4502, gtest_ar.failure_message()) = ::testing::Message()
;
4503 EXPECT_EQ(valid - age, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("valid - age"
, "lease->reuseable_valid_lft_", valid - age, lease->reuseable_valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4503, gtest_ar.failure_message()) = ::testing::Message()
;
4504
4505 // Check other lease parameters.
4506 EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet_->getID()", lease->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4506, gtest_ar.failure_message()) = ::testing::Message()
;
4507 ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->client_id_)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4507, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4508 EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4508, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4509 ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4509, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4510 EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4510, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4511}
4512
4513// This test checks if a lease can be reused in DHCPREQUEST (real allocation)
4514// using cache threshold.
4515TEST_F(AllocEngine4Test, requestCacheThreshold4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestCacheThreshold4") > 1, "test_name must not be empty"
); class AllocEngine4Test_requestCacheThreshold4_Test : public
AllocEngine4Test { public: AllocEngine4Test_requestCacheThreshold4_Test
() = default; ~AllocEngine4Test_requestCacheThreshold4_Test()
override = default; AllocEngine4Test_requestCacheThreshold4_Test
(const AllocEngine4Test_requestCacheThreshold4_Test &) =
delete; AllocEngine4Test_requestCacheThreshold4_Test & operator
=( const AllocEngine4Test_requestCacheThreshold4_Test &) =
delete; AllocEngine4Test_requestCacheThreshold4_Test (AllocEngine4Test_requestCacheThreshold4_Test
&&) noexcept = delete; AllocEngine4Test_requestCacheThreshold4_Test
& operator=( AllocEngine4Test_requestCacheThreshold4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheThreshold4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestCacheThreshold4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4515), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4515), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4515), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheThreshold4_Test
>); void AllocEngine4Test_requestCacheThreshold4_Test::TestBody
()
{
4516 boost::scoped_ptr<AllocEngine> engine;
4517 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4517
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4517
; } } else gtest_label_testnothrow_4517 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4517, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4518 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4518, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4519
4520 // Set valid lifetime to 500.
4521 uint32_t valid = 500;
4522 subnet_->setValid(valid);
4523
4524 // Set the threshold to 25%.
4525 subnet_->setCacheThreshold(.25);
4526
4527 IOAddress addr("192.0.2.105");
4528 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4529 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4530 valid, now, subnet_->getID()));
4531 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4531, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4532 // Copy the lease, so as it can be compared with.
4533 Lease4Ptr original_lease(new Lease4(*lease));
4534 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4534, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4535
4536 // Create a context for real allocation.
4537 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4538 false, false, "", false);
4539
4540 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4541 lease = engine->allocateLease4(ctx);
4542 // Check that we got that single lease.
4543 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4543, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4544 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4544, gtest_ar.failure_message()) = ::testing::Message()
;
4545
4546 // The lease was reused.
4547 time_t age = lease->cltt_ - now;
4548 EXPECT_GE(age, 100)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("age", "100", age
, 100))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4548, gtest_ar.failure_message()) = ::testing::Message()
;
4549 EXPECT_LE(age, 110)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("age", "110", age
, 110))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4549, gtest_ar.failure_message()) = ::testing::Message()
;
4550 EXPECT_EQ(valid - age, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("valid - age"
, "lease->reuseable_valid_lft_", valid - age, lease->reuseable_valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4550, gtest_ar.failure_message()) = ::testing::Message()
;
4551
4552 // Check other lease parameters.
4553 EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet_->getID()", lease->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4553, gtest_ar.failure_message()) = ::testing::Message()
;
4554 ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->client_id_)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4554, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4555 EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4555, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4556 ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4556, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4557 EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4557, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4558
4559 // Check the lease was not updated in the database.
4560 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4561 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4561, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4562
4563 detailCompareLease(original_lease, from_mgr);
4564}
4565
4566/// We proved that there is no different from the "cache" feature between
4567/// discovers and request at the exception of the lease database update.
4568
4569// This test checks if a lease can be reused in DHCPDISCOVER (fake allocation)
4570// using cache max age.
4571TEST_F(AllocEngine4Test, discoverCacheMaxAge4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverCacheMaxAge4") > 1, "test_name must not be empty"
); class AllocEngine4Test_discoverCacheMaxAge4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_discoverCacheMaxAge4_Test() = default
; ~AllocEngine4Test_discoverCacheMaxAge4_Test() override = default
; AllocEngine4Test_discoverCacheMaxAge4_Test (const AllocEngine4Test_discoverCacheMaxAge4_Test
&) = delete; AllocEngine4Test_discoverCacheMaxAge4_Test &
operator=( const AllocEngine4Test_discoverCacheMaxAge4_Test &
) = delete; AllocEngine4Test_discoverCacheMaxAge4_Test (AllocEngine4Test_discoverCacheMaxAge4_Test
&&) noexcept = delete; AllocEngine4Test_discoverCacheMaxAge4_Test
& operator=( AllocEngine4Test_discoverCacheMaxAge4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_discoverCacheMaxAge4_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverCacheMaxAge4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4571), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4571), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4571), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheMaxAge4_Test
>); void AllocEngine4Test_discoverCacheMaxAge4_Test::TestBody
()
{
4572 boost::scoped_ptr<AllocEngine> engine;
4573 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4573
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4573
; } } else gtest_label_testnothrow_4573 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4573, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4574 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4574, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4575
4576 // Set valid lifetime to 500.
4577 uint32_t valid = 500;
4578 subnet_->setValid(valid);
4579
4580 // Set the max age to 200.
4581 subnet_->setCacheMaxAge(200);
4582
4583 IOAddress addr("192.0.2.105");
4584 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4585 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4586 valid, now, subnet_->getID()));
4587 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4587, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4588 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4589
4590 // Create a context for fake allocation.
4591 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4592 false, false, "", true);
4593
4594 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4595 lease = engine->allocateLease4(ctx);
4596 // Check that we got that single lease.
4597 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4597, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4598 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4598, gtest_ar.failure_message()) = ::testing::Message()
;
4599
4600 // The lease was reused.
4601 time_t age = lease->cltt_ - now;
4602 EXPECT_GE(age, 100)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("age", "100", age
, 100))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4602, gtest_ar.failure_message()) = ::testing::Message()
;
4603 EXPECT_LE(age, 110)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("age", "110", age
, 110))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4603, gtest_ar.failure_message()) = ::testing::Message()
;
4604 EXPECT_EQ(valid - age, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("valid - age"
, "lease->reuseable_valid_lft_", valid - age, lease->reuseable_valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4604, gtest_ar.failure_message()) = ::testing::Message()
;
4605
4606 // Check other lease parameters.
4607 EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet_->getID()", lease->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4607, gtest_ar.failure_message()) = ::testing::Message()
;
4608 ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->client_id_)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4608, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4609 EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4609, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4610 ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4611 EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4611, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4612}
4613
4614// This test checks if a lease can be reused in DHCPREQUEST (real allocation)
4615// using both cache threshold and max age.
4616TEST_F(AllocEngine4Test, requestCacheBoth4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestCacheBoth4") > 1, "test_name must not be empty"
); class AllocEngine4Test_requestCacheBoth4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_requestCacheBoth4_Test() = default
; ~AllocEngine4Test_requestCacheBoth4_Test() override = default
; AllocEngine4Test_requestCacheBoth4_Test (const AllocEngine4Test_requestCacheBoth4_Test
&) = delete; AllocEngine4Test_requestCacheBoth4_Test &
operator=( const AllocEngine4Test_requestCacheBoth4_Test &
) = delete; AllocEngine4Test_requestCacheBoth4_Test (AllocEngine4Test_requestCacheBoth4_Test
&&) noexcept = delete; AllocEngine4Test_requestCacheBoth4_Test
& operator=( AllocEngine4Test_requestCacheBoth4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_requestCacheBoth4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestCacheBoth4", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4616), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4616), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4616), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBoth4_Test
>); void AllocEngine4Test_requestCacheBoth4_Test::TestBody
()
{
4617 boost::scoped_ptr<AllocEngine> engine;
4618 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4618
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4618
; } } else gtest_label_testnothrow_4618 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4618, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4619 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4619, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4620
4621 // Set valid lifetime to 500.
4622 uint32_t valid = 500;
4623 subnet_->setValid(valid);
4624
4625 // Set the threshold to 25%.
4626 subnet_->setCacheThreshold(.25);
4627
4628 // Set the max age to 200.
4629 subnet_->setCacheMaxAge(200);
4630
4631 IOAddress addr("192.0.2.105");
4632 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4633 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4634 valid, now, subnet_->getID()));
4635 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4635, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4636 // Copy the lease, so as it can be compared with.
4637 Lease4Ptr original_lease(new Lease4(*lease));
4638 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4638, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4639
4640 // Create a context for real allocation.
4641 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4642 false, false, "", false);
4643
4644 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4645 lease = engine->allocateLease4(ctx);
4646 // Check that we got that single lease.
4647 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4648 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4648, gtest_ar.failure_message()) = ::testing::Message()
;
4649
4650 // The lease was reused.
4651 time_t age = lease->cltt_ - now;
4652 EXPECT_GE(age, 100)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("age", "100", age
, 100))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4652, gtest_ar.failure_message()) = ::testing::Message()
;
4653 EXPECT_LE(age, 110)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("age", "110", age
, 110))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4653, gtest_ar.failure_message()) = ::testing::Message()
;
4654 EXPECT_EQ(valid - age, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("valid - age"
, "lease->reuseable_valid_lft_", valid - age, lease->reuseable_valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4654, gtest_ar.failure_message()) = ::testing::Message()
;
4655
4656 // Check other lease parameters.
4657 EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet_->getID()", lease->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4657, gtest_ar.failure_message()) = ::testing::Message()
;
4658 ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->client_id_)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4658, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4659 EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4659, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4660 ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4660, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4661 EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4661, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4662
4663 // Check the lease was not updated in the database.
4664 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4665 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4665, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4666
4667 detailCompareLease(original_lease, from_mgr);
4668}
4669
4670// This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation)
4671// using too small cache threshold.
4672TEST_F(AllocEngine4Test, discoverCacheBadThreshold4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverCacheBadThreshold4") > 1,
"test_name must not be empty"); class AllocEngine4Test_discoverCacheBadThreshold4_Test
: public AllocEngine4Test { public: AllocEngine4Test_discoverCacheBadThreshold4_Test
() = default; ~AllocEngine4Test_discoverCacheBadThreshold4_Test
() override = default; AllocEngine4Test_discoverCacheBadThreshold4_Test
(const AllocEngine4Test_discoverCacheBadThreshold4_Test &
) = delete; AllocEngine4Test_discoverCacheBadThreshold4_Test &
operator=( const AllocEngine4Test_discoverCacheBadThreshold4_Test
&) = delete; AllocEngine4Test_discoverCacheBadThreshold4_Test
(AllocEngine4Test_discoverCacheBadThreshold4_Test &&
) noexcept = delete; AllocEngine4Test_discoverCacheBadThreshold4_Test
& operator=( AllocEngine4Test_discoverCacheBadThreshold4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheBadThreshold4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverCacheBadThreshold4", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4672), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4672), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4672), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheBadThreshold4_Test
>); void AllocEngine4Test_discoverCacheBadThreshold4_Test::
TestBody()
{
4673 boost::scoped_ptr<AllocEngine> engine;
4674 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4674
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4674
; } } else gtest_label_testnothrow_4674 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4674, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4675 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4675, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4676
4677 // Set valid lifetime to 500.
4678 uint32_t valid = 500;
4679 subnet_->setValid(valid);
4680
4681 // Set the threshold to 10%.
4682 subnet_->setCacheThreshold(.10);
4683
4684 IOAddress addr("192.0.2.105");
4685 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4686 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4687 valid, now, subnet_->getID()));
4688 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4688, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4689 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4689, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4690
4691 // Create a context for fake allocation.
4692 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4693 false, false, "", true);
4694
4695 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4696 lease = engine->allocateLease4(ctx);
4697 // Check that we got that single lease.
4698 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4698, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4699 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4699, gtest_ar.failure_message()) = ::testing::Message()
;
4700
4701 // The lease was not reused.
4702 EXPECT_EQ(0U, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "lease->reuseable_valid_lft_"
, 0U, lease->reuseable_valid_lft_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4702, gtest_ar.failure_message()) = ::testing::Message()
;
4703}
4704
4705// This test checks if a lease can't be reused in DHCPREQUEST (real allocation)
4706// using too small cache max age.
4707TEST_F(AllocEngine4Test, requestCacheBadMaxAge4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestCacheBadMaxAge4") > 1, "test_name must not be empty"
); class AllocEngine4Test_requestCacheBadMaxAge4_Test : public
AllocEngine4Test { public: AllocEngine4Test_requestCacheBadMaxAge4_Test
() = default; ~AllocEngine4Test_requestCacheBadMaxAge4_Test()
override = default; AllocEngine4Test_requestCacheBadMaxAge4_Test
(const AllocEngine4Test_requestCacheBadMaxAge4_Test &) =
delete; AllocEngine4Test_requestCacheBadMaxAge4_Test & operator
=( const AllocEngine4Test_requestCacheBadMaxAge4_Test &) =
delete; AllocEngine4Test_requestCacheBadMaxAge4_Test (AllocEngine4Test_requestCacheBadMaxAge4_Test
&&) noexcept = delete; AllocEngine4Test_requestCacheBadMaxAge4_Test
& operator=( AllocEngine4Test_requestCacheBadMaxAge4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheBadMaxAge4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestCacheBadMaxAge4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4707), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4707), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4707), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBadMaxAge4_Test
>); void AllocEngine4Test_requestCacheBadMaxAge4_Test::TestBody
()
{
4708 boost::scoped_ptr<AllocEngine> engine;
4709 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4709
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4709
; } } else gtest_label_testnothrow_4709 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4709, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4710 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4710, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4711
4712 // Set valid lifetime to 500.
4713 uint32_t valid = 500;
4714 subnet_->setValid(valid);
4715
4716 // Set the threshold to 25%.
4717 subnet_->setCacheThreshold(.25);
4718
4719 // Set the max age to 50.
4720 subnet_->setCacheMaxAge(50);
4721
4722 IOAddress addr("192.0.2.105");
4723 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4724 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4725 valid, now, subnet_->getID()));
4726 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4727
4728 // Create a context for real allocation.
4729 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4730 false, false, "", false);
4731
4732 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4733 lease = engine->allocateLease4(ctx);
4734 // Check that we got that single lease.
4735 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4735, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4736 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4736, gtest_ar.failure_message()) = ::testing::Message()
;
4737
4738 // The lease was not reused.
4739 EXPECT_EQ(0U, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "lease->reuseable_valid_lft_"
, 0U, lease->reuseable_valid_lft_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4739, gtest_ar.failure_message()) = ::testing::Message()
;
4740
4741 // Check the lease was updated in the database.
4742 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4743 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4743, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4744
4745 detailCompareLease(lease, from_mgr);
4746}
4747
4748// This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation)
4749// when the valid lifetime was reduced.
4750TEST_F(AllocEngine4Test, discoverCacheReducedValid4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverCacheReducedValid4") > 1,
"test_name must not be empty"); class AllocEngine4Test_discoverCacheReducedValid4_Test
: public AllocEngine4Test { public: AllocEngine4Test_discoverCacheReducedValid4_Test
() = default; ~AllocEngine4Test_discoverCacheReducedValid4_Test
() override = default; AllocEngine4Test_discoverCacheReducedValid4_Test
(const AllocEngine4Test_discoverCacheReducedValid4_Test &
) = delete; AllocEngine4Test_discoverCacheReducedValid4_Test &
operator=( const AllocEngine4Test_discoverCacheReducedValid4_Test
&) = delete; AllocEngine4Test_discoverCacheReducedValid4_Test
(AllocEngine4Test_discoverCacheReducedValid4_Test &&
) noexcept = delete; AllocEngine4Test_discoverCacheReducedValid4_Test
& operator=( AllocEngine4Test_discoverCacheReducedValid4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheReducedValid4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverCacheReducedValid4", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4750), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4750), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4750), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheReducedValid4_Test
>); void AllocEngine4Test_discoverCacheReducedValid4_Test::
TestBody()
{
4751 boost::scoped_ptr<AllocEngine> engine;
4752 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4752
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4752
; } } else gtest_label_testnothrow_4752 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4752, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4753 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4753, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4754
4755 // Set valid lifetime to 200.
4756 subnet_->setValid(200);
4757
4758 // Set the threshold to 25%.
4759 subnet_->setCacheThreshold(.25);
4760
4761 IOAddress addr("192.0.2.105");
4762 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4763 uint32_t valid = 500; // Used a value greater than subnet_->getValid().
4764 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4765 valid, now, subnet_->getID()));
4766 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4766, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4767 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4767, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4768
4769 // Create a context for fake allocation.
4770 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4771 false, false, "", true);
4772
4773 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4774 lease = engine->allocateLease4(ctx);
4775 // Check that we got that single lease.
4776 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4776, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4777 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4777, gtest_ar.failure_message()) = ::testing::Message()
;
4778
4779 // The lease was not reused.
4780 EXPECT_EQ(0U, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "lease->reuseable_valid_lft_"
, 0U, lease->reuseable_valid_lft_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4780, gtest_ar.failure_message()) = ::testing::Message()
;
4781}
4782
4783// This test checks if a lease can't be reused in DHCPREQUEST (real allocation)
4784// when DDNS parameter changed.
4785TEST_F(AllocEngine4Test, requestCacheFwdDDNS4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestCacheFwdDDNS4") > 1, "test_name must not be empty"
); class AllocEngine4Test_requestCacheFwdDDNS4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_requestCacheFwdDDNS4_Test() = default
; ~AllocEngine4Test_requestCacheFwdDDNS4_Test() override = default
; AllocEngine4Test_requestCacheFwdDDNS4_Test (const AllocEngine4Test_requestCacheFwdDDNS4_Test
&) = delete; AllocEngine4Test_requestCacheFwdDDNS4_Test &
operator=( const AllocEngine4Test_requestCacheFwdDDNS4_Test &
) = delete; AllocEngine4Test_requestCacheFwdDDNS4_Test (AllocEngine4Test_requestCacheFwdDDNS4_Test
&&) noexcept = delete; AllocEngine4Test_requestCacheFwdDDNS4_Test
& operator=( AllocEngine4Test_requestCacheFwdDDNS4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_requestCacheFwdDDNS4_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestCacheFwdDDNS4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4785), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4785), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4785), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheFwdDDNS4_Test
>); void AllocEngine4Test_requestCacheFwdDDNS4_Test::TestBody
()
{
4786 boost::scoped_ptr<AllocEngine> engine;
4787 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4787
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4787
; } } else gtest_label_testnothrow_4787 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4787, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4788 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4788, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4789
4790 // Set valid lifetime to 500.
4791 uint32_t valid = 500;
4792 subnet_->setValid(valid);
4793
4794 // Set the max age to 200.
4795 subnet_->setCacheMaxAge(200);
4796
4797 IOAddress addr("192.0.2.105");
4798 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4799 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4800 valid, now, subnet_->getID()));
4801 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4801, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4802
4803 // Create a context for real allocation with fwd_dns_update changed.
4804 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4805 true, false, "", false);
4806
4807 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4808 lease = engine->allocateLease4(ctx);
4809 // Check that we got that single lease.
4810 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4810, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4811 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4811, gtest_ar.failure_message()) = ::testing::Message()
;
4812
4813 // The lease was not reused.
4814 EXPECT_EQ(0U, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "lease->reuseable_valid_lft_"
, 0U, lease->reuseable_valid_lft_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4814, gtest_ar.failure_message()) = ::testing::Message()
;
4815
4816 // Check the lease was updated in the database.
4817 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4818 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4818, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4819
4820 detailCompareLease(lease, from_mgr);
4821}
4822
4823// This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation)
4824// when DDNS parameter changed.
4825TEST_F(AllocEngine4Test, discoverCacheRevDDNS4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverCacheRevDDNS4") > 1, "test_name must not be empty"
); class AllocEngine4Test_discoverCacheRevDDNS4_Test : public
AllocEngine4Test { public: AllocEngine4Test_discoverCacheRevDDNS4_Test
() = default; ~AllocEngine4Test_discoverCacheRevDDNS4_Test() override
= default; AllocEngine4Test_discoverCacheRevDDNS4_Test (const
AllocEngine4Test_discoverCacheRevDDNS4_Test &) = delete;
AllocEngine4Test_discoverCacheRevDDNS4_Test & operator=(
const AllocEngine4Test_discoverCacheRevDDNS4_Test &) = delete
; AllocEngine4Test_discoverCacheRevDDNS4_Test (AllocEngine4Test_discoverCacheRevDDNS4_Test
&&) noexcept = delete; AllocEngine4Test_discoverCacheRevDDNS4_Test
& operator=( AllocEngine4Test_discoverCacheRevDDNS4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheRevDDNS4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverCacheRevDDNS4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4825), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4825), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4825), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheRevDDNS4_Test
>); void AllocEngine4Test_discoverCacheRevDDNS4_Test::TestBody
()
{
4826 boost::scoped_ptr<AllocEngine> engine;
4827 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4827
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4827
; } } else gtest_label_testnothrow_4827 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4827, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4828 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4829
4830 // Set valid lifetime to 500.
4831 uint32_t valid = 500;
4832 subnet_->setValid(valid);
4833
4834 // Set the threshold to 25%.
4835 subnet_->setCacheThreshold(.25);
4836
4837 // Set the max age to 200.
4838 subnet_->setCacheMaxAge(200);
4839
4840 IOAddress addr("192.0.2.105");
4841 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4842 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4843 valid, now, subnet_->getID()));
4844 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4844, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4845 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4845, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4846
4847 // Create a context for fake allocation with rev_dns_update changed.
4848 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4849 false, true, "", true);
4850
4851 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4852 lease = engine->allocateLease4(ctx);
4853 // Check that we got that single lease.
4854 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4854, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4855 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4855, gtest_ar.failure_message()) = ::testing::Message()
;
4856
4857 // The lease was not reused.
4858 EXPECT_EQ(0U, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "lease->reuseable_valid_lft_"
, 0U, lease->reuseable_valid_lft_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4858, gtest_ar.failure_message()) = ::testing::Message()
;
4859}
4860
4861// This test checks if a lease can't be reused in DHCPREQUEST (real allocation)
4862// when hostname changed.
4863TEST_F(AllocEngine4Test, requestCacheHostname4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestCacheHostname4") > 1, "test_name must not be empty"
); class AllocEngine4Test_requestCacheHostname4_Test : public
AllocEngine4Test { public: AllocEngine4Test_requestCacheHostname4_Test
() = default; ~AllocEngine4Test_requestCacheHostname4_Test() override
= default; AllocEngine4Test_requestCacheHostname4_Test (const
AllocEngine4Test_requestCacheHostname4_Test &) = delete;
AllocEngine4Test_requestCacheHostname4_Test & operator=(
const AllocEngine4Test_requestCacheHostname4_Test &) = delete
; AllocEngine4Test_requestCacheHostname4_Test (AllocEngine4Test_requestCacheHostname4_Test
&&) noexcept = delete; AllocEngine4Test_requestCacheHostname4_Test
& operator=( AllocEngine4Test_requestCacheHostname4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheHostname4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "requestCacheHostname4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4863), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4863), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4863), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheHostname4_Test
>); void AllocEngine4Test_requestCacheHostname4_Test::TestBody
()
{
4864 boost::scoped_ptr<AllocEngine> engine;
4865 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4865
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4865
; } } else gtest_label_testnothrow_4865 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4865, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4866 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4866, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4867
4868 // Set valid lifetime to 500.
4869 uint32_t valid = 500;
4870 subnet_->setValid(valid);
4871
4872 // Set the max age to 200.
4873 subnet_->setCacheMaxAge(200);
4874
4875 IOAddress addr("192.0.2.105");
4876 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4877 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4878 valid, now, subnet_->getID(),
4879 false, false, "foo"));
4880 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4881
4882 // Create a context for real allocation with fwd_dns_update changed.
4883 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4884 false, false, "bar", false);
4885
4886 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4887 lease = engine->allocateLease4(ctx);
4888 // Check that we got that single lease.
4889 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4889, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4890 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4890, gtest_ar.failure_message()) = ::testing::Message()
;
4891
4892 // The lease was not reused.
4893 EXPECT_EQ(0U, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "lease->reuseable_valid_lft_"
, 0U, lease->reuseable_valid_lft_))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4893, gtest_ar.failure_message()) = ::testing::Message()
;
4894 EXPECT_EQ("bar", lease->hostname_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"bar\""
, "lease->hostname_", "bar", lease->hostname_))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4894, gtest_ar.failure_message()) = ::testing::Message()
;
4895
4896 // Check the lease was updated in the database.
4897 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4898 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4898, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4899
4900 detailCompareLease(lease, from_mgr);
4901}
4902
4903// Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate
4904// lifetime value based on the context content.
4905TEST_F(AllocEngine4Test, getValidLft4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getValidLft4") > 1, "test_name must not be empty"
); class AllocEngine4Test_getValidLft4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_getValidLft4_Test() = default; ~AllocEngine4Test_getValidLft4_Test
() override = default; AllocEngine4Test_getValidLft4_Test (const
AllocEngine4Test_getValidLft4_Test &) = delete; AllocEngine4Test_getValidLft4_Test
& operator=( const AllocEngine4Test_getValidLft4_Test &
) = delete; AllocEngine4Test_getValidLft4_Test (AllocEngine4Test_getValidLft4_Test
&&) noexcept = delete; AllocEngine4Test_getValidLft4_Test
& operator=( AllocEngine4Test_getValidLft4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_getValidLft4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "getValidLft4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 4905
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4905), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4905), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getValidLft4_Test
>); void AllocEngine4Test_getValidLft4_Test::TestBody()
{
4906 AllocEngine engine(0);
4907
4908 // Let's make three classes, two with valid-lifetime and one without,
4909 // and add them to the dictionary.
4910 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
4911
4912 ClientClassDefPtr class_def(new ClientClassDef("valid_one", ExpressionPtr()));
4913 Triplet<uint32_t> valid_one(50, 100, 150);
4914 class_def->setValid(valid_one);
4915 dictionary->addClass(class_def);
4916
4917 class_def.reset(new ClientClassDef("valid_two", ExpressionPtr()));
4918 Triplet<uint32_t>valid_two(200, 250, 300);
4919 class_def->setValid(valid_two);
4920 dictionary->addClass(class_def);
4921
4922 class_def.reset(new ClientClassDef("valid_unspec", ExpressionPtr()));
4923 dictionary->addClass(class_def);
4924
4925 // Commit our class changes.
4926 CfgMgr::instance().commit();
4927
4928 // Update the subnet's triplet to something more useful.
4929 subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500));
4930
4931 // Describes a test scenario.
4932 struct Scenario {
4933 std::string desc_; // descriptive text for logging
4934 std::vector<std::string> classes_; // class list of assigned classes
4935 uint32_t requested_lft_; // use as option 51 is > 0
4936 uint32_t exp_valid_; // expected lifetime
4937 };
4938
4939 // Scenarios to test.
4940 std::vector<Scenario> scenarios = {
4941 {
4942 "BOOTP",
4943 { "BOOTP" },
4944 0,
4945 Lease::INFINITY_LFT
4946 },
4947 {
4948 "no classes, no option",
4949 {},
4950 0,
4951 subnet_->getValid()
4952 },
4953 {
4954 "no classes, option",
4955 {},
4956 subnet_->getValid().getMin() + 50,
4957 subnet_->getValid().getMin() + 50
4958 },
4959 {
4960 "no classes, option too small",
4961 {},
4962 subnet_->getValid().getMin() - 50,
4963 subnet_->getValid().getMin()
4964 },
4965 {
4966 "no classes, option too big",
4967 {},
4968 subnet_->getValid().getMax() + 50,
4969 subnet_->getValid().getMax()
4970 },
4971 {
4972 "class unspecified, no option",
4973 { "valid_unspec" },
4974 0,
4975 subnet_->getValid()
4976 },
4977 {
4978 "from last class, no option",
4979 { "valid_unspec", "valid_one" },
4980 0,
4981 valid_one.get()
4982 },
4983 {
4984 "from first class, no option",
4985 { "valid_two", "valid_one" },
4986 0,
4987 valid_two.get()
4988 },
4989 {
4990 "class plus option",
4991 { "valid_one" },
4992 valid_one.getMin() + 25,
4993 valid_one.getMin() + 25
4994 },
4995 {
4996 "class plus option too small",
4997 { "valid_one" },
4998 valid_one.getMin() - 25,
4999 valid_one.getMin()
5000 },
5001 {
5002 "class plus option too big",
5003 { "valid_one" },
5004 valid_one.getMax() + 25,
5005 valid_one.getMax()
5006 }
5007 };
5008
5009 // Iterate over the scenarios and verify the correct outcome.
5010 for (auto const& scenario : scenarios) {
5011 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5011( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5011, (scenario.desc_))
; {
5012 // Create a context;
5013 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
5014 IOAddress("0.0.0.0"), false, false,
5015 "", false);
5016 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5017
5018 // Add client classes (if any)
5019 for (auto const& class_name : scenario.classes_) {
5020 ctx.query_->addClass(class_name);
5021 }
5022
5023 // Add client option (if one)
5024 if (scenario.requested_lft_) {
5025 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME,
5026 scenario.requested_lft_));
5027 ctx.query_->addOption(opt);
5028 }
5029
5030 Lease4Ptr lease = engine.allocateLease4(ctx);
5031 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5031, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5032 EXPECT_EQ(lease->valid_lft_, scenario.exp_valid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->valid_lft_"
, "scenario.exp_valid_", lease->valid_lft_, scenario.exp_valid_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5032, gtest_ar.failure_message()) = ::testing::Message()
;
5033 }
5034 }
5035}
5036
5037// Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate
5038// lifetime value based on the context content.
5039TEST_F(AllocEngine4Test, getTemplateClassValidLft4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getTemplateClassValidLft4") > 1, "test_name must not be empty"
); class AllocEngine4Test_getTemplateClassValidLft4_Test : public
AllocEngine4Test { public: AllocEngine4Test_getTemplateClassValidLft4_Test
() = default; ~AllocEngine4Test_getTemplateClassValidLft4_Test
() override = default; AllocEngine4Test_getTemplateClassValidLft4_Test
(const AllocEngine4Test_getTemplateClassValidLft4_Test &
) = delete; AllocEngine4Test_getTemplateClassValidLft4_Test &
operator=( const AllocEngine4Test_getTemplateClassValidLft4_Test
&) = delete; AllocEngine4Test_getTemplateClassValidLft4_Test
(AllocEngine4Test_getTemplateClassValidLft4_Test &&)
noexcept = delete; AllocEngine4Test_getTemplateClassValidLft4_Test
& operator=( AllocEngine4Test_getTemplateClassValidLft4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_getTemplateClassValidLft4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "getTemplateClassValidLft4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5039), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5039), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5039), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getTemplateClassValidLft4_Test
>); void AllocEngine4Test_getTemplateClassValidLft4_Test::
TestBody()
{
5040 AllocEngine engine(0);
5041
5042 // Let's make three classes, two with valid-lifetime and one without,
5043 // and add them to the dictionary.
5044 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
5045 ExpressionPtr match_expr;
5046 ExpressionParser parser;
5047
5048 ElementPtr test_cfg = Element::create("'valid_one_value'");
5049 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5050
5051 ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr));
5052 Triplet<uint32_t> valid_one(50, 100, 150);
5053 class_def->setValid(valid_one);
5054 dictionary->addClass(class_def);
5055
5056 test_cfg = Element::create("'valid_two_value'");
5057 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5058
5059 class_def.reset(new TemplateClientClassDef("valid_two", match_expr));
5060 Triplet<uint32_t>valid_two(200, 250, 300);
5061 class_def->setValid(valid_two);
5062 dictionary->addClass(class_def);
5063
5064 test_cfg = Element::create("'valid_unspec_value'");
5065 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5066
5067 class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr));
5068 dictionary->addClass(class_def);
5069
5070 // Commit our class changes.
5071 CfgMgr::instance().commit();
5072
5073 // Update the subnet's triplet to something more useful.
5074 subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500));
5075
5076 // Describes a test scenario.
5077 struct Scenario {
5078 std::string desc_; // descriptive text for logging
5079 std::vector<std::string> classes_; // class list of assigned classes
5080 uint32_t requested_lft_; // use as option 51 is > 0
5081 uint32_t exp_valid_; // expected lifetime
5082 };
5083
5084 // Scenarios to test.
5085 std::vector<Scenario> scenarios = {
5086 {
5087 "BOOTP",
5088 { "BOOTP" },
5089 0,
5090 Lease::INFINITY_LFT
5091 },
5092 {
5093 "no classes, no option",
5094 {},
5095 0,
5096 subnet_->getValid()
5097 },
5098 {
5099 "no classes, option",
5100 {},
5101 subnet_->getValid().getMin() + 50,
5102 subnet_->getValid().getMin() + 50
5103 },
5104 {
5105 "no classes, option too small",
5106 {},
5107 subnet_->getValid().getMin() - 50,
5108 subnet_->getValid().getMin()
5109 },
5110 {
5111 "no classes, option too big",
5112 {},
5113 subnet_->getValid().getMax() + 50,
5114 subnet_->getValid().getMax()
5115 },
5116 {
5117 "class unspecified, no option",
5118 { "valid_unspec" },
5119 0,
5120 subnet_->getValid()
5121 },
5122 {
5123 "from last class, no option",
5124 { "valid_unspec", "valid_one" },
5125 0,
5126 valid_one.get()
5127 },
5128 {
5129 "from first class, no option",
5130 { "valid_two", "valid_one" },
5131 0,
5132 valid_two.get()
5133 },
5134 {
5135 "class plus option",
5136 { "valid_one" },
5137 valid_one.getMin() + 25,
5138 valid_one.getMin() + 25
5139 },
5140 {
5141 "class plus option too small",
5142 { "valid_one" },
5143 valid_one.getMin() - 25,
5144 valid_one.getMin()
5145 },
5146 {
5147 "class plus option too big",
5148 { "valid_one" },
5149 valid_one.getMax() + 25,
5150 valid_one.getMax()
5151 }
5152 };
5153
5154 // Iterate over the scenarios and verify the correct outcome.
5155 for (auto const& scenario : scenarios) {
5156 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5156( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5156, (scenario.desc_))
; {
5157 // Create a context;
5158 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
5159 IOAddress("0.0.0.0"), false, false,
5160 "", false);
5161 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5162
5163 // Add client classes (if any)
5164 for (auto const& class_name : scenario.classes_) {
5165 if (class_name == "BOOTP") {
5166 ctx.query_->addClass(class_name);
5167 } else {
5168 string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX);
5169 subclass += class_name;
5170 subclass += "_value";
5171 ctx.query_->addSubClass(class_name, subclass);
5172 }
5173 }
5174
5175 // Add client option (if one)
5176 if (scenario.requested_lft_) {
5177 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME,
5178 scenario.requested_lft_));
5179 ctx.query_->addOption(opt);
5180 }
5181
5182 Lease4Ptr lease = engine.allocateLease4(ctx);
5183 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5183, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5184 EXPECT_EQ(lease->valid_lft_, scenario.exp_valid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->valid_lft_"
, "scenario.exp_valid_", lease->valid_lft_, scenario.exp_valid_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5184, gtest_ar.failure_message()) = ::testing::Message()
;
5185 }
5186 }
5187}
5188
5189// Verifies that AllocEngine::getMinValidLft(ctx4, valid) sets the appropriate
5190// lifetime value based on the context content.
5191TEST_F(AllocEngine4Test, getMinValidLft4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getMinValidLft4") > 1, "test_name must not be empty"
); class AllocEngine4Test_getMinValidLft4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_getMinValidLft4_Test() = default;
~AllocEngine4Test_getMinValidLft4_Test() override = default;
AllocEngine4Test_getMinValidLft4_Test (const AllocEngine4Test_getMinValidLft4_Test
&) = delete; AllocEngine4Test_getMinValidLft4_Test &
operator=( const AllocEngine4Test_getMinValidLft4_Test &
) = delete; AllocEngine4Test_getMinValidLft4_Test (AllocEngine4Test_getMinValidLft4_Test
&&) noexcept = delete; AllocEngine4Test_getMinValidLft4_Test
& operator=( AllocEngine4Test_getMinValidLft4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_getMinValidLft4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "getMinValidLft4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 5191
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5191), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5191), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getMinValidLft4_Test
>); void AllocEngine4Test_getMinValidLft4_Test::TestBody()
{
5192 AllocEngine engine(0);
5193
5194 // Let's make three classes, two with valid-lifetime and one without,
5195 // and add them to the dictionary.
5196 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
5197 ExpressionPtr match_expr;
5198 ExpressionParser parser;
5199
5200 ElementPtr test_cfg = Element::create("'valid_one_value'");
5201 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5202
5203 ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr));
5204 Triplet<uint32_t> valid_one(50, 100, 150);
5205 class_def->setValid(valid_one);
5206 dictionary->addClass(class_def);
5207
5208 test_cfg = Element::create("'valid_two_value'");
5209 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5210
5211 class_def.reset(new TemplateClientClassDef("valid_two", match_expr));
5212 Triplet<uint32_t>valid_two(200, 250, 300);
5213 class_def->setValid(valid_two);
5214 dictionary->addClass(class_def);
5215
5216 test_cfg = Element::create("'valid_unspec_value'");
5217 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5218
5219 class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr));
5220 dictionary->addClass(class_def);
5221
5222 // Commit our class changes.
5223 CfgMgr::instance().commit();
5224
5225 // Update the subnet's triplet to something more useful.
5226 subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500));
5227
5228 // Describes a test scenario.
5229 struct Scenario {
5230 std::string desc_; // descriptive text for logging
5231 std::vector<std::string> classes_; // class list of assigned classes
5232 uint32_t requested_lft_; // use as option 51 is > 0
5233 uint32_t remaining_lft_; // remaining lifime or 0
5234 uint32_t exp_valid_; // expected lifetime
5235 };
5236
5237 // Scenarios to test.
5238 std::vector<Scenario> scenarios = {
5239 {
5240 "BOOTP",
5241 { "BOOTP" },
5242 0,
5243 0,
5244 Lease::INFINITY_LFT
5245 },
5246 {
5247 "no classes, no option, remain 0",
5248 {},
5249 0,
5250 0,
5251 subnet_->getValid().getMin()
5252 },
5253 {
5254 "no classes, no option, remain too small",
5255 {},
5256 0,
5257 100,
5258 subnet_->getValid().getMin()
5259 },
5260 {
5261 "no classes, no option, remain",
5262 {},
5263 0,
5264 800,
5265 800
5266 },
5267 {
5268 "no classes, option, remain 0",
5269 {},
5270 1000,
5271 0,
5272 subnet_->getValid().getMin()
5273 },
5274 {
5275 "class unspecified, no option, remain 0",
5276 { "valid_unspec" },
5277 0,
5278 0,
5279 subnet_->getValid().getMin()
5280 },
5281 {
5282 "from last class, no option, remain 0",
5283 { "valid_unspec", "valid_one" },
5284 0,
5285 0,
5286 valid_one.getMin()
5287 },
5288 {
5289 "from first class, no option, remain 0",
5290 { "valid_two", "valid_one" },
5291 0,
5292 0,
5293 valid_two.getMin()
5294 },
5295 {
5296 "class plus remain too small",
5297 { "valid_one" },
5298 0,
5299 10,
5300 valid_one.getMin(),
5301 },
5302 {
5303 "class plus remain",
5304 { "valid_one" },
5305 0,
5306 100,
5307 100
5308 }
5309 };
5310
5311 // Iterate over the scenarios and verify the correct outcome.
5312 for (auto const& scenario : scenarios) {
5313 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5313( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5313, (scenario.desc_))
; {
5314 // Create a context;
5315 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
5316 IOAddress("0.0.0.0"), false, false,
5317 "", false);
5318 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5319
5320 // Add client classes (if any)
5321 for (auto const& class_name : scenario.classes_) {
5322 if (class_name == "BOOTP") {
5323 ctx.query_->addClass(class_name);
5324 } else {
5325 string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX);
5326 subclass += class_name;
5327 subclass += "_value";
5328 ctx.query_->addSubClass(class_name, subclass);
5329 }
5330 }
5331
5332 // Add client option (if one)
5333 if (scenario.requested_lft_) {
5334 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME,
5335 scenario.requested_lft_));
5336 ctx.query_->addOption(opt);
5337 }
5338
5339 uint32_t valid = scenario.remaining_lft_;
5340 engine.getMinValidLft(ctx, valid);
5341 EXPECT_EQ(valid, scenario.exp_valid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("valid", "scenario.exp_valid_"
, valid, scenario.exp_valid_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5341, gtest_ar.failure_message()) = ::testing::Message()
;
5342 }
5343 }
5344}
5345
5346// Verifies that AllocEngine::getRemaining retuns the remaining lifetime value.
5347TEST_F(AllocEngine4Test, getRemaining)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getRemaining") > 1, "test_name must not be empty"
); class AllocEngine4Test_getRemaining_Test : public AllocEngine4Test
{ public: AllocEngine4Test_getRemaining_Test() = default; ~AllocEngine4Test_getRemaining_Test
() override = default; AllocEngine4Test_getRemaining_Test (const
AllocEngine4Test_getRemaining_Test &) = delete; AllocEngine4Test_getRemaining_Test
& operator=( const AllocEngine4Test_getRemaining_Test &
) = delete; AllocEngine4Test_getRemaining_Test (AllocEngine4Test_getRemaining_Test
&&) noexcept = delete; AllocEngine4Test_getRemaining_Test
& operator=( AllocEngine4Test_getRemaining_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_getRemaining_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "getRemaining", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 5347
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5347), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5347), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getRemaining_Test
>); void AllocEngine4Test_getRemaining_Test::TestBody()
{
5348 // No Lease.
5349 uint32_t valid(1);
5350 Lease4Ptr lease;
5351 AllocEngine::getRemaining(lease, valid);
5352 EXPECT_EQ(0U, valid)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "valid"
, 0U, valid))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5352, gtest_ar.failure_message()) = ::testing::Message()
;
5353
5354 // Unexpected state.
5355 valid = 1;
5356 uint8_t hwaddr_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
5357 HWAddrPtr hwaddr(new HWAddr(hwaddr_data, sizeof(hwaddr_data), HTYPE_ETHER));
5358 uint8_t clientid[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
5359 time_t now = time(0);
5360 lease.reset(new Lease4(IOAddress("192.0.2.100"), hwaddr, clientid,
5361 sizeof(clientid), 100, now, 1));
5362 lease->state_ = Lease::STATE_DECLINED;
5363 AllocEngine::getRemaining(lease, valid);
5364 EXPECT_EQ(0U, valid)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "valid"
, 0U, valid))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5364, gtest_ar.failure_message()) = ::testing::Message()
;
5365
5366 // Infinite lifetime.
5367 lease->state_ = Lease::STATE_DEFAULT;
5368 uint32_t infinity_lft = Lease::INFINITY_LFT;
5369 lease->valid_lft_ = lease->current_valid_lft_ = infinity_lft;
5370 AllocEngine::getRemaining(lease, valid);
5371 EXPECT_EQ(infinity_lft, valid)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("infinity_lft"
, "valid", infinity_lft, valid))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5371, gtest_ar.failure_message()) = ::testing::Message()
;
5372
5373 // Time going backward.
5374 lease->cltt_ = lease->current_cltt_ = now + 100;
5375 lease->valid_lft_ = lease->current_valid_lft_ = 50;
5376 AllocEngine::getRemaining(lease, valid);
5377 EXPECT_EQ(0U, valid)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "valid"
, 0U, valid))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5377, gtest_ar.failure_message()) = ::testing::Message()
;
5378
5379 // Already expired.
5380 valid = 1;
5381 lease->cltt_ = lease->current_cltt_ = now - 100;
5382 AllocEngine::getRemaining(lease, valid);
5383 EXPECT_EQ(0U, valid)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "valid"
, 0U, valid))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5383, gtest_ar.failure_message()) = ::testing::Message()
;
5384
5385 // Valid case.
5386 now = time(0);
5387 lease->cltt_ = lease->current_cltt_ = now - 10;
5388 AllocEngine::getRemaining(lease, valid);
5389 EXPECT_NEAR(40U, valid, 1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::DoubleNearPredFormat("40U",
"valid", "1", 40U, valid, 1))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5389, gtest_ar.failure_message()) = ::testing::Message()
;
5390}
5391
5392// This test checks that deleteRelease handles BOOTP leases.
5393TEST_F(AllocEngine4Test, bootpDelete)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("bootpDelete") > 1, "test_name must not be empty"
); class AllocEngine4Test_bootpDelete_Test : public AllocEngine4Test
{ public: AllocEngine4Test_bootpDelete_Test() = default; ~AllocEngine4Test_bootpDelete_Test
() override = default; AllocEngine4Test_bootpDelete_Test (const
AllocEngine4Test_bootpDelete_Test &) = delete; AllocEngine4Test_bootpDelete_Test
& operator=( const AllocEngine4Test_bootpDelete_Test &
) = delete; AllocEngine4Test_bootpDelete_Test (AllocEngine4Test_bootpDelete_Test
&&) noexcept = delete; AllocEngine4Test_bootpDelete_Test
& operator=( AllocEngine4Test_bootpDelete_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_bootpDelete_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "bootpDelete", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 5393
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5393), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5393), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpDelete_Test
>); void AllocEngine4Test_bootpDelete_Test::TestBody()
{
5394 boost::scoped_ptr<AllocEngine> engine;
5395 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5395
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5395
; } } else gtest_label_testnothrow_5395 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5395, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5396 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5396, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5397
5398 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
5399 false, true, "somehost.example.com.", false);
5400 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
5401 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
5402
5403 // Make the query a BOOTP one.
5404 ctx.query_->addClass("BOOTP");
5405
5406 Lease4Ptr lease = engine->allocateLease4(ctx);
5407 // The new lease has been allocated, so the old lease should not exist.
5408 ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5408, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
5409
5410 // Check that we got a lease
5411 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5411, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5412
5413 // Check that is belongs to the right subnet and client.
5414 EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_"
, "subnet_->getID()", lease->subnet_id_, subnet_->getID
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5414, gtest_ar.failure_message()) = ::testing::Message()
;
5415 EXPECT_TRUE(subnet_->inRange(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease
->addr_))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5415, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
5416 EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease
::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5416, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
5417 ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->client_id_)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5417, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
5418 EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->client_id_
== *clientid_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5418, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
5419 ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5419, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
5420 EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ ==
*hwaddr_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5420, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
5421
5422 // Check the valid lifetime is infinite.
5423 uint32_t infinity_lft = Lease::INFINITY_LFT;
5424 EXPECT_EQ(infinity_lft, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("infinity_lft"
, "lease->valid_lft_", infinity_lft, lease->valid_lft_)
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5424, gtest_ar.failure_message()) = ::testing::Message()
;
5425
5426 // Check that the lease is indeed in LeaseMgr
5427 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5428 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5428, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5429
5430 // Now delete it.
5431 bool deleted = false;
5432 ASSERT_NO_THROW(deleted = LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
deleted = LeaseMgrFactory::instance().deleteLease(lease); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_5432; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_5432; } } else gtest_label_testnothrow_5432
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5432, ("Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
5433 EXPECT_TRUE(deleted)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(deleted)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
5433, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "deleted", "false", "true") .c_str()) = ::testing::Message(
)
;
5434 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5435 EXPECT_FALSE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc",
5435, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "true", "false") .c_str()) = ::testing::Message
()
;
5436}
5437
5438// This test verifies that all addresses in a pool can be allocated.
5439TEST_F(AllocEngine4Test, fullPool)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("fullPool") > 1, "test_name must not be empty"
); class AllocEngine4Test_fullPool_Test : public AllocEngine4Test
{ public: AllocEngine4Test_fullPool_Test() = default; ~AllocEngine4Test_fullPool_Test
() override = default; AllocEngine4Test_fullPool_Test (const AllocEngine4Test_fullPool_Test
&) = delete; AllocEngine4Test_fullPool_Test & operator
=( const AllocEngine4Test_fullPool_Test &) = delete; AllocEngine4Test_fullPool_Test
(AllocEngine4Test_fullPool_Test &&) noexcept = delete
; AllocEngine4Test_fullPool_Test & operator=( AllocEngine4Test_fullPool_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_fullPool_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "fullPool", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 5439
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5439), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5439), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullPool_Test
>); void AllocEngine4Test_fullPool_Test::TestBody()
{
5440 boost::scoped_ptr<AllocEngine> engine;
5441 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5441
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5441
; } } else gtest_label_testnothrow_5441 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5441, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5442 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5442, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5443
5444 // Get rid of the default subnet configuration.
5445 CfgMgr& cfg_mgr = CfgMgr::instance();
5446 cfg_mgr.clear();
5447
5448 // Configure a larger subnet with a /24 pool.
5449 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5450 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5451 subnet_->addPool(pool_);
5452 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5453
5454 // Set exclude-first-last to false.
5455 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false);
5456 cfg_mgr.commit();
5457
5458 size_t cnt = 0;
5459 vector<bool> found(256, false);
5460 while (true) {
5461 vector<uint8_t> duid = clientid_->getClientId();
5462 duid[6] = cnt >> 8;
5463 duid[7] = cnt & 0xff;
5464 ClientIdPtr clientid(new ClientId(duid));
5465 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5466 hwaddr->hwaddr_[4] = cnt >> 8;
5467 hwaddr->hwaddr_[5] = cnt & 0xff;
5468 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5469 IOAddress("0.0.0.0"),
5470 false, false, "foo.bar", false);
5471 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5472 Lease4Ptr lease = engine->allocateLease4(ctx);
5473
5474 if (!lease) {
5475 break;
5476 }
5477 const vector<uint8_t>& addr = lease->addr_.toBytes();
5478 ASSERT_EQ(4U, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("4U", "addr.size()"
, 4U, addr.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5478, gtest_ar.failure_message()) = ::testing::Message()
;
5479 EXPECT_EQ(10U, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("10U", "addr[0]"
, 10U, addr[0]))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5479, gtest_ar.failure_message()) = ::testing::Message()
;
5480 EXPECT_EQ(0U, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addr[1]"
, 0U, addr[1]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5480, gtest_ar.failure_message()) = ::testing::Message()
;
5481 EXPECT_EQ(1U, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "addr[2]"
, 1U, addr[2]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5481, gtest_ar.failure_message()) = ::testing::Message()
;
5482 EXPECT_FALSE(found[addr[3]])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(found[addr[3]]))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5482, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5483 found[addr[3]] = true;
5484 ++cnt;
5485 // Catch unbound loop.
5486 ASSERT_LT(cnt, 1000U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000U",
cnt, 1000U))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5486, gtest_ar.failure_message()) = ::testing::Message()
;
5487 }
5488 EXPECT_EQ(256U, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("256U", "cnt"
, 256U, cnt))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5488, gtest_ar.failure_message()) = ::testing::Message()
;
5489 EXPECT_EQ(found, vector<bool>(256, true))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("found", "vector<bool>(256, true)"
, found, vector<bool>(256, true)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5489, gtest_ar.failure_message()) = ::testing::Message()
;
5490}
5491
5492// This test verifies that all addresses in a subnet can be allocated.
5493TEST_F(AllocEngine4Test, fullSubnet24)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("fullSubnet24") > 1, "test_name must not be empty"
); class AllocEngine4Test_fullSubnet24_Test : public AllocEngine4Test
{ public: AllocEngine4Test_fullSubnet24_Test() = default; ~AllocEngine4Test_fullSubnet24_Test
() override = default; AllocEngine4Test_fullSubnet24_Test (const
AllocEngine4Test_fullSubnet24_Test &) = delete; AllocEngine4Test_fullSubnet24_Test
& operator=( const AllocEngine4Test_fullSubnet24_Test &
) = delete; AllocEngine4Test_fullSubnet24_Test (AllocEngine4Test_fullSubnet24_Test
&&) noexcept = delete; AllocEngine4Test_fullSubnet24_Test
& operator=( AllocEngine4Test_fullSubnet24_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_fullSubnet24_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "fullSubnet24", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 5493
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5493), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5493), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullSubnet24_Test
>); void AllocEngine4Test_fullSubnet24_Test::TestBody()
{
5494 boost::scoped_ptr<AllocEngine> engine;
5495 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5495
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5495
; } } else gtest_label_testnothrow_5495 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5495, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5496 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5496, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5497
5498 // Get rid of the default subnet configuration.
5499 CfgMgr& cfg_mgr = CfgMgr::instance();
5500 cfg_mgr.clear();
5501
5502 // Configure a larger subnet with a /24 pool.
5503 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
5504 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"),
5505 IOAddress("192.0.2.255")));
5506 subnet_->addPool(pool_);
5507 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5508
5509 // Set exclude-first-last to false.
5510 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false);
5511 cfg_mgr.commit();
5512
5513 size_t cnt = 0;
5514 vector<bool> found(256, false);
5515 while (true) {
5516 vector<uint8_t> duid = clientid_->getClientId();
5517 duid[6] = cnt >> 8;
5518 duid[7] = cnt & 0xff;
5519 ClientIdPtr clientid(new ClientId(duid));
5520 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5521 hwaddr->hwaddr_[4] = cnt >> 8;
5522 hwaddr->hwaddr_[5] = cnt & 0xff;
5523 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5524 IOAddress("0.0.0.0"),
5525 false, false, "foo.bar", false);
5526 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5527 Lease4Ptr lease = engine->allocateLease4(ctx);
5528
5529 if (!lease) {
5530 break;
5531 }
5532 const vector<uint8_t>& addr = lease->addr_.toBytes();
5533 ASSERT_EQ(4U, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("4U", "addr.size()"
, 4U, addr.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5533, gtest_ar.failure_message()) = ::testing::Message()
;
5534 EXPECT_EQ(192U, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("192U", "addr[0]"
, 192U, addr[0]))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5534, gtest_ar.failure_message()) = ::testing::Message()
;
5535 EXPECT_EQ(0U, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addr[1]"
, 0U, addr[1]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5535, gtest_ar.failure_message()) = ::testing::Message()
;
5536 EXPECT_EQ(2U, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2U", "addr[2]"
, 2U, addr[2]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5536, gtest_ar.failure_message()) = ::testing::Message()
;
5537 EXPECT_FALSE(found[addr[3]])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(found[addr[3]]))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5537, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5538 found[addr[3]] = true;
5539 ++cnt;
5540 // Catch unbound loop.
5541 ASSERT_LT(cnt, 1000U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000U",
cnt, 1000U))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5541, gtest_ar.failure_message()) = ::testing::Message()
;
5542 }
5543 EXPECT_EQ(256U, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("256U", "cnt"
, 256U, cnt))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5543, gtest_ar.failure_message()) = ::testing::Message()
;
5544 EXPECT_EQ(found, vector<bool>(256, true))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("found", "vector<bool>(256, true)"
, found, vector<bool>(256, true)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5544, gtest_ar.failure_message()) = ::testing::Message()
;
5545}
5546
5547// This test verifies that not all addresses in a pool can be allocated when
5548// exclude-first-last is true.
5549TEST_F(AllocEngine4Test, excludeFirstLast)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("excludeFirstLast") > 1, "test_name must not be empty"
); class AllocEngine4Test_excludeFirstLast_Test : public AllocEngine4Test
{ public: AllocEngine4Test_excludeFirstLast_Test() = default
; ~AllocEngine4Test_excludeFirstLast_Test() override = default
; AllocEngine4Test_excludeFirstLast_Test (const AllocEngine4Test_excludeFirstLast_Test
&) = delete; AllocEngine4Test_excludeFirstLast_Test &
operator=( const AllocEngine4Test_excludeFirstLast_Test &
) = delete; AllocEngine4Test_excludeFirstLast_Test (AllocEngine4Test_excludeFirstLast_Test
&&) noexcept = delete; AllocEngine4Test_excludeFirstLast_Test
& operator=( AllocEngine4Test_excludeFirstLast_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_excludeFirstLast_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "excludeFirstLast", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5549), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5549), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5549), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast_Test
>); void AllocEngine4Test_excludeFirstLast_Test::TestBody(
)
{
5550 boost::scoped_ptr<AllocEngine> engine;
5551 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5551
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5551
; } } else gtest_label_testnothrow_5551 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5551, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5552 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5552, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5553
5554 // Get rid of the default subnet configuration.
5555 CfgMgr& cfg_mgr = CfgMgr::instance();
5556 cfg_mgr.clear();
5557
5558 // Configure a larger subnet with a /24 pool.
5559 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5560 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5561 subnet_->addPool(pool_);
5562 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5563
5564 // Set exclude-first-last to true.
5565 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5566 cfg_mgr.commit();
5567
5568 size_t cnt = 0;
5569 vector<bool> found(256, false);
5570 while (true) {
5571 vector<uint8_t> duid = clientid_->getClientId();
5572 duid[6] = cnt >> 8;
5573 duid[7] = cnt & 0xff;
5574 ClientIdPtr clientid(new ClientId(duid));
5575 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5576 hwaddr->hwaddr_[4] = cnt >> 8;
5577 hwaddr->hwaddr_[5] = cnt & 0xff;
5578 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5579 IOAddress("0.0.0.0"),
5580 false, false, "foo.bar", false);
5581 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5582 Lease4Ptr lease = engine->allocateLease4(ctx);
5583
5584 if (!lease) {
5585 break;
5586 }
5587 const vector<uint8_t>& addr = lease->addr_.toBytes();
5588 ASSERT_EQ(4U, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("4U", "addr.size()"
, 4U, addr.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5588, gtest_ar.failure_message()) = ::testing::Message()
;
5589 EXPECT_EQ(10U, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("10U", "addr[0]"
, 10U, addr[0]))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5589, gtest_ar.failure_message()) = ::testing::Message()
;
5590 EXPECT_EQ(0U, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addr[1]"
, 0U, addr[1]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5590, gtest_ar.failure_message()) = ::testing::Message()
;
5591 EXPECT_EQ(1U, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "addr[2]"
, 1U, addr[2]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5591, gtest_ar.failure_message()) = ::testing::Message()
;
5592 EXPECT_FALSE(found[addr[3]])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(found[addr[3]]))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5593 found[addr[3]] = true;
5594 ++cnt;
5595 // Catch unbound loop.
5596 ASSERT_LT(cnt, 1000U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000U",
cnt, 1000U))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5596, gtest_ar.failure_message()) = ::testing::Message()
;
5597 }
5598 EXPECT_EQ(254U, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("254U", "cnt"
, 254U, cnt))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5598, gtest_ar.failure_message()) = ::testing::Message()
;
5599 vector<bool> expected(256, true);
5600 expected[0] = false;
5601 expected[255] = false;
5602 EXPECT_EQ(expected, found)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "found", expected, found))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5602, gtest_ar.failure_message()) = ::testing::Message()
;
5603}
5604
5605// This test verifies that not all addresses in a subnet can be allocated when
5606// exclude-first-last is true.
5607TEST_F(AllocEngine4Test, excludeFirstLast24)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("excludeFirstLast24") > 1, "test_name must not be empty"
); class AllocEngine4Test_excludeFirstLast24_Test : public AllocEngine4Test
{ public: AllocEngine4Test_excludeFirstLast24_Test() = default
; ~AllocEngine4Test_excludeFirstLast24_Test() override = default
; AllocEngine4Test_excludeFirstLast24_Test (const AllocEngine4Test_excludeFirstLast24_Test
&) = delete; AllocEngine4Test_excludeFirstLast24_Test &
operator=( const AllocEngine4Test_excludeFirstLast24_Test &
) = delete; AllocEngine4Test_excludeFirstLast24_Test (AllocEngine4Test_excludeFirstLast24_Test
&&) noexcept = delete; AllocEngine4Test_excludeFirstLast24_Test
& operator=( AllocEngine4Test_excludeFirstLast24_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_excludeFirstLast24_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "excludeFirstLast24", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5607), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5607), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5607), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast24_Test
>); void AllocEngine4Test_excludeFirstLast24_Test::TestBody
()
{
5608 boost::scoped_ptr<AllocEngine> engine;
5609 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5609
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5609
; } } else gtest_label_testnothrow_5609 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5609, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5610 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5611
5612 // Get rid of the default subnet configuration.
5613 CfgMgr& cfg_mgr = CfgMgr::instance();
5614 cfg_mgr.clear();
5615
5616 // Configure a larger subnet with a /24 pool.
5617 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
5618 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"),
5619 IOAddress("192.0.2.255")));
5620 subnet_->addPool(pool_);
5621 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5622
5623 // Set exclude-first-last to true.
5624 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5625 cfg_mgr.commit();
5626
5627 size_t cnt = 0;
5628 vector<bool> found(256, false);
5629 while (true) {
5630 vector<uint8_t> duid = clientid_->getClientId();
5631 duid[6] = cnt >> 8;
5632 duid[7] = cnt & 0xff;
5633 ClientIdPtr clientid(new ClientId(duid));
5634 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5635 hwaddr->hwaddr_[4] = cnt >> 8;
5636 hwaddr->hwaddr_[5] = cnt & 0xff;
5637 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5638 IOAddress("0.0.0.0"),
5639 false, false, "foo.bar", false);
5640 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5641 Lease4Ptr lease = engine->allocateLease4(ctx);
5642
5643 if (!lease) {
5644 break;
5645 }
5646 const vector<uint8_t>& addr = lease->addr_.toBytes();
5647 ASSERT_EQ(4U, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("4U", "addr.size()"
, 4U, addr.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5647, gtest_ar.failure_message()) = ::testing::Message()
;
5648 EXPECT_EQ(192U, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("192U", "addr[0]"
, 192U, addr[0]))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5648, gtest_ar.failure_message()) = ::testing::Message()
;
5649 EXPECT_EQ(0U, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addr[1]"
, 0U, addr[1]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5649, gtest_ar.failure_message()) = ::testing::Message()
;
5650 EXPECT_EQ(2U, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2U", "addr[2]"
, 2U, addr[2]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5650, gtest_ar.failure_message()) = ::testing::Message()
;
5651 EXPECT_FALSE(found[addr[3]])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(found[addr[3]]))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5651, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5652 found[addr[3]] = true;
5653 ++cnt;
5654 // Catch unbound loop.
5655 ASSERT_LT(cnt, 1000U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000U",
cnt, 1000U))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5655, gtest_ar.failure_message()) = ::testing::Message()
;
5656 }
5657 EXPECT_EQ(254U, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("254U", "cnt"
, 254U, cnt))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5657, gtest_ar.failure_message()) = ::testing::Message()
;
5658 vector<bool> expected(256, true);
5659 expected[0] = false;
5660 expected[255] = false;
5661 EXPECT_EQ(expected, found)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "found", expected, found))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5661, gtest_ar.failure_message()) = ::testing::Message()
;
5662}
5663
5664// This test verifies that all addresses in a subnet can be allocated when
5665// exclude-first-last is true but the prefix length is greater than 24.
5666TEST_F(AllocEngine4Test, excludeFirst25)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("excludeFirst25") > 1, "test_name must not be empty"
); class AllocEngine4Test_excludeFirst25_Test : public AllocEngine4Test
{ public: AllocEngine4Test_excludeFirst25_Test() = default; ~
AllocEngine4Test_excludeFirst25_Test() override = default; AllocEngine4Test_excludeFirst25_Test
(const AllocEngine4Test_excludeFirst25_Test &) = delete;
AllocEngine4Test_excludeFirst25_Test & operator=( const AllocEngine4Test_excludeFirst25_Test
&) = delete; AllocEngine4Test_excludeFirst25_Test (AllocEngine4Test_excludeFirst25_Test
&&) noexcept = delete; AllocEngine4Test_excludeFirst25_Test
& operator=( AllocEngine4Test_excludeFirst25_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_excludeFirst25_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "excludeFirst25", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 5666
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5666), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5666), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirst25_Test
>); void AllocEngine4Test_excludeFirst25_Test::TestBody()
{
5667 boost::scoped_ptr<AllocEngine> engine;
5668 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5668
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5668
; } } else gtest_label_testnothrow_5668 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5668, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5669 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5669, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5670
5671 // Get rid of the default subnet configuration.
5672 CfgMgr& cfg_mgr = CfgMgr::instance();
5673 cfg_mgr.clear();
5674
5675 // Configure a smaller subnet with a /25 pool.
5676 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 25, 1, 2, 3, SubnetID(10));
5677 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"),
5678 IOAddress("192.0.2.127")));
5679 subnet_->addPool(pool_);
5680 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5681
5682 // Set exclude-first-last to true.
5683 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5684 cfg_mgr.commit();
5685
5686 size_t cnt = 0;
5687 vector<bool> found(128, false);
5688 while (true) {
5689 vector<uint8_t> duid = clientid_->getClientId();
5690 duid[6] = cnt >> 8;
5691 duid[7] = cnt & 0xff;
5692 ClientIdPtr clientid(new ClientId(duid));
5693 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5694 hwaddr->hwaddr_[4] = cnt >> 8;
5695 hwaddr->hwaddr_[5] = cnt & 0xff;
5696 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5697 IOAddress("0.0.0.0"),
5698 false, false, "foo.bar", false);
5699 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5700 Lease4Ptr lease = engine->allocateLease4(ctx);
5701
5702 if (!lease) {
5703 break;
5704 }
5705 const vector<uint8_t>& addr = lease->addr_.toBytes();
5706 ASSERT_EQ(4U, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("4U", "addr.size()"
, 4U, addr.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5706, gtest_ar.failure_message()) = ::testing::Message()
;
5707 EXPECT_EQ(192U, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("192U", "addr[0]"
, 192U, addr[0]))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5707, gtest_ar.failure_message()) = ::testing::Message()
;
5708 EXPECT_EQ(0U, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addr[1]"
, 0U, addr[1]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5708, gtest_ar.failure_message()) = ::testing::Message()
;
5709 EXPECT_EQ(2U, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2U", "addr[2]"
, 2U, addr[2]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5709, gtest_ar.failure_message()) = ::testing::Message()
;
5710 ASSERT_GT(128U, addr[3])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("128U", "addr[3]"
, 128U, addr[3]))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5710, gtest_ar.failure_message()) = ::testing::Message()
;
5711 EXPECT_FALSE(found[addr[3]])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(found[addr[3]]))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5711, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5712 found[addr[3]] = true;
5713 ++cnt;
5714 // Catch unbound loop.
5715 ASSERT_LT(cnt, 1000U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000U",
cnt, 1000U))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5715, gtest_ar.failure_message()) = ::testing::Message()
;
5716 }
5717 EXPECT_EQ(128U, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("128U", "cnt"
, 128U, cnt))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5717, gtest_ar.failure_message()) = ::testing::Message()
;
5718 EXPECT_EQ(found, vector<bool>(128, true))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("found", "vector<bool>(128, true)"
, found, vector<bool>(128, true)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5718, gtest_ar.failure_message()) = ::testing::Message()
;
5719}
5720
5721// This test verifies that all addresses in a subnet can be allocated when
5722// exclude-first-last is true but the prefix length is greater than 24.
5723TEST_F(AllocEngine4Test, excludeLast25)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("excludeLast25") > 1, "test_name must not be empty"
); class AllocEngine4Test_excludeLast25_Test : public AllocEngine4Test
{ public: AllocEngine4Test_excludeLast25_Test() = default; ~
AllocEngine4Test_excludeLast25_Test() override = default; AllocEngine4Test_excludeLast25_Test
(const AllocEngine4Test_excludeLast25_Test &) = delete; AllocEngine4Test_excludeLast25_Test
& operator=( const AllocEngine4Test_excludeLast25_Test &
) = delete; AllocEngine4Test_excludeLast25_Test (AllocEngine4Test_excludeLast25_Test
&&) noexcept = delete; AllocEngine4Test_excludeLast25_Test
& operator=( AllocEngine4Test_excludeLast25_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_excludeLast25_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "excludeLast25", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 5723
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5723), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5723), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeLast25_Test
>); void AllocEngine4Test_excludeLast25_Test::TestBody()
{
5724 boost::scoped_ptr<AllocEngine> engine;
5725 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5725
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5725
; } } else gtest_label_testnothrow_5725 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5725, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5726 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5727
5728 // Get rid of the default subnet configuration.
5729 CfgMgr& cfg_mgr = CfgMgr::instance();
5730 cfg_mgr.clear();
5731
5732 // Configure a smaller subnet with a /25 pool.
5733 subnet_ = Subnet4::create(IOAddress("192.0.2.128"), 25, 1, 2, 3, SubnetID(10));
5734 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.128"),
5735 IOAddress("192.0.2.255")));
5736 subnet_->addPool(pool_);
5737 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5738
5739 // Set exclude-first-last to true.
5740 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5741 cfg_mgr.commit();
5742
5743 size_t cnt = 0;
5744 vector<bool> found(128, false);
5745 while (true) {
5746 vector<uint8_t> duid = clientid_->getClientId();
5747 duid[6] = cnt >> 8;
5748 duid[7] = cnt & 0xff;
5749 ClientIdPtr clientid(new ClientId(duid));
5750 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5751 hwaddr->hwaddr_[4] = cnt >> 8;
5752 hwaddr->hwaddr_[5] = cnt & 0xff;
5753 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5754 IOAddress("0.0.0.0"),
5755 false, false, "foo.bar", false);
5756 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5757 Lease4Ptr lease = engine->allocateLease4(ctx);
5758
5759 if (!lease) {
5760 break;
5761 }
5762 const vector<uint8_t>& addr = lease->addr_.toBytes();
5763 ASSERT_EQ(4U, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("4U", "addr.size()"
, 4U, addr.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5763, gtest_ar.failure_message()) = ::testing::Message()
;
5764 EXPECT_EQ(192U, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("192U", "addr[0]"
, 192U, addr[0]))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5764, gtest_ar.failure_message()) = ::testing::Message()
;
5765 EXPECT_EQ(0U, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addr[1]"
, 0U, addr[1]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5765, gtest_ar.failure_message()) = ::testing::Message()
;
5766 EXPECT_EQ(2U, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2U", "addr[2]"
, 2U, addr[2]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5766, gtest_ar.failure_message()) = ::testing::Message()
;
5767 ASSERT_LE(128U, addr[3])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("128U", "addr[3]"
, 128U, addr[3]))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5767, gtest_ar.failure_message()) = ::testing::Message()
;
5768 EXPECT_FALSE(found[addr[3] - 128])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(found[addr[3] - 128
]))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3] - 128]", "true", "false") .c_str()) = ::testing
::Message()
;
5769 found[addr[3] - 128] = true;
5770 ++cnt;
5771 // Catch unbound loop.
5772 ASSERT_LT(cnt, 1000U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000U",
cnt, 1000U))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5772, gtest_ar.failure_message()) = ::testing::Message()
;
5773 }
5774 EXPECT_EQ(128U, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("128U", "cnt"
, 128U, cnt))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5774, gtest_ar.failure_message()) = ::testing::Message()
;
5775 EXPECT_EQ(found, vector<bool>(128, true))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("found", "vector<bool>(128, true)"
, found, vector<bool>(128, true)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5775, gtest_ar.failure_message()) = ::testing::Message()
;
5776}
5777
5778// This test verifies that an excluded address can be allocated when requested
5779// and exclude-first-last is true.
5780TEST_F(AllocEngine4Test, excludeFirstLastRequested)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("excludeFirstLastRequested") > 1, "test_name must not be empty"
); class AllocEngine4Test_excludeFirstLastRequested_Test : public
AllocEngine4Test { public: AllocEngine4Test_excludeFirstLastRequested_Test
() = default; ~AllocEngine4Test_excludeFirstLastRequested_Test
() override = default; AllocEngine4Test_excludeFirstLastRequested_Test
(const AllocEngine4Test_excludeFirstLastRequested_Test &
) = delete; AllocEngine4Test_excludeFirstLastRequested_Test &
operator=( const AllocEngine4Test_excludeFirstLastRequested_Test
&) = delete; AllocEngine4Test_excludeFirstLastRequested_Test
(AllocEngine4Test_excludeFirstLastRequested_Test &&)
noexcept = delete; AllocEngine4Test_excludeFirstLastRequested_Test
& operator=( AllocEngine4Test_excludeFirstLastRequested_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLastRequested_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "excludeFirstLastRequested", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5780), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5780), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5780), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastRequested_Test
>); void AllocEngine4Test_excludeFirstLastRequested_Test::
TestBody()
{
5781 boost::scoped_ptr<AllocEngine> engine;
5782 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5782
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5782
; } } else gtest_label_testnothrow_5782 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5782, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5783 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5783, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5784
5785 // Get rid of the default subnet configuration.
5786 CfgMgr& cfg_mgr = CfgMgr::instance();
5787 cfg_mgr.clear();
5788
5789 // Configure a larger subnet with a /24 pool.
5790 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5791 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5792 subnet_->addPool(pool_);
5793 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5794
5795 // Set exclude-first-last to true.
5796 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5797 cfg_mgr.commit();
5798
5799 // Request the first address.
5800 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
5801 IOAddress("10.0.1.0"),
5802 false, false, "foo.bar", false);
5803 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
5804 Lease4Ptr lease = engine->allocateLease4(ctx);
5805 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5805, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5806 EXPECT_EQ("10.0.1.0", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.0.1.0\""
, "lease->addr_.toText()", "10.0.1.0", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5806, gtest_ar.failure_message()) = ::testing::Message()
;
5807
5808 // Request the last address.
5809 AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_,
5810 IOAddress("10.0.1.255"),
5811 false, false, "bar.foo", false);
5812 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345));
5813 lease = engine->allocateLease4(ctx2);
5814 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5814, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5815 EXPECT_EQ("10.0.1.255", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.0.1.255\""
, "lease->addr_.toText()", "10.0.1.255", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5815, gtest_ar.failure_message()) = ::testing::Message()
;
5816}
5817
5818// This test verifies that an excluded address can be allocated when reserved
5819// and exclude-first-last is true.
5820TEST_F(AllocEngine4Test, excludeFirstLastReserver)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("excludeFirstLastReserver") > 1, "test_name must not be empty"
); class AllocEngine4Test_excludeFirstLastReserver_Test : public
AllocEngine4Test { public: AllocEngine4Test_excludeFirstLastReserver_Test
() = default; ~AllocEngine4Test_excludeFirstLastReserver_Test
() override = default; AllocEngine4Test_excludeFirstLastReserver_Test
(const AllocEngine4Test_excludeFirstLastReserver_Test &)
= delete; AllocEngine4Test_excludeFirstLastReserver_Test &
operator=( const AllocEngine4Test_excludeFirstLastReserver_Test
&) = delete; AllocEngine4Test_excludeFirstLastReserver_Test
(AllocEngine4Test_excludeFirstLastReserver_Test &&) noexcept
= delete; AllocEngine4Test_excludeFirstLastReserver_Test &
operator=( AllocEngine4Test_excludeFirstLastReserver_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_excludeFirstLastReserver_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "excludeFirstLastReserver", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5820), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5820), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5820), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastReserver_Test
>); void AllocEngine4Test_excludeFirstLastReserver_Test::TestBody
()
{
5821 boost::scoped_ptr<AllocEngine> engine;
5822 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5822
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5822
; } } else gtest_label_testnothrow_5822 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5822, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5823 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5823, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5824
5825 // Get rid of the default subnet configuration.
5826 CfgMgr& cfg_mgr = CfgMgr::instance();
5827 cfg_mgr.clear();
5828
5829 // Configure a larger subnet with a /24 pool.
5830 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5831 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5832 subnet_->addPool(pool_);
5833 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5834
5835 // Set exclude-first-last to true.
5836 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5837
5838 // Add reservations.
5839 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
5840 Host::IDENT_HWADDR, subnet_->getID(),
5841 SUBNET_ID_UNUSED, IOAddress("10.0.1.0")));
5842 cfg_mgr.getStagingCfg()->getCfgHosts()->add(host);
5843 HostPtr host2(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(),
5844 Host::IDENT_HWADDR, subnet_->getID(),
5845 SUBNET_ID_UNUSED, IOAddress("10.0.1.255")));
5846 cfg_mgr.getStagingCfg()->getCfgHosts()->add(host2);
5847 subnet_->setReservationsInSubnet(true);
5848 subnet_->setReservationsOutOfPool(false);
5849 cfg_mgr.commit();
5850
5851 // Request the first address.
5852 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
5853 IOAddress("0.0.0.0"),
5854 false, false, "foo.bar", false);
5855 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
5856 AllocEngine::findReservation(ctx);
5857 Lease4Ptr lease = engine->allocateLease4(ctx);
5858 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5858, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5859 EXPECT_EQ("10.0.1.0", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.0.1.0\""
, "lease->addr_.toText()", "10.0.1.0", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5859, gtest_ar.failure_message()) = ::testing::Message()
;
5860
5861 // Request the last address.
5862 AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_,
5863 IOAddress("0.0.0.0"),
5864 false, false, "bar.foo", false);
5865 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345));
5866 AllocEngine::findReservation(ctx2);
5867 lease = engine->allocateLease4(ctx2);
5868 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5868, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5869 EXPECT_EQ("10.0.1.255", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.0.1.255\""
, "lease->addr_.toText()", "10.0.1.255", lease->addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5869, gtest_ar.failure_message()) = ::testing::Message()
;
5870}
5871
5872// Verifies that offer_lft is non-zero, that an offered lease is stored
5873// in the lease database.
5874TEST_F(AllocEngine4Test, discoverOfferLft)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverOfferLft") > 1, "test_name must not be empty"
); class AllocEngine4Test_discoverOfferLft_Test : public AllocEngine4Test
{ public: AllocEngine4Test_discoverOfferLft_Test() = default
; ~AllocEngine4Test_discoverOfferLft_Test() override = default
; AllocEngine4Test_discoverOfferLft_Test (const AllocEngine4Test_discoverOfferLft_Test
&) = delete; AllocEngine4Test_discoverOfferLft_Test &
operator=( const AllocEngine4Test_discoverOfferLft_Test &
) = delete; AllocEngine4Test_discoverOfferLft_Test (AllocEngine4Test_discoverOfferLft_Test
&&) noexcept = delete; AllocEngine4Test_discoverOfferLft_Test
& operator=( AllocEngine4Test_discoverOfferLft_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_discoverOfferLft_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverOfferLft", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5874), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5874), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5874), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLft_Test
>); void AllocEngine4Test_discoverOfferLft_Test::TestBody(
)
{
5875 boost::scoped_ptr<AllocEngine> engine;
5876 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5876
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5876
; } } else gtest_label_testnothrow_5876 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5876, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5877 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5877, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5878
5879 IOAddress addr("192.0.2.15");
5880 CfgMgr& cfg_mgr = CfgMgr::instance();
5881 // Get rid of the default test configuration.
5882 cfg_mgr.clear();
5883
5884 // Create configuration similar to other tests, but with a single address pool
5885 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
5886 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
5887 subnet_->addPool(pool_);
5888
5889 // Set subnet's offer-lifetime to a non-zero, positive value.
5890 uint32_t offer_lft = (subnet_->getValid() / 3);
5891 subnet_->setOfferLft(offer_lft);
5892 ASSERT_EQ(offer_lft, subnet_->getOfferLft().get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("offer_lft"
, "subnet_->getOfferLft().get()", offer_lft, subnet_->getOfferLft
().get()))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5892, gtest_ar.failure_message()) = ::testing::Message()
;
5893
5894 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5895
5896 // Ask for any address
5897 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
5898 IOAddress("0.0.0.0"), true, true,
5899 "one", true);
5900 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5901
5902 // Check that we got that single lease
5903 Lease4Ptr lease = engine->allocateLease4(ctx1);
5904 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5904, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5905 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5905, gtest_ar.failure_message()) = ::testing::Message()
;
5906 EXPECT_EQ(offer_lft, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("offer_lft"
, "lease->valid_lft_", offer_lft, lease->valid_lft_))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5906, gtest_ar.failure_message()) = ::testing::Message()
;
5907 EXPECT_FALSE(lease->fqdn_fwd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->fqdn_fwd_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5907, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
5908 EXPECT_FALSE(lease->fqdn_rev_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->fqdn_rev_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5908, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
5909
5910 // Check that the lease has been stored by LeaseMgr.
5911 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5912 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5912, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5913 EXPECT_EQ(offer_lft, from_mgr->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("offer_lft"
, "from_mgr->valid_lft_", offer_lft, from_mgr->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5913, gtest_ar.failure_message()) = ::testing::Message()
;
5914 EXPECT_FALSE(from_mgr->fqdn_fwd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr->fqdn_fwd_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5914, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
5915 EXPECT_FALSE(from_mgr->fqdn_rev_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr->fqdn_rev_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5915, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
5916
5917 // Try to discover an address for a second client.
5918 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
5919 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
5920
5921 // Ask for any address.
5922 AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2,
5923 IOAddress("0.0.0.0"), true, true,
5924 "two", true);
5925 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1235));
5926
5927 // Verify that we did not get a lease.
5928 lease = engine->allocateLease4(ctx2);
5929 ASSERT_FALSE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
5930
5931 // Original client now does a DHCPREQUEST. Make sure we get the
5932 // previously offered lease with the proper valid lifetime.
5933 AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_,
5934 IOAddress("0.0.0.0"), true, true,
5935 "one", false);
5936 ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1236));
5937
5938 lease = engine->allocateLease4(ctx3);
5939 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5939, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5940 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5940, gtest_ar.failure_message()) = ::testing::Message()
;
5941 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5942 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5942, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5943 EXPECT_EQ(subnet_->getValid(), from_mgr->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid()"
, "from_mgr->valid_lft_", subnet_->getValid(), from_mgr
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5943, gtest_ar.failure_message()) = ::testing::Message()
;
5944}
5945
5946// Verifies that when offer_lft is non-zero, that an existing lease is
5947// whose remaining life is larger than offer_lft, is offered as is.
5948TEST_F(AllocEngine4Test, discoverOfferLftUseExistingLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverOfferLftUseExistingLease4") >
1, "test_name must not be empty"); class AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
: public AllocEngine4Test { public: AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
() = default; ~AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
() override = default; AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
(const AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
&) = delete; AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
& operator=( const AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
&) = delete; AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
(AllocEngine4Test_discoverOfferLftUseExistingLease4_Test &&
) noexcept = delete; AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
& operator=( AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverOfferLftUseExistingLease4", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5948), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5948), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5948), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
>); void AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
::TestBody()
{
5949 boost::scoped_ptr<AllocEngine> engine;
5950 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5950
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5950
; } } else gtest_label_testnothrow_5950 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5950, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5951 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5951, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5952
5953 IOAddress addr("192.0.2.15");
5954 CfgMgr& cfg_mgr = CfgMgr::instance();
5955 // Get rid of the default test configuration.
5956 cfg_mgr.clear();
5957
5958 // Create configuration similar to other tests, but with a single address pool
5959 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 300, SubnetID(10));
5960 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
5961 subnet_->addPool(pool_);
5962
5963 // Set subnet's offer-lifetime to a non-zero, positive value.
5964 uint32_t offer_lft = 100;
5965 subnet_->setOfferLft(offer_lft);
5966 ASSERT_EQ(offer_lft, subnet_->getOfferLft().get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("offer_lft"
, "subnet_->getOfferLft().get()", offer_lft, subnet_->getOfferLft
().get()))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5966, gtest_ar.failure_message()) = ::testing::Message()
;
5967
5968 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5969
5970 time_t now = time(NULL__null) - 5; // Allocated 5 seconds ago
5971 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, 300, now,
5972 subnet_->getID(), true, true, "somehost"));
5973
5974 // Copy the lease, so as it can be compared with the old lease returned
5975 // by the allocation engine.
5976 Lease4 original_lease(*lease);
5977
5978 // Lease was assigned 5 seconds ago, its valid lifetime is 300, its
5979 // remaining lifetime is still larger than offer_lft.
5980 ASSERT_FALSE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->expired()
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5980, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
5981 ASSERT_EQ(300U, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("300U", "lease->valid_lft_"
, 300U, lease->valid_lft_))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5981, gtest_ar.failure_message()) = ::testing::Message()
;
5982 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5982, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
5983
5984 // CASE 1: Asking for any address
5985 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
5986 IOAddress("0.0.0.0"), false, false,
5987 "", true);
5988 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5989 lease = engine->allocateLease4(ctx1);
5990 // Check that we got that single lease
5991 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5991, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5992 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5992, gtest_ar.failure_message()) = ::testing::Message()
;
5993 EXPECT_EQ(300U, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("300U", "lease->valid_lft_"
, 300U, lease->valid_lft_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5993, gtest_ar.failure_message()) = ::testing::Message()
;
5994
5995 // We are reusing the existing lease, the old instance should be
5996 // returned. The returned instance should be the same as the original
5997 // lease.
5998 ASSERT_TRUE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx1.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5998, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
5999 EXPECT_TRUE(original_lease == *ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(original_lease == *ctx1
.old_lease_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5999, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *ctx1.old_lease_", "false", "true") .c_str
()) = ::testing::Message()
;
6000
6001 // Check that the lease has not been modified by LeaseMgr.
6002 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
6003 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6003, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
6004 EXPECT_TRUE(original_lease == *from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(original_lease == *from_mgr
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6004, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *from_mgr", "false", "true") .c_str()) =
::testing::Message()
;
6005}
6006
6007// Verifies that when offer_lft is non-zero, that an expired lease can
6008// be reclaimed an offered correctly.
6009TEST_F(AllocEngine4Test, discoverOfferLftReuseExpiredLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverOfferLftReuseExpiredLease4")
> 1, "test_name must not be empty"); class AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
: public AllocEngine4Test { public: AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
() = default; ~AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
() override = default; AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
(const AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
&) = delete; AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
& operator=( const AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
&) = delete; AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
(AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test &&
) noexcept = delete; AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
& operator=( AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "discoverOfferLftReuseExpiredLease4", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6009), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6009), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6009), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
>); void AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
::TestBody()
{
6010 boost::scoped_ptr<AllocEngine> engine;
6011 ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
engine.reset(new AllocEngine(0)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6011
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6011
; } } else gtest_label_testnothrow_6011 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6011, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
6012 ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(engine)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6012, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
6013
6014 IOAddress addr("192.0.2.15");
6015 CfgMgr& cfg_mgr = CfgMgr::instance();
6016 // Get rid of the default test configuration.
6017 cfg_mgr.clear();
6018
6019 // Create configuration similar to other tests, but with a single address pool
6020 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
6021 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
6022 subnet_->addPool(pool_);
6023
6024 // Set subnet's offer-lifetime to a non-zero, positive value.
6025 uint32_t offer_lft = (subnet_->getValid() / 3);
6026 subnet_->setOfferLft(offer_lft);
6027 ASSERT_EQ(offer_lft, subnet_->getOfferLft().get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("offer_lft"
, "subnet_->getOfferLft().get()", offer_lft, subnet_->getOfferLft
().get()))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6027, gtest_ar.failure_message()) = ::testing::Message()
;
6028
6029 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
6030
6031 // Just a different hw/client-id for the second client
6032 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
6033 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
6034 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
6035 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
6036 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
6037 495, now, subnet_->getID()));
6038 // Copy the lease, so as it can be compared with the old lease returned
6039 // by the allocation engine.
6040 Lease4 original_lease(*lease);
6041
6042 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
6043 // is expired already
6044 ASSERT_TRUE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease->expired()))
; else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6044, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
6045 ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().addLease(lease))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6045, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
6046
6047 // CASE 1: Asking for any address
6048 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
6049 IOAddress("0.0.0.0"), false, false,
6050 "", true);
6051 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
6052 lease = engine->allocateLease4(ctx1);
6053 // Check that we got that single lease
6054 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6054, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
6055 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6055, gtest_ar.failure_message()) = ::testing::Message()
;
6056 EXPECT_EQ(offer_lft, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("offer_lft"
, "lease->valid_lft_", offer_lft, lease->valid_lft_))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6056, gtest_ar.failure_message()) = ::testing::Message()
;
6057 EXPECT_FALSE(lease->fqdn_fwd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->fqdn_fwd_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6057, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
6058 EXPECT_FALSE(lease->fqdn_rev_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(lease->fqdn_rev_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6058, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
6059
6060 // We are reusing expired lease, the old (expired) instance should be
6061 // returned. The returned instance should be the same as the original
6062 // lease.
6063 ASSERT_TRUE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ctx1.old_lease_)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6063, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
6064 EXPECT_TRUE(original_lease == *ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(original_lease == *ctx1
.old_lease_)) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *ctx1.old_lease_", "false", "true") .c_str
()) = ::testing::Message()
;
6065
6066 // Check that the lease has been stored by LeaseMgr.
6067 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
6068 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6068, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
6069 EXPECT_EQ(offer_lft, from_mgr->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("offer_lft"
, "from_mgr->valid_lft_", offer_lft, from_mgr->valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6069, gtest_ar.failure_message()) = ::testing::Message()
;
6070 EXPECT_FALSE(from_mgr->fqdn_fwd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr->fqdn_fwd_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6070, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
6071 EXPECT_FALSE(from_mgr->fqdn_rev_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr->fqdn_rev_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6071, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
6072
6073 // Client now does a DHCPREQUEST. Make sure we get the
6074 // previously offered lease with the proper valid lifetime.
6075 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
6076 IOAddress("0.0.0.0"), true, true,
6077 "one", false);
6078 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1235));
6079
6080 lease = engine->allocateLease4(ctx2);
6081 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6081, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
6082 EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_"
, addr, lease->addr_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6082, gtest_ar.failure_message()) = ::testing::Message()
;
6083 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
6084 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6084, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
6085 EXPECT_EQ(subnet_->getValid(), from_mgr->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid()"
, "from_mgr->valid_lft_", subnet_->getValid(), from_mgr
->valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6085, gtest_ar.failure_message()) = ::testing::Message()
;
6086}
6087
6088// Verifies that AllocEngine::getOfferLft(ctx4) returns the appropriate
6089// lifetime value based on the context content.
6090TEST_F(AllocEngine4Test, getOfferLft4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getOfferLft4") > 1, "test_name must not be empty"
); class AllocEngine4Test_getOfferLft4_Test : public AllocEngine4Test
{ public: AllocEngine4Test_getOfferLft4_Test() = default; ~AllocEngine4Test_getOfferLft4_Test
() override = default; AllocEngine4Test_getOfferLft4_Test (const
AllocEngine4Test_getOfferLft4_Test &) = delete; AllocEngine4Test_getOfferLft4_Test
& operator=( const AllocEngine4Test_getOfferLft4_Test &
) = delete; AllocEngine4Test_getOfferLft4_Test (AllocEngine4Test_getOfferLft4_Test
&&) noexcept = delete; AllocEngine4Test_getOfferLft4_Test
& operator=( AllocEngine4Test_getOfferLft4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const AllocEngine4Test_getOfferLft4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test"
, "getOfferLft4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 6090
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6090), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6090), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getOfferLft4_Test
>); void AllocEngine4Test_getOfferLft4_Test::TestBody()
{
6091 AllocEngine engine(0);
6092
6093 // Let's make three classes, two with offer-lifetime and one without,
6094 // and add them to the dictionary.
6095 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
6096
6097 ClientClassDefPtr class_def(new ClientClassDef("offer_lft_one", ExpressionPtr()));
6098 Optional<uint32_t> offer_lft_one(100);
6099 class_def->setOfferLft(offer_lft_one);
6100 dictionary->addClass(class_def);
6101
6102 class_def.reset(new ClientClassDef("offer_lft_two", ExpressionPtr()));
6103 Optional<uint32_t>offer_lft_two(200);
6104 class_def->setOfferLft(offer_lft_two);
6105 dictionary->addClass(class_def);
6106
6107 class_def.reset(new ClientClassDef("offer_lft_zero", ExpressionPtr()));
6108 Optional<uint32_t>offer_lft_zero(0);
6109 class_def->setOfferLft(offer_lft_zero);
6110 dictionary->addClass(class_def);
6111
6112 class_def.reset(new ClientClassDef("offer_lft_unspec", ExpressionPtr()));
6113 dictionary->addClass(class_def);
6114
6115 // Commit our class changes.
6116 CfgMgr::instance().commit();
6117
6118 // Update the subnet's triplet to something more useful.
6119 subnet_->setOfferLft(Optional<uint32_t>(300));
6120
6121 // Describes a test scenario.
6122 struct Scenario {
6123 std::string desc_; // descriptive text for logging
6124 std::vector<std::string> classes_; // class list of assigned classes
6125 uint32_t exp_valid_lft_; // expected lease lifetime
6126 bool exp_allocate_; // true if lease should be allocated
6127 };
6128
6129 bool exp_allocate = true;
6130
6131 // Scenarios to test.
6132 std::vector<Scenario> scenarios = {
6133 {
6134 "BOOTP",
6135 { "BOOTP" },
6136 Lease::INFINITY_LFT,
6137 !exp_allocate,
6138 },
6139 {
6140 "no classes",
6141 {},
6142 subnet_->getOfferLft(),
6143 exp_allocate
6144 },
6145 {
6146 "class unspecified",
6147 { "offer_lft_unspec" },
6148 subnet_->getOfferLft(),
6149 exp_allocate
6150 },
6151 {
6152 "from last class",
6153 { "offer_lft_unspec", "offer_lft_one" },
6154 offer_lft_one.get(),
6155 exp_allocate
6156 },
6157 {
6158 "from first class",
6159 { "offer_lft_two", "offer_lft_one" },
6160 offer_lft_two.get(),
6161 exp_allocate
6162 },
6163 {
6164 // Using class value of zero should override non-zero set at
6165 // subnet level, lease should have actual valid lft
6166 "zero from class",
6167 { "offer_lft_zero" },
6168 subnet_->getValid(),
6169 !exp_allocate
6170 }
6171 };
6172
6173 // Iterate over the scenarios and verify the correct outcome.
6174 for (auto const& scenario : scenarios) {
6175 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_6175( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6175, (scenario.desc_))
; {
6176 // Create a context;
6177 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
6178 IOAddress("0.0.0.0"), false, false,
6179 "", true);
6180 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
6181
6182 // Add client classes (if any)
6183 for (auto const& class_name : scenario.classes_) {
6184 ctx.query_->addClass(class_name);
6185 }
6186
6187 Lease4Ptr lease = engine.allocateLease4(ctx);
6188 ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(lease)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6188, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
6189 EXPECT_EQ(lease->valid_lft_, scenario.exp_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("lease->valid_lft_"
, "scenario.exp_valid_lft_", lease->valid_lft_, scenario.exp_valid_lft_
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6189, gtest_ar.failure_message()) = ::testing::Message()
;
6190
6191 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
6192 if (!scenario.exp_allocate_) {
6193 ASSERT_FALSE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(from_mgr))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "true", "false") .c_str()) = ::testing::Message
()
;
6194 } else {
6195 ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6195, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
6196 EXPECT_EQ(from_mgr->valid_lft_, scenario.exp_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("from_mgr->valid_lft_"
, "scenario.exp_valid_lft_", from_mgr->valid_lft_, scenario
.exp_valid_lft_))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6196, gtest_ar.failure_message()) = ::testing::Message()
;
6197 ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(from_mgr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance
().deleteLease(from_mgr))) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6197, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(from_mgr)", "false"
, "true") .c_str()) = ::testing::Message()
;
6198 }
6199 }
6200 }
6201}
6202
6203TEST_F(SharedNetworkAlloc4Test, discoverGlobalResVsSubnetRes)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("discoverGlobalResVsSubnetRes") > 1
, "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
() = default; ~SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
() override = default; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
(const SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
&) = delete; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
& operator=( const SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
&) = delete; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
(SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test &&
) noexcept = delete; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
& operator=( SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "discoverGlobalResVsSubnetRes", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6203), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6203), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6203), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
>); void SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test
::TestBody()
{
6204 // global_host with address in subnet1, subnet_host with no address in subnet2
6205 globalResVsSubnetRes(true, IOAddress("192.0.2.100"),
6206 true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(),
6207 SubnetID(20), IOAddress("10.1.2.5"));
6208
6209 // global_host with address in subnet1, subnet_host with address in subnet2
6210 globalResVsSubnetRes(true, IOAddress("192.0.2.100"),
6211 true, SubnetID(20), IOAddress("10.1.2.200"),
6212 SubnetID(20), IOAddress("10.1.2.200"));
6213
6214 // global_host with address in subnet2, subnet_host with no address in subnet2
6215 globalResVsSubnetRes(true, IOAddress("10.1.2.1"),
6216 true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(),
6217 SubnetID(20), IOAddress("10.1.2.6"));
6218
6219 // global_host with address in subnet2, subnet_host with address in subnet2
6220 globalResVsSubnetRes(true, IOAddress("10.1.2.1"),
6221 true, SubnetID(20), IOAddress("10.1.2.200"),
6222 SubnetID(20), IOAddress("10.1.2.200"));
6223}
6224
6225TEST_F(SharedNetworkAlloc4Test, requestGlobalResVsSubnetRes)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("requestGlobalResVsSubnetRes") > 1
, "test_name must not be empty"); class SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
: public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
() = default; ~SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
() override = default; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
(const SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
&) = delete; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
& operator=( const SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
&) = delete; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
(SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test &&
) noexcept = delete; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
& operator=( SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test"
, "requestGlobalResVsSubnetRes", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6225), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6225), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6225), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
>); void SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test
::TestBody()
{
6226 // global_host with address in subnet1, subnet_host with no address in subnet2
6227 globalResVsSubnetRes(true, IOAddress("192.0.2.100"),
6228 true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(),
6229 SubnetID(20), IOAddress("10.1.2.5"), false);
6230
6231 // global_host with address in subnet1, subnet_host with address in subnet2
6232 globalResVsSubnetRes(true, IOAddress("192.0.2.100"),
6233 true, SubnetID(20), IOAddress("10.1.2.200"),
6234 SubnetID(20), IOAddress("10.1.2.200"), false);
6235
6236 // global_host with address in subnet2, subnet_host with no address in subnet2
6237 globalResVsSubnetRes(true, IOAddress("10.1.2.1"),
6238 true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(),
6239 SubnetID(20), IOAddress("10.1.2.6"), false);
6240
6241 // global_host with address in subnet2, subnet_host with address in subnet2
6242 globalResVsSubnetRes(true, IOAddress("10.1.2.1"),
6243 true, SubnetID(20), IOAddress("10.1.2.200"),
6244 SubnetID(20), IOAddress("10.1.2.200"), false);
6245}
6246
6247} // namespace test
6248} // namespace dhcp
6249} // namespace isc