Commit de9d01b7 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[4112] 2 new unit-tests added.

parent 38a25c7c
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef CFG_4OVER6_H
#define CFG_4OVER6_H
......
......@@ -120,6 +120,28 @@ public:
const ClientClasses& client_classes
= ClientClasses()) const;
/// @brief Attempts to do subnet selection based on DHCP4o6 information
///
/// The algorithm implemented is as follows:
///
/// - First: try to match IPv6 subnet (4o6-subnet parameter) with the
/// remote IPv6 address of the incoming packet
/// - Second: try to match interface-id (4o6-interface-id parameter)
/// with the interface-id option in the incoming 4o6 packet
/// - Third: try to match interface-name (4o6-interface parameter)
/// with the name of the interface the incoming 4o6 packet was
/// received over.
///
/// @todo: Add additional selection criteria. See
/// http://kea.isc.org/wiki/ISC-DHCP4o6-Design for details.
///
/// @param selector Const reference to the selector structure which holds
/// various information extracted from the client's packet which are used
/// to find appropriate subnet.
/// @return Pointer to the selected subnet or NULL if no subnet found.
Subnet4Ptr
selectSubnet4o6(const SubnetSelector& selector) const;
/// @brief Updates statistics.
///
/// This method updates statistics that are affected by the newly committed
......@@ -147,27 +169,6 @@ private:
/// @return true if the duplicate subnet exists.
bool isDuplicate(const Subnet4& subnet) const;
/// @brief Attempts to do subnet selection based on DHCP4o6 information
///
/// The algorithm implemented is as follows:
///
/// - First: try to match IPv6 subnet (4o6-subnet parameter) with the
/// remote IPv6 address of the incoming packet
/// - Second: try to match interface-id (4o6-interface-id parameter)
/// with the interface-id option in the incoming 4o6 packet
/// - Third: try to match interface-name (4o6-interface parameter)
/// with the name of the interface the incoming 4o6 packet was
/// received over.
///
/// @todo: Add additional selection criteria. See
/// http://kea.isc.org/wiki/ISC-DHCP4o6-Design for details.
///
/// @param selector
/// @return selected IPv4 subnet
Subnet4Ptr
selectSubnet4o6(const SubnetSelector& selector) const;
/// @brief A container for IPv4 subnets.
Subnet4Collection subnets_;
......
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2016 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
......@@ -12,6 +12,7 @@
#include <dhcpsrv/subnet_id.h>
#include <dhcpsrv/subnet_selector.h>
#include <gtest/gtest.h>
#include <vector>
using namespace isc;
using namespace isc::asiolink;
......@@ -319,7 +320,7 @@ TEST(CfgSubnets4Test, duplication) {
}
// This test checks if the IPv4 subnet can be selected based on the IPv6 address.
TEST(CfgSubnets4Test, 4o6subnet) {
TEST(CfgSubnets4Test, 4o6subnetMatchByAddress) {
CfgSubnets4 cfg;
Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.2.0"), 26, 1, 2, 3, 123));
......@@ -341,5 +342,65 @@ TEST(CfgSubnets4Test, 4o6subnet) {
EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
}
// This test checks if the IPv4 subnet can be selected based on the value of
// interface-id option.
TEST(CfgSubnets4Test, 4o6subnetMatchByInterfaceId) {
CfgSubnets4 cfg;
Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.2.0"), 26, 1, 2, 3, 123));
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.64"), 26, 1, 2, 3, 124));
Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3, 125));
const uint8_t dummyPayload1[] = { 1, 2, 3, 4};
const uint8_t dummyPayload2[] = { 1, 2, 3, 5};
std::vector<uint8_t> data1(dummyPayload1, dummyPayload1 + sizeof(dummyPayload1));
std::vector<uint8_t> data2(dummyPayload2, dummyPayload2 + sizeof(dummyPayload2));
OptionPtr interfaceId1(new Option(Option::V6, D6O_INTERFACE_ID, data1));
OptionPtr interfaceId2(new Option(Option::V6, D6O_INTERFACE_ID, data2));
subnet2->get4o6().setInterfaceId(interfaceId1);
cfg.add(subnet1);
cfg.add(subnet2);
cfg.add(subnet3);
SubnetSelector selector;
selector.dhcp4o6_ = true;
selector.interface_id_ = interfaceId2;
// We have mismatched interface-id options (data1 vs data2). Should not match.
EXPECT_FALSE(cfg.selectSubnet(selector));
// This time we have correct interface-id. Should match.
selector.interface_id_ = interfaceId1;
EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
}
// This test checks if the IPv4 subnet can be selected based on the value of
// interface name option.
TEST(CfgSubnets4Test, 4o6subnetMatchByInterfaceName) {
CfgSubnets4 cfg;
Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.2.0"), 26, 1, 2, 3, 123));
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.64"), 26, 1, 2, 3, 124));
Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3, 125));
subnet2->get4o6().setIface4o6("eth7");
cfg.add(subnet1);
cfg.add(subnet2);
cfg.add(subnet3);
SubnetSelector selector;
selector.dhcp4o6_ = true;
selector.iface_name_ = "eth5";
// We have mismatched interface names. Should not match.
EXPECT_FALSE(cfg.selectSubnet(selector));
// This time we have correct names. Should match.
selector.iface_name_ = "eth7";
EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
}
} // end of anonymous namespace
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