blob: 50afdf3a1e9c9671c5230ebc84e78d618904e090 [file] [log] [blame]
sanghoshin94872a12015-10-16 18:04:34 +09001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.openstackswitching;
17
18import com.google.common.collect.Lists;
19import org.onlab.packet.Ip4Address;
20import org.onlab.packet.MacAddress;
21
sanghoshin46297d22015-11-03 17:51:24 +090022import java.util.Collections;
sanghoshin94872a12015-10-16 18:04:34 +090023import java.util.HashMap;
24import java.util.List;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * It represents the Openstack Port information.
30 */
31public final class OpenstackPort {
32
33 public enum PortStatus {
34 UP,
35 DOWN
36 }
37
38 private PortStatus status;
39 private String name;
40 // FIX_ME
41 private String allowedAddressPairs;
42 private boolean adminStateUp;
43 private String networkId;
44 private String tenantId;
45 private String deviceOwner;
46 private MacAddress macAddress;
47 // <subnet id, ip address>
48 private HashMap<String, Ip4Address> fixedIps;
49 private String id;
50 private List<String> securityGroups;
51 private String deviceId;
52
53 private OpenstackPort(PortStatus status, String name, boolean adminStateUp,
54 String networkId, String tenantId, String deviceOwner,
55 MacAddress macAddress, HashMap fixedIps, String id,
56 List<String> securityGroups, String deviceId) {
57
58 this.status = status;
59 this.name = name;
60 this.adminStateUp = adminStateUp;
61 this.networkId = checkNotNull(networkId);
62 this.tenantId = checkNotNull(tenantId);
63 this.deviceOwner = deviceOwner;
64 this.macAddress = checkNotNull(macAddress);
65 this.fixedIps = checkNotNull(fixedIps);
66 this.id = checkNotNull(id);
67 this.securityGroups = securityGroups;
68 this.deviceId = deviceId;
69 }
70
71
72
73 /**
74 * Returns OpenstackPort builder object.
75 *
76 * @return OpenstackPort builder
77 */
78 public static OpenstackPort.Builder builder() {
79 return new Builder();
80 }
81
82 /**
83 * Returns port status.
84 *
85 * @return port status
86 */
87 public PortStatus status() {
88 return status;
89 }
90
91 /**
92 * Returns port name.
93 *
94 * @return port name
95 */
96 public String name() {
97 return name;
98 }
99
100 /**
101 * Returns whether admin state up or not.
102 *
103 * @return true if admin state up, false otherwise
104 */
105 public boolean isAdminStateUp() {
106 return adminStateUp;
107 }
108
109 /**
110 * Returns network ID.
111 *
112 * @return network ID
113 */
114 public String networkId() {
115 return networkId;
116 }
117
118 /**
119 * Returns device owner.
120 *
121 * @return device owner
122 */
123 public String deviceOwner() {
124 return deviceOwner;
125 }
126
127 /**
128 * Returns mac address.
129 *
130 * @return mac address
131 */
132 public MacAddress macAddress() {
133 return macAddress;
134 }
135
136 /**
137 * Returns the fixed IP information.
138 *
139 * @return fixed IP info
140 */
141 public HashMap fixedIps() {
142 return fixedIps;
143 }
144
145 /**
146 * Returns port ID.
147 *
148 * @return port ID
149 */
150 public String id() {
151 return id;
152 }
153
154 /**
155 * Returns security group information.
156 *
157 * @return security group info
158 */
159 public List<String> securityGroups() {
160 return securityGroups;
161 }
162
163 /**
164 * Returns device ID.
165 *
166 * @return device ID
167 */
168 public String deviceId() {
169 return deviceId;
170 }
171
172 // TODO : Implement the following functions when necessary
173 //@Override
174 //public void equals(Object that) {
175 //
176 //}
177 //
178 //@Override
179 //public int hashCode() {
180 //
181 //}
182
sanghoshin46297d22015-11-03 17:51:24 +0900183 @Override
184 public Object clone() {
185 OpenstackPort op = new OpenstackPort(this.status, this.name, this.adminStateUp,
186 this.networkId, this.tenantId, this.deviceOwner, this.macAddress,
187 (HashMap) this.fixedIps.clone(), this.id,
188 Collections.unmodifiableList(this.securityGroups), this.deviceId);
189
190 return op;
191 }
192
sanghoshin94872a12015-10-16 18:04:34 +0900193 /**
194 * OpenstackPort Builder class.
195 */
196 public static final class Builder {
197
198 private PortStatus status;
199 private String name;
200 // FIX_ME
201 private String allowedAddressPairs;
202 private boolean adminStateUp;
203 private String networkId;
204 private String tenantId;
205 private String deviceOwner;
206 private MacAddress macAddress;
207 // list of hash map <subnet id, ip address>
208 private HashMap<String, Ip4Address> fixedIps;
209 private String id;
210 private List<String> securityGroups;
211 private String deviceId;
212
213 Builder() {
214 fixedIps = new HashMap<>();
215 securityGroups = Lists.newArrayList();
216 }
217
218 /**
219 * Sets port status.
220 *
221 * @param status port status
222 * @return Builder object
223 */
224 public Builder portStatus(PortStatus status) {
225 this.status = status;
226
227 return this;
228 }
229
230 /**
231 * Sets port name.
232 *
233 * @param name port name
234 * @return Builder object
235 */
236 public Builder name(String name) {
237 this.name = name;
238
239 return this;
240 }
241
242 /**
243 * Sets whether admin state up or not.
244 *
245 * @param isAdminStateUp true if admin state is up, false otherwise
246 * @return Builder object
247 */
248 public Builder adminState(boolean isAdminStateUp) {
249 this.adminStateUp = isAdminStateUp;
250
251 return this;
252 }
253
254 /**
255 * Sets network ID.
256 *
257 * @param networkId network ID
258 * @return Builder object
259 */
260 public Builder netwrokId(String networkId) {
261 this.networkId = networkId;
262
263 return this;
264 }
265
266 /**
267 * Sets tenant ID.
268 *
269 * @param tenantId tenant ID
270 * @return Builder object
271 */
272 public Builder tenantId(String tenantId) {
273 this.tenantId = tenantId;
274
275 return this;
276 }
277
278 /**
279 * Sets device owner.
280 *
281 * @param owner device owner
282 * @return Builder object
283 */
284 public Builder deviceOwner(String owner) {
285 this.deviceOwner = owner;
286
287 return this;
288 }
289
290 /**
291 * Sets MAC address of the port.
292 *
293 * @param mac MAC address
294 * @return Builder object
295 */
296 public Builder macAddress(MacAddress mac) {
297 this.macAddress = mac;
298
299 return this;
300 }
301
302 /**
303 * Sets Fixed IP address information.
304 *
305 * @param fixedIpList Fixed IP info
306 * @return Builder object
307 */
308 public Builder fixedIps(HashMap<String, Ip4Address> fixedIpList) {
309 fixedIps.putAll(fixedIpList);
310
311 return this;
312 }
313
314 /**
315 * Sets ID of the port.
316 *
317 * @param id ID of the port
318 * @return Builder object
319 */
320 public Builder id(String id) {
321 this.id = id;
322
323 return this;
324 }
325
326 /**
327 * Sets security group of the port.
328 *
329 * @param securityGroup security group of the port
330 * @return Builder object
331 */
332 public Builder securityGroup(String securityGroup) {
333 securityGroups.add(securityGroup);
334
335 return this;
336 }
337
338 /**
339 * Sets device ID of the port.
340 *
341 * @param deviceId device ID
342 * @return Builder object
343 */
344 public Builder deviceId(String deviceId) {
345 this.deviceId = deviceId;
346
347 return this;
348 }
349
350 /**
351 * Builds an OpenstackPort object.
352 *
353 * @return OpenstackPort objecet
354 */
355 public OpenstackPort build() {
356 return new OpenstackPort(status, name, adminStateUp, networkId, networkId,
357 deviceOwner, macAddress, fixedIps, id, securityGroups, deviceId);
358 }
359 }
360}
361