blob: e8447b0323e42f16ea0e8d480d0963b3b563b306 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
Frank Wangdf383212017-06-23 09:17:41 +080018import com.google.common.annotations.Beta;
BitOhenryb2f8e812015-11-17 19:19:53 +080019import org.onlab.packet.Ip4Address;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070020import org.onlab.packet.Ip6Address;
21import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.MplsLabel;
24import org.onlab.packet.TpPort;
25import org.onlab.packet.VlanId;
Jonathan Hart26a8d952015-12-02 15:16:35 -080026import org.onosproject.net.DeviceId;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.PortNumber;
28import org.onosproject.net.flow.criteria.Criterion;
Jonathan Hart26a8d952015-12-02 15:16:35 -080029import org.onosproject.net.flow.criteria.ExtensionSelector;
Frank Wangdf383212017-06-23 09:17:41 +080030import org.onosproject.net.flow.criteria.PiCriterion;
Jonathan Hart26a8d952015-12-02 15:16:35 -080031
32import java.util.Set;
alshabib7410fea2014-09-16 13:48:39 -070033
tom8bb16062014-09-12 14:47:46 -070034/**
35 * Abstraction of a slice of network traffic.
36 */
37public interface TrafficSelector {
38
39 /**
40 * Returns selection criteria as an ordered list.
41 *
42 * @return list of criteria
43 */
alshabibba5ac482014-10-02 17:15:20 -070044 Set<Criterion> criteria();
tom8bb16062014-09-12 14:47:46 -070045
46 /**
Jonathan Hart936c49d2014-10-23 16:38:59 -070047 * Returns the selection criterion for a particular type, if it exists in
48 * this traffic selector.
49 *
50 * @param type criterion type to look up
51 * @return the criterion of the specified type if one exists, otherwise null
52 */
53 Criterion getCriterion(Criterion.Type type);
54
55 /**
tom8bb16062014-09-12 14:47:46 -070056 * Builder of traffic selector entities.
57 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070058 interface Builder {
tom8bb16062014-09-12 14:47:46 -070059
60 /**
61 * Adds a traffic selection criterion. If a same type criterion has
62 * already been added, it will be replaced by this one.
63 *
64 * @param criterion new criterion
alshabib369d2942014-09-12 17:59:35 -070065 * @return self
tom8bb16062014-09-12 14:47:46 -070066 */
alshabib369d2942014-09-12 17:59:35 -070067 Builder add(Criterion criterion);
tom8bb16062014-09-12 14:47:46 -070068
69 /**
alshabib010c31d2014-09-26 10:01:12 -070070 * Matches an inport.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080071 *
alshabib010c31d2014-09-26 10:01:12 -070072 * @param port the inport
73 * @return a selection builder
74 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070075 Builder matchInPort(PortNumber port);
alshabib010c31d2014-09-26 10:01:12 -070076
77 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080078 * Matches a physical inport.
79 *
80 * @param port the physical inport
81 * @return a selection builder
82 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070083 Builder matchInPhyPort(PortNumber port);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080084
85 /**
86 * Matches a metadata.
87 *
88 * @param metadata the metadata
89 * @return a selection builder
90 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070091 Builder matchMetadata(long metadata);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080092
93 /**
alshabib010c31d2014-09-26 10:01:12 -070094 * Matches a l2 dst address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080095 *
alshabib010c31d2014-09-26 10:01:12 -070096 * @param addr a l2 address
97 * @return a selection builder
98 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -070099 Builder matchEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700100
101 /**
Saurav Das9d6c86b2016-02-19 09:01:07 -0800102 * Matches a l2 dst address with mask.
103 *
104 * @param addr a l2 address
105 * @param mask a mask for an l2 address
106 * @return a selection builder
107 */
108 Builder matchEthDstMasked(MacAddress addr, MacAddress mask);
109
110 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800111 * Matches a l2 src address.
112 *
113 * @param addr a l2 address
114 * @return a selection builder
115 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700116 Builder matchEthSrc(MacAddress addr);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800117
118 /**
Saurav Das9d6c86b2016-02-19 09:01:07 -0800119 * Matches a l2 src address with mask.
120 *
121 * @param addr a l2 address
122 * @param mask a mask for an l2 address
123 * @return a selection builder
124 */
125 Builder matchEthSrcMasked(MacAddress addr, MacAddress mask);
126
127 /**
alshabib010c31d2014-09-26 10:01:12 -0700128 * Matches the ethernet type.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800129 *
alshabib010c31d2014-09-26 10:01:12 -0700130 * @param ethType an ethernet type
131 * @return a selection builder
132 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700133 Builder matchEthType(short ethType);
alshabib010c31d2014-09-26 10:01:12 -0700134
135 /**
136 * Matches the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800137 *
alshabib010c31d2014-09-26 10:01:12 -0700138 * @param vlanId a vlan id
139 * @return a selection builder
140 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700141 Builder matchVlanId(VlanId vlanId);
alshabib010c31d2014-09-26 10:01:12 -0700142
143 /**
144 * Matches a vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800145 *
alshabib010c31d2014-09-26 10:01:12 -0700146 * @param vlanPcp a vlan priority
147 * @return a selection builder
148 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700149 Builder matchVlanPcp(byte vlanPcp);
alshabib010c31d2014-09-26 10:01:12 -0700150
151 /**
alshabibfa0dc662016-01-13 11:23:53 -0800152 * Matches the inner vlan id.
153 *
154 * @param vlanId a vlan id
155 * @return a selection builder
156 */
157 Builder matchInnerVlanId(VlanId vlanId);
158
159 /**
160 * Matches a vlan priority.
161 *
162 * @param vlanPcp a vlan priority
163 * @return a selection builder
164 */
165 Builder matchInnerVlanPcp(byte vlanPcp);
166
167 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800168 * Matches an IP DSCP (6 bits in ToS field).
169 *
170 * @param ipDscp an IP DSCP value
171 * @return a selection builder
172 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700173 Builder matchIPDscp(byte ipDscp);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800174
175 /**
176 * Matches an IP ECN (2 bits in ToS field).
177 *
178 * @param ipEcn an IP ECN value
179 * @return a selection builder
180 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700181 Builder matchIPEcn(byte ipEcn);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800182
183 /**
alshabib010c31d2014-09-26 10:01:12 -0700184 * Matches the l3 protocol.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800185 *
alshabib010c31d2014-09-26 10:01:12 -0700186 * @param proto a l3 protocol
187 * @return a selection builder
188 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700189 Builder matchIPProtocol(byte proto);
alshabib010c31d2014-09-26 10:01:12 -0700190
191 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800192 * Matches a l3 IPv4 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800193 *
alshabib010c31d2014-09-26 10:01:12 -0700194 * @param ip a l3 address
195 * @return a selection builder
196 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700197 Builder matchIPSrc(IpPrefix ip);
alshabib010c31d2014-09-26 10:01:12 -0700198
199 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800200 * Matches a l3 IPv4 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800201 *
alshabib010c31d2014-09-26 10:01:12 -0700202 * @param ip a l3 address
203 * @return a selection builder
204 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700205 Builder matchIPDst(IpPrefix ip);
alshabib010c31d2014-09-26 10:01:12 -0700206
207 /**
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700208 * Matches a TCP source port number.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800209 *
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700210 * @param tcpPort a TCP source port number
211 * @return a selection builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700212 */
213 Builder matchTcpSrc(TpPort tcpPort);
214
215 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100216 * Matches a TCP source port number with mask.
217 *
218 * @param tcpPort a TCP source port number
219 * @param mask a mask for a TCP source port number
220 * @return a selection builder
221 */
222 Builder matchTcpSrcMasked(TpPort tcpPort, TpPort mask);
223
224 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700225 * Matches a TCP destination port number.
226 *
227 * @param tcpPort a TCP destination port number
228 * @return a selection builder
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700229 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700230 Builder matchTcpDst(TpPort tcpPort);
231
232 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100233 * Matches a TCP destination port number with mask.
234 *
235 * @param tcpPort a TCP destination port number
236 * @param mask a mask for a TCP destination port number
237 * @return a selection builder
238 */
239 Builder matchTcpDstMasked(TpPort tcpPort, TpPort mask);
240
241 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700242 * Matches an UDP source port number.
243 *
244 * @param udpPort an UDP source port number
245 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800246 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700247 Builder matchUdpSrc(TpPort udpPort);
248
249 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100250 * Matches a UDP source port number with mask.
251 *
252 * @param udpPort a UDP source port number
253 * @param mask a mask for a UDP source port number
254 * @return a selection builder
255 */
256 Builder matchUdpSrcMasked(TpPort udpPort, TpPort mask);
257
258 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700259 * Matches an UDP destination port number.
260 *
261 * @param udpPort an UDP destination port number
262 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800263 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700264 Builder matchUdpDst(TpPort udpPort);
265
266 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100267 * Matches a UDP destination port number with mask.
268 *
269 * @param udpPort a UDP destination port number
270 * @param mask a mask for a UDP destination port number
271 * @return a selection builder
272 */
273 Builder matchUdpDstMasked(TpPort udpPort, TpPort mask);
274
275 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700276 * Matches a SCTP source port number.
277 *
278 * @param sctpPort a SCTP source port number
279 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800280 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700281 Builder matchSctpSrc(TpPort sctpPort);
282
283 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100284 * Matches a SCTP source port number with mask.
285 *
286 * @param sctpPort a SCTP source port number
287 * @param mask a mask for a SCTP source port number
288 * @return a selection builder
289 */
290 Builder matchSctpSrcMasked(TpPort sctpPort, TpPort mask);
291
292 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700293 * Matches a SCTP destination port number.
294 *
295 * @param sctpPort a SCTP destination port number
296 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800297 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700298 Builder matchSctpDst(TpPort sctpPort);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800299
300 /**
Andreas Gilbert75b882f72017-02-03 09:58:07 +0100301 * Matches a SCTP destination port number with mask.
302 *
303 * @param sctpPort a SCTP destination port number
304 * @param mask a mask for a SCTP destination port number
305 * @return a selection builder
306 */
307 Builder matchSctpDstMasked(TpPort sctpPort, TpPort mask);
308
309 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800310 * Matches an ICMP type.
311 *
312 * @param icmpType an ICMP type
313 * @return a selection builder
314 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700315 Builder matchIcmpType(byte icmpType);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800316
317 /**
318 * Matches an ICMP code.
319 *
320 * @param icmpCode an ICMP code
321 * @return a selection builder
322 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700323 Builder matchIcmpCode(byte icmpCode);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800324
325 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800326 * Matches a l3 IPv6 address.
327 *
328 * @param ip a l3 IPv6 address
329 * @return a selection builder
330 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700331 Builder matchIPv6Src(IpPrefix ip);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800332
333 /**
334 * Matches a l3 IPv6 address.
335 *
336 * @param ip a l3 IPv6 address
337 * @return a selection builder
338 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700339 Builder matchIPv6Dst(IpPrefix ip);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800340
341 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800342 * Matches an IPv6 flow label.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800343 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800344 * @param flowLabel an IPv6 flow label
345 * @return a selection builder
346 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700347 Builder matchIPv6FlowLabel(int flowLabel);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800348
349 /**
350 * Matches an ICMPv6 type.
351 *
352 * @param icmpv6Type an ICMPv6 type
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800353 * @return a selection builder
354 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700355 Builder matchIcmpv6Type(byte icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800356
357 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800358 * Matches an ICMPv6 code.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800359 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800360 * @param icmpv6Code an ICMPv6 code
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800361 * @return a selection builder
362 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700363 Builder matchIcmpv6Code(byte icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800364
365 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800366 * Matches an IPv6 Neighbor Discovery target address.
367 *
368 * @param targetAddress an IPv6 Neighbor Discovery target address
369 * @return a selection builder
370 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700371 Builder matchIPv6NDTargetAddress(Ip6Address targetAddress);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800372
373 /**
374 * Matches an IPv6 Neighbor Discovery source link-layer address.
375 *
376 * @param mac an IPv6 Neighbor Discovery source link-layer address
377 * @return a selection builder
378 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700379 Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800380
381 /**
382 * Matches an IPv6 Neighbor Discovery target link-layer address.
383 *
384 * @param mac an IPv6 Neighbor Discovery target link-layer address
385 * @return a selection builder
386 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700387 Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800388
389 /**
390 * Matches on a MPLS label.
391 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800392 * @param mplsLabel a MPLS label.
393 * @return a selection builder
394 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700395 Builder matchMplsLabel(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800396
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700397 /**
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700398 * Matches on a MPLS Bottom-of-Stack indicator bit.
399 *
400 * @param mplsBos boolean value indicating BOS=1 (true) or BOS=0 (false).
401 * @return a selection builder
402 */
403 Builder matchMplsBos(boolean mplsBos);
404
405 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700406 * Matches a tunnel id.
407 *
408 * @param tunnelId a tunnel id
409 * @return a selection builder
410 */
411 Builder matchTunnelId(long tunnelId);
412
413 /**
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700414 * Matches on IPv6 Extension Header pseudo-field flags.
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800415 *
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700416 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800417 * @return a selection builder
418 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700419 Builder matchIPv6ExthdrFlags(short exthdrFlags);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800420
421 /**
BitOhenryb2f8e812015-11-17 19:19:53 +0800422 * Matches a arp IPv4 destination address.
423 *
424 * @param addr a arp IPv4 destination address
425 * @return a selection builder
426 */
427 Builder matchArpTpa(Ip4Address addr);
428
429 /**
BitOhenry08c72942015-11-18 14:44:29 +0800430 * Matches a arp IPv4 source address.
431 *
432 * @param addr a arp IPv4 source address
433 * @return a selection builder
434 */
435 Builder matchArpSpa(Ip4Address addr);
436
437 /**
BitOhenry914c7ad2015-11-16 14:58:53 +0800438 * Matches a arp_eth_dst address.
439 *
440 * @param addr a arp_eth_dst address
441 * @return a selection builder
442 */
443 Builder matchArpTha(MacAddress addr);
444
445 /**
BitOhenrye330cf02015-11-17 18:59:33 +0800446 * Matches a arp_eth_src address.
447 *
448 * @param addr a arp_eth_src address
449 * @return a selection builder
450 */
451 Builder matchArpSha(MacAddress addr);
452
453 /**
BitOhenryb40129a2015-11-30 12:41:18 +0800454 * Matches a arp operation type.
455 *
456 * @param arpOp a arp operation type
457 * @return a selection builder
458 */
459 Builder matchArpOp(int arpOp);
460
461 /**
Frank Wangdf383212017-06-23 09:17:41 +0800462 * Matches protocol independent fields.
463 *
464 * @param piCriterion protocol-independent criterion
465 * @return a selection builder
466 */
467 @Beta
468 Builder matchPi(PiCriterion piCriterion);
469
470 /**
Jonathan Hart26a8d952015-12-02 15:16:35 -0800471 * Uses an extension selector.
472 *
473 * @param extensionSelector extension selector
474 * @param deviceId device ID
475 * @return a selection builder
476 */
477 Builder extension(ExtensionSelector extensionSelector, DeviceId deviceId);
478
479 /**
tom8bb16062014-09-12 14:47:46 -0700480 * Builds an immutable traffic selector.
481 *
482 * @return traffic selector
483 */
484 TrafficSelector build();
485 }
tom8bb16062014-09-12 14:47:46 -0700486}