blob: 1b264b55d23de74c61948a78a8d63c8debe104e9 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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;
tom8bb16062014-09-12 14:47:46 -070017
BitOhenryb2f8e812015-11-17 19:19:53 +080018import org.onlab.packet.Ip4Address;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070019import org.onlab.packet.Ip6Address;
20import org.onlab.packet.IpPrefix;
21import org.onlab.packet.MacAddress;
22import org.onlab.packet.MplsLabel;
23import org.onlab.packet.TpPort;
24import org.onlab.packet.VlanId;
Jonathan Hart26a8d952015-12-02 15:16:35 -080025import org.onosproject.net.DeviceId;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.net.PortNumber;
27import org.onosproject.net.flow.criteria.Criterion;
Jonathan Hart26a8d952015-12-02 15:16:35 -080028import org.onosproject.net.flow.criteria.ExtensionSelector;
29
30import java.util.Set;
alshabib7410fea2014-09-16 13:48:39 -070031
tom8bb16062014-09-12 14:47:46 -070032/**
33 * Abstraction of a slice of network traffic.
34 */
35public interface TrafficSelector {
36
37 /**
38 * Returns selection criteria as an ordered list.
39 *
40 * @return list of criteria
41 */
alshabibba5ac482014-10-02 17:15:20 -070042 Set<Criterion> criteria();
tom8bb16062014-09-12 14:47:46 -070043
44 /**
Jonathan Hart936c49d2014-10-23 16:38:59 -070045 * Returns the selection criterion for a particular type, if it exists in
46 * this traffic selector.
47 *
48 * @param type criterion type to look up
49 * @return the criterion of the specified type if one exists, otherwise null
50 */
51 Criterion getCriterion(Criterion.Type type);
52
53 /**
tom8bb16062014-09-12 14:47:46 -070054 * Builder of traffic selector entities.
55 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070056 interface Builder {
tom8bb16062014-09-12 14:47:46 -070057
58 /**
59 * Adds a traffic selection criterion. If a same type criterion has
60 * already been added, it will be replaced by this one.
61 *
62 * @param criterion new criterion
alshabib369d2942014-09-12 17:59:35 -070063 * @return self
tom8bb16062014-09-12 14:47:46 -070064 */
alshabib369d2942014-09-12 17:59:35 -070065 Builder add(Criterion criterion);
tom8bb16062014-09-12 14:47:46 -070066
67 /**
alshabib010c31d2014-09-26 10:01:12 -070068 * Matches an inport.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080069 *
alshabib010c31d2014-09-26 10:01:12 -070070 * @param port the inport
71 * @return a selection builder
72 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070073 Builder matchInPort(PortNumber port);
alshabib010c31d2014-09-26 10:01:12 -070074
75 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080076 * Matches a physical inport.
77 *
78 * @param port the physical inport
79 * @return a selection builder
80 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070081 Builder matchInPhyPort(PortNumber port);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080082
83 /**
84 * Matches a metadata.
85 *
86 * @param metadata the metadata
87 * @return a selection builder
88 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070089 Builder matchMetadata(long metadata);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080090
91 /**
alshabib010c31d2014-09-26 10:01:12 -070092 * Matches a l2 dst address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080093 *
alshabib010c31d2014-09-26 10:01:12 -070094 * @param addr a l2 address
95 * @return a selection builder
96 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070097 Builder matchEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -070098
99 /**
Saurav Das9d6c86b2016-02-19 09:01:07 -0800100 * Matches a l2 dst address with mask.
101 *
102 * @param addr a l2 address
103 * @param mask a mask for an l2 address
104 * @return a selection builder
105 */
106 Builder matchEthDstMasked(MacAddress addr, MacAddress mask);
107
108 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800109 * Matches a l2 src address.
110 *
111 * @param addr a l2 address
112 * @return a selection builder
113 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700114 Builder matchEthSrc(MacAddress addr);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800115
116 /**
Saurav Das9d6c86b2016-02-19 09:01:07 -0800117 * Matches a l2 src address with mask.
118 *
119 * @param addr a l2 address
120 * @param mask a mask for an l2 address
121 * @return a selection builder
122 */
123 Builder matchEthSrcMasked(MacAddress addr, MacAddress mask);
124
125 /**
alshabib010c31d2014-09-26 10:01:12 -0700126 * Matches the ethernet type.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800127 *
alshabib010c31d2014-09-26 10:01:12 -0700128 * @param ethType an ethernet type
129 * @return a selection builder
130 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700131 Builder matchEthType(short ethType);
alshabib010c31d2014-09-26 10:01:12 -0700132
133 /**
134 * Matches the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800135 *
alshabib010c31d2014-09-26 10:01:12 -0700136 * @param vlanId a vlan id
137 * @return a selection builder
138 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700139 Builder matchVlanId(VlanId vlanId);
alshabib010c31d2014-09-26 10:01:12 -0700140
141 /**
142 * Matches a vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800143 *
alshabib010c31d2014-09-26 10:01:12 -0700144 * @param vlanPcp a vlan priority
145 * @return a selection builder
146 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700147 Builder matchVlanPcp(byte vlanPcp);
alshabib010c31d2014-09-26 10:01:12 -0700148
149 /**
alshabibfa0dc662016-01-13 11:23:53 -0800150 * Matches the inner vlan id.
151 *
152 * @param vlanId a vlan id
153 * @return a selection builder
154 */
155 Builder matchInnerVlanId(VlanId vlanId);
156
157 /**
158 * Matches a vlan priority.
159 *
160 * @param vlanPcp a vlan priority
161 * @return a selection builder
162 */
163 Builder matchInnerVlanPcp(byte vlanPcp);
164
165 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800166 * Matches an IP DSCP (6 bits in ToS field).
167 *
168 * @param ipDscp an IP DSCP value
169 * @return a selection builder
170 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700171 Builder matchIPDscp(byte ipDscp);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800172
173 /**
174 * Matches an IP ECN (2 bits in ToS field).
175 *
176 * @param ipEcn an IP ECN value
177 * @return a selection builder
178 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700179 Builder matchIPEcn(byte ipEcn);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800180
181 /**
alshabib010c31d2014-09-26 10:01:12 -0700182 * Matches the l3 protocol.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800183 *
alshabib010c31d2014-09-26 10:01:12 -0700184 * @param proto a l3 protocol
185 * @return a selection builder
186 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700187 Builder matchIPProtocol(byte proto);
alshabib010c31d2014-09-26 10:01:12 -0700188
189 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800190 * Matches a l3 IPv4 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800191 *
alshabib010c31d2014-09-26 10:01:12 -0700192 * @param ip a l3 address
193 * @return a selection builder
194 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700195 Builder matchIPSrc(IpPrefix ip);
alshabib010c31d2014-09-26 10:01:12 -0700196
197 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800198 * Matches a l3 IPv4 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800199 *
alshabib010c31d2014-09-26 10:01:12 -0700200 * @param ip a l3 address
201 * @return a selection builder
202 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700203 Builder matchIPDst(IpPrefix ip);
alshabib010c31d2014-09-26 10:01:12 -0700204
205 /**
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700206 * Matches a TCP source port number.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800207 *
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700208 * @param tcpPort a TCP source port number
209 * @return a selection builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700210 */
211 Builder matchTcpSrc(TpPort tcpPort);
212
213 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100214 * Matches a TCP source port number with mask.
215 *
216 * @param tcpPort a TCP source port number
217 * @param mask a mask for a TCP source port number
218 * @return a selection builder
219 */
220 Builder matchTcpSrcMasked(TpPort tcpPort, TpPort mask);
221
222 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700223 * Matches a TCP destination port number.
224 *
225 * @param tcpPort a TCP destination port number
226 * @return a selection builder
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700227 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700228 Builder matchTcpDst(TpPort tcpPort);
229
230 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100231 * Matches a TCP destination port number with mask.
232 *
233 * @param tcpPort a TCP destination port number
234 * @param mask a mask for a TCP destination port number
235 * @return a selection builder
236 */
237 Builder matchTcpDstMasked(TpPort tcpPort, TpPort mask);
238
239 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700240 * Matches an UDP source port number.
241 *
242 * @param udpPort an UDP source port number
243 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800244 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700245 Builder matchUdpSrc(TpPort udpPort);
246
247 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100248 * Matches a UDP source port number with mask.
249 *
250 * @param udpPort a UDP source port number
251 * @param mask a mask for a UDP source port number
252 * @return a selection builder
253 */
254 Builder matchUdpSrcMasked(TpPort udpPort, TpPort mask);
255
256 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700257 * Matches an UDP destination port number.
258 *
259 * @param udpPort an UDP destination port number
260 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800261 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700262 Builder matchUdpDst(TpPort udpPort);
263
264 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100265 * Matches a UDP destination port number with mask.
266 *
267 * @param udpPort a UDP destination port number
268 * @param mask a mask for a UDP destination port number
269 * @return a selection builder
270 */
271 Builder matchUdpDstMasked(TpPort udpPort, TpPort mask);
272
273 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700274 * Matches a SCTP source port number.
275 *
276 * @param sctpPort a SCTP source port number
277 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800278 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700279 Builder matchSctpSrc(TpPort sctpPort);
280
281 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100282 * Matches a SCTP source port number with mask.
283 *
284 * @param sctpPort a SCTP source port number
285 * @param mask a mask for a SCTP source port number
286 * @return a selection builder
287 */
288 Builder matchSctpSrcMasked(TpPort sctpPort, TpPort mask);
289
290 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700291 * Matches a SCTP destination port number.
292 *
293 * @param sctpPort a SCTP destination port number
294 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800295 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700296 Builder matchSctpDst(TpPort sctpPort);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800297
298 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100299 * Matches a SCTP destination port number with mask.
300 *
301 * @param sctpPort a SCTP destination port number
302 * @param mask a mask for a SCTP destination port number
303 * @return a selection builder
304 */
305 Builder matchSctpDstMasked(TpPort sctpPort, TpPort mask);
306
307 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800308 * Matches an ICMP type.
309 *
310 * @param icmpType an ICMP type
311 * @return a selection builder
312 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700313 Builder matchIcmpType(byte icmpType);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800314
315 /**
316 * Matches an ICMP code.
317 *
318 * @param icmpCode an ICMP code
319 * @return a selection builder
320 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700321 Builder matchIcmpCode(byte icmpCode);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800322
323 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800324 * Matches a l3 IPv6 address.
325 *
326 * @param ip a l3 IPv6 address
327 * @return a selection builder
328 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700329 Builder matchIPv6Src(IpPrefix ip);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800330
331 /**
332 * Matches a l3 IPv6 address.
333 *
334 * @param ip a l3 IPv6 address
335 * @return a selection builder
336 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700337 Builder matchIPv6Dst(IpPrefix ip);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800338
339 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800340 * Matches an IPv6 flow label.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800341 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800342 * @param flowLabel an IPv6 flow label
343 * @return a selection builder
344 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700345 Builder matchIPv6FlowLabel(int flowLabel);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800346
347 /**
348 * Matches an ICMPv6 type.
349 *
350 * @param icmpv6Type an ICMPv6 type
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800351 * @return a selection builder
352 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700353 Builder matchIcmpv6Type(byte icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800354
355 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800356 * Matches an ICMPv6 code.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800357 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800358 * @param icmpv6Code an ICMPv6 code
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800359 * @return a selection builder
360 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700361 Builder matchIcmpv6Code(byte icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800362
363 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800364 * Matches an IPv6 Neighbor Discovery target address.
365 *
366 * @param targetAddress an IPv6 Neighbor Discovery target address
367 * @return a selection builder
368 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700369 Builder matchIPv6NDTargetAddress(Ip6Address targetAddress);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800370
371 /**
372 * Matches an IPv6 Neighbor Discovery source link-layer address.
373 *
374 * @param mac an IPv6 Neighbor Discovery source link-layer address
375 * @return a selection builder
376 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700377 Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800378
379 /**
380 * Matches an IPv6 Neighbor Discovery target link-layer address.
381 *
382 * @param mac an IPv6 Neighbor Discovery target link-layer address
383 * @return a selection builder
384 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700385 Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800386
387 /**
388 * Matches on a MPLS label.
389 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800390 * @param mplsLabel a MPLS label.
391 * @return a selection builder
392 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700393 Builder matchMplsLabel(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800394
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700395 /**
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700396 * Matches on a MPLS Bottom-of-Stack indicator bit.
397 *
398 * @param mplsBos boolean value indicating BOS=1 (true) or BOS=0 (false).
399 * @return a selection builder
400 */
401 Builder matchMplsBos(boolean mplsBos);
402
403 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700404 * Matches a tunnel id.
405 *
406 * @param tunnelId a tunnel id
407 * @return a selection builder
408 */
409 Builder matchTunnelId(long tunnelId);
410
411 /**
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700412 * Matches on IPv6 Extension Header pseudo-field flags.
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800413 *
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700414 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800415 * @return a selection builder
416 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700417 Builder matchIPv6ExthdrFlags(short exthdrFlags);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800418
419 /**
BitOhenryb2f8e812015-11-17 19:19:53 +0800420 * Matches a arp IPv4 destination address.
421 *
422 * @param addr a arp IPv4 destination address
423 * @return a selection builder
424 */
425 Builder matchArpTpa(Ip4Address addr);
426
427 /**
BitOhenry08c72942015-11-18 14:44:29 +0800428 * Matches a arp IPv4 source address.
429 *
430 * @param addr a arp IPv4 source address
431 * @return a selection builder
432 */
433 Builder matchArpSpa(Ip4Address addr);
434
435 /**
BitOhenry914c7ad2015-11-16 14:58:53 +0800436 * Matches a arp_eth_dst address.
437 *
438 * @param addr a arp_eth_dst address
439 * @return a selection builder
440 */
441 Builder matchArpTha(MacAddress addr);
442
443 /**
BitOhenrye330cf02015-11-17 18:59:33 +0800444 * Matches a arp_eth_src address.
445 *
446 * @param addr a arp_eth_src address
447 * @return a selection builder
448 */
449 Builder matchArpSha(MacAddress addr);
450
451 /**
BitOhenryb40129a2015-11-30 12:41:18 +0800452 * Matches a arp operation type.
453 *
454 * @param arpOp a arp operation type
455 * @return a selection builder
456 */
457 Builder matchArpOp(int arpOp);
458
459 /**
Jonathan Hart26a8d952015-12-02 15:16:35 -0800460 * Uses an extension selector.
461 *
462 * @param extensionSelector extension selector
463 * @param deviceId device ID
464 * @return a selection builder
465 */
466 Builder extension(ExtensionSelector extensionSelector, DeviceId deviceId);
467
468 /**
tom8bb16062014-09-12 14:47:46 -0700469 * Builds an immutable traffic selector.
470 *
471 * @return traffic selector
472 */
473 TrafficSelector build();
474 }
tom8bb16062014-09-12 14:47:46 -0700475}