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.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
22 @XmlAccessorType(XmlAccessType.NONE)
23 public final class NeutronPort extends NeutronAdminAttributes<NeutronPort> {
24 private static final long serialVersionUID = 1L;
26 // See OpenStack Network API v2.0 Reference for description of
27 // annotated attributes
29 @XmlElement(name = "network_id")
32 @XmlElement(name = "mac_address")
35 @XmlElement(name = "fixed_ips")
36 List<NeutronIps> fixedIps;
38 @XmlElement(name = "device_id")
41 @XmlElement(name = "device_owner")
44 @XmlElement(name = "security_groups")
45 List<NeutronSecurityGroup> securityGroups;
47 @XmlElement(name = "allowed_address_pairs")
48 List<NeutronPortAllowedAddressPairs> allowedAddressPairs;
50 //@XmlElement (name = "binding:host_id")
51 @XmlElement(namespace = "binding", name = "host_id")
54 //@XmlElement (name = "binding:vnic_type")
55 @XmlElement(namespace = "binding", name = "vnic_type")
56 String bindingvnicType;
58 //@XmlElement (name = "binding:vif_type")
59 @XmlElement(namespace = "binding", name = "vif_type")
60 String bindingvifType;
62 //@XmlElement (name = "binding:profile")
63 @XmlElement(namespace = "binding", name = "profile")
64 String bindingProfile;
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 String getMacAddress() {
96 public void setMacAddress(String macAddress) {
97 this.macAddress = macAddress;
100 public List<NeutronIps> getFixedIps() {
104 public void setFixedIps(List<NeutronIps> fixedIps) {
105 this.fixedIps = fixedIps;
108 public String getDeviceID() {
112 public void setDeviceID(String deviceID) {
113 this.deviceID = deviceID;
116 public String getDeviceOwner() {
120 public void setDeviceOwner(String deviceOwner) {
121 this.deviceOwner = deviceOwner;
124 public List<NeutronSecurityGroup> getSecurityGroups() {
125 return securityGroups;
128 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
129 this.securityGroups = securityGroups;
132 public List<NeutronPortAllowedAddressPairs> getAllowedAddressPairs() {
133 return allowedAddressPairs;
136 public void setAllowedAddressPairs(List<NeutronPortAllowedAddressPairs> allowedAddressPairs) {
137 this.allowedAddressPairs = allowedAddressPairs;
140 public List<NeutronPortExtraDHCPOption> getExtraDHCPOptions() {
141 return extraDHCPOptions;
144 public void setExtraDHCPOptions(List<NeutronPortExtraDHCPOption> extraDHCPOptions) {
145 this.extraDHCPOptions = extraDHCPOptions;
148 public Map<String, String> getVIFDetails() {
152 public void setVIFDetails(Map<String, String> details) {
153 this.vifDetails = details;
156 public String getBindinghostID() {
157 return bindinghostID;
160 public void setBindinghostID(String bindinghostID) {
161 this.bindinghostID = bindinghostID;
164 public String getProfile() {
165 return bindingProfile;
168 public void setProfile(String newBindingProfile) {
169 this.bindingProfile = newBindingProfile;
172 public String getBindingvnicType() {
173 return bindingvnicType;
176 public void setBindingvnicType(String bindingvnicType) {
177 this.bindingvnicType = bindingvnicType;
180 public String getBindingvifType() {
181 return bindingvifType;
184 public void setBindingvifType(String bindingvifType) {
185 this.bindingvifType = bindingvifType;
188 public Boolean getPortSecurityEnabled() {
189 if (portSecurityEnabled == null) {
192 return portSecurityEnabled;
195 public String getQosPolicyId() {
199 public void setQosPolicyId(String qosPolicyId) {
200 this.qosPolicyId = qosPolicyId;
203 public void setPortSecurityEnabled(Boolean newValue) {
204 portSecurityEnabled = newValue;
208 protected boolean extractField(String field, NeutronPort ans) {
211 ans.setNetworkUUID(this.getNetworkUUID());
214 ans.setMacAddress(this.getMacAddress());
217 ans.setFixedIps(new ArrayList<>(this.getFixedIps()));
220 ans.setDeviceID(this.getDeviceID());
223 ans.setDeviceOwner(this.getDeviceOwner());
225 case "security_groups":
226 ans.setSecurityGroups(new ArrayList<>(this.getSecurityGroups()));
228 case "allowed_address_pairs":
229 ans.setAllowedAddressPairs(
230 new ArrayList<>(this.getAllowedAddressPairs()));
232 case "binding:host_id":
233 ans.setBindinghostID(this.getBindinghostID());
235 case "binding:vnic_type":
236 ans.setBindingvnicType(this.getBindingvnicType());
238 case "binding:vif_type":
239 ans.setBindingvifType(this.getBindingvifType());
241 case "binding:profile":
242 ans.setProfile(this.getProfile());
244 case "binding:vif_details":
245 ans.setVIFDetails(new HashMap<>(this.getVIFDetails()));
247 case "extra_dhcp_opts":
248 ans.setExtraDHCPOptions(new ArrayList<>(this.getExtraDHCPOptions()));
250 case "port_security_enabled":
251 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
253 case "qos_policy_id":
254 ans.setQosPolicyId(this.getQosPolicyId());
257 return super.extractField(field, ans);
263 public void initDefaults() {
264 super.initDefaults();
265 if (portSecurityEnabled == null) {
266 portSecurityEnabled = true;
268 if (fixedIps == null) {
269 fixedIps = new ArrayList<>();
274 public String toString() {
275 return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name + ", adminStateUp="
276 + adminStateUp + ", status=" + status + ", macAddress=" + macAddress + ", fixedIps=" + fixedIps
277 + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID=" + tenantID
278 + ", securityGroups=" + securityGroups + ", allowedAddressPairs" + allowedAddressPairs
279 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType + ", bindingvifType="
280 + bindingvifType + ", vifDetails=" + vifDetails + ", bindingProfile=" + bindingProfile
281 + ", extraDHCPOptions=" + extraDHCPOptions
282 + ", portSecurityEnabled=" + portSecurityEnabled + ", qosPolicyId=" + qosPolicyId + "]";