blob: a640906922b03a7c79602b38e42b7cd826a32d40 [file] [log] [blame]
Frank Wange33e4ed2017-06-28 10:01:07 +08001/*
2 * Copyright 2017-present 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 */
16
17package org.onosproject.net.flow.criteria;
18
Frank Wange33e4ed2017-06-28 10:01:07 +080019import com.google.common.testing.EqualsTester;
Frank Wange33e4ed2017-06-28 10:01:07 +080020import org.junit.Test;
21import org.onosproject.net.pi.runtime.PiExactFieldMatch;
22import org.onosproject.net.pi.runtime.PiFieldMatch;
23import org.onosproject.net.pi.runtime.PiHeaderFieldId;
24import org.onosproject.net.pi.runtime.PiLpmFieldMatch;
25import org.onosproject.net.pi.runtime.PiRangeFieldMatch;
26import org.onosproject.net.pi.runtime.PiTernaryFieldMatch;
27import org.onosproject.net.pi.runtime.PiValidFieldMatch;
28
Frank Wange33e4ed2017-06-28 10:01:07 +080029import static org.hamcrest.MatcherAssert.assertThat;
30import static org.hamcrest.Matchers.equalTo;
31import static org.hamcrest.Matchers.instanceOf;
32import static org.hamcrest.Matchers.is;
33import static org.hamcrest.Matchers.notNullValue;
34import static org.onlab.util.ImmutableByteSequence.copyFrom;
35
36/**
37 * Unit tests for the PiCriteria class.
38 */
39public class PiCriteriaTest {
40
41 PiHeaderFieldId piEthHeaderFieldId = PiHeaderFieldId.of("ethernet_t", "etherType");
42 byte[] matchExactBytes1 = {0x08, 0x00};
43 byte[] matchExactBytes2 = {0x08, 0x06};
44 Criterion matchPiExactByte1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactBytes1).build();
45 Criterion sameAsMatchPiExactByte1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactBytes1).build();
46 Criterion matchPiExactByte2 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactBytes2).build();
47
48 short matchExactShort1 = 0x800;
49 short matchExactShort2 = 0x806;
50 Criterion matchPiExactShort1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactShort1).build();
51 Criterion sameAsMatchPiExactShort1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactShort1).build();
52 Criterion matchPiExactShort2 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactShort2).build();
53
54 int matchExactInt1 = 0x800;
55 int matchExactInt2 = 0x806;
56 Criterion matchPiExactInt1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactInt1).build();
57 Criterion sameAsMatchPiExactInt1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactInt1).build();
58 Criterion matchPiExactInt2 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactInt2).build();
59
60 long matchExactLong1 = 0x800;
61 long matchExactLong2 = 0x806;
62 Criterion matchPiExactLong1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactLong1).build();
63 Criterion sameAsMatchPiExactLong1 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactLong1).build();
64 Criterion matchPiExactLong2 = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactLong2).build();
65
66 PiHeaderFieldId piIpv4HeaderFieldId = PiHeaderFieldId.of("ipv4_t", "dstAddr");
67 int mask = 0x00ffffff;
68 byte[] matchLpmBytes1 = {0x0a, 0x01, 0x01, 0x01};
69 byte[] matchLpmBytes2 = {0x0a, 0x01, 0x01, 0x02};
70 Criterion matchPiLpmByte1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmBytes1, mask).build();
71 Criterion sameAsMatchPiLpmByte1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmBytes1, mask).build();
72 Criterion matchPiLpmByte2 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmBytes2, mask).build();
73
74 short matchLpmShort1 = 0x0a0a;
75 short matchLpmShort2 = 0x0a0b;
76 Criterion matchPiLpmShort1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmShort1, mask).build();
77 Criterion sameAsMatchPiLpmShort1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId,
78 matchLpmShort1, mask)
79 .build();
80 Criterion matchPiLpmShort2 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmShort2, mask).build();
81
82 int matchLpmInt1 = 0x0a010101;
83 int matchLpmInt2 = 0x0a010102;
84 Criterion matchPiLpmInt1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmInt1, mask).build();
85 Criterion sameAsMatchPiLpmInt1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmInt1, mask).build();
86 Criterion matchPiLpmInt2 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmInt2, mask).build();
87
88 long matchLpmLong1 = 0x0a010101;
89 long matchLpmLong2 = 0x0a010102;
90 Criterion matchPiLpmLong1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmLong1, mask).build();
91 Criterion sameAsMatchPiLpmLong1 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmLong1, mask).build();
92 Criterion matchPiLpmLong2 = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmLong2, mask).build();
93
94
95 byte[] matchTernaryBytes1 = {0x0a, 0x01, 0x01, 0x01};
96 byte[] matchTernaryBytes2 = {0x0a, 0x01, 0x01, 0x02};
97 byte[] matchTernaryMaskBytes = {0x7f, 0x7f, 0x7f, 0x00};
98 Criterion matchPiTernaryByte1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
99 matchTernaryBytes1,
100 matchTernaryMaskBytes)
101 .build();
102 Criterion sameAsMatchPiTernaryByte1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
103 matchTernaryBytes1,
104 matchTernaryMaskBytes)
105 .build();
106 Criterion matchPiTernaryByte2 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
107 matchTernaryBytes2,
108 matchTernaryMaskBytes)
109 .build();
110
111 short matchTernaryShort1 = 0x0a0a;
112 short matchTernaryShort2 = 0x0a0b;
113 short matchTernaryMaskShort = 0xff0;
114 Criterion matchPiTernaryShort1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
115 matchTernaryShort1,
116 matchTernaryMaskShort)
117 .build();
118 Criterion sameAsMatchPiTernaryShort1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
119 matchTernaryShort1,
120 matchTernaryMaskShort)
121 .build();
122 Criterion matchPiTernaryShort2 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
123 matchTernaryShort2,
124 matchTernaryMaskShort)
125 .build();
126
127 int matchTernaryInt1 = 0x0a010101;
128 int matchTernaryInt2 = 0x0a010102;
129 int matchTernaryMaskInt = 0xffff;
130 Criterion matchPiTernaryInt1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
131 matchTernaryInt1,
132 matchTernaryMaskInt)
133 .build();
134 Criterion sameAsMatchPiTernaryInt1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
135 matchTernaryInt1,
136 matchTernaryMaskInt)
137 .build();
138 Criterion matchPiTernaryInt2 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
139 matchTernaryInt2,
140 matchTernaryMaskInt)
141 .build();
142
143 long matchTernaryLong1 = 0x0a010101;
144 long matchTernaryLong2 = 0x0a010102;
145 long matchTernaryMaskLong = 0xffff;
146 Criterion matchPiTernaryLong1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
147 matchTernaryLong1,
148 matchTernaryMaskLong)
149 .build();
150 Criterion sameAsMatchPiTernaryLong1 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
151 matchTernaryLong1,
152 matchTernaryMaskLong)
153 .build();
154 Criterion matchPiTernaryLong2 = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId,
155 matchTernaryLong2,
156 matchTernaryMaskLong)
157 .build();
158
159 Criterion matchPiValid1 = PiCriterion.builder().matchValid(piIpv4HeaderFieldId, false).build();
160 Criterion sameAsMatchPiValid1 = PiCriterion.builder().matchValid(piIpv4HeaderFieldId, false).build();
161 Criterion matchPiValid2 = PiCriterion.builder().matchValid(piIpv4HeaderFieldId, true).build();
162
163 byte[] matchRangeBytes1 = {0x10};
164 byte[] matchRangeBytes2 = {0x20};
165 byte[] matchRangeHighBytes = {0x30};
166 Criterion matchPiRangeByte1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
167 matchRangeBytes1,
168 matchRangeHighBytes)
169 .build();
170 Criterion sameAsMatchPiRangeByte1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
171 matchRangeBytes1,
172 matchRangeHighBytes)
173 .build();
174 Criterion matchPiRangeByte2 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
175 matchRangeBytes2,
176 matchRangeHighBytes)
177 .build();
178
179 short matchRangeShort1 = 0x100;
180 short matchRangeShort2 = 0x200;
181 short matchRangeHighShort = 0x300;
182 Criterion matchPiRangeShort1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
183 matchRangeShort1,
184 matchRangeHighShort)
185 .build();
186 Criterion sameAsMatchPiRangeShort1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
187 matchRangeShort1,
188 matchRangeHighShort)
189 .build();
190 Criterion matchPiRangeShort2 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
191 matchRangeShort2,
192 matchRangeHighShort)
193 .build();
194
195 int matchRangeInt1 = 0x100;
196 int matchRangeInt2 = 0x200;
197 int matchRangeHighInt = 0x300;
198 Criterion matchPiRangeInt1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
199 matchRangeInt1,
200 matchRangeHighInt)
201 .build();
202 Criterion sameAsMatchPiRangeInt1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
203 matchRangeInt1,
204 matchRangeHighInt)
205 .build();
206 Criterion matchPiRangeInt2 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
207 matchRangeInt2,
208 matchRangeHighInt)
209 .build();
210
211 long matchRangeLong1 = 0x100;
212 long matchRangeLong2 = 0x200;
213 long matchRangeHighLong = 0x300;
214 Criterion matchPiRangeLong1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
215 matchRangeLong1,
216 matchRangeHighLong)
217 .build();
218 Criterion sameAsMatchPiRangeLong1 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
219 matchRangeLong1,
220 matchRangeHighLong)
221 .build();
222 Criterion matchPiRangeLong2 = PiCriterion.builder().matchRange(piIpv4HeaderFieldId,
223 matchRangeLong2,
224 matchRangeHighLong)
225 .build();
226
227 /**
228 * Checks that a Criterion object has the proper type, and then converts
229 * it to the proper type.
230 *
231 * @param criterion Criterion object to convert
232 * @param type Enumerated type value for the Criterion class
233 * @param clazz Desired Criterion class
234 * @param <T> The type the caller wants returned
235 * @return converted object
236 */
237 @SuppressWarnings("unchecked")
238 private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) {
239 assertThat(criterion, is(notNullValue()));
240 assertThat(criterion.type(), is(equalTo(type)));
241 assertThat(criterion, instanceOf(clazz));
242 return (T) criterion;
243 }
244
245 /**
246 * Test the ExactMatchPi method.
247 */
248 @Test
249 public void testExactMatchPiMethod() {
250
Frank Wange33e4ed2017-06-28 10:01:07 +0800251 Criterion matchPiBytes = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactBytes1).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800252 PiCriterion piCriterionBytes = checkAndConvert(matchPiBytes, Criterion.Type.PROTOCOL_INDEPENDENT,
253 PiCriterion.class);
254 PiFieldMatch expectedMatchBytes = new PiExactFieldMatch(piEthHeaderFieldId, copyFrom(matchExactBytes1));
255 assertThat(piCriterionBytes.fieldMatches().iterator().next(), is(expectedMatchBytes));
Frank Wange33e4ed2017-06-28 10:01:07 +0800256
257 Criterion matchPiShort = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactShort1).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800258 PiCriterion piCriterionShort = checkAndConvert(matchPiShort, Criterion.Type.PROTOCOL_INDEPENDENT,
259 PiCriterion.class);
260 PiFieldMatch expectedMatchShort = new PiExactFieldMatch(piEthHeaderFieldId, copyFrom(matchExactShort1));
261 assertThat(piCriterionShort.fieldMatches().iterator().next(), is(expectedMatchShort));
Frank Wange33e4ed2017-06-28 10:01:07 +0800262
263 Criterion matchPiInt = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactInt1).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800264 PiCriterion piCriterionInt = checkAndConvert(matchPiInt, Criterion.Type.PROTOCOL_INDEPENDENT,
265 PiCriterion.class);
266 PiFieldMatch expectedMatchInt = new PiExactFieldMatch(piEthHeaderFieldId, copyFrom(matchExactInt1));
267 assertThat(piCriterionInt.fieldMatches().iterator().next(), is(expectedMatchInt));
Frank Wange33e4ed2017-06-28 10:01:07 +0800268
269 Criterion matchPiLong = PiCriterion.builder().matchExact(piEthHeaderFieldId, matchExactLong1).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800270 PiCriterion piCriterionLong = checkAndConvert(matchPiLong, Criterion.Type.PROTOCOL_INDEPENDENT,
271 PiCriterion.class);
272 PiFieldMatch expectedMatchLong = new PiExactFieldMatch(piEthHeaderFieldId, copyFrom(matchExactLong1));
273 assertThat(piCriterionLong.fieldMatches().iterator().next(), is(expectedMatchLong));
Frank Wange33e4ed2017-06-28 10:01:07 +0800274 }
275
276 /**
277 * Test the LpmMatchPi method.
278 */
279 @Test
280 public void testLpmMatchPiMethod() {
281
Frank Wange33e4ed2017-06-28 10:01:07 +0800282 Criterion matchPiBytes = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmBytes1, mask).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800283 PiCriterion piCriterionBytes = checkAndConvert(matchPiBytes, Criterion.Type.PROTOCOL_INDEPENDENT,
284 PiCriterion.class);
285 PiFieldMatch expectedMatchBytes = new PiLpmFieldMatch(piIpv4HeaderFieldId, copyFrom(matchLpmBytes1), mask);
286 assertThat(piCriterionBytes.fieldMatches().iterator().next(), is(expectedMatchBytes));
Frank Wange33e4ed2017-06-28 10:01:07 +0800287
288 Criterion matchPiShort = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmShort1, mask).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800289 PiCriterion piCriterionShort = checkAndConvert(matchPiShort, Criterion.Type.PROTOCOL_INDEPENDENT,
290 PiCriterion.class);
291 PiFieldMatch expectedMatchShort = new PiLpmFieldMatch(piIpv4HeaderFieldId, copyFrom(matchLpmShort1), mask);
292 assertThat(piCriterionShort.fieldMatches().iterator().next(), is(expectedMatchShort));
Frank Wange33e4ed2017-06-28 10:01:07 +0800293
294 Criterion matchPiInt = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmInt1, mask).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800295 PiCriterion piCriterionInt = checkAndConvert(matchPiInt, Criterion.Type.PROTOCOL_INDEPENDENT,
296 PiCriterion.class);
297 PiFieldMatch expectedMatchInt = new PiLpmFieldMatch(piIpv4HeaderFieldId, copyFrom(matchLpmInt1), mask);
298 assertThat(piCriterionInt.fieldMatches().iterator().next(), is(expectedMatchInt));
Frank Wange33e4ed2017-06-28 10:01:07 +0800299
300 Criterion matchPiLong = PiCriterion.builder().matchLpm(piIpv4HeaderFieldId, matchLpmLong1, mask).build();
Frank Wang76057cd2017-07-15 10:22:03 +0800301 PiCriterion piCriterionLong = checkAndConvert(matchPiLong, Criterion.Type.PROTOCOL_INDEPENDENT,
302 PiCriterion.class);
303 PiFieldMatch expectedMatchLong = new PiLpmFieldMatch(piIpv4HeaderFieldId, copyFrom(matchLpmLong1), mask);
304 assertThat(piCriterionLong.fieldMatches().iterator().next(), is(expectedMatchLong));
Frank Wange33e4ed2017-06-28 10:01:07 +0800305 }
306
307 /**
308 * Test the TernaryMatchPi method.
309 */
310 @Test
311 public void testTernaryMatchPiMethod() {
Frank Wange33e4ed2017-06-28 10:01:07 +0800312
313 Criterion matchPiBytes = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId, matchTernaryBytes1,
314 matchTernaryMaskBytes)
315 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800316 PiCriterion piCriterionBytes = checkAndConvert(matchPiBytes, Criterion.Type.PROTOCOL_INDEPENDENT,
317 PiCriterion.class);
318 PiFieldMatch expectedMatchBytes = new PiTernaryFieldMatch(piIpv4HeaderFieldId, copyFrom(matchTernaryBytes1),
319 copyFrom(matchTernaryMaskBytes));
320 assertThat(piCriterionBytes.fieldMatches().iterator().next(), is(expectedMatchBytes));
Frank Wange33e4ed2017-06-28 10:01:07 +0800321
322 Criterion matchPiShort = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId, matchTernaryShort1,
323 matchTernaryMaskShort)
324 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800325 PiCriterion piCriterionShort = checkAndConvert(matchPiShort, Criterion.Type.PROTOCOL_INDEPENDENT,
326 PiCriterion.class);
327 PiFieldMatch expectedMatchShort = new PiTernaryFieldMatch(piIpv4HeaderFieldId, copyFrom(matchTernaryShort1),
328 copyFrom(matchTernaryMaskShort));
329 assertThat(piCriterionShort.fieldMatches().iterator().next(), is(expectedMatchShort));
Frank Wange33e4ed2017-06-28 10:01:07 +0800330
331 Criterion matchPiInt = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId, matchTernaryInt1,
332 matchTernaryMaskInt)
333 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800334 PiCriterion piCriterionInt = checkAndConvert(matchPiInt, Criterion.Type.PROTOCOL_INDEPENDENT,
335 PiCriterion.class);
336 PiFieldMatch expectedMatchInt = new PiTernaryFieldMatch(piIpv4HeaderFieldId, copyFrom(matchTernaryInt1),
337 copyFrom(matchTernaryMaskInt));
338 assertThat(piCriterionInt.fieldMatches().iterator().next(), is(expectedMatchInt));
Frank Wange33e4ed2017-06-28 10:01:07 +0800339
340 Criterion matchPiLong = PiCriterion.builder().matchTernary(piIpv4HeaderFieldId, matchTernaryLong1,
341 matchTernaryMaskLong)
342 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800343 PiCriterion piCriterionLong = checkAndConvert(matchPiLong, Criterion.Type.PROTOCOL_INDEPENDENT,
344 PiCriterion.class);
345 PiFieldMatch expectedMatchLong = new PiTernaryFieldMatch(piIpv4HeaderFieldId, copyFrom(matchTernaryLong1),
346 copyFrom(matchTernaryMaskLong));
347 assertThat(piCriterionLong.fieldMatches().iterator().next(), is(expectedMatchLong));
Frank Wange33e4ed2017-06-28 10:01:07 +0800348 }
349
350 /**
351 * Test the ValidMatchPi method.
352 */
353 @Test
354 public void testValidMatchPiMethod() {
Frank Wang76057cd2017-07-15 10:22:03 +0800355
Frank Wange33e4ed2017-06-28 10:01:07 +0800356 Criterion matchPiBytes = PiCriterion.builder().matchValid(piIpv4HeaderFieldId, true).build();
357 PiCriterion piCriterionBytes = checkAndConvert(matchPiBytes, Criterion.Type.PROTOCOL_INDEPENDENT,
358 PiCriterion.class);
Frank Wang76057cd2017-07-15 10:22:03 +0800359 PiFieldMatch expectedMatch = new PiValidFieldMatch(piIpv4HeaderFieldId, true);
360 assertThat(piCriterionBytes.fieldMatches().iterator().next(), is(expectedMatch));
Frank Wange33e4ed2017-06-28 10:01:07 +0800361 }
362
363 /**
364 * Test the RangeMatchPi method.
365 */
366 @Test
367 public void testRangeMatchPiMethod() {
Frank Wange33e4ed2017-06-28 10:01:07 +0800368
369 Criterion matchPiBytes = PiCriterion.builder().matchRange(piIpv4HeaderFieldId, matchRangeBytes1,
370 matchRangeHighBytes)
371 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800372 PiCriterion piCriterionBytes = checkAndConvert(matchPiBytes, Criterion.Type.PROTOCOL_INDEPENDENT,
373 PiCriterion.class);
374 PiFieldMatch expectedMatchBytes = new PiRangeFieldMatch(piIpv4HeaderFieldId, copyFrom(matchRangeBytes1),
375 copyFrom(matchRangeHighBytes));
376 assertThat(piCriterionBytes.fieldMatches().iterator().next(), is(expectedMatchBytes));
Frank Wange33e4ed2017-06-28 10:01:07 +0800377
378 Criterion matchPiShort = PiCriterion.builder().matchRange(piIpv4HeaderFieldId, matchRangeShort1,
379 matchRangeHighShort)
380 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800381 PiCriterion piCriterionShort = checkAndConvert(matchPiShort, Criterion.Type.PROTOCOL_INDEPENDENT,
382 PiCriterion.class);
383 PiFieldMatch expectedMatchShort = new PiRangeFieldMatch(piIpv4HeaderFieldId, copyFrom(matchRangeShort1),
384 copyFrom(matchRangeHighShort));
385 assertThat(piCriterionShort.fieldMatches().iterator().next(), is(expectedMatchShort));
Frank Wange33e4ed2017-06-28 10:01:07 +0800386
387 Criterion matchPiInt = PiCriterion.builder().matchRange(piIpv4HeaderFieldId, matchRangeInt1,
388 matchRangeHighInt)
389 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800390 PiCriterion piCriterionInt = checkAndConvert(matchPiInt, Criterion.Type.PROTOCOL_INDEPENDENT,
391 PiCriterion.class);
392 PiFieldMatch expectedMatchInt = new PiRangeFieldMatch(piIpv4HeaderFieldId, copyFrom(matchRangeInt1),
393 copyFrom(matchRangeHighInt));
394 assertThat(piCriterionInt.fieldMatches().iterator().next(), is(expectedMatchInt));
Frank Wange33e4ed2017-06-28 10:01:07 +0800395
396 Criterion matchPiLong = PiCriterion.builder().matchRange(piIpv4HeaderFieldId, matchRangeLong1,
397 matchRangeHighLong)
398 .build();
Frank Wang76057cd2017-07-15 10:22:03 +0800399 PiCriterion piCriterionLong = checkAndConvert(matchPiLong, Criterion.Type.PROTOCOL_INDEPENDENT,
400 PiCriterion.class);
401 PiFieldMatch expectedMatchLong = new PiRangeFieldMatch(piIpv4HeaderFieldId, copyFrom(matchRangeLong1),
402 copyFrom(matchRangeHighLong));
403 assertThat(piCriterionLong.fieldMatches().iterator().next(), is(expectedMatchLong));
Frank Wange33e4ed2017-06-28 10:01:07 +0800404 }
405
406 /**
407 * Test the equals() method of the PiCriterion class.
408 */
409 @Test
410 public void testPiExactCriterionEquals() {
411 new EqualsTester()
Carmelo Cascone22619172017-07-13 16:08:17 -0400412 .addEqualityGroup(matchPiExactByte1, sameAsMatchPiExactByte1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800413 .addEqualityGroup(matchPiExactByte2)
414 .testEquals();
415
416 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800417 .addEqualityGroup(matchPiExactShort1, sameAsMatchPiExactShort1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800418 .addEqualityGroup(matchPiExactShort2)
419 .testEquals();
420
421 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800422 .addEqualityGroup(matchPiExactInt1, sameAsMatchPiExactInt1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800423 .addEqualityGroup(matchPiExactInt2)
424 .testEquals();
425
426 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800427 .addEqualityGroup(matchPiExactLong1, sameAsMatchPiExactLong1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800428 .addEqualityGroup(matchPiExactLong2)
429 .testEquals();
430 }
431
432 /**
433 * Test the equals() method of the PiCriterion class.
434 */
435 @Test
436 public void testPiLpmCriterionEquals() {
437 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800438 .addEqualityGroup(matchPiLpmByte1, sameAsMatchPiLpmByte1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800439 .addEqualityGroup(matchPiLpmByte2)
440 .testEquals();
441
442 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800443 .addEqualityGroup(matchPiLpmShort1, sameAsMatchPiLpmShort1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800444 .addEqualityGroup(matchPiLpmShort2)
445 .testEquals();
446
447 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800448 .addEqualityGroup(matchPiLpmInt1, sameAsMatchPiLpmInt1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800449 .addEqualityGroup(matchPiLpmInt2)
450 .testEquals();
451
452 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800453 .addEqualityGroup(matchPiLpmLong1, sameAsMatchPiLpmLong1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800454 .addEqualityGroup(matchPiLpmLong2)
455 .testEquals();
456 }
457
458 /**
459 * Test the equals() method of the PiCriterion class.
460 */
461 @Test
462 public void testPiTernaryCriterionEquals() {
463 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800464 .addEqualityGroup(matchPiTernaryByte1, sameAsMatchPiTernaryByte1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800465 .addEqualityGroup(matchPiTernaryByte2)
466 .testEquals();
467
468 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800469 .addEqualityGroup(matchPiTernaryShort1, sameAsMatchPiTernaryShort1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800470 .addEqualityGroup(matchPiTernaryShort2)
471 .testEquals();
472
473 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800474 .addEqualityGroup(matchPiTernaryInt1, sameAsMatchPiTernaryInt1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800475 .addEqualityGroup(matchPiTernaryInt2)
476 .testEquals();
477
478 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800479 .addEqualityGroup(matchPiTernaryLong1, sameAsMatchPiTernaryLong1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800480 .addEqualityGroup(matchPiTernaryLong2)
481 .testEquals();
482 }
483
484 /**
485 * Test the equals() method of the PiCriterion class.
486 */
487 @Test
488 public void testPiValidCriterionEquals() {
489 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800490 .addEqualityGroup(matchPiValid1, sameAsMatchPiValid1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800491 .addEqualityGroup(matchPiValid2)
492 .testEquals();
493 }
494
495 /**
496 * Test the equals() method of the PiCriterion class.
497 */
498 @Test
499 public void testPiRangeCriterionEquals() {
500 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800501 .addEqualityGroup(matchPiRangeByte1, sameAsMatchPiRangeByte1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800502 .addEqualityGroup(matchPiRangeByte2)
503 .testEquals();
504
505 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800506 .addEqualityGroup(matchPiRangeShort1, sameAsMatchPiRangeShort1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800507 .addEqualityGroup(matchPiRangeShort2)
508 .testEquals();
509
510 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800511 .addEqualityGroup(matchPiRangeInt1, sameAsMatchPiRangeInt1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800512 .addEqualityGroup(matchPiRangeInt2)
513 .testEquals();
514
515 new EqualsTester()
Frank Wang76057cd2017-07-15 10:22:03 +0800516 .addEqualityGroup(matchPiRangeLong1, sameAsMatchPiRangeLong1)
Frank Wange33e4ed2017-06-28 10:01:07 +0800517 .addEqualityGroup(matchPiRangeLong2)
518 .testEquals();
519 }
520}