17 #include <boost/lexical_cast.hpp> 18 #include <boost/make_shared.hpp> 36 return (prefix < pool->getFirstAddress());
48 comparePoolFirstAddress(
const PoolPtr& pool1,
const PoolPtr& pool2) {
49 return (pool1->getFirstAddress() < pool2->getFirstAddress());
62 : id_(id == 0 ? generateNextID() : id), prefix_(prefix),
64 shared_network_name_() {
65 if ((prefix.
isV6() && len > 128) ||
66 (prefix.
isV4() && len > 32)) {
68 "Invalid prefix length specified for subnet: " << len);
77 return ((first <= addr) && (addr <= last));
82 std::stringstream tmp;
99 << static_cast<int>(type));
116 << static_cast<int>(type));
124 uint8_t hint_prefix_length)
const {
136 << static_cast<int>(type));
143 for (
auto const& p : pools) {
144 uint64_t x = p->getCapacity();
148 if (x > std::numeric_limits<uint64_t>::max() - sum) {
149 return (std::numeric_limits<uint64_t>::max());
162 for (
auto const& p : pools) {
163 if (!p->clientSupported(client_classes)) {
166 uint64_t x = p->getCapacity();
170 if (x > std::numeric_limits<uint64_t>::max() - sum) {
171 return (std::numeric_limits<uint64_t>::max());
184 uint8_t hint_prefix_length)
const {
186 for (
auto const& p : pools) {
187 if (!p->clientSupported(client_classes)) {
192 hint_prefix_length)) {
196 uint64_t x = p->getCapacity();
200 if (x > std::numeric_limits<uint64_t>::max() - sum) {
201 return (std::numeric_limits<uint64_t>::max());
210 std::pair<IOAddress, uint8_t>
212 auto pos = prefix.find(
'/');
213 if ((pos == std::string::npos) ||
214 (pos == prefix.size() - 1) ||
220 IOAddress address(prefix.substr(0, pos));
221 int length = boost::lexical_cast<
int>(prefix.substr(pos + 1));
222 return (std::make_pair(address, static_cast<int>(length)));
242 if (!prefix.
isV4()) {
244 <<
" specified in subnet4");
258 Subnet4Ptr subnet = boost::make_shared<Subnet4>
259 (prefix, length, t1, t2, valid_lifetime, id);
261 boost::make_shared<IterativeAllocator>
274 return (network->getNextSubnet(first_subnet,
getID()));
294 subnet = network->getNextSubnet(first_subnet, subnet_id);
297 if (subnet && subnet->clientSupported(client_classes)) {
312 if (network && !network->clientSupported(client_classes)) {
333 << static_cast<int>(type));
351 << static_cast<int>(type));
363 return (alloc->second);
379 return (state->second);
388 bool anypool )
const {
396 if (!pools.empty()) {
405 PoolCollection::const_iterator ub =
406 std::upper_bound(pools.begin(), pools.end(), hint,
407 prefixLessThanFirstAddress);
409 if (ub != pools.begin()) {
411 if ((*ub)->inRange(hint)) {
417 if (!candidate && anypool) {
418 candidate = *pools.begin();
436 if (!pools.empty()) {
437 PoolCollection::const_iterator ub =
438 std::upper_bound(pools.begin(), pools.end(), hint,
439 prefixLessThanFirstAddress);
441 if (ub != pools.begin()) {
443 if ((*ub)->inRange(hint) &&
444 (*ub)->clientSupported(client_classes)) {
457 checkType(pool->getType());
464 if (!
inRange(pool->getFirstAddress()) || !
inRange(pool->getLastAddress())) {
467 <<
", with the following address range: " 468 << pool->getFirstAddress() <<
"-" 469 << pool->getLastAddress() <<
" does not match" 470 <<
" the prefix of a subnet: " 472 <<
" to which it is being added");
477 bool overlaps =
false;
491 <<
", with the following address range: " 492 << pool->getFirstAddress() <<
"-" 493 << pool->getLastAddress() <<
" overlaps with " 494 "an existing pool in the subnet: " 496 <<
" to which it is being added");
502 pools_writable.push_back(pool);
505 std::sort(pools_writable.begin(), pools_writable.end(),
506 comparePoolFirstAddress);
524 for (
auto const& pool : pools) {
525 if (pool->inRange(addr)) {
545 for (
auto const& pool : pools) {
546 if (!pool->clientSupported(client_classes)) {
549 if (pool->inRange(addr)) {
580 PoolCollection::const_iterator pool3_it =
581 std::upper_bound(pools.begin(), pools.end(), pool->getFirstAddress(),
582 prefixLessThanFirstAddress);
594 if (pool3_it != pools.begin()) {
595 PoolPtr pool1 = *(pool3_it - 1);
597 if (pool->getFirstAddress() <= pool1->getLastAddress()) {
604 if (pool3_it != pools.end()) {
608 if (pool3->getFirstAddress() <= pool->getLastAddress()) {
623 if (!prefix.
isV6()) {
625 <<
" specified in subnet6");
642 Subnet6Ptr subnet = boost::make_shared<Subnet6>
643 (prefix, length, t1, t2, preferred_lifetime, valid_lifetime, id);
646 boost::make_shared<IterativeAllocator>
652 boost::make_shared<IterativeAllocator>
658 boost::make_shared<IterativeAllocator>
668 <<
"(" << static_cast<int>(type)
669 <<
"), must be TYPE_NA, TYPE_TA or TYPE_PD for Subnet6");
678 return (network->getNextSubnet(first_subnet,
getID()));
698 subnet = network->getNextSubnet(first_subnet, subnet_id);
701 if (subnet && subnet->clientSupported(client_classes)) {
715 if (network && !network->clientSupported(client_classes)) {
745 merge(map, network_map);
748 const Cfg4o6& d4o6 = get4o6();
754 for (
auto const& pool : pools) {
756 pool_list->add(pool->toElement());
758 map->set(
"pools", pool_list);
763 std::pair<IOAddress, uint8_t>
766 if (!parsed.first.isV4() || parsed.first.isV4Zero() ||
767 (parsed.second > 32) || (parsed.second == 0)) {
779 merge(map, network_map);
784 for (
auto const& pool : pools) {
786 pool_list->add(pool->toElement());
788 map->set(
"pools", pool_list);
793 for (
auto const& pool : pdpools) {
795 pdpool_list->add(pool->toElement());
797 map->set(
"pd-pools", pdpool_list);
802 std::pair<IOAddress, uint8_t>
805 if (!parsed.first.isV6() || parsed.first.isV6Zero() ||
806 (parsed.second > 128) || (parsed.second == 0)) {
static bool isValidPrefixPool(Allocator::PrefixLenMatchType prefix_length_match, PoolPtr pool, uint8_t hint_prefix_length)
Check if the pool matches the selection criteria relative to the provided hint prefix length...
Subnet4Ptr getNextSubnet(const Subnet4Ptr &first_subnet) const
Returns next subnet within shared network.
SubnetAllocationStatePtr getAllocationState(Lease::Type type) const
Returns subnet-specific allocation state.
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
bool inRange(const isc::asiolink::IOAddress &addr) const
checks if specified address is in range.
static Subnet4Ptr create(const isc::asiolink::IOAddress &prefix, uint8_t length, const util::Triplet< uint32_t > &t1, const util::Triplet< uint32_t > &t2, const util::Triplet< uint32_t > &valid_lifetime, const SubnetID id=0)
Factory function creating an instance of the Subnet4.
static std::string typeToText(Type type)
returns text representation of a lease type
Subnet4(const isc::asiolink::IOAddress &prefix, uint8_t length, const util::Triplet< uint32_t > &t1, const util::Triplet< uint32_t > &t2, const util::Triplet< uint32_t > &valid_lifetime, const SubnetID id=0)
Constructor with all parameters.
void setAllocator(Lease::Type type, const AllocatorPtr &allocator)
Sets new allocator instance.
static SubnetIterativeAllocationStatePtr create(const SubnetPtr &subnet)
Factory function creating the state instance from subnet.
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
void addPool(const PoolPtr &pool)
Adds a new pool for the subnet.
void setT1(const isc::util::Triplet< uint32_t > &t1)
Sets new renew timer for a network.
the lease contains IPv6 prefix (for prefix delegation)
boost::shared_ptr< Element > ElementPtr
std::vector< PoolPtr > PoolCollection
a container for either IPv4 or IPv6 Pools
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
std::map< Lease::Type, AllocatorPtr > allocators_
Lease allocators used by the subnet.
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
bool inPool(Lease::Type type, const isc::asiolink::IOAddress &addr) const
checks if the specified address is in pools.
void setAllocationState(Lease::Type type, const SubnetAllocationStatePtr &allocation_state)
Sets subnet-specific allocation state.
uint8_t prefix_len_
a prefix length of the subnet.
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.
static std::pair< asiolink::IOAddress, uint8_t > parsePrefix(const std::string &prefix)
Converts subnet prefix to a pair of prefix/length pair.
virtual data::ElementPtr toElement() const
Unparse a subnet object.
Specialization of the Network object for DHCPv6 case.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
SubnetID getID() const
Returns unique ID for that subnet.
#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...
AllocatorPtr getAllocator(Lease::Type type) const
Returns lease allocator instance.
PrefixLenMatchType
Type of preferred PD-pool prefix length selection criteria.
This structure contains information about DHCP4o6 (RFC7341)
Subnet6Ptr getNextSubnet(const Subnet6Ptr &first_subnet) const
Returns next subnet within shared network.
void getSharedNetwork(SharedNetworkPtrType &shared_network) const
Retrieves pointer to a shared network associated with a subnet.
const PoolCollection & getPools(Lease::Type type) const
Returns all pools (const variant).
boost::shared_ptr< SubnetAllocationState > SubnetAllocationStatePtr
static Subnet6Ptr create(const isc::asiolink::IOAddress &prefix, uint8_t length, const util::Triplet< uint32_t > &t1, const util::Triplet< uint32_t > &t2, const util::Triplet< uint32_t > &preferred_lifetime, const util::Triplet< uint32_t > &valid_lifetime, const SubnetID id=0)
Factory function creating an instance of the Subnet4.
virtual data::ElementPtr toElement() const
Unparse a subnet object.
uint64_t sumPoolCapacity(const PoolCollection &pools) const
Returns a sum of possible leases in all pools.
static std::pair< asiolink::IOAddress, uint8_t > parsePrefixCommon(const std::string &prefix)
Converts subnet prefix to a pair of prefix/length pair.
uint64_t getPoolCapacity(Lease::Type type) const
Returns the number of possible leases for specified lease type.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
isc::asiolink::IOAddress prefix_
a prefix of the subnet.
PoolCollection pools_
collection of IPv4 or non-temporary IPv6 pools in that subnet.
bool isV6() const
Convenience function to check for an IPv6 address.
the lease contains temporary IPv6 address
virtual bool clientSupported(const isc::dhcp::ClientClasses &client_classes) const
Checks whether this network supports client that belongs to specified classes.
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
bool isV4() const
Convenience function to check for an IPv4 address.
bool poolOverlaps(const Lease::Type &pool_type, const PoolPtr &pool) const
Checks if the specified pool overlaps with an existing pool.
the lease contains non-temporary IPv6 address
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
virtual data::ElementPtr toElement() const
Unparse a subnet object.
void setPreferred(const isc::util::Triplet< uint32_t > &preferred)
Sets new preferred lifetime for a network.
Defines the logger used by the top-level component of kea-lfc.
virtual data::ElementPtr toElement() const
Unparses network object.
std::string toText() const
Convert the address to a string.
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element.
PoolCollection & getPoolsWritable(Lease::Type type)
Returns all pools (non-const variant).
const PoolPtr getPool(Lease::Type type, const isc::asiolink::IOAddress &addr, bool anypool=true) const
Returns a pool that specified address belongs to.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Type
Type of lease or pool.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
static std::pair< asiolink::IOAddress, uint8_t > parsePrefix(const std::string &prefix)
Converts subnet prefix to a pair of prefix/length pair.
Specialization of the Network object for DHCPv4 case.
virtual bool clientSupported(const isc::dhcp::ClientClasses &client_classes) const
Checks whether this subnet and parent shared network supports the client that belongs to specified cl...
void delPools(Lease::Type type)
Deletes all pools of specified type.
void setValid(const isc::util::Triplet< uint32_t > &valid)
Sets new valid lifetime for a network.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
PoolCollection pools_ta_
collection of IPv6 temporary address pools in that subnet.
void setT2(const isc::util::Triplet< uint32_t > &t2)
Sets new rebind timer for a network.
The IOAddress class represents an IP addresses (version agnostic)
boost::shared_ptr< Allocator > AllocatorPtr
Defines a pointer to an allocator.
PoolCollection pools_pd_
collection of IPv6 prefix pools in that subnet.
Container for storing client class names.
virtual bool clientSupported(const isc::dhcp::ClientClasses &client_classes) const
Checks whether this subnet and parent shared network supports the client that belongs to specified cl...
virtual data::ElementPtr toElement() const
Unparses network object.
virtual std::string toText() const
Returns textual representation of the subnet (e.g.
std::map< Lease::Type, SubnetAllocationStatePtr > allocation_states_
Holds subnet-specific allocation state.
Subnet6(const isc::asiolink::IOAddress &prefix, uint8_t length, const util::Triplet< uint32_t > &t1, const util::Triplet< uint32_t > &t2, const util::Triplet< uint32_t > &preferred_lifetime, const util::Triplet< uint32_t > &valid_lifetime, const SubnetID id=0)
Constructor with all parameters.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.