|
@@ -17,6 +17,7 @@
|
|
|
#include <dhcp/tests/iface_mgr_test_config.h>
|
|
|
#include <dhcpsrv/cfg_subnets4.h>
|
|
|
#include <dhcpsrv/subnet.h>
|
|
|
+#include <dhcpsrv/subnet_id.h>
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
using namespace isc;
|
|
@@ -41,12 +42,12 @@ TEST(CfgSubnets4Test, getSubnetByCiaddr) {
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.0");
|
|
|
// Set some unicast local address to simulate a Renew.
|
|
|
selector.local_address_ = IOAddress("10.0.0.100");
|
|
|
- ASSERT_FALSE(cfg.get(selector));
|
|
|
+ ASSERT_FALSE(cfg.selectSubnet(selector));
|
|
|
|
|
|
// Add one subnet and make sure it is returned.
|
|
|
cfg.add(subnet1);
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.63");
|
|
|
- EXPECT_EQ(subnet1, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
|
|
|
|
|
|
// Add all other subnets.
|
|
|
cfg.add(subnet2);
|
|
@@ -54,16 +55,16 @@ TEST(CfgSubnets4Test, getSubnetByCiaddr) {
|
|
|
|
|
|
// Make sure they are returned for the appropriate addresses.
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.15");
|
|
|
- EXPECT_EQ(subnet1, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.85");
|
|
|
- EXPECT_EQ(subnet2, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.191");
|
|
|
- EXPECT_EQ(subnet3, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
|
|
|
|
|
|
// Also, make sure that the NULL pointer is returned if the subnet
|
|
|
// cannot be found.
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.192");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -87,11 +88,11 @@ TEST(CfgSubnets4Test, getSubnetByClasses) {
|
|
|
selector.local_address_ = IOAddress("10.0.0.10");
|
|
|
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.5");
|
|
|
- EXPECT_EQ(subnet1, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.70");
|
|
|
- EXPECT_EQ(subnet2, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.130");
|
|
|
- EXPECT_EQ(subnet3, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
|
|
|
|
|
|
ClientClasses client_classes;
|
|
|
client_classes.insert("bar");
|
|
@@ -100,11 +101,11 @@ TEST(CfgSubnets4Test, getSubnetByClasses) {
|
|
|
// There are no class restrictions defined, so everything should work
|
|
|
// as before
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.5");
|
|
|
- EXPECT_EQ(subnet1, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.70");
|
|
|
- EXPECT_EQ(subnet2, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.130");
|
|
|
- EXPECT_EQ(subnet3, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
|
|
|
|
|
|
// Now let's add client class restrictions.
|
|
|
subnet1->allowClientClass("foo"); // Serve here only clients from foo class
|
|
@@ -114,31 +115,31 @@ TEST(CfgSubnets4Test, getSubnetByClasses) {
|
|
|
// The same check as above should result in client being served only in
|
|
|
// bar class, i.e. subnet2.
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.5");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.70");
|
|
|
- EXPECT_EQ(subnet2, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.130");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
|
|
|
// Now let's check that client with wrong class is not supported.
|
|
|
client_classes.clear();
|
|
|
client_classes.insert("some_other_class");
|
|
|
selector.client_classes_ = client_classes;
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.5");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.70");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.130");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
|
|
|
// Finally, let's check that client without any classes is not supported.
|
|
|
client_classes.clear();
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.5");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.70");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.ciaddr_ = IOAddress("192.0.2.130");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
}
|
|
|
|
|
|
// This test verifies that the relay information can be used to retrieve the
|
|
@@ -160,11 +161,11 @@ TEST(CfgSubnetsTest, getSubnetByRelayAddress) {
|
|
|
|
|
|
// Check that without relay-info specified, subnets are not selected
|
|
|
selector.giaddr_ = IOAddress("10.0.0.1");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.giaddr_ = IOAddress("10.0.0.2");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.giaddr_ = IOAddress("10.0.0.3");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
|
|
|
// Now specify relay info
|
|
|
subnet1->setRelayInfo(IOAddress("10.0.0.1"));
|
|
@@ -173,11 +174,11 @@ TEST(CfgSubnetsTest, getSubnetByRelayAddress) {
|
|
|
|
|
|
// And try again. This time relay-info is there and should match.
|
|
|
selector.giaddr_ = IOAddress("10.0.0.1");
|
|
|
- EXPECT_EQ(subnet1, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
|
|
|
selector.giaddr_ = IOAddress("10.0.0.2");
|
|
|
- EXPECT_EQ(subnet2, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
|
|
|
selector.giaddr_ = IOAddress("10.0.0.3");
|
|
|
- EXPECT_EQ(subnet3, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
|
|
|
}
|
|
|
|
|
|
// This test verifies that the subnet can be selected for the client
|
|
@@ -195,12 +196,12 @@ TEST(CfgSubnetsTest, getSubnetNoCiaddr) {
|
|
|
selector.remote_address_ = IOAddress("192.0.2.0");
|
|
|
// Set some unicast local address to simulate a Renew.
|
|
|
selector.local_address_ = IOAddress("10.0.0.100");
|
|
|
- ASSERT_FALSE(cfg.get(selector));
|
|
|
+ ASSERT_FALSE(cfg.selectSubnet(selector));
|
|
|
|
|
|
// Add one subnet and make sure it is returned.
|
|
|
cfg.add(subnet1);
|
|
|
selector.remote_address_ = IOAddress("192.0.2.63");
|
|
|
- EXPECT_EQ(subnet1, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
|
|
|
|
|
|
// Add all other subnets.
|
|
|
cfg.add(subnet2);
|
|
@@ -208,21 +209,25 @@ TEST(CfgSubnetsTest, getSubnetNoCiaddr) {
|
|
|
|
|
|
// Make sure they are returned for the appropriate addresses.
|
|
|
selector.remote_address_ = IOAddress("192.0.2.15");
|
|
|
- EXPECT_EQ(subnet1, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
|
|
|
selector.remote_address_ = IOAddress("192.0.2.85");
|
|
|
- EXPECT_EQ(subnet2, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
|
|
|
selector.remote_address_ = IOAddress("192.0.2.191");
|
|
|
- EXPECT_EQ(subnet3, cfg.get(selector));
|
|
|
+ EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
|
|
|
|
|
|
// Also, make sure that the NULL pointer is returned if the subnet
|
|
|
// cannot be found.
|
|
|
selector.remote_address_ = IOAddress("192.0.2.192");
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
}
|
|
|
|
|
|
// This test verifies that the subnet can be selected using an address
|
|
|
// set on the local interface.
|
|
|
TEST(CfgSubnetsTest, getSubnetInterface) {
|
|
|
+ // The IfaceMgrTestConfig object initializes fake interfaces:
|
|
|
+ // eth0, eth1 and lo on the configuration manager. The CfgSubnets4
|
|
|
+ // object uses addresses assigned to these fake interfaces to
|
|
|
+ // select the appropriate subnet.
|
|
|
IfaceMgrTestConfig config(true);
|
|
|
|
|
|
CfgSubnets4 cfg;
|
|
@@ -231,9 +236,9 @@ TEST(CfgSubnetsTest, getSubnetInterface) {
|
|
|
// Initially, there are no subnets configured, so none of the IPv4
|
|
|
// addresses assigned to eth0 and eth1 can match with any subnet.
|
|
|
selector.iface_name_ = "eth0";
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
selector.iface_name_ = "eth1";
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
|
|
|
// Configure first subnet which address on eth0 corresponds to.
|
|
|
Subnet4Ptr subnet1(new Subnet4(IOAddress("10.0.0.1"), 24, 1, 2, 3));
|
|
@@ -241,12 +246,12 @@ TEST(CfgSubnetsTest, getSubnetInterface) {
|
|
|
|
|
|
// The address on eth0 should match the existing subnet.
|
|
|
selector.iface_name_ = "eth0";
|
|
|
- Subnet4Ptr subnet1_ret = cfg.get(selector);
|
|
|
+ Subnet4Ptr subnet1_ret = cfg.selectSubnet(selector);
|
|
|
ASSERT_TRUE(subnet1_ret);
|
|
|
EXPECT_EQ(subnet1->get().first, subnet1_ret->get().first);
|
|
|
// There should still be no match for eth1.
|
|
|
selector.iface_name_ = "eth1";
|
|
|
- EXPECT_FALSE(cfg.get(selector));
|
|
|
+ EXPECT_FALSE(cfg.selectSubnet(selector));
|
|
|
|
|
|
// Configure a second subnet.
|
|
|
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.1"), 24, 1, 2, 3));
|
|
@@ -255,17 +260,17 @@ TEST(CfgSubnetsTest, getSubnetInterface) {
|
|
|
// There should be match between eth0 and subnet1 and between eth1 and
|
|
|
// subnet 2.
|
|
|
selector.iface_name_ = "eth0";
|
|
|
- subnet1_ret = cfg.get(selector);
|
|
|
+ subnet1_ret = cfg.selectSubnet(selector);
|
|
|
ASSERT_TRUE(subnet1_ret);
|
|
|
EXPECT_EQ(subnet1->get().first, subnet1_ret->get().first);
|
|
|
selector.iface_name_ = "eth1";
|
|
|
- Subnet4Ptr subnet2_ret = cfg.get(selector);
|
|
|
+ Subnet4Ptr subnet2_ret = cfg.selectSubnet(selector);
|
|
|
ASSERT_TRUE(subnet2_ret);
|
|
|
EXPECT_EQ(subnet2->get().first, subnet2_ret->get().first);
|
|
|
|
|
|
// This function throws an exception if the name of the interface is wrong.
|
|
|
selector.iface_name_ = "bogus-interface";
|
|
|
- EXPECT_THROW(cfg.get(selector), isc::BadValue);
|
|
|
+ EXPECT_THROW(cfg.selectSubnet(selector), isc::BadValue);
|
|
|
}
|
|
|
|
|
|
// Checks that detection of duplicated subnet IDs works as expected. It should
|
|
@@ -280,7 +285,7 @@ TEST(CfgSubnets4, duplication) {
|
|
|
ASSERT_NO_THROW(cfg.add(subnet1));
|
|
|
EXPECT_NO_THROW(cfg.add(subnet2));
|
|
|
// Subnet 3 has the same ID as subnet 1. It shouldn't be able to add it.
|
|
|
- EXPECT_THROW(cfg.add(subnet3), isc::dhcp::DuplicateSubnet4ID);
|
|
|
+ EXPECT_THROW(cfg.add(subnet3), isc::dhcp::DuplicateSubnetID);
|
|
|
}
|
|
|
|
|
|
|