blob: 3802bf2fa4e45143c19bcec09e8c245d82c67791 [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;
alshabib55a55d92014-09-16 11:59:31 -070027
Jonathan Hart54b406b2015-03-06 16:24:14 -080028import java.util.List;
29
tom8bb16062014-09-12 14:47:46 -070030/**
31 * Abstraction of network traffic treatment.
32 */
33public interface TrafficTreatment {
34
35 /**
alshabib346b5b32015-03-06 00:42:16 -080036 * Returns the list of treatment instructions that will be applied
37 * further down the pipeline.
38 * @return list of treatment instructions
39 */
40 List<Instruction> deferred();
41
42 /**
43 * Returns the list of treatment instructions that will be applied
44 * immediately.
45 * @return list of treatment instructions
46 */
47 List<Instruction> immediate();
48
49 /**
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -070050 * Returns the list of all instructions in the treatment, both immediate and
51 * deferred.
52 *
53 * @return list of treatment instructions
54 */
55 List<Instruction> allInstructions();
56
57 /**
alshabib346b5b32015-03-06 00:42:16 -080058 * Returns the next table in the pipeline.
59 * @return a table transition; may be null.
60 */
61 Instructions.TableTypeTransition tableTransition();
62
63 /**
64 * Whether the deferred treatment instructions will be cleared
65 * by the device.
66 * @return a boolean
67 */
Jonathan Hart4a0ba562015-03-23 17:23:33 -070068 boolean clearedDeferred();
alshabib346b5b32015-03-06 00:42:16 -080069
70 /**
Saurav Das86af8f12015-05-25 23:55:33 -070071 * Returns the metadata instruction if there is one.
72 *
73 * @return a metadata instruction that may be null
74 */
75 Instructions.MetadataInstruction writeMetadata();
76
77 /**
tom8bb16062014-09-12 14:47:46 -070078 * Builder of traffic treatment entities.
79 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070080 interface Builder {
tom8bb16062014-09-12 14:47:46 -070081
82 /**
alshabib010c31d2014-09-26 10:01:12 -070083 * Adds an instruction to the builder.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080084 *
alshabib010c31d2014-09-26 10:01:12 -070085 * @param instruction an instruction
86 * @return a treatment builder
tom8bb16062014-09-12 14:47:46 -070087 */
alshabib369d2942014-09-12 17:59:35 -070088 Builder add(Instruction instruction);
tom8bb16062014-09-12 14:47:46 -070089
90 /**
Thomas Vachuskaf4df0052015-01-06 12:30:11 -080091 * Adds a drop instruction.
92 *
93 * @return a treatment builder
alshabib010c31d2014-09-26 10:01:12 -070094 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070095 Builder drop();
Thomas Vachuskaf4df0052015-01-06 12:30:11 -080096
97 /**
98 * Adds a punt-to-controller instruction.
99 *
100 * @return a treatment builder
101 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700102 Builder punt();
alshabib010c31d2014-09-26 10:01:12 -0700103
104 /**
105 * Set the output port.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800106 *
alshabib010c31d2014-09-26 10:01:12 -0700107 * @param number the out port
108 * @return a treatment builder
109 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700110 Builder setOutput(PortNumber number);
alshabib010c31d2014-09-26 10:01:12 -0700111
112 /**
113 * Sets the src l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800114 *
alshabib010c31d2014-09-26 10:01:12 -0700115 * @param addr a macaddress
116 * @return a treatment builder
117 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700118 Builder setEthSrc(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700119
120 /**
121 * Sets the dst 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 setEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700127
128 /**
129 * Sets the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800130 *
alshabib010c31d2014-09-26 10:01:12 -0700131 * @param id a vlanid
132 * @return a treatment builder
133 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700134 Builder setVlanId(VlanId id);
alshabib010c31d2014-09-26 10:01:12 -0700135
136 /**
137 * Sets the vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800138 *
alshabib010c31d2014-09-26 10:01:12 -0700139 * @param pcp a vlan priority
140 * @return a treatment builder
141 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700142 Builder setVlanPcp(Byte pcp);
alshabib010c31d2014-09-26 10:01:12 -0700143
144 /**
145 * Sets the src l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800146 *
alshabib010c31d2014-09-26 10:01:12 -0700147 * @param addr an ip
148 * @return a treatment builder
149 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700150 Builder setIpSrc(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700151
152 /**
153 * Sets the dst 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 setIpDst(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700159
160 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800161 * Decrement the TTL in IP header by one.
sangho3f97a17d2015-01-29 22:56:29 -0800162 *
163 * @return a treatment builder
164 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700165 Builder decNwTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800166
167 /**
168 * Copy the TTL to outer protocol layer.
169 *
170 * @return a treatment builder
171 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700172 Builder copyTtlOut();
sangho3f97a17d2015-01-29 22:56:29 -0800173
174 /**
175 * Copy the TTL to inner protocol layer.
176 *
177 * @return a treatment builder
178 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700179 Builder copyTtlIn();
sangho3f97a17d2015-01-29 22:56:29 -0800180
181 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800182 * Push MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800183 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800184 * @return a treatment builder.
185 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700186 Builder pushMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800187
188 /**
189 * Pops MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800190 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800191 * @return a treatment builder.
192 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700193 Builder popMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800194
195 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100196 * Pops MPLS ether type and set the new ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800197 *
Michele Santuari4b6019e2014-12-19 11:31:45 +0100198 * @param etherType an ether type
sangho3f97a17d2015-01-29 22:56:29 -0800199 * @return a treatment builder.
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700200 * @deprecated in Drake Release
sangho3f97a17d2015-01-29 22:56:29 -0800201 */
alshabib7b808c52015-06-26 14:22:24 -0700202 @Deprecated
alshabib0ad43982015-05-07 13:43:13 -0700203 Builder popMpls(int etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800204
205 /**
alshabib7b808c52015-06-26 14:22:24 -0700206 * Pops MPLS ether type and set the new ethertype.
207 *
208 * @param etherType an ether type
209 * @return a treatment builder.
210 */
211 Builder popMpls(EthType etherType);
212
213 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800214 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800215 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800216 * @param mplsLabel MPLS label.
217 * @return a treatment builder.
218 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700219 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800220
221 /**
sangho3f97a17d2015-01-29 22:56:29 -0800222 * Decrement MPLS TTL.
223 *
224 * @return a treatment builder
225 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700226 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800227
228 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700229 * Sets the optical channel ID or lambda.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800230 *
Marc De Leenheer49087752014-10-23 13:54:09 -0700231 * @param lambda optical channel ID
232 * @return a treatment builder
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700233 * @deprecated in Drake Release
Marc De Leenheer49087752014-10-23 13:54:09 -0700234 */
Sho SHIMIZU9553bb82015-06-30 16:02:45 -0700235 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700236 Builder setLambda(short lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700237
238 /**
sangho8995ac52015-02-04 11:29:03 -0800239 * Sets the group ID.
240 *
241 * @param groupId group ID
242 * @return a treatment builder
243 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700244 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800245
alshabib9af70072015-02-09 14:34:16 -0800246
247 /**
248 * Sets the next table type to transition to.
249 *
250 * @param type the table type
251 * @return a treatement builder
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -0700252 * @deprecated in Cardinal Release
alshabib9af70072015-02-09 14:34:16 -0800253 */
alshabibd17abc22015-04-21 18:26:35 -0700254 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700255 Builder transition(FlowRule.Type type);
alshabib9af70072015-02-09 14:34:16 -0800256
sangho8995ac52015-02-04 11:29:03 -0800257 /**
alshabibd17abc22015-04-21 18:26:35 -0700258 * Sets the next table id to transition to.
259 *
260 * @param tableId the table table
261 * @return a treatement builder
262 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700263 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700264
265
266 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800267 * Pops outermost VLAN tag.
268 *
269 * @return a treatment builder.
270 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700271 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800272
273 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800274 * Pushes a new VLAN tag.
275 *
276 * @return a treatment builder.
277 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700278 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800279
280 /**
alshabib346b5b32015-03-06 00:42:16 -0800281 * Any instructions preceded by this method call will be deferred.
282 * @return a treatment builder
283 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700284 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800285
286 /**
287 * Any instructions preceded by this method call will be immediate.
288 * @return a treatment builder
289 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700290 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800291
292
293 /**
294 * Instructs the device to clear the deferred instructions set.
295 * @return a treatment builder
296 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700297 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800298
299 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700300 * Writes metadata to associate with a packet.
301 * <pre>
302 * {@code
303 * new_metadata = (old_metadata & ̃mask) | (value & mask)
304 * }
305 * </pre>
306 *
307 * @param value the metadata to write
308 * @param mask the masked bits for the value
309 * @return a treatment builder
310 */
311 Builder writeMetadata(long value, long mask);
312
313 /**
tom8bb16062014-09-12 14:47:46 -0700314 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700315 * <p>
316 * If the treatment is empty when build() is called, it will add a default
317 * drop rule automatically. For a treatment that is actually empty, use
318 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
319 * </p>
tom8bb16062014-09-12 14:47:46 -0700320 *
321 * @return traffic treatment
322 */
323 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700324
tom8bb16062014-09-12 14:47:46 -0700325 }
Saurav Das86af8f12015-05-25 23:55:33 -0700326
tom8bb16062014-09-12 14:47:46 -0700327}