0e44d7bccb054854249b8bdc9c6eaee70b08d631
[osm/riftware.git] /
1 /*
2  *    Copyright 2016 RIFT.IO Inc
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 /*
18  * STANDARD_RIFT_IO_COPYRIGHT
19  */
20 /**
21  * Created by onvelocity on 11/23/15.
22  */
23
24 'use strict';
25
26 import Position from '../../graph/Position'
27 import DescriptorModel from '../DescriptorModel'
28 import RspConnectionPointRef from './RspConnectionPointRef'
29 import VnfdConnectionPointRef from './VnfdConnectionPointRef'
30 import DescriptorModelFactory from '../DescriptorModelFactory'
31
32 /**
33  * A VirtualNetworkFunctionConnectionPoint is always a child of a VNFD. We use it to build VnfdConnectionPointRef instances. So convenience
34  * methods are add to access the fields needed to do that.
35  */
36 export default class ConnectionPoint extends DescriptorModel {
37
38         static get type() {
39                 return 'connection-point';
40         }
41
42         static get className() {
43                 return 'VirtualNetworkFunctionConnectionPoint';
44         }
45
46         static get qualifiedType() {
47                 return 'vnfd.' + ConnectionPoint.type;
48         }
49
50         constructor(model, parent) {
51                 super(model, parent);
52                 this.type = ConnectionPoint.type;
53                 this.uiState['qualified-type'] = ConnectionPoint.qualifiedType;
54                 this.className = 'VirtualNetworkFunctionConnectionPoint';
55                 this.location = 'bottom-left';
56                 this.position = new Position(parent.position.value());
57                 this.position.top = parent.position.bottom;
58                 this.position.width = 14;
59                 this.position.height = 14;
60         }
61
62         get id() {
63                 return this.model.name;
64         }
65
66         get key() {
67                 return this.parent.key + '/' + this.model.name;
68         }
69
70         get name() {
71                 return this.model.name;
72         }
73
74         get vnfdIndex() {
75                 return this.parent.vnfdIndex;
76         }
77
78         get vnfdId() {
79                 return this.parent.vnfdId;
80         }
81
82         get cpNumber() {
83                 return this.uiState.cpNumber;
84         }
85
86         set cpNumber(n) {
87                 this.uiState.cpNumber = n;
88         }
89
90         /**
91          * Convenience method to generate a VnfdConnectionPointRef instance from any given VirtualNetworkFunctionConnectionPoint.
92          *
93          * @returns {RspConnectionPointRef}
94          */
95         toRspConnectionPointRef() {
96                 const ref = new RspConnectionPointRef({});
97                 ref.vnfdId = this.vnfdId;
98                 ref.vnfdIndex = this.vnfdIndex;
99                 ref.vnfdConnectionPointName = this.name;
100                 ref.cpNumber = this.cpNumber;
101                 return ref;
102         }
103
104         toVnfdConnectionPointRef() {
105                 const ref = new VnfdConnectionPointRef({});
106                 ref.vnfdId = this.vnfdId;
107                 ref.vnfdIndex = this.vnfdIndex;
108                 ref.vnfdConnectionPointName = this.name;
109                 ref.cpNumber = this.cpNumber;
110                 return ref;
111         }
112
113         canConnectTo(obj) {
114                 return (DescriptorModelFactory.isVirtualLink(obj) || DescriptorModelFactory.isConnectionPoint(obj)) && obj.parent !== this.parent;
115         }
116
117         remove() {
118                 return this.parent.removeConnectionPoint(this);
119         }
120
121 }