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;
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.Iterator;
15 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;
22 import org.opendaylight.controller.configuration.ConfigurationObject;
26 @XmlAccessorType(XmlAccessType.NONE)
28 public class NeutronPort extends ConfigurationObject implements Serializable, INeutronObject {
29 private static final long serialVersionUID = 1L;
31 // See OpenStack Network API v2.0 Reference for description of
32 // annotated attributes
34 @XmlElement (name="id")
37 @XmlElement (name="network_id")
40 @XmlElement (name="name")
43 @XmlElement (defaultValue="true", name="admin_state_up")
46 @XmlElement (name="status")
49 @XmlElement (name="mac_address")
52 @XmlElement (name="fixed_ips")
53 List<Neutron_IPs> fixedIPs;
55 @XmlElement (name="device_id")
58 @XmlElement (name="device_owner")
61 @XmlElement (name="tenant_id")
64 @XmlElement (name="security_groups")
65 List<NeutronSecurityGroup> securityGroups;
67 /* this attribute stores the floating IP address assigned to
68 * each fixed IP address
71 HashMap<String, NeutronFloatingIP> floatingIPMap;
73 public NeutronPort() {
74 floatingIPMap = new HashMap<String, NeutronFloatingIP>();
77 public String getID() { return portUUID; }
79 public void setID(String id) { this.portUUID = id; }
81 public String getPortUUID() {
85 public void setPortUUID(String portUUID) {
86 this.portUUID = portUUID;
89 public String getNetworkUUID() {
93 public void setNetworkUUID(String networkUUID) {
94 this.networkUUID = networkUUID;
97 public String getName() {
101 public void setName(String name) {
105 public boolean isAdminStateUp() {
106 if (adminStateUp == null) {
112 public Boolean getAdminStateUp() { return adminStateUp; }
114 public void setAdminStateUp(Boolean newValue) {
115 adminStateUp = newValue;
118 public String getStatus() {
122 public void setStatus(String status) {
123 this.status = status;
126 public String getMacAddress() {
130 public void setMacAddress(String macAddress) {
131 this.macAddress = macAddress;
134 public List<Neutron_IPs> getFixedIPs() {
138 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
139 this.fixedIPs = fixedIPs;
142 public String getDeviceID() {
146 public void setDeviceID(String deviceID) {
147 this.deviceID = deviceID;
150 public String getDeviceOwner() {
154 public void setDeviceOwner(String deviceOwner) {
155 this.deviceOwner = deviceOwner;
158 public String getTenantID() {
162 public void setTenantID(String tenantID) {
163 this.tenantID = tenantID;
166 public List<NeutronSecurityGroup> getSecurityGroups() {
167 return securityGroups;
170 public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
171 this.securityGroups = securityGroups;
174 public NeutronFloatingIP getFloatingIP(String key) {
175 if (!floatingIPMap.containsKey(key)) {
178 return floatingIPMap.get(key);
181 public void removeFloatingIP(String key) {
182 floatingIPMap.remove(key);
185 public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
186 if (!floatingIPMap.containsKey(key)) {
187 floatingIPMap.put(key, floatingIP);
192 * This method copies selected fields from the object and returns them
193 * as a new object, suitable for marshaling.
196 * List of attributes to be extracted
197 * @return an OpenStackPorts object with only the selected fields
201 public NeutronPort extractFields(List<String> fields) {
202 NeutronPort ans = new NeutronPort();
203 Iterator<String> i = fields.iterator();
204 while (i.hasNext()) {
206 if (s.equals("id")) {
207 ans.setPortUUID(this.getPortUUID());
209 if (s.equals("network_id")) {
210 ans.setNetworkUUID(this.getNetworkUUID());
212 if (s.equals("name")) {
213 ans.setName(this.getName());
215 if (s.equals("admin_state_up")) {
216 ans.setAdminStateUp(this.getAdminStateUp());
218 if (s.equals("status")) {
219 ans.setStatus(this.getStatus());
221 if (s.equals("mac_address")) {
222 ans.setMacAddress(this.getMacAddress());
224 if (s.equals("fixed_ips")) {
225 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
226 fixedIPs.addAll(this.getFixedIPs());
227 ans.setFixedIPs(fixedIPs);
229 if (s.equals("device_id")) {
230 ans.setDeviceID(this.getDeviceID());
232 if (s.equals("device_owner")) {
233 ans.setDeviceOwner(this.getDeviceOwner());
235 if (s.equals("tenant_id")) {
236 ans.setTenantID(this.getTenantID());
238 if (s.equals("security_groups")) {
239 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
240 securityGroups.addAll(this.getSecurityGroups());
241 ans.setSecurityGroups(securityGroups);
247 public void initDefaults() {
249 if (status == null) {
252 if (fixedIPs == null) {
253 fixedIPs = new ArrayList<Neutron_IPs>();
258 * This method checks to see if the port has a floating IPv4 address
259 * associated with the supplied fixed IPv4 address
262 * fixed IPv4 address in dotted decimal format
263 * @return a boolean indicating if there is a floating IPv4 address bound
264 * to the fixed IPv4 address
267 public boolean isBoundToFloatingIP(String fixedIP) {
268 return floatingIPMap.containsKey(fixedIP);
272 public String toString() {
273 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
274 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
275 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
276 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups + "]";