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