Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.net.flow.criteria; |
| 17 | |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 18 | import org.onlab.packet.TpPort; |
| 19 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Implementation of TCP port criterion (16 bits unsigned integer). |
| 24 | */ |
| 25 | public final class TcpPortCriterion implements Criterion { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 26 | private final TpPort tcpPort; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 27 | private final Type type; |
| 28 | |
| 29 | /** |
| 30 | * Constructor. |
| 31 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 32 | * @param tcpPort the TCP port to match |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 33 | * @param type the match type. Should be either Type.TCP_SRC or |
| 34 | * Type.TCP_DST |
| 35 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 36 | TcpPortCriterion(TpPort tcpPort, Type type) { |
| 37 | this.tcpPort = tcpPort; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 38 | this.type = type; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public Type type() { |
| 43 | return this.type; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Gets the TCP port to match. |
| 48 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 49 | * @return the TCP port to match |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 50 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 51 | public TpPort tcpPort() { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 52 | return this.tcpPort; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 57 | return type().toString() + SEPARATOR + tcpPort; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 62 | return Objects.hash(type().ordinal(), tcpPort); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean equals(Object obj) { |
| 67 | if (this == obj) { |
| 68 | return true; |
| 69 | } |
| 70 | if (obj instanceof TcpPortCriterion) { |
| 71 | TcpPortCriterion that = (TcpPortCriterion) obj; |
| 72 | return Objects.equals(tcpPort, that.tcpPort) && |
| 73 | Objects.equals(type, that.type); |
| 74 | } |
| 75 | return false; |
| 76 | } |
| 77 | } |