Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow.criteria; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 17 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.PortNumber; |
| 22 | import org.onosproject.net.flow.criteria.Criterion.Type; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 23 | import org.onlab.packet.IpPrefix; |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 24 | import org.onlab.packet.Ip6Address; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onlab.packet.VlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 27 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Factory class to create various traffic selection criteria. |
| 30 | */ |
| 31 | public final class Criteria { |
| 32 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 33 | //TODO: incomplete type implementation. Need to implement complete list from Criterion |
| 34 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 35 | // Ban construction |
| 36 | private Criteria() { |
| 37 | } |
| 38 | |
| 39 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 40 | * Creates a match on IN_PORT field using the specified value. |
| 41 | * |
| 42 | * @param port inport value |
| 43 | * @return match criterion |
| 44 | */ |
| 45 | public static Criterion matchInPort(PortNumber port) { |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 46 | return new PortCriterion(port, Type.IN_PORT); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Creates a match on IN_PHY_PORT field using the specified value. |
| 51 | * |
| 52 | * @param port inport value |
| 53 | * @return match criterion |
| 54 | */ |
| 55 | public static Criterion matchInPhyPort(PortNumber port) { |
| 56 | return new PortCriterion(port, Type.IN_PHY_PORT); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates a match on METADATA field using the specified value. |
| 61 | * |
| 62 | * @param metadata metadata value |
| 63 | * @return match criterion |
| 64 | */ |
| 65 | public static Criterion matchMetadata(Long metadata) { |
| 66 | return new MetadataCriterion(metadata); |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 70 | * Creates a match on ETH_DST field using the specified value. This value |
| 71 | * may be a wildcard mask. |
| 72 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 73 | * @param mac MAC address value or wildcard mask |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 74 | * @return match criterion |
| 75 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 76 | public static Criterion matchEthDst(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 77 | return new EthCriterion(mac, Type.ETH_DST); |
| 78 | } |
| 79 | |
| 80 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 81 | * Creates a match on ETH_SRC field using the specified value. This value |
| 82 | * may be a wildcard mask. |
| 83 | * |
| 84 | * @param mac MAC address value or wildcard mask |
| 85 | * @return match criterion |
| 86 | */ |
| 87 | public static Criterion matchEthSrc(MacAddress mac) { |
| 88 | return new EthCriterion(mac, Type.ETH_SRC); |
| 89 | } |
| 90 | |
| 91 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 92 | * Creates a match on ETH_TYPE field using the specified value. |
| 93 | * |
| 94 | * @param ethType eth type value |
| 95 | * @return match criterion |
| 96 | */ |
| 97 | public static Criterion matchEthType(Short ethType) { |
| 98 | return new EthTypeCriterion(ethType); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Creates a match on VLAN ID field using the specified value. |
| 103 | * |
| 104 | * @param vlanId vlan id value |
| 105 | * @return match criterion |
| 106 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 107 | public static Criterion matchVlanId(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 108 | return new VlanIdCriterion(vlanId); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Creates a match on VLAN PCP field using the specified value. |
| 113 | * |
| 114 | * @param vlanPcp vlan pcp value |
| 115 | * @return match criterion |
| 116 | */ |
alshabib | b45d196 | 2014-09-18 14:25:45 -0700 | [diff] [blame] | 117 | public static Criterion matchVlanPcp(Byte vlanPcp) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 118 | return new VlanPcpCriterion(vlanPcp); |
| 119 | } |
| 120 | |
| 121 | /** |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 122 | * Creates a match on IP DSCP field using the specified value. |
| 123 | * |
| 124 | * @param ipDscp ip dscp value |
| 125 | * @return match criterion |
| 126 | */ |
| 127 | public static Criterion matchIPDscp(Byte ipDscp) { |
| 128 | return new IPDscpCriterion(ipDscp); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Creates a match on IP ECN field using the specified value. |
| 133 | * |
| 134 | * @param ipEcn ip ecn value |
| 135 | * @return match criterion |
| 136 | */ |
| 137 | public static Criterion matchIPEcn(Byte ipEcn) { |
| 138 | return new IPEcnCriterion(ipEcn); |
| 139 | } |
| 140 | |
| 141 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 142 | * Creates a match on IP proto field using the specified value. |
| 143 | * |
| 144 | * @param proto ip protocol value |
| 145 | * @return match criterion |
| 146 | */ |
| 147 | public static Criterion matchIPProtocol(Byte proto) { |
| 148 | return new IPProtocolCriterion(proto); |
| 149 | } |
| 150 | |
| 151 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 152 | * Creates a match on IPv4 source field using the specified value. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 153 | * |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 154 | * @param ip ipv4 source value |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 155 | * @return match criterion |
| 156 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 157 | public static Criterion matchIPSrc(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 158 | return new IPCriterion(ip, Type.IPV4_SRC); |
| 159 | } |
| 160 | |
| 161 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 162 | * Creates a match on IPv4 destination field using the specified value. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 163 | * |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 164 | * @param ip ipv4 source value |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 165 | * @return match criterion |
| 166 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 167 | public static Criterion matchIPDst(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 168 | return new IPCriterion(ip, Type.IPV4_DST); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 171 | /** |
| 172 | * Creates a match on TCP source port field using the specified value. |
| 173 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 174 | * @param tcpPort TCP source port |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 175 | * @return match criterion |
| 176 | */ |
| 177 | public static Criterion matchTcpSrc(Short tcpPort) { |
| 178 | return new TcpPortCriterion(tcpPort, Type.TCP_SRC); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Creates a match on TCP destination port field using the specified value. |
| 183 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 184 | * @param tcpPort TCP destination port |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 185 | * @return match criterion |
| 186 | */ |
| 187 | public static Criterion matchTcpDst(Short tcpPort) { |
| 188 | return new TcpPortCriterion(tcpPort, Type.TCP_DST); |
| 189 | } |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 190 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 191 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 192 | * Creates a match on UDP source port field using the specified value. |
| 193 | * |
| 194 | * @param udpPort UDP source port |
| 195 | * @return match criterion |
| 196 | */ |
| 197 | public static Criterion matchUdpSrc(Short udpPort) { |
| 198 | return new UdpPortCriterion(udpPort, Type.UDP_SRC); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Creates a match on UDP destination port field using the specified value. |
| 203 | * |
| 204 | * @param udpPort UDP destination port |
| 205 | * @return match criterion |
| 206 | */ |
| 207 | public static Criterion matchUdpDst(Short udpPort) { |
| 208 | return new UdpPortCriterion(udpPort, Type.UDP_DST); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Creates a match on SCTP source port field using the specified value. |
| 213 | * |
| 214 | * @param sctpPort SCTP source port |
| 215 | * @return match criterion |
| 216 | */ |
| 217 | public static Criterion matchSctpSrc(Short sctpPort) { |
| 218 | return new SctpPortCriterion(sctpPort, Type.SCTP_SRC); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Creates a match on SCTP destination port field using the specified |
| 223 | * value. |
| 224 | * |
| 225 | * @param sctpPort SCTP destination port |
| 226 | * @return match criterion |
| 227 | */ |
| 228 | public static Criterion matchSctpDst(Short sctpPort) { |
| 229 | return new SctpPortCriterion(sctpPort, Type.SCTP_DST); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Creates a match on ICMP type field using the specified value. |
| 234 | * |
| 235 | * @param icmpType ICMP type |
| 236 | * @return match criterion |
| 237 | */ |
| 238 | public static Criterion matchIcmpType(Byte icmpType) { |
| 239 | return new IcmpTypeCriterion(icmpType); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Creates a match on ICMP code field using the specified value. |
| 244 | * |
| 245 | * @param icmpCode ICMP code |
| 246 | * @return match criterion |
| 247 | */ |
| 248 | public static Criterion matchIcmpCode(Byte icmpCode) { |
| 249 | return new IcmpCodeCriterion(icmpCode); |
| 250 | } |
| 251 | |
| 252 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 253 | * Creates a match on IPv6 source field using the specified value. |
| 254 | * |
| 255 | * @param ip ipv6 source value |
| 256 | * @return match criterion |
| 257 | */ |
| 258 | public static Criterion matchIPv6Src(IpPrefix ip) { |
| 259 | return new IPCriterion(ip, Type.IPV6_SRC); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Creates a match on IPv6 destination field using the specified value. |
| 264 | * |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 265 | * @param ip ipv6 destination value |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 266 | * @return match criterion |
| 267 | */ |
| 268 | public static Criterion matchIPv6Dst(IpPrefix ip) { |
| 269 | return new IPCriterion(ip, Type.IPV6_DST); |
| 270 | } |
| 271 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 272 | /** |
| 273 | * Creates a match on IPv6 flow label field using the specified value. |
| 274 | * |
| 275 | * @param flowLabel IPv6 flow label |
| 276 | * @return match criterion |
| 277 | */ |
| 278 | public static Criterion matchIPv6FlowLabel(Integer flowLabel) { |
| 279 | return new IPv6FlowLabelCriterion(flowLabel); |
| 280 | } |
| 281 | |
| 282 | /** |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 283 | * Creates a match on ICMPv6 type field using the specified value. |
| 284 | * |
| 285 | * @param icmpv6Type ICMPv6 type |
| 286 | * @return match criterion |
| 287 | */ |
| 288 | public static Criterion matchIcmpv6Type(Byte icmpv6Type) { |
| 289 | return new Icmpv6TypeCriterion(icmpv6Type); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Creates a match on ICMPv6 code field using the specified value. |
| 294 | * |
| 295 | * @param icmpv6Code ICMPv6 code |
| 296 | * @return match criterion |
| 297 | */ |
| 298 | public static Criterion matchIcmpv6Code(Byte icmpv6Code) { |
| 299 | return new Icmpv6CodeCriterion(icmpv6Code); |
| 300 | } |
| 301 | |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 302 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 303 | * Creates a match on IPv6 Neighbor Discovery target address using the |
| 304 | * specified value. |
| 305 | * |
| 306 | * @param targetAddress IPv6 Neighbor Discovery target address |
| 307 | * @return match criterion |
| 308 | */ |
| 309 | public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) { |
| 310 | return new IPv6NDTargetAddressCriterion(targetAddress); |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Creates a match on IPv6 Neighbor Discovery source link-layer address |
| 315 | * using the specified value. |
| 316 | * |
| 317 | * @param mac IPv6 Neighbor Discovery source link-layer address |
| 318 | * @return match criterion |
| 319 | */ |
| 320 | public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) { |
| 321 | return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Creates a match on IPv6 Neighbor Discovery target link-layer address |
| 326 | * using the specified value. |
| 327 | * |
| 328 | * @param mac IPv6 Neighbor Discovery target link-layer address |
| 329 | * @return match criterion |
| 330 | */ |
| 331 | public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) { |
| 332 | return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL); |
| 333 | } |
| 334 | |
| 335 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 336 | * Creates a match on MPLS label. |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 337 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 338 | * @param mplsLabel MPLS label |
| 339 | * @return match criterion |
| 340 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 341 | public static Criterion matchMplsLabel(Integer mplsLabel) { |
| 342 | return new MplsCriterion(mplsLabel); |
| 343 | } |
| 344 | |
| 345 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 346 | * Creates a match on lambda field using the specified value. |
| 347 | * |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 348 | * @param lambda lambda to match on |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 349 | * @return match criterion |
| 350 | */ |
| 351 | public static Criterion matchLambda(Short lambda) { |
| 352 | return new LambdaCriterion(lambda, Type.OCH_SIGID); |
| 353 | } |
| 354 | |
| 355 | /** |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 356 | * Creates a match on optical signal type using the specified value. |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 357 | * |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 358 | * @param sigType optical signal type |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 359 | * @return match criterion |
| 360 | */ |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 361 | public static Criterion matchOpticalSignalType(Short sigType) { |
| 362 | return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 365 | /** |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 366 | * Implementation of input port criterion. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 367 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 368 | public static final class PortCriterion implements Criterion { |
| 369 | private final PortNumber port; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 370 | private final Type type; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 371 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 372 | /** |
| 373 | * Constructor. |
| 374 | * |
| 375 | * @param port the input port number to match |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 376 | * @param type the match type. Should be either Type.IN_PORT or |
| 377 | * Type.IN_PHY_PORT |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 378 | */ |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 379 | public PortCriterion(PortNumber port, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 380 | this.port = port; |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 381 | this.type = type; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public Type type() { |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 386 | return this.type; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 389 | /** |
| 390 | * Gets the input port number to match. |
| 391 | * |
| 392 | * @return the input port number to match |
| 393 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 394 | public PortNumber port() { |
| 395 | return this.port; |
| 396 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 397 | |
| 398 | @Override |
| 399 | public String toString() { |
| 400 | return toStringHelper(type().toString()) |
| 401 | .add("port", port).toString(); |
| 402 | } |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 403 | |
| 404 | @Override |
| 405 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 406 | return Objects.hash(type(), port); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public boolean equals(Object obj) { |
| 411 | if (this == obj) { |
| 412 | return true; |
| 413 | } |
| 414 | if (obj instanceof PortCriterion) { |
| 415 | PortCriterion that = (PortCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 416 | return Objects.equals(port, that.port) && |
| 417 | Objects.equals(this.type(), that.type()); |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 418 | } |
| 419 | return false; |
| 420 | } |
| 421 | } |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 422 | |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 423 | /** |
| 424 | * Implementation of Metadata criterion. |
| 425 | */ |
| 426 | public static final class MetadataCriterion implements Criterion { |
| 427 | private final Long metadata; |
| 428 | |
| 429 | /** |
| 430 | * Constructor. |
| 431 | * |
| 432 | * @param metadata the metadata to match |
| 433 | */ |
| 434 | public MetadataCriterion(Long metadata) { |
| 435 | this.metadata = metadata; |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public Type type() { |
| 440 | return Type.METADATA; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Gets the metadata to match. |
| 445 | * |
| 446 | * @return the metadata to match |
| 447 | */ |
| 448 | public Long metadata() { |
| 449 | return metadata; |
| 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public String toString() { |
| 454 | return toStringHelper(type().toString()) |
| 455 | .add("metadata", Long.toHexString(metadata)) |
| 456 | .toString(); |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public int hashCode() { |
| 461 | return Objects.hash(type(), metadata); |
| 462 | } |
| 463 | |
| 464 | @Override |
| 465 | public boolean equals(Object obj) { |
| 466 | if (this == obj) { |
| 467 | return true; |
| 468 | } |
| 469 | if (obj instanceof MetadataCriterion) { |
| 470 | MetadataCriterion that = (MetadataCriterion) obj; |
| 471 | return Objects.equals(metadata, that.metadata) && |
| 472 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 473 | } |
| 474 | return false; |
| 475 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 478 | /** |
| 479 | * Implementation of MAC address criterion. |
| 480 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 481 | public static final class EthCriterion implements Criterion { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 482 | private final MacAddress mac; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 483 | private final Type type; |
| 484 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 485 | /** |
| 486 | * Constructor. |
| 487 | * |
| 488 | * @param mac the source or destination MAC address to match |
| 489 | * @param type the match type. Should be either Type.ETH_DST or |
| 490 | * Type.ETH_SRC |
| 491 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 492 | public EthCriterion(MacAddress mac, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 493 | this.mac = mac; |
| 494 | this.type = type; |
| 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public Type type() { |
| 499 | return this.type; |
| 500 | } |
| 501 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 502 | /** |
| 503 | * Gets the MAC address to match. |
| 504 | * |
| 505 | * @return the MAC address to match |
| 506 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 507 | public MacAddress mac() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 508 | return this.mac; |
| 509 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 510 | |
| 511 | @Override |
| 512 | public String toString() { |
| 513 | return toStringHelper(type().toString()) |
| 514 | .add("mac", mac).toString(); |
| 515 | } |
| 516 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 517 | @Override |
| 518 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 519 | return Objects.hash(type, mac); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean equals(Object obj) { |
| 524 | if (this == obj) { |
| 525 | return true; |
| 526 | } |
| 527 | if (obj instanceof EthCriterion) { |
| 528 | EthCriterion that = (EthCriterion) obj; |
| 529 | return Objects.equals(mac, that.mac) && |
| 530 | Objects.equals(type, that.type); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 531 | } |
| 532 | return false; |
| 533 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 536 | /** |
| 537 | * Implementation of Ethernet type criterion. |
| 538 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 539 | public static final class EthTypeCriterion implements Criterion { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 540 | private final Short ethType; |
| 541 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 542 | /** |
| 543 | * Constructor. |
| 544 | * |
| 545 | * @param ethType the Ethernet frame type to match |
| 546 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 547 | public EthTypeCriterion(Short ethType) { |
| 548 | this.ethType = ethType; |
| 549 | } |
| 550 | |
| 551 | @Override |
| 552 | public Type type() { |
| 553 | return Type.ETH_TYPE; |
| 554 | } |
| 555 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 556 | /** |
| 557 | * Gets the Ethernet frame type to match. |
| 558 | * |
| 559 | * @return the Ethernet frame type to match |
| 560 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 561 | public Short ethType() { |
| 562 | return ethType; |
| 563 | } |
| 564 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 565 | @Override |
| 566 | public String toString() { |
| 567 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 568 | .add("ethType", Long.toHexString(ethType & 0xffff)) |
| 569 | .toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 570 | } |
| 571 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 572 | @Override |
| 573 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 574 | return Objects.hash(type(), ethType); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | @Override |
| 578 | public boolean equals(Object obj) { |
| 579 | if (this == obj) { |
| 580 | return true; |
| 581 | } |
| 582 | if (obj instanceof EthTypeCriterion) { |
| 583 | EthTypeCriterion that = (EthTypeCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 584 | return Objects.equals(ethType, that.ethType) && |
| 585 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 586 | |
| 587 | |
| 588 | } |
| 589 | return false; |
| 590 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 593 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 594 | * Implementation of VLAN ID criterion. |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 595 | */ |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 596 | public static final class VlanIdCriterion implements Criterion { |
| 597 | private final VlanId vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 598 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 599 | /** |
| 600 | * Constructor. |
| 601 | * |
| 602 | * @param vlanId the VLAN ID to match |
| 603 | */ |
| 604 | public VlanIdCriterion(VlanId vlanId) { |
| 605 | this.vlanId = vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public Type type() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 610 | return Type.VLAN_VID; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 613 | /** |
| 614 | * Gets the VLAN ID to match. |
| 615 | * |
| 616 | * @return the VLAN ID to match |
| 617 | */ |
| 618 | public VlanId vlanId() { |
| 619 | return vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 620 | } |
| 621 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 622 | @Override |
| 623 | public String toString() { |
| 624 | return toStringHelper(type().toString()) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 625 | .add("vlanId", vlanId).toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 626 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 627 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 628 | @Override |
| 629 | public int hashCode() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 630 | return Objects.hash(type(), vlanId); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | @Override |
| 634 | public boolean equals(Object obj) { |
| 635 | if (this == obj) { |
| 636 | return true; |
| 637 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 638 | if (obj instanceof VlanIdCriterion) { |
| 639 | VlanIdCriterion that = (VlanIdCriterion) obj; |
| 640 | return Objects.equals(vlanId, that.vlanId) && |
| 641 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 642 | } |
| 643 | return false; |
| 644 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 645 | } |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 646 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 647 | /** |
| 648 | * Implementation of VLAN priority criterion. |
| 649 | */ |
| 650 | public static final class VlanPcpCriterion implements Criterion { |
| 651 | private final Byte vlanPcp; |
| 652 | |
| 653 | /** |
| 654 | * Constructor. |
| 655 | * |
| 656 | * @param vlanPcp the VLAN priority to match |
| 657 | */ |
| 658 | public VlanPcpCriterion(Byte vlanPcp) { |
| 659 | this.vlanPcp = vlanPcp; |
| 660 | } |
| 661 | |
| 662 | @Override |
| 663 | public Type type() { |
| 664 | return Type.VLAN_PCP; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * Gets the VLAN priority to match. |
| 669 | * |
| 670 | * @return the VLAN priority to match |
| 671 | */ |
| 672 | public Byte priority() { |
| 673 | return vlanPcp; |
| 674 | } |
| 675 | |
| 676 | @Override |
| 677 | public String toString() { |
| 678 | return toStringHelper(type().toString()) |
| 679 | .add("priority", Long.toHexString(vlanPcp)).toString(); |
| 680 | } |
| 681 | |
| 682 | @Override |
| 683 | public int hashCode() { |
| 684 | return Objects.hash(type(), vlanPcp); |
| 685 | } |
| 686 | |
| 687 | @Override |
| 688 | public boolean equals(Object obj) { |
| 689 | if (this == obj) { |
| 690 | return true; |
| 691 | } |
| 692 | if (obj instanceof VlanPcpCriterion) { |
| 693 | VlanPcpCriterion that = (VlanPcpCriterion) obj; |
| 694 | return Objects.equals(vlanPcp, that.vlanPcp) && |
| 695 | Objects.equals(this.type(), that.type()); |
| 696 | } |
| 697 | return false; |
| 698 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 701 | /** |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame^] | 702 | * Implementation of IP DSCP criterion (6-bit Differentiated Services |
| 703 | * Code Point). |
| 704 | */ |
| 705 | public static final class IPDscpCriterion implements Criterion { |
| 706 | private static final byte DSCP_MASK = 0x3f; |
| 707 | private final Byte ipDscp; // IP DSCP value: 6 bits |
| 708 | |
| 709 | /** |
| 710 | * Constructor. |
| 711 | * |
| 712 | * @param ipDscp the IP DSCP value to match |
| 713 | */ |
| 714 | public IPDscpCriterion(Byte ipDscp) { |
| 715 | this.ipDscp = (byte) (ipDscp & DSCP_MASK); |
| 716 | } |
| 717 | |
| 718 | @Override |
| 719 | public Type type() { |
| 720 | return Type.IP_DSCP; |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * Gets the IP DSCP value to match. |
| 725 | * |
| 726 | * @return the IP DSCP value to match |
| 727 | */ |
| 728 | public Byte ipDscp() { |
| 729 | return ipDscp; |
| 730 | } |
| 731 | |
| 732 | @Override |
| 733 | public String toString() { |
| 734 | return toStringHelper(type().toString()) |
| 735 | .add("ipDscp", ipDscp).toString(); |
| 736 | } |
| 737 | |
| 738 | @Override |
| 739 | public int hashCode() { |
| 740 | return Objects.hash(type(), ipDscp); |
| 741 | } |
| 742 | |
| 743 | @Override |
| 744 | public boolean equals(Object obj) { |
| 745 | if (this == obj) { |
| 746 | return true; |
| 747 | } |
| 748 | if (obj instanceof IPDscpCriterion) { |
| 749 | IPDscpCriterion that = (IPDscpCriterion) obj; |
| 750 | return Objects.equals(ipDscp, that.ipDscp) && |
| 751 | Objects.equals(this.type(), that.type()); |
| 752 | } |
| 753 | return false; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * Implementation of IP ECN criterion (3-bit Explicit Congestion |
| 759 | * Notification). |
| 760 | */ |
| 761 | public static final class IPEcnCriterion implements Criterion { |
| 762 | private static final byte ECN_MASK = 0x3; |
| 763 | private final Byte ipEcn; // IP ECN value: 3 bits |
| 764 | |
| 765 | /** |
| 766 | * Constructor. |
| 767 | * |
| 768 | * @param ipEcn the IP ECN value to match |
| 769 | */ |
| 770 | public IPEcnCriterion(Byte ipEcn) { |
| 771 | this.ipEcn = (byte) (ipEcn & ECN_MASK); |
| 772 | } |
| 773 | |
| 774 | @Override |
| 775 | public Type type() { |
| 776 | return Type.IP_ECN; |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * Gets the IP ECN value to match. |
| 781 | * |
| 782 | * @return the IP ECN value to match |
| 783 | */ |
| 784 | public Byte ipEcn() { |
| 785 | return ipEcn; |
| 786 | } |
| 787 | |
| 788 | @Override |
| 789 | public String toString() { |
| 790 | return toStringHelper(type().toString()) |
| 791 | .add("ipEcn", ipEcn).toString(); |
| 792 | } |
| 793 | |
| 794 | @Override |
| 795 | public int hashCode() { |
| 796 | return Objects.hash(type(), ipEcn); |
| 797 | } |
| 798 | |
| 799 | @Override |
| 800 | public boolean equals(Object obj) { |
| 801 | if (this == obj) { |
| 802 | return true; |
| 803 | } |
| 804 | if (obj instanceof IPEcnCriterion) { |
| 805 | IPEcnCriterion that = (IPEcnCriterion) obj; |
| 806 | return Objects.equals(ipEcn, that.ipEcn) && |
| 807 | Objects.equals(this.type(), that.type()); |
| 808 | } |
| 809 | return false; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | /** |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 814 | * Implementation of Internet Protocol Number criterion. |
| 815 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 816 | public static final class IPProtocolCriterion implements Criterion { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 817 | private final Byte proto; |
| 818 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 819 | /** |
| 820 | * Constructor. |
| 821 | * |
| 822 | * @param protocol the IP protocol to match (e.g., TCP=6, UDP=17). |
| 823 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 824 | public IPProtocolCriterion(Byte protocol) { |
| 825 | this.proto = protocol; |
| 826 | } |
| 827 | |
| 828 | @Override |
| 829 | public Type type() { |
| 830 | return Type.IP_PROTO; |
| 831 | } |
| 832 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 833 | /** |
| 834 | * Gets the IP protocol to match. |
| 835 | * |
| 836 | * @return the IP protocol to match |
| 837 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 838 | public Byte protocol() { |
| 839 | return proto; |
| 840 | } |
| 841 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 842 | @Override |
| 843 | public String toString() { |
| 844 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 845 | .add("protocol", Long.toHexString(proto & 0xff)) |
| 846 | .toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 847 | } |
| 848 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 849 | @Override |
| 850 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 851 | return Objects.hash(type(), proto); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public boolean equals(Object obj) { |
| 856 | if (this == obj) { |
| 857 | return true; |
| 858 | } |
| 859 | if (obj instanceof IPProtocolCriterion) { |
| 860 | IPProtocolCriterion that = (IPProtocolCriterion) obj; |
| 861 | return Objects.equals(proto, that.proto); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 862 | } |
| 863 | return false; |
| 864 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 867 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 868 | * Implementation of IP address criterion. |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 869 | */ |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 870 | public static final class IPCriterion implements Criterion { |
| 871 | private final IpPrefix ip; |
| 872 | private final Type type; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 873 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 874 | /** |
| 875 | * Constructor. |
| 876 | * |
| 877 | * @param ip the IP prefix to match. Could be either IPv4 or IPv6 |
| 878 | * @param type the match type. Should be one of the following: |
| 879 | * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST |
| 880 | */ |
| 881 | public IPCriterion(IpPrefix ip, Type type) { |
| 882 | this.ip = ip; |
| 883 | this.type = type; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | @Override |
| 887 | public Type type() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 888 | return this.type; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 891 | /** |
| 892 | * Gets the IP prefix to match. |
| 893 | * |
| 894 | * @return the IP prefix to match |
| 895 | */ |
| 896 | public IpPrefix ip() { |
| 897 | return this.ip; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 898 | } |
| 899 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 900 | @Override |
| 901 | public String toString() { |
| 902 | return toStringHelper(type().toString()) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 903 | .add("ip", ip).toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 904 | } |
| 905 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 906 | @Override |
| 907 | public int hashCode() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 908 | return Objects.hash(type, ip); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | @Override |
| 912 | public boolean equals(Object obj) { |
| 913 | if (this == obj) { |
| 914 | return true; |
| 915 | } |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 916 | if (obj instanceof IPCriterion) { |
| 917 | IPCriterion that = (IPCriterion) obj; |
| 918 | return Objects.equals(ip, that.ip) && |
| 919 | Objects.equals(type, that.type); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 920 | } |
| 921 | return false; |
| 922 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 925 | /** |
| 926 | * Implementation of TCP port criterion. |
| 927 | */ |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 928 | public static final class TcpPortCriterion implements Criterion { |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 929 | private final Short tcpPort; |
| 930 | private final Type type; |
| 931 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 932 | /** |
| 933 | * Constructor. |
| 934 | * |
| 935 | * @param tcpPort the TCP port to match |
| 936 | * @param type the match type. Should be either Type.TCP_SRC or |
| 937 | * Type.TCP_DST |
| 938 | */ |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 939 | public TcpPortCriterion(Short tcpPort, Type type) { |
| 940 | this.tcpPort = tcpPort; |
| 941 | this.type = type; |
| 942 | } |
| 943 | |
| 944 | @Override |
| 945 | public Type type() { |
| 946 | return this.type; |
| 947 | } |
| 948 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 949 | /** |
| 950 | * Gets the TCP port to match. |
| 951 | * |
| 952 | * @return the TCP port to match |
| 953 | */ |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 954 | public Short tcpPort() { |
| 955 | return this.tcpPort; |
| 956 | } |
| 957 | |
| 958 | @Override |
| 959 | public String toString() { |
| 960 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 961 | .add("tcpPort", tcpPort & 0xffff).toString(); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | @Override |
| 965 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 966 | return Objects.hash(type, tcpPort); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | @Override |
| 970 | public boolean equals(Object obj) { |
| 971 | if (this == obj) { |
| 972 | return true; |
| 973 | } |
| 974 | if (obj instanceof TcpPortCriterion) { |
| 975 | TcpPortCriterion that = (TcpPortCriterion) obj; |
| 976 | return Objects.equals(tcpPort, that.tcpPort) && |
| 977 | Objects.equals(type, that.type); |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 978 | } |
| 979 | return false; |
| 980 | } |
| 981 | } |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 982 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 983 | /** |
| 984 | * Implementation of UDP port criterion. |
| 985 | */ |
| 986 | public static final class UdpPortCriterion implements Criterion { |
| 987 | private final Short udpPort; |
| 988 | private final Type type; |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 989 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 990 | /** |
| 991 | * Constructor. |
| 992 | * |
| 993 | * @param udpPort the UDP port to match |
| 994 | * @param type the match type. Should be either Type.UDP_SRC or |
| 995 | * Type.UDP_DST |
| 996 | */ |
| 997 | public UdpPortCriterion(Short udpPort, Type type) { |
| 998 | this.udpPort = udpPort; |
| 999 | this.type = type; |
| 1000 | } |
| 1001 | |
| 1002 | @Override |
| 1003 | public Type type() { |
| 1004 | return this.type; |
| 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * Gets the UDP port to match. |
| 1009 | * |
| 1010 | * @return the UDP port to match |
| 1011 | */ |
| 1012 | public Short udpPort() { |
| 1013 | return this.udpPort; |
| 1014 | } |
| 1015 | |
| 1016 | @Override |
| 1017 | public String toString() { |
| 1018 | return toStringHelper(type().toString()) |
| 1019 | .add("udpPort", udpPort & 0xffff).toString(); |
| 1020 | } |
| 1021 | |
| 1022 | @Override |
| 1023 | public int hashCode() { |
| 1024 | return Objects.hash(type, udpPort); |
| 1025 | } |
| 1026 | |
| 1027 | @Override |
| 1028 | public boolean equals(Object obj) { |
| 1029 | if (this == obj) { |
| 1030 | return true; |
| 1031 | } |
| 1032 | if (obj instanceof UdpPortCriterion) { |
| 1033 | UdpPortCriterion that = (UdpPortCriterion) obj; |
| 1034 | return Objects.equals(udpPort, that.udpPort) && |
| 1035 | Objects.equals(type, that.type); |
| 1036 | } |
| 1037 | return false; |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | /** |
| 1042 | * Implementation of SCTP port criterion. |
| 1043 | */ |
| 1044 | public static final class SctpPortCriterion implements Criterion { |
| 1045 | private final Short sctpPort; |
| 1046 | private final Type type; |
| 1047 | |
| 1048 | /** |
| 1049 | * Constructor. |
| 1050 | * |
| 1051 | * @param sctpPort the SCTP port to match |
| 1052 | * @param type the match type. Should be either Type.SCTP_SRC or |
| 1053 | * Type.SCTP_DST |
| 1054 | */ |
| 1055 | public SctpPortCriterion(Short sctpPort, Type type) { |
| 1056 | this.sctpPort = sctpPort; |
| 1057 | this.type = type; |
| 1058 | } |
| 1059 | |
| 1060 | @Override |
| 1061 | public Type type() { |
| 1062 | return this.type; |
| 1063 | } |
| 1064 | |
| 1065 | /** |
| 1066 | * Gets the SCTP port to match. |
| 1067 | * |
| 1068 | * @return the SCTP port to match |
| 1069 | */ |
| 1070 | public Short sctpPort() { |
| 1071 | return this.sctpPort; |
| 1072 | } |
| 1073 | |
| 1074 | @Override |
| 1075 | public String toString() { |
| 1076 | return toStringHelper(type().toString()) |
| 1077 | .add("sctpPort", sctpPort & 0xffff).toString(); |
| 1078 | } |
| 1079 | |
| 1080 | @Override |
| 1081 | public int hashCode() { |
| 1082 | return Objects.hash(type, sctpPort); |
| 1083 | } |
| 1084 | |
| 1085 | @Override |
| 1086 | public boolean equals(Object obj) { |
| 1087 | if (this == obj) { |
| 1088 | return true; |
| 1089 | } |
| 1090 | if (obj instanceof SctpPortCriterion) { |
| 1091 | SctpPortCriterion that = (SctpPortCriterion) obj; |
| 1092 | return Objects.equals(sctpPort, that.sctpPort) && |
| 1093 | Objects.equals(type, that.type); |
| 1094 | } |
| 1095 | return false; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * Implementation of ICMP type criterion. |
| 1101 | */ |
| 1102 | public static final class IcmpTypeCriterion implements Criterion { |
| 1103 | private final Byte icmpType; |
| 1104 | |
| 1105 | /** |
| 1106 | * Constructor. |
| 1107 | * |
| 1108 | * @param icmpType the ICMP type to match |
| 1109 | */ |
| 1110 | public IcmpTypeCriterion(Byte icmpType) { |
| 1111 | this.icmpType = icmpType; |
| 1112 | } |
| 1113 | |
| 1114 | @Override |
| 1115 | public Type type() { |
| 1116 | return Type.ICMPV4_TYPE; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * Gets the ICMP type to match. |
| 1121 | * |
| 1122 | * @return the ICMP type to match |
| 1123 | */ |
| 1124 | public Byte icmpType() { |
| 1125 | return icmpType; |
| 1126 | } |
| 1127 | |
| 1128 | @Override |
| 1129 | public String toString() { |
| 1130 | return toStringHelper(type().toString()) |
| 1131 | .add("icmpType", icmpType & 0xff).toString(); |
| 1132 | } |
| 1133 | |
| 1134 | @Override |
| 1135 | public int hashCode() { |
| 1136 | return Objects.hash(type(), icmpType); |
| 1137 | } |
| 1138 | |
| 1139 | @Override |
| 1140 | public boolean equals(Object obj) { |
| 1141 | if (this == obj) { |
| 1142 | return true; |
| 1143 | } |
| 1144 | if (obj instanceof IcmpTypeCriterion) { |
| 1145 | IcmpTypeCriterion that = (IcmpTypeCriterion) obj; |
| 1146 | return Objects.equals(icmpType, that.icmpType) && |
| 1147 | Objects.equals(this.type(), that.type()); |
| 1148 | } |
| 1149 | return false; |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | /** |
| 1154 | * Implementation of ICMP code criterion. |
| 1155 | */ |
| 1156 | public static final class IcmpCodeCriterion implements Criterion { |
| 1157 | private final Byte icmpCode; |
| 1158 | |
| 1159 | /** |
| 1160 | * Constructor. |
| 1161 | * |
| 1162 | * @param icmpCode the ICMP code to match |
| 1163 | */ |
| 1164 | public IcmpCodeCriterion(Byte icmpCode) { |
| 1165 | this.icmpCode = icmpCode; |
| 1166 | } |
| 1167 | |
| 1168 | @Override |
| 1169 | public Type type() { |
| 1170 | return Type.ICMPV4_CODE; |
| 1171 | } |
| 1172 | |
| 1173 | /** |
| 1174 | * Gets the ICMP code to match. |
| 1175 | * |
| 1176 | * @return the ICMP code to match |
| 1177 | */ |
| 1178 | public Byte icmpCode() { |
| 1179 | return icmpCode; |
| 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public String toString() { |
| 1184 | return toStringHelper(type().toString()) |
| 1185 | .add("icmpCode", icmpCode & 0xff).toString(); |
| 1186 | } |
| 1187 | |
| 1188 | @Override |
| 1189 | public int hashCode() { |
| 1190 | return Objects.hash(type(), icmpCode); |
| 1191 | } |
| 1192 | |
| 1193 | @Override |
| 1194 | public boolean equals(Object obj) { |
| 1195 | if (this == obj) { |
| 1196 | return true; |
| 1197 | } |
| 1198 | if (obj instanceof IcmpCodeCriterion) { |
| 1199 | IcmpCodeCriterion that = (IcmpCodeCriterion) obj; |
| 1200 | return Objects.equals(icmpCode, that.icmpCode) && |
| 1201 | Objects.equals(this.type(), that.type()); |
| 1202 | } |
| 1203 | return false; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | /** |
| 1208 | * Implementation of IPv6 Flow Label criterion (RFC 6437). |
| 1209 | */ |
| 1210 | public static final class IPv6FlowLabelCriterion implements Criterion { |
| 1211 | private static final int FLOW_LABEL_MASK = 0xfffff; |
| 1212 | private final Integer flowLabel; // IPv6 flow label: 20 bits |
| 1213 | |
| 1214 | /** |
| 1215 | * Constructor. |
| 1216 | * |
| 1217 | * @param flowLabel the IPv6 flow label to match |
| 1218 | */ |
| 1219 | public IPv6FlowLabelCriterion(Integer flowLabel) { |
| 1220 | this.flowLabel = flowLabel & FLOW_LABEL_MASK; |
| 1221 | } |
| 1222 | |
| 1223 | @Override |
| 1224 | public Type type() { |
| 1225 | return Type.IPV6_FLABEL; |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * Gets the IPv6 flow label to match. |
| 1230 | * |
| 1231 | * @return the IPv6 flow label to match |
| 1232 | */ |
| 1233 | public Integer flowLabel() { |
| 1234 | return flowLabel; |
| 1235 | } |
| 1236 | |
| 1237 | @Override |
| 1238 | public String toString() { |
| 1239 | return toStringHelper(type().toString()) |
| 1240 | .add("flowLabel", flowLabel).toString(); |
| 1241 | } |
| 1242 | |
| 1243 | @Override |
| 1244 | public int hashCode() { |
| 1245 | return Objects.hash(type(), flowLabel); |
| 1246 | } |
| 1247 | |
| 1248 | @Override |
| 1249 | public boolean equals(Object obj) { |
| 1250 | if (this == obj) { |
| 1251 | return true; |
| 1252 | } |
| 1253 | if (obj instanceof IPv6FlowLabelCriterion) { |
| 1254 | IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj; |
| 1255 | return Objects.equals(flowLabel, that.flowLabel) && |
| 1256 | Objects.equals(this.type(), that.type()); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 1257 | } |
| 1258 | return false; |
| 1259 | } |
| 1260 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1261 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 1262 | /** |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1263 | * Implementation of ICMPv6 type criterion. |
| 1264 | */ |
| 1265 | public static final class Icmpv6TypeCriterion implements Criterion { |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1266 | private final Byte icmpv6Type; |
| 1267 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1268 | /** |
| 1269 | * Constructor. |
| 1270 | * |
| 1271 | * @param icmpv6Type the ICMPv6 type to match |
| 1272 | */ |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1273 | public Icmpv6TypeCriterion(Byte icmpv6Type) { |
| 1274 | this.icmpv6Type = icmpv6Type; |
| 1275 | } |
| 1276 | |
| 1277 | @Override |
| 1278 | public Type type() { |
| 1279 | return Type.ICMPV6_TYPE; |
| 1280 | } |
| 1281 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1282 | /** |
| 1283 | * Gets the ICMPv6 type to match. |
| 1284 | * |
| 1285 | * @return the ICMPv6 type to match |
| 1286 | */ |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1287 | public Byte icmpv6Type() { |
| 1288 | return icmpv6Type; |
| 1289 | } |
| 1290 | |
| 1291 | @Override |
| 1292 | public String toString() { |
| 1293 | return toStringHelper(type().toString()) |
| 1294 | .add("icmpv6Type", icmpv6Type & 0xff).toString(); |
| 1295 | } |
| 1296 | |
| 1297 | @Override |
| 1298 | public int hashCode() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1299 | return Objects.hash(type(), icmpv6Type); |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | @Override |
| 1303 | public boolean equals(Object obj) { |
| 1304 | if (this == obj) { |
| 1305 | return true; |
| 1306 | } |
| 1307 | if (obj instanceof Icmpv6TypeCriterion) { |
| 1308 | Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj; |
| 1309 | return Objects.equals(icmpv6Type, that.icmpv6Type) && |
| 1310 | Objects.equals(this.type(), that.type()); |
| 1311 | } |
| 1312 | return false; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * Implementation of ICMPv6 code criterion. |
| 1318 | */ |
| 1319 | public static final class Icmpv6CodeCriterion implements Criterion { |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1320 | private final Byte icmpv6Code; |
| 1321 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1322 | /** |
| 1323 | * Constructor. |
| 1324 | * |
| 1325 | * @param icmpv6Code the ICMPv6 code to match |
| 1326 | */ |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1327 | public Icmpv6CodeCriterion(Byte icmpv6Code) { |
| 1328 | this.icmpv6Code = icmpv6Code; |
| 1329 | } |
| 1330 | |
| 1331 | @Override |
| 1332 | public Type type() { |
| 1333 | return Type.ICMPV6_CODE; |
| 1334 | } |
| 1335 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1336 | /** |
| 1337 | * Gets the ICMPv6 code to match. |
| 1338 | * |
| 1339 | * @return the ICMPv6 code to match |
| 1340 | */ |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1341 | public Byte icmpv6Code() { |
| 1342 | return icmpv6Code; |
| 1343 | } |
| 1344 | |
| 1345 | @Override |
| 1346 | public String toString() { |
| 1347 | return toStringHelper(type().toString()) |
| 1348 | .add("icmpv6Code", icmpv6Code & 0xff).toString(); |
| 1349 | } |
| 1350 | |
| 1351 | @Override |
| 1352 | public int hashCode() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1353 | return Objects.hash(type(), icmpv6Code); |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | @Override |
| 1357 | public boolean equals(Object obj) { |
| 1358 | if (this == obj) { |
| 1359 | return true; |
| 1360 | } |
| 1361 | if (obj instanceof Icmpv6CodeCriterion) { |
| 1362 | Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj; |
| 1363 | return Objects.equals(icmpv6Code, that.icmpv6Code) && |
| 1364 | Objects.equals(this.type(), that.type()); |
| 1365 | } |
| 1366 | return false; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1371 | * Implementation of IPv6 Neighbor Discovery target address criterion. |
| 1372 | */ |
| 1373 | public static final class IPv6NDTargetAddressCriterion |
| 1374 | implements Criterion { |
| 1375 | private final Ip6Address targetAddress; |
| 1376 | |
| 1377 | /** |
| 1378 | * Constructor. |
| 1379 | * |
| 1380 | * @param targetAddress the IPv6 target address to match |
| 1381 | */ |
| 1382 | public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) { |
| 1383 | this.targetAddress = targetAddress; |
| 1384 | } |
| 1385 | |
| 1386 | @Override |
| 1387 | public Type type() { |
| 1388 | return Type.IPV6_ND_TARGET; |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * Gets the IPv6 target address to match. |
| 1393 | * |
| 1394 | * @return the IPv6 target address to match |
| 1395 | */ |
| 1396 | public Ip6Address targetAddress() { |
| 1397 | return this.targetAddress; |
| 1398 | } |
| 1399 | |
| 1400 | @Override |
| 1401 | public String toString() { |
| 1402 | return toStringHelper(type().toString()) |
| 1403 | .add("targetAddress", targetAddress).toString(); |
| 1404 | } |
| 1405 | |
| 1406 | @Override |
| 1407 | public int hashCode() { |
| 1408 | return Objects.hash(type(), targetAddress); |
| 1409 | } |
| 1410 | |
| 1411 | @Override |
| 1412 | public boolean equals(Object obj) { |
| 1413 | if (this == obj) { |
| 1414 | return true; |
| 1415 | } |
| 1416 | if (obj instanceof IPv6NDTargetAddressCriterion) { |
| 1417 | IPv6NDTargetAddressCriterion that = |
| 1418 | (IPv6NDTargetAddressCriterion) obj; |
| 1419 | return Objects.equals(targetAddress, that.targetAddress) && |
| 1420 | Objects.equals(type(), that.type()); |
| 1421 | } |
| 1422 | return false; |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * Implementation of IPv6 Neighbor Discovery link-layer address criterion. |
| 1428 | */ |
| 1429 | public static final class IPv6NDLinkLayerAddressCriterion |
| 1430 | implements Criterion { |
| 1431 | private final MacAddress mac; |
| 1432 | private final Type type; |
| 1433 | |
| 1434 | /** |
| 1435 | * Constructor. |
| 1436 | * |
| 1437 | * @param mac the source or destination link-layer address to match |
| 1438 | * @param type the match type. Should be either Type.IPV6_ND_SLL or |
| 1439 | * Type.IPV6_ND_TLL |
| 1440 | */ |
| 1441 | public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) { |
| 1442 | this.mac = mac; |
| 1443 | this.type = type; |
| 1444 | } |
| 1445 | |
| 1446 | @Override |
| 1447 | public Type type() { |
| 1448 | return this.type; |
| 1449 | } |
| 1450 | |
| 1451 | /** |
| 1452 | * Gets the MAC link-layer address to match. |
| 1453 | * |
| 1454 | * @return the MAC link-layer address to match |
| 1455 | */ |
| 1456 | public MacAddress mac() { |
| 1457 | return this.mac; |
| 1458 | } |
| 1459 | |
| 1460 | @Override |
| 1461 | public String toString() { |
| 1462 | return toStringHelper(type().toString()) |
| 1463 | .add("mac", mac).toString(); |
| 1464 | } |
| 1465 | |
| 1466 | @Override |
| 1467 | public int hashCode() { |
| 1468 | return Objects.hash(type, mac); |
| 1469 | } |
| 1470 | |
| 1471 | @Override |
| 1472 | public boolean equals(Object obj) { |
| 1473 | if (this == obj) { |
| 1474 | return true; |
| 1475 | } |
| 1476 | if (obj instanceof IPv6NDLinkLayerAddressCriterion) { |
| 1477 | IPv6NDLinkLayerAddressCriterion that = |
| 1478 | (IPv6NDLinkLayerAddressCriterion) obj; |
| 1479 | return Objects.equals(mac, that.mac) && |
| 1480 | Objects.equals(type, that.type); |
| 1481 | } |
| 1482 | return false; |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /** |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 1487 | * Implementation of MPLS tag criterion. |
| 1488 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 1489 | public static final class MplsCriterion implements Criterion { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 1490 | private final Integer mplsLabel; |
| 1491 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1492 | /** |
| 1493 | * Constructor. |
| 1494 | * |
| 1495 | * @param mplsLabel the MPLS label to match |
| 1496 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 1497 | public MplsCriterion(Integer mplsLabel) { |
| 1498 | this.mplsLabel = mplsLabel; |
| 1499 | } |
| 1500 | |
| 1501 | @Override |
| 1502 | public Type type() { |
| 1503 | return Type.MPLS_LABEL; |
| 1504 | } |
| 1505 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1506 | /** |
| 1507 | * Gets the MPLS label to match. |
| 1508 | * |
| 1509 | * @return the MPLS label to match |
| 1510 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 1511 | public Integer label() { |
| 1512 | return mplsLabel; |
| 1513 | } |
| 1514 | |
| 1515 | @Override |
| 1516 | public String toString() { |
| 1517 | return toStringHelper(type().toString()) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1518 | .add("label", mplsLabel & 0xffffffffL).toString(); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | @Override |
| 1522 | public int hashCode() { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1523 | return Objects.hash(type(), mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | @Override |
| 1527 | public boolean equals(Object obj) { |
| 1528 | if (this == obj) { |
| 1529 | return true; |
| 1530 | } |
| 1531 | if (obj instanceof MplsCriterion) { |
| 1532 | MplsCriterion that = (MplsCriterion) obj; |
| 1533 | return Objects.equals(mplsLabel, that.mplsLabel) && |
| 1534 | Objects.equals(this.type(), that.type()); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 1535 | } |
| 1536 | return false; |
| 1537 | } |
| 1538 | |
| 1539 | } |
| 1540 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 1541 | /** |
| 1542 | * Implementation of lambda (wavelength) criterion. |
| 1543 | */ |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1544 | public static final class LambdaCriterion implements Criterion { |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1545 | private final short lambda; |
| 1546 | private final Type type; |
| 1547 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1548 | /** |
| 1549 | * Constructor. |
| 1550 | * |
| 1551 | * @param lambda the lambda (wavelength) to match |
| 1552 | * @param type the match type. Should be Type.OCH_SIGID |
| 1553 | */ |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1554 | public LambdaCriterion(short lambda, Type type) { |
| 1555 | this.lambda = lambda; |
| 1556 | this.type = type; |
| 1557 | } |
| 1558 | |
| 1559 | @Override |
| 1560 | public Type type() { |
| 1561 | return this.type; |
| 1562 | } |
| 1563 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1564 | /** |
| 1565 | * Gets the lambda (wavelength) to match. |
| 1566 | * |
| 1567 | * @return the lambda (wavelength) to match. |
| 1568 | */ |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1569 | public Short lambda() { |
| 1570 | return this.lambda; |
| 1571 | } |
| 1572 | |
| 1573 | @Override |
| 1574 | public String toString() { |
| 1575 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 1576 | .add("lambda", lambda & 0xffff).toString(); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | @Override |
| 1580 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 1581 | return Objects.hash(type, lambda); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | @Override |
| 1585 | public boolean equals(Object obj) { |
| 1586 | if (this == obj) { |
| 1587 | return true; |
| 1588 | } |
| 1589 | if (obj instanceof LambdaCriterion) { |
| 1590 | LambdaCriterion that = (LambdaCriterion) obj; |
| 1591 | return Objects.equals(lambda, that.lambda) && |
| 1592 | Objects.equals(type, that.type); |
| 1593 | } |
| 1594 | return false; |
| 1595 | } |
| 1596 | } |
| 1597 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 1598 | /** |
| 1599 | * Implementation of optical signal type criterion. |
| 1600 | */ |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 1601 | public static final class OpticalSignalTypeCriterion implements Criterion { |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 1602 | private final Short signalType; |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 1603 | private final Type type; |
| 1604 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1605 | /** |
| 1606 | * Constructor. |
| 1607 | * |
| 1608 | * @param signalType the optical signal type to match |
| 1609 | * @param type the match type. Should be Type.OCH_SIGTYPE |
| 1610 | */ |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 1611 | public OpticalSignalTypeCriterion(Short signalType, Type type) { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 1612 | this.signalType = signalType; |
| 1613 | this.type = type; |
| 1614 | } |
| 1615 | |
| 1616 | @Override |
| 1617 | public Type type() { |
| 1618 | return this.type; |
| 1619 | } |
| 1620 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 1621 | /** |
| 1622 | * Gets the optical signal type to match. |
| 1623 | * |
| 1624 | * @return the optical signal type to match |
| 1625 | */ |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 1626 | public Short signalType() { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 1627 | return this.signalType; |
| 1628 | } |
| 1629 | |
| 1630 | @Override |
| 1631 | public String toString() { |
| 1632 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 1633 | .add("signalType", signalType & 0xffff).toString(); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | @Override |
| 1637 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 1638 | return Objects.hash(type, signalType); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | @Override |
| 1642 | public boolean equals(Object obj) { |
| 1643 | if (this == obj) { |
| 1644 | return true; |
| 1645 | } |
| 1646 | if (obj instanceof OpticalSignalTypeCriterion) { |
| 1647 | OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj; |
| 1648 | return Objects.equals(signalType, that.signalType) && |
| 1649 | Objects.equals(type, that.type); |
| 1650 | } |
| 1651 | return false; |
| 1652 | } |
| 1653 | } |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 1654 | } |