blob: 7ee17fdb25c971491f2e3e4738862423c866e547 [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 SHIMIZU084c4ca2015-05-04 11:52:51 -070018import org.onosproject.net.Lambda;
19import org.onosproject.net.OchSignal;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.PortNumber;
21import org.onosproject.net.flow.criteria.Criterion.Type;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070022import org.onlab.packet.IpPrefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080023import org.onlab.packet.Ip6Address;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070024import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010025import org.onlab.packet.MplsLabel;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070026import org.onlab.packet.VlanId;
alshabib7b795492014-09-16 14:38:39 -070027
tom8bb16062014-09-12 14:47:46 -070028/**
29 * Factory class to create various traffic selection criteria.
30 */
31public final class Criteria {
32
alshabib7b795492014-09-16 14:38:39 -070033 //TODO: incomplete type implementation. Need to implement complete list from Criterion
34
tom8bb16062014-09-12 14:47:46 -070035 // Ban construction
36 private Criteria() {
37 }
38
39 /**
alshabib7b795492014-09-16 14:38:39 -070040 * 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 Radoslavovd0fd8412015-02-04 13:57:00 -080046 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 Radoslavovf3b69332015-02-06 15:47:05 -080062 * @param metadata metadata value (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080063 * @return match criterion
64 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080065 public static Criterion matchMetadata(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080066 return new MetadataCriterion(metadata);
alshabib7b795492014-09-16 14:38:39 -070067 }
68
69 /**
alshabib369d2942014-09-12 17:59:35 -070070 * Creates a match on ETH_DST field using the specified value. This value
71 * may be a wildcard mask.
72 *
tomc104d282014-09-19 10:57:55 -070073 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070074 * @return match criterion
75 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070076 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070077 return new EthCriterion(mac, Type.ETH_DST);
78 }
79
80 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080081 * 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 /**
alshabib7b795492014-09-16 14:38:39 -070092 * Creates a match on ETH_TYPE field using the specified value.
93 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080094 * @param ethType eth type value (16 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -070095 * @return match criterion
96 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080097 public static Criterion matchEthType(int ethType) {
alshabib7b795492014-09-16 14:38:39 -070098 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 Koshibea9c199f2014-09-16 16:21:40 -0700107 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700108 return new VlanIdCriterion(vlanId);
109 }
110
111 /**
112 * Creates a match on VLAN PCP field using the specified value.
113 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800114 * @param vlanPcp vlan pcp value (3 bits)
alshabib7b795492014-09-16 14:38:39 -0700115 * @return match criterion
116 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800117 public static Criterion matchVlanPcp(byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -0700118 return new VlanPcpCriterion(vlanPcp);
119 }
120
121 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800122 * Creates a match on IP DSCP field using the specified value.
123 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800124 * @param ipDscp ip dscp value (6 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800125 * @return match criterion
126 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800127 public static Criterion matchIPDscp(byte ipDscp) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800128 return new IPDscpCriterion(ipDscp);
129 }
130
131 /**
132 * Creates a match on IP ECN field using the specified value.
133 *
Pavlin Radoslavovab8553a2015-02-20 14:13:50 -0800134 * @param ipEcn ip ecn value (2 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800135 * @return match criterion
136 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800137 public static Criterion matchIPEcn(byte ipEcn) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800138 return new IPEcnCriterion(ipEcn);
139 }
140
141 /**
alshabib7b795492014-09-16 14:38:39 -0700142 * Creates a match on IP proto field using the specified value.
143 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800144 * @param proto ip protocol value (8 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -0700145 * @return match criterion
146 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800147 public static Criterion matchIPProtocol(short proto) {
alshabib7b795492014-09-16 14:38:39 -0700148 return new IPProtocolCriterion(proto);
149 }
150
151 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800152 * Creates a match on IPv4 source field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700153 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800154 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700155 * @return match criterion
156 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700157 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700158 return new IPCriterion(ip, Type.IPV4_SRC);
159 }
160
161 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800162 * Creates a match on IPv4 destination field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700163 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800164 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700165 * @return match criterion
166 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700167 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700168 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700169 }
170
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700171 /**
172 * Creates a match on TCP source port field using the specified value.
173 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800174 * @param tcpPort TCP source port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700175 * @return match criterion
176 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800177 public static Criterion matchTcpSrc(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700178 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 Radoslavovf3b69332015-02-06 15:47:05 -0800184 * @param tcpPort TCP destination port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700185 * @return match criterion
186 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800187 public static Criterion matchTcpDst(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700188 return new TcpPortCriterion(tcpPort, Type.TCP_DST);
189 }
alshabib369d2942014-09-12 17:59:35 -0700190
Marc De Leenheer49087752014-10-23 13:54:09 -0700191 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800192 * Creates a match on UDP source port field using the specified value.
193 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800194 * @param udpPort UDP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800195 * @return match criterion
196 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800197 public static Criterion matchUdpSrc(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800198 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 Radoslavovf3b69332015-02-06 15:47:05 -0800204 * @param udpPort UDP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800205 * @return match criterion
206 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800207 public static Criterion matchUdpDst(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800208 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 Radoslavovf3b69332015-02-06 15:47:05 -0800214 * @param sctpPort SCTP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800215 * @return match criterion
216 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800217 public static Criterion matchSctpSrc(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800218 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 Radoslavovf3b69332015-02-06 15:47:05 -0800225 * @param sctpPort SCTP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800226 * @return match criterion
227 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800228 public static Criterion matchSctpDst(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800229 return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
230 }
231
232 /**
233 * Creates a match on ICMP type field using the specified value.
234 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800235 * @param icmpType ICMP type (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800236 * @return match criterion
237 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800238 public static Criterion matchIcmpType(short icmpType) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800239 return new IcmpTypeCriterion(icmpType);
240 }
241
242 /**
243 * Creates a match on ICMP code field using the specified value.
244 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800245 * @param icmpCode ICMP code (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800246 * @return match criterion
247 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800248 public static Criterion matchIcmpCode(short icmpCode) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800249 return new IcmpCodeCriterion(icmpCode);
250 }
251
252 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800253 * 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 Radoslavov320e6c92015-02-02 16:51:58 -0800265 * @param ip ipv6 destination value
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800266 * @return match criterion
267 */
268 public static Criterion matchIPv6Dst(IpPrefix ip) {
269 return new IPCriterion(ip, Type.IPV6_DST);
270 }
271
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800272 /**
273 * Creates a match on IPv6 flow label field using the specified value.
274 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800275 * @param flowLabel IPv6 flow label (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800276 * @return match criterion
277 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800278 public static Criterion matchIPv6FlowLabel(int flowLabel) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800279 return new IPv6FlowLabelCriterion(flowLabel);
280 }
281
282 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800283 * Creates a match on ICMPv6 type field using the specified value.
284 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800285 * @param icmpv6Type ICMPv6 type (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800286 * @return match criterion
287 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800288 public static Criterion matchIcmpv6Type(short icmpv6Type) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800289 return new Icmpv6TypeCriterion(icmpv6Type);
290 }
291
292 /**
293 * Creates a match on ICMPv6 code field using the specified value.
294 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800295 * @param icmpv6Code ICMPv6 code (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800296 * @return match criterion
297 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800298 public static Criterion matchIcmpv6Code(short icmpv6Code) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800299 return new Icmpv6CodeCriterion(icmpv6Code);
300 }
301
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800302 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800303 * 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 Balakrishnan8c67d172014-11-10 10:15:41 -0800336 * Creates a match on MPLS label.
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800337 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800338 * @param mplsLabel MPLS label (20 bits)
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800339 * @return match criterion
340 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100341 public static Criterion matchMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800342 return new MplsCriterion(mplsLabel);
343 }
344
345 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800346 * Creates a match on IPv6 Extension Header pseudo-field fiags.
347 * Those are defined in Criterion.IPv6ExthdrFlags.
348 *
349 * @param exthdrFlags IPv6 Extension Header pseudo-field flags (16 bits)
350 * @return match criterion
351 */
352 public static Criterion matchIPv6ExthdrFlags(int exthdrFlags) {
353 return new IPv6ExthdrFlagsCriterion(exthdrFlags);
354 }
355
356 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700357 * Creates a match on lambda field using the specified value.
358 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800359 * @param lambda lambda to match on (16 bits unsigned integer)
Marc De Leenheer49087752014-10-23 13:54:09 -0700360 * @return match criterion
361 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800362 public static Criterion matchLambda(int lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700363 return new LambdaCriterion(lambda, Type.OCH_SIGID);
364 }
365
366 /**
Sho SHIMIZU084c4ca2015-05-04 11:52:51 -0700367 * Creates a match on lambda using the specified value.
368 *
369 * @param lambda lambda
370 * @return match criterion
371 */
372 public static Criterion matchLambda(Lambda lambda) {
373 if (lambda instanceof OchSignal) {
374 return new OchSignalCriterion((OchSignal) lambda);
375 } else {
376 throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda));
377 }
378 }
379
380 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800381 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700382 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800383 * @param sigType optical signal type (8 bits unsigned integer)
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700384 * @return match criterion
385 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800386 public static Criterion matchOpticalSignalType(short sigType) {
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800387 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700388 }
389
alshabiba3a476d2015-04-10 14:35:38 -0700390 public static Criterion dummy() {
391 return new DummyCriterion();
392 }
393
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700394 /**
alshabiba3a476d2015-04-10 14:35:38 -0700395 * Dummy Criterion used with @see{FilteringObjective}.
396 */
397 private static class DummyCriterion implements Criterion {
398
399 @Override
400 public Type type() {
401 return Type.DUMMY;
402 }
403 }
tom8bb16062014-09-12 14:47:46 -0700404}