HwVTEP support for interfacemanager
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / renderer / ovs / statehelpers / OvsInterfaceTopologyStateRemoveHelper.java
index dd4f25db0712bd1c118d37175d63a1bd7f21e866..c607bff946801c333599c84ffd6571a53421e7a2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers;
 
+import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -31,22 +32,25 @@ public class OvsInterfaceTopologyStateRemoveHelper {
     public static List<ListenableFuture<Void>> removePortFromBridge(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
                                                                OvsdbBridgeAugmentation bridgeOld, DataBroker dataBroker) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
-        WriteTransaction t = dataBroker.newWriteOnlyTransaction();;
+        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();;
         BigInteger dpnId = IfmUtil.getDpnId(bridgeOld.getDatapathId());
 
         if (dpnId == null) {
             LOG.warn("Got Null DPID for Bridge: {}", bridgeOld);
             return futures;
         }
-        BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
-        InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
-                InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
-        t.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId);
 
-        // FIX for ovsdb bug for delete TEP
-        SouthboundUtils.deleteBridge(bridgeIid, dataBroker, futures);
+        //delete bridge reference entry in interface meta operational DS
+        InterfaceMetaUtils.deleteBridgeRefEntry(dpnId, transaction);
 
-        futures.add(t.submit());
+        // Workaround for ovsdb bug for delete TEP..
+        Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
+                IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
+        if (!bridgeNodeOptional.isPresent()) {
+            SouthboundUtils.deleteBridge(bridgeIid, dataBroker, futures);
+        }
+
+        futures.add(transaction.submit());
         return futures;
     }
 }
\ No newline at end of file