2 * Copyright IBM Corporation, 2013. 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;
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlElement;
21 import javax.xml.bind.annotation.XmlRootElement;
25 @XmlAccessorType(XmlAccessType.NONE)
27 public class NeutronPort implements Serializable, INeutronObject {
28 private static final long serialVersionUID = 1L;
30 // See OpenStack Network API v2.0 Reference for description of
31 // annotated attributes
33 @XmlElement (name = "id")
36 @XmlElement (name = "network_id")
39 @XmlElement (name = "name")
42 @XmlElement (defaultValue = "true", name = "admin_state_up")
45 @XmlElement (name = "status")
48 @XmlElement (name = "mac_address")
51 @XmlElement (name = "fixed_ips")
52 List<Neutron_IPs> fixedIPs;
54 @XmlElement (name = "device_id")
57 @XmlElement (name = "device_owner")
60 @XmlElement (name = "tenant_id")
63 @XmlElement (name = "security_groups")
64 List<NeutronSecurityGroup> securityGroups;
66 @XmlElement (name = "allowed_address_pairs")
67 List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
69 //@XmlElement (name = "binding:host_id")
70 @XmlElement (namespace = "binding", name = "host_id")
73 //@XmlElement (name = "binding:vnic_type")
74 @XmlElement (namespace = "binding", name = "vnic_type")
75 String bindingvnicType;
77 //@XmlElement (name = "binding:vif_type")
78 @XmlElement (namespace = "binding", name = "vif_type")
79 String bindingvifType;
81 //@XmlElement (name = "binding:vif_details")
82 @XmlElement (namespace = "binding", name = "vif_details")
83 List<NeutronPort_VIFDetail> vifDetails;
85 @XmlElement (name = "extra_dhcp_opts")
86 List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
88 /* this attribute stores the floating IP address assigned to
89 * each fixed IP address
92 Map<String, NeutronFloatingIP> floatingIPMap;
94 public NeutronPort() {
95 floatingIPMap = new HashMap<String, NeutronFloatingIP>();
98 public String getID() { return portUUID; }
100 public void setID(String id) { this.portUUID = id; }
102 public String getPortUUID() {
106 public void setPortUUID(String portUUID) {
107 this.portUUID = portUUID;
110 public String getNetworkUUID() {
114 public void setNetworkUUID(String networkUUID) {
115 this.networkUUID = networkUUID;
118 public String getName() {
122 public void setName(String name) {
126 public boolean isAdminStateUp() {
127 if (adminStateUp == null) {
133 public Boolean getAdminStateUp() { return adminStateUp; }
135 public void setAdminStateUp(Boolean newValue) {
136 adminStateUp = newValue;
139 public String getStatus() {
143 public void setStatus(String status) {
144 this.status = status;
147 public String getMacAddress() {
151 public void setMacAddress(String macAddress) {
152 this.macAddress = macAddress;
155 public List<Neutron_IPs> getFixedIPs() {
159 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
160 this.fixedIPs = fixedIPs;
163 public String getDeviceID() {
167 public void setDeviceID(String deviceID) {
168 this.deviceID = deviceID;
171 public String getDeviceOwner() {
175 public void setDeviceOwner(String deviceOwner) {
176 this.deviceOwner = deviceOwner;
179 public String getTenantID() {
183 public void setTenantID(String tenantID) {
184 this.tenantID = tenantID;
187 public List<NeutronSecurityGroup> getSecurityGroups() {
188 return securityGroups;
191 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
192 this.securityGroups = securityGroups;
195 public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
196 return allowedAddressPairs;
199 public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
200 this.allowedAddressPairs = allowedAddressPairs;
203 public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
204 return extraDHCPOptions;
207 public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
208 this.extraDHCPOptions = extraDHCPOptions;
211 public List<NeutronPort_VIFDetail> getVIFDetail() {
215 public void setVIFDetail(List<NeutronPort_VIFDetail> vifDetails) {
216 this.vifDetails = vifDetails;
219 public String getBindinghostID() {
220 return bindinghostID;
223 public void setBindinghostID(String bindinghostID) {
224 this.bindinghostID = bindinghostID;
227 public String getBindingvnicType() {
228 return bindingvnicType;
231 public void setBindingvnicType(String bindingvnicType) {
232 this.bindingvnicType = bindingvnicType;
235 public String getBindingvifType() {
236 return bindingvifType;
239 public void setBindingvifType(String bindingvifType) {
240 this.bindingvifType = bindingvifType;
243 public NeutronFloatingIP getFloatingIP(String key) {
244 if (!floatingIPMap.containsKey(key)) {
247 return floatingIPMap.get(key);
250 public void removeFloatingIP(String key) {
251 floatingIPMap.remove(key);
254 public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
255 if (!floatingIPMap.containsKey(key)) {
256 floatingIPMap.put(key, floatingIP);
261 * This method copies selected fields from the object and returns them
262 * as a new object, suitable for marshaling.
265 * List of attributes to be extracted
266 * @return an OpenStackPorts object with only the selected fields
270 public NeutronPort extractFields(List<String> fields) {
271 NeutronPort ans = new NeutronPort();
272 for (String field: fields) {
273 if (fields.equals("id")) {
274 ans.setPortUUID(this.getPortUUID());
276 if (fields.equals("network_id")) {
277 ans.setNetworkUUID(this.getNetworkUUID());
279 if (fields.equals("name")) {
280 ans.setName(this.getName());
282 if (fields.equals("admin_state_up")) {
283 ans.setAdminStateUp(this.getAdminStateUp());
285 if (fields.equals("status")) {
286 ans.setStatus(this.getStatus());
288 if (fields.equals("mac_address")) {
289 ans.setMacAddress(this.getMacAddress());
291 if (fields.equals("fixed_ips")) {
292 ans.setFixedIPs(new ArrayList<Neutron_IPs>(this.getFixedIPs()));
294 if (fields.equals("device_id")) {
295 ans.setDeviceID(this.getDeviceID());
297 if (fields.equals("device_owner")) {
298 ans.setDeviceOwner(this.getDeviceOwner());
300 if (fields.equals("tenant_id")) {
301 ans.setTenantID(this.getTenantID());
303 if (fields.equals("security_groups")) {
304 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
310 public void initDefaults() {
312 if (status == null) {
315 if (fixedIPs == null) {
316 fixedIPs = new ArrayList<Neutron_IPs>();
321 * This method checks to see if the port has a floating IPv4 address
322 * associated with the supplied fixed IPv4 address
325 * fixed IPv4 address in dotted decimal format
326 * @return a boolean indicating if there is a floating IPv4 address bound
327 * to the fixed IPv4 address
330 public boolean isBoundToFloatingIP(String fixedIP) {
331 return floatingIPMap.containsKey(fixedIP);
335 public String toString() {
336 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
337 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
338 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
339 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups
340 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
341 + ", bindingvnicType=" + bindingvnicType + "]";