Kea 2.5.8
ip_range_permutation.h
Go to the documentation of this file.
1// Copyright (C) 2020-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 IP_RANGE_PERMUTATION_H
8#define IP_RANGE_PERMUTATION_H
9
10#include <asiolink/io_address.h>
11#include <dhcpsrv/ip_range.h>
12#include <util/bigints.h>
13
14#include <boost/shared_ptr.hpp>
15
16#include <map>
17#include <random>
18
19namespace isc {
20namespace dhcp {
21
68public:
69
73 IPRangePermutation(const AddressRange& range);
74
79 IPRangePermutation(const PrefixRange& range);
80
85 bool exhausted() const {
86 return (done_);
87 }
88
101 asiolink::IOAddress next(bool& done);
102
108 void reset();
109
110private:
111
113 asiolink::IOAddress range_start_;
114
119
124 isc::util::uint128_t cursor_;
125
127 isc::util::uint128_t initial_cursor_;
128
132 std::map<isc::util::uint128_t, asiolink::IOAddress> state_;
133
135 bool done_;
136
138 std::mt19937 generator_;
139};
140
142typedef boost::shared_ptr<IPRangePermutation> IPRangePermutationPtr;
143
144} // end of namespace isc::dhcp
145} // end of namespace isc
146
147#endif // IP_RANGE_PERMUTATION_H
Random IP address/prefix permutation based on Fisher-Yates shuffle.
asiolink::IOAddress next(bool &done)
Returns next random address or prefix from the permutation.
void reset()
Resets the permutation state.
bool exhausted() const
Checks if the range has been exhausted.
boost::shared_ptr< IPRangePermutation > IPRangePermutationPtr
Pointer to the IPRangePermutation.
boost::multiprecision::checked_uint128_t uint128_t
Definition: bigints.h:21
Defines the logger used by the top-level component of kea-lfc.
Structure representing IP address range.
Definition: ip_range.h:16
Structure representing delegated prefix range.
Definition: ip_range.h:32