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