[CORD-2856] Traffic on dual-homed hosts not properly highlighted

Change-Id: Iab6c99c7a6e8a33f1ffa0e31d52fd3e0d360676a
(cherry picked from commit 4f3236a9d3f5e595c29a1ba30da773d49078e64d)
diff --git a/core/api/src/main/java/org/onosproject/net/DefaultEdgeLink.java b/core/api/src/main/java/org/onosproject/net/DefaultEdgeLink.java
index 3e1121e..7fe1ee3 100644
--- a/core/api/src/main/java/org/onosproject/net/DefaultEdgeLink.java
+++ b/core/api/src/main/java/org/onosproject/net/DefaultEdgeLink.java
@@ -15,8 +15,11 @@
  */
 package org.onosproject.net;
 
+import com.google.common.collect.ImmutableSet;
 import org.onosproject.net.provider.ProviderId;
 
+import java.util.Set;
+
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -95,4 +98,25 @@
                                    host.location(), isIngress, host.annotations());
     }
 
+    /**
+     * Creates edge links, to the specified end-station.
+     *
+     * The edge link inherits the target host annotations.
+     *
+     * @param host      host
+     * @param isIngress true to indicate host-to-network direction; false
+     *                  for network-to-host direction
+     * @return new phantom edge link
+     */
+    public static Set<DefaultEdgeLink> createEdgeLinks(Host host, boolean isIngress) {
+        checkNotNull(host, "Host cannot be null");
+        ImmutableSet.Builder<DefaultEdgeLink> edgeLinksBuilder = ImmutableSet.builder();
+        host.locations().forEach(
+                location -> edgeLinksBuilder.add(new DefaultEdgeLink(ProviderId.NONE,
+                                                 new ConnectPoint(host.id(), PortNumber.P0),
+                                                 location, isIngress, host.annotations()))
+        );
+        return edgeLinksBuilder.build();
+    }
+
 }
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java
index 1e2ae83..f45eb8d 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java
@@ -66,6 +66,7 @@
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLinks;
 import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
 import static org.onosproject.ui.impl.TrafficMonitorBase.Mode.RELATED_INTENTS;
 import static org.onosproject.ui.impl.TrafficMonitorBase.Mode.SELECTED_INTENT;
@@ -363,7 +364,7 @@
         Set<Host> hosts = services.host().getConnectedHosts(deviceId);
         if (hosts != null) {
             for (Host host : hosts) {
-                links.add(createEdgeLink(host, false));
+                links.addAll(createEdgeLinks(host, false));
             }
         }
 
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java
index 5de26cc..4296d3b 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java
@@ -18,6 +18,7 @@
 package org.onosproject.ui.impl;
 
 import org.onosproject.incubator.net.PortStatisticsService.MetricType;
+import org.onosproject.net.DefaultEdgeLink;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
 import org.onosproject.net.statistic.Load;
@@ -37,7 +38,7 @@
 
 import static org.onosproject.incubator.net.PortStatisticsService.MetricType.BYTES;
 import static org.onosproject.incubator.net.PortStatisticsService.MetricType.PACKETS;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLinks;
 import static org.onosproject.ui.impl.TrafficMonitorBase.Mode.IDLE;
 
 /**
@@ -306,8 +307,12 @@
      */
     protected void addEdgeLinks(TrafficLinkMap linkMap) {
         services.host().getHosts().forEach(host -> {
-            linkMap.add(createEdgeLink(host, true));
-            linkMap.add(createEdgeLink(host, false));
+            // Ingress edge links
+            Set<DefaultEdgeLink> edgeLinks = createEdgeLinks(host, true);
+            edgeLinks.forEach(linkMap::add);
+            // Egress edge links
+            edgeLinks = createEdgeLinks(host, false);
+            edgeLinks.forEach(linkMap::add);
         });
     }