Fix: add the kubevirt port to the store only if it is not existed

Remove all flows before remove bridge and ports

Change-Id: I8027bc19b70dce10612f8bc32da6062937299d89
(cherry picked from commit e66ed69033b65ad8ec1c6e1405f87b9be304cfd7)
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java
index 47f778a..b829980 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java
@@ -141,7 +141,8 @@
     private static final String DEFAULT_OF_PROTO = "tcp";
     private static final int DEFAULT_OFPORT = 6653;
     private static final int DPID_BEGIN = 3;
-    private static final long SLEEP_MS = 3000; // we wait 3s for init each node
+    private static final long SLEEP_MS = 3000;
+    private static final long SLEEP_LARGE_MS = 5000;
     private static final int DEFAULT_TTL = 0xff;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
@@ -311,6 +312,11 @@
         ifaceConfig.addPatchMode(tunToTenantIntf, brTunTenantPatchDesc);
     }
 
+    private void removeAllFlows(KubevirtNode node, KubevirtNetwork network) {
+        DeviceId deviceId = network.tenantDeviceId(node.hostname());
+        flowService.purgeRules(deviceId);
+    }
+
     private void removePatchInterface(KubevirtNode node, KubevirtNetwork network) {
         Device device = deviceService.getDevice(node.ovsdb());
 
@@ -1231,7 +1237,15 @@
             }
 
             nodeService.completeNodes(WORKER).forEach(n -> {
+                removeAllFlows(n, network);
                 removePatchInterface(n, network);
+
+                try {
+                    sleep(SLEEP_LARGE_MS);
+                } catch (InterruptedException e) {
+                    log.error("Sleep exception", e);
+                }
+
                 removeBridge(n, network);
             });
         }