Bug Summary

File:home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpz0p224zs/../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
Warning:line 4175, 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/tmpz0p224zs -fcoverage-compilation-dir=/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpz0p224zs -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/tmpz0p224zs/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/tmpz0p224zs/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-06-18-163926-5114-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 /// Convenience pointers to configuration elements. These are initialized
986 /// in the constructor and are used throughout the tests.
987 AllocEngine engine_;
988 Subnet4Ptr subnet1_;
989 Subnet4Ptr subnet2_;
990 Pool4Ptr pool1_;
991 Pool4Ptr pool2_;
992 SharedNetwork4Ptr network_;
993
994 HWAddrPtr hwaddr2_; // Note there's hwaddr_ already defined in base class.
995};
996
997// This test verifies that the server can offer an address from a
998// subnet and the introduction of shared network doesn't break anything here.
999TEST_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"
, 999), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 999), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 999), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test
::TestBody()
{
1000
1001 // Create context which will be used to try to allocate leases from the
1002 // shared network. The context points to subnet1, which address space
1003 // is exhausted. We expect the allocation engine to find another subnet
1004 // within the same shared network and offer an address from there.
1005 AllocEngine::ClientContext4
1006 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1007 false, false, "host.example.com.", true);
1008 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1009 Lease4Ptr lease = engine_.allocateLease4(ctx);
1010
1011 // The allocation engine should have assigned an address from the first
1012 // subnet.
1013 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"
, 1013, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1014 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"
, 1014, gtest_ar.failure_message()) = ::testing::Message()
;
1015
1016 // Make sure the lease is not in the lease mgr (this is only
1017 // discover).
1018 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"
, 1018, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
1019}
1020
1021// This test verifies that the server will pick a second subnet out of two
1022// shared subnets if there is a hint for the second subnet.
1023TEST_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"
, 1023), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1023), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1023), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test
::TestBody()
{
1024
1025 // Create context which will be used to try to allocate leases from the
1026 // shared network. The context points to subnet1, which address space
1027 // is exhausted. We expect the allocation engine to find another subnet
1028 // within the same shared network and offer an address from there.
1029
1030 AllocEngine::ClientContext4
1031 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress("10.1.2.25"),
1032 false, false, "host.example.com.", true);
1033 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1034 Lease4Ptr lease = engine_.allocateLease4(ctx);
1035
1036 // The allocation engine should have assigned an address from the second
1037 // subnet, because that's what the hint requested.
1038 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"
, 1038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1039 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"
, 1039, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1040}
1041
1042// This test verifies that the server can offer an address from a
1043// different subnet than orginally selected, when the address pool in
1044// the first subnet is exhausted.
1045TEST_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"
, 1045), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1045), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1045), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetwork_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetwork_Test
::TestBody()
{
1046 // Create a lease for a single address in the first address pool. The
1047 // pool is now exhausted.
1048 Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID());
1049
1050 // Create context which will be used to try to allocate leases from the
1051 // shared network. The context points to subnet1, which address space
1052 // is exhausted. We expect the allocation engine to find another subnet
1053 // within the same shared network and offer an address from there.
1054 AllocEngine::ClientContext4
1055 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1056 false, false, "host.example.com.", true);
1057 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1058 Lease4Ptr lease2 = engine_.allocateLease4(ctx);
1059 // The allocation engine should have assigned an address from the second
1060 // subnet. We could guess that this is 10.1.2.5, being the first address
1061 // in the address pool, but to make the test more generic, we merely
1062 // verify that the address is in the given address pool.
1063 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"
, 1063, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1064 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"
, 1064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1065
1066 // The client should also be offered a lease when it specifies a hint
1067 // that doesn't match the subnet from which the lease is offered. The
1068 // engine should check alternative subnets to match the hint to
1069 // a subnet. The requested lease is available, so it should be offered.
1070 ctx.subnet_ = subnet1_;
1071 ctx.requested_address_ = IOAddress("10.1.2.25");
1072 lease2 = engine_.allocateLease4(ctx);
1073 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"
, 1073, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1074 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"
, 1074, gtest_ar.failure_message()) = ::testing::Message()
;
1075
1076 // The returning client (the one that has a lease) should also be able
1077 // to renew its lease regardless of a subnet it begins with. So, it has
1078 // an address assigned from subnet1, but we use subnet2 as a selected
1079 // subnet.
1080 AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_,
1081 IOAddress("0.0.0.0"), false, false,
1082 "host.example.com.", true);
1083 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1084 lease2 = engine_.allocateLease4(ctx2);
1085 // The existing lease should be returned.
1086 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"
, 1086, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1087 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"
, 1087, gtest_ar.failure_message()) = ::testing::Message()
;
1088}
1089
1090// This test verifies that the server can offer an address from a
1091// different subnet than orginally selected, when the address pool in
1092// the first subnet is exhausted.
1093TEST_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"
, 1093), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1093), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1093), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test
::TestBody()
{
1094
1095 // Try to offer address from subnet1. There is one address available
1096 // so it should be offered.
1097 AllocEngine::ClientContext4
1098 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1099 false, false, "host.example.com.", true);
1100 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1101 Lease4Ptr lease = engine_.allocateLease4(ctx);
1102 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"
, 1102, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1103 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"
, 1103, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1104
1105 // Apply restrictions on the subnet1. This should be only assigned
1106 // to clients belonging to cable-modem class.
1107 subnet1_->allowClientClass("cable-modem");
1108
1109 // The allocation engine should determine that the subnet1 is not
1110 // available for the client not belonging to the cable-modem class.
1111 // Instead, it should offer an address from subnet2 that belongs
1112 // to the same shared network.
1113 ctx.subnet_ = subnet1_;
1114 lease = engine_.allocateLease4(ctx);
1115 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"
, 1115, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1116 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"
, 1116, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1117
1118 // Create reservation for the client in subnet1. Because this subnet is
1119 // not allowed for the client the client should still be offered a
1120 // lease from subnet2.
1121 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1122 Host::IDENT_HWADDR, subnet1_->getID(),
1123 SUBNET_ID_UNUSED, IOAddress("192.0.2.17")));
1124 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1125 CfgMgr::instance().commit();
1126 AllocEngine::findReservation(ctx);
1127
1128 ctx.subnet_ = subnet1_;
1129 lease = engine_.allocateLease4(ctx);
1130 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"
, 1130, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1131 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"
, 1131, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1132
1133 // Assign cable-modem class and try again. This time, we should
1134 // offer an address from the subnet1.
1135 ctx.query_->addClass(ClientClass("cable-modem"));
1136
1137 ctx.subnet_ = subnet1_;
1138 lease = engine_.allocateLease4(ctx);
1139 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"
, 1139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1140 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"
, 1140, gtest_ar.failure_message()) = ::testing::Message()
;
1141}
1142
1143// This test verifies that the server can offer an address from a
1144// different subnet than orginally selected, when the address pool in
1145// the first subnet requires another class.
1146TEST_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"
, 1146), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1146), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1146), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test
::TestBody()
{
1147
1148 // Try to offer address from subnet1. There is one address available
1149 // so it should be offered.
1150 AllocEngine::ClientContext4
1151 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1152 false, false, "host.example.com.", true);
1153 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1154 Lease4Ptr lease = engine_.allocateLease4(ctx);
1155 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"
, 1155, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1156 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"
, 1156, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1157
1158 // Apply restrictions on the pool1. This should be only assigned
1159 // to clients belonging to cable-modem class.
1160 pool1_->allowClientClass("cable-modem");
1161
1162 // The allocation engine should determine that the pool1 is not
1163 // available for the client not belonging to the cable-modem class.
1164 // Instead, it should offer an address from subnet2 that belongs
1165 // to the same shared network.
1166 ctx.subnet_ = subnet1_;
1167 lease = engine_.allocateLease4(ctx);
1168 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"
, 1168, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1169 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"
, 1169, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1170
1171 // Assign cable-modem class and try again. This time, we should
1172 // offer an address from the pool1.
1173 ctx.query_->addClass(ClientClass("cable-modem"));
1174
1175 // Restrict access to pool2 for this client, to make sure that the
1176 // server doesn't accidentally get an address from this pool.
1177 pool2_->allowClientClass("telephone");
1178
1179 ctx.subnet_ = subnet1_;
1180 lease = engine_.allocateLease4(ctx);
1181 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"
, 1181, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1182 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"
, 1182, gtest_ar.failure_message()) = ::testing::Message()
;
1183}
1184
1185// Test that global reservations within shared network take precedence over the
1186// existing leases regardless in which subnet belonging to a shared network
1187// reservations belong.
1188TEST_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"
, 1188), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1188), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1188), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test
::TestBody()
{
1189
1190 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"
, 1190, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1191
1192 // Create reservation for the client.
1193 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1194 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
1195 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1196 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1197 CfgMgr::instance().commit();
1198
1199 subnet1_->setReservationsGlobal(true);
1200 subnet1_->setReservationsInSubnet(true);
1201 subnet2_->setReservationsGlobal(true);
1202 subnet2_->setReservationsInSubnet(true);
1203
1204 // Start allocation from subnet1. The engine should determine that the
1205 // client has global reservations within subnet2 and should rather
1206 // assign reserved addresses.
1207 AllocEngine::ClientContext4
1208 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1209 false, false, "host.example.com.", true);
1210 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1211 AllocEngine::findReservation(ctx);
1212 Lease4Ptr lease = engine_.allocateLease4(ctx);
1213 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"
, 1213, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1214 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"
, 1214, gtest_ar.failure_message()) = ::testing::Message()
;
1215 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"
, 1215, gtest_ar.failure_message()) = ::testing::Message()
;
1216
1217 // Let's create a lease for the client to make sure the lease is not
1218 // renewed but a reserved lease is offered.
1219 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1220 501, time(NULL__null), subnet1_->getID()));
1221 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1222 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"
, 1222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1223 ctx.subnet_ = subnet1_;
1224 ctx.hosts_.clear();
1225 AllocEngine::findReservation(ctx);
1226 lease = engine_.allocateLease4(ctx);
1227 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"
, 1227, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1228 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"
, 1228, gtest_ar.failure_message()) = ::testing::Message()
;
1229 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"
, 1229, gtest_ar.failure_message()) = ::testing::Message()
;
1230}
1231
1232
1233// Test that reservations within shared network take precedence over the
1234// existing leases regardless in which subnet belonging to a shared network
1235// reservations belong.
1236TEST_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"
, 1236), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1236), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1236), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test
::TestBody()
{
1237
1238 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"
, 1238, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1239
1240 // Create reservation for the client.
1241 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1242 Host::IDENT_HWADDR, subnet2_->getID(),
1243 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1244 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1245 CfgMgr::instance().commit();
1246
1247 // Start allocation from subnet1. The engine should determine that the
1248 // client has reservations in subnet2 and should rather assign reserved
1249 // addresses.
1250 AllocEngine::ClientContext4
1251 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1252 false, false, "host.example.com.", true);
1253 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1254 AllocEngine::findReservation(ctx);
1255 Lease4Ptr lease = engine_.allocateLease4(ctx);
1256 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"
, 1256, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1257 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"
, 1257, gtest_ar.failure_message()) = ::testing::Message()
;
1258 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"
, 1258, gtest_ar.failure_message()) = ::testing::Message()
;
1259
1260 // Let's create a lease for the client in subnet1 to make sure the lease
1261 // is not renewed but a reserved lease is offered.
1262 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1263 501, time(NULL__null), subnet1_->getID()));
1264 lease2->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1265 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"
, 1265, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1266 ctx.subnet_ = subnet1_;
1267 ctx.hosts_.clear();
1268 AllocEngine::findReservation(ctx);
1269 lease = engine_.allocateLease4(ctx);
1270 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"
, 1270, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1271 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"
, 1271, gtest_ar.failure_message()) = ::testing::Message()
;
1272 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"
, 1272, gtest_ar.failure_message()) = ::testing::Message()
;
1273
1274 // Let's create a lease for the client in subnet2 to make sure the lease
1275 // is not renewed but a reserved lease is offered.
1276 Lease4Ptr lease3(new Lease4(IOAddress("10.1.2.55"), hwaddr_, ClientIdPtr(),
1277 501, time(NULL__null), subnet2_->getID()));
1278 lease3->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1279 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"
, 1279, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease3)", "false", "true"
) .c_str()) = ::testing::Message()
;
1280 ctx.subnet_ = subnet1_;
1281 ctx.hosts_.clear();
1282 AllocEngine::findReservation(ctx);
1283 lease = engine_.allocateLease4(ctx);
1284 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"
, 1284, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1285 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"
, 1285, gtest_ar.failure_message()) = ::testing::Message()
;
1286 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"
, 1286, gtest_ar.failure_message()) = ::testing::Message()
;
1287}
1288
1289
1290// Test that reservations within shared network take precedence over the
1291// existing leases regardless in which subnet belonging to a shared network
1292// reservations belong. Host lookups returning a collection are disabled.
1293// As it is only an optimization the behavior (so the test) must stay
1294// unchanged.
1295TEST_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"
, 1295), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1295), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1295), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
>); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test
::TestBody()
{
1296
1297 // Disable host lookups returning a collection.
1298 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"
, 1298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1299 HostMgr::instance().setDisableSingleQuery(true);
1300
1301 // Create reservation for the client.
1302 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1303 Host::IDENT_HWADDR, subnet2_->getID(),
1304 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1305 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1306 CfgMgr::instance().commit();
1307
1308 subnet1_->setReservationsGlobal(true);
1309 subnet1_->setReservationsInSubnet(true);
1310 subnet2_->setReservationsGlobal(true);
1311 subnet2_->setReservationsInSubnet(true);
1312
1313 // Start allocation from subnet1. The engine should determine that the
1314 // client has reservations in subnet2 and should rather assign reserved
1315 // addresses.
1316 AllocEngine::ClientContext4
1317 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1318 false, false, "host.example.com.", true);
1319 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1320 AllocEngine::findReservation(ctx);
1321 Lease4Ptr lease = engine_.allocateLease4(ctx);
1322 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"
, 1322, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1323 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"
, 1323, gtest_ar.failure_message()) = ::testing::Message()
;
1324 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"
, 1324, gtest_ar.failure_message()) = ::testing::Message()
;
1325
1326 // Let's create a lease for the client to make sure the lease is not
1327 // renewed but a reserved lease is offered.
1328 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1329 501, time(NULL__null), subnet1_->getID()));
1330 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1331 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"
, 1331, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1332 ctx.subnet_ = subnet1_;
1333 ctx.hosts_.clear();
1334 AllocEngine::findReservation(ctx);
1335 lease = engine_.allocateLease4(ctx);
1336 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"
, 1336, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1337 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"
, 1337, gtest_ar.failure_message()) = ::testing::Message()
;
1338 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"
, 1338, gtest_ar.failure_message()) = ::testing::Message()
;
1339}
1340
1341// This test verifies that the server can offer an address from a shared
1342// subnet if there's at least 1 address left there, but will not offer
1343// anything if both subnets are completely full.
1344TEST_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", 1344
), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1344), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1344), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_runningOut_Test
>); void SharedNetworkAlloc4Test_runningOut_Test::TestBody
()
{
1345
1346 // Allocate everything in subnet1
1347 insertLease("192.0.2.17", subnet1_->getID());
1348
1349 // Allocate everything, except one address in subnet2.
1350 for (int i = 5; i < 100; i++) {
1351 stringstream tmp;
1352 tmp << "10.1.2." << i;
1353 insertLease(tmp.str(), subnet2_->getID());
1354 }
1355
1356 // Create context which will be used to try to allocate leases from the
1357 // shared network. The context points to subnet1, which address space
1358 // is exhausted. We expect the allocation engine to find another subnet
1359 // within the same shared network and offer an address from there.
1360 AllocEngine::ClientContext4
1361 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1362 false, false, "host.example.com.", true);
1363 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1364 Lease4Ptr lease = engine_.allocateLease4(ctx);
1365 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",
1365, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1366
1367 // Now allocate the last address. Now both subnets are exhausted.
1368 insertLease("10.1.2.100", subnet2_->getID());
1369
1370 // Ok, we're out. We should not get anything now.
1371 lease = engine_.allocateLease4(ctx);
1372 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"
, 1372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
1373
1374 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",
1374, gtest_ar.failure_message()) = ::testing::Message()
;
1375 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"
, 1375, gtest_ar.failure_message()) = ::testing::Message()
;
1376 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",
1376, gtest_ar.failure_message()) = ::testing::Message()
;
1377 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",
1377, gtest_ar.failure_message()) = ::testing::Message()
;
1378 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",
1378, gtest_ar.failure_message()) = ::testing::Message()
;
1379
1380 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"
, 1380, gtest_ar.failure_message()) = ::testing::Message()
;
1381 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"
, 1381, gtest_ar.failure_message()) = ::testing::Message()
;
1382 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"
, 1382, gtest_ar.failure_message()) = ::testing::Message()
;
1383 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"
, 1383, gtest_ar.failure_message()) = ::testing::Message()
;
1384 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"
, 1384, gtest_ar.failure_message()) = ::testing::Message()
;
1385}
1386
1387// This test verifies that the server can offer an address from a
1388// subnet and the introduction of shared network doesn't break anything here.
1389TEST_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"
, 1389), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1389), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1389), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test
::TestBody()
{
1390
1391 // Create context which will be used to try to allocate leases from the
1392 // shared network. The context points to subnet1, which address space
1393 // is exhausted. We expect the allocation engine to find another subnet
1394 // within the same shared network and offer an address from there.
1395 AllocEngine::ClientContext4
1396 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1397 false, false, "host.example.com.", false);
1398 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1399 Lease4Ptr lease = engine_.allocateLease4(ctx);
1400
1401 // The allocation engine should have assigned an address from the first
1402 // subnet.
1403 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"
, 1403, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1404 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"
, 1404, gtest_ar.failure_message()) = ::testing::Message()
;
1405
1406 // Make sure the lease is in the lease mgr.
1407 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"
, 1407, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1408}
1409
1410// This test verifies that the server can allocate an address from a
1411// different subnet than orginally selected, when the address pool in
1412// the first subnet is exhausted.
1413TEST_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"
, 1413), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1413), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1413), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetwork_Test
>); void SharedNetworkAlloc4Test_requestSharedNetwork_Test
::TestBody()
{
1414
1415 // Create a lease for a single address in the first address pool. The
1416 // pool is now exhausted.
1417 Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID());
1418
1419 // Create context which will be used to try to allocate leases from the
1420 // shared network. The context points to subnet1, which address space
1421 // is exhausted. We expect the allocation engine to find another subnet
1422 // within the same shared network and offer an address from there.
1423 AllocEngine::ClientContext4
1424 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1425 false, false, "host.example.com.", false);
1426 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1427 Lease4Ptr lease2 = engine_.allocateLease4(ctx);
1428 // The allocation engine should have assigned an address from the second
1429 // subnet. We could guess that this is 10.1.2.5, being the first address
1430 // in the address pool, but to make the test more generic, we merely
1431 // verify that the address is in the given address pool.
1432 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"
, 1432, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1433 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"
, 1433, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1434
1435 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"
, 1435, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease2)", "false",
"true") .c_str()) = ::testing::Message()
;
1436
1437 // The client should also be assigned a lease when it specifies a hint
1438 // that doesn't match the subnet from which the lease is offered. The
1439 // engine should check alternative subnets to match the hint to
1440 // a subnet. The requested lease is available, so it should be offered.
1441 ctx.subnet_ = subnet1_;
1442 ctx.requested_address_ = IOAddress("10.1.2.25");
1443 lease2 = engine_.allocateLease4(ctx);
1444 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"
, 1444, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1445 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"
, 1445, gtest_ar.failure_message()) = ::testing::Message()
;
1446
1447 // The returning client (the one that has a lease) should also be able
1448 // to renew its lease regardless of a subnet it begins with. So, it has
1449 // an address assigned from subnet1, but we use subnet2 as a selected
1450 // subnet.
1451 AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_,
1452 IOAddress("0.0.0.0"), false, false,
1453 "host.example.com.", false);
1454 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1455 lease2 = engine_.allocateLease4(ctx2);
1456 // The existing lease should be returned.
1457 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"
, 1457, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease2", "false", "true") .c_str()) = ::testing::Message()
;
1458 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"
, 1458, gtest_ar.failure_message()) = ::testing::Message()
;
1459}
1460
1461// This test verifies that the server can assign an address from a
1462// different subnet than orginally selected, when the address pool in
1463// the first subnet is exhausted.
1464TEST_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"
, 1464), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1464), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1464), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test
::TestBody()
{
1465 // Try to offer address from subnet1. There is one address available
1466 // so it should be offered.
1467 AllocEngine::ClientContext4
1468 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1469 false, false, "host.example.com.", false);
1470 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1471 Lease4Ptr lease = engine_.allocateLease4(ctx);
1472 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"
, 1472, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1473 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"
, 1473, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1474
1475 // Remove the lease so as we can start over.
1476 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"
, 1476, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1477
1478 // Apply restrictions on the subnet1. This should be only assigned
1479 // to clients belonging to cable-modem class.
1480 subnet1_->allowClientClass("cable-modem");
1481
1482 // The allocation engine should determine that the subnet1 is not
1483 // available for the client not belonging to the cable-modem class.
1484 // Instead, it should assign an address from subnet2 that belongs
1485 // to the same shared network.
1486 ctx.subnet_ = subnet1_;
1487 lease = engine_.allocateLease4(ctx);
1488 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"
, 1488, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1489 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"
, 1489, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1490
1491 // Remove the lease so as we can start over.
1492 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"
, 1492, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1493
1494 // Assign cable-modem class and try again. This time, we should
1495 // offer an address from the subnet1.
1496 ctx.query_->addClass(ClientClass("cable-modem"));
1497
1498 ctx.subnet_ = subnet1_;
1499 lease = engine_.allocateLease4(ctx);
1500 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"
, 1500, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1501 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"
, 1501, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1502
1503 // Let's now remove the client from the cable-modem class and try
1504 // to renew the address. The engine should determine that the
1505 // client doesn't have access to the subnet1 pools anymore and
1506 // assign an address from unrestricted subnet.
1507 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1508 ctx.subnet_ = subnet1_;
1509 lease = engine_.allocateLease4(ctx);
1510 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"
, 1510, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1511 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"
, 1511, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1512}
1513
1514// This test verifies that the server can assign an address from a
1515// different subnet than orginally selected, when the address pool in
1516// the first subnet requires another class.
1517TEST_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"
, 1517), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1517), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1517), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test
::TestBody()
{
1518 // Try to offer address from subnet1. There is one address available
1519 // so it should be offered.
1520 AllocEngine::ClientContext4
1521 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1522 false, false, "host.example.com.", false);
1523 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1524 Lease4Ptr lease = engine_.allocateLease4(ctx);
1525 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"
, 1525, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1526 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"
, 1526, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1527
1528 // Remove the lease so as we can start over.
1529 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"
, 1529, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1530
1531 // Apply restrictions on the pool1. This should be only assigned
1532 // to clients belonging to cable-modem class.
1533 pool1_->allowClientClass("cable-modem");
1534
1535 // The allocation engine should determine that the pool1 is not
1536 // available for the client not belonging to the cable-modem class.
1537 // Instead, it should assign an address from subnet2 that belongs
1538 // to the same shared network.
1539 ctx.subnet_ = subnet1_;
1540 lease = engine_.allocateLease4(ctx);
1541 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"
, 1541, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1542 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"
, 1542, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1543
1544 // Remove the lease so as we can start over.
1545 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"
, 1545, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1546
1547 // Assign cable-modem class and try again. This time, we should
1548 // offer an address from the pool1.
1549 ctx.query_->addClass(ClientClass("cable-modem"));
1550
1551 // Restrict access to pool2 for this client, to make sure that the
1552 // server doesn't accidentally get an address from this pool.
1553 pool2_->allowClientClass("telephone");
1554
1555 ctx.subnet_ = subnet1_;
1556 lease = engine_.allocateLease4(ctx);
1557 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"
, 1557, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1558 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"
, 1558, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1559
1560 // Let's now remove the client from the cable-modem class and try
1561 // to renew the address. The engine should determine that the
1562 // client doesn't have access to the pool1 anymore and
1563 // assign an address from another pool.
1564 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1565 ctx.query_->addClass(ClientClass("telephone"));
1566 ctx.subnet_ = subnet1_;
1567 lease = engine_.allocateLease4(ctx);
1568 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"
, 1568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1569 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"
, 1569, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
1570}
1571
1572// Test that reservations within shared network take precedence over the
1573// existing leases regardless in which subnet belonging to a shared network
1574// reservations belong (DHCPREQUEST case).
1575TEST_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"
, 1575), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1575), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1575), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test
::TestBody()
{
1576
1577 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"
, 1577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1578
1579 // Create reservation for the client.
1580 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1581 Host::IDENT_HWADDR, subnet2_->getID(),
1582 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1583 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1584 CfgMgr::instance().commit();
1585
1586 // Start allocation from subnet1. The engine should determine that the
1587 // client has reservations in subnet2 and should rather assign reserved
1588 // addresses.
1589 AllocEngine::ClientContext4
1590 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1591 false, false, "host.example.com.", false);
1592 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1593 AllocEngine::findReservation(ctx);
1594 Lease4Ptr lease = engine_.allocateLease4(ctx);
1595 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"
, 1595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1596 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"
, 1596, gtest_ar.failure_message()) = ::testing::Message()
;
1597 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"
, 1597, gtest_ar.failure_message()) = ::testing::Message()
;
1598
1599 // Remove the lease for another test below.
1600 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"
, 1600, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1601
1602 // Let's create a lease for the client to make sure the lease is not
1603 // renewed but a reserved lease is allocated again.
1604 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1605 501, time(NULL__null), subnet1_->getID()));
1606 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1607 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"
, 1607, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1608 ctx.subnet_ = subnet1_;
1609 ctx.hosts_.clear();
1610 AllocEngine::findReservation(ctx);
1611 lease = engine_.allocateLease4(ctx);
1612 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"
, 1612, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1613 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"
, 1613, gtest_ar.failure_message()) = ::testing::Message()
;
1614 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"
, 1614, gtest_ar.failure_message()) = ::testing::Message()
;
1615}
1616
1617// Test that reservations within shared network take precedence over the
1618// existing leases regardless in which subnet belonging to a shared network
1619// reservations belong (DHCPREQUEST case). Host lookups returning a collection
1620// are disabled. As it is only an optimization the behavior (so the test)
1621// must stay unchanged.
1622TEST_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"
, 1622), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test
>()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1622), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1622), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
>); void SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test
::TestBody()
{
1623
1624 // Disable host lookups returning a collection.
1625 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"
, 1625, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "HostMgr::instance().getDisableSingleQuery()", "true", "false"
) .c_str()) = ::testing::Message()
;
1626 HostMgr::instance().setDisableSingleQuery(true);
1627
1628 // Create reservation for the client.
1629 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
1630 Host::IDENT_HWADDR, subnet2_->getID(),
1631 SUBNET_ID_UNUSED, IOAddress("10.1.2.105")));
1632 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
1633 CfgMgr::instance().commit();
1634
1635 // Start allocation from subnet1. The engine should determine that the
1636 // client has reservations in subnet2 and should rather assign reserved
1637 // addresses.
1638 AllocEngine::ClientContext4
1639 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(),
1640 false, false, "host.example.com.", false);
1641 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1642 AllocEngine::findReservation(ctx);
1643 Lease4Ptr 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_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"
, 1645, gtest_ar.failure_message()) = ::testing::Message()
;
1646 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"
, 1646, gtest_ar.failure_message()) = ::testing::Message()
;
1647
1648 // Remove the lease for another test below.
1649 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"
, 1649, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1650
1651 // Let's create a lease for the client to make sure the lease is not
1652 // renewed but a reserved lease is allocated again.
1653 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(),
1654 501, time(NULL__null), subnet1_->getID()));
1655 lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago
1656 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"
, 1656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease2)", "false", "true"
) .c_str()) = ::testing::Message()
;
1657 ctx.subnet_ = subnet1_;
1658 ctx.hosts_.clear();
1659 AllocEngine::findReservation(ctx);
1660 lease = engine_.allocateLease4(ctx);
1661 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"
, 1661, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1662 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"
, 1662, gtest_ar.failure_message()) = ::testing::Message()
;
1663 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"
, 1663, gtest_ar.failure_message()) = ::testing::Message()
;
1664}
1665
1666// This test checks if an expired lease can be reused in DHCPDISCOVER (fake
1667// allocation)
1668TEST_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"
, 1668), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1668), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1668), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseExpiredLease4_Test
>); void AllocEngine4Test_discoverReuseExpiredLease4_Test::
TestBody()
{
1669 boost::scoped_ptr<AllocEngine> engine;
1670 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_1670
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1670
; } } else gtest_label_testnothrow_1670 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1670, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1671 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"
, 1671, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1672
1673 IOAddress addr("192.0.2.15");
1674 CfgMgr& cfg_mgr = CfgMgr::instance();
1675 // Get rid of the default test configuration.
1676 cfg_mgr.clear();
1677
1678 // Create configuration similar to other tests, but with a single address pool
1679 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1680 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1681 subnet_->addPool(pool_);
1682 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1683
1684 // Just a different hw/client-id for the second client
1685 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
1686 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
1687 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
1688 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
1689 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
1690 495, now, subnet_->getID()));
1691 // Copy the lease, so as it can be compared with the old lease returned
1692 // by the allocation engine.
1693 Lease4 original_lease(*lease);
1694
1695 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
1696 // is expired already
1697 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"
, 1697, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
1698 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"
, 1698, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1699
1700 // CASE 1: Asking for any address
1701 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
1702 IOAddress("0.0.0.0"), false, false,
1703 "", true);
1704 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1705 lease = engine->allocateLease4(ctx1);
1706 // Check that we got that single lease
1707 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"
, 1707, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1708 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"
, 1708, gtest_ar.failure_message()) = ::testing::Message()
;
1709
1710 // We are reusing expired lease, the old (expired) instance should be
1711 // returned. The returned instance should be the same as the original
1712 // lease.
1713 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"
, 1713, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
1714 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"
, 1714, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *ctx1.old_lease_", "false", "true") .c_str
()) = ::testing::Message()
;
1715
1716 // Do all checks on the lease (if subnet-id, preferred/valid times are ok etc.)
1717 checkLease4(lease);
1718
1719 // CASE 2: Asking specifically for this address
1720 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
1721 IOAddress(addr), false, false,
1722 "", true);
1723 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
1724 lease = engine->allocateLease4(ctx2);
1725 // Check that we got that single lease
1726 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"
, 1726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1727 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"
, 1727, gtest_ar.failure_message()) = ::testing::Message()
;
1728
1729 // We are updating expired lease. The copy of the old lease should be
1730 // returned and it should be equal to the original lease.
1731 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"
, 1731, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
1732 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"
, 1732, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*ctx2.old_lease_ == original_lease", "false", "true") .c_str
()) = ::testing::Message()
;
1733}
1734
1735// This test checks if an expired lease can be reused in REQUEST (actual allocation)
1736TEST_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"
, 1736), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1736), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1736), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseExpiredLease4_Test
>); void AllocEngine4Test_requestReuseExpiredLease4_Test::
TestBody()
{
1737 boost::scoped_ptr<AllocEngine> engine;
1738 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_1738
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1738
; } } else gtest_label_testnothrow_1738 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1738, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1739 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"
, 1739, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1740
1741 IOAddress addr("192.0.2.105");
1742
1743 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"
, 1743, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0)", "false", "true"
) .c_str()) = ::testing::Message()
;
1744 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"
, 1744, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1745 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
1746 subnet_->getID());
1747
1748 int64_t glbl_assigned = getStatistics("assigned-addresses");
1749 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
1750
1751 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"
, 1751, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0)", "false", "true")
.c_str()) = ::testing::Message()
;
1752 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"
, 1752, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1753
1754 // Just a different hw/client-id for the second client
1755 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
1756 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
1757 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
1758 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
1759
1760 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
1761 495, now, subnet_->getID()));
1762 // Make a copy of the lease, so as we can compare that with the old lease
1763 // instance returned by the allocation engine.
1764 Lease4 original_lease(*lease);
1765
1766 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
1767 // is expired already
1768 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"
, 1768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
1769 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"
, 1769, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
1770
1771 // A client comes along, asking specifically for this address
1772 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
1773 IOAddress(addr), false, false,
1774 "host.example.com.", false);
1775 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
1776 lease = engine->allocateLease4(ctx);
1777
1778 // Check that he got that single lease
1779 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"
, 1779, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
1780 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"
, 1780, gtest_ar.failure_message()) = ::testing::Message()
;
1781
1782 // Check that the lease is indeed updated in LeaseMgr
1783 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
1784 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"
, 1784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
1785
1786 // Now check that the lease in LeaseMgr has the same parameters
1787 detailCompareLease(lease, from_mgr);
1788
1789 // The allocation engine should return a copy of the old lease. This
1790 // lease should be equal to the original lease.
1791 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"
, 1791, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
1792 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"
, 1792, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*ctx.old_lease_ == original_lease", "false", "true") .c_str
()) = ::testing::Message()
;
1793
1794 // Check that the stats declined stats were modified correctly. Note, because
1795 // added the lease directly, assigned-leases never bumped to one, so when we
1796 // reclaim it gets decremented to -1, then on assignment back to 0.
1797 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"
, 1797, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1798 cumulative += 1;
1799 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"
, 1800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
1800 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"
, 1800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1801 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"
, 1801, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
1802 glbl_cumulative += 1;
1803 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"
, 1803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
1804 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"
, 1804, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1)", "false", "true")
.c_str()) = ::testing::Message()
;
1805 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"
, 1805, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1806}
1807
1808// This test checks if an expired declined lease can be reused when responding
1809// to DHCPDISCOVER (fake allocation)
1810TEST_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"
, 1810), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1810), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1810), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4_Test
>); void AllocEngine4Test_discoverReuseDeclinedLease4_Test
::TestBody()
{
1811
1812 AllocEnginePtr engine(new AllocEngine(0));
1813 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"
, 1813, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1814
1815 // Now prepare a configuration with single address pool.
1816 IOAddress addr("192.0.2.15");
1817 CfgMgr& cfg_mgr = CfgMgr::instance();
1818 cfg_mgr.clear();
1819 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1820 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1821 subnet_->addPool(pool_);
1822 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1823
1824 // Now create a declined lease, decline it and rewind its cltt, so it
1825 // is expired.
1826 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
1827
1828 // CASE 1: Ask for any address
1829 Lease4Ptr assigned;
1830 testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned);
1831
1832 // Check that we got that single lease
1833 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"
, 1833, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
1834 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"
, 1834, gtest_ar.failure_message()) = ::testing::Message()
;
1835
1836 // CASE 2: Asking specifically for this address
1837 testReuseLease4(engine, declined, "192.0.2.15", true, SHOULD_PASS, assigned);
1838
1839 // Check that we get it again
1840 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"
, 1840, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
1841 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"
, 1841, gtest_ar.failure_message()) = ::testing::Message()
;
1842}
1843
1844// This test checks if statistics are not updated when expired declined lease
1845// is reused when responding to DHCPDISCOVER (fake allocation)
1846TEST_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"
, 1846), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1846), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1846), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
>); void AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test
::TestBody()
{
1847
1848 // Now prepare for DISCOVER processing
1849 AllocEnginePtr engine(new AllocEngine(0));
1850 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"
, 1850, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1851
1852 // Now prepare a configuration with single address pool.
1853 IOAddress addr("192.0.2.15");
1854 CfgMgr& cfg_mgr = CfgMgr::instance();
1855 cfg_mgr.clear();
1856 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1857 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1858 subnet_->addPool(pool_);
1859 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1860 cfg_mgr.commit(); // so we will recalc stats
1861 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
1862 subnet_->getID());
1863
1864 int64_t glbl_assigned = getStatistics("assigned-addresses");
1865 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
1866
1867 // Now create a declined lease, decline it and rewind its cltt, so it
1868 // is expired.
1869 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
1870
1871 // Ask for any address. There's only one address in the pool, so it doesn't
1872 // matter much.
1873 Lease4Ptr assigned;
1874 testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned);
1875
1876 // Check that the stats declined stats were not modified
1877 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"
, 1877, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1878 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"
, 1879, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
1879 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"
, 1879, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1880 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"
, 1880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
1881 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"
, 1881, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
1882 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"
, 1882, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", 0)", "false", "true"
) .c_str()) = ::testing::Message()
;
1883 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"
, 1883, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 0)", "false"
, "true") .c_str()) = ::testing::Message()
;
1884 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"
, 1884, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1885 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"
, 1885, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1886}
1887
1888// This test checks if an expired declined lease can be reused when responding
1889// to REQUEST (actual allocation)
1890TEST_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"
, 1890), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1890), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1890), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4_Test
>); void AllocEngine4Test_requestReuseDeclinedLease4_Test::
TestBody()
{
1891
1892 AllocEnginePtr engine(new AllocEngine(0));
1893 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"
, 1893, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1894
1895 // Now prepare a configuration with single address pool.
1896 IOAddress addr("192.0.2.15");
1897 CfgMgr& cfg_mgr = CfgMgr::instance();
1898 cfg_mgr.clear();
1899 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1900 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1901 subnet_->addPool(pool_);
1902 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1903
1904 // Now create a declined lease, decline it and rewind its cltt, so it
1905 // is expired.
1906 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
1907
1908 // Asking specifically for this address
1909 Lease4Ptr assigned;
1910 testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned);
1911 // Check that we got it.
1912 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"
, 1912, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
1913 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"
, 1913, gtest_ar.failure_message()) = ::testing::Message()
;
1914
1915 // Check that the lease is indeed updated in LeaseMgr
1916 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
1917 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"
, 1917, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
1918
1919 // Now check that the lease in LeaseMgr has the same parameters
1920 detailCompareLease(assigned, from_mgr);
1921}
1922
1923// This test checks if statistics are not updated when expired declined lease
1924// is reused when responding to DHCPREQUEST (actual allocation)
1925TEST_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"
, 1925), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1925), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1925), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
>); void AllocEngine4Test_requestReuseDeclinedLease4Stats_Test
::TestBody()
{
1926
1927 AllocEnginePtr engine(new AllocEngine(0));
1928 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"
, 1928, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1929
1930 // Now prepare a configuration with single address pool.
1931 IOAddress addr("192.0.2.15");
1932 CfgMgr& cfg_mgr = CfgMgr::instance();
1933 cfg_mgr.clear();
1934 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
1935 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
1936 subnet_->addPool(pool_);
1937 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
1938 cfg_mgr.commit();
1939 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
1940 subnet_->getID());
1941
1942 int64_t glbl_assigned = getStatistics("assigned-addresses");
1943 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
1944
1945 // Now create a declined lease, decline it and rewind its cltt, so it
1946 // is expired.
1947 Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10);
1948
1949 // Asking specifically for this address
1950 Lease4Ptr assigned;
1951 testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned);
1952 // Check that we got it.
1953 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"
, 1953, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "assigned", "false", "true") .c_str()) = ::testing::Message
()
;
1954
1955 // Check that the stats are correct. Note that assigned-addresses does
1956 // not get decremented when a lease is declined, ergo not incremented
1957 // when it is reused. Declined address stats will be -1 since
1958 // lease was created as declined which does not increment the stat.
1959 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"
, 1959, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1960 cumulative += 1;
1961 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"
, 1962, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
1962 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"
, 1962, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1963 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"
, 1963, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
1964 glbl_cumulative += 1;
1965 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"
, 1965, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
1966 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"
, 1966, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", -1)", "false", "true"
) .c_str()) = ::testing::Message()
;
1967 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"
, 1967, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 1)", "false"
, "true") .c_str()) = ::testing::Message()
;
1968 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"
, 1968, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"declined-addresses\", -1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1969 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"
, 1969, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-declined-addresses\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1970}
1971
1972// This test checks if a released lease can be reused in REQUEST (actual allocation)
1973TEST_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"
, 1973), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1973), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1973), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseReleasedLease4_Test
>); void AllocEngine4Test_requestReuseReleasedLease4_Test::
TestBody()
{
1974 boost::scoped_ptr<AllocEngine> engine;
1975 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_1975
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1975
; } } else gtest_label_testnothrow_1975 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 1975, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1976 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"
, 1976, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
1977
1978 IOAddress addr("192.0.2.105");
1979
1980 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"
, 1980, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1981 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
1982 subnet_->getID());
1983
1984 int64_t glbl_assigned = getStatistics("assigned-addresses");
1985 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
1986
1987 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"
, 1987, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0)", "false", "true")
.c_str()) = ::testing::Message()
;
1988 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"
, 1988, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
1989
1990 // Just a different hw/client-id for the second client
1991 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
1992 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
1993 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
1994 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
1995
1996 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
1997 495, now, subnet_->getID()));
1998 lease->state_ = Lease4::STATE_RELEASED;
1999 // Make a copy of the lease, so as we can compare that with the old lease
2000 // instance returned by the allocation engine.
2001 Lease4 original_lease(*lease);
2002
2003 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
2004 // is expired already
2005 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"
, 2005, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
2006 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"
, 2006, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
2007
2008 // A client comes along, asking specifically for this address
2009 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2010 IOAddress(addr), false, false,
2011 "host.example.com.", false);
2012 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2013 lease = engine->allocateLease4(ctx);
2014
2015 // Check that he got that single lease
2016 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"
, 2016, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2017 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"
, 2017, gtest_ar.failure_message()) = ::testing::Message()
;
2018
2019 // Check that the lease is indeed updated in LeaseMgr
2020 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
2021 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"
, 2021, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2022
2023 // Now check that the lease in LeaseMgr has the same parameters
2024 detailCompareLease(lease, from_mgr);
2025
2026 // The allocation engine should return a copy of the old lease. This
2027 // lease should be equal to the original lease.
2028 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"
, 2028, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2029 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"
, 2029, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*ctx.old_lease_ == original_lease", "false", "true") .c_str
()) = ::testing::Message()
;
2030
2031 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"
, 2031, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2032 cumulative += 1;
2033 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"
, 2034, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
2034 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"
, 2034, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2035 glbl_assigned += 1;
2036 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"
, 2036, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
2037 glbl_cumulative += 1;
2038 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"
, 2038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
2039 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"
, 2039, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1)", "false", "true")
.c_str()) = ::testing::Message()
;
2040 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"
, 2040, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
2041}
2042
2043// This test checks that the Allocation Engine correctly identifies the
2044// existing client's lease in the lease database, using the client
2045// identifier and HW address.
2046TEST_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"
, 2046), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2046), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2046), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_identifyClientLease_Test
>); void AllocEngine4Test_identifyClientLease_Test::TestBody
()
{
2047 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, clientid_,
2048 100, time(NULL__null), subnet_->getID()));
2049 LeaseMgrFactory::instance().addLease(lease);
2050
2051 AllocEngine engine(0);
2052 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2053 IOAddress::IPV4_ZERO_ADDRESS(),
2054 false, false, "", true);
2055 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2056
2057 Lease4Ptr identified_lease = engine.allocateLease4(ctx);
2058 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"
, 2058, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2059 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"
, 2059, gtest_ar.failure_message()) = ::testing::Message()
;
2060
2061 ctx.hwaddr_ = hwaddr2_;
2062 ctx.clientid_ = clientid_;
2063 identified_lease = engine.allocateLease4(ctx);
2064 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"
, 2064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2065 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"
, 2065, gtest_ar.failure_message()) = ::testing::Message()
;
2066
2067 ctx.hwaddr_ = hwaddr_;
2068 ctx.clientid_ = clientid2_;
2069 identified_lease = engine.allocateLease4(ctx);
2070 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"
, 2070, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2071 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"
, 2071, gtest_ar.failure_message()) = ::testing::Message()
;
2072
2073 ctx.hwaddr_ = hwaddr_;
2074 ctx.clientid_.reset();
2075 identified_lease = engine.allocateLease4(ctx);
2076 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"
, 2076, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2077 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"
, 2077, gtest_ar.failure_message()) = ::testing::Message()
;
2078
2079 ctx.hwaddr_ = hwaddr2_;
2080 ctx.clientid_.reset();
2081 identified_lease = engine.allocateLease4(ctx);
2082 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"
, 2082, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2083 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"
, 2083, gtest_ar.failure_message()) = ::testing::Message()
;
2084
2085 lease->client_id_.reset();
2086 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_2086; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2086; } } else gtest_label_testnothrow_2086
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2086, ("Expected: " "LeaseMgrFactory::instance().updateLease4(lease)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2087
2088 ctx.hwaddr_ = hwaddr_;
2089 ctx.clientid_ = clientid_;
2090 identified_lease = engine.allocateLease4(ctx);
2091 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"
, 2091, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2092 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"
, 2092, gtest_ar.failure_message()) = ::testing::Message()
;
2093
2094 ctx.hwaddr_ = hwaddr_;
2095 ctx.clientid_.reset();
2096 identified_lease = engine.allocateLease4(ctx);
2097 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"
, 2097, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2098 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"
, 2098, gtest_ar.failure_message()) = ::testing::Message()
;
2099
2100 ctx.hwaddr_ = hwaddr2_;
2101 ctx.clientid_ = clientid_;
2102 identified_lease = engine.allocateLease4(ctx);
2103 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"
, 2103, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "identified_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2104 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"
, 2104, gtest_ar.failure_message()) = ::testing::Message()
;
2105}
2106
2107// This test checks that when the client requests the address which belongs
2108// to another client, the allocation engine returns NULL (for the
2109// DHCPREQUEST case) or a lease for the address which belongs to this
2110// client (DHCPDISCOVER case).
2111TEST_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"
, 2111), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2111), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2111), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestOtherClientLease_Test
>); void AllocEngine4Test_requestOtherClientLease_Test::TestBody
()
{
2112 // Create the first lease.
2113 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2114 &clientid_->getClientId()[0],
2115 clientid_->getClientId().size(),
2116 100, time(NULL__null), subnet_->getID(),
2117 false, false, ""));
2118 // Create the second lease. Note that we use the same client id here and
2119 // we expect that the allocation engine will figure out that the hardware
2120 // address is different.
2121 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr2_,
2122 &clientid_->getClientId()[0],
2123 clientid_->getClientId().size(),
2124 100, time(NULL__null), subnet_->getID(),
2125 false, false, ""));
2126 // Add leases for both clients to the Lease Manager.
2127 LeaseMgrFactory::instance().addLease(lease);
2128 LeaseMgrFactory::instance().addLease(lease2);
2129
2130 AllocEngine engine(0);
2131
2132 // First client requests the lease which belongs to the second client.
2133 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"),
2134 false, false, "", false);
2135 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2136 Lease4Ptr new_lease = engine.allocateLease4(ctx);
2137 // Allocation engine should return NULL.
2138 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"
, 2138, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "true", "false") .c_str()) = ::testing::Message
()
;
2139
2140 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",
2140, gtest_ar.failure_message()) = ::testing::Message()
;
2141 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"
, 2141, gtest_ar.failure_message()) = ::testing::Message()
;
2142 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",
2142, gtest_ar.failure_message()) = ::testing::Message()
;
2143 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",
2143, gtest_ar.failure_message()) = ::testing::Message()
;
2144 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",
2144, gtest_ar.failure_message()) = ::testing::Message()
;
2145
2146 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"
, 2146, gtest_ar.failure_message()) = ::testing::Message()
;
2147 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"
, 2147, gtest_ar.failure_message()) = ::testing::Message()
;
2148 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"
, 2148, gtest_ar.failure_message()) = ::testing::Message()
;
2149 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"
, 2149, gtest_ar.failure_message()) = ::testing::Message()
;
2150 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"
, 2150, gtest_ar.failure_message()) = ::testing::Message()
;
2151
2152 // Now simulate the DHCPDISCOVER case when the provided address is
2153 // treated as a hint. The engine should return a lease for a
2154 // different address than requested.
2155 ctx.fake_allocation_ = true;
2156 new_lease = engine.allocateLease4(ctx);
2157 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"
, 2157, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "false", "true") .c_str()) = ::testing::Message
()
;
2158 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"
, 2158, gtest_ar.failure_message()) = ::testing::Message()
;
2159}
2160
2161// Allocation engine should remove a pre-existing lease
2162// and renew the temporary lease when offer-lifetime > 0.
2163// This can happen when a client gets a lease which is
2164// later rendered invalid by the creation of host reservation,
2165// either for the lease address or for the client with
2166// a different address.
2167TEST_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"
, 2167), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2167), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2167), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_existingLeasePlusTemporary_Test
>); void AllocEngine4Test_existingLeasePlusTemporary_Test::
TestBody()
{
2168 // Create the first lease.
2169 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2170 &clientid_->getClientId()[0],
2171 clientid_->getClientId().size(),
2172 100, time(NULL__null), subnet_->getID(),
2173 false, false, ""));
2174
2175 // Create the second lease.
2176 Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr_,
2177 &clientid_->getClientId()[0],
2178 clientid_->getClientId().size(),
2179 100, time(NULL__null), subnet_->getID(),
2180 false, false, ""));
2181 // Add leases for both clients to the Lease Manager.
2182 LeaseMgrFactory::instance().addLease(lease);
2183 LeaseMgrFactory::instance().addLease(lease2);
2184
2185 // When temporary allocations are off and client requests the
2186 // second lease, the engine should not return a lease.
2187 AllocEngine engine(0);
2188 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"),
2189 false, false, "", false);
2190 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2191 Lease4Ptr new_lease = engine.allocateLease4(ctx);
2192
2193 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"
, 2193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "true", "false") .c_str()) = ::testing::Message
()
;
2194
2195 // Both leases should still be in the lease back end.
2196 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"
, 2196, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
2197 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"
, 2197, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease2->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
2198
2199 // Now enable temporary allocations by setting offer lifetime > 0.
2200 subnet_->setOfferLft(120);
2201
2202 // Client requests the second lease.
2203 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"),
2204 false, false, "", false);
2205 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2206 new_lease = engine.allocateLease4(ctx2);
2207
2208 // Allocation should return the second lease and remove the original lease.
2209 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"
, 2209, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "new_lease", "false", "true") .c_str()) = ::testing::Message
()
;
2210 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"
, 2210, gtest_ar.failure_message()) = ::testing::Message()
;
2211
2212 // Original lease should have been deleted from lease back.
2213 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"
, 2213, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2214}
2215
2216// This test checks the behavior of the allocation engine in the following
2217// scenario:
2218// - Client has no lease in the database.
2219// - Client has a reservation.
2220// - Client sends DHCPREQUEST without requested IP Address, nor ciaddr.
2221// - Client is allocated a reserved address.
2222//
2223// Note that client must normally include a requested IP address or ciaddr
2224// in its message. But, we still want to provision clients that don't do that.
2225// The server simply picks reserved address or any other available one if there
2226// is no reservation.
2227TEST_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"
, 2227), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2227), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2227), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHint_Test
>); void AllocEngine4Test_reservedAddressNoHint_Test::TestBody
()
{
2228 // Create reservation for the client.
2229 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2230 Host::IDENT_HWADDR, subnet_->getID(),
2231 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2232 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2233 CfgMgr::instance().commit();
2234
2235 AllocEngine engine(0);
2236
2237 // Try to allocate a lease without specifying a hint. This is actually
2238 // incorrect behavior of the client to not send an address it wants to
2239 // obtain but the server should handle this gracefully.
2240 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2241 IOAddress("0.0.0.0"), false, false,
2242 "", false);
2243 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2244 AllocEngine::findReservation(ctx);
2245 Lease4Ptr lease = engine.allocateLease4(ctx);
2246
2247 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"
, 2247, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2248 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"
, 2248, gtest_ar.failure_message()) = ::testing::Message()
;
2249
2250 // Make sure that the lease has been committed to the lease database.
2251 // And that the committed lease is equal to the one returned.
2252 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2253 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"
, 2253, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2254 detailCompareLease(lease, from_mgr);
2255
2256 // Initially, there was no lease for this client, so the returned old
2257 // lease should be NULL.
2258 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"
, 2258, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
2259}
2260
2261// This test checks behavior of the allocation engine in the following scenario:
2262// - Client has no lease in the database.
2263// - Client has a reservation.
2264// - Client sends DHCPDISCOVER without requested IP Address.
2265// - Server returns DHCPOFFER with the reserved address.
2266TEST_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"
, 2266), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2266), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2266), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test
::TestBody()
{
2267 // Create reservation for the client.
2268 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2269 Host::IDENT_HWADDR, subnet_->getID(),
2270 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2271 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2272 CfgMgr::instance().commit();
2273
2274 AllocEngine engine(0);
2275
2276 // Query allocation engine for the lease to be assigned to this
2277 // client without specifying the address to be assigned.
2278 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2279 IOAddress("0.0.0.0"), false, false,
2280 "", true);
2281 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2282 AllocEngine::findReservation(ctx);
2283 Lease4Ptr lease = engine.allocateLease4(ctx);
2284
2285 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"
, 2285, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2286 // The allocation engine should return a reserved address.
2287 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"
, 2287, gtest_ar.failure_message()) = ::testing::Message()
;
2288
2289 // This is a "fake" allocation so the returned lease should not be committed
2290 // to the lease database.
2291 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"
, 2291, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2292
2293 // Client had no lease in the database, so the old lease returned should
2294 // be NULL.
2295 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"
, 2295, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
2296}
2297
2298// This test checks the behavior of the allocation engine in the following
2299// scenario:
2300// - Client has no lease in the database.
2301// - Client has a reservation.
2302// - Client sends DHCPREQUEST with a requested IP address
2303// - Server returns DHCPNAK when requested IP address is different than
2304// the reserved address. Note that the allocation engine returns NULL
2305// to indicate to the server that it should send DHCPNAK.
2306// - Server allocates a reserved address to the client when the client requests
2307// this address using requested IP address option.
2308TEST_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"
, 2308), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2308), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2308), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHint_Test
>); void AllocEngine4Test_reservedAddressHint_Test::TestBody
()
{
2309 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2310 Host::IDENT_HWADDR, subnet_->getID(),
2311 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2312 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2313 CfgMgr::instance().commit();
2314
2315 AllocEngine engine(0);
2316
2317 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2318 IOAddress("192.0.2.234"), false, false,
2319 "", false);
2320 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2321 AllocEngine::findReservation(ctx1);
2322 Lease4Ptr lease = engine.allocateLease4(ctx1);
2323
2324 // The client requested a different address than reserved, so
2325 // the allocation engine should return NULL lease. When the server
2326 // receives a NULL lease for the client, it will send a DHCPNAK.
2327 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"
, 2327, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
2328 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"
, 2328, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2329
2330 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",
2330, gtest_ar.failure_message()) = ::testing::Message()
;
2331 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"
, 2331, gtest_ar.failure_message()) = ::testing::Message()
;
2332 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",
2332, gtest_ar.failure_message()) = ::testing::Message()
;
2333 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",
2333, gtest_ar.failure_message()) = ::testing::Message()
;
2334 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",
2334, gtest_ar.failure_message()) = ::testing::Message()
;
2335
2336 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"
, 2336, gtest_ar.failure_message()) = ::testing::Message()
;
2337 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"
, 2337, gtest_ar.failure_message()) = ::testing::Message()
;
2338 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"
, 2338, gtest_ar.failure_message()) = ::testing::Message()
;
2339 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"
, 2339, gtest_ar.failure_message()) = ::testing::Message()
;
2340 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"
, 2340, gtest_ar.failure_message()) = ::testing::Message()
;
2341
2342 // Now, request a correct address. The client should obtain it.
2343 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2344 IOAddress("192.0.2.123"), false, false,
2345 "", false);
2346 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2347 AllocEngine::findReservation(ctx2);
2348 lease = engine.allocateLease4(ctx2);
2349 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"
, 2349, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2350 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"
, 2350, gtest_ar.failure_message()) = ::testing::Message()
;
2351
2352 // Make sure that the lease has been committed to the lease database.
2353 // And that the committed lease is equal to the one returned.
2354 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2355 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"
, 2355, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2356 detailCompareLease(lease, from_mgr);
2357
2358 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"
, 2358, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2359}
2360
2361// This test checks the behavior of the allocation engine in the following
2362// scenario:
2363// - Client has no lease in the database.
2364// - Client has a reservation.
2365// - Client sends DHCPDISCOVER with a requested IP address as a hint.
2366// - Server offers a reserved address, even though it is different than the
2367// requested address.
2368TEST_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"
, 2368), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2368), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2368), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressHintFakeAllocation_Test
::TestBody()
{
2369 // Create a reservation for the client.
2370 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2371 Host::IDENT_HWADDR, subnet_->getID(),
2372 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2373 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2374 CfgMgr::instance().commit();
2375
2376 AllocEngine engine(0);
2377
2378 // Query the allocation engine for the lease to be assigned to the client
2379 // and specify a hint being a different address than the reserved one.
2380 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2381 IOAddress("192.0.2.234"), false, false,
2382 "", true);
2383 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2384 AllocEngine::findReservation(ctx);
2385 Lease4Ptr lease = engine.allocateLease4(ctx);
2386
2387 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"
, 2387, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
2388 // Allocation engine should return reserved address.
2389 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"
, 2389, gtest_ar.failure_message()) = ::testing::Message()
;
2390
2391 // This is a "fake" allocation so the returned lease should not be committed
2392 // to the lease database.
2393 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"
, 2393, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2394
2395 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"
, 2395, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
2396}
2397
2398// This test checks that the behavior of the allocation engine in the following
2399// scenario:
2400// - Client has a lease for the address from the dynamic pool in the database.
2401// - Client has a reservation for a different address than the one for which
2402// the client has a lease.
2403// - Client sends DHCPREQUEST, asking for the reserved address (as it has been
2404// offered to it when it sent DHCPDISCOVER).
2405// - Server allocates a reserved address and removes the lease for the address
2406// previously allocated to the client.
2407TEST_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"
, 2407), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2407), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2407), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLease_Test
>); void AllocEngine4Test_reservedAddressExistingLease_Test
::TestBody()
{
2408 // Create the reservation for the client.
2409 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2410 Host::IDENT_HWADDR, subnet_->getID(),
2411 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2412 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2413 CfgMgr::instance().commit();
2414
2415 // Create a lease for the client with a different address than the reserved
2416 // one.
2417 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2418 &clientid_->getClientId()[0],
2419 clientid_->getClientId().size(),
2420 100, time(NULL__null), subnet_->getID(),
2421 false, false, ""));
2422 LeaseMgrFactory::instance().addLease(lease);
2423
2424 AllocEngine engine(0);
2425
2426 // Request allocation of the reserved address.
2427 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2428 IOAddress("192.0.2.123"), false, false,
2429 "", false);
2430 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2431 AllocEngine::findReservation(ctx);
2432 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
2433
2434 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"
, 2434, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2435 // The engine should have allocated the reserved address.
2436 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"
, 2436, gtest_ar.failure_message()) = ::testing::Message()
;
2437
2438 // Make sure that the lease has been committed to the lease database.
2439 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_);
2440 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"
, 2440, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2441 detailCompareLease(allocated_lease, from_mgr);
2442
2443 // The previous lease should have been replaced by a new one. The previous
2444 // lease should be returned by the allocation engine to the caller.
2445 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"
, 2445, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2446 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"
, 2446, gtest_ar.failure_message()) = ::testing::Message()
;
2447 detailCompareLease(ctx.old_lease_, lease);
2448}
2449
2450// This test checks that the behavior of the allocation engine in the following
2451// scenario:
2452// - Client A has a lease in the database.
2453// - Client B has a reservation for the address in use by client A.
2454// - Client B sends a DHCPREQUEST requesting the allocation of the reserved
2455// lease (in use by client A).
2456// - Server determines that the reserved address is in use by a different client
2457// and returns DHCPNAK to client B.
2458TEST_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"
, 2458), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2458), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2458), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijacked_Test
>); void AllocEngine4Test_reservedAddressHijacked_Test::TestBody
()
{
2459 // Create host reservation for the client B.
2460 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2461 Host::IDENT_HWADDR, subnet_->getID(),
2462 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2463 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2464 CfgMgr::instance().commit();
2465
2466 // Allocate a lease for the client A for the same address as reserved
2467 // for the client B.
2468 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0,
2469 100, time(NULL__null), subnet_->getID(),
2470 false, false, ""));
2471 LeaseMgrFactory::instance().addLease(lease);
2472
2473 AllocEngine engine(0);
2474
2475 // Try to allocate the reserved lease to client B.
2476 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2477 IOAddress("192.0.2.123"), false, false,
2478 "", false);
2479 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2480 AllocEngine::findReservation(ctx1);
2481 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2482 // The lease is allocated to someone else, so the allocation should not
2483 // succeed.
2484 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"
, 2484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2485 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"
, 2485, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2486
2487 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",
2487, gtest_ar.failure_message()) = ::testing::Message()
;
2488 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"
, 2488, gtest_ar.failure_message()) = ::testing::Message()
;
2489 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",
2489, gtest_ar.failure_message()) = ::testing::Message()
;
2490 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",
2490, gtest_ar.failure_message()) = ::testing::Message()
;
2491 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",
2491, gtest_ar.failure_message()) = ::testing::Message()
;
2492
2493 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"
, 2493, gtest_ar.failure_message()) = ::testing::Message()
;
2494 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"
, 2494, gtest_ar.failure_message()) = ::testing::Message()
;
2495 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"
, 2495, gtest_ar.failure_message()) = ::testing::Message()
;
2496 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"
, 2496, gtest_ar.failure_message()) = ::testing::Message()
;
2497 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"
, 2497, gtest_ar.failure_message()) = ::testing::Message()
;
2498
2499 // Make sure that the allocation engine didn't modify the lease of the
2500 // client A.
2501 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2502 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"
, 2502, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2503 detailCompareLease(lease, from_mgr);
2504
2505 // Try doing the same thing, but this time do not request any specific
2506 // address. It should have the same effect.
2507 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2508 IOAddress("0.0.0.0"), false, false,
2509 "", false);
2510 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2511 AllocEngine::findReservation(ctx2);
2512 allocated_lease = engine.allocateLease4(ctx2);
2513 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"
, 2513, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2514 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"
, 2514, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2515
2516 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",
2516, gtest_ar.failure_message()) = ::testing::Message()
;
2517 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"
, 2517, gtest_ar.failure_message()) = ::testing::Message()
;
2518 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",
2518, gtest_ar.failure_message()) = ::testing::Message()
;
2519 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",
2519, gtest_ar.failure_message()) = ::testing::Message()
;
2520 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",
2520, gtest_ar.failure_message()) = ::testing::Message()
;
2521
2522 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"
, 2522, gtest_ar.failure_message()) = ::testing::Message()
;
2523 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"
, 2523, gtest_ar.failure_message()) = ::testing::Message()
;
2524 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"
, 2524, gtest_ar.failure_message()) = ::testing::Message()
;
2525 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"
, 2525, gtest_ar.failure_message()) = ::testing::Message()
;
2526 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"
, 2526, gtest_ar.failure_message()) = ::testing::Message()
;
2527
2528 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2529 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"
, 2529, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2530 detailCompareLease(lease, from_mgr);
2531}
2532
2533// This test checks that the behavior of the allocation engine in the following
2534// scenario:
2535// - Client A has a lease in the database.
2536// - Client B has a reservation for the address in use by client A.
2537// - Client B sends a DHCPDISCOVER.
2538// - Server determines that the reserved address is in use by a different client
2539// so it offers an address from the dynamic pool.
2540TEST_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"
, 2540), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2540), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2540), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test
::TestBody()
{
2541 // Create a reservation for the client B.
2542 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2543 Host::IDENT_HWADDR, subnet_->getID(),
2544 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2545 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2546 CfgMgr::instance().commit();
2547
2548 // Create a lease for the client A.
2549 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0,
2550 100, time(NULL__null), subnet_->getID(),
2551 false, false, ""));
2552 LeaseMgrFactory::instance().addLease(lease);
2553
2554 AllocEngine engine(0);
2555
2556 // Query allocation engine for the lease to be allocated to the client B.
2557 // The allocation engine is not able to allocate the lease to the client
2558 // B, because the address is in use by client A.
2559 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2560 IOAddress("192.0.2.123"), false, false,
2561 "", true);
2562 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2563 AllocEngine::findReservation(ctx1);
2564 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2565
2566 // The allocation engine should return a lease but for a different address
2567 // than requested because this address is in use.
2568 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"
, 2568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2569 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"
, 2569, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2570 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"
, 2570, gtest_ar.failure_message()) = ::testing::Message()
;
2571 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"
, 2571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)"
, "false", "true") .c_str()) = ::testing::Message()
;
2572
2573 // Do the same test. But, this time do not specify any address to be
2574 // allocated.
2575 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2576 IOAddress("0.0.0.0"), false, false,
2577 "", true);
2578 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2579 AllocEngine::findReservation(ctx2);
2580 allocated_lease = engine.allocateLease4(ctx2);
2581
2582 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"
, 2582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2583 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"
, 2583, gtest_ar.failure_message()) = ::testing::Message()
;
2584 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"
, 2584, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)"
, "false", "true") .c_str()) = ::testing::Message()
;
2585 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"
, 2585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2586}
2587
2588// This test checks that the behavior of the allocation engine in the following
2589// scenario:
2590// - Client A has an expired lease in the database.
2591// - Client B has a reservation for the address in use by client A.
2592// - Client B sends a DHCPDISCOVER.
2593// - Server determines that the reserved address is in use by a different client
2594// but it is expired and tries to reuse it and fails. It can not allocate a
2595// new lease either as if there is a limit in place.
2596TEST_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"
, 2596), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2596), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2596), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
>); void AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test
::TestBody()
{
2597 // Create a reservation for the client B.
2598 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2599 Host::IDENT_HWADDR, subnet_->getID(),
2600 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2601 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2602 CfgMgr::instance().commit();
2603
2604 // Create a lease for the client A (which is expired).
2605 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0,
2606 100, time(NULL__null) - 200, subnet_->getID(),
2607 false, false, ""));
2608 LeaseMgrFactory::instance().addLease(lease);
2609
2610 AllocEngine engine(0);
2611
2612 // Create callout which sets NEXT_STEP_SKIP flag.
2613 auto callback = [](CalloutHandle& callout_handle) -> int {
2614 callout_handle.setStatus(CalloutHandle::NEXT_STEP_SKIP);
2615
2616 return (0);
2617 };
2618
2619 // Register the callout for the "lease4_select" hook point.
2620 HooksManager::preCalloutsLibraryHandle().registerCallout("lease4_select", callback);
2621
2622 // Query allocation engine for the lease to be allocated to the client B.
2623 // The allocation engine is not able to allocate the lease to the client
2624 // B, because the address is in use by client A.
2625 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2626 IOAddress("192.0.2.123"), false, false,
2627 "", true);
2628
2629 ctx1.callout_handle_ = HooksManager::createCalloutHandle();
2630
2631 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2632 AllocEngine::findReservation(ctx1);
2633 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2634
2635 // The allocation engine should not return any address as it
2636 // can neither reuse the lease or allocate a new lease.
2637 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"
, 2637, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2638 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"
, 2638, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2639
2640 // Do the same test. But, this time do not specify any address to be
2641 // allocated.
2642 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2643 IOAddress("0.0.0.0"), false, false,
2644 "", true);
2645
2646 ctx2.callout_handle_ = HooksManager::createCalloutHandle();
2647
2648 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2649 AllocEngine::findReservation(ctx2);
2650 allocated_lease = engine.allocateLease4(ctx2);
2651
2652 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"
, 2652, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2653 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"
, 2653, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2654}
2655
2656// This test checks that the behavior of the allocation engine in the following
2657// scenario:
2658// - Client has a reservation.
2659// - Client has a lease in the database for a different address than reserved.
2660// - Client sends a DHCPREQUEST and asks for a different address than reserved,
2661// and different than it has in a database.
2662// - Server doesn't allocate the reserved address to the client because the
2663// client asked for the different address.
2664//
2665// Note that in this case the client should get the DHCPNAK and should fall back
2666// to the DHCPDISCOVER.
2667TEST_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"
, 2667), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2667), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2667), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test
::TestBody()
{
2668 // Create a reservation for the client.
2669 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2670 Host::IDENT_HWADDR, subnet_->getID(),
2671 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2672 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2673 CfgMgr::instance().commit();
2674
2675 // Create a lease for the client for a different address than reserved.
2676 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, ClientIdPtr(),
2677 100, time(NULL__null), subnet_->getID(),
2678 false, false, ""));
2679 LeaseMgrFactory::instance().addLease(lease);
2680
2681 AllocEngine engine(0);
2682
2683 // Try to allocate a lease and specify a different address than reserved
2684 // and different from the one that client is currently using.
2685 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2686 IOAddress("192.0.2.102"), false, false,
2687 "", false);
2688 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2689 AllocEngine::findReservation(ctx1);
2690 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2691 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"
, 2691, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2692 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"
, 2692, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2693
2694 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",
2694, gtest_ar.failure_message()) = ::testing::Message()
;
2695 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"
, 2695, gtest_ar.failure_message()) = ::testing::Message()
;
2696 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",
2696, gtest_ar.failure_message()) = ::testing::Message()
;
2697 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",
2697, gtest_ar.failure_message()) = ::testing::Message()
;
2698 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",
2698, gtest_ar.failure_message()) = ::testing::Message()
;
2699
2700 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"
, 2700, gtest_ar.failure_message()) = ::testing::Message()
;
2701 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"
, 2701, gtest_ar.failure_message()) = ::testing::Message()
;
2702 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"
, 2702, gtest_ar.failure_message()) = ::testing::Message()
;
2703 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"
, 2703, gtest_ar.failure_message()) = ::testing::Message()
;
2704 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"
, 2704, gtest_ar.failure_message()) = ::testing::Message()
;
2705
2706 // Repeat the test, but this time ask for the address that the client
2707 // has allocated.
2708 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2709 IOAddress("192.0.2.101"), false, false,
2710 "", false);
2711 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2712 AllocEngine::findReservation(ctx2);
2713 allocated_lease = engine.allocateLease4(ctx2);
2714 // The client has reservation so the server wants to allocate a
2715 // reserved address and doesn't want to renew the address that the
2716 // client is currently using. This is equivalent of the case when
2717 // the client tries to renew the lease but there is a new reservation
2718 // for this client. The server doesn't allow for the renewal and
2719 // responds with DHCPNAK to force the client to return to the
2720 // DHCP server discovery.
2721 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"
, 2721, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
2722 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"
, 2722, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2723
2724 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",
2724, gtest_ar.failure_message()) = ::testing::Message()
;
2725 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"
, 2725, gtest_ar.failure_message()) = ::testing::Message()
;
2726 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",
2726, gtest_ar.failure_message()) = ::testing::Message()
;
2727 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",
2727, gtest_ar.failure_message()) = ::testing::Message()
;
2728 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",
2728, gtest_ar.failure_message()) = ::testing::Message()
;
2729
2730 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"
, 2730, gtest_ar.failure_message()) = ::testing::Message()
;
2731 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"
, 2731, gtest_ar.failure_message()) = ::testing::Message()
;
2732 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"
, 2732, gtest_ar.failure_message()) = ::testing::Message()
;
2733 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"
, 2733, gtest_ar.failure_message()) = ::testing::Message()
;
2734 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"
, 2734, gtest_ar.failure_message()) = ::testing::Message()
;
2735}
2736
2737// This test checks that the behavior of the allocation engine in the following
2738// scenario:
2739// - Client has a lease in the database.
2740// - Client has a reservation for a different address than the one for which it
2741// has a lease.
2742// - Client sends a DHCPDISCOVER and asks for a different address than reserved
2743// and different from which it has a lease for.
2744// - Server ignores the client's hint and offers a reserved address.
2745TEST_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"
, 2745), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2745), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2745), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test
::TestBody()
{
2746 // Create a reservation for the client.
2747 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2748 Host::IDENT_HWADDR, subnet_->getID(),
2749 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2750 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2751 CfgMgr::instance().commit();
2752
2753 // Create a lease for a different address than reserved.
2754 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2755 &clientid_->getClientId()[0],
2756 clientid_->getClientId().size(),
2757 100, time(NULL__null), subnet_->getID(),
2758 false, false, ""));
2759 LeaseMgrFactory::instance().addLease(lease);
2760
2761 AllocEngine engine(0);
2762
2763 // Try to allocate a lease and use a completely different address
2764 // as a hint.
2765 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
2766 IOAddress("192.0.2.102"), false, false,
2767 "", true);
2768 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2769 AllocEngine::findReservation(ctx1);
2770 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
2771
2772 // Server should offer a lease for a reserved address.
2773 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"
, 2773, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2774 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"
, 2774, gtest_ar.failure_message()) = ::testing::Message()
;
2775
2776 // The lease should not be allocated until the client sends a DHCPREQUEST.
2777 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",
2777, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)"
, "true", "false") .c_str()) = ::testing::Message()
;
2778
2779 // Old lease should contain the currently used lease.
2780 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"
, 2780, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2781 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"
, 2781, gtest_ar.failure_message()) = ::testing::Message()
;
2782
2783 // Repeat the test but this time ask for the address for which the
2784 // client has a lease.
2785 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2786 IOAddress("192.0.2.101"), false, false,
2787 "", true);
2788 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2789 AllocEngine::findReservation(ctx2);
2790 allocated_lease = engine.allocateLease4(ctx2);
2791
2792 // The server should offer the lease, but not for the address that
2793 // the client requested. The server should offer a reserved address.
2794 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"
, 2794, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2795 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"
, 2795, gtest_ar.failure_message()) = ::testing::Message()
;
2796
2797 // Old lease should contain the currently used lease.
2798 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"
, 2798, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
2799 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"
, 2799, gtest_ar.failure_message()) = ::testing::Message()
;
2800}
2801
2802// This test checks that the behavior of the allocation engine in the following
2803// scenario:
2804// - Client has a reservation.
2805// - Client has a lease for a different address than reserved.
2806// - Client sends a DHCPREQUEST to allocate a lease.
2807// - The server determines that the client has a reservation for the
2808// different address than it is currently using and should assign
2809// a reserved address and remove the previous lease.
2810TEST_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"
, 2810), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2810), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2810), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test
::TestBody()
{
2811 // Create a reservation.
2812 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2813 Host::IDENT_HWADDR, subnet_->getID(),
2814 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2815 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2816 CfgMgr::instance().commit();
2817
2818 // Create a lease for a different address than reserved.
2819 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2820 &clientid_->getClientId()[0],
2821 clientid_->getClientId().size(),
2822 100, time(NULL__null), subnet_->getID(),
2823 false, false, ""));
2824 LeaseMgrFactory::instance().addLease(lease);
2825
2826 AllocEngine engine(0);
2827
2828 // Try to allocate a lease with providing no hint.
2829 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2830 IOAddress("0.0.0.0"), false, false,
2831 "", false);
2832 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2833 AllocEngine::findReservation(ctx);
2834 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
2835
2836 // The reserved address should be allocated.
2837 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"
, 2837, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2838 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"
, 2838, gtest_ar.failure_message()) = ::testing::Message()
;
2839
2840 // The previous lease should be removed.
2841 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"
, 2841, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
2842
2843 // Make sure that the allocated lease is committed in the lease database.
2844 Lease4Ptr from_mgr =
2845 LeaseMgrFactory::instance().getLease4(allocated_lease->addr_);
2846 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"
, 2846, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2847 detailCompareLease(allocated_lease, from_mgr);
2848
2849 // Old lease should be returned.
2850 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"
, 2850, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2851 detailCompareLease(lease, ctx.old_lease_);
2852}
2853
2854// This test checks that the behavior of the allocation engine in the following
2855// scenario:
2856// - Client has a reservation.
2857// - Client has a lease for a different address than reserved.
2858// - Client sends a DHCPDISCOVER with no hint.
2859// - Server determines that there is a reservation for the client and that
2860// the reserved address should be offered when the client sends a
2861// DHCPDISCOVER.
2862TEST_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"
, 2862), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2862), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2862), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test
::TestBody()
{
2863 // Create a reservation.
2864 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
2865 Host::IDENT_HWADDR, subnet_->getID(),
2866 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
2867 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2868 CfgMgr::instance().commit();
2869
2870 // Create a lease for a different address than reserved.
2871 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2872 &clientid_->getClientId()[0],
2873 clientid_->getClientId().size(),
2874 100, time(NULL__null), subnet_->getID(),
2875 false, false, ""));
2876 LeaseMgrFactory::instance().addLease(lease);
2877
2878 AllocEngine engine(0);
2879
2880 // Query the allocation engine for the lease to be allocated for the
2881 // client.
2882 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
2883 IOAddress("0.0.0.0"), false, false,
2884 "", true);
2885 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
2886 AllocEngine::findReservation(ctx);
2887 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
2888
2889 // The server should offer the reserved address.
2890 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"
, 2890, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
2891 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"
, 2891, gtest_ar.failure_message()) = ::testing::Message()
;
2892
2893 // The lease should not be committed to the lease database until the
2894 // client sends a DHCPREQUEST.
2895 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",
2895, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)"
, "true", "false") .c_str()) = ::testing::Message()
;
2896
2897 // The old lease should reflect what is in the database.
2898 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"
, 2898, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message
()
;
2899 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
2900 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"
, 2900, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2901 detailCompareLease(lease, from_mgr);
2902}
2903
2904// This test checks that the behavior of the allocation engine in the following
2905// scenario:
2906// - Client A has a lease for the address.
2907// - Client B has a reservation for the same address that the Client A is using.
2908// - Client B requests allocation of the reserved address.
2909// - Server returns DHCPNAK to the client to indicate that the requested address
2910// can't be allocated.
2911// - Client A renews the lease.
2912// - Server determines that the lease that the Client A is trying to renew
2913// is for the address reserved for Client B. Therefore, the server returns
2914// DHCPNAK to force the client to return to the server discovery.
2915// - The Client A sends DHCPDISCOVER.
2916// - The server offers an address to the Client A, which is different than
2917// the address reserved for Client B.
2918// - The Client A requests allocation of the offered address.
2919// - The server allocates the new address to Client A.
2920// - The Client B sends DHCPDISCOVER to the server.
2921// - The server offers a reserved address to the Client B.
2922// - The Client B requests the offered address.
2923// - The server allocates the reserved address to the Client B.
2924TEST_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"
, 2924), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2924), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 2924), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressConflictResolution_Test
>); void AllocEngine4Test_reservedAddressConflictResolution_Test
::TestBody()
{
2925 // Create a reservation for client B.
2926 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(),
2927 Host::IDENT_HWADDR, subnet_->getID(),
2928 SUBNET_ID_UNUSED, IOAddress("192.0.2.101")));
2929 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
2930 CfgMgr::instance().commit();
2931
2932 // Create a lease for Client A.
2933 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
2934 &clientid_->getClientId()[0],
2935 clientid_->getClientId().size(),
2936 100, time(NULL__null), subnet_->getID(),
2937 false, false, ""));
2938 LeaseMgrFactory::instance().addLease(lease);
2939
2940 AllocEngine engine(0);
2941
2942 // Client B sends a DHCPREQUEST to allocate a reserved lease. The
2943 // allocation engine can't allocate a reserved lease for this client
2944 // because this specific address is in use by the Client A.
2945 AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr2_,
2946 IOAddress("192.0.2.101"), false, false,
2947 "", false);
2948 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2949 AllocEngine::findReservation(ctx1);
2950 Lease4Ptr offered_lease = engine.allocateLease4(ctx1);
2951 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"
, 2951, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "offered_lease", "true", "false") .c_str()) = ::testing::Message
()
;
2952
2953 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",
2953, gtest_ar.failure_message()) = ::testing::Message()
;
2954 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"
, 2954, gtest_ar.failure_message()) = ::testing::Message()
;
2955 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",
2955, gtest_ar.failure_message()) = ::testing::Message()
;
2956 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",
2956, gtest_ar.failure_message()) = ::testing::Message()
;
2957 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",
2957, gtest_ar.failure_message()) = ::testing::Message()
;
2958
2959 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"
, 2959, gtest_ar.failure_message()) = ::testing::Message()
;
2960 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"
, 2960, gtest_ar.failure_message()) = ::testing::Message()
;
2961 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"
, 2961, gtest_ar.failure_message()) = ::testing::Message()
;
2962 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"
, 2962, gtest_ar.failure_message()) = ::testing::Message()
;
2963 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"
, 2963, gtest_ar.failure_message()) = ::testing::Message()
;
2964
2965 // Client A tries to renew the lease. The renewal should fail because
2966 // server detects that Client A doesn't have reservation for this
2967 // address.
2968 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
2969 IOAddress("192.0.2.101"), false, false,
2970 "", false);
2971 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2972 AllocEngine::findReservation(ctx2);
2973 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"
, 2973, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine.allocateLease4(ctx2)", "true", "false") .c_str()) =
::testing::Message()
;
2974 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"
, 2974, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx2.old_lease_", "true", "false") .c_str()) = ::testing::
Message()
;
2975
2976 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",
2976, gtest_ar.failure_message()) = ::testing::Message()
;
2977 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"
, 2977, gtest_ar.failure_message()) = ::testing::Message()
;
2978 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",
2978, gtest_ar.failure_message()) = ::testing::Message()
;
2979 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",
2979, gtest_ar.failure_message()) = ::testing::Message()
;
2980 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",
2980, gtest_ar.failure_message()) = ::testing::Message()
;
2981
2982 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"
, 2982, gtest_ar.failure_message()) = ::testing::Message()
;
2983 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"
, 2983, gtest_ar.failure_message()) = ::testing::Message()
;
2984 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"
, 2984, gtest_ar.failure_message()) = ::testing::Message()
;
2985 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"
, 2985, gtest_ar.failure_message()) = ::testing::Message()
;
2986 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"
, 2986, gtest_ar.failure_message()) = ::testing::Message()
;
2987
2988 // Client A returns to DHCPDISCOVER and should be offered a lease.
2989 // The offered lease address must be different than the one the
2990 // Client B has reservation for.
2991 AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_,
2992 IOAddress("192.0.2.101"), false, false,
2993 "", true);
2994 ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234));
2995 AllocEngine::findReservation(ctx3);
2996 offered_lease = engine.allocateLease4(ctx3);
2997 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"
, 2997, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "offered_lease", "false", "true") .c_str()) = ::testing::Message
()
;
2998 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"
, 2998, gtest_ar.failure_message()) = ::testing::Message()
;
2999
3000 // Client A tries to acquire the lease. It should succeed. At this point
3001 // the previous lease should be released and become available for the
3002 // Client B.
3003 AllocEngine::ClientContext4 ctx4(subnet_, clientid_, hwaddr_,
3004 offered_lease->addr_, false, false,
3005 "", false);
3006 ctx4.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3007 AllocEngine::findReservation(ctx4);
3008 Lease4Ptr allocated_lease = engine.allocateLease4(ctx4);
3009
3010 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"
, 3010, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3011 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"
, 3011, gtest_ar.failure_message()) = ::testing::Message()
;
3012
3013 // Client B tries to get the lease again. It should be offered
3014 // a reserved lease.
3015 AllocEngine::ClientContext4 ctx5(subnet_, ClientIdPtr(), hwaddr2_,
3016 IOAddress("0.0.0.0"), false, false,
3017 "", true);
3018 ctx5.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3019 AllocEngine::findReservation(ctx5);
3020 offered_lease = engine.allocateLease4(ctx5);
3021
3022 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"
, 3022, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "offered_lease", "false", "true") .c_str()) = ::testing::Message
()
;
3023 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"
, 3023, gtest_ar.failure_message()) = ::testing::Message()
;
3024
3025 // Client B requests allocation of the lease and it should succeed.
3026 AllocEngine::ClientContext4 ctx6(subnet_, ClientIdPtr(), hwaddr2_,
3027 offered_lease->addr_, false, false,
3028 "", false);
3029 ctx6.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3030 allocated_lease = engine.allocateLease4(ctx6);
3031
3032 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"
, 3032, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3033 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"
, 3033, gtest_ar.failure_message()) = ::testing::Message()
;
3034}
3035
3036// This test checks that the address is not assigned from the dynamic
3037// pool if it has been reserved for another client.
3038TEST_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"
, 3038), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3038), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3038), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressVsDynamicPool_Test
>); void AllocEngine4Test_reservedAddressVsDynamicPool_Test
::TestBody()
{
3039 // Create a reservation for the client.
3040 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3041 Host::IDENT_HWADDR, subnet_->getID(),
3042 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3043 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3044 CfgMgr::instance().commit();
3045
3046 AllocEngine engine(0);
3047
3048 // Different client tries to allocate a lease. Note, that we're using
3049 // an iterative allocator which would pick the first address from the
3050 // dynamic pool, i.e. 192.0.2.100. This address is reserved so we expect
3051 // that a different address will be allocated.
3052 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
3053 IOAddress("0.0.0.0"), false, false,
3054 "", false);
3055 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3056 AllocEngine::findReservation(ctx);
3057 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
3058
3059 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"
, 3059, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3060 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"
, 3060, gtest_ar.failure_message()) = ::testing::Message()
;
3061
3062 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_);
3063 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"
, 3063, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3064 detailCompareLease(allocated_lease, from_mgr);
3065}
3066
3067// This test checks that the client requesting an address which is
3068// reserved for another client will get no lease or a different
3069// address will be assigned if the client is sending a DHCPDISCOVER.
3070TEST_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"
, 3070), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3070), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3070), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
>); void AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test
::TestBody()
{
3071 // Create a reservation for the client.
3072 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3073 Host::IDENT_HWADDR, subnet_->getID(),
3074 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3075 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3076 CfgMgr::instance().commit();
3077
3078 AllocEngine engine(0);
3079
3080 // Different client is requesting this address.
3081 AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_,
3082 IOAddress("192.0.2.100"), false, false,
3083 "", false);
3084 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3085 AllocEngine::findReservation(ctx1);
3086 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
3087
3088 // The client should get no lease (DHCPNAK).
3089 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"
, 3089, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
3090
3091 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",
3091, gtest_ar.failure_message()) = ::testing::Message()
;
3092 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"
, 3092, gtest_ar.failure_message()) = ::testing::Message()
;
3093 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",
3093, gtest_ar.failure_message()) = ::testing::Message()
;
3094 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",
3094, gtest_ar.failure_message()) = ::testing::Message()
;
3095 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",
3095, gtest_ar.failure_message()) = ::testing::Message()
;
3096
3097 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"
, 3097, gtest_ar.failure_message()) = ::testing::Message()
;
3098 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"
, 3098, gtest_ar.failure_message()) = ::testing::Message()
;
3099 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"
, 3099, gtest_ar.failure_message()) = ::testing::Message()
;
3100 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"
, 3100, gtest_ar.failure_message()) = ::testing::Message()
;
3101 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"
, 3101, gtest_ar.failure_message()) = ::testing::Message()
;
3102
3103 // The same client should get a different lease than requested if
3104 // if is sending a DHCPDISCOVER (fake allocation is true).
3105 AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_,
3106 IOAddress("192.0.2.100"), false, false,
3107 "", true);
3108 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3109 AllocEngine::findReservation(ctx2);
3110 allocated_lease = engine.allocateLease4(ctx2);
3111
3112 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"
, 3112, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3113 // Make sure the lease obtained is for a different address.
3114 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"
, 3114, gtest_ar.failure_message()) = ::testing::Message()
;
3115}
3116
3117// This test checks that the allocation engine refuses to allocate an
3118// address when the pool is exhausted, and the only available
3119// address is reserved for a different client.
3120TEST_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"
, 3120), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3120), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3120), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressShortPool_Test
>); void AllocEngine4Test_reservedAddressShortPool_Test::TestBody
()
{
3121 AllocEngine engine(0);
3122
3123 // Create short pool with only one address.
3124 initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100"));
3125 // Reserve the address for a different client.
3126 HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(),
3127 Host::IDENT_HWADDR, subnet_->getID(),
3128 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3129 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3130 CfgMgr::instance().commit();
3131
3132 // Allocation engine should determine that the available address is
3133 // reserved for someone else and not allocate it.
3134 AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_,
3135 IOAddress("0.0.0.0"), false, false,
3136 "", false);
3137 ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3138 AllocEngine::findReservation(ctx1);
3139 Lease4Ptr allocated_lease = engine.allocateLease4(ctx1);
3140
3141 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"
, 3141, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "true", "false") .c_str()) = ::testing::
Message()
;
3142
3143 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",
3143, gtest_ar.failure_message()) = ::testing::Message()
;
3144 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"
, 3144, gtest_ar.failure_message()) = ::testing::Message()
;
3145 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",
3145, gtest_ar.failure_message()) = ::testing::Message()
;
3146 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",
3146, gtest_ar.failure_message()) = ::testing::Message()
;
3147 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",
3147, gtest_ar.failure_message()) = ::testing::Message()
;
3148
3149 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"
, 3149, gtest_ar.failure_message()) = ::testing::Message()
;
3150 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"
, 3150, gtest_ar.failure_message()) = ::testing::Message()
;
3151 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"
, 3151, gtest_ar.failure_message()) = ::testing::Message()
;
3152 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"
, 3152, gtest_ar.failure_message()) = ::testing::Message()
;
3153 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"
, 3153, gtest_ar.failure_message()) = ::testing::Message()
;
3154
3155 // Now, let's remove the reservation.
3156 initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100"));
3157 CfgMgr::instance().commit();
3158
3159 // Address should be successfully allocated.
3160 AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_,
3161 IOAddress("0.0.0.0"), false, false,
3162 "", false);
3163 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3164 AllocEngine::findReservation(ctx2);
3165 allocated_lease = engine.allocateLease4(ctx2);
3166
3167 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"
, 3167, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3168 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"
, 3168, gtest_ar.failure_message()) = ::testing::Message()
;
3169}
3170
3171// This test checks that the AllocEngine allocates an address from the
3172// dynamic pool if the client's reservation is made for a hostname but
3173// not for an address.
3174TEST_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"
, 3174), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3174), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3174), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedHostname_Test
>); void AllocEngine4Test_reservedHostname_Test::TestBody(
)
{
3175 AllocEngine engine(0);
3176
3177 // Create a reservation for a hostname. Address is set to 0 which
3178 // indicates that there is no reservation.
3179 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3180 Host::IDENT_HWADDR, subnet_->getID(),
3181 SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(),
3182 "foo.example.org"));
3183 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3184 CfgMgr::instance().commit();
3185
3186 // Try to allocate a lease.
3187 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
3188 IOAddress("192.0.2.109"), false, false,
3189 "foo.example.org", true);
3190 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3191 AllocEngine::findReservation(ctx);
3192 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
3193 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"
, 3193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3194 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"
, 3194, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease->addr_.isV4Zero()", "true", "false") .c_str
()) = ::testing::Message()
;
3195 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"
, 3195, gtest_ar.failure_message()) = ::testing::Message()
;
3196
3197 ctx.requested_address_ = allocated_lease->addr_;
3198 ctx.fake_allocation_ = false;
3199 allocated_lease = engine.allocateLease4(ctx);
3200 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"
, 3200, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3201 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"
, 3201, gtest_ar.failure_message()) = ::testing::Message()
;
3202}
3203
3204// This test checks that the AllocEngine::findReservation method finds
3205// and returns host reservation for the DHCPv4 client using the data from
3206// the client context. If the host reservation can't be found, it sets
3207// the value of NULL in the host_ field of the client context.
3208TEST_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", 3208
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3208), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3208), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_findReservation_Test
>); void AllocEngine4Test_findReservation_Test::TestBody()
{
3209 // Create the instance of the allocation engine.
3210 AllocEngine engine(0);
3211
3212 // Context is required to call the AllocEngine::findReservation.
3213 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3214 IOAddress("0.0.0.0"), false, false,
3215 "", false);
3216 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3217 ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_);
3218 ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getClientId());
3219
3220 // There is no reservation in the database so no host should be returned.
3221 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_3221
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3221
; } } else gtest_label_testnothrow_3221 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3221, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3222 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"
, 3222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3223
3224 // Create a reservation for the client.
3225 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3226 Host::IDENT_HWADDR, subnet_->getID(),
3227 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3228 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3229 CfgMgr::instance().commit();
3230
3231 // This time the reservation should be returned.
3232 ctx.hosts_.clear();
3233 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_3233
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3233
; } } else gtest_label_testnothrow_3233 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3233, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3234 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"
, 3234, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3235 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"
, 3235, gtest_ar.failure_message()) = ::testing::Message()
;
3236
3237 // It shouldn't be returned when reservations-in-subnet is disabled.
3238 subnet_->setReservationsInSubnet(false);
3239 ctx.hosts_.clear();
3240 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_3240
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3240
; } } else gtest_label_testnothrow_3240 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3240, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3241 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"
, 3241, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3242
3243 // Check the reservations-in-subnet and reservations-out-of-pool flags.
3244 subnet_->setReservationsInSubnet(true);
3245 subnet_->setReservationsOutOfPool(true);
3246 ctx.hosts_.clear();
3247 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_3247
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3247
; } } else gtest_label_testnothrow_3247 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3247, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3248 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"
, 3248, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3249 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"
, 3249, gtest_ar.failure_message()) = ::testing::Message()
;
3250
3251 // This time use the client identifier to search for the host.
3252 host.reset(new Host(&clientid_->getClientId()[0],
3253 clientid_->getClientId().size(),
3254 Host::IDENT_DUID, subnet_->getID(),
3255 SUBNET_ID_UNUSED, IOAddress("192.0.2.101")));
3256 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3257 CfgMgr::instance().commit();
3258
3259 ctx.hosts_.clear();
3260 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_3260
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3260
; } } else gtest_label_testnothrow_3260 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3260, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3261 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"
, 3261, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3262 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"
, 3262, gtest_ar.failure_message()) = ::testing::Message()
;
3263
3264 // Remove the subnet. Subnet id is required to find host reservations, so
3265 // if it is set to NULL, no reservation should be returned
3266 ctx.subnet_.reset();
3267 ctx.hosts_.clear();
3268 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_3268
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3268
; } } else gtest_label_testnothrow_3268 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3268, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3269 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"
, 3269, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3270
3271 // The same if there is a mismatch of the subnet id between the reservation
3272 // and the context.
3273 ctx.subnet_ = subnet_;
3274 host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3275 Host::IDENT_HWADDR, subnet_->getID() + 1,
3276 SUBNET_ID_UNUSED, IOAddress("192.0.2.100")));
3277 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3278 CfgMgr::instance().commit();
3279
3280 ctx.hosts_.clear();
3281 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_3281
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3281
; } } else gtest_label_testnothrow_3281 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3281, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3282 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"
, 3282, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "true", "false") .c_str()) = ::testing
::Message()
;
3283}
3284
3285// This test checks if the simple IPv4 allocation can succeed and that
3286// statistic for allocated addresses is increased appropriately.
3287TEST_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"
, 3287), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3287), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3287), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4Stats_Test
>); void AllocEngine4Test_simpleAlloc4Stats_Test::TestBody
()
{
3288 boost::scoped_ptr<AllocEngine> engine;
3289 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_3289
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3289
; } } else gtest_label_testnothrow_3289 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3289, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3290 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"
, 3290, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
3291
3292 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
3293 false, true, "somehost.example.com.", false);
3294 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3295
3296 // Let's pretend 100 addresses were allocated already
3297 string name = StatsMgr::generateName("subnet", subnet_->getID(),
3298 "assigned-addresses");
3299 StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
3300 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
3301 subnet_->getID());
3302
3303 int64_t glbl_assigned = getStatistics("assigned-addresses");
3304 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
3305
3306 Lease4Ptr lease = engine->allocateLease4(ctx);
3307 // The new lease has been allocated, so the old lease should not exist.
3308 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"
, 3308, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3309
3310 // Check that we got a lease
3311 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"
, 3311, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3312
3313 // The statistic should be there and it should be increased by 1 (to 101).
3314 ObservationPtr stat = StatsMgr::instance().getObservation(name);
3315 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",
3315, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "stat", "false", "true") .c_str()) = ::testing::Message()
;
3316 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"
, 3316, gtest_ar.failure_message()) = ::testing::Message()
;
3317 cumulative += 1;
3318 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"
, 3319, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
3319 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"
, 3319, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
3320 glbl_assigned += 1;
3321 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"
, 3321, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
3322 glbl_cumulative += 1;
3323 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"
, 3323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
3324}
3325
3326// This test checks if the fake allocation (for DHCPDISCOVER) can succeed
3327// and that it doesn't increase allocated-addresses statistic.
3328TEST_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", 3328
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3328), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3328), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4Stat_Test
>); void AllocEngine4Test_fakeAlloc4Stat_Test::TestBody()
{
3329 boost::scoped_ptr<AllocEngine> engine;
3330 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_3330
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3330
; } } else gtest_label_testnothrow_3330 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3330, ("Expected: " "engine.reset(new AllocEngine(100))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3331 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"
, 3331, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
3332
3333 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3334 IOAddress("0.0.0.0"), false, true,
3335 "host.example.com.", true);
3336 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3337
3338 // Let's pretend 100 addresses were allocated already
3339 string name = StatsMgr::generateName("subnet", subnet_->getID(),
3340 "assigned-addresses");
3341 StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
3342 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
3343 subnet_->getID());
3344
3345 int64_t glbl_assigned = getStatistics("assigned-addresses");
3346 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
3347
3348 Lease4Ptr lease = engine->allocateLease4(ctx);
3349
3350 // The new lease has been allocated, so the old lease should not exist.
3351 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"
, 3351, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3352
3353 // Check that we got a lease
3354 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"
, 3354, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3355
3356 // The statistic should be there and it should not be increased
3357 // (should be still equal to 100).
3358 ObservationPtr stat = StatsMgr::instance().getObservation(name);
3359 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",
3359, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "stat", "false", "true") .c_str()) = ::testing::Message()
;
3360 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"
, 3360, gtest_ar.failure_message()) = ::testing::Message()
;
3361 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"
, 3362, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
3362 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"
, 3362, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
3363 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"
, 3363, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
3364 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"
, 3364, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
3365}
3366
3367// This test checks that the allocated-addresses statistic is decreased when
3368// the client has a lease and a reservation for a different address is
3369// available.
3370TEST_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"
, 3370), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3370), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3370), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseStat_Test
>); void AllocEngine4Test_reservedAddressExistingLeaseStat_Test
::TestBody()
{
3371 // Create the reservation for the client.
3372 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3373 Host::IDENT_HWADDR, subnet_->getID(),
3374 SUBNET_ID_UNUSED, IOAddress("192.0.2.123")));
3375 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3376 CfgMgr::instance().commit();
3377
3378 // Create a lease for the client with a different address than the reserved
3379 // one.
3380 Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_,
3381 &clientid_->getClientId()[0],
3382 clientid_->getClientId().size(),
3383 100, time(NULL__null), subnet_->getID(),
3384 false, false, ""));
3385 LeaseMgrFactory::instance().addLease(lease);
3386
3387 AllocEngine engine(100);
3388
3389 // Let's pretend 100 addresses were allocated already
3390 string name = StatsMgr::generateName("subnet", subnet_->getID(),
3391 "assigned-addresses");
3392 StatsMgr::instance().addValue(name, static_cast<int64_t>(100));
3393 int64_t cumulative = getStatistics("cumulative-assigned-addresses",
3394 subnet_->getID());
3395
3396 int64_t glbl_assigned = getStatistics("assigned-addresses");
3397 int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses");
3398
3399 // Request allocation of the reserved address.
3400 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3401 IOAddress("192.0.2.123"), false, false,
3402 "", false);
3403 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3404 AllocEngine::findReservation(ctx);
3405
3406 Lease4Ptr allocated_lease = engine.allocateLease4(ctx);
3407
3408 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"
, 3408, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "allocated_lease", "false", "true") .c_str()) = ::testing::
Message()
;
3409
3410 // The statistic should be still at 100. Note that it was decreased
3411 // (because old lease was removed), but also increased (because the
3412 // new lease was immediately allocated).
3413 ObservationPtr stat = StatsMgr::instance().getObservation(name);
3414 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",
3414, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "stat", "false", "true") .c_str()) = ::testing::Message()
;
3415 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"
, 3415, gtest_ar.failure_message()) = ::testing::Message()
;
3416 cumulative += 1;
3417 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"
, 3418, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
3418 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"
, 3418, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())"
, "false", "true") .c_str()) = ::testing::Message()
;
3419 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"
, 3419, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"assigned-addresses\", glbl_assigned)", "false"
, "true") .c_str()) = ::testing::Message()
;
3420 glbl_cumulative += 1;
3421 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"
, 3421, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)"
, "false", "true") .c_str()) = ::testing::Message()
;
3422 // Lets' double check that the actual allocation took place.
3423 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"
, 3423, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.fake_allocation_", "true", "false") .c_str()) = ::testing
::Message()
;
3424}
3425
3426// This test checks the behavior of the allocation engine in the following
3427// scenario:
3428// - Client has no lease in the database.
3429// - Client has a global reservation outside of the subnet.
3430// - Client sends DISCOVER
3431// - Client is allocated an address within the subnet.
3432// - Lease is not added to the lease database
3433TEST_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"
, 3433), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3433), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3433), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
>); void AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test
::TestBody()
{
3434 // Create reservation for the client.
3435 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3436 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3437 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3438 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3439 CfgMgr::instance().commit();
3440
3441 AllocEngine engine(0);
3442
3443 subnet_->setReservationsGlobal(true);
3444
3445 // Query allocation engine for the lease to be assigned to this
3446 // client without specifying the address to be assigned.
3447 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3448 IOAddress("0.0.0.0"), false, false,
3449 "", true);
3450 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3451
3452 // Look up the host.
3453 AllocEngine::findReservation(ctx);
3454
3455 // We should have the correct current host
3456 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"
, 3456, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3457 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"
, 3457, gtest_ar.failure_message()) = ::testing::Message()
;
3458 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"
, 3458, gtest_ar.failure_message()) = ::testing::Message()
;
3459
3460 // We should allocate an address in the subnet
3461 Lease4Ptr lease = engine.allocateLease4(ctx);
3462 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"
, 3462, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3463 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"
, 3463, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
3464
3465 // This is a "fake" allocation so the returned lease should not be committed
3466 // to the lease database.
3467 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"
, 3467, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3468
3469 // Client had no lease in the database, so the old lease returned should
3470 // be NULL.
3471 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"
, 3471, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3472}
3473
3474// This test checks the behavior of the allocation engine in the following
3475// scenario:
3476// - Client has no lease in the database.
3477// - Client has a global reservation matching the current subnet.
3478// - Client sends DISCOVER
3479// - Client is allocated the reserved address.
3480// - Lease is not added to the lease database
3481TEST_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"
, 3481), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3481), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3481), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
>); void AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test
::TestBody()
{
3482 // Create reservation for the client.
3483 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3484 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3485 SUBNET_ID_UNUSED, IOAddress("192.0.2.10")));
3486 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3487 CfgMgr::instance().commit();
3488
3489 AllocEngine engine(0);
3490
3491 subnet_->setReservationsGlobal(true);
3492
3493 // Query allocation engine for the lease to be assigned to this
3494 // client without specifying the address to be assigned.
3495 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3496 IOAddress("0.0.0.0"), false, false,
3497 "", true);
3498 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3499
3500 // Look up the host.
3501 AllocEngine::findReservation(ctx);
3502
3503 // We should have the correct current host
3504 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"
, 3504, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3505 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"
, 3505, gtest_ar.failure_message()) = ::testing::Message()
;
3506 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"
, 3506, gtest_ar.failure_message()) = ::testing::Message()
;
3507
3508 // We should allocate the reserved address.
3509 Lease4Ptr lease = engine.allocateLease4(ctx);
3510 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"
, 3510, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3511 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"
, 3511, gtest_ar.failure_message()) = ::testing::Message()
;
3512
3513 // This is a "fake" allocation so the returned lease should not be committed
3514 // to the lease database.
3515 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"
, 3515, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3516
3517 // Client had no lease in the database, so the old lease returned should
3518 // be NULL.
3519 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"
, 3519, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3520}
3521
3522// This test checks the behavior of the allocation engine in the following
3523// scenario:
3524// - Client has no lease in the database.
3525// - Client has a global reservation outside the current subnet.
3526// - Client sends REQUEST
3527// - Client is allocated a dynamic address.
3528// - Lease is added to the lease database
3529TEST_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"
, 3529), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3529), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3529), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
>); void AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test
::TestBody()
{
3530 // Create reservation for the client.
3531 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3532 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3533 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3534 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3535 CfgMgr::instance().commit();
3536
3537 AllocEngine engine(0);
3538
3539 subnet_->setReservationsGlobal(true);
3540
3541 // Query allocation engine for the lease to be assigned to this
3542 // client without specifying the address to be assigned.
3543 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3544 IOAddress("0.0.0.0"), false, false,
3545 "", false);
3546 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3547
3548 // Look up the host.
3549 AllocEngine::findReservation(ctx);
3550
3551 // We should have the correct current host
3552 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"
, 3552, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3553 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"
, 3553, gtest_ar.failure_message()) = ::testing::Message()
;
3554 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"
, 3554, gtest_ar.failure_message()) = ::testing::Message()
;
3555
3556 // We should allocate the reserved address.
3557 Lease4Ptr lease = engine.allocateLease4(ctx);
3558 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"
, 3558, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3559 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"
, 3559, gtest_ar.failure_message()) = ::testing::Message()
;
3560 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"
, 3560, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
3561
3562 // Check that the lease is indeed in LeaseMgr
3563 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3564 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"
, 3564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3565
3566 // Now check that the lease in LeaseMgr has the same parameters
3567 detailCompareLease(lease, from_mgr);
3568
3569 // Client had no lease in the database, so the old lease returned should
3570 // be NULL.
3571 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"
, 3571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3572}
3573
3574// This test checks the behavior of the allocation engine in the following
3575// scenario:
3576// - Client has no lease in the database.
3577// - Client has a global reservation matching the current subnet.
3578// - Client sends REQUEST
3579// - Client is allocated the reserved address.
3580// - Lease is added to the lease database
3581TEST_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"
, 3581), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3581), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3581), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
>); void AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test
::TestBody()
{
3582 // Create reservation for the client.
3583 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3584 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3585 SUBNET_ID_UNUSED, IOAddress("192.0.2.10")));
3586 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3587 CfgMgr::instance().commit();
3588
3589 AllocEngine engine(0);
3590
3591 subnet_->setReservationsGlobal(true);
3592
3593 // Query allocation engine for the lease to be assigned to this
3594 // client without specifying the address to be assigned.
3595 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3596 IOAddress("0.0.0.0"), false, false,
3597 "", false);
3598 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3599
3600 // Look up the host.
3601 AllocEngine::findReservation(ctx);
3602
3603 // We should have the correct current host
3604 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"
, 3604, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3605 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"
, 3605, gtest_ar.failure_message()) = ::testing::Message()
;
3606 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"
, 3606, gtest_ar.failure_message()) = ::testing::Message()
;
3607
3608 // We should allocate the reserved address.
3609 Lease4Ptr lease = engine.allocateLease4(ctx);
3610 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"
, 3610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3611 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"
, 3611, gtest_ar.failure_message()) = ::testing::Message()
;
3612
3613 // Check that the lease is indeed in LeaseMgr
3614 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3615 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"
, 3615, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3616
3617 // Now check that the lease in LeaseMgr has the same parameters
3618 detailCompareLease(lease, from_mgr);
3619
3620 // Client had no lease in the database, so the old lease returned should
3621 // be NULL.
3622 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"
, 3622, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3623}
3624
3625// This test checks the behavior of the allocation engine in the following
3626// scenario:
3627// - Client has no lease in the database.
3628// - Client has a global reservation.
3629// - Client sends DISCOVER
3630// - Client is allocated a dynamic address from matched subnet
3631// - Lease is not added to the lease database
3632TEST_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"
, 3632), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3632), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3632), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicDiscover_Test
>); void AllocEngine4Test_globalReservationDynamicDiscover_Test
::TestBody()
{
3633 // Create reservation for the client.
3634 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3635 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3636 SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(),
3637 "foo.example.org"));
3638 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3639 CfgMgr::instance().commit();
3640
3641 AllocEngine engine(0);
3642
3643 subnet_->setReservationsGlobal(true);
3644
3645 // Query allocation engine for the lease to be assigned to this
3646 // client without specifying the address to be assigned.
3647 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3648 IOAddress("0.0.0.0"), false, false,
3649 "", true);
3650 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3651
3652 // Look up the host.
3653 AllocEngine::findReservation(ctx);
3654
3655 // We should have the correct current host
3656 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"
, 3656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3657 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"
, 3657, gtest_ar.failure_message()) = ::testing::Message()
;
3658 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"
, 3658, gtest_ar.failure_message()) = ::testing::Message()
;
3659
3660 // We should allocate a dynamic address.
3661 Lease4Ptr lease = engine.allocateLease4(ctx);
3662 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"
, 3662, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3663 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"
, 3663, gtest_ar.failure_message()) = ::testing::Message()
;
3664
3665 // This is a "fake" allocation so the returned lease should not be committed
3666 // to the lease database.
3667 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"
, 3667, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3668
3669 // Client had no lease in the database, so the old lease returned should
3670 // be NULL.
3671 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"
, 3671, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3672}
3673
3674// This test checks the behavior of the allocation engine in the following
3675// scenario:
3676// - Client has no lease in the database.
3677// - Client has a global reservation.
3678// - Client sends REQUEST
3679// - Client is allocated a dynamic address from matched subnet
3680// - Lease is added to the lease database
3681TEST_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"
, 3681), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3681), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3681), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicRequest_Test
>); void AllocEngine4Test_globalReservationDynamicRequest_Test
::TestBody()
{
3682 // Create reservation for the client.
3683 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3684 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3685 SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(),
3686 "foo.example.org"));
3687 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3688 CfgMgr::instance().commit();
3689
3690 AllocEngine engine(0);
3691
3692 subnet_->setReservationsGlobal(true);
3693
3694 // Query allocation engine for the lease to be assigned to this
3695 // client without specifying the address to be assigned.
3696 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3697 IOAddress("0.0.0.0"), false, false,
3698 "", false);
3699 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3700
3701 // Look up the host.
3702 AllocEngine::findReservation(ctx);
3703
3704 // We should have the correct current host
3705 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"
, 3705, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3706 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"
, 3706, gtest_ar.failure_message()) = ::testing::Message()
;
3707 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"
, 3707, gtest_ar.failure_message()) = ::testing::Message()
;
3708
3709 // We should allocate a dynamic address.
3710 Lease4Ptr lease = engine.allocateLease4(ctx);
3711 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"
, 3711, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3712 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"
, 3712, gtest_ar.failure_message()) = ::testing::Message()
;
3713
3714 // Check that the lease is indeed in LeaseMgr
3715 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3716 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"
, 3716, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3717
3718 // Now check that the lease in LeaseMgr has the same parameters
3719 detailCompareLease(lease, from_mgr);
3720
3721 // Client had no lease in the database, so the old lease returned should
3722 // be NULL.
3723 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"
, 3723, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3724}
3725
3726// This test checks the behavior of the allocation engine in the following
3727// scenario:
3728// - Client has no lease in the database.
3729// - Client has a subnet reservation.
3730// - Client sends DISCOVER
3731// - Client is allocated the reserved address.
3732// - Lease is not added to the lease database
3733TEST_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"
, 3733), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3733), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3733), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
>); void AllocEngine4Test_mixedReservationReservedAddressDiscover_Test
::TestBody()
{
3734 // Create reservation for the client.
3735 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3736 Host::IDENT_HWADDR, subnet_->getID(),
3737 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3738 "foo.example.org"));
3739 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3740 CfgMgr::instance().commit();
3741
3742 AllocEngine engine(0);
3743
3744 subnet_->setReservationsGlobal(true);
3745 subnet_->setReservationsInSubnet(true);
3746
3747 // Query allocation engine for the lease to be assigned to this
3748 // client without specifying the address to be assigned.
3749 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3750 IOAddress("0.0.0.0"), false, false,
3751 "", true);
3752 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3753
3754 // Look up the host.
3755 AllocEngine::findReservation(ctx);
3756
3757 // We should have the correct current host
3758 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"
, 3758, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3759 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"
, 3759, gtest_ar.failure_message()) = ::testing::Message()
;
3760 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"
, 3760, gtest_ar.failure_message()) = ::testing::Message()
;
3761
3762 // We should allocate the reserved address.
3763 Lease4Ptr lease = engine.allocateLease4(ctx);
3764 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"
, 3764, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3765 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"
, 3765, gtest_ar.failure_message()) = ::testing::Message()
;
3766
3767 // This is a "fake" allocation so the returned lease should not be committed
3768 // to the lease database.
3769 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"
, 3769, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3770
3771 // Client had no lease in the database, so the old lease returned should
3772 // be NULL.
3773 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"
, 3773, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3774}
3775
3776// This test checks the behavior of the allocation engine in the following
3777// scenario:
3778// - Client has no lease in the database.
3779// - Client has a subnet reservation.
3780// - Client sends REQUEST
3781// - Client is allocated the reserved address.
3782// - Lease is added to the lease database
3783TEST_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"
, 3783), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3783), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3783), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressRequest_Test
>); void AllocEngine4Test_mixedReservationReservedAddressRequest_Test
::TestBody()
{
3784 // Create reservation for the client.
3785 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3786 Host::IDENT_HWADDR, subnet_->getID(),
3787 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3788 "foo.example.org"));
3789 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3790 CfgMgr::instance().commit();
3791
3792 AllocEngine engine(0);
3793
3794 subnet_->setReservationsGlobal(true);
3795 subnet_->setReservationsInSubnet(true);
3796
3797 // Query allocation engine for the lease to be assigned to this
3798 // client without specifying the address to be assigned.
3799 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3800 IOAddress("0.0.0.0"), false, false,
3801 "", false);
3802 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3803
3804 // Look up the host.
3805 AllocEngine::findReservation(ctx);
3806
3807 // We should have the correct current host
3808 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"
, 3808, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3809 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"
, 3809, gtest_ar.failure_message()) = ::testing::Message()
;
3810 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"
, 3810, gtest_ar.failure_message()) = ::testing::Message()
;
3811
3812 // We should allocate the reserved address.
3813 Lease4Ptr lease = engine.allocateLease4(ctx);
3814 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"
, 3814, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3815 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"
, 3815, gtest_ar.failure_message()) = ::testing::Message()
;
3816
3817 // Check that the lease is indeed in LeaseMgr
3818 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3819 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"
, 3819, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3820
3821 // Now check that the lease in LeaseMgr has the same parameters
3822 detailCompareLease(lease, from_mgr);
3823
3824 // Client had no lease in the database, so the old lease returned should
3825 // be NULL.
3826 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"
, 3826, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3827}
3828
3829// This test checks the behavior of the allocation engine in the following
3830// scenario:
3831// - Client has no lease in the database.
3832// - Client has a global and a subnet reservation.
3833// - Client sends DISCOVER
3834// - Client is allocated the reserved address.
3835// - Lease is not added to the lease database
3836TEST_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"
, 3836), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3836), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3836), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressDiscover_Test
>); void AllocEngine4Test_bothReservationReservedAddressDiscover_Test
::TestBody()
{
3837 // Create reservations for the client.
3838 HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3839 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3840 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3841 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost);
3842 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3843 Host::IDENT_HWADDR, subnet_->getID(),
3844 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3845 "foo.example.org"));
3846 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3847 CfgMgr::instance().commit();
3848
3849 AllocEngine engine(0);
3850
3851 subnet_->setReservationsGlobal(true);
3852 subnet_->setReservationsInSubnet(true);
3853
3854 // Query allocation engine for the lease to be assigned to this
3855 // client without specifying the address to be assigned.
3856 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3857 IOAddress("0.0.0.0"), false, false,
3858 "", true);
3859 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
3860
3861 // Look up the host.
3862 AllocEngine::findReservation(ctx);
3863
3864 // We should have the correct current host
3865 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"
, 3865, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3866 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"
, 3866, gtest_ar.failure_message()) = ::testing::Message()
;
3867 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"
, 3867, gtest_ar.failure_message()) = ::testing::Message()
;
3868
3869 // We should allocate the reserved address.
3870 Lease4Ptr lease = engine.allocateLease4(ctx);
3871 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"
, 3871, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3872 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"
, 3872, gtest_ar.failure_message()) = ::testing::Message()
;
3873
3874 // This is a "fake" allocation so the returned lease should not be committed
3875 // to the lease database.
3876 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"
, 3876, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true"
, "false") .c_str()) = ::testing::Message()
;
3877
3878 // Client had no lease in the database, so the old lease returned should
3879 // be NULL.
3880 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"
, 3880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3881}
3882
3883// This test checks the behavior of the allocation engine in the following
3884// scenario:
3885// - Client has no lease in the database.
3886// - Client has a global and a subnet reservation.
3887// - Client sends REQUEST
3888// - Client is allocated the reserved address.
3889// - Lease is added to the lease database
3890TEST_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"
, 3890), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3890), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3890), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressRequest_Test
>); void AllocEngine4Test_bothReservationReservedAddressRequest_Test
::TestBody()
{
3891 // Create reservations for the client.
3892 HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3893 Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
3894 SUBNET_ID_UNUSED, IOAddress("192.0.77.123")));
3895 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost);
3896 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
3897 Host::IDENT_HWADDR, subnet_->getID(),
3898 SUBNET_ID_UNUSED, IOAddress("192.0.2.123"),
3899 "foo.example.org"));
3900 CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
3901 CfgMgr::instance().commit();
3902
3903 AllocEngine engine(0);
3904
3905 subnet_->setReservationsGlobal(true);
3906 subnet_->setReservationsInSubnet(true);
3907
3908 // Query allocation engine for the lease to be assigned to this
3909 // client without specifying the address to be assigned.
3910 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
3911 IOAddress("0.0.0.0"), false, false,
3912 "", false);
3913 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
3914
3915 // Look up the host.
3916 AllocEngine::findReservation(ctx);
3917
3918 // We should have the correct current host
3919 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"
, 3919, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.currentHost()", "false", "true") .c_str()) = ::testing
::Message()
;
3920 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"
, 3920, gtest_ar.failure_message()) = ::testing::Message()
;
3921 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"
, 3921, gtest_ar.failure_message()) = ::testing::Message()
;
3922
3923 // We should allocate the reserved address.
3924 Lease4Ptr lease = engine.allocateLease4(ctx);
3925 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"
, 3925, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
3926 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"
, 3926, gtest_ar.failure_message()) = ::testing::Message()
;
3927
3928 // Check that the lease is indeed in LeaseMgr
3929 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
3930 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"
, 3930, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
3931
3932 // Now check that the lease in LeaseMgr has the same parameters
3933 detailCompareLease(lease, from_mgr);
3934
3935 // Client had no lease in the database, so the old lease returned should
3936 // be NULL.
3937 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"
, 3937, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
3938}
3939
3940// Exercises AllocEnginer4Test::updateExtendedInfo4() through various
3941// permutations of client packet content.
3942TEST_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"
, 3942), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3942), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 3942), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_updateExtendedInfo4_Test
>); void AllocEngine4Test_updateExtendedInfo4_Test::TestBody
()
{
3943
3944 // Structure that defines a test scenario.
3945 struct Scenario {
3946 std::string description_; // test description
3947 std::string orig_context_json_; // user context the lease begins with
3948 std::string rai_data_; // RAI option the client packet contains
3949 std::string exp_context_json_; // expected user context on the lease
3950 bool exp_ret; // expected returned value
3951 };
3952
3953 // Test scenarios.
3954 std::vector<Scenario> scenarios {
3955 {
3956 "no context, no rai",
3957 "",
3958 "",
3959 "",
3960 false
3961 },
3962 {
3963 "some original context, no rai",
3964 "{\"foo\": 123}",
3965 "",
3966 "{\"foo\": 123}",
3967 false
3968 },
3969 {
3970 "no original context, rai",
3971 "",
3972 "0x52060104aabbccdd",
3973 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
3974 " \"0x0104AABBCCDD\" } } }",
3975 true
3976 },
3977 {
3978 "no original context, rai, remote and relay ids",
3979 "",
3980 "0x520a02030102030c03aabbcc",
3981 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
3982 " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\","
3983 " \"relay-id\": \"AABBCC\" } } }",
3984 true
3985 },
3986 {
3987 "some original context, rai",
3988 "{\"foo\": 123, \"ISC\":{\"bar\": 456}}",
3989 "0x52060104aabbccdd",
3990 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
3991 " \"0x0104AABBCCDD\" }, \"bar\": 456 }, \"foo\": 123 }",
3992 true
3993 },
3994 {
3995 "bad original context, rai",
3996 "[\"foo\"]",
3997 "0x52060104aabbccdd",
3998 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
3999 " \"0x0104AABBCCDD\" } } }",
4000 true
4001 },
4002 {
4003 "some original context with bad isc entry, rai",
4004 "{\"foo\": 123, \"ISC\":[\"bar\"]}",
4005 "0x52060104aabbccdd",
4006 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4007 " \"0x0104AABBCCDD\" } }, \"foo\": 123 }",
4008 true
4009 },
4010 {
4011 "some original context, rai, remote and relay ids",
4012 "{\"foo\": 123, \"ISC\":{ \"bar\": 456}}",
4013 "0x520a02030102030c03aabbcc",
4014 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4015 " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\","
4016 " \"relay-id\": \"AABBCC\" }, \"bar\": 456 }, \"foo\": 123 }",
4017 true
4018 },
4019 {
4020 "original rai context, no rai",
4021 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4022 " \"0x0104AABBCCDD\" } } }",
4023 "",
4024 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4025 " \"0x0104AABBCCDD\" } } }",
4026 false
4027 },
4028 {
4029 "original rai context, different rai",
4030 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4031 " \"0x0104AABBCCDD\" } } }",
4032 "0x52060104ddeeffaa",
4033 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4034 " \"0x0104DDEEFFAA\" } } }",
4035 true
4036 },
4037 {
4038 "original rai context, different rai, remote and relay ids",
4039 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4040 " \"0x0104AABBCCDD\" } } }",
4041 "0x520a02030102030c03aabbcc",
4042 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4043 " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\","
4044 " \"relay-id\": \"AABBCC\" } } }",
4045 true
4046 }};
4047
4048 // Create the allocation engine, context and lease.
4049 NakedAllocEngine engine(0);
4050
4051 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
4052 IOAddress::IPV4_ZERO_ADDRESS(),
4053 false, false, "", true);
4054
4055 // All scenarios require storage to be enabled.
4056 subnet_->setStoreExtendedInfo(true);
4057
4058 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4059 Lease4Ptr lease = engine.allocateLease4(ctx);
4060 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"
, 4060, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4061 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"
, 4061, gtest_ar.failure_message()) = ::testing::Message()
;
4062
4063 // Verify that the lease begins with no user context.
4064 ConstElementPtr user_context = lease->getContext();
4065 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"
, 4065, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "true", "false") .c_str()) = ::testing::Message
()
;
4066
4067 // Iterate over the test scenarios.
4068 ElementPtr orig_context;
4069 ElementPtr exp_context;
4070 for (auto const& scenario : scenarios) {
4071 SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4071( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4071, (scenario.description_))
;
4072
4073 // Create the original user context from JSON.
4074 if (scenario.orig_context_json_.empty()) {
4075 orig_context.reset();
4076 } else {
4077 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_4077; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4077
; } } else gtest_label_testnothrow_4077 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4077, ("Expected: " "orig_context = Element::fromJSON(scenario.orig_context_json_)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4078 << "invalid orig_context_json_, test is broken";
4079 }
4080
4081 // Create the expected user context from JSON.
4082 if (scenario.exp_context_json_.empty()) {
4083 exp_context.reset();
4084 } else {
4085 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_4085; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4085
; } } else gtest_label_testnothrow_4085 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4085, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4086 << "invalid exp_context_json_, test is broken";
4087 }
4088
4089 // Initialize lease's user context.
4090 lease->setContext(orig_context);
4091 if (!orig_context) {
4092 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"
, 4092, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4093 } else {
4094 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"
, 4094, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "false", "true") .c_str()) = ::testing
::Message()
;
4095 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"
, 4095, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "orig_context->equals(*(lease->getContext()))", "false"
, "true") .c_str()) = ::testing::Message()
;
4096 }
4097
4098 // Create the client packet and the add RAI option (if one).
4099 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4100 if (!scenario.rai_data_.empty()) {
4101 std::vector<uint8_t> opt_data;
4102 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_4102; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4102
; } } else gtest_label_testnothrow_4102 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4102, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4103 << "scenario.rai_data_ is invalid, test is broken";
4104 const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF();
4105 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"
, 4105, gtest_ar.failure_message()) = ::testing::Message()
;
4106 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"
, 4106, gtest_ar.failure_message()) = ::testing::Message()
;
4107 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"
, 4107, gtest_ar.failure_message()) = ::testing::Message()
;
4108 std::vector<uint8_t> rai_data(opt_data.cbegin() + 2,
4109 opt_data.cend());
4110 OptionCustomPtr rai;
4111 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_4112; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4112; } } else gtest_label_testnothrow_4112
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4112, ("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()
4112 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_4112; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4112; } } else gtest_label_testnothrow_4112
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4112, ("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()
4113 << "could not create rai option, test is broken";
4114 ctx.query_->addOption(rai);
4115 }
4116
4117 // Call AllocEngine::updateLease4ExtendeInfo().
4118 bool ret = false;
4119 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",
4119, "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",
4119, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4120 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"
, 4120, gtest_ar.failure_message()) = ::testing::Message()
;
4121
4122 // Verify the lease has the expected user context content.
4123 if (!exp_context) {
4124 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"
, 4124, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4125 } else {
4126 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"
, 4126, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "false", "true") .c_str()) = ::testing
::Message()
;
4127 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"
, 4127, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "exp_context->equals(*(lease->getContext()))", "false"
, "true") .c_str()) = ::testing::Message()
4128 << "expected: " << *(exp_context) << std::endl
4129 << " actual: " << *(lease->getContext()) << std::endl;
4130 }
4131 }
4132}
4133
4134// Verifies that recovered stashed RAI is not saved in extended info.
4135TEST_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"
, 4135), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4135), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4135), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_stashAgentOptions_Test
>); void AllocEngine4Test_stashAgentOptions_Test::TestBody
()
{
4136 // Create the allocation engine, context and lease.
4137 NakedAllocEngine engine(0);
4138
4139 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
4140 IOAddress::IPV4_ZERO_ADDRESS(),
4141 false, false, "", true);
4142 subnet_->setStoreExtendedInfo(true);
4143 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4144 Lease4Ptr lease = engine.allocateLease4(ctx);
4145 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"
, 4145, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4146 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"
, 4146, gtest_ar.failure_message()) = ::testing::Message()
;
4147
4148 // Verify that the lease begins with no user context.
4149 ConstElementPtr user_context = lease->getContext();
4150 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"
, 4150, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "true", "false") .c_str()) = ::testing::Message
()
;
4151
4152 // Add a RAI in the query.
4153 std::string rai_str = "0104aabbccdd";
4154 std::vector<uint8_t> rai_data;
4155 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_4155; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4155; } } else gtest_label_testnothrow_4155
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4155, ("Expected: " "util::str::decodeFormattedHexString(rai_str, rai_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4156 const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF();
4157 OptionCustomPtr rai;
4158 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_4158; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4158; } } else gtest_label_testnothrow_4158
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4158, ("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()
;
4159 ctx.query_->addOption(rai);
4160
4161 // Verifies that the RAI is saved into lease extended info.
4162 bool ret = false;
4163 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",
4163, "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",
4163, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4164 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",
4164, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ret", "false", "true") .c_str()) = ::testing::Message()
;
4165 user_context = lease->getContext();
4166 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"
, 4166, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "false", "true") .c_str()) = ::testing::Message
()
;
4167 lease->setContext(ElementPtr());
4168
4169 // Set stash-agent-options to true.
4170 CfgMgr::instance().getStagingCfg()->
4171 addConfiguredGlobal("stash-agent-options", Element::create(true));
4172 CfgMgr::instance().commit();
4173
4174 // Verifies that the RAI is saved into lease extended info.
4175 ret = false;
Value stored to 'ret' is never read
4176 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",
4176, "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",
4176, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4177 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",
4177, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ret", "false", "true") .c_str()) = ::testing::Message()
;
4178 user_context = lease->getContext();
4179 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"
, 4179, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "false", "true") .c_str()) = ::testing::Message
()
;
4180 lease->setContext(ElementPtr());
4181
4182 // Put the query in the STASH_AGENT_OPTIONS class.
4183 ctx.query_->addClass("STASH_AGENT_OPTIONS");
4184
4185 // Verifies that the RAI is not saved into lease extended info.
4186 ret = false;
4187 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",
4187, "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",
4187, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)"
<< " threw non-std::exception"; } }
;
4188 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",
4188, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ret", "true", "false") .c_str()) = ::testing::Message()
;
4189 user_context = lease->getContext();
4190 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"
, 4190, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "user_context", "true", "false") .c_str()) = ::testing::Message
()
;
4191}
4192
4193// Verifies that the extended data (e.g. RAI option for now) is
4194// added to a V4 lease when leases are created and/or renewed,
4195// when store-extended-info is true.
4196TEST_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"
, 4196), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4196), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4196), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoEnabled4_Test
>); void AllocEngine4Test_storeExtendedInfoEnabled4_Test::
TestBody()
{
4197
4198 // Structure that defines a test scenario.
4199 struct Scenario {
4200 std::string description_; // test description
4201 std::vector<uint8_t> mac_; // MAC address
4202 std::string rai_data_; // RAI option the client packet contains
4203 std::string exp_context_json_; // expected user context on the lease
4204 std::string exp_address_; // expected lease address
4205 };
4206
4207 std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 };
4208 std::string mac1_addr = "192.0.2.100";
4209
4210 std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 };
4211 std::string mac2_addr = "192.0.2.101";
4212
4213 // Test scenarios.
4214 std::vector<Scenario> scenarios {
4215 {
4216 "create client one without rai",
4217 mac1,
4218 "",
4219 "",
4220 mac1_addr
4221 },
4222 {
4223 "renew client one without rai",
4224 {},
4225 "",
4226 "",
4227 mac1_addr
4228 },
4229 {
4230 "create client two with rai",
4231 mac2,
4232 "0x52050104a1b1c1d1",
4233 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4234 " \"0x52050104A1B1C1D1\" } } }",
4235 mac2_addr
4236 },
4237 {
4238 "renew client two without rai",
4239 {},
4240 "",
4241 "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":"
4242 " \"0x52050104A1B1C1D1\" } } }",
4243 mac2_addr
4244 }};
4245
4246 // Create the allocation engine, context and lease.
4247 NakedAllocEngine engine(0);
4248
4249 // All of the scenarios require storage to be enabled.
4250 subnet_->setStoreExtendedInfo(true);
4251
4252 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
4253 IOAddress::IPV4_ZERO_ADDRESS(),
4254 false, false, "", false);
4255
4256 // Iterate over the test scenarios.
4257 for (auto const& scenario : scenarios) {
4258 SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4258( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4258, (scenario.description_))
;
4259
4260 ElementPtr exp_context;
4261 // Create the expected user context from JSON.
4262 if (!scenario.exp_context_json_.empty()) {
4263 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_4263; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4263
; } } else gtest_label_testnothrow_4263 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4263, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4264 << "invalid exp_context_json_, test is broken";
4265 }
4266
4267 // If we have a MAC address this scenario is for a new client.
4268 if (!scenario.mac_.empty()) {
4269 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_4269; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4269; } } else gtest_label_testnothrow_4269
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4269, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4270 << "invalid MAC address, test is broken";
4271 }
4272
4273 // Create the client packet and the add RAI option (if one).
4274 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4275 if (!scenario.rai_data_.empty()) {
4276 std::vector<uint8_t> opt_data;
4277 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_4277; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4277
; } } else gtest_label_testnothrow_4277 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4277, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4278 << "scenario.rai_data_ is invalid, test is broken";
4279 OptionPtr rai;
4280 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_4280; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4280; } } else gtest_label_testnothrow_4280
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4280, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4281 << "could not create rai option, test is broken";
4282
4283 ctx.query_->addOption(rai);
4284 }
4285
4286 // Create or renew the lease.
4287 Lease4Ptr lease = engine.allocateLease4(ctx);
4288 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"
, 4288, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4289 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"
, 4289, gtest_ar.failure_message()) = ::testing::Message()
;
4290
4291 // Verify the lease has the expected user context content.
4292 if (!exp_context) {
4293 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"
, 4293, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4294 } else {
4295 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"
, 4295, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "false", "true") .c_str()) = ::testing
::Message()
;
4296 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"
, 4296, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "exp_context->equals(*(lease->getContext()))", "false"
, "true") .c_str()) = ::testing::Message()
4297 << "expected: " << *(exp_context) << std::endl
4298 << " actual: " << *(lease->getContext()) << std::endl;
4299 }
4300 }
4301}
4302
4303// Verifies that the extended data (e.g. RAI option for now) is
4304// not added to a V4 lease when leases are created and/or renewed,
4305// when store-extended-info is false.
4306TEST_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"
, 4306), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4306), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4306), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoDisabled4_Test
>); void AllocEngine4Test_storeExtendedInfoDisabled4_Test::
TestBody()
{
4307
4308 // Structure that defines a test scenario.
4309 struct Scenario {
4310 std::string description_; // test description
4311 std::vector<uint8_t> mac_; // MAC address
4312 std::string rai_data_; // RAI option the client packet contains
4313 std::string exp_address_; // expected lease address
4314 };
4315
4316 std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 };
4317 std::string mac1_addr = "192.0.2.100";
4318
4319 std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 };
4320 std::string mac2_addr = "192.0.2.101";
4321
4322 // Test scenarios.
4323 std::vector<Scenario> scenarios {
4324 {
4325 "create client one without rai",
4326 mac1,
4327 "",
4328 mac1_addr
4329 },
4330 {
4331 "renew client one without rai",
4332 {},
4333 "",
4334 mac1_addr
4335 },
4336 {
4337 "create client two with rai",
4338 mac2,
4339 "0x52050104a1b1c1d1",
4340 mac2_addr
4341 },
4342 {
4343 "renew client two with rai",
4344 {},
4345 "0x52050104a1b1c1d1",
4346 mac2_addr
4347 }};
4348
4349 // Create the allocation engine, context and lease.
4350 NakedAllocEngine engine(0);
4351
4352 // All of the scenarios require storage to be disabled.
4353 subnet_->setStoreExtendedInfo(false);
4354
4355 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
4356 IOAddress::IPV4_ZERO_ADDRESS(),
4357 false, false, "", false);
4358
4359 // Iterate over the test scenarios.
4360 for (auto const& scenario : scenarios) {
4361 SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4361( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4361, (scenario.description_))
;
4362
4363 // If we have a MAC address this scenario is for a new client.
4364 if (!scenario.mac_.empty()) {
4365 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_4365; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4365; } } else gtest_label_testnothrow_4365
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4365, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4366 << "invalid MAC address, test is broken";
4367 }
4368
4369 // Create the client packet and the add RAI option (if one).
4370 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4371 if (!scenario.rai_data_.empty()) {
4372 std::vector<uint8_t> opt_data;
4373 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_4373; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4373
; } } else gtest_label_testnothrow_4373 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4373, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4374 << "scenario.rai_data_ is invalid, test is broken";
4375 OptionPtr rai;
4376 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_4376; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4376; } } else gtest_label_testnothrow_4376
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4376, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
4377 << "could not create rai option, test is broken";
4378
4379 ctx.query_->addOption(rai);
4380 }
4381
4382 // Create or renew the lease.
4383 Lease4Ptr lease = engine.allocateLease4(ctx);
4384 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"
, 4384, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4385 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"
, 4385, gtest_ar.failure_message()) = ::testing::Message()
;
4386
4387 // Verify the lease does not have user context content.
4388 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"
, 4388, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->getContext()", "true", "false") .c_str()) = ::testing
::Message()
;
4389 }
4390}
4391
4392// This test checks if a lease can be reused in DHCPDISCOVER (fake allocation)
4393// using cache threshold.
4394TEST_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"
, 4394), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4394), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4394), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheThreshold4_Test
>); void AllocEngine4Test_discoverCacheThreshold4_Test::TestBody
()
{
4395 boost::scoped_ptr<AllocEngine> engine;
4396 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_4396
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4396
; } } else gtest_label_testnothrow_4396 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4396, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4397 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"
, 4397, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4398
4399 // Set valid lifetime to 500.
4400 uint32_t valid = 500;
4401 subnet_->setValid(valid);
4402
4403 // Set the threshold to 25%.
4404 subnet_->setCacheThreshold(.25);
4405
4406 IOAddress addr("192.0.2.105");
4407 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4408 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4409 valid, now, subnet_->getID()));
4410 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"
, 4410, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4411 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"
, 4411, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4412
4413 // Create a context for fake allocation.
4414 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4415 false, false, "", true);
4416
4417 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4418 lease = engine->allocateLease4(ctx);
4419 // Check that we got that single lease.
4420 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"
, 4420, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4421 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"
, 4421, gtest_ar.failure_message()) = ::testing::Message()
;
4422
4423 // The lease was reused.
4424 time_t age = lease->cltt_ - now;
4425 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"
, 4425, gtest_ar.failure_message()) = ::testing::Message()
;
4426 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"
, 4426, gtest_ar.failure_message()) = ::testing::Message()
;
4427 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"
, 4427, gtest_ar.failure_message()) = ::testing::Message()
;
4428
4429 // Check other lease parameters.
4430 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"
, 4430, gtest_ar.failure_message()) = ::testing::Message()
;
4431 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"
, 4431, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4432 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"
, 4432, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4433 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"
, 4433, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4434 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"
, 4434, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4435}
4436
4437// This test checks if a lease can be reused in DHCPREQUEST (real allocation)
4438// using cache threshold.
4439TEST_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"
, 4439), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4439), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4439), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheThreshold4_Test
>); void AllocEngine4Test_requestCacheThreshold4_Test::TestBody
()
{
4440 boost::scoped_ptr<AllocEngine> engine;
4441 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_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: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4442 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"
, 4442, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4443
4444 // Set valid lifetime to 500.
4445 uint32_t valid = 500;
4446 subnet_->setValid(valid);
4447
4448 // Set the threshold to 25%.
4449 subnet_->setCacheThreshold(.25);
4450
4451 IOAddress addr("192.0.2.105");
4452 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4453 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4454 valid, now, subnet_->getID()));
4455 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"
, 4455, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4456 // Copy the lease, so as it can be compared with.
4457 Lease4Ptr original_lease(new Lease4(*lease));
4458 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"
, 4458, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4459
4460 // Create a context for real allocation.
4461 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4462 false, false, "", false);
4463
4464 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4465 lease = engine->allocateLease4(ctx);
4466 // Check that we got that single lease.
4467 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"
, 4467, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4468 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"
, 4468, gtest_ar.failure_message()) = ::testing::Message()
;
4469
4470 // The lease was reused.
4471 time_t age = lease->cltt_ - now;
4472 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"
, 4472, gtest_ar.failure_message()) = ::testing::Message()
;
4473 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"
, 4473, gtest_ar.failure_message()) = ::testing::Message()
;
4474 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"
, 4474, gtest_ar.failure_message()) = ::testing::Message()
;
4475
4476 // Check other lease parameters.
4477 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"
, 4477, gtest_ar.failure_message()) = ::testing::Message()
;
4478 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"
, 4478, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4479 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"
, 4479, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4480 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"
, 4480, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4481 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"
, 4481, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4482
4483 // Check the lease was not updated in the database.
4484 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4485 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"
, 4485, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4486
4487 detailCompareLease(original_lease, from_mgr);
4488}
4489
4490/// We proved that there is no different from the "cache" feature between
4491/// discovers and request at the exception of the lease database update.
4492
4493// This test checks if a lease can be reused in DHCPDISCOVER (fake allocation)
4494// using cache max age.
4495TEST_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"
, 4495), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4495), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4495), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheMaxAge4_Test
>); void AllocEngine4Test_discoverCacheMaxAge4_Test::TestBody
()
{
4496 boost::scoped_ptr<AllocEngine> engine;
4497 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_4497
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4497
; } } else gtest_label_testnothrow_4497 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4497, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4498 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"
, 4498, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4499
4500 // Set valid lifetime to 500.
4501 uint32_t valid = 500;
4502 subnet_->setValid(valid);
4503
4504 // Set the max age to 200.
4505 subnet_->setCacheMaxAge(200);
4506
4507 IOAddress addr("192.0.2.105");
4508 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4509 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4510 valid, now, subnet_->getID()));
4511 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"
, 4511, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4512 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"
, 4512, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4513
4514 // Create a context for fake allocation.
4515 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4516 false, false, "", true);
4517
4518 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4519 lease = engine->allocateLease4(ctx);
4520 // Check that we got that single lease.
4521 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"
, 4521, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4522 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"
, 4522, gtest_ar.failure_message()) = ::testing::Message()
;
4523
4524 // The lease was reused.
4525 time_t age = lease->cltt_ - now;
4526 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"
, 4526, gtest_ar.failure_message()) = ::testing::Message()
;
4527 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"
, 4527, gtest_ar.failure_message()) = ::testing::Message()
;
4528 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"
, 4528, gtest_ar.failure_message()) = ::testing::Message()
;
4529
4530 // Check other lease parameters.
4531 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"
, 4531, gtest_ar.failure_message()) = ::testing::Message()
;
4532 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"
, 4532, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4533 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"
, 4533, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4534 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"
, 4534, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4535 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"
, 4535, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4536}
4537
4538// This test checks if a lease can be reused in DHCPREQUEST (real allocation)
4539// using both cache threshold and max age.
4540TEST_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"
, 4540), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4540), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4540), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBoth4_Test
>); void AllocEngine4Test_requestCacheBoth4_Test::TestBody
()
{
4541 boost::scoped_ptr<AllocEngine> engine;
4542 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_4542
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4542
; } } else gtest_label_testnothrow_4542 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4542, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4543 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"
, 4543, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4544
4545 // Set valid lifetime to 500.
4546 uint32_t valid = 500;
4547 subnet_->setValid(valid);
4548
4549 // Set the threshold to 25%.
4550 subnet_->setCacheThreshold(.25);
4551
4552 // Set the max age to 200.
4553 subnet_->setCacheMaxAge(200);
4554
4555 IOAddress addr("192.0.2.105");
4556 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4557 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4558 valid, now, subnet_->getID()));
4559 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"
, 4559, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4560 // Copy the lease, so as it can be compared with.
4561 Lease4Ptr original_lease(new Lease4(*lease));
4562 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"
, 4562, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4563
4564 // Create a context for real allocation.
4565 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4566 false, false, "", false);
4567
4568 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4569 lease = engine->allocateLease4(ctx);
4570 // Check that we got that single lease.
4571 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"
, 4571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4572 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"
, 4572, gtest_ar.failure_message()) = ::testing::Message()
;
4573
4574 // The lease was reused.
4575 time_t age = lease->cltt_ - now;
4576 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"
, 4576, gtest_ar.failure_message()) = ::testing::Message()
;
4577 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"
, 4577, gtest_ar.failure_message()) = ::testing::Message()
;
4578 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"
, 4578, gtest_ar.failure_message()) = ::testing::Message()
;
4579
4580 // Check other lease parameters.
4581 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"
, 4581, gtest_ar.failure_message()) = ::testing::Message()
;
4582 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"
, 4582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
4583 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"
, 4583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
4584 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"
, 4584, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
4585 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"
, 4585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
4586
4587 // Check the lease was not updated in the database.
4588 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4589 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"
, 4589, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4590
4591 detailCompareLease(original_lease, from_mgr);
4592}
4593
4594// This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation)
4595// using too small cache threshold.
4596TEST_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"
, 4596), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4596), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4596), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheBadThreshold4_Test
>); void AllocEngine4Test_discoverCacheBadThreshold4_Test::
TestBody()
{
4597 boost::scoped_ptr<AllocEngine> engine;
4598 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_4598
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4598
; } } else gtest_label_testnothrow_4598 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4598, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4599 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"
, 4599, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4600
4601 // Set valid lifetime to 500.
4602 uint32_t valid = 500;
4603 subnet_->setValid(valid);
4604
4605 // Set the threshold to 10%.
4606 subnet_->setCacheThreshold(.10);
4607
4608 IOAddress addr("192.0.2.105");
4609 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4610 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4611 valid, now, subnet_->getID()));
4612 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"
, 4612, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4613 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"
, 4613, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4614
4615 // Create a context for fake allocation.
4616 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4617 false, false, "", true);
4618
4619 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4620 lease = engine->allocateLease4(ctx);
4621 // Check that we got that single lease.
4622 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"
, 4622, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4623 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"
, 4623, gtest_ar.failure_message()) = ::testing::Message()
;
4624
4625 // The lease was not reused.
4626 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"
, 4626, gtest_ar.failure_message()) = ::testing::Message()
;
4627}
4628
4629// This test checks if a lease can't be reused in DHCPREQUEST (real allocation)
4630// using too small cache max age.
4631TEST_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"
, 4631), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4631), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4631), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBadMaxAge4_Test
>); void AllocEngine4Test_requestCacheBadMaxAge4_Test::TestBody
()
{
4632 boost::scoped_ptr<AllocEngine> engine;
4633 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_4633
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4633
; } } else gtest_label_testnothrow_4633 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4633, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4634 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"
, 4634, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4635
4636 // Set valid lifetime to 500.
4637 uint32_t valid = 500;
4638 subnet_->setValid(valid);
4639
4640 // Set the threshold to 25%.
4641 subnet_->setCacheThreshold(.25);
4642
4643 // Set the max age to 50.
4644 subnet_->setCacheMaxAge(50);
4645
4646 IOAddress addr("192.0.2.105");
4647 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4648 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4649 valid, now, subnet_->getID()));
4650 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"
, 4650, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4651
4652 // Create a context for real allocation.
4653 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4654 false, false, "", false);
4655
4656 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4657 lease = engine->allocateLease4(ctx);
4658 // Check that we got that single lease.
4659 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"
, 4659, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4660 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"
, 4660, gtest_ar.failure_message()) = ::testing::Message()
;
4661
4662 // The lease was not reused.
4663 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"
, 4663, gtest_ar.failure_message()) = ::testing::Message()
;
4664
4665 // Check the lease was updated in the database.
4666 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4667 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"
, 4667, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4668
4669 detailCompareLease(lease, from_mgr);
4670}
4671
4672// This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation)
4673// when the valid lifetime was reduced.
4674TEST_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"
, 4674), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4674), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4674), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheReducedValid4_Test
>); void AllocEngine4Test_discoverCacheReducedValid4_Test::
TestBody()
{
4675 boost::scoped_ptr<AllocEngine> engine;
4676 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_4676
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4676
; } } else gtest_label_testnothrow_4676 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4676, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4677 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"
, 4677, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4678
4679 // Set valid lifetime to 200.
4680 subnet_->setValid(200);
4681
4682 // Set the threshold to 25%.
4683 subnet_->setCacheThreshold(.25);
4684
4685 IOAddress addr("192.0.2.105");
4686 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4687 uint32_t valid = 500; // Used a value greater than subnet_->getValid().
4688 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4689 valid, now, subnet_->getID()));
4690 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"
, 4690, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4691 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"
, 4691, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4692
4693 // Create a context for fake allocation.
4694 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4695 false, false, "", true);
4696
4697 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4698 lease = engine->allocateLease4(ctx);
4699 // Check that we got that single lease.
4700 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"
, 4700, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4701 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"
, 4701, gtest_ar.failure_message()) = ::testing::Message()
;
4702
4703 // The lease was not reused.
4704 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"
, 4704, gtest_ar.failure_message()) = ::testing::Message()
;
4705}
4706
4707// This test checks if a lease can't be reused in DHCPREQUEST (real allocation)
4708// when DDNS parameter changed.
4709TEST_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"
, 4709), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4709), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4709), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheFwdDDNS4_Test
>); void AllocEngine4Test_requestCacheFwdDDNS4_Test::TestBody
()
{
4710 boost::scoped_ptr<AllocEngine> engine;
4711 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_4711
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4711
; } } else gtest_label_testnothrow_4711 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4711, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4712 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"
, 4712, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4713
4714 // Set valid lifetime to 500.
4715 uint32_t valid = 500;
4716 subnet_->setValid(valid);
4717
4718 // Set the max age to 200.
4719 subnet_->setCacheMaxAge(200);
4720
4721 IOAddress addr("192.0.2.105");
4722 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4723 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4724 valid, now, subnet_->getID()));
4725 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"
, 4725, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4726
4727 // Create a context for real allocation with fwd_dns_update changed.
4728 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4729 true, false, "", false);
4730
4731 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4732 lease = engine->allocateLease4(ctx);
4733 // Check that we got that single lease.
4734 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"
, 4734, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4735 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"
, 4735, gtest_ar.failure_message()) = ::testing::Message()
;
4736
4737 // The lease was not reused.
4738 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"
, 4738, gtest_ar.failure_message()) = ::testing::Message()
;
4739
4740 // Check the lease was updated in the database.
4741 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4742 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"
, 4742, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4743
4744 detailCompareLease(lease, from_mgr);
4745}
4746
4747// This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation)
4748// when DDNS parameter changed.
4749TEST_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"
, 4749), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4749), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4749), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheRevDDNS4_Test
>); void AllocEngine4Test_discoverCacheRevDDNS4_Test::TestBody
()
{
4750 boost::scoped_ptr<AllocEngine> engine;
4751 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_4751
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4751
; } } else gtest_label_testnothrow_4751 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4751, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4752 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"
, 4752, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4753
4754 // Set valid lifetime to 500.
4755 uint32_t valid = 500;
4756 subnet_->setValid(valid);
4757
4758 // Set the threshold to 25%.
4759 subnet_->setCacheThreshold(.25);
4760
4761 // Set the max age to 200.
4762 subnet_->setCacheMaxAge(200);
4763
4764 IOAddress addr("192.0.2.105");
4765 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4766 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4767 valid, now, subnet_->getID()));
4768 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"
, 4768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4769 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"
, 4769, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
4770
4771 // Create a context for fake allocation with rev_dns_update changed.
4772 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4773 false, true, "", true);
4774
4775 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4776 lease = engine->allocateLease4(ctx);
4777 // Check that we got that single lease.
4778 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"
, 4778, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4779 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"
, 4779, gtest_ar.failure_message()) = ::testing::Message()
;
4780
4781 // The lease was not reused.
4782 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"
, 4782, gtest_ar.failure_message()) = ::testing::Message()
;
4783}
4784
4785// This test checks if a lease can't be reused in DHCPREQUEST (real allocation)
4786// when hostname changed.
4787TEST_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"
, 4787), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4787), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4787), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheHostname4_Test
>); void AllocEngine4Test_requestCacheHostname4_Test::TestBody
()
{
4788 boost::scoped_ptr<AllocEngine> engine;
4789 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_4789
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4789
; } } else gtest_label_testnothrow_4789 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4789, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4790 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"
, 4790, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
4791
4792 // Set valid lifetime to 500.
4793 uint32_t valid = 500;
4794 subnet_->setValid(valid);
4795
4796 // Set the max age to 200.
4797 subnet_->setCacheMaxAge(200);
4798
4799 IOAddress addr("192.0.2.105");
4800 time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago.
4801 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_,
4802 valid, now, subnet_->getID(),
4803 false, false, "foo"));
4804 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"
, 4804, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
4805
4806 // Create a context for real allocation with fwd_dns_update changed.
4807 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr,
4808 false, false, "bar", false);
4809
4810 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
4811 lease = engine->allocateLease4(ctx);
4812 // Check that we got that single lease.
4813 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"
, 4813, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4814 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"
, 4814, gtest_ar.failure_message()) = ::testing::Message()
;
4815
4816 // The lease was not reused.
4817 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"
, 4817, gtest_ar.failure_message()) = ::testing::Message()
;
4818 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"
, 4818, gtest_ar.failure_message()) = ::testing::Message()
;
4819
4820 // Check the lease was updated in the database.
4821 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
4822 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"
, 4822, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
4823
4824 detailCompareLease(lease, from_mgr);
4825}
4826
4827// Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate
4828// lifetime value based on the context content.
4829TEST_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", 4829
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4829), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4829), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getValidLft4_Test
>); void AllocEngine4Test_getValidLft4_Test::TestBody()
{
4830 AllocEngine engine(0);
4831
4832 // Let's make three classes, two with valid-lifetime and one without,
4833 // and add them to the dictionary.
4834 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
4835
4836 ClientClassDefPtr class_def(new ClientClassDef("valid_one", ExpressionPtr()));
4837 Triplet<uint32_t> valid_one(50, 100, 150);
4838 class_def->setValid(valid_one);
4839 dictionary->addClass(class_def);
4840
4841 class_def.reset(new ClientClassDef("valid_two", ExpressionPtr()));
4842 Triplet<uint32_t>valid_two(200, 250, 300);
4843 class_def->setValid(valid_two);
4844 dictionary->addClass(class_def);
4845
4846 class_def.reset(new ClientClassDef("valid_unspec", ExpressionPtr()));
4847 dictionary->addClass(class_def);
4848
4849 // Commit our class changes.
4850 CfgMgr::instance().commit();
4851
4852 // Update the subnet's triplet to something more useful.
4853 subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500));
4854
4855 // Describes a test scenario.
4856 struct Scenario {
4857 std::string desc_; // descriptive text for logging
4858 std::vector<std::string> classes_; // class list of assigned classes
4859 uint32_t requested_lft_; // use as option 51 is > 0
4860 uint32_t exp_valid_; // expected lifetime
4861 };
4862
4863 // Scenarios to test.
4864 std::vector<Scenario> scenarios = {
4865 {
4866 "BOOTP",
4867 { "BOOTP" },
4868 0,
4869 Lease::INFINITY_LFT
4870 },
4871 {
4872 "no classes, no option",
4873 {},
4874 0,
4875 subnet_->getValid()
4876 },
4877 {
4878 "no classes, option",
4879 {},
4880 subnet_->getValid().getMin() + 50,
4881 subnet_->getValid().getMin() + 50
4882 },
4883 {
4884 "no classes, option too small",
4885 {},
4886 subnet_->getValid().getMin() - 50,
4887 subnet_->getValid().getMin()
4888 },
4889 {
4890 "no classes, option too big",
4891 {},
4892 subnet_->getValid().getMax() + 50,
4893 subnet_->getValid().getMax()
4894 },
4895 {
4896 "class unspecified, no option",
4897 { "valid_unspec" },
4898 0,
4899 subnet_->getValid()
4900 },
4901 {
4902 "from last class, no option",
4903 { "valid_unspec", "valid_one" },
4904 0,
4905 valid_one.get()
4906 },
4907 {
4908 "from first class, no option",
4909 { "valid_two", "valid_one" },
4910 0,
4911 valid_two.get()
4912 },
4913 {
4914 "class plus option",
4915 { "valid_one" },
4916 valid_one.getMin() + 25,
4917 valid_one.getMin() + 25
4918 },
4919 {
4920 "class plus option too small",
4921 { "valid_one" },
4922 valid_one.getMin() - 25,
4923 valid_one.getMin()
4924 },
4925 {
4926 "class plus option too big",
4927 { "valid_one" },
4928 valid_one.getMax() + 25,
4929 valid_one.getMax()
4930 }
4931 };
4932
4933 // Iterate over the scenarios and verify the correct outcome.
4934 for (auto const& scenario : scenarios) {
4935 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_4935( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4935, (scenario.desc_))
; {
4936 // Create a context;
4937 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
4938 IOAddress("0.0.0.0"), false, false,
4939 "", false);
4940 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
4941
4942 // Add client classes (if any)
4943 for (auto const& class_name : scenario.classes_) {
4944 ctx.query_->addClass(class_name);
4945 }
4946
4947 // Add client option (if one)
4948 if (scenario.requested_lft_) {
4949 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME,
4950 scenario.requested_lft_));
4951 ctx.query_->addOption(opt);
4952 }
4953
4954 Lease4Ptr lease = engine.allocateLease4(ctx);
4955 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"
, 4955, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
4956 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"
, 4956, gtest_ar.failure_message()) = ::testing::Message()
;
4957 }
4958 }
4959}
4960
4961// Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate
4962// lifetime value based on the context content.
4963TEST_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"
, 4963), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4963), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 4963), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getTemplateClassValidLft4_Test
>); void AllocEngine4Test_getTemplateClassValidLft4_Test::
TestBody()
{
4964 AllocEngine engine(0);
4965
4966 // Let's make three classes, two with valid-lifetime and one without,
4967 // and add them to the dictionary.
4968 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
4969 ExpressionPtr match_expr;
4970 ExpressionParser parser;
4971
4972 ElementPtr test_cfg = Element::create("'valid_one_value'");
4973 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
4974
4975 ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr));
4976 Triplet<uint32_t> valid_one(50, 100, 150);
4977 class_def->setValid(valid_one);
4978 dictionary->addClass(class_def);
4979
4980 test_cfg = Element::create("'valid_two_value'");
4981 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
4982
4983 class_def.reset(new TemplateClientClassDef("valid_two", match_expr));
4984 Triplet<uint32_t>valid_two(200, 250, 300);
4985 class_def->setValid(valid_two);
4986 dictionary->addClass(class_def);
4987
4988 test_cfg = Element::create("'valid_unspec_value'");
4989 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
4990
4991 class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr));
4992 dictionary->addClass(class_def);
4993
4994 // Commit our class changes.
4995 CfgMgr::instance().commit();
4996
4997 // Update the subnet's triplet to something more useful.
4998 subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500));
4999
5000 // Describes a test scenario.
5001 struct Scenario {
5002 std::string desc_; // descriptive text for logging
5003 std::vector<std::string> classes_; // class list of assigned classes
5004 uint32_t requested_lft_; // use as option 51 is > 0
5005 uint32_t exp_valid_; // expected lifetime
5006 };
5007
5008 // Scenarios to test.
5009 std::vector<Scenario> scenarios = {
5010 {
5011 "BOOTP",
5012 { "BOOTP" },
5013 0,
5014 Lease::INFINITY_LFT
5015 },
5016 {
5017 "no classes, no option",
5018 {},
5019 0,
5020 subnet_->getValid()
5021 },
5022 {
5023 "no classes, option",
5024 {},
5025 subnet_->getValid().getMin() + 50,
5026 subnet_->getValid().getMin() + 50
5027 },
5028 {
5029 "no classes, option too small",
5030 {},
5031 subnet_->getValid().getMin() - 50,
5032 subnet_->getValid().getMin()
5033 },
5034 {
5035 "no classes, option too big",
5036 {},
5037 subnet_->getValid().getMax() + 50,
5038 subnet_->getValid().getMax()
5039 },
5040 {
5041 "class unspecified, no option",
5042 { "valid_unspec" },
5043 0,
5044 subnet_->getValid()
5045 },
5046 {
5047 "from last class, no option",
5048 { "valid_unspec", "valid_one" },
5049 0,
5050 valid_one.get()
5051 },
5052 {
5053 "from first class, no option",
5054 { "valid_two", "valid_one" },
5055 0,
5056 valid_two.get()
5057 },
5058 {
5059 "class plus option",
5060 { "valid_one" },
5061 valid_one.getMin() + 25,
5062 valid_one.getMin() + 25
5063 },
5064 {
5065 "class plus option too small",
5066 { "valid_one" },
5067 valid_one.getMin() - 25,
5068 valid_one.getMin()
5069 },
5070 {
5071 "class plus option too big",
5072 { "valid_one" },
5073 valid_one.getMax() + 25,
5074 valid_one.getMax()
5075 }
5076 };
5077
5078 // Iterate over the scenarios and verify the correct outcome.
5079 for (auto const& scenario : scenarios) {
5080 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5080( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5080, (scenario.desc_))
; {
5081 // Create a context;
5082 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
5083 IOAddress("0.0.0.0"), false, false,
5084 "", false);
5085 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5086
5087 // Add client classes (if any)
5088 for (auto const& class_name : scenario.classes_) {
5089 if (class_name == "BOOTP") {
5090 ctx.query_->addClass(class_name);
5091 } else {
5092 string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX);
5093 subclass += class_name;
5094 subclass += "_value";
5095 ctx.query_->addSubClass(class_name, subclass);
5096 }
5097 }
5098
5099 // Add client option (if one)
5100 if (scenario.requested_lft_) {
5101 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME,
5102 scenario.requested_lft_));
5103 ctx.query_->addOption(opt);
5104 }
5105
5106 Lease4Ptr lease = engine.allocateLease4(ctx);
5107 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"
, 5107, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5108 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"
, 5108, gtest_ar.failure_message()) = ::testing::Message()
;
5109 }
5110 }
5111}
5112
5113// Verifies that AllocEngine::getMinValidLft(ctx4, valid) sets the appropriate
5114// lifetime value based on the context content.
5115TEST_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", 5115
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5115), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5115), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getMinValidLft4_Test
>); void AllocEngine4Test_getMinValidLft4_Test::TestBody()
{
5116 AllocEngine engine(0);
5117
5118 // Let's make three classes, two with valid-lifetime and one without,
5119 // and add them to the dictionary.
5120 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
5121 ExpressionPtr match_expr;
5122 ExpressionParser parser;
5123
5124 ElementPtr test_cfg = Element::create("'valid_one_value'");
5125 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5126
5127 ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr));
5128 Triplet<uint32_t> valid_one(50, 100, 150);
5129 class_def->setValid(valid_one);
5130 dictionary->addClass(class_def);
5131
5132 test_cfg = Element::create("'valid_two_value'");
5133 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5134
5135 class_def.reset(new TemplateClientClassDef("valid_two", match_expr));
5136 Triplet<uint32_t>valid_two(200, 250, 300);
5137 class_def->setValid(valid_two);
5138 dictionary->addClass(class_def);
5139
5140 test_cfg = Element::create("'valid_unspec_value'");
5141 parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING);
5142
5143 class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr));
5144 dictionary->addClass(class_def);
5145
5146 // Commit our class changes.
5147 CfgMgr::instance().commit();
5148
5149 // Update the subnet's triplet to something more useful.
5150 subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500));
5151
5152 // Describes a test scenario.
5153 struct Scenario {
5154 std::string desc_; // descriptive text for logging
5155 std::vector<std::string> classes_; // class list of assigned classes
5156 uint32_t requested_lft_; // use as option 51 is > 0
5157 uint32_t remaining_lft_; // remaining lifime or 0
5158 uint32_t exp_valid_; // expected lifetime
5159 };
5160
5161 // Scenarios to test.
5162 std::vector<Scenario> scenarios = {
5163 {
5164 "BOOTP",
5165 { "BOOTP" },
5166 0,
5167 0,
5168 Lease::INFINITY_LFT
5169 },
5170 {
5171 "no classes, no option, remain 0",
5172 {},
5173 0,
5174 0,
5175 subnet_->getValid().getMin()
5176 },
5177 {
5178 "no classes, no option, remain too small",
5179 {},
5180 0,
5181 100,
5182 subnet_->getValid().getMin()
5183 },
5184 {
5185 "no classes, no option, remain",
5186 {},
5187 0,
5188 800,
5189 800
5190 },
5191 {
5192 "no classes, option, remain 0",
5193 {},
5194 1000,
5195 0,
5196 subnet_->getValid().getMin()
5197 },
5198 {
5199 "class unspecified, no option, remain 0",
5200 { "valid_unspec" },
5201 0,
5202 0,
5203 subnet_->getValid().getMin()
5204 },
5205 {
5206 "from last class, no option, remain 0",
5207 { "valid_unspec", "valid_one" },
5208 0,
5209 0,
5210 valid_one.getMin()
5211 },
5212 {
5213 "from first class, no option, remain 0",
5214 { "valid_two", "valid_one" },
5215 0,
5216 0,
5217 valid_two.getMin()
5218 },
5219 {
5220 "class plus remain too small",
5221 { "valid_one" },
5222 0,
5223 10,
5224 valid_one.getMin(),
5225 },
5226 {
5227 "class plus remain",
5228 { "valid_one" },
5229 0,
5230 100,
5231 100
5232 }
5233 };
5234
5235 // Iterate over the scenarios and verify the correct outcome.
5236 for (auto const& scenario : scenarios) {
5237 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5237( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5237, (scenario.desc_))
; {
5238 // Create a context;
5239 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
5240 IOAddress("0.0.0.0"), false, false,
5241 "", false);
5242 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5243
5244 // Add client classes (if any)
5245 for (auto const& class_name : scenario.classes_) {
5246 if (class_name == "BOOTP") {
5247 ctx.query_->addClass(class_name);
5248 } else {
5249 string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX);
5250 subclass += class_name;
5251 subclass += "_value";
5252 ctx.query_->addSubClass(class_name, subclass);
5253 }
5254 }
5255
5256 // Add client option (if one)
5257 if (scenario.requested_lft_) {
5258 OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME,
5259 scenario.requested_lft_));
5260 ctx.query_->addOption(opt);
5261 }
5262
5263 uint32_t valid = scenario.remaining_lft_;
5264 engine.getMinValidLft(ctx, valid);
5265 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"
, 5265, gtest_ar.failure_message()) = ::testing::Message()
;
5266 }
5267 }
5268}
5269
5270// Verifies that AllocEngine::getRemaining retuns the remaining lifetime value.
5271TEST_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", 5271
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5271), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5271), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getRemaining_Test
>); void AllocEngine4Test_getRemaining_Test::TestBody()
{
5272 // No Lease.
5273 uint32_t valid(1);
5274 Lease4Ptr lease;
5275 AllocEngine::getRemaining(lease, valid);
5276 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"
, 5276, gtest_ar.failure_message()) = ::testing::Message()
;
5277
5278 // Unexpected state.
5279 valid = 1;
5280 uint8_t hwaddr_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
5281 HWAddrPtr hwaddr(new HWAddr(hwaddr_data, sizeof(hwaddr_data), HTYPE_ETHER));
5282 uint8_t clientid[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
5283 time_t now = time(0);
5284 lease.reset(new Lease4(IOAddress("192.0.2.100"), hwaddr, clientid,
5285 sizeof(clientid), 100, now, 1));
5286 lease->state_ = Lease::STATE_DECLINED;
5287 AllocEngine::getRemaining(lease, valid);
5288 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"
, 5288, gtest_ar.failure_message()) = ::testing::Message()
;
5289
5290 // Infinite lifetime.
5291 lease->state_ = Lease::STATE_DEFAULT;
5292 uint32_t infinity_lft = Lease::INFINITY_LFT;
5293 lease->valid_lft_ = lease->current_valid_lft_ = infinity_lft;
5294 AllocEngine::getRemaining(lease, valid);
5295 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"
, 5295, gtest_ar.failure_message()) = ::testing::Message()
;
5296
5297 // Time going backward.
5298 lease->cltt_ = lease->current_cltt_ = now + 100;
5299 lease->valid_lft_ = lease->current_valid_lft_ = 50;
5300 AllocEngine::getRemaining(lease, valid);
5301 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"
, 5301, gtest_ar.failure_message()) = ::testing::Message()
;
5302
5303 // Already expired.
5304 valid = 1;
5305 lease->cltt_ = lease->current_cltt_ = now - 100;
5306 AllocEngine::getRemaining(lease, valid);
5307 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"
, 5307, gtest_ar.failure_message()) = ::testing::Message()
;
5308
5309 // Valid case.
5310 now = time(0);
5311 lease->cltt_ = lease->current_cltt_ = now - 10;
5312 AllocEngine::getRemaining(lease, valid);
5313 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"
, 5313, gtest_ar.failure_message()) = ::testing::Message()
;
5314}
5315
5316// This test checks that deleteRelease handles BOOTP leases.
5317TEST_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", 5317
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5317), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5317), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpDelete_Test
>); void AllocEngine4Test_bootpDelete_Test::TestBody()
{
5318 boost::scoped_ptr<AllocEngine> engine;
5319 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_5319
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5319
; } } else gtest_label_testnothrow_5319 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5319, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5320 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"
, 5320, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5321
5322 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
5323 false, true, "somehost.example.com.", false);
5324 subnet_->setValid(Triplet<uint32_t>(1, 3, 5));
5325 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
5326
5327 // Make the query a BOOTP one.
5328 ctx.query_->addClass("BOOTP");
5329
5330 Lease4Ptr lease = engine->allocateLease4(ctx);
5331 // The new lease has been allocated, so the old lease should not exist.
5332 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"
, 5332, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message
()
;
5333
5334 // Check that we got a lease
5335 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"
, 5335, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5336
5337 // Check that is belongs to the right subnet and client.
5338 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"
, 5338, gtest_ar.failure_message()) = ::testing::Message()
;
5339 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"
, 5339, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inRange(lease->addr_)", "false", "true") .c_str
()) = ::testing::Message()
;
5340 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"
, 5340, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false"
, "true") .c_str()) = ::testing::Message()
;
5341 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"
, 5341, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->client_id_", "false", "true") .c_str()) = ::testing
::Message()
;
5342 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"
, 5342, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->client_id_ == *clientid_", "false", "true") .c_str
()) = ::testing::Message()
;
5343 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"
, 5343, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->hwaddr_", "false", "true") .c_str()) = ::testing
::Message()
;
5344 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"
, 5344, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str()
) = ::testing::Message()
;
5345
5346 // Check the valid lifetime is infinite.
5347 uint32_t infinity_lft = Lease::INFINITY_LFT;
5348 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"
, 5348, gtest_ar.failure_message()) = ::testing::Message()
;
5349
5350 // Check that the lease is indeed in LeaseMgr
5351 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5352 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"
, 5352, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5353
5354 // Now delete it.
5355 bool deleted = false;
5356 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_5356; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_5356; } } else gtest_label_testnothrow_5356
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5356, ("Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
5357 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",
5357, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "deleted", "false", "true") .c_str()) = ::testing::Message(
)
;
5358 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5359 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",
5359, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "true", "false") .c_str()) = ::testing::Message
()
;
5360}
5361
5362// This test verifies that all addresses in a pool can be allocated.
5363TEST_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", 5363
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5363), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5363), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullPool_Test
>); void AllocEngine4Test_fullPool_Test::TestBody()
{
5364 boost::scoped_ptr<AllocEngine> engine;
5365 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_5365
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5365
; } } else gtest_label_testnothrow_5365 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5365, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5366 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"
, 5366, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5367
5368 // Get rid of the default subnet configuration.
5369 CfgMgr& cfg_mgr = CfgMgr::instance();
5370 cfg_mgr.clear();
5371
5372 // Configure a larger subnet with a /24 pool.
5373 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5374 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5375 subnet_->addPool(pool_);
5376 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5377
5378 // Set exclude-first-last to false.
5379 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false);
5380 cfg_mgr.commit();
5381
5382 size_t cnt = 0;
5383 vector<bool> found(256, false);
5384 while (true) {
5385 vector<uint8_t> duid = clientid_->getClientId();
5386 duid[6] = cnt >> 8;
5387 duid[7] = cnt & 0xff;
5388 ClientIdPtr clientid(new ClientId(duid));
5389 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5390 hwaddr->hwaddr_[4] = cnt >> 8;
5391 hwaddr->hwaddr_[5] = cnt & 0xff;
5392 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5393 IOAddress("0.0.0.0"),
5394 false, false, "foo.bar", false);
5395 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5396 Lease4Ptr lease = engine->allocateLease4(ctx);
5397
5398 if (!lease) {
5399 break;
5400 }
5401 const vector<uint8_t>& addr = lease->addr_.toBytes();
5402 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"
, 5402, gtest_ar.failure_message()) = ::testing::Message()
;
5403 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"
, 5403, gtest_ar.failure_message()) = ::testing::Message()
;
5404 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"
, 5404, gtest_ar.failure_message()) = ::testing::Message()
;
5405 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"
, 5405, gtest_ar.failure_message()) = ::testing::Message()
;
5406 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"
, 5406, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5407 found[addr[3]] = true;
5408 ++cnt;
5409 // Catch unbound loop.
5410 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"
, 5410, gtest_ar.failure_message()) = ::testing::Message()
;
5411 }
5412 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"
, 5412, gtest_ar.failure_message()) = ::testing::Message()
;
5413 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"
, 5413, gtest_ar.failure_message()) = ::testing::Message()
;
5414}
5415
5416// This test verifies that all addresses in a subnet can be allocated.
5417TEST_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", 5417
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5417), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5417), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullSubnet24_Test
>); void AllocEngine4Test_fullSubnet24_Test::TestBody()
{
5418 boost::scoped_ptr<AllocEngine> engine;
5419 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_5419
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5419
; } } else gtest_label_testnothrow_5419 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5419, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5420 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"
, 5420, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5421
5422 // Get rid of the default subnet configuration.
5423 CfgMgr& cfg_mgr = CfgMgr::instance();
5424 cfg_mgr.clear();
5425
5426 // Configure a larger subnet with a /24 pool.
5427 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
5428 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"),
5429 IOAddress("192.0.2.255")));
5430 subnet_->addPool(pool_);
5431 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5432
5433 // Set exclude-first-last to false.
5434 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false);
5435 cfg_mgr.commit();
5436
5437 size_t cnt = 0;
5438 vector<bool> found(256, false);
5439 while (true) {
5440 vector<uint8_t> duid = clientid_->getClientId();
5441 duid[6] = cnt >> 8;
5442 duid[7] = cnt & 0xff;
5443 ClientIdPtr clientid(new ClientId(duid));
5444 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5445 hwaddr->hwaddr_[4] = cnt >> 8;
5446 hwaddr->hwaddr_[5] = cnt & 0xff;
5447 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5448 IOAddress("0.0.0.0"),
5449 false, false, "foo.bar", false);
5450 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5451 Lease4Ptr lease = engine->allocateLease4(ctx);
5452
5453 if (!lease) {
5454 break;
5455 }
5456 const vector<uint8_t>& addr = lease->addr_.toBytes();
5457 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"
, 5457, gtest_ar.failure_message()) = ::testing::Message()
;
5458 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"
, 5458, gtest_ar.failure_message()) = ::testing::Message()
;
5459 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"
, 5459, gtest_ar.failure_message()) = ::testing::Message()
;
5460 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"
, 5460, gtest_ar.failure_message()) = ::testing::Message()
;
5461 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"
, 5461, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5462 found[addr[3]] = true;
5463 ++cnt;
5464 // Catch unbound loop.
5465 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"
, 5465, gtest_ar.failure_message()) = ::testing::Message()
;
5466 }
5467 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"
, 5467, gtest_ar.failure_message()) = ::testing::Message()
;
5468 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"
, 5468, gtest_ar.failure_message()) = ::testing::Message()
;
5469}
5470
5471// This test verifies that not all addresses in a pool can be allocated when
5472// exclude-first-last is true.
5473TEST_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"
, 5473), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5473), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5473), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast_Test
>); void AllocEngine4Test_excludeFirstLast_Test::TestBody(
)
{
5474 boost::scoped_ptr<AllocEngine> engine;
5475 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_5475
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5475
; } } else gtest_label_testnothrow_5475 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5475, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5476 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"
, 5476, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5477
5478 // Get rid of the default subnet configuration.
5479 CfgMgr& cfg_mgr = CfgMgr::instance();
5480 cfg_mgr.clear();
5481
5482 // Configure a larger subnet with a /24 pool.
5483 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5484 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5485 subnet_->addPool(pool_);
5486 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5487
5488 // Set exclude-first-last to true.
5489 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5490 cfg_mgr.commit();
5491
5492 size_t cnt = 0;
5493 vector<bool> found(256, false);
5494 while (true) {
5495 vector<uint8_t> duid = clientid_->getClientId();
5496 duid[6] = cnt >> 8;
5497 duid[7] = cnt & 0xff;
5498 ClientIdPtr clientid(new ClientId(duid));
5499 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5500 hwaddr->hwaddr_[4] = cnt >> 8;
5501 hwaddr->hwaddr_[5] = cnt & 0xff;
5502 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5503 IOAddress("0.0.0.0"),
5504 false, false, "foo.bar", false);
5505 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5506 Lease4Ptr lease = engine->allocateLease4(ctx);
5507
5508 if (!lease) {
5509 break;
5510 }
5511 const vector<uint8_t>& addr = lease->addr_.toBytes();
5512 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"
, 5512, gtest_ar.failure_message()) = ::testing::Message()
;
5513 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"
, 5513, gtest_ar.failure_message()) = ::testing::Message()
;
5514 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"
, 5514, gtest_ar.failure_message()) = ::testing::Message()
;
5515 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"
, 5515, gtest_ar.failure_message()) = ::testing::Message()
;
5516 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"
, 5516, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5517 found[addr[3]] = true;
5518 ++cnt;
5519 // Catch unbound loop.
5520 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"
, 5520, gtest_ar.failure_message()) = ::testing::Message()
;
5521 }
5522 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"
, 5522, gtest_ar.failure_message()) = ::testing::Message()
;
5523 vector<bool> expected(256, true);
5524 expected[0] = false;
5525 expected[255] = false;
5526 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"
, 5526, gtest_ar.failure_message()) = ::testing::Message()
;
5527}
5528
5529// This test verifies that not all addresses in a subnet can be allocated when
5530// exclude-first-last is true.
5531TEST_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"
, 5531), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5531), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5531), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast24_Test
>); void AllocEngine4Test_excludeFirstLast24_Test::TestBody
()
{
5532 boost::scoped_ptr<AllocEngine> engine;
5533 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_5533
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5533
; } } else gtest_label_testnothrow_5533 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5533, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5534 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"
, 5534, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5535
5536 // Get rid of the default subnet configuration.
5537 CfgMgr& cfg_mgr = CfgMgr::instance();
5538 cfg_mgr.clear();
5539
5540 // Configure a larger subnet with a /24 pool.
5541 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
5542 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"),
5543 IOAddress("192.0.2.255")));
5544 subnet_->addPool(pool_);
5545 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5546
5547 // Set exclude-first-last to true.
5548 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5549 cfg_mgr.commit();
5550
5551 size_t cnt = 0;
5552 vector<bool> found(256, false);
5553 while (true) {
5554 vector<uint8_t> duid = clientid_->getClientId();
5555 duid[6] = cnt >> 8;
5556 duid[7] = cnt & 0xff;
5557 ClientIdPtr clientid(new ClientId(duid));
5558 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5559 hwaddr->hwaddr_[4] = cnt >> 8;
5560 hwaddr->hwaddr_[5] = cnt & 0xff;
5561 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5562 IOAddress("0.0.0.0"),
5563 false, false, "foo.bar", false);
5564 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5565 Lease4Ptr lease = engine->allocateLease4(ctx);
5566
5567 if (!lease) {
5568 break;
5569 }
5570 const vector<uint8_t>& addr = lease->addr_.toBytes();
5571 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"
, 5571, gtest_ar.failure_message()) = ::testing::Message()
;
5572 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"
, 5572, gtest_ar.failure_message()) = ::testing::Message()
;
5573 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"
, 5573, gtest_ar.failure_message()) = ::testing::Message()
;
5574 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"
, 5574, gtest_ar.failure_message()) = ::testing::Message()
;
5575 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"
, 5575, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5576 found[addr[3]] = true;
5577 ++cnt;
5578 // Catch unbound loop.
5579 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"
, 5579, gtest_ar.failure_message()) = ::testing::Message()
;
5580 }
5581 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"
, 5581, gtest_ar.failure_message()) = ::testing::Message()
;
5582 vector<bool> expected(256, true);
5583 expected[0] = false;
5584 expected[255] = false;
5585 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"
, 5585, gtest_ar.failure_message()) = ::testing::Message()
;
5586}
5587
5588// This test verifies that all addresses in a subnet can be allocated when
5589// exclude-first-last is true but the prefix length is greater than 24.
5590TEST_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", 5590
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5590), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5590), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirst25_Test
>); void AllocEngine4Test_excludeFirst25_Test::TestBody()
{
5591 boost::scoped_ptr<AllocEngine> engine;
5592 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_5592
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5592
; } } else gtest_label_testnothrow_5592 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5592, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5593 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"
, 5593, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5594
5595 // Get rid of the default subnet configuration.
5596 CfgMgr& cfg_mgr = CfgMgr::instance();
5597 cfg_mgr.clear();
5598
5599 // Configure a smaller subnet with a /25 pool.
5600 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 25, 1, 2, 3, SubnetID(10));
5601 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"),
5602 IOAddress("192.0.2.127")));
5603 subnet_->addPool(pool_);
5604 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5605
5606 // Set exclude-first-last to true.
5607 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5608 cfg_mgr.commit();
5609
5610 size_t cnt = 0;
5611 vector<bool> found(128, false);
5612 while (true) {
5613 vector<uint8_t> duid = clientid_->getClientId();
5614 duid[6] = cnt >> 8;
5615 duid[7] = cnt & 0xff;
5616 ClientIdPtr clientid(new ClientId(duid));
5617 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5618 hwaddr->hwaddr_[4] = cnt >> 8;
5619 hwaddr->hwaddr_[5] = cnt & 0xff;
5620 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5621 IOAddress("0.0.0.0"),
5622 false, false, "foo.bar", false);
5623 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5624 Lease4Ptr lease = engine->allocateLease4(ctx);
5625
5626 if (!lease) {
5627 break;
5628 }
5629 const vector<uint8_t>& addr = lease->addr_.toBytes();
5630 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"
, 5630, gtest_ar.failure_message()) = ::testing::Message()
;
5631 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"
, 5631, gtest_ar.failure_message()) = ::testing::Message()
;
5632 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"
, 5632, gtest_ar.failure_message()) = ::testing::Message()
;
5633 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"
, 5633, gtest_ar.failure_message()) = ::testing::Message()
;
5634 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"
, 5634, gtest_ar.failure_message()) = ::testing::Message()
;
5635 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"
, 5635, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message
()
;
5636 found[addr[3]] = true;
5637 ++cnt;
5638 // Catch unbound loop.
5639 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"
, 5639, gtest_ar.failure_message()) = ::testing::Message()
;
5640 }
5641 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"
, 5641, gtest_ar.failure_message()) = ::testing::Message()
;
5642 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"
, 5642, gtest_ar.failure_message()) = ::testing::Message()
;
5643}
5644
5645// This test verifies that all addresses in a subnet can be allocated when
5646// exclude-first-last is true but the prefix length is greater than 24.
5647TEST_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", 5647
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5647), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5647), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeLast25_Test
>); void AllocEngine4Test_excludeLast25_Test::TestBody()
{
5648 boost::scoped_ptr<AllocEngine> engine;
5649 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_5649
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5649
; } } else gtest_label_testnothrow_5649 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5649, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5650 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"
, 5650, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5651
5652 // Get rid of the default subnet configuration.
5653 CfgMgr& cfg_mgr = CfgMgr::instance();
5654 cfg_mgr.clear();
5655
5656 // Configure a smaller subnet with a /25 pool.
5657 subnet_ = Subnet4::create(IOAddress("192.0.2.128"), 25, 1, 2, 3, SubnetID(10));
5658 pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.128"),
5659 IOAddress("192.0.2.255")));
5660 subnet_->addPool(pool_);
5661 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5662
5663 // Set exclude-first-last to true.
5664 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5665 cfg_mgr.commit();
5666
5667 size_t cnt = 0;
5668 vector<bool> found(128, false);
5669 while (true) {
5670 vector<uint8_t> duid = clientid_->getClientId();
5671 duid[6] = cnt >> 8;
5672 duid[7] = cnt & 0xff;
5673 ClientIdPtr clientid(new ClientId(duid));
5674 HWAddrPtr hwaddr(new HWAddr(*hwaddr_));
5675 hwaddr->hwaddr_[4] = cnt >> 8;
5676 hwaddr->hwaddr_[5] = cnt & 0xff;
5677 AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr,
5678 IOAddress("0.0.0.0"),
5679 false, false, "foo.bar", false);
5680 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt));
5681 Lease4Ptr lease = engine->allocateLease4(ctx);
5682
5683 if (!lease) {
5684 break;
5685 }
5686 const vector<uint8_t>& addr = lease->addr_.toBytes();
5687 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"
, 5687, gtest_ar.failure_message()) = ::testing::Message()
;
5688 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"
, 5688, gtest_ar.failure_message()) = ::testing::Message()
;
5689 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"
, 5689, gtest_ar.failure_message()) = ::testing::Message()
;
5690 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"
, 5690, gtest_ar.failure_message()) = ::testing::Message()
;
5691 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"
, 5691, gtest_ar.failure_message()) = ::testing::Message()
;
5692 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"
, 5692, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "found[addr[3] - 128]", "true", "false") .c_str()) = ::testing
::Message()
;
5693 found[addr[3] - 128] = true;
5694 ++cnt;
5695 // Catch unbound loop.
5696 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"
, 5696, gtest_ar.failure_message()) = ::testing::Message()
;
5697 }
5698 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"
, 5698, gtest_ar.failure_message()) = ::testing::Message()
;
5699 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"
, 5699, gtest_ar.failure_message()) = ::testing::Message()
;
5700}
5701
5702// This test verifies that an excluded address can be allocated when requested
5703// and exclude-first-last is true.
5704TEST_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"
, 5704), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5704), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5704), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastRequested_Test
>); void AllocEngine4Test_excludeFirstLastRequested_Test::
TestBody()
{
5705 boost::scoped_ptr<AllocEngine> engine;
5706 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_5706
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5706
; } } else gtest_label_testnothrow_5706 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5706, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5707 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"
, 5707, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5708
5709 // Get rid of the default subnet configuration.
5710 CfgMgr& cfg_mgr = CfgMgr::instance();
5711 cfg_mgr.clear();
5712
5713 // Configure a larger subnet with a /24 pool.
5714 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5715 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5716 subnet_->addPool(pool_);
5717 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5718
5719 // Set exclude-first-last to true.
5720 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5721 cfg_mgr.commit();
5722
5723 // Request the first address.
5724 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
5725 IOAddress("10.0.1.0"),
5726 false, false, "foo.bar", false);
5727 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
5728 Lease4Ptr lease = engine->allocateLease4(ctx);
5729 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"
, 5729, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5730 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"
, 5730, gtest_ar.failure_message()) = ::testing::Message()
;
5731
5732 // Request the last address.
5733 AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_,
5734 IOAddress("10.0.1.255"),
5735 false, false, "bar.foo", false);
5736 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345));
5737 lease = engine->allocateLease4(ctx2);
5738 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"
, 5738, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5739 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"
, 5739, gtest_ar.failure_message()) = ::testing::Message()
;
5740}
5741
5742// This test verifies that an excluded address can be allocated when reserved
5743// and exclude-first-last is true.
5744TEST_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"
, 5744), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5744), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5744), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastReserver_Test
>); void AllocEngine4Test_excludeFirstLastReserver_Test::TestBody
()
{
5745 boost::scoped_ptr<AllocEngine> engine;
5746 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_5746
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5746
; } } else gtest_label_testnothrow_5746 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5746, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5747 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"
, 5747, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5748
5749 // Get rid of the default subnet configuration.
5750 CfgMgr& cfg_mgr = CfgMgr::instance();
5751 cfg_mgr.clear();
5752
5753 // Configure a larger subnet with a /24 pool.
5754 subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10));
5755 pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255")));
5756 subnet_->addPool(pool_);
5757 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5758
5759 // Set exclude-first-last to true.
5760 cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true);
5761
5762 // Add reservations.
5763 HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
5764 Host::IDENT_HWADDR, subnet_->getID(),
5765 SUBNET_ID_UNUSED, IOAddress("10.0.1.0")));
5766 cfg_mgr.getStagingCfg()->getCfgHosts()->add(host);
5767 HostPtr host2(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(),
5768 Host::IDENT_HWADDR, subnet_->getID(),
5769 SUBNET_ID_UNUSED, IOAddress("10.0.1.255")));
5770 cfg_mgr.getStagingCfg()->getCfgHosts()->add(host2);
5771 subnet_->setReservationsInSubnet(true);
5772 subnet_->setReservationsOutOfPool(false);
5773 cfg_mgr.commit();
5774
5775 // Request the first address.
5776 AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
5777 IOAddress("0.0.0.0"),
5778 false, false, "foo.bar", false);
5779 ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
5780 AllocEngine::findReservation(ctx);
5781 Lease4Ptr lease = engine->allocateLease4(ctx);
5782 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"
, 5782, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5783 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"
, 5783, gtest_ar.failure_message()) = ::testing::Message()
;
5784
5785 // Request the last address.
5786 AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_,
5787 IOAddress("0.0.0.0"),
5788 false, false, "bar.foo", false);
5789 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345));
5790 AllocEngine::findReservation(ctx2);
5791 lease = engine->allocateLease4(ctx2);
5792 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"
, 5792, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5793 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"
, 5793, gtest_ar.failure_message()) = ::testing::Message()
;
5794}
5795
5796// Verifies that offer_lft is non-zero, that an offered lease is stored
5797// in the lease database.
5798TEST_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"
, 5798), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5798), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5798), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLft_Test
>); void AllocEngine4Test_discoverOfferLft_Test::TestBody(
)
{
5799 boost::scoped_ptr<AllocEngine> engine;
5800 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_5800
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5800
; } } else gtest_label_testnothrow_5800 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5800, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5801 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"
, 5801, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5802
5803 IOAddress addr("192.0.2.15");
5804 CfgMgr& cfg_mgr = CfgMgr::instance();
5805 // Get rid of the default test configuration.
5806 cfg_mgr.clear();
5807
5808 // Create configuration similar to other tests, but with a single address pool
5809 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
5810 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
5811 subnet_->addPool(pool_);
5812
5813 // Set subnet's offer-lifetime to a non-zero, positive value.
5814 uint32_t offer_lft = (subnet_->getValid() / 3);
5815 subnet_->setOfferLft(offer_lft);
5816 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"
, 5816, gtest_ar.failure_message()) = ::testing::Message()
;
5817
5818 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5819
5820 // Ask for any address
5821 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
5822 IOAddress("0.0.0.0"), true, true,
5823 "one", true);
5824 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5825
5826 // Check that we got that single lease
5827 Lease4Ptr lease = engine->allocateLease4(ctx1);
5828 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"
, 5828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5829 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"
, 5829, gtest_ar.failure_message()) = ::testing::Message()
;
5830 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"
, 5830, gtest_ar.failure_message()) = ::testing::Message()
;
5831 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"
, 5831, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
5832 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"
, 5832, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
5833
5834 // Check that the lease has been stored by LeaseMgr.
5835 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5836 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"
, 5836, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5837 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"
, 5837, gtest_ar.failure_message()) = ::testing::Message()
;
5838 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"
, 5838, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
5839 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"
, 5839, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
5840
5841 // Try to discover an address for a second client.
5842 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
5843 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
5844
5845 // Ask for any address.
5846 AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2,
5847 IOAddress("0.0.0.0"), true, true,
5848 "two", true);
5849 ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1235));
5850
5851 // Verify that we did not get a lease.
5852 lease = engine->allocateLease4(ctx2);
5853 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"
, 5853, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "true", "false") .c_str()) = ::testing::Message()
;
5854
5855 // Original client now does a DHCPREQUEST. Make sure we get the
5856 // previously offered lease with the proper valid lifetime.
5857 AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_,
5858 IOAddress("0.0.0.0"), true, true,
5859 "one", false);
5860 ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1236));
5861
5862 lease = engine->allocateLease4(ctx3);
5863 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"
, 5863, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5864 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"
, 5864, gtest_ar.failure_message()) = ::testing::Message()
;
5865 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5866 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"
, 5866, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5867 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"
, 5867, gtest_ar.failure_message()) = ::testing::Message()
;
5868}
5869
5870// Verifies that when offer_lft is non-zero, that an existing lease is
5871// whose remaining life is larger than offer_lft, is offered as is.
5872TEST_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"
, 5872), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5872), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5872), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
>); void AllocEngine4Test_discoverOfferLftUseExistingLease4_Test
::TestBody()
{
5873 boost::scoped_ptr<AllocEngine> engine;
5874 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_5874
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5874
; } } else gtest_label_testnothrow_5874 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5874, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5875 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"
, 5875, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5876
5877 IOAddress addr("192.0.2.15");
5878 CfgMgr& cfg_mgr = CfgMgr::instance();
5879 // Get rid of the default test configuration.
5880 cfg_mgr.clear();
5881
5882 // Create configuration similar to other tests, but with a single address pool
5883 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 300, SubnetID(10));
5884 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
5885 subnet_->addPool(pool_);
5886
5887 // Set subnet's offer-lifetime to a non-zero, positive value.
5888 uint32_t offer_lft = 100;
5889 subnet_->setOfferLft(offer_lft);
5890 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"
, 5890, gtest_ar.failure_message()) = ::testing::Message()
;
5891
5892 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5893
5894 time_t now = time(NULL__null) - 5; // Allocated 5 seconds ago
5895 Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, 300, now,
5896 subnet_->getID(), true, true, "somehost"));
5897
5898 // Copy the lease, so as it can be compared with the old lease returned
5899 // by the allocation engine.
5900 Lease4 original_lease(*lease);
5901
5902 // Lease was assigned 5 seconds ago, its valid lifetime is 300, its
5903 // remaining lifetime is still larger than offer_lft.
5904 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"
, 5904, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "true", "false") .c_str()) = ::testing
::Message()
;
5905 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"
, 5905, gtest_ar.failure_message()) = ::testing::Message()
;
5906 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"
, 5906, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
5907
5908 // CASE 1: Asking for any address
5909 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
5910 IOAddress("0.0.0.0"), false, false,
5911 "", true);
5912 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5913 lease = engine->allocateLease4(ctx1);
5914 // Check that we got that single lease
5915 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"
, 5915, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5916 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"
, 5916, gtest_ar.failure_message()) = ::testing::Message()
;
5917 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"
, 5917, gtest_ar.failure_message()) = ::testing::Message()
;
5918
5919 // We are reusing the existing lease, the old instance should be
5920 // returned. The returned instance should be the same as the original
5921 // lease.
5922 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"
, 5922, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
5923 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"
, 5923, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *ctx1.old_lease_", "false", "true") .c_str
()) = ::testing::Message()
;
5924
5925 // Check that the lease has not been modified by LeaseMgr.
5926 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5927 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"
, 5927, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5928 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"
, 5928, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *from_mgr", "false", "true") .c_str()) =
::testing::Message()
;
5929}
5930
5931// Verifies that when offer_lft is non-zero, that an expired lease can
5932// be reclaimed an offered correctly.
5933TEST_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"
, 5933), (::testing::internal::GetTypeId<AllocEngine4Test>
()), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5933), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5933), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
>); void AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test
::TestBody()
{
5934 boost::scoped_ptr<AllocEngine> engine;
5935 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_5935
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5935
; } } else gtest_label_testnothrow_5935 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 5935, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
5936 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"
, 5936, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "engine", "false", "true") .c_str()) = ::testing::Message()
;
5937
5938 IOAddress addr("192.0.2.15");
5939 CfgMgr& cfg_mgr = CfgMgr::instance();
5940 // Get rid of the default test configuration.
5941 cfg_mgr.clear();
5942
5943 // Create configuration similar to other tests, but with a single address pool
5944 subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10));
5945 pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address
5946 subnet_->addPool(pool_);
5947
5948 // Set subnet's offer-lifetime to a non-zero, positive value.
5949 uint32_t offer_lft = (subnet_->getValid() / 3);
5950 subnet_->setOfferLft(offer_lft);
5951 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"
, 5951, gtest_ar.failure_message()) = ::testing::Message()
;
5952
5953 cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_);
5954
5955 // Just a different hw/client-id for the second client
5956 uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
5957 HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
5958 uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
5959 time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago
5960 Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2),
5961 495, now, subnet_->getID()));
5962 // Copy the lease, so as it can be compared with the old lease returned
5963 // by the allocation engine.
5964 Lease4 original_lease(*lease);
5965
5966 // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it
5967 // is expired already
5968 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"
, 5968, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->expired()", "false", "true") .c_str()) = ::testing
::Message()
;
5969 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"
, 5969, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().addLease(lease)", "false", "true"
) .c_str()) = ::testing::Message()
;
5970
5971 // CASE 1: Asking for any address
5972 AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_,
5973 IOAddress("0.0.0.0"), false, false,
5974 "", true);
5975 ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
5976 lease = engine->allocateLease4(ctx1);
5977 // Check that we got that single lease
5978 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"
, 5978, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
5979 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"
, 5979, gtest_ar.failure_message()) = ::testing::Message()
;
5980 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"
, 5980, gtest_ar.failure_message()) = ::testing::Message()
;
5981 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"
, 5981, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
5982 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"
, 5982, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
5983
5984 // We are reusing expired lease, the old (expired) instance should be
5985 // returned. The returned instance should be the same as the original
5986 // lease.
5987 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"
, 5987, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ctx1.old_lease_", "false", "true") .c_str()) = ::testing::
Message()
;
5988 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"
, 5988, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "original_lease == *ctx1.old_lease_", "false", "true") .c_str
()) = ::testing::Message()
;
5989
5990 // Check that the lease has been stored by LeaseMgr.
5991 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
5992 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"
, 5992, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
5993 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"
, 5993, gtest_ar.failure_message()) = ::testing::Message()
;
5994 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"
, 5994, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing
::Message()
;
5995 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"
, 5995, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing
::Message()
;
5996
5997 // Client now does a DHCPREQUEST. Make sure we get the
5998 // previously offered lease with the proper valid lifetime.
5999 AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_,
6000 IOAddress("0.0.0.0"), true, true,
6001 "one", false);
6002 ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1235));
6003
6004 lease = engine->allocateLease4(ctx2);
6005 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"
, 6005, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
6006 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"
, 6006, gtest_ar.failure_message()) = ::testing::Message()
;
6007 from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
6008 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"
, 6008, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
6009 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"
, 6009, gtest_ar.failure_message()) = ::testing::Message()
;
6010}
6011
6012// Verifies that AllocEngine::getOfferLft(ctx4) returns the appropriate
6013// lifetime value based on the context content.
6014TEST_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", 6014
), (::testing::internal::GetTypeId<AllocEngine4Test>())
, ::testing::internal::SuiteApiResolver< AllocEngine4Test>
::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6014), ::testing::internal::SuiteApiResolver< AllocEngine4Test
>::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6014), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getOfferLft4_Test
>); void AllocEngine4Test_getOfferLft4_Test::TestBody()
{
6015 AllocEngine engine(0);
6016
6017 // Let's make three classes, two with offer-lifetime and one without,
6018 // and add them to the dictionary.
6019 ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
6020
6021 ClientClassDefPtr class_def(new ClientClassDef("offer_lft_one", ExpressionPtr()));
6022 Optional<uint32_t> offer_lft_one(100);
6023 class_def->setOfferLft(offer_lft_one);
6024 dictionary->addClass(class_def);
6025
6026 class_def.reset(new ClientClassDef("offer_lft_two", ExpressionPtr()));
6027 Optional<uint32_t>offer_lft_two(200);
6028 class_def->setOfferLft(offer_lft_two);
6029 dictionary->addClass(class_def);
6030
6031 class_def.reset(new ClientClassDef("offer_lft_zero", ExpressionPtr()));
6032 Optional<uint32_t>offer_lft_zero(0);
6033 class_def->setOfferLft(offer_lft_zero);
6034 dictionary->addClass(class_def);
6035
6036 class_def.reset(new ClientClassDef("offer_lft_unspec", ExpressionPtr()));
6037 dictionary->addClass(class_def);
6038
6039 // Commit our class changes.
6040 CfgMgr::instance().commit();
6041
6042 // Update the subnet's triplet to something more useful.
6043 subnet_->setOfferLft(Optional<uint32_t>(300));
6044
6045 // Describes a test scenario.
6046 struct Scenario {
6047 std::string desc_; // descriptive text for logging
6048 std::vector<std::string> classes_; // class list of assigned classes
6049 uint32_t exp_valid_lft_; // expected lease lifetime
6050 bool exp_allocate_; // true if lease should be allocated
6051 };
6052
6053 bool exp_allocate = true;
6054
6055 // Scenarios to test.
6056 std::vector<Scenario> scenarios = {
6057 {
6058 "BOOTP",
6059 { "BOOTP" },
6060 Lease::INFINITY_LFT,
6061 !exp_allocate,
6062 },
6063 {
6064 "no classes",
6065 {},
6066 subnet_->getOfferLft(),
6067 exp_allocate
6068 },
6069 {
6070 "class unspecified",
6071 { "offer_lft_unspec" },
6072 subnet_->getOfferLft(),
6073 exp_allocate
6074 },
6075 {
6076 "from last class",
6077 { "offer_lft_unspec", "offer_lft_one" },
6078 offer_lft_one.get(),
6079 exp_allocate
6080 },
6081 {
6082 "from first class",
6083 { "offer_lft_two", "offer_lft_one" },
6084 offer_lft_two.get(),
6085 exp_allocate
6086 },
6087 {
6088 // Using class value of zero should override non-zero set at
6089 // subnet level, lease should have actual valid lft
6090 "zero from class",
6091 { "offer_lft_zero" },
6092 subnet_->getValid(),
6093 !exp_allocate
6094 }
6095 };
6096
6097 // Iterate over the scenarios and verify the correct outcome.
6098 for (auto const& scenario : scenarios) {
6099 SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_6099( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc"
, 6099, (scenario.desc_))
; {
6100 // Create a context;
6101 AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_,
6102 IOAddress("0.0.0.0"), false, false,
6103 "", true);
6104 ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
6105
6106 // Add client classes (if any)
6107 for (auto const& class_name : scenario.classes_) {
6108 ctx.query_->addClass(class_name);
6109 }
6110
6111 Lease4Ptr lease = engine.allocateLease4(ctx);
6112 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"
, 6112, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "lease", "false", "true") .c_str()) = ::testing::Message()
;
6113 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"
, 6113, gtest_ar.failure_message()) = ::testing::Message()
;
6114
6115 Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_);
6116 if (!scenario.exp_allocate_) {
6117 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"
, 6117, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "true", "false") .c_str()) = ::testing::Message
()
;
6118 } else {
6119 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"
, 6119, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "from_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
6120 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"
, 6120, gtest_ar.failure_message()) = ::testing::Message()
;
6121 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"
, 6121, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "LeaseMgrFactory::instance().deleteLease(from_mgr)", "false"
, "true") .c_str()) = ::testing::Message()
;
6122 }
6123 }
6124 }
6125}
6126
6127} // namespace test
6128} // namespace dhcp
6129} // namespace isc