blob: f9a5916a9d23df4c09f46d943124de0843ee65f9 [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
sanghoshin94872a12015-10-16 18:04:34 +090018import org.onlab.packet.Ip4Address;
19import org.onlab.packet.MacAddress;
20
sangho5db8e052016-01-29 16:08:23 +090021import java.util.Collection;
sanghoshin46297d22015-11-03 17:51:24 +090022import java.util.Collections;
sanghoshin94872a12015-10-16 18:04:34 +090023import java.util.HashMap;
sanghoshin94872a12015-10-16 18:04:34 +090024
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * It represents the Openstack Port information.
29 */
30public final class OpenstackPort {
31
32 public enum PortStatus {
33 UP,
sanghoshinf25d2e02015-11-11 23:07:17 +090034 DOWN,
sanghoshinc5827d52015-12-11 12:52:02 +090035 ACTIVE,
36 NA,
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;
sangho5db8e052016-01-29 16:08:23 +090051 private Collection<String> securityGroups;
sanghoshin94872a12015-10-16 18:04:34 +090052 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,
sangho5db8e052016-01-29 16:08:23 +090057 Collection<String> securityGroups, String deviceId) {
sanghoshin94872a12015-10-16 18:04:34 +090058
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 */
sangho5db8e052016-01-29 16:08:23 +0900160 public Collection<String> securityGroups() {
sanghoshin94872a12015-10-16 18:04:34 +0900161 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,
sangho5db8e052016-01-29 16:08:23 +0900189 Collections.unmodifiableCollection(this.securityGroups), this.deviceId);
sanghoshin46297d22015-11-03 17:51:24 +0900190
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;
sangho5db8e052016-01-29 16:08:23 +0900211 private Collection<String> securityGroups;
sanghoshin94872a12015-10-16 18:04:34 +0900212 private String deviceId;
213
214 Builder() {
215 fixedIps = new HashMap<>();
sanghoshin94872a12015-10-16 18:04:34 +0900216 }
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 *
sangho5db8e052016-01-29 16:08:23 +0900329 * @param securityGroupList security group list of the port
sanghoshin94872a12015-10-16 18:04:34 +0900330 * @return Builder object
331 */
sangho5db8e052016-01-29 16:08:23 +0900332 public Builder securityGroup(Collection<String> securityGroupList) {
333 this.securityGroups = securityGroupList;
sanghoshin94872a12015-10-16 18:04:34 +0900334 return this;
335 }
336
337 /**
338 * Sets device ID of the port.
339 *
340 * @param deviceId device ID
341 * @return Builder object
342 */
343 public Builder deviceId(String deviceId) {
344 this.deviceId = deviceId;
345
346 return this;
347 }
348
349 /**
350 * Builds an OpenstackPort object.
351 *
352 * @return OpenstackPort objecet
353 */
354 public OpenstackPort build() {
355 return new OpenstackPort(status, name, adminStateUp, networkId, networkId,
356 deviceOwner, macAddress, fixedIps, id, securityGroups, deviceId);
357 }
358 }
359}
360