blob: a631abc8b4a006065c972c6141d164d4a75c90f2 [file] [log] [blame]
Jian Li0a5d4d22018-06-08 14:06:56 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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.openstacktelemetry.impl;
17
18import org.onlab.packet.IpPrefix;
19import org.onlab.packet.MacAddress;
Jian Li6bd35102018-06-09 00:18:47 +090020import org.onlab.packet.TpPort;
Jian Li0a5d4d22018-06-08 14:06:56 +090021import org.onlab.packet.VlanId;
22import org.onosproject.net.DeviceId;
Jian Li0a5d4d22018-06-08 14:06:56 +090023import org.onosproject.openstacktelemetry.api.FlowInfo;
24import org.onosproject.openstacktelemetry.api.StatsInfo;
25
26import java.util.Objects;
27
28import static com.google.common.base.MoreObjects.toStringHelper;
29import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Implementation class of FlowInfo.
33 */
34public final class DefaultFlowInfo implements FlowInfo {
35
36 private final byte flowType;
37 private final DeviceId deviceId;
38 private final int inputInterfaceId;
39 private final int outputInterfaceId;
40 private final VlanId vlanId;
41 private final short vxlanId;
42 private final IpPrefix srcIp;
43 private final IpPrefix dstIp;
Jian Li6bd35102018-06-09 00:18:47 +090044 private final TpPort srcPort;
45 private final TpPort dstPort;
Jian Li0a5d4d22018-06-08 14:06:56 +090046 private final byte protocol;
47 private final MacAddress srcMac;
48 private final MacAddress dstMac;
49 private final StatsInfo statsInfo;
50
51 private DefaultFlowInfo(byte flowType, DeviceId deviceId,
52 int inputInterfaceId, int outputInterfaceId,
53 VlanId vlanId, short vxlanId, IpPrefix srcIp,
Jian Li6bd35102018-06-09 00:18:47 +090054 IpPrefix dstIp, TpPort srcPort, TpPort dstPort,
Jian Li0a5d4d22018-06-08 14:06:56 +090055 byte protocol, MacAddress srcMac, MacAddress dstMac,
56 StatsInfo statsInfo) {
57 this.flowType = flowType;
58 this.deviceId = deviceId;
59 this.inputInterfaceId = inputInterfaceId;
60 this.outputInterfaceId = outputInterfaceId;
61 this.vlanId = vlanId;
62 this.vxlanId = vxlanId;
63 this.srcIp = srcIp;
64 this.dstIp = dstIp;
65 this.srcPort = srcPort;
66 this.dstPort = dstPort;
67 this.protocol = protocol;
68 this.srcMac = srcMac;
69 this.dstMac = dstMac;
70 this.statsInfo = statsInfo;
71 }
72
73 @Override
74 public byte flowType() {
75 return flowType;
76 }
77
78 @Override
79 public DeviceId deviceId() {
80 return deviceId;
81 }
82
83 @Override
84 public int inputInterfaceId() {
85 return inputInterfaceId;
86 }
87
88 @Override
89 public int outputInterfaceId() {
90 return outputInterfaceId;
91 }
92
93 @Override
94 public VlanId vlanId() {
95 return vlanId;
96 }
97
98 @Override
99 public short vxlanId() {
100 return vxlanId;
101 }
102
103 @Override
104 public IpPrefix srcIp() {
105 return srcIp;
106 }
107
108 @Override
109 public IpPrefix dstIp() {
110 return dstIp;
111 }
112
113 @Override
Jian Li6bd35102018-06-09 00:18:47 +0900114 public TpPort srcPort() {
Jian Li0a5d4d22018-06-08 14:06:56 +0900115 return srcPort;
116 }
117
118 @Override
Jian Li6bd35102018-06-09 00:18:47 +0900119 public TpPort dstPort() {
Jian Li0a5d4d22018-06-08 14:06:56 +0900120 return dstPort;
121 }
122
123 @Override
124 public byte protocol() {
125 return protocol;
126 }
127
128 @Override
129 public MacAddress srcMac() {
130 return srcMac;
131 }
132
133 @Override
134 public MacAddress dstMac() {
135 return dstMac;
136 }
137
138 @Override
139 public StatsInfo statsInfo() {
140 return statsInfo;
141 }
142
143 @Override
Jian Li0bbbb1c2018-06-22 22:01:17 +0900144 public boolean roughEquals(FlowInfo flowInfo) {
Jian Li85573f42018-06-27 22:29:14 +0900145 final DefaultFlowInfo other = (DefaultFlowInfo) flowInfo;
146 return Objects.equals(this.deviceId, other.deviceId) &&
147 Objects.equals(this.srcIp, other.srcIp) &&
148 Objects.equals(this.dstIp, other.dstIp) &&
149 Objects.equals(this.srcPort, other.srcPort) &&
150 Objects.equals(this.dstPort, other.dstPort) &&
151 Objects.equals(this.protocol, other.protocol);
Jian Li0bbbb1c2018-06-22 22:01:17 +0900152 }
153
154 @Override
Jian Li0a5d4d22018-06-08 14:06:56 +0900155 public boolean equals(Object obj) {
156 if (this == obj) {
157 return true;
158 }
159
160 if (obj instanceof DefaultFlowInfo) {
161 final DefaultFlowInfo other = (DefaultFlowInfo) obj;
162 return Objects.equals(this.flowType, other.flowType) &&
163 Objects.equals(this.deviceId, other.deviceId) &&
164 Objects.equals(this.inputInterfaceId, other.inputInterfaceId) &&
165 Objects.equals(this.outputInterfaceId, other.outputInterfaceId) &&
166 Objects.equals(this.vlanId, other.vlanId) &&
167 Objects.equals(this.vxlanId, other.vxlanId) &&
168 Objects.equals(this.srcIp, other.srcIp) &&
169 Objects.equals(this.dstIp, other.dstIp) &&
170 Objects.equals(this.srcPort, other.srcPort) &&
171 Objects.equals(this.dstPort, other.dstPort) &&
172 Objects.equals(this.protocol, other.protocol) &&
173 Objects.equals(this.srcMac, other.srcMac) &&
174 Objects.equals(this.dstMac, other.dstMac) &&
175 Objects.equals(this.statsInfo, other.statsInfo);
176 }
177 return false;
178 }
179
180 @Override
181 public int hashCode() {
182 return Objects.hash(flowType, deviceId, inputInterfaceId,
183 outputInterfaceId, vlanId, vxlanId, srcIp, dstIp, srcPort, dstPort,
184 protocol, srcMac, dstMac, statsInfo);
185 }
186
187 @Override
188 public String toString() {
189 return toStringHelper(this)
190 .add("flowType", flowType)
191 .add("deviceId", deviceId)
192 .add("inputInterfaceId", inputInterfaceId)
193 .add("outputInterfaceId", outputInterfaceId)
194 .add("vlanId", vlanId)
195 .add("vxlanId", vxlanId)
196 .add("srcIp", srcIp)
197 .add("dstIp", dstIp)
198 .add("srcPort", srcPort)
199 .add("dstPort", dstPort)
200 .add("protocol", protocol)
201 .add("srcMac", srcMac)
202 .add("dstMac", dstMac)
203 .add("statsInfo", statsInfo)
204 .toString();
205 }
206
207 /**
208 * Builder class of DefaultFlowInfo.
209 */
210 public static final class DefaultBuilder implements FlowInfo.Builder {
211
212 private byte flowType;
213 private DeviceId deviceId;
214 private int inputInterfaceId;
215 private int outputInterfaceId;
216 private VlanId vlanId;
217 private short vxlanId;
218 private IpPrefix srcIp;
219 private IpPrefix dstIp;
Jian Li6bd35102018-06-09 00:18:47 +0900220 private TpPort srcPort;
221 private TpPort dstPort;
Jian Li0a5d4d22018-06-08 14:06:56 +0900222 private byte protocol;
223 private MacAddress srcMac;
224 private MacAddress dstMac;
225 private StatsInfo statsInfo;
226
227 @Override
228 public Builder withFlowType(byte flowType) {
229 this.flowType = flowType;
230 return this;
231 }
232
233 @Override
234 public Builder withDeviceId(DeviceId deviceId) {
235 this.deviceId = deviceId;
236 return this;
237 }
238
239 @Override
240 public Builder withInputInterfaceId(int inputInterfaceId) {
241 this.inputInterfaceId = inputInterfaceId;
242 return this;
243 }
244
245 @Override
246 public Builder withOutputInterfaceId(int outputInterfaceId) {
247 this.outputInterfaceId = outputInterfaceId;
248 return this;
249 }
250
251 @Override
252 public Builder withVlanId(VlanId vlanId) {
253 this.vlanId = vlanId;
254 return this;
255 }
256
257 @Override
258 public Builder withVxlanId(short vxlanId) {
259 this.vxlanId = vxlanId;
260 return this;
261 }
262
263 @Override
264 public Builder withSrcIp(IpPrefix srcIp) {
265 this.srcIp = srcIp;
266 return this;
267 }
268
269 @Override
270 public Builder withDstIp(IpPrefix dstIp) {
271 this.dstIp = dstIp;
272 return this;
273 }
274
275 @Override
Jian Li6bd35102018-06-09 00:18:47 +0900276 public Builder withSrcPort(TpPort srcPort) {
Jian Li0a5d4d22018-06-08 14:06:56 +0900277 this.srcPort = srcPort;
278 return this;
279 }
280
281 @Override
Jian Li6bd35102018-06-09 00:18:47 +0900282 public Builder withDstPort(TpPort dstPort) {
Jian Li0a5d4d22018-06-08 14:06:56 +0900283 this.dstPort = dstPort;
284 return this;
285 }
286
287 @Override
288 public Builder withProtocol(byte protocol) {
289 this.protocol = protocol;
290 return this;
291 }
292
293 @Override
294 public Builder withSrcMac(MacAddress srcMac) {
295 this.srcMac = srcMac;
296 return this;
297 }
298
299 @Override
300 public Builder withDstMac(MacAddress dstMac) {
301 this.dstMac = dstMac;
302 return this;
303 }
304
305 @Override
306 public Builder withStatsInfo(StatsInfo statsInfo) {
307 this.statsInfo = statsInfo;
308 return this;
309 }
310
311 @Override
312 public FlowInfo build() {
313
314 // TODO: need to check the null value for more properties
315 checkNotNull(srcIp, "Source IP address cannot be null");
316 checkNotNull(dstIp, "Destination IP address cannot be null");
317 checkNotNull(statsInfo, "StatsInfo cannot be null");
318
319 return new DefaultFlowInfo(flowType, deviceId, inputInterfaceId,
320 outputInterfaceId, vlanId, vxlanId, srcIp, dstIp, srcPort, dstPort,
321 protocol, srcMac, dstMac, statsInfo);
322 }
323 }
324}