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