ONOS-6259: Topo2 - Implement server-side highlighting model
- NOTE: Still WIP
- Implement doAggregation() in Traffic2Monitor.
- Plumb through call to get relevantSynthLinks().
- Create UiLinkId from LinkKey.
- Add reference to original UiLink in the UiSynthLink, (so we can use as a key later).
- TrafficLink enhancements:
-- Implement equals/hashCode
-- add a copy constructor
-- add mergeStats() method
-- add stats accessor methods

Change-Id: I693626971b3511b842e80cee7fcd2a252087597f
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLink.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLink.java
index 166a83a..f2643c6 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLink.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLink.java
@@ -29,6 +29,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import static com.google.common.base.MoreObjects.toStringHelper;
 import static org.onosproject.ui.topo.LinkHighlight.Flavor.NO_HIGHLIGHT;
 import static org.onosproject.ui.topo.LinkHighlight.Flavor.PRIMARY_HIGHLIGHT;
 import static org.onosproject.ui.topo.LinkHighlight.Flavor.SECONDARY_HIGHLIGHT;
@@ -70,6 +71,91 @@
     }
 
     /**
+     * Copy constructor.
+     *
+     * @param copy the instance to copy
+     */
+    public TrafficLink(TrafficLink copy) {
+        super(copy.key(), copy.one());
+        setOther(copy.two());
+        bytes = copy.bytes;
+        rate = copy.rate;
+        flows = copy.flows;
+        taggedFlavor = copy.taggedFlavor;
+        hasTraffic = copy.hasTraffic;
+        isOptical = copy.isOptical;
+        antMarch = copy.antMarch;
+        mods.addAll(copy.mods);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        TrafficLink that = (TrafficLink) o;
+
+        return bytes == that.bytes && rate == that.rate &&
+                flows == that.flows && hasTraffic == that.hasTraffic &&
+                isOptical == that.isOptical && antMarch == that.antMarch &&
+                taggedFlavor == that.taggedFlavor && mods.equals(that.mods);
+    }
+
+    @Override
+    public int hashCode() {
+        int result = (int) (bytes ^ (bytes >>> 32));
+        result = 31 * result + (int) (rate ^ (rate >>> 32));
+        result = 31 * result + (int) (flows ^ (flows >>> 32));
+        result = 31 * result + taggedFlavor.hashCode();
+        result = 31 * result + (hasTraffic ? 1 : 0);
+        result = 31 * result + (isOptical ? 1 : 0);
+        result = 31 * result + (antMarch ? 1 : 0);
+        result = 31 * result + mods.hashCode();
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("key", key())
+                .add("bytes", bytes)
+                .add("rate", rate)
+                .add("flows", flows)
+                .toString();
+    }
+
+    /**
+     * Returns the count of bytes.
+     *
+     * @return the byte count
+     */
+    public long bytes() {
+        return bytes;
+    }
+
+    /**
+     * Returns the rate.
+     *
+     * @return the rate
+     */
+    public long rate() {
+        return rate;
+    }
+
+    /**
+     * Returns the flows.
+     *
+     * @return flow count
+     */
+    public long flows() {
+        return flows;
+    }
+
+    /**
      * Sets the optical flag to the given value.
      *
      * @param b true if an optical link
@@ -149,6 +235,18 @@
         this.flows += count;
     }
 
+    /**
+     * Merges the load recorded on the given traffic link into this one.
+     *
+     * @param other the other traffic link
+     */
+    public void mergeStats(TrafficLink other) {
+        this.bytes += other.bytes;
+        this.rate += other.rate;
+        this.flows += other.flows;
+    }
+
+
     @Override
     public LinkHighlight highlight(Enum<?> type) {
         StatsType statsType = (StatsType) type;