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