blob: bf7723d8654d529707f404ad88e6ef46fcfa6445 [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) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +053078 if (type == 'radio') {
79 p.append('input').attr({
80 type: type,
81 name: name,
82 id: id,
83 class: 'radioButtonSpace'
84 });
85 } else {
86 p.append('input').attr({
87 type: type,
88 name: name,
89 id: id
90 });
91 }
92
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053093
94 p.append('span').text(nameField);
95 p.append('br');
96 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053097
98 //Add the bandwidth related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +053099 addAttribute('band-width-name', 'band-width-box', 'Band Width', 'checkbox');
100 addAttribute('band-width-value-name', 'band-width-value', null, 'number');
101 addAttribute('pce-band-type', 'band-kpbs-val', 'kbps', 'radio');
102 addAttribute('pce-band-type', 'band-mpbs-val', 'mbps', 'radio');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530103 //Add the cost type related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530104 addAttribute('pce-cost-type-name', 'pce-cost-type', 'Cost Type', 'checkbox');
105 addAttribute('pce-cost-type-valname', 'pce-cost-type-igp', 'IGP', 'radio');
106 addAttribute('pce-cost-type-valname', 'pce-cost-type-te', 'TE', 'radio');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530107 //Add the LSP type related inputs.
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530108 addAttribute('pce-lsp-type-name', 'pce-lsp-type', 'Lsp Type', 'checkbox');
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530109 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-cr', 'With signalling', 'radio');
110 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srbe', 'Without SR without signalling', 'radio');
111 addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srte', 'With SR without signalling', 'radio');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530112 //Add the tunnel name
113 addAttribute('pce-tunnel-name', 'pce-tunnel-name-id', 'Tunnel Name', 'text');
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530114
115 return content;
116 }
117
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530118 function createUserTextUpdate(data) {
119 var content = ds.createDiv(),
120 form = content.append('form'),
121 p = form.append('p');
122
123 p.append('span').text('Tunnel IDs');
124 p.append('br');
125
126 data.a.forEach( function (val, idx) {
127 p.append('input').attr({
128 id: 'tunnel-id-'+idx,
129 type: 'radio',
130 name: 'tunnel-id-name',
131 value: val
132 });
133
134 p.append('span').text(val);
135 p.append('br');
136
137 } );
138
139 return content;
140 }
141
142 function createUserTextUpdatePathEvent() {
143 var content = ds.createDiv(),
144 form = content.append('form'),
145 p = form.append('p');
146
147 function addAttribute(name, id, nameField, type) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530148 if (type == 'radio') {
149 p.append('input').attr({
150 type: type,
151 name: name,
152 id: id,
153 class: 'radioButtonSpace'
154 });
155 }
156 else {
157 p.append('input').attr({
158 type: type,
159 name: name,
160 id: id
161 });
162 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530163
164 p.append('span').text(nameField);
165 p.append('br');
166 }
167
168 //Add the bandwidth related inputs.
169 addAttribute('band-width-name', 'update-band-width-box', 'Band Width', 'checkbox');
170 addAttribute('band-width-value-name', 'update-band-width-value', null, 'number');
171 addAttribute('pce-band-type', 'update-band-kpbs-val', 'kbps', 'radio');
172 addAttribute('pce-band-type', 'update-band-mpbs-val', 'mbps', 'radio');
173 //Add the cost type related inputs.
174 addAttribute('pce-cost-type', 'update-pce-cost-type', 'Cost Type', 'checkbox');
175 addAttribute('pce-cost-type-value', 'update-pce-cost-type-igp', 'IGP', 'radio');
176 addAttribute('pce-cost-type-value', 'update-pce-cost-type-te', 'TE', 'radio');
177
178 return content;
179 }
180
181 function createUserTextRemove(data) {
182
183 var content = ds.createDiv(),
184 form = content.append('form'),
185 p = form.append('p');
186
187 p.append('span').text('Tunnel IDs');
188 p.append('br');
189
190 data.a.forEach( function (val, idx) {
191 p.append('input').attr({
192 id: 'tunnel-id-remove-'+idx,
193 type: 'checkbox',
194 name: 'tunnel-id-name-remove',
195 value: val
196 });
197
198 p.append('span').text(val);
199 p.append('br');
200 } );
201
202 return content;
203 }
204
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530205 function isChecked(cboxId) {
206 return d3.select('#' + cboxId).property('checked');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530207 }
208
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530209 function getCheckedValue(cboxId) {
210 return d3.select('#' + cboxId).property('value');
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530211 }
212
213 function showTunnelInformation(data) {
214 wss.unbindHandlers(handlerMap);
215 tunnelNameData = data;
216
217 function dOkUpdate() {
218 var tdString = '' ;
219 tunnelNameData.a.forEach( function (val, idx) {
220 var tunnelName = isChecked('tunnel-id-'+idx);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530221 if (tunnelName) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530222 tdString = val;
223 }
224 } );
225
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530226 constraintsUpdateDialog(tdString);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530227 $log.debug('Dialog OK button clicked');
228 }
229
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530230 tds.openDialog()
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530231 .setTitle('Available LSPs with selected device')
232 .addContent(createUserTextUpdate(data))
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530233 .addOkChained(dOkUpdate, 'OK')
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530234 .addCancel(dClose, 'Close')
235 .bindKeys();
236 }
237
238 function constraintsUpdateDialog(tunnelId) {
239
240 // invoked when the OK button is pressed on this dialog
241 function dOkUpdateEvent() {
242 $log.debug('Select constraints for update path Dialog OK button pressed');
243
244 var bandWidth = isChecked('update-band-width-box'),
245 bandValue = null,
246 bandType = null;
247
248 if (bandWidth) {
249 bandValue = d3.select('#update-band-width-value');
250
251 if (isChecked('update-band-kpbs-val')) {
252 bandType = 'kbps';
253 } else if (isChecked('update-band-mpbs-val')) {
254 bandType = 'mbps';
255 }
256 }
257
258 var costType = isChecked('update-pce-cost-type'),
259 costTypeVal = null;
260
261 if (costType) {
262 if (isChecked('update-pce-cost-type-igp')) {
263 costTypeVal = 'igp';
264 } else if (isChecked('update-pce-cost-type-te')) {
265 costTypeVal = 'te';
266 }
267 }
268
269 wss.sendEvent(updatePathmsg, {
270 bw: bandValue,
271 ctype: costTypeVal,
272 tunnelname: tunnelId
273 });
274
275 flash.flash('update path message');
276
277 }
278
279 tds.openDialog()
280 .setTitle('Select constraints for update path')
281 .addContent(createUserTextUpdatePathEvent())
282 .addCancel()
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530283 .addOk(dOkUpdateEvent, 'OK') // NOTE: NOT the "chained" version!
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530284 .bindKeys();
285
286 }
287
288 function showTunnelInformationRemove(data) {
289
290 wss.unbindHandlers(handlerMapRem);
291 tunnelNameDataRemove = data;
292 tds.openDialog()
293 .setTitle('Available Tunnels for remove')
294 .addContent(createUserTextRemove(data))
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530295 .addOk(dOkRemove, 'OK')
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530296 .addCancel(dClose, 'Close')
297 .bindKeys();
298 }
299
300 //setup path
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530301 function setMode(node) {
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530302
303 function dOk() {
304 var bandWidth = isChecked('band-width-box'),
305 bandValue = null,
306 bandType = null;
307
308 if (bandWidth) {
309 bandValue = getCheckedValue('band-width-value');
310
311 if (isChecked('band-kpbs-val')) {
312 bandType = 'kbps';
313 } else if (isChecked('band-mpbs-val')) {
314 bandType = 'mbps';
315 }
316 }
317
318 var costType = isChecked('pce-cost-type'),
319 costTypeVal = null;
320
321 if (costType) {
322 if (isChecked('pce-cost-type-igp')) {
323 costTypeVal = 'igp';
324 } else if (isChecked('pce-cost-type-te')) {
325 costTypeVal = 'te';
326 }
327 }
328
329 var lspType = isChecked('pce-lsp-type'),
330 lspTypeVal = null;
331
332 if (lspType) {
333 if (isChecked('pce-lsp-type-cr')) {
334 lspTypeVal = 'cr';
335 } else if (isChecked('pce-lsp-type-srbe')) {
336 lspTypeVal = 'srbe';
337 } else if (isChecked('pce-lsp-type-srte')) {
338 lspTypeVal = 'srte';
339 }
340 }
341
342 wss.sendEvent(setPathmsg, {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530343 srid: node[0],
344 dsid: node[1],
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530345 bw: bandValue,
346 bwtype: bandType,
347 ctype: costTypeVal,
348 lsptype: lspTypeVal,
349 tunnelname: getCheckedValue('pce-tunnel-name-id')
350 });
351
352 flash.flash('create path message');
353 $log.debug('Dialog OK button clicked');
354 }
355
356 tds.openDialog()
357 .setTitle('constraints selection')
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530358 .addContent(createUserText())
359 .addOk(dOk, 'OK')
360 .addCancel(dClose, 'Close')
361 .bindKeys();
362 }
363
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530364 function updatePath(node) {
365
366 wss.sendEvent(updatePathmsgQuery, {
367 srid: node[0],
368 dsid: node[1]
369 });
370
371 handlerMap[showTunnelInfoMsg] = showTunnelInformation;
372 wss.bindHandlers(handlerMap);
373
374 flash.flash('update path message');
375 }
376
377 function dOkRemove() {
378
379 tunnelNameDataRemove.a.forEach( function (val, idx) {
380 var tunnelNameVal = isChecked('tunnel-id-remove-'+idx);
381 if (tunnelNameVal) {
382 wss.sendEvent(remPathmsg, {
383 tunnelid: val
384 });
385 }
386 } );
387
388 flash.flash('remove path message');
389 }
390
391 function remPath(node) {
392 wss.sendEvent(remPathmsgQuery, {
393 srid: node[0],
394 dsid: node[1]
395 });
396
397 handlerMapRem[showTunnelInfoRemoveMsg] = showTunnelInformationRemove;
398 wss.bindHandlers(handlerMapRem);
399 }
400
401 function queryTunnelDisplay() {
402 wss.sendEvent(queryDisplayTunnelMsg);
403 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530404 // === ---------------------------
405 // === Module Factory Definition
406
407 angular.module('ovPcewebTopov', [])
408 .factory('PcewebTopovDemoService',
409 ['$log', 'FnService', 'FlashService', 'WebSocketService',
410 'TopoPanelService', 'NavService', 'TopoDialogService', 'DialogService',
411
412 function (_$log_, _fs_, _flash_, _wss_, _tps_, _ns_,_tds_, _ds_) {
413 $log = _$log_;
414 fs = _fs_;
415 flash = _flash_;
416 wss = _wss_;
417 tps = _tps_;
418 ns = _ns_;
419 tds = _tds_;
420 ds = _ds_;
421
422 return {
423 setSrc: setSrc,
424 setDst: setDst,
425 clear: clear,
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530426 setMode: setMode,
427 updatePath: updatePath,
428 remPath: remPath,
429 queryTunnelDisplay: queryTunnelDisplay
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530430 };
431 }]);
432}());