Coverage Report

Created: 2026-05-16 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kea/src/lib/dhcpsrv/random_allocation_state.h
Line
Count
Source
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
#ifndef RANDOM_ALLOCATION_STATE_H
8
#define RANDOM_ALLOCATION_STATE_H
9
10
#include <dhcpsrv/allocation_state.h>
11
#include <dhcpsrv/ip_range_permutation.h>
12
#include <dhcpsrv/pool.h>
13
#include <boost/shared_ptr.hpp>
14
#include <cstdint>
15
16
namespace isc {
17
namespace dhcp {
18
19
/// @brief Forward declaration of the @c PoolRandomAllocationState.
20
class PoolRandomAllocationState;
21
22
/// @brief Type of the pointer to the @c PoolRandomAllocationState.
23
typedef boost::shared_ptr<PoolRandomAllocationState> PoolRandomAllocationStatePtr;
24
25
/// @brief Pool allocation state used by the random allocator.
26
///
27
/// It extends the base class with the mechanism that maintains
28
/// an address or delegated prefix pool permutation. The
29
/// permutation serves random, non-repeating leases.
30
class PoolRandomAllocationState : public AllocationState {
31
public:
32
33
    /// @brief Factory function creating the state instance from pool.
34
    ///
35
    /// @param pool instance of the pool for which the allocation state
36
    /// should be instantiated.
37
    /// @return new allocation state instance.
38
    static PoolRandomAllocationStatePtr create(const PoolPtr& pool);
39
40
    /// @brief Constructor from an IP address pool.
41
    ///
42
    /// @param first first address in the pool.
43
    /// @param last last address in the pool.
44
    PoolRandomAllocationState(const asiolink::IOAddress& first,
45
                              const asiolink::IOAddress& last);
46
47
    /// @brief Constructor from a delegated prefix pool.
48
    ///
49
    /// @param first first address in the pool.
50
    /// @param last last prefix in the pool.
51
    /// @param delegated delegated prefix length.
52
    PoolRandomAllocationState(const asiolink::IOAddress& first,
53
                              const asiolink::IOAddress& last,
54
                              const uint8_t delegated);
55
56
    /// @brief Returns a pointer to the permutation of addresses
57
    /// or delegated prefixes.
58
    ///
59
    /// @return permutation instance.
60
0
    IPRangePermutationPtr getPermutation() const {
61
0
        return (permutation_);
62
0
    }
63
64
private:
65
66
    /// @brief Permutation instance for the pool.
67
    IPRangePermutationPtr permutation_;
68
};
69
70
71
} // end of isc::dhcp namespace
72
} // end of isc namespace
73
74
#endif // RANDOM_ALLOCATION_STATE_H