mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-11-29 14:31:37 +01:00
MeterManager, check max meters before requesting a new meter
Change-Id: I5a5d55ede89bee46c6442b885fe64f231a14e165
This commit is contained in:
parent
aa8de49765
commit
21daebff4b
@ -30,6 +30,7 @@ import org.onosproject.net.meter.Meter;
|
|||||||
import org.onosproject.net.meter.MeterEvent;
|
import org.onosproject.net.meter.MeterEvent;
|
||||||
import org.onosproject.net.meter.MeterFailReason;
|
import org.onosproject.net.meter.MeterFailReason;
|
||||||
import org.onosproject.net.meter.MeterFeatures;
|
import org.onosproject.net.meter.MeterFeatures;
|
||||||
|
import org.onosproject.net.meter.MeterFeaturesKey;
|
||||||
import org.onosproject.net.meter.MeterId;
|
import org.onosproject.net.meter.MeterId;
|
||||||
import org.onosproject.net.meter.MeterKey;
|
import org.onosproject.net.meter.MeterKey;
|
||||||
import org.onosproject.net.meter.MeterListener;
|
import org.onosproject.net.meter.MeterListener;
|
||||||
@ -173,14 +174,26 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M
|
|||||||
}
|
}
|
||||||
|
|
||||||
private MeterId allocateMeterId(DeviceId deviceId) {
|
private MeterId allocateMeterId(DeviceId deviceId) {
|
||||||
|
long maxMeters = store.getMaxMeters(MeterFeaturesKey.key(deviceId));
|
||||||
|
|
||||||
|
if (maxMeters == 0L) {
|
||||||
|
throw new IllegalStateException("Meters not supported by device " + deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
final long mmeters = maxMeters;
|
||||||
long id = meterIdCounters.compute(deviceId, (k, v) -> {
|
long id = meterIdCounters.compute(deviceId, (k, v) -> {
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
return allocateCounter(k);
|
return allocateCounter(k);
|
||||||
}
|
}
|
||||||
|
if (v.get() >= mmeters) {
|
||||||
|
throw new IllegalStateException("Maximum number of meters " +
|
||||||
|
meterIdCounters.get(deviceId).get() +
|
||||||
|
" reached for device " + deviceId);
|
||||||
|
}
|
||||||
return v;
|
return v;
|
||||||
}).incrementAndGet();
|
}).incrementAndGet();
|
||||||
|
|
||||||
return MeterId.meterId((int) id);
|
return MeterId.meterId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AtomicCounter allocateCounter(DeviceId deviceId) {
|
private AtomicCounter allocateCounter(DeviceId deviceId) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user