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 VirtualNetworkFunctionAccessPointMap
from './VirtualNetworkFunctionAccessPointMap'
28 import VirtualLink
from './VirtualLink'
29 import ConstituentVnfd
from './ConstituentVnfd'
30 import PhysicalNetworkFunction
from './PhysicalNetworkFunction'
31 import DescriptorModelFactory
from '../DescriptorModelFactory'
32 import DescriptorModelMetaFactory
from '../DescriptorModelMetaFactory'
34 const indexAsInteger
= d
=> 1 + (parseInt(d
.model
['member-vnf-index'], 10) || 0);
36 const suffixAsInteger = function (field
) {
37 return (d
) => 1 + (parseInt(String(d
.model
[field
]).split('').reverse().join(''), 10) || 0);
40 const toBiggestValue
= (newIndex
, curIndex
) => Math
.max(newIndex
, curIndex
);
42 export default class NetworkService
extends DescriptorModel
{
48 static get className() {
49 return 'NetworkService';
52 constructor(model
, parent
) {
55 this.className
= 'NetworkService';
56 this._connectors
= [];
59 get constituentVnfd() {
60 if (!this.model
['constituent-vnfd']) {
61 this.model
['constituent-vnfd'] = [];
63 return this.model
['constituent-vnfd'].map(d
=> DescriptorModelFactory
.newConstituentVnfd(d
, this));
66 set constituentVnfd(obj
) {
67 const updateNextVnfdIndex
= (cvnfd
) => {
68 const items
= this.constituentVnfd
;
69 const length
= items
.length
;
70 // the default value is set to an instance count but we want it to be a sequence no
71 cvnfd
.model
['member-vnf-index'] = 0;
72 cvnfd
.model
['member-vnf-index'] = items
.map(indexAsInteger
).reduce(toBiggestValue
, length
);
74 this.updateModelList('constituent-vnfd', obj
, ConstituentVnfd
, updateNextVnfdIndex
);
77 createConstituentVnfd(model
) {
78 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.constituent-vnfd');
79 return this.constituentVnfd
= DescriptorModelFactory
.newConstituentVnfd(model
, this);
82 removeConstituentVnfd(cvnfd
) {
83 cvnfd
= this.findChildByUid(cvnfd
);
84 this.vld
.forEach(vld
=> vld
.removeVnfdConnectionPointRefForVnfdIndex(cvnfd
.vnfdIndex
));
85 this.vnffgd
.forEach(fg
=> fg
.removeVnfdConnectionPointRefForVnfdIndex(cvnfd
.vnfdIndex
));
86 return this.removeModelListItem('constituentVnfd', cvnfd
);
90 if (!this.model
.pnfd
) {
93 return this.model
.pnfd
.map(d
=> DescriptorModelFactory
.newPhysicalNetworkFunction(d
, this));
97 this.updateModelList('pnfd', obj
, PhysicalNetworkFunction
);
101 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.pnfd');
102 return this.pnfd
= DescriptorModelFactory
.newPhysicalNetworkFunction(model
, this);
106 return this.removeModelListItem('pnfd', pnfd
);
111 if (!this.model
.vld
) {
114 return this.model
.vld
.map(d
=> DescriptorModelFactory
.newVirtualLink(d
, this));
118 this.updateModelList('vld', obj
, VirtualLink
);
122 const property
= DescriptorModelMetaFactory
.getModelMetaForType('nsd.vld');
123 const uniqueName
= DescriptorModelMetaFactory
.generateItemUniqueName(this.vld
, property
);
124 const model
= DescriptorModelMetaFactory
.createModelInstanceForType('nsd.vld', uniqueName
);
125 return this.vld
= DescriptorModelFactory
.newVirtualLink(model
, this);
129 return this.removeModelListItem('vld', vld
);
133 // <<<<<<< Updated upstream
134 // get configParameterMap() {
135 // if (!this.model['config-parameter-map']) {
136 // this.model['config-parameter-map'] = [];
138 // return this.model['config-parameter-map'].map(d => DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(d, this)).map((fg, i) => {
143 // set configParameterMap(obj) {
144 // const onVirtualNetworkFunctionAccessPointMap = (fg) => {
147 // this.updateModelList('config-parameter-map', obj, VirtualNetworkFunctionAccessPointMap, onVirtualNetworkFunctionAccessPointMap);
150 // createConfigParameterMap(model) {
151 // model = model || DescriptorModelMetaFactory.createModelInstanceForType('nsd.config-parameter-map');
152 // return this.configParameterMap = DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(model, this);
155 get configParameterMap() {
156 if (!this.model
['config-parameter-map']) {
157 this.model
['config-parameter-map'] = [];
159 return this.model
['config-parameter-map'].map(d
=> DescriptorModelFactory
.newVirtualNetworkFunctionAccessPointMap(d
, this))
162 set configParameterMap(obj
) {
163 this.updateModelList('config-parameter-map', obj
, VirtualNetworkFunctionAccessPointMap
);
166 createConfigParameterMap() {
167 const model
= DescriptorModelMetaFactory
.createModelInstanceForType('nsd.config-parameter-map');
168 return this.configParameterMap
= DescriptorModelFactory
.newVirtualNetworkFunctionAccessPointMap(model
, this);
170 // >>>>>>> Stashed changes
173 if (!this.model
.vnffgd
) {
174 this.model
.vnffgd
= [];
176 return this.model
.vnffgd
.map(d
=> DescriptorModelFactory
.newForwardingGraph(d
, this)).map((fg
, i
) => {
177 fg
.uiState
.colors
= ColorGroups
.getColorPair(i
);
183 this.updateModelList('vnffgd', obj
, ForwardingGraph
);
186 createVnffgd(model
) {
187 const property
= DescriptorModelMetaFactory
.getModelMetaForType('nsd.vnffgd');
188 const uniqueName
= DescriptorModelMetaFactory
.generateItemUniqueName(this.vnffgd
, property
, 'fg');
189 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.vnffgd', uniqueName
);
190 return this.vnffgd
= DescriptorModelFactory
.newForwardingGraph(model
, this);
194 return this.removeModelListItem('vnffgd', fg
);
197 get forwardingGraphs() {
203 // NOTE temporarily disable NSD connection points
204 // https://trello.com/c/crVgg2A1/88-do-not-render-nsd-connection-in-the-composer
205 //get connectionPoint() {
206 // if (this.model && this.model['connection-point']) {
207 // return this.model['connection-point'];
213 // const parent = this;
214 // if (!this._connectors.length) {
215 // this._connectors = this.connectionPoint.map(cp => {
216 // return DescriptorModelFactory.newConnectionPoint(parent, cp);
219 // return this._connectors;
222 removeAnyConnectionsForConnector(cpc
) {
223 // todo need to also remove connection points from related ForwardingGraph paths
224 this.vld
.forEach(vldc
=> vldc
.removeVnfdConnectionPointRefKey(cpc
.key
));
227 createConstituentVnfdForVnfd(vnfdRef
) {
228 const cvnfd
= this.createConstituentVnfd();
229 cvnfd
.vnfdRef
= vnfdRef
;
230 cvnfd
.vnfdId
= vnfdRef
.id
;