To fix grep not working for tep:show &
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / cli / TepCommandHelper.java
index 74aa845b45fd32e219395a37dc9de3c2902c900a..b263b5e960ccadb030ee9d17ccb7931614154470 100644 (file)
@@ -9,25 +9,39 @@ package org.opendaylight.genius.itm.cli;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 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.interfacemanager.interfaces.IInterfaceManager;
 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.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.IpPrefix;
-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.state.Interface.AdminStatus;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.*;
+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.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.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.op.rev160406.TunnelList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnel.list.InternalTunnel;
+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.TunnelOperStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZonesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
@@ -44,19 +58,11 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-//import org.opendaylight.genius.interfacemgr.util.OperationalIfmUtil;
-
-
+@Singleton
 public class TepCommandHelper {
 
     private static final Logger LOG = LoggerFactory.getLogger(TepCommandHelper.class);
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     static int check = 0;
     static short flag = 0;
     /*
@@ -64,27 +70,32 @@ public class TepCommandHelper {
      * 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<String, Map<SubnetObject, List<Vteps>>>();
-    private List<Subnets> subnetList = new ArrayList<Subnets>();
-    private List<TransportZone> tZoneList = new ArrayList<TransportZone>();
-    private List<Vteps> vtepDelCommitList = new ArrayList<Vteps>();
-    private IInterfaceManager interfaceManager;
+    final Map<String, Map<SubnetObject, List<Vteps>>> tZones = new HashMap<>();
+    private List<Subnets> subnetList = new ArrayList<>();
+    private List<TransportZone> tZoneList = new ArrayList<>();
+    private List<Vteps> vtepDelCommitList = new ArrayList<>();
 
     // private List<InstanceIdentifier<? extends DataObject>> vtepPaths = new
     // ArrayList<>();
 
-
-    public TepCommandHelper(final DataBroker broker) {
-        this.dataBroker = broker;
+    @Inject
+    public TepCommandHelper(final DataBroker dataBroker) {
+        this.dataBroker = dataBroker;
     }
 
+    @PostConstruct
+    public void start() {
+        configureTunnelType(ITMConstants.DEFAULT_TRANSPORT_ZONE,ITMConstants.TUNNEL_TYPE_VXLAN);
+        LOG.info("TepCommandHelper Started");
+    }
 
-    public void setInterfaceManager(IInterfaceManager interfaceManager) {
-        this.interfaceManager = interfaceManager;
+    @PreDestroy
+    public void close() {
+        LOG.info("TepCommandHelper Closed");
     }
 
     public void createLocalCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress,
-                                 String subnetMask, String gatewayIp, String transportZone{
+                                 String subnetMask, String gatewayIp, String transportZone, CommandSession session) throws TepException{
 
         check++;
         IpAddress ipAddressObj = null;
@@ -100,23 +111,25 @@ public class TepCommandHelper {
                 LOG.debug("gateway is null");
             }
         } catch (Exception e) {
-            System.out.println("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255");
+            handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
             return;
         }
         try {
             subnetMaskObj = new IpPrefix(subnetMask.toCharArray());
         } catch (Exception e) {
-            System.out.println("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32");
+            handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
             return;
         }
 
         if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
-            System.out.println("IpAddress and gateWayIp should belong to the subnet provided");
+            handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
             return;
         }
 
         if (checkTepPerTzPerDpn(transportZone, dpnId)) {
-            System.out.println("Only one end point per transport Zone per Dpn is allowed");
+            if(session  != null) {
+                session.getConsole().println("Only one end point per transport Zone per Dpn is allowed");
+            }
             return;
         }
         Vteps vtepCli = new VtepsBuilder().setDpnId(dpnId).setIpAddress(ipAddressObj).setKey(vtepkey)
@@ -126,9 +139,9 @@ 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 = (Map<SubnetObject, List<Vteps>>) tZones.get(transportZone);
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(transportZone);
             if (subVtepMapTemp.containsKey(subObCli)) { // if Subnet exists
-                List<Vteps> vtepListTemp = (List<Vteps>) subVtepMapTemp.get(subObCli);
+                List<Vteps> vtepListTemp = subVtepMapTemp.get(subObCli);
                 if (vtepListTemp.contains(vtepCli)) {
                     // do nothing
                 } else {
@@ -136,17 +149,19 @@ public class TepCommandHelper {
                 }
             } else { // subnet doesnt exist
                 if (checkExistingSubnet(subVtepMapTemp, subObCli)) {
-                    System.out.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;
                 }
-                List<Vteps> vtepListTemp = new ArrayList<Vteps>();
+                List<Vteps> vtepListTemp = new ArrayList<>();
                 vtepListTemp.add(vtepCli);
                 subVtepMapTemp.put(subObCli, vtepListTemp);
             }
         } else {
-            List<Vteps> vtepListTemp = new ArrayList<Vteps>();
+            List<Vteps> vtepListTemp = new ArrayList<>();
             vtepListTemp.add(vtepCli);
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = new HashMap<SubnetObject, List<Vteps>>();
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = new HashMap<>();
             subVtepMapTemp.put(subObCli, vtepListTemp);
             tZones.put(transportZone, subVtepMapTemp);
         }
@@ -177,7 +192,7 @@ public class TepCommandHelper {
         // Checking for duplicates in local cache
         for (String tZ : tZones.keySet()) {
             boolean isGreType = isGreTunnelType(tZ, tZoneMap);
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(tZ);
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tZ);
             for (SubnetObject subOb : subVtepMapTemp.keySet()) {
                 List<Vteps> vtepList = subVtepMapTemp.get(subOb);
                 validateForDuplicateAndSingleGreTep(inputVtep, isConfiguredTepGreType, isGreType, vtepList);
@@ -208,9 +223,8 @@ public class TepCommandHelper {
         if (isConfiguredTepGreType && isGreType) {
             for (Vteps vtep : vtepList) {
                 if (vtep.getDpnId().equals(dpnId)) {
-                    String errMsg = new StringBuilder("DPN [").append(dpnId)
-                            .append("] already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.")
-                            .toString();
+                    String errMsg = "DPN [" + dpnId +
+                            "] already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.";
                     Preconditions.checkArgument(false, errMsg);
                 }
             }
@@ -249,10 +263,7 @@ public class TepCommandHelper {
             return true;
         }
         */
-        if( (tzone != null) && (tzone.getTunnelType()).equals(TunnelTypeGre.class) ) {
-            return true;
-        }
-        return false;
+        return (tzone != null) && (tzone.getTunnelType()).equals(TunnelTypeGre.class);
     }
 
     /**
@@ -265,30 +276,7 @@ public class TepCommandHelper {
     public TransportZone getTransportZone(String tzone) {
         InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
                 .child(TransportZone.class, new TransportZoneKey(tzone)).build();
-        Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath,
-                dataBroker);
-        if (tZoneOptional.isPresent()) {
-            return tZoneOptional.get();
-        }
-        return null;
-    }
-
-    /**
-     * Gets the transport zone from config ds.
-     *
-     * @param tzone
-     *            the tzone
-     * @return the transport zone
-     */
-    public TransportZone getTransportZoneFromConfigDS(String tzone) {
-        InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
-                .child(TransportZone.class, new TransportZoneKey(tzone)).build();
-        Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath,
-                dataBroker);
-        if (tZoneOptional.isPresent()) {
-            return tZoneOptional.get();
-        }
-        return null;
+        return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker).orNull();
     }
 
     /**
@@ -298,11 +286,7 @@ public class TepCommandHelper {
      */
     public TransportZones getAllTransportZones() {
         InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
-        Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
-        if (tZonesOptional.isPresent()) {
-            return tZonesOptional.get();
-        }
-        return null;
+        return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker).orNull();
     }
 
     public boolean checkExistingSubnet(Map<SubnetObject, List<Vteps>> subVtepMapTemp, SubnetObject subObCli) {
@@ -320,7 +304,7 @@ public class TepCommandHelper {
     public boolean checkTepPerTzPerDpn(String tzone, BigInteger dpnId) {
         // check in local cache
         if (tZones.containsKey(tzone)) {
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(tzone);
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tzone);
             for (SubnetObject subOb : subVtepMapTemp.keySet()) {
                 List<Vteps> vtepList = subVtepMapTemp.get(subOb);
                 for (Vteps vtep : vtepList)
@@ -358,11 +342,11 @@ public class TepCommandHelper {
         try {
             LOG.debug("no of teps added" + check);
             if (tZones != null || !tZones.isEmpty()) {
-                tZoneList = new ArrayList<TransportZone>();
+                tZoneList = new ArrayList<>();
                 for (String tZ : tZones.keySet()) {
                     LOG.debug("tZones" + tZ);
-                    subnetList = new ArrayList<Subnets>();
-                    Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(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);
@@ -417,11 +401,11 @@ public class TepCommandHelper {
                 LOG.debug("NO vteps were configured");
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            LOG.error(e.getMessage());
         }
     }
 
-    public void showTeps(boolean monitorEnabled, int monitorInterval) {
+    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);
@@ -429,10 +413,10 @@ public class TepCommandHelper {
             TransportZones tZones = tZonesOptional.get();
             if(tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty())
             {
-                System.out.println("No teps configured");
+                handleError("No teps configured", session);
                 return;
             }
-            List<String> result = new ArrayList<String>();
+            List<String> result = new ArrayList<>();
             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());
@@ -459,23 +443,45 @@ public class TepCommandHelper {
                         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().toString()));
+                                .getIpAddress().getIpv4Address().getValue(), vtep.getPortname()));
                     }
                 }
             }
-            if (flag == true) {
-                for (String p : result) {
-                    System.out.println(p);
+            if (session != null) {
+                if (flag) {
+                    for (String p : result) {
+                        System.out.println(p);
+                    }
+                } else {
+                    System.out.println("No teps to display");
                 }
-            } else
-                System.out.println("No teps to display");
-        } else
+            }
+        } 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 ") ;
+            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() ;
+            }
+
+        }else
+            System.out.println( "No data in cache for " + cacheName ) ;
+        }
 
     public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
