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.List;
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;
23 @XmlAccessorType(XmlAccessType.NONE)
25 public class NeutronPort extends NeutronObject implements Serializable, INeutronObject {
26 private static final long serialVersionUID = 1L;
28 // See OpenStack Network API v2.0 Reference for description of
29 // annotated attributes
31 @XmlElement (name = "network_id")
34 @XmlElement (name = "name")
37 @XmlElement (defaultValue = "true", name = "admin_state_up")
40 @XmlElement (name = "status")
43 @XmlElement (name = "mac_address")
46 @XmlElement (name = "fixed_ips")
47 List<Neutron_IPs> fixedIPs;
49 @XmlElement (name = "device_id")
52 @XmlElement (name = "device_owner")
55 @XmlElement (name = "security_groups")
56 List<NeutronSecurityGroup> securityGroups;
58 @XmlElement (name = "allowed_address_pairs")
59 List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
61 //@XmlElement (name = "binding:host_id")
62 @XmlElement (namespace = "binding", name = "host_id")
65 //@XmlElement (name = "binding:vnic_type")
66 @XmlElement (namespace = "binding", name = "vnic_type")
67 String bindingvnicType;
69 //@XmlElement (name = "binding:vif_type")
70 @XmlElement (namespace = "binding", name = "vif_type")
71 String bindingvifType;
73 //@XmlElement (name = "binding:vif_details")
74 @XmlElement (namespace = "binding", name = "vif_details")
75 List<NeutronPort_VIFDetail> vifDetails;
77 @XmlElement (name = "extra_dhcp_opts")
78 List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
80 //Port security is enabled by default for backward compatibility.
81 @XmlElement (defaultValue = "true", name = "port_security_enabled")
82 Boolean portSecurityEnabled;
84 public NeutronPort() {
88 public String getPortUUID() {
93 public void setPortUUID(String uuid) {
97 public String getNetworkUUID() {
101 public void setNetworkUUID(String networkUUID) {
102 this.networkUUID = networkUUID;
105 public String getName() {
109 public void setName(String name) {
113 public boolean isAdminStateUp() {
114 if (adminStateUp == null) {
120 public Boolean getAdminStateUp() { return adminStateUp; }
122 public void setAdminStateUp(Boolean newValue) {
123 adminStateUp = newValue;
126 public String getStatus() {
130 public void setStatus(String status) {
131 this.status = status;
134 public String getMacAddress() {
138 public void setMacAddress(String macAddress) {
139 this.macAddress = macAddress;
142 public List<Neutron_IPs> getFixedIPs() {
146 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
147 this.fixedIPs = fixedIPs;
150 public String getDeviceID() {
154 public void setDeviceID(String deviceID) {
155 this.deviceID = deviceID;
158 public String getDeviceOwner() {
162 public void setDeviceOwner(String deviceOwner) {
163 this.deviceOwner = deviceOwner;
166 public List<NeutronSecurityGroup> getSecurityGroups() {
167 return securityGroups;
170 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
171 this.securityGroups = securityGroups;
174 public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
175 return allowedAddressPairs;
178 public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
179 this.allowedAddressPairs = allowedAddressPairs;
182 public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
183 return extraDHCPOptions;
186 public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
187 this.extraDHCPOptions = extraDHCPOptions;
190 public List<NeutronPort_VIFDetail> getVIFDetail() {
194 public void setVIFDetail(List<NeutronPort_VIFDetail> vifDetails) {
195 this.vifDetails = vifDetails;
198 public String getBindinghostID() {
199 return bindinghostID;
202 public void setBindinghostID(String bindinghostID) {
203 this.bindinghostID = bindinghostID;
206 public String getBindingvnicType() {
207 return bindingvnicType;
210 public void setBindingvnicType(String bindingvnicType) {
211 this.bindingvnicType = bindingvnicType;
214 public String getBindingvifType() {
215 return bindingvifType;
218 public void setBindingvifType(String bindingvifType) {
219 this.bindingvifType = bindingvifType;
222 public Boolean getPortSecurityEnabled() {
223 if (portSecurityEnabled == null) {
226 return portSecurityEnabled;
229 public void setPortSecurityEnabled(Boolean newValue) {
230 portSecurityEnabled = newValue;
234 * This method copies selected fields from the object and returns them
235 * as a new object, suitable for marshaling.
238 * List of attributes to be extracted
239 * @return an OpenStackPorts object with only the selected fields
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());
249 if ("network_id".equals(field)) {
250 ans.setNetworkUUID(this.getNetworkUUID());
252 if ("name".equals(field)) {
253 ans.setName(this.getName());
255 if ("admin_state_up".equals(field)) {
256 ans.setAdminStateUp(this.getAdminStateUp());
258 if ("status".equals(field)) {
259 ans.setStatus(this.getStatus());
261 if ("mac_address".equals(field)) {
262 ans.setMacAddress(this.getMacAddress());
264 if ("fixed_ips".equals(field)) {
265 ans.setFixedIPs(new ArrayList<Neutron_IPs>(this.getFixedIPs()));
267 if ("device_id".equals(field)) {
268 ans.setDeviceID(this.getDeviceID());
270 if ("device_owner".equals(field)) {
271 ans.setDeviceOwner(this.getDeviceOwner());
273 if ("tenant_id".equals(field)) {
274 ans.setTenantID(this.getTenantID());
276 if ("security_groups".equals(field)) {
277 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
279 if ("port_security_enabled".equals(field)) {
280 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
287 public void initDefaults() {
289 portSecurityEnabled = true;
290 if (status == null) {
293 if (fixedIPs == null) {
294 fixedIPs = new ArrayList<Neutron_IPs>();
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 +"]";