OF port deletion complete implementation
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / ItmInternalTunnelDeleteWorker.java
index e09a157723d8d771eee7d7354f3d2d38f47b6560..a330502ddec680dc605e355a43be053a51b24cd9 100644 (file)
@@ -23,7 +23,6 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.genius.cloudscaler.api.TombstonedNodeManager;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.cache.DpnTepStateCache;
-import org.opendaylight.genius.itm.cache.OfEndPointCache;
 import org.opendaylight.genius.itm.cache.OvsBridgeEntryCache;
 import org.opendaylight.genius.itm.cache.OvsBridgeRefEntryCache;
 import org.opendaylight.genius.itm.cache.TunnelStateCache;
@@ -51,7 +50,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeLogicalGroup;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.meta.rev171210.bridge.tunnel.info.OvsBridgeEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.meta.rev171210.bridge.tunnel.info.OvsBridgeEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.meta.rev171210.bridge.tunnel.info.ovs.bridge.entry.OvsBridgeTunnelEntry;
@@ -91,8 +89,6 @@ public class ItmInternalTunnelDeleteWorker {
     private final OvsBridgeRefEntryCache ovsBridgeRefEntryCache;
     private final TunnelStateCache tunnelStateCache;
     private final DirectTunnelUtils directTunnelUtils;
-    private final OfEndPointCache ofEndPointCache;
-    private final ItmConfig itmConfig;
     private final TombstonedNodeManager tombstonedNodeManager;
 
     public ItmInternalTunnelDeleteWorker(DataBroker dataBroker, JobCoordinator jobCoordinator,
@@ -102,8 +98,6 @@ public class ItmInternalTunnelDeleteWorker {
                                          OvsBridgeRefEntryCache ovsBridgeRefEntryCache,
                                          TunnelStateCache tunnelStateCache,
                                          DirectTunnelUtils directTunnelUtils,
-                                         OfEndPointCache ofEndPointCache,
-                                         ItmConfig itmConfig,
                                          TombstonedNodeManager tombstonedNodeManager) {
         this.dataBroker = dataBroker;
         this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
@@ -115,8 +109,6 @@ public class ItmInternalTunnelDeleteWorker {
         this.ovsBridgeRefEntryCache = ovsBridgeRefEntryCache;
         this.tunnelStateCache = tunnelStateCache;
         this.directTunnelUtils = directTunnelUtils;
-        this.ofEndPointCache = ofEndPointCache;
-        this.itmConfig = itmConfig;
         this.tombstonedNodeManager = tombstonedNodeManager;
     }
 
@@ -136,7 +128,6 @@ public class ItmInternalTunnelDeleteWorker {
             }
             for (DPNTEPsInfo srcDpn : dpnTepsList) {
                 LOG.trace("Processing srcDpn {}", srcDpn);
-
                 List<TunnelEndPoints> meshedEndPtCache = ItmUtils.getTEPsForDpn(srcDpn.getDPNID(), meshedDpnList);
                 if (meshedEndPtCache == null) {
                     LOG.debug("No Tunnel End Point configured for this DPN {}", srcDpn.getDPNID());
@@ -471,53 +462,39 @@ public class ItmInternalTunnelDeleteWorker {
             return;
         }
 
-        OvsdbBridgeRef ovsdbBridgeRef = getOvsdbBridgeRef(dpId);
-        Optional<OvsBridgeEntry> ovsBridgeEntryOptional = ovsBridgeEntryCache.get(dpId);
+        Optional<OvsBridgeRefEntry> ovsBridgeRefEntryOptional = ovsBridgeRefEntryCache.get(dpId);
+        Optional<OvsBridgeEntry> ovsBridgeEntryOptional;
+        OvsdbBridgeRef ovsdbBridgeRef = null;
+        if (ovsBridgeRefEntryOptional.isPresent()) {
+            ovsdbBridgeRef = ovsBridgeRefEntryOptional.get().getOvsBridgeReference();
+        } else {
+            ovsBridgeEntryOptional = ovsBridgeEntryCache.get(dpId);
+            if (ovsBridgeEntryOptional.isPresent()) {
+                ovsdbBridgeRef = ovsBridgeEntryOptional.get().getOvsBridgeReference();
+            }
+        }
+
+        if (ovsdbBridgeRef != null) {
+            removeTerminationEndPoint(ovsdbBridgeRef.getValue(), interfaceName);
+        }
+        removeTunnelIngressFlow(tx, interfaceName, dpId);
 
         // delete bridge to tunnel interface mappings
         OvsBridgeEntryKey bridgeEntryKey = new OvsBridgeEntryKey(dpId);
         InstanceIdentifier<OvsBridgeEntry> bridgeEntryIid =
                 DirectTunnelUtils.getOvsBridgeEntryIdentifier(bridgeEntryKey);
+        ovsBridgeEntryOptional = ovsBridgeEntryCache.get(dpId);
 
 
         if (ovsBridgeEntryOptional.isPresent()) {
             @NonNull Map<OvsBridgeTunnelEntryKey, OvsBridgeTunnelEntry> bridgeTunnelEntries =
                     ovsBridgeEntryOptional.get().nonnullOvsBridgeTunnelEntry();
 
-            if (ovsdbBridgeRef != null) {
-                if (!itmConfig.isUseOfTunnels()) {
-                    removeTerminationEndPoint(ovsdbBridgeRef.getValue(), interfaceName);
-                } else if (bridgeTunnelEntries.size() <= 1) {
-                    removeTerminationEndPoint(ovsdbBridgeRef.getValue(), ofEndPointCache.get(dpId));
-                    ofEndPointCache.remove(dpId);
-                }
-            }
-
             deleteBridgeInterfaceEntry(bridgeEntryKey, bridgeTunnelEntries, bridgeEntryIid, interfaceName);
             // IfIndex needs to be removed only during State Clean up not Config
+            cleanUpInterfaceWithUnknownState(interfaceName, parentRefs, ifTunnel);
+            directTunnelUtils.removeLportTagInterfaceMap(interfaceName);
         }
-
-        directTunnelUtils.deleteTunnelStateEntry(interfaceName);
-        // delete tunnel ingress flow
-        removeTunnelIngressFlow(tx, interfaceName, dpId);
-        directTunnelUtils.removeTunnelEgressFlow(tx, dpId, interfaceName);
-        cleanUpInterfaceWithUnknownState(interfaceName, parentRefs, ifTunnel);
-        directTunnelUtils.removeLportTagInterfaceMap(interfaceName);
-    }
-
-    private OvsdbBridgeRef getOvsdbBridgeRef(Uint64 dpId) throws ReadFailedException {
-        Optional<OvsBridgeRefEntry> ovsBridgeRefEntryOptional = ovsBridgeRefEntryCache.get(dpId);
-        Optional<OvsBridgeEntry> ovsBridgeEntryOptional;
-        OvsdbBridgeRef ovsdbBridgeRef = null;
-        if (ovsBridgeRefEntryOptional.isPresent()) {
-            ovsdbBridgeRef = ovsBridgeRefEntryOptional.get().getOvsBridgeReference();
-        } else {
-            ovsBridgeEntryOptional = ovsBridgeEntryCache.get(dpId);
-            if (ovsBridgeEntryOptional.isPresent()) {
-                ovsdbBridgeRef = ovsBridgeEntryOptional.get().getOvsBridgeReference();
-            }
-        }
-        return ovsdbBridgeRef;
     }
 
     private void removeTerminationEndPoint(InstanceIdentifier<?> bridgeIid, String interfaceName) {