T3 Fix for only local addresses in pingall

Change-Id: I9c5e014f13c85df3de798d0afc335a4d08e1a90c
(cherry picked from commit 3217ecf71bcd5c46a350e43f22f23ff01a736418)
diff --git a/apps/t3/src/main/java/org/onosproject/t3/cli/TroubleshootPingAllTraceCommand.java b/apps/t3/src/main/java/org/onosproject/t3/cli/TroubleshootPingAllTraceCommand.java
index 4b262ca..d2dba49 100644
--- a/apps/t3/src/main/java/org/onosproject/t3/cli/TroubleshootPingAllTraceCommand.java
+++ b/apps/t3/src/main/java/org/onosproject/t3/cli/TroubleshootPingAllTraceCommand.java
@@ -74,6 +74,11 @@
                         printResultOnly(trace, ipv4);
                     }
                 } else {
+                    if (trace.getEndpointHosts().isPresent()) {
+                        Host source = trace.getEndpointHosts().get().getLeft();
+                        Host destination = trace.getEndpointHosts().get().getRight();
+                        print("Source %s --> Destination %s", source.id(), destination.id());
+                    }
                     print("Error in obtaining trace: %s", trace.resultMessage());
                 }
                 print("%s", StringUtils.leftPad("", 100, '-'));
diff --git a/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java b/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java
index 7c4b2dd..00c2335 100644
--- a/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java
+++ b/apps/t3/src/main/java/org/onosproject/t3/impl/TroubleshootManager.java
@@ -19,6 +19,7 @@
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
@@ -137,9 +138,18 @@
         hostService.getHosts().forEach(host -> {
             List<IpAddress> ipAddresses = getIpAddresses(host, type, false);
             if (ipAddresses.size() > 0) {
+                //check if the host has only local IPs of that ETH type
+                boolean onlyLocalSrc = ipAddresses.size() == 1 && ipAddresses.get(0).isLinkLocal();
                 hostService.getHosts().forEach(hostToPing -> {
                     List<IpAddress> ipAddressesToPing = getIpAddresses(hostToPing, type, false);
-                    if (ipAddressesToPing.size() > 0 && !host.equals(hostToPing)) {
+                    //check if the other host has only local IPs of that ETH type
+                    boolean onlyLocalDst = ipAddressesToPing.size() == 1 && ipAddressesToPing.get(0).isLinkLocal();
+                    boolean sameLocation = Sets.intersection(host.locations(), hostToPing.locations()).size() > 0;
+                    //Trace is done only if they are both local and under the same location
+                    // or not local and if they are not the same host.
+                    if (((sameLocation && onlyLocalDst && onlyLocalSrc) ||
+                            (!onlyLocalSrc && !onlyLocalDst && ipAddressesToPing.size() > 0))
+                            && !host.equals(hostToPing)) {
                         tracesBuilder.add(trace(host.id(), hostToPing.id(), type));
                     }
                 });