Merge "BUG-997 Use shared schema context factory in netconf-connector"
[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, INeutronObject {
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     @XmlElement (name="security_groups")
65     List<NeutronSecurityGroup> securityGroups;
66
67     /* this attribute stores the floating IP address assigned to
68      * each fixed IP address
69      */
70
71     HashMap<String, NeutronFloatingIP> floatingIPMap;
72
73     public NeutronPort() {
74         floatingIPMap = new HashMap<String, NeutronFloatingIP>();
75     }
76
77     public String getID() { return portUUID; }
78
79     public void setID(String id) { this.portUUID = id; }
80
81     public String getPortUUID() {
82         return portUUID;
83     }
84
85     public void setPortUUID(String portUUID) {
86         this.portUUID = portUUID;
87     }
88
89     public String getNetworkUUID() {
90         return networkUUID;
91     }
92
93     public void setNetworkUUID(String networkUUID) {
94         this.networkUUID = networkUUID;
95     }
96
97     public String getName() {
98         return name;
99     }
100
101     public void setName(String name) {
102         this.name = name;
103     }
104
105     public boolean isAdminStateUp() {
106         if (adminStateUp == null) {
107             return true;
108         }
109         return adminStateUp;
110     }
111
112     public Boolean getAdminStateUp() { return adminStateUp; }
113
114     public void setAdminStateUp(Boolean newValue) {
115             adminStateUp = newValue;
116     }
117
118     public String getStatus() {
119         return status;
120     }
121
122     public void setStatus(String status) {
123         this.status = status;
124     }
125
126     public String getMacAddress() {
127         return macAddress;
128     }
129
130     public void setMacAddress(String macAddress) {
131         this.macAddress = macAddress;
132     }
133
134     public List<Neutron_IPs> getFixedIPs() {
135         return fixedIPs;
136     }
137
138     public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
139         this.fixedIPs = fixedIPs;
140     }
141
142     public String getDeviceID() {
143         return deviceID;
144     }
145
146     public void setDeviceID(String deviceID) {
147         this.deviceID = deviceID;
148     }
149
150     public String getDeviceOwner() {
151         return deviceOwner;
152     }
153
154     public void setDeviceOwner(String deviceOwner) {
155         this.deviceOwner = deviceOwner;
156     }
157
158     public String getTenantID() {
159         return tenantID;
160     }
161
162     public void setTenantID(String tenantID) {
163         this.tenantID = tenantID;
164     }
165
166     public List<NeutronSecurityGroup> getSecurityGroups() {
167         return securityGroups;
168     }
169
170     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
171         this.securityGroups = securityGroups;
172     }
173
174     public NeutronFloatingIP getFloatingIP(String key) {
175         if (!floatingIPMap.containsKey(key)) {
176             return null;
177         }
178         return floatingIPMap.get(key);
179     }
180
181     public void removeFloatingIP(String key) {
182         floatingIPMap.remove(key);
183     }
184
185     public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
186         if (!floatingIPMap.containsKey(key)) {
187             floatingIPMap.put(key, floatingIP);
188         }
189     }
190
191     /**
192      * This method copies selected fields from the object and returns them
193      * as a new object, suitable for marshaling.
194      *
195      * @param fields
196      *            List of attributes to be extracted
197      * @return an OpenStackPorts object with only the selected fields
198      * populated
199      */
200
201     public NeutronPort extractFields(List<String> fields) {
202         NeutronPort ans = new NeutronPort();
203         Iterator<String> i = fields.iterator();
204         while (i.hasNext()) {
205             String s = i.next();
206             if (s.equals("id")) {
207                 ans.setPortUUID(this.getPortUUID());
208             }
209             if (s.equals("network_id")) {
210                 ans.setNetworkUUID(this.getNetworkUUID());
211             }
212             if (s.equals("name")) {
213                 ans.setName(this.getName());
214             }
215             if (s.equals("admin_state_up")) {
216                 ans.setAdminStateUp(this.getAdminStateUp());
217             }
218             if (s.equals("status")) {
219                 ans.setStatus(this.getStatus());
220             }
221             if (s.equals("mac_address")) {
222                 ans.setMacAddress(this.getMacAddress());
223             }
224             if (s.equals("fixed_ips")) {
225                 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
226                 fixedIPs.addAll(this.getFixedIPs());
227                 ans.setFixedIPs(fixedIPs);
228             }
229             if (s.equals("device_id")) {
230                 ans.setDeviceID(this.getDeviceID());
231             }
232             if (s.equals("device_owner")) {
233                 ans.setDeviceOwner(this.getDeviceOwner());
234             }
235             if (s.equals("tenant_id")) {
236                 ans.setTenantID(this.getTenantID());
237             }
238             if (s.equals("security_groups")) {
239                 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
240                 securityGroups.addAll(this.getSecurityGroups());
241                 ans.setSecurityGroups(securityGroups);
242             }
243         }
244         return ans;
245     }
246
247     public void initDefaults() {
248         adminStateUp = true;
249         if (status == null) {
250             status = "ACTIVE";
251         }
252         if (fixedIPs == null) {
253             fixedIPs = new ArrayList<Neutron_IPs>();
254         }
255     }
256
257     /**
258      * This method checks to see if the port has a floating IPv4 address
259      * associated with the supplied fixed IPv4 address
260      *
261      * @param fixedIP
262      *            fixed IPv4 address in dotted decimal format
263      * @return a boolean indicating if there is a floating IPv4 address bound
264      * to the fixed IPv4 address
265      */
266
267     public boolean isBoundToFloatingIP(String fixedIP) {
268         return floatingIPMap.containsKey(fixedIP);
269     }
270
271     @Override
272     public String toString() {
273         return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
274                 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
275                 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
276                 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups + "]";
277     }
278 }