Merge "Logger on neutron model"
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronPort.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation and others.  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.neutron.spi;
10
11
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17
18 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
19 import javax.xml.bind.annotation.XmlAccessType;
20 import javax.xml.bind.annotation.XmlAccessorType;
21 import javax.xml.bind.annotation.XmlElement;
22 import javax.xml.bind.annotation.XmlRootElement;
23
24
25 @XmlRootElement
26 @XmlAccessorType(XmlAccessType.NONE)
27 public class NeutronPort extends NeutronObject 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 = "network_id")
34     String networkUUID;
35
36     @XmlElement (name = "name")
37     String name;
38
39     @XmlElement (defaultValue = "true", name = "admin_state_up")
40     Boolean adminStateUp;
41
42     @XmlElement (name = "status")
43     String status;
44
45     @XmlElement (name = "mac_address")
46     String macAddress;
47
48     @XmlElement (name = "fixed_ips")
49     List<Neutron_IPs> fixedIPs;
50
51     @XmlElement (name = "device_id")
52     String deviceID;
53
54     @XmlElement (name = "device_owner")
55     String deviceOwner;
56
57     @XmlElement (name = "security_groups")
58     List<NeutronSecurityGroup> securityGroups;
59
60     @XmlElement (name = "allowed_address_pairs")
61     List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
62
63     //@XmlElement (name = "binding:host_id")
64     @XmlElement (namespace = "binding", name = "host_id")
65     String bindinghostID;
66
67     //@XmlElement (name = "binding:vnic_type")
68     @XmlElement (namespace = "binding", name = "vnic_type")
69     String bindingvnicType;
70
71     //@XmlElement (name = "binding:vif_type")
72     @XmlElement (namespace = "binding", name = "vif_type")
73     String bindingvifType;
74
75     //@XmlElement (name = "binding:vif_details")
76     @XmlElement (namespace = "binding", name = "vif_details")
77     @XmlJavaTypeAdapter(NeutronResourceMapPropertyAdapter.class)
78     Map<String, String> vifDetails;
79
80     @XmlElement (name = "extra_dhcp_opts")
81     List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
82
83     //Port security is enabled by default for backward compatibility.
84     @XmlElement (defaultValue = "true", name = "port_security_enabled")
85     Boolean portSecurityEnabled;
86
87     public NeutronPort() {
88     }
89
90     public String getNetworkUUID() {
91         return networkUUID;
92     }
93
94     public void setNetworkUUID(String networkUUID) {
95         this.networkUUID = networkUUID;
96     }
97
98     public String getName() {
99         return name;
100     }
101
102     public void setName(String name) {
103         this.name = name;
104     }
105
106     public boolean isAdminStateUp() {
107         if (adminStateUp == null) {
108             return true;
109         }
110         return adminStateUp;
111     }
112
113     public Boolean getAdminStateUp() { return adminStateUp; }
114
115     public void setAdminStateUp(Boolean newValue) {
116         adminStateUp = newValue;
117     }
118
119     public String getStatus() {
120         return status;
121     }
122
123     public void setStatus(String status) {
124         this.status = status;
125     }
126
127     public String getMacAddress() {
128         return macAddress;
129     }
130
131     public void setMacAddress(String macAddress) {
132         this.macAddress = macAddress;
133     }
134
135     public List<Neutron_IPs> getFixedIPs() {
136         return fixedIPs;
137     }
138
139     public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
140         this.fixedIPs = fixedIPs;
141     }
142
143     public String getDeviceID() {
144         return deviceID;
145     }
146
147     public void setDeviceID(String deviceID) {
148         this.deviceID = deviceID;
149     }
150
151     public String getDeviceOwner() {
152         return deviceOwner;
153     }
154
155     public void setDeviceOwner(String deviceOwner) {
156         this.deviceOwner = deviceOwner;
157     }
158
159     public List<NeutronSecurityGroup> getSecurityGroups() {
160         return securityGroups;
161     }
162
163     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
164         this.securityGroups = securityGroups;
165     }
166
167     public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
168         return allowedAddressPairs;
169     }
170
171     public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
172         this.allowedAddressPairs = allowedAddressPairs;
173     }
174
175     public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
176         return extraDHCPOptions;
177     }
178
179     public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
180         this.extraDHCPOptions = extraDHCPOptions;
181     }
182
183     public Map<String, String> getVIFDetails() {
184         return vifDetails;
185     }
186
187     public void setVIFDetails(Map<String, String> vifDetails) {
188         this.vifDetails = vifDetails;
189     }
190
191     public String getBindinghostID() {
192         return bindinghostID;
193     }
194
195     public void setBindinghostID(String bindinghostID) {
196         this.bindinghostID = bindinghostID;
197     }
198
199     public String getBindingvnicType() {
200         return bindingvnicType;
201     }
202
203     public void setBindingvnicType(String bindingvnicType) {
204         this.bindingvnicType = bindingvnicType;
205     }
206
207     public String getBindingvifType() {
208         return bindingvifType;
209     }
210
211     public void setBindingvifType(String bindingvifType) {
212         this.bindingvifType = bindingvifType;
213     }
214
215     public Boolean getPortSecurityEnabled() {
216         if (portSecurityEnabled == null) {
217             return true;
218         }
219         return portSecurityEnabled;
220     }
221
222     public void setPortSecurityEnabled(Boolean newValue) {
223         portSecurityEnabled = newValue;
224     }
225
226     /**
227      * This method copies selected fields from the object and returns them
228      * as a new object, suitable for marshaling.
229      *
230      * @param fields
231      *            List of attributes to be extracted
232      * @return an OpenStackPorts object with only the selected fields
233      * populated
234      */
235
236     public NeutronPort extractFields(List<String> fields) {
237         NeutronPort ans = new NeutronPort();
238         for (String field: fields) {
239             if ("id".equals(field)) {
240                 ans.setID(this.getID());
241             }
242             if ("tenant_id".equals(field)) {
243                 ans.setTenantID(this.getTenantID());
244             }
245             if ("network_id".equals(field)) {
246                 ans.setNetworkUUID(this.getNetworkUUID());
247             }
248             if ("name".equals(field)) {
249                 ans.setName(this.getName());
250             }
251             if ("admin_state_up".equals(field)) {
252                 ans.setAdminStateUp(this.getAdminStateUp());
253             }
254             if ("status".equals(field)) {
255                 ans.setStatus(this.getStatus());
256             }
257             if ("mac_address".equals(field)) {
258                 ans.setMacAddress(this.getMacAddress());
259             }
260             if ("fixed_ips".equals(field)) {
261                 ans.setFixedIPs(new ArrayList<Neutron_IPs>(this.getFixedIPs()));
262             }
263             if ("device_id".equals(field)) {
264                 ans.setDeviceID(this.getDeviceID());
265             }
266             if ("device_owner".equals(field)) {
267                 ans.setDeviceOwner(this.getDeviceOwner());
268             }
269             if ("security_groups".equals(field)) {
270                 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
271             }
272             if ("allowed_address_pairs".equals(field)) {
273                 ans.setAllowedAddressPairs(new ArrayList<NeutronPort_AllowedAddressPairs>(this.getAllowedAddressPairs()));
274             }
275             if ("binding:host_id".equals(field)) {
276                 ans.setBindinghostID(this.getBindinghostID());
277             }
278             if ("binding:vnic_type".equals(field)) {
279                 ans.setBindingvnicType(this.getBindingvnicType());
280             }
281             if ("binding:vif_type".equals(field)) {
282                 ans.setBindingvifType(this.getBindingvifType());
283             }
284             if ("binding:vif_details".equals(field)) {
285                 ans.setVIFDetails(new HashMap<String, String>(this.getVIFDetails()));
286             }
287             if ("extra_dhcp_opts".equals(field)) {
288                 ans.setExtraDHCPOptions(new ArrayList<NeutronPort_ExtraDHCPOption>(this.getExtraDHCPOptions()));
289             }
290             if ("port_security_enabled".equals(field)) {
291                 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
292             }
293         }
294         return ans;
295     }
296
297     @Override
298     public void initDefaults() {
299         adminStateUp = true;
300         portSecurityEnabled = true;
301         if (status == null) {
302             status = "ACTIVE";
303         }
304         if (fixedIPs == null) {
305             fixedIPs = new ArrayList<Neutron_IPs>();
306         }
307     }
308
309     @Override
310     public String toString() {
311         return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name
312                 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
313                 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
314                 + tenantID + ", securityGroups=" + securityGroups
315                 + ", allowedAddressPairs" + allowedAddressPairs
316                 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
317                 + ", bindingvifType=" + bindingvifType
318                 + ", vifDetails=" + vifDetails
319                 + ", extraDHCPOptions=" + extraDHCPOptions
320                 + ", portSecurityEnabled=" + portSecurityEnabled +"]";
321     }
322 }