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/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