mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
[4105] 4o6 configuration structure, unit-tests implemented
This commit is contained in:
@@ -3782,4 +3782,143 @@ TEST_F(Dhcp4ParserTest, expiredLeasesProcessingError) {
|
|||||||
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
|
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks if the DHCPv4 is able to parse the configuration without 4o6 parameters
|
||||||
|
// and do not set 4o6 fields at all.
|
||||||
|
TEST_F(Dhcp4ParserTest, 4o6default) {
|
||||||
|
|
||||||
|
ConstElementPtr status;
|
||||||
|
|
||||||
|
// Just a plain v4 config (no 4o6 parameters)
|
||||||
|
string config = "{ " + genIfaceConfig() + "," +
|
||||||
|
"\"rebind-timer\": 2000, "
|
||||||
|
"\"renew-timer\": 1000, "
|
||||||
|
"\"subnet4\": [ { "
|
||||||
|
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
|
||||||
|
" \"subnet\": \"192.0.2.0/24\" } ],"
|
||||||
|
"\"valid-lifetime\": 4000 }";
|
||||||
|
|
||||||
|
ElementPtr json = Element::fromJSON(config);
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
|
||||||
|
|
||||||
|
// check if returned status is OK
|
||||||
|
checkResult(status, 0);
|
||||||
|
|
||||||
|
// Now check if the configuration was indeed handled and we have
|
||||||
|
// expected pool configured.
|
||||||
|
Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->
|
||||||
|
getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
|
||||||
|
ASSERT_TRUE(subnet);
|
||||||
|
|
||||||
|
Cfg4o6& dhcp4o6 = subnet->get4o6();
|
||||||
|
EXPECT_FALSE(dhcp4o6.enabled_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if the DHCPv4 is able to parse the configuration with 4o6 subnet
|
||||||
|
// defined.
|
||||||
|
TEST_F(Dhcp4ParserTest, 4o6subnet) {
|
||||||
|
|
||||||
|
ConstElementPtr status;
|
||||||
|
|
||||||
|
// Just a plain v4 config (no 4o6 parameters)
|
||||||
|
string config = "{ " + genIfaceConfig() + "," +
|
||||||
|
"\"rebind-timer\": 2000, "
|
||||||
|
"\"renew-timer\": 1000, "
|
||||||
|
"\"subnet4\": [ { "
|
||||||
|
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
|
||||||
|
" \"subnet\": \"192.0.2.0/24\","
|
||||||
|
" \"4o6-subnet\": \"2001:db8::123/45\" } ],"
|
||||||
|
"\"valid-lifetime\": 4000 }";
|
||||||
|
|
||||||
|
ElementPtr json = Element::fromJSON(config);
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
|
||||||
|
|
||||||
|
// check if returned status is OK
|
||||||
|
checkResult(status, 0);
|
||||||
|
|
||||||
|
// Now check if the configuration was indeed handled and we have
|
||||||
|
// expected pool configured.
|
||||||
|
Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->
|
||||||
|
getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
|
||||||
|
ASSERT_TRUE(subnet);
|
||||||
|
|
||||||
|
Cfg4o6& dhcp4o6 = subnet->get4o6();
|
||||||
|
EXPECT_TRUE(dhcp4o6.enabled_);
|
||||||
|
EXPECT_EQ(IOAddress("2001:db8::123"), dhcp4o6.subnet4o6_.first);
|
||||||
|
EXPECT_EQ(45, dhcp4o6.subnet4o6_.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if the DHCPv4 is able to parse the configuration with 4o6 network
|
||||||
|
// interface defined.
|
||||||
|
TEST_F(Dhcp4ParserTest, 4o6iface) {
|
||||||
|
|
||||||
|
ConstElementPtr status;
|
||||||
|
|
||||||
|
// Just a plain v4 config (no 4o6 parameters)
|
||||||
|
string config = "{ " + genIfaceConfig() + "," +
|
||||||
|
"\"rebind-timer\": 2000, "
|
||||||
|
"\"renew-timer\": 1000, "
|
||||||
|
"\"subnet4\": [ { "
|
||||||
|
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
|
||||||
|
" \"subnet\": \"192.0.2.0/24\","
|
||||||
|
" \"4o6-interface\": \"ethX\" } ],"
|
||||||
|
"\"valid-lifetime\": 4000 }";
|
||||||
|
|
||||||
|
ElementPtr json = Element::fromJSON(config);
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
|
||||||
|
|
||||||
|
// check if returned status is OK
|
||||||
|
checkResult(status, 0);
|
||||||
|
|
||||||
|
// Now check if the configuration was indeed handled and we have
|
||||||
|
// expected pool configured.
|
||||||
|
Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->
|
||||||
|
getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
|
||||||
|
ASSERT_TRUE(subnet);
|
||||||
|
|
||||||
|
Cfg4o6& dhcp4o6 = subnet->get4o6();
|
||||||
|
EXPECT_TRUE(dhcp4o6.enabled_);
|
||||||
|
EXPECT_EQ("ethX", dhcp4o6.iface4o6_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if the DHCPv4 is able to parse the configuration with both 4o6 network
|
||||||
|
// interface and v6 subnet defined.
|
||||||
|
TEST_F(Dhcp4ParserTest, 4o6subnetIface) {
|
||||||
|
|
||||||
|
ConstElementPtr status;
|
||||||
|
|
||||||
|
// Just a plain v4 config (no 4o6 parameters)
|
||||||
|
string config = "{ " + genIfaceConfig() + "," +
|
||||||
|
"\"rebind-timer\": 2000, "
|
||||||
|
"\"renew-timer\": 1000, "
|
||||||
|
"\"subnet4\": [ { "
|
||||||
|
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
|
||||||
|
" \"subnet\": \"192.0.2.0/24\","
|
||||||
|
" \"4o6-subnet\": \"2001:db8::543/21\","
|
||||||
|
" \"4o6-interface\": \"ethX\" } ],"
|
||||||
|
"\"valid-lifetime\": 4000 }";
|
||||||
|
|
||||||
|
ElementPtr json = Element::fromJSON(config);
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
|
||||||
|
|
||||||
|
// check if returned status is OK
|
||||||
|
checkResult(status, 0);
|
||||||
|
|
||||||
|
// Now check if the configuration was indeed handled and we have
|
||||||
|
// expected pool configured.
|
||||||
|
Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->
|
||||||
|
getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
|
||||||
|
ASSERT_TRUE(subnet);
|
||||||
|
|
||||||
|
Cfg4o6& dhcp4o6 = subnet->get4o6();
|
||||||
|
EXPECT_TRUE(dhcp4o6.enabled_);
|
||||||
|
EXPECT_EQ(IOAddress("2001:db8::543"), dhcp4o6.subnet4o6_.first);
|
||||||
|
EXPECT_EQ(21, dhcp4o6.subnet4o6_.second);
|
||||||
|
EXPECT_EQ("ethX", dhcp4o6.iface4o6_);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -507,6 +507,29 @@ private:
|
|||||||
/// @brief A generic pointer to either Subnet4 or Subnet6 object
|
/// @brief A generic pointer to either Subnet4 or Subnet6 object
|
||||||
typedef boost::shared_ptr<Subnet> SubnetPtr;
|
typedef boost::shared_ptr<Subnet> SubnetPtr;
|
||||||
|
|
||||||
|
/// @brief This structure contains information about DHCP4o6 (RFC7341)
|
||||||
|
///
|
||||||
|
/// DHCP4o6 is completely optional. If it is not enabled, this structure
|
||||||
|
/// does not contain any information.
|
||||||
|
struct Cfg4o6 {
|
||||||
|
|
||||||
|
/// the default constructor.
|
||||||
|
///
|
||||||
|
/// Initializes fields to their default value.
|
||||||
|
Cfg4o6()
|
||||||
|
:enabled_(false), subnet4o6_(std::make_pair(asiolink::IOAddress("::"), 128u)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Specifies if 4o6 is enabled on this subnet.
|
||||||
|
bool enabled_;
|
||||||
|
|
||||||
|
/// Specifies the network interface used as subnet selector
|
||||||
|
std::string iface4o6_;
|
||||||
|
|
||||||
|
/// Specifies the IPv6 subnet used for subnet selection
|
||||||
|
std::pair<asiolink::IOAddress, uint8_t> subnet4o6_;
|
||||||
|
};
|
||||||
|
|
||||||
/// @brief A configuration holder for IPv4 subnet.
|
/// @brief A configuration holder for IPv4 subnet.
|
||||||
///
|
///
|
||||||
/// This class represents an IPv4 subnet.
|
/// This class represents an IPv4 subnet.
|
||||||
@@ -559,6 +582,14 @@ public:
|
|||||||
return (match_client_id_);
|
return (match_client_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Returns DHCP4o6 configuration parameters.
|
||||||
|
///
|
||||||
|
/// This structure is always available. If the 4o6 is not enabled, its
|
||||||
|
/// enabled_ field will be set to false.
|
||||||
|
Cfg4o6& get4o6() {
|
||||||
|
return (dhcp4o6_);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// @brief Returns default address for pool selection
|
/// @brief Returns default address for pool selection
|
||||||
@@ -581,6 +612,10 @@ private:
|
|||||||
/// @brief Should server use client identifiers for client lease
|
/// @brief Should server use client identifiers for client lease
|
||||||
/// lookup.
|
/// lookup.
|
||||||
bool match_client_id_;
|
bool match_client_id_;
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief All the information related to DHCP4o6
|
||||||
|
Cfg4o6 dhcp4o6_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief A pointer to a @c Subnet4 object
|
/// @brief A pointer to a @c Subnet4 object
|
||||||
|
Reference in New Issue
Block a user