Kea  1.5.0
base_host_data_source.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2018 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>
11 #include <dhcpsrv/host.h>
12 #include <exceptions/exceptions.h>
13 #include <boost/shared_ptr.hpp>
14 
15 #include <vector>
16 
17 namespace isc {
18 namespace dhcp {
19 
21 class DuplicateHost : public Exception {
22 public:
23  DuplicateHost(const char* file, size_t line, const char* what) :
24  isc::Exception(file, line, what) { };
25 };
26 
29 class ReservedAddress : public Exception {
30 public:
31  ReservedAddress(const char* file, size_t line, const char* what) :
32  isc::Exception(file, line, what) { };
33 };
34 
37 class BadHostAddress : public isc::BadValue {
38 public:
39  BadHostAddress(const char* file, size_t line, const char* what) :
40  isc::BadValue(file, line, what) { };
41 };
42 
58 public:
59 
69  enum IdType {
70  ID_HWADDR = 0,
71  ID_DUID = 1
72  };
73 
75  virtual ~BaseHostDataSource() { }
76 
90  virtual ConstHostCollection
91  getAll(const Host::IdentifierType& identifier_type,
92  const uint8_t* identifier_begin,
93  const size_t identifier_len) const = 0;
94 
103  virtual ConstHostCollection
104  getAll4(const asiolink::IOAddress& address) const = 0;
105 
116  virtual ConstHostPtr
117  get4(const SubnetID& subnet_id,
118  const Host::IdentifierType& identifier_type,
119  const uint8_t* identifier_begin,
120  const size_t identifier_len) const = 0;
121 
138  virtual ConstHostPtr
139  get4(const SubnetID& subnet_id,
140  const asiolink::IOAddress& address) const = 0;
141 
152  virtual ConstHostPtr
153  get6(const SubnetID& subnet_id,
154  const Host::IdentifierType& identifier_type,
155  const uint8_t* identifier_begin,
156  const size_t identifier_len) const = 0;
157 
164  virtual ConstHostPtr
165  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const = 0;
166 
174  virtual ConstHostPtr
175  get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const =
176  0;
177 
188  virtual void add(const HostPtr& host) = 0;
189 
198  virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr) = 0;
199 
211  virtual bool del4(const SubnetID& subnet_id,
212  const Host::IdentifierType& identifier_type,
213  const uint8_t* identifier_begin, const size_t identifier_len) = 0;
214 
226  virtual bool del6(const SubnetID& subnet_id,
227  const Host::IdentifierType& identifier_type,
228  const uint8_t* identifier_begin, const size_t identifier_len) = 0;
229 
235  virtual std::string getType() const = 0;
236 
241  virtual void commit() {};
242 
247  virtual void rollback() {};
248 };
249 
251 typedef boost::shared_ptr<BaseHostDataSource> HostDataSourcePtr;
252 
254 typedef std::vector<HostDataSourcePtr> HostDataSourceList;
255 
256 }
257 }
258 
259 #endif // BASE_HOST_DATA_SOURCE_H
virtual std::string getType() const =0
Return backend type.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
IdType
Specifies the type of an identifier.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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)
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 a host 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:731
virtual ConstHostCollection getAll4(const asiolink::IOAddress &address) const =0
Returns a collection of hosts using the specified IPv4 address.
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:728
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 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.
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:252
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...
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24