sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 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 | */ |
sangho | 93447f1 | 2016-02-24 00:33:22 +0900 | [diff] [blame] | 16 | package org.onosproject.openstackinterface; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 17 | |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Maps; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 20 | import org.onlab.packet.Ip4Address; |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 22 | import org.onlab.packet.MacAddress; |
| 23 | |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 24 | import java.util.Collection; |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 25 | import java.util.Map; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 26 | |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
| 29 | /** |
| 30 | * It represents the Openstack Port information. |
| 31 | */ |
| 32 | public final class OpenstackPort { |
| 33 | |
| 34 | public enum PortStatus { |
| 35 | UP, |
sanghoshin | f25d2e0 | 2015-11-11 23:07:17 +0900 | [diff] [blame] | 36 | DOWN, |
sanghoshin | c5827d5 | 2015-12-11 12:52:02 +0900 | [diff] [blame] | 37 | ACTIVE, |
| 38 | NA, |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | private PortStatus status; |
| 42 | private String name; |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 43 | private ImmutableMap<IpAddress, MacAddress> allowedAddressPairs; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 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> |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 50 | private ImmutableMap<String, Ip4Address> fixedIps; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 51 | private String id; |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 52 | private Collection<String> securityGroups; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 53 | private String deviceId; |
| 54 | |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 55 | private OpenstackPort(PortStatus status, String name, Map<IpAddress, MacAddress> allowedAddressPairs, |
| 56 | boolean adminStateUp, String networkId, String tenantId, |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 57 | String deviceOwner, MacAddress macAddress, Map<String, Ip4Address> fixedIps, |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 58 | String id, Collection<String> securityGroups, String deviceId) { |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 59 | this.status = status; |
| 60 | this.name = name; |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 61 | this.allowedAddressPairs = checkNotNull(ImmutableMap.copyOf(allowedAddressPairs)); |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 62 | this.adminStateUp = adminStateUp; |
| 63 | this.networkId = checkNotNull(networkId); |
| 64 | this.tenantId = checkNotNull(tenantId); |
| 65 | this.deviceOwner = deviceOwner; |
| 66 | this.macAddress = checkNotNull(macAddress); |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 67 | this.fixedIps = checkNotNull(ImmutableMap.copyOf(fixedIps)); |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 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 | /** |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 103 | * 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 | /** |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 112 | * 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 Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 152 | public Map<String, Ip4Address> fixedIps() { |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 153 | 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 | */ |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 170 | public Collection<String> securityGroups() { |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 171 | return securityGroups; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Returns device ID. |
| 176 | * |
| 177 | * @return device ID |
| 178 | */ |
| 179 | public String deviceId() { |
| 180 | return deviceId; |
| 181 | } |
| 182 | |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 183 | /** |
| 184 | * OpenstackPort Builder class. |
| 185 | */ |
| 186 | public static final class Builder { |
| 187 | |
| 188 | private PortStatus status; |
| 189 | private String name; |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 190 | private Map<IpAddress, MacAddress> allowedAddressPairs; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 191 | 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 Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 197 | private Map<String, Ip4Address> fixedIps; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 198 | private String id; |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 199 | private Collection<String> securityGroups; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 200 | private String deviceId; |
| 201 | |
| 202 | Builder() { |
Hyunsun Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 203 | fixedIps = Maps.newHashMap(); |
| 204 | allowedAddressPairs = Maps.newHashMap(); |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 205 | } |
| 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 Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 232 | * 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 | /** |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 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 | */ |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 308 | public Builder fixedIps(Map<String, Ip4Address> fixedIpList) { |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 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 | * |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 329 | * @param securityGroupList security group list of the port |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 330 | * @return Builder object |
| 331 | */ |
sangho | 5db8e05 | 2016-01-29 16:08:23 +0900 | [diff] [blame] | 332 | public Builder securityGroup(Collection<String> securityGroupList) { |
| 333 | this.securityGroups = securityGroupList; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 334 | 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 Moon | 1020132 | 2016-02-15 05:00:22 -0800 | [diff] [blame] | 355 | return new OpenstackPort(status, name, allowedAddressPairs, adminStateUp, |
| 356 | networkId, networkId, deviceOwner, macAddress, fixedIps, |
| 357 | id, securityGroups, deviceId); |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | } |
| 361 | |