Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 SCTP port criterion (16 bits unsigned integer). |
| 24 | */ |
| 25 | public final class SctpPortCriterion implements Criterion { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 26 | private final TpPort sctpPort; |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 27 | private final TpPort mask; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 28 | private final Type type; |
| 29 | |
| 30 | /** |
| 31 | * Constructor. |
| 32 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 33 | * @param sctpPort the SCTP port to match |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 34 | * @param mask the mask for the SCTP port |
| 35 | * @param type the match type. Should be either Type.SCTP_SRC_MASKED or |
| 36 | * Type.SCTP_SRC_DST_MASKED |
| 37 | */ |
| 38 | SctpPortCriterion(TpPort sctpPort, TpPort mask, Type type) { |
| 39 | this.sctpPort = sctpPort; |
| 40 | this.mask = mask; |
| 41 | this.type = type; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Constructor. |
| 46 | * |
| 47 | * @param sctpPort the SCTP port to match |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 48 | * @param type the match type. Should be either Type.SCTP_SRC or |
| 49 | * Type.SCTP_DST |
| 50 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 51 | SctpPortCriterion(TpPort sctpPort, Type type) { |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 52 | this(sctpPort, null, type); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public Type type() { |
| 57 | return this.type; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Gets the SCTP port to match. |
| 62 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 63 | * @return the SCTP port to match |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 64 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 65 | public TpPort sctpPort() { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 66 | return this.sctpPort; |
| 67 | } |
| 68 | |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 69 | /** |
| 70 | * Gets the mask for the SCTP port to match. |
| 71 | * |
| 72 | * @return the SCTP port mask, null if not specified |
| 73 | */ |
| 74 | public TpPort mask() { |
| 75 | return this.mask; |
| 76 | } |
| 77 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 78 | @Override |
| 79 | public String toString() { |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 80 | return (mask != null) ? |
| 81 | type().toString() + SEPARATOR + sctpPort + "/" + mask : |
| 82 | type().toString() + SEPARATOR + sctpPort; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public int hashCode() { |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 87 | return Objects.hash(type.ordinal(), sctpPort, mask); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public boolean equals(Object obj) { |
| 92 | if (this == obj) { |
| 93 | return true; |
| 94 | } |
| 95 | if (obj instanceof SctpPortCriterion) { |
| 96 | SctpPortCriterion that = (SctpPortCriterion) obj; |
| 97 | return Objects.equals(sctpPort, that.sctpPort) && |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 98 | Objects.equals(mask, that.mask) && |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 99 | Objects.equals(type, that.type); |
| 100 | } |
| 101 | return false; |
| 102 | } |
| 103 | } |