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;
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlElement;
20 import javax.xml.bind.annotation.XmlRootElement;
24 @XmlAccessorType(XmlAccessType.NONE)
26 public class NeutronPort implements Serializable, INeutronObject {
27 private static final long serialVersionUID = 1L;
29 // See OpenStack Network API v2.0 Reference for description of
30 // annotated attributes
32 @XmlElement (name = "id")
35 @XmlElement (name = "network_id")
38 @XmlElement (name = "name")
41 @XmlElement (defaultValue = "true", name = "admin_state_up")
44 @XmlElement (name = "status")
47 @XmlElement (name = "mac_address")
50 @XmlElement (name = "fixed_ips")
51 List<Neutron_IPs> fixedIPs;
53 @XmlElement (name = "device_id")
56 @XmlElement (name = "device_owner")
59 @XmlElement (name = "tenant_id")
62 @XmlElement (name = "security_groups")
63 List<NeutronSecurityGroup> securityGroups;
65 @XmlElement (name = "allowed_address_pairs")
66 List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
68 //@XmlElement (name = "binding:host_id")
69 @XmlElement (namespace = "binding", name = "host_id")
72 //@XmlElement (name = "binding:vnic_type")
73 @XmlElement (namespace = "binding", name = "vnic_type")
74 String bindingvnicType;
76 //@XmlElement (name = "binding:vif_type")
77 @XmlElement (namespace = "binding", name = "vif_type")
78 String bindingvifType;
80 //@XmlElement (name = "binding:vif_details")
81 @XmlElement (namespace = "binding", name = "vif_details")
82 Map<String, String> vifDetails;
84 @XmlElement (name = "extra_dhcp_opts")
85 List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
87 //Port security is enabled by default for backward compatibility.
88 @XmlElement (defaultValue = "true", name = "port_security_enabled")
89 Boolean portSecurityEnabled;
92 NeutronPort originalPort;
94 public NeutronPort() {
97 public String getID() { return portUUID; }
99 public void setID(String id) { this.portUUID = id; }
101 public String getPortUUID() {
105 public void setPortUUID(String portUUID) {
106 this.portUUID = portUUID;
109 public String getNetworkUUID() {
113 public void setNetworkUUID(String networkUUID) {
114 this.networkUUID = networkUUID;
117 public String getName() {
121 public void setName(String name) {
125 public boolean isAdminStateUp() {
126 if (adminStateUp == null) {
132 public Boolean getAdminStateUp() { return adminStateUp; }
134 public void setAdminStateUp(Boolean newValue) {
135 adminStateUp = newValue;
138 public String getStatus() {
142 public void setStatus(String status) {
143 this.status = status;
146 public String getMacAddress() {
150 public void setMacAddress(String macAddress) {
151 this.macAddress = macAddress;
154 public List<Neutron_IPs> getFixedIPs() {
158 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
159 this.fixedIPs = fixedIPs;
162 public String getDeviceID() {
166 public void setDeviceID(String deviceID) {
167 this.deviceID = deviceID;
170 public String getDeviceOwner() {
174 public void setDeviceOwner(String deviceOwner) {
175 this.deviceOwner = deviceOwner;
178 public String getTenantID() {
182 public void setTenantID(String tenantID) {
183 this.tenantID = tenantID;
186 public List<NeutronSecurityGroup> getSecurityGroups() {
187 return securityGroups;
190 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
191 this.securityGroups = securityGroups;
194 public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
195 return allowedAddressPairs;
198 public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
199 this.allowedAddressPairs = allowedAddressPairs;
202 public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
203 return extraDHCPOptions;
206 public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
207 this.extraDHCPOptions = extraDHCPOptions;
210 public Map<String, String> getVIFDetails() {
214 public void setVIFDetails(Map<String, String> vifDetails) {
215 this.vifDetails = vifDetails;
218 public String getBindinghostID() {
219 return bindinghostID;
222 public void setBindinghostID(String bindinghostID) {
223 this.bindinghostID = bindinghostID;
226 public String getBindingvnicType() {
227 return bindingvnicType;
230 public void setBindingvnicType(String bindingvnicType) {
231 this.bindingvnicType = bindingvnicType;
234 public String getBindingvifType() {
235 return bindingvifType;
238 public void setBindingvifType(String bindingvifType) {
239 this.bindingvifType = bindingvifType;
242 public Boolean getPortSecurityEnabled() {
243 if (portSecurityEnabled == null) {
246 return portSecurityEnabled;
249 public void setPortSecurityEnabled(Boolean newValue) {
250 portSecurityEnabled = newValue;
254 public NeutronPort getOriginalPort() {
259 public void setOriginalPort(NeutronPort originalPort) {
260 this.originalPort = originalPort;
264 * This method copies selected fields from the object and returns them
265 * as a new object, suitable for marshaling.
268 * List of attributes to be extracted
269 * @return an OpenStackPorts object with only the selected fields
273 public NeutronPort extractFields(List<String> fields) {
274 NeutronPort ans = new NeutronPort();
275 for (String field: fields) {
276 if ("id".equals(field)) {
277 ans.setPortUUID(this.getPortUUID());
279 if ("network_id".equals(field)) {
280 ans.setNetworkUUID(this.getNetworkUUID());
282 if ("name".equals(field)) {
283 ans.setName(this.getName());
285 if ("admin_state_up".equals(field)) {
286 ans.setAdminStateUp(this.getAdminStateUp());
288 if ("status".equals(field)) {
289 ans.setStatus(this.getStatus());
291 if ("mac_address".equals(field)) {
292 ans.setMacAddress(this.getMacAddress());
294 if ("fixed_ips".equals(field)) {
295 ans.setFixedIPs(new ArrayList<>(this.getFixedIPs()));
297 if ("device_id".equals(field)) {
298 ans.setDeviceID(this.getDeviceID());
300 if ("device_owner".equals(field)) {
301 ans.setDeviceOwner(this.getDeviceOwner());
303 if ("tenant_id".equals(field)) {
304 ans.setTenantID(this.getTenantID());
306 if ("security_groups".equals(field)) {
307 ans.setSecurityGroups(new ArrayList<>(this.getSecurityGroups()));
309 if ("port_security_enabled".equals(field)) {
310 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
316 public void initDefaults() {
318 portSecurityEnabled = true;
319 if (status == null) {
322 if (fixedIPs == null) {
323 fixedIPs = new ArrayList<>();
328 public String toString() {
329 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
330 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
331 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
332 + tenantID + ", securityGroups=" + securityGroups
333 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
334 + ", bindingvnicType=" + bindingvnicType + ", portSecurityEnabled=" + portSecurityEnabled +"]";