-                           String gatewayIp, String transportZone) {
+                           String gatewayIp, String transportZone,CommandSession session) throws TepException {
 
         IpAddress ipAddressObj = null;
         IpAddress gatewayIpObj = null;
@@ -490,18 +496,18 @@ public class TepCommandHelper {
                 LOG.debug("gateway is null");
             }
         } catch (Exception e) {
-            System.out.println("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255");
+            handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
             return;
         }
         try {
             subnetMaskObj = new IpPrefix(subnetMask.toCharArray());
         } catch (Exception e) {
-            System.out.println("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32");
+            handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
             return;
         }
 
         if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
-            System.out.println("IpAddress and gateWayIp should belong to the subnet provided");
+            handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
             return;
         }
         SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
@@ -514,7 +520,7 @@ public class TepCommandHelper {
                         .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);
+        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()) {
@@ -531,14 +537,16 @@ public class TepCommandHelper {
                         if(subCli.getGatewayIp().equals(gatewayIpObj) && subCli.getVlanId().equals(vlanId)){
                             vtepDelCommitList.add(vtepCli);
                         }
-                        else
-                            System.out.println(String.format("vtep with this vlan or gateway doesnt exist"));
+                        else if(session != null) {
+                                session.getConsole().println("vtep with this vlan or gateway doesnt exist");
+                        }
                     }
                 }
