ONOS-6259: Topo2 - Implement server-side highlighting model (WIP)
- Enhanced BiLink to allow a UiLinkId as its identifier.
- Corrected aggregation of traffic data for synthetic links in regions.
- Removed TrafficLink copy constructor (not needed).

Change-Id: Ia7d84f28ec69737e7474bfc100262b837effef73
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/BiLink.java b/core/api/src/main/java/org/onosproject/ui/topo/BiLink.java
index b50e34d..be7fa90 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/BiLink.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/BiLink.java
@@ -18,6 +18,7 @@
 
 import org.onosproject.net.Link;
 import org.onosproject.net.LinkKey;
+import org.onosproject.ui.model.topo.UiLinkId;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -26,9 +27,14 @@
  * <p>
  * Subclasses will decide how to generate the link highlighting (coloring
  * and labeling) for the topology view.
+ * <p>
+ * As an alternative, a bi-link can be initialized with a {@link UiLinkId}
+ * (ignoring the LinkKey and links one and two), which will be reported as
+ * its identifier instead.
  */
 public abstract class BiLink {
 
+    private final UiLinkId uiLinkId;
     private final LinkKey key;
     private final Link one;
     private Link two;
@@ -44,6 +50,19 @@
     public BiLink(LinkKey key, Link link) {
         this.key = checkNotNull(key);
         this.one = checkNotNull(link);
+        this.uiLinkId = null;
+    }
+
+    /**
+     * Constructs a bi-link for the given UI link identifier; sets remaining
+     * fields to null.
+     *
+     * @param uilinkId canonical ID for this bi-link
+     */
+    public BiLink(UiLinkId uilinkId) {
+        this.uiLinkId = checkNotNull(uilinkId);
+        this.key = null;
+        this.one = null;
     }
 
     /**
@@ -62,7 +81,16 @@
      * @return link identifier
      */
     public String linkId() {
-        return key.asId();
+        return uiLinkId != null ? uiLinkId.toString() : key.asId();
+    }
+
+    /**
+     * Returns the UI link identifier for this bi-link (if set).
+     *
+     * @return the UI link ID
+     */
+    public UiLinkId uiLinkId() {
+        return uiLinkId;
     }
 
     /**
@@ -94,7 +122,7 @@
 
     @Override
     public String toString() {
-        return key.asId();
+        return linkId();
     }
 
     /**
diff --git a/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTest.java b/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTest.java
index df6d3f7..937014f 100644
--- a/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTest.java
@@ -17,6 +17,8 @@
 package org.onosproject.ui.topo;
 
 import org.junit.Test;
+import org.onosproject.net.region.RegionId;
+import org.onosproject.ui.model.topo.UiLinkId;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -28,6 +30,10 @@
 
     private static final String EXP_ID_AB = "device-a/1-device-b/2";
 
+    private static final RegionId RA = RegionId.regionId("rA");
+    private static final RegionId RB = RegionId.regionId("rB");
+    private static final String EXP_RA_RB = "rA~rB";
+
     private BiLink blink;
 
     @Test
@@ -77,5 +83,17 @@
         print(blink);
         assertEquals("non-canon BA", expected, blink.linkId());
     }
+
+    @Test
+    public void uiLinkId() {
+        blink = new ConcreteLink(UiLinkId.uiLinkId(RA, RB));
+        print(blink);
+        assertEquals("non-canon AB", EXP_RA_RB, blink.linkId());
+
+        assertNull("key not null", blink.key());
+        assertNull("one not null", blink.one());
+        assertNull("two not null", blink.two());
+    }
+
 }
 
diff --git a/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTestBase.java b/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTestBase.java
index 77b6858..f713b81 100644
--- a/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTestBase.java
+++ b/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTestBase.java
@@ -25,6 +25,7 @@
 import org.onosproject.net.driver.Behaviour;
 import org.onosproject.net.provider.ProviderId;
 import org.onosproject.ui.AbstractUiTest;
+import org.onosproject.ui.model.topo.UiLinkId;
 
 /**
  * Base class for unit tests of {@link BiLink} and {@link BiLinkMap}.
@@ -110,6 +111,10 @@
             super(key, link);
         }
 
+        public ConcreteLink(UiLinkId uiLinkId) {
+            super(uiLinkId);
+        }
+
         @Override
         public LinkHighlight highlight(Enum<?> type) {
             return null;