Initial cut for UI topo model implementation.
- also moved existing classes down a package (to util).
Change-Id: Ie6c99ff10a3f4255795217a93f7028b5d8717d21
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/IntentSelection.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/IntentSelection.java
new file mode 100644
index 0000000..04724df
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/IntentSelection.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ui.impl.topo.util;
+
+import org.onosproject.net.intent.Intent;
+import org.onosproject.ui.topo.NodeSelection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Encapsulates a selection of intents (paths) inferred from a selection
+ * of devices and/or hosts from the topology view.
+ */
+public class IntentSelection {
+
+ private static final int ALL = -1;
+
+ protected static final Logger log =
+ LoggerFactory.getLogger(IntentSelection.class);
+
+ private final NodeSelection nodes;
+
+ private final List<Intent> intents;
+ private int index = ALL;
+
+ /**
+ * Creates an intent selection group, based on selected nodes.
+ *
+ * @param nodes node selection
+ * @param filter intent filter
+ */
+ public IntentSelection(NodeSelection nodes, TopoIntentFilter filter) {
+ this.nodes = nodes;
+ intents = filter.findPathIntents(nodes.hostsWithHover(), nodes.devicesWithHover());
+ if (intents.size() == 1) {
+ index = 0; // pre-select a single intent
+ }
+ }
+
+ /**
+ * Creates an intent selection group, for a single intent.
+ *
+ * @param intent the intent
+ */
+ public IntentSelection(Intent intent) {
+ nodes = null;
+ intents = new ArrayList<>(1);
+ intents.add(intent);
+ index = 0;
+ }
+
+ /**
+ * Returns true if no intents are selected.
+ *
+ * @return true if nothing selected
+ */
+ public boolean none() {
+ return intents.isEmpty();
+ }
+
+ /**
+ * Returns true if all intents in this select group are currently selected.
+ * This is the initial state, so that all intents are shown on the
+ * topology view with primary highlighting.
+ *
+ * @return true if all selected
+ */
+ public boolean all() {
+ return index == ALL;
+ }
+
+ /**
+ * Returns true if there is a single intent in this select group, or if
+ * a specific intent has been marked (index != ALL).
+ *
+ * @return true if single intent marked
+ */
+ public boolean single() {
+ return !all();
+ }
+
+ /**
+ * Returns the number of intents in this selection group.
+ *
+ * @return number of intents
+ */
+ public int size() {
+ return intents.size();
+ }
+
+ /**
+ * Returns the index of the currently selected intent.
+ *
+ * @return the current index
+ */
+ public int index() {
+ return index;
+ }
+
+ /**
+ * The list of intents in this selection group.
+ *
+ * @return list of intents
+ */
+ public List<Intent> intents() {
+ return Collections.unmodifiableList(intents);
+ }
+
+ /**
+ * Marks and returns the next intent in this group. Note that the
+ * selection wraps around to the beginning again, if necessary.
+ *
+ * @return the next intent in the group
+ */
+ public Intent next() {
+ index += 1;
+ if (index >= intents.size()) {
+ index = 0;
+ }
+ return intents.get(index);
+ }
+
+ /**
+ * Marks and returns the previous intent in this group. Note that the
+ * selection wraps around to the end again, if necessary.
+ *
+ * @return the previous intent in the group
+ */
+ public Intent prev() {
+ index -= 1;
+ if (index < 0) {
+ index = intents.size() - 1;
+ }
+ return intents.get(index);
+ }
+
+ /**
+ * Returns the currently marked intent, or null if "all" intents
+ * are marked.
+ *
+ * @return the currently marked intent
+ */
+ public Intent current() {
+ return all() ? null : intents.get(index);
+ }
+
+ @Override
+ public String toString() {
+ return "IntentSelection{" +
+ "nodes=" + nodes +
+ ", #intents=" + intents.size() +
+ ", index=" + index +
+ '}';
+ }
+
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/ServicesBundle.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/ServicesBundle.java
new file mode 100644
index 0000000..d78c01a
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/ServicesBundle.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ui.impl.topo.util;
+
+import org.onosproject.incubator.net.PortStatisticsService;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.intent.IntentService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.statistic.StatisticService;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A bundle of services that the topology view requires to get its job done.
+ */
+public class ServicesBundle {
+
+ private final IntentService intentService;
+ private final DeviceService deviceService;
+ private final HostService hostService;
+ private final LinkService linkService;
+ private final FlowRuleService flowService;
+ private final StatisticService flowStatsService;
+ private final PortStatisticsService portStatsService;
+
+ /**
+ * Creates the services bundle.
+ *
+ * @param intentService intent service reference
+ * @param deviceService device service reference
+ * @param hostService host service reference
+ * @param linkService link service reference
+ * @param flowService flow service reference
+ * @param flowStatsService flow statistics service reference
+ * @param portStatsService port statistics service reference
+ */
+ public ServicesBundle(IntentService intentService,
+ DeviceService deviceService,
+ HostService hostService,
+ LinkService linkService,
+ FlowRuleService flowService,
+ StatisticService flowStatsService,
+ PortStatisticsService portStatsService) {
+ this.intentService = checkNotNull(intentService);
+ this.deviceService = checkNotNull(deviceService);
+ this.hostService = checkNotNull(hostService);
+ this.linkService = checkNotNull(linkService);
+ this.flowService = checkNotNull(flowService);
+ this.flowStatsService = checkNotNull(flowStatsService);
+ this.portStatsService = checkNotNull(portStatsService);
+ }
+
+ /**
+ * Returns a reference to the intent service.
+ *
+ * @return intent service reference
+ */
+ public IntentService intentService() {
+ return intentService;
+ }
+
+ /**
+ * Returns a reference to the device service.
+ *
+ * @return device service reference
+ */
+ public DeviceService deviceService() {
+ return deviceService;
+ }
+
+ /**
+ * Returns a reference to the host service.
+ *
+ * @return host service reference
+ */
+ public HostService hostService() {
+ return hostService;
+ }
+
+ /**
+ * Returns a reference to the link service.
+ *
+ * @return link service reference
+ */
+ public LinkService linkService() {
+ return linkService;
+ }
+
+ /**
+ * Returns a reference to the flow rule service.
+ *
+ * @return flow service reference
+ */
+ public FlowRuleService flowService() {
+ return flowService;
+ }
+
+ /**
+ * Returns a reference to the flow statistics service.
+ *
+ * @return flow statistics service reference
+ */
+ public StatisticService flowStatsService() {
+ return flowStatsService;
+ }
+
+ /**
+ * Returns a reference to the port statistics service.
+ *
+ * @return port statistics service reference
+ */
+ public PortStatisticsService portStatsService() {
+ return portStatsService;
+ }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TopoIntentFilter.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TopoIntentFilter.java
new file mode 100644
index 0000000..c99453c
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TopoIntentFilter.java
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ui.impl.topo.util;
+
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.Link;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.intent.FlowObjectiveIntent;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.HostToHostIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentService;
+import org.onosproject.net.intent.LinkCollectionIntent;
+import org.onosproject.net.intent.MultiPointToSinglePointIntent;
+import org.onosproject.net.intent.OpticalConnectivityIntent;
+import org.onosproject.net.intent.PathIntent;
+import org.onosproject.net.intent.PointToPointIntent;
+import org.onosproject.net.link.LinkService;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+import static org.onosproject.net.intent.IntentState.INSTALLED;
+
+/**
+ * Auxiliary facility to query the intent service based on the specified
+ * set of end-station hosts, edge points or infrastructure devices.
+ */
+public class TopoIntentFilter {
+
+ private final IntentService intentService;
+ private final DeviceService deviceService;
+ private final HostService hostService;
+ private final LinkService linkService;
+
+ /**
+ * Creates an intent filter.
+ *
+ * @param services service references bundle
+ */
+ public TopoIntentFilter(ServicesBundle services) {
+ this.intentService = services.intentService();
+ this.deviceService = services.deviceService();
+ this.hostService = services.hostService();
+ this.linkService = services.linkService();
+ }
+
+ /**
+ * Finds all path (host-to-host or point-to-point) intents that pertain
+ * to the given hosts and devices.
+ *
+ * @param hosts set of hosts to query by
+ * @param devices set of devices to query by
+ * @return set of intents that 'match' all hosts and devices given
+ */
+ public List<Intent> findPathIntents(Set<Host> hosts, Set<Device> devices) {
+ // start with all intents
+ Iterable<Intent> sourceIntents = intentService.getIntents();
+
+ // Derive from this the set of edge connect points.
+ Set<ConnectPoint> edgePoints = getEdgePoints(hosts);
+
+ // Iterate over all intents and produce a set that contains only those
+ // intents that target all selected hosts or derived edge connect points.
+ return getIntents(hosts, devices, edgePoints, sourceIntents);
+ }
+
+
+ // Produces a set of edge points from the specified set of hosts.
+ private Set<ConnectPoint> getEdgePoints(Set<Host> hosts) {
+ Set<ConnectPoint> edgePoints = new HashSet<>();
+ for (Host host : hosts) {
+ edgePoints.add(host.location());
+ }
+ return edgePoints;
+ }
+
+ // Produces a list of intents that target all selected hosts, devices or connect points.
+ private List<Intent> getIntents(Set<Host> hosts, Set<Device> devices,
+ Set<ConnectPoint> edgePoints,
+ Iterable<Intent> sourceIntents) {
+ List<Intent> intents = new ArrayList<>();
+ if (hosts.isEmpty() && devices.isEmpty()) {
+ return intents;
+ }
+
+ Set<OpticalConnectivityIntent> opticalIntents = new HashSet<>();
+
+ // Search through all intents and see if they are relevant to our search.
+ for (Intent intent : sourceIntents) {
+ if (intentService.getIntentState(intent.key()) == INSTALLED) {
+ boolean isRelevant = false;
+ if (intent instanceof HostToHostIntent) {
+ isRelevant = isIntentRelevantToHosts((HostToHostIntent) intent, hosts) &&
+ isIntentRelevantToDevices(intent, devices);
+ } else if (intent instanceof PointToPointIntent) {
+ isRelevant = isIntentRelevant((PointToPointIntent) intent, edgePoints) &&
+ isIntentRelevantToDevices(intent, devices);
+ } else if (intent instanceof MultiPointToSinglePointIntent) {
+ isRelevant = isIntentRelevant((MultiPointToSinglePointIntent) intent, edgePoints) &&
+ isIntentRelevantToDevices(intent, devices);
+ } else if (intent instanceof OpticalConnectivityIntent) {
+ opticalIntents.add((OpticalConnectivityIntent) intent);
+ }
+ // TODO: add other intents, e.g. SinglePointToMultiPointIntent
+
+ if (isRelevant) {
+ intents.add(intent);
+ }
+ }
+ }
+
+ // As a second pass, try to link up any optical intents with the
+ // packet-level ones.
+ for (OpticalConnectivityIntent intent : opticalIntents) {
+ if (isIntentRelevant(intent, intents) &&
+ isIntentRelevantToDevices(intent, devices)) {
+ intents.add(intent);
+ }
+ }
+ return intents;
+ }
+
+ // Indicates whether the specified intent involves all of the given hosts.
+ private boolean isIntentRelevantToHosts(HostToHostIntent intent, Iterable<Host> hosts) {
+ for (Host host : hosts) {
+ HostId id = host.id();
+ // Bail if intent does not involve this host.
+ if (!id.equals(intent.one()) && !id.equals(intent.two())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Indicates whether the specified intent involves all of the given devices.
+ private boolean isIntentRelevantToDevices(Intent intent, Iterable<Device> devices) {
+ List<Intent> installables = intentService.getInstallableIntents(intent.key());
+ for (Device device : devices) {
+ if (!isIntentRelevantToDevice(installables, device)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Indicates whether the specified intent involves the given device.
+ private boolean isIntentRelevantToDevice(List<Intent> installables, Device device) {
+ if (installables != null) {
+ for (Intent installable : installables) {
+ if (installable instanceof PathIntent) {
+ PathIntent pathIntent = (PathIntent) installable;
+ if (pathContainsDevice(pathIntent.path().links(), device.id())) {
+ return true;
+ }
+ } else if (installable instanceof FlowRuleIntent) {
+ FlowRuleIntent flowRuleIntent = (FlowRuleIntent) installable;
+ if (rulesContainDevice(flowRuleIntent.flowRules(), device.id())) {
+ return true;
+ }
+ } else if (installable instanceof FlowObjectiveIntent) {
+ FlowObjectiveIntent objectiveIntent = (FlowObjectiveIntent) installable;
+ return objectiveIntent.devices().contains(device.id());
+
+ } else if (installable instanceof LinkCollectionIntent) {
+ LinkCollectionIntent linksIntent = (LinkCollectionIntent) installable;
+ if (pathContainsDevice(linksIntent.links(), device.id())) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ // Indicates whether the specified links involve the given device.
+ private boolean pathContainsDevice(Iterable<Link> links, DeviceId id) {
+ for (Link link : links) {
+ if (link.src().elementId().equals(id) || link.dst().elementId().equals(id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Indicates whether the specified flow rules involvesthe given device.
+ private boolean rulesContainDevice(Collection<FlowRule> flowRules, DeviceId id) {
+ for (FlowRule rule : flowRules) {
+ if (rule.deviceId().equals(id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isIntentRelevant(PointToPointIntent intent,
+ Iterable<ConnectPoint> edgePoints) {
+ for (ConnectPoint point : edgePoints) {
+ // Bail if intent does not involve this edge point.
+ if (!point.equals(intent.egressPoint()) &&
+ !point.equals(intent.ingressPoint())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Indicates whether the specified intent involves all of the given edge points.
+ private boolean isIntentRelevant(MultiPointToSinglePointIntent intent,
+ Iterable<ConnectPoint> edgePoints) {
+ for (ConnectPoint point : edgePoints) {
+ // Bail if intent does not involve this edge point.
+ if (!point.equals(intent.egressPoint()) &&
+ !intent.ingressPoints().contains(point)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Indicates whether the specified intent involves all of the given edge points.
+ private boolean isIntentRelevant(OpticalConnectivityIntent opticalIntent,
+ Iterable<Intent> intents) {
+ Link ccSrc = getFirstLink(opticalIntent.getSrc(), false);
+ Link ccDst = getFirstLink(opticalIntent.getDst(), true);
+ if (ccSrc == null || ccDst == null) {
+ return false;
+ }
+
+ for (Intent intent : intents) {
+ List<Intent> installables = intentService.getInstallableIntents(intent.key());
+ for (Intent installable : installables) {
+ if (installable instanceof PathIntent) {
+ List<Link> links = ((PathIntent) installable).path().links();
+ if (links.size() == 3) {
+ Link tunnel = links.get(1);
+ if (Objects.equals(tunnel.src(), ccSrc.src()) &&
+ Objects.equals(tunnel.dst(), ccDst.dst())) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private Link getFirstLink(ConnectPoint point, boolean ingress) {
+ for (Link link : linkService.getLinks(point)) {
+ if (point.equals(ingress ? link.src() : link.dst())) {
+ return link;
+ }
+ }
+ return null;
+ }
+}
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
new file mode 100644
index 0000000..3fd4099
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLink.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ui.impl.topo.util;
+
+import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
+import org.onosproject.net.statistic.Load;
+import org.onosproject.ui.topo.BiLink;
+import org.onosproject.ui.topo.LinkHighlight;
+import org.onosproject.ui.topo.LinkHighlight.Flavor;
+import org.onosproject.ui.topo.TopoUtils;
+
+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;
+
+/**
+ * Representation of a link and its inverse, and associated traffic data.
+ * This class understands how to generate the appropriate
+ * {@link LinkHighlight}s for showing traffic data on the topology view.
+ */
+public class TrafficLink extends BiLink {
+
+ private static final String EMPTY = "";
+ private static final String QUE = "?";
+
+ private long bytes = 0;
+ private long rate = 0;
+ private long flows = 0;
+ private Flavor taggedFlavor = NO_HIGHLIGHT;
+ private boolean hasTraffic = false;
+ private boolean isOptical = false;
+ private boolean antMarch = false;
+
+ /**
+ * Constructs a traffic link for the given key and initial link.
+ *
+ * @param key canonical key for this traffic link
+ * @param link first link
+ */
+ public TrafficLink(LinkKey key, Link link) {
+ super(key, link);
+ }
+
+ /**
+ * Sets the optical flag to the given value.
+ *
+ * @param b true if an optical link
+ * @return self, for chaining
+ */
+ public TrafficLink optical(boolean b) {
+ isOptical = b;
+ return this;
+ }
+
+ /**
+ * Sets the ant march flag to the given value.
+ *
+ * @param b true if marching ants required
+ * @return self, for chaining
+ */
+ public TrafficLink antMarch(boolean b) {
+ antMarch = b;
+ return this;
+ }
+
+ /**
+ * Tags this traffic link with the flavor to be used in visual rendering.
+ *
+ * @param flavor the flavor to tag
+ * @return self, for chaining
+ */
+ public TrafficLink tagFlavor(Flavor flavor) {
+ this.taggedFlavor = flavor;
+ return this;
+ }
+
+ /**
+ * Adds load statistics, marks the traffic link as having traffic.
+ *
+ * @param load load to add
+ */
+ public void addLoad(Load load) {
+ addLoad(load, 0);
+ }
+
+ /**
+ * Adds load statistics, marks the traffic link as having traffic, if the
+ * load {@link Load#rate rate} is greater than the given threshold
+ * (expressed in bytes per second).
+ *
+ * @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 traffic link.
+ *
+ * @param count count of flows
+ */
+ public void addFlows(int count) {
+ this.flows += count;
+ }
+
+ @Override
+ public LinkHighlight highlight(Enum<?> type) {
+ StatsType statsType = (StatsType) type;
+ switch (statsType) {
+ case FLOW_COUNT:
+ return highlightForFlowCount(statsType);
+
+ case FLOW_STATS:
+ case PORT_STATS:
+ return highlightForStats(statsType);
+
+ case TAGGED:
+ return highlightForTagging(statsType);
+
+ default:
+ throw new IllegalStateException("unexpected case: " + statsType);
+ }
+ }
+
+ private LinkHighlight highlightForStats(StatsType type) {
+ return new LinkHighlight(linkId(), SECONDARY_HIGHLIGHT)
+ .setLabel(generateLabel(type));
+ }
+
+ private LinkHighlight highlightForFlowCount(StatsType type) {
+ Flavor flavor = flows > 0 ? PRIMARY_HIGHLIGHT : SECONDARY_HIGHLIGHT;
+ return new LinkHighlight(linkId(), flavor)
+ .setLabel(generateLabel(type));
+ }
+
+ private LinkHighlight highlightForTagging(StatsType type) {
+ LinkHighlight hlite = new LinkHighlight(linkId(), taggedFlavor)
+ .setLabel(generateLabel(type));
+ if (isOptical) {
+ hlite.addMod(LinkHighlight.MOD_OPTICAL);
+ }
+ if (antMarch) {
+ hlite.addMod(LinkHighlight.MOD_ANIMATED);
+ }
+ return hlite;
+ }
+
+ // Generates a string representation of the load, to be used as a label
+ private String generateLabel(StatsType 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 QUE;
+ }
+ }
+
+ /**
+ * Returns true if this link has been deemed to have enough traffic
+ * to register on the topology view in the web UI.
+ *
+ * @return true if this link has displayable traffic
+ */
+ public boolean hasTraffic() {
+ return hasTraffic;
+ }
+
+ /**
+ * Designates type of traffic statistics to report on a highlighted link.
+ */
+ public enum StatsType {
+ /**
+ * Number of flows.
+ */
+ FLOW_COUNT,
+
+ /**
+ * Number of bytes.
+ */
+ FLOW_STATS,
+
+ /**
+ * Number of bits per second.
+ */
+ PORT_STATS,
+
+ /**
+ * Custom tagged information.
+ */
+ TAGGED
+ }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLinkMap.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLinkMap.java
new file mode 100644
index 0000000..e4c79e9
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/TrafficLinkMap.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ui.impl.topo.util;
+
+import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
+import org.onosproject.ui.topo.BiLinkMap;
+
+/**
+ * Collection of {@link TrafficLink}s.
+ */
+public class TrafficLinkMap extends BiLinkMap<TrafficLink> {
+
+ @Override
+ public TrafficLink create(LinkKey key, Link link) {
+ return new TrafficLink(key, link);
+ }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/package-info.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/package-info.java
new file mode 100644
index 0000000..80be5eb
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/util/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Topology resources for the ONOS GUI.
+ */
+package org.onosproject.ui.impl.topo.util;