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