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.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.Iterator;
14 import java.util.List;
16 import javax.xml.bind.annotation.XmlAccessType;
17 import javax.xml.bind.annotation.XmlAccessorType;
18 import javax.xml.bind.annotation.XmlElement;
19 import javax.xml.bind.annotation.XmlRootElement;
23 @XmlAccessorType(XmlAccessType.NONE)
25 public class NeutronPort {
26 // See OpenStack Network API v2.0 Reference for description of
27 // annotated attributes
29 @XmlElement (name="id")
32 @XmlElement (name="network_id")
35 @XmlElement (name="name")
38 @XmlElement (defaultValue="true", name="admin_state_up")
41 @XmlElement (name="status")
44 @XmlElement (name="mac_address")
47 @XmlElement (name="fixed_ips")
48 List<Neutron_IPs> fixedIPs;
50 @XmlElement (name="device_id")
53 @XmlElement (name="device_owner")
56 @XmlElement (name="tenant_id")
59 // TODO: add security groups
60 // @XmlElement (name="security_groups")
61 // List<String> securityGroups;
63 /* this attribute stores the floating IP address assigned to
64 * each fixed IP address
67 HashMap<String, NeutronFloatingIP> floatingIPMap;
69 public NeutronPort() {
70 floatingIPMap = new HashMap<String, NeutronFloatingIP>();
73 public String getID() { return portUUID; }
75 public String getPortUUID() {
79 public void setPortUUID(String portUUID) {
80 this.portUUID = portUUID;
83 public String getNetworkUUID() {
87 public void setNetworkUUID(String networkUUID) {
88 this.networkUUID = networkUUID;
91 public String getName() {
95 public void setName(String name) {
99 public boolean isAdminStateUp() {
100 if (adminStateUp == null) {
106 public Boolean getAdminStateUp() { return adminStateUp; }
108 public void setAdminStateUp(Boolean newValue) {
109 adminStateUp = newValue;
112 public String getStatus() {
116 public void setStatus(String status) {
117 this.status = status;
120 public String getMacAddress() {
124 public void setMacAddress(String macAddress) {
125 this.macAddress = macAddress;
128 public List<Neutron_IPs> getFixedIPs() {
132 public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
133 this.fixedIPs = fixedIPs;
136 public String getDeviceID() {
140 public void setDeviceID(String deviceID) {
141 this.deviceID = deviceID;
144 public String getDeviceOwner() {
148 public void setDeviceOwner(String deviceOwner) {
149 this.deviceOwner = deviceOwner;
152 public String getTenantID() {
156 public void setTenantID(String tenantID) {
157 this.tenantID = tenantID;
160 public NeutronFloatingIP getFloatingIP(String key) {
161 if (!floatingIPMap.containsKey(key)) {
164 return floatingIPMap.get(key);
167 public void removeFloatingIP(String key) {
168 floatingIPMap.remove(key);
171 public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
172 if (!floatingIPMap.containsKey(key)) {
173 floatingIPMap.put(key, floatingIP);
178 * This method copies selected fields from the object and returns them
179 * as a new object, suitable for marshaling.
182 * List of attributes to be extracted
183 * @return an OpenStackPorts object with only the selected fields
187 public NeutronPort extractFields(List<String> fields) {
188 NeutronPort ans = new NeutronPort();
189 Iterator<String> i = fields.iterator();
190 while (i.hasNext()) {
192 if (s.equals("id")) {
193 ans.setPortUUID(this.getPortUUID());
195 if (s.equals("network_id")) {
196 ans.setNetworkUUID(this.getNetworkUUID());
198 if (s.equals("name")) {
199 ans.setName(this.getName());
201 if (s.equals("admin_state_up")) {
202 ans.setAdminStateUp(this.getAdminStateUp());
204 if (s.equals("status")) {
205 ans.setStatus(this.getStatus());
207 if (s.equals("mac_address")) {
208 ans.setMacAddress(this.getMacAddress());
210 if (s.equals("fixed_ips")) {
211 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
212 fixedIPs.addAll(this.getFixedIPs());
213 ans.setFixedIPs(fixedIPs);
215 if (s.equals("device_id")) {
216 ans.setDeviceID(this.getDeviceID());
218 if (s.equals("device_owner")) {
219 ans.setDeviceOwner(this.getDeviceOwner());
221 if (s.equals("tenant_id")) {
222 ans.setTenantID(this.getTenantID());
228 public void initDefaults() {
230 if (status == null) {
233 if (fixedIPs == null) {
234 fixedIPs = new ArrayList<Neutron_IPs>();
239 * This method checks to see if the port has a floating IPv4 address
240 * associated with the supplied fixed IPv4 address
243 * fixed IPv4 address in dotted decimal format
244 * @return a boolean indicating if there is a floating IPv4 address bound
245 * to the fixed IPv4 address
248 public boolean isBoundToFloatingIP(String fixedIP) {
249 return floatingIPMap.containsKey(fixedIP);
253 public String toString() {
254 return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
255 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
256 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
257 + tenantID + ", floatingIPMap=" + floatingIPMap + "]";