blob: 4392d425cf02de96466ccb6289546a00608743fd [file] [log] [blame]
Simon Hunt1002cd82015-04-23 14:44:03 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Hunt1002cd82015-04-23 14:44:03 -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 ONOS GUI -- Flow View Module
19 */
20
21(function () {
22 'use strict';
23
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -070024 // injected references
Simon Huntcaed0412017-08-12 13:49:17 -070025 var $log, $scope, $location, fs, tbs, ns, mast, ps, wss, is;
Viswanath KSP7bdc9172016-10-19 20:19:17 +053026
27 // internal state
28 var detailsPanel,
29 pStartY,
30 pHeight,
31 top,
Viswanath KSP70e0d142016-10-28 21:58:32 +053032 topTable,
Viswanath KSPed55ecf2016-12-22 18:15:45 +053033 topSelTable,
Simon Hunt8f057ee2017-07-19 14:05:26 -070034 topTrtTable,
Viswanath KSP7bdc9172016-10-19 20:19:17 +053035 iconDiv,
Viswanath KSP7bdc9172016-10-19 20:19:17 +053036 wSize;
37
Viswanath KSP7bdc9172016-10-19 20:19:17 +053038 // constants
39 var topPdg = 28,
Thomas Vachuska3da62122017-10-04 13:49:12 -070040 wtPdg = 400,
Viswanath KSP7bdc9172016-10-19 20:19:17 +053041
42 pName = 'flow-details-panel',
43 detailsReq = 'flowDetailsRequest',
Viswanath KSP70e0d142016-10-28 21:58:32 +053044 detailsResp = 'flowDetailsResponse',
45
46 propOrder = [
Simon Hunt9bff5952017-07-13 14:05:09 -070047 'flowId',
48 'state',
49
50 'bytes',
51 'packets',
52 'duration',
53
54 'priority',
Yi Tseng18177a52017-09-08 01:26:59 -070055 'tableName',
Simon Hunt36b658d2017-07-14 16:20:11 -070056 'appName',
Simon Hunt9bff5952017-07-13 14:05:09 -070057 'appId',
58
59 'groupId',
Thomas Vachuska3da62122017-10-04 13:49:12 -070060 'idleTimeout',
61 'hardTimeout',
Steven Burrows1c2a9682017-07-14 16:52:46 +010062 'permanent',
Viswanath KSP70e0d142016-10-28 21:58:32 +053063 ],
64 friendlyProps = [
Simon Hunt9bff5952017-07-13 14:05:09 -070065 'Flow ID',
66 'State',
67
68 'Bytes',
69 'Packets',
70 'Duration',
71
72 'Flow Priority',
Yi Tseng18177a52017-09-08 01:26:59 -070073 'Table Name',
Simon Hunt36b658d2017-07-14 16:20:11 -070074 'App Name',
Simon Hunt9bff5952017-07-13 14:05:09 -070075 'App ID',
76
77 'Group ID',
Thomas Vachuska3da62122017-10-04 13:49:12 -070078 'Idle Timeout',
79 'Hard Timeout',
Steven Burrows1c2a9682017-07-14 16:52:46 +010080 'Permanent',
Viswanath KSP70e0d142016-10-28 21:58:32 +053081 ];
Viswanath KSP7bdc9172016-10-19 20:19:17 +053082
83 function closePanel() {
84 if (detailsPanel.isVisible()) {
85 $scope.selId = null;
86 detailsPanel.hide();
87 return true;
88 }
89 return false;
90 }
91
92 function addCloseBtn(div) {
93 is.loadEmbeddedIcon(div, 'close', 20);
94 div.on('click', closePanel);
95 }
96
Viswanath KSP70e0d142016-10-28 21:58:32 +053097 function handleEscape() {
98 return closePanel();
99 }
100
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530101 function setUpPanel() {
Simon Huntcaed0412017-08-12 13:49:17 -0700102 var container, closeBtn;
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530103 detailsPanel.empty();
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530104 container = detailsPanel.append('div').classed('container', true);
Simon Hunt8f057ee2017-07-19 14:05:26 -0700105
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530106 top = container.append('div').classed('top', true);
107 closeBtn = top.append('div').classed('close-btn', true);
108 addCloseBtn(closeBtn);
109 iconDiv = top.append('div').classed('dev-icon', true);
110 top.append('h2');
Viswanath KSP70e0d142016-10-28 21:58:32 +0530111 topTable = top.append('div').classed('top-content', true)
112 .append('table');
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530113 top.append('hr');
Simon Hunt9bff5952017-07-13 14:05:09 -0700114
Thomas Vachuska3da62122017-10-04 13:49:12 -0700115 top.append('h3').text('Selector');
116 topSelTable = top.append('div').classed('top-content', true).append('table');
117 top.append('hr');
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530118
Thomas Vachuska3da62122017-10-04 13:49:12 -0700119 top.append('h3').text('Treatment');
120 topTrtTable = top.append('div').classed('top-content', true).append('table');
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530121 }
122
Simon Hunt8f057ee2017-07-19 14:05:26 -0700123 function addProp(tbody, label, value) {
Viswanath KSPed55ecf2016-12-22 18:15:45 +0530124 var tr = tbody.append('tr');
125
126 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700127 tr.append('td').attr('class', cls).text(txt);
Viswanath KSPed55ecf2016-12-22 18:15:45 +0530128 }
129 addCell('label', label + ' :');
130 addCell('value', value);
131 }
132
Simon Hunt8f057ee2017-07-19 14:05:26 -0700133 // deferred fetching of user-visible strings, so that lion context is set
134 function getLionProps() {
135 // TODO: Localization... (see cluster.js for the pattern)
136 // var l = $scope.lion;
137 // return [
138 // l('flow_id'),
139 // ...
140 // ];
141 return friendlyProps;
142 }
143
144 function getLionClearDeferred() {
145 // TODO: Localization...
146 return 'Clear deferred';
147 }
148
Viswanath KSP70e0d142016-10-28 21:58:32 +0530149 function populateTop(details) {
150 is.loadEmbeddedIcon(iconDiv, 'flowTable', 40);
Simon Hunt239f09e2017-05-18 13:10:09 -0700151 top.select('h2').text(details.flowId);
Viswanath KSP70e0d142016-10-28 21:58:32 +0530152
Simon Hunt8f057ee2017-07-19 14:05:26 -0700153 var tbody = topTable.append('tbody'),
154 tbodySel = topSelTable.append('tbody'),
155 tbodyTrt = topTrtTable.append('tbody'),
156 selArray = details.selector,
157 treat = details.treatment,
158 propLabels = getLionProps();
Viswanath KSP70e0d142016-10-28 21:58:32 +0530159
Simon Hunt8f057ee2017-07-19 14:05:26 -0700160 function addLabVal(tbody, lv) {
161 var bits = lv.match(/^([^:]*):(.*)/);
162 addProp(tbody, bits[1], bits[2]);
163 }
Viswanath KSPed55ecf2016-12-22 18:15:45 +0530164
Simon Hunt8f057ee2017-07-19 14:05:26 -0700165 function popInstrList(items, tag) {
166 items.forEach(function (item) {
167 addLabVal(tbodyTrt, tag + item);
168 });
169 }
Viswanath KSPed55ecf2016-12-22 18:15:45 +0530170
Simon Hunt8f057ee2017-07-19 14:05:26 -0700171 // basic flow properties
Viswanath KSP70e0d142016-10-28 21:58:32 +0530172 propOrder.forEach(function (prop, i) {
Simon Hunt8f057ee2017-07-19 14:05:26 -0700173 addProp(tbody, propLabels[i], details[prop]);
Viswanath KSP70e0d142016-10-28 21:58:32 +0530174 });
Viswanath KSPed55ecf2016-12-22 18:15:45 +0530175
Simon Hunt8f057ee2017-07-19 14:05:26 -0700176 // selection criteria
177 selArray.forEach(function (lv) {
178 addLabVal(tbodySel, lv);
Viswanath KSPed55ecf2016-12-22 18:15:45 +0530179 });
180
Simon Hunt8f057ee2017-07-19 14:05:26 -0700181 // traffic treatment
182 treat.immed && popInstrList(treat.immed, '[imm]');
183 treat.defer && popInstrList(treat.defer, '[def]');
184 treat.meter && addLabVal(tbodyTrt, treat.meter);
185 treat.table && addLabVal(tbodyTrt, treat.table);
186 treat.meta && addLabVal(tbodyTrt, treat.meta);
187 addProp(tbodyTrt, getLionClearDeferred(), treat.clearDef);
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530188 }
189
190 function createDetailsPane() {
191 detailsPanel = ps.createPanel(pName, {
192 width: wSize.width,
193 margin: 0,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100194 hideMargin: 0,
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530195 });
196 detailsPanel.el().style({
197 position: 'absolute',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100198 top: pStartY + 'px',
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530199 });
200 $scope.hidePanel = function () { detailsPanel.hide(); };
201 detailsPanel.hide();
202 }
203
204 function populateDetails(details) {
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530205 setUpPanel();
206 populateTop(details);
207
Steven Burrows1c2a9682017-07-14 16:52:46 +0100208 // ToDo add more details
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530209 detailsPanel.height(pHeight);
210 detailsPanel.width(wtPdg);
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530211 }
212
213 function respDetailsCb(data) {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100214 $log.debug('Got response from server :', data);
Viswanath KSP70e0d142016-10-28 21:58:32 +0530215 $scope.panelData = data.details;
216 $scope.$apply();
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530217 }
Bri Prebilic Colecdc188d2015-04-24 16:40:11 -0700218
Simon Hunt1002cd82015-04-23 14:44:03 -0700219 angular.module('ovFlow', [])
Steven Burrows1c2a9682017-07-14 16:52:46 +0100220 .controller('OvFlowCtrl',
221 ['$log', '$scope', '$location',
222 'FnService', 'TableBuilderService', 'NavService',
223 'MastService', 'PanelService', 'KeyService', 'IconService',
224 'WebSocketService',
Simon Hunt1002cd82015-04-23 14:44:03 -0700225
Steven Burrows1c2a9682017-07-14 16:52:46 +0100226 function (_$log_, _$scope_, _$location_, _fs_, _tbs_, _ns_,
227 _mast_, _ps_, _ks_, _is_, _wss_) {
228 var params,
229 handlers = {};
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530230
Steven Burrows1c2a9682017-07-14 16:52:46 +0100231 $log = _$log_;
232 $scope = _$scope_;
233 $location = _$location_;
234 fs = _fs_;
235 tbs = _tbs_;
236 ns = _ns_;
237 is = _is_;
238 wss = _wss_;
239 mast = _mast_;
240 ps = _ps_;
241 $scope.deviceTip = 'Show device table';
242 $scope.portTip = 'Show port view for this device';
243 $scope.groupTip = 'Show group view for this device';
244 $scope.meterTip = 'Show meter view for selected device';
Yi Tsenga87b40c2017-09-10 00:59:03 -0700245 $scope.pipeconfTip = 'Show pipeconf view for selected device';
Steven Burrows1c2a9682017-07-14 16:52:46 +0100246 $scope.briefTip = 'Switch to brief view';
247 $scope.detailTip = 'Switch to detailed view';
Yi Tsenga87b40c2017-09-10 00:59:03 -0700248
Steven Burrows1c2a9682017-07-14 16:52:46 +0100249 $scope.brief = true;
250 params = $location.search();
251 if (params.hasOwnProperty('devId')) {
252 $scope.devId = params['devId'];
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530253 }
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530254
Steven Burrows1c2a9682017-07-14 16:52:46 +0100255 tbs.buildTable({
256 scope: $scope,
257 tag: 'flow',
258 selCb: selCb,
259 query: params,
260 });
261
262 $scope.nav = function (path) {
263 if ($scope.devId) {
264 ns.navTo(path, { devId: $scope.devId });
265 }
266 };
267
268 // details panel handlers
269 handlers[detailsResp] = respDetailsCb;
270 wss.bindHandlers(handlers);
271
272 function selCb($event, row) {
273 if ($scope.selId) {
Simon Huntf257a962017-08-25 18:58:47 -0700274 wss.sendEvent(detailsReq, {
275 flowId: row.id,
276 appId: row.appId
277 });
Steven Burrows1c2a9682017-07-14 16:52:46 +0100278 } else {
279 $scope.hidePanel();
280 }
281 $log.debug('Got a click on:', row);
282 }
283
284 $scope.$on('$destroy', function () {
285 wss.unbindHandlers(handlers);
286 });
287
288 $scope.briefToggle = function () {
289 $scope.brief = !$scope.brief;
290 };
291
292 Object.defineProperty($scope, 'queryFilter', {
293 get: function () {
294 var out = {};
295 out[$scope.queryBy || '$'] = $scope.queryTxt;
296 return out;
297 },
298 });
299
300 $log.log('OvFlowCtrl has been created');
301 }])
302
303 .directive('flowDetailsPanel',
304 ['$rootScope', '$window', '$timeout', 'KeyService',
Simon Huntf257a962017-08-25 18:58:47 -0700305 function ($rootScope, $window, $timeout, ks) {
306 return function (scope) {
307 var unbindWatch;
Steven Burrows1c2a9682017-07-14 16:52:46 +0100308
Simon Huntf257a962017-08-25 18:58:47 -0700309 function heightCalc() {
310 var tabhead = d3.select('.tabular-header');
Steven Burrows1c2a9682017-07-14 16:52:46 +0100311
Simon Huntf257a962017-08-25 18:58:47 -0700312 pStartY = fs.noPxStyle(tabhead, 'height') +
313 mast.mastHeight() + topPdg;
314 wSize = fs.windowSize(pStartY);
315 pHeight = wSize.height;
316 }
Steven Burrows1c2a9682017-07-14 16:52:46 +0100317
Simon Huntf257a962017-08-25 18:58:47 -0700318 function initPanel() {
319 heightCalc();
320 createDetailsPane();
321 }
322
323 // Safari has a bug where it renders the fixed-layout
324 // table wrong if you ask for the window's size too early
325 if (scope.onos.browser === 'safari') {
326 $timeout(initPanel);
327 } else {
328 initPanel();
329 }
330 // create key bindings to handle panel
331 ks.keyBindings({
332 esc: [handleEscape, 'Close the details panel'],
333 _helpFormat: ['esc'],
334 });
335 ks.gestureNotes([
336 ['click', 'Select a row to show cluster node details'],
337 ['scroll down', 'See available cluster nodes'],
338 ]);
339 // if the panelData changes
340 scope.$watch('panelData', function () {
341 if (!fs.isEmptyObject(scope.panelData)) {
342 populateDetails(scope.panelData);
343 detailsPanel.show();
Steven Burrows1c2a9682017-07-14 16:52:46 +0100344 }
Simon Huntf257a962017-08-25 18:58:47 -0700345 });
346 // if the window size changes
347 unbindWatch = $rootScope.$watchCollection(
348 function () {
349 return {
350 h: $window.innerHeight,
351 w: $window.innerWidth,
352 };
353 }, function () {
Steven Burrows1c2a9682017-07-14 16:52:46 +0100354 if (!fs.isEmptyObject(scope.panelData)) {
Simon Huntf257a962017-08-25 18:58:47 -0700355 heightCalc();
Steven Burrows1c2a9682017-07-14 16:52:46 +0100356 populateDetails(scope.panelData);
Steven Burrows1c2a9682017-07-14 16:52:46 +0100357 }
Simon Huntf257a962017-08-25 18:58:47 -0700358 }
359 );
Steven Burrows1c2a9682017-07-14 16:52:46 +0100360
Simon Huntf257a962017-08-25 18:58:47 -0700361 scope.$on('$destroy', function () {
362 unbindWatch();
363 ps.destroyPanel(pName);
364 });
365 };
366 }]);
Viswanath KSP7bdc9172016-10-19 20:19:17 +0530367
Simon Hunt1002cd82015-04-23 14:44:03 -0700368}());