Fix missing P4Runtime groups because of infinite delete/insert cycle

The fix is simple: when cleaning up inconsistent entries from device,
we update the mirror when the response is received, and not before
sending the request. Otherwise, if delete goes wrong, writes happening
right after reconciliation cycle might find an inconsistent mirror state.

When writing entries (e.g. apply group/flow rule) we keep updating the
mirror before sending the request to handled the case of back-to-back
writes.

Change-Id: I9e1cc5cac3f8746c67e93e2cee17aff78d3f1d7e
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/TimedEntry.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/TimedEntry.java
index 76b44a0..4b7170e 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/TimedEntry.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/mirror/TimedEntry.java
@@ -16,9 +16,12 @@
 
 package org.onosproject.drivers.p4runtime.mirror;
 
+import com.google.common.base.MoreObjects;
 import org.onosproject.net.pi.runtime.PiEntity;
 import org.onosproject.store.service.WallClockTimestamp;
 
+import java.util.Objects;
+
 public class TimedEntry<E extends PiEntity> {
 
     private final long timestamp;
@@ -41,4 +44,30 @@
         final long now = new WallClockTimestamp().unixTimestamp();
         return (now - timestamp) / 1000;
     }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(timestamp, entity);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        final TimedEntry other = (TimedEntry) obj;
+        return Objects.equals(this.timestamp, other.timestamp)
+                && Objects.equals(this.entity, other.entity);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("timestamp", timestamp)
+                .add("entity", entity)
+                .toString();
+    }
 }