19 : range_start_(range.start_), step_(1), cursor_(
addrsInRange(range_start_, range.end_) - 1),
20 initial_cursor_(cursor_), state_(), done_(false), generator_() {
21 std::random_device rd;
22 generator_.seed(rd());
26 : range_start_(range.start_), step_(
isc::util::uint128_t(1) << (128 - range.delegated_length_)),
27 cursor_(
prefixesInRange(range.prefix_length_, range.delegated_length_) - 1),
28 initial_cursor_(cursor_), state_(), done_(false), generator_() {
29 std::random_device rd;
30 generator_.seed(rd());
45 return (state_.at(0));
55 uint64_t max_limit = std::numeric_limits<uint64_t>::max();
57 max_limit =
static_cast<uint64_t
>(cursor_ - 1);
59 std::uniform_int_distribution<uint64_t> dist(0, max_limit);
60 auto next_loc = dist(generator_);
67 auto next_loc_existing = state_.find(next_loc);
68 if (next_loc_existing != state_.end()) {
70 next_loc_address = next_loc_existing->second;
77 next_loc_address =
offsetAddress(range_start_, next_loc * step_);
82 auto cursor_existing = state_.find(cursor_);
83 if (cursor_existing != state_.end()) {
84 cursor_address = cursor_existing->second;
86 cursor_address =
offsetAddress(range_start_, cursor_ * step_);
94 if (next_loc_existing == state_.end()) {
95 state_.insert(std::make_pair(next_loc, cursor_address));
97 state_.at(next_loc) = cursor_address;
103 return (next_loc_address);
109 cursor_ = initial_cursor_;
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
bool isV4() const
Convenience function to check for an IPv4 address.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
asiolink::IOAddress next(bool &done)
Returns next random address or prefix from the permutation.
void reset()
Resets the permutation state.
IPRangePermutation(const AddressRange &range)
Constructor for address ranges.
uint128_t addrsInRange(const IOAddress &min, const IOAddress &max)
Returns number of available addresses in the specified range (min - max).
uint128_t prefixesInRange(const uint8_t pool_len, const uint8_t delegated_len)
Returns number of available IPv6 prefixes in the specified prefix.
IOAddress offsetAddress(const IOAddress &addr, uint128_t offset)
Finds the address increased by offset.
boost::multiprecision::checked_int128_t int128_t
Defines the logger used by the top-level component of kea-lfc.
Structure representing IP address range.
Structure representing delegated prefix range.