blob: 3cebd8eb29884460b2d98439e51fb102babdaea4 [file] [log] [blame]
Ray Milkey33d90232014-11-04 10:49:00 -08001/*
2 * Copyright 2014 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow.criteria;
Ray Milkey33d90232014-11-04 10:49:00 -080017
18import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.PortNumber;
Ray Milkey33d90232014-11-04 10:49:00 -080020import org.onlab.packet.IpPrefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080021import org.onlab.packet.Ip6Address;
Ray Milkey33d90232014-11-04 10:49:00 -080022import org.onlab.packet.MacAddress;
23import org.onlab.packet.VlanId;
24
Ray Milkeyfff20b52014-11-06 14:45:10 -080025import com.google.common.testing.EqualsTester;
26
Ray Milkey33d90232014-11-04 10:49:00 -080027import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey33d90232014-11-04 10:49:00 -080028import static org.hamcrest.Matchers.equalTo;
29import static org.hamcrest.Matchers.instanceOf;
30import static org.hamcrest.Matchers.is;
Ray Milkey33d90232014-11-04 10:49:00 -080031import static org.hamcrest.Matchers.notNullValue;
32import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
33import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import static org.onosproject.net.PortNumber.portNumber;
Ray Milkey33d90232014-11-04 10:49:00 -080035
36/**
37 * Unit tests for the Criteria class and its subclasses.
38 */
39public class CriteriaTest {
40
41 final PortNumber port1 = portNumber(1);
42 final PortNumber port2 = portNumber(2);
43
44 Criterion matchInPort1 = Criteria.matchInPort(port1);
45 Criterion sameAsMatchInPort1 = Criteria.matchInPort(port1);
46 Criterion matchInPort2 = Criteria.matchInPort(port2);
47
Ray Milkey33d90232014-11-04 10:49:00 -080048 private static final String MAC1 = "00:00:00:00:00:01";
49 private static final String MAC2 = "00:00:00:00:00:02";
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080050 private MacAddress mac1 = MacAddress.valueOf(MAC1);
51 private MacAddress mac2 = MacAddress.valueOf(MAC2);
Ray Milkey33d90232014-11-04 10:49:00 -080052 Criterion matchEth1 = Criteria.matchEthSrc(mac1);
53 Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1);
54 Criterion matchEth2 = Criteria.matchEthDst(mac2);
55
56 short ethType1 = 1;
57 short ethType2 = 2;
58 Criterion matchEthType1 = Criteria.matchEthType(ethType1);
59 Criterion sameAsMatchEthType1 = Criteria.matchEthType(ethType1);
60 Criterion matchEthType2 = Criteria.matchEthType(ethType2);
61
62 short vlan1 = 1;
63 short vlan2 = 2;
64 VlanId vlanId1 = VlanId.vlanId(vlan1);
65 VlanId vlanId2 = VlanId.vlanId(vlan2);
66 Criterion matchVlanId1 = Criteria.matchVlanId(vlanId1);
67 Criterion sameAsMatchVlanId1 = Criteria.matchVlanId(vlanId1);
68 Criterion matchVlanId2 = Criteria.matchVlanId(vlanId2);
69
70 byte vlanPcp1 = 1;
71 byte vlanPcp2 = 2;
72 Criterion matchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
73 Criterion sameAsMatchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
74 Criterion matchVlanPcp2 = Criteria.matchVlanPcp(vlanPcp2);
75
76 byte protocol1 = 1;
77 byte protocol2 = 2;
78 Criterion matchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
79 Criterion sameAsMatchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
80 Criterion matchIpProtocol2 = Criteria.matchIPProtocol(protocol2);
81
82 private static final String IP1 = "1.2.3.4/24";
83 private static final String IP2 = "5.6.7.8/24";
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080084 private static final String IPV61 = "fe80::1/64";
85 private static final String IPV62 = "fc80::2/64";
Ray Milkey33d90232014-11-04 10:49:00 -080086 private IpPrefix ip1 = IpPrefix.valueOf(IP1);
87 private IpPrefix ip2 = IpPrefix.valueOf(IP2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080088 private IpPrefix ipv61 = IpPrefix.valueOf(IPV61);
89 private IpPrefix ipv62 = IpPrefix.valueOf(IPV62);
Ray Milkey33d90232014-11-04 10:49:00 -080090 Criterion matchIp1 = Criteria.matchIPSrc(ip1);
91 Criterion sameAsMatchIp1 = Criteria.matchIPSrc(ip1);
92 Criterion matchIp2 = Criteria.matchIPSrc(ip2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +080093 Criterion matchIpv61 = Criteria.matchIPSrc(ipv61);
94 Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
95 Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
Ray Milkey33d90232014-11-04 10:49:00 -080096
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080097 Criterion matchTcpPort1 = Criteria.matchTcpSrc((short) 1);
98 Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc((short) 1);
99 Criterion matchTcpPort2 = Criteria.matchTcpDst((short) 2);
100
101 Criterion matchUdpPort1 = Criteria.matchUdpSrc((short) 1);
102 Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc((short) 1);
103 Criterion matchUdpPort2 = Criteria.matchUdpDst((short) 2);
104
105 Criterion matchSctpPort1 = Criteria.matchSctpSrc((short) 1);
106 Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc((short) 1);
107 Criterion matchSctpPort2 = Criteria.matchSctpDst((short) 2);
108
109 byte icmpType1 = 1;
110 byte icmpType2 = 2;
111 Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1);
112 Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1);
113 Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2);
114
115 byte icmpCode1 = 1;
116 byte icmpCode2 = 2;
117 Criterion matchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
118 Criterion sameAsMatchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
119 Criterion matchIcmpCode2 = Criteria.matchIcmpCode(icmpCode2);
120
121 int flowLabel1 = 1;
122 int flowLabel2 = 2;
123 Criterion matchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
124 Criterion sameAsMatchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
125 Criterion matchFlowLabel2 = Criteria.matchIPv6FlowLabel(flowLabel2);
126
127 byte icmpv6Type1 = 1;
128 byte icmpv6Type2 = 2;
129 Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
130 Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
131 Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2);
132
133 byte icmpv6Code1 = 1;
134 byte icmpv6Code2 = 2;
135 Criterion matchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
136 Criterion sameAsMatchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
137 Criterion matchIcmpv6Code2 = Criteria.matchIcmpv6Code(icmpv6Code2);
138
139 private static final String IPV6_ADDR1 = "fe80::1";
140 private static final String IPV6_ADDR2 = "fe80::2";
141 private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
142 private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
143 Criterion matchIpv6TargetAddr1 =
144 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
145 Criterion sameAsMatchIpv6TargetAddr1 =
146 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
147 Criterion matchIpv6TargetAddr2 =
148 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
149
150 private static final String LL_MAC1 = "00:00:00:00:00:01";
151 private static final String LL_MAC2 = "00:00:00:00:00:02";
152 private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
153 private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
154 Criterion matchSrcLlAddr1 =
155 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
156 Criterion sameAsMatchSrcLlAddr1 =
157 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
158 Criterion matchSrcLlAddr2 =
159 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
160 Criterion matchTargetLlAddr1 =
161 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
162 Criterion sameAsMatchTargetLlAddr1 =
163 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
164 Criterion matchTargetLlAddr2 =
165 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
166
167 int mpls1 = 1;
168 int mpls2 = 2;
169 Criterion matchMpls1 = Criteria.matchMplsLabel(mpls1);
170 Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1);
171 Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2);
172
Ray Milkey33d90232014-11-04 10:49:00 -0800173 short lambda1 = 1;
174 short lambda2 = 2;
175 Criterion matchLambda1 = Criteria.matchLambda(lambda1);
176 Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1);
177 Criterion matchLambda2 = Criteria.matchLambda(lambda2);
178
Ray Milkey9d078652014-11-05 10:35:54 -0800179 short signalLambda1 = 1;
180 short signalLambda2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -0800181 Criterion matchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
182 Criterion sameAsMatchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
183 Criterion matchSignalLambda2 = Criteria.matchOpticalSignalType(signalLambda2);
184
185 /**
186 * Checks that a Criterion object has the proper type, and then converts
187 * it to the proper type.
188 *
189 * @param criterion Criterion object to convert
190 * @param type Enumerated type value for the Criterion class
191 * @param clazz Desired Criterion class
192 * @param <T> The type the caller wants returned
193 * @return converted object
194 */
195 @SuppressWarnings("unchecked")
196 private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) {
197 assertThat(criterion, is(notNullValue()));
198 assertThat(criterion.type(), is(equalTo(type)));
Ray Milkey78081052014-11-05 10:38:12 -0800199 assertThat(criterion, instanceOf(clazz));
Ray Milkey33d90232014-11-04 10:49:00 -0800200 return (T) criterion;
201 }
202
203 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800204 * Check that the Criteria class is a valid utility class.
205 */
206 @Test
207 public void testCriteriaUtility() {
208 assertThatClassIsUtility(Criteria.class);
209 }
210
211 /**
212 * Check that the Criteria implementations are immutable.
213 */
214 @Test
215 public void testCriteriaImmutability() {
216 assertThatClassIsImmutable(Criteria.PortCriterion.class);
217 assertThatClassIsImmutable(Criteria.EthCriterion.class);
218 assertThatClassIsImmutable(Criteria.EthTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800219 assertThatClassIsImmutable(Criteria.VlanIdCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800220 assertThatClassIsImmutable(Criteria.VlanPcpCriterion.class);
221 assertThatClassIsImmutable(Criteria.IPProtocolCriterion.class);
222 assertThatClassIsImmutable(Criteria.IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800223 assertThatClassIsImmutable(Criteria.TcpPortCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800224 assertThatClassIsImmutable(Criteria.UdpPortCriterion.class);
225 assertThatClassIsImmutable(Criteria.SctpPortCriterion.class);
226 assertThatClassIsImmutable(Criteria.IcmpTypeCriterion.class);
227 assertThatClassIsImmutable(Criteria.IcmpCodeCriterion.class);
228 assertThatClassIsImmutable(Criteria.IPv6FlowLabelCriterion.class);
229 assertThatClassIsImmutable(Criteria.Icmpv6TypeCriterion.class);
230 assertThatClassIsImmutable(Criteria.Icmpv6CodeCriterion.class);
231 assertThatClassIsImmutable(Criteria.IPv6NDTargetAddressCriterion.class);
232 assertThatClassIsImmutable(Criteria.IPv6NDLinkLayerAddressCriterion.class);
233 assertThatClassIsImmutable(Criteria.MplsCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800234 assertThatClassIsImmutable(Criteria.LambdaCriterion.class);
235 assertThatClassIsImmutable(Criteria.OpticalSignalTypeCriterion.class);
236 }
237
238 // PortCriterion class
239
240 /**
241 * Test the matchInPort method.
242 */
243 @Test
244 public void testMatchInPortMethod() {
245 PortNumber p1 = portNumber(1);
246 Criterion matchInPort = Criteria.matchInPort(p1);
247 Criteria.PortCriterion portCriterion =
248 checkAndConvert(matchInPort,
249 Criterion.Type.IN_PORT,
250 Criteria.PortCriterion.class);
251 assertThat(portCriterion.port(), is(equalTo(p1)));
252 }
253
254 /**
255 * Test the equals() method of the PortCriterion class.
256 */
257 @Test
258 public void testPortCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800259 new EqualsTester()
260 .addEqualityGroup(matchInPort1, sameAsMatchInPort1)
261 .addEqualityGroup(matchInPort2)
262 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800263 }
264
265 // EthCriterion class
266
267 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800268 * Test the matchEthDst method.
269 */
270 @Test
271 public void testMatchEthDstMethod() {
272 Criterion matchEthDst = Criteria.matchEthDst(mac1);
273 Criteria.EthCriterion ethCriterion =
274 checkAndConvert(matchEthDst,
275 Criterion.Type.ETH_DST,
276 Criteria.EthCriterion.class);
277 assertThat(ethCriterion.mac(), is(equalTo(mac1)));
278 }
279
280 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800281 * Test the matchEthSrc method.
282 */
283 @Test
284 public void testMatchEthSrcMethod() {
285 Criterion matchEthSrc = Criteria.matchEthSrc(mac1);
286 Criteria.EthCriterion ethCriterion =
287 checkAndConvert(matchEthSrc,
288 Criterion.Type.ETH_SRC,
289 Criteria.EthCriterion.class);
290 assertThat(ethCriterion.mac(), is(mac1));
291 }
292
293 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800294 * Test the equals() method of the EthCriterion class.
295 */
296 @Test
297 public void testEthCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800298 new EqualsTester()
299 .addEqualityGroup(matchEth1, sameAsMatchEth1)
300 .addEqualityGroup(matchEth2)
301 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800302 }
303
Ray Milkey33d90232014-11-04 10:49:00 -0800304 // EthTypeCriterion class
305
306 /**
307 * Test the matchEthType method.
308 */
309 @Test
310 public void testMatchEthTypeMethod() {
311 Short ethType = 12;
312 Criterion matchEthType = Criteria.matchEthType(ethType);
313 Criteria.EthTypeCriterion ethTypeCriterion =
314 checkAndConvert(matchEthType,
315 Criterion.Type.ETH_TYPE,
316 Criteria.EthTypeCriterion.class);
317 assertThat(ethTypeCriterion.ethType(), is(equalTo(ethType)));
318 }
319
320 /**
321 * Test the equals() method of the EthTypeCriterion class.
322 */
323 @Test
324 public void testEthTypeCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800325 new EqualsTester()
326 .addEqualityGroup(matchEthType1, sameAsMatchEthType1)
327 .addEqualityGroup(matchEthType2)
328 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800329 }
330
Ray Milkey33d90232014-11-04 10:49:00 -0800331 // VlanIdCriterion class
332
333 /**
334 * Test the matchVlanId method.
335 */
336 @Test
337 public void testMatchVlanIdMethod() {
338 Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
339 Criteria.VlanIdCriterion vlanIdCriterion =
340 checkAndConvert(matchVlanId,
341 Criterion.Type.VLAN_VID,
342 Criteria.VlanIdCriterion.class);
343 assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
344 }
345
346 /**
347 * Test the equals() method of the VlanIdCriterion class.
348 */
349 @Test
350 public void testVlanIdCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800351 new EqualsTester()
352 .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1)
353 .addEqualityGroup(matchVlanId2)
354 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800355 }
356
357 // VlanPcpCriterion class
358
359 /**
360 * Test the matchVlanPcp method.
361 */
362 @Test
363 public void testMatchVlanPcpMethod() {
364 Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
365 Criteria.VlanPcpCriterion vlanPcpCriterion =
366 checkAndConvert(matchVlanPcp,
367 Criterion.Type.VLAN_PCP,
368 Criteria.VlanPcpCriterion.class);
369 assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
370 }
371
372 /**
373 * Test the equals() method of the VlanPcpCriterion class.
374 */
375 @Test
376 public void testVlanPcpCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800377 new EqualsTester()
378 .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1)
379 .addEqualityGroup(matchVlanPcp2)
380 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800381 }
382
383 // IpProtocolCriterion class
384
385 /**
386 * Test the matchIpProtocol method.
387 */
388 @Test
389 public void testMatchIpProtocolMethod() {
390 Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
391 Criteria.IPProtocolCriterion ipProtocolCriterion =
392 checkAndConvert(matchIPProtocol,
393 Criterion.Type.IP_PROTO,
394 Criteria.IPProtocolCriterion.class);
395 assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
396 }
397
398 /**
399 * Test the equals() method of the IpProtocolCriterion class.
400 */
401 @Test
402 public void testIpProtocolCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800403 new EqualsTester()
404 .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1)
405 .addEqualityGroup(matchIpProtocol2)
406 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800407 }
408
409 // IPCriterion class
410
411 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800412 * Test the matchIPSrc method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800413 */
414 @Test
415 public void testMatchIPSrcMethod() {
416 Criterion matchIpSrc = Criteria.matchIPSrc(ip1);
417 Criteria.IPCriterion ipCriterion =
418 checkAndConvert(matchIpSrc,
419 Criterion.Type.IPV4_SRC,
420 Criteria.IPCriterion.class);
421 assertThat(ipCriterion.ip(), is(ip1));
422 }
423
424 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800425 * Test the matchIPDst method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800426 */
427 @Test
428 public void testMatchIPDstMethod() {
429 Criterion matchIPDst = Criteria.matchIPDst(ip1);
430 Criteria.IPCriterion ipCriterion =
431 checkAndConvert(matchIPDst,
432 Criterion.Type.IPV4_DST,
433 Criteria.IPCriterion.class);
434 assertThat(ipCriterion.ip(), is(equalTo(ip1)));
435 }
436
437 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800438 * Test the matchIPSrc method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800439 */
440 @Test
441 public void testMatchIPv6SrcMethod() {
442 Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
443 Criteria.IPCriterion ipCriterion =
444 checkAndConvert(matchIpv6Src,
445 Criterion.Type.IPV6_SRC,
446 Criteria.IPCriterion.class);
447 assertThat(ipCriterion.ip(), is(ipv61));
448 }
449
450 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800451 * Test the matchIPDst method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800452 */
453 @Test
454 public void testMatchIPv6DstMethod() {
455 Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
456 Criteria.IPCriterion ipCriterion =
457 checkAndConvert(matchIPv6Dst,
458 Criterion.Type.IPV6_DST,
459 Criteria.IPCriterion.class);
460 assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
461 }
462
463 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800464 * Test the equals() method of the IpCriterion class.
465 */
466 @Test
467 public void testIPCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800468 new EqualsTester()
469 .addEqualityGroup(matchIp1, sameAsMatchIp1)
470 .addEqualityGroup(matchIp2)
471 .testEquals();
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800472
473 new EqualsTester()
474 .addEqualityGroup(matchIpv61, sameAsMatchIpv61)
475 .addEqualityGroup(matchIpv62)
476 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800477 }
478
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800479 // TcpPortCriterion class
480
481 /**
482 * Test the matchTcpSrc method.
483 */
484 @Test
485 public void testMatchTcpSrcMethod() {
486 Criterion matchTcpSrc = Criteria.matchTcpSrc((short) 1);
487 Criteria.TcpPortCriterion tcpPortCriterion =
488 checkAndConvert(matchTcpSrc,
489 Criterion.Type.TCP_SRC,
490 Criteria.TcpPortCriterion.class);
491 assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
492 }
493
494 /**
495 * Test the matchTcpDst method.
496 */
497 @Test
498 public void testMatchTcpDstMethod() {
499 Criterion matchTcpDst = Criteria.matchTcpDst((short) 1);
500 Criteria.TcpPortCriterion tcpPortCriterion =
501 checkAndConvert(matchTcpDst,
502 Criterion.Type.TCP_DST,
503 Criteria.TcpPortCriterion.class);
504 assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
505 }
506
507 /**
508 * Test the equals() method of the TcpPortCriterion class.
509 */
510 @Test
511 public void testTcpPortCriterionEquals() {
512 new EqualsTester()
513 .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
514 .addEqualityGroup(matchTcpPort2)
515 .testEquals();
516 }
517
518 // UdpPortCriterion class
519
520 /**
521 * Test the matchUdpSrc method.
522 */
523 @Test
524 public void testMatchUdpSrcMethod() {
525 Criterion matchUdpSrc = Criteria.matchUdpSrc((short) 1);
526 Criteria.UdpPortCriterion udpPortCriterion =
527 checkAndConvert(matchUdpSrc,
528 Criterion.Type.UDP_SRC,
529 Criteria.UdpPortCriterion.class);
530 assertThat(udpPortCriterion.udpPort(), is(equalTo((short) 1)));
531 }
532
533 /**
534 * Test the matchUdpDst method.
535 */
536 @Test
537 public void testMatchUdpDstMethod() {
538 Criterion matchUdpDst = Criteria.matchUdpDst((short) 1);
539 Criteria.UdpPortCriterion udpPortCriterion =
540 checkAndConvert(matchUdpDst,
541 Criterion.Type.UDP_DST,
542 Criteria.UdpPortCriterion.class);
543 assertThat(udpPortCriterion.udpPort(), is(equalTo((short) 1)));
544 }
545
546 /**
547 * Test the equals() method of the UdpPortCriterion class.
548 */
549 @Test
550 public void testUdpPortCriterionEquals() {
551 new EqualsTester()
552 .addEqualityGroup(matchUdpPort1, sameAsMatchUdpPort1)
553 .addEqualityGroup(matchUdpPort2)
554 .testEquals();
555 }
556
557 // SctpPortCriterion class
558
559 /**
560 * Test the matchSctpSrc method.
561 */
562 @Test
563 public void testMatchSctpSrcMethod() {
564 Criterion matchSctpSrc = Criteria.matchSctpSrc((short) 1);
565 Criteria.SctpPortCriterion sctpPortCriterion =
566 checkAndConvert(matchSctpSrc,
567 Criterion.Type.SCTP_SRC,
568 Criteria.SctpPortCriterion.class);
569 assertThat(sctpPortCriterion.sctpPort(), is(equalTo((short) 1)));
570 }
571
572 /**
573 * Test the matchSctpDst method.
574 */
575 @Test
576 public void testMatchSctpDstMethod() {
577 Criterion matchSctpDst = Criteria.matchSctpDst((short) 1);
578 Criteria.SctpPortCriterion sctpPortCriterion =
579 checkAndConvert(matchSctpDst,
580 Criterion.Type.SCTP_DST,
581 Criteria.SctpPortCriterion.class);
582 assertThat(sctpPortCriterion.sctpPort(), is(equalTo((short) 1)));
583 }
584
585 /**
586 * Test the equals() method of the SctpPortCriterion class.
587 */
588 @Test
589 public void testSctpPortCriterionEquals() {
590 new EqualsTester()
591 .addEqualityGroup(matchSctpPort1, sameAsMatchSctpPort1)
592 .addEqualityGroup(matchSctpPort2)
593 .testEquals();
594 }
595
596 // IcmpTypeCriterion class
597
598 /**
599 * Test the matchIcmpType method.
600 */
601 @Test
602 public void testMatchIcmpTypeMethod() {
603 Byte icmpType = 12;
604 Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
605 Criteria.IcmpTypeCriterion icmpTypeCriterion =
606 checkAndConvert(matchIcmpType,
607 Criterion.Type.ICMPV4_TYPE,
608 Criteria.IcmpTypeCriterion.class);
609 assertThat(icmpTypeCriterion.icmpType(), is(equalTo(icmpType)));
610 }
611
612 /**
613 * Test the equals() method of the IcmpTypeCriterion class.
614 */
615 @Test
616 public void testIcmpTypeCriterionEquals() {
617 new EqualsTester()
618 .addEqualityGroup(matchIcmpType1, sameAsMatchIcmpType1)
619 .addEqualityGroup(matchIcmpType2)
620 .testEquals();
621 }
622
623 // IcmpCodeCriterion class
624
625 /**
626 * Test the matchIcmpCode method.
627 */
628 @Test
629 public void testMatchIcmpCodeMethod() {
630 Byte icmpCode = 12;
631 Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
632 Criteria.IcmpCodeCriterion icmpCodeCriterion =
633 checkAndConvert(matchIcmpCode,
634 Criterion.Type.ICMPV4_CODE,
635 Criteria.IcmpCodeCriterion.class);
636 assertThat(icmpCodeCriterion.icmpCode(), is(equalTo(icmpCode)));
637 }
638
639 /**
640 * Test the equals() method of the IcmpCodeCriterion class.
641 */
642 @Test
643 public void testIcmpCodeCriterionEquals() {
644 new EqualsTester()
645 .addEqualityGroup(matchIcmpCode1, sameAsMatchIcmpCode1)
646 .addEqualityGroup(matchIcmpCode2)
647 .testEquals();
648 }
649
650 // IPv6FlowLabelCriterion class
651
652 /**
653 * Test the matchIPv6FlowLabel method.
654 */
655 @Test
656 public void testMatchIPv6FlowLabelMethod() {
657 Integer flowLabel = 12;
658 Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
659 Criteria.IPv6FlowLabelCriterion flowLabelCriterion =
660 checkAndConvert(matchFlowLabel,
661 Criterion.Type.IPV6_FLABEL,
662 Criteria.IPv6FlowLabelCriterion.class);
663 assertThat(flowLabelCriterion.flowLabel(), is(equalTo(flowLabel)));
664 }
665
666 /**
667 * Test the equals() method of the IPv6FlowLabelCriterion class.
668 */
669 @Test
670 public void testIPv6FlowLabelCriterionEquals() {
671 new EqualsTester()
672 .addEqualityGroup(matchFlowLabel1, sameAsMatchFlowLabel1)
673 .addEqualityGroup(matchFlowLabel2)
674 .testEquals();
675 }
676
677 // Icmpv6TypeCriterion class
678
679 /**
680 * Test the matchIcmpv6Type method.
681 */
682 @Test
683 public void testMatchIcmpv6TypeMethod() {
684 Byte icmpv6Type = 12;
685 Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
686 Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
687 checkAndConvert(matchIcmpv6Type,
688 Criterion.Type.ICMPV6_TYPE,
689 Criteria.Icmpv6TypeCriterion.class);
690 assertThat(icmpv6TypeCriterion.icmpv6Type(), is(equalTo(icmpv6Type)));
691 }
692
693 /**
694 * Test the equals() method of the Icmpv6TypeCriterion class.
695 */
696 @Test
697 public void testIcmpv6TypeCriterionEquals() {
698 new EqualsTester()
699 .addEqualityGroup(matchIcmpv6Type1, sameAsMatchIcmpv6Type1)
700 .addEqualityGroup(matchIcmpv6Type2)
701 .testEquals();
702 }
703
704 // Icmpv6CodeCriterion class
705
706 /**
707 * Test the matchIcmpv6Code method.
708 */
709 @Test
710 public void testMatchIcmpv6CodeMethod() {
711 Byte icmpv6Code = 12;
712 Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
713 Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
714 checkAndConvert(matchIcmpv6Code,
715 Criterion.Type.ICMPV6_CODE,
716 Criteria.Icmpv6CodeCriterion.class);
717 assertThat(icmpv6CodeCriterion.icmpv6Code(), is(equalTo(icmpv6Code)));
718 }
719
720 /**
721 * Test the equals() method of the Icmpv6CodeCriterion class.
722 */
723 @Test
724 public void testIcmpv6CodeCriterionEquals() {
725 new EqualsTester()
726 .addEqualityGroup(matchIcmpv6Code1, sameAsMatchIcmpv6Code1)
727 .addEqualityGroup(matchIcmpv6Code2)
728 .testEquals();
729 }
730
731 // IPv6NDTargetAddressCriterion class
732
733 /**
734 * Test the matchIPv6NDTargetAddress method.
735 */
736 @Test
737 public void testMatchIPv6NDTargetAddressMethod() {
738 Criterion matchTargetAddress =
739 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
740 Criteria.IPv6NDTargetAddressCriterion targetAddressCriterion =
741 checkAndConvert(matchTargetAddress,
742 Criterion.Type.IPV6_ND_TARGET,
743 Criteria.IPv6NDTargetAddressCriterion.class);
744 assertThat(targetAddressCriterion.targetAddress(),
745 is(ip6TargetAddress1));
746 }
747
748 /**
749 * Test the equals() method of the IPv6NDTargetAddressCriterion class.
750 */
751 @Test
752 public void testIPv6NDTargetAddressCriterionEquals() {
753 new EqualsTester()
754 .addEqualityGroup(matchIpv6TargetAddr1,
755 sameAsMatchIpv6TargetAddr1)
756 .addEqualityGroup(matchIpv6TargetAddr2)
757 .testEquals();
758 }
759
760 // IPv6NDLinkLayerAddressCriterion class
761
762 /**
763 * Test the matchIPv6NDSourceLinkLayerAddress method.
764 */
765 @Test
766 public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
767 Criterion matchSrcLlAddr =
768 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
769 Criteria.IPv6NDLinkLayerAddressCriterion srcLlCriterion =
770 checkAndConvert(matchSrcLlAddr,
771 Criterion.Type.IPV6_ND_SLL,
772 Criteria.IPv6NDLinkLayerAddressCriterion.class);
773 assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
774 }
775
776 /**
777 * Test the matchIPv6NDTargetLinkLayerAddress method.
778 */
779 @Test
780 public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
781 Criterion matchTargetLlAddr =
782 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
783 Criteria.IPv6NDLinkLayerAddressCriterion targetLlCriterion =
784 checkAndConvert(matchTargetLlAddr,
785 Criterion.Type.IPV6_ND_TLL,
786 Criteria.IPv6NDLinkLayerAddressCriterion.class);
787 assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
788 }
789
790 /**
791 * Test the equals() method of the IPv6NDLinkLayerAddressCriterion class.
792 */
793 @Test
794 public void testIPv6NDLinkLayerAddressCriterionEquals() {
795 new EqualsTester()
796 .addEqualityGroup(matchSrcLlAddr1, sameAsMatchSrcLlAddr1)
797 .addEqualityGroup(matchSrcLlAddr2)
798 .testEquals();
799
800 new EqualsTester()
801 .addEqualityGroup(matchTargetLlAddr1, sameAsMatchTargetLlAddr1)
802 .addEqualityGroup(matchTargetLlAddr2)
803 .testEquals();
804 }
805
806 // MplsCriterion class
807
808 /**
809 * Test the matchMplsLabel method.
810 */
811 @Test
812 public void testMatchMplsLabelMethod() {
813 Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
814 Criteria.MplsCriterion mplsCriterion =
815 checkAndConvert(matchMplsLabel,
816 Criterion.Type.MPLS_LABEL,
817 Criteria.MplsCriterion.class);
818 assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
819 }
820
821 /**
822 * Test the equals() method of the MplsCriterion class.
823 */
824 @Test
825 public void testMplsCriterionEquals() {
826 new EqualsTester()
827 .addEqualityGroup(matchMpls1, sameAsMatchMpls1)
828 .addEqualityGroup(matchMpls2)
829 .testEquals();
830 }
831
Ray Milkey33d90232014-11-04 10:49:00 -0800832 // LambdaCriterion class
833
834 /**
835 * Test the matchLambda method.
836 */
837 @Test
838 public void testMatchLambdaMethod() {
839 Criterion matchLambda = Criteria.matchLambda(lambda1);
840 Criteria.LambdaCriterion lambdaCriterion =
841 checkAndConvert(matchLambda,
842 Criterion.Type.OCH_SIGID,
843 Criteria.LambdaCriterion.class);
844 assertThat(lambdaCriterion.lambda(), is(equalTo(lambda1)));
845 }
846
847 /**
848 * Test the equals() method of the LambdaCriterion class.
849 */
850 @Test
851 public void testLambdaCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800852 new EqualsTester()
853 .addEqualityGroup(matchLambda1, sameAsMatchLambda1)
854 .addEqualityGroup(matchLambda2)
855 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800856 }
857
858 // OpticalSignalTypeCriterion class
859
860 /**
861 * Test the matchOpticalSignalType method.
862 */
863 @Test
864 public void testMatchOpticalSignalTypeMethod() {
865 Criterion matchLambda = Criteria.matchOpticalSignalType(signalLambda1);
866 Criteria.OpticalSignalTypeCriterion opticalSignalTypeCriterion =
867 checkAndConvert(matchLambda,
868 Criterion.Type.OCH_SIGTYPE,
869 Criteria.OpticalSignalTypeCriterion.class);
870 assertThat(opticalSignalTypeCriterion.signalType(), is(equalTo(signalLambda1)));
871 }
872
873 /**
874 * Test the equals() method of the OpticalSignalTypeCriterion class.
875 */
876 @Test
877 public void testOpticalSignalTypeCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800878 new EqualsTester()
879 .addEqualityGroup(matchSignalLambda1, sameAsMatchSignalLambda1)
880 .addEqualityGroup(matchSignalLambda2)
881 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800882 }
Ray Milkey33d90232014-11-04 10:49:00 -0800883}