blob: d86744df28918a774a7a50fb4f177325053b0597 [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
Yafit Hadar52d81552015-10-07 12:26:52 +030018import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.equalTo;
20import static org.hamcrest.Matchers.instanceOf;
21import static org.hamcrest.Matchers.is;
22import static org.hamcrest.Matchers.notNullValue;
23import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
24import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
25import static org.onosproject.net.OduSignalId.oduSignalId;
26import static org.onosproject.net.PortNumber.portNumber;
27
Ray Milkey33d90232014-11-04 10:49:00 -080028import org.junit.Test;
alshabibcaf1ca22015-06-25 15:18:16 -070029import org.onlab.packet.EthType;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070030import org.onlab.packet.Ip6Address;
31import org.onlab.packet.IpPrefix;
32import org.onlab.packet.MacAddress;
33import org.onlab.packet.MplsLabel;
34import org.onlab.packet.TpPort;
35import org.onlab.packet.VlanId;
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -070036import org.onosproject.net.ChannelSpacing;
37import org.onosproject.net.GridType;
38import org.onosproject.net.Lambda;
Yafit Hadar52d81552015-10-07 12:26:52 +030039import org.onosproject.net.OchSignalType;
40import org.onosproject.net.OduSignalId;
41import org.onosproject.net.OduSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080042import org.onosproject.net.PortNumber;
Ray Milkey33d90232014-11-04 10:49:00 -080043
Ray Milkeyfff20b52014-11-06 14:45:10 -080044import com.google.common.testing.EqualsTester;
Ray Milkey33d90232014-11-04 10:49:00 -080045/**
46 * Unit tests for the Criteria class and its subclasses.
47 */
48public class CriteriaTest {
49
50 final PortNumber port1 = portNumber(1);
51 final PortNumber port2 = portNumber(2);
52
53 Criterion matchInPort1 = Criteria.matchInPort(port1);
54 Criterion sameAsMatchInPort1 = Criteria.matchInPort(port1);
55 Criterion matchInPort2 = Criteria.matchInPort(port2);
56
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080057 Criterion matchInPhyPort1 = Criteria.matchInPhyPort(port1);
58 Criterion sameAsMatchInPhyPort1 = Criteria.matchInPhyPort(port1);
59 Criterion matchInPhyPort2 = Criteria.matchInPhyPort(port2);
60
61 long metadata1 = 1;
62 long metadata2 = 2;
63 Criterion matchMetadata1 = Criteria.matchMetadata(metadata1);
64 Criterion sameAsMatchMetadata1 = Criteria.matchMetadata(metadata1);
65 Criterion matchMetadata2 = Criteria.matchMetadata(metadata2);
66
Ray Milkey33d90232014-11-04 10:49:00 -080067 private static final String MAC1 = "00:00:00:00:00:01";
68 private static final String MAC2 = "00:00:00:00:00:02";
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080069 private MacAddress mac1 = MacAddress.valueOf(MAC1);
70 private MacAddress mac2 = MacAddress.valueOf(MAC2);
Ray Milkey33d90232014-11-04 10:49:00 -080071 Criterion matchEth1 = Criteria.matchEthSrc(mac1);
72 Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1);
73 Criterion matchEth2 = Criteria.matchEthDst(mac2);
74
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080075 int ethType1 = 1;
76 int ethType2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -080077 Criterion matchEthType1 = Criteria.matchEthType(ethType1);
78 Criterion sameAsMatchEthType1 = Criteria.matchEthType(ethType1);
79 Criterion matchEthType2 = Criteria.matchEthType(ethType2);
80
81 short vlan1 = 1;
82 short vlan2 = 2;
83 VlanId vlanId1 = VlanId.vlanId(vlan1);
84 VlanId vlanId2 = VlanId.vlanId(vlan2);
85 Criterion matchVlanId1 = Criteria.matchVlanId(vlanId1);
86 Criterion sameAsMatchVlanId1 = Criteria.matchVlanId(vlanId1);
87 Criterion matchVlanId2 = Criteria.matchVlanId(vlanId2);
88
89 byte vlanPcp1 = 1;
90 byte vlanPcp2 = 2;
91 Criterion matchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
92 Criterion sameAsMatchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
93 Criterion matchVlanPcp2 = Criteria.matchVlanPcp(vlanPcp2);
94
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080095 byte ipDscp1 = 1;
96 byte ipDscp2 = 2;
97 Criterion matchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
98 Criterion sameAsMatchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
99 Criterion matchIpDscp2 = Criteria.matchIPDscp(ipDscp2);
100
101 byte ipEcn1 = 1;
102 byte ipEcn2 = 2;
103 Criterion matchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
104 Criterion sameAsMatchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
105 Criterion matchIpEcn2 = Criteria.matchIPEcn(ipEcn2);
106
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800107 short protocol1 = 1;
108 short protocol2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -0800109 Criterion matchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
110 Criterion sameAsMatchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
111 Criterion matchIpProtocol2 = Criteria.matchIPProtocol(protocol2);
112
113 private static final String IP1 = "1.2.3.4/24";
114 private static final String IP2 = "5.6.7.8/24";
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800115 private static final String IPV61 = "fe80::1/64";
116 private static final String IPV62 = "fc80::2/64";
Ray Milkey33d90232014-11-04 10:49:00 -0800117 private IpPrefix ip1 = IpPrefix.valueOf(IP1);
118 private IpPrefix ip2 = IpPrefix.valueOf(IP2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800119 private IpPrefix ipv61 = IpPrefix.valueOf(IPV61);
120 private IpPrefix ipv62 = IpPrefix.valueOf(IPV62);
Ray Milkey33d90232014-11-04 10:49:00 -0800121 Criterion matchIp1 = Criteria.matchIPSrc(ip1);
122 Criterion sameAsMatchIp1 = Criteria.matchIPSrc(ip1);
123 Criterion matchIp2 = Criteria.matchIPSrc(ip2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800124 Criterion matchIpv61 = Criteria.matchIPSrc(ipv61);
125 Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
126 Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
Ray Milkey33d90232014-11-04 10:49:00 -0800127
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700128 private TpPort tpPort1 = TpPort.tpPort(1);
129 private TpPort tpPort2 = TpPort.tpPort(2);
130 Criterion matchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
131 Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
132 Criterion matchTcpPort2 = Criteria.matchTcpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800133
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700134 Criterion matchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
135 Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
136 Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800137
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700138 Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
139 Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
140 Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800141
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800142 short icmpType1 = 1;
143 short icmpType2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800144 Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1);
145 Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1);
146 Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2);
147
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800148 short icmpCode1 = 1;
149 short icmpCode2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800150 Criterion matchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
151 Criterion sameAsMatchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
152 Criterion matchIcmpCode2 = Criteria.matchIcmpCode(icmpCode2);
153
154 int flowLabel1 = 1;
155 int flowLabel2 = 2;
156 Criterion matchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
157 Criterion sameAsMatchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
158 Criterion matchFlowLabel2 = Criteria.matchIPv6FlowLabel(flowLabel2);
159
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800160 short icmpv6Type1 = 1;
161 short icmpv6Type2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800162 Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
163 Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
164 Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2);
165
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800166 short icmpv6Code1 = 1;
167 short icmpv6Code2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800168 Criterion matchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
169 Criterion sameAsMatchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
170 Criterion matchIcmpv6Code2 = Criteria.matchIcmpv6Code(icmpv6Code2);
171
172 private static final String IPV6_ADDR1 = "fe80::1";
173 private static final String IPV6_ADDR2 = "fe80::2";
174 private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
175 private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
176 Criterion matchIpv6TargetAddr1 =
177 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
178 Criterion sameAsMatchIpv6TargetAddr1 =
179 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
180 Criterion matchIpv6TargetAddr2 =
181 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
182
183 private static final String LL_MAC1 = "00:00:00:00:00:01";
184 private static final String LL_MAC2 = "00:00:00:00:00:02";
185 private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
186 private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
187 Criterion matchSrcLlAddr1 =
188 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
189 Criterion sameAsMatchSrcLlAddr1 =
190 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
191 Criterion matchSrcLlAddr2 =
192 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
193 Criterion matchTargetLlAddr1 =
194 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
195 Criterion sameAsMatchTargetLlAddr1 =
196 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
197 Criterion matchTargetLlAddr2 =
198 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
199
Michele Santuari4b6019e2014-12-19 11:31:45 +0100200 MplsLabel mpls1 = MplsLabel.mplsLabel(1);
201 MplsLabel mpls2 = MplsLabel.mplsLabel(2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800202 Criterion matchMpls1 = Criteria.matchMplsLabel(mpls1);
203 Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1);
204 Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2);
205
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700206 long tunnelId1 = 1;
207 long tunnelId2 = 2;
208 Criterion matchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
209 Criterion sameAsMatchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
210 Criterion matchTunnelId2 = Criteria.matchTunnelId(tunnelId2);
211
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800212 int ipv6ExthdrFlags1 =
213 Criterion.IPv6ExthdrFlags.NONEXT.getValue() |
214 Criterion.IPv6ExthdrFlags.ESP.getValue() |
215 Criterion.IPv6ExthdrFlags.AUTH.getValue() |
216 Criterion.IPv6ExthdrFlags.DEST.getValue() |
217 Criterion.IPv6ExthdrFlags.FRAG.getValue() |
218 Criterion.IPv6ExthdrFlags.ROUTER.getValue() |
219 Criterion.IPv6ExthdrFlags.HOP.getValue() |
220 Criterion.IPv6ExthdrFlags.UNREP.getValue();
221 int ipv6ExthdrFlags2 = ipv6ExthdrFlags1 |
222 Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
223 Criterion matchIpv6ExthdrFlags1 =
224 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
225 Criterion sameAsMatchIpv6ExthdrFlags1 =
226 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
227 Criterion matchIpv6ExthdrFlags2 =
228 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
229
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700230 Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
231 Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -0700232 Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID);
233
Sho SHIMIZUefc2e282015-05-04 15:26:23 -0700234 Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
235 Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
236 Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2));
237
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -0700238 Criterion matchOchSignal1 =
239 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
240 Criterion sameAsMatchOchSignal1 =
241 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
242 Criterion matchOchSignal2 =
243 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
244
Yafit Hadar52d81552015-10-07 12:26:52 +0300245 final OduSignalId odu1 = oduSignalId(1, 80, new byte [] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
246 final OduSignalId odu2 = oduSignalId(3, 8, new byte [] {1, 0, 0, 0, 0, 0, 0, 0, 0, 0});
247 Criterion matchOduSignalId1 = Criteria.matchOduSignalId(odu1);
248 Criterion sameAsMatchOduSignalId1 = Criteria.matchOduSignalId(odu1);
249 Criterion matchOduSignalId2 = Criteria.matchOduSignalId(odu2);
250
251 final OduSignalType oduSigType1 = OduSignalType.ODU2;
252 final OduSignalType oduSigType2 = OduSignalType.ODU4;
253 Criterion matchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1);
254 Criterion sameAsMatchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1);
255 Criterion matchOduSignalType2 = Criteria.matchOduSignalType(oduSigType2);
256
Ray Milkey33d90232014-11-04 10:49:00 -0800257 /**
258 * Checks that a Criterion object has the proper type, and then converts
259 * it to the proper type.
260 *
261 * @param criterion Criterion object to convert
262 * @param type Enumerated type value for the Criterion class
263 * @param clazz Desired Criterion class
264 * @param <T> The type the caller wants returned
265 * @return converted object
266 */
267 @SuppressWarnings("unchecked")
268 private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) {
269 assertThat(criterion, is(notNullValue()));
270 assertThat(criterion.type(), is(equalTo(type)));
Ray Milkey78081052014-11-05 10:38:12 -0800271 assertThat(criterion, instanceOf(clazz));
Ray Milkey33d90232014-11-04 10:49:00 -0800272 return (T) criterion;
273 }
274
275 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800276 * Check that the Criteria class is a valid utility class.
277 */
278 @Test
279 public void testCriteriaUtility() {
280 assertThatClassIsUtility(Criteria.class);
281 }
282
283 /**
284 * Check that the Criteria implementations are immutable.
285 */
286 @Test
287 public void testCriteriaImmutability() {
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700288 assertThatClassIsImmutable(PortCriterion.class);
289 assertThatClassIsImmutable(MetadataCriterion.class);
290 assertThatClassIsImmutable(EthCriterion.class);
291 assertThatClassIsImmutable(EthTypeCriterion.class);
292 assertThatClassIsImmutable(VlanIdCriterion.class);
293 assertThatClassIsImmutable(VlanPcpCriterion.class);
294 assertThatClassIsImmutable(IPDscpCriterion.class);
295 assertThatClassIsImmutable(IPEcnCriterion.class);
296 assertThatClassIsImmutable(IPProtocolCriterion.class);
297 assertThatClassIsImmutable(IPCriterion.class);
298 assertThatClassIsImmutable(TcpPortCriterion.class);
299 assertThatClassIsImmutable(UdpPortCriterion.class);
300 assertThatClassIsImmutable(SctpPortCriterion.class);
301 assertThatClassIsImmutable(IcmpTypeCriterion.class);
302 assertThatClassIsImmutable(IcmpCodeCriterion.class);
303 assertThatClassIsImmutable(IPv6FlowLabelCriterion.class);
304 assertThatClassIsImmutable(Icmpv6TypeCriterion.class);
305 assertThatClassIsImmutable(Icmpv6CodeCriterion.class);
306 assertThatClassIsImmutable(IPv6NDTargetAddressCriterion.class);
307 assertThatClassIsImmutable(IPv6NDLinkLayerAddressCriterion.class);
308 assertThatClassIsImmutable(MplsCriterion.class);
309 assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class);
310 assertThatClassIsImmutable(LambdaCriterion.class);
Yafit Hadar52d81552015-10-07 12:26:52 +0300311 assertThatClassIsImmutable(OduSignalIdCriterion.class);
312 assertThatClassIsImmutable(OduSignalTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800313 }
314
315 // PortCriterion class
316
317 /**
318 * Test the matchInPort method.
319 */
320 @Test
321 public void testMatchInPortMethod() {
322 PortNumber p1 = portNumber(1);
323 Criterion matchInPort = Criteria.matchInPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700324 PortCriterion portCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800325 checkAndConvert(matchInPort,
326 Criterion.Type.IN_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700327 PortCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800328 assertThat(portCriterion.port(), is(equalTo(p1)));
329 }
330
331 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800332 * Test the matchInPhyPort method.
333 */
334 @Test
335 public void testMatchInPhyPortMethod() {
336 PortNumber p1 = portNumber(1);
337 Criterion matchInPhyPort = Criteria.matchInPhyPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700338 PortCriterion portCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800339 checkAndConvert(matchInPhyPort,
340 Criterion.Type.IN_PHY_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700341 PortCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800342 assertThat(portCriterion.port(), is(equalTo(p1)));
343 }
344
345 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800346 * Test the equals() method of the PortCriterion class.
347 */
348 @Test
349 public void testPortCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800350 new EqualsTester()
351 .addEqualityGroup(matchInPort1, sameAsMatchInPort1)
352 .addEqualityGroup(matchInPort2)
353 .testEquals();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800354
355 new EqualsTester()
356 .addEqualityGroup(matchInPhyPort1, sameAsMatchInPhyPort1)
357 .addEqualityGroup(matchInPhyPort2)
358 .testEquals();
359 }
360
361 // MetadataCriterion class
362
363 /**
364 * Test the matchMetadata method.
365 */
366 @Test
367 public void testMatchMetadataMethod() {
368 Long metadata = 12L;
369 Criterion matchMetadata = Criteria.matchMetadata(metadata);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700370 MetadataCriterion metadataCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800371 checkAndConvert(matchMetadata,
372 Criterion.Type.METADATA,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700373 MetadataCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800374 assertThat(metadataCriterion.metadata(), is(equalTo(metadata)));
375 }
376
377 /**
378 * Test the equals() method of the MetadataCriterion class.
379 */
380 @Test
381 public void testMetadataCriterionEquals() {
382 new EqualsTester()
383 .addEqualityGroup(matchMetadata1, sameAsMatchMetadata1)
384 .addEqualityGroup(matchMetadata2)
385 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800386 }
387
388 // EthCriterion class
389
390 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800391 * Test the matchEthDst method.
392 */
393 @Test
394 public void testMatchEthDstMethod() {
395 Criterion matchEthDst = Criteria.matchEthDst(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700396 EthCriterion ethCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800397 checkAndConvert(matchEthDst,
398 Criterion.Type.ETH_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700399 EthCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800400 assertThat(ethCriterion.mac(), is(equalTo(mac1)));
401 }
402
403 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800404 * Test the matchEthSrc method.
405 */
406 @Test
407 public void testMatchEthSrcMethod() {
408 Criterion matchEthSrc = Criteria.matchEthSrc(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700409 EthCriterion ethCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800410 checkAndConvert(matchEthSrc,
411 Criterion.Type.ETH_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700412 EthCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800413 assertThat(ethCriterion.mac(), is(mac1));
414 }
415
416 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800417 * Test the equals() method of the EthCriterion class.
418 */
419 @Test
420 public void testEthCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800421 new EqualsTester()
422 .addEqualityGroup(matchEth1, sameAsMatchEth1)
423 .addEqualityGroup(matchEth2)
424 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800425 }
426
Ray Milkey33d90232014-11-04 10:49:00 -0800427 // EthTypeCriterion class
428
429 /**
430 * Test the matchEthType method.
431 */
432 @Test
433 public void testMatchEthTypeMethod() {
alshabibcaf1ca22015-06-25 15:18:16 -0700434 EthType ethType = new EthType(12);
435 Criterion matchEthType = Criteria.matchEthType(new EthType(12));
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700436 EthTypeCriterion ethTypeCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800437 checkAndConvert(matchEthType,
438 Criterion.Type.ETH_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700439 EthTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800440 assertThat(ethTypeCriterion.ethType(), is(equalTo(ethType)));
441 }
442
443 /**
444 * Test the equals() method of the EthTypeCriterion class.
445 */
446 @Test
447 public void testEthTypeCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800448 new EqualsTester()
449 .addEqualityGroup(matchEthType1, sameAsMatchEthType1)
450 .addEqualityGroup(matchEthType2)
451 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800452 }
453
Ray Milkey33d90232014-11-04 10:49:00 -0800454 // VlanIdCriterion class
455
456 /**
457 * Test the matchVlanId method.
458 */
459 @Test
460 public void testMatchVlanIdMethod() {
461 Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700462 VlanIdCriterion vlanIdCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800463 checkAndConvert(matchVlanId,
464 Criterion.Type.VLAN_VID,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700465 VlanIdCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800466 assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
467 }
468
469 /**
470 * Test the equals() method of the VlanIdCriterion class.
471 */
472 @Test
473 public void testVlanIdCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800474 new EqualsTester()
475 .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1)
476 .addEqualityGroup(matchVlanId2)
477 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800478 }
479
480 // VlanPcpCriterion class
481
482 /**
483 * Test the matchVlanPcp method.
484 */
485 @Test
486 public void testMatchVlanPcpMethod() {
487 Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700488 VlanPcpCriterion vlanPcpCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800489 checkAndConvert(matchVlanPcp,
490 Criterion.Type.VLAN_PCP,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700491 VlanPcpCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800492 assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
493 }
494
495 /**
496 * Test the equals() method of the VlanPcpCriterion class.
497 */
498 @Test
499 public void testVlanPcpCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800500 new EqualsTester()
501 .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1)
502 .addEqualityGroup(matchVlanPcp2)
503 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800504 }
505
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800506 // IPDscpCriterion class
507
508 /**
509 * Test the matchIPDscp method.
510 */
511 @Test
512 public void testMatchIPDscpMethod() {
513 Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700514 IPDscpCriterion ipDscpCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800515 checkAndConvert(matchIPDscp,
516 Criterion.Type.IP_DSCP,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700517 IPDscpCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800518 assertThat(ipDscpCriterion.ipDscp(), is(equalTo(ipDscp1)));
519 }
520
521 /**
522 * Test the equals() method of the IPDscpCriterion class.
523 */
524 @Test
525 public void testIPDscpCriterionEquals() {
526 new EqualsTester()
527 .addEqualityGroup(matchIpDscp1, sameAsMatchIpDscp1)
528 .addEqualityGroup(matchIpDscp2)
529 .testEquals();
530 }
531
532 // IPEcnCriterion class
533
534 /**
535 * Test the matchIPEcn method.
536 */
537 @Test
538 public void testMatchIPEcnMethod() {
539 Criterion matchIPEcn = Criteria.matchIPEcn(ipEcn1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700540 IPEcnCriterion ipEcnCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800541 checkAndConvert(matchIPEcn,
542 Criterion.Type.IP_ECN,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700543 IPEcnCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800544 assertThat(ipEcnCriterion.ipEcn(), is(equalTo(ipEcn1)));
545 }
546
547 /**
548 * Test the equals() method of the IPEcnCriterion class.
549 */
550 @Test
551 public void testIPEcnCriterionEquals() {
552 new EqualsTester()
553 .addEqualityGroup(matchIpEcn1, sameAsMatchIpEcn1)
554 .addEqualityGroup(matchIpEcn2)
555 .testEquals();
556 }
557
Ray Milkey33d90232014-11-04 10:49:00 -0800558 // IpProtocolCriterion class
559
560 /**
561 * Test the matchIpProtocol method.
562 */
563 @Test
564 public void testMatchIpProtocolMethod() {
565 Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700566 IPProtocolCriterion ipProtocolCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800567 checkAndConvert(matchIPProtocol,
568 Criterion.Type.IP_PROTO,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700569 IPProtocolCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800570 assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
571 }
572
573 /**
574 * Test the equals() method of the IpProtocolCriterion class.
575 */
576 @Test
577 public void testIpProtocolCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800578 new EqualsTester()
579 .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1)
580 .addEqualityGroup(matchIpProtocol2)
581 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800582 }
583
584 // IPCriterion class
585
586 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800587 * Test the matchIPSrc method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800588 */
589 @Test
590 public void testMatchIPSrcMethod() {
591 Criterion matchIpSrc = Criteria.matchIPSrc(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700592 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800593 checkAndConvert(matchIpSrc,
594 Criterion.Type.IPV4_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700595 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800596 assertThat(ipCriterion.ip(), is(ip1));
597 }
598
599 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800600 * Test the matchIPDst method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800601 */
602 @Test
603 public void testMatchIPDstMethod() {
604 Criterion matchIPDst = Criteria.matchIPDst(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700605 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800606 checkAndConvert(matchIPDst,
607 Criterion.Type.IPV4_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700608 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800609 assertThat(ipCriterion.ip(), is(equalTo(ip1)));
610 }
611
612 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800613 * Test the matchIPSrc method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800614 */
615 @Test
616 public void testMatchIPv6SrcMethod() {
617 Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700618 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800619 checkAndConvert(matchIpv6Src,
620 Criterion.Type.IPV6_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700621 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800622 assertThat(ipCriterion.ip(), is(ipv61));
623 }
624
625 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800626 * Test the matchIPDst method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800627 */
628 @Test
629 public void testMatchIPv6DstMethod() {
630 Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700631 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800632 checkAndConvert(matchIPv6Dst,
633 Criterion.Type.IPV6_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700634 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800635 assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
636 }
637
638 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800639 * Test the equals() method of the IpCriterion class.
640 */
641 @Test
642 public void testIPCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800643 new EqualsTester()
644 .addEqualityGroup(matchIp1, sameAsMatchIp1)
645 .addEqualityGroup(matchIp2)
646 .testEquals();
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800647
648 new EqualsTester()
649 .addEqualityGroup(matchIpv61, sameAsMatchIpv61)
650 .addEqualityGroup(matchIpv62)
651 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800652 }
653
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800654 // TcpPortCriterion class
655
656 /**
657 * Test the matchTcpSrc method.
658 */
659 @Test
660 public void testMatchTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700661 Criterion matchTcpSrc = Criteria.matchTcpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700662 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800663 checkAndConvert(matchTcpSrc,
664 Criterion.Type.TCP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700665 TcpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700666 assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800667 }
668
669 /**
670 * Test the matchTcpDst method.
671 */
672 @Test
673 public void testMatchTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700674 Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700675 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800676 checkAndConvert(matchTcpDst,
677 Criterion.Type.TCP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700678 TcpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700679 assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800680 }
681
682 /**
683 * Test the equals() method of the TcpPortCriterion class.
684 */
685 @Test
686 public void testTcpPortCriterionEquals() {
687 new EqualsTester()
688 .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
689 .addEqualityGroup(matchTcpPort2)
690 .testEquals();
691 }
692
693 // UdpPortCriterion class
694
695 /**
696 * Test the matchUdpSrc method.
697 */
698 @Test
699 public void testMatchUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700700 Criterion matchUdpSrc = Criteria.matchUdpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700701 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800702 checkAndConvert(matchUdpSrc,
703 Criterion.Type.UDP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700704 UdpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700705 assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800706 }
707
708 /**
709 * Test the matchUdpDst method.
710 */
711 @Test
712 public void testMatchUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700713 Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700714 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800715 checkAndConvert(matchUdpDst,
716 Criterion.Type.UDP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700717 UdpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700718 assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800719 }
720
721 /**
722 * Test the equals() method of the UdpPortCriterion class.
723 */
724 @Test
725 public void testUdpPortCriterionEquals() {
726 new EqualsTester()
727 .addEqualityGroup(matchUdpPort1, sameAsMatchUdpPort1)
728 .addEqualityGroup(matchUdpPort2)
729 .testEquals();
730 }
731
732 // SctpPortCriterion class
733
734 /**
735 * Test the matchSctpSrc method.
736 */
737 @Test
738 public void testMatchSctpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700739 Criterion matchSctpSrc = Criteria.matchSctpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700740 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800741 checkAndConvert(matchSctpSrc,
742 Criterion.Type.SCTP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700743 SctpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700744 assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800745 }
746
747 /**
748 * Test the matchSctpDst method.
749 */
750 @Test
751 public void testMatchSctpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700752 Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700753 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800754 checkAndConvert(matchSctpDst,
755 Criterion.Type.SCTP_DST,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700756 SctpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700757 assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800758 }
759
760 /**
761 * Test the equals() method of the SctpPortCriterion class.
762 */
763 @Test
764 public void testSctpPortCriterionEquals() {
765 new EqualsTester()
766 .addEqualityGroup(matchSctpPort1, sameAsMatchSctpPort1)
767 .addEqualityGroup(matchSctpPort2)
768 .testEquals();
769 }
770
771 // IcmpTypeCriterion class
772
773 /**
774 * Test the matchIcmpType method.
775 */
776 @Test
777 public void testMatchIcmpTypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800778 short icmpType = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800779 Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700780 IcmpTypeCriterion icmpTypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800781 checkAndConvert(matchIcmpType,
782 Criterion.Type.ICMPV4_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700783 IcmpTypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800784 assertThat(icmpTypeCriterion.icmpType(), is(equalTo(icmpType)));
785 }
786
787 /**
788 * Test the equals() method of the IcmpTypeCriterion class.
789 */
790 @Test
791 public void testIcmpTypeCriterionEquals() {
792 new EqualsTester()
793 .addEqualityGroup(matchIcmpType1, sameAsMatchIcmpType1)
794 .addEqualityGroup(matchIcmpType2)
795 .testEquals();
796 }
797
798 // IcmpCodeCriterion class
799
800 /**
801 * Test the matchIcmpCode method.
802 */
803 @Test
804 public void testMatchIcmpCodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800805 short icmpCode = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800806 Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700807 IcmpCodeCriterion icmpCodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800808 checkAndConvert(matchIcmpCode,
809 Criterion.Type.ICMPV4_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700810 IcmpCodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800811 assertThat(icmpCodeCriterion.icmpCode(), is(equalTo(icmpCode)));
812 }
813
814 /**
815 * Test the equals() method of the IcmpCodeCriterion class.
816 */
817 @Test
818 public void testIcmpCodeCriterionEquals() {
819 new EqualsTester()
820 .addEqualityGroup(matchIcmpCode1, sameAsMatchIcmpCode1)
821 .addEqualityGroup(matchIcmpCode2)
822 .testEquals();
823 }
824
825 // IPv6FlowLabelCriterion class
826
827 /**
828 * Test the matchIPv6FlowLabel method.
829 */
830 @Test
831 public void testMatchIPv6FlowLabelMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800832 int flowLabel = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800833 Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700834 IPv6FlowLabelCriterion flowLabelCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800835 checkAndConvert(matchFlowLabel,
836 Criterion.Type.IPV6_FLABEL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700837 IPv6FlowLabelCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800838 assertThat(flowLabelCriterion.flowLabel(), is(equalTo(flowLabel)));
839 }
840
841 /**
842 * Test the equals() method of the IPv6FlowLabelCriterion class.
843 */
844 @Test
845 public void testIPv6FlowLabelCriterionEquals() {
846 new EqualsTester()
847 .addEqualityGroup(matchFlowLabel1, sameAsMatchFlowLabel1)
848 .addEqualityGroup(matchFlowLabel2)
849 .testEquals();
850 }
851
852 // Icmpv6TypeCriterion class
853
854 /**
855 * Test the matchIcmpv6Type method.
856 */
857 @Test
858 public void testMatchIcmpv6TypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800859 short icmpv6Type = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800860 Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700861 Icmpv6TypeCriterion icmpv6TypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800862 checkAndConvert(matchIcmpv6Type,
863 Criterion.Type.ICMPV6_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700864 Icmpv6TypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800865 assertThat(icmpv6TypeCriterion.icmpv6Type(), is(equalTo(icmpv6Type)));
866 }
867
868 /**
869 * Test the equals() method of the Icmpv6TypeCriterion class.
870 */
871 @Test
872 public void testIcmpv6TypeCriterionEquals() {
873 new EqualsTester()
874 .addEqualityGroup(matchIcmpv6Type1, sameAsMatchIcmpv6Type1)
875 .addEqualityGroup(matchIcmpv6Type2)
876 .testEquals();
877 }
878
879 // Icmpv6CodeCriterion class
880
881 /**
882 * Test the matchIcmpv6Code method.
883 */
884 @Test
885 public void testMatchIcmpv6CodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800886 short icmpv6Code = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800887 Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700888 Icmpv6CodeCriterion icmpv6CodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800889 checkAndConvert(matchIcmpv6Code,
890 Criterion.Type.ICMPV6_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700891 Icmpv6CodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800892 assertThat(icmpv6CodeCriterion.icmpv6Code(), is(equalTo(icmpv6Code)));
893 }
894
895 /**
896 * Test the equals() method of the Icmpv6CodeCriterion class.
897 */
898 @Test
899 public void testIcmpv6CodeCriterionEquals() {
900 new EqualsTester()
901 .addEqualityGroup(matchIcmpv6Code1, sameAsMatchIcmpv6Code1)
902 .addEqualityGroup(matchIcmpv6Code2)
903 .testEquals();
904 }
905
906 // IPv6NDTargetAddressCriterion class
907
908 /**
909 * Test the matchIPv6NDTargetAddress method.
910 */
911 @Test
912 public void testMatchIPv6NDTargetAddressMethod() {
913 Criterion matchTargetAddress =
914 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700915 IPv6NDTargetAddressCriterion targetAddressCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800916 checkAndConvert(matchTargetAddress,
917 Criterion.Type.IPV6_ND_TARGET,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700918 IPv6NDTargetAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800919 assertThat(targetAddressCriterion.targetAddress(),
920 is(ip6TargetAddress1));
921 }
922
923 /**
924 * Test the equals() method of the IPv6NDTargetAddressCriterion class.
925 */
926 @Test
927 public void testIPv6NDTargetAddressCriterionEquals() {
928 new EqualsTester()
929 .addEqualityGroup(matchIpv6TargetAddr1,
930 sameAsMatchIpv6TargetAddr1)
931 .addEqualityGroup(matchIpv6TargetAddr2)
932 .testEquals();
933 }
934
935 // IPv6NDLinkLayerAddressCriterion class
936
937 /**
938 * Test the matchIPv6NDSourceLinkLayerAddress method.
939 */
940 @Test
941 public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
942 Criterion matchSrcLlAddr =
943 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700944 IPv6NDLinkLayerAddressCriterion srcLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800945 checkAndConvert(matchSrcLlAddr,
946 Criterion.Type.IPV6_ND_SLL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700947 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800948 assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
949 }
950
951 /**
952 * Test the matchIPv6NDTargetLinkLayerAddress method.
953 */
954 @Test
955 public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
956 Criterion matchTargetLlAddr =
957 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700958 IPv6NDLinkLayerAddressCriterion targetLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800959 checkAndConvert(matchTargetLlAddr,
960 Criterion.Type.IPV6_ND_TLL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700961 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800962 assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
963 }
964
965 /**
966 * Test the equals() method of the IPv6NDLinkLayerAddressCriterion class.
967 */
968 @Test
969 public void testIPv6NDLinkLayerAddressCriterionEquals() {
970 new EqualsTester()
971 .addEqualityGroup(matchSrcLlAddr1, sameAsMatchSrcLlAddr1)
972 .addEqualityGroup(matchSrcLlAddr2)
973 .testEquals();
974
975 new EqualsTester()
976 .addEqualityGroup(matchTargetLlAddr1, sameAsMatchTargetLlAddr1)
977 .addEqualityGroup(matchTargetLlAddr2)
978 .testEquals();
979 }
980
981 // MplsCriterion class
982
983 /**
984 * Test the matchMplsLabel method.
985 */
986 @Test
987 public void testMatchMplsLabelMethod() {
988 Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700989 MplsCriterion mplsCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800990 checkAndConvert(matchMplsLabel,
991 Criterion.Type.MPLS_LABEL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700992 MplsCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800993 assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
994 }
995
996 /**
997 * Test the equals() method of the MplsCriterion class.
998 */
999 @Test
1000 public void testMplsCriterionEquals() {
1001 new EqualsTester()
1002 .addEqualityGroup(matchMpls1, sameAsMatchMpls1)
1003 .addEqualityGroup(matchMpls2)
1004 .testEquals();
1005 }
1006
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001007 // TunnelIdCriterion class
1008
1009 /**
1010 * Test the matchTunnelId method.
1011 */
1012 @Test
1013 public void testMatchTunnelIdMethod() {
1014 Criterion matchTunnelId = Criteria.matchTunnelId(tunnelId1);
1015 TunnelIdCriterion tunnelIdCriterion =
1016 checkAndConvert(matchTunnelId,
1017 Criterion.Type.TUNNEL_ID,
1018 TunnelIdCriterion.class);
1019 assertThat(tunnelIdCriterion.tunnelId(), is(equalTo(tunnelId1)));
1020
1021 }
1022
1023 /**
1024 * Test the equals() method of the TunnelIdCriterion class.
1025 */
1026 @Test
1027 public void testTunnelIdCriterionEquals() {
1028 new EqualsTester()
1029 .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
1030 .addEqualityGroup(matchTunnelId2)
1031 .testEquals();
1032 }
1033
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001034 // IPv6ExthdrFlagsCriterion class
1035
1036 /**
1037 * Test the matchIPv6ExthdrFlags method.
1038 */
1039 @Test
1040 public void testMatchIPv6ExthdrFlagsMethod() {
1041 Criterion matchExthdrFlags =
1042 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001043 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001044 checkAndConvert(matchExthdrFlags,
1045 Criterion.Type.IPV6_EXTHDR,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001046 IPv6ExthdrFlagsCriterion.class);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001047 assertThat(exthdrFlagsCriterion.exthdrFlags(),
1048 is(equalTo(ipv6ExthdrFlags1)));
1049 }
1050
1051 /**
1052 * Test the equals() method of the IPv6ExthdrFlagsCriterion class.
1053 */
1054 @Test
1055 public void testIPv6ExthdrFlagsCriterionEquals() {
1056 new EqualsTester()
1057 .addEqualityGroup(matchIpv6ExthdrFlags1,
1058 sameAsMatchIpv6ExthdrFlags1)
1059 .addEqualityGroup(matchIpv6ExthdrFlags2)
1060 .testEquals();
1061 }
1062
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001063 @Test
Sho SHIMIZUefc2e282015-05-04 15:26:23 -07001064 public void testIndexedLambdaCriterionEquals() {
1065 new EqualsTester()
1066 .addEqualityGroup(matchIndexedLambda1, sameAsMatchIndexedLambda1)
1067 .addEqualityGroup(matchIndexedLambda2)
1068 .testEquals();
1069 }
1070
1071 @Test
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001072 public void testOchSignalCriterionEquals() {
1073 new EqualsTester()
1074 .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1)
1075 .addEqualityGroup(matchOchSignal2)
1076 .testEquals();
1077 }
1078
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -07001079 /**
1080 * Test the equals() method of the OchSignalTypeCriterion class.
1081 */
1082 @Test
1083 public void testOchSignalTypeCriterionEquals() {
1084 new EqualsTester()
1085 .addEqualityGroup(matchOchSignalType1, sameAsMatchOchSignalType1)
1086 .addEqualityGroup(matchOchSignalType2)
1087 .testEquals();
1088 }
Yafit Hadar52d81552015-10-07 12:26:52 +03001089
1090 /**
1091 * Test the OduSignalId method.
1092 */
1093 @Test
1094 public void testMatchOduSignalIdMethod() {
1095 OduSignalId odu = oduSignalId(1, 80, new byte[]{2, 1, 1, 3, 1, 1, 3, 1, 1, 3});
1096
1097 Criterion matchoduSignalId = Criteria.matchOduSignalId(odu);
1098 OduSignalIdCriterion oduSignalIdCriterion =
1099 checkAndConvert(matchoduSignalId,
1100 Criterion.Type.ODU_SIGID,
1101 OduSignalIdCriterion.class);
1102 assertThat(oduSignalIdCriterion.oduSignalId(), is(equalTo(odu)));
1103 }
1104
1105 /**
1106 * Test the equals() method of the OduSignalIdCriterion class.
1107 */
1108 @Test
1109 public void testOduSignalIdCriterionEquals() {
1110 new EqualsTester()
1111 .addEqualityGroup(matchOduSignalId1, sameAsMatchOduSignalId1)
1112 .addEqualityGroup(matchOduSignalId2)
1113 .testEquals();
1114 }
1115
1116 // OduSignalTypeCriterion class
1117
1118 /**
1119 * Test the OduSignalType method.
1120 */
1121 @Test
1122 public void testMatchOduSignalTypeMethod() {
1123 OduSignalType oduSigType = OduSignalType.ODU2;
1124 Criterion matchoduSignalType = Criteria.matchOduSignalType(oduSigType);
1125 OduSignalTypeCriterion oduSignalTypeCriterion =
1126 checkAndConvert(matchoduSignalType,
1127 Criterion.Type.ODU_SIGTYPE,
1128 OduSignalTypeCriterion.class);
1129 assertThat(oduSignalTypeCriterion.signalType(), is(equalTo(oduSigType)));
1130 }
1131
1132 /**
1133 * Test the equals() method of the OduSignalTypeCriterion class.
1134 */
1135 @Test
1136 public void testOduSignalTypeCriterionEquals() {
1137 new EqualsTester()
1138 .addEqualityGroup(matchOduSignalType1, sameAsMatchOduSignalType1)
1139 .addEqualityGroup(matchOduSignalType2)
1140 .testEquals();
1141 }
Ray Milkey33d90232014-11-04 10:49:00 -08001142}