Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 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 -- Flow View Module |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 24 | // injected references |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 25 | var $log, $scope, $location, fs, tbs, ns, mast, ps, wss, is, ks; |
| 26 | |
| 27 | // internal state |
| 28 | var detailsPanel, |
| 29 | pStartY, |
| 30 | pHeight, |
| 31 | top, |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 32 | topTable, |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 33 | trtDiv, |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 34 | selDiv, |
| 35 | topSelTable, |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 36 | topTrtTable, |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 37 | bottom, |
| 38 | iconDiv, |
| 39 | nameDiv, |
| 40 | wSize; |
| 41 | |
| 42 | |
| 43 | // constants |
| 44 | var topPdg = 28, |
| 45 | ctnrPdg = 24, |
| 46 | scrollSize = 17, |
| 47 | portsTblPdg = 50, |
| 48 | htPdg = 479, |
| 49 | wtPdg = 532, |
| 50 | |
| 51 | pName = 'flow-details-panel', |
| 52 | detailsReq = 'flowDetailsRequest', |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 53 | detailsResp = 'flowDetailsResponse', |
| 54 | |
| 55 | propOrder = [ |
Simon Hunt | 9bff595 | 2017-07-13 14:05:09 -0700 | [diff] [blame] | 56 | 'flowId', |
| 57 | 'state', |
| 58 | |
| 59 | 'bytes', |
| 60 | 'packets', |
| 61 | 'duration', |
| 62 | |
| 63 | 'priority', |
| 64 | 'tableId', |
Simon Hunt | 36b658d | 2017-07-14 16:20:11 -0700 | [diff] [blame] | 65 | 'appName', |
Simon Hunt | 9bff595 | 2017-07-13 14:05:09 -0700 | [diff] [blame] | 66 | 'appId', |
| 67 | |
| 68 | 'groupId', |
| 69 | 'timeout', |
| 70 | 'permanent' |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 71 | ], |
| 72 | friendlyProps = [ |
Simon Hunt | 9bff595 | 2017-07-13 14:05:09 -0700 | [diff] [blame] | 73 | 'Flow ID', |
| 74 | 'State', |
| 75 | |
| 76 | 'Bytes', |
| 77 | 'Packets', |
| 78 | 'Duration', |
| 79 | |
| 80 | 'Flow Priority', |
| 81 | 'Table ID', |
Simon Hunt | 36b658d | 2017-07-14 16:20:11 -0700 | [diff] [blame] | 82 | 'App Name', |
Simon Hunt | 9bff595 | 2017-07-13 14:05:09 -0700 | [diff] [blame] | 83 | 'App ID', |
| 84 | |
| 85 | 'Group ID', |
| 86 | 'Timeout', |
| 87 | 'Permanent' |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 88 | ]; |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 89 | |
| 90 | function closePanel() { |
| 91 | if (detailsPanel.isVisible()) { |
| 92 | $scope.selId = null; |
| 93 | detailsPanel.hide(); |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | function addCloseBtn(div) { |
| 100 | is.loadEmbeddedIcon(div, 'close', 20); |
| 101 | div.on('click', closePanel); |
| 102 | } |
| 103 | |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 104 | function handleEscape() { |
| 105 | return closePanel(); |
| 106 | } |
| 107 | |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 108 | function setUpPanel() { |
| 109 | var container, closeBtn, tblDiv; |
| 110 | detailsPanel.empty(); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 111 | container = detailsPanel.append('div').classed('container', true); |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 112 | |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 113 | top = container.append('div').classed('top', true); |
| 114 | closeBtn = top.append('div').classed('close-btn', true); |
| 115 | addCloseBtn(closeBtn); |
| 116 | iconDiv = top.append('div').classed('dev-icon', true); |
| 117 | top.append('h2'); |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 118 | topTable = top.append('div').classed('top-content', true) |
| 119 | .append('table'); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 120 | top.append('hr'); |
Simon Hunt | 9bff595 | 2017-07-13 14:05:09 -0700 | [diff] [blame] | 121 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 122 | selDiv = container.append('div').classed('top', true); |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 123 | selDiv.append('h2').text('Selector'); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 124 | topSelTable = selDiv.append('div').classed('top-content', true) |
| 125 | .append('table'); |
Simon Hunt | 9bff595 | 2017-07-13 14:05:09 -0700 | [diff] [blame] | 126 | selDiv.append('hr'); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 127 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 128 | trtDiv = container.append('div').classed('top', true); |
| 129 | trtDiv.append('h2').text('Treatment'); |
| 130 | topTrtTable = trtDiv.append('div').classed('top-content', true) |
Simon Hunt | 9bff595 | 2017-07-13 14:05:09 -0700 | [diff] [blame] | 131 | .append('table'); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 132 | } |
| 133 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 134 | function addProp(tbody, label, value) { |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 135 | var tr = tbody.append('tr'); |
| 136 | |
| 137 | function addCell(cls, txt) { |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 138 | tr.append('td').attr('class', cls).text(txt); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 139 | } |
| 140 | addCell('label', label + ' :'); |
| 141 | addCell('value', value); |
| 142 | } |
| 143 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 144 | // deferred fetching of user-visible strings, so that lion context is set |
| 145 | function getLionProps() { |
| 146 | // TODO: Localization... (see cluster.js for the pattern) |
| 147 | // var l = $scope.lion; |
| 148 | // return [ |
| 149 | // l('flow_id'), |
| 150 | // ... |
| 151 | // ]; |
| 152 | return friendlyProps; |
| 153 | } |
| 154 | |
| 155 | function getLionClearDeferred() { |
| 156 | // TODO: Localization... |
| 157 | return 'Clear deferred'; |
| 158 | } |
| 159 | |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 160 | function populateTop(details) { |
| 161 | is.loadEmbeddedIcon(iconDiv, 'flowTable', 40); |
Simon Hunt | 239f09e | 2017-05-18 13:10:09 -0700 | [diff] [blame] | 162 | top.select('h2').text(details.flowId); |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 163 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 164 | var tbody = topTable.append('tbody'), |
| 165 | tbodySel = topSelTable.append('tbody'), |
| 166 | tbodyTrt = topTrtTable.append('tbody'), |
| 167 | selArray = details.selector, |
| 168 | treat = details.treatment, |
| 169 | propLabels = getLionProps(); |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 170 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 171 | function addLabVal(tbody, lv) { |
| 172 | var bits = lv.match(/^([^:]*):(.*)/); |
| 173 | addProp(tbody, bits[1], bits[2]); |
| 174 | } |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 175 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 176 | function popInstrList(items, tag) { |
| 177 | items.forEach(function (item) { |
| 178 | addLabVal(tbodyTrt, tag + item); |
| 179 | }); |
| 180 | } |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 181 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 182 | // basic flow properties |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 183 | propOrder.forEach(function (prop, i) { |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 184 | addProp(tbody, propLabels[i], details[prop]); |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 185 | }); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 186 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 187 | // selection criteria |
| 188 | selArray.forEach(function (lv) { |
| 189 | addLabVal(tbodySel, lv); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 190 | }); |
| 191 | |
Simon Hunt | 8f057ee | 2017-07-19 14:05:26 -0700 | [diff] [blame^] | 192 | // traffic treatment |
| 193 | treat.immed && popInstrList(treat.immed, '[imm]'); |
| 194 | treat.defer && popInstrList(treat.defer, '[def]'); |
| 195 | treat.meter && addLabVal(tbodyTrt, treat.meter); |
| 196 | treat.table && addLabVal(tbodyTrt, treat.table); |
| 197 | treat.meta && addLabVal(tbodyTrt, treat.meta); |
| 198 | addProp(tbodyTrt, getLionClearDeferred(), treat.clearDef); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | function createDetailsPane() { |
| 202 | detailsPanel = ps.createPanel(pName, { |
| 203 | width: wSize.width, |
| 204 | margin: 0, |
| 205 | hideMargin: 0 |
| 206 | }); |
| 207 | detailsPanel.el().style({ |
| 208 | position: 'absolute', |
| 209 | top: pStartY + 'px' |
| 210 | }); |
| 211 | $scope.hidePanel = function () { detailsPanel.hide(); }; |
| 212 | detailsPanel.hide(); |
| 213 | } |
| 214 | |
| 215 | function populateDetails(details) { |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 216 | setUpPanel(); |
| 217 | populateTop(details); |
| 218 | |
| 219 | //ToDo add more details |
| 220 | detailsPanel.height(pHeight); |
| 221 | detailsPanel.width(wtPdg); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | function respDetailsCb(data) { |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 225 | $log.debug("Got response from server :", data); |
| 226 | $scope.panelData = data.details; |
| 227 | $scope.$apply(); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 228 | } |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 229 | |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 230 | angular.module('ovFlow', []) |
| 231 | .controller('OvFlowCtrl', |
Bri Prebilic Cole | 3d4d01c | 2015-04-30 13:48:36 -0700 | [diff] [blame] | 232 | ['$log', '$scope', '$location', |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 233 | 'FnService', 'TableBuilderService', 'NavService', |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 234 | 'MastService', 'PanelService', 'KeyService', 'IconService', |
| 235 | 'WebSocketService', |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 236 | |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 237 | function (_$log_, _$scope_, _$location_, _fs_, _tbs_, _ns_, |
| 238 | _mast_, _ps_, _ks_, _is_, _wss_) { |
| 239 | var params, |
| 240 | handlers = {}; |
| 241 | |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 242 | $log = _$log_; |
| 243 | $scope = _$scope_; |
| 244 | $location = _$location_; |
| 245 | fs = _fs_; |
| 246 | tbs = _tbs_; |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 247 | ns = _ns_; |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 248 | is = _is_; |
| 249 | wss = _wss_; |
| 250 | mast = _mast_; |
| 251 | ps = _ps_; |
Simon Hunt | 20856ec | 2015-11-16 15:58:14 -0800 | [diff] [blame] | 252 | $scope.deviceTip = 'Show device table'; |
Bri Prebilic Cole | eef67ae | 2015-07-01 16:26:59 -0700 | [diff] [blame] | 253 | $scope.portTip = 'Show port view for this device'; |
| 254 | $scope.groupTip = 'Show group view for this device'; |
Jian Li | 1f54473 | 2015-12-30 23:36:37 -0800 | [diff] [blame] | 255 | $scope.meterTip = 'Show meter view for selected device'; |
Kavitha Alagesan | eaf614c | 2016-08-22 23:46:05 -0700 | [diff] [blame] | 256 | $scope.briefTip = 'Switch to brief view'; |
| 257 | $scope.detailTip = 'Switch to detailed view'; |
| 258 | $scope.brief = true; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 259 | params = $location.search(); |
| 260 | if (params.hasOwnProperty('devId')) { |
Bri Prebilic Cole | e568ead | 2015-05-01 09:51:28 -0700 | [diff] [blame] | 261 | $scope.devId = params['devId']; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | tbs.buildTable({ |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 265 | scope: $scope, |
| 266 | tag: 'flow', |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 267 | selCb: selCb, |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 268 | query: params |
| 269 | }); |
Bri Prebilic Cole | 3d4d01c | 2015-04-30 13:48:36 -0700 | [diff] [blame] | 270 | |
Bri Prebilic Cole | 9b1fb9a | 2015-07-01 13:57:11 -0700 | [diff] [blame] | 271 | $scope.nav = function (path) { |
| 272 | if ($scope.devId) { |
| 273 | ns.navTo(path, { devId: $scope.devId }); |
| 274 | } |
| 275 | }; |
| 276 | |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 277 | // details panel handlers |
| 278 | handlers[detailsResp] = respDetailsCb; |
| 279 | wss.bindHandlers(handlers); |
| 280 | |
| 281 | function selCb($event, row) { |
| 282 | if ($scope.selId) { |
| 283 | wss.sendEvent(detailsReq, {flowId: row.id, appId: row.appId}); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 284 | } else { |
| 285 | $scope.hidePanel(); |
| 286 | } |
| 287 | $log.debug('Got a click on:', row); |
| 288 | } |
| 289 | |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 290 | $scope.$on('$destroy', function () { |
| 291 | wss.unbindHandlers(handlers); |
| 292 | }); |
| 293 | |
Kavitha Alagesan | eaf614c | 2016-08-22 23:46:05 -0700 | [diff] [blame] | 294 | $scope.briefToggle = function () { |
| 295 | $scope.brief = !$scope.brief; |
| 296 | }; |
| 297 | |
sisubram | 9ada8d7 | 2016-09-02 13:54:40 +0530 | [diff] [blame] | 298 | Object.defineProperty($scope, "queryFilter", { |
| 299 | get: function() { |
Simon Hunt | c8f06d9 | 2016-09-28 17:28:26 -0700 | [diff] [blame] | 300 | var out = {}; |
| 301 | out[$scope.queryBy || "$"] = $scope.queryTxt; |
| 302 | return out; |
sisubram | 9ada8d7 | 2016-09-02 13:54:40 +0530 | [diff] [blame] | 303 | } |
| 304 | }); |
| 305 | |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 306 | $log.log('OvFlowCtrl has been created'); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 307 | }]) |
| 308 | |
| 309 | .directive('flowDetailsPanel', |
| 310 | ['$rootScope', '$window', '$timeout', 'KeyService', |
| 311 | function ($rootScope, $window, $timeout, ks) { |
| 312 | return function (scope) { |
| 313 | var unbindWatch; |
| 314 | |
| 315 | function heightCalc() { |
| 316 | pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height') |
| 317 | + mast.mastHeight() + topPdg; |
| 318 | wSize = fs.windowSize(pStartY); |
| 319 | pHeight = wSize.height; |
| 320 | } |
| 321 | |
| 322 | function initPanel() { |
| 323 | heightCalc(); |
| 324 | createDetailsPane(); |
| 325 | } |
| 326 | |
| 327 | // Safari has a bug where it renders the fixed-layout table wrong |
| 328 | // if you ask for the window's size too early |
| 329 | if (scope.onos.browser === 'safari') { |
| 330 | $timeout(initPanel); |
| 331 | } else { |
| 332 | initPanel(); |
| 333 | } |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 334 | // create key bindings to handle panel |
| 335 | ks.keyBindings({ |
| 336 | esc: [handleEscape, 'Close the details panel'], |
| 337 | _helpFormat: ['esc'] |
| 338 | }); |
| 339 | ks.gestureNotes([ |
| 340 | ['click', 'Select a row to show cluster node details'], |
| 341 | ['scroll down', 'See available cluster nodes'] |
| 342 | ]); |
| 343 | // if the panelData changes |
| 344 | scope.$watch('panelData', function () { |
| 345 | if (!fs.isEmptyObject(scope.panelData)) { |
| 346 | populateDetails(scope.panelData); |
| 347 | detailsPanel.show(); |
| 348 | } |
| 349 | }); |
Viswanath KSP | 7bdc917 | 2016-10-19 20:19:17 +0530 | [diff] [blame] | 350 | // if the window size changes |
| 351 | unbindWatch = $rootScope.$watchCollection( |
| 352 | function () { |
| 353 | return { |
| 354 | h: $window.innerHeight, |
| 355 | w: $window.innerWidth |
| 356 | }; |
| 357 | }, function () { |
| 358 | if (!fs.isEmptyObject(scope.panelData)) { |
| 359 | heightCalc(); |
| 360 | populateDetails(scope.panelData); |
| 361 | } |
| 362 | } |
| 363 | ); |
| 364 | |
| 365 | scope.$on('$destroy', function () { |
| 366 | unbindWatch(); |
| 367 | ps.destroyPanel(pName); |
| 368 | }); |
| 369 | }; |
| 370 | }]); |
| 371 | |
Simon Hunt | 1002cd8 | 2015-04-23 14:44:03 -0700 | [diff] [blame] | 372 | }()); |