migrate TepShowState from deprecated OsgiCommandSupport to Action
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / cli / TepCommandHelper.java
index 25f2f5f905d09360f3106c4bf6f19bed80247474..e0f482cbe14383bc60b235e3bc5cc256f48b05aa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -11,9 +11,13 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicInteger;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
@@ -23,19 +27,25 @@ import org.apache.commons.net.util.SubnetUtils;
 import org.apache.felix.service.command.CommandSession;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
-import org.opendaylight.genius.mdsalutil.MDSALDataStoreUtils;
 import org.opendaylight.genius.utils.cache.DataStoreCache;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 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;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder;
 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.TunnelMonitoringTypeLldp;
 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.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;
@@ -59,25 +69,27 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig;
-
 @Singleton
+@SuppressWarnings("checkstyle:RegexpSingleLineJava")
 public class TepCommandHelper {
 
     private static final Logger LOG = LoggerFactory.getLogger(TepCommandHelper.class);
+
+    private static final AtomicInteger CHECK = new AtomicInteger();
+
     private final DataBroker dataBroker;
+    private final ManagedNewTransactionRunner txRunner;
     private final ItmConfig itmConfig;
-    static int check = 0;
-    static short flag = 0;
+
     /*
      * boolean flag add_or_delete --- can be set to true if the last called tep
      * command is Tep-add else set to false when Tep-delete is called
      * tepCommandHelper object is created only once in session initiated
      */
-    final Map<String, Map<SubnetObject, List<Vteps>>> tZones = new HashMap<>();
+    private final Map<String, Map<SubnetObject, List<Vteps>>> transportZonesHashMap = new HashMap<>();
     private List<Subnets> subnetList = new ArrayList<>();
-    private List<TransportZone> tZoneList = new ArrayList<>();
-    private List<Vteps> vtepDelCommitList = new ArrayList<>();
+    private List<TransportZone> transportZoneArrayList = new ArrayList<>();
+    private final List<Vteps> vtepDelCommitList = new ArrayList<>();
 
     // private List<InstanceIdentifier<? extends DataObject>> vtepPaths = new
     // ArrayList<>();
@@ -85,11 +97,12 @@ public class TepCommandHelper {
     @Inject
     public TepCommandHelper(final DataBroker dataBroker, final ItmConfig itmConfig) {
         this.dataBroker = dataBroker;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         this.itmConfig = itmConfig;
     }
 
     @PostConstruct
-    public void start() throws Exception {
+    public void start() {
         boolean defTzEnabled = itmConfig.isDefTzEnabled();
         if (defTzEnabled) {
             String tunnelType = itmConfig.getDefTzTunnelType();
@@ -111,40 +124,44 @@ public class TepCommandHelper {
         LOG.info("TepCommandHelper Closed");
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void createLocalCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress,
-                                 String subnetMask, String gatewayIp, String transportZone, CommandSession session) throws TepException{
+                                 String subnetMask, String gatewayIp, String transportZone,
+                                 CommandSession session) throws TepException {
 
-        check++;
+        CHECK.incrementAndGet();
         IpAddress ipAddressObj = null;
         IpAddress gatewayIpObj = null;
         IpPrefix subnetMaskObj = null;
-        VtepsKey vtepkey = new VtepsKey(dpnId, portName);
+        final VtepsKey vtepkey = new VtepsKey(dpnId, portName);
         try {
-            ipAddressObj = new IpAddress(ipAddress.toCharArray());
-            gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
-            if (gatewayIp != null) {
-                gatewayIpObj = new IpAddress(gatewayIp.toCharArray());
+            ipAddressObj = IpAddressBuilder.getDefaultInstance(ipAddress);
+            gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
+            if (gatewayIp != null && !gatewayIp.isEmpty()
+                    && !"null".equals(gatewayIp) || "0.0.0.0".equals(gatewayIp)) {
+                gatewayIpObj = IpAddressBuilder.getDefaultInstance(gatewayIp);
             } else {
                 LOG.debug("gateway is null");
+                gatewayIp = null;
             }
-        } catch (Exception e) {
-            handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
+        } catch (RuntimeException e) {
+            handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255");
             return;
         }
         try {
-            subnetMaskObj = new IpPrefix(subnetMask.toCharArray());
+            subnetMaskObj = IpPrefixBuilder.getDefaultInstance(subnetMask);
         } catch (Exception e) {
-            handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
+            handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32");
             return;
         }
 
         if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
-            handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
+            handleError("IpAddress and gateWayIp should belong to the subnet provided");
             return;
         }
 
         if (checkTepPerTzPerDpn(transportZone, dpnId)) {
-            if(session  != null) {
+            if (session != null) {
                 session.getConsole().println("Only one end point per transport Zone per Dpn is allowed");
             }
             return;
@@ -155,8 +172,8 @@ public class TepCommandHelper {
 
         SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
         SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
-        if (tZones.containsKey(transportZone)) {
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(transportZone);
+        if (transportZonesHashMap.containsKey(transportZone)) {
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = transportZonesHashMap.get(transportZone);
             if (subVtepMapTemp.containsKey(subObCli)) { // if Subnet exists
                 List<Vteps> vtepListTemp = subVtepMapTemp.get(subObCli);
                 if (vtepListTemp.contains(vtepCli)) {
@@ -166,8 +183,9 @@ public class TepCommandHelper {
                 }
             } else { // subnet doesnt exist
                 if (checkExistingSubnet(subVtepMapTemp, subObCli)) {
-                    if(session != null) {
-                        session.getConsole().println("subnet with subnet mask " + subObCli.get_key() + "already exists");
+                    if (session != null) {
+                        session.getConsole().println("subnet with subnet mask "
+                                + subObCli.get_key() + "already exists");
                     }
                     return;
                 }
@@ -180,13 +198,13 @@ public class TepCommandHelper {
             vtepListTemp.add(vtepCli);
             Map<SubnetObject, List<Vteps>> subVtepMapTemp = new HashMap<>();
             subVtepMapTemp.put(subObCli, vtepListTemp);
-            tZones.put(transportZone, subVtepMapTemp);
+            transportZonesHashMap.put(transportZone, subVtepMapTemp);
         }
     }
 
     private boolean validateIPs(String ipAddress, String subnetMask, String gatewayIp) {
         SubnetUtils utils = new SubnetUtils(subnetMask);
-        if ((utils.getInfo().isInRange(ipAddress)) && ((gatewayIp == null) || (utils.getInfo().isInRange(gatewayIp)))) {
+        if (utils.getInfo().isInRange(ipAddress) && (gatewayIp == null || utils.getInfo().isInRange(gatewayIp))) {
             return true;
         } else {
             LOG.trace("InValid IP");
@@ -203,25 +221,25 @@ public class TepCommandHelper {
      *            the transport zone
      */
     public void validateForDuplicates(Vteps inputVtep, String transportZone) {
-        Map<String, TransportZone> tZoneMap = getAllTransportZonesAsMap();
+        Map<String, TransportZone> allTransportZonesAsMap = getAllTransportZonesAsMap();
 
-        boolean isConfiguredTepGreType = isGreTunnelType(transportZone, tZoneMap);
+        boolean isConfiguredTepGreType = isGreTunnelType(transportZone, allTransportZonesAsMap);
         // Checking for duplicates in local cache
-        for (String tZ : tZones.keySet()) {
-            boolean isGreType = isGreTunnelType(tZ, tZoneMap);
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tZ);
-            for (SubnetObject subOb : subVtepMapTemp.keySet()) {
-                List<Vteps> vtepList = subVtepMapTemp.get(subOb);
+        for (Entry<String, Map<SubnetObject, List<Vteps>>> entry : transportZonesHashMap.entrySet()) {
+            String tz = entry.getKey();
+            boolean isGreType = isGreTunnelType(tz, allTransportZonesAsMap);
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = entry.getValue();
+            for (List<Vteps> vtepList : subVtepMapTemp.values()) {
                 validateForDuplicateAndSingleGreTep(inputVtep, isConfiguredTepGreType, isGreType, vtepList);
             }
         }
         // Checking for duplicates in config DS
-        for (TransportZone tZ : tZoneMap.values()) {
+        for (TransportZone tz : allTransportZonesAsMap.values()) {
             boolean isGreType = false;
-            if (tZ.getTunnelType().equals(TunnelTypeGre.class)) {
+            if (tz.getTunnelType().equals(TunnelTypeGre.class)) {
                 isGreType = true;
             }
-            for (Subnets sub : ItmUtils.emptyIfNull(tZ.getSubnets())) {
+            for (Subnets sub : ItmUtils.emptyIfNull(tz.getSubnets())) {
                 List<Vteps> vtepList = sub.getVteps();
                 validateForDuplicateAndSingleGreTep(inputVtep, isConfiguredTepGreType, isGreType, vtepList);
             }
@@ -229,7 +247,7 @@ public class TepCommandHelper {
     }
 
     private void validateForDuplicateAndSingleGreTep(Vteps inputVtep, boolean isConfiguredTepGreType, boolean isGreType,
-                                                     List<Vteps> vtepList) {
+            List<Vteps> vtepList) {
         if (ItmUtils.isEmpty(vtepList)) {
             return;
         }
@@ -240,8 +258,8 @@ public class TepCommandHelper {
         if (isConfiguredTepGreType && isGreType) {
             for (Vteps vtep : vtepList) {
                 if (vtep.getDpnId().equals(dpnId)) {
-                    String errMsg = "DPN [" + dpnId +
-                            "] already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.";
+                    String errMsg = "DPN [" + dpnId + "] already configured with GRE TEP."
+                            + " Mutiple GRE TEP's on a single DPN are not allowed.";
                     Preconditions.checkArgument(false, errMsg);
                 }
             }
@@ -254,45 +272,45 @@ public class TepCommandHelper {
      * @return all transport zones as map
      */
     private Map<String, TransportZone> getAllTransportZonesAsMap() {
-        TransportZones tZones = getAllTransportZones();
-        Map<String, TransportZone> tZoneMap = new HashMap<>();
-        if( null != tZones) {
-            for (TransportZone tzone : ItmUtils.emptyIfNull(tZones.getTransportZone())) {
-                tZoneMap.put(tzone.getZoneName(), tzone);
+        TransportZones allTransportZones = getAllTransportZones();
+        Map<String, TransportZone> transportZoneMap = new HashMap<>();
+        if (null != allTransportZones) {
+            for (TransportZone tzone : ItmUtils.emptyIfNull(allTransportZones.getTransportZone())) {
+                transportZoneMap.put(tzone.getZoneName(), tzone);
             }
         }
-        return tZoneMap;
+        return transportZoneMap;
     }
 
     /**
      * Checks if is gre tunnel type.
      *
-     * @param tZoneName
+     * @param transportZoneName
      *            the zone name
-     * @param tZoneMap
+     * @param trsnsportZoneMap
      *            the zone map
      * @return true, if is gre tunnel type
      */
-    private boolean isGreTunnelType(String tZoneName, Map<String, TransportZone> tZoneMap) {
-        TransportZone tzone = tZoneMap.get(tZoneName);
+    private boolean isGreTunnelType(String transportZoneName, Map<String, TransportZone> trsnsportZoneMap) {
+        TransportZone tzone = trsnsportZoneMap.get(transportZoneName);
         /*
-        if (tzone != null && StringUtils.equalsIgnoreCase(ITMConstants.TUNNEL_TYPE_GRE, tzone.getTunnelType())) {
-            return true;
-        }
-        */
-        return (tzone != null) && (tzone.getTunnelType()).equals(TunnelTypeGre.class);
+         * if (tzone != null &&
+         * StringUtils.equalsIgnoreCase(ITMConstants.TUNNEL_TYPE_GRE,
+         * tzone.getTunnelType())) { return true; }
+         */
+        return tzone != null && tzone.getTunnelType().equals(TunnelTypeGre.class);
     }
 
     /**
      * Gets the transport zone.
      *
-     * @param tzone
+     * @param transportZoneName
      *            the tzone
      * @return the transport zone
      */
-    public TransportZone getTransportZone(String tzone) {
+    public TransportZone getTransportZone(String transportZoneName) {
         InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
-                .child(TransportZone.class, new TransportZoneKey(tzone)).build();
+                .child(TransportZone.class, new TransportZoneKey(transportZoneName)).build();
         return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker).orNull();
     }
 
@@ -309,10 +327,12 @@ public class TepCommandHelper {
     public boolean checkExistingSubnet(Map<SubnetObject, List<Vteps>> subVtepMapTemp, SubnetObject subObCli) {
         for (SubnetObject subOb : subVtepMapTemp.keySet()) {
             if (subOb.get_key().equals(subObCli.get_key())) {
-                if (!(subOb.get_vlanId().equals(subObCli.get_vlanId())))
+                if (!subOb.get_vlanId().equals(subObCli.get_vlanId())) {
                     return true;
-                if (!(subOb.get_gatewayIp().equals(subObCli.get_gatewayIp())))
+                }
+                if (!subOb.get_gatewayIp().equals(subObCli.get_gatewayIp())) {
                     return true;
+                }
             }
         }
         return false;
@@ -320,13 +340,14 @@ public class TepCommandHelper {
 
     public boolean checkTepPerTzPerDpn(String tzone, BigInteger dpnId) {
         // check in local cache
-        if (tZones.containsKey(tzone)) {
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tzone);
-            for (SubnetObject subOb : subVtepMapTemp.keySet()) {
-                List<Vteps> vtepList = subVtepMapTemp.get(subOb);
-                for (Vteps vtep : vtepList)
-                    if (vtep.getDpnId().equals(dpnId))
+        if (transportZonesHashMap.containsKey(tzone)) {
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = transportZonesHashMap.get(tzone);
+            for (List<Vteps> vtepList : subVtepMapTemp.values()) {
+                for (Vteps vtep : vtepList) {
+                    if (vtep.getDpnId().equals(dpnId)) {
                         return true;
+                    }
+                }
             }
         }
 
@@ -334,15 +355,17 @@ public class TepCommandHelper {
         InstanceIdentifier<TransportZone> tzonePath =
                 InstanceIdentifier.builder(TransportZones.class)
                         .child(TransportZone.class, new TransportZoneKey(tzone)).build();
-        Optional<TransportZone> tZoneOptional =
+        Optional<TransportZone> transportZoneOptional =
                 ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
-        if (tZoneOptional.isPresent()) {
-            TransportZone tz = tZoneOptional.get();
-            if (tz.getSubnets() == null || tz.getSubnets().isEmpty())
+        if (transportZoneOptional.isPresent()) {
+            TransportZone tz = transportZoneOptional.get();
+            if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
                 return false;
+            }
             for (Subnets sub : tz.getSubnets()) {
-                if (sub.getVteps() == null || sub.getVteps().isEmpty())
+                if (sub.getVteps() == null || sub.getVteps().isEmpty()) {
                     continue;
+                }
                 for (Vteps vtep : sub.getVteps()) {
                     if (vtep.getDpnId().equals(dpnId)) {
                         return true;
@@ -353,221 +376,260 @@ public class TepCommandHelper {
         return false;
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void buildTeps() {
-        TransportZones tZonesBuilt = null;
-        TransportZone tZone = null;
+        TransportZones transportZonesBuilt = null;
+        TransportZone transportZone = null;
         try {
-            LOG.debug("no of teps added" + check);
-            if (tZones != null || !tZones.isEmpty()) {
-                tZoneList = new ArrayList<>();
-                for (String tZ : tZones.keySet()) {
-                    LOG.debug("tZones" + tZ);
+            LOG.debug("no of teps added {}", CHECK);
+            if (transportZonesHashMap != null && !transportZonesHashMap.isEmpty()) {
+                transportZoneArrayList = new ArrayList<>();
+                for (Entry<String, Map<SubnetObject, List<Vteps>>> mapEntry : transportZonesHashMap.entrySet()) {
+                    String tz = mapEntry.getKey();
+                    LOG.debug("transportZonesHashMap {}", tz);
                     subnetList = new ArrayList<>();
-                    Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tZ);
-                    for (SubnetObject subOb : subVtepMapTemp.keySet()) {
-                        LOG.debug("subnets" + subOb.get_prefix());
-                        List<Vteps> vtepList = subVtepMapTemp.get(subOb);
-                        Subnets subnet =
-                                new SubnetsBuilder().setGatewayIp(subOb.get_gatewayIp())
-                                        .setKey(subOb.get_key()).setPrefix(subOb.get_prefix())
-                                        .setVlanId(subOb.get_vlanId()).setVteps(vtepList).build();
+                    Map<SubnetObject, List<Vteps>> subVtepMapTemp = mapEntry.getValue();
+                    for (Entry<SubnetObject, List<Vteps>> entry : subVtepMapTemp.entrySet()) {
+                        SubnetObject subOb = entry.getKey();
+                        LOG.debug("subnets {}", subOb.get_prefix());
+                        List<Vteps> vtepList = entry.getValue();
+                        Subnets subnet = new SubnetsBuilder().setGatewayIp(subOb.get_gatewayIp())
+                                .setKey(subOb.get_key()).setPrefix(subOb.get_prefix()).setVlanId(subOb.get_vlanId())
+                                .setVteps(vtepList).build();
                         subnetList.add(subnet);
-                        LOG.debug("vteps" + vtepList);
+                        LOG.debug("vteps {}", vtepList);
                     }
-                    InstanceIdentifier<TransportZone> tZonepath =
+                    InstanceIdentifier<TransportZone> transportZonePath =
                             InstanceIdentifier.builder(TransportZones.class)
-                                    .child(TransportZone.class, new TransportZoneKey(tZ)).build();
-                    Optional<TransportZone> tZoneOptional =
-                            ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tZonepath, dataBroker);
+                                    .child(TransportZone.class, new TransportZoneKey(tz)).build();
+                    Optional<TransportZone> transportZoneOptional =
+                            ItmUtils.read(LogicalDatastoreType.CONFIGURATION, transportZonePath, dataBroker);
                     LOG.debug("read container from DS");
-                    if (tZoneOptional.isPresent()) {
-                        TransportZone tzoneFromDs = tZoneOptional.get();
-                        LOG.debug("read tzone container" + tzoneFromDs.toString());
+                    if (transportZoneOptional.isPresent()) {
+                        TransportZone tzoneFromDs = transportZoneOptional.get();
+                        LOG.debug("read tzone container {}", tzoneFromDs);
                         if (tzoneFromDs.getTunnelType() == null
-                                || (tzoneFromDs.getTunnelType()).equals(TunnelTypeVxlan.class)) {
-                            tZone =
-                                    new TransportZoneBuilder().setKey(new TransportZoneKey(tZ))
+                                || tzoneFromDs.getTunnelType().equals(TunnelTypeVxlan.class)) {
+                            transportZone =
+                                    new TransportZoneBuilder().setKey(new TransportZoneKey(tz))
                                             .setTunnelType(TunnelTypeVxlan.class).setSubnets(subnetList)
-                                            .setZoneName(tZ).build();
-                        } else if ((tzoneFromDs.getTunnelType()).equals(TunnelTypeGre.class)) {
-                            tZone =
-                                    new TransportZoneBuilder().setKey(new TransportZoneKey(tZ))
+                                            .setZoneName(tz).build();
+                        } else if (tzoneFromDs.getTunnelType().equals(TunnelTypeGre.class)) {
+                            transportZone =
+                                    new TransportZoneBuilder().setKey(new TransportZoneKey(tz))
                                             .setTunnelType(TunnelTypeGre.class).setSubnets(subnetList)
-                                            .setZoneName(tZ).build();
+                                            .setZoneName(tz).build();
                         }
                     } else {
-                        tZone =
-                                new TransportZoneBuilder().setKey(new TransportZoneKey(tZ))
-                                        .setTunnelType(TunnelTypeVxlan.class).setSubnets(subnetList).setZoneName(tZ)
+                        transportZone =
+                                new TransportZoneBuilder().setKey(new TransportZoneKey(tz))
+                                        .setTunnelType(TunnelTypeVxlan.class).setSubnets(subnetList).setZoneName(tz)
                                         .build();
                     }
-                    LOG.debug("tzone object" + tZone);
-                    tZoneList.add(tZone);
+                    LOG.debug("tzone object {}", transportZone);
+                    transportZoneArrayList.add(transportZone);
                 }
-                tZonesBuilt = new TransportZonesBuilder().setTransportZone(tZoneList).build();
+                transportZonesBuilt = new TransportZonesBuilder().setTransportZone(transportZoneArrayList).build();
                 InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
-                LOG.debug("InstanceIdentifier" + path);
-                ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tZonesBuilt, dataBroker,
+                LOG.debug("InstanceIdentifier {}", path);
+                ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, transportZonesBuilt, dataBroker,
                         ItmUtils.DEFAULT_CALLBACK);
-                LOG.debug("wrote to Config DS" + tZonesBuilt);
-                tZones.clear();
-                tZoneList.clear();
+                LOG.debug("wrote to Config DS {}", transportZonesBuilt);
+                transportZonesHashMap.clear();
+                transportZoneArrayList.clear();
                 subnetList.clear();
                 LOG.debug("Everything cleared");
             } else {
                 LOG.debug("NO vteps were configured");
             }
-        } catch (Exception e) {
-            LOG.error(e.getMessage());
+        } catch (RuntimeException e) {
+            LOG.error("Error building TEPs", e);
         }
     }
 
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
     public void showTeps(boolean monitorEnabled, int monitorInterval, CommandSession session) throws TepException {
         boolean flag = false;
         InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
-        Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
-        if (tZonesOptional.isPresent()) {
-            TransportZones tZones = tZonesOptional.get();
-            if(tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty())
-            {
-                handleError("No teps configured", session);
+        Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
+                path, dataBroker);
+        if (transportZonesOptional.isPresent()) {
+            TransportZones transportZones = transportZonesOptional.get();
+            if (transportZones.getTransportZone() == null || transportZones.getTransportZone().isEmpty()) {
+                handleError("No teps configured");
                 return;
             }
             List<String> result = new ArrayList<>();
-            result.add(String.format("Tunnel Monitoring (for VXLAN tunnels): %s", (monitorEnabled ? "On" : "Off")));
+            result.add(String.format("Tunnel Monitoring (for VXLAN tunnels): %s", monitorEnabled ? "On" : "Off"));
             result.add(String.format("Tunnel Monitoring Interval (for VXLAN tunnels): %d", monitorInterval));
             result.add(System.lineSeparator());
-            result.add(String.format("%-16s  %-16s  %-16s  %-12s  %-12s %-12s %-16s %-12s", "TransportZone", "TunnelType", "SubnetMask",
-                    "GatewayIP", "VlanID", "DpnID", "IPAddress", "PortName"));
-            result.add("------------------------------------------------------------------------------------------------------------------------------");
-            for (TransportZone tZ : tZones.getTransportZone()) {
-                if (tZ.getSubnets() == null || tZ.getSubnets().isEmpty()) {
-                    LOG.error("Transport Zone " + tZ.getZoneName() + "has no subnets");
+            result.add(String.format("%-16s  %-16s  %-16s  %-12s  %-12s %-12s %-16s %-12s", "TransportZone",
+                    "TunnelType", "SubnetMask", "GatewayIP", "VlanID", "DpnID", "IPAddress", "PortName"));
+            result.add("---------------------------------------------------------------------------------------------"
+                    + "---------------------------------");
+            for (TransportZone tz : transportZones.getTransportZone()) {
+                if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
+                    LOG.error("Transport Zone {} has no subnets", tz.getZoneName());
                     continue;
                 }
-                for (Subnets sub : tZ.getSubnets()) {
+                for (Subnets sub : tz.getSubnets()) {
                     if (sub.getVteps() == null || sub.getVteps().isEmpty()) {
-                        LOG.error("Transport Zone " + tZ.getZoneName() + "subnet " + sub.getPrefix() + "has no vteps");
+                        LOG.error("Transport Zone {} subnet {} has no vteps", tz.getZoneName(), sub.getPrefix());
                         continue;
                     }
                     for (Vteps vtep : sub.getVteps()) {
                         flag = true;
                         String strTunnelType ;
-                        if( (tZ.getTunnelType()).equals(TunnelTypeGre.class) )
-                            strTunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
-                        else
-                            strTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
-                        result.add(String.format("%-16s  %-16s  %-16s  %-12s  %-12s %-12s %-16s %-12s", tZ.getZoneName(), strTunnelType, sub
-                                .getPrefix().getIpv4Prefix().getValue(), sub.getGatewayIp().getIpv4Address()
-                                .getValue(), sub.getVlanId().toString(), vtep.getDpnId().toString(), vtep
-                                .getIpAddress().getIpv4Address().getValue(), vtep.getPortname()));
+                        if (tz.getTunnelType().equals(TunnelTypeGre.class)) {
+                            strTunnelType = ITMConstants.TUNNEL_TYPE_GRE;
+                        } else {
+                            strTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
+                        }
+                        result.add(String.format("%-16s  %-16s  %-16s  %-12s  %-12s %-12s %-16s %-12s",
+                                tz.getZoneName(), strTunnelType, new String(sub.getPrefix().getValue()),
+                                new String(sub.getGatewayIp().getValue()), sub.getVlanId().toString(),
+                                vtep.getDpnId().toString(), new String(vtep.getIpAddress().getValue()),
+                                vtep.getPortname()));
                     }
                 }
             }
             if (session != null) {
                 if (flag) {
-                    for (String p : result) {
-                        session.getConsole().println(p);
+                    for (String print : result) {
+                        System.out.println(print);
                     }
                 } else {
-                    session.getConsole().println("No teps to display");
+                    System.out.println("No teps to display");
                 }
             }
-        } else if(session != null){
-            session.getConsole().println("No teps configured");
+        } else if (session != null) {
+            System.out.println("No teps configured");
         }
     }
 
-public void showCache(String cacheName) {
-
-        if( !DataStoreCache.isCacheValid(cacheName)) {
-            System.out.println( " " + cacheName + " is not a valid Cache Name ") ;
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
+    public void showCache(String cacheName) {
+        boolean dataStoreCache = DataStoreCache.isCacheValid(cacheName);
+        boolean inMemoryCache = isInMemoryCacheNameValid(cacheName);
+        if (!dataStoreCache && !inMemoryCache) {
+            System.out.println(" " + cacheName + " is not a valid Cache Name ");
             return ;
         }
-        List<Object> keys = null ;
-        keys = DataStoreCache.getKeys(cacheName);
-        if( keys != null && !keys.isEmpty()) {
-            System.out.println( "Dumping the data in cache for " + cacheName ) ;
-            for( Object key : keys ) {
-                System.out.println( " KEY:  " + key + " Value: " + DataStoreCache.get(cacheName, key) ) ;
-                System.out.println() ;
+        if (dataStoreCache) {
+            List<Object> keys = null;
+            keys = DataStoreCache.getKeys(cacheName);
+            if (keys != null && !keys.isEmpty()) {
+                System.out.println("Dumping the data in cache for " + cacheName);
+                for (Object key : keys) {
+                    System.out.println(" KEY:  " + key + " Value: " + DataStoreCache.get(cacheName, key));
+                }
+            } else {
+                System.out.println("No data in cache for " + cacheName);
+            }
+        } else if (inMemoryCache) {
+            System.out.println("Dumping the data in cache for " + cacheName);
+            Collection<String> cacheContent;
+            switch (cacheName) {
+                case ITMConstants.INTERNAL_TUNNEL_CACHE_NAME:
+                    cacheContent = ItmUtils.ITM_CACHE.getAllInternalInterfaces();
+                    break;
+                case ITMConstants.EXTERNAL_TUNNEL_CACHE_NAME:
+                    cacheContent = ItmUtils.ITM_CACHE.getAllExternalInterfaces();
+                    break;
+                default:
+                    cacheContent = Collections.emptyList();
+            }
+            System.out.println("Number of data in cache " + cacheContent.size());
+            if (!cacheContent.isEmpty()) {
+                for (String key : cacheContent) {
+                    System.out.println(key + " ");
+                }
+            } else {
+                System.out.println("No data in cache for " + cacheName);
             }
-
-        }else
-            System.out.println( "No data in cache for " + cacheName ) ;
         }
+    }
+
+    public boolean isInMemoryCacheNameValid(String name) {
+        boolean valid = false;
+        valid = name.equals(ITMConstants.INTERNAL_TUNNEL_CACHE_NAME)
+                || name.equals(ITMConstants.EXTERNAL_TUNNEL_CACHE_NAME);
+        return valid;
+    }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
-                           String gatewayIp, String transportZone,CommandSession session) throws TepException {
+            String gatewayIp, String transportZone, CommandSession session) throws TepException {
 
         IpAddress ipAddressObj = null;
         IpAddress gatewayIpObj = null;
         IpPrefix subnetMaskObj = null;
-        VtepsKey vtepkey = new VtepsKey(dpnId, portName);
+        final VtepsKey vtepkey = new VtepsKey(dpnId, portName);
         try {
-            ipAddressObj = new IpAddress(ipAddress.toCharArray());
-            gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
-            if (gatewayIp != null) {
-                gatewayIpObj = new IpAddress(gatewayIp.toCharArray());
+            ipAddressObj = IpAddressBuilder.getDefaultInstance(ipAddress);
+            gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
+            if (!"null".equals(gatewayIp) || "0.0.0.0".equals(gatewayIp) && gatewayIp != null) {
+                gatewayIpObj = IpAddressBuilder.getDefaultInstance(gatewayIp);
             } else {
                 LOG.debug("gateway is null");
+                gatewayIp = null;
             }
-        } catch (Exception e) {
-            handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
+        } catch (RuntimeException e) {
+            handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255");
             return;
         }
         try {
-            subnetMaskObj = new IpPrefix(subnetMask.toCharArray());
+            subnetMaskObj = IpPrefixBuilder.getDefaultInstance(subnetMask);
         } catch (Exception e) {
-            handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
+            handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32");
             return;
         }
 
         if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
-            handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
+            handleError("IpAddress and gateWayIp should belong to the subnet provided");
             return;
         }
         SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
         Vteps vtepCli = null;
         Subnets subCli = null;
 
-        InstanceIdentifier<Vteps> vpath =
-                InstanceIdentifier.builder(TransportZones.class)
-                        .child(TransportZone.class, new TransportZoneKey(transportZone))
-                        .child(Subnets.class, subnetsKey).child(Vteps.class, vtepkey).build();
+        InstanceIdentifier<Vteps> vpath = InstanceIdentifier.builder(TransportZones.class)
+                .child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey)
+                .child(Vteps.class, vtepkey).build();
 
-        // check if present in tzones and delete from cache
-        boolean existsInCache = isInCache(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone, session);
+    // check if present in tzones and delete from cache
+        boolean existsInCache = isInCache(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp,
+                transportZone, session);
         if (!existsInCache) {
             Optional<Vteps> vtepOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, vpath, dataBroker);
             if (vtepOptional.isPresent()) {
                 vtepCli = vtepOptional.get();
-                if(vtepCli.getIpAddress().equals(ipAddressObj)){
+                if (vtepCli.getIpAddress().equals(ipAddressObj)) {
                     InstanceIdentifier<Subnets> spath =
                             InstanceIdentifier
                                     .builder(TransportZones.class)
                                     .child(TransportZone.class, new TransportZoneKey(transportZone))
                                     .child(Subnets.class, subnetsKey).build();
-                    Optional<Subnets> subOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, spath, dataBroker);
+                    Optional<Subnets> subOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, spath,
+                            dataBroker);
                     if (subOptional.isPresent()) {
                         subCli = subOptional.get();
-                        if(subCli.getGatewayIp().equals(gatewayIpObj) && subCli.getVlanId().equals(vlanId)){
+                        if (subCli.getGatewayIp().equals(gatewayIpObj) && subCli.getVlanId().equals(vlanId)) {
                             vtepDelCommitList.add(vtepCli);
-                        }
-                        else if(session != null) {
-                                session.getConsole().println("vtep with this vlan or gateway doesnt exist");
+                        } else if (session != null) {
+                            session.getConsole().println("vtep with this vlan or gateway doesnt exist");
                         }
                     }
+                } else if (session != null) {
+                    session.getConsole().println("Vtep with this ipaddress doesnt exist");
                 }
-                else if(session != null) {
-                        session.getConsole().println("Vtep with this ipaddress doesnt exist");
-                }
-            } else if(session != null) {
-                    session.getConsole().println("Vtep Doesnt exist");
+            } else if (session != null) {
+                session.getConsole().println("Vtep Doesnt exist");
             }
         }
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public <T extends DataObject> void deleteOnCommit() {
         List<InstanceIdentifier<T>> vtepPaths = new ArrayList<>();
         List<InstanceIdentifier<T>> subnetPaths = new ArrayList<>();
@@ -579,20 +641,21 @@ public void showCache(String cacheName) {
         try {
             if (vtepDelCommitList != null && !vtepDelCommitList.isEmpty()) {
                 InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
-                Optional<TransportZones> tZonesOptional =
+                Optional<TransportZones> transportZonesOptional =
                         ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
-                if (tZonesOptional.isPresent()) {
-                    TransportZones tZones = tZonesOptional.get();
-                    for (TransportZone tZ : tZones.getTransportZone()) {
-                        if (tZ.getSubnets() == null || tZ.getSubnets().isEmpty())
+                if (transportZonesOptional.isPresent()) {
+                    TransportZones transportZones = transportZonesOptional.get();
+                    for (TransportZone tz : transportZones.getTransportZone()) {
+                        if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
                             continue;
-                        for (Subnets sub : tZ.getSubnets()) {
+                        }
+                        for (Subnets sub : tz.getSubnets()) {
                             vtepDelList.addAll(vtepDelCommitList);
                             for (Vteps vtep : vtepDelList) {
                                 InstanceIdentifier<T> vpath =
                                         (InstanceIdentifier<T>) InstanceIdentifier
                                                 .builder(TransportZones.class)
-                                                .child(TransportZone.class, tZ.getKey())
+                                                .child(TransportZone.class, tz.getKey())
                                                 .child(Subnets.class, sub.getKey())
                                                 .child(Vteps.class, vtep.getKey()).build();
                                 if (sub.getVteps().remove(vtep)) {
@@ -606,33 +669,36 @@ public void showCache(String cacheName) {
                         }
                     }
 
-                    for (TransportZone tZ : tZones.getTransportZone()) {
-                        if (tZ.getSubnets() == null || tZ.getSubnets().isEmpty())
+                    for (TransportZone tz : transportZones.getTransportZone()) {
+                        if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
                             continue;
+                        }
                         for (Subnets sub : subDelList) {
-                            if (tZ.getSubnets().remove(sub)) {
+                            if (tz.getSubnets().remove(sub)) {
                                 InstanceIdentifier<T> spath =
                                         (InstanceIdentifier<T>) InstanceIdentifier
                                                 .builder(TransportZones.class)
-                                                .child(TransportZone.class, tZ.getKey())
+                                                .child(TransportZone.class, tz.getKey())
                                                 .child(Subnets.class, sub.getKey()).build();
                                 subnetPaths.add(spath);
-                                if (tZ.getSubnets() == null || tZ.getSubnets().size() == 0) {
-                                    tzDelList.add(tZ);
+                                if (tz.getSubnets() == null || tz.getSubnets().size() == 0) {
+                                    tzDelList.add(tz);
                                 }
                             }
                         }
                     }
 
-                    for (TransportZone tZ : tzDelList) {
-                        if (tZones.getTransportZone().remove(tZ)) {
+                    for (TransportZone tz : tzDelList) {
+                        if (transportZones.getTransportZone().remove(tz)) {
                             InstanceIdentifier<T> tpath =
                                     (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class)
-                                            .child(TransportZone.class, tZ.getKey()).build();
+                                            .child(TransportZone.class, tz.getKey()).build();
                             tzPaths.add(tpath);
-                            if (tZones.getTransportZone() == null || tZones.getTransportZone().size() == 0) {
-                                MDSALDataStoreUtils.asyncRemove(dataBroker, LogicalDatastoreType.CONFIGURATION, path,
-                                        ItmUtils.DEFAULT_CALLBACK);
+                            if (transportZones.getTransportZone() == null
+                                    || transportZones.getTransportZone().size() == 0) {
+                                ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                                    tx -> tx.delete(LogicalDatastoreType.CONFIGURATION, path)), LOG,
+                                    "Error deleting {}", path);
                                 return;
                             }
                         }
@@ -649,73 +715,76 @@ public void showCache(String cacheName) {
                 allPaths.clear();
                 vtepDelCommitList.clear();
             }
-        } catch (Exception e) {
-            LOG.error(e.getMessage());
+        } catch (RuntimeException e) {
+            LOG.error("Unexpected error", e);
         }
     }
 
-    public void showState(List<StateTunnelList> tunnelLists, boolean tunnelMonitorEnabled,CommandSession session) throws TepException{
+    @SuppressWarnings("checkstyle:RegexpSinglelineJava")
+    public void showState(Collection<StateTunnelList> tunnelLists, boolean tunnelMonitorEnabled) throws TepException {
         if (tunnelLists == null || tunnelLists.isEmpty()) {
-            handleError("No Internal Tunnels Exist", session);
+            handleError("No Internal Tunnels Exist");
             return;
         }
         if (!tunnelMonitorEnabled) {
-            if(session != null) {
-                session.getConsole().println("Tunnel Monitoring is Off");
-            }
+            System.out.println("Tunnel Monitoring is Off");
         }
         String displayFormat = "%-16s  %-16s  %-16s  %-16s  %-16s  %-10s  %-10s";
-        session.getConsole().println(String.format(displayFormat, "Tunnel Name", "Source-DPN",
+        System.out.println(String.format(displayFormat, "Tunnel Name", "Source-DPN",
                         "Destination-DPN", "Source-IP", "Destination-IP", "Trunk-State", "Transport Type"));
-        session.getConsole().println("-------------------------------------------------------------------------------------------------------------------------------------");
+        System.out.println("-----------------------------------------------------------------------------------------"
+                + "--------------------------------------------");
 
         for (StateTunnelList tunnelInst : tunnelLists) {
            // Display only the internal tunnels
-            if(  tunnelInst.getDstInfo().getTepDeviceType().equals(TepTypeInternal.class)) {
+            if (tunnelInst.getDstInfo().getTepDeviceType().equals(TepTypeInternal.class)) {
                 String tunnelInterfaceName = tunnelInst.getTunnelInterfaceName();
                 LOG.trace("tunnelInterfaceName::: {}", tunnelInterfaceName);
                 String tunnelState = ITMConstants.TUNNEL_STATE_UNKNOWN;
-                if (tunnelInst.getOperState() == TunnelOperStatus.Up)
+                if (tunnelInst.getOperState() == TunnelOperStatus.Up) {
                     tunnelState = ITMConstants.TUNNEL_STATE_UP;
-                else if (tunnelInst.getOperState() == TunnelOperStatus.Down )
+                } else if (tunnelInst.getOperState() == TunnelOperStatus.Down) {
                     tunnelState = ITMConstants.TUNNEL_STATE_DOWN;
+                }
                 Class<? extends TunnelTypeBase> tunType = tunnelInst.getTransportType();
                 String tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
-                if( tunType.equals(TunnelTypeVxlan.class))
-                   tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
-                else if( tunType.equals(TunnelTypeGre.class) )
-                   tunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
-                else if (tunType.equals(TunnelTypeMplsOverGre.class))
+                if (tunType.equals(TunnelTypeVxlan.class)) {
+                    tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
+                } else if (tunType.equals(TunnelTypeGre.class)) {
+                    tunnelType = ITMConstants.TUNNEL_TYPE_GRE;
+                } else if (tunType.equals(TunnelTypeMplsOverGre.class)) {
                     tunnelType = ITMConstants.TUNNEL_TYPE_MPLSoGRE;
-                session.getConsole().println(String.format(displayFormat, tunnelInst.getTunnelInterfaceName(), tunnelInst.getSrcInfo().getTepDeviceId(),
-                        tunnelInst.getDstInfo().getTepDeviceId(), tunnelInst.getSrcInfo().getTepIp().getIpv4Address().getValue(), tunnelInst.getDstInfo().getTepIp().getIpv4Address().getValue(), tunnelState,
-                        tunnelType));
-                
+                } else if (tunType.equals(TunnelTypeLogicalGroup.class)) {
+                    tunnelType = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
+                }
+                System.out.println(String.format(displayFormat, tunnelInst.getTunnelInterfaceName(),
+                        tunnelInst.getSrcInfo().getTepDeviceId(), tunnelInst.getDstInfo().getTepDeviceId(),
+                        new String(tunnelInst.getSrcInfo().getTepIp().getValue()),
+                        new String(tunnelInst.getDstInfo().getTepIp().getValue()), tunnelState, tunnelType));
             }
         }
     }
 
     // deletes from ADD-cache if it exists.
     public boolean isInCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
-                             String gatewayIp, String transportZone, CommandSession session) {
+            String gatewayIp, String transportZone, CommandSession session) {
         boolean exists = false;
-        VtepsKey vtepkey = new VtepsKey(dpnId, portName);
-        IpAddress ipAddressObj = new IpAddress(ipAddress.toCharArray());
-        IpPrefix subnetMaskObj = new IpPrefix(subnetMask.toCharArray());
-        IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
+        final VtepsKey vtepkey = new VtepsKey(dpnId, portName);
+        IpAddress ipAddressObj = IpAddressBuilder.getDefaultInstance(ipAddress);
+        IpPrefix subnetMaskObj = IpPrefixBuilder.getDefaultInstance(subnetMask);
+        IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
         if (gatewayIp != null) {
-            gatewayIpObj = new IpAddress(gatewayIp.toCharArray());
+            gatewayIpObj = IpAddressBuilder.getDefaultInstance(gatewayIp);
         } else {
             LOG.debug("gateway is null");
         }
         SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
-        Vteps vtepCli =
-                new VtepsBuilder().setDpnId(dpnId).setIpAddress(ipAddressObj).setKey(vtepkey)
-                        .setPortname(portName).build();
+        Vteps vtepCli = new VtepsBuilder().setDpnId(dpnId).setIpAddress(ipAddressObj).setKey(vtepkey)
+                .setPortname(portName).build();
         SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
 
-        if (tZones.containsKey(transportZone)) {
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(transportZone);
+        if (transportZonesHashMap.containsKey(transportZone)) {
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = transportZonesHashMap.get(transportZone);
             if (subVtepMapTemp.containsKey(subObCli)) { // if Subnet exists
                 List<Vteps> vtepListTemp = subVtepMapTemp.get(subObCli);
                 if (vtepListTemp.contains(vtepCli)) {
@@ -724,34 +793,33 @@ public void showCache(String cacheName) {
                     if (vtepListTemp.size() == 0) {
                         subVtepMapTemp.remove(subObCli);
                         if (subVtepMapTemp.size() == 0) {
-                            tZones.remove(transportZone);
+                            transportZonesHashMap.remove(transportZone);
                         }
                     }
-                } else if(session != null) {
-                        session.getConsole().println("Vtep " + "has not been configured");
+                } else if (session != null) {
+                    session.getConsole().println("Vtep " + "has not been configured");
                 }
             }
         }
         return exists;
     }
 
-    public void configureTunnelType(String tZoneName, String tunnelType) {
-        LOG.debug("configureTunnelType {} for transportZone {}", tunnelType, tZoneName);
+    public void configureTunnelType(String transportZoneName, String tunnelType) {
+        LOG.debug("configureTunnelType {} for transportZone {}", tunnelType, transportZoneName);
 
-        TransportZone tZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(tZoneName, dataBroker);
+        TransportZone transportZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(transportZoneName, dataBroker);
         Class<? extends TunnelTypeBase> tunType;
 
-        validateTunnelType(tZoneName, tunnelType, tZoneFromConfigDS);
-        if (tZoneFromConfigDS != null) {
-            if (!tZoneName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
-                LOG.debug(
-                    "Transport zone {} with tunnel type {} already exists. No action required.",
-                    tZoneName, tunnelType);
+        validateTunnelType(transportZoneName, tunnelType, transportZoneFromConfigDS);
+        if (transportZoneFromConfigDS != null) {
+            if (!transportZoneName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
+                LOG.debug("Transport zone {} with tunnel type {} already exists. No action required.",
+                    transportZoneName, tunnelType);
                 return;
             } else {
                 tunnelType = StringUtils.upperCase(tunnelType);
                 tunType = ItmUtils.TUNNEL_TYPE_MAP.get(tunnelType);
-                if(tZoneFromConfigDS.getTunnelType().equals(tunType)) {
+                if (transportZoneFromConfigDS.getTunnelType().equals(tunType)) {
                     // default-TZ already exists and tunnel-type is not changed during
                     // controller restart, then nothing to do now. Just return.
                     return;
@@ -764,22 +832,22 @@ public void showCache(String cacheName) {
         tunType = ItmUtils.TUNNEL_TYPE_MAP.get(tunnelType);
 
         TransportZones transportZones = null;
-        List<TransportZone> tZoneList = null;
+        List<TransportZone> tzList = null;
         InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
-        Optional<TransportZones> tZones = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+        Optional<TransportZones> tzones = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
 
-        TransportZone tZone = new TransportZoneBuilder().setKey(new TransportZoneKey(tZoneName))
+        TransportZone tzone = new TransportZoneBuilder().setKey(new TransportZoneKey(transportZoneName))
                 .setTunnelType(tunType).build();
-        if (tZones.isPresent()) {
-            tZoneList = tZones.get().getTransportZone();
-            if(tZoneList == null || tZoneList.isEmpty()) {
-                tZoneList = new ArrayList<>();
+        if (tzones.isPresent()) {
+            tzList = tzones.get().getTransportZone();
+            if (tzList == null || tzList.isEmpty()) {
+                tzList = new ArrayList<>();
             }
         } else {
-            tZoneList = new ArrayList<>();
+            tzList = new ArrayList<>();
         }
-        tZoneList.add(tZone);
-        transportZones = new TransportZonesBuilder().setTransportZone(tZoneList).build();
+        tzList.add(tzone);
+        transportZones = new TransportZonesBuilder().setTransportZone(tzList).build();
         ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, path, transportZones, dataBroker);
 
     }
@@ -787,44 +855,43 @@ public void showCache(String cacheName) {
     /**
      * Validate tunnel type.
      *
-     * @param tZoneName
+     * @param transportZoneName
      *            the t zone name
      * @param tunnelType
      *            the tunnel type
      */
-    private void validateTunnelType(String tZoneName, String tunnelType,TransportZone tZoneFromConfigDS) {
+    private void validateTunnelType(String transportZoneName, String tunnelType,TransportZone tzoneFromConfigDs) {
         /*
+         * String strTunnelType = ItmUtils.validateTunnelType(tunnelType);
+         *
+         * TransportZone tZone = getTransportZone(tZoneName); if (tZone != null)
+         * { if (!StringUtils.equalsIgnoreCase(strTunnelType,
+         * tZone.getTunnelType()) && ItmUtils.isNotEmpty(tZone.getSubnets())) {
+         * String errorMsg = new StringBuilder("Changing the tunnel type from "
+         * ).append(tZone.getTunnelType()) .append(" to ").append(strTunnelType)
+         * .append(" is not allowed for already configured transport zone ["
+         * ).append(tZoneName) .append("].").toString();
+         * Preconditions.checkArgument(false, errorMsg); } }
+         */
         String strTunnelType = ItmUtils.validateTunnelType(tunnelType);
-
-        TransportZone tZone = getTransportZone(tZoneName);
-        if (tZone != null) {
-            if (!StringUtils.equalsIgnoreCase(strTunnelType, tZone.getTunnelType())
-                    && ItmUtils.isNotEmpty(tZone.getSubnets())) {
-                String errorMsg = new StringBuilder("Changing the tunnel type from ").append(tZone.getTunnelType())
-                        .append(" to ").append(strTunnelType)
-                        .append(" is not allowed for already configured transport zone [").append(tZoneName)
-                        .append("].").toString();
-                Preconditions.checkArgument(false, errorMsg);
-            }
+        Class<? extends TunnelTypeBase> tunType;
+        if (strTunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) {
+            tunType = TunnelTypeVxlan.class;
+        } else {
+            tunType = TunnelTypeGre.class;
         }
-        */
-        String strTunnelType = ItmUtils.validateTunnelType(tunnelType);
-        Class<? extends TunnelTypeBase> tunType ;
-        if( strTunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN))
-            tunType = TunnelTypeVxlan.class ;
-        else
-            tunType = TunnelTypeGre.class ;
-        //TransportZone tZone = getTransportZone(tZoneName);
+        // TransportZone tZone = getTransportZone(tZoneName);
         // if (tZone != null) {
-        if (tZoneFromConfigDS != null) {
-            if( (!tZoneFromConfigDS.getTunnelType().equals(tunType))  && ItmUtils.isNotEmpty(tZoneFromConfigDS.getSubnets())) {
+        if (tzoneFromConfigDs != null) {
+            if (!tzoneFromConfigDs.getTunnelType().equals(tunType)  && ItmUtils.isNotEmpty(tzoneFromConfigDs
+                    .getSubnets())) {
                 // for default-TZ, such error message is not needed to be thrown.
                 // it needs to be handled in different way, by deleting default-TZ
                 // with old tunnel-type and then add default-TZ with new tunnel-type
-                if (!tZoneName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
-                    String errorMsg = "Changing the tunnel type from " + tZoneFromConfigDS.getTunnelType()
+                if (!transportZoneName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
+                    String errorMsg = "Changing the tunnel type from " + tzoneFromConfigDs.getTunnelType()
                         + " to " + strTunnelType
-                        + " is not allowed for already configured transport zone [" + tZoneName
+                        + " is not allowed for already configured transport zone [" + transportZoneName
                         + "].";
                     Preconditions.checkArgument(false, errorMsg);
                 } else {
@@ -837,19 +904,21 @@ public void showCache(String cacheName) {
 
     public void configureTunnelMonitorParams(boolean monitorEnabled, String monitorProtocol) {
         InstanceIdentifier<TunnelMonitorParams> path = InstanceIdentifier.builder(TunnelMonitorParams.class).build();
-        Optional<TunnelMonitorParams> storedTunnelMonitor = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+        Optional<TunnelMonitorParams> storedTunnelMonitor = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
+                path, dataBroker);
         Class<? extends TunnelMonitoringTypeBase> monitorType ;
-        if(storedTunnelMonitor.isPresent() && storedTunnelMonitor.get().getMonitorProtocol()!=null )
+        if (storedTunnelMonitor.isPresent() && storedTunnelMonitor.get().getMonitorProtocol() != null) {
             monitorType = storedTunnelMonitor.get().getMonitorProtocol();
-        else
-        {
-            if(monitorProtocol!=null && monitorProtocol.equalsIgnoreCase(ITMConstants.MONITOR_TYPE_LLDP))
-                monitorType = TunnelMonitoringTypeLldp.class ;
-            else
-                monitorType = TunnelMonitoringTypeBfd.class ;
-        }
-        if (!storedTunnelMonitor.isPresent()|| storedTunnelMonitor.get().isEnabled() != monitorEnabled)  {
-            TunnelMonitorParams tunnelMonitor = new TunnelMonitorParamsBuilder().setEnabled(monitorEnabled).setMonitorProtocol(monitorType).build();
+        } else {
+            if (monitorProtocol != null && monitorProtocol.equalsIgnoreCase(ITMConstants.MONITOR_TYPE_LLDP)) {
+                monitorType = TunnelMonitoringTypeLldp.class;
+            } else {
+                monitorType = TunnelMonitoringTypeBfd.class;
+            }
+        }
+        if (!storedTunnelMonitor.isPresent() || storedTunnelMonitor.get().isEnabled() != monitorEnabled) {
+            TunnelMonitorParams tunnelMonitor = new TunnelMonitorParamsBuilder().setEnabled(monitorEnabled)
+                    .setMonitorProtocol(monitorType).build();
             ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tunnelMonitor, dataBroker,
                     ItmUtils.DEFAULT_CALLBACK);
 
@@ -857,8 +926,10 @@ public void showCache(String cacheName) {
     }
 
     public void configureTunnelMonitorInterval(int interval) {
-        InstanceIdentifier<TunnelMonitorInterval> path = InstanceIdentifier.builder(TunnelMonitorInterval.class).build();
-        Optional<TunnelMonitorInterval> storedTunnelMonitor = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+        InstanceIdentifier<TunnelMonitorInterval> path =
+                InstanceIdentifier.builder(TunnelMonitorInterval.class).build();
+        Optional<TunnelMonitorInterval> storedTunnelMonitor = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path,
+                dataBroker);
         if (!storedTunnelMonitor.isPresent() || storedTunnelMonitor.get().getInterval() != interval) {
             TunnelMonitorInterval tunnelMonitor = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
             ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tunnelMonitor, dataBroker,
@@ -866,12 +937,7 @@ public void showCache(String cacheName) {
         }
     }
 
-    public void handleError(String errorMessage, CommandSession session) throws TepException {
-        if(session != null) {
-            session.getConsole().println(errorMessage);
-        } else {
-            throw new TepException(errorMessage);
-        }
-
+    public void handleError(String errorMessage) throws TepException {
+        throw new TepException(errorMessage);
     }
 }