1 define(['app/cpeui/cpeui.module'],function(cpeui) {
3 cpeui.factory('CpeuiSvc', function($http, CpeUiUtils) {
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 if (response.data["ingress-bwp-flows"]["bwp-flow"]){
58 response.data["ingress-bwp-flows"]["bwp-flow"].forEach(function(p){
59 p.cir = Math.round(p.cir/1024);
62 callback(response.data["ingress-bwp-flows"]["bwp-flow"]);
64 }, function errorCallback(response) {
65 if (response.status == 404) {
68 console.log(response);
72 svc.addProfile = function(name, cir, cbs, callback){
75 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/",
81 }).then(function successCallback(response) {
82 if (callback != undefined) {
88 svc.editProfile = function(name, cir, cbs, callback){
91 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/bwp-flow/"+name,
97 }).then(function successCallback(response) {
98 if (callback != undefined) {
104 svc.deleteProfile = function(name, callback) {
107 url:"/restconf/config/mef-global:mef-global/profiles/ingress-bwp-flows/bwp-flow/"+name,
108 }).then(function successCallback(response) {
109 if (callback != undefined) {
116 svc.addCe = function(id, name, callback) {
119 url:"/restconf/config/mef-topology:mef-topology/devices/",
126 "interfaces": {"interface": []}
131 }).then(function successCallback(response) {
132 if (callback != undefined) {
138 svc.addCeName = function(ce, new_name, callback) {
141 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id'],
142 data: {"device-name": new_name}
143 }).then(function successCallback(response) {
144 if (callback != undefined) {
147 }, function errorCallback(response) {
148 console.log(response);
151 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ce['dev-id']
152 }).then(function successCallback(response) {
153 ce["device-name"] = response.data["device"][0]["device-name"];
158 svc.getCes = function(callback) {
163 url:"/restconf/operational/mef-topology:mef-topology/devices/"
164 }).then(function successCallback(response) {
165 ces = response.data["devices"]["device"];
166 ces.forEach(function(c) {
167 c.displayName = c['dev-id'];
168 operMap[c['dev-id']] = c;
170 }).finally(function() {
173 url:"/restconf/config/mef-topology:mef-topology/devices/"
174 }).then(function(response){
175 var confCes = response.data["devices"]["device"];
176 confCes.forEach(function(c) {
177 c.displayName = c['device-name'] ? c['device-name'] : c['dev-id'];
178 if (operMap[c['dev-id']]) {
179 for (var attrname in c) {
180 operMap[c['dev-id']][attrname] = c[attrname];
183 operMap[c['dev-id']] = c;
186 }).finally(function() {
187 if (callback != undefined) {
188 callback(Object.values(operMap));
194 svc.removeCe = function(ceid, callback) {
197 url:"/restconf/config/mef-topology:mef-topology/devices/device/" + ceid + "/"
198 }).then(function successCallback(response) {
199 if (callback != undefined) {
207 svc.addUni = function(id, tenantid, callback) {
210 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/",
213 "tenant-id":tenantid,
214 "admin-state-enabled":true
216 }).then(function successCallback(response) {
217 if (callback != undefined) {
224 svc.updateUni = function(id, tenantid, callback) {
225 // TODO didn't find a better way to keep other uni fields, PATCH method is not supported :(
228 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/uni/" + id + "/"
229 }).then(function successCallback(response) {
231 uni["uni"][0]["tenant-id"] = tenantid;
233 delete uni["uni"][0]["tenant-id"];
235 uni["uni"][0]["admin-state-enabled"] = true;
238 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + id + "/",
240 }).then(function successCallback(response) {
241 if (callback != undefined) {
248 svc.getUnis = function(callback) {
252 url:"/restconf/operational/mef-interfaces:mef-interfaces/unis/"
253 }).then(function successCallback(response) {
254 unis = response.data["unis"]["uni"];
255 if (unis != undefined){
256 for (i=0; i < unis.length; i++) {
257 if ((unis[i]["physical-layers"] != undefined) && (unis[i]["physical-layers"].links != undefined)){
258 unis[i].device = unis[i]["physical-layers"].links.link[0].device;
265 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/"
266 }).then(function(response){
267 var confUnis = response.data["unis"]["uni"];
268 confUnis.forEach(function(u) {
269 confMap[u['uni-id']] = u;
271 }).finally(function(){
272 unis.forEach(function(u) {
273 u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
274 // copy config fields like tenant-id
275 if (confMap[u['uni-id']]){
276 for (var attrname in confMap[u['uni-id']]) {
277 u[attrname] = confMap[u['uni-id']][attrname];
281 if (callback != undefined) {
285 }, function errorCallback(response) {
286 if (response.status == 404) {
289 console.log(response);
293 svc.getTenantUnis = function(tenantid, callback) {
295 svc.getUnis(function(unis){
296 if (unis != undefined){
297 unis = unis.filter(function(u){return u["tenant-id"] == tenantid;});
299 if (callback != undefined) {
305 svc.removeUni = function(uniid, callback) {
308 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/" + uniid + "/"
309 }).then(function successCallback(response) {
310 if (callback != undefined) {
317 svc.addIpvc = function(ipvc, tenant, callback) {
318 var ipvcId = CpeUiUtils.randomId();
322 "name" : ipvc.svc_name,
323 "svc-type" : 'eplan',
324 "tenant-id" : tenant,
327 "ipvc-type" : 'multipoint',
333 url:"/restconf/config/mef-services:mef-services/",
335 }).then(function successCallback(response) {
336 if (callback != undefined) {
342 svc.addIpUni = function(uniid, ip_address, vlan, segmentation_id, callback) {
343 var ipUniId = CpeUiUtils.randomId();
344 var data = {"ip-uni":{
345 "ip-uni-id": ipUniId,
346 "ip-address": ip_address
349 data["ip-uni"].vlan = vlan;
351 if (segmentation_id) {
352 data["ip-uni"]["segmentation-id"] = segmentation_id;
356 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/",
358 }).then(function successCallback(response) {
359 if (callback != undefined) {
365 svc.getAllIpUniSubnets = function(callback) {
368 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/"
369 }).then(function successCallback(response) {
370 var raw_subnets = response.data["subnets"]["subnet"];
372 raw_subnets.forEach(function(sub){
373 if (subnets[sub["uni-id"]] == undefined) {
374 subnets[sub["uni-id"]] = {};
376 if (subnets[sub["uni-id"]][sub["ip-uni-id"]] == undefined) {
377 subnets[sub["uni-id"]][sub["ip-uni-id"]] = [];
379 subnets[sub["uni-id"]][sub["ip-uni-id"]].push(sub);
381 if (callback != undefined) {
384 }, function errorCallback(response) {
385 console.log(response);
389 svc.addIpUniSubnet = function(uniid, ipuniid, subnet, gateway, callback) {
402 url : "/restconf/config/mef-interfaces:mef-interfaces/subnets/",
404 }).then(function successCallback(response) {
405 if (callback != undefined) {
411 svc.deleteIpUniSubnet = function(uniid, ipuni_id, subnet, callback) {
415 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/subnet/"+uniid+"/"+ipuni_id+"/"+subnet.replace("/","%2F")+"/"
416 }).then(function successCallback(response) {
417 if (callback != undefined) {
422 svc.deleteIpUni = function(uniid, ipuni_id, callback) {
426 url:"/restconf/config/mef-interfaces:mef-interfaces/unis/uni/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/"
427 }).then(function successCallback(response) {
428 if (callback != undefined) {
434 svc.getIpUniSubnets = function(uniid, ipuni_id, callback) {
437 url:"/restconf/config/mef-interfaces:mef-interfaces/subnets/"
438 //subnet/"+uniid+"/ip-unis/ip-uni/"+ipuni_id+"/subnets"
439 }).then(function successCallback(response) {
440 subnets = response.data["subnets"]["subnet"];
441 subnets = subnets.filterByField('uni-id',uniid).filterByField('ip-uni-id',ipuni_id);
442 if (callback != undefined) {
450 function getJsonUnis(unis) {
452 if (unis == undefined) {
455 unis.forEach(function(i){uni_json.push({"uni-id":i});});
459 svc.addEvc = function(evc, evc_type, tenant, callback) {
460 var uni_json = getJsonUnis(evc.unis);
462 var evcId = CpeUiUtils.randomId();
466 "name" : evc.svc_name,
467 "svc-type" : evc.svc_type,
468 "tenant-id" : tenant,
471 "evc-type" : evc_type,
472 "preserve-ce-vlan-id" : evc.is_preserve_vlan,
473 "max-svc-frame-size" : evc.mtu_size,
474 "unicast-svc-frm-delivery" : evc.unicast,
475 "multicast-svc-frm-delivery" : evc.multicast,
476 "mac-timeout":evc.mac_timeout,
480 "admin-state-enabled" : true
484 if (evc.is_preserve_vlan) {
485 data["mef-service"]["evc"]["preserved-vlan"] = evc.preserved_vlan;
488 data["mef-service"]["evc"].subnet = evc.subnet;
490 if (evc.segmentation_id) {
491 data["mef-service"]["evc"]["segmentation-id"] = evc.segmentation_id;
495 url:"/restconf/config/mef-services:mef-services/",
497 }).then(function successCallback(response) {
498 if (callback != undefined) {
503 svc.getServices = function(tenantid, callback) {
507 url:"/restconf/config/mef-services:mef-services/"
508 }).then(function successCallback(response) {
509 evcs = response.data["mef-services"]["mef-service"]; // TODO try to filter on server side
510 if (evcs != undefined) {
511 evcs = evcs.filter(function(evc){return evc["tenant-id"] == tenantid;});
512 for (i=0; i < evcs.length; i++) {
513 if ((evcs[i].evc != undefined) && (evcs[i].evc.unis.uni != undefined)) {
514 var unis = evcs[i].evc.unis.uni;
515 for (j=0; j < unis.length; j++) {
516 if ((unis[j]['evc-uni-ce-vlans'] != undefined) && (unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'] != undefined)){
517 unis[j].vlans = unis[j]['evc-uni-ce-vlans']['evc-uni-ce-vlan'].map(function(u){return u.vid;}).sort();
525 if (callback != undefined) {
528 }, function errorCallback(response) {
529 console.log(response);
534 svc.getAllServices = function(callback) {
537 url:"/restconf/config/mef-services:mef-services/"
538 }).then(function successCallback(response) {
539 if (callback != undefined) {
540 callback(response.data["mef-services"]["mef-service"]);
542 }, function errorCallback(response) {
543 if (response.status == 404) {
546 console.log(response);
550 svc.addTenantToService = function(svcId, tenantName, callbackSuccess, callbackFailure){
553 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcId,
554 data:{"tenant-id":tenantName}
556 if (callbackSuccess != undefined) {
560 if (callbackFailure != undefined) {
563 console.log(response);
568 svc.removeEvc = function(svcid, callback) {
571 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/"
572 }).then(function successCallback(response) {
573 if (callback != undefined) {
579 svc.addIpvcUni = function(svcid, uni_id, ipuni_id, profile_name, callback) {
586 data.uni["ingress-bw-profile"] = profile_name;
590 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/"+uni_id+"/"+ipuni_id,
592 }).then(function successCallback(response) {
593 if (callback != undefined) {
596 }, function failureCallback(response) {
597 if (callback != undefined) {
603 svc.deleteIpvcUni = function(svcid, uni_id, ipuni_id, callback) {
606 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/ipvc/unis/uni/" + uni_id +"/"+ipuni_id + "/"
607 }).then(function successCallback(response) {
608 if (callback != undefined) {
616 svc.addEvcUni = function(svcid, uni_id, role, vlans, profile_name, callback) {
620 "admin-state-enabled":true
624 data.uni["ingress-bw-profile"] = profile_name;
626 if (vlans != undefined) {
627 data.uni['evc-uni-ce-vlans'] = {"evc-uni-ce-vlan":[]}
628 for (var i=0; i< vlans.length; ++i) {
629 data.uni['evc-uni-ce-vlans']["evc-uni-ce-vlan"].push({"vid":vlans[i]});
634 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis",
636 }).then(function successCallback(response) {
637 if (callback != undefined) {
640 }, function failureCallback(response) {
641 if (callback != undefined) {
647 svc.addEvcUniVlan = function(svcid, uni_id, vlan, callback) {
650 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/evc-uni-ce-vlans/",
651 data:{"evc-uni-ce-vlan":{"vid":vlan}}
652 }).then(function successCallback(response) {
653 if (callback != undefined) {
659 svc.deleteEvcUni = function(svcid, uni_id, callback) {
662 url:"/restconf/config/mef-services:mef-services/mef-service/" + svcid + "/evc/unis/uni/" + uni_id + "/"
663 }).then(function successCallback(response) {
664 if (callback != undefined) {
672 svc.deleteVlan = function(svc_id, uni_id, vlan,callback) {
675 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+"/"
676 }).then(function successCallback(response) {
677 if (callback != undefined) {
683 svc.addVlan = function(svc_id, uni_id, vlan, callback) {
686 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+"/",
687 data:{"evc-uni-ce-vlan":{"vid":vlan}}
688 }).then(function successCallback(response) {
689 if (callback != undefined) {
695 svc.getNetworkNames = function(callback){
698 url:"/restconf/config/neutron:neutron/networks/"
699 }).then(function successCallback(response) {
700 if (callback != undefined) {
701 callback(response.data.networks.network);