|
@@ -713,23 +713,42 @@ TEST_F(CfgMgrTest, d2ClientConfig) {
|
|
|
|
|
|
// This test verfies that CfgMgr correctly determines that the address of the
|
|
|
// interface belongs to existing IPv4 subnet.
|
|
|
-TEST_F(CfgMgrTest, belongsToSubnet4) {
|
|
|
+TEST_F(CfgMgrTest, getSubnet4ForInterface) {
|
|
|
IfaceMgrTestConfig config(true);
|
|
|
|
|
|
- ASSERT_FALSE(CfgMgr::instance().belongsToSubnet4("eth0"));
|
|
|
- ASSERT_FALSE(CfgMgr::instance().belongsToSubnet4("eth1"));
|
|
|
+ // Initially, there are no subnets configured, so none of the IPv4
|
|
|
+ // addresses assigned to eth0 and eth1 can match with any subnet.
|
|
|
+ ASSERT_FALSE(CfgMgr::instance().getSubnet4("eth0"));
|
|
|
+ ASSERT_FALSE(CfgMgr::instance().getSubnet4("eth1"));
|
|
|
|
|
|
+ // Configure first subnet which address on eth0 corresponds to.
|
|
|
Subnet4Ptr subnet1(new Subnet4(IOAddress("10.0.0.1"), 24, 1, 2, 3));
|
|
|
CfgMgr::instance().addSubnet4(subnet1);
|
|
|
|
|
|
- EXPECT_TRUE(CfgMgr::instance().belongsToSubnet4("eth0"));
|
|
|
- EXPECT_FALSE(CfgMgr::instance().belongsToSubnet4("eth1"));
|
|
|
+ // The address on eth0 should match the existing subnet.
|
|
|
+ Subnet4Ptr subnet1_ret;
|
|
|
+ subnet1_ret = CfgMgr::instance().getSubnet4("eth0");
|
|
|
+ ASSERT_TRUE(subnet1_ret);
|
|
|
+ EXPECT_EQ(subnet1->get().first, subnet1_ret->get().first);
|
|
|
+ // There should still be no match for eth1.
|
|
|
+ EXPECT_FALSE(CfgMgr::instance().getSubnet4("eth1"));
|
|
|
|
|
|
+ // Configure a second subnet.
|
|
|
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.1"), 24, 1, 2, 3));
|
|
|
CfgMgr::instance().addSubnet4(subnet2);
|
|
|
|
|
|
- EXPECT_TRUE(CfgMgr::instance().belongsToSubnet4("eth0"));
|
|
|
- EXPECT_TRUE(CfgMgr::instance().belongsToSubnet4("eth1"));
|
|
|
+ // There should be match between eth0 and subnet1 and between eth1 and
|
|
|
+ // subnet 2.
|
|
|
+ subnet1_ret = CfgMgr::instance().getSubnet4("eth0");
|
|
|
+ ASSERT_TRUE(subnet1_ret);
|
|
|
+ EXPECT_EQ(subnet1->get().first, subnet1_ret->get().first);
|
|
|
+ Subnet4Ptr subnet2_ret = CfgMgr::instance().getSubnet4("eth1");
|
|
|
+ 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.
|
|
|
+ EXPECT_THROW(CfgMgr::instance().getSubnet4("bogus-interface"),
|
|
|
+ isc::BadValue);
|
|
|
|
|
|
}
|
|
|
|