blob: 1cb703f5b536a1f4e0244f3770092ff04abf1174 [file] [log] [blame]
Simon Hunt6cc86452017-04-27 17:46:22 -07001/*
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,
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', {
60 trafficType: allTrafficTypes[allIndex]
61 });
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', [
75 '$log', 'FnService', 'FlashService', 'WebSocketService',
76
77 function (_$log_, _fs_, _flash_, _wss_) {
78 $log = _$log_;
79 fs = _fs_;
80 flash = _flash_;
81 wss = _wss_;
82
83 return {
84 initTraffic: function (_api_) { api = _api_; },
85 destroyTraffic: function () {},
86
87 // invoked from toolbar overlay buttons or keystrokes
88 cancelTraffic: cancelTraffic,
Steven Burrowsca1a39c2017-05-08 17:31:08 -040089 showAllTraffic: showAllTraffic,
90 selectedTrafficOverlay: selectedTrafficOverlay
Simon Hunt6cc86452017-04-27 17:46:22 -070091 }
92 }
93 ]);
94}());