blob: 9ddabe180d206e1373b401be1b8da73ce3f198b1 [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
Yafit Hadar5796d972015-10-15 13:16:11 +030018import java.util.List;
19
Frank Wangdf383212017-06-23 09:17:41 +080020import com.google.common.annotations.Beta;
alshabib7b808c52015-06-26 14:22:24 -070021import org.onlab.packet.EthType;
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -070022import org.onlab.packet.IpAddress;
alshabib010c31d2014-09-26 10:01:12 -070023import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010024import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070025import org.onlab.packet.TpPort;
alshabib010c31d2014-09-26 10:01:12 -070026import org.onlab.packet.VlanId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080027import org.onosproject.core.GroupId;
Jonathan Hart3c259162015-10-21 21:31:19 -070028import org.onosproject.net.DeviceId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080029import org.onosproject.net.PortNumber;
alshabib880b6442015-11-23 22:13:04 -080030import org.onosproject.net.flow.instructions.ExtensionTreatment;
Jonathan Hart54b406b2015-03-06 16:24:14 -080031import org.onosproject.net.flow.instructions.Instruction;
alshabib346b5b32015-03-06 00:42:16 -080032import org.onosproject.net.flow.instructions.Instructions;
alshabib10c810b2015-08-18 16:59:04 -070033import org.onosproject.net.meter.MeterId;
Frank Wangdf383212017-06-23 09:17:41 +080034import org.onosproject.net.pi.runtime.PiTableAction;
alshabib55a55d92014-09-16 11:59:31 -070035
tom8bb16062014-09-12 14:47:46 -070036/**
37 * Abstraction of network traffic treatment.
38 */
39public interface TrafficTreatment {
40
41 /**
alshabib346b5b32015-03-06 00:42:16 -080042 * Returns the list of treatment instructions that will be applied
43 * further down the pipeline.
44 * @return list of treatment instructions
45 */
46 List<Instruction> deferred();
47
48 /**
49 * Returns the list of treatment instructions that will be applied
50 * immediately.
51 * @return list of treatment instructions
52 */
53 List<Instruction> immediate();
54
55 /**
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -070056 * Returns the list of all instructions in the treatment, both immediate and
57 * deferred.
58 *
59 * @return list of treatment instructions
60 */
61 List<Instruction> allInstructions();
62
63 /**
alshabib346b5b32015-03-06 00:42:16 -080064 * Returns the next table in the pipeline.
65 * @return a table transition; may be null.
66 */
67 Instructions.TableTypeTransition tableTransition();
68
69 /**
70 * Whether the deferred treatment instructions will be cleared
71 * by the device.
72 * @return a boolean
73 */
Jonathan Hart4a0ba562015-03-23 17:23:33 -070074 boolean clearedDeferred();
alshabib346b5b32015-03-06 00:42:16 -080075
76 /**
Saurav Das86af8f12015-05-25 23:55:33 -070077 * Returns the metadata instruction if there is one.
78 *
79 * @return a metadata instruction that may be null
80 */
81 Instructions.MetadataInstruction writeMetadata();
82
83 /**
alshabib10c810b2015-08-18 16:59:04 -070084 * Returns the meter instruction if there is one.
85 *
86 * @return a meter instruction that may be null
87 */
88 Instructions.MeterInstruction metered();
89
90 /**
tom8bb16062014-09-12 14:47:46 -070091 * Builder of traffic treatment entities.
92 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070093 interface Builder {
tom8bb16062014-09-12 14:47:46 -070094
95 /**
alshabib010c31d2014-09-26 10:01:12 -070096 * Adds an instruction to the builder.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080097 *
alshabib010c31d2014-09-26 10:01:12 -070098 * @param instruction an instruction
99 * @return a treatment builder
tom8bb16062014-09-12 14:47:46 -0700100 */
alshabib369d2942014-09-12 17:59:35 -0700101 Builder add(Instruction instruction);
tom8bb16062014-09-12 14:47:46 -0700102
103 /**
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800104 * Adds a drop instruction.
105 *
106 * @return a treatment builder
alshabib010c31d2014-09-26 10:01:12 -0700107 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700108 Builder drop();
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800109
110 /**
111 * Adds a punt-to-controller instruction.
112 *
113 * @return a treatment builder
114 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700115 Builder punt();
alshabib010c31d2014-09-26 10:01:12 -0700116
117 /**
118 * Set the output port.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800119 *
alshabib010c31d2014-09-26 10:01:12 -0700120 * @param number the out port
121 * @return a treatment builder
122 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700123 Builder setOutput(PortNumber number);
alshabib010c31d2014-09-26 10:01:12 -0700124
125 /**
126 * Sets the src l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800127 *
alshabib010c31d2014-09-26 10:01:12 -0700128 * @param addr a macaddress
129 * @return a treatment builder
130 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700131 Builder setEthSrc(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700132
133 /**
134 * Sets the dst l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800135 *
alshabib010c31d2014-09-26 10:01:12 -0700136 * @param addr a macaddress
137 * @return a treatment builder
138 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700139 Builder setEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700140
141 /**
142 * Sets the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800143 *
alshabib010c31d2014-09-26 10:01:12 -0700144 * @param id a vlanid
145 * @return a treatment builder
146 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700147 Builder setVlanId(VlanId id);
alshabib010c31d2014-09-26 10:01:12 -0700148
149 /**
150 * Sets the vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800151 *
alshabib010c31d2014-09-26 10:01:12 -0700152 * @param pcp a vlan priority
153 * @return a treatment builder
154 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700155 Builder setVlanPcp(Byte pcp);
alshabib010c31d2014-09-26 10:01:12 -0700156
157 /**
158 * Sets the src l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800159 *
alshabib010c31d2014-09-26 10:01:12 -0700160 * @param addr an ip
161 * @return a treatment builder
162 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700163 Builder setIpSrc(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700164
165 /**
166 * Sets the dst l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800167 *
alshabib010c31d2014-09-26 10:01:12 -0700168 * @param addr an ip
169 * @return a treatment builder
170 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700171 Builder setIpDst(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700172
173 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800174 * Decrement the TTL in IP header by one.
sangho3f97a17d2015-01-29 22:56:29 -0800175 *
176 * @return a treatment builder
177 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700178 Builder decNwTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800179
180 /**
181 * Copy the TTL to outer protocol layer.
182 *
183 * @return a treatment builder
184 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700185 Builder copyTtlOut();
sangho3f97a17d2015-01-29 22:56:29 -0800186
187 /**
188 * Copy the TTL to inner protocol layer.
189 *
190 * @return a treatment builder
191 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700192 Builder copyTtlIn();
sangho3f97a17d2015-01-29 22:56:29 -0800193
194 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800195 * Push MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800196 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700197 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800198 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700199 Builder pushMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800200
201 /**
202 * Pops MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800203 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700204 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800205 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700206 Builder popMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800207
208 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100209 * Pops MPLS ether type and set the new ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800210 *
Michele Santuari4b6019e2014-12-19 11:31:45 +0100211 * @param etherType an ether type
Jonathan Hart3e594642015-10-20 17:31:24 -0700212 * @return a treatment builder
alshabib7b808c52015-06-26 14:22:24 -0700213 */
214 Builder popMpls(EthType etherType);
215
216 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800217 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800218 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700219 * @param mplsLabel MPLS label
220 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800221 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700222 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800223
224 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700225 * Sets the mpls bottom-of-stack indicator bit.
226 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700227 * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false)
Saurav Das73a7dd42015-08-19 22:20:31 -0700228 * @return a treatment builder.
229 */
230 Builder setMplsBos(boolean mplsBos);
231
232 /**
sangho3f97a17d2015-01-29 22:56:29 -0800233 * Decrement MPLS TTL.
234 *
235 * @return a treatment builder
236 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700237 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800238
239 /**
sangho8995ac52015-02-04 11:29:03 -0800240 * Sets the group ID.
241 *
242 * @param groupId group ID
243 * @return a treatment builder
244 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700245 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800246
alshabib10c810b2015-08-18 16:59:04 -0700247 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200248 * Sets the Queue ID.
249 *
250 * @param queueId a queue ID
251 * @return a treatment builder
252 */
253 Builder setQueue(long queueId);
254
255 /**
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200256 * Sets the Queue ID for a specific port.
257 *
258 * @param queueId a queue ID
259 * @param port a port number
260 * @return a treatment builder
261 */
262 Builder setQueue(long queueId, PortNumber port);
263
264 /**
alshabib10c810b2015-08-18 16:59:04 -0700265 * Sets a meter to be used by this flow.
266 *
267 * @param meterId a meter id
268 * @return a treatment builder
269 */
270 Builder meter(MeterId meterId);
alshabib9af70072015-02-09 14:34:16 -0800271
272 /**
alshabibd17abc22015-04-21 18:26:35 -0700273 * Sets the next table id to transition to.
274 *
275 * @param tableId the table table
276 * @return a treatement builder
277 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700278 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700279
280
281 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800282 * Pops outermost VLAN tag.
283 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700284 * @return a treatment builder
Saurav Dasfbe25c52015-03-04 11:12:00 -0800285 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700286 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800287
288 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800289 * Pushes a new VLAN tag.
290 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700291 * @return a treatment builder
Jonathan Hart54b406b2015-03-06 16:24:14 -0800292 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700293 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800294
295 /**
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500296 * Pushes a new VLAN tag using the supplied Ethernet type.
297 *
Ray Milkeyef794342016-11-09 16:20:29 -0800298 * @param ethType ethernet type
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500299 * @return a treatment builder
300 */
301 Builder pushVlan(EthType ethType);
302
303 /**
alshabib346b5b32015-03-06 00:42:16 -0800304 * Any instructions preceded by this method call will be deferred.
305 * @return a treatment builder
306 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700307 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800308
309 /**
310 * Any instructions preceded by this method call will be immediate.
311 * @return a treatment builder
312 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700313 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800314
315
316 /**
317 * Instructs the device to clear the deferred instructions set.
318 * @return a treatment builder
319 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700320 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800321
322 /**
HelloONOSaf3b4282017-06-27 16:27:31 +0900323 * the instruction to clear not wipe the deferred instructions set.
324 * @return a treatment builder
325 */
326 Builder notWipeDeferred();
327
328 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700329 * Writes metadata to associate with a packet.
330 * <pre>
331 * {@code
332 * new_metadata = (old_metadata & ̃mask) | (value & mask)
333 * }
334 * </pre>
335 *
336 * @param value the metadata to write
337 * @param mask the masked bits for the value
338 * @return a treatment builder
339 */
340 Builder writeMetadata(long value, long mask);
341
342 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700343 * Sets the tunnel id.
344 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700345 * @param tunnelId a tunnel id
346 * @return a treatment builder
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700347 */
348 Builder setTunnelId(long tunnelId);
349
350 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700351 * Sets the src TCP port.
352 *
353 * @param port a port number
354 * @return a treatment builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700355 */
356 Builder setTcpSrc(TpPort port);
357
358 /**
359 * Sets the dst TCP port.
360 *
361 * @param port a port number
362 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700363 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700364 Builder setTcpDst(TpPort port);
365
366 /**
367 * Sets the src UDP port.
368 *
369 * @param port a port number
370 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700371 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700372 Builder setUdpSrc(TpPort port);
373
374 /**
375 * Sets the dst UDP port.
376 *
377 * @param port a port number
378 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700379 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700380 Builder setUdpDst(TpPort port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700381
382 /**
lishuai3cce60b2015-12-01 19:35:16 +0800383 * Sets the arp src ip address.
384 *
385 * @param addr an ip
386 * @return a treatment builder
387 */
388 Builder setArpSpa(IpAddress addr);
389
390 /**
391 * Sets the arp src mac address.
392 *
393 * @param addr a macaddress
394 * @return a treatment builder
395 */
396 Builder setArpSha(MacAddress addr);
397
398 /**
399 * Sets the arp operation.
400 *
401 * @param op the value of arp operation.
402 * @return a treatment builder.
403 */
404 Builder setArpOp(short op);
405
406 /**
Frank Wangdf383212017-06-23 09:17:41 +0800407 * Sets the protocol independent table action.
408 *
409 * @param piTableAction protocol-independent table action
410 * @return a treatment builder.
411 */
412 @Beta
413 Builder piTableAction(PiTableAction piTableAction);
414
415 /**
Jonathan Hart3c259162015-10-21 21:31:19 -0700416 * Uses an extension treatment.
417 *
418 * @param extension extension treatment
419 * @param deviceId device ID
420 * @return a treatment builder
421 */
alshabib880b6442015-11-23 22:13:04 -0800422 Builder extension(ExtensionTreatment extension, DeviceId deviceId);
Jonathan Hart3c259162015-10-21 21:31:19 -0700423
424 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700425 * Add all instructions from another treatment.
426 *
427 * @param treatment another treatment
428 * @return a treatment builder
429 */
430 Builder addTreatment(TrafficTreatment treatment);
431
432 /**
tom8bb16062014-09-12 14:47:46 -0700433 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700434 * <p>
435 * If the treatment is empty when build() is called, it will add a default
436 * drop rule automatically. For a treatment that is actually empty, use
437 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
438 * </p>
tom8bb16062014-09-12 14:47:46 -0700439 *
440 * @return traffic treatment
441 */
442 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700443
tom8bb16062014-09-12 14:47:46 -0700444 }
Saurav Das86af8f12015-05-25 23:55:33 -0700445
tom8bb16062014-09-12 14:47:46 -0700446}