28057dda2bbae8f74d0dbfdb9e90aaf2df038f47
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronBgpvpn.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.List;
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 @XmlRootElement(name = "bgpvpn")
21 @XmlAccessorType(XmlAccessType.NONE)
22 public final class NeutronBgpvpn extends NeutronAdminAttributes<NeutronBgpvpn> implements Serializable {
23     private static final Logger LOGGER = LoggerFactory.getLogger(NeutronBgpvpn.class);
24     // See OpenStack Network API v2.0 Reference for description of
25     // annotated attributes
26
27     private static final long serialVersionUID = 1L;
28
29     @XmlElement(defaultValue = "l3", name = "type")
30     String type;
31
32     @XmlElement(name = "technique")
33     String technique;
34
35     @XmlElement(name = "route_targets")
36     List<String> routeTargets;
37
38     @XmlElement(name = "import_targets")
39     List<String> importTargets;
40
41     @XmlElement(name = "export_targets")
42     List<String> exportTargets;
43
44     @XmlElement(name = "route_distinguishers")
45     List<String> routeDistinguishers;
46
47     @XmlElement(name = "vnid")
48     Long vnid;
49
50     @XmlElement(defaultValue = "false", name = "auto_aggregate")
51     Boolean autoAggregate;
52
53     @XmlElement(name = "networks")
54     List<String> networks;
55
56     @XmlElement(name = "routers")
57     List<String> routers;
58
59     /* This attribute lists the ports associated with an instance
60      * which is needed for determining if that instance can be deleted
61      */
62
63     public NeutronBgpvpn() {
64     }
65
66     public void initDefaults() {
67         super.initDefaults();
68         if (type == null) {
69             type = "l3";
70         }
71         if (autoAggregate == null) {
72             autoAggregate = false;
73         }
74     }
75
76     public boolean isAdminStateUp() {
77         return adminStateUp;
78     }
79
80     public boolean isAutoAggregate() {
81         return autoAggregate;
82     }
83
84     public String getType() {
85         return type;
86     }
87
88     public void setType(String type) {
89         this.type = type;
90     }
91
92     public String getTechnique() {
93         return technique;
94     }
95
96     public void setTechnique(String technique) {
97         this.technique = technique;
98     }
99
100     public List<String> getRouteTargets() {
101         return routeTargets;
102     }
103
104     public void setRouteTargets(List<String> routeTargets) {
105         this.routeTargets = routeTargets;
106     }
107
108     public void addRouteTarget(String uuid) {
109         routeTargets.add(uuid);
110     }
111
112     public void removeRouteTarget(String uuid) {
113         routeTargets.remove(uuid);
114     }
115
116     public List<String> getImportTargets() {
117         return importTargets;
118     }
119
120     public void setImportTargets(List<String> importTargets) {
121         this.importTargets = importTargets;
122     }
123
124     public void addImportTarget(String uuid) {
125         importTargets.add(uuid);
126     }
127
128     public void removeImportTarget(String uuid) {
129         importTargets.remove(uuid);
130     }
131
132     public List<String> getExportTargets() {
133         return exportTargets;
134     }
135
136     public void setExportTargets(List<String> exportTargets) {
137         this.exportTargets = exportTargets;
138     }
139
140     public void addExportTarget(String uuid) {
141         exportTargets.add(uuid);
142     }
143
144     public void removeExportTarget(String uuid) {
145         exportTargets.remove(uuid);
146     }
147
148     public List<String> getRouteDistinguishers() {
149         return routeDistinguishers;
150     }
151
152     public void setRouteDistinguishers(List<String> routeDistinguishers) {
153         this.routeDistinguishers = routeDistinguishers;
154     }
155
156     public void addRouteDistinguisher(String uuid) {
157         routeDistinguishers.add(uuid);
158     }
159
160     public void removeRouteDistinguisher(String uuid) {
161         routeDistinguishers.remove(uuid);
162     }
163
164     public Long getVnid() {
165         return vnid;
166     }
167
168     public void setVnid(Long input) {
169         vnid = input;
170     }
171
172     public Boolean getAutoAggregate() {
173         return autoAggregate;
174     }
175
176     public void setAutoAggregate(boolean newValue) {
177         autoAggregate = newValue;
178     }
179
180     public List<String> getNetworks() {
181         return networks;
182     }
183
184     public void setNetworks(List<String> networks) {
185         this.networks = networks;
186     }
187
188     public void addNetwork(String uuid) {
189         networks.add(uuid);
190     }
191
192     public void removeNetwork(String uuid) {
193         networks.remove(uuid);
194     }
195
196     public List<String> getRouters() {
197         return routers;
198     }
199
200     public void setRouters(List<String> routers) {
201         this.routers = routers;
202     }
203
204     public void addRouter(String uuid) {
205         routers.add(uuid);
206     }
207
208     public void removeRouter(String uuid) {
209         routers.remove(uuid);
210     }
211
212     /**
213      * This method copies selected fields from the object and returns them
214      * as a new object, suitable for marshaling.
215      *
216      * @param fields
217      *            List of attributes to be extracted
218      * @return an OpenStackNetworks object with only the selected fields
219      *             populated
220      */
221
222     public NeutronBgpvpn extractFields(List<String> fields) {
223         NeutronBgpvpn ans = new NeutronBgpvpn();
224         for (String s : fields) {
225             if (extractField(s, ans)) {
226                 continue;
227             }
228             switch (s) {
229                 case "type":
230                     ans.setType(this.getType());
231                     break;
232                 case "technique":
233                     ans.setTechnique(this.getTechnique());
234                     break;
235                 case "route_targets":
236                     ans.setRouteTargets(this.getRouteTargets());
237                     break;
238                 case "import_targets":
239                     ans.setImportTargets(this.getImportTargets());
240                     break;
241                 case "export_targets":
242                     ans.setExportTargets(this.getExportTargets());
243                     break;
244                 case "route_distinguishe":
245                     ans.setRouteDistinguishers(this.getRouteDistinguishers());
246                     break;
247                 case "routers":
248                     ans.setRouters(this.getRouters());
249                     break;
250                 case "networks":
251                     ans.setNetworks(this.getNetworks());
252                     break;
253                 case "vnid":
254                     ans.setVnid(this.getVnid());
255                     break;
256                 case "auto_aggregate":
257                     ans.setAutoAggregate(this.getAutoAggregate());
258                     break;
259                 default:
260                     LOGGER.warn("{} is not a NeutronBgpvpn suitable field.", s);
261                     break;
262             }
263         }
264         return ans;
265     }
266
267     @Override
268     public String toString() {
269         return "NeutronBgpvpn [bgpvpnUUID=" + uuid + ", bgpvpnName=" + name + ", adminStateUp=" + adminStateUp
270                 + ", status=" + status + ", tenantID=" + tenantID + ", type=" + type + ", technique=" + technique
271                 + ", routeTargets=" + routeTargets + ", importTargets=" + importTargets + ", exportTargets="
272                 + exportTargets + ", routeDistinguishers=" + routeDistinguishers + ", vnid = " + vnid
273                 + ", autoAggregate = " + autoAggregate + ", networks = " + networks + ", routers = " + routers + "]";
274     }
275 }