@@ -20,18 +20,17 @@ namespace isc {
2020namespace dhcp {
2121
2222FreeLeaseQueue::FreeLeaseQueue ()
23- : containers_ () {
23+ : ranges_ () {
2424}
2525
2626void
2727FreeLeaseQueue::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
3736void
@@ -41,12 +40,12 @@ FreeLeaseQueue::addRange(const IOAddress& start, const IOAddress& end) {
4140
4241void
4342FreeLeaseQueue::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
5251void
@@ -58,16 +57,16 @@ FreeLeaseQueue::addRange(const asiolink::IOAddress& prefix, const uint8_t prefix
5857bool
5958FreeLeaseQueue::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) {
8685bool
8786FreeLeaseQueue::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
116115FreeLeaseQueue::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
123122void
124123FreeLeaseQueue::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
133132void
134133FreeLeaseQueue::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
140139bool
141140FreeLeaseQueue::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) {
152151bool
153152FreeLeaseQueue::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
0 commit comments