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