From: Tomek Mrugalski Date: Thu, 5 May 2016 13:41:47 +0000 (+0200) Subject: [4112] 2 new unit-tests added. X-Git-Tag: trac4106_update_base~25^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de9d01b7e1bffc3a907ba9bbdfc66ad4d891935f;p=thirdparty%2Fkea.git [4112] 2 new unit-tests added. --- diff --git a/src/lib/dhcpsrv/cfg_4o6.h b/src/lib/dhcpsrv/cfg_4o6.h index 3a6215f8ff..90bbf460ec 100644 --- a/src/lib/dhcpsrv/cfg_4o6.h +++ b/src/lib/dhcpsrv/cfg_4o6.h @@ -1,16 +1,8 @@ -// 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 diff --git a/src/lib/dhcpsrv/cfg_subnets4.h b/src/lib/dhcpsrv/cfg_subnets4.h index e418baf3cd..6ff0a73e18 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.h +++ b/src/lib/dhcpsrv/cfg_subnets4.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_; diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc index 15263a566c..36ec5ae3c8 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc @@ -1,4 +1,4 @@ -// 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 #include #include +#include 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 data1(dummyPayload1, dummyPayload1 + sizeof(dummyPayload1)); + std::vector 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