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