blob: 58ac5831ea2c94f7feb66d66e4bf2608913e47e4 [file] [log] [blame]
sanghoshin94872a12015-10-16 18:04:34 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
sanghoshin94872a12015-10-16 18:04:34 +09003 *
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 */
sangho93447f12016-02-24 00:33:22 +090016package org.onosproject.openstackinterface;
sanghoshin94872a12015-10-16 18:04:34 +090017
Daniel Park23193902016-03-24 18:17:19 +090018import com.google.common.collect.ImmutableMap;
Hyunsun Moon10201322016-02-15 05:00:22 -080019import com.google.common.collect.Maps;
sanghoshin94872a12015-10-16 18:04:34 +090020import org.onlab.packet.Ip4Address;
Hyunsun Moon10201322016-02-15 05:00:22 -080021import org.onlab.packet.IpAddress;
sanghoshin94872a12015-10-16 18:04:34 +090022import org.onlab.packet.MacAddress;
23
sangho5db8e052016-01-29 16:08:23 +090024import java.util.Collection;
Hyunsun Moon10201322016-02-15 05:00:22 -080025import java.util.Map;
sanghoshin94872a12015-10-16 18:04:34 +090026
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
30 * It represents the Openstack Port information.
31 */
32public final class OpenstackPort {
33
34 public enum PortStatus {
35 UP,
sanghoshinf25d2e02015-11-11 23:07:17 +090036 DOWN,
sanghoshinc5827d52015-12-11 12:52:02 +090037 ACTIVE,
38 NA,
sanghoshin94872a12015-10-16 18:04:34 +090039 }
40
41 private PortStatus status;
42 private String name;
Daniel Park23193902016-03-24 18:17:19 +090043 private ImmutableMap<IpAddress, MacAddress> allowedAddressPairs;
sanghoshin94872a12015-10-16 18:04:34 +090044 private boolean adminStateUp;
45 private String networkId;
46 private String tenantId;
47 private String deviceOwner;
48 private MacAddress macAddress;
49 // <subnet id, ip address>
Daniel Park23193902016-03-24 18:17:19 +090050 private ImmutableMap<String, Ip4Address> fixedIps;
sanghoshin94872a12015-10-16 18:04:34 +090051 private String id;
sangho5db8e052016-01-29 16:08:23 +090052 private Collection<String> securityGroups;
sanghoshin94872a12015-10-16 18:04:34 +090053 private String deviceId;
54
Hyunsun Moon10201322016-02-15 05:00:22 -080055 private OpenstackPort(PortStatus status, String name, Map<IpAddress, MacAddress> allowedAddressPairs,
56 boolean adminStateUp, String networkId, String tenantId,
Daniel Park23193902016-03-24 18:17:19 +090057 String deviceOwner, MacAddress macAddress, Map<String, Ip4Address> fixedIps,
Hyunsun Moon10201322016-02-15 05:00:22 -080058 String id, Collection<String> securityGroups, String deviceId) {
sanghoshin94872a12015-10-16 18:04:34 +090059 this.status = status;
60 this.name = name;
Daniel Park23193902016-03-24 18:17:19 +090061 this.allowedAddressPairs = checkNotNull(ImmutableMap.copyOf(allowedAddressPairs));
sanghoshin94872a12015-10-16 18:04:34 +090062 this.adminStateUp = adminStateUp;
63 this.networkId = checkNotNull(networkId);
64 this.tenantId = checkNotNull(tenantId);
65 this.deviceOwner = deviceOwner;
66 this.macAddress = checkNotNull(macAddress);
Daniel Park23193902016-03-24 18:17:19 +090067 this.fixedIps = checkNotNull(ImmutableMap.copyOf(fixedIps));
sanghoshin94872a12015-10-16 18:04:34 +090068 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 /**
Hyunsun Moon10201322016-02-15 05:00:22 -0800103 * Returns allowed address pairs.
104 *
105 * @return map of ip address and mac address, or empty map
106 */
107 public Map<IpAddress, MacAddress> allowedAddressPairs() {
108 return allowedAddressPairs;
109 }
110
111 /**
sanghoshin94872a12015-10-16 18:04:34 +0900112 * Returns whether admin state up or not.
113 *
114 * @return true if admin state up, false otherwise
115 */
116 public boolean isAdminStateUp() {
117 return adminStateUp;
118 }
119
120 /**
121 * Returns network ID.
122 *
123 * @return network ID
124 */
125 public String networkId() {
126 return networkId;
127 }
128
129 /**
130 * Returns device owner.
131 *
132 * @return device owner
133 */
134 public String deviceOwner() {
135 return deviceOwner;
136 }
137
138 /**
139 * Returns mac address.
140 *
141 * @return mac address
142 */
143 public MacAddress macAddress() {
144 return macAddress;
145 }
146
147 /**
148 * Returns the fixed IP information.
149 *
150 * @return fixed IP info
151 */
Daniel Park23193902016-03-24 18:17:19 +0900152 public Map<String, Ip4Address> fixedIps() {
sanghoshin94872a12015-10-16 18:04:34 +0900153 return fixedIps;
154 }
155
156 /**
157 * Returns port ID.
158 *
159 * @return port ID
160 */
161 public String id() {
162 return id;
163 }
164
165 /**
166 * Returns security group information.
167 *
168 * @return security group info
169 */
sangho5db8e052016-01-29 16:08:23 +0900170 public Collection<String> securityGroups() {
sanghoshin94872a12015-10-16 18:04:34 +0900171 return securityGroups;
172 }
173
174 /**
175 * Returns device ID.
176 *
177 * @return device ID
178 */
179 public String deviceId() {
180 return deviceId;
181 }
182
sanghoshin94872a12015-10-16 18:04:34 +0900183 /**
184 * OpenstackPort Builder class.
185 */
186 public static final class Builder {
187
188 private PortStatus status;
189 private String name;
Hyunsun Moon10201322016-02-15 05:00:22 -0800190 private Map<IpAddress, MacAddress> allowedAddressPairs;
sanghoshin94872a12015-10-16 18:04:34 +0900191 private boolean adminStateUp;
192 private String networkId;
193 private String tenantId;
194 private String deviceOwner;
195 private MacAddress macAddress;
196 // list of hash map <subnet id, ip address>
Daniel Park23193902016-03-24 18:17:19 +0900197 private Map<String, Ip4Address> fixedIps;
sanghoshin94872a12015-10-16 18:04:34 +0900198 private String id;
sangho5db8e052016-01-29 16:08:23 +0900199 private Collection<String> securityGroups;
sanghoshin94872a12015-10-16 18:04:34 +0900200 private String deviceId;
201
202 Builder() {
Hyunsun Moon10201322016-02-15 05:00:22 -0800203 fixedIps = Maps.newHashMap();
204 allowedAddressPairs = Maps.newHashMap();
sanghoshin94872a12015-10-16 18:04:34 +0900205 }
206
207 /**
208 * Sets port status.
209 *
210 * @param status port status
211 * @return Builder object
212 */
213 public Builder portStatus(PortStatus status) {
214 this.status = status;
215
216 return this;
217 }
218
219 /**
220 * Sets port name.
221 *
222 * @param name port name
223 * @return Builder object
224 */
225 public Builder name(String name) {
226 this.name = name;
227
228 return this;
229 }
230
231 /**
Hyunsun Moon10201322016-02-15 05:00:22 -0800232 * Sets allowed address pairs.
233 *
234 * @param addrPairs map of ip address and mac address
235 * @return Builder object
236 */
237 public Builder allowedAddressPairs(Map<IpAddress, MacAddress> addrPairs) {
238 this.allowedAddressPairs.putAll(addrPairs);
239 return this;
240 }
241
242 /**
sanghoshin94872a12015-10-16 18:04:34 +0900243 * 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 */
Daniel Park23193902016-03-24 18:17:19 +0900308 public Builder fixedIps(Map<String, Ip4Address> fixedIpList) {
sanghoshin94872a12015-10-16 18:04:34 +0900309 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() {
Hyunsun Moon10201322016-02-15 05:00:22 -0800355 return new OpenstackPort(status, name, allowedAddressPairs, adminStateUp,
Eunjin Choidb46ab392016-12-05 16:26:33 +0900356 networkId, tenantId, deviceOwner, macAddress, fixedIps,
Hyunsun Moon10201322016-02-15 05:00:22 -0800357 id, securityGroups, deviceId);
sanghoshin94872a12015-10-16 18:04:34 +0900358 }
359 }
360}
361