blob: 096f872313be1fb36301cd759d4a94c5da300a5e [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;
24
25 // constants
26 var srcMessage = 'pceTopovSetSrc',
27 dstMessage = 'pceTopovSetDst',
28 clearMessage = 'pceTopovClear',
29 setModemsg = 'pceTopovSetMode',
30 L3dev = 'requestIpDevDetails';
31 // internal state
32 var currentMode = null;
33
34 // === ---------------------------
35 // === Helper functions
36
37 // === ---------------------------
38 // === Main API functions
39
40 function setSrc(node) {
41 wss.sendEvent(srcMessage, {
42 id: node.id,
43 type: node.type
44 });
45 flash.flash('Source node: ' + node.id);
46 }
47
48 function setDst(node) {
49 wss.sendEvent(dstMessage, {
50 id: node.id,
51 type: node.type
52 });
53 flash.flash('Destination node: ' + node.id);
54 }
55
56 function clear() {
57 wss.sendEvent(clearMessage);
58 flash.flash('Cleared source and destination');
59 }
60
61 function dOk() {
62 var bandWidth = d3.select('#band-width-box').property("checked");
63 var bandValue = null;
64 var bandType = null;
65
66 if (bandWidth) {
67
68 bandValue = d3.select('#band-width-value').property("value");
69
70 if (d3.select("#band-kpbs-val").property("checked")) {
71 bandType = 'kbps';
72 } else if (d3.select('#band-mpbs-val').property("checked")) {
73 bandType = 'mbps';
74 }
75 }
76
77 var costType = d3.select('#pce-cost-type').property("checked");
78 var costTypeVal = null;
79
80 if (costType) {
81
82 if (d3.select("#pce-cost-type-igp").property("checked")) {
83 costTypeVal = 'igp';
84 } else if (d3.select('#pce-cost-type-te').property("checked")) {
85 costTypeVal = 'te';
86 }
87 }
88
89 var lspType = d3.select('#pce-lsp-type').property("checked");
90 var lspTypeVal = null;
91
92 if (lspType) {
93
94 if (d3.select("#pce-lsp-type-cr").property("checked")) {
95 lspTypeVal = 'cr';
96 } else if (d3.select('#pce-lsp-type-srbe').property("checked")) {
97 lspTypeVal = 'srbe';
98 } else if (d3.select('#pce-lsp-type-srte').property("checked")) {
99 lspTypeVal = 'srte';
100 }
101 }
102
103 //TBD: Read the user inputs and need to send the event for calculating the path based on constrainsts.
104 // TBD: Need to read IGP cost type and LSP type.
105 //wss.sendEvent(setModemsg);
106 //flash.flash('creat path message');
107
108 $log.debug('Dialog OK button clicked');
109 }
110
111 function dClose() {
112 $log.debug('Dialog Close button clicked (or Esc pressed)');
113 }
114
115 function createUserText() {
116 var content = ds.createDiv();
117 var form = content.append('form');
118 var p = form.append('p');
119
120 //Add the bandwidth related inputs.
121 p.append('input').attr({
122 id: 'band-width-box',
123 type: 'checkbox',
124 name: 'band-width-name'
125 });
126 p.append('span').text('Band Width');
127 p.append('br');
128 p.append('input').attr({
129 id: 'band-width-value',
130 type: 'number',
131 name: 'band-width-value-name'
132 });
133 p.append('input').attr({
134 id: 'band-kpbs-val',
135 type: 'radio',
136 name: 'pce-band-type'
137 });
138 p.append('span').text('kpbs');
139 p.append('input').attr({
140 id: 'band-mpbs-val',
141 type: 'radio',
142 name: 'pce-band-type'
143 });
144 p.append('span').text('mpbs');
145 p.append('br');
146
147 //Add the cost type related inputs.
148 p.append('input').attr({
149 id: 'pce-cost-type',
150 type: 'checkbox',
151 name: 'pce-cost-type-name'
152 });
153 p.append('span').text('Cost Type');
154 p.append('br');
155 p.append('input').attr({
156 id: 'pce-cost-type-igp',
157 type: 'radio',
158 name: 'pce-cost-type-valname'
159 });
160 p.append('span').text('IGP');
161 p.append('input').attr({
162 id: 'pce-cost-type-te',
163 type: 'radio',
164 name: 'pce-cost-type-valname'
165 });
166 p.append('span').text('TE');
167 p.append('br');
168
169 //Add the LSP type related inputs.
170 p.append('input').attr({
171 id: 'pce-lsp-type',
172 type: 'checkbox',
173 name: 'pce-lsp-type-name'
174 });
175 p.append('span').text('Lsp Type');
176 p.append('br');
177 p.append('input').attr({
178 id: 'pce-lsp-type-cr',
179 type: 'radio',
180 name: 'pce-lsp-type-valname'
181 });
182 p.append('span').text('CR');
183 p.append('input').attr({
184 id: 'pce-lsp-type-srbe',
185 type: 'radio',
186 name: 'pce-lsp-type-valname'
187 });
188 p.append('span').text('SR BE');
189 p.append('input').attr({
190 id: 'pce-lsp-type-srte',
191 type: 'radio',
192 name: 'pce-lsp-type-valname'
193 });
194 p.append('span').text('SR TE');
195
196 return content;
197 }
198
199 function setMode() {
200 tds.openDialog()
201 .setTitle('constraints user')
202 .addContent(createUserText())
203 .addOk(dOk, 'OK')
204 .addCancel(dClose, 'Close')
205 .bindKeys();
206 }
207
208 // === ---------------------------
209 // === Module Factory Definition
210
211 angular.module('ovPcewebTopov', [])
212 .factory('PcewebTopovDemoService',
213 ['$log', 'FnService', 'FlashService', 'WebSocketService',
214 'TopoPanelService', 'NavService', 'TopoDialogService', 'DialogService',
215
216 function (_$log_, _fs_, _flash_, _wss_, _tps_, _ns_,_tds_, _ds_) {
217 $log = _$log_;
218 fs = _fs_;
219 flash = _flash_;
220 wss = _wss_;
221 tps = _tps_;
222 ns = _ns_;
223 tds = _tds_;
224 ds = _ds_;
225
226 return {
227 setSrc: setSrc,
228 setDst: setDst,
229 clear: clear,
230 setMode: setMode
231
232 };
233 }]);
234}());