Kea 2.7.5
allocator.h
Go to the documentation of this file.
1// Copyright (C) 2022-2024 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 ALLOCATOR_H
8#define ALLOCATOR_H
9
10#include <asiolink/io_address.h>
11#include <dhcp/classify.h>
12#include <dhcp/duid.h>
14#include <dhcpsrv/lease.h>
15#include <dhcpsrv/subnet_id.h>
16#include <dhcpsrv/pool.h>
18#include <boost/shared_ptr.hpp>
19#include <boost/weak_ptr.hpp>
20#include <mutex>
21
22namespace isc {
23namespace dhcp {
24
29class Subnet;
30
32typedef boost::weak_ptr<Subnet> WeakSubnetPtr;
33
36class AllocFailed : public Exception {
37public:
38
44 AllocFailed(const char* file, size_t line, const char* what)
45 : Exception(file, line, what) {}
46};
47
57class Allocator {
58public:
59
62 PREFIX_LEN_EQUAL, // select PD-pools with specific prefix length
63 PREFIX_LEN_LOWER, // select PD-pools with lower prefix length
64 PREFIX_LEN_HIGHER // select PD-pools with higher prefix length
65 };
66
74 Allocator(Lease::Type type, const WeakSubnetPtr& subnet);
75
79 virtual ~Allocator();
80
84 virtual std::string getType() const = 0;
85
102 pickAddress(const ClientClasses& client_classes,
103 const IdentifierBaseTypePtr& duid,
104 const asiolink::IOAddress& hint) {
106 return (pickAddressInternal(client_classes, duid, hint));
107 }
108
131 pickPrefix(const ClientClasses& client_classes,
132 Pool6Ptr& pool,
133 const IdentifierBaseTypePtr& duid,
134 PrefixLenMatchType prefix_length_match,
135 const asiolink::IOAddress& hint,
136 uint8_t hint_prefix_length) {
138 return (pickPrefixInternal(client_classes, pool, duid,
139 prefix_length_match, hint,
140 hint_prefix_length));
141 }
142
153 static bool isValidPrefixPool(Allocator::PrefixLenMatchType prefix_length_match,
154 PoolPtr pool, uint8_t hint_prefix_length);
155
164 void initAfterConfigure();
165
166protected:
167
173
174private:
175
188 pickAddressInternal(const ClientClasses& client_classes,
189 const IdentifierBaseTypePtr& duid,
190 const isc::asiolink::IOAddress& hint) = 0;
191
210 pickPrefixInternal(const ClientClasses& client_classes,
211 Pool6Ptr& pool,
212 const IdentifierBaseTypePtr& duid,
213 PrefixLenMatchType prefix_length_match,
214 const isc::asiolink::IOAddress& hint,
215 uint8_t hint_prefix_length) = 0;
216
217protected:
218
224
227
230
233
235 std::mutex mutex_;
236};
237
239typedef boost::shared_ptr<Allocator> AllocatorPtr;
240
241} // end of namespace isc::dhcp
242} // end of namespace isc
243
244#endif // ALLOCATOR_H
Defines elements for storing the names of client classes.
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.
An exception that is thrown when allocation module fails (e.g.
Definition allocator.h:36
AllocFailed(const char *file, size_t line, const char *what)
Constructor.
Definition allocator.h:44
Base class for all address/prefix allocation algorithms.
Definition allocator.h:57
void initAfterConfigure()
Performs allocator initialization after server's reconfiguration.
Definition allocator.cc:68
virtual isc::asiolink::IOAddress pickAddress(const ClientClasses &client_classes, const IdentifierBaseTypePtr &duid, const asiolink::IOAddress &hint)
Picks an address.
Definition allocator.h:102
SubnetID subnet_id_
ID of a subnet to which the allocator belongs.
Definition allocator.h:229
virtual void initAfterConfigureInternal()
Allocator-specific initialization function.
Definition allocator.h:172
Lease::Type pool_type_
Defines pool type allocation.
Definition allocator.h:226
PrefixLenMatchType
Type of preferred PD-pool prefix length selection criteria.
Definition allocator.h:61
std::mutex mutex_
The mutex to protect the allocated lease.
Definition allocator.h:235
bool inited_
Indicates if the allocator has been initialized.
Definition allocator.h:223
virtual isc::asiolink::IOAddress pickPrefix(const ClientClasses &client_classes, Pool6Ptr &pool, const IdentifierBaseTypePtr &duid, PrefixLenMatchType prefix_length_match, const asiolink::IOAddress &hint, uint8_t hint_prefix_length)
Picks a delegated prefix.
Definition allocator.h:131
Allocator(Lease::Type type, const WeakSubnetPtr &subnet)
Constructor.
Definition allocator.cc:17
virtual ~Allocator()
Virtual destructor.
Definition allocator.cc:27
WeakSubnetPtr subnet_
Weak pointer to the subnet owning the allocator.
Definition allocator.h:232
virtual std::string getType() const =0
Returns allocator type string.
static bool isValidPrefixPool(Allocator::PrefixLenMatchType prefix_length_match, PoolPtr pool, uint8_t hint_prefix_length)
Check if the pool matches the selection criteria relative to the provided hint prefix length.
Definition allocator.cc:38
Container for storing client class names.
Definition classify.h:108
boost::weak_ptr< Subnet > WeakSubnetPtr
Weak pointer to the Subnet.
Definition allocator.h:32
boost::shared_ptr< IdentifierBaseType > IdentifierBaseTypePtr
Shared pointer to a IdentifierType.
Definition duid.h:34
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:488
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< Allocator > AllocatorPtr
Defines a pointer to an allocator.
Definition allocator.h:239
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Definition pool.h:298
Defines the logger used by the top-level component of kea-lfc.
Type
Type of lease or pool.
Definition lease.h:46
RAII lock object to protect the code in the same scope with a mutex.