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;
18 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
19 import javax.xml.bind.annotation.XmlAccessType;
20 import javax.xml.bind.annotation.XmlAccessorType;
21 import javax.xml.bind.annotation.XmlElement;
22 import javax.xml.bind.annotation.XmlRootElement;
26 @XmlAccessorType(XmlAccessType.NONE)
27 public class NeutronPort extends NeutronObject implements Serializable, INeutronObject {
28 private static final long serialVersionUID = 1L;
30 // See OpenStack Network API v2.0 Reference for description of
31 // annotated attributes
33 @XmlElement (name = "network_id")
36 @XmlElement (name = "name")
39 @XmlElement (defaultValue = "true", name = "admin_state_up")
42 @XmlElement (name = "status")
45 @XmlElement (name = "mac_address")
48 @XmlElement (name = "fixed_ips")
49 List<Neutron_IPs> fixedIPs;
51 @XmlElement (name = "device_id")
54 @XmlElement (name = "device_owner")
57 @XmlElement (name = "security_groups")
58 List<NeutronSecurityGroup> securityGroups;
60 @XmlElement (name = "allowed_address_pairs")
61 List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
63 //@XmlElement (name = "binding:host_id")
64 @XmlElement (namespace = "binding", name = "host_id")
67 //@XmlElement (name = "binding:vnic_type")
68 @XmlElement (namespace = "binding", name = "vnic_type")
69 String bindingvnicType;
71 //@XmlElement (name = "binding:vif_type")
72 @XmlElement (namespace = "binding", name = "vif_type")
73 String bindingvifType;
75 //@XmlElement (name = "binding:vif_details")
76 @XmlElement (namespace = "binding", name = "vif_details")
77 @XmlJavaTypeAdapter(NeutronResourceMapPropertyAdapter.class)
78 Map<String, String> vifDetails;
80 @XmlElement (name = "extra_dhcp_opts")
81 List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
83 //Port security is enabled by default for backward compatibility.
84 @XmlElement (defaultValue = "true", name = "port_security_enabled")
85 Boolean portSecurityEnabled;
87 public NeutronPort() {
90 public String getNetworkUUID() {
94 public void setNetworkUUID(String networkUUID) {
95 this.networkUUID = networkUUID;
98 public String getName() {
102 public void setName(String name) {
106 public boolean isAdminStateUp() {
107 if (adminStateUp == null) {
113 public Boolean getAdminStateUp() { return adminStateUp; }
115 public void setAdminStateUp(Boolean newValue) {
116 adminStateUp = newValue;
119 public String getStatus() {
123 public void setStatus(String status) {
124 this.status = status;
127 public String getMacAddress() {
131 public void setMacAddress(String macAddress) {
132 this.macAddress = macAddress;
135 public List<Neutron_IPs> getFixedIPs() {
139 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
140 this.fixedIPs = fixedIPs;
143 public String getDeviceID() {
147 public void setDeviceID(String deviceID) {
148 this.deviceID = deviceID;
151 public String getDeviceOwner() {
155 public void setDeviceOwner(String deviceOwner) {
156 this.deviceOwner = deviceOwner;
159 public List<NeutronSecurityGroup> getSecurityGroups() {
160 return securityGroups;
163 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
164 this.securityGroups = securityGroups;
167 public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
168 return allowedAddressPairs;
171 public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
172 this.allowedAddressPairs = allowedAddressPairs;
175 public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
176 return extraDHCPOptions;
179 public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
180 this.extraDHCPOptions = extraDHCPOptions;
183 public Map<String, String> getVIFDetails() {
187 public void setVIFDetails(Map<String, String> vifDetails) {
188 this.vifDetails = vifDetails;
191 public String getBindinghostID() {
192 return bindinghostID;
195 public void setBindinghostID(String bindinghostID) {
196 this.bindinghostID = bindinghostID;
199 public String getBindingvnicType() {
200 return bindingvnicType;
203 public void setBindingvnicType(String bindingvnicType) {
204 this.bindingvnicType = bindingvnicType;
207 public String getBindingvifType() {
208 return bindingvifType;
211 public void setBindingvifType(String bindingvifType) {
212 this.bindingvifType = bindingvifType;
215 public Boolean getPortSecurityEnabled() {
216 if (portSecurityEnabled == null) {
219 return portSecurityEnabled;
222 public void setPortSecurityEnabled(Boolean newValue) {
223 portSecurityEnabled = newValue;
227 * This method copies selected fields from the object and returns them
228 * as a new object, suitable for marshaling.
231 * List of attributes to be extracted
232 * @return an OpenStackPorts object with only the selected fields
236 public NeutronPort extractFields(List<String> fields) {
237 NeutronPort ans = new NeutronPort();
238 for (String field: fields) {
239 if ("id".equals(field)) {
240 ans.setID(this.getID());
242 if ("tenant_id".equals(field)) {
243 ans.setTenantID(this.getTenantID());
245 if ("network_id".equals(field)) {
246 ans.setNetworkUUID(this.getNetworkUUID());
248 if ("name".equals(field)) {
249 ans.setName(this.getName());
251 if ("admin_state_up".equals(field)) {
252 ans.setAdminStateUp(this.getAdminStateUp());
254 if ("status".equals(field)) {
255 ans.setStatus(this.getStatus());
257 if ("mac_address".equals(field)) {
258 ans.setMacAddress(this.getMacAddress());
260 if ("fixed_ips".equals(field)) {
261 ans.setFixedIPs(new ArrayList<Neutron_IPs>(this.getFixedIPs()));
263 if ("device_id".equals(field)) {
264 ans.setDeviceID(this.getDeviceID());
266 if ("device_owner".equals(field)) {
267 ans.setDeviceOwner(this.getDeviceOwner());
269 if ("security_groups".equals(field)) {
270 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
272 if ("allowed_address_pairs".equals(field)) {
273 ans.setAllowedAddressPairs(new ArrayList<NeutronPort_AllowedAddressPairs>(this.getAllowedAddressPairs()));
275 if ("binding:host_id".equals(field)) {
276 ans.setBindinghostID(this.getBindinghostID());
278 if ("binding:vnic_type".equals(field)) {
279 ans.setBindingvnicType(this.getBindingvnicType());
281 if ("binding:vif_type".equals(field)) {
282 ans.setBindingvifType(this.getBindingvifType());
284 if ("binding:vif_details".equals(field)) {
285 ans.setVIFDetails(new HashMap<String, String>(this.getVIFDetails()));
287 if ("extra_dhcp_opts".equals(field)) {
288 ans.setExtraDHCPOptions(new ArrayList<NeutronPort_ExtraDHCPOption>(this.getExtraDHCPOptions()));
290 if ("port_security_enabled".equals(field)) {
291 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
298 public void initDefaults() {
300 portSecurityEnabled = true;
301 if (status == null) {
304 if (fixedIPs == null) {
305 fixedIPs = new ArrayList<Neutron_IPs>();
310 public String toString() {
311 return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name
312 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
313 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
314 + tenantID + ", securityGroups=" + securityGroups
315 + ", allowedAddressPairs" + allowedAddressPairs
316 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
317 + ", bindingvifType=" + bindingvifType
318 + ", vifDetails=" + vifDetails
319 + ", extraDHCPOptions=" + extraDHCPOptions
320 + ", portSecurityEnabled=" + portSecurityEnabled +"]";