blob: e16e15bdb616c7d5e2b786848c1ef377047ca3e9 [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');
99 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');
102 //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
185 function isChecked(viewId) {
186 return d3.select('#' + viewId).property('checked');
187 }
188
189 function getCheckedValue(viewId) {
190 return d3.select('#' + viewId).property('value');
191 }
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);
201 if (tunnelName)
202 {
203 tdString = val;
204 }
205 } );
206
207 if (tdString) {
208 constraintsUpdateDialog(tdString);
209 } else {
210 $log.debug("No tunnel id is selected.");
211 }
212
213 $log.debug('Dialog OK button clicked');
214 }
215
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530216 tds.openDialog()
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530217 .setTitle('Available LSPs with selected device')
218 .addContent(createUserTextUpdate(data))
219 .addOkChained(dOkUpdate, 'GOTO Selection of constraints')
220 .addCancel(dClose, 'Close')
221 .bindKeys();
222 }
223
224 function constraintsUpdateDialog(tunnelId) {
225
226 // invoked when the OK button is pressed on this dialog
227 function dOkUpdateEvent() {
228 $log.debug('Select constraints for update path Dialog OK button pressed');
229
230 var bandWidth = isChecked('update-band-width-box'),
231 bandValue = null,
232 bandType = null;
233
234 if (bandWidth) {
235 bandValue = d3.select('#update-band-width-value');
236
237 if (isChecked('update-band-kpbs-val')) {
238 bandType = 'kbps';
239 } else if (isChecked('update-band-mpbs-val')) {
240 bandType = 'mbps';
241 }
242 }
243
244 var costType = isChecked('update-pce-cost-type'),
245 costTypeVal = null;
246
247 if (costType) {
248 if (isChecked('update-pce-cost-type-igp')) {
249 costTypeVal = 'igp';
250 } else if (isChecked('update-pce-cost-type-te')) {
251 costTypeVal = 'te';
252 }
253 }
254
255 wss.sendEvent(updatePathmsg, {
256 bw: bandValue,
257 ctype: costTypeVal,
258 tunnelname: tunnelId
259 });
260
261 flash.flash('update path message');
262
263 }
264
265 tds.openDialog()
266 .setTitle('Select constraints for update path')
267 .addContent(createUserTextUpdatePathEvent())
268 .addCancel()
269 .addOk(dOkUpdateEvent, 'Update Path') // NOTE: NOT the "chained" version!
270 .bindKeys();
271
272 }
273
274 function showTunnelInformationRemove(data) {
275
276 wss.unbindHandlers(handlerMapRem);
277 tunnelNameDataRemove = data;
278 tds.openDialog()
279 .setTitle('Available Tunnels for remove')
280 .addContent(createUserTextRemove(data))
281 .addOk(dOkRemove, 'Remove')
282 .addCancel(dClose, 'Close')
283 .bindKeys();
284 }
285
286 //setup path
287 function setMode() {
288
289 function dOk() {
290 var bandWidth = isChecked('band-width-box'),
291 bandValue = null,
292 bandType = null;
293
294 if (bandWidth) {
295 bandValue = getCheckedValue('band-width-value');
296
297 if (isChecked('band-kpbs-val')) {
298 bandType = 'kbps';
299 } else if (isChecked('band-mpbs-val')) {
300 bandType = 'mbps';
301 }
302 }
303
304 var costType = isChecked('pce-cost-type'),
305 costTypeVal = null;
306
307 if (costType) {
308 if (isChecked('pce-cost-type-igp')) {
309 costTypeVal = 'igp';
310 } else if (isChecked('pce-cost-type-te')) {
311 costTypeVal = 'te';
312 }
313 }
314
315 var lspType = isChecked('pce-lsp-type'),
316 lspTypeVal = null;
317
318 if (lspType) {
319 if (isChecked('pce-lsp-type-cr')) {
320 lspTypeVal = 'cr';
321 } else if (isChecked('pce-lsp-type-srbe')) {
322 lspTypeVal = 'srbe';
323 } else if (isChecked('pce-lsp-type-srte')) {
324 lspTypeVal = 'srte';
325 }
326 }
327
328 wss.sendEvent(setPathmsg, {
329 bw: bandValue,
330 bwtype: bandType,
331 ctype: costTypeVal,
332 lsptype: lspTypeVal,
333 tunnelname: getCheckedValue('pce-tunnel-name-id')
334 });
335
336 flash.flash('create path message');
337 $log.debug('Dialog OK button clicked');
338 }
339
340 tds.openDialog()
341 .setTitle('constraints selection')
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530342 .addContent(createUserText())
343 .addOk(dOk, 'OK')
344 .addCancel(dClose, 'Close')
345 .bindKeys();
346 }
347
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530348 function updatePath(node) {
349
350 wss.sendEvent(updatePathmsgQuery, {
351 srid: node[0],
352 dsid: node[1]
353 });
354
355 handlerMap[showTunnelInfoMsg] = showTunnelInformation;
356 wss.bindHandlers(handlerMap);
357
358 flash.flash('update path message');
359 }
360
361 function dOkRemove() {
362
363 tunnelNameDataRemove.a.forEach( function (val, idx) {
364 var tunnelNameVal = isChecked('tunnel-id-remove-'+idx);
365 if (tunnelNameVal) {
366 wss.sendEvent(remPathmsg, {
367 tunnelid: val
368 });
369 }
370 } );
371
372 flash.flash('remove path message');
373 }
374
375 function remPath(node) {
376 wss.sendEvent(remPathmsgQuery, {
377 srid: node[0],
378 dsid: node[1]
379 });
380
381 handlerMapRem[showTunnelInfoRemoveMsg] = showTunnelInformationRemove;
382 wss.bindHandlers(handlerMapRem);
383 }
384
385 function queryTunnelDisplay() {
386 wss.sendEvent(queryDisplayTunnelMsg);
387 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530388 // === ---------------------------
389 // === Module Factory Definition
390
391 angular.module('ovPcewebTopov', [])
392 .factory('PcewebTopovDemoService',
393 ['$log', 'FnService', 'FlashService', 'WebSocketService',
394 'TopoPanelService', 'NavService', 'TopoDialogService', 'DialogService',
395
396 function (_$log_, _fs_, _flash_, _wss_, _tps_, _ns_,_tds_, _ds_) {
397 $log = _$log_;
398 fs = _fs_;
399 flash = _flash_;
400 wss = _wss_;
401 tps = _tps_;
402 ns = _ns_;
403 tds = _tds_;
404 ds = _ds_;
405
406 return {
407 setSrc: setSrc,
408 setDst: setDst,
409 clear: clear,
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530410 setMode: setMode,
411 updatePath: updatePath,
412 remPath: remPath,
413 queryTunnelDisplay: queryTunnelDisplay
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530414 };
415 }]);
416}());