From: Francis Dupont Date: Mon, 20 Nov 2017 14:46:58 +0000 (+0100) Subject: [5425] Checkpoint: alloc done, new tests todo X-Git-Tag: trac5374_base~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9663c46dc31098a262e29d67b35cdbd421170f5b;p=thirdparty%2Fkea.git [5425] Checkpoint: alloc done, new tests todo --- diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index dcc3bf2377..c2cdcbbe5c 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -4144,47 +4144,47 @@ TEST_F(Dhcp4ParserTest, classifyPools) { // everyone). ClientClasses classes; classes.insert("alpha"); - EXPECT_TRUE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE(pools.at(3)->clientSupported(classes)); + EXPECT_TRUE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE(pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to beta class is supported in pool[1] // and not supported in any other pool (except pools[3], which allows // everyone). classes.clear(); classes.insert("beta"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_TRUE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE(pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_TRUE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE(pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to gamma class is supported in pool[2] // and not supported in any other pool (except pool[3], which allows // everyone). classes.clear(); classes.insert("gamma"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_TRUE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE(pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_TRUE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE(pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to some other class (not mentioned in // the config) is supported only in pool[3], which allows everyone. classes.clear(); classes.insert("delta"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE(pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE(pools.at(3)->clientSupported(classes, false)); // Finally, let's check class-less client. He should be allowed only in // the last pool, which does not have any class restrictions. classes.clear(); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE(pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE(pools.at(3)->clientSupported(classes, false)); } // This test verifies that the host reservations can be specified for diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index b29fd5840f..27f4edc129 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -4181,47 +4181,47 @@ TEST_F(Dhcp6ParserTest, classifyPools) { // everyone). ClientClasses classes; classes.insert("alpha"); - EXPECT_TRUE (pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_TRUE (pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to beta class is supported in pool[1] // and not supported in any other pool (except pool[3], which allows // everyone). classes.clear(); classes.insert("beta"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_TRUE (pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to gamma class is supported in pool[2] // and not supported in any other pool (except pool[3], which allows // everyone). classes.clear(); classes.insert("gamma"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_TRUE (pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to some other class (not mentioned in // the config) is supported only in pool[3], which allows everyone. classes.clear(); classes.insert("delta"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Finally, let's check class-less client. He should be allowed only in // the last pool, which does not have any class restrictions. classes.clear(); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); } // Goal of this test is to verify that multiple pdpools can be configured @@ -4279,47 +4279,47 @@ TEST_F(Dhcp6ParserTest, classifyPdPools) { // everyone). ClientClasses classes; classes.insert("alpha"); - EXPECT_TRUE (pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_TRUE (pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to beta class is supported in pool[1] // and not supported in any other pool (except pool[3], which allows // everyone). classes.clear(); classes.insert("beta"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_TRUE (pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to gamma class is supported in pool[2] // and not supported in any other pool (except pool[3], which allows // everyone). classes.clear(); classes.insert("gamma"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_TRUE (pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Let's check if client belonging to some other class (not mentioned in // the config) is supported only in pool[3], which allows everyone. classes.clear(); classes.insert("delta"); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); // Finally, let's check class-less client. He should be allowed only in // the last pool, which does not have any class restrictions. classes.clear(); - EXPECT_FALSE(pools.at(0)->clientSupported(classes)); - EXPECT_FALSE(pools.at(1)->clientSupported(classes)); - EXPECT_FALSE(pools.at(2)->clientSupported(classes)); - EXPECT_TRUE (pools.at(3)->clientSupported(classes)); + EXPECT_FALSE(pools.at(0)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(1)->clientSupported(classes, false)); + EXPECT_FALSE(pools.at(2)->clientSupported(classes, false)); + EXPECT_TRUE (pools.at(3)->clientSupported(classes, false)); } // This test checks the ability of the server to parse a configuration diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index d608de1b28..7e8015fc1c 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -158,6 +158,7 @@ AllocEngine::IterativeAllocator::increaseAddress(const isc::asiolink::IOAddress& isc::asiolink::IOAddress AllocEngine::IterativeAllocator::pickAddress(const SubnetPtr& subnet, const ClientClasses& client_classes, + bool known_client, const DuidPtr&, const IOAddress&) { @@ -183,7 +184,7 @@ AllocEngine::IterativeAllocator::pickAddress(const SubnetPtr& subnet, PoolCollection::const_iterator first = pools.end(); PoolPtr first_pool; for (it = pools.begin(); it != pools.end(); ++it) { - if (!(*it)->clientSupported(client_classes)) { + if (!(*it)->clientSupported(client_classes, known_client)) { continue; } if (first == pools.end()) { @@ -212,7 +213,7 @@ AllocEngine::IterativeAllocator::pickAddress(const SubnetPtr& subnet, // Trying next pool if (retrying) { for (; it != pools.end(); ++it) { - if ((*it)->clientSupported(client_classes)) { + if ((*it)->clientSupported(client_classes, known_client)) { break; } } @@ -271,7 +272,7 @@ AllocEngine::IterativeAllocator::pickAddress(const SubnetPtr& subnet, // Let's rewind to the beginning. for (it = first; it != pools.end(); ++it) { - if ((*it)->clientSupported(client_classes)) { + if ((*it)->clientSupported(client_classes, known_client)) { (*it)->setLastAllocated((*it)->getFirstAddress()); (*it)->resetLastAllocated(); } @@ -293,6 +294,7 @@ AllocEngine::HashedAllocator::HashedAllocator(Lease::Type lease_type) isc::asiolink::IOAddress AllocEngine::HashedAllocator::pickAddress(const SubnetPtr&, const ClientClasses&, + bool known_client, const DuidPtr&, const IOAddress&) { isc_throw(NotImplemented, "Hashed allocator is not implemented"); @@ -307,6 +309,7 @@ AllocEngine::RandomAllocator::RandomAllocator(Lease::Type lease_type) isc::asiolink::IOAddress AllocEngine::RandomAllocator::pickAddress(const SubnetPtr&, const ClientClasses&, + bool known_client, const DuidPtr&, const IOAddress&) { isc_throw(NotImplemented, "Random allocator is not implemented"); @@ -447,7 +450,8 @@ inAllowedPool(AllocEngine::ClientContext6& ctx, const Lease::Type& lease_type, } } else { if (current_subnet->inPool(lease_type, address, - ctx.query_->getClasses())) { + ctx.query_->getClasses(), + !ctx.hosts_.empty())) { return (true); } } @@ -752,10 +756,12 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) { // check if the hint is in pool and is available // This is equivalent of subnet->inPool(hint), but returns the pool pool = boost::dynamic_pointer_cast - (subnet->getPool(ctx.currentIA().type_, ctx.query_->getClasses(), hint)); + (subnet->getPool(ctx.currentIA().type_, ctx.query_->getClasses(), + !ctx.hosts_.empty(), hint)); // check if the pool is allowed - if (pool && !pool->clientSupported(ctx.query_->getClasses())) { + if (pool && !pool->clientSupported(ctx.query_->getClasses(), + !ctx.hosts_.empty())) { pool.reset(); } @@ -857,7 +863,8 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) { // - we exhaust number of tries uint64_t possible_attempts = subnet->getPoolCapacity(ctx.currentIA().type_, - ctx.query_->getClasses()); + ctx.query_->getClasses(), + !ctx.hosts_.empty()); // Try next subnet if there is no chance to get something if (possible_attempts == 0) { subnet = subnet->getNextSubnet(original_subnet); @@ -871,6 +878,7 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) { IOAddress candidate = allocator->pickAddress(subnet, ctx.query_->getClasses(), + !ctx.hosts_.empty(), ctx.duid_, hint); @@ -889,7 +897,10 @@ AllocEngine::allocateUnreservedLeases6(ClientContext6& ctx) { uint8_t prefix_len = 128; if (ctx.currentIA().type_ == Lease::TYPE_PD) { pool = boost::dynamic_pointer_cast( - subnet->getPool(ctx.currentIA().type_, ctx.query_->getClasses(), candidate)); + subnet->getPool(ctx.currentIA().type_, + ctx.query_->getClasses(), + !ctx.hosts_.empty(), + candidate)); if (pool) { prefix_len = pool->getLength(); } @@ -2626,7 +2637,8 @@ inAllowedPool(AllocEngine::ClientContext4& ctx, const IOAddress& address) { while (current_subnet) { if (current_subnet->inPool(Lease::TYPE_V4, address, - ctx.query_->getClasses())) { + ctx.query_->getClasses(), + !ctx.hosts_.empty())) { // We found a subnet that this address belongs to, so it // seems that this subnet is the good candidate for allocation. // Let's update the selected subnet. @@ -3354,7 +3366,8 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) { uint64_t possible_attempts = subnet->getPoolCapacity(Lease::TYPE_V4, - ctx.query_->getClasses()); + ctx.query_->getClasses(), + !ctx.hosts_.empty()); uint64_t max_attempts = (attempts_ > 0 ? attempts_ : possible_attempts); // Skip trying if there is no chance to get something if (possible_attempts == 0) { @@ -3364,6 +3377,7 @@ AllocEngine::allocateUnreservedLease4(ClientContext4& ctx) { for (uint64_t i = 0; i < max_attempts; ++i) { IOAddress candidate = allocator->pickAddress(subnet, ctx.query_->getClasses(), + !ctx.hosts_.empty(), client_id, ctx.requested_address_); // If address is not reserved for another client, try to allocate it. diff --git a/src/lib/dhcpsrv/alloc_engine.h b/src/lib/dhcpsrv/alloc_engine.h index af5c44da21..251db83e3b 100644 --- a/src/lib/dhcpsrv/alloc_engine.h +++ b/src/lib/dhcpsrv/alloc_engine.h @@ -83,7 +83,7 @@ protected: /// /// @param subnet next address will be returned from pool of that subnet /// @param client_classes list of classes client belongs to - + /// @param known_client client has a reservation /// @param duid Client's DUID /// @param hint client's hint /// @@ -91,6 +91,7 @@ protected: virtual isc::asiolink::IOAddress pickAddress(const SubnetPtr& subnet, const ClientClasses& client_classes, + bool known_client, const DuidPtr& duid, const isc::asiolink::IOAddress& hint) = 0; @@ -133,12 +134,14 @@ protected: /// /// @param subnet next address will be returned from pool of that subnet /// @param client_classes list of classes client belongs to + /// @param known_client client has a reservation /// @param duid Client's DUID (ignored) /// @param hint client's hint (ignored) /// @return the next address virtual isc::asiolink::IOAddress pickAddress(const SubnetPtr& subnet, const ClientClasses& client_classes, + bool known_client, const DuidPtr& duid, const isc::asiolink::IOAddress& hint); protected: @@ -188,12 +191,14 @@ protected: /// /// @param subnet an address will be picked from pool of that subnet /// @param client_classes list of classes client belongs to + /// @param known_client client has a reservation /// @param duid Client's DUID /// @param hint a hint (last address that was picked) /// @return selected address virtual isc::asiolink::IOAddress pickAddress(const SubnetPtr& subnet, const ClientClasses& client_classes, + bool known_client, const DuidPtr& duid, const isc::asiolink::IOAddress& hint); }; @@ -219,6 +224,7 @@ protected: virtual isc::asiolink::IOAddress pickAddress(const SubnetPtr& subnet, const ClientClasses& client_classes, + bool known_client, const DuidPtr& duid, const isc::asiolink::IOAddress& hint); }; diff --git a/src/lib/dhcpsrv/pool.cc b/src/lib/dhcpsrv/pool.cc index da3258f2b9..9e6aca6389 100644 --- a/src/lib/dhcpsrv/pool.cc +++ b/src/lib/dhcpsrv/pool.cc @@ -27,21 +27,39 @@ bool Pool::inRange(const isc::asiolink::IOAddress& addr) const { return (first_.smallerEqual(addr) && addr.smallerEqual(last_)); } -bool Pool::clientSupported(const ClientClasses& classes) const { +bool Pool::clientSupported(const ClientClasses& classes, + bool known_client) const { + bool match = false; if (white_list_.empty()) { // There is no class defined for this pool, so we do // support everyone. - return (true); + match = true; + } else { + + for (ClientClasses::const_iterator it = white_list_.begin(); + it != white_list_.end(); ++it) { + if (classes.contains(*it)) { + match = true; + break; + } + } } - for (ClientClasses::const_iterator it = white_list_.begin(); - it != white_list_.end(); ++it) { - if (classes.contains(*it)) { - return (true); - } + if (!match) { + return (false); } - return (false); + switch (known_clients_) { + case SERVE_BOTH: + return (true); + case SERVE_KNOWN: + return (known_client); + case SERVE_UNKNOWN: + return (!known_client); + default: + // Saninity check for an impossible condition + isc_throw(BadValue, "Invalid value of known clients"); + } } void Pool::allowClientClass(const ClientClass& class_name) { diff --git a/src/lib/dhcpsrv/pool.h b/src/lib/dhcpsrv/pool.h index d74022ac33..d4fb980364 100644 --- a/src/lib/dhcpsrv/pool.h +++ b/src/lib/dhcpsrv/pool.h @@ -121,8 +121,11 @@ public: /// is known to be improved. /// /// @param client_classes list of all classes the client belongs to + /// @param known_client true if the client is known, i.e. has a + /// reservation /// @return true if client can be supported, false otherwise - bool clientSupported(const ClientClasses& client_classes) const; + bool clientSupported(const ClientClasses& client_classes, + bool known_client) const; /// @brief Adds class class_name to the list of supported classes /// diff --git a/src/lib/dhcpsrv/subnet.cc b/src/lib/dhcpsrv/subnet.cc index 8585264aa9..31d285c7ed 100644 --- a/src/lib/dhcpsrv/subnet.cc +++ b/src/lib/dhcpsrv/subnet.cc @@ -136,15 +136,16 @@ Subnet::getPoolCapacity(Lease::Type type) const { uint64_t Subnet::getPoolCapacity(Lease::Type type, - const ClientClasses& client_classes) const { + const ClientClasses& client_classes, + bool known_client) const { switch (type) { case Lease::TYPE_V4: case Lease::TYPE_NA: - return sumPoolCapacity(pools_, client_classes); + return sumPoolCapacity(pools_, client_classes, known_client); case Lease::TYPE_TA: - return sumPoolCapacity(pools_ta_, client_classes); + return sumPoolCapacity(pools_ta_, client_classes, known_client); case Lease::TYPE_PD: - return sumPoolCapacity(pools_pd_, client_classes); + return sumPoolCapacity(pools_pd_, client_classes, known_client); default: isc_throw(BadValue, "Unsupported pool type: " << static_cast(type)); @@ -171,10 +172,11 @@ Subnet::sumPoolCapacity(const PoolCollection& pools) const { uint64_t Subnet::sumPoolCapacity(const PoolCollection& pools, - const ClientClasses& client_classes) const { + const ClientClasses& client_classes, + bool known_client) const { uint64_t sum = 0; for (PoolCollection::const_iterator p = pools.begin(); p != pools.end(); ++p) { - if (!(*p)->clientSupported(client_classes)) { + if (!(*p)->clientSupported(client_classes, known_client)) { continue; } uint64_t x = (*p)->getCapacity(); @@ -370,6 +372,7 @@ const PoolPtr Subnet::getPool(Lease::Type type, const isc::asiolink::IOAddress& const PoolPtr Subnet::getPool(Lease::Type type, const ClientClasses& client_classes, + bool known_client, const isc::asiolink::IOAddress& hint) const { // check if the type is valid (and throw if it isn't) checkType(type); @@ -385,7 +388,8 @@ const PoolPtr Subnet::getPool(Lease::Type type, if (ub != pools.begin()) { --ub; - if ((*ub)->inRange(hint) && (*ub)->clientSupported(client_classes)) { + if ((*ub)->inRange(hint) && + (*ub)->clientSupported(client_classes, known_client)) { candidate = *ub; } } @@ -478,7 +482,8 @@ Subnet::inPool(Lease::Type type, const isc::asiolink::IOAddress& addr) const { bool Subnet::inPool(Lease::Type type, const isc::asiolink::IOAddress& addr, - const ClientClasses& client_classes) const { + const ClientClasses& client_classes, + bool known_client) const { // Let's start with checking if it even belongs to that subnet. if ((type != Lease::TYPE_PD) && !inRange(addr)) { @@ -489,7 +494,7 @@ Subnet::inPool(Lease::Type type, for (PoolCollection::const_iterator pool = pools.begin(); pool != pools.end(); ++pool) { - if (!(*pool)->clientSupported(client_classes)) { + if (!(*pool)->clientSupported(client_classes, known_client)) { continue; } if ((*pool)->inRange(addr)) { diff --git a/src/lib/dhcpsrv/subnet.h b/src/lib/dhcpsrv/subnet.h index dacdad8d05..5aa3640b7b 100644 --- a/src/lib/dhcpsrv/subnet.h +++ b/src/lib/dhcpsrv/subnet.h @@ -56,16 +56,18 @@ public: /// @brief checks if the specified address is in allowed pools /// - /// This takes also into account client classes + /// This takes also into account client classes and known client /// /// @param type type of pools to iterate over /// @param addr this address will be checked if it belongs to any pools in /// that subnet /// @param client_classes client class list which must be allowed + /// @param known_client true if the client is known, i.e. has a reservation /// @return true if the address is in any of the allowed pools bool inPool(Lease::Type type, const isc::asiolink::IOAddress& addr, - const ClientClasses& client_classes) const; + const ClientClasses& client_classes, + bool known_client) const; /// @brief returns the last address that was tried from this subnet /// @@ -157,13 +159,15 @@ public: /// @brief Returns a pool that specified address belongs to with classes /// - /// Variant using only pools allowing given classes + /// Variant using only pools allowing given classes and known clients /// /// @param type pool type that the pool is looked for /// @param client_classes client class list which must be allowed + /// @param known_client true if the client is known, i.e. has a reservation /// @param addr address that the returned pool should cover (optional) const PoolPtr getPool(Lease::Type type, const ClientClasses& client_classes, + bool known_client, const isc::asiolink::IOAddress& addr) const; /// @brief Returns a pool without any address specified @@ -194,12 +198,15 @@ public: uint64_t getPoolCapacity(Lease::Type type) const; /// @brief Returns the number of possible leases for specified lease type - /// allowed for a client which belongs to classes. + /// allowed for a client which belongs to classes and matches known + /// clients constraint. /// /// @param type type of the lease /// @param client_classes List of classes the client belongs to. + /// @param known_client true if the client is known, i.e. has a reservation uint64_t getPoolCapacity(Lease::Type type, - const ClientClasses& client_classes) const; + const ClientClasses& client_classes, + bool known_client) const; /// @brief Returns textual representation of the subnet (e.g. /// "2001:db8::/64") @@ -335,9 +342,11 @@ protected: /// @brief returns a sum of possible leases in all pools allowing classes /// @param pools list of pools /// @param client_classes list of classes + /// @param known_client true if the client is known, i.e. has a reservation /// @return sum of possible/allowed leases uint64_t sumPoolCapacity(const PoolCollection& pools, - const ClientClasses& client_classes) const; + const ClientClasses& client_classes, + bool known_client) const; /// @brief Checks if the specified pool overlaps with an existing pool. /// diff --git a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc index 3e1a370580..66329452a2 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc @@ -326,7 +326,8 @@ TEST_F(AllocEngine4Test, IterativeAllocator) { alloc(new NakedAllocEngine::IterativeAllocator(Lease::TYPE_V4)); for (int i = 0; i < 1000; ++i) { - IOAddress candidate = alloc->pickAddress(subnet_, cc_, clientid_, + IOAddress candidate = alloc->pickAddress(subnet_, cc_, + known_client_, clientid_, IOAddress("0.0.0.0")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate)); } @@ -349,10 +350,11 @@ TEST_F(AllocEngine4Test, IterativeAllocator_class) { cc_.insert("bar"); for (int i = 0; i < 1000; ++i) { - IOAddress candidate = alloc->pickAddress(subnet_, cc_, clientid_, + IOAddress candidate = alloc->pickAddress(subnet_, cc_, + known_client_, clientid_, IOAddress("0.0.0.0")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate)); - EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_)); + EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_, known_client_)); } } @@ -382,7 +384,7 @@ TEST_F(AllocEngine4Test, IterativeAllocator_manyPools4) { std::set generated_addrs; int cnt = 0; while (++cnt) { - IOAddress candidate = alloc.pickAddress(subnet_, cc_, clientid_, IOAddress("0.0.0.0")); + IOAddress candidate = alloc.pickAddress(subnet_, cc_, known_client_, clientid_, IOAddress("0.0.0.0")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate)); // One way to easily verify that the iterative allocator really works is diff --git a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc index e96ebbd37b..09dd38f7cf 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc @@ -189,7 +189,8 @@ TEST_F(AllocEngine6Test, IterativeAllocator) { alloc(new NakedAllocEngine::IterativeAllocator(Lease::TYPE_NA)); for (int i = 0; i < 1000; ++i) { - IOAddress candidate = alloc->pickAddress(subnet_, cc_, duid_, IOAddress("::")); + IOAddress candidate = alloc->pickAddress(subnet_, cc_, known_client_, + duid_, IOAddress("::")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate)); } } @@ -211,9 +212,10 @@ TEST_F(AllocEngine6Test, IterativeAllocator_class) { cc_.insert("bar"); for (int i = 0; i < 1000; ++i) { - IOAddress candidate = alloc->pickAddress(subnet_, cc_, duid_, IOAddress("::")); + IOAddress candidate = alloc->pickAddress(subnet_, cc_, known_client_, + duid_, IOAddress("::")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate)); - EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_)); + EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate, cc_, known_client_)); } } @@ -233,23 +235,43 @@ TEST_F(AllocEngine6Test, IterativeAllocatorAddrStep) { subnet_->addPool(pool3); // Let's check the first pool (5 addresses here) - EXPECT_EQ("2001:db8:1::1", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::2", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::3", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::4", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::5", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::1", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::2", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::3", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::4", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::5", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // The second pool is easy - only one address here - EXPECT_EQ("2001:db8:1::100", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::100", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // This is the third and last pool, with 2 addresses in it - EXPECT_EQ("2001:db8:1::105", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::106", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::105", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::106", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // We iterated over all addresses and reached to the end of the last pool. // Let's wrap around and start from the beginning - EXPECT_EQ("2001:db8:1::1", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::2", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::1", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::2", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } TEST_F(AllocEngine6Test, IterativeAllocatorAddrStepInClass) { @@ -274,23 +296,43 @@ TEST_F(AllocEngine6Test, IterativeAllocatorAddrStepInClass) { cc_.insert("foo"); // Let's check the first pool (5 addresses here) - EXPECT_EQ("2001:db8:1::1", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::2", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::3", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::4", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::5", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::1", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::2", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::3", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::4", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::5", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // The second pool is easy - only one address here - EXPECT_EQ("2001:db8:1::100", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::100", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // This is the third and last pool, with 2 addresses in it - EXPECT_EQ("2001:db8:1::105", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::106", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::105", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::106", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // We iterated over all addresses and reached to the end of the last pool. // Let's wrap around and start from the beginning - EXPECT_EQ("2001:db8:1::1", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::2", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::1", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::2", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } TEST_F(AllocEngine6Test, IterativeAllocatorAddrStepOutClass) { @@ -311,22 +353,40 @@ TEST_F(AllocEngine6Test, IterativeAllocatorAddrStepOutClass) { subnet_->addPool(pool3); // Let's check the first pool (5 addresses here) - EXPECT_EQ("2001:db8:1::1", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::2", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::3", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::4", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::5", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::1", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::2", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::3", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::4", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::5", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // The second pool is skipped // This is the third and last pool, with 2 addresses in it - EXPECT_EQ("2001:db8:1::105", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::106", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::105", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::106", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // We iterated over all addresses and reached to the end of the last pool. // Let's wrap around and start from the beginning - EXPECT_EQ("2001:db8:1::1", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:1::2", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::1", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::2", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStep) { @@ -347,41 +407,85 @@ TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStep) { // 2001:db8:2::/56 split into /64 prefixes (256 leases) (or 2001:db8:2:XX::) // First pool check (Let's check over all 16 leases) - EXPECT_EQ("2001:db8::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:10::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:20::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:30::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:40::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:50::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:60::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:70::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:80::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:90::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:a0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:b0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:c0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:d0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:e0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:f0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:10::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:20::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:30::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:40::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:50::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:60::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:70::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:80::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:90::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:a0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:b0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:c0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:d0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:e0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:f0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // Second pool (just one lease here) - EXPECT_EQ("2001:db8:1::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // Third pool (256 leases, let's check first and last explicitly and the // rest over in a pool - EXPECT_EQ("2001:db8:2::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:2::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); for (int i = 1; i < 255; i++) { stringstream exp; exp << "2001:db8:2:" << hex << i << dec << "::"; - EXPECT_EQ(exp.str(), alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ(exp.str(), + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } - EXPECT_EQ("2001:db8:2:ff::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:2:ff::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // Ok, we've iterated over all prefixes in all pools. We now wrap around. // We're looping over now (iterating over first pool again) - EXPECT_EQ("2001:db8::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:10::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:10::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStepInClass) { @@ -408,41 +512,85 @@ TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStepInClass) { // 2001:db8:2::/56 split into /64 prefixes (256 leases) (or 2001:db8:2:XX::) // First pool check (Let's check over all 16 leases) - EXPECT_EQ("2001:db8::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:10::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:20::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:30::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:40::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:50::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:60::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:70::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:80::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:90::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:a0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:b0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:c0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:d0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:e0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:f0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:10::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:20::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:30::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:40::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:50::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:60::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:70::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:80::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:90::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:a0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:b0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:c0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:d0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:e0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:f0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // Second pool (just one lease here) - EXPECT_EQ("2001:db8:1::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:1::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // Third pool (256 leases, let's check first and last explicitly and the // rest over in a pool - EXPECT_EQ("2001:db8:2::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:2::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); for (int i = 1; i < 255; i++) { stringstream exp; exp << "2001:db8:2:" << hex << i << dec << "::"; - EXPECT_EQ(exp.str(), alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ(exp.str(), + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } - EXPECT_EQ("2001:db8:2:ff::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:2:ff::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // Ok, we've iterated over all prefixes in all pools. We now wrap around. // We're looping over now (iterating over first pool again) - EXPECT_EQ("2001:db8::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:10::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:10::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStepOutClass) { @@ -465,40 +613,82 @@ TEST_F(AllocEngine6Test, IterativeAllocatorPrefixStepOutClass) { // 2001:db8:2::/56 split into /64 prefixes (256 leases) (or 2001:db8:2:XX::) // First pool check (Let's check over all 16 leases) - EXPECT_EQ("2001:db8::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:10::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:20::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:30::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:40::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:50::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:60::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:70::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:80::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:90::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:a0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:b0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:c0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:d0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:e0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:f0::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:10::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:20::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:30::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:40::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:50::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:60::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:70::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:80::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:90::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:a0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:b0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:c0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:d0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:e0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:f0::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // The second pool is skipped // Third pool (256 leases, let's check first and last explicitly and the // rest over in a pool - EXPECT_EQ("2001:db8:2::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:2::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); for (int i = 1; i < 255; i++) { stringstream exp; exp << "2001:db8:2:" << hex << i << dec << "::"; - EXPECT_EQ(exp.str(), alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ(exp.str(), + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } - EXPECT_EQ("2001:db8:2:ff::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:2:ff::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); // Ok, we've iterated over all prefixes in all pools. We now wrap around. // We're looping over now (iterating over first pool again) - EXPECT_EQ("2001:db8::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); - EXPECT_EQ("2001:db8:0:10::", alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")).toText()); + EXPECT_EQ("2001:db8::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); + EXPECT_EQ("2001:db8:0:10::", + alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("::")).toText()); } // This test verifies that the iterative allocator can step over addresses @@ -506,7 +696,8 @@ TEST_F(AllocEngine6Test, IterativeAllocatorAddressIncrease) { NakedAllocEngine::NakedIterativeAllocator alloc(Lease::TYPE_NA); // Let's pick the first address - IOAddress addr1 = alloc.pickAddress(subnet_, cc_, duid_, IOAddress("2001:db8:1::10")); + IOAddress addr1 = alloc.pickAddress(subnet_, cc_, known_client_, duid_, + IOAddress("2001:db8:1::10")); // Check that we can indeed pick the first address from the pool EXPECT_EQ("2001:db8:1::10", addr1.toText()); @@ -596,7 +787,8 @@ TEST_F(AllocEngine6Test, IterativeAllocator_manyPools6) { std::set generated_addrs; int cnt = 0; while (++cnt) { - IOAddress candidate = alloc.pickAddress(subnet_, cc_, duid_, IOAddress("::")); + IOAddress candidate = alloc.pickAddress(subnet_, cc_, known_client_, + duid_, IOAddress("::")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_NA, candidate)); // One way to easily verify that the iterative allocator really works is @@ -634,8 +826,9 @@ TEST_F(AllocEngine6Test, smallPool6) { IOAddress addr("2001:db8:1::ad"); // Create a subnet with a pool that has one address. - initSubnet(IOAddress("2001:db8:1::"), addr, addr); - + initSubnet(IOAddress("2001:db8:1::"), + addr, addr); + // Initialize FQDN for a lease. initFqdn("myhost.example.com", true, true); diff --git a/src/lib/dhcpsrv/tests/alloc_engine_utils.h b/src/lib/dhcpsrv/tests/alloc_engine_utils.h index eeed469755..1d20f0fc69 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_utils.h +++ b/src/lib/dhcpsrv/tests/alloc_engine_utils.h @@ -411,6 +411,7 @@ public: bool fqdn_rev_; ///< Perform reverse update for a lease. LeaseMgrFactory factory_; ///< pointer to LeaseMgr factory ClientClasses cc_; ///< client classes + bool known_client_; ///< client has a reservation }; /// @brief Used in Allocation Engine tests for IPv4 @@ -513,6 +514,7 @@ public: LeaseMgrFactory factory_; ///< Pointer to LeaseMgr factory AllocEngine::ClientContext4 ctx_; ///< Context information passed to various ClientClasses cc_; ///< Client classes + bool known_client_; ///< client has a reservation ///< allocation engine functions. }; diff --git a/src/lib/dhcpsrv/tests/pool_unittest.cc b/src/lib/dhcpsrv/tests/pool_unittest.cc index d720c2b023..bc54a7ed0b 100644 --- a/src/lib/dhcpsrv/tests/pool_unittest.cc +++ b/src/lib/dhcpsrv/tests/pool_unittest.cc @@ -215,19 +215,19 @@ TEST(Pool4Test, clientClass) { // No class restrictions defined, any client should be supported EXPECT_EQ(0, pool->getClientClasses().size()); - EXPECT_TRUE(pool->clientSupported(no_class)); - EXPECT_TRUE(pool->clientSupported(foo_class)); - EXPECT_TRUE(pool->clientSupported(bar_class)); - EXPECT_TRUE(pool->clientSupported(three_classes)); + EXPECT_TRUE(pool->clientSupported(no_class, false)); + EXPECT_TRUE(pool->clientSupported(foo_class, false)); + EXPECT_TRUE(pool->clientSupported(bar_class, false)); + EXPECT_TRUE(pool->clientSupported(three_classes, false)); // Let's allow only clients belonging to "bar" class. pool->allowClientClass("bar"); EXPECT_EQ(1, pool->getClientClasses().size()); - EXPECT_FALSE(pool->clientSupported(no_class)); - EXPECT_FALSE(pool->clientSupported(foo_class)); - EXPECT_TRUE(pool->clientSupported(bar_class)); - EXPECT_TRUE(pool->clientSupported(three_classes)); + EXPECT_FALSE(pool->clientSupported(no_class, false)); + EXPECT_FALSE(pool->clientSupported(foo_class, false)); + EXPECT_TRUE(pool->clientSupported(bar_class, false)); + EXPECT_TRUE(pool->clientSupported(three_classes, false)); } // This test checks that handling for multiple client-classes is valid. @@ -249,9 +249,9 @@ TEST(Pool4Test, clientClasses) { // No class restrictions defined, any client should be supported EXPECT_EQ(0, pool->getClientClasses().size()); - EXPECT_TRUE(pool->clientSupported(no_class)); - EXPECT_TRUE(pool->clientSupported(foo_class)); - EXPECT_TRUE(pool->clientSupported(bar_class)); + EXPECT_TRUE(pool->clientSupported(no_class, false)); + EXPECT_TRUE(pool->clientSupported(foo_class, false)); + EXPECT_TRUE(pool->clientSupported(bar_class, false)); // Let's allow clients belonging to "bar" or "foo" class. pool->allowClientClass("bar"); @@ -259,13 +259,13 @@ TEST(Pool4Test, clientClasses) { EXPECT_EQ(2, pool->getClientClasses().size()); // Class-less clients are to be rejected. - EXPECT_FALSE(pool->clientSupported(no_class)); + EXPECT_FALSE(pool->clientSupported(no_class, false)); // Clients in foo class should be accepted. - EXPECT_TRUE(pool->clientSupported(foo_class)); + EXPECT_TRUE(pool->clientSupported(foo_class, false)); // Clients in bar class should be accepted as well. - EXPECT_TRUE(pool->clientSupported(bar_class)); + EXPECT_TRUE(pool->clientSupported(bar_class, false)); } // This test checks that handling for known-clients is valid. @@ -633,19 +633,19 @@ TEST(Pool6Test, clientClass) { // No class restrictions defined, any client should be supported EXPECT_EQ(0, pool.getClientClasses().size()); - EXPECT_TRUE(pool.clientSupported(no_class)); - EXPECT_TRUE(pool.clientSupported(foo_class)); - EXPECT_TRUE(pool.clientSupported(bar_class)); - EXPECT_TRUE(pool.clientSupported(three_classes)); + EXPECT_TRUE(pool.clientSupported(no_class, false)); + EXPECT_TRUE(pool.clientSupported(foo_class, false)); + EXPECT_TRUE(pool.clientSupported(bar_class, false)); + EXPECT_TRUE(pool.clientSupported(three_classes, false)); // Let's allow only clients belonging to "bar" class. pool.allowClientClass("bar"); EXPECT_EQ(1, pool.getClientClasses().size()); - EXPECT_FALSE(pool.clientSupported(no_class)); - EXPECT_FALSE(pool.clientSupported(foo_class)); - EXPECT_TRUE(pool.clientSupported(bar_class)); - EXPECT_TRUE(pool.clientSupported(three_classes)); + EXPECT_FALSE(pool.clientSupported(no_class, false)); + EXPECT_FALSE(pool.clientSupported(foo_class, false)); + EXPECT_TRUE(pool.clientSupported(bar_class, false)); + EXPECT_TRUE(pool.clientSupported(three_classes, false)); } // This test checks that handling for multiple client-classes is valid. @@ -667,9 +667,9 @@ TEST(Pool6Test, clientClasses) { // No class restrictions defined, any client should be supported EXPECT_EQ(0, pool.getClientClasses().size()); - EXPECT_TRUE(pool.clientSupported(no_class)); - EXPECT_TRUE(pool.clientSupported(foo_class)); - EXPECT_TRUE(pool.clientSupported(bar_class)); + EXPECT_TRUE(pool.clientSupported(no_class, false)); + EXPECT_TRUE(pool.clientSupported(foo_class, false)); + EXPECT_TRUE(pool.clientSupported(bar_class, false)); // Let's allow clients belonging to "bar" or "foo" class. pool.allowClientClass("bar"); @@ -677,13 +677,13 @@ TEST(Pool6Test, clientClasses) { EXPECT_EQ(2, pool.getClientClasses().size()); // Class-less clients are to be rejected. - EXPECT_FALSE(pool.clientSupported(no_class)); + EXPECT_FALSE(pool.clientSupported(no_class, false)); // Clients in foo class should be accepted. - EXPECT_TRUE(pool.clientSupported(foo_class)); + EXPECT_TRUE(pool.clientSupported(foo_class, false)); // Clients in bar class should be accepted as well. - EXPECT_TRUE(pool.clientSupported(bar_class)); + EXPECT_TRUE(pool.clientSupported(bar_class, false)); } // This test checks that handling for known-clients is valid. diff --git a/src/lib/dhcpsrv/tests/subnet_unittest.cc b/src/lib/dhcpsrv/tests/subnet_unittest.cc index 4226bc2eea..8da02897ae 100644 --- a/src/lib/dhcpsrv/tests/subnet_unittest.cc +++ b/src/lib/dhcpsrv/tests/subnet_unittest.cc @@ -235,34 +235,34 @@ TEST(Subnet4Test, pool4InSubnet4) { three_classes.insert("baz"); // If we provide a hint, we should get a pool that this hint belongs to - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false, IOAddress("192.1.2.201"))); EXPECT_EQ(mypool, pool4); - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false, IOAddress("192.1.2.129"))); EXPECT_EQ(mypool, pool2); - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false, IOAddress("192.1.2.64"))); EXPECT_EQ(mypool, pool1); // Specify addresses which don't belong to any existing pools. - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, three_classes, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, three_classes, false, IOAddress("192.1.2.210"))); EXPECT_FALSE(mypool); // Pool3 requires a member of bar - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false, IOAddress("192.1.2.195"))); EXPECT_FALSE(mypool); - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, foo_class, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, foo_class, false, IOAddress("192.1.2.195"))); EXPECT_FALSE(mypool); - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, bar_class, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, bar_class, false, IOAddress("192.1.2.195"))); EXPECT_EQ(mypool, pool3); - ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, three_classes, + ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, three_classes, false, IOAddress("192.1.2.195"))); EXPECT_EQ(mypool, pool3); } @@ -319,10 +319,10 @@ TEST(Subnet4Test, getCapacity) { pool3->allowClientClass("bar"); // Pool3 requires a member of bar - EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4, no_class)); - EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4, foo_class)); - EXPECT_EQ(200, subnet->getPoolCapacity(Lease::TYPE_V4, bar_class)); - EXPECT_EQ(200, subnet->getPoolCapacity(Lease::TYPE_V4, three_classes)); + EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4, no_class, false)); + EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4, foo_class, false)); + EXPECT_EQ(200, subnet->getPoolCapacity(Lease::TYPE_V4, bar_class, false)); + EXPECT_EQ(200, subnet->getPoolCapacity(Lease::TYPE_V4, three_classes, false)); } // Checks that it is not allowed to add invalid pools. @@ -541,24 +541,24 @@ TEST(Subnet4Test, inRangeinPool) { // This client does not belong to any class. isc::dhcp::ClientClasses no_class; - EXPECT_FALSE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), no_class)); + EXPECT_FALSE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), no_class, false)); // This client belongs to foo only isc::dhcp::ClientClasses foo_class; foo_class.insert("foo"); - EXPECT_FALSE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), foo_class)); + EXPECT_FALSE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), foo_class, false)); // This client belongs to bar only. I like that client. isc::dhcp::ClientClasses bar_class; bar_class.insert("bar"); - EXPECT_TRUE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), bar_class)); + EXPECT_TRUE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), bar_class, false)); // This client belongs to foo, bar and baz classes. isc::dhcp::ClientClasses three_classes; three_classes.insert("foo"); three_classes.insert("bar"); three_classes.insert("baz"); - EXPECT_TRUE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), three_classes)); + EXPECT_TRUE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), three_classes, false)); } // This test checks if the toText() method returns text representation @@ -781,13 +781,13 @@ TEST(Subnet6Test, Pool6getCapacity) { // Pool3 requires a member of bar EXPECT_EQ(uint64_t(4294967296ull + 65536), - subnet->getPoolCapacity(Lease::TYPE_NA, no_class)); + subnet->getPoolCapacity(Lease::TYPE_NA, no_class, false)); EXPECT_EQ(uint64_t(4294967296ull + 65536), - subnet->getPoolCapacity(Lease::TYPE_NA, foo_class)); + subnet->getPoolCapacity(Lease::TYPE_NA, foo_class, false)); EXPECT_EQ(uint64_t(4294967296ull + 4294967296ull + 65536), - subnet->getPoolCapacity(Lease::TYPE_NA, bar_class)); + subnet->getPoolCapacity(Lease::TYPE_NA, bar_class, false)); EXPECT_EQ(uint64_t(4294967296ull + 4294967296ull + 65536), - subnet->getPoolCapacity(Lease::TYPE_NA, three_classes)); + subnet->getPoolCapacity(Lease::TYPE_NA, three_classes, false)); // This is 2^64 prefixes. We're overflown uint64_t. PoolPtr pool4(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:4::"), 64)); @@ -891,16 +891,16 @@ TEST(Subnet6Test, Pool6InSubnet6) { pool3->allowClientClass("bar"); // Pool3 requires a member of bar - mypool = subnet->getPool(Lease::TYPE_NA, no_class, + mypool = subnet->getPool(Lease::TYPE_NA, no_class, false, IOAddress("2001:db8:1:3::dead:beef")); EXPECT_FALSE(mypool); - mypool = subnet->getPool(Lease::TYPE_NA, foo_class, + mypool = subnet->getPool(Lease::TYPE_NA, foo_class, false, IOAddress("2001:db8:1:3::dead:beef")); EXPECT_FALSE(mypool); - mypool = subnet->getPool(Lease::TYPE_NA, bar_class, + mypool = subnet->getPool(Lease::TYPE_NA, bar_class, false, IOAddress("2001:db8:1:3::dead:beef")); EXPECT_EQ(mypool, pool3); - mypool = subnet->getPool(Lease::TYPE_NA, three_classes, + mypool = subnet->getPool(Lease::TYPE_NA, three_classes, false, IOAddress("2001:db8:1:3::dead:beef")); EXPECT_EQ(mypool, pool3); } @@ -1396,24 +1396,24 @@ TEST(Subnet6Test, inRangeinPool) { // This client does not belong to any class. isc::dhcp::ClientClasses no_class; - EXPECT_FALSE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), no_class)); + EXPECT_FALSE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), no_class, false)); // This client belongs to foo only isc::dhcp::ClientClasses foo_class; foo_class.insert("foo"); - EXPECT_FALSE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), foo_class)); + EXPECT_FALSE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), foo_class, false)); // This client belongs to bar only. I like that client. isc::dhcp::ClientClasses bar_class; bar_class.insert("bar"); - EXPECT_TRUE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), bar_class)); + EXPECT_TRUE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), bar_class, false)); // This client belongs to foo, bar and baz classes. isc::dhcp::ClientClasses three_classes; three_classes.insert("foo"); three_classes.insert("bar"); three_classes.insert("baz"); - EXPECT_TRUE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), three_classes)); + EXPECT_TRUE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::18"), three_classes, false)); } // This test verifies that inRange() and inPool() methods work properly