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.netvirt.openstack.netvirt.translator;
12 import java.io.Serializable;
13 import java.util.ArrayList;
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;
23 @XmlAccessorType(XmlAccessType.NONE)
25 public class NeutronPort implements Serializable, INeutronObject {
26 private static final long serialVersionUID = 1L;
28 // See OpenStack Network API v2.0 Reference for description of
29 // annotated attributes
31 @XmlElement (name = "id")
34 @XmlElement (name = "network_id")
37 @XmlElement (name = "name")
40 @XmlElement (defaultValue = "true", name = "admin_state_up")
43 @XmlElement (name = "status")
46 @XmlElement (name = "mac_address")
49 @XmlElement (name = "fixed_ips")
50 List<Neutron_IPs> fixedIPs;
52 @XmlElement (name = "device_id")
55 @XmlElement (name = "device_owner")
58 @XmlElement (name = "tenant_id")
61 @XmlElement (name = "security_groups")
62 List<NeutronSecurityGroup> securityGroups;
64 @XmlElement (name = "allowed_address_pairs")
65 List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
67 //@XmlElement (name = "binding:host_id")
68 @XmlElement (namespace = "binding", name = "host_id")
71 //@XmlElement (name = "binding:vnic_type")
72 @XmlElement (namespace = "binding", name = "vnic_type")
73 String bindingvnicType;
75 //@XmlElement (name = "binding:vif_type")
76 @XmlElement (namespace = "binding", name = "vif_type")
77 String bindingvifType;
79 //@XmlElement (name = "binding:vif_details")
80 @XmlElement (namespace = "binding", name = "vif_details")
81 List<NeutronPort_VIFDetail> vifDetails;
83 @XmlElement (name = "extra_dhcp_opts")
84 List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
86 //Port security is enabled by default for backward compatibility.
87 @XmlElement (defaultValue = "true", name = "port_security_enabled")
88 Boolean portSecurityEnabled;
91 NeutronPort originalPort;
93 public NeutronPort() {
96 public String getID() { return portUUID; }
98 public void setID(String id) { this.portUUID = id; }
100 public String getPortUUID() {
104 public void setPortUUID(String portUUID) {
105 this.portUUID = portUUID;
108 public String getNetworkUUID() {
112 public void setNetworkUUID(String networkUUID) {
113 this.networkUUID = networkUUID;
116 public String getName() {
120 public void setName(String name) {
124 public boolean isAdminStateUp() {
125 if (adminStateUp == null) {
131 public Boolean getAdminStateUp() { return adminStateUp; }
133 public void setAdminStateUp(Boolean newValue) {
134 adminStateUp = newValue;
137 public String getStatus() {
141 public void setStatus(String status) {
142 this.status = status;
145 public String getMacAddress() {
149 public void setMacAddress(String macAddress) {
150 this.macAddress = macAddress;
153 public List<Neutron_IPs> getFixedIPs() {
157 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
158 this.fixedIPs = fixedIPs;
161 public String getDeviceID() {
165 public void setDeviceID(String deviceID) {
166 this.deviceID = deviceID;
169 public String getDeviceOwner() {
173 public void setDeviceOwner(String deviceOwner) {
174 this.deviceOwner = deviceOwner;
177 public String getTenantID() {
181 public void setTenantID(String tenantID) {
182 this.tenantID = tenantID;
185 public List<NeutronSecurityGroup> getSecurityGroups() {
186 return securityGroups;
189 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
190 this.securityGroups = securityGroups;
193 public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
194 return allowedAddressPairs;
197 public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
198 this.allowedAddressPairs = allowedAddressPairs;
201 public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
202 return extraDHCPOptions;
205 public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
206 this.extraDHCPOptions = extraDHCPOptions;
209 public List<NeutronPort_VIFDetail> getVIFDetail() {
213 public void setVIFDetail(List<NeutronPort_VIFDetail> vifDetails) {
214 this.vifDetails = vifDetails;
217 public String getBindinghostID() {
218 return bindinghostID;
221 public void setBindinghostID(String bindinghostID) {
222 this.bindinghostID = bindinghostID;
225 public String getBindingvnicType() {
226 return bindingvnicType;
229 public void setBindingvnicType(String bindingvnicType) {
230 this.bindingvnicType = bindingvnicType;
233 public String getBindingvifType() {
234 return bindingvifType;
237 public void setBindingvifType(String bindingvifType) {
238 this.bindingvifType = bindingvifType;
241 public Boolean getPortSecurityEnabled() {
242 if (portSecurityEnabled == null) {
245 return portSecurityEnabled;
248 public void setPortSecurityEnabled(Boolean newValue) {
249 portSecurityEnabled = newValue;
253 public NeutronPort getOriginalPort() {
258 public void setOriginalPort(NeutronPort originalPort) {
259 this.originalPort = originalPort;
263 * This method copies selected fields from the object and returns them
264 * as a new object, suitable for marshaling.
267 * List of attributes to be extracted
268 * @return an OpenStackPorts object with only the selected fields
272 public NeutronPort extractFields(List<String> fields) {
273 NeutronPort ans = new NeutronPort();
274 for (String field: fields) {
275 if ("id".equals(field)) {
276 ans.setPortUUID(this.getPortUUID());
278 if ("network_id".equals(field)) {
279 ans.setNetworkUUID(this.getNetworkUUID());
281 if ("name".equals(field)) {
282 ans.setName(this.getName());
284 if ("admin_state_up".equals(field)) {
285 ans.setAdminStateUp(this.getAdminStateUp());
287 if ("status".equals(field)) {
288 ans.setStatus(this.getStatus());
290 if ("mac_address".equals(field)) {
291 ans.setMacAddress(this.getMacAddress());
293 if ("fixed_ips".equals(field)) {
294 ans.setFixedIPs(new ArrayList<>(this.getFixedIPs()));
296 if ("device_id".equals(field)) {
297 ans.setDeviceID(this.getDeviceID());
299 if ("device_owner".equals(field)) {
300 ans.setDeviceOwner(this.getDeviceOwner());
302 if ("tenant_id".equals(field)) {
303 ans.setTenantID(this.getTenantID());
305 if ("security_groups".equals(field)) {
306 ans.setSecurityGroups(new ArrayList<>(this.getSecurityGroups()));
308 if ("port_security_enabled".equals(field)) {
309 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
315 public void initDefaults() {
317 portSecurityEnabled = true;
318 if (status == null) {
321 if (fixedIPs == null) {
322 fixedIPs = new ArrayList<>();
327 public String toString() {
328 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
329 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
330 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
331 + tenantID + ", securityGroups=" + securityGroups
332 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
333 + ", bindingvnicType=" + bindingvnicType + ", portSecurityEnabled=" + portSecurityEnabled +"]";