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;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 @XmlAccessorType(XmlAccessType.NONE)
26 public final class NeutronPort extends NeutronAdminAttributes<NeutronPort> implements Serializable {
27 private static final Logger LOGGER = LoggerFactory.getLogger(NeutronPort.class);
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 = "mac_address")
39 @XmlElement(name = "fixed_ips")
40 List<NeutronIps> fixedIps;
42 @XmlElement(name = "device_id")
45 @XmlElement(name = "device_owner")
48 @XmlElement(name = "security_groups")
49 List<NeutronSecurityGroup> securityGroups;
51 @XmlElement(name = "allowed_address_pairs")
52 List<NeutronPortAllowedAddressPairs> allowedAddressPairs;
54 //@XmlElement (name = "binding:host_id")
55 @XmlElement(namespace = "binding", name = "host_id")
58 //@XmlElement (name = "binding:vnic_type")
59 @XmlElement(namespace = "binding", name = "vnic_type")
60 String bindingvnicType;
62 //@XmlElement (name = "binding:vif_type")
63 @XmlElement(namespace = "binding", name = "vif_type")
64 String bindingvifType;
66 //@XmlElement (name = "binding:vif_details")
67 @XmlElement(namespace = "binding", name = "vif_details")
68 @XmlJavaTypeAdapter(NeutronResourceMapPropertyAdapter.class)
69 Map<String, String> vifDetails;
71 @XmlElement(name = "extra_dhcp_opts")
72 List<NeutronPortExtraDHCPOption> extraDHCPOptions;
74 //Port security is enabled by default for backward compatibility.
75 @XmlElement(defaultValue = "true", name = "port_security_enabled")
76 Boolean portSecurityEnabled;
78 @XmlElement(name = "qos_policy_id")
81 public NeutronPort() {
84 public String getNetworkUUID() {
88 public void setNetworkUUID(String networkUUID) {
89 this.networkUUID = networkUUID;
92 public boolean isAdminStateUp() {
93 if (adminStateUp == null) {
99 public String getMacAddress() {
103 public void setMacAddress(String macAddress) {
104 this.macAddress = macAddress;
107 public List<NeutronIps> getFixedIps() {
111 public void setFixedIps(List<NeutronIps> fixedIps) {
112 this.fixedIps = fixedIps;
115 public String getDeviceID() {
119 public void setDeviceID(String deviceID) {
120 this.deviceID = deviceID;
123 public String getDeviceOwner() {
127 public void setDeviceOwner(String deviceOwner) {
128 this.deviceOwner = deviceOwner;
131 public List<NeutronSecurityGroup> getSecurityGroups() {
132 return securityGroups;
135 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
136 this.securityGroups = securityGroups;
139 public List<NeutronPortAllowedAddressPairs> getAllowedAddressPairs() {
140 return allowedAddressPairs;
143 public void setAllowedAddressPairs(List<NeutronPortAllowedAddressPairs> allowedAddressPairs) {
144 this.allowedAddressPairs = allowedAddressPairs;
147 public List<NeutronPortExtraDHCPOption> getExtraDHCPOptions() {
148 return extraDHCPOptions;
151 public void setExtraDHCPOptions(List<NeutronPortExtraDHCPOption> extraDHCPOptions) {
152 this.extraDHCPOptions = extraDHCPOptions;
155 public Map<String, String> getVIFDetails() {
159 public void setVIFDetails(Map<String, String> vifDetails) {
160 this.vifDetails = vifDetails;
163 public String getBindinghostID() {
164 return bindinghostID;
167 public void setBindinghostID(String bindinghostID) {
168 this.bindinghostID = bindinghostID;
171 public String getBindingvnicType() {
172 return bindingvnicType;
175 public void setBindingvnicType(String bindingvnicType) {
176 this.bindingvnicType = bindingvnicType;
179 public String getBindingvifType() {
180 return bindingvifType;
183 public void setBindingvifType(String bindingvifType) {
184 this.bindingvifType = bindingvifType;
187 public Boolean getPortSecurityEnabled() {
188 if (portSecurityEnabled == null) {
191 return portSecurityEnabled;
194 public String getQosPolicyId() {
198 public void setQosPolicyId(String qosPolicyId) {
199 this.qosPolicyId = qosPolicyId;
202 public void setPortSecurityEnabled(Boolean newValue) {
203 portSecurityEnabled = newValue;
207 * This method copies selected fields from the object and returns them
208 * as a new object, suitable for marshaling.
211 * List of attributes to be extracted
212 * @return an OpenStackPorts object with only the selected fields
216 public NeutronPort extractFields(List<String> fields) {
217 NeutronPort ans = new NeutronPort();
218 for (String s : fields) {
219 if (extractField(s, ans)) {
224 ans.setNetworkUUID(this.getNetworkUUID());
227 ans.setMacAddress(this.getMacAddress());
230 ans.setFixedIps(new ArrayList<NeutronIps>(this.getFixedIps()));
233 ans.setDeviceID(this.getDeviceID());
236 ans.setDeviceOwner(this.getDeviceOwner());
238 case "security_groups":
239 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
241 case "allowed_address_pairs":
242 ans.setAllowedAddressPairs(
243 new ArrayList<NeutronPortAllowedAddressPairs>(this.getAllowedAddressPairs()));
245 case "binding:host_id":
246 ans.setBindinghostID(this.getBindinghostID());
248 case "binding:vnic_type":
249 ans.setBindingvnicType(this.getBindingvnicType());
251 case "binding:vif_type":
252 ans.setBindingvifType(this.getBindingvifType());
254 case "binding:vif_details":
255 ans.setVIFDetails(new HashMap<String, String>(this.getVIFDetails()));
257 case "extra_dhcp_opts":
258 ans.setExtraDHCPOptions(new ArrayList<NeutronPortExtraDHCPOption>(this.getExtraDHCPOptions()));
260 case "port_security_enabled":
261 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
263 case "qos_policy_id":
264 ans.setQosPolicyId(this.getQosPolicyId());
267 LOGGER.warn("{} is not a NeutronPort suitable field.", s);
275 public void initDefaults() {
276 super.initDefaults();
277 if (portSecurityEnabled == null) {
278 portSecurityEnabled = true;
280 if (fixedIps == null) {
281 fixedIps = new ArrayList<NeutronIps>();
286 public String toString() {
287 return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name + ", adminStateUp="
288 + adminStateUp + ", status=" + status + ", macAddress=" + macAddress + ", fixedIps=" + fixedIps
289 + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID=" + tenantID
290 + ", securityGroups=" + securityGroups + ", allowedAddressPairs" + allowedAddressPairs
291 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType + ", bindingvifType="
292 + bindingvifType + ", vifDetails=" + vifDetails + ", extraDHCPOptions=" + extraDHCPOptions
293 + ", portSecurityEnabled=" + portSecurityEnabled + ", qosPolicyId=" + qosPolicyId + "]";