1 define(['app/cpeui/cpeui.module'],function(cpeui) {
3 cpeui.factory('CpeuiSvc', function($http, Utils) {
4 var baseUrl = "/restconf/config/mef-global:mef-global/";
7 svc.getTenantList = function(callback) {
11 url:baseUrl + "tenants-instances"
12 }).then(function successCallback(response) {
13 tenantList = response.data["tenants-instances"]["tenant-list"];
14 if (callback != undefined) {
17 }, function errorCallback(response) {
18 if (response.status == 404) {
21 console.log(response);
26 svc.addTenant = function(name, callback){
29 url:baseUrl + "tenants-instances/",
30 data: {"tenant-list":[{
33 }).then(function successCallback(response) {
34 if (callback != undefined) {
39 svc.deleteTenant = function(id, callback) {
42 url:baseUrl + "tenants-instances/tenant-list/" + id + "/",
43 }).then(function successCallback(response) {
44 if (callback != undefined) {
51 svc.getProfiles = function(callback) {
54 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/"
55 }).then(function successCallback(response) {
56 if (callback != undefined) {
57 callback(response.data["ingress-bwp-flows"]["bwp-flow"]);
59 }, function errorCallback(response) {
60 if (response.status == 404) {
63 console.log(response);
67 svc.addProfile = function(name, cir, cbs, callback){
70 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/",
76 }).then(function successCallback(response) {
77 if (callback != undefined) {
83 svc.editProfile = function(name, cir, cbs, callback){
86 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/bwp-flow/"+name,
92 }).then(function successCallback(response) {
93 if (callback != undefined) {
99 svc.deleteProfile = function(name, callback) {
102 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/bwp-flow/"+name,
103 }).then(function successCallback(response) {
104 if (callback != undefined) {
111 svc.addCe = function(id, name, callback) {
114 url:"/restconf/config/mef-topology:mef-topology/devices/",
121 "interfaces": {"interface": []}
126 }).then(function successCallback(response) {
127 if (callback != undefined) {
133 svc.addCeName = function(ce, new_name, callback) {
136 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id'],
137 data: {"device-name": new_name}
138 }).then(function successCallback(response) {
139 if (callback != undefined) {
142 }, function errorCallback(response) {
143 console.log(response);
146 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id']
147 }).then(function successCallback(response) {
148 ce["device-name"] = response.data["device"][0]["device-name"];
153 svc.getCes = function(callback) {
159 url:"/restconf/operational/mef-topology:mef-topology/devices/"
160 }).then(function successCallback(response) {
161 ces = response.data["devices"]["device"];
162 ces.forEach(function(c) {
163 c.displayName = c['dev-id'];
164 operMap[c['dev-id']] = c;
166 }).finally(function() {
169 url:"/restconf/config/mef-topology:mef-topology/devices/"
170 }).then(function(response){
171 var confCes = response.data["devices"]["device"];
172 confCes.forEach(function(c) {
173 c.displayName = c['device-name'] ? c['device-name'] : c['dev-id'];
174 if (operMap[c['dev-id']]) {
175 for (var attrname in c) {
176 operMap[c['dev-id']][attrname] = c[attrname];
179 operMap[c['dev-id']] = c;
182 }).finally(function() {
183 if (callback != undefined) {
184 callback(Object.values(operMap));
190 svc.removeCe = function(ceid, callback) {
193 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ceid + "/"
194 }).then(function successCallback(response) {
195 if (callback != undefined) {
203 svc.addUni = function(id, tenantid, callback) {
206 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/",
209 "tenant-id":tenantid,
210 "admin-state-enabled":true
212 }).then(function successCallback(response) {
213 if (callback != undefined) {
220 svc.updateUni = function(id, tenantid, callback) {
221 // TODO didn't find a better way to keep other uni fields, PATCH method is not supported :(
224 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/uni/" + id + "/"
225 }).then(function successCallback(response) {
227 uni["uni"][0]["tenant-id"] = tenantid;
229 delete uni["uni"][0]["tenant-id"];
231 uni["uni"][0]["admin-state-enabled"] = true;
234 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + id + "/",
236 }).then(function successCallback(response) {
237 if (callback != undefined) {
244 svc.getUnis = function(callback) {
248 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/"
249 }).then(function successCallback(response) {
250 unis = response.data["unis"]["uni"];
251 if (unis != undefined){
252 for (i=0; i < unis.length; i++) {
253 if ((unis[i]["physical-layers"] != undefined) && (unis[i]["physical-layers"].links != undefined)){
254 unis[i].device = unis[i]["physical-layers"].links.link[0].device;
261 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/"
262 }).then(function(response){
263 var confUnis = response.data["unis"]["uni"];
264 confUnis.forEach(function(u) {
265 confMap[u['uni-id']] = u;
267 }).finally(function(){
268 unis.forEach(function(u) {
269 u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
270 // copy config fields like tenant-id
271 if (confMap[u['uni-id']]){
272 for (var attrname in confMap[u['uni-id']]) {
273 u[attrname] = confMap[u['uni-id']][attrname];
277 if (callback != undefined) {
281 }, function errorCallback(response) {
282 if (response.status == 404) {
285 console.log(response);
289 svc.getTenantUnis = function(tenantid, callback) {
291 svc.getUnis(function(unis){
292 if (unis != undefined){
293 unis = unis.filter(function(u){return u["tenant-id"] == tenantid;});
295 if (callback != undefined) {
301 svc.removeUni = function(uniid, callback) {
304 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + uniid + "/"
305 }).then(function successCallback(response) {
306 if (callback != undefined) {
313 svc.addIpvc = function(ipvc, tenant, callback) {
314 var ipvcId = Utils.randomId();
318 "name" : ipvc.svc_name,
319 "svc-type" : 'eplan',
320 "tenant-id" : tenant,
323 "ipvc-type" : 'multipoint',
329 url:"/restconf/config/mef-services:mef-services/",
331 }).then(function successCallback(response) {
332 if (callback != undefined) {
338 svc.addIpUni = function(uniid, ip_address, vlan, segmentation_id, callback) {
339 var ipUniId = Utils.randomId();
340 var data = {"ip-uni":{
341 "ip-uni-id": ipUniId,
342 "ip-address": ip_address
345 data["ip-uni"].vlan = vlan;
347 if (segmentation_id) {
348 data["ip-uni"]["segmentation-id"] = segmentation_id;
352 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/",
354 }).then(function successCallback(response) {
355 if (callback != undefined) {
361 svc.getAllIpUniSubnets = function(callback) {
364 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/"
365 }).then(function successCallback(response) {
366 var raw_subnets = response.data["subnets"]["subnet"];
368 raw_subnets.forEach(function(sub){
369 if (subnets[sub["uni-id"]] == undefined) {
370 subnets[sub["uni-id"]] = {};
372 if (subnets[sub["uni-id"]][sub["ip-uni-id"]] == undefined) {
373 subnets[sub["uni-id"]][sub["ip-uni-id"]] = [];
375 subnets[sub["uni-id"]][sub["ip-uni-id"]].push(sub);
377 if (callback != undefined) {
380 }, function errorCallback(response) {
381 console.log(response);
385 svc.addIpUniSubnet = function(uniid, ipuniid, subnet, gateway, callback) {
398 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/",
400 }).then(function successCallback(response) {
401 if (callback != undefined) {
407 svc.deleteIpUniSubnet = function(uniid, ipuni_id, subnet, callback) {
411 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/subnet/"+uniid+"/"+ipuni_id+"/"+subnet.replace("/","%2F")+"/"
412 }).then(function successCallback(response) {
413 if (callback != undefined) {
418 svc.deleteIpUni = function(uniid, ipuni_id, callback) {
422 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/"
423 }).then(function successCallback(response) {
424 if (callback != undefined) {
430 svc.getIpUniSubnets = function(uniid, ipuni_id, callback) {
433 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/"
434 //subnet/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/subnets"
435 }).then(function successCallback(response) {
436 subnets = response.data["subnets"]["subnet"];
437 subnets = subnets.filterByField('uni-id',uniid).filterByField('ip-uni-id',ipuni_id);
438 if (callback != undefined) {
446 function getJsonUnis(unis) {
448 if (unis == undefined) {
451 unis.forEach(function(i){uni_json.push({"uni-id":i});});
455 svc.addEvc = function(evc, evc_type, tenant, callback) {
456 var uni_json = getJsonUnis(evc.unis);
458 var evcId = Utils.randomId();
462 "name" : evc.svc_name,
463 "svc-type" : evc.svc_type,
464 "tenant-id" : tenant,
467 "evc-type" : evc_type,
468 "preserve-ce-vlan-id" : evc.is_preserve_vlan,
469 "max-svc-frame-size" : evc.mtu_size,
470 "unicast-svc-frm-delivery" : evc.unicast,
471 "multicast-svc-frm-delivery" : evc.multicast,
472 "mac-timeout":evc.mac_timeout,
476 "admin-state-enabled" : true
480 if (evc.is_preserve_vlan) {
481 data["mef-service"]["evc"]["preserved-vlan"] = evc.preserved_vlan;
484 data["mef-service"]["evc"].subnet = evc.subnet;
486 if (evc.segmentation_id) {
487 data["mef-service"]["evc"]["segmentation-id"] = evc.segmentation_id;
491 url:"/restconf/config/mef-services:mef-services/",
493 }).then(function successCallback(response) {
494 if (callback != undefined) {
499 svc.getServices = function(tenantid, callback) {
503 url:"/restconf/config/mef-services:mef-services/"
504 }).then(function successCallback(response) {
505 evcs = response.data["mef-services"]["mef-service"]; // TODO try to filter on server side
506 if (evcs != undefined) {
507 evcs = evcs.filter(function(evc){return evc["tenant-id"] == tenantid;});
508 for (i=0; i < evcs.length; i++) {
509 if ((evcs[i].evc != undefined) && (evcs[i].evc.unis.uni != undefined)) {
510 var unis = evcs[i].evc.unis.uni;
511 for (j=0; j < unis.length; j++) {
512 if ((unis[j]['evc-uni-ce-vlans'] != undefined) && (unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'] != undefined)){
513 unis[j].vlans = unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'].map(function(u){return u.vid;}).sort();
521 if (callback != undefined) {
524 }, function errorCallback(response) {
525 console.log(response);
530 svc.getAllServices = function(callback) {
533 url:"/restconf/config/mef-services:mef-services/"
534 }).then(function successCallback(response) {
535 if (callback != undefined) {
536 callback(response.data["mef-services"]["mef-service"]);
538 }, function errorCallback(response) {
539 if (response.status == 404) {
542 console.log(response);
546 svc.addTenantToService = function(svcId, tenantName, callbackSuccess, callbackFailure){
549 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcId,
550 data:{"tenant-id":tenantName}
552 if (callbackSuccess != undefined) {
556 if (callbackFailure != undefined) {
559 console.log(response);
564 svc.removeEvc = function(svcid, callback) {
567 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/"
568 }).then(function successCallback(response) {
569 if (callback != undefined) {
575 svc.addIpvcUni = function(svcid, uni_id, ipuni_id, profile_name, callback) {
582 data.uni["ingress-bw-profile"] = profile_name;
586 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/"+uni_id+"/"+ipuni_id,
588 }).then(function successCallback(response) {
589 if (callback != undefined) {
592 }, function failureCallback(response) {
593 if (callback != undefined) {
599 svc.deleteIpvcUni = function(svcid, uni_id, ipuni_id, callback) {
602 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/" + uni_id +"/"+ipuni_id + "/"
603 }).then(function successCallback(response) {
604 if (callback != undefined) {
612 svc.addEvcUni = function(svcid, uni_id, role, vlans, profile_name, callback) {
616 "admin-state-enabled":true
620 data.uni["ingress-bw-profile"] = profile_name;
622 if (vlans != undefined) {
623 data.uni['evc-uni-ce-vlans'] = {"evc-uni-ce-vlan":[]}
624 for (var i=0; i< vlans.length; ++i) {
625 data.uni['evc-uni-ce-vlans']["evc-uni-ce-vlan"].push({"vid":vlans[i]});
630 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis",
632 }).then(function successCallback(response) {
633 if (callback != undefined) {
636 }, function failureCallback(response) {
637 if (callback != undefined) {
643 svc.addEvcUniVlan = function(svcid, uni_id, vlan, callback) {
646 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/evc-uni-ce-vlans/",
647 data:{"evc-uni-ce-vlan":{"vid":vlan}}
648 }).then(function successCallback(response) {
649 if (callback != undefined) {
655 svc.deleteEvcUni = function(svcid, uni_id, callback) {
658 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/"
659 }).then(function successCallback(response) {
660 if (callback != undefined) {
668 svc.deleteVlan = function(svc_id, uni_id, vlan,callback) {
671 url:"/restconf/config/mef-services:mef-services/mef-service/" + svc_id + "/evc/unis/uni/" + uni_id + "/evc-uni-ce-vlans/evc-uni-ce-vlan/"+ vlan+"/"
672 }).then(function successCallback(response) {
673 if (callback != undefined) {
679 svc.addVlan = function(svc_id, uni_id, vlan, callback) {
682 url:"/restconf/config/mef-services:mef-services/mef-service/" + svc_id + "/evc/unis/uni/"+uni_id+"/evc-uni-ce-vlans/evc-uni-ce-vlan/"+vlan+"/",
683 data:{"evc-uni-ce-vlan":{"vid":vlan}}
684 }).then(function successCallback(response) {
685 if (callback != undefined) {
691 svc.getNetworkNames = function(callback){
694 url:"/restconf/config/neutron:neutron/networks/"
695 }).then(function successCallback(response) {
696 if (callback != undefined) {
697 callback(response.data.networks.network);