ONOS-6258: UiTopo2Overlay et al.
- revert DriverMatrix app.
- simplify overlay base class to be consistent with classic topo
- add topo2overlay and topo2traffic (skeleton code for now)
Change-Id: I88fda4d7b75807bd08637d846a869846a364c1f8
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 02d0808..6bab13e 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
@@ -50,12 +50,14 @@
import org.onosproject.ui.UiExtensionService;
import org.onosproject.ui.UiMessageHandlerFactory;
import org.onosproject.ui.UiPreferencesService;
+import org.onosproject.ui.UiTopo2OverlayFactory;
import org.onosproject.ui.UiTopoMap;
import org.onosproject.ui.UiTopoMapFactory;
import org.onosproject.ui.UiTopoOverlayFactory;
import org.onosproject.ui.UiView;
import org.onosproject.ui.UiViewHidden;
import org.onosproject.ui.impl.topo.Topo2ViewMessageHandler;
+import org.onosproject.ui.impl.topo.Traffic2Overlay;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -172,6 +174,11 @@
new ProtectedIntentOverlay()
);
+ UiTopo2OverlayFactory topo2OverlayFactory =
+ () -> ImmutableList.of(
+ new Traffic2Overlay()
+ );
+
UiTopoMapFactory topoMapFactory =
() -> ImmutableList.of(
new UiTopoMap("australia", "Australia", "*australia", 1.0),
@@ -194,6 +201,7 @@
return new UiExtension.Builder(CL, coreViews)
.messageHandlerFactory(messageHandlerFactory)
.topoOverlayFactory(topoOverlayFactory)
+ .topo2OverlayFactory(topo2OverlayFactory)
.topoMapFactory(topoMapFactory)
.resourcePath(CORE)
.build();
@@ -202,11 +210,11 @@
@Activate
public void activate() {
Serializer serializer = Serializer.using(KryoNamespaces.API,
- ObjectNode.class, ArrayNode.class,
- JsonNodeFactory.class, LinkedHashMap.class,
- TextNode.class, BooleanNode.class,
- LongNode.class, DoubleNode.class, ShortNode.class,
- IntNode.class, NullNode.class);
+ ObjectNode.class, ArrayNode.class,
+ JsonNodeFactory.class, LinkedHashMap.class,
+ TextNode.class, BooleanNode.class,
+ LongNode.class, DoubleNode.class, ShortNode.class,
+ IntNode.class, NullNode.class);
prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder()
.withName(ONOS_USER_PREFERENCES)
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2OverlayCache.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2OverlayCache.java
index 1c05acf..b95aeaf 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2OverlayCache.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2OverlayCache.java
@@ -135,12 +135,7 @@
// overlay instance representing "no overlay selected"
private static class NullOverlay extends UiTopo2Overlay {
NullOverlay() {
- super(EMPTY, NO_OVERLAY);
- }
-
- @Override
- public String glyphId() {
- return UNKNOWN;
+ super(EMPTY);
}
}
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2ViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2ViewMessageHandler.java
index 1763048..b30ff11 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2ViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2ViewMessageHandler.java
@@ -16,14 +16,12 @@
package org.onosproject.ui.impl.topo;
-import com.fasterxml.jackson.databind.node.ArrayNode;
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.onosproject.ui.UiTopo2Overlay;
import org.onosproject.ui.impl.UiWebSocket;
import org.onosproject.ui.model.topo.UiClusterMember;
import org.onosproject.ui.model.topo.UiNode;
@@ -129,23 +127,6 @@
return peersPayload;
}
- private ObjectNode mkOverlaysMessage() {
- ArrayNode a = arrayNode();
- for (UiTopo2Overlay ov : overlay2Cache.list()) {
- a.add(json(ov));
- }
- ObjectNode payload = objectNode();
- payload.set("overlays", a);
- return payload;
- }
-
- private ObjectNode json(UiTopo2Overlay ov) {
- return objectNode()
- .put("id", ov.id())
- .put("name", ov.name())
- .put("gid", ov.glyphId());
- }
-
// ==================================================================
@@ -186,9 +167,6 @@
// these are the regions/devices that are siblings to this region
sendMessage(PEER_REGIONS, mkPeersMessage(currentLayout));
-
- // these are the registered overlays
- sendMessage(OVERLAYS, mkOverlaysMessage());
}
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Traffic2Overlay.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Traffic2Overlay.java
new file mode 100644
index 0000000..a4dba20
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Traffic2Overlay.java
@@ -0,0 +1,46 @@
+/*
+ * 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 org.onosproject.ui.UiTopo2Overlay;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Traffic overlay for topology 2 view.
+ */
+public class Traffic2Overlay extends UiTopo2Overlay {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ // NOTE: this must match the ID defined in topo2TrafficOverlay.js
+ private static final String OVERLAY_ID = "traffic-2-overlay";
+
+ /**
+ * Creates a traffic overlay instance.
+ */
+ public Traffic2Overlay() {
+ super(OVERLAY_ID);
+ }
+
+ @Override
+ public void highlightingCallback() {
+ log.debug("highlightingCallback() invoked");
+ // TODO: implement
+ }
+}
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js b/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
new file mode 100644
index 0000000..ce662fb
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Overlay.js
@@ -0,0 +1,180 @@
+/*
+ * 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';
+
+ // constants
+ var t2os = 'Topo2OverlayService: ';
+
+ // injected refs
+ var $log, $timeout, fs, gs, wss, api;
+
+ // internal state
+ var overlays = {},
+ current = null,
+ reset = true;
+
+ function error(fn, msg) {
+ $log.error(t2os + fn + '(): ' + msg);
+ }
+
+ function warn(fn, msg) {
+ $log.warn(t2os + fn + '(): ' + msg);
+ }
+
+ function register(overlay) {
+ var r = 'register',
+ over = fs.isO(overlay),
+ kb = over ? fs.isO(overlay.keyBindings) : null,
+ id = over ? over.overlayId : '';
+
+ if (!id) {
+ return error(r, 'not a recognized overlay');
+ }
+ if (overlays[id]) {
+ return warn(r, 'already registered: "' + id + '"');
+ }
+ overlays[id] = overlay;
+ // TODO handleGlyphs(overlay) ... see topoOverlay.js
+
+ if (kb) {
+ if (!fs.isA(kb._keyOrder)) {
+ warn(r, 'no _keyOrder array defined on keyBindings');
+ } else {
+ kb._keyOrder.forEach(function (k) {
+ if (k !== '-' && !kb[k]) {
+ warn(r, 'no "' + k + '" property defined on keyBindings');
+ }
+ });
+ }
+ }
+
+ $log.debug(t2os + 'registered overlay: ' + id, overlay);
+ }
+
+ // TODO: check topoOverlay.js for more code
+ // TODO: medium term -- factor out common code
+ // TODO: longer term -- deprecate classic topology view
+
+ // === -----------------------------------------------------
+ // Hooks for overlays
+
+ function _hook(x) {
+ var h = current && current.hooks;
+ return h && fs.isF(h[x]);
+ }
+
+ function escapeHook() {
+ var eh = _hook('escape');
+ return eh ? eh() : false;
+ }
+
+ function emptySelectHook() {
+ var cb = _hook('empty');
+ cb && cb();
+ }
+
+ function singleSelectHook(data) {
+ var cb = _hook('single');
+ cb && cb(data);
+ }
+
+ function multiSelectHook(selectOrder) {
+ var cb = _hook('multi');
+ cb && cb(selectOrder);
+ }
+
+ function mouseOverHook(what) {
+ var cb = _hook('mouseover');
+ cb && cb(what);
+ }
+
+ function mouseOutHook() {
+ var cb = _hook('mouseout');
+ cb && cb();
+ }
+
+ // NOTE: modifyLinkData (on classic topo) should not be necessary, as
+ // we should have a way of doing that server side
+
+ // NOTE: while classic topology view persists, it should be the one to
+ // handle "visualization of intents" from intent view
+
+
+ // === -----------------------------------------------------
+ // Event Handlers (events from server)
+
+ function setApi(_api_) {
+ api = _api_;
+ }
+
+ function showHighlights(data) {
+ function doHighlight() {
+ _showHighlights(data);
+ }
+
+ // note: this allows the server-side event to add a manual delay
+ // before invoking the highlight... this was (originally) to
+ // allow for the re-creation of the DOM model, before trying
+ // to reference elements. For Topo2, there may be a better
+ // solution, making this piece of code redundant. Steven??
+
+ if (data.delay) {
+ $timeout(doHighlight, data.delay);
+ } else {
+ doHighlight();
+ }
+
+ }
+
+ function _showHighlights(data) {
+ // TODO: implement the highlighting .. see topoOverlay.js for example
+ $log.info('+++ TOPO 2 +++ show highlights', data);
+ }
+
+ // ========================================================================
+
+ angular.module('ovTopo2')
+ .factory('Topo2OverlayService', [
+ '$log', '$timeout', 'FnService', 'GlyphService', 'WebSocketService',
+
+ function (_$log_, _$timeout_, _fs_, _gs_, _wss_) {
+ $log = _$log_;
+ $timeout = _$timeout_;
+ fs = _fs_;
+ gs = _gs_;
+ wss = _wss_;
+
+ return {
+ register: register,
+ setApi: setApi,
+
+ hooks: {
+ escape: escapeHook,
+ emptySelect: emptySelectHook,
+ singleSelect: singleSelectHook,
+ multiSelect: multiSelectHook,
+ mouseOver: mouseOverHook,
+ mouseOut: mouseOutHook
+ },
+ showHighlights: showHighlights
+ }
+ }
+ ]);
+
+}());
\ 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
new file mode 100644
index 0000000..4515b8a
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Traffic.js
@@ -0,0 +1,87 @@
+/*
+ * 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';
+
+ // injected refs
+ var $log, fs, flash, wss, api;
+
+ // configuration
+ var allTrafficTypes = [
+ 'flowStatsBytes',
+ 'portStatsBitSec',
+ 'portStatsPktSec'
+ ],
+ allTrafficMsgs = [
+ 'Flow Stats (bytes)',
+ 'Port Stats (bits / second)',
+ 'Port Stats (packets / second)'
+ ];
+
+ // internal state
+ var mode = null,
+ allIndex = 0;
+
+ // === -----------------------------------------------------
+
+ function cancelTraffic() {
+ $log.debug('Topo2Traffic: Cancel Traffic');
+
+ if (!mode) {
+ return false;
+ }
+ mode = null;
+ wss.sendEvent('topo2CancelTraffic');
+ flash.flash('Traffic monitoring canceled');
+ return true;
+ }
+
+ function showAllTraffic() {
+ $log.debug('Topo2Traffic: Show All Traffic');
+
+ mode = 'allFlowPort';
+ wss.sendEvent('topo2RequestAllTraffic', {
+ trafficType: allTrafficTypes[allIndex]
+ });
+ flash.flash(allTrafficMsgs[allIndex]);
+ allIndex = (allIndex + 1) % 3;
+ }
+
+ // === -----------------------------------------------------
+
+ angular.module('ovTopo2')
+ .factory('Topo2TrafficService', [
+ '$log', 'FnService', 'FlashService', 'WebSocketService',
+
+ function (_$log_, _fs_, _flash_, _wss_) {
+ $log = _$log_;
+ fs = _fs_;
+ flash = _flash_;
+ wss = _wss_;
+
+ return {
+ initTraffic: function (_api_) { api = _api_; },
+ destroyTraffic: function () {},
+
+ // invoked from toolbar overlay buttons or keystrokes
+ cancelTraffic: cancelTraffic,
+ showAllTraffic: showAllTraffic
+ }
+ }
+ ]);
+}());
\ No newline at end of file
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2TrafficOverlay.js b/web/gui/src/main/webapp/app/view/topo2/topo2TrafficOverlay.js
new file mode 100644
index 0000000..19d0844
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2TrafficOverlay.js
@@ -0,0 +1,83 @@
+/*
+ * 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';
+
+ // injected refs
+ var $log, t2ov, t2ts;
+
+ // NOTE: no internal state here -- see Topo2TrafficService for that
+
+ // traffic 2 overlay definition
+ var overlay = {
+ overlayId: 'traffic-2-overlay',
+ glyphId: 'm_allTraffic',
+ tooltip: 'Traffic Overlay',
+
+ activate: function () {
+ $log.debug("Traffic-2 overlay ACTIVATED");
+ },
+
+ deactivate: function () {
+ t2ts.cancelTraffic(true);
+ $log.debug("Traffic-2 overlay DEACTIVATED");
+ },
+
+ // key bindings for toolbar buttons
+ // NOTE: fully qual. button ID is derived from overlay-id and key-name
+ keyBindings: {
+ 0: {
+ cb: function () { t2ts.cancelTraffic(true); },
+ tt: 'Cancel traffic monitoring',
+ gid: 'm_xMark'
+ },
+
+ A: {
+ cb: function () { t2ts.showAllTraffic(); },
+ tt: 'Monitor all traffic',
+ gid: 'm_allTraffic'
+ },
+
+ _keyOrder: [
+ '0', 'A'
+ ]
+ },
+
+ hooks: {
+ // hook for handling escape key
+ escape: function () {
+ // Must return true to consume ESC, false otherwise.
+ return t2ts.cancelTraffic(true);
+ }
+ // TODO : add node selection events etc.
+ // NOTE : see topoTrafficNew.js
+ }
+ };
+
+ // invoke code to register with the overlay service
+ angular.module('ovTopo2')
+ .run(['$log', 'Topo2OverlayService', 'Topo2TrafficService',
+
+ function (_$log_, _t2ov_, _t2ts_) {
+ $log = _$log_;
+ t2ov = _t2ov_;
+ t2ts = _t2ts_;
+ t2ov.register(overlay);
+ }]);
+
+}());
\ No newline at end of file
diff --git a/web/gui/src/main/webapp/index.html b/web/gui/src/main/webapp/index.html
index 7ca688d..5f3e9ff 100644
--- a/web/gui/src/main/webapp/index.html
+++ b/web/gui/src/main/webapp/index.html
@@ -154,6 +154,7 @@
<script src="app/view/topo2/topo2NodeModel.js"></script>
<script src="app/view/topo2/topo2NodePosition.js"></script>
<script src="app/view/topo2/topo2NoDevicesConnected.js"></script>
+ <script src="app/view/topo2/topo2Overlay.js"></script>
<script src="app/view/topo2/topo2Panel.js"></script>
<script src="app/view/topo2/topo2PeerRegion.js"></script>
<script src="app/view/topo2/topo2Prefs.js"></script>
@@ -165,6 +166,8 @@
<script src="app/view/topo2/topo2SubRegion.js"></script>
<script src="app/view/topo2/topo2SubRegionPanel.js"></script>
<script src="app/view/topo2/topo2Toolbar.js"></script>
+ <script src="app/view/topo2/topo2Traffic.js"></script>
+ <script src="app/view/topo2/topo2TrafficOverlay.js"></script>
<script src="app/view/topo2/topo2View.js"></script>
<script src="app/view/topo2/topo2ViewController.js"></script>
<script src="app/view/topo2/topo2Zoom.js"></script>