| File: | home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpxsedttj5/../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc |
| Warning: | line 4107, 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(NULL__null); |
| 422 | Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2, |
| 423 | clientid2, sizeof(clientid2), 1, now, subnet_->getID())); |
| 424 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(used))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 424, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(used)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 425 | |
| 426 | // Another client comes in and request an address that is in pool, but |
| 427 | // unfortunately it is used already. The same address must not be allocated |
| 428 | // twice. |
| 429 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 430 | IOAddress("192.0.2.106"), false, false, |
| 431 | "", true); |
| 432 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 433 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 434 | |
| 435 | // New lease has been allocated, so the old lease should not exist. |
| 436 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 436, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 437 | |
| 438 | // Check that we got a lease |
| 439 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 439, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 440 | |
| 441 | // Allocated address must be different |
| 442 | EXPECT_NE(used->addr_, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("used->addr_" , "lease->addr_", used->addr_, lease->addr_))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 442, gtest_ar.failure_message()) = ::testing::Message(); |
| 443 | |
| 444 | // We should NOT get what we asked for, because it is used already |
| 445 | EXPECT_NE("192.0.2.106", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("\"192.0.2.106\"" , "lease->addr_.toText()", "192.0.2.106", lease->addr_. toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 445, gtest_ar.failure_message()) = ::testing::Message(); |
| 446 | |
| 447 | // Do all checks on the lease |
| 448 | checkLease4(lease); |
| 449 | |
| 450 | // The lease should not be in the LeaseMgr because it was a failed allocation. |
| 451 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 452 | ASSERT_FALSE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(from_mgr))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 452, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "true", "false") .c_str()) = ::testing::Message (); |
| 453 | } |
| 454 | |
| 455 | // This test checks if an allocation with a hint that is out of the blue |
| 456 | // can succeed. The invalid hint should be ignored completely. |
| 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 if a returning client can renew an |
| 560 | // an existing lease and assigned-leases increments accordingly |
| 561 | 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", 561 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 561), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 561), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleRenew4_Test >); void AllocEngine4Test_simpleRenew4_Test::TestBody() { |
| 562 | boost::scoped_ptr<AllocEngine> engine; |
| 563 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_563 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_563 ; } } else gtest_label_testnothrow_563 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 563, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 564 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 565 | |
| 566 | EXPECT_TRUE(testStatistics("assigned-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 566, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 567 | EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 567, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 568 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 569 | subnet_->getID()); |
| 570 | |
| 571 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 572 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 573 | |
| 574 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 575 | false, true, "somehost.example.com.", false); |
| 576 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 577 | |
| 578 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 579 | |
| 580 | // Check that we got a lease and it's sane |
| 581 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 581, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 582 | checkLease4(lease); |
| 583 | |
| 584 | // The new lease has been allocated, so the old lease should not exist. |
| 585 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 586 | |
| 587 | // We should have incremented assigned-addresses |
| 588 | EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 589 | cumulative += 1; |
| 590 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 591, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 591 | cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 591, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 592 | glbl_assigned += 1; |
| 593 | EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , glbl_assigned))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 593, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 594 | glbl_cumulative += 1; |
| 595 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , glbl_cumulative))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 596 | |
| 597 | // Do it again, this should amount to the renew of an existing lease |
| 598 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 599 | |
| 600 | // Check that we got a lease and it's sane |
| 601 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 601, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 602 | checkLease4(lease2); |
| 603 | |
| 604 | // Lease already existed, so old_lease should be set. |
| 605 | EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 605, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 606 | |
| 607 | // Should NOT have bumped assigned-addresses |
| 608 | EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 608, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 609 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 610 | cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 611 | EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , glbl_assigned))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 611, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 612 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , glbl_cumulative))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 612, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 613 | } |
| 614 | |
| 615 | // This test checks simple renewal uses the default valid lifetime. |
| 616 | 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", 616 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 616), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 616), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultRenew4_Test >); void AllocEngine4Test_defaultRenew4_Test::TestBody() { |
| 617 | boost::scoped_ptr<AllocEngine> engine; |
| 618 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_618 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_618 ; } } else gtest_label_testnothrow_618 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 618, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 619 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 619, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 620 | |
| 621 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 622 | false, true, "somehost.example.com.", false); |
| 623 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 624 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 625 | |
| 626 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 627 | |
| 628 | // Check that we got a lease and it's sane |
| 629 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 629, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 630 | checkLease4(lease); |
| 631 | |
| 632 | // Check the valid lifetime has the default. |
| 633 | EXPECT_EQ(subnet_->getValid(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid()" , "lease->valid_lft_", subnet_->getValid(), lease->valid_lft_ ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 633, gtest_ar.failure_message()) = ::testing::Message(); |
| 634 | |
| 635 | // The new lease has been allocated, so the old lease should not exist. |
| 636 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 636, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 637 | |
| 638 | // Do it again, this should amount to the renew of an existing lease |
| 639 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 640 | |
| 641 | // Check that we got a lease and it's sane |
| 642 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 642, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 643 | checkLease4(lease2); |
| 644 | |
| 645 | // Lease already existed, so old_lease should be set. |
| 646 | EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 646, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 647 | |
| 648 | // Check the renewed valid lifetime has the default. |
| 649 | EXPECT_EQ(subnet_->getValid(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid()" , "lease2->valid_lft_", subnet_->getValid(), lease2-> valid_lft_))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 649, gtest_ar.failure_message()) = ::testing::Message(); |
| 650 | } |
| 651 | |
| 652 | // This test checks simple renewal uses the specified valid lifetime. |
| 653 | 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", 653 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 653), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 653), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintRenew4_Test >); void AllocEngine4Test_hintRenew4_Test::TestBody() { |
| 654 | boost::scoped_ptr<AllocEngine> engine; |
| 655 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_655 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_655 ; } } else gtest_label_testnothrow_655 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 655, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 656 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 657 | |
| 658 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 659 | false, true, "somehost.example.com.", false); |
| 660 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 661 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 662 | |
| 663 | // Specify the valid lifetime we want. |
| 664 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); |
| 665 | ctx.query_->addOption(opt); |
| 666 | |
| 667 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 668 | |
| 669 | // Check that we got a lease and it's sane |
| 670 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 670, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 671 | checkLease4(lease); |
| 672 | |
| 673 | // Check the valid lifetime has the wanted value. |
| 674 | EXPECT_EQ(opt->getValue(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("opt->getValue()" , "lease->valid_lft_", opt->getValue(), lease->valid_lft_ ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 674, gtest_ar.failure_message()) = ::testing::Message(); |
| 675 | |
| 676 | // The new lease has been allocated, so the old lease should not exist. |
| 677 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 677, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 678 | |
| 679 | // Do it again, this should amount to the renew of an existing lease |
| 680 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 681 | |
| 682 | // Check that we got a lease and it's sane |
| 683 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 683, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 684 | checkLease4(lease2); |
| 685 | |
| 686 | // Lease already existed, so old_lease should be set. |
| 687 | EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 687, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 688 | |
| 689 | // Check the renewed valid lifetime has the wanted value. |
| 690 | EXPECT_EQ(opt->getValue(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("opt->getValue()" , "lease2->valid_lft_", opt->getValue(), lease2->valid_lft_ ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 690, gtest_ar.failure_message()) = ::testing::Message(); |
| 691 | } |
| 692 | |
| 693 | // This test checks simple renewal uses the min valid lifetime. |
| 694 | 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", 694 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 694), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 694), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minRenew4_Test >); void AllocEngine4Test_minRenew4_Test::TestBody() { |
| 695 | boost::scoped_ptr<AllocEngine> engine; |
| 696 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_696 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_696 ; } } else gtest_label_testnothrow_696 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 696, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 697 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 697, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 698 | |
| 699 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 700 | false, true, "somehost.example.com.", false); |
| 701 | subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); |
| 702 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 703 | |
| 704 | // Specify the valid lifetime we want, as it is lower than the min value |
| 705 | // we'll get this min value instead. |
| 706 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); |
| 707 | ctx.query_->addOption(opt); |
| 708 | |
| 709 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 710 | |
| 711 | // Check that we got a lease and it's sane |
| 712 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 712, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 713 | checkLease4(lease); |
| 714 | |
| 715 | // Check the valid lifetime has the min value. |
| 716 | EXPECT_EQ(subnet_->getValid().getMin(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMin()" , "lease->valid_lft_", subnet_->getValid().getMin(), lease ->valid_lft_))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 716, gtest_ar.failure_message()) = ::testing::Message(); |
| 717 | |
| 718 | // The new lease has been allocated, so the old lease should not exist. |
| 719 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 719, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 720 | |
| 721 | // Do it again, this should amount to the renew of an existing lease |
| 722 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 723 | |
| 724 | // Check that we got a lease and it's sane |
| 725 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 725, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 726 | checkLease4(lease2); |
| 727 | |
| 728 | // Lease already existed, so old_lease should be set. |
| 729 | EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 729, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 730 | |
| 731 | // Check the renewed valid lifetime has the min value. |
| 732 | EXPECT_EQ(subnet_->getValid().getMin(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMin()" , "lease2->valid_lft_", subnet_->getValid().getMin(), lease2 ->valid_lft_))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 732, gtest_ar.failure_message()) = ::testing::Message(); |
| 733 | } |
| 734 | |
| 735 | // This test checks simple renewal uses the max valid lifetime. |
| 736 | 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", 736 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 736), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 736), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxRenew4_Test >); void AllocEngine4Test_maxRenew4_Test::TestBody() { |
| 737 | boost::scoped_ptr<AllocEngine> engine; |
| 738 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_738 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_738 ; } } else gtest_label_testnothrow_738 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 738, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 739 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 739, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 740 | |
| 741 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 742 | false, true, "somehost.example.com.", false); |
| 743 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 744 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 745 | |
| 746 | // Specify the valid lifetime we want, as it is greater than the max value |
| 747 | // we'll get this max value instead. |
| 748 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); |
| 749 | ctx.query_->addOption(opt); |
| 750 | |
| 751 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 752 | |
| 753 | // Check that we got a lease and it's sane |
| 754 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 754, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 755 | checkLease4(lease); |
| 756 | |
| 757 | // Check the valid lifetime has the max value. |
| 758 | EXPECT_EQ(subnet_->getValid().getMax(), lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMax()" , "lease->valid_lft_", subnet_->getValid().getMax(), lease ->valid_lft_))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 758, gtest_ar.failure_message()) = ::testing::Message(); |
| 759 | |
| 760 | // The new lease has been allocated, so the old lease should not exist. |
| 761 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 761, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 762 | |
| 763 | // Do it again, this should amount to the renew of an existing lease |
| 764 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 765 | |
| 766 | // Check that we got a lease and it's sane |
| 767 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 767, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 768 | checkLease4(lease2); |
| 769 | |
| 770 | // Lease already existed, so old_lease should be set. |
| 771 | EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 771, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 772 | |
| 773 | // Check the renewed valid lifetime has the max value. |
| 774 | EXPECT_EQ(subnet_->getValid().getMax(), lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("subnet_->getValid().getMax()" , "lease2->valid_lft_", subnet_->getValid().getMax(), lease2 ->valid_lft_))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 774, gtest_ar.failure_message()) = ::testing::Message(); |
| 775 | } |
| 776 | |
| 777 | // This test checks simple renewal handles BOOTP queries. |
| 778 | 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", 778 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 778), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 778), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpRenew4_Test >); void AllocEngine4Test_bootpRenew4_Test::TestBody() { |
| 779 | boost::scoped_ptr<AllocEngine> engine; |
| 780 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_780 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_780 ; } } else gtest_label_testnothrow_780 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 780, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 781 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 781, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 782 | |
| 783 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 784 | false, true, "somehost.example.com.", false); |
| 785 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 786 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 787 | |
| 788 | // Make the query a BOOTP one. |
| 789 | ctx.query_->addClass("BOOTP"); |
| 790 | |
| 791 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 792 | |
| 793 | // Check that we got a lease. |
| 794 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 794, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 795 | |
| 796 | // Check that is belongs to the right subnet and client. |
| 797 | EXPECT_EQ(lease->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet_->getID()", lease->subnet_id_, subnet_->getID ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 797, gtest_ar.failure_message()) = ::testing::Message(); |
| 798 | EXPECT_TRUE(subnet_->inRange(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease ->addr_))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 798, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 799 | EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 799, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 800 | ASSERT_TRUE(lease->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease->client_id_) ) ; else return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 801 | EXPECT_TRUE(*lease->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*lease->client_id_ == *clientid_)) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 801, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 802 | ASSERT_TRUE(lease->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease->hwaddr_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 802, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 803 | EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*lease->hwaddr_ == *hwaddr_)) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 804 | |
| 805 | // Check the valid lifetime is infinite. |
| 806 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
| 807 | EXPECT_EQ(infinity_lft, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("infinity_lft" , "lease->valid_lft_", infinity_lft, lease->valid_lft_) )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 807, gtest_ar.failure_message()) = ::testing::Message(); |
| 808 | |
| 809 | // The new lease has been allocated, so the old lease should not exist. |
| 810 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 810, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 811 | |
| 812 | // Do it again, this should amount to the renew of an existing lease |
| 813 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 814 | |
| 815 | // Check that we got a lease. |
| 816 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 816, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 817 | |
| 818 | // Check that is belongs to the right subnet and client. |
| 819 | EXPECT_EQ(lease2->subnet_id_, subnet_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease2->subnet_id_" , "subnet_->getID()", lease2->subnet_id_, subnet_->getID ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 819, gtest_ar.failure_message()) = ::testing::Message(); |
| 820 | EXPECT_TRUE(subnet_->inRange(lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet_->inRange(lease2 ->addr_))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 820, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease2->addr_)", "false", "true") . c_str()) = ::testing::Message(); |
| 821 | EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease ::TYPE_V4, lease2->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 821, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 822 | ASSERT_TRUE(lease2->client_id_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2->client_id_ )) ; else return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 822, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 823 | EXPECT_TRUE(*lease2->client_id_ == *clientid_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*lease2->client_id_ == *clientid_)) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 823, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 824 | ASSERT_TRUE(lease2->hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2->hwaddr_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 824, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 825 | EXPECT_TRUE(*lease2->hwaddr_ == *hwaddr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*lease2->hwaddr_ == *hwaddr_)) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 825, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->hwaddr_ == *hwaddr_", "false", "true") .c_str( )) = ::testing::Message(); |
| 826 | |
| 827 | // Lease already existed, so old_lease should be set. |
| 828 | EXPECT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 829 | |
| 830 | // Check the renewed valid lifetime has the max value. |
| 831 | EXPECT_EQ(infinity_lft, lease2->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("infinity_lft" , "lease2->valid_lft_", infinity_lft, lease2->valid_lft_ ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 831, gtest_ar.failure_message()) = ::testing::Message(); |
| 832 | } |
| 833 | |
| 834 | // This test checks if really small pools are working |
| 835 | 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", 835 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 835), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 835), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_smallPool4_Test >); void AllocEngine4Test_smallPool4_Test::TestBody() { |
| 836 | boost::scoped_ptr<AllocEngine> engine; |
| 837 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_837 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_837 ; } } else gtest_label_testnothrow_837 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 837, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 838 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 838, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 839 | |
| 840 | IOAddress addr("192.0.2.17"); |
| 841 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 842 | |
| 843 | // Get rid of the default subnet configuration. |
| 844 | cfg_mgr.clear(); |
| 845 | |
| 846 | // Create configuration similar to other tests, but with a single address pool |
| 847 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 848 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 849 | subnet_->addPool(pool_); |
| 850 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 851 | |
| 852 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 853 | IOAddress("0.0.0.0"), false, false, |
| 854 | "host.example.com.", false); |
| 855 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 856 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 857 | |
| 858 | // Check that we got that single lease |
| 859 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 860 | |
| 861 | // We have allocated new lease, so the old lease should not exist. |
| 862 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 862, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 863 | |
| 864 | EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\"" , "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 864, gtest_ar.failure_message()) = ::testing::Message(); |
| 865 | |
| 866 | // Do all checks on the lease |
| 867 | checkLease4(lease); |
| 868 | |
| 869 | // Check that the lease is indeed in LeaseMgr |
| 870 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 871 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 871, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 872 | |
| 873 | // Now check that the lease in LeaseMgr has the same parameters |
| 874 | detailCompareLease(lease, from_mgr); |
| 875 | } |
| 876 | |
| 877 | // This test checks if all addresses in a pool are currently used, the attempt |
| 878 | // to find out a new lease fails. |
| 879 | 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", 879 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 879), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 879), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_outOfAddresses4_Test >); void AllocEngine4Test_outOfAddresses4_Test::TestBody() { |
| 880 | boost::scoped_ptr<AllocEngine> engine; |
| 881 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_881 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_881 ; } } else gtest_label_testnothrow_881 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 881, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 882 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 882, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 883 | |
| 884 | IOAddress addr("192.0.2.17"); |
| 885 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 886 | // Get rid of the default test configuration. |
| 887 | cfg_mgr.clear(); |
| 888 | |
| 889 | // Create configuration similar to other tests, but with a single address pool |
| 890 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 891 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 892 | subnet_->addPool(pool_); |
| 893 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 894 | |
| 895 | // Just a different hw/client-id for the second client |
| 896 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 897 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 898 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 899 | time_t now = time(NULL__null); |
| 900 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, |
| 901 | sizeof(clientid2), 501, now, |
| 902 | subnet_->getID())); |
| 903 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 904 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 904, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 905 | |
| 906 | // There is just a single address in the pool and allocated it to someone |
| 907 | // else, so the allocation should fail |
| 908 | |
| 909 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 910 | IOAddress("0.0.0.0"), false, false, |
| 911 | "host.example.com.", false); |
| 912 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 913 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
| 914 | ASSERT_FALSE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(lease2))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 914, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "true", "false") .c_str()) = ::testing::Message(); |
| 915 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 915, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 916 | |
| 917 | EXPECT_EQ(1, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\")" , 1, getStatistics("v4-allocation-fail")))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 917, gtest_ar.failure_message()) = ::testing::Message(); |
| 918 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")" , 0, getStatistics("v4-allocation-fail-shared-network")))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 918, gtest_ar.failure_message()) = ::testing::Message(); |
| 919 | EXPECT_EQ(1, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-subnet\")" , 1, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 919, gtest_ar.failure_message()) = ::testing::Message(); |
| 920 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")" , 0, getStatistics("v4-allocation-fail-no-pools")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 920, gtest_ar.failure_message()) = ::testing::Message(); |
| 921 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")" , 0, getStatistics("v4-allocation-fail-classes")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 921, gtest_ar.failure_message()) = ::testing::Message(); |
| 922 | |
| 923 | EXPECT_EQ(1, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\", subnet_->getID())" , 1, getStatistics("v4-allocation-fail", subnet_->getID()) ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 923, gtest_ar.failure_message()) = ::testing::Message(); |
| 924 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-shared-network", subnet_ ->getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 924, gtest_ar.failure_message()) = ::testing::Message(); |
| 925 | EXPECT_EQ(1, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())" , 1, getStatistics("v4-allocation-fail-subnet", subnet_->getID ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 925, gtest_ar.failure_message()) = ::testing::Message(); |
| 926 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-no-pools", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 926, gtest_ar.failure_message()) = ::testing::Message(); |
| 927 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-classes", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 927, gtest_ar.failure_message()) = ::testing::Message(); |
| 928 | } |
| 929 | |
| 930 | /// @brief This test class is dedicated to testing shared networks |
| 931 | /// |
| 932 | /// It uses one common configuration: |
| 933 | /// 1 shared network with 2 subnets: |
| 934 | /// - 192.0.2.0/24 subnet with a small pool of single address: 192.0.2.17 |
| 935 | /// - 10.1.2.0/24 subnet with pool with 96 addresses. |
| 936 | class SharedNetworkAlloc4Test : public AllocEngine4Test { |
| 937 | public: |
| 938 | |
| 939 | /// @brief Initializes configuration (2 subnets, 1 shared network) |
| 940 | SharedNetworkAlloc4Test() : engine_(0) { |
| 941 | // Create two subnets, each with a single address pool. The first subnet |
| 942 | // has only one address in its address pool to make it easier to simulate |
| 943 | // address exhaustion. |
| 944 | subnet1_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 945 | subnet2_ = Subnet4::create(IOAddress("10.1.2.0"), 24, 1, 2, 3, SubnetID(20)); |
| 946 | pool1_.reset(new Pool4(IOAddress("192.0.2.17"), IOAddress("192.0.2.17"))); |
| 947 | pool2_.reset(new Pool4(IOAddress("10.1.2.5"), IOAddress("10.1.2.100"))); |
| 948 | |
| 949 | subnet1_->addPool(pool1_); |
| 950 | subnet2_->addPool(pool2_); |
| 951 | |
| 952 | // Both subnets belong to the same network so they can be used |
| 953 | // interchangeably. |
| 954 | network_.reset(new SharedNetwork4("test_network")); |
| 955 | network_->add(subnet1_); |
| 956 | network_->add(subnet2_); |
| 957 | |
| 958 | std::vector<uint8_t> hwaddr_vec = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 959 | hwaddr2_.reset(new HWAddr(hwaddr_vec, HTYPE_ETHER)); |
| 960 | } |
| 961 | |
| 962 | /// @brief Inserts a new lease for specified address |
| 963 | /// |
| 964 | /// Creates a new lease for specified address and subnet-id and inserts |
| 965 | /// it into database. This is not particularly fancy method, it is used |
| 966 | /// just to mark existing addresses as used. It uses hwaddr2_ to allocate |
| 967 | /// the lease. |
| 968 | /// |
| 969 | /// @param addr text representation of the address |
| 970 | /// @param subnet_id ID of the subnet |
| 971 | /// @param return pointer to the lease |
| 972 | Lease4Ptr |
| 973 | insertLease(std::string addr, SubnetID subnet_id) { |
| 974 | Lease4Ptr lease(new Lease4(IOAddress(addr), hwaddr2_, ClientIdPtr(), |
| 975 | 501, time(NULL__null), subnet_id)); |
| 976 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 977 | if (!LeaseMgrFactory::instance().addLease(lease)) { |
| 978 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 978, "Failed") = ::testing::Message() << "Attempt to add a lease for IP " << addr |
| 979 | << " in subnet " << subnet_id << " failed"; |
| 980 | } |
| 981 | |
| 982 | return (lease); |
| 983 | } |
| 984 | |
| 985 | /// Convenience pointers to configuration elements. These are initialized |
| 986 | /// in the constructor and are used throughout the tests. |
| 987 | AllocEngine engine_; |
| 988 | Subnet4Ptr subnet1_; |
| 989 | Subnet4Ptr subnet2_; |
| 990 | Pool4Ptr pool1_; |
| 991 | Pool4Ptr pool2_; |
| 992 | SharedNetwork4Ptr network_; |
| 993 | |
| 994 | HWAddrPtr hwaddr2_; // Note there's hwaddr_ already defined in base class. |
| 995 | }; |
| 996 | |
| 997 | // This test verifies that the server can offer an address from a |
| 998 | // subnet and the introduction of shared network doesn't break anything here. |
| 999 | 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" , 999), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 999), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 999), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test ::TestBody() { |
| 1000 | |
| 1001 | // Create context which will be used to try to allocate leases from the |
| 1002 | // shared network. The context points to subnet1, which address space |
| 1003 | // is exhausted. We expect the allocation engine to find another subnet |
| 1004 | // within the same shared network and offer an address from there. |
| 1005 | AllocEngine::ClientContext4 |
| 1006 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1007 | false, false, "host.example.com.", true); |
| 1008 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1009 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1010 | |
| 1011 | // The allocation engine should have assigned an address from the first |
| 1012 | // subnet. |
| 1013 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1013, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1014 | EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\"" , "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1014, gtest_ar.failure_message()) = ::testing::Message(); |
| 1015 | |
| 1016 | // Make sure the lease is not in the lease mgr (this is only |
| 1017 | // discover). |
| 1018 | ASSERT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance ().getLease4(lease->addr_)))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1018, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 1019 | } |
| 1020 | |
| 1021 | // This test verifies that the server will pick a second subnet out of two |
| 1022 | // shared subnets if there is a hint for the second subnet. |
| 1023 | 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" , 1023), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1023), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1023), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test ::TestBody() { |
| 1024 | |
| 1025 | // Create context which will be used to try to allocate leases from the |
| 1026 | // shared network. The context points to subnet1, which address space |
| 1027 | // is exhausted. We expect the allocation engine to find another subnet |
| 1028 | // within the same shared network and offer an address from there. |
| 1029 | |
| 1030 | AllocEngine::ClientContext4 |
| 1031 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress("10.1.2.25"), |
| 1032 | false, false, "host.example.com.", true); |
| 1033 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1034 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1035 | |
| 1036 | // The allocation engine should have assigned an address from the second |
| 1037 | // subnet, because that's what the hint requested. |
| 1038 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1039 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1039, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1040 | } |
| 1041 | |
| 1042 | // This test verifies that the server can offer an address from a |
| 1043 | // different subnet than orginally selected, when the address pool in |
| 1044 | // the first subnet is exhausted. |
| 1045 | 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" , 1045), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1045), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1045), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetwork_Test >); void SharedNetworkAlloc4Test_discoverSharedNetwork_Test ::TestBody() { |
| 1046 | // Create a lease for a single address in the first address pool. The |
| 1047 | // pool is now exhausted. |
| 1048 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
| 1049 | |
| 1050 | // Create context which will be used to try to allocate leases from the |
| 1051 | // shared network. The context points to subnet1, which address space |
| 1052 | // is exhausted. We expect the allocation engine to find another subnet |
| 1053 | // within the same shared network and offer an address from there. |
| 1054 | AllocEngine::ClientContext4 |
| 1055 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1056 | false, false, "host.example.com.", true); |
| 1057 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1058 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
| 1059 | // The allocation engine should have assigned an address from the second |
| 1060 | // subnet. We could guess that this is 10.1.2.5, being the first address |
| 1061 | // in the address pool, but to make the test more generic, we merely |
| 1062 | // verify that the address is in the given address pool. |
| 1063 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1063, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1064 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease2->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1065 | |
| 1066 | // The client should also be offered a lease when it specifies a hint |
| 1067 | // that doesn't match the subnet from which the lease is offered. The |
| 1068 | // engine should check alternative subnets to match the hint to |
| 1069 | // a subnet. The requested lease is available, so it should be offered. |
| 1070 | ctx.subnet_ = subnet1_; |
| 1071 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
| 1072 | lease2 = engine_.allocateLease4(ctx); |
| 1073 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1073, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1074 | EXPECT_EQ("10.1.2.25", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.25\"" , "lease2->addr_.toText()", "10.1.2.25", lease2->addr_. toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1074, gtest_ar.failure_message()) = ::testing::Message(); |
| 1075 | |
| 1076 | // The returning client (the one that has a lease) should also be able |
| 1077 | // to renew its lease regardless of a subnet it begins with. So, it has |
| 1078 | // an address assigned from subnet1, but we use subnet2 as a selected |
| 1079 | // subnet. |
| 1080 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
| 1081 | IOAddress("0.0.0.0"), false, false, |
| 1082 | "host.example.com.", true); |
| 1083 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1084 | lease2 = engine_.allocateLease4(ctx2); |
| 1085 | // The existing lease should be returned. |
| 1086 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1086, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1087 | EXPECT_EQ("192.0.2.17", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\"" , "lease2->addr_.toText()", "192.0.2.17", lease2->addr_ .toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1087, gtest_ar.failure_message()) = ::testing::Message(); |
| 1088 | } |
| 1089 | |
| 1090 | // This test verifies that the server can offer an address from a |
| 1091 | // different subnet than orginally selected, when the address pool in |
| 1092 | // the first subnet is exhausted. |
| 1093 | 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" , 1093), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1093), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1093), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test ::TestBody() { |
| 1094 | |
| 1095 | // Try to offer address from subnet1. There is one address available |
| 1096 | // so it should be offered. |
| 1097 | AllocEngine::ClientContext4 |
| 1098 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1099 | false, false, "host.example.com.", true); |
| 1100 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1101 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1102 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1102, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1103 | EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1103, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1104 | |
| 1105 | // Apply restrictions on the subnet1. This should be only assigned |
| 1106 | // to clients belonging to cable-modem class. |
| 1107 | subnet1_->allowClientClass("cable-modem"); |
| 1108 | |
| 1109 | // The allocation engine should determine that the subnet1 is not |
| 1110 | // available for the client not belonging to the cable-modem class. |
| 1111 | // Instead, it should offer an address from subnet2 that belongs |
| 1112 | // to the same shared network. |
| 1113 | ctx.subnet_ = subnet1_; |
| 1114 | lease = engine_.allocateLease4(ctx); |
| 1115 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1115, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1116 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1116, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1117 | |
| 1118 | // Create reservation for the client in subnet1. Because this subnet is |
| 1119 | // not allowed for the client the client should still be offered a |
| 1120 | // lease from subnet2. |
| 1121 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1122 | Host::IDENT_HWADDR, subnet1_->getID(), |
| 1123 | SUBNET_ID_UNUSED, IOAddress("192.0.2.17"))); |
| 1124 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1125 | CfgMgr::instance().commit(); |
| 1126 | AllocEngine::findReservation(ctx); |
| 1127 | |
| 1128 | ctx.subnet_ = subnet1_; |
| 1129 | lease = engine_.allocateLease4(ctx); |
| 1130 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1130, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1131 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1131, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1132 | |
| 1133 | // Assign cable-modem class and try again. This time, we should |
| 1134 | // offer an address from the subnet1. |
| 1135 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1136 | |
| 1137 | ctx.subnet_ = subnet1_; |
| 1138 | lease = engine_.allocateLease4(ctx); |
| 1139 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1140 | EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\"" , "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1140, gtest_ar.failure_message()) = ::testing::Message(); |
| 1141 | } |
| 1142 | |
| 1143 | // This test verifies that the server can offer an address from a |
| 1144 | // different subnet than orginally selected, when the address pool in |
| 1145 | // the first subnet requires another class. |
| 1146 | 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" , 1146), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1146), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1146), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test ::TestBody() { |
| 1147 | |
| 1148 | // Try to offer address from subnet1. There is one address available |
| 1149 | // so it should be offered. |
| 1150 | AllocEngine::ClientContext4 |
| 1151 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1152 | false, false, "host.example.com.", true); |
| 1153 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1154 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1155 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1155, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1156 | EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1156, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1157 | |
| 1158 | // Apply restrictions on the pool1. This should be only assigned |
| 1159 | // to clients belonging to cable-modem class. |
| 1160 | pool1_->allowClientClass("cable-modem"); |
| 1161 | |
| 1162 | // The allocation engine should determine that the pool1 is not |
| 1163 | // available for the client not belonging to the cable-modem class. |
| 1164 | // Instead, it should offer an address from subnet2 that belongs |
| 1165 | // to the same shared network. |
| 1166 | ctx.subnet_ = subnet1_; |
| 1167 | lease = engine_.allocateLease4(ctx); |
| 1168 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1168, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1169 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1169, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1170 | |
| 1171 | // Assign cable-modem class and try again. This time, we should |
| 1172 | // offer an address from the pool1. |
| 1173 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1174 | |
| 1175 | // Restrict access to pool2 for this client, to make sure that the |
| 1176 | // server doesn't accidentally get an address from this pool. |
| 1177 | pool2_->allowClientClass("telephone"); |
| 1178 | |
| 1179 | ctx.subnet_ = subnet1_; |
| 1180 | lease = engine_.allocateLease4(ctx); |
| 1181 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1181, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1182 | EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\"" , "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1182, gtest_ar.failure_message()) = ::testing::Message(); |
| 1183 | } |
| 1184 | |
| 1185 | // Test that global reservations within shared network take precedence over the |
| 1186 | // existing leases regardless in which subnet belonging to a shared network |
| 1187 | // reservations belong. |
| 1188 | 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" , 1188), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1188), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1188), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test ::TestBody() { |
| 1189 | |
| 1190 | EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance() .getDisableSingleQuery()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1190, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1191 | |
| 1192 | // Create reservation for the client. |
| 1193 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1194 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 1195 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1196 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1197 | CfgMgr::instance().commit(); |
| 1198 | |
| 1199 | subnet1_->setReservationsGlobal(true); |
| 1200 | subnet1_->setReservationsInSubnet(true); |
| 1201 | subnet2_->setReservationsGlobal(true); |
| 1202 | subnet2_->setReservationsInSubnet(true); |
| 1203 | |
| 1204 | // Start allocation from subnet1. The engine should determine that the |
| 1205 | // client has global reservations within subnet2 and should rather |
| 1206 | // assign reserved addresses. |
| 1207 | AllocEngine::ClientContext4 |
| 1208 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1209 | false, false, "host.example.com.", true); |
| 1210 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1211 | AllocEngine::findReservation(ctx); |
| 1212 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1213 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1213, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1214 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1214, gtest_ar.failure_message()) = ::testing::Message(); |
| 1215 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1215, gtest_ar.failure_message()) = ::testing::Message(); |
| 1216 | |
| 1217 | // Let's create a lease for the client to make sure the lease is not |
| 1218 | // renewed but a reserved lease is offered. |
| 1219 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1220 | 501, time(NULL__null), subnet1_->getID())); |
| 1221 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 1222 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1223 | ctx.subnet_ = subnet1_; |
| 1224 | ctx.hosts_.clear(); |
| 1225 | AllocEngine::findReservation(ctx); |
| 1226 | lease = engine_.allocateLease4(ctx); |
| 1227 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1227, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1228 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1228, gtest_ar.failure_message()) = ::testing::Message(); |
| 1229 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1229, gtest_ar.failure_message()) = ::testing::Message(); |
| 1230 | } |
| 1231 | |
| 1232 | |
| 1233 | // Test that reservations within shared network take precedence over the |
| 1234 | // existing leases regardless in which subnet belonging to a shared network |
| 1235 | // reservations belong. |
| 1236 | 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" , 1236), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1236), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1236), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test ::TestBody() { |
| 1237 | |
| 1238 | EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance() .getDisableSingleQuery()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1238, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1239 | |
| 1240 | // Create reservation for the client. |
| 1241 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1242 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1243 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1244 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1245 | CfgMgr::instance().commit(); |
| 1246 | |
| 1247 | // Start allocation from subnet1. The engine should determine that the |
| 1248 | // client has reservations in subnet2 and should rather assign reserved |
| 1249 | // addresses. |
| 1250 | AllocEngine::ClientContext4 |
| 1251 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1252 | false, false, "host.example.com.", true); |
| 1253 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1254 | AllocEngine::findReservation(ctx); |
| 1255 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1256 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1256, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1257 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1257, gtest_ar.failure_message()) = ::testing::Message(); |
| 1258 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1258, gtest_ar.failure_message()) = ::testing::Message(); |
| 1259 | |
| 1260 | // Let's create a lease for the client in subnet1 to make sure the lease |
| 1261 | // is not renewed but a reserved lease is offered. |
| 1262 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1263 | 501, time(NULL__null), subnet1_->getID())); |
| 1264 | lease2->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 1265 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1265, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1266 | ctx.subnet_ = subnet1_; |
| 1267 | ctx.hosts_.clear(); |
| 1268 | AllocEngine::findReservation(ctx); |
| 1269 | lease = engine_.allocateLease4(ctx); |
| 1270 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1270, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1271 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1271, gtest_ar.failure_message()) = ::testing::Message(); |
| 1272 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1272, gtest_ar.failure_message()) = ::testing::Message(); |
| 1273 | |
| 1274 | // Let's create a lease for the client in subnet2 to make sure the lease |
| 1275 | // is not renewed but a reserved lease is offered. |
| 1276 | Lease4Ptr lease3(new Lease4(IOAddress("10.1.2.55"), hwaddr_, ClientIdPtr(), |
| 1277 | 501, time(NULL__null), subnet2_->getID())); |
| 1278 | lease3->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 1279 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease3))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease3))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1279, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease3)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1280 | ctx.subnet_ = subnet1_; |
| 1281 | ctx.hosts_.clear(); |
| 1282 | AllocEngine::findReservation(ctx); |
| 1283 | lease = engine_.allocateLease4(ctx); |
| 1284 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1284, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1285 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1285, gtest_ar.failure_message()) = ::testing::Message(); |
| 1286 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1286, gtest_ar.failure_message()) = ::testing::Message(); |
| 1287 | } |
| 1288 | |
| 1289 | |
| 1290 | // Test that reservations within shared network take precedence over the |
| 1291 | // existing leases regardless in which subnet belonging to a shared network |
| 1292 | // reservations belong. Host lookups returning a collection are disabled. |
| 1293 | // As it is only an optimization the behavior (so the test) must stay |
| 1294 | // unchanged. |
| 1295 | 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" , 1295), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1295), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1295), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test ::TestBody() { |
| 1296 | |
| 1297 | // Disable host lookups returning a collection. |
| 1298 | ASSERT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance() .getDisableSingleQuery()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1299 | HostMgr::instance().setDisableSingleQuery(true); |
| 1300 | |
| 1301 | // Create reservation for the client. |
| 1302 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1303 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1304 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1305 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1306 | CfgMgr::instance().commit(); |
| 1307 | |
| 1308 | subnet1_->setReservationsGlobal(true); |
| 1309 | subnet1_->setReservationsInSubnet(true); |
| 1310 | subnet2_->setReservationsGlobal(true); |
| 1311 | subnet2_->setReservationsInSubnet(true); |
| 1312 | |
| 1313 | // Start allocation from subnet1. The engine should determine that the |
| 1314 | // client has reservations in subnet2 and should rather assign reserved |
| 1315 | // addresses. |
| 1316 | AllocEngine::ClientContext4 |
| 1317 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1318 | false, false, "host.example.com.", true); |
| 1319 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1320 | AllocEngine::findReservation(ctx); |
| 1321 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1322 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1322, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1323 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1323, gtest_ar.failure_message()) = ::testing::Message(); |
| 1324 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1324, gtest_ar.failure_message()) = ::testing::Message(); |
| 1325 | |
| 1326 | // Let's create a lease for the client to make sure the lease is not |
| 1327 | // renewed but a reserved lease is offered. |
| 1328 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1329 | 501, time(NULL__null), subnet1_->getID())); |
| 1330 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 1331 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1331, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1332 | ctx.subnet_ = subnet1_; |
| 1333 | ctx.hosts_.clear(); |
| 1334 | AllocEngine::findReservation(ctx); |
| 1335 | lease = engine_.allocateLease4(ctx); |
| 1336 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1336, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1337 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1337, gtest_ar.failure_message()) = ::testing::Message(); |
| 1338 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1338, gtest_ar.failure_message()) = ::testing::Message(); |
| 1339 | } |
| 1340 | |
| 1341 | // This test verifies that the server can offer an address from a shared |
| 1342 | // subnet if there's at least 1 address left there, but will not offer |
| 1343 | // anything if both subnets are completely full. |
| 1344 | 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", 1344 ), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1344), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1344), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_runningOut_Test >); void SharedNetworkAlloc4Test_runningOut_Test::TestBody () { |
| 1345 | |
| 1346 | // Allocate everything in subnet1 |
| 1347 | insertLease("192.0.2.17", subnet1_->getID()); |
| 1348 | |
| 1349 | // Allocate everything, except one address in subnet2. |
| 1350 | for (int i = 5; i < 100; i++) { |
| 1351 | stringstream tmp; |
| 1352 | tmp << "10.1.2." << i; |
| 1353 | insertLease(tmp.str(), subnet2_->getID()); |
| 1354 | } |
| 1355 | |
| 1356 | // Create context which will be used to try to allocate leases from the |
| 1357 | // shared network. The context points to subnet1, which address space |
| 1358 | // is exhausted. We expect the allocation engine to find another subnet |
| 1359 | // within the same shared network and offer an address from there. |
| 1360 | AllocEngine::ClientContext4 |
| 1361 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1362 | false, false, "host.example.com.", true); |
| 1363 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1364 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1365 | EXPECT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 1365, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1366 | |
| 1367 | // Now allocate the last address. Now both subnets are exhausted. |
| 1368 | insertLease("10.1.2.100", subnet2_->getID()); |
| 1369 | |
| 1370 | // Ok, we're out. We should not get anything now. |
| 1371 | lease = engine_.allocateLease4(ctx); |
| 1372 | ASSERT_FALSE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(lease))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 1373 | |
| 1374 | EXPECT_EQ(1, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\")" , 1, getStatistics("v4-allocation-fail")))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 1374, gtest_ar.failure_message()) = ::testing::Message(); |
| 1375 | EXPECT_EQ(1, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-shared-network\")" , 1, getStatistics("v4-allocation-fail-shared-network")))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1375, gtest_ar.failure_message()) = ::testing::Message(); |
| 1376 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")" , 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 1376, gtest_ar.failure_message()) = ::testing::Message(); |
| 1377 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")" , 0, getStatistics("v4-allocation-fail-no-pools")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 1377, gtest_ar.failure_message()) = ::testing::Message(); |
| 1378 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")" , 0, getStatistics("v4-allocation-fail-classes")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 1378, gtest_ar.failure_message()) = ::testing::Message(); |
| 1379 | |
| 1380 | EXPECT_EQ(1, getStatistics("v4-allocation-fail", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail\", subnet1_->getID())" , 1, getStatistics("v4-allocation-fail", subnet1_->getID() )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1380, gtest_ar.failure_message()) = ::testing::Message(); |
| 1381 | EXPECT_EQ(1, getStatistics("v4-allocation-fail-shared-network", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "getStatistics(\"v4-allocation-fail-shared-network\", subnet1_->getID())" , 1, getStatistics("v4-allocation-fail-shared-network", subnet1_ ->getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1381, gtest_ar.failure_message()) = ::testing::Message(); |
| 1382 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet1_->getID())" , 0, getStatistics("v4-allocation-fail-subnet", subnet1_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1382, gtest_ar.failure_message()) = ::testing::Message(); |
| 1383 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet1_->getID())" , 0, getStatistics("v4-allocation-fail-no-pools", subnet1_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1383, gtest_ar.failure_message()) = ::testing::Message(); |
| 1384 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet1_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet1_->getID())" , 0, getStatistics("v4-allocation-fail-classes", subnet1_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1384, gtest_ar.failure_message()) = ::testing::Message(); |
| 1385 | } |
| 1386 | |
| 1387 | // This test verifies that the server can offer an address from a |
| 1388 | // subnet and the introduction of shared network doesn't break anything here. |
| 1389 | 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" , 1389), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1389), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1389), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test ::TestBody() { |
| 1390 | |
| 1391 | // Create context which will be used to try to allocate leases from the |
| 1392 | // shared network. The context points to subnet1, which address space |
| 1393 | // is exhausted. We expect the allocation engine to find another subnet |
| 1394 | // within the same shared network and offer an address from there. |
| 1395 | AllocEngine::ClientContext4 |
| 1396 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1397 | false, false, "host.example.com.", false); |
| 1398 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1399 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1400 | |
| 1401 | // The allocation engine should have assigned an address from the first |
| 1402 | // subnet. |
| 1403 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1403, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1404 | EXPECT_EQ("192.0.2.17", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\"" , "lease->addr_.toText()", "192.0.2.17", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1404, gtest_ar.failure_message()) = ::testing::Message(); |
| 1405 | |
| 1406 | // Make sure the lease is in the lease mgr. |
| 1407 | ASSERT_TRUE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().getLease4(lease->addr_))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1407, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1408 | } |
| 1409 | |
| 1410 | // This test verifies that the server can allocate an address from a |
| 1411 | // different subnet than orginally selected, when the address pool in |
| 1412 | // the first subnet is exhausted. |
| 1413 | 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" , 1413), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1413), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1413), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetwork_Test >); void SharedNetworkAlloc4Test_requestSharedNetwork_Test ::TestBody() { |
| 1414 | |
| 1415 | // Create a lease for a single address in the first address pool. The |
| 1416 | // pool is now exhausted. |
| 1417 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
| 1418 | |
| 1419 | // Create context which will be used to try to allocate leases from the |
| 1420 | // shared network. The context points to subnet1, which address space |
| 1421 | // is exhausted. We expect the allocation engine to find another subnet |
| 1422 | // within the same shared network and offer an address from there. |
| 1423 | AllocEngine::ClientContext4 |
| 1424 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1425 | false, false, "host.example.com.", false); |
| 1426 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1427 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
| 1428 | // The allocation engine should have assigned an address from the second |
| 1429 | // subnet. We could guess that this is 10.1.2.5, being the first address |
| 1430 | // in the address pool, but to make the test more generic, we merely |
| 1431 | // verify that the address is in the given address pool. |
| 1432 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1432, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1433 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease2->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1433, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1434 | |
| 1435 | ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().deleteLease(lease2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1435, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease2)", "false", "true") .c_str()) = ::testing::Message(); |
| 1436 | |
| 1437 | // The client should also be assigned a lease when it specifies a hint |
| 1438 | // that doesn't match the subnet from which the lease is offered. The |
| 1439 | // engine should check alternative subnets to match the hint to |
| 1440 | // a subnet. The requested lease is available, so it should be offered. |
| 1441 | ctx.subnet_ = subnet1_; |
| 1442 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
| 1443 | lease2 = engine_.allocateLease4(ctx); |
| 1444 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1444, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1445 | EXPECT_EQ("10.1.2.25", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.25\"" , "lease2->addr_.toText()", "10.1.2.25", lease2->addr_. toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1445, gtest_ar.failure_message()) = ::testing::Message(); |
| 1446 | |
| 1447 | // The returning client (the one that has a lease) should also be able |
| 1448 | // to renew its lease regardless of a subnet it begins with. So, it has |
| 1449 | // an address assigned from subnet1, but we use subnet2 as a selected |
| 1450 | // subnet. |
| 1451 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
| 1452 | IOAddress("0.0.0.0"), false, false, |
| 1453 | "host.example.com.", false); |
| 1454 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1455 | lease2 = engine_.allocateLease4(ctx2); |
| 1456 | // The existing lease should be returned. |
| 1457 | ASSERT_TRUE(lease2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1457, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2", "false", "true") .c_str()) = ::testing::Message(); |
| 1458 | EXPECT_EQ("192.0.2.17", lease2->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.17\"" , "lease2->addr_.toText()", "192.0.2.17", lease2->addr_ .toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1458, gtest_ar.failure_message()) = ::testing::Message(); |
| 1459 | } |
| 1460 | |
| 1461 | // This test verifies that the server can assign an address from a |
| 1462 | // different subnet than orginally selected, when the address pool in |
| 1463 | // the first subnet is exhausted. |
| 1464 | 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" , 1464), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1464), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1464), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test ::TestBody() { |
| 1465 | // Try to offer address from subnet1. There is one address available |
| 1466 | // so it should be offered. |
| 1467 | AllocEngine::ClientContext4 |
| 1468 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1469 | false, false, "host.example.com.", false); |
| 1470 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1471 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1472 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1472, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1473 | EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1473, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1474 | |
| 1475 | // Remove the lease so as we can start over. |
| 1476 | ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().deleteLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1476, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1477 | |
| 1478 | // Apply restrictions on the subnet1. This should be only assigned |
| 1479 | // to clients belonging to cable-modem class. |
| 1480 | subnet1_->allowClientClass("cable-modem"); |
| 1481 | |
| 1482 | // The allocation engine should determine that the subnet1 is not |
| 1483 | // available for the client not belonging to the cable-modem class. |
| 1484 | // Instead, it should assign an address from subnet2 that belongs |
| 1485 | // to the same shared network. |
| 1486 | ctx.subnet_ = subnet1_; |
| 1487 | lease = engine_.allocateLease4(ctx); |
| 1488 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1488, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1489 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1489, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1490 | |
| 1491 | // Remove the lease so as we can start over. |
| 1492 | ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().deleteLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1492, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1493 | |
| 1494 | // Assign cable-modem class and try again. This time, we should |
| 1495 | // offer an address from the subnet1. |
| 1496 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1497 | |
| 1498 | ctx.subnet_ = subnet1_; |
| 1499 | lease = engine_.allocateLease4(ctx); |
| 1500 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1500, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1501 | EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1501, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1502 | |
| 1503 | // Let's now remove the client from the cable-modem class and try |
| 1504 | // to renew the address. The engine should determine that the |
| 1505 | // client doesn't have access to the subnet1 pools anymore and |
| 1506 | // assign an address from unrestricted subnet. |
| 1507 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1508 | ctx.subnet_ = subnet1_; |
| 1509 | lease = engine_.allocateLease4(ctx); |
| 1510 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1510, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1511 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1511, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1512 | } |
| 1513 | |
| 1514 | // This test verifies that the server can assign an address from a |
| 1515 | // different subnet than orginally selected, when the address pool in |
| 1516 | // the first subnet requires another class. |
| 1517 | 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" , 1517), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1517), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1517), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test ::TestBody() { |
| 1518 | // Try to offer address from subnet1. There is one address available |
| 1519 | // so it should be offered. |
| 1520 | AllocEngine::ClientContext4 |
| 1521 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1522 | false, false, "host.example.com.", false); |
| 1523 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1524 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1525 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1525, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1526 | EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1526, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1527 | |
| 1528 | // Remove the lease so as we can start over. |
| 1529 | ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().deleteLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1529, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1530 | |
| 1531 | // Apply restrictions on the pool1. This should be only assigned |
| 1532 | // to clients belonging to cable-modem class. |
| 1533 | pool1_->allowClientClass("cable-modem"); |
| 1534 | |
| 1535 | // The allocation engine should determine that the pool1 is not |
| 1536 | // available for the client not belonging to the cable-modem class. |
| 1537 | // Instead, it should assign an address from subnet2 that belongs |
| 1538 | // to the same shared network. |
| 1539 | ctx.subnet_ = subnet1_; |
| 1540 | lease = engine_.allocateLease4(ctx); |
| 1541 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1541, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1542 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1542, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1543 | |
| 1544 | // Remove the lease so as we can start over. |
| 1545 | ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().deleteLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1545, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1546 | |
| 1547 | // Assign cable-modem class and try again. This time, we should |
| 1548 | // offer an address from the pool1. |
| 1549 | ctx.query_->addClass(ClientClass("cable-modem")); |
| 1550 | |
| 1551 | // Restrict access to pool2 for this client, to make sure that the |
| 1552 | // server doesn't accidentally get an address from this pool. |
| 1553 | pool2_->allowClientClass("telephone"); |
| 1554 | |
| 1555 | ctx.subnet_ = subnet1_; |
| 1556 | lease = engine_.allocateLease4(ctx); |
| 1557 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1557, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1558 | EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1558, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1559 | |
| 1560 | // Let's now remove the client from the cable-modem class and try |
| 1561 | // to renew the address. The engine should determine that the |
| 1562 | // client doesn't have access to the pool1 anymore and |
| 1563 | // assign an address from another pool. |
| 1564 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1565 | ctx.query_->addClass(ClientClass("telephone")); |
| 1566 | ctx.subnet_ = subnet1_; |
| 1567 | lease = engine_.allocateLease4(ctx); |
| 1568 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1569 | EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2_->inPool(Lease ::TYPE_V4, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1569, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1570 | } |
| 1571 | |
| 1572 | // Test that reservations within shared network take precedence over the |
| 1573 | // existing leases regardless in which subnet belonging to a shared network |
| 1574 | // reservations belong (DHCPREQUEST case). |
| 1575 | 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" , 1575), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1575), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1575), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test ::TestBody() { |
| 1576 | |
| 1577 | EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance() .getDisableSingleQuery()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1578 | |
| 1579 | // Create reservation for the client. |
| 1580 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1581 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1582 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1583 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1584 | CfgMgr::instance().commit(); |
| 1585 | |
| 1586 | // Start allocation from subnet1. The engine should determine that the |
| 1587 | // client has reservations in subnet2 and should rather assign reserved |
| 1588 | // addresses. |
| 1589 | AllocEngine::ClientContext4 |
| 1590 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1591 | false, false, "host.example.com.", false); |
| 1592 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1593 | AllocEngine::findReservation(ctx); |
| 1594 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1595 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1596 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1596, gtest_ar.failure_message()) = ::testing::Message(); |
| 1597 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1597, gtest_ar.failure_message()) = ::testing::Message(); |
| 1598 | |
| 1599 | // Remove the lease for another test below. |
| 1600 | ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().deleteLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1600, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1601 | |
| 1602 | // Let's create a lease for the client to make sure the lease is not |
| 1603 | // renewed but a reserved lease is allocated again. |
| 1604 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1605 | 501, time(NULL__null), subnet1_->getID())); |
| 1606 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 1607 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1607, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1608 | ctx.subnet_ = subnet1_; |
| 1609 | ctx.hosts_.clear(); |
| 1610 | AllocEngine::findReservation(ctx); |
| 1611 | lease = engine_.allocateLease4(ctx); |
| 1612 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1612, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1613 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1613, gtest_ar.failure_message()) = ::testing::Message(); |
| 1614 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1614, gtest_ar.failure_message()) = ::testing::Message(); |
| 1615 | } |
| 1616 | |
| 1617 | // Test that reservations within shared network take precedence over the |
| 1618 | // existing leases regardless in which subnet belonging to a shared network |
| 1619 | // reservations belong (DHCPREQUEST case). Host lookups returning a collection |
| 1620 | // are disabled. As it is only an optimization the behavior (so the test) |
| 1621 | // must stay unchanged. |
| 1622 | 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" , 1622), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1622), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1622), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test ::TestBody() { |
| 1623 | |
| 1624 | // Disable host lookups returning a collection. |
| 1625 | ASSERT_FALSE(HostMgr::instance().getDisableSingleQuery())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(HostMgr::instance() .getDisableSingleQuery()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1625, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
| 1626 | HostMgr::instance().setDisableSingleQuery(true); |
| 1627 | |
| 1628 | // Create reservation for the client. |
| 1629 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 1630 | Host::IDENT_HWADDR, subnet2_->getID(), |
| 1631 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
| 1632 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 1633 | CfgMgr::instance().commit(); |
| 1634 | |
| 1635 | // Start allocation from subnet1. The engine should determine that the |
| 1636 | // client has reservations in subnet2 and should rather assign reserved |
| 1637 | // addresses. |
| 1638 | AllocEngine::ClientContext4 |
| 1639 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
| 1640 | false, false, "host.example.com.", false); |
| 1641 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1642 | AllocEngine::findReservation(ctx); |
| 1643 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
| 1644 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1644, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1645 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1645, gtest_ar.failure_message()) = ::testing::Message(); |
| 1646 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1646, gtest_ar.failure_message()) = ::testing::Message(); |
| 1647 | |
| 1648 | // Remove the lease for another test below. |
| 1649 | ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().deleteLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1649, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1650 | |
| 1651 | // Let's create a lease for the client to make sure the lease is not |
| 1652 | // renewed but a reserved lease is allocated again. |
| 1653 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
| 1654 | 501, time(NULL__null), subnet1_->getID())); |
| 1655 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
| 1656 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1657 | ctx.subnet_ = subnet1_; |
| 1658 | ctx.hosts_.clear(); |
| 1659 | AllocEngine::findReservation(ctx); |
| 1660 | lease = engine_.allocateLease4(ctx); |
| 1661 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1661, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1662 | EXPECT_EQ("10.1.2.105", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.105\"" , "lease->addr_.toText()", "10.1.2.105", lease->addr_.toText ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1662, gtest_ar.failure_message()) = ::testing::Message(); |
| 1663 | EXPECT_EQ(lease->subnet_id_, subnet2_->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("lease->subnet_id_" , "subnet2_->getID()", lease->subnet_id_, subnet2_-> getID()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1663, gtest_ar.failure_message()) = ::testing::Message(); |
| 1664 | } |
| 1665 | |
| 1666 | // This test checks if an expired lease can be reused in DHCPDISCOVER (fake |
| 1667 | // allocation) |
| 1668 | 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" , 1668), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1668), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1668), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseExpiredLease4_Test >); void AllocEngine4Test_discoverReuseExpiredLease4_Test:: TestBody() { |
| 1669 | boost::scoped_ptr<AllocEngine> engine; |
| 1670 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1670 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1670 ; } } else gtest_label_testnothrow_1670 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1670, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 1671 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1671, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1672 | |
| 1673 | IOAddress addr("192.0.2.15"); |
| 1674 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 1675 | // Get rid of the default test configuration. |
| 1676 | cfg_mgr.clear(); |
| 1677 | |
| 1678 | // Create configuration similar to other tests, but with a single address pool |
| 1679 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1680 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 1681 | subnet_->addPool(pool_); |
| 1682 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 1683 | |
| 1684 | // Just a different hw/client-id for the second client |
| 1685 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 1686 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 1687 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 1688 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
| 1689 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 1690 | 495, now, subnet_->getID())); |
| 1691 | // Copy the lease, so as it can be compared with the old lease returned |
| 1692 | // by the allocation engine. |
| 1693 | Lease4 original_lease(*lease); |
| 1694 | |
| 1695 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 1696 | // is expired already |
| 1697 | ASSERT_TRUE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease->expired())) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1697, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 1698 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1698, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1699 | |
| 1700 | // CASE 1: Asking for any address |
| 1701 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 1702 | IOAddress("0.0.0.0"), false, false, |
| 1703 | "", true); |
| 1704 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1705 | lease = engine->allocateLease4(ctx1); |
| 1706 | // Check that we got that single lease |
| 1707 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1707, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1708 | EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_" , addr, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1708, gtest_ar.failure_message()) = ::testing::Message(); |
| 1709 | |
| 1710 | // We are reusing expired lease, the old (expired) instance should be |
| 1711 | // returned. The returned instance should be the same as the original |
| 1712 | // lease. |
| 1713 | ASSERT_TRUE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx1.old_lease_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1713, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 1714 | EXPECT_TRUE(original_lease == *ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(original_lease == *ctx1 .old_lease_)) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1714, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
| 1715 | |
| 1716 | // Do all checks on the lease (if subnet-id, preferred/valid times are ok etc.) |
| 1717 | checkLease4(lease); |
| 1718 | |
| 1719 | // CASE 2: Asking specifically for this address |
| 1720 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 1721 | IOAddress(addr), false, false, |
| 1722 | "", true); |
| 1723 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 1724 | lease = engine->allocateLease4(ctx2); |
| 1725 | // Check that we got that single lease |
| 1726 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1727 | EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_" , addr, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1727, gtest_ar.failure_message()) = ::testing::Message(); |
| 1728 | |
| 1729 | // We are updating expired lease. The copy of the old lease should be |
| 1730 | // returned and it should be equal to the original lease. |
| 1731 | ASSERT_TRUE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx2.old_lease_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1731, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 1732 | EXPECT_TRUE(*ctx2.old_lease_ == original_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*ctx2.old_lease_ == original_lease )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1732, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*ctx2.old_lease_ == original_lease", "false", "true") .c_str ()) = ::testing::Message(); |
| 1733 | } |
| 1734 | |
| 1735 | // This test checks if an expired lease can be reused in REQUEST (actual allocation) |
| 1736 | 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" , 1736), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1736), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1736), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseExpiredLease4_Test >); void AllocEngine4Test_requestReuseExpiredLease4_Test:: TestBody() { |
| 1737 | boost::scoped_ptr<AllocEngine> engine; |
| 1738 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1738 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1738 ; } } else gtest_label_testnothrow_1738 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1738, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 1739 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1739, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1740 | |
| 1741 | IOAddress addr("192.0.2.105"); |
| 1742 | |
| 1743 | EXPECT_TRUE(testStatistics("assigned-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1743, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1744 | EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1744, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1745 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 1746 | subnet_->getID()); |
| 1747 | |
| 1748 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 1749 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 1750 | |
| 1751 | EXPECT_TRUE(testStatistics("reclaimed-leases", 0))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1751, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0)", "false", "true") .c_str()) = ::testing::Message(); |
| 1752 | EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1752, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1753 | |
| 1754 | // Just a different hw/client-id for the second client |
| 1755 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 1756 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 1757 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 1758 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
| 1759 | |
| 1760 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 1761 | 495, now, subnet_->getID())); |
| 1762 | // Make a copy of the lease, so as we can compare that with the old lease |
| 1763 | // instance returned by the allocation engine. |
| 1764 | Lease4 original_lease(*lease); |
| 1765 | |
| 1766 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 1767 | // is expired already |
| 1768 | ASSERT_TRUE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease->expired())) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 1769 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1769, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1770 | |
| 1771 | // A client comes along, asking specifically for this address |
| 1772 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 1773 | IOAddress(addr), false, false, |
| 1774 | "host.example.com.", false); |
| 1775 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 1776 | lease = engine->allocateLease4(ctx); |
| 1777 | |
| 1778 | // Check that he got that single lease |
| 1779 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1779, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 1780 | EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_" , addr, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1780, gtest_ar.failure_message()) = ::testing::Message(); |
| 1781 | |
| 1782 | // Check that the lease is indeed updated in LeaseMgr |
| 1783 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 1784 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 1785 | |
| 1786 | // Now check that the lease in LeaseMgr has the same parameters |
| 1787 | detailCompareLease(lease, from_mgr); |
| 1788 | |
| 1789 | // The allocation engine should return a copy of the old lease. This |
| 1790 | // lease should be equal to the original lease. |
| 1791 | ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1791, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 1792 | EXPECT_TRUE(*ctx.old_lease_ == original_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*ctx.old_lease_ == original_lease )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1792, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*ctx.old_lease_ == original_lease", "false", "true") .c_str ()) = ::testing::Message(); |
| 1793 | |
| 1794 | // Check that the stats declined stats were modified correctly. Note, because |
| 1795 | // added the lease directly, assigned-leases never bumped to one, so when we |
| 1796 | // reclaim it gets decremented to -1, then on assignment back to 0. |
| 1797 | EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1797, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1798 | cumulative += 1; |
| 1799 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 1800 | cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1801 | EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , glbl_assigned))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1801, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1802 | glbl_cumulative += 1; |
| 1803 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , glbl_cumulative))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 1804 | EXPECT_TRUE(testStatistics("reclaimed-leases", 1))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1804, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1)", "false", "true") .c_str()) = ::testing::Message(); |
| 1805 | EXPECT_TRUE(testStatistics("reclaimed-leases", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1805, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1806 | } |
| 1807 | |
| 1808 | // This test checks if an expired declined lease can be reused when responding |
| 1809 | // to DHCPDISCOVER (fake allocation) |
| 1810 | 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" , 1810), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1810), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1810), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4_Test ::TestBody() { |
| 1811 | |
| 1812 | AllocEnginePtr engine(new AllocEngine(0)); |
| 1813 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1813, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1814 | |
| 1815 | // Now prepare a configuration with single address pool. |
| 1816 | IOAddress addr("192.0.2.15"); |
| 1817 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 1818 | cfg_mgr.clear(); |
| 1819 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1820 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 1821 | subnet_->addPool(pool_); |
| 1822 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 1823 | |
| 1824 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 1825 | // is expired. |
| 1826 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 1827 | |
| 1828 | // CASE 1: Ask for any address |
| 1829 | Lease4Ptr assigned; |
| 1830 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
| 1831 | |
| 1832 | // Check that we got that single lease |
| 1833 | ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1833, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 1834 | EXPECT_EQ(addr, assigned->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "assigned->addr_" , addr, assigned->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1834, gtest_ar.failure_message()) = ::testing::Message(); |
| 1835 | |
| 1836 | // CASE 2: Asking specifically for this address |
| 1837 | testReuseLease4(engine, declined, "192.0.2.15", true, SHOULD_PASS, assigned); |
| 1838 | |
| 1839 | // Check that we get it again |
| 1840 | ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1840, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 1841 | EXPECT_EQ(addr, assigned->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "assigned->addr_" , addr, assigned->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1841, gtest_ar.failure_message()) = ::testing::Message(); |
| 1842 | } |
| 1843 | |
| 1844 | // This test checks if statistics are not updated when expired declined lease |
| 1845 | // is reused when responding to DHCPDISCOVER (fake allocation) |
| 1846 | 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" , 1846), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1846), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1846), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test ::TestBody() { |
| 1847 | |
| 1848 | // Now prepare for DISCOVER processing |
| 1849 | AllocEnginePtr engine(new AllocEngine(0)); |
| 1850 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1850, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1851 | |
| 1852 | // Now prepare a configuration with single address pool. |
| 1853 | IOAddress addr("192.0.2.15"); |
| 1854 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 1855 | cfg_mgr.clear(); |
| 1856 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1857 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 1858 | subnet_->addPool(pool_); |
| 1859 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 1860 | cfg_mgr.commit(); // so we will recalc stats |
| 1861 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 1862 | subnet_->getID()); |
| 1863 | |
| 1864 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 1865 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 1866 | |
| 1867 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 1868 | // is expired. |
| 1869 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 1870 | |
| 1871 | // Ask for any address. There's only one address in the pool, so it doesn't |
| 1872 | // matter much. |
| 1873 | Lease4Ptr assigned; |
| 1874 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
| 1875 | |
| 1876 | // Check that the stats declined stats were not modified |
| 1877 | EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1877, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1878 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1879, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 1879 | cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1879, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1880 | EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , glbl_assigned))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1881 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , glbl_cumulative))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1881, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 1882 | EXPECT_TRUE(testStatistics("declined-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses" , 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1882, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", 0)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1883 | EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses" , 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1883, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 0)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1884 | EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1884, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1885 | EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1885, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1886 | } |
| 1887 | |
| 1888 | // This test checks if an expired declined lease can be reused when responding |
| 1889 | // to REQUEST (actual allocation) |
| 1890 | 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" , 1890), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1890), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1890), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4_Test >); void AllocEngine4Test_requestReuseDeclinedLease4_Test:: TestBody() { |
| 1891 | |
| 1892 | AllocEnginePtr engine(new AllocEngine(0)); |
| 1893 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1893, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1894 | |
| 1895 | // Now prepare a configuration with single address pool. |
| 1896 | IOAddress addr("192.0.2.15"); |
| 1897 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 1898 | cfg_mgr.clear(); |
| 1899 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1900 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 1901 | subnet_->addPool(pool_); |
| 1902 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 1903 | |
| 1904 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 1905 | // is expired. |
| 1906 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 1907 | |
| 1908 | // Asking specifically for this address |
| 1909 | Lease4Ptr assigned; |
| 1910 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
| 1911 | // Check that we got it. |
| 1912 | ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1912, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 1913 | EXPECT_EQ(addr, assigned->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "assigned->addr_" , addr, assigned->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1913, gtest_ar.failure_message()) = ::testing::Message(); |
| 1914 | |
| 1915 | // Check that the lease is indeed updated in LeaseMgr |
| 1916 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 1917 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1917, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 1918 | |
| 1919 | // Now check that the lease in LeaseMgr has the same parameters |
| 1920 | detailCompareLease(assigned, from_mgr); |
| 1921 | } |
| 1922 | |
| 1923 | // This test checks if statistics are not updated when expired declined lease |
| 1924 | // is reused when responding to DHCPREQUEST (actual allocation) |
| 1925 | 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" , 1925), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1925), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1925), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_requestReuseDeclinedLease4Stats_Test ::TestBody() { |
| 1926 | |
| 1927 | AllocEnginePtr engine(new AllocEngine(0)); |
| 1928 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1928, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1929 | |
| 1930 | // Now prepare a configuration with single address pool. |
| 1931 | IOAddress addr("192.0.2.15"); |
| 1932 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 1933 | cfg_mgr.clear(); |
| 1934 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 1935 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 1936 | subnet_->addPool(pool_); |
| 1937 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 1938 | cfg_mgr.commit(); |
| 1939 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 1940 | subnet_->getID()); |
| 1941 | |
| 1942 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 1943 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 1944 | |
| 1945 | // Now create a declined lease, decline it and rewind its cltt, so it |
| 1946 | // is expired. |
| 1947 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
| 1948 | |
| 1949 | // Asking specifically for this address |
| 1950 | Lease4Ptr assigned; |
| 1951 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
| 1952 | // Check that we got it. |
| 1953 | ASSERT_TRUE(assigned)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(assigned)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1953, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "assigned", "false", "true") .c_str()) = ::testing::Message (); |
| 1954 | |
| 1955 | // Check that the stats are correct. Note that assigned-addresses does |
| 1956 | // not get decremented when a lease is declined, ergo not incremented |
| 1957 | // when it is reused. Declined address stats will be -1 since |
| 1958 | // lease was created as declined which does not increment the stat. |
| 1959 | EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1959, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1960 | cumulative += 1; |
| 1961 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1962, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 1962 | cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1962, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1963 | EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , glbl_assigned))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1963, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1964 | glbl_cumulative += 1; |
| 1965 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , glbl_cumulative))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1965, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 1966 | EXPECT_TRUE(testStatistics("declined-addresses", -1))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses" , -1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1966, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", -1)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 1967 | EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses" , 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1967, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 1)", "false" , "true") .c_str()) = ::testing::Message(); |
| 1968 | EXPECT_TRUE(testStatistics("declined-addresses", -1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("declined-addresses" , -1, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1968, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", -1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1969 | EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-declined-addresses" , 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1969, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1970 | } |
| 1971 | |
| 1972 | // This test checks if a released lease can be reused in REQUEST (actual allocation) |
| 1973 | 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" , 1973), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1973), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1973), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseReleasedLease4_Test >); void AllocEngine4Test_requestReuseReleasedLease4_Test:: TestBody() { |
| 1974 | boost::scoped_ptr<AllocEngine> engine; |
| 1975 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { engine.reset(new AllocEngine(0)); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1975 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1975 ; } } else gtest_label_testnothrow_1975 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1975, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 1976 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1976, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 1977 | |
| 1978 | IOAddress addr("192.0.2.105"); |
| 1979 | |
| 1980 | EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1980, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1981 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 1982 | subnet_->getID()); |
| 1983 | |
| 1984 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 1985 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 1986 | |
| 1987 | EXPECT_TRUE(testStatistics("reclaimed-leases", 0))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 0))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1987, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0)", "false", "true") .c_str()) = ::testing::Message(); |
| 1988 | EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 0, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 1988, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 1989 | |
| 1990 | // Just a different hw/client-id for the second client |
| 1991 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 1992 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 1993 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 1994 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
| 1995 | |
| 1996 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 1997 | 495, now, subnet_->getID())); |
| 1998 | lease->state_ = Lease4::STATE_RELEASED; |
| 1999 | // Make a copy of the lease, so as we can compare that with the old lease |
| 2000 | // instance returned by the allocation engine. |
| 2001 | Lease4 original_lease(*lease); |
| 2002 | |
| 2003 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 2004 | // is expired already |
| 2005 | ASSERT_TRUE(lease->expired())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease->expired())) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2005, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 2006 | ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().addLease(lease))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2006, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 2007 | |
| 2008 | // A client comes along, asking specifically for this address |
| 2009 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2010 | IOAddress(addr), false, false, |
| 2011 | "host.example.com.", false); |
| 2012 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2013 | lease = engine->allocateLease4(ctx); |
| 2014 | |
| 2015 | // Check that he got that single lease |
| 2016 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2016, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2017 | EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_" , addr, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2017, gtest_ar.failure_message()) = ::testing::Message(); |
| 2018 | |
| 2019 | // Check that the lease is indeed updated in LeaseMgr |
| 2020 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 2021 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2021, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2022 | |
| 2023 | // Now check that the lease in LeaseMgr has the same parameters |
| 2024 | detailCompareLease(lease, from_mgr); |
| 2025 | |
| 2026 | // The allocation engine should return a copy of the old lease. This |
| 2027 | // lease should be equal to the original lease. |
| 2028 | ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2028, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 2029 | EXPECT_TRUE(*ctx.old_lease_ == original_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*ctx.old_lease_ == original_lease )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2029, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*ctx.old_lease_ == original_lease", "false", "true") .c_str ()) = ::testing::Message(); |
| 2030 | |
| 2031 | EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2031, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2032 | cumulative += 1; |
| 2033 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2034, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 2034 | cumulative, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , cumulative, subnet_->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2034, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2035 | glbl_assigned += 1; |
| 2036 | EXPECT_TRUE(testStatistics("assigned-addresses", glbl_assigned))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("assigned-addresses" , glbl_assigned))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2036, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2037 | glbl_cumulative += 1; |
| 2038 | EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("cumulative-assigned-addresses" , glbl_cumulative))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2039 | EXPECT_TRUE(testStatistics("reclaimed-leases", 1))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 1))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2039, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1)", "false", "true") .c_str()) = ::testing::Message(); |
| 2040 | EXPECT_TRUE(testStatistics("reclaimed-leases", 1, subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(testStatistics("reclaimed-leases" , 1, subnet_->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2040, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 2041 | } |
| 2042 | |
| 2043 | // This test checks that the Allocation Engine correctly identifies the |
| 2044 | // existing client's lease in the lease database, using the client |
| 2045 | // identifier and HW address. |
| 2046 | 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" , 2046), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2046), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2046), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_identifyClientLease_Test >); void AllocEngine4Test_identifyClientLease_Test::TestBody () { |
| 2047 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, clientid_, |
| 2048 | 100, time(NULL__null), subnet_->getID())); |
| 2049 | LeaseMgrFactory::instance().addLease(lease); |
| 2050 | |
| 2051 | AllocEngine engine(0); |
| 2052 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2053 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 2054 | false, false, "", true); |
| 2055 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2056 | |
| 2057 | Lease4Ptr identified_lease = engine.allocateLease4(ctx); |
| 2058 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2058, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2059 | EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\"" , "identified_lease->addr_.toText()", "192.0.2.101", identified_lease ->addr_.toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2059, gtest_ar.failure_message()) = ::testing::Message(); |
| 2060 | |
| 2061 | ctx.hwaddr_ = hwaddr2_; |
| 2062 | ctx.clientid_ = clientid_; |
| 2063 | identified_lease = engine.allocateLease4(ctx); |
| 2064 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2065 | EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\"" , "identified_lease->addr_.toText()", "192.0.2.101", identified_lease ->addr_.toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2065, gtest_ar.failure_message()) = ::testing::Message(); |
| 2066 | |
| 2067 | ctx.hwaddr_ = hwaddr_; |
| 2068 | ctx.clientid_ = clientid2_; |
| 2069 | identified_lease = engine.allocateLease4(ctx); |
| 2070 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2070, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2071 | EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("identified_lease->addr_.toText()" , "\"192.0.2.101\"", identified_lease->addr_.toText(), "192.0.2.101" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2071, gtest_ar.failure_message()) = ::testing::Message(); |
| 2072 | |
| 2073 | ctx.hwaddr_ = hwaddr_; |
| 2074 | ctx.clientid_.reset(); |
| 2075 | identified_lease = engine.allocateLease4(ctx); |
| 2076 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2076, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2077 | EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\"" , "identified_lease->addr_.toText()", "192.0.2.101", identified_lease ->addr_.toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2077, gtest_ar.failure_message()) = ::testing::Message(); |
| 2078 | |
| 2079 | ctx.hwaddr_ = hwaddr2_; |
| 2080 | ctx.clientid_.reset(); |
| 2081 | identified_lease = engine.allocateLease4(ctx); |
| 2082 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2082, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2083 | EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("identified_lease->addr_.toText()" , "\"192.0.2.101\"", identified_lease->addr_.toText(), "192.0.2.101" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2083, gtest_ar.failure_message()) = ::testing::Message(); |
| 2084 | |
| 2085 | lease->client_id_.reset(); |
| 2086 | ASSERT_NO_THROW(LeaseMgrFactory::instance().updateLease4(lease))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { LeaseMgrFactory::instance().updateLease4(lease); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2086; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2086; } } else gtest_label_testnothrow_2086 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2086, ("Expected: " "LeaseMgrFactory::instance().updateLease4(lease)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 2087 | |
| 2088 | ctx.hwaddr_ = hwaddr_; |
| 2089 | ctx.clientid_ = clientid_; |
| 2090 | identified_lease = engine.allocateLease4(ctx); |
| 2091 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2091, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2092 | EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\"" , "identified_lease->addr_.toText()", "192.0.2.101", identified_lease ->addr_.toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2092, gtest_ar.failure_message()) = ::testing::Message(); |
| 2093 | |
| 2094 | ctx.hwaddr_ = hwaddr_; |
| 2095 | ctx.clientid_.reset(); |
| 2096 | identified_lease = engine.allocateLease4(ctx); |
| 2097 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2097, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2098 | EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\"" , "identified_lease->addr_.toText()", "192.0.2.101", identified_lease ->addr_.toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2098, gtest_ar.failure_message()) = ::testing::Message(); |
| 2099 | |
| 2100 | ctx.hwaddr_ = hwaddr2_; |
| 2101 | ctx.clientid_ = clientid_; |
| 2102 | identified_lease = engine.allocateLease4(ctx); |
| 2103 | ASSERT_TRUE(identified_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(identified_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2103, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "identified_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2104 | EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("identified_lease->addr_.toText()" , "\"192.0.2.101\"", identified_lease->addr_.toText(), "192.0.2.101" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2104, gtest_ar.failure_message()) = ::testing::Message(); |
| 2105 | } |
| 2106 | |
| 2107 | // This test checks that when the client requests the address which belongs |
| 2108 | // to another client, the allocation engine returns NULL (for the |
| 2109 | // DHCPREQUEST case) or a lease for the address which belongs to this |
| 2110 | // client (DHCPDISCOVER case). |
| 2111 | 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" , 2111), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2111), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2111), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestOtherClientLease_Test >); void AllocEngine4Test_requestOtherClientLease_Test::TestBody () { |
| 2112 | // Create the first lease. |
| 2113 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2114 | &clientid_->getClientId()[0], |
| 2115 | clientid_->getClientId().size(), |
| 2116 | 100, time(NULL__null), subnet_->getID(), |
| 2117 | false, false, "")); |
| 2118 | // Create the second lease. Note that we use the same client id here and |
| 2119 | // we expect that the allocation engine will figure out that the hardware |
| 2120 | // address is different. |
| 2121 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr2_, |
| 2122 | &clientid_->getClientId()[0], |
| 2123 | clientid_->getClientId().size(), |
| 2124 | 100, time(NULL__null), subnet_->getID(), |
| 2125 | false, false, "")); |
| 2126 | // Add leases for both clients to the Lease Manager. |
| 2127 | LeaseMgrFactory::instance().addLease(lease); |
| 2128 | LeaseMgrFactory::instance().addLease(lease2); |
| 2129 | |
| 2130 | AllocEngine engine(0); |
| 2131 | |
| 2132 | // First client requests the lease which belongs to the second client. |
| 2133 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
| 2134 | false, false, "", false); |
| 2135 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2136 | Lease4Ptr new_lease = engine.allocateLease4(ctx); |
| 2137 | // Allocation engine should return NULL. |
| 2138 | ASSERT_FALSE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(new_lease))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2138, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "true", "false") .c_str()) = ::testing::Message (); |
| 2139 | |
| 2140 | EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")" , 0, getStatistics("v4-allocation-fail")))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2140, gtest_ar.failure_message()) = ::testing::Message(); |
| 2141 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")" , 0, getStatistics("v4-allocation-fail-shared-network")))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2141, gtest_ar.failure_message()) = ::testing::Message(); |
| 2142 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")" , 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2142, gtest_ar.failure_message()) = ::testing::Message(); |
| 2143 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")" , 0, getStatistics("v4-allocation-fail-no-pools")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2143, gtest_ar.failure_message()) = ::testing::Message(); |
| 2144 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")" , 0, getStatistics("v4-allocation-fail-classes")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2144, gtest_ar.failure_message()) = ::testing::Message(); |
| 2145 | |
| 2146 | EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail", subnet_->getID()) ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2146, gtest_ar.failure_message()) = ::testing::Message(); |
| 2147 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-shared-network", subnet_ ->getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2147, gtest_ar.failure_message()) = ::testing::Message(); |
| 2148 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2148, gtest_ar.failure_message()) = ::testing::Message(); |
| 2149 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-no-pools", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2149, gtest_ar.failure_message()) = ::testing::Message(); |
| 2150 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-classes", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2150, gtest_ar.failure_message()) = ::testing::Message(); |
| 2151 | |
| 2152 | // Now simulate the DHCPDISCOVER case when the provided address is |
| 2153 | // treated as a hint. The engine should return a lease for a |
| 2154 | // different address than requested. |
| 2155 | ctx.fake_allocation_ = true; |
| 2156 | new_lease = engine.allocateLease4(ctx); |
| 2157 | ASSERT_TRUE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(new_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2157, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 2158 | EXPECT_EQ("192.0.2.101", new_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\"" , "new_lease->addr_.toText()", "192.0.2.101", new_lease-> addr_.toText()))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2158, gtest_ar.failure_message()) = ::testing::Message(); |
| 2159 | } |
| 2160 | |
| 2161 | // Allocation engine should remove a pre-existing lease |
| 2162 | // and renew the temporary lease when offer-lifetime > 0. |
| 2163 | // This can happen when a client gets a lease which is |
| 2164 | // later rendered invalid by the creation of host reservation, |
| 2165 | // either for the lease address or for the client with |
| 2166 | // a different address. |
| 2167 | 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" , 2167), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2167), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2167), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_existingLeasePlusTemporary_Test >); void AllocEngine4Test_existingLeasePlusTemporary_Test:: TestBody() { |
| 2168 | // Create the first lease. |
| 2169 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2170 | &clientid_->getClientId()[0], |
| 2171 | clientid_->getClientId().size(), |
| 2172 | 100, time(NULL__null), subnet_->getID(), |
| 2173 | false, false, "")); |
| 2174 | |
| 2175 | // Create the second lease. |
| 2176 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr_, |
| 2177 | &clientid_->getClientId()[0], |
| 2178 | clientid_->getClientId().size(), |
| 2179 | 100, time(NULL__null), subnet_->getID(), |
| 2180 | false, false, "")); |
| 2181 | // Add leases for both clients to the Lease Manager. |
| 2182 | LeaseMgrFactory::instance().addLease(lease); |
| 2183 | LeaseMgrFactory::instance().addLease(lease2); |
| 2184 | |
| 2185 | // When temporary allocations are off and client requests the |
| 2186 | // second lease, the engine should not return a lease. |
| 2187 | AllocEngine engine(0); |
| 2188 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
| 2189 | false, false, "", false); |
| 2190 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2191 | Lease4Ptr new_lease = engine.allocateLease4(ctx); |
| 2192 | |
| 2193 | ASSERT_FALSE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(new_lease))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "true", "false") .c_str()) = ::testing::Message (); |
| 2194 | |
| 2195 | // Both leases should still be in the lease back end. |
| 2196 | ASSERT_TRUE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().getLease4(lease->addr_))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2196, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2197 | ASSERT_TRUE(LeaseMgrFactory::instance().getLease4(lease2->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(LeaseMgrFactory::instance ().getLease4(lease2->addr_))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2197, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 2198 | |
| 2199 | // Now enable temporary allocations by setting offer lifetime > 0. |
| 2200 | subnet_->setOfferLft(120); |
| 2201 | |
| 2202 | // Client requests the second lease. |
| 2203 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
| 2204 | false, false, "", false); |
| 2205 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2206 | new_lease = engine.allocateLease4(ctx2); |
| 2207 | |
| 2208 | // Allocation should return the second lease and remove the original lease. |
| 2209 | ASSERT_TRUE(new_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(new_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2209, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "new_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 2210 | EXPECT_EQ("192.0.2.102", new_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.102\"" , "new_lease->addr_.toText()", "192.0.2.102", new_lease-> addr_.toText()))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2210, gtest_ar.failure_message()) = ::testing::Message(); |
| 2211 | |
| 2212 | // Original lease should have been deleted from lease back. |
| 2213 | ASSERT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance ().getLease4(lease->addr_)))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2213, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 2214 | } |
| 2215 | |
| 2216 | // This test checks the behavior of the allocation engine in the following |
| 2217 | // scenario: |
| 2218 | // - Client has no lease in the database. |
| 2219 | // - Client has a reservation. |
| 2220 | // - Client sends DHCPREQUEST without requested IP Address, nor ciaddr. |
| 2221 | // - Client is allocated a reserved address. |
| 2222 | // |
| 2223 | // Note that client must normally include a requested IP address or ciaddr |
| 2224 | // in its message. But, we still want to provision clients that don't do that. |
| 2225 | // The server simply picks reserved address or any other available one if there |
| 2226 | // is no reservation. |
| 2227 | 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" , 2227), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2227), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2227), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHint_Test >); void AllocEngine4Test_reservedAddressNoHint_Test::TestBody () { |
| 2228 | // Create reservation for the client. |
| 2229 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2230 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2231 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2232 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2233 | CfgMgr::instance().commit(); |
| 2234 | |
| 2235 | AllocEngine engine(0); |
| 2236 | |
| 2237 | // Try to allocate a lease without specifying a hint. This is actually |
| 2238 | // incorrect behavior of the client to not send an address it wants to |
| 2239 | // obtain but the server should handle this gracefully. |
| 2240 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2241 | IOAddress("0.0.0.0"), false, false, |
| 2242 | "", false); |
| 2243 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2244 | AllocEngine::findReservation(ctx); |
| 2245 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 2246 | |
| 2247 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2247, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2248 | EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\"" , "lease->addr_.toText()", "192.0.2.123", lease->addr_. toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2248, gtest_ar.failure_message()) = ::testing::Message(); |
| 2249 | |
| 2250 | // Make sure that the lease has been committed to the lease database. |
| 2251 | // And that the committed lease is equal to the one returned. |
| 2252 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2253 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2253, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2254 | detailCompareLease(lease, from_mgr); |
| 2255 | |
| 2256 | // Initially, there was no lease for this client, so the returned old |
| 2257 | // lease should be NULL. |
| 2258 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2258, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 2259 | } |
| 2260 | |
| 2261 | // This test checks behavior of the allocation engine in the following scenario: |
| 2262 | // - Client has no lease in the database. |
| 2263 | // - Client has a reservation. |
| 2264 | // - Client sends DHCPDISCOVER without requested IP Address. |
| 2265 | // - Server returns DHCPOFFER with the reserved address. |
| 2266 | 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" , 2266), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2266), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2266), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test ::TestBody() { |
| 2267 | // Create reservation for the client. |
| 2268 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2269 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2270 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2271 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2272 | CfgMgr::instance().commit(); |
| 2273 | |
| 2274 | AllocEngine engine(0); |
| 2275 | |
| 2276 | // Query allocation engine for the lease to be assigned to this |
| 2277 | // client without specifying the address to be assigned. |
| 2278 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2279 | IOAddress("0.0.0.0"), false, false, |
| 2280 | "", true); |
| 2281 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 2282 | AllocEngine::findReservation(ctx); |
| 2283 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 2284 | |
| 2285 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2285, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2286 | // The allocation engine should return a reserved address. |
| 2287 | EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\"" , "lease->addr_.toText()", "192.0.2.123", lease->addr_. toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2287, gtest_ar.failure_message()) = ::testing::Message(); |
| 2288 | |
| 2289 | // This is a "fake" allocation so the returned lease should not be committed |
| 2290 | // to the lease database. |
| 2291 | EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance ().getLease4(lease->addr_)))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2291, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 2292 | |
| 2293 | // Client had no lease in the database, so the old lease returned should |
| 2294 | // be NULL. |
| 2295 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2295, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 2296 | } |
| 2297 | |
| 2298 | // This test checks the behavior of the allocation engine in the following |
| 2299 | // scenario: |
| 2300 | // - Client has no lease in the database. |
| 2301 | // - Client has a reservation. |
| 2302 | // - Client sends DHCPREQUEST with a requested IP address |
| 2303 | // - Server returns DHCPNAK when requested IP address is different than |
| 2304 | // the reserved address. Note that the allocation engine returns NULL |
| 2305 | // to indicate to the server that it should send DHCPNAK. |
| 2306 | // - Server allocates a reserved address to the client when the client requests |
| 2307 | // this address using requested IP address option. |
| 2308 | 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" , 2308), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2308), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2308), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHint_Test >); void AllocEngine4Test_reservedAddressHint_Test::TestBody () { |
| 2309 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2310 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2311 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2312 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2313 | CfgMgr::instance().commit(); |
| 2314 | |
| 2315 | AllocEngine engine(0); |
| 2316 | |
| 2317 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2318 | IOAddress("192.0.2.234"), false, false, |
| 2319 | "", false); |
| 2320 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2321 | AllocEngine::findReservation(ctx1); |
| 2322 | Lease4Ptr lease = engine.allocateLease4(ctx1); |
| 2323 | |
| 2324 | // The client requested a different address than reserved, so |
| 2325 | // the allocation engine should return NULL lease. When the server |
| 2326 | // receives a NULL lease for the client, it will send a DHCPNAK. |
| 2327 | ASSERT_FALSE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(lease))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2327, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 2328 | ASSERT_FALSE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx1.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2328, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2329 | |
| 2330 | EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")" , 0, getStatistics("v4-allocation-fail")))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2330, gtest_ar.failure_message()) = ::testing::Message(); |
| 2331 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")" , 0, getStatistics("v4-allocation-fail-shared-network")))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2331, gtest_ar.failure_message()) = ::testing::Message(); |
| 2332 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")" , 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2332, gtest_ar.failure_message()) = ::testing::Message(); |
| 2333 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")" , 0, getStatistics("v4-allocation-fail-no-pools")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2333, gtest_ar.failure_message()) = ::testing::Message(); |
| 2334 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")" , 0, getStatistics("v4-allocation-fail-classes")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2334, gtest_ar.failure_message()) = ::testing::Message(); |
| 2335 | |
| 2336 | EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail", subnet_->getID()) ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2336, gtest_ar.failure_message()) = ::testing::Message(); |
| 2337 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-shared-network", subnet_ ->getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2337, gtest_ar.failure_message()) = ::testing::Message(); |
| 2338 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2338, gtest_ar.failure_message()) = ::testing::Message(); |
| 2339 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-no-pools", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2339, gtest_ar.failure_message()) = ::testing::Message(); |
| 2340 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-classes", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2340, gtest_ar.failure_message()) = ::testing::Message(); |
| 2341 | |
| 2342 | // Now, request a correct address. The client should obtain it. |
| 2343 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2344 | IOAddress("192.0.2.123"), false, false, |
| 2345 | "", false); |
| 2346 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2347 | AllocEngine::findReservation(ctx2); |
| 2348 | lease = engine.allocateLease4(ctx2); |
| 2349 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2349, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2350 | EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\"" , "lease->addr_.toText()", "192.0.2.123", lease->addr_. toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2350, gtest_ar.failure_message()) = ::testing::Message(); |
| 2351 | |
| 2352 | // Make sure that the lease has been committed to the lease database. |
| 2353 | // And that the committed lease is equal to the one returned. |
| 2354 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2355 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2355, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2356 | detailCompareLease(lease, from_mgr); |
| 2357 | |
| 2358 | ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2358, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2359 | } |
| 2360 | |
| 2361 | // This test checks the behavior of the allocation engine in the following |
| 2362 | // scenario: |
| 2363 | // - Client has no lease in the database. |
| 2364 | // - Client has a reservation. |
| 2365 | // - Client sends DHCPDISCOVER with a requested IP address as a hint. |
| 2366 | // - Server offers a reserved address, even though it is different than the |
| 2367 | // requested address. |
| 2368 | 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" , 2368), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2368), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2368), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHintFakeAllocation_Test ::TestBody() { |
| 2369 | // Create a reservation for the client. |
| 2370 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2371 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2372 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2373 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2374 | CfgMgr::instance().commit(); |
| 2375 | |
| 2376 | AllocEngine engine(0); |
| 2377 | |
| 2378 | // Query the allocation engine for the lease to be assigned to the client |
| 2379 | // and specify a hint being a different address than the reserved one. |
| 2380 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2381 | IOAddress("192.0.2.234"), false, false, |
| 2382 | "", true); |
| 2383 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2384 | AllocEngine::findReservation(ctx); |
| 2385 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 2386 | |
| 2387 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2387, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 2388 | // Allocation engine should return reserved address. |
| 2389 | EXPECT_EQ("192.0.2.123", lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\"" , "lease->addr_.toText()", "192.0.2.123", lease->addr_. toText()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2389, gtest_ar.failure_message()) = ::testing::Message(); |
| 2390 | |
| 2391 | // This is a "fake" allocation so the returned lease should not be committed |
| 2392 | // to the lease database. |
| 2393 | EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(LeaseMgrFactory::instance ().getLease4(lease->addr_)))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2393, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 2394 | |
| 2395 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2395, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 2396 | } |
| 2397 | |
| 2398 | // This test checks that the behavior of the allocation engine in the following |
| 2399 | // scenario: |
| 2400 | // - Client has a lease for the address from the dynamic pool in the database. |
| 2401 | // - Client has a reservation for a different address than the one for which |
| 2402 | // the client has a lease. |
| 2403 | // - Client sends DHCPREQUEST, asking for the reserved address (as it has been |
| 2404 | // offered to it when it sent DHCPDISCOVER). |
| 2405 | // - Server allocates a reserved address and removes the lease for the address |
| 2406 | // previously allocated to the client. |
| 2407 | 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" , 2407), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2407), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2407), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLease_Test >); void AllocEngine4Test_reservedAddressExistingLease_Test ::TestBody() { |
| 2408 | // Create the reservation for the client. |
| 2409 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2410 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2411 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2412 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2413 | CfgMgr::instance().commit(); |
| 2414 | |
| 2415 | // Create a lease for the client with a different address than the reserved |
| 2416 | // one. |
| 2417 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2418 | &clientid_->getClientId()[0], |
| 2419 | clientid_->getClientId().size(), |
| 2420 | 100, time(NULL__null), subnet_->getID(), |
| 2421 | false, false, "")); |
| 2422 | LeaseMgrFactory::instance().addLease(lease); |
| 2423 | |
| 2424 | AllocEngine engine(0); |
| 2425 | |
| 2426 | // Request allocation of the reserved address. |
| 2427 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2428 | IOAddress("192.0.2.123"), false, false, |
| 2429 | "", false); |
| 2430 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2431 | AllocEngine::findReservation(ctx); |
| 2432 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 2433 | |
| 2434 | ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2434, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2435 | // The engine should have allocated the reserved address. |
| 2436 | EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.123\"" , "allocated_lease->addr_.toText()", "192.0.2.123", allocated_lease ->addr_.toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2436, gtest_ar.failure_message()) = ::testing::Message(); |
| 2437 | |
| 2438 | // Make sure that the lease has been committed to the lease database. |
| 2439 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
| 2440 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2440, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2441 | detailCompareLease(allocated_lease, from_mgr); |
| 2442 | |
| 2443 | // The previous lease should have been replaced by a new one. The previous |
| 2444 | // lease should be returned by the allocation engine to the caller. |
| 2445 | ASSERT_TRUE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.old_lease_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2445, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 2446 | EXPECT_EQ("192.0.2.101", ctx.old_lease_->addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.101\"" , "ctx.old_lease_->addr_.toText()", "192.0.2.101", ctx.old_lease_ ->addr_.toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2446, gtest_ar.failure_message()) = ::testing::Message(); |
| 2447 | detailCompareLease(ctx.old_lease_, lease); |
| 2448 | } |
| 2449 | |
| 2450 | // This test checks that the behavior of the allocation engine in the following |
| 2451 | // scenario: |
| 2452 | // - Client A has a lease in the database. |
| 2453 | // - Client B has a reservation for the address in use by client A. |
| 2454 | // - Client B sends a DHCPREQUEST requesting the allocation of the reserved |
| 2455 | // lease (in use by client A). |
| 2456 | // - Server determines that the reserved address is in use by a different client |
| 2457 | // and returns DHCPNAK to client B. |
| 2458 | 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" , 2458), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2458), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2458), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijacked_Test >); void AllocEngine4Test_reservedAddressHijacked_Test::TestBody () { |
| 2459 | // Create host reservation for the client B. |
| 2460 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2461 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2462 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2463 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2464 | CfgMgr::instance().commit(); |
| 2465 | |
| 2466 | // Allocate a lease for the client A for the same address as reserved |
| 2467 | // for the client B. |
| 2468 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
| 2469 | 100, time(NULL__null), subnet_->getID(), |
| 2470 | false, false, "")); |
| 2471 | LeaseMgrFactory::instance().addLease(lease); |
| 2472 | |
| 2473 | AllocEngine engine(0); |
| 2474 | |
| 2475 | // Try to allocate the reserved lease to client B. |
| 2476 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2477 | IOAddress("192.0.2.123"), false, false, |
| 2478 | "", false); |
| 2479 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2480 | AllocEngine::findReservation(ctx1); |
| 2481 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2482 | // The lease is allocated to someone else, so the allocation should not |
| 2483 | // succeed. |
| 2484 | ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2485 | ASSERT_FALSE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx1.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2485, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2486 | |
| 2487 | EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")" , 0, getStatistics("v4-allocation-fail")))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2487, gtest_ar.failure_message()) = ::testing::Message(); |
| 2488 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")" , 0, getStatistics("v4-allocation-fail-shared-network")))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2488, gtest_ar.failure_message()) = ::testing::Message(); |
| 2489 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")" , 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2489, gtest_ar.failure_message()) = ::testing::Message(); |
| 2490 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")" , 0, getStatistics("v4-allocation-fail-no-pools")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2490, gtest_ar.failure_message()) = ::testing::Message(); |
| 2491 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")" , 0, getStatistics("v4-allocation-fail-classes")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2491, gtest_ar.failure_message()) = ::testing::Message(); |
| 2492 | |
| 2493 | EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail", subnet_->getID()) ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2493, gtest_ar.failure_message()) = ::testing::Message(); |
| 2494 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-shared-network", subnet_ ->getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2494, gtest_ar.failure_message()) = ::testing::Message(); |
| 2495 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2495, gtest_ar.failure_message()) = ::testing::Message(); |
| 2496 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-no-pools", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2496, gtest_ar.failure_message()) = ::testing::Message(); |
| 2497 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-classes", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2497, gtest_ar.failure_message()) = ::testing::Message(); |
| 2498 | |
| 2499 | // Make sure that the allocation engine didn't modify the lease of the |
| 2500 | // client A. |
| 2501 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2502 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2502, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2503 | detailCompareLease(lease, from_mgr); |
| 2504 | |
| 2505 | // Try doing the same thing, but this time do not request any specific |
| 2506 | // address. It should have the same effect. |
| 2507 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2508 | IOAddress("0.0.0.0"), false, false, |
| 2509 | "", false); |
| 2510 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2511 | AllocEngine::findReservation(ctx2); |
| 2512 | allocated_lease = engine.allocateLease4(ctx2); |
| 2513 | ASSERT_FALSE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(allocated_lease))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2513, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2514 | ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2514, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2515 | |
| 2516 | EXPECT_EQ(0, getStatistics("v4-allocation-fail"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\")" , 0, getStatistics("v4-allocation-fail")))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2516, gtest_ar.failure_message()) = ::testing::Message(); |
| 2517 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\")" , 0, getStatistics("v4-allocation-fail-shared-network")))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2517, gtest_ar.failure_message()) = ::testing::Message(); |
| 2518 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\")" , 0, getStatistics("v4-allocation-fail-subnet")))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2518, gtest_ar.failure_message()) = ::testing::Message(); |
| 2519 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\")" , 0, getStatistics("v4-allocation-fail-no-pools")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2519, gtest_ar.failure_message()) = ::testing::Message(); |
| 2520 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\")" , 0, getStatistics("v4-allocation-fail-classes")))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 2520, gtest_ar.failure_message()) = ::testing::Message(); |
| 2521 | |
| 2522 | EXPECT_EQ(0, getStatistics("v4-allocation-fail", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail", subnet_->getID()) ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2522, gtest_ar.failure_message()) = ::testing::Message(); |
| 2523 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-shared-network", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-shared-network\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-shared-network", subnet_ ->getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2523, gtest_ar.failure_message()) = ::testing::Message(); |
| 2524 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-subnet", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-subnet\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-subnet", subnet_->getID ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2524, gtest_ar.failure_message()) = ::testing::Message(); |
| 2525 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-no-pools", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-no-pools\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-no-pools", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2525, gtest_ar.failure_message()) = ::testing::Message(); |
| 2526 | EXPECT_EQ(0, getStatistics("v4-allocation-fail-classes", subnet_->getID()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "getStatistics(\"v4-allocation-fail-classes\", subnet_->getID())" , 0, getStatistics("v4-allocation-fail-classes", subnet_-> getID())))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2526, gtest_ar.failure_message()) = ::testing::Message(); |
| 2527 | |
| 2528 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2529 | ASSERT_TRUE(from_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(from_mgr)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2529, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2530 | detailCompareLease(lease, from_mgr); |
| 2531 | } |
| 2532 | |
| 2533 | // This test checks that the behavior of the allocation engine in the following |
| 2534 | // scenario: |
| 2535 | // - Client A has a lease in the database. |
| 2536 | // - Client B has a reservation for the address in use by client A. |
| 2537 | // - Client B sends a DHCPDISCOVER. |
| 2538 | // - Server determines that the reserved address is in use by a different client |
| 2539 | // so it offers an address from the dynamic pool. |
| 2540 | 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" , 2540), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2540), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2540), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test ::TestBody() { |
| 2541 | // Create a reservation for the client B. |
| 2542 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2543 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2544 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2545 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2546 | CfgMgr::instance().commit(); |
| 2547 | |
| 2548 | // Create a lease for the client A. |
| 2549 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
| 2550 | 100, time(NULL__null), subnet_->getID(), |
| 2551 | false, false, "")); |
| 2552 | LeaseMgrFactory::instance().addLease(lease); |
| 2553 | |
| 2554 | AllocEngine engine(0); |
| 2555 | |
| 2556 | // Query allocation engine for the lease to be allocated to the client B. |
| 2557 | // The allocation engine is not able to allocate the lease to the client |
| 2558 | // B, because the address is in use by client A. |
| 2559 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2560 | IOAddress("192.0.2.123"), false, false, |
| 2561 | "", true); |
| 2562 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2563 | AllocEngine::findReservation(ctx1); |
| 2564 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2565 | |
| 2566 | // The allocation engine should return a lease but for a different address |
| 2567 | // than requested because this address is in use. |
| 2568 | ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2569 | ASSERT_FALSE(ctx1.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx1.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2569, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2570 | EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.123")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("allocated_lease->addr_.toText()" , "\"192.0.2.123\"", allocated_lease->addr_.toText(), "192.0.2.123" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2570, gtest_ar.failure_message()) = ::testing::Message(); |
| 2571 | EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease ::TYPE_V4, allocated_lease->addr_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2572 | |
| 2573 | // Do the same test. But, this time do not specify any address to be |
| 2574 | // allocated. |
| 2575 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2576 | IOAddress("0.0.0.0"), false, false, |
| 2577 | "", true); |
| 2578 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2579 | AllocEngine::findReservation(ctx2); |
| 2580 | allocated_lease = engine.allocateLease4(ctx2); |
| 2581 | |
| 2582 | ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2583 | EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.123")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("allocated_lease->addr_.toText()" , "\"192.0.2.123\"", allocated_lease->addr_.toText(), "192.0.2.123" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2583, gtest_ar.failure_message()) = ::testing::Message(); |
| 2584 | EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet_->inPool(Lease ::TYPE_V4, allocated_lease->addr_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2584, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true") .c_str()) = ::testing::Message(); |
| 2585 | ASSERT_FALSE(ctx2.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx2.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2586 | } |
| 2587 | |
| 2588 | // This test checks that the behavior of the allocation engine in the following |
| 2589 | // scenario: |
| 2590 | // - Client has a reservation. |
| 2591 | // - Client has a lease in the database for a different address than reserved. |
| 2592 | // - Client sends a DHCPREQUEST and asks for a different address than reserved, |
| 2593 | // and different than it has in a database. |
| 2594 | // - Server doesn't allocate the reserved address to the client because the |
| 2595 | // client asked for the different address. |
| 2596 | // |
| 2597 | // Note that in this case the client should get the DHCPNAK and should fall back |
| 2598 | // to the DHCPDISCOVER. |
| 2599 | 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" , 2599), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2599), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2599), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test ::TestBody() { |
| 2600 | // Create a reservation for the client. |
| 2601 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2602 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2603 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2604 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2605 | CfgMgr::instance().commit(); |
| 2606 | |
| 2607 | // Create a lease for the client for a different address than reserved. |
| 2608 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, ClientIdPtr(), |
| 2609 | 100, time(NULL__null), subnet_->getID(), |
| 2610 | false, false, "")); |
| 2611 | LeaseMgrFactory::instance().addLease(lease); |
| 2612 | |
| 2613 | AllocEngine engine(0); |
| 2614 | |
| 2615 | // Try to allocate a lease and specify a different address than reserved |
| 2616 | // and different from the one that client is currently using. |
| 2617 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2618 | IOAddress("192.0.2.102"), false, false, |
| 2619 | "", false); |
| 2620 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2621 | AllocEngine::findReservation(ctx1); |
| 2622 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2623 | 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" , 2623, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2624 | 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" , 2624, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2625 | |
| 2626 | 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", 2626, gtest_ar.failure_message()) = ::testing::Message(); |
| 2627 | 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" , 2627, gtest_ar.failure_message()) = ::testing::Message(); |
| 2628 | 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", 2628, gtest_ar.failure_message()) = ::testing::Message(); |
| 2629 | 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", 2629, gtest_ar.failure_message()) = ::testing::Message(); |
| 2630 | 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", 2630, gtest_ar.failure_message()) = ::testing::Message(); |
| 2631 | |
| 2632 | 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" , 2632, gtest_ar.failure_message()) = ::testing::Message(); |
| 2633 | 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" , 2633, gtest_ar.failure_message()) = ::testing::Message(); |
| 2634 | 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" , 2634, gtest_ar.failure_message()) = ::testing::Message(); |
| 2635 | 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" , 2635, gtest_ar.failure_message()) = ::testing::Message(); |
| 2636 | 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" , 2636, gtest_ar.failure_message()) = ::testing::Message(); |
| 2637 | |
| 2638 | // Repeat the test, but this time ask for the address that the client |
| 2639 | // has allocated. |
| 2640 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2641 | IOAddress("192.0.2.101"), false, false, |
| 2642 | "", false); |
| 2643 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2644 | AllocEngine::findReservation(ctx2); |
| 2645 | allocated_lease = engine.allocateLease4(ctx2); |
| 2646 | // The client has reservation so the server wants to allocate a |
| 2647 | // reserved address and doesn't want to renew the address that the |
| 2648 | // client is currently using. This is equivalent of the case when |
| 2649 | // the client tries to renew the lease but there is a new reservation |
| 2650 | // for this client. The server doesn't allow for the renewal and |
| 2651 | // responds with DHCPNAK to force the client to return to the |
| 2652 | // DHCP server discovery. |
| 2653 | 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" , 2653, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 2654 | 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" , 2654, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2655 | |
| 2656 | 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", 2656, gtest_ar.failure_message()) = ::testing::Message(); |
| 2657 | 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" , 2657, gtest_ar.failure_message()) = ::testing::Message(); |
| 2658 | 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", 2658, gtest_ar.failure_message()) = ::testing::Message(); |
| 2659 | 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", 2659, gtest_ar.failure_message()) = ::testing::Message(); |
| 2660 | 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", 2660, gtest_ar.failure_message()) = ::testing::Message(); |
| 2661 | |
| 2662 | 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" , 2662, gtest_ar.failure_message()) = ::testing::Message(); |
| 2663 | 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" , 2663, gtest_ar.failure_message()) = ::testing::Message(); |
| 2664 | 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" , 2664, gtest_ar.failure_message()) = ::testing::Message(); |
| 2665 | 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" , 2665, gtest_ar.failure_message()) = ::testing::Message(); |
| 2666 | 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" , 2666, gtest_ar.failure_message()) = ::testing::Message(); |
| 2667 | } |
| 2668 | |
| 2669 | // This test checks that the behavior of the allocation engine in the following |
| 2670 | // scenario: |
| 2671 | // - Client has a lease in the database. |
| 2672 | // - Client has a reservation for a different address than the one for which it |
| 2673 | // has a lease. |
| 2674 | // - Client sends a DHCPDISCOVER and asks for a different address than reserved |
| 2675 | // and different from which it has a lease for. |
| 2676 | // - Server ignores the client's hint and offers a reserved address. |
| 2677 | 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" , 2677), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2677), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2677), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test ::TestBody() { |
| 2678 | // Create a reservation for the client. |
| 2679 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2680 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2681 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2682 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2683 | CfgMgr::instance().commit(); |
| 2684 | |
| 2685 | // Create a lease for a different address than reserved. |
| 2686 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2687 | &clientid_->getClientId()[0], |
| 2688 | clientid_->getClientId().size(), |
| 2689 | 100, time(NULL__null), subnet_->getID(), |
| 2690 | false, false, "")); |
| 2691 | LeaseMgrFactory::instance().addLease(lease); |
| 2692 | |
| 2693 | AllocEngine engine(0); |
| 2694 | |
| 2695 | // Try to allocate a lease and use a completely different address |
| 2696 | // as a hint. |
| 2697 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 2698 | IOAddress("192.0.2.102"), false, false, |
| 2699 | "", true); |
| 2700 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 2701 | AllocEngine::findReservation(ctx1); |
| 2702 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 2703 | |
| 2704 | // Server should offer a lease for a reserved address. |
| 2705 | 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" , 2705, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2706 | 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" , 2706, gtest_ar.failure_message()) = ::testing::Message(); |
| 2707 | |
| 2708 | // The lease should not be allocated until the client sends a DHCPREQUEST. |
| 2709 | 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", 2709, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false") .c_str()) = ::testing::Message(); |
| 2710 | |
| 2711 | // Old lease should contain the currently used lease. |
| 2712 | 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" , 2712, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 2713 | 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" , 2713, gtest_ar.failure_message()) = ::testing::Message(); |
| 2714 | |
| 2715 | // Repeat the test but this time ask for the address for which the |
| 2716 | // client has a lease. |
| 2717 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2718 | IOAddress("192.0.2.101"), false, false, |
| 2719 | "", true); |
| 2720 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 2721 | AllocEngine::findReservation(ctx2); |
| 2722 | allocated_lease = engine.allocateLease4(ctx2); |
| 2723 | |
| 2724 | // The server should offer the lease, but not for the address that |
| 2725 | // the client requested. The server should offer a reserved address. |
| 2726 | 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" , 2726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2727 | 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" , 2727, gtest_ar.failure_message()) = ::testing::Message(); |
| 2728 | |
| 2729 | // Old lease should contain the currently used lease. |
| 2730 | 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" , 2730, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 2731 | 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" , 2731, gtest_ar.failure_message()) = ::testing::Message(); |
| 2732 | } |
| 2733 | |
| 2734 | // This test checks that the behavior of the allocation engine in the following |
| 2735 | // scenario: |
| 2736 | // - Client has a reservation. |
| 2737 | // - Client has a lease for a different address than reserved. |
| 2738 | // - Client sends a DHCPREQUEST to allocate a lease. |
| 2739 | // - The server determines that the client has a reservation for the |
| 2740 | // different address than it is currently using and should assign |
| 2741 | // a reserved address and remove the previous lease. |
| 2742 | 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" , 2742), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2742), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2742), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test ::TestBody() { |
| 2743 | // Create a reservation. |
| 2744 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2745 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2746 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2747 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2748 | CfgMgr::instance().commit(); |
| 2749 | |
| 2750 | // Create a lease for a different address than reserved. |
| 2751 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2752 | &clientid_->getClientId()[0], |
| 2753 | clientid_->getClientId().size(), |
| 2754 | 100, time(NULL__null), subnet_->getID(), |
| 2755 | false, false, "")); |
| 2756 | LeaseMgrFactory::instance().addLease(lease); |
| 2757 | |
| 2758 | AllocEngine engine(0); |
| 2759 | |
| 2760 | // Try to allocate a lease with providing no hint. |
| 2761 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2762 | IOAddress("0.0.0.0"), false, false, |
| 2763 | "", false); |
| 2764 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2765 | AllocEngine::findReservation(ctx); |
| 2766 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 2767 | |
| 2768 | // The reserved address should be allocated. |
| 2769 | 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" , 2769, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2770 | 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" , 2770, gtest_ar.failure_message()) = ::testing::Message(); |
| 2771 | |
| 2772 | // The previous lease should be removed. |
| 2773 | 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" , 2773, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 2774 | |
| 2775 | // Make sure that the allocated lease is committed in the lease database. |
| 2776 | Lease4Ptr from_mgr = |
| 2777 | LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
| 2778 | 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" , 2778, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2779 | detailCompareLease(allocated_lease, from_mgr); |
| 2780 | |
| 2781 | // Old lease should be returned. |
| 2782 | 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" , 2782, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 2783 | detailCompareLease(lease, ctx.old_lease_); |
| 2784 | } |
| 2785 | |
| 2786 | // This test checks that the behavior of the allocation engine in the following |
| 2787 | // scenario: |
| 2788 | // - Client has a reservation. |
| 2789 | // - Client has a lease for a different address than reserved. |
| 2790 | // - Client sends a DHCPDISCOVER with no hint. |
| 2791 | // - Server determines that there is a reservation for the client and that |
| 2792 | // the reserved address should be offered when the client sends a |
| 2793 | // DHCPDISCOVER. |
| 2794 | 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" , 2794), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2794), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2794), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test ::TestBody() { |
| 2795 | // Create a reservation. |
| 2796 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2797 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2798 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 2799 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2800 | CfgMgr::instance().commit(); |
| 2801 | |
| 2802 | // Create a lease for a different address than reserved. |
| 2803 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2804 | &clientid_->getClientId()[0], |
| 2805 | clientid_->getClientId().size(), |
| 2806 | 100, time(NULL__null), subnet_->getID(), |
| 2807 | false, false, "")); |
| 2808 | LeaseMgrFactory::instance().addLease(lease); |
| 2809 | |
| 2810 | AllocEngine engine(0); |
| 2811 | |
| 2812 | // Query the allocation engine for the lease to be allocated for the |
| 2813 | // client. |
| 2814 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 2815 | IOAddress("0.0.0.0"), false, false, |
| 2816 | "", true); |
| 2817 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 2818 | AllocEngine::findReservation(ctx); |
| 2819 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 2820 | |
| 2821 | // The server should offer the reserved address. |
| 2822 | 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" , 2822, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2823 | 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" , 2823, gtest_ar.failure_message()) = ::testing::Message(); |
| 2824 | |
| 2825 | // The lease should not be committed to the lease database until the |
| 2826 | // client sends a DHCPREQUEST. |
| 2827 | 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", 2827, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false") .c_str()) = ::testing::Message(); |
| 2828 | |
| 2829 | // The old lease should reflect what is in the database. |
| 2830 | 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" , 2830, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "false", "true") .c_str()) = ::testing::Message (); |
| 2831 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 2832 | 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" , 2832, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2833 | detailCompareLease(lease, from_mgr); |
| 2834 | } |
| 2835 | |
| 2836 | // This test checks that the behavior of the allocation engine in the following |
| 2837 | // scenario: |
| 2838 | // - Client A has a lease for the address. |
| 2839 | // - Client B has a reservation for the same address that the Client A is using. |
| 2840 | // - Client B requests allocation of the reserved address. |
| 2841 | // - Server returns DHCPNAK to the client to indicate that the requested address |
| 2842 | // can't be allocated. |
| 2843 | // - Client A renews the lease. |
| 2844 | // - Server determines that the lease that the Client A is trying to renew |
| 2845 | // is for the address reserved for Client B. Therefore, the server returns |
| 2846 | // DHCPNAK to force the client to return to the server discovery. |
| 2847 | // - The Client A sends DHCPDISCOVER. |
| 2848 | // - The server offers an address to the Client A, which is different than |
| 2849 | // the address reserved for Client B. |
| 2850 | // - The Client A requests allocation of the offered address. |
| 2851 | // - The server allocates the new address to Client A. |
| 2852 | // - The Client B sends DHCPDISCOVER to the server. |
| 2853 | // - The server offers a reserved address to the Client B. |
| 2854 | // - The Client B requests the offered address. |
| 2855 | // - The server allocates the reserved address to the Client B. |
| 2856 | 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" , 2856), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2856), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2856), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressConflictResolution_Test >); void AllocEngine4Test_reservedAddressConflictResolution_Test ::TestBody() { |
| 2857 | // Create a reservation for client B. |
| 2858 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
| 2859 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2860 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
| 2861 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2862 | CfgMgr::instance().commit(); |
| 2863 | |
| 2864 | // Create a lease for Client A. |
| 2865 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 2866 | &clientid_->getClientId()[0], |
| 2867 | clientid_->getClientId().size(), |
| 2868 | 100, time(NULL__null), subnet_->getID(), |
| 2869 | false, false, "")); |
| 2870 | LeaseMgrFactory::instance().addLease(lease); |
| 2871 | |
| 2872 | AllocEngine engine(0); |
| 2873 | |
| 2874 | // Client B sends a DHCPREQUEST to allocate a reserved lease. The |
| 2875 | // allocation engine can't allocate a reserved lease for this client |
| 2876 | // because this specific address is in use by the Client A. |
| 2877 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr2_, |
| 2878 | IOAddress("192.0.2.101"), false, false, |
| 2879 | "", false); |
| 2880 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2881 | AllocEngine::findReservation(ctx1); |
| 2882 | Lease4Ptr offered_lease = engine.allocateLease4(ctx1); |
| 2883 | 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" , 2883, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "offered_lease", "true", "false") .c_str()) = ::testing::Message (); |
| 2884 | |
| 2885 | 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", 2885, gtest_ar.failure_message()) = ::testing::Message(); |
| 2886 | 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" , 2886, gtest_ar.failure_message()) = ::testing::Message(); |
| 2887 | 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", 2887, gtest_ar.failure_message()) = ::testing::Message(); |
| 2888 | 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", 2888, gtest_ar.failure_message()) = ::testing::Message(); |
| 2889 | 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", 2889, gtest_ar.failure_message()) = ::testing::Message(); |
| 2890 | |
| 2891 | 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" , 2891, gtest_ar.failure_message()) = ::testing::Message(); |
| 2892 | 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" , 2892, gtest_ar.failure_message()) = ::testing::Message(); |
| 2893 | 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" , 2893, gtest_ar.failure_message()) = ::testing::Message(); |
| 2894 | 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" , 2894, gtest_ar.failure_message()) = ::testing::Message(); |
| 2895 | 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" , 2895, gtest_ar.failure_message()) = ::testing::Message(); |
| 2896 | |
| 2897 | // Client A tries to renew the lease. The renewal should fail because |
| 2898 | // server detects that Client A doesn't have reservation for this |
| 2899 | // address. |
| 2900 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 2901 | IOAddress("192.0.2.101"), false, false, |
| 2902 | "", false); |
| 2903 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2904 | AllocEngine::findReservation(ctx2); |
| 2905 | 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" , 2905, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine.allocateLease4(ctx2)", "true", "false") .c_str()) = ::testing::Message(); |
| 2906 | 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" , 2906, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx2.old_lease_", "true", "false") .c_str()) = ::testing:: Message(); |
| 2907 | |
| 2908 | 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", 2908, gtest_ar.failure_message()) = ::testing::Message(); |
| 2909 | 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" , 2909, gtest_ar.failure_message()) = ::testing::Message(); |
| 2910 | 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", 2910, gtest_ar.failure_message()) = ::testing::Message(); |
| 2911 | 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", 2911, gtest_ar.failure_message()) = ::testing::Message(); |
| 2912 | 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", 2912, gtest_ar.failure_message()) = ::testing::Message(); |
| 2913 | |
| 2914 | 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" , 2914, gtest_ar.failure_message()) = ::testing::Message(); |
| 2915 | 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" , 2915, gtest_ar.failure_message()) = ::testing::Message(); |
| 2916 | 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" , 2916, gtest_ar.failure_message()) = ::testing::Message(); |
| 2917 | 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" , 2917, gtest_ar.failure_message()) = ::testing::Message(); |
| 2918 | 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" , 2918, gtest_ar.failure_message()) = ::testing::Message(); |
| 2919 | |
| 2920 | // Client A returns to DHCPDISCOVER and should be offered a lease. |
| 2921 | // The offered lease address must be different than the one the |
| 2922 | // Client B has reservation for. |
| 2923 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
| 2924 | IOAddress("192.0.2.101"), false, false, |
| 2925 | "", true); |
| 2926 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2927 | AllocEngine::findReservation(ctx3); |
| 2928 | offered_lease = engine.allocateLease4(ctx3); |
| 2929 | 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" , 2929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "offered_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 2930 | 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" , 2930, gtest_ar.failure_message()) = ::testing::Message(); |
| 2931 | |
| 2932 | // Client A tries to acquire the lease. It should succeed. At this point |
| 2933 | // the previous lease should be released and become available for the |
| 2934 | // Client B. |
| 2935 | AllocEngine::ClientContext4 ctx4(subnet_, clientid_, hwaddr_, |
| 2936 | offered_lease->addr_, false, false, |
| 2937 | "", false); |
| 2938 | ctx4.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2939 | AllocEngine::findReservation(ctx4); |
| 2940 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx4); |
| 2941 | |
| 2942 | 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" , 2942, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2943 | 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" , 2943, gtest_ar.failure_message()) = ::testing::Message(); |
| 2944 | |
| 2945 | // Client B tries to get the lease again. It should be offered |
| 2946 | // a reserved lease. |
| 2947 | AllocEngine::ClientContext4 ctx5(subnet_, ClientIdPtr(), hwaddr2_, |
| 2948 | IOAddress("0.0.0.0"), false, false, |
| 2949 | "", true); |
| 2950 | ctx5.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2951 | AllocEngine::findReservation(ctx5); |
| 2952 | offered_lease = engine.allocateLease4(ctx5); |
| 2953 | |
| 2954 | 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" , 2954, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "offered_lease", "false", "true") .c_str()) = ::testing::Message (); |
| 2955 | 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" , 2955, gtest_ar.failure_message()) = ::testing::Message(); |
| 2956 | |
| 2957 | // Client B requests allocation of the lease and it should succeed. |
| 2958 | AllocEngine::ClientContext4 ctx6(subnet_, ClientIdPtr(), hwaddr2_, |
| 2959 | offered_lease->addr_, false, false, |
| 2960 | "", false); |
| 2961 | ctx6.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2962 | allocated_lease = engine.allocateLease4(ctx6); |
| 2963 | |
| 2964 | 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" , 2964, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2965 | 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" , 2965, gtest_ar.failure_message()) = ::testing::Message(); |
| 2966 | } |
| 2967 | |
| 2968 | // This test checks that the address is not assigned from the dynamic |
| 2969 | // pool if it has been reserved for another client. |
| 2970 | 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" , 2970), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2970), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 2970), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressVsDynamicPool_Test >); void AllocEngine4Test_reservedAddressVsDynamicPool_Test ::TestBody() { |
| 2971 | // Create a reservation for the client. |
| 2972 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 2973 | Host::IDENT_HWADDR, subnet_->getID(), |
| 2974 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 2975 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 2976 | CfgMgr::instance().commit(); |
| 2977 | |
| 2978 | AllocEngine engine(0); |
| 2979 | |
| 2980 | // Different client tries to allocate a lease. Note, that we're using |
| 2981 | // an iterative allocator which would pick the first address from the |
| 2982 | // dynamic pool, i.e. 192.0.2.100. This address is reserved so we expect |
| 2983 | // that a different address will be allocated. |
| 2984 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 2985 | IOAddress("0.0.0.0"), false, false, |
| 2986 | "", false); |
| 2987 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 2988 | AllocEngine::findReservation(ctx); |
| 2989 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 2990 | |
| 2991 | 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" , 2991, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 2992 | 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" , 2992, gtest_ar.failure_message()) = ::testing::Message(); |
| 2993 | |
| 2994 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
| 2995 | 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" , 2995, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 2996 | detailCompareLease(allocated_lease, from_mgr); |
| 2997 | } |
| 2998 | |
| 2999 | // This test checks that the client requesting an address which is |
| 3000 | // reserved for another client will get no lease or a different |
| 3001 | // address will be assigned if the client is sending a DHCPDISCOVER. |
| 3002 | 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" , 3002), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3002), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3002), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test >); void AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test ::TestBody() { |
| 3003 | // Create a reservation for the client. |
| 3004 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3005 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3006 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3007 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3008 | CfgMgr::instance().commit(); |
| 3009 | |
| 3010 | AllocEngine engine(0); |
| 3011 | |
| 3012 | // Different client is requesting this address. |
| 3013 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
| 3014 | IOAddress("192.0.2.100"), false, false, |
| 3015 | "", false); |
| 3016 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3017 | AllocEngine::findReservation(ctx1); |
| 3018 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 3019 | |
| 3020 | // The client should get no lease (DHCPNAK). |
| 3021 | 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" , 3021, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 3022 | |
| 3023 | 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", 3023, gtest_ar.failure_message()) = ::testing::Message(); |
| 3024 | 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" , 3024, gtest_ar.failure_message()) = ::testing::Message(); |
| 3025 | 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", 3025, gtest_ar.failure_message()) = ::testing::Message(); |
| 3026 | 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", 3026, gtest_ar.failure_message()) = ::testing::Message(); |
| 3027 | 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", 3027, gtest_ar.failure_message()) = ::testing::Message(); |
| 3028 | |
| 3029 | 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" , 3029, gtest_ar.failure_message()) = ::testing::Message(); |
| 3030 | 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" , 3030, gtest_ar.failure_message()) = ::testing::Message(); |
| 3031 | 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" , 3031, gtest_ar.failure_message()) = ::testing::Message(); |
| 3032 | 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" , 3032, gtest_ar.failure_message()) = ::testing::Message(); |
| 3033 | 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" , 3033, gtest_ar.failure_message()) = ::testing::Message(); |
| 3034 | |
| 3035 | // The same client should get a different lease than requested if |
| 3036 | // if is sending a DHCPDISCOVER (fake allocation is true). |
| 3037 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
| 3038 | IOAddress("192.0.2.100"), false, false, |
| 3039 | "", true); |
| 3040 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3041 | AllocEngine::findReservation(ctx2); |
| 3042 | allocated_lease = engine.allocateLease4(ctx2); |
| 3043 | |
| 3044 | 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" , 3044, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3045 | // Make sure the lease obtained is for a different address. |
| 3046 | 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" , 3046, gtest_ar.failure_message()) = ::testing::Message(); |
| 3047 | } |
| 3048 | |
| 3049 | // This test checks that the allocation engine refuses to allocate an |
| 3050 | // address when the pool is exhausted, and the only available |
| 3051 | // address is reserved for a different client. |
| 3052 | 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" , 3052), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3052), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3052), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressShortPool_Test >); void AllocEngine4Test_reservedAddressShortPool_Test::TestBody () { |
| 3053 | AllocEngine engine(0); |
| 3054 | |
| 3055 | // Create short pool with only one address. |
| 3056 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
| 3057 | // Reserve the address for a different client. |
| 3058 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
| 3059 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3060 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3061 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3062 | CfgMgr::instance().commit(); |
| 3063 | |
| 3064 | // Allocation engine should determine that the available address is |
| 3065 | // reserved for someone else and not allocate it. |
| 3066 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
| 3067 | IOAddress("0.0.0.0"), false, false, |
| 3068 | "", false); |
| 3069 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3070 | AllocEngine::findReservation(ctx1); |
| 3071 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
| 3072 | |
| 3073 | 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" , 3073, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "true", "false") .c_str()) = ::testing:: Message(); |
| 3074 | |
| 3075 | 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", 3075, gtest_ar.failure_message()) = ::testing::Message(); |
| 3076 | 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" , 3076, gtest_ar.failure_message()) = ::testing::Message(); |
| 3077 | 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", 3077, gtest_ar.failure_message()) = ::testing::Message(); |
| 3078 | 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", 3078, gtest_ar.failure_message()) = ::testing::Message(); |
| 3079 | 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", 3079, gtest_ar.failure_message()) = ::testing::Message(); |
| 3080 | |
| 3081 | 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" , 3081, gtest_ar.failure_message()) = ::testing::Message(); |
| 3082 | 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" , 3082, gtest_ar.failure_message()) = ::testing::Message(); |
| 3083 | 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" , 3083, gtest_ar.failure_message()) = ::testing::Message(); |
| 3084 | 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" , 3084, gtest_ar.failure_message()) = ::testing::Message(); |
| 3085 | 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" , 3085, gtest_ar.failure_message()) = ::testing::Message(); |
| 3086 | |
| 3087 | // Now, let's remove the reservation. |
| 3088 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
| 3089 | CfgMgr::instance().commit(); |
| 3090 | |
| 3091 | // Address should be successfully allocated. |
| 3092 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
| 3093 | IOAddress("0.0.0.0"), false, false, |
| 3094 | "", false); |
| 3095 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3096 | AllocEngine::findReservation(ctx2); |
| 3097 | allocated_lease = engine.allocateLease4(ctx2); |
| 3098 | |
| 3099 | 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" , 3099, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3100 | 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" , 3100, gtest_ar.failure_message()) = ::testing::Message(); |
| 3101 | } |
| 3102 | |
| 3103 | // This test checks that the AllocEngine allocates an address from the |
| 3104 | // dynamic pool if the client's reservation is made for a hostname but |
| 3105 | // not for an address. |
| 3106 | 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" , 3106), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3106), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3106), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedHostname_Test >); void AllocEngine4Test_reservedHostname_Test::TestBody( ) { |
| 3107 | AllocEngine engine(0); |
| 3108 | |
| 3109 | // Create a reservation for a hostname. Address is set to 0 which |
| 3110 | // indicates that there is no reservation. |
| 3111 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3112 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3113 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
| 3114 | "foo.example.org")); |
| 3115 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3116 | CfgMgr::instance().commit(); |
| 3117 | |
| 3118 | // Try to allocate a lease. |
| 3119 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 3120 | IOAddress("192.0.2.109"), false, false, |
| 3121 | "foo.example.org", true); |
| 3122 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3123 | AllocEngine::findReservation(ctx); |
| 3124 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 3125 | 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" , 3125, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3126 | 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" , 3126, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease->addr_.isV4Zero()", "true", "false") .c_str ()) = ::testing::Message(); |
| 3127 | 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" , 3127, gtest_ar.failure_message()) = ::testing::Message(); |
| 3128 | |
| 3129 | ctx.requested_address_ = allocated_lease->addr_; |
| 3130 | ctx.fake_allocation_ = false; |
| 3131 | allocated_lease = engine.allocateLease4(ctx); |
| 3132 | 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" , 3132, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3133 | 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" , 3133, gtest_ar.failure_message()) = ::testing::Message(); |
| 3134 | } |
| 3135 | |
| 3136 | // This test checks that the AllocEngine::findReservation method finds |
| 3137 | // and returns host reservation for the DHCPv4 client using the data from |
| 3138 | // the client context. If the host reservation can't be found, it sets |
| 3139 | // the value of NULL in the host_ field of the client context. |
| 3140 | 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", 3140 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3140), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3140), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_findReservation_Test >); void AllocEngine4Test_findReservation_Test::TestBody() { |
| 3141 | // Create the instance of the allocation engine. |
| 3142 | AllocEngine engine(0); |
| 3143 | |
| 3144 | // Context is required to call the AllocEngine::findReservation. |
| 3145 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3146 | IOAddress("0.0.0.0"), false, false, |
| 3147 | "", false); |
| 3148 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3149 | ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_); |
| 3150 | ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getClientId()); |
| 3151 | |
| 3152 | // There is no reservation in the database so no host should be returned. |
| 3153 | 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_3153 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3153 ; } } else gtest_label_testnothrow_3153 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3153, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3154 | 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" , 3154, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3155 | |
| 3156 | // Create a reservation for the client. |
| 3157 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3158 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3159 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3160 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3161 | CfgMgr::instance().commit(); |
| 3162 | |
| 3163 | // This time the reservation should be returned. |
| 3164 | ctx.hosts_.clear(); |
| 3165 | 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_3165 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3165 ; } } else gtest_label_testnothrow_3165 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3165, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3166 | 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" , 3166, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3167 | 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" , 3167, gtest_ar.failure_message()) = ::testing::Message(); |
| 3168 | |
| 3169 | // It shouldn't be returned when reservations-in-subnet is disabled. |
| 3170 | subnet_->setReservationsInSubnet(false); |
| 3171 | ctx.hosts_.clear(); |
| 3172 | 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_3172 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3172 ; } } else gtest_label_testnothrow_3172 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3172, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3173 | 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" , 3173, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3174 | |
| 3175 | // Check the reservations-in-subnet and reservations-out-of-pool flags. |
| 3176 | subnet_->setReservationsInSubnet(true); |
| 3177 | subnet_->setReservationsOutOfPool(true); |
| 3178 | ctx.hosts_.clear(); |
| 3179 | 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_3179 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3179 ; } } else gtest_label_testnothrow_3179 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3179, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3180 | 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" , 3180, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3181 | 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" , 3181, gtest_ar.failure_message()) = ::testing::Message(); |
| 3182 | |
| 3183 | // This time use the client identifier to search for the host. |
| 3184 | host.reset(new Host(&clientid_->getClientId()[0], |
| 3185 | clientid_->getClientId().size(), |
| 3186 | Host::IDENT_DUID, subnet_->getID(), |
| 3187 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
| 3188 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3189 | CfgMgr::instance().commit(); |
| 3190 | |
| 3191 | ctx.hosts_.clear(); |
| 3192 | 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_3192 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3192 ; } } else gtest_label_testnothrow_3192 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3192, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3193 | 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" , 3193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3194 | 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" , 3194, gtest_ar.failure_message()) = ::testing::Message(); |
| 3195 | |
| 3196 | // Remove the subnet. Subnet id is required to find host reservations, so |
| 3197 | // if it is set to NULL, no reservation should be returned |
| 3198 | ctx.subnet_.reset(); |
| 3199 | ctx.hosts_.clear(); |
| 3200 | 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_3200 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3200 ; } } else gtest_label_testnothrow_3200 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3200, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3201 | 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" , 3201, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3202 | |
| 3203 | // The same if there is a mismatch of the subnet id between the reservation |
| 3204 | // and the context. |
| 3205 | ctx.subnet_ = subnet_; |
| 3206 | host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3207 | Host::IDENT_HWADDR, subnet_->getID() + 1, |
| 3208 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
| 3209 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3210 | CfgMgr::instance().commit(); |
| 3211 | |
| 3212 | ctx.hosts_.clear(); |
| 3213 | 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_3213 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3213 ; } } else gtest_label_testnothrow_3213 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3213, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3214 | 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" , 3214, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "true", "false") .c_str()) = ::testing ::Message(); |
| 3215 | } |
| 3216 | |
| 3217 | // This test checks if the simple IPv4 allocation can succeed and that |
| 3218 | // statistic for allocated addresses is increased appropriately. |
| 3219 | 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" , 3219), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3219), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3219), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4Stats_Test >); void AllocEngine4Test_simpleAlloc4Stats_Test::TestBody () { |
| 3220 | boost::scoped_ptr<AllocEngine> engine; |
| 3221 | 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_3221 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3221 ; } } else gtest_label_testnothrow_3221 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3221, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3222 | 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" , 3222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 3223 | |
| 3224 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 3225 | false, true, "somehost.example.com.", false); |
| 3226 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3227 | |
| 3228 | // Let's pretend 100 addresses were allocated already |
| 3229 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
| 3230 | "assigned-addresses"); |
| 3231 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
| 3232 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 3233 | subnet_->getID()); |
| 3234 | |
| 3235 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 3236 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 3237 | |
| 3238 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 3239 | // The new lease has been allocated, so the old lease should not exist. |
| 3240 | 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" , 3240, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3241 | |
| 3242 | // Check that we got a lease |
| 3243 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3243, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3244 | |
| 3245 | // The statistic should be there and it should be increased by 1 (to 101). |
| 3246 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
| 3247 | 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", 3247, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "stat", "false", "true") .c_str()) = ::testing::Message(); |
| 3248 | 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" , 3248, gtest_ar.failure_message()) = ::testing::Message(); |
| 3249 | cumulative += 1; |
| 3250 | 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" , 3251, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 3251 | 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" , 3251, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 3252 | glbl_assigned += 1; |
| 3253 | 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" , 3253, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 3254 | glbl_cumulative += 1; |
| 3255 | 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" , 3255, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 3256 | } |
| 3257 | |
| 3258 | // This test checks if the fake allocation (for DHCPDISCOVER) can succeed |
| 3259 | // and that it doesn't increase allocated-addresses statistic. |
| 3260 | 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", 3260 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3260), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3260), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4Stat_Test >); void AllocEngine4Test_fakeAlloc4Stat_Test::TestBody() { |
| 3261 | boost::scoped_ptr<AllocEngine> engine; |
| 3262 | 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_3262 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3262 ; } } else gtest_label_testnothrow_3262 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3262, ("Expected: " "engine.reset(new AllocEngine(100))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 3263 | 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" , 3263, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 3264 | |
| 3265 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3266 | IOAddress("0.0.0.0"), false, true, |
| 3267 | "host.example.com.", true); |
| 3268 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3269 | |
| 3270 | // Let's pretend 100 addresses were allocated already |
| 3271 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
| 3272 | "assigned-addresses"); |
| 3273 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
| 3274 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 3275 | subnet_->getID()); |
| 3276 | |
| 3277 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 3278 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 3279 | |
| 3280 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 3281 | |
| 3282 | // The new lease has been allocated, so the old lease should not exist. |
| 3283 | 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" , 3283, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3284 | |
| 3285 | // Check that we got a lease |
| 3286 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3286, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3287 | |
| 3288 | // The statistic should be there and it should not be increased |
| 3289 | // (should be still equal to 100). |
| 3290 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
| 3291 | 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", 3291, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "stat", "false", "true") .c_str()) = ::testing::Message(); |
| 3292 | 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" , 3292, gtest_ar.failure_message()) = ::testing::Message(); |
| 3293 | 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" , 3294, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 3294 | 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" , 3294, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 3295 | 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" , 3295, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 3296 | 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" , 3296, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 3297 | } |
| 3298 | |
| 3299 | // This test checks that the allocated-addresses statistic is decreased when |
| 3300 | // the client has a lease and a reservation for a different address is |
| 3301 | // available. |
| 3302 | 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" , 3302), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3302), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3302), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseStat_Test >); void AllocEngine4Test_reservedAddressExistingLeaseStat_Test ::TestBody() { |
| 3303 | // Create the reservation for the client. |
| 3304 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3305 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3306 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
| 3307 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3308 | CfgMgr::instance().commit(); |
| 3309 | |
| 3310 | // Create a lease for the client with a different address than the reserved |
| 3311 | // one. |
| 3312 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
| 3313 | &clientid_->getClientId()[0], |
| 3314 | clientid_->getClientId().size(), |
| 3315 | 100, time(NULL__null), subnet_->getID(), |
| 3316 | false, false, "")); |
| 3317 | LeaseMgrFactory::instance().addLease(lease); |
| 3318 | |
| 3319 | AllocEngine engine(100); |
| 3320 | |
| 3321 | // Let's pretend 100 addresses were allocated already |
| 3322 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
| 3323 | "assigned-addresses"); |
| 3324 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
| 3325 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
| 3326 | subnet_->getID()); |
| 3327 | |
| 3328 | int64_t glbl_assigned = getStatistics("assigned-addresses"); |
| 3329 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
| 3330 | |
| 3331 | // Request allocation of the reserved address. |
| 3332 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3333 | IOAddress("192.0.2.123"), false, false, |
| 3334 | "", false); |
| 3335 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3336 | AllocEngine::findReservation(ctx); |
| 3337 | |
| 3338 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
| 3339 | |
| 3340 | 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" , 3340, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease", "false", "true") .c_str()) = ::testing:: Message(); |
| 3341 | |
| 3342 | // The statistic should be still at 100. Note that it was decreased |
| 3343 | // (because old lease was removed), but also increased (because the |
| 3344 | // new lease was immediately allocated). |
| 3345 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
| 3346 | 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", 3346, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "stat", "false", "true") .c_str()) = ::testing::Message(); |
| 3347 | 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" , 3347, gtest_ar.failure_message()) = ::testing::Message(); |
| 3348 | cumulative += 1; |
| 3349 | 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" , 3350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
| 3350 | 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" , 3350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
| 3351 | 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" , 3351, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", glbl_assigned)", "false" , "true") .c_str()) = ::testing::Message(); |
| 3352 | glbl_cumulative += 1; |
| 3353 | 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" , 3353, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
| 3354 | // Lets' double check that the actual allocation took place. |
| 3355 | 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" , 3355, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.fake_allocation_", "true", "false") .c_str()) = ::testing ::Message(); |
| 3356 | } |
| 3357 | |
| 3358 | // This test checks the behavior of the allocation engine in the following |
| 3359 | // scenario: |
| 3360 | // - Client has no lease in the database. |
| 3361 | // - Client has a global reservation outside of the subnet. |
| 3362 | // - Client sends DISCOVER |
| 3363 | // - Client is allocated an address within the subnet. |
| 3364 | // - Lease is not added to the lease database |
| 3365 | 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" , 3365), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3365), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3365), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test ::TestBody() { |
| 3366 | // Create reservation for the client. |
| 3367 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3368 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3369 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 3370 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3371 | CfgMgr::instance().commit(); |
| 3372 | |
| 3373 | AllocEngine engine(0); |
| 3374 | |
| 3375 | subnet_->setReservationsGlobal(true); |
| 3376 | |
| 3377 | // Query allocation engine for the lease to be assigned to this |
| 3378 | // client without specifying the address to be assigned. |
| 3379 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3380 | IOAddress("0.0.0.0"), false, false, |
| 3381 | "", true); |
| 3382 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3383 | |
| 3384 | // Look up the host. |
| 3385 | AllocEngine::findReservation(ctx); |
| 3386 | |
| 3387 | // We should have the correct current host |
| 3388 | 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" , 3388, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3389 | 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" , 3389, gtest_ar.failure_message()) = ::testing::Message(); |
| 3390 | 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" , 3390, gtest_ar.failure_message()) = ::testing::Message(); |
| 3391 | |
| 3392 | // We should allocate an address in the subnet |
| 3393 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3394 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3394, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3395 | 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" , 3395, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 3396 | |
| 3397 | // This is a "fake" allocation so the returned lease should not be committed |
| 3398 | // to the lease database. |
| 3399 | 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" , 3399, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3400 | |
| 3401 | // Client had no lease in the database, so the old lease returned should |
| 3402 | // be NULL. |
| 3403 | 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" , 3403, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3404 | } |
| 3405 | |
| 3406 | // This test checks the behavior of the allocation engine in the following |
| 3407 | // scenario: |
| 3408 | // - Client has no lease in the database. |
| 3409 | // - Client has a global reservation matching the current subnet. |
| 3410 | // - Client sends DISCOVER |
| 3411 | // - Client is allocated the reserved address. |
| 3412 | // - Lease is not added to the lease database |
| 3413 | 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" , 3413), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3413), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3413), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test ::TestBody() { |
| 3414 | // Create reservation for the client. |
| 3415 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3416 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3417 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
| 3418 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3419 | CfgMgr::instance().commit(); |
| 3420 | |
| 3421 | AllocEngine engine(0); |
| 3422 | |
| 3423 | subnet_->setReservationsGlobal(true); |
| 3424 | |
| 3425 | // Query allocation engine for the lease to be assigned to this |
| 3426 | // client without specifying the address to be assigned. |
| 3427 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3428 | IOAddress("0.0.0.0"), false, false, |
| 3429 | "", true); |
| 3430 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3431 | |
| 3432 | // Look up the host. |
| 3433 | AllocEngine::findReservation(ctx); |
| 3434 | |
| 3435 | // We should have the correct current host |
| 3436 | 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" , 3436, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3437 | 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" , 3437, gtest_ar.failure_message()) = ::testing::Message(); |
| 3438 | 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" , 3438, gtest_ar.failure_message()) = ::testing::Message(); |
| 3439 | |
| 3440 | // We should allocate the reserved address. |
| 3441 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3442 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3442, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3443 | 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" , 3443, gtest_ar.failure_message()) = ::testing::Message(); |
| 3444 | |
| 3445 | // This is a "fake" allocation so the returned lease should not be committed |
| 3446 | // to the lease database. |
| 3447 | 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" , 3447, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3448 | |
| 3449 | // Client had no lease in the database, so the old lease returned should |
| 3450 | // be NULL. |
| 3451 | 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" , 3451, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3452 | } |
| 3453 | |
| 3454 | // This test checks the behavior of the allocation engine in the following |
| 3455 | // scenario: |
| 3456 | // - Client has no lease in the database. |
| 3457 | // - Client has a global reservation outside the current subnet. |
| 3458 | // - Client sends REQUEST |
| 3459 | // - Client is allocated a dynamic address. |
| 3460 | // - Lease is added to the lease database |
| 3461 | 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" , 3461), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3461), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3461), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test ::TestBody() { |
| 3462 | // Create reservation for the client. |
| 3463 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3464 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3465 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 3466 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3467 | CfgMgr::instance().commit(); |
| 3468 | |
| 3469 | AllocEngine engine(0); |
| 3470 | |
| 3471 | subnet_->setReservationsGlobal(true); |
| 3472 | |
| 3473 | // Query allocation engine for the lease to be assigned to this |
| 3474 | // client without specifying the address to be assigned. |
| 3475 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3476 | IOAddress("0.0.0.0"), false, false, |
| 3477 | "", false); |
| 3478 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3479 | |
| 3480 | // Look up the host. |
| 3481 | AllocEngine::findReservation(ctx); |
| 3482 | |
| 3483 | // We should have the correct current host |
| 3484 | 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" , 3484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3485 | 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" , 3485, gtest_ar.failure_message()) = ::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 | // We should allocate the reserved address. |
| 3489 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3490 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3490, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3491 | 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" , 3491, gtest_ar.failure_message()) = ::testing::Message(); |
| 3492 | 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" , 3492, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 3493 | |
| 3494 | // Check that the lease is indeed in LeaseMgr |
| 3495 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3496 | 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" , 3496, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3497 | |
| 3498 | // Now check that the lease in LeaseMgr has the same parameters |
| 3499 | detailCompareLease(lease, from_mgr); |
| 3500 | |
| 3501 | // Client had no lease in the database, so the old lease returned should |
| 3502 | // be NULL. |
| 3503 | 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" , 3503, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3504 | } |
| 3505 | |
| 3506 | // This test checks the behavior of the allocation engine in the following |
| 3507 | // scenario: |
| 3508 | // - Client has no lease in the database. |
| 3509 | // - Client has a global reservation matching the current subnet. |
| 3510 | // - Client sends REQUEST |
| 3511 | // - Client is allocated the reserved address. |
| 3512 | // - Lease is added to the lease database |
| 3513 | 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" , 3513), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3513), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3513), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test ::TestBody() { |
| 3514 | // Create reservation for the client. |
| 3515 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3516 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3517 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
| 3518 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3519 | CfgMgr::instance().commit(); |
| 3520 | |
| 3521 | AllocEngine engine(0); |
| 3522 | |
| 3523 | subnet_->setReservationsGlobal(true); |
| 3524 | |
| 3525 | // Query allocation engine for the lease to be assigned to this |
| 3526 | // client without specifying the address to be assigned. |
| 3527 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3528 | IOAddress("0.0.0.0"), false, false, |
| 3529 | "", false); |
| 3530 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3531 | |
| 3532 | // Look up the host. |
| 3533 | AllocEngine::findReservation(ctx); |
| 3534 | |
| 3535 | // We should have the correct current host |
| 3536 | 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" , 3536, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3537 | 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" , 3537, gtest_ar.failure_message()) = ::testing::Message(); |
| 3538 | 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" , 3538, gtest_ar.failure_message()) = ::testing::Message(); |
| 3539 | |
| 3540 | // We should allocate the reserved address. |
| 3541 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3542 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3542, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3543 | 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" , 3543, gtest_ar.failure_message()) = ::testing::Message(); |
| 3544 | |
| 3545 | // Check that the lease is indeed in LeaseMgr |
| 3546 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3547 | 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" , 3547, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3548 | |
| 3549 | // Now check that the lease in LeaseMgr has the same parameters |
| 3550 | detailCompareLease(lease, from_mgr); |
| 3551 | |
| 3552 | // Client had no lease in the database, so the old lease returned should |
| 3553 | // be NULL. |
| 3554 | 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" , 3554, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3555 | } |
| 3556 | |
| 3557 | // This test checks the behavior of the allocation engine in the following |
| 3558 | // scenario: |
| 3559 | // - Client has no lease in the database. |
| 3560 | // - Client has a global reservation. |
| 3561 | // - Client sends DISCOVER |
| 3562 | // - Client is allocated a dynamic address from matched subnet |
| 3563 | // - Lease is not added to the lease database |
| 3564 | 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" , 3564), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3564), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3564), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicDiscover_Test >); void AllocEngine4Test_globalReservationDynamicDiscover_Test ::TestBody() { |
| 3565 | // Create reservation for the client. |
| 3566 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3567 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3568 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
| 3569 | "foo.example.org")); |
| 3570 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3571 | CfgMgr::instance().commit(); |
| 3572 | |
| 3573 | AllocEngine engine(0); |
| 3574 | |
| 3575 | subnet_->setReservationsGlobal(true); |
| 3576 | |
| 3577 | // Query allocation engine for the lease to be assigned to this |
| 3578 | // client without specifying the address to be assigned. |
| 3579 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3580 | IOAddress("0.0.0.0"), false, false, |
| 3581 | "", true); |
| 3582 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3583 | |
| 3584 | // Look up the host. |
| 3585 | AllocEngine::findReservation(ctx); |
| 3586 | |
| 3587 | // We should have the correct current host |
| 3588 | 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" , 3588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3589 | 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" , 3589, gtest_ar.failure_message()) = ::testing::Message(); |
| 3590 | 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" , 3590, gtest_ar.failure_message()) = ::testing::Message(); |
| 3591 | |
| 3592 | // We should allocate a dynamic address. |
| 3593 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3594 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3594, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3595 | 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" , 3595, gtest_ar.failure_message()) = ::testing::Message(); |
| 3596 | |
| 3597 | // This is a "fake" allocation so the returned lease should not be committed |
| 3598 | // to the lease database. |
| 3599 | 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" , 3599, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3600 | |
| 3601 | // Client had no lease in the database, so the old lease returned should |
| 3602 | // be NULL. |
| 3603 | 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" , 3603, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3604 | } |
| 3605 | |
| 3606 | // This test checks the behavior of the allocation engine in the following |
| 3607 | // scenario: |
| 3608 | // - Client has no lease in the database. |
| 3609 | // - Client has a global reservation. |
| 3610 | // - Client sends REQUEST |
| 3611 | // - Client is allocated a dynamic address from matched subnet |
| 3612 | // - Lease is added to the lease database |
| 3613 | 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" , 3613), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3613), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3613), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationDynamicRequest_Test >); void AllocEngine4Test_globalReservationDynamicRequest_Test ::TestBody() { |
| 3614 | // Create reservation for the client. |
| 3615 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3616 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3617 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
| 3618 | "foo.example.org")); |
| 3619 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3620 | CfgMgr::instance().commit(); |
| 3621 | |
| 3622 | AllocEngine engine(0); |
| 3623 | |
| 3624 | subnet_->setReservationsGlobal(true); |
| 3625 | |
| 3626 | // Query allocation engine for the lease to be assigned to this |
| 3627 | // client without specifying the address to be assigned. |
| 3628 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3629 | IOAddress("0.0.0.0"), false, false, |
| 3630 | "", false); |
| 3631 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3632 | |
| 3633 | // Look up the host. |
| 3634 | AllocEngine::findReservation(ctx); |
| 3635 | |
| 3636 | // We should have the correct current host |
| 3637 | 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" , 3637, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3638 | 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" , 3638, gtest_ar.failure_message()) = ::testing::Message(); |
| 3639 | 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" , 3639, gtest_ar.failure_message()) = ::testing::Message(); |
| 3640 | |
| 3641 | // We should allocate a dynamic address. |
| 3642 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3643 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3643, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3644 | 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" , 3644, gtest_ar.failure_message()) = ::testing::Message(); |
| 3645 | |
| 3646 | // Check that the lease is indeed in LeaseMgr |
| 3647 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3648 | 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" , 3648, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3649 | |
| 3650 | // Now check that the lease in LeaseMgr has the same parameters |
| 3651 | detailCompareLease(lease, from_mgr); |
| 3652 | |
| 3653 | // Client had no lease in the database, so the old lease returned should |
| 3654 | // be NULL. |
| 3655 | 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" , 3655, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3656 | } |
| 3657 | |
| 3658 | // This test checks the behavior of the allocation engine in the following |
| 3659 | // scenario: |
| 3660 | // - Client has no lease in the database. |
| 3661 | // - Client has a subnet reservation. |
| 3662 | // - Client sends DISCOVER |
| 3663 | // - Client is allocated the reserved address. |
| 3664 | // - Lease is not added to the lease database |
| 3665 | 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" , 3665), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3665), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3665), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressDiscover_Test >); void AllocEngine4Test_mixedReservationReservedAddressDiscover_Test ::TestBody() { |
| 3666 | // Create reservation for the client. |
| 3667 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3668 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3669 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 3670 | "foo.example.org")); |
| 3671 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3672 | CfgMgr::instance().commit(); |
| 3673 | |
| 3674 | AllocEngine engine(0); |
| 3675 | |
| 3676 | subnet_->setReservationsGlobal(true); |
| 3677 | subnet_->setReservationsInSubnet(true); |
| 3678 | |
| 3679 | // Query allocation engine for the lease to be assigned to this |
| 3680 | // client without specifying the address to be assigned. |
| 3681 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3682 | IOAddress("0.0.0.0"), false, false, |
| 3683 | "", true); |
| 3684 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3685 | |
| 3686 | // Look up the host. |
| 3687 | AllocEngine::findReservation(ctx); |
| 3688 | |
| 3689 | // We should have the correct current host |
| 3690 | 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" , 3690, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3691 | 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" , 3691, gtest_ar.failure_message()) = ::testing::Message(); |
| 3692 | 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" , 3692, gtest_ar.failure_message()) = ::testing::Message(); |
| 3693 | |
| 3694 | // We should allocate the reserved address. |
| 3695 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3696 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3696, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3697 | 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" , 3697, gtest_ar.failure_message()) = ::testing::Message(); |
| 3698 | |
| 3699 | // This is a "fake" allocation so the returned lease should not be committed |
| 3700 | // to the lease database. |
| 3701 | 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" , 3701, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3702 | |
| 3703 | // Client had no lease in the database, so the old lease returned should |
| 3704 | // be NULL. |
| 3705 | 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" , 3705, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3706 | } |
| 3707 | |
| 3708 | // This test checks the behavior of the allocation engine in the following |
| 3709 | // scenario: |
| 3710 | // - Client has no lease in the database. |
| 3711 | // - Client has a subnet reservation. |
| 3712 | // - Client sends REQUEST |
| 3713 | // - Client is allocated the reserved address. |
| 3714 | // - Lease is added to the lease database |
| 3715 | 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" , 3715), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3715), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3715), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressRequest_Test >); void AllocEngine4Test_mixedReservationReservedAddressRequest_Test ::TestBody() { |
| 3716 | // Create reservation for the client. |
| 3717 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3718 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3719 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 3720 | "foo.example.org")); |
| 3721 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3722 | CfgMgr::instance().commit(); |
| 3723 | |
| 3724 | AllocEngine engine(0); |
| 3725 | |
| 3726 | subnet_->setReservationsGlobal(true); |
| 3727 | subnet_->setReservationsInSubnet(true); |
| 3728 | |
| 3729 | // Query allocation engine for the lease to be assigned to this |
| 3730 | // client without specifying the address to be assigned. |
| 3731 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3732 | IOAddress("0.0.0.0"), false, false, |
| 3733 | "", false); |
| 3734 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3735 | |
| 3736 | // Look up the host. |
| 3737 | AllocEngine::findReservation(ctx); |
| 3738 | |
| 3739 | // We should have the correct current host |
| 3740 | 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" , 3740, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3741 | 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" , 3741, gtest_ar.failure_message()) = ::testing::Message(); |
| 3742 | 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" , 3742, gtest_ar.failure_message()) = ::testing::Message(); |
| 3743 | |
| 3744 | // We should allocate the reserved address. |
| 3745 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3746 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3746, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3747 | 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" , 3747, gtest_ar.failure_message()) = ::testing::Message(); |
| 3748 | |
| 3749 | // Check that the lease is indeed in LeaseMgr |
| 3750 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3751 | 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" , 3751, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3752 | |
| 3753 | // Now check that the lease in LeaseMgr has the same parameters |
| 3754 | detailCompareLease(lease, from_mgr); |
| 3755 | |
| 3756 | // Client had no lease in the database, so the old lease returned should |
| 3757 | // be NULL. |
| 3758 | 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" , 3758, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3759 | } |
| 3760 | |
| 3761 | // This test checks the behavior of the allocation engine in the following |
| 3762 | // scenario: |
| 3763 | // - Client has no lease in the database. |
| 3764 | // - Client has a global and a subnet reservation. |
| 3765 | // - Client sends DISCOVER |
| 3766 | // - Client is allocated the reserved address. |
| 3767 | // - Lease is not added to the lease database |
| 3768 | 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" , 3768), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3768), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3768), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressDiscover_Test >); void AllocEngine4Test_bothReservationReservedAddressDiscover_Test ::TestBody() { |
| 3769 | // Create reservations for the client. |
| 3770 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3771 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3772 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 3773 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
| 3774 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3775 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3776 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 3777 | "foo.example.org")); |
| 3778 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3779 | CfgMgr::instance().commit(); |
| 3780 | |
| 3781 | AllocEngine engine(0); |
| 3782 | |
| 3783 | subnet_->setReservationsGlobal(true); |
| 3784 | subnet_->setReservationsInSubnet(true); |
| 3785 | |
| 3786 | // Query allocation engine for the lease to be assigned to this |
| 3787 | // client without specifying the address to be assigned. |
| 3788 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3789 | IOAddress("0.0.0.0"), false, false, |
| 3790 | "", true); |
| 3791 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 3792 | |
| 3793 | // Look up the host. |
| 3794 | AllocEngine::findReservation(ctx); |
| 3795 | |
| 3796 | // We should have the correct current host |
| 3797 | 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" , 3797, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3798 | 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" , 3798, gtest_ar.failure_message()) = ::testing::Message(); |
| 3799 | 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" , 3799, gtest_ar.failure_message()) = ::testing::Message(); |
| 3800 | |
| 3801 | // We should allocate the reserved address. |
| 3802 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3803 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3804 | 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" , 3804, gtest_ar.failure_message()) = ::testing::Message(); |
| 3805 | |
| 3806 | // This is a "fake" allocation so the returned lease should not be committed |
| 3807 | // to the lease database. |
| 3808 | 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" , 3808, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
| 3809 | |
| 3810 | // Client had no lease in the database, so the old lease returned should |
| 3811 | // be NULL. |
| 3812 | 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" , 3812, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3813 | } |
| 3814 | |
| 3815 | // This test checks the behavior of the allocation engine in the following |
| 3816 | // scenario: |
| 3817 | // - Client has no lease in the database. |
| 3818 | // - Client has a global and a subnet reservation. |
| 3819 | // - Client sends REQUEST |
| 3820 | // - Client is allocated the reserved address. |
| 3821 | // - Lease is added to the lease database |
| 3822 | 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" , 3822), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3822), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3822), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressRequest_Test >); void AllocEngine4Test_bothReservationReservedAddressRequest_Test ::TestBody() { |
| 3823 | // Create reservations for the client. |
| 3824 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3825 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
| 3826 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
| 3827 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
| 3828 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 3829 | Host::IDENT_HWADDR, subnet_->getID(), |
| 3830 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
| 3831 | "foo.example.org")); |
| 3832 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
| 3833 | CfgMgr::instance().commit(); |
| 3834 | |
| 3835 | AllocEngine engine(0); |
| 3836 | |
| 3837 | subnet_->setReservationsGlobal(true); |
| 3838 | subnet_->setReservationsInSubnet(true); |
| 3839 | |
| 3840 | // Query allocation engine for the lease to be assigned to this |
| 3841 | // client without specifying the address to be assigned. |
| 3842 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3843 | IOAddress("0.0.0.0"), false, false, |
| 3844 | "", false); |
| 3845 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3846 | |
| 3847 | // Look up the host. |
| 3848 | AllocEngine::findReservation(ctx); |
| 3849 | |
| 3850 | // We should have the correct current host |
| 3851 | 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" , 3851, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.currentHost()", "false", "true") .c_str()) = ::testing ::Message(); |
| 3852 | 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" , 3852, gtest_ar.failure_message()) = ::testing::Message(); |
| 3853 | 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" , 3853, gtest_ar.failure_message()) = ::testing::Message(); |
| 3854 | |
| 3855 | // We should allocate the reserved address. |
| 3856 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3857 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3857, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3858 | 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" , 3858, gtest_ar.failure_message()) = ::testing::Message(); |
| 3859 | |
| 3860 | // Check that the lease is indeed in LeaseMgr |
| 3861 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 3862 | 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" , 3862, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 3863 | |
| 3864 | // Now check that the lease in LeaseMgr has the same parameters |
| 3865 | detailCompareLease(lease, from_mgr); |
| 3866 | |
| 3867 | // Client had no lease in the database, so the old lease returned should |
| 3868 | // be NULL. |
| 3869 | 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" , 3869, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 3870 | } |
| 3871 | |
| 3872 | // Exercises AllocEnginer4Test::updateExtendedInfo4() through various |
| 3873 | // permutations of client packet content. |
| 3874 | 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" , 3874), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3874), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3874), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_updateExtendedInfo4_Test >); void AllocEngine4Test_updateExtendedInfo4_Test::TestBody () { |
| 3875 | |
| 3876 | // Structure that defines a test scenario. |
| 3877 | struct Scenario { |
| 3878 | std::string description_; // test description |
| 3879 | std::string orig_context_json_; // user context the lease begins with |
| 3880 | std::string rai_data_; // RAI option the client packet contains |
| 3881 | std::string exp_context_json_; // expected user context on the lease |
| 3882 | bool exp_ret; // expected returned value |
| 3883 | }; |
| 3884 | |
| 3885 | // Test scenarios. |
| 3886 | std::vector<Scenario> scenarios { |
| 3887 | { |
| 3888 | "no context, no rai", |
| 3889 | "", |
| 3890 | "", |
| 3891 | "", |
| 3892 | false |
| 3893 | }, |
| 3894 | { |
| 3895 | "some original context, no rai", |
| 3896 | "{\"foo\": 123}", |
| 3897 | "", |
| 3898 | "{\"foo\": 123}", |
| 3899 | false |
| 3900 | }, |
| 3901 | { |
| 3902 | "no original context, rai", |
| 3903 | "", |
| 3904 | "0x52060104aabbccdd", |
| 3905 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3906 | " \"0x0104AABBCCDD\" } } }", |
| 3907 | true |
| 3908 | }, |
| 3909 | { |
| 3910 | "no original context, rai, remote and relay ids", |
| 3911 | "", |
| 3912 | "0x520a02030102030c03aabbcc", |
| 3913 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3914 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
| 3915 | " \"relay-id\": \"AABBCC\" } } }", |
| 3916 | true |
| 3917 | }, |
| 3918 | { |
| 3919 | "some original context, rai", |
| 3920 | "{\"foo\": 123, \"ISC\":{\"bar\": 456}}", |
| 3921 | "0x52060104aabbccdd", |
| 3922 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3923 | " \"0x0104AABBCCDD\" }, \"bar\": 456 }, \"foo\": 123 }", |
| 3924 | true |
| 3925 | }, |
| 3926 | { |
| 3927 | "bad original context, rai", |
| 3928 | "[\"foo\"]", |
| 3929 | "0x52060104aabbccdd", |
| 3930 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3931 | " \"0x0104AABBCCDD\" } } }", |
| 3932 | true |
| 3933 | }, |
| 3934 | { |
| 3935 | "some original context with bad isc entry, rai", |
| 3936 | "{\"foo\": 123, \"ISC\":[\"bar\"]}", |
| 3937 | "0x52060104aabbccdd", |
| 3938 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3939 | " \"0x0104AABBCCDD\" } }, \"foo\": 123 }", |
| 3940 | true |
| 3941 | }, |
| 3942 | { |
| 3943 | "some original context, rai, remote and relay ids", |
| 3944 | "{\"foo\": 123, \"ISC\":{ \"bar\": 456}}", |
| 3945 | "0x520a02030102030c03aabbcc", |
| 3946 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3947 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
| 3948 | " \"relay-id\": \"AABBCC\" }, \"bar\": 456 }, \"foo\": 123 }", |
| 3949 | true |
| 3950 | }, |
| 3951 | { |
| 3952 | "original rai context, no rai", |
| 3953 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3954 | " \"0x0104AABBCCDD\" } } }", |
| 3955 | "", |
| 3956 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3957 | " \"0x0104AABBCCDD\" } } }", |
| 3958 | false |
| 3959 | }, |
| 3960 | { |
| 3961 | "original rai context, different rai", |
| 3962 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3963 | " \"0x0104AABBCCDD\" } } }", |
| 3964 | "0x52060104ddeeffaa", |
| 3965 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3966 | " \"0x0104DDEEFFAA\" } } }", |
| 3967 | true |
| 3968 | }, |
| 3969 | { |
| 3970 | "original rai context, different rai, remote and relay ids", |
| 3971 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3972 | " \"0x0104AABBCCDD\" } } }", |
| 3973 | "0x520a02030102030c03aabbcc", |
| 3974 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 3975 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
| 3976 | " \"relay-id\": \"AABBCC\" } } }", |
| 3977 | true |
| 3978 | }}; |
| 3979 | |
| 3980 | // Create the allocation engine, context and lease. |
| 3981 | NakedAllocEngine engine(0); |
| 3982 | |
| 3983 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 3984 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 3985 | false, false, "", true); |
| 3986 | |
| 3987 | // All scenarios require storage to be enabled. |
| 3988 | subnet_->setStoreExtendedInfo(true); |
| 3989 | |
| 3990 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 3991 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 3992 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 3992, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 3993 | 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" , 3993, gtest_ar.failure_message()) = ::testing::Message(); |
| 3994 | |
| 3995 | // Verify that the lease begins with no user context. |
| 3996 | ConstElementPtr user_context = lease->getContext(); |
| 3997 | 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" , 3997, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "true", "false") .c_str()) = ::testing::Message (); |
| 3998 | |
| 3999 | // Iterate over the test scenarios. |
| 4000 | ElementPtr orig_context; |
| 4001 | ElementPtr exp_context; |
| 4002 | for (auto const& scenario : scenarios) { |
| 4003 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4003( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4003, (scenario.description_)); |
| 4004 | |
| 4005 | // Create the original user context from JSON. |
| 4006 | if (scenario.orig_context_json_.empty()) { |
| 4007 | orig_context.reset(); |
| 4008 | } else { |
| 4009 | 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_4009; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4009 ; } } else gtest_label_testnothrow_4009 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4009, ("Expected: " "orig_context = Element::fromJSON(scenario.orig_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4010 | << "invalid orig_context_json_, test is broken"; |
| 4011 | } |
| 4012 | |
| 4013 | // Create the expected user context from JSON. |
| 4014 | if (scenario.exp_context_json_.empty()) { |
| 4015 | exp_context.reset(); |
| 4016 | } else { |
| 4017 | 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_4017; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4017 ; } } else gtest_label_testnothrow_4017 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4017, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4018 | << "invalid exp_context_json_, test is broken"; |
| 4019 | } |
| 4020 | |
| 4021 | // Initialize lease's user context. |
| 4022 | lease->setContext(orig_context); |
| 4023 | if (!orig_context) { |
| 4024 | 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" , 4024, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4025 | } else { |
| 4026 | 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" , 4026, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4027 | 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" , 4027, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "orig_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message(); |
| 4028 | } |
| 4029 | |
| 4030 | // Create the client packet and the add RAI option (if one). |
| 4031 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4032 | if (!scenario.rai_data_.empty()) { |
| 4033 | std::vector<uint8_t> opt_data; |
| 4034 | 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_4034; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4034 ; } } else gtest_label_testnothrow_4034 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4034, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4035 | << "scenario.rai_data_ is invalid, test is broken"; |
| 4036 | const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF(); |
| 4037 | ASSERT_GT(opt_data.size(), 2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGT("opt_data.size()" , "2", opt_data.size(), 2))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4037, gtest_ar.failure_message()) = ::testing::Message(); |
| 4038 | 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" , 4038, gtest_ar.failure_message()) = ::testing::Message(); |
| 4039 | ASSERT_EQ(opt_data[1] + 2, opt_data.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("opt_data[1] + 2" , "opt_data.size()", opt_data[1] + 2, opt_data.size()))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4039, gtest_ar.failure_message()) = ::testing::Message(); |
| 4040 | std::vector<uint8_t> rai_data(opt_data.cbegin() + 2, |
| 4041 | opt_data.cend()); |
| 4042 | OptionCustomPtr rai; |
| 4043 | 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_4044; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4044; } } else gtest_label_testnothrow_4044 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4044, ("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() |
| 4044 | 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_4044; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4044; } } else gtest_label_testnothrow_4044 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4044, ("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() |
| 4045 | << "could not create rai option, test is broken"; |
| 4046 | ctx.query_->addOption(rai); |
| 4047 | } |
| 4048 | |
| 4049 | // Call AllocEngine::updateLease4ExtendeInfo(). |
| 4050 | bool ret = false; |
| 4051 | 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", 4051, "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", 4051, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4052 | 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" , 4052, gtest_ar.failure_message()) = ::testing::Message(); |
| 4053 | |
| 4054 | // Verify the lease has the expected user context content. |
| 4055 | if (!exp_context) { |
| 4056 | 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" , 4056, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4057 | } else { |
| 4058 | 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" , 4058, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4059 | 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" , 4059, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message() |
| 4060 | << "expected: " << *(exp_context) << std::endl |
| 4061 | << " actual: " << *(lease->getContext()) << std::endl; |
| 4062 | } |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | // Verifies that recovered stashed RAI is not saved in extended info. |
| 4067 | 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" , 4067), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4067), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4067), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_stashAgentOptions_Test >); void AllocEngine4Test_stashAgentOptions_Test::TestBody () { |
| 4068 | // Create the allocation engine, context and lease. |
| 4069 | NakedAllocEngine engine(0); |
| 4070 | |
| 4071 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 4072 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 4073 | false, false, "", true); |
| 4074 | subnet_->setStoreExtendedInfo(true); |
| 4075 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4076 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4077 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4077, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4078 | 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" , 4078, gtest_ar.failure_message()) = ::testing::Message(); |
| 4079 | |
| 4080 | // Verify that the lease begins with no user context. |
| 4081 | ConstElementPtr user_context = lease->getContext(); |
| 4082 | 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" , 4082, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "true", "false") .c_str()) = ::testing::Message (); |
| 4083 | |
| 4084 | // Add a RAI in the query. |
| 4085 | std::string rai_str = "0104aabbccdd"; |
| 4086 | std::vector<uint8_t> rai_data; |
| 4087 | 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_4087; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4087; } } else gtest_label_testnothrow_4087 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4087, ("Expected: " "util::str::decodeFormattedHexString(rai_str, rai_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 4088 | const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF(); |
| 4089 | OptionCustomPtr rai; |
| 4090 | 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_4090; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4090; } } else gtest_label_testnothrow_4090 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4090, ("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(); |
| 4091 | ctx.query_->addOption(rai); |
| 4092 | |
| 4093 | // Verifies that the RAI is saved into lease extended info. |
| 4094 | bool ret = false; |
| 4095 | 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", 4095, "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", 4095, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4096 | 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", 4096, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ret", "false", "true") .c_str()) = ::testing::Message(); |
| 4097 | user_context = lease->getContext(); |
| 4098 | 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" , 4098, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "false", "true") .c_str()) = ::testing::Message (); |
| 4099 | lease->setContext(ElementPtr()); |
| 4100 | |
| 4101 | // Set stash-agent-options to true. |
| 4102 | CfgMgr::instance().getStagingCfg()-> |
| 4103 | addConfiguredGlobal("stash-agent-options", Element::create(true)); |
| 4104 | CfgMgr::instance().commit(); |
| 4105 | |
| 4106 | // Verifies that the RAI is saved into lease extended info. |
| 4107 | ret = false; |
Value stored to 'ret' is never read | |
| 4108 | 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", 4108, "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", 4108, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4109 | 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", 4109, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ret", "false", "true") .c_str()) = ::testing::Message(); |
| 4110 | user_context = lease->getContext(); |
| 4111 | 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" , 4111, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "false", "true") .c_str()) = ::testing::Message (); |
| 4112 | lease->setContext(ElementPtr()); |
| 4113 | |
| 4114 | // Put the query in the STASH_AGENT_OPTIONS class. |
| 4115 | ctx.query_->addClass("STASH_AGENT_OPTIONS"); |
| 4116 | |
| 4117 | // Verifies that the RAI is not saved into lease extended info. |
| 4118 | ret = false; |
| 4119 | ASSERT_NO_THROW_LOG(ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)){ try { ret = engine.callUpdateLease4ExtendedInfo(lease, ctx) ; } catch (const std::exception& ex) { return ::testing:: internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 4119, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc", 4119, "Failed") = ::testing::Message() << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
| 4120 | 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", 4120, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ret", "true", "false") .c_str()) = ::testing::Message(); |
| 4121 | user_context = lease->getContext(); |
| 4122 | 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" , 4122, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "user_context", "true", "false") .c_str()) = ::testing::Message (); |
| 4123 | } |
| 4124 | |
| 4125 | // Verifies that the extended data (e.g. RAI option for now) is |
| 4126 | // added to a V4 lease when leases are created and/or renewed, |
| 4127 | // when store-extended-info is true. |
| 4128 | 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" , 4128), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4128), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4128), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoEnabled4_Test >); void AllocEngine4Test_storeExtendedInfoEnabled4_Test:: TestBody() { |
| 4129 | |
| 4130 | // Structure that defines a test scenario. |
| 4131 | struct Scenario { |
| 4132 | std::string description_; // test description |
| 4133 | std::vector<uint8_t> mac_; // MAC address |
| 4134 | std::string rai_data_; // RAI option the client packet contains |
| 4135 | std::string exp_context_json_; // expected user context on the lease |
| 4136 | std::string exp_address_; // expected lease address |
| 4137 | }; |
| 4138 | |
| 4139 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
| 4140 | std::string mac1_addr = "192.0.2.100"; |
| 4141 | |
| 4142 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
| 4143 | std::string mac2_addr = "192.0.2.101"; |
| 4144 | |
| 4145 | // Test scenarios. |
| 4146 | std::vector<Scenario> scenarios { |
| 4147 | { |
| 4148 | "create client one without rai", |
| 4149 | mac1, |
| 4150 | "", |
| 4151 | "", |
| 4152 | mac1_addr |
| 4153 | }, |
| 4154 | { |
| 4155 | "renew client one without rai", |
| 4156 | {}, |
| 4157 | "", |
| 4158 | "", |
| 4159 | mac1_addr |
| 4160 | }, |
| 4161 | { |
| 4162 | "create client two with rai", |
| 4163 | mac2, |
| 4164 | "0x52050104a1b1c1d1", |
| 4165 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4166 | " \"0x52050104A1B1C1D1\" } } }", |
| 4167 | mac2_addr |
| 4168 | }, |
| 4169 | { |
| 4170 | "renew client two without rai", |
| 4171 | {}, |
| 4172 | "", |
| 4173 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
| 4174 | " \"0x52050104A1B1C1D1\" } } }", |
| 4175 | mac2_addr |
| 4176 | }}; |
| 4177 | |
| 4178 | // Create the allocation engine, context and lease. |
| 4179 | NakedAllocEngine engine(0); |
| 4180 | |
| 4181 | // All of the scenarios require storage to be enabled. |
| 4182 | subnet_->setStoreExtendedInfo(true); |
| 4183 | |
| 4184 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 4185 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 4186 | false, false, "", false); |
| 4187 | |
| 4188 | // Iterate over the test scenarios. |
| 4189 | for (auto const& scenario : scenarios) { |
| 4190 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4190( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4190, (scenario.description_)); |
| 4191 | |
| 4192 | ElementPtr exp_context; |
| 4193 | // Create the expected user context from JSON. |
| 4194 | if (!scenario.exp_context_json_.empty()) { |
| 4195 | 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_4195; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4195 ; } } else gtest_label_testnothrow_4195 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4195, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4196 | << "invalid exp_context_json_, test is broken"; |
| 4197 | } |
| 4198 | |
| 4199 | // If we have a MAC address this scenario is for a new client. |
| 4200 | if (!scenario.mac_.empty()) { |
| 4201 | 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_4201; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4201; } } else gtest_label_testnothrow_4201 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4201, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4202 | << "invalid MAC address, test is broken"; |
| 4203 | } |
| 4204 | |
| 4205 | // Create the client packet and the add RAI option (if one). |
| 4206 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4207 | if (!scenario.rai_data_.empty()) { |
| 4208 | std::vector<uint8_t> opt_data; |
| 4209 | 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_4209; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4209 ; } } else gtest_label_testnothrow_4209 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4209, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4210 | << "scenario.rai_data_ is invalid, test is broken"; |
| 4211 | OptionPtr rai; |
| 4212 | 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_4212; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4212; } } else gtest_label_testnothrow_4212 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4212, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4213 | << "could not create rai option, test is broken"; |
| 4214 | |
| 4215 | ctx.query_->addOption(rai); |
| 4216 | } |
| 4217 | |
| 4218 | // Create or renew the lease. |
| 4219 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4220 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4220, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4221 | 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" , 4221, gtest_ar.failure_message()) = ::testing::Message(); |
| 4222 | |
| 4223 | // Verify the lease has the expected user context content. |
| 4224 | if (!exp_context) { |
| 4225 | 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" , 4225, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4226 | } else { |
| 4227 | 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" , 4227, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
| 4228 | 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" , 4228, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message() |
| 4229 | << "expected: " << *(exp_context) << std::endl |
| 4230 | << " actual: " << *(lease->getContext()) << std::endl; |
| 4231 | } |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | // Verifies that the extended data (e.g. RAI option for now) is |
| 4236 | // not added to a V4 lease when leases are created and/or renewed, |
| 4237 | // when store-extended-info is false. |
| 4238 | 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" , 4238), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4238), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4238), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoDisabled4_Test >); void AllocEngine4Test_storeExtendedInfoDisabled4_Test:: TestBody() { |
| 4239 | |
| 4240 | // Structure that defines a test scenario. |
| 4241 | struct Scenario { |
| 4242 | std::string description_; // test description |
| 4243 | std::vector<uint8_t> mac_; // MAC address |
| 4244 | std::string rai_data_; // RAI option the client packet contains |
| 4245 | std::string exp_address_; // expected lease address |
| 4246 | }; |
| 4247 | |
| 4248 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
| 4249 | std::string mac1_addr = "192.0.2.100"; |
| 4250 | |
| 4251 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
| 4252 | std::string mac2_addr = "192.0.2.101"; |
| 4253 | |
| 4254 | // Test scenarios. |
| 4255 | std::vector<Scenario> scenarios { |
| 4256 | { |
| 4257 | "create client one without rai", |
| 4258 | mac1, |
| 4259 | "", |
| 4260 | mac1_addr |
| 4261 | }, |
| 4262 | { |
| 4263 | "renew client one without rai", |
| 4264 | {}, |
| 4265 | "", |
| 4266 | mac1_addr |
| 4267 | }, |
| 4268 | { |
| 4269 | "create client two with rai", |
| 4270 | mac2, |
| 4271 | "0x52050104a1b1c1d1", |
| 4272 | mac2_addr |
| 4273 | }, |
| 4274 | { |
| 4275 | "renew client two with rai", |
| 4276 | {}, |
| 4277 | "0x52050104a1b1c1d1", |
| 4278 | mac2_addr |
| 4279 | }}; |
| 4280 | |
| 4281 | // Create the allocation engine, context and lease. |
| 4282 | NakedAllocEngine engine(0); |
| 4283 | |
| 4284 | // All of the scenarios require storage to be disabled. |
| 4285 | subnet_->setStoreExtendedInfo(false); |
| 4286 | |
| 4287 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 4288 | IOAddress::IPV4_ZERO_ADDRESS(), |
| 4289 | false, false, "", false); |
| 4290 | |
| 4291 | // Iterate over the test scenarios. |
| 4292 | for (auto const& scenario : scenarios) { |
| 4293 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4293( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4293, (scenario.description_)); |
| 4294 | |
| 4295 | // If we have a MAC address this scenario is for a new client. |
| 4296 | if (!scenario.mac_.empty()) { |
| 4297 | 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_4297; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4297; } } else gtest_label_testnothrow_4297 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4297, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4298 | << "invalid MAC address, test is broken"; |
| 4299 | } |
| 4300 | |
| 4301 | // Create the client packet and the add RAI option (if one). |
| 4302 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4303 | if (!scenario.rai_data_.empty()) { |
| 4304 | std::vector<uint8_t> opt_data; |
| 4305 | 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_4305; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4305 ; } } else gtest_label_testnothrow_4305 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4305, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4306 | << "scenario.rai_data_ is invalid, test is broken"; |
| 4307 | OptionPtr rai; |
| 4308 | 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_4308; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4308; } } else gtest_label_testnothrow_4308 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4308, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
| 4309 | << "could not create rai option, test is broken"; |
| 4310 | |
| 4311 | ctx.query_->addOption(rai); |
| 4312 | } |
| 4313 | |
| 4314 | // Create or renew the lease. |
| 4315 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4316 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4316, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4317 | 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" , 4317, gtest_ar.failure_message()) = ::testing::Message(); |
| 4318 | |
| 4319 | // Verify the lease does not have user context content. |
| 4320 | 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" , 4320, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
| 4325 | // using cache threshold. |
| 4326 | 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" , 4326), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4326), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4326), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheThreshold4_Test >); void AllocEngine4Test_discoverCacheThreshold4_Test::TestBody () { |
| 4327 | boost::scoped_ptr<AllocEngine> engine; |
| 4328 | 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_4328 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4328 ; } } else gtest_label_testnothrow_4328 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4328, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4329 | 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" , 4329, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4330 | |
| 4331 | // Set valid lifetime to 500. |
| 4332 | uint32_t valid = 500; |
| 4333 | subnet_->setValid(valid); |
| 4334 | |
| 4335 | // Set the threshold to 25%. |
| 4336 | subnet_->setCacheThreshold(.25); |
| 4337 | |
| 4338 | IOAddress addr("192.0.2.105"); |
| 4339 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4340 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4341 | valid, now, subnet_->getID())); |
| 4342 | 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" , 4342, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4343 | 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" , 4343, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4344 | |
| 4345 | // Create a context for fake allocation. |
| 4346 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4347 | false, false, "", true); |
| 4348 | |
| 4349 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4350 | lease = engine->allocateLease4(ctx); |
| 4351 | // Check that we got that single lease. |
| 4352 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4352, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4353 | 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" , 4353, gtest_ar.failure_message()) = ::testing::Message(); |
| 4354 | |
| 4355 | // The lease was reused. |
| 4356 | time_t age = lease->cltt_ - now; |
| 4357 | 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" , 4357, gtest_ar.failure_message()) = ::testing::Message(); |
| 4358 | 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" , 4358, gtest_ar.failure_message()) = ::testing::Message(); |
| 4359 | 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" , 4359, gtest_ar.failure_message()) = ::testing::Message(); |
| 4360 | |
| 4361 | // Check other lease parameters. |
| 4362 | 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" , 4362, gtest_ar.failure_message()) = ::testing::Message(); |
| 4363 | 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" , 4363, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4364 | 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" , 4364, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4365 | 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" , 4365, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4366 | 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" , 4366, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4367 | } |
| 4368 | |
| 4369 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
| 4370 | // using cache threshold. |
| 4371 | 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" , 4371), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4371), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4371), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheThreshold4_Test >); void AllocEngine4Test_requestCacheThreshold4_Test::TestBody () { |
| 4372 | boost::scoped_ptr<AllocEngine> engine; |
| 4373 | 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_4373 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4373 ; } } else gtest_label_testnothrow_4373 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4373, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4374 | 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" , 4374, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4375 | |
| 4376 | // Set valid lifetime to 500. |
| 4377 | uint32_t valid = 500; |
| 4378 | subnet_->setValid(valid); |
| 4379 | |
| 4380 | // Set the threshold to 25%. |
| 4381 | subnet_->setCacheThreshold(.25); |
| 4382 | |
| 4383 | IOAddress addr("192.0.2.105"); |
| 4384 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4385 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4386 | valid, now, subnet_->getID())); |
| 4387 | 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" , 4387, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4388 | // Copy the lease, so as it can be compared with. |
| 4389 | Lease4Ptr original_lease(new Lease4(*lease)); |
| 4390 | 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" , 4390, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4391 | |
| 4392 | // Create a context for real allocation. |
| 4393 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4394 | false, false, "", false); |
| 4395 | |
| 4396 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4397 | lease = engine->allocateLease4(ctx); |
| 4398 | // Check that we got that single lease. |
| 4399 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4399, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4400 | 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" , 4400, gtest_ar.failure_message()) = ::testing::Message(); |
| 4401 | |
| 4402 | // The lease was reused. |
| 4403 | time_t age = lease->cltt_ - now; |
| 4404 | 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" , 4404, gtest_ar.failure_message()) = ::testing::Message(); |
| 4405 | 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" , 4405, gtest_ar.failure_message()) = ::testing::Message(); |
| 4406 | 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" , 4406, gtest_ar.failure_message()) = ::testing::Message(); |
| 4407 | |
| 4408 | // Check other lease parameters. |
| 4409 | 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" , 4409, gtest_ar.failure_message()) = ::testing::Message(); |
| 4410 | 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" , 4410, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4411 | 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" , 4411, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4412 | 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" , 4412, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4413 | 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" , 4413, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4414 | |
| 4415 | // Check the lease was not updated in the database. |
| 4416 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4417 | 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" , 4417, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4418 | |
| 4419 | detailCompareLease(original_lease, from_mgr); |
| 4420 | } |
| 4421 | |
| 4422 | /// We proved that there is no different from the "cache" feature between |
| 4423 | /// discovers and request at the exception of the lease database update. |
| 4424 | |
| 4425 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
| 4426 | // using cache max age. |
| 4427 | 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" , 4427), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4427), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4427), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheMaxAge4_Test >); void AllocEngine4Test_discoverCacheMaxAge4_Test::TestBody () { |
| 4428 | boost::scoped_ptr<AllocEngine> engine; |
| 4429 | 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_4429 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4429 ; } } else gtest_label_testnothrow_4429 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4429, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4430 | 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" , 4430, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4431 | |
| 4432 | // Set valid lifetime to 500. |
| 4433 | uint32_t valid = 500; |
| 4434 | subnet_->setValid(valid); |
| 4435 | |
| 4436 | // Set the max age to 200. |
| 4437 | subnet_->setCacheMaxAge(200); |
| 4438 | |
| 4439 | IOAddress addr("192.0.2.105"); |
| 4440 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4441 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4442 | valid, now, subnet_->getID())); |
| 4443 | 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" , 4443, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4444 | 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" , 4444, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4445 | |
| 4446 | // Create a context for fake allocation. |
| 4447 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4448 | false, false, "", true); |
| 4449 | |
| 4450 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4451 | lease = engine->allocateLease4(ctx); |
| 4452 | // Check that we got that single lease. |
| 4453 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4453, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4454 | 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" , 4454, gtest_ar.failure_message()) = ::testing::Message(); |
| 4455 | |
| 4456 | // The lease was reused. |
| 4457 | time_t age = lease->cltt_ - now; |
| 4458 | 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" , 4458, gtest_ar.failure_message()) = ::testing::Message(); |
| 4459 | 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" , 4459, gtest_ar.failure_message()) = ::testing::Message(); |
| 4460 | 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" , 4460, gtest_ar.failure_message()) = ::testing::Message(); |
| 4461 | |
| 4462 | // Check other lease parameters. |
| 4463 | 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" , 4463, gtest_ar.failure_message()) = ::testing::Message(); |
| 4464 | 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" , 4464, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4465 | 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" , 4465, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4466 | 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" , 4466, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4467 | 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" , 4467, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4468 | } |
| 4469 | |
| 4470 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
| 4471 | // using both cache threshold and max age. |
| 4472 | 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" , 4472), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4472), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4472), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBoth4_Test >); void AllocEngine4Test_requestCacheBoth4_Test::TestBody () { |
| 4473 | boost::scoped_ptr<AllocEngine> engine; |
| 4474 | 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_4474 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4474 ; } } else gtest_label_testnothrow_4474 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4474, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4475 | 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" , 4475, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4476 | |
| 4477 | // Set valid lifetime to 500. |
| 4478 | uint32_t valid = 500; |
| 4479 | subnet_->setValid(valid); |
| 4480 | |
| 4481 | // Set the threshold to 25%. |
| 4482 | subnet_->setCacheThreshold(.25); |
| 4483 | |
| 4484 | // Set the max age to 200. |
| 4485 | subnet_->setCacheMaxAge(200); |
| 4486 | |
| 4487 | IOAddress addr("192.0.2.105"); |
| 4488 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4489 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4490 | valid, now, subnet_->getID())); |
| 4491 | 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" , 4491, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4492 | // Copy the lease, so as it can be compared with. |
| 4493 | Lease4Ptr original_lease(new Lease4(*lease)); |
| 4494 | 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" , 4494, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4495 | |
| 4496 | // Create a context for real allocation. |
| 4497 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4498 | false, false, "", false); |
| 4499 | |
| 4500 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4501 | lease = engine->allocateLease4(ctx); |
| 4502 | // Check that we got that single lease. |
| 4503 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4503, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4504 | 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" , 4504, gtest_ar.failure_message()) = ::testing::Message(); |
| 4505 | |
| 4506 | // The lease was reused. |
| 4507 | time_t age = lease->cltt_ - now; |
| 4508 | 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" , 4508, gtest_ar.failure_message()) = ::testing::Message(); |
| 4509 | 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" , 4509, gtest_ar.failure_message()) = ::testing::Message(); |
| 4510 | 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" , 4510, gtest_ar.failure_message()) = ::testing::Message(); |
| 4511 | |
| 4512 | // Check other lease parameters. |
| 4513 | 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" , 4513, gtest_ar.failure_message()) = ::testing::Message(); |
| 4514 | 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" , 4514, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4515 | 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" , 4515, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 4516 | 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" , 4516, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 4517 | 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" , 4517, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 4518 | |
| 4519 | // Check the lease was not updated in the database. |
| 4520 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4521 | 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" , 4521, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4522 | |
| 4523 | detailCompareLease(original_lease, from_mgr); |
| 4524 | } |
| 4525 | |
| 4526 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
| 4527 | // using too small cache threshold. |
| 4528 | 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" , 4528), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4528), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4528), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheBadThreshold4_Test >); void AllocEngine4Test_discoverCacheBadThreshold4_Test:: TestBody() { |
| 4529 | boost::scoped_ptr<AllocEngine> engine; |
| 4530 | 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_4530 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4530 ; } } else gtest_label_testnothrow_4530 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4530, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4531 | 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" , 4531, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4532 | |
| 4533 | // Set valid lifetime to 500. |
| 4534 | uint32_t valid = 500; |
| 4535 | subnet_->setValid(valid); |
| 4536 | |
| 4537 | // Set the threshold to 10%. |
| 4538 | subnet_->setCacheThreshold(.10); |
| 4539 | |
| 4540 | IOAddress addr("192.0.2.105"); |
| 4541 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4542 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4543 | valid, now, subnet_->getID())); |
| 4544 | 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" , 4544, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4545 | 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" , 4545, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4546 | |
| 4547 | // Create a context for fake allocation. |
| 4548 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4549 | false, false, "", true); |
| 4550 | |
| 4551 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4552 | lease = engine->allocateLease4(ctx); |
| 4553 | // Check that we got that single lease. |
| 4554 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4554, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4555 | 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" , 4555, gtest_ar.failure_message()) = ::testing::Message(); |
| 4556 | |
| 4557 | // The lease was not reused. |
| 4558 | EXPECT_EQ(0, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "lease->reuseable_valid_lft_" , 0, lease->reuseable_valid_lft_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4558, gtest_ar.failure_message()) = ::testing::Message(); |
| 4559 | } |
| 4560 | |
| 4561 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
| 4562 | // using too small cache max age. |
| 4563 | 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" , 4563), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4563), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4563), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBadMaxAge4_Test >); void AllocEngine4Test_requestCacheBadMaxAge4_Test::TestBody () { |
| 4564 | boost::scoped_ptr<AllocEngine> engine; |
| 4565 | 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_4565 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4565 ; } } else gtest_label_testnothrow_4565 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4565, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4566 | 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" , 4566, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4567 | |
| 4568 | // Set valid lifetime to 500. |
| 4569 | uint32_t valid = 500; |
| 4570 | subnet_->setValid(valid); |
| 4571 | |
| 4572 | // Set the threshold to 25%. |
| 4573 | subnet_->setCacheThreshold(.25); |
| 4574 | |
| 4575 | // Set the max age to 50. |
| 4576 | subnet_->setCacheMaxAge(50); |
| 4577 | |
| 4578 | IOAddress addr("192.0.2.105"); |
| 4579 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4580 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4581 | valid, now, subnet_->getID())); |
| 4582 | 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" , 4582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4583 | |
| 4584 | // Create a context for real allocation. |
| 4585 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4586 | false, false, "", false); |
| 4587 | |
| 4588 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4589 | lease = engine->allocateLease4(ctx); |
| 4590 | // Check that we got that single lease. |
| 4591 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4591, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4592 | 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" , 4592, gtest_ar.failure_message()) = ::testing::Message(); |
| 4593 | |
| 4594 | // The lease was not reused. |
| 4595 | EXPECT_EQ(0, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "lease->reuseable_valid_lft_" , 0, lease->reuseable_valid_lft_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4595, gtest_ar.failure_message()) = ::testing::Message(); |
| 4596 | |
| 4597 | // Check the lease was updated in the database. |
| 4598 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4599 | 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" , 4599, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4600 | |
| 4601 | detailCompareLease(lease, from_mgr); |
| 4602 | } |
| 4603 | |
| 4604 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
| 4605 | // when the valid lifetime was reduced. |
| 4606 | 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" , 4606), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4606), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4606), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheReducedValid4_Test >); void AllocEngine4Test_discoverCacheReducedValid4_Test:: TestBody() { |
| 4607 | boost::scoped_ptr<AllocEngine> engine; |
| 4608 | 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_4608 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4608 ; } } else gtest_label_testnothrow_4608 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4608, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4609 | 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" , 4609, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4610 | |
| 4611 | // Set valid lifetime to 200. |
| 4612 | subnet_->setValid(200); |
| 4613 | |
| 4614 | // Set the threshold to 25%. |
| 4615 | subnet_->setCacheThreshold(.25); |
| 4616 | |
| 4617 | IOAddress addr("192.0.2.105"); |
| 4618 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4619 | uint32_t valid = 500; // Used a value greater than subnet_->getValid(). |
| 4620 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4621 | valid, now, subnet_->getID())); |
| 4622 | 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" , 4622, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4623 | 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" , 4623, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4624 | |
| 4625 | // Create a context for fake allocation. |
| 4626 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4627 | false, false, "", true); |
| 4628 | |
| 4629 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4630 | lease = engine->allocateLease4(ctx); |
| 4631 | // Check that we got that single lease. |
| 4632 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4632, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4633 | 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" , 4633, gtest_ar.failure_message()) = ::testing::Message(); |
| 4634 | |
| 4635 | // The lease was not reused. |
| 4636 | EXPECT_EQ(0, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "lease->reuseable_valid_lft_" , 0, lease->reuseable_valid_lft_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4636, gtest_ar.failure_message()) = ::testing::Message(); |
| 4637 | } |
| 4638 | |
| 4639 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
| 4640 | // when DDNS parameter changed. |
| 4641 | 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" , 4641), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4641), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4641), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheFwdDDNS4_Test >); void AllocEngine4Test_requestCacheFwdDDNS4_Test::TestBody () { |
| 4642 | boost::scoped_ptr<AllocEngine> engine; |
| 4643 | 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_4643 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4643 ; } } else gtest_label_testnothrow_4643 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4643, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4644 | 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" , 4644, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4645 | |
| 4646 | // Set valid lifetime to 500. |
| 4647 | uint32_t valid = 500; |
| 4648 | subnet_->setValid(valid); |
| 4649 | |
| 4650 | // Set the max age to 200. |
| 4651 | subnet_->setCacheMaxAge(200); |
| 4652 | |
| 4653 | IOAddress addr("192.0.2.105"); |
| 4654 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4655 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4656 | valid, now, subnet_->getID())); |
| 4657 | 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" , 4657, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4658 | |
| 4659 | // Create a context for real allocation with fwd_dns_update changed. |
| 4660 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4661 | true, false, "", false); |
| 4662 | |
| 4663 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 4664 | lease = engine->allocateLease4(ctx); |
| 4665 | // Check that we got that single lease. |
| 4666 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4666, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4667 | 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" , 4667, gtest_ar.failure_message()) = ::testing::Message(); |
| 4668 | |
| 4669 | // The lease was not reused. |
| 4670 | EXPECT_EQ(0, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "lease->reuseable_valid_lft_" , 0, lease->reuseable_valid_lft_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4670, gtest_ar.failure_message()) = ::testing::Message(); |
| 4671 | |
| 4672 | // Check the lease was updated in the database. |
| 4673 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4674 | 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" , 4674, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4675 | |
| 4676 | detailCompareLease(lease, from_mgr); |
| 4677 | } |
| 4678 | |
| 4679 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
| 4680 | // when DDNS parameter changed. |
| 4681 | 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" , 4681), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4681), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4681), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheRevDDNS4_Test >); void AllocEngine4Test_discoverCacheRevDDNS4_Test::TestBody () { |
| 4682 | boost::scoped_ptr<AllocEngine> engine; |
| 4683 | 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_4683 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4683 ; } } else gtest_label_testnothrow_4683 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4683, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 4684 | 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" , 4684, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 4685 | |
| 4686 | // Set valid lifetime to 500. |
| 4687 | uint32_t valid = 500; |
| 4688 | subnet_->setValid(valid); |
| 4689 | |
| 4690 | // Set the threshold to 25%. |
| 4691 | subnet_->setCacheThreshold(.25); |
| 4692 | |
| 4693 | // Set the max age to 200. |
| 4694 | subnet_->setCacheMaxAge(200); |
| 4695 | |
| 4696 | IOAddress addr("192.0.2.105"); |
| 4697 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4698 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4699 | valid, now, subnet_->getID())); |
| 4700 | 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" , 4700, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4701 | 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" , 4701, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 4702 | |
| 4703 | // Create a context for fake allocation with rev_dns_update changed. |
| 4704 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4705 | false, true, "", true); |
| 4706 | |
| 4707 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4708 | lease = engine->allocateLease4(ctx); |
| 4709 | // Check that we got that single lease. |
| 4710 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4710, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4711 | 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" , 4711, gtest_ar.failure_message()) = ::testing::Message(); |
| 4712 | |
| 4713 | // The lease was not reused. |
| 4714 | EXPECT_EQ(0, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "lease->reuseable_valid_lft_" , 0, lease->reuseable_valid_lft_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4714, gtest_ar.failure_message()) = ::testing::Message(); |
| 4715 | } |
| 4716 | |
| 4717 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
| 4718 | // when hostname changed. |
| 4719 | 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" , 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_requestCacheHostname4_Test >); void AllocEngine4Test_requestCacheHostname4_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(NULL__null) - 100; // Allocated 100 seconds ago. |
| 4733 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
| 4734 | valid, now, subnet_->getID(), |
| 4735 | false, false, "foo")); |
| 4736 | 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" , 4736, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 4737 | |
| 4738 | // Create a context for real allocation with fwd_dns_update changed. |
| 4739 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
| 4740 | false, false, "bar", false); |
| 4741 | |
| 4742 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 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 not reused. |
| 4749 | EXPECT_EQ(0, lease->reuseable_valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "lease->reuseable_valid_lft_" , 0, lease->reuseable_valid_lft_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4749, gtest_ar.failure_message()) = ::testing::Message(); |
| 4750 | 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" , 4750, gtest_ar.failure_message()) = ::testing::Message(); |
| 4751 | |
| 4752 | // Check the lease was updated in the database. |
| 4753 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
| 4754 | 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" , 4754, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 4755 | |
| 4756 | detailCompareLease(lease, from_mgr); |
| 4757 | } |
| 4758 | |
| 4759 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
| 4760 | // lifetime value based on the context content. |
| 4761 | 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", 4761 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4761), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4761), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getValidLft4_Test >); void AllocEngine4Test_getValidLft4_Test::TestBody() { |
| 4762 | AllocEngine engine(0); |
| 4763 | |
| 4764 | // Let's make three classes, two with valid-lifetime and one without, |
| 4765 | // and add them to the dictionary. |
| 4766 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 4767 | |
| 4768 | ClientClassDefPtr class_def(new ClientClassDef("valid_one", ExpressionPtr())); |
| 4769 | Triplet<uint32_t> valid_one(50, 100, 150); |
| 4770 | class_def->setValid(valid_one); |
| 4771 | dictionary->addClass(class_def); |
| 4772 | |
| 4773 | class_def.reset(new ClientClassDef("valid_two", ExpressionPtr())); |
| 4774 | Triplet<uint32_t>valid_two(200, 250, 300); |
| 4775 | class_def->setValid(valid_two); |
| 4776 | dictionary->addClass(class_def); |
| 4777 | |
| 4778 | class_def.reset(new ClientClassDef("valid_unspec", ExpressionPtr())); |
| 4779 | dictionary->addClass(class_def); |
| 4780 | |
| 4781 | // Commit our class changes. |
| 4782 | CfgMgr::instance().commit(); |
| 4783 | |
| 4784 | // Update the subnet's triplet to something more useful. |
| 4785 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
| 4786 | |
| 4787 | // Describes a test scenario. |
| 4788 | struct Scenario { |
| 4789 | std::string desc_; // descriptive text for logging |
| 4790 | std::vector<std::string> classes_; // class list of assigned classes |
| 4791 | uint32_t requested_lft_; // use as option 51 is > 0 |
| 4792 | uint32_t exp_valid_; // expected lifetime |
| 4793 | }; |
| 4794 | |
| 4795 | // Scenarios to test. |
| 4796 | std::vector<Scenario> scenarios = { |
| 4797 | { |
| 4798 | "BOOTP", |
| 4799 | { "BOOTP" }, |
| 4800 | 0, |
| 4801 | Lease::INFINITY_LFT |
| 4802 | }, |
| 4803 | { |
| 4804 | "no classes, no option", |
| 4805 | {}, |
| 4806 | 0, |
| 4807 | subnet_->getValid() |
| 4808 | }, |
| 4809 | { |
| 4810 | "no classes, option", |
| 4811 | {}, |
| 4812 | subnet_->getValid().getMin() + 50, |
| 4813 | subnet_->getValid().getMin() + 50 |
| 4814 | }, |
| 4815 | { |
| 4816 | "no classes, option too small", |
| 4817 | {}, |
| 4818 | subnet_->getValid().getMin() - 50, |
| 4819 | subnet_->getValid().getMin() |
| 4820 | }, |
| 4821 | { |
| 4822 | "no classes, option too big", |
| 4823 | {}, |
| 4824 | subnet_->getValid().getMax() + 50, |
| 4825 | subnet_->getValid().getMax() |
| 4826 | }, |
| 4827 | { |
| 4828 | "class unspecified, no option", |
| 4829 | { "valid_unspec" }, |
| 4830 | 0, |
| 4831 | subnet_->getValid() |
| 4832 | }, |
| 4833 | { |
| 4834 | "from last class, no option", |
| 4835 | { "valid_unspec", "valid_one" }, |
| 4836 | 0, |
| 4837 | valid_one.get() |
| 4838 | }, |
| 4839 | { |
| 4840 | "from first class, no option", |
| 4841 | { "valid_two", "valid_one" }, |
| 4842 | 0, |
| 4843 | valid_two.get() |
| 4844 | }, |
| 4845 | { |
| 4846 | "class plus option", |
| 4847 | { "valid_one" }, |
| 4848 | valid_one.getMin() + 25, |
| 4849 | valid_one.getMin() + 25 |
| 4850 | }, |
| 4851 | { |
| 4852 | "class plus option too small", |
| 4853 | { "valid_one" }, |
| 4854 | valid_one.getMin() - 25, |
| 4855 | valid_one.getMin() |
| 4856 | }, |
| 4857 | { |
| 4858 | "class plus option too big", |
| 4859 | { "valid_one" }, |
| 4860 | valid_one.getMax() + 25, |
| 4861 | valid_one.getMax() |
| 4862 | } |
| 4863 | }; |
| 4864 | |
| 4865 | // Iterate over the scenarios and verify the correct outcome. |
| 4866 | for (auto const& scenario : scenarios) { |
| 4867 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_4867( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4867, (scenario.desc_)); { |
| 4868 | // Create a context; |
| 4869 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 4870 | IOAddress("0.0.0.0"), false, false, |
| 4871 | "", false); |
| 4872 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 4873 | |
| 4874 | // Add client classes (if any) |
| 4875 | for (auto const& class_name : scenario.classes_) { |
| 4876 | ctx.query_->addClass(class_name); |
| 4877 | } |
| 4878 | |
| 4879 | // Add client option (if one) |
| 4880 | if (scenario.requested_lft_) { |
| 4881 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
| 4882 | scenario.requested_lft_)); |
| 4883 | ctx.query_->addOption(opt); |
| 4884 | } |
| 4885 | |
| 4886 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 4887 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4887, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 4888 | 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" , 4888, gtest_ar.failure_message()) = ::testing::Message(); |
| 4889 | } |
| 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
| 4894 | // lifetime value based on the context content. |
| 4895 | 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" , 4895), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4895), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 4895), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getTemplateClassValidLft4_Test >); void AllocEngine4Test_getTemplateClassValidLft4_Test:: TestBody() { |
| 4896 | AllocEngine engine(0); |
| 4897 | |
| 4898 | // Let's make three classes, two with valid-lifetime and one without, |
| 4899 | // and add them to the dictionary. |
| 4900 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 4901 | ExpressionPtr match_expr; |
| 4902 | ExpressionParser parser; |
| 4903 | |
| 4904 | ElementPtr test_cfg = Element::create("'valid_one_value'"); |
| 4905 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 4906 | |
| 4907 | ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr)); |
| 4908 | Triplet<uint32_t> valid_one(50, 100, 150); |
| 4909 | class_def->setValid(valid_one); |
| 4910 | dictionary->addClass(class_def); |
| 4911 | |
| 4912 | test_cfg = Element::create("'valid_two_value'"); |
| 4913 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 4914 | |
| 4915 | class_def.reset(new TemplateClientClassDef("valid_two", match_expr)); |
| 4916 | Triplet<uint32_t>valid_two(200, 250, 300); |
| 4917 | class_def->setValid(valid_two); |
| 4918 | dictionary->addClass(class_def); |
| 4919 | |
| 4920 | test_cfg = Element::create("'valid_unspec_value'"); |
| 4921 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 4922 | |
| 4923 | class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr)); |
| 4924 | dictionary->addClass(class_def); |
| 4925 | |
| 4926 | // Commit our class changes. |
| 4927 | CfgMgr::instance().commit(); |
| 4928 | |
| 4929 | // Update the subnet's triplet to something more useful. |
| 4930 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
| 4931 | |
| 4932 | // Describes a test scenario. |
| 4933 | struct Scenario { |
| 4934 | std::string desc_; // descriptive text for logging |
| 4935 | std::vector<std::string> classes_; // class list of assigned classes |
| 4936 | uint32_t requested_lft_; // use as option 51 is > 0 |
| 4937 | uint32_t exp_valid_; // expected lifetime |
| 4938 | }; |
| 4939 | |
| 4940 | // Scenarios to test. |
| 4941 | std::vector<Scenario> scenarios = { |
| 4942 | { |
| 4943 | "BOOTP", |
| 4944 | { "BOOTP" }, |
| 4945 | 0, |
| 4946 | Lease::INFINITY_LFT |
| 4947 | }, |
| 4948 | { |
| 4949 | "no classes, no option", |
| 4950 | {}, |
| 4951 | 0, |
| 4952 | subnet_->getValid() |
| 4953 | }, |
| 4954 | { |
| 4955 | "no classes, option", |
| 4956 | {}, |
| 4957 | subnet_->getValid().getMin() + 50, |
| 4958 | subnet_->getValid().getMin() + 50 |
| 4959 | }, |
| 4960 | { |
| 4961 | "no classes, option too small", |
| 4962 | {}, |
| 4963 | subnet_->getValid().getMin() - 50, |
| 4964 | subnet_->getValid().getMin() |
| 4965 | }, |
| 4966 | { |
| 4967 | "no classes, option too big", |
| 4968 | {}, |
| 4969 | subnet_->getValid().getMax() + 50, |
| 4970 | subnet_->getValid().getMax() |
| 4971 | }, |
| 4972 | { |
| 4973 | "class unspecified, no option", |
| 4974 | { "valid_unspec" }, |
| 4975 | 0, |
| 4976 | subnet_->getValid() |
| 4977 | }, |
| 4978 | { |
| 4979 | "from last class, no option", |
| 4980 | { "valid_unspec", "valid_one" }, |
| 4981 | 0, |
| 4982 | valid_one.get() |
| 4983 | }, |
| 4984 | { |
| 4985 | "from first class, no option", |
| 4986 | { "valid_two", "valid_one" }, |
| 4987 | 0, |
| 4988 | valid_two.get() |
| 4989 | }, |
| 4990 | { |
| 4991 | "class plus option", |
| 4992 | { "valid_one" }, |
| 4993 | valid_one.getMin() + 25, |
| 4994 | valid_one.getMin() + 25 |
| 4995 | }, |
| 4996 | { |
| 4997 | "class plus option too small", |
| 4998 | { "valid_one" }, |
| 4999 | valid_one.getMin() - 25, |
| 5000 | valid_one.getMin() |
| 5001 | }, |
| 5002 | { |
| 5003 | "class plus option too big", |
| 5004 | { "valid_one" }, |
| 5005 | valid_one.getMax() + 25, |
| 5006 | valid_one.getMax() |
| 5007 | } |
| 5008 | }; |
| 5009 | |
| 5010 | // Iterate over the scenarios and verify the correct outcome. |
| 5011 | for (auto const& scenario : scenarios) { |
| 5012 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5012( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5012, (scenario.desc_)); { |
| 5013 | // Create a context; |
| 5014 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 5015 | IOAddress("0.0.0.0"), false, false, |
| 5016 | "", false); |
| 5017 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5018 | |
| 5019 | // Add client classes (if any) |
| 5020 | for (auto const& class_name : scenario.classes_) { |
| 5021 | if (class_name == "BOOTP") { |
| 5022 | ctx.query_->addClass(class_name); |
| 5023 | } else { |
| 5024 | string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX); |
| 5025 | subclass += class_name; |
| 5026 | subclass += "_value"; |
| 5027 | ctx.query_->addSubClass(class_name, subclass); |
| 5028 | } |
| 5029 | } |
| 5030 | |
| 5031 | // Add client option (if one) |
| 5032 | if (scenario.requested_lft_) { |
| 5033 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
| 5034 | scenario.requested_lft_)); |
| 5035 | ctx.query_->addOption(opt); |
| 5036 | } |
| 5037 | |
| 5038 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 5039 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5039, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5040 | 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" , 5040, gtest_ar.failure_message()) = ::testing::Message(); |
| 5041 | } |
| 5042 | } |
| 5043 | } |
| 5044 | |
| 5045 | // Verifies that AllocEngine::getMinValidLft(ctx4, valid) sets the appropriate |
| 5046 | // lifetime value based on the context content. |
| 5047 | 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", 5047 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5047), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5047), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getMinValidLft4_Test >); void AllocEngine4Test_getMinValidLft4_Test::TestBody() { |
| 5048 | AllocEngine engine(0); |
| 5049 | |
| 5050 | // Let's make three classes, two with valid-lifetime and one without, |
| 5051 | // and add them to the dictionary. |
| 5052 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 5053 | ExpressionPtr match_expr; |
| 5054 | ExpressionParser parser; |
| 5055 | |
| 5056 | ElementPtr test_cfg = Element::create("'valid_one_value'"); |
| 5057 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5058 | |
| 5059 | ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr)); |
| 5060 | Triplet<uint32_t> valid_one(50, 100, 150); |
| 5061 | class_def->setValid(valid_one); |
| 5062 | dictionary->addClass(class_def); |
| 5063 | |
| 5064 | test_cfg = Element::create("'valid_two_value'"); |
| 5065 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5066 | |
| 5067 | class_def.reset(new TemplateClientClassDef("valid_two", match_expr)); |
| 5068 | Triplet<uint32_t>valid_two(200, 250, 300); |
| 5069 | class_def->setValid(valid_two); |
| 5070 | dictionary->addClass(class_def); |
| 5071 | |
| 5072 | test_cfg = Element::create("'valid_unspec_value'"); |
| 5073 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
| 5074 | |
| 5075 | class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr)); |
| 5076 | dictionary->addClass(class_def); |
| 5077 | |
| 5078 | // Commit our class changes. |
| 5079 | CfgMgr::instance().commit(); |
| 5080 | |
| 5081 | // Update the subnet's triplet to something more useful. |
| 5082 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
| 5083 | |
| 5084 | // Describes a test scenario. |
| 5085 | struct Scenario { |
| 5086 | std::string desc_; // descriptive text for logging |
| 5087 | std::vector<std::string> classes_; // class list of assigned classes |
| 5088 | uint32_t requested_lft_; // use as option 51 is > 0 |
| 5089 | uint32_t remaining_lft_; // remaining lifime or 0 |
| 5090 | uint32_t exp_valid_; // expected lifetime |
| 5091 | }; |
| 5092 | |
| 5093 | // Scenarios to test. |
| 5094 | std::vector<Scenario> scenarios = { |
| 5095 | { |
| 5096 | "BOOTP", |
| 5097 | { "BOOTP" }, |
| 5098 | 0, |
| 5099 | 0, |
| 5100 | Lease::INFINITY_LFT |
| 5101 | }, |
| 5102 | { |
| 5103 | "no classes, no option, remain 0", |
| 5104 | {}, |
| 5105 | 0, |
| 5106 | 0, |
| 5107 | subnet_->getValid().getMin() |
| 5108 | }, |
| 5109 | { |
| 5110 | "no classes, no option, remain too small", |
| 5111 | {}, |
| 5112 | 0, |
| 5113 | 100, |
| 5114 | subnet_->getValid().getMin() |
| 5115 | }, |
| 5116 | { |
| 5117 | "no classes, no option, remain", |
| 5118 | {}, |
| 5119 | 0, |
| 5120 | 800, |
| 5121 | 800 |
| 5122 | }, |
| 5123 | { |
| 5124 | "no classes, option, remain 0", |
| 5125 | {}, |
| 5126 | 1000, |
| 5127 | 0, |
| 5128 | subnet_->getValid().getMin() |
| 5129 | }, |
| 5130 | { |
| 5131 | "class unspecified, no option, remain 0", |
| 5132 | { "valid_unspec" }, |
| 5133 | 0, |
| 5134 | 0, |
| 5135 | subnet_->getValid().getMin() |
| 5136 | }, |
| 5137 | { |
| 5138 | "from last class, no option, remain 0", |
| 5139 | { "valid_unspec", "valid_one" }, |
| 5140 | 0, |
| 5141 | 0, |
| 5142 | valid_one.getMin() |
| 5143 | }, |
| 5144 | { |
| 5145 | "from first class, no option, remain 0", |
| 5146 | { "valid_two", "valid_one" }, |
| 5147 | 0, |
| 5148 | 0, |
| 5149 | valid_two.getMin() |
| 5150 | }, |
| 5151 | { |
| 5152 | "class plus remain too small", |
| 5153 | { "valid_one" }, |
| 5154 | 0, |
| 5155 | 10, |
| 5156 | valid_one.getMin(), |
| 5157 | }, |
| 5158 | { |
| 5159 | "class plus remain", |
| 5160 | { "valid_one" }, |
| 5161 | 0, |
| 5162 | 100, |
| 5163 | 100 |
| 5164 | } |
| 5165 | }; |
| 5166 | |
| 5167 | // Iterate over the scenarios and verify the correct outcome. |
| 5168 | for (auto const& scenario : scenarios) { |
| 5169 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5169( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5169, (scenario.desc_)); { |
| 5170 | // Create a context; |
| 5171 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 5172 | IOAddress("0.0.0.0"), false, false, |
| 5173 | "", false); |
| 5174 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5175 | |
| 5176 | // Add client classes (if any) |
| 5177 | for (auto const& class_name : scenario.classes_) { |
| 5178 | if (class_name == "BOOTP") { |
| 5179 | ctx.query_->addClass(class_name); |
| 5180 | } else { |
| 5181 | string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX); |
| 5182 | subclass += class_name; |
| 5183 | subclass += "_value"; |
| 5184 | ctx.query_->addSubClass(class_name, subclass); |
| 5185 | } |
| 5186 | } |
| 5187 | |
| 5188 | // Add client option (if one) |
| 5189 | if (scenario.requested_lft_) { |
| 5190 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
| 5191 | scenario.requested_lft_)); |
| 5192 | ctx.query_->addOption(opt); |
| 5193 | } |
| 5194 | |
| 5195 | uint32_t valid = scenario.remaining_lft_; |
| 5196 | engine.getMinValidLft(ctx, valid); |
| 5197 | 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" , 5197, gtest_ar.failure_message()) = ::testing::Message(); |
| 5198 | } |
| 5199 | } |
| 5200 | } |
| 5201 | |
| 5202 | // Verifies that AllocEngine::getRemaining retuns the remaining lifetime value. |
| 5203 | 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", 5203 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5203), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5203), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getRemaining_Test >); void AllocEngine4Test_getRemaining_Test::TestBody() { |
| 5204 | // No Lease. |
| 5205 | uint32_t valid(1); |
| 5206 | Lease4Ptr lease; |
| 5207 | AllocEngine::getRemaining(lease, valid); |
| 5208 | EXPECT_EQ(0, valid)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "valid" , 0, valid))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5208, gtest_ar.failure_message()) = ::testing::Message(); |
| 5209 | |
| 5210 | // Unexpected state. |
| 5211 | valid = 1; |
| 5212 | uint8_t hwaddr_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 5213 | HWAddrPtr hwaddr(new HWAddr(hwaddr_data, sizeof(hwaddr_data), HTYPE_ETHER)); |
| 5214 | uint8_t clientid[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 5215 | time_t now = time(0); |
| 5216 | lease.reset(new Lease4(IOAddress("192.0.2.100"), hwaddr, clientid, |
| 5217 | sizeof(clientid), 100, now, 1)); |
| 5218 | lease->state_ = Lease::STATE_DECLINED; |
| 5219 | AllocEngine::getRemaining(lease, valid); |
| 5220 | EXPECT_EQ(0, valid)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "valid" , 0, valid))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5220, gtest_ar.failure_message()) = ::testing::Message(); |
| 5221 | |
| 5222 | // Infinite lifetime. |
| 5223 | lease->state_ = Lease::STATE_DEFAULT; |
| 5224 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
| 5225 | lease->valid_lft_ = lease->current_valid_lft_ = infinity_lft; |
| 5226 | AllocEngine::getRemaining(lease, valid); |
| 5227 | 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" , 5227, gtest_ar.failure_message()) = ::testing::Message(); |
| 5228 | |
| 5229 | // Time going backward. |
| 5230 | lease->cltt_ = lease->current_cltt_ = now + 100; |
| 5231 | lease->valid_lft_ = lease->current_valid_lft_ = 50; |
| 5232 | AllocEngine::getRemaining(lease, valid); |
| 5233 | EXPECT_EQ(0, valid)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "valid" , 0, valid))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5233, gtest_ar.failure_message()) = ::testing::Message(); |
| 5234 | |
| 5235 | // Already expired. |
| 5236 | valid = 1; |
| 5237 | lease->cltt_ = lease->current_cltt_ = now - 100; |
| 5238 | AllocEngine::getRemaining(lease, valid); |
| 5239 | EXPECT_EQ(0, valid)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "valid" , 0, valid))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5239, gtest_ar.failure_message()) = ::testing::Message(); |
| 5240 | |
| 5241 | // Valid case. |
| 5242 | now = time(0); |
| 5243 | lease->cltt_ = lease->current_cltt_ = now - 10; |
| 5244 | AllocEngine::getRemaining(lease, valid); |
| 5245 | EXPECT_NEAR(40, valid, 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::DoubleNearPredFormat("40", "valid" , "1", 40, valid, 1))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5245, gtest_ar.failure_message()) = ::testing::Message(); |
| 5246 | } |
| 5247 | |
| 5248 | // This test checks that deleteRelease handles BOOTP leases. |
| 5249 | 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", 5249 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5249), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5249), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpDelete_Test >); void AllocEngine4Test_bootpDelete_Test::TestBody() { |
| 5250 | boost::scoped_ptr<AllocEngine> engine; |
| 5251 | 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_5251 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5251 ; } } else gtest_label_testnothrow_5251 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5251, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5252 | 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" , 5252, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5253 | |
| 5254 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
| 5255 | false, true, "somehost.example.com.", false); |
| 5256 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
| 5257 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 5258 | |
| 5259 | // Make the query a BOOTP one. |
| 5260 | ctx.query_->addClass("BOOTP"); |
| 5261 | |
| 5262 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5263 | // The new lease has been allocated, so the old lease should not exist. |
| 5264 | 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" , 5264, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx.old_lease_", "true", "false") .c_str()) = ::testing::Message (); |
| 5265 | |
| 5266 | // Check that we got a lease |
| 5267 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5267, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5268 | |
| 5269 | // Check that is belongs to the right subnet and client. |
| 5270 | 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" , 5270, gtest_ar.failure_message()) = ::testing::Message(); |
| 5271 | 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" , 5271, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
| 5272 | 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" , 5272, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
| 5273 | 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" , 5273, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
| 5274 | 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" , 5274, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
| 5275 | 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" , 5275, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->hwaddr_", "false", "true") .c_str()) = ::testing ::Message(); |
| 5276 | 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" , 5276, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
| 5277 | |
| 5278 | // Check the valid lifetime is infinite. |
| 5279 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
| 5280 | 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" , 5280, gtest_ar.failure_message()) = ::testing::Message(); |
| 5281 | |
| 5282 | // Check that the lease is indeed in LeaseMgr |
| 5283 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5284 | 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" , 5284, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5285 | |
| 5286 | // Now delete it. |
| 5287 | bool deleted = false; |
| 5288 | 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_5288; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5288; } } else gtest_label_testnothrow_5288 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5288, ("Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 5289 | 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", 5289, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "deleted", "false", "true") .c_str()) = ::testing::Message( ); |
| 5290 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5291 | 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", 5291, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "true", "false") .c_str()) = ::testing::Message (); |
| 5292 | } |
| 5293 | |
| 5294 | // This test verifies that all addresses in a pool can be allocated. |
| 5295 | 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", 5295 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5295), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5295), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullPool_Test >); void AllocEngine4Test_fullPool_Test::TestBody() { |
| 5296 | boost::scoped_ptr<AllocEngine> engine; |
| 5297 | 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_5297 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5297 ; } } else gtest_label_testnothrow_5297 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5297, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5298 | 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" , 5298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5299 | |
| 5300 | // Get rid of the default subnet configuration. |
| 5301 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5302 | cfg_mgr.clear(); |
| 5303 | |
| 5304 | // Configure a larger subnet with a /24 pool. |
| 5305 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5306 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5307 | subnet_->addPool(pool_); |
| 5308 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5309 | |
| 5310 | // Set exclude-first-last to false. |
| 5311 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
| 5312 | cfg_mgr.commit(); |
| 5313 | |
| 5314 | size_t cnt = 0; |
| 5315 | vector<bool> found(256, false); |
| 5316 | while (true) { |
| 5317 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5318 | duid[6] = cnt >> 8; |
| 5319 | duid[7] = cnt & 0xff; |
| 5320 | ClientIdPtr clientid(new ClientId(duid)); |
| 5321 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5322 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5323 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5324 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5325 | IOAddress("0.0.0.0"), |
| 5326 | false, false, "foo.bar", false); |
| 5327 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5328 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5329 | |
| 5330 | if (!lease) { |
| 5331 | break; |
| 5332 | } |
| 5333 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5334 | ASSERT_EQ(4, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "addr.size()" , 4, addr.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5334, gtest_ar.failure_message()) = ::testing::Message(); |
| 5335 | EXPECT_EQ(10, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("10", "addr[0]" , 10, addr[0]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5335, gtest_ar.failure_message()) = ::testing::Message(); |
| 5336 | EXPECT_EQ(0, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "addr[1]" , 0, addr[1]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5336, gtest_ar.failure_message()) = ::testing::Message(); |
| 5337 | EXPECT_EQ(1, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "addr[2]" , 1, addr[2]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5337, gtest_ar.failure_message()) = ::testing::Message(); |
| 5338 | 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" , 5338, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5339 | found[addr[3]] = true; |
| 5340 | ++cnt; |
| 5341 | // Catch unbound loop. |
| 5342 | ASSERT_LT(cnt, 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000", cnt , 1000))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5342, gtest_ar.failure_message()) = ::testing::Message(); |
| 5343 | } |
| 5344 | EXPECT_EQ(256, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("256", "cnt" , 256, cnt))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5344, gtest_ar.failure_message()) = ::testing::Message(); |
| 5345 | 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" , 5345, gtest_ar.failure_message()) = ::testing::Message(); |
| 5346 | } |
| 5347 | |
| 5348 | // This test verifies that all addresses in a subnet can be allocated. |
| 5349 | 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", 5349 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5349), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5349), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullSubnet24_Test >); void AllocEngine4Test_fullSubnet24_Test::TestBody() { |
| 5350 | boost::scoped_ptr<AllocEngine> engine; |
| 5351 | 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_5351 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5351 ; } } else gtest_label_testnothrow_5351 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5351, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5352 | 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" , 5352, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5353 | |
| 5354 | // Get rid of the default subnet configuration. |
| 5355 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5356 | cfg_mgr.clear(); |
| 5357 | |
| 5358 | // Configure a larger subnet with a /24 pool. |
| 5359 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 5360 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
| 5361 | IOAddress("192.0.2.255"))); |
| 5362 | subnet_->addPool(pool_); |
| 5363 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5364 | |
| 5365 | // Set exclude-first-last to false. |
| 5366 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
| 5367 | cfg_mgr.commit(); |
| 5368 | |
| 5369 | size_t cnt = 0; |
| 5370 | vector<bool> found(256, false); |
| 5371 | while (true) { |
| 5372 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5373 | duid[6] = cnt >> 8; |
| 5374 | duid[7] = cnt & 0xff; |
| 5375 | ClientIdPtr clientid(new ClientId(duid)); |
| 5376 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5377 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5378 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5379 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5380 | IOAddress("0.0.0.0"), |
| 5381 | false, false, "foo.bar", false); |
| 5382 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5383 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5384 | |
| 5385 | if (!lease) { |
| 5386 | break; |
| 5387 | } |
| 5388 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5389 | ASSERT_EQ(4, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "addr.size()" , 4, addr.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5389, gtest_ar.failure_message()) = ::testing::Message(); |
| 5390 | EXPECT_EQ(192, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("192", "addr[0]" , 192, addr[0]))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5390, gtest_ar.failure_message()) = ::testing::Message(); |
| 5391 | EXPECT_EQ(0, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "addr[1]" , 0, addr[1]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5391, gtest_ar.failure_message()) = ::testing::Message(); |
| 5392 | EXPECT_EQ(2, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "addr[2]" , 2, addr[2]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5392, gtest_ar.failure_message()) = ::testing::Message(); |
| 5393 | 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" , 5393, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5394 | found[addr[3]] = true; |
| 5395 | ++cnt; |
| 5396 | // Catch unbound loop. |
| 5397 | ASSERT_LT(cnt, 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000", cnt , 1000))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5397, gtest_ar.failure_message()) = ::testing::Message(); |
| 5398 | } |
| 5399 | EXPECT_EQ(256, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("256", "cnt" , 256, cnt))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5399, gtest_ar.failure_message()) = ::testing::Message(); |
| 5400 | 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" , 5400, gtest_ar.failure_message()) = ::testing::Message(); |
| 5401 | } |
| 5402 | |
| 5403 | // This test verifies that not all addresses in a pool can be allocated when |
| 5404 | // exclude-first-last is true. |
| 5405 | 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" , 5405), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5405), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5405), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast_Test >); void AllocEngine4Test_excludeFirstLast_Test::TestBody( ) { |
| 5406 | boost::scoped_ptr<AllocEngine> engine; |
| 5407 | 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_5407 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5407 ; } } else gtest_label_testnothrow_5407 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5407, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5408 | 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" , 5408, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5409 | |
| 5410 | // Get rid of the default subnet configuration. |
| 5411 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5412 | cfg_mgr.clear(); |
| 5413 | |
| 5414 | // Configure a larger subnet with a /24 pool. |
| 5415 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5416 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5417 | subnet_->addPool(pool_); |
| 5418 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5419 | |
| 5420 | // Set exclude-first-last to true. |
| 5421 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5422 | cfg_mgr.commit(); |
| 5423 | |
| 5424 | size_t cnt = 0; |
| 5425 | vector<bool> found(256, false); |
| 5426 | while (true) { |
| 5427 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5428 | duid[6] = cnt >> 8; |
| 5429 | duid[7] = cnt & 0xff; |
| 5430 | ClientIdPtr clientid(new ClientId(duid)); |
| 5431 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5432 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5433 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5434 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5435 | IOAddress("0.0.0.0"), |
| 5436 | false, false, "foo.bar", false); |
| 5437 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5438 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5439 | |
| 5440 | if (!lease) { |
| 5441 | break; |
| 5442 | } |
| 5443 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5444 | ASSERT_EQ(4, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "addr.size()" , 4, addr.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5444, gtest_ar.failure_message()) = ::testing::Message(); |
| 5445 | EXPECT_EQ(10, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("10", "addr[0]" , 10, addr[0]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5445, gtest_ar.failure_message()) = ::testing::Message(); |
| 5446 | EXPECT_EQ(0, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "addr[1]" , 0, addr[1]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5446, gtest_ar.failure_message()) = ::testing::Message(); |
| 5447 | EXPECT_EQ(1, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "addr[2]" , 1, addr[2]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5447, gtest_ar.failure_message()) = ::testing::Message(); |
| 5448 | 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" , 5448, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5449 | found[addr[3]] = true; |
| 5450 | ++cnt; |
| 5451 | // Catch unbound loop. |
| 5452 | ASSERT_LT(cnt, 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000", cnt , 1000))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5452, gtest_ar.failure_message()) = ::testing::Message(); |
| 5453 | } |
| 5454 | EXPECT_EQ(254, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("254", "cnt" , 254, cnt))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5454, gtest_ar.failure_message()) = ::testing::Message(); |
| 5455 | vector<bool> expected(256, true); |
| 5456 | expected[0] = false; |
| 5457 | expected[255] = false; |
| 5458 | 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" , 5458, gtest_ar.failure_message()) = ::testing::Message(); |
| 5459 | } |
| 5460 | |
| 5461 | // This test verifies that not all addresses in a subnet can be allocated when |
| 5462 | // exclude-first-last is true. |
| 5463 | 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" , 5463), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5463), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5463), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast24_Test >); void AllocEngine4Test_excludeFirstLast24_Test::TestBody () { |
| 5464 | boost::scoped_ptr<AllocEngine> engine; |
| 5465 | 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_5465 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5465 ; } } else gtest_label_testnothrow_5465 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5465, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5466 | 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" , 5466, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5467 | |
| 5468 | // Get rid of the default subnet configuration. |
| 5469 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5470 | cfg_mgr.clear(); |
| 5471 | |
| 5472 | // Configure a larger subnet with a /24 pool. |
| 5473 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 5474 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
| 5475 | IOAddress("192.0.2.255"))); |
| 5476 | subnet_->addPool(pool_); |
| 5477 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5478 | |
| 5479 | // Set exclude-first-last to true. |
| 5480 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5481 | cfg_mgr.commit(); |
| 5482 | |
| 5483 | size_t cnt = 0; |
| 5484 | vector<bool> found(256, false); |
| 5485 | while (true) { |
| 5486 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5487 | duid[6] = cnt >> 8; |
| 5488 | duid[7] = cnt & 0xff; |
| 5489 | ClientIdPtr clientid(new ClientId(duid)); |
| 5490 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5491 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5492 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5493 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5494 | IOAddress("0.0.0.0"), |
| 5495 | false, false, "foo.bar", false); |
| 5496 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5497 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5498 | |
| 5499 | if (!lease) { |
| 5500 | break; |
| 5501 | } |
| 5502 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5503 | ASSERT_EQ(4, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "addr.size()" , 4, addr.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5503, gtest_ar.failure_message()) = ::testing::Message(); |
| 5504 | EXPECT_EQ(192, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("192", "addr[0]" , 192, addr[0]))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5504, gtest_ar.failure_message()) = ::testing::Message(); |
| 5505 | EXPECT_EQ(0, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "addr[1]" , 0, addr[1]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5505, gtest_ar.failure_message()) = ::testing::Message(); |
| 5506 | EXPECT_EQ(2, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "addr[2]" , 2, addr[2]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5506, gtest_ar.failure_message()) = ::testing::Message(); |
| 5507 | 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" , 5507, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5508 | found[addr[3]] = true; |
| 5509 | ++cnt; |
| 5510 | // Catch unbound loop. |
| 5511 | ASSERT_LT(cnt, 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000", cnt , 1000))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5511, gtest_ar.failure_message()) = ::testing::Message(); |
| 5512 | } |
| 5513 | EXPECT_EQ(254, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("254", "cnt" , 254, cnt))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5513, gtest_ar.failure_message()) = ::testing::Message(); |
| 5514 | vector<bool> expected(256, true); |
| 5515 | expected[0] = false; |
| 5516 | expected[255] = false; |
| 5517 | 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" , 5517, gtest_ar.failure_message()) = ::testing::Message(); |
| 5518 | } |
| 5519 | |
| 5520 | // This test verifies that all addresses in a subnet can be allocated when |
| 5521 | // exclude-first-last is true but the prefix length is greater than 24. |
| 5522 | 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", 5522 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5522), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5522), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirst25_Test >); void AllocEngine4Test_excludeFirst25_Test::TestBody() { |
| 5523 | boost::scoped_ptr<AllocEngine> engine; |
| 5524 | 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_5524 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5524 ; } } else gtest_label_testnothrow_5524 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5524, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5525 | 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" , 5525, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5526 | |
| 5527 | // Get rid of the default subnet configuration. |
| 5528 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5529 | cfg_mgr.clear(); |
| 5530 | |
| 5531 | // Configure a smaller subnet with a /25 pool. |
| 5532 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 25, 1, 2, 3, SubnetID(10)); |
| 5533 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
| 5534 | IOAddress("192.0.2.127"))); |
| 5535 | subnet_->addPool(pool_); |
| 5536 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5537 | |
| 5538 | // Set exclude-first-last to true. |
| 5539 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5540 | cfg_mgr.commit(); |
| 5541 | |
| 5542 | size_t cnt = 0; |
| 5543 | vector<bool> found(128, false); |
| 5544 | while (true) { |
| 5545 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5546 | duid[6] = cnt >> 8; |
| 5547 | duid[7] = cnt & 0xff; |
| 5548 | ClientIdPtr clientid(new ClientId(duid)); |
| 5549 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5550 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5551 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5552 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5553 | IOAddress("0.0.0.0"), |
| 5554 | false, false, "foo.bar", false); |
| 5555 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5556 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5557 | |
| 5558 | if (!lease) { |
| 5559 | break; |
| 5560 | } |
| 5561 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5562 | ASSERT_EQ(4, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "addr.size()" , 4, addr.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5562, gtest_ar.failure_message()) = ::testing::Message(); |
| 5563 | EXPECT_EQ(192, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("192", "addr[0]" , 192, addr[0]))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5563, gtest_ar.failure_message()) = ::testing::Message(); |
| 5564 | EXPECT_EQ(0, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "addr[1]" , 0, addr[1]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5564, gtest_ar.failure_message()) = ::testing::Message(); |
| 5565 | EXPECT_EQ(2, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "addr[2]" , 2, addr[2]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5565, gtest_ar.failure_message()) = ::testing::Message(); |
| 5566 | ASSERT_GT(128, addr[3])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGT("128", "addr[3]" , 128, addr[3]))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5566, gtest_ar.failure_message()) = ::testing::Message(); |
| 5567 | 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" , 5567, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3]]", "true", "false") .c_str()) = ::testing::Message (); |
| 5568 | found[addr[3]] = true; |
| 5569 | ++cnt; |
| 5570 | // Catch unbound loop. |
| 5571 | ASSERT_LT(cnt, 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000", cnt , 1000))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5571, gtest_ar.failure_message()) = ::testing::Message(); |
| 5572 | } |
| 5573 | EXPECT_EQ(128, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("128", "cnt" , 128, cnt))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5573, gtest_ar.failure_message()) = ::testing::Message(); |
| 5574 | EXPECT_EQ(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" , 5574, gtest_ar.failure_message()) = ::testing::Message(); |
| 5575 | } |
| 5576 | |
| 5577 | // This test verifies that all addresses in a subnet can be allocated when |
| 5578 | // exclude-first-last is true but the prefix length is greater than 24. |
| 5579 | 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", 5579 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5579), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5579), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeLast25_Test >); void AllocEngine4Test_excludeLast25_Test::TestBody() { |
| 5580 | boost::scoped_ptr<AllocEngine> engine; |
| 5581 | 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_5581 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5581 ; } } else gtest_label_testnothrow_5581 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5581, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5582 | 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" , 5582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5583 | |
| 5584 | // Get rid of the default subnet configuration. |
| 5585 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5586 | cfg_mgr.clear(); |
| 5587 | |
| 5588 | // Configure a smaller subnet with a /25 pool. |
| 5589 | subnet_ = Subnet4::create(IOAddress("192.0.2.128"), 25, 1, 2, 3, SubnetID(10)); |
| 5590 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.128"), |
| 5591 | IOAddress("192.0.2.255"))); |
| 5592 | subnet_->addPool(pool_); |
| 5593 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5594 | |
| 5595 | // Set exclude-first-last to true. |
| 5596 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5597 | cfg_mgr.commit(); |
| 5598 | |
| 5599 | size_t cnt = 0; |
| 5600 | vector<bool> found(128, false); |
| 5601 | while (true) { |
| 5602 | vector<uint8_t> duid = clientid_->getClientId(); |
| 5603 | duid[6] = cnt >> 8; |
| 5604 | duid[7] = cnt & 0xff; |
| 5605 | ClientIdPtr clientid(new ClientId(duid)); |
| 5606 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
| 5607 | hwaddr->hwaddr_[4] = cnt >> 8; |
| 5608 | hwaddr->hwaddr_[5] = cnt & 0xff; |
| 5609 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
| 5610 | IOAddress("0.0.0.0"), |
| 5611 | false, false, "foo.bar", false); |
| 5612 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
| 5613 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5614 | |
| 5615 | if (!lease) { |
| 5616 | break; |
| 5617 | } |
| 5618 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
| 5619 | ASSERT_EQ(4, addr.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "addr.size()" , 4, addr.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5619, gtest_ar.failure_message()) = ::testing::Message(); |
| 5620 | EXPECT_EQ(192, addr[0])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("192", "addr[0]" , 192, addr[0]))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5620, gtest_ar.failure_message()) = ::testing::Message(); |
| 5621 | EXPECT_EQ(0, addr[1])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "addr[1]" , 0, addr[1]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5621, gtest_ar.failure_message()) = ::testing::Message(); |
| 5622 | EXPECT_EQ(2, addr[2])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "addr[2]" , 2, addr[2]))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5622, gtest_ar.failure_message()) = ::testing::Message(); |
| 5623 | ASSERT_LE(128, addr[3])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperLE("128", "addr[3]" , 128, addr[3]))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5623, gtest_ar.failure_message()) = ::testing::Message(); |
| 5624 | 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" , 5624, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "found[addr[3] - 128]", "true", "false") .c_str()) = ::testing ::Message(); |
| 5625 | found[addr[3] - 128] = true; |
| 5626 | ++cnt; |
| 5627 | // Catch unbound loop. |
| 5628 | ASSERT_LT(cnt, 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperLT("cnt", "1000", cnt , 1000))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5628, gtest_ar.failure_message()) = ::testing::Message(); |
| 5629 | } |
| 5630 | EXPECT_EQ(128, cnt)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("128", "cnt" , 128, cnt))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5630, gtest_ar.failure_message()) = ::testing::Message(); |
| 5631 | 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" , 5631, gtest_ar.failure_message()) = ::testing::Message(); |
| 5632 | } |
| 5633 | |
| 5634 | // This test verifies that an excluded address can be allocated when requested |
| 5635 | // and exclude-first-last is true. |
| 5636 | 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" , 5636), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5636), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5636), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastRequested_Test >); void AllocEngine4Test_excludeFirstLastRequested_Test:: TestBody() { |
| 5637 | boost::scoped_ptr<AllocEngine> engine; |
| 5638 | 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_5638 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5638 ; } } else gtest_label_testnothrow_5638 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5638, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5639 | 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" , 5639, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5640 | |
| 5641 | // Get rid of the default subnet configuration. |
| 5642 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5643 | cfg_mgr.clear(); |
| 5644 | |
| 5645 | // Configure a larger subnet with a /24 pool. |
| 5646 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5647 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5648 | subnet_->addPool(pool_); |
| 5649 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5650 | |
| 5651 | // Set exclude-first-last to true. |
| 5652 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5653 | cfg_mgr.commit(); |
| 5654 | |
| 5655 | // Request the first address. |
| 5656 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 5657 | IOAddress("10.0.1.0"), |
| 5658 | false, false, "foo.bar", false); |
| 5659 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 5660 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5661 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5661, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5662 | 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" , 5662, gtest_ar.failure_message()) = ::testing::Message(); |
| 5663 | |
| 5664 | // Request the last address. |
| 5665 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
| 5666 | IOAddress("10.0.1.255"), |
| 5667 | false, false, "bar.foo", false); |
| 5668 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
| 5669 | lease = engine->allocateLease4(ctx2); |
| 5670 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5670, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5671 | 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" , 5671, gtest_ar.failure_message()) = ::testing::Message(); |
| 5672 | } |
| 5673 | |
| 5674 | // This test verifies that an excluded address can be allocated when reserved |
| 5675 | // and exclude-first-last is true. |
| 5676 | 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" , 5676), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5676), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5676), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastReserver_Test >); void AllocEngine4Test_excludeFirstLastReserver_Test::TestBody () { |
| 5677 | boost::scoped_ptr<AllocEngine> engine; |
| 5678 | 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_5678 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5678 ; } } else gtest_label_testnothrow_5678 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5678, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5679 | 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" , 5679, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5680 | |
| 5681 | // Get rid of the default subnet configuration. |
| 5682 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5683 | cfg_mgr.clear(); |
| 5684 | |
| 5685 | // Configure a larger subnet with a /24 pool. |
| 5686 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
| 5687 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
| 5688 | subnet_->addPool(pool_); |
| 5689 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5690 | |
| 5691 | // Set exclude-first-last to true. |
| 5692 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
| 5693 | |
| 5694 | // Add reservations. |
| 5695 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
| 5696 | Host::IDENT_HWADDR, subnet_->getID(), |
| 5697 | SUBNET_ID_UNUSED, IOAddress("10.0.1.0"))); |
| 5698 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host); |
| 5699 | HostPtr host2(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
| 5700 | Host::IDENT_HWADDR, subnet_->getID(), |
| 5701 | SUBNET_ID_UNUSED, IOAddress("10.0.1.255"))); |
| 5702 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host2); |
| 5703 | subnet_->setReservationsInSubnet(true); |
| 5704 | subnet_->setReservationsOutOfPool(false); |
| 5705 | cfg_mgr.commit(); |
| 5706 | |
| 5707 | // Request the first address. |
| 5708 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
| 5709 | IOAddress("0.0.0.0"), |
| 5710 | false, false, "foo.bar", false); |
| 5711 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
| 5712 | AllocEngine::findReservation(ctx); |
| 5713 | Lease4Ptr lease = engine->allocateLease4(ctx); |
| 5714 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5714, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5715 | 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" , 5715, gtest_ar.failure_message()) = ::testing::Message(); |
| 5716 | |
| 5717 | // Request the last address. |
| 5718 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
| 5719 | IOAddress("0.0.0.0"), |
| 5720 | false, false, "bar.foo", false); |
| 5721 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
| 5722 | AllocEngine::findReservation(ctx2); |
| 5723 | lease = engine->allocateLease4(ctx2); |
| 5724 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5724, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5725 | 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" , 5725, gtest_ar.failure_message()) = ::testing::Message(); |
| 5726 | } |
| 5727 | |
| 5728 | // Verifies that offer_lft is non-zero, that an offered lease is stored |
| 5729 | // in the lease database. |
| 5730 | 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" , 5730), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5730), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5730), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLft_Test >); void AllocEngine4Test_discoverOfferLft_Test::TestBody( ) { |
| 5731 | boost::scoped_ptr<AllocEngine> engine; |
| 5732 | 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_5732 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5732 ; } } else gtest_label_testnothrow_5732 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5732, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5733 | 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" , 5733, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5734 | |
| 5735 | IOAddress addr("192.0.2.15"); |
| 5736 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5737 | // Get rid of the default test configuration. |
| 5738 | cfg_mgr.clear(); |
| 5739 | |
| 5740 | // Create configuration similar to other tests, but with a single address pool |
| 5741 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 5742 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 5743 | subnet_->addPool(pool_); |
| 5744 | |
| 5745 | // Set subnet's offer-lifetime to a non-zero, positive value. |
| 5746 | uint32_t offer_lft = (subnet_->getValid() / 3); |
| 5747 | subnet_->setOfferLft(offer_lft); |
| 5748 | 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" , 5748, gtest_ar.failure_message()) = ::testing::Message(); |
| 5749 | |
| 5750 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5751 | |
| 5752 | // Ask for any address |
| 5753 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 5754 | IOAddress("0.0.0.0"), true, true, |
| 5755 | "one", true); |
| 5756 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5757 | |
| 5758 | // Check that we got that single lease |
| 5759 | Lease4Ptr lease = engine->allocateLease4(ctx1); |
| 5760 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5760, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5761 | 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" , 5761, gtest_ar.failure_message()) = ::testing::Message(); |
| 5762 | 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" , 5762, gtest_ar.failure_message()) = ::testing::Message(); |
| 5763 | 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" , 5763, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5764 | 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" , 5764, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5765 | |
| 5766 | // Check that the lease has been stored by LeaseMgr. |
| 5767 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5768 | 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" , 5768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5769 | 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" , 5769, gtest_ar.failure_message()) = ::testing::Message(); |
| 5770 | 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" , 5770, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5771 | 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" , 5771, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5772 | |
| 5773 | // Try to discover an address for a second client. |
| 5774 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 5775 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 5776 | |
| 5777 | // Ask for any address. |
| 5778 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, |
| 5779 | IOAddress("0.0.0.0"), true, true, |
| 5780 | "two", true); |
| 5781 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1235)); |
| 5782 | |
| 5783 | // Verify that we did not get a lease. |
| 5784 | lease = engine->allocateLease4(ctx2); |
| 5785 | 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" , 5785, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "true", "false") .c_str()) = ::testing::Message(); |
| 5786 | |
| 5787 | // Original client now does a DHCPREQUEST. Make sure we get the |
| 5788 | // previously offered lease with the proper valid lifetime. |
| 5789 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
| 5790 | IOAddress("0.0.0.0"), true, true, |
| 5791 | "one", false); |
| 5792 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1236)); |
| 5793 | |
| 5794 | lease = engine->allocateLease4(ctx3); |
| 5795 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5795, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5796 | 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" , 5796, gtest_ar.failure_message()) = ::testing::Message(); |
| 5797 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5798 | 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" , 5798, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5799 | 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" , 5799, gtest_ar.failure_message()) = ::testing::Message(); |
| 5800 | } |
| 5801 | |
| 5802 | // Verifies that when offer_lft is non-zero, that an existing lease is |
| 5803 | // whose remaining life is larger than offer_lft, is offered as is. |
| 5804 | 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" , 5804), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5804), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5804), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftUseExistingLease4_Test >); void AllocEngine4Test_discoverOfferLftUseExistingLease4_Test ::TestBody() { |
| 5805 | boost::scoped_ptr<AllocEngine> engine; |
| 5806 | 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_5806 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5806 ; } } else gtest_label_testnothrow_5806 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5806, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5807 | 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" , 5807, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5808 | |
| 5809 | IOAddress addr("192.0.2.15"); |
| 5810 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5811 | // Get rid of the default test configuration. |
| 5812 | cfg_mgr.clear(); |
| 5813 | |
| 5814 | // Create configuration similar to other tests, but with a single address pool |
| 5815 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 300, SubnetID(10)); |
| 5816 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 5817 | subnet_->addPool(pool_); |
| 5818 | |
| 5819 | // Set subnet's offer-lifetime to a non-zero, positive value. |
| 5820 | uint32_t offer_lft = 100; |
| 5821 | subnet_->setOfferLft(offer_lft); |
| 5822 | 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" , 5822, gtest_ar.failure_message()) = ::testing::Message(); |
| 5823 | |
| 5824 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5825 | |
| 5826 | time_t now = time(NULL__null) - 5; // Allocated 5 seconds ago |
| 5827 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, 300, now, |
| 5828 | subnet_->getID(), true, true, "somehost")); |
| 5829 | |
| 5830 | // Copy the lease, so as it can be compared with the old lease returned |
| 5831 | // by the allocation engine. |
| 5832 | Lease4 original_lease(*lease); |
| 5833 | |
| 5834 | // Lease was assigned 5 seconds ago, its valid lifetime is 300, its |
| 5835 | // remaining lifetime is still larger than offer_lft. |
| 5836 | 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" , 5836, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
| 5837 | ASSERT_EQ(300, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("300", "lease->valid_lft_" , 300, lease->valid_lft_))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5837, gtest_ar.failure_message()) = ::testing::Message(); |
| 5838 | 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" , 5838, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 5839 | |
| 5840 | // CASE 1: Asking for any address |
| 5841 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 5842 | IOAddress("0.0.0.0"), false, false, |
| 5843 | "", true); |
| 5844 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5845 | lease = engine->allocateLease4(ctx1); |
| 5846 | // Check that we got that single lease |
| 5847 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5847, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5848 | 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" , 5848, gtest_ar.failure_message()) = ::testing::Message(); |
| 5849 | EXPECT_EQ(300, lease->valid_lft_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("300", "lease->valid_lft_" , 300, lease->valid_lft_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5849, gtest_ar.failure_message()) = ::testing::Message(); |
| 5850 | |
| 5851 | // We are reusing the existing lease, the old instance should be |
| 5852 | // returned. The returned instance should be the same as the original |
| 5853 | // lease. |
| 5854 | 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" , 5854, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 5855 | 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" , 5855, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
| 5856 | |
| 5857 | // Check that the lease has not been modified by LeaseMgr. |
| 5858 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5859 | 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" , 5859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5860 | 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" , 5860, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *from_mgr", "false", "true") .c_str()) = ::testing::Message(); |
| 5861 | } |
| 5862 | |
| 5863 | // Verifies that when offer_lft is non-zero, that an expired lease can |
| 5864 | // be reclaimed an offered correctly. |
| 5865 | 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" , 5865), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5865), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5865), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test >); void AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test ::TestBody() { |
| 5866 | boost::scoped_ptr<AllocEngine> engine; |
| 5867 | 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_5867 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5867 ; } } else gtest_label_testnothrow_5867 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5867, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 5868 | 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" , 5868, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine", "false", "true") .c_str()) = ::testing::Message(); |
| 5869 | |
| 5870 | IOAddress addr("192.0.2.15"); |
| 5871 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
| 5872 | // Get rid of the default test configuration. |
| 5873 | cfg_mgr.clear(); |
| 5874 | |
| 5875 | // Create configuration similar to other tests, but with a single address pool |
| 5876 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
| 5877 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
| 5878 | subnet_->addPool(pool_); |
| 5879 | |
| 5880 | // Set subnet's offer-lifetime to a non-zero, positive value. |
| 5881 | uint32_t offer_lft = (subnet_->getValid() / 3); |
| 5882 | subnet_->setOfferLft(offer_lft); |
| 5883 | 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" , 5883, gtest_ar.failure_message()) = ::testing::Message(); |
| 5884 | |
| 5885 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
| 5886 | |
| 5887 | // Just a different hw/client-id for the second client |
| 5888 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
| 5889 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
| 5890 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 5891 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
| 5892 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
| 5893 | 495, now, subnet_->getID())); |
| 5894 | // Copy the lease, so as it can be compared with the old lease returned |
| 5895 | // by the allocation engine. |
| 5896 | Lease4 original_lease(*lease); |
| 5897 | |
| 5898 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
| 5899 | // is expired already |
| 5900 | 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" , 5900, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "false", "true") .c_str()) = ::testing ::Message(); |
| 5901 | 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" , 5901, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
| 5902 | |
| 5903 | // CASE 1: Asking for any address |
| 5904 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
| 5905 | IOAddress("0.0.0.0"), false, false, |
| 5906 | "", true); |
| 5907 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 5908 | lease = engine->allocateLease4(ctx1); |
| 5909 | // Check that we got that single lease |
| 5910 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5910, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5911 | 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" , 5911, gtest_ar.failure_message()) = ::testing::Message(); |
| 5912 | 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" , 5912, gtest_ar.failure_message()) = ::testing::Message(); |
| 5913 | 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" , 5913, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5914 | 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" , 5914, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5915 | |
| 5916 | // We are reusing expired lease, the old (expired) instance should be |
| 5917 | // returned. The returned instance should be the same as the original |
| 5918 | // lease. |
| 5919 | 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" , 5919, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx1.old_lease_", "false", "true") .c_str()) = ::testing:: Message(); |
| 5920 | 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" , 5920, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
| 5921 | |
| 5922 | // Check that the lease has been stored by LeaseMgr. |
| 5923 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5924 | 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" , 5924, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5925 | 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" , 5925, gtest_ar.failure_message()) = ::testing::Message(); |
| 5926 | 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" , 5926, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_fwd_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5927 | 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" , 5927, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr->fqdn_rev_", "true", "false") .c_str()) = ::testing ::Message(); |
| 5928 | |
| 5929 | // Client now does a DHCPREQUEST. Make sure we get the |
| 5930 | // previously offered lease with the proper valid lifetime. |
| 5931 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
| 5932 | IOAddress("0.0.0.0"), true, true, |
| 5933 | "one", false); |
| 5934 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1235)); |
| 5935 | |
| 5936 | lease = engine->allocateLease4(ctx2); |
| 5937 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5937, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 5938 | 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" , 5938, gtest_ar.failure_message()) = ::testing::Message(); |
| 5939 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 5940 | 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" , 5940, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 5941 | 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" , 5941, gtest_ar.failure_message()) = ::testing::Message(); |
| 5942 | } |
| 5943 | |
| 5944 | // Verifies that AllocEngine::getOfferLft(ctx4) returns the appropriate |
| 5945 | // lifetime value based on the context content. |
| 5946 | 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", 5946 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5946), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 5946), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getOfferLft4_Test >); void AllocEngine4Test_getOfferLft4_Test::TestBody() { |
| 5947 | AllocEngine engine(0); |
| 5948 | |
| 5949 | // Let's make three classes, two with offer-lifetime and one without, |
| 5950 | // and add them to the dictionary. |
| 5951 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
| 5952 | |
| 5953 | ClientClassDefPtr class_def(new ClientClassDef("offer_lft_one", ExpressionPtr())); |
| 5954 | Optional<uint32_t> offer_lft_one(100); |
| 5955 | class_def->setOfferLft(offer_lft_one); |
| 5956 | dictionary->addClass(class_def); |
| 5957 | |
| 5958 | class_def.reset(new ClientClassDef("offer_lft_two", ExpressionPtr())); |
| 5959 | Optional<uint32_t>offer_lft_two(200); |
| 5960 | class_def->setOfferLft(offer_lft_two); |
| 5961 | dictionary->addClass(class_def); |
| 5962 | |
| 5963 | class_def.reset(new ClientClassDef("offer_lft_zero", ExpressionPtr())); |
| 5964 | Optional<uint32_t>offer_lft_zero(0); |
| 5965 | class_def->setOfferLft(offer_lft_zero); |
| 5966 | dictionary->addClass(class_def); |
| 5967 | |
| 5968 | class_def.reset(new ClientClassDef("offer_lft_unspec", ExpressionPtr())); |
| 5969 | dictionary->addClass(class_def); |
| 5970 | |
| 5971 | // Commit our class changes. |
| 5972 | CfgMgr::instance().commit(); |
| 5973 | |
| 5974 | // Update the subnet's triplet to something more useful. |
| 5975 | subnet_->setOfferLft(Optional<uint32_t>(300)); |
| 5976 | |
| 5977 | // Describes a test scenario. |
| 5978 | struct Scenario { |
| 5979 | std::string desc_; // descriptive text for logging |
| 5980 | std::vector<std::string> classes_; // class list of assigned classes |
| 5981 | uint32_t exp_valid_lft_; // expected lease lifetime |
| 5982 | bool exp_allocate_; // true if lease should be allocated |
| 5983 | }; |
| 5984 | |
| 5985 | bool exp_allocate = true; |
| 5986 | |
| 5987 | // Scenarios to test. |
| 5988 | std::vector<Scenario> scenarios = { |
| 5989 | { |
| 5990 | "BOOTP", |
| 5991 | { "BOOTP" }, |
| 5992 | Lease::INFINITY_LFT, |
| 5993 | !exp_allocate, |
| 5994 | }, |
| 5995 | { |
| 5996 | "no classes", |
| 5997 | {}, |
| 5998 | subnet_->getOfferLft(), |
| 5999 | exp_allocate |
| 6000 | }, |
| 6001 | { |
| 6002 | "class unspecified", |
| 6003 | { "offer_lft_unspec" }, |
| 6004 | subnet_->getOfferLft(), |
| 6005 | exp_allocate |
| 6006 | }, |
| 6007 | { |
| 6008 | "from last class", |
| 6009 | { "offer_lft_unspec", "offer_lft_one" }, |
| 6010 | offer_lft_one.get(), |
| 6011 | exp_allocate |
| 6012 | }, |
| 6013 | { |
| 6014 | "from first class", |
| 6015 | { "offer_lft_two", "offer_lft_one" }, |
| 6016 | offer_lft_two.get(), |
| 6017 | exp_allocate |
| 6018 | }, |
| 6019 | { |
| 6020 | // Using class value of zero should override non-zero set at |
| 6021 | // subnet level, lease should have actual valid lft |
| 6022 | "zero from class", |
| 6023 | { "offer_lft_zero" }, |
| 6024 | subnet_->getValid(), |
| 6025 | !exp_allocate |
| 6026 | } |
| 6027 | }; |
| 6028 | |
| 6029 | // Iterate over the scenarios and verify the correct outcome. |
| 6030 | for (auto const& scenario : scenarios) { |
| 6031 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_6031( "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6031, (scenario.desc_)); { |
| 6032 | // Create a context; |
| 6033 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
| 6034 | IOAddress("0.0.0.0"), false, false, |
| 6035 | "", true); |
| 6036 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
| 6037 | |
| 6038 | // Add client classes (if any) |
| 6039 | for (auto const& class_name : scenario.classes_) { |
| 6040 | ctx.query_->addClass(class_name); |
| 6041 | } |
| 6042 | |
| 6043 | Lease4Ptr lease = engine.allocateLease4(ctx); |
| 6044 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc" , 6044, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease", "false", "true") .c_str()) = ::testing::Message(); |
| 6045 | 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" , 6045, gtest_ar.failure_message()) = ::testing::Message(); |
| 6046 | |
| 6047 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
| 6048 | if (!scenario.exp_allocate_) { |
| 6049 | 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" , 6049, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "true", "false") .c_str()) = ::testing::Message (); |
| 6050 | } else { |
| 6051 | 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" , 6051, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "from_mgr", "false", "true") .c_str()) = ::testing::Message (); |
| 6052 | 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" , 6052, gtest_ar.failure_message()) = ::testing::Message(); |
| 6053 | 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" , 6053, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(from_mgr)", "false" , "true") .c_str()) = ::testing::Message(); |
| 6054 | } |
| 6055 | } |
| 6056 | } |
| 6057 | } |
| 6058 | |
| 6059 | } // namespace test |
| 6060 | } // namespace dhcp |
| 6061 | } // namespace isc |