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 (namespace = "binding", name = "host_id")
72 @XmlElement (namespace = "binding", name = "vnic_type")
73 String bindingvnicType;
75 @XmlElement (namespace = "binding", name = "vif_type")
76 String bindingvifType;
79 /* this attribute stores the floating IP address assigned to
80 * each fixed IP address
83 HashMap<String, NeutronFloatingIP> floatingIPMap;
85 public NeutronPort() {
86 floatingIPMap = new HashMap<String, NeutronFloatingIP>();
89 public String getID() { return portUUID; }
91 public void setID(String id) { this.portUUID = id; }
93 public String getPortUUID() {
97 public void setPortUUID(String portUUID) {
98 this.portUUID = portUUID;
101 public String getNetworkUUID() {
105 public void setNetworkUUID(String networkUUID) {
106 this.networkUUID = networkUUID;
109 public String getName() {
113 public void setName(String name) {
117 public boolean isAdminStateUp() {
118 if (adminStateUp == null) {
124 public Boolean getAdminStateUp() { return adminStateUp; }
126 public void setAdminStateUp(Boolean newValue) {
127 adminStateUp = newValue;
130 public String getStatus() {
134 public void setStatus(String status) {
135 this.status = status;
138 public String getMacAddress() {
142 public void setMacAddress(String macAddress) {
143 this.macAddress = macAddress;
146 public List<Neutron_IPs> getFixedIPs() {
150 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
151 this.fixedIPs = fixedIPs;
154 public String getDeviceID() {
158 public void setDeviceID(String deviceID) {
159 this.deviceID = deviceID;
162 public String getDeviceOwner() {
166 public void setDeviceOwner(String deviceOwner) {
167 this.deviceOwner = deviceOwner;
170 public String getTenantID() {
174 public void setTenantID(String tenantID) {
175 this.tenantID = tenantID;
178 public List<NeutronSecurityGroup> getSecurityGroups() {
179 return securityGroups;
182 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
183 this.securityGroups = securityGroups;
186 public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
187 return allowedAddressPairs;
190 public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
191 this.allowedAddressPairs = allowedAddressPairs;
194 public String getBindinghostID() {
195 return bindinghostID;
198 public void setBindinghostID(String bindinghostID) {
199 this.bindinghostID = bindinghostID;
202 public String getBindingvnicType() {
203 return bindingvnicType;
206 public void setBindingvnicType(String bindingvnicType) {
207 this.bindingvnicType = bindingvnicType;
210 public String getBindingvifType() {
211 return bindingvifType;
214 public void setBindingvifType(String bindingvifType) {
215 this.bindingvifType = bindingvifType;
218 public NeutronFloatingIP getFloatingIP(String key) {
219 if (!floatingIPMap.containsKey(key)) {
222 return floatingIPMap.get(key);
225 public void removeFloatingIP(String key) {
226 floatingIPMap.remove(key);
229 public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
230 if (!floatingIPMap.containsKey(key)) {
231 floatingIPMap.put(key, floatingIP);
236 * This method copies selected fields from the object and returns them
237 * as a new object, suitable for marshaling.
240 * List of attributes to be extracted
241 * @return an OpenStackPorts object with only the selected fields
245 public NeutronPort extractFields(List<String> fields) {
246 NeutronPort ans = new NeutronPort();
247 Iterator<String> i = fields.iterator();
248 while (i.hasNext()) {
250 if (s.equals("id")) {
251 ans.setPortUUID(this.getPortUUID());
253 if (s.equals("network_id")) {
254 ans.setNetworkUUID(this.getNetworkUUID());
256 if (s.equals("name")) {
257 ans.setName(this.getName());
259 if (s.equals("admin_state_up")) {
260 ans.setAdminStateUp(this.getAdminStateUp());
262 if (s.equals("status")) {
263 ans.setStatus(this.getStatus());
265 if (s.equals("mac_address")) {
266 ans.setMacAddress(this.getMacAddress());
268 if (s.equals("fixed_ips")) {
269 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
270 fixedIPs.addAll(this.getFixedIPs());
271 ans.setFixedIPs(fixedIPs);
273 if (s.equals("device_id")) {
274 ans.setDeviceID(this.getDeviceID());
276 if (s.equals("device_owner")) {
277 ans.setDeviceOwner(this.getDeviceOwner());
279 if (s.equals("tenant_id")) {
280 ans.setTenantID(this.getTenantID());
282 if (s.equals("security_groups")) {
283 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
284 securityGroups.addAll(this.getSecurityGroups());
285 ans.setSecurityGroups(securityGroups);
291 public void initDefaults() {
293 if (status == null) {
296 if (fixedIPs == null) {
297 fixedIPs = new ArrayList<Neutron_IPs>();
302 * This method checks to see if the port has a floating IPv4 address
303 * associated with the supplied fixed IPv4 address
306 * fixed IPv4 address in dotted decimal format
307 * @return a boolean indicating if there is a floating IPv4 address bound
308 * to the fixed IPv4 address
311 public boolean isBoundToFloatingIP(String fixedIP) {
312 return floatingIPMap.containsKey(fixedIP);
316 public String toString() {
317 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
318 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
319 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
320 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups
321 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
322 + ", bindingvnicType=" + bindingvnicType + "]";