2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 define(['app/vpp/vpp.module'], function(vpp) {
10 vpp.register.controller('bdmCtrl', ['$scope', '$rootScope','$filter', 'dataService', 'toastService', function ($scope, $rootScope, filter, dataService, toastService) {
14 vpp.register.controller('TableController', ['$scope', '$rootScope','$filter', 'dataService', 'toastService', 'bdmInterfaceService',
15 function ($scope, $rootScope, filter, dataService, toastService, bdmInterfaceService) {
16 $scope.interfaceList = [];
17 $scope.unassignedInterfaceList = [];
18 $scope.assignedInterfaces = [];
22 vm.updateAssignment = function(receivedInterface) {
23 if (receivedInterface.assigned){
24 receivedInterface.vbdName = $scope.selectedBd['topology-id'];
25 vm.assignInterface($scope.selectedBd, receivedInterface);
28 vm.unassignInterface(receivedInterface);
32 vm.assignInterface = function(bridgeDomain, interface) {
33 var interfaceObject = bdmInterfaceService.createObj(interface['tp-id'], interface['tp-id']);
35 var successCallback = function() {
36 toastService.showToast('Interface assigned');
37 $scope.assignedInterfaces.push(interface);
39 $scope.$emit('INTERFACE_CHANGED', interface);
42 var errorCallback = function() {
43 toastService.showToast('Unable to assign interface');
46 bdmInterfaceService.add(interfaceObject, bridgeDomain['topology-id'], interface.vppName, successCallback, errorCallback);
49 vm.unassignInterface = function(interface) {
50 var interfaceObject = bdmInterfaceService.createObj(interface['tp-id'], interface['tp-id']);
52 var successCallback = function() {
53 toastService.showToast('Interface unassigned');
54 $scope.assignedInterfaces.splice($scope.assignedInterfaces.indexOf(interface), 1);
55 interface.vbdName = '';
57 $scope.$emit('INTERFACE_CHANGED', interface);
60 var errorCallback = function() {
61 toastService.showToast('Unable to unassign interface');
64 bdmInterfaceService.delete(interfaceObject, interface.vbdName, interface.vppName, successCallback, errorCallback);
68 $scope.$on('BUILD_INTERFACES_TABLE', function(event) {
69 $scope.interfaceList = [];
70 $scope.unassignedInterfaceList = [];
71 $scope.assignedInterfaces = $scope.getAssignedInterfaces();
73 $scope.assignedInterfacesFlat = [];
75 var getAssignedInterfacesFlat = function() {
76 var keys = Object.keys($scope.assignedInterfaces);
79 keys.forEach(function (k) {
80 if($scope.assignedInterfaces[k]) {
81 $scope.assignedInterfaces[k].forEach(function(ai) {
82 checkAndPushIntoArray($scope.assignedInterfacesFlat, ai);
89 var checkAndPushIntoArray = function(array, item) {
90 var check = array.some(function(i) {
91 return i['tp-id'] === item['tp-id'] && i.vppName === item.vppName;
99 getAssignedInterfacesFlat();
101 dataService.vpps.forEach(function(vpp){
102 vpp.interfaces.forEach(function(interface){
103 var interfaceObject = bdmInterfaceService.createObj(interface.name, interface.name);
105 var check = $scope.assignedInterfacesFlat.some(function (ai) {
106 return interfaceObject['tp-id'] === ai['tp-id'] && vpp.name === ai.vppName;
110 interfaceObject.vppName = vpp.name;
111 checkAndPushIntoArray($scope.unassignedInterfaceList, interfaceObject);
116 if($scope.selectedBd) {
117 $scope.interfaceList = $scope.assignedInterfaces[$scope.selectedBd['topology-id']] ? $scope.assignedInterfaces[$scope.selectedBd['topology-id']].concat($scope.unassignedInterfaceList) : $scope.unassignedInterfaceList;
120 $scope.interfaceDisplayList = [].concat($scope.interfaceList);
123 $scope.$on('INIT_INTERFACES_TABLE', function(event) {
124 $scope.interfaceList = [];
125 $scope.unassignedInterfaceList = [];
126 $scope.assignedInterfaces = [];
127 $scope.assignedInterfacesFlat = [];
134 vpp.register.controller('BridgeDomainsController', ['$scope', '$rootScope','$filter', 'dataService', 'bdmBridgeDomainService', 'toastService', '$mdDialog', 'bdmTunnelService',
135 function($scope, $rootScope, $filter, dataService, bdmBridgeDomainService, toastService, $mdDialog, bdmTunnelService) {
136 $scope.bridgeDomainList = [];
137 $scope.showOverlay = true;
139 $scope.loadBridgeDomains = function(bridgeDomain, successCallback) {
140 bdmBridgeDomainService.get(function(data) {
141 $scope.bridgeDomainList = data;
144 $scope.selectedBd = $scope.bridgeDomainList.filter(function(bd) {
145 return bd['topology-id'] === bridgeDomain['topology-id'];
148 $scope.showTopology($scope.selectedBd);
153 }, function(data,status) {
159 $scope.getInterfacesForBridgeDomain = function(bridgeDomain) {
160 var interfaceList = [];
162 if(bridgeDomain.node) {
163 bridgeDomain.node.forEach(function (n) {
164 if (n['termination-point']) {
165 n['termination-point'].forEach(function (tp) {
166 tp.vppName = n['node-id'];
167 tp.vbdName = bridgeDomain['topology-id'];
170 interfaceList.push(tp);
176 return interfaceList;
179 $scope.getAssignedInterfaces = function() {
182 $scope.bridgeDomainList.forEach(function(bd) {
184 angular.copy(bd, bdCopy);
186 interfaces[bdCopy['topology-id']] = $scope.getInterfacesForBridgeDomain(bdCopy);
192 $scope.addBd = function() {
195 controller: function() {
200 //function called when the cancel button ( 'x' in the top right) is clicked
201 vm.close = function() {
205 vm.isDone = function(status, bridgeDomain) {
207 if (status === 'success') {
208 $scope.reload(bridgeDomain);
213 //function called when the update button is clicked
214 vm.updateConfig = function() {
216 //send a POST with the entered content in the form field
218 var obj = bdmBridgeDomainService.createObj(vm.bd.name);
220 bdmBridgeDomainService.add(obj,
222 vm.isDone('success', obj);
230 controllerAs: 'NewBdDialogCtrl',
231 templateUrl: $scope.view_path + 'new-bd-dialog.html',
232 parent: angular.element(document.body),
233 clickOutsideToClose:false
237 $scope.removeBd = function() {
238 if($scope.selectedBd['topology-id']) {
239 var successCallback = function(success) {
240 $scope.selectedBd = null;
241 $scope.loadBridgeDomains(null, function() {
242 $scope.$broadcast('INIT_INTERFACES_TABLE');
243 $scope.clearTopologies();
247 bdmBridgeDomainService.remove($scope.selectedBd['topology-id'], function(){successCallback(true)}, function(){successCallback(false)});
251 $scope.bdChanged = function() {
252 $scope.loadBridgeDomains($scope.selectedBd, function() {
253 $scope.$broadcast('BUILD_INTERFACES_TABLE');
255 $scope.showTopology($scope.selectedBd);
260 nx.graphic.Icons.registerIcon("bd", "src/app/vpp/assets/images/bd1.svg", 45, 45);
261 nx.graphic.Icons.registerIcon("interf", "src/app/vpp/assets/images/interf.svg", 45, 45);
263 $scope.showOverlayTopology = function(bridgeDomain) {
265 angular.copy(bridgeDomain, bdCopy);
267 $scope.bridgeDomainsTopo = new nx.graphic.Topology({
271 enableGradualScaling: true,
274 label: 'model.label',
275 scale: 'model.scale',
276 iconType: function (vertex) {
277 var type = vertex.get().type;
286 label: 'model.label',
287 linkType: 'parallel',
288 color: function (link) {
289 if (link.getData().type === 'tunnel') {
295 width: function (link) {
296 if (link.getData().type === 'tunnel') {
302 dataProcessor: 'force',
304 enableSmartNode: false,
305 tooltipManagerConfig: {
306 nodeTooltipContentClass: 'TooltipNode',
307 linkTooltipContentClass: 'TooltipLink'
311 $scope.overlayNextApp = new nx.ui.Application;
316 "label": bdCopy['topology-id']
319 var nodes = [].concat(bdNode);
322 _.forEach($scope.getInterfacesForBridgeDomain(bdCopy), function(tp, index){
329 links.push({source: 0, target: nodes.length-1});
333 $scope.bridgeDomainsTopo.data({
338 $scope.overlayNextApp.container(document.getElementById('overlay-next-app'));
339 $scope.bridgeDomainsTopo.attach($scope.overlayNextApp);
342 $scope.fillOverlayTopology = function(bridgeDomain) {
344 angular.copy(bridgeDomain, bdCopy);
349 "label": bdCopy['topology-id']
352 var nodes = [].concat(bdNode);
355 _.forEach($scope.getInterfacesForBridgeDomain(bdCopy), function(tp, index){
362 links.push({source: 0, target: nodes.length-1});
366 $scope.bridgeDomainsTopo.data({
373 $scope.showUnderTopology = function(bridgeDomain) {
375 //angular.copy(bridgeDomain, bdCopy);
377 $scope.underlayTopo = new nx.graphic.Topology({
381 enableGradualScaling:true,
384 label: 'model.label',
385 scale: 'model.scale',
386 iconType: function(vertex) {
387 var type = vertex.get().type;
390 } else if (type==='vpp') {
398 label: 'model.label',
399 linkType: 'parallel',
400 color: function(link) {
401 if (link.getData().type === 'tunnel') {
407 width: function(link) {
408 if (link.getData().type === 'tunnel') {
414 enableSmartNode: false
417 $scope.underlayNextApp = new nx.ui.Application;
419 $scope.fillUnderlayTopology(bridgeDomain);
421 $scope.underlayNextApp.container(document.getElementById('underlay-next-app'));
422 $scope.underlayTopo.attach($scope.underlayNextApp);
425 $scope.fillUnderlayTopology = function(bridgeDomain) {
427 angular.copy(bridgeDomain, bdCopy);
432 _.forEach(bdCopy.node, function(node, index){
436 label: node['node-id'],
437 x: (-1+(2*(i%2)))*((i+1)/2 * 500),
444 bdmTunnelService.get(
445 bdCopy['topology-id'],
451 var sourceNode = link[0].source['source-node'];
452 var targetNode = link[0].destination['dest-node'];
455 source: _.findIndex(nodes, {label: sourceNode, type: 'vpp'}),
456 target: _.findIndex(nodes, {label: targetNode, type: 'vpp'}),
460 $scope.underlayTopo.data({
466 $scope.underlayTopo.data({
474 $scope.underlayTopo.data({
480 $scope.reload = function(bridgeDomain) {
481 $scope.loadBridgeDomains(bridgeDomain, function() {
482 $scope.$broadcast('BUILD_INTERFACES_TABLE');
484 $scope.showTopology($scope.selectedBd);
489 $scope.toggleUnderlay = function() {
490 $scope.showOverlay = !$scope.showOverlay;
492 $scope.reload($scope.selectedBd);
495 $scope.showTopology = function(bridgeDomain) {
496 if($scope.showOverlay) {
497 if(!$scope.bridgeDomainsTopo) {
498 $scope.showOverlayTopology(bridgeDomain);
501 $scope.fillOverlayTopology(bridgeDomain);
504 if(!$scope.underlayTopo) {
505 $scope.showUnderTopology(bridgeDomain);
508 $scope.fillUnderlayTopology(bridgeDomain);
513 $scope.clearTopologies = function() {
514 if($scope.bridgeDomainsTopo) {
515 $scope.bridgeDomainsTopo.data({
521 if($scope.bridgeDomainsTopo) {
522 $scope.underlayTopo.data({
529 $scope.$on('INTERFACE_CHANGED', function(event, data) {
530 bdmBridgeDomainService.getOne($scope.selectedBd['topology-id'],
532 $scope.fillOverlayTopology(bdData);
535 console.log('error getting vbd');
539 $scope.loadBridgeDomains(null, function() {});