Cleaning up style checks in spi part 1
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronPort.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.neutron.spi;
10
11
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.List;
17
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlElement;
21 import javax.xml.bind.annotation.XmlRootElement;
22
23
24 @XmlRootElement
25 @XmlAccessorType(XmlAccessType.NONE)
26
27 public class NeutronPort implements Serializable, INeutronObject {
28     private static final long serialVersionUID = 1L;
29
30     // See OpenStack Network API v2.0 Reference for description of
31     // annotated attributes
32
33     @XmlElement (name = "id")
34     String portUUID;
35
36     @XmlElement (name = "network_id")
37     String networkUUID;
38
39     @XmlElement (name = "name")
40     String name;
41
42     @XmlElement (defaultValue = "true", name = "admin_state_up")
43     Boolean adminStateUp;
44
45     @XmlElement (name = "status")
46     String status;
47
48     @XmlElement (name = "mac_address")
49     String macAddress;
50
51     @XmlElement (name = "fixed_ips")
52     List<Neutron_IPs> fixedIPs;
53
54     @XmlElement (name = "device_id")
55     String deviceID;
56
57     @XmlElement (name = "device_owner")
58     String deviceOwner;
59
60     @XmlElement (name = "tenant_id")
61     String tenantID;
62
63     @XmlElement (name = "security_groups")
64     List<NeutronSecurityGroup> securityGroups;
65
66     @XmlElement (name = "allowed_address_pairs")
67     List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
68
69     @XmlElement (namespace = "binding", name = "host_id")
70     String bindinghostID;
71
72     @XmlElement (namespace = "binding", name = "vnic_type")
73     String bindingvnicType;
74
75     @XmlElement (namespace = "binding", name = "vif_type")
76     String bindingvifType;
77
78
79     /* this attribute stores the floating IP address assigned to
80      * each fixed IP address
81      */
82
83     HashMap<String, NeutronFloatingIP> floatingIPMap;
84
85     public NeutronPort() {
86         floatingIPMap = new HashMap<String, NeutronFloatingIP>();
87     }
88
89     public String getID() { return portUUID; }
90
91     public void setID(String id) { this.portUUID = id; }
92
93     public String getPortUUID() {
94         return portUUID;
95     }
96
97     public void setPortUUID(String portUUID) {
98         this.portUUID = portUUID;
99     }
100
101     public String getNetworkUUID() {
102         return networkUUID;
103     }
104
105     public void setNetworkUUID(String networkUUID) {
106         this.networkUUID = networkUUID;
107     }
108
109     public String getName() {
110         return name;
111     }
112
113     public void setName(String name) {
114         this.name = name;
115     }
116
117     public boolean isAdminStateUp() {
118         if (adminStateUp == null) {
119             return true;
120         }
121         return adminStateUp;
122     }
123
124     public Boolean getAdminStateUp() { return adminStateUp; }
125
126     public void setAdminStateUp(Boolean newValue) {
127             adminStateUp = newValue;
128     }
129
130     public String getStatus() {
131         return status;
132     }
133
134     public void setStatus(String status) {
135         this.status = status;
136     }
137
138     public String getMacAddress() {
139         return macAddress;
140     }
141
142     public void setMacAddress(String macAddress) {
143         this.macAddress = macAddress;
144     }
145
146     public List<Neutron_IPs> getFixedIPs() {
147         return fixedIPs;
148     }
149
150     public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
151         this.fixedIPs = fixedIPs;
152     }
153
154     public String getDeviceID() {
155         return deviceID;
156     }
157
158     public void setDeviceID(String deviceID) {
159         this.deviceID = deviceID;
160     }
161
162     public String getDeviceOwner() {
163         return deviceOwner;
164     }
165
166     public void setDeviceOwner(String deviceOwner) {
167         this.deviceOwner = deviceOwner;
168     }
169
170     public String getTenantID() {
171         return tenantID;
172     }
173
174     public void setTenantID(String tenantID) {
175         this.tenantID = tenantID;
176     }
177
178     public List<NeutronSecurityGroup> getSecurityGroups() {
179         return securityGroups;
180     }
181
182     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
183         this.securityGroups = securityGroups;
184     }
185
186     public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
187         return allowedAddressPairs;
188     }
189
190     public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
191         this.allowedAddressPairs = allowedAddressPairs;
192     }
193
194     public String getBindinghostID() {
195       return bindinghostID;
196     }
197
198     public void setBindinghostID(String bindinghostID) {
199       this.bindinghostID = bindinghostID;
200     }
201
202   public String getBindingvnicType() {
203     return bindingvnicType;
204   }
205
206   public void setBindingvnicType(String bindingvnicType) {
207     this.bindingvnicType = bindingvnicType;
208   }
209
210   public String getBindingvifType() {
211     return bindingvifType;
212   }
213
214   public void setBindingvifType(String bindingvifType) {
215     this.bindingvifType = bindingvifType;
216   }
217
218     public NeutronFloatingIP getFloatingIP(String key) {
219         if (!floatingIPMap.containsKey(key)) {
220             return null;
221         }
222         return floatingIPMap.get(key);
223     }
224
225     public void removeFloatingIP(String key) {
226         floatingIPMap.remove(key);
227     }
228
229     public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
230         if (!floatingIPMap.containsKey(key)) {
231             floatingIPMap.put(key, floatingIP);
232         }
233     }
234
235     /**
236      * This method copies selected fields from the object and returns them
237      * as a new object, suitable for marshaling.
238      *
239      * @param fields
240      *            List of attributes to be extracted
241      * @return an OpenStackPorts object with only the selected fields
242      * populated
243      */
244
245     public NeutronPort extractFields(List<String> fields) {
246         NeutronPort ans = new NeutronPort();
247         Iterator<String> i = fields.iterator();
248         while (i.hasNext()) {
249             String s = i.next();
250             if (s.equals("id")) {
251                 ans.setPortUUID(this.getPortUUID());
252             }
253             if (s.equals("network_id")) {
254                 ans.setNetworkUUID(this.getNetworkUUID());
255             }
256             if (s.equals("name")) {
257                 ans.setName(this.getName());
258             }
259             if (s.equals("admin_state_up")) {
260                 ans.setAdminStateUp(this.getAdminStateUp());
261             }
262             if (s.equals("status")) {
263                 ans.setStatus(this.getStatus());
264             }
265             if (s.equals("mac_address")) {
266                 ans.setMacAddress(this.getMacAddress());
267             }
268             if (s.equals("fixed_ips")) {
269                 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
270                 fixedIPs.addAll(this.getFixedIPs());
271                 ans.setFixedIPs(fixedIPs);
272             }
273             if (s.equals("device_id")) {
274                 ans.setDeviceID(this.getDeviceID());
275             }
276             if (s.equals("device_owner")) {
277                 ans.setDeviceOwner(this.getDeviceOwner());
278             }
279             if (s.equals("tenant_id")) {
280                 ans.setTenantID(this.getTenantID());
281             }
282             if (s.equals("security_groups")) {
283                 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
284                 securityGroups.addAll(this.getSecurityGroups());
285                 ans.setSecurityGroups(securityGroups);
286             }
287         }
288         return ans;
289     }
290
291     public void initDefaults() {
292         adminStateUp = true;
293         if (status == null) {
294             status = "ACTIVE";
295         }
296         if (fixedIPs == null) {
297             fixedIPs = new ArrayList<Neutron_IPs>();
298         }
299     }
300
301     /**
302      * This method checks to see if the port has a floating IPv4 address
303      * associated with the supplied fixed IPv4 address
304      *
305      * @param fixedIP
306      *            fixed IPv4 address in dotted decimal format
307      * @return a boolean indicating if there is a floating IPv4 address bound
308      * to the fixed IPv4 address
309      */
310
311     public boolean isBoundToFloatingIP(String fixedIP) {
312         return floatingIPMap.containsKey(fixedIP);
313     }
314
315     @Override
316     public String toString() {
317         return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
318                 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
319                 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
320                 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups
321                 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
322                 + ", bindingvnicType=" + bindingvnicType + "]";
323     }
324 }