blob: 95d605c68258c60830ff4d75c48d150db5bffdbc [file] [log] [blame]
Ray Milkey33d90232014-11-04 10:49:00 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Ray Milkey33d90232014-11-04 10:49:00 -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 */
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;
alshabibcaf1ca22015-06-25 15:18:16 -070019import org.onlab.packet.EthType;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070020import org.onlab.packet.Ip6Address;
21import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.MplsLabel;
24import org.onlab.packet.TpPort;
25import org.onlab.packet.VlanId;
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -070026import org.onosproject.net.ChannelSpacing;
27import org.onosproject.net.GridType;
28import org.onosproject.net.Lambda;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.PortNumber;
Ray Milkey33d90232014-11-04 10:49:00 -080030
Ray Milkeyfff20b52014-11-06 14:45:10 -080031import com.google.common.testing.EqualsTester;
Sho SHIMIZU585bed92015-05-13 11:08:45 -070032import org.onosproject.net.OchSignalType;
Ray Milkeyfff20b52014-11-06 14:45:10 -080033
Ray Milkey33d90232014-11-04 10:49:00 -080034import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkey33d90232014-11-04 10:49:00 -080035import static org.hamcrest.Matchers.equalTo;
36import static org.hamcrest.Matchers.instanceOf;
37import static org.hamcrest.Matchers.is;
Ray Milkey33d90232014-11-04 10:49:00 -080038import static org.hamcrest.Matchers.notNullValue;
39import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
40import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import static org.onosproject.net.PortNumber.portNumber;
Ray Milkey33d90232014-11-04 10:49:00 -080042
43/**
44 * Unit tests for the Criteria class and its subclasses.
45 */
46public class CriteriaTest {
47
48 final PortNumber port1 = portNumber(1);
49 final PortNumber port2 = portNumber(2);
50
51 Criterion matchInPort1 = Criteria.matchInPort(port1);
52 Criterion sameAsMatchInPort1 = Criteria.matchInPort(port1);
53 Criterion matchInPort2 = Criteria.matchInPort(port2);
54
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080055 Criterion matchInPhyPort1 = Criteria.matchInPhyPort(port1);
56 Criterion sameAsMatchInPhyPort1 = Criteria.matchInPhyPort(port1);
57 Criterion matchInPhyPort2 = Criteria.matchInPhyPort(port2);
58
59 long metadata1 = 1;
60 long metadata2 = 2;
61 Criterion matchMetadata1 = Criteria.matchMetadata(metadata1);
62 Criterion sameAsMatchMetadata1 = Criteria.matchMetadata(metadata1);
63 Criterion matchMetadata2 = Criteria.matchMetadata(metadata2);
64
Ray Milkey33d90232014-11-04 10:49:00 -080065 private static final String MAC1 = "00:00:00:00:00:01";
66 private static final String MAC2 = "00:00:00:00:00:02";
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080067 private MacAddress mac1 = MacAddress.valueOf(MAC1);
68 private MacAddress mac2 = MacAddress.valueOf(MAC2);
Ray Milkey33d90232014-11-04 10:49:00 -080069 Criterion matchEth1 = Criteria.matchEthSrc(mac1);
70 Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1);
71 Criterion matchEth2 = Criteria.matchEthDst(mac2);
72
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080073 int ethType1 = 1;
74 int ethType2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -080075 Criterion matchEthType1 = Criteria.matchEthType(ethType1);
76 Criterion sameAsMatchEthType1 = Criteria.matchEthType(ethType1);
77 Criterion matchEthType2 = Criteria.matchEthType(ethType2);
78
79 short vlan1 = 1;
80 short vlan2 = 2;
81 VlanId vlanId1 = VlanId.vlanId(vlan1);
82 VlanId vlanId2 = VlanId.vlanId(vlan2);
83 Criterion matchVlanId1 = Criteria.matchVlanId(vlanId1);
84 Criterion sameAsMatchVlanId1 = Criteria.matchVlanId(vlanId1);
85 Criterion matchVlanId2 = Criteria.matchVlanId(vlanId2);
86
87 byte vlanPcp1 = 1;
88 byte vlanPcp2 = 2;
89 Criterion matchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
90 Criterion sameAsMatchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
91 Criterion matchVlanPcp2 = Criteria.matchVlanPcp(vlanPcp2);
92
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080093 byte ipDscp1 = 1;
94 byte ipDscp2 = 2;
95 Criterion matchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
96 Criterion sameAsMatchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
97 Criterion matchIpDscp2 = Criteria.matchIPDscp(ipDscp2);
98
99 byte ipEcn1 = 1;
100 byte ipEcn2 = 2;
101 Criterion matchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
102 Criterion sameAsMatchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
103 Criterion matchIpEcn2 = Criteria.matchIPEcn(ipEcn2);
104
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800105 short protocol1 = 1;
106 short protocol2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -0800107 Criterion matchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
108 Criterion sameAsMatchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
109 Criterion matchIpProtocol2 = Criteria.matchIPProtocol(protocol2);
110
111 private static final String IP1 = "1.2.3.4/24";
112 private static final String IP2 = "5.6.7.8/24";
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800113 private static final String IPV61 = "fe80::1/64";
114 private static final String IPV62 = "fc80::2/64";
Ray Milkey33d90232014-11-04 10:49:00 -0800115 private IpPrefix ip1 = IpPrefix.valueOf(IP1);
116 private IpPrefix ip2 = IpPrefix.valueOf(IP2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800117 private IpPrefix ipv61 = IpPrefix.valueOf(IPV61);
118 private IpPrefix ipv62 = IpPrefix.valueOf(IPV62);
Ray Milkey33d90232014-11-04 10:49:00 -0800119 Criterion matchIp1 = Criteria.matchIPSrc(ip1);
120 Criterion sameAsMatchIp1 = Criteria.matchIPSrc(ip1);
121 Criterion matchIp2 = Criteria.matchIPSrc(ip2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800122 Criterion matchIpv61 = Criteria.matchIPSrc(ipv61);
123 Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
124 Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
Ray Milkey33d90232014-11-04 10:49:00 -0800125
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700126 private TpPort tpPort1 = TpPort.tpPort(1);
127 private TpPort tpPort2 = TpPort.tpPort(2);
128 Criterion matchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
129 Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
130 Criterion matchTcpPort2 = Criteria.matchTcpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800131
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700132 Criterion matchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
133 Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
134 Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800135
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700136 Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
137 Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
138 Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800139
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800140 short icmpType1 = 1;
141 short icmpType2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800142 Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1);
143 Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1);
144 Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2);
145
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800146 short icmpCode1 = 1;
147 short icmpCode2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800148 Criterion matchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
149 Criterion sameAsMatchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
150 Criterion matchIcmpCode2 = Criteria.matchIcmpCode(icmpCode2);
151
152 int flowLabel1 = 1;
153 int flowLabel2 = 2;
154 Criterion matchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
155 Criterion sameAsMatchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
156 Criterion matchFlowLabel2 = Criteria.matchIPv6FlowLabel(flowLabel2);
157
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800158 short icmpv6Type1 = 1;
159 short icmpv6Type2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800160 Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
161 Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
162 Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2);
163
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800164 short icmpv6Code1 = 1;
165 short icmpv6Code2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800166 Criterion matchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
167 Criterion sameAsMatchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
168 Criterion matchIcmpv6Code2 = Criteria.matchIcmpv6Code(icmpv6Code2);
169
170 private static final String IPV6_ADDR1 = "fe80::1";
171 private static final String IPV6_ADDR2 = "fe80::2";
172 private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
173 private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
174 Criterion matchIpv6TargetAddr1 =
175 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
176 Criterion sameAsMatchIpv6TargetAddr1 =
177 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
178 Criterion matchIpv6TargetAddr2 =
179 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
180
181 private static final String LL_MAC1 = "00:00:00:00:00:01";
182 private static final String LL_MAC2 = "00:00:00:00:00:02";
183 private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
184 private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
185 Criterion matchSrcLlAddr1 =
186 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
187 Criterion sameAsMatchSrcLlAddr1 =
188 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
189 Criterion matchSrcLlAddr2 =
190 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
191 Criterion matchTargetLlAddr1 =
192 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
193 Criterion sameAsMatchTargetLlAddr1 =
194 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
195 Criterion matchTargetLlAddr2 =
196 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
197
Michele Santuari4b6019e2014-12-19 11:31:45 +0100198 MplsLabel mpls1 = MplsLabel.mplsLabel(1);
199 MplsLabel mpls2 = MplsLabel.mplsLabel(2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800200 Criterion matchMpls1 = Criteria.matchMplsLabel(mpls1);
201 Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1);
202 Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2);
203
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700204 long tunnelId1 = 1;
205 long tunnelId2 = 2;
206 Criterion matchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
207 Criterion sameAsMatchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
208 Criterion matchTunnelId2 = Criteria.matchTunnelId(tunnelId2);
209
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800210 int ipv6ExthdrFlags1 =
211 Criterion.IPv6ExthdrFlags.NONEXT.getValue() |
212 Criterion.IPv6ExthdrFlags.ESP.getValue() |
213 Criterion.IPv6ExthdrFlags.AUTH.getValue() |
214 Criterion.IPv6ExthdrFlags.DEST.getValue() |
215 Criterion.IPv6ExthdrFlags.FRAG.getValue() |
216 Criterion.IPv6ExthdrFlags.ROUTER.getValue() |
217 Criterion.IPv6ExthdrFlags.HOP.getValue() |
218 Criterion.IPv6ExthdrFlags.UNREP.getValue();
219 int ipv6ExthdrFlags2 = ipv6ExthdrFlags1 |
220 Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
221 Criterion matchIpv6ExthdrFlags1 =
222 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
223 Criterion sameAsMatchIpv6ExthdrFlags1 =
224 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
225 Criterion matchIpv6ExthdrFlags2 =
226 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
227
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700228 Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
229 Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -0700230 Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID);
231
Sho SHIMIZUefc2e282015-05-04 15:26:23 -0700232 Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
233 Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
234 Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2));
235
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -0700236 Criterion matchOchSignal1 =
237 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
238 Criterion sameAsMatchOchSignal1 =
239 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
240 Criterion matchOchSignal2 =
241 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
242
Ray Milkey33d90232014-11-04 10:49:00 -0800243 /**
244 * Checks that a Criterion object has the proper type, and then converts
245 * it to the proper type.
246 *
247 * @param criterion Criterion object to convert
248 * @param type Enumerated type value for the Criterion class
249 * @param clazz Desired Criterion class
250 * @param <T> The type the caller wants returned
251 * @return converted object
252 */
253 @SuppressWarnings("unchecked")
254 private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) {
255 assertThat(criterion, is(notNullValue()));
256 assertThat(criterion.type(), is(equalTo(type)));
Ray Milkey78081052014-11-05 10:38:12 -0800257 assertThat(criterion, instanceOf(clazz));
Ray Milkey33d90232014-11-04 10:49:00 -0800258 return (T) criterion;
259 }
260
261 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800262 * Check that the Criteria class is a valid utility class.
263 */
264 @Test
265 public void testCriteriaUtility() {
266 assertThatClassIsUtility(Criteria.class);
267 }
268
269 /**
270 * Check that the Criteria implementations are immutable.
271 */
272 @Test
273 public void testCriteriaImmutability() {
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700274 assertThatClassIsImmutable(PortCriterion.class);
275 assertThatClassIsImmutable(MetadataCriterion.class);
276 assertThatClassIsImmutable(EthCriterion.class);
277 assertThatClassIsImmutable(EthTypeCriterion.class);
278 assertThatClassIsImmutable(VlanIdCriterion.class);
279 assertThatClassIsImmutable(VlanPcpCriterion.class);
280 assertThatClassIsImmutable(IPDscpCriterion.class);
281 assertThatClassIsImmutable(IPEcnCriterion.class);
282 assertThatClassIsImmutable(IPProtocolCriterion.class);
283 assertThatClassIsImmutable(IPCriterion.class);
284 assertThatClassIsImmutable(TcpPortCriterion.class);
285 assertThatClassIsImmutable(UdpPortCriterion.class);
286 assertThatClassIsImmutable(SctpPortCriterion.class);
287 assertThatClassIsImmutable(IcmpTypeCriterion.class);
288 assertThatClassIsImmutable(IcmpCodeCriterion.class);
289 assertThatClassIsImmutable(IPv6FlowLabelCriterion.class);
290 assertThatClassIsImmutable(Icmpv6TypeCriterion.class);
291 assertThatClassIsImmutable(Icmpv6CodeCriterion.class);
292 assertThatClassIsImmutable(IPv6NDTargetAddressCriterion.class);
293 assertThatClassIsImmutable(IPv6NDLinkLayerAddressCriterion.class);
294 assertThatClassIsImmutable(MplsCriterion.class);
295 assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class);
296 assertThatClassIsImmutable(LambdaCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800297 }
298
299 // PortCriterion class
300
301 /**
302 * Test the matchInPort method.
303 */
304 @Test
305 public void testMatchInPortMethod() {
306 PortNumber p1 = portNumber(1);
307 Criterion matchInPort = Criteria.matchInPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700308 PortCriterion portCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800309 checkAndConvert(matchInPort,
310 Criterion.Type.IN_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700311 PortCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800312 assertThat(portCriterion.port(), is(equalTo(p1)));
313 }
314
315 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800316 * Test the matchInPhyPort method.
317 */
318 @Test
319 public void testMatchInPhyPortMethod() {
320 PortNumber p1 = portNumber(1);
321 Criterion matchInPhyPort = Criteria.matchInPhyPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700322 PortCriterion portCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800323 checkAndConvert(matchInPhyPort,
324 Criterion.Type.IN_PHY_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700325 PortCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800326 assertThat(portCriterion.port(), is(equalTo(p1)));
327 }
328
329 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800330 * Test the equals() method of the PortCriterion class.
331 */
332 @Test
333 public void testPortCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800334 new EqualsTester()
335 .addEqualityGroup(matchInPort1, sameAsMatchInPort1)
336 .addEqualityGroup(matchInPort2)
337 .testEquals();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800338
339 new EqualsTester()
340 .addEqualityGroup(matchInPhyPort1, sameAsMatchInPhyPort1)
341 .addEqualityGroup(matchInPhyPort2)
342 .testEquals();
343 }
344
345 // MetadataCriterion class
346
347 /**
348 * Test the matchMetadata method.
349 */
350 @Test
351 public void testMatchMetadataMethod() {
352 Long metadata = 12L;
353 Criterion matchMetadata = Criteria.matchMetadata(metadata);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700354 MetadataCriterion metadataCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800355 checkAndConvert(matchMetadata,
356 Criterion.Type.METADATA,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700357 MetadataCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800358 assertThat(metadataCriterion.metadata(), is(equalTo(metadata)));
359 }
360
361 /**
362 * Test the equals() method of the MetadataCriterion class.
363 */
364 @Test
365 public void testMetadataCriterionEquals() {
366 new EqualsTester()
367 .addEqualityGroup(matchMetadata1, sameAsMatchMetadata1)
368 .addEqualityGroup(matchMetadata2)
369 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800370 }
371
372 // EthCriterion class
373
374 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800375 * Test the matchEthDst method.
376 */
377 @Test
378 public void testMatchEthDstMethod() {
379 Criterion matchEthDst = Criteria.matchEthDst(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700380 EthCriterion ethCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800381 checkAndConvert(matchEthDst,
382 Criterion.Type.ETH_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700383 EthCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800384 assertThat(ethCriterion.mac(), is(equalTo(mac1)));
385 }
386
387 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800388 * Test the matchEthSrc method.
389 */
390 @Test
391 public void testMatchEthSrcMethod() {
392 Criterion matchEthSrc = Criteria.matchEthSrc(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700393 EthCriterion ethCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800394 checkAndConvert(matchEthSrc,
395 Criterion.Type.ETH_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700396 EthCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800397 assertThat(ethCriterion.mac(), is(mac1));
398 }
399
400 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800401 * Test the equals() method of the EthCriterion class.
402 */
403 @Test
404 public void testEthCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800405 new EqualsTester()
406 .addEqualityGroup(matchEth1, sameAsMatchEth1)
407 .addEqualityGroup(matchEth2)
408 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800409 }
410
Ray Milkey33d90232014-11-04 10:49:00 -0800411 // EthTypeCriterion class
412
413 /**
414 * Test the matchEthType method.
415 */
416 @Test
417 public void testMatchEthTypeMethod() {
alshabibcaf1ca22015-06-25 15:18:16 -0700418 EthType ethType = new EthType(12);
419 Criterion matchEthType = Criteria.matchEthType(new EthType(12));
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700420 EthTypeCriterion ethTypeCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800421 checkAndConvert(matchEthType,
422 Criterion.Type.ETH_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700423 EthTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800424 assertThat(ethTypeCriterion.ethType(), is(equalTo(ethType)));
425 }
426
427 /**
428 * Test the equals() method of the EthTypeCriterion class.
429 */
430 @Test
431 public void testEthTypeCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800432 new EqualsTester()
433 .addEqualityGroup(matchEthType1, sameAsMatchEthType1)
434 .addEqualityGroup(matchEthType2)
435 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800436 }
437
Ray Milkey33d90232014-11-04 10:49:00 -0800438 // VlanIdCriterion class
439
440 /**
441 * Test the matchVlanId method.
442 */
443 @Test
444 public void testMatchVlanIdMethod() {
445 Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700446 VlanIdCriterion vlanIdCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800447 checkAndConvert(matchVlanId,
448 Criterion.Type.VLAN_VID,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700449 VlanIdCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800450 assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
451 }
452
453 /**
454 * Test the equals() method of the VlanIdCriterion class.
455 */
456 @Test
457 public void testVlanIdCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800458 new EqualsTester()
459 .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1)
460 .addEqualityGroup(matchVlanId2)
461 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800462 }
463
464 // VlanPcpCriterion class
465
466 /**
467 * Test the matchVlanPcp method.
468 */
469 @Test
470 public void testMatchVlanPcpMethod() {
471 Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700472 VlanPcpCriterion vlanPcpCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800473 checkAndConvert(matchVlanPcp,
474 Criterion.Type.VLAN_PCP,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700475 VlanPcpCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800476 assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
477 }
478
479 /**
480 * Test the equals() method of the VlanPcpCriterion class.
481 */
482 @Test
483 public void testVlanPcpCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800484 new EqualsTester()
485 .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1)
486 .addEqualityGroup(matchVlanPcp2)
487 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800488 }
489
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800490 // IPDscpCriterion class
491
492 /**
493 * Test the matchIPDscp method.
494 */
495 @Test
496 public void testMatchIPDscpMethod() {
497 Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700498 IPDscpCriterion ipDscpCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800499 checkAndConvert(matchIPDscp,
500 Criterion.Type.IP_DSCP,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700501 IPDscpCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800502 assertThat(ipDscpCriterion.ipDscp(), is(equalTo(ipDscp1)));
503 }
504
505 /**
506 * Test the equals() method of the IPDscpCriterion class.
507 */
508 @Test
509 public void testIPDscpCriterionEquals() {
510 new EqualsTester()
511 .addEqualityGroup(matchIpDscp1, sameAsMatchIpDscp1)
512 .addEqualityGroup(matchIpDscp2)
513 .testEquals();
514 }
515
516 // IPEcnCriterion class
517
518 /**
519 * Test the matchIPEcn method.
520 */
521 @Test
522 public void testMatchIPEcnMethod() {
523 Criterion matchIPEcn = Criteria.matchIPEcn(ipEcn1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700524 IPEcnCriterion ipEcnCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800525 checkAndConvert(matchIPEcn,
526 Criterion.Type.IP_ECN,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700527 IPEcnCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800528 assertThat(ipEcnCriterion.ipEcn(), is(equalTo(ipEcn1)));
529 }
530
531 /**
532 * Test the equals() method of the IPEcnCriterion class.
533 */
534 @Test
535 public void testIPEcnCriterionEquals() {
536 new EqualsTester()
537 .addEqualityGroup(matchIpEcn1, sameAsMatchIpEcn1)
538 .addEqualityGroup(matchIpEcn2)
539 .testEquals();
540 }
541
Ray Milkey33d90232014-11-04 10:49:00 -0800542 // IpProtocolCriterion class
543
544 /**
545 * Test the matchIpProtocol method.
546 */
547 @Test
548 public void testMatchIpProtocolMethod() {
549 Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700550 IPProtocolCriterion ipProtocolCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800551 checkAndConvert(matchIPProtocol,
552 Criterion.Type.IP_PROTO,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700553 IPProtocolCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800554 assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
555 }
556
557 /**
558 * Test the equals() method of the IpProtocolCriterion class.
559 */
560 @Test
561 public void testIpProtocolCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800562 new EqualsTester()
563 .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1)
564 .addEqualityGroup(matchIpProtocol2)
565 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800566 }
567
568 // IPCriterion class
569
570 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800571 * Test the matchIPSrc method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800572 */
573 @Test
574 public void testMatchIPSrcMethod() {
575 Criterion matchIpSrc = Criteria.matchIPSrc(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700576 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800577 checkAndConvert(matchIpSrc,
578 Criterion.Type.IPV4_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700579 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800580 assertThat(ipCriterion.ip(), is(ip1));
581 }
582
583 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800584 * Test the matchIPDst method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800585 */
586 @Test
587 public void testMatchIPDstMethod() {
588 Criterion matchIPDst = Criteria.matchIPDst(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700589 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800590 checkAndConvert(matchIPDst,
591 Criterion.Type.IPV4_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700592 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800593 assertThat(ipCriterion.ip(), is(equalTo(ip1)));
594 }
595
596 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800597 * Test the matchIPSrc method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800598 */
599 @Test
600 public void testMatchIPv6SrcMethod() {
601 Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700602 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800603 checkAndConvert(matchIpv6Src,
604 Criterion.Type.IPV6_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700605 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800606 assertThat(ipCriterion.ip(), is(ipv61));
607 }
608
609 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800610 * Test the matchIPDst method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800611 */
612 @Test
613 public void testMatchIPv6DstMethod() {
614 Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700615 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800616 checkAndConvert(matchIPv6Dst,
617 Criterion.Type.IPV6_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700618 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800619 assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
620 }
621
622 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800623 * Test the equals() method of the IpCriterion class.
624 */
625 @Test
626 public void testIPCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800627 new EqualsTester()
628 .addEqualityGroup(matchIp1, sameAsMatchIp1)
629 .addEqualityGroup(matchIp2)
630 .testEquals();
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800631
632 new EqualsTester()
633 .addEqualityGroup(matchIpv61, sameAsMatchIpv61)
634 .addEqualityGroup(matchIpv62)
635 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800636 }
637
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800638 // TcpPortCriterion class
639
640 /**
641 * Test the matchTcpSrc method.
642 */
643 @Test
644 public void testMatchTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700645 Criterion matchTcpSrc = Criteria.matchTcpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700646 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800647 checkAndConvert(matchTcpSrc,
648 Criterion.Type.TCP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700649 TcpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700650 assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800651 }
652
653 /**
654 * Test the matchTcpDst method.
655 */
656 @Test
657 public void testMatchTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700658 Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700659 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800660 checkAndConvert(matchTcpDst,
661 Criterion.Type.TCP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700662 TcpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700663 assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800664 }
665
666 /**
667 * Test the equals() method of the TcpPortCriterion class.
668 */
669 @Test
670 public void testTcpPortCriterionEquals() {
671 new EqualsTester()
672 .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
673 .addEqualityGroup(matchTcpPort2)
674 .testEquals();
675 }
676
677 // UdpPortCriterion class
678
679 /**
680 * Test the matchUdpSrc method.
681 */
682 @Test
683 public void testMatchUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700684 Criterion matchUdpSrc = Criteria.matchUdpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700685 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800686 checkAndConvert(matchUdpSrc,
687 Criterion.Type.UDP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700688 UdpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700689 assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800690 }
691
692 /**
693 * Test the matchUdpDst method.
694 */
695 @Test
696 public void testMatchUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700697 Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700698 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800699 checkAndConvert(matchUdpDst,
700 Criterion.Type.UDP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700701 UdpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700702 assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800703 }
704
705 /**
706 * Test the equals() method of the UdpPortCriterion class.
707 */
708 @Test
709 public void testUdpPortCriterionEquals() {
710 new EqualsTester()
711 .addEqualityGroup(matchUdpPort1, sameAsMatchUdpPort1)
712 .addEqualityGroup(matchUdpPort2)
713 .testEquals();
714 }
715
716 // SctpPortCriterion class
717
718 /**
719 * Test the matchSctpSrc method.
720 */
721 @Test
722 public void testMatchSctpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700723 Criterion matchSctpSrc = Criteria.matchSctpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700724 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800725 checkAndConvert(matchSctpSrc,
726 Criterion.Type.SCTP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700727 SctpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700728 assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800729 }
730
731 /**
732 * Test the matchSctpDst method.
733 */
734 @Test
735 public void testMatchSctpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700736 Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700737 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800738 checkAndConvert(matchSctpDst,
739 Criterion.Type.SCTP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700740 SctpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700741 assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800742 }
743
744 /**
745 * Test the equals() method of the SctpPortCriterion class.
746 */
747 @Test
748 public void testSctpPortCriterionEquals() {
749 new EqualsTester()
750 .addEqualityGroup(matchSctpPort1, sameAsMatchSctpPort1)
751 .addEqualityGroup(matchSctpPort2)
752 .testEquals();
753 }
754
755 // IcmpTypeCriterion class
756
757 /**
758 * Test the matchIcmpType method.
759 */
760 @Test
761 public void testMatchIcmpTypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800762 short icmpType = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800763 Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700764 IcmpTypeCriterion icmpTypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800765 checkAndConvert(matchIcmpType,
766 Criterion.Type.ICMPV4_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700767 IcmpTypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800768 assertThat(icmpTypeCriterion.icmpType(), is(equalTo(icmpType)));
769 }
770
771 /**
772 * Test the equals() method of the IcmpTypeCriterion class.
773 */
774 @Test
775 public void testIcmpTypeCriterionEquals() {
776 new EqualsTester()
777 .addEqualityGroup(matchIcmpType1, sameAsMatchIcmpType1)
778 .addEqualityGroup(matchIcmpType2)
779 .testEquals();
780 }
781
782 // IcmpCodeCriterion class
783
784 /**
785 * Test the matchIcmpCode method.
786 */
787 @Test
788 public void testMatchIcmpCodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800789 short icmpCode = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800790 Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700791 IcmpCodeCriterion icmpCodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800792 checkAndConvert(matchIcmpCode,
793 Criterion.Type.ICMPV4_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700794 IcmpCodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800795 assertThat(icmpCodeCriterion.icmpCode(), is(equalTo(icmpCode)));
796 }
797
798 /**
799 * Test the equals() method of the IcmpCodeCriterion class.
800 */
801 @Test
802 public void testIcmpCodeCriterionEquals() {
803 new EqualsTester()
804 .addEqualityGroup(matchIcmpCode1, sameAsMatchIcmpCode1)
805 .addEqualityGroup(matchIcmpCode2)
806 .testEquals();
807 }
808
809 // IPv6FlowLabelCriterion class
810
811 /**
812 * Test the matchIPv6FlowLabel method.
813 */
814 @Test
815 public void testMatchIPv6FlowLabelMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800816 int flowLabel = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800817 Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700818 IPv6FlowLabelCriterion flowLabelCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800819 checkAndConvert(matchFlowLabel,
820 Criterion.Type.IPV6_FLABEL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700821 IPv6FlowLabelCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800822 assertThat(flowLabelCriterion.flowLabel(), is(equalTo(flowLabel)));
823 }
824
825 /**
826 * Test the equals() method of the IPv6FlowLabelCriterion class.
827 */
828 @Test
829 public void testIPv6FlowLabelCriterionEquals() {
830 new EqualsTester()
831 .addEqualityGroup(matchFlowLabel1, sameAsMatchFlowLabel1)
832 .addEqualityGroup(matchFlowLabel2)
833 .testEquals();
834 }
835
836 // Icmpv6TypeCriterion class
837
838 /**
839 * Test the matchIcmpv6Type method.
840 */
841 @Test
842 public void testMatchIcmpv6TypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800843 short icmpv6Type = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800844 Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700845 Icmpv6TypeCriterion icmpv6TypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800846 checkAndConvert(matchIcmpv6Type,
847 Criterion.Type.ICMPV6_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700848 Icmpv6TypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800849 assertThat(icmpv6TypeCriterion.icmpv6Type(), is(equalTo(icmpv6Type)));
850 }
851
852 /**
853 * Test the equals() method of the Icmpv6TypeCriterion class.
854 */
855 @Test
856 public void testIcmpv6TypeCriterionEquals() {
857 new EqualsTester()
858 .addEqualityGroup(matchIcmpv6Type1, sameAsMatchIcmpv6Type1)
859 .addEqualityGroup(matchIcmpv6Type2)
860 .testEquals();
861 }
862
863 // Icmpv6CodeCriterion class
864
865 /**
866 * Test the matchIcmpv6Code method.
867 */
868 @Test
869 public void testMatchIcmpv6CodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800870 short icmpv6Code = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800871 Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700872 Icmpv6CodeCriterion icmpv6CodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800873 checkAndConvert(matchIcmpv6Code,
874 Criterion.Type.ICMPV6_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700875 Icmpv6CodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800876 assertThat(icmpv6CodeCriterion.icmpv6Code(), is(equalTo(icmpv6Code)));
877 }
878
879 /**
880 * Test the equals() method of the Icmpv6CodeCriterion class.
881 */
882 @Test
883 public void testIcmpv6CodeCriterionEquals() {
884 new EqualsTester()
885 .addEqualityGroup(matchIcmpv6Code1, sameAsMatchIcmpv6Code1)
886 .addEqualityGroup(matchIcmpv6Code2)
887 .testEquals();
888 }
889
890 // IPv6NDTargetAddressCriterion class
891
892 /**
893 * Test the matchIPv6NDTargetAddress method.
894 */
895 @Test
896 public void testMatchIPv6NDTargetAddressMethod() {
897 Criterion matchTargetAddress =
898 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700899 IPv6NDTargetAddressCriterion targetAddressCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800900 checkAndConvert(matchTargetAddress,
901 Criterion.Type.IPV6_ND_TARGET,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700902 IPv6NDTargetAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800903 assertThat(targetAddressCriterion.targetAddress(),
904 is(ip6TargetAddress1));
905 }
906
907 /**
908 * Test the equals() method of the IPv6NDTargetAddressCriterion class.
909 */
910 @Test
911 public void testIPv6NDTargetAddressCriterionEquals() {
912 new EqualsTester()
913 .addEqualityGroup(matchIpv6TargetAddr1,
914 sameAsMatchIpv6TargetAddr1)
915 .addEqualityGroup(matchIpv6TargetAddr2)
916 .testEquals();
917 }
918
919 // IPv6NDLinkLayerAddressCriterion class
920
921 /**
922 * Test the matchIPv6NDSourceLinkLayerAddress method.
923 */
924 @Test
925 public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
926 Criterion matchSrcLlAddr =
927 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700928 IPv6NDLinkLayerAddressCriterion srcLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800929 checkAndConvert(matchSrcLlAddr,
930 Criterion.Type.IPV6_ND_SLL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700931 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800932 assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
933 }
934
935 /**
936 * Test the matchIPv6NDTargetLinkLayerAddress method.
937 */
938 @Test
939 public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
940 Criterion matchTargetLlAddr =
941 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700942 IPv6NDLinkLayerAddressCriterion targetLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800943 checkAndConvert(matchTargetLlAddr,
944 Criterion.Type.IPV6_ND_TLL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700945 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800946 assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
947 }
948
949 /**
950 * Test the equals() method of the IPv6NDLinkLayerAddressCriterion class.
951 */
952 @Test
953 public void testIPv6NDLinkLayerAddressCriterionEquals() {
954 new EqualsTester()
955 .addEqualityGroup(matchSrcLlAddr1, sameAsMatchSrcLlAddr1)
956 .addEqualityGroup(matchSrcLlAddr2)
957 .testEquals();
958
959 new EqualsTester()
960 .addEqualityGroup(matchTargetLlAddr1, sameAsMatchTargetLlAddr1)
961 .addEqualityGroup(matchTargetLlAddr2)
962 .testEquals();
963 }
964
965 // MplsCriterion class
966
967 /**
968 * Test the matchMplsLabel method.
969 */
970 @Test
971 public void testMatchMplsLabelMethod() {
972 Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700973 MplsCriterion mplsCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800974 checkAndConvert(matchMplsLabel,
975 Criterion.Type.MPLS_LABEL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700976 MplsCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800977 assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
978 }
979
980 /**
981 * Test the equals() method of the MplsCriterion class.
982 */
983 @Test
984 public void testMplsCriterionEquals() {
985 new EqualsTester()
986 .addEqualityGroup(matchMpls1, sameAsMatchMpls1)
987 .addEqualityGroup(matchMpls2)
988 .testEquals();
989 }
990
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700991 // TunnelIdCriterion class
992
993 /**
994 * Test the matchTunnelId method.
995 */
996 @Test
997 public void testMatchTunnelIdMethod() {
998 Criterion matchTunnelId = Criteria.matchTunnelId(tunnelId1);
999 TunnelIdCriterion tunnelIdCriterion =
1000 checkAndConvert(matchTunnelId,
1001 Criterion.Type.TUNNEL_ID,
1002 TunnelIdCriterion.class);
1003 assertThat(tunnelIdCriterion.tunnelId(), is(equalTo(tunnelId1)));
1004
1005 }
1006
1007 /**
1008 * Test the equals() method of the TunnelIdCriterion class.
1009 */
1010 @Test
1011 public void testTunnelIdCriterionEquals() {
1012 new EqualsTester()
1013 .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
1014 .addEqualityGroup(matchTunnelId2)
1015 .testEquals();
1016 }
1017
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001018 // IPv6ExthdrFlagsCriterion class
1019
1020 /**
1021 * Test the matchIPv6ExthdrFlags method.
1022 */
1023 @Test
1024 public void testMatchIPv6ExthdrFlagsMethod() {
1025 Criterion matchExthdrFlags =
1026 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001027 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001028 checkAndConvert(matchExthdrFlags,
1029 Criterion.Type.IPV6_EXTHDR,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001030 IPv6ExthdrFlagsCriterion.class);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001031 assertThat(exthdrFlagsCriterion.exthdrFlags(),
1032 is(equalTo(ipv6ExthdrFlags1)));
1033 }
1034
1035 /**
1036 * Test the equals() method of the IPv6ExthdrFlagsCriterion class.
1037 */
1038 @Test
1039 public void testIPv6ExthdrFlagsCriterionEquals() {
1040 new EqualsTester()
1041 .addEqualityGroup(matchIpv6ExthdrFlags1,
1042 sameAsMatchIpv6ExthdrFlags1)
1043 .addEqualityGroup(matchIpv6ExthdrFlags2)
1044 .testEquals();
1045 }
1046
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001047 @Test
Sho SHIMIZUefc2e282015-05-04 15:26:23 -07001048 public void testIndexedLambdaCriterionEquals() {
1049 new EqualsTester()
1050 .addEqualityGroup(matchIndexedLambda1, sameAsMatchIndexedLambda1)
1051 .addEqualityGroup(matchIndexedLambda2)
1052 .testEquals();
1053 }
1054
1055 @Test
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001056 public void testOchSignalCriterionEquals() {
1057 new EqualsTester()
1058 .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1)
1059 .addEqualityGroup(matchOchSignal2)
1060 .testEquals();
1061 }
1062
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -07001063 /**
1064 * Test the equals() method of the OchSignalTypeCriterion class.
1065 */
1066 @Test
1067 public void testOchSignalTypeCriterionEquals() {
1068 new EqualsTester()
1069 .addEqualityGroup(matchOchSignalType1, sameAsMatchOchSignalType1)
1070 .addEqualityGroup(matchOchSignalType2)
1071 .testEquals();
1072 }
Ray Milkey33d90232014-11-04 10:49:00 -08001073}