Kea 2.7.5
pool.h
Go to the documentation of this file.
1// Copyright (C) 2012-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 POOL_H
8#define POOL_H
9
10#include <asiolink/io_address.h>
11#include <cc/data.h>
12#include <cc/user_context.h>
13#include <dhcp/classify.h>
16#include <dhcpsrv/cfg_option.h>
17#include <dhcpsrv/lease.h>
19#include <util/bigints.h>
20
21#include <boost/shared_ptr.hpp>
22
23#include <vector>
24
25namespace isc {
26namespace dhcp {
27
33
34public:
37
44 uint64_t getID() const {
45 return (id_);
46 }
47
54 void setID(const uint64_t id) {
55 id_ = id;
56 }
57
62 return (first_);
63 }
64
68 return (last_);
69 }
70
74 bool inRange(const isc::asiolink::IOAddress& addr) const;
75
79 return (type_);
80 }
81
85 virtual std::string toText() const;
86
92 virtual ~Pool() = default;
93
100 return (capacity_);
101 }
102
105 return (cfg_option_);
106 }
107
111 return (cfg_option_);
112 }
113
121 bool clientSupported(const ClientClasses& client_classes) const;
122
126 void allowClientClass(const ClientClass& class_name);
127
135 return (client_class_);
136 }
137
141 void addAdditionalClass(const ClientClass& class_name) {
142 if (!additional_classes_.contains(class_name)) {
143 additional_classes_.insert(class_name);
144 }
145 }
146
149 return (additional_classes_);
150 }
151
156
165
169 void setAllocationState(const AllocationStatePtr& allocation_state) {
170 allocation_state_ = allocation_state;
171 }
172
176 virtual data::ElementPtr toElement() const;
177
178protected:
179
189 Pool(Lease::Type type,
190 const isc::asiolink::IOAddress& first,
191 const isc::asiolink::IOAddress& last);
192
197 uint64_t id_;
198
201
204
207
215
218
223
228
231
234};
235
236class Pool4;
237
239typedef boost::shared_ptr<Pool4> Pool4Ptr;
240
245class Pool4 : public Pool {
246public:
251 Pool4(const isc::asiolink::IOAddress& first,
252 const isc::asiolink::IOAddress& last);
253
258 Pool4(const isc::asiolink::IOAddress& prefix,
259 uint8_t prefix_len);
260
272 static Pool4Ptr create(const isc::asiolink::IOAddress& first,
273 const isc::asiolink::IOAddress& last);
274
286 static Pool4Ptr create(const isc::asiolink::IOAddress& prefix,
287 uint8_t prefix_len);
288
292 virtual data::ElementPtr toElement() const;
293};
294
295class Pool6;
296
298typedef boost::shared_ptr<Pool6> Pool6Ptr;
299
304class Pool6 : public Pool {
305public:
306
314 Pool6(Lease::Type type, const isc::asiolink::IOAddress& first,
315 const isc::asiolink::IOAddress& last);
316
344 Pool6(Lease::Type type, const isc::asiolink::IOAddress& prefix,
345 uint8_t prefix_len, uint8_t delegated_len = 128);
346
359 Pool6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
360 const uint8_t delegated_len,
361 const asiolink::IOAddress& excluded_prefix,
362 const uint8_t excluded_prefix_len);
363
376 static Pool6Ptr create(Lease::Type type,
377 const isc::asiolink::IOAddress& first,
378 const isc::asiolink::IOAddress& last);
379
393 static Pool6Ptr create(Lease::Type type,
394 const isc::asiolink::IOAddress& prefix,
395 uint8_t prefix_len,
396 uint8_t delegated_len = 128);
397
412 static Pool6Ptr create(const asiolink::IOAddress& prefix,
413 const uint8_t prefix_len,
414 const uint8_t delegated_len,
415 const asiolink::IOAddress& excluded_prefix,
416 const uint8_t excluded_prefix_len);
417
422 return (type_);
423 }
424
430 uint8_t getLength() const {
431 return (prefix_len_);
432 }
433
439 return (pd_exclude_option_);
440 }
441
445 virtual data::ElementPtr toElement() const;
446
450 virtual std::string toText() const;
451
452private:
453
472 void init(const Lease::Type& type,
473 const asiolink::IOAddress& prefix,
474 const uint8_t prefix_len,
475 const uint8_t delegated_len,
476 const asiolink::IOAddress& excluded_prefix,
477 const uint8_t excluded_prefix_len);
478
480 uint8_t prefix_len_;
481
483 Option6PDExcludePtr pd_exclude_option_;
484
485};
486
488typedef boost::shared_ptr<Pool> PoolPtr;
489
491typedef std::vector<PoolPtr> PoolCollection;
492
493} // end of isc::dhcp namespace
494} // end of isc namespace
495
496#endif // POOL_H
Defines elements for storing the names of client classes.
Container for storing client class names.
Definition classify.h:108
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
Definition classify.cc:55
void insert(const ClientClass &class_name)
Insert an element.
Definition classify.h:155
Pool information for IPv4 addresses.
Definition pool.h:245
virtual data::ElementPtr toElement() const
Unparse a Pool4 object.
Definition pool.cc:142
Pool4(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool4 "min-max" style definition
Definition pool.cc:47
static Pool4Ptr create(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
Factory function for creating an instance of the Pool4.
Definition pool.cc:97
Pool information for IPv6 addresses and prefixes.
Definition pool.h:304
uint8_t getLength() const
returns delegated prefix length
Definition pool.h:430
virtual data::ElementPtr toElement() const
Unparse a Pool6 object.
Definition pool.cc:353
Option6PDExcludePtr getPrefixExcludeOption() const
Returns instance of the pool specific Prefix Exclude option.
Definition pool.h:438
static Pool6Ptr create(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
Factory function for creating an instance of the Pool6.
Definition pool.cc:266
virtual std::string toText() const
returns textual representation of the pool
Definition pool.cc:423
Pool6(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool6 "min-max" style definition
Definition pool.cc:163
Lease::Type getType() const
returns pool type
Definition pool.h:421
base class for Pool4 and Pool6
Definition pool.h:32
data::ConstElementPtr user_context_
Pointer to the user context (may be NULL)
Definition pool.h:230
const ClientClasses & getAdditionalClasses() const
Returns the additional classes list.
Definition pool.h:148
virtual data::ElementPtr toElement() const
Unparse a pool object.
Definition pool.cc:107
CfgOptionPtr cfg_option_
Pointer to the option data configuration for this pool.
Definition pool.h:217
void setID(const uint64_t id)
Sets Pool-id.
Definition pool.h:54
ClientClasses & getMutableAdditionalClasses()
Returns the mutable additional classes list.
Definition pool.h:153
Pool(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
protected constructor
Definition pool.cc:21
isc::util::uint128_t getCapacity() const
Returns the number of all leases in this pool.
Definition pool.h:99
const isc::asiolink::IOAddress & getFirstAddress() const
Returns the first address in a pool.
Definition pool.h:61
ClientClasses additional_classes_
Additional classes.
Definition pool.h:227
void allowClientClass(const ClientClass &class_name)
Sets the supported class to class class_name.
Definition pool.cc:35
uint64_t id_
pool-id
Definition pool.h:197
AllocationStatePtr getAllocationState() const
Returns pool-specific allocation state.
Definition pool.h:162
Lease::Type getType() const
Returns pool type (v4, v6 non-temporary, v6 temp, v6 prefix)
Definition pool.h:78
const isc::asiolink::IOAddress & getLastAddress() const
Returns the last address in a pool.
Definition pool.h:67
void setAllocationState(const AllocationStatePtr &allocation_state)
Sets pool-specific allocation state.
Definition pool.h:169
isc::util::uint128_t capacity_
Stores number of possible leases.
Definition pool.h:214
uint64_t getID() const
Returns Pool-id.
Definition pool.h:44
const ClientClass & getClientClass() const
returns the client class
Definition pool.h:134
isc::asiolink::IOAddress last_
The last address in a pool.
Definition pool.h:203
AllocationStatePtr allocation_state_
Holds pool-specific allocation state.
Definition pool.h:233
isc::asiolink::IOAddress first_
The first address in a pool.
Definition pool.h:200
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this pool.
Definition pool.h:104
virtual std::string toText() const
returns textual representation of the pool
Definition pool.cc:40
bool inRange(const isc::asiolink::IOAddress &addr) const
Checks if a given address is in the range.
Definition pool.cc:27
void addAdditionalClass(const ClientClass &class_name)
Adds class class_name to the additional classes list.
Definition pool.h:141
ClientClass client_class_
Optional definition of a client class.
Definition pool.h:222
bool clientSupported(const ClientClasses &client_classes) const
Checks whether this pool supports client that belongs to specified classes.
Definition pool.cc:31
virtual ~Pool()=default
virtual destructor
ConstCfgOptionPtr getCfgOption() const
Returns const pointer to the option data configuration for this pool.
Definition pool.h:110
Lease::Type type_
defines a lease type that will be served from this pool
Definition pool.h:206
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< Pool4 > Pool4Ptr
a pointer an IPv4 Pool
Definition pool.h:239
std::string ClientClass
Defines a single class name.
Definition classify.h:42
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition cfg_option.h:832
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
boost::shared_ptr< AllocationState > AllocationStatePtr
Type of the pointer to the AllocationState.
std::vector< PoolPtr > PoolCollection
a container for either IPv4 or IPv6 Pools
Definition pool.h:491
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:488
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition cfg_option.h:835
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Definition pool.h:298
boost::multiprecision::checked_uint128_t uint128_t
Definition bigints.h:21
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
Type
Type of lease or pool.
Definition lease.h:46