blob: c16e2c00f3d8da19254010fba2470569c0e65e7f [file] [log] [blame]
Georgios Katsikas973a2652018-06-28 08:45:47 +02001/*
2 * Copyright 2018-present Open Networking Foundation
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 ONOS GUI -- Throughput View Module
19 */
20(function () {
21 'use strict';
22
23 // injected references
24 var $log, $scope, $location, ks, fs, cbs, ns;
25
26 var hasDeviceId;
27 // TODO: Pass this dynamically
28 var coresNb = 16;
29
30 var labels = new Array(1);
31 var data = new Array(coresNb);
32 for (var i = 0; i < coresNb; i++) {
33 data[i] = new Array(1);
34 data[i][0] = 0;
35 }
36
37 angular.module('ovThroughput', ["chart.js"])
38 .controller('OvThroughputCtrl',
39 ['$log', '$scope', '$location', 'FnService', 'ChartBuilderService', 'NavService',
40
41 function (_$log_, _$scope_, _$location_, _fs_, _cbs_, _ns_) {
42 var params;
43 $log = _$log_;
44 $scope = _$scope_;
45 $location = _$location_;
46 fs = _fs_;
47 cbs = _cbs_;
48 ns = _ns_;
49
50 params = $location.search();
51
52 if (params.hasOwnProperty('devId')) {
53 $scope.devId = params['devId'];
54 hasDeviceId = true;
55 } else {
56 hasDeviceId = false;
57 }
58
59 cbs.buildChart({
60 scope: $scope,
61 tag: 'throughput',
62 query: params
63 });
64
65 $scope.$watch('chartData', function () {
66 if (!fs.isEmptyObject($scope.chartData)) {
67 $scope.showLoader = false;
68 var length = $scope.chartData.length;
69 labels = new Array(length);
70 for (var i = 0; i < coresNb; i++) {
71 data[i] = new Array(length);
72 }
73
74 $scope.chartData.forEach(
75 function (cm, idx) {
76 // TODO: Squeeze using a working loop?
77 data[0][idx] = cm.throughput_0;
78 data[1][idx] = cm.throughput_1;
79 data[2][idx] = cm.throughput_2;
80 data[3][idx] = cm.throughput_3;
81 data[4][idx] = cm.throughput_4;
82 data[5][idx] = cm.throughput_5;
83 data[6][idx] = cm.throughput_6;
84 data[7][idx] = cm.throughput_7;
85 data[8][idx] = cm.throughput_8;
86 data[9][idx] = cm.throughput_9;
87 data[10][idx] = cm.throughput_10;
88 data[11][idx] = cm.throughput_11;
89 data[12][idx] = cm.throughput_12;
90 data[13][idx] = cm.throughput_13;
91 data[14][idx] = cm.throughput_14;
92 data[15][idx] = cm.throughput_15;
93
94 labels[idx] = cm.label;
95 }
96 );
97 }
98
99 $scope.labels = labels;
100 $scope.data = data;
101
102 $scope.options = {
103 scales: {
104 yAxes: [{
105 type: 'linear',
106 position: 'left',
107 id: 'y-axis-throughput',
108 ticks: {
109 min: 0,
110 max: 100,
111 fontSize: 28,
112 },
113 scaleLabel: {
114 display: true,
115 labelString: 'Throughput/CPU Core (Gbps)',
116 fontSize: 28,
117 }
118 }],
119 xAxes: [{
120 id: 'x-axis-servers-cores',
121 ticks: {
122 fontSize: 28,
123 },
124 scaleLabel: {
125 display: true,
126 fontSize: 28,
127 }
128 }]
129 }
130 };
131
132 $scope.onClick = function (points, evt) {
133 var label = labels[points[0]._index];
134 if (label) {
135 ns.navTo('throughput', { devId: label });
136 $log.log(label);
137 }
138 };
139
140 if (!fs.isEmptyObject($scope.annots)) {
141 $scope.deviceIds = JSON.parse($scope.annots.deviceIds);
142 }
143
144 $scope.onChange = function (deviceId) {
145 ns.navTo('throughput', { devId: deviceId });
146 };
147 });
148
149 $scope.series = new Array(coresNb);
150 for (var i = 0; i < coresNb; i++) {
151 $scope.series[i] = 'Throughput-CPU ' + i;
152 }
153
154 $scope.labels = labels;
155 $scope.data = data;
156
157 // TODO: For some reason, this assignment does not work
158 $scope.chartColors = [
159 '#e6194b', // Red
160 '#3cb44b', // Green
161 '#ffe119', // Yellow
162 '#0082c8', // Blue
163 '#f58231', // Orange
164 '#808080', // Grey
165 '#fffac8', // Beige
166 '#aaffc3', // Mint
167 '#911eb4', // Purple
168 '#46f0f0', // Cyan
169 '#d2f53c', // Lime
170 '#800000', // Maroon
171 '#000000', // Black
172 '#f032e6', // Magenta
173 '#008080', // Teal
174 '#808000', // Olive
175 '#aa6e28' // Brown
176 ];
177 Chart.defaults.global.colours = $scope.chartColors;
178
179 $scope.showLoader = true;
180
181 $log.log('OvThroughputCtrl has been created');
182 }]);
183
184}());