Commit 3a0d60a5 authored by Francis Dupont's avatar Francis Dupont Committed by Razvan Becheriu

[#1265] Removed the random index for subnets

parent 3067ac68
......@@ -793,7 +793,12 @@ public:
ASSERT_TRUE(subnets);
ASSERT_GE(subnets->size(), subnet_index + 1);
const PoolCollection pools = subnets->at(subnet_index)->getPools(Lease::TYPE_V4);
auto subnet = subnets->begin();
// std::advance is not available for subnets iterators.
for (size_t i = 0; i < subnet_index; ++i) {
subnet = std::next(subnet);
}
const PoolCollection pools = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_GE(pools.size(), pool_index + 1);
pool = pools.at(pool_index);
......@@ -1109,10 +1114,11 @@ TEST_F(Dhcp4ParserTest, multipleSubnets) {
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
// Check subnet-ids of each subnet (it should be monotonously increasing)
EXPECT_EQ(1, subnets->at(0)->getID());
EXPECT_EQ(2, subnets->at(1)->getID());
EXPECT_EQ(3, subnets->at(2)->getID());
EXPECT_EQ(4, subnets->at(3)->getID());
auto subnet = subnets->begin();
EXPECT_EQ(1, (*subnet)->getID());
EXPECT_EQ(2, (*++subnet)->getID());
EXPECT_EQ(3, (*++subnet)->getID());
EXPECT_EQ(4, (*++subnet)->getID());
// Repeat reconfiguration process 10 times and check that the subnet-id
// is set to the same value. Technically, just two iterations would be
......@@ -1167,10 +1173,12 @@ TEST_F(Dhcp4ParserTest, multipleSubnetsExplicitIDs) {
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
// Verify that subnet ids are as expected.
EXPECT_EQ(1024, subnets->at(0)->getID());
EXPECT_EQ(100, subnets->at(1)->getID());
EXPECT_EQ(1, subnets->at(2)->getID());
EXPECT_EQ(34, subnets->at(3)->getID());
// Now the subnet order is the subnet id one.
auto subnet = subnets->begin();
EXPECT_EQ(1, (*subnet)->getID());
EXPECT_EQ(34, (*++subnet)->getID());
EXPECT_EQ(100, (*++subnet)->getID());
EXPECT_EQ(1024, (*++subnet)->getID());
// Repeat reconfiguration process 10 times and check that the subnet-id
// is set to the same value.
......@@ -1312,9 +1320,10 @@ TEST_F(Dhcp4ParserTest, reconfigureRemoveSubnet) {
ASSERT_EQ(3, subnets->size()); // We expect 3 subnets now (4th is removed)
// Check subnet-ids of each subnet (it should be monotonously increasing)
EXPECT_EQ(1, subnets->at(0)->getID());
EXPECT_EQ(2, subnets->at(1)->getID());
EXPECT_EQ(3, subnets->at(2)->getID());
auto subnet = subnets->begin();
EXPECT_EQ(1, (*subnet)->getID());
EXPECT_EQ(2, (*++subnet)->getID());
EXPECT_EQ(3, (*++subnet)->getID());
CfgMgr::instance().clear();
......@@ -1335,11 +1344,11 @@ TEST_F(Dhcp4ParserTest, reconfigureRemoveSubnet) {
ASSERT_TRUE(subnets);
ASSERT_EQ(3, subnets->size()); // We expect 4 subnets
EXPECT_EQ(1, subnets->at(0)->getID());
auto subnet_it = subnets->begin();
EXPECT_EQ(1, (*subnet_it)->getID());
// The second subnet (with subnet-id = 2) is no longer there
EXPECT_EQ(3, subnets->at(1)->getID());
EXPECT_EQ(4, subnets->at(2)->getID());
EXPECT_EQ(3, (*++subnet_it)->getID());
EXPECT_EQ(4, (*++subnet_it)->getID());
}
/// @todo: implement subnet removal test as part of #3281.
......@@ -1869,26 +1878,28 @@ TEST_F(Dhcp4ParserTest, multiplePools) {
ASSERT_EQ(2, subnets->size()); // We expect 2 subnets
// Check the first subnet
const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_V4);
auto subnet = subnets->begin();
const PoolCollection& pools1 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(2, pools1.size());
EXPECT_EQ("type=V4, 192.0.2.0-192.0.2.15",
pools1[0]->toText());
EXPECT_EQ("type=V4, 192.0.2.200-192.0.2.255",
pools1[1]->toText());
// There shouldn't be any TA or PD pools
EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_TA), BadValue);
EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_PD), BadValue);
EXPECT_THROW((*subnet)->getPools(Lease::TYPE_TA), BadValue);
EXPECT_THROW((*subnet)->getPools(Lease::TYPE_PD), BadValue);
// Check the second subnet
const PoolCollection& pools2 = subnets->at(1)->getPools(Lease::TYPE_V4);
++subnet;
const PoolCollection& pools2 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(2, pools2.size());
EXPECT_EQ("type=V4, 192.0.3.0-192.0.3.127",
pools2[0]->toText());
EXPECT_EQ("type=V4, 192.0.3.128-192.0.3.255",
pools2[1]->toText());
// There shouldn't be any TA or PD pools
EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_TA).empty(), BadValue);
EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_PD).empty(), BadValue);
EXPECT_THROW((*subnet)->getPools(Lease::TYPE_TA).empty(), BadValue);
EXPECT_THROW((*subnet)->getPools(Lease::TYPE_PD).empty(), BadValue);
}
// Test verifies that a subnet with pool values that do not belong to that
......@@ -4742,47 +4753,51 @@ TEST_F(Dhcp4ParserTest, classifySubnets) {
// everyone).
ClientClasses classes;
classes.insert("alpha");
EXPECT_TRUE (subnets->at(0)->clientSupported(classes));
EXPECT_FALSE(subnets->at(1)->clientSupported(classes));
EXPECT_FALSE(subnets->at(2)->clientSupported(classes));
EXPECT_TRUE (subnets->at(3)->clientSupported(classes));
auto subnet0 = subnets->begin();
auto subnet1 = std::next(subnet0);
auto subnet2 = std::next(subnet1);
auto subnet3 = std::next(subnet2);
EXPECT_TRUE ((*subnet0)->clientSupported(classes));
EXPECT_FALSE((*subnet1)->clientSupported(classes));
EXPECT_FALSE((*subnet2)->clientSupported(classes));
EXPECT_TRUE ((*subnet3)->clientSupported(classes));
// Let's check if client belonging to beta class is supported in subnet[1]
// and not supported in any other subnet (except subnet[3], which allows
// everyone).
classes.clear();
classes.insert("beta");
EXPECT_FALSE(subnets->at(0)->clientSupported(classes));
EXPECT_TRUE (subnets->at(1)->clientSupported(classes));
EXPECT_FALSE(subnets->at(2)->clientSupported(classes));
EXPECT_TRUE (subnets->at(3)->clientSupported(classes));
EXPECT_FALSE((*subnet0)->clientSupported(classes));
EXPECT_TRUE ((*subnet1)->clientSupported(classes));
EXPECT_FALSE((*subnet2)->clientSupported(classes));
EXPECT_TRUE ((*subnet3)->clientSupported(classes));
// Let's check if client belonging to gamma class is supported in subnet[2]
// and not supported in any other subnet (except subnet[3], which allows
// everyone).
classes.clear();
classes.insert("gamma");
EXPECT_FALSE(subnets->at(0)->clientSupported(classes));
EXPECT_FALSE(subnets->at(1)->clientSupported(classes));
EXPECT_TRUE (subnets->at(2)->clientSupported(classes));
EXPECT_TRUE (subnets->at(3)->clientSupported(classes));
EXPECT_FALSE((*subnet0)->clientSupported(classes));
EXPECT_FALSE((*subnet1)->clientSupported(classes));
EXPECT_TRUE ((*subnet2)->clientSupported(classes));
EXPECT_TRUE ((*subnet3)->clientSupported(classes));
// Let's check if client belonging to some other class (not mentioned in
// the config) is supported only in subnet[3], which allows everyone.
classes.clear();
classes.insert("delta");
EXPECT_FALSE(subnets->at(0)->clientSupported(classes));
EXPECT_FALSE(subnets->at(1)->clientSupported(classes));
EXPECT_FALSE(subnets->at(2)->clientSupported(classes));
EXPECT_TRUE (subnets->at(3)->clientSupported(classes));
EXPECT_FALSE((*subnet0)->clientSupported(classes));
EXPECT_FALSE((*subnet1)->clientSupported(classes));
EXPECT_FALSE((*subnet2)->clientSupported(classes));
EXPECT_TRUE ((*subnet3)->clientSupported(classes));
// Finally, let's check class-less client. He should be allowed only in
// the last subnet, which does not have any class restrictions.
classes.clear();
EXPECT_FALSE(subnets->at(0)->clientSupported(classes));
EXPECT_FALSE(subnets->at(1)->clientSupported(classes));
EXPECT_FALSE(subnets->at(2)->clientSupported(classes));
EXPECT_TRUE (subnets->at(3)->clientSupported(classes));
EXPECT_FALSE((*subnet0)->clientSupported(classes));
EXPECT_FALSE((*subnet1)->clientSupported(classes));
EXPECT_FALSE((*subnet2)->clientSupported(classes));
EXPECT_TRUE ((*subnet3)->clientSupported(classes));
}
// Goal of this test is to verify that multiple pools can be configured
......@@ -4823,7 +4838,7 @@ TEST_F(Dhcp4ParserTest, classifyPools) {
CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getAll();
ASSERT_TRUE(subnets);
ASSERT_EQ(1, subnets->size());
const PoolCollection& pools = subnets->at(0)->getPools(Lease::TYPE_V4);
const PoolCollection& pools = (*subnets->begin())->getPools(Lease::TYPE_V4);
ASSERT_EQ(4, pools.size()); // We expect 4 pools
// Let's check if client belonging to alpha class is supported in pool[0]
......@@ -6602,7 +6617,7 @@ TEST_F(Dhcp4ParserTest, comments) {
const Subnet4Collection* subs = net->getAllSubnets();
ASSERT_TRUE(subs);
ASSERT_EQ(1, subs->size());
Subnet4Ptr sub = subs->at(0);
Subnet4Ptr sub = *subs->begin();
ASSERT_TRUE(sub);
EXPECT_EQ(100, sub->getID());
EXPECT_EQ("192.0.1.0/24", sub->toText());
......
......@@ -106,7 +106,7 @@ Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
ASSERT_EQ(1, subnets->size());
std::stringstream name;
name << "subnet[" << subnets->at(0)->getID() << "].declined-addresses";
name << "subnet[" << (*subnets->begin())->getID() << "].declined-addresses";
// Set the subnet specific statistic explicitly to zero.
isc::stats::StatsMgr::instance().setValue(name.str(), static_cast<int64_t>(0));
......
......@@ -1720,7 +1720,7 @@ TEST_F(Dhcpv4SrvTest, discoverEchoClientId) {
const Subnet4Collection* subnets = cfg->getCfgSubnets4()->getAll();
ASSERT_EQ(1, subnets->size());
CfgMgr::instance().clear();
CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(subnets->at(0));
CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(*subnets->begin());
CfgMgr::instance().getStagingCfg()->setEchoClientId(false);
CfgMgr::instance().commit();
......@@ -1797,7 +1797,7 @@ TEST_F(Dhcpv4SrvTest, requestEchoClientId) {
const Subnet4Collection* subnets = cfg->getCfgSubnets4()->getAll();
ASSERT_EQ(1, subnets->size());
CfgMgr::instance().clear();
CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(subnets->at(0));
CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(*subnets->begin());
CfgMgr::instance().getStagingCfg()->setEchoClientId(false);
CfgMgr::instance().commit();
......@@ -3547,8 +3547,8 @@ TEST_F(Dhcpv4SrvTest, relayOverride) {
ASSERT_EQ(2, subnets->size());
// Let's get them for easy reference
Subnet4Ptr subnet1 = (*subnets)[0];
Subnet4Ptr subnet2 = (*subnets)[1];
Subnet4Ptr subnet1 = *subnets->begin();
Subnet4Ptr subnet2 = *std::next(subnets->begin());
ASSERT_TRUE(subnet1);
ASSERT_TRUE(subnet2);
......@@ -3633,8 +3633,8 @@ TEST_F(Dhcpv4SrvTest, relayOverrideAndClientClass) {
ASSERT_EQ(2, subnets->size());
// Let's get them for easy reference
Subnet4Ptr subnet1 = (*subnets)[0];
Subnet4Ptr subnet2 = (*subnets)[1];
Subnet4Ptr subnet1 = *subnets->begin();
Subnet4Ptr subnet2 = *std::next(subnets->begin());
ASSERT_TRUE(subnet1);
ASSERT_TRUE(subnet2);
......@@ -3695,9 +3695,12 @@ TEST_F(Dhcpv4SrvTest, relayLinkSelect) {
ASSERT_EQ(3, subnets->size());
// Let's get them for easy reference
Subnet4Ptr subnet1 = (*subnets)[0];
Subnet4Ptr subnet2 = (*subnets)[1];
Subnet4Ptr subnet3 = (*subnets)[2];
auto subnet_it = subnets->begin();
Subnet4Ptr subnet1 = *subnet_it;
++subnet_it;
Subnet4Ptr subnet2 = *subnet_it;
++subnet_it;
Subnet4Ptr subnet3 = *subnet_it;
ASSERT_TRUE(subnet1);
ASSERT_TRUE(subnet2);
ASSERT_TRUE(subnet3);
......@@ -3814,9 +3817,12 @@ TEST_F(Dhcpv4SrvTest, subnetSelect) {
ASSERT_EQ(3, subnets->size());
// Let's get them for easy reference
Subnet4Ptr subnet1 = (*subnets)[0];
Subnet4Ptr subnet2 = (*subnets)[1];
Subnet4Ptr subnet3 = (*subnets)[2];
auto subnet_it = subnets->begin();
Subnet4Ptr subnet1 = *subnet_it;
++subnet_it;
Subnet4Ptr subnet2 = *subnet_it;
++subnet_it;
Subnet4Ptr subnet3 = *subnet_it;
ASSERT_TRUE(subnet1);
ASSERT_TRUE(subnet2);
ASSERT_TRUE(subnet3);
......@@ -4154,7 +4160,7 @@ TEST_F(Dhcpv4SrvTest, userContext) {
ASSERT_EQ(1, subnets->size());
// Let's get the subnet and check its context.
Subnet4Ptr subnet1 = (*subnets)[0];
Subnet4Ptr subnet1 = *subnets->begin();
ASSERT_TRUE(subnet1);
ASSERT_TRUE(subnet1->getContext());
EXPECT_EQ("{ \"secure\": false }", subnet1->getContext()->str());
......
......@@ -2877,12 +2877,12 @@ const char* UNPARSED_CONFIGS[] = {
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"calculate-tee-times\": false,\n"
" \"id\": 1024,\n"
" \"id\": 1,\n"
" \"option-data\": [ ],\n"
" \"pools\": [\n"
" {\n"
" \"option-data\": [ ],\n"
" \"pool\": \"192.0.2.1-192.0.2.100\"\n"
" \"pool\": \"192.0.4.101-192.0.4.150\"\n"
" }\n"
" ],\n"
" \"rebind-timer\": 2000,\n"
......@@ -2892,7 +2892,7 @@ const char* UNPARSED_CONFIGS[] = {
" \"renew-timer\": 1000,\n"
" \"reservations\": [ ],\n"
" \"store-extended-info\": false,\n"
" \"subnet\": \"192.0.2.0/24\",\n"
" \"subnet\": \"192.0.4.0/24\",\n"
" \"t1-percent\": 0.5,\n"
" \"t2-percent\": 0.875,\n"
" \"valid-lifetime\": 4000\n"
......@@ -2902,12 +2902,12 @@ const char* UNPARSED_CONFIGS[] = {
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"calculate-tee-times\": false,\n"
" \"id\": 100,\n"
" \"id\": 34,\n"
" \"option-data\": [ ],\n"
" \"pools\": [\n"
" {\n"
" \"option-data\": [ ],\n"
" \"pool\": \"192.0.3.101-192.0.3.150\"\n"
" \"pool\": \"192.0.5.101-192.0.5.150\"\n"
" }\n"
" ],\n"
" \"rebind-timer\": 2000,\n"
......@@ -2917,7 +2917,7 @@ const char* UNPARSED_CONFIGS[] = {
" \"renew-timer\": 1000,\n"
" \"reservations\": [ ],\n"
" \"store-extended-info\": false,\n"
" \"subnet\": \"192.0.3.0/24\",\n"
" \"subnet\": \"192.0.5.0/24\",\n"
" \"t1-percent\": 0.5,\n"
" \"t2-percent\": 0.875,\n"
" \"valid-lifetime\": 4000\n"
......@@ -2927,12 +2927,12 @@ const char* UNPARSED_CONFIGS[] = {
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"calculate-tee-times\": false,\n"
" \"id\": 1,\n"
" \"id\": 100,\n"
" \"option-data\": [ ],\n"
" \"pools\": [\n"
" {\n"
" \"option-data\": [ ],\n"
" \"pool\": \"192.0.4.101-192.0.4.150\"\n"
" \"pool\": \"192.0.3.101-192.0.3.150\"\n"
" }\n"
" ],\n"
" \"rebind-timer\": 2000,\n"
......@@ -2942,7 +2942,7 @@ const char* UNPARSED_CONFIGS[] = {
" \"renew-timer\": 1000,\n"
" \"reservations\": [ ],\n"
" \"store-extended-info\": false,\n"
" \"subnet\": \"192.0.4.0/24\",\n"
" \"subnet\": \"192.0.3.0/24\",\n"
" \"t1-percent\": 0.5,\n"
" \"t2-percent\": 0.875,\n"
" \"valid-lifetime\": 4000\n"
......@@ -2952,12 +2952,12 @@ const char* UNPARSED_CONFIGS[] = {
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"calculate-tee-times\": false,\n"
" \"id\": 34,\n"
" \"id\": 1024,\n"
" \"option-data\": [ ],\n"
" \"pools\": [\n"
" {\n"
" \"option-data\": [ ],\n"
" \"pool\": \"192.0.5.101-192.0.5.150\"\n"
" \"pool\": \"192.0.2.1-192.0.2.100\"\n"
" }\n"
" ],\n"
" \"rebind-timer\": 2000,\n"
......@@ -2967,7 +2967,7 @@ const char* UNPARSED_CONFIGS[] = {
" \"renew-timer\": 1000,\n"
" \"reservations\": [ ],\n"
" \"store-extended-info\": false,\n"
" \"subnet\": \"192.0.5.0/24\",\n"
" \"subnet\": \"192.0.2.0/24\",\n"
" \"t1-percent\": 0.5,\n"
" \"t2-percent\": 0.875,\n"
" \"valid-lifetime\": 4000\n"
......
......@@ -563,7 +563,7 @@ public:
// Let's change to a different subnet
if (subnets->size() > 1) {
subnet = (*subnets)[1]; // Let's pick the other subnet
subnet = *std::next(subnets->begin()); // Let's pick the other subnet
callout_handle.setArgument("subnet4", subnet);
}
......@@ -1617,15 +1617,15 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) {
// The server is supposed to pick the first subnet, because of matching
// interface. Check that the value is reported properly.
ASSERT_TRUE(callback_subnet4_);
EXPECT_EQ(exp_subnets->front().get(), callback_subnet4_.get());
EXPECT_EQ(exp_subnets->begin()->get(), callback_subnet4_.get());
// Server is supposed to report two subnets
ASSERT_EQ(exp_subnets->size(), callback_subnet4collection_->size());
ASSERT_GE(exp_subnets->size(), 2);
// Compare that the available subnets are reported as expected
EXPECT_TRUE((*exp_subnets)[0].get() == (*callback_subnet4collection_)[0].get());
EXPECT_TRUE((*exp_subnets)[1].get() == (*callback_subnet4collection_)[1].get());
EXPECT_TRUE((*exp_subnets->begin())->get() == (*callback_subnet4collection_->begin())->get());
EXPECT_TRUE((*std::next(exp_subnets->begin()))->get() == (*std::next(callback_subnet4collection_->begin()))->get());
// Pkt passed to a callout must be configured to copy retrieved options.
EXPECT_TRUE(callback_qry_options_copy_);
......@@ -1698,8 +1698,10 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) {
// Advertised address must belong to the second pool (in subnet's range,
// in dynamic pool)
EXPECT_TRUE((*subnets)[1]->inRange(addr));
EXPECT_TRUE((*subnets)[1]->inPool(Lease::TYPE_V4, addr));
auto subnet = subnets->begin();
++subnet;
EXPECT_TRUE((*subnet)->inRange(addr));
EXPECT_TRUE((*subnet)->inPool(Lease::TYPE_V4, addr));
// Check if the callout handle state was reset after the callout.
checkCalloutHandleReset(sol);
......
......@@ -431,35 +431,37 @@ TEST_F(JSONFileBackendTest, jsonFile) {
ASSERT_TRUE(subnets);
ASSERT_EQ(3, subnets->size()); // We expect 3 subnets.
// Check subnet 1.
EXPECT_EQ("192.0.2.0", subnets->at(0)->get().first.toText());
EXPECT_EQ(24, subnets->at(0)->get().second);
auto subnet = subnets->begin();
EXPECT_EQ("192.0.2.0", (*subnet)->get().first.toText());
EXPECT_EQ(24, (*subnet)->get().second);
// Check pools in the first subnet.
const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_V4);
const PoolCollection& pools1 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(1, pools1.size());
EXPECT_EQ("192.0.2.1", pools1.at(0)->getFirstAddress().toText());
EXPECT_EQ("192.0.2.100", pools1.at(0)->getLastAddress().toText());
EXPECT_EQ(Lease::TYPE_V4, pools1.at(0)->getType());
// Check subnet 2.
EXPECT_EQ("192.0.3.0", subnets->at(1)->get().first.toText());
EXPECT_EQ(24, subnets->at(1)->get().second);
++subnet;
EXPECT_EQ("192.0.3.0", (*subnet)->get().first.toText());
EXPECT_EQ(24, (*subnet)->get().second);
// Check pools in the second subnet.
const PoolCollection& pools2 = subnets->at(1)->getPools(Lease::TYPE_V4);
const PoolCollection& pools2 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(1, pools2.size());
EXPECT_EQ("192.0.3.101", pools2.at(0)->getFirstAddress().toText());
EXPECT_EQ("192.0.3.150", pools2.at(0)->getLastAddress().toText());
EXPECT_EQ(Lease::TYPE_V4, pools2.at(0)->getType());
// And finally check subnet 3.
EXPECT_EQ("192.0.4.0", subnets->at(2)->get().first.toText());
EXPECT_EQ(24, subnets->at(2)->get().second);
++subnet;
EXPECT_EQ("192.0.4.0", (*subnet)->get().first.toText());
EXPECT_EQ(24, (*subnet)->get().second);
// ... and it's only pool.
const PoolCollection& pools3 = subnets->at(2)->getPools(Lease::TYPE_V4);
const PoolCollection& pools3 = (*subnet)->getPools(Lease::TYPE_V4);
EXPECT_EQ("192.0.4.101", pools3.at(0)->getFirstAddress().toText());
EXPECT_EQ("192.0.4.150", pools3.at(0)->getLastAddress().toText());
EXPECT_EQ(Lease::TYPE_V4, pools3.at(0)->getType());
......@@ -503,11 +505,12 @@ TEST_F(JSONFileBackendTest, hashComments) {
ASSERT_EQ(1, subnets->size());
// Check subnet 1.
EXPECT_EQ("192.0.2.0", subnets->at(0)->get().first.toText());
EXPECT_EQ(22, subnets->at(0)->get().second);
auto subnet = subnets->begin();
EXPECT_EQ("192.0.2.0", (*subnet)->get().first.toText());
EXPECT_EQ(22, (*subnet)->get().second);
// Check pools in the first subnet.
const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_V4);
const PoolCollection& pools1 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(1, pools1.size());
EXPECT_EQ("192.0.2.0", pools1.at(0)->getFirstAddress().toText());
EXPECT_EQ("192.0.2.255", pools1.at(0)->getLastAddress().toText());
......@@ -552,11 +555,12 @@ TEST_F(JSONFileBackendTest, cppLineComments) {
ASSERT_EQ(1, subnets->size());
// Check subnet 1.
EXPECT_EQ("192.0.2.0", subnets->at(0)->get().first.toText());
EXPECT_EQ(22, subnets->at(0)->get().second);
auto subnet = subnets->begin();
EXPECT_EQ("192.0.2.0", (*subnet)->get().first.toText());
EXPECT_EQ(22, (*subnet)->get().second);
// Check pools in the first subnet.
const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_V4);
const PoolCollection& pools1 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(1, pools1.size());
EXPECT_EQ("192.0.2.0", pools1.at(0)->getFirstAddress().toText());
EXPECT_EQ("192.0.2.255", pools1.at(0)->getLastAddress().toText());
......@@ -601,11 +605,12 @@ TEST_F(JSONFileBackendTest, cBlockComments) {
ASSERT_EQ(1, subnets->size());
// Check subnet 1.
EXPECT_EQ("192.0.2.0", subnets->at(0)->get().first.toText());
EXPECT_EQ(22, subnets->at(0)->get().second);
auto subnet = subnets->begin();
EXPECT_EQ("192.0.2.0", (*subnet)->get().first.toText());
EXPECT_EQ(22, (*subnet)->get().second);
// Check pools in the first subnet.
const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_V4);
const PoolCollection& pools1 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(1, pools1.size());
EXPECT_EQ("192.0.2.0", pools1.at(0)->getFirstAddress().toText());
EXPECT_EQ("192.0.2.255", pools1.at(0)->getLastAddress().toText());
......@@ -650,11 +655,12 @@ TEST_F(JSONFileBackendTest, include) {
ASSERT_EQ(1, subnets->size());
// Check subnet 1.
EXPECT_EQ("192.0.2.0", subnets->at(0)->get().first.toText());
EXPECT_EQ(22, subnets->at(0)->get().second);
auto subnet = subnets->begin();
EXPECT_EQ("192.0.2.0", (*subnet)->get().first.toText());
EXPECT_EQ(22, (*subnet)->get().second);
// Check pools in the first subnet.
const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_V4);
const PoolCollection& pools1 = (*subnet)->getPools(Lease::TYPE_V4);
ASSERT_EQ(1, pools1.size());
EXPECT_EQ("192.0.2.0", pools1.at(0)->getFirstAddress().toText());
EXPECT_EQ("192.0.2.255", pools1.at(0)->getLastAddress().toText());
......
......@@ -141,7 +141,7 @@ ReleaseTest::acquireAndRelease(const std::string& hw_address_1,
const Subnet4Collection* subnets =
CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
ASSERT_EQ(1, subnets->size());
name << "subnet[" << subnets->at(0)->getID() << "].assigned-addresses";
name << "subnet[" << (*subnets->begin())->getID() << "].assigned-addresses";
ObservationPtr assigned_cnt = StatsMgr::instance().getObservation(name.str());
ASSERT_TRUE(assigned_cnt);
......
......@@ -1286,8 +1286,8 @@ TEST_F(ClassifyTest, relayOverrideAndClientClass) {
ASSERT_EQ(2, subnets->size());
// Let's get them for easy reference
Subnet6Ptr subnet1 = (*subnets)[0];
Subnet6Ptr subnet2 = (*subnets)[1];
Subnet6Ptr subnet1 = *subnets->begin();
Subnet6Ptr subnet2 = *std::next(subnets->begin());
ASSERT_TRUE(subnet1);
ASSERT_TRUE(subnet2);
......
......@@ -961,7 +961,12 @@ public:
ASSERT_TRUE(subnets);
ASSERT_GE(subnets->size(), subnet_index + 1);
const PoolCollection pools = subnets->at(subnet_index)->getPools(type);
auto subnet = subnets->begin();
// std::advance is not available for subnets iterators.
for (size_t i = 0; i < subnet_index; ++i) {
subnet = std::next(subnet);
}
const PoolCollection pools = (*subnet)->getPools(type);
ASSERT_GE(pools.size(), pool_index + 1);
pool = pools.at(pool_index);
......@@ -1297,10 +1302,11 @@ TEST_F(Dhcp6ParserTest, multipleSubnets) {
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
// Check subnet-ids of each subnet (it should be monotonously increasing)
EXPECT_EQ(1, subnets->at(0)->getID());
EXPECT_EQ(2, subnets->at(1)->getID());
EXPECT_EQ(3, subnets->at(2)->getID());
EXPECT_EQ(4, subnets->at(3)->getID());
auto subnet = subnets->begin();
EXPECT_EQ(1, (*subnet)->getID());
EXPECT_EQ(2, (*++subnet)->getID());
EXPECT_EQ(3, (*++subnet)->getID());
EXPECT_EQ(4, (*++subnet)->getID());
// Repeat reconfiguration process 10 times and check that the subnet-id
// is set to the same value. Technically, just two iterations would be
......@@ -1357,10 +1363,12 @@ TEST_F(Dhcp6ParserTest, multipleSubnetsExplicitIDs) {
ASSERT_EQ(4, subnets->size()); // We expect 4 subnets
// Check that subnet ids are as expected.
EXPECT_EQ(1024, subnets->at(0)->getID());
EXPECT_EQ(100, subnets->at(1)->getID());
EXPECT_EQ(1, subnets->at(2)->getID());
EXPECT_EQ(34, subnets->at(3)->getID());
// Now the subnet order is the subnet id one.
auto subnet = subnets->begin();
EXPECT_EQ(1, (*subnet)->getID());
EXPECT_EQ(34, (*++subnet)->getID());
EXPECT_EQ(100, (*++subnet)->getID());
EXPECT_EQ(1024, (*++subnet)->getID());
// Repeat reconfiguration process 10 times and check that the subnet-id
// is set to the same value.
......@@ -1508,9 +1516,10 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
ASSERT_TRUE(subnets);
ASSERT_EQ(3, subnets->size()); // We expect 3 subnets now (4th is removed)
EXPECT_EQ(1, subnets->at(0)->getID());
EXPECT_EQ(2, subnets->at(1)->getID());
EXPECT_EQ(3, subnets->at(2)->getID());
auto subnet = subnets->begin();
EXPECT_EQ(1, (*subnet)->getID());
EXPECT_EQ(2, (*++subnet)->getID());
EXPECT_EQ(3, (*++subnet)->getID());
/// CASE 2: Configure 4 subnets, then reconfigure and remove one
/// from in between (not first, not last)
......@@ -1532,10 +1541,11 @@ TEST_F(Dhcp6ParserTest, reconfigureRemoveSubnet) {
ASSERT_TRUE(subnets);
ASSERT_EQ(3, subnets->size()); // We expect 4 subnets
EXPECT_EQ(1, subnets->at(0)->getID());