Kea 2.7.5
flq_allocation_state.cc
Go to the documentation of this file.
1// Copyright (C) 2023 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#include <config.h>
9#include <boost/make_shared.hpp>
10
11using namespace isc::asiolink;
12
13namespace isc {
14namespace dhcp {
15
18 return (boost::make_shared<PoolFreeLeaseQueueAllocationState>(pool->getType()));
19}
20
22 : AllocationState(), free_lease4_queue_(), free_lease6_queue_() {
23 if (type == Lease::TYPE_V4) {
24 free_lease4_queue_ = boost::make_shared<FreeLeaseQueue<uint32_t>>();
25 } else {
26 free_lease6_queue_ = boost::make_shared<FreeLeaseQueue<IOAddress>>();
27 }
28}
29
30bool
32 return ((free_lease4_queue_ && free_lease4_queue_->empty()) ||
33 (free_lease6_queue_ && free_lease6_queue_->empty()));
34}
35
36void
38 if (free_lease4_queue_) {
39 free_lease4_queue_->push_back(address.toUint32());
40 } else {
41 free_lease6_queue_->push_back(address);
42 }
43}
44
45void
47 if (free_lease4_queue_) {
48 auto& idx = free_lease4_queue_->get<1>();
49 idx.erase(address.toUint32());
50 } else {
51 auto& idx = free_lease6_queue_->get<1>();
52 idx.erase(address);
53 }
54}
55
58 if (free_lease4_queue_) {
59 if (free_lease4_queue_->empty()) {
61 }
62 uint32_t lease = free_lease4_queue_->front();
63 free_lease4_queue_->pop_front();
64 free_lease4_queue_->push_back(lease);
65 return (IOAddress(lease));
66 }
67
68 if (free_lease6_queue_->empty()) {
70 }
71 IOAddress lease = free_lease6_queue_->front();
72 free_lease6_queue_->pop_front();
73 free_lease6_queue_->push_back(lease);
74 return (lease);
75}
76
77size_t
79 if (free_lease4_queue_) {
80 return (free_lease4_queue_->size());
81 }
82 return (free_lease6_queue_->size());
83}
84
85} // end of namespace isc::dhcp
86} // end of namespace isc
87
Base class for representing allocation state in pools and subnets.
asiolink::IOAddress offerFreeLease()
Returns next available lease.
PoolFreeLeaseQueueAllocationState(Lease::Type type)
Constructor.
bool exhausted() const
Checks if the pool has run out of free leases.
void deleteFreeLease(const asiolink::IOAddress &address)
Deletes free lease from the queue.
void addFreeLease(const asiolink::IOAddress &address)
Adds a free lease to the queue.
static PoolFreeLeaseQueueAllocationStatePtr create(const PoolPtr &pool)
Factory function creating the state instance from a pool.
size_t getFreeLeaseCount() const
Returns the current number of free leases in the queue.
boost::shared_ptr< PoolFreeLeaseQueueAllocationState > PoolFreeLeaseQueueAllocationStatePtr
Type of the pointer to the PoolFreeLeaseQueueAllocationState.
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:488
Defines the logger used by the top-level component of kea-lfc.
Type
Type of lease or pool.
Definition lease.h:46
@ TYPE_V4
IPv4 lease.
Definition lease.h:50