blob: 06b6ffa0b50165d039462e4d20c116add4aff650 [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;
Jonathan Hart3c259162015-10-21 21:31:19 -070027import org.onosproject.net.DeviceId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080028import org.onosproject.net.PortNumber;
alshabib880b6442015-11-23 22:13:04 -080029import org.onosproject.net.flow.instructions.ExtensionTreatment;
Jonathan Hart54b406b2015-03-06 16:24:14 -080030import org.onosproject.net.flow.instructions.Instruction;
alshabib346b5b32015-03-06 00:42:16 -080031import org.onosproject.net.flow.instructions.Instructions;
alshabib10c810b2015-08-18 16:59:04 -070032import org.onosproject.net.meter.MeterId;
alshabib55a55d92014-09-16 11:59:31 -070033
tom8bb16062014-09-12 14:47:46 -070034/**
35 * Abstraction of network traffic treatment.
36 */
37public interface TrafficTreatment {
38
39 /**
alshabib346b5b32015-03-06 00:42:16 -080040 * Returns the list of treatment instructions that will be applied
41 * further down the pipeline.
42 * @return list of treatment instructions
43 */
44 List<Instruction> deferred();
45
46 /**
47 * Returns the list of treatment instructions that will be applied
48 * immediately.
49 * @return list of treatment instructions
50 */
51 List<Instruction> immediate();
52
53 /**
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -070054 * Returns the list of all instructions in the treatment, both immediate and
55 * deferred.
56 *
57 * @return list of treatment instructions
58 */
59 List<Instruction> allInstructions();
60
61 /**
alshabib346b5b32015-03-06 00:42:16 -080062 * Returns the next table in the pipeline.
63 * @return a table transition; may be null.
64 */
65 Instructions.TableTypeTransition tableTransition();
66
67 /**
68 * Whether the deferred treatment instructions will be cleared
69 * by the device.
70 * @return a boolean
71 */
Jonathan Hart4a0ba562015-03-23 17:23:33 -070072 boolean clearedDeferred();
alshabib346b5b32015-03-06 00:42:16 -080073
74 /**
Saurav Das86af8f12015-05-25 23:55:33 -070075 * Returns the metadata instruction if there is one.
76 *
77 * @return a metadata instruction that may be null
78 */
79 Instructions.MetadataInstruction writeMetadata();
80
81 /**
alshabib10c810b2015-08-18 16:59:04 -070082 * Returns the meter instruction if there is one.
83 *
84 * @return a meter instruction that may be null
85 */
86 Instructions.MeterInstruction metered();
87
88 /**
tom8bb16062014-09-12 14:47:46 -070089 * Builder of traffic treatment entities.
90 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070091 interface Builder {
tom8bb16062014-09-12 14:47:46 -070092
93 /**
alshabib010c31d2014-09-26 10:01:12 -070094 * Adds an instruction to the builder.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080095 *
alshabib010c31d2014-09-26 10:01:12 -070096 * @param instruction an instruction
97 * @return a treatment builder
tom8bb16062014-09-12 14:47:46 -070098 */
alshabib369d2942014-09-12 17:59:35 -070099 Builder add(Instruction instruction);
tom8bb16062014-09-12 14:47:46 -0700100
101 /**
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800102 * Adds a drop instruction.
103 *
104 * @return a treatment builder
alshabib010c31d2014-09-26 10:01:12 -0700105 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700106 Builder drop();
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800107
108 /**
109 * Adds a punt-to-controller instruction.
110 *
111 * @return a treatment builder
112 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700113 Builder punt();
alshabib010c31d2014-09-26 10:01:12 -0700114
115 /**
116 * Set the output port.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800117 *
alshabib010c31d2014-09-26 10:01:12 -0700118 * @param number the out port
119 * @return a treatment builder
120 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700121 Builder setOutput(PortNumber number);
alshabib010c31d2014-09-26 10:01:12 -0700122
123 /**
124 * Sets the src l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800125 *
alshabib010c31d2014-09-26 10:01:12 -0700126 * @param addr a macaddress
127 * @return a treatment builder
128 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700129 Builder setEthSrc(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700130
131 /**
132 * Sets the dst l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800133 *
alshabib010c31d2014-09-26 10:01:12 -0700134 * @param addr a macaddress
135 * @return a treatment builder
136 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700137 Builder setEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700138
139 /**
140 * Sets the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800141 *
alshabib010c31d2014-09-26 10:01:12 -0700142 * @param id a vlanid
143 * @return a treatment builder
144 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700145 Builder setVlanId(VlanId id);
alshabib010c31d2014-09-26 10:01:12 -0700146
147 /**
148 * Sets the vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800149 *
alshabib010c31d2014-09-26 10:01:12 -0700150 * @param pcp a vlan priority
151 * @return a treatment builder
152 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700153 Builder setVlanPcp(Byte pcp);
alshabib010c31d2014-09-26 10:01:12 -0700154
155 /**
156 * Sets the src l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800157 *
alshabib010c31d2014-09-26 10:01:12 -0700158 * @param addr an ip
159 * @return a treatment builder
160 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700161 Builder setIpSrc(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700162
163 /**
164 * Sets the dst l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800165 *
alshabib010c31d2014-09-26 10:01:12 -0700166 * @param addr an ip
167 * @return a treatment builder
168 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700169 Builder setIpDst(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700170
171 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800172 * Decrement the TTL in IP header by one.
sangho3f97a17d2015-01-29 22:56:29 -0800173 *
174 * @return a treatment builder
175 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700176 Builder decNwTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800177
178 /**
179 * Copy the TTL to outer protocol layer.
180 *
181 * @return a treatment builder
182 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700183 Builder copyTtlOut();
sangho3f97a17d2015-01-29 22:56:29 -0800184
185 /**
186 * Copy the TTL to inner protocol layer.
187 *
188 * @return a treatment builder
189 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700190 Builder copyTtlIn();
sangho3f97a17d2015-01-29 22:56:29 -0800191
192 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800193 * Push MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800194 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700195 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800196 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700197 Builder pushMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800198
199 /**
200 * Pops MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800201 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700202 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800203 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700204 Builder popMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800205
206 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100207 * Pops MPLS ether type and set the new ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800208 *
Michele Santuari4b6019e2014-12-19 11:31:45 +0100209 * @param etherType an ether type
Jonathan Hart3e594642015-10-20 17:31:24 -0700210 * @return a treatment builder
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700211 * @deprecated in Drake Release
sangho3f97a17d2015-01-29 22:56:29 -0800212 */
alshabib7b808c52015-06-26 14:22:24 -0700213 @Deprecated
alshabib0ad43982015-05-07 13:43:13 -0700214 Builder popMpls(int etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800215
216 /**
alshabib7b808c52015-06-26 14:22:24 -0700217 * Pops MPLS ether type and set the new ethertype.
218 *
219 * @param etherType an ether type
Jonathan Hart3e594642015-10-20 17:31:24 -0700220 * @return a treatment builder
alshabib7b808c52015-06-26 14:22:24 -0700221 */
222 Builder popMpls(EthType etherType);
223
224 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800225 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800226 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700227 * @param mplsLabel MPLS label
228 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800229 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700230 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800231
232 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700233 * Sets the mpls bottom-of-stack indicator bit.
234 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700235 * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false)
Saurav Das73a7dd42015-08-19 22:20:31 -0700236 * @return a treatment builder.
237 */
238 Builder setMplsBos(boolean mplsBos);
239
240 /**
sangho3f97a17d2015-01-29 22:56:29 -0800241 * Decrement MPLS TTL.
242 *
243 * @return a treatment builder
244 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700245 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800246
247 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700248 * Sets the optical channel ID or lambda.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800249 *
Marc De Leenheer49087752014-10-23 13:54:09 -0700250 * @param lambda optical channel ID
251 * @return a treatment builder
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700252 * @deprecated in Drake Release
Marc De Leenheer49087752014-10-23 13:54:09 -0700253 */
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700254 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700255 Builder setLambda(short lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700256
257 /**
sangho8995ac52015-02-04 11:29:03 -0800258 * Sets the group ID.
259 *
260 * @param groupId group ID
261 * @return a treatment builder
262 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700263 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800264
alshabib10c810b2015-08-18 16:59:04 -0700265 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200266 * Sets the Queue ID.
267 *
268 * @param queueId a queue ID
269 * @return a treatment builder
270 */
271 Builder setQueue(long queueId);
272
273 /**
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200274 * Sets the Queue ID for a specific port.
275 *
276 * @param queueId a queue ID
277 * @param port a port number
278 * @return a treatment builder
279 */
280 Builder setQueue(long queueId, PortNumber port);
281
282 /**
alshabib10c810b2015-08-18 16:59:04 -0700283 * Sets a meter to be used by this flow.
284 *
285 * @param meterId a meter id
286 * @return a treatment builder
287 */
288 Builder meter(MeterId meterId);
alshabib9af70072015-02-09 14:34:16 -0800289
290 /**
alshabibd17abc22015-04-21 18:26:35 -0700291 * Sets the next table id to transition to.
292 *
293 * @param tableId the table table
294 * @return a treatement builder
295 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700296 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700297
298
299 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800300 * Pops outermost VLAN tag.
301 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700302 * @return a treatment builder
Saurav Dasfbe25c52015-03-04 11:12:00 -0800303 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700304 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800305
306 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800307 * Pushes a new VLAN tag.
308 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700309 * @return a treatment builder
Jonathan Hart54b406b2015-03-06 16:24:14 -0800310 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700311 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800312
313 /**
alshabib346b5b32015-03-06 00:42:16 -0800314 * Any instructions preceded by this method call will be deferred.
315 * @return a treatment builder
316 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700317 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800318
319 /**
320 * Any instructions preceded by this method call will be immediate.
321 * @return a treatment builder
322 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700323 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800324
325
326 /**
327 * Instructs the device to clear the deferred instructions set.
328 * @return a treatment builder
329 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700330 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800331
332 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700333 * Writes metadata to associate with a packet.
334 * <pre>
335 * {@code
336 * new_metadata = (old_metadata & ̃mask) | (value & mask)
337 * }
338 * </pre>
339 *
340 * @param value the metadata to write
341 * @param mask the masked bits for the value
342 * @return a treatment builder
343 */
344 Builder writeMetadata(long value, long mask);
345
346 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700347 * Sets the tunnel id.
348 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700349 * @param tunnelId a tunnel id
350 * @return a treatment builder
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700351 */
352 Builder setTunnelId(long tunnelId);
353
354 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700355 * Sets the src TCP port.
356 *
357 * @param port a port number
358 * @return a treatment builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700359 * @deprecated in Drake release
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700360 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700361 @Deprecated
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700362 Builder setTcpSrc(short port);
363
364 /**
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700365 * Sets the src TCP port.
366 *
367 * @param port a port number
368 * @return a treatment builder
369 */
370 Builder setTcpSrc(TpPort port);
371
372 /**
373 * Sets the dst TCP port.
374 *
375 * @param port a port number
376 * @return a treatment builder
377 * @deprecated in Drake release
378 */
379 @Deprecated
380 Builder setTcpDst(short port);
381
382 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700383 * Sets the dst TCP port.
384 *
385 * @param port a port number
386 * @return a treatment builder
387 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700388 Builder setTcpDst(TpPort port);
389
390 /**
391 * Sets the src UDP port.
392 *
393 * @param port a port number
394 * @return a treatment builder
395 * @deprecated in Drake release
396 */
397 @Deprecated
398 Builder setUdpSrc(short port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700399
400 /**
401 * Sets the src UDP port.
402 *
403 * @param port a port number
404 * @return a treatment builder
405 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700406 Builder setUdpSrc(TpPort port);
407
408 /**
409 * Sets the dst UDP port.
410 *
411 * @param port a port number
412 * @return a treatment builder
413 * @deprecated in Drake release
414 */
415 @Deprecated
416 Builder setUdpDst(short port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700417
418 /**
419 * Sets the dst UDP port.
420 *
421 * @param port a port number
422 * @return a treatment builder
423 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700424 Builder setUdpDst(TpPort port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700425
426 /**
Jonathan Hart3c259162015-10-21 21:31:19 -0700427 * Uses an extension treatment.
428 *
429 * @param extension extension treatment
430 * @param deviceId device ID
431 * @return a treatment builder
432 */
alshabib880b6442015-11-23 22:13:04 -0800433 Builder extension(ExtensionTreatment extension, DeviceId deviceId);
Jonathan Hart3c259162015-10-21 21:31:19 -0700434
435 /**
tom8bb16062014-09-12 14:47:46 -0700436 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700437 * <p>
438 * If the treatment is empty when build() is called, it will add a default
439 * drop rule automatically. For a treatment that is actually empty, use
440 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
441 * </p>
tom8bb16062014-09-12 14:47:46 -0700442 *
443 * @return traffic treatment
444 */
445 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700446
tom8bb16062014-09-12 14:47:46 -0700447 }
Saurav Das86af8f12015-05-25 23:55:33 -0700448
tom8bb16062014-09-12 14:47:46 -0700449}