ONOS-6258: UiTopo2Overlay et al.
- Added Topo2TrafficMessageHandler
- Wired topo2 traffic overlay into topo2 view
Change-Id: I2b67af6abc10f737b8d3183d219d8c651bf57e31
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
index 6bab13e..5e36357 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
@@ -56,6 +56,7 @@
import org.onosproject.ui.UiTopoOverlayFactory;
import org.onosproject.ui.UiView;
import org.onosproject.ui.UiViewHidden;
+import org.onosproject.ui.impl.topo.Topo2TrafficMessageHandler;
import org.onosproject.ui.impl.topo.Topo2ViewMessageHandler;
import org.onosproject.ui.impl.topo.Traffic2Overlay;
import org.slf4j.Logger;
@@ -151,6 +152,7 @@
new UserPreferencesMessageHandler(),
new TopologyViewMessageHandler(),
new Topo2ViewMessageHandler(),
+ new Topo2TrafficMessageHandler(),
new MapSelectorMessageHandler(),
new DeviceViewMessageHandler(),
new LinkViewMessageHandler(),
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
index c302c6b..2179f42 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
@@ -296,6 +296,10 @@
overlayCache.destroy();
overlayCache = null;
}
+ if (overlay2Cache != null) {
+ overlay2Cache.destroy();
+ overlay2Cache = null;
+ }
}
// Sends initial information (username and cluster member information)
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2TrafficMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2TrafficMessageHandler.java
new file mode 100644
index 0000000..8a6ec8b
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2TrafficMessageHandler.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2017-present 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.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onlab.osgi.ServiceDirectory;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiConnection;
+import org.onosproject.ui.UiMessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+
+/**
+ * Server-side component to handle messages pertaining to topo-2 traffic.
+ */
+public class Topo2TrafficMessageHandler extends UiMessageHandler {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ // === Inbound event identifiers
+ private static final String REQUEST_ALL_TRAFFIC = "topo2RequestAllTraffic";
+ private static final String CANCEL_TRAFFIC = "topo2CancelTraffic";
+
+ // === Outbound event identifiers
+ private static final String HIGHLIGHTS = "topo2Highlights";
+
+// private UiTopoSession topoSession;
+// private Topo2Jsonifier t2json;
+
+ @Override
+ public void init(UiConnection connection, ServiceDirectory directory) {
+ super.init(connection, directory);
+
+ // get the topo session from the UiWebSocket
+// topoSession = ((UiWebSocket) connection).topoSession();
+// t2json = new Topo2Jsonifier(directory, connection.userName());
+
+ }
+
+ @Override
+ protected Collection<RequestHandler> createRequestHandlers() {
+ return ImmutableSet.of(
+ new Topo2AllTraffic(),
+ new Topo2CancelTraffic()
+ );
+ }
+
+ // ==================================================================
+
+ private final class Topo2AllTraffic extends RequestHandler {
+ private Topo2AllTraffic() {
+ super(REQUEST_ALL_TRAFFIC);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ String mode = string(payload, "trafficType");
+ log.debug("SHOW TRAFFIC: " + mode);
+ switch (mode) {
+ case "flowStatsBytes":
+ // TODO: invoke traffic monitor for flow stats / bytes
+ break;
+
+ case "portStatsBitSec":
+ // TODO: invoke traffic monitor for port stats / bps
+ break;
+
+ case "portStatsPktSec":
+ // TODO: invoke traffic monitor for port stats / pps
+ break;
+
+ default:
+ log.warn("Unknown traffic monitor type: " + mode);
+ break;
+ }
+ }
+ }
+
+ private final class Topo2CancelTraffic extends RequestHandler {
+ private Topo2CancelTraffic() {
+ super(CANCEL_TRAFFIC);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ log.debug("CANCEL TRAFFIC");
+ // TODO: tell traffic monitor to quit monitoring traffic
+ }
+ }
+}
+
+
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2.js b/web/gui/src/main/webapp/app/view/topo2/topo2.js
index c798927..cf13d11 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2.js
@@ -101,7 +101,7 @@
'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
'Topo2MapConfigService', 'Topo2ZoomService', 'Topo2SpriteLayerService',
'Topo2SummaryPanelService', 'Topo2DeviceDetailsPanel', 'Topo2ToolbarService',
- 'Topo2NoDevicesConnectedService',
+ 'Topo2NoDevicesConnectedService', 'Topo2OverlayService',
function (
_$scope_, _$log_, _$loc_,
@@ -111,7 +111,7 @@
_t2es_, _t2fs_, _t2is_,
_t2bcs_, _t2kcs_, _t2ms_,
_t2mcs_, _t2zs_, t2sls,
- summaryPanel, detailsPanel, t2tbs, t2ndcs
+ summaryPanel, detailsPanel, t2tbs, t2ndcs, t2os
) {
var params = _$loc_.search(),
dim,
@@ -198,6 +198,9 @@
// restoreConfigFromPrefs();
// ttbs.setDefaultOverlay(prefsState.ovid);
+ // ++ TEMPORARY HARD-CODE TRAFFIC OVERLAY ++
+ t2os.setOverlay('traffic-2-overlay');
+
summaryPanel.init(detailsPanel);
detailsPanel.init(summaryPanel);
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2KeyCommands.js b/web/gui/src/main/webapp/app/view/topo2/topo2KeyCommands.js
index a9c9c1c..939b9d2 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2KeyCommands.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2KeyCommands.js
@@ -40,7 +40,7 @@
_keyListener: t2tbs.keyListener.bind(t2tbs)
}
- };
+ }
function init(_t2fs_, _t2tbs_) {
t2fs = _t2fs_;
@@ -48,9 +48,26 @@
bindCommands();
}
- function bindCommands() {
+ function bindCommands(additional) {
- ks.keyBindings(actionMap());
+ var am = actionMap(),
+ add = fs.isO(additional);
+
+ if (add) {
+ _.each(add, function (value, key) {
+ // filter out meta properties (e.g. _keyOrder)
+ if (!(key.startsWith('_'))) {
+ // don't allow re-definition of existing key bindings
+ if (am[key]) {
+ $log.warn('keybind: ' + key + ' already exists');
+ } else {
+ am[key] = [value.cb, value.tt];
+ }
+ }
+ });
+ }
+
+ ks.keyBindings(am);
ks.gestureNotes([
['click', 'Select the item and show details'],
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js b/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
index ce662fb..808ee69 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
@@ -22,7 +22,7 @@
var t2os = 'Topo2OverlayService: ';
// injected refs
- var $log, $timeout, fs, gs, wss, api;
+ var $log, $timeout, fs, gs, wss, t2kcs, api;
// internal state
var overlays = {},
@@ -123,6 +123,16 @@
api = _api_;
}
+ function setOverlay(ovid) {
+ var ov = overlays[ovid];
+ if (!ov) {
+ $log.error('setOverlay: no such overlay ID: ' + ovid);
+ } else {
+ current = ov;
+ t2kcs.bindCommands(current.keyBindings);
+ }
+ }
+
function showHighlights(data) {
function doHighlight() {
_showHighlights(data);
@@ -152,17 +162,20 @@
angular.module('ovTopo2')
.factory('Topo2OverlayService', [
'$log', '$timeout', 'FnService', 'GlyphService', 'WebSocketService',
+ 'Topo2KeyCommandService',
- function (_$log_, _$timeout_, _fs_, _gs_, _wss_) {
+ function (_$log_, _$timeout_, _fs_, _gs_, _wss_, _t2kcs_) {
$log = _$log_;
$timeout = _$timeout_;
fs = _fs_;
gs = _gs_;
wss = _wss_;
+ t2kcs = _t2kcs_;
return {
register: register,
setApi: setApi,
+ setOverlay: setOverlay,
hooks: {
escape: escapeHook,
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Toolbar.js b/web/gui/src/main/webapp/app/view/topo2/topo2Toolbar.js
index 620d2c6..1edcdff 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Toolbar.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Toolbar.js
@@ -1,5 +1,22 @@
+/*
+ * Copyright 2017-present 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.
+ *
+ */
+
(function () {
- 'use-strict';
+ 'use strict';
var instance;
@@ -109,4 +126,4 @@
return instance || new Toolbar();
}
]);
-})();
\ No newline at end of file
+}());
\ No newline at end of file
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Traffic.js b/web/gui/src/main/webapp/app/view/topo2/topo2Traffic.js
index 4515b8a..6ca4d5e 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Traffic.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Traffic.js
@@ -52,7 +52,7 @@
}
function showAllTraffic() {
- $log.debug('Topo2Traffic: Show All Traffic');
+ $log.debug('Topo2Traffic: Show All Traffic:', allTrafficTypes[allIndex]);
mode = 'allFlowPort';
wss.sendEvent('topo2RequestAllTraffic', {