/// the use of alternate datasources, e.g. as a result of server's
/// reconfiguration. However, the use of the primary host data source (i.e.
/// reservations specified in the configuration file) can't be disabled.
-class HostMgr : public boost::noncopyable, public BaseHostDataSource {
+class HostMgr : public boost::noncopyable {
public:
/// @brief Creates new instance of the @c HostMgr.
/// @param identifier_len Identifier length.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const;
/// @param subnet_id Subnet identifier.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAll4(const SubnetID& subnet_id) const;
/// @brief Return all hosts in a DHCPv6 subnet.
/// @param subnet_id Subnet identifier.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAll6(const SubnetID& subnet_id) const;
/// @brief Return all hosts with a hostname.
/// @param hostname The lower case hostname.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAllbyHostname(const std::string& hostname) const;
/// @brief Return all hosts with a hostname in a DHCPv4 subnet.
/// @param subnet_id Subnet identifier.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
/// @brief Return all hosts with a hostname in a DHCPv6 subnet.
/// @param subnet_id Subnet identifier.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
/// @brief Returns range of hosts in a DHCPv4 subnet.
/// @param page_size maximum size of the page returned.
///
/// @return Host collection (may be empty).
- virtual ConstHostCollection
+ ConstHostCollection
getPage4(const SubnetID& subnet_id,
size_t& source_index,
uint64_t lower_host_id,
/// @param page_size maximum size of the page returned.
///
/// @return Host collection (may be empty).
- virtual ConstHostCollection
+ ConstHostCollection
getPage6(const SubnetID& subnet_id,
size_t& source_index,
uint64_t lower_host_id,
/// @param page_size maximum size of the page returned.
///
/// @return Host collection (may be empty).
- virtual ConstHostCollection
+ ConstHostCollection
getPage4(size_t& source_index,
uint64_t lower_host_id,
const HostPageSize& page_size) const;
/// @param page_size maximum size of the page returned.
///
/// @return Host collection (may be empty).
- virtual ConstHostCollection
+ ConstHostCollection
getPage6(size_t& source_index,
uint64_t lower_host_id,
const HostPageSize& page_size) const;
/// @param address IPv4 address for which the @c Host object is searched.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAll4(const asiolink::IOAddress& address) const;
/// @brief Returns any host connected to the IPv4 subnet.
///
/// @return Const @c Host object for which reservation has been made using
/// the specified identifier.
- virtual ConstHostPtr
+ ConstHostPtr
get4Any(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
///
/// @return Const @c Host object for which reservation has been made using
/// the specified identifier.
- virtual ConstHostPtr
+ ConstHostPtr
get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const size_t identifier_len) const;
/// @param address reserved IPv4 address.
///
/// @return Const @c Host object using a specified IPv4 address.
- virtual ConstHostPtr
+ ConstHostPtr
get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
/// @brief Returns all hosts connected to the IPv4 subnet and having
/// @param address reserved IPv4 address.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAll4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const;
///
/// @return Const @c Host object for which reservation has been made using
/// the specified identifier.
- virtual ConstHostPtr
+ ConstHostPtr
get6Any(const SubnetID& subnet_id,
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
///
/// @return Const @c Host object for which reservation has been made using
/// the specified identifier.
- virtual ConstHostPtr
+ ConstHostPtr
get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const size_t identifier_len) const;
/// @param prefix_len IPv6 prefix length.
///
/// @return Const @c Host object using a specified IPv6 prefix.
- virtual ConstHostPtr
+ ConstHostPtr
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
/// @brief Returns a host from specific subnet and reserved address.
/// @param addr specified address.
///
/// @return Const @c host object that has a reservation for specified address.
- virtual ConstHostPtr
+ ConstHostPtr
get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const;
/// @brief Returns all hosts connected to the IPv6 subnet and having
/// @param address reserved IPv6 address/prefix.
///
/// @return Collection of const @c Host objects.
- virtual ConstHostCollection
+ ConstHostCollection
getAll6(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const;
/// in use.
///
/// @param host Pointer to the new @c Host object being added.
- virtual void add(const HostPtr& host);
+ void add(const HostPtr& host);
/// @brief Attempts to delete hosts by address.
///
/// @param subnet_id subnet identifier.
/// @param addr specified address.
/// @return true if deletion was successful, false otherwise.
- virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
+ bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
/// @brief Attempts to delete a host by (subnet4-id, identifier, identifier-type)
///
/// an identifier.
/// @param identifier_len Identifier length.
/// @return true if deletion was successful, false otherwise.
- virtual bool
+ bool
del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const size_t identifier_len);
/// an identifier.
/// @param identifier_len Identifier length.
/// @return true if deletion was successful, false otherwise.
- virtual bool
+ bool
del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin, const size_t identifier_len);
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
///
/// @return Type of the backend.
- virtual std::string getType() const {
+ std::string getType() const {
return (std::string("host_mgr"));
}
/// unique or can be non-unique.
/// @return true if the new setting was accepted by the backend or false
/// otherwise.
- virtual bool setIPReservationsUnique(const bool unique);
+ bool setIPReservationsUnique(const bool unique);
/// @brief Returns the boolean flag indicating if the IP reservations
/// must be unique or can be non-unique.
/// @brief Cache an answer.
///
/// @param host Pointer to the missed host.
- virtual void cache(ConstHostPtr host) const;
+ void cache(ConstHostPtr host) const;
/// @brief Cache a negative answer.
///
/// @param identifier_type Identifier type.
/// @param identifier_begin Pointer to a beginning of the Identifier.
/// @param identifier_len Identifier length.
- virtual void cacheNegative(const SubnetID& ipv4_subnet_id,
+ void cacheNegative(const SubnetID& ipv4_subnet_id,
const SubnetID& ipv6_subnet_id,
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
}
void
-HostMgrTest::addHost4(BaseHostDataSource& data_source,
+HostMgrTest::addHost4(BaseHostDataSource& host_manager,
const HWAddrPtr& hwaddr,
const SubnetID& subnet_id,
const IOAddress& address) {
- data_source.add(HostPtr(new Host(hwaddr->toText(false),
+ host_manager.add(HostPtr(new Host(hwaddr->toText(false),
+ "hw-address", subnet_id, SUBNET_ID_UNUSED,
+ address)));
+}
+
+void
+HostMgrTest::addHost4(HostMgr& host_manager,
+ const HWAddrPtr& hwaddr,
+ const SubnetID& subnet_id,
+ const IOAddress& address) {
+ host_manager.add(HostPtr(new Host(hwaddr->toText(false),
"hw-address", subnet_id, SUBNET_ID_UNUSED,
address)));
}
data_source.add(new_host);
}
+void
+HostMgrTest::addHost6(HostMgr& data_source,
+ const DuidPtr& duid,
+ const SubnetID& subnet_id,
+ const IOAddress& address,
+ const uint8_t prefix_len) {
+ HostPtr new_host(new Host(duid->toText(), "duid", SubnetID(1),
+ subnet_id, IOAddress::IPV4_ZERO_ADDRESS()));
+ new_host->addReservation(IPv6Resrv(prefix_len == 128 ? IPv6Resrv::TYPE_NA :
+ IPv6Resrv::TYPE_PD,
+ address, prefix_len));
+ data_source.add(new_host);
+}
void
HostMgrTest::testGetAll(BaseHostDataSource& data_source1,
void
HostMgrTest::testGetPage4(bool use_database) {
- BaseHostDataSource& data_source1 = *getCfgHosts();
- BaseHostDataSource& data_source2 = HostMgr::instance();
+ auto& data_source1 = *getCfgHosts();
+ auto& data_source2 = HostMgr::instance();
// Initially, no reservations should be present.
size_t idx(0);
// Add two reservations for the same subnet.
addHost4(data_source1, hwaddrs_[0], SubnetID(1), IOAddress("192.0.2.5"));
- addHost4(use_database ? data_source2 : data_source1,
- hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.6"));
+ if (use_database) {
+ addHost4(data_source2, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.6"));
+ } else {
+ addHost4(data_source1, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.6"));
+ }
CfgMgr::instance().commit();
void
HostMgrTest::testGetPage6(bool use_database) {
- BaseHostDataSource& data_source1 = *getCfgHosts();
- BaseHostDataSource& data_source2 = HostMgr::instance();
+ auto& data_source1 = *getCfgHosts();
+ auto& data_source2 = HostMgr::instance();
// Initially, no reservations should be present.
size_t idx(0);
// Add two reservations for the same subnet.
addHost6(data_source1, duids_[0], SubnetID(1), IOAddress("2001:db8:1::5"));
- addHost6(use_database ? data_source2 : data_source1,
- duids_[1], SubnetID(1), IOAddress("2001:db8:1::6"));
+ if (use_database) {
+ addHost6(data_source2,
+ duids_[1], SubnetID(1), IOAddress("2001:db8:1::6"));
+ } else {
+ addHost6(data_source1,
+ duids_[1], SubnetID(1), IOAddress("2001:db8:1::6"));
+ }
CfgMgr::instance().commit();
void
HostMgrTest::testGetPage4All(bool use_database) {
- BaseHostDataSource& data_source1 = *getCfgHosts();
- BaseHostDataSource& data_source2 = HostMgr::instance();
+ auto& data_source1 = *getCfgHosts();
+ auto& data_source2 = HostMgr::instance();
// Initially, no reservations should be present.
size_t idx(0);
// Add two reservations.
addHost4(data_source1, hwaddrs_[0], SubnetID(1), IOAddress("192.0.2.5"));
- addHost4(use_database ? data_source2 : data_source1,
+ if (use_database) {
+ addHost4(data_source2,
+ hwaddrs_[1], SubnetID(2), IOAddress("192.0.2.6"));
+ } else {
+ addHost4(data_source1,
hwaddrs_[1], SubnetID(2), IOAddress("192.0.2.6"));
+ }
CfgMgr::instance().commit();
void
HostMgrTest::testGetPage6All(bool use_database) {
- BaseHostDataSource& data_source1 = *getCfgHosts();
- BaseHostDataSource& data_source2 = HostMgr::instance();
+ auto& data_source1 = *getCfgHosts();
+ auto& data_source2 = HostMgr::instance();
// Initially, no reservations should be present.
size_t idx(0);
// Add two reservations.
addHost6(data_source1, duids_[0], SubnetID(1), IOAddress("2001:db8:1::5"));
- addHost6(use_database ? data_source2 : data_source1,
+ if (use_database) {
+ addHost6(data_source2,
+ duids_[1], SubnetID(2), IOAddress("2001:db8:1::6"));
+ } else {
+ addHost6(data_source1,
duids_[1], SubnetID(2), IOAddress("2001:db8:1::6"));
+ }
CfgMgr::instance().commit();
const SubnetID& subnet_id,
const isc::asiolink::IOAddress& address);
+ /// @brief Inserts IPv4 reservation into the host manager.
+ ///
+ /// @param host_manager Reference to the host manager to which the reservation
+ /// should be inserted.
+ /// @param hwaddr Pointer to the hardware address to be associated with the
+ /// reservation.
+ /// @param subnet_id IPv4 subnet id.
+ /// @param address IPv4 address to be reserved.
+ void addHost4(HostMgr& host_manager,
+ const HWAddrPtr& hwaddr,
+ const SubnetID& subnet_id,
+ const isc::asiolink::IOAddress& address);
+
/// @brief Inserts IPv6 reservation into the host data source.
///
/// @param data_source Reference to the data source to which the reservation
const isc::asiolink::IOAddress& address,
const uint8_t prefix_len = 128);
+/// @brief Inserts IPv6 reservation into the host manger.
+ ///
+ /// @param host_manager Reference to the host manager to which the
+ // reservation should be inserted.
+ /// @param duid Pointer to the DUID to be associated with the reservation.
+ /// @param subnet_id IPv6 subnet id.
+ /// @param address IPv6 address/prefix to be reserved.
+ /// @param prefix_len Prefix length. The default value is 128 which
+ /// indicates that the reservation is for an IPv6 address rather than a
+ /// prefix.
+ void addHost6(HostMgr& host_manager,
+ const DuidPtr& duid,
+ const SubnetID& subnet_id,
+ const isc::asiolink::IOAddress& address,
+ const uint8_t prefix_len = 128);
+
/// @brief This test verifies that HostMgr returns all reservations for the
/// specified HW address.
///