3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * Created by onvelocity on 11/23/15.
24 import ColorGroups
from '../../ColorGroups'
25 import DescriptorModel
from '../DescriptorModel'
26 import ForwardingGraph
from './ForwardingGraph'
27 import VirtualLink
from './VirtualLink'
28 import ConstituentVnfd
from './ConstituentVnfd'
29 import PhysicalNetworkFunction
from './PhysicalNetworkFunction'
30 import DescriptorModelFactory
from '../DescriptorModelFactory'
31 import DescriptorModelMetaFactory
from '../DescriptorModelMetaFactory'
33 const indexAsInteger
= d
=> 1 + (parseInt(d
.model
['member-vnf-index'], 10) || 0);
35 const suffixAsInteger = function (field
) {
36 return (d
) => 1 + (parseInt(String(d
.model
[field
]).split('').reverse().join(''), 10) || 0);
39 const toBiggestValue
= (newIndex
, curIndex
) => Math
.max(newIndex
, curIndex
);
41 export default class NetworkService
extends DescriptorModel
{
47 static get className() {
48 return 'NetworkService';
51 constructor(model
, parent
) {
54 this.className
= 'NetworkService';
55 this._connectors
= [];
58 get constituentVnfd() {
59 if (!this.model
['constituent-vnfd']) {
60 this.model
['constituent-vnfd'] = [];
62 return this.model
['constituent-vnfd'].map(d
=> DescriptorModelFactory
.newConstituentVnfd(d
, this));
65 set constituentVnfd(obj
) {
66 const updateNextVnfdIndex
= (cvnfd
) => {
67 const items
= this.constituentVnfd
;
68 const length
= items
.length
;
69 // the default value is set to an instance count but we want it to be a sequence no
70 cvnfd
.model
['member-vnf-index'] = 0;
71 cvnfd
.model
['member-vnf-index'] = items
.map(indexAsInteger
).reduce(toBiggestValue
, length
);
73 this.updateModelList('constituent-vnfd', obj
, ConstituentVnfd
, updateNextVnfdIndex
);
76 createConstituentVnfd(model
) {
77 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.constituent-vnfd');
78 return this.constituentVnfd
= DescriptorModelFactory
.newConstituentVnfd(model
, this);
81 removeConstituentVnfd(cvnfd
) {
82 cvnfd
= this.findChildByUid(cvnfd
);
83 this.vld
.forEach(vld
=> vld
.removeVnfdConnectionPointRefForVnfdIndex(cvnfd
.vnfdIndex
));
84 this.vnffgd
.forEach(fg
=> fg
.removeVnfdConnectionPointRefForVnfdIndex(cvnfd
.vnfdIndex
));
85 return this.removeModelListItem('constituentVnfd', cvnfd
);
89 if (!this.model
.pnfd
) {
92 return this.model
.pnfd
.map(d
=> DescriptorModelFactory
.newPhysicalNetworkFunction(d
, this));
96 this.updateModelList('pnfd', obj
, PhysicalNetworkFunction
);
100 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.pnfd');
101 return this.pnfd
= DescriptorModelFactory
.newPhysicalNetworkFunction(model
, this);
105 return this.removeModelListItem('pnfd', pnfd
);
110 if (!this.model
.vld
) {
113 return this.model
.vld
.map(d
=> DescriptorModelFactory
.newVirtualLink(d
, this));
117 this.updateModelList('vld', obj
, VirtualLink
);
121 const property
= DescriptorModelMetaFactory
.getModelMetaForType('nsd.vld');
122 const uniqueName
= DescriptorModelMetaFactory
.generateItemUniqueName(this.vld
, property
);
123 const model
= DescriptorModelMetaFactory
.createModelInstanceForType('nsd.vld', uniqueName
);
124 return this.vld
= DescriptorModelFactory
.newVirtualLink(model
, this);
128 return this.removeModelListItem('vld', vld
);
133 if (!this.model
.vnffgd
) {
134 this.model
.vnffgd
= [];
136 return this.model
.vnffgd
.map(d
=> DescriptorModelFactory
.newForwardingGraph(d
, this)).map((fg
, i
) => {
137 fg
.uiState
.colors
= ColorGroups
.getColorPair(i
);
143 this.updateModelList('vnffgd', obj
, ForwardingGraph
);
146 createVnffgd(model
) {
147 const property
= DescriptorModelMetaFactory
.getModelMetaForType('nsd.vnffgd');
148 const uniqueName
= DescriptorModelMetaFactory
.generateItemUniqueName(this.vnffgd
, property
, 'fg');
149 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.vnffgd', uniqueName
);
150 return this.vnffgd
= DescriptorModelFactory
.newForwardingGraph(model
, this);
154 return this.removeModelListItem('vnffgd', fg
);
157 get forwardingGraphs() {
162 // NOTE temporarily disable NSD connection points
163 // https://trello.com/c/crVgg2A1/88-do-not-render-nsd-connection-in-the-composer
164 //get connectionPoint() {
165 // if (this.model && this.model['connection-point']) {
166 // return this.model['connection-point'];
172 // const parent = this;
173 // if (!this._connectors.length) {
174 // this._connectors = this.connectionPoint.map(cp => {
175 // return DescriptorModelFactory.newConnectionPoint(parent, cp);
178 // return this._connectors;
181 removeAnyConnectionsForConnector(cpc
) {
182 // todo need to also remove connection points from related ForwardingGraph paths
183 this.vld
.forEach(vldc
=> vldc
.removeVnfdConnectionPointRefKey(cpc
.key
));
186 createConstituentVnfdForVnfd(vnfdRef
) {
187 const cvnfd
= this.createConstituentVnfd();
188 cvnfd
.vnfdRef
= vnfdRef
;
189 cvnfd
.vnfdId
= vnfdRef
.id
;