blob: 042aeaf6a300c06c1eac143b0888d3554219e4bd [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 /**
sangho3f97a17d2015-01-29 22:56:29 -0800230 * Decrement MPLS TTL.
231 *
232 * @return a treatment builder
233 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700234 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800235
236 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700237 * Sets the optical channel ID or lambda.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800238 *
Marc De Leenheer49087752014-10-23 13:54:09 -0700239 * @param lambda optical channel ID
240 * @return a treatment builder
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700241 * @deprecated in Drake Release
Marc De Leenheer49087752014-10-23 13:54:09 -0700242 */
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700243 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700244 Builder setLambda(short lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700245
246 /**
sangho8995ac52015-02-04 11:29:03 -0800247 * Sets the group ID.
248 *
249 * @param groupId group ID
250 * @return a treatment builder
251 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700252 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800253
alshabib10c810b2015-08-18 16:59:04 -0700254 /**
255 * Sets a meter to be used by this flow.
256 *
257 * @param meterId a meter id
258 * @return a treatment builder
259 */
260 Builder meter(MeterId meterId);
alshabib9af70072015-02-09 14:34:16 -0800261
262 /**
263 * Sets the next table type to transition to.
264 *
265 * @param type the table type
266 * @return a treatement builder
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700267 * @deprecated in Cardinal Release
alshabib9af70072015-02-09 14:34:16 -0800268 */
alshabibd17abc22015-04-21 18:26:35 -0700269 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700270 Builder transition(FlowRule.Type type);
alshabib9af70072015-02-09 14:34:16 -0800271
sangho8995ac52015-02-04 11:29:03 -0800272 /**
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 *
284 * @return a treatment builder.
285 */
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 *
291 * @return a treatment builder.
292 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700293 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800294
295 /**
alshabib346b5b32015-03-06 00:42:16 -0800296 * Any instructions preceded by this method call will be deferred.
297 * @return a treatment builder
298 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700299 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800300
301 /**
302 * Any instructions preceded by this method call will be immediate.
303 * @return a treatment builder
304 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700305 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800306
307
308 /**
309 * Instructs the device to clear the deferred instructions set.
310 * @return a treatment builder
311 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700312 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800313
314 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700315 * Writes metadata to associate with a packet.
316 * <pre>
317 * {@code
318 * new_metadata = (old_metadata & ̃mask) | (value & mask)
319 * }
320 * </pre>
321 *
322 * @param value the metadata to write
323 * @param mask the masked bits for the value
324 * @return a treatment builder
325 */
326 Builder writeMetadata(long value, long mask);
327
328 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700329 * Sets the tunnel id.
330 *
331 * @param tunnelId a tunnel id.
332 * @return a treatment builder.
333 */
334 Builder setTunnelId(long tunnelId);
335
336 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700337 * Sets the src TCP port.
338 *
339 * @param port a port number
340 * @return a treatment builder
341 */
342 Builder setTcpSrc(short port);
343
344 /**
345 * Sets the dst TCP port.
346 *
347 * @param port a port number
348 * @return a treatment builder
349 */
350 Builder setTcpDst(short port);
351
352 /**
353 * Sets the src UDP port.
354 *
355 * @param port a port number
356 * @return a treatment builder
357 */
358 Builder setUdpSrc(short port);
359
360 /**
361 * Sets the dst UDP port.
362 *
363 * @param port a port number
364 * @return a treatment builder
365 */
366 Builder setUdpDst(short port);
367
368 /**
tom8bb16062014-09-12 14:47:46 -0700369 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700370 * <p>
371 * If the treatment is empty when build() is called, it will add a default
372 * drop rule automatically. For a treatment that is actually empty, use
373 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
374 * </p>
tom8bb16062014-09-12 14:47:46 -0700375 *
376 * @return traffic treatment
377 */
378 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700379
tom8bb16062014-09-12 14:47:46 -0700380 }
Saurav Das86af8f12015-05-25 23:55:33 -0700381
tom8bb16062014-09-12 14:47:46 -0700382}