Fix FindBugs violations
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronPort.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation and others.  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 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
20
21 @XmlRootElement
22 @XmlAccessorType(XmlAccessType.NONE)
23 public final class NeutronPort extends NeutronAdminAttributes<NeutronPort> {
24     private static final long serialVersionUID = 1L;
25
26     // See OpenStack Network API v2.0 Reference for description of
27     // annotated attributes
28
29     @XmlElement(name = "network_id")
30     String networkUUID;
31
32     @XmlElement(name = "mac_address")
33     String macAddress;
34
35     @XmlElement(name = "fixed_ips")
36     List<NeutronIps> fixedIps;
37
38     @XmlElement(name = "device_id")
39     String deviceID;
40
41     @XmlElement(name = "device_owner")
42     String deviceOwner;
43
44     @XmlElement(name = "security_groups")
45     List<NeutronSecurityGroup> securityGroups;
46
47     @XmlElement(name = "allowed_address_pairs")
48     List<NeutronPortAllowedAddressPairs> allowedAddressPairs;
49
50     //@XmlElement (name = "binding:host_id")
51     @XmlElement(namespace = "binding", name = "host_id")
52     String bindinghostID;
53
54     //@XmlElement (name = "binding:vnic_type")
55     @XmlElement(namespace = "binding", name = "vnic_type")
56     String bindingvnicType;
57
58     //@XmlElement (name = "binding:vif_type")
59     @XmlElement(namespace = "binding", name = "vif_type")
60     String bindingvifType;
61
62     //@XmlElement (name = "binding:profile")
63     @XmlElement(namespace = "binding", name = "profile")
64     String bindingProfile;
65
66     //@XmlElement (name = "binding:vif_details")
67     @XmlElement(namespace = "binding", name = "vif_details")
68     @XmlJavaTypeAdapter(NeutronResourceMapPropertyAdapter.class)
69     Map<String, String> vifDetails;
70
71     @XmlElement(name = "extra_dhcp_opts")
72     List<NeutronPortExtraDHCPOption> extraDHCPOptions;
73
74     //Port security is enabled by default for backward compatibility.
75     @XmlElement(defaultValue = "true", name = "port_security_enabled")
76     Boolean portSecurityEnabled;
77
78     @XmlElement(name = "qos_policy_id")
79     String qosPolicyId;
80
81     public NeutronPort() {
82     }
83
84     public String getNetworkUUID() {
85         return networkUUID;
86     }
87
88     public void setNetworkUUID(String networkUUID) {
89         this.networkUUID = networkUUID;
90     }
91
92     public String getMacAddress() {
93         return macAddress;
94     }
95
96     public void setMacAddress(String macAddress) {
97         this.macAddress = macAddress;
98     }
99
100     public List<NeutronIps> getFixedIps() {
101         return fixedIps;
102     }
103
104     public void setFixedIps(List<NeutronIps> fixedIps) {
105         this.fixedIps = fixedIps;
106     }
107
108     public String getDeviceID() {
109         return deviceID;
110     }
111
112     public void setDeviceID(String deviceID) {
113         this.deviceID = deviceID;
114     }
115
116     public String getDeviceOwner() {
117         return deviceOwner;
118     }
119
120     public void setDeviceOwner(String deviceOwner) {
121         this.deviceOwner = deviceOwner;
122     }
123
124     public List<NeutronSecurityGroup> getSecurityGroups() {
125         return securityGroups;
126     }
127
128     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
129         this.securityGroups = securityGroups;
130     }
131
132     public List<NeutronPortAllowedAddressPairs> getAllowedAddressPairs() {
133         return allowedAddressPairs;
134     }
135
136     public void setAllowedAddressPairs(List<NeutronPortAllowedAddressPairs> allowedAddressPairs) {
137         this.allowedAddressPairs = allowedAddressPairs;
138     }
139
140     public List<NeutronPortExtraDHCPOption> getExtraDHCPOptions() {
141         return extraDHCPOptions;
142     }
143
144     public void setExtraDHCPOptions(List<NeutronPortExtraDHCPOption> extraDHCPOptions) {
145         this.extraDHCPOptions = extraDHCPOptions;
146     }
147
148     public Map<String, String> getVIFDetails() {
149         return vifDetails;
150     }
151
152     public void setVIFDetails(Map<String, String> details) {
153         this.vifDetails = details;
154     }
155
156     public String getBindinghostID() {
157         return bindinghostID;
158     }
159
160     public void setBindinghostID(String bindinghostID) {
161         this.bindinghostID = bindinghostID;
162     }
163
164     public String getProfile() {
165         return bindingProfile;
166     }
167
168     public void setProfile(String newBindingProfile) {
169         this.bindingProfile = newBindingProfile;
170     }
171
172     public String getBindingvnicType() {
173         return bindingvnicType;
174     }
175
176     public void setBindingvnicType(String bindingvnicType) {
177         this.bindingvnicType = bindingvnicType;
178     }
179
180     public String getBindingvifType() {
181         return bindingvifType;
182     }
183
184     public void setBindingvifType(String bindingvifType) {
185         this.bindingvifType = bindingvifType;
186     }
187
188     public Boolean getPortSecurityEnabled() {
189         if (portSecurityEnabled == null) {
190             return true;
191         }
192         return portSecurityEnabled;
193     }
194
195     public String getQosPolicyId() {
196         return qosPolicyId;
197     }
198
199     public void setQosPolicyId(String qosPolicyId) {
200         this.qosPolicyId = qosPolicyId;
201     }
202
203     public void setPortSecurityEnabled(Boolean newValue) {
204         portSecurityEnabled = newValue;
205     }
206
207     @Override
208     protected boolean extractField(String field, NeutronPort ans) {
209         switch (field) {
210             case "network_id":
211                 ans.setNetworkUUID(this.getNetworkUUID());
212                 break;
213             case "mac_address":
214                 ans.setMacAddress(this.getMacAddress());
215                 break;
216             case "fixed_ips":
217                 ans.setFixedIps(new ArrayList<>(this.getFixedIps()));
218                 break;
219             case "device_id":
220                 ans.setDeviceID(this.getDeviceID());
221                 break;
222             case "device_owner":
223                 ans.setDeviceOwner(this.getDeviceOwner());
224                 break;
225             case "security_groups":
226                 ans.setSecurityGroups(new ArrayList<>(this.getSecurityGroups()));
227                 break;
228             case "allowed_address_pairs":
229                 ans.setAllowedAddressPairs(
230                         new ArrayList<>(this.getAllowedAddressPairs()));
231                 break;
232             case "binding:host_id":
233                 ans.setBindinghostID(this.getBindinghostID());
234                 break;
235             case "binding:vnic_type":
236                 ans.setBindingvnicType(this.getBindingvnicType());
237                 break;
238             case "binding:vif_type":
239                 ans.setBindingvifType(this.getBindingvifType());
240                 break;
241             case "binding:profile":
242                 ans.setProfile(this.getProfile());
243                 break;
244             case "binding:vif_details":
245                 ans.setVIFDetails(new HashMap<>(this.getVIFDetails()));
246                 break;
247             case "extra_dhcp_opts":
248                 ans.setExtraDHCPOptions(new ArrayList<>(this.getExtraDHCPOptions()));
249                 break;
250             case "port_security_enabled":
251                 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
252                 break;
253             case "qos_policy_id":
254                 ans.setQosPolicyId(this.getQosPolicyId());
255                 break;
256             default:
257                 return super.extractField(field, ans);
258         }
259         return true;
260     }
261
262     @Override
263     public void initDefaults() {
264         super.initDefaults();
265         if (portSecurityEnabled == null) {
266             portSecurityEnabled = true;
267         }
268         if (fixedIps == null) {
269             fixedIps = new ArrayList<>();
270         }
271     }
272
273     @Override
274     public String toString() {
275         return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name + ", adminStateUp="
276                 + adminStateUp + ", status=" + status + ", macAddress=" + macAddress + ", fixedIps=" + fixedIps
277                 + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID=" + tenantID
278                 + ", securityGroups=" + securityGroups + ", allowedAddressPairs" + allowedAddressPairs
279                 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType + ", bindingvifType="
280                 + bindingvifType + ", vifDetails=" + vifDetails + ", bindingProfile=" + bindingProfile
281                 + ", extraDHCPOptions=" + extraDHCPOptions
282                 + ", portSecurityEnabled=" + portSecurityEnabled + ", qosPolicyId=" + qosPolicyId + "]";
283     }
284 }