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.Iterator;
16 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 HashMap<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 Iterator<String> i = fields.iterator();
273 while (i.hasNext()) {
275 if (s.equals("id")) {
276 ans.setPortUUID(this.getPortUUID());
278 if (s.equals("network_id")) {
279 ans.setNetworkUUID(this.getNetworkUUID());
281 if (s.equals("name")) {
282 ans.setName(this.getName());
284 if (s.equals("admin_state_up")) {
285 ans.setAdminStateUp(this.getAdminStateUp());
287 if (s.equals("status")) {
288 ans.setStatus(this.getStatus());
290 if (s.equals("mac_address")) {
291 ans.setMacAddress(this.getMacAddress());
293 if (s.equals("fixed_ips")) {
294 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
295 fixedIPs.addAll(this.getFixedIPs());
296 ans.setFixedIPs(fixedIPs);
298 if (s.equals("device_id")) {
299 ans.setDeviceID(this.getDeviceID());
301 if (s.equals("device_owner")) {
302 ans.setDeviceOwner(this.getDeviceOwner());
304 if (s.equals("tenant_id")) {
305 ans.setTenantID(this.getTenantID());
307 if (s.equals("security_groups")) {
308 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
309 securityGroups.addAll(this.getSecurityGroups());
310 ans.setSecurityGroups(securityGroups);
316 public void initDefaults() {
318 if (status == null) {
321 if (fixedIPs == null) {
322 fixedIPs = new ArrayList<Neutron_IPs>();
327 * This method checks to see if the port has a floating IPv4 address
328 * associated with the supplied fixed IPv4 address
331 * fixed IPv4 address in dotted decimal format
332 * @return a boolean indicating if there is a floating IPv4 address bound
333 * to the fixed IPv4 address
336 public boolean isBoundToFloatingIP(String fixedIP) {
337 return floatingIPMap.containsKey(fixedIP);
341 public String toString() {
342 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
343 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
344 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
345 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups
346 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
347 + ", bindingvnicType=" + bindingvnicType + "]";