File: | home/fedora/workspace/kea-dev/clang-static-analyzer/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc |
Warning: | line 3958, 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/tests/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 | |
24 | #if defined HAVE_MYSQL1 |
25 | #include <mysql/testutils/mysql_schema.h> |
26 | #endif |
27 | |
28 | #if defined HAVE_PGSQL1 |
29 | #include <pgsql/testutils/pgsql_schema.h> |
30 | #endif |
31 | |
32 | #include <boost/pointer_cast.hpp> |
33 | |
34 | using namespace std; |
35 | using namespace isc::hooks; |
36 | using namespace isc::asiolink; |
37 | using namespace isc::data; |
38 | using namespace isc::stats; |
39 | using namespace isc::util; |
40 | |
41 | namespace isc { |
42 | namespace dhcp { |
43 | namespace test { |
44 | |
45 | // This test checks if the v4 Allocation Engine can be instantiated, parses |
46 | // parameters string and allocators are created. |
47 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_constructor_Test( AllocEngine4Test_constructor_Test const &) = delete; void operator=(AllocEngine4Test_constructor_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_constructor_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "constructor", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 47), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 47), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 47) , new ::testing::internal::TestFactoryImpl<AllocEngine4Test_constructor_Test >); void AllocEngine4Test_constructor_Test::TestBody() { |
48 | boost::scoped_ptr<AllocEngine> x; |
49 | |
50 | // Create V4 (ipv6=false) Allocation Engine that will try at most |
51 | // 100 attempts to pick up a lease |
52 | ASSERT_NO_THROW(x.reset(new AllocEngine(100)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { x.reset( new AllocEngine(100)); }; } catch (...) { goto gtest_label_testnothrow_52 ; } } else gtest_label_testnothrow_52: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 52, "Expected: " "x.reset(new AllocEngine(100))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
53 | } |
54 | |
55 | // This test checks if two simple IPv4 allocations succeed and that the |
56 | // statistics is properly updated. Prior to the second allocation it |
57 | // resets the pointer to the last allocated address within the address |
58 | // pool. This causes the engine to walk over the already allocated |
59 | // address and then pick the first available address for the second |
60 | // allocation. Because the allocation engine checks the callouts next |
61 | // step status after each attempt to allocate an address, this test |
62 | // also sets this status to non-default value prior to the second |
63 | // allocation attempt, to make sure that this unexpected status will |
64 | // not interfere with the allocation. |
65 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_simpleAlloc4_Test (AllocEngine4Test_simpleAlloc4_Test const &) = delete; void operator=(AllocEngine4Test_simpleAlloc4_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_simpleAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "simpleAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 65), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 65), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 65) , new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4_Test >); void AllocEngine4Test_simpleAlloc4_Test::TestBody() { |
66 | boost::scoped_ptr<AllocEngine> engine; |
67 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_67 ; } } else gtest_label_testnothrow_67: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 67, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
68 | 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", 68, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
69 | |
70 | // Assigned addresses should be zero. |
71 | 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" , 71, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
72 | |
73 | // Get the cumulative count of assigned addresses. |
74 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
75 | subnet_->getID()); |
76 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
77 | |
78 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
79 | false, true, "somehost.example.com.", false); |
80 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
81 | |
82 | Lease4Ptr lease = engine->allocateLease4(ctx); |
83 | // The new lease has been allocated, so the old lease should not exist. |
84 | 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", 84, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
85 | |
86 | // Check that we got a lease |
87 | ASSERT_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", 87, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
88 | |
89 | // Do all checks on the lease |
90 | checkLease4(lease); |
91 | |
92 | // Check that the lease is indeed in LeaseMgr |
93 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
94 | 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", 94, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
95 | |
96 | // Now check that the lease in LeaseMgr has the same parameters |
97 | detailCompareLease(lease, from_mgr); |
98 | |
99 | // Assigned addresses should have incremented. |
100 | 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" , 100, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
101 | cumulative += 1; |
102 | 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" , 103, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
103 | 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" , 103, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
104 | glbl_cumulative += 1; |
105 | 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" , 105, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
106 | |
107 | // Second allocation starts here. |
108 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
109 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
110 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, IOAddress("0.0.0.0"), |
111 | false, true, "anotherhost.example.com.", |
112 | false); |
113 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
114 | |
115 | // Set the next step to non-default value to verify that it doesn't |
116 | // affect the allocation. |
117 | ctx2.callout_handle_ = HooksManager::createCalloutHandle(); |
118 | ctx2.callout_handle_->setStatus(CalloutHandle::NEXT_STEP_SKIP); |
119 | |
120 | // Set the last allocated to the beginning of the pool. The allocation |
121 | // engine should detect that the first address is already allocated and |
122 | // assign the first available one. |
123 | auto allocation_state = boost::dynamic_pointer_cast<PoolIterativeAllocationState>(pool_->getAllocationState()); |
124 | allocation_state->resetLastAllocated(); |
125 | |
126 | lease = engine->allocateLease4(ctx2); |
127 | |
128 | // The new lease has been allocated, so the old lease should not exist. |
129 | 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", 129, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
130 | |
131 | // Check that we got a lease |
132 | ASSERT_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", 132, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
133 | |
134 | // Check that the lease is indeed in LeaseMgr |
135 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
136 | 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", 136, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
137 | |
138 | // Now check that the lease in LeaseMgr has the same parameters |
139 | detailCompareLease(lease, from_mgr); |
140 | |
141 | // Assigned addresses should have incremented. |
142 | 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" , 142, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 2, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
143 | cumulative += 1; |
144 | 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" , 145, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
145 | 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" , 145, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
146 | glbl_cumulative += 1; |
147 | 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" , 147, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
148 | } |
149 | |
150 | // This test checks that simple allocation uses the default valid lifetime. |
151 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_defaultAlloc4_Test (AllocEngine4Test_defaultAlloc4_Test const &) = delete; void operator=(AllocEngine4Test_defaultAlloc4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_defaultAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "defaultAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 151), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 151), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 151 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultAlloc4_Test >); void AllocEngine4Test_defaultAlloc4_Test::TestBody() { |
152 | boost::scoped_ptr<AllocEngine> engine; |
153 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_153 ; } } else gtest_label_testnothrow_153: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 153, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
154 | 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", 154, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
155 | |
156 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
157 | false, true, "somehost.example.com.", false); |
158 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
159 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
160 | |
161 | Lease4Ptr lease = engine->allocateLease4(ctx); |
162 | // The new lease has been allocated, so the old lease should not exist. |
163 | 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", 163, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
164 | |
165 | // Check that we got a lease |
166 | ASSERT_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", 166, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
167 | |
168 | // Do all checks on the lease |
169 | checkLease4(lease); |
170 | |
171 | // Check the valid lifetime has the default. |
172 | 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", 172, gtest_ar .failure_message()) = ::testing::Message(); |
173 | |
174 | // Check that the lease is indeed in LeaseMgr |
175 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
176 | 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", 176, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
177 | |
178 | // Now check that the lease in LeaseMgr has the same parameters |
179 | detailCompareLease(lease, from_mgr); |
180 | } |
181 | |
182 | // This test checks that simple allocation uses the specified valid lifetime. |
183 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_hintAlloc4_Test(AllocEngine4Test_hintAlloc4_Test const &) = delete; void operator=(AllocEngine4Test_hintAlloc4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_hintAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "hintAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 183), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 183), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 183 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintAlloc4_Test >); void AllocEngine4Test_hintAlloc4_Test::TestBody() { |
184 | boost::scoped_ptr<AllocEngine> engine; |
185 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_185 ; } } else gtest_label_testnothrow_185: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 185, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
186 | 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", 186, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
187 | |
188 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
189 | false, true, "somehost.example.com.", false); |
190 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
191 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
192 | |
193 | // Specify the valid lifetime we want. |
194 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); |
195 | ctx.query_->addOption(opt); |
196 | |
197 | Lease4Ptr lease = engine->allocateLease4(ctx); |
198 | // The new lease has been allocated, so the old lease should not exist. |
199 | 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", 199, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
200 | |
201 | // Check that we got a lease |
202 | ASSERT_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", 202, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
203 | |
204 | // Do all checks on the lease |
205 | checkLease4(lease); |
206 | |
207 | // Check the valid lifetime has the wanted value. |
208 | 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", 208, gtest_ar .failure_message()) = ::testing::Message(); |
209 | |
210 | // Check that the lease is indeed in LeaseMgr |
211 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
212 | 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", 212, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
213 | |
214 | // Now check that the lease in LeaseMgr has the same parameters |
215 | detailCompareLease(lease, from_mgr); |
216 | } |
217 | |
218 | // This test checks that simple allocation uses the min valid lifetime. |
219 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_minAlloc4_Test(AllocEngine4Test_minAlloc4_Test const &) = delete; void operator=(AllocEngine4Test_minAlloc4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_minAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "minAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 219), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 219), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 219 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minAlloc4_Test >); void AllocEngine4Test_minAlloc4_Test::TestBody() { |
220 | boost::scoped_ptr<AllocEngine> engine; |
221 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_221 ; } } else gtest_label_testnothrow_221: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 221, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
222 | 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", 222, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
223 | |
224 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
225 | false, true, "somehost.example.com.", false); |
226 | subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); |
227 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
228 | |
229 | // Specify the valid lifetime we want, as it is lower than the min value |
230 | // we'll get this min value instead. |
231 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); |
232 | ctx.query_->addOption(opt); |
233 | |
234 | Lease4Ptr lease = engine->allocateLease4(ctx); |
235 | // The new lease has been allocated, so the old lease should not exist. |
236 | 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", 236, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
237 | |
238 | // Check that we got a lease |
239 | ASSERT_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", 239, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
240 | |
241 | // Do all checks on the lease |
242 | checkLease4(lease); |
243 | |
244 | // Check the valid lifetime has the wanted value. |
245 | 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" , 245, gtest_ar.failure_message()) = ::testing::Message(); |
246 | |
247 | // Check that the lease is indeed in LeaseMgr |
248 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
249 | 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", 249, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
250 | |
251 | // Now check that the lease in LeaseMgr has the same parameters |
252 | detailCompareLease(lease, from_mgr); |
253 | } |
254 | |
255 | // This test checks that simple allocation uses the max valid lifetime. |
256 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_maxAlloc4_Test(AllocEngine4Test_maxAlloc4_Test const &) = delete; void operator=(AllocEngine4Test_maxAlloc4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_maxAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "maxAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 256), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 256), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 256 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxAlloc4_Test >); void AllocEngine4Test_maxAlloc4_Test::TestBody() { |
257 | boost::scoped_ptr<AllocEngine> engine; |
258 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_258 ; } } else gtest_label_testnothrow_258: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 258, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
259 | 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", 259, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
260 | |
261 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
262 | false, true, "somehost.example.com.", false); |
263 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
264 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
265 | |
266 | // Specify the valid lifetime we want, as it is greater than the max value |
267 | // we'll get this max value instead. |
268 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); |
269 | ctx.query_->addOption(opt); |
270 | |
271 | Lease4Ptr lease = engine->allocateLease4(ctx); |
272 | // The new lease has been allocated, so the old lease should not exist. |
273 | 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", 273, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
274 | |
275 | // Check that we got a lease |
276 | ASSERT_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", 276, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
277 | |
278 | // Do all checks on the lease |
279 | checkLease4(lease); |
280 | |
281 | // Check the valid lifetime has the wanted value. |
282 | 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" , 282, gtest_ar.failure_message()) = ::testing::Message(); |
283 | |
284 | // Check that the lease is indeed in LeaseMgr |
285 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
286 | 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", 286, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
287 | |
288 | // Now check that the lease in LeaseMgr has the same parameters |
289 | detailCompareLease(lease, from_mgr); |
290 | } |
291 | |
292 | // This test checks that simple allocation handles BOOTP queries. |
293 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_bootpAlloc4_Test( AllocEngine4Test_bootpAlloc4_Test const &) = delete; void operator=(AllocEngine4Test_bootpAlloc4_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_bootpAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bootpAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 293), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 293), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 293 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpAlloc4_Test >); void AllocEngine4Test_bootpAlloc4_Test::TestBody() { |
294 | boost::scoped_ptr<AllocEngine> engine; |
295 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_295 ; } } else gtest_label_testnothrow_295: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 295, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
296 | 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", 296, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
297 | |
298 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
299 | false, true, "somehost.example.com.", false); |
300 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
301 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
302 | |
303 | // Make the query a BOOTP one. |
304 | ctx.query_->addClass("BOOTP"); |
305 | |
306 | Lease4Ptr lease = engine->allocateLease4(ctx); |
307 | // The new lease has been allocated, so the old lease should not exist. |
308 | 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", 308, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
309 | |
310 | // Check that we got a lease |
311 | ASSERT_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", 311, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
312 | |
313 | // Check that is belongs to the right subnet and client. |
314 | 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", 314, gtest_ar .failure_message()) = ::testing::Message(); |
315 | 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" , 315, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
316 | 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" , 316, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
317 | 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", 317 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
318 | 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" , 318, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
319 | 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", 319, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
320 | 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" , 320, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
321 | |
322 | // Check the valid lifetime is infinite. |
323 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
324 | 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", 324, gtest_ar .failure_message()) = ::testing::Message(); |
325 | |
326 | // Check that the lease is indeed in LeaseMgr |
327 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
328 | 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", 328, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
329 | |
330 | // Now check that the lease in LeaseMgr has the same parameters |
331 | detailCompareLease(lease, from_mgr); |
332 | } |
333 | |
334 | // This test checks if the fake allocation (for DHCPDISCOVER) can succeed |
335 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_fakeAlloc4_Test(AllocEngine4Test_fakeAlloc4_Test const &) = delete; void operator=(AllocEngine4Test_fakeAlloc4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_fakeAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fakeAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 335), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 335), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 335 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4_Test >); void AllocEngine4Test_fakeAlloc4_Test::TestBody() { |
336 | boost::scoped_ptr<AllocEngine> engine; |
337 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_337 ; } } else gtest_label_testnothrow_337: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 337, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
338 | 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", 338, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
339 | |
340 | // Assigned addresses should be zero. |
341 | 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" , 341, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
342 | |
343 | // Get the cumulative count of assigned addresses. |
344 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
345 | subnet_->getID()); |
346 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
347 | |
348 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
349 | IOAddress("0.0.0.0"), false, true, |
350 | "host.example.com.", true); |
351 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
352 | |
353 | Lease4Ptr lease = engine->allocateLease4(ctx); |
354 | |
355 | // The new lease has been allocated, so the old lease should not exist. |
356 | 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", 356, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
357 | |
358 | // Check that we got a lease |
359 | ASSERT_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", 359, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
360 | |
361 | // Do all checks on the lease |
362 | checkLease4(lease); |
363 | |
364 | // Check that the lease is NOT in LeaseMgr |
365 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
366 | 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", 366, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "true" , "false").c_str()) = ::testing::Message(); |
367 | |
368 | // Assigned addresses should still be zero. |
369 | 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" , 369, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
370 | 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" , 371, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
371 | 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" , 371, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
372 | 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" , 372, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
373 | } |
374 | |
375 | // This test checks if the allocation with a hint that is valid (in range, |
376 | // in pool and free) can succeed |
377 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_allocWithValidHint4_Test (AllocEngine4Test_allocWithValidHint4_Test const &) = delete ; void operator=(AllocEngine4Test_allocWithValidHint4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_allocWithValidHint4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocWithValidHint4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 377), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 377), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 377), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocWithValidHint4_Test >); void AllocEngine4Test_allocWithValidHint4_Test::TestBody () { |
378 | boost::scoped_ptr<AllocEngine> engine; |
379 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_379 ; } } else gtest_label_testnothrow_379: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 379, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
380 | 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", 380, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
381 | |
382 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
383 | IOAddress("192.0.2.105"), true, true, |
384 | "host.example.com.", false); |
385 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
386 | Lease4Ptr lease = engine->allocateLease4(ctx); |
387 | |
388 | // Check that we got a lease |
389 | ASSERT_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", 389, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
390 | |
391 | // We have allocated the new lease, so the old lease should not exist. |
392 | 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", 392, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
393 | |
394 | // We should get what we asked for |
395 | 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", 395, gtest_ar .failure_message()) = ::testing::Message(); |
396 | |
397 | // Do all checks on the lease |
398 | checkLease4(lease); |
399 | |
400 | // Check that the lease is indeed in LeaseMgr |
401 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
402 | 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", 402, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
403 | |
404 | // Now check that the lease in LeaseMgr has the same parameters |
405 | detailCompareLease(lease, from_mgr); |
406 | } |
407 | |
408 | // This test checks if the allocation with a hint that is in range, |
409 | // in pool, but is currently used can succeed |
410 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_allocWithUsedHint4_Test (AllocEngine4Test_allocWithUsedHint4_Test const &) = delete ; void operator=(AllocEngine4Test_allocWithUsedHint4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_allocWithUsedHint4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocWithUsedHint4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 410), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 410), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 410), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocWithUsedHint4_Test >); void AllocEngine4Test_allocWithUsedHint4_Test::TestBody () { |
411 | boost::scoped_ptr<AllocEngine> engine; |
412 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_412 ; } } else gtest_label_testnothrow_412: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 412, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
413 | 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", 413, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
414 | |
415 | // Let's create a lease and put it in the LeaseMgr |
416 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
417 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
418 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
419 | time_t now = time(NULL__null); |
420 | Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2, |
421 | clientid2, sizeof(clientid2), 1, now, subnet_->getID())); |
422 | 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" , 422, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(used)", "false", "true" ).c_str()) = ::testing::Message(); |
423 | |
424 | // Another client comes in and request an address that is in pool, but |
425 | // unfortunately it is used already. The same address must not be allocated |
426 | // twice. |
427 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
428 | IOAddress("192.0.2.106"), false, false, |
429 | "", true); |
430 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
431 | Lease4Ptr lease = engine->allocateLease4(ctx); |
432 | |
433 | // New lease has been allocated, so the old lease should not exist. |
434 | 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", 434, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
435 | |
436 | // Check that we got a lease |
437 | ASSERT_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", 437, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
438 | |
439 | // Allocated address must be different |
440 | 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", 440, gtest_ar. failure_message()) = ::testing::Message(); |
441 | |
442 | // We should NOT get what we asked for, because it is used already |
443 | 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" , 443, gtest_ar.failure_message()) = ::testing::Message(); |
444 | |
445 | // Do all checks on the lease |
446 | checkLease4(lease); |
447 | |
448 | // The lease should not be in the LeaseMgr because it was a failed allocation. |
449 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
450 | 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", 450, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "true" , "false").c_str()) = ::testing::Message(); |
451 | } |
452 | |
453 | // This test checks if an allocation with a hint that is out of the blue |
454 | // can succeed. The invalid hint should be ignored completely. |
455 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_allocBogusHint4_Test (AllocEngine4Test_allocBogusHint4_Test const &) = delete; void operator=(AllocEngine4Test_allocBogusHint4_Test const & ) = delete; }; ::testing::TestInfo* const AllocEngine4Test_allocBogusHint4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocBogusHint4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 455), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 455), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 455 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocBogusHint4_Test >); void AllocEngine4Test_allocBogusHint4_Test::TestBody() { |
456 | boost::scoped_ptr<AllocEngine> engine; |
457 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_457 ; } } else gtest_label_testnothrow_457: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 457, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
458 | 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", 458, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
459 | |
460 | // Client would like to get a 10.1.1.1 lease, which does not belong to any |
461 | // supported lease. Allocation engine should ignore it and carry on |
462 | // with the normal allocation |
463 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
464 | IOAddress("10.1.1.1"), false, false, |
465 | "", true); |
466 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
467 | Lease4Ptr lease = engine->allocateLease4(ctx); |
468 | // Check that we got a lease |
469 | ASSERT_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", 469, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
470 | |
471 | // We have allocated a new lease, so the old lease should not exist. |
472 | 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", 472, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
473 | |
474 | // We should NOT get what we asked for, because it is used already |
475 | 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", 475, gtest_ar .failure_message()) = ::testing::Message(); |
476 | |
477 | // Do all checks on the lease |
478 | checkLease4(lease); |
479 | |
480 | // Check that the lease is not in the LeaseMgr as it is a fake allocation. |
481 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
482 | 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", 482, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "from_mgr", "true", "false").c_str()) = ::testing ::Message(); |
483 | } |
484 | |
485 | // This test checks that NULL values are handled properly |
486 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_allocateLease4Nulls_Test (AllocEngine4Test_allocateLease4Nulls_Test const &) = delete ; void operator=(AllocEngine4Test_allocateLease4Nulls_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_allocateLease4Nulls_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "allocateLease4Nulls", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 486), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 486), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 486), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_allocateLease4Nulls_Test >); void AllocEngine4Test_allocateLease4Nulls_Test::TestBody () { |
487 | boost::scoped_ptr<AllocEngine> engine; |
488 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_488 ; } } else gtest_label_testnothrow_488: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 488, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
489 | 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", 489, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
490 | |
491 | // Allocations without subnet are not allowed |
492 | AllocEngine::ClientContext4 ctx1(Subnet4Ptr(), clientid_, hwaddr_, |
493 | IOAddress("0.0.0.0"), false, false, |
494 | "", false); |
495 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
496 | Lease4Ptr lease = engine->allocateLease4(ctx1); |
497 | |
498 | 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", 498, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false").c_str()) = ::testing::Message(); |
499 | |
500 | 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", 500, gtest_ar.failure_message( )) = ::testing::Message(); |
501 | 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", 501, gtest_ar. failure_message()) = ::testing::Message(); |
502 | 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", 502, gtest_ar.failure_message( )) = ::testing::Message(); |
503 | 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", 503, gtest_ar.failure_message( )) = ::testing::Message(); |
504 | 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", 504, gtest_ar.failure_message( )) = ::testing::Message(); |
505 | |
506 | 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", 506, gtest_ar .failure_message()) = ::testing::Message(); |
507 | 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" , 507, gtest_ar.failure_message()) = ::testing::Message(); |
508 | 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", 508, gtest_ar .failure_message()) = ::testing::Message(); |
509 | 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" , 509, gtest_ar.failure_message()) = ::testing::Message(); |
510 | 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" , 510, gtest_ar.failure_message()) = ::testing::Message(); |
511 | |
512 | // Allocations without HW address are not allowed |
513 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, HWAddrPtr(), |
514 | IOAddress("0.0.0.0"), false, false, |
515 | "", false); |
516 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
517 | lease = engine->allocateLease4(ctx2); |
518 | 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", 518, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false").c_str()) = ::testing::Message(); |
519 | 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", 519, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
520 | |
521 | 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", 521, gtest_ar.failure_message( )) = ::testing::Message(); |
522 | 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", 522, gtest_ar. failure_message()) = ::testing::Message(); |
523 | 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", 523, gtest_ar.failure_message( )) = ::testing::Message(); |
524 | 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", 524, gtest_ar.failure_message( )) = ::testing::Message(); |
525 | 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", 525, gtest_ar.failure_message( )) = ::testing::Message(); |
526 | |
527 | 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", 527, gtest_ar .failure_message()) = ::testing::Message(); |
528 | 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" , 528, gtest_ar.failure_message()) = ::testing::Message(); |
529 | 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", 529, gtest_ar .failure_message()) = ::testing::Message(); |
530 | 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" , 530, gtest_ar.failure_message()) = ::testing::Message(); |
531 | 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" , 531, gtest_ar.failure_message()) = ::testing::Message(); |
532 | |
533 | // Allocations without client-id are allowed |
534 | clientid_.reset(); |
535 | AllocEngine::ClientContext4 ctx3(subnet_, ClientIdPtr(), hwaddr_, |
536 | IOAddress("0.0.0.0"), false, false, |
537 | "", false); |
538 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
539 | lease = engine->allocateLease4(ctx3); |
540 | |
541 | // Check that we got a lease |
542 | ASSERT_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", 542, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
543 | // New lease has been allocated, so the old lease should not exist. |
544 | 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", 544, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx3.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
545 | |
546 | // Do all checks on the lease |
547 | checkLease4(lease); |
548 | |
549 | // Check that the lease is indeed in LeaseMgr |
550 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
551 | 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", 551, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
552 | |
553 | // Now check that the lease in LeaseMgr has the same parameters |
554 | detailCompareLease(lease, from_mgr); |
555 | } |
556 | |
557 | // This test checks if a returning client can renew an |
558 | // an existing lease and assigned-leases increments accordingly |
559 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_simpleRenew4_Test (AllocEngine4Test_simpleRenew4_Test const &) = delete; void operator=(AllocEngine4Test_simpleRenew4_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_simpleRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "simpleRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 559), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 559), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 559 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleRenew4_Test >); void AllocEngine4Test_simpleRenew4_Test::TestBody() { |
560 | boost::scoped_ptr<AllocEngine> engine; |
561 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_561 ; } } else gtest_label_testnothrow_561: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 561, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
562 | 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", 562, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
563 | |
564 | 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" , 564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
565 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
566 | subnet_->getID()); |
567 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
568 | |
569 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
570 | false, true, "somehost.example.com.", false); |
571 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
572 | |
573 | Lease4Ptr lease = engine->allocateLease4(ctx); |
574 | |
575 | // Check that we got a lease and it's sane |
576 | ASSERT_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", 576, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
577 | checkLease4(lease); |
578 | |
579 | // The new lease has been allocated, so the old lease should not exist. |
580 | 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", 580, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
581 | |
582 | // We should have incremented assigned-addresses |
583 | 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" , 583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
584 | cumulative += 1; |
585 | 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" , 586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
586 | 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" , 586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
587 | glbl_cumulative += 1; |
588 | 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" , 588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
589 | |
590 | // Do it again, this should amount to the renew of an existing lease |
591 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
592 | |
593 | // Check that we got a lease and it's sane |
594 | 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", 594, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true").c_str()) = ::testing::Message(); |
595 | checkLease4(lease2); |
596 | |
597 | // Lease already existed, so old_lease should be set. |
598 | 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", 598, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
599 | |
600 | // Should NOT have bumped assigned-addresses |
601 | 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" , 601, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 1, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
602 | 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" , 603, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
603 | 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" , 603, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
604 | 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" , 604, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
605 | } |
606 | |
607 | // This test checks simple renewal uses the default valid lifetime. |
608 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_defaultRenew4_Test (AllocEngine4Test_defaultRenew4_Test const &) = delete; void operator=(AllocEngine4Test_defaultRenew4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_defaultRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "defaultRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 608), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 608), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 608 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_defaultRenew4_Test >); void AllocEngine4Test_defaultRenew4_Test::TestBody() { |
609 | boost::scoped_ptr<AllocEngine> engine; |
610 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_610 ; } } else gtest_label_testnothrow_610: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 610, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
611 | 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", 611, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
612 | |
613 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
614 | false, true, "somehost.example.com.", false); |
615 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
616 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
617 | |
618 | Lease4Ptr lease = engine->allocateLease4(ctx); |
619 | |
620 | // Check that we got a lease and it's sane |
621 | ASSERT_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", 621, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
622 | checkLease4(lease); |
623 | |
624 | // Check the valid lifetime has the default. |
625 | 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", 625, gtest_ar .failure_message()) = ::testing::Message(); |
626 | |
627 | // The new lease has been allocated, so the old lease should not exist. |
628 | 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", 628, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
629 | |
630 | // Do it again, this should amount to the renew of an existing lease |
631 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
632 | |
633 | // Check that we got a lease and it's sane |
634 | 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", 634, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true").c_str()) = ::testing::Message(); |
635 | checkLease4(lease2); |
636 | |
637 | // Lease already existed, so old_lease should be set. |
638 | 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", 638, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
639 | |
640 | // Check the renewed valid lifetime has the default. |
641 | 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" , 641, gtest_ar.failure_message()) = ::testing::Message(); |
642 | } |
643 | |
644 | // This test checks simple renewal uses the specified valid lifetime. |
645 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_hintRenew4_Test(AllocEngine4Test_hintRenew4_Test const &) = delete; void operator=(AllocEngine4Test_hintRenew4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_hintRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "hintRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 645), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 645), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 645 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_hintRenew4_Test >); void AllocEngine4Test_hintRenew4_Test::TestBody() { |
646 | boost::scoped_ptr<AllocEngine> engine; |
647 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_647 ; } } else gtest_label_testnothrow_647: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 647, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
648 | 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", 648, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
649 | |
650 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
651 | false, true, "somehost.example.com.", false); |
652 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
653 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
654 | |
655 | // Specify the valid lifetime we want. |
656 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); |
657 | ctx.query_->addOption(opt); |
658 | |
659 | Lease4Ptr lease = engine->allocateLease4(ctx); |
660 | |
661 | // Check that we got a lease and it's sane |
662 | ASSERT_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", 662, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
663 | checkLease4(lease); |
664 | |
665 | // Check the valid lifetime has the wanted value. |
666 | 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", 666, gtest_ar .failure_message()) = ::testing::Message(); |
667 | |
668 | // The new lease has been allocated, so the old lease should not exist. |
669 | 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", 669, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
670 | |
671 | // Do it again, this should amount to the renew of an existing lease |
672 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
673 | |
674 | // Check that we got a lease and it's sane |
675 | 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", 675, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true").c_str()) = ::testing::Message(); |
676 | checkLease4(lease2); |
677 | |
678 | // Lease already existed, so old_lease should be set. |
679 | 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", 679, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
680 | |
681 | // Check the renewed valid lifetime has the wanted value. |
682 | 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", 682, gtest_ar .failure_message()) = ::testing::Message(); |
683 | } |
684 | |
685 | // This test checks simple renewal uses the min valid lifetime. |
686 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_minRenew4_Test(AllocEngine4Test_minRenew4_Test const &) = delete; void operator=(AllocEngine4Test_minRenew4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_minRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "minRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 686), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 686), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 686 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_minRenew4_Test >); void AllocEngine4Test_minRenew4_Test::TestBody() { |
687 | boost::scoped_ptr<AllocEngine> engine; |
688 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_688 ; } } else gtest_label_testnothrow_688: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 688, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
689 | 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", 689, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
690 | |
691 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
692 | false, true, "somehost.example.com.", false); |
693 | subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); |
694 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
695 | |
696 | // Specify the valid lifetime we want, as it is lower than the min value |
697 | // we'll get this min value instead. |
698 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); |
699 | ctx.query_->addOption(opt); |
700 | |
701 | Lease4Ptr lease = engine->allocateLease4(ctx); |
702 | |
703 | // Check that we got a lease and it's sane |
704 | ASSERT_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", 704, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
705 | checkLease4(lease); |
706 | |
707 | // Check the valid lifetime has the min value. |
708 | 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" , 708, gtest_ar.failure_message()) = ::testing::Message(); |
709 | |
710 | // The new lease has been allocated, so the old lease should not exist. |
711 | 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", 711, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
712 | |
713 | // Do it again, this should amount to the renew of an existing lease |
714 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
715 | |
716 | // Check that we got a lease and it's sane |
717 | 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", 717, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true").c_str()) = ::testing::Message(); |
718 | checkLease4(lease2); |
719 | |
720 | // Lease already existed, so old_lease should be set. |
721 | 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", 721, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
722 | |
723 | // Check the renewed valid lifetime has the min value. |
724 | 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" , 724, gtest_ar.failure_message()) = ::testing::Message(); |
725 | } |
726 | |
727 | // This test checks simple renewal uses the max valid lifetime. |
728 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_maxRenew4_Test(AllocEngine4Test_maxRenew4_Test const &) = delete; void operator=(AllocEngine4Test_maxRenew4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_maxRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "maxRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 728), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 728), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 728 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_maxRenew4_Test >); void AllocEngine4Test_maxRenew4_Test::TestBody() { |
729 | boost::scoped_ptr<AllocEngine> engine; |
730 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_730 ; } } else gtest_label_testnothrow_730: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 730, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
731 | 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", 731, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
732 | |
733 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
734 | false, true, "somehost.example.com.", false); |
735 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
736 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
737 | |
738 | // Specify the valid lifetime we want, as it is greater than the max value |
739 | // we'll get this max value instead. |
740 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); |
741 | ctx.query_->addOption(opt); |
742 | |
743 | Lease4Ptr lease = engine->allocateLease4(ctx); |
744 | |
745 | // Check that we got a lease and it's sane |
746 | ASSERT_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", 746, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
747 | checkLease4(lease); |
748 | |
749 | // Check the valid lifetime has the max value. |
750 | 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" , 750, gtest_ar.failure_message()) = ::testing::Message(); |
751 | |
752 | // The new lease has been allocated, so the old lease should not exist. |
753 | 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", 753, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
754 | |
755 | // Do it again, this should amount to the renew of an existing lease |
756 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
757 | |
758 | // Check that we got a lease and it's sane |
759 | 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", 759, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true").c_str()) = ::testing::Message(); |
760 | checkLease4(lease2); |
761 | |
762 | // Lease already existed, so old_lease should be set. |
763 | 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", 763, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
764 | |
765 | // Check the renewed valid lifetime has the max value. |
766 | 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" , 766, gtest_ar.failure_message()) = ::testing::Message(); |
767 | } |
768 | |
769 | // This test checks simple renewal handles BOOTP queries. |
770 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_bootpRenew4_Test( AllocEngine4Test_bootpRenew4_Test const &) = delete; void operator=(AllocEngine4Test_bootpRenew4_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_bootpRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bootpRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 770), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 770), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 770 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpRenew4_Test >); void AllocEngine4Test_bootpRenew4_Test::TestBody() { |
771 | boost::scoped_ptr<AllocEngine> engine; |
772 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_772 ; } } else gtest_label_testnothrow_772: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 772, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
773 | 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", 773, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
774 | |
775 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
776 | false, true, "somehost.example.com.", false); |
777 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
778 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
779 | |
780 | // Make the query a BOOTP one. |
781 | ctx.query_->addClass("BOOTP"); |
782 | |
783 | Lease4Ptr lease = engine->allocateLease4(ctx); |
784 | |
785 | // Check that we got a lease. |
786 | ASSERT_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", 786, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
787 | |
788 | // Check that is belongs to the right subnet and client. |
789 | 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", 789, gtest_ar .failure_message()) = ::testing::Message(); |
790 | 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" , 790, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
791 | 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" , 791, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
792 | 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", 792 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
793 | 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" , 793, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
794 | 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", 794, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
795 | 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" , 795, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
796 | |
797 | // Check the valid lifetime is infinite. |
798 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
799 | 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", 799, gtest_ar .failure_message()) = ::testing::Message(); |
800 | |
801 | // The new lease has been allocated, so the old lease should not exist. |
802 | 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", 802, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
803 | |
804 | // Do it again, this should amount to the renew of an existing lease |
805 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
806 | |
807 | // Check that we got a lease. |
808 | 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", 808, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "false" , "true").c_str()) = ::testing::Message(); |
809 | |
810 | // Check that is belongs to the right subnet and client. |
811 | 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", 811, gtest_ar .failure_message()) = ::testing::Message(); |
812 | 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" , 812, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease2->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
813 | 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" , 813, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
814 | 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", 814 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
815 | 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" , 815, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
816 | 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", 816, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
817 | 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" , 817, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->hwaddr_ == *hwaddr_", "false", "true").c_str() ) = ::testing::Message(); |
818 | |
819 | // Lease already existed, so old_lease should be set. |
820 | 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", 820, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
821 | |
822 | // Check the renewed valid lifetime has the max value. |
823 | 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", 823, gtest_ar .failure_message()) = ::testing::Message(); |
824 | } |
825 | |
826 | // This test checks if really small pools are working |
827 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_smallPool4_Test(AllocEngine4Test_smallPool4_Test const &) = delete; void operator=(AllocEngine4Test_smallPool4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_smallPool4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "smallPool4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 827), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 827), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 827 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_smallPool4_Test >); void AllocEngine4Test_smallPool4_Test::TestBody() { |
828 | boost::scoped_ptr<AllocEngine> engine; |
829 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_829 ; } } else gtest_label_testnothrow_829: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 829, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
830 | 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", 830, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
831 | |
832 | IOAddress addr("192.0.2.17"); |
833 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
834 | |
835 | // Get rid of the default subnet configuration. |
836 | cfg_mgr.clear(); |
837 | |
838 | // Create configuration similar to other tests, but with a single address pool |
839 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
840 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
841 | subnet_->addPool(pool_); |
842 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
843 | |
844 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
845 | IOAddress("0.0.0.0"), false, false, |
846 | "host.example.com.", false); |
847 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
848 | Lease4Ptr lease = engine->allocateLease4(ctx); |
849 | |
850 | // Check that we got that single lease |
851 | ASSERT_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", 851, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false" , "true").c_str()) = ::testing::Message(); |
852 | |
853 | // We have allocated new lease, so the old lease should not exist. |
854 | 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", 854, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
855 | |
856 | 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", 856, gtest_ar .failure_message()) = ::testing::Message(); |
857 | |
858 | // Do all checks on the lease |
859 | checkLease4(lease); |
860 | |
861 | // Check that the lease is indeed in LeaseMgr |
862 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
863 | 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", 863, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr", "false" , "true").c_str()) = ::testing::Message(); |
864 | |
865 | // Now check that the lease in LeaseMgr has the same parameters |
866 | detailCompareLease(lease, from_mgr); |
867 | } |
868 | |
869 | // This test checks if all addresses in a pool are currently used, the attempt |
870 | // to find out a new lease fails. |
871 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_outOfAddresses4_Test (AllocEngine4Test_outOfAddresses4_Test const &) = delete; void operator=(AllocEngine4Test_outOfAddresses4_Test const & ) = delete; }; ::testing::TestInfo* const AllocEngine4Test_outOfAddresses4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "outOfAddresses4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 871), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 871), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 871 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_outOfAddresses4_Test >); void AllocEngine4Test_outOfAddresses4_Test::TestBody() { |
872 | boost::scoped_ptr<AllocEngine> engine; |
873 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_873 ; } } else gtest_label_testnothrow_873: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 873, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
874 | ASSERT_TRUE(engine)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(engine)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 874, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "engine", "false" , "true").c_str()) = ::testing::Message(); |
875 | |
876 | IOAddress addr("192.0.2.17"); |
877 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
878 | // Get rid of the default test configuration. |
879 | cfg_mgr.clear(); |
880 | |
881 | // Create configuration similar to other tests, but with a single address pool |
882 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
883 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
884 | subnet_->addPool(pool_); |
885 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
886 | |
887 | // Just a different hw/client-id for the second client |
888 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
889 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
890 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
891 | time_t now = time(NULL__null); |
892 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, |
893 | sizeof(clientid2), 501, now, |
894 | subnet_->getID())); |
895 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
896 | 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" , 896, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
897 | |
898 | // There is just a single address in the pool and allocated it to someone |
899 | // else, so the allocation should fail |
900 | |
901 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
902 | IOAddress("0.0.0.0"), false, false, |
903 | "host.example.com.", false); |
904 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
905 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
906 | 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", 906, ::testing::internal ::GetBoolAssertionFailureMessage( gtest_ar_, "lease2", "true" , "false").c_str()) = ::testing::Message(); |
907 | 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", 907, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
908 | |
909 | 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", 909, gtest_ar.failure_message( )) = ::testing::Message(); |
910 | 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", 910, gtest_ar. failure_message()) = ::testing::Message(); |
911 | 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", 911, gtest_ar.failure_message( )) = ::testing::Message(); |
912 | 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", 912, gtest_ar.failure_message( )) = ::testing::Message(); |
913 | 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", 913, gtest_ar.failure_message( )) = ::testing::Message(); |
914 | |
915 | 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", 915, gtest_ar .failure_message()) = ::testing::Message(); |
916 | 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" , 916, gtest_ar.failure_message()) = ::testing::Message(); |
917 | 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", 917, gtest_ar .failure_message()) = ::testing::Message(); |
918 | 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" , 918, gtest_ar.failure_message()) = ::testing::Message(); |
919 | 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" , 919, gtest_ar.failure_message()) = ::testing::Message(); |
920 | } |
921 | |
922 | /// @brief This test class is dedicated to testing shared networks |
923 | /// |
924 | /// It uses one common configuration: |
925 | /// 1 shared network with 2 subnets: |
926 | /// - 192.0.2.0/24 subnet with a small pool of single address: 192.0.2.17 |
927 | /// - 10.1.2.0/24 subnet with pool with 96 addresses. |
928 | class SharedNetworkAlloc4Test : public AllocEngine4Test { |
929 | public: |
930 | |
931 | /// @brief Initializes configuration (2 subnets, 1 shared network) |
932 | SharedNetworkAlloc4Test() : engine_(0) { |
933 | // Create two subnets, each with a single address pool. The first subnet |
934 | // has only one address in its address pool to make it easier to simulate |
935 | // address exhaustion. |
936 | subnet1_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
937 | subnet2_ = Subnet4::create(IOAddress("10.1.2.0"), 24, 1, 2, 3, SubnetID(20)); |
938 | pool1_.reset(new Pool4(IOAddress("192.0.2.17"), IOAddress("192.0.2.17"))); |
939 | pool2_.reset(new Pool4(IOAddress("10.1.2.5"), IOAddress("10.1.2.100"))); |
940 | |
941 | subnet1_->addPool(pool1_); |
942 | subnet2_->addPool(pool2_); |
943 | |
944 | // Both subnets belong to the same network so they can be used |
945 | // interchangeably. |
946 | network_.reset(new SharedNetwork4("test_network")); |
947 | network_->add(subnet1_); |
948 | network_->add(subnet2_); |
949 | |
950 | std::vector<uint8_t> hwaddr_vec = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
951 | hwaddr2_.reset(new HWAddr(hwaddr_vec, HTYPE_ETHER)); |
952 | } |
953 | |
954 | /// @brief Inserts a new lease for specified address |
955 | /// |
956 | /// Creates a new lease for specified address and subnet-id and inserts |
957 | /// it into database. This is not particularly fancy method, it is used |
958 | /// just to mark existing addresses as used. It uses hwaddr2_ to allocate |
959 | /// the lease. |
960 | /// |
961 | /// @param addr text representation of the address |
962 | /// @param subnet_id ID of the subnet |
963 | /// @param return pointer to the lease |
964 | Lease4Ptr |
965 | insertLease(std::string addr, SubnetID subnet_id) { |
966 | Lease4Ptr lease(new Lease4(IOAddress(addr), hwaddr2_, ClientIdPtr(), |
967 | 501, time(NULL__null), subnet_id)); |
968 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
969 | if (!LeaseMgrFactory::instance().addLease(lease)) { |
970 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "alloc_engine4_unittest.cc", 970, "Failed") = ::testing::Message() << "Attempt to add a lease for IP " << addr |
971 | << " in subnet " << subnet_id << " failed"; |
972 | } |
973 | |
974 | return (lease); |
975 | } |
976 | |
977 | /// Convenience pointers to configuration elements. These are initialized |
978 | /// in the constructor and are used throughout the tests. |
979 | AllocEngine engine_; |
980 | Subnet4Ptr subnet1_; |
981 | Subnet4Ptr subnet2_; |
982 | Pool4Ptr pool1_; |
983 | Pool4Ptr pool2_; |
984 | SharedNetwork4Ptr network_; |
985 | |
986 | HWAddrPtr hwaddr2_; // Note there's hwaddr_ already defined in base class. |
987 | }; |
988 | |
989 | // This test verifies that the server can offer an address from a |
990 | // subnet and the introduction of shared network doesn't break anything here. |
991 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test (SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkSimple", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 991), (:: testing::internal::GetTypeId<SharedNetworkAlloc4Test>() ), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 991), :: testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 991 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkSimple_Test ::TestBody() { |
992 | |
993 | // Create context which will be used to try to allocate leases from the |
994 | // shared network. The context points to subnet1, which address space |
995 | // is exhausted. We expect the allocation engine to find another subnet |
996 | // within the same shared network and offer an address from there. |
997 | AllocEngine::ClientContext4 |
998 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
999 | false, false, "host.example.com.", true); |
1000 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1001 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1002 | |
1003 | // The allocation engine should have assigned an address from the first |
1004 | // subnet. |
1005 | ASSERT_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", 1005, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1006 | 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", 1006, gtest_ar .failure_message()) = ::testing::Message(); |
1007 | |
1008 | // Make sure the lease is not in the lease mgr (this is only |
1009 | // discover). |
1010 | 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" , 1010, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
1011 | } |
1012 | |
1013 | // This test verifies that the server will pick a second subnet out of two |
1014 | // shared subnets if there is a hint for the second subnet. |
1015 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test (SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkHint", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1015), (::testing ::internal::GetTypeId<SharedNetworkAlloc4Test>()), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1015), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1015), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkHint_Test ::TestBody() { |
1016 | |
1017 | // Create context which will be used to try to allocate leases from the |
1018 | // shared network. The context points to subnet1, which address space |
1019 | // is exhausted. We expect the allocation engine to find another subnet |
1020 | // within the same shared network and offer an address from there. |
1021 | |
1022 | AllocEngine::ClientContext4 |
1023 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress("10.1.2.25"), |
1024 | false, false, "host.example.com.", true); |
1025 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1026 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1027 | |
1028 | // The allocation engine should have assigned an address from the second |
1029 | // subnet, because that's what the hint requested. |
1030 | ASSERT_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", 1030, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1031 | 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" , 1031, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1032 | } |
1033 | |
1034 | // This test verifies that the server can offer an address from a |
1035 | // different subnet than orginally selected, when the address pool in |
1036 | // the first subnet is exhausted. |
1037 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetwork_Test (SharedNetworkAlloc4Test_discoverSharedNetwork_Test const & ) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetwork_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetwork_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetwork", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1037), (::testing ::internal::GetTypeId<SharedNetworkAlloc4Test>()), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1037), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1037), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetwork_Test >); void SharedNetworkAlloc4Test_discoverSharedNetwork_Test ::TestBody() { |
1038 | // Create a lease for a single address in the first address pool. The |
1039 | // pool is now exhausted. |
1040 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
1041 | |
1042 | // Create context which will be used to try to allocate leases from the |
1043 | // shared network. The context points to subnet1, which address space |
1044 | // is exhausted. We expect the allocation engine to find another subnet |
1045 | // within the same shared network and offer an address from there. |
1046 | AllocEngine::ClientContext4 |
1047 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1048 | false, false, "host.example.com.", true); |
1049 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1050 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
1051 | // The allocation engine should have assigned an address from the second |
1052 | // subnet. We could guess that this is 10.1.2.5, being the first address |
1053 | // in the address pool, but to make the test more generic, we merely |
1054 | // verify that the address is in the given address pool. |
1055 | 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", 1055, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
1056 | 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" , 1056, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1057 | |
1058 | // The client should also be offered a lease when it specifies a hint |
1059 | // that doesn't match the subnet from which the lease is offered. The |
1060 | // engine should check alternative subnets to match the hint to |
1061 | // a subnet. The requested lease is available, so it should be offered. |
1062 | ctx.subnet_ = subnet1_; |
1063 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
1064 | lease2 = engine_.allocateLease4(ctx); |
1065 | 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", 1065, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
1066 | 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" , 1066, gtest_ar.failure_message()) = ::testing::Message(); |
1067 | |
1068 | // The returning client (the one that has a lease) should also be able |
1069 | // to renew its lease regardless of a subnet it begins with. So, it has |
1070 | // an address assigned from subnet1, but we use subnet2 as a selected |
1071 | // subnet. |
1072 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
1073 | IOAddress("0.0.0.0"), false, false, |
1074 | "host.example.com.", true); |
1075 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1076 | lease2 = engine_.allocateLease4(ctx2); |
1077 | // The existing lease should be returned. |
1078 | 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", 1078, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
1079 | 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" , 1079, gtest_ar.failure_message()) = ::testing::Message(); |
1080 | } |
1081 | |
1082 | // This test verifies that the server can offer an address from a |
1083 | // different subnet than orginally selected, when the address pool in |
1084 | // the first subnet is exhausted. |
1085 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test (SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkClassification", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 1085 ), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1085), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1085 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkClassification_Test ::TestBody() { |
1086 | |
1087 | // Try to offer address from subnet1. There is one address available |
1088 | // so it should be offered. |
1089 | AllocEngine::ClientContext4 |
1090 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1091 | false, false, "host.example.com.", true); |
1092 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1093 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1094 | ASSERT_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", 1094, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1095 | 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" , 1095, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1096 | |
1097 | // Apply restrictions on the subnet1. This should be only assigned |
1098 | // to clients belonging to cable-modem class. |
1099 | subnet1_->allowClientClass("cable-modem"); |
1100 | |
1101 | // The allocation engine should determine that the subnet1 is not |
1102 | // available for the client not belonging to the cable-modem class. |
1103 | // Instead, it should offer an address from subnet2 that belongs |
1104 | // to the same shared network. |
1105 | ctx.subnet_ = subnet1_; |
1106 | lease = engine_.allocateLease4(ctx); |
1107 | ASSERT_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", 1107, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1108 | 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" , 1108, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1109 | |
1110 | // Create reservation for the client in subnet1. Because this subnet is |
1111 | // not allowed for the client the client should still be offered a |
1112 | // lease from subnet2. |
1113 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1114 | Host::IDENT_HWADDR, subnet1_->getID(), |
1115 | SUBNET_ID_UNUSED, IOAddress("192.0.2.17"))); |
1116 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1117 | CfgMgr::instance().commit(); |
1118 | AllocEngine::findReservation(ctx); |
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_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" , 1123, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1124 | |
1125 | // Assign cable-modem class and try again. This time, we should |
1126 | // offer an address from the subnet1. |
1127 | ctx.query_->addClass(ClientClass("cable-modem")); |
1128 | |
1129 | ctx.subnet_ = subnet1_; |
1130 | lease = engine_.allocateLease4(ctx); |
1131 | ASSERT_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", 1131, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1132 | 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", 1132, gtest_ar .failure_message()) = ::testing::Message(); |
1133 | } |
1134 | |
1135 | // This test verifies that the server can offer an address from a |
1136 | // different subnet than orginally selected, when the address pool in |
1137 | // the first subnet requires another class. |
1138 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test (SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkPoolClassification", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1138), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1138), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1138 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkPoolClassification_Test ::TestBody() { |
1139 | |
1140 | // Try to offer address from subnet1. There is one address available |
1141 | // so it should be offered. |
1142 | AllocEngine::ClientContext4 |
1143 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1144 | false, false, "host.example.com.", true); |
1145 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1146 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1147 | ASSERT_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", 1147, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1148 | 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" , 1148, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1149 | |
1150 | // Apply restrictions on the pool1. This should be only assigned |
1151 | // to clients belonging to cable-modem class. |
1152 | pool1_->allowClientClass("cable-modem"); |
1153 | |
1154 | // The allocation engine should determine that the pool1 is not |
1155 | // available for the client not belonging to the cable-modem class. |
1156 | // Instead, it should offer an address from subnet2 that belongs |
1157 | // to the same shared network. |
1158 | ctx.subnet_ = subnet1_; |
1159 | lease = engine_.allocateLease4(ctx); |
1160 | ASSERT_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", 1160, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1161 | 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" , 1161, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1162 | |
1163 | // Assign cable-modem class and try again. This time, we should |
1164 | // offer an address from the pool1. |
1165 | ctx.query_->addClass(ClientClass("cable-modem")); |
1166 | |
1167 | // Restrict access to pool2 for this client, to make sure that the |
1168 | // server doesn't accidentally get an address from this pool. |
1169 | pool2_->allowClientClass("telephone"); |
1170 | |
1171 | ctx.subnet_ = subnet1_; |
1172 | lease = engine_.allocateLease4(ctx); |
1173 | ASSERT_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", 1173, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1174 | 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", 1174, gtest_ar .failure_message()) = ::testing::Message(); |
1175 | } |
1176 | |
1177 | // Test that global reservations within shared network take precedence over the |
1178 | // existing leases regardless in which subnet belonging to a shared network |
1179 | // reservations belong. |
1180 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test (SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkReservationsGlobal", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1180), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1180), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1180 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsGlobal_Test ::TestBody() { |
1181 | |
1182 | 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" , 1182, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ).c_str()) = ::testing::Message(); |
1183 | |
1184 | // Create reservation for the client. |
1185 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1186 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
1187 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1188 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1189 | CfgMgr::instance().commit(); |
1190 | |
1191 | subnet1_->setReservationsGlobal(true); |
1192 | subnet1_->setReservationsInSubnet(true); |
1193 | subnet2_->setReservationsGlobal(true); |
1194 | subnet2_->setReservationsInSubnet(true); |
1195 | |
1196 | // Start allocation from subnet1. The engine should determine that the |
1197 | // client has global reservations within subnet2 and should rather |
1198 | // assign reserved addresses. |
1199 | AllocEngine::ClientContext4 |
1200 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1201 | false, false, "host.example.com.", true); |
1202 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1203 | AllocEngine::findReservation(ctx); |
1204 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1205 | ASSERT_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", 1205, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1206 | 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", 1206, gtest_ar .failure_message()) = ::testing::Message(); |
1207 | 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" , 1207, gtest_ar.failure_message()) = ::testing::Message(); |
1208 | |
1209 | // Let's create a lease for the client to make sure the lease is not |
1210 | // renewed but a reserved lease is offered. |
1211 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1212 | 501, time(NULL__null), subnet1_->getID())); |
1213 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1214 | 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" , 1214, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ).c_str()) = ::testing::Message(); |
1215 | ctx.subnet_ = subnet1_; |
1216 | ctx.hosts_.clear(); |
1217 | AllocEngine::findReservation(ctx); |
1218 | lease = engine_.allocateLease4(ctx); |
1219 | ASSERT_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", 1219, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1220 | 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", 1220, gtest_ar .failure_message()) = ::testing::Message(); |
1221 | 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" , 1221, gtest_ar.failure_message()) = ::testing::Message(); |
1222 | } |
1223 | |
1224 | |
1225 | // Test that reservations within shared network take precedence over the |
1226 | // existing leases regardless in which subnet belonging to a shared network |
1227 | // reservations belong. |
1228 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test (SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkReservations", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1228), ( ::testing::internal::GetTypeId<SharedNetworkAlloc4Test> ()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1228), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1228 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservations_Test ::TestBody() { |
1229 | |
1230 | 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" , 1230, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ).c_str()) = ::testing::Message(); |
1231 | |
1232 | // Create reservation for the client. |
1233 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1234 | Host::IDENT_HWADDR, subnet2_->getID(), |
1235 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1236 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1237 | CfgMgr::instance().commit(); |
1238 | |
1239 | // Start allocation from subnet1. The engine should determine that the |
1240 | // client has reservations in subnet2 and should rather assign reserved |
1241 | // addresses. |
1242 | AllocEngine::ClientContext4 |
1243 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1244 | false, false, "host.example.com.", true); |
1245 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1246 | AllocEngine::findReservation(ctx); |
1247 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1248 | ASSERT_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", 1248, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1249 | 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", 1249, gtest_ar .failure_message()) = ::testing::Message(); |
1250 | 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" , 1250, gtest_ar.failure_message()) = ::testing::Message(); |
1251 | |
1252 | // Let's create a lease for the client in subnet1 to make sure the lease |
1253 | // is not renewed but a reserved lease is offered. |
1254 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1255 | 501, time(NULL__null), subnet1_->getID())); |
1256 | lease2->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1257 | 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" , 1257, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ).c_str()) = ::testing::Message(); |
1258 | ctx.subnet_ = subnet1_; |
1259 | ctx.hosts_.clear(); |
1260 | AllocEngine::findReservation(ctx); |
1261 | lease = engine_.allocateLease4(ctx); |
1262 | ASSERT_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", 1262, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1263 | 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", 1263, gtest_ar .failure_message()) = ::testing::Message(); |
1264 | 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" , 1264, gtest_ar.failure_message()) = ::testing::Message(); |
1265 | |
1266 | // Let's create a lease for the client in subnet2 to make sure the lease |
1267 | // is not renewed but a reserved lease is offered. |
1268 | Lease4Ptr lease3(new Lease4(IOAddress("10.1.2.55"), hwaddr_, ClientIdPtr(), |
1269 | 501, time(NULL__null), subnet2_->getID())); |
1270 | lease3->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1271 | 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" , 1271, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease3)", "false", "true" ).c_str()) = ::testing::Message(); |
1272 | ctx.subnet_ = subnet1_; |
1273 | ctx.hosts_.clear(); |
1274 | AllocEngine::findReservation(ctx); |
1275 | lease = engine_.allocateLease4(ctx); |
1276 | ASSERT_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", 1276, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1277 | 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", 1277, gtest_ar .failure_message()) = ::testing::Message(); |
1278 | 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" , 1278, gtest_ar.failure_message()) = ::testing::Message(); |
1279 | } |
1280 | |
1281 | |
1282 | // Test that reservations within shared network take precedence over the |
1283 | // existing leases regardless in which subnet belonging to a shared network |
1284 | // reservations belong. Host lookups returning a collection are disabled. |
1285 | // As it is only an optimization the behavior (so the test) must stay |
1286 | // unchanged. |
1287 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test (SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "discoverSharedNetworkReservationsNoColl", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1287), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1287), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1287 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_discoverSharedNetworkReservationsNoColl_Test ::TestBody() { |
1288 | |
1289 | // Disable host lookups returning a collection. |
1290 | 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" , 1290, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ).c_str()) = ::testing::Message(); |
1291 | HostMgr::instance().setDisableSingleQuery(true); |
1292 | |
1293 | // Create reservation for the client. |
1294 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1295 | Host::IDENT_HWADDR, subnet2_->getID(), |
1296 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1297 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1298 | CfgMgr::instance().commit(); |
1299 | |
1300 | subnet1_->setReservationsGlobal(true); |
1301 | subnet1_->setReservationsInSubnet(true); |
1302 | subnet2_->setReservationsGlobal(true); |
1303 | subnet2_->setReservationsInSubnet(true); |
1304 | |
1305 | // Start allocation from subnet1. The engine should determine that the |
1306 | // client has reservations in subnet2 and should rather assign reserved |
1307 | // addresses. |
1308 | AllocEngine::ClientContext4 |
1309 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1310 | false, false, "host.example.com.", true); |
1311 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1312 | AllocEngine::findReservation(ctx); |
1313 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1314 | ASSERT_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", 1314, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1315 | 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", 1315, gtest_ar .failure_message()) = ::testing::Message(); |
1316 | 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" , 1316, gtest_ar.failure_message()) = ::testing::Message(); |
1317 | |
1318 | // Let's create a lease for the client to make sure the lease is not |
1319 | // renewed but a reserved lease is offered. |
1320 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1321 | 501, time(NULL__null), subnet1_->getID())); |
1322 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1323 | 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" , 1323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ).c_str()) = ::testing::Message(); |
1324 | ctx.subnet_ = subnet1_; |
1325 | ctx.hosts_.clear(); |
1326 | AllocEngine::findReservation(ctx); |
1327 | lease = engine_.allocateLease4(ctx); |
1328 | ASSERT_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", 1328, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1329 | 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", 1329, gtest_ar .failure_message()) = ::testing::Message(); |
1330 | 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" , 1330, gtest_ar.failure_message()) = ::testing::Message(); |
1331 | } |
1332 | |
1333 | // This test verifies that the server can offer an address from a shared |
1334 | // subnet if there's at least 1 address left there, but will not offer |
1335 | // anything if both subnets are completely full. |
1336 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_runningOut_Test (SharedNetworkAlloc4Test_runningOut_Test const &) = delete ; void operator=(SharedNetworkAlloc4Test_runningOut_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_runningOut_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "runningOut", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 1336), (::testing::internal::GetTypeId <SharedNetworkAlloc4Test>()), ::testing::internal::SuiteApiResolver < SharedNetworkAlloc4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 1336), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1336 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_runningOut_Test >); void SharedNetworkAlloc4Test_runningOut_Test::TestBody () { |
1337 | |
1338 | // Allocate everything in subnet1 |
1339 | insertLease("192.0.2.17", subnet1_->getID()); |
1340 | |
1341 | // Allocate everything, except one address in subnet2. |
1342 | for (int i = 5; i < 100; i++) { |
1343 | stringstream tmp; |
1344 | tmp << "10.1.2." << i; |
1345 | insertLease(tmp.str(), subnet2_->getID()); |
1346 | } |
1347 | |
1348 | // Create context which will be used to try to allocate leases from the |
1349 | // shared network. The context points to subnet1, which address space |
1350 | // is exhausted. We expect the allocation engine to find another subnet |
1351 | // within the same shared network and offer an address from there. |
1352 | AllocEngine::ClientContext4 |
1353 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1354 | false, false, "host.example.com.", true); |
1355 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1356 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1357 | 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", 1357, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "lease", "false", "true").c_str()) = ::testing:: Message(); |
1358 | |
1359 | // Now allocate the last address. Now both subnets are exhausted. |
1360 | insertLease("10.1.2.100", subnet2_->getID()); |
1361 | |
1362 | // Ok, we're out. We should not get anything now. |
1363 | lease = engine_.allocateLease4(ctx); |
1364 | 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", 1364, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false").c_str()) = ::testing::Message(); |
1365 | |
1366 | 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", 1366, gtest_ar.failure_message ()) = ::testing::Message(); |
1367 | 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", 1367, gtest_ar .failure_message()) = ::testing::Message(); |
1368 | 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", 1368, gtest_ar.failure_message ()) = ::testing::Message(); |
1369 | 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", 1369, gtest_ar.failure_message ()) = ::testing::Message(); |
1370 | 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", 1370, gtest_ar.failure_message ()) = ::testing::Message(); |
1371 | |
1372 | 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", 1372, gtest_ar .failure_message()) = ::testing::Message(); |
1373 | 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" , 1373, gtest_ar.failure_message()) = ::testing::Message(); |
1374 | 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" , 1374, gtest_ar.failure_message()) = ::testing::Message(); |
1375 | 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" , 1375, gtest_ar.failure_message()) = ::testing::Message(); |
1376 | 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" , 1376, gtest_ar.failure_message()) = ::testing::Message(); |
1377 | } |
1378 | |
1379 | // This test verifies that the server can offer an address from a |
1380 | // subnet and the introduction of shared network doesn't break anything here. |
1381 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test (SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkSimple", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1381), (:: testing::internal::GetTypeId<SharedNetworkAlloc4Test>() ), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1381), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1381 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkSimple_Test ::TestBody() { |
1382 | |
1383 | // Create context which will be used to try to allocate leases from the |
1384 | // shared network. The context points to subnet1, which address space |
1385 | // is exhausted. We expect the allocation engine to find another subnet |
1386 | // within the same shared network and offer an address from there. |
1387 | AllocEngine::ClientContext4 |
1388 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1389 | false, false, "host.example.com.", false); |
1390 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1391 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1392 | |
1393 | // The allocation engine should have assigned an address from the first |
1394 | // subnet. |
1395 | ASSERT_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", 1395, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1396 | 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", 1396, gtest_ar .failure_message()) = ::testing::Message(); |
1397 | |
1398 | // Make sure the lease is in the lease mgr. |
1399 | 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" , 1399, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1400 | } |
1401 | |
1402 | // This test verifies that the server can allocate an address from a |
1403 | // different subnet than orginally selected, when the address pool in |
1404 | // the first subnet is exhausted. |
1405 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_requestSharedNetwork_Test (SharedNetworkAlloc4Test_requestSharedNetwork_Test const & ) = delete; void operator=(SharedNetworkAlloc4Test_requestSharedNetwork_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetwork_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetwork", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1405), (::testing ::internal::GetTypeId<SharedNetworkAlloc4Test>()), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1405), ::testing ::internal::SuiteApiResolver< SharedNetworkAlloc4Test>:: GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1405), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetwork_Test >); void SharedNetworkAlloc4Test_requestSharedNetwork_Test ::TestBody() { |
1406 | |
1407 | // Create a lease for a single address in the first address pool. The |
1408 | // pool is now exhausted. |
1409 | Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); |
1410 | |
1411 | // Create context which will be used to try to allocate leases from the |
1412 | // shared network. The context points to subnet1, which address space |
1413 | // is exhausted. We expect the allocation engine to find another subnet |
1414 | // within the same shared network and offer an address from there. |
1415 | AllocEngine::ClientContext4 |
1416 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1417 | false, false, "host.example.com.", false); |
1418 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1419 | Lease4Ptr lease2 = engine_.allocateLease4(ctx); |
1420 | // The allocation engine should have assigned an address from the second |
1421 | // subnet. We could guess that this is 10.1.2.5, being the first address |
1422 | // in the address pool, but to make the test more generic, we merely |
1423 | // verify that the address is in the given address pool. |
1424 | 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", 1424, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
1425 | 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" , 1425, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1426 | |
1427 | 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" , 1427, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease2)", "false", "true").c_str()) = ::testing::Message(); |
1428 | |
1429 | // The client should also be assigned a lease when it specifies a hint |
1430 | // that doesn't match the subnet from which the lease is offered. The |
1431 | // engine should check alternative subnets to match the hint to |
1432 | // a subnet. The requested lease is available, so it should be offered. |
1433 | ctx.subnet_ = subnet1_; |
1434 | ctx.requested_address_ = IOAddress("10.1.2.25"); |
1435 | lease2 = engine_.allocateLease4(ctx); |
1436 | 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", 1436, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
1437 | 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" , 1437, gtest_ar.failure_message()) = ::testing::Message(); |
1438 | |
1439 | // The returning client (the one that has a lease) should also be able |
1440 | // to renew its lease regardless of a subnet it begins with. So, it has |
1441 | // an address assigned from subnet1, but we use subnet2 as a selected |
1442 | // subnet. |
1443 | AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, |
1444 | IOAddress("0.0.0.0"), false, false, |
1445 | "host.example.com.", false); |
1446 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1447 | lease2 = engine_.allocateLease4(ctx2); |
1448 | // The existing lease should be returned. |
1449 | 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", 1449, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
1450 | 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" , 1450, gtest_ar.failure_message()) = ::testing::Message(); |
1451 | } |
1452 | |
1453 | // This test verifies that the server can assign an address from a |
1454 | // different subnet than orginally selected, when the address pool in |
1455 | // the first subnet is exhausted. |
1456 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test (SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkClassification", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1456), ( ::testing::internal::GetTypeId<SharedNetworkAlloc4Test> ()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1456), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1456 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkClassification_Test ::TestBody() { |
1457 | // Try to offer address from subnet1. There is one address available |
1458 | // so it should be offered. |
1459 | AllocEngine::ClientContext4 |
1460 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1461 | false, false, "host.example.com.", false); |
1462 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1463 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1464 | ASSERT_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", 1464, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1465 | 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" , 1465, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1466 | |
1467 | // Remove the lease so as we can start over. |
1468 | 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" , 1468, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1469 | |
1470 | // Apply restrictions on the subnet1. This should be only assigned |
1471 | // to clients belonging to cable-modem class. |
1472 | subnet1_->allowClientClass("cable-modem"); |
1473 | |
1474 | // The allocation engine should determine that the subnet1 is not |
1475 | // available for the client not belonging to the cable-modem class. |
1476 | // Instead, it should assign an address from subnet2 that belongs |
1477 | // to the same shared network. |
1478 | ctx.subnet_ = subnet1_; |
1479 | lease = engine_.allocateLease4(ctx); |
1480 | ASSERT_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", 1480, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1481 | 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" , 1481, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1482 | |
1483 | // Remove the lease so as we can start over. |
1484 | 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" , 1484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1485 | |
1486 | // Assign cable-modem class and try again. This time, we should |
1487 | // offer an address from the subnet1. |
1488 | ctx.query_->addClass(ClientClass("cable-modem")); |
1489 | |
1490 | ctx.subnet_ = subnet1_; |
1491 | lease = engine_.allocateLease4(ctx); |
1492 | ASSERT_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", 1492, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1493 | 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" , 1493, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1494 | |
1495 | // Let's now remove the client from the cable-modem class and try |
1496 | // to renew the address. The engine should determine that the |
1497 | // client doesn't have access to the subnet1 pools anymore and |
1498 | // assign an address from unrestricted subnet. |
1499 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1500 | ctx.subnet_ = subnet1_; |
1501 | lease = engine_.allocateLease4(ctx); |
1502 | ASSERT_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", 1502, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1503 | 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" , 1503, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1504 | } |
1505 | |
1506 | // This test verifies that the server can assign an address from a |
1507 | // different subnet than orginally selected, when the address pool in |
1508 | // the first subnet requires another class. |
1509 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test (SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkPoolClassification", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1509), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1509), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1509 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkPoolClassification_Test ::TestBody() { |
1510 | // Try to offer address from subnet1. There is one address available |
1511 | // so it should be offered. |
1512 | AllocEngine::ClientContext4 |
1513 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1514 | false, false, "host.example.com.", false); |
1515 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1516 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1517 | ASSERT_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", 1517, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1518 | 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" , 1518, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1519 | |
1520 | // Remove the lease so as we can start over. |
1521 | 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" , 1521, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1522 | |
1523 | // Apply restrictions on the pool1. This should be only assigned |
1524 | // to clients belonging to cable-modem class. |
1525 | pool1_->allowClientClass("cable-modem"); |
1526 | |
1527 | // The allocation engine should determine that the pool1 is not |
1528 | // available for the client not belonging to the cable-modem class. |
1529 | // Instead, it should assign an address from subnet2 that belongs |
1530 | // to the same shared network. |
1531 | ctx.subnet_ = subnet1_; |
1532 | lease = engine_.allocateLease4(ctx); |
1533 | ASSERT_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", 1533, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1534 | 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" , 1534, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1535 | |
1536 | // Remove the lease so as we can start over. |
1537 | 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" , 1537, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1538 | |
1539 | // Assign cable-modem class and try again. This time, we should |
1540 | // offer an address from the pool1. |
1541 | ctx.query_->addClass(ClientClass("cable-modem")); |
1542 | |
1543 | // Restrict access to pool2 for this client, to make sure that the |
1544 | // server doesn't accidentally get an address from this pool. |
1545 | pool2_->allowClientClass("telephone"); |
1546 | |
1547 | ctx.subnet_ = subnet1_; |
1548 | lease = engine_.allocateLease4(ctx); |
1549 | ASSERT_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", 1549, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1550 | 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" , 1550, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1551 | |
1552 | // Let's now remove the client from the cable-modem class and try |
1553 | // to renew the address. The engine should determine that the |
1554 | // client doesn't have access to the pool1 anymore and |
1555 | // assign an address from another pool. |
1556 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1557 | ctx.query_->addClass(ClientClass("telephone")); |
1558 | ctx.subnet_ = subnet1_; |
1559 | lease = engine_.allocateLease4(ctx); |
1560 | ASSERT_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", 1560, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1561 | 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" , 1561, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
1562 | } |
1563 | |
1564 | // Test that reservations within shared network take precedence over the |
1565 | // existing leases regardless in which subnet belonging to a shared network |
1566 | // reservations belong (DHCPREQUEST case). |
1567 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test (SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkReservations", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1567), ( ::testing::internal::GetTypeId<SharedNetworkAlloc4Test> ()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1567), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1567 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservations_Test ::TestBody() { |
1568 | |
1569 | 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" , 1569, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ).c_str()) = ::testing::Message(); |
1570 | |
1571 | // Create reservation for the client. |
1572 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1573 | Host::IDENT_HWADDR, subnet2_->getID(), |
1574 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1575 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1576 | CfgMgr::instance().commit(); |
1577 | |
1578 | // Start allocation from subnet1. The engine should determine that the |
1579 | // client has reservations in subnet2 and should rather assign reserved |
1580 | // addresses. |
1581 | AllocEngine::ClientContext4 |
1582 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1583 | false, false, "host.example.com.", false); |
1584 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1585 | AllocEngine::findReservation(ctx); |
1586 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1587 | ASSERT_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", 1587, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1588 | 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", 1588, gtest_ar .failure_message()) = ::testing::Message(); |
1589 | 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" , 1589, gtest_ar.failure_message()) = ::testing::Message(); |
1590 | |
1591 | // Remove the lease for another test below. |
1592 | 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" , 1592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1593 | |
1594 | // Let's create a lease for the client to make sure the lease is not |
1595 | // renewed but a reserved lease is allocated again. |
1596 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1597 | 501, time(NULL__null), subnet1_->getID())); |
1598 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1599 | 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" , 1599, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ).c_str()) = ::testing::Message(); |
1600 | ctx.subnet_ = subnet1_; |
1601 | ctx.hosts_.clear(); |
1602 | AllocEngine::findReservation(ctx); |
1603 | lease = engine_.allocateLease4(ctx); |
1604 | ASSERT_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", 1604, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1605 | 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", 1605, gtest_ar .failure_message()) = ::testing::Message(); |
1606 | 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" , 1606, gtest_ar.failure_message()) = ::testing::Message(); |
1607 | } |
1608 | |
1609 | // Test that reservations within shared network take precedence over the |
1610 | // existing leases regardless in which subnet belonging to a shared network |
1611 | // reservations belong (DHCPREQUEST case). Host lookups returning a collection |
1612 | // are disabled. As it is only an optimization the behavior (so the test) |
1613 | // must stay unchanged. |
1614 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test (SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test const &) = delete; void operator=(SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test const &) = delete; }; ::testing::TestInfo* const SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SharedNetworkAlloc4Test" , "requestSharedNetworkReservationsNoColl", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 1614), (::testing::internal::GetTypeId<SharedNetworkAlloc4Test >()), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1614), ::testing::internal::SuiteApiResolver< SharedNetworkAlloc4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 1614 ), new ::testing::internal::TestFactoryImpl<SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test >); void SharedNetworkAlloc4Test_requestSharedNetworkReservationsNoColl_Test ::TestBody() { |
1615 | |
1616 | // Disable host lookups returning a collection. |
1617 | 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" , 1617, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "HostMgr::instance().getDisableSingleQuery()", "true", "false" ).c_str()) = ::testing::Message(); |
1618 | HostMgr::instance().setDisableSingleQuery(true); |
1619 | |
1620 | // Create reservation for the client. |
1621 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
1622 | Host::IDENT_HWADDR, subnet2_->getID(), |
1623 | SUBNET_ID_UNUSED, IOAddress("10.1.2.105"))); |
1624 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
1625 | CfgMgr::instance().commit(); |
1626 | |
1627 | // Start allocation from subnet1. The engine should determine that the |
1628 | // client has reservations in subnet2 and should rather assign reserved |
1629 | // addresses. |
1630 | AllocEngine::ClientContext4 |
1631 | ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), |
1632 | false, false, "host.example.com.", false); |
1633 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1634 | AllocEngine::findReservation(ctx); |
1635 | Lease4Ptr lease = engine_.allocateLease4(ctx); |
1636 | ASSERT_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", 1636, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1637 | 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", 1637, gtest_ar .failure_message()) = ::testing::Message(); |
1638 | 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" , 1638, gtest_ar.failure_message()) = ::testing::Message(); |
1639 | |
1640 | // Remove the lease for another test below. |
1641 | 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" , 1641, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1642 | |
1643 | // Let's create a lease for the client to make sure the lease is not |
1644 | // renewed but a reserved lease is allocated again. |
1645 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), |
1646 | 501, time(NULL__null), subnet1_->getID())); |
1647 | lease->cltt_ = time(NULL__null) - 10; // Allocated 10 seconds ago |
1648 | 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" , 1648, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease2)", "false", "true" ).c_str()) = ::testing::Message(); |
1649 | ctx.subnet_ = subnet1_; |
1650 | ctx.hosts_.clear(); |
1651 | AllocEngine::findReservation(ctx); |
1652 | lease = engine_.allocateLease4(ctx); |
1653 | ASSERT_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", 1653, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1654 | 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", 1654, gtest_ar .failure_message()) = ::testing::Message(); |
1655 | 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" , 1655, gtest_ar.failure_message()) = ::testing::Message(); |
1656 | } |
1657 | |
1658 | // This test checks if an expired lease can be reused in DHCPDISCOVER (fake |
1659 | // allocation) |
1660 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverReuseExpiredLease4_Test (AllocEngine4Test_discoverReuseExpiredLease4_Test const & ) = delete; void operator=(AllocEngine4Test_discoverReuseExpiredLease4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseExpiredLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverReuseExpiredLease4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1660), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1660), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1660), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseExpiredLease4_Test >); void AllocEngine4Test_discoverReuseExpiredLease4_Test:: TestBody() { |
1661 | boost::scoped_ptr<AllocEngine> engine; |
1662 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_1662 ; } } else gtest_label_testnothrow_1662: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 1662, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
1663 | 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", 1663, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
1664 | |
1665 | IOAddress addr("192.0.2.15"); |
1666 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1667 | // Get rid of the default test configuration. |
1668 | cfg_mgr.clear(); |
1669 | |
1670 | // Create configuration similar to other tests, but with a single address pool |
1671 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1672 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1673 | subnet_->addPool(pool_); |
1674 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1675 | |
1676 | // Just a different hw/client-id for the second client |
1677 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
1678 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
1679 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
1680 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
1681 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
1682 | 495, now, subnet_->getID())); |
1683 | // Copy the lease, so as it can be compared with the old lease returned |
1684 | // by the allocation engine. |
1685 | Lease4 original_lease(*lease); |
1686 | |
1687 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
1688 | // is expired already |
1689 | 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", 1689, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->expired()" , "false", "true").c_str()) = ::testing::Message(); |
1690 | 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" , 1690, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1691 | |
1692 | // CASE 1: Asking for any address |
1693 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
1694 | IOAddress("0.0.0.0"), false, false, |
1695 | "", true); |
1696 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1697 | lease = engine->allocateLease4(ctx1); |
1698 | // Check that we got that single lease |
1699 | ASSERT_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", 1699, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1700 | 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" , 1700, gtest_ar.failure_message()) = ::testing::Message(); |
1701 | |
1702 | // We are reusing expired lease, the old (expired) instance should be |
1703 | // returned. The returned instance should be the same as the original |
1704 | // lease. |
1705 | 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", 1705, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
1706 | 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" , 1706, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true").c_str ()) = ::testing::Message(); |
1707 | |
1708 | // Do all checks on the lease (if subnet-id, preferred/valid times are ok etc.) |
1709 | checkLease4(lease); |
1710 | |
1711 | // CASE 2: Asking specifically for this address |
1712 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
1713 | IOAddress(addr), false, false, |
1714 | "", true); |
1715 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
1716 | lease = engine->allocateLease4(ctx2); |
1717 | // Check that we got that single lease |
1718 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 1718, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1719 | 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" , 1719, gtest_ar.failure_message()) = ::testing::Message(); |
1720 | |
1721 | // We are updating expired lease. The copy of the old lease should be |
1722 | // returned and it should be equal to the original lease. |
1723 | 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", 1723, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
1724 | 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", 1724, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "*ctx2.old_lease_ == original_lease" , "false", "true").c_str()) = ::testing::Message(); |
1725 | } |
1726 | |
1727 | // This test checks if an expired lease can be reused in REQUEST (actual allocation) |
1728 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestReuseExpiredLease4_Test (AllocEngine4Test_requestReuseExpiredLease4_Test const &) = delete; void operator=(AllocEngine4Test_requestReuseExpiredLease4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestReuseExpiredLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestReuseExpiredLease4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1728), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1728), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1728), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseExpiredLease4_Test >); void AllocEngine4Test_requestReuseExpiredLease4_Test:: TestBody() { |
1729 | boost::scoped_ptr<AllocEngine> engine; |
1730 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_1730 ; } } else gtest_label_testnothrow_1730: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 1730, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
1731 | 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", 1731, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
1732 | |
1733 | IOAddress addr("192.0.2.105"); |
1734 | |
1735 | 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" , 1735, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1736 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
1737 | subnet_->getID()); |
1738 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
1739 | 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", 1739, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-leases\", 0)" , "false", "true").c_str()) = ::testing::Message(); |
1740 | 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" , 1740, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1741 | |
1742 | // Just a different hw/client-id for the second client |
1743 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
1744 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
1745 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
1746 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
1747 | |
1748 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
1749 | 495, now, subnet_->getID())); |
1750 | // Make a copy of the lease, so as we can compare that with the old lease |
1751 | // instance returned by the allocation engine. |
1752 | Lease4 original_lease(*lease); |
1753 | |
1754 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
1755 | // is expired already |
1756 | 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", 1756, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->expired()" , "false", "true").c_str()) = ::testing::Message(); |
1757 | 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" , 1757, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
1758 | |
1759 | // A client comes along, asking specifically for this address |
1760 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
1761 | IOAddress(addr), false, false, |
1762 | "host.example.com.", false); |
1763 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1764 | lease = engine->allocateLease4(ctx); |
1765 | |
1766 | // Check that he got that single lease |
1767 | ASSERT_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", 1767, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
1768 | 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" , 1768, gtest_ar.failure_message()) = ::testing::Message(); |
1769 | |
1770 | // Check that the lease is indeed updated in LeaseMgr |
1771 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
1772 | 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", 1772, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
1773 | |
1774 | // Now check that the lease in LeaseMgr has the same parameters |
1775 | detailCompareLease(lease, from_mgr); |
1776 | |
1777 | // The allocation engine should return a copy of the old lease. This |
1778 | // lease should be equal to the original lease. |
1779 | 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", 1779, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
1780 | 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", 1780, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "*ctx.old_lease_ == original_lease" , "false", "true").c_str()) = ::testing::Message(); |
1781 | |
1782 | // Check that the stats declined stats were modified correctly. Note, because |
1783 | // added the lease directly, assigned-leases never bumped to one, so when we |
1784 | // reclaim it gets decremented to -1, then on assignment back to 0. |
1785 | 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" , 1785, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1786 | cumulative += 1; |
1787 | 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" , 1788, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
1788 | 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" , 1788, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1789 | glbl_cumulative += 1; |
1790 | 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" , 1790, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
1791 | 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", 1791, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-leases\", 1)" , "false", "true").c_str()) = ::testing::Message(); |
1792 | 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" , 1792, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-leases\", 1, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1793 | } |
1794 | |
1795 | // This test checks if an expired declined lease can be reused when responding |
1796 | // to DHCPDISCOVER (fake allocation) |
1797 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverReuseDeclinedLease4_Test (AllocEngine4Test_discoverReuseDeclinedLease4_Test const & ) = delete; void operator=(AllocEngine4Test_discoverReuseDeclinedLease4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseDeclinedLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverReuseDeclinedLease4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1797), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1797), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1797), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4_Test ::TestBody() { |
1798 | |
1799 | AllocEnginePtr engine(new AllocEngine(0)); |
1800 | 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", 1800, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
1801 | |
1802 | // Now prepare a configuration with single address pool. |
1803 | IOAddress addr("192.0.2.15"); |
1804 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1805 | cfg_mgr.clear(); |
1806 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1807 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1808 | subnet_->addPool(pool_); |
1809 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1810 | |
1811 | // Now create a declined lease, decline it and rewind its cltt, so it |
1812 | // is expired. |
1813 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1814 | |
1815 | // CASE 1: Ask for any address |
1816 | Lease4Ptr assigned; |
1817 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
1818 | |
1819 | // Check that we got that single lease |
1820 | 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", 1820, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true").c_str()) = ::testing::Message(); |
1821 | 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" , 1821, gtest_ar.failure_message()) = ::testing::Message(); |
1822 | |
1823 | // CASE 2: Asking specifically for this address |
1824 | testReuseLease4(engine, declined, "192.0.2.15", true, SHOULD_PASS, assigned); |
1825 | |
1826 | // Check that we get it again |
1827 | 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", 1827, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true").c_str()) = ::testing::Message(); |
1828 | 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" , 1828, gtest_ar.failure_message()) = ::testing::Message(); |
1829 | } |
1830 | |
1831 | // This test checks if statistics are not updated when expired declined lease |
1832 | // is reused when responding to DHCPDISCOVER (fake allocation) |
1833 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test (AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test const &) = delete; void operator=(AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverReuseDeclinedLease4Stats", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1833), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1833), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 1833), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_discoverReuseDeclinedLease4Stats_Test ::TestBody() { |
1834 | |
1835 | // Now prepare for DISCOVER processing |
1836 | AllocEnginePtr engine(new AllocEngine(0)); |
1837 | 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", 1837, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
1838 | |
1839 | // Now prepare a configuration with single address pool. |
1840 | IOAddress addr("192.0.2.15"); |
1841 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1842 | cfg_mgr.clear(); |
1843 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1844 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1845 | subnet_->addPool(pool_); |
1846 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1847 | cfg_mgr.commit(); // so we will recalc stats |
1848 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
1849 | subnet_->getID()); |
1850 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
1851 | |
1852 | // Now create a declined lease, decline it and rewind its cltt, so it |
1853 | // is expired. |
1854 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1855 | |
1856 | // Ask for any address. There's only one address in the pool, so it doesn't |
1857 | // matter much. |
1858 | Lease4Ptr assigned; |
1859 | testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); |
1860 | |
1861 | // Check that the stats declined stats were not modified |
1862 | 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" , 1862, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1863 | 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" , 1864, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
1864 | 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" , 1864, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1865 | 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" , 1865, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
1866 | 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", 1866, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"declined-addresses\", 0)" , "false", "true").c_str()) = ::testing::Message(); |
1867 | 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", 1867, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-declined-addresses\", 0)" , "false", "true").c_str()) = ::testing::Message(); |
1868 | 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" , 1868, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1869 | 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" , 1869, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1870 | } |
1871 | |
1872 | // This test checks if an expired declined lease can be reused when responding |
1873 | // to REQUEST (actual allocation) |
1874 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestReuseDeclinedLease4_Test (AllocEngine4Test_requestReuseDeclinedLease4_Test const & ) = delete; void operator=(AllocEngine4Test_requestReuseDeclinedLease4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestReuseDeclinedLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestReuseDeclinedLease4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 1874), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1874), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1874), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4_Test >); void AllocEngine4Test_requestReuseDeclinedLease4_Test:: TestBody() { |
1875 | |
1876 | AllocEnginePtr engine(new AllocEngine(0)); |
1877 | 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", 1877, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
1878 | |
1879 | // Now prepare a configuration with single address pool. |
1880 | IOAddress addr("192.0.2.15"); |
1881 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1882 | cfg_mgr.clear(); |
1883 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1884 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1885 | subnet_->addPool(pool_); |
1886 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1887 | |
1888 | // Now create a declined lease, decline it and rewind its cltt, so it |
1889 | // is expired. |
1890 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1891 | |
1892 | // Asking specifically for this address |
1893 | Lease4Ptr assigned; |
1894 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
1895 | // Check that we got it. |
1896 | 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", 1896, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true").c_str()) = ::testing::Message(); |
1897 | 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" , 1897, gtest_ar.failure_message()) = ::testing::Message(); |
1898 | |
1899 | // Check that the lease is indeed updated in LeaseMgr |
1900 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
1901 | 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", 1901, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
1902 | |
1903 | // Now check that the lease in LeaseMgr has the same parameters |
1904 | detailCompareLease(assigned, from_mgr); |
1905 | } |
1906 | |
1907 | // This test checks if statistics are not updated when expired declined lease |
1908 | // is reused when responding to DHCPREQUEST (actual allocation) |
1909 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestReuseDeclinedLease4Stats_Test (AllocEngine4Test_requestReuseDeclinedLease4Stats_Test const & ) = delete; void operator=(AllocEngine4Test_requestReuseDeclinedLease4Stats_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestReuseDeclinedLease4Stats_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestReuseDeclinedLease4Stats", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 1909), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 1909), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 1909), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_requestReuseDeclinedLease4Stats_Test >); void AllocEngine4Test_requestReuseDeclinedLease4Stats_Test ::TestBody() { |
1910 | |
1911 | AllocEnginePtr engine(new AllocEngine(0)); |
1912 | 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", 1912, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
1913 | |
1914 | // Now prepare a configuration with single address pool. |
1915 | IOAddress addr("192.0.2.15"); |
1916 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
1917 | cfg_mgr.clear(); |
1918 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
1919 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
1920 | subnet_->addPool(pool_); |
1921 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
1922 | cfg_mgr.commit(); |
1923 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
1924 | subnet_->getID()); |
1925 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
1926 | |
1927 | // Now create a declined lease, decline it and rewind its cltt, so it |
1928 | // is expired. |
1929 | Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); |
1930 | |
1931 | // Asking specifically for this address |
1932 | Lease4Ptr assigned; |
1933 | testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); |
1934 | // Check that we got it. |
1935 | 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", 1935, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "assigned" , "false", "true").c_str()) = ::testing::Message(); |
1936 | |
1937 | // Check that the stats are correct. Note that assigned-addresses does |
1938 | // not get decremented when a lease is declined, ergo not incremented |
1939 | // when it is reused. Declined address stats will be -1 since |
1940 | // lease was created as declined which does not increment the stat. |
1941 | 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" , 1941, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"assigned-addresses\", 0, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1942 | cumulative += 1; |
1943 | 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" , 1944, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
1944 | 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" , 1944, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1945 | glbl_cumulative += 1; |
1946 | 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" , 1946, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
1947 | 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", 1947, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"declined-addresses\", -1)" , "false", "true").c_str()) = ::testing::Message(); |
1948 | 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", 1948, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "testStatistics(\"reclaimed-declined-addresses\", 1)" , "false", "true").c_str()) = ::testing::Message(); |
1949 | 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" , 1949, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"declined-addresses\", -1, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1950 | 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" , 1950, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"reclaimed-declined-addresses\", 1, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
1951 | } |
1952 | |
1953 | // This test checks that the Allocation Engine correctly identifies the |
1954 | // existing client's lease in the lease database, using the client |
1955 | // identifier and HW address. |
1956 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_identifyClientLease_Test (AllocEngine4Test_identifyClientLease_Test const &) = delete ; void operator=(AllocEngine4Test_identifyClientLease_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_identifyClientLease_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "identifyClientLease", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 1956), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 1956), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 1956), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_identifyClientLease_Test >); void AllocEngine4Test_identifyClientLease_Test::TestBody () { |
1957 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, clientid_, |
1958 | 100, time(NULL__null), subnet_->getID())); |
1959 | LeaseMgrFactory::instance().addLease(lease); |
1960 | |
1961 | AllocEngine engine(0); |
1962 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
1963 | IOAddress::IPV4_ZERO_ADDRESS(), |
1964 | false, false, "", true); |
1965 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
1966 | |
1967 | Lease4Ptr identified_lease = engine.allocateLease4(ctx); |
1968 | 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", 1968, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
1969 | 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" , 1969, gtest_ar.failure_message()) = ::testing::Message(); |
1970 | |
1971 | ctx.hwaddr_ = hwaddr2_; |
1972 | ctx.clientid_ = clientid_; |
1973 | identified_lease = engine.allocateLease4(ctx); |
1974 | 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", 1974, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
1975 | 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" , 1975, gtest_ar.failure_message()) = ::testing::Message(); |
1976 | |
1977 | ctx.hwaddr_ = hwaddr_; |
1978 | ctx.clientid_ = clientid2_; |
1979 | identified_lease = engine.allocateLease4(ctx); |
1980 | 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", 1980, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
1981 | 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", 1981, gtest_ar .failure_message()) = ::testing::Message(); |
1982 | |
1983 | ctx.hwaddr_ = hwaddr_; |
1984 | ctx.clientid_.reset(); |
1985 | identified_lease = engine.allocateLease4(ctx); |
1986 | 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", 1986, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
1987 | 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" , 1987, gtest_ar.failure_message()) = ::testing::Message(); |
1988 | |
1989 | ctx.hwaddr_ = hwaddr2_; |
1990 | ctx.clientid_.reset(); |
1991 | identified_lease = engine.allocateLease4(ctx); |
1992 | 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", 1992, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
1993 | 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", 1993, gtest_ar .failure_message()) = ::testing::Message(); |
1994 | |
1995 | lease->client_id_.reset(); |
1996 | ASSERT_NO_THROW(LeaseMgrFactory::instance().updateLease4(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { LeaseMgrFactory ::instance().updateLease4(lease); }; } catch (...) { goto gtest_label_testnothrow_1996 ; } } else gtest_label_testnothrow_1996: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 1996, "Expected: " "LeaseMgrFactory::instance().updateLease4(lease)" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message(); |
1997 | |
1998 | ctx.hwaddr_ = hwaddr_; |
1999 | ctx.clientid_ = clientid_; |
2000 | identified_lease = engine.allocateLease4(ctx); |
2001 | 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", 2001, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
2002 | 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" , 2002, gtest_ar.failure_message()) = ::testing::Message(); |
2003 | |
2004 | ctx.hwaddr_ = hwaddr_; |
2005 | ctx.clientid_.reset(); |
2006 | identified_lease = engine.allocateLease4(ctx); |
2007 | 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", 2007, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
2008 | 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" , 2008, gtest_ar.failure_message()) = ::testing::Message(); |
2009 | |
2010 | ctx.hwaddr_ = hwaddr2_; |
2011 | ctx.clientid_ = clientid_; |
2012 | identified_lease = engine.allocateLease4(ctx); |
2013 | 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", 2013, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "identified_lease" , "false", "true").c_str()) = ::testing::Message(); |
2014 | 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", 2014, gtest_ar .failure_message()) = ::testing::Message(); |
2015 | } |
2016 | |
2017 | // This test checks that when the client requests the address which belongs |
2018 | // to another client, the allocation engine returns NULL (for the |
2019 | // DHCPREQUEST case) or a lease for the address which belongs to this |
2020 | // client (DHCPDISCOVER case). |
2021 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestOtherClientLease_Test (AllocEngine4Test_requestOtherClientLease_Test const &) = delete; void operator=(AllocEngine4Test_requestOtherClientLease_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestOtherClientLease_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestOtherClientLease", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2021), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2021), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2021), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestOtherClientLease_Test >); void AllocEngine4Test_requestOtherClientLease_Test::TestBody () { |
2022 | // Create the first lease. |
2023 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2024 | &clientid_->getClientId()[0], |
2025 | clientid_->getClientId().size(), |
2026 | 100, time(NULL__null), subnet_->getID(), |
2027 | false, false, "")); |
2028 | // Create the second lease. Note that we use the same client id here and |
2029 | // we expect that the allocation engine will figure out that the hardware |
2030 | // address is different. |
2031 | Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr2_, |
2032 | &clientid_->getClientId()[0], |
2033 | clientid_->getClientId().size(), |
2034 | 100, time(NULL__null), subnet_->getID(), |
2035 | false, false, "")); |
2036 | // Add leases for both clients to the Lease Manager. |
2037 | LeaseMgrFactory::instance().addLease(lease); |
2038 | LeaseMgrFactory::instance().addLease(lease2); |
2039 | |
2040 | AllocEngine engine(0); |
2041 | |
2042 | // First client requests the lease which belongs to the second client. |
2043 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), |
2044 | false, false, "", false); |
2045 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2046 | Lease4Ptr new_lease = engine.allocateLease4(ctx); |
2047 | // Allocation engine should return NULL. |
2048 | 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", 2048, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "new_lease" , "true", "false").c_str()) = ::testing::Message(); |
2049 | |
2050 | 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", 2050, gtest_ar.failure_message ()) = ::testing::Message(); |
2051 | 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", 2051, gtest_ar .failure_message()) = ::testing::Message(); |
2052 | 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", 2052, gtest_ar.failure_message ()) = ::testing::Message(); |
2053 | 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", 2053, gtest_ar.failure_message ()) = ::testing::Message(); |
2054 | 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", 2054, gtest_ar.failure_message ()) = ::testing::Message(); |
2055 | |
2056 | 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", 2056, gtest_ar .failure_message()) = ::testing::Message(); |
2057 | 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" , 2057, gtest_ar.failure_message()) = ::testing::Message(); |
2058 | 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", 2058, gtest_ar .failure_message()) = ::testing::Message(); |
2059 | 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" , 2059, gtest_ar.failure_message()) = ::testing::Message(); |
2060 | 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" , 2060, gtest_ar.failure_message()) = ::testing::Message(); |
2061 | |
2062 | // Now simulate the DHCPDISCOVER case when the provided address is |
2063 | // treated as a hint. The engine should return a lease for a |
2064 | // different address than requested. |
2065 | ctx.fake_allocation_ = true; |
2066 | new_lease = engine.allocateLease4(ctx); |
2067 | 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", 2067, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "new_lease" , "false", "true").c_str()) = ::testing::Message(); |
2068 | 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" , 2068, gtest_ar.failure_message()) = ::testing::Message(); |
2069 | } |
2070 | |
2071 | // This test checks the behavior of the allocation engine in the following |
2072 | // scenario: |
2073 | // - Client has no lease in the database. |
2074 | // - Client has a reservation. |
2075 | // - Client sends DHCPREQUEST without requested IP Address, nor ciaddr. |
2076 | // - Client is allocated a reserved address. |
2077 | // |
2078 | // Note that client must normally include a requested IP address or ciaddr |
2079 | // in its message. But, we still want to provision clients that don't do that. |
2080 | // The server simply picks reserved address or any other available one if there |
2081 | // is no reservation. |
2082 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressNoHint_Test (AllocEngine4Test_reservedAddressNoHint_Test const &) = delete ; void operator=(AllocEngine4Test_reservedAddressNoHint_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressNoHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressNoHint", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2082), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2082), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2082), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressNoHint_Test >); void AllocEngine4Test_reservedAddressNoHint_Test::TestBody () { |
2083 | // Create reservation for the client. |
2084 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2085 | Host::IDENT_HWADDR, subnet_->getID(), |
2086 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2087 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2088 | CfgMgr::instance().commit(); |
2089 | |
2090 | AllocEngine engine(0); |
2091 | |
2092 | // Try to allocate a lease without specifying a hint. This is actually |
2093 | // incorrect behavior of the client to not send an address it wants to |
2094 | // obtain but the server should handle this gracefully. |
2095 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2096 | IOAddress("0.0.0.0"), false, false, |
2097 | "", false); |
2098 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2099 | AllocEngine::findReservation(ctx); |
2100 | Lease4Ptr lease = engine.allocateLease4(ctx); |
2101 | |
2102 | ASSERT_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", 2102, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
2103 | 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" , 2103, gtest_ar.failure_message()) = ::testing::Message(); |
2104 | |
2105 | // Make sure that the lease has been committed to the lease database. |
2106 | // And that the committed lease is equal to the one returned. |
2107 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2108 | 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", 2108, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2109 | detailCompareLease(lease, from_mgr); |
2110 | |
2111 | // Initially, there was no lease for this client, so the returned old |
2112 | // lease should be NULL. |
2113 | 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", 2113, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2114 | } |
2115 | |
2116 | // This test checks behavior of the allocation engine in the following scenario: |
2117 | // - Client has no lease in the database. |
2118 | // - Client has a reservation. |
2119 | // - Client sends DHCPDISCOVER without requested IP Address. |
2120 | // - Server returns DHCPOFFER with the reserved address. |
2121 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test (AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressNoHintFakeAllocation", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 2121 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2121), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2121), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressNoHintFakeAllocation_Test ::TestBody() { |
2122 | // Create reservation for the client. |
2123 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2124 | Host::IDENT_HWADDR, subnet_->getID(), |
2125 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2126 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2127 | CfgMgr::instance().commit(); |
2128 | |
2129 | AllocEngine engine(0); |
2130 | |
2131 | // Query allocation engine for the lease to be assigned to this |
2132 | // client without specifying the address to be assigned. |
2133 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2134 | IOAddress("0.0.0.0"), false, false, |
2135 | "", true); |
2136 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2137 | AllocEngine::findReservation(ctx); |
2138 | Lease4Ptr lease = engine.allocateLease4(ctx); |
2139 | |
2140 | ASSERT_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", 2140, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
2141 | // The allocation engine should return a reserved address. |
2142 | 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" , 2142, gtest_ar.failure_message()) = ::testing::Message(); |
2143 | |
2144 | // This is a "fake" allocation so the returned lease should not be committed |
2145 | // to the lease database. |
2146 | 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" , 2146, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
2147 | |
2148 | // Client had no lease in the database, so the old lease returned should |
2149 | // be NULL. |
2150 | 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", 2150, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2151 | } |
2152 | |
2153 | // This test checks the behavior of the allocation engine in the following |
2154 | // scenario: |
2155 | // - Client has no lease in the database. |
2156 | // - Client has a reservation. |
2157 | // - Client sends DHCPREQUEST with a requested IP address |
2158 | // - Server returns DHCPNAK when requested IP address is different than |
2159 | // the reserved address. Note that the allocation engine returns NULL |
2160 | // to indicate to the server that it should send DHCPNAK. |
2161 | // - Server allocates a reserved address to the client when the client requests |
2162 | // this address using requested IP address option. |
2163 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressHint_Test (AllocEngine4Test_reservedAddressHint_Test const &) = delete ; void operator=(AllocEngine4Test_reservedAddressHint_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHint", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2163), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2163), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2163), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHint_Test >); void AllocEngine4Test_reservedAddressHint_Test::TestBody () { |
2164 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2165 | Host::IDENT_HWADDR, subnet_->getID(), |
2166 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2167 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2168 | CfgMgr::instance().commit(); |
2169 | |
2170 | AllocEngine engine(0); |
2171 | |
2172 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2173 | IOAddress("192.0.2.234"), false, false, |
2174 | "", false); |
2175 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2176 | AllocEngine::findReservation(ctx1); |
2177 | Lease4Ptr lease = engine.allocateLease4(ctx1); |
2178 | |
2179 | // The client requested a different address than reserved, so |
2180 | // the allocation engine should return NULL lease. When the server |
2181 | // receives a NULL lease for the client, it will send a DHCPNAK. |
2182 | 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", 2182, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false").c_str()) = ::testing::Message(); |
2183 | 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", 2183, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2184 | |
2185 | 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", 2185, gtest_ar.failure_message ()) = ::testing::Message(); |
2186 | 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", 2186, gtest_ar .failure_message()) = ::testing::Message(); |
2187 | 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", 2187, gtest_ar.failure_message ()) = ::testing::Message(); |
2188 | 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", 2188, gtest_ar.failure_message ()) = ::testing::Message(); |
2189 | 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", 2189, gtest_ar.failure_message ()) = ::testing::Message(); |
2190 | |
2191 | 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", 2191, gtest_ar .failure_message()) = ::testing::Message(); |
2192 | 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" , 2192, gtest_ar.failure_message()) = ::testing::Message(); |
2193 | 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", 2193, gtest_ar .failure_message()) = ::testing::Message(); |
2194 | 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" , 2194, gtest_ar.failure_message()) = ::testing::Message(); |
2195 | 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" , 2195, gtest_ar.failure_message()) = ::testing::Message(); |
2196 | |
2197 | // Now, request a correct address. The client should obtain it. |
2198 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2199 | IOAddress("192.0.2.123"), false, false, |
2200 | "", false); |
2201 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2202 | AllocEngine::findReservation(ctx2); |
2203 | lease = engine.allocateLease4(ctx2); |
2204 | ASSERT_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", 2204, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
2205 | 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" , 2205, gtest_ar.failure_message()) = ::testing::Message(); |
2206 | |
2207 | // Make sure that the lease has been committed to the lease database. |
2208 | // And that the committed lease is equal to the one returned. |
2209 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2210 | 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", 2210, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2211 | detailCompareLease(lease, from_mgr); |
2212 | |
2213 | 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", 2213, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2214 | } |
2215 | |
2216 | // This test checks the behavior of the allocation engine in the following |
2217 | // scenario: |
2218 | // - Client has no lease in the database. |
2219 | // - Client has a reservation. |
2220 | // - Client sends DHCPDISCOVER with a requested IP address as a hint. |
2221 | // - Server offers a reserved address, even though it is different than the |
2222 | // requested address. |
2223 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressHintFakeAllocation_Test (AllocEngine4Test_reservedAddressHintFakeAllocation_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressHintFakeAllocation_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHintFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHintFakeAllocation", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2223), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2223), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2223), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHintFakeAllocation_Test ::TestBody() { |
2224 | // Create a reservation for the client. |
2225 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2226 | Host::IDENT_HWADDR, subnet_->getID(), |
2227 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2228 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2229 | CfgMgr::instance().commit(); |
2230 | |
2231 | AllocEngine engine(0); |
2232 | |
2233 | // Query the allocation engine for the lease to be assigned to the client |
2234 | // and specify a hint being a different address than the reserved one. |
2235 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2236 | IOAddress("192.0.2.234"), false, false, |
2237 | "", true); |
2238 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2239 | AllocEngine::findReservation(ctx); |
2240 | Lease4Ptr lease = engine.allocateLease4(ctx); |
2241 | |
2242 | ASSERT_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", 2242, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
2243 | // Allocation engine should return reserved address. |
2244 | 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" , 2244, gtest_ar.failure_message()) = ::testing::Message(); |
2245 | |
2246 | // This is a "fake" allocation so the returned lease should not be committed |
2247 | // to the lease database. |
2248 | 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" , 2248, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
2249 | |
2250 | 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", 2250, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2251 | } |
2252 | |
2253 | // This test checks that the behavior of the allocation engine in the following |
2254 | // scenario: |
2255 | // - Client has a lease for the address from the dynamic pool in the database. |
2256 | // - Client has a reservation for a different address than the one for which |
2257 | // the client has a lease. |
2258 | // - Client sends DHCPREQUEST, asking for the reserved address (as it has been |
2259 | // offered to it when it sent DHCPDISCOVER). |
2260 | // - Server allocates a reserved address and removes the lease for the address |
2261 | // previously allocated to the client. |
2262 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressExistingLease_Test (AllocEngine4Test_reservedAddressExistingLease_Test const & ) = delete; void operator=(AllocEngine4Test_reservedAddressExistingLease_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLease_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLease", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2262), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2262), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2262), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLease_Test >); void AllocEngine4Test_reservedAddressExistingLease_Test ::TestBody() { |
2263 | // Create the reservation for the client. |
2264 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2265 | Host::IDENT_HWADDR, subnet_->getID(), |
2266 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2267 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2268 | CfgMgr::instance().commit(); |
2269 | |
2270 | // Create a lease for the client with a different address than the reserved |
2271 | // one. |
2272 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2273 | &clientid_->getClientId()[0], |
2274 | clientid_->getClientId().size(), |
2275 | 100, time(NULL__null), subnet_->getID(), |
2276 | false, false, "")); |
2277 | LeaseMgrFactory::instance().addLease(lease); |
2278 | |
2279 | AllocEngine engine(0); |
2280 | |
2281 | // Request allocation of the reserved address. |
2282 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2283 | IOAddress("192.0.2.123"), false, false, |
2284 | "", false); |
2285 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2286 | AllocEngine::findReservation(ctx); |
2287 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2288 | |
2289 | 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", 2289, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2290 | // The engine should have allocated the reserved address. |
2291 | 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" , 2291, gtest_ar.failure_message()) = ::testing::Message(); |
2292 | |
2293 | // Make sure that the lease has been committed to the lease database. |
2294 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
2295 | 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", 2295, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2296 | detailCompareLease(allocated_lease, from_mgr); |
2297 | |
2298 | // The previous lease should have been replaced by a new one. The previous |
2299 | // lease should be returned by the allocation engine to the caller. |
2300 | 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", 2300, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
2301 | 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" , 2301, gtest_ar.failure_message()) = ::testing::Message(); |
2302 | detailCompareLease(ctx.old_lease_, lease); |
2303 | } |
2304 | |
2305 | // This test checks that the behavior of the allocation engine in the following |
2306 | // scenario: |
2307 | // - Client A has a lease in the database. |
2308 | // - Client B has a reservation for the address in use by client A. |
2309 | // - Client B sends a DHCPREQUEST requesting the allocation of the reserved |
2310 | // lease (in use by client A). |
2311 | // - Server determines that the reserved address is in use by a different client |
2312 | // and returns DHCPNAK to client B. |
2313 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressHijacked_Test (AllocEngine4Test_reservedAddressHijacked_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressHijacked_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHijacked_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHijacked", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2313), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2313), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2313), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressHijacked_Test >); void AllocEngine4Test_reservedAddressHijacked_Test::TestBody () { |
2314 | // Create host reservation for the client B. |
2315 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2316 | Host::IDENT_HWADDR, subnet_->getID(), |
2317 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2318 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2319 | CfgMgr::instance().commit(); |
2320 | |
2321 | // Allocate a lease for the client A for the same address as reserved |
2322 | // for the client B. |
2323 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
2324 | 100, time(NULL__null), subnet_->getID(), |
2325 | false, false, "")); |
2326 | LeaseMgrFactory::instance().addLease(lease); |
2327 | |
2328 | AllocEngine engine(0); |
2329 | |
2330 | // Try to allocate the reserved lease to client B. |
2331 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2332 | IOAddress("192.0.2.123"), false, false, |
2333 | "", false); |
2334 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2335 | AllocEngine::findReservation(ctx1); |
2336 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2337 | // The lease is allocated to someone else, so the allocation should not |
2338 | // succeed. |
2339 | 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", 2339, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false").c_str()) = ::testing::Message(); |
2340 | 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", 2340, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2341 | |
2342 | 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", 2342, gtest_ar.failure_message ()) = ::testing::Message(); |
2343 | 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", 2343, gtest_ar .failure_message()) = ::testing::Message(); |
2344 | 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", 2344, gtest_ar.failure_message ()) = ::testing::Message(); |
2345 | 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", 2345, gtest_ar.failure_message ()) = ::testing::Message(); |
2346 | 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", 2346, gtest_ar.failure_message ()) = ::testing::Message(); |
2347 | |
2348 | 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", 2348, gtest_ar .failure_message()) = ::testing::Message(); |
2349 | 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" , 2349, gtest_ar.failure_message()) = ::testing::Message(); |
2350 | 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", 2350, gtest_ar .failure_message()) = ::testing::Message(); |
2351 | 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" , 2351, gtest_ar.failure_message()) = ::testing::Message(); |
2352 | 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" , 2352, gtest_ar.failure_message()) = ::testing::Message(); |
2353 | |
2354 | // Make sure that the allocation engine didn't modify the lease of the |
2355 | // client A. |
2356 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2357 | 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", 2357, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2358 | detailCompareLease(lease, from_mgr); |
2359 | |
2360 | // Try doing the same thing, but this time do not request any specific |
2361 | // address. It should have the same effect. |
2362 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2363 | IOAddress("0.0.0.0"), false, false, |
2364 | "", false); |
2365 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2366 | AllocEngine::findReservation(ctx2); |
2367 | allocated_lease = engine.allocateLease4(ctx2); |
2368 | 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", 2368, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false").c_str()) = ::testing::Message(); |
2369 | 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", 2369, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2370 | |
2371 | 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", 2371, gtest_ar.failure_message ()) = ::testing::Message(); |
2372 | 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", 2372, gtest_ar .failure_message()) = ::testing::Message(); |
2373 | 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", 2373, gtest_ar.failure_message ()) = ::testing::Message(); |
2374 | 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", 2374, gtest_ar.failure_message ()) = ::testing::Message(); |
2375 | 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", 2375, gtest_ar.failure_message ()) = ::testing::Message(); |
2376 | |
2377 | 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", 2377, gtest_ar .failure_message()) = ::testing::Message(); |
2378 | 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" , 2378, gtest_ar.failure_message()) = ::testing::Message(); |
2379 | 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", 2379, gtest_ar .failure_message()) = ::testing::Message(); |
2380 | 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" , 2380, gtest_ar.failure_message()) = ::testing::Message(); |
2381 | 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" , 2381, gtest_ar.failure_message()) = ::testing::Message(); |
2382 | |
2383 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2384 | 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", 2384, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2385 | detailCompareLease(lease, from_mgr); |
2386 | } |
2387 | |
2388 | // This test checks that the behavior of the allocation engine in the following |
2389 | // scenario: |
2390 | // - Client A has a lease in the database. |
2391 | // - Client B has a reservation for the address in use by client A. |
2392 | // - Client B sends a DHCPDISCOVER. |
2393 | // - Server determines that the reserved address is in use by a different client |
2394 | // so it offers an address from the dynamic pool. |
2395 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test (AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHijackedFakeAllocation", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 2395 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2395), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2395), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test >); void AllocEngine4Test_reservedAddressHijackedFakeAllocation_Test ::TestBody() { |
2396 | // Create a reservation for the client B. |
2397 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2398 | Host::IDENT_HWADDR, subnet_->getID(), |
2399 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2400 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2401 | CfgMgr::instance().commit(); |
2402 | |
2403 | // Create a lease for the client A. |
2404 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, |
2405 | 100, time(NULL__null), subnet_->getID(), |
2406 | false, false, "")); |
2407 | LeaseMgrFactory::instance().addLease(lease); |
2408 | |
2409 | AllocEngine engine(0); |
2410 | |
2411 | // Query allocation engine for the lease to be allocated to the client B. |
2412 | // The allocation engine is not able to allocate the lease to the client |
2413 | // B, because the address is in use by client A. |
2414 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2415 | IOAddress("192.0.2.123"), false, false, |
2416 | "", true); |
2417 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2418 | AllocEngine::findReservation(ctx1); |
2419 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2420 | |
2421 | // The allocation engine should return a lease but for a different address |
2422 | // than requested because this address is in use. |
2423 | 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", 2423, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2424 | 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", 2424, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2425 | 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", 2425, gtest_ar .failure_message()) = ::testing::Message(); |
2426 | 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" , 2426, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true").c_str()) = ::testing::Message(); |
2427 | |
2428 | // Do the same test. But, this time do not specify any address to be |
2429 | // allocated. |
2430 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2431 | IOAddress("0.0.0.0"), false, false, |
2432 | "", true); |
2433 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2434 | AllocEngine::findReservation(ctx2); |
2435 | allocated_lease = engine.allocateLease4(ctx2); |
2436 | |
2437 | 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", 2437, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2438 | 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", 2438, gtest_ar .failure_message()) = ::testing::Message(); |
2439 | 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" , 2439, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)" , "false", "true").c_str()) = ::testing::Message(); |
2440 | 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", 2440, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2441 | } |
2442 | |
2443 | // This test checks that the behavior of the allocation engine in the following |
2444 | // scenario: |
2445 | // - Client has a reservation. |
2446 | // - Client has a lease in the database for a different address than reserved. |
2447 | // - Client sends a DHCPREQUEST and asks for a different address than reserved, |
2448 | // and different than it has in a database. |
2449 | // - Server doesn't allocate the reserved address to the client because the |
2450 | // client asked for the different address. |
2451 | // |
2452 | // Note that in this case the client should get the DHCPNAK and should fall back |
2453 | // to the DHCPDISCOVER. |
2454 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test (AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseInvalidHint", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 2454), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2454), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 2454), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseInvalidHint_Test ::TestBody() { |
2455 | // Create a reservation for the client. |
2456 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2457 | Host::IDENT_HWADDR, subnet_->getID(), |
2458 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2459 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2460 | CfgMgr::instance().commit(); |
2461 | |
2462 | // Create a lease for the client for a different address than reserved. |
2463 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, ClientIdPtr(), |
2464 | 100, time(NULL__null), subnet_->getID(), |
2465 | false, false, "")); |
2466 | LeaseMgrFactory::instance().addLease(lease); |
2467 | |
2468 | AllocEngine engine(0); |
2469 | |
2470 | // Try to allocate a lease and specify a different address than reserved |
2471 | // and different from the one that client is currently using. |
2472 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2473 | IOAddress("192.0.2.102"), false, false, |
2474 | "", false); |
2475 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2476 | AllocEngine::findReservation(ctx1); |
2477 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2478 | 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", 2478, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false").c_str()) = ::testing::Message(); |
2479 | 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", 2479, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2480 | |
2481 | 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", 2481, gtest_ar.failure_message ()) = ::testing::Message(); |
2482 | 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", 2482, gtest_ar .failure_message()) = ::testing::Message(); |
2483 | 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", 2483, gtest_ar.failure_message ()) = ::testing::Message(); |
2484 | 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", 2484, gtest_ar.failure_message ()) = ::testing::Message(); |
2485 | 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", 2485, gtest_ar.failure_message ()) = ::testing::Message(); |
2486 | |
2487 | 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", 2487, gtest_ar .failure_message()) = ::testing::Message(); |
2488 | 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" , 2488, gtest_ar.failure_message()) = ::testing::Message(); |
2489 | 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", 2489, gtest_ar .failure_message()) = ::testing::Message(); |
2490 | 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" , 2490, gtest_ar.failure_message()) = ::testing::Message(); |
2491 | 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" , 2491, gtest_ar.failure_message()) = ::testing::Message(); |
2492 | |
2493 | // Repeat the test, but this time ask for the address that the client |
2494 | // has allocated. |
2495 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2496 | IOAddress("192.0.2.101"), false, false, |
2497 | "", false); |
2498 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2499 | AllocEngine::findReservation(ctx2); |
2500 | allocated_lease = engine.allocateLease4(ctx2); |
2501 | // The client has reservation so the server wants to allocate a |
2502 | // reserved address and doesn't want to renew the address that the |
2503 | // client is currently using. This is equivalent of the case when |
2504 | // the client tries to renew the lease but there is a new reservation |
2505 | // for this client. The server doesn't allow for the renewal and |
2506 | // responds with DHCPNAK to force the client to return to the |
2507 | // DHCP server discovery. |
2508 | 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", 2508, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false").c_str()) = ::testing::Message(); |
2509 | 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", 2509, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2510 | |
2511 | 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", 2511, gtest_ar.failure_message ()) = ::testing::Message(); |
2512 | 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", 2512, gtest_ar .failure_message()) = ::testing::Message(); |
2513 | 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", 2513, gtest_ar.failure_message ()) = ::testing::Message(); |
2514 | 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", 2514, gtest_ar.failure_message ()) = ::testing::Message(); |
2515 | 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", 2515, gtest_ar.failure_message ()) = ::testing::Message(); |
2516 | |
2517 | 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", 2517, gtest_ar .failure_message()) = ::testing::Message(); |
2518 | 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" , 2518, gtest_ar.failure_message()) = ::testing::Message(); |
2519 | 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", 2519, gtest_ar .failure_message()) = ::testing::Message(); |
2520 | 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" , 2520, gtest_ar.failure_message()) = ::testing::Message(); |
2521 | 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" , 2521, gtest_ar.failure_message()) = ::testing::Message(); |
2522 | } |
2523 | |
2524 | // This test checks that the behavior of the allocation engine in the following |
2525 | // scenario: |
2526 | // - Client has a lease in the database. |
2527 | // - Client has a reservation for a different address than the one for which it |
2528 | // has a lease. |
2529 | // - Client sends a DHCPDISCOVER and asks for a different address than reserved |
2530 | // and different from which it has a lease for. |
2531 | // - Server ignores the client's hint and offers a reserved address. |
2532 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test (AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseFakeAllocation", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 2532), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2532), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 2532), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseFakeAllocation_Test ::TestBody() { |
2533 | // Create a reservation for the client. |
2534 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2535 | Host::IDENT_HWADDR, subnet_->getID(), |
2536 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2537 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2538 | CfgMgr::instance().commit(); |
2539 | |
2540 | // Create a lease for a different address than reserved. |
2541 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2542 | &clientid_->getClientId()[0], |
2543 | clientid_->getClientId().size(), |
2544 | 100, time(NULL__null), subnet_->getID(), |
2545 | false, false, "")); |
2546 | LeaseMgrFactory::instance().addLease(lease); |
2547 | |
2548 | AllocEngine engine(0); |
2549 | |
2550 | // Try to allocate a lease and use a completely different address |
2551 | // as a hint. |
2552 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
2553 | IOAddress("192.0.2.102"), false, false, |
2554 | "", true); |
2555 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2556 | AllocEngine::findReservation(ctx1); |
2557 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2558 | |
2559 | // Server should offer a lease for a reserved address. |
2560 | 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", 2560, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2561 | 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" , 2561, gtest_ar.failure_message()) = ::testing::Message(); |
2562 | |
2563 | // The lease should not be allocated until the client sends a DHCPREQUEST. |
2564 | 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", 2564, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false").c_str()) = ::testing::Message(); |
2565 | |
2566 | // Old lease should contain the currently used lease. |
2567 | 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", 2567, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
2568 | 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" , 2568, gtest_ar.failure_message()) = ::testing::Message(); |
2569 | |
2570 | // Repeat the test but this time ask for the address for which the |
2571 | // client has a lease. |
2572 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2573 | IOAddress("192.0.2.101"), false, false, |
2574 | "", true); |
2575 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2576 | AllocEngine::findReservation(ctx2); |
2577 | allocated_lease = engine.allocateLease4(ctx2); |
2578 | |
2579 | // The server should offer the lease, but not for the address that |
2580 | // the client requested. The server should offer a reserved address. |
2581 | 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", 2581, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2582 | 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" , 2582, gtest_ar.failure_message()) = ::testing::Message(); |
2583 | |
2584 | // Old lease should contain the currently used lease. |
2585 | 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", 2585, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
2586 | 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" , 2586, gtest_ar.failure_message()) = ::testing::Message(); |
2587 | } |
2588 | |
2589 | // This test checks that the behavior of the allocation engine in the following |
2590 | // scenario: |
2591 | // - Client has a reservation. |
2592 | // - Client has a lease for a different address than reserved. |
2593 | // - Client sends a DHCPREQUEST to allocate a lease. |
2594 | // - The server determines that the client has a reservation for the |
2595 | // different address than it is currently using and should assign |
2596 | // a reserved address and remove the previous lease. |
2597 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test (AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseNoHint", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2597), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2597), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2597), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHint_Test ::TestBody() { |
2598 | // Create a reservation. |
2599 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2600 | Host::IDENT_HWADDR, subnet_->getID(), |
2601 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2602 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2603 | CfgMgr::instance().commit(); |
2604 | |
2605 | // Create a lease for a different address than reserved. |
2606 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2607 | &clientid_->getClientId()[0], |
2608 | clientid_->getClientId().size(), |
2609 | 100, time(NULL__null), subnet_->getID(), |
2610 | false, false, "")); |
2611 | LeaseMgrFactory::instance().addLease(lease); |
2612 | |
2613 | AllocEngine engine(0); |
2614 | |
2615 | // Try to allocate a lease with providing no hint. |
2616 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2617 | IOAddress("0.0.0.0"), false, false, |
2618 | "", false); |
2619 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2620 | AllocEngine::findReservation(ctx); |
2621 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2622 | |
2623 | // The reserved address should be allocated. |
2624 | 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", 2624, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2625 | 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" , 2625, gtest_ar.failure_message()) = ::testing::Message(); |
2626 | |
2627 | // The previous lease should be removed. |
2628 | 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" , 2628, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
2629 | |
2630 | // Make sure that the allocated lease is committed in the lease database. |
2631 | Lease4Ptr from_mgr = |
2632 | LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
2633 | 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", 2633, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2634 | detailCompareLease(allocated_lease, from_mgr); |
2635 | |
2636 | // Old lease should be returned. |
2637 | 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", 2637, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
2638 | detailCompareLease(lease, ctx.old_lease_); |
2639 | } |
2640 | |
2641 | // This test checks that the behavior of the allocation engine in the following |
2642 | // scenario: |
2643 | // - Client has a reservation. |
2644 | // - Client has a lease for a different address than reserved. |
2645 | // - Client sends a DHCPDISCOVER with no hint. |
2646 | // - Server determines that there is a reservation for the client and that |
2647 | // the reserved address should be offered when the client sends a |
2648 | // DHCPDISCOVER. |
2649 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test (AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseNoHintFakeAllocation", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 2649), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2649), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 2649), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test >); void AllocEngine4Test_reservedAddressExistingLeaseNoHintFakeAllocation_Test ::TestBody() { |
2650 | // Create a reservation. |
2651 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2652 | Host::IDENT_HWADDR, subnet_->getID(), |
2653 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
2654 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2655 | CfgMgr::instance().commit(); |
2656 | |
2657 | // Create a lease for a different address than reserved. |
2658 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2659 | &clientid_->getClientId()[0], |
2660 | clientid_->getClientId().size(), |
2661 | 100, time(NULL__null), subnet_->getID(), |
2662 | false, false, "")); |
2663 | LeaseMgrFactory::instance().addLease(lease); |
2664 | |
2665 | AllocEngine engine(0); |
2666 | |
2667 | // Query the allocation engine for the lease to be allocated for the |
2668 | // client. |
2669 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
2670 | IOAddress("0.0.0.0"), false, false, |
2671 | "", true); |
2672 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
2673 | AllocEngine::findReservation(ctx); |
2674 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2675 | |
2676 | // The server should offer the reserved address. |
2677 | 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", 2677, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2678 | 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" , 2678, gtest_ar.failure_message()) = ::testing::Message(); |
2679 | |
2680 | // The lease should not be committed to the lease database until the |
2681 | // client sends a DHCPREQUEST. |
2682 | 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", 2682, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)" , "true", "false").c_str()) = ::testing::Message(); |
2683 | |
2684 | // The old lease should reflect what is in the database. |
2685 | 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", 2685, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
2686 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
2687 | 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", 2687, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2688 | detailCompareLease(lease, from_mgr); |
2689 | } |
2690 | |
2691 | // This test checks that the behavior of the allocation engine in the following |
2692 | // scenario: |
2693 | // - Client A has a lease for the address. |
2694 | // - Client B has a reservation for the same address that the Client A is using. |
2695 | // - Client B requests allocation of the reserved address. |
2696 | // - Server returns DHCPNAK to the client to indicate that the requested address |
2697 | // can't be allocated. |
2698 | // - Client A renews the lease. |
2699 | // - Server determines that the lease that the Client A is trying to renew |
2700 | // is for the address reserved for Client B. Therefore, the server returns |
2701 | // DHCPNAK to force the client to return to the server discovery. |
2702 | // - The Client A sends DHCPDISCOVER. |
2703 | // - The server offers an address to the Client A, which is different than |
2704 | // the address reserved for Client B. |
2705 | // - The Client A requests allocation of the offered address. |
2706 | // - The server allocates the new address to Client A. |
2707 | // - The Client B sends DHCPDISCOVER to the server. |
2708 | // - The server offers a reserved address to the Client B. |
2709 | // - The Client B requests the offered address. |
2710 | // - The server allocates the reserved address to the Client B. |
2711 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressConflictResolution_Test (AllocEngine4Test_reservedAddressConflictResolution_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressConflictResolution_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressConflictResolution_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressConflictResolution", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2711), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2711), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2711), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressConflictResolution_Test >); void AllocEngine4Test_reservedAddressConflictResolution_Test ::TestBody() { |
2712 | // Create a reservation for client B. |
2713 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
2714 | Host::IDENT_HWADDR, subnet_->getID(), |
2715 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
2716 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2717 | CfgMgr::instance().commit(); |
2718 | |
2719 | // Create a lease for Client A. |
2720 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
2721 | &clientid_->getClientId()[0], |
2722 | clientid_->getClientId().size(), |
2723 | 100, time(NULL__null), subnet_->getID(), |
2724 | false, false, "")); |
2725 | LeaseMgrFactory::instance().addLease(lease); |
2726 | |
2727 | AllocEngine engine(0); |
2728 | |
2729 | // Client B sends a DHCPREQUEST to allocate a reserved lease. The |
2730 | // allocation engine can't allocate a reserved lease for this client |
2731 | // because this specific address is in use by the Client A. |
2732 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr2_, |
2733 | IOAddress("192.0.2.101"), false, false, |
2734 | "", false); |
2735 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2736 | AllocEngine::findReservation(ctx1); |
2737 | Lease4Ptr offered_lease = engine.allocateLease4(ctx1); |
2738 | 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", 2738, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "offered_lease" , "true", "false").c_str()) = ::testing::Message(); |
2739 | |
2740 | 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", 2740, gtest_ar.failure_message ()) = ::testing::Message(); |
2741 | 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", 2741, gtest_ar .failure_message()) = ::testing::Message(); |
2742 | 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", 2742, gtest_ar.failure_message ()) = ::testing::Message(); |
2743 | 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", 2743, gtest_ar.failure_message ()) = ::testing::Message(); |
2744 | 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", 2744, gtest_ar.failure_message ()) = ::testing::Message(); |
2745 | |
2746 | 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", 2746, gtest_ar .failure_message()) = ::testing::Message(); |
2747 | 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" , 2747, gtest_ar.failure_message()) = ::testing::Message(); |
2748 | 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", 2748, gtest_ar .failure_message()) = ::testing::Message(); |
2749 | 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" , 2749, gtest_ar.failure_message()) = ::testing::Message(); |
2750 | 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" , 2750, gtest_ar.failure_message()) = ::testing::Message(); |
2751 | |
2752 | // Client A tries to renew the lease. The renewal should fail because |
2753 | // server detects that Client A doesn't have reservation for this |
2754 | // address. |
2755 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
2756 | IOAddress("192.0.2.101"), false, false, |
2757 | "", false); |
2758 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2759 | AllocEngine::findReservation(ctx2); |
2760 | 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", 2760, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "engine.allocateLease4(ctx2)", "true", "false").c_str()) = :: testing::Message(); |
2761 | 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", 2761, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx2.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
2762 | |
2763 | 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", 2763, gtest_ar.failure_message ()) = ::testing::Message(); |
2764 | 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", 2764, gtest_ar .failure_message()) = ::testing::Message(); |
2765 | 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", 2765, gtest_ar.failure_message ()) = ::testing::Message(); |
2766 | 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", 2766, gtest_ar.failure_message ()) = ::testing::Message(); |
2767 | 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", 2767, gtest_ar.failure_message ()) = ::testing::Message(); |
2768 | |
2769 | 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", 2769, gtest_ar .failure_message()) = ::testing::Message(); |
2770 | 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" , 2770, gtest_ar.failure_message()) = ::testing::Message(); |
2771 | 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", 2771, gtest_ar .failure_message()) = ::testing::Message(); |
2772 | 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" , 2772, gtest_ar.failure_message()) = ::testing::Message(); |
2773 | 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" , 2773, gtest_ar.failure_message()) = ::testing::Message(); |
2774 | |
2775 | // Client A returns to DHCPDISCOVER and should be offered a lease. |
2776 | // The offered lease address must be different than the one the |
2777 | // Client B has reservation for. |
2778 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
2779 | IOAddress("192.0.2.101"), false, false, |
2780 | "", true); |
2781 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2782 | AllocEngine::findReservation(ctx3); |
2783 | offered_lease = engine.allocateLease4(ctx3); |
2784 | 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", 2784, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "offered_lease" , "false", "true").c_str()) = ::testing::Message(); |
2785 | 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", 2785, gtest_ar .failure_message()) = ::testing::Message(); |
2786 | |
2787 | // Client A tries to acquire the lease. It should succeed. At this point |
2788 | // the previous lease should be released and become available for the |
2789 | // Client B. |
2790 | AllocEngine::ClientContext4 ctx4(subnet_, clientid_, hwaddr_, |
2791 | offered_lease->addr_, false, false, |
2792 | "", false); |
2793 | ctx4.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2794 | AllocEngine::findReservation(ctx4); |
2795 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx4); |
2796 | |
2797 | 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", 2797, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2798 | 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", 2798, gtest_ar .failure_message()) = ::testing::Message(); |
2799 | |
2800 | // Client B tries to get the lease again. It should be offered |
2801 | // a reserved lease. |
2802 | AllocEngine::ClientContext4 ctx5(subnet_, ClientIdPtr(), hwaddr2_, |
2803 | IOAddress("0.0.0.0"), false, false, |
2804 | "", true); |
2805 | ctx5.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2806 | AllocEngine::findReservation(ctx5); |
2807 | offered_lease = engine.allocateLease4(ctx5); |
2808 | |
2809 | 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", 2809, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "offered_lease" , "false", "true").c_str()) = ::testing::Message(); |
2810 | 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" , 2810, gtest_ar.failure_message()) = ::testing::Message(); |
2811 | |
2812 | // Client B requests allocation of the lease and it should succeed. |
2813 | AllocEngine::ClientContext4 ctx6(subnet_, ClientIdPtr(), hwaddr2_, |
2814 | offered_lease->addr_, false, false, |
2815 | "", false); |
2816 | ctx6.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2817 | allocated_lease = engine.allocateLease4(ctx6); |
2818 | |
2819 | 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", 2819, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2820 | 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" , 2820, gtest_ar.failure_message()) = ::testing::Message(); |
2821 | } |
2822 | |
2823 | // This test checks that the address is not assigned from the dynamic |
2824 | // pool if it has been reserved for another client. |
2825 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressVsDynamicPool_Test (AllocEngine4Test_reservedAddressVsDynamicPool_Test const & ) = delete; void operator=(AllocEngine4Test_reservedAddressVsDynamicPool_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressVsDynamicPool_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressVsDynamicPool", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 2825), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2825), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2825), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressVsDynamicPool_Test >); void AllocEngine4Test_reservedAddressVsDynamicPool_Test ::TestBody() { |
2826 | // Create a reservation for the client. |
2827 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2828 | Host::IDENT_HWADDR, subnet_->getID(), |
2829 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
2830 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2831 | CfgMgr::instance().commit(); |
2832 | |
2833 | AllocEngine engine(0); |
2834 | |
2835 | // Different client tries to allocate a lease. Note, that we're using |
2836 | // an iterative allocator which would pick the first address from the |
2837 | // dynamic pool, i.e. 192.0.2.100. This address is reserved so we expect |
2838 | // that a different address will be allocated. |
2839 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
2840 | IOAddress("0.0.0.0"), false, false, |
2841 | "", false); |
2842 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2843 | AllocEngine::findReservation(ctx); |
2844 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2845 | |
2846 | 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", 2846, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2847 | 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", 2847, gtest_ar .failure_message()) = ::testing::Message(); |
2848 | |
2849 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); |
2850 | 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", 2850, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
2851 | detailCompareLease(allocated_lease, from_mgr); |
2852 | } |
2853 | |
2854 | // This test checks that the client requesting an address which is |
2855 | // reserved for another client will get no lease or a different |
2856 | // address will be assigned if the client is sending a DHCPDISCOVER. |
2857 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test (AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressHintUsedByOtherClient", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 2857 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 2857), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 2857), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test >); void AllocEngine4Test_reservedAddressHintUsedByOtherClient_Test ::TestBody() { |
2858 | // Create a reservation for the client. |
2859 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2860 | Host::IDENT_HWADDR, subnet_->getID(), |
2861 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
2862 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2863 | CfgMgr::instance().commit(); |
2864 | |
2865 | AllocEngine engine(0); |
2866 | |
2867 | // Different client is requesting this address. |
2868 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
2869 | IOAddress("192.0.2.100"), false, false, |
2870 | "", false); |
2871 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2872 | AllocEngine::findReservation(ctx1); |
2873 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2874 | |
2875 | // The client should get no lease (DHCPNAK). |
2876 | 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", 2876, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false").c_str()) = ::testing::Message(); |
2877 | |
2878 | 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", 2878, gtest_ar.failure_message ()) = ::testing::Message(); |
2879 | 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", 2879, gtest_ar .failure_message()) = ::testing::Message(); |
2880 | 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", 2880, gtest_ar.failure_message ()) = ::testing::Message(); |
2881 | 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", 2881, gtest_ar.failure_message ()) = ::testing::Message(); |
2882 | 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", 2882, gtest_ar.failure_message ()) = ::testing::Message(); |
2883 | |
2884 | 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", 2884, gtest_ar .failure_message()) = ::testing::Message(); |
2885 | 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" , 2885, gtest_ar.failure_message()) = ::testing::Message(); |
2886 | 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", 2886, gtest_ar .failure_message()) = ::testing::Message(); |
2887 | 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" , 2887, gtest_ar.failure_message()) = ::testing::Message(); |
2888 | 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" , 2888, gtest_ar.failure_message()) = ::testing::Message(); |
2889 | |
2890 | // The same client should get a different lease than requested if |
2891 | // if is sending a DHCPDISCOVER (fake allocation is true). |
2892 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
2893 | IOAddress("192.0.2.100"), false, false, |
2894 | "", true); |
2895 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2896 | AllocEngine::findReservation(ctx2); |
2897 | allocated_lease = engine.allocateLease4(ctx2); |
2898 | |
2899 | 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", 2899, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2900 | // Make sure the lease obtained is for a different address. |
2901 | 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", 2901, gtest_ar .failure_message()) = ::testing::Message(); |
2902 | } |
2903 | |
2904 | // This test checks that the allocation engine refuses to allocate an |
2905 | // address when the pool is exhausted, and the only available |
2906 | // address is reserved for a different client. |
2907 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressShortPool_Test (AllocEngine4Test_reservedAddressShortPool_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressShortPool_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressShortPool_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressShortPool", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 2907), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2907), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2907), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedAddressShortPool_Test >); void AllocEngine4Test_reservedAddressShortPool_Test::TestBody () { |
2908 | AllocEngine engine(0); |
2909 | |
2910 | // Create short pool with only one address. |
2911 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
2912 | // Reserve the address for a different client. |
2913 | HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
2914 | Host::IDENT_HWADDR, subnet_->getID(), |
2915 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
2916 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2917 | CfgMgr::instance().commit(); |
2918 | |
2919 | // Allocation engine should determine that the available address is |
2920 | // reserved for someone else and not allocate it. |
2921 | AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, |
2922 | IOAddress("0.0.0.0"), false, false, |
2923 | "", false); |
2924 | ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2925 | AllocEngine::findReservation(ctx1); |
2926 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); |
2927 | |
2928 | 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", 2928, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "true", "false").c_str()) = ::testing::Message(); |
2929 | |
2930 | 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", 2930, gtest_ar.failure_message ()) = ::testing::Message(); |
2931 | 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", 2931, gtest_ar .failure_message()) = ::testing::Message(); |
2932 | 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", 2932, gtest_ar.failure_message ()) = ::testing::Message(); |
2933 | 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", 2933, gtest_ar.failure_message ()) = ::testing::Message(); |
2934 | 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", 2934, gtest_ar.failure_message ()) = ::testing::Message(); |
2935 | |
2936 | 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", 2936, gtest_ar .failure_message()) = ::testing::Message(); |
2937 | 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" , 2937, gtest_ar.failure_message()) = ::testing::Message(); |
2938 | 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", 2938, gtest_ar .failure_message()) = ::testing::Message(); |
2939 | 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" , 2939, gtest_ar.failure_message()) = ::testing::Message(); |
2940 | 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" , 2940, gtest_ar.failure_message()) = ::testing::Message(); |
2941 | |
2942 | // Now, let's remove the reservation. |
2943 | initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); |
2944 | CfgMgr::instance().commit(); |
2945 | |
2946 | // Address should be successfully allocated. |
2947 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, |
2948 | IOAddress("0.0.0.0"), false, false, |
2949 | "", false); |
2950 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2951 | AllocEngine::findReservation(ctx2); |
2952 | allocated_lease = engine.allocateLease4(ctx2); |
2953 | |
2954 | 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", 2954, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2955 | 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" , 2955, gtest_ar.failure_message()) = ::testing::Message(); |
2956 | } |
2957 | |
2958 | // This test checks that the AllocEngine allocates an address from the |
2959 | // dynamic pool if the client's reservation is made for a hostname but |
2960 | // not for an address. |
2961 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedHostname_Test (AllocEngine4Test_reservedHostname_Test const &) = delete ; void operator=(AllocEngine4Test_reservedHostname_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedHostname_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedHostname", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 2961), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 2961), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 2961), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_reservedHostname_Test >); void AllocEngine4Test_reservedHostname_Test::TestBody( ) { |
2962 | AllocEngine engine(0); |
2963 | |
2964 | // Create a reservation for a hostname. Address is set to 0 which |
2965 | // indicates that there is no reservation. |
2966 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
2967 | Host::IDENT_HWADDR, subnet_->getID(), |
2968 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
2969 | "foo.example.org")); |
2970 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
2971 | CfgMgr::instance().commit(); |
2972 | |
2973 | // Try to allocate a lease. |
2974 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
2975 | IOAddress("192.0.2.109"), false, false, |
2976 | "foo.example.org", true); |
2977 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
2978 | AllocEngine::findReservation(ctx); |
2979 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
2980 | 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", 2980, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2981 | 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" , 2981, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "allocated_lease->addr_.isV4Zero()", "true", "false").c_str ()) = ::testing::Message(); |
2982 | 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" , 2982, gtest_ar.failure_message()) = ::testing::Message(); |
2983 | |
2984 | ctx.requested_address_ = allocated_lease->addr_; |
2985 | ctx.fake_allocation_ = false; |
2986 | allocated_lease = engine.allocateLease4(ctx); |
2987 | 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", 2987, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
2988 | 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" , 2988, gtest_ar.failure_message()) = ::testing::Message(); |
2989 | } |
2990 | |
2991 | // This test checks that the AllocEngine::findReservation method finds |
2992 | // and returns host reservation for the DHCPv4 client using the data from |
2993 | // the client context. If the host reservation can't be found, it sets |
2994 | // the value of NULL in the host_ field of the client context. |
2995 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_findReservation_Test (AllocEngine4Test_findReservation_Test const &) = delete; void operator=(AllocEngine4Test_findReservation_Test const & ) = delete; }; ::testing::TestInfo* const AllocEngine4Test_findReservation_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "findReservation", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 2995), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 2995), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 2995 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_findReservation_Test >); void AllocEngine4Test_findReservation_Test::TestBody() { |
2996 | // Create the instance of the allocation engine. |
2997 | AllocEngine engine(0); |
2998 | |
2999 | // Context is required to call the AllocEngine::findReservation. |
3000 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3001 | IOAddress("0.0.0.0"), false, false, |
3002 | "", false); |
3003 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3004 | ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_); |
3005 | ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getClientId()); |
3006 | |
3007 | // There is no reservation in the database so no host should be returned. |
3008 | ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.findReservation (ctx); }; } catch (...) { goto gtest_label_testnothrow_3008; } } else gtest_label_testnothrow_3008: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3008, "Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3009 | 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", 3009, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false").c_str()) = ::testing::Message(); |
3010 | |
3011 | // Create a reservation for the client. |
3012 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3013 | Host::IDENT_HWADDR, subnet_->getID(), |
3014 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
3015 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3016 | CfgMgr::instance().commit(); |
3017 | |
3018 | // This time the reservation should be returned. |
3019 | ctx.hosts_.clear(); |
3020 | ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.findReservation (ctx); }; } catch (...) { goto gtest_label_testnothrow_3020; } } else gtest_label_testnothrow_3020: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3020, "Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3021 | 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", 3021, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3022 | 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" , 3022, gtest_ar.failure_message()) = ::testing::Message(); |
3023 | |
3024 | // It shouldn't be returned when reservations-in-subnet is disabled. |
3025 | subnet_->setReservationsInSubnet(false); |
3026 | ctx.hosts_.clear(); |
3027 | ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.findReservation (ctx); }; } catch (...) { goto gtest_label_testnothrow_3027; } } else gtest_label_testnothrow_3027: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3027, "Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3028 | 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", 3028, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false").c_str()) = ::testing::Message(); |
3029 | |
3030 | // Check the reservations-in-subnet and reservations-out-of-pool flags. |
3031 | subnet_->setReservationsInSubnet(true); |
3032 | subnet_->setReservationsOutOfPool(true); |
3033 | ctx.hosts_.clear(); |
3034 | ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.findReservation (ctx); }; } catch (...) { goto gtest_label_testnothrow_3034; } } else gtest_label_testnothrow_3034: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3034, "Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3035 | 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", 3035, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3036 | 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" , 3036, gtest_ar.failure_message()) = ::testing::Message(); |
3037 | |
3038 | // This time use the client identifier to search for the host. |
3039 | host.reset(new Host(&clientid_->getClientId()[0], |
3040 | clientid_->getClientId().size(), |
3041 | Host::IDENT_DUID, subnet_->getID(), |
3042 | SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); |
3043 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3044 | CfgMgr::instance().commit(); |
3045 | |
3046 | ctx.hosts_.clear(); |
3047 | ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.findReservation (ctx); }; } catch (...) { goto gtest_label_testnothrow_3047; } } else gtest_label_testnothrow_3047: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3047, "Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3048 | 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", 3048, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3049 | 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" , 3049, gtest_ar.failure_message()) = ::testing::Message(); |
3050 | |
3051 | // Remove the subnet. Subnet id is required to find host reservations, so |
3052 | // if it is set to NULL, no reservation should be returned |
3053 | ctx.subnet_.reset(); |
3054 | ctx.hosts_.clear(); |
3055 | ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.findReservation (ctx); }; } catch (...) { goto gtest_label_testnothrow_3055; } } else gtest_label_testnothrow_3055: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3055, "Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3056 | 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", 3056, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false").c_str()) = ::testing::Message(); |
3057 | |
3058 | // The same if there is a mismatch of the subnet id between the reservation |
3059 | // and the context. |
3060 | ctx.subnet_ = subnet_; |
3061 | host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3062 | Host::IDENT_HWADDR, subnet_->getID() + 1, |
3063 | SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); |
3064 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3065 | CfgMgr::instance().commit(); |
3066 | |
3067 | ctx.hosts_.clear(); |
3068 | ASSERT_NO_THROW(engine.findReservation(ctx))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.findReservation (ctx); }; } catch (...) { goto gtest_label_testnothrow_3068; } } else gtest_label_testnothrow_3068: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3068, "Expected: " "engine.findReservation(ctx)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3069 | 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", 3069, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "true", "false").c_str()) = ::testing::Message(); |
3070 | } |
3071 | |
3072 | // This test checks if the simple IPv4 allocation can succeed and that |
3073 | // statistic for allocated addresses is increased appropriately. |
3074 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_simpleAlloc4Stats_Test (AllocEngine4Test_simpleAlloc4Stats_Test const &) = delete ; void operator=(AllocEngine4Test_simpleAlloc4Stats_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_simpleAlloc4Stats_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "simpleAlloc4Stats", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 3074), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3074), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3074), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_simpleAlloc4Stats_Test >); void AllocEngine4Test_simpleAlloc4Stats_Test::TestBody () { |
3075 | boost::scoped_ptr<AllocEngine> engine; |
3076 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_3076 ; } } else gtest_label_testnothrow_3076: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3076, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3077 | 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", 3077, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
3078 | |
3079 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
3080 | false, true, "somehost.example.com.", false); |
3081 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3082 | |
3083 | // Let's pretend 100 addresses were allocated already |
3084 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
3085 | "assigned-addresses"); |
3086 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
3087 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
3088 | subnet_->getID()); |
3089 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
3090 | |
3091 | Lease4Ptr lease = engine->allocateLease4(ctx); |
3092 | // The new lease has been allocated, so the old lease should not exist. |
3093 | 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", 3093, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3094 | |
3095 | // Check that we got a lease |
3096 | ASSERT_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", 3096, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3097 | |
3098 | // The statistic should be there and it should be increased by 1 (to 101). |
3099 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
3100 | 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", 3100, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "stat", "false", "true").c_str()) = ::testing::Message (); |
3101 | 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" , 3101, gtest_ar.failure_message()) = ::testing::Message(); |
3102 | cumulative += 1; |
3103 | 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" , 3104, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
3104 | 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" , 3104, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
3105 | glbl_cumulative += 1; |
3106 | 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" , 3106, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
3107 | } |
3108 | |
3109 | // This test checks if the fake allocation (for DHCPDISCOVER) can succeed |
3110 | // and that it doesn't increase allocated-addresses statistic. |
3111 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_fakeAlloc4Stat_Test (AllocEngine4Test_fakeAlloc4Stat_Test const &) = delete; void operator=(AllocEngine4Test_fakeAlloc4Stat_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_fakeAlloc4Stat_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fakeAlloc4Stat", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 3111), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 3111), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3111 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fakeAlloc4Stat_Test >); void AllocEngine4Test_fakeAlloc4Stat_Test::TestBody() { |
3112 | boost::scoped_ptr<AllocEngine> engine; |
3113 | ASSERT_NO_THROW(engine.reset(new AllocEngine(100)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(100)); }; } catch (...) { goto gtest_label_testnothrow_3113 ; } } else gtest_label_testnothrow_3113: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 3113, "Expected: " "engine.reset(new AllocEngine(100))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3114 | 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", 3114, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
3115 | |
3116 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3117 | IOAddress("0.0.0.0"), false, true, |
3118 | "host.example.com.", true); |
3119 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3120 | |
3121 | // Let's pretend 100 addresses were allocated already |
3122 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
3123 | "assigned-addresses"); |
3124 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
3125 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
3126 | subnet_->getID()); |
3127 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
3128 | |
3129 | Lease4Ptr lease = engine->allocateLease4(ctx); |
3130 | |
3131 | // The new lease has been allocated, so the old lease should not exist. |
3132 | 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", 3132, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3133 | |
3134 | // Check that we got a lease |
3135 | ASSERT_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", 3135, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3136 | |
3137 | // The statistic should be there and it should not be increased |
3138 | // (should be still equal to 100). |
3139 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
3140 | 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", 3140, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "stat", "false", "true").c_str()) = ::testing::Message (); |
3141 | 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" , 3141, gtest_ar.failure_message()) = ::testing::Message(); |
3142 | 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" , 3143, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
3143 | 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" , 3143, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
3144 | 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" , 3144, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
3145 | } |
3146 | |
3147 | // This test checks that the allocated-addresses statistic is decreased when |
3148 | // the client has a lease and a reservation for a different address is |
3149 | // available. |
3150 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_reservedAddressExistingLeaseStat_Test (AllocEngine4Test_reservedAddressExistingLeaseStat_Test const &) = delete; void operator=(AllocEngine4Test_reservedAddressExistingLeaseStat_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_reservedAddressExistingLeaseStat_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "reservedAddressExistingLeaseStat", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 3150), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3150), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3150), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_reservedAddressExistingLeaseStat_Test >); void AllocEngine4Test_reservedAddressExistingLeaseStat_Test ::TestBody() { |
3151 | // Create the reservation for the client. |
3152 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3153 | Host::IDENT_HWADDR, subnet_->getID(), |
3154 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); |
3155 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3156 | CfgMgr::instance().commit(); |
3157 | |
3158 | // Create a lease for the client with a different address than the reserved |
3159 | // one. |
3160 | Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, |
3161 | &clientid_->getClientId()[0], |
3162 | clientid_->getClientId().size(), |
3163 | 100, time(NULL__null), subnet_->getID(), |
3164 | false, false, "")); |
3165 | LeaseMgrFactory::instance().addLease(lease); |
3166 | |
3167 | AllocEngine engine(100); |
3168 | |
3169 | // Let's pretend 100 addresses were allocated already |
3170 | string name = StatsMgr::generateName("subnet", subnet_->getID(), |
3171 | "assigned-addresses"); |
3172 | StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); |
3173 | int64_t cumulative = getStatistics("cumulative-assigned-addresses", |
3174 | subnet_->getID()); |
3175 | int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); |
3176 | |
3177 | // Request allocation of the reserved address. |
3178 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3179 | IOAddress("192.0.2.123"), false, false, |
3180 | "", false); |
3181 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3182 | AllocEngine::findReservation(ctx); |
3183 | |
3184 | Lease4Ptr allocated_lease = engine.allocateLease4(ctx); |
3185 | |
3186 | 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", 3186, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "allocated_lease" , "false", "true").c_str()) = ::testing::Message(); |
3187 | |
3188 | // The statistic should be still at 100. Note that it was decreased |
3189 | // (because old lease was removed), but also increased (because the |
3190 | // new lease was immediately allocated). |
3191 | ObservationPtr stat = StatsMgr::instance().getObservation(name); |
3192 | 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", 3192, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "stat", "false", "true").c_str()) = ::testing::Message (); |
3193 | 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" , 3193, gtest_ar.failure_message()) = ::testing::Message(); |
3194 | cumulative += 1; |
3195 | 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" , 3196, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message() |
3196 | 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" , 3196, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", cumulative, subnet_->getID())" , "false", "true").c_str()) = ::testing::Message(); |
3197 | glbl_cumulative += 1; |
3198 | 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" , 3198, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "testStatistics(\"cumulative-assigned-addresses\", glbl_cumulative)" , "false", "true").c_str()) = ::testing::Message(); |
3199 | |
3200 | // Lets' double check that the actual allocation took place. |
3201 | 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", 3201, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.fake_allocation_" , "true", "false").c_str()) = ::testing::Message(); |
3202 | } |
3203 | |
3204 | // This test checks the behavior of the allocation engine in the following |
3205 | // scenario: |
3206 | // - Client has no lease in the database. |
3207 | // - Client has a global reservation outside of the subnet. |
3208 | // - Client sends DISCOVER |
3209 | // - Client is allocated an address within the subnet. |
3210 | // - Lease is not added to the lease database |
3211 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test (AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test const &) = delete; void operator=(AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedNonMatchingAddressDiscover", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3211), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3211), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3211), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressDiscover_Test ::TestBody() { |
3212 | // Create reservation for the client. |
3213 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3214 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3215 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3216 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3217 | CfgMgr::instance().commit(); |
3218 | |
3219 | AllocEngine engine(0); |
3220 | |
3221 | subnet_->setReservationsGlobal(true); |
3222 | |
3223 | // Query allocation engine for the lease to be assigned to this |
3224 | // client without specifying the address to be assigned. |
3225 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3226 | IOAddress("0.0.0.0"), false, false, |
3227 | "", true); |
3228 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3229 | |
3230 | // Look up the host. |
3231 | AllocEngine::findReservation(ctx); |
3232 | |
3233 | // We should have the correct current host |
3234 | EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "alloc_engine4_unittest.cc", 3234, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3235 | 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" , 3235, gtest_ar.failure_message()) = ::testing::Message(); |
3236 | 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" , 3236, gtest_ar.failure_message()) = ::testing::Message(); |
3237 | |
3238 | // We should allocate an address in the subnet |
3239 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3240 | ASSERT_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", 3240, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3241 | 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" , 3241, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
3242 | |
3243 | // This is a "fake" allocation so the returned lease should not be committed |
3244 | // to the lease database. |
3245 | 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" , 3245, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
3246 | |
3247 | // Client had no lease in the database, so the old lease returned should |
3248 | // be NULL. |
3249 | 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", 3249, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3250 | } |
3251 | |
3252 | // This test checks the behavior of the allocation engine in the following |
3253 | // scenario: |
3254 | // - Client has no lease in the database. |
3255 | // - Client has a global reservation matching the current subnet. |
3256 | // - Client sends DISCOVER |
3257 | // - Client is allocated the reserved address. |
3258 | // - Lease is not added to the lease database |
3259 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test (AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test const &) = delete; void operator=(AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedMatchingAddressDiscover", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3259), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3259), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3259), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressDiscover_Test ::TestBody() { |
3260 | // Create reservation for the client. |
3261 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3262 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3263 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
3264 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3265 | CfgMgr::instance().commit(); |
3266 | |
3267 | AllocEngine engine(0); |
3268 | |
3269 | subnet_->setReservationsGlobal(true); |
3270 | |
3271 | // Query allocation engine for the lease to be assigned to this |
3272 | // client without specifying the address to be assigned. |
3273 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3274 | IOAddress("0.0.0.0"), false, false, |
3275 | "", true); |
3276 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3277 | |
3278 | // Look up the host. |
3279 | AllocEngine::findReservation(ctx); |
3280 | |
3281 | // We should have the correct current host |
3282 | 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", 3282, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3283 | 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" , 3283, gtest_ar.failure_message()) = ::testing::Message(); |
3284 | 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" , 3284, gtest_ar.failure_message()) = ::testing::Message(); |
3285 | |
3286 | // We should allocate the reserved address. |
3287 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3288 | ASSERT_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", 3288, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3289 | 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", 3289, gtest_ar .failure_message()) = ::testing::Message(); |
3290 | |
3291 | // This is a "fake" allocation so the returned lease should not be committed |
3292 | // to the lease database. |
3293 | 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" , 3293, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
3294 | |
3295 | // Client had no lease in the database, so the old lease returned should |
3296 | // be NULL. |
3297 | 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", 3297, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3298 | } |
3299 | |
3300 | // This test checks the behavior of the allocation engine in the following |
3301 | // scenario: |
3302 | // - Client has no lease in the database. |
3303 | // - Client has a global reservation outside the current subnet. |
3304 | // - Client sends REQUEST |
3305 | // - Client is allocated a dynamic address. |
3306 | // - Lease is added to the lease database |
3307 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test (AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test const &) = delete; void operator=(AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedNonMatchingAddressRequest", nullptr , nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3307), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3307), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3307), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedNonMatchingAddressRequest_Test ::TestBody() { |
3308 | // Create reservation for the client. |
3309 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3310 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3311 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3312 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3313 | CfgMgr::instance().commit(); |
3314 | |
3315 | AllocEngine engine(0); |
3316 | |
3317 | subnet_->setReservationsGlobal(true); |
3318 | |
3319 | // Query allocation engine for the lease to be assigned to this |
3320 | // client without specifying the address to be assigned. |
3321 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3322 | IOAddress("0.0.0.0"), false, false, |
3323 | "", false); |
3324 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3325 | |
3326 | // Look up the host. |
3327 | AllocEngine::findReservation(ctx); |
3328 | |
3329 | // We should have the correct current host |
3330 | 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", 3330, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3331 | 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" , 3331, gtest_ar.failure_message()) = ::testing::Message(); |
3332 | 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" , 3332, gtest_ar.failure_message()) = ::testing::Message(); |
3333 | |
3334 | // We should allocate the reserved address. |
3335 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3336 | ASSERT_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", 3336, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3337 | 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" , 3337, gtest_ar.failure_message()) = ::testing::Message(); |
3338 | 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" , 3338, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
3339 | |
3340 | // Check that the lease is indeed in LeaseMgr |
3341 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3342 | 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", 3342, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
3343 | |
3344 | // Now check that the lease in LeaseMgr has the same parameters |
3345 | detailCompareLease(lease, from_mgr); |
3346 | |
3347 | // Client had no lease in the database, so the old lease returned should |
3348 | // be NULL. |
3349 | 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", 3349, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3350 | } |
3351 | |
3352 | // This test checks the behavior of the allocation engine in the following |
3353 | // scenario: |
3354 | // - Client has no lease in the database. |
3355 | // - Client has a global reservation matching the current subnet. |
3356 | // - Client sends REQUEST |
3357 | // - Client is allocated the reserved address. |
3358 | // - Lease is added to the lease database |
3359 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test (AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test const &) = delete; void operator=(AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationReservedMatchingAddressRequest", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3359), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3359), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3359), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test >); void AllocEngine4Test_globalReservationReservedMatchingAddressRequest_Test ::TestBody() { |
3360 | // Create reservation for the client. |
3361 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3362 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3363 | SUBNET_ID_UNUSED, IOAddress("192.0.2.10"))); |
3364 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3365 | CfgMgr::instance().commit(); |
3366 | |
3367 | AllocEngine engine(0); |
3368 | |
3369 | subnet_->setReservationsGlobal(true); |
3370 | |
3371 | // Query allocation engine for the lease to be assigned to this |
3372 | // client without specifying the address to be assigned. |
3373 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3374 | IOAddress("0.0.0.0"), false, false, |
3375 | "", false); |
3376 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3377 | |
3378 | // Look up the host. |
3379 | AllocEngine::findReservation(ctx); |
3380 | |
3381 | // We should have the correct current host |
3382 | 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", 3382, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3383 | 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" , 3383, gtest_ar.failure_message()) = ::testing::Message(); |
3384 | 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" , 3384, gtest_ar.failure_message()) = ::testing::Message(); |
3385 | |
3386 | // We should allocate the reserved address. |
3387 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3388 | ASSERT_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", 3388, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3389 | 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", 3389, gtest_ar .failure_message()) = ::testing::Message(); |
3390 | |
3391 | // Check that the lease is indeed in LeaseMgr |
3392 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3393 | 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", 3393, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
3394 | |
3395 | // Now check that the lease in LeaseMgr has the same parameters |
3396 | detailCompareLease(lease, from_mgr); |
3397 | |
3398 | // Client had no lease in the database, so the old lease returned should |
3399 | // be NULL. |
3400 | 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", 3400, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3401 | } |
3402 | |
3403 | // This test checks the behavior of the allocation engine in the following |
3404 | // scenario: |
3405 | // - Client has no lease in the database. |
3406 | // - Client has a global reservation. |
3407 | // - Client sends DISCOVER |
3408 | // - Client is allocated a dynamic address from matched subnet |
3409 | // - Lease is not added to the lease database |
3410 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_globalReservationDynamicDiscover_Test (AllocEngine4Test_globalReservationDynamicDiscover_Test const &) = delete; void operator=(AllocEngine4Test_globalReservationDynamicDiscover_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationDynamicDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationDynamicDiscover", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 3410), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3410), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3410), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_globalReservationDynamicDiscover_Test >); void AllocEngine4Test_globalReservationDynamicDiscover_Test ::TestBody() { |
3411 | // Create reservation for the client. |
3412 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3413 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3414 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
3415 | "foo.example.org")); |
3416 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3417 | CfgMgr::instance().commit(); |
3418 | |
3419 | AllocEngine engine(0); |
3420 | |
3421 | subnet_->setReservationsGlobal(true); |
3422 | |
3423 | // Query allocation engine for the lease to be assigned to this |
3424 | // client without specifying the address to be assigned. |
3425 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3426 | IOAddress("0.0.0.0"), false, false, |
3427 | "", true); |
3428 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3429 | |
3430 | // Look up the host. |
3431 | AllocEngine::findReservation(ctx); |
3432 | |
3433 | // We should have the correct current host |
3434 | 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", 3434, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3435 | 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" , 3435, gtest_ar.failure_message()) = ::testing::Message(); |
3436 | 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" , 3436, gtest_ar.failure_message()) = ::testing::Message(); |
3437 | |
3438 | // We should allocate a dynamic address. |
3439 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3440 | ASSERT_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", 3440, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3441 | 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" , 3441, gtest_ar.failure_message()) = ::testing::Message(); |
3442 | |
3443 | // This is a "fake" allocation so the returned lease should not be committed |
3444 | // to the lease database. |
3445 | 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" , 3445, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
3446 | |
3447 | // Client had no lease in the database, so the old lease returned should |
3448 | // be NULL. |
3449 | 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", 3449, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3450 | } |
3451 | |
3452 | // This test checks the behavior of the allocation engine in the following |
3453 | // scenario: |
3454 | // - Client has no lease in the database. |
3455 | // - Client has a global reservation. |
3456 | // - Client sends REQUEST |
3457 | // - Client is allocated a dynamic address from matched subnet |
3458 | // - Lease is added to the lease database |
3459 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_globalReservationDynamicRequest_Test (AllocEngine4Test_globalReservationDynamicRequest_Test const & ) = delete; void operator=(AllocEngine4Test_globalReservationDynamicRequest_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_globalReservationDynamicRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "globalReservationDynamicRequest", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 3459), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3459), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3459), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_globalReservationDynamicRequest_Test >); void AllocEngine4Test_globalReservationDynamicRequest_Test ::TestBody() { |
3460 | // Create reservation for the client. |
3461 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3462 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3463 | SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), |
3464 | "foo.example.org")); |
3465 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3466 | CfgMgr::instance().commit(); |
3467 | |
3468 | AllocEngine engine(0); |
3469 | |
3470 | subnet_->setReservationsGlobal(true); |
3471 | |
3472 | // Query allocation engine for the lease to be assigned to this |
3473 | // client without specifying the address to be assigned. |
3474 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3475 | IOAddress("0.0.0.0"), false, false, |
3476 | "", false); |
3477 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3478 | |
3479 | // Look up the host. |
3480 | AllocEngine::findReservation(ctx); |
3481 | |
3482 | // We should have the correct current host |
3483 | 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", 3483, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3484 | 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" , 3484, gtest_ar.failure_message()) = ::testing::Message(); |
3485 | 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" , 3485, gtest_ar.failure_message()) = ::testing::Message(); |
3486 | |
3487 | // We should allocate a dynamic address. |
3488 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3489 | ASSERT_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", 3489, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3490 | 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" , 3490, gtest_ar.failure_message()) = ::testing::Message(); |
3491 | |
3492 | // Check that the lease is indeed in LeaseMgr |
3493 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3494 | 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", 3494, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
3495 | |
3496 | // Now check that the lease in LeaseMgr has the same parameters |
3497 | detailCompareLease(lease, from_mgr); |
3498 | |
3499 | // Client had no lease in the database, so the old lease returned should |
3500 | // be NULL. |
3501 | 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", 3501, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3502 | } |
3503 | |
3504 | // This test checks the behavior of the allocation engine in the following |
3505 | // scenario: |
3506 | // - Client has no lease in the database. |
3507 | // - Client has a subnet reservation. |
3508 | // - Client sends DISCOVER |
3509 | // - Client is allocated the reserved address. |
3510 | // - Lease is not added to the lease database |
3511 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_mixedReservationReservedAddressDiscover_Test (AllocEngine4Test_mixedReservationReservedAddressDiscover_Test const &) = delete; void operator=(AllocEngine4Test_mixedReservationReservedAddressDiscover_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_mixedReservationReservedAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "mixedReservationReservedAddressDiscover", nullptr, nullptr , ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3511), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3511), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3511), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressDiscover_Test >); void AllocEngine4Test_mixedReservationReservedAddressDiscover_Test ::TestBody() { |
3512 | // Create reservation for the client. |
3513 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3514 | Host::IDENT_HWADDR, subnet_->getID(), |
3515 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
3516 | "foo.example.org")); |
3517 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3518 | CfgMgr::instance().commit(); |
3519 | |
3520 | AllocEngine engine(0); |
3521 | |
3522 | subnet_->setReservationsGlobal(true); |
3523 | subnet_->setReservationsInSubnet(true); |
3524 | |
3525 | // Query allocation engine for the lease to be assigned to this |
3526 | // client without specifying the address to be assigned. |
3527 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3528 | IOAddress("0.0.0.0"), false, false, |
3529 | "", true); |
3530 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
3531 | |
3532 | // Look up the host. |
3533 | AllocEngine::findReservation(ctx); |
3534 | |
3535 | // We should have the correct current host |
3536 | EXPECT_TRUE(ctx.currentHost())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx.currentHost())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "alloc_engine4_unittest.cc", 3536, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3537 | EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getHostname()" , "host->getHostname()", ctx.currentHost()->getHostname (), host->getHostname()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "alloc_engine4_unittest.cc" , 3537, gtest_ar.failure_message()) = ::testing::Message(); |
3538 | EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("ctx.currentHost()->getIPv4Reservation()" , "host->getIPv4Reservation()", ctx.currentHost()->getIPv4Reservation (), host->getIPv4Reservation()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "alloc_engine4_unittest.cc" , 3538, gtest_ar.failure_message()) = ::testing::Message(); |
3539 | |
3540 | // We should allocate the reserved address. |
3541 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3542 | ASSERT_TRUE(lease)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(lease)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3542, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3543 | 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" , 3543, gtest_ar.failure_message()) = ::testing::Message(); |
3544 | |
3545 | // This is a "fake" allocation so the returned lease should not be committed |
3546 | // to the lease database. |
3547 | 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" , 3547, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
3548 | |
3549 | // Client had no lease in the database, so the old lease returned should |
3550 | // be NULL. |
3551 | 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", 3551, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3552 | } |
3553 | |
3554 | // This test checks the behavior of the allocation engine in the following |
3555 | // scenario: |
3556 | // - Client has no lease in the database. |
3557 | // - Client has a subnet reservation. |
3558 | // - Client sends REQUEST |
3559 | // - Client is allocated the reserved address. |
3560 | // - Lease is added to the lease database |
3561 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_mixedReservationReservedAddressRequest_Test (AllocEngine4Test_mixedReservationReservedAddressRequest_Test const &) = delete; void operator=(AllocEngine4Test_mixedReservationReservedAddressRequest_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_mixedReservationReservedAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "mixedReservationReservedAddressRequest", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3561), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3561), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3561), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_mixedReservationReservedAddressRequest_Test >); void AllocEngine4Test_mixedReservationReservedAddressRequest_Test ::TestBody() { |
3562 | // Create reservation for the client. |
3563 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3564 | Host::IDENT_HWADDR, subnet_->getID(), |
3565 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
3566 | "foo.example.org")); |
3567 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3568 | CfgMgr::instance().commit(); |
3569 | |
3570 | AllocEngine engine(0); |
3571 | |
3572 | subnet_->setReservationsGlobal(true); |
3573 | subnet_->setReservationsInSubnet(true); |
3574 | |
3575 | // Query allocation engine for the lease to be assigned to this |
3576 | // client without specifying the address to be assigned. |
3577 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3578 | IOAddress("0.0.0.0"), false, false, |
3579 | "", false); |
3580 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3581 | |
3582 | // Look up the host. |
3583 | AllocEngine::findReservation(ctx); |
3584 | |
3585 | // We should have the correct current host |
3586 | 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", 3586, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3587 | 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" , 3587, gtest_ar.failure_message()) = ::testing::Message(); |
3588 | 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" , 3588, gtest_ar.failure_message()) = ::testing::Message(); |
3589 | |
3590 | // We should allocate the reserved address. |
3591 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3592 | ASSERT_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", 3592, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3593 | 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" , 3593, gtest_ar.failure_message()) = ::testing::Message(); |
3594 | |
3595 | // Check that the lease is indeed in LeaseMgr |
3596 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3597 | 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", 3597, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
3598 | |
3599 | // Now check that the lease in LeaseMgr has the same parameters |
3600 | detailCompareLease(lease, from_mgr); |
3601 | |
3602 | // Client had no lease in the database, so the old lease returned should |
3603 | // be NULL. |
3604 | 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", 3604, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3605 | } |
3606 | |
3607 | // This test checks the behavior of the allocation engine in the following |
3608 | // scenario: |
3609 | // - Client has no lease in the database. |
3610 | // - Client has a global and a subnet reservation. |
3611 | // - Client sends DISCOVER |
3612 | // - Client is allocated the reserved address. |
3613 | // - Lease is not added to the lease database |
3614 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_bothReservationReservedAddressDiscover_Test (AllocEngine4Test_bothReservationReservedAddressDiscover_Test const &) = delete; void operator=(AllocEngine4Test_bothReservationReservedAddressDiscover_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_bothReservationReservedAddressDiscover_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bothReservationReservedAddressDiscover", nullptr, nullptr, ::testing::internal::CodeLocation("alloc_engine4_unittest.cc" , 3614), (::testing::internal::GetTypeId<AllocEngine4Test> ()), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3614), ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 3614), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressDiscover_Test >); void AllocEngine4Test_bothReservationReservedAddressDiscover_Test ::TestBody() { |
3615 | // Create reservations for the client. |
3616 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3617 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3618 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3619 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
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 | "", true); |
3637 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 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 | // This is a "fake" allocation so the returned lease should not be committed |
3653 | // to the lease database. |
3654 | 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" , 3654, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().getLease4(lease->addr_)", "true" , "false").c_str()) = ::testing::Message(); |
3655 | |
3656 | // Client had no lease in the database, so the old lease returned should |
3657 | // be NULL. |
3658 | 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", 3658, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
3659 | } |
3660 | |
3661 | // This test checks the behavior of the allocation engine in the following |
3662 | // scenario: |
3663 | // - Client has no lease in the database. |
3664 | // - Client has a global and a subnet reservation. |
3665 | // - Client sends REQUEST |
3666 | // - Client is allocated the reserved address. |
3667 | // - Lease is added to the lease database |
3668 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_bothReservationReservedAddressRequest_Test (AllocEngine4Test_bothReservationReservedAddressRequest_Test const &) = delete; void operator=(AllocEngine4Test_bothReservationReservedAddressRequest_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_bothReservationReservedAddressRequest_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bothReservationReservedAddressRequest", nullptr, nullptr, :: testing::internal::CodeLocation("alloc_engine4_unittest.cc", 3668 ), (::testing::internal::GetTypeId<AllocEngine4Test>()) , ::testing::internal::SuiteApiResolver< AllocEngine4Test> ::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 3668), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 3668), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_bothReservationReservedAddressRequest_Test >); void AllocEngine4Test_bothReservationReservedAddressRequest_Test ::TestBody() { |
3669 | // Create reservations for the client. |
3670 | HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3671 | Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, |
3672 | SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); |
3673 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); |
3674 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
3675 | Host::IDENT_HWADDR, subnet_->getID(), |
3676 | SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), |
3677 | "foo.example.org")); |
3678 | CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); |
3679 | CfgMgr::instance().commit(); |
3680 | |
3681 | AllocEngine engine(0); |
3682 | |
3683 | subnet_->setReservationsGlobal(true); |
3684 | subnet_->setReservationsInSubnet(true); |
3685 | |
3686 | // Query allocation engine for the lease to be assigned to this |
3687 | // client without specifying the address to be assigned. |
3688 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3689 | IOAddress("0.0.0.0"), false, false, |
3690 | "", false); |
3691 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3692 | |
3693 | // Look up the host. |
3694 | AllocEngine::findReservation(ctx); |
3695 | |
3696 | // We should have the correct current host |
3697 | 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", 3697, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.currentHost()" , "false", "true").c_str()) = ::testing::Message(); |
3698 | 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" , 3698, gtest_ar.failure_message()) = ::testing::Message(); |
3699 | 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" , 3699, gtest_ar.failure_message()) = ::testing::Message(); |
3700 | |
3701 | // We should allocate the reserved address. |
3702 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3703 | ASSERT_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", 3703, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3704 | 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" , 3704, gtest_ar.failure_message()) = ::testing::Message(); |
3705 | |
3706 | // Check that the lease is indeed in LeaseMgr |
3707 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
3708 | 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", 3708, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
3709 | |
3710 | // Now check that the lease in LeaseMgr has the same parameters |
3711 | detailCompareLease(lease, from_mgr); |
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 | // Exercises AllocEnginer4Test::updateExtendedInfo4() through various |
3719 | // permutations of client packet content. |
3720 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_updateExtendedInfo4_Test (AllocEngine4Test_updateExtendedInfo4_Test const &) = delete ; void operator=(AllocEngine4Test_updateExtendedInfo4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_updateExtendedInfo4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "updateExtendedInfo4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 3720), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3720), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3720), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_updateExtendedInfo4_Test >); void AllocEngine4Test_updateExtendedInfo4_Test::TestBody () { |
3721 | |
3722 | // Structure that defines a test scenario. |
3723 | struct Scenario { |
3724 | std::string description_; // test description |
3725 | std::string orig_context_json_; // user context the lease begins with |
3726 | std::string rai_data_; // RAI option the client packet contains |
3727 | std::string exp_context_json_; // expected user context on the lease |
3728 | bool exp_ret; // expected returned value |
3729 | }; |
3730 | |
3731 | // Test scenarios. |
3732 | std::vector<Scenario> scenarios { |
3733 | { |
3734 | "no context, no rai", |
3735 | "", |
3736 | "", |
3737 | "", |
3738 | false |
3739 | }, |
3740 | { |
3741 | "some original context, no rai", |
3742 | "{\"foo\": 123}", |
3743 | "", |
3744 | "{\"foo\": 123}", |
3745 | false |
3746 | }, |
3747 | { |
3748 | "no original context, rai", |
3749 | "", |
3750 | "0x52060104aabbccdd", |
3751 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3752 | " \"0x0104AABBCCDD\" } } }", |
3753 | true |
3754 | }, |
3755 | { |
3756 | "no original context, rai, remote and relay ids", |
3757 | "", |
3758 | "0x520a02030102030c03aabbcc", |
3759 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3760 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
3761 | " \"relay-id\": \"AABBCC\" } } }", |
3762 | true |
3763 | }, |
3764 | { |
3765 | "some original context, rai", |
3766 | "{\"foo\": 123, \"ISC\":{\"bar\": 456}}", |
3767 | "0x52060104aabbccdd", |
3768 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3769 | " \"0x0104AABBCCDD\" }, \"bar\": 456 }, \"foo\": 123 }", |
3770 | true |
3771 | }, |
3772 | { |
3773 | "bad original context, rai", |
3774 | "[\"foo\"]", |
3775 | "0x52060104aabbccdd", |
3776 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3777 | " \"0x0104AABBCCDD\" } } }", |
3778 | true |
3779 | }, |
3780 | { |
3781 | "some original context with bad isc entry, rai", |
3782 | "{\"foo\": 123, \"ISC\":[\"bar\"]}", |
3783 | "0x52060104aabbccdd", |
3784 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3785 | " \"0x0104AABBCCDD\" } }, \"foo\": 123 }", |
3786 | true |
3787 | }, |
3788 | { |
3789 | "some original context, rai, remote and relay ids", |
3790 | "{\"foo\": 123, \"ISC\":{ \"bar\": 456}}", |
3791 | "0x520a02030102030c03aabbcc", |
3792 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3793 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
3794 | " \"relay-id\": \"AABBCC\" }, \"bar\": 456 }, \"foo\": 123 }", |
3795 | true |
3796 | }, |
3797 | { |
3798 | "original rai context, no rai", |
3799 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3800 | " \"0x0104AABBCCDD\" } } }", |
3801 | "", |
3802 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3803 | " \"0x0104AABBCCDD\" } } }", |
3804 | false |
3805 | }, |
3806 | { |
3807 | "original rai context, different rai", |
3808 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3809 | " \"0x0104AABBCCDD\" } } }", |
3810 | "0x52060104ddeeffaa", |
3811 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3812 | " \"0x0104DDEEFFAA\" } } }", |
3813 | true |
3814 | }, |
3815 | { |
3816 | "original rai context, different rai, remote and relay ids", |
3817 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3818 | " \"0x0104AABBCCDD\" } } }", |
3819 | "0x520a02030102030c03aabbcc", |
3820 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
3821 | " \"0x02030102030C03AABBCC\", \"remote-id\": \"010203\"," |
3822 | " \"relay-id\": \"AABBCC\" } } }", |
3823 | true |
3824 | }}; |
3825 | |
3826 | // Create the allocation engine, context and lease. |
3827 | NakedAllocEngine engine(0); |
3828 | |
3829 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3830 | IOAddress::IPV4_ZERO_ADDRESS(), |
3831 | false, false, "", true); |
3832 | |
3833 | // All scenarios require storage to be enabled. |
3834 | ctx.subnet_->setStoreExtendedInfo(true); |
3835 | |
3836 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3837 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3838 | ASSERT_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", 3838, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3839 | 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" , 3839, gtest_ar.failure_message()) = ::testing::Message(); |
3840 | |
3841 | // Verify that the lease begins with no user context. |
3842 | ConstElementPtr user_context = lease->getContext(); |
3843 | 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", 3843, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "true", "false").c_str()) = ::testing::Message(); |
3844 | |
3845 | // Iterate over the test scenarios. |
3846 | ElementPtr orig_context; |
3847 | ElementPtr exp_context; |
3848 | for (auto const& scenario : scenarios) { |
3849 | SCOPED_TRACE(scenario.description_)::testing::ScopedTrace gtest_trace_3849( "alloc_engine4_unittest.cc" , 3849, (scenario.description_)); |
3850 | |
3851 | // Create the original user context from JSON. |
3852 | if (scenario.orig_context_json_.empty()) { |
3853 | orig_context.reset(); |
3854 | } else { |
3855 | ASSERT_NO_THROW(orig_context = Element::fromJSON(scenario.orig_context_json_))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { orig_context = Element::fromJSON(scenario.orig_context_json_); }; } catch (...) { goto gtest_label_testnothrow_3855; } } else gtest_label_testnothrow_3855 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3855, "Expected: " "orig_context = Element::fromJSON(scenario.orig_context_json_)" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
3856 | << "invalid orig_context_json_, test is broken"; |
3857 | } |
3858 | |
3859 | // Create the expected user context from JSON. |
3860 | if (scenario.exp_context_json_.empty()) { |
3861 | exp_context.reset(); |
3862 | } else { |
3863 | ASSERT_NO_THROW(exp_context = Element::fromJSON(scenario.exp_context_json_))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { exp_context = Element::fromJSON(scenario.exp_context_json_); }; } catch ( ...) { goto gtest_label_testnothrow_3863; } } else gtest_label_testnothrow_3863 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3863, "Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
3864 | << "invalid exp_context_json_, test is broken"; |
3865 | } |
3866 | |
3867 | // Initialize lease's user context. |
3868 | lease->setContext(orig_context); |
3869 | if (!orig_context) { |
3870 | 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", 3870, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false").c_str()) = ::testing ::Message(); |
3871 | } else { |
3872 | 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", 3872, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true").c_str()) = ::testing ::Message(); |
3873 | 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" , 3873, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "orig_context->equals(*(lease->getContext()))", "false" , "true").c_str()) = ::testing::Message(); |
3874 | } |
3875 | |
3876 | // Create the client packet and the add RAI option (if one). |
3877 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3878 | if (!scenario.rai_data_.empty()) { |
3879 | std::vector<uint8_t> opt_data; |
3880 | ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { util::str ::decodeFormattedHexString(scenario.rai_data_, opt_data); }; } catch (...) { goto gtest_label_testnothrow_3880; } } else gtest_label_testnothrow_3880 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3880, "Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
3881 | << "scenario.rai_data_ is invalid, test is broken"; |
3882 | OptionDefinitionPtr rai_def = |
3883 | LibDHCP::getOptionDef(DHCP4_OPTION_SPACE"dhcp4", |
3884 | DHO_DHCP_AGENT_OPTIONS); |
3885 | ASSERT_TRUE(rai_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(rai_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3885, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "rai_def" , "false", "true").c_str()) = ::testing::Message() << "could not get RAI definition, test is broken"; |
3886 | 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" , 3886, gtest_ar.failure_message()) = ::testing::Message(); |
3887 | 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", 3887, gtest_ar. failure_message()) = ::testing::Message(); |
3888 | 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", 3888, gtest_ar. failure_message()) = ::testing::Message(); |
3889 | std::vector<uint8_t> rai_data(opt_data.cbegin() + 2, |
3890 | opt_data.cend()); |
3891 | OptionCustomPtr rai; |
3892 | ASSERT_NO_THROW(rai.reset(new OptionCustom(*rai_def, Option::V4,switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { rai.reset (new OptionCustom(*rai_def, Option::V4, rai_data)); }; } catch (...) { goto gtest_label_testnothrow_3893; } } else gtest_label_testnothrow_3893 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3893, "Expected: " "rai.reset(new OptionCustom(*rai_def, Option::V4, rai_data))" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
3893 | rai_data)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { rai.reset (new OptionCustom(*rai_def, Option::V4, rai_data)); }; } catch (...) { goto gtest_label_testnothrow_3893; } } else gtest_label_testnothrow_3893 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3893, "Expected: " "rai.reset(new OptionCustom(*rai_def, Option::V4, rai_data))" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
3894 | << "could not create rai option, test is broken"; |
3895 | ctx.query_->addOption(rai); |
3896 | } |
3897 | |
3898 | // Call AllocEngine::updateLease4ExtendeInfo(). |
3899 | bool ret = false; |
3900 | 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", 3900, "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", 3900, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
3901 | 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" , 3901, gtest_ar.failure_message()) = ::testing::Message(); |
3902 | |
3903 | // Verify the lease has the expected user context content. |
3904 | if (!exp_context) { |
3905 | 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", 3905, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false").c_str()) = ::testing ::Message(); |
3906 | } else { |
3907 | 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", 3907, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true").c_str()) = ::testing ::Message(); |
3908 | 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" , 3908, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true").c_str()) = ::testing::Message() |
3909 | << "expected: " << *(exp_context) << std::endl |
3910 | << " actual: " << *(lease->getContext()) << std::endl; |
3911 | } |
3912 | } |
3913 | } |
3914 | |
3915 | // Verifies that recovered stashed RAI is not saved in extended info. |
3916 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_stashAgentOptions_Test (AllocEngine4Test_stashAgentOptions_Test const &) = delete ; void operator=(AllocEngine4Test_stashAgentOptions_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_stashAgentOptions_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "stashAgentOptions", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 3916), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3916), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3916), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_stashAgentOptions_Test >); void AllocEngine4Test_stashAgentOptions_Test::TestBody () { |
3917 | // Create the allocation engine, context and lease. |
3918 | NakedAllocEngine engine(0); |
3919 | |
3920 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
3921 | IOAddress::IPV4_ZERO_ADDRESS(), |
3922 | false, false, "", true); |
3923 | ctx.subnet_->setStoreExtendedInfo(true); |
3924 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
3925 | Lease4Ptr lease = engine.allocateLease4(ctx); |
3926 | ASSERT_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", 3926, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
3927 | 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" , 3927, gtest_ar.failure_message()) = ::testing::Message(); |
3928 | |
3929 | // Verify that the lease begins with no user context. |
3930 | ConstElementPtr user_context = lease->getContext(); |
3931 | 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", 3931, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "true", "false").c_str()) = ::testing::Message(); |
3932 | |
3933 | // Add a RAI in the query. |
3934 | std::string rai_str = "0104aabbccdd"; |
3935 | std::vector<uint8_t> rai_data; |
3936 | ASSERT_NO_THROW(util::str::decodeFormattedHexString(rai_str, rai_data))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { util::str ::decodeFormattedHexString(rai_str, rai_data); }; } catch (... ) { goto gtest_label_testnothrow_3936; } } else gtest_label_testnothrow_3936 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3936, "Expected: " "util::str::decodeFormattedHexString(rai_str, rai_data)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
3937 | OptionDefinitionPtr rai_def = LibDHCP::getOptionDef(DHCP4_OPTION_SPACE"dhcp4", |
3938 | DHO_DHCP_AGENT_OPTIONS); |
3939 | ASSERT_TRUE(rai_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(rai_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "alloc_engine4_unittest.cc", 3939, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "rai_def" , "false", "true").c_str()) = ::testing::Message(); |
3940 | OptionCustomPtr rai; |
3941 | ASSERT_NO_THROW(rai.reset(new OptionCustom(*rai_def, Option::V4, rai_data)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { rai.reset (new OptionCustom(*rai_def, Option::V4, rai_data)); }; } catch (...) { goto gtest_label_testnothrow_3941; } } else gtest_label_testnothrow_3941 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 3941, "Expected: " "rai.reset(new OptionCustom(*rai_def, Option::V4, rai_data))" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message(); |
3942 | ctx.query_->addOption(rai); |
3943 | |
3944 | // Verifies that the RAI is saved into lease extended info. |
3945 | bool ret = false; |
3946 | 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", 3946, "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", 3946, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
3947 | 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", 3947, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "ret", "false", "true").c_str()) = ::testing::Message (); |
3948 | user_context = lease->getContext(); |
3949 | 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", 3949, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "false", "true").c_str()) = ::testing::Message(); |
3950 | lease->setContext(ElementPtr()); |
3951 | |
3952 | // Set stash-agent-options to true. |
3953 | CfgMgr::instance().getStagingCfg()-> |
3954 | addConfiguredGlobal("stash-agent-options", Element::create(true)); |
3955 | CfgMgr::instance().commit(); |
3956 | |
3957 | // Verifies that the RAI is saved into lease extended info. |
3958 | ret = false; |
Value stored to 'ret' is never read | |
3959 | 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", 3959, "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", 3959, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
3960 | 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", 3960, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "ret", "false", "true").c_str()) = ::testing::Message (); |
3961 | user_context = lease->getContext(); |
3962 | 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", 3962, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "false", "true").c_str()) = ::testing::Message(); |
3963 | lease->setContext(ElementPtr()); |
3964 | |
3965 | // Put the query in the STASH_AGENT_OPTIONS class. |
3966 | ctx.query_->addClass("STASH_AGENT_OPTIONS"); |
3967 | |
3968 | // Verifies that the RAI is not saved into lease extended info. |
3969 | ret = false; |
3970 | 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", 3970, "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", 3970, "Failed") = ::testing::Message () << "ret = engine.callUpdateLease4ExtendedInfo(lease, ctx)" << " threw non-std::exception"; } }; |
3971 | 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", 3971, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "ret", "true", "false").c_str()) = ::testing::Message (); |
3972 | user_context = lease->getContext(); |
3973 | 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", 3973, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "user_context" , "true", "false").c_str()) = ::testing::Message(); |
3974 | } |
3975 | |
3976 | // Verifies that the extended data (e.g. RAI option for now) is |
3977 | // added to a V4 lease when leases are created and/or renewed, |
3978 | // when store-extended-info is true. |
3979 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_storeExtendedInfoEnabled4_Test (AllocEngine4Test_storeExtendedInfoEnabled4_Test const &) = delete; void operator=(AllocEngine4Test_storeExtendedInfoEnabled4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_storeExtendedInfoEnabled4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "storeExtendedInfoEnabled4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 3979), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 3979), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 3979), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoEnabled4_Test >); void AllocEngine4Test_storeExtendedInfoEnabled4_Test:: TestBody() { |
3980 | |
3981 | // Structure that defines a test scenario. |
3982 | struct Scenario { |
3983 | std::string description_; // test description |
3984 | std::vector<uint8_t> mac_; // MAC address |
3985 | std::string rai_data_; // RAI option the client packet contains |
3986 | std::string exp_context_json_; // expected user context on the lease |
3987 | std::string exp_address_; // expected lease address |
3988 | }; |
3989 | |
3990 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
3991 | std::string mac1_addr = "192.0.2.100"; |
3992 | |
3993 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
3994 | std::string mac2_addr = "192.0.2.101"; |
3995 | |
3996 | // Test scenarios. |
3997 | std::vector<Scenario> scenarios { |
3998 | { |
3999 | "create client one without rai", |
4000 | mac1, |
4001 | "", |
4002 | "", |
4003 | mac1_addr |
4004 | }, |
4005 | { |
4006 | "renew client one without rai", |
4007 | {}, |
4008 | "", |
4009 | "", |
4010 | mac1_addr |
4011 | }, |
4012 | { |
4013 | "create client two with rai", |
4014 | mac2, |
4015 | "0x52050104a1b1c1d1", |
4016 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
4017 | " \"0x52050104A1B1C1D1\" } } }", |
4018 | mac2_addr |
4019 | }, |
4020 | { |
4021 | "renew client two without rai", |
4022 | {}, |
4023 | "", |
4024 | "{ \"ISC\": { \"relay-agent-info\": { \"sub-options\":" |
4025 | " \"0x52050104A1B1C1D1\" } } }", |
4026 | mac2_addr |
4027 | }}; |
4028 | |
4029 | // Create the allocation engine, context and lease. |
4030 | NakedAllocEngine engine(0); |
4031 | |
4032 | // All of the scenarios require storage to be enabled. |
4033 | subnet_->setStoreExtendedInfo(true); |
4034 | |
4035 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4036 | IOAddress::IPV4_ZERO_ADDRESS(), |
4037 | false, false, "", false); |
4038 | |
4039 | // Iterate over the test scenarios. |
4040 | Lease4Ptr lease; |
4041 | for (auto const& scenario : scenarios) { |
4042 | SCOPED_TRACE(scenario.description_)::testing::ScopedTrace gtest_trace_4042( "alloc_engine4_unittest.cc" , 4042, (scenario.description_)); |
4043 | |
4044 | ElementPtr exp_context; |
4045 | // Create the expected user context from JSON. |
4046 | if (!scenario.exp_context_json_.empty()) { |
4047 | ASSERT_NO_THROW(exp_context = Element::fromJSON(scenario.exp_context_json_))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { exp_context = Element::fromJSON(scenario.exp_context_json_); }; } catch ( ...) { goto gtest_label_testnothrow_4047; } } else gtest_label_testnothrow_4047 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4047, "Expected: " "exp_context = Element::fromJSON(scenario.exp_context_json_)" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
4048 | << "invalid exp_context_json_, test is broken"; |
4049 | } |
4050 | |
4051 | // If we have a MAC address this scenario is for a new client. |
4052 | if (!scenario.mac_.empty()) { |
4053 | std::cout << "setting mac address" << std::endl; |
4054 | ASSERT_NO_THROW(ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { ctx.hwaddr_ .reset(new HWAddr(scenario.mac_, HTYPE_ETHER)); }; } catch (... ) { goto gtest_label_testnothrow_4054; } } else gtest_label_testnothrow_4054 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4054, "Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message() |
4055 | << "invalid MAC address, test is broken"; |
4056 | } |
4057 | |
4058 | // Create the client packet and the add RAI option (if one). |
4059 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4060 | if (!scenario.rai_data_.empty()) { |
4061 | std::vector<uint8_t> opt_data; |
4062 | ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { util::str ::decodeFormattedHexString(scenario.rai_data_, opt_data); }; } catch (...) { goto gtest_label_testnothrow_4062; } } else gtest_label_testnothrow_4062 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4062, "Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
4063 | << "scenario.rai_data_ is invalid, test is broken"; |
4064 | OptionPtr rai; |
4065 | ASSERT_NO_THROW(rai.reset(new Option(Option::V4, 0x52, opt_data)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { rai.reset (new Option(Option::V4, 0x52, opt_data)); }; } catch (...) { goto gtest_label_testnothrow_4065; } } else gtest_label_testnothrow_4065 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4065, "Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message() |
4066 | << "could not create rai option, test is broken"; |
4067 | |
4068 | ctx.query_->addOption(rai); |
4069 | } |
4070 | |
4071 | // Create or renew the lease. |
4072 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4073 | ASSERT_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", 4073, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4074 | 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" , 4074, gtest_ar.failure_message()) = ::testing::Message(); |
4075 | |
4076 | // Verify the lease has the expected user context content. |
4077 | if (!exp_context) { |
4078 | 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", 4078, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false").c_str()) = ::testing ::Message(); |
4079 | } else { |
4080 | 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", 4080, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "false", "true").c_str()) = ::testing ::Message(); |
4081 | 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" , 4081, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "exp_context->equals(*(lease->getContext()))", "false" , "true").c_str()) = ::testing::Message() |
4082 | << "expected: " << *(exp_context) << std::endl |
4083 | << " actual: " << *(lease->getContext()) << std::endl; |
4084 | } |
4085 | } |
4086 | } |
4087 | |
4088 | // Verifies that the extended data (e.g. RAI option for now) is |
4089 | // not added to a V4 lease when leases are created and/or renewed, |
4090 | // when store-extended-info is false. |
4091 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_storeExtendedInfoDisabled4_Test (AllocEngine4Test_storeExtendedInfoDisabled4_Test const & ) = delete; void operator=(AllocEngine4Test_storeExtendedInfoDisabled4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_storeExtendedInfoDisabled4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "storeExtendedInfoDisabled4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 4091), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4091), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4091), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_storeExtendedInfoDisabled4_Test >); void AllocEngine4Test_storeExtendedInfoDisabled4_Test:: TestBody() { |
4092 | |
4093 | // Structure that defines a test scenario. |
4094 | struct Scenario { |
4095 | std::string description_; // test description |
4096 | std::vector<uint8_t> mac_; // MAC address |
4097 | std::string rai_data_; // RAI option the client packet contains |
4098 | std::string exp_address_; // expected lease address |
4099 | }; |
4100 | |
4101 | std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01 }; |
4102 | std::string mac1_addr = "192.0.2.100"; |
4103 | |
4104 | std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02 }; |
4105 | std::string mac2_addr = "192.0.2.101"; |
4106 | |
4107 | // Test scenarios. |
4108 | std::vector<Scenario> scenarios { |
4109 | { |
4110 | "create client one without rai", |
4111 | mac1, |
4112 | "", |
4113 | mac1_addr |
4114 | }, |
4115 | { |
4116 | "renew client one without rai", |
4117 | {}, |
4118 | "", |
4119 | mac1_addr |
4120 | }, |
4121 | { |
4122 | "create client two with rai", |
4123 | mac2, |
4124 | "0x52050104a1b1c1d1", |
4125 | mac2_addr |
4126 | }, |
4127 | { |
4128 | "renew client two with rai", |
4129 | {}, |
4130 | "0x52050104a1b1c1d1", |
4131 | mac2_addr |
4132 | }}; |
4133 | |
4134 | // Create the allocation engine, context and lease. |
4135 | NakedAllocEngine engine(0); |
4136 | |
4137 | // All of the scenarios require storage to be disabled. |
4138 | subnet_->setStoreExtendedInfo(false); |
4139 | |
4140 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4141 | IOAddress::IPV4_ZERO_ADDRESS(), |
4142 | false, false, "", false); |
4143 | |
4144 | Lease4Ptr lease; |
4145 | |
4146 | // Iterate over the test scenarios. |
4147 | for (auto const& scenario : scenarios) { |
4148 | SCOPED_TRACE(scenario.description_)::testing::ScopedTrace gtest_trace_4148( "alloc_engine4_unittest.cc" , 4148, (scenario.description_)); |
4149 | |
4150 | // If we have a MAC address this scenario is for a new client. |
4151 | if (!scenario.mac_.empty()) { |
4152 | std::cout << "setting mac address" << std::endl; |
4153 | ASSERT_NO_THROW(ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { ctx.hwaddr_ .reset(new HWAddr(scenario.mac_, HTYPE_ETHER)); }; } catch (... ) { goto gtest_label_testnothrow_4153; } } else gtest_label_testnothrow_4153 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4153, "Expected: " "ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message() |
4154 | << "invalid MAC address, test is broken"; |
4155 | } |
4156 | |
4157 | // Create the client packet and the add RAI option (if one). |
4158 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4159 | if (!scenario.rai_data_.empty()) { |
4160 | std::vector<uint8_t> opt_data; |
4161 | ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { util::str ::decodeFormattedHexString(scenario.rai_data_, opt_data); }; } catch (...) { goto gtest_label_testnothrow_4161; } } else gtest_label_testnothrow_4161 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4161, "Expected: " "util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)" " doesn't throw an exception.\n" " Actual: it throws.") = :: testing::Message() |
4162 | << "scenario.rai_data_ is invalid, test is broken"; |
4163 | OptionPtr rai; |
4164 | ASSERT_NO_THROW(rai.reset(new Option(Option::V4, 0x52, opt_data)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { rai.reset (new Option(Option::V4, 0x52, opt_data)); }; } catch (...) { goto gtest_label_testnothrow_4164; } } else gtest_label_testnothrow_4164 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4164, "Expected: " "rai.reset(new Option(Option::V4, 0x52, opt_data))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message() |
4165 | << "could not create rai option, test is broken"; |
4166 | |
4167 | ctx.query_->addOption(rai); |
4168 | } |
4169 | |
4170 | // Create or renew the lease. |
4171 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4172 | ASSERT_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", 4172, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4173 | 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" , 4173, gtest_ar.failure_message()) = ::testing::Message(); |
4174 | |
4175 | // Verify the lease does not have user context content. |
4176 | 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", 4176, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->getContext()", "true", "false").c_str()) = ::testing ::Message(); |
4177 | } |
4178 | } |
4179 | |
4180 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
4181 | // using cache threshold. |
4182 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverCacheThreshold4_Test (AllocEngine4Test_discoverCacheThreshold4_Test const &) = delete; void operator=(AllocEngine4Test_discoverCacheThreshold4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheThreshold4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheThreshold4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4182), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4182), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4182), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheThreshold4_Test >); void AllocEngine4Test_discoverCacheThreshold4_Test::TestBody () { |
4183 | boost::scoped_ptr<AllocEngine> engine; |
4184 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4184 ; } } else gtest_label_testnothrow_4184: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4184, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4185 | 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", 4185, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4186 | |
4187 | // Set valid lifetime to 500. |
4188 | uint32_t valid = 500; |
4189 | subnet_->setValid(valid); |
4190 | |
4191 | // Set the threshold to 25%. |
4192 | subnet_->setCacheThreshold(.25); |
4193 | |
4194 | IOAddress addr("192.0.2.105"); |
4195 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4196 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4197 | valid, now, subnet_->getID())); |
4198 | 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", 4198, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4199 | 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" , 4199, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
4200 | |
4201 | // Create a context for fake allocation. |
4202 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4203 | false, false, "", true); |
4204 | |
4205 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4206 | lease = engine->allocateLease4(ctx); |
4207 | // Check that we got that single lease. |
4208 | ASSERT_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", 4208, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4209 | 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" , 4209, gtest_ar.failure_message()) = ::testing::Message(); |
4210 | |
4211 | // The lease was reused. |
4212 | time_t age = lease->cltt_ - now; |
4213 | 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" , 4213, gtest_ar.failure_message()) = ::testing::Message(); |
4214 | 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" , 4214, gtest_ar.failure_message()) = ::testing::Message(); |
4215 | 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", 4215, gtest_ar .failure_message()) = ::testing::Message(); |
4216 | |
4217 | // Check other lease parameters. |
4218 | 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", 4218, gtest_ar .failure_message()) = ::testing::Message(); |
4219 | 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", 4219 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
4220 | 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" , 4220, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
4221 | 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", 4221, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
4222 | 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" , 4222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
4223 | } |
4224 | |
4225 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
4226 | // using cache threshold. |
4227 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestCacheThreshold4_Test (AllocEngine4Test_requestCacheThreshold4_Test const &) = delete ; void operator=(AllocEngine4Test_requestCacheThreshold4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheThreshold4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheThreshold4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4227), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4227), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4227), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheThreshold4_Test >); void AllocEngine4Test_requestCacheThreshold4_Test::TestBody () { |
4228 | boost::scoped_ptr<AllocEngine> engine; |
4229 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4229 ; } } else gtest_label_testnothrow_4229: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4229, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4230 | 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", 4230, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4231 | |
4232 | // Set valid lifetime to 500. |
4233 | uint32_t valid = 500; |
4234 | subnet_->setValid(valid); |
4235 | |
4236 | // Set the threshold to 25%. |
4237 | subnet_->setCacheThreshold(.25); |
4238 | |
4239 | IOAddress addr("192.0.2.105"); |
4240 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4241 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4242 | valid, now, subnet_->getID())); |
4243 | 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", 4243, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4244 | // Copy the lease, so as it can be compared with. |
4245 | Lease4Ptr original_lease(new Lease4(*lease)); |
4246 | 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" , 4246, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
4247 | |
4248 | // Create a context for real allocation. |
4249 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4250 | false, false, "", false); |
4251 | |
4252 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4253 | lease = engine->allocateLease4(ctx); |
4254 | // Check that we got that single lease. |
4255 | ASSERT_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", 4255, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4256 | 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" , 4256, gtest_ar.failure_message()) = ::testing::Message(); |
4257 | |
4258 | // The lease was reused. |
4259 | time_t age = lease->cltt_ - now; |
4260 | 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" , 4260, gtest_ar.failure_message()) = ::testing::Message(); |
4261 | 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" , 4261, gtest_ar.failure_message()) = ::testing::Message(); |
4262 | 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", 4262, gtest_ar .failure_message()) = ::testing::Message(); |
4263 | |
4264 | // Check other lease parameters. |
4265 | 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", 4265, gtest_ar .failure_message()) = ::testing::Message(); |
4266 | 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", 4266 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
4267 | 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" , 4267, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
4268 | 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", 4268, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
4269 | 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" , 4269, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
4270 | |
4271 | // Check the lease was not updated in the database. |
4272 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4273 | 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", 4273, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
4274 | |
4275 | detailCompareLease(original_lease, from_mgr); |
4276 | } |
4277 | |
4278 | /// We proved that there is no different from the "cache" feature between |
4279 | /// discovers and request at the exception of the lease database update. |
4280 | |
4281 | // This test checks if a lease can be reused in DHCPDISCOVER (fake allocation) |
4282 | // using cache max age. |
4283 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverCacheMaxAge4_Test (AllocEngine4Test_discoverCacheMaxAge4_Test const &) = delete ; void operator=(AllocEngine4Test_discoverCacheMaxAge4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheMaxAge4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheMaxAge4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4283), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4283), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4283), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheMaxAge4_Test >); void AllocEngine4Test_discoverCacheMaxAge4_Test::TestBody () { |
4284 | boost::scoped_ptr<AllocEngine> engine; |
4285 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4285 ; } } else gtest_label_testnothrow_4285: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4285, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4286 | 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", 4286, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4287 | |
4288 | // Set valid lifetime to 500. |
4289 | uint32_t valid = 500; |
4290 | subnet_->setValid(valid); |
4291 | |
4292 | // Set the max age to 200. |
4293 | subnet_->setCacheMaxAge(200); |
4294 | |
4295 | IOAddress addr("192.0.2.105"); |
4296 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4297 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4298 | valid, now, subnet_->getID())); |
4299 | 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", 4299, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4300 | 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" , 4300, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
4301 | |
4302 | // Create a context for fake allocation. |
4303 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4304 | false, false, "", true); |
4305 | |
4306 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4307 | lease = engine->allocateLease4(ctx); |
4308 | // Check that we got that single lease. |
4309 | ASSERT_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", 4309, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4310 | 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" , 4310, gtest_ar.failure_message()) = ::testing::Message(); |
4311 | |
4312 | // The lease was reused. |
4313 | time_t age = lease->cltt_ - now; |
4314 | 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" , 4314, gtest_ar.failure_message()) = ::testing::Message(); |
4315 | 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" , 4315, gtest_ar.failure_message()) = ::testing::Message(); |
4316 | 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", 4316, gtest_ar .failure_message()) = ::testing::Message(); |
4317 | |
4318 | // Check other lease parameters. |
4319 | 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", 4319, gtest_ar .failure_message()) = ::testing::Message(); |
4320 | 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", 4320 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
4321 | 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" , 4321, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
4322 | 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", 4322, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
4323 | 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" , 4323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
4324 | } |
4325 | |
4326 | // This test checks if a lease can be reused in DHCPREQUEST (real allocation) |
4327 | // using both cache threshold and max age. |
4328 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestCacheBoth4_Test (AllocEngine4Test_requestCacheBoth4_Test const &) = delete ; void operator=(AllocEngine4Test_requestCacheBoth4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheBoth4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheBoth4", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 4328), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4328), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4328), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBoth4_Test >); void AllocEngine4Test_requestCacheBoth4_Test::TestBody () { |
4329 | boost::scoped_ptr<AllocEngine> engine; |
4330 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4330 ; } } else gtest_label_testnothrow_4330: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4330, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4331 | 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", 4331, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4332 | |
4333 | // Set valid lifetime to 500. |
4334 | uint32_t valid = 500; |
4335 | subnet_->setValid(valid); |
4336 | |
4337 | // Set the threshold to 25%. |
4338 | subnet_->setCacheThreshold(.25); |
4339 | |
4340 | // Set the max age to 200. |
4341 | subnet_->setCacheMaxAge(200); |
4342 | |
4343 | IOAddress addr("192.0.2.105"); |
4344 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4345 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4346 | valid, now, subnet_->getID())); |
4347 | 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", 4347, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4348 | // Copy the lease, so as it can be compared with. |
4349 | Lease4Ptr original_lease(new Lease4(*lease)); |
4350 | 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" , 4350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
4351 | |
4352 | // Create a context for real allocation. |
4353 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4354 | false, false, "", false); |
4355 | |
4356 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4357 | lease = engine->allocateLease4(ctx); |
4358 | // Check that we got that single lease. |
4359 | ASSERT_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", 4359, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4360 | 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" , 4360, gtest_ar.failure_message()) = ::testing::Message(); |
4361 | |
4362 | // The lease was reused. |
4363 | time_t age = lease->cltt_ - now; |
4364 | 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" , 4364, gtest_ar.failure_message()) = ::testing::Message(); |
4365 | 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" , 4365, gtest_ar.failure_message()) = ::testing::Message(); |
4366 | 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", 4366, gtest_ar .failure_message()) = ::testing::Message(); |
4367 | |
4368 | // Check other lease parameters. |
4369 | 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", 4369, gtest_ar .failure_message()) = ::testing::Message(); |
4370 | 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", 4370 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
4371 | 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" , 4371, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
4372 | 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", 4372, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
4373 | 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" , 4373, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
4374 | |
4375 | // Check the lease was not updated in the database. |
4376 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4377 | 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", 4377, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
4378 | |
4379 | detailCompareLease(original_lease, from_mgr); |
4380 | } |
4381 | |
4382 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
4383 | // using too small cache threshold. |
4384 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverCacheBadThreshold4_Test (AllocEngine4Test_discoverCacheBadThreshold4_Test const & ) = delete; void operator=(AllocEngine4Test_discoverCacheBadThreshold4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheBadThreshold4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheBadThreshold4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 4384), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4384), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4384), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheBadThreshold4_Test >); void AllocEngine4Test_discoverCacheBadThreshold4_Test:: TestBody() { |
4385 | boost::scoped_ptr<AllocEngine> engine; |
4386 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4386 ; } } else gtest_label_testnothrow_4386: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4386, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4387 | 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", 4387, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4388 | |
4389 | // Set valid lifetime to 500. |
4390 | uint32_t valid = 500; |
4391 | subnet_->setValid(valid); |
4392 | |
4393 | // Set the threshold to 10%. |
4394 | subnet_->setCacheThreshold(.10); |
4395 | |
4396 | IOAddress addr("192.0.2.105"); |
4397 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4398 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4399 | valid, now, subnet_->getID())); |
4400 | 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", 4400, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4401 | 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" , 4401, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
4402 | |
4403 | // Create a context for fake allocation. |
4404 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4405 | false, false, "", true); |
4406 | |
4407 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4408 | lease = engine->allocateLease4(ctx); |
4409 | // Check that we got that single lease. |
4410 | ASSERT_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", 4410, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4411 | 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" , 4411, gtest_ar.failure_message()) = ::testing::Message(); |
4412 | |
4413 | // The lease was not reused. |
4414 | 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" , 4414, gtest_ar.failure_message()) = ::testing::Message(); |
4415 | } |
4416 | |
4417 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
4418 | // using too small cache max age. |
4419 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestCacheBadMaxAge4_Test (AllocEngine4Test_requestCacheBadMaxAge4_Test const &) = delete ; void operator=(AllocEngine4Test_requestCacheBadMaxAge4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheBadMaxAge4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheBadMaxAge4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4419), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4419), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4419), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheBadMaxAge4_Test >); void AllocEngine4Test_requestCacheBadMaxAge4_Test::TestBody () { |
4420 | boost::scoped_ptr<AllocEngine> engine; |
4421 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4421 ; } } else gtest_label_testnothrow_4421: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4421, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4422 | 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", 4422, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4423 | |
4424 | // Set valid lifetime to 500. |
4425 | uint32_t valid = 500; |
4426 | subnet_->setValid(valid); |
4427 | |
4428 | // Set the threshold to 25%. |
4429 | subnet_->setCacheThreshold(.25); |
4430 | |
4431 | // Set the max age to 50. |
4432 | subnet_->setCacheMaxAge(50); |
4433 | |
4434 | IOAddress addr("192.0.2.105"); |
4435 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4436 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4437 | valid, now, subnet_->getID())); |
4438 | 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", 4438, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4439 | |
4440 | // Create a context for real allocation. |
4441 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4442 | false, false, "", false); |
4443 | |
4444 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4445 | lease = engine->allocateLease4(ctx); |
4446 | // Check that we got that single lease. |
4447 | ASSERT_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", 4447, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4448 | 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" , 4448, gtest_ar.failure_message()) = ::testing::Message(); |
4449 | |
4450 | // The lease was not reused. |
4451 | 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" , 4451, gtest_ar.failure_message()) = ::testing::Message(); |
4452 | |
4453 | // Check the lease was updated in the database. |
4454 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4455 | 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", 4455, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
4456 | |
4457 | detailCompareLease(lease, from_mgr); |
4458 | } |
4459 | |
4460 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
4461 | // when the valid lifetime was reduced. |
4462 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverCacheReducedValid4_Test (AllocEngine4Test_discoverCacheReducedValid4_Test const & ) = delete; void operator=(AllocEngine4Test_discoverCacheReducedValid4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheReducedValid4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheReducedValid4", nullptr, nullptr, ::testing:: internal::CodeLocation("alloc_engine4_unittest.cc", 4462), (:: testing::internal::GetTypeId<AllocEngine4Test>()), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4462), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4462), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheReducedValid4_Test >); void AllocEngine4Test_discoverCacheReducedValid4_Test:: TestBody() { |
4463 | boost::scoped_ptr<AllocEngine> engine; |
4464 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4464 ; } } else gtest_label_testnothrow_4464: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4464, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4465 | 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", 4465, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4466 | |
4467 | // Set valid lifetime to 200. |
4468 | subnet_->setValid(200); |
4469 | |
4470 | // Set the threshold to 25%. |
4471 | subnet_->setCacheThreshold(.25); |
4472 | |
4473 | IOAddress addr("192.0.2.105"); |
4474 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4475 | uint32_t valid = 500; // Used a value greater than subnet_->getValid(). |
4476 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4477 | valid, now, subnet_->getID())); |
4478 | 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", 4478, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4479 | 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" , 4479, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
4480 | |
4481 | // Create a context for fake allocation. |
4482 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4483 | false, false, "", true); |
4484 | |
4485 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4486 | lease = engine->allocateLease4(ctx); |
4487 | // Check that we got that single lease. |
4488 | ASSERT_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", 4488, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4489 | 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" , 4489, gtest_ar.failure_message()) = ::testing::Message(); |
4490 | |
4491 | // The lease was not reused. |
4492 | 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" , 4492, gtest_ar.failure_message()) = ::testing::Message(); |
4493 | } |
4494 | |
4495 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
4496 | // when DDNS parameter changed. |
4497 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestCacheFwdDDNS4_Test (AllocEngine4Test_requestCacheFwdDDNS4_Test const &) = delete ; void operator=(AllocEngine4Test_requestCacheFwdDDNS4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheFwdDDNS4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheFwdDDNS4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4497), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4497), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4497), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheFwdDDNS4_Test >); void AllocEngine4Test_requestCacheFwdDDNS4_Test::TestBody () { |
4498 | boost::scoped_ptr<AllocEngine> engine; |
4499 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4499 ; } } else gtest_label_testnothrow_4499: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4499, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4500 | 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", 4500, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4501 | |
4502 | // Set valid lifetime to 500. |
4503 | uint32_t valid = 500; |
4504 | subnet_->setValid(valid); |
4505 | |
4506 | // Set the max age to 200. |
4507 | subnet_->setCacheMaxAge(200); |
4508 | |
4509 | IOAddress addr("192.0.2.105"); |
4510 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4511 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4512 | valid, now, subnet_->getID())); |
4513 | 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", 4513, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4514 | |
4515 | // Create a context for real allocation with fwd_dns_update changed. |
4516 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4517 | true, false, "", false); |
4518 | |
4519 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4520 | lease = engine->allocateLease4(ctx); |
4521 | // Check that we got that single lease. |
4522 | ASSERT_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", 4522, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4523 | 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" , 4523, gtest_ar.failure_message()) = ::testing::Message(); |
4524 | |
4525 | // The lease was not reused. |
4526 | 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" , 4526, gtest_ar.failure_message()) = ::testing::Message(); |
4527 | |
4528 | // Check the lease was updated in the database. |
4529 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4530 | 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", 4530, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
4531 | |
4532 | detailCompareLease(lease, from_mgr); |
4533 | } |
4534 | |
4535 | // This test checks if a lease can't be reused in DHCPDISCOVER (fake allocation) |
4536 | // when DDNS parameter changed. |
4537 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverCacheRevDDNS4_Test (AllocEngine4Test_discoverCacheRevDDNS4_Test const &) = delete ; void operator=(AllocEngine4Test_discoverCacheRevDDNS4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverCacheRevDDNS4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverCacheRevDDNS4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4537), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4537), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4537), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverCacheRevDDNS4_Test >); void AllocEngine4Test_discoverCacheRevDDNS4_Test::TestBody () { |
4538 | boost::scoped_ptr<AllocEngine> engine; |
4539 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4539 ; } } else gtest_label_testnothrow_4539: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4539, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4540 | 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", 4540, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4541 | |
4542 | // Set valid lifetime to 500. |
4543 | uint32_t valid = 500; |
4544 | subnet_->setValid(valid); |
4545 | |
4546 | // Set the threshold to 25%. |
4547 | subnet_->setCacheThreshold(.25); |
4548 | |
4549 | // Set the max age to 200. |
4550 | subnet_->setCacheMaxAge(200); |
4551 | |
4552 | IOAddress addr("192.0.2.105"); |
4553 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4554 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4555 | valid, now, subnet_->getID())); |
4556 | 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", 4556, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4557 | 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" , 4557, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
4558 | |
4559 | // Create a context for fake allocation with rev_dns_update changed. |
4560 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4561 | false, true, "", true); |
4562 | |
4563 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4564 | lease = engine->allocateLease4(ctx); |
4565 | // Check that we got that single lease. |
4566 | ASSERT_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", 4566, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4567 | 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" , 4567, gtest_ar.failure_message()) = ::testing::Message(); |
4568 | |
4569 | // The lease was not reused. |
4570 | 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" , 4570, gtest_ar.failure_message()) = ::testing::Message(); |
4571 | } |
4572 | |
4573 | // This test checks if a lease can't be reused in DHCPREQUEST (real allocation) |
4574 | // when hostname changed. |
4575 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_requestCacheHostname4_Test (AllocEngine4Test_requestCacheHostname4_Test const &) = delete ; void operator=(AllocEngine4Test_requestCacheHostname4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_requestCacheHostname4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "requestCacheHostname4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4575), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4575), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4575), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_requestCacheHostname4_Test >); void AllocEngine4Test_requestCacheHostname4_Test::TestBody () { |
4576 | boost::scoped_ptr<AllocEngine> engine; |
4577 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4577 ; } } else gtest_label_testnothrow_4577: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4577, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4578 | 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", 4578, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4579 | |
4580 | // Set valid lifetime to 500. |
4581 | uint32_t valid = 500; |
4582 | subnet_->setValid(valid); |
4583 | |
4584 | // Set the max age to 200. |
4585 | subnet_->setCacheMaxAge(200); |
4586 | |
4587 | IOAddress addr("192.0.2.105"); |
4588 | time_t now = time(NULL__null) - 100; // Allocated 100 seconds ago. |
4589 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, |
4590 | valid, now, subnet_->getID(), |
4591 | false, false, "foo")); |
4592 | 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", 4592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
4593 | |
4594 | // Create a context for real allocation with fwd_dns_update changed. |
4595 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, addr, |
4596 | false, false, "bar", false); |
4597 | |
4598 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4599 | lease = engine->allocateLease4(ctx); |
4600 | // Check that we got that single lease. |
4601 | ASSERT_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", 4601, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4602 | 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" , 4602, gtest_ar.failure_message()) = ::testing::Message(); |
4603 | |
4604 | // The lease was not reused. |
4605 | 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" , 4605, gtest_ar.failure_message()) = ::testing::Message(); |
4606 | 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", 4606, gtest_ar .failure_message()) = ::testing::Message(); |
4607 | |
4608 | // Check the lease was updated in the database. |
4609 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); |
4610 | 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", 4610, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
4611 | |
4612 | detailCompareLease(lease, from_mgr); |
4613 | } |
4614 | |
4615 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
4616 | // lifetime value based on the context content. |
4617 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_getValidLft4_Test (AllocEngine4Test_getValidLft4_Test const &) = delete; void operator=(AllocEngine4Test_getValidLft4_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_getValidLft4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "getValidLft4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 4617), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 4617), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 4617 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getValidLft4_Test >); void AllocEngine4Test_getValidLft4_Test::TestBody() { |
4618 | AllocEngine engine(0); |
4619 | |
4620 | // Let's make three classes, two with valid-lifetime and one without, |
4621 | // and add them to the dictionary. |
4622 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
4623 | |
4624 | ClientClassDefPtr class_def(new ClientClassDef("valid_one", ExpressionPtr())); |
4625 | Triplet<uint32_t> valid_one(50, 100, 150); |
4626 | class_def->setValid(valid_one); |
4627 | dictionary->addClass(class_def); |
4628 | |
4629 | class_def.reset(new ClientClassDef("valid_two", ExpressionPtr())); |
4630 | Triplet<uint32_t>valid_two(200, 250, 300); |
4631 | class_def->setValid(valid_two); |
4632 | dictionary->addClass(class_def); |
4633 | |
4634 | class_def.reset(new ClientClassDef("valid_unspec", ExpressionPtr())); |
4635 | dictionary->addClass(class_def); |
4636 | |
4637 | // Commit our class changes. |
4638 | CfgMgr::instance().commit(); |
4639 | |
4640 | // Update the subnet's triplet to something more useful. |
4641 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
4642 | |
4643 | // Describes a test scenario. |
4644 | struct Scenario { |
4645 | std::string desc_; // descriptive text for logging |
4646 | std::vector<std::string> classes_; // class list of assigned classes |
4647 | uint32_t requested_lft_; // use as option 51 is > 0 |
4648 | uint32_t exp_valid_; // expected lifetime |
4649 | }; |
4650 | |
4651 | // Scenarios to test. |
4652 | std::vector<Scenario> scenarios = { |
4653 | { |
4654 | "BOOTP", |
4655 | { "BOOTP" }, |
4656 | 0, |
4657 | Lease::INFINITY_LFT |
4658 | }, |
4659 | { |
4660 | "no classes, no option", |
4661 | {}, |
4662 | 0, |
4663 | subnet_->getValid() |
4664 | }, |
4665 | { |
4666 | "no classes, option", |
4667 | {}, |
4668 | subnet_->getValid().getMin() + 50, |
4669 | subnet_->getValid().getMin() + 50 |
4670 | }, |
4671 | { |
4672 | "no classes, option too small", |
4673 | {}, |
4674 | subnet_->getValid().getMin() - 50, |
4675 | subnet_->getValid().getMin() |
4676 | }, |
4677 | { |
4678 | "no classes, option too big", |
4679 | {}, |
4680 | subnet_->getValid().getMax() + 50, |
4681 | subnet_->getValid().getMax() |
4682 | }, |
4683 | { |
4684 | "class unspecified, no option", |
4685 | { "valid_unspec" }, |
4686 | 0, |
4687 | subnet_->getValid() |
4688 | }, |
4689 | { |
4690 | "from last class, no option", |
4691 | { "valid_unspec", "valid_one" }, |
4692 | 0, |
4693 | valid_one.get() |
4694 | }, |
4695 | { |
4696 | "from first class, no option", |
4697 | { "valid_two", "valid_one" }, |
4698 | 0, |
4699 | valid_two.get() |
4700 | }, |
4701 | { |
4702 | "class plus option", |
4703 | { "valid_one" }, |
4704 | valid_one.getMin() + 25, |
4705 | valid_one.getMin() + 25 |
4706 | }, |
4707 | { |
4708 | "class plus option too small", |
4709 | { "valid_one" }, |
4710 | valid_one.getMin() - 25, |
4711 | valid_one.getMin() |
4712 | }, |
4713 | { |
4714 | "class plus option too big", |
4715 | { "valid_one" }, |
4716 | valid_one.getMax() + 25, |
4717 | valid_one.getMax() |
4718 | } |
4719 | }; |
4720 | |
4721 | // Iterate over the scenarios and verify the correct outcome. |
4722 | for (auto const& scenario : scenarios) { |
4723 | SCOPED_TRACE(scenario.desc_)::testing::ScopedTrace gtest_trace_4723( "alloc_engine4_unittest.cc" , 4723, (scenario.desc_)); { |
4724 | // Create a context; |
4725 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4726 | IOAddress("0.0.0.0"), false, false, |
4727 | "", false); |
4728 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4729 | |
4730 | // Add client classes (if any) |
4731 | for (auto const& class_name : scenario.classes_) { |
4732 | ctx.query_->addClass(class_name); |
4733 | } |
4734 | |
4735 | // Add client option (if one) |
4736 | if (scenario.requested_lft_) { |
4737 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
4738 | scenario.requested_lft_)); |
4739 | ctx.query_->addOption(opt); |
4740 | } |
4741 | |
4742 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4743 | ASSERT_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", 4743, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4744 | 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", 4744, gtest_ar .failure_message()) = ::testing::Message(); |
4745 | } |
4746 | } |
4747 | } |
4748 | |
4749 | // Verifies that AllocEngine::getValidLft(ctx4) returns the appropriate |
4750 | // lifetime value based on the context content. |
4751 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_getTemplateClassValidLft4_Test (AllocEngine4Test_getTemplateClassValidLft4_Test const &) = delete; void operator=(AllocEngine4Test_getTemplateClassValidLft4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_getTemplateClassValidLft4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "getTemplateClassValidLft4", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 4751), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 4751), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 4751), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getTemplateClassValidLft4_Test >); void AllocEngine4Test_getTemplateClassValidLft4_Test:: TestBody() { |
4752 | AllocEngine engine(0); |
4753 | |
4754 | // Let's make three classes, two with valid-lifetime and one without, |
4755 | // and add them to the dictionary. |
4756 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
4757 | ExpressionPtr match_expr; |
4758 | ExpressionParser parser; |
4759 | |
4760 | ElementPtr test_cfg = Element::create("'valid_one_value'"); |
4761 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
4762 | |
4763 | ClientClassDefPtr class_def(new TemplateClientClassDef("valid_one", match_expr)); |
4764 | Triplet<uint32_t> valid_one(50, 100, 150); |
4765 | class_def->setValid(valid_one); |
4766 | dictionary->addClass(class_def); |
4767 | |
4768 | test_cfg = Element::create("'valid_two_value'"); |
4769 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
4770 | |
4771 | class_def.reset(new TemplateClientClassDef("valid_two", match_expr)); |
4772 | Triplet<uint32_t>valid_two(200, 250, 300); |
4773 | class_def->setValid(valid_two); |
4774 | dictionary->addClass(class_def); |
4775 | |
4776 | test_cfg = Element::create("'valid_unspec_value'"); |
4777 | parser.parse(match_expr, test_cfg, AF_INET2, EvalContext::acceptAll, EvalContext::PARSER_STRING); |
4778 | |
4779 | class_def.reset(new TemplateClientClassDef("valid_unspec", match_expr)); |
4780 | dictionary->addClass(class_def); |
4781 | |
4782 | // Commit our class changes. |
4783 | CfgMgr::instance().commit(); |
4784 | |
4785 | // Update the subnet's triplet to something more useful. |
4786 | subnet_->setValid(Triplet<uint32_t>(500, 1000, 1500)); |
4787 | |
4788 | // Describes a test scenario. |
4789 | struct Scenario { |
4790 | std::string desc_; // descriptive text for logging |
4791 | std::vector<std::string> classes_; // class list of assigned classes |
4792 | uint32_t requested_lft_; // use as option 51 is > 0 |
4793 | uint32_t exp_valid_; // expected lifetime |
4794 | }; |
4795 | |
4796 | // Scenarios to test. |
4797 | std::vector<Scenario> scenarios = { |
4798 | { |
4799 | "BOOTP", |
4800 | { "BOOTP" }, |
4801 | 0, |
4802 | Lease::INFINITY_LFT |
4803 | }, |
4804 | { |
4805 | "no classes, no option", |
4806 | {}, |
4807 | 0, |
4808 | subnet_->getValid() |
4809 | }, |
4810 | { |
4811 | "no classes, option", |
4812 | {}, |
4813 | subnet_->getValid().getMin() + 50, |
4814 | subnet_->getValid().getMin() + 50 |
4815 | }, |
4816 | { |
4817 | "no classes, option too small", |
4818 | {}, |
4819 | subnet_->getValid().getMin() - 50, |
4820 | subnet_->getValid().getMin() |
4821 | }, |
4822 | { |
4823 | "no classes, option too big", |
4824 | {}, |
4825 | subnet_->getValid().getMax() + 50, |
4826 | subnet_->getValid().getMax() |
4827 | }, |
4828 | { |
4829 | "class unspecified, no option", |
4830 | { "valid_unspec" }, |
4831 | 0, |
4832 | subnet_->getValid() |
4833 | }, |
4834 | { |
4835 | "from last class, no option", |
4836 | { "valid_unspec", "valid_one" }, |
4837 | 0, |
4838 | valid_one.get() |
4839 | }, |
4840 | { |
4841 | "from first class, no option", |
4842 | { "valid_two", "valid_one" }, |
4843 | 0, |
4844 | valid_two.get() |
4845 | }, |
4846 | { |
4847 | "class plus option", |
4848 | { "valid_one" }, |
4849 | valid_one.getMin() + 25, |
4850 | valid_one.getMin() + 25 |
4851 | }, |
4852 | { |
4853 | "class plus option too small", |
4854 | { "valid_one" }, |
4855 | valid_one.getMin() - 25, |
4856 | valid_one.getMin() |
4857 | }, |
4858 | { |
4859 | "class plus option too big", |
4860 | { "valid_one" }, |
4861 | valid_one.getMax() + 25, |
4862 | valid_one.getMax() |
4863 | } |
4864 | }; |
4865 | |
4866 | // Iterate over the scenarios and verify the correct outcome. |
4867 | for (auto const& scenario : scenarios) { |
4868 | SCOPED_TRACE(scenario.desc_)::testing::ScopedTrace gtest_trace_4868( "alloc_engine4_unittest.cc" , 4868, (scenario.desc_)); { |
4869 | // Create a context; |
4870 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
4871 | IOAddress("0.0.0.0"), false, false, |
4872 | "", false); |
4873 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
4874 | |
4875 | // Add client classes (if any) |
4876 | for (auto const& class_name : scenario.classes_) { |
4877 | if (class_name == "BOOTP") { |
4878 | ctx.query_->addClass(class_name); |
4879 | } else { |
4880 | string subclass(TemplateClientClassDef::SPAWN_CLASS_PREFIX); |
4881 | subclass += class_name; |
4882 | subclass += "_value"; |
4883 | ctx.query_->addSubClass(class_name, subclass); |
4884 | } |
4885 | } |
4886 | |
4887 | // Add client option (if one) |
4888 | if (scenario.requested_lft_) { |
4889 | OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, |
4890 | scenario.requested_lft_)); |
4891 | ctx.query_->addOption(opt); |
4892 | } |
4893 | |
4894 | Lease4Ptr lease = engine.allocateLease4(ctx); |
4895 | ASSERT_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", 4895, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4896 | 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", 4896, gtest_ar .failure_message()) = ::testing::Message(); |
4897 | } |
4898 | } |
4899 | } |
4900 | |
4901 | // This test checks that deleteRelease handles BOOTP leases. |
4902 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_bootpDelete_Test( AllocEngine4Test_bootpDelete_Test const &) = delete; void operator=(AllocEngine4Test_bootpDelete_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_bootpDelete_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "bootpDelete", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 4902), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 4902), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 4902 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_bootpDelete_Test >); void AllocEngine4Test_bootpDelete_Test::TestBody() { |
4903 | boost::scoped_ptr<AllocEngine> engine; |
4904 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4904 ; } } else gtest_label_testnothrow_4904: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4904, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4905 | 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", 4905, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4906 | |
4907 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
4908 | false, true, "somehost.example.com.", false); |
4909 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
4910 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
4911 | |
4912 | // Make the query a BOOTP one. |
4913 | ctx.query_->addClass("BOOTP"); |
4914 | |
4915 | Lease4Ptr lease = engine->allocateLease4(ctx); |
4916 | // The new lease has been allocated, so the old lease should not exist. |
4917 | 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", 4917, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
4918 | |
4919 | // Check that we got a lease |
4920 | ASSERT_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", 4920, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
4921 | |
4922 | // Check that is belongs to the right subnet and client. |
4923 | 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", 4923, gtest_ar .failure_message()) = ::testing::Message(); |
4924 | 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" , 4924, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
4925 | 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" , 4925, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
4926 | 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", 4926 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
4927 | 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" , 4927, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
4928 | 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", 4928, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
4929 | 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" , 4929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
4930 | |
4931 | // Check the valid lifetime is infinite. |
4932 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
4933 | 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", 4933, gtest_ar .failure_message()) = ::testing::Message(); |
4934 | |
4935 | // Check that the lease is indeed in LeaseMgr |
4936 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
4937 | 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", 4937, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
4938 | |
4939 | // Now delete it. |
4940 | bool deleted = false; |
4941 | ASSERT_NO_THROW(deleted = LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { deleted = LeaseMgrFactory::instance().deleteLease(lease); }; } catch ( ...) { goto gtest_label_testnothrow_4941; } } else gtest_label_testnothrow_4941 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 4941, "Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4942 | 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", 4942, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "deleted", "false", "true").c_str()) = ::testing ::Message(); |
4943 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
4944 | 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", 4944, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "from_mgr", "true", "false").c_str()) = ::testing ::Message(); |
4945 | } |
4946 | |
4947 | // This test verifies that all addresses in a pool can be allocated. |
4948 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_fullPool_Test(AllocEngine4Test_fullPool_Test const &) = delete; void operator=(AllocEngine4Test_fullPool_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_fullPool_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fullPool", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 4948), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 4948), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 4948 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullPool_Test >); void AllocEngine4Test_fullPool_Test::TestBody() { |
4949 | boost::scoped_ptr<AllocEngine> engine; |
4950 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_4950 ; } } else gtest_label_testnothrow_4950: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 4950, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
4951 | 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", 4951, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
4952 | |
4953 | // Get rid of the default subnet configuration. |
4954 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
4955 | cfg_mgr.clear(); |
4956 | |
4957 | // Configure a larger subnet with a /24 pool. |
4958 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
4959 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
4960 | subnet_->addPool(pool_); |
4961 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
4962 | |
4963 | // Set exclude-first-last to false. |
4964 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
4965 | cfg_mgr.commit(); |
4966 | |
4967 | size_t cnt = 0; |
4968 | vector<bool> found(256, false); |
4969 | while (true) { |
4970 | vector<uint8_t> duid = clientid_->getClientId(); |
4971 | duid[6] = cnt >> 8; |
4972 | duid[7] = cnt & 0xff; |
4973 | ClientIdPtr clientid(new ClientId(duid)); |
4974 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
4975 | hwaddr->hwaddr_[4] = cnt >> 8; |
4976 | hwaddr->hwaddr_[5] = cnt & 0xff; |
4977 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
4978 | IOAddress("0.0.0.0"), |
4979 | false, false, "foo.bar", false); |
4980 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
4981 | Lease4Ptr lease = engine->allocateLease4(ctx); |
4982 | |
4983 | if (!lease) { |
4984 | break; |
4985 | } |
4986 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
4987 | 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" , 4987, gtest_ar.failure_message()) = ::testing::Message(); |
4988 | 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" , 4988, gtest_ar.failure_message()) = ::testing::Message(); |
4989 | 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" , 4989, gtest_ar.failure_message()) = ::testing::Message(); |
4990 | 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" , 4990, gtest_ar.failure_message()) = ::testing::Message(); |
4991 | 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", 4991, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false").c_str()) = ::testing::Message(); |
4992 | found[addr[3]] = true; |
4993 | ++cnt; |
4994 | // Catch unbound loop. |
4995 | 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", 4995, gtest_ar.failure_message()) = ::testing::Message(); |
4996 | } |
4997 | 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" , 4997, gtest_ar.failure_message()) = ::testing::Message(); |
4998 | 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" , 4998, gtest_ar.failure_message()) = ::testing::Message(); |
4999 | } |
5000 | |
5001 | // This test verifies that all addresses in a subnet can be allocated. |
5002 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_fullSubnet24_Test (AllocEngine4Test_fullSubnet24_Test const &) = delete; void operator=(AllocEngine4Test_fullSubnet24_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_fullSubnet24_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "fullSubnet24", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5002), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5002), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5002 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_fullSubnet24_Test >); void AllocEngine4Test_fullSubnet24_Test::TestBody() { |
5003 | boost::scoped_ptr<AllocEngine> engine; |
5004 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5004 ; } } else gtest_label_testnothrow_5004: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5004, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5005 | 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", 5005, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5006 | |
5007 | // Get rid of the default subnet configuration. |
5008 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5009 | cfg_mgr.clear(); |
5010 | |
5011 | // Configure a larger subnet with a /24 pool. |
5012 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5013 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
5014 | IOAddress("192.0.2.255"))); |
5015 | subnet_->addPool(pool_); |
5016 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5017 | |
5018 | // Set exclude-first-last to false. |
5019 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(false); |
5020 | cfg_mgr.commit(); |
5021 | |
5022 | size_t cnt = 0; |
5023 | vector<bool> found(256, false); |
5024 | while (true) { |
5025 | vector<uint8_t> duid = clientid_->getClientId(); |
5026 | duid[6] = cnt >> 8; |
5027 | duid[7] = cnt & 0xff; |
5028 | ClientIdPtr clientid(new ClientId(duid)); |
5029 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5030 | hwaddr->hwaddr_[4] = cnt >> 8; |
5031 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5032 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5033 | IOAddress("0.0.0.0"), |
5034 | false, false, "foo.bar", false); |
5035 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5036 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5037 | |
5038 | if (!lease) { |
5039 | break; |
5040 | } |
5041 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5042 | 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" , 5042, gtest_ar.failure_message()) = ::testing::Message(); |
5043 | 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" , 5043, gtest_ar.failure_message()) = ::testing::Message(); |
5044 | 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" , 5044, gtest_ar.failure_message()) = ::testing::Message(); |
5045 | 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" , 5045, gtest_ar.failure_message()) = ::testing::Message(); |
5046 | 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", 5046, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false").c_str()) = ::testing::Message(); |
5047 | found[addr[3]] = true; |
5048 | ++cnt; |
5049 | // Catch unbound loop. |
5050 | 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", 5050, gtest_ar.failure_message()) = ::testing::Message(); |
5051 | } |
5052 | 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" , 5052, gtest_ar.failure_message()) = ::testing::Message(); |
5053 | 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" , 5053, gtest_ar.failure_message()) = ::testing::Message(); |
5054 | } |
5055 | |
5056 | // This test verifies that not all addresses in a pool can be allocated when |
5057 | // exclude-first-last is true. |
5058 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_excludeFirstLast_Test (AllocEngine4Test_excludeFirstLast_Test const &) = delete ; void operator=(AllocEngine4Test_excludeFirstLast_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLast_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLast", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 5058), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5058), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5058), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast_Test >); void AllocEngine4Test_excludeFirstLast_Test::TestBody( ) { |
5059 | boost::scoped_ptr<AllocEngine> engine; |
5060 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5060 ; } } else gtest_label_testnothrow_5060: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5060, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5061 | 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", 5061, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5062 | |
5063 | // Get rid of the default subnet configuration. |
5064 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5065 | cfg_mgr.clear(); |
5066 | |
5067 | // Configure a larger subnet with a /24 pool. |
5068 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
5069 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
5070 | subnet_->addPool(pool_); |
5071 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5072 | |
5073 | // Set exclude-first-last to true. |
5074 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5075 | cfg_mgr.commit(); |
5076 | |
5077 | size_t cnt = 0; |
5078 | vector<bool> found(256, false); |
5079 | while (true) { |
5080 | vector<uint8_t> duid = clientid_->getClientId(); |
5081 | duid[6] = cnt >> 8; |
5082 | duid[7] = cnt & 0xff; |
5083 | ClientIdPtr clientid(new ClientId(duid)); |
5084 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5085 | hwaddr->hwaddr_[4] = cnt >> 8; |
5086 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5087 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5088 | IOAddress("0.0.0.0"), |
5089 | false, false, "foo.bar", false); |
5090 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5091 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5092 | |
5093 | if (!lease) { |
5094 | break; |
5095 | } |
5096 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5097 | 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" , 5097, gtest_ar.failure_message()) = ::testing::Message(); |
5098 | 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" , 5098, gtest_ar.failure_message()) = ::testing::Message(); |
5099 | 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" , 5099, gtest_ar.failure_message()) = ::testing::Message(); |
5100 | 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" , 5100, gtest_ar.failure_message()) = ::testing::Message(); |
5101 | 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", 5101, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false").c_str()) = ::testing::Message(); |
5102 | found[addr[3]] = true; |
5103 | ++cnt; |
5104 | // Catch unbound loop. |
5105 | 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", 5105, gtest_ar.failure_message()) = ::testing::Message(); |
5106 | } |
5107 | 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" , 5107, gtest_ar.failure_message()) = ::testing::Message(); |
5108 | vector<bool> expected(256, true); |
5109 | expected[0] = false; |
5110 | expected[255] = false; |
5111 | 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" , 5111, gtest_ar.failure_message()) = ::testing::Message(); |
5112 | } |
5113 | |
5114 | // This test verifies that not all addresses in a subnet can be allocated when |
5115 | // exclude-first-last is true. |
5116 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_excludeFirstLast24_Test (AllocEngine4Test_excludeFirstLast24_Test const &) = delete ; void operator=(AllocEngine4Test_excludeFirstLast24_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLast24_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLast24", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 5116), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5116), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5116), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLast24_Test >); void AllocEngine4Test_excludeFirstLast24_Test::TestBody () { |
5117 | boost::scoped_ptr<AllocEngine> engine; |
5118 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5118 ; } } else gtest_label_testnothrow_5118: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5118, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5119 | 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", 5119, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5120 | |
5121 | // Get rid of the default subnet configuration. |
5122 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5123 | cfg_mgr.clear(); |
5124 | |
5125 | // Configure a larger subnet with a /24 pool. |
5126 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5127 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
5128 | IOAddress("192.0.2.255"))); |
5129 | subnet_->addPool(pool_); |
5130 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5131 | |
5132 | // Set exclude-first-last to true. |
5133 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5134 | cfg_mgr.commit(); |
5135 | |
5136 | size_t cnt = 0; |
5137 | vector<bool> found(256, false); |
5138 | while (true) { |
5139 | vector<uint8_t> duid = clientid_->getClientId(); |
5140 | duid[6] = cnt >> 8; |
5141 | duid[7] = cnt & 0xff; |
5142 | ClientIdPtr clientid(new ClientId(duid)); |
5143 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5144 | hwaddr->hwaddr_[4] = cnt >> 8; |
5145 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5146 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5147 | IOAddress("0.0.0.0"), |
5148 | false, false, "foo.bar", false); |
5149 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5150 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5151 | |
5152 | if (!lease) { |
5153 | break; |
5154 | } |
5155 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5156 | 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" , 5156, gtest_ar.failure_message()) = ::testing::Message(); |
5157 | 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" , 5157, gtest_ar.failure_message()) = ::testing::Message(); |
5158 | 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" , 5158, gtest_ar.failure_message()) = ::testing::Message(); |
5159 | 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" , 5159, gtest_ar.failure_message()) = ::testing::Message(); |
5160 | 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", 5160, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false").c_str()) = ::testing::Message(); |
5161 | found[addr[3]] = true; |
5162 | ++cnt; |
5163 | // Catch unbound loop. |
5164 | 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", 5164, gtest_ar.failure_message()) = ::testing::Message(); |
5165 | } |
5166 | 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" , 5166, gtest_ar.failure_message()) = ::testing::Message(); |
5167 | vector<bool> expected(256, true); |
5168 | expected[0] = false; |
5169 | expected[255] = false; |
5170 | 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" , 5170, gtest_ar.failure_message()) = ::testing::Message(); |
5171 | } |
5172 | |
5173 | // This test verifies that all addresses in a subnet can be allocated when |
5174 | // exclude-first-last is true but the prefix length is greater than 24. |
5175 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_excludeFirst25_Test (AllocEngine4Test_excludeFirst25_Test const &) = delete; void operator=(AllocEngine4Test_excludeFirst25_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_excludeFirst25_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirst25", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5175), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5175), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5175 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirst25_Test >); void AllocEngine4Test_excludeFirst25_Test::TestBody() { |
5176 | boost::scoped_ptr<AllocEngine> engine; |
5177 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5177 ; } } else gtest_label_testnothrow_5177: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5177, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5178 | 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", 5178, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5179 | |
5180 | // Get rid of the default subnet configuration. |
5181 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5182 | cfg_mgr.clear(); |
5183 | |
5184 | // Configure a smaller subnet with a /25 pool. |
5185 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 25, 1, 2, 3, SubnetID(10)); |
5186 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.0"), |
5187 | IOAddress("192.0.2.127"))); |
5188 | subnet_->addPool(pool_); |
5189 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5190 | |
5191 | // Set exclude-first-last to true. |
5192 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5193 | cfg_mgr.commit(); |
5194 | |
5195 | size_t cnt = 0; |
5196 | vector<bool> found(128, false); |
5197 | while (true) { |
5198 | vector<uint8_t> duid = clientid_->getClientId(); |
5199 | duid[6] = cnt >> 8; |
5200 | duid[7] = cnt & 0xff; |
5201 | ClientIdPtr clientid(new ClientId(duid)); |
5202 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5203 | hwaddr->hwaddr_[4] = cnt >> 8; |
5204 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5205 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5206 | IOAddress("0.0.0.0"), |
5207 | false, false, "foo.bar", false); |
5208 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5209 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5210 | |
5211 | if (!lease) { |
5212 | break; |
5213 | } |
5214 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5215 | 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" , 5215, gtest_ar.failure_message()) = ::testing::Message(); |
5216 | 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" , 5216, gtest_ar.failure_message()) = ::testing::Message(); |
5217 | 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" , 5217, gtest_ar.failure_message()) = ::testing::Message(); |
5218 | 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" , 5218, gtest_ar.failure_message()) = ::testing::Message(); |
5219 | 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" , 5219, gtest_ar.failure_message()) = ::testing::Message(); |
5220 | 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", 5220, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3]]" , "true", "false").c_str()) = ::testing::Message(); |
5221 | found[addr[3]] = true; |
5222 | ++cnt; |
5223 | // Catch unbound loop. |
5224 | 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", 5224, gtest_ar.failure_message()) = ::testing::Message(); |
5225 | } |
5226 | 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" , 5226, gtest_ar.failure_message()) = ::testing::Message(); |
5227 | 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" , 5227, gtest_ar.failure_message()) = ::testing::Message(); |
5228 | } |
5229 | |
5230 | // This test verifies that all addresses in a subnet can be allocated when |
5231 | // exclude-first-last is true but the prefix length is greater than 24. |
5232 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_excludeLast25_Test (AllocEngine4Test_excludeLast25_Test const &) = delete; void operator=(AllocEngine4Test_excludeLast25_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_excludeLast25_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeLast25", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5232), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5232), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5232 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeLast25_Test >); void AllocEngine4Test_excludeLast25_Test::TestBody() { |
5233 | boost::scoped_ptr<AllocEngine> engine; |
5234 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5234 ; } } else gtest_label_testnothrow_5234: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5234, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5235 | 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", 5235, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5236 | |
5237 | // Get rid of the default subnet configuration. |
5238 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5239 | cfg_mgr.clear(); |
5240 | |
5241 | // Configure a smaller subnet with a /25 pool. |
5242 | subnet_ = Subnet4::create(IOAddress("192.0.2.128"), 25, 1, 2, 3, SubnetID(10)); |
5243 | pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.128"), |
5244 | IOAddress("192.0.2.255"))); |
5245 | subnet_->addPool(pool_); |
5246 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5247 | |
5248 | // Set exclude-first-last to true. |
5249 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5250 | cfg_mgr.commit(); |
5251 | |
5252 | size_t cnt = 0; |
5253 | vector<bool> found(128, false); |
5254 | while (true) { |
5255 | vector<uint8_t> duid = clientid_->getClientId(); |
5256 | duid[6] = cnt >> 8; |
5257 | duid[7] = cnt & 0xff; |
5258 | ClientIdPtr clientid(new ClientId(duid)); |
5259 | HWAddrPtr hwaddr(new HWAddr(*hwaddr_)); |
5260 | hwaddr->hwaddr_[4] = cnt >> 8; |
5261 | hwaddr->hwaddr_[5] = cnt & 0xff; |
5262 | AllocEngine::ClientContext4 ctx(subnet_, clientid, hwaddr, |
5263 | IOAddress("0.0.0.0"), |
5264 | false, false, "foo.bar", false); |
5265 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234 + cnt)); |
5266 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5267 | |
5268 | if (!lease) { |
5269 | break; |
5270 | } |
5271 | const vector<uint8_t>& addr = lease->addr_.toBytes(); |
5272 | 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" , 5272, gtest_ar.failure_message()) = ::testing::Message(); |
5273 | 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" , 5273, gtest_ar.failure_message()) = ::testing::Message(); |
5274 | 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" , 5274, gtest_ar.failure_message()) = ::testing::Message(); |
5275 | 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" , 5275, gtest_ar.failure_message()) = ::testing::Message(); |
5276 | 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" , 5276, gtest_ar.failure_message()) = ::testing::Message(); |
5277 | 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", 5277, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "found[addr[3] - 128]" , "true", "false").c_str()) = ::testing::Message(); |
5278 | found[addr[3] - 128] = true; |
5279 | ++cnt; |
5280 | // Catch unbound loop. |
5281 | 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", 5281, gtest_ar.failure_message()) = ::testing::Message(); |
5282 | } |
5283 | 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" , 5283, gtest_ar.failure_message()) = ::testing::Message(); |
5284 | 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" , 5284, gtest_ar.failure_message()) = ::testing::Message(); |
5285 | } |
5286 | |
5287 | // This test verifies that an excluded address can be allocated when requested |
5288 | // and exclude-first-last is true. |
5289 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_excludeFirstLastRequested_Test (AllocEngine4Test_excludeFirstLastRequested_Test const &) = delete; void operator=(AllocEngine4Test_excludeFirstLastRequested_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLastRequested_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLastRequested", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 5289), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5289), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5289), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastRequested_Test >); void AllocEngine4Test_excludeFirstLastRequested_Test:: TestBody() { |
5290 | boost::scoped_ptr<AllocEngine> engine; |
5291 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5291 ; } } else gtest_label_testnothrow_5291: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5291, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5292 | 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", 5292, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5293 | |
5294 | // Get rid of the default subnet configuration. |
5295 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5296 | cfg_mgr.clear(); |
5297 | |
5298 | // Configure a larger subnet with a /24 pool. |
5299 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
5300 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
5301 | subnet_->addPool(pool_); |
5302 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5303 | |
5304 | // Set exclude-first-last to true. |
5305 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5306 | cfg_mgr.commit(); |
5307 | |
5308 | // Request the first address. |
5309 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
5310 | IOAddress("10.0.1.0"), |
5311 | false, false, "foo.bar", false); |
5312 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5313 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5314 | ASSERT_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", 5314, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5315 | 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", 5315, gtest_ar .failure_message()) = ::testing::Message(); |
5316 | |
5317 | // Request the last address. |
5318 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
5319 | IOAddress("10.0.1.255"), |
5320 | false, false, "bar.foo", false); |
5321 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
5322 | lease = engine->allocateLease4(ctx2); |
5323 | ASSERT_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", 5323, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5324 | 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", 5324, gtest_ar .failure_message()) = ::testing::Message(); |
5325 | } |
5326 | |
5327 | // This test verifies that an excluded address can be allocated when reserved |
5328 | // and exclude-first-last is true. |
5329 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_excludeFirstLastReserver_Test (AllocEngine4Test_excludeFirstLastReserver_Test const &) = delete; void operator=(AllocEngine4Test_excludeFirstLastReserver_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_excludeFirstLastReserver_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "excludeFirstLastReserver", nullptr, nullptr, ::testing::internal ::CodeLocation("alloc_engine4_unittest.cc", 5329), (::testing ::internal::GetTypeId<AllocEngine4Test>()), ::testing:: internal::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5329), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5329), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_excludeFirstLastReserver_Test >); void AllocEngine4Test_excludeFirstLastReserver_Test::TestBody () { |
5330 | boost::scoped_ptr<AllocEngine> engine; |
5331 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5331 ; } } else gtest_label_testnothrow_5331: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5331, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5332 | 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", 5332, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5333 | |
5334 | // Get rid of the default subnet configuration. |
5335 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5336 | cfg_mgr.clear(); |
5337 | |
5338 | // Configure a larger subnet with a /24 pool. |
5339 | subnet_ = Subnet4::create(IOAddress("10.0.0.0"), 8, 1, 2, 3, SubnetID(10)); |
5340 | pool_ = Pool4Ptr(new Pool4(IOAddress("10.0.1.0"), IOAddress("10.0.1.255"))); |
5341 | subnet_->addPool(pool_); |
5342 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5343 | |
5344 | // Set exclude-first-last to true. |
5345 | cfg_mgr.getStagingCfg()->setExcludeFirstLast24(true); |
5346 | |
5347 | // Add reservations. |
5348 | HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), |
5349 | Host::IDENT_HWADDR, subnet_->getID(), |
5350 | SUBNET_ID_UNUSED, IOAddress("10.0.1.0"))); |
5351 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host); |
5352 | HostPtr host2(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), |
5353 | Host::IDENT_HWADDR, subnet_->getID(), |
5354 | SUBNET_ID_UNUSED, IOAddress("10.0.1.255"))); |
5355 | cfg_mgr.getStagingCfg()->getCfgHosts()->add(host2); |
5356 | subnet_->setReservationsInSubnet(true); |
5357 | subnet_->setReservationsOutOfPool(false); |
5358 | cfg_mgr.commit(); |
5359 | |
5360 | // Request the first address. |
5361 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, |
5362 | IOAddress("0.0.0.0"), |
5363 | false, false, "foo.bar", false); |
5364 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5365 | AllocEngine::findReservation(ctx); |
5366 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5367 | ASSERT_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", 5367, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5368 | 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", 5368, gtest_ar .failure_message()) = ::testing::Message(); |
5369 | |
5370 | // Request the last address. |
5371 | AllocEngine::ClientContext4 ctx2(subnet_, clientid2_, hwaddr2_, |
5372 | IOAddress("0.0.0.0"), |
5373 | false, false, "bar.foo", false); |
5374 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 2345)); |
5375 | AllocEngine::findReservation(ctx2); |
5376 | lease = engine->allocateLease4(ctx2); |
5377 | ASSERT_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", 5377, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5378 | 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", 5378, gtest_ar .failure_message()) = ::testing::Message(); |
5379 | } |
5380 | |
5381 | #ifdef HAVE_MYSQL1 |
5382 | /// @brief Extension of the fixture class to use the MySQL backend. |
5383 | class MySqlAllocEngine4Test : public AllocEngine4Test { |
5384 | public: |
5385 | /// @brief Constructor. |
5386 | MySqlAllocEngine4Test() { |
5387 | // Ensure we have the proper schema with no transient data. |
5388 | db::test::createMySQLSchema(); |
5389 | factory_.create(db::test::validMySQLConnectionString()); |
5390 | } |
5391 | |
5392 | /// @brief Destructor. |
5393 | ~MySqlAllocEngine4Test() { |
5394 | // If data wipe enabled, delete transient data otherwise destroy |
5395 | // the schema. |
5396 | db::test::destroyMySQLSchema(); |
5397 | LeaseMgrFactory::destroy(); |
5398 | } |
5399 | }; |
5400 | |
5401 | // This test checks that simple allocation handles BOOTP queries. |
5402 | TEST_F(MySqlAllocEngine4Test, bootpAlloc4)static_assert(sizeof("MySqlAllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("bootpAlloc4") > 1, "test_name must not be empty" ); class MySqlAllocEngine4Test_bootpAlloc4_Test : public MySqlAllocEngine4Test { public: MySqlAllocEngine4Test_bootpAlloc4_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); MySqlAllocEngine4Test_bootpAlloc4_Test (MySqlAllocEngine4Test_bootpAlloc4_Test const &) = delete ; void operator=(MySqlAllocEngine4Test_bootpAlloc4_Test const &) = delete; }; ::testing::TestInfo* const MySqlAllocEngine4Test_bootpAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MySqlAllocEngine4Test" , "bootpAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5402), (::testing::internal::GetTypeId <MySqlAllocEngine4Test>()), ::testing::internal::SuiteApiResolver < MySqlAllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5402), ::testing::internal::SuiteApiResolver< MySqlAllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5402 ), new ::testing::internal::TestFactoryImpl<MySqlAllocEngine4Test_bootpAlloc4_Test >); void MySqlAllocEngine4Test_bootpAlloc4_Test::TestBody( ) { |
5403 | boost::scoped_ptr<AllocEngine> engine; |
5404 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5404 ; } } else gtest_label_testnothrow_5404: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5404, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5405 | 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", 5405, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5406 | |
5407 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
5408 | false, true, "somehost.example.com.", false); |
5409 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
5410 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5411 | |
5412 | // Make the query a BOOTP one. |
5413 | ctx.query_->addClass("BOOTP"); |
5414 | |
5415 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5416 | // The new lease has been allocated, so the old lease should not exist. |
5417 | 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", 5417, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
5418 | |
5419 | // Check that we got a lease |
5420 | ASSERT_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", 5420, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5421 | |
5422 | // Check that is belongs to the right subnet and client. |
5423 | 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", 5423, gtest_ar .failure_message()) = ::testing::Message(); |
5424 | 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" , 5424, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5425 | 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" , 5425, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5426 | 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", 5426 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5427 | 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" , 5427, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5428 | 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", 5428, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5429 | 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" , 5429, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
5430 | |
5431 | // Check the valid lifetime is infinite. |
5432 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
5433 | 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", 5433, gtest_ar .failure_message()) = ::testing::Message(); |
5434 | |
5435 | // Check that the lease is indeed in LeaseMgr |
5436 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5437 | 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", 5437, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5438 | // The MySQL database does not keep the hwtype for DHCPv4 leases. |
5439 | from_mgr->hwaddr_->htype_ = HTYPE_FDDI; |
5440 | |
5441 | // Now check that the lease in LeaseMgr has the same parameters |
5442 | detailCompareLease(lease, from_mgr); |
5443 | } |
5444 | |
5445 | // This test checks simple renewal handles BOOTP queries. |
5446 | TEST_F(MySqlAllocEngine4Test, bootpRenew4)static_assert(sizeof("MySqlAllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("bootpRenew4") > 1, "test_name must not be empty" ); class MySqlAllocEngine4Test_bootpRenew4_Test : public MySqlAllocEngine4Test { public: MySqlAllocEngine4Test_bootpRenew4_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); MySqlAllocEngine4Test_bootpRenew4_Test (MySqlAllocEngine4Test_bootpRenew4_Test const &) = delete ; void operator=(MySqlAllocEngine4Test_bootpRenew4_Test const &) = delete; }; ::testing::TestInfo* const MySqlAllocEngine4Test_bootpRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MySqlAllocEngine4Test" , "bootpRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5446), (::testing::internal::GetTypeId <MySqlAllocEngine4Test>()), ::testing::internal::SuiteApiResolver < MySqlAllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5446), ::testing::internal::SuiteApiResolver< MySqlAllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5446 ), new ::testing::internal::TestFactoryImpl<MySqlAllocEngine4Test_bootpRenew4_Test >); void MySqlAllocEngine4Test_bootpRenew4_Test::TestBody( ) { |
5447 | boost::scoped_ptr<AllocEngine> engine; |
5448 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5448 ; } } else gtest_label_testnothrow_5448: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5448, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5449 | 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", 5449, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5450 | |
5451 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
5452 | false, true, "somehost.example.com.", false); |
5453 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
5454 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5455 | |
5456 | // Make the query a BOOTP one. |
5457 | ctx.query_->addClass("BOOTP"); |
5458 | |
5459 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5460 | |
5461 | // Check that we got a lease. |
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 | |
5464 | // Check that is belongs to the right subnet and client. |
5465 | 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", 5465, gtest_ar .failure_message()) = ::testing::Message(); |
5466 | 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" , 5466, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5467 | 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" , 5467, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5468 | 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", 5468 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5469 | 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" , 5469, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5470 | 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", 5470, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5471 | 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" , 5471, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
5472 | |
5473 | // Check the valid lifetime is infinite. |
5474 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
5475 | 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", 5475, gtest_ar .failure_message()) = ::testing::Message(); |
5476 | |
5477 | // The new lease has been allocated, so the old lease should not exist. |
5478 | 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", 5478, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
5479 | |
5480 | // Do it again, this should amount to the renew of an existing lease |
5481 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
5482 | |
5483 | // Check that we got a lease. |
5484 | 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", 5484, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
5485 | |
5486 | // Check that is belongs to the right subnet and client. |
5487 | 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", 5487, gtest_ar .failure_message()) = ::testing::Message(); |
5488 | 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" , 5488, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease2->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5489 | 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" , 5489, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5490 | 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", 5490 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5491 | 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" , 5491, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5492 | 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", 5492, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5493 | 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" , 5493, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->hwaddr_ == *hwaddr_", "false", "true").c_str() ) = ::testing::Message(); |
5494 | |
5495 | // Lease already existed, so old_lease should be set. |
5496 | 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", 5496, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
5497 | |
5498 | // Check the renewed valid lifetime has the max value. |
5499 | 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", 5499, gtest_ar .failure_message()) = ::testing::Message(); |
5500 | } |
5501 | |
5502 | // This test checks that deleteRelease handles BOOTP leases. |
5503 | TEST_F(MySqlAllocEngine4Test, bootpDelete)static_assert(sizeof("MySqlAllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("bootpDelete") > 1, "test_name must not be empty" ); class MySqlAllocEngine4Test_bootpDelete_Test : public MySqlAllocEngine4Test { public: MySqlAllocEngine4Test_bootpDelete_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); MySqlAllocEngine4Test_bootpDelete_Test (MySqlAllocEngine4Test_bootpDelete_Test const &) = delete ; void operator=(MySqlAllocEngine4Test_bootpDelete_Test const &) = delete; }; ::testing::TestInfo* const MySqlAllocEngine4Test_bootpDelete_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MySqlAllocEngine4Test" , "bootpDelete", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5503), (::testing::internal::GetTypeId <MySqlAllocEngine4Test>()), ::testing::internal::SuiteApiResolver < MySqlAllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5503), ::testing::internal::SuiteApiResolver< MySqlAllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5503 ), new ::testing::internal::TestFactoryImpl<MySqlAllocEngine4Test_bootpDelete_Test >); void MySqlAllocEngine4Test_bootpDelete_Test::TestBody( ) { |
5504 | boost::scoped_ptr<AllocEngine> engine; |
5505 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5505 ; } } else gtest_label_testnothrow_5505: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5505, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5506 | 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", 5506, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5507 | |
5508 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
5509 | false, true, "somehost.example.com.", false); |
5510 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
5511 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5512 | |
5513 | // Make the query a BOOTP one. |
5514 | ctx.query_->addClass("BOOTP"); |
5515 | |
5516 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5517 | // The new lease has been allocated, so the old lease should not exist. |
5518 | 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", 5518, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
5519 | |
5520 | // Check that we got a lease |
5521 | ASSERT_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", 5521, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5522 | |
5523 | // Check that is belongs to the right subnet and client. |
5524 | 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", 5524, gtest_ar .failure_message()) = ::testing::Message(); |
5525 | 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" , 5525, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5526 | 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" , 5526, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5527 | 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", 5527 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5528 | 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" , 5528, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5529 | 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", 5529, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5530 | 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" , 5530, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
5531 | |
5532 | // Check the valid lifetime is infinite. |
5533 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
5534 | 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", 5534, gtest_ar .failure_message()) = ::testing::Message(); |
5535 | |
5536 | // Check that the lease is indeed in LeaseMgr |
5537 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5538 | 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", 5538, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5539 | |
5540 | // Now delete it. |
5541 | bool deleted = false; |
5542 | ASSERT_NO_THROW(deleted = LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { deleted = LeaseMgrFactory::instance().deleteLease(lease); }; } catch ( ...) { goto gtest_label_testnothrow_5542; } } else gtest_label_testnothrow_5542 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 5542, "Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5543 | 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", 5543, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "deleted", "false", "true").c_str()) = ::testing ::Message(); |
5544 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5545 | 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", 5545, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "from_mgr", "true", "false").c_str()) = ::testing ::Message(); |
5546 | } |
5547 | #endif |
5548 | |
5549 | #ifdef HAVE_PGSQL1 |
5550 | /// @brief Extension of the fixture class to use the PostgreSql backend. |
5551 | class PgSqlAllocEngine4Test : public AllocEngine4Test { |
5552 | public: |
5553 | /// @brief Constructor. |
5554 | PgSqlAllocEngine4Test() { |
5555 | // Ensure we have the proper schema with no transient data. |
5556 | db::test::createPgSQLSchema(); |
5557 | factory_.create(db::test::validPgSQLConnectionString()); |
5558 | } |
5559 | |
5560 | /// @brief Destructor. |
5561 | ~PgSqlAllocEngine4Test() { |
5562 | // If data wipe enabled, delete transient data otherwise destroy |
5563 | // the schema. |
5564 | db::test::destroyPgSQLSchema(); |
5565 | LeaseMgrFactory::destroy(); |
5566 | } |
5567 | }; |
5568 | |
5569 | // This test checks that simple allocation handles BOOTP queries. |
5570 | TEST_F(PgSqlAllocEngine4Test, bootpAlloc4)static_assert(sizeof("PgSqlAllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("bootpAlloc4") > 1, "test_name must not be empty" ); class PgSqlAllocEngine4Test_bootpAlloc4_Test : public PgSqlAllocEngine4Test { public: PgSqlAllocEngine4Test_bootpAlloc4_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); PgSqlAllocEngine4Test_bootpAlloc4_Test (PgSqlAllocEngine4Test_bootpAlloc4_Test const &) = delete ; void operator=(PgSqlAllocEngine4Test_bootpAlloc4_Test const &) = delete; }; ::testing::TestInfo* const PgSqlAllocEngine4Test_bootpAlloc4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "PgSqlAllocEngine4Test" , "bootpAlloc4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5570), (::testing::internal::GetTypeId <PgSqlAllocEngine4Test>()), ::testing::internal::SuiteApiResolver < PgSqlAllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5570), ::testing::internal::SuiteApiResolver< PgSqlAllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5570 ), new ::testing::internal::TestFactoryImpl<PgSqlAllocEngine4Test_bootpAlloc4_Test >); void PgSqlAllocEngine4Test_bootpAlloc4_Test::TestBody( ) { |
5571 | boost::scoped_ptr<AllocEngine> engine; |
5572 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5572 ; } } else gtest_label_testnothrow_5572: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5572, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5573 | 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", 5573, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5574 | |
5575 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
5576 | false, true, "somehost.example.com.", false); |
5577 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
5578 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5579 | |
5580 | // Make the query a BOOTP one. |
5581 | ctx.query_->addClass("BOOTP"); |
5582 | |
5583 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5584 | // The new lease has been allocated, so the old lease should not exist. |
5585 | 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", 5585, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
5586 | |
5587 | // Check that we got a lease |
5588 | ASSERT_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", 5588, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5589 | |
5590 | // Check that is belongs to the right subnet and client. |
5591 | 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", 5591, gtest_ar .failure_message()) = ::testing::Message(); |
5592 | 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" , 5592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5593 | 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" , 5593, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5594 | 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", 5594 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5595 | 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" , 5595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5596 | 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", 5596, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5597 | 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" , 5597, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
5598 | |
5599 | // Check the valid lifetime is infinite. |
5600 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
5601 | 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", 5601, gtest_ar .failure_message()) = ::testing::Message(); |
5602 | |
5603 | // Check that the lease is indeed in LeaseMgr |
5604 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5605 | 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", 5605, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5606 | // The PostgreSql database does not keep the hwtype for DHCPv4 leases. |
5607 | from_mgr->hwaddr_->htype_ = HTYPE_FDDI; |
5608 | |
5609 | // Now check that the lease in LeaseMgr has the same parameters |
5610 | detailCompareLease(lease, from_mgr); |
5611 | } |
5612 | |
5613 | // This test checks simple renewal handles BOOTP queries. |
5614 | TEST_F(PgSqlAllocEngine4Test, bootpRenew4)static_assert(sizeof("PgSqlAllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("bootpRenew4") > 1, "test_name must not be empty" ); class PgSqlAllocEngine4Test_bootpRenew4_Test : public PgSqlAllocEngine4Test { public: PgSqlAllocEngine4Test_bootpRenew4_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); PgSqlAllocEngine4Test_bootpRenew4_Test (PgSqlAllocEngine4Test_bootpRenew4_Test const &) = delete ; void operator=(PgSqlAllocEngine4Test_bootpRenew4_Test const &) = delete; }; ::testing::TestInfo* const PgSqlAllocEngine4Test_bootpRenew4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "PgSqlAllocEngine4Test" , "bootpRenew4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5614), (::testing::internal::GetTypeId <PgSqlAllocEngine4Test>()), ::testing::internal::SuiteApiResolver < PgSqlAllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5614), ::testing::internal::SuiteApiResolver< PgSqlAllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5614 ), new ::testing::internal::TestFactoryImpl<PgSqlAllocEngine4Test_bootpRenew4_Test >); void PgSqlAllocEngine4Test_bootpRenew4_Test::TestBody( ) { |
5615 | boost::scoped_ptr<AllocEngine> engine; |
5616 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5616 ; } } else gtest_label_testnothrow_5616: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5616, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5617 | 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", 5617, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5618 | |
5619 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
5620 | false, true, "somehost.example.com.", false); |
5621 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
5622 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5623 | |
5624 | // Make the query a BOOTP one. |
5625 | ctx.query_->addClass("BOOTP"); |
5626 | |
5627 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5628 | |
5629 | // Check that we got a lease. |
5630 | ASSERT_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", 5630, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5631 | |
5632 | // Check that is belongs to the right subnet and client. |
5633 | 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", 5633, gtest_ar .failure_message()) = ::testing::Message(); |
5634 | 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" , 5634, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5635 | 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" , 5635, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5636 | 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", 5636 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5637 | 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" , 5637, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5638 | 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", 5638, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5639 | 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" , 5639, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
5640 | |
5641 | // Check the valid lifetime is infinite. |
5642 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
5643 | 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", 5643, gtest_ar .failure_message()) = ::testing::Message(); |
5644 | |
5645 | // The new lease has been allocated, so the old lease should not exist. |
5646 | 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", 5646, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
5647 | |
5648 | // Do it again, this should amount to the renew of an existing lease |
5649 | Lease4Ptr lease2 = engine->allocateLease4(ctx); |
5650 | |
5651 | // Check that we got a lease. |
5652 | 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", 5652, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2" , "false", "true").c_str()) = ::testing::Message(); |
5653 | |
5654 | // Check that is belongs to the right subnet and client. |
5655 | 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", 5655, gtest_ar .failure_message()) = ::testing::Message(); |
5656 | 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" , 5656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease2->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5657 | 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" , 5657, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease2->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5658 | 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", 5658 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease2->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5659 | 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" , 5659, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5660 | 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", 5660, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease2->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5661 | 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" , 5661, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease2->hwaddr_ == *hwaddr_", "false", "true").c_str() ) = ::testing::Message(); |
5662 | |
5663 | // Lease already existed, so old_lease should be set. |
5664 | 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", 5664, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
5665 | |
5666 | // Check the renewed valid lifetime has the max value. |
5667 | 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", 5667, gtest_ar .failure_message()) = ::testing::Message(); |
5668 | } |
5669 | |
5670 | // This test checks that deleteRelease handles BOOTP leases. |
5671 | TEST_F(PgSqlAllocEngine4Test, bootpDelete)static_assert(sizeof("PgSqlAllocEngine4Test") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("bootpDelete") > 1, "test_name must not be empty" ); class PgSqlAllocEngine4Test_bootpDelete_Test : public PgSqlAllocEngine4Test { public: PgSqlAllocEngine4Test_bootpDelete_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); PgSqlAllocEngine4Test_bootpDelete_Test (PgSqlAllocEngine4Test_bootpDelete_Test const &) = delete ; void operator=(PgSqlAllocEngine4Test_bootpDelete_Test const &) = delete; }; ::testing::TestInfo* const PgSqlAllocEngine4Test_bootpDelete_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "PgSqlAllocEngine4Test" , "bootpDelete", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5671), (::testing::internal::GetTypeId <PgSqlAllocEngine4Test>()), ::testing::internal::SuiteApiResolver < PgSqlAllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5671), ::testing::internal::SuiteApiResolver< PgSqlAllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5671 ), new ::testing::internal::TestFactoryImpl<PgSqlAllocEngine4Test_bootpDelete_Test >); void PgSqlAllocEngine4Test_bootpDelete_Test::TestBody( ) { |
5672 | boost::scoped_ptr<AllocEngine> engine; |
5673 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5673 ; } } else gtest_label_testnothrow_5673: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5673, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5674 | 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", 5674, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5675 | |
5676 | AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), |
5677 | false, true, "somehost.example.com.", false); |
5678 | subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); |
5679 | ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); |
5680 | |
5681 | // Make the query a BOOTP one. |
5682 | ctx.query_->addClass("BOOTP"); |
5683 | |
5684 | Lease4Ptr lease = engine->allocateLease4(ctx); |
5685 | // The new lease has been allocated, so the old lease should not exist. |
5686 | 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", 5686, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx.old_lease_" , "true", "false").c_str()) = ::testing::Message(); |
5687 | |
5688 | // Check that we got a lease |
5689 | ASSERT_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", 5689, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5690 | |
5691 | // Check that is belongs to the right subnet and client. |
5692 | 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", 5692, gtest_ar .failure_message()) = ::testing::Message(); |
5693 | 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" , 5693, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inRange(lease->addr_)", "false", "true").c_str ()) = ::testing::Message(); |
5694 | 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" , 5694, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet_->inPool(Lease::TYPE_V4, lease->addr_)", "false" , "true").c_str()) = ::testing::Message(); |
5695 | 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", 5695 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->client_id_", "false", "true").c_str()) = ::testing ::Message(); |
5696 | 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" , 5696, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->client_id_ == *clientid_", "false", "true").c_str ()) = ::testing::Message(); |
5697 | 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", 5697, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->hwaddr_" , "false", "true").c_str()) = ::testing::Message(); |
5698 | 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" , 5698, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*lease->hwaddr_ == *hwaddr_", "false", "true").c_str()) = ::testing::Message(); |
5699 | |
5700 | // Check the valid lifetime is infinite. |
5701 | uint32_t infinity_lft = Lease::INFINITY_LFT; |
5702 | 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", 5702, gtest_ar .failure_message()) = ::testing::Message(); |
5703 | |
5704 | // Check that the lease is indeed in LeaseMgr |
5705 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5706 | 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", 5706, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5707 | |
5708 | // Now delete it. |
5709 | bool deleted = false; |
5710 | ASSERT_NO_THROW(deleted = LeaseMgrFactory::instance().deleteLease(lease))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { deleted = LeaseMgrFactory::instance().deleteLease(lease); }; } catch ( ...) { goto gtest_label_testnothrow_5710; } } else gtest_label_testnothrow_5710 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "alloc_engine4_unittest.cc", 5710, "Expected: " "deleted = LeaseMgrFactory::instance().deleteLease(lease)" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5711 | 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", 5711, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "deleted", "false", "true").c_str()) = ::testing ::Message(); |
5712 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5713 | 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", 5713, ::testing::internal::GetBoolAssertionFailureMessage ( gtest_ar_, "from_mgr", "true", "false").c_str()) = ::testing ::Message(); |
5714 | } |
5715 | #endif |
5716 | |
5717 | // Verifies that offer_lft is non-zero, that an offered lease is stored |
5718 | // in the lease database. |
5719 | 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() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverOfferLft_Test (AllocEngine4Test_discoverOfferLft_Test const &) = delete ; void operator=(AllocEngine4Test_discoverOfferLft_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLft_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverOfferLft", nullptr, nullptr, ::testing::internal:: CodeLocation("alloc_engine4_unittest.cc", 5719), (::testing:: internal::GetTypeId<AllocEngine4Test>()), ::testing::internal ::SuiteApiResolver< AllocEngine4Test>::GetSetUpCaseOrSuite ("alloc_engine4_unittest.cc", 5719), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc" , 5719), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_discoverOfferLft_Test >); void AllocEngine4Test_discoverOfferLft_Test::TestBody( ) { |
5720 | boost::scoped_ptr<AllocEngine> engine; |
5721 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5721 ; } } else gtest_label_testnothrow_5721: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5721, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5722 | 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", 5722, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5723 | |
5724 | IOAddress addr("192.0.2.15"); |
5725 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5726 | // Get rid of the default test configuration. |
5727 | cfg_mgr.clear(); |
5728 | |
5729 | // Create configuration similar to other tests, but with a single address pool |
5730 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5731 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
5732 | subnet_->addPool(pool_); |
5733 | |
5734 | // Set subnet's offer-lifetime to a non-zero, positive value. |
5735 | uint32_t offer_lft = (subnet_->getValid() / 3); |
5736 | subnet_->setOfferLft(offer_lft); |
5737 | 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" , 5737, gtest_ar.failure_message()) = ::testing::Message(); |
5738 | |
5739 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5740 | |
5741 | // Ask for any address |
5742 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
5743 | IOAddress("0.0.0.0"), true, true, |
5744 | "one", true); |
5745 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
5746 | |
5747 | // Check that we got that single lease |
5748 | Lease4Ptr lease = engine->allocateLease4(ctx1); |
5749 | ASSERT_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", 5749, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5750 | 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" , 5750, gtest_ar.failure_message()) = ::testing::Message(); |
5751 | 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", 5751, gtest_ar .failure_message()) = ::testing::Message(); |
5752 | 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", 5752, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_fwd_" , "true", "false").c_str()) = ::testing::Message(); |
5753 | 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", 5753, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_rev_" , "true", "false").c_str()) = ::testing::Message(); |
5754 | |
5755 | // Check that the lease has been stored by LeaseMgr. |
5756 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5757 | 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", 5757, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5758 | 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", 5758, gtest_ar .failure_message()) = ::testing::Message(); |
5759 | 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", 5759, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_fwd_" , "true", "false").c_str()) = ::testing::Message(); |
5760 | 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", 5760, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_rev_" , "true", "false").c_str()) = ::testing::Message(); |
5761 | |
5762 | // Try to discover an address for a second client. |
5763 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
5764 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
5765 | |
5766 | // Ask for any address. |
5767 | AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, |
5768 | IOAddress("0.0.0.0"), true, true, |
5769 | "two", true); |
5770 | ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1235)); |
5771 | |
5772 | // Verify that we did not get a lease. |
5773 | lease = engine->allocateLease4(ctx2); |
5774 | 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", 5774, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "true", "false").c_str()) = ::testing::Message(); |
5775 | |
5776 | // Original client now does a DHCPREQUEST. Make sure we get the |
5777 | // previously offered lease with the proper valid lifetime. |
5778 | AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, |
5779 | IOAddress("0.0.0.0"), true, true, |
5780 | "one", false); |
5781 | ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1236)); |
5782 | |
5783 | lease = engine->allocateLease4(ctx3); |
5784 | ASSERT_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", 5784, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5785 | 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" , 5785, gtest_ar.failure_message()) = ::testing::Message(); |
5786 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5787 | 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", 5787, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5788 | 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" , 5788, gtest_ar.failure_message()) = ::testing::Message(); |
5789 | } |
5790 | |
5791 | // Verifies that when offer_lft is non-zero, that an existing lease is |
5792 | // whose remaining life is larger than offer_lft, is offered as is. |
5793 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverOfferLftUseExistingLease4_Test (AllocEngine4Test_discoverOfferLftUseExistingLease4_Test const &) = delete; void operator=(AllocEngine4Test_discoverOfferLftUseExistingLease4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLftUseExistingLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverOfferLftUseExistingLease4", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 5793), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 5793), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 5793), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_discoverOfferLftUseExistingLease4_Test >); void AllocEngine4Test_discoverOfferLftUseExistingLease4_Test ::TestBody() { |
5794 | boost::scoped_ptr<AllocEngine> engine; |
5795 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5795 ; } } else gtest_label_testnothrow_5795: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5795, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5796 | 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", 5796, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5797 | |
5798 | IOAddress addr("192.0.2.15"); |
5799 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5800 | // Get rid of the default test configuration. |
5801 | cfg_mgr.clear(); |
5802 | |
5803 | // Create configuration similar to other tests, but with a single address pool |
5804 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 300, SubnetID(10)); |
5805 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
5806 | subnet_->addPool(pool_); |
5807 | |
5808 | // Set subnet's offer-lifetime to a non-zero, positive value. |
5809 | uint32_t offer_lft = 100; |
5810 | subnet_->setOfferLft(offer_lft); |
5811 | 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" , 5811, gtest_ar.failure_message()) = ::testing::Message(); |
5812 | |
5813 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5814 | |
5815 | time_t now = time(NULL__null) - 5; // Allocated 5 seconds ago |
5816 | Lease4Ptr lease(new Lease4(addr, hwaddr_, clientid_, 300, now, |
5817 | subnet_->getID(), true, true, "somehost")); |
5818 | |
5819 | // Copy the lease, so as it can be compared with the old lease returned |
5820 | // by the allocation engine. |
5821 | Lease4 original_lease(*lease); |
5822 | |
5823 | // Lease was assigned 5 seconds ago, its valid lifetime is 300, its |
5824 | // remaining lifetime is still larger than offer_lft. |
5825 | 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", 5825, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "lease->expired()", "true", "false").c_str()) = ::testing ::Message(); |
5826 | 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" , 5826, gtest_ar.failure_message()) = ::testing::Message(); |
5827 | 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" , 5827, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
5828 | |
5829 | // CASE 1: Asking for any address |
5830 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
5831 | IOAddress("0.0.0.0"), false, false, |
5832 | "", true); |
5833 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
5834 | lease = engine->allocateLease4(ctx1); |
5835 | // Check that we got that single lease |
5836 | ASSERT_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", 5836, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5837 | 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" , 5837, gtest_ar.failure_message()) = ::testing::Message(); |
5838 | 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" , 5838, gtest_ar.failure_message()) = ::testing::Message(); |
5839 | |
5840 | // We are reusing the existing lease, the old instance should be |
5841 | // returned. The returned instance should be the same as the original |
5842 | // lease. |
5843 | 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", 5843, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
5844 | 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" , 5844, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true").c_str ()) = ::testing::Message(); |
5845 | |
5846 | // Check that the lease has not been modified by LeaseMgr. |
5847 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5848 | 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", 5848, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5849 | 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", 5849, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "original_lease == *from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5850 | } |
5851 | |
5852 | // Verifies that when offer_lft is non-zero, that an expired lease can |
5853 | // be reclaimed an offered correctly. |
5854 | 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 () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test (AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test const &) = delete; void operator=(AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test const &) = delete; }; ::testing::TestInfo* const AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "discoverOfferLftReuseExpiredLease4", nullptr, nullptr, ::testing ::internal::CodeLocation("alloc_engine4_unittest.cc", 5854), ( ::testing::internal::GetTypeId<AllocEngine4Test>()), :: testing::internal::SuiteApiResolver< AllocEngine4Test>:: GetSetUpCaseOrSuite("alloc_engine4_unittest.cc", 5854), ::testing ::internal::SuiteApiResolver< AllocEngine4Test>::GetTearDownCaseOrSuite ("alloc_engine4_unittest.cc", 5854), new ::testing::internal:: TestFactoryImpl<AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test >); void AllocEngine4Test_discoverOfferLftReuseExpiredLease4_Test ::TestBody() { |
5855 | boost::scoped_ptr<AllocEngine> engine; |
5856 | ASSERT_NO_THROW(engine.reset(new AllocEngine(0)))switch (0) case 0: default: if (::testing::internal::AlwaysTrue ()) { try { if (::testing::internal::AlwaysTrue()) { engine.reset (new AllocEngine(0)); }; } catch (...) { goto gtest_label_testnothrow_5856 ; } } else gtest_label_testnothrow_5856: return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "alloc_engine4_unittest.cc" , 5856, "Expected: " "engine.reset(new AllocEngine(0))" " doesn't throw an exception.\n" " Actual: it throws.") = ::testing::Message(); |
5857 | 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", 5857, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "engine" , "false", "true").c_str()) = ::testing::Message(); |
5858 | |
5859 | IOAddress addr("192.0.2.15"); |
5860 | CfgMgr& cfg_mgr = CfgMgr::instance(); |
5861 | // Get rid of the default test configuration. |
5862 | cfg_mgr.clear(); |
5863 | |
5864 | // Create configuration similar to other tests, but with a single address pool |
5865 | subnet_ = Subnet4::create(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(10)); |
5866 | pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address |
5867 | subnet_->addPool(pool_); |
5868 | |
5869 | // Set subnet's offer-lifetime to a non-zero, positive value. |
5870 | uint32_t offer_lft = (subnet_->getValid() / 3); |
5871 | subnet_->setOfferLft(offer_lft); |
5872 | 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" , 5872, gtest_ar.failure_message()) = ::testing::Message(); |
5873 | |
5874 | cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); |
5875 | |
5876 | // Just a different hw/client-id for the second client |
5877 | uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe }; |
5878 | HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); |
5879 | uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
5880 | time_t now = time(NULL__null) - 500; // Allocated 500 seconds ago |
5881 | Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), |
5882 | 495, now, subnet_->getID())); |
5883 | // Copy the lease, so as it can be compared with the old lease returned |
5884 | // by the allocation engine. |
5885 | Lease4 original_lease(*lease); |
5886 | |
5887 | // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it |
5888 | // is expired already |
5889 | 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", 5889, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->expired()" , "false", "true").c_str()) = ::testing::Message(); |
5890 | 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" , 5890, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().addLease(lease)", "false", "true" ).c_str()) = ::testing::Message(); |
5891 | |
5892 | // CASE 1: Asking for any address |
5893 | AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, |
5894 | IOAddress("0.0.0.0"), false, false, |
5895 | "", true); |
5896 | ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
5897 | lease = engine->allocateLease4(ctx1); |
5898 | // Check that we got that single lease |
5899 | ASSERT_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", 5899, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5900 | 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" , 5900, gtest_ar.failure_message()) = ::testing::Message(); |
5901 | 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", 5901, gtest_ar .failure_message()) = ::testing::Message(); |
5902 | 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", 5902, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_fwd_" , "true", "false").c_str()) = ::testing::Message(); |
5903 | 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", 5903, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease->fqdn_rev_" , "true", "false").c_str()) = ::testing::Message(); |
5904 | |
5905 | // We are reusing expired lease, the old (expired) instance should be |
5906 | // returned. The returned instance should be the same as the original |
5907 | // lease. |
5908 | 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", 5908, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "ctx1.old_lease_" , "false", "true").c_str()) = ::testing::Message(); |
5909 | 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" , 5909, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "original_lease == *ctx1.old_lease_", "false", "true").c_str ()) = ::testing::Message(); |
5910 | |
5911 | // Check that the lease has been stored by LeaseMgr. |
5912 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5913 | 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", 5913, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5914 | 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", 5914, gtest_ar .failure_message()) = ::testing::Message(); |
5915 | 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", 5915, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_fwd_" , "true", "false").c_str()) = ::testing::Message(); |
5916 | 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", 5916, ::testing ::internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr->fqdn_rev_" , "true", "false").c_str()) = ::testing::Message(); |
5917 | |
5918 | // Client now does a DHCPREQUEST. Make sure we get the |
5919 | // previously offered lease with the proper valid lifetime. |
5920 | AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, |
5921 | IOAddress("0.0.0.0"), true, true, |
5922 | "one", false); |
5923 | ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1235)); |
5924 | |
5925 | lease = engine->allocateLease4(ctx2); |
5926 | ASSERT_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", 5926, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
5927 | 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" , 5927, gtest_ar.failure_message()) = ::testing::Message(); |
5928 | from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
5929 | 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", 5929, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
5930 | 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" , 5930, gtest_ar.failure_message()) = ::testing::Message(); |
5931 | } |
5932 | |
5933 | // Verifies that AllocEngine::getOfferLft(ctx4) returns the appropriate |
5934 | // lifetime value based on the context content. |
5935 | 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() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); AllocEngine4Test_getOfferLft4_Test (AllocEngine4Test_getOfferLft4_Test const &) = delete; void operator=(AllocEngine4Test_getOfferLft4_Test const &) = delete ; }; ::testing::TestInfo* const AllocEngine4Test_getOfferLft4_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "AllocEngine4Test" , "getOfferLft4", nullptr, nullptr, ::testing::internal::CodeLocation ("alloc_engine4_unittest.cc", 5935), (::testing::internal::GetTypeId <AllocEngine4Test>()), ::testing::internal::SuiteApiResolver < AllocEngine4Test>::GetSetUpCaseOrSuite("alloc_engine4_unittest.cc" , 5935), ::testing::internal::SuiteApiResolver< AllocEngine4Test >::GetTearDownCaseOrSuite("alloc_engine4_unittest.cc", 5935 ), new ::testing::internal::TestFactoryImpl<AllocEngine4Test_getOfferLft4_Test >); void AllocEngine4Test_getOfferLft4_Test::TestBody() { |
5936 | AllocEngine engine(0); |
5937 | |
5938 | // Let's make three classes, two with offer-lifetime and one without, |
5939 | // and add them to the dictionary. |
5940 | ClientClassDictionaryPtr dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); |
5941 | |
5942 | ClientClassDefPtr class_def(new ClientClassDef("offer_lft_one", ExpressionPtr())); |
5943 | Optional<uint32_t> offer_lft_one(100); |
5944 | class_def->setOfferLft(offer_lft_one); |
5945 | dictionary->addClass(class_def); |
5946 | |
5947 | class_def.reset(new ClientClassDef("offer_lft_two", ExpressionPtr())); |
5948 | Optional<uint32_t>offer_lft_two(200); |
5949 | class_def->setOfferLft(offer_lft_two); |
5950 | dictionary->addClass(class_def); |
5951 | |
5952 | class_def.reset(new ClientClassDef("offer_lft_zero", ExpressionPtr())); |
5953 | Optional<uint32_t>offer_lft_zero(0); |
5954 | class_def->setOfferLft(offer_lft_zero); |
5955 | dictionary->addClass(class_def); |
5956 | |
5957 | class_def.reset(new ClientClassDef("offer_lft_unspec", ExpressionPtr())); |
5958 | dictionary->addClass(class_def); |
5959 | |
5960 | // Commit our class changes. |
5961 | CfgMgr::instance().commit(); |
5962 | |
5963 | // Update the subnet's triplet to something more useful. |
5964 | subnet_->setOfferLft(Optional<uint32_t>(300)); |
5965 | |
5966 | // Describes a test scenario. |
5967 | struct Scenario { |
5968 | std::string desc_; // descriptive text for logging |
5969 | std::vector<std::string> classes_; // class list of assigned classes |
5970 | uint32_t exp_valid_lft_; // expected lease lifetime |
5971 | bool exp_allocate_; // true if lease should be allocated |
5972 | }; |
5973 | |
5974 | bool exp_allocate = true; |
5975 | |
5976 | // Scenarios to test. |
5977 | std::vector<Scenario> scenarios = { |
5978 | { |
5979 | "BOOTP", |
5980 | { "BOOTP" }, |
5981 | Lease::INFINITY_LFT, |
5982 | !exp_allocate, |
5983 | }, |
5984 | { |
5985 | "no classes", |
5986 | {}, |
5987 | subnet_->getOfferLft(), |
5988 | exp_allocate |
5989 | }, |
5990 | { |
5991 | "class unspecified", |
5992 | { "offer_lft_unspec" }, |
5993 | subnet_->getOfferLft(), |
5994 | exp_allocate |
5995 | }, |
5996 | { |
5997 | "from last class", |
5998 | { "offer_lft_unspec", "offer_lft_one" }, |
5999 | offer_lft_one.get(), |
6000 | exp_allocate |
6001 | }, |
6002 | { |
6003 | "from first class", |
6004 | { "offer_lft_two", "offer_lft_one" }, |
6005 | offer_lft_two.get(), |
6006 | exp_allocate |
6007 | }, |
6008 | { |
6009 | // Using class value of zero should override non-zero set at |
6010 | // subnet level, lease should have actual valid lft |
6011 | "zero from class", |
6012 | { "offer_lft_zero" }, |
6013 | subnet_->getValid(), |
6014 | !exp_allocate |
6015 | } |
6016 | }; |
6017 | |
6018 | // Iterate over the scenarios and verify the correct outcome. |
6019 | for (auto const& scenario : scenarios) { |
6020 | SCOPED_TRACE(scenario.desc_)::testing::ScopedTrace gtest_trace_6020( "alloc_engine4_unittest.cc" , 6020, (scenario.desc_)); { |
6021 | // Create a context; |
6022 | AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, |
6023 | IOAddress("0.0.0.0"), false, false, |
6024 | "", true); |
6025 | ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); |
6026 | |
6027 | // Add client classes (if any) |
6028 | for (auto const& class_name : scenario.classes_) { |
6029 | ctx.query_->addClass(class_name); |
6030 | } |
6031 | |
6032 | Lease4Ptr lease = engine.allocateLease4(ctx); |
6033 | ASSERT_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", 6033, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "lease", "false", "true").c_str()) = ::testing::Message(); |
6034 | 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", 6034, gtest_ar .failure_message()) = ::testing::Message(); |
6035 | |
6036 | Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); |
6037 | if (!scenario.exp_allocate_) { |
6038 | 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", 6038, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "true", "false").c_str()) = ::testing::Message(); |
6039 | } else { |
6040 | 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", 6040, ::testing:: internal::GetBoolAssertionFailureMessage( gtest_ar_, "from_mgr" , "false", "true").c_str()) = ::testing::Message(); |
6041 | 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" , 6041, gtest_ar.failure_message()) = ::testing::Message(); |
6042 | 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" , 6042, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LeaseMgrFactory::instance().deleteLease(from_mgr)", "false" , "true").c_str()) = ::testing::Message(); |
6043 | } |
6044 | } |
6045 | } |
6046 | } |
6047 | |
6048 | } // namespace test |
6049 | } // namespace dhcp |
6050 | } // namespace isc |