blob: 773353f8e9cb63557815a77e22a73e66d2309643 [file] [log] [blame]
Jian Li10a20702016-02-01 16:39:51 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Li10a20702016-02-01 16:39:51 -08003 *
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 ONOS GUI -- Control Plane Manager View Module
19 */
20(function () {
21 'use strict';
22
Jian Li1aa07822016-04-19 17:58:02 -070023 // injected references
Jian Lid5be69f2016-04-25 18:11:52 -070024 var $log, $scope, $location, ks, fs, cbs, ns;
Jian Li10a20702016-02-01 16:39:51 -080025
Jian Lid5be69f2016-04-25 18:11:52 -070026 var hasDeviceId;
27
28 var labels = new Array(1);
29 var data = new Array(6);
30 for (var i = 0; i < 6; i++) {
31 data[i] = new Array(1);
32 }
33
Jian Li72f3f102016-04-28 12:40:57 -070034 var max;
Jian Lid5be69f2016-04-25 18:11:52 -070035
36 function ceil(num) {
37 if (isNaN(num)) {
38 return 0;
39 }
40 var pre = num.toString().length - 1
41 var pow = Math.pow(10, pre);
42 return (Math.ceil(num / pow)) * pow;
43 }
Jian Li10a20702016-02-01 16:39:51 -080044
Jian Li72f3f102016-04-28 12:40:57 -070045 function maxInArray(array) {
46 var merged = [].concat.apply([], array);
47 return Math.max.apply(null, merged);
48 }
49
Jian Li1aa07822016-04-19 17:58:02 -070050 angular.module('ovCpman', ["chart.js"])
Jian Li10a20702016-02-01 16:39:51 -080051 .controller('OvCpmanCtrl',
Jian Lid5be69f2016-04-25 18:11:52 -070052 ['$log', '$scope', '$location', 'FnService', 'ChartBuilderService', 'NavService',
Jian Li10a20702016-02-01 16:39:51 -080053
Jian Lid5be69f2016-04-25 18:11:52 -070054 function (_$log_, _$scope_, _$location_, _fs_, _cbs_, _ns_) {
Jian Li1aa07822016-04-19 17:58:02 -070055 var params;
Jian Li10a20702016-02-01 16:39:51 -080056 $log = _$log_;
57 $scope = _$scope_;
Jian Li1aa07822016-04-19 17:58:02 -070058 $location = _$location_;
59 fs = _fs_;
60 cbs = _cbs_;
Jian Lid5be69f2016-04-25 18:11:52 -070061 ns = _ns_;
Jian Li10a20702016-02-01 16:39:51 -080062
Jian Li1aa07822016-04-19 17:58:02 -070063 params = $location.search();
Jian Lid5be69f2016-04-25 18:11:52 -070064
Jian Li1aa07822016-04-19 17:58:02 -070065 if (params.hasOwnProperty('devId')) {
66 $scope.devId = params['devId'];
Jian Lid5be69f2016-04-25 18:11:52 -070067 hasDeviceId = true;
68 } else {
Jian Lid5be69f2016-04-25 18:11:52 -070069 hasDeviceId = false;
Jian Li1aa07822016-04-19 17:58:02 -070070 }
Jian Li10a20702016-02-01 16:39:51 -080071
Jian Li1aa07822016-04-19 17:58:02 -070072 cbs.buildChart({
73 scope: $scope,
74 tag: 'cpman',
75 query: params
Jian Li10a20702016-02-01 16:39:51 -080076 });
77
Jian Li1aa07822016-04-19 17:58:02 -070078 $scope.$watch('chartData', function () {
Jian Li1aa07822016-04-19 17:58:02 -070079 if (!fs.isEmptyObject($scope.chartData)) {
Jian Lid5be69f2016-04-25 18:11:52 -070080 $scope.showLoader = false;
81 var length = $scope.chartData.length;
82 labels = new Array(length);
83 for (var i = 0; i < 6; i++) {
84 data[i] = new Array(length);
85 }
86
87 $scope.chartData.forEach(function (cm, idx) {
Jian Li1aa07822016-04-19 17:58:02 -070088 data[0][idx] = cm.inbound_packet;
89 data[1][idx] = cm.outbound_packet;
90 data[2][idx] = cm.flow_mod_packet;
91 data[3][idx] = cm.flow_removed_packet;
92 data[4][idx] = cm.request_packet;
93 data[5][idx] = cm.reply_packet;
Jian Lid5be69f2016-04-25 18:11:52 -070094
Jian Li72f3f102016-04-28 12:40:57 -070095 labels[idx] = cm.label;
Jian Li1aa07822016-04-19 17:58:02 -070096 });
97 }
Jian Lid5be69f2016-04-25 18:11:52 -070098
Jian Li72f3f102016-04-28 12:40:57 -070099 max = maxInArray(data)
Jian Lid5be69f2016-04-25 18:11:52 -0700100 $scope.labels = labels;
101 $scope.data = data;
102 $scope.options = {
103 scaleOverride : true,
104 scaleSteps : 10,
105 scaleStepWidth : ceil(max) / 10,
Jian Li72f3f102016-04-28 12:40:57 -0700106 scaleStartValue : 0,
107 scaleFontSize : 16
Jian Lid5be69f2016-04-25 18:11:52 -0700108 };
109 $scope.onClick = function (points, evt) {
Jian Li9c857942016-08-03 02:38:19 +0900110 var label = labels[points[0]._index];
111 if (label) {
112 ns.navTo('cpman', { devId: label });
113 $log.log(label);
Jian Lid5be69f2016-04-25 18:11:52 -0700114 }
115 };
Jian Li92b0d2e2016-05-04 19:58:46 -0700116
117 if (!fs.isEmptyObject($scope.annots)) {
118 $scope.deviceIds = JSON.parse($scope.annots.deviceIds);
119 }
120
121 $scope.onChange = function (deviceId) {
122 ns.navTo('cpman', { devId: deviceId });
123 };
Jian Li1aa07822016-04-19 17:58:02 -0700124 });
125
126 $scope.series = ['INBOUND', 'OUTBOUND', 'FLOW-MOD',
Jian Li72f3f102016-04-28 12:40:57 -0700127 'FLOW-REMOVED', 'REQUEST', 'REPLY'];
Jian Li1aa07822016-04-19 17:58:02 -0700128 $scope.labels = labels;
Jian Li1aa07822016-04-19 17:58:02 -0700129 $scope.data = data;
130
Jian Lid5be69f2016-04-25 18:11:52 -0700131 $scope.chartColors = [
132 '#286090',
133 '#F7464A',
134 '#46BFBD',
135 '#FDB45C',
136 '#97BBCD',
137 '#4D5360',
138 '#8c4f9f'
139 ];
140 Chart.defaults.global.colours = $scope.chartColors;
141
142 $scope.showLoader = true;
143
Jian Li10a20702016-02-01 16:39:51 -0800144 $log.log('OvCpmanCtrl has been created');
145 }]);
146
147}());