Add GPE option to ITM config
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / impl / ItmUtils.java
index 748803bf86a6499565c3cccb220e315c0e541554..949201d5899a1ee4e5b6bb7b56792e20ae038c11 100644 (file)
@@ -31,10 +31,12 @@ import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 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.TransactionCommitFailedException;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 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.confighelpers.HwVtep;
+import org.opendaylight.genius.itm.confighelpers.ItmTunnelAggregationHelper;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
@@ -56,12 +58,38 @@ 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.idmanager.rev160406.*;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBfd;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeLogicalGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifierBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifierKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.tunnel.optional.params.TunnelOptions;
+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.TunnelMonitorInterval;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParamsBuilder;
+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;
@@ -73,12 +101,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406
 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.TunnelList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus;
 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.TepTypeInternal;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeExternal;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeHwvtep;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeInternal;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelsState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder;
@@ -129,8 +157,7 @@ public class ItmUtils {
     public static final String TUNNEL_TYPE_VXLAN = "VXLAN";
     public static final String TUNNEL_TYPE_GRE = "GRE";
     public static final String TUNNEL = "tun";
-    public static final IpPrefix DUMMY_IP_PREFIX = new IpPrefix(
-        ITMConstants.DUMMY_PREFIX.toCharArray());
+    public static final IpPrefix DUMMY_IP_PREFIX = new IpPrefix(ITMConstants.DUMMY_PREFIX.toCharArray());
     public static ItmCache itmCache = new ItmCache();
 
     private static final Logger LOG = LoggerFactory.getLogger(ItmUtils.class);
@@ -155,6 +182,7 @@ public class ItmUtils {
         }
     };
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public static <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
                                                           InstanceIdentifier<T> path, DataBroker broker) {
         try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
@@ -165,27 +193,33 @@ public class ItmUtils {
     }
 
     public static <T extends DataObject> void asyncWrite(LogicalDatastoreType datastoreType,
-                                                         InstanceIdentifier<T> path, T data, DataBroker broker, FutureCallback<Void> callback) {
+                                                         InstanceIdentifier<T> path, T data, DataBroker broker,
+                                                         FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.put(datastoreType, path, data, true);
         Futures.addCallback(tx.submit(), callback);
     }
 
     public static <T extends DataObject> void asyncUpdate(LogicalDatastoreType datastoreType,
-                                                          InstanceIdentifier<T> path, T data, DataBroker broker, FutureCallback<Void> callback) {
+                                                          InstanceIdentifier<T> path, T data, DataBroker broker,
+                                                          FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.merge(datastoreType, path, data, true);
         Futures.addCallback(tx.submit(), callback);
     }
 
     public static <T extends DataObject> void asyncDelete(LogicalDatastoreType datastoreType,
-                                                          InstanceIdentifier<T> path, DataBroker broker, FutureCallback<Void> callback) {
+                                                          InstanceIdentifier<T> path, DataBroker broker,
+                                                          FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.delete(datastoreType, path);
         Futures.addCallback(tx.submit(), callback);
     }
-    public static <T extends DataObject> void asyncBulkRemove(final DataBroker broker,final LogicalDatastoreType datastoreType,
-                                                              List<InstanceIdentifier<T>> pathList, FutureCallback<Void> callback) {
+
+    public static <T extends DataObject> void asyncBulkRemove(final DataBroker broker,
+                                                              final LogicalDatastoreType datastoreType,
+                                                              List<InstanceIdentifier<T>> pathList,
+                                                              FutureCallback<Void> callback) {
         if (!pathList.isEmpty()) {
             WriteTransaction tx = broker.newWriteOnlyTransaction();
             for (InstanceIdentifier<T> path : pathList) {
@@ -208,35 +242,47 @@ public class ItmUtils {
     public static String getTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName,
                                                String localHostName, String remoteHostName, String tunnelType) {
         String tunnelTypeStr;
-        if(tunnelType.contains("TunnelTypeGre")) {
+        if (tunnelType.contains("TunnelTypeGre")) {
             tunnelTypeStr = ITMConstants.TUNNEL_TYPE_GRE;
+        } else if (tunnelType.contains("TunnelTypeLogicalGroup")) {
+            tunnelTypeStr = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
         } else {
             tunnelTypeStr = ITMConstants.TUNNEL_TYPE_VXLAN;
         }
-        String trunkInterfaceName = String.format(  "%s:%s:%s:%s", parentInterfaceName, localHostName,
+        String trunkInterfaceName = String.format("%s:%s:%s:%s", parentInterfaceName, localHostName,
                 remoteHostName, tunnelTypeStr);
         LOG.trace("trunk interface name is {}", trunkInterfaceName);
         trunkInterfaceName = String.format("%s%s", TUNNEL, getUniqueIdString(trunkInterfaceName));
         return trunkInterfaceName;
     }
 
-    public static void releaseIdForTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName, String localHostName, String remoteHostName, String tunnelType) {
+    public static void releaseIdForTrunkInterfaceName(IdManagerService idManager, String parentInterfaceName,
+                                                      String localHostName, String remoteHostName, String tunnelType) {
         String tunnelTypeStr;
-        if(tunnelType.contains("TunnelTypeGre")) {
+        if (tunnelType.contains("TunnelTypeGre")) {
             tunnelTypeStr = ITMConstants.TUNNEL_TYPE_GRE;
         } else {
             tunnelTypeStr = ITMConstants.TUNNEL_TYPE_VXLAN;
         }
-        String trunkInterfaceName = String.format("%s:%s:%s:%s", parentInterfaceName, localHostName, remoteHostName, tunnelTypeStr);
-        LOG.trace("Releasing Id for trunkInterface - {}", trunkInterfaceName );
+        String trunkInterfaceName = String.format("%s:%s:%s:%s", parentInterfaceName, localHostName,
+                remoteHostName, tunnelTypeStr);
+        LOG.trace("Releasing Id for trunkInterface - {}", trunkInterfaceName);
         //releaseId(idManager, trunkInterfaceName) ;
     }
 
+    public static String getLogicalTunnelGroupName(BigInteger srcDpnId, BigInteger destDpnId) {
+        String tunnelTypeStr = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
+        String groupName = String.format("%s:%s:%s", srcDpnId.toString(), destDpnId.toString(), tunnelTypeStr);
+        LOG.trace("logical tunnel group name is {}", groupName);
+        groupName = String.format("%s%s", TUNNEL, getUniqueIdString(groupName));
+        return groupName;
+    }
+
     public static InetAddress getInetAddressFromIpAddress(IpAddress ip) {
         return InetAddresses.forString(ip.getIpv4Address().getValue());
     }
 
-    public static InstanceIdentifier<DPNTEPsInfo> getDPNTEPInstance(BigInteger dpIdKey) {
+    public static InstanceIdentifier<DPNTEPsInfo> getDpnTepInstance(BigInteger dpIdKey) {
         InstanceIdentifier.InstanceIdentifierBuilder<DPNTEPsInfo> dpnTepInfoBuilder =
                 InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class,
                         new DPNTEPsInfoKey(dpIdKey));
@@ -245,19 +291,21 @@ public class ItmUtils {
     }
 
     public static DPNTEPsInfo createDPNTepInfo(BigInteger dpId, List<TunnelEndPoints> endpoints) {
-
         return new DPNTEPsInfoBuilder().setKey(new DPNTEPsInfoKey(dpId)).setTunnelEndPoints(endpoints).build();
     }
 
     public static TunnelEndPoints createTunnelEndPoints(BigInteger dpnId, IpAddress ipAddress, String portName,
                                                         boolean isOfTunnel, int vlanId, IpPrefix prefix,
                                                         IpAddress gwAddress, List<TzMembership> zones,
-                                                        Class<? extends TunnelTypeBase>  tunnel_type) {
+                                                        Class<? extends TunnelTypeBase>  tunnelType,
+                                                        String tos) {
         // when Interface Mgr provides support to take in Dpn Id
-        return new TunnelEndPointsBuilder().setKey(new TunnelEndPointsKey(ipAddress, portName,tunnel_type, vlanId))
+        return new TunnelEndPointsBuilder().setKey(new TunnelEndPointsKey(ipAddress, portName,tunnelType, vlanId))
                 .setSubnetMask(prefix).setGwIpAddress(gwAddress).setTzMembership(zones)
                 .setOptionOfTunnel(isOfTunnel).setInterfaceName(ItmUtils.getInterfaceName(dpnId, portName, vlanId))
-                .setTunnelType(tunnel_type).build();
+                .setTunnelType(tunnelType)
+                .setOptionTunnelTos(tos)
+                .build();
     }
 
     public static DpnEndpoints createDpnEndpoints(List<DPNTEPsInfo> dpnTepInfo) {
@@ -271,25 +319,59 @@ public class ItmUtils {
         return id;
     }
 
+    public static InstanceIdentifier<IfTunnel> buildTunnelId(String ifName) {
+        InstanceIdentifier<IfTunnel> tunnelInstIdentifier = InstanceIdentifier.builder(Interfaces.class)
+                .child(Interface.class, new InterfaceKey(ifName)).augmentation(IfTunnel.class).build();
+        return tunnelInstIdentifier;
+    }
+
+    public static Interface buildLogicalTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled) {
+        InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName)
+                .setDescription(desc).setEnabled(enabled).setType(Tunnel.class);
+        ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).build();
+        builder.addAugmentation(ParentRefs.class, parentRefs);
+
+        IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(new IpAddress("0.0.0.0".toCharArray()))
+                .setTunnelSource(new IpAddress("0.0.0.0".toCharArray())).setInternal(true).setMonitorEnabled(false)
+                .setTunnelInterfaceType(TunnelTypeLogicalGroup.class).setTunnelRemoteIpFlow(false).build();
+        builder.addAugmentation(IfTunnel.class, tunnel);
+        return builder.build();
+    }
+
+    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,
+                                                 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);
+    }
+
     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,
                                                  Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
-                                                 Integer monitorInterval, boolean useOfTunnel) {
+                                                 Integer monitorInterval, boolean useOfTunnel, String parentIfaceName,
+                                                 List<TunnelOptions> tunnelOptions) {
         InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName)
                 .setDescription(desc).setEnabled(enabled).setType(Tunnel.class);
-        ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).build();
+        ParentRefs parentRefs =
+                new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).setParentInterface(parentIfaceName).build();
         builder.addAugmentation(ParentRefs.class, parentRefs);
-        Long monitoringInterval=null;
-        ifvlanId > 0) {
+        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);
-
+        LOG.debug("buildTunnelInterface: monitorProtocol = {} and monitorInterval = {}",
+                monitorProtocol.getName(),monitorInterval);
 
-        if(monitorInterval != null) {
+        if (monitorInterval != null) {
             monitoringInterval = monitorInterval.longValue();
         }
 
@@ -297,51 +379,54 @@ public class ItmUtils {
                 .setTunnelSource(localIp).setTunnelInterfaceType(tunType).setInternal(internal)
                 .setMonitorEnabled(monitorEnabled).setMonitorProtocol(monitorProtocol)
                 .setMonitorInterval(monitoringInterval).setTunnelRemoteIpFlow(useOfTunnel)
+                .setTunnelOptions(tunnelOptions)
                 .build();
         builder.addAugmentation(IfTunnel.class, tunnel);
         return builder.build();
     }
 
-    public static Interface buildHwTunnelInterface(String tunnelIfName, String desc, boolean enabled, String topo_id,
-                                                   String node_id, Class<? extends TunnelTypeBase> tunType, IpAddress srcIp, IpAddress destIp,
-                                                   IpAddress gWIp, Boolean monitor_enabled, Class<? extends TunnelMonitoringTypeBase> monitorProtocol, Integer monitor_interval){
-        InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelIfName)).setName(
-                tunnelIfName).setDescription(desc).
-                setEnabled(enabled).setType(Tunnel.class);
+    public static Interface buildHwTunnelInterface(String tunnelIfName, String desc, boolean enabled, String topoId,
+                                                   String nodeId, Class<? extends TunnelTypeBase> tunType,
+                                                   IpAddress srcIp, IpAddress destIp, IpAddress gwIp,
+                                                   Boolean monitorEnabled,
+                                                   Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
+                                                   Integer monitorInterval) {
+        InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelIfName))
+                .setName(tunnelIfName).setDescription(desc).setEnabled(enabled).setType(Tunnel.class);
         List<NodeIdentifier> nodeIds = new ArrayList<>();
