BIND 10 trac2995, updated. df2ee17ce15c5259ec2632ebf536f9f117419c88 [2995] Minor tweaks in lease6_select.
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jun 27 10:49:38 UTC 2013
The branch, trac2995 has been updated
via df2ee17ce15c5259ec2632ebf536f9f117419c88 (commit)
via 2ba18911d1daf85d52fea1e380f9425b7e8c3101 (commit)
from d2846e4ecf8679ec53b2cd16e543b7b2488f2692 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit df2ee17ce15c5259ec2632ebf536f9f117419c88
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Thu Jun 27 12:49:22 2013 +0200
[2995] Minor tweaks in lease6_select.
commit 2ba18911d1daf85d52fea1e380f9425b7e8c3101
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Thu Jun 27 12:39:15 2013 +0200
[2995] lease6_select unit-tests are now working.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcpsrv/tests/alloc_engine_unittest.cc | 141 ++++++++++++++++++++----
1 file changed, 121 insertions(+), 20 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
index 0d24393..cf520c9 100644
--- a/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
+++ b/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
@@ -110,7 +110,7 @@ public:
// @todo: check cltt
}
- ~AllocEngine6Test() {
+ virtual ~AllocEngine6Test() {
factory_.destroy();
// Remove all registered hook points (it must be done even for tests that
@@ -182,7 +182,7 @@ public:
// @todo: check cltt
}
- ~AllocEngine4Test() {
+ virtual ~AllocEngine4Test() {
factory_.destroy();
// Remove all registered hook points (it must be done even for tests that
@@ -1034,22 +1034,21 @@ TEST_F(AllocEngine4Test, renewLease4) {
detailCompareLease(lease, from_mgr);
}
+/// @brief helper class used in Hooks testing in AllocEngine6
+///
+/// It features a couple of callout functions and buffers to store
+/// the data that is accessible via callouts.
class HookAllocEngine6Test : public AllocEngine6Test {
public:
HookAllocEngine6Test() {
resetCalloutBuffers();
-
- // Initialize Hooks Manager
- vector<string> libraries; // no libraries at this time
- HooksManager::getHooksManager().loadLibraries(libraries);
-
- EXPECT_NO_THROW(HooksManager::getCalloutManager()->setLibraryIndex(0));
}
- ~HookAllocEngine6Test() {
+ virtual ~HookAllocEngine6Test() {
}
+ /// @brief clears out buffers, so callouts can store received arguments
void resetCalloutBuffers() {
callback_name_ = string("");
callback_subnet6_.reset();
@@ -1063,6 +1062,7 @@ public:
/// callback that stores received callout name and received values
static int
lease6_select_callout(CalloutHandle& callout_handle) {
+
callback_name_ = string("lease6_select");
callout_handle.getArgument("subnet6", callback_subnet6_);
@@ -1075,26 +1075,38 @@ public:
return (0);
}
- /// callback that picks a different lease
+ /// callback that overrides the lease with different values
static int
lease6_select_different_callout(CalloutHandle& callout_handle) {
+ // Let's call the basic callout, so it can record all parameters
lease6_select_callout(callout_handle);
- callback_name_ = string("lease6_select");
-
+ // Now we need to tweak the least a bit
Lease6Ptr lease;
callout_handle.getArgument("lease6", lease);
-
- callback_addr_updated_ = IOAddress("2001:db8::abcd");
+ callback_addr_updated_ = addr_override_;
lease->addr_ = callback_addr_updated_;
+ lease->t1_ = t1_override_;
+ lease->t2_ = t2_override_;
+ lease->preferred_lft_ = pref_override_;
+ lease->valid_lft_ = valid_override_;
return (0);
}
+ // Values to be used in callout to override lease6 content
+ static const IOAddress addr_override_;
+ static const uint32_t t1_override_;
+ static const uint32_t t2_override_;
+ static const uint32_t pref_override_;
+ static const uint32_t valid_override_;
+
+ // Callback will store original and overridden values here
static IOAddress callback_addr_original_;
static IOAddress callback_addr_updated_;
+ // Buffers (callback will store received values here)
static string callback_name_;
static Subnet6Ptr callback_subnet6_;
static Lease6Ptr callback_lease6_;
@@ -1102,30 +1114,55 @@ public:
static vector<string> callback_argument_names_;
};
+// For some reason intialization within a class makes the linker confused.
+// linker complains about undefined references if they are defined within
+// the class declaration.
+const IOAddress HookAllocEngine6Test::addr_override_("2001:db8::abcd");
+const uint32_t HookAllocEngine6Test::t1_override_ = 6000;
+const uint32_t HookAllocEngine6Test::t2_override_ = 7000;
+const uint32_t HookAllocEngine6Test::pref_override_ = 8000;
+const uint32_t HookAllocEngine6Test::valid_override_ = 9000;
+
IOAddress HookAllocEngine6Test::callback_addr_original_("::");
IOAddress HookAllocEngine6Test::callback_addr_updated_("::");
+
string HookAllocEngine6Test::callback_name_;
Subnet6Ptr HookAllocEngine6Test::callback_subnet6_;
Lease6Ptr HookAllocEngine6Test::callback_lease6_;
bool HookAllocEngine6Test::callback_fake_allocation_;
vector<string> HookAllocEngine6Test::callback_argument_names_;
-
-// This test checks if the simple allocation can succeed
+// This test checks if the lease6_select callout is executed and expected
+// parameters as passed.
TEST_F(HookAllocEngine6Test, lease6_select) {
+
+ // Note: The following order is working as expected:
+ // 1. create AllocEngine (that register hook points)
+ // 2. call loadLibraries()
+ //
+ // This order, however, causes segfault in HooksManager
+ // 1. call loadLibraries()
+ // 2. create AllocEngine (that register hook points)
+
+ // Create allocation engine (hook names are registered in its ctor)
boost::scoped_ptr<AllocEngine> engine;
ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100)));
ASSERT_TRUE(engine);
- // Install pkt6_receive_callout
+ // Initialize Hooks Manager
+ vector<string> libraries; // no libraries at this time
+ HooksManager::getHooksManager().loadLibraries(libraries);
+ // Install pkt6_receive_callout
ASSERT_TRUE(HooksManager::getCalloutManager());
-
+ EXPECT_NO_THROW(HooksManager::getCalloutManager()->setLibraryIndex(0));
EXPECT_NO_THROW(HooksManager::getCalloutManager()->registerCallout("lease6_select",
lease6_select_callout));
+ CalloutHandlePtr callout_handle = HooksManager::getHooksManager().createCalloutHandle();
+
Lease6Ptr lease = engine->allocateAddress6(subnet_, duid_, iaid_, IOAddress("::"),
- false, CalloutHandlePtr());
+ false, callout_handle);
// Check that we got a lease
ASSERT_TRUE(lease);
@@ -1137,7 +1174,7 @@ TEST_F(HookAllocEngine6Test, lease6_select) {
ASSERT_TRUE(from_mgr);
// Check that callouts were indeed called
- EXPECT_EQ(callback_name_, "subnet6_select");
+ EXPECT_EQ(callback_name_, "lease6_select");
// Now check that the lease in LeaseMgr has the same parameters
ASSERT_TRUE(callback_lease6_);
@@ -1147,7 +1184,71 @@ TEST_F(HookAllocEngine6Test, lease6_select) {
EXPECT_EQ(subnet_->toText(), callback_subnet6_->toText());
EXPECT_EQ(callback_fake_allocation_, false);
+
+ // Check if all expected parameters are reported. It's a bit tricky, because
+ // order may be different. If the test starts failing, because someone tweaked
+ // hooks engine, we'll have to implement proper vector matching (ignoring order)
+ vector<string> expected_argument_names;
+ expected_argument_names.push_back("fake_allocation");
+ expected_argument_names.push_back("lease6");
+ expected_argument_names.push_back("subnet6");
+ EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
}
+// This test checks if lease6_select callout is able to override the values
+// in a lease6.
+TEST_F(HookAllocEngine6Test, change_lease6_select) {
+
+ // Make sure that the overridden values are different than the ones from
+ // subnet originally used to create the lease
+ ASSERT_NE(t1_override_, subnet_->getT1());
+ ASSERT_NE(t2_override_, subnet_->getT2());
+ ASSERT_NE(pref_override_, subnet_->getPreferred());
+ ASSERT_NE(valid_override_, subnet_->getValid());
+ ASSERT_FALSE(subnet_->inRange(addr_override_));
+
+ // Create allocation engine (hook names are registered in its ctor)
+ boost::scoped_ptr<AllocEngine> engine;
+ ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100)));
+ ASSERT_TRUE(engine);
+
+ // Initialize Hooks Manager
+ vector<string> libraries; // no libraries at this time
+ HooksManager::getHooksManager().loadLibraries(libraries);
+
+ // Install a callout
+ ASSERT_TRUE(HooksManager::getCalloutManager());
+ EXPECT_NO_THROW(HooksManager::getCalloutManager()->setLibraryIndex(0));
+ EXPECT_NO_THROW(HooksManager::getCalloutManager()->registerCallout("lease6_select",
+ lease6_select_different_callout));
+
+ // Normally, dhcpv6_srv would passed the handle when calling allocateAddress6,
+ // but in tests we need to create it on our own.
+ CalloutHandlePtr callout_handle = HooksManager::getHooksManager().createCalloutHandle();
+
+ // Call allocateAddress6. Callouts should be triggered here.
+ Lease6Ptr lease = engine->allocateAddress6(subnet_, duid_, iaid_, IOAddress("::"),
+ false, callout_handle);
+ // Check that we got a lease
+ ASSERT_TRUE(lease);
+
+ // See if the values overridden by callout are there
+ EXPECT_TRUE(lease->addr_.equals(addr_override_));
+ EXPECT_EQ(lease->t1_, t1_override_);
+ EXPECT_EQ(lease->t2_, t2_override_);
+ EXPECT_EQ(lease->preferred_lft_, pref_override_);
+ EXPECT_EQ(lease->valid_lft_, valid_override_);
+
+ // Now check if the lease is in the database
+ Lease6Ptr from_mgr = LeaseMgrFactory::instance().getLease6(lease->addr_);
+ ASSERT_TRUE(from_mgr);
+
+ // Check if values in the database are overridden
+ EXPECT_TRUE(from_mgr->addr_.equals(addr_override_));
+ EXPECT_EQ(from_mgr->t1_, t1_override_);
+ EXPECT_EQ(from_mgr->t2_, t2_override_);
+ EXPECT_EQ(from_mgr->preferred_lft_, pref_override_);
+ EXPECT_EQ(from_mgr->valid_lft_, valid_override_);
+}
}; // End of anonymous namespace
More information about the bind10-changes
mailing list