| File: | home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpk3qwau10/../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc |
| Warning: | line 4399, column 5 Value stored to 'ret' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 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 | |
| 25 | using namespace std; |
| 26 | using namespace isc::hooks; |
| 27 | using namespace isc::asiolink; |
| 28 | using namespace isc::data; |
| 29 | using namespace isc::stats; |
| 30 | using namespace isc::util; |
| 31 | |
| 32 | namespace isc { |
| 33 | namespace dhcp { |
| 34 | namespace test { |
| 35 | |
| 36 | // This test checks if the v4 Allocation Engine can be instantiated, parses |
| 37 | // parameters string and allocators are created. |
| 38 | TEST_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. |
| 56 | TEST_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. |
| 149 | TEST_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. |
| 181 | TEST_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. |
| 217 | TEST_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. |
| 254 | TEST_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. |
| 291 | TEST_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 |
| 333 | TEST_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 |
| 379 | TEST_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 |
| 412 | TEST_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(0); |
| 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. |
| 457 | TEST_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 |
| 488 | TEST_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 that simple allocation works with match-client-id false |
| 560 | // and empty hardware address. |
| 561 | TEST_F(AllocEngine4Test, emptyHWAlloc4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("emptyHWAlloc4") > 1, "test_name must not be empty" ); class AllocEngine4Test_emptyHWAlloc4_Test : public AllocEngine4Test { public: AllocEngine4Test_emptyHWAlloc4_Test() = default; ~ AllocEngine4Test_emptyHWAlloc4_Test() override = default; AllocEngine4Test_emptyHWAlloc4_Test (const AllocEngine4Test_emptyHWAlloc4_Test &) = delete; AllocEngine4Test_emptyHWAlloc4_Test & operator=( const AllocEngine4Test_emptyHWAlloc4_Test & ) = delete; AllocEngine4Test_emptyHWAlloc4_Test (AllocEngine4Test_emptyHWAlloc4_Test &&) noexcept = delete; AllocEngine4Test_emptyHWAlloc4_Test & operator=( AllocEngine4Test_emptyHWAlloc4_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const AllocEngine4Test_emptyHWAlloc4_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "emptyHWAlloc4", 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_emptyHWAlloc4_Test >); void AllocEngine4Test_emptyHWAlloc4_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 | // Set match-client-id to false. |
| 567 | subnet_->setMatchClientId(false); |
| 568 | |
| 569 | // Set the hardware address to empty. |
| 570 | std::vector<uint8_t> empty; |
| 571 | hwaddr_.reset(new HWAddr(empty, HTYPE_ETHER)); |
| 572 | |
| 573 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 574 | false, true, "somehost.example.com.", false); |
| 575 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 576 | |
| 577 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 578 | // The new lease has been allocated, so the old lease should not exist. |
| 579 | 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" , 579, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 580 | |
| 581 | // Check that we got a lease |
| 582 | 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" , 582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 583 | |
| 584 | // Do all checks on the lease |
| 585 | checkLease4(lease); |
| 586 | |
| 587 | // Check that the lease is indeed in LeaseMgr |
| 588 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 589 | 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" , 589, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 590 | |
| 591 | // Now check that the lease in LeaseMgr has the same parameters |
| 592 | detailCompareLease(lease, from_mgr); |
| 593 | } |
| 594 | |
| 595 | // This test checks if a returning client can renew an |
| 596 | // an existing lease and assigned-leases increments accordingly |
| 597 | TEST_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", 597 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 597), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 597), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleRenew4_Test >); void AllocEngine4Test_simpleRenew4_Test::TestBody() { |
| 598 | boost::scoped_ptr<AllocEngine> engine; |
| 599 | 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_599 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_599 ; } } else gtest_label_testnothrow_599 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 599, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 600 | 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" , 600, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 601 | |
| 602 | 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" , 602, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 603 | 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" , 603, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 604 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 605 | subnet_->getID()); |
| 606 | |
| 607 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 608 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 609 | |
| 610 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 611 | false, true, "somehost.example.com.", false); |
| 612 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 613 | |
| 614 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 615 | |
| 616 | // Check that we got a lease and it's sane |
| 617 | 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" , 617, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 618 | checkLease4(lease); |
| 619 | |
| 620 | // The new lease has been allocated, so the old lease should not exist. |
| 621 | 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" , 621, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 622 | |
| 623 | // We should have incremented assigned-addresses |
| 624 | 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" , 624, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 625 | cumulative += 1; |
| 626 | 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" , 627, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 627 | 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" , 627, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 628 | glbl_assigned += 1; |
| 629 | 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" , 629, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 630 | glbl_cumulative += 1; |
| 631 | 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" , 631, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 632 | |
| 633 | // Do it again, this should amount to the renew of an existing lease |
| 634 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 635 | |
| 636 | // Check that we got a lease and it's sane |
| 637 | 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" , 637, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 638 | checkLease4(lease2); |
| 639 | |
| 640 | // Lease already existed, so old_lease should be set. |
| 641 | 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" , 641, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 642 | |
| 643 | // Should NOT have bumped assigned-addresses |
| 644 | 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" , 644, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 645 | 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" , 646, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 646 | 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" , 646, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 647 | 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" , 647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 648 | 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" , 648, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 649 | } |
| 650 | |
| 651 | // This test checks simple renewal uses the default valid lifetime. |
| 652 | TEST_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", 652 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 652), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 652), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultRenew4_Test >); void AllocEngine4Test_defaultRenew4_Test::TestBody() { |
| 653 | boost::scoped_ptr<AllocEngine> engine; |
| 654 | 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_654 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_654 ; } } else gtest_label_testnothrow_654 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 654, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 655 | 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" , 655, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 656 | |
| 657 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 658 | false, true, "somehost.example.com.", false); |
| 659 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 660 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 661 | |
| 662 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 663 | |
| 664 | // Check that we got a lease and it's sane |
| 665 | 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" , 665, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 666 | checkLease4(lease); |
| 667 | |
| 668 | // Check the valid lifetime has the default. |
| 669 | 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" , 669, gtest_ar.failure_message()) = ::testing::Message(); |
| 670 | |
| 671 | // The new lease has been allocated, so the old lease should not exist. |
| 672 | 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" , 672, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 673 | |
| 674 | // Do it again, this should amount to the renew of an existing lease |
| 675 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 676 | |
| 677 | // Check that we got a lease and it's sane |
| 678 | 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" , 678, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 679 | checkLease4(lease2); |
| 680 | |
| 681 | // Lease already existed, so old_lease should be set. |
| 682 | 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" , 682, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 683 | |
| 684 | // Check the renewed valid lifetime has the default. |
| 685 | 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" , 685, gtest_ar.failure_message()) = ::testing::Message(); |
| 686 | } |
| 687 | |
| 688 | // This test checks simple renewal uses the specified valid lifetime. |
| 689 | TEST_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", 689 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 689), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 689), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintRenew4_Test >); void AllocEngine4Test_hintRenew4_Test::TestBody() { |
| 690 | boost::scoped_ptr<AllocEngine> engine; |
| 691 | 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_691 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_691 ; } } else gtest_label_testnothrow_691 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 691, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 692 | 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" , 692, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 693 | |
| 694 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 695 | false, true, "somehost.example.com.", false); |
| 696 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 697 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 698 | |
| 699 | // Specify the valid lifetime we want. |
| 700 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); |
| 701 | ctx.query_->addOption(opt); |
| 702 | |
| 703 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 704 | |
| 705 | // Check that we got a lease and it's sane |
| 706 | 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" , 706, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 707 | checkLease4(lease); |
| 708 | |
| 709 | // Check the valid lifetime has the wanted value. |
| 710 | 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" , 710, gtest_ar.failure_message()) = ::testing::Message(); |
| 711 | |
| 712 | // The new lease has been allocated, so the old lease should not exist. |
| 713 | 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" , 713, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 714 | |
| 715 | // Do it again, this should amount to the renew of an existing lease |
| 716 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 717 | |
| 718 | // Check that we got a lease and it's sane |
| 719 | 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" , 719, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 720 | checkLease4(lease2); |
| 721 | |
| 722 | // Lease already existed, so old_lease should be set. |
| 723 | 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" , 723, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 724 | |
| 725 | // Check the renewed valid lifetime has the wanted value. |
| 726 | 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" , 726, gtest_ar.failure_message()) = ::testing::Message(); |
| 727 | } |
| 728 | |
| 729 | // This test checks simple renewal uses the min valid lifetime. |
| 730 | TEST_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", 730 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 730), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 730), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minRenew4_Test >); void AllocEngine4Test_minRenew4_Test::TestBody() { |
| 731 | boost::scoped_ptr<AllocEngine> engine; |
| 732 | 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_732 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_732 ; } } else gtest_label_testnothrow_732 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 732, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 733 | 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" , 733, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 734 | |
| 735 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 736 | false, true, "somehost.example.com.", false); |
| 737 | subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); |
| 738 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 739 | |
| 740 | // Specify the valid lifetime we want, as it is lower than the min value |
| 741 | // we'll get this min value instead. |
| 742 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); |
| 743 | ctx.query_->addOption(opt); |
| 744 | |
| 745 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 746 | |
| 747 | // Check that we got a lease and it's sane |
| 748 | 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" , 748, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 749 | checkLease4(lease); |
| 750 | |
| 751 | // Check the valid lifetime has the min value. |
| 752 | 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" , 752, gtest_ar.failure_message()) = ::testing::Message(); |
| 753 | |
| 754 | // The new lease has been allocated, so the old lease should not exist. |
| 755 | 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" , 755, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 756 | |
| 757 | // Do it again, this should amount to the renew of an existing lease |
| 758 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 759 | |
| 760 | // Check that we got a lease and it's sane |
| 761 | 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" , 761, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 762 | checkLease4(lease2); |
| 763 | |
| 764 | // Lease already existed, so old_lease should be set. |
| 765 | 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" , 765, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 766 | |
| 767 | // Check the renewed valid lifetime has the min value. |
| 768 | 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" , 768, gtest_ar.failure_message()) = ::testing::Message(); |
| 769 | } |
| 770 | |
| 771 | // This test checks simple renewal uses the max valid lifetime. |
| 772 | TEST_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", 772 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 772), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 772), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxRenew4_Test >); void AllocEngine4Test_maxRenew4_Test::TestBody() { |
| 773 | boost::scoped_ptr<AllocEngine> engine; |
| 774 | 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_774 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_774 ; } } else gtest_label_testnothrow_774 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 774, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 775 | 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" , 775, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 776 | |
| 777 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 778 | false, true, "somehost.example.com.", false); |
| 779 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 780 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 781 | |
| 782 | // Specify the valid lifetime we want, as it is greater than the max value |
| 783 | // we'll get this max value instead. |
| 784 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); |
| 785 | ctx.query_->addOption(opt); |
| 786 | |
| 787 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 788 | |
| 789 | // Check that we got a lease and it's sane |
| 790 | 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" , 790, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 791 | checkLease4(lease); |
| 792 | |
| 793 | // Check the valid lifetime has the max value. |
| 794 | 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" , 794, gtest_ar.failure_message()) = ::testing::Message(); |
| 795 | |
| 796 | // The new lease has been allocated, so the old lease should not exist. |
| 797 | 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" , 797, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 798 | |
| 799 | // Do it again, this should amount to the renew of an existing lease |
| 800 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 801 | |
| 802 | // Check that we got a lease and it's sane |
| 803 | 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" , 803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 804 | checkLease4(lease2); |
| 805 | |
| 806 | // Lease already existed, so old_lease should be set. |
| 807 | 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" , 807, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 808 | |
| 809 | // Check the renewed valid lifetime has the max value. |
| 810 | 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" , 810, gtest_ar.failure_message()) = ::testing::Message(); |
| 811 | } |
| 812 | |
| 813 | // This test checks simple renewal handles BOOTP queries. |
| 814 | TEST_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", 814 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 814), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 814), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpRenew4_Test >); void AllocEngine4Test_bootpRenew4_Test::TestBody() { |
| 815 | boost::scoped_ptr<AllocEngine> engine; |
| 816 | 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_816 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_816 ; } } else gtest_label_testnothrow_816 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 816, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 817 | 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" , 817, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 818 | |
| 819 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 820 | false, true, "somehost.example.com.", false); |
| 821 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 822 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 823 | |
| 824 | // Make the query a BOOTP one. |
| 825 | ctx.query_->addClass("BOOTP"); |
| 826 | |
| 827 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 828 | |
| 829 | // Check that we got a lease. |
| 830 | 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" , 830, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 831 | |
| 832 | // Check that is belongs to the right subnet and client. |
| 833 | 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" , 833, gtest_ar.failure_message()) = ::testing::Message(); |
| 834 | 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" , 834, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 835 | 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" , 835, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 836 | 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" , 836, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 837 | 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" , 837, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 838 | 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" , 838, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 839 | 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" , 839, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 840 | |
| 841 | // Check the valid lifetime is infinite. |
| 842 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
| 843 | 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" , 843, gtest_ar.failure_message()) = ::testing::Message(); |
| 844 | |
| 845 | // The new lease has been allocated, so the old lease should not exist. |
| 846 | 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" , 846, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 847 | |
| 848 | // Do it again, this should amount to the renew of an existing lease |
| 849 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 850 | |
| 851 | // Check that we got a lease. |
| 852 | 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" , 852, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 853 | |
| 854 | // Check that is belongs to the right subnet and client. |
| 855 | 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" , 855, gtest_ar.failure_message()) = ::testing::Message(); |
| 856 | 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" , 856, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease2->addr_)", "false", "true") . c_str()) = ::testing::Message(); |
| 857 | 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" , 857, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 858 | 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" , 858, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 859 | 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" , 859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 860 | 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" , 860, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 861 | 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" , 861, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->hwaddr_ == *hwaddr_", "false", "true") .c_str( )) = ::testing::Message(); |
| 862 | |
| 863 | // Lease already existed, so old_lease should be set. |
| 864 | 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" , 864, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 865 | |
| 866 | // Check the renewed valid lifetime has the max value. |
| 867 | 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" , 867, gtest_ar.failure_message()) = ::testing::Message(); |
| 868 | } |
| 869 | |
| 870 | // This test checks if really small pools are working |
| 871 | TEST_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", 871 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 871), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 871), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_smallPool4_Test >); void AllocEngine4Test_smallPool4_Test::TestBody() { |
| 872 | boost::scoped_ptr<AllocEngine> engine; |
| 873 | 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_873 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_873 ; } } else gtest_label_testnothrow_873 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 873, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 874 | 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" , 874, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 875 | |
| 876 | IOAddress addr("192.0.2.17"); |
| 877 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 878 | |
| 879 | // Get rid of the default subnet configuration. |
| 880 | cfg_mgr.clear(); |
| 881 | |
| 882 | // Create configuration similar to other tests, but with a single address pool |
| 883 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 884 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 885 | subnet_->addPool(pool_); |
| 886 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 887 | |
| 888 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 889 | IOAddress("0.0.0.0"), false, false, |
| 890 | "host.example.com.", false); |
| 891 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 892 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 893 | |
| 894 | // Check that we got that single lease |
| 895 | 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" , 895, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 896 | |
| 897 | // We have allocated new lease, so the old lease should not exist. |
| 898 | 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" , 898, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 899 | |
| 900 | 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" , 900, gtest_ar.failure_message()) = ::testing::Message(); |
| 901 | |
| 902 | // Do all checks on the lease |
| 903 | checkLease4(lease); |
| 904 | |
| 905 | // Check that the lease is indeed in LeaseMgr |
| 906 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 907 | 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" , 907, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 908 | |
| 909 | // Now check that the lease in LeaseMgr has the same parameters |
| 910 | detailCompareLease(lease, from_mgr); |
| 911 | } |
| 912 | |
| 913 | // This test checks if all addresses in a pool are currently used, the attempt |
| 914 | // to find out a new lease fails. |
| 915 | TEST_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", 915 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 915), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 915), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_outOfAddresses4_Test >); void AllocEngine4Test_outOfAddresses4_Test::TestBody() { |
| 916 | boost::scoped_ptr<AllocEngine> engine; |
| 917 | 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_917 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_917 ; } } else gtest_label_testnothrow_917 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 917, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 918 | 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" , 918, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 919 | |
| 920 | IOAddress addr("192.0.2.17"); |
| 921 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 922 | // Get rid of the default test configuration. |
| 923 | cfg_mgr.clear(); |
| 924 | |
| 925 | // Create configuration similar to other tests, but with a single address pool |
| 926 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 927 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 928 | subnet_->addPool(pool_); |
| 929 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 930 | |
| 931 | // Just a different hw/client-id for the second client |
| 932 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 933 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 934 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 935 | time_t now = time(0); |
| 936 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, |
| 937 | sizeof(clientid2), 501, now, |
| 938 | subnet_->getID())); |
| 939 | lease->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 940 | 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" , 940, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 941 | |
| 942 | // There is just a single address in the pool and allocated it to someone |
| 943 | // else, so the allocation should fail |
| 944 | |
| 945 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 946 | IOAddress("0.0.0.0"), false, false, |
| 947 | "host.example.com.", false); |
| 948 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 949 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 950 | 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" , 950, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "true", "false") .c_str()) = ::testing::Message(); |
| 951 | 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" , 951, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 952 | |
| 953 | 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", 953, gtest_ar.failure_message()) = ::testing::Message(); |
| 954 | 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" , 954, gtest_ar.failure_message()) = ::testing::Message(); |
| 955 | 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", 955, gtest_ar.failure_message()) = ::testing::Message(); |
| 956 | 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", 956, gtest_ar.failure_message()) = ::testing::Message(); |
| 957 | 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", 957, gtest_ar.failure_message()) = ::testing::Message(); |
| 958 | |
| 959 | 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" , 959, gtest_ar.failure_message()) = ::testing::Message(); |
| 960 | 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" , 960, gtest_ar.failure_message()) = ::testing::Message(); |
| 961 | 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" , 961, gtest_ar.failure_message()) = ::testing::Message(); |
| 962 | 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" , 962, gtest_ar.failure_message()) = ::testing::Message(); |
| 963 | 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" , 963, gtest_ar.failure_message()) = ::testing::Message(); |
| 964 | } |
| 965 | |
| 966 | // This test checks simple renewal works with match-client-id false and |
| 967 | // empty hardware address. |
| 968 | TEST_F(AllocEngine4Test, emptyHWRenew4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("emptyHWRenew4") > 1, "test_name must not be empty" ); class AllocEngine4Test_emptyHWRenew4_Test : public AllocEngine4Test { public: AllocEngine4Test_emptyHWRenew4_Test() = default; ~ AllocEngine4Test_emptyHWRenew4_Test() override = default; AllocEngine4Test_emptyHWRenew4_Test (const AllocEngine4Test_emptyHWRenew4_Test &) = delete; AllocEngine4Test_emptyHWRenew4_Test & operator=( const AllocEngine4Test_emptyHWRenew4_Test & ) = delete; AllocEngine4Test_emptyHWRenew4_Test (AllocEngine4Test_emptyHWRenew4_Test &&) noexcept = delete; AllocEngine4Test_emptyHWRenew4_Test & operator=( AllocEngine4Test_emptyHWRenew4_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const AllocEngine4Test_emptyHWRenew4_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "emptyHWRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 968 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 968), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 968), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_emptyHWRenew4_Test >); void AllocEngine4Test_emptyHWRenew4_Test::TestBody() { |
| 969 | boost::scoped_ptr<AllocEngine> engine; |
| 970 | 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_970 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_970 ; } } else gtest_label_testnothrow_970 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 970, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 971 | 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" , 971, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 972 | |
| 973 | // Set match-client-id to false. |
| 974 | subnet_->setMatchClientId(false); |
| 975 | |
| 976 | // Set the hardware address to empty. |
| 977 | std::vector<uint8_t> empty; |
| 978 | hwaddr_.reset(new HWAddr(empty, HTYPE_ETHER)); |
| 979 | |
| 980 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 981 | false, true, "somehost.example.com.", false); |
| 982 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 983 | |
| 984 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 985 | |
| 986 | // Check that we got a lease and it's sane |
| 987 | 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" , 987, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 988 | checkLease4(lease); |
| 989 | |
| 990 | // The new lease has been allocated, so the old lease should not exist. |
| 991 | 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" , 991, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 992 | |
| 993 | // Do it again, this should amount to the renew of an existing lease |
| 994 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 995 | |
| 996 | // Check that we got a lease and it's sane |
| 997 | 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" , 997, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 998 | checkLease4(lease2); |
| 999 | |
| 1000 | // Lease already existed, so old_lease should be set. |
| 1001 | 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" , 1001, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 1002 | } |
| 1003 | |
| 1004 | /// @brief This test class is dedicated to testing shared networks |
| 1005 | /// |
| 1006 | /// It uses one common configuration: |
| 1007 | /// 1 shared network with 2 subnets: |
| 1008 | /// - 192.0.2.0/24 subnet with a small pool of single address: 192.0.2.17 |
| 1009 | /// - 10.1.2.0/24 subnet with pool with 96 addresses. |
| 1010 | class SharedNetworkAlloc4Test : public AllocEngine4Test { |
| 1011 | public: |
| 1012 | |
| 1013 | /// @brief Initializes configuration (2 subnets, 1 shared network) |
| 1014 | SharedNetworkAlloc4Test() : engine_(0) { |
| 1015 | // Create two subnets, each with a single address pool. The first subnet |
| 1016 | // has only one address in its address pool to make it easier to simulate |
| 1017 | // address exhaustion. |
| 1018 | subnet1_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1019 | subnet2_ = Subnet4::create(IOAddress("10.1.2.0"), 24, 1, 2, 3, SubnetID(20)); |
| 1020 | pool1_.reset(new Pool4(IOAddress("192.0.2.17"), IOAddress("192.0.2.17"))); |
| 1021 | pool2_.reset(new Pool4(IOAddress("10.1.2.5"), IOAddress("10.1.2.100"))); |
| 1022 | |
| 1023 | subnet1_->addPool(pool1_); |
| 1024 | subnet2_->addPool(pool2_); |
| 1025 | |
| 1026 | // Both subnets belong to the same network so they can be used |
| 1027 | // interchangeably. |
| 1028 | network_.reset(new SharedNetwork4("test_network")); |
| 1029 | network_->add(subnet1_); |
| 1030 | network_->add(subnet2_); |
| 1031 | |
| 1032 | std::vector<uint8_t> hwaddr_vec = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 1033 | hwaddr2_.reset(new HWAddr(hwaddr_vec, HTYPE_ETHER)); |
| 1034 | } |
| 1035 | |
| 1036 | /// @brief Inserts a new lease for specified address |
| 1037 | /// |
| 1038 | /// Creates a new lease for specified address and subnet-id and inserts |
| 1039 | /// it into database. This is not particularly fancy method, it is used |
| 1040 | /// just to mark existing addresses as used. It uses hwaddr2_ to allocate |
| 1041 | /// the lease. |
| 1042 | /// |
| 1043 | /// @param addr text representation of the address |
| 1044 | /// @param subnet_id ID of the subnet |
| 1045 | /// @param return pointer to the lease |
| 1046 | Lease4Ptr |
| 1047 | insertLease(std::string addr, SubnetID subnet_id) { |
| 1048 | Lease4Ptr lease(new Lease4(IOAddress(addr), hwaddr2_, ClientIdPtr(), |
| 1049 | 501, time(0), subnet_id)); |
| 1050 | lease->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 1051 | if (!LeaseMgrFactory::instance().addLease(lease)) { |
| 1052 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1052, "Failed") = ::testing::Message() << "Attempt to add a lease for IP " << addr |
| 1053 | << " in subnet " << subnet_id << " failed"; |
| 1054 | } |
| 1055 | |
| 1056 | return (lease); |
| 1057 | } |
| 1058 | |
| 1059 | /// @brief Test host order of precedence in shared-network |
| 1060 | /// |
| 1061 | /// Creates global and shared-network subnet host reservations, |
| 1062 | /// with or without addresses, and attempts to allocate a lease. |
| 1063 | /// The resultant lease is then tested to have the expected subnet |
| 1064 | /// and address. |
| 1065 | /// |
| 1066 | /// |
| 1067 | /// @param include_global_host create a global host when true |
| 1068 | /// @param global_host_address address to use in the global host reservation or |
| 1069 | /// none if it is IPV4_ZERO_ADDRESS. |
| 1070 | /// @param include_subnet_host create a subnet host when true |
| 1071 | /// @param subnet_host_subnet_id id of the subnet to which the subnet host should |
| 1072 | /// be added. |
| 1073 | /// @param subnet_host_address address to use in the subnet host reservation or |
| 1074 | /// none if it is IPV4_ZERO_ADDRESS. |
| 1075 | /// @param exp_subnet expected subnet of the resultant lease. |
| 1076 | /// @param exp_address expected address of the resultant lease. |
| 1077 | /// @param fake_allocation tests the DISCOVER code path when true, REQUEST when |
| 1078 | /// false. |
| 1079 | void globalResVsSubnetRes(bool include_global_host, IOAddress global_host_address, |
| 1080 | bool include_subnet_host, SubnetID subnet_host_subnet_id, |
| 1081 | IOAddress subnet_host_address, SubnetID exp_subnet, |
| 1082 | IOAddress exp_address, bool fake_allocation = true) { |
| 1083 | 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" , 1083, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1084 | |
| 1085 | HostPtr global_host; |
| 1086 | if (include_global_host) { |
| 1087 | // Create global reservation for the client in subnet2. |
| 1088 | global_host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1089 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 1090 | SUBNET_ID_UNUSED, global_host_address)); |
| 1091 | |
| 1092 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(global_host); |
| 1093 | } |
| 1094 | |
| 1095 | // Create subnet reservation for the client in subnet2. |
| 1096 | HostPtr subnet_host; |
| 1097 | if (include_subnet_host) { |
| 1098 | subnet_host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1099 | Host::IDENT_HWADDR, subnet_host_subnet_id, |
| 1100 | SUBNET_ID_UNUSED, subnet_host_address)); |
| 1101 | |
| 1102 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(subnet_host); |
| 1103 | } |
| 1104 | |
| 1105 | CfgMgr::instance().commit(); |
| 1106 | |
| 1107 | subnet1_->setReservationsGlobal(true); |
| 1108 | subnet1_->setReservationsInSubnet(true); |
| 1109 | subnet2_->setReservationsGlobal(true); |
| 1110 | subnet2_->setReservationsInSubnet(true); |
| 1111 | |
| 1112 | // Start allocation from subnet1. |
| 1113 | AllocEngine::ClientContext4 |
| 1114 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1115 | false, false, "host.example.com.", true); |
| 1116 | |
| 1117 | ctx.fake_allocation_ = fake_allocation; |
| 1118 | if (fake_allocation) { |
| 1119 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1120 | } else { |
| 1121 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1122 | } |
| 1123 | |
| 1124 | AllocEngine::findReservation(ctx); |
| 1125 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1126 | 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" , 1126, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1127 | EXPECT_EQ(exp_subnet, lease->subnet_id_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("exp_subnet" , "lease->subnet_id_", exp_subnet, lease->subnet_id_))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1127, gtest_ar.failure_message()) = ::testing::Message(); |
| 1128 | EXPECT_EQ(exp_address, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("exp_address" , "lease->addr_", exp_address, lease->addr_))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 1128, gtest_ar.failure_message()) = ::testing::Message(); |
| 1129 | |
| 1130 | if (!fake_allocation) { |
| 1131 | 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" , 1131, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | /// Convenience pointers to configuration elements. These are initialized |
| 1136 | /// in the constructor and are used throughout the tests. |
| 1137 | AllocEngine engine_; |
| 1138 | Subnet4Ptr subnet1_; |
| 1139 | Subnet4Ptr subnet2_; |
| 1140 | Pool4Ptr pool1_; |
| 1141 | Pool4Ptr pool2_; |
| 1142 | SharedNetwork4Ptr network_; |
| 1143 | |
| 1144 | HWAddrPtr hwaddr2_; // Note there's hwaddr_ already defined in base class. |
| 1145 | }; |
| 1146 | |
| 1147 | // This test verifies that the server can offer an address from a |
| 1148 | // subnet and the introduction of shared network doesn't break anything here. |
| 1149 | TEST_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" , 1149), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1149), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1149), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test ::TestBody() { |
| 1150 | |
| 1151 | // Create context which will be used to try to allocate leases from the |
| 1152 | // shared network. The context points to subnet1, which address space |
| 1153 | // is exhausted. We expect the allocation engine to find another subnet |
| 1154 | // within the same shared network and offer an address from there. |
| 1155 | AllocEngine::ClientContext4 |
| 1156 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1157 | false, false, "host.example.com.", true); |
| 1158 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1159 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1160 | |
| 1161 | // The allocation engine should have assigned an address from the first |
| 1162 | // subnet. |
| 1163 | 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" , 1163, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1164 | 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" , 1164, gtest_ar.failure_message()) = ::testing::Message(); |
| 1165 | |
| 1166 | // Make sure the lease is not in the lease mgr (this is only |
| 1167 | // discover). |
| 1168 | 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" , 1168, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 1169 | } |
| 1170 | |
| 1171 | // This test verifies that the server will pick a second subnet out of two |
| 1172 | // shared subnets if there is a hint for the second subnet. |
| 1173 | TEST_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" , 1173), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1173), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1173), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test ::TestBody() { |
| 1174 | |
| 1175 | // Create context which will be used to try to allocate leases from the |
| 1176 | // shared network. The context points to subnet1, which address space |
| 1177 | // is exhausted. We expect the allocation engine to find another subnet |
| 1178 | // within the same shared network and offer an address from there. |
| 1179 | |
| 1180 | AllocEngine::ClientContext4 |
| 1181 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress("10.1.2.25"), |
| 1182 | false, false, "host.example.com.", true); |
| 1183 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1184 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1185 | |
| 1186 | // The allocation engine should have assigned an address from the second |
| 1187 | // subnet, because that's what the hint requested. |
| 1188 | 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" , 1188, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1189 | 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" , 1189, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1190 | } |
| 1191 | |
| 1192 | // This test verifies that the server can offer an address from a |
| 1193 | // different subnet than orginally selected, when the address pool in |
| 1194 | // the first subnet is exhausted. |
| 1195 | TEST_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" , 1195), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1195), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1195), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetwork_Test >); void SharedNetworkAlloc4Test_discoverSharedNetwork_Test ::TestBody() { |
| 1196 | // Create a lease for a single address in the first address pool. The |
| 1197 | // pool is now exhausted. |
| 1198 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
| 1199 | |
| 1200 | // Create context which will be used to try to allocate leases from the |
| 1201 | // shared network. The context points to subnet1, which address space |
| 1202 | // is exhausted. We expect the allocation engine to find another subnet |
| 1203 | // within the same shared network and offer an address from there. |
| 1204 | AllocEngine::ClientContext4 |
| 1205 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1206 | false, false, "host.example.com.", true); |
| 1207 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1208 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
| 1209 | // The allocation engine should have assigned an address from the second |
| 1210 | // subnet. We could guess that this is 10.1.2.5, being the first address |
| 1211 | // in the address pool, but to make the test more generic, we merely |
| 1212 | // verify that the address is in the given address pool. |
| 1213 | 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" , 1213, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1214 | 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" , 1214, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1215 | |
| 1216 | // The client should also be offered a lease when it specifies a hint |
| 1217 | // that doesn't match the subnet from which the lease is offered. The |
| 1218 | // engine should check alternative subnets to match the hint to |
| 1219 | // a subnet. The requested lease is available, so it should be offered. |
| 1220 | ctx.subnet_ = subnet1_; |
| 1221 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
| 1222 | lease2 = engine_.allocateLease4(ctx); |
| 1223 | 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" , 1223, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1224 | 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" , 1224, gtest_ar.failure_message()) = ::testing::Message(); |
| 1225 | |
| 1226 | // The returning client (the one that has a lease) should also be able |
| 1227 | // to renew its lease regardless of a subnet it begins with. So, it has |
| 1228 | // an address assigned from subnet1, but we use subnet2 as a selected |
| 1229 | // subnet. |
| 1230 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
| 1231 | IOAddress("0.0.0.0"), false, false, |
| 1232 | "host.example.com.", true); |
| 1233 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1234 | lease2 = engine_.allocateLease4(ctx2); |
| 1235 | // The existing lease should be returned. |
| 1236 | 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" , 1236, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1237 | 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" , 1237, gtest_ar.failure_message()) = ::testing::Message(); |
| 1238 | } |
| 1239 | |
| 1240 | // This test verifies that the server can offer an address from a |
| 1241 | // different subnet than orginally selected, when the address pool in |
| 1242 | // the first subnet is exhausted. |
| 1243 | TEST_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" , 1243), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1243), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1243), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test ::TestBody() { |
| 1244 | |
| 1245 | // Try to offer address from subnet1. There is one address available |
| 1246 | // so it should be offered. |
| 1247 | AllocEngine::ClientContext4 |
| 1248 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1249 | false, false, "host.example.com.", true); |
| 1250 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1251 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1252 | 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" , 1252, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1253 | 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" , 1253, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1254 | |
| 1255 | // Apply restrictions on the subnet1. This should be only assigned |
| 1256 | // to clients belonging to cable-modem class. |
| 1257 | subnet1_->allowClientClass("cable-modem"); |
| 1258 | |
| 1259 | // The allocation engine should determine that the subnet1 is not |
| 1260 | // available for the client not belonging to the cable-modem class. |
| 1261 | // Instead, it should offer an address from subnet2 that belongs |
| 1262 | // to the same shared network. |
| 1263 | ctx.subnet_ = subnet1_; |
| 1264 | lease = engine_.allocateLease4(ctx); |
| 1265 | 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" , 1265, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1266 | 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" , 1266, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1267 | |
| 1268 | // Create reservation for the client in subnet1. Because this subnet is |
| 1269 | // not allowed for the client the client should still be offered a |
| 1270 | // lease from subnet2. |
| 1271 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1272 | Host::IDENT_HWADDR, subnet1_->getID(), |
| 1273 | SUBNET_ID_UNUSED, IOAddress("192.0.2.17"))); |
| 1274 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1275 | CfgMgr::instance().commit(); |
| 1276 | AllocEngine::findReservation(ctx); |
| 1277 | |
| 1278 | ctx.subnet_ = subnet1_; |
| 1279 | lease = engine_.allocateLease4(ctx); |
| 1280 | 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" , 1280, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1281 | 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" , 1281, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1282 | |
| 1283 | // Assign cable-modem class and try again. This time, we should |
| 1284 | // offer an address from the subnet1. |
| 1285 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1286 | |
| 1287 | ctx.subnet_ = subnet1_; |
| 1288 | lease = engine_.allocateLease4(ctx); |
| 1289 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1289, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1290 | EXPECT_EQ("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" , 1290, gtest_ar.failure_message()) = ::testing::Message(); |
| 1291 | } |
| 1292 | |
| 1293 | // This test verifies that the server can offer an address from a |
| 1294 | // different subnet than orginally selected, when the address pool in |
| 1295 | // the first subnet requires another class. |
| 1296 | TEST_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" , 1296), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1296), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1296), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test ::TestBody() { |
| 1297 | |
| 1298 | // Try to offer address from subnet1. There is one address available |
| 1299 | // so it should be offered. |
| 1300 | AllocEngine::ClientContext4 |
| 1301 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1302 | false, false, "host.example.com.", true); |
| 1303 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1304 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1305 | 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" , 1305, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1306 | 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" , 1306, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1307 | |
| 1308 | // Apply restrictions on the pool1. This should be only assigned |
| 1309 | // to clients belonging to cable-modem class. |
| 1310 | pool1_->allowClientClass("cable-modem"); |
| 1311 | |
| 1312 | // The allocation engine should determine that the pool1 is not |
| 1313 | // available for the client not belonging to the cable-modem class. |
| 1314 | // Instead, it should offer an address from subnet2 that belongs |
| 1315 | // to the same shared network. |
| 1316 | ctx.subnet_ = subnet1_; |
| 1317 | lease = engine_.allocateLease4(ctx); |
| 1318 | 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" , 1318, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1319 | 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" , 1319, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1320 | |
| 1321 | // Assign cable-modem class and try again. This time, we should |
| 1322 | // offer an address from the pool1. |
| 1323 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1324 | |
| 1325 | // Restrict access to pool2 for this client, to make sure that the |
| 1326 | // server doesn't accidentally get an address from this pool. |
| 1327 | pool2_->allowClientClass("telephone"); |
| 1328 | |
| 1329 | ctx.subnet_ = subnet1_; |
| 1330 | lease = engine_.allocateLease4(ctx); |
| 1331 | 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" , 1331, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1332 | 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" , 1332, gtest_ar.failure_message()) = ::testing::Message(); |
| 1333 | } |
| 1334 | |
| 1335 | // Test that global reservations within shared network take precedence over the |
| 1336 | // existing leases regardless in which subnet belonging to a shared network |
| 1337 | // reservations belong. |
| 1338 | TEST_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" , 1338), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1338), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1338), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test ::TestBody() { |
| 1339 | |
| 1340 | 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" , 1340, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1341 | |
| 1342 | // Create reservation for the client. |
| 1343 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1344 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 1345 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1346 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1347 | CfgMgr::instance().commit(); |
| 1348 | |
| 1349 | subnet1_->setReservationsGlobal(true); |
| 1350 | subnet1_->setReservationsInSubnet(true); |
| 1351 | subnet2_->setReservationsGlobal(true); |
| 1352 | subnet2_->setReservationsInSubnet(true); |
| 1353 | |
| 1354 | // Start allocation from subnet1. The engine should determine that the |
| 1355 | // client has global reservations within subnet2 and should rather |
| 1356 | // assign reserved addresses. |
| 1357 | AllocEngine::ClientContext4 |
| 1358 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1359 | false, false, "host.example.com.", true); |
| 1360 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1361 | AllocEngine::findReservation(ctx); |
| 1362 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1363 | 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" , 1363, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1364 | 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" , 1364, gtest_ar.failure_message()) = ::testing::Message(); |
| 1365 | 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" , 1365, gtest_ar.failure_message()) = ::testing::Message(); |
| 1366 | |
| 1367 | // Let's create a lease for the client to make sure the lease is not |
| 1368 | // renewed but a reserved lease is offered. |
| 1369 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1370 | 501, time(0), subnet1_->getID())); |
| 1371 | lease->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 1372 | 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" , 1372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1373 | ctx.subnet_ = subnet1_; |
| 1374 | ctx.hosts_.clear(); |
| 1375 | AllocEngine::findReservation(ctx); |
| 1376 | lease = engine_.allocateLease4(ctx); |
| 1377 | 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" , 1377, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1378 | 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" , 1378, gtest_ar.failure_message()) = ::testing::Message(); |
| 1379 | 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" , 1379, gtest_ar.failure_message()) = ::testing::Message(); |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | // Test that reservations within shared network take precedence over the |
| 1384 | // existing leases regardless in which subnet belonging to a shared network |
| 1385 | // reservations belong. |
| 1386 | TEST_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" , 1386), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1386), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1386), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test ::TestBody() { |
| 1387 | |
| 1388 | 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" , 1388, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1389 | |
| 1390 | // Create reservation for the client. |
| 1391 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1392 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1393 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1394 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1395 | CfgMgr::instance().commit(); |
| 1396 | |
| 1397 | // Start allocation from subnet1. The engine should determine that the |
| 1398 | // client has reservations in subnet2 and should rather assign reserved |
| 1399 | // addresses. |
| 1400 | AllocEngine::ClientContext4 |
| 1401 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1402 | false, false, "host.example.com.", true); |
| 1403 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1404 | AllocEngine::findReservation(ctx); |
| 1405 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1406 | 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" , 1406, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1407 | 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" , 1407, gtest_ar.failure_message()) = ::testing::Message(); |
| 1408 | 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" , 1408, gtest_ar.failure_message()) = ::testing::Message(); |
| 1409 | |
| 1410 | // Let's create a lease for the client in subnet1 to make sure the lease |
| 1411 | // is not renewed but a reserved lease is offered. |
| 1412 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1413 | 501, time(0), subnet1_->getID())); |
| 1414 | lease2->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 1415 | 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" , 1415, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1416 | ctx.subnet_ = subnet1_; |
| 1417 | ctx.hosts_.clear(); |
| 1418 | AllocEngine::findReservation(ctx); |
| 1419 | lease = engine_.allocateLease4(ctx); |
| 1420 | 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" , 1420, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1421 | 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" , 1421, gtest_ar.failure_message()) = ::testing::Message(); |
| 1422 | 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" , 1422, gtest_ar.failure_message()) = ::testing::Message(); |
| 1423 | |
| 1424 | // Let's create a lease for the client in subnet2 to make sure the lease |
| 1425 | // is not renewed but a reserved lease is offered. |
| 1426 | Lease4Ptr lease3(new Lease4(IOAddress("10.1.2.55"), hwaddr_, ClientIdPtr(), |
| 1427 | 501, time(0), subnet2_->getID())); |
| 1428 | lease3->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 1429 | 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" , 1429, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease3)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1430 | ctx.subnet_ = subnet1_; |
| 1431 | ctx.hosts_.clear(); |
| 1432 | AllocEngine::findReservation(ctx); |
| 1433 | lease = engine_.allocateLease4(ctx); |
| 1434 | 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" , 1434, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1435 | 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" , 1435, gtest_ar.failure_message()) = ::testing::Message(); |
| 1436 | 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" , 1436, gtest_ar.failure_message()) = ::testing::Message(); |
| 1437 | } |
| 1438 | |
| 1439 | |
| 1440 | // Test that reservations within shared network take precedence over the |
| 1441 | // existing leases regardless in which subnet belonging to a shared network |
| 1442 | // reservations belong. Host lookups returning a collection are disabled. |
| 1443 | // As it is only an optimization the behavior (so the test) must stay |
| 1444 | // unchanged. |
| 1445 | TEST_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" , 1445), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1445), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1445), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test ::TestBody() { |
| 1446 | |
| 1447 | // Disable host lookups returning a collection. |
| 1448 | 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" , 1448, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1449 | HostMgr::instance().setDisableSingleQuery(true); |
| 1450 | |
| 1451 | // Create reservation for the client. |
| 1452 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1453 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1454 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1455 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1456 | CfgMgr::instance().commit(); |
| 1457 | |
| 1458 | subnet1_->setReservationsGlobal(true); |
| 1459 | subnet1_->setReservationsInSubnet(true); |
| 1460 | subnet2_->setReservationsGlobal(true); |
| 1461 | subnet2_->setReservationsInSubnet(true); |
| 1462 | |
| 1463 | // Start allocation from subnet1. The engine should determine that the |
| 1464 | // client has reservations in subnet2 and should rather assign reserved |
| 1465 | // addresses. |
| 1466 | AllocEngine::ClientContext4 |
| 1467 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1468 | false, false, "host.example.com.", true); |
| 1469 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1470 | AllocEngine::findReservation(ctx); |
| 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_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" , 1473, gtest_ar.failure_message()) = ::testing::Message(); |
| 1474 | 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" , 1474, gtest_ar.failure_message()) = ::testing::Message(); |
| 1475 | |
| 1476 | // Let's create a lease for the client to make sure the lease is not |
| 1477 | // renewed but a reserved lease is offered. |
| 1478 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1479 | 501, time(0), subnet1_->getID())); |
| 1480 | lease->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 1481 | 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" , 1481, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1482 | ctx.subnet_ = subnet1_; |
| 1483 | ctx.hosts_.clear(); |
| 1484 | AllocEngine::findReservation(ctx); |
| 1485 | lease = engine_.allocateLease4(ctx); |
| 1486 | 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" , 1486, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1487 | 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" , 1487, gtest_ar.failure_message()) = ::testing::Message(); |
| 1488 | 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" , 1488, gtest_ar.failure_message()) = ::testing::Message(); |
| 1489 | } |
| 1490 | |
| 1491 | // This test verifies that the server can offer an address from a shared |
| 1492 | // subnet if there's at least 1 address left there, but will not offer |
| 1493 | // anything if both subnets are completely full. |
| 1494 | TEST_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", 1494 ), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1494), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1494), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_runningOut_Test >); void SharedNetworkAlloc4Test_runningOut_Test::TestBody () { |
| 1495 | |
| 1496 | // Allocate everything in subnet1 |
| 1497 | insertLease("192.0.2.17", subnet1_->getID()); |
| 1498 | |
| 1499 | // Allocate everything, except one address in subnet2. |
| 1500 | for (int i = 5; i < 100; i++) { |
| 1501 | stringstream tmp; |
| 1502 | tmp << "10.1.2." << i; |
| 1503 | insertLease(tmp.str(), subnet2_->getID()); |
| 1504 | } |
| 1505 | |
| 1506 | // Create context which will be used to try to allocate leases from the |
| 1507 | // shared network. The context points to subnet1, which address space |
| 1508 | // is exhausted. We expect the allocation engine to find another subnet |
| 1509 | // within the same shared network and offer an address from there. |
| 1510 | AllocEngine::ClientContext4 |
| 1511 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1512 | false, false, "host.example.com.", true); |
| 1513 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1514 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1515 | 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", 1515, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1516 | |
| 1517 | // Now allocate the last address. Now both subnets are exhausted. |
| 1518 | insertLease("10.1.2.100", subnet2_->getID()); |
| 1519 | |
| 1520 | // Ok, we're out. We should not get anything now. |
| 1521 | lease = engine_.allocateLease4(ctx); |
| 1522 | 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" , 1522, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 1523 | |
| 1524 | 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", 1524, gtest_ar.failure_message()) = ::testing::Message(); |
| 1525 | 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" , 1525, gtest_ar.failure_message()) = ::testing::Message(); |
| 1526 | 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", 1526, gtest_ar.failure_message()) = ::testing::Message(); |
| 1527 | 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", 1527, gtest_ar.failure_message()) = ::testing::Message(); |
| 1528 | 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", 1528, gtest_ar.failure_message()) = ::testing::Message(); |
| 1529 | |
| 1530 | 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" , 1530, gtest_ar.failure_message()) = ::testing::Message(); |
| 1531 | 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" , 1531, gtest_ar.failure_message()) = ::testing::Message(); |
| 1532 | 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" , 1532, gtest_ar.failure_message()) = ::testing::Message(); |
| 1533 | 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" , 1533, gtest_ar.failure_message()) = ::testing::Message(); |
| 1534 | 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" , 1534, gtest_ar.failure_message()) = ::testing::Message(); |
| 1535 | } |
| 1536 | |
| 1537 | // This test verifies that the server can offer an address from a |
| 1538 | // subnet and the introduction of shared network doesn't break anything here. |
| 1539 | TEST_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" , 1539), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1539), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1539), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test ::TestBody() { |
| 1540 | |
| 1541 | // Create context which will be used to try to allocate leases from the |
| 1542 | // shared network. The context points to subnet1, which address space |
| 1543 | // is exhausted. We expect the allocation engine to find another subnet |
| 1544 | // within the same shared network and offer an address from there. |
| 1545 | AllocEngine::ClientContext4 |
| 1546 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1547 | false, false, "host.example.com.", false); |
| 1548 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1549 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1550 | |
| 1551 | // The allocation engine should have assigned an address from the first |
| 1552 | // subnet. |
| 1553 | 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" , 1553, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1554 | 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" , 1554, gtest_ar.failure_message()) = ::testing::Message(); |
| 1555 | |
| 1556 | // Make sure the lease is in the lease mgr. |
| 1557 | 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" , 1557, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1558 | } |
| 1559 | |
| 1560 | // This test verifies that the server can allocate an address from a |
| 1561 | // different subnet than orginally selected, when the address pool in |
| 1562 | // the first subnet is exhausted. |
| 1563 | TEST_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" , 1563), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1563), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1563), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetwork_Test >); void SharedNetworkAlloc4Test_requestSharedNetwork_Test ::TestBody() { |
| 1564 | |
| 1565 | // Create a lease for a single address in the first address pool. The |
| 1566 | // pool is now exhausted. |
| 1567 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
| 1568 | |
| 1569 | // Create context which will be used to try to allocate leases from the |
| 1570 | // shared network. The context points to subnet1, which address space |
| 1571 | // is exhausted. We expect the allocation engine to find another subnet |
| 1572 | // within the same shared network and offer an address from there. |
| 1573 | AllocEngine::ClientContext4 |
| 1574 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1575 | false, false, "host.example.com.", false); |
| 1576 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1577 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
| 1578 | // The allocation engine should have assigned an address from the second |
| 1579 | // subnet. We could guess that this is 10.1.2.5, being the first address |
| 1580 | // in the address pool, but to make the test more generic, we merely |
| 1581 | // verify that the address is in the given address pool. |
| 1582 | 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" , 1582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1583 | 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" , 1583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1584 | |
| 1585 | 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" , 1585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease2)", "false", "true") .c_str()) = ::testing::Message(); |
| 1586 | |
| 1587 | // The client should also be assigned a lease when it specifies a hint |
| 1588 | // that doesn't match the subnet from which the lease is offered. The |
| 1589 | // engine should check alternative subnets to match the hint to |
| 1590 | // a subnet. The requested lease is available, so it should be offered. |
| 1591 | ctx.subnet_ = subnet1_; |
| 1592 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
| 1593 | lease2 = engine_.allocateLease4(ctx); |
| 1594 | 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" , 1594, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1595 | 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" , 1595, gtest_ar.failure_message()) = ::testing::Message(); |
| 1596 | |
| 1597 | // The returning client (the one that has a lease) should also be able |
| 1598 | // to renew its lease regardless of a subnet it begins with. So, it has |
| 1599 | // an address assigned from subnet1, but we use subnet2 as a selected |
| 1600 | // subnet. |
| 1601 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
| 1602 | IOAddress("0.0.0.0"), false, false, |
| 1603 | "host.example.com.", false); |
| 1604 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1605 | lease2 = engine_.allocateLease4(ctx2); |
| 1606 | // The existing lease should be returned. |
| 1607 | 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" , 1607, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1608 | 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" , 1608, gtest_ar.failure_message()) = ::testing::Message(); |
| 1609 | } |
| 1610 | |
| 1611 | // This test verifies that the server can assign an address from a |
| 1612 | // different subnet than orginally selected, when the address pool in |
| 1613 | // the first subnet is exhausted. |
| 1614 | TEST_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" , 1614), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1614), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1614), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test ::TestBody() { |
| 1615 | // Try to offer address from subnet1. There is one address available |
| 1616 | // so it should be offered. |
| 1617 | AllocEngine::ClientContext4 |
| 1618 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1619 | false, false, "host.example.com.", false); |
| 1620 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1621 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1622 | 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" , 1622, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1623 | 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" , 1623, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1624 | |
| 1625 | // Remove the lease so as we can start over. |
| 1626 | 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" , 1626, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1627 | |
| 1628 | // Apply restrictions on the subnet1. This should be only assigned |
| 1629 | // to clients belonging to cable-modem class. |
| 1630 | subnet1_->allowClientClass("cable-modem"); |
| 1631 | |
| 1632 | // The allocation engine should determine that the subnet1 is not |
| 1633 | // available for the client not belonging to the cable-modem class. |
| 1634 | // Instead, it should assign an address from subnet2 that belongs |
| 1635 | // to the same shared network. |
| 1636 | ctx.subnet_ = subnet1_; |
| 1637 | lease = engine_.allocateLease4(ctx); |
| 1638 | 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" , 1638, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1639 | 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" , 1639, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1640 | |
| 1641 | // Remove the lease so as we can start over. |
| 1642 | 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" , 1642, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1643 | |
| 1644 | // Assign cable-modem class and try again. This time, we should |
| 1645 | // offer an address from the subnet1. |
| 1646 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1647 | |
| 1648 | ctx.subnet_ = subnet1_; |
| 1649 | lease = engine_.allocateLease4(ctx); |
| 1650 | 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" , 1650, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1651 | 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" , 1651, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1652 | |
| 1653 | // Let's now remove the client from the cable-modem class and try |
| 1654 | // to renew the address. The engine should determine that the |
| 1655 | // client doesn't have access to the subnet1 pools anymore and |
| 1656 | // assign an address from unrestricted subnet. |
| 1657 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1658 | ctx.subnet_ = subnet1_; |
| 1659 | lease = engine_.allocateLease4(ctx); |
| 1660 | 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" , 1660, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1661 | 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" , 1661, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1662 | } |
| 1663 | |
| 1664 | // This test verifies that the server can assign an address from a |
| 1665 | // different subnet than orginally selected, when the address pool in |
| 1666 | // the first subnet requires another class. |
| 1667 | TEST_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" , 1667), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1667), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1667), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test ::TestBody() { |
| 1668 | // Try to offer address from subnet1. There is one address available |
| 1669 | // so it should be offered. |
| 1670 | AllocEngine::ClientContext4 |
| 1671 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1672 | false, false, "host.example.com.", false); |
| 1673 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1674 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1675 | 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" , 1675, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1676 | 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" , 1676, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1677 | |
| 1678 | // Remove the lease so as we can start over. |
| 1679 | 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" , 1679, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1680 | |
| 1681 | // Apply restrictions on the pool1. This should be only assigned |
| 1682 | // to clients belonging to cable-modem class. |
| 1683 | pool1_->allowClientClass("cable-modem"); |
| 1684 | |
| 1685 | // The allocation engine should determine that the pool1 is not |
| 1686 | // available for the client not belonging to the cable-modem class. |
| 1687 | // Instead, it should assign an address from subnet2 that belongs |
| 1688 | // to the same shared network. |
| 1689 | ctx.subnet_ = subnet1_; |
| 1690 | lease = engine_.allocateLease4(ctx); |
| 1691 | 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" , 1691, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1692 | 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" , 1692, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1693 | |
| 1694 | // Remove the lease so as we can start over. |
| 1695 | 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" , 1695, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1696 | |
| 1697 | // Assign cable-modem class and try again. This time, we should |
| 1698 | // offer an address from the pool1. |
| 1699 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1700 | |
| 1701 | // Restrict access to pool2 for this client, to make sure that the |
| 1702 | // server doesn't accidentally get an address from this pool. |
| 1703 | pool2_->allowClientClass("telephone"); |
| 1704 | |
| 1705 | ctx.subnet_ = subnet1_; |
| 1706 | lease = engine_.allocateLease4(ctx); |
| 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_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" , 1708, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1709 | |
| 1710 | // Let's now remove the client from the cable-modem class and try |
| 1711 | // to renew the address. The engine should determine that the |
| 1712 | // client doesn't have access to the pool1 anymore and |
| 1713 | // assign an address from another pool. |
| 1714 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1715 | ctx.query_->addClass(ClientClass("telephone")); |
| 1716 | ctx.subnet_ = subnet1_; |
| 1717 | lease = engine_.allocateLease4(ctx); |
| 1718 | 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" , 1718, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1719 | 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" , 1719, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1720 | } |
| 1721 | |
| 1722 | // Test that reservations within shared network take precedence over the |
| 1723 | // existing leases regardless in which subnet belonging to a shared network |
| 1724 | // reservations belong (DHCPREQUEST case). |
| 1725 | TEST_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" , 1725), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1725), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1725), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test ::TestBody() { |
| 1726 | |
| 1727 | 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" , 1727, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1728 | |
| 1729 | // Create reservation for the client. |
| 1730 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1731 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1732 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1733 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1734 | CfgMgr::instance().commit(); |
| 1735 | |
| 1736 | // Start allocation from subnet1. The engine should determine that the |
| 1737 | // client has reservations in subnet2 and should rather assign reserved |
| 1738 | // addresses. |
| 1739 | AllocEngine::ClientContext4 |
| 1740 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1741 | false, false, "host.example.com.", false); |
| 1742 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1743 | AllocEngine::findReservation(ctx); |
| 1744 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1745 | 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" , 1745, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1746 | 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" , 1746, gtest_ar.failure_message()) = ::testing::Message(); |
| 1747 | 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" , 1747, gtest_ar.failure_message()) = ::testing::Message(); |
| 1748 | |
| 1749 | // Remove the lease for another test below. |
| 1750 | 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" , 1750, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1751 | |
| 1752 | // Let's create a lease for the client to make sure the lease is not |
| 1753 | // renewed but a reserved lease is allocated again. |
| 1754 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1755 | 501, time(0), subnet1_->getID())); |
| 1756 | lease->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 1757 | 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" , 1757, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1758 | ctx.subnet_ = subnet1_; |
| 1759 | ctx.hosts_.clear(); |
| 1760 | AllocEngine::findReservation(ctx); |
| 1761 | lease = engine_.allocateLease4(ctx); |
| 1762 | 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" , 1762, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1763 | 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" , 1763, gtest_ar.failure_message()) = ::testing::Message(); |
| 1764 | 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" , 1764, gtest_ar.failure_message()) = ::testing::Message(); |
| 1765 | } |
| 1766 | |
| 1767 | // Test that reservations within shared network take precedence over the |
| 1768 | // existing leases regardless in which subnet belonging to a shared network |
| 1769 | // reservations belong (DHCPREQUEST case). Host lookups returning a collection |
| 1770 | // are disabled. As it is only an optimization the behavior (so the test) |
| 1771 | // must stay unchanged. |
| 1772 | TEST_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" , 1772), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1772), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1772), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test ::TestBody() { |
| 1773 | |
| 1774 | // Disable host lookups returning a collection. |
| 1775 | 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" , 1775, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1776 | HostMgr::instance().setDisableSingleQuery(true); |
| 1777 | |
| 1778 | // Create reservation for the client. |
| 1779 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1780 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1781 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1782 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1783 | CfgMgr::instance().commit(); |
| 1784 | |
| 1785 | // Start allocation from subnet1. The engine should determine that the |
| 1786 | // client has reservations in subnet2 and should rather assign reserved |
| 1787 | // addresses. |
| 1788 | AllocEngine::ClientContext4 |
| 1789 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1790 | false, false, "host.example.com.", false); |
| 1791 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1792 | AllocEngine::findReservation(ctx); |
| 1793 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1794 | 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" , 1794, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1795 | 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" , 1795, gtest_ar.failure_message()) = ::testing::Message(); |
| 1796 | 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" , 1796, gtest_ar.failure_message()) = ::testing::Message(); |
| 1797 | |
| 1798 | // Remove the lease for another test below. |
| 1799 | 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" , 1799, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1800 | |
| 1801 | // Let's create a lease for the client to make sure the lease is not |
| 1802 | // renewed but a reserved lease is allocated again. |
| 1803 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1804 | 501, time(0), subnet1_->getID())); |
| 1805 | lease->cltt_ = time(0) - 10; // Allocated 10 seconds ago |
| 1806 | 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" , 1806, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1807 | ctx.subnet_ = subnet1_; |
| 1808 | ctx.hosts_.clear(); |
| 1809 | AllocEngine::findReservation(ctx); |
| 1810 | lease = engine_.allocateLease4(ctx); |
| 1811 | 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" , 1811, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1812 | 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" , 1812, gtest_ar.failure_message()) = ::testing::Message(); |
| 1813 | 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" , 1813, gtest_ar.failure_message()) = ::testing::Message(); |
| 1814 | } |
| 1815 | |
| 1816 | // This test checks if an expired lease can be reused in DHCPDISCOVER (fake |
| 1817 | // allocation) |
| 1818 | TEST_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" , 1818), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1818), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1818), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseExpiredLease4_Test >); void AllocEngine4Test_discoverReuseExpiredLease4_Test:: TestBody() { |
| 1819 | boost::scoped_ptr<AllocEngine> engine; |
| 1820 | 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_1820 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1820 ; } } else gtest_label_testnothrow_1820 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1820, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 1821 | 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" , 1821, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1822 | |
| 1823 | IOAddress addr("192.0.2.15"); |
| 1824 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 1825 | // Get rid of the default test configuration. |
| 1826 | cfg_mgr.clear(); |
| 1827 | |
| 1828 | // Create configuration similar to other tests, but with a single address pool |
| 1829 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1830 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 1831 | subnet_->addPool(pool_); |
| 1832 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 1833 | |
| 1834 | // Just a different hw/client-id for the second client |
| 1835 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 1836 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 1837 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 1838 | time_t now = time(0) - 500; // Allocated 500 seconds ago |
| 1839 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 1840 | 495, now, subnet_->getID())); |
| 1841 | // Copy the lease, so as it can be compared with the old lease returned |
| 1842 | // by the allocation engine. |
| 1843 | Lease4 original_lease(*lease); |
| 1844 | |
| 1845 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 1846 | // is expired already |
| 1847 | 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" , 1847, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 1848 | 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" , 1848, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1849 | |
| 1850 | // CASE 1: Asking for any address |
| 1851 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 1852 | IOAddress("0.0.0.0"), false, false, |
| 1853 | "", true); |
| 1854 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1855 | lease = engine->allocateLease4(ctx1); |
| 1856 | // Check that we got that single lease |
| 1857 | 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" , 1857, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1858 | 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" , 1858, gtest_ar.failure_message()) = ::testing::Message(); |
| 1859 | |
| 1860 | // We are reusing expired lease, the old (expired) instance should be |
| 1861 | // returned. The returned instance should be the same as the original |
| 1862 | // lease. |
| 1863 | 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" , 1863, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 1864 | 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" , 1864, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
| 1865 | |
| 1866 | // Do all checks on the lease (if subnet-id, preferred/valid times are ok etc.) |
| 1867 | checkLease4(lease); |
| 1868 | |
| 1869 | // CASE 2: Asking specifically for this address |
| 1870 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 1871 | IOAddress(addr), false, false, |
| 1872 | "", true); |
| 1873 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1874 | lease = engine->allocateLease4(ctx2); |
| 1875 | // Check that we got that single lease |
| 1876 | 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" , 1876, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1877 | 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" , 1877, gtest_ar.failure_message()) = ::testing::Message(); |
| 1878 | |
| 1879 | // We are updating expired lease. The copy of the old lease should be |
| 1880 | // returned and it should be equal to the original lease. |
| 1881 | 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" , 1881, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 1882 | 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" , 1882, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*ctx2.old_lease_ == original_lease", "false", "true") .c_str ()) = ::testing::Message(); |
| 1883 | } |
| 1884 | |
| 1885 | // This test checks if an expired lease can be reused in REQUEST (actual allocation) |
| 1886 | TEST_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" , 1886), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1886), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1886), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseExpiredLease4_Test >); void AllocEngine4Test_requestReuseExpiredLease4_Test:: TestBody() { |
| 1887 | boost::scoped_ptr<AllocEngine> engine; |
| 1888 | 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_1888 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1888 ; } } else gtest_label_testnothrow_1888 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1888, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 1889 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1889, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1890 | |
| 1891 | IOAddress addr("192.0.2.105"); |
| 1892 | |
| 1893 | 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" , 1893, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1894 | 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" , 1894, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1895 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 1896 | subnet_->getID()); |
| 1897 | |
| 1898 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 1899 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 1900 | |
| 1901 | 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" , 1901, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0)", "false", "true") .c_str()) = ::testing::Message(); |
| 1902 | 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" , 1902, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1903 | |
| 1904 | // Just a different hw/client-id for the second client |
| 1905 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 1906 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 1907 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 1908 | time_t now = time(0) - 500; // Allocated 500 seconds ago |
| 1909 | |
| 1910 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 1911 | 495, now, subnet_->getID())); |
| 1912 | // Make a copy of the lease, so as we can compare that with the old lease |
| 1913 | // instance returned by the allocation engine. |
| 1914 | Lease4 original_lease(*lease); |
| 1915 | |
| 1916 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 1917 | // is expired already |
| 1918 | 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" , 1918, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 1919 | 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" , 1919, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1920 | |
| 1921 | // A client comes along, asking specifically for this address |
| 1922 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 1923 | IOAddress(addr), false, false, |
| 1924 | "host.example.com.", false); |
| 1925 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1926 | lease = engine->allocateLease4(ctx); |
| 1927 | |
| 1928 | // Check that he got that single lease |
| 1929 | 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" , 1929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1930 | 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" , 1930, gtest_ar.failure_message()) = ::testing::Message(); |
| 1931 | |
| 1932 | // Check that the lease is indeed updated in LeaseMgr |
| 1933 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 1934 | 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" , 1934, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 1935 | |
| 1936 | // Now check that the lease in LeaseMgr has the same parameters |
| 1937 | detailCompareLease(lease, from_mgr); |
| 1938 | |
| 1939 | // The allocation engine should return a copy of the old lease. This |
| 1940 | // lease should be equal to the original lease. |
| 1941 | 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" , 1941, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 1942 | 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" , 1942, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*ctx.old_lease_ == original_lease", "false", "true") .c_str ()) = ::testing::Message(); |
| 1943 | |
| 1944 | // Check that the stats declined stats were modified correctly. Note, because |
| 1945 | // added the lease directly, assigned-leases never bumped to one, so when we |
| 1946 | // reclaim it gets decremented to -1, then on assignment back to 0. |
| 1947 | 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" , 1947, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1948 | cumulative += 1; |
| 1949 | 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" , 1950, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 1950 | 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" , 1950, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1951 | 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" , 1951, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1952 | glbl_cumulative += 1; |
| 1953 | 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" , 1953, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 1954 | 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" , 1954, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1)", "false", "true") .c_str()) = ::testing::Message(); |
| 1955 | 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" , 1955, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1956 | } |
| 1957 | |
| 1958 | // This test checks if an expired declined lease can be reused when responding |
| 1959 | // to DHCPDISCOVER (fake allocation) |
| 1960 | TEST_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" , 1960), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1960), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1960), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4_Test ::TestBody() { |
| 1961 | |
| 1962 | AllocEnginePtr engine(new AllocEngine(0)); |
| 1963 | 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" , 1963, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1964 | |
| 1965 | // Now prepare a configuration with single address pool. |
| 1966 | IOAddress addr("192.0.2.15"); |
| 1967 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 1968 | cfg_mgr.clear(); |
| 1969 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1970 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 1971 | subnet_->addPool(pool_); |
| 1972 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 1973 | |
| 1974 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 1975 | // is expired. |
| 1976 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 1977 | |
| 1978 | // CASE 1: Ask for any address |
| 1979 | Lease4Ptr assigned; |
| 1980 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
| 1981 | |
| 1982 | // Check that we got that single lease |
| 1983 | 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" , 1983, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 1984 | 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" , 1984, gtest_ar.failure_message()) = ::testing::Message(); |
| 1985 | |
| 1986 | // CASE 2: Asking specifically for this address |
| 1987 | testReuseLease4(engine, declined, "192.0.2.15", true, SHOULD_PASS, assigned); |
| 1988 | |
| 1989 | // Check that we get it again |
| 1990 | 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" , 1990, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 1991 | 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" , 1991, gtest_ar.failure_message()) = ::testing::Message(); |
| 1992 | } |
| 1993 | |
| 1994 | // This test checks if statistics are not updated when expired declined lease |
| 1995 | // is reused when responding to DHCPDISCOVER (fake allocation) |
| 1996 | TEST_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" , 1996), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1996), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1996), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test ::TestBody() { |
| 1997 | |
| 1998 | // Now prepare for DISCOVER processing |
| 1999 | AllocEnginePtr engine(new AllocEngine(0)); |
| 2000 | 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" , 2000, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 2001 | |
| 2002 | // Now prepare a configuration with single address pool. |
| 2003 | IOAddress addr("192.0.2.15"); |
| 2004 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 2005 | cfg_mgr.clear(); |
| 2006 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 2007 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 2008 | subnet_->addPool(pool_); |
| 2009 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 2010 | cfg_mgr.commit(); // so we will recalc stats |
| 2011 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 2012 | subnet_->getID()); |
| 2013 | |
| 2014 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 2015 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 2016 | |
| 2017 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 2018 | // is expired. |
| 2019 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 2020 | |
| 2021 | // Ask for any address. There's only one address in the pool, so it doesn't |
| 2022 | // matter much. |
| 2023 | Lease4Ptr assigned; |
| 2024 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
| 2025 | |
| 2026 | // Check that the stats declined stats were not modified |
| 2027 | 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" , 2027, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2028 | 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" , 2029, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 2029 | 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" , 2029, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2030 | 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" , 2030, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2031 | 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" , 2031, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2032 | 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" , 2032, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", 0)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 2033 | 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" , 2033, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 0)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2034 | 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" , 2034, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2035 | 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" , 2035, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2036 | } |
| 2037 | |
| 2038 | // This test checks if a not expired declined lease can not be reused |
| 2039 | // when responding to DHCPDISCOVER (fake allocation) |
| 2040 | TEST_F(AllocEngine4Test, discoverBadReuseDeclinedLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("discoverBadReuseDeclinedLease4") > 1, "test_name must not be empty"); class AllocEngine4Test_discoverBadReuseDeclinedLease4_Test : public AllocEngine4Test { public: AllocEngine4Test_discoverBadReuseDeclinedLease4_Test () = default; ~AllocEngine4Test_discoverBadReuseDeclinedLease4_Test () override = default; AllocEngine4Test_discoverBadReuseDeclinedLease4_Test (const AllocEngine4Test_discoverBadReuseDeclinedLease4_Test & ) = delete; AllocEngine4Test_discoverBadReuseDeclinedLease4_Test & operator=( const AllocEngine4Test_discoverBadReuseDeclinedLease4_Test &) = delete; AllocEngine4Test_discoverBadReuseDeclinedLease4_Test (AllocEngine4Test_discoverBadReuseDeclinedLease4_Test && ) noexcept = delete; AllocEngine4Test_discoverBadReuseDeclinedLease4_Test & operator=( AllocEngine4Test_discoverBadReuseDeclinedLease4_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const AllocEngine4Test_discoverBadReuseDeclinedLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverBadReuseDeclinedLease4", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2040), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2040), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2040), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverBadReuseDeclinedLease4_Test >); void AllocEngine4Test_discoverBadReuseDeclinedLease4_Test ::TestBody() { |
| 2041 | |
| 2042 | AllocEnginePtr engine(new AllocEngine(0)); |
| 2043 | 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" , 2043, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 2044 | |
| 2045 | // Now prepare a configuration with single address pool. |
| 2046 | IOAddress addr("192.0.2.15"); |
| 2047 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 2048 | cfg_mgr.clear(); |
| 2049 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 2050 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 2051 | subnet_->addPool(pool_); |
| 2052 | // Set match-client-id to false. |
| 2053 | subnet_->setMatchClientId(false); |
| 2054 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 2055 | |
| 2056 | // Now create a declined lease which is not yet expired. |
| 2057 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, 100); |
| 2058 | |
| 2059 | // Set the hardware address to empty. |
| 2060 | std::vector<uint8_t> empty; |
| 2061 | hwaddr_.reset(new HWAddr(empty, HTYPE_ETHER)); |
| 2062 | |
| 2063 | // Asking specifically for this address (inline testReuseLease4). |
| 2064 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(declined))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(declined))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(declined)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 2065 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2066 | IOAddress("192.0.2.15"), false, false, |
| 2067 | "", true); |
| 2068 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 2069 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 2070 | EXPECT_FALSE(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", 2070, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 2071 | } |
| 2072 | |
| 2073 | // This test checks if an expired declined lease can be reused when responding |
| 2074 | // to REQUEST (actual allocation) |
| 2075 | TEST_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" , 2075), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2075), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2075), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4_Test >); void AllocEngine4Test_requestReuseDeclinedLease4_Test:: TestBody() { |
| 2076 | |
| 2077 | AllocEnginePtr engine(new AllocEngine(0)); |
| 2078 | 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" , 2078, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 2079 | |
| 2080 | // Now prepare a configuration with single address pool. |
| 2081 | IOAddress addr("192.0.2.15"); |
| 2082 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 2083 | cfg_mgr.clear(); |
| 2084 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 2085 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 2086 | subnet_->addPool(pool_); |
| 2087 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 2088 | |
| 2089 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 2090 | // is expired. |
| 2091 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 2092 | |
| 2093 | // Asking specifically for this address |
| 2094 | Lease4Ptr assigned; |
| 2095 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
| 2096 | // Check that we got it. |
| 2097 | 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" , 2097, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 2098 | 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" , 2098, gtest_ar.failure_message()) = ::testing::Message(); |
| 2099 | |
| 2100 | // Check that the lease is indeed updated in LeaseMgr |
| 2101 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 2102 | 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" , 2102, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2103 | |
| 2104 | // Now check that the lease in LeaseMgr has the same parameters |
| 2105 | detailCompareLease(assigned, from_mgr); |
| 2106 | } |
| 2107 | |
| 2108 | // This test checks if statistics are not updated when expired declined lease |
| 2109 | // is reused when responding to DHCPREQUEST (actual allocation) |
| 2110 | TEST_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" , 2110), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2110), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2110), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_requestReuseDeclinedLease4Stats_Test ::TestBody() { |
| 2111 | |
| 2112 | AllocEnginePtr engine(new AllocEngine(0)); |
| 2113 | 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" , 2113, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 2114 | |
| 2115 | // Now prepare a configuration with single address pool. |
| 2116 | IOAddress addr("192.0.2.15"); |
| 2117 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 2118 | cfg_mgr.clear(); |
| 2119 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 2120 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 2121 | subnet_->addPool(pool_); |
| 2122 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 2123 | cfg_mgr.commit(); |
| 2124 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 2125 | subnet_->getID()); |
| 2126 | |
| 2127 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 2128 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 2129 | |
| 2130 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 2131 | // is expired. |
| 2132 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 2133 | |
| 2134 | // Asking specifically for this address |
| 2135 | Lease4Ptr assigned; |
| 2136 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
| 2137 | // Check that we got it. |
| 2138 | 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" , 2138, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 2139 | |
| 2140 | // Check that the stats are correct. Note that assigned-addresses does |
| 2141 | // not get decremented when a lease is declined, ergo not incremented |
| 2142 | // when it is reused. Declined address stats will be -1 since |
| 2143 | // lease was created as declined which does not increment the stat. |
| 2144 | 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" , 2144, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2145 | cumulative += 1; |
| 2146 | 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" , 2147, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 2147 | 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" , 2147, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2148 | 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" , 2148, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2149 | glbl_cumulative += 1; |
| 2150 | 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" , 2150, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2151 | 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" , 2151, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", -1)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 2152 | 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" , 2152, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 1)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2153 | 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" , 2153, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", -1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2154 | 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" , 2154, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2155 | } |
| 2156 | |
| 2157 | // This test checks if a not expired declined lease can not be reused |
| 2158 | // when responding to REQUEST (actual allocation) |
| 2159 | TEST_F(AllocEngine4Test, requestBadReuseDeclinedLease4)static_assert(sizeof("AllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("requestBadReuseDeclinedLease4") > 1, "test_name must not be empty"); class AllocEngine4Test_requestBadReuseDeclinedLease4_Test : public AllocEngine4Test { public: AllocEngine4Test_requestBadReuseDeclinedLease4_Test () = default; ~AllocEngine4Test_requestBadReuseDeclinedLease4_Test () override = default; AllocEngine4Test_requestBadReuseDeclinedLease4_Test (const AllocEngine4Test_requestBadReuseDeclinedLease4_Test & ) = delete; AllocEngine4Test_requestBadReuseDeclinedLease4_Test & operator=( const AllocEngine4Test_requestBadReuseDeclinedLease4_Test &) = delete; AllocEngine4Test_requestBadReuseDeclinedLease4_Test (AllocEngine4Test_requestBadReuseDeclinedLease4_Test && ) noexcept = delete; AllocEngine4Test_requestBadReuseDeclinedLease4_Test & operator=( AllocEngine4Test_requestBadReuseDeclinedLease4_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const AllocEngine4Test_requestBadReuseDeclinedLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestBadReuseDeclinedLease4", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2159), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2159), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2159), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestBadReuseDeclinedLease4_Test >); void AllocEngine4Test_requestBadReuseDeclinedLease4_Test ::TestBody() { |
| 2160 | |
| 2161 | AllocEnginePtr engine(new AllocEngine(0)); |
| 2162 | 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" , 2162, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 2163 | |
| 2164 | // Now prepare a configuration with single address pool. |
| 2165 | IOAddress addr("192.0.2.15"); |
| 2166 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 2167 | cfg_mgr.clear(); |
| 2168 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 2169 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 2170 | subnet_->addPool(pool_); |
| 2171 | // Set match-client-id to false. |
| 2172 | subnet_->setMatchClientId(false); |
| 2173 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 2174 | |
| 2175 | // Now create a declined lease which is not yet expired. |
| 2176 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, 100); |
| 2177 | |
| 2178 | // Set the hardware address to empty. |
| 2179 | std::vector<uint8_t> empty; |
| 2180 | hwaddr_.reset(new HWAddr(empty, HTYPE_ETHER)); |
| 2181 | |
| 2182 | // Asking specifically for this address (inline testReuseLease4). |
| 2183 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(declined))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(declined))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2183, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(declined)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 2184 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2185 | IOAddress("192.0.2.15"), false, false, |
| 2186 | "", false); |
| 2187 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2188 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 2189 | EXPECT_FALSE(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", 2189, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 2190 | } |
| 2191 | |
| 2192 | // This test checks if a released lease can be reused in REQUEST (actual allocation) |
| 2193 | TEST_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" , 2193), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2193), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2193), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseReleasedLease4_Test >); void AllocEngine4Test_requestReuseReleasedLease4_Test:: TestBody() { |
| 2194 | boost::scoped_ptr<AllocEngine> engine; |
| 2195 | 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_2195 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2195 ; } } else gtest_label_testnothrow_2195 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2195, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 2196 | 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" , 2196, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 2197 | |
| 2198 | IOAddress addr("192.0.2.105"); |
| 2199 | |
| 2200 | 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" , 2200, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2201 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 2202 | subnet_->getID()); |
| 2203 | |
| 2204 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 2205 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 2206 | |
| 2207 | 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" , 2207, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0)", "false", "true") .c_str()) = ::testing::Message(); |
| 2208 | 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" , 2208, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2209 | |
| 2210 | // Just a different hw/client-id for the second client |
| 2211 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 2212 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 2213 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 2214 | time_t now = time(0) - 500; // Allocated 500 seconds ago |
| 2215 | |
| 2216 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 2217 | 495, now, subnet_->getID())); |
| 2218 | lease->state_ = Lease4::STATE_RELEASED; |
| 2219 | // Make a copy of the lease, so as we can compare that with the old lease |
| 2220 | // instance returned by the allocation engine. |
| 2221 | Lease4 original_lease(*lease); |
| 2222 | |
| 2223 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 2224 | // is expired already |
| 2225 | 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" , 2225, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 2226 | 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" , 2226, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 2227 | |
| 2228 | // A client comes along, asking specifically for this address |
| 2229 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2230 | IOAddress(addr), false, false, |
| 2231 | "host.example.com.", false); |
| 2232 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2233 | lease = engine->allocateLease4(ctx); |
| 2234 | |
| 2235 | // Check that he got that single lease |
| 2236 | 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" , 2236, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2237 | 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" , 2237, gtest_ar.failure_message()) = ::testing::Message(); |
| 2238 | |
| 2239 | // Check that the lease is indeed updated in LeaseMgr |
| 2240 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 2241 | 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" , 2241, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2242 | |
| 2243 | // Now check that the lease in LeaseMgr has the same parameters |
| 2244 | detailCompareLease(lease, from_mgr); |
| 2245 | |
| 2246 | // The allocation engine should return a copy of the old lease. This |
| 2247 | // lease should be equal to the original lease. |
| 2248 | 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" , 2248, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 2249 | 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" , 2249, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*ctx.old_lease_ == original_lease", "false", "true") .c_str ()) = ::testing::Message(); |
| 2250 | |
| 2251 | 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" , 2251, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2252 | cumulative += 1; |
| 2253 | 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" , 2254, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 2254 | 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" , 2254, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2255 | glbl_assigned += 1; |
| 2256 | 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" , 2256, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2257 | glbl_cumulative += 1; |
| 2258 | 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" , 2258, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2259 | 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" , 2259, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1)", "false", "true") .c_str()) = ::testing::Message(); |
| 2260 | 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" , 2260, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2261 | } |
| 2262 | |
| 2263 | // This test checks that the Allocation Engine correctly identifies the |
| 2264 | // existing client's lease in the lease database, using the client |
| 2265 | // identifier and HW address. |
| 2266 | TEST_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" , 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_identifyClientLease_Test >); void AllocEngine4Test_identifyClientLease_Test::TestBody () { |
| 2267 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, clientid_, |
| 2268 | 100, time(0), subnet_->getID())); |
| 2269 | LeaseMgrFactory::instance().addLease(lease); |
| 2270 | |
| 2271 | AllocEngine engine(0); |
| 2272 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2273 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 2274 | false, false, "", true); |
| 2275 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2276 | |
| 2277 | Lease4Ptr identified_lease = engine.allocateLease4(ctx); |
| 2278 | 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" , 2278, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2279 | 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" , 2279, gtest_ar.failure_message()) = ::testing::Message(); |
| 2280 | |
| 2281 | ctx.hwaddr_ = hwaddr2_; |
| 2282 | ctx.clientid_ = clientid_; |
| 2283 | identified_lease = engine.allocateLease4(ctx); |
| 2284 | 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" , 2284, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2285 | 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" , 2285, gtest_ar.failure_message()) = ::testing::Message(); |
| 2286 | |
| 2287 | ctx.hwaddr_ = hwaddr_; |
| 2288 | ctx.clientid_ = clientid2_; |
| 2289 | identified_lease = engine.allocateLease4(ctx); |
| 2290 | 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" , 2290, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2291 | 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" , 2291, gtest_ar.failure_message()) = ::testing::Message(); |
| 2292 | |
| 2293 | ctx.hwaddr_ = hwaddr_; |
| 2294 | ctx.clientid_.reset(); |
| 2295 | identified_lease = engine.allocateLease4(ctx); |
| 2296 | 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" , 2296, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2297 | 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" , 2297, gtest_ar.failure_message()) = ::testing::Message(); |
| 2298 | |
| 2299 | ctx.hwaddr_ = hwaddr2_; |
| 2300 | ctx.clientid_.reset(); |
| 2301 | identified_lease = engine.allocateLease4(ctx); |
| 2302 | 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" , 2302, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2303 | 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" , 2303, gtest_ar.failure_message()) = ::testing::Message(); |
| 2304 | |
| 2305 | lease->client_id_.reset(); |
| 2306 | 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_2306; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2306; } } else gtest_label_testnothrow_2306 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2306, ("Expected: " "LeaseMgrFactory::instance().updateLease4(lease)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 2307 | |
| 2308 | ctx.hwaddr_ = hwaddr_; |
| 2309 | ctx.clientid_ = clientid_; |
| 2310 | identified_lease = engine.allocateLease4(ctx); |
| 2311 | 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" , 2311, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2312 | 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" , 2312, gtest_ar.failure_message()) = ::testing::Message(); |
| 2313 | |
| 2314 | ctx.hwaddr_ = hwaddr_; |
| 2315 | ctx.clientid_.reset(); |
| 2316 | identified_lease = engine.allocateLease4(ctx); |
| 2317 | 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" , 2317, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2318 | 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" , 2318, gtest_ar.failure_message()) = ::testing::Message(); |
| 2319 | |
| 2320 | ctx.hwaddr_ = hwaddr2_; |
| 2321 | ctx.clientid_ = clientid_; |
| 2322 | identified_lease = engine.allocateLease4(ctx); |
| 2323 | 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" , 2323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2324 | 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" , 2324, gtest_ar.failure_message()) = ::testing::Message(); |
| 2325 | } |
| 2326 | |
| 2327 | // This test checks that when the client requests the address which belongs |
| 2328 | // to another client, the allocation engine returns null (for the |
| 2329 | // DHCPREQUEST case) or a lease for the address which belongs to this |
| 2330 | // client (DHCPDISCOVER case). |
| 2331 | TEST_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" , 2331), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2331), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2331), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestOtherClientLease_Test >); void AllocEngine4Test_requestOtherClientLease_Test::TestBody () { |
| 2332 | // Create the first lease. |
| 2333 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2334 | &clientid_->getClientId()[0], |
| 2335 | clientid_->getClientId().size(), |
| 2336 | 100, time(0), subnet_->getID(), |
| 2337 | false, false, "")); |
| 2338 | // Create the second lease. Note that we use the same client id here and |
| 2339 | // we expect that the allocation engine will figure out that the hardware |
| 2340 | // address is different. |
| 2341 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr2_, |
| 2342 | &clientid_->getClientId()[0], |
| 2343 | clientid_->getClientId().size(), |
| 2344 | 100, time(0), subnet_->getID(), |
| 2345 | false, false, "")); |
| 2346 | // Add leases for both clients to the Lease Manager. |
| 2347 | LeaseMgrFactory::instance().addLease(lease); |
| 2348 | LeaseMgrFactory::instance().addLease(lease2); |
| 2349 | |
| 2350 | AllocEngine engine(0); |
| 2351 | |
| 2352 | // First client requests the lease which belongs to the second client. |
| 2353 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
| 2354 | false, false, "", false); |
| 2355 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2356 | Lease4Ptr new_lease = engine.allocateLease4(ctx); |
| 2357 | // Allocation engine should return null. |
| 2358 | 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" , 2358, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "true", "false") .c_str()) = ::testing::Message (); |
| 2359 | |
| 2360 | 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", 2360, gtest_ar.failure_message()) = ::testing::Message(); |
| 2361 | 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" , 2361, gtest_ar.failure_message()) = ::testing::Message(); |
| 2362 | 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", 2362, gtest_ar.failure_message()) = ::testing::Message(); |
| 2363 | 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", 2363, gtest_ar.failure_message()) = ::testing::Message(); |
| 2364 | 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", 2364, gtest_ar.failure_message()) = ::testing::Message(); |
| 2365 | |
| 2366 | 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" , 2366, gtest_ar.failure_message()) = ::testing::Message(); |
| 2367 | 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" , 2367, gtest_ar.failure_message()) = ::testing::Message(); |
| 2368 | 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" , 2368, gtest_ar.failure_message()) = ::testing::Message(); |
| 2369 | 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" , 2369, gtest_ar.failure_message()) = ::testing::Message(); |
| 2370 | 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" , 2370, gtest_ar.failure_message()) = ::testing::Message(); |
| 2371 | |
| 2372 | // Now simulate the DHCPDISCOVER case when the provided address is |
| 2373 | // treated as a hint. The engine should return a lease for a |
| 2374 | // different address than requested. |
| 2375 | ctx.fake_allocation_ = true; |
| 2376 | new_lease = engine.allocateLease4(ctx); |
| 2377 | 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" , 2377, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 2378 | 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" , 2378, gtest_ar.failure_message()) = ::testing::Message(); |
| 2379 | } |
| 2380 | |
| 2381 | // Allocation engine should remove a pre-existing lease |
| 2382 | // and renew the temporary lease when offer-lifetime > 0. |
| 2383 | // This can happen when a client gets a lease which is |
| 2384 | // later rendered invalid by the creation of host reservation, |
| 2385 | // either for the lease address or for the client with |
| 2386 | // a different address. |
| 2387 | TEST_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" , 2387), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2387), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2387), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_existingLeasePlusTemporary_Test >); void AllocEngine4Test_existingLeasePlusTemporary_Test:: TestBody() { |
| 2388 | // Create the first lease. |
| 2389 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2390 | &clientid_->getClientId()[0], |
| 2391 | clientid_->getClientId().size(), |
| 2392 | 100, time(0), subnet_->getID(), |
| 2393 | false, false, "")); |
| 2394 | |
| 2395 | // Create the second lease. |
| 2396 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr_, |
| 2397 | &clientid_->getClientId()[0], |
| 2398 | clientid_->getClientId().size(), |
| 2399 | 100, time(0), subnet_->getID(), |
| 2400 | false, false, "")); |
| 2401 | // Add leases for both clients to the Lease Manager. |
| 2402 | LeaseMgrFactory::instance().addLease(lease); |
| 2403 | LeaseMgrFactory::instance().addLease(lease2); |
| 2404 | |
| 2405 | // When temporary allocations are off and client requests the |
| 2406 | // second lease, the engine should not return a lease. |
| 2407 | AllocEngine engine(0); |
| 2408 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
| 2409 | false, false, "", false); |
| 2410 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2411 | Lease4Ptr new_lease = engine.allocateLease4(ctx); |
| 2412 | |
| 2413 | 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" , 2413, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "true", "false") .c_str()) = ::testing::Message (); |
| 2414 | |
| 2415 | // Both leases should still be in the lease back end. |
| 2416 | 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" , 2416, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2417 | 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" , 2417, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2418 | |
| 2419 | // Now enable temporary allocations by setting offer lifetime > 0. |
| 2420 | subnet_->setOfferLft(120); |
| 2421 | |
| 2422 | // Client requests the second lease. |
| 2423 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
| 2424 | false, false, "", false); |
| 2425 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2426 | new_lease = engine.allocateLease4(ctx2); |
| 2427 | |
| 2428 | // Allocation should return the second lease and remove the original lease. |
| 2429 | 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" , 2429, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 2430 | 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" , 2430, gtest_ar.failure_message()) = ::testing::Message(); |
| 2431 | |
| 2432 | // Original lease should have been deleted from lease back. |
| 2433 | 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" , 2433, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 2434 | } |
| 2435 | |
| 2436 | // This test checks the behavior of the allocation engine in the following |
| 2437 | // scenario: |
| 2438 | // - Client has no lease in the database. |
| 2439 | // - Client has a reservation. |
| 2440 | // - Client sends DHCPREQUEST without requested IP Address, nor ciaddr. |
| 2441 | // - Client is allocated a reserved address. |
| 2442 | // |
| 2443 | // Note that client must normally include a requested IP address or ciaddr |
| 2444 | // in its message. But, we still want to provision clients that don't do that. |
| 2445 | // The server simply picks reserved address or any other available one if there |
| 2446 | // is no reservation. |
| 2447 | TEST_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" , 2447), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2447), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2447), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHint_Test >); void AllocEngine4Test_reservedAddressNoHint_Test::TestBody () { |
| 2448 | // Create reservation for the client. |
| 2449 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2450 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2451 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2452 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2453 | CfgMgr::instance().commit(); |
| 2454 | |
| 2455 | AllocEngine engine(0); |
| 2456 | |
| 2457 | // Try to allocate a lease without specifying a hint. This is actually |
| 2458 | // incorrect behavior of the client to not send an address it wants to |
| 2459 | // obtain but the server should handle this gracefully. |
| 2460 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2461 | IOAddress("0.0.0.0"), false, false, |
| 2462 | "", false); |
| 2463 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2464 | AllocEngine::findReservation(ctx); |
| 2465 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 2466 | |
| 2467 | 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" , 2467, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2468 | 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" , 2468, gtest_ar.failure_message()) = ::testing::Message(); |
| 2469 | |
| 2470 | // Make sure that the lease has been committed to the lease database. |
| 2471 | // And that the committed lease is equal to the one returned. |
| 2472 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2473 | 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" , 2473, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2474 | detailCompareLease(lease, from_mgr); |
| 2475 | |
| 2476 | // Initially, there was no lease for this client, so the returned old |
| 2477 | // lease should be null. |
| 2478 | 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" , 2478, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 2479 | } |
| 2480 | |
| 2481 | // This test checks behavior of the allocation engine in the following scenario: |
| 2482 | // - Client has no lease in the database. |
| 2483 | // - Client has a reservation. |
| 2484 | // - Client sends DHCPDISCOVER without requested IP Address. |
| 2485 | // - Server returns DHCPOFFER with the reserved address. |
| 2486 | TEST_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" , 2486), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2486), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2486), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test ::TestBody() { |
| 2487 | // Create reservation for the client. |
| 2488 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2489 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2490 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2491 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2492 | CfgMgr::instance().commit(); |
| 2493 | |
| 2494 | AllocEngine engine(0); |
| 2495 | |
| 2496 | // Query allocation engine for the lease to be assigned to this |
| 2497 | // client without specifying the address to be assigned. |
| 2498 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2499 | IOAddress("0.0.0.0"), false, false, |
| 2500 | "", true); |
| 2501 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 2502 | AllocEngine::findReservation(ctx); |
| 2503 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 2504 | |
| 2505 | 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" , 2505, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2506 | // The allocation engine should return a reserved address. |
| 2507 | 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" , 2507, gtest_ar.failure_message()) = ::testing::Message(); |
| 2508 | |
| 2509 | // This is a "fake" allocation so the returned lease should not be committed |
| 2510 | // to the lease database. |
| 2511 | 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" , 2511, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 2512 | |
| 2513 | // Client had no lease in the database, so the old lease returned should |
| 2514 | // be null. |
| 2515 | 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" , 2515, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 2516 | } |
| 2517 | |
| 2518 | // This test checks the behavior of the allocation engine in the following |
| 2519 | // scenario: |
| 2520 | // - Client has no lease in the database. |
| 2521 | // - Client has a reservation. |
| 2522 | // - Client sends DHCPREQUEST with a requested IP address |
| 2523 | // - Server returns DHCPNAK when requested IP address is different than |
| 2524 | // the reserved address. Note that the allocation engine returns null |
| 2525 | // to indicate to the server that it should send DHCPNAK. |
| 2526 | // - Server allocates a reserved address to the client when the client requests |
| 2527 | // this address using requested IP address option. |
| 2528 | TEST_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" , 2528), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2528), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2528), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHint_Test >); void AllocEngine4Test_reservedAddressHint_Test::TestBody () { |
| 2529 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2530 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2531 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2532 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2533 | CfgMgr::instance().commit(); |
| 2534 | |
| 2535 | AllocEngine engine(0); |
| 2536 | |
| 2537 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2538 | IOAddress("192.0.2.234"), false, false, |
| 2539 | "", false); |
| 2540 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2541 | AllocEngine::findReservation(ctx1); |
| 2542 | Lease4Ptr lease = engine.allocateLease4(ctx1); |
| 2543 | |
| 2544 | // The client requested a different address than reserved, so |
| 2545 | // the allocation engine should return null lease. When the server |
| 2546 | // receives a null lease for the client, it will send a DHCPNAK. |
| 2547 | 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" , 2547, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 2548 | 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" , 2548, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2549 | |
| 2550 | 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", 2550, gtest_ar.failure_message()) = ::testing::Message(); |
| 2551 | 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" , 2551, gtest_ar.failure_message()) = ::testing::Message(); |
| 2552 | 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", 2552, gtest_ar.failure_message()) = ::testing::Message(); |
| 2553 | 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", 2553, gtest_ar.failure_message()) = ::testing::Message(); |
| 2554 | 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", 2554, gtest_ar.failure_message()) = ::testing::Message(); |
| 2555 | |
| 2556 | 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" , 2556, gtest_ar.failure_message()) = ::testing::Message(); |
| 2557 | 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" , 2557, gtest_ar.failure_message()) = ::testing::Message(); |
| 2558 | 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" , 2558, gtest_ar.failure_message()) = ::testing::Message(); |
| 2559 | 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" , 2559, gtest_ar.failure_message()) = ::testing::Message(); |
| 2560 | 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" , 2560, gtest_ar.failure_message()) = ::testing::Message(); |
| 2561 | |
| 2562 | // Now, request a correct address. The client should obtain it. |
| 2563 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2564 | IOAddress("192.0.2.123"), false, false, |
| 2565 | "", false); |
| 2566 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2567 | AllocEngine::findReservation(ctx2); |
| 2568 | lease = engine.allocateLease4(ctx2); |
| 2569 | 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" , 2569, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2570 | 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" , 2570, gtest_ar.failure_message()) = ::testing::Message(); |
| 2571 | |
| 2572 | // Make sure that the lease has been committed to the lease database. |
| 2573 | // And that the committed lease is equal to the one returned. |
| 2574 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2575 | 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" , 2575, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2576 | detailCompareLease(lease, from_mgr); |
| 2577 | |
| 2578 | 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" , 2578, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2579 | } |
| 2580 | |
| 2581 | // This test checks the behavior of the allocation engine in the following |
| 2582 | // scenario: |
| 2583 | // - Client has no lease in the database. |
| 2584 | // - Client has a reservation. |
| 2585 | // - Client sends DHCPDISCOVER with a requested IP address as a hint. |
| 2586 | // - Server offers a reserved address, even though it is different than the |
| 2587 | // requested address. |
| 2588 | TEST_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" , 2588), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2588), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2588), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHintFakeAllocation_Test ::TestBody() { |
| 2589 | // Create a reservation for the client. |
| 2590 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2591 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2592 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2593 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2594 | CfgMgr::instance().commit(); |
| 2595 | |
| 2596 | AllocEngine engine(0); |
| 2597 | |
| 2598 | // Query the allocation engine for the lease to be assigned to the client |
| 2599 | // and specify a hint being a different address than the reserved one. |
| 2600 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2601 | IOAddress("192.0.2.234"), false, false, |
| 2602 | "", true); |
| 2603 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2604 | AllocEngine::findReservation(ctx); |
| 2605 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 2606 | |
| 2607 | 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" , 2607, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2608 | // Allocation engine should return reserved address. |
| 2609 | 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" , 2609, gtest_ar.failure_message()) = ::testing::Message(); |
| 2610 | |
| 2611 | // This is a "fake" allocation so the returned lease should not be committed |
| 2612 | // to the lease database. |
| 2613 | 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" , 2613, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 2614 | |
| 2615 | 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" , 2615, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 2616 | } |
| 2617 | |
| 2618 | // This test checks that the behavior of the allocation engine in the following |
| 2619 | // scenario: |
| 2620 | // - Client has a lease for the address from the dynamic pool in the database. |
| 2621 | // - Client has a reservation for a different address than the one for which |
| 2622 | // the client has a lease. |
| 2623 | // - Client sends DHCPREQUEST, asking for the reserved address (as it has been |
| 2624 | // offered to it when it sent DHCPDISCOVER). |
| 2625 | // - Server allocates a reserved address and removes the lease for the address |
| 2626 | // previously allocated to the client. |
| 2627 | TEST_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" , 2627), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2627), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2627), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLease_Test >); void AllocEngine4Test_reservedAddressExistingLease_Test ::TestBody() { |
| 2628 | // Create the reservation for the client. |
| 2629 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2630 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2631 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2632 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2633 | CfgMgr::instance().commit(); |
| 2634 | |
| 2635 | // Create a lease for the client with a different address than the reserved |
| 2636 | // one. |
| 2637 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2638 | &clientid_->getClientId()[0], |
| 2639 | clientid_->getClientId().size(), |
| 2640 | 100, time(0), subnet_->getID(), |
| 2641 | false, false, "")); |
| 2642 | LeaseMgrFactory::instance().addLease(lease); |
| 2643 | |
| 2644 | AllocEngine engine(0); |
| 2645 | |
| 2646 | // Request allocation of the reserved address. |
| 2647 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2648 | IOAddress("192.0.2.123"), false, false, |
| 2649 | "", false); |
| 2650 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2651 | AllocEngine::findReservation(ctx); |
| 2652 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 2653 | |
| 2654 | 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" , 2654, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2655 | // The engine should have allocated the reserved address. |
| 2656 | 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" , 2656, gtest_ar.failure_message()) = ::testing::Message(); |
| 2657 | |
| 2658 | // Make sure that the lease has been committed to the lease database. |
| 2659 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
| 2660 | 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" , 2660, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2661 | detailCompareLease(allocated_lease, from_mgr); |
| 2662 | |
| 2663 | // The previous lease should have been replaced by a new one. The previous |
| 2664 | // lease should be returned by the allocation engine to the caller. |
| 2665 | 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" , 2665, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 2666 | 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" , 2666, gtest_ar.failure_message()) = ::testing::Message(); |
| 2667 | detailCompareLease(ctx.old_lease_, lease); |
| 2668 | } |
| 2669 | |
| 2670 | // This test checks that the behavior of the allocation engine in the following |
| 2671 | // scenario: |
| 2672 | // - Client A has a lease in the database. |
| 2673 | // - Client B has a reservation for the address in use by client A. |
| 2674 | // - Client B sends a DHCPREQUEST requesting the allocation of the reserved |
| 2675 | // lease (in use by client A). |
| 2676 | // - Server determines that the reserved address is in use by a different client |
| 2677 | // and returns DHCPNAK to client B. |
| 2678 | TEST_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" , 2678), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2678), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2678), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijacked_Test >); void AllocEngine4Test_reservedAddressHijacked_Test::TestBody () { |
| 2679 | // Create host reservation for the client B. |
| 2680 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2681 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2682 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2683 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2684 | CfgMgr::instance().commit(); |
| 2685 | |
| 2686 | // Allocate a lease for the client A for the same address as reserved |
| 2687 | // for the client B. |
| 2688 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
| 2689 | 100, time(0), subnet_->getID(), |
| 2690 | false, false, "")); |
| 2691 | LeaseMgrFactory::instance().addLease(lease); |
| 2692 | |
| 2693 | AllocEngine engine(0); |
| 2694 | |
| 2695 | // Try to allocate the reserved lease to client B. |
| 2696 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2697 | IOAddress("192.0.2.123"), false, false, |
| 2698 | "", false); |
| 2699 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2700 | AllocEngine::findReservation(ctx1); |
| 2701 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2702 | // The lease is allocated to someone else, so the allocation should not |
| 2703 | // succeed. |
| 2704 | 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" , 2704, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2705 | 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" , 2705, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2706 | |
| 2707 | 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", 2707, gtest_ar.failure_message()) = ::testing::Message(); |
| 2708 | 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" , 2708, gtest_ar.failure_message()) = ::testing::Message(); |
| 2709 | 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", 2709, gtest_ar.failure_message()) = ::testing::Message(); |
| 2710 | 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", 2710, gtest_ar.failure_message()) = ::testing::Message(); |
| 2711 | 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", 2711, gtest_ar.failure_message()) = ::testing::Message(); |
| 2712 | |
| 2713 | 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" , 2713, gtest_ar.failure_message()) = ::testing::Message(); |
| 2714 | 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" , 2714, gtest_ar.failure_message()) = ::testing::Message(); |
| 2715 | 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" , 2715, gtest_ar.failure_message()) = ::testing::Message(); |
| 2716 | 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" , 2716, gtest_ar.failure_message()) = ::testing::Message(); |
| 2717 | 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" , 2717, gtest_ar.failure_message()) = ::testing::Message(); |
| 2718 | |
| 2719 | // Make sure that the allocation engine didn't modify the lease of the |
| 2720 | // client A. |
| 2721 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2722 | 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" , 2722, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2723 | detailCompareLease(lease, from_mgr); |
| 2724 | |
| 2725 | // Try doing the same thing, but this time do not request any specific |
| 2726 | // address. It should have the same effect. |
| 2727 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2728 | IOAddress("0.0.0.0"), false, false, |
| 2729 | "", false); |
| 2730 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2731 | AllocEngine::findReservation(ctx2); |
| 2732 | allocated_lease = engine.allocateLease4(ctx2); |
| 2733 | 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" , 2733, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2734 | 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" , 2734, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2735 | |
| 2736 | 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", 2736, gtest_ar.failure_message()) = ::testing::Message(); |
| 2737 | 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" , 2737, gtest_ar.failure_message()) = ::testing::Message(); |
| 2738 | 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", 2738, gtest_ar.failure_message()) = ::testing::Message(); |
| 2739 | 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", 2739, gtest_ar.failure_message()) = ::testing::Message(); |
| 2740 | 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", 2740, gtest_ar.failure_message()) = ::testing::Message(); |
| 2741 | |
| 2742 | 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" , 2742, gtest_ar.failure_message()) = ::testing::Message(); |
| 2743 | 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" , 2743, gtest_ar.failure_message()) = ::testing::Message(); |
| 2744 | 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" , 2744, gtest_ar.failure_message()) = ::testing::Message(); |
| 2745 | 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" , 2745, gtest_ar.failure_message()) = ::testing::Message(); |
| 2746 | 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" , 2746, gtest_ar.failure_message()) = ::testing::Message(); |
| 2747 | |
| 2748 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2749 | 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" , 2749, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2750 | detailCompareLease(lease, from_mgr); |
| 2751 | } |
| 2752 | |
| 2753 | // This test checks that the behavior of the allocation engine in the following |
| 2754 | // scenario: |
| 2755 | // - Client A has a lease in the database. |
| 2756 | // - Client B has a reservation for the address in use by client A. |
| 2757 | // - Client B sends a DHCPDISCOVER. |
| 2758 | // - Server determines that the reserved address is in use by a different client |
| 2759 | // so it offers an address from the dynamic pool. |
| 2760 | TEST_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" , 2760), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2760), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2760), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test ::TestBody() { |
| 2761 | // Create a reservation for the client B. |
| 2762 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2763 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2764 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2765 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2766 | CfgMgr::instance().commit(); |
| 2767 | |
| 2768 | // Create a lease for the client A. |
| 2769 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
| 2770 | 100, time(0), subnet_->getID(), |
| 2771 | false, false, "")); |
| 2772 | LeaseMgrFactory::instance().addLease(lease); |
| 2773 | |
| 2774 | AllocEngine engine(0); |
| 2775 | |
| 2776 | // Query allocation engine for the lease to be allocated to the client B. |
| 2777 | // The allocation engine is not able to allocate the lease to the client |
| 2778 | // B, because the address is in use by client A. |
| 2779 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2780 | IOAddress("192.0.2.123"), false, false, |
| 2781 | "", true); |
| 2782 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2783 | AllocEngine::findReservation(ctx1); |
| 2784 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2785 | |
| 2786 | // The allocation engine should return a lease but for a different address |
| 2787 | // than requested because this address is in use. |
| 2788 | 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" , 2788, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2789 | 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" , 2789, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2790 | 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" , 2790, gtest_ar.failure_message()) = ::testing::Message(); |
| 2791 | 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" , 2791, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2792 | |
| 2793 | // Do the same test. But, this time do not specify any address to be |
| 2794 | // allocated. |
| 2795 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2796 | IOAddress("0.0.0.0"), false, false, |
| 2797 | "", true); |
| 2798 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2799 | AllocEngine::findReservation(ctx2); |
| 2800 | allocated_lease = engine.allocateLease4(ctx2); |
| 2801 | |
| 2802 | 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" , 2802, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2803 | 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" , 2803, gtest_ar.failure_message()) = ::testing::Message(); |
| 2804 | 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" , 2804, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2805 | 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" , 2805, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2806 | } |
| 2807 | |
| 2808 | // This test checks that the behavior of the allocation engine in the following |
| 2809 | // scenario: |
| 2810 | // - Client A has an expired lease in the database. |
| 2811 | // - Client B has a reservation for the address in use by client A. |
| 2812 | // - Client B sends a DHCPDISCOVER. |
| 2813 | // - Server determines that the reserved address is in use by a different client |
| 2814 | // but it is expired and tries to reuse it and fails. It can not allocate a |
| 2815 | // new lease either as if there is a limit in place. |
| 2816 | TEST_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" , 2816), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2816), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2816), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test >); void AllocEngine4Test_reservedAddressHijackedFakeAllocationSelectLeaseSkip_Test ::TestBody() { |
| 2817 | // Create a reservation for the client B. |
| 2818 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2819 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2820 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2821 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2822 | CfgMgr::instance().commit(); |
| 2823 | |
| 2824 | // Create a lease for the client A (which is expired). |
| 2825 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
| 2826 | 100, time(0) - 200, subnet_->getID(), |
| 2827 | false, false, "")); |
| 2828 | LeaseMgrFactory::instance().addLease(lease); |
| 2829 | |
| 2830 | AllocEngine engine(0); |
| 2831 | |
| 2832 | // Create callout which sets NEXT_STEP_SKIP flag. |
| 2833 | auto callback = [](CalloutHandle& callout_handle) -> int { |
| 2834 | callout_handle.setStatus(CalloutHandle::NEXT_STEP_SKIP); |
| 2835 | |
| 2836 | return (0); |
| 2837 | }; |
| 2838 | |
| 2839 | // Register the callout for the "lease4_select" hook point. |
| 2840 | HooksManager::preCalloutsLibraryHandle().registerCallout("lease4_select", callback); |
| 2841 | |
| 2842 | // Query allocation engine for the lease to be allocated to the client B. |
| 2843 | // The allocation engine is not able to allocate the lease to the client |
| 2844 | // B, because the address is in use by client A. |
| 2845 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2846 | IOAddress("192.0.2.123"), false, false, |
| 2847 | "", true); |
| 2848 | |
| 2849 | ctx1.callout_handle_ = HooksManager::createCalloutHandle(); |
| 2850 | |
| 2851 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2852 | AllocEngine::findReservation(ctx1); |
| 2853 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2854 | |
| 2855 | // The allocation engine should not return any address as it |
| 2856 | // can neither reuse the lease or allocate a new lease. |
| 2857 | 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" , 2857, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2858 | 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" , 2858, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 2859 | |
| 2860 | // Do the same test. But, this time do not specify any address to be |
| 2861 | // allocated. |
| 2862 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2863 | IOAddress("0.0.0.0"), false, false, |
| 2864 | "", true); |
| 2865 | |
| 2866 | ctx2.callout_handle_ = HooksManager::createCalloutHandle(); |
| 2867 | |
| 2868 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2869 | AllocEngine::findReservation(ctx2); |
| 2870 | allocated_lease = engine.allocateLease4(ctx2); |
| 2871 | |
| 2872 | 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" , 2872, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2873 | 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" , 2873, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 2874 | } |
| 2875 | |
| 2876 | // This test checks that the behavior of the allocation engine in the following |
| 2877 | // scenario: |
| 2878 | // - Client has a reservation. |
| 2879 | // - Client has a lease in the database for a different address than reserved. |
| 2880 | // - Client sends a DHCPREQUEST and asks for a different address than reserved, |
| 2881 | // and different than it has in a database. |
| 2882 | // - Server doesn't allocate the reserved address to the client because the |
| 2883 | // client asked for the different address. |
| 2884 | // |
| 2885 | // Note that in this case the client should get the DHCPNAK and should fall back |
| 2886 | // to the DHCPDISCOVER. |
| 2887 | TEST_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" , 2887), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2887), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2887), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test ::TestBody() { |
| 2888 | // Create a reservation for the client. |
| 2889 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2890 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2891 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2892 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2893 | CfgMgr::instance().commit(); |
| 2894 | |
| 2895 | // Create a lease for the client for a different address than reserved. |
| 2896 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, ClientIdPtr(), |
| 2897 | 100, time(0), subnet_->getID(), |
| 2898 | false, false, "")); |
| 2899 | LeaseMgrFactory::instance().addLease(lease); |
| 2900 | |
| 2901 | AllocEngine engine(0); |
| 2902 | |
| 2903 | // Try to allocate a lease and specify a different address than reserved |
| 2904 | // and different from the one that client is currently using. |
| 2905 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2906 | IOAddress("192.0.2.102"), false, false, |
| 2907 | "", false); |
| 2908 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2909 | AllocEngine::findReservation(ctx1); |
| 2910 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2911 | 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" , 2911, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2912 | 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" , 2912, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2913 | |
| 2914 | 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", 2914, gtest_ar.failure_message()) = ::testing::Message(); |
| 2915 | 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" , 2915, gtest_ar.failure_message()) = ::testing::Message(); |
| 2916 | 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", 2916, gtest_ar.failure_message()) = ::testing::Message(); |
| 2917 | 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", 2917, gtest_ar.failure_message()) = ::testing::Message(); |
| 2918 | 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", 2918, gtest_ar.failure_message()) = ::testing::Message(); |
| 2919 | |
| 2920 | 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" , 2920, gtest_ar.failure_message()) = ::testing::Message(); |
| 2921 | 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" , 2921, gtest_ar.failure_message()) = ::testing::Message(); |
| 2922 | 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" , 2922, gtest_ar.failure_message()) = ::testing::Message(); |
| 2923 | 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" , 2923, gtest_ar.failure_message()) = ::testing::Message(); |
| 2924 | 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" , 2924, gtest_ar.failure_message()) = ::testing::Message(); |
| 2925 | |
| 2926 | // Repeat the test, but this time ask for the address that the client |
| 2927 | // has allocated. |
| 2928 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2929 | IOAddress("192.0.2.101"), false, false, |
| 2930 | "", false); |
| 2931 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2932 | AllocEngine::findReservation(ctx2); |
| 2933 | allocated_lease = engine.allocateLease4(ctx2); |
| 2934 | // The client has reservation so the server wants to allocate a |
| 2935 | // reserved address and doesn't want to renew the address that the |
| 2936 | // client is currently using. This is equivalent of the case when |
| 2937 | // the client tries to renew the lease but there is a new reservation |
| 2938 | // for this client. The server doesn't allow for the renewal and |
| 2939 | // responds with DHCPNAK to force the client to return to the |
| 2940 | // DHCP server discovery. |
| 2941 | 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" , 2941, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2942 | 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" , 2942, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2943 | |
| 2944 | 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", 2944, gtest_ar.failure_message()) = ::testing::Message(); |
| 2945 | 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" , 2945, gtest_ar.failure_message()) = ::testing::Message(); |
| 2946 | 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", 2946, gtest_ar.failure_message()) = ::testing::Message(); |
| 2947 | 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", 2947, gtest_ar.failure_message()) = ::testing::Message(); |
| 2948 | 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", 2948, gtest_ar.failure_message()) = ::testing::Message(); |
| 2949 | |
| 2950 | 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" , 2950, gtest_ar.failure_message()) = ::testing::Message(); |
| 2951 | 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" , 2951, gtest_ar.failure_message()) = ::testing::Message(); |
| 2952 | 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" , 2952, gtest_ar.failure_message()) = ::testing::Message(); |
| 2953 | 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" , 2953, gtest_ar.failure_message()) = ::testing::Message(); |
| 2954 | 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" , 2954, gtest_ar.failure_message()) = ::testing::Message(); |
| 2955 | } |
| 2956 | |
| 2957 | // This test checks that the behavior of the allocation engine in the following |
| 2958 | // scenario: |
| 2959 | // - Client has a lease in the database. |
| 2960 | // - Client has a reservation for a different address than the one for which it |
| 2961 | // has a lease. |
| 2962 | // - Client sends a DHCPDISCOVER and asks for a different address than reserved |
| 2963 | // and different from which it has a lease for. |
| 2964 | // - Server ignores the client's hint and offers a reserved address. |
| 2965 | TEST_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" , 2965), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2965), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2965), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test ::TestBody() { |
| 2966 | // Create a reservation for the client. |
| 2967 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2968 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2969 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2970 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2971 | CfgMgr::instance().commit(); |
| 2972 | |
| 2973 | // Create a lease for a different address than reserved. |
| 2974 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2975 | &clientid_->getClientId()[0], |
| 2976 | clientid_->getClientId().size(), |
| 2977 | 100, time(0), subnet_->getID(), |
| 2978 | false, false, "")); |
| 2979 | LeaseMgrFactory::instance().addLease(lease); |
| 2980 | |
| 2981 | AllocEngine engine(0); |
| 2982 | |
| 2983 | // Try to allocate a lease and use a completely different address |
| 2984 | // as a hint. |
| 2985 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2986 | IOAddress("192.0.2.102"), false, false, |
| 2987 | "", true); |
| 2988 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 2989 | AllocEngine::findReservation(ctx1); |
| 2990 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2991 | |
| 2992 | // Server should offer a lease for a reserved address. |
| 2993 | 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" , 2993, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2994 | 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" , 2994, gtest_ar.failure_message()) = ::testing::Message(); |
| 2995 | |
| 2996 | // The lease should not be allocated until the client sends a DHCPREQUEST. |
| 2997 | 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", 2997, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false") .c_str()) = ::testing::Message(); |
| 2998 | |
| 2999 | // Old lease should contain the currently used lease. |
| 3000 | 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" , 3000, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 3001 | 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" , 3001, gtest_ar.failure_message()) = ::testing::Message(); |
| 3002 | |
| 3003 | // Repeat the test but this time ask for the address for which the |
| 3004 | // client has a lease. |
| 3005 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 3006 | IOAddress("192.0.2.101"), false, false, |
| 3007 | "", true); |
| 3008 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3009 | AllocEngine::findReservation(ctx2); |
| 3010 | allocated_lease = engine.allocateLease4(ctx2); |
| 3011 | |
| 3012 | // The server should offer the lease, but not for the address that |
| 3013 | // the client requested. The server should offer a reserved address. |
| 3014 | 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" , 3014, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3015 | 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" , 3015, gtest_ar.failure_message()) = ::testing::Message(); |
| 3016 | |
| 3017 | // Old lease should contain the currently used lease. |
| 3018 | 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" , 3018, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 3019 | 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" , 3019, gtest_ar.failure_message()) = ::testing::Message(); |
| 3020 | } |
| 3021 | |
| 3022 | // This test checks that the behavior of the allocation engine in the following |
| 3023 | // scenario: |
| 3024 | // - Client has a reservation. |
| 3025 | // - Client has a lease for a different address than reserved. |
| 3026 | // - Client sends a DHCPREQUEST to allocate a lease. |
| 3027 | // - The server determines that the client has a reservation for the |
| 3028 | // different address than it is currently using and should assign |
| 3029 | // a reserved address and remove the previous lease. |
| 3030 | TEST_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" , 3030), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3030), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3030), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test ::TestBody() { |
| 3031 | // Create a reservation. |
| 3032 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3033 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3034 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 3035 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3036 | CfgMgr::instance().commit(); |
| 3037 | |
| 3038 | // Create a lease for a different address than reserved. |
| 3039 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 3040 | &clientid_->getClientId()[0], |
| 3041 | clientid_->getClientId().size(), |
| 3042 | 100, time(0), subnet_->getID(), |
| 3043 | false, false, "")); |
| 3044 | LeaseMgrFactory::instance().addLease(lease); |
| 3045 | |
| 3046 | AllocEngine engine(0); |
| 3047 | |
| 3048 | // Try to allocate a lease with providing no hint. |
| 3049 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3050 | IOAddress("0.0.0.0"), false, false, |
| 3051 | "", false); |
| 3052 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3053 | AllocEngine::findReservation(ctx); |
| 3054 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 3055 | |
| 3056 | // The reserved address should be allocated. |
| 3057 | 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" , 3057, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3058 | 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" , 3058, gtest_ar.failure_message()) = ::testing::Message(); |
| 3059 | |
| 3060 | // The previous lease should be removed. |
| 3061 | 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" , 3061, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3062 | |
| 3063 | // Make sure that the allocated lease is committed in the lease database. |
| 3064 | Lease4Ptr from_mgr = |
| 3065 | LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
| 3066 | 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" , 3066, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3067 | detailCompareLease(allocated_lease, from_mgr); |
| 3068 | |
| 3069 | // Old lease should be returned. |
| 3070 | 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" , 3070, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 3071 | detailCompareLease(lease, ctx.old_lease_); |
| 3072 | } |
| 3073 | |
| 3074 | // This test checks that the behavior of the allocation engine in the following |
| 3075 | // scenario: |
| 3076 | // - Client has a reservation. |
| 3077 | // - Client has a lease for a different address than reserved. |
| 3078 | // - Client sends a DHCPDISCOVER with no hint. |
| 3079 | // - Server determines that there is a reservation for the client and that |
| 3080 | // the reserved address should be offered when the client sends a |
| 3081 | // DHCPDISCOVER. |
| 3082 | TEST_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" , 3082), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3082), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3082), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test ::TestBody() { |
| 3083 | // Create a reservation. |
| 3084 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3085 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3086 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 3087 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3088 | CfgMgr::instance().commit(); |
| 3089 | |
| 3090 | // Create a lease for a different address than reserved. |
| 3091 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 3092 | &clientid_->getClientId()[0], |
| 3093 | clientid_->getClientId().size(), |
| 3094 | 100, time(0), subnet_->getID(), |
| 3095 | false, false, "")); |
| 3096 | LeaseMgrFactory::instance().addLease(lease); |
| 3097 | |
| 3098 | AllocEngine engine(0); |
| 3099 | |
| 3100 | // Query the allocation engine for the lease to be allocated for the |
| 3101 | // client. |
| 3102 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3103 | IOAddress("0.0.0.0"), false, false, |
| 3104 | "", true); |
| 3105 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3106 | AllocEngine::findReservation(ctx); |
| 3107 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 3108 | |
| 3109 | // The server should offer the reserved address. |
| 3110 | 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" , 3110, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3111 | 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" , 3111, gtest_ar.failure_message()) = ::testing::Message(); |
| 3112 | |
| 3113 | // The lease should not be committed to the lease database until the |
| 3114 | // client sends a DHCPREQUEST. |
| 3115 | 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", 3115, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false") .c_str()) = ::testing::Message(); |
| 3116 | |
| 3117 | // The old lease should reflect what is in the database. |
| 3118 | 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" , 3118, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 3119 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3120 | 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" , 3120, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3121 | detailCompareLease(lease, from_mgr); |
| 3122 | } |
| 3123 | |
| 3124 | // This test checks that the behavior of the allocation engine in the following |
| 3125 | // scenario: |
| 3126 | // - Client A has a lease for the address. |
| 3127 | // - Client B has a reservation for the same address that the Client A is using. |
| 3128 | // - Client B requests allocation of the reserved address. |
| 3129 | // - Server returns DHCPNAK to the client to indicate that the requested address |
| 3130 | // can't be allocated. |
| 3131 | // - Client A renews the lease. |
| 3132 | // - Server determines that the lease that the Client A is trying to renew |
| 3133 | // is for the address reserved for Client B. Therefore, the server returns |
| 3134 | // DHCPNAK to force the client to return to the server discovery. |
| 3135 | // - The Client A sends DHCPDISCOVER. |
| 3136 | // - The server offers an address to the Client A, which is different than |
| 3137 | // the address reserved for Client B. |
| 3138 | // - The Client A requests allocation of the offered address. |
| 3139 | // - The server allocates the new address to Client A. |
| 3140 | // - The Client B sends DHCPDISCOVER to the server. |
| 3141 | // - The server offers a reserved address to the Client B. |
| 3142 | // - The Client B requests the offered address. |
| 3143 | // - The server allocates the reserved address to the Client B. |
| 3144 | TEST_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" , 3144), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3144), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3144), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressConflictResolution_Test >); void AllocEngine4Test_reservedAddressConflictResolution_Test ::TestBody() { |
| 3145 | // Create a reservation for client B. |
| 3146 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
| 3147 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3148 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
| 3149 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3150 | CfgMgr::instance().commit(); |
| 3151 | |
| 3152 | // Create a lease for Client A. |
| 3153 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 3154 | &clientid_->getClientId()[0], |
| 3155 | clientid_->getClientId().size(), |
| 3156 | 100, time(0), subnet_->getID(), |
| 3157 | false, false, "")); |
| 3158 | LeaseMgrFactory::instance().addLease(lease); |
| 3159 | |
| 3160 | AllocEngine engine(0); |
| 3161 | |
| 3162 | // Client B sends a DHCPREQUEST to allocate a reserved lease. The |
| 3163 | // allocation engine can't allocate a reserved lease for this client |
| 3164 | // because this specific address is in use by the Client A. |
| 3165 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr2_, |
| 3166 | IOAddress("192.0.2.101"), false, false, |
| 3167 | "", false); |
| 3168 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3169 | AllocEngine::findReservation(ctx1); |
| 3170 | Lease4Ptr offered_lease = engine.allocateLease4(ctx1); |
| 3171 | 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" , 3171, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "offered_lease", "true", "false") .c_str()) = ::testing::Message (); |
| 3172 | |
| 3173 | 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", 3173, gtest_ar.failure_message()) = ::testing::Message(); |
| 3174 | 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" , 3174, gtest_ar.failure_message()) = ::testing::Message(); |
| 3175 | 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", 3175, gtest_ar.failure_message()) = ::testing::Message(); |
| 3176 | 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", 3176, gtest_ar.failure_message()) = ::testing::Message(); |
| 3177 | 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", 3177, gtest_ar.failure_message()) = ::testing::Message(); |
| 3178 | |
| 3179 | 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" , 3179, gtest_ar.failure_message()) = ::testing::Message(); |
| 3180 | 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" , 3180, gtest_ar.failure_message()) = ::testing::Message(); |
| 3181 | 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" , 3181, gtest_ar.failure_message()) = ::testing::Message(); |
| 3182 | 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" , 3182, gtest_ar.failure_message()) = ::testing::Message(); |
| 3183 | 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" , 3183, gtest_ar.failure_message()) = ::testing::Message(); |
| 3184 | |
| 3185 | // Client A tries to renew the lease. The renewal should fail because |
| 3186 | // server detects that Client A doesn't have reservation for this |
| 3187 | // address. |
| 3188 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 3189 | IOAddress("192.0.2.101"), false, false, |
| 3190 | "", false); |
| 3191 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3192 | AllocEngine::findReservation(ctx2); |
| 3193 | 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" , 3193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine.allocateLease4(ctx2)", "true", "false") .c_str()) = ::testing::Message(); |
| 3194 | 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" , 3194, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 3195 | |
| 3196 | 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", 3196, gtest_ar.failure_message()) = ::testing::Message(); |
| 3197 | 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" , 3197, gtest_ar.failure_message()) = ::testing::Message(); |
| 3198 | 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", 3198, gtest_ar.failure_message()) = ::testing::Message(); |
| 3199 | 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", 3199, gtest_ar.failure_message()) = ::testing::Message(); |
| 3200 | 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", 3200, gtest_ar.failure_message()) = ::testing::Message(); |
| 3201 | |
| 3202 | 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" , 3202, gtest_ar.failure_message()) = ::testing::Message(); |
| 3203 | 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" , 3203, gtest_ar.failure_message()) = ::testing::Message(); |
| 3204 | 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" , 3204, gtest_ar.failure_message()) = ::testing::Message(); |
| 3205 | 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" , 3205, gtest_ar.failure_message()) = ::testing::Message(); |
| 3206 | 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" , 3206, gtest_ar.failure_message()) = ::testing::Message(); |
| 3207 | |
| 3208 | // Client A returns to DHCPDISCOVER and should be offered a lease. |
| 3209 | // The offered lease address must be different than the one the |
| 3210 | // Client B has reservation for. |
| 3211 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
| 3212 | IOAddress("192.0.2.101"), false, false, |
| 3213 | "", true); |
| 3214 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3215 | AllocEngine::findReservation(ctx3); |
| 3216 | offered_lease = engine.allocateLease4(ctx3); |
| 3217 | 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" , 3217, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "offered_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 3218 | 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" , 3218, gtest_ar.failure_message()) = ::testing::Message(); |
| 3219 | |
| 3220 | // Client A tries to acquire the lease. It should succeed. At this point |
| 3221 | // the previous lease should be released and become available for the |
| 3222 | // Client B. |
| 3223 | AllocEngine::ClientContext4 ctx4(subnet_, clientid_, hwaddr_, |
| 3224 | offered_lease->addr_, false, false, |
| 3225 | "", false); |
| 3226 | ctx4.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3227 | AllocEngine::findReservation(ctx4); |
| 3228 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx4); |
| 3229 | |
| 3230 | 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" , 3230, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3231 | 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" , 3231, gtest_ar.failure_message()) = ::testing::Message(); |
| 3232 | |
| 3233 | // Client B tries to get the lease again. It should be offered |
| 3234 | // a reserved lease. |
| 3235 | AllocEngine::ClientContext4 ctx5(subnet_, ClientIdPtr(), hwaddr2_, |
| 3236 | IOAddress("0.0.0.0"), false, false, |
| 3237 | "", true); |
| 3238 | ctx5.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3239 | AllocEngine::findReservation(ctx5); |
| 3240 | offered_lease = engine.allocateLease4(ctx5); |
| 3241 | |
| 3242 | 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" , 3242, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "offered_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 3243 | 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" , 3243, gtest_ar.failure_message()) = ::testing::Message(); |
| 3244 | |
| 3245 | // Client B requests allocation of the lease and it should succeed. |
| 3246 | AllocEngine::ClientContext4 ctx6(subnet_, ClientIdPtr(), hwaddr2_, |
| 3247 | offered_lease->addr_, false, false, |
| 3248 | "", false); |
| 3249 | ctx6.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3250 | allocated_lease = engine.allocateLease4(ctx6); |
| 3251 | |
| 3252 | 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" , 3252, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3253 | 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" , 3253, gtest_ar.failure_message()) = ::testing::Message(); |
| 3254 | } |
| 3255 | |
| 3256 | // This test checks that the address is not assigned from the dynamic |
| 3257 | // pool if it has been reserved for another client. |
| 3258 | TEST_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" , 3258), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3258), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3258), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressVsDynamicPool_Test >); void AllocEngine4Test_reservedAddressVsDynamicPool_Test ::TestBody() { |
| 3259 | // Create a reservation for the client. |
| 3260 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3261 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3262 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3263 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3264 | CfgMgr::instance().commit(); |
| 3265 | |
| 3266 | AllocEngine engine(0); |
| 3267 | |
| 3268 | // Different client tries to allocate a lease. Note, that we're using |
| 3269 | // an iterative allocator which would pick the first address from the |
| 3270 | // dynamic pool, i.e. 192.0.2.100. This address is reserved so we expect |
| 3271 | // that a different address will be allocated. |
| 3272 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 3273 | IOAddress("0.0.0.0"), false, false, |
| 3274 | "", false); |
| 3275 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3276 | AllocEngine::findReservation(ctx); |
| 3277 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 3278 | |
| 3279 | 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" , 3279, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3280 | 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" , 3280, gtest_ar.failure_message()) = ::testing::Message(); |
| 3281 | |
| 3282 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
| 3283 | 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" , 3283, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3284 | detailCompareLease(allocated_lease, from_mgr); |
| 3285 | } |
| 3286 | |
| 3287 | // This test checks that the client requesting an address which is |
| 3288 | // reserved for another client will get no lease or a different |
| 3289 | // address will be assigned if the client is sending a DHCPDISCOVER. |
| 3290 | TEST_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" , 3290), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3290), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3290), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test >); void AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test ::TestBody() { |
| 3291 | // Create a reservation for the client. |
| 3292 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3293 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3294 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3295 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3296 | CfgMgr::instance().commit(); |
| 3297 | |
| 3298 | AllocEngine engine(0); |
| 3299 | |
| 3300 | // Different client is requesting this address. |
| 3301 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
| 3302 | IOAddress("192.0.2.100"), false, false, |
| 3303 | "", false); |
| 3304 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3305 | AllocEngine::findReservation(ctx1); |
| 3306 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 3307 | |
| 3308 | // The client should get no lease (DHCPNAK). |
| 3309 | 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" , 3309, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 3310 | |
| 3311 | 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", 3311, gtest_ar.failure_message()) = ::testing::Message(); |
| 3312 | 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" , 3312, gtest_ar.failure_message()) = ::testing::Message(); |
| 3313 | 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", 3313, gtest_ar.failure_message()) = ::testing::Message(); |
| 3314 | 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", 3314, gtest_ar.failure_message()) = ::testing::Message(); |
| 3315 | 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", 3315, gtest_ar.failure_message()) = ::testing::Message(); |
| 3316 | |
| 3317 | 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" , 3317, gtest_ar.failure_message()) = ::testing::Message(); |
| 3318 | 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" , 3318, gtest_ar.failure_message()) = ::testing::Message(); |
| 3319 | 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" , 3319, gtest_ar.failure_message()) = ::testing::Message(); |
| 3320 | 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" , 3320, gtest_ar.failure_message()) = ::testing::Message(); |
| 3321 | 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" , 3321, gtest_ar.failure_message()) = ::testing::Message(); |
| 3322 | |
| 3323 | // The same client should get a different lease than requested if |
| 3324 | // if is sending a DHCPDISCOVER (fake allocation is true). |
| 3325 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
| 3326 | IOAddress("192.0.2.100"), false, false, |
| 3327 | "", true); |
| 3328 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3329 | AllocEngine::findReservation(ctx2); |
| 3330 | allocated_lease = engine.allocateLease4(ctx2); |
| 3331 | |
| 3332 | 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" , 3332, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3333 | // Make sure the lease obtained is for a different address. |
| 3334 | 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" , 3334, gtest_ar.failure_message()) = ::testing::Message(); |
| 3335 | } |
| 3336 | |
| 3337 | // This test checks that the allocation engine refuses to allocate an |
| 3338 | // address when the pool is exhausted, and the only available |
| 3339 | // address is reserved for a different client. |
| 3340 | TEST_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" , 3340), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3340), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3340), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressShortPool_Test >); void AllocEngine4Test_reservedAddressShortPool_Test::TestBody () { |
| 3341 | AllocEngine engine(0); |
| 3342 | |
| 3343 | // Create short pool with only one address. |
| 3344 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
| 3345 | // Reserve the address for a different client. |
| 3346 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
| 3347 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3348 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3349 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3350 | CfgMgr::instance().commit(); |
| 3351 | |
| 3352 | // Allocation engine should determine that the available address is |
| 3353 | // reserved for someone else and not allocate it. |
| 3354 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
| 3355 | IOAddress("0.0.0.0"), false, false, |
| 3356 | "", false); |
| 3357 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3358 | AllocEngine::findReservation(ctx1); |
| 3359 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 3360 | |
| 3361 | 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" , 3361, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 3362 | |
| 3363 | 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", 3363, gtest_ar.failure_message()) = ::testing::Message(); |
| 3364 | 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" , 3364, gtest_ar.failure_message()) = ::testing::Message(); |
| 3365 | 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", 3365, gtest_ar.failure_message()) = ::testing::Message(); |
| 3366 | 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", 3366, gtest_ar.failure_message()) = ::testing::Message(); |
| 3367 | 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", 3367, gtest_ar.failure_message()) = ::testing::Message(); |
| 3368 | |
| 3369 | 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" , 3369, gtest_ar.failure_message()) = ::testing::Message(); |
| 3370 | 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" , 3370, gtest_ar.failure_message()) = ::testing::Message(); |
| 3371 | 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" , 3371, gtest_ar.failure_message()) = ::testing::Message(); |
| 3372 | 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" , 3372, gtest_ar.failure_message()) = ::testing::Message(); |
| 3373 | 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" , 3373, gtest_ar.failure_message()) = ::testing::Message(); |
| 3374 | |
| 3375 | // Now, let's remove the reservation. |
| 3376 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
| 3377 | CfgMgr::instance().commit(); |
| 3378 | |
| 3379 | // Address should be successfully allocated. |
| 3380 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
| 3381 | IOAddress("0.0.0.0"), false, false, |
| 3382 | "", false); |
| 3383 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3384 | AllocEngine::findReservation(ctx2); |
| 3385 | allocated_lease = engine.allocateLease4(ctx2); |
| 3386 | |
| 3387 | 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" , 3387, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3388 | 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" , 3388, gtest_ar.failure_message()) = ::testing::Message(); |
| 3389 | } |
| 3390 | |
| 3391 | // This test checks that the AllocEngine allocates an address from the |
| 3392 | // dynamic pool if the client's reservation is made for a hostname but |
| 3393 | // not for an address. |
| 3394 | TEST_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" , 3394), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3394), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3394), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedHostname_Test >); void AllocEngine4Test_reservedHostname_Test::TestBody( ) { |
| 3395 | AllocEngine engine(0); |
| 3396 | |
| 3397 | // Create a reservation for a hostname. Address is set to 0 which |
| 3398 | // indicates that there is no reservation. |
| 3399 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3400 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3401 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
| 3402 | "foo.example.org")); |
| 3403 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3404 | CfgMgr::instance().commit(); |
| 3405 | |
| 3406 | // Try to allocate a lease. |
| 3407 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 3408 | IOAddress("192.0.2.109"), false, false, |
| 3409 | "foo.example.org", true); |
| 3410 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3411 | AllocEngine::findReservation(ctx); |
| 3412 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 3413 | 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" , 3413, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3414 | 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" , 3414, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease->addr_.isV4Zero()", "true", "false") .c_str ()) = ::testing::Message(); |
| 3415 | 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" , 3415, gtest_ar.failure_message()) = ::testing::Message(); |
| 3416 | |
| 3417 | ctx.requested_address_ = allocated_lease->addr_; |
| 3418 | ctx.fake_allocation_ = false; |
| 3419 | allocated_lease = engine.allocateLease4(ctx); |
| 3420 | 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" , 3420, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3421 | 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" , 3421, gtest_ar.failure_message()) = ::testing::Message(); |
| 3422 | } |
| 3423 | |
| 3424 | // This test checks that the AllocEngine::findReservation method finds |
| 3425 | // and returns host reservation for the DHCPv4 client using the data from |
| 3426 | // the client context. If the host reservation can't be found, it sets |
| 3427 | // the value of null in the host_ field of the client context. |
| 3428 | TEST_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", 3428 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3428), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3428), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_findReservation_Test >); void AllocEngine4Test_findReservation_Test::TestBody() { |
| 3429 | // Create the instance of the allocation engine. |
| 3430 | AllocEngine engine(0); |
| 3431 | |
| 3432 | // Context is required to call the AllocEngine::findReservation. |
| 3433 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3434 | IOAddress("0.0.0.0"), false, false, |
| 3435 | "", false); |
| 3436 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3437 | |
| 3438 | // Adding an empty identifier should throw. |
| 3439 | EXPECT_THROW(ctx.addHostIdentifier(Host::IDENT_HWADDR, {}), BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { ctx.addHostIdentifier(Host ::IDENT_HWADDR, {}); } else static_assert(true, ""); } catch ( BadValue const&) { gtest_caught_expected = true; } catch ( typename std::conditional< std::is_same<typename std::remove_cv <typename std::remove_reference< BadValue>::type> ::type, std::exception>::value, const ::testing::internal:: NeverThrown&, const std::exception&>::type e) { gtest_msg .value = "Expected: " "ctx.addHostIdentifier(Host::IDENT_HWADDR, {})" " throws an exception of type " "BadValue" ".\n Actual: 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_testthrow_3439 ; } catch (...) { gtest_msg.value = "Expected: " "ctx.addHostIdentifier(Host::IDENT_HWADDR, {})" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_3439; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "ctx.addHostIdentifier(Host::IDENT_HWADDR, {})" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_3439; } } else gtest_label_testthrow_3439 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3439, gtest_msg.value.c_str()) = ::testing::Message(); |
| 3440 | |
| 3441 | ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_); |
| 3442 | ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getClientId()); |
| 3443 | |
| 3444 | // There is no reservation in the database so no host should be returned. |
| 3445 | 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_3445 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3445 ; } } else gtest_label_testnothrow_3445 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3445, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3446 | 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" , 3446, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3447 | |
| 3448 | // Create a reservation for the client. |
| 3449 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3450 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3451 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3452 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3453 | CfgMgr::instance().commit(); |
| 3454 | |
| 3455 | // This time the reservation should be returned. |
| 3456 | ctx.hosts_.clear(); |
| 3457 | 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_3457 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3457 ; } } else gtest_label_testnothrow_3457 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3457, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3458 | 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" , 3458, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3459 | 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" , 3459, gtest_ar.failure_message()) = ::testing::Message(); |
| 3460 | |
| 3461 | // It shouldn't be returned when reservations-in-subnet is disabled. |
| 3462 | subnet_->setReservationsInSubnet(false); |
| 3463 | ctx.hosts_.clear(); |
| 3464 | 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_3464 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3464 ; } } else gtest_label_testnothrow_3464 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3464, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3465 | 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" , 3465, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3466 | |
| 3467 | // Check the reservations-in-subnet and reservations-out-of-pool flags. |
| 3468 | subnet_->setReservationsInSubnet(true); |
| 3469 | subnet_->setReservationsOutOfPool(true); |
| 3470 | ctx.hosts_.clear(); |
| 3471 | 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_3471 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3471 ; } } else gtest_label_testnothrow_3471 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3471, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3472 | 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" , 3472, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3473 | 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" , 3473, gtest_ar.failure_message()) = ::testing::Message(); |
| 3474 | |
| 3475 | // This time use the client identifier to search for the host. |
| 3476 | host.reset(new Host(&clientid_->getClientId()[0], |
| 3477 | clientid_->getClientId().size(), |
| 3478 | Host::IDENT_DUID, subnet_->getID(), |
| 3479 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
| 3480 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3481 | CfgMgr::instance().commit(); |
| 3482 | |
| 3483 | ctx.hosts_.clear(); |
| 3484 | 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_3484 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3484 ; } } else gtest_label_testnothrow_3484 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3484, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3485 | 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" , 3485, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3486 | 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" , 3486, gtest_ar.failure_message()) = ::testing::Message(); |
| 3487 | |
| 3488 | // Remove the subnet. Subnet id is required to find host reservations, so |
| 3489 | // if it is set to null, no reservation should be returned |
| 3490 | ctx.subnet_.reset(); |
| 3491 | ctx.hosts_.clear(); |
| 3492 | 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_3492 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3492 ; } } else gtest_label_testnothrow_3492 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3492, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3493 | 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" , 3493, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3494 | |
| 3495 | // The same if there is a mismatch of the subnet id between the reservation |
| 3496 | // and the context. |
| 3497 | ctx.subnet_ = subnet_; |
| 3498 | host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3499 | Host::IDENT_HWADDR, subnet_->getID() + 1, |
| 3500 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3501 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3502 | CfgMgr::instance().commit(); |
| 3503 | |
| 3504 | ctx.hosts_.clear(); |
| 3505 | 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_3505 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3505 ; } } else gtest_label_testnothrow_3505 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3505, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3506 | 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" , 3506, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3507 | } |
| 3508 | |
| 3509 | // This test checks if the simple IPv4 allocation can succeed and that |
| 3510 | // statistic for allocated addresses is increased appropriately. |
| 3511 | TEST_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" , 3511), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3511), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3511), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4Stats_Test >); void AllocEngine4Test_simpleAlloc4Stats_Test::TestBody () { |
| 3512 | boost::scoped_ptr<AllocEngine> engine; |
| 3513 | 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_3513 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3513 ; } } else gtest_label_testnothrow_3513 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3513, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3514 | 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" , 3514, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 3515 | |
| 3516 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 3517 | false, true, "somehost.example.com.", false); |
| 3518 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3519 | |
| 3520 | // Let's pretend 100 addresses were allocated already |
| 3521 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
| 3522 | "assigned-addresses"); |
| 3523 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
| 3524 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 3525 | subnet_->getID()); |
| 3526 | |
| 3527 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 3528 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 3529 | |
| 3530 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 3531 | // The new lease has been allocated, so the old lease should not exist. |
| 3532 | 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" , 3532, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3533 | |
| 3534 | // Check that we got a lease |
| 3535 | 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" , 3535, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3536 | |
| 3537 | // The statistic should be there and it should be increased by 1 (to 101). |
| 3538 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
| 3539 | 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", 3539, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "stat", "false", "true") .c_str()) = ::testing::Message(); |
| 3540 | 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" , 3540, gtest_ar.failure_message()) = ::testing::Message(); |
| 3541 | cumulative += 1; |
| 3542 | 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" , 3543, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 3543 | 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" , 3543, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 3544 | glbl_assigned += 1; |
| 3545 | 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" , 3545, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 3546 | glbl_cumulative += 1; |
| 3547 | 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" , 3547, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 3548 | } |
| 3549 | |
| 3550 | // This test checks if the fake allocation (for DHCPDISCOVER) can succeed |
| 3551 | // and that it doesn't increase allocated-addresses statistic. |
| 3552 | TEST_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", 3552 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3552), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3552), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4Stat_Test >); void AllocEngine4Test_fakeAlloc4Stat_Test::TestBody() { |
| 3553 | boost::scoped_ptr<AllocEngine> engine; |
| 3554 | 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_3554 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3554 ; } } else gtest_label_testnothrow_3554 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3554, ("Expected: " "engine.reset(new AllocEngine(100))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3555 | 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" , 3555, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 3556 | |
| 3557 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3558 | IOAddress("0.0.0.0"), false, true, |
| 3559 | "host.example.com.", true); |
| 3560 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3561 | |
| 3562 | // Let's pretend 100 addresses were allocated already |
| 3563 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
| 3564 | "assigned-addresses"); |
| 3565 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
| 3566 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 3567 | subnet_->getID()); |
| 3568 | |
| 3569 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 3570 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 3571 | |
| 3572 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 3573 | |
| 3574 | // The new lease has been allocated, so the old lease should not exist. |
| 3575 | 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" , 3575, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3576 | |
| 3577 | // Check that we got a lease |
| 3578 | 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" , 3578, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3579 | |
| 3580 | // The statistic should be there and it should not be increased |
| 3581 | // (should be still equal to 100). |
| 3582 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
| 3583 | 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", 3583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "stat", "false", "true") .c_str()) = ::testing::Message(); |
| 3584 | 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" , 3584, gtest_ar.failure_message()) = ::testing::Message(); |
| 3585 | 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" , 3586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 3586 | 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" , 3586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 3587 | 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" , 3587, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 3588 | 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" , 3588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 3589 | } |
| 3590 | |
| 3591 | // This test checks that the allocated-addresses statistic is decreased when |
| 3592 | // the client has a lease and a reservation for a different address is |
| 3593 | // available. |
| 3594 | TEST_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" , 3594), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3594), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3594), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseStat_Test >); void AllocEngine4Test_reservedAddressExistingLeaseStat_Test ::TestBody() { |
| 3595 | // Create the reservation for the client. |
| 3596 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3597 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3598 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 3599 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3600 | CfgMgr::instance().commit(); |
| 3601 | |
| 3602 | // Create a lease for the client with a different address than the reserved |
| 3603 | // one. |
| 3604 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 3605 | &clientid_->getClientId()[0], |
| 3606 | clientid_->getClientId().size(), |
| 3607 | 100, time(0), subnet_->getID(), |
| 3608 | false, false, "")); |
| 3609 | LeaseMgrFactory::instance().addLease(lease); |
| 3610 | |
| 3611 | AllocEngine engine(100); |
| 3612 | |
| 3613 | // Let's pretend 100 addresses were allocated already |
| 3614 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
| 3615 | "assigned-addresses"); |
| 3616 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
| 3617 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 3618 | subnet_->getID()); |
| 3619 | |
| 3620 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 3621 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 3622 | |
| 3623 | // Request allocation of the reserved address. |
| 3624 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3625 | IOAddress("192.0.2.123"), false, false, |
| 3626 | "", false); |
| 3627 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3628 | AllocEngine::findReservation(ctx); |
| 3629 | |
| 3630 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 3631 | |
| 3632 | 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" , 3632, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3633 | |
| 3634 | // The statistic should be still at 100. Note that it was decreased |
| 3635 | // (because old lease was removed), but also increased (because the |
| 3636 | // new lease was immediately allocated). |
| 3637 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
| 3638 | 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", 3638, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "stat", "false", "true") .c_str()) = ::testing::Message(); |
| 3639 | 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" , 3639, gtest_ar.failure_message()) = ::testing::Message(); |
| 3640 | cumulative += 1; |
| 3641 | 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" , 3642, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 3642 | 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" , 3642, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 3643 | 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" , 3643, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 3644 | glbl_cumulative += 1; |
| 3645 | 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" , 3645, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 3646 | // Lets' double check that the actual allocation took place. |
| 3647 | 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" , 3647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.fake_allocation_", "true", "false") .c_str()) = ::testing ::Message(); |
| 3648 | } |
| 3649 | |
| 3650 | // This test checks the behavior of the allocation engine in the following |
| 3651 | // scenario: |
| 3652 | // - Client has no lease in the database. |
| 3653 | // - Client has a global reservation outside of the subnet. |
| 3654 | // - Client sends DISCOVER |
| 3655 | // - Client is allocated an address within the subnet. |
| 3656 | // - Lease is not added to the lease database |
| 3657 | TEST_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" , 3657), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3657), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3657), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test ::TestBody() { |
| 3658 | // Create reservation for the client. |
| 3659 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3660 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3661 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 3662 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3663 | CfgMgr::instance().commit(); |
| 3664 | |
| 3665 | AllocEngine engine(0); |
| 3666 | |
| 3667 | subnet_->setReservationsGlobal(true); |
| 3668 | |
| 3669 | // Query allocation engine for the lease to be assigned to this |
| 3670 | // client without specifying the address to be assigned. |
| 3671 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3672 | IOAddress("0.0.0.0"), false, false, |
| 3673 | "", true); |
| 3674 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3675 | |
| 3676 | // Look up the host. |
| 3677 | AllocEngine::findReservation(ctx); |
| 3678 | |
| 3679 | // We should have the correct current host |
| 3680 | EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3680, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3681 | EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()" , "host->getHostname()", ctx.currentHost()->getHostname (), host->getHostname()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3681, gtest_ar.failure_message()) = ::testing::Message(); |
| 3682 | EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()" , "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation (), host->getIPv4Reservation()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3682, gtest_ar.failure_message()) = ::testing::Message(); |
| 3683 | |
| 3684 | // We should allocate an address in the subnet |
| 3685 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3686 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3686, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3687 | EXPECT_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" , 3687, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 3688 | |
| 3689 | // This is a "fake" allocation so the returned lease should not be committed |
| 3690 | // to the lease database. |
| 3691 | 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" , 3691, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3692 | |
| 3693 | // Client had no lease in the database, so the old lease returned should |
| 3694 | // be null. |
| 3695 | 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" , 3695, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3696 | } |
| 3697 | |
| 3698 | // This test checks the behavior of the allocation engine in the following |
| 3699 | // scenario: |
| 3700 | // - Client has no lease in the database. |
| 3701 | // - Client has a global reservation matching the current subnet. |
| 3702 | // - Client sends DISCOVER |
| 3703 | // - Client is allocated the reserved address. |
| 3704 | // - Lease is not added to the lease database |
| 3705 | TEST_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" , 3705), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3705), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3705), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test ::TestBody() { |
| 3706 | // Create reservation for the client. |
| 3707 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3708 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3709 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
| 3710 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3711 | CfgMgr::instance().commit(); |
| 3712 | |
| 3713 | AllocEngine engine(0); |
| 3714 | |
| 3715 | subnet_->setReservationsGlobal(true); |
| 3716 | |
| 3717 | // Query allocation engine for the lease to be assigned to this |
| 3718 | // client without specifying the address to be assigned. |
| 3719 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3720 | IOAddress("0.0.0.0"), false, false, |
| 3721 | "", true); |
| 3722 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3723 | |
| 3724 | // Look up the host. |
| 3725 | AllocEngine::findReservation(ctx); |
| 3726 | |
| 3727 | // We should have the correct current host |
| 3728 | 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" , 3728, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3729 | 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" , 3729, gtest_ar.failure_message()) = ::testing::Message(); |
| 3730 | 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" , 3730, gtest_ar.failure_message()) = ::testing::Message(); |
| 3731 | |
| 3732 | // We should allocate the reserved address. |
| 3733 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3734 | 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" , 3734, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3735 | 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" , 3735, gtest_ar.failure_message()) = ::testing::Message(); |
| 3736 | |
| 3737 | // This is a "fake" allocation so the returned lease should not be committed |
| 3738 | // to the lease database. |
| 3739 | 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" , 3739, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3740 | |
| 3741 | // Client had no lease in the database, so the old lease returned should |
| 3742 | // be null. |
| 3743 | 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" , 3743, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3744 | } |
| 3745 | |
| 3746 | // This test checks the behavior of the allocation engine in the following |
| 3747 | // scenario: |
| 3748 | // - Client has no lease in the database. |
| 3749 | // - Client has a global reservation outside the current subnet. |
| 3750 | // - Client sends REQUEST |
| 3751 | // - Client is allocated a dynamic address. |
| 3752 | // - Lease is added to the lease database |
| 3753 | TEST_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" , 3753), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3753), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3753), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test ::TestBody() { |
| 3754 | // Create reservation for the client. |
| 3755 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3756 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3757 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 3758 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3759 | CfgMgr::instance().commit(); |
| 3760 | |
| 3761 | AllocEngine engine(0); |
| 3762 | |
| 3763 | subnet_->setReservationsGlobal(true); |
| 3764 | |
| 3765 | // Query allocation engine for the lease to be assigned to this |
| 3766 | // client without specifying the address to be assigned. |
| 3767 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3768 | IOAddress("0.0.0.0"), false, false, |
| 3769 | "", false); |
| 3770 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3771 | |
| 3772 | // Look up the host. |
| 3773 | AllocEngine::findReservation(ctx); |
| 3774 | |
| 3775 | // We should have the correct current host |
| 3776 | 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" , 3776, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3777 | 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" , 3777, gtest_ar.failure_message()) = ::testing::Message(); |
| 3778 | 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" , 3778, gtest_ar.failure_message()) = ::testing::Message(); |
| 3779 | |
| 3780 | // We should allocate the reserved address. |
| 3781 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3782 | 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" , 3782, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3783 | 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" , 3783, gtest_ar.failure_message()) = ::testing::Message(); |
| 3784 | 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" , 3784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 3785 | |
| 3786 | // Check that the lease is indeed in LeaseMgr |
| 3787 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3788 | 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" , 3788, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3789 | |
| 3790 | // Now check that the lease in LeaseMgr has the same parameters |
| 3791 | detailCompareLease(lease, from_mgr); |
| 3792 | |
| 3793 | // Client had no lease in the database, so the old lease returned should |
| 3794 | // be null. |
| 3795 | 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" , 3795, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3796 | } |
| 3797 | |
| 3798 | // This test checks the behavior of the allocation engine in the following |
| 3799 | // scenario: |
| 3800 | // - Client has no lease in the database. |
| 3801 | // - Client has a global reservation matching the current subnet. |
| 3802 | // - Client sends REQUEST |
| 3803 | // - Client is allocated the reserved address. |
| 3804 | // - Lease is added to the lease database |
| 3805 | TEST_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" , 3805), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3805), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3805), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test ::TestBody() { |
| 3806 | // Create reservation for the client. |
| 3807 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3808 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3809 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
| 3810 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3811 | CfgMgr::instance().commit(); |
| 3812 | |
| 3813 | AllocEngine engine(0); |
| 3814 | |
| 3815 | subnet_->setReservationsGlobal(true); |
| 3816 | |
| 3817 | // Query allocation engine for the lease to be assigned to this |
| 3818 | // client without specifying the address to be assigned. |
| 3819 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3820 | IOAddress("0.0.0.0"), false, false, |
| 3821 | "", false); |
| 3822 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3823 | |
| 3824 | // Look up the host. |
| 3825 | AllocEngine::findReservation(ctx); |
| 3826 | |
| 3827 | // We should have the correct current host |
| 3828 | 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" , 3828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3829 | 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" , 3829, gtest_ar.failure_message()) = ::testing::Message(); |
| 3830 | 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" , 3830, gtest_ar.failure_message()) = ::testing::Message(); |
| 3831 | |
| 3832 | // We should allocate the reserved address. |
| 3833 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3834 | 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" , 3834, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3835 | 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" , 3835, gtest_ar.failure_message()) = ::testing::Message(); |
| 3836 | |
| 3837 | // Check that the lease is indeed in LeaseMgr |
| 3838 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3839 | 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" , 3839, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3840 | |
| 3841 | // Now check that the lease in LeaseMgr has the same parameters |
| 3842 | detailCompareLease(lease, from_mgr); |
| 3843 | |
| 3844 | // Client had no lease in the database, so the old lease returned should |
| 3845 | // be null. |
| 3846 | 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" , 3846, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3847 | } |
| 3848 | |
| 3849 | // This test checks the behavior of the allocation engine in the following |
| 3850 | // scenario: |
| 3851 | // - Client has no lease in the database. |
| 3852 | // - Client has a global reservation. |
| 3853 | // - Client sends DISCOVER |
| 3854 | // - Client is allocated a dynamic address from matched subnet |
| 3855 | // - Lease is not added to the lease database |
| 3856 | TEST_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" , 3856), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3856), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3856), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicDiscover_Test >); void AllocEngine4Test_globalReservationDynamicDiscover_Test ::TestBody() { |
| 3857 | // Create reservation for the client. |
| 3858 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3859 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3860 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
| 3861 | "foo.example.org")); |
| 3862 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3863 | CfgMgr::instance().commit(); |
| 3864 | |
| 3865 | AllocEngine engine(0); |
| 3866 | |
| 3867 | subnet_->setReservationsGlobal(true); |
| 3868 | |
| 3869 | // Query allocation engine for the lease to be assigned to this |
| 3870 | // client without specifying the address to be assigned. |
| 3871 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3872 | IOAddress("0.0.0.0"), false, false, |
| 3873 | "", true); |
| 3874 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3875 | |
| 3876 | // Look up the host. |
| 3877 | AllocEngine::findReservation(ctx); |
| 3878 | |
| 3879 | // We should have the correct current host |
| 3880 | 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" , 3880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3881 | 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" , 3881, gtest_ar.failure_message()) = ::testing::Message(); |
| 3882 | 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" , 3882, gtest_ar.failure_message()) = ::testing::Message(); |
| 3883 | |
| 3884 | // We should allocate a dynamic address. |
| 3885 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3886 | 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" , 3886, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3887 | 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" , 3887, gtest_ar.failure_message()) = ::testing::Message(); |
| 3888 | |
| 3889 | // This is a "fake" allocation so the returned lease should not be committed |
| 3890 | // to the lease database. |
| 3891 | 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" , 3891, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3892 | |
| 3893 | // Client had no lease in the database, so the old lease returned should |
| 3894 | // be null. |
| 3895 | 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" , 3895, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3896 | } |
| 3897 | |
| 3898 | // This test checks the behavior of the allocation engine in the following |
| 3899 | // scenario: |
| 3900 | // - Client has no lease in the database. |
| 3901 | // - Client has a global reservation. |
| 3902 | // - Client sends REQUEST |
| 3903 | // - Client is allocated a dynamic address from matched subnet |
| 3904 | // - Lease is added to the lease database |
| 3905 | TEST_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" , 3905), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3905), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3905), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicRequest_Test >); void AllocEngine4Test_globalReservationDynamicRequest_Test ::TestBody() { |
| 3906 | // Create reservation for the client. |
| 3907 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3908 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3909 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
| 3910 | "foo.example.org")); |
| 3911 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3912 | CfgMgr::instance().commit(); |
| 3913 | |
| 3914 | AllocEngine engine(0); |
| 3915 | |
| 3916 | subnet_->setReservationsGlobal(true); |
| 3917 | |
| 3918 | // Query allocation engine for the lease to be assigned to this |
| 3919 | // client without specifying the address to be assigned. |
| 3920 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3921 | IOAddress("0.0.0.0"), false, false, |
| 3922 | "", false); |
| 3923 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3924 | |
| 3925 | // Look up the host. |
| 3926 | AllocEngine::findReservation(ctx); |
| 3927 | |
| 3928 | // We should have the correct current host |
| 3929 | 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" , 3929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3930 | 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" , 3930, gtest_ar.failure_message()) = ::testing::Message(); |
| 3931 | 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" , 3931, gtest_ar.failure_message()) = ::testing::Message(); |
| 3932 | |
| 3933 | // We should allocate a dynamic address. |
| 3934 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3935 | 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" , 3935, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3936 | 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" , 3936, gtest_ar.failure_message()) = ::testing::Message(); |
| 3937 | |
| 3938 | // Check that the lease is indeed in LeaseMgr |
| 3939 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3940 | 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" , 3940, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3941 | |
| 3942 | // Now check that the lease in LeaseMgr has the same parameters |
| 3943 | detailCompareLease(lease, from_mgr); |
| 3944 | |
| 3945 | // Client had no lease in the database, so the old lease returned should |
| 3946 | // be null. |
| 3947 | 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" , 3947, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3948 | } |
| 3949 | |
| 3950 | // This test checks the behavior of the allocation engine in the following |
| 3951 | // scenario: |
| 3952 | // - Client has no lease in the database. |
| 3953 | // - Client has a subnet reservation. |
| 3954 | // - Client sends DISCOVER |
| 3955 | // - Client is allocated the reserved address. |
| 3956 | // - Lease is not added to the lease database |
| 3957 | TEST_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" , 3957), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3957), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3957), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressDiscover_Test >); void AllocEngine4Test_mixedReservationReservedAddressDiscover_Test ::TestBody() { |
| 3958 | // Create reservation for the client. |
| 3959 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3960 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3961 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 3962 | "foo.example.org")); |
| 3963 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3964 | CfgMgr::instance().commit(); |
| 3965 | |
| 3966 | AllocEngine engine(0); |
| 3967 | |
| 3968 | subnet_->setReservationsGlobal(true); |
| 3969 | subnet_->setReservationsInSubnet(true); |
| 3970 | |
| 3971 | // Query allocation engine for the lease to be assigned to this |
| 3972 | // client without specifying the address to be assigned. |
| 3973 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3974 | IOAddress("0.0.0.0"), false, false, |
| 3975 | "", true); |
| 3976 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3977 | |
| 3978 | // Look up the host. |
| 3979 | AllocEngine::findReservation(ctx); |
| 3980 | |
| 3981 | // We should have the correct current host |
| 3982 | 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" , 3982, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3983 | 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" , 3983, gtest_ar.failure_message()) = ::testing::Message(); |
| 3984 | 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" , 3984, gtest_ar.failure_message()) = ::testing::Message(); |
| 3985 | |
| 3986 | // We should allocate the reserved address. |
| 3987 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3988 | 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" , 3988, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3989 | 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" , 3989, gtest_ar.failure_message()) = ::testing::Message(); |
| 3990 | |
| 3991 | // This is a "fake" allocation so the returned lease should not be committed |
| 3992 | // to the lease database. |
| 3993 | 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" , 3993, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3994 | |
| 3995 | // Client had no lease in the database, so the old lease returned should |
| 3996 | // be null. |
| 3997 | 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" , 3997, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3998 | } |
| 3999 | |
| 4000 | // This test checks the behavior of the allocation engine in the following |
| 4001 | // scenario: |
| 4002 | // - Client has no lease in the database. |
| 4003 | // - Client has a subnet reservation. |
| 4004 | // - Client sends REQUEST |
| 4005 | // - Client is allocated the reserved address. |
| 4006 | // - Lease is added to the lease database |
| 4007 | TEST_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" , 4007), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4007), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4007), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressRequest_Test >); void AllocEngine4Test_mixedReservationReservedAddressRequest_Test ::TestBody() { |
| 4008 | // Create reservation for the client. |
| 4009 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 4010 | Host::IDENT_HWADDR, subnet_->getID(), |
| 4011 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 4012 | "foo.example.org")); |
| 4013 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 4014 | CfgMgr::instance().commit(); |
| 4015 | |
| 4016 | AllocEngine engine(0); |
| 4017 | |
| 4018 | subnet_->setReservationsGlobal(true); |
| 4019 | subnet_->setReservationsInSubnet(true); |
| 4020 | |
| 4021 | // Query allocation engine for the lease to be assigned to this |
| 4022 | // client without specifying the address to be assigned. |
| 4023 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 4024 | IOAddress("0.0.0.0"), false, false, |
| 4025 | "", false); |
| 4026 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4027 | |
| 4028 | // Look up the host. |
| 4029 | AllocEngine::findReservation(ctx); |
| 4030 | |
| 4031 | // We should have the correct current host |
| 4032 | 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" , 4032, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4033 | 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" , 4033, gtest_ar.failure_message()) = ::testing::Message(); |
| 4034 | 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" , 4034, gtest_ar.failure_message()) = ::testing::Message(); |
| 4035 | |
| 4036 | // We should allocate the reserved address. |
| 4037 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4038 | 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" , 4038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4039 | 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" , 4039, gtest_ar.failure_message()) = ::testing::Message(); |
| 4040 | |
| 4041 | // Check that the lease is indeed in LeaseMgr |
| 4042 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 4043 | 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" , 4043, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4044 | |
| 4045 | // Now check that the lease in LeaseMgr has the same parameters |
| 4046 | detailCompareLease(lease, from_mgr); |
| 4047 | |
| 4048 | // Client had no lease in the database, so the old lease returned should |
| 4049 | // be null. |
| 4050 | 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" , 4050, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 4051 | } |
| 4052 | |
| 4053 | // This test checks the behavior of the allocation engine in the following |
| 4054 | // scenario: |
| 4055 | // - Client has no lease in the database. |
| 4056 | // - Client has a global and a subnet reservation. |
| 4057 | // - Client sends DISCOVER |
| 4058 | // - Client is allocated the reserved address. |
| 4059 | // - Lease is not added to the lease database |
| 4060 | TEST_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" , 4060), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4060), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4060), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressDiscover_Test >); void AllocEngine4Test_bothReservationReservedAddressDiscover_Test ::TestBody() { |
| 4061 | // Create reservations for the client. |
| 4062 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 4063 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 4064 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 4065 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
| 4066 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 4067 | Host::IDENT_HWADDR, subnet_->getID(), |
| 4068 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 4069 | "foo.example.org")); |
| 4070 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 4071 | CfgMgr::instance().commit(); |
| 4072 | |
| 4073 | AllocEngine engine(0); |
| 4074 | |
| 4075 | subnet_->setReservationsGlobal(true); |
| 4076 | subnet_->setReservationsInSubnet(true); |
| 4077 | |
| 4078 | // Query allocation engine for the lease to be assigned to this |
| 4079 | // client without specifying the address to be assigned. |
| 4080 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 4081 | IOAddress("0.0.0.0"), false, false, |
| 4082 | "", true); |
| 4083 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4084 | |
| 4085 | // Look up the host. |
| 4086 | AllocEngine::findReservation(ctx); |
| 4087 | |
| 4088 | // We should have the correct current host |
| 4089 | 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" , 4089, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4090 | 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" , 4090, gtest_ar.failure_message()) = ::testing::Message(); |
| 4091 | 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" , 4091, gtest_ar.failure_message()) = ::testing::Message(); |
| 4092 | |
| 4093 | // We should allocate the reserved address. |
| 4094 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4095 | 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" , 4095, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4096 | 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" , 4096, gtest_ar.failure_message()) = ::testing::Message(); |
| 4097 | |
| 4098 | // This is a "fake" allocation so the returned lease should not be committed |
| 4099 | // to the lease database. |
| 4100 | 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" , 4100, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 4101 | |
| 4102 | // Client had no lease in the database, so the old lease returned should |
| 4103 | // be null. |
| 4104 | 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" , 4104, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 4105 | } |
| 4106 | |
| 4107 | // This test checks the behavior of the allocation engine in the following |
| 4108 | // scenario: |
| 4109 | // - Client has no lease in the database. |
| 4110 | // - Client has a global and a subnet reservation. |
| 4111 | // - Client sends REQUEST |
| 4112 | // - Client is allocated the reserved address. |
| 4113 | // - Lease is added to the lease database |
| 4114 | TEST_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" , 4114), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4114), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4114), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressRequest_Test >); void AllocEngine4Test_bothReservationReservedAddressRequest_Test ::TestBody() { |
| 4115 | // Create reservations for the client. |
| 4116 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 4117 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 4118 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 4119 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
| 4120 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 4121 | Host::IDENT_HWADDR, subnet_->getID(), |
| 4122 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 4123 | "foo.example.org")); |
| 4124 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 4125 | CfgMgr::instance().commit(); |
| 4126 | |
| 4127 | AllocEngine engine(0); |
| 4128 | |
| 4129 | subnet_->setReservationsGlobal(true); |
| 4130 | subnet_->setReservationsInSubnet(true); |
| 4131 | |
| 4132 | // Query allocation engine for the lease to be assigned to this |
| 4133 | // client without specifying the address to be assigned. |
| 4134 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 4135 | IOAddress("0.0.0.0"), false, false, |
| 4136 | "", false); |
| 4137 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4138 | |
| 4139 | // Look up the host. |
| 4140 | AllocEngine::findReservation(ctx); |
| 4141 | |
| 4142 | // We should have the correct current host |
| 4143 | 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" , 4143, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4144 | 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" , 4144, gtest_ar.failure_message()) = ::testing::Message(); |
| 4145 | 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" , 4145, gtest_ar.failure_message()) = ::testing::Message(); |
| 4146 | |
| 4147 | // We should allocate the reserved address. |
| 4148 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4149 | 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" , 4149, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4150 | 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" , 4150, gtest_ar.failure_message()) = ::testing::Message(); |
| 4151 | |
| 4152 | // Check that the lease is indeed in LeaseMgr |
| 4153 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 4154 | 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" , 4154, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4155 | |
| 4156 | // Now check that the lease in LeaseMgr has the same parameters |
| 4157 | detailCompareLease(lease, from_mgr); |
| 4158 | |
| 4159 | // Client had no lease in the database, so the old lease returned should |
| 4160 | // be null. |
| 4161 | 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" , 4161, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 4162 | } |
| 4163 | |
| 4164 | // Exercises AllocEnginer4Test::updateExtendedInfo4() through various |
| 4165 | // permutations of client packet content. |
| 4166 | TEST_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" , 4166), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4166), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4166), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_updateExtendedInfo4_Test >); void AllocEngine4Test_updateExtendedInfo4_Test::TestBody () { |
| 4167 | |
| 4168 | // Structure that defines a test scenario. |
| 4169 | struct Scenario { |
| 4170 | std::string description_; // test description |
| 4171 | std::string orig_context_json_; // user context the lease begins with |
| 4172 | std::string rai_data_; // RAI option the client packet contains |
| 4173 | std::string exp_context_json_; // expected user context on the lease |
| 4174 | bool exp_ret; // expected returned value |
| 4175 | }; |
| 4176 | |
| 4177 | // Test scenarios. |
| 4178 | std::vector<Scenario> scenarios { |
| 4179 | { |
| 4180 | "no context, no rai", |
| 4181 | "", |
| 4182 | "", |
| 4183 | "", |
| 4184 | false |
| 4185 | }, |
| 4186 | { |
| 4187 | "some original context, no rai", |
| 4188 | "{\"foo\": 123}", |
| 4189 | "", |
| 4190 | "{\"foo\": 123}", |
| 4191 | false |
| 4192 | }, |
| 4193 | { |
| 4194 | "no original context, rai", |
| 4195 | "", |
| 4196 | "0x52060104aabbccdd", |
| 4197 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4198 | " \"0x0104AABBCCDD\" } } }", |
| 4199 | true |
| 4200 | }, |
| 4201 | { |
| 4202 | "no original context, rai, remote and relay ids", |
| 4203 | "", |
| 4204 | "0x520a02030102030c03aabbcc", |
| 4205 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4206 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
| 4207 | " \"relay-id\": \"AABBCC\" } } }", |
| 4208 | true |
| 4209 | }, |
| 4210 | { |
| 4211 | "some original context, rai", |
| 4212 | "{\"foo\": 123, \"ISC\":{\"bar\": 456}}", |
| 4213 | "0x52060104aabbccdd", |
| 4214 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4215 | " \"0x0104AABBCCDD\" }, \"bar\": 456 }, \"foo\": 123 }", |
| 4216 | true |
| 4217 | }, |
| 4218 | { |
| 4219 | "bad original context, rai", |
| 4220 | "[\"foo\"]", |
| 4221 | "0x52060104aabbccdd", |
| 4222 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4223 | " \"0x0104AABBCCDD\" } } }", |
| 4224 | true |
| 4225 | }, |
| 4226 | { |
| 4227 | "some original context with bad isc entry, rai", |
| 4228 | "{\"foo\": 123, \"ISC\":[\"bar\"]}", |
| 4229 | "0x52060104aabbccdd", |
| 4230 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4231 | " \"0x0104AABBCCDD\" } }, \"foo\": 123 }", |
| 4232 | true |
| 4233 | }, |
| 4234 | { |
| 4235 | "some original context, rai, remote and relay ids", |
| 4236 | "{\"foo\": 123, \"ISC\":{ \"bar\": 456}}", |
| 4237 | "0x520a02030102030c03aabbcc", |
| 4238 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4239 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
| 4240 | " \"relay-id\": \"AABBCC\" }, \"bar\": 456 }, \"foo\": 123 }", |
| 4241 | true |
| 4242 | }, |
| 4243 | { |
| 4244 | "original rai context, no rai", |
| 4245 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4246 | " \"0x0104AABBCCDD\" } } }", |
| 4247 | "", |
| 4248 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4249 | " \"0x0104AABBCCDD\" } } }", |
| 4250 | false |
| 4251 | }, |
| 4252 | { |
| 4253 | "original rai context, different rai", |
| 4254 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4255 | " \"0x0104AABBCCDD\" } } }", |
| 4256 | "0x52060104ddeeffaa", |
| 4257 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4258 | " \"0x0104DDEEFFAA\" } } }", |
| 4259 | true |
| 4260 | }, |
| 4261 | { |
| 4262 | "original rai context, different rai, remote and relay ids", |
| 4263 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4264 | " \"0x0104AABBCCDD\" } } }", |
| 4265 | "0x520a02030102030c03aabbcc", |
| 4266 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4267 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
| 4268 | " \"relay-id\": \"AABBCC\" } } }", |
| 4269 | true |
| 4270 | }}; |
| 4271 | |
| 4272 | // Create the allocation engine, context and lease. |
| 4273 | NakedAllocEngine engine(0); |
| 4274 | |
| 4275 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 4276 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 4277 | false, false, "", true); |
| 4278 | |
| 4279 | // All scenarios require storage to be enabled. |
| 4280 | subnet_->setStoreExtendedInfo(true); |
| 4281 | |
| 4282 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4283 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4284 | 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" , 4284, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4285 | 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" , 4285, gtest_ar.failure_message()) = ::testing::Message(); |
| 4286 | |
| 4287 | // Verify that the lease begins with no user context. |
| 4288 | ConstElementPtr user_context = lease->getContext(); |
| 4289 | 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" , 4289, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "true", "false") .c_str()) = ::testing::Message (); |
| 4290 | |
| 4291 | // Iterate over the test scenarios. |
| 4292 | ElementPtr orig_context; |
| 4293 | ElementPtr exp_context; |
| 4294 | for (auto const& scenario : scenarios) { |
| 4295 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4295( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4295, (scenario.description_)); |
| 4296 | |
| 4297 | // Create the original user context from JSON. |
| 4298 | if (scenario.orig_context_json_.empty()) { |
| 4299 | orig_context.reset(); |
| 4300 | } else { |
| 4301 | 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_4301; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4301 ; } } else gtest_label_testnothrow_4301 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4301, ("Expected: " "orig_context = Element::fromJSON(scenario.orig_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4302 | << "invalid orig_context_json_, test is broken"; |
| 4303 | } |
| 4304 | |
| 4305 | // Create the expected user context from JSON. |
| 4306 | if (scenario.exp_context_json_.empty()) { |
| 4307 | exp_context.reset(); |
| 4308 | } else { |
| 4309 | 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_4309; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4309 ; } } else gtest_label_testnothrow_4309 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4309, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4310 | << "invalid exp_context_json_, test is broken"; |
| 4311 | } |
| 4312 | |
| 4313 | // Initialize lease's user context. |
| 4314 | lease->setContext(orig_context); |
| 4315 | if (!orig_context) { |
| 4316 | 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" , 4316, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4317 | } else { |
| 4318 | 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" , 4318, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4319 | 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" , 4319, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "orig_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message(); |
| 4320 | } |
| 4321 | |
| 4322 | // Create the client packet and the add RAI option (if one). |
| 4323 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4324 | if (!scenario.rai_data_.empty()) { |
| 4325 | std::vector<uint8_t> opt_data; |
| 4326 | 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_4326; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4326 ; } } else gtest_label_testnothrow_4326 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4326, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4327 | << "scenario.rai_data_ is invalid, test is broken"; |
| 4328 | const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF(); |
| 4329 | 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" , 4329, gtest_ar.failure_message()) = ::testing::Message(); |
| 4330 | 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" , 4330, gtest_ar.failure_message()) = ::testing::Message(); |
| 4331 | 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" , 4331, gtest_ar.failure_message()) = ::testing::Message(); |
| 4332 | std::vector<uint8_t> rai_data(opt_data.cbegin() + 2, |
| 4333 | opt_data.cend()); |
| 4334 | OptionCustomPtr rai; |
| 4335 | 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_4336; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4336; } } else gtest_label_testnothrow_4336 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4336, ("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() |
| 4336 | 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_4336; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4336; } } else gtest_label_testnothrow_4336 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4336, ("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() |
| 4337 | << "could not create rai option, test is broken"; |
| 4338 | ctx.query_->addOption(rai); |
| 4339 | } |
| 4340 | |
| 4341 | // Call AllocEngine::updateLease4ExtendeInfo(). |
| 4342 | bool ret = false; |
| 4343 | 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", 4343, "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", 4343, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4344 | 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" , 4344, gtest_ar.failure_message()) = ::testing::Message(); |
| 4345 | |
| 4346 | // Verify the lease has the expected user context content. |
| 4347 | if (!exp_context) { |
| 4348 | 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" , 4348, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4349 | } else { |
| 4350 | 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" , 4350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4351 | 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" , 4351, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message() |
| 4352 | << "expected: " << *(exp_context) << std::endl |
| 4353 | << " actual: " << *(lease->getContext()) << std::endl; |
| 4354 | } |
| 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | // Verifies that recovered stashed RAI is not saved in extended info. |
| 4359 | TEST_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" , 4359), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4359), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4359), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_stashAgentOptions_Test >); void AllocEngine4Test_stashAgentOptions_Test::TestBody () { |
| 4360 | // Create the allocation engine, context and lease. |
| 4361 | NakedAllocEngine engine(0); |
| 4362 | |
| 4363 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 4364 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 4365 | false, false, "", true); |
| 4366 | subnet_->setStoreExtendedInfo(true); |
| 4367 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4368 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4369 | 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" , 4369, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4370 | 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" , 4370, gtest_ar.failure_message()) = ::testing::Message(); |
| 4371 | |
| 4372 | // Verify that the lease begins with no user context. |
| 4373 | ConstElementPtr user_context = lease->getContext(); |
| 4374 | 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" , 4374, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "true", "false") .c_str()) = ::testing::Message (); |
| 4375 | |
| 4376 | // Add a RAI in the query. |
| 4377 | std::string rai_str = "0104aabbccdd"; |
| 4378 | std::vector<uint8_t> rai_data; |
| 4379 | 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_4379; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4379; } } else gtest_label_testnothrow_4379 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4379, ("Expected: " "util::str::decodeFormattedHexString(rai_str, rai_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 4380 | const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF(); |
| 4381 | OptionCustomPtr rai; |
| 4382 | 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_4382; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4382; } } else gtest_label_testnothrow_4382 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4382, ("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(); |
| 4383 | ctx.query_->addOption(rai); |
| 4384 | |
| 4385 | // Verifies that the RAI is saved into lease extended info. |
| 4386 | bool ret = false; |
| 4387 | 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", 4387, "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", 4387, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4388 | 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", 4388, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ret", "false", "true") .c_str()) = ::testing::Message(); |
| 4389 | user_context = lease->getContext(); |
| 4390 | 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" , 4390, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "false", "true") .c_str()) = ::testing::Message (); |
| 4391 | lease->setContext(ElementPtr()); |
| 4392 | |
| 4393 | // Set stash-agent-options to true. |
| 4394 | CfgMgr::instance().getStagingCfg()-> |
| 4395 | addConfiguredGlobal("stash-agent-options", Element::create(true)); |
| 4396 | CfgMgr::instance().commit(); |
| 4397 | |
| 4398 | // Verifies that the RAI is saved into lease extended info. |
| 4399 | ret = false; |
Value stored to 'ret' is never read | |
| 4400 | 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", 4400, "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", 4400, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4401 | 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", 4401, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ret", "false", "true") .c_str()) = ::testing::Message(); |
| 4402 | user_context = lease->getContext(); |
| 4403 | 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" , 4403, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "false", "true") .c_str()) = ::testing::Message (); |
| 4404 | lease->setContext(ElementPtr()); |
| 4405 | |
| 4406 | // Put the query in the STASH_AGENT_OPTIONS class. |
| 4407 | ctx.query_->addClass("STASH_AGENT_OPTIONS"); |
| 4408 | |
| 4409 | // Verifies that the RAI is not saved into lease extended info. |
| 4410 | ret = false; |
| 4411 | 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", 4411, "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", 4411, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4412 | 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", 4412, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ret", "true", "false") .c_str()) = ::testing::Message(); |
| 4413 | user_context = lease->getContext(); |
| 4414 | 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" , 4414, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "true", "false") .c_str()) = ::testing::Message (); |
| 4415 | } |
| 4416 | |
| 4417 | // Verifies that the extended data (e.g. RAI option for now) is |
| 4418 | // added to a V4 lease when leases are created and/or renewed, |
| 4419 | // when store-extended-info is true. |
| 4420 | TEST_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" , 4420), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4420), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4420), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoEnabled4_Test >); void AllocEngine4Test_storeExtendedInfoEnabled4_Test:: TestBody() { |
| 4421 | |
| 4422 | // Structure that defines a test scenario. |
| 4423 | struct Scenario { |
| 4424 | std::string description_; // test description |
| 4425 | std::vector<uint8_t> mac_; // MAC address |
| 4426 | std::string rai_data_; // RAI option the client packet contains |
| 4427 | std::string exp_context_json_; // expected user context on the lease |
| 4428 | std::string exp_address_; // expected lease address |
| 4429 | }; |
| 4430 | |
| 4431 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
| 4432 | std::string mac1_addr = "192.0.2.100"; |
| 4433 | |
| 4434 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
| 4435 | std::string mac2_addr = "192.0.2.101"; |
| 4436 | |
| 4437 | // Test scenarios. |
| 4438 | std::vector<Scenario> scenarios { |
| 4439 | { |
| 4440 | "create client one without rai", |
| 4441 | mac1, |
| 4442 | "", |
| 4443 | "", |
| 4444 | mac1_addr |
| 4445 | }, |
| 4446 | { |
| 4447 | "renew client one without rai", |
| 4448 | {}, |
| 4449 | "", |
| 4450 | "", |
| 4451 | mac1_addr |
| 4452 | }, |
| 4453 | { |
| 4454 | "create client two with rai", |
| 4455 | mac2, |
| 4456 | "0x52050104a1b1c1d1", |
| 4457 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4458 | " \"0x52050104A1B1C1D1\" } } }", |
| 4459 | mac2_addr |
| 4460 | }, |
| 4461 | { |
| 4462 | "renew client two without rai", |
| 4463 | {}, |
| 4464 | "", |
| 4465 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4466 | " \"0x52050104A1B1C1D1\" } } }", |
| 4467 | mac2_addr |
| 4468 | }}; |
| 4469 | |
| 4470 | // Create the allocation engine, context and lease. |
| 4471 | NakedAllocEngine engine(0); |
| 4472 | |
| 4473 | // All of the scenarios require storage to be enabled. |
| 4474 | subnet_->setStoreExtendedInfo(true); |
| 4475 | |
| 4476 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 4477 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 4478 | false, false, "", false); |
| 4479 | |
| 4480 | // Iterate over the test scenarios. |
| 4481 | for (auto const& scenario : scenarios) { |
| 4482 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4482( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4482, (scenario.description_)); |
| 4483 | |
| 4484 | ElementPtr exp_context; |
| 4485 | // Create the expected user context from JSON. |
| 4486 | if (!scenario.exp_context_json_.empty()) { |
| 4487 | 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_4487; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4487 ; } } else gtest_label_testnothrow_4487 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4487, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4488 | << "invalid exp_context_json_, test is broken"; |
| 4489 | } |
| 4490 | |
| 4491 | // If we have a MAC address this scenario is for a new client. |
| 4492 | if (!scenario.mac_.empty()) { |
| 4493 | 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_4493; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4493; } } else gtest_label_testnothrow_4493 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4493, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4494 | << "invalid MAC address, test is broken"; |
| 4495 | } |
| 4496 | |
| 4497 | // Create the client packet and the add RAI option (if one). |
| 4498 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4499 | if (!scenario.rai_data_.empty()) { |
| 4500 | std::vector<uint8_t> opt_data; |
| 4501 | 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_4501; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4501 ; } } else gtest_label_testnothrow_4501 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4501, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4502 | << "scenario.rai_data_ is invalid, test is broken"; |
| 4503 | OptionPtr rai; |
| 4504 | 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_4504; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4504; } } else gtest_label_testnothrow_4504 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4504, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4505 | << "could not create rai option, test is broken"; |
| 4506 | |
| 4507 | ctx.query_->addOption(rai); |
| 4508 | } |
| 4509 | |
| 4510 | // Create or renew the lease. |
| 4511 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4512 | 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" , 4512, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4513 | 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" , 4513, gtest_ar.failure_message()) = ::testing::Message(); |
| 4514 | |
| 4515 | // Verify the lease has the expected user context content. |
| 4516 | if (!exp_context) { |
| 4517 | 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" , 4517, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4518 | } else { |
| 4519 | 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" , 4519, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4520 | 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" , 4520, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message() |
| 4521 | << "expected: " << *(exp_context) << std::endl |
| 4522 | << " actual: " << *(lease->getContext()) << std::endl; |
| 4523 | } |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | // Verifies that the extended data (e.g. RAI option for now) is |
| 4528 | // not added to a V4 lease when leases are created and/or renewed, |
| 4529 | // when store-extended-info is false. |
| 4530 | TEST_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" , 4530), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4530), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4530), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoDisabled4_Test >); void AllocEngine4Test_storeExtendedInfoDisabled4_Test:: TestBody() { |
| 4531 | |
| 4532 | // Structure that defines a test scenario. |
| 4533 | struct Scenario { |
| 4534 | std::string description_; // test description |
| 4535 | std::vector<uint8_t> mac_; // MAC address |
| 4536 | std::string rai_data_; // RAI option the client packet contains |
| 4537 | std::string exp_address_; // expected lease address |
| 4538 | }; |
| 4539 | |
| 4540 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
| 4541 | std::string mac1_addr = "192.0.2.100"; |
| 4542 | |
| 4543 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
| 4544 | std::string mac2_addr = "192.0.2.101"; |
| 4545 | |
| 4546 | // Test scenarios. |
| 4547 | std::vector<Scenario> scenarios { |
| 4548 | { |
| 4549 | "create client one without rai", |
| 4550 | mac1, |
| 4551 | "", |
| 4552 | mac1_addr |
| 4553 | }, |
| 4554 | { |
| 4555 | "renew client one without rai", |
| 4556 | {}, |
| 4557 | "", |
| 4558 | mac1_addr |
| 4559 | }, |
| 4560 | { |
| 4561 | "create client two with rai", |
| 4562 | mac2, |
| 4563 | "0x52050104a1b1c1d1", |
| 4564 | mac2_addr |
| 4565 | }, |
| 4566 | { |
| 4567 | "renew client two with rai", |
| 4568 | {}, |
| 4569 | "0x52050104a1b1c1d1", |
| 4570 | mac2_addr |
| 4571 | }}; |
| 4572 | |
| 4573 | // Create the allocation engine, context and lease. |
| 4574 | NakedAllocEngine engine(0); |
| 4575 | |
| 4576 | // All of the scenarios require storage to be disabled. |
| 4577 | subnet_->setStoreExtendedInfo(false); |
| 4578 | |
| 4579 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 4580 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 4581 | false, false, "", false); |
| 4582 | |
| 4583 | // Iterate over the test scenarios. |
| 4584 | for (auto const& scenario : scenarios) { |
| 4585 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4585( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4585, (scenario.description_)); |
| 4586 | |
| 4587 | // If we have a MAC address this scenario is for a new client. |
| 4588 | if (!scenario.mac_.empty()) { |
| 4589 | 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_4589; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4589; } } else gtest_label_testnothrow_4589 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4589, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4590 | << "invalid MAC address, test is broken"; |
| 4591 | } |
| 4592 | |
| 4593 | // Create the client packet and the add RAI option (if one). |
| 4594 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4595 | if (!scenario.rai_data_.empty()) { |
| 4596 | std::vector<uint8_t> opt_data; |
| 4597 | 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_4597; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4597 ; } } else gtest_label_testnothrow_4597 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4597, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4598 | << "scenario.rai_data_ is invalid, test is broken"; |
| 4599 | OptionPtr rai; |
| 4600 | 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_4600; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4600; } } else gtest_label_testnothrow_4600 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4600, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4601 | << "could not create rai option, test is broken"; |
| 4602 | |
| 4603 | ctx.query_->addOption(rai); |
| 4604 | } |
| 4605 | |
| 4606 | // Create or renew the lease. |
| 4607 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4608 | 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" , 4608, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4609 | 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" , 4609, gtest_ar.failure_message()) = ::testing::Message(); |
| 4610 | |
| 4611 | // Verify the lease does not have user context content. |
| 4612 | 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" , 4612, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
| 4617 | // using cache threshold. |
| 4618 | TEST_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" , 4618), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4618), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4618), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheThreshold4_Test >); void AllocEngine4Test_discoverCacheThreshold4_Test::TestBody () { |
| 4619 | boost::scoped_ptr<AllocEngine> engine; |
| 4620 | 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_4620 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4620 ; } } else gtest_label_testnothrow_4620 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4620, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4621 | 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" , 4621, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4622 | |
| 4623 | // Set valid lifetime to 500. |
| 4624 | uint32_t valid = 500; |
| 4625 | subnet_->setValid(valid); |
| 4626 | |
| 4627 | // Set the threshold to 25%. |
| 4628 | subnet_->setCacheThreshold(.25); |
| 4629 | |
| 4630 | IOAddress addr("192.0.2.105"); |
| 4631 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4632 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4633 | valid, now, subnet_->getID())); |
| 4634 | 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" , 4634, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4635 | 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" , 4635, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4636 | |
| 4637 | // Create a context for fake allocation. |
| 4638 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4639 | false, false, "", true); |
| 4640 | |
| 4641 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4642 | lease = engine->allocateLease4(ctx); |
| 4643 | // Check that we got that single lease. |
| 4644 | 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" , 4644, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4645 | 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" , 4645, gtest_ar.failure_message()) = ::testing::Message(); |
| 4646 | |
| 4647 | // The lease was reused. |
| 4648 | time_t age = lease->cltt_ - now; |
| 4649 | 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" , 4649, gtest_ar.failure_message()) = ::testing::Message(); |
| 4650 | 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" , 4650, gtest_ar.failure_message()) = ::testing::Message(); |
| 4651 | 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" , 4651, gtest_ar.failure_message()) = ::testing::Message(); |
| 4652 | |
| 4653 | // Check other lease parameters. |
| 4654 | 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" , 4654, gtest_ar.failure_message()) = ::testing::Message(); |
| 4655 | 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" , 4655, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4656 | 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" , 4656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4657 | 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" , 4657, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4658 | 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" , 4658, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4659 | } |
| 4660 | |
| 4661 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
| 4662 | // using cache threshold. |
| 4663 | TEST_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" , 4663), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4663), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4663), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheThreshold4_Test >); void AllocEngine4Test_requestCacheThreshold4_Test::TestBody () { |
| 4664 | boost::scoped_ptr<AllocEngine> engine; |
| 4665 | 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_4665 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4665 ; } } else gtest_label_testnothrow_4665 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4665, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4666 | 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" , 4666, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4667 | |
| 4668 | // Set valid lifetime to 500. |
| 4669 | uint32_t valid = 500; |
| 4670 | subnet_->setValid(valid); |
| 4671 | |
| 4672 | // Set the threshold to 25%. |
| 4673 | subnet_->setCacheThreshold(.25); |
| 4674 | |
| 4675 | IOAddress addr("192.0.2.105"); |
| 4676 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4677 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4678 | valid, now, subnet_->getID())); |
| 4679 | 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" , 4679, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4680 | // Copy the lease, so as it can be compared with. |
| 4681 | Lease4Ptr original_lease(new Lease4(*lease)); |
| 4682 | 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" , 4682, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4683 | |
| 4684 | // Create a context for real allocation. |
| 4685 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4686 | false, false, "", false); |
| 4687 | |
| 4688 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4689 | lease = engine->allocateLease4(ctx); |
| 4690 | // Check that we got that single lease. |
| 4691 | 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" , 4691, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4692 | 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" , 4692, gtest_ar.failure_message()) = ::testing::Message(); |
| 4693 | |
| 4694 | // The lease was reused. |
| 4695 | time_t age = lease->cltt_ - now; |
| 4696 | 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" , 4696, gtest_ar.failure_message()) = ::testing::Message(); |
| 4697 | 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" , 4697, gtest_ar.failure_message()) = ::testing::Message(); |
| 4698 | 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" , 4698, gtest_ar.failure_message()) = ::testing::Message(); |
| 4699 | |
| 4700 | // Check other lease parameters. |
| 4701 | 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" , 4701, gtest_ar.failure_message()) = ::testing::Message(); |
| 4702 | 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" , 4702, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4703 | 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" , 4703, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4704 | 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" , 4704, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4705 | 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" , 4705, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4706 | |
| 4707 | // Check the lease was not updated in the database. |
| 4708 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4709 | 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" , 4709, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4710 | |
| 4711 | detailCompareLease(original_lease, from_mgr); |
| 4712 | } |
| 4713 | |
| 4714 | /// We proved that there is no different from the "cache" feature between |
| 4715 | /// discovers and request at the exception of the lease database update. |
| 4716 | |
| 4717 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
| 4718 | // using cache max age. |
| 4719 | TEST_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" , 4719), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4719), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4719), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheMaxAge4_Test >); void AllocEngine4Test_discoverCacheMaxAge4_Test::TestBody () { |
| 4720 | boost::scoped_ptr<AllocEngine> engine; |
| 4721 | 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_4721 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4721 ; } } else gtest_label_testnothrow_4721 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4721, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4722 | 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" , 4722, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4723 | |
| 4724 | // Set valid lifetime to 500. |
| 4725 | uint32_t valid = 500; |
| 4726 | subnet_->setValid(valid); |
| 4727 | |
| 4728 | // Set the max age to 200. |
| 4729 | subnet_->setCacheMaxAge(200); |
| 4730 | |
| 4731 | IOAddress addr("192.0.2.105"); |
| 4732 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4733 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4734 | valid, now, subnet_->getID())); |
| 4735 | 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" , 4735, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4736 | 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" , 4736, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4737 | |
| 4738 | // Create a context for fake allocation. |
| 4739 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4740 | false, false, "", true); |
| 4741 | |
| 4742 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4743 | lease = engine->allocateLease4(ctx); |
| 4744 | // Check that we got that single lease. |
| 4745 | 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" , 4745, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4746 | 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" , 4746, gtest_ar.failure_message()) = ::testing::Message(); |
| 4747 | |
| 4748 | // The lease was reused. |
| 4749 | time_t age = lease->cltt_ - now; |
| 4750 | 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" , 4750, gtest_ar.failure_message()) = ::testing::Message(); |
| 4751 | 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" , 4751, gtest_ar.failure_message()) = ::testing::Message(); |
| 4752 | 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" , 4752, gtest_ar.failure_message()) = ::testing::Message(); |
| 4753 | |
| 4754 | // Check other lease parameters. |
| 4755 | 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" , 4755, gtest_ar.failure_message()) = ::testing::Message(); |
| 4756 | 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" , 4756, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4757 | 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" , 4757, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4758 | 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" , 4758, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4759 | 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" , 4759, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4760 | } |
| 4761 | |
| 4762 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
| 4763 | // using both cache threshold and max age. |
| 4764 | TEST_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" , 4764), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4764), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4764), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBoth4_Test >); void AllocEngine4Test_requestCacheBoth4_Test::TestBody () { |
| 4765 | boost::scoped_ptr<AllocEngine> engine; |
| 4766 | 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_4766 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4766 ; } } else gtest_label_testnothrow_4766 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4766, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4767 | 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" , 4767, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4768 | |
| 4769 | // Set valid lifetime to 500. |
| 4770 | uint32_t valid = 500; |
| 4771 | subnet_->setValid(valid); |
| 4772 | |
| 4773 | // Set the threshold to 25%. |
| 4774 | subnet_->setCacheThreshold(.25); |
| 4775 | |
| 4776 | // Set the max age to 200. |
| 4777 | subnet_->setCacheMaxAge(200); |
| 4778 | |
| 4779 | IOAddress addr("192.0.2.105"); |
| 4780 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4781 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4782 | valid, now, subnet_->getID())); |
| 4783 | 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" , 4783, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4784 | // Copy the lease, so as it can be compared with. |
| 4785 | Lease4Ptr original_lease(new Lease4(*lease)); |
| 4786 | 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" , 4786, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4787 | |
| 4788 | // Create a context for real allocation. |
| 4789 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4790 | false, false, "", false); |
| 4791 | |
| 4792 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4793 | lease = engine->allocateLease4(ctx); |
| 4794 | // Check that we got that single lease. |
| 4795 | 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" , 4795, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4796 | 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" , 4796, gtest_ar.failure_message()) = ::testing::Message(); |
| 4797 | |
| 4798 | // The lease was reused. |
| 4799 | time_t age = lease->cltt_ - now; |
| 4800 | 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" , 4800, gtest_ar.failure_message()) = ::testing::Message(); |
| 4801 | 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" , 4801, gtest_ar.failure_message()) = ::testing::Message(); |
| 4802 | 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" , 4802, gtest_ar.failure_message()) = ::testing::Message(); |
| 4803 | |
| 4804 | // Check other lease parameters. |
| 4805 | 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" , 4805, gtest_ar.failure_message()) = ::testing::Message(); |
| 4806 | 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" , 4806, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4807 | 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" , 4807, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4808 | 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" , 4808, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4809 | 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" , 4809, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4810 | |
| 4811 | // Check the lease was not updated in the database. |
| 4812 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4813 | 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" , 4813, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4814 | |
| 4815 | detailCompareLease(original_lease, from_mgr); |
| 4816 | } |
| 4817 | |
| 4818 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
| 4819 | // using too small cache threshold. |
| 4820 | TEST_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" , 4820), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4820), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4820), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheBadThreshold4_Test >); void AllocEngine4Test_discoverCacheBadThreshold4_Test:: TestBody() { |
| 4821 | boost::scoped_ptr<AllocEngine> engine; |
| 4822 | 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_4822 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4822 ; } } else gtest_label_testnothrow_4822 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4822, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4823 | 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" , 4823, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4824 | |
| 4825 | // Set valid lifetime to 500. |
| 4826 | uint32_t valid = 500; |
| 4827 | subnet_->setValid(valid); |
| 4828 | |
| 4829 | // Set the threshold to 10%. |
| 4830 | subnet_->setCacheThreshold(.10); |
| 4831 | |
| 4832 | IOAddress addr("192.0.2.105"); |
| 4833 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4834 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4835 | valid, now, subnet_->getID())); |
| 4836 | 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" , 4836, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4837 | 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" , 4837, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4838 | |
| 4839 | // Create a context for fake allocation. |
| 4840 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4841 | false, false, "", true); |
| 4842 | |
| 4843 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4844 | lease = engine->allocateLease4(ctx); |
| 4845 | // Check that we got that single lease. |
| 4846 | 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" , 4846, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4847 | 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" , 4847, gtest_ar.failure_message()) = ::testing::Message(); |
| 4848 | |
| 4849 | // The lease was not reused. |
| 4850 | 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" , 4850, gtest_ar.failure_message()) = ::testing::Message(); |
| 4851 | } |
| 4852 | |
| 4853 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
| 4854 | // using too small cache max age. |
| 4855 | TEST_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" , 4855), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4855), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4855), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBadMaxAge4_Test >); void AllocEngine4Test_requestCacheBadMaxAge4_Test::TestBody () { |
| 4856 | boost::scoped_ptr<AllocEngine> engine; |
| 4857 | 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_4857 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4857 ; } } else gtest_label_testnothrow_4857 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4857, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4858 | 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" , 4858, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4859 | |
| 4860 | // Set valid lifetime to 500. |
| 4861 | uint32_t valid = 500; |
| 4862 | subnet_->setValid(valid); |
| 4863 | |
| 4864 | // Set the threshold to 25%. |
| 4865 | subnet_->setCacheThreshold(.25); |
| 4866 | |
| 4867 | // Set the max age to 50. |
| 4868 | subnet_->setCacheMaxAge(50); |
| 4869 | |
| 4870 | IOAddress addr("192.0.2.105"); |
| 4871 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4872 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4873 | valid, now, subnet_->getID())); |
| 4874 | 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" , 4874, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4875 | |
| 4876 | // Create a context for real allocation. |
| 4877 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4878 | false, false, "", false); |
| 4879 | |
| 4880 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4881 | lease = engine->allocateLease4(ctx); |
| 4882 | // Check that we got that single lease. |
| 4883 | 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" , 4883, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4884 | 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" , 4884, gtest_ar.failure_message()) = ::testing::Message(); |
| 4885 | |
| 4886 | // The lease was not reused. |
| 4887 | 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" , 4887, gtest_ar.failure_message()) = ::testing::Message(); |
| 4888 | |
| 4889 | // Check the lease was updated in the database. |
| 4890 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4891 | 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" , 4891, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4892 | |
| 4893 | detailCompareLease(lease, from_mgr); |
| 4894 | } |
| 4895 | |
| 4896 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
| 4897 | // when the valid lifetime was reduced. |
| 4898 | TEST_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" , 4898), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4898), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4898), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheReducedValid4_Test >); void AllocEngine4Test_discoverCacheReducedValid4_Test:: TestBody() { |
| 4899 | boost::scoped_ptr<AllocEngine> engine; |
| 4900 | 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_4900 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4900 ; } } else gtest_label_testnothrow_4900 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4900, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4901 | 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" , 4901, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4902 | |
| 4903 | // Set valid lifetime to 200. |
| 4904 | subnet_->setValid(200); |
| 4905 | |
| 4906 | // Set the threshold to 25%. |
| 4907 | subnet_->setCacheThreshold(.25); |
| 4908 | |
| 4909 | IOAddress addr("192.0.2.105"); |
| 4910 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4911 | uint32_t valid = 500; // Used a value greater than subnet_->getValid(). |
| 4912 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4913 | valid, now, subnet_->getID())); |
| 4914 | 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" , 4914, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4915 | 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" , 4915, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4916 | |
| 4917 | // Create a context for fake allocation. |
| 4918 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4919 | false, false, "", true); |
| 4920 | |
| 4921 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4922 | lease = engine->allocateLease4(ctx); |
| 4923 | // Check that we got that single lease. |
| 4924 | 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" , 4924, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4925 | 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" , 4925, gtest_ar.failure_message()) = ::testing::Message(); |
| 4926 | |
| 4927 | // The lease was not reused. |
| 4928 | 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" , 4928, gtest_ar.failure_message()) = ::testing::Message(); |
| 4929 | } |
| 4930 | |
| 4931 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
| 4932 | // when DDNS parameter changed. |
| 4933 | TEST_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" , 4933), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4933), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4933), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheFwdDDNS4_Test >); void AllocEngine4Test_requestCacheFwdDDNS4_Test::TestBody () { |
| 4934 | boost::scoped_ptr<AllocEngine> engine; |
| 4935 | 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_4935 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4935 ; } } else gtest_label_testnothrow_4935 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4935, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4936 | 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" , 4936, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4937 | |
| 4938 | // Set valid lifetime to 500. |
| 4939 | uint32_t valid = 500; |
| 4940 | subnet_->setValid(valid); |
| 4941 | |
| 4942 | // Set the max age to 200. |
| 4943 | subnet_->setCacheMaxAge(200); |
| 4944 | |
| 4945 | IOAddress addr("192.0.2.105"); |
| 4946 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4947 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4948 | valid, now, subnet_->getID())); |
| 4949 | 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" , 4949, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4950 | |
| 4951 | // Create a context for real allocation with fwd_dns_update changed. |
| 4952 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4953 | true, false, "", false); |
| 4954 | |
| 4955 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4956 | lease = engine->allocateLease4(ctx); |
| 4957 | // Check that we got that single lease. |
| 4958 | 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" , 4958, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4959 | 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" , 4959, gtest_ar.failure_message()) = ::testing::Message(); |
| 4960 | |
| 4961 | // The lease was not reused. |
| 4962 | 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" , 4962, gtest_ar.failure_message()) = ::testing::Message(); |
| 4963 | |
| 4964 | // Check the lease was updated in the database. |
| 4965 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4966 | 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" , 4966, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4967 | |
| 4968 | detailCompareLease(lease, from_mgr); |
| 4969 | } |
| 4970 | |
| 4971 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
| 4972 | // when DDNS parameter changed. |
| 4973 | TEST_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" , 4973), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4973), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4973), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheRevDDNS4_Test >); void AllocEngine4Test_discoverCacheRevDDNS4_Test::TestBody () { |
| 4974 | boost::scoped_ptr<AllocEngine> engine; |
| 4975 | 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_4975 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4975 ; } } else gtest_label_testnothrow_4975 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4975, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4976 | 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" , 4976, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4977 | |
| 4978 | // Set valid lifetime to 500. |
| 4979 | uint32_t valid = 500; |
| 4980 | subnet_->setValid(valid); |
| 4981 | |
| 4982 | // Set the threshold to 25%. |
| 4983 | subnet_->setCacheThreshold(.25); |
| 4984 | |
| 4985 | // Set the max age to 200. |
| 4986 | subnet_->setCacheMaxAge(200); |
| 4987 | |
| 4988 | IOAddress addr("192.0.2.105"); |
| 4989 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 4990 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4991 | valid, now, subnet_->getID())); |
| 4992 | 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" , 4992, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4993 | 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" , 4993, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4994 | |
| 4995 | // Create a context for fake allocation with rev_dns_update changed. |
| 4996 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4997 | false, true, "", true); |
| 4998 | |
| 4999 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5000 | lease = engine->allocateLease4(ctx); |
| 5001 | // Check that we got that single lease. |
| 5002 | 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" , 5002, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5003 | 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" , 5003, gtest_ar.failure_message()) = ::testing::Message(); |
| 5004 | |
| 5005 | // The lease was not reused. |
| 5006 | 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" , 5006, gtest_ar.failure_message()) = ::testing::Message(); |
| 5007 | } |
| 5008 | |
| 5009 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
| 5010 | // when hostname changed. |
| 5011 | TEST_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" , 5011), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5011), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5011), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheHostname4_Test >); void AllocEngine4Test_requestCacheHostname4_Test::TestBody () { |
| 5012 | boost::scoped_ptr<AllocEngine> engine; |
| 5013 | 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_5013 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5013 ; } } else gtest_label_testnothrow_5013 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5013, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5014 | 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" , 5014, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5015 | |
| 5016 | // Set valid lifetime to 500. |
| 5017 | uint32_t valid = 500; |
| 5018 | subnet_->setValid(valid); |
| 5019 | |
| 5020 | // Set the max age to 200. |
| 5021 | subnet_->setCacheMaxAge(200); |
| 5022 | |
| 5023 | IOAddress addr("192.0.2.105"); |
| 5024 | time_t now = time(0) - 100; // Allocated 100 seconds ago. |
| 5025 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 5026 | valid, now, subnet_->getID(), |
| 5027 | false, false, "foo")); |
| 5028 | 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" , 5028, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 5029 | |
| 5030 | // Create a context for real allocation with fwd_dns_update changed. |
| 5031 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 5032 | false, false, "bar", false); |
| 5033 | |
| 5034 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 5035 | lease = engine->allocateLease4(ctx); |
| 5036 | // Check that we got that single lease. |
| 5037 | 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" , 5037, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5038 | 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" , 5038, gtest_ar.failure_message()) = ::testing::Message(); |
| 5039 | |
| 5040 | // The lease was not reused. |
| 5041 | 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" , 5041, gtest_ar.failure_message()) = ::testing::Message(); |
| 5042 | 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" , 5042, gtest_ar.failure_message()) = ::testing::Message(); |
| 5043 | |
| 5044 | // Check the lease was updated in the database. |
| 5045 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 5046 | 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" , 5046, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5047 | |
| 5048 | detailCompareLease(lease, from_mgr); |
| 5049 | } |
| 5050 | |
| 5051 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
| 5052 | // lifetime value based on the context content. |
| 5053 | TEST_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", 5053 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5053), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5053), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getValidLft4_Test >); void AllocEngine4Test_getValidLft4_Test::TestBody() { |
| 5054 | AllocEngine engine(0); |
| 5055 | |
| 5056 | // Let's make three classes, two with valid-lifetime and one without, |
| 5057 | // and add them to the dictionary. |
| 5058 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 5059 | |
| 5060 | ClientClassDefPtr class_def(new ClientClassDef("valid_one", ExpressionPtr())); |
| 5061 | Triplet<uint32_t> valid_one(50, 100, 150); |
| 5062 | class_def->setValid(valid_one); |
| 5063 | dictionary->addClass(class_def); |
| 5064 | |
| 5065 | class_def.reset(new ClientClassDef("valid_two", ExpressionPtr())); |
| 5066 | Triplet<uint32_t>valid_two(200, 250, 300); |
| 5067 | class_def->setValid(valid_two); |
| 5068 | dictionary->addClass(class_def); |
| 5069 | |
| 5070 | class_def.reset(new ClientClassDef("valid_unspec", ExpressionPtr())); |
| 5071 | dictionary->addClass(class_def); |
| 5072 | |
| 5073 | // Commit our class changes. |
| 5074 | CfgMgr::instance().commit(); |
| 5075 | |
| 5076 | // Update the subnet's triplet to something more useful. |
| 5077 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
| 5078 | |
| 5079 | // Describes a test scenario. |
| 5080 | struct Scenario { |
| 5081 | std::string desc_; // descriptive text for logging |
| 5082 | std::vector<std::string> classes_; // class list of assigned classes |
| 5083 | uint32_t requested_lft_; // use as option 51 is > 0 |
| 5084 | uint32_t exp_valid_; // expected lifetime |
| 5085 | }; |
| 5086 | |
| 5087 | // Scenarios to test. |
| 5088 | std::vector<Scenario> scenarios = { |
| 5089 | { |
| 5090 | "BOOTP", |
| 5091 | { "BOOTP" }, |
| 5092 | 0, |
| 5093 | Lease::INFINITY_LFT |
| 5094 | }, |
| 5095 | { |
| 5096 | "no classes, no option", |
| 5097 | {}, |
| 5098 | 0, |
| 5099 | subnet_->getValid() |
| 5100 | }, |
| 5101 | { |
| 5102 | "no classes, option", |
| 5103 | {}, |
| 5104 | subnet_->getValid().getMin() + 50, |
| 5105 | subnet_->getValid().getMin() + 50 |
| 5106 | }, |
| 5107 | { |
| 5108 | "no classes, option too small", |
| 5109 | {}, |
| 5110 | subnet_->getValid().getMin() - 50, |
| 5111 | subnet_->getValid().getMin() |
| 5112 | }, |
| 5113 | { |
| 5114 | "no classes, option too big", |
| 5115 | {}, |
| 5116 | subnet_->getValid().getMax() + 50, |
| 5117 | subnet_->getValid().getMax() |
| 5118 | }, |
| 5119 | { |
| 5120 | "class unspecified, no option", |
| 5121 | { "valid_unspec" }, |
| 5122 | 0, |
| 5123 | subnet_->getValid() |
| 5124 | }, |
| 5125 | { |
| 5126 | "from last class, no option", |
| 5127 | { "valid_unspec", "valid_one" }, |
| 5128 | 0, |
| 5129 | valid_one.get() |
| 5130 | }, |
| 5131 | { |
| 5132 | "from first class, no option", |
| 5133 | { "valid_two", "valid_one" }, |
| 5134 | 0, |
| 5135 | valid_two.get() |
| 5136 | }, |
| 5137 | { |
| 5138 | "class plus option", |
| 5139 | { "valid_one" }, |
| 5140 | valid_one.getMin() + 25, |
| 5141 | valid_one.getMin() + 25 |
| 5142 | }, |
| 5143 | { |
| 5144 | "class plus option too small", |
| 5145 | { "valid_one" }, |
| 5146 | valid_one.getMin() - 25, |
| 5147 | valid_one.getMin() |
| 5148 | }, |
| 5149 | { |
| 5150 | "class plus option too big", |
| 5151 | { "valid_one" }, |
| 5152 | valid_one.getMax() + 25, |
| 5153 | valid_one.getMax() |
| 5154 | } |
| 5155 | }; |
| 5156 | |
| 5157 | // Iterate over the scenarios and verify the correct outcome. |
| 5158 | for (auto const& scenario : scenarios) { |
| 5159 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5159( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5159, (scenario.desc_)); { |
| 5160 | // Create a context; |
| 5161 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 5162 | IOAddress("0.0.0.0"), false, false, |
| 5163 | "", false); |
| 5164 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5165 | |
| 5166 | // Add client classes (if any) |
| 5167 | for (auto const& class_name : scenario.classes_) { |
| 5168 | ctx.query_->addClass(class_name); |
| 5169 | } |
| 5170 | |
| 5171 | // Add client option (if one) |
| 5172 | if (scenario.requested_lft_) { |
| 5173 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
| 5174 | scenario.requested_lft_)); |
| 5175 | ctx.query_->addOption(opt); |
| 5176 | } |
| 5177 | |
| 5178 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 5179 | 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" , 5179, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5180 | 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" , 5180, gtest_ar.failure_message()) = ::testing::Message(); |
| 5181 | } |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
| 5186 | // lifetime value based on the context content. |
| 5187 | TEST_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" , 5187), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5187), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5187), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getTemplateClassValidLft4_Test >); void AllocEngine4Test_getTemplateClassValidLft4_Test:: TestBody() { |
| 5188 | AllocEngine engine(0); |
| 5189 | |
| 5190 | // Let's make three classes, two with valid-lifetime and one without, |
| 5191 | // and add them to the dictionary. |
| 5192 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 5193 | ExpressionPtr match_expr; |
| 5194 | ExpressionParser parser; |
| 5195 | |
| 5196 | ElementPtr test_cfg = Element::create("'valid_one_value'"); |
| 5197 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5198 | |
| 5199 | ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr)); |
| 5200 | Triplet<uint32_t> valid_one(50, 100, 150); |
| 5201 | class_def->setValid(valid_one); |
| 5202 | dictionary->addClass(class_def); |
| 5203 | |
| 5204 | test_cfg = Element::create("'valid_two_value'"); |
| 5205 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5206 | |
| 5207 | class_def.reset(new TemplateClientClassDef("valid_two", match_expr)); |
| 5208 | Triplet<uint32_t>valid_two(200, 250, 300); |
| 5209 | class_def->setValid(valid_two); |
| 5210 | dictionary->addClass(class_def); |
| 5211 | |
| 5212 | test_cfg = Element::create("'valid_unspec_value'"); |
| 5213 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5214 | |
| 5215 | class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr)); |
| 5216 | dictionary->addClass(class_def); |
| 5217 | |
| 5218 | // Commit our class changes. |
| 5219 | CfgMgr::instance().commit(); |
| 5220 | |
| 5221 | // Update the subnet's triplet to something more useful. |
| 5222 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
| 5223 | |
| 5224 | // Describes a test scenario. |
| 5225 | struct Scenario { |
| 5226 | std::string desc_; // descriptive text for logging |
| 5227 | std::vector<std::string> classes_; // class list of assigned classes |
| 5228 | uint32_t requested_lft_; // use as option 51 is > 0 |
| 5229 | uint32_t exp_valid_; // expected lifetime |
| 5230 | }; |
| 5231 | |
| 5232 | // Scenarios to test. |
| 5233 | std::vector<Scenario> scenarios = { |
| 5234 | { |
| 5235 | "BOOTP", |
| 5236 | { "BOOTP" }, |
| 5237 | 0, |
| 5238 | Lease::INFINITY_LFT |
| 5239 | }, |
| 5240 | { |
| 5241 | "no classes, no option", |
| 5242 | {}, |
| 5243 | 0, |
| 5244 | subnet_->getValid() |
| 5245 | }, |
| 5246 | { |
| 5247 | "no classes, option", |
| 5248 | {}, |
| 5249 | subnet_->getValid().getMin() + 50, |
| 5250 | subnet_->getValid().getMin() + 50 |
| 5251 | }, |
| 5252 | { |
| 5253 | "no classes, option too small", |
| 5254 | {}, |
| 5255 | subnet_->getValid().getMin() - 50, |
| 5256 | subnet_->getValid().getMin() |
| 5257 | }, |
| 5258 | { |
| 5259 | "no classes, option too big", |
| 5260 | {}, |
| 5261 | subnet_->getValid().getMax() + 50, |
| 5262 | subnet_->getValid().getMax() |
| 5263 | }, |
| 5264 | { |
| 5265 | "class unspecified, no option", |
| 5266 | { "valid_unspec" }, |
| 5267 | 0, |
| 5268 | subnet_->getValid() |
| 5269 | }, |
| 5270 | { |
| 5271 | "from last class, no option", |
| 5272 | { "valid_unspec", "valid_one" }, |
| 5273 | 0, |
| 5274 | valid_one.get() |
| 5275 | }, |
| 5276 | { |
| 5277 | "from first class, no option", |
| 5278 | { "valid_two", "valid_one" }, |
| 5279 | 0, |
| 5280 | valid_two.get() |
| 5281 | }, |
| 5282 | { |
| 5283 | "class plus option", |
| 5284 | { "valid_one" }, |
| 5285 | valid_one.getMin() + 25, |
| 5286 | valid_one.getMin() + 25 |
| 5287 | }, |
| 5288 | { |
| 5289 | "class plus option too small", |
| 5290 | { "valid_one" }, |
| 5291 | valid_one.getMin() - 25, |
| 5292 | valid_one.getMin() |
| 5293 | }, |
| 5294 | { |
| 5295 | "class plus option too big", |
| 5296 | { "valid_one" }, |
| 5297 | valid_one.getMax() + 25, |
| 5298 | valid_one.getMax() |
| 5299 | } |
| 5300 | }; |
| 5301 | |
| 5302 | // Iterate over the scenarios and verify the correct outcome. |
| 5303 | for (auto const& scenario : scenarios) { |
| 5304 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5304( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5304, (scenario.desc_)); { |
| 5305 | // Create a context; |
| 5306 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 5307 | IOAddress("0.0.0.0"), false, false, |
| 5308 | "", false); |
| 5309 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5310 | |
| 5311 | // Add client classes (if any) |
| 5312 | for (auto const& class_name : scenario.classes_) { |
| 5313 | if (class_name == "BOOTP") { |
| 5314 | ctx.query_->addClass(class_name); |
| 5315 | } else { |
| 5316 | string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX); |
| 5317 | subclass += class_name; |
| 5318 | subclass += "_value"; |
| 5319 | ctx.query_->addSubClass(class_name, subclass); |
| 5320 | } |
| 5321 | } |
| 5322 | |
| 5323 | // Add client option (if one) |
| 5324 | if (scenario.requested_lft_) { |
| 5325 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
| 5326 | scenario.requested_lft_)); |
| 5327 | ctx.query_->addOption(opt); |
| 5328 | } |
| 5329 | |
| 5330 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 5331 | 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" , 5331, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5332 | 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" , 5332, gtest_ar.failure_message()) = ::testing::Message(); |
| 5333 | } |
| 5334 | } |
| 5335 | } |
| 5336 | |
| 5337 | // Verifies that AllocEngine::getMinValidLft(ctx4, valid) sets the appropriate |
| 5338 | // lifetime value based on the context content. |
| 5339 | TEST_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", 5339 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5339), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5339), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getMinValidLft4_Test >); void AllocEngine4Test_getMinValidLft4_Test::TestBody() { |
| 5340 | AllocEngine engine(0); |
| 5341 | |
| 5342 | // Let's make three classes, two with valid-lifetime and one without, |
| 5343 | // and add them to the dictionary. |
| 5344 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 5345 | ExpressionPtr match_expr; |
| 5346 | ExpressionParser parser; |
| 5347 | |
| 5348 | ElementPtr test_cfg = Element::create("'valid_one_value'"); |
| 5349 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5350 | |
| 5351 | ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr)); |
| 5352 | Triplet<uint32_t> valid_one(50, 100, 150); |
| 5353 | class_def->setValid(valid_one); |
| 5354 | dictionary->addClass(class_def); |
| 5355 | |
| 5356 | test_cfg = Element::create("'valid_two_value'"); |
| 5357 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5358 | |
| 5359 | class_def.reset(new TemplateClientClassDef("valid_two", match_expr)); |
| 5360 | Triplet<uint32_t>valid_two(200, 250, 300); |
| 5361 | class_def->setValid(valid_two); |
| 5362 | dictionary->addClass(class_def); |
| 5363 | |
| 5364 | test_cfg = Element::create("'valid_unspec_value'"); |
| 5365 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5366 | |
| 5367 | class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr)); |
| 5368 | dictionary->addClass(class_def); |
| 5369 | |
| 5370 | // Commit our class changes. |
| 5371 | CfgMgr::instance().commit(); |
| 5372 | |
| 5373 | // Update the subnet's triplet to something more useful. |
| 5374 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
| 5375 | |
| 5376 | // Describes a test scenario. |
| 5377 | struct Scenario { |
| 5378 | std::string desc_; // descriptive text for logging |
| 5379 | std::vector<std::string> classes_; // class list of assigned classes |
| 5380 | uint32_t requested_lft_; // use as option 51 is > 0 |
| 5381 | uint32_t remaining_lft_; // remaining lifime or 0 |
| 5382 | uint32_t exp_valid_; // expected lifetime |
| 5383 | }; |
| 5384 | |
| 5385 | // Scenarios to test. |
| 5386 | std::vector<Scenario> scenarios = { |
| 5387 | { |
| 5388 | "BOOTP", |
| 5389 | { "BOOTP" }, |
| 5390 | 0, |
| 5391 | 0, |
| 5392 | Lease::INFINITY_LFT |
| 5393 | }, |
| 5394 | { |
| 5395 | "no classes, no option, remain 0", |
| 5396 | {}, |
| 5397 | 0, |
| 5398 | 0, |
| 5399 | subnet_->getValid().getMin() |
| 5400 | }, |
| 5401 | { |
| 5402 | "no classes, no option, remain too small", |
| 5403 | {}, |
| 5404 | 0, |
| 5405 | 100, |
| 5406 | subnet_->getValid().getMin() |
| 5407 | }, |
| 5408 | { |
| 5409 | "no classes, no option, remain", |
| 5410 | {}, |
| 5411 | 0, |
| 5412 | 800, |
| 5413 | 800 |
| 5414 | }, |
| 5415 | { |
| 5416 | "no classes, option, remain 0", |
| 5417 | {}, |
| 5418 | 1000, |
| 5419 | 0, |
| 5420 | subnet_->getValid().getMin() |
| 5421 | }, |
| 5422 | { |
| 5423 | "class unspecified, no option, remain 0", |
| 5424 | { "valid_unspec" }, |
| 5425 | 0, |
| 5426 | 0, |
| 5427 | subnet_->getValid().getMin() |
| 5428 | }, |
| 5429 | { |
| 5430 | "from last class, no option, remain 0", |
| 5431 | { "valid_unspec", "valid_one" }, |
| 5432 | 0, |
| 5433 | 0, |
| 5434 | valid_one.getMin() |
| 5435 | }, |
| 5436 | { |
| 5437 | "from first class, no option, remain 0", |
| 5438 | { "valid_two", "valid_one" }, |
| 5439 | 0, |
| 5440 | 0, |
| 5441 | valid_two.getMin() |
| 5442 | }, |
| 5443 | { |
| 5444 | "class plus remain too small", |
| 5445 | { "valid_one" }, |
| 5446 | 0, |
| 5447 | 10, |
| 5448 | valid_one.getMin(), |
| 5449 | }, |
| 5450 | { |
| 5451 | "class plus remain", |
| 5452 | { "valid_one" }, |
| 5453 | 0, |
| 5454 | 100, |
| 5455 | 100 |
| 5456 | } |
| 5457 | }; |
| 5458 | |
| 5459 | // Iterate over the scenarios and verify the correct outcome. |
| 5460 | for (auto const& scenario : scenarios) { |
| 5461 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5461( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5461, (scenario.desc_)); { |
| 5462 | // Create a context; |
| 5463 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 5464 | IOAddress("0.0.0.0"), false, false, |
| 5465 | "", false); |
| 5466 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5467 | |
| 5468 | // Add client classes (if any) |
| 5469 | for (auto const& class_name : scenario.classes_) { |
| 5470 | if (class_name == "BOOTP") { |
| 5471 | ctx.query_->addClass(class_name); |
| 5472 | } else { |
| 5473 | string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX); |
| 5474 | subclass += class_name; |
| 5475 | subclass += "_value"; |
| 5476 | ctx.query_->addSubClass(class_name, subclass); |
| 5477 | } |
| 5478 | } |
| 5479 | |
| 5480 | // Add client option (if one) |
| 5481 | if (scenario.requested_lft_) { |
| 5482 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
| 5483 | scenario.requested_lft_)); |
| 5484 | ctx.query_->addOption(opt); |
| 5485 | } |
| 5486 | |
| 5487 | uint32_t valid = scenario.remaining_lft_; |
| 5488 | engine.getMinValidLft(ctx, valid); |
| 5489 | 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" , 5489, gtest_ar.failure_message()) = ::testing::Message(); |
| 5490 | } |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | // Verifies that AllocEngine::getRemaining retuns the remaining lifetime value. |
| 5495 | TEST_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", 5495 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5495), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5495), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getRemaining_Test >); void AllocEngine4Test_getRemaining_Test::TestBody() { |
| 5496 | // No Lease. |
| 5497 | uint32_t valid(1); |
| 5498 | Lease4Ptr lease; |
| 5499 | AllocEngine::getRemaining(lease, valid); |
| 5500 | 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" , 5500, gtest_ar.failure_message()) = ::testing::Message(); |
| 5501 | |
| 5502 | // Unexpected state. |
| 5503 | valid = 1; |
| 5504 | uint8_t hwaddr_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 5505 | HWAddrPtr hwaddr(new HWAddr(hwaddr_data, sizeof(hwaddr_data), HTYPE_ETHER)); |
| 5506 | uint8_t clientid[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 5507 | time_t now = time(0); |
| 5508 | lease.reset(new Lease4(IOAddress("192.0.2.100"), hwaddr, clientid, |
| 5509 | sizeof(clientid), 100, now, 1)); |
| 5510 | lease->state_ = Lease::STATE_DECLINED; |
| 5511 | AllocEngine::getRemaining(lease, valid); |
| 5512 | 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" , 5512, gtest_ar.failure_message()) = ::testing::Message(); |
| 5513 | |
| 5514 | // Infinite lifetime. |
| 5515 | lease->state_ = Lease::STATE_DEFAULT; |
| 5516 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
| 5517 | lease->valid_lft_ = lease->current_valid_lft_ = infinity_lft; |
| 5518 | AllocEngine::getRemaining(lease, valid); |
| 5519 | 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" , 5519, gtest_ar.failure_message()) = ::testing::Message(); |
| 5520 | |
| 5521 | // Time going backward. |
| 5522 | lease->cltt_ = lease->current_cltt_ = now + 100; |
| 5523 | lease->valid_lft_ = lease->current_valid_lft_ = 50; |
| 5524 | AllocEngine::getRemaining(lease, valid); |
| 5525 | 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" , 5525, gtest_ar.failure_message()) = ::testing::Message(); |
| 5526 | |
| 5527 | // Already expired. |
| 5528 | valid = 1; |
| 5529 | lease->cltt_ = lease->current_cltt_ = now - 100; |
| 5530 | AllocEngine::getRemaining(lease, valid); |
| 5531 | 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" , 5531, gtest_ar.failure_message()) = ::testing::Message(); |
| 5532 | |
| 5533 | // Valid case. |
| 5534 | now = time(0); |
| 5535 | lease->cltt_ = lease->current_cltt_ = now - 10; |
| 5536 | AllocEngine::getRemaining(lease, valid); |
| 5537 | 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" , 5537, gtest_ar.failure_message()) = ::testing::Message(); |
| 5538 | } |
| 5539 | |
| 5540 | // This test checks that deleteRelease handles BOOTP leases. |
| 5541 | TEST_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", 5541 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5541), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5541), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpDelete_Test >); void AllocEngine4Test_bootpDelete_Test::TestBody() { |
| 5542 | boost::scoped_ptr<AllocEngine> engine; |
| 5543 | 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_5543 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5543 ; } } else gtest_label_testnothrow_5543 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5543, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5544 | 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" , 5544, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5545 | |
| 5546 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 5547 | false, true, "somehost.example.com.", false); |
| 5548 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 5549 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 5550 | |
| 5551 | // Make the query a BOOTP one. |
| 5552 | ctx.query_->addClass("BOOTP"); |
| 5553 | |
| 5554 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5555 | // The new lease has been allocated, so the old lease should not exist. |
| 5556 | 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" , 5556, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 5557 | |
| 5558 | // Check that we got a lease |
| 5559 | 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" , 5559, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5560 | |
| 5561 | // Check that is belongs to the right subnet and client. |
| 5562 | 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" , 5562, gtest_ar.failure_message()) = ::testing::Message(); |
| 5563 | 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" , 5563, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 5564 | 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" , 5564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 5565 | 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" , 5565, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 5566 | 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" , 5566, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 5567 | 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" , 5567, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 5568 | 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" , 5568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 5569 | |
| 5570 | // Check the valid lifetime is infinite. |
| 5571 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
| 5572 | 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" , 5572, gtest_ar.failure_message()) = ::testing::Message(); |
| 5573 | |
| 5574 | // Check that the lease is indeed in LeaseMgr |
| 5575 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5576 | 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" , 5576, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5577 | |
| 5578 | // Now delete it. |
| 5579 | bool deleted = false; |
| 5580 | 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_5580; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5580; } } else gtest_label_testnothrow_5580 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5580, ("Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 5581 | 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", 5581, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "deleted", "false", "true") .c_str()) = ::testing::Message( ); |
| 5582 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5583 | 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", 5583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "true", "false") .c_str()) = ::testing::Message (); |
| 5584 | } |
| 5585 | |
| 5586 | // This test verifies that all addresses in a pool can be allocated. |
| 5587 | TEST_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", 5587 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5587), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5587), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullPool_Test >); void AllocEngine4Test_fullPool_Test::TestBody() { |
| 5588 | boost::scoped_ptr<AllocEngine> engine; |
| 5589 | 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_5589 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5589 ; } } else gtest_label_testnothrow_5589 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5589, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5590 | 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" , 5590, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5591 | |
| 5592 | // Get rid of the default subnet configuration. |
| 5593 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5594 | cfg_mgr.clear(); |
| 5595 | |
| 5596 | // Configure a larger subnet with a /24 pool. |
| 5597 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5598 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5599 | subnet_->addPool(pool_); |
| 5600 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5601 | |
| 5602 | // Set exclude-first-last to false. |
| 5603 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
| 5604 | cfg_mgr.commit(); |
| 5605 | |
| 5606 | size_t cnt = 0; |
| 5607 | vector<bool> found(256, false); |
| 5608 | while (true) { |
| 5609 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5610 | duid[6] = cnt >> 8; |
| 5611 | duid[7] = cnt & 0xff; |
| 5612 | ClientIdPtr clientid(new ClientId(duid)); |
| 5613 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5614 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5615 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5616 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5617 | IOAddress("0.0.0.0"), |
| 5618 | false, false, "foo.bar", false); |
| 5619 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5620 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5621 | |
| 5622 | if (!lease) { |
| 5623 | break; |
| 5624 | } |
| 5625 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5626 | 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" , 5626, gtest_ar.failure_message()) = ::testing::Message(); |
| 5627 | 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" , 5627, gtest_ar.failure_message()) = ::testing::Message(); |
| 5628 | 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" , 5628, gtest_ar.failure_message()) = ::testing::Message(); |
| 5629 | 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" , 5629, gtest_ar.failure_message()) = ::testing::Message(); |
| 5630 | 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" , 5630, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5631 | found[addr[3]] = true; |
| 5632 | ++cnt; |
| 5633 | // Catch unbound loop. |
| 5634 | 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" , 5634, gtest_ar.failure_message()) = ::testing::Message(); |
| 5635 | } |
| 5636 | 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" , 5636, gtest_ar.failure_message()) = ::testing::Message(); |
| 5637 | 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" , 5637, gtest_ar.failure_message()) = ::testing::Message(); |
| 5638 | } |
| 5639 | |
| 5640 | // This test verifies that all addresses in a subnet can be allocated. |
| 5641 | TEST_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", 5641 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5641), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5641), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullSubnet24_Test >); void AllocEngine4Test_fullSubnet24_Test::TestBody() { |
| 5642 | boost::scoped_ptr<AllocEngine> engine; |
| 5643 | 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_5643 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5643 ; } } else gtest_label_testnothrow_5643 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5643, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5644 | 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" , 5644, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5645 | |
| 5646 | // Get rid of the default subnet configuration. |
| 5647 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5648 | cfg_mgr.clear(); |
| 5649 | |
| 5650 | // Configure a larger subnet with a /24 pool. |
| 5651 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 5652 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
| 5653 | IOAddress("192.0.2.255"))); |
| 5654 | subnet_->addPool(pool_); |
| 5655 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5656 | |
| 5657 | // Set exclude-first-last to false. |
| 5658 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
| 5659 | cfg_mgr.commit(); |
| 5660 | |
| 5661 | size_t cnt = 0; |
| 5662 | vector<bool> found(256, false); |
| 5663 | while (true) { |
| 5664 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5665 | duid[6] = cnt >> 8; |
| 5666 | duid[7] = cnt & 0xff; |
| 5667 | ClientIdPtr clientid(new ClientId(duid)); |
| 5668 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5669 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5670 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5671 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5672 | IOAddress("0.0.0.0"), |
| 5673 | false, false, "foo.bar", false); |
| 5674 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5675 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5676 | |
| 5677 | if (!lease) { |
| 5678 | break; |
| 5679 | } |
| 5680 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5681 | 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" , 5681, gtest_ar.failure_message()) = ::testing::Message(); |
| 5682 | 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" , 5682, gtest_ar.failure_message()) = ::testing::Message(); |
| 5683 | 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" , 5683, gtest_ar.failure_message()) = ::testing::Message(); |
| 5684 | 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" , 5684, gtest_ar.failure_message()) = ::testing::Message(); |
| 5685 | 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" , 5685, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5686 | found[addr[3]] = true; |
| 5687 | ++cnt; |
| 5688 | // Catch unbound loop. |
| 5689 | 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" , 5689, gtest_ar.failure_message()) = ::testing::Message(); |
| 5690 | } |
| 5691 | 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" , 5691, gtest_ar.failure_message()) = ::testing::Message(); |
| 5692 | 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" , 5692, gtest_ar.failure_message()) = ::testing::Message(); |
| 5693 | } |
| 5694 | |
| 5695 | // This test verifies that not all addresses in a pool can be allocated when |
| 5696 | // exclude-first-last is true. |
| 5697 | TEST_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" , 5697), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5697), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5697), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast_Test >); void AllocEngine4Test_excludeFirstLast_Test::TestBody( ) { |
| 5698 | boost::scoped_ptr<AllocEngine> engine; |
| 5699 | 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_5699 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5699 ; } } else gtest_label_testnothrow_5699 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5699, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5700 | 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" , 5700, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5701 | |
| 5702 | // Get rid of the default subnet configuration. |
| 5703 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5704 | cfg_mgr.clear(); |
| 5705 | |
| 5706 | // Configure a larger subnet with a /24 pool. |
| 5707 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5708 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5709 | subnet_->addPool(pool_); |
| 5710 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5711 | |
| 5712 | // Set exclude-first-last to true. |
| 5713 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5714 | cfg_mgr.commit(); |
| 5715 | |
| 5716 | size_t cnt = 0; |
| 5717 | vector<bool> found(256, false); |
| 5718 | while (true) { |
| 5719 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5720 | duid[6] = cnt >> 8; |
| 5721 | duid[7] = cnt & 0xff; |
| 5722 | ClientIdPtr clientid(new ClientId(duid)); |
| 5723 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5724 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5725 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5726 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5727 | IOAddress("0.0.0.0"), |
| 5728 | false, false, "foo.bar", false); |
| 5729 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5730 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5731 | |
| 5732 | if (!lease) { |
| 5733 | break; |
| 5734 | } |
| 5735 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5736 | 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" , 5736, gtest_ar.failure_message()) = ::testing::Message(); |
| 5737 | 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" , 5737, gtest_ar.failure_message()) = ::testing::Message(); |
| 5738 | 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" , 5738, gtest_ar.failure_message()) = ::testing::Message(); |
| 5739 | 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" , 5739, gtest_ar.failure_message()) = ::testing::Message(); |
| 5740 | 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" , 5740, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5741 | found[addr[3]] = true; |
| 5742 | ++cnt; |
| 5743 | // Catch unbound loop. |
| 5744 | 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" , 5744, gtest_ar.failure_message()) = ::testing::Message(); |
| 5745 | } |
| 5746 | 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" , 5746, gtest_ar.failure_message()) = ::testing::Message(); |
| 5747 | vector<bool> expected(256, true); |
| 5748 | expected[0] = false; |
| 5749 | expected[255] = false; |
| 5750 | 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" , 5750, gtest_ar.failure_message()) = ::testing::Message(); |
| 5751 | } |
| 5752 | |
| 5753 | // This test verifies that not all addresses in a subnet can be allocated when |
| 5754 | // exclude-first-last is true. |
| 5755 | TEST_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" , 5755), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5755), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5755), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast24_Test >); void AllocEngine4Test_excludeFirstLast24_Test::TestBody () { |
| 5756 | boost::scoped_ptr<AllocEngine> engine; |
| 5757 | 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_5757 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5757 ; } } else gtest_label_testnothrow_5757 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5757, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5758 | 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" , 5758, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5759 | |
| 5760 | // Get rid of the default subnet configuration. |
| 5761 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5762 | cfg_mgr.clear(); |
| 5763 | |
| 5764 | // Configure a larger subnet with a /24 pool. |
| 5765 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 5766 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
| 5767 | IOAddress("192.0.2.255"))); |
| 5768 | subnet_->addPool(pool_); |
| 5769 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5770 | |
| 5771 | // Set exclude-first-last to true. |
| 5772 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5773 | cfg_mgr.commit(); |
| 5774 | |
| 5775 | size_t cnt = 0; |
| 5776 | vector<bool> found(256, false); |
| 5777 | while (true) { |
| 5778 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5779 | duid[6] = cnt >> 8; |
| 5780 | duid[7] = cnt & 0xff; |
| 5781 | ClientIdPtr clientid(new ClientId(duid)); |
| 5782 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5783 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5784 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5785 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5786 | IOAddress("0.0.0.0"), |
| 5787 | false, false, "foo.bar", false); |
| 5788 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5789 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5790 | |
| 5791 | if (!lease) { |
| 5792 | break; |
| 5793 | } |
| 5794 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5795 | 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" , 5795, gtest_ar.failure_message()) = ::testing::Message(); |
| 5796 | 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" , 5796, gtest_ar.failure_message()) = ::testing::Message(); |
| 5797 | 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" , 5797, gtest_ar.failure_message()) = ::testing::Message(); |
| 5798 | 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" , 5798, gtest_ar.failure_message()) = ::testing::Message(); |
| 5799 | 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" , 5799, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5800 | found[addr[3]] = true; |
| 5801 | ++cnt; |
| 5802 | // Catch unbound loop. |
| 5803 | 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" , 5803, gtest_ar.failure_message()) = ::testing::Message(); |
| 5804 | } |
| 5805 | 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" , 5805, gtest_ar.failure_message()) = ::testing::Message(); |
| 5806 | vector<bool> expected(256, true); |
| 5807 | expected[0] = false; |
| 5808 | expected[255] = false; |
| 5809 | 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" , 5809, gtest_ar.failure_message()) = ::testing::Message(); |
| 5810 | } |
| 5811 | |
| 5812 | // This test verifies that all addresses in a subnet can be allocated when |
| 5813 | // exclude-first-last is true but the prefix length is greater than 24. |
| 5814 | TEST_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", 5814 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5814), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5814), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirst25_Test >); void AllocEngine4Test_excludeFirst25_Test::TestBody() { |
| 5815 | boost::scoped_ptr<AllocEngine> engine; |
| 5816 | 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_5816 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5816 ; } } else gtest_label_testnothrow_5816 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5816, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5817 | 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" , 5817, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5818 | |
| 5819 | // Get rid of the default subnet configuration. |
| 5820 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5821 | cfg_mgr.clear(); |
| 5822 | |
| 5823 | // Configure a smaller subnet with a /25 pool. |
| 5824 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 25, 1, 2, 3, SubnetID(10)); |
| 5825 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
| 5826 | IOAddress("192.0.2.127"))); |
| 5827 | subnet_->addPool(pool_); |
| 5828 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5829 | |
| 5830 | // Set exclude-first-last to true. |
| 5831 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5832 | cfg_mgr.commit(); |
| 5833 | |
| 5834 | size_t cnt = 0; |
| 5835 | vector<bool> found(128, false); |
| 5836 | while (true) { |
| 5837 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5838 | duid[6] = cnt >> 8; |
| 5839 | duid[7] = cnt & 0xff; |
| 5840 | ClientIdPtr clientid(new ClientId(duid)); |
| 5841 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5842 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5843 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5844 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5845 | IOAddress("0.0.0.0"), |
| 5846 | false, false, "foo.bar", false); |
| 5847 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5848 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5849 | |
| 5850 | if (!lease) { |
| 5851 | break; |
| 5852 | } |
| 5853 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5854 | 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" , 5854, gtest_ar.failure_message()) = ::testing::Message(); |
| 5855 | 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" , 5855, gtest_ar.failure_message()) = ::testing::Message(); |
| 5856 | 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" , 5856, gtest_ar.failure_message()) = ::testing::Message(); |
| 5857 | 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" , 5857, gtest_ar.failure_message()) = ::testing::Message(); |
| 5858 | 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" , 5858, gtest_ar.failure_message()) = ::testing::Message(); |
| 5859 | 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" , 5859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5860 | found[addr[3]] = true; |
| 5861 | ++cnt; |
| 5862 | // Catch unbound loop. |
| 5863 | 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" , 5863, gtest_ar.failure_message()) = ::testing::Message(); |
| 5864 | } |
| 5865 | 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" , 5865, gtest_ar.failure_message()) = ::testing::Message(); |
| 5866 | 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" , 5866, gtest_ar.failure_message()) = ::testing::Message(); |
| 5867 | } |
| 5868 | |
| 5869 | // This test verifies that all addresses in a subnet can be allocated when |
| 5870 | // exclude-first-last is true but the prefix length is greater than 24. |
| 5871 | TEST_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", 5871 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5871), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5871), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeLast25_Test >); void AllocEngine4Test_excludeLast25_Test::TestBody() { |
| 5872 | boost::scoped_ptr<AllocEngine> engine; |
| 5873 | 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_5873 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5873 ; } } else gtest_label_testnothrow_5873 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5873, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5874 | 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" , 5874, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5875 | |
| 5876 | // Get rid of the default subnet configuration. |
| 5877 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5878 | cfg_mgr.clear(); |
| 5879 | |
| 5880 | // Configure a smaller subnet with a /25 pool. |
| 5881 | subnet_ = Subnet4::create(IOAddress("192.0.2.128"), 25, 1, 2, 3, SubnetID(10)); |
| 5882 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.128"), |
| 5883 | IOAddress("192.0.2.255"))); |
| 5884 | subnet_->addPool(pool_); |
| 5885 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5886 | |
| 5887 | // Set exclude-first-last to true. |
| 5888 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5889 | cfg_mgr.commit(); |
| 5890 | |
| 5891 | size_t cnt = 0; |
| 5892 | vector<bool> found(128, false); |
| 5893 | while (true) { |
| 5894 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5895 | duid[6] = cnt >> 8; |
| 5896 | duid[7] = cnt & 0xff; |
| 5897 | ClientIdPtr clientid(new ClientId(duid)); |
| 5898 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5899 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5900 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5901 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5902 | IOAddress("0.0.0.0"), |
| 5903 | false, false, "foo.bar", false); |
| 5904 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5905 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5906 | |
| 5907 | if (!lease) { |
| 5908 | break; |
| 5909 | } |
| 5910 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5911 | 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" , 5911, gtest_ar.failure_message()) = ::testing::Message(); |
| 5912 | 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" , 5912, gtest_ar.failure_message()) = ::testing::Message(); |
| 5913 | 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" , 5913, gtest_ar.failure_message()) = ::testing::Message(); |
| 5914 | 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" , 5914, gtest_ar.failure_message()) = ::testing::Message(); |
| 5915 | 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" , 5915, gtest_ar.failure_message()) = ::testing::Message(); |
| 5916 | 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" , 5916, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3] - 128]", "true", "false") .c_str()) = ::testing ::Message(); |
| 5917 | found[addr[3] - 128] = true; |
| 5918 | ++cnt; |
| 5919 | // Catch unbound loop. |
| 5920 | 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" , 5920, gtest_ar.failure_message()) = ::testing::Message(); |
| 5921 | } |
| 5922 | 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" , 5922, gtest_ar.failure_message()) = ::testing::Message(); |
| 5923 | 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" , 5923, gtest_ar.failure_message()) = ::testing::Message(); |
| 5924 | } |
| 5925 | |
| 5926 | // This test verifies that an excluded address can be allocated when requested |
| 5927 | // and exclude-first-last is true. |
| 5928 | TEST_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" , 5928), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5928), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5928), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastRequested_Test >); void AllocEngine4Test_excludeFirstLastRequested_Test:: TestBody() { |
| 5929 | boost::scoped_ptr<AllocEngine> engine; |
| 5930 | 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_5930 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5930 ; } } else gtest_label_testnothrow_5930 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5930, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5931 | 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" , 5931, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5932 | |
| 5933 | // Get rid of the default subnet configuration. |
| 5934 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5935 | cfg_mgr.clear(); |
| 5936 | |
| 5937 | // Configure a larger subnet with a /24 pool. |
| 5938 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5939 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5940 | subnet_->addPool(pool_); |
| 5941 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5942 | |
| 5943 | // Set exclude-first-last to true. |
| 5944 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5945 | cfg_mgr.commit(); |
| 5946 | |
| 5947 | // Request the first address. |
| 5948 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 5949 | IOAddress("10.0.1.0"), |
| 5950 | false, false, "foo.bar", false); |
| 5951 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 5952 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5953 | 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" , 5953, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5954 | 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" , 5954, gtest_ar.failure_message()) = ::testing::Message(); |
| 5955 | |
| 5956 | // Request the last address. |
| 5957 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
| 5958 | IOAddress("10.0.1.255"), |
| 5959 | false, false, "bar.foo", false); |
| 5960 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
| 5961 | lease = engine->allocateLease4(ctx2); |
| 5962 | 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" , 5962, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5963 | 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" , 5963, gtest_ar.failure_message()) = ::testing::Message(); |
| 5964 | } |
| 5965 | |
| 5966 | // This test verifies that an excluded address can be allocated when reserved |
| 5967 | // and exclude-first-last is true. |
| 5968 | TEST_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" , 5968), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5968), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5968), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastReserver_Test >); void AllocEngine4Test_excludeFirstLastReserver_Test::TestBody () { |
| 5969 | boost::scoped_ptr<AllocEngine> engine; |
| 5970 | 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_5970 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5970 ; } } else gtest_label_testnothrow_5970 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5970, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5971 | 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" , 5971, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5972 | |
| 5973 | // Get rid of the default subnet configuration. |
| 5974 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5975 | cfg_mgr.clear(); |
| 5976 | |
| 5977 | // Configure a larger subnet with a /24 pool. |
| 5978 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5979 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5980 | subnet_->addPool(pool_); |
| 5981 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5982 | |
| 5983 | // Set exclude-first-last to true. |
| 5984 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5985 | |
| 5986 | // Add reservations. |
| 5987 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 5988 | Host::IDENT_HWADDR, subnet_->getID(), |
| 5989 | SUBNET_ID_UNUSED, IOAddress("10.0.1.0"))); |
| 5990 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host); |
| 5991 | HostPtr host2(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
| 5992 | Host::IDENT_HWADDR, subnet_->getID(), |
| 5993 | SUBNET_ID_UNUSED, IOAddress("10.0.1.255"))); |
| 5994 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host2); |
| 5995 | subnet_->setReservationsInSubnet(true); |
| 5996 | subnet_->setReservationsOutOfPool(false); |
| 5997 | cfg_mgr.commit(); |
| 5998 | |
| 5999 | // Request the first address. |
| 6000 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 6001 | IOAddress("0.0.0.0"), |
| 6002 | false, false, "foo.bar", false); |
| 6003 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 6004 | AllocEngine::findReservation(ctx); |
| 6005 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 6006 | 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" , 6006, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6007 | 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" , 6007, gtest_ar.failure_message()) = ::testing::Message(); |
| 6008 | |
| 6009 | // Request the last address. |
| 6010 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
| 6011 | IOAddress("0.0.0.0"), |
| 6012 | false, false, "bar.foo", false); |
| 6013 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
| 6014 | AllocEngine::findReservation(ctx2); |
| 6015 | lease = engine->allocateLease4(ctx2); |
| 6016 | 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" , 6016, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6017 | 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" , 6017, gtest_ar.failure_message()) = ::testing::Message(); |
| 6018 | } |
| 6019 | |
| 6020 | // Verifies that offer_lft is non-zero, that an offered lease is stored |
| 6021 | // in the lease database. |
| 6022 | TEST_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" , 6022), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6022), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6022), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLft_Test >); void AllocEngine4Test_discoverOfferLft_Test::TestBody( ) { |
| 6023 | boost::scoped_ptr<AllocEngine> engine; |
| 6024 | 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_6024 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6024 ; } } else gtest_label_testnothrow_6024 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6024, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 6025 | 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" , 6025, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 6026 | |
| 6027 | IOAddress addr("192.0.2.15"); |
| 6028 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 6029 | // Get rid of the default test configuration. |
| 6030 | cfg_mgr.clear(); |
| 6031 | |
| 6032 | // Create configuration similar to other tests, but with a single address pool |
| 6033 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 6034 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 6035 | subnet_->addPool(pool_); |
| 6036 | |
| 6037 | // Set subnet's offer-lifetime to a non-zero, positive value. |
| 6038 | uint32_t offer_lft = (subnet_->getValid() / 3); |
| 6039 | subnet_->setOfferLft(offer_lft); |
| 6040 | 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" , 6040, gtest_ar.failure_message()) = ::testing::Message(); |
| 6041 | |
| 6042 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 6043 | |
| 6044 | // Ask for any address |
| 6045 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 6046 | IOAddress("0.0.0.0"), true, true, |
| 6047 | "one", true); |
| 6048 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 6049 | |
| 6050 | // Check that we got that single lease |
| 6051 | Lease4Ptr lease = engine->allocateLease4(ctx1); |
| 6052 | 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" , 6052, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6053 | 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" , 6053, gtest_ar.failure_message()) = ::testing::Message(); |
| 6054 | 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" , 6054, gtest_ar.failure_message()) = ::testing::Message(); |
| 6055 | 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" , 6055, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6056 | 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" , 6056, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6057 | |
| 6058 | // Check that the lease has been stored by LeaseMgr. |
| 6059 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 6060 | 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" , 6060, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 6061 | 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" , 6061, gtest_ar.failure_message()) = ::testing::Message(); |
| 6062 | 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" , 6062, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6063 | 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" , 6063, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6064 | |
| 6065 | // Try to discover an address for a second client. |
| 6066 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 6067 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 6068 | |
| 6069 | // Ask for any address. |
| 6070 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, |
| 6071 | IOAddress("0.0.0.0"), true, true, |
| 6072 | "two", true); |
| 6073 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1235)); |
| 6074 | |
| 6075 | // Verify that we did not get a lease. |
| 6076 | lease = engine->allocateLease4(ctx2); |
| 6077 | 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" , 6077, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 6078 | |
| 6079 | // Original client now does a DHCPREQUEST. Make sure we get the |
| 6080 | // previously offered lease with the proper valid lifetime. |
| 6081 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
| 6082 | IOAddress("0.0.0.0"), true, true, |
| 6083 | "one", false); |
| 6084 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1236)); |
| 6085 | |
| 6086 | lease = engine->allocateLease4(ctx3); |
| 6087 | 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" , 6087, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6088 | 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" , 6088, gtest_ar.failure_message()) = ::testing::Message(); |
| 6089 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 6090 | 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" , 6090, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 6091 | 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" , 6091, gtest_ar.failure_message()) = ::testing::Message(); |
| 6092 | } |
| 6093 | |
| 6094 | // Verifies that when offer_lft is non-zero, that an existing lease is |
| 6095 | // whose remaining life is larger than offer_lft, is offered as is. |
| 6096 | TEST_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" , 6096), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6096), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6096), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftUseExistingLease4_Test >); void AllocEngine4Test_discoverOfferLftUseExistingLease4_Test ::TestBody() { |
| 6097 | boost::scoped_ptr<AllocEngine> engine; |
| 6098 | 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_6098 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6098 ; } } else gtest_label_testnothrow_6098 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6098, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 6099 | 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" , 6099, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 6100 | |
| 6101 | IOAddress addr("192.0.2.15"); |
| 6102 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 6103 | // Get rid of the default test configuration. |
| 6104 | cfg_mgr.clear(); |
| 6105 | |
| 6106 | // Create configuration similar to other tests, but with a single address pool |
| 6107 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 300, SubnetID(10)); |
| 6108 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 6109 | subnet_->addPool(pool_); |
| 6110 | |
| 6111 | // Set subnet's offer-lifetime to a non-zero, positive value. |
| 6112 | uint32_t offer_lft = 100; |
| 6113 | subnet_->setOfferLft(offer_lft); |
| 6114 | 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" , 6114, gtest_ar.failure_message()) = ::testing::Message(); |
| 6115 | |
| 6116 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 6117 | |
| 6118 | time_t now = time(0) - 5; // Allocated 5 seconds ago |
| 6119 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, 300, now, |
| 6120 | subnet_->getID(), true, true, "somehost")); |
| 6121 | |
| 6122 | // Copy the lease, so as it can be compared with the old lease returned |
| 6123 | // by the allocation engine. |
| 6124 | Lease4 original_lease(*lease); |
| 6125 | |
| 6126 | // Lease was assigned 5 seconds ago, its valid lifetime is 300, its |
| 6127 | // remaining lifetime is still larger than offer_lft. |
| 6128 | 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" , 6128, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 6129 | 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" , 6129, gtest_ar.failure_message()) = ::testing::Message(); |
| 6130 | 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" , 6130, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 6131 | |
| 6132 | // CASE 1: Asking for any address |
| 6133 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 6134 | IOAddress("0.0.0.0"), false, false, |
| 6135 | "", true); |
| 6136 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 6137 | lease = engine->allocateLease4(ctx1); |
| 6138 | // Check that we got that single lease |
| 6139 | 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" , 6139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6140 | 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" , 6140, gtest_ar.failure_message()) = ::testing::Message(); |
| 6141 | 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" , 6141, gtest_ar.failure_message()) = ::testing::Message(); |
| 6142 | |
| 6143 | // We are reusing the existing lease, the old instance should be |
| 6144 | // returned. The returned instance should be the same as the original |
| 6145 | // lease. |
| 6146 | 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" , 6146, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 6147 | 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" , 6147, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
| 6148 | |
| 6149 | // Check that the lease has not been modified by LeaseMgr. |
| 6150 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 6151 | 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" , 6151, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 6152 | 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" , 6152, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *from_mgr", "false", "true") .c_str()) = ::testing::Message(); |
| 6153 | } |
| 6154 | |
| 6155 | // Verifies that when offer_lft is non-zero, that an expired lease can |
| 6156 | // be reclaimed an offered correctly. |
| 6157 | TEST_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" , 6157), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6157), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6157), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test >); void AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test ::TestBody() { |
| 6158 | boost::scoped_ptr<AllocEngine> engine; |
| 6159 | 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_6159 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6159 ; } } else gtest_label_testnothrow_6159 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6159, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 6160 | 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" , 6160, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 6161 | |
| 6162 | IOAddress addr("192.0.2.15"); |
| 6163 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 6164 | // Get rid of the default test configuration. |
| 6165 | cfg_mgr.clear(); |
| 6166 | |
| 6167 | // Create configuration similar to other tests, but with a single address pool |
| 6168 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 6169 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 6170 | subnet_->addPool(pool_); |
| 6171 | |
| 6172 | // Set subnet's offer-lifetime to a non-zero, positive value. |
| 6173 | uint32_t offer_lft = (subnet_->getValid() / 3); |
| 6174 | subnet_->setOfferLft(offer_lft); |
| 6175 | 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" , 6175, gtest_ar.failure_message()) = ::testing::Message(); |
| 6176 | |
| 6177 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 6178 | |
| 6179 | // Just a different hw/client-id for the second client |
| 6180 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 6181 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 6182 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 6183 | time_t now = time(0) - 500; // Allocated 500 seconds ago |
| 6184 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 6185 | 495, now, subnet_->getID())); |
| 6186 | // Copy the lease, so as it can be compared with the old lease returned |
| 6187 | // by the allocation engine. |
| 6188 | Lease4 original_lease(*lease); |
| 6189 | |
| 6190 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 6191 | // is expired already |
| 6192 | 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" , 6192, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 6193 | 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" , 6193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 6194 | |
| 6195 | // CASE 1: Asking for any address |
| 6196 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 6197 | IOAddress("0.0.0.0"), false, false, |
| 6198 | "", true); |
| 6199 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 6200 | lease = engine->allocateLease4(ctx1); |
| 6201 | // Check that we got that single lease |
| 6202 | 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" , 6202, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6203 | 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" , 6203, gtest_ar.failure_message()) = ::testing::Message(); |
| 6204 | 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" , 6204, gtest_ar.failure_message()) = ::testing::Message(); |
| 6205 | 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" , 6205, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6206 | 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" , 6206, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6207 | |
| 6208 | // We are reusing expired lease, the old (expired) instance should be |
| 6209 | // returned. The returned instance should be the same as the original |
| 6210 | // lease. |
| 6211 | 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" , 6211, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 6212 | 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" , 6212, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
| 6213 | |
| 6214 | // Check that the lease has been stored by LeaseMgr. |
| 6215 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 6216 | 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" , 6216, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 6217 | 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" , 6217, gtest_ar.failure_message()) = ::testing::Message(); |
| 6218 | 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" , 6218, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6219 | 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" , 6219, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 6220 | |
| 6221 | // Client now does a DHCPREQUEST. Make sure we get the |
| 6222 | // previously offered lease with the proper valid lifetime. |
| 6223 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 6224 | IOAddress("0.0.0.0"), true, true, |
| 6225 | "one", false); |
| 6226 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1235)); |
| 6227 | |
| 6228 | lease = engine->allocateLease4(ctx2); |
| 6229 | 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" , 6229, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6230 | 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" , 6230, gtest_ar.failure_message()) = ::testing::Message(); |
| 6231 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 6232 | 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" , 6232, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 6233 | 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" , 6233, gtest_ar.failure_message()) = ::testing::Message(); |
| 6234 | } |
| 6235 | |
| 6236 | // Verifies that AllocEngine::getOfferLft(ctx4) returns the appropriate |
| 6237 | // lifetime value based on the context content. |
| 6238 | TEST_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", 6238 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6238), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6238), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getOfferLft4_Test >); void AllocEngine4Test_getOfferLft4_Test::TestBody() { |
| 6239 | AllocEngine engine(0); |
| 6240 | |
| 6241 | // Let's make three classes, two with offer-lifetime and one without, |
| 6242 | // and add them to the dictionary. |
| 6243 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 6244 | |
| 6245 | ClientClassDefPtr class_def(new ClientClassDef("offer_lft_one", ExpressionPtr())); |
| 6246 | Optional<uint32_t> offer_lft_one(100); |
| 6247 | class_def->setOfferLft(offer_lft_one); |
| 6248 | dictionary->addClass(class_def); |
| 6249 | |
| 6250 | class_def.reset(new ClientClassDef("offer_lft_two", ExpressionPtr())); |
| 6251 | Optional<uint32_t>offer_lft_two(200); |
| 6252 | class_def->setOfferLft(offer_lft_two); |
| 6253 | dictionary->addClass(class_def); |
| 6254 | |
| 6255 | class_def.reset(new ClientClassDef("offer_lft_zero", ExpressionPtr())); |
| 6256 | Optional<uint32_t>offer_lft_zero(0); |
| 6257 | class_def->setOfferLft(offer_lft_zero); |
| 6258 | dictionary->addClass(class_def); |
| 6259 | |
| 6260 | class_def.reset(new ClientClassDef("offer_lft_unspec", ExpressionPtr())); |
| 6261 | dictionary->addClass(class_def); |
| 6262 | |
| 6263 | // Commit our class changes. |
| 6264 | CfgMgr::instance().commit(); |
| 6265 | |
| 6266 | // Update the subnet's triplet to something more useful. |
| 6267 | subnet_->setOfferLft(Optional<uint32_t>(300)); |
| 6268 | |
| 6269 | // Describes a test scenario. |
| 6270 | struct Scenario { |
| 6271 | std::string desc_; // descriptive text for logging |
| 6272 | std::vector<std::string> classes_; // class list of assigned classes |
| 6273 | uint32_t exp_valid_lft_; // expected lease lifetime |
| 6274 | bool exp_allocate_; // true if lease should be allocated |
| 6275 | }; |
| 6276 | |
| 6277 | bool exp_allocate = true; |
| 6278 | |
| 6279 | // Scenarios to test. |
| 6280 | std::vector<Scenario> scenarios = { |
| 6281 | { |
| 6282 | "BOOTP", |
| 6283 | { "BOOTP" }, |
| 6284 | Lease::INFINITY_LFT, |
| 6285 | !exp_allocate, |
| 6286 | }, |
| 6287 | { |
| 6288 | "no classes", |
| 6289 | {}, |
| 6290 | subnet_->getOfferLft(), |
| 6291 | exp_allocate |
| 6292 | }, |
| 6293 | { |
| 6294 | "class unspecified", |
| 6295 | { "offer_lft_unspec" }, |
| 6296 | subnet_->getOfferLft(), |
| 6297 | exp_allocate |
| 6298 | }, |
| 6299 | { |
| 6300 | "from last class", |
| 6301 | { "offer_lft_unspec", "offer_lft_one" }, |
| 6302 | offer_lft_one.get(), |
| 6303 | exp_allocate |
| 6304 | }, |
| 6305 | { |
| 6306 | "from first class", |
| 6307 | { "offer_lft_two", "offer_lft_one" }, |
| 6308 | offer_lft_two.get(), |
| 6309 | exp_allocate |
| 6310 | }, |
| 6311 | { |
| 6312 | // Using class value of zero should override non-zero set at |
| 6313 | // subnet level, lease should have actual valid lft |
| 6314 | "zero from class", |
| 6315 | { "offer_lft_zero" }, |
| 6316 | subnet_->getValid(), |
| 6317 | !exp_allocate |
| 6318 | } |
| 6319 | }; |
| 6320 | |
| 6321 | // Iterate over the scenarios and verify the correct outcome. |
| 6322 | for (auto const& scenario : scenarios) { |
| 6323 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_6323( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6323, (scenario.desc_)); { |
| 6324 | // Create a context; |
| 6325 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 6326 | IOAddress("0.0.0.0"), false, false, |
| 6327 | "", true); |
| 6328 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 6329 | |
| 6330 | // Add client classes (if any) |
| 6331 | for (auto const& class_name : scenario.classes_) { |
| 6332 | ctx.query_->addClass(class_name); |
| 6333 | } |
| 6334 | |
| 6335 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 6336 | 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" , 6336, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6337 | 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" , 6337, gtest_ar.failure_message()) = ::testing::Message(); |
| 6338 | |
| 6339 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 6340 | if (!scenario.exp_allocate_) { |
| 6341 | 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" , 6341, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "true", "false") .c_str()) = ::testing::Message (); |
| 6342 | } else { |
| 6343 | 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" , 6343, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 6344 | 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" , 6344, gtest_ar.failure_message()) = ::testing::Message(); |
| 6345 | 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" , 6345, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(from_mgr)", "false" , "true") .c_str()) = ::testing::Message(); |
| 6346 | } |
| 6347 | } |
| 6348 | } |
| 6349 | } |
| 6350 | |
| 6351 | TEST_F(SharedNetworkAlloc4Test, discoverGlobalResVsSubnetRes)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("discoverGlobalResVsSubnetRes") > 1 , "test_name must not be empty"); class SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test : public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test () = default; ~SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test () override = default; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test (const SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test &) = delete; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test & operator=( const SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test &) = delete; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test (SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test && ) noexcept = delete; SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test & operator=( SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverGlobalResVsSubnetRes", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6351), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6351), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6351), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test >); void SharedNetworkAlloc4Test_discoverGlobalResVsSubnetRes_Test ::TestBody() { |
| 6352 | // global_host with address in subnet1, subnet_host with no address in subnet2 |
| 6353 | globalResVsSubnetRes(true, IOAddress("192.0.2.100"), |
| 6354 | true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(), |
| 6355 | SubnetID(20), IOAddress("10.1.2.5")); |
| 6356 | |
| 6357 | // global_host with address in subnet1, subnet_host with address in subnet2 |
| 6358 | globalResVsSubnetRes(true, IOAddress("192.0.2.100"), |
| 6359 | true, SubnetID(20), IOAddress("10.1.2.200"), |
| 6360 | SubnetID(20), IOAddress("10.1.2.200")); |
| 6361 | |
| 6362 | // global_host with address in subnet2, subnet_host with no address in subnet2 |
| 6363 | globalResVsSubnetRes(true, IOAddress("10.1.2.1"), |
| 6364 | true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(), |
| 6365 | SubnetID(20), IOAddress("10.1.2.6")); |
| 6366 | |
| 6367 | // global_host with address in subnet2, subnet_host with address in subnet2 |
| 6368 | globalResVsSubnetRes(true, IOAddress("10.1.2.1"), |
| 6369 | true, SubnetID(20), IOAddress("10.1.2.200"), |
| 6370 | SubnetID(20), IOAddress("10.1.2.200")); |
| 6371 | } |
| 6372 | |
| 6373 | TEST_F(SharedNetworkAlloc4Test, requestGlobalResVsSubnetRes)static_assert(sizeof("SharedNetworkAlloc4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("requestGlobalResVsSubnetRes") > 1 , "test_name must not be empty"); class SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test : public SharedNetworkAlloc4Test { public: SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test () = default; ~SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test () override = default; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test (const SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test &) = delete; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test & operator=( const SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test &) = delete; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test (SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test && ) noexcept = delete; SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test & operator=( SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestGlobalResVsSubnetRes", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6373), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6373), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6373), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test >); void SharedNetworkAlloc4Test_requestGlobalResVsSubnetRes_Test ::TestBody() { |
| 6374 | // global_host with address in subnet1, subnet_host with no address in subnet2 |
| 6375 | globalResVsSubnetRes(true, IOAddress("192.0.2.100"), |
| 6376 | true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(), |
| 6377 | SubnetID(20), IOAddress("10.1.2.5"), false); |
| 6378 | |
| 6379 | // global_host with address in subnet1, subnet_host with address in subnet2 |
| 6380 | globalResVsSubnetRes(true, IOAddress("192.0.2.100"), |
| 6381 | true, SubnetID(20), IOAddress("10.1.2.200"), |
| 6382 | SubnetID(20), IOAddress("10.1.2.200"), false); |
| 6383 | |
| 6384 | // global_host with address in subnet2, subnet_host with no address in subnet2 |
| 6385 | globalResVsSubnetRes(true, IOAddress("10.1.2.1"), |
| 6386 | true, SubnetID(20), IOAddress::IPV4_ZERO_ADDRESS(), |
| 6387 | SubnetID(20), IOAddress("10.1.2.6"), false); |
| 6388 | |
| 6389 | // global_host with address in subnet2, subnet_host with address in subnet2 |
| 6390 | globalResVsSubnetRes(true, IOAddress("10.1.2.1"), |
| 6391 | true, SubnetID(20), IOAddress("10.1.2.200"), |
| 6392 | SubnetID(20), IOAddress("10.1.2.200"), false); |
| 6393 | } |
| 6394 | |
| 6395 | } // namespace test |
| 6396 | } // namespace dhcp |
| 6397 | } // namespace isc |