blob: 56a6ff63aa96ddd45471e16a3d33c17e6f1f08ac [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;
Jian Li79bdf3c2015-11-30 14:54:54 -080045
Ray Milkey33d90232014-11-04 10:49:00 -080046/**
47 * Unit tests for the Criteria class and its subclasses.
48 */
49public class CriteriaTest {
50
51 final PortNumber port1 = portNumber(1);
52 final PortNumber port2 = portNumber(2);
53
54 Criterion matchInPort1 = Criteria.matchInPort(port1);
55 Criterion sameAsMatchInPort1 = Criteria.matchInPort(port1);
56 Criterion matchInPort2 = Criteria.matchInPort(port2);
57
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080058 Criterion matchInPhyPort1 = Criteria.matchInPhyPort(port1);
59 Criterion sameAsMatchInPhyPort1 = Criteria.matchInPhyPort(port1);
60 Criterion matchInPhyPort2 = Criteria.matchInPhyPort(port2);
61
62 long metadata1 = 1;
63 long metadata2 = 2;
64 Criterion matchMetadata1 = Criteria.matchMetadata(metadata1);
65 Criterion sameAsMatchMetadata1 = Criteria.matchMetadata(metadata1);
66 Criterion matchMetadata2 = Criteria.matchMetadata(metadata2);
67
Ray Milkey33d90232014-11-04 10:49:00 -080068 private static final String MAC1 = "00:00:00:00:00:01";
69 private static final String MAC2 = "00:00:00:00:00:02";
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080070 private MacAddress mac1 = MacAddress.valueOf(MAC1);
71 private MacAddress mac2 = MacAddress.valueOf(MAC2);
Ray Milkey33d90232014-11-04 10:49:00 -080072 Criterion matchEth1 = Criteria.matchEthSrc(mac1);
73 Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1);
74 Criterion matchEth2 = Criteria.matchEthDst(mac2);
75
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080076 int ethType1 = 1;
77 int ethType2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -080078 Criterion matchEthType1 = Criteria.matchEthType(ethType1);
79 Criterion sameAsMatchEthType1 = Criteria.matchEthType(ethType1);
80 Criterion matchEthType2 = Criteria.matchEthType(ethType2);
81
82 short vlan1 = 1;
83 short vlan2 = 2;
84 VlanId vlanId1 = VlanId.vlanId(vlan1);
85 VlanId vlanId2 = VlanId.vlanId(vlan2);
86 Criterion matchVlanId1 = Criteria.matchVlanId(vlanId1);
87 Criterion sameAsMatchVlanId1 = Criteria.matchVlanId(vlanId1);
88 Criterion matchVlanId2 = Criteria.matchVlanId(vlanId2);
89
90 byte vlanPcp1 = 1;
91 byte vlanPcp2 = 2;
92 Criterion matchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
93 Criterion sameAsMatchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
94 Criterion matchVlanPcp2 = Criteria.matchVlanPcp(vlanPcp2);
95
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080096 byte ipDscp1 = 1;
97 byte ipDscp2 = 2;
98 Criterion matchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
99 Criterion sameAsMatchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
100 Criterion matchIpDscp2 = Criteria.matchIPDscp(ipDscp2);
101
102 byte ipEcn1 = 1;
103 byte ipEcn2 = 2;
104 Criterion matchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
105 Criterion sameAsMatchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
106 Criterion matchIpEcn2 = Criteria.matchIPEcn(ipEcn2);
107
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800108 short protocol1 = 1;
109 short protocol2 = 2;
Ray Milkey33d90232014-11-04 10:49:00 -0800110 Criterion matchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
111 Criterion sameAsMatchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
112 Criterion matchIpProtocol2 = Criteria.matchIPProtocol(protocol2);
113
114 private static final String IP1 = "1.2.3.4/24";
115 private static final String IP2 = "5.6.7.8/24";
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800116 private static final String IPV61 = "fe80::1/64";
117 private static final String IPV62 = "fc80::2/64";
Ray Milkey33d90232014-11-04 10:49:00 -0800118 private IpPrefix ip1 = IpPrefix.valueOf(IP1);
119 private IpPrefix ip2 = IpPrefix.valueOf(IP2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800120 private IpPrefix ipv61 = IpPrefix.valueOf(IPV61);
121 private IpPrefix ipv62 = IpPrefix.valueOf(IPV62);
Ray Milkey33d90232014-11-04 10:49:00 -0800122 Criterion matchIp1 = Criteria.matchIPSrc(ip1);
123 Criterion sameAsMatchIp1 = Criteria.matchIPSrc(ip1);
124 Criterion matchIp2 = Criteria.matchIPSrc(ip2);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800125 Criterion matchIpv61 = Criteria.matchIPSrc(ipv61);
126 Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
127 Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
Ray Milkey33d90232014-11-04 10:49:00 -0800128
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700129 private TpPort tpPort1 = TpPort.tpPort(1);
130 private TpPort tpPort2 = TpPort.tpPort(2);
131 Criterion matchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
132 Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
133 Criterion matchTcpPort2 = Criteria.matchTcpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800134
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700135 Criterion matchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
136 Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
137 Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800138
Jian Li79bdf3c2015-11-30 14:54:54 -0800139
140 int tcpFlags1 =
141 Criterion.TCPFlags.NS.getValue() |
142 Criterion.TCPFlags.CWR.getValue() |
143 Criterion.TCPFlags.ECE.getValue() |
144 Criterion.TCPFlags.URG.getValue() |
145 Criterion.TCPFlags.ACK.getValue() |
146 Criterion.TCPFlags.PSH.getValue() |
147 Criterion.TCPFlags.RST.getValue() |
148 Criterion.TCPFlags.SYN.getValue();
149
150 int tcpFlags2 = tcpFlags1 |
151 Criterion.TCPFlags.FIN.getValue();
152
153 Criterion matchTcpFlags1 = Criteria.matchTcpFlags(tcpFlags1);
154 Criterion sameAsmatchTcpFlags1 = Criteria.matchTcpFlags(tcpFlags1);
155 Criterion matchTcpFlags2 = Criteria.matchTcpFlags(tcpFlags2);
156
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700157 Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
158 Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
159 Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800160
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800161 short icmpType1 = 1;
162 short icmpType2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800163 Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1);
164 Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1);
165 Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2);
166
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800167 short icmpCode1 = 1;
168 short icmpCode2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800169 Criterion matchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
170 Criterion sameAsMatchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
171 Criterion matchIcmpCode2 = Criteria.matchIcmpCode(icmpCode2);
172
173 int flowLabel1 = 1;
174 int flowLabel2 = 2;
175 Criterion matchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
176 Criterion sameAsMatchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
177 Criterion matchFlowLabel2 = Criteria.matchIPv6FlowLabel(flowLabel2);
178
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800179 short icmpv6Type1 = 1;
180 short icmpv6Type2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800181 Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
182 Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
183 Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2);
184
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800185 short icmpv6Code1 = 1;
186 short icmpv6Code2 = 2;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800187 Criterion matchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
188 Criterion sameAsMatchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
189 Criterion matchIcmpv6Code2 = Criteria.matchIcmpv6Code(icmpv6Code2);
190
191 private static final String IPV6_ADDR1 = "fe80::1";
192 private static final String IPV6_ADDR2 = "fe80::2";
193 private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
194 private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
195 Criterion matchIpv6TargetAddr1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800196 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800197 Criterion sameAsMatchIpv6TargetAddr1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800198 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800199 Criterion matchIpv6TargetAddr2 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800200 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800201
202 private static final String LL_MAC1 = "00:00:00:00:00:01";
203 private static final String LL_MAC2 = "00:00:00:00:00:02";
204 private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
205 private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
206 Criterion matchSrcLlAddr1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800207 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800208 Criterion sameAsMatchSrcLlAddr1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800209 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800210 Criterion matchSrcLlAddr2 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800211 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800212 Criterion matchTargetLlAddr1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800213 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800214 Criterion sameAsMatchTargetLlAddr1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800215 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800216 Criterion matchTargetLlAddr2 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800217 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800218
Michele Santuari4b6019e2014-12-19 11:31:45 +0100219 MplsLabel mpls1 = MplsLabel.mplsLabel(1);
220 MplsLabel mpls2 = MplsLabel.mplsLabel(2);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800221 Criterion matchMpls1 = Criteria.matchMplsLabel(mpls1);
222 Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1);
223 Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2);
224
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700225 long tunnelId1 = 1;
226 long tunnelId2 = 2;
227 Criterion matchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
228 Criterion sameAsMatchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
229 Criterion matchTunnelId2 = Criteria.matchTunnelId(tunnelId2);
230
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800231 int ipv6ExthdrFlags1 =
232 Criterion.IPv6ExthdrFlags.NONEXT.getValue() |
233 Criterion.IPv6ExthdrFlags.ESP.getValue() |
234 Criterion.IPv6ExthdrFlags.AUTH.getValue() |
235 Criterion.IPv6ExthdrFlags.DEST.getValue() |
236 Criterion.IPv6ExthdrFlags.FRAG.getValue() |
237 Criterion.IPv6ExthdrFlags.ROUTER.getValue() |
238 Criterion.IPv6ExthdrFlags.HOP.getValue() |
239 Criterion.IPv6ExthdrFlags.UNREP.getValue();
240 int ipv6ExthdrFlags2 = ipv6ExthdrFlags1 |
Jian Li79bdf3c2015-11-30 14:54:54 -0800241 Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800242 Criterion matchIpv6ExthdrFlags1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800243 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800244 Criterion sameAsMatchIpv6ExthdrFlags1 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800245 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800246 Criterion matchIpv6ExthdrFlags2 =
Jian Li79bdf3c2015-11-30 14:54:54 -0800247 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800248
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700249 Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
250 Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -0700251 Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID);
252
Sho SHIMIZUefc2e282015-05-04 15:26:23 -0700253 Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
254 Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
255 Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2));
256
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -0700257 Criterion matchOchSignal1 =
258 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
259 Criterion sameAsMatchOchSignal1 =
260 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
261 Criterion matchOchSignal2 =
262 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
263
Jian Li79bdf3c2015-11-30 14:54:54 -0800264 final OduSignalId odu1 = oduSignalId(1, 80, new byte[]{1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
265 final OduSignalId odu2 = oduSignalId(3, 8, new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0});
Yafit Hadar52d81552015-10-07 12:26:52 +0300266 Criterion matchOduSignalId1 = Criteria.matchOduSignalId(odu1);
267 Criterion sameAsMatchOduSignalId1 = Criteria.matchOduSignalId(odu1);
268 Criterion matchOduSignalId2 = Criteria.matchOduSignalId(odu2);
269
270 final OduSignalType oduSigType1 = OduSignalType.ODU2;
271 final OduSignalType oduSigType2 = OduSignalType.ODU4;
272 Criterion matchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1);
273 Criterion sameAsMatchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1);
274 Criterion matchOduSignalType2 = Criteria.matchOduSignalType(oduSigType2);
275
Ray Milkey33d90232014-11-04 10:49:00 -0800276 /**
277 * Checks that a Criterion object has the proper type, and then converts
278 * it to the proper type.
279 *
280 * @param criterion Criterion object to convert
Jian Li79bdf3c2015-11-30 14:54:54 -0800281 * @param type Enumerated type value for the Criterion class
282 * @param clazz Desired Criterion class
283 * @param <T> The type the caller wants returned
Ray Milkey33d90232014-11-04 10:49:00 -0800284 * @return converted object
285 */
286 @SuppressWarnings("unchecked")
287 private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) {
288 assertThat(criterion, is(notNullValue()));
289 assertThat(criterion.type(), is(equalTo(type)));
Ray Milkey78081052014-11-05 10:38:12 -0800290 assertThat(criterion, instanceOf(clazz));
Ray Milkey33d90232014-11-04 10:49:00 -0800291 return (T) criterion;
292 }
293
294 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800295 * Check that the Criteria class is a valid utility class.
296 */
297 @Test
298 public void testCriteriaUtility() {
299 assertThatClassIsUtility(Criteria.class);
300 }
301
302 /**
303 * Check that the Criteria implementations are immutable.
304 */
305 @Test
306 public void testCriteriaImmutability() {
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700307 assertThatClassIsImmutable(PortCriterion.class);
308 assertThatClassIsImmutable(MetadataCriterion.class);
309 assertThatClassIsImmutable(EthCriterion.class);
310 assertThatClassIsImmutable(EthTypeCriterion.class);
311 assertThatClassIsImmutable(VlanIdCriterion.class);
312 assertThatClassIsImmutable(VlanPcpCriterion.class);
313 assertThatClassIsImmutable(IPDscpCriterion.class);
314 assertThatClassIsImmutable(IPEcnCriterion.class);
315 assertThatClassIsImmutable(IPProtocolCriterion.class);
316 assertThatClassIsImmutable(IPCriterion.class);
317 assertThatClassIsImmutable(TcpPortCriterion.class);
318 assertThatClassIsImmutable(UdpPortCriterion.class);
Jian Li79bdf3c2015-11-30 14:54:54 -0800319 assertThatClassIsImmutable(TcpFlagsCriterion.class);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700320 assertThatClassIsImmutable(SctpPortCriterion.class);
321 assertThatClassIsImmutable(IcmpTypeCriterion.class);
322 assertThatClassIsImmutable(IcmpCodeCriterion.class);
323 assertThatClassIsImmutable(IPv6FlowLabelCriterion.class);
324 assertThatClassIsImmutable(Icmpv6TypeCriterion.class);
325 assertThatClassIsImmutable(Icmpv6CodeCriterion.class);
326 assertThatClassIsImmutable(IPv6NDTargetAddressCriterion.class);
327 assertThatClassIsImmutable(IPv6NDLinkLayerAddressCriterion.class);
328 assertThatClassIsImmutable(MplsCriterion.class);
329 assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class);
330 assertThatClassIsImmutable(LambdaCriterion.class);
Yafit Hadar52d81552015-10-07 12:26:52 +0300331 assertThatClassIsImmutable(OduSignalIdCriterion.class);
332 assertThatClassIsImmutable(OduSignalTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800333 }
334
335 // PortCriterion class
336
337 /**
338 * Test the matchInPort method.
339 */
340 @Test
341 public void testMatchInPortMethod() {
342 PortNumber p1 = portNumber(1);
343 Criterion matchInPort = Criteria.matchInPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700344 PortCriterion portCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800345 checkAndConvert(matchInPort,
346 Criterion.Type.IN_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700347 PortCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800348 assertThat(portCriterion.port(), is(equalTo(p1)));
349 }
350
351 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800352 * Test the matchInPhyPort method.
353 */
354 @Test
355 public void testMatchInPhyPortMethod() {
356 PortNumber p1 = portNumber(1);
357 Criterion matchInPhyPort = Criteria.matchInPhyPort(p1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700358 PortCriterion portCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800359 checkAndConvert(matchInPhyPort,
360 Criterion.Type.IN_PHY_PORT,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700361 PortCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800362 assertThat(portCriterion.port(), is(equalTo(p1)));
363 }
364
365 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800366 * Test the equals() method of the PortCriterion class.
367 */
368 @Test
369 public void testPortCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800370 new EqualsTester()
371 .addEqualityGroup(matchInPort1, sameAsMatchInPort1)
372 .addEqualityGroup(matchInPort2)
373 .testEquals();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800374
375 new EqualsTester()
376 .addEqualityGroup(matchInPhyPort1, sameAsMatchInPhyPort1)
377 .addEqualityGroup(matchInPhyPort2)
378 .testEquals();
379 }
380
381 // MetadataCriterion class
382
383 /**
384 * Test the matchMetadata method.
385 */
386 @Test
387 public void testMatchMetadataMethod() {
388 Long metadata = 12L;
389 Criterion matchMetadata = Criteria.matchMetadata(metadata);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700390 MetadataCriterion metadataCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800391 checkAndConvert(matchMetadata,
392 Criterion.Type.METADATA,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700393 MetadataCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800394 assertThat(metadataCriterion.metadata(), is(equalTo(metadata)));
395 }
396
397 /**
398 * Test the equals() method of the MetadataCriterion class.
399 */
400 @Test
401 public void testMetadataCriterionEquals() {
402 new EqualsTester()
403 .addEqualityGroup(matchMetadata1, sameAsMatchMetadata1)
404 .addEqualityGroup(matchMetadata2)
405 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800406 }
407
408 // EthCriterion class
409
410 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800411 * Test the matchEthDst method.
412 */
413 @Test
414 public void testMatchEthDstMethod() {
415 Criterion matchEthDst = Criteria.matchEthDst(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700416 EthCriterion ethCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800417 checkAndConvert(matchEthDst,
Jian Li79bdf3c2015-11-30 14:54:54 -0800418 Criterion.Type.ETH_DST,
419 EthCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800420 assertThat(ethCriterion.mac(), is(equalTo(mac1)));
421 }
422
423 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800424 * Test the matchEthSrc method.
425 */
426 @Test
427 public void testMatchEthSrcMethod() {
428 Criterion matchEthSrc = Criteria.matchEthSrc(mac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700429 EthCriterion ethCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800430 checkAndConvert(matchEthSrc,
431 Criterion.Type.ETH_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700432 EthCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800433 assertThat(ethCriterion.mac(), is(mac1));
434 }
435
436 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800437 * Test the equals() method of the EthCriterion class.
438 */
439 @Test
440 public void testEthCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800441 new EqualsTester()
442 .addEqualityGroup(matchEth1, sameAsMatchEth1)
443 .addEqualityGroup(matchEth2)
444 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800445 }
446
Ray Milkey33d90232014-11-04 10:49:00 -0800447 // EthTypeCriterion class
448
449 /**
450 * Test the matchEthType method.
451 */
452 @Test
453 public void testMatchEthTypeMethod() {
alshabibcaf1ca22015-06-25 15:18:16 -0700454 EthType ethType = new EthType(12);
455 Criterion matchEthType = Criteria.matchEthType(new EthType(12));
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700456 EthTypeCriterion ethTypeCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800457 checkAndConvert(matchEthType,
458 Criterion.Type.ETH_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700459 EthTypeCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800460 assertThat(ethTypeCriterion.ethType(), is(equalTo(ethType)));
461 }
462
463 /**
464 * Test the equals() method of the EthTypeCriterion class.
465 */
466 @Test
467 public void testEthTypeCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800468 new EqualsTester()
469 .addEqualityGroup(matchEthType1, sameAsMatchEthType1)
470 .addEqualityGroup(matchEthType2)
471 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800472 }
473
Ray Milkey33d90232014-11-04 10:49:00 -0800474 // VlanIdCriterion class
475
476 /**
477 * Test the matchVlanId method.
478 */
479 @Test
480 public void testMatchVlanIdMethod() {
481 Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700482 VlanIdCriterion vlanIdCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800483 checkAndConvert(matchVlanId,
Jian Li79bdf3c2015-11-30 14:54:54 -0800484 Criterion.Type.VLAN_VID,
485 VlanIdCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800486 assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
487 }
488
489 /**
490 * Test the equals() method of the VlanIdCriterion class.
491 */
492 @Test
493 public void testVlanIdCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800494 new EqualsTester()
495 .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1)
496 .addEqualityGroup(matchVlanId2)
497 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800498 }
499
500 // VlanPcpCriterion class
501
502 /**
503 * Test the matchVlanPcp method.
504 */
505 @Test
506 public void testMatchVlanPcpMethod() {
507 Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700508 VlanPcpCriterion vlanPcpCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800509 checkAndConvert(matchVlanPcp,
Jian Li79bdf3c2015-11-30 14:54:54 -0800510 Criterion.Type.VLAN_PCP,
511 VlanPcpCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800512 assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
513 }
514
515 /**
516 * Test the equals() method of the VlanPcpCriterion class.
517 */
518 @Test
519 public void testVlanPcpCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800520 new EqualsTester()
521 .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1)
522 .addEqualityGroup(matchVlanPcp2)
523 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800524 }
525
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800526 // IPDscpCriterion class
527
528 /**
529 * Test the matchIPDscp method.
530 */
531 @Test
532 public void testMatchIPDscpMethod() {
533 Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700534 IPDscpCriterion ipDscpCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800535 checkAndConvert(matchIPDscp,
Jian Li79bdf3c2015-11-30 14:54:54 -0800536 Criterion.Type.IP_DSCP,
537 IPDscpCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800538 assertThat(ipDscpCriterion.ipDscp(), is(equalTo(ipDscp1)));
539 }
540
541 /**
542 * Test the equals() method of the IPDscpCriterion class.
543 */
544 @Test
545 public void testIPDscpCriterionEquals() {
546 new EqualsTester()
547 .addEqualityGroup(matchIpDscp1, sameAsMatchIpDscp1)
548 .addEqualityGroup(matchIpDscp2)
549 .testEquals();
550 }
551
552 // IPEcnCriterion class
553
554 /**
555 * Test the matchIPEcn method.
556 */
557 @Test
558 public void testMatchIPEcnMethod() {
559 Criterion matchIPEcn = Criteria.matchIPEcn(ipEcn1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700560 IPEcnCriterion ipEcnCriterion =
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800561 checkAndConvert(matchIPEcn,
Jian Li79bdf3c2015-11-30 14:54:54 -0800562 Criterion.Type.IP_ECN,
563 IPEcnCriterion.class);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800564 assertThat(ipEcnCriterion.ipEcn(), is(equalTo(ipEcn1)));
565 }
566
567 /**
568 * Test the equals() method of the IPEcnCriterion class.
569 */
570 @Test
571 public void testIPEcnCriterionEquals() {
572 new EqualsTester()
573 .addEqualityGroup(matchIpEcn1, sameAsMatchIpEcn1)
574 .addEqualityGroup(matchIpEcn2)
575 .testEquals();
576 }
577
Ray Milkey33d90232014-11-04 10:49:00 -0800578 // IpProtocolCriterion class
579
580 /**
581 * Test the matchIpProtocol method.
582 */
583 @Test
584 public void testMatchIpProtocolMethod() {
585 Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700586 IPProtocolCriterion ipProtocolCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800587 checkAndConvert(matchIPProtocol,
Jian Li79bdf3c2015-11-30 14:54:54 -0800588 Criterion.Type.IP_PROTO,
589 IPProtocolCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800590 assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
591 }
592
593 /**
594 * Test the equals() method of the IpProtocolCriterion class.
595 */
596 @Test
597 public void testIpProtocolCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800598 new EqualsTester()
599 .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1)
600 .addEqualityGroup(matchIpProtocol2)
601 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800602 }
603
604 // IPCriterion class
605
606 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800607 * Test the matchIPSrc method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800608 */
609 @Test
610 public void testMatchIPSrcMethod() {
611 Criterion matchIpSrc = Criteria.matchIPSrc(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700612 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800613 checkAndConvert(matchIpSrc,
614 Criterion.Type.IPV4_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700615 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800616 assertThat(ipCriterion.ip(), is(ip1));
617 }
618
619 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800620 * Test the matchIPDst method: IPv4.
Ray Milkey33d90232014-11-04 10:49:00 -0800621 */
622 @Test
623 public void testMatchIPDstMethod() {
624 Criterion matchIPDst = Criteria.matchIPDst(ip1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700625 IPCriterion ipCriterion =
Ray Milkey33d90232014-11-04 10:49:00 -0800626 checkAndConvert(matchIPDst,
Jian Li79bdf3c2015-11-30 14:54:54 -0800627 Criterion.Type.IPV4_DST,
628 IPCriterion.class);
Ray Milkey33d90232014-11-04 10:49:00 -0800629 assertThat(ipCriterion.ip(), is(equalTo(ip1)));
630 }
631
632 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800633 * Test the matchIPSrc method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800634 */
635 @Test
636 public void testMatchIPv6SrcMethod() {
637 Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700638 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800639 checkAndConvert(matchIpv6Src,
Jian Li79bdf3c2015-11-30 14:54:54 -0800640 Criterion.Type.IPV6_SRC,
641 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800642 assertThat(ipCriterion.ip(), is(ipv61));
643 }
644
645 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800646 * Test the matchIPDst method: IPv6.
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800647 */
648 @Test
649 public void testMatchIPv6DstMethod() {
650 Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700651 IPCriterion ipCriterion =
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800652 checkAndConvert(matchIPv6Dst,
Jian Li79bdf3c2015-11-30 14:54:54 -0800653 Criterion.Type.IPV6_DST,
654 IPCriterion.class);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800655 assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
656 }
657
658 /**
Ray Milkey33d90232014-11-04 10:49:00 -0800659 * Test the equals() method of the IpCriterion class.
660 */
661 @Test
662 public void testIPCriterionEquals() {
Ray Milkeyfff20b52014-11-06 14:45:10 -0800663 new EqualsTester()
664 .addEqualityGroup(matchIp1, sameAsMatchIp1)
665 .addEqualityGroup(matchIp2)
666 .testEquals();
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800667
668 new EqualsTester()
669 .addEqualityGroup(matchIpv61, sameAsMatchIpv61)
670 .addEqualityGroup(matchIpv62)
671 .testEquals();
Ray Milkey33d90232014-11-04 10:49:00 -0800672 }
673
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800674 // TcpPortCriterion class
675
676 /**
677 * Test the matchTcpSrc method.
678 */
679 @Test
680 public void testMatchTcpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700681 Criterion matchTcpSrc = Criteria.matchTcpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700682 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800683 checkAndConvert(matchTcpSrc,
684 Criterion.Type.TCP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700685 TcpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700686 assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800687 }
688
689 /**
690 * Test the matchTcpDst method.
691 */
692 @Test
693 public void testMatchTcpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700694 Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700695 TcpPortCriterion tcpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800696 checkAndConvert(matchTcpDst,
Jian Li79bdf3c2015-11-30 14:54:54 -0800697 Criterion.Type.TCP_DST,
698 TcpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700699 assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800700 }
701
702 /**
703 * Test the equals() method of the TcpPortCriterion class.
704 */
705 @Test
706 public void testTcpPortCriterionEquals() {
707 new EqualsTester()
708 .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
709 .addEqualityGroup(matchTcpPort2)
710 .testEquals();
711 }
712
713 // UdpPortCriterion class
714
715 /**
716 * Test the matchUdpSrc method.
717 */
718 @Test
719 public void testMatchUdpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700720 Criterion matchUdpSrc = Criteria.matchUdpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700721 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800722 checkAndConvert(matchUdpSrc,
723 Criterion.Type.UDP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700724 UdpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700725 assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800726 }
727
728 /**
729 * Test the matchUdpDst method.
730 */
731 @Test
732 public void testMatchUdpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700733 Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700734 UdpPortCriterion udpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800735 checkAndConvert(matchUdpDst,
Jian Li79bdf3c2015-11-30 14:54:54 -0800736 Criterion.Type.UDP_DST,
737 UdpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700738 assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800739 }
740
741 /**
742 * Test the equals() method of the UdpPortCriterion class.
743 */
744 @Test
745 public void testUdpPortCriterionEquals() {
746 new EqualsTester()
747 .addEqualityGroup(matchUdpPort1, sameAsMatchUdpPort1)
748 .addEqualityGroup(matchUdpPort2)
749 .testEquals();
750 }
751
Jian Li79bdf3c2015-11-30 14:54:54 -0800752 // TcpFlagsCriterion class
753
754 /**
755 * Test the equals() method of the TcpFlagsCriterion class.
756 */
757 @Test
758 public void testTcpFlagsCriterionEquals() {
759 new EqualsTester()
760 .addEqualityGroup(matchTcpFlags1, sameAsmatchTcpFlags1)
761 .addEqualityGroup(matchTcpFlags2)
762 .testEquals();
763 }
764
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800765 // SctpPortCriterion class
766
767 /**
768 * Test the matchSctpSrc method.
769 */
770 @Test
771 public void testMatchSctpSrcMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700772 Criterion matchSctpSrc = Criteria.matchSctpSrc(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700773 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800774 checkAndConvert(matchSctpSrc,
775 Criterion.Type.SCTP_SRC,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700776 SctpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700777 assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800778 }
779
780 /**
781 * Test the matchSctpDst method.
782 */
783 @Test
784 public void testMatchSctpDstMethod() {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700785 Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700786 SctpPortCriterion sctpPortCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800787 checkAndConvert(matchSctpDst,
Jian Li79bdf3c2015-11-30 14:54:54 -0800788 Criterion.Type.SCTP_DST,
789 SctpPortCriterion.class);
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700790 assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800791 }
792
793 /**
794 * Test the equals() method of the SctpPortCriterion class.
795 */
796 @Test
797 public void testSctpPortCriterionEquals() {
798 new EqualsTester()
799 .addEqualityGroup(matchSctpPort1, sameAsMatchSctpPort1)
800 .addEqualityGroup(matchSctpPort2)
801 .testEquals();
802 }
803
804 // IcmpTypeCriterion class
805
806 /**
807 * Test the matchIcmpType method.
808 */
809 @Test
810 public void testMatchIcmpTypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800811 short icmpType = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800812 Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700813 IcmpTypeCriterion icmpTypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800814 checkAndConvert(matchIcmpType,
815 Criterion.Type.ICMPV4_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700816 IcmpTypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800817 assertThat(icmpTypeCriterion.icmpType(), is(equalTo(icmpType)));
818 }
819
820 /**
821 * Test the equals() method of the IcmpTypeCriterion class.
822 */
823 @Test
824 public void testIcmpTypeCriterionEquals() {
825 new EqualsTester()
826 .addEqualityGroup(matchIcmpType1, sameAsMatchIcmpType1)
827 .addEqualityGroup(matchIcmpType2)
828 .testEquals();
829 }
830
831 // IcmpCodeCriterion class
832
833 /**
834 * Test the matchIcmpCode method.
835 */
836 @Test
837 public void testMatchIcmpCodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800838 short icmpCode = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800839 Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700840 IcmpCodeCriterion icmpCodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800841 checkAndConvert(matchIcmpCode,
842 Criterion.Type.ICMPV4_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700843 IcmpCodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800844 assertThat(icmpCodeCriterion.icmpCode(), is(equalTo(icmpCode)));
845 }
846
847 /**
848 * Test the equals() method of the IcmpCodeCriterion class.
849 */
850 @Test
851 public void testIcmpCodeCriterionEquals() {
852 new EqualsTester()
853 .addEqualityGroup(matchIcmpCode1, sameAsMatchIcmpCode1)
854 .addEqualityGroup(matchIcmpCode2)
855 .testEquals();
856 }
857
858 // IPv6FlowLabelCriterion class
859
860 /**
861 * Test the matchIPv6FlowLabel method.
862 */
863 @Test
864 public void testMatchIPv6FlowLabelMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800865 int flowLabel = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800866 Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700867 IPv6FlowLabelCriterion flowLabelCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800868 checkAndConvert(matchFlowLabel,
869 Criterion.Type.IPV6_FLABEL,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700870 IPv6FlowLabelCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800871 assertThat(flowLabelCriterion.flowLabel(), is(equalTo(flowLabel)));
872 }
873
874 /**
875 * Test the equals() method of the IPv6FlowLabelCriterion class.
876 */
877 @Test
878 public void testIPv6FlowLabelCriterionEquals() {
879 new EqualsTester()
880 .addEqualityGroup(matchFlowLabel1, sameAsMatchFlowLabel1)
881 .addEqualityGroup(matchFlowLabel2)
882 .testEquals();
883 }
884
885 // Icmpv6TypeCriterion class
886
887 /**
888 * Test the matchIcmpv6Type method.
889 */
890 @Test
891 public void testMatchIcmpv6TypeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800892 short icmpv6Type = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800893 Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700894 Icmpv6TypeCriterion icmpv6TypeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800895 checkAndConvert(matchIcmpv6Type,
896 Criterion.Type.ICMPV6_TYPE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700897 Icmpv6TypeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800898 assertThat(icmpv6TypeCriterion.icmpv6Type(), is(equalTo(icmpv6Type)));
899 }
900
901 /**
902 * Test the equals() method of the Icmpv6TypeCriterion class.
903 */
904 @Test
905 public void testIcmpv6TypeCriterionEquals() {
906 new EqualsTester()
907 .addEqualityGroup(matchIcmpv6Type1, sameAsMatchIcmpv6Type1)
908 .addEqualityGroup(matchIcmpv6Type2)
909 .testEquals();
910 }
911
912 // Icmpv6CodeCriterion class
913
914 /**
915 * Test the matchIcmpv6Code method.
916 */
917 @Test
918 public void testMatchIcmpv6CodeMethod() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800919 short icmpv6Code = 12;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800920 Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700921 Icmpv6CodeCriterion icmpv6CodeCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800922 checkAndConvert(matchIcmpv6Code,
923 Criterion.Type.ICMPV6_CODE,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700924 Icmpv6CodeCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800925 assertThat(icmpv6CodeCriterion.icmpv6Code(), is(equalTo(icmpv6Code)));
926 }
927
928 /**
929 * Test the equals() method of the Icmpv6CodeCriterion class.
930 */
931 @Test
932 public void testIcmpv6CodeCriterionEquals() {
933 new EqualsTester()
934 .addEqualityGroup(matchIcmpv6Code1, sameAsMatchIcmpv6Code1)
935 .addEqualityGroup(matchIcmpv6Code2)
936 .testEquals();
937 }
938
939 // IPv6NDTargetAddressCriterion class
940
941 /**
942 * Test the matchIPv6NDTargetAddress method.
943 */
944 @Test
945 public void testMatchIPv6NDTargetAddressMethod() {
946 Criterion matchTargetAddress =
Jian Li79bdf3c2015-11-30 14:54:54 -0800947 Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700948 IPv6NDTargetAddressCriterion targetAddressCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800949 checkAndConvert(matchTargetAddress,
950 Criterion.Type.IPV6_ND_TARGET,
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700951 IPv6NDTargetAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800952 assertThat(targetAddressCriterion.targetAddress(),
953 is(ip6TargetAddress1));
954 }
955
956 /**
957 * Test the equals() method of the IPv6NDTargetAddressCriterion class.
958 */
959 @Test
960 public void testIPv6NDTargetAddressCriterionEquals() {
961 new EqualsTester()
962 .addEqualityGroup(matchIpv6TargetAddr1,
963 sameAsMatchIpv6TargetAddr1)
964 .addEqualityGroup(matchIpv6TargetAddr2)
965 .testEquals();
966 }
967
968 // IPv6NDLinkLayerAddressCriterion class
969
970 /**
971 * Test the matchIPv6NDSourceLinkLayerAddress method.
972 */
973 @Test
974 public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
975 Criterion matchSrcLlAddr =
Jian Li79bdf3c2015-11-30 14:54:54 -0800976 Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700977 IPv6NDLinkLayerAddressCriterion srcLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800978 checkAndConvert(matchSrcLlAddr,
Jian Li79bdf3c2015-11-30 14:54:54 -0800979 Criterion.Type.IPV6_ND_SLL,
980 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800981 assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
982 }
983
984 /**
985 * Test the matchIPv6NDTargetLinkLayerAddress method.
986 */
987 @Test
988 public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
989 Criterion matchTargetLlAddr =
Jian Li79bdf3c2015-11-30 14:54:54 -0800990 Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -0700991 IPv6NDLinkLayerAddressCriterion targetLlCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800992 checkAndConvert(matchTargetLlAddr,
Jian Li79bdf3c2015-11-30 14:54:54 -0800993 Criterion.Type.IPV6_ND_TLL,
994 IPv6NDLinkLayerAddressCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800995 assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
996 }
997
998 /**
999 * Test the equals() method of the IPv6NDLinkLayerAddressCriterion class.
1000 */
1001 @Test
1002 public void testIPv6NDLinkLayerAddressCriterionEquals() {
1003 new EqualsTester()
1004 .addEqualityGroup(matchSrcLlAddr1, sameAsMatchSrcLlAddr1)
1005 .addEqualityGroup(matchSrcLlAddr2)
1006 .testEquals();
1007
1008 new EqualsTester()
1009 .addEqualityGroup(matchTargetLlAddr1, sameAsMatchTargetLlAddr1)
1010 .addEqualityGroup(matchTargetLlAddr2)
1011 .testEquals();
1012 }
1013
1014 // MplsCriterion class
1015
1016 /**
1017 * Test the matchMplsLabel method.
1018 */
1019 @Test
1020 public void testMatchMplsLabelMethod() {
1021 Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001022 MplsCriterion mplsCriterion =
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001023 checkAndConvert(matchMplsLabel,
Jian Li79bdf3c2015-11-30 14:54:54 -08001024 Criterion.Type.MPLS_LABEL,
1025 MplsCriterion.class);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001026 assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
1027 }
1028
1029 /**
1030 * Test the equals() method of the MplsCriterion class.
1031 */
1032 @Test
1033 public void testMplsCriterionEquals() {
1034 new EqualsTester()
1035 .addEqualityGroup(matchMpls1, sameAsMatchMpls1)
1036 .addEqualityGroup(matchMpls2)
1037 .testEquals();
1038 }
1039
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001040 // TunnelIdCriterion class
1041
1042 /**
1043 * Test the matchTunnelId method.
1044 */
1045 @Test
1046 public void testMatchTunnelIdMethod() {
1047 Criterion matchTunnelId = Criteria.matchTunnelId(tunnelId1);
1048 TunnelIdCriterion tunnelIdCriterion =
1049 checkAndConvert(matchTunnelId,
1050 Criterion.Type.TUNNEL_ID,
1051 TunnelIdCriterion.class);
1052 assertThat(tunnelIdCriterion.tunnelId(), is(equalTo(tunnelId1)));
1053
1054 }
1055
1056 /**
1057 * Test the equals() method of the TunnelIdCriterion class.
1058 */
1059 @Test
1060 public void testTunnelIdCriterionEquals() {
Jian Li79bdf3c2015-11-30 14:54:54 -08001061 new EqualsTester()
1062 .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
1063 .addEqualityGroup(matchTunnelId2)
1064 .testEquals();
Hyunsun Moona08c5d02015-07-14 17:53:00 -07001065 }
1066
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001067 // IPv6ExthdrFlagsCriterion class
1068
1069 /**
1070 * Test the matchIPv6ExthdrFlags method.
1071 */
1072 @Test
1073 public void testMatchIPv6ExthdrFlagsMethod() {
1074 Criterion matchExthdrFlags =
Jian Li79bdf3c2015-11-30 14:54:54 -08001075 Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001076 IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001077 checkAndConvert(matchExthdrFlags,
Jian Li79bdf3c2015-11-30 14:54:54 -08001078 Criterion.Type.IPV6_EXTHDR,
1079 IPv6ExthdrFlagsCriterion.class);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001080 assertThat(exthdrFlagsCriterion.exthdrFlags(),
1081 is(equalTo(ipv6ExthdrFlags1)));
1082 }
1083
1084 /**
1085 * Test the equals() method of the IPv6ExthdrFlagsCriterion class.
1086 */
1087 @Test
1088 public void testIPv6ExthdrFlagsCriterionEquals() {
1089 new EqualsTester()
1090 .addEqualityGroup(matchIpv6ExthdrFlags1,
1091 sameAsMatchIpv6ExthdrFlags1)
1092 .addEqualityGroup(matchIpv6ExthdrFlags2)
1093 .testEquals();
1094 }
1095
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001096 @Test
Sho SHIMIZUefc2e282015-05-04 15:26:23 -07001097 public void testIndexedLambdaCriterionEquals() {
1098 new EqualsTester()
1099 .addEqualityGroup(matchIndexedLambda1, sameAsMatchIndexedLambda1)
1100 .addEqualityGroup(matchIndexedLambda2)
1101 .testEquals();
1102 }
1103
1104 @Test
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -07001105 public void testOchSignalCriterionEquals() {
1106 new EqualsTester()
1107 .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1)
1108 .addEqualityGroup(matchOchSignal2)
1109 .testEquals();
1110 }
1111
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -07001112 /**
1113 * Test the equals() method of the OchSignalTypeCriterion class.
1114 */
1115 @Test
1116 public void testOchSignalTypeCriterionEquals() {
1117 new EqualsTester()
1118 .addEqualityGroup(matchOchSignalType1, sameAsMatchOchSignalType1)
1119 .addEqualityGroup(matchOchSignalType2)
1120 .testEquals();
1121 }
Yafit Hadar52d81552015-10-07 12:26:52 +03001122
1123 /**
1124 * Test the OduSignalId method.
1125 */
1126 @Test
1127 public void testMatchOduSignalIdMethod() {
1128 OduSignalId odu = oduSignalId(1, 80, new byte[]{2, 1, 1, 3, 1, 1, 3, 1, 1, 3});
1129
1130 Criterion matchoduSignalId = Criteria.matchOduSignalId(odu);
1131 OduSignalIdCriterion oduSignalIdCriterion =
1132 checkAndConvert(matchoduSignalId,
1133 Criterion.Type.ODU_SIGID,
1134 OduSignalIdCriterion.class);
1135 assertThat(oduSignalIdCriterion.oduSignalId(), is(equalTo(odu)));
1136 }
1137
1138 /**
1139 * Test the equals() method of the OduSignalIdCriterion class.
1140 */
1141 @Test
1142 public void testOduSignalIdCriterionEquals() {
1143 new EqualsTester()
1144 .addEqualityGroup(matchOduSignalId1, sameAsMatchOduSignalId1)
1145 .addEqualityGroup(matchOduSignalId2)
1146 .testEquals();
1147 }
1148
1149 // OduSignalTypeCriterion class
1150
1151 /**
1152 * Test the OduSignalType method.
1153 */
1154 @Test
1155 public void testMatchOduSignalTypeMethod() {
1156 OduSignalType oduSigType = OduSignalType.ODU2;
1157 Criterion matchoduSignalType = Criteria.matchOduSignalType(oduSigType);
1158 OduSignalTypeCriterion oduSignalTypeCriterion =
1159 checkAndConvert(matchoduSignalType,
1160 Criterion.Type.ODU_SIGTYPE,
1161 OduSignalTypeCriterion.class);
1162 assertThat(oduSignalTypeCriterion.signalType(), is(equalTo(oduSigType)));
1163 }
1164
1165 /**
1166 * Test the equals() method of the OduSignalTypeCriterion class.
1167 */
1168 @Test
1169 public void testOduSignalTypeCriterionEquals() {
1170 new EqualsTester()
1171 .addEqualityGroup(matchOduSignalType1, sameAsMatchOduSignalType1)
1172 .addEqualityGroup(matchOduSignalType2)
1173 .testEquals();
1174 }
Ray Milkey33d90232014-11-04 10:49:00 -08001175}