12 #include <boost/make_shared.hpp> 23 : id_(getNextID()), first_(first), last_(last), type_(type),
24 capacity_(0), cfg_option_(new
CfgOption()), client_class_(
""),
42 std::stringstream tmp;
76 if (prefix_len == 0 || prefix_len > 32) {
81 if (first_address != prefix) {
83 <<
" is not the first address in prefix: " << first_address
84 <<
"/" << static_cast<uint32_t>(prefix_len));
99 return (boost::make_shared<Pool4>(first, last));
104 return (boost::make_shared<Pool4>(prefix, prefix_len));
117 map->set(
"option-data", opts->toElement());
121 if (!cclass.empty()) {
127 if (!classes.
empty()) {
130 it != classes.
cend(); ++it) {
133 map->set(
"require-client-classes", class_list);
147 std::string range = first.
toText() +
"-" + last.
toText();
151 if (prefix_len >= 0) {
152 std::ostringstream oss;
153 oss << first.
toText() <<
"/" << prefix_len;
163 :
Pool(type, first, last), prefix_len_(128), pd_exclude_option_() {
166 if (!first.
isV6() || !last.
isV6()) {
173 <<
", must be TYPE_IA, TYPE_TA or TYPE_PD");
194 << static_cast<int>(type));
204 const uint8_t prefix_len,
const uint8_t delegated_len )
206 prefix_len_(delegated_len), pd_exclude_option_() {
208 init(type, prefix, prefix_len, delegated_len,
213 const uint8_t delegated_len,
215 const uint8_t excluded_prefix_len)
217 prefix_len_(delegated_len), pd_exclude_option_() {
219 init(
Lease::TYPE_PD, prefix, prefix_len, delegated_len, excluded_prefix,
220 excluded_prefix_len);
225 if (!excluded_prefix.
isV6()) {
230 if ((excluded_prefix.
isV6Zero() && (excluded_prefix_len != 0)) ||
231 (!excluded_prefix.
isV6Zero() && (excluded_prefix_len == 0))) {
233 << excluded_prefix <<
"/" 234 << static_cast<unsigned>(excluded_prefix_len));
238 if (!excluded_prefix.
isV6Zero() && (excluded_prefix_len != 0)) {
240 if (excluded_prefix_len > 128) {
242 << static_cast<unsigned>(excluded_prefix_len)
243 <<
" must not be greater than 128");
248 if (excluded_prefix_len <= prefix_len_) {
250 << static_cast<unsigned>(excluded_prefix_len)
251 <<
" must be longer than the delegated prefix length " 252 << static_cast<unsigned>(prefix_len_));
265 return (boost::make_shared<Pool6>(type, first, last));
270 uint8_t prefix_len, uint8_t delegated_len) {
271 return (boost::make_shared<Pool6>(type, prefix, prefix_len, delegated_len));
276 const uint8_t delegated_len,
const IOAddress& excluded_prefix,
277 const uint8_t excluded_prefix_len) {
278 return (boost::make_shared<Pool6>(prefix, prefix_len,
279 delegated_len, excluded_prefix,
280 excluded_prefix_len));
286 const uint8_t prefix_len,
287 const uint8_t delegated_len,
289 const uint8_t excluded_prefix_len) {
291 if (!prefix.
isV6()) {
296 if (prefix_len == 0 || prefix_len > 128) {
298 << static_cast<unsigned>(prefix_len));
301 if (prefix_len > delegated_len) {
303 << static_cast<int>(delegated_len)
304 <<
") must be longer than or equal to prefix length (" 305 << static_cast<int>(prefix_len) <<
")");
309 (delegated_len != 128)) {
315 if (excluded_prefix_len && (excluded_prefix_len <= delegated_len)) {
317 << static_cast<int>(excluded_prefix_len)
318 <<
") must be longer than the delegated prefix length (" 319 << static_cast<int>(delegated_len) <<
")");
323 if (first_address != prefix) {
325 <<
" is not the first address in prefix: " << first_address
326 <<
"/" << static_cast<uint32_t>(prefix_len));
342 if (excluded_prefix_len > 0) {
345 excluded_prefix_len));
358 std::string range = first.
toText() +
"-" + last.
toText();
362 if (prefix_len >= 0) {
363 std::ostringstream oss;
364 oss << first.
toText() <<
"/" << prefix_len;
379 if (prefix_len < 0) {
393 const IOAddress& xprefix = xopt->getExcludedPrefix(prefix, len);
396 uint8_t xlen = xopt->getExcludedPrefixLength();
397 map->set(
"excluded-prefix-len",
412 <<
", unsupported for Pool6");
421 std::ostringstream s;
423 <<
"-" <<
last_ <<
", delegated_len=" 424 <<
static_cast<unsigned>(prefix_len_);
426 if (pd_exclude_option_) {
427 s <<
", excluded_prefix_len=" 428 <<
static_cast<unsigned>(pd_exclude_option_->getExcludedPrefixLength());
boost::shared_ptr< Pool4 > Pool4Ptr
a pointer an IPv4 Pool
const isc::asiolink::IOAddress & getFirstAddress() const
Returns the first address in a pool.
const ClientClasses & getRequiredClasses() const
Returns classes which are required to be evaluated.
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.
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).
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
DHCPv6 option class representing Prefix Exclude Option (RFC 6603).
the lease contains IPv6 prefix (for prefix delegation)
boost::shared_ptr< Element > ElementPtr
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
const_iterator cbegin() const
Iterators to the first element.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Pool6(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool6 "min-max" style definition
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
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...
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Represents option data configuration for the DHCP server.
Lease::Type getType() const
returns pool type
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.
Lease::Type type_
defines a lease type that will be served from this pool
bool clientSupported(const ClientClasses &client_classes) const
Checks whether this pool supports client that belongs to specified classes.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
ClientClass client_class_
Optional definition of a client class.
bool isV6() const
Convenience function to check for an IPv6 address.
the lease contains temporary IPv6 address
bool isV4() const
Convenience function to check for an IPv4 address.
uint8_t getLength() const
returns delegated prefix length
bool empty() const
Check if classes is empty.
the lease contains non-temporary IPv6 address
virtual std::string toText() const
returns textual representation of the pool
isc::asiolink::IOAddress first_
The first address in a pool.
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
virtual data::ElementPtr toElement() const
Unparse a Pool6 object.
Defines the logger used by the top-level component of kea-lfc.
std::string toText() const
Convert the address to a string.
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
isc::asiolink::IOAddress last_
The last address in a pool.
const isc::asiolink::IOAddress & getLastAddress() const
Returns the last address in a pool.
static ElementPtr create(const Position &pos=ZERO_POSITION())
a common structure for IPv4 and IPv6 leases
Type
Type of lease or pool.
const ClientClass & getClientClass() const
returns the client class
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
const_iterator cend() const
Iterators to the past the end element.
virtual std::string toText() const
returns textual representation of the pool
int prefixLengthFromRange(const IOAddress &min, const IOAddress &max)
Returns prefix length from the specified range (min - max).
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.
virtual data::ElementPtr toElement() const
Unparse a pool object.
The IOAddress class represents an IP addresses (version agnostic)
Container for storing client class names.
uint64_t capacity_
Stores number of possible leases.
bool inRange(const isc::asiolink::IOAddress &addr) const
Checks if a given address is in the range.