ONOS-1479 -- GUI - augmenting topology view for extensibility: WIP.
- Major refactoring of TopologyViewMessageHandler and related classes.

Change-Id: I920f7f9f7317f3987a9a8da35ac086e9f8cab8d3
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
new file mode 100644
index 0000000..5ab4e0e
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/BiLink.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright 2015 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;
+
+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;
+
+/**
+ * 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.
+ */
+public class BiLink {
+
+    private static final String EMPTY = "";
+
+    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.
+     *
+     * @param key canonical key for this bilink
+     * @param link first link
+     */
+    public BiLink(LinkKey key, Link link) {
+        this.key = key;
+        this.one = link;
+    }
+
+    /**
+     * Sets the second link for this bilink.
+     *
+     * @param link second link
+     */
+    public void setOther(Link link) {
+        this.two = link;
+    }
+
+    /**
+     * Sets the optical flag to the given value.
+     *
+     * @param b true if an optical link
+     */
+    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() {
+        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
+
+    public LinkKey key() {
+        return key;
+    }
+
+    public Link one() {
+        return one;
+    }
+
+    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;
+    }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/IntentSelection.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/IntentSelection.java
new file mode 100644
index 0000000..eb959c5
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/IntentSelection.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2015 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;
+
+import org.onosproject.net.intent.Intent;
+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, TopologyViewIntentFilter filter) {
+        this.nodes = nodes;
+        intents = filter.findPathIntents(nodes.hosts(), nodes.devices());
+    }
+
+    /**
+     * 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/LinkStatsType.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/LinkStatsType.java
new file mode 100644
index 0000000..589cddd
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/LinkStatsType.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 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;
+
+/**
+ * Designates type of stats to report on a highlighted link.
+ */
+public enum LinkStatsType {
+    /**
+     * 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/NodeSelection.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/NodeSelection.java
new file mode 100644
index 0000000..fa776b3
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/NodeSelection.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2015 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;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.net.Device;
+import org.onosproject.net.Host;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.host.HostService;
+import org.onosproject.ui.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.net.HostId.hostId;
+
+/**
+ * Encapsulates a selection of devices and/or hosts from the topology view.
+ */
+public class NodeSelection {
+
+    protected static final Logger log =
+            LoggerFactory.getLogger(NodeSelection.class);
+
+    private static final String IDS = "ids";
+    private static final String HOVER = "hover";
+
+    private final DeviceService deviceService;
+    private final HostService hostService;
+
+    private final Set<String> ids;
+    private final String hover;
+
+    private final Set<Device> devices = new HashSet<>();
+    private final Set<Host> hosts = new HashSet<>();
+
+    /**
+     * Creates a node selection entity, from the given payload, using the
+     * supplied device and host services.
+     *
+     * @param payload message payload
+     * @param deviceService device service
+     * @param hostService host service
+     */
+    public NodeSelection(ObjectNode payload,
+                         DeviceService deviceService,
+                         HostService hostService) {
+        this.deviceService = deviceService;
+        this.hostService = hostService;
+
+        ids = extractIds(payload);
+        hover = extractHover(payload);
+
+        Set<String> unmatched = findDevices(ids);
+        unmatched = findHosts(unmatched);
+        if (unmatched.size() > 0) {
+            log.debug("Skipping unmatched IDs {}", unmatched);
+        }
+
+        if (!isNullOrEmpty(hover)) {
+            unmatched = new HashSet<>();
+            unmatched.add(hover);
+            unmatched = findDevices(unmatched);
+            unmatched = findHosts(unmatched);
+            if (unmatched.size() > 0) {
+                log.debug("Skipping unmatched HOVER {}", unmatched);
+            }
+        }
+    }
+
+    /**
+     * Returns a view of the selected devices.
+     *
+     * @return selected devices
+     */
+    public Set<Device> devices() {
+        return Collections.unmodifiableSet(devices);
+    }
+
+    /**
+     * Returns a view of the selected hosts.
+     *
+     * @return selected hosts
+     */
+    public Set<Host> hosts() {
+        return Collections.unmodifiableSet(hosts);
+    }
+
+    /**
+     * Returns true if nothing is selected.
+     *
+     * @return true if nothing selected
+     */
+    public boolean none() {
+        return devices().size() == 0 && hosts().size() == 0;
+    }
+
+    @Override
+    public String toString() {
+        return "NodeSelection{" +
+                "ids=" + ids +
+                ", hover='" + hover + '\'' +
+                ", #devices=" + devices.size() +
+                ", #hosts=" + hosts.size() +
+                '}';
+    }
+
+    // == helper methods
+
+    private Set<String> extractIds(ObjectNode payload) {
+        ArrayNode array = (ArrayNode) payload.path(IDS);
+        if (array == null || array.size() == 0) {
+            return Collections.emptySet();
+        }
+
+        Set<String> ids = new HashSet<>();
+        for (JsonNode node : array) {
+            ids.add(node.asText());
+        }
+        return ids;
+    }
+
+    private String extractHover(ObjectNode payload) {
+        return JsonUtils.string(payload, HOVER);
+    }
+
+    private Set<String> findDevices(Set<String> ids) {
+        Set<String> unmatched = new HashSet<>();
+        Device device;
+
+        for (String id : ids) {
+            try {
+                device = deviceService.getDevice(deviceId(id));
+                if (device != null) {
+                    devices.add(device);
+                } else {
+                    log.debug("Device with ID {} not found", id);
+                }
+            } catch (IllegalArgumentException e) {
+                unmatched.add(id);
+            }
+        }
+        return unmatched;
+    }
+
+    private Set<String> findHosts(Set<String> ids) {
+        Set<String> unmatched = new HashSet<>();
+        Host host;
+
+        for (String id : ids) {
+            try {
+                host = hostService.getHost(hostId(id));
+                if (host != null) {
+                    hosts.add(host);
+                } else {
+                    log.debug("Host with ID {} not found", id);
+                }
+            } catch (IllegalArgumentException e) {
+                unmatched.add(id);
+            }
+        }
+        return unmatched;
+    }
+
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/ServicesBundle.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/ServicesBundle.java
new file mode 100644
index 0000000..4282cdc
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/ServicesBundle.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2015 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;
+
+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);
+    }
+
+    public IntentService intentService() {
+        return intentService;
+    }
+
+    public DeviceService deviceService() {
+        return deviceService;
+    }
+
+    public HostService hostService() {
+        return hostService;
+    }
+
+    public LinkService linkService() {
+        return linkService;
+    }
+
+    public FlowRuleService flowService() {
+        return flowService;
+    }
+
+    public StatisticService flowStatsService() {
+        return flowStatsService;
+    }
+
+    public PortStatisticsService portStatsService() {
+        return portStatsService;
+    }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoUtils.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoUtils.java
new file mode 100644
index 0000000..8d6b319
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopoUtils.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2015 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;
+
+import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
+
+import java.text.DecimalFormat;
+import java.util.Map;
+
+import static org.onosproject.net.LinkKey.linkKey;
+
+/**
+ * Utility methods for helping out with the topology view.
+ */
+public final class TopoUtils {
+
+    public static final double KILO = 1024;
+    public static final double MEGA = 1024 * KILO;
+    public static final double GIGA = 1024 * MEGA;
+
+    public static final String GBITS_UNIT = "Gb";
+    public static final String MBITS_UNIT = "Mb";
+    public static final String KBITS_UNIT = "Kb";
+    public static final String BITS_UNIT = "b";
+    public static final String GBYTES_UNIT = "GB";
+    public static final String MBYTES_UNIT = "MB";
+    public static final String KBYTES_UNIT = "KB";
+    public static final String BYTES_UNIT = "B";
+
+
+    private static final DecimalFormat DF2 = new DecimalFormat("#,###.##");
+
+    private static final String COMPACT = "%s/%s-%s/%s";
+    private static final String EMPTY = "";
+    private static final String SPACE = " ";
+    private static final String PER_SEC = "ps";
+    private static final String FLOW = "flow";
+    private static final String FLOWS = "flows";
+
+    // non-instantiable
+    private TopoUtils() { }
+
+    /**
+     * Returns a compact identity for the given link, in the form
+     * used to identify links in the Topology View on the client.
+     *
+     * @param link link
+     * @return compact link identity
+     */
+    public static String compactLinkString(Link link) {
+        return String.format(COMPACT, link.src().elementId(), link.src().port(),
+                             link.dst().elementId(), link.dst().port());
+    }
+
+    /**
+     * Produces a canonical link key, that is, one that will match both a link
+     * and its inverse.
+     *
+     * @param link the link
+     * @return canonical key
+     */
+    public static LinkKey canonicalLinkKey(Link link) {
+        String sn = link.src().elementId().toString();
+        String dn = link.dst().elementId().toString();
+        return sn.compareTo(dn) < 0 ?
+                linkKey(link.src(), link.dst()) : linkKey(link.dst(), link.src());
+    }
+
+    /**
+     * Returns human readable count of bytes, to be displayed as a label.
+     *
+     * @param bytes number of bytes
+     * @return formatted byte count
+     */
+    public static String formatBytes(long bytes) {
+        String unit;
+        double value;
+        if (bytes > GIGA) {
+            value = bytes / GIGA;
+            unit = GBYTES_UNIT;
+        } else if (bytes > MEGA) {
+            value = bytes / MEGA;
+            unit = MBYTES_UNIT;
+        } else if (bytes > KILO) {
+            value = bytes / KILO;
+            unit = KBYTES_UNIT;
+        } else {
+            value = bytes;
+            unit = BYTES_UNIT;
+        }
+        return DF2.format(value) + SPACE + unit;
+    }
+
+    /**
+     * Returns human readable bit rate, to be displayed as a label.
+     *
+     * @param bytes bytes per second
+     * @return formatted bits per second
+     */
+    public static String formatBitRate(long bytes) {
+        String unit;
+        double value;
+
+        //Convert to bits
+        long bits = bytes * 8;
+        if (bits > GIGA) {
+            value = bits / GIGA;
+            unit = GBITS_UNIT;
+
+            // NOTE: temporary hack to clip rate at 10.0 Gbps
+            //  Added for the CORD Fabric demo at ONS 2015
+            // TODO: provide a more elegant solution to this issue
+            if (value > 10.0) {
+                value = 10.0;
+            }
+
+        } else if (bits > MEGA) {
+            value = bits / MEGA;
+            unit = MBITS_UNIT;
+        } else if (bits > KILO) {
+            value = bits / KILO;
+            unit = KBITS_UNIT;
+        } else {
+            value = bits;
+            unit = BITS_UNIT;
+        }
+        return DF2.format(value) + SPACE + unit + PER_SEC;
+    }
+
+    /**
+     * Returns human readable flow count, to be displayed as a label.
+     *
+     * @param flows number of flows
+     * @return formatted flow count
+     */
+    public static String formatFlows(long flows) {
+        if (flows < 1) {
+            return EMPTY;
+        }
+        return String.valueOf(flows) + SPACE + (flows > 1 ? FLOWS : FLOW);
+    }
+
+
+    /**
+     * Creates a new biLink with the supplied link (and adds it to the map),
+     * or attaches the link to an existing biLink (which already has the
+     * peer link).
+     *
+     * @param linkMap map of biLinks
+     * @param link the link to add
+     * @return the biLink to which the link was added
+     */
+    // creates a new biLink with supplied link, or attaches link to the
+    //  existing biLink (which already has its peer link)
+    public static BiLink addLink(Map<LinkKey, BiLink> linkMap, Link link) {
+        LinkKey key = TopoUtils.canonicalLinkKey(link);
+        BiLink biLink = linkMap.get(key);
+        if (biLink != null) {
+            biLink.setOther(link);
+        } else {
+            biLink = new BiLink(key, link);
+            linkMap.put(key, biLink);
+        }
+        return biLink;
+    }
+
+
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopologyViewIntentFilter.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopologyViewIntentFilter.java
new file mode 100644
index 0000000..1bd2b58
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TopologyViewIntentFilter.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright 2014-2015 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;
+
+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.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 TopologyViewIntentFilter {
+
+    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 TopologyViewIntentFilter(ServicesBundle services) {
+        this.intentService = services.intentService();
+        this.deviceService = services.deviceService();
+        this.hostService = services.hostService();
+        this.linkService = services.linkService();
+    }
+
+
+    // TODO: Review - do we need this signature, with sourceIntents??
+//    public List<Intent> findPathIntents(Set<Host> hosts, Set<Device> devices,
+//                                        Iterable<Intent> sourceIntents) {
+//    }
+
+    /**
+     * 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 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/TrafficClass.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TrafficClass.java
new file mode 100644
index 0000000..1389aba
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/TrafficClass.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2015 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;
+
+import org.onosproject.net.intent.Intent;
+import org.onosproject.ui.topo.LinkHighlight;
+
+/**
+ * Auxiliary data carrier for assigning a highlight class to a set of
+ * intents, for visualization in the topology view.
+ */
+public class TrafficClass {
+
+    private final LinkHighlight.Flavor flavor;
+    private final Iterable<Intent> intents;
+    private final boolean showTraffic;
+
+    public TrafficClass(LinkHighlight.Flavor flavor, Iterable<Intent> intents) {
+        this(flavor, intents, false);
+    }
+
+    public TrafficClass(LinkHighlight.Flavor flavor, Iterable<Intent> intents,
+                        boolean showTraffic) {
+        this.flavor = flavor;
+        this.intents = intents;
+        this.showTraffic = showTraffic;
+    }
+
+    public LinkHighlight.Flavor flavor() {
+        return flavor;
+    }
+
+    public Iterable<Intent> intents() {
+        return intents;
+    }
+
+    public boolean showTraffic() {
+        return showTraffic;
+    }
+}