genius/interfacemanager annotation based bp
[genius.git] / interfacemanager / interfacemanager-impl / src / main / java / org / opendaylight / genius / interfacemanager / commons / InterfaceMetaUtils.java
index 632da11155dc17a703873a968905d03ede92c273..bee8a9e39f20e8a8f80a903097907b3fe3194b12 100644 (file)
@@ -7,12 +7,27 @@
  */
 package org.opendaylight.genius.interfacemanager.commons;
 
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+
 import java.math.BigInteger;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.Datastore.Operational;
+import org.opendaylight.genius.infra.TypedReadTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.IfmConstants;
 import org.opendaylight.genius.interfacemanager.IfmUtil;
 import org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.BatchingUtils;
@@ -48,14 +63,29 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class InterfaceMetaUtils {
+@Singleton
+public final class InterfaceMetaUtils {
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceMetaUtils.class);
-    private static ConcurrentHashMap<BigInteger, BridgeEntry> bridgeEntryMap = new ConcurrentHashMap();
-    private static ConcurrentHashMap<BigInteger, BridgeRefEntry> bridgeRefEntryMap = new ConcurrentHashMap();
+
+    private final DataBroker dataBroker;
+    private final IdManagerService idManager;
+    private final BatchingUtils batchingUtils;
+    private final ConcurrentMap<BigInteger, BridgeEntry> bridgeEntryMap = new ConcurrentHashMap<>();
+    private final ConcurrentMap<BigInteger, BridgeRefEntry> bridgeRefEntryMap = new ConcurrentHashMap<>();
+
+    @Inject
+    public InterfaceMetaUtils(@Reference DataBroker dataBroker,
+                              IdManagerService idManager,
+                              BatchingUtils batchingUtils) {
+        this.dataBroker = dataBroker;
+        this.idManager = idManager;
+        this.batchingUtils = batchingUtils;
+    }
 
     public static InstanceIdentifier<BridgeRefEntry> getBridgeRefEntryIdentifier(BridgeRefEntryKey bridgeRefEntryKey) {
         InstanceIdentifier.InstanceIdentifierBuilder<BridgeRefEntry> bridgeRefEntryInstanceIdentifierBuilder =
@@ -64,7 +94,19 @@ public class InterfaceMetaUtils {
         return bridgeRefEntryInstanceIdentifierBuilder.build();
     }
 
-    public static BridgeRefEntry getBridgeRefEntryFromOperDS(BigInteger dpId, DataBroker dataBroker) {
+    public BridgeRefEntry getBridgeRefEntryFromOperationalDS(BigInteger dpId) {
+        BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpId);
+        InstanceIdentifier<BridgeRefEntry> bridgeRefEntryIid = InterfaceMetaUtils
+                .getBridgeRefEntryIdentifier(bridgeRefEntryKey);
+        BridgeRefEntry bridgeRefEntry = IfmUtil.read(LogicalDatastoreType.OPERATIONAL,
+                bridgeRefEntryIid, dataBroker).orNull();
+        if (bridgeRefEntry != null) {
+            addBridgeRefEntryToCache(dpId, bridgeRefEntry);
+        }
+        return bridgeRefEntry;
+    }
+
+    public BridgeRefEntry getBridgeRefEntryFromOperDS(BigInteger dpId) {
         BridgeRefEntry bridgeRefEntry = getBridgeRefEntryFromCache(dpId);
         if (bridgeRefEntry != null) {
             return bridgeRefEntry;
@@ -79,14 +121,14 @@ public class InterfaceMetaUtils {
         return bridgeRefEntry;
     }
 
-    public static OvsdbBridgeRef getOvsdbBridgeRef(BigInteger dpId, DataBroker dataBroker) {
+    public OvsdbBridgeRef getOvsdbBridgeRef(BigInteger dpId) {
 
-        BridgeRefEntry bridgeRefEntry = getBridgeRefEntryFromOperDS(dpId, dataBroker);
+        BridgeRefEntry bridgeRefEntry = getBridgeRefEntryFromOperDS(dpId);
 
         if (bridgeRefEntry == null) {
             // bridge ref entry will be null if the bridge is disconnected from controller.
             // In that case, fetch bridge reference from bridge interface entry config DS
-            BridgeEntry bridgeEntry = getBridgeEntryFromConfigDS(dpId, dataBroker);
+            BridgeEntry bridgeEntry = getBridgeEntryFromConfigDS(dpId);
             if (bridgeEntry == null) {
                 return null;
             }
@@ -95,15 +137,13 @@ public class InterfaceMetaUtils {
         return bridgeRefEntry.getBridgeReference();
     }
 
-    public static BridgeRefEntry getBridgeReferenceForInterface(Interface interfaceInfo,
-                                                                DataBroker dataBroker) {
-        ParentRefs parentRefs = interfaceInfo.getAugmentation(ParentRefs.class);
+    public BridgeRefEntry getBridgeReferenceForInterface(Interface interfaceInfo) {
+        ParentRefs parentRefs = interfaceInfo.augmentation(ParentRefs.class);
         BigInteger dpn = parentRefs.getDatapathNodeIdentifier();
-        return getBridgeRefEntryFromOperDS(dpn, dataBroker);
+        return getBridgeRefEntryFromOperDS(dpn);
     }
 
-    public static boolean bridgeExists(BridgeRefEntry bridgeRefEntry,
-                                       DataBroker dataBroker) {
+    public boolean bridgeExists(BridgeRefEntry bridgeRefEntry) {
         if (bridgeRefEntry != null && bridgeRefEntry.getBridgeReference() != null) {
             InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
                     (InstanceIdentifier<OvsdbBridgeAugmentation>) bridgeRefEntry.getBridgeReference().getValue();
@@ -118,8 +158,7 @@ public class InterfaceMetaUtils {
         return bridgeEntryIdBuilder.build();
     }
 
-    public static BridgeEntry getBridgeEntryFromConfigDS(BigInteger dpnId,
-                                                         DataBroker dataBroker) {
+    public BridgeEntry getBridgeEntryFromConfigDS(BigInteger dpnId) {
         BridgeEntry bridgeEntry = getBridgeEntryFromCache(dpnId);
         if (bridgeEntry != null) {
             return bridgeEntry;
@@ -128,22 +167,20 @@ public class InterfaceMetaUtils {
         InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier =
                 InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey);
         LOG.debug("Trying to retrieve bridge entry from config for Id: {}", bridgeEntryInstanceIdentifier);
-        bridgeEntry = readBridgeEntryFromConfigDS(bridgeEntryInstanceIdentifier,
-                dataBroker);
+        bridgeEntry = readBridgeEntryFromConfigDS(bridgeEntryInstanceIdentifier);
         if (bridgeEntry != null) {
             addBridgeEntryToCache(dpnId, bridgeEntry);
         }
         return bridgeEntry;
     }
 
-    public static BridgeEntry getBridgeEntryFromConfigDS(InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier,
-            DataBroker dataBroker) {
+    public BridgeEntry getBridgeEntryFromConfigDS(InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier) {
         BigInteger dpnId = bridgeEntryInstanceIdentifier.firstKeyOf(BridgeEntry.class).getDpid();
-        return getBridgeEntryFromConfigDS(dpnId, dataBroker);
+        return getBridgeEntryFromConfigDS(dpnId);
     }
 
-    private static BridgeEntry readBridgeEntryFromConfigDS(
-            InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier, DataBroker dataBroker) {
+    private BridgeEntry readBridgeEntryFromConfigDS(
+            InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier) {
         return IfmUtil.read(LogicalDatastoreType.CONFIGURATION, bridgeEntryInstanceIdentifier, dataBroker).orNull();
     }
 
@@ -155,15 +192,14 @@ public class InterfaceMetaUtils {
 
     }
 
-    public static void createBridgeInterfaceEntryInConfigDS(BigInteger dpId,
-                                                            String childInterface) {
+    public void createBridgeInterfaceEntryInConfigDS(BigInteger dpId, String childInterface) {
         BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpId);
         BridgeInterfaceEntryKey bridgeInterfaceEntryKey = new BridgeInterfaceEntryKey(childInterface);
         InstanceIdentifier<BridgeInterfaceEntry> bridgeInterfaceEntryIid =
                 InterfaceMetaUtils.getBridgeInterfaceEntryIdentifier(bridgeEntryKey, bridgeInterfaceEntryKey);
-        BridgeInterfaceEntryBuilder entryBuilder = new BridgeInterfaceEntryBuilder().setKey(bridgeInterfaceEntryKey)
+        BridgeInterfaceEntryBuilder entryBuilder = new BridgeInterfaceEntryBuilder().withKey(bridgeInterfaceEntryKey)
                 .setInterfaceName(childInterface);
-        BatchingUtils.write(bridgeInterfaceEntryIid, entryBuilder.build(), BatchingUtils.EntityType.DEFAULT_CONFIG);
+        batchingUtils.write(bridgeInterfaceEntryIid, entryBuilder.build(), BatchingUtils.EntityType.DEFAULT_CONFIG);
     }
 
     public static InstanceIdentifier<InterfaceParentEntry> getInterfaceParentEntryIdentifier(
@@ -183,51 +219,68 @@ public class InterfaceMetaUtils {
         return intfIdBuilder.build();
     }
 
-    public static InterfaceParentEntry getInterfaceParentEntryFromConfigDS(
-            String interfaceName, DataBroker dataBroker) {
+    @Deprecated
+    public InterfaceParentEntry getInterfaceParentEntryFromConfigDS(String interfaceName) {
+        InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(interfaceName);
+        InterfaceParentEntry interfaceParentEntry = getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey);
+        return interfaceParentEntry;
+    }
+
+    public InterfaceParentEntry getInterfaceParentEntryFromConfigDS(ReadTransaction tx, String interfaceName)
+            throws ReadFailedException {
         InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(interfaceName);
-        InterfaceParentEntry interfaceParentEntry =
-                InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
+        InterfaceParentEntry interfaceParentEntry = getInterfaceParentEntryFromConfigDS(tx, interfaceParentEntryKey);
         return interfaceParentEntry;
     }
 
-    public static InterfaceParentEntry getInterfaceParentEntryFromConfigDS(
-            InterfaceParentEntryKey interfaceParentEntryKey, DataBroker dataBroker) {
+    @Deprecated
+    public InterfaceParentEntry getInterfaceParentEntryFromConfigDS(InterfaceParentEntryKey interfaceParentEntryKey) {
+        InstanceIdentifier<InterfaceParentEntry> intfParentIid =
+                getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+
+        return getInterfaceParentEntryFromConfigDS(intfParentIid);
+    }
+
+    public InterfaceParentEntry getInterfaceParentEntryFromConfigDS(ReadTransaction tx,
+            InterfaceParentEntryKey interfaceParentEntryKey) throws ReadFailedException {
         InstanceIdentifier<InterfaceParentEntry> intfParentIid =
                 getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
 
-        return getInterfaceParentEntryFromConfigDS(intfParentIid, dataBroker);
+        return getInterfaceParentEntryFromConfigDS(tx, intfParentIid);
     }
 
-    public static InterfaceParentEntry getInterfaceParentEntryFromConfigDS(
-            InstanceIdentifier<InterfaceParentEntry> intfId, DataBroker dataBroker) {
+    public InterfaceParentEntry getInterfaceParentEntryFromConfigDS(InstanceIdentifier<InterfaceParentEntry> intfId) {
         return IfmUtil.read(LogicalDatastoreType.CONFIGURATION, intfId, dataBroker).orNull();
     }
 
-    public static InterfaceChildEntry getInterfaceChildEntryFromConfigDS(
-            InterfaceParentEntryKey interfaceParentEntryKey, InterfaceChildEntryKey interfaceChildEntryKey,
-            DataBroker dataBroker) {
+    public InterfaceParentEntry getInterfaceParentEntryFromConfigDS(ReadTransaction tx,
+            InstanceIdentifier<InterfaceParentEntry> intfId) throws ReadFailedException {
+        return tx.read(LogicalDatastoreType.CONFIGURATION, intfId).checkedGet().orNull();
+    }
+
+    public InterfaceChildEntry getInterfaceChildEntryFromConfigDS(
+            InterfaceParentEntryKey interfaceParentEntryKey, InterfaceChildEntryKey interfaceChildEntryKey) {
         InstanceIdentifier<InterfaceChildEntry> intfChildIid =
                 getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
 
-        return getInterfaceChildEntryFromConfigDS(intfChildIid, dataBroker);
+        return getInterfaceChildEntryFromConfigDS(intfChildIid);
     }
 
-    public static InterfaceChildEntry getInterfaceChildEntryFromConfigDS(
-            InstanceIdentifier<InterfaceChildEntry> intfChildIid, DataBroker dataBroker) {
+    public InterfaceChildEntry getInterfaceChildEntryFromConfigDS(
+            InstanceIdentifier<InterfaceChildEntry> intfChildIid) {
         return IfmUtil.read(LogicalDatastoreType.CONFIGURATION, intfChildIid, dataBroker).orNull();
     }
 
-    public static void createLportTagInterfaceMap(WriteTransaction tx, String infName, Integer ifIndex) {
-        LOG.debug("creating lport tag to interface map for {}",infName);
+    public void createLportTagInterfaceMap(String infName, Integer ifIndex) {
+        LOG.debug("creating lport tag to interface map for {} ifIndex {}",infName, ifIndex);
         InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class)
                 .child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
         IfIndexInterface ifIndexInterface = new IfIndexInterfaceBuilder().setIfIndex(ifIndex)
-                .setKey(new IfIndexInterfaceKey(ifIndex)).setInterfaceName(infName).build();
-        BatchingUtils.write(id, ifIndexInterface, BatchingUtils.EntityType.DEFAULT_OPERATIONAL);
+                .withKey(new IfIndexInterfaceKey(ifIndex)).setInterfaceName(infName).build();
+        batchingUtils.write(id, ifIndexInterface, BatchingUtils.EntityType.DEFAULT_OPERATIONAL);
     }
 
-    public static void removeLportTagInterfaceMap(IdManagerService idManager, WriteTransaction tx, String infName) {
+    public int removeLportTagInterfaceMap(WriteTransaction tx, String infName) {
         // workaround to get the id to remove from lport tag interface map
         Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, infName);
         IfmUtil.releaseId(idManager, IfmConstants.IFM_IDPOOL_NAME, infName);
@@ -235,56 +288,63 @@ public class InterfaceMetaUtils {
         InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class)
                 .child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
         tx.delete(LogicalDatastoreType.OPERATIONAL, id);
+        return ifIndex;
+    }
+
+    public int removeLportTagInterfaceMap(TypedWriteTransaction<Operational> tx, String infName) {
+        // workaround to get the id to remove from lport tag interface map
+        Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, infName);
+        IfmUtil.releaseId(idManager, IfmConstants.IFM_IDPOOL_NAME, infName);
+        LOG.debug("removing lport tag to interface map for {}",infName);
+        InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class)
+            .child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
+        tx.delete(id);
+        return ifIndex;
     }
 
     public static void addBridgeRefToBridgeInterfaceEntry(BigInteger dpId, OvsdbBridgeRef ovsdbBridgeRef,
-            WriteTransaction tx) {
+            TypedWriteTransaction<Configuration> tx) {
         BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpId);
         InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier = getBridgeEntryIdentifier(bridgeEntryKey);
 
         BridgeEntryBuilder bridgeEntryBuilder =
-                new BridgeEntryBuilder().setKey(bridgeEntryKey).setBridgeReference(ovsdbBridgeRef);
-        tx.merge(LogicalDatastoreType.CONFIGURATION, bridgeEntryInstanceIdentifier, bridgeEntryBuilder.build(), true);
+                new BridgeEntryBuilder().withKey(bridgeEntryKey).setBridgeReference(ovsdbBridgeRef);
+        tx.merge(bridgeEntryInstanceIdentifier, bridgeEntryBuilder.build(), CREATE_MISSING_PARENTS);
     }
 
     public static void createBridgeRefEntry(BigInteger dpnId, InstanceIdentifier<?> bridgeIid,
-                                            WriteTransaction tx) {
+                                            TypedWriteTransaction<Operational> tx) {
         LOG.debug("Creating bridge ref entry for dpn: {} bridge: {}",
                 dpnId, bridgeIid);
         BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
         InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
                 InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
         BridgeRefEntryBuilder tunnelDpnBridgeEntryBuilder =
-                new BridgeRefEntryBuilder().setKey(bridgeRefEntryKey).setDpid(dpnId)
+                new BridgeRefEntryBuilder().withKey(bridgeRefEntryKey).setDpid(dpnId)
                         .setBridgeReference(new OvsdbBridgeRef(bridgeIid));
-        tx.put(LogicalDatastoreType.OPERATIONAL, bridgeEntryId, tunnelDpnBridgeEntryBuilder.build(), true);
+        tx.put(bridgeEntryId, tunnelDpnBridgeEntryBuilder.build(), CREATE_MISSING_PARENTS);
     }
 
-    public static void deleteBridgeRefEntry(BigInteger dpnId,
-                                            WriteTransaction tx) {
-        LOG.debug("Deleting bridge ref entry for dpn: {}",
-                dpnId);
-        BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
-        InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
-                InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
-        tx.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId);
+    public static void deleteBridgeRefEntry(BigInteger dpnId, TypedWriteTransaction<Operational> tx) {
+        LOG.debug("Deleting bridge ref entry for dpn: {}", dpnId);
+        tx.delete(InterfaceMetaUtils.getBridgeRefEntryIdentifier(new BridgeRefEntryKey(dpnId)));
     }
 
     public static void createTunnelToInterfaceMap(String tunnelInstanceId,
                                                   String infName,
-                                                  WriteTransaction transaction) {
+                                                  TypedWriteTransaction<Operational> transaction) {
         LOG.debug("creating tunnel instance identifier to interface map for {}",infName);
         InstanceIdentifier<TunnelInstanceInterface> id = InstanceIdentifier.builder(TunnelInstanceInterfaceMap.class)
                 .child(TunnelInstanceInterface.class, new TunnelInstanceInterfaceKey(tunnelInstanceId)).build();
         TunnelInstanceInterface tunnelInstanceInterface = new TunnelInstanceInterfaceBuilder()
-                .setTunnelInstanceIdentifier(tunnelInstanceId).setKey(new TunnelInstanceInterfaceKey(tunnelInstanceId))
+                .setTunnelInstanceIdentifier(tunnelInstanceId).withKey(new TunnelInstanceInterfaceKey(tunnelInstanceId))
                 .setInterfaceName(infName).build();
-        transaction.put(LogicalDatastoreType.OPERATIONAL, id, tunnelInstanceInterface, true);
+        transaction.put(id, tunnelInstanceInterface, CREATE_MISSING_PARENTS);
 
     }
 
     public static void createTunnelToInterfaceMap(String infName,InstanceIdentifier<Node> nodeId,
-                                                  WriteTransaction transaction,
+                                                  TypedWriteTransaction<Operational> transaction,
                                                   IfTunnel ifTunnel) {
         InstanceIdentifier<Tunnels> tunnelsInstanceIdentifier = org.opendaylight.genius.interfacemanager.renderer
                 .hwvtep.utilities.SouthboundUtils.createTunnelsInstanceIdentifier(nodeId,
@@ -293,25 +353,25 @@ public class InterfaceMetaUtils {
     }
 
     public static void removeTunnelToInterfaceMap(InstanceIdentifier<Node> nodeId,
-                                                  WriteTransaction transaction,
+                                                  TypedWriteTransaction<Operational> transaction,
                                                   IfTunnel ifTunnel) {
         InstanceIdentifier<Tunnels> tunnelsInstanceIdentifier = org.opendaylight.genius.interfacemanager.renderer
                 .hwvtep.utilities.SouthboundUtils.createTunnelsInstanceIdentifier(
                         nodeId, ifTunnel.getTunnelSource(), ifTunnel.getTunnelDestination());
-        transaction.delete(LogicalDatastoreType.OPERATIONAL, tunnelsInstanceIdentifier);
+        transaction.delete(tunnelsInstanceIdentifier);
     }
 
     public static String getInterfaceForTunnelInstanceIdentifier(String tunnelInstanceId,
-                                                                 DataBroker dataBroker) {
+                                                                 TypedReadTransaction<Operational> tx)
+        throws ExecutionException, InterruptedException {
         InstanceIdentifier<TunnelInstanceInterface> id = InstanceIdentifier.builder(TunnelInstanceInterfaceMap.class)
                 .child(TunnelInstanceInterface.class, new TunnelInstanceInterfaceKey(tunnelInstanceId)).build();
-        return IfmUtil.read(LogicalDatastoreType.OPERATIONAL, id, dataBroker).transform(
-                TunnelInstanceInterface::getInterfaceName).orNull();
+        return tx.read(id).get().toJavaUtil().map(TunnelInstanceInterface::getInterfaceName).orElse(null);
     }
 
-    public static void deleteBridgeInterfaceEntry(BridgeEntryKey bridgeEntryKey,
+    public void deleteBridgeInterfaceEntry(BridgeEntryKey bridgeEntryKey,
             List<BridgeInterfaceEntry> bridgeInterfaceEntries, InstanceIdentifier<BridgeEntry> bridgeEntryIid,
-            WriteTransaction transaction, String interfaceName) {
+            String interfaceName) {
         BridgeInterfaceEntryKey bridgeInterfaceEntryKey =
                 new BridgeInterfaceEntryKey(interfaceName);
         InstanceIdentifier<BridgeInterfaceEntry> bridgeInterfaceEntryIid =
@@ -319,56 +379,74 @@ public class InterfaceMetaUtils {
                         bridgeInterfaceEntryKey);
 
         if (bridgeInterfaceEntries.size() <= 1) {
-            BatchingUtils.delete(bridgeEntryIid, BatchingUtils.EntityType.DEFAULT_CONFIG);
+            LOG.debug("{} is last bridge-interface entry for DPN : {}", interfaceName, bridgeEntryKey.getDpid());
+            batchingUtils.delete(bridgeEntryIid, BatchingUtils.EntityType.DEFAULT_CONFIG);
         } else {
             // No point deleting interface individually if bridge entry is being deleted
             // Note: Will this cause issue in listener code? Does it expect separate notifications for two?
-            BatchingUtils.delete(bridgeInterfaceEntryIid, BatchingUtils.EntityType.DEFAULT_CONFIG);
+            LOG.debug("deleting bridge-interface entry {} for DPN : {}", interfaceName, bridgeEntryKey.getDpid());
+            batchingUtils.delete(bridgeInterfaceEntryIid, BatchingUtils.EntityType.DEFAULT_CONFIG);
+        }
+    }
+
+    public List<TerminationPoint> getTerminationPointsOnBridge(BigInteger dpnId) {
+        BridgeRefEntry bridgeRefEntry = getBridgeRefEntryFromOperDS(dpnId);
+        if (bridgeRefEntry == null || bridgeRefEntry.getBridgeReference() == null) {
+            LOG.debug("BridgeRefEntry for DPNID {} not found", dpnId);
+            return Collections.emptyList();
+        }
+        InstanceIdentifier<Node> nodeIid =
+                        bridgeRefEntry.getBridgeReference().getValue().firstIdentifierOf(Node.class);
+        com.google.common.base.Optional<Node> optNode =
+            IfmUtil.read(LogicalDatastoreType.OPERATIONAL, nodeIid,  dataBroker);
+        if (optNode.isPresent()) {
+            return optNode.get().getTerminationPoint();
         }
+        return Collections.emptyList();
     }
 
     // Cache Util methods
 
     // Start: BridgeEntryCache
-    public static void addBridgeEntryToCache(BigInteger dpnId, BridgeEntry bridgeEntry) {
+    public void addBridgeEntryToCache(BigInteger dpnId, BridgeEntry bridgeEntry) {
         bridgeEntryMap.put(dpnId, bridgeEntry);
     }
 
-    public static void addBridgeEntryToCache(BridgeEntry bridgeEntry) {
-        addBridgeEntryToCache(bridgeEntry.getKey().getDpid(), bridgeEntry);
+    public void addBridgeEntryToCache(BridgeEntry bridgeEntry) {
+        addBridgeEntryToCache(bridgeEntry.key().getDpid(), bridgeEntry);
     }
 
-    public static void removeFromBridgeEntryCache(BigInteger dpnId) {
+    public void removeFromBridgeEntryCache(BigInteger dpnId) {
         bridgeEntryMap.remove(dpnId);
     }
 
-    public static void removeFromBridgeEntryCache(BridgeEntry bridgeEntry) {
-        removeFromBridgeEntryCache(bridgeEntry.getKey().getDpid());
+    public void removeFromBridgeEntryCache(BridgeEntry bridgeEntry) {
+        removeFromBridgeEntryCache(bridgeEntry.key().getDpid());
     }
 
-    public static BridgeEntry getBridgeEntryFromCache(BigInteger dpnId) {
+    public BridgeEntry getBridgeEntryFromCache(BigInteger dpnId) {
         return bridgeEntryMap.get(dpnId);
     }
     // End: Bridge Entry Cache
 
     //Start: BridgeRefEntry Cache
-    public static void addBridgeRefEntryToCache(BigInteger dpnId, BridgeRefEntry bridgeRefEntry) {
+    public void addBridgeRefEntryToCache(BigInteger dpnId, BridgeRefEntry bridgeRefEntry) {
         bridgeRefEntryMap.put(dpnId, bridgeRefEntry);
     }
 
-    public static void addBridgeRefEntryToCache(BridgeRefEntry bridgeRefEntry) {
-        addBridgeRefEntryToCache(bridgeRefEntry.getKey().getDpid(), bridgeRefEntry);
+    public void addBridgeRefEntryToCache(BridgeRefEntry bridgeRefEntry) {
+        addBridgeRefEntryToCache(bridgeRefEntry.key().getDpid(), bridgeRefEntry);
     }
 
-    public static void removeFromBridgeRefEntryCache(BigInteger dpnId) {
+    public void removeFromBridgeRefEntryCache(BigInteger dpnId) {
         bridgeRefEntryMap.remove(dpnId);
     }
 
-    public static void removeFromBridgeRefEntryCache(BridgeRefEntry bridgeRefEntry) {
-        removeFromBridgeRefEntryCache(bridgeRefEntry.getKey().getDpid());
+    public void removeFromBridgeRefEntryCache(BridgeRefEntry bridgeRefEntry) {
+        removeFromBridgeRefEntryCache(bridgeRefEntry.key().getDpid());
     }
 
-    public static BridgeRefEntry getBridgeRefEntryFromCache(BigInteger dpnId) {
+    public BridgeRefEntry getBridgeRefEntryFromCache(BigInteger dpnId) {
         return bridgeRefEntryMap.get(dpnId);
     }
 }