File: | home/fedora/workspace/kea-dev/clang-static-analyzer/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc |
Warning: | line 4010, column 5 Value stored to 'ret' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | // Copyright (C) 2015-2024 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_constructor_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "constructor", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 38), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 38), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("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, "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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_simpleAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "simpleAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 56), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 56), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("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, "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, "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, 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, "alloc_engine4_unittest.cc" , 62, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
63 | |
64 | // Get the cumulative count of assigned addresses. |
65 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
66 | subnet_->getID()); |
67 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
68 | |
69 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
70 | false, true, "somehost.example.com.", false); |
71 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
72 | |
73 | Lease4Ptr lease = engine->allocateLease4(ctx); |
74 | // The new lease has been allocated, so the old lease should not exist. |
75 | 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, "alloc_engine4_unittest.cc", 75, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
76 | |
77 | // Check that we got a lease |
78 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 78, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
79 | |
80 | // Do all checks on the lease |
81 | checkLease4(lease); |
82 | |
83 | // Check that the lease is indeed in LeaseMgr |
84 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
85 | 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, "alloc_engine4_unittest.cc", 85, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
86 | |
87 | // Now check that the lease in LeaseMgr has the same parameters |
88 | detailCompareLease(lease, from_mgr); |
89 | |
90 | // Assigned addresses should have incremented. |
91 | 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, "alloc_engine4_unittest.cc" , 91, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
92 | cumulative += 1; |
93 | 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, "alloc_engine4_unittest.cc" , 94, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
94 | 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, "alloc_engine4_unittest.cc" , 94, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
95 | glbl_cumulative += 1; |
96 | 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, "alloc_engine4_unittest.cc" , 96, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
97 | |
98 | // Second allocation starts here. |
99 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
100 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
101 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, IOAddress("0.0.0.0"), |
102 | false, true, "anotherhost.example.com.", |
103 | false); |
104 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
105 | |
106 | // Set the next step to non-default value to verify that it doesn't |
107 | // affect the allocation. |
108 | ctx2.callout_handle_ = HooksManager::createCalloutHandle(); |
109 | ctx2.callout_handle_->setStatus(CalloutHandle::NEXT_STEP_SKIP); |
110 | |
111 | // Set the last allocated to the beginning of the pool. The allocation |
112 | // engine should detect that the first address is already allocated and |
113 | // assign the first available one. |
114 | auto allocation_state = boost::dynamic_pointer_cast<PoolIterativeAllocationState>(pool_->getAllocationState()); |
115 | allocation_state->resetLastAllocated(); |
116 | |
117 | lease = engine->allocateLease4(ctx2); |
118 | |
119 | // The new lease has been allocated, so the old lease should not exist. |
120 | 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, "alloc_engine4_unittest.cc", 120, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
121 | |
122 | // Check that we got a lease |
123 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 123, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
124 | |
125 | // Check that the lease is indeed in LeaseMgr |
126 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
127 | 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, "alloc_engine4_unittest.cc", 127, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
128 | |
129 | // Now check that the lease in LeaseMgr has the same parameters |
130 | detailCompareLease(lease, from_mgr); |
131 | |
132 | // Assigned addresses should have incremented. |
133 | 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, "alloc_engine4_unittest.cc" , 133, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 2, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
134 | cumulative += 1; |
135 | 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, "alloc_engine4_unittest.cc" , 136, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
136 | 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, "alloc_engine4_unittest.cc" , 136, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
137 | glbl_cumulative += 1; |
138 | 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, "alloc_engine4_unittest.cc" , 138, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
139 | } |
140 | |
141 | // This test checks that simple allocation uses the default valid lifetime. |
142 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_defaultAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "defaultAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 142), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 142), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 142 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultAlloc4_Test >); void AllocEngine4Test_defaultAlloc4_Test::TestBody() { |
143 | boost::scoped_ptr<AllocEngine> engine; |
144 | 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_144 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_144 ; } } else gtest_label_testnothrow_144 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 144, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
145 | 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, "alloc_engine4_unittest.cc", 145, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
146 | |
147 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
148 | false, true, "somehost.example.com.", false); |
149 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
150 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
151 | |
152 | Lease4Ptr lease = engine->allocateLease4(ctx); |
153 | // The new lease has been allocated, so the old lease should not exist. |
154 | 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, "alloc_engine4_unittest.cc", 154, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
155 | |
156 | // Check that we got a lease |
157 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 157, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
158 | |
159 | // Do all checks on the lease |
160 | checkLease4(lease); |
161 | |
162 | // Check the valid lifetime has the default. |
163 | 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, "alloc_engine4_unittest.cc", 163, gtest_ar .failure_message()) = ::testing::Message(); |
164 | |
165 | // Check that the lease is indeed in LeaseMgr |
166 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
167 | 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, "alloc_engine4_unittest.cc", 167, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
168 | |
169 | // Now check that the lease in LeaseMgr has the same parameters |
170 | detailCompareLease(lease, from_mgr); |
171 | } |
172 | |
173 | // This test checks that simple allocation uses the specified valid lifetime. |
174 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_hintAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "hintAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 174), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 174), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 174 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintAlloc4_Test >); void AllocEngine4Test_hintAlloc4_Test::TestBody() { |
175 | boost::scoped_ptr<AllocEngine> engine; |
176 | 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_176 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_176 ; } } else gtest_label_testnothrow_176 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 176, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
177 | 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, "alloc_engine4_unittest.cc", 177, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
178 | |
179 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
180 | false, true, "somehost.example.com.", false); |
181 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
182 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
183 | |
184 | // Specify the valid lifetime we want. |
185 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); |
186 | ctx.query_->addOption(opt); |
187 | |
188 | Lease4Ptr lease = engine->allocateLease4(ctx); |
189 | // The new lease has been allocated, so the old lease should not exist. |
190 | 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, "alloc_engine4_unittest.cc", 190, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
191 | |
192 | // Check that we got a lease |
193 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 193, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
194 | |
195 | // Do all checks on the lease |
196 | checkLease4(lease); |
197 | |
198 | // Check the valid lifetime has the wanted value. |
199 | 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, "alloc_engine4_unittest.cc", 199, gtest_ar .failure_message()) = ::testing::Message(); |
200 | |
201 | // Check that the lease is indeed in LeaseMgr |
202 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
203 | 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, "alloc_engine4_unittest.cc", 203, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
204 | |
205 | // Now check that the lease in LeaseMgr has the same parameters |
206 | detailCompareLease(lease, from_mgr); |
207 | } |
208 | |
209 | // This test checks that simple allocation uses the min valid lifetime. |
210 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_minAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "minAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 210), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 210), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 210 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minAlloc4_Test >); void AllocEngine4Test_minAlloc4_Test::TestBody() { |
211 | boost::scoped_ptr<AllocEngine> engine; |
212 | 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_212 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_212 ; } } else gtest_label_testnothrow_212 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 212, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
213 | 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, "alloc_engine4_unittest.cc", 213, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
214 | |
215 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
216 | false, true, "somehost.example.com.", false); |
217 | subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); |
218 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
219 | |
220 | // Specify the valid lifetime we want, as it is lower than the min value |
221 | // we'll get this min value instead. |
222 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); |
223 | ctx.query_->addOption(opt); |
224 | |
225 | Lease4Ptr lease = engine->allocateLease4(ctx); |
226 | // The new lease has been allocated, so the old lease should not exist. |
227 | 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, "alloc_engine4_unittest.cc", 227, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
228 | |
229 | // Check that we got a lease |
230 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 230, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
231 | |
232 | // Do all checks on the lease |
233 | checkLease4(lease); |
234 | |
235 | // Check the valid lifetime has the wanted value. |
236 | 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, "alloc_engine4_unittest.cc" , 236, gtest_ar.failure_message()) = ::testing::Message(); |
237 | |
238 | // Check that the lease is indeed in LeaseMgr |
239 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
240 | 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, "alloc_engine4_unittest.cc", 240, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
241 | |
242 | // Now check that the lease in LeaseMgr has the same parameters |
243 | detailCompareLease(lease, from_mgr); |
244 | } |
245 | |
246 | // This test checks that simple allocation uses the max valid lifetime. |
247 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_maxAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "maxAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 247), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 247), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 247 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxAlloc4_Test >); void AllocEngine4Test_maxAlloc4_Test::TestBody() { |
248 | boost::scoped_ptr<AllocEngine> engine; |
249 | 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_249 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_249 ; } } else gtest_label_testnothrow_249 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 249, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
250 | 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, "alloc_engine4_unittest.cc", 250, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
251 | |
252 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
253 | false, true, "somehost.example.com.", false); |
254 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
255 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
256 | |
257 | // Specify the valid lifetime we want, as it is greater than the max value |
258 | // we'll get this max value instead. |
259 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); |
260 | ctx.query_->addOption(opt); |
261 | |
262 | Lease4Ptr lease = engine->allocateLease4(ctx); |
263 | // The new lease has been allocated, so the old lease should not exist. |
264 | 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, "alloc_engine4_unittest.cc", 264, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
265 | |
266 | // Check that we got a lease |
267 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 267, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
268 | |
269 | // Do all checks on the lease |
270 | checkLease4(lease); |
271 | |
272 | // Check the valid lifetime has the wanted value. |
273 | 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, "alloc_engine4_unittest.cc" , 273, gtest_ar.failure_message()) = ::testing::Message(); |
274 | |
275 | // Check that the lease is indeed in LeaseMgr |
276 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
277 | 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, "alloc_engine4_unittest.cc", 277, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
278 | |
279 | // Now check that the lease in LeaseMgr has the same parameters |
280 | detailCompareLease(lease, from_mgr); |
281 | } |
282 | |
283 | // This test checks that simple allocation handles BOOTP queries. |
284 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_bootpAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bootpAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 284), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 284), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 284 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpAlloc4_Test >); void AllocEngine4Test_bootpAlloc4_Test::TestBody() { |
285 | boost::scoped_ptr<AllocEngine> engine; |
286 | 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_286 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_286 ; } } else gtest_label_testnothrow_286 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 286, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
287 | 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, "alloc_engine4_unittest.cc", 287, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
288 | |
289 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
290 | false, true, "somehost.example.com.", false); |
291 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
292 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
293 | |
294 | // Make the query a BOOTP one. |
295 | ctx.query_->addClass("BOOTP"); |
296 | |
297 | Lease4Ptr lease = engine->allocateLease4(ctx); |
298 | // The new lease has been allocated, so the old lease should not exist. |
299 | 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, "alloc_engine4_unittest.cc", 299, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
300 | |
301 | // Check that we got a lease |
302 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 302, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
303 | |
304 | // Check that is belongs to the right subnet and client. |
305 | 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, "alloc_engine4_unittest.cc", 305, gtest_ar .failure_message()) = ::testing::Message(); |
306 | 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, "alloc_engine4_unittest.cc" , 306, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
307 | 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, "alloc_engine4_unittest.cc" , 307, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
308 | 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, "alloc_engine4_unittest.cc", 308 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
309 | 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, "alloc_engine4_unittest.cc" , 309, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
310 | 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, "alloc_engine4_unittest.cc", 310, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
311 | 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, "alloc_engine4_unittest.cc" , 311, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
312 | |
313 | // Check the valid lifetime is infinite. |
314 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
315 | 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, "alloc_engine4_unittest.cc", 315, gtest_ar .failure_message()) = ::testing::Message(); |
316 | |
317 | // Check that the lease is indeed in LeaseMgr |
318 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
319 | 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, "alloc_engine4_unittest.cc", 319, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
320 | |
321 | // Now check that the lease in LeaseMgr has the same parameters |
322 | detailCompareLease(lease, from_mgr); |
323 | } |
324 | |
325 | // This test checks if the fake allocation (for DHCPDISCOVER) can succeed |
326 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_fakeAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fakeAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 326), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 326), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 326 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4_Test >); void AllocEngine4Test_fakeAlloc4_Test::TestBody() { |
327 | boost::scoped_ptr<AllocEngine> engine; |
328 | 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_328 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_328 ; } } else gtest_label_testnothrow_328 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 328, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
329 | 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, "alloc_engine4_unittest.cc", 329, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
330 | |
331 | // Assigned addresses should be zero. |
332 | 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, "alloc_engine4_unittest.cc" , 332, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
333 | |
334 | // Get the cumulative count of assigned addresses. |
335 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
336 | subnet_->getID()); |
337 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
338 | |
339 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
340 | IOAddress("0.0.0.0"), false, true, |
341 | "host.example.com.", true); |
342 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
343 | |
344 | Lease4Ptr lease = engine->allocateLease4(ctx); |
345 | |
346 | // The new lease has been allocated, so the old lease should not exist. |
347 | 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, "alloc_engine4_unittest.cc", 347, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
348 | |
349 | // Check that we got a lease |
350 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 350, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
351 | |
352 | // Do all checks on the lease |
353 | checkLease4(lease); |
354 | |
355 | // Check that the lease is NOT in LeaseMgr |
356 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
357 | 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, "alloc_engine4_unittest.cc", 357, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "true" , "false") .c_str()) = ::testing::Message(); |
358 | |
359 | // Assigned addresses should still be zero. |
360 | 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, "alloc_engine4_unittest.cc" , 360, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
361 | 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, "alloc_engine4_unittest.cc" , 362, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
362 | 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, "alloc_engine4_unittest.cc" , 362, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
363 | 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, "alloc_engine4_unittest.cc" , 363, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
364 | } |
365 | |
366 | // This test checks if the allocation with a hint that is valid (in range, |
367 | // in pool and free) can succeed |
368 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_allocWithValidHint4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocWithValidHint4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 368), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 368), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 368), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocWithValidHint4_Test >); void AllocEngine4Test_allocWithValidHint4_Test::TestBody () { |
369 | boost::scoped_ptr<AllocEngine> engine; |
370 | 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_370 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_370 ; } } else gtest_label_testnothrow_370 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 370, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
371 | 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, "alloc_engine4_unittest.cc", 371, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
372 | |
373 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
374 | IOAddress("192.0.2.105"), true, true, |
375 | "host.example.com.", false); |
376 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
377 | Lease4Ptr lease = engine->allocateLease4(ctx); |
378 | |
379 | // Check that we got a lease |
380 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 380, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
381 | |
382 | // We have allocated the new lease, so the old lease should not exist. |
383 | 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, "alloc_engine4_unittest.cc", 383, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
384 | |
385 | // We should get what we asked for |
386 | 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, "alloc_engine4_unittest.cc", 386, gtest_ar .failure_message()) = ::testing::Message(); |
387 | |
388 | // Do all checks on the lease |
389 | checkLease4(lease); |
390 | |
391 | // Check that the lease is indeed in LeaseMgr |
392 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
393 | 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, "alloc_engine4_unittest.cc", 393, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
394 | |
395 | // Now check that the lease in LeaseMgr has the same parameters |
396 | detailCompareLease(lease, from_mgr); |
397 | } |
398 | |
399 | // This test checks if the allocation with a hint that is in range, |
400 | // in pool, but is currently used can succeed |
401 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_allocWithUsedHint4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocWithUsedHint4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 401), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 401), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 401), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocWithUsedHint4_Test >); void AllocEngine4Test_allocWithUsedHint4_Test::TestBody () { |
402 | boost::scoped_ptr<AllocEngine> engine; |
403 | 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_403 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_403 ; } } else gtest_label_testnothrow_403 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 403, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
404 | 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, "alloc_engine4_unittest.cc", 404, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
405 | |
406 | // Let's create a lease and put it in the LeaseMgr |
407 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
408 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
409 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
410 | time_t now = time(NULL__null); |
411 | Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2, |
412 | clientid2, sizeof(clientid2), 1, now, subnet_->getID())); |
413 | 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, "alloc_engine4_unittest.cc" , 413, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(used)", "false", "true" ) .c_str()) = ::testing::Message(); |
414 | |
415 | // Another client comes in and request an address that is in pool, but |
416 | // unfortunately it is used already. The same address must not be allocated |
417 | // twice. |
418 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
419 | IOAddress("192.0.2.106"), false, false, |
420 | "", true); |
421 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
422 | Lease4Ptr lease = engine->allocateLease4(ctx); |
423 | |
424 | // New lease has been allocated, so the old lease should not exist. |
425 | 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, "alloc_engine4_unittest.cc", 425, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
426 | |
427 | // Check that we got a lease |
428 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 428, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
429 | |
430 | // Allocated address must be different |
431 | 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, "alloc_engine4_unittest.cc", 431, gtest_ar. failure_message()) = ::testing::Message(); |
432 | |
433 | // We should NOT get what we asked for, because it is used already |
434 | 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, "alloc_engine4_unittest.cc" , 434, gtest_ar.failure_message()) = ::testing::Message(); |
435 | |
436 | // Do all checks on the lease |
437 | checkLease4(lease); |
438 | |
439 | // The lease should not be in the LeaseMgr because it was a failed allocation. |
440 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
441 | 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, "alloc_engine4_unittest.cc", 441, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "true" , "false") .c_str()) = ::testing::Message(); |
442 | } |
443 | |
444 | // This test checks if an allocation with a hint that is out of the blue |
445 | // can succeed. The invalid hint should be ignored completely. |
446 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_allocBogusHint4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocBogusHint4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 446), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 446), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 446 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocBogusHint4_Test >); void AllocEngine4Test_allocBogusHint4_Test::TestBody() { |
447 | boost::scoped_ptr<AllocEngine> engine; |
448 | 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_448 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_448 ; } } else gtest_label_testnothrow_448 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 448, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
449 | 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, "alloc_engine4_unittest.cc", 449, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
450 | |
451 | // Client would like to get a 10.1.1.1 lease, which does not belong to any |
452 | // supported lease. Allocation engine should ignore it and carry on |
453 | // with the normal allocation |
454 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
455 | IOAddress("10.1.1.1"), false, false, |
456 | "", true); |
457 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
458 | Lease4Ptr lease = engine->allocateLease4(ctx); |
459 | // Check that we got a lease |
460 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 460, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
461 | |
462 | // We have allocated a new lease, so the old lease should not exist. |
463 | 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, "alloc_engine4_unittest.cc", 463, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
464 | |
465 | // We should NOT get what we asked for, because it is used already |
466 | 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, "alloc_engine4_unittest.cc", 466, gtest_ar .failure_message()) = ::testing::Message(); |
467 | |
468 | // Do all checks on the lease |
469 | checkLease4(lease); |
470 | |
471 | // Check that the lease is not in the LeaseMgr as it is a fake allocation. |
472 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
473 | 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 , "alloc_engine4_unittest.cc", 473, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "from_mgr", "true", "false") .c_str()) = ::testing ::Message(); |
474 | } |
475 | |
476 | // This test checks that NULL values are handled properly |
477 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_allocateLease4Nulls_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocateLease4Nulls", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 477), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 477), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 477), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocateLease4Nulls_Test >); void AllocEngine4Test_allocateLease4Nulls_Test::TestBody () { |
478 | boost::scoped_ptr<AllocEngine> engine; |
479 | 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_479 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_479 ; } } else gtest_label_testnothrow_479 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 479, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
480 | 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, "alloc_engine4_unittest.cc", 480, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
481 | |
482 | // Allocations without subnet are not allowed |
483 | AllocEngine::ClientContext4 ctx1(Subnet4Ptr(), clientid_, hwaddr_, |
484 | IOAddress("0.0.0.0"), false, false, |
485 | "", false); |
486 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
487 | Lease4Ptr lease = engine->allocateLease4(ctx1); |
488 | |
489 | 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, "alloc_engine4_unittest.cc", 489, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false") .c_str()) = ::testing::Message(); |
490 | |
491 | 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 , "alloc_engine4_unittest.cc", 491, gtest_ar.failure_message( )) = ::testing::Message(); |
492 | 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, "alloc_engine4_unittest.cc", 492, gtest_ar. failure_message()) = ::testing::Message(); |
493 | 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 , "alloc_engine4_unittest.cc", 493, gtest_ar.failure_message( )) = ::testing::Message(); |
494 | 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 , "alloc_engine4_unittest.cc", 494, gtest_ar.failure_message( )) = ::testing::Message(); |
495 | 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 , "alloc_engine4_unittest.cc", 495, gtest_ar.failure_message( )) = ::testing::Message(); |
496 | |
497 | 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, "alloc_engine4_unittest.cc", 497, gtest_ar .failure_message()) = ::testing::Message(); |
498 | 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, "alloc_engine4_unittest.cc" , 498, gtest_ar.failure_message()) = ::testing::Message(); |
499 | 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, "alloc_engine4_unittest.cc", 499, gtest_ar .failure_message()) = ::testing::Message(); |
500 | 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, "alloc_engine4_unittest.cc" , 500, gtest_ar.failure_message()) = ::testing::Message(); |
501 | 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, "alloc_engine4_unittest.cc" , 501, gtest_ar.failure_message()) = ::testing::Message(); |
502 | |
503 | // Allocations without HW address are not allowed |
504 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, HWAddrPtr(), |
505 | IOAddress("0.0.0.0"), false, false, |
506 | "", false); |
507 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
508 | lease = engine->allocateLease4(ctx2); |
509 | 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, "alloc_engine4_unittest.cc", 509, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false") .c_str()) = ::testing::Message(); |
510 | 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, "alloc_engine4_unittest.cc", 510, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
511 | |
512 | 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 , "alloc_engine4_unittest.cc", 512, gtest_ar.failure_message( )) = ::testing::Message(); |
513 | 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, "alloc_engine4_unittest.cc", 513, gtest_ar. failure_message()) = ::testing::Message(); |
514 | 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 , "alloc_engine4_unittest.cc", 514, gtest_ar.failure_message( )) = ::testing::Message(); |
515 | 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 , "alloc_engine4_unittest.cc", 515, gtest_ar.failure_message( )) = ::testing::Message(); |
516 | 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 , "alloc_engine4_unittest.cc", 516, gtest_ar.failure_message( )) = ::testing::Message(); |
517 | |
518 | 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, "alloc_engine4_unittest.cc", 518, gtest_ar .failure_message()) = ::testing::Message(); |
519 | 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, "alloc_engine4_unittest.cc" , 519, gtest_ar.failure_message()) = ::testing::Message(); |
520 | 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, "alloc_engine4_unittest.cc", 520, gtest_ar .failure_message()) = ::testing::Message(); |
521 | 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, "alloc_engine4_unittest.cc" , 521, gtest_ar.failure_message()) = ::testing::Message(); |
522 | 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, "alloc_engine4_unittest.cc" , 522, gtest_ar.failure_message()) = ::testing::Message(); |
523 | |
524 | // Allocations without client-id are allowed |
525 | clientid_.reset(); |
526 | AllocEngine::ClientContext4 ctx3(subnet_, ClientIdPtr(), hwaddr_, |
527 | IOAddress("0.0.0.0"), false, false, |
528 | "", false); |
529 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
530 | lease = engine->allocateLease4(ctx3); |
531 | |
532 | // Check that we got a lease |
533 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 533, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
534 | // New lease has been allocated, so the old lease should not exist. |
535 | 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, "alloc_engine4_unittest.cc", 535, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx3.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
536 | |
537 | // Do all checks on the lease |
538 | checkLease4(lease); |
539 | |
540 | // Check that the lease is indeed in LeaseMgr |
541 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
542 | 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, "alloc_engine4_unittest.cc", 542, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
543 | |
544 | // Now check that the lease in LeaseMgr has the same parameters |
545 | detailCompareLease(lease, from_mgr); |
546 | } |
547 | |
548 | // This test checks if a returning client can renew an |
549 | // an existing lease and assigned-leases increments accordingly |
550 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_simpleRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "simpleRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 550), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 550), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 550 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleRenew4_Test >); void AllocEngine4Test_simpleRenew4_Test::TestBody() { |
551 | boost::scoped_ptr<AllocEngine> engine; |
552 | 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_552 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_552 ; } } else gtest_label_testnothrow_552 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 552, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
553 | 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, "alloc_engine4_unittest.cc", 553, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
554 | |
555 | 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, "alloc_engine4_unittest.cc" , 555, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
556 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
557 | subnet_->getID()); |
558 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
559 | |
560 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
561 | false, true, "somehost.example.com.", false); |
562 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
563 | |
564 | Lease4Ptr lease = engine->allocateLease4(ctx); |
565 | |
566 | // Check that we got a lease and it's sane |
567 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 567, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
568 | checkLease4(lease); |
569 | |
570 | // The new lease has been allocated, so the old lease should not exist. |
571 | 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, "alloc_engine4_unittest.cc", 571, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
572 | |
573 | // We should have incremented assigned-addresses |
574 | 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, "alloc_engine4_unittest.cc" , 574, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
575 | cumulative += 1; |
576 | 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, "alloc_engine4_unittest.cc" , 577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
577 | 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, "alloc_engine4_unittest.cc" , 577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
578 | glbl_cumulative += 1; |
579 | 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, "alloc_engine4_unittest.cc" , 579, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
580 | |
581 | // Do it again, this should amount to the renew of an existing lease |
582 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
583 | |
584 | // Check that we got a lease and it's sane |
585 | 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, "alloc_engine4_unittest.cc", 585, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true") .c_str()) = ::testing::Message(); |
586 | checkLease4(lease2); |
587 | |
588 | // Lease already existed, so old_lease should be set. |
589 | 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, "alloc_engine4_unittest.cc", 589, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
590 | |
591 | // Should NOT have bumped assigned-addresses |
592 | 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, "alloc_engine4_unittest.cc" , 592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
593 | 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, "alloc_engine4_unittest.cc" , 594, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
594 | 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, "alloc_engine4_unittest.cc" , 594, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
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, "alloc_engine4_unittest.cc" , 595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
596 | } |
597 | |
598 | // This test checks simple renewal uses the default valid lifetime. |
599 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_defaultRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "defaultRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 599), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 599), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 599 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultRenew4_Test >); void AllocEngine4Test_defaultRenew4_Test::TestBody() { |
600 | boost::scoped_ptr<AllocEngine> engine; |
601 | 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_601 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_601 ; } } else gtest_label_testnothrow_601 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 601, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
602 | 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, "alloc_engine4_unittest.cc", 602, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
603 | |
604 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
605 | false, true, "somehost.example.com.", false); |
606 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
607 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
608 | |
609 | Lease4Ptr lease = engine->allocateLease4(ctx); |
610 | |
611 | // Check that we got a lease and it's sane |
612 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 612, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
613 | checkLease4(lease); |
614 | |
615 | // Check the valid lifetime has the default. |
616 | 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, "alloc_engine4_unittest.cc", 616, gtest_ar .failure_message()) = ::testing::Message(); |
617 | |
618 | // The new lease has been allocated, so the old lease should not exist. |
619 | 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, "alloc_engine4_unittest.cc", 619, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
620 | |
621 | // Do it again, this should amount to the renew of an existing lease |
622 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
623 | |
624 | // Check that we got a lease and it's sane |
625 | 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, "alloc_engine4_unittest.cc", 625, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true") .c_str()) = ::testing::Message(); |
626 | checkLease4(lease2); |
627 | |
628 | // Lease already existed, so old_lease should be set. |
629 | 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, "alloc_engine4_unittest.cc", 629, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
630 | |
631 | // Check the renewed valid lifetime has the default. |
632 | 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, "alloc_engine4_unittest.cc" , 632, gtest_ar.failure_message()) = ::testing::Message(); |
633 | } |
634 | |
635 | // This test checks simple renewal uses the specified valid lifetime. |
636 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_hintRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "hintRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 636), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 636), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 636 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintRenew4_Test >); void AllocEngine4Test_hintRenew4_Test::TestBody() { |
637 | boost::scoped_ptr<AllocEngine> engine; |
638 | 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_638 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_638 ; } } else gtest_label_testnothrow_638 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 638, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
639 | 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, "alloc_engine4_unittest.cc", 639, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
640 | |
641 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
642 | false, true, "somehost.example.com.", false); |
643 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
644 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
645 | |
646 | // Specify the valid lifetime we want. |
647 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); |
648 | ctx.query_->addOption(opt); |
649 | |
650 | Lease4Ptr lease = engine->allocateLease4(ctx); |
651 | |
652 | // Check that we got a lease and it's sane |
653 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 653, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
654 | checkLease4(lease); |
655 | |
656 | // Check the valid lifetime has the wanted value. |
657 | 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, "alloc_engine4_unittest.cc", 657, gtest_ar .failure_message()) = ::testing::Message(); |
658 | |
659 | // The new lease has been allocated, so the old lease should not exist. |
660 | 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, "alloc_engine4_unittest.cc", 660, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
661 | |
662 | // Do it again, this should amount to the renew of an existing lease |
663 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
664 | |
665 | // Check that we got a lease and it's sane |
666 | 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, "alloc_engine4_unittest.cc", 666, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true") .c_str()) = ::testing::Message(); |
667 | checkLease4(lease2); |
668 | |
669 | // Lease already existed, so old_lease should be set. |
670 | 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, "alloc_engine4_unittest.cc", 670, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
671 | |
672 | // Check the renewed valid lifetime has the wanted value. |
673 | 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, "alloc_engine4_unittest.cc", 673, gtest_ar .failure_message()) = ::testing::Message(); |
674 | } |
675 | |
676 | // This test checks simple renewal uses the min valid lifetime. |
677 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_minRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "minRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 677), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 677), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 677 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minRenew4_Test >); void AllocEngine4Test_minRenew4_Test::TestBody() { |
678 | boost::scoped_ptr<AllocEngine> engine; |
679 | 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_679 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_679 ; } } else gtest_label_testnothrow_679 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 679, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
680 | 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, "alloc_engine4_unittest.cc", 680, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
681 | |
682 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
683 | false, true, "somehost.example.com.", false); |
684 | subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); |
685 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
686 | |
687 | // Specify the valid lifetime we want, as it is lower than the min value |
688 | // we'll get this min value instead. |
689 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); |
690 | ctx.query_->addOption(opt); |
691 | |
692 | Lease4Ptr lease = engine->allocateLease4(ctx); |
693 | |
694 | // Check that we got a lease and it's sane |
695 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 695, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
696 | checkLease4(lease); |
697 | |
698 | // Check the valid lifetime has the min value. |
699 | 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, "alloc_engine4_unittest.cc" , 699, gtest_ar.failure_message()) = ::testing::Message(); |
700 | |
701 | // The new lease has been allocated, so the old lease should not exist. |
702 | 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, "alloc_engine4_unittest.cc", 702, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
703 | |
704 | // Do it again, this should amount to the renew of an existing lease |
705 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
706 | |
707 | // Check that we got a lease and it's sane |
708 | 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, "alloc_engine4_unittest.cc", 708, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true") .c_str()) = ::testing::Message(); |
709 | checkLease4(lease2); |
710 | |
711 | // Lease already existed, so old_lease should be set. |
712 | 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, "alloc_engine4_unittest.cc", 712, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
713 | |
714 | // Check the renewed valid lifetime has the min value. |
715 | 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, "alloc_engine4_unittest.cc" , 715, gtest_ar.failure_message()) = ::testing::Message(); |
716 | } |
717 | |
718 | // This test checks simple renewal uses the max valid lifetime. |
719 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_maxRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "maxRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 719), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 719), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 719 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxRenew4_Test >); void AllocEngine4Test_maxRenew4_Test::TestBody() { |
720 | boost::scoped_ptr<AllocEngine> engine; |
721 | 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_721 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_721 ; } } else gtest_label_testnothrow_721 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 721, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
722 | 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, "alloc_engine4_unittest.cc", 722, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
723 | |
724 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
725 | false, true, "somehost.example.com.", false); |
726 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
727 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
728 | |
729 | // Specify the valid lifetime we want, as it is greater than the max value |
730 | // we'll get this max value instead. |
731 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); |
732 | ctx.query_->addOption(opt); |
733 | |
734 | Lease4Ptr lease = engine->allocateLease4(ctx); |
735 | |
736 | // Check that we got a lease and it's sane |
737 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 737, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
738 | checkLease4(lease); |
739 | |
740 | // Check the valid lifetime has the max value. |
741 | 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, "alloc_engine4_unittest.cc" , 741, gtest_ar.failure_message()) = ::testing::Message(); |
742 | |
743 | // The new lease has been allocated, so the old lease should not exist. |
744 | 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, "alloc_engine4_unittest.cc", 744, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
745 | |
746 | // Do it again, this should amount to the renew of an existing lease |
747 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
748 | |
749 | // Check that we got a lease and it's sane |
750 | 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, "alloc_engine4_unittest.cc", 750, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true") .c_str()) = ::testing::Message(); |
751 | checkLease4(lease2); |
752 | |
753 | // Lease already existed, so old_lease should be set. |
754 | 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, "alloc_engine4_unittest.cc", 754, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
755 | |
756 | // Check the renewed valid lifetime has the max value. |
757 | 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, "alloc_engine4_unittest.cc" , 757, gtest_ar.failure_message()) = ::testing::Message(); |
758 | } |
759 | |
760 | // This test checks simple renewal handles BOOTP queries. |
761 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_bootpRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bootpRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 761), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 761), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 761 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpRenew4_Test >); void AllocEngine4Test_bootpRenew4_Test::TestBody() { |
762 | boost::scoped_ptr<AllocEngine> engine; |
763 | 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_763 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_763 ; } } else gtest_label_testnothrow_763 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 763, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
764 | 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, "alloc_engine4_unittest.cc", 764, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
765 | |
766 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
767 | false, true, "somehost.example.com.", false); |
768 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
769 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
770 | |
771 | // Make the query a BOOTP one. |
772 | ctx.query_->addClass("BOOTP"); |
773 | |
774 | Lease4Ptr lease = engine->allocateLease4(ctx); |
775 | |
776 | // Check that we got a lease. |
777 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 777, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
778 | |
779 | // Check that is belongs to the right subnet and client. |
780 | 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, "alloc_engine4_unittest.cc", 780, gtest_ar .failure_message()) = ::testing::Message(); |
781 | 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, "alloc_engine4_unittest.cc" , 781, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
782 | 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, "alloc_engine4_unittest.cc" , 782, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
783 | 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, "alloc_engine4_unittest.cc", 783 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
784 | 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, "alloc_engine4_unittest.cc" , 784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
785 | 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, "alloc_engine4_unittest.cc", 785, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
786 | 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, "alloc_engine4_unittest.cc" , 786, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
787 | |
788 | // Check the valid lifetime is infinite. |
789 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
790 | 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, "alloc_engine4_unittest.cc", 790, gtest_ar .failure_message()) = ::testing::Message(); |
791 | |
792 | // The new lease has been allocated, so the old lease should not exist. |
793 | 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, "alloc_engine4_unittest.cc", 793, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
794 | |
795 | // Do it again, this should amount to the renew of an existing lease |
796 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
797 | |
798 | // Check that we got a lease. |
799 | 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, "alloc_engine4_unittest.cc", 799, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true") .c_str()) = ::testing::Message(); |
800 | |
801 | // Check that is belongs to the right subnet and client. |
802 | 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, "alloc_engine4_unittest.cc", 802, gtest_ar .failure_message()) = ::testing::Message(); |
803 | 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, "alloc_engine4_unittest.cc" , 803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease2->addr_)", "false", "true") . c_str()) = ::testing::Message(); |
804 | 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, "alloc_engine4_unittest.cc" , 804, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
805 | 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, "alloc_engine4_unittest.cc", 805 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
806 | 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, "alloc_engine4_unittest.cc" , 806, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
807 | 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, "alloc_engine4_unittest.cc", 807, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
808 | 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, "alloc_engine4_unittest.cc" , 808, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->hwaddr_ == *hwaddr_", "false", "true") .c_str( )) = ::testing::Message(); |
809 | |
810 | // Lease already existed, so old_lease should be set. |
811 | 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, "alloc_engine4_unittest.cc", 811, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
812 | |
813 | // Check the renewed valid lifetime has the max value. |
814 | 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, "alloc_engine4_unittest.cc", 814, gtest_ar .failure_message()) = ::testing::Message(); |
815 | } |
816 | |
817 | // This test checks if really small pools are working |
818 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_smallPool4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "smallPool4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 818), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 818), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 818 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_smallPool4_Test >); void AllocEngine4Test_smallPool4_Test::TestBody() { |
819 | boost::scoped_ptr<AllocEngine> engine; |
820 | 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_820 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_820 ; } } else gtest_label_testnothrow_820 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 820, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
821 | 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, "alloc_engine4_unittest.cc", 821, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
822 | |
823 | IOAddress addr("192.0.2.17"); |
824 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
825 | |
826 | // Get rid of the default subnet configuration. |
827 | cfg_mgr.clear(); |
828 | |
829 | // Create configuration similar to other tests, but with a single address pool |
830 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
831 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
832 | subnet_->addPool(pool_); |
833 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
834 | |
835 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
836 | IOAddress("0.0.0.0"), false, false, |
837 | "host.example.com.", false); |
838 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
839 | Lease4Ptr lease = engine->allocateLease4(ctx); |
840 | |
841 | // Check that we got that single lease |
842 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 842, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
843 | |
844 | // We have allocated new lease, so the old lease should not exist. |
845 | 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, "alloc_engine4_unittest.cc", 845, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
846 | |
847 | 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, "alloc_engine4_unittest.cc", 847, gtest_ar .failure_message()) = ::testing::Message(); |
848 | |
849 | // Do all checks on the lease |
850 | checkLease4(lease); |
851 | |
852 | // Check that the lease is indeed in LeaseMgr |
853 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
854 | 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, "alloc_engine4_unittest.cc", 854, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true") .c_str()) = ::testing::Message(); |
855 | |
856 | // Now check that the lease in LeaseMgr has the same parameters |
857 | detailCompareLease(lease, from_mgr); |
858 | } |
859 | |
860 | // This test checks if all addresses in a pool are currently used, the attempt |
861 | // to find out a new lease fails. |
862 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_outOfAddresses4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "outOfAddresses4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 862), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 862), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 862 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_outOfAddresses4_Test >); void AllocEngine4Test_outOfAddresses4_Test::TestBody() { |
863 | boost::scoped_ptr<AllocEngine> engine; |
864 | 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_864 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_864 ; } } else gtest_label_testnothrow_864 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 864, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
865 | 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, "alloc_engine4_unittest.cc", 865, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true") .c_str()) = ::testing::Message(); |
866 | |
867 | IOAddress addr("192.0.2.17"); |
868 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
869 | // Get rid of the default test configuration. |
870 | cfg_mgr.clear(); |
871 | |
872 | // Create configuration similar to other tests, but with a single address pool |
873 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
874 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
875 | subnet_->addPool(pool_); |
876 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
877 | |
878 | // Just a different hw/client-id for the second client |
879 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
880 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
881 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
882 | time_t now = time(NULL__null); |
883 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, |
884 | sizeof(clientid2), 501, now, |
885 | subnet_->getID())); |
886 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
887 | 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, "alloc_engine4_unittest.cc" , 887, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
888 | |
889 | // There is just a single address in the pool and allocated it to someone |
890 | // else, so the allocation should fail |
891 | |
892 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
893 | IOAddress("0.0.0.0"), false, false, |
894 | "host.example.com.", false); |
895 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
896 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
897 | 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, "alloc_engine4_unittest.cc", 897, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "true" , "false") .c_str()) = ::testing::Message(); |
898 | ASSERT_FALSE(ctx.old_lease_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ctx.old_lease_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 898, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
899 | |
900 | 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 , "alloc_engine4_unittest.cc", 900, gtest_ar.failure_message( )) = ::testing::Message(); |
901 | 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, "alloc_engine4_unittest.cc", 901, gtest_ar. failure_message()) = ::testing::Message(); |
902 | 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 , "alloc_engine4_unittest.cc", 902, gtest_ar.failure_message( )) = ::testing::Message(); |
903 | 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 , "alloc_engine4_unittest.cc", 903, gtest_ar.failure_message( )) = ::testing::Message(); |
904 | 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 , "alloc_engine4_unittest.cc", 904, gtest_ar.failure_message( )) = ::testing::Message(); |
905 | |
906 | 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, "alloc_engine4_unittest.cc", 906, gtest_ar .failure_message()) = ::testing::Message(); |
907 | 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, "alloc_engine4_unittest.cc" , 907, gtest_ar.failure_message()) = ::testing::Message(); |
908 | 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, "alloc_engine4_unittest.cc", 908, gtest_ar .failure_message()) = ::testing::Message(); |
909 | 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, "alloc_engine4_unittest.cc" , 909, gtest_ar.failure_message()) = ::testing::Message(); |
910 | 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, "alloc_engine4_unittest.cc" , 910, gtest_ar.failure_message()) = ::testing::Message(); |
911 | } |
912 | |
913 | /// @brief This test class is dedicated to testing shared networks |
914 | /// |
915 | /// It uses one common configuration: |
916 | /// 1 shared network with 2 subnets: |
917 | /// - 192.0.2.0/24 subnet with a small pool of single address: 192.0.2.17 |
918 | /// - 10.1.2.0/24 subnet with pool with 96 addresses. |
919 | class SharedNetworkAlloc4Test : public AllocEngine4Test { |
920 | public: |
921 | |
922 | /// @brief Initializes configuration (2 subnets, 1 shared network) |
923 | SharedNetworkAlloc4Test() : engine_(0) { |
924 | // Create two subnets, each with a single address pool. The first subnet |
925 | // has only one address in its address pool to make it easier to simulate |
926 | // address exhaustion. |
927 | subnet1_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
928 | subnet2_ = Subnet4::create(IOAddress("10.1.2.0"), 24, 1, 2, 3, SubnetID(20)); |
929 | pool1_.reset(new Pool4(IOAddress("192.0.2.17"), IOAddress("192.0.2.17"))); |
930 | pool2_.reset(new Pool4(IOAddress("10.1.2.5"), IOAddress("10.1.2.100"))); |
931 | |
932 | subnet1_->addPool(pool1_); |
933 | subnet2_->addPool(pool2_); |
934 | |
935 | // Both subnets belong to the same network so they can be used |
936 | // interchangeably. |
937 | network_.reset(new SharedNetwork4("test_network")); |
938 | network_->add(subnet1_); |
939 | network_->add(subnet2_); |
940 | |
941 | std::vector<uint8_t> hwaddr_vec = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
942 | hwaddr2_.reset(new HWAddr(hwaddr_vec, HTYPE_ETHER)); |
943 | } |
944 | |
945 | /// @brief Inserts a new lease for specified address |
946 | /// |
947 | /// Creates a new lease for specified address and subnet-id and inserts |
948 | /// it into database. This is not particularly fancy method, it is used |
949 | /// just to mark existing addresses as used. It uses hwaddr2_ to allocate |
950 | /// the lease. |
951 | /// |
952 | /// @param addr text representation of the address |
953 | /// @param subnet_id ID of the subnet |
954 | /// @param return pointer to the lease |
955 | Lease4Ptr |
956 | insertLease(std::string addr, SubnetID subnet_id) { |
957 | Lease4Ptr lease(new Lease4(IOAddress(addr), hwaddr2_, ClientIdPtr(), |
958 | 501, time(NULL__null), subnet_id)); |
959 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
960 | if (!LeaseMgrFactory::instance().addLease(lease)) { |
961 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "alloc_engine4_unittest.cc", 961, "Failed") = ::testing::Message() << "Attempt to add a lease for IP " << addr |
962 | << " in subnet " << subnet_id << " failed"; |
963 | } |
964 | |
965 | return (lease); |
966 | } |
967 | |
968 | /// Convenience pointers to configuration elements. These are initialized |
969 | /// in the constructor and are used throughout the tests. |
970 | AllocEngine engine_; |
971 | Subnet4Ptr subnet1_; |
972 | Subnet4Ptr subnet2_; |
973 | Pool4Ptr pool1_; |
974 | Pool4Ptr pool2_; |
975 | SharedNetwork4Ptr network_; |
976 | |
977 | HWAddrPtr hwaddr2_; // Note there's hwaddr_ already defined in base class. |
978 | }; |
979 | |
980 | // This test verifies that the server can offer an address from a |
981 | // subnet and the introduction of shared network doesn't break anything here. |
982 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkSimple", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 982), (:: testing::internal::GetTypeId<SharedNetworkAlloc4Test>() ), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 982), :: testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 982 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test ::TestBody() { |
983 | |
984 | // Create context which will be used to try to allocate leases from the |
985 | // shared network. The context points to subnet1, which address space |
986 | // is exhausted. We expect the allocation engine to find another subnet |
987 | // within the same shared network and offer an address from there. |
988 | AllocEngine::ClientContext4 |
989 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
990 | false, false, "host.example.com.", true); |
991 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
992 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
993 | |
994 | // The allocation engine should have assigned an address from the first |
995 | // subnet. |
996 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 996, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true") .c_str()) = ::testing::Message(); |
997 | 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, "alloc_engine4_unittest.cc", 997, gtest_ar .failure_message()) = ::testing::Message(); |
998 | |
999 | // Make sure the lease is not in the lease mgr (this is only |
1000 | // discover). |
1001 | 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, "alloc_engine4_unittest.cc" , 1001, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
1002 | } |
1003 | |
1004 | // This test verifies that the server will pick a second subnet out of two |
1005 | // shared subnets if there is a hint for the second subnet. |
1006 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkHint", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1006), (::testing ::internal::GetTypeId<SharedNetworkAlloc4Test>()), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1006), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1006), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test ::TestBody() { |
1007 | |
1008 | // Create context which will be used to try to allocate leases from the |
1009 | // shared network. The context points to subnet1, which address space |
1010 | // is exhausted. We expect the allocation engine to find another subnet |
1011 | // within the same shared network and offer an address from there. |
1012 | |
1013 | AllocEngine::ClientContext4 |
1014 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress("10.1.2.25"), |
1015 | false, false, "host.example.com.", true); |
1016 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1017 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1018 | |
1019 | // The allocation engine should have assigned an address from the second |
1020 | // subnet, because that's what the hint requested. |
1021 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1021, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1022 | 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, "alloc_engine4_unittest.cc" , 1022, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1023 | } |
1024 | |
1025 | // This test verifies that the server can offer an address from a |
1026 | // different subnet than orginally selected, when the address pool in |
1027 | // the first subnet is exhausted. |
1028 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetwork_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetwork", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1028), (::testing ::internal::GetTypeId<SharedNetworkAlloc4Test>()), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1028), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1028), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetwork_Test >); void SharedNetworkAlloc4Test_discoverSharedNetwork_Test ::TestBody() { |
1029 | // Create a lease for a single address in the first address pool. The |
1030 | // pool is now exhausted. |
1031 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
1032 | |
1033 | // Create context which will be used to try to allocate leases from the |
1034 | // shared network. The context points to subnet1, which address space |
1035 | // is exhausted. We expect the allocation engine to find another subnet |
1036 | // within the same shared network and offer an address from there. |
1037 | AllocEngine::ClientContext4 |
1038 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1039 | false, false, "host.example.com.", true); |
1040 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1041 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
1042 | // The allocation engine should have assigned an address from the second |
1043 | // subnet. We could guess that this is 10.1.2.5, being the first address |
1044 | // in the address pool, but to make the test more generic, we merely |
1045 | // verify that the address is in the given address pool. |
1046 | 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, "alloc_engine4_unittest.cc", 1046, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true") .c_str()) = ::testing::Message(); |
1047 | 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, "alloc_engine4_unittest.cc" , 1047, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1048 | |
1049 | // The client should also be offered a lease when it specifies a hint |
1050 | // that doesn't match the subnet from which the lease is offered. The |
1051 | // engine should check alternative subnets to match the hint to |
1052 | // a subnet. The requested lease is available, so it should be offered. |
1053 | ctx.subnet_ = subnet1_; |
1054 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
1055 | lease2 = engine_.allocateLease4(ctx); |
1056 | 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, "alloc_engine4_unittest.cc", 1056, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true") .c_str()) = ::testing::Message(); |
1057 | 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, "alloc_engine4_unittest.cc" , 1057, gtest_ar.failure_message()) = ::testing::Message(); |
1058 | |
1059 | // The returning client (the one that has a lease) should also be able |
1060 | // to renew its lease regardless of a subnet it begins with. So, it has |
1061 | // an address assigned from subnet1, but we use subnet2 as a selected |
1062 | // subnet. |
1063 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
1064 | IOAddress("0.0.0.0"), false, false, |
1065 | "host.example.com.", true); |
1066 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1067 | lease2 = engine_.allocateLease4(ctx2); |
1068 | // The existing lease should be returned. |
1069 | 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, "alloc_engine4_unittest.cc", 1069, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true") .c_str()) = ::testing::Message(); |
1070 | 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, "alloc_engine4_unittest.cc" , 1070, gtest_ar.failure_message()) = ::testing::Message(); |
1071 | } |
1072 | |
1073 | // This test verifies that the server can offer an address from a |
1074 | // different subnet than orginally selected, when the address pool in |
1075 | // the first subnet is exhausted. |
1076 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkClassification", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 1076 ), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1076), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1076 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test ::TestBody() { |
1077 | |
1078 | // Try to offer address from subnet1. There is one address available |
1079 | // so it should be offered. |
1080 | AllocEngine::ClientContext4 |
1081 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1082 | false, false, "host.example.com.", true); |
1083 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1084 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1085 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1085, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1086 | 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, "alloc_engine4_unittest.cc" , 1086, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1087 | |
1088 | // Apply restrictions on the subnet1. This should be only assigned |
1089 | // to clients belonging to cable-modem class. |
1090 | subnet1_->allowClientClass("cable-modem"); |
1091 | |
1092 | // The allocation engine should determine that the subnet1 is not |
1093 | // available for the client not belonging to the cable-modem class. |
1094 | // Instead, it should offer an address from subnet2 that belongs |
1095 | // to the same shared network. |
1096 | ctx.subnet_ = subnet1_; |
1097 | lease = engine_.allocateLease4(ctx); |
1098 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1098, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1099 | 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, "alloc_engine4_unittest.cc" , 1099, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1100 | |
1101 | // Create reservation for the client in subnet1. Because this subnet is |
1102 | // not allowed for the client the client should still be offered a |
1103 | // lease from subnet2. |
1104 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1105 | Host::IDENT_HWADDR, subnet1_->getID(), |
1106 | SUBNET_ID_UNUSED, IOAddress("192.0.2.17"))); |
1107 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1108 | CfgMgr::instance().commit(); |
1109 | AllocEngine::findReservation(ctx); |
1110 | |
1111 | ctx.subnet_ = subnet1_; |
1112 | lease = engine_.allocateLease4(ctx); |
1113 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1113, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1114 | 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, "alloc_engine4_unittest.cc" , 1114, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1115 | |
1116 | // Assign cable-modem class and try again. This time, we should |
1117 | // offer an address from the subnet1. |
1118 | ctx.query_->addClass(ClientClass("cable-modem")); |
1119 | |
1120 | ctx.subnet_ = subnet1_; |
1121 | lease = engine_.allocateLease4(ctx); |
1122 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1122, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1123 | 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, "alloc_engine4_unittest.cc", 1123, gtest_ar .failure_message()) = ::testing::Message(); |
1124 | } |
1125 | |
1126 | // This test verifies that the server can offer an address from a |
1127 | // different subnet than orginally selected, when the address pool in |
1128 | // the first subnet requires another class. |
1129 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkPoolClassification", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1129), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1129), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1129 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test ::TestBody() { |
1130 | |
1131 | // Try to offer address from subnet1. There is one address available |
1132 | // so it should be offered. |
1133 | AllocEngine::ClientContext4 |
1134 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1135 | false, false, "host.example.com.", true); |
1136 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1137 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1138 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1138, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1139 | 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, "alloc_engine4_unittest.cc" , 1139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1140 | |
1141 | // Apply restrictions on the pool1. This should be only assigned |
1142 | // to clients belonging to cable-modem class. |
1143 | pool1_->allowClientClass("cable-modem"); |
1144 | |
1145 | // The allocation engine should determine that the pool1 is not |
1146 | // available for the client not belonging to the cable-modem class. |
1147 | // Instead, it should offer an address from subnet2 that belongs |
1148 | // to the same shared network. |
1149 | ctx.subnet_ = subnet1_; |
1150 | lease = engine_.allocateLease4(ctx); |
1151 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1151, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1152 | 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, "alloc_engine4_unittest.cc" , 1152, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1153 | |
1154 | // Assign cable-modem class and try again. This time, we should |
1155 | // offer an address from the pool1. |
1156 | ctx.query_->addClass(ClientClass("cable-modem")); |
1157 | |
1158 | // Restrict access to pool2 for this client, to make sure that the |
1159 | // server doesn't accidentally get an address from this pool. |
1160 | pool2_->allowClientClass("telephone"); |
1161 | |
1162 | ctx.subnet_ = subnet1_; |
1163 | lease = engine_.allocateLease4(ctx); |
1164 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1164, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1165 | 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, "alloc_engine4_unittest.cc", 1165, gtest_ar .failure_message()) = ::testing::Message(); |
1166 | } |
1167 | |
1168 | // Test that global reservations within shared network take precedence over the |
1169 | // existing leases regardless in which subnet belonging to a shared network |
1170 | // reservations belong. |
1171 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkReservationsGlobal", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1171), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1171), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1171 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test ::TestBody() { |
1172 | |
1173 | 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, "alloc_engine4_unittest.cc" , 1173, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
1174 | |
1175 | // Create reservation for the client. |
1176 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1177 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
1178 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1179 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1180 | CfgMgr::instance().commit(); |
1181 | |
1182 | subnet1_->setReservationsGlobal(true); |
1183 | subnet1_->setReservationsInSubnet(true); |
1184 | subnet2_->setReservationsGlobal(true); |
1185 | subnet2_->setReservationsInSubnet(true); |
1186 | |
1187 | // Start allocation from subnet1. The engine should determine that the |
1188 | // client has global reservations within subnet2 and should rather |
1189 | // assign reserved addresses. |
1190 | AllocEngine::ClientContext4 |
1191 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1192 | false, false, "host.example.com.", true); |
1193 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1194 | AllocEngine::findReservation(ctx); |
1195 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1196 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1196, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1197 | 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, "alloc_engine4_unittest.cc", 1197, gtest_ar .failure_message()) = ::testing::Message(); |
1198 | 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, "alloc_engine4_unittest.cc" , 1198, gtest_ar.failure_message()) = ::testing::Message(); |
1199 | |
1200 | // Let's create a lease for the client to make sure the lease is not |
1201 | // renewed but a reserved lease is offered. |
1202 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1203 | 501, time(NULL__null), subnet1_->getID())); |
1204 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1205 | 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, "alloc_engine4_unittest.cc" , 1205, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
1206 | ctx.subnet_ = subnet1_; |
1207 | ctx.hosts_.clear(); |
1208 | AllocEngine::findReservation(ctx); |
1209 | lease = engine_.allocateLease4(ctx); |
1210 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1210, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1211 | 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, "alloc_engine4_unittest.cc", 1211, gtest_ar .failure_message()) = ::testing::Message(); |
1212 | 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, "alloc_engine4_unittest.cc" , 1212, gtest_ar.failure_message()) = ::testing::Message(); |
1213 | } |
1214 | |
1215 | |
1216 | // Test that reservations within shared network take precedence over the |
1217 | // existing leases regardless in which subnet belonging to a shared network |
1218 | // reservations belong. |
1219 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkReservations", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1219), ( ::testing::internal::GetTypeId<SharedNetworkAlloc4Test> ()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1219), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1219 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test ::TestBody() { |
1220 | |
1221 | 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, "alloc_engine4_unittest.cc" , 1221, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
1222 | |
1223 | // Create reservation for the client. |
1224 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1225 | Host::IDENT_HWADDR, subnet2_->getID(), |
1226 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1227 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1228 | CfgMgr::instance().commit(); |
1229 | |
1230 | // Start allocation from subnet1. The engine should determine that the |
1231 | // client has reservations in subnet2 and should rather assign reserved |
1232 | // addresses. |
1233 | AllocEngine::ClientContext4 |
1234 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1235 | false, false, "host.example.com.", true); |
1236 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1237 | AllocEngine::findReservation(ctx); |
1238 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1239 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1239, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1240 | 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, "alloc_engine4_unittest.cc", 1240, gtest_ar .failure_message()) = ::testing::Message(); |
1241 | 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, "alloc_engine4_unittest.cc" , 1241, gtest_ar.failure_message()) = ::testing::Message(); |
1242 | |
1243 | // Let's create a lease for the client in subnet1 to make sure the lease |
1244 | // is not renewed but a reserved lease is offered. |
1245 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1246 | 501, time(NULL__null), subnet1_->getID())); |
1247 | lease2->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1248 | 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, "alloc_engine4_unittest.cc" , 1248, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
1249 | ctx.subnet_ = subnet1_; |
1250 | ctx.hosts_.clear(); |
1251 | AllocEngine::findReservation(ctx); |
1252 | lease = engine_.allocateLease4(ctx); |
1253 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1253, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1254 | 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, "alloc_engine4_unittest.cc", 1254, gtest_ar .failure_message()) = ::testing::Message(); |
1255 | 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, "alloc_engine4_unittest.cc" , 1255, gtest_ar.failure_message()) = ::testing::Message(); |
1256 | |
1257 | // Let's create a lease for the client in subnet2 to make sure the lease |
1258 | // is not renewed but a reserved lease is offered. |
1259 | Lease4Ptr lease3(new Lease4(IOAddress("10.1.2.55"), hwaddr_, ClientIdPtr(), |
1260 | 501, time(NULL__null), subnet2_->getID())); |
1261 | lease3->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1262 | 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, "alloc_engine4_unittest.cc" , 1262, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease3)", "false", "true" ) .c_str()) = ::testing::Message(); |
1263 | ctx.subnet_ = subnet1_; |
1264 | ctx.hosts_.clear(); |
1265 | AllocEngine::findReservation(ctx); |
1266 | lease = engine_.allocateLease4(ctx); |
1267 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1267, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1268 | 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, "alloc_engine4_unittest.cc", 1268, gtest_ar .failure_message()) = ::testing::Message(); |
1269 | 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, "alloc_engine4_unittest.cc" , 1269, gtest_ar.failure_message()) = ::testing::Message(); |
1270 | } |
1271 | |
1272 | |
1273 | // Test that reservations within shared network take precedence over the |
1274 | // existing leases regardless in which subnet belonging to a shared network |
1275 | // reservations belong. Host lookups returning a collection are disabled. |
1276 | // As it is only an optimization the behavior (so the test) must stay |
1277 | // unchanged. |
1278 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkReservationsNoColl", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1278), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1278), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1278 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test ::TestBody() { |
1279 | |
1280 | // Disable host lookups returning a collection. |
1281 | 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, "alloc_engine4_unittest.cc" , 1281, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
1282 | HostMgr::instance().setDisableSingleQuery(true); |
1283 | |
1284 | // Create reservation for the client. |
1285 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1286 | Host::IDENT_HWADDR, subnet2_->getID(), |
1287 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1288 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1289 | CfgMgr::instance().commit(); |
1290 | |
1291 | subnet1_->setReservationsGlobal(true); |
1292 | subnet1_->setReservationsInSubnet(true); |
1293 | subnet2_->setReservationsGlobal(true); |
1294 | subnet2_->setReservationsInSubnet(true); |
1295 | |
1296 | // Start allocation from subnet1. The engine should determine that the |
1297 | // client has reservations in subnet2 and should rather assign reserved |
1298 | // addresses. |
1299 | AllocEngine::ClientContext4 |
1300 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1301 | false, false, "host.example.com.", true); |
1302 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1303 | AllocEngine::findReservation(ctx); |
1304 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1305 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1305, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1306 | 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, "alloc_engine4_unittest.cc", 1306, gtest_ar .failure_message()) = ::testing::Message(); |
1307 | 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, "alloc_engine4_unittest.cc" , 1307, gtest_ar.failure_message()) = ::testing::Message(); |
1308 | |
1309 | // Let's create a lease for the client to make sure the lease is not |
1310 | // renewed but a reserved lease is offered. |
1311 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1312 | 501, time(NULL__null), subnet1_->getID())); |
1313 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1314 | 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, "alloc_engine4_unittest.cc" , 1314, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
1315 | ctx.subnet_ = subnet1_; |
1316 | ctx.hosts_.clear(); |
1317 | AllocEngine::findReservation(ctx); |
1318 | lease = engine_.allocateLease4(ctx); |
1319 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1319, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1320 | 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, "alloc_engine4_unittest.cc", 1320, gtest_ar .failure_message()) = ::testing::Message(); |
1321 | 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, "alloc_engine4_unittest.cc" , 1321, gtest_ar.failure_message()) = ::testing::Message(); |
1322 | } |
1323 | |
1324 | // This test verifies that the server can offer an address from a shared |
1325 | // subnet if there's at least 1 address left there, but will not offer |
1326 | // anything if both subnets are completely full. |
1327 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_runningOut_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "runningOut", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 1327), (::testing::internal::GetTypeId <SharedNetworkAlloc4Test>()), ::testing::internal::SuiteApiResolver < SharedNetworkAlloc4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 1327), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1327 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_runningOut_Test >); void SharedNetworkAlloc4Test_runningOut_Test::TestBody () { |
1328 | |
1329 | // Allocate everything in subnet1 |
1330 | insertLease("192.0.2.17", subnet1_->getID()); |
1331 | |
1332 | // Allocate everything, except one address in subnet2. |
1333 | for (int i = 5; i < 100; i++) { |
1334 | stringstream tmp; |
1335 | tmp << "10.1.2." << i; |
1336 | insertLease(tmp.str(), subnet2_->getID()); |
1337 | } |
1338 | |
1339 | // Create context which will be used to try to allocate leases from the |
1340 | // shared network. The context points to subnet1, which address space |
1341 | // is exhausted. We expect the allocation engine to find another subnet |
1342 | // within the same shared network and offer an address from there. |
1343 | AllocEngine::ClientContext4 |
1344 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1345 | false, false, "host.example.com.", true); |
1346 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1347 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1348 | EXPECT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "alloc_engine4_unittest.cc", 1348, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing:: Message(); |
1349 | |
1350 | // Now allocate the last address. Now both subnets are exhausted. |
1351 | insertLease("10.1.2.100", subnet2_->getID()); |
1352 | |
1353 | // Ok, we're out. We should not get anything now. |
1354 | lease = engine_.allocateLease4(ctx); |
1355 | 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, "alloc_engine4_unittest.cc", 1355, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false") .c_str()) = ::testing::Message(); |
1356 | |
1357 | 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 , "alloc_engine4_unittest.cc", 1357, gtest_ar.failure_message ()) = ::testing::Message(); |
1358 | 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, "alloc_engine4_unittest.cc", 1358, gtest_ar .failure_message()) = ::testing::Message(); |
1359 | 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 , "alloc_engine4_unittest.cc", 1359, gtest_ar.failure_message ()) = ::testing::Message(); |
1360 | 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 , "alloc_engine4_unittest.cc", 1360, gtest_ar.failure_message ()) = ::testing::Message(); |
1361 | 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 , "alloc_engine4_unittest.cc", 1361, gtest_ar.failure_message ()) = ::testing::Message(); |
1362 | |
1363 | 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, "alloc_engine4_unittest.cc", 1363, gtest_ar .failure_message()) = ::testing::Message(); |
1364 | 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, "alloc_engine4_unittest.cc" , 1364, gtest_ar.failure_message()) = ::testing::Message(); |
1365 | 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, "alloc_engine4_unittest.cc" , 1365, gtest_ar.failure_message()) = ::testing::Message(); |
1366 | 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, "alloc_engine4_unittest.cc" , 1366, gtest_ar.failure_message()) = ::testing::Message(); |
1367 | 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, "alloc_engine4_unittest.cc" , 1367, gtest_ar.failure_message()) = ::testing::Message(); |
1368 | } |
1369 | |
1370 | // This test verifies that the server can offer an address from a |
1371 | // subnet and the introduction of shared network doesn't break anything here. |
1372 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkSimple", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1372), (:: testing::internal::GetTypeId<SharedNetworkAlloc4Test>() ), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1372), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1372 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test ::TestBody() { |
1373 | |
1374 | // Create context which will be used to try to allocate leases from the |
1375 | // shared network. The context points to subnet1, which address space |
1376 | // is exhausted. We expect the allocation engine to find another subnet |
1377 | // within the same shared network and offer an address from there. |
1378 | AllocEngine::ClientContext4 |
1379 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1380 | false, false, "host.example.com.", false); |
1381 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1382 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1383 | |
1384 | // The allocation engine should have assigned an address from the first |
1385 | // subnet. |
1386 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1386, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1387 | 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, "alloc_engine4_unittest.cc", 1387, gtest_ar .failure_message()) = ::testing::Message(); |
1388 | |
1389 | // Make sure the lease is in the lease mgr. |
1390 | 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, "alloc_engine4_unittest.cc" , 1390, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1391 | } |
1392 | |
1393 | // This test verifies that the server can allocate an address from a |
1394 | // different subnet than orginally selected, when the address pool in |
1395 | // the first subnet is exhausted. |
1396 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetwork_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetwork", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1396), (::testing ::internal::GetTypeId<SharedNetworkAlloc4Test>()), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1396), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1396), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetwork_Test >); void SharedNetworkAlloc4Test_requestSharedNetwork_Test ::TestBody() { |
1397 | |
1398 | // Create a lease for a single address in the first address pool. The |
1399 | // pool is now exhausted. |
1400 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
1401 | |
1402 | // Create context which will be used to try to allocate leases from the |
1403 | // shared network. The context points to subnet1, which address space |
1404 | // is exhausted. We expect the allocation engine to find another subnet |
1405 | // within the same shared network and offer an address from there. |
1406 | AllocEngine::ClientContext4 |
1407 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1408 | false, false, "host.example.com.", false); |
1409 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1410 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
1411 | // The allocation engine should have assigned an address from the second |
1412 | // subnet. We could guess that this is 10.1.2.5, being the first address |
1413 | // in the address pool, but to make the test more generic, we merely |
1414 | // verify that the address is in the given address pool. |
1415 | 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, "alloc_engine4_unittest.cc", 1415, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true") .c_str()) = ::testing::Message(); |
1416 | 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, "alloc_engine4_unittest.cc" , 1416, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1417 | |
1418 | 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, "alloc_engine4_unittest.cc" , 1418, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease2)", "false", "true") .c_str()) = ::testing::Message(); |
1419 | |
1420 | // The client should also be assigned a lease when it specifies a hint |
1421 | // that doesn't match the subnet from which the lease is offered. The |
1422 | // engine should check alternative subnets to match the hint to |
1423 | // a subnet. The requested lease is available, so it should be offered. |
1424 | ctx.subnet_ = subnet1_; |
1425 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
1426 | lease2 = engine_.allocateLease4(ctx); |
1427 | 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, "alloc_engine4_unittest.cc", 1427, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true") .c_str()) = ::testing::Message(); |
1428 | 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, "alloc_engine4_unittest.cc" , 1428, gtest_ar.failure_message()) = ::testing::Message(); |
1429 | |
1430 | // The returning client (the one that has a lease) should also be able |
1431 | // to renew its lease regardless of a subnet it begins with. So, it has |
1432 | // an address assigned from subnet1, but we use subnet2 as a selected |
1433 | // subnet. |
1434 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
1435 | IOAddress("0.0.0.0"), false, false, |
1436 | "host.example.com.", false); |
1437 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1438 | lease2 = engine_.allocateLease4(ctx2); |
1439 | // The existing lease should be returned. |
1440 | 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, "alloc_engine4_unittest.cc", 1440, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true") .c_str()) = ::testing::Message(); |
1441 | 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, "alloc_engine4_unittest.cc" , 1441, gtest_ar.failure_message()) = ::testing::Message(); |
1442 | } |
1443 | |
1444 | // This test verifies that the server can assign an address from a |
1445 | // different subnet than orginally selected, when the address pool in |
1446 | // the first subnet is exhausted. |
1447 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkClassification", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1447), ( ::testing::internal::GetTypeId<SharedNetworkAlloc4Test> ()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1447), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1447 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test ::TestBody() { |
1448 | // Try to offer address from subnet1. There is one address available |
1449 | // so it should be offered. |
1450 | AllocEngine::ClientContext4 |
1451 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1452 | false, false, "host.example.com.", false); |
1453 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1454 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1455 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1455, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1456 | 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, "alloc_engine4_unittest.cc" , 1456, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1457 | |
1458 | // Remove the lease so as we can start over. |
1459 | 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, "alloc_engine4_unittest.cc" , 1459, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1460 | |
1461 | // Apply restrictions on the subnet1. This should be only assigned |
1462 | // to clients belonging to cable-modem class. |
1463 | subnet1_->allowClientClass("cable-modem"); |
1464 | |
1465 | // The allocation engine should determine that the subnet1 is not |
1466 | // available for the client not belonging to the cable-modem class. |
1467 | // Instead, it should assign an address from subnet2 that belongs |
1468 | // to the same shared network. |
1469 | ctx.subnet_ = subnet1_; |
1470 | lease = engine_.allocateLease4(ctx); |
1471 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1471, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1472 | 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, "alloc_engine4_unittest.cc" , 1472, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1473 | |
1474 | // Remove the lease so as we can start over. |
1475 | 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, "alloc_engine4_unittest.cc" , 1475, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1476 | |
1477 | // Assign cable-modem class and try again. This time, we should |
1478 | // offer an address from the subnet1. |
1479 | ctx.query_->addClass(ClientClass("cable-modem")); |
1480 | |
1481 | ctx.subnet_ = subnet1_; |
1482 | lease = engine_.allocateLease4(ctx); |
1483 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1483, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1484 | 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, "alloc_engine4_unittest.cc" , 1484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1485 | |
1486 | // Let's now remove the client from the cable-modem class and try |
1487 | // to renew the address. The engine should determine that the |
1488 | // client doesn't have access to the subnet1 pools anymore and |
1489 | // assign an address from unrestricted subnet. |
1490 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1491 | ctx.subnet_ = subnet1_; |
1492 | lease = engine_.allocateLease4(ctx); |
1493 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1493, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1494 | 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, "alloc_engine4_unittest.cc" , 1494, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1495 | } |
1496 | |
1497 | // This test verifies that the server can assign an address from a |
1498 | // different subnet than orginally selected, when the address pool in |
1499 | // the first subnet requires another class. |
1500 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkPoolClassification", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1500), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1500), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1500 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test ::TestBody() { |
1501 | // Try to offer address from subnet1. There is one address available |
1502 | // so it should be offered. |
1503 | AllocEngine::ClientContext4 |
1504 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1505 | false, false, "host.example.com.", false); |
1506 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1507 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1508 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1508, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1509 | 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, "alloc_engine4_unittest.cc" , 1509, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1510 | |
1511 | // Remove the lease so as we can start over. |
1512 | 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, "alloc_engine4_unittest.cc" , 1512, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1513 | |
1514 | // Apply restrictions on the pool1. This should be only assigned |
1515 | // to clients belonging to cable-modem class. |
1516 | pool1_->allowClientClass("cable-modem"); |
1517 | |
1518 | // The allocation engine should determine that the pool1 is not |
1519 | // available for the client not belonging to the cable-modem class. |
1520 | // Instead, it should assign an address from subnet2 that belongs |
1521 | // to the same shared network. |
1522 | ctx.subnet_ = subnet1_; |
1523 | lease = engine_.allocateLease4(ctx); |
1524 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1524, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1525 | 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, "alloc_engine4_unittest.cc" , 1525, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1526 | |
1527 | // Remove the lease so as we can start over. |
1528 | 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, "alloc_engine4_unittest.cc" , 1528, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1529 | |
1530 | // Assign cable-modem class and try again. This time, we should |
1531 | // offer an address from the pool1. |
1532 | ctx.query_->addClass(ClientClass("cable-modem")); |
1533 | |
1534 | // Restrict access to pool2 for this client, to make sure that the |
1535 | // server doesn't accidentally get an address from this pool. |
1536 | pool2_->allowClientClass("telephone"); |
1537 | |
1538 | ctx.subnet_ = subnet1_; |
1539 | lease = engine_.allocateLease4(ctx); |
1540 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1540, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1541 | 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, "alloc_engine4_unittest.cc" , 1541, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1542 | |
1543 | // Let's now remove the client from the cable-modem class and try |
1544 | // to renew the address. The engine should determine that the |
1545 | // client doesn't have access to the pool1 anymore and |
1546 | // assign an address from another pool. |
1547 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1548 | ctx.query_->addClass(ClientClass("telephone")); |
1549 | ctx.subnet_ = subnet1_; |
1550 | lease = engine_.allocateLease4(ctx); |
1551 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1551, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1552 | 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, "alloc_engine4_unittest.cc" , 1552, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
1553 | } |
1554 | |
1555 | // Test that reservations within shared network take precedence over the |
1556 | // existing leases regardless in which subnet belonging to a shared network |
1557 | // reservations belong (DHCPREQUEST case). |
1558 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkReservations", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1558), ( ::testing::internal::GetTypeId<SharedNetworkAlloc4Test> ()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1558), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1558 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test ::TestBody() { |
1559 | |
1560 | 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, "alloc_engine4_unittest.cc" , 1560, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
1561 | |
1562 | // Create reservation for the client. |
1563 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1564 | Host::IDENT_HWADDR, subnet2_->getID(), |
1565 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1566 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1567 | CfgMgr::instance().commit(); |
1568 | |
1569 | // Start allocation from subnet1. The engine should determine that the |
1570 | // client has reservations in subnet2 and should rather assign reserved |
1571 | // addresses. |
1572 | AllocEngine::ClientContext4 |
1573 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1574 | false, false, "host.example.com.", false); |
1575 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1576 | AllocEngine::findReservation(ctx); |
1577 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1578 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1578, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1579 | 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, "alloc_engine4_unittest.cc", 1579, gtest_ar .failure_message()) = ::testing::Message(); |
1580 | 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, "alloc_engine4_unittest.cc" , 1580, gtest_ar.failure_message()) = ::testing::Message(); |
1581 | |
1582 | // Remove the lease for another test below. |
1583 | 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, "alloc_engine4_unittest.cc" , 1583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1584 | |
1585 | // Let's create a lease for the client to make sure the lease is not |
1586 | // renewed but a reserved lease is allocated again. |
1587 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1588 | 501, time(NULL__null), subnet1_->getID())); |
1589 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1590 | 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, "alloc_engine4_unittest.cc" , 1590, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
1591 | ctx.subnet_ = subnet1_; |
1592 | ctx.hosts_.clear(); |
1593 | AllocEngine::findReservation(ctx); |
1594 | 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, "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, "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, "alloc_engine4_unittest.cc" , 1597, gtest_ar.failure_message()) = ::testing::Message(); |
1598 | } |
1599 | |
1600 | // Test that reservations within shared network take precedence over the |
1601 | // existing leases regardless in which subnet belonging to a shared network |
1602 | // reservations belong (DHCPREQUEST case). Host lookups returning a collection |
1603 | // are disabled. As it is only an optimization the behavior (so the test) |
1604 | // must stay unchanged. |
1605 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkReservationsNoColl", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1605), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1605), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1605 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test ::TestBody() { |
1606 | |
1607 | // Disable host lookups returning a collection. |
1608 | 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, "alloc_engine4_unittest.cc" , 1608, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ) .c_str()) = ::testing::Message(); |
1609 | HostMgr::instance().setDisableSingleQuery(true); |
1610 | |
1611 | // Create reservation for the client. |
1612 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1613 | Host::IDENT_HWADDR, subnet2_->getID(), |
1614 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1615 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1616 | CfgMgr::instance().commit(); |
1617 | |
1618 | // Start allocation from subnet1. The engine should determine that the |
1619 | // client has reservations in subnet2 and should rather assign reserved |
1620 | // addresses. |
1621 | AllocEngine::ClientContext4 |
1622 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1623 | false, false, "host.example.com.", false); |
1624 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1625 | AllocEngine::findReservation(ctx); |
1626 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1627 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1627, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1628 | 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, "alloc_engine4_unittest.cc", 1628, gtest_ar .failure_message()) = ::testing::Message(); |
1629 | 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, "alloc_engine4_unittest.cc" , 1629, gtest_ar.failure_message()) = ::testing::Message(); |
1630 | |
1631 | // Remove the lease for another test below. |
1632 | 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, "alloc_engine4_unittest.cc" , 1632, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1633 | |
1634 | // Let's create a lease for the client to make sure the lease is not |
1635 | // renewed but a reserved lease is allocated again. |
1636 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1637 | 501, time(NULL__null), subnet1_->getID())); |
1638 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1639 | 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, "alloc_engine4_unittest.cc" , 1639, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ) .c_str()) = ::testing::Message(); |
1640 | ctx.subnet_ = subnet1_; |
1641 | ctx.hosts_.clear(); |
1642 | AllocEngine::findReservation(ctx); |
1643 | lease = engine_.allocateLease4(ctx); |
1644 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "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, "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, "alloc_engine4_unittest.cc" , 1646, gtest_ar.failure_message()) = ::testing::Message(); |
1647 | } |
1648 | |
1649 | // This test checks if an expired lease can be reused in DHCPDISCOVER (fake |
1650 | // allocation) |
1651 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseExpiredLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverReuseExpiredLease4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1651), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1651), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1651), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseExpiredLease4_Test >); void AllocEngine4Test_discoverReuseExpiredLease4_Test:: TestBody() { |
1652 | boost::scoped_ptr<AllocEngine> engine; |
1653 | 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_1653 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1653 ; } } else gtest_label_testnothrow_1653 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 1653, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
1654 | 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, "alloc_engine4_unittest.cc", 1654, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
1655 | |
1656 | IOAddress addr("192.0.2.15"); |
1657 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1658 | // Get rid of the default test configuration. |
1659 | cfg_mgr.clear(); |
1660 | |
1661 | // Create configuration similar to other tests, but with a single address pool |
1662 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1663 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1664 | subnet_->addPool(pool_); |
1665 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1666 | |
1667 | // Just a different hw/client-id for the second client |
1668 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
1669 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
1670 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
1671 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
1672 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
1673 | 495, now, subnet_->getID())); |
1674 | // Copy the lease, so as it can be compared with the old lease returned |
1675 | // by the allocation engine. |
1676 | Lease4 original_lease(*lease); |
1677 | |
1678 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
1679 | // is expired already |
1680 | 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, "alloc_engine4_unittest.cc", 1680, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->expired()" , "false", "true") .c_str()) = ::testing::Message(); |
1681 | 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, "alloc_engine4_unittest.cc" , 1681, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1682 | |
1683 | // CASE 1: Asking for any address |
1684 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
1685 | IOAddress("0.0.0.0"), false, false, |
1686 | "", true); |
1687 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1688 | lease = engine->allocateLease4(ctx1); |
1689 | // Check that we got that single lease |
1690 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1690, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1691 | 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, "alloc_engine4_unittest.cc" , 1691, gtest_ar.failure_message()) = ::testing::Message(); |
1692 | |
1693 | // We are reusing expired lease, the old (expired) instance should be |
1694 | // returned. The returned instance should be the same as the original |
1695 | // lease. |
1696 | 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, "alloc_engine4_unittest.cc", 1696, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
1697 | 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, "alloc_engine4_unittest.cc" , 1697, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
1698 | |
1699 | // Do all checks on the lease (if subnet-id, preferred/valid times are ok etc.) |
1700 | checkLease4(lease); |
1701 | |
1702 | // CASE 2: Asking specifically for this address |
1703 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
1704 | IOAddress(addr), false, false, |
1705 | "", true); |
1706 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1707 | lease = engine->allocateLease4(ctx2); |
1708 | // Check that we got that single lease |
1709 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1709, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1710 | 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, "alloc_engine4_unittest.cc" , 1710, gtest_ar.failure_message()) = ::testing::Message(); |
1711 | |
1712 | // We are updating expired lease. The copy of the old lease should be |
1713 | // returned and it should be equal to the original lease. |
1714 | 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, "alloc_engine4_unittest.cc", 1714, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
1715 | 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, "alloc_engine4_unittest.cc", 1715, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "*ctx2.old_lease_ == original_lease" , "false", "true") .c_str()) = ::testing::Message(); |
1716 | } |
1717 | |
1718 | // This test checks if an expired lease can be reused in REQUEST (actual allocation) |
1719 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestReuseExpiredLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestReuseExpiredLease4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1719), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1719), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1719), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseExpiredLease4_Test >); void AllocEngine4Test_requestReuseExpiredLease4_Test:: TestBody() { |
1720 | boost::scoped_ptr<AllocEngine> engine; |
1721 | 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_1721 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1721 ; } } else gtest_label_testnothrow_1721 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 1721, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
1722 | 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, "alloc_engine4_unittest.cc", 1722, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
1723 | |
1724 | IOAddress addr("192.0.2.105"); |
1725 | |
1726 | 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, "alloc_engine4_unittest.cc" , 1726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1727 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
1728 | subnet_->getID()); |
1729 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
1730 | 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, "alloc_engine4_unittest.cc", 1730, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-leases\", 0)" , "false", "true") .c_str()) = ::testing::Message(); |
1731 | 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, "alloc_engine4_unittest.cc" , 1731, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1732 | |
1733 | // Just a different hw/client-id for the second client |
1734 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
1735 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
1736 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
1737 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
1738 | |
1739 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
1740 | 495, now, subnet_->getID())); |
1741 | // Make a copy of the lease, so as we can compare that with the old lease |
1742 | // instance returned by the allocation engine. |
1743 | Lease4 original_lease(*lease); |
1744 | |
1745 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
1746 | // is expired already |
1747 | 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, "alloc_engine4_unittest.cc", 1747, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->expired()" , "false", "true") .c_str()) = ::testing::Message(); |
1748 | 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, "alloc_engine4_unittest.cc" , 1748, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1749 | |
1750 | // A client comes along, asking specifically for this address |
1751 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
1752 | IOAddress(addr), false, false, |
1753 | "host.example.com.", false); |
1754 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1755 | lease = engine->allocateLease4(ctx); |
1756 | |
1757 | // Check that he got that single lease |
1758 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1758, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1759 | 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, "alloc_engine4_unittest.cc" , 1759, gtest_ar.failure_message()) = ::testing::Message(); |
1760 | |
1761 | // Check that the lease is indeed updated in LeaseMgr |
1762 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
1763 | 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, "alloc_engine4_unittest.cc", 1763, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
1764 | |
1765 | // Now check that the lease in LeaseMgr has the same parameters |
1766 | detailCompareLease(lease, from_mgr); |
1767 | |
1768 | // The allocation engine should return a copy of the old lease. This |
1769 | // lease should be equal to the original lease. |
1770 | 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, "alloc_engine4_unittest.cc", 1770, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
1771 | 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, "alloc_engine4_unittest.cc", 1771, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "*ctx.old_lease_ == original_lease" , "false", "true") .c_str()) = ::testing::Message(); |
1772 | |
1773 | // Check that the stats declined stats were modified correctly. Note, because |
1774 | // added the lease directly, assigned-leases never bumped to one, so when we |
1775 | // reclaim it gets decremented to -1, then on assignment back to 0. |
1776 | 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, "alloc_engine4_unittest.cc" , 1776, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1777 | cumulative += 1; |
1778 | 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, "alloc_engine4_unittest.cc" , 1779, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
1779 | 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, "alloc_engine4_unittest.cc" , 1779, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1780 | glbl_cumulative += 1; |
1781 | 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, "alloc_engine4_unittest.cc" , 1781, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
1782 | 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, "alloc_engine4_unittest.cc", 1782, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-leases\", 1)" , "false", "true") .c_str()) = ::testing::Message(); |
1783 | 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, "alloc_engine4_unittest.cc" , 1783, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1784 | } |
1785 | |
1786 | // This test checks if an expired declined lease can be reused when responding |
1787 | // to DHCPDISCOVER (fake allocation) |
1788 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseDeclinedLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverReuseDeclinedLease4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1788), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1788), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1788), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4_Test ::TestBody() { |
1789 | |
1790 | AllocEnginePtr engine(new AllocEngine(0)); |
1791 | 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, "alloc_engine4_unittest.cc", 1791, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
1792 | |
1793 | // Now prepare a configuration with single address pool. |
1794 | IOAddress addr("192.0.2.15"); |
1795 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1796 | cfg_mgr.clear(); |
1797 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1798 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1799 | subnet_->addPool(pool_); |
1800 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1801 | |
1802 | // Now create a declined lease, decline it and rewind its cltt, so it |
1803 | // is expired. |
1804 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1805 | |
1806 | // CASE 1: Ask for any address |
1807 | Lease4Ptr assigned; |
1808 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
1809 | |
1810 | // Check that we got that single lease |
1811 | 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, "alloc_engine4_unittest.cc", 1811, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true") .c_str()) = ::testing::Message(); |
1812 | 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, "alloc_engine4_unittest.cc" , 1812, gtest_ar.failure_message()) = ::testing::Message(); |
1813 | |
1814 | // CASE 2: Asking specifically for this address |
1815 | testReuseLease4(engine, declined, "192.0.2.15", true, SHOULD_PASS, assigned); |
1816 | |
1817 | // Check that we get it again |
1818 | 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, "alloc_engine4_unittest.cc", 1818, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true") .c_str()) = ::testing::Message(); |
1819 | 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, "alloc_engine4_unittest.cc" , 1819, gtest_ar.failure_message()) = ::testing::Message(); |
1820 | } |
1821 | |
1822 | // This test checks if statistics are not updated when expired declined lease |
1823 | // is reused when responding to DHCPDISCOVER (fake allocation) |
1824 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverReuseDeclinedLease4Stats", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1824), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1824), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 1824), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test ::TestBody() { |
1825 | |
1826 | // Now prepare for DISCOVER processing |
1827 | AllocEnginePtr engine(new AllocEngine(0)); |
1828 | 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, "alloc_engine4_unittest.cc", 1828, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
1829 | |
1830 | // Now prepare a configuration with single address pool. |
1831 | IOAddress addr("192.0.2.15"); |
1832 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1833 | cfg_mgr.clear(); |
1834 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1835 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1836 | subnet_->addPool(pool_); |
1837 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1838 | cfg_mgr.commit(); // so we will recalc stats |
1839 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
1840 | subnet_->getID()); |
1841 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
1842 | |
1843 | // Now create a declined lease, decline it and rewind its cltt, so it |
1844 | // is expired. |
1845 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1846 | |
1847 | // Ask for any address. There's only one address in the pool, so it doesn't |
1848 | // matter much. |
1849 | Lease4Ptr assigned; |
1850 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
1851 | |
1852 | // Check that the stats declined stats were not modified |
1853 | 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, "alloc_engine4_unittest.cc" , 1853, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1854 | 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, "alloc_engine4_unittest.cc" , 1855, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
1855 | 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, "alloc_engine4_unittest.cc" , 1855, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1856 | 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, "alloc_engine4_unittest.cc" , 1856, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
1857 | 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, "alloc_engine4_unittest.cc", 1857, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"declined-addresses\", 0)" , "false", "true") .c_str()) = ::testing::Message(); |
1858 | 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, "alloc_engine4_unittest.cc", 1858, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-declined-addresses\", 0)" , "false", "true") .c_str()) = ::testing::Message(); |
1859 | 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, "alloc_engine4_unittest.cc" , 1859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1860 | 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, "alloc_engine4_unittest.cc" , 1860, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1861 | } |
1862 | |
1863 | // This test checks if an expired declined lease can be reused when responding |
1864 | // to REQUEST (actual allocation) |
1865 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestReuseDeclinedLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestReuseDeclinedLease4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1865), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1865), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1865), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4_Test >); void AllocEngine4Test_requestReuseDeclinedLease4_Test:: TestBody() { |
1866 | |
1867 | AllocEnginePtr engine(new AllocEngine(0)); |
1868 | 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, "alloc_engine4_unittest.cc", 1868, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
1869 | |
1870 | // Now prepare a configuration with single address pool. |
1871 | IOAddress addr("192.0.2.15"); |
1872 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1873 | cfg_mgr.clear(); |
1874 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1875 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1876 | subnet_->addPool(pool_); |
1877 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1878 | |
1879 | // Now create a declined lease, decline it and rewind its cltt, so it |
1880 | // is expired. |
1881 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1882 | |
1883 | // Asking specifically for this address |
1884 | Lease4Ptr assigned; |
1885 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
1886 | // Check that we got it. |
1887 | 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, "alloc_engine4_unittest.cc", 1887, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true") .c_str()) = ::testing::Message(); |
1888 | 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, "alloc_engine4_unittest.cc" , 1888, gtest_ar.failure_message()) = ::testing::Message(); |
1889 | |
1890 | // Check that the lease is indeed updated in LeaseMgr |
1891 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
1892 | 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, "alloc_engine4_unittest.cc", 1892, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
1893 | |
1894 | // Now check that the lease in LeaseMgr has the same parameters |
1895 | detailCompareLease(assigned, from_mgr); |
1896 | } |
1897 | |
1898 | // This test checks if statistics are not updated when expired declined lease |
1899 | // is reused when responding to DHCPREQUEST (actual allocation) |
1900 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestReuseDeclinedLease4Stats_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestReuseDeclinedLease4Stats", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1900), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1900), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 1900), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_requestReuseDeclinedLease4Stats_Test ::TestBody() { |
1901 | |
1902 | AllocEnginePtr engine(new AllocEngine(0)); |
1903 | 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, "alloc_engine4_unittest.cc", 1903, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
1904 | |
1905 | // Now prepare a configuration with single address pool. |
1906 | IOAddress addr("192.0.2.15"); |
1907 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1908 | cfg_mgr.clear(); |
1909 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1910 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1911 | subnet_->addPool(pool_); |
1912 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1913 | cfg_mgr.commit(); |
1914 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
1915 | subnet_->getID()); |
1916 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
1917 | |
1918 | // Now create a declined lease, decline it and rewind its cltt, so it |
1919 | // is expired. |
1920 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1921 | |
1922 | // Asking specifically for this address |
1923 | Lease4Ptr assigned; |
1924 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
1925 | // Check that we got it. |
1926 | 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, "alloc_engine4_unittest.cc", 1926, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true") .c_str()) = ::testing::Message(); |
1927 | |
1928 | // Check that the stats are correct. Note that assigned-addresses does |
1929 | // not get decremented when a lease is declined, ergo not incremented |
1930 | // when it is reused. Declined address stats will be -1 since |
1931 | // lease was created as declined which does not increment the stat. |
1932 | 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, "alloc_engine4_unittest.cc" , 1932, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1933 | cumulative += 1; |
1934 | 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, "alloc_engine4_unittest.cc" , 1935, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
1935 | 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, "alloc_engine4_unittest.cc" , 1935, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1936 | glbl_cumulative += 1; |
1937 | 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, "alloc_engine4_unittest.cc" , 1937, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
1938 | 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, "alloc_engine4_unittest.cc", 1938, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"declined-addresses\", -1)" , "false", "true") .c_str()) = ::testing::Message(); |
1939 | 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, "alloc_engine4_unittest.cc", 1939, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-declined-addresses\", 1)" , "false", "true") .c_str()) = ::testing::Message(); |
1940 | 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, "alloc_engine4_unittest.cc" , 1940, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", -1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1941 | 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, "alloc_engine4_unittest.cc" , 1941, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1942 | } |
1943 | |
1944 | // This test checks if a released lease can be reused in REQUEST (actual allocation) |
1945 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestReuseReleasedLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestReuseReleasedLease4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1945), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1945), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1945), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseReleasedLease4_Test >); void AllocEngine4Test_requestReuseReleasedLease4_Test:: TestBody() { |
1946 | boost::scoped_ptr<AllocEngine> engine; |
1947 | 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_1947 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1947 ; } } else gtest_label_testnothrow_1947 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 1947, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
1948 | 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, "alloc_engine4_unittest.cc", 1948, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
1949 | |
1950 | IOAddress addr("192.0.2.105"); |
1951 | |
1952 | 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, "alloc_engine4_unittest.cc" , 1952, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1953 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
1954 | subnet_->getID()); |
1955 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
1956 | 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, "alloc_engine4_unittest.cc", 1956, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-leases\", 0)" , "false", "true") .c_str()) = ::testing::Message(); |
1957 | 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, "alloc_engine4_unittest.cc" , 1957, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
1958 | |
1959 | // Just a different hw/client-id for the second client |
1960 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
1961 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
1962 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
1963 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
1964 | |
1965 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
1966 | 495, now, subnet_->getID())); |
1967 | lease->state_ = Lease4::STATE_RELEASED; |
1968 | // Make a copy of the lease, so as we can compare that with the old lease |
1969 | // instance returned by the allocation engine. |
1970 | Lease4 original_lease(*lease); |
1971 | |
1972 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
1973 | // is expired already |
1974 | 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, "alloc_engine4_unittest.cc", 1974, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->expired()" , "false", "true") .c_str()) = ::testing::Message(); |
1975 | 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, "alloc_engine4_unittest.cc" , 1975, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
1976 | |
1977 | // A client comes along, asking specifically for this address |
1978 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
1979 | IOAddress(addr), false, false, |
1980 | "host.example.com.", false); |
1981 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1982 | lease = engine->allocateLease4(ctx); |
1983 | |
1984 | // Check that he got that single lease |
1985 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1985, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
1986 | 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, "alloc_engine4_unittest.cc" , 1986, gtest_ar.failure_message()) = ::testing::Message(); |
1987 | |
1988 | // Check that the lease is indeed updated in LeaseMgr |
1989 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
1990 | 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, "alloc_engine4_unittest.cc", 1990, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
1991 | |
1992 | // Now check that the lease in LeaseMgr has the same parameters |
1993 | detailCompareLease(lease, from_mgr); |
1994 | |
1995 | // The allocation engine should return a copy of the old lease. This |
1996 | // lease should be equal to the original lease. |
1997 | 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, "alloc_engine4_unittest.cc", 1997, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
1998 | 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, "alloc_engine4_unittest.cc", 1998, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "*ctx.old_lease_ == original_lease" , "false", "true") .c_str()) = ::testing::Message(); |
1999 | |
2000 | 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, "alloc_engine4_unittest.cc" , 2000, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
2001 | cumulative += 1; |
2002 | 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, "alloc_engine4_unittest.cc" , 2003, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
2003 | 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, "alloc_engine4_unittest.cc" , 2003, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
2004 | glbl_cumulative += 1; |
2005 | 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, "alloc_engine4_unittest.cc" , 2005, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
2006 | 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, "alloc_engine4_unittest.cc", 2006, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-leases\", 1)" , "false", "true") .c_str()) = ::testing::Message(); |
2007 | 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, "alloc_engine4_unittest.cc" , 2007, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
2008 | } |
2009 | |
2010 | // This test checks that the Allocation Engine correctly identifies the |
2011 | // existing client's lease in the lease database, using the client |
2012 | // identifier and HW address. |
2013 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_identifyClientLease_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "identifyClientLease", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2013), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2013), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2013), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_identifyClientLease_Test >); void AllocEngine4Test_identifyClientLease_Test::TestBody () { |
2014 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, clientid_, |
2015 | 100, time(NULL__null), subnet_->getID())); |
2016 | LeaseMgrFactory::instance().addLease(lease); |
2017 | |
2018 | AllocEngine engine(0); |
2019 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2020 | IOAddress::IPV4_ZERO_ADDRESS(), |
2021 | false, false, "", true); |
2022 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2023 | |
2024 | Lease4Ptr identified_lease = engine.allocateLease4(ctx); |
2025 | 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, "alloc_engine4_unittest.cc", 2025, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2026 | 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, "alloc_engine4_unittest.cc" , 2026, gtest_ar.failure_message()) = ::testing::Message(); |
2027 | |
2028 | ctx.hwaddr_ = hwaddr2_; |
2029 | ctx.clientid_ = clientid_; |
2030 | identified_lease = engine.allocateLease4(ctx); |
2031 | 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, "alloc_engine4_unittest.cc", 2031, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2032 | 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, "alloc_engine4_unittest.cc" , 2032, gtest_ar.failure_message()) = ::testing::Message(); |
2033 | |
2034 | ctx.hwaddr_ = hwaddr_; |
2035 | ctx.clientid_ = clientid2_; |
2036 | identified_lease = engine.allocateLease4(ctx); |
2037 | 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, "alloc_engine4_unittest.cc", 2037, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2038 | 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, "alloc_engine4_unittest.cc", 2038, gtest_ar .failure_message()) = ::testing::Message(); |
2039 | |
2040 | ctx.hwaddr_ = hwaddr_; |
2041 | ctx.clientid_.reset(); |
2042 | identified_lease = engine.allocateLease4(ctx); |
2043 | 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, "alloc_engine4_unittest.cc", 2043, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2044 | 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, "alloc_engine4_unittest.cc" , 2044, gtest_ar.failure_message()) = ::testing::Message(); |
2045 | |
2046 | ctx.hwaddr_ = hwaddr2_; |
2047 | ctx.clientid_.reset(); |
2048 | identified_lease = engine.allocateLease4(ctx); |
2049 | 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, "alloc_engine4_unittest.cc", 2049, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2050 | 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, "alloc_engine4_unittest.cc", 2050, gtest_ar .failure_message()) = ::testing::Message(); |
2051 | |
2052 | lease->client_id_.reset(); |
2053 | 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_2053; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2053; } } else gtest_label_testnothrow_2053 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 2053, ("Expected: " "LeaseMgrFactory::instance().updateLease4(lease)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
2054 | |
2055 | ctx.hwaddr_ = hwaddr_; |
2056 | ctx.clientid_ = clientid_; |
2057 | 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, "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, "alloc_engine4_unittest.cc" , 2059, gtest_ar.failure_message()) = ::testing::Message(); |
2060 | |
2061 | ctx.hwaddr_ = hwaddr_; |
2062 | ctx.clientid_.reset(); |
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, "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, "alloc_engine4_unittest.cc" , 2065, gtest_ar.failure_message()) = ::testing::Message(); |
2066 | |
2067 | ctx.hwaddr_ = hwaddr2_; |
2068 | ctx.clientid_ = clientid_; |
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, "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, "alloc_engine4_unittest.cc", 2071, gtest_ar .failure_message()) = ::testing::Message(); |
2072 | } |
2073 | |
2074 | // This test checks that when the client requests the address which belongs |
2075 | // to another client, the allocation engine returns NULL (for the |
2076 | // DHCPREQUEST case) or a lease for the address which belongs to this |
2077 | // client (DHCPDISCOVER case). |
2078 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestOtherClientLease_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestOtherClientLease", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2078), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2078), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2078), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestOtherClientLease_Test >); void AllocEngine4Test_requestOtherClientLease_Test::TestBody () { |
2079 | // Create the first lease. |
2080 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2081 | &clientid_->getClientId()[0], |
2082 | clientid_->getClientId().size(), |
2083 | 100, time(NULL__null), subnet_->getID(), |
2084 | false, false, "")); |
2085 | // Create the second lease. Note that we use the same client id here and |
2086 | // we expect that the allocation engine will figure out that the hardware |
2087 | // address is different. |
2088 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr2_, |
2089 | &clientid_->getClientId()[0], |
2090 | clientid_->getClientId().size(), |
2091 | 100, time(NULL__null), subnet_->getID(), |
2092 | false, false, "")); |
2093 | // Add leases for both clients to the Lease Manager. |
2094 | LeaseMgrFactory::instance().addLease(lease); |
2095 | LeaseMgrFactory::instance().addLease(lease2); |
2096 | |
2097 | AllocEngine engine(0); |
2098 | |
2099 | // First client requests the lease which belongs to the second client. |
2100 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
2101 | false, false, "", false); |
2102 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2103 | Lease4Ptr new_lease = engine.allocateLease4(ctx); |
2104 | // Allocation engine should return NULL. |
2105 | 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, "alloc_engine4_unittest.cc", 2105, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "new_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2106 | |
2107 | 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 , "alloc_engine4_unittest.cc", 2107, gtest_ar.failure_message ()) = ::testing::Message(); |
2108 | 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, "alloc_engine4_unittest.cc", 2108, gtest_ar .failure_message()) = ::testing::Message(); |
2109 | 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 , "alloc_engine4_unittest.cc", 2109, gtest_ar.failure_message ()) = ::testing::Message(); |
2110 | 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 , "alloc_engine4_unittest.cc", 2110, gtest_ar.failure_message ()) = ::testing::Message(); |
2111 | 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 , "alloc_engine4_unittest.cc", 2111, gtest_ar.failure_message ()) = ::testing::Message(); |
2112 | |
2113 | 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, "alloc_engine4_unittest.cc", 2113, gtest_ar .failure_message()) = ::testing::Message(); |
2114 | 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, "alloc_engine4_unittest.cc" , 2114, gtest_ar.failure_message()) = ::testing::Message(); |
2115 | 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, "alloc_engine4_unittest.cc", 2115, gtest_ar .failure_message()) = ::testing::Message(); |
2116 | 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, "alloc_engine4_unittest.cc" , 2116, gtest_ar.failure_message()) = ::testing::Message(); |
2117 | 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, "alloc_engine4_unittest.cc" , 2117, gtest_ar.failure_message()) = ::testing::Message(); |
2118 | |
2119 | // Now simulate the DHCPDISCOVER case when the provided address is |
2120 | // treated as a hint. The engine should return a lease for a |
2121 | // different address than requested. |
2122 | ctx.fake_allocation_ = true; |
2123 | new_lease = engine.allocateLease4(ctx); |
2124 | 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, "alloc_engine4_unittest.cc", 2124, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "new_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2125 | 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, "alloc_engine4_unittest.cc" , 2125, gtest_ar.failure_message()) = ::testing::Message(); |
2126 | } |
2127 | |
2128 | // This test checks the behavior of the allocation engine in the following |
2129 | // scenario: |
2130 | // - Client has no lease in the database. |
2131 | // - Client has a reservation. |
2132 | // - Client sends DHCPREQUEST without requested IP Address, nor ciaddr. |
2133 | // - Client is allocated a reserved address. |
2134 | // |
2135 | // Note that client must normally include a requested IP address or ciaddr |
2136 | // in its message. But, we still want to provision clients that don't do that. |
2137 | // The server simply picks reserved address or any other available one if there |
2138 | // is no reservation. |
2139 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressNoHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressNoHint", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2139), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2139), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2139), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHint_Test >); void AllocEngine4Test_reservedAddressNoHint_Test::TestBody () { |
2140 | // Create reservation for the client. |
2141 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2142 | Host::IDENT_HWADDR, subnet_->getID(), |
2143 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2144 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2145 | CfgMgr::instance().commit(); |
2146 | |
2147 | AllocEngine engine(0); |
2148 | |
2149 | // Try to allocate a lease without specifying a hint. This is actually |
2150 | // incorrect behavior of the client to not send an address it wants to |
2151 | // obtain but the server should handle this gracefully. |
2152 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2153 | IOAddress("0.0.0.0"), false, false, |
2154 | "", false); |
2155 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2156 | AllocEngine::findReservation(ctx); |
2157 | Lease4Ptr lease = engine.allocateLease4(ctx); |
2158 | |
2159 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 2159, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
2160 | 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, "alloc_engine4_unittest.cc" , 2160, gtest_ar.failure_message()) = ::testing::Message(); |
2161 | |
2162 | // Make sure that the lease has been committed to the lease database. |
2163 | // And that the committed lease is equal to the one returned. |
2164 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2165 | 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, "alloc_engine4_unittest.cc", 2165, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2166 | detailCompareLease(lease, from_mgr); |
2167 | |
2168 | // Initially, there was no lease for this client, so the returned old |
2169 | // lease should be NULL. |
2170 | 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, "alloc_engine4_unittest.cc", 2170, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2171 | } |
2172 | |
2173 | // This test checks behavior of the allocation engine in the following scenario: |
2174 | // - Client has no lease in the database. |
2175 | // - Client has a reservation. |
2176 | // - Client sends DHCPDISCOVER without requested IP Address. |
2177 | // - Server returns DHCPOFFER with the reserved address. |
2178 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressNoHintFakeAllocation", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 2178 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2178), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2178), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test ::TestBody() { |
2179 | // Create reservation for the client. |
2180 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2181 | Host::IDENT_HWADDR, subnet_->getID(), |
2182 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2183 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2184 | CfgMgr::instance().commit(); |
2185 | |
2186 | AllocEngine engine(0); |
2187 | |
2188 | // Query allocation engine for the lease to be assigned to this |
2189 | // client without specifying the address to be assigned. |
2190 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2191 | IOAddress("0.0.0.0"), false, false, |
2192 | "", true); |
2193 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2194 | AllocEngine::findReservation(ctx); |
2195 | Lease4Ptr lease = engine.allocateLease4(ctx); |
2196 | |
2197 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 2197, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
2198 | // The allocation engine should return a reserved address. |
2199 | 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, "alloc_engine4_unittest.cc" , 2199, gtest_ar.failure_message()) = ::testing::Message(); |
2200 | |
2201 | // This is a "fake" allocation so the returned lease should not be committed |
2202 | // to the lease database. |
2203 | 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, "alloc_engine4_unittest.cc" , 2203, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
2204 | |
2205 | // Client had no lease in the database, so the old lease returned should |
2206 | // be NULL. |
2207 | 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, "alloc_engine4_unittest.cc", 2207, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2208 | } |
2209 | |
2210 | // This test checks the behavior of the allocation engine in the following |
2211 | // scenario: |
2212 | // - Client has no lease in the database. |
2213 | // - Client has a reservation. |
2214 | // - Client sends DHCPREQUEST with a requested IP address |
2215 | // - Server returns DHCPNAK when requested IP address is different than |
2216 | // the reserved address. Note that the allocation engine returns NULL |
2217 | // to indicate to the server that it should send DHCPNAK. |
2218 | // - Server allocates a reserved address to the client when the client requests |
2219 | // this address using requested IP address option. |
2220 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHint", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2220), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2220), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2220), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHint_Test >); void AllocEngine4Test_reservedAddressHint_Test::TestBody () { |
2221 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2222 | Host::IDENT_HWADDR, subnet_->getID(), |
2223 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2224 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2225 | CfgMgr::instance().commit(); |
2226 | |
2227 | AllocEngine engine(0); |
2228 | |
2229 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2230 | IOAddress("192.0.2.234"), false, false, |
2231 | "", false); |
2232 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2233 | AllocEngine::findReservation(ctx1); |
2234 | Lease4Ptr lease = engine.allocateLease4(ctx1); |
2235 | |
2236 | // The client requested a different address than reserved, so |
2237 | // the allocation engine should return NULL lease. When the server |
2238 | // receives a NULL lease for the client, it will send a DHCPNAK. |
2239 | 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, "alloc_engine4_unittest.cc", 2239, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false") .c_str()) = ::testing::Message(); |
2240 | 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, "alloc_engine4_unittest.cc", 2240, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2241 | |
2242 | 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 , "alloc_engine4_unittest.cc", 2242, gtest_ar.failure_message ()) = ::testing::Message(); |
2243 | 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, "alloc_engine4_unittest.cc", 2243, gtest_ar .failure_message()) = ::testing::Message(); |
2244 | 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 , "alloc_engine4_unittest.cc", 2244, gtest_ar.failure_message ()) = ::testing::Message(); |
2245 | 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 , "alloc_engine4_unittest.cc", 2245, gtest_ar.failure_message ()) = ::testing::Message(); |
2246 | 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 , "alloc_engine4_unittest.cc", 2246, gtest_ar.failure_message ()) = ::testing::Message(); |
2247 | |
2248 | 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, "alloc_engine4_unittest.cc", 2248, gtest_ar .failure_message()) = ::testing::Message(); |
2249 | 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, "alloc_engine4_unittest.cc" , 2249, gtest_ar.failure_message()) = ::testing::Message(); |
2250 | 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, "alloc_engine4_unittest.cc", 2250, gtest_ar .failure_message()) = ::testing::Message(); |
2251 | 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, "alloc_engine4_unittest.cc" , 2251, gtest_ar.failure_message()) = ::testing::Message(); |
2252 | 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, "alloc_engine4_unittest.cc" , 2252, gtest_ar.failure_message()) = ::testing::Message(); |
2253 | |
2254 | // Now, request a correct address. The client should obtain it. |
2255 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2256 | IOAddress("192.0.2.123"), false, false, |
2257 | "", false); |
2258 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2259 | AllocEngine::findReservation(ctx2); |
2260 | lease = engine.allocateLease4(ctx2); |
2261 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 2261, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
2262 | 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, "alloc_engine4_unittest.cc" , 2262, gtest_ar.failure_message()) = ::testing::Message(); |
2263 | |
2264 | // Make sure that the lease has been committed to the lease database. |
2265 | // And that the committed lease is equal to the one returned. |
2266 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2267 | 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, "alloc_engine4_unittest.cc", 2267, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2268 | detailCompareLease(lease, from_mgr); |
2269 | |
2270 | 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, "alloc_engine4_unittest.cc", 2270, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2271 | } |
2272 | |
2273 | // This test checks the behavior of the allocation engine in the following |
2274 | // scenario: |
2275 | // - Client has no lease in the database. |
2276 | // - Client has a reservation. |
2277 | // - Client sends DHCPDISCOVER with a requested IP address as a hint. |
2278 | // - Server offers a reserved address, even though it is different than the |
2279 | // requested address. |
2280 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHintFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHintFakeAllocation", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2280), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2280), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2280), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHintFakeAllocation_Test ::TestBody() { |
2281 | // Create a reservation for the client. |
2282 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2283 | Host::IDENT_HWADDR, subnet_->getID(), |
2284 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2285 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2286 | CfgMgr::instance().commit(); |
2287 | |
2288 | AllocEngine engine(0); |
2289 | |
2290 | // Query the allocation engine for the lease to be assigned to the client |
2291 | // and specify a hint being a different address than the reserved one. |
2292 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2293 | IOAddress("192.0.2.234"), false, false, |
2294 | "", true); |
2295 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2296 | AllocEngine::findReservation(ctx); |
2297 | Lease4Ptr lease = engine.allocateLease4(ctx); |
2298 | |
2299 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 2299, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
2300 | // Allocation engine should return reserved address. |
2301 | 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, "alloc_engine4_unittest.cc" , 2301, gtest_ar.failure_message()) = ::testing::Message(); |
2302 | |
2303 | // This is a "fake" allocation so the returned lease should not be committed |
2304 | // to the lease database. |
2305 | 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, "alloc_engine4_unittest.cc" , 2305, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
2306 | |
2307 | 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, "alloc_engine4_unittest.cc", 2307, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2308 | } |
2309 | |
2310 | // This test checks that the behavior of the allocation engine in the following |
2311 | // scenario: |
2312 | // - Client has a lease for the address from the dynamic pool in the database. |
2313 | // - Client has a reservation for a different address than the one for which |
2314 | // the client has a lease. |
2315 | // - Client sends DHCPREQUEST, asking for the reserved address (as it has been |
2316 | // offered to it when it sent DHCPDISCOVER). |
2317 | // - Server allocates a reserved address and removes the lease for the address |
2318 | // previously allocated to the client. |
2319 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLease_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLease", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2319), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2319), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2319), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLease_Test >); void AllocEngine4Test_reservedAddressExistingLease_Test ::TestBody() { |
2320 | // Create the reservation for the client. |
2321 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2322 | Host::IDENT_HWADDR, subnet_->getID(), |
2323 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2324 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2325 | CfgMgr::instance().commit(); |
2326 | |
2327 | // Create a lease for the client with a different address than the reserved |
2328 | // one. |
2329 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2330 | &clientid_->getClientId()[0], |
2331 | clientid_->getClientId().size(), |
2332 | 100, time(NULL__null), subnet_->getID(), |
2333 | false, false, "")); |
2334 | LeaseMgrFactory::instance().addLease(lease); |
2335 | |
2336 | AllocEngine engine(0); |
2337 | |
2338 | // Request allocation of the reserved address. |
2339 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2340 | IOAddress("192.0.2.123"), false, false, |
2341 | "", false); |
2342 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2343 | AllocEngine::findReservation(ctx); |
2344 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2345 | |
2346 | 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, "alloc_engine4_unittest.cc", 2346, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2347 | // The engine should have allocated the reserved address. |
2348 | 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, "alloc_engine4_unittest.cc" , 2348, gtest_ar.failure_message()) = ::testing::Message(); |
2349 | |
2350 | // Make sure that the lease has been committed to the lease database. |
2351 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
2352 | 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, "alloc_engine4_unittest.cc", 2352, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2353 | detailCompareLease(allocated_lease, from_mgr); |
2354 | |
2355 | // The previous lease should have been replaced by a new one. The previous |
2356 | // lease should be returned by the allocation engine to the caller. |
2357 | 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, "alloc_engine4_unittest.cc", 2357, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
2358 | 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, "alloc_engine4_unittest.cc" , 2358, gtest_ar.failure_message()) = ::testing::Message(); |
2359 | detailCompareLease(ctx.old_lease_, lease); |
2360 | } |
2361 | |
2362 | // This test checks that the behavior of the allocation engine in the following |
2363 | // scenario: |
2364 | // - Client A has a lease in the database. |
2365 | // - Client B has a reservation for the address in use by client A. |
2366 | // - Client B sends a DHCPREQUEST requesting the allocation of the reserved |
2367 | // lease (in use by client A). |
2368 | // - Server determines that the reserved address is in use by a different client |
2369 | // and returns DHCPNAK to client B. |
2370 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHijacked_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHijacked", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2370), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2370), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2370), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijacked_Test >); void AllocEngine4Test_reservedAddressHijacked_Test::TestBody () { |
2371 | // Create host reservation for the client B. |
2372 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2373 | Host::IDENT_HWADDR, subnet_->getID(), |
2374 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2375 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2376 | CfgMgr::instance().commit(); |
2377 | |
2378 | // Allocate a lease for the client A for the same address as reserved |
2379 | // for the client B. |
2380 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
2381 | 100, time(NULL__null), subnet_->getID(), |
2382 | false, false, "")); |
2383 | LeaseMgrFactory::instance().addLease(lease); |
2384 | |
2385 | AllocEngine engine(0); |
2386 | |
2387 | // Try to allocate the reserved lease to client B. |
2388 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2389 | IOAddress("192.0.2.123"), false, false, |
2390 | "", false); |
2391 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2392 | AllocEngine::findReservation(ctx1); |
2393 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2394 | // The lease is allocated to someone else, so the allocation should not |
2395 | // succeed. |
2396 | 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, "alloc_engine4_unittest.cc", 2396, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2397 | 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, "alloc_engine4_unittest.cc", 2397, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2398 | |
2399 | 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 , "alloc_engine4_unittest.cc", 2399, gtest_ar.failure_message ()) = ::testing::Message(); |
2400 | 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, "alloc_engine4_unittest.cc", 2400, gtest_ar .failure_message()) = ::testing::Message(); |
2401 | 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 , "alloc_engine4_unittest.cc", 2401, gtest_ar.failure_message ()) = ::testing::Message(); |
2402 | 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 , "alloc_engine4_unittest.cc", 2402, gtest_ar.failure_message ()) = ::testing::Message(); |
2403 | 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 , "alloc_engine4_unittest.cc", 2403, gtest_ar.failure_message ()) = ::testing::Message(); |
2404 | |
2405 | 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, "alloc_engine4_unittest.cc", 2405, gtest_ar .failure_message()) = ::testing::Message(); |
2406 | 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, "alloc_engine4_unittest.cc" , 2406, gtest_ar.failure_message()) = ::testing::Message(); |
2407 | 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, "alloc_engine4_unittest.cc", 2407, gtest_ar .failure_message()) = ::testing::Message(); |
2408 | 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, "alloc_engine4_unittest.cc" , 2408, gtest_ar.failure_message()) = ::testing::Message(); |
2409 | 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, "alloc_engine4_unittest.cc" , 2409, gtest_ar.failure_message()) = ::testing::Message(); |
2410 | |
2411 | // Make sure that the allocation engine didn't modify the lease of the |
2412 | // client A. |
2413 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2414 | 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, "alloc_engine4_unittest.cc", 2414, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2415 | detailCompareLease(lease, from_mgr); |
2416 | |
2417 | // Try doing the same thing, but this time do not request any specific |
2418 | // address. It should have the same effect. |
2419 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2420 | IOAddress("0.0.0.0"), false, false, |
2421 | "", false); |
2422 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2423 | AllocEngine::findReservation(ctx2); |
2424 | allocated_lease = engine.allocateLease4(ctx2); |
2425 | 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, "alloc_engine4_unittest.cc", 2425, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2426 | 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, "alloc_engine4_unittest.cc", 2426, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2427 | |
2428 | 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 , "alloc_engine4_unittest.cc", 2428, gtest_ar.failure_message ()) = ::testing::Message(); |
2429 | 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, "alloc_engine4_unittest.cc", 2429, gtest_ar .failure_message()) = ::testing::Message(); |
2430 | 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 , "alloc_engine4_unittest.cc", 2430, gtest_ar.failure_message ()) = ::testing::Message(); |
2431 | 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 , "alloc_engine4_unittest.cc", 2431, gtest_ar.failure_message ()) = ::testing::Message(); |
2432 | 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 , "alloc_engine4_unittest.cc", 2432, gtest_ar.failure_message ()) = ::testing::Message(); |
2433 | |
2434 | 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, "alloc_engine4_unittest.cc", 2434, gtest_ar .failure_message()) = ::testing::Message(); |
2435 | 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, "alloc_engine4_unittest.cc" , 2435, gtest_ar.failure_message()) = ::testing::Message(); |
2436 | 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, "alloc_engine4_unittest.cc", 2436, gtest_ar .failure_message()) = ::testing::Message(); |
2437 | 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, "alloc_engine4_unittest.cc" , 2437, gtest_ar.failure_message()) = ::testing::Message(); |
2438 | 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, "alloc_engine4_unittest.cc" , 2438, gtest_ar.failure_message()) = ::testing::Message(); |
2439 | |
2440 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2441 | 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, "alloc_engine4_unittest.cc", 2441, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2442 | detailCompareLease(lease, from_mgr); |
2443 | } |
2444 | |
2445 | // This test checks that the behavior of the allocation engine in the following |
2446 | // scenario: |
2447 | // - Client A has a lease in the database. |
2448 | // - Client B has a reservation for the address in use by client A. |
2449 | // - Client B sends a DHCPDISCOVER. |
2450 | // - Server determines that the reserved address is in use by a different client |
2451 | // so it offers an address from the dynamic pool. |
2452 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHijackedFakeAllocation", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 2452 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2452), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2452), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test ::TestBody() { |
2453 | // Create a reservation for the client B. |
2454 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2455 | Host::IDENT_HWADDR, subnet_->getID(), |
2456 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2457 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2458 | CfgMgr::instance().commit(); |
2459 | |
2460 | // Create a lease for the client A. |
2461 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
2462 | 100, time(NULL__null), subnet_->getID(), |
2463 | false, false, "")); |
2464 | LeaseMgrFactory::instance().addLease(lease); |
2465 | |
2466 | AllocEngine engine(0); |
2467 | |
2468 | // Query allocation engine for the lease to be allocated to the client B. |
2469 | // The allocation engine is not able to allocate the lease to the client |
2470 | // B, because the address is in use by client A. |
2471 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2472 | IOAddress("192.0.2.123"), false, false, |
2473 | "", true); |
2474 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2475 | AllocEngine::findReservation(ctx1); |
2476 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2477 | |
2478 | // The allocation engine should return a lease but for a different address |
2479 | // than requested because this address is in use. |
2480 | 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, "alloc_engine4_unittest.cc", 2480, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2481 | 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, "alloc_engine4_unittest.cc", 2481, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2482 | 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, "alloc_engine4_unittest.cc", 2482, gtest_ar .failure_message()) = ::testing::Message(); |
2483 | 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, "alloc_engine4_unittest.cc" , 2483, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true") .c_str()) = ::testing::Message(); |
2484 | |
2485 | // Do the same test. But, this time do not specify any address to be |
2486 | // allocated. |
2487 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2488 | IOAddress("0.0.0.0"), false, false, |
2489 | "", true); |
2490 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2491 | AllocEngine::findReservation(ctx2); |
2492 | allocated_lease = engine.allocateLease4(ctx2); |
2493 | |
2494 | 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, "alloc_engine4_unittest.cc", 2494, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2495 | 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, "alloc_engine4_unittest.cc", 2495, gtest_ar .failure_message()) = ::testing::Message(); |
2496 | 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, "alloc_engine4_unittest.cc" , 2496, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true") .c_str()) = ::testing::Message(); |
2497 | 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, "alloc_engine4_unittest.cc", 2497, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2498 | } |
2499 | |
2500 | // This test checks that the behavior of the allocation engine in the following |
2501 | // scenario: |
2502 | // - Client has a reservation. |
2503 | // - Client has a lease in the database for a different address than reserved. |
2504 | // - Client sends a DHCPREQUEST and asks for a different address than reserved, |
2505 | // and different than it has in a database. |
2506 | // - Server doesn't allocate the reserved address to the client because the |
2507 | // client asked for the different address. |
2508 | // |
2509 | // Note that in this case the client should get the DHCPNAK and should fall back |
2510 | // to the DHCPDISCOVER. |
2511 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseInvalidHint", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 2511), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2511), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 2511), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test ::TestBody() { |
2512 | // Create a reservation for the client. |
2513 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2514 | Host::IDENT_HWADDR, subnet_->getID(), |
2515 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2516 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2517 | CfgMgr::instance().commit(); |
2518 | |
2519 | // Create a lease for the client for a different address than reserved. |
2520 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, ClientIdPtr(), |
2521 | 100, time(NULL__null), subnet_->getID(), |
2522 | false, false, "")); |
2523 | LeaseMgrFactory::instance().addLease(lease); |
2524 | |
2525 | AllocEngine engine(0); |
2526 | |
2527 | // Try to allocate a lease and specify a different address than reserved |
2528 | // and different from the one that client is currently using. |
2529 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2530 | IOAddress("192.0.2.102"), false, false, |
2531 | "", false); |
2532 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2533 | AllocEngine::findReservation(ctx1); |
2534 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2535 | 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, "alloc_engine4_unittest.cc", 2535, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2536 | 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, "alloc_engine4_unittest.cc", 2536, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2537 | |
2538 | 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 , "alloc_engine4_unittest.cc", 2538, gtest_ar.failure_message ()) = ::testing::Message(); |
2539 | 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, "alloc_engine4_unittest.cc", 2539, gtest_ar .failure_message()) = ::testing::Message(); |
2540 | 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 , "alloc_engine4_unittest.cc", 2540, gtest_ar.failure_message ()) = ::testing::Message(); |
2541 | 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 , "alloc_engine4_unittest.cc", 2541, gtest_ar.failure_message ()) = ::testing::Message(); |
2542 | 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 , "alloc_engine4_unittest.cc", 2542, gtest_ar.failure_message ()) = ::testing::Message(); |
2543 | |
2544 | 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, "alloc_engine4_unittest.cc", 2544, gtest_ar .failure_message()) = ::testing::Message(); |
2545 | 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, "alloc_engine4_unittest.cc" , 2545, gtest_ar.failure_message()) = ::testing::Message(); |
2546 | 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, "alloc_engine4_unittest.cc", 2546, gtest_ar .failure_message()) = ::testing::Message(); |
2547 | 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, "alloc_engine4_unittest.cc" , 2547, gtest_ar.failure_message()) = ::testing::Message(); |
2548 | 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, "alloc_engine4_unittest.cc" , 2548, gtest_ar.failure_message()) = ::testing::Message(); |
2549 | |
2550 | // Repeat the test, but this time ask for the address that the client |
2551 | // has allocated. |
2552 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2553 | IOAddress("192.0.2.101"), false, false, |
2554 | "", false); |
2555 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2556 | AllocEngine::findReservation(ctx2); |
2557 | allocated_lease = engine.allocateLease4(ctx2); |
2558 | // The client has reservation so the server wants to allocate a |
2559 | // reserved address and doesn't want to renew the address that the |
2560 | // client is currently using. This is equivalent of the case when |
2561 | // the client tries to renew the lease but there is a new reservation |
2562 | // for this client. The server doesn't allow for the renewal and |
2563 | // responds with DHCPNAK to force the client to return to the |
2564 | // DHCP server discovery. |
2565 | 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, "alloc_engine4_unittest.cc", 2565, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2566 | 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, "alloc_engine4_unittest.cc", 2566, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2567 | |
2568 | 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 , "alloc_engine4_unittest.cc", 2568, gtest_ar.failure_message ()) = ::testing::Message(); |
2569 | 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, "alloc_engine4_unittest.cc", 2569, gtest_ar .failure_message()) = ::testing::Message(); |
2570 | 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 , "alloc_engine4_unittest.cc", 2570, gtest_ar.failure_message ()) = ::testing::Message(); |
2571 | 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 , "alloc_engine4_unittest.cc", 2571, gtest_ar.failure_message ()) = ::testing::Message(); |
2572 | 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 , "alloc_engine4_unittest.cc", 2572, gtest_ar.failure_message ()) = ::testing::Message(); |
2573 | |
2574 | 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, "alloc_engine4_unittest.cc", 2574, gtest_ar .failure_message()) = ::testing::Message(); |
2575 | 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, "alloc_engine4_unittest.cc" , 2575, gtest_ar.failure_message()) = ::testing::Message(); |
2576 | 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, "alloc_engine4_unittest.cc", 2576, gtest_ar .failure_message()) = ::testing::Message(); |
2577 | 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, "alloc_engine4_unittest.cc" , 2577, gtest_ar.failure_message()) = ::testing::Message(); |
2578 | 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, "alloc_engine4_unittest.cc" , 2578, gtest_ar.failure_message()) = ::testing::Message(); |
2579 | } |
2580 | |
2581 | // This test checks that the behavior of the allocation engine in the following |
2582 | // scenario: |
2583 | // - Client has a lease in the database. |
2584 | // - Client has a reservation for a different address than the one for which it |
2585 | // has a lease. |
2586 | // - Client sends a DHCPDISCOVER and asks for a different address than reserved |
2587 | // and different from which it has a lease for. |
2588 | // - Server ignores the client's hint and offers a reserved address. |
2589 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseFakeAllocation", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 2589), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2589), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 2589), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test ::TestBody() { |
2590 | // Create a reservation for the client. |
2591 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2592 | Host::IDENT_HWADDR, subnet_->getID(), |
2593 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2594 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2595 | CfgMgr::instance().commit(); |
2596 | |
2597 | // Create a lease for a different address than reserved. |
2598 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2599 | &clientid_->getClientId()[0], |
2600 | clientid_->getClientId().size(), |
2601 | 100, time(NULL__null), subnet_->getID(), |
2602 | false, false, "")); |
2603 | LeaseMgrFactory::instance().addLease(lease); |
2604 | |
2605 | AllocEngine engine(0); |
2606 | |
2607 | // Try to allocate a lease and use a completely different address |
2608 | // as a hint. |
2609 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2610 | IOAddress("192.0.2.102"), false, false, |
2611 | "", true); |
2612 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2613 | AllocEngine::findReservation(ctx1); |
2614 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2615 | |
2616 | // Server should offer a lease for a reserved address. |
2617 | 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, "alloc_engine4_unittest.cc", 2617, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2618 | 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, "alloc_engine4_unittest.cc" , 2618, gtest_ar.failure_message()) = ::testing::Message(); |
2619 | |
2620 | // The lease should not be allocated until the client sends a DHCPREQUEST. |
2621 | 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 , "alloc_engine4_unittest.cc", 2621, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false") .c_str()) = ::testing::Message(); |
2622 | |
2623 | // Old lease should contain the currently used lease. |
2624 | 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, "alloc_engine4_unittest.cc", 2624, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
2625 | 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, "alloc_engine4_unittest.cc" , 2625, gtest_ar.failure_message()) = ::testing::Message(); |
2626 | |
2627 | // Repeat the test but this time ask for the address for which the |
2628 | // client has a lease. |
2629 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2630 | IOAddress("192.0.2.101"), false, false, |
2631 | "", true); |
2632 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2633 | AllocEngine::findReservation(ctx2); |
2634 | allocated_lease = engine.allocateLease4(ctx2); |
2635 | |
2636 | // The server should offer the lease, but not for the address that |
2637 | // the client requested. The server should offer a reserved address. |
2638 | 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, "alloc_engine4_unittest.cc", 2638, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2639 | 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, "alloc_engine4_unittest.cc" , 2639, gtest_ar.failure_message()) = ::testing::Message(); |
2640 | |
2641 | // Old lease should contain the currently used lease. |
2642 | 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, "alloc_engine4_unittest.cc", 2642, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
2643 | 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, "alloc_engine4_unittest.cc" , 2643, gtest_ar.failure_message()) = ::testing::Message(); |
2644 | } |
2645 | |
2646 | // This test checks that the behavior of the allocation engine in the following |
2647 | // scenario: |
2648 | // - Client has a reservation. |
2649 | // - Client has a lease for a different address than reserved. |
2650 | // - Client sends a DHCPREQUEST to allocate a lease. |
2651 | // - The server determines that the client has a reservation for the |
2652 | // different address than it is currently using and should assign |
2653 | // a reserved address and remove the previous lease. |
2654 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseNoHint", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2654), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2654), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2654), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test ::TestBody() { |
2655 | // Create a reservation. |
2656 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2657 | Host::IDENT_HWADDR, subnet_->getID(), |
2658 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2659 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2660 | CfgMgr::instance().commit(); |
2661 | |
2662 | // Create a lease for a different address than reserved. |
2663 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2664 | &clientid_->getClientId()[0], |
2665 | clientid_->getClientId().size(), |
2666 | 100, time(NULL__null), subnet_->getID(), |
2667 | false, false, "")); |
2668 | LeaseMgrFactory::instance().addLease(lease); |
2669 | |
2670 | AllocEngine engine(0); |
2671 | |
2672 | // Try to allocate a lease with providing no hint. |
2673 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2674 | IOAddress("0.0.0.0"), false, false, |
2675 | "", false); |
2676 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2677 | AllocEngine::findReservation(ctx); |
2678 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2679 | |
2680 | // The reserved address should be allocated. |
2681 | 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, "alloc_engine4_unittest.cc", 2681, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2682 | 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, "alloc_engine4_unittest.cc" , 2682, gtest_ar.failure_message()) = ::testing::Message(); |
2683 | |
2684 | // The previous lease should be removed. |
2685 | 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, "alloc_engine4_unittest.cc" , 2685, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
2686 | |
2687 | // Make sure that the allocated lease is committed in the lease database. |
2688 | Lease4Ptr from_mgr = |
2689 | LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
2690 | 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, "alloc_engine4_unittest.cc", 2690, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2691 | detailCompareLease(allocated_lease, from_mgr); |
2692 | |
2693 | // Old lease should be returned. |
2694 | 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, "alloc_engine4_unittest.cc", 2694, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
2695 | detailCompareLease(lease, ctx.old_lease_); |
2696 | } |
2697 | |
2698 | // This test checks that the behavior of the allocation engine in the following |
2699 | // scenario: |
2700 | // - Client has a reservation. |
2701 | // - Client has a lease for a different address than reserved. |
2702 | // - Client sends a DHCPDISCOVER with no hint. |
2703 | // - Server determines that there is a reservation for the client and that |
2704 | // the reserved address should be offered when the client sends a |
2705 | // DHCPDISCOVER. |
2706 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseNoHintFakeAllocation", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 2706), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2706), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 2706), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test ::TestBody() { |
2707 | // Create a reservation. |
2708 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2709 | Host::IDENT_HWADDR, subnet_->getID(), |
2710 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2711 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2712 | CfgMgr::instance().commit(); |
2713 | |
2714 | // Create a lease for a different address than reserved. |
2715 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2716 | &clientid_->getClientId()[0], |
2717 | clientid_->getClientId().size(), |
2718 | 100, time(NULL__null), subnet_->getID(), |
2719 | false, false, "")); |
2720 | LeaseMgrFactory::instance().addLease(lease); |
2721 | |
2722 | AllocEngine engine(0); |
2723 | |
2724 | // Query the allocation engine for the lease to be allocated for the |
2725 | // client. |
2726 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2727 | IOAddress("0.0.0.0"), false, false, |
2728 | "", true); |
2729 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2730 | AllocEngine::findReservation(ctx); |
2731 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2732 | |
2733 | // The server should offer the reserved address. |
2734 | 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, "alloc_engine4_unittest.cc", 2734, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2735 | 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, "alloc_engine4_unittest.cc" , 2735, gtest_ar.failure_message()) = ::testing::Message(); |
2736 | |
2737 | // The lease should not be committed to the lease database until the |
2738 | // client sends a DHCPREQUEST. |
2739 | 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 , "alloc_engine4_unittest.cc", 2739, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false") .c_str()) = ::testing::Message(); |
2740 | |
2741 | // The old lease should reflect what is in the database. |
2742 | 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, "alloc_engine4_unittest.cc", 2742, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
2743 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2744 | 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, "alloc_engine4_unittest.cc", 2744, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2745 | detailCompareLease(lease, from_mgr); |
2746 | } |
2747 | |
2748 | // This test checks that the behavior of the allocation engine in the following |
2749 | // scenario: |
2750 | // - Client A has a lease for the address. |
2751 | // - Client B has a reservation for the same address that the Client A is using. |
2752 | // - Client B requests allocation of the reserved address. |
2753 | // - Server returns DHCPNAK to the client to indicate that the requested address |
2754 | // can't be allocated. |
2755 | // - Client A renews the lease. |
2756 | // - Server determines that the lease that the Client A is trying to renew |
2757 | // is for the address reserved for Client B. Therefore, the server returns |
2758 | // DHCPNAK to force the client to return to the server discovery. |
2759 | // - The Client A sends DHCPDISCOVER. |
2760 | // - The server offers an address to the Client A, which is different than |
2761 | // the address reserved for Client B. |
2762 | // - The Client A requests allocation of the offered address. |
2763 | // - The server allocates the new address to Client A. |
2764 | // - The Client B sends DHCPDISCOVER to the server. |
2765 | // - The server offers a reserved address to the Client B. |
2766 | // - The Client B requests the offered address. |
2767 | // - The server allocates the reserved address to the Client B. |
2768 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressConflictResolution_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressConflictResolution", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2768), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2768), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2768), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressConflictResolution_Test >); void AllocEngine4Test_reservedAddressConflictResolution_Test ::TestBody() { |
2769 | // Create a reservation for client B. |
2770 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
2771 | Host::IDENT_HWADDR, subnet_->getID(), |
2772 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
2773 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2774 | CfgMgr::instance().commit(); |
2775 | |
2776 | // Create a lease for Client A. |
2777 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2778 | &clientid_->getClientId()[0], |
2779 | clientid_->getClientId().size(), |
2780 | 100, time(NULL__null), subnet_->getID(), |
2781 | false, false, "")); |
2782 | LeaseMgrFactory::instance().addLease(lease); |
2783 | |
2784 | AllocEngine engine(0); |
2785 | |
2786 | // Client B sends a DHCPREQUEST to allocate a reserved lease. The |
2787 | // allocation engine can't allocate a reserved lease for this client |
2788 | // because this specific address is in use by the Client A. |
2789 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr2_, |
2790 | IOAddress("192.0.2.101"), false, false, |
2791 | "", false); |
2792 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2793 | AllocEngine::findReservation(ctx1); |
2794 | Lease4Ptr offered_lease = engine.allocateLease4(ctx1); |
2795 | 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, "alloc_engine4_unittest.cc", 2795, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "offered_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2796 | |
2797 | 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 , "alloc_engine4_unittest.cc", 2797, gtest_ar.failure_message ()) = ::testing::Message(); |
2798 | 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, "alloc_engine4_unittest.cc", 2798, gtest_ar .failure_message()) = ::testing::Message(); |
2799 | 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 , "alloc_engine4_unittest.cc", 2799, gtest_ar.failure_message ()) = ::testing::Message(); |
2800 | 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 , "alloc_engine4_unittest.cc", 2800, gtest_ar.failure_message ()) = ::testing::Message(); |
2801 | 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 , "alloc_engine4_unittest.cc", 2801, gtest_ar.failure_message ()) = ::testing::Message(); |
2802 | |
2803 | 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, "alloc_engine4_unittest.cc", 2803, gtest_ar .failure_message()) = ::testing::Message(); |
2804 | 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, "alloc_engine4_unittest.cc" , 2804, gtest_ar.failure_message()) = ::testing::Message(); |
2805 | 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, "alloc_engine4_unittest.cc", 2805, gtest_ar .failure_message()) = ::testing::Message(); |
2806 | 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, "alloc_engine4_unittest.cc" , 2806, gtest_ar.failure_message()) = ::testing::Message(); |
2807 | 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, "alloc_engine4_unittest.cc" , 2807, gtest_ar.failure_message()) = ::testing::Message(); |
2808 | |
2809 | // Client A tries to renew the lease. The renewal should fail because |
2810 | // server detects that Client A doesn't have reservation for this |
2811 | // address. |
2812 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2813 | IOAddress("192.0.2.101"), false, false, |
2814 | "", false); |
2815 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2816 | AllocEngine::findReservation(ctx2); |
2817 | 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, "alloc_engine4_unittest.cc", 2817, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine.allocateLease4(ctx2)", "true", "false") .c_str()) = ::testing::Message(); |
2818 | 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, "alloc_engine4_unittest.cc", 2818, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
2819 | |
2820 | 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 , "alloc_engine4_unittest.cc", 2820, gtest_ar.failure_message ()) = ::testing::Message(); |
2821 | 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, "alloc_engine4_unittest.cc", 2821, gtest_ar .failure_message()) = ::testing::Message(); |
2822 | 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 , "alloc_engine4_unittest.cc", 2822, gtest_ar.failure_message ()) = ::testing::Message(); |
2823 | 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 , "alloc_engine4_unittest.cc", 2823, gtest_ar.failure_message ()) = ::testing::Message(); |
2824 | 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 , "alloc_engine4_unittest.cc", 2824, gtest_ar.failure_message ()) = ::testing::Message(); |
2825 | |
2826 | 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, "alloc_engine4_unittest.cc", 2826, gtest_ar .failure_message()) = ::testing::Message(); |
2827 | 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, "alloc_engine4_unittest.cc" , 2827, gtest_ar.failure_message()) = ::testing::Message(); |
2828 | 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, "alloc_engine4_unittest.cc", 2828, gtest_ar .failure_message()) = ::testing::Message(); |
2829 | 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, "alloc_engine4_unittest.cc" , 2829, gtest_ar.failure_message()) = ::testing::Message(); |
2830 | 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, "alloc_engine4_unittest.cc" , 2830, gtest_ar.failure_message()) = ::testing::Message(); |
2831 | |
2832 | // Client A returns to DHCPDISCOVER and should be offered a lease. |
2833 | // The offered lease address must be different than the one the |
2834 | // Client B has reservation for. |
2835 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
2836 | IOAddress("192.0.2.101"), false, false, |
2837 | "", true); |
2838 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2839 | AllocEngine::findReservation(ctx3); |
2840 | offered_lease = engine.allocateLease4(ctx3); |
2841 | 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, "alloc_engine4_unittest.cc", 2841, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "offered_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2842 | 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, "alloc_engine4_unittest.cc", 2842, gtest_ar .failure_message()) = ::testing::Message(); |
2843 | |
2844 | // Client A tries to acquire the lease. It should succeed. At this point |
2845 | // the previous lease should be released and become available for the |
2846 | // Client B. |
2847 | AllocEngine::ClientContext4 ctx4(subnet_, clientid_, hwaddr_, |
2848 | offered_lease->addr_, false, false, |
2849 | "", false); |
2850 | ctx4.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2851 | AllocEngine::findReservation(ctx4); |
2852 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx4); |
2853 | |
2854 | 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, "alloc_engine4_unittest.cc", 2854, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2855 | 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, "alloc_engine4_unittest.cc", 2855, gtest_ar .failure_message()) = ::testing::Message(); |
2856 | |
2857 | // Client B tries to get the lease again. It should be offered |
2858 | // a reserved lease. |
2859 | AllocEngine::ClientContext4 ctx5(subnet_, ClientIdPtr(), hwaddr2_, |
2860 | IOAddress("0.0.0.0"), false, false, |
2861 | "", true); |
2862 | ctx5.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2863 | AllocEngine::findReservation(ctx5); |
2864 | offered_lease = engine.allocateLease4(ctx5); |
2865 | |
2866 | 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, "alloc_engine4_unittest.cc", 2866, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "offered_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2867 | 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, "alloc_engine4_unittest.cc" , 2867, gtest_ar.failure_message()) = ::testing::Message(); |
2868 | |
2869 | // Client B requests allocation of the lease and it should succeed. |
2870 | AllocEngine::ClientContext4 ctx6(subnet_, ClientIdPtr(), hwaddr2_, |
2871 | offered_lease->addr_, false, false, |
2872 | "", false); |
2873 | ctx6.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2874 | allocated_lease = engine.allocateLease4(ctx6); |
2875 | |
2876 | 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, "alloc_engine4_unittest.cc", 2876, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2877 | 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, "alloc_engine4_unittest.cc" , 2877, gtest_ar.failure_message()) = ::testing::Message(); |
2878 | } |
2879 | |
2880 | // This test checks that the address is not assigned from the dynamic |
2881 | // pool if it has been reserved for another client. |
2882 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressVsDynamicPool_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressVsDynamicPool", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2882), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2882), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2882), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressVsDynamicPool_Test >); void AllocEngine4Test_reservedAddressVsDynamicPool_Test ::TestBody() { |
2883 | // Create a reservation for the client. |
2884 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2885 | Host::IDENT_HWADDR, subnet_->getID(), |
2886 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
2887 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2888 | CfgMgr::instance().commit(); |
2889 | |
2890 | AllocEngine engine(0); |
2891 | |
2892 | // Different client tries to allocate a lease. Note, that we're using |
2893 | // an iterative allocator which would pick the first address from the |
2894 | // dynamic pool, i.e. 192.0.2.100. This address is reserved so we expect |
2895 | // that a different address will be allocated. |
2896 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
2897 | IOAddress("0.0.0.0"), false, false, |
2898 | "", false); |
2899 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2900 | AllocEngine::findReservation(ctx); |
2901 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2902 | |
2903 | 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, "alloc_engine4_unittest.cc", 2903, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2904 | 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, "alloc_engine4_unittest.cc", 2904, gtest_ar .failure_message()) = ::testing::Message(); |
2905 | |
2906 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
2907 | 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, "alloc_engine4_unittest.cc", 2907, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
2908 | detailCompareLease(allocated_lease, from_mgr); |
2909 | } |
2910 | |
2911 | // This test checks that the client requesting an address which is |
2912 | // reserved for another client will get no lease or a different |
2913 | // address will be assigned if the client is sending a DHCPDISCOVER. |
2914 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHintUsedByOtherClient", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 2914 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2914), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2914), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test >); void AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test ::TestBody() { |
2915 | // Create a reservation for the client. |
2916 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2917 | Host::IDENT_HWADDR, subnet_->getID(), |
2918 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
2919 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2920 | CfgMgr::instance().commit(); |
2921 | |
2922 | AllocEngine engine(0); |
2923 | |
2924 | // Different client is requesting this address. |
2925 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
2926 | IOAddress("192.0.2.100"), false, false, |
2927 | "", false); |
2928 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2929 | AllocEngine::findReservation(ctx1); |
2930 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2931 | |
2932 | // The client should get no lease (DHCPNAK). |
2933 | 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, "alloc_engine4_unittest.cc", 2933, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2934 | |
2935 | 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 , "alloc_engine4_unittest.cc", 2935, gtest_ar.failure_message ()) = ::testing::Message(); |
2936 | 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, "alloc_engine4_unittest.cc", 2936, gtest_ar .failure_message()) = ::testing::Message(); |
2937 | 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 , "alloc_engine4_unittest.cc", 2937, gtest_ar.failure_message ()) = ::testing::Message(); |
2938 | 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 , "alloc_engine4_unittest.cc", 2938, gtest_ar.failure_message ()) = ::testing::Message(); |
2939 | 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 , "alloc_engine4_unittest.cc", 2939, gtest_ar.failure_message ()) = ::testing::Message(); |
2940 | |
2941 | 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, "alloc_engine4_unittest.cc", 2941, gtest_ar .failure_message()) = ::testing::Message(); |
2942 | 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, "alloc_engine4_unittest.cc" , 2942, gtest_ar.failure_message()) = ::testing::Message(); |
2943 | 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, "alloc_engine4_unittest.cc", 2943, gtest_ar .failure_message()) = ::testing::Message(); |
2944 | 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, "alloc_engine4_unittest.cc" , 2944, gtest_ar.failure_message()) = ::testing::Message(); |
2945 | 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, "alloc_engine4_unittest.cc" , 2945, gtest_ar.failure_message()) = ::testing::Message(); |
2946 | |
2947 | // The same client should get a different lease than requested if |
2948 | // if is sending a DHCPDISCOVER (fake allocation is true). |
2949 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
2950 | IOAddress("192.0.2.100"), false, false, |
2951 | "", true); |
2952 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2953 | AllocEngine::findReservation(ctx2); |
2954 | allocated_lease = engine.allocateLease4(ctx2); |
2955 | |
2956 | 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, "alloc_engine4_unittest.cc", 2956, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
2957 | // Make sure the lease obtained is for a different address. |
2958 | 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, "alloc_engine4_unittest.cc", 2958, gtest_ar .failure_message()) = ::testing::Message(); |
2959 | } |
2960 | |
2961 | // This test checks that the allocation engine refuses to allocate an |
2962 | // address when the pool is exhausted, and the only available |
2963 | // address is reserved for a different client. |
2964 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressShortPool_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressShortPool", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2964), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2964), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2964), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressShortPool_Test >); void AllocEngine4Test_reservedAddressShortPool_Test::TestBody () { |
2965 | AllocEngine engine(0); |
2966 | |
2967 | // Create short pool with only one address. |
2968 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
2969 | // Reserve the address for a different client. |
2970 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
2971 | Host::IDENT_HWADDR, subnet_->getID(), |
2972 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
2973 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2974 | CfgMgr::instance().commit(); |
2975 | |
2976 | // Allocation engine should determine that the available address is |
2977 | // reserved for someone else and not allocate it. |
2978 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
2979 | IOAddress("0.0.0.0"), false, false, |
2980 | "", false); |
2981 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2982 | AllocEngine::findReservation(ctx1); |
2983 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2984 | |
2985 | 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, "alloc_engine4_unittest.cc", 2985, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false") .c_str()) = ::testing::Message(); |
2986 | |
2987 | 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 , "alloc_engine4_unittest.cc", 2987, gtest_ar.failure_message ()) = ::testing::Message(); |
2988 | 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, "alloc_engine4_unittest.cc", 2988, gtest_ar .failure_message()) = ::testing::Message(); |
2989 | 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 , "alloc_engine4_unittest.cc", 2989, gtest_ar.failure_message ()) = ::testing::Message(); |
2990 | 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 , "alloc_engine4_unittest.cc", 2990, gtest_ar.failure_message ()) = ::testing::Message(); |
2991 | 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 , "alloc_engine4_unittest.cc", 2991, gtest_ar.failure_message ()) = ::testing::Message(); |
2992 | |
2993 | 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, "alloc_engine4_unittest.cc", 2993, gtest_ar .failure_message()) = ::testing::Message(); |
2994 | 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, "alloc_engine4_unittest.cc" , 2994, gtest_ar.failure_message()) = ::testing::Message(); |
2995 | 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, "alloc_engine4_unittest.cc", 2995, gtest_ar .failure_message()) = ::testing::Message(); |
2996 | 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, "alloc_engine4_unittest.cc" , 2996, gtest_ar.failure_message()) = ::testing::Message(); |
2997 | 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, "alloc_engine4_unittest.cc" , 2997, gtest_ar.failure_message()) = ::testing::Message(); |
2998 | |
2999 | // Now, let's remove the reservation. |
3000 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
3001 | CfgMgr::instance().commit(); |
3002 | |
3003 | // Address should be successfully allocated. |
3004 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
3005 | IOAddress("0.0.0.0"), false, false, |
3006 | "", false); |
3007 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3008 | AllocEngine::findReservation(ctx2); |
3009 | allocated_lease = engine.allocateLease4(ctx2); |
3010 | |
3011 | 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, "alloc_engine4_unittest.cc", 3011, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
3012 | 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, "alloc_engine4_unittest.cc" , 3012, gtest_ar.failure_message()) = ::testing::Message(); |
3013 | } |
3014 | |
3015 | // This test checks that the AllocEngine allocates an address from the |
3016 | // dynamic pool if the client's reservation is made for a hostname but |
3017 | // not for an address. |
3018 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_reservedHostname_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedHostname", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 3018), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3018), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3018), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedHostname_Test >); void AllocEngine4Test_reservedHostname_Test::TestBody( ) { |
3019 | AllocEngine engine(0); |
3020 | |
3021 | // Create a reservation for a hostname. Address is set to 0 which |
3022 | // indicates that there is no reservation. |
3023 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3024 | Host::IDENT_HWADDR, subnet_->getID(), |
3025 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
3026 | "foo.example.org")); |
3027 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3028 | CfgMgr::instance().commit(); |
3029 | |
3030 | // Try to allocate a lease. |
3031 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
3032 | IOAddress("192.0.2.109"), false, false, |
3033 | "foo.example.org", true); |
3034 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3035 | AllocEngine::findReservation(ctx); |
3036 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
3037 | 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, "alloc_engine4_unittest.cc", 3037, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
3038 | 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, "alloc_engine4_unittest.cc" , 3038, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease->addr_.isV4Zero()", "true", "false") .c_str ()) = ::testing::Message(); |
3039 | 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, "alloc_engine4_unittest.cc" , 3039, gtest_ar.failure_message()) = ::testing::Message(); |
3040 | |
3041 | ctx.requested_address_ = allocated_lease->addr_; |
3042 | ctx.fake_allocation_ = false; |
3043 | allocated_lease = engine.allocateLease4(ctx); |
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, "alloc_engine4_unittest.cc", 3044, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
3045 | 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, "alloc_engine4_unittest.cc" , 3045, gtest_ar.failure_message()) = ::testing::Message(); |
3046 | } |
3047 | |
3048 | // This test checks that the AllocEngine::findReservation method finds |
3049 | // and returns host reservation for the DHCPv4 client using the data from |
3050 | // the client context. If the host reservation can't be found, it sets |
3051 | // the value of NULL in the host_ field of the client context. |
3052 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_findReservation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "findReservation", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 3052), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 3052), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3052 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_findReservation_Test >); void AllocEngine4Test_findReservation_Test::TestBody() { |
3053 | // Create the instance of the allocation engine. |
3054 | AllocEngine engine(0); |
3055 | |
3056 | // Context is required to call the AllocEngine::findReservation. |
3057 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3058 | IOAddress("0.0.0.0"), false, false, |
3059 | "", false); |
3060 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3061 | ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_); |
3062 | ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getClientId()); |
3063 | |
3064 | // There is no reservation in the database so no host should be returned. |
3065 | 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_3065 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3065 ; } } else gtest_label_testnothrow_3065 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3065, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3066 | 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, "alloc_engine4_unittest.cc", 3066, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false") .c_str()) = ::testing::Message(); |
3067 | |
3068 | // Create a reservation for the client. |
3069 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3070 | Host::IDENT_HWADDR, subnet_->getID(), |
3071 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
3072 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3073 | CfgMgr::instance().commit(); |
3074 | |
3075 | // This time the reservation should be returned. |
3076 | ctx.hosts_.clear(); |
3077 | 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_3077 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3077 ; } } else gtest_label_testnothrow_3077 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3077, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3078 | 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, "alloc_engine4_unittest.cc", 3078, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3079 | 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, "alloc_engine4_unittest.cc" , 3079, gtest_ar.failure_message()) = ::testing::Message(); |
3080 | |
3081 | // It shouldn't be returned when reservations-in-subnet is disabled. |
3082 | subnet_->setReservationsInSubnet(false); |
3083 | ctx.hosts_.clear(); |
3084 | 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_3084 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3084 ; } } else gtest_label_testnothrow_3084 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3084, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3085 | 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, "alloc_engine4_unittest.cc", 3085, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false") .c_str()) = ::testing::Message(); |
3086 | |
3087 | // Check the reservations-in-subnet and reservations-out-of-pool flags. |
3088 | subnet_->setReservationsInSubnet(true); |
3089 | subnet_->setReservationsOutOfPool(true); |
3090 | ctx.hosts_.clear(); |
3091 | 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_3091 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3091 ; } } else gtest_label_testnothrow_3091 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3091, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3092 | 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, "alloc_engine4_unittest.cc", 3092, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3093 | 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, "alloc_engine4_unittest.cc" , 3093, gtest_ar.failure_message()) = ::testing::Message(); |
3094 | |
3095 | // This time use the client identifier to search for the host. |
3096 | host.reset(new Host(&clientid_->getClientId()[0], |
3097 | clientid_->getClientId().size(), |
3098 | Host::IDENT_DUID, subnet_->getID(), |
3099 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
3100 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3101 | CfgMgr::instance().commit(); |
3102 | |
3103 | ctx.hosts_.clear(); |
3104 | 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_3104 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3104 ; } } else gtest_label_testnothrow_3104 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3104, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3105 | 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, "alloc_engine4_unittest.cc", 3105, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3106 | 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, "alloc_engine4_unittest.cc" , 3106, gtest_ar.failure_message()) = ::testing::Message(); |
3107 | |
3108 | // Remove the subnet. Subnet id is required to find host reservations, so |
3109 | // if it is set to NULL, no reservation should be returned |
3110 | ctx.subnet_.reset(); |
3111 | ctx.hosts_.clear(); |
3112 | 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_3112 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3112 ; } } else gtest_label_testnothrow_3112 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3112, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3113 | 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, "alloc_engine4_unittest.cc", 3113, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false") .c_str()) = ::testing::Message(); |
3114 | |
3115 | // The same if there is a mismatch of the subnet id between the reservation |
3116 | // and the context. |
3117 | ctx.subnet_ = subnet_; |
3118 | host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3119 | Host::IDENT_HWADDR, subnet_->getID() + 1, |
3120 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
3121 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3122 | CfgMgr::instance().commit(); |
3123 | |
3124 | ctx.hosts_.clear(); |
3125 | 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_3125 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3125 ; } } else gtest_label_testnothrow_3125 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3125, ("Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3126 | 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, "alloc_engine4_unittest.cc", 3126, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false") .c_str()) = ::testing::Message(); |
3127 | } |
3128 | |
3129 | // This test checks if the simple IPv4 allocation can succeed and that |
3130 | // statistic for allocated addresses is increased appropriately. |
3131 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_simpleAlloc4Stats_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "simpleAlloc4Stats", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 3131), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3131), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3131), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4Stats_Test >); void AllocEngine4Test_simpleAlloc4Stats_Test::TestBody () { |
3132 | boost::scoped_ptr<AllocEngine> engine; |
3133 | 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_3133 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3133 ; } } else gtest_label_testnothrow_3133 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3133, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3134 | 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, "alloc_engine4_unittest.cc", 3134, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
3135 | |
3136 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
3137 | false, true, "somehost.example.com.", false); |
3138 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3139 | |
3140 | // Let's pretend 100 addresses were allocated already |
3141 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
3142 | "assigned-addresses"); |
3143 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
3144 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
3145 | subnet_->getID()); |
3146 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
3147 | |
3148 | Lease4Ptr lease = engine->allocateLease4(ctx); |
3149 | // The new lease has been allocated, so the old lease should not exist. |
3150 | 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, "alloc_engine4_unittest.cc", 3150, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3151 | |
3152 | // Check that we got a lease |
3153 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3153, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3154 | |
3155 | // The statistic should be there and it should be increased by 1 (to 101). |
3156 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
3157 | 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 , "alloc_engine4_unittest.cc", 3157, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "stat", "false", "true") .c_str()) = ::testing:: Message(); |
3158 | 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, "alloc_engine4_unittest.cc" , 3158, gtest_ar.failure_message()) = ::testing::Message(); |
3159 | cumulative += 1; |
3160 | 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, "alloc_engine4_unittest.cc" , 3161, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
3161 | 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, "alloc_engine4_unittest.cc" , 3161, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
3162 | glbl_cumulative += 1; |
3163 | 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, "alloc_engine4_unittest.cc" , 3163, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
3164 | } |
3165 | |
3166 | // This test checks if the fake allocation (for DHCPDISCOVER) can succeed |
3167 | // and that it doesn't increase allocated-addresses statistic. |
3168 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_fakeAlloc4Stat_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fakeAlloc4Stat", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 3168), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 3168), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3168 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4Stat_Test >); void AllocEngine4Test_fakeAlloc4Stat_Test::TestBody() { |
3169 | boost::scoped_ptr<AllocEngine> engine; |
3170 | 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_3170 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3170 ; } } else gtest_label_testnothrow_3170 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3170, ("Expected: " "engine.reset(new AllocEngine(100))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3171 | 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, "alloc_engine4_unittest.cc", 3171, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
3172 | |
3173 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3174 | IOAddress("0.0.0.0"), false, true, |
3175 | "host.example.com.", true); |
3176 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3177 | |
3178 | // Let's pretend 100 addresses were allocated already |
3179 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
3180 | "assigned-addresses"); |
3181 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
3182 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
3183 | subnet_->getID()); |
3184 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
3185 | |
3186 | Lease4Ptr lease = engine->allocateLease4(ctx); |
3187 | |
3188 | // The new lease has been allocated, so the old lease should not exist. |
3189 | 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, "alloc_engine4_unittest.cc", 3189, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3190 | |
3191 | // Check that we got a lease |
3192 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3192, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3193 | |
3194 | // The statistic should be there and it should not be increased |
3195 | // (should be still equal to 100). |
3196 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
3197 | 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 , "alloc_engine4_unittest.cc", 3197, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "stat", "false", "true") .c_str()) = ::testing:: Message(); |
3198 | 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, "alloc_engine4_unittest.cc" , 3198, gtest_ar.failure_message()) = ::testing::Message(); |
3199 | 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, "alloc_engine4_unittest.cc" , 3200, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
3200 | 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, "alloc_engine4_unittest.cc" , 3200, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message(); |
3201 | 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, "alloc_engine4_unittest.cc" , 3201, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
3202 | } |
3203 | |
3204 | // This test checks that the allocated-addresses statistic is decreased when |
3205 | // the client has a lease and a reservation for a different address is |
3206 | // available. |
3207 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseStat_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseStat", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 3207), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3207), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3207), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseStat_Test >); void AllocEngine4Test_reservedAddressExistingLeaseStat_Test ::TestBody() { |
3208 | // Create the reservation for the client. |
3209 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3210 | Host::IDENT_HWADDR, subnet_->getID(), |
3211 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
3212 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3213 | CfgMgr::instance().commit(); |
3214 | |
3215 | // Create a lease for the client with a different address than the reserved |
3216 | // one. |
3217 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
3218 | &clientid_->getClientId()[0], |
3219 | clientid_->getClientId().size(), |
3220 | 100, time(NULL__null), subnet_->getID(), |
3221 | false, false, "")); |
3222 | LeaseMgrFactory::instance().addLease(lease); |
3223 | |
3224 | AllocEngine engine(100); |
3225 | |
3226 | // Let's pretend 100 addresses were allocated already |
3227 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
3228 | "assigned-addresses"); |
3229 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
3230 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
3231 | subnet_->getID()); |
3232 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
3233 | |
3234 | // Request allocation of the reserved address. |
3235 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3236 | IOAddress("192.0.2.123"), false, false, |
3237 | "", false); |
3238 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3239 | AllocEngine::findReservation(ctx); |
3240 | |
3241 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
3242 | |
3243 | ASSERT_TRUE(allocated_lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(allocated_lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3243, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true") .c_str()) = ::testing::Message(); |
3244 | |
3245 | // The statistic should be still at 100. Note that it was decreased |
3246 | // (because old lease was removed), but also increased (because the |
3247 | // new lease was immediately allocated). |
3248 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
3249 | 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 , "alloc_engine4_unittest.cc", 3249, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "stat", "false", "true") .c_str()) = ::testing:: Message(); |
3250 | 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, "alloc_engine4_unittest.cc" , 3250, gtest_ar.failure_message()) = ::testing::Message(); |
3251 | cumulative += 1; |
3252 | 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, "alloc_engine4_unittest.cc" , 3253, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true") .c_str()) = ::testing::Message() |
3253 | 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, "alloc_engine4_unittest.cc" , 3253, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "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, "alloc_engine4_unittest.cc" , 3255, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true") .c_str()) = ::testing::Message(); |
3256 | |
3257 | // Lets' double check that the actual allocation took place. |
3258 | 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, "alloc_engine4_unittest.cc", 3258, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.fake_allocation_" , "true", "false") .c_str()) = ::testing::Message(); |
3259 | } |
3260 | |
3261 | // This test checks the behavior of the allocation engine in the following |
3262 | // scenario: |
3263 | // - Client has no lease in the database. |
3264 | // - Client has a global reservation outside of the subnet. |
3265 | // - Client sends DISCOVER |
3266 | // - Client is allocated an address within the subnet. |
3267 | // - Lease is not added to the lease database |
3268 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedNonMatchingAddressDiscover", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3268), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3268), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3268), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test ::TestBody() { |
3269 | // Create reservation for the client. |
3270 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3271 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3272 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3273 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3274 | CfgMgr::instance().commit(); |
3275 | |
3276 | AllocEngine engine(0); |
3277 | |
3278 | subnet_->setReservationsGlobal(true); |
3279 | |
3280 | // Query allocation engine for the lease to be assigned to this |
3281 | // client without specifying the address to be assigned. |
3282 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3283 | IOAddress("0.0.0.0"), false, false, |
3284 | "", true); |
3285 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3286 | |
3287 | // Look up the host. |
3288 | AllocEngine::findReservation(ctx); |
3289 | |
3290 | // We should have the correct current host |
3291 | 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, "alloc_engine4_unittest.cc", 3291, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3292 | 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, "alloc_engine4_unittest.cc" , 3292, gtest_ar.failure_message()) = ::testing::Message(); |
3293 | 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, "alloc_engine4_unittest.cc" , 3293, gtest_ar.failure_message()) = ::testing::Message(); |
3294 | |
3295 | // We should allocate an address in the subnet |
3296 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3297 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3297, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3298 | 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, "alloc_engine4_unittest.cc" , 3298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
3299 | |
3300 | // This is a "fake" allocation so the returned lease should not be committed |
3301 | // to the lease database. |
3302 | 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, "alloc_engine4_unittest.cc" , 3302, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
3303 | |
3304 | // Client had no lease in the database, so the old lease returned should |
3305 | // be NULL. |
3306 | 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, "alloc_engine4_unittest.cc", 3306, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3307 | } |
3308 | |
3309 | // This test checks the behavior of the allocation engine in the following |
3310 | // scenario: |
3311 | // - Client has no lease in the database. |
3312 | // - Client has a global reservation matching the current subnet. |
3313 | // - Client sends DISCOVER |
3314 | // - Client is allocated the reserved address. |
3315 | // - Lease is not added to the lease database |
3316 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedMatchingAddressDiscover", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3316), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3316), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3316), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test ::TestBody() { |
3317 | // Create reservation for the client. |
3318 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3319 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3320 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
3321 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3322 | CfgMgr::instance().commit(); |
3323 | |
3324 | AllocEngine engine(0); |
3325 | |
3326 | subnet_->setReservationsGlobal(true); |
3327 | |
3328 | // Query allocation engine for the lease to be assigned to this |
3329 | // client without specifying the address to be assigned. |
3330 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3331 | IOAddress("0.0.0.0"), false, false, |
3332 | "", true); |
3333 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3334 | |
3335 | // Look up the host. |
3336 | AllocEngine::findReservation(ctx); |
3337 | |
3338 | // We should have the correct current host |
3339 | 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, "alloc_engine4_unittest.cc", 3339, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3340 | 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, "alloc_engine4_unittest.cc" , 3340, gtest_ar.failure_message()) = ::testing::Message(); |
3341 | 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, "alloc_engine4_unittest.cc" , 3341, gtest_ar.failure_message()) = ::testing::Message(); |
3342 | |
3343 | // We should allocate the reserved address. |
3344 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3345 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3345, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3346 | 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, "alloc_engine4_unittest.cc", 3346, gtest_ar .failure_message()) = ::testing::Message(); |
3347 | |
3348 | // This is a "fake" allocation so the returned lease should not be committed |
3349 | // to the lease database. |
3350 | 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, "alloc_engine4_unittest.cc" , 3350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
3351 | |
3352 | // Client had no lease in the database, so the old lease returned should |
3353 | // be NULL. |
3354 | 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, "alloc_engine4_unittest.cc", 3354, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3355 | } |
3356 | |
3357 | // This test checks the behavior of the allocation engine in the following |
3358 | // scenario: |
3359 | // - Client has no lease in the database. |
3360 | // - Client has a global reservation outside the current subnet. |
3361 | // - Client sends REQUEST |
3362 | // - Client is allocated a dynamic address. |
3363 | // - Lease is added to the lease database |
3364 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedNonMatchingAddressRequest", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3364), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3364), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3364), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test ::TestBody() { |
3365 | // Create reservation for the client. |
3366 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3367 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3368 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3369 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3370 | CfgMgr::instance().commit(); |
3371 | |
3372 | AllocEngine engine(0); |
3373 | |
3374 | subnet_->setReservationsGlobal(true); |
3375 | |
3376 | // Query allocation engine for the lease to be assigned to this |
3377 | // client without specifying the address to be assigned. |
3378 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3379 | IOAddress("0.0.0.0"), false, false, |
3380 | "", false); |
3381 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3382 | |
3383 | // Look up the host. |
3384 | AllocEngine::findReservation(ctx); |
3385 | |
3386 | // We should have the correct current host |
3387 | 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, "alloc_engine4_unittest.cc", 3387, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3388 | 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, "alloc_engine4_unittest.cc" , 3388, gtest_ar.failure_message()) = ::testing::Message(); |
3389 | 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, "alloc_engine4_unittest.cc" , 3389, gtest_ar.failure_message()) = ::testing::Message(); |
3390 | |
3391 | // We should allocate the reserved address. |
3392 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3393 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3393, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3394 | 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, "alloc_engine4_unittest.cc" , 3394, gtest_ar.failure_message()) = ::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, "alloc_engine4_unittest.cc" , 3395, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
3396 | |
3397 | // Check that the lease is indeed in LeaseMgr |
3398 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3399 | 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, "alloc_engine4_unittest.cc", 3399, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
3400 | |
3401 | // Now check that the lease in LeaseMgr has the same parameters |
3402 | detailCompareLease(lease, from_mgr); |
3403 | |
3404 | // Client had no lease in the database, so the old lease returned should |
3405 | // be NULL. |
3406 | 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, "alloc_engine4_unittest.cc", 3406, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3407 | } |
3408 | |
3409 | // This test checks the behavior of the allocation engine in the following |
3410 | // scenario: |
3411 | // - Client has no lease in the database. |
3412 | // - Client has a global reservation matching the current subnet. |
3413 | // - Client sends REQUEST |
3414 | // - Client is allocated the reserved address. |
3415 | // - Lease is added to the lease database |
3416 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedMatchingAddressRequest", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3416), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3416), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3416), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test ::TestBody() { |
3417 | // Create reservation for the client. |
3418 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3419 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3420 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
3421 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3422 | CfgMgr::instance().commit(); |
3423 | |
3424 | AllocEngine engine(0); |
3425 | |
3426 | subnet_->setReservationsGlobal(true); |
3427 | |
3428 | // Query allocation engine for the lease to be assigned to this |
3429 | // client without specifying the address to be assigned. |
3430 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3431 | IOAddress("0.0.0.0"), false, false, |
3432 | "", false); |
3433 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3434 | |
3435 | // Look up the host. |
3436 | AllocEngine::findReservation(ctx); |
3437 | |
3438 | // We should have the correct current host |
3439 | 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, "alloc_engine4_unittest.cc", 3439, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3440 | 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, "alloc_engine4_unittest.cc" , 3440, gtest_ar.failure_message()) = ::testing::Message(); |
3441 | 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, "alloc_engine4_unittest.cc" , 3441, gtest_ar.failure_message()) = ::testing::Message(); |
3442 | |
3443 | // We should allocate the reserved address. |
3444 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3445 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3445, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3446 | 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, "alloc_engine4_unittest.cc", 3446, gtest_ar .failure_message()) = ::testing::Message(); |
3447 | |
3448 | // Check that the lease is indeed in LeaseMgr |
3449 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3450 | 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, "alloc_engine4_unittest.cc", 3450, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
3451 | |
3452 | // Now check that the lease in LeaseMgr has the same parameters |
3453 | detailCompareLease(lease, from_mgr); |
3454 | |
3455 | // Client had no lease in the database, so the old lease returned should |
3456 | // be NULL. |
3457 | 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, "alloc_engine4_unittest.cc", 3457, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3458 | } |
3459 | |
3460 | // This test checks the behavior of the allocation engine in the following |
3461 | // scenario: |
3462 | // - Client has no lease in the database. |
3463 | // - Client has a global reservation. |
3464 | // - Client sends DISCOVER |
3465 | // - Client is allocated a dynamic address from matched subnet |
3466 | // - Lease is not added to the lease database |
3467 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_globalReservationDynamicDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationDynamicDiscover", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 3467), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3467), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3467), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_globalReservationDynamicDiscover_Test >); void AllocEngine4Test_globalReservationDynamicDiscover_Test ::TestBody() { |
3468 | // Create reservation for the client. |
3469 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3470 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3471 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
3472 | "foo.example.org")); |
3473 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3474 | CfgMgr::instance().commit(); |
3475 | |
3476 | AllocEngine engine(0); |
3477 | |
3478 | subnet_->setReservationsGlobal(true); |
3479 | |
3480 | // Query allocation engine for the lease to be assigned to this |
3481 | // client without specifying the address to be assigned. |
3482 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3483 | IOAddress("0.0.0.0"), false, false, |
3484 | "", true); |
3485 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3486 | |
3487 | // Look up the host. |
3488 | AllocEngine::findReservation(ctx); |
3489 | |
3490 | // We should have the correct current host |
3491 | 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, "alloc_engine4_unittest.cc", 3491, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3492 | 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, "alloc_engine4_unittest.cc" , 3492, gtest_ar.failure_message()) = ::testing::Message(); |
3493 | 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, "alloc_engine4_unittest.cc" , 3493, gtest_ar.failure_message()) = ::testing::Message(); |
3494 | |
3495 | // We should allocate a dynamic address. |
3496 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3497 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3497, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3498 | 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, "alloc_engine4_unittest.cc" , 3498, gtest_ar.failure_message()) = ::testing::Message(); |
3499 | |
3500 | // This is a "fake" allocation so the returned lease should not be committed |
3501 | // to the lease database. |
3502 | 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, "alloc_engine4_unittest.cc" , 3502, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
3503 | |
3504 | // Client had no lease in the database, so the old lease returned should |
3505 | // be NULL. |
3506 | 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, "alloc_engine4_unittest.cc", 3506, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3507 | } |
3508 | |
3509 | // This test checks the behavior of the allocation engine in the following |
3510 | // scenario: |
3511 | // - Client has no lease in the database. |
3512 | // - Client has a global reservation. |
3513 | // - Client sends REQUEST |
3514 | // - Client is allocated a dynamic address from matched subnet |
3515 | // - Lease is added to the lease database |
3516 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_globalReservationDynamicRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationDynamicRequest", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 3516), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3516), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3516), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_globalReservationDynamicRequest_Test >); void AllocEngine4Test_globalReservationDynamicRequest_Test ::TestBody() { |
3517 | // Create reservation for the client. |
3518 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3519 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3520 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
3521 | "foo.example.org")); |
3522 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3523 | CfgMgr::instance().commit(); |
3524 | |
3525 | AllocEngine engine(0); |
3526 | |
3527 | subnet_->setReservationsGlobal(true); |
3528 | |
3529 | // Query allocation engine for the lease to be assigned to this |
3530 | // client without specifying the address to be assigned. |
3531 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3532 | IOAddress("0.0.0.0"), false, false, |
3533 | "", false); |
3534 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3535 | |
3536 | // Look up the host. |
3537 | AllocEngine::findReservation(ctx); |
3538 | |
3539 | // We should have the correct current host |
3540 | 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, "alloc_engine4_unittest.cc", 3540, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3541 | 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, "alloc_engine4_unittest.cc" , 3541, gtest_ar.failure_message()) = ::testing::Message(); |
3542 | 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, "alloc_engine4_unittest.cc" , 3542, gtest_ar.failure_message()) = ::testing::Message(); |
3543 | |
3544 | // We should allocate a dynamic address. |
3545 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3546 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3546, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3547 | 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, "alloc_engine4_unittest.cc" , 3547, gtest_ar.failure_message()) = ::testing::Message(); |
3548 | |
3549 | // Check that the lease is indeed in LeaseMgr |
3550 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3551 | 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, "alloc_engine4_unittest.cc", 3551, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
3552 | |
3553 | // Now check that the lease in LeaseMgr has the same parameters |
3554 | detailCompareLease(lease, from_mgr); |
3555 | |
3556 | // Client had no lease in the database, so the old lease returned should |
3557 | // be NULL. |
3558 | 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, "alloc_engine4_unittest.cc", 3558, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3559 | } |
3560 | |
3561 | // This test checks the behavior of the allocation engine in the following |
3562 | // scenario: |
3563 | // - Client has no lease in the database. |
3564 | // - Client has a subnet reservation. |
3565 | // - Client sends DISCOVER |
3566 | // - Client is allocated the reserved address. |
3567 | // - Lease is not added to the lease database |
3568 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_mixedReservationReservedAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "mixedReservationReservedAddressDiscover", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3568), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3568), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3568), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressDiscover_Test >); void AllocEngine4Test_mixedReservationReservedAddressDiscover_Test ::TestBody() { |
3569 | // Create reservation for the client. |
3570 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3571 | Host::IDENT_HWADDR, subnet_->getID(), |
3572 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
3573 | "foo.example.org")); |
3574 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3575 | CfgMgr::instance().commit(); |
3576 | |
3577 | AllocEngine engine(0); |
3578 | |
3579 | subnet_->setReservationsGlobal(true); |
3580 | subnet_->setReservationsInSubnet(true); |
3581 | |
3582 | // Query allocation engine for the lease to be assigned to this |
3583 | // client without specifying the address to be assigned. |
3584 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3585 | IOAddress("0.0.0.0"), false, false, |
3586 | "", true); |
3587 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3588 | |
3589 | // Look up the host. |
3590 | AllocEngine::findReservation(ctx); |
3591 | |
3592 | // We should have the correct current host |
3593 | 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, "alloc_engine4_unittest.cc", 3593, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3594 | 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, "alloc_engine4_unittest.cc" , 3594, gtest_ar.failure_message()) = ::testing::Message(); |
3595 | 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, "alloc_engine4_unittest.cc" , 3595, gtest_ar.failure_message()) = ::testing::Message(); |
3596 | |
3597 | // We should allocate the reserved address. |
3598 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3599 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3599, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3600 | 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, "alloc_engine4_unittest.cc" , 3600, gtest_ar.failure_message()) = ::testing::Message(); |
3601 | |
3602 | // This is a "fake" allocation so the returned lease should not be committed |
3603 | // to the lease database. |
3604 | 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, "alloc_engine4_unittest.cc" , 3604, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
3605 | |
3606 | // Client had no lease in the database, so the old lease returned should |
3607 | // be NULL. |
3608 | 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, "alloc_engine4_unittest.cc", 3608, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3609 | } |
3610 | |
3611 | // This test checks the behavior of the allocation engine in the following |
3612 | // scenario: |
3613 | // - Client has no lease in the database. |
3614 | // - Client has a subnet reservation. |
3615 | // - Client sends REQUEST |
3616 | // - Client is allocated the reserved address. |
3617 | // - Lease is added to the lease database |
3618 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_mixedReservationReservedAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "mixedReservationReservedAddressRequest", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3618), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3618), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3618), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressRequest_Test >); void AllocEngine4Test_mixedReservationReservedAddressRequest_Test ::TestBody() { |
3619 | // Create reservation for the client. |
3620 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3621 | Host::IDENT_HWADDR, subnet_->getID(), |
3622 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
3623 | "foo.example.org")); |
3624 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3625 | CfgMgr::instance().commit(); |
3626 | |
3627 | AllocEngine engine(0); |
3628 | |
3629 | subnet_->setReservationsGlobal(true); |
3630 | subnet_->setReservationsInSubnet(true); |
3631 | |
3632 | // Query allocation engine for the lease to be assigned to this |
3633 | // client without specifying the address to be assigned. |
3634 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3635 | IOAddress("0.0.0.0"), false, false, |
3636 | "", false); |
3637 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3638 | |
3639 | // Look up the host. |
3640 | AllocEngine::findReservation(ctx); |
3641 | |
3642 | // We should have the correct current host |
3643 | 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, "alloc_engine4_unittest.cc", 3643, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3644 | 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, "alloc_engine4_unittest.cc" , 3644, gtest_ar.failure_message()) = ::testing::Message(); |
3645 | 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, "alloc_engine4_unittest.cc" , 3645, gtest_ar.failure_message()) = ::testing::Message(); |
3646 | |
3647 | // We should allocate the reserved address. |
3648 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3649 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3649, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3650 | 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, "alloc_engine4_unittest.cc" , 3650, gtest_ar.failure_message()) = ::testing::Message(); |
3651 | |
3652 | // Check that the lease is indeed in LeaseMgr |
3653 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3654 | 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, "alloc_engine4_unittest.cc", 3654, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
3655 | |
3656 | // Now check that the lease in LeaseMgr has the same parameters |
3657 | detailCompareLease(lease, from_mgr); |
3658 | |
3659 | // Client had no lease in the database, so the old lease returned should |
3660 | // be NULL. |
3661 | 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, "alloc_engine4_unittest.cc", 3661, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3662 | } |
3663 | |
3664 | // This test checks the behavior of the allocation engine in the following |
3665 | // scenario: |
3666 | // - Client has no lease in the database. |
3667 | // - Client has a global and a subnet reservation. |
3668 | // - Client sends DISCOVER |
3669 | // - Client is allocated the reserved address. |
3670 | // - Lease is not added to the lease database |
3671 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_bothReservationReservedAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bothReservationReservedAddressDiscover", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3671), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3671), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3671), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressDiscover_Test >); void AllocEngine4Test_bothReservationReservedAddressDiscover_Test ::TestBody() { |
3672 | // Create reservations for the client. |
3673 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3674 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3675 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3676 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
3677 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3678 | Host::IDENT_HWADDR, subnet_->getID(), |
3679 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
3680 | "foo.example.org")); |
3681 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3682 | CfgMgr::instance().commit(); |
3683 | |
3684 | AllocEngine engine(0); |
3685 | |
3686 | subnet_->setReservationsGlobal(true); |
3687 | subnet_->setReservationsInSubnet(true); |
3688 | |
3689 | // Query allocation engine for the lease to be assigned to this |
3690 | // client without specifying the address to be assigned. |
3691 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3692 | IOAddress("0.0.0.0"), false, false, |
3693 | "", true); |
3694 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3695 | |
3696 | // Look up the host. |
3697 | AllocEngine::findReservation(ctx); |
3698 | |
3699 | // We should have the correct current host |
3700 | 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, "alloc_engine4_unittest.cc", 3700, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3701 | 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, "alloc_engine4_unittest.cc" , 3701, gtest_ar.failure_message()) = ::testing::Message(); |
3702 | 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, "alloc_engine4_unittest.cc" , 3702, gtest_ar.failure_message()) = ::testing::Message(); |
3703 | |
3704 | // We should allocate the reserved address. |
3705 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3706 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3706, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3707 | 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, "alloc_engine4_unittest.cc" , 3707, gtest_ar.failure_message()) = ::testing::Message(); |
3708 | |
3709 | // This is a "fake" allocation so the returned lease should not be committed |
3710 | // to the lease database. |
3711 | 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, "alloc_engine4_unittest.cc" , 3711, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false") .c_str()) = ::testing::Message(); |
3712 | |
3713 | // Client had no lease in the database, so the old lease returned should |
3714 | // be NULL. |
3715 | 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, "alloc_engine4_unittest.cc", 3715, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3716 | } |
3717 | |
3718 | // This test checks the behavior of the allocation engine in the following |
3719 | // scenario: |
3720 | // - Client has no lease in the database. |
3721 | // - Client has a global and a subnet reservation. |
3722 | // - Client sends REQUEST |
3723 | // - Client is allocated the reserved address. |
3724 | // - Lease is added to the lease database |
3725 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_bothReservationReservedAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bothReservationReservedAddressRequest", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 3725 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3725), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3725), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressRequest_Test >); void AllocEngine4Test_bothReservationReservedAddressRequest_Test ::TestBody() { |
3726 | // Create reservations for the client. |
3727 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3728 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3729 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3730 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
3731 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3732 | Host::IDENT_HWADDR, subnet_->getID(), |
3733 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
3734 | "foo.example.org")); |
3735 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3736 | CfgMgr::instance().commit(); |
3737 | |
3738 | AllocEngine engine(0); |
3739 | |
3740 | subnet_->setReservationsGlobal(true); |
3741 | subnet_->setReservationsInSubnet(true); |
3742 | |
3743 | // Query allocation engine for the lease to be assigned to this |
3744 | // client without specifying the address to be assigned. |
3745 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3746 | IOAddress("0.0.0.0"), false, false, |
3747 | "", false); |
3748 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3749 | |
3750 | // Look up the host. |
3751 | AllocEngine::findReservation(ctx); |
3752 | |
3753 | // We should have the correct current host |
3754 | 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, "alloc_engine4_unittest.cc", 3754, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true") .c_str()) = ::testing::Message(); |
3755 | 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, "alloc_engine4_unittest.cc" , 3755, gtest_ar.failure_message()) = ::testing::Message(); |
3756 | 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, "alloc_engine4_unittest.cc" , 3756, gtest_ar.failure_message()) = ::testing::Message(); |
3757 | |
3758 | // We should allocate the reserved address. |
3759 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3760 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3760, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3761 | 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, "alloc_engine4_unittest.cc" , 3761, gtest_ar.failure_message()) = ::testing::Message(); |
3762 | |
3763 | // Check that the lease is indeed in LeaseMgr |
3764 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3765 | 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, "alloc_engine4_unittest.cc", 3765, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
3766 | |
3767 | // Now check that the lease in LeaseMgr has the same parameters |
3768 | detailCompareLease(lease, from_mgr); |
3769 | |
3770 | // Client had no lease in the database, so the old lease returned should |
3771 | // be NULL. |
3772 | 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, "alloc_engine4_unittest.cc", 3772, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
3773 | } |
3774 | |
3775 | // Exercises AllocEnginer4Test::updateExtendedInfo4() through various |
3776 | // permutations of client packet content. |
3777 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_updateExtendedInfo4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "updateExtendedInfo4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 3777), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3777), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3777), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_updateExtendedInfo4_Test >); void AllocEngine4Test_updateExtendedInfo4_Test::TestBody () { |
3778 | |
3779 | // Structure that defines a test scenario. |
3780 | struct Scenario { |
3781 | std::string description_; // test description |
3782 | std::string orig_context_json_; // user context the lease begins with |
3783 | std::string rai_data_; // RAI option the client packet contains |
3784 | std::string exp_context_json_; // expected user context on the lease |
3785 | bool exp_ret; // expected returned value |
3786 | }; |
3787 | |
3788 | // Test scenarios. |
3789 | std::vector<Scenario> scenarios { |
3790 | { |
3791 | "no context, no rai", |
3792 | "", |
3793 | "", |
3794 | "", |
3795 | false |
3796 | }, |
3797 | { |
3798 | "some original context, no rai", |
3799 | "{\"foo\": 123}", |
3800 | "", |
3801 | "{\"foo\": 123}", |
3802 | false |
3803 | }, |
3804 | { |
3805 | "no original context, rai", |
3806 | "", |
3807 | "0x52060104aabbccdd", |
3808 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3809 | " \"0x0104AABBCCDD\" } } }", |
3810 | true |
3811 | }, |
3812 | { |
3813 | "no original context, rai, remote and relay ids", |
3814 | "", |
3815 | "0x520a02030102030c03aabbcc", |
3816 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3817 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
3818 | " \"relay-id\": \"AABBCC\" } } }", |
3819 | true |
3820 | }, |
3821 | { |
3822 | "some original context, rai", |
3823 | "{\"foo\": 123, \"ISC\":{\"bar\": 456}}", |
3824 | "0x52060104aabbccdd", |
3825 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3826 | " \"0x0104AABBCCDD\" }, \"bar\": 456 }, \"foo\": 123 }", |
3827 | true |
3828 | }, |
3829 | { |
3830 | "bad original context, rai", |
3831 | "[\"foo\"]", |
3832 | "0x52060104aabbccdd", |
3833 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3834 | " \"0x0104AABBCCDD\" } } }", |
3835 | true |
3836 | }, |
3837 | { |
3838 | "some original context with bad isc entry, rai", |
3839 | "{\"foo\": 123, \"ISC\":[\"bar\"]}", |
3840 | "0x52060104aabbccdd", |
3841 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3842 | " \"0x0104AABBCCDD\" } }, \"foo\": 123 }", |
3843 | true |
3844 | }, |
3845 | { |
3846 | "some original context, rai, remote and relay ids", |
3847 | "{\"foo\": 123, \"ISC\":{ \"bar\": 456}}", |
3848 | "0x520a02030102030c03aabbcc", |
3849 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3850 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
3851 | " \"relay-id\": \"AABBCC\" }, \"bar\": 456 }, \"foo\": 123 }", |
3852 | true |
3853 | }, |
3854 | { |
3855 | "original rai context, no rai", |
3856 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3857 | " \"0x0104AABBCCDD\" } } }", |
3858 | "", |
3859 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3860 | " \"0x0104AABBCCDD\" } } }", |
3861 | false |
3862 | }, |
3863 | { |
3864 | "original rai context, different rai", |
3865 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3866 | " \"0x0104AABBCCDD\" } } }", |
3867 | "0x52060104ddeeffaa", |
3868 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3869 | " \"0x0104DDEEFFAA\" } } }", |
3870 | true |
3871 | }, |
3872 | { |
3873 | "original rai context, different rai, remote and relay ids", |
3874 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3875 | " \"0x0104AABBCCDD\" } } }", |
3876 | "0x520a02030102030c03aabbcc", |
3877 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3878 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
3879 | " \"relay-id\": \"AABBCC\" } } }", |
3880 | true |
3881 | }}; |
3882 | |
3883 | // Create the allocation engine, context and lease. |
3884 | NakedAllocEngine engine(0); |
3885 | |
3886 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3887 | IOAddress::IPV4_ZERO_ADDRESS(), |
3888 | false, false, "", true); |
3889 | |
3890 | // All scenarios require storage to be enabled. |
3891 | subnet_->setStoreExtendedInfo(true); |
3892 | |
3893 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3894 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3895 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3895, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3896 | 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, "alloc_engine4_unittest.cc" , 3896, gtest_ar.failure_message()) = ::testing::Message(); |
3897 | |
3898 | // Verify that the lease begins with no user context. |
3899 | ConstElementPtr user_context = lease->getContext(); |
3900 | 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, "alloc_engine4_unittest.cc", 3900, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "true", "false") .c_str()) = ::testing::Message(); |
3901 | |
3902 | // Iterate over the test scenarios. |
3903 | ElementPtr orig_context; |
3904 | ElementPtr exp_context; |
3905 | for (auto const& scenario : scenarios) { |
3906 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_3906( "alloc_engine4_unittest.cc" , 3906, (scenario.description_)); |
3907 | |
3908 | // Create the original user context from JSON. |
3909 | if (scenario.orig_context_json_.empty()) { |
3910 | orig_context.reset(); |
3911 | } else { |
3912 | 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_3912; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3912 ; } } else gtest_label_testnothrow_3912 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3912, ("Expected: " "orig_context = Element::fromJSON(scenario.orig_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
3913 | << "invalid orig_context_json_, test is broken"; |
3914 | } |
3915 | |
3916 | // Create the expected user context from JSON. |
3917 | if (scenario.exp_context_json_.empty()) { |
3918 | exp_context.reset(); |
3919 | } else { |
3920 | 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_3920; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3920 ; } } else gtest_label_testnothrow_3920 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3920, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
3921 | << "invalid exp_context_json_, test is broken"; |
3922 | } |
3923 | |
3924 | // Initialize lease's user context. |
3925 | lease->setContext(orig_context); |
3926 | if (!orig_context) { |
3927 | 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, "alloc_engine4_unittest.cc", 3927, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
3928 | } else { |
3929 | 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, "alloc_engine4_unittest.cc", 3929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
3930 | 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, "alloc_engine4_unittest.cc" , 3930, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "orig_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message(); |
3931 | } |
3932 | |
3933 | // Create the client packet and the add RAI option (if one). |
3934 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3935 | if (!scenario.rai_data_.empty()) { |
3936 | std::vector<uint8_t> opt_data; |
3937 | 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_3937; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3937 ; } } else gtest_label_testnothrow_3937 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3937, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
3938 | << "scenario.rai_data_ is invalid, test is broken"; |
3939 | const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF(); |
3940 | 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, "alloc_engine4_unittest.cc" , 3940, gtest_ar.failure_message()) = ::testing::Message(); |
3941 | 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, "alloc_engine4_unittest.cc", 3941, gtest_ar. failure_message()) = ::testing::Message(); |
3942 | 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, "alloc_engine4_unittest.cc", 3942, gtest_ar. failure_message()) = ::testing::Message(); |
3943 | std::vector<uint8_t> rai_data(opt_data.cbegin() + 2, |
3944 | opt_data.cend()); |
3945 | OptionCustomPtr rai; |
3946 | 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_3947; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3947; } } else gtest_label_testnothrow_3947 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3947, ("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() |
3947 | 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_3947; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3947; } } else gtest_label_testnothrow_3947 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3947, ("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() |
3948 | << "could not create rai option, test is broken"; |
3949 | ctx.query_->addOption(rai); |
3950 | } |
3951 | |
3952 | // Call AllocEngine::updateLease4ExtendeInfo(). |
3953 | bool ret = false; |
3954 | 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 , "alloc_engine4_unittest.cc", 3954, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "alloc_engine4_unittest.cc", 3954, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
3955 | 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, "alloc_engine4_unittest.cc" , 3955, gtest_ar.failure_message()) = ::testing::Message(); |
3956 | |
3957 | // Verify the lease has the expected user context content. |
3958 | if (!exp_context) { |
3959 | 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, "alloc_engine4_unittest.cc", 3959, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
3960 | } else { |
3961 | 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, "alloc_engine4_unittest.cc", 3961, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
3962 | 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, "alloc_engine4_unittest.cc" , 3962, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message() |
3963 | << "expected: " << *(exp_context) << std::endl |
3964 | << " actual: " << *(lease->getContext()) << std::endl; |
3965 | } |
3966 | } |
3967 | } |
3968 | |
3969 | // Verifies that recovered stashed RAI is not saved in extended info. |
3970 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_stashAgentOptions_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "stashAgentOptions", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 3970), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3970), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3970), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_stashAgentOptions_Test >); void AllocEngine4Test_stashAgentOptions_Test::TestBody () { |
3971 | // Create the allocation engine, context and lease. |
3972 | NakedAllocEngine engine(0); |
3973 | |
3974 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3975 | IOAddress::IPV4_ZERO_ADDRESS(), |
3976 | false, false, "", true); |
3977 | subnet_->setStoreExtendedInfo(true); |
3978 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3979 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3980 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3980, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
3981 | 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, "alloc_engine4_unittest.cc" , 3981, gtest_ar.failure_message()) = ::testing::Message(); |
3982 | |
3983 | // Verify that the lease begins with no user context. |
3984 | ConstElementPtr user_context = lease->getContext(); |
3985 | 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, "alloc_engine4_unittest.cc", 3985, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "true", "false") .c_str()) = ::testing::Message(); |
3986 | |
3987 | // Add a RAI in the query. |
3988 | std::string rai_str = "0104aabbccdd"; |
3989 | std::vector<uint8_t> rai_data; |
3990 | 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_3990; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3990; } } else gtest_label_testnothrow_3990 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3990, ("Expected: " "util::str::decodeFormattedHexString(rai_str, rai_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
3991 | const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF(); |
3992 | OptionCustomPtr rai; |
3993 | 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_3993; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3993; } } else gtest_label_testnothrow_3993 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3993, ("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(); |
3994 | ctx.query_->addOption(rai); |
3995 | |
3996 | // Verifies that the RAI is saved into lease extended info. |
3997 | bool ret = false; |
3998 | 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 , "alloc_engine4_unittest.cc", 3998, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "alloc_engine4_unittest.cc", 3998, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
3999 | EXPECT_TRUE(ret)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ret)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "alloc_engine4_unittest.cc", 3999, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "ret", "false", "true") .c_str()) = ::testing::Message (); |
4000 | user_context = lease->getContext(); |
4001 | 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, "alloc_engine4_unittest.cc", 4001, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "false", "true") .c_str()) = ::testing::Message(); |
4002 | lease->setContext(ElementPtr()); |
4003 | |
4004 | // Set stash-agent-options to true. |
4005 | CfgMgr::instance().getStagingCfg()-> |
4006 | addConfiguredGlobal("stash-agent-options", Element::create(true)); |
4007 | CfgMgr::instance().commit(); |
4008 | |
4009 | // Verifies that the RAI is saved into lease extended info. |
4010 | ret = false; |
Value stored to 'ret' is never read | |
4011 | 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 , "alloc_engine4_unittest.cc", 4011, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "alloc_engine4_unittest.cc", 4011, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
4012 | EXPECT_TRUE(ret)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ret)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "alloc_engine4_unittest.cc", 4012, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "ret", "false", "true") .c_str()) = ::testing::Message (); |
4013 | user_context = lease->getContext(); |
4014 | 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, "alloc_engine4_unittest.cc", 4014, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "false", "true") .c_str()) = ::testing::Message(); |
4015 | lease->setContext(ElementPtr()); |
4016 | |
4017 | // Put the query in the STASH_AGENT_OPTIONS class. |
4018 | ctx.query_->addClass("STASH_AGENT_OPTIONS"); |
4019 | |
4020 | // Verifies that the RAI is not saved into lease extended info. |
4021 | ret = false; |
4022 | 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 , "alloc_engine4_unittest.cc", 4022, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "alloc_engine4_unittest.cc", 4022, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
4023 | EXPECT_FALSE(ret)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(ret))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "alloc_engine4_unittest.cc", 4023, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "ret", "true", "false") .c_str()) = ::testing::Message (); |
4024 | user_context = lease->getContext(); |
4025 | 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, "alloc_engine4_unittest.cc", 4025, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "true", "false") .c_str()) = ::testing::Message(); |
4026 | } |
4027 | |
4028 | // Verifies that the extended data (e.g. RAI option for now) is |
4029 | // added to a V4 lease when leases are created and/or renewed, |
4030 | // when store-extended-info is true. |
4031 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_storeExtendedInfoEnabled4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "storeExtendedInfoEnabled4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4031), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4031), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4031), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoEnabled4_Test >); void AllocEngine4Test_storeExtendedInfoEnabled4_Test:: TestBody() { |
4032 | |
4033 | // Structure that defines a test scenario. |
4034 | struct Scenario { |
4035 | std::string description_; // test description |
4036 | std::vector<uint8_t> mac_; // MAC address |
4037 | std::string rai_data_; // RAI option the client packet contains |
4038 | std::string exp_context_json_; // expected user context on the lease |
4039 | std::string exp_address_; // expected lease address |
4040 | }; |
4041 | |
4042 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
4043 | std::string mac1_addr = "192.0.2.100"; |
4044 | |
4045 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
4046 | std::string mac2_addr = "192.0.2.101"; |
4047 | |
4048 | // Test scenarios. |
4049 | std::vector<Scenario> scenarios { |
4050 | { |
4051 | "create client one without rai", |
4052 | mac1, |
4053 | "", |
4054 | "", |
4055 | mac1_addr |
4056 | }, |
4057 | { |
4058 | "renew client one without rai", |
4059 | {}, |
4060 | "", |
4061 | "", |
4062 | mac1_addr |
4063 | }, |
4064 | { |
4065 | "create client two with rai", |
4066 | mac2, |
4067 | "0x52050104a1b1c1d1", |
4068 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
4069 | " \"0x52050104A1B1C1D1\" } } }", |
4070 | mac2_addr |
4071 | }, |
4072 | { |
4073 | "renew client two without rai", |
4074 | {}, |
4075 | "", |
4076 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
4077 | " \"0x52050104A1B1C1D1\" } } }", |
4078 | mac2_addr |
4079 | }}; |
4080 | |
4081 | // Create the allocation engine, context and lease. |
4082 | NakedAllocEngine engine(0); |
4083 | |
4084 | // All of the scenarios require storage to be enabled. |
4085 | subnet_->setStoreExtendedInfo(true); |
4086 | |
4087 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4088 | IOAddress::IPV4_ZERO_ADDRESS(), |
4089 | false, false, "", false); |
4090 | |
4091 | // Iterate over the test scenarios. |
4092 | for (auto const& scenario : scenarios) { |
4093 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4093( "alloc_engine4_unittest.cc" , 4093, (scenario.description_)); |
4094 | |
4095 | ElementPtr exp_context; |
4096 | // Create the expected user context from JSON. |
4097 | if (!scenario.exp_context_json_.empty()) { |
4098 | 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_4098; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4098 ; } } else gtest_label_testnothrow_4098 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4098, ("Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
4099 | << "invalid exp_context_json_, test is broken"; |
4100 | } |
4101 | |
4102 | // If we have a MAC address this scenario is for a new client. |
4103 | if (!scenario.mac_.empty()) { |
4104 | std::cout << "setting mac address" << std::endl; |
4105 | 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_4105; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4105; } } else gtest_label_testnothrow_4105 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4105, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message () |
4106 | << "invalid MAC address, test is broken"; |
4107 | } |
4108 | |
4109 | // Create the client packet and the add RAI option (if one). |
4110 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4111 | if (!scenario.rai_data_.empty()) { |
4112 | std::vector<uint8_t> opt_data; |
4113 | 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_4113; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4113 ; } } else gtest_label_testnothrow_4113 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4113, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
4114 | << "scenario.rai_data_ is invalid, test is broken"; |
4115 | OptionPtr rai; |
4116 | 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_4116; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4116; } } else gtest_label_testnothrow_4116 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4116, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message () |
4117 | << "could not create rai option, test is broken"; |
4118 | |
4119 | ctx.query_->addOption(rai); |
4120 | } |
4121 | |
4122 | // Create or renew the lease. |
4123 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4124 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4124, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4125 | 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, "alloc_engine4_unittest.cc" , 4125, gtest_ar.failure_message()) = ::testing::Message(); |
4126 | |
4127 | // Verify the lease has the expected user context content. |
4128 | if (!exp_context) { |
4129 | 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, "alloc_engine4_unittest.cc", 4129, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
4130 | } else { |
4131 | 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, "alloc_engine4_unittest.cc", 4131, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true") .c_str()) = ::testing ::Message(); |
4132 | 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, "alloc_engine4_unittest.cc" , 4132, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true") .c_str()) = ::testing::Message() |
4133 | << "expected: " << *(exp_context) << std::endl |
4134 | << " actual: " << *(lease->getContext()) << std::endl; |
4135 | } |
4136 | } |
4137 | } |
4138 | |
4139 | // Verifies that the extended data (e.g. RAI option for now) is |
4140 | // not added to a V4 lease when leases are created and/or renewed, |
4141 | // when store-extended-info is false. |
4142 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_storeExtendedInfoDisabled4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "storeExtendedInfoDisabled4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 4142), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4142), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4142), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoDisabled4_Test >); void AllocEngine4Test_storeExtendedInfoDisabled4_Test:: TestBody() { |
4143 | |
4144 | // Structure that defines a test scenario. |
4145 | struct Scenario { |
4146 | std::string description_; // test description |
4147 | std::vector<uint8_t> mac_; // MAC address |
4148 | std::string rai_data_; // RAI option the client packet contains |
4149 | std::string exp_address_; // expected lease address |
4150 | }; |
4151 | |
4152 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
4153 | std::string mac1_addr = "192.0.2.100"; |
4154 | |
4155 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
4156 | std::string mac2_addr = "192.0.2.101"; |
4157 | |
4158 | // Test scenarios. |
4159 | std::vector<Scenario> scenarios { |
4160 | { |
4161 | "create client one without rai", |
4162 | mac1, |
4163 | "", |
4164 | mac1_addr |
4165 | }, |
4166 | { |
4167 | "renew client one without rai", |
4168 | {}, |
4169 | "", |
4170 | mac1_addr |
4171 | }, |
4172 | { |
4173 | "create client two with rai", |
4174 | mac2, |
4175 | "0x52050104a1b1c1d1", |
4176 | mac2_addr |
4177 | }, |
4178 | { |
4179 | "renew client two with rai", |
4180 | {}, |
4181 | "0x52050104a1b1c1d1", |
4182 | mac2_addr |
4183 | }}; |
4184 | |
4185 | // Create the allocation engine, context and lease. |
4186 | NakedAllocEngine engine(0); |
4187 | |
4188 | // All of the scenarios require storage to be disabled. |
4189 | subnet_->setStoreExtendedInfo(false); |
4190 | |
4191 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4192 | IOAddress::IPV4_ZERO_ADDRESS(), |
4193 | false, false, "", false); |
4194 | |
4195 | // Iterate over the test scenarios. |
4196 | for (auto const& scenario : scenarios) { |
4197 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_4197( "alloc_engine4_unittest.cc" , 4197, (scenario.description_)); |
4198 | |
4199 | // If we have a MAC address this scenario is for a new client. |
4200 | if (!scenario.mac_.empty()) { |
4201 | std::cout << "setting mac address" << std::endl; |
4202 | 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_4202; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4202; } } else gtest_label_testnothrow_4202 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4202, ("Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message () |
4203 | << "invalid MAC address, test is broken"; |
4204 | } |
4205 | |
4206 | // Create the client packet and the add RAI option (if one). |
4207 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4208 | if (!scenario.rai_data_.empty()) { |
4209 | std::vector<uint8_t> opt_data; |
4210 | 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_4210; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4210 ; } } else gtest_label_testnothrow_4210 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4210, ("Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() |
4211 | << "scenario.rai_data_ is invalid, test is broken"; |
4212 | OptionPtr rai; |
4213 | 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_4213; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4213; } } else gtest_label_testnothrow_4213 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4213, ("Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message () |
4214 | << "could not create rai option, test is broken"; |
4215 | |
4216 | ctx.query_->addOption(rai); |
4217 | } |
4218 | |
4219 | // Create or renew the lease. |
4220 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4221 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4221, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4222 | 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, "alloc_engine4_unittest.cc" , 4222, gtest_ar.failure_message()) = ::testing::Message(); |
4223 | |
4224 | // Verify the lease does not have user context content. |
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, "alloc_engine4_unittest.cc", 4225, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false") .c_str()) = ::testing ::Message(); |
4226 | } |
4227 | } |
4228 | |
4229 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
4230 | // using cache threshold. |
4231 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheThreshold4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheThreshold4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4231), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4231), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4231), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheThreshold4_Test >); void AllocEngine4Test_discoverCacheThreshold4_Test::TestBody () { |
4232 | boost::scoped_ptr<AllocEngine> engine; |
4233 | 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_4233 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4233 ; } } else gtest_label_testnothrow_4233 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4233, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4234 | 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, "alloc_engine4_unittest.cc", 4234, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4235 | |
4236 | // Set valid lifetime to 500. |
4237 | uint32_t valid = 500; |
4238 | subnet_->setValid(valid); |
4239 | |
4240 | // Set the threshold to 25%. |
4241 | subnet_->setCacheThreshold(.25); |
4242 | |
4243 | IOAddress addr("192.0.2.105"); |
4244 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4245 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4246 | valid, now, subnet_->getID())); |
4247 | 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, "alloc_engine4_unittest.cc", 4247, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4248 | 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, "alloc_engine4_unittest.cc" , 4248, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
4249 | |
4250 | // Create a context for fake allocation. |
4251 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4252 | false, false, "", true); |
4253 | |
4254 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4255 | lease = engine->allocateLease4(ctx); |
4256 | // Check that we got that single lease. |
4257 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4257, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4258 | 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, "alloc_engine4_unittest.cc" , 4258, gtest_ar.failure_message()) = ::testing::Message(); |
4259 | |
4260 | // The lease was reused. |
4261 | time_t age = lease->cltt_ - now; |
4262 | 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, "alloc_engine4_unittest.cc" , 4262, gtest_ar.failure_message()) = ::testing::Message(); |
4263 | 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, "alloc_engine4_unittest.cc" , 4263, gtest_ar.failure_message()) = ::testing::Message(); |
4264 | 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, "alloc_engine4_unittest.cc", 4264, gtest_ar .failure_message()) = ::testing::Message(); |
4265 | |
4266 | // Check other lease parameters. |
4267 | 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, "alloc_engine4_unittest.cc", 4267, gtest_ar .failure_message()) = ::testing::Message(); |
4268 | 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, "alloc_engine4_unittest.cc", 4268 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
4269 | 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, "alloc_engine4_unittest.cc" , 4269, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
4270 | 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, "alloc_engine4_unittest.cc", 4270, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
4271 | 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, "alloc_engine4_unittest.cc" , 4271, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
4272 | } |
4273 | |
4274 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
4275 | // using cache threshold. |
4276 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestCacheThreshold4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheThreshold4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4276), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4276), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4276), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheThreshold4_Test >); void AllocEngine4Test_requestCacheThreshold4_Test::TestBody () { |
4277 | boost::scoped_ptr<AllocEngine> engine; |
4278 | 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_4278 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4278 ; } } else gtest_label_testnothrow_4278 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4278, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4279 | 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, "alloc_engine4_unittest.cc", 4279, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4280 | |
4281 | // Set valid lifetime to 500. |
4282 | uint32_t valid = 500; |
4283 | subnet_->setValid(valid); |
4284 | |
4285 | // Set the threshold to 25%. |
4286 | subnet_->setCacheThreshold(.25); |
4287 | |
4288 | IOAddress addr("192.0.2.105"); |
4289 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4290 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4291 | valid, now, subnet_->getID())); |
4292 | 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, "alloc_engine4_unittest.cc", 4292, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4293 | // Copy the lease, so as it can be compared with. |
4294 | Lease4Ptr original_lease(new Lease4(*lease)); |
4295 | 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, "alloc_engine4_unittest.cc" , 4295, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
4296 | |
4297 | // Create a context for real allocation. |
4298 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4299 | false, false, "", false); |
4300 | |
4301 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4302 | lease = engine->allocateLease4(ctx); |
4303 | // Check that we got that single lease. |
4304 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4304, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4305 | 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, "alloc_engine4_unittest.cc" , 4305, gtest_ar.failure_message()) = ::testing::Message(); |
4306 | |
4307 | // The lease was reused. |
4308 | time_t age = lease->cltt_ - now; |
4309 | 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, "alloc_engine4_unittest.cc" , 4309, gtest_ar.failure_message()) = ::testing::Message(); |
4310 | 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, "alloc_engine4_unittest.cc" , 4310, gtest_ar.failure_message()) = ::testing::Message(); |
4311 | 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, "alloc_engine4_unittest.cc", 4311, gtest_ar .failure_message()) = ::testing::Message(); |
4312 | |
4313 | // Check other lease parameters. |
4314 | 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, "alloc_engine4_unittest.cc", 4314, gtest_ar .failure_message()) = ::testing::Message(); |
4315 | 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, "alloc_engine4_unittest.cc", 4315 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
4316 | 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, "alloc_engine4_unittest.cc" , 4316, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
4317 | 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, "alloc_engine4_unittest.cc", 4317, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
4318 | 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, "alloc_engine4_unittest.cc" , 4318, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
4319 | |
4320 | // Check the lease was not updated in the database. |
4321 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4322 | 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, "alloc_engine4_unittest.cc", 4322, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
4323 | |
4324 | detailCompareLease(original_lease, from_mgr); |
4325 | } |
4326 | |
4327 | /// We proved that there is no different from the "cache" feature between |
4328 | /// discovers and request at the exception of the lease database update. |
4329 | |
4330 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
4331 | // using cache max age. |
4332 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheMaxAge4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheMaxAge4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4332), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4332), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4332), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheMaxAge4_Test >); void AllocEngine4Test_discoverCacheMaxAge4_Test::TestBody () { |
4333 | boost::scoped_ptr<AllocEngine> engine; |
4334 | 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_4334 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4334 ; } } else gtest_label_testnothrow_4334 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4334, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4335 | 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, "alloc_engine4_unittest.cc", 4335, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4336 | |
4337 | // Set valid lifetime to 500. |
4338 | uint32_t valid = 500; |
4339 | subnet_->setValid(valid); |
4340 | |
4341 | // Set the max age to 200. |
4342 | subnet_->setCacheMaxAge(200); |
4343 | |
4344 | IOAddress addr("192.0.2.105"); |
4345 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4346 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4347 | valid, now, subnet_->getID())); |
4348 | 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, "alloc_engine4_unittest.cc", 4348, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4349 | 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, "alloc_engine4_unittest.cc" , 4349, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
4350 | |
4351 | // Create a context for fake allocation. |
4352 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4353 | false, false, "", true); |
4354 | |
4355 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4356 | lease = engine->allocateLease4(ctx); |
4357 | // Check that we got that single lease. |
4358 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4358, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4359 | 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, "alloc_engine4_unittest.cc" , 4359, gtest_ar.failure_message()) = ::testing::Message(); |
4360 | |
4361 | // The lease was reused. |
4362 | time_t age = lease->cltt_ - now; |
4363 | 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, "alloc_engine4_unittest.cc" , 4363, gtest_ar.failure_message()) = ::testing::Message(); |
4364 | 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, "alloc_engine4_unittest.cc" , 4364, gtest_ar.failure_message()) = ::testing::Message(); |
4365 | 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, "alloc_engine4_unittest.cc", 4365, gtest_ar .failure_message()) = ::testing::Message(); |
4366 | |
4367 | // Check other lease parameters. |
4368 | 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, "alloc_engine4_unittest.cc", 4368, gtest_ar .failure_message()) = ::testing::Message(); |
4369 | 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, "alloc_engine4_unittest.cc", 4369 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
4370 | 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, "alloc_engine4_unittest.cc" , 4370, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
4371 | 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, "alloc_engine4_unittest.cc", 4371, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
4372 | 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, "alloc_engine4_unittest.cc" , 4372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
4373 | } |
4374 | |
4375 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
4376 | // using both cache threshold and max age. |
4377 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_requestCacheBoth4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheBoth4", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 4377), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4377), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4377), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBoth4_Test >); void AllocEngine4Test_requestCacheBoth4_Test::TestBody () { |
4378 | boost::scoped_ptr<AllocEngine> engine; |
4379 | 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_4379 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4379 ; } } else gtest_label_testnothrow_4379 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4379, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4380 | 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, "alloc_engine4_unittest.cc", 4380, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4381 | |
4382 | // Set valid lifetime to 500. |
4383 | uint32_t valid = 500; |
4384 | subnet_->setValid(valid); |
4385 | |
4386 | // Set the threshold to 25%. |
4387 | subnet_->setCacheThreshold(.25); |
4388 | |
4389 | // Set the max age to 200. |
4390 | subnet_->setCacheMaxAge(200); |
4391 | |
4392 | IOAddress addr("192.0.2.105"); |
4393 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4394 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4395 | valid, now, subnet_->getID())); |
4396 | 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, "alloc_engine4_unittest.cc", 4396, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4397 | // Copy the lease, so as it can be compared with. |
4398 | Lease4Ptr original_lease(new Lease4(*lease)); |
4399 | 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, "alloc_engine4_unittest.cc" , 4399, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
4400 | |
4401 | // Create a context for real allocation. |
4402 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4403 | false, false, "", false); |
4404 | |
4405 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4406 | lease = engine->allocateLease4(ctx); |
4407 | // Check that we got that single lease. |
4408 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4408, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4409 | 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, "alloc_engine4_unittest.cc" , 4409, gtest_ar.failure_message()) = ::testing::Message(); |
4410 | |
4411 | // The lease was reused. |
4412 | time_t age = lease->cltt_ - now; |
4413 | 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, "alloc_engine4_unittest.cc" , 4413, gtest_ar.failure_message()) = ::testing::Message(); |
4414 | 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, "alloc_engine4_unittest.cc" , 4414, gtest_ar.failure_message()) = ::testing::Message(); |
4415 | 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, "alloc_engine4_unittest.cc", 4415, gtest_ar .failure_message()) = ::testing::Message(); |
4416 | |
4417 | // Check other lease parameters. |
4418 | 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, "alloc_engine4_unittest.cc", 4418, gtest_ar .failure_message()) = ::testing::Message(); |
4419 | 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, "alloc_engine4_unittest.cc", 4419 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
4420 | 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, "alloc_engine4_unittest.cc" , 4420, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
4421 | 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, "alloc_engine4_unittest.cc", 4421, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
4422 | 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, "alloc_engine4_unittest.cc" , 4422, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
4423 | |
4424 | // Check the lease was not updated in the database. |
4425 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4426 | 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, "alloc_engine4_unittest.cc", 4426, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
4427 | |
4428 | detailCompareLease(original_lease, from_mgr); |
4429 | } |
4430 | |
4431 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
4432 | // using too small cache threshold. |
4433 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheBadThreshold4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheBadThreshold4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 4433), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4433), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4433), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheBadThreshold4_Test >); void AllocEngine4Test_discoverCacheBadThreshold4_Test:: TestBody() { |
4434 | boost::scoped_ptr<AllocEngine> engine; |
4435 | 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_4435 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4435 ; } } else gtest_label_testnothrow_4435 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4435, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4436 | 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, "alloc_engine4_unittest.cc", 4436, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4437 | |
4438 | // Set valid lifetime to 500. |
4439 | uint32_t valid = 500; |
4440 | subnet_->setValid(valid); |
4441 | |
4442 | // Set the threshold to 10%. |
4443 | subnet_->setCacheThreshold(.10); |
4444 | |
4445 | IOAddress addr("192.0.2.105"); |
4446 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4447 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4448 | valid, now, subnet_->getID())); |
4449 | 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, "alloc_engine4_unittest.cc", 4449, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4450 | 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, "alloc_engine4_unittest.cc" , 4450, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
4451 | |
4452 | // Create a context for fake allocation. |
4453 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4454 | false, false, "", true); |
4455 | |
4456 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4457 | lease = engine->allocateLease4(ctx); |
4458 | // Check that we got that single lease. |
4459 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4459, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4460 | 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, "alloc_engine4_unittest.cc" , 4460, gtest_ar.failure_message()) = ::testing::Message(); |
4461 | |
4462 | // The lease was not reused. |
4463 | 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, "alloc_engine4_unittest.cc" , 4463, gtest_ar.failure_message()) = ::testing::Message(); |
4464 | } |
4465 | |
4466 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
4467 | // using too small cache max age. |
4468 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestCacheBadMaxAge4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheBadMaxAge4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4468), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4468), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4468), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBadMaxAge4_Test >); void AllocEngine4Test_requestCacheBadMaxAge4_Test::TestBody () { |
4469 | boost::scoped_ptr<AllocEngine> engine; |
4470 | 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_4470 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4470 ; } } else gtest_label_testnothrow_4470 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4470, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4471 | 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, "alloc_engine4_unittest.cc", 4471, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4472 | |
4473 | // Set valid lifetime to 500. |
4474 | uint32_t valid = 500; |
4475 | subnet_->setValid(valid); |
4476 | |
4477 | // Set the threshold to 25%. |
4478 | subnet_->setCacheThreshold(.25); |
4479 | |
4480 | // Set the max age to 50. |
4481 | subnet_->setCacheMaxAge(50); |
4482 | |
4483 | IOAddress addr("192.0.2.105"); |
4484 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4485 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4486 | valid, now, subnet_->getID())); |
4487 | 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, "alloc_engine4_unittest.cc", 4487, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4488 | |
4489 | // Create a context for real allocation. |
4490 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4491 | false, false, "", false); |
4492 | |
4493 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4494 | lease = engine->allocateLease4(ctx); |
4495 | // Check that we got that single lease. |
4496 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4496, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4497 | EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_" , addr, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "alloc_engine4_unittest.cc" , 4497, gtest_ar.failure_message()) = ::testing::Message(); |
4498 | |
4499 | // The lease was not reused. |
4500 | 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, "alloc_engine4_unittest.cc" , 4500, gtest_ar.failure_message()) = ::testing::Message(); |
4501 | |
4502 | // Check the lease was updated in the database. |
4503 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4504 | 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, "alloc_engine4_unittest.cc", 4504, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
4505 | |
4506 | detailCompareLease(lease, from_mgr); |
4507 | } |
4508 | |
4509 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
4510 | // when the valid lifetime was reduced. |
4511 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheReducedValid4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheReducedValid4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 4511), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4511), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4511), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheReducedValid4_Test >); void AllocEngine4Test_discoverCacheReducedValid4_Test:: TestBody() { |
4512 | boost::scoped_ptr<AllocEngine> engine; |
4513 | 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_4513 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4513 ; } } else gtest_label_testnothrow_4513 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4513, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4514 | 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, "alloc_engine4_unittest.cc", 4514, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4515 | |
4516 | // Set valid lifetime to 200. |
4517 | subnet_->setValid(200); |
4518 | |
4519 | // Set the threshold to 25%. |
4520 | subnet_->setCacheThreshold(.25); |
4521 | |
4522 | IOAddress addr("192.0.2.105"); |
4523 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4524 | uint32_t valid = 500; // Used a value greater than subnet_->getValid(). |
4525 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4526 | valid, now, subnet_->getID())); |
4527 | 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, "alloc_engine4_unittest.cc", 4527, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4528 | 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, "alloc_engine4_unittest.cc" , 4528, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
4529 | |
4530 | // Create a context for fake allocation. |
4531 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4532 | false, false, "", true); |
4533 | |
4534 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4535 | lease = engine->allocateLease4(ctx); |
4536 | // Check that we got that single lease. |
4537 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4537, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4538 | 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, "alloc_engine4_unittest.cc" , 4538, gtest_ar.failure_message()) = ::testing::Message(); |
4539 | |
4540 | // The lease was not reused. |
4541 | 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, "alloc_engine4_unittest.cc" , 4541, gtest_ar.failure_message()) = ::testing::Message(); |
4542 | } |
4543 | |
4544 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
4545 | // when DDNS parameter changed. |
4546 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_requestCacheFwdDDNS4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheFwdDDNS4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4546), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4546), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4546), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheFwdDDNS4_Test >); void AllocEngine4Test_requestCacheFwdDDNS4_Test::TestBody () { |
4547 | boost::scoped_ptr<AllocEngine> engine; |
4548 | 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_4548 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4548 ; } } else gtest_label_testnothrow_4548 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4548, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4549 | 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, "alloc_engine4_unittest.cc", 4549, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4550 | |
4551 | // Set valid lifetime to 500. |
4552 | uint32_t valid = 500; |
4553 | subnet_->setValid(valid); |
4554 | |
4555 | // Set the max age to 200. |
4556 | subnet_->setCacheMaxAge(200); |
4557 | |
4558 | IOAddress addr("192.0.2.105"); |
4559 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4560 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4561 | valid, now, subnet_->getID())); |
4562 | 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, "alloc_engine4_unittest.cc", 4562, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4563 | |
4564 | // Create a context for real allocation with fwd_dns_update changed. |
4565 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4566 | true, false, "", false); |
4567 | |
4568 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4569 | lease = engine->allocateLease4(ctx); |
4570 | // Check that we got that single lease. |
4571 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4571, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4572 | EXPECT_EQ(addr, lease->addr_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("addr", "lease->addr_" , addr, lease->addr_))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "alloc_engine4_unittest.cc" , 4572, gtest_ar.failure_message()) = ::testing::Message(); |
4573 | |
4574 | // The lease was not reused. |
4575 | 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, "alloc_engine4_unittest.cc" , 4575, gtest_ar.failure_message()) = ::testing::Message(); |
4576 | |
4577 | // Check the lease was updated in the database. |
4578 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4579 | 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, "alloc_engine4_unittest.cc", 4579, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
4580 | |
4581 | detailCompareLease(lease, from_mgr); |
4582 | } |
4583 | |
4584 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
4585 | // when DDNS parameter changed. |
4586 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheRevDDNS4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheRevDDNS4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4586), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4586), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4586), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheRevDDNS4_Test >); void AllocEngine4Test_discoverCacheRevDDNS4_Test::TestBody () { |
4587 | boost::scoped_ptr<AllocEngine> engine; |
4588 | 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_4588 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4588 ; } } else gtest_label_testnothrow_4588 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4588, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4589 | 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, "alloc_engine4_unittest.cc", 4589, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4590 | |
4591 | // Set valid lifetime to 500. |
4592 | uint32_t valid = 500; |
4593 | subnet_->setValid(valid); |
4594 | |
4595 | // Set the threshold to 25%. |
4596 | subnet_->setCacheThreshold(.25); |
4597 | |
4598 | // Set the max age to 200. |
4599 | subnet_->setCacheMaxAge(200); |
4600 | |
4601 | IOAddress addr("192.0.2.105"); |
4602 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4603 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4604 | valid, now, subnet_->getID())); |
4605 | 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, "alloc_engine4_unittest.cc", 4605, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4606 | 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, "alloc_engine4_unittest.cc" , 4606, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
4607 | |
4608 | // Create a context for fake allocation with rev_dns_update changed. |
4609 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4610 | false, true, "", true); |
4611 | |
4612 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4613 | lease = engine->allocateLease4(ctx); |
4614 | // Check that we got that single lease. |
4615 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4615, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4616 | 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, "alloc_engine4_unittest.cc" , 4616, gtest_ar.failure_message()) = ::testing::Message(); |
4617 | |
4618 | // The lease was not reused. |
4619 | 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, "alloc_engine4_unittest.cc" , 4619, gtest_ar.failure_message()) = ::testing::Message(); |
4620 | } |
4621 | |
4622 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
4623 | // when hostname changed. |
4624 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_requestCacheHostname4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheHostname4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4624), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4624), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4624), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheHostname4_Test >); void AllocEngine4Test_requestCacheHostname4_Test::TestBody () { |
4625 | boost::scoped_ptr<AllocEngine> engine; |
4626 | 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_4626 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4626 ; } } else gtest_label_testnothrow_4626 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4626, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4627 | 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, "alloc_engine4_unittest.cc", 4627, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4628 | |
4629 | // Set valid lifetime to 500. |
4630 | uint32_t valid = 500; |
4631 | subnet_->setValid(valid); |
4632 | |
4633 | // Set the max age to 200. |
4634 | subnet_->setCacheMaxAge(200); |
4635 | |
4636 | IOAddress addr("192.0.2.105"); |
4637 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4638 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4639 | valid, now, subnet_->getID(), |
4640 | false, false, "foo")); |
4641 | 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, "alloc_engine4_unittest.cc", 4641, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
4642 | |
4643 | // Create a context for real allocation with fwd_dns_update changed. |
4644 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4645 | false, false, "bar", false); |
4646 | |
4647 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4648 | lease = engine->allocateLease4(ctx); |
4649 | // Check that we got that single lease. |
4650 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4650, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4651 | 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, "alloc_engine4_unittest.cc" , 4651, gtest_ar.failure_message()) = ::testing::Message(); |
4652 | |
4653 | // The lease was not reused. |
4654 | 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, "alloc_engine4_unittest.cc" , 4654, gtest_ar.failure_message()) = ::testing::Message(); |
4655 | 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, "alloc_engine4_unittest.cc", 4655, gtest_ar .failure_message()) = ::testing::Message(); |
4656 | |
4657 | // Check the lease was updated in the database. |
4658 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4659 | 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, "alloc_engine4_unittest.cc", 4659, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
4660 | |
4661 | detailCompareLease(lease, from_mgr); |
4662 | } |
4663 | |
4664 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
4665 | // lifetime value based on the context content. |
4666 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_getValidLft4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "getValidLft4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 4666), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 4666), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 4666 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getValidLft4_Test >); void AllocEngine4Test_getValidLft4_Test::TestBody() { |
4667 | AllocEngine engine(0); |
4668 | |
4669 | // Let's make three classes, two with valid-lifetime and one without, |
4670 | // and add them to the dictionary. |
4671 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
4672 | |
4673 | ClientClassDefPtr class_def(new ClientClassDef("valid_one", ExpressionPtr())); |
4674 | Triplet<uint32_t> valid_one(50, 100, 150); |
4675 | class_def->setValid(valid_one); |
4676 | dictionary->addClass(class_def); |
4677 | |
4678 | class_def.reset(new ClientClassDef("valid_two", ExpressionPtr())); |
4679 | Triplet<uint32_t>valid_two(200, 250, 300); |
4680 | class_def->setValid(valid_two); |
4681 | dictionary->addClass(class_def); |
4682 | |
4683 | class_def.reset(new ClientClassDef("valid_unspec", ExpressionPtr())); |
4684 | dictionary->addClass(class_def); |
4685 | |
4686 | // Commit our class changes. |
4687 | CfgMgr::instance().commit(); |
4688 | |
4689 | // Update the subnet's triplet to something more useful. |
4690 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
4691 | |
4692 | // Describes a test scenario. |
4693 | struct Scenario { |
4694 | std::string desc_; // descriptive text for logging |
4695 | std::vector<std::string> classes_; // class list of assigned classes |
4696 | uint32_t requested_lft_; // use as option 51 is > 0 |
4697 | uint32_t exp_valid_; // expected lifetime |
4698 | }; |
4699 | |
4700 | // Scenarios to test. |
4701 | std::vector<Scenario> scenarios = { |
4702 | { |
4703 | "BOOTP", |
4704 | { "BOOTP" }, |
4705 | 0, |
4706 | Lease::INFINITY_LFT |
4707 | }, |
4708 | { |
4709 | "no classes, no option", |
4710 | {}, |
4711 | 0, |
4712 | subnet_->getValid() |
4713 | }, |
4714 | { |
4715 | "no classes, option", |
4716 | {}, |
4717 | subnet_->getValid().getMin() + 50, |
4718 | subnet_->getValid().getMin() + 50 |
4719 | }, |
4720 | { |
4721 | "no classes, option too small", |
4722 | {}, |
4723 | subnet_->getValid().getMin() - 50, |
4724 | subnet_->getValid().getMin() |
4725 | }, |
4726 | { |
4727 | "no classes, option too big", |
4728 | {}, |
4729 | subnet_->getValid().getMax() + 50, |
4730 | subnet_->getValid().getMax() |
4731 | }, |
4732 | { |
4733 | "class unspecified, no option", |
4734 | { "valid_unspec" }, |
4735 | 0, |
4736 | subnet_->getValid() |
4737 | }, |
4738 | { |
4739 | "from last class, no option", |
4740 | { "valid_unspec", "valid_one" }, |
4741 | 0, |
4742 | valid_one.get() |
4743 | }, |
4744 | { |
4745 | "from first class, no option", |
4746 | { "valid_two", "valid_one" }, |
4747 | 0, |
4748 | valid_two.get() |
4749 | }, |
4750 | { |
4751 | "class plus option", |
4752 | { "valid_one" }, |
4753 | valid_one.getMin() + 25, |
4754 | valid_one.getMin() + 25 |
4755 | }, |
4756 | { |
4757 | "class plus option too small", |
4758 | { "valid_one" }, |
4759 | valid_one.getMin() - 25, |
4760 | valid_one.getMin() |
4761 | }, |
4762 | { |
4763 | "class plus option too big", |
4764 | { "valid_one" }, |
4765 | valid_one.getMax() + 25, |
4766 | valid_one.getMax() |
4767 | } |
4768 | }; |
4769 | |
4770 | // Iterate over the scenarios and verify the correct outcome. |
4771 | for (auto const& scenario : scenarios) { |
4772 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_4772( "alloc_engine4_unittest.cc" , 4772, (scenario.desc_)); { |
4773 | // Create a context; |
4774 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4775 | IOAddress("0.0.0.0"), false, false, |
4776 | "", false); |
4777 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4778 | |
4779 | // Add client classes (if any) |
4780 | for (auto const& class_name : scenario.classes_) { |
4781 | ctx.query_->addClass(class_name); |
4782 | } |
4783 | |
4784 | // Add client option (if one) |
4785 | if (scenario.requested_lft_) { |
4786 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
4787 | scenario.requested_lft_)); |
4788 | ctx.query_->addOption(opt); |
4789 | } |
4790 | |
4791 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4792 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4792, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4793 | 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, "alloc_engine4_unittest.cc", 4793, gtest_ar .failure_message()) = ::testing::Message(); |
4794 | } |
4795 | } |
4796 | } |
4797 | |
4798 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
4799 | // lifetime value based on the context content. |
4800 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_getTemplateClassValidLft4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "getTemplateClassValidLft4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4800), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4800), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4800), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getTemplateClassValidLft4_Test >); void AllocEngine4Test_getTemplateClassValidLft4_Test:: TestBody() { |
4801 | AllocEngine engine(0); |
4802 | |
4803 | // Let's make three classes, two with valid-lifetime and one without, |
4804 | // and add them to the dictionary. |
4805 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
4806 | ExpressionPtr match_expr; |
4807 | ExpressionParser parser; |
4808 | |
4809 | ElementPtr test_cfg = Element::create("'valid_one_value'"); |
4810 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
4811 | |
4812 | ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr)); |
4813 | Triplet<uint32_t> valid_one(50, 100, 150); |
4814 | class_def->setValid(valid_one); |
4815 | dictionary->addClass(class_def); |
4816 | |
4817 | test_cfg = Element::create("'valid_two_value'"); |
4818 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
4819 | |
4820 | class_def.reset(new TemplateClientClassDef("valid_two", match_expr)); |
4821 | Triplet<uint32_t>valid_two(200, 250, 300); |
4822 | class_def->setValid(valid_two); |
4823 | dictionary->addClass(class_def); |
4824 | |
4825 | test_cfg = Element::create("'valid_unspec_value'"); |
4826 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
4827 | |
4828 | class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr)); |
4829 | dictionary->addClass(class_def); |
4830 | |
4831 | // Commit our class changes. |
4832 | CfgMgr::instance().commit(); |
4833 | |
4834 | // Update the subnet's triplet to something more useful. |
4835 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
4836 | |
4837 | // Describes a test scenario. |
4838 | struct Scenario { |
4839 | std::string desc_; // descriptive text for logging |
4840 | std::vector<std::string> classes_; // class list of assigned classes |
4841 | uint32_t requested_lft_; // use as option 51 is > 0 |
4842 | uint32_t exp_valid_; // expected lifetime |
4843 | }; |
4844 | |
4845 | // Scenarios to test. |
4846 | std::vector<Scenario> scenarios = { |
4847 | { |
4848 | "BOOTP", |
4849 | { "BOOTP" }, |
4850 | 0, |
4851 | Lease::INFINITY_LFT |
4852 | }, |
4853 | { |
4854 | "no classes, no option", |
4855 | {}, |
4856 | 0, |
4857 | subnet_->getValid() |
4858 | }, |
4859 | { |
4860 | "no classes, option", |
4861 | {}, |
4862 | subnet_->getValid().getMin() + 50, |
4863 | subnet_->getValid().getMin() + 50 |
4864 | }, |
4865 | { |
4866 | "no classes, option too small", |
4867 | {}, |
4868 | subnet_->getValid().getMin() - 50, |
4869 | subnet_->getValid().getMin() |
4870 | }, |
4871 | { |
4872 | "no classes, option too big", |
4873 | {}, |
4874 | subnet_->getValid().getMax() + 50, |
4875 | subnet_->getValid().getMax() |
4876 | }, |
4877 | { |
4878 | "class unspecified, no option", |
4879 | { "valid_unspec" }, |
4880 | 0, |
4881 | subnet_->getValid() |
4882 | }, |
4883 | { |
4884 | "from last class, no option", |
4885 | { "valid_unspec", "valid_one" }, |
4886 | 0, |
4887 | valid_one.get() |
4888 | }, |
4889 | { |
4890 | "from first class, no option", |
4891 | { "valid_two", "valid_one" }, |
4892 | 0, |
4893 | valid_two.get() |
4894 | }, |
4895 | { |
4896 | "class plus option", |
4897 | { "valid_one" }, |
4898 | valid_one.getMin() + 25, |
4899 | valid_one.getMin() + 25 |
4900 | }, |
4901 | { |
4902 | "class plus option too small", |
4903 | { "valid_one" }, |
4904 | valid_one.getMin() - 25, |
4905 | valid_one.getMin() |
4906 | }, |
4907 | { |
4908 | "class plus option too big", |
4909 | { "valid_one" }, |
4910 | valid_one.getMax() + 25, |
4911 | valid_one.getMax() |
4912 | } |
4913 | }; |
4914 | |
4915 | // Iterate over the scenarios and verify the correct outcome. |
4916 | for (auto const& scenario : scenarios) { |
4917 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_4917( "alloc_engine4_unittest.cc" , 4917, (scenario.desc_)); { |
4918 | // Create a context; |
4919 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4920 | IOAddress("0.0.0.0"), false, false, |
4921 | "", false); |
4922 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4923 | |
4924 | // Add client classes (if any) |
4925 | for (auto const& class_name : scenario.classes_) { |
4926 | if (class_name == "BOOTP") { |
4927 | ctx.query_->addClass(class_name); |
4928 | } else { |
4929 | string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX); |
4930 | subclass += class_name; |
4931 | subclass += "_value"; |
4932 | ctx.query_->addSubClass(class_name, subclass); |
4933 | } |
4934 | } |
4935 | |
4936 | // Add client option (if one) |
4937 | if (scenario.requested_lft_) { |
4938 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
4939 | scenario.requested_lft_)); |
4940 | ctx.query_->addOption(opt); |
4941 | } |
4942 | |
4943 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4944 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4944, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4945 | 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, "alloc_engine4_unittest.cc", 4945, gtest_ar .failure_message()) = ::testing::Message(); |
4946 | } |
4947 | } |
4948 | } |
4949 | |
4950 | // This test checks that deleteRelease handles BOOTP leases. |
4951 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_bootpDelete_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bootpDelete", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 4951), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 4951), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 4951 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpDelete_Test >); void AllocEngine4Test_bootpDelete_Test::TestBody() { |
4952 | boost::scoped_ptr<AllocEngine> engine; |
4953 | 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_4953 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4953 ; } } else gtest_label_testnothrow_4953 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4953, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4954 | 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, "alloc_engine4_unittest.cc", 4954, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
4955 | |
4956 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
4957 | false, true, "somehost.example.com.", false); |
4958 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
4959 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4960 | |
4961 | // Make the query a BOOTP one. |
4962 | ctx.query_->addClass("BOOTP"); |
4963 | |
4964 | Lease4Ptr lease = engine->allocateLease4(ctx); |
4965 | // The new lease has been allocated, so the old lease should not exist. |
4966 | 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, "alloc_engine4_unittest.cc", 4966, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false") .c_str()) = ::testing::Message(); |
4967 | |
4968 | // Check that we got a lease |
4969 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 4969, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
4970 | |
4971 | // Check that is belongs to the right subnet and client. |
4972 | 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, "alloc_engine4_unittest.cc", 4972, gtest_ar .failure_message()) = ::testing::Message(); |
4973 | 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, "alloc_engine4_unittest.cc" , 4973, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true") .c_str ()) = ::testing::Message(); |
4974 | 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, "alloc_engine4_unittest.cc" , 4974, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true") .c_str()) = ::testing::Message(); |
4975 | 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, "alloc_engine4_unittest.cc", 4975 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true") .c_str()) = ::testing ::Message(); |
4976 | 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, "alloc_engine4_unittest.cc" , 4976, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true") .c_str ()) = ::testing::Message(); |
4977 | 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, "alloc_engine4_unittest.cc", 4977, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true") .c_str()) = ::testing::Message(); |
4978 | 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, "alloc_engine4_unittest.cc" , 4978, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true") .c_str() ) = ::testing::Message(); |
4979 | |
4980 | // Check the valid lifetime is infinite. |
4981 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
4982 | 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, "alloc_engine4_unittest.cc", 4982, gtest_ar .failure_message()) = ::testing::Message(); |
4983 | |
4984 | // Check that the lease is indeed in LeaseMgr |
4985 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
4986 | 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, "alloc_engine4_unittest.cc", 4986, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
4987 | |
4988 | // Now delete it. |
4989 | bool deleted = false; |
4990 | 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_4990; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4990; } } else gtest_label_testnothrow_4990 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4990, ("Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
4991 | EXPECT_TRUE(deleted)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(deleted)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "alloc_engine4_unittest.cc", 4991, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "deleted", "false", "true") .c_str()) = ::testing ::Message(); |
4992 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
4993 | 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 , "alloc_engine4_unittest.cc", 4993, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "from_mgr", "true", "false") .c_str()) = ::testing ::Message(); |
4994 | } |
4995 | |
4996 | // This test verifies that all addresses in a pool can be allocated. |
4997 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_fullPool_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fullPool", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 4997), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 4997), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 4997 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullPool_Test >); void AllocEngine4Test_fullPool_Test::TestBody() { |
4998 | boost::scoped_ptr<AllocEngine> engine; |
4999 | 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_4999 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4999 ; } } else gtest_label_testnothrow_4999 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4999, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5000 | 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, "alloc_engine4_unittest.cc", 5000, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5001 | |
5002 | // Get rid of the default subnet configuration. |
5003 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5004 | cfg_mgr.clear(); |
5005 | |
5006 | // Configure a larger subnet with a /24 pool. |
5007 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
5008 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
5009 | subnet_->addPool(pool_); |
5010 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5011 | |
5012 | // Set exclude-first-last to false. |
5013 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
5014 | cfg_mgr.commit(); |
5015 | |
5016 | size_t cnt = 0; |
5017 | vector<bool> found(256, false); |
5018 | while (true) { |
5019 | vector<uint8_t> duid = clientid_->getClientId(); |
5020 | duid[6] = cnt >> 8; |
5021 | duid[7] = cnt & 0xff; |
5022 | ClientIdPtr clientid(new ClientId(duid)); |
5023 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5024 | hwaddr->hwaddr_[4] = cnt >> 8; |
5025 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5026 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5027 | IOAddress("0.0.0.0"), |
5028 | false, false, "foo.bar", false); |
5029 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5030 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5031 | |
5032 | if (!lease) { |
5033 | break; |
5034 | } |
5035 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5036 | 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, "alloc_engine4_unittest.cc" , 5036, gtest_ar.failure_message()) = ::testing::Message(); |
5037 | 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, "alloc_engine4_unittest.cc" , 5037, gtest_ar.failure_message()) = ::testing::Message(); |
5038 | 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, "alloc_engine4_unittest.cc" , 5038, gtest_ar.failure_message()) = ::testing::Message(); |
5039 | 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, "alloc_engine4_unittest.cc" , 5039, gtest_ar.failure_message()) = ::testing::Message(); |
5040 | 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, "alloc_engine4_unittest.cc", 5040, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false") .c_str()) = ::testing::Message(); |
5041 | found[addr[3]] = true; |
5042 | ++cnt; |
5043 | // Catch unbound loop. |
5044 | 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, "alloc_engine4_unittest.cc", 5044, gtest_ar.failure_message()) = ::testing::Message(); |
5045 | } |
5046 | 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, "alloc_engine4_unittest.cc" , 5046, gtest_ar.failure_message()) = ::testing::Message(); |
5047 | 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, "alloc_engine4_unittest.cc" , 5047, gtest_ar.failure_message()) = ::testing::Message(); |
5048 | } |
5049 | |
5050 | // This test verifies that all addresses in a subnet can be allocated. |
5051 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_fullSubnet24_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fullSubnet24", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5051), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5051), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5051 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullSubnet24_Test >); void AllocEngine4Test_fullSubnet24_Test::TestBody() { |
5052 | boost::scoped_ptr<AllocEngine> engine; |
5053 | 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_5053 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5053 ; } } else gtest_label_testnothrow_5053 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5053, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5054 | 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, "alloc_engine4_unittest.cc", 5054, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5055 | |
5056 | // Get rid of the default subnet configuration. |
5057 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5058 | cfg_mgr.clear(); |
5059 | |
5060 | // Configure a larger subnet with a /24 pool. |
5061 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5062 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
5063 | IOAddress("192.0.2.255"))); |
5064 | subnet_->addPool(pool_); |
5065 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5066 | |
5067 | // Set exclude-first-last to false. |
5068 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
5069 | cfg_mgr.commit(); |
5070 | |
5071 | size_t cnt = 0; |
5072 | vector<bool> found(256, false); |
5073 | while (true) { |
5074 | vector<uint8_t> duid = clientid_->getClientId(); |
5075 | duid[6] = cnt >> 8; |
5076 | duid[7] = cnt & 0xff; |
5077 | ClientIdPtr clientid(new ClientId(duid)); |
5078 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5079 | hwaddr->hwaddr_[4] = cnt >> 8; |
5080 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5081 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5082 | IOAddress("0.0.0.0"), |
5083 | false, false, "foo.bar", false); |
5084 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5085 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5086 | |
5087 | if (!lease) { |
5088 | break; |
5089 | } |
5090 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5091 | 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, "alloc_engine4_unittest.cc" , 5091, gtest_ar.failure_message()) = ::testing::Message(); |
5092 | 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, "alloc_engine4_unittest.cc" , 5092, gtest_ar.failure_message()) = ::testing::Message(); |
5093 | 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, "alloc_engine4_unittest.cc" , 5093, gtest_ar.failure_message()) = ::testing::Message(); |
5094 | 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, "alloc_engine4_unittest.cc" , 5094, gtest_ar.failure_message()) = ::testing::Message(); |
5095 | 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, "alloc_engine4_unittest.cc", 5095, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false") .c_str()) = ::testing::Message(); |
5096 | found[addr[3]] = true; |
5097 | ++cnt; |
5098 | // Catch unbound loop. |
5099 | 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, "alloc_engine4_unittest.cc", 5099, gtest_ar.failure_message()) = ::testing::Message(); |
5100 | } |
5101 | 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, "alloc_engine4_unittest.cc" , 5101, gtest_ar.failure_message()) = ::testing::Message(); |
5102 | 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, "alloc_engine4_unittest.cc" , 5102, gtest_ar.failure_message()) = ::testing::Message(); |
5103 | } |
5104 | |
5105 | // This test verifies that not all addresses in a pool can be allocated when |
5106 | // exclude-first-last is true. |
5107 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLast_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLast", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 5107), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5107), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5107), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast_Test >); void AllocEngine4Test_excludeFirstLast_Test::TestBody( ) { |
5108 | boost::scoped_ptr<AllocEngine> engine; |
5109 | 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_5109 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5109 ; } } else gtest_label_testnothrow_5109 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5109, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5110 | 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, "alloc_engine4_unittest.cc", 5110, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5111 | |
5112 | // Get rid of the default subnet configuration. |
5113 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5114 | cfg_mgr.clear(); |
5115 | |
5116 | // Configure a larger subnet with a /24 pool. |
5117 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
5118 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
5119 | subnet_->addPool(pool_); |
5120 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5121 | |
5122 | // Set exclude-first-last to true. |
5123 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5124 | cfg_mgr.commit(); |
5125 | |
5126 | size_t cnt = 0; |
5127 | vector<bool> found(256, false); |
5128 | while (true) { |
5129 | vector<uint8_t> duid = clientid_->getClientId(); |
5130 | duid[6] = cnt >> 8; |
5131 | duid[7] = cnt & 0xff; |
5132 | ClientIdPtr clientid(new ClientId(duid)); |
5133 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5134 | hwaddr->hwaddr_[4] = cnt >> 8; |
5135 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5136 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5137 | IOAddress("0.0.0.0"), |
5138 | false, false, "foo.bar", false); |
5139 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5140 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5141 | |
5142 | if (!lease) { |
5143 | break; |
5144 | } |
5145 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5146 | 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, "alloc_engine4_unittest.cc" , 5146, gtest_ar.failure_message()) = ::testing::Message(); |
5147 | 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, "alloc_engine4_unittest.cc" , 5147, gtest_ar.failure_message()) = ::testing::Message(); |
5148 | 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, "alloc_engine4_unittest.cc" , 5148, gtest_ar.failure_message()) = ::testing::Message(); |
5149 | 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, "alloc_engine4_unittest.cc" , 5149, gtest_ar.failure_message()) = ::testing::Message(); |
5150 | 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, "alloc_engine4_unittest.cc", 5150, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false") .c_str()) = ::testing::Message(); |
5151 | found[addr[3]] = true; |
5152 | ++cnt; |
5153 | // Catch unbound loop. |
5154 | 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, "alloc_engine4_unittest.cc", 5154, gtest_ar.failure_message()) = ::testing::Message(); |
5155 | } |
5156 | 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, "alloc_engine4_unittest.cc" , 5156, gtest_ar.failure_message()) = ::testing::Message(); |
5157 | vector<bool> expected(256, true); |
5158 | expected[0] = false; |
5159 | expected[255] = false; |
5160 | 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, "alloc_engine4_unittest.cc" , 5160, gtest_ar.failure_message()) = ::testing::Message(); |
5161 | } |
5162 | |
5163 | // This test verifies that not all addresses in a subnet can be allocated when |
5164 | // exclude-first-last is true. |
5165 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLast24_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLast24", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 5165), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5165), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5165), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast24_Test >); void AllocEngine4Test_excludeFirstLast24_Test::TestBody () { |
5166 | boost::scoped_ptr<AllocEngine> engine; |
5167 | 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_5167 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5167 ; } } else gtest_label_testnothrow_5167 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5167, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5168 | 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, "alloc_engine4_unittest.cc", 5168, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5169 | |
5170 | // Get rid of the default subnet configuration. |
5171 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5172 | cfg_mgr.clear(); |
5173 | |
5174 | // Configure a larger subnet with a /24 pool. |
5175 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5176 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
5177 | IOAddress("192.0.2.255"))); |
5178 | subnet_->addPool(pool_); |
5179 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5180 | |
5181 | // Set exclude-first-last to true. |
5182 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5183 | cfg_mgr.commit(); |
5184 | |
5185 | size_t cnt = 0; |
5186 | vector<bool> found(256, false); |
5187 | while (true) { |
5188 | vector<uint8_t> duid = clientid_->getClientId(); |
5189 | duid[6] = cnt >> 8; |
5190 | duid[7] = cnt & 0xff; |
5191 | ClientIdPtr clientid(new ClientId(duid)); |
5192 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5193 | hwaddr->hwaddr_[4] = cnt >> 8; |
5194 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5195 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5196 | IOAddress("0.0.0.0"), |
5197 | false, false, "foo.bar", false); |
5198 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5199 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5200 | |
5201 | if (!lease) { |
5202 | break; |
5203 | } |
5204 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5205 | 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, "alloc_engine4_unittest.cc" , 5205, gtest_ar.failure_message()) = ::testing::Message(); |
5206 | 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, "alloc_engine4_unittest.cc" , 5206, gtest_ar.failure_message()) = ::testing::Message(); |
5207 | 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, "alloc_engine4_unittest.cc" , 5207, gtest_ar.failure_message()) = ::testing::Message(); |
5208 | 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, "alloc_engine4_unittest.cc" , 5208, gtest_ar.failure_message()) = ::testing::Message(); |
5209 | 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, "alloc_engine4_unittest.cc", 5209, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false") .c_str()) = ::testing::Message(); |
5210 | found[addr[3]] = true; |
5211 | ++cnt; |
5212 | // Catch unbound loop. |
5213 | 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, "alloc_engine4_unittest.cc", 5213, gtest_ar.failure_message()) = ::testing::Message(); |
5214 | } |
5215 | 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, "alloc_engine4_unittest.cc" , 5215, gtest_ar.failure_message()) = ::testing::Message(); |
5216 | vector<bool> expected(256, true); |
5217 | expected[0] = false; |
5218 | expected[255] = false; |
5219 | 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, "alloc_engine4_unittest.cc" , 5219, gtest_ar.failure_message()) = ::testing::Message(); |
5220 | } |
5221 | |
5222 | // This test verifies that all addresses in a subnet can be allocated when |
5223 | // exclude-first-last is true but the prefix length is greater than 24. |
5224 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_excludeFirst25_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirst25", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5224), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5224), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5224 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirst25_Test >); void AllocEngine4Test_excludeFirst25_Test::TestBody() { |
5225 | boost::scoped_ptr<AllocEngine> engine; |
5226 | 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_5226 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5226 ; } } else gtest_label_testnothrow_5226 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5226, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5227 | 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, "alloc_engine4_unittest.cc", 5227, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5228 | |
5229 | // Get rid of the default subnet configuration. |
5230 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5231 | cfg_mgr.clear(); |
5232 | |
5233 | // Configure a smaller subnet with a /25 pool. |
5234 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 25, 1, 2, 3, SubnetID(10)); |
5235 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
5236 | IOAddress("192.0.2.127"))); |
5237 | subnet_->addPool(pool_); |
5238 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5239 | |
5240 | // Set exclude-first-last to true. |
5241 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5242 | cfg_mgr.commit(); |
5243 | |
5244 | size_t cnt = 0; |
5245 | vector<bool> found(128, false); |
5246 | while (true) { |
5247 | vector<uint8_t> duid = clientid_->getClientId(); |
5248 | duid[6] = cnt >> 8; |
5249 | duid[7] = cnt & 0xff; |
5250 | ClientIdPtr clientid(new ClientId(duid)); |
5251 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5252 | hwaddr->hwaddr_[4] = cnt >> 8; |
5253 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5254 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5255 | IOAddress("0.0.0.0"), |
5256 | false, false, "foo.bar", false); |
5257 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5258 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5259 | |
5260 | if (!lease) { |
5261 | break; |
5262 | } |
5263 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5264 | 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, "alloc_engine4_unittest.cc" , 5264, gtest_ar.failure_message()) = ::testing::Message(); |
5265 | 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, "alloc_engine4_unittest.cc" , 5265, gtest_ar.failure_message()) = ::testing::Message(); |
5266 | 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, "alloc_engine4_unittest.cc" , 5266, gtest_ar.failure_message()) = ::testing::Message(); |
5267 | 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, "alloc_engine4_unittest.cc" , 5267, gtest_ar.failure_message()) = ::testing::Message(); |
5268 | 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, "alloc_engine4_unittest.cc" , 5268, gtest_ar.failure_message()) = ::testing::Message(); |
5269 | 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, "alloc_engine4_unittest.cc", 5269, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false") .c_str()) = ::testing::Message(); |
5270 | found[addr[3]] = true; |
5271 | ++cnt; |
5272 | // Catch unbound loop. |
5273 | 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, "alloc_engine4_unittest.cc", 5273, gtest_ar.failure_message()) = ::testing::Message(); |
5274 | } |
5275 | 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, "alloc_engine4_unittest.cc" , 5275, gtest_ar.failure_message()) = ::testing::Message(); |
5276 | 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, "alloc_engine4_unittest.cc" , 5276, gtest_ar.failure_message()) = ::testing::Message(); |
5277 | } |
5278 | |
5279 | // This test verifies that all addresses in a subnet can be allocated when |
5280 | // exclude-first-last is true but the prefix length is greater than 24. |
5281 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_excludeLast25_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeLast25", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5281), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5281), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5281 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeLast25_Test >); void AllocEngine4Test_excludeLast25_Test::TestBody() { |
5282 | boost::scoped_ptr<AllocEngine> engine; |
5283 | 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_5283 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5283 ; } } else gtest_label_testnothrow_5283 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5283, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5284 | 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, "alloc_engine4_unittest.cc", 5284, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5285 | |
5286 | // Get rid of the default subnet configuration. |
5287 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5288 | cfg_mgr.clear(); |
5289 | |
5290 | // Configure a smaller subnet with a /25 pool. |
5291 | subnet_ = Subnet4::create(IOAddress("192.0.2.128"), 25, 1, 2, 3, SubnetID(10)); |
5292 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.128"), |
5293 | IOAddress("192.0.2.255"))); |
5294 | subnet_->addPool(pool_); |
5295 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5296 | |
5297 | // Set exclude-first-last to true. |
5298 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5299 | cfg_mgr.commit(); |
5300 | |
5301 | size_t cnt = 0; |
5302 | vector<bool> found(128, false); |
5303 | while (true) { |
5304 | vector<uint8_t> duid = clientid_->getClientId(); |
5305 | duid[6] = cnt >> 8; |
5306 | duid[7] = cnt & 0xff; |
5307 | ClientIdPtr clientid(new ClientId(duid)); |
5308 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5309 | hwaddr->hwaddr_[4] = cnt >> 8; |
5310 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5311 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5312 | IOAddress("0.0.0.0"), |
5313 | false, false, "foo.bar", false); |
5314 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5315 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5316 | |
5317 | if (!lease) { |
5318 | break; |
5319 | } |
5320 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5321 | 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, "alloc_engine4_unittest.cc" , 5321, gtest_ar.failure_message()) = ::testing::Message(); |
5322 | 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, "alloc_engine4_unittest.cc" , 5322, gtest_ar.failure_message()) = ::testing::Message(); |
5323 | 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, "alloc_engine4_unittest.cc" , 5323, gtest_ar.failure_message()) = ::testing::Message(); |
5324 | 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, "alloc_engine4_unittest.cc" , 5324, gtest_ar.failure_message()) = ::testing::Message(); |
5325 | 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, "alloc_engine4_unittest.cc" , 5325, gtest_ar.failure_message()) = ::testing::Message(); |
5326 | 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, "alloc_engine4_unittest.cc", 5326, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3] - 128]" , "true", "false") .c_str()) = ::testing::Message(); |
5327 | found[addr[3] - 128] = true; |
5328 | ++cnt; |
5329 | // Catch unbound loop. |
5330 | 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, "alloc_engine4_unittest.cc", 5330, gtest_ar.failure_message()) = ::testing::Message(); |
5331 | } |
5332 | 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, "alloc_engine4_unittest.cc" , 5332, gtest_ar.failure_message()) = ::testing::Message(); |
5333 | 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, "alloc_engine4_unittest.cc" , 5333, gtest_ar.failure_message()) = ::testing::Message(); |
5334 | } |
5335 | |
5336 | // This test verifies that an excluded address can be allocated when requested |
5337 | // and exclude-first-last is true. |
5338 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLastRequested_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLastRequested", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 5338), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5338), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5338), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastRequested_Test >); void AllocEngine4Test_excludeFirstLastRequested_Test:: TestBody() { |
5339 | boost::scoped_ptr<AllocEngine> engine; |
5340 | 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_5340 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5340 ; } } else gtest_label_testnothrow_5340 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5340, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5341 | 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, "alloc_engine4_unittest.cc", 5341, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5342 | |
5343 | // Get rid of the default subnet configuration. |
5344 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5345 | cfg_mgr.clear(); |
5346 | |
5347 | // Configure a larger subnet with a /24 pool. |
5348 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
5349 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
5350 | subnet_->addPool(pool_); |
5351 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5352 | |
5353 | // Set exclude-first-last to true. |
5354 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5355 | cfg_mgr.commit(); |
5356 | |
5357 | // Request the first address. |
5358 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
5359 | IOAddress("10.0.1.0"), |
5360 | false, false, "foo.bar", false); |
5361 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5362 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5363 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5363, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5364 | 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, "alloc_engine4_unittest.cc", 5364, gtest_ar .failure_message()) = ::testing::Message(); |
5365 | |
5366 | // Request the last address. |
5367 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
5368 | IOAddress("10.0.1.255"), |
5369 | false, false, "bar.foo", false); |
5370 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
5371 | lease = engine->allocateLease4(ctx2); |
5372 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5372, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5373 | 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, "alloc_engine4_unittest.cc", 5373, gtest_ar .failure_message()) = ::testing::Message(); |
5374 | } |
5375 | |
5376 | // This test verifies that an excluded address can be allocated when reserved |
5377 | // and exclude-first-last is true. |
5378 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLastReserver_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLastReserver", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 5378), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5378), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5378), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastReserver_Test >); void AllocEngine4Test_excludeFirstLastReserver_Test::TestBody () { |
5379 | boost::scoped_ptr<AllocEngine> engine; |
5380 | 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_5380 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5380 ; } } else gtest_label_testnothrow_5380 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5380, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5381 | 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, "alloc_engine4_unittest.cc", 5381, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5382 | |
5383 | // Get rid of the default subnet configuration. |
5384 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5385 | cfg_mgr.clear(); |
5386 | |
5387 | // Configure a larger subnet with a /24 pool. |
5388 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
5389 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
5390 | subnet_->addPool(pool_); |
5391 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5392 | |
5393 | // Set exclude-first-last to true. |
5394 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5395 | |
5396 | // Add reservations. |
5397 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
5398 | Host::IDENT_HWADDR, subnet_->getID(), |
5399 | SUBNET_ID_UNUSED, IOAddress("10.0.1.0"))); |
5400 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host); |
5401 | HostPtr host2(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
5402 | Host::IDENT_HWADDR, subnet_->getID(), |
5403 | SUBNET_ID_UNUSED, IOAddress("10.0.1.255"))); |
5404 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host2); |
5405 | subnet_->setReservationsInSubnet(true); |
5406 | subnet_->setReservationsOutOfPool(false); |
5407 | cfg_mgr.commit(); |
5408 | |
5409 | // Request the first address. |
5410 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
5411 | IOAddress("0.0.0.0"), |
5412 | false, false, "foo.bar", false); |
5413 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5414 | AllocEngine::findReservation(ctx); |
5415 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5416 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5416, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5417 | 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, "alloc_engine4_unittest.cc", 5417, gtest_ar .failure_message()) = ::testing::Message(); |
5418 | |
5419 | // Request the last address. |
5420 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
5421 | IOAddress("0.0.0.0"), |
5422 | false, false, "bar.foo", false); |
5423 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
5424 | AllocEngine::findReservation(ctx2); |
5425 | lease = engine->allocateLease4(ctx2); |
5426 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5426, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5427 | 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, "alloc_engine4_unittest.cc", 5427, gtest_ar .failure_message()) = ::testing::Message(); |
5428 | } |
5429 | |
5430 | // Verifies that offer_lft is non-zero, that an offered lease is stored |
5431 | // in the lease database. |
5432 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLft_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverOfferLft", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 5432), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5432), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5432), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLft_Test >); void AllocEngine4Test_discoverOfferLft_Test::TestBody( ) { |
5433 | boost::scoped_ptr<AllocEngine> engine; |
5434 | 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_5434 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5434 ; } } else gtest_label_testnothrow_5434 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5434, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5435 | 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, "alloc_engine4_unittest.cc", 5435, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5436 | |
5437 | IOAddress addr("192.0.2.15"); |
5438 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5439 | // Get rid of the default test configuration. |
5440 | cfg_mgr.clear(); |
5441 | |
5442 | // Create configuration similar to other tests, but with a single address pool |
5443 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5444 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
5445 | subnet_->addPool(pool_); |
5446 | |
5447 | // Set subnet's offer-lifetime to a non-zero, positive value. |
5448 | uint32_t offer_lft = (subnet_->getValid() / 3); |
5449 | subnet_->setOfferLft(offer_lft); |
5450 | 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, "alloc_engine4_unittest.cc" , 5450, gtest_ar.failure_message()) = ::testing::Message(); |
5451 | |
5452 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5453 | |
5454 | // Ask for any address |
5455 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
5456 | IOAddress("0.0.0.0"), true, true, |
5457 | "one", true); |
5458 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
5459 | |
5460 | // Check that we got that single lease |
5461 | Lease4Ptr lease = engine->allocateLease4(ctx1); |
5462 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5462, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5463 | 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, "alloc_engine4_unittest.cc" , 5463, gtest_ar.failure_message()) = ::testing::Message(); |
5464 | 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, "alloc_engine4_unittest.cc", 5464, gtest_ar .failure_message()) = ::testing::Message(); |
5465 | 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, "alloc_engine4_unittest.cc", 5465, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_fwd_" , "true", "false") .c_str()) = ::testing::Message(); |
5466 | 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, "alloc_engine4_unittest.cc", 5466, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_rev_" , "true", "false") .c_str()) = ::testing::Message(); |
5467 | |
5468 | // Check that the lease has been stored by LeaseMgr. |
5469 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5470 | 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, "alloc_engine4_unittest.cc", 5470, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
5471 | 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, "alloc_engine4_unittest.cc", 5471, gtest_ar .failure_message()) = ::testing::Message(); |
5472 | 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, "alloc_engine4_unittest.cc", 5472, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_fwd_" , "true", "false") .c_str()) = ::testing::Message(); |
5473 | 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, "alloc_engine4_unittest.cc", 5473, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_rev_" , "true", "false") .c_str()) = ::testing::Message(); |
5474 | |
5475 | // Try to discover an address for a second client. |
5476 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
5477 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
5478 | |
5479 | // Ask for any address. |
5480 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, |
5481 | IOAddress("0.0.0.0"), true, true, |
5482 | "two", true); |
5483 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1235)); |
5484 | |
5485 | // Verify that we did not get a lease. |
5486 | lease = engine->allocateLease4(ctx2); |
5487 | 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, "alloc_engine4_unittest.cc", 5487, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false") .c_str()) = ::testing::Message(); |
5488 | |
5489 | // Original client now does a DHCPREQUEST. Make sure we get the |
5490 | // previously offered lease with the proper valid lifetime. |
5491 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
5492 | IOAddress("0.0.0.0"), true, true, |
5493 | "one", false); |
5494 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1236)); |
5495 | |
5496 | lease = engine->allocateLease4(ctx3); |
5497 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5497, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5498 | 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, "alloc_engine4_unittest.cc" , 5498, gtest_ar.failure_message()) = ::testing::Message(); |
5499 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5500 | 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, "alloc_engine4_unittest.cc", 5500, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
5501 | 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, "alloc_engine4_unittest.cc" , 5501, gtest_ar.failure_message()) = ::testing::Message(); |
5502 | } |
5503 | |
5504 | // Verifies that when offer_lft is non-zero, that an existing lease is |
5505 | // whose remaining life is larger than offer_lft, is offered as is. |
5506 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLftUseExistingLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverOfferLftUseExistingLease4", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 5506), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 5506), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 5506), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_discoverOfferLftUseExistingLease4_Test >); void AllocEngine4Test_discoverOfferLftUseExistingLease4_Test ::TestBody() { |
5507 | boost::scoped_ptr<AllocEngine> engine; |
5508 | 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_5508 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5508 ; } } else gtest_label_testnothrow_5508 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5508, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5509 | 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, "alloc_engine4_unittest.cc", 5509, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5510 | |
5511 | IOAddress addr("192.0.2.15"); |
5512 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5513 | // Get rid of the default test configuration. |
5514 | cfg_mgr.clear(); |
5515 | |
5516 | // Create configuration similar to other tests, but with a single address pool |
5517 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 300, SubnetID(10)); |
5518 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
5519 | subnet_->addPool(pool_); |
5520 | |
5521 | // Set subnet's offer-lifetime to a non-zero, positive value. |
5522 | uint32_t offer_lft = 100; |
5523 | subnet_->setOfferLft(offer_lft); |
5524 | 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, "alloc_engine4_unittest.cc" , 5524, gtest_ar.failure_message()) = ::testing::Message(); |
5525 | |
5526 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5527 | |
5528 | time_t now = time(NULL__null) - 5; // Allocated 5 seconds ago |
5529 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, 300, now, |
5530 | subnet_->getID(), true, true, "somehost")); |
5531 | |
5532 | // Copy the lease, so as it can be compared with the old lease returned |
5533 | // by the allocation engine. |
5534 | Lease4 original_lease(*lease); |
5535 | |
5536 | // Lease was assigned 5 seconds ago, its valid lifetime is 300, its |
5537 | // remaining lifetime is still larger than offer_lft. |
5538 | 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, "alloc_engine4_unittest.cc", 5538, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false") .c_str()) = ::testing ::Message(); |
5539 | 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, "alloc_engine4_unittest.cc" , 5539, gtest_ar.failure_message()) = ::testing::Message(); |
5540 | 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, "alloc_engine4_unittest.cc" , 5540, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
5541 | |
5542 | // CASE 1: Asking for any address |
5543 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
5544 | IOAddress("0.0.0.0"), false, false, |
5545 | "", true); |
5546 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
5547 | lease = engine->allocateLease4(ctx1); |
5548 | // Check that we got that single lease |
5549 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5549, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5550 | 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, "alloc_engine4_unittest.cc" , 5550, gtest_ar.failure_message()) = ::testing::Message(); |
5551 | 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, "alloc_engine4_unittest.cc" , 5551, gtest_ar.failure_message()) = ::testing::Message(); |
5552 | |
5553 | // We are reusing the existing lease, the old instance should be |
5554 | // returned. The returned instance should be the same as the original |
5555 | // lease. |
5556 | 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, "alloc_engine4_unittest.cc", 5556, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
5557 | 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, "alloc_engine4_unittest.cc" , 5557, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
5558 | |
5559 | // Check that the lease has not been modified by LeaseMgr. |
5560 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5561 | 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, "alloc_engine4_unittest.cc", 5561, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
5562 | 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, "alloc_engine4_unittest.cc", 5562, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "original_lease == *from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
5563 | } |
5564 | |
5565 | // Verifies that when offer_lft is non-zero, that an expired lease can |
5566 | // be reclaimed an offered correctly. |
5567 | 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 ; static ::testing::TestInfo* const test_info_ __attribute__( (unused)); }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverOfferLftReuseExpiredLease4", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 5567), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 5567), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 5567), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test >); void AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test ::TestBody() { |
5568 | boost::scoped_ptr<AllocEngine> engine; |
5569 | 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_5569 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5569 ; } } else gtest_label_testnothrow_5569 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5569, ("Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
5570 | 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, "alloc_engine4_unittest.cc", 5570, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true") .c_str()) = ::testing::Message(); |
5571 | |
5572 | IOAddress addr("192.0.2.15"); |
5573 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5574 | // Get rid of the default test configuration. |
5575 | cfg_mgr.clear(); |
5576 | |
5577 | // Create configuration similar to other tests, but with a single address pool |
5578 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5579 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
5580 | subnet_->addPool(pool_); |
5581 | |
5582 | // Set subnet's offer-lifetime to a non-zero, positive value. |
5583 | uint32_t offer_lft = (subnet_->getValid() / 3); |
5584 | subnet_->setOfferLft(offer_lft); |
5585 | 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, "alloc_engine4_unittest.cc" , 5585, gtest_ar.failure_message()) = ::testing::Message(); |
5586 | |
5587 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5588 | |
5589 | // Just a different hw/client-id for the second client |
5590 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
5591 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
5592 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
5593 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
5594 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
5595 | 495, now, subnet_->getID())); |
5596 | // Copy the lease, so as it can be compared with the old lease returned |
5597 | // by the allocation engine. |
5598 | Lease4 original_lease(*lease); |
5599 | |
5600 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
5601 | // is expired already |
5602 | 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, "alloc_engine4_unittest.cc", 5602, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->expired()" , "false", "true") .c_str()) = ::testing::Message(); |
5603 | 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, "alloc_engine4_unittest.cc" , 5603, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ) .c_str()) = ::testing::Message(); |
5604 | |
5605 | // CASE 1: Asking for any address |
5606 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
5607 | IOAddress("0.0.0.0"), false, false, |
5608 | "", true); |
5609 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
5610 | lease = engine->allocateLease4(ctx1); |
5611 | // Check that we got that single lease |
5612 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5612, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5613 | 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, "alloc_engine4_unittest.cc" , 5613, gtest_ar.failure_message()) = ::testing::Message(); |
5614 | 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, "alloc_engine4_unittest.cc", 5614, gtest_ar .failure_message()) = ::testing::Message(); |
5615 | 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, "alloc_engine4_unittest.cc", 5615, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_fwd_" , "true", "false") .c_str()) = ::testing::Message(); |
5616 | 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, "alloc_engine4_unittest.cc", 5616, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_rev_" , "true", "false") .c_str()) = ::testing::Message(); |
5617 | |
5618 | // We are reusing expired lease, the old (expired) instance should be |
5619 | // returned. The returned instance should be the same as the original |
5620 | // lease. |
5621 | 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, "alloc_engine4_unittest.cc", 5621, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true") .c_str()) = ::testing::Message(); |
5622 | 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, "alloc_engine4_unittest.cc" , 5622, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true") .c_str ()) = ::testing::Message(); |
5623 | |
5624 | // Check that the lease has been stored by LeaseMgr. |
5625 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5626 | 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, "alloc_engine4_unittest.cc", 5626, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
5627 | 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, "alloc_engine4_unittest.cc", 5627, gtest_ar .failure_message()) = ::testing::Message(); |
5628 | 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, "alloc_engine4_unittest.cc", 5628, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_fwd_" , "true", "false") .c_str()) = ::testing::Message(); |
5629 | 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, "alloc_engine4_unittest.cc", 5629, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_rev_" , "true", "false") .c_str()) = ::testing::Message(); |
5630 | |
5631 | // Client now does a DHCPREQUEST. Make sure we get the |
5632 | // previously offered lease with the proper valid lifetime. |
5633 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
5634 | IOAddress("0.0.0.0"), true, true, |
5635 | "one", false); |
5636 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1235)); |
5637 | |
5638 | lease = engine->allocateLease4(ctx2); |
5639 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5639, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5640 | 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, "alloc_engine4_unittest.cc" , 5640, gtest_ar.failure_message()) = ::testing::Message(); |
5641 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5642 | 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, "alloc_engine4_unittest.cc", 5642, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
5643 | 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, "alloc_engine4_unittest.cc" , 5643, gtest_ar.failure_message()) = ::testing::Message(); |
5644 | } |
5645 | |
5646 | // Verifies that AllocEngine::getOfferLft(ctx4) returns the appropriate |
5647 | // lifetime value based on the context content. |
5648 | 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; static ::testing::TestInfo* const test_info_ __attribute__((unused) ); }; ::testing::TestInfo* const AllocEngine4Test_getOfferLft4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "getOfferLft4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5648), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5648), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5648 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getOfferLft4_Test >); void AllocEngine4Test_getOfferLft4_Test::TestBody() { |
5649 | AllocEngine engine(0); |
5650 | |
5651 | // Let's make three classes, two with offer-lifetime and one without, |
5652 | // and add them to the dictionary. |
5653 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
5654 | |
5655 | ClientClassDefPtr class_def(new ClientClassDef("offer_lft_one", ExpressionPtr())); |
5656 | Optional<uint32_t> offer_lft_one(100); |
5657 | class_def->setOfferLft(offer_lft_one); |
5658 | dictionary->addClass(class_def); |
5659 | |
5660 | class_def.reset(new ClientClassDef("offer_lft_two", ExpressionPtr())); |
5661 | Optional<uint32_t>offer_lft_two(200); |
5662 | class_def->setOfferLft(offer_lft_two); |
5663 | dictionary->addClass(class_def); |
5664 | |
5665 | class_def.reset(new ClientClassDef("offer_lft_zero", ExpressionPtr())); |
5666 | Optional<uint32_t>offer_lft_zero(0); |
5667 | class_def->setOfferLft(offer_lft_zero); |
5668 | dictionary->addClass(class_def); |
5669 | |
5670 | class_def.reset(new ClientClassDef("offer_lft_unspec", ExpressionPtr())); |
5671 | dictionary->addClass(class_def); |
5672 | |
5673 | // Commit our class changes. |
5674 | CfgMgr::instance().commit(); |
5675 | |
5676 | // Update the subnet's triplet to something more useful. |
5677 | subnet_->setOfferLft(Optional<uint32_t>(300)); |
5678 | |
5679 | // Describes a test scenario. |
5680 | struct Scenario { |
5681 | std::string desc_; // descriptive text for logging |
5682 | std::vector<std::string> classes_; // class list of assigned classes |
5683 | uint32_t exp_valid_lft_; // expected lease lifetime |
5684 | bool exp_allocate_; // true if lease should be allocated |
5685 | }; |
5686 | |
5687 | bool exp_allocate = true; |
5688 | |
5689 | // Scenarios to test. |
5690 | std::vector<Scenario> scenarios = { |
5691 | { |
5692 | "BOOTP", |
5693 | { "BOOTP" }, |
5694 | Lease::INFINITY_LFT, |
5695 | !exp_allocate, |
5696 | }, |
5697 | { |
5698 | "no classes", |
5699 | {}, |
5700 | subnet_->getOfferLft(), |
5701 | exp_allocate |
5702 | }, |
5703 | { |
5704 | "class unspecified", |
5705 | { "offer_lft_unspec" }, |
5706 | subnet_->getOfferLft(), |
5707 | exp_allocate |
5708 | }, |
5709 | { |
5710 | "from last class", |
5711 | { "offer_lft_unspec", "offer_lft_one" }, |
5712 | offer_lft_one.get(), |
5713 | exp_allocate |
5714 | }, |
5715 | { |
5716 | "from first class", |
5717 | { "offer_lft_two", "offer_lft_one" }, |
5718 | offer_lft_two.get(), |
5719 | exp_allocate |
5720 | }, |
5721 | { |
5722 | // Using class value of zero should override non-zero set at |
5723 | // subnet level, lease should have actual valid lft |
5724 | "zero from class", |
5725 | { "offer_lft_zero" }, |
5726 | subnet_->getValid(), |
5727 | !exp_allocate |
5728 | } |
5729 | }; |
5730 | |
5731 | // Iterate over the scenarios and verify the correct outcome. |
5732 | for (auto const& scenario : scenarios) { |
5733 | SCOPED_TRACE(scenario.desc_)const ::testing::ScopedTrace gtest_trace_5733( "alloc_engine4_unittest.cc" , 5733, (scenario.desc_)); { |
5734 | // Create a context; |
5735 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
5736 | IOAddress("0.0.0.0"), false, false, |
5737 | "", true); |
5738 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
5739 | |
5740 | // Add client classes (if any) |
5741 | for (auto const& class_name : scenario.classes_) { |
5742 | ctx.query_->addClass(class_name); |
5743 | } |
5744 | |
5745 | Lease4Ptr lease = engine.allocateLease4(ctx); |
5746 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 5746, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true") .c_str()) = ::testing::Message(); |
5747 | 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, "alloc_engine4_unittest.cc", 5747, gtest_ar .failure_message()) = ::testing::Message(); |
5748 | |
5749 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5750 | if (!scenario.exp_allocate_) { |
5751 | 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, "alloc_engine4_unittest.cc", 5751, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "true", "false") .c_str()) = ::testing::Message(); |
5752 | } else { |
5753 | 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, "alloc_engine4_unittest.cc", 5753, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true") .c_str()) = ::testing::Message(); |
5754 | 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, "alloc_engine4_unittest.cc" , 5754, gtest_ar.failure_message()) = ::testing::Message(); |
5755 | 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, "alloc_engine4_unittest.cc" , 5755, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(from_mgr)", "false" , "true") .c_str()) = ::testing::Message(); |
5756 | } |
5757 | } |
5758 | } |
5759 | } |
5760 | |
5761 | } // namespace test |
5762 | } // namespace dhcp |
5763 | } // namespace isc |