blob: bed028904002659999df2a22307cf0d330f291f6 [file] [log] [blame]
sangho0c2a3da2016-02-16 13:39:07 +09001/*
2 * Copyright 2016 Open Networking Laboratory
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 */
16package org.onosproject.openstacknetworking;
17
18import org.onlab.packet.Ip4Address;
19
20import java.util.Objects;
21
22/**
23 * An Openstack Neutron Floating IP Model.
24 */
25public final class OpenstackFloatingIP {
26
27 public enum FloatingIPStatus {
28 UP,
29 DOWN,
30 ACTIVE,
31 }
32
33 private final String tenantId;
34 private final String networkId;
35 private final Ip4Address fixedIpAddress;
36 private final String portId;
37 private final String routerId;
38 private final String id;
39 private final Ip4Address floatingIpAddress;
40 private final FloatingIPStatus status;
41
42 private OpenstackFloatingIP(FloatingIPStatus status, String id, String tenantId,
43 String networkId, Ip4Address fixedIpAddress, String portId,
44 String routerId, Ip4Address floatingIpAddress) {
45 this.status = status;
46 this.id = id;
47 this.tenantId = tenantId;
48 this.networkId = networkId;
49 this.fixedIpAddress = fixedIpAddress;
50 this.portId = portId;
51 this.routerId = routerId;
52 this.floatingIpAddress = floatingIpAddress;
53 }
54
55 /**
56 * Returns floating IP status.
57 *
58 * @return floating IP status
59 */
60 public FloatingIPStatus status() {
61 return status;
62 }
63
64 /**
65 * Returns floating IP`s ID.
66 *
67 * @return floating IP`s ID
68 */
69 public String id() {
70 return id;
71 }
72
73 /**
74 * Returns tenant ID.
75 *
76 * @return tenant ID
77 */
78 public String tenantId() {
79 return tenantId;
80 }
81
82 /**
83 * Returns network ID.
84 *
85 * @return network ID
86 */
87 public String networkId() {
88 return networkId;
89 }
90
91 /**
92 * Returns fixed IP Address.
93 *
94 * @return fixed IP Address
95 */
96 public Ip4Address fixedIpAddress() {
97 return fixedIpAddress;
98 }
99
100 /**
101 * Returns port ID.
102 *
103 * @return port ID
104 */
105 public String portId() {
106 return portId;
107 }
108
109 /**
110 * Returns router ID.
111 *
112 * @return router ID
113 */
114 public String routerId() {
115 return routerId;
116 }
117
118 /**
119 * Returns floating IP address.
120 *
121 * @return Floating IP address
122 */
123 public Ip4Address floatingIpAddress() {
124 return floatingIpAddress;
125 }
126
127 @Override
128 public boolean equals(Object o) {
129 if (this == o) {
130 return true;
131 }
132
133 if (o instanceof OpenstackFloatingIP) {
134 OpenstackFloatingIP that = (OpenstackFloatingIP) o;
135
136 return this.status.equals(that.status) &&
137 this.id.equals(that.id) &&
138 this.tenantId.equals(that.tenantId) &&
139 this.networkId.equals(that.networkId) &&
140 this.fixedIpAddress.equals(that.fixedIpAddress) &&
141 this.floatingIpAddress.equals(that.floatingIpAddress) &&
142 this.portId.equals(that.portId) &&
143 this.routerId.equals(that.routerId);
144 }
145
146 return false;
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(status, id, tenantId, networkId, floatingIpAddress, fixedIpAddress, portId, routerId);
152 }
153
154 /**
155 * An Openstack Floating IP Builder class.
156 */
157 public static final class Builder {
158 private String tenantId;
159 private String networkId;
160 private Ip4Address fixedIpAddress;
161 private String portId;
162 private String routerId;
163 private String id;
164 private Ip4Address floatingIpAddress;
165 private FloatingIPStatus status;
166
167 /**
168 * Sets tenant ID.
169 *
170 * @param tenantId tenant ID
171 * @return Builder object
172 */
173 public Builder tenantId(String tenantId) {
174 this.tenantId = tenantId;
175 return this;
176 }
177
178 /**
179 * Sets floating IP status.
180 *
181 * @param status Floating IP status
182 * @return Builder object
183 */
184 public Builder status(FloatingIPStatus status) {
185 this.status = status;
186 return this;
187 }
188
189 /**
190 * Sets Floating IP`s ID.
191 *
192 * @param id Floating IP`s ID
193 * @return Builder object
194 */
195 public Builder id(String id) {
196 this.id = id;
197 return this;
198 }
199
200 /**
201 * Sets network ID.
202 *
203 * @param networkId Network ID
204 * @return Builder object
205 */
206 public Builder networkId(String networkId) {
207 this.networkId = networkId;
208 return this;
209 }
210
211 /**
212 * Sets fixed IP address.
213 *
214 * @param fixedIpAddress Fixed IP address
215 * @return Builder object
216 */
217 public Builder fixedIpAddress(Ip4Address fixedIpAddress) {
218 this.fixedIpAddress = fixedIpAddress;
219 return this;
220 }
221
222 /**
223 * Sets port ID.
224 *
225 * @param portId port ID
226 * @return Builder object
227 */
228 public Builder portId(String portId) {
229 this.portId = portId;
230 return this;
231 }
232
233 /**
234 * Sets router ID.
235 *
236 * @param routerId router ID
237 * @return Builder object
238 */
239 public Builder routerId(String routerId) {
240 this.routerId = routerId;
241 return this;
242 }
243
244 /**
245 * Sets floating IP address.
246 *
247 * @param floatingIpAddress Floating IP address
248 * @return Builder object
249 */
250 public Builder floatingIpAddress(Ip4Address floatingIpAddress) {
251 this.floatingIpAddress = floatingIpAddress;
252 return this;
253 }
254
255 /**
256 * Builds an OpenstackFloatingIP object.
257 *
258 * @return OpenstackFloatingIP object
259 */
260 public OpenstackFloatingIP build() {
261 return new OpenstackFloatingIP(status, id, tenantId, networkId,
262 fixedIpAddress, portId, routerId, floatingIpAddress);
263
264 }
265 }
266}