Kea 2.2.0
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>
14#include <boost/shared_ptr.hpp>
15
16#include <vector>
17
18namespace isc {
19namespace dhcp {
20
22class DuplicateHost : public Exception {
23public:
24 DuplicateHost(const char* file, size_t line, const char* what) :
25 isc::Exception(file, line, what) { };
26};
27
30class ReservedAddress : public Exception {
31public:
32 ReservedAddress(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) { };
34};
35
39public:
40 BadHostAddress(const char* file, size_t line, const char* what) :
41 isc::BadValue(file, line, what) { };
42};
43
46public:
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
81public:
82
92 enum IdType {
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
514typedef boost::shared_ptr<BaseHostDataSource> HostDataSourcePtr;
515
517typedef std::vector<HostDataSourcePtr> HostDataSourceList;
518
519}
520}
521
522#endif // BASE_HOST_DATA_SOURCE_H
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown when invalid IP address has been specified for Host.
BadHostAddress(const char *file, size_t line, const char *what)
Base interface for the classes implementing simple data source for host reservations.
virtual std::string getType() const =0
Return backend type.
virtual bool isUnusable()
Flag which indicates if the host manager has at least one unusable connection.
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const =0
Return all hosts with a hostname in a DHCPv6 subnet.
virtual void add(const HostPtr &host)=0
Adds a new host to the collection.
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const =0
Return all hosts in a DHCPv6 subnet.
virtual void commit()
Commit Transactions.
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const =0
Return all hosts with a hostname in a DHCPv4 subnet.
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)=0
Attempts to delete hosts by (subnet-id, address)
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.
virtual ConstHostPtr get4(const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.
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 ConstHostCollection getAll4(const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
Returns all hosts connected to the IPv4 subnet and having a reservation for a specified address.
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)
virtual bool setIPReservationsUnique(const bool unique)=0
Controls whether IP reservations are unique or non-unique.
virtual ConstHostPtr get6(const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
Returns a host connected to the IPv6 subnet and having a reservation for a specified IPv6 address or ...
virtual isc::db::DatabaseConnection::ParameterMap getParameters() const
Return backend parameters.
IdType
Specifies the type of an identifier.
virtual ConstHostCollection getPage6(size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const =0
Returns range of hosts.
virtual ConstHostCollection getAll4(const asiolink::IOAddress &address) const =0
Returns a collection of hosts using the specified IPv4 address.
virtual ConstHostCollection getPage4(size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const =0
Returns range of hosts.
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.
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.
virtual ConstHostPtr get6(const asiolink::IOAddress &prefix, const uint8_t prefix_len) const =0
Returns a host using the specified IPv6 prefix.
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const =0
Return all hosts with a hostname.
virtual ConstHostCollection getAll6(const SubnetID &subnet_id, const asiolink::IOAddress &address) const =0
Returns all hosts connected to the IPv6 subnet and having a reservation for a specified address or de...
virtual ~BaseHostDataSource()
Default destructor implementation.
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 ConstHostCollection getAll4(const SubnetID &subnet_id) const =0
Return all hosts in a DHCPv4 subnet.
Exception thrown when the duplicate Host object is detected.
DuplicateHost(const char *file, size_t line, const char *what)
Wraps value holding size of the page with host reservations.
const size_t page_size_
Holds page size.
HostPageSize(const size_t page_size)
Constructor.
IdentifierType
Type of the host identifier.
Definition: host.h:307
Exception thrown when an address is already reserved by a Host object (DuplicateHost is same identity...
ReservedAddress(const char *file, size_t line, const char *what)
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:791
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:788
Defines the logger used by the top-level component of kea-lfc.