Commit f1280450 authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] Merged trac5104 (prefix triple assignment)

parents 7d45ef02 5b02a964
// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -367,7 +367,7 @@ bool
Subnet::inPool(Lease::Type type, const isc::asiolink::IOAddress& addr) const {
// Let's start with checking if it even belongs to that subnet.
if (!inRange(addr)) {
if ((type != Lease::TYPE_PD) && !inRange(addr)) {
return (false);
}
......
......@@ -72,11 +72,12 @@ public:
/// @brief checks if the specified address is in pools
///
/// Note the difference between inRange() and inPool(). For a given
/// subnet (e.g. 2001::/64) there may be one or more pools defined
/// that may or may not cover entire subnet, e.g. pool 2001::1-2001::10).
/// inPool() returning true implies inRange(), but the reverse implication
/// is not always true. For the given example, 2001::1234:abcd would return
/// Note the difference between inRange() and inPool() for addresses
/// (i.e. *not* prefixes). For a given subnet (e.g. 2001::/64) there
/// may be one or more pools defined that may or may not cover
/// entire subnet, e.g. pool 2001::1-2001::10). inPool() returning
/// true implies inRange(), but the reverse implication is not
/// always true. For the given example, 2001::1234:abcd would return
/// true for inRange(), but false for inPool() check.
///
/// @param type type of pools to iterate over
......
// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -112,7 +112,7 @@ TEST(Pool4Test, unique_id) {
}
// Simple check if toText returns reasonable values
TEST(Pool4Test,toText) {
TEST(Pool4Test, toText) {
Pool4 pool1(IOAddress("192.0.2.7"), IOAddress("192.0.2.17"));
EXPECT_EQ("type=V4, 192.0.2.7-192.0.2.17", pool1.toText());
......
// Copyright (C) 2012-2015,2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -1096,7 +1096,7 @@ TEST(Subnet6Test, inRangeinPool) {
IOAddress("2001:db8::20")));
subnet->addPool(pool1);
// 192.1.1.1 belongs to the subnet...
// 2001:db8::1 belongs to the subnet...
EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::1")));
// ... but it does not belong to any pool within
EXPECT_FALSE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::1")));
......@@ -1122,6 +1122,40 @@ TEST(Subnet6Test, inRangeinPool) {
EXPECT_FALSE(subnet->inPool(Lease::TYPE_NA, IOAddress("2001:db8::21")));
}
// This test verifies that inRange() and inPool() methods work properly
// for prefixes too.
TEST(Subnet6Test, PdinRangeinPool) {
Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 64, 1, 2, 3, 4));
// this one is in subnet
Pool6Ptr pool1(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8::"),
96, 112));
subnet->addPool(pool1);
// this one is not in subnet
Pool6Ptr pool2(new Pool6(Lease::TYPE_PD, IOAddress("2001:db8:1::"),
96, 112));
subnet->addPool(pool2);
// 2001:db8::1:0:0 belongs to the subnet...
EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::1:0:0")));
// ... but it does not belong to any pool within
EXPECT_FALSE(subnet->inPool(Lease::TYPE_PD, IOAddress("2001:db8::1:0:0")));
// 2001:db8:1::1 does not belong to the subnet...
EXPECT_FALSE(subnet->inRange(IOAddress("2001:db8:1::1")));
// ... but it belongs to the second pool
EXPECT_TRUE(subnet->inPool(Lease::TYPE_PD, IOAddress("2001:db8:1::1")));
// 2001:db8::1 belongs to the subnet and to the first pool
EXPECT_TRUE(subnet->inRange(IOAddress("2001:db8::1")));
EXPECT_TRUE(subnet->inPool(Lease::TYPE_PD, IOAddress("2001:db8::1")));
// 2001:db8:0:1:0:1:: does not belong to the subnet and any pool
EXPECT_FALSE(subnet->inRange(IOAddress("2001:db8:0:1:0:1::")));
EXPECT_FALSE(subnet->inPool(Lease::TYPE_PD, IOAddress("2001:db8:0:1:0:1::")));
}
// This test checks if the toText() method returns text representation
TEST(Subnet6Test, toText) {
Subnet6 subnet(IOAddress("2001:db8::"), 32, 1, 2, 3, 4);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment