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 protected boolean extractField(String field, NeutronPort ans) {
207 ans.setNetworkUUID(this.getNetworkUUID());
210 ans.setMacAddress(this.getMacAddress());
213 ans.setFixedIps(new ArrayList<NeutronIps>(this.getFixedIps()));
216 ans.setDeviceID(this.getDeviceID());
219 ans.setDeviceOwner(this.getDeviceOwner());
221 case "security_groups":
222 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
224 case "allowed_address_pairs":
225 ans.setAllowedAddressPairs(
226 new ArrayList<NeutronPortAllowedAddressPairs>(this.getAllowedAddressPairs()));
228 case "binding:host_id":
229 ans.setBindinghostID(this.getBindinghostID());
231 case "binding:vnic_type":
232 ans.setBindingvnicType(this.getBindingvnicType());
234 case "binding:vif_type":
235 ans.setBindingvifType(this.getBindingvifType());
237 case "binding:vif_details":
238 ans.setVIFDetails(new HashMap<String, String>(this.getVIFDetails()));
240 case "extra_dhcp_opts":
241 ans.setExtraDHCPOptions(new ArrayList<NeutronPortExtraDHCPOption>(this.getExtraDHCPOptions()));
243 case "port_security_enabled":
244 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
246 case "qos_policy_id":
247 ans.setQosPolicyId(this.getQosPolicyId());
250 return super.extractField(field, ans);
256 public void initDefaults() {
257 super.initDefaults();
258 if (portSecurityEnabled == null) {
259 portSecurityEnabled = true;
261 if (fixedIps == null) {
262 fixedIps = new ArrayList<NeutronIps>();
267 public String toString() {
268 return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name + ", adminStateUp="
269 + adminStateUp + ", status=" + status + ", macAddress=" + macAddress + ", fixedIps=" + fixedIps
270 + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID=" + tenantID
271 + ", securityGroups=" + securityGroups + ", allowedAddressPairs" + allowedAddressPairs
272 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType + ", bindingvifType="
273 + bindingvifType + ", vifDetails=" + vifDetails + ", extraDHCPOptions=" + extraDHCPOptions
274 + ", portSecurityEnabled=" + portSecurityEnabled + ", qosPolicyId=" + qosPolicyId + "]";