Added mechanism for apps to easily add their own custom link/node/host highlighting wihout having to create a new UI extensions
Change-Id: Iefa21d76190c60db79a4b07a8b22e301d29fe58e
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java
index 2f14ac4..ae3c909 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitorBase.java
@@ -38,6 +38,9 @@
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.statistic.Load;
+import org.onosproject.ui.UiExtensionService;
+import org.onosproject.ui.UiTopoHighlighter;
+import org.onosproject.ui.UiTopoHighlighterFactory;
import org.onosproject.ui.impl.topo.TopoologyTrafficMessageHandlerAbstract;
import org.onosproject.ui.impl.topo.util.IntentSelection;
import org.onosproject.ui.impl.topo.util.ServicesBundle;
@@ -69,8 +72,7 @@
import static org.onosproject.net.statistic.PortStatisticsService.MetricType.BYTES;
import static org.onosproject.net.statistic.PortStatisticsService.MetricType.PACKETS;
import static org.onosproject.net.DefaultEdgeLink.createEdgeLinks;
-import static org.onosproject.ui.impl.TrafficMonitorBase.Mode.IDLE;
-import static org.onosproject.ui.impl.TrafficMonitorBase.Mode.SELECTED_INTENT;
+import static org.onosproject.ui.impl.TrafficMonitorBase.Mode.*;
/**
* Base superclass for traffic monitor (both 'classic' and 'topo2' versions).
@@ -85,6 +87,7 @@
protected IntentSelection selectedIntents = null;
protected final TopoologyTrafficMessageHandlerAbstract msgHandler;
protected NodeSelection selectedNodes = null;
+ protected UiTopoHighlighter topoHighlighter = null;
protected void sendSelectedIntents() {
log.debug("sendSelectedIntents: {}", selectedIntents);
@@ -285,7 +288,8 @@
ALL_PORT_TRAFFIC_PKT_PS,
DEV_LINK_FLOWS,
RELATED_INTENTS,
- SELECTED_INTENT
+ SELECTED_INTENT,
+ CUSTOM_TRAFFIC_MONITOR
}
/**
@@ -375,6 +379,22 @@
}
}
+
+ public synchronized void monitor(int index) {
+ mode = CUSTOM_TRAFFIC_MONITOR;
+ List<UiTopoHighlighterFactory> factories = services.get(UiExtensionService.class)
+ .getTopoHighlighterFactories();
+ if (factories.isEmpty()) {
+ return;
+ }
+
+ UiTopoHighlighterFactory factory = factories.get(index % factories.size());
+ topoHighlighter = factory.newTopoHighlighter();
+ clearSelection();
+ scheduleTask();
+ sendCustomTraffic();
+ }
+
/**
* Monitor for traffic data to be sent back to the web client, under
* the given mode, using the given selection of devices and hosts.
@@ -474,6 +494,12 @@
protected abstract void sendSelectedIntentTraffic();
/**
+ * Subclass should compile and send appropriate highlights data showing
+ * custom traffic on links.
+ */
+ protected abstract void sendCustomTraffic();
+
+ /**
* Subclass should send a "clear highlights" event.
*/
protected abstract void sendClearHighlights();
@@ -712,6 +738,9 @@
case SELECTED_INTENT:
sendSelectedIntentTraffic();
break;
+ case CUSTOM_TRAFFIC_MONITOR:
+ sendCustomTraffic();
+ break;
default:
// RELATED_INTENTS and IDLE modes should never invoke