ONOS-5958 Meter restoration to device
Change-Id: I55e72c5779c450027951016bbbc9cf93f076c34e
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java
index 9aed99b..62b77de 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/meter/impl/MeterManager.java
@@ -245,6 +245,20 @@
Map<Pair<DeviceId, MeterId>, Meter> storedMeterMap = store.getAllMeters().stream()
.collect(Collectors.toMap(m -> Pair.of(m.deviceId(), m.id()), Function.identity()));
+ Map<MeterId, Meter> meterEntriesMap = meterEntries.stream()
+ .collect(Collectors.toMap(Meter::id, Meter -> Meter));
+
+ storedMeterMap.keySet().stream()
+ .filter(m -> m.getLeft().equals(deviceId)).forEach(m -> {
+ if (!meterEntriesMap.containsKey(m.getRight())) {
+ // The meter is missing in the device. Reinstall!
+ Meter meter = storedMeterMap.get(Pair.of(deviceId, m.getRight()));
+ provider().performMeterOperation(deviceId,
+ new MeterOperation(meter, MeterOperation.Type.ADD));
+ }
+
+ });
+
meterEntries.stream()
.filter(m -> storedMeterMap.remove(Pair.of(m.deviceId(), m.id())) != null)
.forEach(m -> store.updateMeterState(m));