Merge "Do not duplicate OSGi dependencyManagement"
[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
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;
17
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;
22
23
24 @XmlRootElement
25 @XmlAccessorType(XmlAccessType.NONE)
26
27 public class NeutronPort implements Serializable, INeutronObject {
28     private static final long serialVersionUID = 1L;
29
30     // See OpenStack Network API v2.0 Reference for description of
31     // annotated attributes
32
33     @XmlElement (name="id")
34     String portUUID;
35
36     @XmlElement (name="network_id")
37     String networkUUID;
38
39     @XmlElement (name="name")
40     String name;
41
42     @XmlElement (defaultValue="true", name="admin_state_up")
43     Boolean adminStateUp;
44
45     @XmlElement (name="status")
46     String status;
47
48     @XmlElement (name="mac_address")
49     String macAddress;
50
51     @XmlElement (name="fixed_ips")
52     List<Neutron_IPs> fixedIPs;
53
54     @XmlElement (name="device_id")
55     String deviceID;
56
57     @XmlElement (name="device_owner")
58     String deviceOwner;
59
60     @XmlElement (name="tenant_id")
61     String tenantID;
62
63     @XmlElement (name="security_groups")
64     List<NeutronSecurityGroup> securityGroups;
65
66     @XmlElement (namespace= "binding", name="host_id")
67     String bindinghostID;
68
69     @XmlElement (namespace= "binding", name="vnic_type")
70     String bindingvnicType;
71
72     @XmlElement (namespace= "binding", name="vif_type")
73     String bindingvifType;
74
75
76     /* this attribute stores the floating IP address assigned to
77      * each fixed IP address
78      */
79
80     HashMap<String, NeutronFloatingIP> floatingIPMap;
81
82     public NeutronPort() {
83         floatingIPMap = new HashMap<String, NeutronFloatingIP>();
84     }
85
86     public String getID() { return portUUID; }
87
88     public void setID(String id) { this.portUUID = id; }
89
90     public String getPortUUID() {
91         return portUUID;
92     }
93
94     public void setPortUUID(String portUUID) {
95         this.portUUID = portUUID;
96     }
97
98     public String getNetworkUUID() {
99         return networkUUID;
100     }
101
102     public void setNetworkUUID(String networkUUID) {
103         this.networkUUID = networkUUID;
104     }
105
106     public String getName() {
107         return name;
108     }
109
110     public void setName(String name) {
111         this.name = name;
112     }
113
114     public boolean isAdminStateUp() {
115         if (adminStateUp == null) {
116             return true;
117         }
118         return adminStateUp;
119     }
120
121     public Boolean getAdminStateUp() { return adminStateUp; }
122
123     public void setAdminStateUp(Boolean newValue) {
124             adminStateUp = newValue;
125     }
126
127     public String getStatus() {
128         return status;
129     }
130
131     public void setStatus(String status) {
132         this.status = status;
133     }
134
135     public String getMacAddress() {
136         return macAddress;
137     }
138
139     public void setMacAddress(String macAddress) {
140         this.macAddress = macAddress;
141     }
142
143     public List<Neutron_IPs> getFixedIPs() {
144         return fixedIPs;
145     }
146
147     public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
148         this.fixedIPs = fixedIPs;
149     }
150
151     public String getDeviceID() {
152         return deviceID;
153     }
154
155     public void setDeviceID(String deviceID) {
156         this.deviceID = deviceID;
157     }
158
159     public String getDeviceOwner() {
160         return deviceOwner;
161     }
162
163     public void setDeviceOwner(String deviceOwner) {
164         this.deviceOwner = deviceOwner;
165     }
166
167     public String getTenantID() {
168         return tenantID;
169     }
170
171     public void setTenantID(String tenantID) {
172         this.tenantID = tenantID;
173     }
174
175     public List<NeutronSecurityGroup> getSecurityGroups() {
176         return securityGroups;
177     }
178
179     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
180         this.securityGroups = securityGroups;
181     }
182
183     public String getBindinghostID() {
184       return bindinghostID;
185     }
186
187     public void setBindinghostID(String bindinghostID) {
188       this.bindinghostID = bindinghostID;
189     }
190
191   public String getBindingvnicType() {
192     return bindingvnicType;
193   }
194
195   public void setBindingvnicType(String bindingvnicType) {
196     this.bindingvnicType = bindingvnicType;
197   }
198
199   public String getBindingvifType() {
200     return bindingvifType;
201   }
202
203   public void setBindingvifType(String bindingvifType) {
204     this.bindingvifType = bindingvifType;
205   }
206
207     public NeutronFloatingIP getFloatingIP(String key) {
208         if (!floatingIPMap.containsKey(key)) {
209             return null;
210         }
211         return floatingIPMap.get(key);
212     }
213
214     public void removeFloatingIP(String key) {
215         floatingIPMap.remove(key);
216     }
217
218     public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
219         if (!floatingIPMap.containsKey(key)) {
220             floatingIPMap.put(key, floatingIP);
221         }
222     }
223
224     /**
225      * This method copies selected fields from the object and returns them
226      * as a new object, suitable for marshaling.
227      *
228      * @param fields
229      *            List of attributes to be extracted
230      * @return an OpenStackPorts object with only the selected fields
231      * populated
232      */
233
234     public NeutronPort extractFields(List<String> fields) {
235         NeutronPort ans = new NeutronPort();
236         Iterator<String> i = fields.iterator();
237         while (i.hasNext()) {
238             String s = i.next();
239             if (s.equals("id")) {
240                 ans.setPortUUID(this.getPortUUID());
241             }
242             if (s.equals("network_id")) {
243                 ans.setNetworkUUID(this.getNetworkUUID());
244             }
245             if (s.equals("name")) {
246                 ans.setName(this.getName());
247             }
248             if (s.equals("admin_state_up")) {
249                 ans.setAdminStateUp(this.getAdminStateUp());
250             }
251             if (s.equals("status")) {
252                 ans.setStatus(this.getStatus());
253             }
254             if (s.equals("mac_address")) {
255                 ans.setMacAddress(this.getMacAddress());
256             }
257             if (s.equals("fixed_ips")) {
258                 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
259                 fixedIPs.addAll(this.getFixedIPs());
260                 ans.setFixedIPs(fixedIPs);
261             }
262             if (s.equals("device_id")) {
263                 ans.setDeviceID(this.getDeviceID());
264             }
265             if (s.equals("device_owner")) {
266                 ans.setDeviceOwner(this.getDeviceOwner());
267             }
268             if (s.equals("tenant_id")) {
269                 ans.setTenantID(this.getTenantID());
270             }
271             if (s.equals("security_groups")) {
272                 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
273                 securityGroups.addAll(this.getSecurityGroups());
274                 ans.setSecurityGroups(securityGroups);
275             }
276         }
277         return ans;
278     }
279
280     public void initDefaults() {
281         adminStateUp = true;
282         if (status == null) {
283             status = "ACTIVE";
284         }
285         if (fixedIPs == null) {
286             fixedIPs = new ArrayList<Neutron_IPs>();
287         }
288     }
289
290     /**
291      * This method checks to see if the port has a floating IPv4 address
292      * associated with the supplied fixed IPv4 address
293      *
294      * @param fixedIP
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
298      */
299
300     public boolean isBoundToFloatingIP(String fixedIP) {
301         return floatingIPMap.containsKey(fixedIP);
302     }
303
304     @Override
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 + "]";
312     }
313 }