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
8 define(['app/vpp/vpp.module', 'next'], function(vpp) {
10 vpp.register.factory('VPPRestangular', function(Restangular, ENV) {
11 return Restangular.withConfig(function(RestangularConfig) {
12 RestangularConfig.setBaseUrl(ENV.getBaseURL("MD_SAL"));
16 vpp.register.factory('VPPRestangularXml', function(Restangular, ENV) {
17 return Restangular.withConfig(function(RestangularConfig) {
18 RestangularConfig.setBaseUrl(ENV.getBaseURL("MD_SAL"));
19 RestangularConfig.setDefaultHeaders({ "Content-Type": "application/xml" }, { "Accept": "application/xml" });
23 vpp.register.service('toastService', function($mdToast) {
24 this.showToast = function(content) {
25 var toast = $mdToast.simple()
28 .position('bottom right');
33 vpp.register.service('dataService', ['$timeout', function($timeout) {
37 nx.graphic.Icons.registerIcon("bd", "src/app/vpp/assets/images/bd1.svg", 45, 45);
38 nx.graphic.Icons.registerIcon("interf", "src/app/vpp/assets/images/interf.svg", 45, 45);
40 this.bridgeDomainsTopo = new nx.graphic.Topology({
44 enableGradualScaling:true,
49 iconType: function(vertex) {
50 var type = vertex.get().type;
61 color: function(link) {
62 if (link.getData().type === 'tunnel') {
68 width: function(link) {
69 if (link.getData().type === 'tunnel') {
75 dataProcessor: 'force',
77 enableSmartNode: false,
78 tooltipManagerConfig: {
79 nodeTooltipContentClass: 'TooltipNode',
80 linkTooltipContentClass: 'TooltipLink'
83 this.nextApp = new nx.ui.Application;
84 this.bridgedomainsLoaded = false;
87 this.tableContent = [];
88 this.originalAssignments = [];
90 this.injectedInterfaces = [];
91 this.bridgedomains = [];
92 this.changedInterfaces = [];
97 this.generateInterfaces = function() {
98 self.interfaces.length = 0;
99 _.forEach(this.vpps, function(vpp) {
100 _.forEach(vpp.interfaces, function(interf) {
101 interf.vppName = vpp.name;
102 interf.label = vpp.name+'/'+interf.name;
104 self.interfaces.push(interf);
107 console.log(this.interfaces);
110 this.buildAssignedInterfaces = function() {
111 this.originalAssignments.length = 0;
112 _.forEach(this.bridgedomains, function(bd){
113 var bdName = bd['topology-id'];
116 _.forEach(nodes, function(vpp) {
117 var vppName = vpp['node-id'];
118 var tps = vpp['termination-point'];
120 _.forEach(tps, function(tp) {
121 tp.vppName = vppName;
123 self.originalAssignments.push(tp);
130 console.log('Assigned Interfaces: ');
131 console.log(this.originalAssignments);
134 this.buildTableContent = function() {
135 this.tableContent.length = 0;
136 angular.copy(this.interfaces,this.tableContent);
139 //Makes assignements based on previously changed interfaces, or assignments retrieved from ODL
140 _.forEach(this.tableContent, function(interf) {
141 var matchedChangedInterface = _.find(self.changedInterfaces, {
143 vppName: interf.vppName
146 var matchedOriginalAssignment = _.find(self.originalAssignments, {
147 'vbridge-topology:user-interface': interf.name,
148 vppName: interf.vppName
151 if (matchedChangedInterface) {
152 interf.assigned = matchedChangedInterface.assigned;
153 interf.vbd = matchedChangedInterface.vbd;
154 } else if (matchedOriginalAssignment) {
155 interf.assigned = true;
156 interf.vbd = matchedOriginalAssignment.vbd;
158 interf.assigned = false;
163 _.remove(self.tableContent, function(interf){
164 var isAssigned = interf.assigned === true;
165 var isNotCorrectBd = !(interf.vbd === self.selectedBd.name);
166 return(isAssigned && isNotCorrectBd);
169 //_.forEach(this.originalAssignments, function(origAssignment) {
170 // if (origAssignment.vbd === self.selectedBd.name) {
171 // var matchedInterface = _.find(self.tableContent, {
172 // name: origAssignment['vbridge-topology:user-interface'],
173 // vppName: origAssignment.vppName
175 // if (matchedInterface) {
176 // matchedInterface.assigned = true;
177 // matchedInterface.vbd = origAssignment.vbd;
179 // console.error('Interface "'+origAssignment['vbridge-topology:user-interface']+'" on VPP "'+origAssignment.vppName+'" in vBD "'+origAssignment.vbd+'" was not found at mount point!');
182 // _.remove(self.tableContent, {
183 // name: origAssignment['vbridge-topology:user-interface'],
184 // vppName: origAssignment.vppName
189 //_.forEach(this.changedInterfaces, function(changedInterface) {
191 // var matchedInterface = _.find(self.tableContent, {
192 // name: changedInterface.name,
193 // vppName: changedInterface.vppName
196 // if (matchedInterface) {
197 // if (changedInterface.assigned) {
198 // if (changedInterface.vbd === self.selectedBd.name) {
199 // matchedInterface.assigned = true;
200 // matchedInterface.vbd = changedInterface.vbd;
203 // _.remove(self.tableContent, {
204 // name: changedInterface.name,
205 // vppName: changedInterface.vppName
209 // matchedInterface.assigned = false;
210 // matchedInterface.vbd = '';
217 //_.remove(self.tableContent, {
218 // name: origAssignment['vbridge-topology:user-interface'],
219 // vppName: origAssignment.vppName
222 this.injectBridgeDomainsTopoElements();
227 this.clearTopology = function() {
228 this.bridgeDomainsTopo.clear();
229 this.injectedInterfaces.length = 0;
233 //this.generateUnassignedInterfaces = function() {
234 // this.unassignedInterfaces.length = 0;
235 // for (var x=0; x<this.interfaces.length; x++) {
236 // if (!this.interfaces[x]['v3po:l2']['bridge-domain']) {
237 // this.unassignedInterfaces.push(this.interfaces[x]);
242 this.setData = function() {
244 for (var x=0; x<this.tableContent.length; x++) {
245 if (this.tableContent[x].assigned) {
246 this.bridgeDomainsTopo.addNode(this.tableContent[x]);
247 this.injectedInterfaces.push(this.tableContent[x]);
252 name : this.selectedBd.name,
253 label: this.selectedBd.name,
258 }].concat(this.injectedInterfaces);
261 for (var x=1; x<nodes.length; x++){
262 links.push({'source':0, 'target': x});
270 this.bridgeDomainsTopo.data(topoData);
273 this.injectBridgeDomainsTopoElements = function() {
274 this.clearTopology();
276 self.bridgeDomainsTopo.adaptToContainer();