blob: 6a018c38fe549f7a24e169a2e402379d7322bb98 [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 /**
214 * Matches a TCP destination port number.
215 *
216 * @param tcpPort a TCP destination port number
217 * @return a selection builder
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700218 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700219 Builder matchTcpDst(TpPort tcpPort);
220
221 /**
222 * Matches an UDP source port number.
223 *
224 * @param udpPort an UDP source port number
225 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800226 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700227 Builder matchUdpSrc(TpPort udpPort);
228
229 /**
230 * Matches an UDP destination port number.
231 *
232 * @param udpPort an UDP destination port number
233 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800234 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700235 Builder matchUdpDst(TpPort udpPort);
236
237 /**
238 * Matches a SCTP source port number.
239 *
240 * @param sctpPort a SCTP source port number
241 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800242 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700243 Builder matchSctpSrc(TpPort sctpPort);
244
245 /**
246 * Matches a SCTP destination port number.
247 *
248 * @param sctpPort a SCTP destination port number
249 * @return a selection builder
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800250 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700251 Builder matchSctpDst(TpPort sctpPort);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800252
253 /**
254 * Matches an ICMP type.
255 *
256 * @param icmpType an ICMP type
257 * @return a selection builder
258 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700259 Builder matchIcmpType(byte icmpType);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800260
261 /**
262 * Matches an ICMP code.
263 *
264 * @param icmpCode an ICMP code
265 * @return a selection builder
266 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700267 Builder matchIcmpCode(byte icmpCode);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800268
269 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800270 * Matches a l3 IPv6 address.
271 *
272 * @param ip a l3 IPv6 address
273 * @return a selection builder
274 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700275 Builder matchIPv6Src(IpPrefix ip);
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800276
277 /**
278 * Matches a l3 IPv6 address.
279 *
280 * @param ip a l3 IPv6 address
281 * @return a selection builder
282 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700283 Builder matchIPv6Dst(IpPrefix ip);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800284
285 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800286 * Matches an IPv6 flow label.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800287 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800288 * @param flowLabel an IPv6 flow label
289 * @return a selection builder
290 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700291 Builder matchIPv6FlowLabel(int flowLabel);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800292
293 /**
294 * Matches an ICMPv6 type.
295 *
296 * @param icmpv6Type an ICMPv6 type
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800297 * @return a selection builder
298 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700299 Builder matchIcmpv6Type(byte icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800300
301 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800302 * Matches an ICMPv6 code.
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800303 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800304 * @param icmpv6Code an ICMPv6 code
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800305 * @return a selection builder
306 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700307 Builder matchIcmpv6Code(byte icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800308
309 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800310 * Matches an IPv6 Neighbor Discovery target address.
311 *
312 * @param targetAddress an IPv6 Neighbor Discovery target address
313 * @return a selection builder
314 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700315 Builder matchIPv6NDTargetAddress(Ip6Address targetAddress);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800316
317 /**
318 * Matches an IPv6 Neighbor Discovery source link-layer address.
319 *
320 * @param mac an IPv6 Neighbor Discovery source link-layer address
321 * @return a selection builder
322 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700323 Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800324
325 /**
326 * Matches an IPv6 Neighbor Discovery target link-layer address.
327 *
328 * @param mac an IPv6 Neighbor Discovery target link-layer address
329 * @return a selection builder
330 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700331 Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800332
333 /**
334 * Matches on a MPLS label.
335 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800336 * @param mplsLabel a MPLS label.
337 * @return a selection builder
338 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700339 Builder matchMplsLabel(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800340
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700341 /**
Saurav Dasffc5bbc2015-08-18 23:30:19 -0700342 * Matches on a MPLS Bottom-of-Stack indicator bit.
343 *
344 * @param mplsBos boolean value indicating BOS=1 (true) or BOS=0 (false).
345 * @return a selection builder
346 */
347 Builder matchMplsBos(boolean mplsBos);
348
349 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700350 * Matches a tunnel id.
351 *
352 * @param tunnelId a tunnel id
353 * @return a selection builder
354 */
355 Builder matchTunnelId(long tunnelId);
356
357 /**
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700358 * Matches on IPv6 Extension Header pseudo-field flags.
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800359 *
Sho SHIMIZU60f12142015-05-06 14:22:03 -0700360 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800361 * @return a selection builder
362 */
Sho SHIMIZU15c38002015-04-28 19:00:37 -0700363 Builder matchIPv6ExthdrFlags(short exthdrFlags);
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800364
365 /**
BitOhenryb2f8e812015-11-17 19:19:53 +0800366 * Matches a arp IPv4 destination address.
367 *
368 * @param addr a arp IPv4 destination address
369 * @return a selection builder
370 */
371 Builder matchArpTpa(Ip4Address addr);
372
373 /**
BitOhenry08c72942015-11-18 14:44:29 +0800374 * Matches a arp IPv4 source address.
375 *
376 * @param addr a arp IPv4 source address
377 * @return a selection builder
378 */
379 Builder matchArpSpa(Ip4Address addr);
380
381 /**
BitOhenry914c7ad2015-11-16 14:58:53 +0800382 * Matches a arp_eth_dst address.
383 *
384 * @param addr a arp_eth_dst address
385 * @return a selection builder
386 */
387 Builder matchArpTha(MacAddress addr);
388
389 /**
BitOhenrye330cf02015-11-17 18:59:33 +0800390 * Matches a arp_eth_src address.
391 *
392 * @param addr a arp_eth_src address
393 * @return a selection builder
394 */
395 Builder matchArpSha(MacAddress addr);
396
397 /**
BitOhenryb40129a2015-11-30 12:41:18 +0800398 * Matches a arp operation type.
399 *
400 * @param arpOp a arp operation type
401 * @return a selection builder
402 */
403 Builder matchArpOp(int arpOp);
404
405 /**
Jonathan Hart26a8d952015-12-02 15:16:35 -0800406 * Uses an extension selector.
407 *
408 * @param extensionSelector extension selector
409 * @param deviceId device ID
410 * @return a selection builder
411 */
412 Builder extension(ExtensionSelector extensionSelector, DeviceId deviceId);
413
414 /**
tom8bb16062014-09-12 14:47:46 -0700415 * Builds an immutable traffic selector.
416 *
417 * @return traffic selector
418 */
419 TrafficSelector build();
420 }
tom8bb16062014-09-12 14:47:46 -0700421}