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