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