Merge "Prevent ConfigPusher from killing its thread"
[controller.git] / opendaylight / networkconfiguration / neutron / src / main / java / org / opendaylight / controller / networkconfig / neutron / NeutronPort.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.networkconfig.neutron;
10
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;
16
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;
21
22 import org.opendaylight.controller.configuration.ConfigurationObject;
23
24
25 @XmlRootElement
26 @XmlAccessorType(XmlAccessType.NONE)
27
28 public class NeutronPort extends ConfigurationObject implements Serializable {
29     private static final long serialVersionUID = 1L;
30
31     // See OpenStack Network API v2.0 Reference for description of
32     // annotated attributes
33
34     @XmlElement (name="id")
35     String portUUID;
36
37     @XmlElement (name="network_id")
38     String networkUUID;
39
40     @XmlElement (name="name")
41     String name;
42
43     @XmlElement (defaultValue="true", name="admin_state_up")
44     Boolean adminStateUp;
45
46     @XmlElement (name="status")
47     String status;
48
49     @XmlElement (name="mac_address")
50     String macAddress;
51
52     @XmlElement (name="fixed_ips")
53     List<Neutron_IPs> fixedIPs;
54
55     @XmlElement (name="device_id")
56     String deviceID;
57
58     @XmlElement (name="device_owner")
59     String deviceOwner;
60
61     @XmlElement (name="tenant_id")
62     String tenantID;
63
64     // TODO: add security groups
65     //        @XmlElement (name="security_groups")
66     //        List<String> securityGroups;
67
68     /* this attribute stores the floating IP address assigned to
69      * each fixed IP address
70      */
71
72     HashMap<String, NeutronFloatingIP> floatingIPMap;
73
74     public NeutronPort() {
75         floatingIPMap = new HashMap<String, NeutronFloatingIP>();
76     }
77
78     public String getID() { return portUUID; }
79
80     public String getPortUUID() {
81         return portUUID;
82     }
83
84     public void setPortUUID(String portUUID) {
85         this.portUUID = portUUID;
86     }
87
88     public String getNetworkUUID() {
89         return networkUUID;
90     }
91
92     public void setNetworkUUID(String networkUUID) {
93         this.networkUUID = networkUUID;
94     }
95
96     public String getName() {
97         return name;
98     }
99
100     public void setName(String name) {
101         this.name = name;
102     }
103
104     public boolean isAdminStateUp() {
105         if (adminStateUp == null) {
106             return true;
107         }
108         return adminStateUp;
109     }
110
111     public Boolean getAdminStateUp() { return adminStateUp; }
112
113     public void setAdminStateUp(Boolean newValue) {
114             adminStateUp = newValue;
115     }
116
117     public String getStatus() {
118         return status;
119     }
120
121     public void setStatus(String status) {
122         this.status = status;
123     }
124
125     public String getMacAddress() {
126         return macAddress;
127     }
128
129     public void setMacAddress(String macAddress) {
130         this.macAddress = macAddress;
131     }
132
133     public List<Neutron_IPs> getFixedIPs() {
134         return fixedIPs;
135     }
136
137     public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
138         this.fixedIPs = fixedIPs;
139     }
140
141     public String getDeviceID() {
142         return deviceID;
143     }
144
145     public void setDeviceID(String deviceID) {
146         this.deviceID = deviceID;
147     }
148
149     public String getDeviceOwner() {
150         return deviceOwner;
151     }
152
153     public void setDeviceOwner(String deviceOwner) {
154         this.deviceOwner = deviceOwner;
155     }
156
157     public String getTenantID() {
158         return tenantID;
159     }
160
161     public void setTenantID(String tenantID) {
162         this.tenantID = tenantID;
163     }
164
165     public NeutronFloatingIP getFloatingIP(String key) {
166         if (!floatingIPMap.containsKey(key)) {
167             return null;
168         }
169         return floatingIPMap.get(key);
170     }
171
172     public void removeFloatingIP(String key) {
173         floatingIPMap.remove(key);
174     }
175
176     public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
177         if (!floatingIPMap.containsKey(key)) {
178             floatingIPMap.put(key, floatingIP);
179         }
180     }
181
182     /**
183      * This method copies selected fields from the object and returns them
184      * as a new object, suitable for marshaling.
185      *
186      * @param fields
187      *            List of attributes to be extracted
188      * @return an OpenStackPorts object with only the selected fields
189      * populated
190      */
191
192     public NeutronPort extractFields(List<String> fields) {
193         NeutronPort ans = new NeutronPort();
194         Iterator<String> i = fields.iterator();
195         while (i.hasNext()) {
196             String s = i.next();
197             if (s.equals("id")) {
198                 ans.setPortUUID(this.getPortUUID());
199             }
200             if (s.equals("network_id")) {
201                 ans.setNetworkUUID(this.getNetworkUUID());
202             }
203             if (s.equals("name")) {
204                 ans.setName(this.getName());
205             }
206             if (s.equals("admin_state_up")) {
207                 ans.setAdminStateUp(this.getAdminStateUp());
208             }
209             if (s.equals("status")) {
210                 ans.setStatus(this.getStatus());
211             }
212             if (s.equals("mac_address")) {
213                 ans.setMacAddress(this.getMacAddress());
214             }
215             if (s.equals("fixed_ips")) {
216                 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
217                 fixedIPs.addAll(this.getFixedIPs());
218                 ans.setFixedIPs(fixedIPs);
219             }
220             if (s.equals("device_id")) {
221                 ans.setDeviceID(this.getDeviceID());
222             }
223             if (s.equals("device_owner")) {
224                 ans.setDeviceOwner(this.getDeviceOwner());
225             }
226             if (s.equals("tenant_id")) {
227                 ans.setTenantID(this.getTenantID());
228             }
229         }
230         return ans;
231     }
232
233     public void initDefaults() {
234         adminStateUp = true;
235         if (status == null) {
236             status = "ACTIVE";
237         }
238         if (fixedIPs == null) {
239             fixedIPs = new ArrayList<Neutron_IPs>();
240         }
241     }
242
243     /**
244      * This method checks to see if the port has a floating IPv4 address
245      * associated with the supplied fixed IPv4 address
246      *
247      * @param fixedIP
248      *            fixed IPv4 address in dotted decimal format
249      * @return a boolean indicating if there is a floating IPv4 address bound
250      * to the fixed IPv4 address
251      */
252
253     public boolean isBoundToFloatingIP(String fixedIP) {
254         return floatingIPMap.containsKey(fixedIP);
255     }
256
257     @Override
258     public String toString() {
259         return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
260                 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
261                 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
262                 + tenantID + ", floatingIPMap=" + floatingIPMap + "]";
263     }
264 }