ONOS-8053 bugfix to handle PENDING_REMOVE meter state properly.
* If a meter_stats_reply is received when the meter_state is
PENDING_REMOVE, do not change it to ADDED
* Use a pendingRemoveMeters set to send METER_REMOVED event
just once.
Change-Id: I0c78d6082e0b09aee5b843932d26f81ed6e26c84
diff --git a/core/store/dist/src/main/java/org/onosproject/store/meter/impl/DistributedMeterStore.java b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/DistributedMeterStore.java
index 0646e66..0b4e2a4 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/meter/impl/DistributedMeterStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/DistributedMeterStore.java
@@ -282,7 +282,10 @@
MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
meters.computeIfPresent(key, (k, v) -> {
DefaultMeter m = (DefaultMeter) v.meter();
- m.setState(meter.state());
+ MeterState meterState = m.state();
+ if (meterState == MeterState.PENDING_ADD) {
+ m.setState(meter.state());
+ }
m.setProcessedPackets(meter.packetsSeen());
m.setProcessedBytes(meter.bytesSeen());
m.setLife(meter.life());
@@ -329,11 +332,12 @@
// Remove the future
futures.remove(key);
// Remove the meter
- meters.remove(key);
- // Free the id
- freeMeterId(m.deviceId(), m.id());
- // Finally notify the delegate
- notifyDelegate(new MeterEvent(MeterEvent.Type.METER_REMOVED, m));
+ if (Versioned.valueOrNull(meters.remove(key)) != null) {
+ // Free the id
+ freeMeterId(m.deviceId(), m.id());
+ // Finally notify the delegate
+ notifyDelegate(new MeterEvent(MeterEvent.Type.METER_REMOVED, m));
+ }
}
@Override