blob: 6ed4462f163e6a96aee6f7f3a0f882c378a34501 [file] [log] [blame]
sangho0c2a3da2016-02-16 13:39:07 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
sangho0c2a3da2016-02-16 13:39:07 +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;
sangho0c2a3da2016-02-16 13:39:07 +090017
18import org.onlab.packet.Ip4Address;
19
20import java.util.Objects;
21
Kyuhwi Choie2b37e32016-02-05 14:04:14 +090022import static com.google.common.base.Preconditions.checkNotNull;
23
sangho0c2a3da2016-02-16 13:39:07 +090024/**
25 * An Openstack Neutron Floating IP Model.
26 */
27public final class OpenstackFloatingIP {
28
Kyuhwi Choie2b37e32016-02-05 14:04:14 +090029 public enum FloatingIpStatus {
sangho0c2a3da2016-02-16 13:39:07 +090030 UP,
31 DOWN,
32 ACTIVE,
33 }
34
35 private final String tenantId;
36 private final String networkId;
37 private final Ip4Address fixedIpAddress;
Kyuhwi Choie2b37e32016-02-05 14:04:14 +090038 private String portId;
39 private String routerId;
sangho0c2a3da2016-02-16 13:39:07 +090040 private final String id;
41 private final Ip4Address floatingIpAddress;
Kyuhwi Choie2b37e32016-02-05 14:04:14 +090042 private final FloatingIpStatus status;
sangho0c2a3da2016-02-16 13:39:07 +090043
Kyuhwi Choie2b37e32016-02-05 14:04:14 +090044 private OpenstackFloatingIP(FloatingIpStatus status, String id, String tenantId,
sangho0c2a3da2016-02-16 13:39:07 +090045 String networkId, Ip4Address fixedIpAddress, String portId,
46 String routerId, Ip4Address floatingIpAddress) {
47 this.status = status;
48 this.id = id;
49 this.tenantId = tenantId;
50 this.networkId = networkId;
51 this.fixedIpAddress = fixedIpAddress;
52 this.portId = portId;
53 this.routerId = routerId;
54 this.floatingIpAddress = floatingIpAddress;
55 }
56
57 /**
58 * Returns floating IP status.
59 *
60 * @return floating IP status
61 */
Kyuhwi Choie2b37e32016-02-05 14:04:14 +090062 public FloatingIpStatus status() {
sangho0c2a3da2016-02-16 13:39:07 +090063 return status;
64 }
65
66 /**
67 * Returns floating IP`s ID.
68 *
69 * @return floating IP`s ID
70 */
71 public String id() {
72 return id;
73 }
74
75 /**
76 * Returns tenant ID.
77 *
78 * @return tenant ID
79 */
80 public String tenantId() {
81 return tenantId;
82 }
83
84 /**
85 * Returns network ID.
86 *
87 * @return network ID
88 */
89 public String networkId() {
90 return networkId;
91 }
92
93 /**
94 * Returns fixed IP Address.
95 *
96 * @return fixed IP Address
97 */
98 public Ip4Address fixedIpAddress() {
99 return fixedIpAddress;
100 }
101
102 /**
103 * Returns port ID.
104 *
105 * @return port ID
106 */
107 public String portId() {
108 return portId;
109 }
110
111 /**
Kyuhwi Choie2b37e32016-02-05 14:04:14 +0900112 * Updates port ID.
113 *
114 * @param portId Updated port ID
115 */
116 public void updatePortId(String portId) {
117 this.portId = portId;
118 }
119
120 /**
sangho0c2a3da2016-02-16 13:39:07 +0900121 * Returns router ID.
122 *
123 * @return router ID
124 */
125 public String routerId() {
126 return routerId;
127 }
128
129 /**
Kyuhwi Choie2b37e32016-02-05 14:04:14 +0900130 * Updates router ID.
131 *
132 * @param routerId Updated router ID
133 */
134 public void updateRouterId(String routerId) {
135 this.routerId = routerId;
136 }
137
138 /**
sangho0c2a3da2016-02-16 13:39:07 +0900139 * Returns floating IP address.
140 *
141 * @return Floating IP address
142 */
143 public Ip4Address floatingIpAddress() {
144 return floatingIpAddress;
145 }
146
147 @Override
148 public boolean equals(Object o) {
149 if (this == o) {
150 return true;
151 }
152
153 if (o instanceof OpenstackFloatingIP) {
154 OpenstackFloatingIP that = (OpenstackFloatingIP) o;
155
156 return this.status.equals(that.status) &&
157 this.id.equals(that.id) &&
158 this.tenantId.equals(that.tenantId) &&
159 this.networkId.equals(that.networkId) &&
160 this.fixedIpAddress.equals(that.fixedIpAddress) &&
161 this.floatingIpAddress.equals(that.floatingIpAddress) &&
162 this.portId.equals(that.portId) &&
163 this.routerId.equals(that.routerId);
164 }
165
166 return false;
167 }
168
169 @Override
170 public int hashCode() {
171 return Objects.hash(status, id, tenantId, networkId, floatingIpAddress, fixedIpAddress, portId, routerId);
172 }
173
174 /**
175 * An Openstack Floating IP Builder class.
176 */
177 public static final class Builder {
178 private String tenantId;
179 private String networkId;
180 private Ip4Address fixedIpAddress;
181 private String portId;
182 private String routerId;
183 private String id;
184 private Ip4Address floatingIpAddress;
Kyuhwi Choie2b37e32016-02-05 14:04:14 +0900185 private FloatingIpStatus status;
sangho0c2a3da2016-02-16 13:39:07 +0900186
187 /**
188 * Sets tenant ID.
189 *
190 * @param tenantId tenant ID
191 * @return Builder object
192 */
193 public Builder tenantId(String tenantId) {
194 this.tenantId = tenantId;
195 return this;
196 }
197
198 /**
199 * Sets floating IP status.
200 *
201 * @param status Floating IP status
202 * @return Builder object
203 */
Kyuhwi Choie2b37e32016-02-05 14:04:14 +0900204 public Builder status(FloatingIpStatus status) {
sangho0c2a3da2016-02-16 13:39:07 +0900205 this.status = status;
206 return this;
207 }
208
209 /**
210 * Sets Floating IP`s ID.
211 *
212 * @param id Floating IP`s ID
213 * @return Builder object
214 */
215 public Builder id(String id) {
216 this.id = id;
217 return this;
218 }
219
220 /**
221 * Sets network ID.
222 *
223 * @param networkId Network ID
224 * @return Builder object
225 */
226 public Builder networkId(String networkId) {
227 this.networkId = networkId;
228 return this;
229 }
230
231 /**
232 * Sets fixed IP address.
233 *
234 * @param fixedIpAddress Fixed IP address
235 * @return Builder object
236 */
237 public Builder fixedIpAddress(Ip4Address fixedIpAddress) {
238 this.fixedIpAddress = fixedIpAddress;
239 return this;
240 }
241
242 /**
243 * Sets port ID.
244 *
245 * @param portId port ID
246 * @return Builder object
247 */
248 public Builder portId(String portId) {
249 this.portId = portId;
250 return this;
251 }
252
253 /**
254 * Sets router ID.
255 *
256 * @param routerId router ID
257 * @return Builder object
258 */
259 public Builder routerId(String routerId) {
260 this.routerId = routerId;
261 return this;
262 }
263
264 /**
265 * Sets floating IP address.
266 *
267 * @param floatingIpAddress Floating IP address
268 * @return Builder object
269 */
270 public Builder floatingIpAddress(Ip4Address floatingIpAddress) {
271 this.floatingIpAddress = floatingIpAddress;
272 return this;
273 }
274
275 /**
276 * Builds an OpenstackFloatingIP object.
277 *
278 * @return OpenstackFloatingIP object
279 */
280 public OpenstackFloatingIP build() {
Kyuhwi Choie2b37e32016-02-05 14:04:14 +0900281 return new OpenstackFloatingIP(checkNotNull(status), checkNotNull(id), checkNotNull(tenantId),
282 checkNotNull(networkId), fixedIpAddress, portId,
283 routerId, checkNotNull(floatingIpAddress));
sangho0c2a3da2016-02-16 13:39:07 +0900284
285 }
286 }
287}