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 _
from 'lodash'
25 import ColorGroups
from '../../ColorGroups'
26 import DescriptorModel
from '../DescriptorModel'
27 import ForwardingGraph
from './ForwardingGraph'
28 import VirtualNetworkFunctionAccessPointMap
from './VirtualNetworkFunctionAccessPointMap'
29 import VirtualLink
from './VirtualLink'
30 import ConstituentVnfd
from './ConstituentVnfd'
31 import PhysicalNetworkFunction
from './PhysicalNetworkFunction'
32 import DescriptorModelFactory
from '../DescriptorModelFactory'
33 import DescriptorModelMetaFactory
from '../DescriptorModelMetaFactory'
35 const indexAsInteger
= d
=> 1 + (parseInt(d
.model
['member-vnf-index'], 10) || 0);
37 const suffixAsInteger = function (field
) {
38 return (d
) => 1 + (parseInt(String(d
.model
[field
]).split('').reverse().join(''), 10) || 0);
41 const toBiggestValue
= (newIndex
, curIndex
) => Math
.max(newIndex
, curIndex
);
43 export default class NetworkService
extends DescriptorModel
{
49 static get className() {
50 return 'NetworkService';
53 constructor(model
, parent
) {
56 this.className
= 'NetworkService';
57 this._connectors
= [];
60 get constituentVnfd() {
61 if (!this.model
['constituent-vnfd']) {
62 this.model
['constituent-vnfd'] = [];
64 return this.model
['constituent-vnfd'].map(d
=> DescriptorModelFactory
.newConstituentVnfd(d
, this));
67 set constituentVnfd(obj
) {
68 const updateNextVnfdIndex
= (cvnfd
) => {
69 const items
= this.constituentVnfd
;
70 const length
= items
.length
;
71 // the default value is set to an instance count but we want it to be a sequence no
72 cvnfd
.model
['member-vnf-index'] = 0;
73 cvnfd
.model
['member-vnf-index'] = items
.map(indexAsInteger
).reduce(toBiggestValue
, length
);
75 this.updateModelList('constituent-vnfd', obj
, ConstituentVnfd
, updateNextVnfdIndex
);
78 createConstituentVnfd(model
) {
79 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.constituent-vnfd');
80 return this.constituentVnfd
= DescriptorModelFactory
.newConstituentVnfd(model
, this);
83 removeConstituentVnfd(cvnfd
) {
84 cvnfd
= this.findChildByUid(cvnfd
);
85 this.vld
.forEach(vld
=> vld
.removeVnfdConnectionPointRefForVnfdIndex(cvnfd
.vnfdIndex
));
86 this.vnffgd
.forEach(fg
=> fg
.removeVnfdConnectionPointRefForVnfdIndex(cvnfd
.vnfdIndex
));
87 return this.removeModelListItem('constituentVnfd', cvnfd
);
91 if (!this.model
.pnfd
) {
94 return this.model
.pnfd
.map(d
=> DescriptorModelFactory
.newPhysicalNetworkFunction(d
, this));
98 this.updateModelList('pnfd', obj
, PhysicalNetworkFunction
);
102 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.pnfd');
103 return this.pnfd
= DescriptorModelFactory
.newPhysicalNetworkFunction(model
, this);
107 return this.removeModelListItem('pnfd', pnfd
);
112 if (!this.model
.vld
) {
115 return this.model
.vld
.map(d
=> DescriptorModelFactory
.newVirtualLink(d
, this));
119 this.updateModelList('vld', obj
, VirtualLink
);
123 const model
= DescriptorModelMetaFactory
.createModelInstanceForType('nsd.vld');
124 return this.vld
= DescriptorModelFactory
.newVirtualLink(model
, this);
128 return this.removeModelListItem('vld', vld
);
132 // <<<<<<< Updated upstream
133 // get configParameterMap() {
134 // if (!this.model['config-parameter-map']) {
135 // this.model['config-parameter-map'] = [];
137 // return this.model['config-parameter-map'].map(d => DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(d, this)).map((fg, i) => {
142 // set configParameterMap(obj) {
143 // const onVirtualNetworkFunctionAccessPointMap = (fg) => {
146 // this.updateModelList('config-parameter-map', obj, VirtualNetworkFunctionAccessPointMap, onVirtualNetworkFunctionAccessPointMap);
149 // createConfigParameterMap(model) {
150 // model = model || DescriptorModelMetaFactory.createModelInstanceForType('nsd.config-parameter-map');
151 // return this.configParameterMap = DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(model, this);
154 get configParameterMap() {
155 if (!this.model
['config-parameter-map']) {
156 this.model
['config-parameter-map'] = [];
158 return this.model
['config-parameter-map'].map(d
=> DescriptorModelFactory
.newVirtualNetworkFunctionAccessPointMap(d
, this))
161 set configParameterMap(obj
) {
162 this.updateModelList('config-parameter-map', obj
, VirtualNetworkFunctionAccessPointMap
);
165 createConfigParameterMap() {
166 const model
= DescriptorModelMetaFactory
.createModelInstanceForType('nsd.config-parameter-map');
167 return this.configParameterMap
= DescriptorModelFactory
.newVirtualNetworkFunctionAccessPointMap(model
, this);
169 // >>>>>>> Stashed changes
172 if (!this.model
.vnffgd
) {
173 this.model
.vnffgd
= [];
175 return this.model
.vnffgd
.map(d
=> DescriptorModelFactory
.newForwardingGraph(d
, this)).map((fg
, i
) => {
176 fg
.uiState
.colors
= ColorGroups
.getColorPair(i
);
182 const onAddForwardingGraph
= (fg
) => {
183 const index
= this.vnffgd
.map(suffixAsInteger('short-name')).reduce(toBiggestValue
, this.vnffgd
.length
);
184 fg
.model
['short-name'] = 'FG-' + index
;
186 this.updateModelList('vnffgd', obj
, ForwardingGraph
, onAddForwardingGraph
);
189 createVnffgd(model
) {
190 model
= model
|| DescriptorModelMetaFactory
.createModelInstanceForType('nsd.vnffgd');
191 return this.vnffgd
= DescriptorModelFactory
.newForwardingGraph(model
, this);
195 return this.removeModelListItem('vnffgd', fg
);
198 get forwardingGraphs() {
204 // NOTE temporarily disable NSD connection points
205 // https://trello.com/c/crVgg2A1/88-do-not-render-nsd-connection-in-the-composer
206 //get connectionPoint() {
207 // if (this.model && this.model['connection-point']) {
208 // return this.model['connection-point'];
214 // const parent = this;
215 // if (!this._connectors.length) {
216 // this._connectors = this.connectionPoint.map(cp => {
217 // return DescriptorModelFactory.newConnectionPoint(parent, cp);
220 // return this._connectors;
223 removeAnyConnectionsForConnector(cpc
) {
224 // todo need to also remove connection points from related ForwardingGraph paths
225 this.vld
.forEach(vldc
=> vldc
.removeVnfdConnectionPointRefKey(cpc
.key
));
228 createConstituentVnfdForVnfd(vnfdRef
) {
229 const cvnfd
= this.createConstituentVnfd();
230 cvnfd
.vnfdRef
= vnfdRef
;
231 cvnfd
.vnfdId
= vnfdRef
.id
;