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