Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow.criteria; |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 17 | |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.equalTo; |
| 20 | import static org.hamcrest.Matchers.instanceOf; |
| 21 | import static org.hamcrest.Matchers.is; |
| 22 | import static org.hamcrest.Matchers.notNullValue; |
| 23 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 24 | import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; |
| 25 | import static org.onosproject.net.OduSignalId.oduSignalId; |
| 26 | import static org.onosproject.net.PortNumber.portNumber; |
| 27 | |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 28 | import org.junit.Test; |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 29 | import org.onlab.packet.EthType; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 30 | import org.onlab.packet.Ip6Address; |
| 31 | import org.onlab.packet.IpPrefix; |
| 32 | import org.onlab.packet.MacAddress; |
| 33 | import org.onlab.packet.MplsLabel; |
| 34 | import org.onlab.packet.TpPort; |
| 35 | import org.onlab.packet.VlanId; |
Sho SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 36 | import org.onosproject.net.ChannelSpacing; |
| 37 | import org.onosproject.net.GridType; |
| 38 | import org.onosproject.net.Lambda; |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 39 | import org.onosproject.net.OchSignalType; |
| 40 | import org.onosproject.net.OduSignalId; |
| 41 | import org.onosproject.net.OduSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 42 | import org.onosproject.net.PortNumber; |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 43 | |
Ray Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 44 | import com.google.common.testing.EqualsTester; |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 45 | /** |
| 46 | * Unit tests for the Criteria class and its subclasses. |
| 47 | */ |
| 48 | public 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 Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 57 | 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 Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 67 | private static final String MAC1 = "00:00:00:00:00:01"; |
| 68 | private static final String MAC2 = "00:00:00:00:00:02"; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 69 | private MacAddress mac1 = MacAddress.valueOf(MAC1); |
| 70 | private MacAddress mac2 = MacAddress.valueOf(MAC2); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 71 | Criterion matchEth1 = Criteria.matchEthSrc(mac1); |
| 72 | Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1); |
| 73 | Criterion matchEth2 = Criteria.matchEthDst(mac2); |
| 74 | |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 75 | int ethType1 = 1; |
| 76 | int ethType2 = 2; |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 77 | 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 Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 95 | 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 Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 107 | short protocol1 = 1; |
| 108 | short protocol2 = 2; |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 109 | 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. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 115 | private static final String IPV61 = "fe80::1/64"; |
| 116 | private static final String IPV62 = "fc80::2/64"; |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 117 | private IpPrefix ip1 = IpPrefix.valueOf(IP1); |
| 118 | private IpPrefix ip2 = IpPrefix.valueOf(IP2); |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 119 | private IpPrefix ipv61 = IpPrefix.valueOf(IPV61); |
| 120 | private IpPrefix ipv62 = IpPrefix.valueOf(IPV62); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 121 | Criterion matchIp1 = Criteria.matchIPSrc(ip1); |
| 122 | Criterion sameAsMatchIp1 = Criteria.matchIPSrc(ip1); |
| 123 | Criterion matchIp2 = Criteria.matchIPSrc(ip2); |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 124 | Criterion matchIpv61 = Criteria.matchIPSrc(ipv61); |
| 125 | Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61); |
| 126 | Criterion matchIpv62 = Criteria.matchIPSrc(ipv62); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 127 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 128 | 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 Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 133 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 134 | Criterion matchUdpPort1 = Criteria.matchUdpSrc(tpPort1); |
| 135 | Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1); |
| 136 | Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 137 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 138 | Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1); |
| 139 | Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1); |
| 140 | Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 141 | |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 142 | short icmpType1 = 1; |
| 143 | short icmpType2 = 2; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 144 | Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1); |
| 145 | Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1); |
| 146 | Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2); |
| 147 | |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 148 | short icmpCode1 = 1; |
| 149 | short icmpCode2 = 2; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 150 | 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 Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 160 | short icmpv6Type1 = 1; |
| 161 | short icmpv6Type2 = 2; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 162 | Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1); |
| 163 | Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1); |
| 164 | Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2); |
| 165 | |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 166 | short icmpv6Code1 = 1; |
| 167 | short icmpv6Code2 = 2; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 168 | 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 Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 200 | MplsLabel mpls1 = MplsLabel.mplsLabel(1); |
| 201 | MplsLabel mpls2 = MplsLabel.mplsLabel(2); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 202 | Criterion matchMpls1 = Criteria.matchMplsLabel(mpls1); |
| 203 | Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1); |
| 204 | Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2); |
| 205 | |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 206 | 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 Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 212 | 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 Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 230 | Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID); |
| 231 | Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID); |
Sho SHIMIZU | b5e6de6 | 2015-05-04 12:13:44 -0700 | [diff] [blame] | 232 | Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID); |
| 233 | |
Sho SHIMIZU | efc2e28 | 2015-05-04 15:26:23 -0700 | [diff] [blame] | 234 | 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 SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 238 | 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 Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 245 | 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 Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 257 | /** |
| 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 Milkey | 7808105 | 2014-11-05 10:38:12 -0800 | [diff] [blame] | 271 | assertThat(criterion, instanceOf(clazz)); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 272 | return (T) criterion; |
| 273 | } |
| 274 | |
| 275 | /** |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 276 | * 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 288 | 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 Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 311 | assertThatClassIsImmutable(OduSignalIdCriterion.class); |
| 312 | assertThatClassIsImmutable(OduSignalTypeCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 313 | } |
| 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 324 | PortCriterion portCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 325 | checkAndConvert(matchInPort, |
| 326 | Criterion.Type.IN_PORT, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 327 | PortCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 328 | assertThat(portCriterion.port(), is(equalTo(p1))); |
| 329 | } |
| 330 | |
| 331 | /** |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 332 | * Test the matchInPhyPort method. |
| 333 | */ |
| 334 | @Test |
| 335 | public void testMatchInPhyPortMethod() { |
| 336 | PortNumber p1 = portNumber(1); |
| 337 | Criterion matchInPhyPort = Criteria.matchInPhyPort(p1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 338 | PortCriterion portCriterion = |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 339 | checkAndConvert(matchInPhyPort, |
| 340 | Criterion.Type.IN_PHY_PORT, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 341 | PortCriterion.class); |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 342 | assertThat(portCriterion.port(), is(equalTo(p1))); |
| 343 | } |
| 344 | |
| 345 | /** |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 346 | * Test the equals() method of the PortCriterion class. |
| 347 | */ |
| 348 | @Test |
| 349 | public void testPortCriterionEquals() { |
Ray Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 350 | new EqualsTester() |
| 351 | .addEqualityGroup(matchInPort1, sameAsMatchInPort1) |
| 352 | .addEqualityGroup(matchInPort2) |
| 353 | .testEquals(); |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 354 | |
| 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 370 | MetadataCriterion metadataCriterion = |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 371 | checkAndConvert(matchMetadata, |
| 372 | Criterion.Type.METADATA, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 373 | MetadataCriterion.class); |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 374 | 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 Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | // EthCriterion class |
| 389 | |
| 390 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 391 | * Test the matchEthDst method. |
| 392 | */ |
| 393 | @Test |
| 394 | public void testMatchEthDstMethod() { |
| 395 | Criterion matchEthDst = Criteria.matchEthDst(mac1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 396 | EthCriterion ethCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 397 | checkAndConvert(matchEthDst, |
| 398 | Criterion.Type.ETH_DST, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 399 | EthCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 400 | assertThat(ethCriterion.mac(), is(equalTo(mac1))); |
| 401 | } |
| 402 | |
| 403 | /** |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 404 | * Test the matchEthSrc method. |
| 405 | */ |
| 406 | @Test |
| 407 | public void testMatchEthSrcMethod() { |
| 408 | Criterion matchEthSrc = Criteria.matchEthSrc(mac1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 409 | EthCriterion ethCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 410 | checkAndConvert(matchEthSrc, |
| 411 | Criterion.Type.ETH_SRC, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 412 | EthCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 413 | assertThat(ethCriterion.mac(), is(mac1)); |
| 414 | } |
| 415 | |
| 416 | /** |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 417 | * Test the equals() method of the EthCriterion class. |
| 418 | */ |
| 419 | @Test |
| 420 | public void testEthCriterionEquals() { |
Ray Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 421 | new EqualsTester() |
| 422 | .addEqualityGroup(matchEth1, sameAsMatchEth1) |
| 423 | .addEqualityGroup(matchEth2) |
| 424 | .testEquals(); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 427 | // EthTypeCriterion class |
| 428 | |
| 429 | /** |
| 430 | * Test the matchEthType method. |
| 431 | */ |
| 432 | @Test |
| 433 | public void testMatchEthTypeMethod() { |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 434 | EthType ethType = new EthType(12); |
| 435 | Criterion matchEthType = Criteria.matchEthType(new EthType(12)); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 436 | EthTypeCriterion ethTypeCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 437 | checkAndConvert(matchEthType, |
| 438 | Criterion.Type.ETH_TYPE, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 439 | EthTypeCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 440 | 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 Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 448 | new EqualsTester() |
| 449 | .addEqualityGroup(matchEthType1, sameAsMatchEthType1) |
| 450 | .addEqualityGroup(matchEthType2) |
| 451 | .testEquals(); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 454 | // VlanIdCriterion class |
| 455 | |
| 456 | /** |
| 457 | * Test the matchVlanId method. |
| 458 | */ |
| 459 | @Test |
| 460 | public void testMatchVlanIdMethod() { |
| 461 | Criterion matchVlanId = Criteria.matchVlanId(vlanId1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 462 | VlanIdCriterion vlanIdCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 463 | checkAndConvert(matchVlanId, |
| 464 | Criterion.Type.VLAN_VID, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 465 | VlanIdCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 466 | 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 Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 474 | new EqualsTester() |
| 475 | .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1) |
| 476 | .addEqualityGroup(matchVlanId2) |
| 477 | .testEquals(); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 478 | } |
| 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 488 | VlanPcpCriterion vlanPcpCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 489 | checkAndConvert(matchVlanPcp, |
| 490 | Criterion.Type.VLAN_PCP, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 491 | VlanPcpCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 492 | 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 Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 500 | new EqualsTester() |
| 501 | .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1) |
| 502 | .addEqualityGroup(matchVlanPcp2) |
| 503 | .testEquals(); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 506 | // IPDscpCriterion class |
| 507 | |
| 508 | /** |
| 509 | * Test the matchIPDscp method. |
| 510 | */ |
| 511 | @Test |
| 512 | public void testMatchIPDscpMethod() { |
| 513 | Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 514 | IPDscpCriterion ipDscpCriterion = |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 515 | checkAndConvert(matchIPDscp, |
| 516 | Criterion.Type.IP_DSCP, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 517 | IPDscpCriterion.class); |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 518 | 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 540 | IPEcnCriterion ipEcnCriterion = |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 541 | checkAndConvert(matchIPEcn, |
| 542 | Criterion.Type.IP_ECN, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 543 | IPEcnCriterion.class); |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 544 | 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 Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 558 | // IpProtocolCriterion class |
| 559 | |
| 560 | /** |
| 561 | * Test the matchIpProtocol method. |
| 562 | */ |
| 563 | @Test |
| 564 | public void testMatchIpProtocolMethod() { |
| 565 | Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 566 | IPProtocolCriterion ipProtocolCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 567 | checkAndConvert(matchIPProtocol, |
| 568 | Criterion.Type.IP_PROTO, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 569 | IPProtocolCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 570 | 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 Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 578 | new EqualsTester() |
| 579 | .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1) |
| 580 | .addEqualityGroup(matchIpProtocol2) |
| 581 | .testEquals(); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | // IPCriterion class |
| 585 | |
| 586 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 587 | * Test the matchIPSrc method: IPv4. |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 588 | */ |
| 589 | @Test |
| 590 | public void testMatchIPSrcMethod() { |
| 591 | Criterion matchIpSrc = Criteria.matchIPSrc(ip1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 592 | IPCriterion ipCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 593 | checkAndConvert(matchIpSrc, |
| 594 | Criterion.Type.IPV4_SRC, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 595 | IPCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 596 | assertThat(ipCriterion.ip(), is(ip1)); |
| 597 | } |
| 598 | |
| 599 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 600 | * Test the matchIPDst method: IPv4. |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 601 | */ |
| 602 | @Test |
| 603 | public void testMatchIPDstMethod() { |
| 604 | Criterion matchIPDst = Criteria.matchIPDst(ip1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 605 | IPCriterion ipCriterion = |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 606 | checkAndConvert(matchIPDst, |
| 607 | Criterion.Type.IPV4_DST, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 608 | IPCriterion.class); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 609 | assertThat(ipCriterion.ip(), is(equalTo(ip1))); |
| 610 | } |
| 611 | |
| 612 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 613 | * Test the matchIPSrc method: IPv6. |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 614 | */ |
| 615 | @Test |
| 616 | public void testMatchIPv6SrcMethod() { |
| 617 | Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 618 | IPCriterion ipCriterion = |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 619 | checkAndConvert(matchIpv6Src, |
| 620 | Criterion.Type.IPV6_SRC, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 621 | IPCriterion.class); |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 622 | assertThat(ipCriterion.ip(), is(ipv61)); |
| 623 | } |
| 624 | |
| 625 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 626 | * Test the matchIPDst method: IPv6. |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 627 | */ |
| 628 | @Test |
| 629 | public void testMatchIPv6DstMethod() { |
| 630 | Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 631 | IPCriterion ipCriterion = |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 632 | checkAndConvert(matchIPv6Dst, |
| 633 | Criterion.Type.IPV6_DST, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 634 | IPCriterion.class); |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 635 | assertThat(ipCriterion.ip(), is(equalTo(ipv61))); |
| 636 | } |
| 637 | |
| 638 | /** |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 639 | * Test the equals() method of the IpCriterion class. |
| 640 | */ |
| 641 | @Test |
| 642 | public void testIPCriterionEquals() { |
Ray Milkey | fff20b5 | 2014-11-06 14:45:10 -0800 | [diff] [blame] | 643 | new EqualsTester() |
| 644 | .addEqualityGroup(matchIp1, sameAsMatchIp1) |
| 645 | .addEqualityGroup(matchIp2) |
| 646 | .testEquals(); |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 647 | |
| 648 | new EqualsTester() |
| 649 | .addEqualityGroup(matchIpv61, sameAsMatchIpv61) |
| 650 | .addEqualityGroup(matchIpv62) |
| 651 | .testEquals(); |
Ray Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 654 | // TcpPortCriterion class |
| 655 | |
| 656 | /** |
| 657 | * Test the matchTcpSrc method. |
| 658 | */ |
| 659 | @Test |
| 660 | public void testMatchTcpSrcMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 661 | Criterion matchTcpSrc = Criteria.matchTcpSrc(tpPort1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 662 | TcpPortCriterion tcpPortCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 663 | checkAndConvert(matchTcpSrc, |
| 664 | Criterion.Type.TCP_SRC, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 665 | TcpPortCriterion.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 666 | assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1))); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Test the matchTcpDst method. |
| 671 | */ |
| 672 | @Test |
| 673 | public void testMatchTcpDstMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 674 | Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 675 | TcpPortCriterion tcpPortCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 676 | checkAndConvert(matchTcpDst, |
| 677 | Criterion.Type.TCP_DST, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 678 | TcpPortCriterion.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 679 | assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1))); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 680 | } |
| 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 Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 700 | Criterion matchUdpSrc = Criteria.matchUdpSrc(tpPort1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 701 | UdpPortCriterion udpPortCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 702 | checkAndConvert(matchUdpSrc, |
| 703 | Criterion.Type.UDP_SRC, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 704 | UdpPortCriterion.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 705 | assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1))); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Test the matchUdpDst method. |
| 710 | */ |
| 711 | @Test |
| 712 | public void testMatchUdpDstMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 713 | Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 714 | UdpPortCriterion udpPortCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 715 | checkAndConvert(matchUdpDst, |
| 716 | Criterion.Type.UDP_DST, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 717 | UdpPortCriterion.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 718 | assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1))); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 719 | } |
| 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 Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 739 | Criterion matchSctpSrc = Criteria.matchSctpSrc(tpPort1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 740 | SctpPortCriterion sctpPortCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 741 | checkAndConvert(matchSctpSrc, |
| 742 | Criterion.Type.SCTP_SRC, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 743 | SctpPortCriterion.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 744 | assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1))); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Test the matchSctpDst method. |
| 749 | */ |
| 750 | @Test |
| 751 | public void testMatchSctpDstMethod() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 752 | Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 753 | SctpPortCriterion sctpPortCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 754 | checkAndConvert(matchSctpDst, |
| 755 | Criterion.Type.SCTP_DST, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 756 | SctpPortCriterion.class); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 757 | assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1))); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 758 | } |
| 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 Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 778 | short icmpType = 12; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 779 | Criterion matchIcmpType = Criteria.matchIcmpType(icmpType); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 780 | IcmpTypeCriterion icmpTypeCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 781 | checkAndConvert(matchIcmpType, |
| 782 | Criterion.Type.ICMPV4_TYPE, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 783 | IcmpTypeCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 784 | 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 Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 805 | short icmpCode = 12; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 806 | Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 807 | IcmpCodeCriterion icmpCodeCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 808 | checkAndConvert(matchIcmpCode, |
| 809 | Criterion.Type.ICMPV4_CODE, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 810 | IcmpCodeCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 811 | 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 Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 832 | int flowLabel = 12; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 833 | Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 834 | IPv6FlowLabelCriterion flowLabelCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 835 | checkAndConvert(matchFlowLabel, |
| 836 | Criterion.Type.IPV6_FLABEL, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 837 | IPv6FlowLabelCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 838 | 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 Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 859 | short icmpv6Type = 12; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 860 | Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 861 | Icmpv6TypeCriterion icmpv6TypeCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 862 | checkAndConvert(matchIcmpv6Type, |
| 863 | Criterion.Type.ICMPV6_TYPE, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 864 | Icmpv6TypeCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 865 | 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 Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 886 | short icmpv6Code = 12; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 887 | Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 888 | Icmpv6CodeCriterion icmpv6CodeCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 889 | checkAndConvert(matchIcmpv6Code, |
| 890 | Criterion.Type.ICMPV6_CODE, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 891 | Icmpv6CodeCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 892 | 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 915 | IPv6NDTargetAddressCriterion targetAddressCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 916 | checkAndConvert(matchTargetAddress, |
| 917 | Criterion.Type.IPV6_ND_TARGET, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 918 | IPv6NDTargetAddressCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 919 | 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 944 | IPv6NDLinkLayerAddressCriterion srcLlCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 945 | checkAndConvert(matchSrcLlAddr, |
| 946 | Criterion.Type.IPV6_ND_SLL, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 947 | IPv6NDLinkLayerAddressCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 948 | 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 958 | IPv6NDLinkLayerAddressCriterion targetLlCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 959 | checkAndConvert(matchTargetLlAddr, |
| 960 | Criterion.Type.IPV6_ND_TLL, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 961 | IPv6NDLinkLayerAddressCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 962 | 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 SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 989 | MplsCriterion mplsCriterion = |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 990 | checkAndConvert(matchMplsLabel, |
| 991 | Criterion.Type.MPLS_LABEL, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 992 | MplsCriterion.class); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 993 | 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 Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 1007 | // 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 Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 1034 | // IPv6ExthdrFlagsCriterion class |
| 1035 | |
| 1036 | /** |
| 1037 | * Test the matchIPv6ExthdrFlags method. |
| 1038 | */ |
| 1039 | @Test |
| 1040 | public void testMatchIPv6ExthdrFlagsMethod() { |
| 1041 | Criterion matchExthdrFlags = |
| 1042 | Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1043 | IPv6ExthdrFlagsCriterion exthdrFlagsCriterion = |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 1044 | checkAndConvert(matchExthdrFlags, |
| 1045 | Criterion.Type.IPV6_EXTHDR, |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1046 | IPv6ExthdrFlagsCriterion.class); |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 1047 | 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 SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 1063 | @Test |
Sho SHIMIZU | efc2e28 | 2015-05-04 15:26:23 -0700 | [diff] [blame] | 1064 | public void testIndexedLambdaCriterionEquals() { |
| 1065 | new EqualsTester() |
| 1066 | .addEqualityGroup(matchIndexedLambda1, sameAsMatchIndexedLambda1) |
| 1067 | .addEqualityGroup(matchIndexedLambda2) |
| 1068 | .testEquals(); |
| 1069 | } |
| 1070 | |
| 1071 | @Test |
Sho SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 1072 | public void testOchSignalCriterionEquals() { |
| 1073 | new EqualsTester() |
| 1074 | .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1) |
| 1075 | .addEqualityGroup(matchOchSignal2) |
| 1076 | .testEquals(); |
| 1077 | } |
| 1078 | |
Sho SHIMIZU | b5e6de6 | 2015-05-04 12:13:44 -0700 | [diff] [blame] | 1079 | /** |
| 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 Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 1089 | |
| 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 Milkey | 33d9023 | 2014-11-04 10:49:00 -0800 | [diff] [blame] | 1142 | } |