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;
24 @XmlAccessorType(XmlAccessType.NONE)
26 public class NeutronPort implements Serializable {
27 private static final long serialVersionUID = 1L;
29 // See OpenStack Network API v2.0 Reference for description of
30 // annotated attributes
32 @XmlElement (name="id")
35 @XmlElement (name="network_id")
38 @XmlElement (name="name")
41 @XmlElement (defaultValue="true", name="admin_state_up")
44 @XmlElement (name="status")
47 @XmlElement (name="mac_address")
50 @XmlElement (name="fixed_ips")
51 List<Neutron_IPs> fixedIPs;
53 @XmlElement (name="device_id")
56 @XmlElement (name="device_owner")
59 @XmlElement (name="tenant_id")
62 // TODO: add security groups
63 // @XmlElement (name="security_groups")
64 // List<String> securityGroups;
66 /* this attribute stores the floating IP address assigned to
67 * each fixed IP address
70 HashMap<String, NeutronFloatingIP> floatingIPMap;
72 public NeutronPort() {
73 floatingIPMap = new HashMap<String, NeutronFloatingIP>();
76 public String getID() { return portUUID; }
78 public String getPortUUID() {
82 public void setPortUUID(String portUUID) {
83 this.portUUID = portUUID;
86 public String getNetworkUUID() {
90 public void setNetworkUUID(String networkUUID) {
91 this.networkUUID = networkUUID;
94 public String getName() {
98 public void setName(String name) {
102 public boolean isAdminStateUp() {
103 if (adminStateUp == null) {
109 public Boolean getAdminStateUp() { return adminStateUp; }
111 public void setAdminStateUp(Boolean newValue) {
112 adminStateUp = newValue;
115 public String getStatus() {
119 public void setStatus(String status) {
120 this.status = status;
123 public String getMacAddress() {
127 public void setMacAddress(String macAddress) {
128 this.macAddress = macAddress;
131 public List<Neutron_IPs> getFixedIPs() {
135 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
136 this.fixedIPs = fixedIPs;
139 public String getDeviceID() {
143 public void setDeviceID(String deviceID) {
144 this.deviceID = deviceID;
147 public String getDeviceOwner() {
151 public void setDeviceOwner(String deviceOwner) {
152 this.deviceOwner = deviceOwner;
155 public String getTenantID() {
159 public void setTenantID(String tenantID) {
160 this.tenantID = tenantID;
163 public NeutronFloatingIP getFloatingIP(String key) {
164 if (!floatingIPMap.containsKey(key)) {
167 return floatingIPMap.get(key);
170 public void removeFloatingIP(String key) {
171 floatingIPMap.remove(key);
174 public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
175 if (!floatingIPMap.containsKey(key)) {
176 floatingIPMap.put(key, floatingIP);
181 * This method copies selected fields from the object and returns them
182 * as a new object, suitable for marshaling.
185 * List of attributes to be extracted
186 * @return an OpenStackPorts object with only the selected fields
190 public NeutronPort extractFields(List<String> fields) {
191 NeutronPort ans = new NeutronPort();
192 Iterator<String> i = fields.iterator();
193 while (i.hasNext()) {
195 if (s.equals("id")) {
196 ans.setPortUUID(this.getPortUUID());
198 if (s.equals("network_id")) {
199 ans.setNetworkUUID(this.getNetworkUUID());
201 if (s.equals("name")) {
202 ans.setName(this.getName());
204 if (s.equals("admin_state_up")) {
205 ans.setAdminStateUp(this.getAdminStateUp());
207 if (s.equals("status")) {
208 ans.setStatus(this.getStatus());
210 if (s.equals("mac_address")) {
211 ans.setMacAddress(this.getMacAddress());
213 if (s.equals("fixed_ips")) {
214 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
215 fixedIPs.addAll(this.getFixedIPs());
216 ans.setFixedIPs(fixedIPs);
218 if (s.equals("device_id")) {
219 ans.setDeviceID(this.getDeviceID());
221 if (s.equals("device_owner")) {
222 ans.setDeviceOwner(this.getDeviceOwner());
224 if (s.equals("tenant_id")) {
225 ans.setTenantID(this.getTenantID());
231 public void initDefaults() {
233 if (status == null) {
236 if (fixedIPs == null) {
237 fixedIPs = new ArrayList<Neutron_IPs>();
242 * This method checks to see if the port has a floating IPv4 address
243 * associated with the supplied fixed IPv4 address
246 * fixed IPv4 address in dotted decimal format
247 * @return a boolean indicating if there is a floating IPv4 address bound
248 * to the fixed IPv4 address
251 public boolean isBoundToFloatingIP(String fixedIP) {
252 return floatingIPMap.containsKey(fixedIP);
256 public String toString() {
257 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
258 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
259 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
260 + tenantID + ", floatingIPMap=" + floatingIPMap + "]";