2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.openstackswitching;
18 import com.google.common.collect.Lists;
19 import org.onlab.packet.Ip4Address;
20 import org.onlab.packet.MacAddress;
22 import java.util.HashMap;
23 import java.util.List;
25 import static com.google.common.base.Preconditions.checkNotNull;
28 * It represents the Openstack Port information.
30 public final class OpenstackPort {
32 public enum PortStatus {
37 private PortStatus status;
40 private String allowedAddressPairs;
41 private boolean adminStateUp;
42 private String networkId;
43 private String tenantId;
44 private String deviceOwner;
45 private MacAddress macAddress;
46 // <subnet id, ip address>
47 private HashMap<String, Ip4Address> fixedIps;
49 private List<String> securityGroups;
50 private String deviceId;
52 private OpenstackPort(PortStatus status, String name, boolean adminStateUp,
53 String networkId, String tenantId, String deviceOwner,
54 MacAddress macAddress, HashMap fixedIps, String id,
55 List<String> securityGroups, String deviceId) {
59 this.adminStateUp = adminStateUp;
60 this.networkId = checkNotNull(networkId);
61 this.tenantId = checkNotNull(tenantId);
62 this.deviceOwner = deviceOwner;
63 this.macAddress = checkNotNull(macAddress);
64 this.fixedIps = checkNotNull(fixedIps);
65 this.id = checkNotNull(id);
66 this.securityGroups = securityGroups;
67 this.deviceId = deviceId;
73 * Returns OpenstackPort builder object.
75 * @return OpenstackPort builder
77 public static OpenstackPort.Builder builder() {
82 * Returns port status.
86 public PortStatus status() {
95 public String name() {
100 * Returns whether admin state up or not.
102 * @return true if admin state up, false otherwise
104 public boolean isAdminStateUp() {
109 * Returns network ID.
113 public String networkId() {
118 * Returns device owner.
120 * @return device owner
122 public String deviceOwner() {
127 * Returns mac address.
129 * @return mac address
131 public MacAddress macAddress() {
136 * Returns the fixed IP information.
138 * @return fixed IP info
140 public HashMap fixedIps() {
154 * Returns security group information.
156 * @return security group info
158 public List<String> securityGroups() {
159 return securityGroups;
167 public String deviceId() {
171 // TODO : Implement the following functions when necessary
173 //public void equals(Object that) {
178 //public int hashCode() {
183 * OpenstackPort Builder class.
185 public static final class Builder {
187 private PortStatus status;
190 private String allowedAddressPairs;
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>
197 private HashMap<String, Ip4Address> fixedIps;
199 private List<String> securityGroups;
200 private String deviceId;
203 fixedIps = new HashMap<>();
204 securityGroups = Lists.newArrayList();
210 * @param status port status
211 * @return Builder object
213 public Builder portStatus(PortStatus status) {
214 this.status = status;
222 * @param name port name
223 * @return Builder object
225 public Builder name(String name) {
232 * Sets whether admin state up or not.
234 * @param isAdminStateUp true if admin state is up, false otherwise
235 * @return Builder object
237 public Builder adminState(boolean isAdminStateUp) {
238 this.adminStateUp = isAdminStateUp;
246 * @param networkId network ID
247 * @return Builder object
249 public Builder netwrokId(String networkId) {
250 this.networkId = networkId;
258 * @param tenantId tenant ID
259 * @return Builder object
261 public Builder tenantId(String tenantId) {
262 this.tenantId = tenantId;
270 * @param owner device owner
271 * @return Builder object
273 public Builder deviceOwner(String owner) {
274 this.deviceOwner = owner;
280 * Sets MAC address of the port.
282 * @param mac MAC address
283 * @return Builder object
285 public Builder macAddress(MacAddress mac) {
286 this.macAddress = mac;
292 * Sets Fixed IP address information.
294 * @param fixedIpList Fixed IP info
295 * @return Builder object
297 public Builder fixedIps(HashMap<String, Ip4Address> fixedIpList) {
298 fixedIps.putAll(fixedIpList);
304 * Sets ID of the port.
306 * @param id ID of the port
307 * @return Builder object
309 public Builder id(String id) {
316 * Sets security group of the port.
318 * @param securityGroup security group of the port
319 * @return Builder object
321 public Builder securityGroup(String securityGroup) {
322 securityGroups.add(securityGroup);
328 * Sets device ID of the port.
330 * @param deviceId device ID
331 * @return Builder object
333 public Builder deviceId(String deviceId) {
334 this.deviceId = deviceId;
340 * Builds an OpenstackPort object.
342 * @return OpenstackPort objecet
344 public OpenstackPort build() {
345 return new OpenstackPort(status, name, adminStateUp, networkId, networkId,
346 deviceOwner, macAddress, fixedIps, id, securityGroups, deviceId);