Commit 50906735 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[master] Merge branch 'trac3625'

parents 8744ddae 56ade63c
......@@ -33,6 +33,7 @@
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_selector.h>
#include <dhcpsrv/utils.h>
#include <dhcpsrv/utils.h>
#include <hooks/callout_handle.h>
......@@ -1542,7 +1543,7 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) const {
Subnet4Ptr subnet;
CfgSubnets4::Selector selector;
SubnetSelector selector;
selector.ciaddr_ = question->getCiaddr();
selector.giaddr_ = question->getGiaddr();
selector.local_address_ = question->getLocalAddr();
......
......@@ -38,6 +38,7 @@
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_selector.h>
#include <dhcpsrv/utils.h>
#include <exceptions/exceptions.h>
#include <hooks/callout_handle.h>
......@@ -868,42 +869,24 @@ Dhcpv6Srv::sanityCheck(const Pkt6Ptr& pkt, RequirementLevel clientid,
Subnet6Ptr
Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question) {
// Initialize subnet selector with the values used to select the subnet.
SubnetSelector selector;
selector.iface_name_ = question->getIface();
selector.remote_address_ = question->getRemoteAddr();
selector.first_relay_linkaddr_ = IOAddress("::");
selector.client_classes_ = question->classes_;
// Initialize fields specific to relayed messages.
if (!question->relay_info_.empty()) {
selector.first_relay_linkaddr_ = question->relay_info_.back().linkaddr_;
selector.interface_id_ =
question->getAnyRelayOption(D6O_INTERFACE_ID,
Pkt6::RELAY_GET_FIRST);
}
Subnet6Ptr subnet;
if (question->relay_info_.empty()) {
// This is a direct (non-relayed) message
// Try to find a subnet if received packet from a directly connected client
subnet = CfgMgr::instance().getSubnet6(question->getIface(),
question->classes_);
if (!subnet) {
// If no subnet was found, try to find it based on remote address
subnet = CfgMgr::instance().getSubnet6(question->getRemoteAddr(),
question->classes_);
}
} else {
// This is a relayed message
OptionPtr interface_id = question->getAnyRelayOption(D6O_INTERFACE_ID,
Pkt6::RELAY_GET_FIRST);
if (interface_id) {
subnet = CfgMgr::instance().getSubnet6(interface_id,
question->classes_);
}
if (!subnet) {
// If no interface-id was specified (or not configured on server),
// let's try address matching
IOAddress link_addr = question->relay_info_.back().linkaddr_;
Subnet6Ptr subnet = CfgMgr::instance().getCurrentCfg()->
getCfgSubnets6()->selectSubnet(selector);
// if relay filled in link_addr field, then let's use it
if (link_addr != IOAddress("::")) {
subnet = CfgMgr::instance().getSubnet6(link_addr,
question->classes_, true);
}
}
}
// Let's execute all callouts registered for subnet6_receive
if (HooksManager::calloutsPresent(Hooks.hook_index_subnet6_select_)) {
......@@ -919,7 +902,9 @@ Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question) {
// 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());
callout_handle->setArgument("subnet6collection",
CfgMgr::instance().getCurrentCfg()->
getCfgSubnets6()->getAll());
// Call user (and server-side) callouts
HooksManager::callCallouts(Hooks.hook_index_subnet6_select_, *callout_handle);
......
......@@ -344,7 +344,7 @@ public:
// subnet id is invalid (duplicate). Thus, we catch exceptions
// here to append a position in the configuration string.
try {
isc::dhcp::CfgMgr::instance().addSubnet6(sub6ptr);
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(sub6ptr);
} catch (const std::exception& ex) {
isc_throw(DhcpConfigError, ex.what() << " ("
<< subnet->getPosition() << ")");
......@@ -534,12 +534,6 @@ public:
///
/// @param subnets_list pointer to a list of IPv6 subnets
void build(ConstElementPtr subnets_list) {
// @todo: Implement more subtle reconfiguration than toss
// the old one and replace with the new one.
// remove old subnets
isc::dhcp::CfgMgr::instance().deleteSubnets6();
BOOST_FOREACH(ConstElementPtr subnet, subnets_list->listValue()) {
ParserPtr parser(new Subnet6ConfigParser("subnet"));
parser->build(subnet);
......
......@@ -26,6 +26,7 @@
#include <dhcpsrv/addr_utilities.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_selector.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <hooks/hooks_manager.h>
......@@ -247,13 +248,13 @@ public:
getOptionFromSubnet(const IOAddress& subnet_address,
const uint16_t option_code,
const uint16_t expected_options_count = 1) {
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(subnet_address,
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(subnet_address, classify_);
if (!subnet) {
/// @todo replace toText() with the use of operator <<.
ADD_FAILURE() << "A subnet for the specified address "
<< subnet_address.toText()
<< "does not exist in Config Manager";
<< " does not exist in Config Manager";
}
OptionContainerPtr options =
subnet->getCfgOption()->getAll("dhcp6");
......@@ -469,6 +470,8 @@ public:
const uint16_t option_code,
const uint8_t* expected_data,
const size_t expected_data_len) {
CfgMgr::instance().clear();
std::string config = createConfigWithOption(params);
ASSERT_TRUE(executeConfiguration(config, "parse option configuration"));
......@@ -557,8 +560,8 @@ TEST_F(Dhcp6ParserTest, subnetGlobalDefaults) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ(1000, subnet->getT1());
EXPECT_EQ(2000, subnet->getT2());
......@@ -605,7 +608,10 @@ TEST_F(Dhcp6ParserTest, multipleSubnets) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
CfgMgr::instance().commit();
const Subnet6Collection* subnets =
CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
......@@ -660,7 +666,10 @@ TEST_F(Dhcp6ParserTest, multipleSubnetsExplicitIDs) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
CfgMgr::instance().commit();
const Subnet6Collection* subnets =
CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
......@@ -796,7 +805,10 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
CfgMgr::instance().commit();
const Subnet6Collection* subnets =
CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
......@@ -805,7 +817,9 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
subnets = CfgMgr::instance().getSubnets6();
CfgMgr::instance().commit();
subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(3, subnets->size()); // We expect 3 subnets now (4th is removed)
......@@ -820,12 +834,16 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
CfgMgr::instance().commit();
// Do reconfiguration
json = Element::fromJSON(config_second_removed);
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
subnets = CfgMgr::instance().getSubnets6();
CfgMgr::instance().commit();
subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(3, subnets->size()); // We expect 4 subnets
......@@ -863,8 +881,8 @@ TEST_F(Dhcp6ParserTest, subnetLocal) {
// returned value should be 0 (configuration success)
checkResult(status, 0);
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ(1, subnet->getT1());
EXPECT_EQ(2, subnet->getT2());
......@@ -898,8 +916,8 @@ TEST_F(Dhcp6ParserTest, subnetInterface) {
// returned value should be 0 (configuration success)
checkResult(status, 0);
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ(valid_iface_, subnet->getIface());
}
......@@ -931,8 +949,8 @@ TEST_F(Dhcp6ParserTest, subnetInterfaceBogus) {
checkResult(status, 1);
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
EXPECT_FALSE(subnet);
}
......@@ -993,16 +1011,20 @@ TEST_F(Dhcp6ParserTest, subnetInterfaceId) {
// Try to get a subnet based on bogus interface-id option
OptionBuffer tmp(bogus_interface_id.begin(), bogus_interface_id.end());
OptionPtr ifaceid(new Option(Option::V6, D6O_INTERFACE_ID, tmp));
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(ifaceid, classify_);
SubnetSelector selector;
selector.first_relay_linkaddr_ = IOAddress("5000::1");
selector.interface_id_.reset(new Option(Option::V6, D6O_INTERFACE_ID, tmp));
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(selector);
EXPECT_FALSE(subnet);
// Now try to get subnet for valid interface-id value
tmp = OptionBuffer(valid_interface_id.begin(), valid_interface_id.end());
ifaceid.reset(new Option(Option::V6, D6O_INTERFACE_ID, tmp));
subnet = CfgMgr::instance().getSubnet6(ifaceid, classify_);
selector.interface_id_.reset(new Option(Option::V6, D6O_INTERFACE_ID, tmp));
subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(selector);
ASSERT_TRUE(subnet);
EXPECT_TRUE(ifaceid->equals(subnet->getInterfaceId()));
EXPECT_TRUE(selector.interface_id_->equals(subnet->getInterfaceId()));
}
......@@ -1084,7 +1106,8 @@ TEST_F(Dhcp6ParserTest, multiplePools) {
ASSERT_NO_THROW(status = configureDhcp6Server(srv_, json));
checkResult(status, 0);
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
const Subnet6Collection* subnets =
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(2, subnets->size()); // We expect 2 subnets
......@@ -1163,8 +1186,8 @@ TEST_F(Dhcp6ParserTest, poolPrefixLen) {
// returned value must be 1 (configuration parse error)
checkResult(x, 0);
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ(1000, subnet->getT1());
EXPECT_EQ(2000, subnet->getT2());
......@@ -1205,8 +1228,8 @@ TEST_F(Dhcp6ParserTest, pdPoolBasics) {
checkResult(x, 0);
// Test that we can retrieve the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
// Fetch the collection of PD pools. It should have 1 entry.
......@@ -1277,8 +1300,8 @@ TEST_F(Dhcp6ParserTest, pdPoolList) {
checkResult(x, 0);
// Test that we can retrieve the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
// Fetch the collection of NA pools. It should have 1 entry.
......@@ -1333,8 +1356,8 @@ TEST_F(Dhcp6ParserTest, subnetAndPrefixDelegated) {
checkResult(x, 0);
// Test that we can retrieve the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
......@@ -2027,8 +2050,8 @@ TEST_F(Dhcp6ParserTest, optionDataDefaults) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
OptionContainerPtr options = subnet->getCfgOption()->getAll("dhcp6");
ASSERT_EQ(2, options->size());
......@@ -2122,8 +2145,8 @@ TEST_F(Dhcp6ParserTest, optionDataTwoSpaces) {
checkResult(status, 0);
// Options should be now available for the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
// Try to get the option from the space dhcp6.
OptionDescriptor desc1 = subnet->getCfgOption()->get("dhcp6", 38);
......@@ -2278,8 +2301,8 @@ TEST_F(Dhcp6ParserTest, optionDataEncapsulate) {
checkResult(status, 0);
// Get the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
// We should have one option available.
......@@ -2341,8 +2364,8 @@ TEST_F(Dhcp6ParserTest, optionDataInMultipleSubnets) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
Subnet6Ptr subnet1 = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet1 = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet1);
OptionContainerPtr options1 = subnet1->getCfgOption()->getAll("dhcp6");
ASSERT_EQ(1, options1->size());
......@@ -2367,8 +2390,8 @@ TEST_F(Dhcp6ParserTest, optionDataInMultipleSubnets) {
sizeof(subid_expected));
// Test another subnet in the same way.
Subnet6Ptr subnet2 = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:2::4"),
classify_);
Subnet6Ptr subnet2 = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:2::4"), classify_);
ASSERT_TRUE(subnet2);
OptionContainerPtr options2 = subnet2->getCfgOption()->getAll("dhcp6");
ASSERT_EQ(1, options2->size());
......@@ -2402,8 +2425,6 @@ TEST_F(Dhcp6ParserTest, optionDataBoolean) {
ASSERT_TRUE(executeConfiguration(config, "parse configuration with a"
" boolean value"));
CfgMgr::instance().commit();
// The subnet should now hold one option with the code 1000.
OptionDescriptor desc =
getOptionFromSubnet(IOAddress("2001:db8:1::5"), 1000);
......@@ -2538,8 +2559,8 @@ TEST_F(Dhcp6ParserTest, optionDataLowerCase) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
OptionContainerPtr options = subnet->getCfgOption()->getAll("dhcp6");
ASSERT_EQ(1, options->size());
......@@ -2581,8 +2602,8 @@ TEST_F(Dhcp6ParserTest, stdOptionData) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
OptionContainerPtr options = subnet->getCfgOption()->getAll("dhcp6");
ASSERT_EQ(1, options->size());
......@@ -2659,8 +2680,8 @@ TEST_F(Dhcp6ParserTest, vendorOptionsHex) {
checkResult(status, 0);
// Options should be now available for the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
// Try to get the option from the vendor space 4491
......@@ -2721,8 +2742,8 @@ TEST_F(Dhcp6ParserTest, vendorOptionsCsv) {
checkResult(status, 0);
// Options should be now available for the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
// Try to get the option from the vendor space 4491
......@@ -2864,8 +2885,8 @@ TEST_F(Dhcp6ParserTest, DISABLED_stdOptionDataEncapsulate) {
checkResult(status, 0);
// Get the subnet.
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::5"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::5"), classify_);
ASSERT_TRUE(subnet);
// We should have one option available.
......@@ -3151,8 +3172,8 @@ TEST_F(Dhcp6ParserTest, subnetRelayInfo) {
// returned value should be 0 (configuration success)
checkResult(status, 0);
Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(IOAddress("2001:db8:1::1"),
classify_);
Subnet6Ptr subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->
selectSubnet(IOAddress("2001:db8:1::1"), classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ("2001:db8:1::abcd", subnet->getRelayInfo().addr_.toText());
}
......@@ -3191,7 +3212,8 @@ TEST_F(Dhcp6ParserTest, classifySubnets) {
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 0);
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
const Subnet6Collection* subnets =
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
......
......@@ -233,7 +233,8 @@ TEST_F(ConfirmTest, relayedClientNoAddress) {
// Configure the server.
configure(CONFIRM_CONFIGS[1], *client.getServer());
// Make sure we ended-up having expected number of subnets configured.
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
const Subnet6Collection* subnets =
CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
ASSERT_EQ(2, subnets->size());
// Client to send relayed message.
client.useRelay();
......@@ -255,7 +256,7 @@ TEST_F(ConfirmTest, relayedClientNoSubnet) {
ASSERT_NO_FATAL_FAILURE(requestLease(CONFIRM_CONFIGS[1], 2, client));
// Now that the client has a lease, let's remove any subnets to check
// how the server would respond to the Confirm.
ASSERT_NO_THROW(CfgMgr::instance().deleteSubnets6());
ASSERT_NO_THROW(CfgMgr::instance().clear());
// Send Confirm message to the server.
ASSERT_NO_THROW(client.doConfirm());
// Client should have received a status code option and this option should
......
......@@ -182,7 +182,7 @@ TEST_F(CtrlDhcpv6SrvTest, configReload) {
ElementPtr config = Element::fromJSON(config_txt);
// Make sure there are no subnets configured.
CfgMgr::instance().deleteSubnets6();
CfgMgr::instance().clear();
// Now send the command
int rcode = -1;
......@@ -192,11 +192,12 @@ TEST_F(CtrlDhcpv6SrvTest, configReload) {
EXPECT_EQ(0, rcode); // Expect success
// Check that the config was indeed applied.
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
const Subnet6Collection* subnets =
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->getAll();
EXPECT_EQ(3, subnets->size());
// Clean up after the test.
CfgMgr::instance().deleteSubnets6();
CfgMgr::instance().clear();
}
} // End of anonymous namespace
......@@ -128,6 +128,7 @@ Dhcp6SrvD2Test::configureD2(bool enable_d2, const bool exp_result,
void
Dhcp6SrvD2Test::configure(const std::string& config, bool exp_result) {
CfgMgr::instance().clear();
ElementPtr json = Element::fromJSON(config);
ConstElementPtr status;
......
......@@ -53,7 +53,8 @@ Dhcpv6MessageTest::requestLease(const std::string& config,
// Configure the server.
configure(config, *client.getServer());
// Make sure we ended-up having expected number of subnets configured.
const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
const Subnet6Collection* subnets =
CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
ASSERT_EQ(subnets_num, subnets->size());
// Do the actual 4-way exchange.
ASSERT_NO_THROW(client.doSARR());
......@@ -63,8 +64,8 @@ Dhcpv6MessageTest::requestLease(const std::string& config,
// subnets.
ASSERT_EQ(1, client.getLeaseNum());
Lease6 lease_client = client.getLease(0);
ASSERT_TRUE(CfgMgr::instance().getSubnet6(lease_client.addr_,
ClientClasses()));
ASSERT_TRUE(CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->
selectSubnet(lease_client.addr_, ClientClasses()));
// Check that the client's lease matches the information on the server
// side.
Lease6Ptr lease_server = checkLease(lease_client);
......
......@@ -1182,8 +1182,9 @@ TEST_F(Dhcpv6SrvTest, selectSubnetAddr) {
// CASE 1: We have only one subnet defined and we received local traffic.
// The only available subnet used to be picked, but not anymore
CfgMgr::instance().deleteSubnets6();
CfgMgr::instance().addSubnet6(subnet1); // just a single subnet
CfgMgr::instance().clear();
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet1); // just a single subnet
CfgMgr::instance().commit();
Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
pkt->setRemoteAddr(IOAddress("fe80::abcd"));
......@@ -1196,38 +1197,42 @@ TEST_F(Dhcpv6SrvTest, selectSubnetAddr) {
// We should NOT select it.
// Identical steps as in case 1, but repeated for clarity
CfgMgr::instance().deleteSubnets6();
CfgMgr::instance().addSubnet6(subnet1); // just a single subnet
CfgMgr::instance().clear();
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet1); // just a single subnet
CfgMgr::instance().commit();
pkt->setRemoteAddr(IOAddress("2001:db8:abcd::2345"));
Subnet6Ptr selected = srv.selectSubnet(pkt);
EXPECT_FALSE(selected);
// CASE 3: We have three subnets defined and we received local traffic.
// Nothing should be selected.
CfgMgr::instance().deleteSubnets6();
CfgMgr::instance().addSubnet6(subnet1);
CfgMgr::instance().addSubnet6(subnet2);
CfgMgr::instance().addSubnet6(subnet3);
CfgMgr::instance().clear();
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet1);
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet2);
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet3);
CfgMgr::instance().commit();
pkt->setRemoteAddr(IOAddress("fe80::abcd"));
selected = srv.selectSubnet(pkt);
EXPECT_FALSE(selected);
// CASE 4: We have three subnets defined and we received relayed traffic
// that came out of subnet 2. We should select subnet2 then
CfgMgr::instance().deleteSubnets6();
CfgMgr::instance().addSubnet6(subnet1);
CfgMgr::instance().addSubnet6(subnet2);
CfgMgr::instance().addSubnet6(subnet3);
CfgMgr::instance().clear();
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet1);
CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->add(subnet2);