daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | /* OpenStack Networking UI Overlay description */ |
| 18 | (function () { |
| 19 | 'use strict'; |
| 20 | |
| 21 | // injected refs |
| 22 | var $log, tov, sts, flash, ds, wss; |
| 23 | var traceSrc = null; |
| 24 | var traceDst = null; |
Daniel Park | 577b69c | 2018-07-16 17:29:34 +0900 | [diff] [blame] | 25 | var srcDeviceId = null; |
| 26 | var dstDeviceId = null; |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 27 | |
| 28 | var traceInfoDialogId = 'traceInfoDialogId', |
Daniel Park | 4e037f5 | 2018-09-20 18:04:18 +0900 | [diff] [blame] | 29 | traceInfoDialogOpt = { |
boyoung2 | 7b44412 | 2018-09-01 17:28:13 +0900 | [diff] [blame] | 30 | width: 350, |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 31 | edge: 'left', |
| 32 | margin: 20, |
| 33 | hideMargin: -20 |
| 34 | } |
| 35 | |
| 36 | var overlay = { |
| 37 | // NOTE: this must match the ID defined in AppUiTopovOverlay |
| 38 | overlayId: 'sona-overlay', |
| 39 | glyphId: '*star4', |
| 40 | tooltip: 'OpenstackNetworking UI', |
| 41 | |
| 42 | glyphs: { |
| 43 | star4: { |
| 44 | vb: '0 0 8 8', |
| 45 | d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z' |
| 46 | }, |
| 47 | banner: { |
| 48 | vb: '0 0 6 6', |
| 49 | d: 'M1,1v4l2,-2l2,2v-4z' |
| 50 | } |
| 51 | }, |
| 52 | |
| 53 | activate: function () { |
| 54 | $log.debug("OpenstackNetworking UI ACTIVATED"); |
| 55 | }, |
| 56 | deactivate: function () { |
| 57 | sts.stopDisplay(); |
| 58 | $log.debug("OpenstackNetworking UI DEACTIVATED"); |
| 59 | }, |
| 60 | |
| 61 | // detail panel button definitions |
| 62 | buttons: { |
| 63 | flowtrace: { |
| 64 | gid: 'checkMark', |
| 65 | tt: 'Flow Trace', |
| 66 | cb: function (data) { |
| 67 | |
| 68 | if (traceSrc == null && data.navPath == 'host') { |
Daniel Park | 577b69c | 2018-07-16 17:29:34 +0900 | [diff] [blame] | 69 | traceSrc = data.propValues.ip; |
| 70 | srcDeviceId = data.propValues.DeviceId |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 71 | |
| 72 | flash.flash('Src ' + traceSrc + ' selected. Please select the dst'); |
| 73 | } else if (traceDst == null && data.title != traceSrc && data.navPath == 'host') { |
Daniel Park | 577b69c | 2018-07-16 17:29:34 +0900 | [diff] [blame] | 74 | traceDst = data.propValues.ip; |
| 75 | dstDeviceId = data.propValues.DeviceId; |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 76 | openTraceInfoDialog(); |
| 77 | flash.flash('Dst ' + traceDst + ' selected. Press Request button'); |
| 78 | } |
| 79 | |
| 80 | $log.debug('Perform flow trace test between VMs:', data); |
| 81 | } |
| 82 | }, |
| 83 | |
| 84 | reset: { |
| 85 | gid: 'xMark', |
| 86 | tt: 'Reset', |
| 87 | cb: function (data) { |
| 88 | flash.flash('Reset flow trace'); |
| 89 | traceSrc = null; |
| 90 | traceDst = null; |
| 91 | ds.closeDialog(); |
| 92 | $log.debug('BAR action invoked with data:', data); |
| 93 | } |
| 94 | }, |
| 95 | toGateway: { |
| 96 | gid: 'm_switch', |
| 97 | tt: 'Trace to Gateway', |
| 98 | cb: function (data) { |
| 99 | if (traceSrc != null && data.title == traceSrc && data.navPath == 'host') { |
| 100 | //Set traceSrc to traceDst in case trace to gateway |
| 101 | traceDst = traceSrc; |
Daniel Park | 577b69c | 2018-07-16 17:29:34 +0900 | [diff] [blame] | 102 | dstDeviceId = 'toGateway'; |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 103 | openTraceInfoDialog(); |
| 104 | flash.flash('Trace to Gateway'); |
| 105 | } |
| 106 | } |
| 107 | }, |
| 108 | toExternal: { |
| 109 | gid: 'm_cloud', |
| 110 | tt: 'Trace to External', |
| 111 | cb: function (data) { |
| 112 | if (traceSrc != null && data.title == traceSrc && data.navPath == 'host') { |
| 113 | //Set traceDst to 8.8.8.8 to check external connection |
| 114 | traceDst = '8.8.8.8'; |
Daniel Park | 577b69c | 2018-07-16 17:29:34 +0900 | [diff] [blame] | 115 | dstDeviceId = 'toExternal'; |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 116 | openTraceInfoDialog(); |
| 117 | flash.flash('Trace to External') |
| 118 | } |
| 119 | } |
boyoung2 | 7b44412 | 2018-09-01 17:28:13 +0900 | [diff] [blame] | 120 | }, |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 121 | }, |
| 122 | |
| 123 | keyBindings: { |
| 124 | 0: { |
| 125 | cb: function () { sts.stopDisplay(); }, |
| 126 | tt: 'Cancel OpenstackNetworking UI Overlay Mode', |
| 127 | gid: 'xMark' |
| 128 | }, |
| 129 | V: { |
| 130 | cb: function () { |
| 131 | wss.bindHandlers({ |
| 132 | flowTraceResult: sts, |
| 133 | }); |
| 134 | sts.startDisplay('mouse'); |
| 135 | }, |
| 136 | tt: 'Start OpenstackNetworking UI Overlay Mode', |
| 137 | gid: 'crown' |
| 138 | }, |
| 139 | |
| 140 | _keyOrder: [ |
| 141 | '0', 'V' |
| 142 | ] |
| 143 | }, |
| 144 | |
| 145 | hooks: { |
| 146 | // hook for handling escape key |
| 147 | // Must return true to consume ESC, false otherwise. |
| 148 | escape: function () { |
| 149 | // Must return true to consume ESC, false otherwise. |
| 150 | return sts.stopDisplay(); |
| 151 | }, |
| 152 | mouseover: function (m) { |
| 153 | // m has id, class, and type properties |
| 154 | $log.debug('mouseover:', m); |
| 155 | sts.updateDisplay(m); |
| 156 | }, |
| 157 | mouseout: function () { |
| 158 | $log.debug('mouseout'); |
| 159 | sts.updateDisplay(); |
| 160 | } |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | function openTraceInfoDialog() { |
| 165 | ds.openDialog(traceInfoDialogId, traceInfoDialogOpt) |
| 166 | .setTitle('Flow Trace Information') |
| 167 | .addContent(createTraceInfoDiv(traceSrc, traceDst)) |
| 168 | .addOk(flowTraceResultBtn, 'Request') |
| 169 | .bindKeys(); |
| 170 | } |
| 171 | |
| 172 | function createTraceInfoDiv(src, dst) { |
| 173 | var texts = ds.createDiv('traceInfo'); |
| 174 | texts.append('hr'); |
| 175 | texts.append('table').append('tbody').append('tr'); |
| 176 | |
| 177 | var tBodySelection = texts.select('table').select('tbody').select('tr'); |
| 178 | |
| 179 | tBodySelection.append('td').text('Source IP:').attr("class", "label"); |
| 180 | tBodySelection.append('td').text(src).attr("class", "value"); |
| 181 | |
| 182 | texts.select('table').select('tbody').append('tr'); |
| 183 | |
| 184 | tBodySelection = texts.select('table').select('tbody').select('tr:nth-child(2)'); |
| 185 | |
| 186 | tBodySelection.append('td').text('Destination IP:').attr("class", "label"); |
| 187 | if (dst == src) { |
| 188 | tBodySelection.append('td').text('toGateway').attr("class", "value"); |
| 189 | } else { |
| 190 | tBodySelection.append('td').text(dst).attr("class", "value"); |
| 191 | } |
| 192 | |
Daniel Park | 577b69c | 2018-07-16 17:29:34 +0900 | [diff] [blame] | 193 | texts.select('table').select('tbody').append('tr'); |
| 194 | tBodySelection = texts.select('table').select('tbody').select('tr:nth-child(3)'); |
| 195 | tBodySelection.append('td').text('SrcDeviceId').attr("class", "label"); |
| 196 | tBodySelection.append('td').text(srcDeviceId).attr("class", "value"); |
| 197 | |
| 198 | texts.select('table').select('tbody').append('tr'); |
| 199 | tBodySelection = texts.select('table').select('tbody').select('tr:nth-child(4)'); |
| 200 | tBodySelection.append('td').text('DstDeviceId').attr("class", "label"); |
| 201 | tBodySelection.append('td').text(dstDeviceId).attr("class", "value"); |
| 202 | |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 203 | texts.append('hr'); |
| 204 | |
| 205 | return texts; |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | function flowTraceResultBtn() { |
Daniel Park | 4e037f5 | 2018-09-20 18:04:18 +0900 | [diff] [blame] | 209 | sts.sendFlowTraceRequest(traceSrc, traceDst, srcDeviceId, dstDeviceId, true); |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 210 | ds.closeDialog(); |
| 211 | traceSrc = null; |
| 212 | traceDst = null; |
| 213 | flash.flash('Send Flow Trace Request'); |
| 214 | } |
| 215 | |
| 216 | function buttonCallback(x) { |
| 217 | $log.debug('Toolbar-button callback', x); |
| 218 | } |
| 219 | |
| 220 | // invoke code to register with the overlay service |
| 221 | angular.module('ovSonaTopov') |
| 222 | .run(['$log', 'TopoOverlayService', 'SonaTopovService', |
| 223 | 'FlashService', 'DialogService', 'WebSocketService', |
| 224 | |
| 225 | function (_$log_, _tov_, _sts_, _flash_, _ds_, _wss_) { |
| 226 | $log = _$log_; |
| 227 | tov = _tov_; |
| 228 | sts = _sts_; |
| 229 | flash = _flash_; |
| 230 | ds = _ds_; |
| 231 | wss = _wss_; |
| 232 | tov.register(overlay); |
| 233 | }]); |
| 234 | |
| 235 | }()); |