Kea 2.7.1
pool.h
Go to the documentation of this file.
1// Copyright (C) 2012-2023 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 requireClientClass(const ClientClass& class_name) {
142 if (!required_classes_.contains(class_name)) {
143 required_classes_.insert(class_name);
144 }
145 }
146
149 return (required_classes_);
150 }
151
160
164 void setAllocationState(const AllocationStatePtr& allocation_state) {
165 allocation_state_ = allocation_state;
166 }
167
171 virtual data::ElementPtr toElement() const;
172
173protected:
174
184 Pool(Lease::Type type,
185 const isc::asiolink::IOAddress& first,
186 const isc::asiolink::IOAddress& last);
187
192 uint64_t id_;
193
196
199
202
210
213
218
223
226
229};
230
231class Pool4;
232
234typedef boost::shared_ptr<Pool4> Pool4Ptr;
235
240class Pool4 : public Pool {
241public:
246 Pool4(const isc::asiolink::IOAddress& first,
247 const isc::asiolink::IOAddress& last);
248
253 Pool4(const isc::asiolink::IOAddress& prefix,
254 uint8_t prefix_len);
255
267 static Pool4Ptr create(const isc::asiolink::IOAddress& first,
268 const isc::asiolink::IOAddress& last);
269
281 static Pool4Ptr create(const isc::asiolink::IOAddress& prefix,
282 uint8_t prefix_len);
283
287 virtual data::ElementPtr toElement() const;
288};
289
290class Pool6;
291
293typedef boost::shared_ptr<Pool6> Pool6Ptr;
294
299class Pool6 : public Pool {
300public:
301
309 Pool6(Lease::Type type, const isc::asiolink::IOAddress& first,
310 const isc::asiolink::IOAddress& last);
311
339 Pool6(Lease::Type type, const isc::asiolink::IOAddress& prefix,
340 uint8_t prefix_len, uint8_t delegated_len = 128);
341
354 Pool6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
355 const uint8_t delegated_len,
356 const asiolink::IOAddress& excluded_prefix,
357 const uint8_t excluded_prefix_len);
358
371 static Pool6Ptr create(Lease::Type type,
372 const isc::asiolink::IOAddress& first,
373 const isc::asiolink::IOAddress& last);
374
388 static Pool6Ptr create(Lease::Type type,
389 const isc::asiolink::IOAddress& prefix,
390 uint8_t prefix_len,
391 uint8_t delegated_len = 128);
392
407 static Pool6Ptr create(const asiolink::IOAddress& prefix,
408 const uint8_t prefix_len,
409 const uint8_t delegated_len,
410 const asiolink::IOAddress& excluded_prefix,
411 const uint8_t excluded_prefix_len);
412
417 return (type_);
418 }
419
425 uint8_t getLength() const {
426 return (prefix_len_);
427 }
428
434 return (pd_exclude_option_);
435 }
436
440 virtual data::ElementPtr toElement() const;
441
445 virtual std::string toText() const;
446
447private:
448
467 void init(const Lease::Type& type,
468 const asiolink::IOAddress& prefix,
469 const uint8_t prefix_len,
470 const uint8_t delegated_len,
471 const asiolink::IOAddress& excluded_prefix,
472 const uint8_t excluded_prefix_len);
473
475 uint8_t prefix_len_;
476
478 Option6PDExcludePtr pd_exclude_option_;
479
480};
481
483typedef boost::shared_ptr<Pool> PoolPtr;
484
486typedef std::vector<PoolPtr> PoolCollection;
487
488} // end of isc::dhcp namespace
489} // end of isc namespace
490
491#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:49
void insert(const ClientClass &class_name)
Insert an element.
Definition classify.h:128
Pool information for IPv4 addresses.
Definition pool.h:240
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:299
uint8_t getLength() const
returns delegated prefix length
Definition pool.h:425
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:433
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:416
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:225
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:212
void setID(const uint64_t id)
Sets Pool-id.
Definition pool.h:54
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
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:192
AllocationStatePtr getAllocationState() const
Returns pool-specific allocation state.
Definition pool.h:157
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:164
isc::util::uint128_t capacity_
Stores number of possible leases.
Definition pool.h:209
uint64_t getID() const
Returns Pool-id.
Definition pool.h:44
const ClientClass & getClientClass() const
returns the client class
Definition pool.h:134
ClientClasses required_classes_
Required classes.
Definition pool.h:222
const ClientClasses & getRequiredClasses() const
Returns classes which are required to be evaluated.
Definition pool.h:148
isc::asiolink::IOAddress last_
The last address in a pool.
Definition pool.h:198
AllocationStatePtr allocation_state_
Holds pool-specific allocation state.
Definition pool.h:228
isc::asiolink::IOAddress first_
The first address in a pool.
Definition pool.h:195
void requireClientClass(const ClientClass &class_name)
Adds class class_name to classes required to be evaluated.
Definition pool.h:141
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
ClientClass client_class_
Optional definition of a client class.
Definition pool.h:217
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:201
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:234
std::string ClientClass
Defines a single class name.
Definition classify.h:42
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition cfg_option.h:803
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:486
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:483
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition cfg_option.h:806
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Definition pool.h:293
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