TSC-181: ITM Yang Models Cleanup
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / impl / ItmUtils.java
index b130c84ca2ccbae0f1bc114a507c3ce5519036a3..558c2d2f1b450d18d0b2944888b5635db5d42b93 100644 (file)
@@ -7,14 +7,16 @@
  */
 package org.opendaylight.genius.itm.impl;
 
+import static java.util.Collections.emptyList;
+
 import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.net.InetAddress;
@@ -23,12 +25,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import javax.annotation.Nonnull;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.net.util.SubnetUtils;
-import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -40,7 +41,6 @@ import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.interfacemanager.globals.IfmConstants;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
-import org.opendaylight.genius.itm.api.IITMProvider;
 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
 import org.opendaylight.genius.itm.confighelpers.HwVtep;
 import org.opendaylight.genius.itm.confighelpers.ItmTunnelAggregationHelper;
@@ -55,7 +55,7 @@ import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.Tunnel;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
@@ -67,8 +67,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
@@ -86,18 +84,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.tunnel.optional.params.TunnelOptionsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.tunnel.optional.params.TunnelOptionsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.VtepConfigSchemas;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.VtepIpPools;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchemaBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchemaKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.vtep.config.schema.DpnIds;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.vtep.config.schema.DpnIdsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.vtep.config.schema.DpnIdsKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpoints;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.DpnEndpointsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeExternal;
@@ -125,17 +112,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tun
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.state.tunnel.list.DstInfoBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.state.tunnel.list.SrcInfoBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.NotHostedTransportZones;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZoneKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -145,6 +127,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -171,14 +154,14 @@ public final class ItmUtils {
     private ItmUtils() {
     }
 
-    public static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
+    public static final FutureCallback<Void> DEFAULT_WRITE_CALLBACK = new FutureCallback<Void>() {
         @Override
         public void onSuccess(Void result) {
             LOG.debug("Success in Datastore write operation");
         }
 
         @Override
-        public void onFailure(@Nonnull Throwable error) {
+        public void onFailure(@NonNull Throwable error) {
             LOG.error("Error in Datastore write operation", error);
         }
     };
@@ -213,7 +196,7 @@ public final class ItmUtils {
                                                          FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.put(datastoreType, path, data, true);
-        Futures.addCallback(tx.submit(), callback);
+        Futures.addCallback(tx.submit(), callback, MoreExecutors.directExecutor());
     }
 
     /**
@@ -227,7 +210,7 @@ public final class ItmUtils {
                                                           FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.merge(datastoreType, path, data, true);
-        Futures.addCallback(tx.submit(), callback);
+        Futures.addCallback(tx.submit(), callback, MoreExecutors.directExecutor());
     }
 
     /**
@@ -241,7 +224,7 @@ public final class ItmUtils {
                                                           FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.delete(datastoreType, path);
-        Futures.addCallback(tx.submit(), callback);
+        Futures.addCallback(tx.submit(), callback, MoreExecutors.directExecutor());
     }
 
     /**
@@ -259,19 +242,16 @@ public final class ItmUtils {
             for (InstanceIdentifier<T> path : pathList) {
                 tx.delete(datastoreType, path);
             }
-            Futures.addCallback(tx.submit(), callback);
+            Futures.addCallback(tx.submit(), callback ,MoreExecutors.directExecutor());
         }
     }
 
+    //ITM cleanup:portname and vlanId are removed, causes change in generated
+    //interface name: This has upgrade impact
     public static String getInterfaceName(final BigInteger datapathid, final String portName, final Integer vlanId) {
         return String.format("%s:%s:%s", datapathid, portName, vlanId);
     }
 
-    public static BigInteger getDpnIdFromInterfaceName(String interfaceName) {
-        String[] dpnStr = interfaceName.split(":");
-        return new BigInteger(dpnStr[0]);
-    }
-
     public static String getTrunkInterfaceName(String parentInterfaceName,
                                                String localHostName, String remoteHostName, String tunnelType) {
         String tunnelTypeStr;
@@ -324,21 +304,25 @@ public final class ItmUtils {
     }
 
     public static TunnelEndPoints createTunnelEndPoints(BigInteger dpnId, IpAddress ipAddress, String portName,
-                                                        boolean isOfTunnel, int vlanId, IpPrefix prefix,
-                                                        IpAddress gwAddress, List<TzMembership> zones,
+                                                        boolean isOfTunnel, int vlanId, List<TzMembership> zones,
                                                         Class<? extends TunnelTypeBase>  tunnelType,
                                                         String tos) {
         // when Interface Mgr provides support to take in Dpn Id
-        return new TunnelEndPointsBuilder().withKey(new TunnelEndPointsKey(ipAddress, portName,tunnelType, vlanId))
-                .setSubnetMask(prefix).setGwIpAddress(gwAddress).setTzMembership(zones)
+        return new TunnelEndPointsBuilder().withKey(new TunnelEndPointsKey(ipAddress, tunnelType))
+                .setTzMembership(zones)
                 .setOptionOfTunnel(isOfTunnel).setInterfaceName(ItmUtils.getInterfaceName(dpnId, portName, vlanId))
                 .setTunnelType(tunnelType)
                 .setOptionTunnelTos(tos)
                 .build();
     }
 
-    public static DpnEndpoints createDpnEndpoints(List<DPNTEPsInfo> dpnTepInfo) {
-        return new DpnEndpointsBuilder().setDPNTEPsInfo(dpnTepInfo).build();
+    public static TunnelEndPoints createDummyTunnelEndPoints(BigInteger dpnID, IpAddress ipAddress, boolean ofTunnel,
+                                                             String tos, List<TzMembership> zones,
+                                                             Class<? extends TunnelTypeBase>  tunnelType,
+                                                             String port, int vlanID) {
+
+        return ItmUtils.createTunnelEndPoints(dpnID, ipAddress, port, ofTunnel,vlanID, zones,
+                tunnelType, tos);
     }
 
     public static InstanceIdentifier<Interface> buildId(String interfaceName) {
@@ -368,21 +352,21 @@ public final class ItmUtils {
 
     public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled,
                                                  Class<? extends TunnelTypeBase> tunType, IpAddress localIp,
-                                                 IpAddress remoteIp, IpAddress gatewayIp, Integer vlanId,
-                                                 boolean internal, Boolean monitorEnabled,
+                                                 IpAddress remoteIp,
+                                                 Boolean monitorEnabled,
                                                  Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
                                                  Integer monitorInterval, boolean useOfTunnel,
                                                  List<TunnelOptions> tunOptions) {
 
-        return buildTunnelInterface(dpn, ifName, desc, enabled, tunType, localIp, remoteIp,  gatewayIp,  vlanId,
-                                    internal,  monitorEnabled, monitorProtocol, monitorInterval,  useOfTunnel, null,
-                                    tunOptions);
+        return buildTunnelInterface(dpn, ifName, desc, enabled, tunType, localIp, remoteIp,
+                monitorEnabled, monitorProtocol, monitorInterval,  useOfTunnel, null,
+                tunOptions);
     }
 
     public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled,
                                                  Class<? extends TunnelTypeBase> tunType, IpAddress localIp,
-                                                 IpAddress remoteIp, IpAddress gatewayIp, Integer vlanId,
-                                                 boolean internal, Boolean monitorEnabled,
+                                                 IpAddress remoteIp,
+                                                 Boolean monitorEnabled,
                                                  Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
                                                  Integer monitorInterval, boolean useOfTunnel, String parentIfaceName,
                                                  List<TunnelOptions> tunnelOptions) {
@@ -392,10 +376,6 @@ public final class ItmUtils {
                 new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).setParentInterface(parentIfaceName).build();
         builder.addAugmentation(ParentRefs.class, parentRefs);
         Long monitoringInterval = null;
-        if (vlanId > 0) {
-            IfL2vlan l2vlan = new IfL2vlanBuilder().setVlanId(new VlanId(vlanId)).build();
-            builder.addAugmentation(IfL2vlan.class, l2vlan);
-        }
         LOG.debug("buildTunnelInterface: monitorProtocol = {} and monitorInterval = {}",
                 monitorProtocol.getName(),monitorInterval);
 
@@ -403,8 +383,8 @@ public final class ItmUtils {
             monitoringInterval = monitorInterval.longValue();
         }
 
-        IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(gatewayIp)
-                .setTunnelSource(localIp).setTunnelInterfaceType(tunType).setInternal(internal)
+        IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp)
+                .setTunnelSource(localIp).setTunnelInterfaceType(tunType)
                 .setMonitorEnabled(monitorEnabled).setMonitorProtocol(monitorProtocol)
                 .setMonitorInterval(monitoringInterval).setTunnelRemoteIpFlow(useOfTunnel)
                 .setTunnelOptions(tunnelOptions)
@@ -477,7 +457,7 @@ public final class ItmUtils {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static void addTerminatingServiceTable(TypedReadWriteTransaction<Configuration> tx,
-        BigInteger dpnId, IMdsalApiManager mdsalManager) {
+                                                  BigInteger dpnId, IMdsalApiManager mdsalManager) {
         LOG.trace("Installing PUNT to Controller flow in DPN {} ", dpnId);
         List<ActionInfo> listActionInfo = new ArrayList<>();
         listActionInfo.add(new ActionPuntToController());
@@ -491,11 +471,11 @@ public final class ItmUtils {
             mkInstructions.add(new InstructionApplyActions(listActionInfo));
 
             FlowEntity terminatingServiceTableFlowEntity = MDSALUtil
-                .buildFlowEntity(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE,
-                    getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE, ITMConstants.LLDP_SERVICE_ID),
-                    5, String.format("%s:%d","ITM Flow Entry ", ITMConstants.LLDP_SERVICE_ID), 0, 0,
-                    ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(ITMConstants.LLDP_SERVICE_ID)),
-                    mkMatches, mkInstructions);
+                    .buildFlowEntity(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE,
+                            getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE, ITMConstants.LLDP_SERVICE_ID),
+                            5, String.format("%s:%d","ITM Flow Entry ", ITMConstants.LLDP_SERVICE_ID), 0, 0,
+                            ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(ITMConstants.LLDP_SERVICE_ID)),
+                            mkMatches, mkInstructions);
             mdsalManager.addFlow(tx, terminatingServiceTableFlowEntity);
         } catch (Exception e) {
             LOG.error("Error while setting up Table 36 for {}", dpnId, e);
@@ -504,13 +484,13 @@ public final class ItmUtils {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static void removeTerminatingServiceTable(TypedReadWriteTransaction<Configuration> tx,
-        BigInteger dpnId, IMdsalApiManager mdsalManager) {
+                                                     BigInteger dpnId, IMdsalApiManager mdsalManager) {
         LOG.trace("Removing PUNT to Controller flow in DPN {} ", dpnId);
 
         try {
             mdsalManager.removeFlow(tx, dpnId,
-                getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE, ITMConstants.LLDP_SERVICE_ID),
-                NwConstants.INTERNAL_TUNNEL_TABLE);
+                    getFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE, ITMConstants.LLDP_SERVICE_ID),
+                    NwConstants.INTERNAL_TUNNEL_TABLE);
         } catch (Exception e) {
             LOG.error("Error while setting up Table 36 for {}", dpnId, e);
         }
@@ -520,277 +500,19 @@ public final class ItmUtils {
         return String.valueOf(termSvcTable) + svcId;
     }
 
-    public static InstanceIdentifier<VtepConfigSchema> getVtepConfigSchemaIdentifier(String schemaName) {
-        return InstanceIdentifier.builder(VtepConfigSchemas.class)
-                .child(VtepConfigSchema.class, new VtepConfigSchemaKey(schemaName)).build();
-    }
-
-    public static InstanceIdentifier<VtepConfigSchema> getVtepConfigSchemaIdentifier() {
-        return InstanceIdentifier.builder(VtepConfigSchemas.class).child(VtepConfigSchema.class).build();
-    }
-
-    public static InstanceIdentifier<VtepConfigSchemas> getVtepConfigSchemasIdentifier() {
-        return InstanceIdentifier.builder(VtepConfigSchemas.class).build();
-    }
-
-    public static InstanceIdentifier<VtepIpPool> getVtepIpPoolIdentifier(String subnetCidr) {
-        return InstanceIdentifier.builder(VtepIpPools.class).child(VtepIpPool.class, new VtepIpPoolKey(subnetCidr))
-                .build();
-    }
-
-    public static VtepConfigSchema validateForAddVtepConfigSchema(VtepConfigSchema schema,
-                                                                  List<VtepConfigSchema> existingSchemas) {
-        VtepConfigSchema validSchema = validateVtepConfigSchema(schema);
-        for (VtepConfigSchema existingSchema : emptyIfNull(existingSchemas)) {
-            if (!StringUtils.equalsIgnoreCase(schema.getSchemaName(), existingSchema.getSchemaName())
-                    && schema.getSubnet().equals(existingSchema.getSubnet())) {
-                String subnetCidr = getSubnetCidrAsString(schema.getSubnet());
-                Preconditions.checkArgument(false, "VTEP schema with subnet [" + subnetCidr
-                        + "] already exists. Multiple VTEP schemas with same subnet is not allowed.");
-            }
-        }
-        if (isNotEmpty(getDpnIdList(validSchema.getDpnIds()))) {
-            String tzone = validSchema.getTransportZoneName();
-            List<BigInteger> lstDpns = getConflictingDpnsAlreadyConfiguredWithTz(validSchema.getSchemaName(), tzone,
-                    getDpnIdList(validSchema.getDpnIds()), existingSchemas);
-            if (!lstDpns.isEmpty()) {
-                Preconditions.checkArgument(false, "DPN's " + lstDpns + " already configured for transport zone "
-                                + tzone + ". Only one end point per transport Zone per Dpn is allowed.");
-            }
-            if (schema.getTunnelType().equals(TunnelTypeGre.class)) {
-                validateForSingleGreTep(validSchema.getSchemaName(), getDpnIdList(validSchema.getDpnIds()),
-                        existingSchemas);
-            }
-        }
-        return validSchema;
-    }
-
-    private static void validateForSingleGreTep(String schemaName, List<BigInteger> lstDpnsForAdd,
-                                                List<VtepConfigSchema> existingSchemas) {
-        for (VtepConfigSchema existingSchema : emptyIfNull(existingSchemas)) {
-            if (TunnelTypeGre.class.equals(existingSchema.getTunnelType())
-                    && !StringUtils.equalsIgnoreCase(schemaName, existingSchema.getSchemaName())) {
-                List<BigInteger> lstConflictingDpns = new ArrayList<>(getDpnIdList(existingSchema.getDpnIds()));
-                lstConflictingDpns.retainAll(emptyIfNull(lstDpnsForAdd));
-                if (!lstConflictingDpns.isEmpty()) {
-                    String errMsg = "DPN's " + lstConflictingDpns
-                            + " already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.";
-                    Preconditions.checkArgument(false, errMsg);
-                }
-            }
-        }
-    }
-
-    public static VtepConfigSchema validateVtepConfigSchema(VtepConfigSchema schema) {
-        Preconditions.checkNotNull(schema);
-        Preconditions.checkArgument(StringUtils.isNotBlank(schema.getSchemaName()));
-        Preconditions.checkArgument(StringUtils.isNotBlank(schema.getPortName()));
-        Preconditions.checkArgument(schema.getVlanId() >= 0 && schema.getVlanId() < 4095,
-                "Invalid VLAN ID, range (0-4094)");
-        Preconditions.checkArgument(StringUtils.isNotBlank(schema.getTransportZoneName()));
-        Preconditions.checkNotNull(schema.getSubnet());
-        String subnetCidr = getSubnetCidrAsString(schema.getSubnet());
-        SubnetUtils subnetUtils = new SubnetUtils(subnetCidr);
-        IpAddress gatewayIp = schema.getGatewayIp();
-        if (gatewayIp != null) {
-            String strGatewayIp = gatewayIp.stringValue();
-            if (!strGatewayIp.equals(ITMConstants.DUMMY_IP_ADDRESS) && !subnetUtils.getInfo().isInRange(strGatewayIp)) {
-                Preconditions.checkArgument(false, "Gateway IP address " + strGatewayIp
-                        + " is not in subnet range " + subnetCidr);
-            }
-        }
-        ItmUtils.getExcludeIpAddresses(schema.getExcludeIpFilter(), subnetUtils.getInfo());
-        return new VtepConfigSchemaBuilder(schema).setTunnelType(schema.getTunnelType()).build();
-    }
-
-    public static String validateTunnelType(String tunnelType) {
-        if (tunnelType == null) {
-            tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
-        } else {
-            tunnelType = StringUtils.upperCase(tunnelType);
-            String error = "Invalid tunnel type. Valid values: "
-                    + ITMConstants.TUNNEL_TYPE_VXLAN + " | " + ITMConstants.TUNNEL_TYPE_GRE;
-            Preconditions.checkArgument(ITMConstants.TUNNEL_TYPE_VXLAN.equals(tunnelType)
-                    || ITMConstants.TUNNEL_TYPE_GRE.equals(tunnelType), error);
-        }
-        return tunnelType;
-    }
-
-    private static List<BigInteger> getConflictingDpnsAlreadyConfiguredWithTz(String schemaName, String tzone,
-                                                                              List<BigInteger> lstDpns,
-                                                                              List<VtepConfigSchema> existingSchemas) {
-        List<BigInteger> lstConflictingDpns = new ArrayList<>();
-        for (VtepConfigSchema schema : emptyIfNull(existingSchemas)) {
-            if (!StringUtils.equalsIgnoreCase(schemaName, schema.getSchemaName())
-                    && StringUtils.equals(schema.getTransportZoneName(), tzone)) {
-                lstConflictingDpns = new ArrayList<>(getDpnIdList(schema.getDpnIds()));
-                lstConflictingDpns.retainAll(lstDpns);
-                if (!lstConflictingDpns.isEmpty()) {
-                    break;
-                }
-            }
-        }
-        return lstConflictingDpns;
-    }
-
-    public static VtepConfigSchema constructVtepConfigSchema(String schemaName, String portName, Integer vlanId,
-                                                             String subnetMask, String gatewayIp, String transportZone,
-                                                             String tunnelType, List<BigInteger> dpnIds,
-                                                             String excludeIpFilter) {
-        IpAddress gatewayIpObj = StringUtils.isBlank(gatewayIp) ? null : IpAddressBuilder.getDefaultInstance(gatewayIp);
-        IpPrefix subnet = StringUtils.isBlank(subnetMask) ? null : IpPrefixBuilder.getDefaultInstance(subnetMask);
-        Class<? extends TunnelTypeBase> tunType ;
-        if (tunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) {
-            tunType = TunnelTypeVxlan.class ;
-        } else {
-            tunType = TunnelTypeGre.class ;
-        }
-        VtepConfigSchemaBuilder schemaBuilder = new VtepConfigSchemaBuilder().setSchemaName(schemaName)
-                .setPortName(portName).setVlanId(vlanId).setSubnet(subnet).setGatewayIp(gatewayIpObj)
-                .setTransportZoneName(transportZone).setTunnelType(tunType).setDpnIds(getDpnIdsListFromBigInt(dpnIds))
-                .setExcludeIpFilter(excludeIpFilter);
-        return schemaBuilder.build();
-    }
-
-    public static List<IpAddress> getExcludeIpAddresses(String excludeIpFilter, SubnetInfo subnetInfo) {
-        final List<IpAddress> lstIpAddress = new ArrayList<>();
-        if (StringUtils.isBlank(excludeIpFilter)) {
-            return lstIpAddress;
-        }
-        final String[] arrIps = StringUtils.split(excludeIpFilter, ',');
-        for (String ip : arrIps) {
-            if (StringUtils.countMatches(ip, "-") == 1) {
-                final String[] arrIpRange = StringUtils.split(ip, '-');
-                String strStartIp = StringUtils.trim(arrIpRange[0]);
-                String strEndIp = StringUtils.trim(arrIpRange[1]);
-                Preconditions.checkArgument(InetAddresses.isInetAddress(strStartIp),
-                        "Invalid exclude IP filter: invalid IP address value " + strStartIp);
-                Preconditions.checkArgument(InetAddresses.isInetAddress(strEndIp),
-                        "Invalid exclude IP filter: invalid IP address value " + strEndIp);
-                Preconditions.checkArgument(subnetInfo.isInRange(strStartIp),
-                        "Invalid exclude IP filter: IP address [" + strStartIp
-                                + "] not in subnet range " + subnetInfo.getCidrSignature());
-                Preconditions.checkArgument(subnetInfo.isInRange(strEndIp),
-                        "Invalid exclude IP filter: IP address [" + strEndIp
-                                + "] not in subnet range " + subnetInfo.getCidrSignature());
-                int startIp = subnetInfo.asInteger(strStartIp);
-                int endIp = subnetInfo.asInteger(strEndIp);
-
-                Preconditions.checkArgument(startIp < endIp,
-                        "Invalid exclude IP filter: Invalid range [" + ip + "] ");
-                for (int iter = startIp; iter <= endIp; iter++) {
-                    String ipAddress = ipFormat(toIpArray(iter));
-                    validateAndAddIpAddressToList(subnetInfo, lstIpAddress, ipAddress);
-                }
-            } else {
-                validateAndAddIpAddressToList(subnetInfo, lstIpAddress, ip);
-            }
-        }
-        return lstIpAddress;
-    }
-
-    private static void validateAndAddIpAddressToList(SubnetInfo subnetInfo, final List<IpAddress> lstIpAddress,
-                                                      String ipAddress) {
-        String ip = StringUtils.trim(ipAddress);
-        Preconditions.checkArgument(InetAddresses.isInetAddress(ip),
-                "Invalid exclude IP filter: invalid IP address value " + ip);
-        Preconditions.checkArgument(subnetInfo.isInRange(ip),
-                "Invalid exclude IP filter: IP address [" + ip + "] not in subnet range "
-                        + subnetInfo.getCidrSignature());
-        lstIpAddress.add(IpAddressBuilder.getDefaultInstance(ip));
-    }
-
-    private static int[] toIpArray(int val) {
-        int[] ret = new int[4];
-        for (int iter = 3; iter >= 0; --iter) {
-            ret[iter] |= val >>> 8 * (3 - iter) & 0xff;
-        }
-        return ret;
-    }
-
-    private static String ipFormat(int[] octets) {
-        StringBuilder str = new StringBuilder();
-        for (int iter = 0; iter < octets.length; ++iter) {
-            str.append(octets[iter]);
-            if (iter != octets.length - 1) {
-                str.append(".");
-            }
-        }
-        return str.toString();
-    }
-
-    public static VtepConfigSchema validateForUpdateVtepSchema(String schemaName, List<BigInteger> lstDpnsForAdd,
-                                                               List<BigInteger> lstDpnsForDelete,
-                                                               IITMProvider itmProvider) {
-        Preconditions.checkArgument(StringUtils.isNotBlank(schemaName));
-        if ((lstDpnsForAdd == null || lstDpnsForAdd.isEmpty())
-                && (lstDpnsForDelete == null || lstDpnsForDelete.isEmpty())) {
-            Preconditions.checkArgument(false,
-                    "DPN ID list for add | delete is null or empty in schema " + schemaName);
-        }
-        VtepConfigSchema schema = itmProvider.getVtepConfigSchema(schemaName);
-        if (schema == null) {
-            Preconditions.checkArgument(false, "Specified VTEP Schema [" + schemaName
-                    + "] doesn't exists!");
-        }
-        List<BigInteger> existingDpnIds = getDpnIdList(schema.getDpnIds());
-        if (isNotEmpty(lstDpnsForAdd)) {
-            List<BigInteger> lstAlreadyExistingDpns = new ArrayList<>(existingDpnIds);
-            lstAlreadyExistingDpns.retainAll(lstDpnsForAdd);
-            Preconditions.checkArgument(lstAlreadyExistingDpns.isEmpty(),
-                    "DPN ID's " + lstAlreadyExistingDpns
-                            + " already exists in VTEP schema [" + schemaName + "]");
-            if (schema.getTunnelType().equals(TunnelTypeGre.class)) {
-                validateForSingleGreTep(schema.getSchemaName(), lstDpnsForAdd, itmProvider.getAllVtepConfigSchemas());
-            }
-        }
-        if (isNotEmpty(lstDpnsForDelete)) {
-            if (existingDpnIds.isEmpty()) {
-                String builder = "DPN ID's " + lstDpnsForDelete
-                        + " specified for delete from VTEP schema [" + schemaName
-                        + "] are not configured in the schema.";
-                Preconditions.checkArgument(false, builder);
-            } else if (!existingDpnIds.containsAll(lstDpnsForDelete)) {
-                List<BigInteger> lstConflictingDpns = new ArrayList<>(lstDpnsForDelete);
-                lstConflictingDpns.removeAll(existingDpnIds);
-                String builder = "DPN ID's " + lstConflictingDpns
-                        + " specified for delete from VTEP schema [" + schemaName
-                        + "] are not configured in the schema.";
-                Preconditions.checkArgument(false, builder);
-            }
-        }
-        return schema;
-    }
-
-    public static String getSubnetCidrAsString(IpPrefix subnet) {
-        return subnet == null ? StringUtils.EMPTY : subnet.stringValue();
-    }
-
-    public static <T> List<T> emptyIfNull(List<T> list) {
-        return list == null ? Collections.emptyList() : list;
-    }
-
     public static <T> boolean isEmpty(Collection<T> collection) {
         return collection == null || collection.isEmpty();
     }
 
-    public static <T> boolean isNotEmpty(Collection<T> collection) {
-        return !isEmpty(collection);
-    }
-
     @Nonnull
-    public static HwVtep createHwVtepObject(String topoId, String nodeId, IpAddress ipAddress, IpPrefix ipPrefix,
-                                            IpAddress gatewayIP, int vlanID,
+    public static HwVtep createHwVtepObject(String topoId, String nodeId, IpAddress ipAddress,
                                             Class<? extends TunnelTypeBase> tunneltype, TransportZone transportZone) {
         HwVtep hwVtep = new HwVtep();
-        hwVtep.setGatewayIP(gatewayIP);
         hwVtep.setHwIp(ipAddress);
-        hwVtep.setIpPrefix(ipPrefix);
         hwVtep.setNodeId(nodeId);
         hwVtep.setTopoId(topoId);
         hwVtep.setTransportZone(transportZone.getZoneName());
         hwVtep.setTunnelType(tunneltype);
-        hwVtep.setVlanID(vlanID);
         return hwVtep;
     }
 
@@ -818,182 +540,48 @@ public final class ItmUtils {
         }
     }
 
-    @Nonnull
-    public static List<BigInteger> getDpnIdList(List<DpnIds> dpnIds) {
-        List<BigInteger> dpnList = new ArrayList<>() ;
-        for (DpnIds dpn : dpnIds) {
-            dpnList.add(dpn.getDPN()) ;
-        }
-        return dpnList ;
-    }
-
-    public static List<DpnIds> getDpnIdsListFromBigInt(List<BigInteger> dpnIds) {
-        List<DpnIds> dpnIdList = new ArrayList<>();
-        DpnIdsBuilder builder = new DpnIdsBuilder();
-        for (BigInteger dpnId : dpnIds) {
-            dpnIdList.add(builder.withKey(new DpnIdsKey(dpnId)).setDPN(dpnId).build());
-        }
-        return dpnIdList;
-    }
-
     public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces
             .rev140508.interfaces.state.Interface> buildStateInterfaceId(
             String interfaceName) {
         return InstanceIdentifier.builder(InterfacesState.class)
                 .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces
-                               .state.Interface.class,
-                       new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces
-                               .rev140508.interfaces.state.InterfaceKey(
-                               interfaceName)).build();
+                                .state.Interface.class,
+                        new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces
+                                .rev140508.interfaces.state.InterfaceKey(
+                                interfaceName)).build();
     }
 
-    @Nonnull
+    @NonNull
     public static List<String> getInternalTunnelInterfaces(DataBroker dataBroker) {
-        List<String> tunnelList = new ArrayList<>();
         Collection<String> internalInterfaces = ITM_CACHE.getAllInternalInterfaces();
+        List<String> tunnelList = new ArrayList<>();
         if (internalInterfaces.isEmpty()) {
-            updateTunnelsCache(dataBroker);
-            internalInterfaces = ITM_CACHE.getAllInternalInterfaces();
+            tunnelList = getAllInternalTunnlInterfacesFromDS(dataBroker);
+        }
+        else {
+            LOG.debug("Internal Interfaces from Cache size: {}", internalInterfaces.size());
+            tunnelList.addAll(internalInterfaces);
         }
-        LOG.debug("ItmUtils.getTunnelList Cache Internal Interfaces size: {} ", internalInterfaces.size());
-        tunnelList.addAll(internalInterfaces);
-        LOG.trace("ItmUtils.getTunnelList Internal: {}", tunnelList);
+        LOG.trace("ItmUtils Internal TunnelList: {}", tunnelList);
         return tunnelList;
     }
 
     public static List<InternalTunnel> getInternalTunnelsFromCache(DataBroker dataBroker) {
-        List<InternalTunnel> tunnelList = new ArrayList<>();
         Collection<InternalTunnel> internalInterfaces = ITM_CACHE.getAllInternalTunnel();
+        LOG.trace("getInternalTunnelsFromCache - List of InternalTunnels in the Cache: {} ", internalInterfaces);
+        List<InternalTunnel> tunnelList = new ArrayList<>();
         if (internalInterfaces.isEmpty()) {
-            updateTunnelsCache(dataBroker);
-            internalInterfaces = ITM_CACHE.getAllInternalTunnel();
+            LOG.trace("ItmUtils.getInternalTunnelsFromCache invoking getAllInternalTunnlInterfacesFromDS");
+            tunnelList = getAllInternalTunnels(dataBroker);
+        }
+        else {
+            LOG.debug("No. of Internal Tunnel Interfaces in cache: {} ", internalInterfaces.size());
+            tunnelList.addAll(internalInterfaces);
         }
-        LOG.debug("Number of Internal Tunnel Interfaces in cache: {} ", internalInterfaces.size());
-        tunnelList.addAll(internalInterfaces);
         LOG.trace("List of Internal Tunnels: {}", tunnelList);
         return tunnelList;
     }
 
-    public static List<String> getTunnelsofTzone(List<HwVtep> hwVteps, String tzone, DataBroker dataBroker,
-                                                 Boolean hwVtepsExist) {
-        List<String> tunnels = new ArrayList<>();
-        InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class)
-                .child(TransportZone.class, new TransportZoneKey(tzone)).build();
-        Optional<TransportZone> transportZoneOptional =
-                ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
-        if (transportZoneOptional.isPresent()) {
-            TransportZone transportZone = transportZoneOptional.get();
-            Class<? extends TunnelTypeBase> tunType = transportZone.getTunnelType();
-            if (transportZone.getSubnets() != null && !transportZone.getSubnets().isEmpty()) {
-                for (Subnets sub : transportZone.getSubnets()) {
-                    if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
-                        for (Vteps vtepLocal : sub.getVteps()) {
-                            for (Vteps vtepRemote : sub.getVteps()) {
-                                if (!vtepLocal.equals(vtepRemote)) {
-                                    InternalTunnelKey key = new InternalTunnelKey(vtepRemote.getDpnId(),
-                                            vtepLocal.getDpnId(), tunType);
-                                    InstanceIdentifier<InternalTunnel> intIID =
-                                            InstanceIdentifier.builder(TunnelList.class)
-                                                    .child(InternalTunnel.class, key).build();
-                                    Optional<InternalTunnel> tunnelsOptional =
-                                            ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
-                                    if (tunnelsOptional.isPresent()) {
-                                        List<String> tunnelInterfaceNames = tunnelsOptional
-                                                .get().getTunnelInterfaceNames();
-                                        if (tunnelInterfaceNames != null && !tunnelInterfaceNames.isEmpty()) {
-                                            String tunnelInterfaceName = tunnelInterfaceNames.get(0);
-                                            LOG.trace("Internal Tunnel added {}", tunnelInterfaceName);
-                                            tunnels.add(tunnelInterfaceName);
-                                        }
-                                    }
-                                }
-                            }
-                            if (hwVteps != null && !hwVteps.isEmpty()) {
-                                for (HwVtep hwVtep : hwVteps) {
-                                    tunnels.add(getExtTunnel(hwVtep.getNodeId(), vtepLocal.getDpnId().toString(),
-                                            tunType, dataBroker));
-                                    tunnels.add(getExtTunnel(vtepLocal.getDpnId().toString(), hwVtep.getNodeId(),
-                                            tunType, dataBroker));
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-            if (hwVtepsExist) {
-                for (HwVtep hwVtep : hwVteps) {
-                    for (HwVtep hwVtepOther : hwVteps) {
-                        if (!hwVtep.getHwIp().equals(hwVtepOther.getHwIp())) {
-                            tunnels.add(getExtTunnel(hwVtep.getNodeId(), hwVtepOther.getNodeId(),
-                                    tunType, dataBroker));
-                            tunnels.add(getExtTunnel(hwVtepOther.getNodeId(), hwVtep.getNodeId(),
-                                    tunType, dataBroker));
-                        }
-                    }
-                }
-            }
-        }
-        return tunnels;
-    }
-
-    public static List<String> getInternalTunnelsofTzone(String tzone, DataBroker dataBroker) {
-        List<String> tunnels = new ArrayList<>();
-        LOG.trace("Getting internal tunnels of {}",tzone);
-        InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class)
-                .child(TransportZone.class, new TransportZoneKey(tzone)).build();
-        Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
-                path, dataBroker);
-        if (transportZoneOptional.isPresent()) {
-            TransportZone transportZone = transportZoneOptional.get();
-            if (transportZone.getSubnets() != null && !transportZone.getSubnets().isEmpty()) {
-                for (Subnets sub : transportZone.getSubnets()) {
-                    if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
-                        for (Vteps vtepLocal : sub.getVteps()) {
-                            for (Vteps vtepRemote : sub.getVteps()) {
-                                if (!vtepLocal.equals(vtepRemote)) {
-                                    InternalTunnelKey key =
-                                            new InternalTunnelKey(vtepRemote.getDpnId(), vtepLocal.getDpnId(),
-                                                    transportZone.getTunnelType());
-                                    InstanceIdentifier<InternalTunnel> intIID =
-                                            InstanceIdentifier.builder(TunnelList.class)
-                                                    .child(InternalTunnel.class, key).build();
-                                    Optional<InternalTunnel> tunnelsOptional =
-                                            ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
-                                    if (tunnelsOptional.isPresent()) {
-                                        List<String> tunnelInterfaceNames = tunnelsOptional.get()
-                                                .getTunnelInterfaceNames();
-                                        if (tunnelInterfaceNames != null && !tunnelInterfaceNames.isEmpty()) {
-                                            String tunnelInterfaceName = tunnelInterfaceNames.get(0);
-                                            LOG.trace("Internal Tunnel added {}", tunnelInterfaceName);
-                                            tunnels.add(tunnelInterfaceName);
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return tunnels;
-    }
-
-    private static String getExtTunnel(String nodeId, String dpId,Class<? extends TunnelTypeBase> tunType, DataBroker
-            dataBroker) {
-        LOG.trace("getting ext tunnel for {} and dpId {}",nodeId,dpId);
-        ExternalTunnelKey key = getExternalTunnelKey(dpId, nodeId, tunType);
-        InstanceIdentifier<ExternalTunnel> intIID = InstanceIdentifier.builder(ExternalTunnelList.class)
-                .child(ExternalTunnel.class, key).build();
-        Optional<ExternalTunnel> tunnelsOptional =
-                ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
-        if (tunnelsOptional.isPresent()) {
-            String tunnelInterfaceName = tunnelsOptional.get().getTunnelInterfaceName();
-            LOG.trace("ext tunnel returned {} ", tunnelInterfaceName);
-            return tunnelInterfaceName;
-        }
-        return null;
-    }
-
     @SuppressFBWarnings("RV_CHECK_FOR_POSITIVE_INDEXOF")
     public static ExternalTunnelKey getExternalTunnelKey(String dst , String src,
                                                          Class<? extends TunnelTypeBase> tunType) {
@@ -1009,11 +597,9 @@ public final class ItmUtils {
     }
 
     public static List<TunnelEndPoints> getTEPsForDpn(BigInteger srcDpn, Collection<DPNTEPsInfo> dpnList) {
-        List<TunnelEndPoints> tunnelEndPoints = new ArrayList<>();
         for (DPNTEPsInfo dpn : dpnList) {
-            if (dpn.getDPNID().equals(srcDpn)) {
-                tunnelEndPoints.addAll(dpn.getTunnelEndPoints());
-                return tunnelEndPoints ;
+            if (Objects.equals(dpn.getDPNID(), srcDpn)) {
+                return new ArrayList<>(dpn.nonnullTunnelEndPoints());
             }
         }
         return null;
@@ -1028,26 +614,57 @@ public final class ItmUtils {
             result = tunnelList.get().getInternalTunnel();
         }
         if (result == null) {
-            result = Collections.emptyList();
+            result = emptyList();
         }
         return result;
     }
 
     public static InternalTunnel getInternalTunnel(String interfaceName, DataBroker broker) {
         InternalTunnel internalTunnel = ITM_CACHE.getInternalTunnel(interfaceName);
+        LOG.trace("ItmUtils getInternalTunnel List of InternalTunnels in the Cache {} ", internalTunnel);
         if (internalTunnel == null) {
-            updateTunnelsCache(broker);
-            internalTunnel = ITM_CACHE.getInternalTunnel(interfaceName);
+            internalTunnel = getInternalTunnelFromDS(interfaceName, broker);
         }
         return internalTunnel;
     }
 
+    private static List<String> getAllInternalTunnlInterfacesFromDS(DataBroker broker) {
+        List<String> tunnelList = new ArrayList<>();
+        List<InternalTunnel> internalTunnels = getAllInternalTunnels(broker);
+        if (internalTunnels != null) {
+            for (InternalTunnel tunnel : internalTunnels) {
+                List<String> tunnelInterfaceNames = tunnel.getTunnelInterfaceNames();
+                if (tunnelInterfaceNames != null) {
+                    for (String tunnelInterfaceName : tunnelInterfaceNames) {
+                        tunnelList.add(tunnelInterfaceName);
+                    }
+                }
+            }
+        }
+        LOG.debug("Internal Tunnel Interfaces list: {} ", tunnelList);
+        return tunnelList;
+    }
+
+    private static ExternalTunnel getExternalTunnelFromDS(String interfaceName, DataBroker broker) {
+        List<ExternalTunnel> externalTunnels = getAllExternalTunnels(broker);
+        if (externalTunnels !=  null) {
+            for (ExternalTunnel tunnel : externalTunnels) {
+                String tunnelInterfaceName = tunnel.getTunnelInterfaceName();
+                if (tunnelInterfaceName != null && (tunnelInterfaceName.equalsIgnoreCase(interfaceName))) {
+                    LOG.trace("getExternalTunnelFromDS tunnelInterfaceName: {} ", tunnelInterfaceName);
+                    return tunnel;
+                }
+            }
+        }
+        return null;
+    }
+
     public static ExternalTunnel getExternalTunnel(String interfaceName, DataBroker broker) {
         ExternalTunnel externalTunnel = ITM_CACHE.getExternalTunnel(interfaceName);
         if (externalTunnel == null) {
-            updateTunnelsCache(broker);
-            externalTunnel = ITM_CACHE.getExternalTunnel(interfaceName);
+            externalTunnel = getExternalTunnelFromDS(interfaceName, broker);
         }
+        LOG.trace("getExternalTunnel externalTunnel: {} ", externalTunnel);
         return externalTunnel;
     }
 
@@ -1059,7 +676,7 @@ public final class ItmUtils {
             result = tunnelList.get().getExternalTunnel();
         }
         if (result == null) {
-            result = Collections.emptyList();
+            result = emptyList();
         }
         return result;
     }
@@ -1075,7 +692,7 @@ public final class ItmUtils {
         } else if (tunType.equals(TunnelTypeLogicalGroup.class)) {
             tunnelType = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
         }
-        return tunnelType ;
+        return tunnelType;
     }
 
 
@@ -1092,17 +709,6 @@ public final class ItmUtils {
         return key;
     }
 
-    private static void updateTunnelsCache(DataBroker broker) {
-        List<InternalTunnel> internalTunnels = getAllInternalTunnels(broker);
-        for (InternalTunnel tunnel : internalTunnels) {
-            ITM_CACHE.addInternalTunnel(tunnel);
-        }
-        List<ExternalTunnel> externalTunnels = getAllExternalTunnels(broker);
-        for (ExternalTunnel tunnel : externalTunnels) {
-            ITM_CACHE.addExternalTunnel(tunnel);
-        }
-    }
-
     public static Interface getInterface(
             String name, IInterfaceManager ifaceManager) {
         Interface result = ITM_CACHE.getInterface(name);
@@ -1115,20 +721,6 @@ public final class ItmUtils {
         return result;
     }
 
-    public static List<DcGatewayIp> getDcGatewayIpList(DataBroker broker) {
-        InstanceIdentifier<DcGatewayIpList> dcGatewayIpListid =
-                InstanceIdentifier.builder(DcGatewayIpList.class).build();
-        Optional<DcGatewayIpList> dcGatewayIpListConfig =
-                ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dcGatewayIpListid, broker);
-        if (dcGatewayIpListConfig.isPresent()) {
-            DcGatewayIpList containerList = dcGatewayIpListConfig.get();
-            if (containerList != null) {
-                return containerList.getDcGatewayIp();
-            }
-        }
-        return null;
-    }
-
     public static boolean falseIfNull(Boolean value) {
         return value == null ? false : value;
     }
@@ -1164,13 +756,13 @@ public final class ItmUtils {
      * @return the TepsInNotHostedTransportZone object in the TepsNotHosted list in Oper DS
      */
     public static TepsInNotHostedTransportZone getUnknownTransportZoneFromITMOperDS(
-        String unknownTz, DataBroker dataBroker) {
+            String unknownTz, DataBroker dataBroker) {
         InstanceIdentifier<TepsInNotHostedTransportZone> unknownTzPath =
-            InstanceIdentifier.builder(NotHostedTransportZones.class)
-                    .child(TepsInNotHostedTransportZone.class,
-                    new TepsInNotHostedTransportZoneKey(unknownTz)).build();
+                InstanceIdentifier.builder(NotHostedTransportZones.class)
+                        .child(TepsInNotHostedTransportZone.class,
+                                new TepsInNotHostedTransportZoneKey(unknownTz)).build();
         Optional<TepsInNotHostedTransportZone> unknownTzOptional =
-            ItmUtils.read(LogicalDatastoreType.OPERATIONAL, unknownTzPath, dataBroker);
+                ItmUtils.read(LogicalDatastoreType.OPERATIONAL, unknownTzPath, dataBroker);
         if (unknownTzOptional.isPresent()) {
             return unknownTzOptional.get();
         }
@@ -1196,13 +788,13 @@ public final class ItmUtils {
         NodeId ovsdbNodeId = node.key().getNodeId();
 
         NodeId brNodeId = new NodeId(ovsdbNodeId.getValue()
-            + "/" + ITMConstants.BRIDGE_URI_PREFIX + "/" + bridge);
+                + "/" + ITMConstants.BRIDGE_URI_PREFIX + "/" + bridge);
 
         InstanceIdentifier<Node> bridgeIid =
-            InstanceIdentifier
-                .create(NetworkTopology.class)
-                .child(Topology.class, new TopologyKey(IfmConstants.OVSDB_TOPOLOGY_ID))
-                .child(Node.class,new NodeKey(brNodeId));
+                InstanceIdentifier
+                        .create(NetworkTopology.class)
+                        .child(Topology.class, new TopologyKey(IfmConstants.OVSDB_TOPOLOGY_ID))
+                        .child(Node.class,new NodeKey(brNodeId));
 
         Optional<Node> opBridgeNode = ItmUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
 
@@ -1230,12 +822,12 @@ public final class ItmUtils {
      * @return the Network Topology Node i.e. OVSDB node which is managing the specified bridge
      */
     public static Node getOvsdbNode(OvsdbBridgeAugmentation bridgeAugmentation,
-        DataBroker dataBroker) {
+                                    DataBroker dataBroker) {
         Node ovsdbNode = null;
         Optional<Node> opOvsdbNode = Optional.absent();
         if (bridgeAugmentation != null) {
             InstanceIdentifier<Node> ovsdbNodeIid =
-                (InstanceIdentifier<Node>) bridgeAugmentation.getManagedBy().getValue();
+                    (InstanceIdentifier<Node>) bridgeAugmentation.getManagedBy().getValue();
             opOvsdbNode = ItmUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbNodeIid, dataBroker);
         }
         if (opOvsdbNode.isPresent()) {
@@ -1317,7 +909,7 @@ public final class ItmUtils {
 
     public static List<TzMembership> removeTransportZoneMembership(TunnelEndPoints endPts, List<TzMembership> zones) {
         LOG.trace(" RemoveTransportZoneMembership TEPs {}, Membership to be removed {} ", endPts, zones);
-        List<TzMembership> existingTzList = new ArrayList<>(endPts.getTzMembership()) ;
+        List<TzMembership> existingTzList = new ArrayList<>(endPts.nonnullTzMembership()) ;
         for (TzMembership membership : zones) {
             existingTzList.remove(new TzMembershipBuilder().setZoneName(membership.getZoneName()).build());
         }
@@ -1325,21 +917,22 @@ public final class ItmUtils {
         return existingTzList;
     }
 
+    @NonNull
     public static List<TzMembership> getOriginalTzMembership(TunnelEndPoints srcTep, BigInteger dpnId,
                                                              Collection<DPNTEPsInfo> meshedDpnList) {
         LOG.trace("Original Membership for source DPN {}, source TEP {}", dpnId, srcTep);
         for (DPNTEPsInfo dstDpn : meshedDpnList) {
             if (dpnId.equals(dstDpn.getDPNID())) {
-                List<TunnelEndPoints> endPts = dstDpn.getTunnelEndPoints();
-                for (TunnelEndPoints tep : endPts) {
-                    if (tep.getIpAddress().equals(srcTep.getIpAddress())) {
-                        LOG.debug("Original Membership size {}", tep.getTzMembership().size()) ;
-                        return tep.getTzMembership();
+                for (TunnelEndPoints tep : dstDpn.nonnullTunnelEndPoints()) {
+                    if (Objects.equals(tep.getIpAddress(), srcTep.getIpAddress())) {
+                        List<TzMembership> tzMemberships = tep.nonnullTzMembership();
+                        LOG.debug("Original Membership size {}", tzMemberships.size()) ;
+                        return tzMemberships;
                     }
                 }
             }
         }
-        return null ;
+        return emptyList();
     }
 
     public static StateTunnelList buildStateTunnelList(StateTunnelListKey tlKey, String name, boolean state,
@@ -1362,9 +955,8 @@ public final class ItmUtils {
         ExternalTunnel externalTunnel = ItmUtils.ITM_CACHE.getExternalTunnel(name);
         if (internalTunnel == null && externalTunnel == null) {
             // both not present in cache. let us update and try again.
-            ItmUtils.updateTunnelsCache(broker);
-            internalTunnel = ItmUtils.ITM_CACHE.getInternalTunnel(name);
-            externalTunnel = ItmUtils.ITM_CACHE.getExternalTunnel(name);
+            internalTunnel = getInternalTunnel(name, broker);
+            externalTunnel = getExternalTunnel(name, broker);
         }
         if (internalTunnel != null) {
             srcInfoBuilder.setTepDeviceId(internalTunnel.getSourceDPN().toString())
@@ -1389,7 +981,8 @@ public final class ItmUtils {
     private static Class<? extends TepTypeBase> getDeviceType(String device) {
         if (device.startsWith("hwvtep")) {
             return TepTypeHwvtep.class;
-        } else if (device.contains("IpAddress")) {
+        } else if (InetAddresses.isInetAddress(device)) {
+            // In case of external tunnel, destination-device will be of IP address type.
             return TepTypeExternal.class;
         } else {
             return TepTypeInternal.class;
@@ -1397,11 +990,10 @@ public final class ItmUtils {
     }
 
     public static InstanceIdentifier<StateTunnelList> buildStateTunnelListId(StateTunnelListKey tlKey) {
-        return InstanceIdentifier.builder(TunnelsState.class)
-                .child(StateTunnelList.class, tlKey).build();
+        return InstanceIdentifier.builder(TunnelsState.class).child(StateTunnelList.class, tlKey).build();
     }
 
-    @Nonnull
+    @NonNull
     public static  Optional<InternalTunnel> getInternalTunnelFromDS(BigInteger srcDpn, BigInteger destDpn,
                                                                     Class<? extends TunnelTypeBase> type,
                                                                     DataBroker dataBroker) {
@@ -1412,6 +1004,24 @@ public final class ItmUtils {
         return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, pathLogicTunnel, dataBroker);
     }
 
+    private static InternalTunnel getInternalTunnelFromDS(String interfaceName, DataBroker broker) {
+        List<InternalTunnel> internalTunnels = getAllInternalTunnels(broker);
+        if (internalTunnels != null) {
+            for (InternalTunnel tunnel : internalTunnels) {
+                List<String> tunnelInterfaceNames = tunnel.getTunnelInterfaceNames();
+                if (tunnelInterfaceNames != null) {
+                    for (String tunnelInterfaceName : tunnelInterfaceNames) {
+                        if (tunnelInterfaceName.equalsIgnoreCase(interfaceName)) {
+                            LOG.trace("ItmUtils getInternalTunnelFromDS {} ", tunnelInterfaceName);
+                            return tunnel;
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     public static boolean isTunnelAggregationUsed(Class<? extends TunnelTypeBase> tunType) {
         return ItmTunnelAggregationHelper.isTunnelAggregationEnabled()
                 && (tunType.isAssignableFrom(TunnelTypeVxlan.class)
@@ -1497,4 +1107,5 @@ public final class ItmUtils {
         }
         return tunType ;
     }
+
 }