2 * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved.
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
9 package org.opendaylight.neutron.spi;
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
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;
25 @XmlAccessorType(XmlAccessType.NONE)
26 public class NeutronPort extends NeutronObject implements Serializable, INeutronObject {
27 private static final long serialVersionUID = 1L;
29 // See OpenStack Network API v2.0 Reference for description of
30 // annotated attributes
32 @XmlElement (name = "network_id")
35 @XmlElement (name = "name")
38 @XmlElement (defaultValue = "true", name = "admin_state_up")
41 @XmlElement (name = "status")
44 @XmlElement (name = "mac_address")
47 @XmlElement (name = "fixed_ips")
48 List<Neutron_IPs> fixedIPs;
50 @XmlElement (name = "device_id")
53 @XmlElement (name = "device_owner")
56 @XmlElement (name = "security_groups")
57 List<NeutronSecurityGroup> securityGroups;
59 @XmlElement (name = "allowed_address_pairs")
60 List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
62 //@XmlElement (name = "binding:host_id")
63 @XmlElement (namespace = "binding", name = "host_id")
66 //@XmlElement (name = "binding:vnic_type")
67 @XmlElement (namespace = "binding", name = "vnic_type")
68 String bindingvnicType;
70 //@XmlElement (name = "binding:vif_type")
71 @XmlElement (namespace = "binding", name = "vif_type")
72 String bindingvifType;
74 //@XmlElement (name = "binding:vif_details")
75 @XmlElement (namespace = "binding", name = "vif_details")
76 @XmlJavaTypeAdapter(NeutronResourceMapPropertyAdapter.class)
77 Map<String, String> vifDetails;
79 @XmlElement (name = "extra_dhcp_opts")
80 List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
82 //Port security is enabled by default for backward compatibility.
83 @XmlElement (defaultValue = "true", name = "port_security_enabled")
84 Boolean portSecurityEnabled;
86 @XmlElement (name = "qos_policy_id")
89 public NeutronPort() {
92 public String getNetworkUUID() {
96 public void setNetworkUUID(String networkUUID) {
97 this.networkUUID = networkUUID;
100 public String getName() {
104 public void setName(String name) {
108 public boolean isAdminStateUp() {
109 if (adminStateUp == null) {
115 public Boolean getAdminStateUp() { return adminStateUp; }
117 public void setAdminStateUp(Boolean newValue) {
118 adminStateUp = newValue;
121 public String getStatus() {
125 public void setStatus(String status) {
126 this.status = status;
129 public String getMacAddress() {
133 public void setMacAddress(String macAddress) {
134 this.macAddress = macAddress;
137 public List<Neutron_IPs> getFixedIPs() {
141 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
142 this.fixedIPs = fixedIPs;
145 public String getDeviceID() {
149 public void setDeviceID(String deviceID) {
150 this.deviceID = deviceID;
153 public String getDeviceOwner() {
157 public void setDeviceOwner(String deviceOwner) {
158 this.deviceOwner = deviceOwner;
161 public List<NeutronSecurityGroup> getSecurityGroups() {
162 return securityGroups;
165 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
166 this.securityGroups = securityGroups;
169 public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
170 return allowedAddressPairs;
173 public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
174 this.allowedAddressPairs = allowedAddressPairs;
177 public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
178 return extraDHCPOptions;
181 public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
182 this.extraDHCPOptions = extraDHCPOptions;
185 public Map<String, String> getVIFDetails() {
189 public void setVIFDetails(Map<String, String> vifDetails) {
190 this.vifDetails = vifDetails;
193 public String getBindinghostID() {
194 return bindinghostID;
197 public void setBindinghostID(String bindinghostID) {
198 this.bindinghostID = bindinghostID;
201 public String getBindingvnicType() {
202 return bindingvnicType;
205 public void setBindingvnicType(String bindingvnicType) {
206 this.bindingvnicType = bindingvnicType;
209 public String getBindingvifType() {
210 return bindingvifType;
213 public void setBindingvifType(String bindingvifType) {
214 this.bindingvifType = bindingvifType;
217 public Boolean getPortSecurityEnabled() {
218 if (portSecurityEnabled == null) {
221 return portSecurityEnabled;
223 public String getQosPolicyId() {
227 public void setQosPolicyId(String qosPolicyId) {
228 this.qosPolicyId = qosPolicyId;
232 public void setPortSecurityEnabled(Boolean newValue) {
233 portSecurityEnabled = newValue;
237 * This method copies selected fields from the object and returns them
238 * as a new object, suitable for marshaling.
241 * List of attributes to be extracted
242 * @return an OpenStackPorts object with only the selected fields
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());
252 if ("tenant_id".equals(field)) {
253 ans.setTenantID(this.getTenantID());
255 if ("network_id".equals(field)) {
256 ans.setNetworkUUID(this.getNetworkUUID());
258 if ("name".equals(field)) {
259 ans.setName(this.getName());
261 if ("admin_state_up".equals(field)) {
262 ans.setAdminStateUp(this.getAdminStateUp());
264 if ("status".equals(field)) {
265 ans.setStatus(this.getStatus());
267 if ("mac_address".equals(field)) {
268 ans.setMacAddress(this.getMacAddress());
270 if ("fixed_ips".equals(field)) {
271 ans.setFixedIPs(new ArrayList<Neutron_IPs>(this.getFixedIPs()));
273 if ("device_id".equals(field)) {
274 ans.setDeviceID(this.getDeviceID());
276 if ("device_owner".equals(field)) {
277 ans.setDeviceOwner(this.getDeviceOwner());
279 if ("security_groups".equals(field)) {
280 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
282 if ("allowed_address_pairs".equals(field)) {
283 ans.setAllowedAddressPairs(new ArrayList<NeutronPort_AllowedAddressPairs>(this.getAllowedAddressPairs()));
285 if ("binding:host_id".equals(field)) {
286 ans.setBindinghostID(this.getBindinghostID());
288 if ("binding:vnic_type".equals(field)) {
289 ans.setBindingvnicType(this.getBindingvnicType());
291 if ("binding:vif_type".equals(field)) {
292 ans.setBindingvifType(this.getBindingvifType());
294 if ("binding:vif_details".equals(field)) {
295 ans.setVIFDetails(new HashMap<String, String>(this.getVIFDetails()));
297 if ("extra_dhcp_opts".equals(field)) {
298 ans.setExtraDHCPOptions(new ArrayList<NeutronPort_ExtraDHCPOption>(this.getExtraDHCPOptions()));
300 if ("port_security_enabled".equals(field)) {
301 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
303 if ("qos_policy_id".equals(field)) {
304 ans.setQosPolicyId(this.getQosPolicyId());
311 public void initDefaults() {
313 portSecurityEnabled = true;
314 if (status == null) {
317 if (fixedIPs == null) {
318 fixedIPs = new ArrayList<Neutron_IPs>();
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 +"]";