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.controller.networkconfig.neutron;
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 (namespace= "binding", name="host_id")
69 @XmlElement (namespace= "binding", name="vnic_type")
70 String bindingvnicType;
72 @XmlElement (namespace= "binding", name="vif_type")
73 String bindingvifType;
76 /* this attribute stores the floating IP address assigned to
77 * each fixed IP address
80 HashMap<String, NeutronFloatingIP> floatingIPMap;
82 public NeutronPort() {
83 floatingIPMap = new HashMap<String, NeutronFloatingIP>();
86 public String getID() { return portUUID; }
88 public void setID(String id) { this.portUUID = id; }
90 public String getPortUUID() {
94 public void setPortUUID(String portUUID) {
95 this.portUUID = portUUID;
98 public String getNetworkUUID() {
102 public void setNetworkUUID(String networkUUID) {
103 this.networkUUID = networkUUID;
106 public String getName() {
110 public void setName(String name) {
114 public boolean isAdminStateUp() {
115 if (adminStateUp == null) {
121 public Boolean getAdminStateUp() { return adminStateUp; }
123 public void setAdminStateUp(Boolean newValue) {
124 adminStateUp = newValue;
127 public String getStatus() {
131 public void setStatus(String status) {
132 this.status = status;
135 public String getMacAddress() {
139 public void setMacAddress(String macAddress) {
140 this.macAddress = macAddress;
143 public List<Neutron_IPs> getFixedIPs() {
147 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
148 this.fixedIPs = fixedIPs;
151 public String getDeviceID() {
155 public void setDeviceID(String deviceID) {
156 this.deviceID = deviceID;
159 public String getDeviceOwner() {
163 public void setDeviceOwner(String deviceOwner) {
164 this.deviceOwner = deviceOwner;
167 public String getTenantID() {
171 public void setTenantID(String tenantID) {
172 this.tenantID = tenantID;
175 public List<NeutronSecurityGroup> getSecurityGroups() {
176 return securityGroups;
179 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
180 this.securityGroups = securityGroups;
183 public String getBindinghostID() {
184 return bindinghostID;
187 public void setBindinghostID(String bindinghostID) {
188 this.bindinghostID = bindinghostID;
191 public String getBindingvnicType() {
192 return bindingvnicType;
195 public void setBindingvnicType(String bindingvnicType) {
196 this.bindingvnicType = bindingvnicType;
199 public String getBindingvifType() {
200 return bindingvifType;
203 public void setBindingvifType(String bindingvifType) {
204 this.bindingvifType = bindingvifType;
207 public NeutronFloatingIP getFloatingIP(String key) {
208 if (!floatingIPMap.containsKey(key)) {
211 return floatingIPMap.get(key);
214 public void removeFloatingIP(String key) {
215 floatingIPMap.remove(key);
218 public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
219 if (!floatingIPMap.containsKey(key)) {
220 floatingIPMap.put(key, floatingIP);
225 * This method copies selected fields from the object and returns them
226 * as a new object, suitable for marshaling.
229 * List of attributes to be extracted
230 * @return an OpenStackPorts object with only the selected fields
234 public NeutronPort extractFields(List<String> fields) {
235 NeutronPort ans = new NeutronPort();
236 Iterator<String> i = fields.iterator();
237 while (i.hasNext()) {
239 if (s.equals("id")) {
240 ans.setPortUUID(this.getPortUUID());
242 if (s.equals("network_id")) {
243 ans.setNetworkUUID(this.getNetworkUUID());
245 if (s.equals("name")) {
246 ans.setName(this.getName());
248 if (s.equals("admin_state_up")) {
249 ans.setAdminStateUp(this.getAdminStateUp());
251 if (s.equals("status")) {
252 ans.setStatus(this.getStatus());
254 if (s.equals("mac_address")) {
255 ans.setMacAddress(this.getMacAddress());
257 if (s.equals("fixed_ips")) {
258 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
259 fixedIPs.addAll(this.getFixedIPs());
260 ans.setFixedIPs(fixedIPs);
262 if (s.equals("device_id")) {
263 ans.setDeviceID(this.getDeviceID());
265 if (s.equals("device_owner")) {
266 ans.setDeviceOwner(this.getDeviceOwner());
268 if (s.equals("tenant_id")) {
269 ans.setTenantID(this.getTenantID());
271 if (s.equals("security_groups")) {
272 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
273 securityGroups.addAll(this.getSecurityGroups());
274 ans.setSecurityGroups(securityGroups);
280 public void initDefaults() {
282 if (status == null) {
285 if (fixedIPs == null) {
286 fixedIPs = new ArrayList<Neutron_IPs>();
291 * This method checks to see if the port has a floating IPv4 address
292 * associated with the supplied fixed IPv4 address
295 * fixed IPv4 address in dotted decimal format
296 * @return a boolean indicating if there is a floating IPv4 address bound
297 * to the fixed IPv4 address
300 public boolean isBoundToFloatingIP(String fixedIP) {
301 return floatingIPMap.containsKey(fixedIP);
305 public String toString() {
306 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
307 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
308 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
309 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups
310 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
311 + ", bindingvnicType=" + bindingvnicType + "]";