1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2022-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef ALLOCATION_STATE_H
#define ALLOCATION_STATE_H

#include <dhcpsrv/lease.h>
#include <boost/scoped_ptr.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/shared_ptr.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/date_time/posix_time/posix_time.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <mutex><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace dhcp {

/// @brief Base class for representing allocation state in pools and subnets.
///
/// Allocators are used in Kea to implement different lease selection
/// algorithms. They are stateful (i.e., they remember various information
/// about the previous allocations) to work efficiently. For example, an
/// iterative allocator must remember the last allocated address to pick
/// the consecutive address when the new allocation request is issued.
/// Allocation states differ between the allocators. State classes used
/// by different allocators derive from this class.
///
/// The allocation states can be associated with pools and/or subnets.
/// Both pool-specific and subnet-specific states derive from this class.
class AllocationState {
public:

    /// @brief Virtual destructor.
    virtual ~AllocationState() = default;
};

/// @brief Type of the pointer to the @c AllocationState.
typedef boost::shared_ptr<AllocationState> AllocationStatePtr;

/// @brief Common base class for subnet-specific allocation states.
///
/// All subnet-specific allocation states should derive from this class.
/// It provides a mutex for thread-safe access to the class members.
/// It maintains last allocation times for various lease types. These
/// times are used by the shared networks to find the "preferred" subnet
/// (i.e., a subnet from which the latest lease was assigned).
class SubnetAllocationState : public AllocationState {
public:

    /// @brief Constructor.
    ///
    /// Initializes the mutex.
    SubnetAllocationState();

    /// @brief Returns last allocation time for the specified lease type.
    ///
    /// @return Last allocation time for the lease type or
    /// @c boost::posix_time::neg_infin when no leases have been allocated
    /// from this subnet yet.
    boost::posix_time::ptime
    getLastAllocatedTime() const;

protected:

    /// @brief Sets the last allocation time to current.
    ///
    /// This function should be called by derived classes. It should be
    /// called in the thread-safe context.
    void setCurrentAllocatedTimeInternal();

    /// @brief Mutex used for thread-safe access to the state members.
    boost::scoped_ptr<std::mutex> mutex_;

    /// @brief Timestamp indicating when a lease has been last allocated
    /// from the subnet.
    boost::posix_time::ptime last_allocated_time_;
};

typedef boost::shared_ptr<SubnetAllocationState> SubnetAllocationStatePtr;

} // end of namespace isc::dhcp
} // end of namespace isc

#endif // ALLOCATION_STATE_H