blob: 60334830eb28d17c892517b7a875a8d14bf52ea0 [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 /**
Jian Liae3fcff2018-07-30 11:55:44 +0900208 * Obtains a default flow info builder object.
209 *
210 * @return flow info builder object
211 */
212 public static Builder builder() {
213 return new DefaultBuilder();
214 }
215
216 /**
Jian Li0a5d4d22018-06-08 14:06:56 +0900217 * Builder class of DefaultFlowInfo.
218 */
219 public static final class DefaultBuilder implements FlowInfo.Builder {
220
221 private byte flowType;
222 private DeviceId deviceId;
223 private int inputInterfaceId;
224 private int outputInterfaceId;
225 private VlanId vlanId;
226 private short vxlanId;
227 private IpPrefix srcIp;
228 private IpPrefix dstIp;
Jian Li6bd35102018-06-09 00:18:47 +0900229 private TpPort srcPort;
230 private TpPort dstPort;
Jian Li0a5d4d22018-06-08 14:06:56 +0900231 private byte protocol;
232 private MacAddress srcMac;
233 private MacAddress dstMac;
234 private StatsInfo statsInfo;
235
236 @Override
237 public Builder withFlowType(byte flowType) {
238 this.flowType = flowType;
239 return this;
240 }
241
242 @Override
243 public Builder withDeviceId(DeviceId deviceId) {
244 this.deviceId = deviceId;
245 return this;
246 }
247
248 @Override
249 public Builder withInputInterfaceId(int inputInterfaceId) {
250 this.inputInterfaceId = inputInterfaceId;
251 return this;
252 }
253
254 @Override
255 public Builder withOutputInterfaceId(int outputInterfaceId) {
256 this.outputInterfaceId = outputInterfaceId;
257 return this;
258 }
259
260 @Override
261 public Builder withVlanId(VlanId vlanId) {
262 this.vlanId = vlanId;
263 return this;
264 }
265
266 @Override
267 public Builder withVxlanId(short vxlanId) {
268 this.vxlanId = vxlanId;
269 return this;
270 }
271
272 @Override
273 public Builder withSrcIp(IpPrefix srcIp) {
274 this.srcIp = srcIp;
275 return this;
276 }
277
278 @Override
279 public Builder withDstIp(IpPrefix dstIp) {
280 this.dstIp = dstIp;
281 return this;
282 }
283
284 @Override
Jian Li6bd35102018-06-09 00:18:47 +0900285 public Builder withSrcPort(TpPort srcPort) {
Jian Li0a5d4d22018-06-08 14:06:56 +0900286 this.srcPort = srcPort;
287 return this;
288 }
289
290 @Override
Jian Li6bd35102018-06-09 00:18:47 +0900291 public Builder withDstPort(TpPort dstPort) {
Jian Li0a5d4d22018-06-08 14:06:56 +0900292 this.dstPort = dstPort;
293 return this;
294 }
295
296 @Override
297 public Builder withProtocol(byte protocol) {
298 this.protocol = protocol;
299 return this;
300 }
301
302 @Override
303 public Builder withSrcMac(MacAddress srcMac) {
304 this.srcMac = srcMac;
305 return this;
306 }
307
308 @Override
309 public Builder withDstMac(MacAddress dstMac) {
310 this.dstMac = dstMac;
311 return this;
312 }
313
314 @Override
315 public Builder withStatsInfo(StatsInfo statsInfo) {
316 this.statsInfo = statsInfo;
317 return this;
318 }
319
320 @Override
321 public FlowInfo build() {
322
323 // TODO: need to check the null value for more properties
324 checkNotNull(srcIp, "Source IP address cannot be null");
325 checkNotNull(dstIp, "Destination IP address cannot be null");
326 checkNotNull(statsInfo, "StatsInfo cannot be null");
327
328 return new DefaultFlowInfo(flowType, deviceId, inputInterfaceId,
329 outputInterfaceId, vlanId, vxlanId, srcIp, dstIp, srcPort, dstPort,
330 protocol, srcMac, dstMac, statsInfo);
331 }
332 }
333}