blob: 586ebea1a7c8464a71189bec36a683080f6b4880 [file] [log] [blame]
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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/*PCE topology overlay web application implementation.*/
18
19(function () {
20 'use strict';
21
22 // injected refs
23 var $log, fs, flash, wss, tps, ns, tds, ds;
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053024 var tunnelNameData, tunnelNameDataRemove;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053025 // constants
26 var srcMessage = 'pceTopovSetSrc',
27 dstMessage = 'pceTopovSetDst',
28 clearMessage = 'pceTopovClear',
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053029 setPathmsg = 'pceTopovSetMode',
30 updatePathmsgQuery = 'pceTopovUpdateQuery',
31 remPathmsgQuery = 'pceTopovRemQuery',
32 updatePathmsg = 'pceTopovUpdate',
33 remPathmsg = 'pceTopovRem',
34 showTunnelInfoMsg = 'pceTopovShowTunnels',
35 queryDisplayTunnelMsg = 'pceTopovTunnelDisplay',
36 showTunnelInfoRemoveMsg = 'pceTopovShowTunnelsRem';
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053037 // internal state
38 var currentMode = null;
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053039 var handlerMap = {},
40 handlerMapRem = {};
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053041 // === ---------------------------
42 // === Helper functions
43
44 // === ---------------------------
45 // === Main API functions
46
47 function setSrc(node) {
48 wss.sendEvent(srcMessage, {
49 id: node.id,
50 type: node.type
51 });
52 flash.flash('Source node: ' + node.id);
53 }
54
55 function setDst(node) {
56 wss.sendEvent(dstMessage, {
57 id: node.id,
58 type: node.type
59 });
60 flash.flash('Destination node: ' + node.id);
61 }
62
63 function clear() {
64 wss.sendEvent(clearMessage);
65 flash.flash('Cleared source and destination');
66 }
67
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053068 function dClose() {
69 $log.debug('Dialog Close button clicked (or Esc pressed)');
70 }
71
72 function createUserText() {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053073 var content = ds.createDiv('constraints-input'),
74 form = content.append('form'),
75 p = form.append('p');
76
77 function addAttribute(name, id, nameField, type) {
78 p.append('input').attr({
79 type: type,
80 name: name,
81 id: id
82 });
83
84 p.append('span').text(nameField);
85 p.append('br');
86 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053087
88 //Add the bandwidth related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053089 addAttribute('band-width-name', 'band-width-box', 'Band Width', 'checkbox');
90 addAttribute('band-width-value-name', 'band-width-value', null, 'number');
91 addAttribute('pce-band-type', 'band-kpbs-val', 'kbps', 'radio');
92 addAttribute('pce-band-type', 'band-mpbs-val', 'mbps', 'radio');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053093 //Add the cost type related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053094 addAttribute('pce-cost-type-name', 'pce-cost-type', 'Cost Type', 'checkbox');
95 addAttribute('pce-cost-type-valname', 'pce-cost-type-igp', 'IGP', 'radio');
96 addAttribute('pce-cost-type-valname', 'pce-cost-type-te', 'TE', 'radio');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053097 //Add the LSP type related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053098 addAttribute('pce-lsp-type-name', 'pce-lsp-type', 'Lsp Type', 'checkbox');
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053099 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-cr', 'With signalling', 'radio');
100 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srbe', 'Without SR without signalling', 'radio');
101 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srte', 'With SR without signalling', 'radio');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530102 //Add the tunnel name
103 addAttribute('pce-tunnel-name', 'pce-tunnel-name-id', 'Tunnel Name', 'text');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530104
105 return content;
106 }
107
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530108 function createUserTextUpdate(data) {
109 var content = ds.createDiv(),
110 form = content.append('form'),
111 p = form.append('p');
112
113 p.append('span').text('Tunnel IDs');
114 p.append('br');
115
116 data.a.forEach( function (val, idx) {
117 p.append('input').attr({
118 id: 'tunnel-id-'+idx,
119 type: 'radio',
120 name: 'tunnel-id-name',
121 value: val
122 });
123
124 p.append('span').text(val);
125 p.append('br');
126
127 } );
128
129 return content;
130 }
131
132 function createUserTextUpdatePathEvent() {
133 var content = ds.createDiv(),
134 form = content.append('form'),
135 p = form.append('p');
136
137 function addAttribute(name, id, nameField, type) {
138 p.append('input').attr({
139 type: type,
140 name: name,
141 id: id
142 });
143
144 p.append('span').text(nameField);
145 p.append('br');
146 }
147
148 //Add the bandwidth related inputs.
149 addAttribute('band-width-name', 'update-band-width-box', 'Band Width', 'checkbox');
150 addAttribute('band-width-value-name', 'update-band-width-value', null, 'number');
151 addAttribute('pce-band-type', 'update-band-kpbs-val', 'kbps', 'radio');
152 addAttribute('pce-band-type', 'update-band-mpbs-val', 'mbps', 'radio');
153 //Add the cost type related inputs.
154 addAttribute('pce-cost-type', 'update-pce-cost-type', 'Cost Type', 'checkbox');
155 addAttribute('pce-cost-type-value', 'update-pce-cost-type-igp', 'IGP', 'radio');
156 addAttribute('pce-cost-type-value', 'update-pce-cost-type-te', 'TE', 'radio');
157
158 return content;
159 }
160
161 function createUserTextRemove(data) {
162
163 var content = ds.createDiv(),
164 form = content.append('form'),
165 p = form.append('p');
166
167 p.append('span').text('Tunnel IDs');
168 p.append('br');
169
170 data.a.forEach( function (val, idx) {
171 p.append('input').attr({
172 id: 'tunnel-id-remove-'+idx,
173 type: 'checkbox',
174 name: 'tunnel-id-name-remove',
175 value: val
176 });
177
178 p.append('span').text(val);
179 p.append('br');
180 } );
181
182 return content;
183 }
184
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530185 function isChecked(cboxId) {
186 return d3.select('#' + cboxId).property('checked');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530187 }
188
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530189 function getCheckedValue(cboxId) {
190 return d3.select('#' + cboxId).property('value');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530191 }
192
193 function showTunnelInformation(data) {
194 wss.unbindHandlers(handlerMap);
195 tunnelNameData = data;
196
197 function dOkUpdate() {
198 var tdString = '' ;
199 tunnelNameData.a.forEach( function (val, idx) {
200 var tunnelName = isChecked('tunnel-id-'+idx);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530201 if (tunnelName) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530202 tdString = val;
203 }
204 } );
205
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530206 constraintsUpdateDialog(tdString);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530207 $log.debug('Dialog OK button clicked');
208 }
209
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530210 tds.openDialog()
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530211 .setTitle('Available LSPs with selected device')
212 .addContent(createUserTextUpdate(data))
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530213 .addOkChained(dOkUpdate, 'OK')
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530214 .addCancel(dClose, 'Close')
215 .bindKeys();
216 }
217
218 function constraintsUpdateDialog(tunnelId) {
219
220 // invoked when the OK button is pressed on this dialog
221 function dOkUpdateEvent() {
222 $log.debug('Select constraints for update path Dialog OK button pressed');
223
224 var bandWidth = isChecked('update-band-width-box'),
225 bandValue = null,
226 bandType = null;
227
228 if (bandWidth) {
229 bandValue = d3.select('#update-band-width-value');
230
231 if (isChecked('update-band-kpbs-val')) {
232 bandType = 'kbps';
233 } else if (isChecked('update-band-mpbs-val')) {
234 bandType = 'mbps';
235 }
236 }
237
238 var costType = isChecked('update-pce-cost-type'),
239 costTypeVal = null;
240
241 if (costType) {
242 if (isChecked('update-pce-cost-type-igp')) {
243 costTypeVal = 'igp';
244 } else if (isChecked('update-pce-cost-type-te')) {
245 costTypeVal = 'te';
246 }
247 }
248
249 wss.sendEvent(updatePathmsg, {
250 bw: bandValue,
251 ctype: costTypeVal,
252 tunnelname: tunnelId
253 });
254
255 flash.flash('update path message');
256
257 }
258
259 tds.openDialog()
260 .setTitle('Select constraints for update path')
261 .addContent(createUserTextUpdatePathEvent())
262 .addCancel()
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530263 .addOk(dOkUpdateEvent, 'OK') // NOTE: NOT the "chained" version!
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530264 .bindKeys();
265
266 }
267
268 function showTunnelInformationRemove(data) {
269
270 wss.unbindHandlers(handlerMapRem);
271 tunnelNameDataRemove = data;
272 tds.openDialog()
273 .setTitle('Available Tunnels for remove')
274 .addContent(createUserTextRemove(data))
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530275 .addOk(dOkRemove, 'OK')
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530276 .addCancel(dClose, 'Close')
277 .bindKeys();
278 }
279
280 //setup path
281 function setMode() {
282
283 function dOk() {
284 var bandWidth = isChecked('band-width-box'),
285 bandValue = null,
286 bandType = null;
287
288 if (bandWidth) {
289 bandValue = getCheckedValue('band-width-value');
290
291 if (isChecked('band-kpbs-val')) {
292 bandType = 'kbps';
293 } else if (isChecked('band-mpbs-val')) {
294 bandType = 'mbps';
295 }
296 }
297
298 var costType = isChecked('pce-cost-type'),
299 costTypeVal = null;
300
301 if (costType) {
302 if (isChecked('pce-cost-type-igp')) {
303 costTypeVal = 'igp';
304 } else if (isChecked('pce-cost-type-te')) {
305 costTypeVal = 'te';
306 }
307 }
308
309 var lspType = isChecked('pce-lsp-type'),
310 lspTypeVal = null;
311
312 if (lspType) {
313 if (isChecked('pce-lsp-type-cr')) {
314 lspTypeVal = 'cr';
315 } else if (isChecked('pce-lsp-type-srbe')) {
316 lspTypeVal = 'srbe';
317 } else if (isChecked('pce-lsp-type-srte')) {
318 lspTypeVal = 'srte';
319 }
320 }
321
322 wss.sendEvent(setPathmsg, {
323 bw: bandValue,
324 bwtype: bandType,
325 ctype: costTypeVal,
326 lsptype: lspTypeVal,
327 tunnelname: getCheckedValue('pce-tunnel-name-id')
328 });
329
330 flash.flash('create path message');
331 $log.debug('Dialog OK button clicked');
332 }
333
334 tds.openDialog()
335 .setTitle('constraints selection')
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530336 .addContent(createUserText())
337 .addOk(dOk, 'OK')
338 .addCancel(dClose, 'Close')
339 .bindKeys();
340 }
341
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530342 function updatePath(node) {
343
344 wss.sendEvent(updatePathmsgQuery, {
345 srid: node[0],
346 dsid: node[1]
347 });
348
349 handlerMap[showTunnelInfoMsg] = showTunnelInformation;
350 wss.bindHandlers(handlerMap);
351
352 flash.flash('update path message');
353 }
354
355 function dOkRemove() {
356
357 tunnelNameDataRemove.a.forEach( function (val, idx) {
358 var tunnelNameVal = isChecked('tunnel-id-remove-'+idx);
359 if (tunnelNameVal) {
360 wss.sendEvent(remPathmsg, {
361 tunnelid: val
362 });
363 }
364 } );
365
366 flash.flash('remove path message');
367 }
368
369 function remPath(node) {
370 wss.sendEvent(remPathmsgQuery, {
371 srid: node[0],
372 dsid: node[1]
373 });
374
375 handlerMapRem[showTunnelInfoRemoveMsg] = showTunnelInformationRemove;
376 wss.bindHandlers(handlerMapRem);
377 }
378
379 function queryTunnelDisplay() {
380 wss.sendEvent(queryDisplayTunnelMsg);
381 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530382 // === ---------------------------
383 // === Module Factory Definition
384
385 angular.module('ovPcewebTopov', [])
386 .factory('PcewebTopovDemoService',
387 ['$log', 'FnService', 'FlashService', 'WebSocketService',
388 'TopoPanelService', 'NavService', 'TopoDialogService', 'DialogService',
389
390 function (_$log_, _fs_, _flash_, _wss_, _tps_, _ns_,_tds_, _ds_) {
391 $log = _$log_;
392 fs = _fs_;
393 flash = _flash_;
394 wss = _wss_;
395 tps = _tps_;
396 ns = _ns_;
397 tds = _tds_;
398 ds = _ds_;
399
400 return {
401 setSrc: setSrc,
402 setDst: setDst,
403 clear: clear,
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530404 setMode: setMode,
405 updatePath: updatePath,
406 remPath: remPath,
407 queryTunnelDisplay: queryTunnelDisplay
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530408 };
409 }]);
410}());