Skip to content

Commit 3939643

Browse files
committed
[#1415] Renames in FreeLeaseQueue per review
Renamed: - Container to Leases, - ContainerDescriptor to RangeDescriptor - Containers to Ranges
1 parent 5cfc8f9 commit 3939643

File tree

2 files changed

+55
-56
lines changed

2 files changed

+55
-56
lines changed

src/lib/dhcpsrv/free_lease_queue.cc

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ namespace isc {
2020
namespace dhcp {
2121

2222
FreeLeaseQueue::FreeLeaseQueue()
23-
: containers_() {
23+
: ranges_() {
2424
}
2525

2626
void
2727
FreeLeaseQueue::addRange(const AddressRange& range) {
2828
// If the container with ranges is empty, there are is no need for
2929
// doing any checks. Let's just add the new range.
30-
if (!containers_.empty()) {
30+
if (!ranges_.empty()) {
3131
checkRangeOverlaps(range.start_, range.end_);
3232
}
33-
containers_.insert(ContainerDescriptor{range.start_, range.end_, 128,
34-
boost::make_shared<Container>()});
33+
ranges_.insert(RangeDescriptor{range.start_, range.end_, 128, boost::make_shared<Leases>()});
3534
}
3635

3736
void
@@ -41,12 +40,12 @@ FreeLeaseQueue::addRange(const IOAddress& start, const IOAddress& end) {
4140

4241
void
4342
FreeLeaseQueue::addRange(const PrefixRange& range) {
44-
if (!containers_.empty()) {
43+
if (!ranges_.empty()) {
4544
auto last_addr = offsetAddress(range.end_, range.delegated_length_ - 1);
4645
checkRangeOverlaps(range.start_, last_addr);
4746
}
48-
containers_.insert(ContainerDescriptor{range.start_, range.end_, range.delegated_length_,
49-
boost::make_shared<Container>()});
47+
ranges_.insert(RangeDescriptor{range.start_, range.end_, range.delegated_length_,
48+
boost::make_shared<Leases>()});
5049
}
5150

5251
void
@@ -58,16 +57,16 @@ FreeLeaseQueue::addRange(const asiolink::IOAddress& prefix, const uint8_t prefix
5857
bool
5958
FreeLeaseQueue::append(const IOAddress& address) {
6059
// If there are no ranges defined, there is nothing to do.
61-
if (containers_.empty()) {
60+
if (ranges_.empty()) {
6261
return (false);
6362
}
6463
// Find the beginning of the range which has the start address
6564
// greater than the address we're appending.
66-
auto lb = containers_.upper_bound(address);
65+
auto lb = ranges_.upper_bound(address);
6766
// If the range we found is the first one in the container
6867
// there is no range matching our address because all existing
6968
// ranges include higher addresses.
70-
if (lb == containers_.begin()) {
69+
if (lb == ranges_.begin()) {
7170
return (false);
7271
}
7372
--lb;
@@ -86,16 +85,16 @@ FreeLeaseQueue::append(const IOAddress& address) {
8685
bool
8786
FreeLeaseQueue::append(const IOAddress& prefix, const uint8_t delegated_length) {
8887
// If there are no ranges defined, there is nothing to do.
89-
if (containers_.empty()) {
88+
if (ranges_.empty()) {
9089
return (false);
9190
}
9291
// Find the beginning of the range which has the start address
9392
// greater than the address we're appending.
94-
auto lb = containers_.upper_bound(prefix);
93+
auto lb = ranges_.upper_bound(prefix);
9594
// If the range we found is the first one in the container
9695
// there is no range matching our prefix because all existing
9796
// ranges include higher addresses.
98-
if (lb == containers_.begin()) {
97+
if (lb == ranges_.begin()) {
9998
return (false);
10099
}
101100
--lb;
@@ -116,31 +115,31 @@ void
116115
FreeLeaseQueue::append(const AddressRange& range, const IOAddress& address) {
117116
// Make sure the address is within the range boundaries.
118117
checkRangeBoundaries(range, address);
119-
auto cont = getContainer(range);
118+
auto cont = getLeases(range);
120119
cont->insert(address);
121120
}
122121

123122
void
124123
FreeLeaseQueue::append(const uint64_t range_index, const IOAddress& ip) {
125-
auto desc = getContainerDescriptor(range_index);
124+
auto desc = getRangeDescriptor(range_index);
126125
if ((ip < desc.range_start_) || (desc.range_end_ < ip)) {
127126
isc_throw(BadValue, ip << " is not within the range of " << desc.range_start_
128127
<< ":" << desc.range_end_);
129128
}
130-
desc.container_->insert(ip);
129+
desc.leases_->insert(ip);
131130
}
132131

133132
void
134133
FreeLeaseQueue::append(const PrefixRange& range, const asiolink::IOAddress& prefix) {
135134
checkRangeBoundaries(range, prefix, true);
136-
auto cont = getContainer(range);
135+
auto cont = getLeases(range);
137136
cont->insert(prefix);
138137
}
139138

140139
bool
141140
FreeLeaseQueue::use(const AddressRange& range, const IOAddress& address) {
142141
checkRangeBoundaries(range, address);
143-
auto cont = getContainer(range);
142+
auto cont = getLeases(range);
144143
auto found = cont->find(address);
145144
if (found != cont->end()) {
146145
static_cast<void>(cont->erase(found));
@@ -152,7 +151,7 @@ FreeLeaseQueue::use(const AddressRange& range, const IOAddress& address) {
152151
bool
153152
FreeLeaseQueue::use(const PrefixRange& range, const IOAddress& prefix) {
154153
checkRangeBoundaries(range, prefix, true);
155-
auto cont = getContainer(range);
154+
auto cont = getLeases(range);
156155
auto found = cont->find(prefix);
157156
if (found != cont->end()) {
158157
static_cast<void>(cont->erase(found));
@@ -176,13 +175,13 @@ FreeLeaseQueue::checkRangeOverlaps(const IOAddress& start, const IOAddress& end)
176175
// Get the next range in the container relative to the start of the new
177176
// range. The upper_bound returns the range which starts after the start
178177
// of the new range.
179-
auto next_range = containers_.lower_bound(start);
178+
auto next_range = ranges_.lower_bound(start);
180179
// Get the range the range that is before that one. It is also possible that
181180
// there is no previous range in which case we default to end().
182-
auto previous_range = containers_.end();
181+
auto previous_range = ranges_.end();
183182
// If the next range is at the beginning of the container there is no
184183
// previous range.
185-
if (next_range != containers_.begin()) {
184+
if (next_range != ranges_.begin()) {
186185
// This should work fine even if the next range is set to end(). We
187186
// will get the range that is one position before end() and that
188187
// should be the range that goes before the new one.
@@ -199,50 +198,50 @@ FreeLeaseQueue::checkRangeOverlaps(const IOAddress& start, const IOAddress& end)
199198
// are constructed such that the end must be greater or equal the start
200199
// it is sufficient to check that the start of the new range is not lower
201200
// or equal the end of the previous range.
202-
if ((previous_range != containers_.end()) &&
201+
if ((previous_range != ranges_.end()) &&
203202
(start <= previous_range->range_end_)) {
204203
isc_throw(BadValue, "new address range " << start << ":" << end
205204
<< " overlaps with the existing range");
206205
}
207206

208207
// If the next range exists, let's check that the end of the new range
209208
// is neither within that range nor higher.
210-
if ((next_range != containers_.end()) &&
209+
if ((next_range != ranges_.end()) &&
211210
(next_range->range_start_ <= end)) {
212211
isc_throw(BadValue, "new address range " << start << ":" << end
213212
<< " overlaps with the existing range");
214213
}
215214
}
216215

217216

218-
FreeLeaseQueue::ContainerPtr
219-
FreeLeaseQueue::getContainer(const AddressRange& range) const {
220-
auto cont = containers_.find(range.start_);
221-
if (cont == containers_.end()) {
217+
FreeLeaseQueue::LeasesPtr
218+
FreeLeaseQueue::getLeases(const AddressRange& range) const {
219+
auto cont = ranges_.find(range.start_);
220+
if (cont == ranges_.end()) {
222221
isc_throw(BadValue, "conatiner for the specified address range " << range.start_
223222
<< ":" << range.end_ << " does not exist");
224223
}
225-
return (cont->container_);
224+
return (cont->leases_);
226225
}
227226

228-
FreeLeaseQueue::ContainerPtr
229-
FreeLeaseQueue::getContainer(const PrefixRange& range) const {
230-
auto cont = containers_.find(range.start_);
231-
if (cont == containers_.end()) {
227+
FreeLeaseQueue::LeasesPtr
228+
FreeLeaseQueue::getLeases(const PrefixRange& range) const {
229+
auto cont = ranges_.find(range.start_);
230+
if (cont == ranges_.end()) {
232231
isc_throw(BadValue, "conatiner for the specified prefix " << range.start_
233232
<< " and delegated length of " << static_cast<int>(range.delegated_length_)
234233
<< " does not exist");
235234
}
236-
return (cont->container_);
235+
return (cont->leases_);
237236
}
238237

239-
FreeLeaseQueue::ContainerDescriptor
240-
FreeLeaseQueue::getContainerDescriptor(const uint64_t range_index) const {
241-
if (containers_.get<2>().size() <= range_index) {
238+
FreeLeaseQueue::RangeDescriptor
239+
FreeLeaseQueue::getRangeDescriptor(const uint64_t range_index) const {
240+
if (ranges_.get<2>().size() <= range_index) {
242241
isc_throw(BadValue, "conatiner for the specified range index " << range_index
243242
<< " does not exist");
244243
}
245-
auto cont = containers_.get<2>().at(range_index);
244+
auto cont = ranges_.get<2>().at(range_index);
246245
return (cont);
247246
}
248247

src/lib/dhcpsrv/free_lease_queue.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class FreeLeaseQueue {
126126
/// @return true if the range existed and was removed.
127127
template<typename RangeType>
128128
bool removeRange(const RangeType& range) {
129-
return (containers_.get<1>().erase(range.start_) > 0);
129+
return (ranges_.get<1>().erase(range.start_) > 0);
130130
}
131131

132132
/// @brief Appends an address at the end of the queue for a range.
@@ -257,12 +257,12 @@ class FreeLeaseQueue {
257257
/// @throw BadValue if the range does not exist.
258258
template<typename RangeType>
259259
uint64_t getRangeIndex(const RangeType& range) const {
260-
auto cont = containers_.get<1>().find(range.start_);
261-
if (cont == containers_.get<1>().end()) {
260+
auto cont = ranges_.get<1>().find(range.start_);
261+
if (cont == ranges_.get<1>().end()) {
262262
isc_throw(BadValue, "conatiner for the specified range " << range.start_
263263
<< ":" << range.end_ << " does not exist");
264264
}
265-
return (std::distance(containers_.get<2>().begin(), containers_.project<2>(cont)));
265+
return (std::distance(ranges_.get<2>().begin(), ranges_.project<2>(cont)));
266266
}
267267

268268
private:
@@ -281,22 +281,22 @@ class FreeLeaseQueue {
281281
>,
282282
boost::multi_index::sequenced<>
283283
>
284-
> Container;
284+
> Leases;
285285

286286
/// Pointer to the container of free leases for a range.
287-
typedef boost::shared_ptr<Container> ContainerPtr;
287+
typedef boost::shared_ptr<Leases> LeasesPtr;
288288

289289
/// @brief Helper structure associating a range with the container of
290290
/// free leases.
291-
struct ContainerDescriptor {
291+
struct RangeDescriptor {
292292
/// Range start.
293293
asiolink::IOAddress range_start_;
294294
/// Range end.
295295
asiolink::IOAddress range_end_;
296296
/// Delegated length (used in prefix delegation).
297297
uint8_t delegated_length_;
298298
/// Container holding free addresses for the range.
299-
ContainerPtr container_;
299+
LeasesPtr leases_;
300300
};
301301

302302
/// @brief Collection (container) of containers for various ranges.
@@ -306,19 +306,19 @@ class FreeLeaseQueue {
306306
/// range start value. The second index is the random access index allowing
307307
/// faster access once the range index is known.
308308
typedef boost::multi_index_container<
309-
ContainerDescriptor,
309+
RangeDescriptor,
310310
boost::multi_index::indexed_by<
311311
boost::multi_index::ordered_unique<
312-
boost::multi_index::member<ContainerDescriptor, asiolink::IOAddress,
313-
&ContainerDescriptor::range_start_>
312+
boost::multi_index::member<RangeDescriptor, asiolink::IOAddress,
313+
&RangeDescriptor::range_start_>
314314
>,
315315
boost::multi_index::hashed_unique<
316-
boost::multi_index::member<ContainerDescriptor, asiolink::IOAddress,
317-
&ContainerDescriptor::range_start_>
316+
boost::multi_index::member<RangeDescriptor, asiolink::IOAddress,
317+
&RangeDescriptor::range_start_>
318318
>,
319319
boost::multi_index::random_access<>
320320
>
321-
> Containers;
321+
> Ranges;
322322

323323
/// @brief Checks if the specified address or delegated prefix is within the
324324
/// range.
@@ -347,14 +347,14 @@ class FreeLeaseQueue {
347347
/// @param range range for which the container should be returned.
348348
/// @return Pointer to the container (if found).
349349
/// @throw BadValue if the specified range does not exist.
350-
ContainerPtr getContainer(const AddressRange& range) const;
350+
LeasesPtr getContainer(const AddressRange& range) const;
351351

352352
/// @brief Returns container for a given prefix range.
353353
///
354354
/// @param range range for which the container should be returned.
355355
/// @return Pointer to the container (if found).
356356
/// @throw BadValue if the specified range does not exist.
357-
ContainerPtr getContainer(const PrefixRange& range) const;
357+
LeasesPtr getContainer(const PrefixRange& range) const;
358358

359359
/// @brief Returns container descriptor for a given range index.
360360
///
@@ -365,7 +365,7 @@ class FreeLeaseQueue {
365365
/// returned.
366366
/// @return Range descriptor if found.
367367
/// @throw BadValue if the range with the given index does not exist.
368-
ContainerDescriptor getContainerDescriptor(const uint64_t range_index) const;
368+
RangeDescriptor getContainerDescriptor(const uint64_t range_index) const;
369369

370370
/// @brief This is internal implemenation of the @c next and @c pop
371371
/// methods.
@@ -394,7 +394,7 @@ class FreeLeaseQueue {
394394

395395
/// @brief Holds a collection of containers with free leases for each
396396
/// address range.
397-
Containers containers_;
397+
Ranges ranges_;
398398
};
399399

400400
} // end of namespace isc::dhcp

0 commit comments

Comments
 (0)