blob: f61b017ebbe55a06a4fd26b832ae5eaa85a0f25c [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;
Cem Türker3baff672017-10-12 15:09:01 +030019import java.util.Map;
cansu.toprak409289d2017-10-27 10:04:05 +030020import java.util.Set;
Yafit Hadar5796d972015-10-15 13:16:11 +030021
Frank Wangdf383212017-06-23 09:17:41 +080022import com.google.common.annotations.Beta;
alshabib7b808c52015-06-26 14:22:24 -070023import org.onlab.packet.EthType;
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -070024import org.onlab.packet.IpAddress;
alshabib010c31d2014-09-26 10:01:12 -070025import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010026import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070027import org.onlab.packet.TpPort;
alshabib010c31d2014-09-26 10:01:12 -070028import org.onlab.packet.VlanId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080029import org.onosproject.core.GroupId;
Jonathan Hart3c259162015-10-21 21:31:19 -070030import org.onosproject.net.DeviceId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080031import org.onosproject.net.PortNumber;
alshabib880b6442015-11-23 22:13:04 -080032import org.onosproject.net.flow.instructions.ExtensionTreatment;
Jonathan Hart54b406b2015-03-06 16:24:14 -080033import org.onosproject.net.flow.instructions.Instruction;
alshabib346b5b32015-03-06 00:42:16 -080034import org.onosproject.net.flow.instructions.Instructions;
alshabib10c810b2015-08-18 16:59:04 -070035import org.onosproject.net.meter.MeterId;
Frank Wangdf383212017-06-23 09:17:41 +080036import org.onosproject.net.pi.runtime.PiTableAction;
alshabib55a55d92014-09-16 11:59:31 -070037
tom8bb16062014-09-12 14:47:46 -070038/**
39 * Abstraction of network traffic treatment.
40 */
41public interface TrafficTreatment {
42
43 /**
alshabib346b5b32015-03-06 00:42:16 -080044 * Returns the list of treatment instructions that will be applied
45 * further down the pipeline.
46 * @return list of treatment instructions
47 */
48 List<Instruction> deferred();
49
50 /**
51 * Returns the list of treatment instructions that will be applied
52 * immediately.
53 * @return list of treatment instructions
54 */
55 List<Instruction> immediate();
56
57 /**
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -070058 * Returns the list of all instructions in the treatment, both immediate and
59 * deferred.
60 *
61 * @return list of treatment instructions
62 */
63 List<Instruction> allInstructions();
64
65 /**
alshabib346b5b32015-03-06 00:42:16 -080066 * Returns the next table in the pipeline.
67 * @return a table transition; may be null.
68 */
69 Instructions.TableTypeTransition tableTransition();
70
71 /**
72 * Whether the deferred treatment instructions will be cleared
73 * by the device.
74 * @return a boolean
75 */
Jonathan Hart4a0ba562015-03-23 17:23:33 -070076 boolean clearedDeferred();
alshabib346b5b32015-03-06 00:42:16 -080077
78 /**
Saurav Das86af8f12015-05-25 23:55:33 -070079 * Returns the metadata instruction if there is one.
80 *
81 * @return a metadata instruction that may be null
82 */
83 Instructions.MetadataInstruction writeMetadata();
84
85 /**
Cem Türker3baff672017-10-12 15:09:01 +030086 * Returns the stat trigger instruction if there is one.
87 * @return a stat trigger instruction; may be null.
88 */
89 Instructions.StatTriggerInstruction statTrigger();
90
91 /**
alshabib10c810b2015-08-18 16:59:04 -070092 * Returns the meter instruction if there is one.
93 *
cansu.toprak409289d2017-10-27 10:04:05 +030094 * @return a meter instruction that may be a null.
alshabib10c810b2015-08-18 16:59:04 -070095 */
96 Instructions.MeterInstruction metered();
97
98 /**
cansu.toprak409289d2017-10-27 10:04:05 +030099 * Returns the meter instructions if there is any.
100 *
101 * @return meter instructions that may be an empty set.
102 */
103 Set<Instructions.MeterInstruction> meters();
104
105 /**
tom8bb16062014-09-12 14:47:46 -0700106 * Builder of traffic treatment entities.
107 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700108 interface Builder {
tom8bb16062014-09-12 14:47:46 -0700109
110 /**
alshabib010c31d2014-09-26 10:01:12 -0700111 * Adds an instruction to the builder.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800112 *
alshabib010c31d2014-09-26 10:01:12 -0700113 * @param instruction an instruction
114 * @return a treatment builder
tom8bb16062014-09-12 14:47:46 -0700115 */
alshabib369d2942014-09-12 17:59:35 -0700116 Builder add(Instruction instruction);
tom8bb16062014-09-12 14:47:46 -0700117
118 /**
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800119 * Adds a drop instruction.
120 *
121 * @return a treatment builder
alshabib010c31d2014-09-26 10:01:12 -0700122 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700123 Builder drop();
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800124
125 /**
126 * Adds a punt-to-controller instruction.
127 *
128 * @return a treatment builder
129 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700130 Builder punt();
alshabib010c31d2014-09-26 10:01:12 -0700131
132 /**
133 * Set the output port.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800134 *
alshabib010c31d2014-09-26 10:01:12 -0700135 * @param number the out port
136 * @return a treatment builder
137 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700138 Builder setOutput(PortNumber number);
alshabib010c31d2014-09-26 10:01:12 -0700139
140 /**
141 * Sets the src l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800142 *
alshabib010c31d2014-09-26 10:01:12 -0700143 * @param addr a macaddress
144 * @return a treatment builder
145 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700146 Builder setEthSrc(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700147
148 /**
149 * Sets the dst l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800150 *
alshabib010c31d2014-09-26 10:01:12 -0700151 * @param addr a macaddress
152 * @return a treatment builder
153 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700154 Builder setEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700155
156 /**
157 * Sets the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800158 *
alshabib010c31d2014-09-26 10:01:12 -0700159 * @param id a vlanid
160 * @return a treatment builder
161 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700162 Builder setVlanId(VlanId id);
alshabib010c31d2014-09-26 10:01:12 -0700163
164 /**
165 * Sets the vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800166 *
alshabib010c31d2014-09-26 10:01:12 -0700167 * @param pcp a vlan priority
168 * @return a treatment builder
169 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700170 Builder setVlanPcp(Byte pcp);
alshabib010c31d2014-09-26 10:01:12 -0700171
172 /**
173 * Sets the src l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800174 *
alshabib010c31d2014-09-26 10:01:12 -0700175 * @param addr an ip
176 * @return a treatment builder
177 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700178 Builder setIpSrc(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700179
180 /**
181 * Sets the dst l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800182 *
alshabib010c31d2014-09-26 10:01:12 -0700183 * @param addr an ip
184 * @return a treatment builder
185 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700186 Builder setIpDst(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700187
188 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800189 * Decrement the TTL in IP header by one.
sangho3f97a17d2015-01-29 22:56:29 -0800190 *
191 * @return a treatment builder
192 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700193 Builder decNwTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800194
195 /**
196 * Copy the TTL to outer protocol layer.
197 *
198 * @return a treatment builder
199 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700200 Builder copyTtlOut();
sangho3f97a17d2015-01-29 22:56:29 -0800201
202 /**
203 * Copy the TTL to inner protocol layer.
204 *
205 * @return a treatment builder
206 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700207 Builder copyTtlIn();
sangho3f97a17d2015-01-29 22:56:29 -0800208
209 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800210 * Push MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800211 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700212 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800213 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700214 Builder pushMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800215
216 /**
217 * Pops MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800218 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700219 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800220 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700221 Builder popMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800222
223 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100224 * Pops MPLS ether type and set the new ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800225 *
Michele Santuari4b6019e2014-12-19 11:31:45 +0100226 * @param etherType an ether type
Jonathan Hart3e594642015-10-20 17:31:24 -0700227 * @return a treatment builder
alshabib7b808c52015-06-26 14:22:24 -0700228 */
229 Builder popMpls(EthType etherType);
230
231 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800232 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800233 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700234 * @param mplsLabel MPLS label
235 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800236 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700237 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800238
239 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700240 * Sets the mpls bottom-of-stack indicator bit.
241 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700242 * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false)
Saurav Das73a7dd42015-08-19 22:20:31 -0700243 * @return a treatment builder.
244 */
245 Builder setMplsBos(boolean mplsBos);
246
247 /**
sangho3f97a17d2015-01-29 22:56:29 -0800248 * Decrement MPLS TTL.
249 *
250 * @return a treatment builder
251 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700252 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800253
254 /**
sangho8995ac52015-02-04 11:29:03 -0800255 * Sets the group ID.
256 *
257 * @param groupId group ID
258 * @return a treatment builder
259 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700260 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800261
alshabib10c810b2015-08-18 16:59:04 -0700262 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200263 * Sets the Queue ID.
264 *
265 * @param queueId a queue ID
266 * @return a treatment builder
267 */
268 Builder setQueue(long queueId);
269
270 /**
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200271 * Sets the Queue ID for a specific port.
272 *
273 * @param queueId a queue ID
274 * @param port a port number
275 * @return a treatment builder
276 */
277 Builder setQueue(long queueId, PortNumber port);
278
279 /**
alshabib10c810b2015-08-18 16:59:04 -0700280 * Sets a meter to be used by this flow.
281 *
282 * @param meterId a meter id
283 * @return a treatment builder
284 */
285 Builder meter(MeterId meterId);
alshabib9af70072015-02-09 14:34:16 -0800286
287 /**
alshabibd17abc22015-04-21 18:26:35 -0700288 * Sets the next table id to transition to.
289 *
290 * @param tableId the table table
291 * @return a treatement builder
292 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700293 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700294
295
296 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800297 * Pops outermost VLAN tag.
298 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700299 * @return a treatment builder
Saurav Dasfbe25c52015-03-04 11:12:00 -0800300 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700301 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800302
303 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800304 * Pushes a new VLAN tag.
305 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700306 * @return a treatment builder
Jonathan Hart54b406b2015-03-06 16:24:14 -0800307 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700308 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800309
310 /**
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500311 * Pushes a new VLAN tag using the supplied Ethernet type.
312 *
Ray Milkeyef794342016-11-09 16:20:29 -0800313 * @param ethType ethernet type
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500314 * @return a treatment builder
315 */
316 Builder pushVlan(EthType ethType);
317
318 /**
alshabib346b5b32015-03-06 00:42:16 -0800319 * Any instructions preceded by this method call will be deferred.
320 * @return a treatment builder
321 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700322 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800323
324 /**
325 * Any instructions preceded by this method call will be immediate.
326 * @return a treatment builder
327 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700328 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800329
330
331 /**
332 * Instructs the device to clear the deferred instructions set.
333 * @return a treatment builder
334 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700335 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800336
337 /**
HelloONOSaf3b4282017-06-27 16:27:31 +0900338 * the instruction to clear not wipe the deferred instructions set.
339 * @return a treatment builder
340 */
341 Builder notWipeDeferred();
342
343 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700344 * Writes metadata to associate with a packet.
345 * <pre>
346 * {@code
347 * new_metadata = (old_metadata & ̃mask) | (value & mask)
348 * }
349 * </pre>
350 *
351 * @param value the metadata to write
352 * @param mask the masked bits for the value
353 * @return a treatment builder
354 */
355 Builder writeMetadata(long value, long mask);
356
357 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700358 * Sets the tunnel id.
359 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700360 * @param tunnelId a tunnel id
361 * @return a treatment builder
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700362 */
363 Builder setTunnelId(long tunnelId);
364
365 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700366 * Sets the src TCP port.
367 *
368 * @param port a port number
369 * @return a treatment builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700370 */
371 Builder setTcpSrc(TpPort port);
372
373 /**
374 * Sets the dst TCP port.
375 *
376 * @param port a port number
377 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700378 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700379 Builder setTcpDst(TpPort port);
380
381 /**
382 * Sets the src UDP port.
383 *
384 * @param port a port number
385 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700386 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700387 Builder setUdpSrc(TpPort port);
388
389 /**
390 * Sets the dst UDP port.
391 *
392 * @param port a port number
393 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700394 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700395 Builder setUdpDst(TpPort port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700396
397 /**
lishuai3cce60b2015-12-01 19:35:16 +0800398 * Sets the arp src ip address.
399 *
400 * @param addr an ip
401 * @return a treatment builder
402 */
403 Builder setArpSpa(IpAddress addr);
404
405 /**
406 * Sets the arp src mac address.
407 *
408 * @param addr a macaddress
409 * @return a treatment builder
410 */
411 Builder setArpSha(MacAddress addr);
412
413 /**
414 * Sets the arp operation.
415 *
416 * @param op the value of arp operation.
417 * @return a treatment builder.
418 */
419 Builder setArpOp(short op);
420
421 /**
Frank Wangdf383212017-06-23 09:17:41 +0800422 * Sets the protocol independent table action.
423 *
424 * @param piTableAction protocol-independent table action
425 * @return a treatment builder.
426 */
427 @Beta
428 Builder piTableAction(PiTableAction piTableAction);
429
430 /**
Jonathan Hart3c259162015-10-21 21:31:19 -0700431 * Uses an extension treatment.
432 *
433 * @param extension extension treatment
434 * @param deviceId device ID
435 * @return a treatment builder
436 */
alshabib880b6442015-11-23 22:13:04 -0800437 Builder extension(ExtensionTreatment extension, DeviceId deviceId);
Jonathan Hart3c259162015-10-21 21:31:19 -0700438
439 /**
Cem Türker3baff672017-10-12 15:09:01 +0300440 * Add stat trigger instruction.
441 *
442 * @param statTriggerFieldMap defines stat trigger constraints
443 * @param statTriggerFlag describes which circumstances that start will be triggered
444 * @return a treatment builder
445 */
446 Builder statTrigger(Map<StatTriggerField, Long> statTriggerFieldMap,
447 StatTriggerFlag statTriggerFlag);
448
449 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700450 * Add all instructions from another treatment.
451 *
452 * @param treatment another treatment
453 * @return a treatment builder
454 */
455 Builder addTreatment(TrafficTreatment treatment);
456
457 /**
tom8bb16062014-09-12 14:47:46 -0700458 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700459 * <p>
460 * If the treatment is empty when build() is called, it will add a default
461 * drop rule automatically. For a treatment that is actually empty, use
462 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
463 * </p>
tom8bb16062014-09-12 14:47:46 -0700464 *
465 * @return traffic treatment
466 */
467 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700468
tom8bb16062014-09-12 14:47:46 -0700469 }
Saurav Das86af8f12015-05-25 23:55:33 -0700470
tom8bb16062014-09-12 14:47:46 -0700471}