blob: 92509bd8378315e5fad72a2b288f474909b4753a [file] [log] [blame]
Simon Hunt6cc86452017-04-27 17:46:22 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Simon Hunt6cc86452017-04-27 17:46:22 -07003 *
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 Burrows1c2a9682017-07-14 16:52:46 +010022 var $log, flash, wss;
Simon Hunt6cc86452017-04-27 17:46:22 -070023
24 // configuration
25 var allTrafficTypes = [
26 'flowStatsBytes',
27 'portStatsBitSec',
Steven Burrows1c2a9682017-07-14 16:52:46 +010028 'portStatsPktSec',
Simon Hunt6cc86452017-04-27 17:46:22 -070029 ],
30 allTrafficMsgs = [
31 'Flow Stats (bytes)',
32 'Port Stats (bits / second)',
Steven Burrows1c2a9682017-07-14 16:52:46 +010033 'Port Stats (packets / second)',
Simon Hunt6cc86452017-04-27 17:46:22 -070034 ];
35
36 // internal state
37 var mode = null,
Steven Burrowsca1a39c2017-05-08 17:31:08 -040038 currentIndex = 0,
Simon Hunt6cc86452017-04-27 17:46:22 -070039 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 Hunte6f64612017-04-28 00:01:48 -070056 $log.debug('Topo2Traffic: Show All Traffic:', allTrafficTypes[allIndex]);
Simon Hunt6cc86452017-04-27 17:46:22 -070057
58 mode = 'allFlowPort';
59 wss.sendEvent('topo2RequestAllTraffic', {
Steven Burrows1c2a9682017-07-14 16:52:46 +010060 trafficType: allTrafficTypes[allIndex],
Simon Hunt6cc86452017-04-27 17:46:22 -070061 });
62 flash.flash(allTrafficMsgs[allIndex]);
Steven Burrowsca1a39c2017-05-08 17:31:08 -040063 currentIndex = allIndex;
Simon Hunt6cc86452017-04-27 17:46:22 -070064 allIndex = (allIndex + 1) % 3;
65 }
66
Steven Burrowsca1a39c2017-05-08 17:31:08 -040067 function selectedTrafficOverlay() {
68 return allTrafficTypes[currentIndex];
69 }
70
Simon Hunt6cc86452017-04-27 17:46:22 -070071 // === -----------------------------------------------------
72
73 angular.module('ovTopo2')
74 .factory('Topo2TrafficService', [
Steven Burrows1c2a9682017-07-14 16:52:46 +010075 '$log', 'FlashService', 'WebSocketService',
Simon Hunt6cc86452017-04-27 17:46:22 -070076
Steven Burrows1c2a9682017-07-14 16:52:46 +010077 function (_$log_, _flash_, _wss_) {
Simon Hunt6cc86452017-04-27 17:46:22 -070078 $log = _$log_;
Simon Hunt6cc86452017-04-27 17:46:22 -070079 flash = _flash_;
80 wss = _wss_;
81
82 return {
Steven Burrows1c2a9682017-07-14 16:52:46 +010083 // TODO: Remove References
84 initTraffic: function (_api_) {},
Simon Hunt6cc86452017-04-27 17:46:22 -070085 destroyTraffic: function () {},
86
87 // invoked from toolbar overlay buttons or keystrokes
88 cancelTraffic: cancelTraffic,
Steven Burrowsca1a39c2017-05-08 17:31:08 -040089 showAllTraffic: showAllTraffic,
Steven Burrows1c2a9682017-07-14 16:52:46 +010090 selectedTrafficOverlay: selectedTrafficOverlay,
91 };
92 },
Simon Hunt6cc86452017-04-27 17:46:22 -070093 ]);
Steven Burrows1c2a9682017-07-14 16:52:46 +010094}());