blob: 6e9a228b0e7c28abfa428889db10c4878eca5c2b [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow.criteria;
tom8bb16062014-09-12 14:47:46 -070017
Sho SHIMIZUefc2e282015-05-04 15:26:23 -070018import org.onosproject.net.IndexedLambda;
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -070019import org.onosproject.net.Lambda;
20import org.onosproject.net.OchSignal;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.PortNumber;
22import org.onosproject.net.flow.criteria.Criterion.Type;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070023import org.onlab.packet.IpPrefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080024import org.onlab.packet.Ip6Address;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070025import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010026import org.onlab.packet.MplsLabel;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070027import org.onlab.packet.VlanId;
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -070028import org.onosproject.net.tunnel.OchSignalType;
alshabib7b795492014-09-16 14:38:39 -070029
tom8bb16062014-09-12 14:47:46 -070030/**
31 * Factory class to create various traffic selection criteria.
32 */
33public final class Criteria {
34
alshabib7b795492014-09-16 14:38:39 -070035 //TODO: incomplete type implementation. Need to implement complete list from Criterion
36
tom8bb16062014-09-12 14:47:46 -070037 // Ban construction
38 private Criteria() {
39 }
40
41 /**
alshabib7b795492014-09-16 14:38:39 -070042 * Creates a match on IN_PORT field using the specified value.
43 *
44 * @param port inport value
45 * @return match criterion
46 */
47 public static Criterion matchInPort(PortNumber port) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080048 return new PortCriterion(port, Type.IN_PORT);
49 }
50
51 /**
52 * Creates a match on IN_PHY_PORT field using the specified value.
53 *
54 * @param port inport value
55 * @return match criterion
56 */
57 public static Criterion matchInPhyPort(PortNumber port) {
58 return new PortCriterion(port, Type.IN_PHY_PORT);
59 }
60
61 /**
62 * Creates a match on METADATA field using the specified value.
63 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080064 * @param metadata metadata value (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080065 * @return match criterion
66 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080067 public static Criterion matchMetadata(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080068 return new MetadataCriterion(metadata);
alshabib7b795492014-09-16 14:38:39 -070069 }
70
71 /**
alshabib369d2942014-09-12 17:59:35 -070072 * Creates a match on ETH_DST field using the specified value. This value
73 * may be a wildcard mask.
74 *
tomc104d282014-09-19 10:57:55 -070075 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070076 * @return match criterion
77 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070078 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070079 return new EthCriterion(mac, Type.ETH_DST);
80 }
81
82 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080083 * Creates a match on ETH_SRC field using the specified value. This value
84 * may be a wildcard mask.
85 *
86 * @param mac MAC address value or wildcard mask
87 * @return match criterion
88 */
89 public static Criterion matchEthSrc(MacAddress mac) {
90 return new EthCriterion(mac, Type.ETH_SRC);
91 }
92
93 /**
alshabib7b795492014-09-16 14:38:39 -070094 * Creates a match on ETH_TYPE field using the specified value.
95 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080096 * @param ethType eth type value (16 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -070097 * @return match criterion
98 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080099 public static Criterion matchEthType(int ethType) {
alshabib7b795492014-09-16 14:38:39 -0700100 return new EthTypeCriterion(ethType);
101 }
102
103 /**
104 * Creates a match on VLAN ID field using the specified value.
105 *
106 * @param vlanId vlan id value
107 * @return match criterion
108 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700109 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700110 return new VlanIdCriterion(vlanId);
111 }
112
113 /**
114 * Creates a match on VLAN PCP field using the specified value.
115 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800116 * @param vlanPcp vlan pcp value (3 bits)
alshabib7b795492014-09-16 14:38:39 -0700117 * @return match criterion
118 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800119 public static Criterion matchVlanPcp(byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -0700120 return new VlanPcpCriterion(vlanPcp);
121 }
122
123 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800124 * Creates a match on IP DSCP field using the specified value.
125 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800126 * @param ipDscp ip dscp value (6 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800127 * @return match criterion
128 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800129 public static Criterion matchIPDscp(byte ipDscp) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800130 return new IPDscpCriterion(ipDscp);
131 }
132
133 /**
134 * Creates a match on IP ECN field using the specified value.
135 *
Pavlin Radoslavovab8553a2015-02-20 14:13:50 -0800136 * @param ipEcn ip ecn value (2 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800137 * @return match criterion
138 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800139 public static Criterion matchIPEcn(byte ipEcn) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800140 return new IPEcnCriterion(ipEcn);
141 }
142
143 /**
alshabib7b795492014-09-16 14:38:39 -0700144 * Creates a match on IP proto field using the specified value.
145 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800146 * @param proto ip protocol value (8 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -0700147 * @return match criterion
148 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800149 public static Criterion matchIPProtocol(short proto) {
alshabib7b795492014-09-16 14:38:39 -0700150 return new IPProtocolCriterion(proto);
151 }
152
153 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800154 * Creates a match on IPv4 source field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700155 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800156 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700157 * @return match criterion
158 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700159 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700160 return new IPCriterion(ip, Type.IPV4_SRC);
161 }
162
163 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800164 * Creates a match on IPv4 destination field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700165 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800166 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700167 * @return match criterion
168 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700169 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700170 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700171 }
172
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700173 /**
174 * Creates a match on TCP source port field using the specified value.
175 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800176 * @param tcpPort TCP source port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700177 * @return match criterion
178 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800179 public static Criterion matchTcpSrc(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700180 return new TcpPortCriterion(tcpPort, Type.TCP_SRC);
181 }
182
183 /**
184 * Creates a match on TCP destination port field using the specified value.
185 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800186 * @param tcpPort TCP destination port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700187 * @return match criterion
188 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800189 public static Criterion matchTcpDst(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700190 return new TcpPortCriterion(tcpPort, Type.TCP_DST);
191 }
alshabib369d2942014-09-12 17:59:35 -0700192
Marc De Leenheer49087752014-10-23 13:54:09 -0700193 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800194 * Creates a match on UDP source port field using the specified value.
195 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800196 * @param udpPort UDP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800197 * @return match criterion
198 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800199 public static Criterion matchUdpSrc(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800200 return new UdpPortCriterion(udpPort, Type.UDP_SRC);
201 }
202
203 /**
204 * Creates a match on UDP destination port field using the specified value.
205 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800206 * @param udpPort UDP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800207 * @return match criterion
208 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800209 public static Criterion matchUdpDst(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800210 return new UdpPortCriterion(udpPort, Type.UDP_DST);
211 }
212
213 /**
214 * Creates a match on SCTP source port field using the specified value.
215 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800216 * @param sctpPort SCTP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800217 * @return match criterion
218 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800219 public static Criterion matchSctpSrc(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800220 return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
221 }
222
223 /**
224 * Creates a match on SCTP destination port field using the specified
225 * value.
226 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800227 * @param sctpPort SCTP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800228 * @return match criterion
229 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800230 public static Criterion matchSctpDst(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800231 return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
232 }
233
234 /**
235 * Creates a match on ICMP type field using the specified value.
236 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800237 * @param icmpType ICMP type (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800238 * @return match criterion
239 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800240 public static Criterion matchIcmpType(short icmpType) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800241 return new IcmpTypeCriterion(icmpType);
242 }
243
244 /**
245 * Creates a match on ICMP code field using the specified value.
246 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800247 * @param icmpCode ICMP code (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800248 * @return match criterion
249 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800250 public static Criterion matchIcmpCode(short icmpCode) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800251 return new IcmpCodeCriterion(icmpCode);
252 }
253
254 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800255 * Creates a match on IPv6 source field using the specified value.
256 *
257 * @param ip ipv6 source value
258 * @return match criterion
259 */
260 public static Criterion matchIPv6Src(IpPrefix ip) {
261 return new IPCriterion(ip, Type.IPV6_SRC);
262 }
263
264 /**
265 * Creates a match on IPv6 destination field using the specified value.
266 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800267 * @param ip ipv6 destination value
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800268 * @return match criterion
269 */
270 public static Criterion matchIPv6Dst(IpPrefix ip) {
271 return new IPCriterion(ip, Type.IPV6_DST);
272 }
273
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800274 /**
275 * Creates a match on IPv6 flow label field using the specified value.
276 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800277 * @param flowLabel IPv6 flow label (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800278 * @return match criterion
279 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800280 public static Criterion matchIPv6FlowLabel(int flowLabel) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800281 return new IPv6FlowLabelCriterion(flowLabel);
282 }
283
284 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800285 * Creates a match on ICMPv6 type field using the specified value.
286 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800287 * @param icmpv6Type ICMPv6 type (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800288 * @return match criterion
289 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800290 public static Criterion matchIcmpv6Type(short icmpv6Type) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800291 return new Icmpv6TypeCriterion(icmpv6Type);
292 }
293
294 /**
295 * Creates a match on ICMPv6 code field using the specified value.
296 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800297 * @param icmpv6Code ICMPv6 code (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800298 * @return match criterion
299 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800300 public static Criterion matchIcmpv6Code(short icmpv6Code) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800301 return new Icmpv6CodeCriterion(icmpv6Code);
302 }
303
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800304 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800305 * Creates a match on IPv6 Neighbor Discovery target address using the
306 * specified value.
307 *
308 * @param targetAddress IPv6 Neighbor Discovery target address
309 * @return match criterion
310 */
311 public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) {
312 return new IPv6NDTargetAddressCriterion(targetAddress);
313 }
314
315 /**
316 * Creates a match on IPv6 Neighbor Discovery source link-layer address
317 * using the specified value.
318 *
319 * @param mac IPv6 Neighbor Discovery source link-layer address
320 * @return match criterion
321 */
322 public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
323 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL);
324 }
325
326 /**
327 * Creates a match on IPv6 Neighbor Discovery target link-layer address
328 * using the specified value.
329 *
330 * @param mac IPv6 Neighbor Discovery target link-layer address
331 * @return match criterion
332 */
333 public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
334 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL);
335 }
336
337 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800338 * Creates a match on MPLS label.
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800339 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800340 * @param mplsLabel MPLS label (20 bits)
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800341 * @return match criterion
342 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100343 public static Criterion matchMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800344 return new MplsCriterion(mplsLabel);
345 }
346
347 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800348 * Creates a match on IPv6 Extension Header pseudo-field fiags.
349 * Those are defined in Criterion.IPv6ExthdrFlags.
350 *
351 * @param exthdrFlags IPv6 Extension Header pseudo-field flags (16 bits)
352 * @return match criterion
353 */
354 public static Criterion matchIPv6ExthdrFlags(int exthdrFlags) {
355 return new IPv6ExthdrFlagsCriterion(exthdrFlags);
356 }
357
358 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700359 * Creates a match on lambda field using the specified value.
360 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800361 * @param lambda lambda to match on (16 bits unsigned integer)
Marc De Leenheer49087752014-10-23 13:54:09 -0700362 * @return match criterion
363 */
Sho SHIMIZUefc2e282015-05-04 15:26:23 -0700364 @Deprecated
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800365 public static Criterion matchLambda(int lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700366 return new LambdaCriterion(lambda, Type.OCH_SIGID);
367 }
368
369 /**
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -0700370 * Creates a match on lambda using the specified value.
371 *
372 * @param lambda lambda
373 * @return match criterion
374 */
375 public static Criterion matchLambda(Lambda lambda) {
Sho SHIMIZUefc2e282015-05-04 15:26:23 -0700376 if (lambda instanceof IndexedLambda) {
377 return new IndexedLambdaCriterion((IndexedLambda) lambda);
378 } else if (lambda instanceof OchSignal) {
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -0700379 return new OchSignalCriterion((OchSignal) lambda);
380 } else {
381 throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda));
382 }
383 }
384
385 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800386 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700387 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800388 * @param sigType optical signal type (8 bits unsigned integer)
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700389 * @return match criterion
390 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800391 public static Criterion matchOpticalSignalType(short sigType) {
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800392 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700393 }
394
Sho SHIMIZUb5e6de62015-05-04 12:13:44 -0700395 /**
396 * Create a match on OCh (Optical Channel) signal type.
397 *
398 * @param signalType OCh signal type
399 * @return match criterion
400 */
401 public static Criterion matchOchSignalType(OchSignalType signalType) {
402 return new OchSignalTypeCriterion(signalType);
403 }
404
alshabiba3a476d2015-04-10 14:35:38 -0700405 public static Criterion dummy() {
406 return new DummyCriterion();
407 }
408
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700409 /**
alshabiba3a476d2015-04-10 14:35:38 -0700410 * Dummy Criterion used with @see{FilteringObjective}.
411 */
412 private static class DummyCriterion implements Criterion {
413
414 @Override
415 public Type type() {
416 return Type.DUMMY;
417 }
418 }
tom8bb16062014-09-12 14:47:46 -0700419}