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;
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.HashMap;
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;
20 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
23 @XmlAccessorType(XmlAccessType.NONE)
24 public final class NeutronPort extends NeutronAdminAttributes<NeutronPort> implements Serializable {
25 private static final long serialVersionUID = 1L;
27 // See OpenStack Network API v2.0 Reference for description of
28 // annotated attributes
30 @XmlElement(name = "network_id")
33 @XmlElement(name = "mac_address")
36 @XmlElement(name = "fixed_ips")
37 List<NeutronIPs> fixedIPs;
39 @XmlElement(name = "device_id")
42 @XmlElement(name = "device_owner")
45 @XmlElement(name = "security_groups")
46 List<NeutronSecurityGroup> securityGroups;
48 @XmlElement(name = "allowed_address_pairs")
49 List<NeutronPortAllowedAddressPairs> allowedAddressPairs;
51 //@XmlElement (name = "binding:host_id")
52 @XmlElement(namespace = "binding", name = "host_id")
55 //@XmlElement (name = "binding:vnic_type")
56 @XmlElement(namespace = "binding", name = "vnic_type")
57 String bindingvnicType;
59 //@XmlElement (name = "binding:vif_type")
60 @XmlElement(namespace = "binding", name = "vif_type")
61 String bindingvifType;
63 //@XmlElement (name = "binding:vif_details")
64 @XmlElement(namespace = "binding", name = "vif_details")
65 @XmlJavaTypeAdapter(NeutronResourceMapPropertyAdapter.class)
66 Map<String, String> vifDetails;
68 @XmlElement(name = "extra_dhcp_opts")
69 List<NeutronPortExtraDHCPOption> extraDHCPOptions;
71 //Port security is enabled by default for backward compatibility.
72 @XmlElement(defaultValue = "true", name = "port_security_enabled")
73 Boolean portSecurityEnabled;
75 @XmlElement(name = "qos_policy_id")
78 public NeutronPort() {
81 public String getNetworkUUID() {
85 public void setNetworkUUID(String networkUUID) {
86 this.networkUUID = networkUUID;
89 public boolean isAdminStateUp() {
90 if (adminStateUp == null) {
96 public String getMacAddress() {
100 public void setMacAddress(String macAddress) {
101 this.macAddress = macAddress;
104 public List<NeutronIPs> getFixedIPs() {
108 public void setFixedIPs(List<NeutronIPs> fixedIPs) {
109 this.fixedIPs = fixedIPs;
112 public String getDeviceID() {
116 public void setDeviceID(String deviceID) {
117 this.deviceID = deviceID;
120 public String getDeviceOwner() {
124 public void setDeviceOwner(String deviceOwner) {
125 this.deviceOwner = deviceOwner;
128 public List<NeutronSecurityGroup> getSecurityGroups() {
129 return securityGroups;
132 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
133 this.securityGroups = securityGroups;
136 public List<NeutronPortAllowedAddressPairs> getAllowedAddressPairs() {
137 return allowedAddressPairs;
140 public void setAllowedAddressPairs(List<NeutronPortAllowedAddressPairs> allowedAddressPairs) {
141 this.allowedAddressPairs = allowedAddressPairs;
144 public List<NeutronPortExtraDHCPOption> getExtraDHCPOptions() {
145 return extraDHCPOptions;
148 public void setExtraDHCPOptions(List<NeutronPortExtraDHCPOption> extraDHCPOptions) {
149 this.extraDHCPOptions = extraDHCPOptions;
152 public Map<String, String> getVIFDetails() {
156 public void setVIFDetails(Map<String, String> vifDetails) {
157 this.vifDetails = vifDetails;
160 public String getBindinghostID() {
161 return bindinghostID;
164 public void setBindinghostID(String bindinghostID) {
165 this.bindinghostID = bindinghostID;
168 public String getBindingvnicType() {
169 return bindingvnicType;
172 public void setBindingvnicType(String bindingvnicType) {
173 this.bindingvnicType = bindingvnicType;
176 public String getBindingvifType() {
177 return bindingvifType;
180 public void setBindingvifType(String bindingvifType) {
181 this.bindingvifType = bindingvifType;
184 public Boolean getPortSecurityEnabled() {
185 if (portSecurityEnabled == null) {
188 return portSecurityEnabled;
191 public String getQosPolicyId() {
195 public void setQosPolicyId(String qosPolicyId) {
196 this.qosPolicyId = qosPolicyId;
199 public void setPortSecurityEnabled(Boolean newValue) {
200 portSecurityEnabled = newValue;
204 * This method copies selected fields from the object and returns them
205 * as a new object, suitable for marshaling.
208 * List of attributes to be extracted
209 * @return an OpenStackPorts object with only the selected fields
213 public NeutronPort extractFields(List<String> fields) {
214 NeutronPort ans = new NeutronPort();
215 for (String field : fields) {
216 extractField(field, ans);
217 if ("network_id".equals(field)) {
218 ans.setNetworkUUID(this.getNetworkUUID());
220 if ("mac_address".equals(field)) {
221 ans.setMacAddress(this.getMacAddress());
223 if ("fixed_ips".equals(field)) {
224 ans.setFixedIPs(new ArrayList<NeutronIPs>(this.getFixedIPs()));
226 if ("device_id".equals(field)) {
227 ans.setDeviceID(this.getDeviceID());
229 if ("device_owner".equals(field)) {
230 ans.setDeviceOwner(this.getDeviceOwner());
232 if ("security_groups".equals(field)) {
233 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
235 if ("allowed_address_pairs".equals(field)) {
236 ans.setAllowedAddressPairs(
237 new ArrayList<NeutronPortAllowedAddressPairs>(this.getAllowedAddressPairs()));
239 if ("binding:host_id".equals(field)) {
240 ans.setBindinghostID(this.getBindinghostID());
242 if ("binding:vnic_type".equals(field)) {
243 ans.setBindingvnicType(this.getBindingvnicType());
245 if ("binding:vif_type".equals(field)) {
246 ans.setBindingvifType(this.getBindingvifType());
248 if ("binding:vif_details".equals(field)) {
249 ans.setVIFDetails(new HashMap<String, String>(this.getVIFDetails()));
251 if ("extra_dhcp_opts".equals(field)) {
252 ans.setExtraDHCPOptions(new ArrayList<NeutronPortExtraDHCPOption>(this.getExtraDHCPOptions()));
254 if ("port_security_enabled".equals(field)) {
255 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
257 if ("qos_policy_id".equals(field)) {
258 ans.setQosPolicyId(this.getQosPolicyId());
265 public void initDefaults() {
267 portSecurityEnabled = true;
268 if (status == null) {
271 if (fixedIPs == null) {
272 fixedIPs = new ArrayList<NeutronIPs>();
277 public String toString() {
278 return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name + ", adminStateUp="
279 + adminStateUp + ", status=" + status + ", macAddress=" + macAddress + ", fixedIPs=" + fixedIPs
280 + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID=" + tenantID
281 + ", securityGroups=" + securityGroups + ", allowedAddressPairs" + allowedAddressPairs
282 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType + ", bindingvifType="
283 + bindingvifType + ", vifDetails=" + vifDetails + ", extraDHCPOptions=" + extraDHCPOptions
284 + ", portSecurityEnabled=" + portSecurityEnabled + ", qosPolicyId=" + qosPolicyId + "]";