void
CfgSubnets4::del(const ConstSubnet4Ptr& subnet) {
+ del(subnet->getID());
+}
+
+void
+CfgSubnets4::del(const SubnetID& subnet_id) {
auto& index = subnets_.get<SubnetSubnetIdIndexTag>();
- auto subnet_it = index.find(subnet->getID());
+ auto subnet_it = index.find(subnet_id);
if (subnet_it == index.end()) {
- isc_throw(BadValue, "no subnet with ID of '" << subnet->getID()
+ isc_throw(BadValue, "no subnet with ID of '" << subnet_id
<< "' found");
}
+
+ Subnet4Ptr subnet = *subnet_it;
+
index.erase(subnet_it);
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DEL_SUBNET4)
/// @throw isc::BadValue if such subnet doesn't exist.
void del(const ConstSubnet4Ptr& subnet);
+ /// @brief Removes subnet from the configuration.
+ ///
+ /// @param subnet_id Identifier of the subnet to be removed.
+ ///
+ /// @throw isc::BadValue if such subnet doesn't exist.
+ void del(const SubnetID& subnet_id);
+
/// @brief Merges specified subnet configuration into this configuration.
///
/// This method merges subnets from the @c other configuration into this
void
CfgSubnets6::del(const ConstSubnet6Ptr& subnet) {
+ del(subnet->getID());
+}
+
+void
+CfgSubnets6::del(const SubnetID& subnet_id) {
auto& index = subnets_.get<SubnetSubnetIdIndexTag>();
- auto subnet_it = index.find(subnet->getID());
+ auto subnet_it = index.find(subnet_id);
if (subnet_it == index.end()) {
- isc_throw(BadValue, "no subnet with ID of '" << subnet->getID()
+ isc_throw(BadValue, "no subnet with ID of '" << subnet_id
<< "' found");
}
+
+ Subnet6Ptr subnet = *subnet_it;
+
index.erase(subnet_it);
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DEL_SUBNET6)
/// @throw isc::BadValue if such subnet doesn't exist.
void del(const ConstSubnet6Ptr& subnet);
+ /// @brief Removes subnet from the configuration.
+ ///
+ /// @param subnet_id Identifier of the subnet to be removed.
+ ///
+ /// @throw isc::BadValue if such subnet doesn't exist.
+ void del(const SubnetID& subnet_id);
+
/// @brief Returns pointer to the collection of all IPv6 subnets.
///
/// This is used in a hook (subnet6_select), where the hook is able
ASSERT_NO_THROW(cfg.del(subnet2));
ASSERT_EQ(2, cfg.getAll()->size());
EXPECT_FALSE(cfg.getByPrefix("192.0.3.0/26"));
+
+ // Remove another subnet by ID.
+ ASSERT_NO_THROW(cfg.del(subnet1->getID()));
+ ASSERT_EQ(1, cfg.getAll()->size());
+ EXPECT_FALSE(cfg.getByPrefix("192.0.2.0/26"));
}
// This test verifies that subnets configuration is properly merged.
ASSERT_NO_THROW(cfg.del(subnet2));
ASSERT_EQ(2, cfg.getAll()->size());
EXPECT_FALSE(cfg.getByPrefix("2001:db8:2::/48"));
+
+ // Remove another subnet by ID.
+ ASSERT_NO_THROW(cfg.del(subnet1->getID()));
+ ASSERT_EQ(1, cfg.getAll()->size());
+ EXPECT_FALSE(cfg.getByPrefix("2001:db8:1::/48"));
}
// This test checks that the subnet can be selected using a relay agent's