Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | (function () { |
| 19 | 'use strict'; |
| 20 | |
| 21 | // injected refs |
| 22 | var $log, fs, flash, wss, api; |
| 23 | |
| 24 | // configuration |
| 25 | var allTrafficTypes = [ |
| 26 | 'flowStatsBytes', |
| 27 | 'portStatsBitSec', |
| 28 | 'portStatsPktSec' |
| 29 | ], |
| 30 | allTrafficMsgs = [ |
| 31 | 'Flow Stats (bytes)', |
| 32 | 'Port Stats (bits / second)', |
| 33 | 'Port Stats (packets / second)' |
| 34 | ]; |
| 35 | |
| 36 | // internal state |
| 37 | var mode = null, |
| 38 | allIndex = 0; |
| 39 | |
| 40 | // === ----------------------------------------------------- |
| 41 | |
| 42 | function cancelTraffic() { |
| 43 | $log.debug('Topo2Traffic: Cancel Traffic'); |
| 44 | |
| 45 | if (!mode) { |
| 46 | return false; |
| 47 | } |
| 48 | mode = null; |
| 49 | wss.sendEvent('topo2CancelTraffic'); |
| 50 | flash.flash('Traffic monitoring canceled'); |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | function showAllTraffic() { |
| 55 | $log.debug('Topo2Traffic: Show All Traffic'); |
| 56 | |
| 57 | mode = 'allFlowPort'; |
| 58 | wss.sendEvent('topo2RequestAllTraffic', { |
| 59 | trafficType: allTrafficTypes[allIndex] |
| 60 | }); |
| 61 | flash.flash(allTrafficMsgs[allIndex]); |
| 62 | allIndex = (allIndex + 1) % 3; |
| 63 | } |
| 64 | |
| 65 | // === ----------------------------------------------------- |
| 66 | |
| 67 | angular.module('ovTopo2') |
| 68 | .factory('Topo2TrafficService', [ |
| 69 | '$log', 'FnService', 'FlashService', 'WebSocketService', |
| 70 | |
| 71 | function (_$log_, _fs_, _flash_, _wss_) { |
| 72 | $log = _$log_; |
| 73 | fs = _fs_; |
| 74 | flash = _flash_; |
| 75 | wss = _wss_; |
| 76 | |
| 77 | return { |
| 78 | initTraffic: function (_api_) { api = _api_; }, |
| 79 | destroyTraffic: function () {}, |
| 80 | |
| 81 | // invoked from toolbar overlay buttons or keystrokes |
| 82 | cancelTraffic: cancelTraffic, |
| 83 | showAllTraffic: showAllTraffic |
| 84 | } |
| 85 | } |
| 86 | ]); |
| 87 | }()); |