blob: dddacea2a2a9264bab0e5439d6aba97d52d143d2 [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;
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 * @deprecated in Drake release
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700211 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700212 @Deprecated
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700213 Builder matchTcpSrc(short tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700214
215 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700216 * Matches a TCP source port number.
217 *
218 * @param tcpPort a TCP source port number
219 * @return a selection builder
220 */
221 Builder matchTcpSrc(TpPort tcpPort);
222
223 /**
224 * Matches a TCP destination port number.
225 *
226 * @param tcpPort a TCP destination port number
227 * @return a selection builder
228 * @deprecated in Drake release
229 */
230 @Deprecated
231 Builder matchTcpDst(short tcpPort);
232
233 /**
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700234 * Matches a TCP destination port number.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800235 *
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700236 * @param tcpPort a TCP destination port number
237 * @return a selection builder
238 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700239 Builder matchTcpDst(TpPort tcpPort);
240
241 /**
242 * Matches an UDP source port number.
243 *
244 * @param udpPort an UDP source port number
245 * @return a selection builder
246 * @deprecated in Drake release
247 */
248 @Deprecated
249 Builder matchUdpSrc(short udpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700250
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800251 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800252 * Matches an UDP source port number.
253 *
254 * @param udpPort an UDP source port number
255 * @return a selection builder
256 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700257 Builder matchUdpSrc(TpPort udpPort);
258
259 /**
260 * Matches an UDP destination port number.
261 *
262 * @param udpPort an UDP destination port number
263 * @return a selection builder
264 * @deprecated in Drake release
265 */
266 @Deprecated
267 Builder matchUdpDst(short udpPort);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800268
269 /**
270 * Matches an UDP destination port number.
271 *
272 * @param udpPort an UDP destination port number
273 * @return a selection builder
274 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700275 Builder matchUdpDst(TpPort udpPort);
276
277 /**
278 * Matches a SCTP source port number.
279 *
280 * @param sctpPort a SCTP source port number
281 * @return a selection builder
282 * @deprecated in Drake release
283 */
284 @Deprecated
285 Builder matchSctpSrc(short sctpPort);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800286
287 /**
288 * Matches a SCTP source port number.
289 *
290 * @param sctpPort a SCTP source port number
291 * @return a selection builder
292 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700293 Builder matchSctpSrc(TpPort sctpPort);
294
295 /**
296 * Matches a SCTP destination port number.
297 *
298 * @param sctpPort a SCTP destination port number
299 * @return a selection builder
300 * @deprecated in Drake release
301 */
302 @Deprecated
303 Builder matchSctpDst(short sctpPort);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800304
305 /**
306 * Matches a SCTP destination port number.
307 *
308 * @param sctpPort a SCTP destination port number
309 * @return a selection builder
310 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700311 Builder matchSctpDst(TpPort sctpPort);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800312
313 /**
314 * Matches an ICMP type.
315 *
316 * @param icmpType an ICMP type
317 * @return a selection builder
318 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700319 Builder matchIcmpType(byte icmpType);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800320
321 /**
322 * Matches an ICMP code.
323 *
324 * @param icmpCode an ICMP code
325 * @return a selection builder
326 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700327 Builder matchIcmpCode(byte icmpCode);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800328
329 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800330 * Matches a l3 IPv6 address.
331 *
332 * @param ip a l3 IPv6 address
333 * @return a selection builder
334 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700335 Builder matchIPv6Src(IpPrefix ip);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800336
337 /**
338 * Matches a l3 IPv6 address.
339 *
340 * @param ip a l3 IPv6 address
341 * @return a selection builder
342 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700343 Builder matchIPv6Dst(IpPrefix ip);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800344
345 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800346 * Matches an IPv6 flow label.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800347 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800348 * @param flowLabel an IPv6 flow label
349 * @return a selection builder
350 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700351 Builder matchIPv6FlowLabel(int flowLabel);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800352
353 /**
354 * Matches an ICMPv6 type.
355 *
356 * @param icmpv6Type an ICMPv6 type
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800357 * @return a selection builder
358 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700359 Builder matchIcmpv6Type(byte icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800360
361 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800362 * Matches an ICMPv6 code.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800363 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800364 * @param icmpv6Code an ICMPv6 code
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800365 * @return a selection builder
366 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700367 Builder matchIcmpv6Code(byte icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800368
369 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800370 * Matches an IPv6 Neighbor Discovery target address.
371 *
372 * @param targetAddress an IPv6 Neighbor Discovery target address
373 * @return a selection builder
374 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700375 Builder matchIPv6NDTargetAddress(Ip6Address targetAddress);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800376
377 /**
378 * Matches an IPv6 Neighbor Discovery source link-layer address.
379 *
380 * @param mac an IPv6 Neighbor Discovery source link-layer address
381 * @return a selection builder
382 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700383 Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800384
385 /**
386 * Matches an IPv6 Neighbor Discovery target link-layer address.
387 *
388 * @param mac an IPv6 Neighbor Discovery target link-layer address
389 * @return a selection builder
390 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700391 Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800392
393 /**
394 * Matches on a MPLS label.
395 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800396 * @param mplsLabel a MPLS label.
397 * @return a selection builder
398 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700399 Builder matchMplsLabel(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800400
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700401 /**
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700402 * Matches on a MPLS Bottom-of-Stack indicator bit.
403 *
404 * @param mplsBos boolean value indicating BOS=1 (true) or BOS=0 (false).
405 * @return a selection builder
406 */
407 Builder matchMplsBos(boolean mplsBos);
408
409 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700410 * Matches a tunnel id.
411 *
412 * @param tunnelId a tunnel id
413 * @return a selection builder
414 */
415 Builder matchTunnelId(long tunnelId);
416
417 /**
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700418 * Matches on IPv6 Extension Header pseudo-field flags.
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800419 *
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700420 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800421 * @return a selection builder
422 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700423 Builder matchIPv6ExthdrFlags(short exthdrFlags);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800424
425 /**
BitOhenryb2f8e812015-11-17 19:19:53 +0800426 * Matches a arp IPv4 destination address.
427 *
428 * @param addr a arp IPv4 destination address
429 * @return a selection builder
430 */
431 Builder matchArpTpa(Ip4Address addr);
432
433 /**
BitOhenry08c72942015-11-18 14:44:29 +0800434 * Matches a arp IPv4 source address.
435 *
436 * @param addr a arp IPv4 source address
437 * @return a selection builder
438 */
439 Builder matchArpSpa(Ip4Address addr);
440
441 /**
BitOhenry914c7ad2015-11-16 14:58:53 +0800442 * Matches a arp_eth_dst address.
443 *
444 * @param addr a arp_eth_dst address
445 * @return a selection builder
446 */
447 Builder matchArpTha(MacAddress addr);
448
449 /**
BitOhenrye330cf02015-11-17 18:59:33 +0800450 * Matches a arp_eth_src address.
451 *
452 * @param addr a arp_eth_src address
453 * @return a selection builder
454 */
455 Builder matchArpSha(MacAddress addr);
456
457 /**
BitOhenryb40129a2015-11-30 12:41:18 +0800458 * Matches a arp operation type.
459 *
460 * @param arpOp a arp operation type
461 * @return a selection builder
462 */
463 Builder matchArpOp(int arpOp);
464
465 /**
Jonathan Hart26a8d952015-12-02 15:16:35 -0800466 * Uses an extension selector.
467 *
468 * @param extensionSelector extension selector
469 * @param deviceId device ID
470 * @return a selection builder
471 */
472 Builder extension(ExtensionSelector extensionSelector, DeviceId deviceId);
473
474 /**
tom8bb16062014-09-12 14:47:46 -0700475 * Builds an immutable traffic selector.
476 *
477 * @return traffic selector
478 */
479 TrafficSelector build();
480 }
tom8bb16062014-09-12 14:47:46 -0700481}