Kea  1.9.9-git
base_host_data_source.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef BASE_HOST_DATA_SOURCE_H
8 #define BASE_HOST_DATA_SOURCE_H
9 
10 #include <asiolink/io_address.h>
12 #include <dhcpsrv/host.h>
13 #include <exceptions/exceptions.h>
14 #include <boost/shared_ptr.hpp>
15 
16 #include <vector>
17 
18 namespace isc {
19 namespace dhcp {
20 
22 class DuplicateHost : public Exception {
23 public:
24  DuplicateHost(const char* file, size_t line, const char* what) :
25  isc::Exception(file, line, what) { };
26 };
27 
30 class ReservedAddress : public Exception {
31 public:
32  ReservedAddress(const char* file, size_t line, const char* what) :
33  isc::Exception(file, line, what) { };
34 };
35 
38 class BadHostAddress : public isc::BadValue {
39 public:
40  BadHostAddress(const char* file, size_t line, const char* what) :
41  isc::BadValue(file, line, what) { };
42 };
43 
45 class HostPageSize {
46 public:
47 
53  explicit HostPageSize(const size_t page_size) : page_size_(page_size) {
54  if (page_size_ == 0) {
55  isc_throw(OutOfRange, "page size of retrieved hosts must not be 0");
56  }
57  if (page_size_ > std::numeric_limits<uint32_t>::max()) {
58  isc_throw(OutOfRange, "page size of retrieved hosts must not be greate than "
59  << std::numeric_limits<uint32_t>::max());
60  }
61  }
62 
63  const size_t page_size_;
64 };
65 
81 public:
82 
92  enum IdType {
93  ID_HWADDR = 0,
94  ID_DUID = 1
95  };
96 
98  virtual ~BaseHostDataSource() { }
99 
113  virtual ConstHostCollection
114  getAll(const Host::IdentifierType& identifier_type,
115  const uint8_t* identifier_begin,
116  const size_t identifier_len) const = 0;
117 
126  virtual ConstHostCollection
127  getAll4(const SubnetID& subnet_id) const = 0;
128 
137  virtual ConstHostCollection
138  getAll6(const SubnetID& subnet_id) const = 0;
139 
152  virtual ConstHostCollection
153  getAllbyHostname(const std::string& hostname) const = 0;
154 
164  virtual ConstHostCollection
165  getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const = 0;
166 
176  virtual ConstHostCollection
177  getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const = 0;
178 
196  virtual ConstHostCollection
197  getPage4(const SubnetID& subnet_id,
198  size_t& source_index,
199  uint64_t lower_host_id,
200  const HostPageSize& page_size) const = 0;
201 
219  virtual ConstHostCollection
220  getPage6(const SubnetID& subnet_id,
221  size_t& source_index,
222  uint64_t lower_host_id,
223  const HostPageSize& page_size) const = 0;
224 
241  virtual ConstHostCollection
242  getPage4(size_t& source_index,
243  uint64_t lower_host_id,
244  const HostPageSize& page_size) const = 0;
245 
262  virtual ConstHostCollection
263  getPage6(size_t& source_index,
264  uint64_t lower_host_id,
265  const HostPageSize& page_size) const = 0;
266 
275  virtual ConstHostCollection
276  getAll4(const asiolink::IOAddress& address) const = 0;
277 
288  virtual ConstHostPtr
289  get4(const SubnetID& subnet_id,
290  const Host::IdentifierType& identifier_type,
291  const uint8_t* identifier_begin,
292  const size_t identifier_len) const = 0;
293 
310  virtual ConstHostPtr
311  get4(const SubnetID& subnet_id,
312  const asiolink::IOAddress& address) const = 0;
313 
337  virtual ConstHostCollection
338  getAll4(const SubnetID& subnet_id,
339  const asiolink::IOAddress& address) const = 0;
340 
351  virtual ConstHostPtr
352  get6(const SubnetID& subnet_id,
353  const Host::IdentifierType& identifier_type,
354  const uint8_t* identifier_begin,
355  const size_t identifier_len) const = 0;
356 
363  virtual ConstHostPtr
364  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const = 0;
365 
373  virtual ConstHostPtr
374  get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const = 0;
375 
399  virtual ConstHostCollection
400  getAll6(const SubnetID& subnet_id,
401  const asiolink::IOAddress& address) const = 0;
402 
413  virtual void add(const HostPtr& host) = 0;
414 
423  virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) = 0;
424 
436  virtual bool del4(const SubnetID& subnet_id,
437  const Host::IdentifierType& identifier_type,
438  const uint8_t* identifier_begin, const size_t identifier_len) = 0;
439 
451  virtual bool del6(const SubnetID& subnet_id,
452  const Host::IdentifierType& identifier_type,
453  const uint8_t* identifier_begin, const size_t identifier_len) = 0;
454 
460  virtual std::string getType() const = 0;
461 
469  };
470 
475  virtual void commit() {};
476 
481  virtual void rollback() {};
482 
501  virtual bool setIPReservationsUnique(const bool unique) = 0;
502 
508  virtual bool isUnusable() {
509  return (false);
510  }
511 };
512 
514 typedef boost::shared_ptr<BaseHostDataSource> HostDataSourcePtr;
515 
517 typedef std::vector<HostDataSourcePtr> HostDataSourceList;
518 
519 }
520 }
521 
522 #endif // BASE_HOST_DATA_SOURCE_H
virtual isc::db::DatabaseConnection::ParameterMap getParameters() const
Return backend parameters.
virtual bool setIPReservationsUnique(const bool unique)=0
Controls whether IP reservations are unique or non-unique.
virtual std::string getType() const =0
Return backend type.
Wraps value holding size of the page with host reservations.
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const =0
Return all hosts with a hostname in a DHCPv4 subnet.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
IdType
Specifies the type of an identifier.
virtual bool isUnusable()
Flag which indicates if the host manager has at least one unusable connection.
const size_t page_size_
Holds page size.
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const =0
Return all hosts with a hostname in a DHCPv6 subnet.
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const =0
Return all hosts in a DHCPv4 subnet.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
HostPageSize(const size_t page_size)
Constructor.
virtual bool del4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)=0
Attempts to delete a host by (subnet-id4, identifier, identifier-type)
virtual ConstHostCollection getPage6(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const =0
Returns range of hosts in a DHCPv6 subnet.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)=0
Attempts to delete hosts by (subnet-id, address)
DuplicateHost(const char *file, size_t line, const char *what)
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:791
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:788
virtual ConstHostCollection getAll(const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const =0
Return all hosts connected to any subnet for which reservations have been made using a specified iden...
virtual void rollback()
Rollback Transactions.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
virtual ConstHostPtr get4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const =0
Returns a host connected to the IPv4 subnet.
virtual bool del6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)=0
Attempts to delete a host by (subnet-id6, identifier, identifier-type)
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual ConstHostPtr get6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const =0
Returns a host connected to the IPv6 subnet.
ReservedAddress(const char *file, size_t line, const char *what)
Exception thrown when the duplicate Host object is detected.
virtual void commit()
Commit Transactions.
Base interface for the classes implementing simple data source for host reservations.
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
virtual ~BaseHostDataSource()
Default destructor implementation.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Exception thrown when invalid IP address has been specified for Host.
BadHostAddress(const char *file, size_t line, const char *what)
IdentifierType
Type of the host identifier.
Definition: host.h:307
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
virtual void add(const HostPtr &host)=0
Adds a new host to the collection.
Exception thrown when an address is already reserved by a Host object (DuplicateHost is same identity...
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const =0
Return all hosts with a hostname.
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const =0
Return all hosts in a DHCPv6 subnet.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
virtual ConstHostCollection getPage4(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const =0
Returns range of hosts in a DHCPv4 subnet.