12 #include <boost/make_shared.hpp>
23 :id_(getNextID()), first_(first), last_(last), type_(type),
24 capacity_(0), cfg_option_(new
CfgOption()), client_class_(
""),
25 last_allocated_(first), last_allocated_valid_(false),
43 std::stringstream tmp;
77 if (prefix_len == 0 || prefix_len > 32) {
93 return (boost::make_shared<Pool4>(first, last));
98 return (boost::make_shared<Pool4>(prefix, prefix_len));
111 map->set(
"option-data", opts->toElement());
115 if (!cclass.empty()) {
116 map->set(
"client-class", Element::create(cclass));
121 if (!classes.
empty()) {
124 it != classes.
cend(); ++it) {
125 class_list->add(Element::create(*it));
127 map->set(
"require-client-classes", class_list);
141 std::string range = first.
toText() +
"-" + last.
toText();
145 if (prefix_len >= 0) {
146 std::ostringstream oss;
147 oss << first.
toText() <<
"/" << prefix_len;
151 map->set(
"pool", Element::create(range));
158 :
Pool(type, first, last), prefix_len_(128), pd_exclude_option_() {
161 if (!first.
isV6() || !last.
isV6()) {
168 <<
", must be TYPE_IA, TYPE_TA or TYPE_PD");
189 << static_cast<int>(type));
199 const uint8_t prefix_len,
const uint8_t delegated_len )
201 prefix_len_(delegated_len), pd_exclude_option_() {
203 init(type, prefix, prefix_len, delegated_len,
208 const uint8_t delegated_len,
210 const uint8_t excluded_prefix_len)
212 prefix_len_(delegated_len), pd_exclude_option_() {
214 init(
Lease::TYPE_PD, prefix, prefix_len, delegated_len, excluded_prefix,
215 excluded_prefix_len);
220 if (!excluded_prefix.
isV6()) {
225 if ((excluded_prefix.
isV6Zero() && (excluded_prefix_len != 0)) ||
226 (!excluded_prefix.
isV6Zero() && (excluded_prefix_len == 0))) {
228 << excluded_prefix <<
"/"
229 << static_cast<unsigned>(excluded_prefix_len));
233 if (!excluded_prefix.
isV6Zero() && (excluded_prefix_len != 0)) {
236 if (excluded_prefix_len > 128) {
238 << static_cast<unsigned>(excluded_prefix_len)
239 <<
" must not be greater than 128");
244 if (excluded_prefix_len <= prefix_len_) {
246 << static_cast<unsigned>(excluded_prefix_len)
247 <<
" must be lower than the delegated prefix length "
248 << static_cast<unsigned>(prefix_len_));
261 return (boost::make_shared<Pool6>(type, first, last));
266 uint8_t prefix_len, uint8_t delegated_len) {
267 return (boost::make_shared<Pool6>(type, prefix, prefix_len, delegated_len));
272 const uint8_t delegated_len,
const IOAddress& excluded_prefix,
273 const uint8_t excluded_prefix_len) {
274 return (boost::make_shared<Pool6>(prefix, prefix_len,
275 delegated_len, excluded_prefix,
276 excluded_prefix_len));
282 const uint8_t prefix_len,
283 const uint8_t delegated_len,
285 const uint8_t excluded_prefix_len) {
287 if (!prefix.
isV6()) {
292 if (prefix_len == 0 || prefix_len > 128) {
294 << static_cast<unsigned>(prefix_len));
297 if (prefix_len > delegated_len) {
299 << static_cast<int>(delegated_len)
300 <<
") must be longer than or equal to prefix length ("
301 << static_cast<int>(prefix_len) <<
")");
305 (delegated_len != 128)) {
306 isc_throw(BadValue,
"For IA or TA pools, delegated prefix length must"
311 if (excluded_prefix_len && (excluded_prefix_len < delegated_len)) {
313 << static_cast<int>(excluded_prefix_len)
314 <<
") must be longer than or equal to the delegated prefix length ("
315 << static_cast<int>(delegated_len) <<
")");
331 if (excluded_prefix_len > 0) {
332 pd_exclude_option_.reset(
new Option6PDExclude(prefix, delegated_len,
334 excluded_prefix_len));
347 std::string range = first.
toText() +
"-" + last.
toText();
351 if (prefix_len >= 0) {
352 std::ostringstream oss;
353 oss << first.
toText() <<
"/" << prefix_len;
357 map->set(
"pool", Element::create(range));
363 map->set(
"prefix", Element::create(prefix.
toText()));
368 if (prefix_len < 0) {
373 map->set(
"prefix-len", Element::create(prefix_len));
377 map->set(
"delegated-len", Element::create(static_cast<int>(len)));
382 const IOAddress& xprefix = xopt->getExcludedPrefix(prefix, len);
383 map->set(
"excluded-prefix", Element::create(xprefix.
toText()));
385 uint8_t xlen = xopt->getExcludedPrefixLength();
386 map->set(
"excluded-prefix-len",
387 Element::create(static_cast<int>(xlen)));
401 <<
", unsupported for Pool6");
411 std::ostringstream s;
413 <<
"-" <<
last_ <<
", delegated_len="
414 <<
static_cast<unsigned>(prefix_len_);
416 if (pd_exclude_option_) {
417 s <<
", excluded_prefix_len="
418 <<
static_cast<unsigned>(pd_exclude_option_->getExcludedPrefixLength());
boost::shared_ptr< Pool4 > Pool4Ptr
a pointer an IPv4 Pool
bool inRange(const isc::asiolink::IOAddress &addr) const
Checks if a given address is in the range.
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.
static Pool4Ptr create(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
Factory function for creating an instance of the Pool4.
Lease::Type getType() const
returns pool type
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
static std::string typeToText(Type type)
returns text representation of a lease type
uint64_t addrsInRange(const IOAddress &min, const IOAddress &max)
Returns number of available addresses in the specified range (min - max).
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
the lease contains IPv6 prefix (for prefix delegation)
boost::shared_ptr< Element > ElementPtr
virtual data::ElementPtr toElement() const
Unparse a Pool6 object.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
bool isV4() const
Convenience function to check for an IPv4 address.
Pool6(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool6 "min-max" style definition
const ClientClasses & getRequiredClasses() const
Returns classes which are required to be evaluated.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Represents option data configuration for the DHCP server.
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
const_iterator cend() const
Iterator to the past the end element.
Lease::Type type_
defines a lease type that will be served from this pool
const isc::asiolink::IOAddress & getLastAddress() const
Returns the last address in a pool.
Option6PDExcludePtr getPrefixExcludeOption() const
Returns instance of the pool specific Prefix Exclude option.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
ClientClass client_class_
Optional definition of a client class.
virtual std::string toText() const
returns textual representation of the pool
virtual std::string toText() const
returns textual representation of the pool
the lease contains temporary IPv6 address
bool clientSupported(const ClientClasses &client_classes) const
Checks whether this pool supports client that belongs to specified classes.
the lease contains non-temporary IPv6 address
isc::asiolink::IOAddress first_
The first address in a pool.
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Pool4(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool4 "min-max" style definition
isc::asiolink::IOAddress last_
The last address in a pool.
a common structure for IPv4 and IPv6 leases
Type
Type of lease or pool.
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this pool.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
std::string toText() const
Convert the address to a string.
virtual data::ElementPtr toElement() const
Unparse a Pool4 object.
int prefixLengthFromRange(const IOAddress &min, const IOAddress &max)
Returns prefix length from the specified range (min - max).
bool isV6() const
Convenience function to check for an IPv6 address.
base class for Pool4 and Pool6
uint64_t prefixesInRange(const uint8_t pool_len, const uint8_t delegated_len)
Returns number of available IPv6 prefixes in the specified prefix.
std::string ClientClass
Defines a single class name.
bool empty() const
Check if classes is empty.
The IOAddress class represents an IP addresses (version agnostic)
uint8_t getLength() const
returns delegated prefix length
const ClientClass & getClientClass() const
returns the client class
virtual data::ElementPtr toElement() const
Unparse a pool object.
const_iterator cbegin() const
Iterator to the first element.
Container for storing client class names.
uint64_t capacity_
Stores number of possible leases.