Kea  2.3.5-git
pool.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2022 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>
14 #include <dhcp/option6_pdexclude.h>
16 #include <dhcpsrv/cfg_option.h>
17 #include <dhcpsrv/lease.h>
19 
20 #include <boost/shared_ptr.hpp>
21 
22 #include <vector>
23 
24 namespace isc {
25 namespace dhcp {
26 
32 
33 public:
36 
41  uint32_t getId() const {
42  return (id_);
43  }
44 
49  return (first_);
50  }
51 
55  return (last_);
56  }
57 
61  bool inRange(const isc::asiolink::IOAddress& addr) const;
62 
65  Lease::Type getType() const {
66  return (type_);
67  }
68 
72  virtual std::string toText() const;
73 
79  virtual ~Pool() {
80  }
81 
87  uint64_t getCapacity() const {
88  return (capacity_);
89  }
90 
93  return (cfg_option_);
94  }
95 
99  return (cfg_option_);
100  }
101 
109  bool clientSupported(const ClientClasses& client_classes) const;
110 
114  void allowClientClass(const ClientClass& class_name);
115 
122  const ClientClass& getClientClass() const {
123  return (client_class_);
124  }
125 
129  void requireClientClass(const ClientClass& class_name) {
130  if (!required_classes_.contains(class_name)) {
131  required_classes_.insert(class_name);
132  }
133  }
134 
137  return (required_classes_);
138  }
139 
146  return (allocation_state_);
147  }
148 
152  void setAllocationState(const AllocationStatePtr& allocation_state) {
153  allocation_state_ = allocation_state;
154  }
155 
159  virtual data::ElementPtr toElement() const;
160 
165  return (permutation_);
166  }
167 
168 protected:
169 
179  Pool(Lease::Type type,
180  const isc::asiolink::IOAddress& first,
181  const isc::asiolink::IOAddress& last);
182 
186  static uint32_t getNextID() {
187  static uint32_t id = 0;
188  return (id++);
189  }
190 
194  uint32_t id_;
195 
198 
201 
204 
211  uint64_t capacity_;
212 
215 
220 
225 
228 
231 
237 };
238 
239 class Pool4;
240 
242 typedef boost::shared_ptr<Pool4> Pool4Ptr;
243 
248 class Pool4 : public Pool {
249 public:
254  Pool4(const isc::asiolink::IOAddress& first,
255  const isc::asiolink::IOAddress& last);
256 
261  Pool4(const isc::asiolink::IOAddress& prefix,
262  uint8_t prefix_len);
263 
275  static Pool4Ptr create(const isc::asiolink::IOAddress& first,
276  const isc::asiolink::IOAddress& last);
277 
289  static Pool4Ptr create(const isc::asiolink::IOAddress& prefix,
290  uint8_t prefix_len);
291 
295  virtual data::ElementPtr toElement() const;
296 };
297 
298 class Pool6;
299 
301 typedef boost::shared_ptr<Pool6> Pool6Ptr;
302 
307 class Pool6 : public Pool {
308 public:
309 
317  Pool6(Lease::Type type, const isc::asiolink::IOAddress& first,
318  const isc::asiolink::IOAddress& last);
319 
347  Pool6(Lease::Type type, const isc::asiolink::IOAddress& prefix,
348  uint8_t prefix_len, uint8_t delegated_len = 128);
349 
362  Pool6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
363  const uint8_t delegated_len,
364  const asiolink::IOAddress& excluded_prefix,
365  const uint8_t excluded_prefix_len);
366 
379  static Pool6Ptr create(Lease::Type type,
380  const isc::asiolink::IOAddress& first,
381  const isc::asiolink::IOAddress& last);
382 
396  static Pool6Ptr create(Lease::Type type,
397  const isc::asiolink::IOAddress& prefix,
398  uint8_t prefix_len,
399  uint8_t delegated_len = 128);
400 
415  static Pool6Ptr create(const asiolink::IOAddress& prefix,
416  const uint8_t prefix_len,
417  const uint8_t delegated_len,
418  const asiolink::IOAddress& excluded_prefix,
419  const uint8_t excluded_prefix_len);
420 
425  return (type_);
426  }
427 
433  uint8_t getLength() const {
434  return (prefix_len_);
435  }
436 
442  return (pd_exclude_option_);
443  }
444 
448  virtual data::ElementPtr toElement() const;
449 
453  virtual std::string toText() const;
454 
455 private:
456 
475  void init(const Lease::Type& type,
476  const asiolink::IOAddress& prefix,
477  const uint8_t prefix_len,
478  const uint8_t delegated_len,
479  const asiolink::IOAddress& excluded_prefix,
480  const uint8_t excluded_prefix_len);
481 
483  uint8_t prefix_len_;
484 
486  Option6PDExcludePtr pd_exclude_option_;
487 
488 };
489 
491 typedef boost::shared_ptr<Pool> PoolPtr;
492 
494 typedef std::vector<PoolPtr> PoolCollection;
495 
496 
497 } // end of isc::dhcp namespace
498 } // end of isc namespace
499 
500 
501 #endif // POOL_H
Lease::Type getType() const
Returns pool type (v4, v6 non-temporary, v6 temp, v6 prefix)
Definition: pool.h:65
Pool(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
protected constructor
Definition: pool.cc:21
boost::shared_ptr< Pool4 > Pool4Ptr
a pointer an IPv4 Pool
Definition: pool.h:239
const isc::asiolink::IOAddress & getFirstAddress() const
Returns the first address in a pool.
Definition: pool.h:48
const ClientClasses & getRequiredClasses() const
Returns classes which are required to be evaluated.
Definition: pool.h:136
uint32_t getId() const
returns Pool-id
Definition: pool.h:41
IPRangePermutationPtr getPermutation() const
Returns pointer to the permutation associated with the pool.
Definition: pool.h:164
void allowClientClass(const ClientClass &class_name)
Sets the supported class to class class_name.
Definition: pool.cc:36
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:745
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Definition: pool.h:298
ClientClasses required_classes_
Required classes.
Definition: pool.h:224
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
Definition: classify.cc:49
Base class for user context.
Definition: user_context.h:22
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition: cfg_option.h:748
void requireClientClass(const ClientClass &class_name)
Adds class class_name to classes required to be evaluated.
Definition: pool.h:129
Defines elements for storing the names of client classes.
CfgOptionPtr cfg_option_
Pointer to the option data configuration for this pool.
Definition: pool.h:214
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
std::vector< PoolPtr > PoolCollection
a container for either IPv4 or IPv6 Pools
Definition: pool.h:494
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition: pool.h:491
virtual ~Pool()
virtual destructor
Definition: pool.h:79
Pool information for IPv6 addresses and prefixes.
Definition: pool.h:307
Lease::Type getType() const
returns pool type
Definition: pool.h:424
Option6PDExcludePtr getPrefixExcludeOption() const
Returns instance of the pool specific Prefix Exclude option.
Definition: pool.h:441
Abstract class for configuration Cfg_* classes.
Lease::Type type_
defines a lease type that will be served from this pool
Definition: pool.h:203
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
bool clientSupported(const ClientClasses &client_classes) const
Checks whether this pool supports client that belongs to specified classes.
Definition: pool.cc:32
ClientClass client_class_
Optional definition of a client class.
Definition: pool.h:219
uint8_t getLength() const
returns delegated prefix length
Definition: pool.h:433
static uint32_t getNextID()
returns the next unique Pool-ID
Definition: pool.h:186
boost::shared_ptr< AllocationState > AllocationStatePtr
Type of the pointer to the AllocationState.
virtual std::string toText() const
returns textual representation of the pool
Definition: pool.cc:41
isc::asiolink::IOAddress first_
The first address in a pool.
Definition: pool.h:197
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
Defines the logger used by the top-level component of kea-lfc.
ConstCfgOptionPtr getCfgOption() const
Returns const pointer to the option data configuration for this pool.
Definition: pool.h:98
AllocationStatePtr getAllocationState() const
Returns pool-specific allocation state.
Definition: pool.h:145
uint64_t getCapacity() const
Returns the number of all leases in this pool.
Definition: pool.h:87
AllocationStatePtr allocation_state_
Holds pool-specific allocation state.
Definition: pool.h:230
isc::asiolink::IOAddress last_
The last address in a pool.
Definition: pool.h:200
const isc::asiolink::IOAddress & getLastAddress() const
Returns the last address in a pool.
Definition: pool.h:54
uint32_t id_
pool-id
Definition: pool.h:194
void setAllocationState(const AllocationStatePtr &allocation_state)
Sets pool-specific allocation state.
Definition: pool.h:152
boost::shared_ptr< IPRangePermutation > IPRangePermutationPtr
Pointer to the IPRangePermutation.
Type
Type of lease or pool.
Definition: lease.h:46
const ClientClass & getClientClass() const
returns the client class
Definition: pool.h:122
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this pool.
Definition: pool.h:92
data::ConstElementPtr user_context_
Pointer to the user context (may be NULL)
Definition: pool.h:227
base class for Pool4 and Pool6
Definition: pool.h:31
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:128
std::string ClientClass
Defines a single class name.
Definition: classify.h:42
virtual data::ElementPtr toElement() const
Unparse a pool object.
Definition: pool.cc:108
Container for storing client class names.
Definition: classify.h:108
IPRangePermutationPtr permutation_
Pointer to the permutation object.
Definition: pool.h:236
uint64_t capacity_
Stores number of possible leases.
Definition: pool.h:211
Pool information for IPv4 addresses.
Definition: pool.h:248
bool inRange(const isc::asiolink::IOAddress &addr) const
Checks if a given address is in the range.
Definition: pool.cc:28