-                else
-                    System.out.println(String.format("Vtep with this ipaddress doesnt exist"));
-            } else {
-                System.out.println(String.format("Vtep 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");
             }
         }
     }
@@ -547,9 +555,9 @@ public class TepCommandHelper {
         List<InstanceIdentifier<T>> vtepPaths = new ArrayList<>();
         List<InstanceIdentifier<T>> subnetPaths = new ArrayList<>();
         List<InstanceIdentifier<T>> tzPaths = new ArrayList<>();
-        List<Subnets> subDelList = new ArrayList<Subnets>();
-        List<TransportZone> tzDelList = new ArrayList<TransportZone>();
-        List<Vteps> vtepDelList = new ArrayList<Vteps>();
+        List<Subnets> subDelList = new ArrayList<>();
+        List<TransportZone> tzDelList = new ArrayList<>();
+        List<Vteps> vtepDelList = new ArrayList<>();
         List<InstanceIdentifier<T>> allPaths = new ArrayList<>();
         try {
             if (vtepDelCommitList != null && !vtepDelCommitList.isEmpty()) {
@@ -625,66 +633,53 @@ public class TepCommandHelper {
                 vtepDelCommitList.clear();
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            LOG.error(e.getMessage());
         }
     }
 
-    public void showState(TunnelList tunnels, boolean tunnelMonitorEnabled) {
-        IfTunnel tunnelInterface = null;
-        IfL2vlan l2Vlan = null;
-        List<InternalTunnel> tunnelLists = tunnels.getInternalTunnel();
+    public void showState(List<StateTunnelList> tunnelLists, boolean tunnelMonitorEnabled,CommandSession session) throws TepException{
         if (tunnelLists == null || tunnelLists.isEmpty()) {
-            System.out.println("No Internal Tunnels Exist");
+            handleError("No Internal Tunnels Exist", session);
             return;
         }
         if (!tunnelMonitorEnabled) {
-            System.out.println("Tunnel Monitoring is Off");
+            if(session != null) {
+                session.getConsole().println("Tunnel Monitoring is Off");
+            }
         }
-        String displayFormat = "%-16s  %-16s  %-16s  %-16s  %-16s  %-8s  %-10s  %-10s";
+        String displayFormat = "%-16s  %-16s  %-16s  %-16s  %-16s  %-10s  %-10s";
         System.out.println(String.format(displayFormat, "Tunnel Name", "Source-DPN",
-                "Destination-DPN", "Source-IP", "Destination-IP", "Vlan Id", "Trunk-State", "Transport Type"));
+                        "Destination-DPN", "Source-IP", "Destination-IP", "Trunk-State", "Transport Type"));
         System.out.println("-------------------------------------------------------------------------------------------------------------------------------------");
 
-        for (InternalTunnel tunnel : tunnelLists) {
-            String tunnelInterfaceName = tunnel.getTunnelInterfaceName();
-            LOG.trace("tunnelInterfaceName::: {}", tunnelInterfaceName);
-
-            InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
-                    ItmUtils.buildStateInterfaceId(tunnelInterfaceName);
-            Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateOptional =
-                    ItmUtils.read(LogicalDatastoreType.OPERATIONAL, ifStateId, dataBroker);
-            String tunnelState = "DOWN" ;
-            if (ifStateOptional.isPresent()) {
-                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface iface = ifStateOptional.get() ;
-                if(iface.getAdminStatus() == AdminStatus.Up && iface.getOperStatus() == OperStatus.Up)
-                    tunnelState = "UP" ;
-            }
-            InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
-            Optional<Interface> ifaceObj = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, dataBroker) ;
-            if (ifaceObj.isPresent()) {
-                l2Vlan = (IfL2vlan) ifaceObj.get().getAugmentation(IfL2vlan.class);
-                tunnelInterface = (IfTunnel) ifaceObj.get().getAugmentation(IfTunnel.class);
-
-                Class<? extends TunnelTypeBase> tunType = tunnelInterface.getTunnelInterfaceType();
+        for (StateTunnelList tunnelInst : tunnelLists) {
+           // Display only the internal tunnels
+            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)
+                    tunnelState = ITMConstants.TUNNEL_STATE_UP;
+                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 ;
-                int vlanId = 0;
-                if( l2Vlan != null ) {
-                   vlanId = l2Vlan.getVlanId().getValue() ;
-                }
-                System.out.println(String.format(displayFormat, tunnel.getTunnelInterfaceName(), tunnel
-                            .getSourceDPN().toString(), tunnel.getDestinationDPN().toString(), tunnelInterface.getTunnelSource().getIpv4Address().getValue(), tunnelInterface.getTunnelDestination().getIpv4Address().getValue(),vlanId, tunnelState ,
-                    tunnelType));
+                else if (tunType.equals(TunnelTypeMplsOverGre.class))
+                    tunnelType = ITMConstants.TUNNEL_TYPE_MPLSoGRE;
+                System.out.println(String.format(displayFormat, tunnelInst.getTunnelInterfaceName(), tunnelInst.getSrcInfo().getTepDeviceId(),
+                        tunnelInst.getDstInfo().getTepDeviceId(), tunnelInst.getSrcInfo().getTepIp().getIpv4Address().getValue(), tunnelInst.getDstInfo().getTepIp().getIpv4Address().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) {
+                             String gatewayIp, String transportZone, CommandSession session) {
         boolean exists = false;
         VtepsKey vtepkey = new VtepsKey(dpnId, portName);
         IpAddress ipAddressObj = new IpAddress(ipAddress.toCharArray());
@@ -702,9 +697,9 @@ public class TepCommandHelper {
         SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
 
         if (tZones.containsKey(transportZone)) {
-            Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(transportZone);
+            Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(transportZone);
             if (subVtepMapTemp.containsKey(subObCli)) { // if Subnet exists
-                List<Vteps> vtepListTemp = (List<Vteps>) subVtepMapTemp.get(subObCli);
+                List<Vteps> vtepListTemp = subVtepMapTemp.get(subObCli);
                 if (vtepListTemp.contains(vtepCli)) {
                     exists = true; // return true if tzones has vtep
                     vtepListTemp.remove(vtepCli);
@@ -714,8 +709,8 @@ public class TepCommandHelper {
                             tZones.remove(transportZone);
                         }
                     }
-                } else {
-                    System.out.println("Vtep " + "has not been configured");
+                } else if(session != null) {
+                        session.getConsole().println("Vtep " + "has not been configured");
                 }
             }
         }
@@ -725,7 +720,7 @@ public class TepCommandHelper {
     public void configureTunnelType(String tZoneName, String tunnelType) {
         LOG.debug("configureTunnelType {} for transportZone {}", tunnelType, tZoneName);
 
-        TransportZone tZoneFromConfigDS = getTransportZoneFromConfigDS(tZoneName);
+        TransportZone tZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(tZoneName, dataBroker);
         validateTunnelType(tZoneName, tunnelType,tZoneFromConfigDS);
 
         if (tZoneFromConfigDS != null) {
@@ -748,10 +743,10 @@ public class TepCommandHelper {
         if (tZones.isPresent()) {
             tZoneList = tZones.get().getTransportZone();
             if(tZoneList == null || tZoneList.isEmpty()) {
-                tZoneList = new ArrayList<TransportZone>();
+                tZoneList = new ArrayList<>();
             }
         } else {
-            tZoneList = new ArrayList<TransportZone>();
+            tZoneList = new ArrayList<>();
         }
         tZoneList.add(tZone);
         transportZones = new TransportZonesBuilder().setTransportZone(tZoneList).build();
@@ -793,10 +788,10 @@ public class TepCommandHelper {
         // if (tZone != null) {
         if (tZoneFromConfigDS != null) {
             if( (!tZoneFromConfigDS.getTunnelType().equals(tunType))  && ItmUtils.isNotEmpty(tZoneFromConfigDS.getSubnets())) {
-                String errorMsg = new StringBuilder("Changing the tunnel type from ").append(tZoneFromConfigDS.getTunnelType())
-                        .append(" to ").append(strTunnelType)
-                        .append(" is not allowed for already configured transport zone [").append(tZoneName)
-                        .append("].").toString();
+                String errorMsg = "Changing the tunnel type from " + tZoneFromConfigDS.getTunnelType() +
+                        " to " + strTunnelType +
+                        " is not allowed for already configured transport zone [" + tZoneName +
+                        "].";
                 Preconditions.checkArgument(false, errorMsg);
             }
         }
@@ -832,4 +827,13 @@ public class TepCommandHelper {
                     ItmUtils.DEFAULT_CALLBACK);
         }
     }
+
+    public void handleError(String errorMessage, CommandSession session) throws TepException {
+        if(session != null) {
+            session.getConsole().println(errorMessage);
+        } else {
+            throw new TepException(errorMessage);
+        }
+
+    }
 }