From: Tomek Mrugalski Date: Fri, 12 Jul 2013 12:47:51 +0000 (+0200) Subject: [2995] Subnet6Collection is now passed as pointer to const object X-Git-Tag: bind10-1.2.0beta1-release~340^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d6de376f97313ba40fef989e4a437d184fdf70cc;p=thirdparty%2Fkea.git [2995] Subnet6Collection is now passed as pointer to const object --- diff --git a/src/bin/dhcp6/dhcp6_hooks.dox b/src/bin/dhcp6/dhcp6_hooks.dox index cf03e5057a..c9379c643d 100644 --- a/src/bin/dhcp6/dhcp6_hooks.dox +++ b/src/bin/dhcp6/dhcp6_hooks.dox @@ -75,7 +75,7 @@ packet processing. Hook points that are not specific to packet processing - @b Arguments: - name: @b query6, type: isc::dhcp::Pkt6Ptr, direction: in/out - name: @b subnet6, type: isc::dhcp::Subnet6Ptr, direction: in/out - - name: @b subnet6collection, type: const isc::dhcp::Subnet6Collection&, direction: in + - name: @b subnet6collection, type: const isc::dhcp::Subnet6Collection *, direction: in - @b Description: this callout is executed when a subnet is being selected for the incoming packet. All parameters, addresses and diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 4491a85d87..1ea696588a 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -660,6 +660,10 @@ Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question) { // Set new arguments callout_handle->setArgument("query6", question); callout_handle->setArgument("subnet6", subnet); + + // We pass pointer to const collection for performance reasons. + // Otherwise we would get a non-trivial performance penalty each + // time subnet6_select is called. callout_handle->setArgument("subnet6collection", CfgMgr::instance().getSubnets6()); // Call user (and server-side) callouts diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index f9239078ac..7957ed4558 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -2097,14 +2097,14 @@ public: // Call the basic calllout to record all passed values subnet6_select_callout(callout_handle); - Subnet6Collection subnets; + const Subnet6Collection* subnets; Subnet6Ptr subnet; callout_handle.getArgument("subnet6", subnet); callout_handle.getArgument("subnet6collection", subnets); // Let's change to a different subnet - if (subnets.size() > 1) { - subnet = subnets[1]; // Let's pick the other subnet + if (subnets->size() > 1) { + subnet = (*subnets)[1]; // Let's pick the other subnet callout_handle.setArgument("subnet6", subnet); } @@ -2116,7 +2116,7 @@ public: callback_name_ = string(""); callback_pkt6_.reset(); callback_subnet6_.reset(); - callback_subnet6collection_.clear(); + callback_subnet6collection_ = NULL; callback_argument_names_.clear(); } @@ -2135,7 +2135,7 @@ public: static Subnet6Ptr callback_subnet6_; /// A list of all available subnets (received by callout) - static Subnet6Collection callback_subnet6collection_; + static const Subnet6Collection* callback_subnet6collection_; /// A list of all received arguments static vector callback_argument_names_; @@ -2146,7 +2146,7 @@ public: string HooksDhcpv6SrvTest::callback_name_; Pkt6Ptr HooksDhcpv6SrvTest::callback_pkt6_; Subnet6Ptr HooksDhcpv6SrvTest::callback_subnet6_; -Subnet6Collection HooksDhcpv6SrvTest::callback_subnet6collection_; +const Subnet6Collection* HooksDhcpv6SrvTest::callback_subnet6collection_; vector HooksDhcpv6SrvTest::callback_argument_names_; @@ -2452,19 +2452,19 @@ TEST_F(HooksDhcpv6SrvTest, subnet6_select) { // Check that pkt6 argument passing was successful and returned proper value EXPECT_TRUE(callback_pkt6_.get() == sol.get()); - Subnet6Collection exp_subnets = CfgMgr::instance().getSubnets6(); + const Subnet6Collection* exp_subnets = CfgMgr::instance().getSubnets6(); // The server is supposed to pick the first subnet, because of matching // interface. Check that the value is reported properly. ASSERT_TRUE(callback_subnet6_); - EXPECT_EQ(callback_subnet6_.get(), exp_subnets.front().get()); + EXPECT_EQ(callback_subnet6_.get(), exp_subnets->front().get()); // Server is supposed to report two subnets - ASSERT_EQ(exp_subnets.size(), callback_subnet6collection_.size()); + ASSERT_EQ(exp_subnets->size(), callback_subnet6collection_->size()); // Compare that the available subnets are reported as expected - EXPECT_TRUE(exp_subnets[0].get() == callback_subnet6collection_[0].get()); - EXPECT_TRUE(exp_subnets[1].get() == callback_subnet6collection_[1].get()); + EXPECT_TRUE((*exp_subnets)[0].get() == (*callback_subnet6collection_)[0].get()); + EXPECT_TRUE((*exp_subnets)[1].get() == (*callback_subnet6collection_)[1].get()); } // This test checks if callout installed on subnet6_select hook point can pick @@ -2526,13 +2526,13 @@ TEST_F(HooksDhcpv6SrvTest, subnet_select_change) { ASSERT_TRUE(addr_opt); // Get all subnets and use second subnet for verification - Subnet6Collection subnets = CfgMgr::instance().getSubnets6(); - ASSERT_EQ(2, subnets.size()); + const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6(); + ASSERT_EQ(2, subnets->size()); // Advertised address must belong to the second pool (in subnet's range, // in dynamic pool) - EXPECT_TRUE(subnets[1]->inRange(addr_opt->getAddress())); - EXPECT_TRUE(subnets[1]->inPool(addr_opt->getAddress())); + EXPECT_TRUE((*subnets)[1]->inRange(addr_opt->getAddress())); + EXPECT_TRUE((*subnets)[1]->inPool(addr_opt->getAddress())); } diff --git a/src/lib/dhcpsrv/cfgmgr.h b/src/lib/dhcpsrv/cfgmgr.h index cbf3df6b22..28cfc76143 100644 --- a/src/lib/dhcpsrv/cfgmgr.h +++ b/src/lib/dhcpsrv/cfgmgr.h @@ -207,9 +207,9 @@ public: /// This is used in a hook (subnet6_select), where the hook is able /// to choose a different subnet. Server code has to offer a list /// of possible choices (i.e. all subnets). - /// @return const reference to Subnet6 collection - inline const Subnet6Collection& getSubnets6() { - return (subnets6_); + /// @return a pointer to const Subnet6 collection + const Subnet6Collection* getSubnets6() { + return (&subnets6_); }