12#include <boost/make_shared.hpp>
23 : id_(0), first_(first), last_(last), type_(type), capacity_(0),
24 cfg_option_(new
CfgOption()), client_class_(
"") {
41 std::stringstream tmp;
51 if (!first.
isV4() || !last.isV4()) {
75 if (prefix_len == 0 || prefix_len > 32) {
80 if (first_address != prefix) {
82 <<
" is not the first address in prefix: " << first_address
83 <<
"/" <<
static_cast<uint32_t
>(prefix_len));
98 return (boost::make_shared<Pool4>(first, last));
103 return (boost::make_shared<Pool4>(prefix, prefix_len));
116 map->set(
"option-data", opts->toElement());
120 if (!cclass.empty()) {
126 if (!classes.empty()) {
128 for (
auto const& it : classes) {
131 map->set(
"evaluate-additional-classes", class_list);
149 std::string range = first.
toText() +
"-" + last.toText();
153 if (prefix_len >= 0) {
154 std::ostringstream oss;
155 oss << first.
toText() <<
"/" << prefix_len;
165 :
Pool(type, first, last), prefix_len_(128), pd_exclude_option_() {
168 if (!first.
isV6() || !last.isV6()) {
175 <<
", must be TYPE_IA, TYPE_TA or TYPE_PD");
196 <<
static_cast<int>(type));
206 const uint8_t prefix_len,
const uint8_t delegated_len )
208 prefix_len_(delegated_len), pd_exclude_option_() {
210 init(type, prefix, prefix_len, delegated_len,
215 const uint8_t delegated_len,
217 const uint8_t excluded_prefix_len)
219 prefix_len_(delegated_len), pd_exclude_option_() {
221 init(
Lease::TYPE_PD, prefix, prefix_len, delegated_len, excluded_prefix,
222 excluded_prefix_len);
227 if (!excluded_prefix.isV6()) {
232 if ((excluded_prefix.isV6Zero() && (excluded_prefix_len != 0)) ||
233 (!excluded_prefix.isV6Zero() && (excluded_prefix_len == 0))) {
235 << excluded_prefix <<
"/"
236 <<
static_cast<unsigned>(excluded_prefix_len));
240 if (!excluded_prefix.isV6Zero() && (excluded_prefix_len != 0)) {
242 if (excluded_prefix_len > 128) {
244 <<
static_cast<unsigned>(excluded_prefix_len)
245 <<
" must not be greater than 128");
250 if (excluded_prefix_len <= prefix_len_) {
252 <<
static_cast<unsigned>(excluded_prefix_len)
253 <<
" must be longer than the delegated prefix length "
254 <<
static_cast<unsigned>(prefix_len_));
267 return (boost::make_shared<Pool6>(type, first, last));
272 uint8_t prefix_len, uint8_t delegated_len) {
273 return (boost::make_shared<Pool6>(type, prefix, prefix_len, delegated_len));
278 const uint8_t delegated_len,
const IOAddress& excluded_prefix,
279 const uint8_t excluded_prefix_len) {
280 return (boost::make_shared<Pool6>(prefix, prefix_len,
281 delegated_len, excluded_prefix,
282 excluded_prefix_len));
288 const uint8_t prefix_len,
289 const uint8_t delegated_len,
291 const uint8_t excluded_prefix_len) {
293 if (!prefix.isV6()) {
298 if (prefix_len == 0 || prefix_len > 128) {
300 <<
static_cast<unsigned>(prefix_len));
303 if (prefix_len > delegated_len) {
305 <<
static_cast<int>(delegated_len)
306 <<
") must be longer than or equal to prefix length ("
307 <<
static_cast<int>(prefix_len) <<
")");
316 if (excluded_prefix_len && (excluded_prefix_len <= delegated_len)) {
318 <<
static_cast<int>(excluded_prefix_len)
319 <<
") must be longer than the delegated prefix length ("
320 <<
static_cast<int>(delegated_len) <<
")");
323 if (prefix_len != 128) {
325 if (first_address != prefix) {
327 <<
" is not the first address in prefix: " << first_address
328 <<
"/" <<
static_cast<uint32_t
>(prefix_len));
345 if (excluded_prefix_len > 0) {
346 pd_exclude_option_.reset(
new Option6PDExclude(prefix, delegated_len,
348 excluded_prefix_len));
361 std::string range = first.
toText() +
"-" + last.toText();
365 if (prefix_len >= 0) {
366 std::ostringstream oss;
367 oss << first.
toText() <<
"/" << prefix_len;
382 if (prefix_len < 0) {
385 << prefix.toText() <<
"-" << last.toText());
396 const IOAddress& xprefix = xopt->getExcludedPrefix(prefix, len);
399 uint8_t xlen = xopt->getExcludedPrefixLength();
400 map->set(
"excluded-prefix-len",
415 <<
", unsupported for Pool6");
424 std::ostringstream s;
426 <<
"-" <<
last_ <<
", delegated_len="
427 <<
static_cast<unsigned>(prefix_len_);
429 if (pd_exclude_option_) {
430 s <<
", excluded_prefix="
431 << pd_exclude_option_->getExcludedPrefix(
first_, prefix_len_).toText()
433 <<
static_cast<unsigned>(pd_exclude_option_->getExcludedPrefixLength());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Represents option data configuration for the DHCP server.
Container for storing client class names.
virtual data::ElementPtr toElement() const
Unparse a Pool4 object.
Pool4(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool4 "min-max" style definition
static Pool4Ptr create(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
Factory function for creating an instance of the Pool4.
uint8_t getLength() const
returns delegated prefix length
virtual data::ElementPtr toElement() const
Unparse a Pool6 object.
Option6PDExcludePtr getPrefixExcludeOption() const
Returns instance of the pool specific Prefix Exclude option.
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.
virtual std::string toText() const
returns textual representation of the pool
Pool6(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool6 "min-max" style definition
Lease::Type getType() const
returns pool type
base class for Pool4 and Pool6
const ClientClasses & getAdditionalClasses() const
Returns the additional classes list.
virtual data::ElementPtr toElement() const
Unparse a pool object.
Pool(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
protected constructor
const isc::asiolink::IOAddress & getFirstAddress() const
Returns the first address in a pool.
void allowClientClass(const ClientClass &class_name)
Sets the supported class to class class_name.
const isc::asiolink::IOAddress & getLastAddress() const
Returns the last address in a pool.
isc::util::uint128_t capacity_
Stores number of possible leases.
const ClientClass & getClientClass() const
returns the client class
isc::asiolink::IOAddress last_
The last address in a pool.
isc::asiolink::IOAddress first_
The first address in a pool.
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this pool.
virtual std::string toText() const
returns textual representation of the pool
bool inRange(const isc::asiolink::IOAddress &addr) const
Checks if a given address is in the range.
ClientClass client_class_
Optional definition of a client class.
bool clientSupported(const ClientClasses &client_classes) const
Checks whether this pool supports client that belongs to specified classes.
Lease::Type type_
defines a lease type that will be served from this pool
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
uint128_t addrsInRange(const IOAddress &min, const IOAddress &max)
Returns number of available addresses in the specified range (min - max).
uint128_t prefixesInRange(const uint8_t pool_len, const uint8_t delegated_len)
Returns number of available IPv6 prefixes in the specified prefix.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
int prefixLengthFromRange(const IOAddress &min, const IOAddress &max)
Returns prefix length from the specified range (min - max).
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Pool4 > Pool4Ptr
a pointer an IPv4 Pool
std::string ClientClass
Defines a single class name.
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Defines the logger used by the top-level component of kea-lfc.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
a common structure for IPv4 and IPv6 leases
Type
Type of lease or pool.
@ TYPE_TA
the lease contains temporary IPv6 address
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address
static std::string typeToText(Type type)
returns text representation of a lease type