blob: b982199b6d7136506dc5a78cacb305431abde7f3 [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
alshabib7b808c52015-06-26 14:22:24 -070018import org.onlab.packet.EthType;
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -070019import org.onlab.packet.IpAddress;
alshabib010c31d2014-09-26 10:01:12 -070020import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010021import org.onlab.packet.MplsLabel;
alshabib010c31d2014-09-26 10:01:12 -070022import org.onlab.packet.VlanId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080023import org.onosproject.core.GroupId;
24import org.onosproject.net.PortNumber;
25import org.onosproject.net.flow.instructions.Instruction;
alshabib346b5b32015-03-06 00:42:16 -080026import org.onosproject.net.flow.instructions.Instructions;
alshabib10c810b2015-08-18 16:59:04 -070027import org.onosproject.net.meter.MeterId;
alshabib55a55d92014-09-16 11:59:31 -070028
Jonathan Hart54b406b2015-03-06 16:24:14 -080029import java.util.List;
30
tom8bb16062014-09-12 14:47:46 -070031/**
32 * Abstraction of network traffic treatment.
33 */
34public interface TrafficTreatment {
35
36 /**
alshabib346b5b32015-03-06 00:42:16 -080037 * Returns the list of treatment instructions that will be applied
38 * further down the pipeline.
39 * @return list of treatment instructions
40 */
41 List<Instruction> deferred();
42
43 /**
44 * Returns the list of treatment instructions that will be applied
45 * immediately.
46 * @return list of treatment instructions
47 */
48 List<Instruction> immediate();
49
50 /**
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -070051 * Returns the list of all instructions in the treatment, both immediate and
52 * deferred.
53 *
54 * @return list of treatment instructions
55 */
56 List<Instruction> allInstructions();
57
58 /**
alshabib346b5b32015-03-06 00:42:16 -080059 * Returns the next table in the pipeline.
60 * @return a table transition; may be null.
61 */
62 Instructions.TableTypeTransition tableTransition();
63
64 /**
65 * Whether the deferred treatment instructions will be cleared
66 * by the device.
67 * @return a boolean
68 */
Jonathan Hart4a0ba562015-03-23 17:23:33 -070069 boolean clearedDeferred();
alshabib346b5b32015-03-06 00:42:16 -080070
71 /**
Saurav Das86af8f12015-05-25 23:55:33 -070072 * Returns the metadata instruction if there is one.
73 *
74 * @return a metadata instruction that may be null
75 */
76 Instructions.MetadataInstruction writeMetadata();
77
78 /**
alshabib10c810b2015-08-18 16:59:04 -070079 * Returns the meter instruction if there is one.
80 *
81 * @return a meter instruction that may be null
82 */
83 Instructions.MeterInstruction metered();
84
85 /**
tom8bb16062014-09-12 14:47:46 -070086 * Builder of traffic treatment entities.
87 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070088 interface Builder {
tom8bb16062014-09-12 14:47:46 -070089
90 /**
alshabib010c31d2014-09-26 10:01:12 -070091 * Adds an instruction to the builder.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080092 *
alshabib010c31d2014-09-26 10:01:12 -070093 * @param instruction an instruction
94 * @return a treatment builder
tom8bb16062014-09-12 14:47:46 -070095 */
alshabib369d2942014-09-12 17:59:35 -070096 Builder add(Instruction instruction);
tom8bb16062014-09-12 14:47:46 -070097
98 /**
Thomas Vachuskaf4df0052015-01-06 12:30:11 -080099 * Adds a drop instruction.
100 *
101 * @return a treatment builder
alshabib010c31d2014-09-26 10:01:12 -0700102 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700103 Builder drop();
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800104
105 /**
106 * Adds a punt-to-controller instruction.
107 *
108 * @return a treatment builder
109 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700110 Builder punt();
alshabib010c31d2014-09-26 10:01:12 -0700111
112 /**
113 * Set the output port.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800114 *
alshabib010c31d2014-09-26 10:01:12 -0700115 * @param number the out port
116 * @return a treatment builder
117 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700118 Builder setOutput(PortNumber number);
alshabib010c31d2014-09-26 10:01:12 -0700119
120 /**
121 * Sets the src l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800122 *
alshabib010c31d2014-09-26 10:01:12 -0700123 * @param addr a macaddress
124 * @return a treatment builder
125 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700126 Builder setEthSrc(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700127
128 /**
129 * Sets the dst l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800130 *
alshabib010c31d2014-09-26 10:01:12 -0700131 * @param addr a macaddress
132 * @return a treatment builder
133 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700134 Builder setEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700135
136 /**
137 * Sets the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800138 *
alshabib010c31d2014-09-26 10:01:12 -0700139 * @param id a vlanid
140 * @return a treatment builder
141 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700142 Builder setVlanId(VlanId id);
alshabib010c31d2014-09-26 10:01:12 -0700143
144 /**
145 * Sets the vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800146 *
alshabib010c31d2014-09-26 10:01:12 -0700147 * @param pcp a vlan priority
148 * @return a treatment builder
149 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700150 Builder setVlanPcp(Byte pcp);
alshabib010c31d2014-09-26 10:01:12 -0700151
152 /**
153 * Sets the src l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800154 *
alshabib010c31d2014-09-26 10:01:12 -0700155 * @param addr an ip
156 * @return a treatment builder
157 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700158 Builder setIpSrc(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700159
160 /**
161 * Sets the dst l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800162 *
alshabib010c31d2014-09-26 10:01:12 -0700163 * @param addr an ip
164 * @return a treatment builder
165 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700166 Builder setIpDst(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700167
168 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800169 * Decrement the TTL in IP header by one.
sangho3f97a17d2015-01-29 22:56:29 -0800170 *
171 * @return a treatment builder
172 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700173 Builder decNwTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800174
175 /**
176 * Copy the TTL to outer protocol layer.
177 *
178 * @return a treatment builder
179 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700180 Builder copyTtlOut();
sangho3f97a17d2015-01-29 22:56:29 -0800181
182 /**
183 * Copy the TTL to inner protocol layer.
184 *
185 * @return a treatment builder
186 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700187 Builder copyTtlIn();
sangho3f97a17d2015-01-29 22:56:29 -0800188
189 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800190 * Push MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800191 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800192 * @return a treatment builder.
193 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700194 Builder pushMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800195
196 /**
197 * Pops MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800198 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800199 * @return a treatment builder.
200 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700201 Builder popMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800202
203 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100204 * Pops MPLS ether type and set the new ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800205 *
Michele Santuari4b6019e2014-12-19 11:31:45 +0100206 * @param etherType an ether type
sangho3f97a17d2015-01-29 22:56:29 -0800207 * @return a treatment builder.
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700208 * @deprecated in Drake Release
sangho3f97a17d2015-01-29 22:56:29 -0800209 */
alshabib7b808c52015-06-26 14:22:24 -0700210 @Deprecated
alshabib0ad43982015-05-07 13:43:13 -0700211 Builder popMpls(int etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800212
213 /**
alshabib7b808c52015-06-26 14:22:24 -0700214 * Pops MPLS ether type and set the new ethertype.
215 *
216 * @param etherType an ether type
217 * @return a treatment builder.
218 */
219 Builder popMpls(EthType etherType);
220
221 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800222 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800223 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800224 * @param mplsLabel MPLS label.
225 * @return a treatment builder.
226 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700227 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800228
229 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700230 * Sets the mpls bottom-of-stack indicator bit.
231 *
232 * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false).
233 * @return a treatment builder.
234 */
235 Builder setMplsBos(boolean mplsBos);
236
237 /**
sangho3f97a17d2015-01-29 22:56:29 -0800238 * Decrement MPLS TTL.
239 *
240 * @return a treatment builder
241 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700242 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800243
244 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700245 * Sets the optical channel ID or lambda.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800246 *
Marc De Leenheer49087752014-10-23 13:54:09 -0700247 * @param lambda optical channel ID
248 * @return a treatment builder
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700249 * @deprecated in Drake Release
Marc De Leenheer49087752014-10-23 13:54:09 -0700250 */
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700251 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700252 Builder setLambda(short lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700253
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 /**
263 * Sets a meter to be used by this flow.
264 *
265 * @param meterId a meter id
266 * @return a treatment builder
267 */
268 Builder meter(MeterId meterId);
alshabib9af70072015-02-09 14:34:16 -0800269
270 /**
271 * Sets the next table type to transition to.
272 *
273 * @param type the table type
274 * @return a treatement builder
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700275 * @deprecated in Cardinal Release
alshabib9af70072015-02-09 14:34:16 -0800276 */
alshabibd17abc22015-04-21 18:26:35 -0700277 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700278 Builder transition(FlowRule.Type type);
alshabib9af70072015-02-09 14:34:16 -0800279
sangho8995ac52015-02-04 11:29:03 -0800280 /**
alshabibd17abc22015-04-21 18:26:35 -0700281 * Sets the next table id to transition to.
282 *
283 * @param tableId the table table
284 * @return a treatement builder
285 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700286 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700287
288
289 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800290 * Pops outermost VLAN tag.
291 *
292 * @return a treatment builder.
293 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700294 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800295
296 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800297 * Pushes a new VLAN tag.
298 *
299 * @return a treatment builder.
300 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700301 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800302
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 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700323 * Writes metadata to associate with a packet.
324 * <pre>
325 * {@code
326 * new_metadata = (old_metadata & ̃mask) | (value & mask)
327 * }
328 * </pre>
329 *
330 * @param value the metadata to write
331 * @param mask the masked bits for the value
332 * @return a treatment builder
333 */
334 Builder writeMetadata(long value, long mask);
335
336 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700337 * Sets the tunnel id.
338 *
339 * @param tunnelId a tunnel id.
340 * @return a treatment builder.
341 */
342 Builder setTunnelId(long tunnelId);
343
344 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700345 * Sets the src TCP port.
346 *
347 * @param port a port number
348 * @return a treatment builder
349 */
350 Builder setTcpSrc(short port);
351
352 /**
353 * Sets the dst TCP port.
354 *
355 * @param port a port number
356 * @return a treatment builder
357 */
358 Builder setTcpDst(short port);
359
360 /**
361 * Sets the src UDP port.
362 *
363 * @param port a port number
364 * @return a treatment builder
365 */
366 Builder setUdpSrc(short port);
367
368 /**
369 * Sets the dst UDP port.
370 *
371 * @param port a port number
372 * @return a treatment builder
373 */
374 Builder setUdpDst(short port);
375
376 /**
tom8bb16062014-09-12 14:47:46 -0700377 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700378 * <p>
379 * If the treatment is empty when build() is called, it will add a default
380 * drop rule automatically. For a treatment that is actually empty, use
381 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
382 * </p>
tom8bb16062014-09-12 14:47:46 -0700383 *
384 * @return traffic treatment
385 */
386 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700387
tom8bb16062014-09-12 14:47:46 -0700388 }
Saurav Das86af8f12015-05-25 23:55:33 -0700389
tom8bb16062014-09-12 14:47:46 -0700390}