123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- // Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
- //
- // Permission to use, copy, modify, and/or distribute this software for any
- // purpose with or without fee is hereby granted, provided that the above
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- #ifndef BASE_HOST_DATA_SOURCE_H
- #define BASE_HOST_DATA_SOURCE_H
- #include <asiolink/io_address.h>
- #include <dhcp/duid.h>
- #include <dhcp/hwaddr.h>
- #include <dhcpsrv/host.h>
- #include <exceptions/exceptions.h>
- namespace isc {
- namespace dhcp {
- /// @brief Exception thrown when the duplicate @c Host object is detected.
- class DuplicateHost : public Exception {
- public:
- DuplicateHost(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) { };
- };
- /// @brief Base interface for the classes implementing simple data source
- /// for host reservations.
- ///
- /// This abstract class defines an interface for the classes implementing
- /// basic data source for host reservations. This interface allows for
- /// adding new reservations (represented by @c Host objects) and retrieving
- /// these reservations using various parameters such as HW address or DUID,
- /// subnet identifier (either IPv4 or IPv6) or reserved IP address.
- ///
- /// This interface DOES NOT specify the methods to manage existing
- /// host reservations such as to remove one IPv6 reservation but leave
- /// other reservations. It also lacks the methods used for preparing
- /// the data to be added to the SQL database: commit, rollback etc.
- /// Such methods are declared in other interfaces.
- class BaseHostDataSource {
- public:
- /// @brief Default destructor implementation.
- virtual ~BaseHostDataSource() {
- }
- /// @brief Return all hosts for the specified HW address or DUID.
- ///
- /// This method returns all @c Host objects which represent reservations
- /// for the specified HW address or DUID. Note, that this method may
- /// return multiple reservations because a particular client may have
- /// reservations in multiple subnets and the same client may be identified
- /// by HW address or DUID. The server is unable to verify that the specific
- /// DUID and HW address belong to the same client, until the client sends
- /// a DHCP message.
- ///
- /// Specifying both hardware address and DUID is allowed for this method
- /// and results in returning all objects that are associated with hardware
- /// address OR duid. For example: if one host is associated with the
- /// specified hardware address and another host is associated with the
- /// specified DUID, two hosts will be returned.
- ///
- /// @param hwaddr HW address of the client or NULL if no HW address
- /// available.
- /// @param duid client id or NULL if not available, e.g. DHCPv4 client case.
- ///
- /// @return Collection of const @c Host objects.
- virtual ConstHostCollection
- getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const = 0;
- /// @brief Returns a collection of hosts using the specified IPv4 address.
- ///
- /// This method may return multiple @c Host objects if they are connected
- /// to different subnets.
- ///
- /// @param address IPv4 address for which the @c Host object is searched.
- ///
- /// @return Collection of const @c Host objects.
- virtual ConstHostCollection
- getAll4(const asiolink::IOAddress& address) const = 0;
- /// @brief Returns a host connected to the IPv4 subnet.
- ///
- /// Implementations of this method should guard against the case when
- /// mutliple instances of the @c Host are present, e.g. when two
- /// @c Host objects are found, one for the DUID, another one for the
- /// HW address. In such case, an implementation of this method
- /// should throw an exception.
- ///
- /// @param subnet_id Subnet identifier.
- /// @param hwaddr HW address of the client or NULL if no HW address
- /// available.
- /// @param duid client id or NULL if not available.
- ///
- /// @return Const @c Host object using a specified HW address or DUID.
- virtual ConstHostPtr
- get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
- const DuidPtr& duid = DuidPtr()) const = 0;
- /// @brief Returns a host connected to the IPv6 subnet.
- ///
- /// Implementations of this method should guard against the case when
- /// mutliple instances of the @c Host are present, e.g. when two
- /// @c Host objects are found, one for the DUID, another one for the
- /// HW address. In such case, an implementation of this method
- /// should throw an exception.
- ///
- /// @param subnet_id Subnet identifier.
- /// @param hwaddr HW address of the client or NULL if no HW address
- /// available.
- /// @param duid DUID or NULL if not available.
- ///
- /// @return Const @c Host object using a specified HW address or DUID.
- virtual ConstHostPtr
- get6(const SubnetID& subnet_id, const DuidPtr& duid,
- const HWAddrPtr& hwaddr = HWAddrPtr()) const = 0;
- /// @brief Returns a host using the specified IPv6 prefix.
- ///
- /// @param prefix IPv6 prefix for which the @c Host object is searched.
- /// @param prefix_len IPv6 prefix length.
- ///
- /// @return Const @c Host object using a specified HW address or DUID.
- virtual ConstHostPtr
- get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const = 0;
- /// @brief Adds a new host to the collection.
- ///
- /// The implementations of this method should guard against duplicate
- /// reservations for the same host, where possible. For example, when the
- /// reservation for the same HW address and subnet id is added twice, the
- /// implementation should throw an exception. Note, that usually it is
- /// impossible to guard against adding duplicated host, where one instance
- /// is identified by HW address, another one by DUID.
- ///
- /// @param host Pointer to the new @c Host object being added.
- virtual void add(const HostPtr& host) = 0;
- };
- }
- }
- #endif // BASE_HOST_DATA_SOURCE_H
|