ONOS-2186 - GUI Topo Overlay - (WIP)
- split BiLink into abstract superclass and concrete subclasses.
- created BiLinkMap to collate bilinks (and derivative subclasses).
- added missing Javadocs, and other general cleanup.
Change-Id: Icfa85bc44a223c6cf245a4005170583dad1cc801
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/BiLink.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/BiLink.java
index 5ab4e0e..8ccf543 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/BiLink.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/BiLink.java
@@ -19,226 +19,87 @@
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
-import org.onosproject.net.statistic.Load;
import org.onosproject.ui.topo.LinkHighlight;
-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;
+import static com.google.common.base.Preconditions.checkNotNull;
/**
- * Representation of a link and its inverse, and any associated traffic data.
- * This class understands how to generate {@link LinkHighlight}s for sending
- * back to the topology view.
+ * Representation of a link and its inverse, as a partial implementation.
+ * <p>
+ * Subclasses will decide how to generate the link highlighting (coloring
+ * and labeling) for the topology view.
*/
-public class BiLink {
-
- private static final String EMPTY = "";
+public abstract class BiLink {
private final LinkKey key;
private final Link one;
private Link two;
- private boolean hasTraffic = false;
- private long bytes = 0;
- private long rate = 0;
- private long flows = 0;
- private boolean isOptical = false;
- private LinkHighlight.Flavor taggedFlavor = NO_HIGHLIGHT;
- private boolean antMarch = false;
-
/**
- * Constructs a bilink for the given key and initial link.
+ * Constructs a bi-link for the given key and initial link. It is expected
+ * that the caller will have used {@link TopoUtils#canonicalLinkKey(Link)}
+ * to generate the key.
*
- * @param key canonical key for this bilink
+ * @param key canonical key for this bi-link
* @param link first link
*/
public BiLink(LinkKey key, Link link) {
- this.key = key;
- this.one = link;
+ this.key = checkNotNull(key);
+ this.one = checkNotNull(link);
}
/**
- * Sets the second link for this bilink.
+ * Sets the second link for this bi-link.
*
* @param link second link
*/
public void setOther(Link link) {
- this.two = link;
+ this.two = checkNotNull(link);
}
/**
- * Sets the optical flag to the given value.
+ * Returns the link identifier in the form expected on the Topology View
+ * in the web client.
*
- * @param b true if an optical link
+ * @return link identifier
*/
- public void setOptical(boolean b) {
- isOptical = b;
- }
-
- /**
- * Sets the ant march flag to the given value.
- *
- * @param b true if marching ants required
- */
- public void setAntMarch(boolean b) {
- antMarch = b;
- }
-
- /**
- * Tags this bilink with a link flavor to be used in visual rendering.
- *
- * @param flavor the flavor to tag
- */
- public void tagFlavor(LinkHighlight.Flavor flavor) {
- this.taggedFlavor = flavor;
- }
-
- /**
- * Adds load statistics, marks the bilink as having traffic.
- *
- * @param load load to add
- */
- public void addLoad(Load load) {
- addLoad(load, 0);
- }
-
- /**
- * Adds load statistics, marks the bilink as having traffic, if the
- * load rate is greater than the given threshold.
- *
- * @param load load to add
- * @param threshold threshold to register traffic
- */
- public void addLoad(Load load, double threshold) {
- if (load != null) {
- this.hasTraffic = hasTraffic || load.rate() > threshold;
- this.bytes += load.latest();
- this.rate += load.rate();
- }
- }
-
- /**
- * Adds the given count of flows to this bilink.
- *
- * @param count count of flows
- */
- public void addFlows(int count) {
- this.flows += count;
- }
-
- /**
- * Generates a link highlight entity, based on state of this bilink.
- *
- * @param type the type of statistics to use to interpret the data
- * @return link highlight data for this bilink
- */
- public LinkHighlight generateHighlight(LinkStatsType type) {
- switch (type) {
- case FLOW_COUNT:
- return highlightForFlowCount(type);
-
- case FLOW_STATS:
- case PORT_STATS:
- return highlightForStats(type);
-
- case TAGGED:
- return highlightForTagging(type);
-
- default:
- throw new IllegalStateException("unexpected case: " + type);
- }
- }
-
- private LinkHighlight highlightForStats(LinkStatsType type) {
- return new LinkHighlight(linkId(), SECONDARY_HIGHLIGHT)
- .setLabel(generateLabel(type));
- }
-
- private LinkHighlight highlightForFlowCount(LinkStatsType type) {
- LinkHighlight.Flavor flavor = flows() > 0 ?
- PRIMARY_HIGHLIGHT : SECONDARY_HIGHLIGHT;
- return new LinkHighlight(linkId(), flavor)
- .setLabel(generateLabel(type));
- }
-
- private LinkHighlight highlightForTagging(LinkStatsType type) {
- LinkHighlight hlite = new LinkHighlight(linkId(), flavor())
- .setLabel(generateLabel(type));
- if (isOptical()) {
- hlite.addMod(LinkHighlight.MOD_OPTICAL);
- }
- if (isAntMarch()) {
- hlite.addMod(LinkHighlight.MOD_ANIMATED);
- }
- return hlite;
- }
-
- // Generates a link identifier in the form that the Topology View on the
- private String linkId() {
+ public String linkId() {
return TopoUtils.compactLinkString(one);
}
- // Generates a string representation of the load, to be used as a label
- private String generateLabel(LinkStatsType type) {
- switch (type) {
- case FLOW_COUNT:
- return TopoUtils.formatFlows(flows());
-
- case FLOW_STATS:
- return TopoUtils.formatBytes(bytes());
-
- case PORT_STATS:
- return TopoUtils.formatBitRate(rate());
-
- case TAGGED:
- return hasTraffic() ? TopoUtils.formatBytes(bytes()) : EMPTY;
-
- default:
- return "?";
- }
- }
-
- // === ----------------------------------------------------------------
- // accessors
-
+ /**
+ * Returns the key for this bi-link.
+ *
+ * @return the key
+ */
public LinkKey key() {
return key;
}
+ /**
+ * Returns the first link in this bi-link.
+ *
+ * @return the first link
+ */
public Link one() {
return one;
}
+ /**
+ * Returns the second link in this bi-link.
+ *
+ * @return the second link
+ */
public Link two() {
return two;
}
- public boolean hasTraffic() {
- return hasTraffic;
- }
-
- public boolean isOptical() {
- return isOptical;
- }
-
- public boolean isAntMarch() {
- return antMarch;
- }
-
- public LinkHighlight.Flavor flavor() {
- return taggedFlavor;
- }
-
- public long bytes() {
- return bytes;
- }
-
- public long rate() {
- return rate;
- }
-
- public long flows() {
- return flows;
- }
+ /**
+ * Returns the link highlighting to use, based on this bi-link's current
+ * state.
+ *
+ * @param type optional highlighting type parameter
+ * @return link highlighting model
+ */
+ public abstract LinkHighlight highlight(Enum<?> type);
}