blob: 646fd43736f82e5716da49844aa1a33dc9217203 [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-Huaweid8eaf972016-06-16 19:08:24 +053024 var tunnelNameData, tunnelNameDataRemove, tunnelDataUpdateInfo, tunnelIdUpd;
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',
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053033 updatePathmsgInfo = 'updatePathmsgInfo',
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053034 remPathmsg = 'pceTopovRem',
35 showTunnelInfoMsg = 'pceTopovShowTunnels',
36 queryDisplayTunnelMsg = 'pceTopovTunnelDisplay',
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053037 showTunnelInfoRemoveMsg = 'pceTopovShowTunnelsRem',
38 showTunnelInfoUpdateMsg = 'pceTopovShowTunnelsUpdate';
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053039 // internal state
40 var currentMode = null;
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053041 var handlerMap = {},
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053042 handlerMapRem = {},
43 handlerMapShowUpdate = {};
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053044 // === ---------------------------
45 // === Helper functions
46
47 // === ---------------------------
48 // === Main API functions
49
50 function setSrc(node) {
51 wss.sendEvent(srcMessage, {
52 id: node.id,
53 type: node.type
54 });
55 flash.flash('Source node: ' + node.id);
56 }
57
58 function setDst(node) {
59 wss.sendEvent(dstMessage, {
60 id: node.id,
61 type: node.type
62 });
63 flash.flash('Destination node: ' + node.id);
64 }
65
66 function clear() {
67 wss.sendEvent(clearMessage);
68 flash.flash('Cleared source and destination');
69 }
70
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053071 function dClose() {
72 $log.debug('Dialog Close button clicked (or Esc pressed)');
73 }
74
75 function createUserText() {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053076 var content = ds.createDiv('constraints-input'),
77 form = content.append('form'),
78 p = form.append('p');
79
80 function addAttribute(name, id, nameField, type) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +053081 if (type == 'radio') {
82 p.append('input').attr({
83 type: type,
84 name: name,
85 id: id,
86 class: 'radioButtonSpace'
87 });
88 } else {
89 p.append('input').attr({
90 type: type,
91 name: name,
92 id: id
93 });
94 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053095 p.append('span').text(nameField);
96 p.append('br');
97 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053098
99 //Add the bandwidth related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530100 addAttribute('band-width-name', 'band-width-box', 'Band Width', 'checkbox');
101 addAttribute('band-width-value-name', 'band-width-value', null, 'number');
102 addAttribute('pce-band-type', 'band-kpbs-val', 'kbps', 'radio');
103 addAttribute('pce-band-type', 'band-mpbs-val', 'mbps', 'radio');
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530104 addAttribute('pce-band-type', 'band-bps-val', 'bps', 'radio');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530105 //Add the cost type related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530106 addAttribute('pce-cost-type-name', 'pce-cost-type', 'Cost Type', 'checkbox');
107 addAttribute('pce-cost-type-valname', 'pce-cost-type-igp', 'IGP', 'radio');
108 addAttribute('pce-cost-type-valname', 'pce-cost-type-te', 'TE', 'radio');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530109 //Add the LSP type related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530110 addAttribute('pce-lsp-type-name', 'pce-lsp-type', 'Lsp Type', 'checkbox');
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530111 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-cr', 'With signalling', 'radio');
112 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srbe', 'Without SR without signalling', 'radio');
113 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srte', 'With SR without signalling', 'radio');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530114 //Add the tunnel name
115 addAttribute('pce-tunnel-name', 'pce-tunnel-name-id', 'Tunnel Name', 'text');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530116
117 return content;
118 }
119
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530120 function createUserTextUpdate(data) {
121 var content = ds.createDiv(),
122 form = content.append('form'),
123 p = form.append('p');
124
125 p.append('span').text('Tunnel IDs');
126 p.append('br');
127
128 data.a.forEach( function (val, idx) {
129 p.append('input').attr({
130 id: 'tunnel-id-'+idx,
131 type: 'radio',
132 name: 'tunnel-id-name',
133 value: val
134 });
135
136 p.append('span').text(val);
137 p.append('br');
138
139 } );
140
141 return content;
142 }
143
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530144 function createUserTextUpdatePathEvent(data) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530145 var content = ds.createDiv(),
146 form = content.append('form'),
147 p = form.append('p');
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530148 var constType;
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530149
150 function addAttribute(name, id, nameField, type) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530151 if (type == 'radio') {
152 p.append('input').attr({
153 type: type,
154 name: name,
155 id: id,
156 class: 'radioButtonSpace'
157 });
158 }
159 else {
160 p.append('input').attr({
161 type: type,
162 name: name,
163 id: id
164 });
165 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530166
167 p.append('span').text(nameField);
168 p.append('br');
169 }
170
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530171 data.a.forEach( function (val, idx) {
172 if (val == 'Tunnel') {
173 constType = 'TUNNEL';
174 return;
175 }
176
177 if (val == 'BandWidth') {
178 constType = 'BW';
179 return;
180 }
181
182 if (val == 'CostType') {
183 constType = 'CT';
184 return;
185 }
186
187 if (constType == 'TUNNEL') {
188 p.append('span').text('Tunnel Id: ');
189 p.append('span').text(val);
190 p.append('br');
191 tunnelIdUpd = val;
192 }
193
194 if (constType == 'BW') {
195 addAttribute('band-width-name', 'update-band-width-box', 'Band Width', 'checkbox');
196 p.append('input').attr({
197 id: 'update-band-width-value',
198 type: 'number',
199 name: 'band-width-value-name',
200 value: val
201 });
202 p.append('br');
203 p.append('input').attr({
204 id: 'update-band-bps-val',
205 type: 'radio',
206 name: 'pce-band-type',
207 checked: 'checked',
208 class: 'radioButtonSpace'
209 });
210 p.append('span').text('bps');
211 p.append('br');
212 addAttribute('pce-band-type', 'update-band-kbps-val', 'kbps', 'radio');
213 addAttribute('pce-band-type', 'update-band-mbps-val', 'mbps', 'radio');
214 }
215
216 if (constType == 'CT') {
217 addAttribute('pce-cost-type', 'update-pce-cost-type', 'Cost Type', 'checkbox');
218 if (val == 'COST') {
219 p.append('input').attr({
220 id: 'update-pce-cost-type-igp',
221 type: 'radio',
222 name: 'pce-cost-type-value',
223 checked: 'checked',
224 class: 'radioButtonSpace'
225 });
226 p.append('span').text('IGP');
227 p.append('br');
228 addAttribute('pce-cost-type-value', 'update-pce-cost-type-te', 'TE', 'radio');
229
230 } else {
231 addAttribute('pce-cost-type-value', 'update-pce-cost-type-igp', 'IGP', 'radio');
232 p.append('input').attr({
233 id: 'update-pce-cost-type-te',
234 type: 'radio',
235 name: 'pce-cost-type-value',
236 checked: 'checked',
237 class: 'radioButtonSpace'
238 });
239 p.append('span').text('TE');
240 p.append('br');
241 }
242 }
243 } );
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530244
245 return content;
246 }
247
248 function createUserTextRemove(data) {
249
250 var content = ds.createDiv(),
251 form = content.append('form'),
252 p = form.append('p');
253
254 p.append('span').text('Tunnel IDs');
255 p.append('br');
256
257 data.a.forEach( function (val, idx) {
258 p.append('input').attr({
259 id: 'tunnel-id-remove-'+idx,
260 type: 'checkbox',
261 name: 'tunnel-id-name-remove',
262 value: val
263 });
264
265 p.append('span').text(val);
266 p.append('br');
267 } );
268
269 return content;
270 }
271
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530272 function isChecked(cboxId) {
273 return d3.select('#' + cboxId).property('checked');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530274 }
275
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530276 function getCheckedValue(cboxId) {
277 return d3.select('#' + cboxId).property('value');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530278 }
279
280 function showTunnelInformation(data) {
281 wss.unbindHandlers(handlerMap);
282 tunnelNameData = data;
283
284 function dOkUpdate() {
285 var tdString = '' ;
286 tunnelNameData.a.forEach( function (val, idx) {
287 var tunnelName = isChecked('tunnel-id-'+idx);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530288 if (tunnelName) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530289 tdString = val;
290 }
291 } );
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530292 //send event to server for getting the tunnel information.
293 if (tdString != null) {
294 handlerMapShowUpdate[showTunnelInfoUpdateMsg] = showTunnelInfoUpdateMsgHandle;
295 wss.bindHandlers(handlerMapShowUpdate);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530296
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530297 wss.sendEvent(updatePathmsgInfo, {
298 tunnelid: tdString
299 });
300 }
301 //constraintsUpdateDialog(tdString);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530302 $log.debug('Dialog OK button clicked');
303 }
304
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530305 tds.openDialog()
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530306 .setTitle('Available LSPs with selected device')
307 .addContent(createUserTextUpdate(data))
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530308 .addOk(dOkUpdate, 'OK')
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530309 .addCancel(dClose, 'Close')
310 .bindKeys();
311 }
312
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530313 function dOkUpdateEvent() {
314 $log.debug('Select constraints for update path Dialog OK button pressed');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530315
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530316 var bandWidth = isChecked('update-band-width-box'),
317 bandValue = null,
318 bandType = null;
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530319
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530320 if (bandWidth) {
321 bandValue = getCheckedValue('update-band-width-value');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530322
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530323 if (isChecked('update-band-kbps-val')) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530324 bandType = 'kbps';
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530325 } else if (isChecked('update-band-mbps-val')) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530326 bandType = 'mbps';
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530327 } else if (isChecked('update-band-bps-val')) {
328 bandType = 'bps';
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530329 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530330 }
331
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530332 var costType = isChecked('update-pce-cost-type'),
333 costTypeVal = null;
334
335 if (costType) {
336 if (isChecked('update-pce-cost-type-igp')) {
337 costTypeVal = 'igp';
338 } else if (isChecked('update-pce-cost-type-te')) {
339 costTypeVal = 'te';
340 }
341 }
342
343 wss.sendEvent(updatePathmsg, {
344 bw: bandValue,
345 bwtype: bandType,
346 ctype: costTypeVal,
MaheshRaju-Huaweibb591072016-06-17 17:47:16 +0530347 tunnelid: tunnelIdUpd
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530348 });
349
350 flash.flash('update path message');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530351
352 }
353
354 function showTunnelInformationRemove(data) {
355
356 wss.unbindHandlers(handlerMapRem);
357 tunnelNameDataRemove = data;
358 tds.openDialog()
359 .setTitle('Available Tunnels for remove')
360 .addContent(createUserTextRemove(data))
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530361 .addOk(dOkRemove, 'OK')
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530362 .addCancel(dClose, 'Close')
363 .bindKeys();
364 }
365
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530366 function showTunnelInfoUpdateMsgHandle(data) {
367
368 wss.unbindHandlers(handlerMapShowUpdate);
369 tunnelDataUpdateInfo = data;
370 tds.openDialog()
371 .setTitle('Constrainst selection for update')
372 .addContent(createUserTextUpdatePathEvent(data))
373 .addOk(dOkUpdateEvent, 'OK')
374 .addCancel(dClose, 'Close')
375 .bindKeys();
376 }
377
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530378 //setup path
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530379 function setMode(node) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530380
381 function dOk() {
382 var bandWidth = isChecked('band-width-box'),
383 bandValue = null,
384 bandType = null;
385
386 if (bandWidth) {
387 bandValue = getCheckedValue('band-width-value');
388
389 if (isChecked('band-kpbs-val')) {
390 bandType = 'kbps';
391 } else if (isChecked('band-mpbs-val')) {
392 bandType = 'mbps';
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530393 } else if (isChecked('band-bps-val')) {
394 bandType = 'bps';
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530395 }
396 }
397
398 var costType = isChecked('pce-cost-type'),
399 costTypeVal = null;
400
401 if (costType) {
402 if (isChecked('pce-cost-type-igp')) {
403 costTypeVal = 'igp';
404 } else if (isChecked('pce-cost-type-te')) {
405 costTypeVal = 'te';
406 }
407 }
408
409 var lspType = isChecked('pce-lsp-type'),
410 lspTypeVal = null;
411
412 if (lspType) {
413 if (isChecked('pce-lsp-type-cr')) {
414 lspTypeVal = 'cr';
415 } else if (isChecked('pce-lsp-type-srbe')) {
416 lspTypeVal = 'srbe';
417 } else if (isChecked('pce-lsp-type-srte')) {
418 lspTypeVal = 'srte';
419 }
420 }
421
422 wss.sendEvent(setPathmsg, {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530423 srid: node[0],
424 dsid: node[1],
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530425 bw: bandValue,
426 bwtype: bandType,
427 ctype: costTypeVal,
428 lsptype: lspTypeVal,
429 tunnelname: getCheckedValue('pce-tunnel-name-id')
430 });
431
432 flash.flash('create path message');
433 $log.debug('Dialog OK button clicked');
434 }
435
436 tds.openDialog()
437 .setTitle('constraints selection')
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530438 .addContent(createUserText())
439 .addOk(dOk, 'OK')
440 .addCancel(dClose, 'Close')
441 .bindKeys();
442 }
443
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530444 function updatePath(node) {
445
446 wss.sendEvent(updatePathmsgQuery, {
447 srid: node[0],
448 dsid: node[1]
449 });
450
451 handlerMap[showTunnelInfoMsg] = showTunnelInformation;
452 wss.bindHandlers(handlerMap);
453
454 flash.flash('update path message');
455 }
456
457 function dOkRemove() {
458
459 tunnelNameDataRemove.a.forEach( function (val, idx) {
460 var tunnelNameVal = isChecked('tunnel-id-remove-'+idx);
461 if (tunnelNameVal) {
462 wss.sendEvent(remPathmsg, {
463 tunnelid: val
464 });
465 }
466 } );
467
468 flash.flash('remove path message');
469 }
470
471 function remPath(node) {
472 wss.sendEvent(remPathmsgQuery, {
473 srid: node[0],
474 dsid: node[1]
475 });
476
477 handlerMapRem[showTunnelInfoRemoveMsg] = showTunnelInformationRemove;
478 wss.bindHandlers(handlerMapRem);
479 }
480
481 function queryTunnelDisplay() {
482 wss.sendEvent(queryDisplayTunnelMsg);
483 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530484 // === ---------------------------
485 // === Module Factory Definition
486
487 angular.module('ovPcewebTopov', [])
488 .factory('PcewebTopovDemoService',
489 ['$log', 'FnService', 'FlashService', 'WebSocketService',
490 'TopoPanelService', 'NavService', 'TopoDialogService', 'DialogService',
491
492 function (_$log_, _fs_, _flash_, _wss_, _tps_, _ns_,_tds_, _ds_) {
493 $log = _$log_;
494 fs = _fs_;
495 flash = _flash_;
496 wss = _wss_;
497 tps = _tps_;
498 ns = _ns_;
499 tds = _tds_;
500 ds = _ds_;
501
502 return {
503 setSrc: setSrc,
504 setDst: setDst,
505 clear: clear,
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530506 setMode: setMode,
507 updatePath: updatePath,
508 remPath: remPath,
509 queryTunnelDisplay: queryTunnelDisplay
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530510 };
511 }]);
512}());