| Kea 3.0.2-git

iterative_allocation_state.cc
Go to the documentation of this file.
1// Copyright (C) 2022-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>
8#include <asiolink/addr_utilities.h>
9#include <dhcpsrv/iterative_allocation_state.h>
10#include <util/multi_threading_mgr.h>
11#include <boost/date_time/posix_time/posix_time.hpp>
12#include <boost/make_shared.hpp>
13
14 using namespace isc::asiolink;
15 using namespace isc::util;
16
17 namespace isc {
18 namespace dhcp {
19
20 SubnetIterativeAllocationStatePtr
21 SubnetIterativeAllocationState::create(const SubnetPtr& subnet) {
22 auto subnet_prefix = subnet->get();
23 return (boost::make_shared<SubnetIterativeAllocationState>(subnet_prefix.first, subnet_prefix.second));
24}
25
26 SubnetIterativeAllocationState::SubnetIterativeAllocationState(const IOAddress& prefix,
27 const uint8_t prefix_length)
28 : SubnetAllocationState(),
29 last_allocated_(lastAddrInPrefix(prefix, prefix_length)) {
30}
31
32 IOAddress
33 SubnetIterativeAllocationState::getLastAllocated() const {
34 MultiThreadingLock lock(*mutex_);
35 return (last_allocated_);
36}
37
38 void
39 SubnetIterativeAllocationState::setLastAllocated(const IOAddress& address) {
40 MultiThreadingLock lock(*mutex_);
41 last_allocated_ = address;
42 // Update the timestamp of the last allocation.
43 setCurrentAllocatedTimeInternal();
44}
45
46 PoolIterativeAllocationStatePtr
47 PoolIterativeAllocationState::create(const PoolPtr& pool) {
48 return (boost::make_shared<PoolIterativeAllocationState>(pool->getFirstAddress()));
49}
50
51 PoolIterativeAllocationState::PoolIterativeAllocationState(const IOAddress& first)
52 : last_allocated_(first), last_allocated_valid_(false) {
53}
54
55} // end of namespace isc::dhcp
56} // end of namespace isc
addr_utilities.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::dhcp::PoolIterativeAllocationState::create
static PoolIterativeAllocationStatePtr create(const PoolPtr &pool)
Factory function creating the state instance from pool.
Definition iterative_allocation_state.cc:47
isc::dhcp::PoolIterativeAllocationState::PoolIterativeAllocationState
PoolIterativeAllocationState(const asiolink::IOAddress &first)
Constructor.
Definition iterative_allocation_state.cc:51
isc::dhcp::SubnetAllocationState::mutex_
boost::scoped_ptr< std::mutex > mutex_
Mutex used for thread-safe access to the state members.
Definition allocation_state.h:73
isc::dhcp::SubnetAllocationState::SubnetAllocationState
SubnetAllocationState()
Constructor.
Definition allocation_state.cc:17
isc::dhcp::SubnetAllocationState::setCurrentAllocatedTimeInternal
void setCurrentAllocatedTimeInternal()
Sets the last allocation time to current.
Definition allocation_state.cc:29
isc::dhcp::SubnetIterativeAllocationState::getLastAllocated
asiolink::IOAddress getLastAllocated() const
Returns last allocated address or prefix.
Definition iterative_allocation_state.cc:33
isc::dhcp::SubnetIterativeAllocationState::SubnetIterativeAllocationState
SubnetIterativeAllocationState(const asiolink::IOAddress &prefix, const uint8_t prefix_length)
Constructor.
Definition iterative_allocation_state.cc:26
isc::dhcp::SubnetIterativeAllocationState::setLastAllocated
void setLastAllocated(const asiolink::IOAddress &address)
Sets last allocated address or prefix.
Definition iterative_allocation_state.cc:39
isc::dhcp::SubnetIterativeAllocationState::create
static SubnetIterativeAllocationStatePtr create(const SubnetPtr &subnet)
Factory function creating the state instance from subnet.
Definition iterative_allocation_state.cc:21
iterative_allocation_state.h
multi_threading_mgr.h
isc::asiolink
Definition addr_utilities.cc:170
isc::asiolink::lastAddrInPrefix
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
Definition addr_utilities.cc:182
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::SubnetPtr
boost::shared_ptr< Subnet > SubnetPtr
A generic pointer to either Subnet4 or Subnet6 object.
Definition subnet.h:449
isc::dhcp::PoolPtr
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:726
isc::dhcp::PoolIterativeAllocationStatePtr
boost::shared_ptr< PoolIterativeAllocationState > PoolIterativeAllocationStatePtr
Type of the pointer to the PoolIterativeAllocationState.
Definition iterative_allocation_state.h:78
isc::dhcp::SubnetIterativeAllocationStatePtr
boost::shared_ptr< SubnetIterativeAllocationState > SubnetIterativeAllocationStatePtr
Type of the pointer to the SubnetIterativeAllocationState.
Definition iterative_allocation_state.h:25
isc::util
Definition time_utils.cc:43
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
isc::util::MultiThreadingLock
RAII lock object to protect the code in the same scope with a mutex.
Definition multi_threading_mgr.h:349