Kea  2.3.1-git
pool.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2020 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>
15 #include <dhcpsrv/cfg_option.h>
16 #include <dhcpsrv/lease.h>
18 
19 #include <boost/shared_ptr.hpp>
20 
21 #include <vector>
22 
23 namespace isc {
24 namespace dhcp {
25 
31 
32 public:
35 
40  uint32_t getId() const {
41  return (id_);
42  }
43 
48  return (first_);
49  }
50 
54  return (last_);
55  }
56 
60  bool inRange(const isc::asiolink::IOAddress& addr) const;
61 
64  Lease::Type getType() const {
65  return (type_);
66  }
67 
71  virtual std::string toText() const;
72 
78  virtual ~Pool() {
79  }
80 
86  uint64_t getCapacity() const {
87  return (capacity_);
88  }
89 
92  return (cfg_option_);
93  }
94 
98  return (cfg_option_);
99  }
100 
108  bool clientSupported(const ClientClasses& client_classes) const;
109 
113  void allowClientClass(const ClientClass& class_name);
114 
121  const ClientClass& getClientClass() const {
122  return (client_class_);
123  }
124 
128  void requireClientClass(const ClientClass& class_name) {
129  if (!required_classes_.contains(class_name)) {
130  required_classes_.insert(class_name);
131  }
132  }
133 
136  return (required_classes_);
137  }
138 
143  return last_allocated_;
144  }
145 
148  bool isLastAllocatedValid() const {
149  return last_allocated_valid_;
150  }
151 
156  last_allocated_ = addr;
157  last_allocated_valid_ = true;
158  }
159 
162  last_allocated_valid_ = false;
163  }
164 
168  virtual data::ElementPtr toElement() const;
169 
174  return (permutation_);
175  }
176 
177 protected:
178 
188  Pool(Lease::Type type,
189  const isc::asiolink::IOAddress& first,
190  const isc::asiolink::IOAddress& last);
191 
195  static uint32_t getNextID() {
196  static uint32_t id = 0;
197  return (id++);
198  }
199 
203  uint32_t id_;
204 
207 
210 
213 
220  uint64_t capacity_;
221 
224 
229 
234 
237 
242 
245 
251 };
252 
253 class Pool4;
254 
256 typedef boost::shared_ptr<Pool4> Pool4Ptr;
257 
262 class Pool4 : public Pool {
263 public:
268  Pool4(const isc::asiolink::IOAddress& first,
269  const isc::asiolink::IOAddress& last);
270 
275  Pool4(const isc::asiolink::IOAddress& prefix,
276  uint8_t prefix_len);
277 
289  static Pool4Ptr create(const isc::asiolink::IOAddress& first,
290  const isc::asiolink::IOAddress& last);
291 
303  static Pool4Ptr create(const isc::asiolink::IOAddress& prefix,
304  uint8_t prefix_len);
305 
309  virtual data::ElementPtr toElement() const;
310 };
311 
312 class Pool6;
313 
315 typedef boost::shared_ptr<Pool6> Pool6Ptr;
316 
321 class Pool6 : public Pool {
322 public:
323 
331  Pool6(Lease::Type type, const isc::asiolink::IOAddress& first,
332  const isc::asiolink::IOAddress& last);
333 
361  Pool6(Lease::Type type, const isc::asiolink::IOAddress& prefix,
362  uint8_t prefix_len, uint8_t delegated_len = 128);
363 
376  Pool6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
377  const uint8_t delegated_len,
378  const asiolink::IOAddress& excluded_prefix,
379  const uint8_t excluded_prefix_len);
380 
393  static Pool6Ptr create(Lease::Type type,
394  const isc::asiolink::IOAddress& first,
395  const isc::asiolink::IOAddress& last);
396 
410  static Pool6Ptr create(Lease::Type type,
411  const isc::asiolink::IOAddress& prefix,
412  uint8_t prefix_len,
413  uint8_t delegated_len = 128);
414 
429  static Pool6Ptr create(const asiolink::IOAddress& prefix,
430  const uint8_t prefix_len,
431  const uint8_t delegated_len,
432  const asiolink::IOAddress& excluded_prefix,
433  const uint8_t excluded_prefix_len);
434 
439  return (type_);
440  }
441 
447  uint8_t getLength() const {
448  return (prefix_len_);
449  }
450 
456  return (pd_exclude_option_);
457  }
458 
462  virtual data::ElementPtr toElement() const;
463 
467  virtual std::string toText() const;
468 
469 private:
470 
489  void init(const Lease::Type& type,
490  const asiolink::IOAddress& prefix,
491  const uint8_t prefix_len,
492  const uint8_t delegated_len,
493  const asiolink::IOAddress& excluded_prefix,
494  const uint8_t excluded_prefix_len);
495 
497  uint8_t prefix_len_;
498 
500  Option6PDExcludePtr pd_exclude_option_;
501 
502 };
503 
505 typedef boost::shared_ptr<Pool> PoolPtr;
506 
508 typedef std::vector<PoolPtr> PoolCollection;
509 
510 
511 } // end of isc::dhcp namespace
512 } // end of isc namespace
513 
514 
515 #endif // POOL_H
Lease::Type getType() const
Returns pool type (v4, v6 non-temporary, v6 temp, v6 prefix)
Definition: pool.h:64
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:253
const isc::asiolink::IOAddress & getFirstAddress() const
Returns the first address in a pool.
Definition: pool.h:47
const ClientClasses & getRequiredClasses() const
Returns classes which are required to be evaluated.
Definition: pool.h:135
uint32_t getId() const
returns Pool-id
Definition: pool.h:40
IPRangePermutationPtr getPermutation() const
Returns pointer to the permutation associated with the pool.
Definition: pool.h:173
bool last_allocated_valid_
Status of last allocated address.
Definition: pool.h:244
void allowClientClass(const ClientClass &class_name)
Sets the supported class to class class_name.
Definition: pool.cc:37
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:312
void setLastAllocated(const isc::asiolink::IOAddress &addr)
sets the last address that was tried from this pool
Definition: pool.h:155
ClientClasses required_classes_
Required classes.
Definition: pool.h:233
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:128
Defines elements for storing the names of client classes.
CfgOptionPtr cfg_option_
Pointer to the option data configuration for this pool.
Definition: pool.h:223
bool isLastAllocatedValid() const
checks if the last address is valid
Definition: pool.h:148
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
std::vector< PoolPtr > PoolCollection
a container for either IPv4 or IPv6 Pools
Definition: pool.h:508
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition: pool.h:505
isc::asiolink::IOAddress getLastAllocated() const
returns the last address that was tried from this pool
Definition: pool.h:142
virtual ~Pool()
virtual destructor
Definition: pool.h:78
Pool information for IPv6 addresses and prefixes.
Definition: pool.h:321
Lease::Type getType() const
returns pool type
Definition: pool.h:438
Option6PDExcludePtr getPrefixExcludeOption() const
Returns instance of the pool specific Prefix Exclude option.
Definition: pool.h:455
Abstract class for configuration Cfg_* classes.
Lease::Type type_
defines a lease type that will be served from this pool
Definition: pool.h:212
void resetLastAllocated()
resets the last address to invalid
Definition: pool.h:161
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:33
ClientClass client_class_
Optional definition of a client class.
Definition: pool.h:228
uint8_t getLength() const
returns delegated prefix length
Definition: pool.h:447
static uint32_t getNextID()
returns the next unique Pool-ID
Definition: pool.h:195
virtual std::string toText() const
returns textual representation of the pool
Definition: pool.cc:42
isc::asiolink::IOAddress first_
The first address in a pool.
Definition: pool.h:206
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
isc::asiolink::IOAddress last_allocated_
Last allocated address See isc::dhcp::Subnet::last_allocated_ia_ Initialized and reset to first...
Definition: pool.h:241
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:97
uint64_t getCapacity() const
Returns the number of all leases in this pool.
Definition: pool.h:86
isc::asiolink::IOAddress last_
The last address in a pool.
Definition: pool.h:209
const isc::asiolink::IOAddress & getLastAddress() const
Returns the last address in a pool.
Definition: pool.h:53
uint32_t id_
pool-id
Definition: pool.h:203
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:121
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this pool.
Definition: pool.h:91
data::ConstElementPtr user_context_
Pointer to the user context (may be NULL)
Definition: pool.h:236
base class for Pool4 and Pool6
Definition: pool.h:30
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:90
std::string ClientClass
Defines a single class name.
Definition: classify.h:42
virtual data::ElementPtr toElement() const
Unparse a pool object.
Definition: pool.cc:102
Container for storing client class names.
Definition: classify.h:70
IPRangePermutationPtr permutation_
Pointer to the permutation object.
Definition: pool.h:250
uint64_t capacity_
Stores number of possible leases.
Definition: pool.h:220
Pool information for IPv4 addresses.
Definition: pool.h:262
bool inRange(const isc::asiolink::IOAddress &addr) const
Checks if a given address is in the range.
Definition: pool.cc:29