blob: ee294f6f02a10e4f86a1482b6b4af13d33b422ea [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
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800228 int lambda1 = 1;
229 int lambda2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -0800230 Criterion matchLambda1 = Criteria.matchLambda(lambda1);
231 Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1);
232 Criterion matchLambda2 = Criteria.matchLambda(lambda2);
233
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700234 Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
235 Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -0700236 Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID);
237
Sho SHIMIZUefc2e282015-05-04 15:26:23 -0700238 Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
239 Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
240 Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2));
241
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800242 short signalLambda1 = 1;
243 short signalLambda2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -0800244 Criterion matchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
245 Criterion sameAsMatchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
246 Criterion matchSignalLambda2 = Criteria.matchOpticalSignalType(signalLambda2);
247
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -0700248 Criterion matchOchSignal1 =
249 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
250 Criterion sameAsMatchOchSignal1 =
251 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
252 Criterion matchOchSignal2 =
253 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
254
Ray Milkey33d90232014-11-04 10:49:00 -0800255 /**
256 * Checks that a Criterion object has the proper type, and then converts
257 * it to the proper type.
258 *
259 * @param criterion Criterion object to convert
260 * @param type Enumerated type value for the Criterion class
261 * @param clazz Desired Criterion class
262 * @param <T> The type the caller wants returned
263 * @return converted object
264 */
265 @SuppressWarnings("unchecked")
266 private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) {
267 assertThat(criterion, is(notNullValue()));
268 assertThat(criterion.type(), is(equalTo(type)));
Ray Milkey78081052014-11-05 10:38:12 -0800269 assertThat(criterion, instanceOf(clazz));
Ray Milkey33d90232014-11-04 10:49:00 -0800270 return (T) criterion;
271 }
272
273 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800274 * Check that the Criteria class is a valid utility class.
275 */
276 @Test
277 public void testCriteriaUtility() {
278 assertThatClassIsUtility(Criteria.class);
279 }
280
281 /**
282 * Check that the Criteria implementations are immutable.
283 */
284 @Test
285 public void testCriteriaImmutability() {
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700286 assertThatClassIsImmutable(PortCriterion.class);
287 assertThatClassIsImmutable(MetadataCriterion.class);
288 assertThatClassIsImmutable(EthCriterion.class);
289 assertThatClassIsImmutable(EthTypeCriterion.class);
290 assertThatClassIsImmutable(VlanIdCriterion.class);
291 assertThatClassIsImmutable(VlanPcpCriterion.class);
292 assertThatClassIsImmutable(IPDscpCriterion.class);
293 assertThatClassIsImmutable(IPEcnCriterion.class);
294 assertThatClassIsImmutable(IPProtocolCriterion.class);
295 assertThatClassIsImmutable(IPCriterion.class);
296 assertThatClassIsImmutable(TcpPortCriterion.class);
297 assertThatClassIsImmutable(UdpPortCriterion.class);
298 assertThatClassIsImmutable(SctpPortCriterion.class);
299 assertThatClassIsImmutable(IcmpTypeCriterion.class);
300 assertThatClassIsImmutable(IcmpCodeCriterion.class);
301 assertThatClassIsImmutable(IPv6FlowLabelCriterion.class);
302 assertThatClassIsImmutable(Icmpv6TypeCriterion.class);
303 assertThatClassIsImmutable(Icmpv6CodeCriterion.class);
304 assertThatClassIsImmutable(IPv6NDTargetAddressCriterion.class);
305 assertThatClassIsImmutable(IPv6NDLinkLayerAddressCriterion.class);
306 assertThatClassIsImmutable(MplsCriterion.class);
307 assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class);
308 assertThatClassIsImmutable(LambdaCriterion.class);
309 assertThatClassIsImmutable(OpticalSignalTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800310 }
311
312 // PortCriterion class
313
314 /**
315 * Test the matchInPort method.
316 */
317 @Test
318 public void testMatchInPortMethod() {
319 PortNumber p1 = portNumber(1);
320 Criterion matchInPort = Criteria.matchInPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700321 PortCriterion portCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800322 checkAndConvert(matchInPort,
323 Criterion.Type.IN_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700324 PortCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800325 assertThat(portCriterion.port(), is(equalTo(p1)));
326 }
327
328 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800329 * Test the matchInPhyPort method.
330 */
331 @Test
332 public void testMatchInPhyPortMethod() {
333 PortNumber p1 = portNumber(1);
334 Criterion matchInPhyPort = Criteria.matchInPhyPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700335 PortCriterion portCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800336 checkAndConvert(matchInPhyPort,
337 Criterion.Type.IN_PHY_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700338 PortCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800339 assertThat(portCriterion.port(), is(equalTo(p1)));
340 }
341
342 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800343 * Test the equals() method of the PortCriterion class.
344 */
345 @Test
346 public void testPortCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800347 new EqualsTester()
348 .addEqualityGroup(matchInPort1, sameAsMatchInPort1)
349 .addEqualityGroup(matchInPort2)
350 .testEquals();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800351
352 new EqualsTester()
353 .addEqualityGroup(matchInPhyPort1, sameAsMatchInPhyPort1)
354 .addEqualityGroup(matchInPhyPort2)
355 .testEquals();
356 }
357
358 // MetadataCriterion class
359
360 /**
361 * Test the matchMetadata method.
362 */
363 @Test
364 public void testMatchMetadataMethod() {
365 Long metadata = 12L;
366 Criterion matchMetadata = Criteria.matchMetadata(metadata);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700367 MetadataCriterion metadataCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800368 checkAndConvert(matchMetadata,
369 Criterion.Type.METADATA,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700370 MetadataCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800371 assertThat(metadataCriterion.metadata(), is(equalTo(metadata)));
372 }
373
374 /**
375 * Test the equals() method of the MetadataCriterion class.
376 */
377 @Test
378 public void testMetadataCriterionEquals() {
379 new EqualsTester()
380 .addEqualityGroup(matchMetadata1, sameAsMatchMetadata1)
381 .addEqualityGroup(matchMetadata2)
382 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800383 }
384
385 // EthCriterion class
386
387 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800388 * Test the matchEthDst method.
389 */
390 @Test
391 public void testMatchEthDstMethod() {
392 Criterion matchEthDst = Criteria.matchEthDst(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700393 EthCriterion ethCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800394 checkAndConvert(matchEthDst,
395 Criterion.Type.ETH_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700396 EthCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800397 assertThat(ethCriterion.mac(), is(equalTo(mac1)));
398 }
399
400 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800401 * Test the matchEthSrc method.
402 */
403 @Test
404 public void testMatchEthSrcMethod() {
405 Criterion matchEthSrc = Criteria.matchEthSrc(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700406 EthCriterion ethCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800407 checkAndConvert(matchEthSrc,
408 Criterion.Type.ETH_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700409 EthCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800410 assertThat(ethCriterion.mac(), is(mac1));
411 }
412
413 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800414 * Test the equals() method of the EthCriterion class.
415 */
416 @Test
417 public void testEthCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800418 new EqualsTester()
419 .addEqualityGroup(matchEth1, sameAsMatchEth1)
420 .addEqualityGroup(matchEth2)
421 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800422 }
423
Ray Milkey33d90232014-11-04 10:49:00 -0800424 // EthTypeCriterion class
425
426 /**
427 * Test the matchEthType method.
428 */
429 @Test
430 public void testMatchEthTypeMethod() {
alshabibcaf1ca22015-06-25 15:18:16 -0700431 EthType ethType = new EthType(12);
432 Criterion matchEthType = Criteria.matchEthType(new EthType(12));
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700433 EthTypeCriterion ethTypeCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800434 checkAndConvert(matchEthType,
435 Criterion.Type.ETH_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700436 EthTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800437 assertThat(ethTypeCriterion.ethType(), is(equalTo(ethType)));
438 }
439
440 /**
441 * Test the equals() method of the EthTypeCriterion class.
442 */
443 @Test
444 public void testEthTypeCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800445 new EqualsTester()
446 .addEqualityGroup(matchEthType1, sameAsMatchEthType1)
447 .addEqualityGroup(matchEthType2)
448 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800449 }
450
Ray Milkey33d90232014-11-04 10:49:00 -0800451 // VlanIdCriterion class
452
453 /**
454 * Test the matchVlanId method.
455 */
456 @Test
457 public void testMatchVlanIdMethod() {
458 Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700459 VlanIdCriterion vlanIdCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800460 checkAndConvert(matchVlanId,
461 Criterion.Type.VLAN_VID,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700462 VlanIdCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800463 assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
464 }
465
466 /**
467 * Test the equals() method of the VlanIdCriterion class.
468 */
469 @Test
470 public void testVlanIdCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800471 new EqualsTester()
472 .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1)
473 .addEqualityGroup(matchVlanId2)
474 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800475 }
476
477 // VlanPcpCriterion class
478
479 /**
480 * Test the matchVlanPcp method.
481 */
482 @Test
483 public void testMatchVlanPcpMethod() {
484 Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700485 VlanPcpCriterion vlanPcpCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800486 checkAndConvert(matchVlanPcp,
487 Criterion.Type.VLAN_PCP,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700488 VlanPcpCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800489 assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
490 }
491
492 /**
493 * Test the equals() method of the VlanPcpCriterion class.
494 */
495 @Test
496 public void testVlanPcpCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800497 new EqualsTester()
498 .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1)
499 .addEqualityGroup(matchVlanPcp2)
500 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800501 }
502
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800503 // IPDscpCriterion class
504
505 /**
506 * Test the matchIPDscp method.
507 */
508 @Test
509 public void testMatchIPDscpMethod() {
510 Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700511 IPDscpCriterion ipDscpCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800512 checkAndConvert(matchIPDscp,
513 Criterion.Type.IP_DSCP,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700514 IPDscpCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800515 assertThat(ipDscpCriterion.ipDscp(), is(equalTo(ipDscp1)));
516 }
517
518 /**
519 * Test the equals() method of the IPDscpCriterion class.
520 */
521 @Test
522 public void testIPDscpCriterionEquals() {
523 new EqualsTester()
524 .addEqualityGroup(matchIpDscp1, sameAsMatchIpDscp1)
525 .addEqualityGroup(matchIpDscp2)
526 .testEquals();
527 }
528
529 // IPEcnCriterion class
530
531 /**
532 * Test the matchIPEcn method.
533 */
534 @Test
535 public void testMatchIPEcnMethod() {
536 Criterion matchIPEcn = Criteria.matchIPEcn(ipEcn1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700537 IPEcnCriterion ipEcnCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800538 checkAndConvert(matchIPEcn,
539 Criterion.Type.IP_ECN,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700540 IPEcnCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800541 assertThat(ipEcnCriterion.ipEcn(), is(equalTo(ipEcn1)));
542 }
543
544 /**
545 * Test the equals() method of the IPEcnCriterion class.
546 */
547 @Test
548 public void testIPEcnCriterionEquals() {
549 new EqualsTester()
550 .addEqualityGroup(matchIpEcn1, sameAsMatchIpEcn1)
551 .addEqualityGroup(matchIpEcn2)
552 .testEquals();
553 }
554
Ray Milkey33d90232014-11-04 10:49:00 -0800555 // IpProtocolCriterion class
556
557 /**
558 * Test the matchIpProtocol method.
559 */
560 @Test
561 public void testMatchIpProtocolMethod() {
562 Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700563 IPProtocolCriterion ipProtocolCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800564 checkAndConvert(matchIPProtocol,
565 Criterion.Type.IP_PROTO,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700566 IPProtocolCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800567 assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
568 }
569
570 /**
571 * Test the equals() method of the IpProtocolCriterion class.
572 */
573 @Test
574 public void testIpProtocolCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800575 new EqualsTester()
576 .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1)
577 .addEqualityGroup(matchIpProtocol2)
578 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800579 }
580
581 // IPCriterion class
582
583 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800584 * Test the matchIPSrc method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800585 */
586 @Test
587 public void testMatchIPSrcMethod() {
588 Criterion matchIpSrc = Criteria.matchIPSrc(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700589 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800590 checkAndConvert(matchIpSrc,
591 Criterion.Type.IPV4_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700592 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800593 assertThat(ipCriterion.ip(), is(ip1));
594 }
595
596 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800597 * Test the matchIPDst method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800598 */
599 @Test
600 public void testMatchIPDstMethod() {
601 Criterion matchIPDst = Criteria.matchIPDst(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700602 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800603 checkAndConvert(matchIPDst,
604 Criterion.Type.IPV4_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700605 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800606 assertThat(ipCriterion.ip(), is(equalTo(ip1)));
607 }
608
609 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800610 * Test the matchIPSrc method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800611 */
612 @Test
613 public void testMatchIPv6SrcMethod() {
614 Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700615 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800616 checkAndConvert(matchIpv6Src,
617 Criterion.Type.IPV6_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700618 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800619 assertThat(ipCriterion.ip(), is(ipv61));
620 }
621
622 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800623 * Test the matchIPDst method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800624 */
625 @Test
626 public void testMatchIPv6DstMethod() {
627 Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700628 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800629 checkAndConvert(matchIPv6Dst,
630 Criterion.Type.IPV6_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700631 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800632 assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
633 }
634
635 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800636 * Test the equals() method of the IpCriterion class.
637 */
638 @Test
639 public void testIPCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800640 new EqualsTester()
641 .addEqualityGroup(matchIp1, sameAsMatchIp1)
642 .addEqualityGroup(matchIp2)
643 .testEquals();
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800644
645 new EqualsTester()
646 .addEqualityGroup(matchIpv61, sameAsMatchIpv61)
647 .addEqualityGroup(matchIpv62)
648 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800649 }
650
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800651 // TcpPortCriterion class
652
653 /**
654 * Test the matchTcpSrc method.
655 */
656 @Test
657 public void testMatchTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700658 Criterion matchTcpSrc = Criteria.matchTcpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700659 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800660 checkAndConvert(matchTcpSrc,
661 Criterion.Type.TCP_SRC,
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 matchTcpDst method.
668 */
669 @Test
670 public void testMatchTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700671 Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700672 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800673 checkAndConvert(matchTcpDst,
674 Criterion.Type.TCP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700675 TcpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700676 assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800677 }
678
679 /**
680 * Test the equals() method of the TcpPortCriterion class.
681 */
682 @Test
683 public void testTcpPortCriterionEquals() {
684 new EqualsTester()
685 .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
686 .addEqualityGroup(matchTcpPort2)
687 .testEquals();
688 }
689
690 // UdpPortCriterion class
691
692 /**
693 * Test the matchUdpSrc method.
694 */
695 @Test
696 public void testMatchUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700697 Criterion matchUdpSrc = Criteria.matchUdpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700698 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800699 checkAndConvert(matchUdpSrc,
700 Criterion.Type.UDP_SRC,
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 matchUdpDst method.
707 */
708 @Test
709 public void testMatchUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700710 Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700711 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800712 checkAndConvert(matchUdpDst,
713 Criterion.Type.UDP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700714 UdpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700715 assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800716 }
717
718 /**
719 * Test the equals() method of the UdpPortCriterion class.
720 */
721 @Test
722 public void testUdpPortCriterionEquals() {
723 new EqualsTester()
724 .addEqualityGroup(matchUdpPort1, sameAsMatchUdpPort1)
725 .addEqualityGroup(matchUdpPort2)
726 .testEquals();
727 }
728
729 // SctpPortCriterion class
730
731 /**
732 * Test the matchSctpSrc method.
733 */
734 @Test
735 public void testMatchSctpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700736 Criterion matchSctpSrc = Criteria.matchSctpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700737 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800738 checkAndConvert(matchSctpSrc,
739 Criterion.Type.SCTP_SRC,
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 matchSctpDst method.
746 */
747 @Test
748 public void testMatchSctpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700749 Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700750 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800751 checkAndConvert(matchSctpDst,
752 Criterion.Type.SCTP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700753 SctpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700754 assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800755 }
756
757 /**
758 * Test the equals() method of the SctpPortCriterion class.
759 */
760 @Test
761 public void testSctpPortCriterionEquals() {
762 new EqualsTester()
763 .addEqualityGroup(matchSctpPort1, sameAsMatchSctpPort1)
764 .addEqualityGroup(matchSctpPort2)
765 .testEquals();
766 }
767
768 // IcmpTypeCriterion class
769
770 /**
771 * Test the matchIcmpType method.
772 */
773 @Test
774 public void testMatchIcmpTypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800775 short icmpType = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800776 Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700777 IcmpTypeCriterion icmpTypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800778 checkAndConvert(matchIcmpType,
779 Criterion.Type.ICMPV4_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700780 IcmpTypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800781 assertThat(icmpTypeCriterion.icmpType(), is(equalTo(icmpType)));
782 }
783
784 /**
785 * Test the equals() method of the IcmpTypeCriterion class.
786 */
787 @Test
788 public void testIcmpTypeCriterionEquals() {
789 new EqualsTester()
790 .addEqualityGroup(matchIcmpType1, sameAsMatchIcmpType1)
791 .addEqualityGroup(matchIcmpType2)
792 .testEquals();
793 }
794
795 // IcmpCodeCriterion class
796
797 /**
798 * Test the matchIcmpCode method.
799 */
800 @Test
801 public void testMatchIcmpCodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800802 short icmpCode = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800803 Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700804 IcmpCodeCriterion icmpCodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800805 checkAndConvert(matchIcmpCode,
806 Criterion.Type.ICMPV4_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700807 IcmpCodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800808 assertThat(icmpCodeCriterion.icmpCode(), is(equalTo(icmpCode)));
809 }
810
811 /**
812 * Test the equals() method of the IcmpCodeCriterion class.
813 */
814 @Test
815 public void testIcmpCodeCriterionEquals() {
816 new EqualsTester()
817 .addEqualityGroup(matchIcmpCode1, sameAsMatchIcmpCode1)
818 .addEqualityGroup(matchIcmpCode2)
819 .testEquals();
820 }
821
822 // IPv6FlowLabelCriterion class
823
824 /**
825 * Test the matchIPv6FlowLabel method.
826 */
827 @Test
828 public void testMatchIPv6FlowLabelMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800829 int flowLabel = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800830 Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700831 IPv6FlowLabelCriterion flowLabelCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800832 checkAndConvert(matchFlowLabel,
833 Criterion.Type.IPV6_FLABEL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700834 IPv6FlowLabelCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800835 assertThat(flowLabelCriterion.flowLabel(), is(equalTo(flowLabel)));
836 }
837
838 /**
839 * Test the equals() method of the IPv6FlowLabelCriterion class.
840 */
841 @Test
842 public void testIPv6FlowLabelCriterionEquals() {
843 new EqualsTester()
844 .addEqualityGroup(matchFlowLabel1, sameAsMatchFlowLabel1)
845 .addEqualityGroup(matchFlowLabel2)
846 .testEquals();
847 }
848
849 // Icmpv6TypeCriterion class
850
851 /**
852 * Test the matchIcmpv6Type method.
853 */
854 @Test
855 public void testMatchIcmpv6TypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800856 short icmpv6Type = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800857 Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700858 Icmpv6TypeCriterion icmpv6TypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800859 checkAndConvert(matchIcmpv6Type,
860 Criterion.Type.ICMPV6_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700861 Icmpv6TypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800862 assertThat(icmpv6TypeCriterion.icmpv6Type(), is(equalTo(icmpv6Type)));
863 }
864
865 /**
866 * Test the equals() method of the Icmpv6TypeCriterion class.
867 */
868 @Test
869 public void testIcmpv6TypeCriterionEquals() {
870 new EqualsTester()
871 .addEqualityGroup(matchIcmpv6Type1, sameAsMatchIcmpv6Type1)
872 .addEqualityGroup(matchIcmpv6Type2)
873 .testEquals();
874 }
875
876 // Icmpv6CodeCriterion class
877
878 /**
879 * Test the matchIcmpv6Code method.
880 */
881 @Test
882 public void testMatchIcmpv6CodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800883 short icmpv6Code = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800884 Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700885 Icmpv6CodeCriterion icmpv6CodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800886 checkAndConvert(matchIcmpv6Code,
887 Criterion.Type.ICMPV6_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700888 Icmpv6CodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800889 assertThat(icmpv6CodeCriterion.icmpv6Code(), is(equalTo(icmpv6Code)));
890 }
891
892 /**
893 * Test the equals() method of the Icmpv6CodeCriterion class.
894 */
895 @Test
896 public void testIcmpv6CodeCriterionEquals() {
897 new EqualsTester()
898 .addEqualityGroup(matchIcmpv6Code1, sameAsMatchIcmpv6Code1)
899 .addEqualityGroup(matchIcmpv6Code2)
900 .testEquals();
901 }
902
903 // IPv6NDTargetAddressCriterion class
904
905 /**
906 * Test the matchIPv6NDTargetAddress method.
907 */
908 @Test
909 public void testMatchIPv6NDTargetAddressMethod() {
910 Criterion matchTargetAddress =
911 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700912 IPv6NDTargetAddressCriterion targetAddressCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800913 checkAndConvert(matchTargetAddress,
914 Criterion.Type.IPV6_ND_TARGET,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700915 IPv6NDTargetAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800916 assertThat(targetAddressCriterion.targetAddress(),
917 is(ip6TargetAddress1));
918 }
919
920 /**
921 * Test the equals() method of the IPv6NDTargetAddressCriterion class.
922 */
923 @Test
924 public void testIPv6NDTargetAddressCriterionEquals() {
925 new EqualsTester()
926 .addEqualityGroup(matchIpv6TargetAddr1,
927 sameAsMatchIpv6TargetAddr1)
928 .addEqualityGroup(matchIpv6TargetAddr2)
929 .testEquals();
930 }
931
932 // IPv6NDLinkLayerAddressCriterion class
933
934 /**
935 * Test the matchIPv6NDSourceLinkLayerAddress method.
936 */
937 @Test
938 public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
939 Criterion matchSrcLlAddr =
940 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700941 IPv6NDLinkLayerAddressCriterion srcLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800942 checkAndConvert(matchSrcLlAddr,
943 Criterion.Type.IPV6_ND_SLL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700944 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800945 assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
946 }
947
948 /**
949 * Test the matchIPv6NDTargetLinkLayerAddress method.
950 */
951 @Test
952 public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
953 Criterion matchTargetLlAddr =
954 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700955 IPv6NDLinkLayerAddressCriterion targetLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800956 checkAndConvert(matchTargetLlAddr,
957 Criterion.Type.IPV6_ND_TLL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700958 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800959 assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
960 }
961
962 /**
963 * Test the equals() method of the IPv6NDLinkLayerAddressCriterion class.
964 */
965 @Test
966 public void testIPv6NDLinkLayerAddressCriterionEquals() {
967 new EqualsTester()
968 .addEqualityGroup(matchSrcLlAddr1, sameAsMatchSrcLlAddr1)
969 .addEqualityGroup(matchSrcLlAddr2)
970 .testEquals();
971
972 new EqualsTester()
973 .addEqualityGroup(matchTargetLlAddr1, sameAsMatchTargetLlAddr1)
974 .addEqualityGroup(matchTargetLlAddr2)
975 .testEquals();
976 }
977
978 // MplsCriterion class
979
980 /**
981 * Test the matchMplsLabel method.
982 */
983 @Test
984 public void testMatchMplsLabelMethod() {
985 Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700986 MplsCriterion mplsCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800987 checkAndConvert(matchMplsLabel,
988 Criterion.Type.MPLS_LABEL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700989 MplsCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800990 assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
991 }
992
993 /**
994 * Test the equals() method of the MplsCriterion class.
995 */
996 @Test
997 public void testMplsCriterionEquals() {
998 new EqualsTester()
999 .addEqualityGroup(matchMpls1, sameAsMatchMpls1)
1000 .addEqualityGroup(matchMpls2)
1001 .testEquals();
1002 }
1003
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001004 // TunnelIdCriterion class
1005
1006 /**
1007 * Test the matchTunnelId method.
1008 */
1009 @Test
1010 public void testMatchTunnelIdMethod() {
1011 Criterion matchTunnelId = Criteria.matchTunnelId(tunnelId1);
1012 TunnelIdCriterion tunnelIdCriterion =
1013 checkAndConvert(matchTunnelId,
1014 Criterion.Type.TUNNEL_ID,
1015 TunnelIdCriterion.class);
1016 assertThat(tunnelIdCriterion.tunnelId(), is(equalTo(tunnelId1)));
1017
1018 }
1019
1020 /**
1021 * Test the equals() method of the TunnelIdCriterion class.
1022 */
1023 @Test
1024 public void testTunnelIdCriterionEquals() {
1025 new EqualsTester()
1026 .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
1027 .addEqualityGroup(matchTunnelId2)
1028 .testEquals();
1029 }
1030
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001031 // IPv6ExthdrFlagsCriterion class
1032
1033 /**
1034 * Test the matchIPv6ExthdrFlags method.
1035 */
1036 @Test
1037 public void testMatchIPv6ExthdrFlagsMethod() {
1038 Criterion matchExthdrFlags =
1039 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001040 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001041 checkAndConvert(matchExthdrFlags,
1042 Criterion.Type.IPV6_EXTHDR,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001043 IPv6ExthdrFlagsCriterion.class);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001044 assertThat(exthdrFlagsCriterion.exthdrFlags(),
1045 is(equalTo(ipv6ExthdrFlags1)));
1046 }
1047
1048 /**
1049 * Test the equals() method of the IPv6ExthdrFlagsCriterion class.
1050 */
1051 @Test
1052 public void testIPv6ExthdrFlagsCriterionEquals() {
1053 new EqualsTester()
1054 .addEqualityGroup(matchIpv6ExthdrFlags1,
1055 sameAsMatchIpv6ExthdrFlags1)
1056 .addEqualityGroup(matchIpv6ExthdrFlags2)
1057 .testEquals();
1058 }
1059
Ray Milkey33d90232014-11-04 10:49:00 -08001060 // LambdaCriterion class
1061
1062 /**
1063 * Test the matchLambda method.
1064 */
1065 @Test
1066 public void testMatchLambdaMethod() {
1067 Criterion matchLambda = Criteria.matchLambda(lambda1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001068 LambdaCriterion lambdaCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -08001069 checkAndConvert(matchLambda,
1070 Criterion.Type.OCH_SIGID,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001071 LambdaCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -08001072 assertThat(lambdaCriterion.lambda(), is(equalTo(lambda1)));
1073 }
1074
1075 /**
1076 * Test the equals() method of the LambdaCriterion class.
1077 */
1078 @Test
1079 public void testLambdaCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -08001080 new EqualsTester()
1081 .addEqualityGroup(matchLambda1, sameAsMatchLambda1)
1082 .addEqualityGroup(matchLambda2)
1083 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -08001084 }
1085
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001086 @Test
Sho SHIMIZUefc2e282015-05-04 15:26:23 -07001087 public void testIndexedLambdaCriterionEquals() {
1088 new EqualsTester()
1089 .addEqualityGroup(matchIndexedLambda1, sameAsMatchIndexedLambda1)
1090 .addEqualityGroup(matchIndexedLambda2)
1091 .testEquals();
1092 }
1093
1094 @Test
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001095 public void testOchSignalCriterionEquals() {
1096 new EqualsTester()
1097 .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1)
1098 .addEqualityGroup(matchOchSignal2)
1099 .testEquals();
1100 }
1101
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -07001102 /**
1103 * Test the equals() method of the OchSignalTypeCriterion class.
1104 */
1105 @Test
1106 public void testOchSignalTypeCriterionEquals() {
1107 new EqualsTester()
1108 .addEqualityGroup(matchOchSignalType1, sameAsMatchOchSignalType1)
1109 .addEqualityGroup(matchOchSignalType2)
1110 .testEquals();
1111 }
1112
Ray Milkey33d90232014-11-04 10:49:00 -08001113 // OpticalSignalTypeCriterion class
1114
1115 /**
1116 * Test the matchOpticalSignalType method.
1117 */
1118 @Test
1119 public void testMatchOpticalSignalTypeMethod() {
1120 Criterion matchLambda = Criteria.matchOpticalSignalType(signalLambda1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001121 OpticalSignalTypeCriterion opticalSignalTypeCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -08001122 checkAndConvert(matchLambda,
1123 Criterion.Type.OCH_SIGTYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001124 OpticalSignalTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -08001125 assertThat(opticalSignalTypeCriterion.signalType(), is(equalTo(signalLambda1)));
1126 }
1127
1128 /**
1129 * Test the equals() method of the OpticalSignalTypeCriterion class.
1130 */
1131 @Test
1132 public void testOpticalSignalTypeCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -08001133 new EqualsTester()
1134 .addEqualityGroup(matchSignalLambda1, sameAsMatchSignalLambda1)
1135 .addEqualityGroup(matchSignalLambda2)
1136 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -08001137 }
Ray Milkey33d90232014-11-04 10:49:00 -08001138}