blob: 1ce669c241a8b6bec8185f79c2a144b419ee8e28 [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;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070022import org.onlab.packet.TpPort;
alshabib010c31d2014-09-26 10:01:12 -070023import org.onlab.packet.VlanId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080024import org.onosproject.core.GroupId;
25import org.onosproject.net.PortNumber;
26import org.onosproject.net.flow.instructions.Instruction;
alshabib346b5b32015-03-06 00:42:16 -080027import org.onosproject.net.flow.instructions.Instructions;
alshabib10c810b2015-08-18 16:59:04 -070028import org.onosproject.net.meter.MeterId;
alshabib55a55d92014-09-16 11:59:31 -070029
Jonathan Hart54b406b2015-03-06 16:24:14 -080030import java.util.List;
31
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 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800193 * @return a treatment builder.
194 */
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 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800200 * @return a treatment builder.
201 */
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
sangho3f97a17d2015-01-29 22:56:29 -0800208 * @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
218 * @return a treatment builder.
219 */
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 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800225 * @param mplsLabel MPLS label.
226 * @return a treatment builder.
227 */
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 *
233 * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false).
234 * @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 /**
264 * Sets a meter to be used by this flow.
265 *
266 * @param meterId a meter id
267 * @return a treatment builder
268 */
269 Builder meter(MeterId meterId);
alshabib9af70072015-02-09 14:34:16 -0800270
271 /**
272 * Sets the next table type to transition to.
273 *
274 * @param type the table type
275 * @return a treatement builder
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700276 * @deprecated in Cardinal Release
alshabib9af70072015-02-09 14:34:16 -0800277 */
alshabibd17abc22015-04-21 18:26:35 -0700278 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700279 Builder transition(FlowRule.Type type);
alshabib9af70072015-02-09 14:34:16 -0800280
sangho8995ac52015-02-04 11:29:03 -0800281 /**
alshabibd17abc22015-04-21 18:26:35 -0700282 * Sets the next table id to transition to.
283 *
284 * @param tableId the table table
285 * @return a treatement builder
286 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700287 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700288
289
290 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800291 * Pops outermost VLAN tag.
292 *
293 * @return a treatment builder.
294 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700295 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800296
297 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800298 * Pushes a new VLAN tag.
299 *
300 * @return a treatment builder.
301 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700302 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800303
304 /**
alshabib346b5b32015-03-06 00:42:16 -0800305 * Any instructions preceded by this method call will be deferred.
306 * @return a treatment builder
307 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700308 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800309
310 /**
311 * Any instructions preceded by this method call will be immediate.
312 * @return a treatment builder
313 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700314 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800315
316
317 /**
318 * Instructs the device to clear the deferred instructions set.
319 * @return a treatment builder
320 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700321 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800322
323 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700324 * Writes metadata to associate with a packet.
325 * <pre>
326 * {@code
327 * new_metadata = (old_metadata & ̃mask) | (value & mask)
328 * }
329 * </pre>
330 *
331 * @param value the metadata to write
332 * @param mask the masked bits for the value
333 * @return a treatment builder
334 */
335 Builder writeMetadata(long value, long mask);
336
337 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700338 * Sets the tunnel id.
339 *
340 * @param tunnelId a tunnel id.
341 * @return a treatment builder.
342 */
343 Builder setTunnelId(long tunnelId);
344
345 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700346 * Sets the src TCP port.
347 *
348 * @param port a port number
349 * @return a treatment builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700350 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700351 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700352 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700353 Builder setTcpSrc(short port);
354
355 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700356 * Sets the src TCP port.
357 *
358 * @param port a port number
359 * @return a treatment builder
360 */
361 Builder setTcpSrc(TpPort port);
362
363 /**
364 * Sets the dst TCP port.
365 *
366 * @param port a port number
367 * @return a treatment builder
368 * @deprecated in Drake release
369 */
370 @Deprecated
371 Builder setTcpDst(short port);
372
373 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700374 * Sets the dst TCP port.
375 *
376 * @param port a port number
377 * @return a treatment builder
378 */
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
386 * @deprecated in Drake release
387 */
388 @Deprecated
389 Builder setUdpSrc(short port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700390
391 /**
392 * Sets the src UDP port.
393 *
394 * @param port a port number
395 * @return a treatment builder
396 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700397 Builder setUdpSrc(TpPort port);
398
399 /**
400 * Sets the dst UDP port.
401 *
402 * @param port a port number
403 * @return a treatment builder
404 * @deprecated in Drake release
405 */
406 @Deprecated
407 Builder setUdpDst(short port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700408
409 /**
410 * Sets the dst UDP port.
411 *
412 * @param port a port number
413 * @return a treatment builder
414 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700415 Builder setUdpDst(TpPort port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700416
417 /**
tom8bb16062014-09-12 14:47:46 -0700418 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700419 * <p>
420 * If the treatment is empty when build() is called, it will add a default
421 * drop rule automatically. For a treatment that is actually empty, use
422 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
423 * </p>
tom8bb16062014-09-12 14:47:46 -0700424 *
425 * @return traffic treatment
426 */
427 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700428
tom8bb16062014-09-12 14:47:46 -0700429 }
Saurav Das86af8f12015-05-25 23:55:33 -0700430
tom8bb16062014-09-12 14:47:46 -0700431}