Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 19 | package org.onlab.onos.net.flow.criteria; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 20 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 23 | import java.util.Objects; |
| 24 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 25 | import org.onlab.onos.net.PortNumber; |
| 26 | import org.onlab.onos.net.flow.criteria.Criterion.Type; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 27 | import org.onlab.packet.IpPrefix; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 28 | import org.onlab.packet.MacAddress; |
| 29 | import org.onlab.packet.VlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 30 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Factory class to create various traffic selection criteria. |
| 33 | */ |
| 34 | public final class Criteria { |
| 35 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 36 | //TODO: incomplete type implementation. Need to implement complete list from Criterion |
| 37 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 38 | // Ban construction |
| 39 | private Criteria() { |
| 40 | } |
| 41 | |
| 42 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 43 | * Creates a match on IN_PORT field using the specified value. |
| 44 | * |
| 45 | * @param port inport value |
| 46 | * @return match criterion |
| 47 | */ |
| 48 | public static Criterion matchInPort(PortNumber port) { |
| 49 | return new PortCriterion(port); |
| 50 | } |
| 51 | |
| 52 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 53 | * Creates a match on ETH_SRC field using the specified value. This value |
| 54 | * may be a wildcard mask. |
| 55 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 56 | * @param mac MAC address value or wildcard mask |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 57 | * @return match criterion |
| 58 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 59 | public static Criterion matchEthSrc(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 60 | return new EthCriterion(mac, Type.ETH_SRC); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 61 | } |
| 62 | |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Creates a match on ETH_DST field using the specified value. This value |
| 65 | * may be a wildcard mask. |
| 66 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 67 | * @param mac MAC address value or wildcard mask |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 68 | * @return match criterion |
| 69 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 70 | public static Criterion matchEthDst(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 71 | return new EthCriterion(mac, Type.ETH_DST); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Creates a match on ETH_TYPE field using the specified value. |
| 76 | * |
| 77 | * @param ethType eth type value |
| 78 | * @return match criterion |
| 79 | */ |
| 80 | public static Criterion matchEthType(Short ethType) { |
| 81 | return new EthTypeCriterion(ethType); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Creates a match on VLAN ID field using the specified value. |
| 86 | * |
| 87 | * @param vlanId vlan id value |
| 88 | * @return match criterion |
| 89 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 90 | public static Criterion matchVlanId(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 91 | return new VlanIdCriterion(vlanId); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Creates a match on VLAN PCP field using the specified value. |
| 96 | * |
| 97 | * @param vlanPcp vlan pcp value |
| 98 | * @return match criterion |
| 99 | */ |
alshabib | b45d196 | 2014-09-18 14:25:45 -0700 | [diff] [blame] | 100 | public static Criterion matchVlanPcp(Byte vlanPcp) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 101 | return new VlanPcpCriterion(vlanPcp); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Creates a match on IP proto field using the specified value. |
| 106 | * |
| 107 | * @param proto ip protocol value |
| 108 | * @return match criterion |
| 109 | */ |
| 110 | public static Criterion matchIPProtocol(Byte proto) { |
| 111 | return new IPProtocolCriterion(proto); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Creates a match on IP src field using the specified value. |
| 116 | * |
| 117 | * @param ip ip src value |
| 118 | * @return match criterion |
| 119 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 120 | public static Criterion matchIPSrc(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 121 | return new IPCriterion(ip, Type.IPV4_SRC); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Creates a match on IP dst field using the specified value. |
| 126 | * |
| 127 | * @param ip ip src value |
| 128 | * @return match criterion |
| 129 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 130 | public static Criterion matchIPDst(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 131 | return new IPCriterion(ip, Type.IPV4_DST); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 134 | /** |
| 135 | * Creates a match on TCP source port field using the specified value. |
| 136 | * |
| 137 | * @param tcpPort |
| 138 | * @return match criterion |
| 139 | */ |
| 140 | public static Criterion matchTcpSrc(Short tcpPort) { |
| 141 | return new TcpPortCriterion(tcpPort, Type.TCP_SRC); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Creates a match on TCP destination port field using the specified value. |
| 146 | * |
| 147 | * @param tcpPort |
| 148 | * @return match criterion |
| 149 | */ |
| 150 | public static Criterion matchTcpDst(Short tcpPort) { |
| 151 | return new TcpPortCriterion(tcpPort, Type.TCP_DST); |
| 152 | } |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 153 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame^] | 154 | /** |
| 155 | * Creates a match on lambda field using the specified value. |
| 156 | * |
| 157 | * @param lambda |
| 158 | * @return match criterion |
| 159 | */ |
| 160 | public static Criterion matchLambda(Short lambda) { |
| 161 | return new LambdaCriterion(lambda, Type.OCH_SIGID); |
| 162 | } |
| 163 | |
| 164 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 165 | * Implementations of criteria. |
| 166 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 167 | public static final class PortCriterion implements Criterion { |
| 168 | private final PortNumber port; |
| 169 | |
| 170 | public PortCriterion(PortNumber port) { |
| 171 | this.port = port; |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public Type type() { |
| 176 | return Type.IN_PORT; |
| 177 | } |
| 178 | |
| 179 | public PortNumber port() { |
| 180 | return this.port; |
| 181 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 182 | |
| 183 | @Override |
| 184 | public String toString() { |
| 185 | return toStringHelper(type().toString()) |
| 186 | .add("port", port).toString(); |
| 187 | } |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 188 | |
| 189 | @Override |
| 190 | public int hashCode() { |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 191 | return Objects.hash(port, type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public boolean equals(Object obj) { |
| 196 | if (this == obj) { |
| 197 | return true; |
| 198 | } |
| 199 | if (obj instanceof PortCriterion) { |
| 200 | PortCriterion that = (PortCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 201 | return Objects.equals(port, that.port) && |
| 202 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 203 | |
| 204 | } |
| 205 | return false; |
| 206 | } |
| 207 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
| 211 | public static final class EthCriterion implements Criterion { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 212 | private final MacAddress mac; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 213 | private final Type type; |
| 214 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 215 | public EthCriterion(MacAddress mac, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 216 | this.mac = mac; |
| 217 | this.type = type; |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public Type type() { |
| 222 | return this.type; |
| 223 | } |
| 224 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 225 | public MacAddress mac() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 226 | return this.mac; |
| 227 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 228 | |
| 229 | @Override |
| 230 | public String toString() { |
| 231 | return toStringHelper(type().toString()) |
| 232 | .add("mac", mac).toString(); |
| 233 | } |
| 234 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 235 | @Override |
| 236 | public int hashCode() { |
| 237 | return Objects.hash(mac, type); |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public boolean equals(Object obj) { |
| 242 | if (this == obj) { |
| 243 | return true; |
| 244 | } |
| 245 | if (obj instanceof EthCriterion) { |
| 246 | EthCriterion that = (EthCriterion) obj; |
| 247 | return Objects.equals(mac, that.mac) && |
| 248 | Objects.equals(type, that.type); |
| 249 | |
| 250 | |
| 251 | } |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | public static final class EthTypeCriterion implements Criterion { |
| 259 | |
| 260 | private final Short ethType; |
| 261 | |
| 262 | public EthTypeCriterion(Short ethType) { |
| 263 | this.ethType = ethType; |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public Type type() { |
| 268 | return Type.ETH_TYPE; |
| 269 | } |
| 270 | |
| 271 | public Short ethType() { |
| 272 | return ethType; |
| 273 | } |
| 274 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 275 | @Override |
| 276 | public String toString() { |
| 277 | return toStringHelper(type().toString()) |
| 278 | .add("ethType", Long.toHexString(ethType)).toString(); |
| 279 | } |
| 280 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 281 | @Override |
| 282 | public int hashCode() { |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 283 | return Objects.hash(ethType, type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public boolean equals(Object obj) { |
| 288 | if (this == obj) { |
| 289 | return true; |
| 290 | } |
| 291 | if (obj instanceof EthTypeCriterion) { |
| 292 | EthTypeCriterion that = (EthTypeCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 293 | return Objects.equals(ethType, that.ethType) && |
| 294 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 295 | |
| 296 | |
| 297 | } |
| 298 | return false; |
| 299 | } |
| 300 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | |
| 304 | public static final class IPCriterion implements Criterion { |
| 305 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 306 | private final IpPrefix ip; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 307 | private final Type type; |
| 308 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 309 | public IPCriterion(IpPrefix ip, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 310 | this.ip = ip; |
| 311 | this.type = type; |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public Type type() { |
| 316 | return this.type; |
| 317 | } |
| 318 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 319 | public IpPrefix ip() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 320 | return this.ip; |
| 321 | } |
| 322 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 323 | @Override |
| 324 | public String toString() { |
| 325 | return toStringHelper(type().toString()) |
| 326 | .add("ip", ip).toString(); |
| 327 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 328 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 329 | @Override |
| 330 | public int hashCode() { |
| 331 | return Objects.hash(ip, type); |
| 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public boolean equals(Object obj) { |
| 336 | if (this == obj) { |
| 337 | return true; |
| 338 | } |
| 339 | if (obj instanceof IPCriterion) { |
| 340 | IPCriterion that = (IPCriterion) obj; |
| 341 | return Objects.equals(ip, that.ip) && |
| 342 | Objects.equals(type, that.type); |
| 343 | |
| 344 | |
| 345 | } |
| 346 | return false; |
| 347 | } |
| 348 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
| 352 | public static final class IPProtocolCriterion implements Criterion { |
| 353 | |
| 354 | private final Byte proto; |
| 355 | |
| 356 | public IPProtocolCriterion(Byte protocol) { |
| 357 | this.proto = protocol; |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public Type type() { |
| 362 | return Type.IP_PROTO; |
| 363 | } |
| 364 | |
| 365 | public Byte protocol() { |
| 366 | return proto; |
| 367 | } |
| 368 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 369 | @Override |
| 370 | public String toString() { |
| 371 | return toStringHelper(type().toString()) |
| 372 | .add("protocol", Long.toHexString(proto)).toString(); |
| 373 | } |
| 374 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 375 | @Override |
| 376 | public int hashCode() { |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 377 | return Objects.hash(proto, type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | @Override |
| 381 | public boolean equals(Object obj) { |
| 382 | if (this == obj) { |
| 383 | return true; |
| 384 | } |
| 385 | if (obj instanceof IPProtocolCriterion) { |
| 386 | IPProtocolCriterion that = (IPProtocolCriterion) obj; |
| 387 | return Objects.equals(proto, that.proto); |
| 388 | |
| 389 | |
| 390 | } |
| 391 | return false; |
| 392 | } |
| 393 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | |
| 397 | public static final class VlanPcpCriterion implements Criterion { |
| 398 | |
| 399 | private final Byte vlanPcp; |
| 400 | |
| 401 | public VlanPcpCriterion(Byte vlanPcp) { |
| 402 | this.vlanPcp = vlanPcp; |
| 403 | } |
| 404 | |
| 405 | @Override |
| 406 | public Type type() { |
| 407 | return Type.VLAN_PCP; |
| 408 | } |
| 409 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 410 | public Byte priority() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 411 | return vlanPcp; |
| 412 | } |
| 413 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 414 | @Override |
| 415 | public String toString() { |
| 416 | return toStringHelper(type().toString()) |
| 417 | .add("pcp", Long.toHexString(vlanPcp)).toString(); |
| 418 | } |
| 419 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 420 | @Override |
| 421 | public int hashCode() { |
| 422 | return Objects.hash(vlanPcp); |
| 423 | } |
| 424 | |
| 425 | @Override |
| 426 | public boolean equals(Object obj) { |
| 427 | if (this == obj) { |
| 428 | return true; |
| 429 | } |
| 430 | if (obj instanceof VlanPcpCriterion) { |
| 431 | VlanPcpCriterion that = (VlanPcpCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 432 | return Objects.equals(vlanPcp, that.vlanPcp) && |
| 433 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 434 | |
| 435 | |
| 436 | } |
| 437 | return false; |
| 438 | } |
| 439 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | |
| 443 | public static final class VlanIdCriterion implements Criterion { |
| 444 | |
| 445 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 446 | private final VlanId vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 447 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 448 | public VlanIdCriterion(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 449 | this.vlanId = vlanId; |
| 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public Type type() { |
| 454 | return Type.VLAN_VID; |
| 455 | } |
| 456 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 457 | public VlanId vlanId() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 458 | return vlanId; |
| 459 | } |
| 460 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 461 | @Override |
| 462 | public String toString() { |
| 463 | return toStringHelper(type().toString()) |
| 464 | .add("id", vlanId).toString(); |
| 465 | } |
| 466 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 467 | @Override |
| 468 | public int hashCode() { |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 469 | return Objects.hash(vlanId, type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | @Override |
| 473 | public boolean equals(Object obj) { |
| 474 | if (this == obj) { |
| 475 | return true; |
| 476 | } |
| 477 | if (obj instanceof VlanIdCriterion) { |
| 478 | VlanIdCriterion that = (VlanIdCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 479 | return Objects.equals(vlanId, that.vlanId) && |
| 480 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 481 | |
| 482 | |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 490 | public static final class TcpPortCriterion implements Criterion { |
| 491 | |
| 492 | private final Short tcpPort; |
| 493 | private final Type type; |
| 494 | |
| 495 | public TcpPortCriterion(Short tcpPort, Type type) { |
| 496 | this.tcpPort = tcpPort; |
| 497 | this.type = type; |
| 498 | } |
| 499 | |
| 500 | @Override |
| 501 | public Type type() { |
| 502 | return this.type; |
| 503 | } |
| 504 | |
| 505 | public Short tcpPort() { |
| 506 | return this.tcpPort; |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public String toString() { |
| 511 | return toStringHelper(type().toString()) |
| 512 | .add("tcpPort", tcpPort).toString(); |
| 513 | } |
| 514 | |
| 515 | @Override |
| 516 | public int hashCode() { |
| 517 | return Objects.hash(tcpPort, type); |
| 518 | } |
| 519 | |
| 520 | @Override |
| 521 | public boolean equals(Object obj) { |
| 522 | if (this == obj) { |
| 523 | return true; |
| 524 | } |
| 525 | if (obj instanceof TcpPortCriterion) { |
| 526 | TcpPortCriterion that = (TcpPortCriterion) obj; |
| 527 | return Objects.equals(tcpPort, that.tcpPort) && |
| 528 | Objects.equals(type, that.type); |
| 529 | |
| 530 | |
| 531 | } |
| 532 | return false; |
| 533 | } |
| 534 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame^] | 535 | |
| 536 | public static final class LambdaCriterion implements Criterion { |
| 537 | |
| 538 | private final short lambda; |
| 539 | private final Type type; |
| 540 | |
| 541 | public LambdaCriterion(short lambda, Type type) { |
| 542 | this.lambda = lambda; |
| 543 | this.type = type; |
| 544 | } |
| 545 | |
| 546 | @Override |
| 547 | public Type type() { |
| 548 | return this.type; |
| 549 | } |
| 550 | |
| 551 | public Short lambda() { |
| 552 | return this.lambda; |
| 553 | } |
| 554 | |
| 555 | @Override |
| 556 | public String toString() { |
| 557 | return toStringHelper(type().toString()) |
| 558 | .add("lambda", lambda).toString(); |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public int hashCode() { |
| 563 | return Objects.hash(lambda, type); |
| 564 | } |
| 565 | |
| 566 | @Override |
| 567 | public boolean equals(Object obj) { |
| 568 | if (this == obj) { |
| 569 | return true; |
| 570 | } |
| 571 | if (obj instanceof LambdaCriterion) { |
| 572 | LambdaCriterion that = (LambdaCriterion) obj; |
| 573 | return Objects.equals(lambda, that.lambda) && |
| 574 | Objects.equals(type, that.type); |
| 575 | } |
| 576 | return false; |
| 577 | } |
| 578 | } |
| 579 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 580 | } |