Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present 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 | 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 | /** |
| 241 | * Creates a match on TCP destination port field using the specified value. |
| 242 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 243 | * @param tcpPort TCP destination port |
| 244 | * @return match criterion |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 245 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 246 | public static Criterion matchTcpDst(TpPort tcpPort) { |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 247 | return new TcpPortCriterion(tcpPort, Type.TCP_DST); |
| 248 | } |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 249 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 250 | /** |
Jian Li | 2748b2c | 2015-11-30 11:43:09 -0800 | [diff] [blame] | 251 | * Creates a match on TCP flags using the specified value. |
| 252 | * |
| 253 | * @param flags TCP flags |
| 254 | * @return match criterion |
| 255 | */ |
| 256 | public static Criterion matchTcpFlags(int flags) { |
| 257 | return new TcpFlagsCriterion(flags); |
| 258 | } |
| 259 | |
| 260 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 261 | * Creates a match on UDP source port field using the specified value. |
| 262 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 263 | * @param udpPort UDP source port |
| 264 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 265 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 266 | public static Criterion matchUdpSrc(TpPort udpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 267 | return new UdpPortCriterion(udpPort, Type.UDP_SRC); |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Creates a match on UDP destination port field using the specified value. |
| 272 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 273 | * @param udpPort UDP destination port |
| 274 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 275 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 276 | public static Criterion matchUdpDst(TpPort udpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 277 | return new UdpPortCriterion(udpPort, Type.UDP_DST); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Creates a match on SCTP source port field using the specified value. |
| 282 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 283 | * @param sctpPort SCTP source port |
| 284 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 285 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 286 | public static Criterion matchSctpSrc(TpPort sctpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 287 | return new SctpPortCriterion(sctpPort, Type.SCTP_SRC); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Creates a match on SCTP destination port field using the specified |
| 292 | * value. |
| 293 | * |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 294 | * @param sctpPort SCTP destination port |
| 295 | * @return match criterion |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 296 | */ |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 297 | public static Criterion matchSctpDst(TpPort sctpPort) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 298 | return new SctpPortCriterion(sctpPort, Type.SCTP_DST); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Creates a match on ICMP type field using the specified value. |
| 303 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 304 | * @param icmpType ICMP type (8 bits unsigned integer) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 305 | * @return match criterion |
| 306 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 307 | public static Criterion matchIcmpType(short icmpType) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 308 | return new IcmpTypeCriterion(icmpType); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Creates a match on ICMP code field using the specified value. |
| 313 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 314 | * @param icmpCode ICMP code (8 bits unsigned integer) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 315 | * @return match criterion |
| 316 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 317 | public static Criterion matchIcmpCode(short icmpCode) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 318 | return new IcmpCodeCriterion(icmpCode); |
| 319 | } |
| 320 | |
| 321 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 322 | * Creates a match on IPv6 source field using the specified value. |
| 323 | * |
| 324 | * @param ip ipv6 source value |
| 325 | * @return match criterion |
| 326 | */ |
| 327 | public static Criterion matchIPv6Src(IpPrefix ip) { |
| 328 | return new IPCriterion(ip, Type.IPV6_SRC); |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Creates a match on IPv6 destination field using the specified value. |
| 333 | * |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 334 | * @param ip ipv6 destination value |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 335 | * @return match criterion |
| 336 | */ |
| 337 | public static Criterion matchIPv6Dst(IpPrefix ip) { |
| 338 | return new IPCriterion(ip, Type.IPV6_DST); |
| 339 | } |
| 340 | |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 341 | /** |
| 342 | * Creates a match on IPv6 flow label field using the specified value. |
| 343 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 344 | * @param flowLabel IPv6 flow label (20 bits) |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 345 | * @return match criterion |
| 346 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 347 | public static Criterion matchIPv6FlowLabel(int flowLabel) { |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 348 | return new IPv6FlowLabelCriterion(flowLabel); |
| 349 | } |
| 350 | |
| 351 | /** |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 352 | * Creates a match on ICMPv6 type field using the specified value. |
| 353 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 354 | * @param icmpv6Type ICMPv6 type (8 bits unsigned integer) |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 355 | * @return match criterion |
| 356 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 357 | public static Criterion matchIcmpv6Type(short icmpv6Type) { |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 358 | return new Icmpv6TypeCriterion(icmpv6Type); |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Creates a match on ICMPv6 code field using the specified value. |
| 363 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 364 | * @param icmpv6Code ICMPv6 code (8 bits unsigned integer) |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 365 | * @return match criterion |
| 366 | */ |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 367 | public static Criterion matchIcmpv6Code(short icmpv6Code) { |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame] | 368 | return new Icmpv6CodeCriterion(icmpv6Code); |
| 369 | } |
| 370 | |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 371 | /** |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 372 | * Creates a match on IPv6 Neighbor Discovery target address using the |
| 373 | * specified value. |
| 374 | * |
| 375 | * @param targetAddress IPv6 Neighbor Discovery target address |
| 376 | * @return match criterion |
| 377 | */ |
| 378 | public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) { |
| 379 | return new IPv6NDTargetAddressCriterion(targetAddress); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Creates a match on IPv6 Neighbor Discovery source link-layer address |
| 384 | * using the specified value. |
| 385 | * |
| 386 | * @param mac IPv6 Neighbor Discovery source link-layer address |
| 387 | * @return match criterion |
| 388 | */ |
| 389 | public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) { |
| 390 | return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL); |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Creates a match on IPv6 Neighbor Discovery target link-layer address |
| 395 | * using the specified value. |
| 396 | * |
| 397 | * @param mac IPv6 Neighbor Discovery target link-layer address |
| 398 | * @return match criterion |
| 399 | */ |
| 400 | public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) { |
| 401 | return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL); |
| 402 | } |
| 403 | |
| 404 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 405 | * Creates a match on MPLS label. |
Pavlin Radoslavov | 320e6c9 | 2015-02-02 16:51:58 -0800 | [diff] [blame] | 406 | * |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 407 | * @param mplsLabel MPLS label (20 bits) |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 408 | * @return match criterion |
| 409 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 410 | public static Criterion matchMplsLabel(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 411 | return new MplsCriterion(mplsLabel); |
| 412 | } |
| 413 | |
| 414 | /** |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 415 | * Creates a match on MPLS Bottom-of-Stack indicator bit. |
| 416 | * |
| 417 | * @param mplsBos boolean value indicating true (BOS=1) or false (BOS=0) |
| 418 | * @return match criterion |
| 419 | */ |
Jian Li | 5c4cf1e | 2015-11-30 13:10:46 -0800 | [diff] [blame] | 420 | public static Criterion matchMplsBos(boolean mplsBos) { |
Saurav Das | ffc5bbc | 2015-08-18 23:30:19 -0700 | [diff] [blame] | 421 | return new MplsBosCriterion(mplsBos); |
| 422 | } |
| 423 | |
| 424 | /** |
Jian Li | fd44dc9 | 2015-11-26 16:32:32 -0800 | [diff] [blame] | 425 | * Creates a match on MPLS TC. |
| 426 | * |
| 427 | * @param mplsTc MPLS TC (3 bits) |
| 428 | * @return match criterion |
| 429 | */ |
| 430 | public static Criterion matchMplsTc(byte mplsTc) { |
| 431 | return new MplsTcCriterion(mplsTc); |
| 432 | } |
| 433 | |
| 434 | /** |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 435 | * Creates a match on Tunnel ID. |
| 436 | * |
| 437 | * @param tunnelId Tunnel ID (64 bits) |
| 438 | * @return match criterion |
| 439 | */ |
| 440 | public static Criterion matchTunnelId(long tunnelId) { |
| 441 | return new TunnelIdCriterion(tunnelId); |
| 442 | } |
| 443 | |
| 444 | /** |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 445 | * Creates a match on IPv6 Extension Header pseudo-field fiags. |
| 446 | * Those are defined in Criterion.IPv6ExthdrFlags. |
| 447 | * |
| 448 | * @param exthdrFlags IPv6 Extension Header pseudo-field flags (16 bits) |
| 449 | * @return match criterion |
| 450 | */ |
| 451 | public static Criterion matchIPv6ExthdrFlags(int exthdrFlags) { |
| 452 | return new IPv6ExthdrFlagsCriterion(exthdrFlags); |
| 453 | } |
| 454 | |
| 455 | /** |
Sho SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 456 | * Creates a match on lambda using the specified value. |
| 457 | * |
| 458 | * @param lambda lambda |
| 459 | * @return match criterion |
| 460 | */ |
| 461 | public static Criterion matchLambda(Lambda lambda) { |
Sho SHIMIZU | 0681016 | 2016-02-24 12:52:32 -0800 | [diff] [blame] | 462 | if (lambda instanceof OchSignal) { |
Sho SHIMIZU | 084c4ca | 2015-05-04 11:52:51 -0700 | [diff] [blame] | 463 | return new OchSignalCriterion((OchSignal) lambda); |
| 464 | } else { |
| 465 | throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda)); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | /** |
Sho SHIMIZU | b5e6de6 | 2015-05-04 12:13:44 -0700 | [diff] [blame] | 470 | * Create a match on OCh (Optical Channel) signal type. |
| 471 | * |
| 472 | * @param signalType OCh signal type |
| 473 | * @return match criterion |
| 474 | */ |
| 475 | public static Criterion matchOchSignalType(OchSignalType signalType) { |
| 476 | return new OchSignalTypeCriterion(signalType); |
| 477 | } |
| 478 | |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 479 | /** |
| 480 | * Creates a match on ODU (Optical channel Data Unit) signal ID using the specified value. |
| 481 | * |
| 482 | * @param oduSignalId ODU Signal Id |
| 483 | * @return match criterion |
| 484 | */ |
| 485 | public static Criterion matchOduSignalId(OduSignalId oduSignalId) { |
| 486 | return new OduSignalIdCriterion(oduSignalId); |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Creates a match on ODU (Optical channel Data Unit) signal Type using the specified value. |
| 491 | * |
| 492 | * @param signalType ODU Signal Type |
| 493 | * @return match criterion |
| 494 | */ |
| 495 | public static Criterion matchOduSignalType(OduSignalType signalType) { |
| 496 | return new OduSignalTypeCriterion(signalType); |
| 497 | } |
| 498 | |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 499 | /** |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 500 | * Creates a match on IPv4 destination field using the specified value. |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 501 | * |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 502 | * @param ip ipv4 destination value |
lishuai | a72d44d | 2015-10-19 17:27:38 +0800 | [diff] [blame] | 503 | * @return match criterion |
| 504 | */ |
| 505 | public static Criterion matchArpTpa(Ip4Address ip) { |
| 506 | return new ArpPaCriterion(ip, Type.ARP_TPA); |
| 507 | } |
| 508 | |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 509 | /** |
BitOhenry | 08c7294 | 2015-11-18 14:44:29 +0800 | [diff] [blame] | 510 | * Creates a match on IPv4 source field using the specified value. |
| 511 | * |
| 512 | * @param ip ipv4 source value |
| 513 | * @return match criterion |
| 514 | */ |
| 515 | public static Criterion matchArpSpa(Ip4Address ip) { |
| 516 | return new ArpPaCriterion(ip, Type.ARP_SPA); |
| 517 | } |
| 518 | |
| 519 | /** |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 520 | * Creates a match on MAC destination field using the specified value. |
| 521 | * |
| 522 | * @param mac MAC destination value |
| 523 | * @return match criterion |
| 524 | */ |
| 525 | public static Criterion matchArpTha(MacAddress mac) { |
| 526 | return new ArpHaCriterion(mac, Type.ARP_THA); |
| 527 | } |
| 528 | |
| 529 | /** |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 530 | * Creates a match on MAC source field using the specified value. |
| 531 | * |
| 532 | * @param mac MAC source value |
| 533 | * @return match criterion |
| 534 | */ |
BitOhenry | e330cf0 | 2015-11-17 18:59:33 +0800 | [diff] [blame] | 535 | public static Criterion matchArpSha(MacAddress mac) { |
| 536 | return new ArpHaCriterion(mac, Type.ARP_SHA); |
BitOhenry | cc024eb | 2015-11-10 17:17:36 +0800 | [diff] [blame] | 537 | } |
| 538 | |
BitOhenry | 11620c9 | 2015-11-27 08:42:36 +0800 | [diff] [blame] | 539 | /** |
| 540 | * Creates a match on arp operation type field using the specified value. |
| 541 | * |
| 542 | * @param arpOp arp operation type value |
| 543 | * @return match criterion |
| 544 | */ |
| 545 | public static Criterion matchArpOp(int arpOp) { |
| 546 | return new ArpOpCriterion(arpOp, Type.ARP_OP); |
| 547 | } |
| 548 | |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 549 | /** |
Jian Li | f1ecf99 | 2015-12-02 17:48:54 -0800 | [diff] [blame] | 550 | * Creates a match on PBB I-SID field using the specific value. |
| 551 | * |
| 552 | * @param pbbIsid PBB I-SID |
| 553 | * @return match criterion |
| 554 | */ |
| 555 | public static Criterion matchPbbIsid(int pbbIsid) { |
| 556 | return new PbbIsidCriterion(pbbIsid); |
| 557 | } |
| 558 | |
| 559 | /** |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 560 | * Creates an extension criterion for the specified extension selector. |
| 561 | * |
| 562 | * @param extensionSelector extension selector |
| 563 | * @param deviceId device ID |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 564 | * @return match extension criterion |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 565 | */ |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 566 | public static ExtensionCriterion extension(ExtensionSelector extensionSelector, |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 567 | DeviceId deviceId) { |
| 568 | return new ExtensionCriterion(extensionSelector, deviceId); |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Creates a dummy criterion. |
| 573 | * |
| 574 | * @return match criterion |
| 575 | */ |
alshabib | a3a476d | 2015-04-10 14:35:38 -0700 | [diff] [blame] | 576 | public static Criterion dummy() { |
| 577 | return new DummyCriterion(); |
| 578 | } |
| 579 | |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 580 | /** |
alshabib | a3a476d | 2015-04-10 14:35:38 -0700 | [diff] [blame] | 581 | * Dummy Criterion used with @see{FilteringObjective}. |
| 582 | */ |
| 583 | private static class DummyCriterion implements Criterion { |
| 584 | |
| 585 | @Override |
| 586 | public Type type() { |
| 587 | return Type.DUMMY; |
| 588 | } |
| 589 | } |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 590 | } |