Change the header to SO
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / openstack / beans / NetworkInfo.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.openstack.beans;
22
23
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.HashMap;
29
30 import com.woorea.openstack.quantum.model.Network;
31 import com.woorea.openstack.quantum.model.Segment;
32
33 /*
34  * This Java bean class relays Network details (including status) to ActiveVOS processes.
35  *
36  * This bean is returned by all Network-specific adapter operations (create, query, delete)
37  */
38
39 public class NetworkInfo {
40         // Set defaults for everything
41         private String name = "";
42         private String id = "";
43         private NetworkStatus status = NetworkStatus.UNKNOWN;
44         private String provider = "";
45         private List<Integer> vlans = new ArrayList<Integer>();
46         private List<String> subnets = new ArrayList<String>();
47         private String shared = "";
48
49         static Map<String,NetworkStatus> NetworkStatusMap;
50         static {
51                 NetworkStatusMap = new HashMap<String,NetworkStatus>();
52                 NetworkStatusMap.put("ACTIVE", NetworkStatus.ACTIVE);
53                 NetworkStatusMap.put("DOWN", NetworkStatus.DOWN);
54                 NetworkStatusMap.put("BUILD", NetworkStatus.BUILD);
55                 NetworkStatusMap.put("ERROR", NetworkStatus.ERROR);
56         }
57
58         public NetworkInfo () {
59         }
60
61         public NetworkInfo (String name, NetworkStatus status) {
62                 this.name = name;
63                 this.id = name; // Don't have an ID, so just use name
64                 this.status = status;
65         }
66
67         /**
68          * Capture the data from a Neutron Network object.
69          *
70          * For MSO, there are assumptions regarding all networks.
71          * - Everything will be a provider network
72          * - All provider networks are VLANs
73          * - Multiple VLANs are supported, and indicated by multi-provider segments.
74          *   Each will have the same physical network & network type "vlan".
75          *
76          * @param network
77          */
78         public NetworkInfo (Network network)
79         {
80                 if (network == null) {
81                         this.status = NetworkStatus.NOTFOUND;
82                         return;
83                 }
84
85                 this.name = network.getName();
86                 this.id = network.getId();
87
88                 if (network.getStatus() == null) {
89                         // Can this happen on a newly created network?
90                         this.status = NetworkStatus.UNKNOWN;
91                 } else if (NetworkStatusMap.containsKey(network.getStatus())) {
92                         this.status = NetworkStatusMap.get(network.getStatus());
93                 } else {
94                         this.status = NetworkStatus.UNKNOWN;
95                 }
96
97                 if (network.getProviderPhysicalNetwork() != null) {
98                         this.provider = network.getProviderPhysicalNetwork();
99                         if (network.getProviderNetworkType().equals("vlan")) {
100                 this.vlans.add(network.getProviderSegmentationId());
101             }
102                 }
103                 else if (network.getSegments() != null && network.getSegments().size() > 0) {
104                         Segment s = network.getSegments().get(0);
105                         this.provider = s.getProviderPhysicalNetwork();
106                         if (s.getProviderNetworkType().equals("vlan")) {
107                 for (Segment s1 : network.getSegments()) {
108                                         this.vlans.add(s1.getProviderSegmentationId());
109                                 }
110             }
111                 }
112                 this.subnets = network.getSubnets();
113         }
114
115         public String getName() {
116                 return name;
117         }
118
119         public void setName (String name) {
120                 this.name = name;
121         }
122
123         public String getId() {
124                 return id;
125         }
126
127         public void setId (String id) {
128                 this.id = id;
129         }
130
131         public NetworkStatus getStatus() {
132                 return status;
133         }
134
135         public void setStatus (NetworkStatus status) {
136                 this.status = status;
137         }
138
139         public String getProvider() {
140                 return provider;
141         }
142
143         public void setProvider (String provider) {
144                 this.provider = provider;
145         }
146
147         public List<Integer> getVlans () {
148                 return vlans;
149         }
150
151         public void setVlans (List<Integer> vlans) {
152                 this.vlans = vlans;
153         }
154
155         public List<String> getSubnets () {
156                 return subnets;
157         }
158
159         public void setSubnets (List<String> subnets) {
160                 this.subnets = subnets;
161         }
162
163         public String getShared() {
164                 return shared;
165         }
166
167         public void setShared(String shared) {
168                 this.shared = shared;
169         }
170
171         @Override
172     public String toString () {
173                 return "Network: name=" + name + ",id=" + id + ",status=" + status +
174                                 ",provider=" + provider + ",vlans=" + vlans + ",subnets=" + subnets + ",shared=" + shared;
175         }
176 }
177