blob: 0ab868151ce1b8a45ae07774f73b18534e901f10 [file] [log] [blame]
Daniel Park5df65182016-01-09 00:12:03 +09001/*
Daniel Park3a06c522016-01-28 20:51:12 +09002 * Copyright 2015 Open Networking Laboratory
Daniel Park5df65182016-01-09 00:12:03 +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 */
sangho0c2a3da2016-02-16 13:39:07 +090016package org.onosproject.openstacknetworking;
Daniel Park5df65182016-01-09 00:12:03 +090017
18import org.onlab.packet.Ip4Address;
sangho3623cb62016-01-15 22:06:38 +090019import org.onlab.packet.MacAddress;
Daniel Park5df65182016-01-09 00:12:03 +090020import org.onosproject.net.DeviceId;
sangho90088532016-02-25 18:06:12 +090021
22import java.util.Collection;
23import java.util.Collections;
24
Daniel Park5df65182016-01-09 00:12:03 +090025import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Contains OpenstackPort Information.
29 */
Daniel Park3a06c522016-01-28 20:51:12 +090030public class OpenstackPortInfo {
Daniel Park5df65182016-01-09 00:12:03 +090031 private final Ip4Address hostIp;
sangho3623cb62016-01-15 22:06:38 +090032 private final MacAddress hostMac;
Daniel Park3a06c522016-01-28 20:51:12 +090033 private final DeviceId deviceId;
Daniel Park5df65182016-01-09 00:12:03 +090034 private final long vni;
Daniel Park3a06c522016-01-28 20:51:12 +090035 private final Ip4Address gatewayIP;
sangho90088532016-02-25 18:06:12 +090036 private final Collection<String> securityGroups;
Daniel Park5df65182016-01-09 00:12:03 +090037
sangho90088532016-02-25 18:06:12 +090038 /**
39 * Returns OpenstackPortInfo reference.
40 *
41 * @param hostIp host IP address
42 * @param hostMac host MAC address
43 * @param deviceId device ID
44 * @param vni tunnel ID
45 * @param gatewayIP gateway IP address
46 * @param securityGroups security group list
47 */
48 public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni,
49 Ip4Address gatewayIP, Collection<String> securityGroups) {
Daniel Park5df65182016-01-09 00:12:03 +090050 this.hostIp = hostIp;
sangho3623cb62016-01-15 22:06:38 +090051 this.hostMac = hostMac;
Daniel Park5df65182016-01-09 00:12:03 +090052 this.deviceId = deviceId;
53 this.vni = vni;
Daniel Park3a06c522016-01-28 20:51:12 +090054 this.gatewayIP = gatewayIP;
sangho90088532016-02-25 18:06:12 +090055 this.securityGroups = securityGroups;
Daniel Park5df65182016-01-09 00:12:03 +090056 }
57
sangho90088532016-02-25 18:06:12 +090058 /**
59 * Returns IP address of the port.
60 *
61 * @return IP address
62 */
Daniel Park5df65182016-01-09 00:12:03 +090063 public Ip4Address ip() {
64 return hostIp;
65 }
66
sangho90088532016-02-25 18:06:12 +090067 /**
68 * Returns MAC address of the port.
69 *
70 * @return MAC address
71 */
sangho3623cb62016-01-15 22:06:38 +090072 public MacAddress mac() {
73 return hostMac;
74 }
75
sangho90088532016-02-25 18:06:12 +090076 /**
77 * Returns device ID.
78 *
79 * @return device ID
80 */
Daniel Park5df65182016-01-09 00:12:03 +090081 public DeviceId deviceId() {
82 return deviceId;
83 }
84
sangho90088532016-02-25 18:06:12 +090085 /**
86 * Returns tunnel ID.
87 *
88 * @return tunnel ID
89 */
Daniel Park5df65182016-01-09 00:12:03 +090090 public long vni() {
91 return vni;
92 }
93
sangho90088532016-02-25 18:06:12 +090094 /**
95 * Returns gateway IP address.
96 *
97 * @return gateway IP address
98 */
Daniel Park3a06c522016-01-28 20:51:12 +090099 public Ip4Address gatewayIP() {
100 return gatewayIP;
101 }
102
sangho90088532016-02-25 18:06:12 +0900103 /**
104 * Returns Security Group ID list.
105 *
106 * @return list of Security Group ID
107 */
108 public Collection<String> securityGroups() {
109 return Collections.unmodifiableCollection(securityGroups);
110 }
111
112 /**
113 * Returns the builder of the OpenstackPortInfo.
114 *
115 * @return OpenstackPortInfo builder reference
116 */
Daniel Park5df65182016-01-09 00:12:03 +0900117 public static OpenstackPortInfo.Builder builder() {
118 return new Builder();
119 }
120
sangho90088532016-02-25 18:06:12 +0900121 /**
122 * Represents the OpenstackPortInfo Builder.
123 *
124 */
Daniel Park5df65182016-01-09 00:12:03 +0900125 public static final class Builder {
126 private Ip4Address hostIp;
sangho3623cb62016-01-15 22:06:38 +0900127 private MacAddress hostMac;
Daniel Park5df65182016-01-09 00:12:03 +0900128 private DeviceId deviceId;
129 private long vni;
Daniel Park3a06c522016-01-28 20:51:12 +0900130 private Ip4Address gatewayIP;
sangho90088532016-02-25 18:06:12 +0900131 private Collection<String> securityGroups;
Daniel Park3a06c522016-01-28 20:51:12 +0900132
sangho90088532016-02-25 18:06:12 +0900133 /**
134 * Sets the IP address of the port.
135 *
136 * @param gatewayIP
137 * @return Builder reference
138 */
Daniel Park3a06c522016-01-28 20:51:12 +0900139 public Builder setGatewayIP(Ip4Address gatewayIP) {
140 this.gatewayIP = checkNotNull(gatewayIP, "gatewayIP cannot be null");
141 return this;
142 }
Daniel Park5df65182016-01-09 00:12:03 +0900143
sangho90088532016-02-25 18:06:12 +0900144 /**
145 * Sets the host IP address of the port.
146 *
147 * @param hostIp host IP address
148 * @return Builder reference
149 */
Daniel Park5df65182016-01-09 00:12:03 +0900150 public Builder setHostIp(Ip4Address hostIp) {
151 this.hostIp = checkNotNull(hostIp, "hostIp cannot be null");
152 return this;
153 }
154
sangho90088532016-02-25 18:06:12 +0900155 /**
156 * Sets the host MAC address of the port.
157 *
158 * @param hostMac host MAC address
159 * @return Builder reference
160 */
sangho3623cb62016-01-15 22:06:38 +0900161 public Builder setHostMac(MacAddress hostMac) {
162 this.hostMac = checkNotNull(hostMac, "hostMac cannot be bull");
163 return this;
164 }
165
sangho90088532016-02-25 18:06:12 +0900166 /**
167 * Sets the device ID.
168 *
169 * @param deviceId device ID
170 * @return Builder reference
171 */
Daniel Park5df65182016-01-09 00:12:03 +0900172 public Builder setDeviceId(DeviceId deviceId) {
173 this.deviceId = checkNotNull(deviceId, "deviceId cannot be null");
174 return this;
175 }
176
sangho90088532016-02-25 18:06:12 +0900177 /**
178 * Sets the tunnel ID.
179 *
180 * @param vni tunnel ID
181 * @return Builder reference
182 */
Jonathan Hart51539b82015-10-29 09:53:04 -0700183 public Builder setVni(long vni) {
Daniel Park5df65182016-01-09 00:12:03 +0900184 this.vni = checkNotNull(vni, "vni cannot be null");
185 return this;
186 }
sangho90088532016-02-25 18:06:12 +0900187
188 /**
189 * Sets the security group ID list.
190 *
191 * @param securityGroups security group ID list
192 * @return Builder reference
193 */
194 public Builder setSecurityGroups(Collection<String> securityGroups) {
195 this.securityGroups = securityGroups;
196 return this;
197 }
198
199 /**
200 * Builds the OpenstackPortInfo reference.
201 *
202 * @return OpenstackPortInfo reference
203 */
Daniel Park5df65182016-01-09 00:12:03 +0900204 public OpenstackPortInfo build() {
205 return new OpenstackPortInfo(this);
206 }
207 }
208
209 private OpenstackPortInfo(Builder builder) {
210 hostIp = builder.hostIp;
sangho3623cb62016-01-15 22:06:38 +0900211 hostMac = builder.hostMac;
Daniel Park5df65182016-01-09 00:12:03 +0900212 deviceId = builder.deviceId;
213 vni = builder.vni;
Daniel Park3a06c522016-01-28 20:51:12 +0900214 gatewayIP = builder.gatewayIP;
sangho90088532016-02-25 18:06:12 +0900215 securityGroups = builder.securityGroups;
Daniel Park5df65182016-01-09 00:12:03 +0900216 }
217}