[ONOS-7382] Ensure flow tables are removed when last entry is removed

Change-Id: I967af049022faaf448ff474d88b9a707a6feb538
diff --git a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/ECFlowRuleStore.java b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/ECFlowRuleStore.java
index 266e6fb..64c09cf 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/ECFlowRuleStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/ECFlowRuleStore.java
@@ -827,15 +827,16 @@
 
         public FlowEntry remove(DeviceId deviceId, FlowEntry rule) {
             final AtomicReference<FlowEntry> removedRule = new AtomicReference<>();
-            getFlowEntriesInternal(rule.deviceId(), rule.id())
-                .computeIfPresent((StoredFlowEntry) rule, (k, stored) -> {
+            final Map<FlowId, Map<StoredFlowEntry, StoredFlowEntry>> flowTable = getFlowTable(deviceId);
+            flowTable.computeIfPresent(rule.id(), (flowId, flowEntries) -> {
+                flowEntries.computeIfPresent((StoredFlowEntry) rule, (k, stored) -> {
                     if (rule instanceof DefaultFlowEntry) {
                         DefaultFlowEntry toRemove = (DefaultFlowEntry) rule;
                         if (stored instanceof DefaultFlowEntry) {
                             DefaultFlowEntry storedEntry = (DefaultFlowEntry) stored;
                             if (toRemove.created() < storedEntry.created()) {
                                 log.debug("Trying to remove more recent flow entry {} (stored: {})",
-                                          toRemove, stored);
+                                    toRemove, stored);
                                 // the key is not updated, removedRule remains null
                                 return stored;
                             }
@@ -844,6 +845,8 @@
                     removedRule.set(stored);
                     return null;
                 });
+                return flowEntries.isEmpty() ? null : flowEntries;
+            });
 
             if (removedRule.get() != null) {
                 lastUpdateTimes.put(deviceId, System.currentTimeMillis());