blob: 91c19b7fd3d67ab4c424de35624cdb300b19365e [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
Yafit Hadar5796d972015-10-15 13:16:11 +030018import java.util.List;
19
alshabib7b808c52015-06-26 14:22:24 -070020import org.onlab.packet.EthType;
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -070021import org.onlab.packet.IpAddress;
alshabib010c31d2014-09-26 10:01:12 -070022import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010023import org.onlab.packet.MplsLabel;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070024import org.onlab.packet.TpPort;
alshabib010c31d2014-09-26 10:01:12 -070025import org.onlab.packet.VlanId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080026import org.onosproject.core.GroupId;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.flow.instructions.Instruction;
alshabib346b5b32015-03-06 00:42:16 -080029import org.onosproject.net.flow.instructions.Instructions;
alshabib10c810b2015-08-18 16:59:04 -070030import org.onosproject.net.meter.MeterId;
alshabib55a55d92014-09-16 11:59:31 -070031
tom8bb16062014-09-12 14:47:46 -070032/**
33 * Abstraction of network traffic treatment.
34 */
35public interface TrafficTreatment {
36
37 /**
alshabib346b5b32015-03-06 00:42:16 -080038 * Returns the list of treatment instructions that will be applied
39 * further down the pipeline.
40 * @return list of treatment instructions
41 */
42 List<Instruction> deferred();
43
44 /**
45 * Returns the list of treatment instructions that will be applied
46 * immediately.
47 * @return list of treatment instructions
48 */
49 List<Instruction> immediate();
50
51 /**
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -070052 * Returns the list of all instructions in the treatment, both immediate and
53 * deferred.
54 *
55 * @return list of treatment instructions
56 */
57 List<Instruction> allInstructions();
58
59 /**
alshabib346b5b32015-03-06 00:42:16 -080060 * Returns the next table in the pipeline.
61 * @return a table transition; may be null.
62 */
63 Instructions.TableTypeTransition tableTransition();
64
65 /**
66 * Whether the deferred treatment instructions will be cleared
67 * by the device.
68 * @return a boolean
69 */
Jonathan Hart4a0ba562015-03-23 17:23:33 -070070 boolean clearedDeferred();
alshabib346b5b32015-03-06 00:42:16 -080071
72 /**
Saurav Das86af8f12015-05-25 23:55:33 -070073 * Returns the metadata instruction if there is one.
74 *
75 * @return a metadata instruction that may be null
76 */
77 Instructions.MetadataInstruction writeMetadata();
78
79 /**
alshabib10c810b2015-08-18 16:59:04 -070080 * Returns the meter instruction if there is one.
81 *
82 * @return a meter instruction that may be null
83 */
84 Instructions.MeterInstruction metered();
85
86 /**
tom8bb16062014-09-12 14:47:46 -070087 * Builder of traffic treatment entities.
88 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070089 interface Builder {
tom8bb16062014-09-12 14:47:46 -070090
91 /**
alshabib010c31d2014-09-26 10:01:12 -070092 * Adds an instruction to the builder.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080093 *
alshabib010c31d2014-09-26 10:01:12 -070094 * @param instruction an instruction
95 * @return a treatment builder
tom8bb16062014-09-12 14:47:46 -070096 */
alshabib369d2942014-09-12 17:59:35 -070097 Builder add(Instruction instruction);
tom8bb16062014-09-12 14:47:46 -070098
99 /**
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800100 * Adds a drop instruction.
101 *
102 * @return a treatment builder
alshabib010c31d2014-09-26 10:01:12 -0700103 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700104 Builder drop();
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800105
106 /**
107 * Adds a punt-to-controller instruction.
108 *
109 * @return a treatment builder
110 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700111 Builder punt();
alshabib010c31d2014-09-26 10:01:12 -0700112
113 /**
114 * Set the output port.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800115 *
alshabib010c31d2014-09-26 10:01:12 -0700116 * @param number the out port
117 * @return a treatment builder
118 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700119 Builder setOutput(PortNumber number);
alshabib010c31d2014-09-26 10:01:12 -0700120
121 /**
122 * Sets the src l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800123 *
alshabib010c31d2014-09-26 10:01:12 -0700124 * @param addr a macaddress
125 * @return a treatment builder
126 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700127 Builder setEthSrc(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700128
129 /**
130 * Sets the dst l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800131 *
alshabib010c31d2014-09-26 10:01:12 -0700132 * @param addr a macaddress
133 * @return a treatment builder
134 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700135 Builder setEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700136
137 /**
138 * Sets the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800139 *
alshabib010c31d2014-09-26 10:01:12 -0700140 * @param id a vlanid
141 * @return a treatment builder
142 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700143 Builder setVlanId(VlanId id);
alshabib010c31d2014-09-26 10:01:12 -0700144
145 /**
146 * Sets the vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800147 *
alshabib010c31d2014-09-26 10:01:12 -0700148 * @param pcp a vlan priority
149 * @return a treatment builder
150 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700151 Builder setVlanPcp(Byte pcp);
alshabib010c31d2014-09-26 10:01:12 -0700152
153 /**
154 * Sets the src l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800155 *
alshabib010c31d2014-09-26 10:01:12 -0700156 * @param addr an ip
157 * @return a treatment builder
158 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700159 Builder setIpSrc(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700160
161 /**
162 * Sets the dst l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800163 *
alshabib010c31d2014-09-26 10:01:12 -0700164 * @param addr an ip
165 * @return a treatment builder
166 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700167 Builder setIpDst(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700168
169 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800170 * Decrement the TTL in IP header by one.
sangho3f97a17d2015-01-29 22:56:29 -0800171 *
172 * @return a treatment builder
173 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700174 Builder decNwTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800175
176 /**
177 * Copy the TTL to outer protocol layer.
178 *
179 * @return a treatment builder
180 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700181 Builder copyTtlOut();
sangho3f97a17d2015-01-29 22:56:29 -0800182
183 /**
184 * Copy the TTL to inner protocol layer.
185 *
186 * @return a treatment builder
187 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700188 Builder copyTtlIn();
sangho3f97a17d2015-01-29 22:56:29 -0800189
190 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800191 * Push MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800192 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700193 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800194 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700195 Builder pushMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800196
197 /**
198 * Pops MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800199 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700200 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800201 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700202 Builder popMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800203
204 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100205 * Pops MPLS ether type and set the new ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800206 *
Michele Santuari4b6019e2014-12-19 11:31:45 +0100207 * @param etherType an ether type
Jonathan Hart3e594642015-10-20 17:31:24 -0700208 * @return a treatment builder
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700209 * @deprecated in Drake Release
sangho3f97a17d2015-01-29 22:56:29 -0800210 */
alshabib7b808c52015-06-26 14:22:24 -0700211 @Deprecated
alshabib0ad43982015-05-07 13:43:13 -0700212 Builder popMpls(int etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800213
214 /**
alshabib7b808c52015-06-26 14:22:24 -0700215 * Pops MPLS ether type and set the new ethertype.
216 *
217 * @param etherType an ether type
Jonathan Hart3e594642015-10-20 17:31:24 -0700218 * @return a treatment builder
alshabib7b808c52015-06-26 14:22:24 -0700219 */
220 Builder popMpls(EthType etherType);
221
222 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800223 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800224 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700225 * @param mplsLabel MPLS label
226 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800227 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700228 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800229
230 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700231 * Sets the mpls bottom-of-stack indicator bit.
232 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700233 * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false)
Saurav Das73a7dd42015-08-19 22:20:31 -0700234 * @return a treatment builder.
235 */
236 Builder setMplsBos(boolean mplsBos);
237
238 /**
sangho3f97a17d2015-01-29 22:56:29 -0800239 * Decrement MPLS TTL.
240 *
241 * @return a treatment builder
242 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700243 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800244
245 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700246 * Sets the optical channel ID or lambda.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800247 *
Marc De Leenheer49087752014-10-23 13:54:09 -0700248 * @param lambda optical channel ID
249 * @return a treatment builder
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700250 * @deprecated in Drake Release
Marc De Leenheer49087752014-10-23 13:54:09 -0700251 */
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700252 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700253 Builder setLambda(short lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700254
255 /**
sangho8995ac52015-02-04 11:29:03 -0800256 * Sets the group ID.
257 *
258 * @param groupId group ID
259 * @return a treatment builder
260 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700261 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800262
alshabib10c810b2015-08-18 16:59:04 -0700263 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200264 * Sets the Queue ID.
265 *
266 * @param queueId a queue ID
267 * @return a treatment builder
268 */
269 Builder setQueue(long queueId);
270
271 /**
alshabib10c810b2015-08-18 16:59:04 -0700272 * Sets a meter to be used by this flow.
273 *
274 * @param meterId a meter id
275 * @return a treatment builder
276 */
277 Builder meter(MeterId meterId);
alshabib9af70072015-02-09 14:34:16 -0800278
279 /**
alshabibd17abc22015-04-21 18:26:35 -0700280 * Sets the next table id to transition to.
281 *
282 * @param tableId the table table
283 * @return a treatement builder
284 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700285 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700286
287
288 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800289 * Pops outermost VLAN tag.
290 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700291 * @return a treatment builder
Saurav Dasfbe25c52015-03-04 11:12:00 -0800292 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700293 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800294
295 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800296 * Pushes a new VLAN tag.
297 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700298 * @return a treatment builder
Jonathan Hart54b406b2015-03-06 16:24:14 -0800299 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700300 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800301
302 /**
alshabib346b5b32015-03-06 00:42:16 -0800303 * Any instructions preceded by this method call will be deferred.
304 * @return a treatment builder
305 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700306 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800307
308 /**
309 * Any instructions preceded by this method call will be immediate.
310 * @return a treatment builder
311 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700312 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800313
314
315 /**
316 * Instructs the device to clear the deferred instructions set.
317 * @return a treatment builder
318 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700319 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800320
321 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700322 * Writes metadata to associate with a packet.
323 * <pre>
324 * {@code
325 * new_metadata = (old_metadata & ̃mask) | (value & mask)
326 * }
327 * </pre>
328 *
329 * @param value the metadata to write
330 * @param mask the masked bits for the value
331 * @return a treatment builder
332 */
333 Builder writeMetadata(long value, long mask);
334
335 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700336 * Sets the tunnel id.
337 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700338 * @param tunnelId a tunnel id
339 * @return a treatment builder
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700340 */
341 Builder setTunnelId(long tunnelId);
342
343 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700344 * Sets the src TCP port.
345 *
346 * @param port a port number
347 * @return a treatment builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700348 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700349 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700350 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700351 Builder setTcpSrc(short port);
352
353 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700354 * Sets the src TCP port.
355 *
356 * @param port a port number
357 * @return a treatment builder
358 */
359 Builder setTcpSrc(TpPort port);
360
361 /**
362 * Sets the dst TCP port.
363 *
364 * @param port a port number
365 * @return a treatment builder
366 * @deprecated in Drake release
367 */
368 @Deprecated
369 Builder setTcpDst(short port);
370
371 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700372 * Sets the dst TCP port.
373 *
374 * @param port a port number
375 * @return a treatment builder
376 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700377 Builder setTcpDst(TpPort port);
378
379 /**
380 * Sets the src UDP port.
381 *
382 * @param port a port number
383 * @return a treatment builder
384 * @deprecated in Drake release
385 */
386 @Deprecated
387 Builder setUdpSrc(short port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700388
389 /**
390 * Sets the src UDP port.
391 *
392 * @param port a port number
393 * @return a treatment builder
394 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700395 Builder setUdpSrc(TpPort port);
396
397 /**
398 * Sets the dst UDP port.
399 *
400 * @param port a port number
401 * @return a treatment builder
402 * @deprecated in Drake release
403 */
404 @Deprecated
405 Builder setUdpDst(short port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700406
407 /**
408 * Sets the dst UDP port.
409 *
410 * @param port a port number
411 * @return a treatment builder
412 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700413 Builder setUdpDst(TpPort port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700414
415 /**
tom8bb16062014-09-12 14:47:46 -0700416 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700417 * <p>
418 * If the treatment is empty when build() is called, it will add a default
419 * drop rule automatically. For a treatment that is actually empty, use
420 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
421 * </p>
tom8bb16062014-09-12 14:47:46 -0700422 *
423 * @return traffic treatment
424 */
425 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700426
tom8bb16062014-09-12 14:47:46 -0700427 }
Saurav Das86af8f12015-05-25 23:55:33 -0700428
tom8bb16062014-09-12 14:47:46 -0700429}