b36cbf5699e3a8bf09cf77157e01ce3bf784dfb7
[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 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
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 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
21
22 @XmlRootElement
23 @XmlAccessorType(XmlAccessType.NONE)
24 public final class NeutronPort extends NeutronAdminAttributes<NeutronPort> implements Serializable {
25     private static final long serialVersionUID = 1L;
26
27     // See OpenStack Network API v2.0 Reference for description of
28     // annotated attributes
29
30     @XmlElement(name = "network_id")
31     String networkUUID;
32
33     @XmlElement(name = "mac_address")
34     String macAddress;
35
36     @XmlElement(name = "fixed_ips")
37     List<NeutronIps> fixedIps;
38
39     @XmlElement(name = "device_id")
40     String deviceID;
41
42     @XmlElement(name = "device_owner")
43     String deviceOwner;
44
45     @XmlElement(name = "security_groups")
46     List<NeutronSecurityGroup> securityGroups;
47
48     @XmlElement(name = "allowed_address_pairs")
49     List<NeutronPortAllowedAddressPairs> allowedAddressPairs;
50
51     //@XmlElement (name = "binding:host_id")
52     @XmlElement(namespace = "binding", name = "host_id")
53     String bindinghostID;
54
55     //@XmlElement (name = "binding:vnic_type")
56     @XmlElement(namespace = "binding", name = "vnic_type")
57     String bindingvnicType;
58
59     //@XmlElement (name = "binding:vif_type")
60     @XmlElement(namespace = "binding", name = "vif_type")
61     String bindingvifType;
62
63     //@XmlElement (name = "binding:vif_details")
64     @XmlElement(namespace = "binding", name = "vif_details")
65     @XmlJavaTypeAdapter(NeutronResourceMapPropertyAdapter.class)
66     Map<String, String> vifDetails;
67
68     @XmlElement(name = "extra_dhcp_opts")
69     List<NeutronPortExtraDHCPOption> extraDHCPOptions;
70
71     //Port security is enabled by default for backward compatibility.
72     @XmlElement(defaultValue = "true", name = "port_security_enabled")
73     Boolean portSecurityEnabled;
74
75     @XmlElement(name = "qos_policy_id")
76     String qosPolicyId;
77
78     public NeutronPort() {
79     }
80
81     public String getNetworkUUID() {
82         return networkUUID;
83     }
84
85     public void setNetworkUUID(String networkUUID) {
86         this.networkUUID = networkUUID;
87     }
88
89     public boolean isAdminStateUp() {
90         if (adminStateUp == null) {
91             return true;
92         }
93         return adminStateUp;
94     }
95
96     public String getMacAddress() {
97         return macAddress;
98     }
99
100     public void setMacAddress(String macAddress) {
101         this.macAddress = macAddress;
102     }
103
104     public List<NeutronIps> getFixedIps() {
105         return fixedIps;
106     }
107
108     public void setFixedIps(List<NeutronIps> fixedIps) {
109         this.fixedIps = fixedIps;
110     }
111
112     public String getDeviceID() {
113         return deviceID;
114     }
115
116     public void setDeviceID(String deviceID) {
117         this.deviceID = deviceID;
118     }
119
120     public String getDeviceOwner() {
121         return deviceOwner;
122     }
123
124     public void setDeviceOwner(String deviceOwner) {
125         this.deviceOwner = deviceOwner;
126     }
127
128     public List<NeutronSecurityGroup> getSecurityGroups() {
129         return securityGroups;
130     }
131
132     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
133         this.securityGroups = securityGroups;
134     }
135
136     public List<NeutronPortAllowedAddressPairs> getAllowedAddressPairs() {
137         return allowedAddressPairs;
138     }
139
140     public void setAllowedAddressPairs(List<NeutronPortAllowedAddressPairs> allowedAddressPairs) {
141         this.allowedAddressPairs = allowedAddressPairs;
142     }
143
144     public List<NeutronPortExtraDHCPOption> getExtraDHCPOptions() {
145         return extraDHCPOptions;
146     }
147
148     public void setExtraDHCPOptions(List<NeutronPortExtraDHCPOption> extraDHCPOptions) {
149         this.extraDHCPOptions = extraDHCPOptions;
150     }
151
152     public Map<String, String> getVIFDetails() {
153         return vifDetails;
154     }
155
156     public void setVIFDetails(Map<String, String> vifDetails) {
157         this.vifDetails = vifDetails;
158     }
159
160     public String getBindinghostID() {
161         return bindinghostID;
162     }
163
164     public void setBindinghostID(String bindinghostID) {
165         this.bindinghostID = bindinghostID;
166     }
167
168     public String getBindingvnicType() {
169         return bindingvnicType;
170     }
171
172     public void setBindingvnicType(String bindingvnicType) {
173         this.bindingvnicType = bindingvnicType;
174     }
175
176     public String getBindingvifType() {
177         return bindingvifType;
178     }
179
180     public void setBindingvifType(String bindingvifType) {
181         this.bindingvifType = bindingvifType;
182     }
183
184     public Boolean getPortSecurityEnabled() {
185         if (portSecurityEnabled == null) {
186             return true;
187         }
188         return portSecurityEnabled;
189     }
190
191     public String getQosPolicyId() {
192         return qosPolicyId;
193     }
194
195     public void setQosPolicyId(String qosPolicyId) {
196         this.qosPolicyId = qosPolicyId;
197     }
198
199     public void setPortSecurityEnabled(Boolean newValue) {
200         portSecurityEnabled = newValue;
201     }
202
203     @Override
204     protected boolean extractField(String field, NeutronPort ans) {
205         switch (field) {
206             case "network_id":
207                 ans.setNetworkUUID(this.getNetworkUUID());
208                 break;
209             case "mac_address":
210                 ans.setMacAddress(this.getMacAddress());
211                 break;
212             case "fixed_ips":
213                 ans.setFixedIps(new ArrayList<NeutronIps>(this.getFixedIps()));
214                 break;
215             case "device_id":
216                 ans.setDeviceID(this.getDeviceID());
217                 break;
218             case "device_owner":
219                 ans.setDeviceOwner(this.getDeviceOwner());
220                 break;
221             case "security_groups":
222                 ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
223                 break;
224             case "allowed_address_pairs":
225                 ans.setAllowedAddressPairs(
226                         new ArrayList<NeutronPortAllowedAddressPairs>(this.getAllowedAddressPairs()));
227                 break;
228             case "binding:host_id":
229                 ans.setBindinghostID(this.getBindinghostID());
230                 break;
231             case "binding:vnic_type":
232                 ans.setBindingvnicType(this.getBindingvnicType());
233                 break;
234             case "binding:vif_type":
235                 ans.setBindingvifType(this.getBindingvifType());
236                 break;
237             case "binding:vif_details":
238                 ans.setVIFDetails(new HashMap<String, String>(this.getVIFDetails()));
239                 break;
240             case "extra_dhcp_opts":
241                 ans.setExtraDHCPOptions(new ArrayList<NeutronPortExtraDHCPOption>(this.getExtraDHCPOptions()));
242                 break;
243             case "port_security_enabled":
244                 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
245                 break;
246             case "qos_policy_id":
247                 ans.setQosPolicyId(this.getQosPolicyId());
248                 break;
249             default:
250                 return super.extractField(field, ans);
251         }
252         return true;
253     }
254
255     @Override
256     public void initDefaults() {
257         super.initDefaults();
258         if (portSecurityEnabled == null) {
259             portSecurityEnabled = true;
260         }
261         if (fixedIps == null) {
262             fixedIps = new ArrayList<NeutronIps>();
263         }
264     }
265
266     @Override
267     public String toString() {
268         return "NeutronPort [portUUID=" + uuid + ", networkUUID=" + networkUUID + ", name=" + name + ", adminStateUp="
269                 + adminStateUp + ", status=" + status + ", macAddress=" + macAddress + ", fixedIps=" + fixedIps
270                 + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID=" + tenantID
271                 + ", securityGroups=" + securityGroups + ", allowedAddressPairs" + allowedAddressPairs
272                 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType + ", bindingvifType="
273                 + bindingvifType + ", vifDetails=" + vifDetails + ", extraDHCPOptions=" + extraDHCPOptions
274                 + ", portSecurityEnabled=" + portSecurityEnabled + ", qosPolicyId=" + qosPolicyId + "]";
275     }
276 }