blob: b746b6c167db824e0db52fa20aaf826b4d1a5fc7 [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,
sanghoshinf25d2e02015-11-11 23:07:17 +090035 DOWN,
sanghoshinc5827d52015-12-11 12:52:02 +090036 ACTIVE,
37 NA,
sanghoshin94872a12015-10-16 18:04:34 +090038 }
39
40 private PortStatus status;
41 private String name;
42 // FIX_ME
43 private String allowedAddressPairs;
44 private boolean adminStateUp;
45 private String networkId;
46 private String tenantId;
47 private String deviceOwner;
48 private MacAddress macAddress;
49 // <subnet id, ip address>
50 private HashMap<String, Ip4Address> fixedIps;
51 private String id;
52 private List<String> securityGroups;
53 private String deviceId;
54
55 private OpenstackPort(PortStatus status, String name, boolean adminStateUp,
56 String networkId, String tenantId, String deviceOwner,
57 MacAddress macAddress, HashMap fixedIps, String id,
58 List<String> securityGroups, String deviceId) {
59
60 this.status = status;
61 this.name = name;
62 this.adminStateUp = adminStateUp;
63 this.networkId = checkNotNull(networkId);
64 this.tenantId = checkNotNull(tenantId);
65 this.deviceOwner = deviceOwner;
66 this.macAddress = checkNotNull(macAddress);
67 this.fixedIps = checkNotNull(fixedIps);
68 this.id = checkNotNull(id);
69 this.securityGroups = securityGroups;
70 this.deviceId = deviceId;
71 }
72
73
74
75 /**
76 * Returns OpenstackPort builder object.
77 *
78 * @return OpenstackPort builder
79 */
80 public static OpenstackPort.Builder builder() {
81 return new Builder();
82 }
83
84 /**
85 * Returns port status.
86 *
87 * @return port status
88 */
89 public PortStatus status() {
90 return status;
91 }
92
93 /**
94 * Returns port name.
95 *
96 * @return port name
97 */
98 public String name() {
99 return name;
100 }
101
102 /**
103 * Returns whether admin state up or not.
104 *
105 * @return true if admin state up, false otherwise
106 */
107 public boolean isAdminStateUp() {
108 return adminStateUp;
109 }
110
111 /**
112 * Returns network ID.
113 *
114 * @return network ID
115 */
116 public String networkId() {
117 return networkId;
118 }
119
120 /**
121 * Returns device owner.
122 *
123 * @return device owner
124 */
125 public String deviceOwner() {
126 return deviceOwner;
127 }
128
129 /**
130 * Returns mac address.
131 *
132 * @return mac address
133 */
134 public MacAddress macAddress() {
135 return macAddress;
136 }
137
138 /**
139 * Returns the fixed IP information.
140 *
141 * @return fixed IP info
142 */
143 public HashMap fixedIps() {
144 return fixedIps;
145 }
146
147 /**
148 * Returns port ID.
149 *
150 * @return port ID
151 */
152 public String id() {
153 return id;
154 }
155
156 /**
157 * Returns security group information.
158 *
159 * @return security group info
160 */
161 public List<String> securityGroups() {
162 return securityGroups;
163 }
164
165 /**
166 * Returns device ID.
167 *
168 * @return device ID
169 */
170 public String deviceId() {
171 return deviceId;
172 }
173
174 // TODO : Implement the following functions when necessary
175 //@Override
176 //public void equals(Object that) {
177 //
178 //}
179 //
180 //@Override
181 //public int hashCode() {
182 //
183 //}
184
sanghoshin46297d22015-11-03 17:51:24 +0900185 @Override
186 public Object clone() {
187 OpenstackPort op = new OpenstackPort(this.status, this.name, this.adminStateUp,
188 this.networkId, this.tenantId, this.deviceOwner, this.macAddress,
189 (HashMap) this.fixedIps.clone(), this.id,
190 Collections.unmodifiableList(this.securityGroups), this.deviceId);
191
192 return op;
193 }
194
sanghoshin94872a12015-10-16 18:04:34 +0900195 /**
196 * OpenstackPort Builder class.
197 */
198 public static final class Builder {
199
200 private PortStatus status;
201 private String name;
202 // FIX_ME
203 private String allowedAddressPairs;
204 private boolean adminStateUp;
205 private String networkId;
206 private String tenantId;
207 private String deviceOwner;
208 private MacAddress macAddress;
209 // list of hash map <subnet id, ip address>
210 private HashMap<String, Ip4Address> fixedIps;
211 private String id;
212 private List<String> securityGroups;
213 private String deviceId;
214
215 Builder() {
216 fixedIps = new HashMap<>();
217 securityGroups = Lists.newArrayList();
218 }
219
220 /**
221 * Sets port status.
222 *
223 * @param status port status
224 * @return Builder object
225 */
226 public Builder portStatus(PortStatus status) {
227 this.status = status;
228
229 return this;
230 }
231
232 /**
233 * Sets port name.
234 *
235 * @param name port name
236 * @return Builder object
237 */
238 public Builder name(String name) {
239 this.name = name;
240
241 return this;
242 }
243
244 /**
245 * Sets whether admin state up or not.
246 *
247 * @param isAdminStateUp true if admin state is up, false otherwise
248 * @return Builder object
249 */
250 public Builder adminState(boolean isAdminStateUp) {
251 this.adminStateUp = isAdminStateUp;
252
253 return this;
254 }
255
256 /**
257 * Sets network ID.
258 *
259 * @param networkId network ID
260 * @return Builder object
261 */
262 public Builder netwrokId(String networkId) {
263 this.networkId = networkId;
264
265 return this;
266 }
267
268 /**
269 * Sets tenant ID.
270 *
271 * @param tenantId tenant ID
272 * @return Builder object
273 */
274 public Builder tenantId(String tenantId) {
275 this.tenantId = tenantId;
276
277 return this;
278 }
279
280 /**
281 * Sets device owner.
282 *
283 * @param owner device owner
284 * @return Builder object
285 */
286 public Builder deviceOwner(String owner) {
287 this.deviceOwner = owner;
288
289 return this;
290 }
291
292 /**
293 * Sets MAC address of the port.
294 *
295 * @param mac MAC address
296 * @return Builder object
297 */
298 public Builder macAddress(MacAddress mac) {
299 this.macAddress = mac;
300
301 return this;
302 }
303
304 /**
305 * Sets Fixed IP address information.
306 *
307 * @param fixedIpList Fixed IP info
308 * @return Builder object
309 */
310 public Builder fixedIps(HashMap<String, Ip4Address> fixedIpList) {
311 fixedIps.putAll(fixedIpList);
312
313 return this;
314 }
315
316 /**
317 * Sets ID of the port.
318 *
319 * @param id ID of the port
320 * @return Builder object
321 */
322 public Builder id(String id) {
323 this.id = id;
324
325 return this;
326 }
327
328 /**
329 * Sets security group of the port.
330 *
331 * @param securityGroup security group of the port
332 * @return Builder object
333 */
334 public Builder securityGroup(String securityGroup) {
335 securityGroups.add(securityGroup);
336
337 return this;
338 }
339
340 /**
341 * Sets device ID of the port.
342 *
343 * @param deviceId device ID
344 * @return Builder object
345 */
346 public Builder deviceId(String deviceId) {
347 this.deviceId = deviceId;
348
349 return this;
350 }
351
352 /**
353 * Builds an OpenstackPort object.
354 *
355 * @return OpenstackPort objecet
356 */
357 public OpenstackPort build() {
358 return new OpenstackPort(status, name, adminStateUp, networkId, networkId,
359 deviceOwner, macAddress, fixedIps, id, securityGroups, deviceId);
360 }
361 }
362}
363