Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 18 | import org.onlab.packet.EthType; |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 19 | import org.onlab.packet.Ip4Address; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 20 | import org.onlab.packet.Ip6Address; |
| 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.MplsLabel; |
| 24 | import org.onlab.packet.TpPort; |
| 25 | import org.onlab.packet.VlanId; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 27 | import org.onosproject.net.Lambda; |
| 28 | import org.onosproject.net.OchSignal; |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 29 | import org.onosproject.net.OchSignalType; |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 30 | import org.onosproject.net.OduSignalId; |
| 31 | import org.onosproject.net.OduSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.net.PortNumber; |
| 33 | import org.onosproject.net.flow.criteria.Criterion.Type; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 34 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Factory class to create various traffic selection criteria. |
| 37 | */ |
| 38 | public final class Criteria { |
| 39 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 40 | //TODO: incomplete type implementation. Need to implement complete list from Criterion |
| 41 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 42 | // Ban construction |
| 43 | private Criteria() { |
| 44 | } |
| 45 | |
| 46 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 47 | * Creates a match on IN_PORT field using the specified value. |
| 48 | * |
| 49 | * @param port inport value |
| 50 | * @return match criterion |
| 51 | */ |
| 52 | public static Criterion matchInPort(PortNumber port) { |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 53 | return new PortCriterion(port, Type.IN_PORT); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Creates a match on IN_PHY_PORT field using the specified value. |
| 58 | * |
| 59 | * @param port inport value |
| 60 | * @return match criterion |
| 61 | */ |
| 62 | public static Criterion matchInPhyPort(PortNumber port) { |
| 63 | return new PortCriterion(port, Type.IN_PHY_PORT); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Creates a match on METADATA field using the specified value. |
| 68 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 69 | * @param metadata metadata value (64 bits data) |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 70 | * @return match criterion |
| 71 | */ |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 72 | public static Criterion matchMetadata(long metadata) { |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 73 | return new MetadataCriterion(metadata); |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 77 | * Creates a match on ETH_DST field using the specified value. This value |
| 78 | * may be a wildcard mask. |
| 79 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 80 | * @param mac MAC address value or wildcard mask |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 81 | * @return match criterion |
| 82 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 83 | public static Criterion matchEthDst(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 84 | return new EthCriterion(mac, Type.ETH_DST); |
| 85 | } |
| 86 | |
| 87 | /** |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 88 | * Creates a masked match on ETH_DST field using the specified value and mask. |
| 89 | * |
| 90 | * @param mac MAC address value |
| 91 | * @param mask MAC address masking |
| 92 | * @return match criterion |
| 93 | */ |
| 94 | public static Criterion matchEthDstMasked(MacAddress mac, MacAddress mask) { |
| 95 | return new EthCriterion(mac, mask, Type.ETH_DST_MASKED); |
| 96 | } |
| 97 | |
| 98 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 99 | * Creates a match on ETH_SRC field using the specified value. This value |
| 100 | * may be a wildcard mask. |
| 101 | * |
| 102 | * @param mac MAC address value or wildcard mask |
| 103 | * @return match criterion |
| 104 | */ |
| 105 | public static Criterion matchEthSrc(MacAddress mac) { |
| 106 | return new EthCriterion(mac, Type.ETH_SRC); |
| 107 | } |
| 108 | |
| 109 | /** |
Saurav Das | 9d6c86b | 2016-02-19 09:01:07 -0800 | [diff] [blame] | 110 | * Creates a masked match on ETH_SRC field using the specified value and mask. |
| 111 | * |
| 112 | * @param mac MAC address value |
| 113 | * @param mask MAC address masking |
| 114 | * @return match criterion |
| 115 | */ |
| 116 | public static Criterion matchEthSrcMasked(MacAddress mac, MacAddress mask) { |
| 117 | return new EthCriterion(mac, mask, Type.ETH_SRC_MASKED); |
| 118 | } |
| 119 | |
| 120 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 121 | * Creates a match on ETH_TYPE field using the specified value. |
| 122 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 123 | * @param ethType eth type value (16 bits unsigned integer) |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 124 | * @return match criterion |
| 125 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 126 | public static Criterion matchEthType(int ethType) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 127 | return new EthTypeCriterion(ethType); |
| 128 | } |
| 129 | |
| 130 | /** |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 131 | * Creates a match on ETH_TYPE field using the specified value. |
| 132 | * |
| 133 | * @param ethType eth type value |
| 134 | * @return match criterion |
| 135 | */ |
| 136 | public static Criterion matchEthType(EthType ethType) { |
| 137 | return new EthTypeCriterion(ethType); |
| 138 | } |
| 139 | |
| 140 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 141 | * Creates a match on VLAN ID field using the specified value. |
| 142 | * |
| 143 | * @param vlanId vlan id value |
| 144 | * @return match criterion |
| 145 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 146 | public static Criterion matchVlanId(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 147 | return new VlanIdCriterion(vlanId); |
| 148 | } |
| 149 | |
| 150 | /** |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 151 | * Creates a match on the inner VLAN ID field using the specified value. |
| 152 | * |
| 153 | * @param vlanId vlan id value |
| 154 | * @return match criterion |
| 155 | */ |
| 156 | public static Criterion matchInnerVlanId(VlanId vlanId) { |
| 157 | return new VlanIdCriterion(vlanId, Type.INNER_VLAN_VID); |
| 158 | } |
| 159 | |
| 160 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 161 | * Creates a match on VLAN PCP field using the specified value. |
| 162 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 163 | * @param vlanPcp vlan pcp value (3 bits) |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 164 | * @return match criterion |
| 165 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 166 | public static Criterion matchVlanPcp(byte vlanPcp) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 167 | return new VlanPcpCriterion(vlanPcp); |
| 168 | } |
| 169 | |
| 170 | /** |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 171 | * Creates a match on the inner VLAN PCP field using the specified value. |
| 172 | * |
| 173 | * @param vlanPcp vlan pcp value (3 bits) |
| 174 | * @return match criterion |
| 175 | */ |
| 176 | public static Criterion matchInnerVlanPcp(byte vlanPcp) { |
| 177 | return new VlanPcpCriterion(vlanPcp, Type.INNER_VLAN_PCP); |
| 178 | } |
| 179 | |
| 180 | /** |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 181 | * Creates a match on IP DSCP field using the specified value. |
| 182 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 183 | * @param ipDscp ip dscp value (6 bits) |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 184 | * @return match criterion |
| 185 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 186 | public static Criterion matchIPDscp(byte ipDscp) { |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 187 | return new IPDscpCriterion(ipDscp); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Creates a match on IP ECN field using the specified value. |
| 192 | * |
Pavlin Radoslavov | ab8553a | 2015-02-20 14:13:50 -0800 | [diff] [blame] | 193 | * @param ipEcn ip ecn value (2 bits) |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 194 | * @return match criterion |
| 195 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 196 | public static Criterion matchIPEcn(byte ipEcn) { |
Pavlin Radoslavov | d0fd841 | 2015-02-04 13:57:00 -0800 | [diff] [blame] | 197 | return new IPEcnCriterion(ipEcn); |
| 198 | } |
| 199 | |
| 200 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 201 | * Creates a match on IP proto field using the specified value. |
| 202 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 203 | * @param proto ip protocol value (8 bits unsigned integer) |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 204 | * @return match criterion |
| 205 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 206 | public static Criterion matchIPProtocol(short proto) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 207 | return new IPProtocolCriterion(proto); |
| 208 | } |
| 209 | |
| 210 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 211 | * Creates a match on IPv4 source field using the specified value. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 212 | * |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 213 | * @param ip ipv4 source value |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 214 | * @return match criterion |
| 215 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 216 | public static Criterion matchIPSrc(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 217 | return new IPCriterion(ip, Type.IPV4_SRC); |
| 218 | } |
| 219 | |
| 220 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 221 | * Creates a match on IPv4 destination field using the specified value. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 222 | * |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 223 | * @param ip ipv4 source value |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 224 | * @return match criterion |
| 225 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 226 | public static Criterion matchIPDst(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 227 | return new IPCriterion(ip, Type.IPV4_DST); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 230 | /** |
| 231 | * Creates a match on TCP source port field using the specified value. |
| 232 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 233 | * @param tcpPort TCP source port |
| 234 | * @return match criterion |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 235 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 236 | public static Criterion matchTcpSrc(TpPort tcpPort) { |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 237 | return new TcpPortCriterion(tcpPort, Type.TCP_SRC); |
| 238 | } |
| 239 | |
| 240 | /** |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 241 | * Creates a masked match on TCP source port field using the specified value and mask. |
| 242 | * |
| 243 | * @param tcpPort TCP source port |
| 244 | * @param mask TCP source port masking |
| 245 | * @return match criterion |
| 246 | */ |
| 247 | public static Criterion matchTcpSrcMasked(TpPort tcpPort, TpPort mask) { |
| 248 | return new TcpPortCriterion(tcpPort, mask, Type.TCP_SRC_MASKED); |
| 249 | } |
| 250 | |
| 251 | /** |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 252 | * Creates a match on TCP destination port field using the specified value. |
| 253 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 254 | * @param tcpPort TCP destination port |
| 255 | * @return match criterion |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 256 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 257 | public static Criterion matchTcpDst(TpPort tcpPort) { |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 258 | return new TcpPortCriterion(tcpPort, Type.TCP_DST); |
| 259 | } |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 260 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 261 | /** |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 262 | * Creates a masked match on TCP destination port field using the specified value and mask. |
| 263 | * |
| 264 | * @param tcpPort TCP destination port |
| 265 | * @param mask TCP destination port masking |
| 266 | * @return match criterion |
| 267 | */ |
| 268 | public static Criterion matchTcpDstMasked(TpPort tcpPort, TpPort mask) { |
| 269 | return new TcpPortCriterion(tcpPort, mask, Type.TCP_DST_MASKED); |
| 270 | } |
| 271 | |
| 272 | /** |
Jian Li | 2748b2c | 2015-11-30 11:43:09 -0800 | [diff] [blame] | 273 | * Creates a match on TCP flags using the specified value. |
| 274 | * |
| 275 | * @param flags TCP flags |
| 276 | * @return match criterion |
| 277 | */ |
| 278 | public static Criterion matchTcpFlags(int flags) { |
| 279 | return new TcpFlagsCriterion(flags); |
| 280 | } |
| 281 | |
| 282 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 283 | * Creates a match on UDP source port field using the specified value. |
| 284 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 285 | * @param udpPort UDP source port |
| 286 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 287 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 288 | public static Criterion matchUdpSrc(TpPort udpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 289 | return new UdpPortCriterion(udpPort, Type.UDP_SRC); |
| 290 | } |
| 291 | |
| 292 | /** |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 293 | * Creates a masked match on UDP source port field using the specified value and mask. |
| 294 | * |
| 295 | * @param udpPort UDP source port |
| 296 | * @param mask UDP source port masking |
| 297 | * @return match criterion |
| 298 | */ |
| 299 | public static Criterion matchUdpSrcMasked(TpPort udpPort, TpPort mask) { |
| 300 | return new UdpPortCriterion(udpPort, mask, Type.UDP_SRC_MASKED); |
| 301 | } |
| 302 | |
| 303 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 304 | * Creates a match on UDP destination port field using the specified value. |
| 305 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 306 | * @param udpPort UDP destination port |
| 307 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 308 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 309 | public static Criterion matchUdpDst(TpPort udpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 310 | return new UdpPortCriterion(udpPort, Type.UDP_DST); |
| 311 | } |
| 312 | |
| 313 | /** |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 314 | * Creates a masked match on UDP destination port field using the specified value and mask. |
| 315 | * |
| 316 | * @param udpPort UDP destination port |
| 317 | * @param mask UDP destination port masking |
| 318 | * @return match criterion |
| 319 | */ |
| 320 | public static Criterion matchUdpDstMasked(TpPort udpPort, TpPort mask) { |
| 321 | return new UdpPortCriterion(udpPort, mask, Type.UDP_DST_MASKED); |
| 322 | } |
| 323 | |
| 324 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 325 | * Creates a match on SCTP source port field using the specified value. |
| 326 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 327 | * @param sctpPort SCTP source port |
| 328 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 329 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 330 | public static Criterion matchSctpSrc(TpPort sctpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 331 | return new SctpPortCriterion(sctpPort, Type.SCTP_SRC); |
| 332 | } |
| 333 | |
| 334 | /** |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 335 | * Creates a masked match on SCTP source port field using the specified value and mask. |
| 336 | * |
| 337 | * @param sctpPort SCTP source port |
| 338 | * @param mask SCTP source port masking |
| 339 | * @return match criterion |
| 340 | */ |
| 341 | public static Criterion matchSctpSrcMasked(TpPort sctpPort, TpPort mask) { |
| 342 | return new SctpPortCriterion(sctpPort, mask, Type.SCTP_SRC_MASKED); |
| 343 | } |
| 344 | |
| 345 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 346 | * Creates a match on SCTP destination port field using the specified |
| 347 | * value. |
| 348 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 349 | * @param sctpPort SCTP destination port |
| 350 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 351 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 352 | public static Criterion matchSctpDst(TpPort sctpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 353 | return new SctpPortCriterion(sctpPort, Type.SCTP_DST); |
| 354 | } |
| 355 | |
| 356 | /** |
Andreas Gilbert | 75b882f7 | 2017-02-03 09:58:07 +0100 | [diff] [blame] | 357 | * Creates a masked match on SCTP destination port field using the specified value and mask. |
| 358 | * |
| 359 | * @param sctpPort SCTP destination port |
| 360 | * @param mask SCTP destination port masking |
| 361 | * @return match criterion |
| 362 | */ |
| 363 | public static Criterion matchSctpDstMasked(TpPort sctpPort, TpPort mask) { |
| 364 | return new SctpPortCriterion(sctpPort, mask, Type.SCTP_DST_MASKED); |
| 365 | } |
| 366 | |
| 367 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 368 | * Creates a match on ICMP type field using the specified value. |
| 369 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 370 | * @param icmpType ICMP type (8 bits unsigned integer) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 371 | * @return match criterion |
| 372 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 373 | public static Criterion matchIcmpType(short icmpType) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 374 | return new IcmpTypeCriterion(icmpType); |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Creates a match on ICMP code field using the specified value. |
| 379 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 380 | * @param icmpCode ICMP code (8 bits unsigned integer) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 381 | * @return match criterion |
| 382 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 383 | public static Criterion matchIcmpCode(short icmpCode) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 384 | return new IcmpCodeCriterion(icmpCode); |
| 385 | } |
| 386 | |
| 387 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 388 | * Creates a match on IPv6 source field using the specified value. |
| 389 | * |
| 390 | * @param ip ipv6 source value |
| 391 | * @return match criterion |
| 392 | */ |
| 393 | public static Criterion matchIPv6Src(IpPrefix ip) { |
| 394 | return new IPCriterion(ip, Type.IPV6_SRC); |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Creates a match on IPv6 destination field using the specified value. |
| 399 | * |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 400 | * @param ip ipv6 destination value |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 401 | * @return match criterion |
| 402 | */ |
| 403 | public static Criterion matchIPv6Dst(IpPrefix ip) { |
| 404 | return new IPCriterion(ip, Type.IPV6_DST); |
| 405 | } |
| 406 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 407 | /** |
| 408 | * Creates a match on IPv6 flow label field using the specified value. |
| 409 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 410 | * @param flowLabel IPv6 flow label (20 bits) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 411 | * @return match criterion |
| 412 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 413 | public static Criterion matchIPv6FlowLabel(int flowLabel) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 414 | return new IPv6FlowLabelCriterion(flowLabel); |
| 415 | } |
| 416 | |
| 417 | /** |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 418 | * Creates a match on ICMPv6 type field using the specified value. |
| 419 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 420 | * @param icmpv6Type ICMPv6 type (8 bits unsigned integer) |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 421 | * @return match criterion |
| 422 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 423 | public static Criterion matchIcmpv6Type(short icmpv6Type) { |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 424 | return new Icmpv6TypeCriterion(icmpv6Type); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Creates a match on ICMPv6 code field using the specified value. |
| 429 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 430 | * @param icmpv6Code ICMPv6 code (8 bits unsigned integer) |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 431 | * @return match criterion |
| 432 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 433 | public static Criterion matchIcmpv6Code(short icmpv6Code) { |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 434 | return new Icmpv6CodeCriterion(icmpv6Code); |
| 435 | } |
| 436 | |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 437 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 438 | * Creates a match on IPv6 Neighbor Discovery target address using the |
| 439 | * specified value. |
| 440 | * |
| 441 | * @param targetAddress IPv6 Neighbor Discovery target address |
| 442 | * @return match criterion |
| 443 | */ |
| 444 | public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) { |
| 445 | return new IPv6NDTargetAddressCriterion(targetAddress); |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Creates a match on IPv6 Neighbor Discovery source link-layer address |
| 450 | * using the specified value. |
| 451 | * |
| 452 | * @param mac IPv6 Neighbor Discovery source link-layer address |
| 453 | * @return match criterion |
| 454 | */ |
| 455 | public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) { |
| 456 | return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Creates a match on IPv6 Neighbor Discovery target link-layer address |
| 461 | * using the specified value. |
| 462 | * |
| 463 | * @param mac IPv6 Neighbor Discovery target link-layer address |
| 464 | * @return match criterion |
| 465 | */ |
| 466 | public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) { |
| 467 | return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL); |
| 468 | } |
| 469 | |
| 470 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 471 | * Creates a match on MPLS label. |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 472 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 473 | * @param mplsLabel MPLS label (20 bits) |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 474 | * @return match criterion |
| 475 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 476 | public static Criterion matchMplsLabel(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 477 | return new MplsCriterion(mplsLabel); |
| 478 | } |
| 479 | |
| 480 | /** |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 481 | * Creates a match on MPLS Bottom-of-Stack indicator bit. |
| 482 | * |
| 483 | * @param mplsBos boolean value indicating true (BOS=1) or false (BOS=0) |
| 484 | * @return match criterion |
| 485 | */ |
Jian Li | 5c4cf1e | 2015-11-30 13:10:46 -0800 | [diff] [blame] | 486 | public static Criterion matchMplsBos(boolean mplsBos) { |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 487 | return new MplsBosCriterion(mplsBos); |
| 488 | } |
| 489 | |
| 490 | /** |
Jian Li | fd44dc9 | 2015-11-26 16:32:32 -0800 | [diff] [blame] | 491 | * Creates a match on MPLS TC. |
| 492 | * |
| 493 | * @param mplsTc MPLS TC (3 bits) |
| 494 | * @return match criterion |
| 495 | */ |
| 496 | public static Criterion matchMplsTc(byte mplsTc) { |
| 497 | return new MplsTcCriterion(mplsTc); |
| 498 | } |
| 499 | |
| 500 | /** |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 501 | * Creates a match on Tunnel ID. |
| 502 | * |
| 503 | * @param tunnelId Tunnel ID (64 bits) |
| 504 | * @return match criterion |
| 505 | */ |
| 506 | public static Criterion matchTunnelId(long tunnelId) { |
| 507 | return new TunnelIdCriterion(tunnelId); |
| 508 | } |
| 509 | |
| 510 | /** |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 511 | * Creates a match on IPv6 Extension Header pseudo-field fiags. |
| 512 | * Those are defined in Criterion.IPv6ExthdrFlags. |
| 513 | * |
| 514 | * @param exthdrFlags IPv6 Extension Header pseudo-field flags (16 bits) |
| 515 | * @return match criterion |
| 516 | */ |
| 517 | public static Criterion matchIPv6ExthdrFlags(int exthdrFlags) { |
| 518 | return new IPv6ExthdrFlagsCriterion(exthdrFlags); |
| 519 | } |
| 520 | |
| 521 | /** |
Sho SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 522 | * Creates a match on lambda using the specified value. |
| 523 | * |
| 524 | * @param lambda lambda |
| 525 | * @return match criterion |
| 526 | */ |
| 527 | public static Criterion matchLambda(Lambda lambda) { |
Sho SHIMIZU | 0681016 | 2016-02-24 12:52:32 -0800 | [diff] [blame] | 528 | if (lambda instanceof OchSignal) { |
Sho SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 529 | return new OchSignalCriterion((OchSignal) lambda); |
| 530 | } else { |
| 531 | throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda)); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | /** |
Sho SHIMIZU | b5e6de6 | 2015-05-04 12:13:44 -0700 | [diff] [blame] | 536 | * Create a match on OCh (Optical Channel) signal type. |
| 537 | * |
| 538 | * @param signalType OCh signal type |
| 539 | * @return match criterion |
| 540 | */ |
| 541 | public static Criterion matchOchSignalType(OchSignalType signalType) { |
| 542 | return new OchSignalTypeCriterion(signalType); |
| 543 | } |
| 544 | |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 545 | /** |
| 546 | * Creates a match on ODU (Optical channel Data Unit) signal ID using the specified value. |
| 547 | * |
| 548 | * @param oduSignalId ODU Signal Id |
| 549 | * @return match criterion |
| 550 | */ |
| 551 | public static Criterion matchOduSignalId(OduSignalId oduSignalId) { |
| 552 | return new OduSignalIdCriterion(oduSignalId); |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Creates a match on ODU (Optical channel Data Unit) signal Type using the specified value. |
| 557 | * |
| 558 | * @param signalType ODU Signal Type |
| 559 | * @return match criterion |
| 560 | */ |
| 561 | public static Criterion matchOduSignalType(OduSignalType signalType) { |
| 562 | return new OduSignalTypeCriterion(signalType); |
| 563 | } |
| 564 | |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 565 | /** |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 566 | * Creates a match on IPv4 destination field using the specified value. |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 567 | * |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 568 | * @param ip ipv4 destination value |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 569 | * @return match criterion |
| 570 | */ |
| 571 | public static Criterion matchArpTpa(Ip4Address ip) { |
| 572 | return new ArpPaCriterion(ip, Type.ARP_TPA); |
| 573 | } |
| 574 | |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 575 | /** |
BitOhenry | 08c7294 | 2015-11-18 14:44:29 +0800 | [diff] [blame] | 576 | * Creates a match on IPv4 source field using the specified value. |
| 577 | * |
| 578 | * @param ip ipv4 source value |
| 579 | * @return match criterion |
| 580 | */ |
| 581 | public static Criterion matchArpSpa(Ip4Address ip) { |
| 582 | return new ArpPaCriterion(ip, Type.ARP_SPA); |
| 583 | } |
| 584 | |
| 585 | /** |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 586 | * Creates a match on MAC destination field using the specified value. |
| 587 | * |
| 588 | * @param mac MAC destination value |
| 589 | * @return match criterion |
| 590 | */ |
| 591 | public static Criterion matchArpTha(MacAddress mac) { |
| 592 | return new ArpHaCriterion(mac, Type.ARP_THA); |
| 593 | } |
| 594 | |
| 595 | /** |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 596 | * Creates a match on MAC source field using the specified value. |
| 597 | * |
| 598 | * @param mac MAC source value |
| 599 | * @return match criterion |
| 600 | */ |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 601 | public static Criterion matchArpSha(MacAddress mac) { |
| 602 | return new ArpHaCriterion(mac, Type.ARP_SHA); |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 603 | } |
| 604 | |
BitOhenry | 11620c9 | 2015-11-27 08:42:36 +0800 | [diff] [blame] | 605 | /** |
| 606 | * Creates a match on arp operation type field using the specified value. |
| 607 | * |
| 608 | * @param arpOp arp operation type value |
| 609 | * @return match criterion |
| 610 | */ |
| 611 | public static Criterion matchArpOp(int arpOp) { |
| 612 | return new ArpOpCriterion(arpOp, Type.ARP_OP); |
| 613 | } |
| 614 | |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 615 | /** |
Jian Li | f1ecf99 | 2015-12-02 17:48:54 -0800 | [diff] [blame] | 616 | * Creates a match on PBB I-SID field using the specific value. |
| 617 | * |
| 618 | * @param pbbIsid PBB I-SID |
| 619 | * @return match criterion |
| 620 | */ |
| 621 | public static Criterion matchPbbIsid(int pbbIsid) { |
| 622 | return new PbbIsidCriterion(pbbIsid); |
| 623 | } |
| 624 | |
| 625 | /** |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 626 | * Creates an extension criterion for the specified extension selector. |
| 627 | * |
| 628 | * @param extensionSelector extension selector |
| 629 | * @param deviceId device ID |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 630 | * @return match extension criterion |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 631 | */ |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 632 | public static ExtensionCriterion extension(ExtensionSelector extensionSelector, |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 633 | DeviceId deviceId) { |
| 634 | return new ExtensionCriterion(extensionSelector, deviceId); |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Creates a dummy criterion. |
| 639 | * |
| 640 | * @return match criterion |
| 641 | */ |
alshabib | a3a476d | 2015-04-10 14:35:38 -0700 | [diff] [blame] | 642 | public static Criterion dummy() { |
| 643 | return new DummyCriterion(); |
| 644 | } |
| 645 | |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 646 | /** |
alshabib | a3a476d | 2015-04-10 14:35:38 -0700 | [diff] [blame] | 647 | * Dummy Criterion used with @see{FilteringObjective}. |
| 648 | */ |
| 649 | private static class DummyCriterion implements Criterion { |
| 650 | |
| 651 | @Override |
| 652 | public Type type() { |
| 653 | return Type.DUMMY; |
| 654 | } |
| 655 | } |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 656 | } |