-        NodeIdentifier hWnode = new NodeIdentifierBuilder().setKey(new NodeIdentifierKey(topo_id)).setTopologyId(
-                topo_id).
-                setNodeId(node_id).build();
-        nodeIds.add(hWnode);
+        NodeIdentifier hwNode = new NodeIdentifierBuilder().setKey(new NodeIdentifierKey(topoId))
+                .setTopologyId(topoId).setNodeId(nodeId).build();
+        nodeIds.add(hwNode);
         ParentRefs parent = new ParentRefsBuilder().setNodeIdentifier(nodeIds).build();
         builder.addAugmentation(ParentRefs.class, parent);
         Long monitoringInterval = (long) ITMConstants.DEFAULT_MONITOR_INTERVAL;
         Boolean monitoringEnabled = true;
         Class<? extends TunnelMonitoringTypeBase> monitoringProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
-        if(monitor_interval!= null) {
-            monitoringInterval = monitor_interval.longValue();
+        if (monitoringInterval != null) {
+            monitoringInterval = monitorInterval.longValue();
         }
-        if(monitor_enabled!=null  ) {
-            monitoringEnabled = monitor_enabled;
+        if (monitorEnabled != null) {
+            monitoringEnabled = monitorEnabled;
         }
-        if(monitorProtocol!=null) {
+        if (monitorProtocol != null) {
             monitoringProtocol = monitorProtocol;
         }
-        IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(destIp).setTunnelGateway(gWIp).setTunnelSource(
-                srcIp).setMonitorEnabled(monitoringEnabled).setMonitorProtocol(monitorProtocol).setMonitorInterval(100L).
-                setTunnelInterfaceType(tunType).setInternal(false).build();
+        IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(destIp).setTunnelGateway(gwIp)
+                .setTunnelSource(srcIp).setMonitorEnabled(monitoringEnabled).setMonitorProtocol(monitorProtocol)
+                .setMonitorInterval(100L).setTunnelInterfaceType(tunType).setInternal(false).build();
         builder.addAugmentation(IfTunnel.class, tunnel);
-        LOG.trace("iftunnel {} built from hwvtep {} ", tunnel, node_id);
+        LOG.trace("iftunnel {} built from hwvtep {} ", tunnel, nodeId);
         return builder.build();
     }
 
 
-    public static InternalTunnel buildInternalTunnel( BigInteger srcDpnId, BigInteger dstDpnId,
-                                                      Class<? extends TunnelTypeBase> tunType,
-                                                      String trunkInterfaceName) {
-        InternalTunnel tnl = new InternalTunnelBuilder().setKey(new InternalTunnelKey(dstDpnId, srcDpnId, tunType)).setDestinationDPN(dstDpnId)
+    public static InternalTunnel buildInternalTunnel(BigInteger srcDpnId, BigInteger dstDpnId,
+                                                     Class<? extends TunnelTypeBase> tunType,
+                                                     String trunkInterfaceName) {
+        InternalTunnel tnl = new InternalTunnelBuilder().setKey(new InternalTunnelKey(dstDpnId, srcDpnId, tunType))
+                .setDestinationDPN(dstDpnId)
                 .setSourceDPN(srcDpnId).setTransportType(tunType)
-                .setTunnelInterfaceName(trunkInterfaceName).build();
+                .setTunnelInterfaceNames(Collections.singletonList(trunkInterfaceName)).build();
         return tnl ;
     }
 
@@ -353,45 +438,45 @@ public class ItmUtils {
                 .setSourceDevice(srcNode).setDestinationDevice(dstNode)
                 .setTunnelInterfaceName(trunkInterfaceName)
                 .setTransportType(tunType).build();
-        return extTnl ;
+        return extTnl;
     }
 
     public static List<DPNTEPsInfo> getTunnelMeshInfo(DataBroker dataBroker) {
-        List<DPNTEPsInfo> dpnTEPs= null ;
+        List<DPNTEPsInfo> dpnTEPs = null ;
 
         // Read the Mesh Information from Cache if not read from the DS
         dpnTEPs = getTunnelMeshInfo() ;
-        if( dpnTEPs != null ) {
-            return dpnTEPs ;
+        if (dpnTEPs != null) {
+            return dpnTEPs;
         }
 
         // Read the EndPoint Info from the operational database
-        InstanceIdentifierBuilder<DpnEndpoints> depBuilder = InstanceIdentifier.builder( DpnEndpoints.class);
+        InstanceIdentifierBuilder<DpnEndpoints> depBuilder = InstanceIdentifier.builder(DpnEndpoints.class);
         InstanceIdentifier<DpnEndpoints> deps = depBuilder.build();
         Optional<DpnEndpoints> dpnEps = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, deps, dataBroker);
         if (dpnEps.isPresent()) {
-            DpnEndpoints tn= dpnEps.get() ;
+            DpnEndpoints tn = dpnEps.get();
             dpnTEPs = tn.getDPNTEPsInfo();
-            LOG.debug( "Read from CONFIGURATION datastore - No. of Dpns " , dpnTEPs.size() );
+            LOG.debug("Read from CONFIGURATION datastore - No. of Dpns " , dpnTEPs.size());
         } else {
-            LOG.debug( "No Dpn information in CONFIGURATION datastore "  );
+            LOG.debug("No Dpn information in CONFIGURATION datastore ");
         }
-        return dpnTEPs ;
+        return dpnTEPs;
     }
 
     // Reading the Mesh Information from Cache
-    public static List<DPNTEPsInfo> getTunnelMeshInfo(){
+    public static List<DPNTEPsInfo> getTunnelMeshInfo() {
         List<DPNTEPsInfo> dpnTepsInfo = null ;
         List<Object> values = null ;
 
         values = DataStoreCache.getValues(ITMConstants.DPN_TEPs_Info_CACHE_NAME);
-        if( values != null ) {
+        if (values != null) {
             dpnTepsInfo = new ArrayList<>() ;
-            for( Object value : values ) {
+            for (Object value : values) {
                 dpnTepsInfo.add((DPNTEPsInfo)value) ;
             }
         }
-        return dpnTepsInfo ;
+        return dpnTepsInfo;
     }
 
     public static int getUniqueId(IdManagerService idManager, String idKey) {
@@ -402,7 +487,7 @@ public class ItmUtils {
         try {
             Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
             RpcResult<AllocateIdOutput> rpcResult = result.get();
-            if(rpcResult.isSuccessful()) {
+            if (rpcResult.isSuccessful()) {
                 return rpcResult.getResult().getIdValue().intValue();
             } else {
                 LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors());
@@ -423,7 +508,7 @@ public class ItmUtils {
         try {
             Future<RpcResult<Void>> result = idManager.releaseId(idInput);
             RpcResult<Void> rpcResult = result.get();
-            if(!rpcResult.isSuccessful()) {
+            if (!rpcResult.isSuccessful()) {
                 LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors());
             }
         } catch (InterruptedException | ExecutionException e) {
@@ -431,14 +516,14 @@ public class ItmUtils {
         }
     }
 
-    public static List<DPNTEPsInfo> getDPNTEPListFromDPNId(DataBroker dataBroker, List<BigInteger> dpnIds) {
+    public static List<DPNTEPsInfo> getDpnTepListFromDpnId(DataBroker dataBroker, List<BigInteger> dpnIds) {
         List<DPNTEPsInfo> meshedDpnList = getTunnelMeshInfo(dataBroker) ;
         List<DPNTEPsInfo> cfgDpnList = new ArrayList<>();
-        ifnull != meshedDpnList) {
-            for(BigInteger dpnId : dpnIds) {
-                for( DPNTEPsInfo teps : meshedDpnList ) {
-                    ifdpnId.equals(teps.getDPNID())) {
-                        cfgDpnList.add( teps) ;
+        if (null != meshedDpnList) {
+            for (BigInteger dpnId : dpnIds) {
+                for (DPNTEPsInfo teps : meshedDpnList) {
+                    if (dpnId.equals(teps.getDPNID())) {
+                        cfgDpnList.add(teps);
                     }
                 }
             }
@@ -446,9 +531,11 @@ public class ItmUtils {
         return cfgDpnList;
     }
 
-    public static void setUpOrRemoveTerminatingServiceTable(BigInteger dpnId, IMdsalApiManager mdsalManager, boolean addFlag) {
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public static void setUpOrRemoveTerminatingServiceTable(BigInteger dpnId, IMdsalApiManager mdsalManager,
+                                                            boolean addFlag) {
         String logmsg = addFlag ? "Installing" : "Removing";
-        LOG.trace( logmsg + " PUNT to Controller flow in DPN {} ", dpnId );
+        LOG.trace(logmsg + " PUNT to Controller flow in DPN {} ", dpnId);
         List<ActionInfo> listActionInfo = new ArrayList<>();
         listActionInfo.add(new ActionPuntToController());
 
@@ -461,15 +548,12 @@ public 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)),
+                    .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);
-            if(addFlag) {
+            if (addFlag) {
                 mdsalManager.installFlow(terminatingServiceTableFlowEntity);
             } else {
                 mdsalManager.removeFlow(terminatingServiceTableFlowEntity);
@@ -482,6 +566,7 @@ public class ItmUtils {
     private static String getFlowRef(long termSvcTable, int svcId) {
         return String.valueOf(termSvcTable) + svcId;
     }
+
     public static InstanceIdentifier<VtepConfigSchema> getVtepConfigSchemaIdentifier(String schemaName) {
         return InstanceIdentifier.builder(VtepConfigSchemas.class)
                 .child(VtepConfigSchema.class, new VtepConfigSchemaKey(schemaName)).build();
@@ -490,13 +575,16 @@ public class ItmUtils {
     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);
@@ -504,8 +592,8 @@ public class ItmUtils {
             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.");
+                Preconditions.checkArgument(false, "VTEP schema with subnet [" + subnetCidr
+                        "] already exists. Multiple VTEP schemas with same subnet is not allowed.");
             }
         }
         if (isNotEmpty(getDpnIdList(validSchema.getDpnIds()))) {
@@ -513,16 +601,17 @@ public class ItmUtils {
             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.");
+                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);
+            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)) {
@@ -531,13 +620,14 @@ public class ItmUtils {
                 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.";
+                    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()));
@@ -552,27 +642,30 @@ public class ItmUtils {
         if (gatewayIp != null) {
             String strGatewayIp = String.valueOf(gatewayIp.getValue());
             if (!strGatewayIp.equals(ITMConstants.DUMMY_IP_ADDRESS) && !subnetUtils.getInfo().isInRange(strGatewayIp)) {
-                Preconditions.checkArgument(false, "Gateway IP address " + strGatewayIp +
-                        " is not in subnet range " + subnetCidr);
+                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;
+            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> lstDpns,
+                                                                              List<VtepConfigSchema> existingSchemas) {
         List<BigInteger> lstConflictingDpns = new ArrayList<>();
         for (VtepConfigSchema schema : emptyIfNull(existingSchemas)) {
             if (!StringUtils.equalsIgnoreCase(schemaName, schema.getSchemaName())
@@ -586,13 +679,15 @@ public class ItmUtils {
         }
         return lstConflictingDpns;
     }
+
     public static VtepConfigSchema constructVtepConfigSchema(String schemaName, String portName, Integer vlanId,
-                                                             String subnetMask, String gatewayIp, String transportZone,String tunnelType, List<BigInteger> dpnIds,
+                                                             String subnetMask, String gatewayIp, String transportZone,
+                                                             String tunnelType, List<BigInteger> dpnIds,
                                                              String excludeIpFilter) {
         IpAddress gatewayIpObj = StringUtils.isBlank(gatewayIp) ? null : new IpAddress(gatewayIp.toCharArray());
         IpPrefix subnet = StringUtils.isBlank(subnetMask) ? null : new IpPrefix(subnetMask.toCharArray());
         Class<? extends TunnelTypeBase> tunType ;
-        iftunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) {
+        if (tunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) {
             tunType = TunnelTypeVxlan.class ;
         } else {
             tunType = TunnelTypeGre.class ;
@@ -603,6 +698,7 @@ public class ItmUtils {
                 .setExcludeIpFilter(excludeIpFilter);
         return schemaBuilder.build();
     }
+
     public static List<IpAddress> getExcludeIpAddresses(String excludeIpFilter, SubnetInfo subnetInfo) {
         final List<IpAddress> lstIpAddress = new ArrayList<>();
         if (StringUtils.isBlank(excludeIpFilter)) {
@@ -619,18 +715,18 @@ public class ItmUtils {
                 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());
+                        "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());
+                        "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 i = startIp; i <= endIp; i++) {
-                    String ipAddress = ipFormat(toIpArray(i));
+                for (int iter = startIp; iter <= endIp; iter++) {
+                    String ipAddress = ipFormat(toIpArray(iter));
                     validateAndAddIpAddressToList(subnetInfo, lstIpAddress, ipAddress);
                 }
             } else {
@@ -639,35 +735,40 @@ public class ItmUtils {
         }
         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());
+                "Invalid exclude IP filter: IP address [" + ip + "] not in subnet range "
+                        subnetInfo.getCidrSignature());
         lstIpAddress.add(new IpAddress(ip.toCharArray()));
     }
+
     private static int[] toIpArray(int val) {
         int[] ret = new int[4];
-        for (int j = 3; j >= 0; --j) {
-            ret[j] |= val >>> 8 * (3 - j) & 0xff;
+        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 i = 0; i < octets.length; ++i) {
-            str.append(octets[i]);
-            if (i != octets.length - 1) {
+        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) {
+                                                               List<BigInteger> lstDpnsForDelete,
+                                                               IITMProvider itmProvider) {
         Preconditions.checkArgument(StringUtils.isNotBlank(schemaName));
         if ((lstDpnsForAdd == null || lstDpnsForAdd.isEmpty())
                 && (lstDpnsForDelete == null || lstDpnsForDelete.isEmpty())) {
@@ -676,8 +777,8 @@ public class ItmUtils {
         }
         VtepConfigSchema schema = itmProvider.getVtepConfigSchema(schemaName);
         if (schema == null) {
-            Preconditions.checkArgument(false, "Specified VTEP Schema [" + schemaName +
-                    "] doesn't exists!");
+            Preconditions.checkArgument(false, "Specified VTEP Schema [" + schemaName
+                    "] doesn't exists!");
         }
         List<BigInteger> existingDpnIds = getDpnIdList(schema.getDpnIds());
         if (isNotEmpty(lstDpnsForAdd)) {
@@ -685,8 +786,8 @@ public class ItmUtils {
             List<BigInteger> lstAlreadyExistingDpns = new ArrayList<>(existingDpnIds);
             lstAlreadyExistingDpns.retainAll(lstDpnsForAdd);
             Preconditions.checkArgument(lstAlreadyExistingDpns.isEmpty(),
-                    "DPN ID's " + lstAlreadyExistingDpns +
-                            " already exists in VTEP schema [" + schemaName + "]");
+                    "DPN ID's " + lstAlreadyExistingDpns
+                            " already exists in VTEP schema [" + schemaName + "]");
             //    }
             if (schema.getTunnelType().equals(TunnelTypeGre.class)) {
                 validateForSingleGreTep(schema.getSchemaName(), lstDpnsForAdd, itmProvider.getAllVtepConfigSchemas());
@@ -694,48 +795,55 @@ public class ItmUtils {
         }
         if (isNotEmpty(lstDpnsForDelete)) {
             if (existingDpnIds == null || existingDpnIds.isEmpty()) {
-                String builder = "DPN ID's " + lstDpnsForDelete +
-                        " specified for delete from VTEP schema [" + schemaName +
-                        "] are not configured in the schema.";
+                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.";
+                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 : String.valueOf(subnet.getValue());
     }
+
     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);
     }
-    public static HwVtep createHwVtepObject(String topo_id, String node_id, IpAddress ipAddress, IpPrefix ipPrefix, IpAddress gatewayIP, int vlanID, Class<? extends TunnelTypeBase> tunnel_type, TransportZone transportZone) {
+
+    public static HwVtep createHwVtepObject(String topoId, String nodeId, IpAddress ipAddress, IpPrefix ipPrefix,
+                                            IpAddress gatewayIP, int vlanID,
+                                            Class<? extends TunnelTypeBase> tunneltype, TransportZone transportZone) {
         HwVtep hwVtep = new HwVtep();
         hwVtep.setGatewayIP(gatewayIP);
         hwVtep.setHwIp(ipAddress);
         hwVtep.setIpPrefix(ipPrefix);
-        hwVtep.setNode_id(node_id);
-        hwVtep.setTopo_id(topo_id);
+        hwVtep.setNode_id(nodeId);
+        hwVtep.setTopo_id(topoId);
         hwVtep.setTransportZone(transportZone.getZoneName());
-        hwVtep.setTunnel_type(tunnel_type);
+        hwVtep.setTunnel_type(tunneltype);
         hwVtep.setVlanID(vlanID);
         return hwVtep;
     }
 
-    public static String getHwParentIf(String topo_id, String srcNodeid) {
-        return String.format("%s:%s", topo_id, srcNodeid);
+    public static String getHwParentIf(String topoId, String srcNodeid) {
+        return String.format("%s:%s", topoId, srcNodeid);
     }
 
     public static <T extends DataObject> void syncWrite(LogicalDatastoreType datastoreType,
@@ -751,36 +859,41 @@ public class ItmUtils {
         }
     }
 
-    public static List<BigInteger> getDpnIdList( List<DpnIds> dpnIds ) {
+    public static List<BigInteger> getDpnIdList(List<DpnIds> dpnIds) {
         List<BigInteger> dpnList = new ArrayList<>() ;
-        forDpnIds dpn : dpnIds) {
+        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() ;
-        forBigInteger dpnId : dpnIds) {
-            dpnIdList.add(builder.setKey(new DpnIdsKey(dpnId)).setDPN(dpnId).build() );
+    public static List<DpnIds> getDpnIdsListFromBigInt(List<BigInteger> dpnIds) {
+        List<DpnIds> dpnIdList = new ArrayList<>();
+        DpnIdsBuilder builder = new DpnIdsBuilder();
+        for (BigInteger dpnId : dpnIds) {
+            dpnIdList.add(builder.setKey(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) {
-        InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> idBuilder =
-                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));
-        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> id = idBuilder.build();
+    public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508
+            .interfaces.state.Interface> buildStateInterfaceId(String interfaceName) {
+        InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508
+                .interfaces.state.Interface> idBuilder = 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));
+        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508
+                .interfaces.state.Interface> id = idBuilder.build();
         return id;
     }
+
     public static Boolean readMonitoringStateFromCache(DataBroker dataBroker) {
         InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.create(TunnelMonitorParams.class);
-        TunnelMonitorParams tunnelMonitorParams = (TunnelMonitorParams) DataStoreCache.get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"MonitorParams",dataBroker,true);
-        if(tunnelMonitorParams!=null) {
+        TunnelMonitorParams tunnelMonitorParams = (TunnelMonitorParams) DataStoreCache
+                .get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"MonitorParams",dataBroker,true);
+        if (tunnelMonitorParams != null) {
             return tunnelMonitorParams.isEnabled();
         } else {
             return ITMConstants.DEFAULT_MONITOR_ENABLED;
@@ -789,8 +902,9 @@ public class ItmUtils {
 
     public static Integer readMonitorIntervalfromCache(DataBroker dataBroker) {
         InstanceIdentifier<TunnelMonitorInterval> iid = InstanceIdentifier.create(TunnelMonitorInterval.class);
-        TunnelMonitorInterval tunnelMonitorIOptional = (TunnelMonitorInterval)DataStoreCache.get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"Interval",dataBroker,true);
-        if(tunnelMonitorIOptional!=null) {
+        TunnelMonitorInterval tunnelMonitorIOptional = (TunnelMonitorInterval)DataStoreCache
+                .get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"Interval",dataBroker,true);
+        if (tunnelMonitorIOptional != null) {
             return tunnelMonitorIOptional.getInterval();
         }
         return null;
@@ -800,9 +914,9 @@ public class ItmUtils {
     public static Integer determineMonitorInterval(DataBroker dataBroker) {
         Integer monitorInterval = ItmUtils.readMonitorIntervalfromCache(dataBroker);
         LOG.debug("determineMonitorInterval: monitorInterval from DS = {}", monitorInterval);
-        if(monitorInterval==null){
+        if (monitorInterval == null) {
             Class<? extends TunnelMonitoringTypeBase> monitorProtocol = determineMonitorProtocol(dataBroker);
-            if(monitorProtocol.isAssignableFrom(TunnelMonitoringTypeBfd.class)) {
+            if (monitorProtocol.isAssignableFrom(TunnelMonitoringTypeBfd.class)) {
                 monitorInterval = ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL;
             } else {
                 monitorInterval = ITMConstants.DEFAULT_MONITOR_INTERVAL;
@@ -811,33 +925,36 @@ public class ItmUtils {
         LOG.debug("determineMonitorInterval: monitorInterval = {}", monitorInterval);
         InstanceIdentifier<TunnelMonitorInterval> iid = InstanceIdentifier.builder(TunnelMonitorInterval.class).build();
         TunnelMonitorInterval intervalBuilder = new TunnelMonitorIntervalBuilder().setInterval(monitorInterval).build();
-        ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, intervalBuilder, dataBroker, ItmUtils.DEFAULT_CALLBACK);
+        ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, intervalBuilder, dataBroker,
+                ItmUtils.DEFAULT_CALLBACK);
         return monitorInterval;
     }
 
-    public static List<String> getInternalTunnelInterfaces(DataBroker dataBroker){
+    public static List<String> getInternalTunnelInterfaces(DataBroker dataBroker) {
         List<String> tunnelList = new ArrayList<>();
         Collection<String> internalInterfaces = itmCache.getAllInternalInterfaces();
-        if(internalInterfaces == null) {
+        if (internalInterfaces == null) {
             updateTunnelsCache(dataBroker);
             internalInterfaces = itmCache.getAllInternalInterfaces();
         }
         LOG.debug("ItmUtils.getTunnelList Cache Internal Interfaces size: {} ", internalInterfaces.size());
-        if(internalInterfaces!=null) {
+        if (internalInterfaces != null) {
             tunnelList.addAll(internalInterfaces);
         }
         LOG.trace("ItmUtils.getTunnelList Internal: {}", tunnelList);
         return tunnelList;
     }
 
-    public static List<String> getTunnelsofTzone(List<HwVtep> hwVteps, String tzone, DataBroker dataBroker, Boolean hwVtepsExist) {
+    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> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
-        if (tZoneOptional.isPresent()) {
-            TransportZone transportZone = tZoneOptional.get();
+        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()) {
@@ -845,20 +962,25 @@ public class ItmUtils {
                         for (Vteps vtepLocal : sub.getVteps()) {
                             for (Vteps vtepRemote : sub.getVteps()) {
                                 if (!vtepLocal.equals(vtepRemote)) {
-                                    InternalTunnelKey key = new InternalTunnelKey(vtepRemote.getDpnId(), vtepLocal.getDpnId(), tunType);
+                                    InternalTunnelKey key = new InternalTunnelKey(vtepRemote.getDpnId(),
+                                            vtepLocal.getDpnId(), tunType);
                                     InstanceIdentifier<InternalTunnel> intIID =
-                                            InstanceIdentifier.builder(TunnelList.class).
-                                                    child(InternalTunnel.class, key).build();
-                                    Optional<InternalTunnel> TunnelsOptional =
+                                            InstanceIdentifier.builder(TunnelList.class)
+                                                    .child(InternalTunnel.class, key).build();
+                                    Optional<InternalTunnel> tunnelsOptional =
                                             ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
-                                    if (TunnelsOptional.isPresent()) {
-                                        String tunnelInterfaceName = TunnelsOptional.get().getTunnelInterfaceName();
-                                        LOG.trace("Internal Tunnel added {}", tunnelInterfaceName);
-                                        tunnels.add(tunnelInterfaceName);
+                                    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()) {
+                            if (hwVteps != null && !hwVteps.isEmpty()) {
                                 for (HwVtep hwVtep : hwVteps) {
                                     tunnels.add(getExtTunnel(hwVtep.getNode_id(), vtepLocal.getDpnId().toString(),
                                             tunType, dataBroker));
@@ -874,8 +996,10 @@ public class ItmUtils {
                 for (HwVtep hwVtep : hwVteps) {
                     for (HwVtep hwVtepOther : hwVteps) {
                         if (!hwVtep.getHwIp().equals(hwVtepOther.getHwIp())) {
-                            tunnels.add(getExtTunnel(hwVtep.getNode_id(), hwVtepOther.getNode_id(), tunType, dataBroker));
-                            tunnels.add(getExtTunnel(hwVtepOther.getNode_id(), hwVtep.getNode_id(), tunType, dataBroker));
+                            tunnels.add(getExtTunnel(hwVtep.getNode_id(), hwVtepOther.getNode_id(),
+                                    tunType, dataBroker));
+                            tunnels.add(getExtTunnel(hwVtepOther.getNode_id(), hwVtep.getNode_id(),
+                                    tunType, dataBroker));
                         }
                     }
                 }
@@ -887,11 +1011,12 @@ public class ItmUtils {
     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> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
-        if (tZoneOptional.isPresent()) {
-            TransportZone transportZone = tZoneOptional.get();
+        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()) {
@@ -902,14 +1027,18 @@ public class ItmUtils {
                                             new InternalTunnelKey(vtepRemote.getDpnId(), vtepLocal.getDpnId(),
                                                     transportZone.getTunnelType());
                                     InstanceIdentifier<InternalTunnel> intIID =
-                                            InstanceIdentifier.builder(TunnelList.class).
-                                                    child(InternalTunnel.class, key).build();
+                                            InstanceIdentifier.builder(TunnelList.class)
+                                                    .child(InternalTunnel.class, key).build();
                                     Optional<InternalTunnel> tunnelsOptional =
                                             ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
                                     if (tunnelsOptional.isPresent()) {
-                                        String tunnelInterfaceName = tunnelsOptional.get().getTunnelInterfaceName();
-                                        LOG.trace("Internal Tunnel added {}", tunnelInterfaceName);
-                                        tunnels.add(tunnelInterfaceName);
+                                        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);
+                                        }
                                     }
                                 }
                             }
@@ -921,11 +1050,12 @@ public class ItmUtils {
         return tunnels;
     }
 
-    private static String getExtTunnel(String node_id, String dpId,Class<? extends TunnelTypeBase> tunType, DataBroker dataBroker) {
-        LOG.trace("getting ext tunnel for {} and dpId {}",node_id,dpId);
-        ExternalTunnelKey key = getExternalTunnelKey(dpId, node_id, tunType);
-        InstanceIdentifier<ExternalTunnel> intIID = InstanceIdentifier.builder(ExternalTunnelList.class).
-                child(ExternalTunnel.class, key).build();
+    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()) {
@@ -935,7 +1065,9 @@ public class ItmUtils {
         }
         return null;
     }
-    public static ExternalTunnelKey getExternalTunnelKey(String dst , String src, Class<? extends TunnelTypeBase> tunType) {
+
+    public static ExternalTunnelKey getExternalTunnelKey(String dst , String src,
+                                                         Class<? extends TunnelTypeBase> tunType) {
         if (src.indexOf("physicalswitch") > 0) {
             src = src.substring(0, src.indexOf("physicalswitch") - 1);
         }
@@ -945,18 +1077,35 @@ public class ItmUtils {
         return new ExternalTunnelKey(dst, src, tunType);
     }
 
-    public static List<TunnelEndPoints> getTEPsForDpn( BigInteger srcDpn, List<DPNTEPsInfo> dpnList) {
+    public static List<TunnelEndPoints> getTEPsForDpn(BigInteger srcDpn, List<DPNTEPsInfo> dpnList) {
         for (DPNTEPsInfo dpn : dpnList) {
-            ifdpn.getDPNID().equals(srcDpn)) {
+            if (dpn.getDPNID().equals(srcDpn)) {
                 return dpn.getTunnelEndPoints() ;
             }
         }
         return null ;
     }
+
     public static TunnelList getAllInternalTunnels(DataBroker broker) {
-        InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier = InstanceIdentifier.builder(TunnelList.class).build();
+        InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier =
+                InstanceIdentifier.builder(TunnelList.class).build();
         return read(LogicalDatastoreType.CONFIGURATION, tunnelListInstanceIdentifier, broker).orNull();
     }
+
+    public static List<InternalTunnel> getAllInternalTunnels(DataBroker dataBroker,
+                                                             LogicalDatastoreType datastoreType) {
+        List<InternalTunnel> result = null;
+        InstanceIdentifier<TunnelList> iid = InstanceIdentifier.builder(TunnelList.class).build();
+        Optional<TunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
+        if (tunnelList.isPresent()) {
+            result = tunnelList.get().getInternalTunnel();
+        }
+        if (result == null) {
+            result = Collections.emptyList();
+        }
+        return result;
+    }
+
     public static InternalTunnel getInternalTunnel(String interfaceName, DataBroker broker) {
         InternalTunnel internalTunnel = null;
         internalTunnel = itmCache.getInternalTunnel(interfaceName);
@@ -966,6 +1115,7 @@ public class ItmUtils {
         }
         return internalTunnel;
     }
+
     public static ExternalTunnel getExternalTunnel(String interfaceName, DataBroker broker) {
         ExternalTunnel externalTunnel = null;
         externalTunnel = itmCache.getExternalTunnel(interfaceName);
@@ -975,6 +1125,7 @@ public class ItmUtils {
         }
         return externalTunnel;
     }
+
     public static List<ExternalTunnel> getAllExternalTunnels(DataBroker broker) {
         List<ExternalTunnel> result = null;
         InstanceIdentifier<ExternalTunnelList> id = InstanceIdentifier.builder(ExternalTunnelList.class).build();
@@ -987,14 +1138,31 @@ public class ItmUtils {
         }
         return result;
     }
-    public static String convertTunnelTypetoString(Class<? extends TunnelTypeBase> tunType ) {
+
+    public static List<ExternalTunnel> getAllExternalTunnels(DataBroker dataBroker,
+                                                             LogicalDatastoreType datastoreType) {
+        List<ExternalTunnel> result = null;
+        InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
+        Optional<ExternalTunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
+        if (tunnelList.isPresent()) {
+            result = tunnelList.get().getExternalTunnel();
+        }
+        if (result == null) {
+            result = Collections.emptyList();
+        }
+        return result;
+    }
+
+    public static String convertTunnelTypetoString(Class<? extends TunnelTypeBase> tunType) {
         String tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
-        iftunType.equals(TunnelTypeVxlan.class)) {
+        if (tunType.equals(TunnelTypeVxlan.class)) {
             tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
-        } else if( tunType.equals(TunnelTypeGre.class) ) {
+        } else if (tunType.equals(TunnelTypeGre.class)) {
             tunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
-        } else if (tunnelType.equals(TunnelTypeMplsOverGre.class)) {
+        } else if (tunType.equals(TunnelTypeMplsOverGre.class)) {
             tunnelType = ITMConstants.TUNNEL_TYPE_MPLSoGRE;
+        } else if (tunType.equals(TunnelTypeLogicalGroup.class)) {
+            tunnelType = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
         }
         return tunnelType ;
     }
@@ -1004,9 +1172,10 @@ public class ItmUtils {
         return ifType != null && ifType.isAssignableFrom(Tunnel.class);
     }
 
-    public static StateTunnelListKey getTunnelStateKey( org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface iface) {
+    public static StateTunnelListKey getTunnelStateKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
+                                                               .interfaces.rev140508.interfaces.state.Interface iface) {
         StateTunnelListKey key = null;
-        if(isItmIfType(iface.getType())) {
+        if (isItmIfType(iface.getType())) {
             key = new StateTunnelListKey(iface.getName());
         }
         return key;
@@ -1023,32 +1192,6 @@ public class ItmUtils {
         }
     }
 
-    public static List<ExternalTunnel> getAllExternalTunnels(DataBroker dataBroker, LogicalDatastoreType datastoreType) {
-        List<ExternalTunnel> result = null;
-        InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
-        Optional<ExternalTunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
-        if (tunnelList.isPresent()) {
-            result = tunnelList.get().getExternalTunnel();
-        }
-        if (result == null) {
-            result = Collections.emptyList();
-        }
-        return result;
-    }
-
-    public static List<InternalTunnel> getAllInternalTunnels(DataBroker dataBroker, LogicalDatastoreType datastoreType) {
-        List<InternalTunnel> result = null;
-        InstanceIdentifier<TunnelList> iid = InstanceIdentifier.builder(TunnelList.class).build();
-        Optional<TunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
-        if (tunnelList.isPresent()) {
-            result = tunnelList.get().getInternalTunnel();
-        }
-        if (result == null) {
-            result = Collections.emptyList();
-        }
-        return result;
-    }
-
     public static Interface getInterface(
             String name, IInterfaceManager ifaceManager) {
         Interface result = itmCache.getInterface(name);
@@ -1060,12 +1203,15 @@ public class ItmUtils {
         }
         return result;
     }
+
     public static StateTunnelList getTunnelState(DataBroker dataBroker, String ifaceName,
-                                                 InstanceIdentifier<StateTunnelList> stListId){
-        StateTunnelList tunnelState = (StateTunnelList)DataStoreCache.get(ITMConstants.TUNNEL_STATE_CACHE_NAME, ifaceName);
-        if(tunnelState == null) {
-            Optional<StateTunnelList> tunnelsState = ItmUtils.read(LogicalDatastoreType.OPERATIONAL, stListId, dataBroker);
-            if(tunnelsState.isPresent()){
+                                                 InstanceIdentifier<StateTunnelList> stListId) {
+        StateTunnelList tunnelState = (StateTunnelList)DataStoreCache
+                .get(ITMConstants.TUNNEL_STATE_CACHE_NAME, ifaceName);
+        if (tunnelState == null) {
+            Optional<StateTunnelList> tunnelsState = ItmUtils
+                    .read(LogicalDatastoreType.OPERATIONAL, stListId, dataBroker);
+            if (tunnelsState.isPresent()) {
                 return tunnelState;
             }
         }
@@ -1074,37 +1220,43 @@ public class ItmUtils {
 
     public static Class<? extends TunnelMonitoringTypeBase> readMonitoringProtocolFromCache(DataBroker dataBroker) {
         InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.create(TunnelMonitorParams.class);
-        TunnelMonitorParams tunnelMonitorParams = (TunnelMonitorParams) DataStoreCache.get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"MonitorParams",dataBroker,true);
-        if(tunnelMonitorParams!=null) {
+        TunnelMonitorParams tunnelMonitorParams = (TunnelMonitorParams) DataStoreCache
+                .get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"MonitorParams",dataBroker,true);
+        if (tunnelMonitorParams != null) {
             return tunnelMonitorParams.getMonitorProtocol();
         }
         return null;
     }
 
     public static Class<? extends TunnelMonitoringTypeBase> determineMonitorProtocol(DataBroker dataBroker) {
-        Class<? extends TunnelMonitoringTypeBase> monitoringProtocol = ItmUtils.readMonitoringProtocolFromCache(dataBroker);
+        Class<? extends TunnelMonitoringTypeBase> monitoringProtocol =
+                ItmUtils.readMonitoringProtocolFromCache(dataBroker);
         LOG.debug("determineMonitorProtocol: monitorProtocol from DS = {}", monitoringProtocol);
-        if(monitoringProtocol==null) {
+        if (monitoringProtocol == null) {
             monitoringProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
         }
         LOG.debug("determineMonitorProtocol: monitorProtocol = {}", monitoringProtocol);
         Boolean monitorState = ItmUtils.readMonitoringStateFromCache(dataBroker);
-        if(monitorState==null) {
+        if (monitorState == null) {
             monitorState = true;
         }
         LOG.debug("determineMonitorProtocol: monitorState = {}", monitorState);
         InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.builder(TunnelMonitorParams.class).build();
-        TunnelMonitorParams protocolBuilder = new TunnelMonitorParamsBuilder().setEnabled(monitorState).setMonitorProtocol(monitoringProtocol).build();
-        ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, protocolBuilder, dataBroker, ItmUtils.DEFAULT_CALLBACK);
+        TunnelMonitorParams protocolBuilder = new TunnelMonitorParamsBuilder().setEnabled(monitorState)
+                .setMonitorProtocol(monitoringProtocol).build();
+        ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, protocolBuilder, dataBroker,
+                ItmUtils.DEFAULT_CALLBACK);
         return monitoringProtocol;
     }
 
-    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()){
+    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){
+            if (containerList != null) {
                 return containerList.getDcGatewayIp();
             }
         }
@@ -1117,12 +1269,12 @@ public class ItmUtils {
 
     public static <T> List<T> getIntersection(List<T> list1, List<T> list2) {
         List<T> list = new ArrayList<>();
-        for (T t : list1) {
-            if(list2.contains(t)) {
-                list.add(t);
+        for (T iter : list1) {
+            if (list2.contains(iter)) {
+                list.add(iter);
             }
         }
-        LOG.debug( " getIntersection - L1 {}, L2 - {}, Intersection - {}", list1, list2, list);
+        LOG.debug(" getIntersection - L1 {}, L2 - {}, Intersection - {}", list1, list2, list);
         return list;
     }
 
@@ -1141,22 +1293,22 @@ public class ItmUtils {
      *
      * @param tzName transport zone name
      * @param dataBroker data broker handle to perform operations on datastore
+     * @return the TransportZone object in Config DS
      */
     // FIXME: Better is to implement cache to avoid datastore read.
     public static TransportZone getTransportZoneFromConfigDS(String tzName, DataBroker dataBroker) {
         InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
-            .child(TransportZone.class, new TransportZoneKey(tzName)).build();
-        Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath,
+                .child(TransportZone.class, new TransportZoneKey(tzName)).build();
+        Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath,
             dataBroker);
-        if (tZoneOptional.isPresent()) {
-            return tZoneOptional.get();
+        if (transportZoneOptional.isPresent()) {
+            return transportZoneOptional.get();
         }
         return null;
     }
 
     /**
-     * Gets the transport zone in TepsNotHosted list in the Configuration Datastore
-     * based on transport zone name
+     * Gets the transport zone in TepsNotHosted list in the Configuration Datastore, based on transport zone name.
      *
      * @param unknownTz transport zone name
      *
@@ -1168,7 +1320,7 @@ public class ItmUtils {
         String unknownTz, DataBroker dataBroker) {
         InstanceIdentifier<TepsNotHostedInTransportZone> unknownTzPath =
             InstanceIdentifier.builder(TransportZones.class)
-                .child(TepsNotHostedInTransportZone.class,
+                    .child(TepsNotHostedInTransportZone.class,
                     new TepsNotHostedInTransportZoneKey(unknownTz)).build();
         Optional<TepsNotHostedInTransportZone> unknownTzOptional =
             ItmUtils.read(LogicalDatastoreType.CONFIGURATION, unknownTzPath, dataBroker);
@@ -1179,8 +1331,7 @@ public class ItmUtils {
     }
 
     /**
-     * Gets the bridge datapath ID from Network topology Node's OvsdbBridgeAugmentation
-     * in the Operational DS.
+     * Gets the bridge datapath ID from Network topology Node's OvsdbBridgeAugmentation, in the Operational DS.
      *
      * @param node Network Topology Node
      *
@@ -1263,7 +1414,7 @@ public class ItmUtils {
     }
 
     /**
-     * Returns the dummy subnet (255.255.255.255/32) as IpPrefix object
+     * Returns the dummy subnet (255.255.255.255/32) as IpPrefix object.
      *
      * @return the dummy subnet (255.255.255.255/32) in IpPrefix object
      */
@@ -1279,14 +1430,18 @@ public class ItmUtils {
      */
     public static void deleteTransportZoneFromConfigDS(String tzName, DataBroker dataBroker) {
         // check whether transport-zone exists in config DS.
-        TransportZone tZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
-        if (tZoneFromConfigDS != null) {
+        TransportZone transportZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
+        if (transportZoneFromConfigDS != null) {
             // it exists, delete default-TZ now
             InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class)
-                .child(TransportZone.class,
+                    .child(TransportZone.class,
                     new TransportZoneKey(tzName)).build();
             LOG.debug("Removing {} transport-zone from config DS.", tzName);
-            ItmUtils.asyncDelete(LogicalDatastoreType.CONFIGURATION, path, dataBroker, ItmUtils.DEFAULT_CALLBACK);
+            try {
+                SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
+            } catch (TransactionCommitFailedException e) {
+                LOG.error("deleteTransportZoneFromConfigDS failed. {} could not be deleted.", tzName, e);
+            }
         }
     }
 
@@ -1303,8 +1458,8 @@ public class ItmUtils {
         // take VXLAN tunnel type by default
         if (tunnelType == null || tunnelType.isEmpty()) {
             return TUNNEL_TYPE_MAP.get(ITMConstants.TUNNEL_TYPE_VXLAN);
-        } else if (!tunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN) &&
-            !tunnelType.equals(ITMConstants.TUNNEL_TYPE_GRE)) {
+        } else if (!tunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN)
+                && !tunnelType.equals(ITMConstants.TUNNEL_TYPE_GRE)) {
             // if tunnel type is some incorrect value, then
             // take VXLAN tunnel type by default
             return TUNNEL_TYPE_MAP.get(ITMConstants.TUNNEL_TYPE_VXLAN);
@@ -1314,35 +1469,39 @@ public class ItmUtils {
         return TUNNEL_TYPE_MAP.get(tunnelType);
     }
 
-    public static List<TzMembership> removeTransportZoneMembership(TunnelEndPoints endPts, List<TzMembership> zones){
-        LOG.trace( " RemoveTransportZoneMembership TEPs {}, Membership to be removed {} ", endPts, zones);
+    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()) ;
-        forTzMembership membership : zones) {
+        for (TzMembership membership : zones) {
             existingTzList.remove(new TzMembershipBuilder().setZoneName(membership.getZoneName()).build());
         }
-        LOG.debug( "Modified Membership List {}", existingTzList);
+        LOG.debug("Modified Membership List {}", existingTzList);
         return existingTzList;
     }
 
-    public static List<TzMembership> getOriginalTzMembership(TunnelEndPoints srcTep, BigInteger dpnId, List<DPNTEPsInfo> meshedDpnList) {
-        LOG.trace( "Original Membership for source DPN {}, source TEP {}", dpnId, srcTep) ;
+    public static List<TzMembership> getOriginalTzMembership(TunnelEndPoints srcTep, BigInteger dpnId,
+                                                             List<DPNTEPsInfo> meshedDpnList) {
+        LOG.trace("Original Membership for source DPN {}, source TEP {}", dpnId, srcTep);
         for (DPNTEPsInfo dstDpn : meshedDpnList) {
-            if( dpnId.equals(dstDpn.getDPNID()) ){
+            if (dpnId.equals(dstDpn.getDPNID())) {
                 List<TunnelEndPoints> endPts = dstDpn.getTunnelEndPoints();
-                forTunnelEndPoints tep : endPts) {
-                    if( tep.getIpAddress().equals( srcTep.getIpAddress())){
-                        LOG.debug( "Original Membership size " + tep.getTzMembership().size()) ;
-                        return tep.getTzMembership() ;
+                for (TunnelEndPoints tep : endPts) {
+                    if (tep.getIpAddress().equals(srcTep.getIpAddress())) {
+                        LOG.debug("Original Membership size " + tep.getTzMembership().size()) ;
+                        return tep.getTzMembership();
                     }
                 }
             }
         }
         return null ;
     }
-    public static StateTunnelList buildStateTunnelList(StateTunnelListKey tlKey, String name, boolean state, TunnelOperStatus tunOpStatus, IInterfaceManager  ifaceManager, DataBroker broker) {
+
+    public static StateTunnelList buildStateTunnelList(StateTunnelListKey tlKey, String name, boolean state,
+                                                       TunnelOperStatus tunOpStatus, IInterfaceManager  ifaceManager,
+                                                       DataBroker broker) {
         StateTunnelListBuilder stlBuilder = new StateTunnelListBuilder();
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = ItmUtils
-                .getInterface(name, ifaceManager);
+        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
+                ItmUtils.getInterface(name, ifaceManager);
         IfTunnel ifTunnel = iface.getAugmentation(IfTunnel.class);
         ParentRefs parentRefs = iface.getAugmentation(ParentRefs.class);
         if (ifTunnel == null && parentRefs == null) {
@@ -1380,6 +1539,7 @@ public class ItmUtils {
                 .setDstInfo(dstInfoBuilder.build()).setSrcInfo(srcInfoBuilder.build());
         return stlBuilder.build();
     }
+
     public static Class<? extends TepTypeBase> getDeviceType(String device) {
         if (device.startsWith("hwvtep")) {
             return TepTypeHwvtep.class;
@@ -1394,4 +1554,47 @@ public class ItmUtils {
         return InstanceIdentifier.builder(TunnelsState.class)
                 .child(StateTunnelList.class, tlKey).build();
     }
+
+    public static  Optional<InternalTunnel> getInternalTunnelFromDS(BigInteger srcDpn, BigInteger destDpn,
+                                                                    Class<? extends TunnelTypeBase> type,
+                                                                    DataBroker dataBroker) {
+        InstanceIdentifier<InternalTunnel> pathLogicTunnel = InstanceIdentifier.create(TunnelList.class)
+                .child(InternalTunnel.class,
+                        new InternalTunnelKey(destDpn, srcDpn, type));
+        //TODO: need to be replaced by cached copy
+        return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, pathLogicTunnel, dataBroker);
+    }
+
+    public static boolean isTunnelAggregationUsed(Class<? extends TunnelTypeBase> tunType) {
+        return (ItmTunnelAggregationHelper.isTunnelAggregationEnabled()
+                && (tunType.isAssignableFrom(TunnelTypeVxlan.class)
+                        || tunType.isAssignableFrom(TunnelTypeLogicalGroup.class)));
+    }
+
+    public static List<TunnelOptions> buildTunnelOptions(TunnelEndPoints tep, ItmConfig itmConfig) {
+        List<TunnelOptions> tunOptions = new ArrayList<>();
+
+        String tos = tep.getOptionTunnelTos();
+        if (tos == null) {
+            tos = itmConfig.getDefaultTunnelTos();
+        }
+        /* populate tos option only if its not default value of 0 */
+        if (tos != null && !tos.equals("0")) {
+            TunnelOptionsBuilder optionsBuilder = new TunnelOptionsBuilder();
+            optionsBuilder.setKey(new TunnelOptionsKey("tos"));
+            optionsBuilder.setTunnelOption("tos");
+            optionsBuilder.setValue(tos);
+            tunOptions.add(optionsBuilder.build());
+        }
+
+        if (tep.getTunnelType() == TunnelTypeVxlan.class && itmConfig.isGpeExtensionEnabled()) {
+            TunnelOptionsBuilder optionsBuilder = new TunnelOptionsBuilder();
+            optionsBuilder.setKey(new TunnelOptionsKey("exts"));
+            optionsBuilder.setTunnelOption("exts");
+            optionsBuilder.setValue("gpe");
+            tunOptions.add(optionsBuilder.build());
+        }
+
+        return tunOptions.isEmpty() ? null : tunOptions;
+    }
 }