blob: 34eb25f05aaf1a7a2a75e99e9c4d6a791b59799a [file] [log] [blame]
jiangrui9c6db862015-11-27 14:50:46 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui9c6db862015-11-27 14:50:46 +08003 *
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.vtnrsc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23import org.onlab.packet.IpAddress;
24
25/**
26 * Default implementation of FloatingIp interface.
27 */
28public final class DefaultFloatingIp implements FloatingIp {
29
30 private final FloatingIpId id;
31 private final TenantId tenantId;
32 private final TenantNetworkId networkId;
33 private final VirtualPortId portId;
34 private final RouterId routerId;
35 private final IpAddress floatingIp;
36 private final IpAddress fixedIp;
37 private final Status status;
38
39 /**
40 *
41 * Creates a floating Ip object.
42 *
43 * @param id floatingIp identifier
44 * @param tenantId tenant identifier
45 * @param networkId the identifier of network associated with the floating Ip
46 * @param portId port identifier
47 * @param routerId router identifier
48 * @param floatingIp floatingIp address
49 * @param fixedIp the fixed Ip associated with the floating Ip
50 * @param status the floating Ip status
51 */
52 public DefaultFloatingIp(FloatingIpId id, TenantId tenantId,
53 TenantNetworkId networkId, VirtualPortId portId,
54 RouterId routerId, IpAddress floatingIp,
55 IpAddress fixedIp, Status status) {
56 this.id = checkNotNull(id, "id cannot be null");
57 this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
58 this.networkId = checkNotNull(networkId, "networkId cannot be null");
59 this.portId = portId;
60 this.routerId = routerId;
61 this.floatingIp = checkNotNull(floatingIp, "floatingIp cannot be null");
62 this.fixedIp = fixedIp;
63 this.status = checkNotNull(status, "status cannot be null");
64 }
65
66 @Override
67 public FloatingIpId id() {
68 return id;
69 }
70
71 @Override
72 public TenantId tenantId() {
73 return tenantId;
74 }
75
76 @Override
77 public TenantNetworkId networkId() {
78 return networkId;
79 }
80
81 @Override
82 public VirtualPortId portId() {
83 return portId;
84 }
85
86 @Override
87 public RouterId routerId() {
88 return routerId;
89 }
90
91 @Override
92 public IpAddress floatingIp() {
93 return floatingIp;
94 }
95
96 @Override
97 public IpAddress fixedIp() {
98 return fixedIp;
99 }
100
101 @Override
102 public Status status() {
103 return status;
104 }
105
106 @Override
107 public int hashCode() {
108 return Objects.hash(id, tenantId, networkId, portId, routerId,
109 floatingIp, fixedIp, status);
110 }
111
112 @Override
113 public boolean equals(Object obj) {
114 if (this == obj) {
115 return true;
116 }
117 if (obj instanceof DefaultFloatingIp) {
118 final DefaultFloatingIp that = (DefaultFloatingIp) obj;
119 return Objects.equals(this.id, that.id)
120 && Objects.equals(this.tenantId, that.tenantId)
121 && Objects.equals(this.networkId, that.networkId)
122 && Objects.equals(this.portId, that.portId)
123 && Objects.equals(this.routerId, that.routerId)
124 && Objects.equals(this.floatingIp, that.floatingIp)
125 && Objects.equals(this.fixedIp, that.fixedIp)
126 && Objects.equals(this.status, that.status);
127 }
128 return false;
129 }
130
131 @Override
132 public String toString() {
133 return toStringHelper(this).add("id", id).add("tenantId", tenantId)
134 .add("networkId", networkId).add("portId", portId)
135 .add("routerId", routerId).add("floatingIp", floatingIp)
136 .add("fixedIp", fixedIp).add("floatingIpStatus", status)
137 .toString();
138 }
139
140}