blob: d0de8e48dd72f1cb566822fa8d3ac58280e41992 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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
alshabib7b808c52015-06-26 14:22:24 -0700211 */
212 Builder popMpls(EthType etherType);
213
214 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800215 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800216 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700217 * @param mplsLabel MPLS label
218 * @return a treatment builder
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800219 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700220 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800221
222 /**
Saurav Das73a7dd42015-08-19 22:20:31 -0700223 * Sets the mpls bottom-of-stack indicator bit.
224 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700225 * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false)
Saurav Das73a7dd42015-08-19 22:20:31 -0700226 * @return a treatment builder.
227 */
228 Builder setMplsBos(boolean mplsBos);
229
230 /**
sangho3f97a17d2015-01-29 22:56:29 -0800231 * Decrement MPLS TTL.
232 *
233 * @return a treatment builder
234 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700235 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800236
237 /**
sangho8995ac52015-02-04 11:29:03 -0800238 * Sets the group ID.
239 *
240 * @param groupId group ID
241 * @return a treatment builder
242 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700243 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800244
alshabib10c810b2015-08-18 16:59:04 -0700245 /**
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200246 * Sets the Queue ID.
247 *
248 * @param queueId a queue ID
249 * @return a treatment builder
250 */
251 Builder setQueue(long queueId);
252
253 /**
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200254 * Sets the Queue ID for a specific port.
255 *
256 * @param queueId a queue ID
257 * @param port a port number
258 * @return a treatment builder
259 */
260 Builder setQueue(long queueId, PortNumber port);
261
262 /**
alshabib10c810b2015-08-18 16:59:04 -0700263 * 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 /**
alshabibd17abc22015-04-21 18:26:35 -0700271 * Sets the next table id to transition to.
272 *
273 * @param tableId the table table
274 * @return a treatement builder
275 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700276 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700277
278
279 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800280 * Pops outermost VLAN tag.
281 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700282 * @return a treatment builder
Saurav Dasfbe25c52015-03-04 11:12:00 -0800283 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700284 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800285
286 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800287 * Pushes a new VLAN tag.
288 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700289 * @return a treatment builder
Jonathan Hart54b406b2015-03-06 16:24:14 -0800290 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700291 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800292
293 /**
alshabib346b5b32015-03-06 00:42:16 -0800294 * Any instructions preceded by this method call will be deferred.
295 * @return a treatment builder
296 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700297 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800298
299 /**
300 * Any instructions preceded by this method call will be immediate.
301 * @return a treatment builder
302 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700303 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800304
305
306 /**
307 * Instructs the device to clear the deferred instructions set.
308 * @return a treatment builder
309 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700310 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800311
312 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700313 * Writes metadata to associate with a packet.
314 * <pre>
315 * {@code
316 * new_metadata = (old_metadata & ̃mask) | (value & mask)
317 * }
318 * </pre>
319 *
320 * @param value the metadata to write
321 * @param mask the masked bits for the value
322 * @return a treatment builder
323 */
324 Builder writeMetadata(long value, long mask);
325
326 /**
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700327 * Sets the tunnel id.
328 *
Jonathan Hart3e594642015-10-20 17:31:24 -0700329 * @param tunnelId a tunnel id
330 * @return a treatment builder
Hyunsun Moona08c5d02015-07-14 17:53:00 -0700331 */
332 Builder setTunnelId(long tunnelId);
333
334 /**
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700335 * Sets the src TCP port.
336 *
337 * @param port a port number
338 * @return a treatment builder
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700339 */
340 Builder setTcpSrc(TpPort port);
341
342 /**
343 * Sets the dst TCP port.
344 *
345 * @param port a port number
346 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700347 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700348 Builder setTcpDst(TpPort port);
349
350 /**
351 * Sets the src UDP port.
352 *
353 * @param port a port number
354 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700355 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700356 Builder setUdpSrc(TpPort port);
357
358 /**
359 * Sets the dst UDP port.
360 *
361 * @param port a port number
362 * @return a treatment builder
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700363 */
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700364 Builder setUdpDst(TpPort port);
Hyunsun Moonc8bd97c2015-07-18 22:47:33 -0700365
366 /**
lishuai3cce60b2015-12-01 19:35:16 +0800367 * Sets the arp src ip address.
368 *
369 * @param addr an ip
370 * @return a treatment builder
371 */
372 Builder setArpSpa(IpAddress addr);
373
374 /**
375 * Sets the arp src mac address.
376 *
377 * @param addr a macaddress
378 * @return a treatment builder
379 */
380 Builder setArpSha(MacAddress addr);
381
382 /**
383 * Sets the arp operation.
384 *
385 * @param op the value of arp operation.
386 * @return a treatment builder.
387 */
388 Builder setArpOp(short op);
389
390 /**
Jonathan Hart3c259162015-10-21 21:31:19 -0700391 * Uses an extension treatment.
392 *
393 * @param extension extension treatment
394 * @param deviceId device ID
395 * @return a treatment builder
396 */
alshabib880b6442015-11-23 22:13:04 -0800397 Builder extension(ExtensionTreatment extension, DeviceId deviceId);
Jonathan Hart3c259162015-10-21 21:31:19 -0700398
399 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700400 * Add all instructions from another treatment.
401 *
402 * @param treatment another treatment
403 * @return a treatment builder
404 */
405 Builder addTreatment(TrafficTreatment treatment);
406
407 /**
tom8bb16062014-09-12 14:47:46 -0700408 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700409 * <p>
410 * If the treatment is empty when build() is called, it will add a default
411 * drop rule automatically. For a treatment that is actually empty, use
412 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
413 * </p>
tom8bb16062014-09-12 14:47:46 -0700414 *
415 * @return traffic treatment
416 */
417 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700418
tom8bb16062014-09-12 14:47:46 -0700419 }
Saurav Das86af8f12015-05-25 23:55:33 -0700420
tom8bb16062014-09-12 14:47:46 -0700421}