Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 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 |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 22 | var $log, flash, wss; |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 23 | |
| 24 | // configuration |
| 25 | var allTrafficTypes = [ |
| 26 | 'flowStatsBytes', |
| 27 | 'portStatsBitSec', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 28 | 'portStatsPktSec', |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 29 | ], |
| 30 | allTrafficMsgs = [ |
| 31 | 'Flow Stats (bytes)', |
| 32 | 'Port Stats (bits / second)', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 33 | 'Port Stats (packets / second)', |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 34 | ]; |
| 35 | |
| 36 | // internal state |
| 37 | var mode = null, |
Steven Burrows | ca1a39c | 2017-05-08 17:31:08 -0400 | [diff] [blame] | 38 | currentIndex = 0, |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 39 | allIndex = 0; |
| 40 | |
| 41 | // === ----------------------------------------------------- |
| 42 | |
| 43 | function cancelTraffic() { |
| 44 | $log.debug('Topo2Traffic: Cancel Traffic'); |
| 45 | |
| 46 | if (!mode) { |
| 47 | return false; |
| 48 | } |
| 49 | mode = null; |
| 50 | wss.sendEvent('topo2CancelTraffic'); |
| 51 | flash.flash('Traffic monitoring canceled'); |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | function showAllTraffic() { |
Simon Hunt | e6f6461 | 2017-04-28 00:01:48 -0700 | [diff] [blame] | 56 | $log.debug('Topo2Traffic: Show All Traffic:', allTrafficTypes[allIndex]); |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 57 | |
| 58 | mode = 'allFlowPort'; |
| 59 | wss.sendEvent('topo2RequestAllTraffic', { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 60 | trafficType: allTrafficTypes[allIndex], |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 61 | }); |
| 62 | flash.flash(allTrafficMsgs[allIndex]); |
Steven Burrows | ca1a39c | 2017-05-08 17:31:08 -0400 | [diff] [blame] | 63 | currentIndex = allIndex; |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 64 | allIndex = (allIndex + 1) % 3; |
| 65 | } |
| 66 | |
Steven Burrows | ca1a39c | 2017-05-08 17:31:08 -0400 | [diff] [blame] | 67 | function selectedTrafficOverlay() { |
| 68 | return allTrafficTypes[currentIndex]; |
| 69 | } |
| 70 | |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 71 | // === ----------------------------------------------------- |
| 72 | |
| 73 | angular.module('ovTopo2') |
| 74 | .factory('Topo2TrafficService', [ |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 75 | '$log', 'FlashService', 'WebSocketService', |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 76 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 77 | function (_$log_, _flash_, _wss_) { |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 78 | $log = _$log_; |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 79 | flash = _flash_; |
| 80 | wss = _wss_; |
| 81 | |
| 82 | return { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 83 | // TODO: Remove References |
| 84 | initTraffic: function (_api_) {}, |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 85 | destroyTraffic: function () {}, |
| 86 | |
| 87 | // invoked from toolbar overlay buttons or keystrokes |
| 88 | cancelTraffic: cancelTraffic, |
Steven Burrows | ca1a39c | 2017-05-08 17:31:08 -0400 | [diff] [blame] | 89 | showAllTraffic: showAllTraffic, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 90 | selectedTrafficOverlay: selectedTrafficOverlay, |
| 91 | }; |
| 92 | }, |
Simon Hunt | 6cc8645 | 2017-04-27 17:46:22 -0700 | [diff] [blame] | 93 | ]); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 94 | }()); |