bool
CfgHosts::del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) {
- size_t erased_host_count = 0;
- size_t erased_reservation_count = 0;
+ size_t erased_hosts = 0;
+ size_t erased_addresses = 0;
if (addr.isV4()) {
+ // Delete IPv4 reservation and host.
HostContainerIndex1& idx = hosts_.get<1>();
- erased_host_count = idx.erase(addr);
- erased_reservation_count = erased_host_count;
+ erased_hosts = idx.erase(addr);
+ erased_addresses = erased_hosts;
} else {
HostContainer6Index1& idx6 = hosts6_.get<1>();
HostContainerIndex4& idx = hosts_.get<4>();
+ // Delete IPv6 reservations.
const auto& range = idx6.equal_range(boost::make_tuple(subnet_id, addr));
idx6.erase(range.first, range.second);
+ erased_addresses = boost::distance(range.first, range.second);
+ // Delete hosts.
for (auto key = range.first; key != range.second; ++key) {
- erased_reservation_count++;
- erased_host_count += idx.erase(key->host_->getHostId());
+ erased_hosts += idx.erase(key->host_->getHostId());
}
}
- // ToDo: Log message.
+ LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_DEL)
+ .arg(erased_hosts)
+ .arg(erased_addresses)
+ .arg(subnet_id)
+ .arg(addr.toText());
- return (erased_host_count != 0);
+ return (erased_hosts != 0);
}
size_t
extern const isc::log::MessageID HOSTS_CFG_ADD_HOST = "HOSTS_CFG_ADD_HOST";
extern const isc::log::MessageID HOSTS_CFG_CACHE_HOST_DATA_SOURCE = "HOSTS_CFG_CACHE_HOST_DATA_SOURCE";
extern const isc::log::MessageID HOSTS_CFG_CLOSE_HOST_DATA_SOURCE = "HOSTS_CFG_CLOSE_HOST_DATA_SOURCE";
+extern const isc::log::MessageID HOSTS_CFG_DEL = "HOSTS_CFG_DEL";
extern const isc::log::MessageID HOSTS_CFG_DEL_ALL_SUBNET4 = "HOSTS_CFG_DEL_ALL_SUBNET4";
extern const isc::log::MessageID HOSTS_CFG_DEL_ALL_SUBNET6 = "HOSTS_CFG_DEL_ALL_SUBNET6";
extern const isc::log::MessageID HOSTS_CFG_GET_ALL = "HOSTS_CFG_GET_ALL";
"HOSTS_CFG_ADD_HOST", "add the host for reservations: %1",
"HOSTS_CFG_CACHE_HOST_DATA_SOURCE", "get host cache data source: %1",
"HOSTS_CFG_CLOSE_HOST_DATA_SOURCE", "Closing host data source: %1",
+ "HOSTS_CFG_DEL", "deleted %1 host(s) having %2 IPv6 reservation(s) for subnet id %3 and address %4",
"HOSTS_CFG_DEL_ALL_SUBNET4", "deleted all %1 host(s) for subnet id %2",
"HOSTS_CFG_DEL_ALL_SUBNET6", "deleted all %1 host(s) having %2 IPv6 reservation(s) for subnet id %3",
"HOSTS_CFG_GET_ALL", "get all hosts with reservations",
extern const isc::log::MessageID HOSTS_CFG_ADD_HOST;
extern const isc::log::MessageID HOSTS_CFG_CACHE_HOST_DATA_SOURCE;
extern const isc::log::MessageID HOSTS_CFG_CLOSE_HOST_DATA_SOURCE;
+extern const isc::log::MessageID HOSTS_CFG_DEL;
extern const isc::log::MessageID HOSTS_CFG_DEL_ALL_SUBNET4;
extern const isc::log::MessageID HOSTS_CFG_DEL_ALL_SUBNET6;
extern const isc::log::MessageID HOSTS_CFG_GET_ALL;
This is a normal message being printed when the server closes host data
source connection.
+% HOSTS_CFG_DEL deleted %1 host(s) having %2 IPv6 reservation(s) for subnet id %3 and address %4
+This debug message is issued when reservations are deleted for the specified
+subnet and address. The first argument specifies how many hosts have been
+deleted. The second argument specifies how many reservations have been deleted.
+The third argument is the subnet identifier. The fourth argument is the IP
+address.
+
% HOSTS_CFG_DEL_ALL_SUBNET4 deleted all %1 host(s) for subnet id %2
This debug message is issued when all IPv4 reservations are deleted for
the specified subnet. The first argument specifies how many reservations
This debug message is issued when all IPv6 reservations are deleted for
the specified subnet. The first argument specifies how many hosts
have been deleted. The second argument specifies how many IPv6
-(addresses and prefixes) have been deleted. The third argument is the
-subnet identifier.
+(addresses and prefixes) reservations have been deleted. The third argument is
+the subnet identifier.
% HOSTS_CFG_GET_ALL get all hosts with reservations
This debug message is issued when starting to retrieve all hosts.
for (size_t i = 0; i < host_count; i++)
{
- std::ostringstream s;
- s << "hostname" << i;
-
cfg.add(HostPtr(new Host(hwaddrs_[i]->toText(false),
"hw-address",
subnet_id, SUBNET_ID_UNUSED,
- increase(address, i), s.str())));
+ increase(address, i))));
}
// Get all inserted hosts.
for (size_t i = 0; i < host_count; i++)
{
- std::ostringstream s;
- s << "hostname" << i;
-
HostPtr host = HostPtr(new Host(duids_[i]->toText(), "duid",
SUBNET_ID_UNUSED, subnet_id,
- IOAddress("0.0.0.0"),
- s.str()));
+ IOAddress("0.0.0.0")));
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
increase(IOAddress(address), i)));
cfg.add(host);
auto hostsBySubnetAndAddress = cfg.getAll6(subnet_id, address);
auto hostsBySubnet = cfg.getAll6(subnet_id);
// Make sure the hosts and IP reservations were added.
- EXPECT_EQ(1, hostsBySubnetAndAddress.size());
+ ASSERT_EQ(1, hostsBySubnetAndAddress.size());
ASSERT_EQ(host_count, hostsBySubnet.size());
// Delete one host.
EXPECT_EQ(host_count-1, hostsBySubnet.size());
}
+// This test checks that false is returned for deleting the IPv4 reservation
+// that doesn't exist.
+TEST_F(CfgHostsTest, deleteForMissingIPv4) {
+ CfgHosts cfg;
+
+ // Delete non-existent host.
+ EXPECT_FALSE(cfg.del(SubnetID(42), IOAddress(("10.0.0.42"))));
+}
+
+// This test checks that false is returned for deleting the IPv6 reservation
+// that doesn't exist.
+TEST_F(CfgHostsTest, deleteForMissingIPv6) {
+ CfgHosts cfg;
+
+ // Delete non-existent host.
+ EXPECT_FALSE(cfg.del(SubnetID(42), IOAddress(("2001:db8:1::1"))));
+}
+
// This test checks that all reservations for the specified IPv4 subnet can
// be deleted.
TEST_F(CfgHostsTest, deleteAll4) {