blob: 27a604c0a04d33cf460f7d57a62478c51240ff88 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
alshabibdb774072015-04-20 13:13:51 -070018import org.onosproject.core.ApplicationId;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.core.GroupId;
20import org.onosproject.net.DeviceId;
tom8bb16062014-09-12 14:47:46 -070021
tom8bb16062014-09-12 14:47:46 -070022/**
jcc3d4e14a2015-04-21 11:32:05 +080023 * Represents a generalized match & action pair to be applied to an
24 * infrastructure device.
tom8bb16062014-09-12 14:47:46 -070025 */
Sho SHIMIZU5e5d4aa2015-01-26 16:12:11 -080026public interface FlowRule {
tom8bb16062014-09-12 14:47:46 -070027
Carmelo Cascone41605742017-06-19 15:46:44 +090028 IndexTableId DEFAULT_TABLE = IndexTableId.of(0);
Sho SHIMIZUe2952e42015-09-11 17:11:21 -070029 int MAX_TIMEOUT = 60;
30 int MIN_PRIORITY = 0;
Kavitha Alagesan14dc5132016-06-13 17:25:18 +053031 int MAX_PRIORITY = 65535;
alshabiba7f7ca82014-09-22 11:41:23 -070032
sangho11c30ac2015-01-22 14:30:55 -080033 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -070034 * Reason for flow parameter received from switches.
35 * Used to check reason parameter in flows.
36 */
37 enum FlowRemoveReason {
Murat Parlakisikc6759e82016-06-29 03:22:22 -070038 IDLE_TIMEOUT,
Jimmy Jine9b7a022016-08-12 16:56:48 -070039 HARD_TIMEOUT,
40 DELETE,
41 GROUP_DELETE,
42 METER_DELETE,
43 EVICTION,
44 NO_REASON;
45
46 /**
47 * Covert short to enum.
48 * @return reason in enum
49 * @param reason remove reason in integer
50 */
Murat Parlakisikc6759e82016-06-29 03:22:22 -070051 public static FlowRemoveReason parseShort(short reason) {
52 switch (reason) {
53 case -1 :
54 return NO_REASON;
55 case 0:
56 return IDLE_TIMEOUT;
57 case 1:
58 return HARD_TIMEOUT;
Jimmy Jine9b7a022016-08-12 16:56:48 -070059 case 2 :
60 return DELETE;
61 case 3:
62 return GROUP_DELETE;
63 case 4:
64 return METER_DELETE;
65 case 5:
66 return EVICTION;
Murat Parlakisikc6759e82016-06-29 03:22:22 -070067 default :
68 return NO_REASON;
69 }
70 }
71 }
72
73 /**
Ayaka Koshibed4e53e12014-09-18 14:24:55 -070074 * Returns the ID of this flow.
75 *
76 * @return the flow ID
77 */
78 FlowId id();
alshabib369d2942014-09-12 17:59:35 -070079
tom8bb16062014-09-12 14:47:46 -070080 /**
alshabiba68eb962014-09-24 20:34:13 -070081 * Returns the application id of this flow.
82 *
83 * @return an applicationId
84 */
alshabib92c65ad2014-10-08 21:56:05 -070085 short appId();
alshabiba68eb962014-09-24 20:34:13 -070086
87 /**
alshabib28204e52014-11-12 18:29:45 -080088 * Returns the group id of this flow.
89 *
90 * @return an groupId
91 */
Sho SHIMIZU75a5bd92014-11-25 11:22:56 -080092 GroupId groupId();
alshabib28204e52014-11-12 18:29:45 -080093
94 /**
tom8bb16062014-09-12 14:47:46 -070095 * Returns the flow rule priority given in natural order; higher numbers
96 * mean higher priorities.
97 *
98 * @return flow rule priority
99 */
100 int priority();
101
102 /**
103 * Returns the identity of the device where this rule applies.
104 *
105 * @return device identifier
106 */
107 DeviceId deviceId();
108
109 /**
jcc3d4e14a2015-04-21 11:32:05 +0800110 * Returns the traffic selector that identifies what traffic this rule
111 * should apply to.
tom8bb16062014-09-12 14:47:46 -0700112 *
113 * @return traffic selector
114 */
115 TrafficSelector selector();
116
117 /**
118 * Returns the traffic treatment that applies to selected traffic.
119 *
120 * @return traffic treatment
121 */
alshabib369d2942014-09-12 17:59:35 -0700122 TrafficTreatment treatment();
tom8bb16062014-09-12 14:47:46 -0700123
Ayaka Koshibed4e53e12014-09-18 14:24:55 -0700124 /**
alshabibba5ac482014-10-02 17:15:20 -0700125 * Returns the timeout for this flow requested by an application.
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700126 *
alshabibba5ac482014-10-02 17:15:20 -0700127 * @return integer value of the timeout
alshabib6eb438a2014-10-01 16:39:37 -0700128 */
alshabibba5ac482014-10-02 17:15:20 -0700129 int timeout();
alshabib6eb438a2014-10-01 16:39:37 -0700130
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700131 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700132 * Returns the hard timeout for this flow requested by an application.
Jonathan Hart2b3e22b2017-02-03 18:31:13 -0800133 * This parameter configure switch's flow hard timeout.
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700134 * In case of controller-switch connection lost, this variable can be useful.
135 * @return integer value of the hard Timeout
136 */
137 int hardTimeout();
138
139 /**
140 * Returns the reason for the flow received from switches.
141 *
142 * @return FlowRemoveReason value of reason
143 */
144 FlowRemoveReason reason();
145
146 /**
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700147 * Returns whether the flow is permanent i.e. does not time out.
148 *
149 * @return true if the flow is permanent, otherwise false
150 */
151 boolean isPermanent();
152
sangho11c30ac2015-01-22 14:30:55 -0800153 /**
alshabibdb774072015-04-20 13:13:51 -0700154 * Returns the table id for this rule.
155 *
156 * @return an integer.
Carmelo Cascone41605742017-06-19 15:46:44 +0900157 * @deprecated in Loon release (version 1.11.0). Use {@link #table()} instead.
alshabibdb774072015-04-20 13:13:51 -0700158 */
Carmelo Cascone41605742017-06-19 15:46:44 +0900159 @Deprecated
alshabibdb774072015-04-20 13:13:51 -0700160 int tableId();
161
162 /**
Carmelo Cascone41605742017-06-19 15:46:44 +0900163 * Returns the table identifier for this rule.
164 *
165 * @return a table identifier.
166 */
167 TableId table();
168
169 /**
Jonathan Hartf44e42c2015-08-04 09:58:46 -0700170 * {@inheritDoc}
171 *
172 * Equality for flow rules only considers 'match equality'. This means that
173 * two flow rules with the same match conditions will be equal, regardless
174 * of the treatment or other characteristics of the flow.
175 *
176 * @param obj the reference object with which to compare.
177 * @return {@code true} if this object is the same as the obj
178 * argument; {@code false} otherwise.
179 */
180 boolean equals(Object obj);
181
182 /**
183 * Returns whether this flow rule is an exact match to the flow rule given
184 * in the argument.
185 * <p>
186 * Exact match means that deviceId, priority, selector,
187 * tableId, flowId and treatment are equal. Note that this differs from
188 * the notion of object equality for flow rules, which does not consider the
189 * flowId or treatment when testing equality.
190 * </p>
191 *
192 * @param rule other rule to match against
193 * @return true if the rules are an exact match, otherwise false
194 */
195 boolean exactMatch(FlowRule rule);
196
197 /**
alshabibdb774072015-04-20 13:13:51 -0700198 * A flowrule builder.
199 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700200 interface Builder {
alshabibdb774072015-04-20 13:13:51 -0700201
202 /**
203 * Assigns a cookie value to this flowrule. Mutually exclusive with the
204 * fromApp method. This method is intended to take a cookie value from
205 * the dataplane and not from the application.
206 *
207 * @param cookie a long value
208 * @return this
209 */
210 Builder withCookie(long cookie);
211
212 /**
213 * Assigns the application that built this flow rule to this object.
214 * The short value of the appId will be used as a basis for the
215 * cookie value computation. It is expected that application use this
216 * call to set their application id.
217 *
218 * @param appId an application id
219 * @return this
220 */
221 Builder fromApp(ApplicationId appId);
222
223 /**
224 * Sets the priority for this flow rule.
225 *
226 * @param priority an integer
227 * @return this
228 */
229 Builder withPriority(int priority);
230
231 /**
232 * Sets the deviceId for this flow rule.
233 *
234 * @param deviceId a device id
235 * @return this
236 */
237 Builder forDevice(DeviceId deviceId);
238
239 /**
Carmelo Cascone41605742017-06-19 15:46:44 +0900240 * Sets the table id for this flow rule, when the identifier is of type {@link TableId.Type#INDEX}. Default
241 * value is 0.
242 * <p>
243 * <em>Important:</em> This method is left here for backward compatibility with applications that specifies
244 * table identifiers using integers, e.g. as in OpenFlow. Currently there is no plan to deprecate this method,
245 * however, new applications should favor using {@link #forTable(TableId)}.
alshabibdb774072015-04-20 13:13:51 -0700246 *
247 * @param tableId an integer
248 * @return this
249 */
250 Builder forTable(int tableId);
251
252 /**
Carmelo Cascone41605742017-06-19 15:46:44 +0900253 * Sets the table identifier for this flow rule.
254 * Default identifier is of type {@link TableId.Type#INDEX} and value 0.
255 *
256 * @param tableId table identifier
257 * @return this
258 */
259 Builder forTable(TableId tableId);
260
261 /**
alshabibdb774072015-04-20 13:13:51 -0700262 * Sets the selector (or match field) for this flow rule.
263 *
264 * @param selector a traffic selector
265 * @return this
266 */
267 Builder withSelector(TrafficSelector selector);
268
269 /**
270 * Sets the traffic treatment for this flow rule.
271 *
272 * @param treatment a traffic treatment
273 * @return this
274 */
275 Builder withTreatment(TrafficTreatment treatment);
276
277 /**
278 * Makes this rule permanent on the dataplane.
279 *
280 * @return this
281 */
282 Builder makePermanent();
283
284 /**
285 * Makes this rule temporary and timeout after the specified amount
286 * of time.
287 *
288 * @param timeout an integer
289 * @return this
290 */
291 Builder makeTemporary(int timeout);
292
293 /**
Thiago Santos943cd542017-01-13 13:05:09 -0300294 * Sets the idle timeout parameter in flow table.
295 *
296 * Will automatically make it permanent or temporary if the timeout is 0 or not, respectively.
297 * @param timeout an integer
298 * @return this
299 */
300 default Builder withIdleTimeout(int timeout) {
301 if (timeout == 0) {
302 return makePermanent();
303 } else {
304 return makeTemporary(timeout);
305 }
306 }
307
308 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700309 * Sets hard timeout parameter in flow table.
310 * @param timeout an integer
311 * @return this
312 */
313 Builder withHardTimeout(int timeout);
314
315 /**
316 * Sets reason parameter received from switches .
317 * @param reason a short
318 * @return this
319 */
320 Builder withReason(FlowRemoveReason reason);
321
322 /**
alshabibdb774072015-04-20 13:13:51 -0700323 * Builds a flow rule object.
324 *
325 * @return a flow rule.
326 */
327 FlowRule build();
328
329 }
330
jcc3d4e14a2015-04-21 11:32:05 +0800331 /**
332 * Returns the third party original flow rule.
333 *
334 * @return FlowRuleExtPayLoad
Jonathan Hart2b3e22b2017-02-03 18:31:13 -0800335 * @deprecated in Junco release
jcc3d4e14a2015-04-21 11:32:05 +0800336 */
Jonathan Hart2b3e22b2017-02-03 18:31:13 -0800337 @Deprecated
jcc3d4e14a2015-04-21 11:32:05 +0800338 FlowRuleExtPayLoad payLoad();
tom8bb16062014-09-12 14:47:46 -0700339}