Commit d6de376f authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[2995] Subnet6Collection is now passed as pointer to const object

parent 14018a4e
......@@ -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: <b>in/out</b>
- name: @b subnet6, type: isc::dhcp::Subnet6Ptr, direction: <b>in/out</b>
- name: @b subnet6collection, type: const isc::dhcp::Subnet6Collection&, direction: <b>in</b>
- name: @b subnet6collection, type: const isc::dhcp::Subnet6Collection *, direction: <b>in</b>
- @b Description: this callout is executed when a subnet is being
selected for the incoming packet. All parameters, addresses and
......@@ -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
......@@ -2097,14 +2097,14 @@ public:
// Call the basic calllout to record all passed values
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_subnet6collection_ = NULL;
......@@ -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<string> 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<string> 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.
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) {
// 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)
......@@ -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_);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment