blob: a82919f60d91cb014b647b983e43ecdef51e7974 [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
Pavlin Radoslavov855ea2d2014-10-30 15:32:39 -070018import org.onlab.packet.IpAddress;
alshabib010c31d2014-09-26 10:01:12 -070019import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010020import org.onlab.packet.MplsLabel;
alshabib010c31d2014-09-26 10:01:12 -070021import org.onlab.packet.VlanId;
Jonathan Hart54b406b2015-03-06 16:24:14 -080022import org.onosproject.core.GroupId;
23import org.onosproject.net.PortNumber;
24import org.onosproject.net.flow.instructions.Instruction;
alshabib346b5b32015-03-06 00:42:16 -080025import org.onosproject.net.flow.instructions.Instructions;
alshabib55a55d92014-09-16 11:59:31 -070026
Jonathan Hart54b406b2015-03-06 16:24:14 -080027import java.util.List;
28
tom8bb16062014-09-12 14:47:46 -070029/**
30 * Abstraction of network traffic treatment.
31 */
32public interface TrafficTreatment {
33
34 /**
alshabib346b5b32015-03-06 00:42:16 -080035 * Returns the list of treatment instructions that will be applied
36 * further down the pipeline.
37 * @return list of treatment instructions
38 */
39 List<Instruction> deferred();
40
41 /**
42 * Returns the list of treatment instructions that will be applied
43 * immediately.
44 * @return list of treatment instructions
45 */
46 List<Instruction> immediate();
47
48 /**
Jonathan Hart8ef6d3b2015-03-08 21:21:27 -070049 * Returns the list of all instructions in the treatment, both immediate and
50 * deferred.
51 *
52 * @return list of treatment instructions
53 */
54 List<Instruction> allInstructions();
55
56 /**
alshabib346b5b32015-03-06 00:42:16 -080057 * Returns the next table in the pipeline.
58 * @return a table transition; may be null.
59 */
60 Instructions.TableTypeTransition tableTransition();
61
62 /**
63 * Whether the deferred treatment instructions will be cleared
64 * by the device.
65 * @return a boolean
66 */
Jonathan Hart4a0ba562015-03-23 17:23:33 -070067 boolean clearedDeferred();
alshabib346b5b32015-03-06 00:42:16 -080068
69 /**
Saurav Das86af8f12015-05-25 23:55:33 -070070 * Returns the metadata instruction if there is one.
71 *
72 * @return a metadata instruction that may be null
73 */
74 Instructions.MetadataInstruction writeMetadata();
75
76 /**
tom8bb16062014-09-12 14:47:46 -070077 * Builder of traffic treatment entities.
78 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070079 interface Builder {
tom8bb16062014-09-12 14:47:46 -070080
81 /**
alshabib010c31d2014-09-26 10:01:12 -070082 * Adds an instruction to the builder.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -080083 *
alshabib010c31d2014-09-26 10:01:12 -070084 * @param instruction an instruction
85 * @return a treatment builder
tom8bb16062014-09-12 14:47:46 -070086 */
alshabib369d2942014-09-12 17:59:35 -070087 Builder add(Instruction instruction);
tom8bb16062014-09-12 14:47:46 -070088
89 /**
Thomas Vachuskaf4df0052015-01-06 12:30:11 -080090 * Adds a drop instruction.
91 *
92 * @return a treatment builder
alshabib010c31d2014-09-26 10:01:12 -070093 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -070094 Builder drop();
Thomas Vachuskaf4df0052015-01-06 12:30:11 -080095
96 /**
97 * Adds a punt-to-controller instruction.
98 *
99 * @return a treatment builder
100 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700101 Builder punt();
alshabib010c31d2014-09-26 10:01:12 -0700102
103 /**
104 * Set the output port.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800105 *
alshabib010c31d2014-09-26 10:01:12 -0700106 * @param number the out port
107 * @return a treatment builder
108 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700109 Builder setOutput(PortNumber number);
alshabib010c31d2014-09-26 10:01:12 -0700110
111 /**
112 * Sets the src l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800113 *
alshabib010c31d2014-09-26 10:01:12 -0700114 * @param addr a macaddress
115 * @return a treatment builder
116 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700117 Builder setEthSrc(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700118
119 /**
120 * Sets the dst l2 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800121 *
alshabib010c31d2014-09-26 10:01:12 -0700122 * @param addr a macaddress
123 * @return a treatment builder
124 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700125 Builder setEthDst(MacAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700126
127 /**
128 * Sets the vlan id.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800129 *
alshabib010c31d2014-09-26 10:01:12 -0700130 * @param id a vlanid
131 * @return a treatment builder
132 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700133 Builder setVlanId(VlanId id);
alshabib010c31d2014-09-26 10:01:12 -0700134
135 /**
136 * Sets the vlan priority.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800137 *
alshabib010c31d2014-09-26 10:01:12 -0700138 * @param pcp a vlan priority
139 * @return a treatment builder
140 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700141 Builder setVlanPcp(Byte pcp);
alshabib010c31d2014-09-26 10:01:12 -0700142
143 /**
144 * Sets the src l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800145 *
alshabib010c31d2014-09-26 10:01:12 -0700146 * @param addr an ip
147 * @return a treatment builder
148 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700149 Builder setIpSrc(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700150
151 /**
152 * Sets the dst l3 address.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800153 *
alshabib010c31d2014-09-26 10:01:12 -0700154 * @param addr an ip
155 * @return a treatment builder
156 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700157 Builder setIpDst(IpAddress addr);
alshabib010c31d2014-09-26 10:01:12 -0700158
159 /**
Pavlin Radoslavovfebe82c2015-02-11 19:08:15 -0800160 * Decrement the TTL in IP header by one.
sangho3f97a17d2015-01-29 22:56:29 -0800161 *
162 * @return a treatment builder
163 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700164 Builder decNwTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800165
166 /**
167 * Copy the TTL to outer protocol layer.
168 *
169 * @return a treatment builder
170 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700171 Builder copyTtlOut();
sangho3f97a17d2015-01-29 22:56:29 -0800172
173 /**
174 * Copy the TTL to inner protocol layer.
175 *
176 * @return a treatment builder
177 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700178 Builder copyTtlIn();
sangho3f97a17d2015-01-29 22:56:29 -0800179
180 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800181 * Push MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800182 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800183 * @return a treatment builder.
184 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700185 Builder pushMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800186
187 /**
188 * Pops MPLS ether type.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800189 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800190 * @return a treatment builder.
191 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700192 Builder popMpls();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800193
194 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100195 * Pops MPLS ether type and set the new ethertype.
sangho3f97a17d2015-01-29 22:56:29 -0800196 *
Michele Santuari4b6019e2014-12-19 11:31:45 +0100197 * @param etherType an ether type
sangho3f97a17d2015-01-29 22:56:29 -0800198 * @return a treatment builder.
199 */
alshabib0ad43982015-05-07 13:43:13 -0700200 Builder popMpls(int etherType);
sangho3f97a17d2015-01-29 22:56:29 -0800201
202 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800203 * Sets the mpls label.
Thomas Vachuskaf4df0052015-01-06 12:30:11 -0800204 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800205 * @param mplsLabel MPLS label.
206 * @return a treatment builder.
207 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700208 Builder setMpls(MplsLabel mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800209
210 /**
sangho3f97a17d2015-01-29 22:56:29 -0800211 * Decrement MPLS TTL.
212 *
213 * @return a treatment builder
214 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700215 Builder decMplsTtl();
sangho3f97a17d2015-01-29 22:56:29 -0800216
217 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700218 * Sets the optical channel ID or lambda.
Sho SHIMIZUbdaea832014-11-12 11:29:38 -0800219 *
Marc De Leenheer49087752014-10-23 13:54:09 -0700220 * @param lambda optical channel ID
221 * @return a treatment builder
222 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700223 Builder setLambda(short lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700224
225 /**
sangho8995ac52015-02-04 11:29:03 -0800226 * Sets the group ID.
227 *
228 * @param groupId group ID
229 * @return a treatment builder
230 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700231 Builder group(GroupId groupId);
sangho8995ac52015-02-04 11:29:03 -0800232
alshabib9af70072015-02-09 14:34:16 -0800233
234 /**
235 * Sets the next table type to transition to.
236 *
237 * @param type the table type
238 * @return a treatement builder
239 */
alshabibd17abc22015-04-21 18:26:35 -0700240 @Deprecated
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700241 Builder transition(FlowRule.Type type);
alshabib9af70072015-02-09 14:34:16 -0800242
sangho8995ac52015-02-04 11:29:03 -0800243 /**
alshabibd17abc22015-04-21 18:26:35 -0700244 * Sets the next table id to transition to.
245 *
246 * @param tableId the table table
247 * @return a treatement builder
248 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700249 Builder transition(Integer tableId);
alshabibd17abc22015-04-21 18:26:35 -0700250
251
252 /**
Saurav Dasfbe25c52015-03-04 11:12:00 -0800253 * Pops outermost VLAN tag.
254 *
255 * @return a treatment builder.
256 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700257 Builder popVlan();
Saurav Dasfbe25c52015-03-04 11:12:00 -0800258
259 /**
Jonathan Hart54b406b2015-03-06 16:24:14 -0800260 * Pushes a new VLAN tag.
261 *
262 * @return a treatment builder.
263 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700264 Builder pushVlan();
Jonathan Hart54b406b2015-03-06 16:24:14 -0800265
266 /**
alshabib346b5b32015-03-06 00:42:16 -0800267 * Any instructions preceded by this method call will be deferred.
268 * @return a treatment builder
269 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700270 Builder deferred();
alshabib346b5b32015-03-06 00:42:16 -0800271
272 /**
273 * Any instructions preceded by this method call will be immediate.
274 * @return a treatment builder
275 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700276 Builder immediate();
alshabib346b5b32015-03-06 00:42:16 -0800277
278
279 /**
280 * Instructs the device to clear the deferred instructions set.
281 * @return a treatment builder
282 */
Sho SHIMIZU79906e42015-05-04 18:27:31 -0700283 Builder wipeDeferred();
alshabib346b5b32015-03-06 00:42:16 -0800284
285 /**
Saurav Das86af8f12015-05-25 23:55:33 -0700286 * Writes metadata to associate with a packet.
287 * <pre>
288 * {@code
289 * new_metadata = (old_metadata & ̃mask) | (value & mask)
290 * }
291 * </pre>
292 *
293 * @param value the metadata to write
294 * @param mask the masked bits for the value
295 * @return a treatment builder
296 */
297 Builder writeMetadata(long value, long mask);
298
299 /**
tom8bb16062014-09-12 14:47:46 -0700300 * Builds an immutable traffic treatment descriptor.
Brian O'Connor6b528132015-03-10 16:39:52 -0700301 * <p>
302 * If the treatment is empty when build() is called, it will add a default
303 * drop rule automatically. For a treatment that is actually empty, use
304 * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
305 * </p>
tom8bb16062014-09-12 14:47:46 -0700306 *
307 * @return traffic treatment
308 */
309 TrafficTreatment build();
Saurav Das86af8f12015-05-25 23:55:33 -0700310
tom8bb16062014-09-12 14:47:46 -0700311 }
Saurav Das86af8f12015-05-25 23:55:33 -0700312
tom8bb16062014-09-12 14:47:46 -0700313}