blob: 750376af0225c3e5d76c51c16d326f21d555717f [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;
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080021import org.onosproject.net.pi.service.PiTranslatable;
tom8bb16062014-09-12 14:47:46 -070022
tom8bb16062014-09-12 14:47:46 -070023/**
jcc3d4e14a2015-04-21 11:32:05 +080024 * Represents a generalized match & action pair to be applied to an
25 * infrastructure device.
tom8bb16062014-09-12 14:47:46 -070026 */
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080027public interface FlowRule extends PiTranslatable {
tom8bb16062014-09-12 14:47:46 -070028
Carmelo Cascone41605742017-06-19 15:46:44 +090029 IndexTableId DEFAULT_TABLE = IndexTableId.of(0);
Sho SHIMIZUe2952e42015-09-11 17:11:21 -070030 int MAX_TIMEOUT = 60;
31 int MIN_PRIORITY = 0;
Kavitha Alagesan14dc5132016-06-13 17:25:18 +053032 int MAX_PRIORITY = 65535;
alshabiba7f7ca82014-09-22 11:41:23 -070033
sangho11c30ac2015-01-22 14:30:55 -080034 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -070035 * Reason for flow parameter received from switches.
36 * Used to check reason parameter in flows.
37 */
38 enum FlowRemoveReason {
Murat Parlakisikc6759e82016-06-29 03:22:22 -070039 IDLE_TIMEOUT,
Jimmy Jine9b7a022016-08-12 16:56:48 -070040 HARD_TIMEOUT,
41 DELETE,
42 GROUP_DELETE,
43 METER_DELETE,
44 EVICTION,
45 NO_REASON;
46
47 /**
48 * Covert short to enum.
49 * @return reason in enum
50 * @param reason remove reason in integer
51 */
Murat Parlakisikc6759e82016-06-29 03:22:22 -070052 public static FlowRemoveReason parseShort(short reason) {
53 switch (reason) {
54 case -1 :
55 return NO_REASON;
56 case 0:
57 return IDLE_TIMEOUT;
58 case 1:
59 return HARD_TIMEOUT;
Jimmy Jine9b7a022016-08-12 16:56:48 -070060 case 2 :
61 return DELETE;
62 case 3:
63 return GROUP_DELETE;
64 case 4:
65 return METER_DELETE;
66 case 5:
67 return EVICTION;
Murat Parlakisikc6759e82016-06-29 03:22:22 -070068 default :
69 return NO_REASON;
70 }
71 }
72 }
73
74 /**
Ayaka Koshibed4e53e12014-09-18 14:24:55 -070075 * Returns the ID of this flow.
76 *
77 * @return the flow ID
78 */
79 FlowId id();
alshabib369d2942014-09-12 17:59:35 -070080
tom8bb16062014-09-12 14:47:46 -070081 /**
alshabiba68eb962014-09-24 20:34:13 -070082 * Returns the application id of this flow.
83 *
84 * @return an applicationId
85 */
alshabib92c65ad2014-10-08 21:56:05 -070086 short appId();
alshabiba68eb962014-09-24 20:34:13 -070087
88 /**
alshabib28204e52014-11-12 18:29:45 -080089 * Returns the group id of this flow.
90 *
91 * @return an groupId
92 */
Sho SHIMIZU75a5bd92014-11-25 11:22:56 -080093 GroupId groupId();
alshabib28204e52014-11-12 18:29:45 -080094
95 /**
tom8bb16062014-09-12 14:47:46 -070096 * Returns the flow rule priority given in natural order; higher numbers
97 * mean higher priorities.
98 *
99 * @return flow rule priority
100 */
101 int priority();
102
103 /**
104 * Returns the identity of the device where this rule applies.
105 *
106 * @return device identifier
107 */
108 DeviceId deviceId();
109
110 /**
jcc3d4e14a2015-04-21 11:32:05 +0800111 * Returns the traffic selector that identifies what traffic this rule
112 * should apply to.
tom8bb16062014-09-12 14:47:46 -0700113 *
114 * @return traffic selector
115 */
116 TrafficSelector selector();
117
118 /**
119 * Returns the traffic treatment that applies to selected traffic.
120 *
121 * @return traffic treatment
122 */
alshabib369d2942014-09-12 17:59:35 -0700123 TrafficTreatment treatment();
tom8bb16062014-09-12 14:47:46 -0700124
Ayaka Koshibed4e53e12014-09-18 14:24:55 -0700125 /**
alshabibba5ac482014-10-02 17:15:20 -0700126 * Returns the timeout for this flow requested by an application.
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700127 *
alshabibba5ac482014-10-02 17:15:20 -0700128 * @return integer value of the timeout
alshabib6eb438a2014-10-01 16:39:37 -0700129 */
alshabibba5ac482014-10-02 17:15:20 -0700130 int timeout();
alshabib6eb438a2014-10-01 16:39:37 -0700131
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700132 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700133 * Returns the hard timeout for this flow requested by an application.
Jonathan Hart2b3e22b2017-02-03 18:31:13 -0800134 * This parameter configure switch's flow hard timeout.
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700135 * In case of controller-switch connection lost, this variable can be useful.
136 * @return integer value of the hard Timeout
137 */
138 int hardTimeout();
139
140 /**
141 * Returns the reason for the flow received from switches.
142 *
143 * @return FlowRemoveReason value of reason
144 */
145 FlowRemoveReason reason();
146
147 /**
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700148 * Returns whether the flow is permanent i.e. does not time out.
149 *
150 * @return true if the flow is permanent, otherwise false
151 */
152 boolean isPermanent();
153
sangho11c30ac2015-01-22 14:30:55 -0800154 /**
alshabibdb774072015-04-20 13:13:51 -0700155 * Returns the table id for this rule.
156 *
157 * @return an integer.
Carmelo Cascone41605742017-06-19 15:46:44 +0900158 * @deprecated in Loon release (version 1.11.0). Use {@link #table()} instead.
alshabibdb774072015-04-20 13:13:51 -0700159 */
Carmelo Cascone41605742017-06-19 15:46:44 +0900160 @Deprecated
alshabibdb774072015-04-20 13:13:51 -0700161 int tableId();
162
163 /**
Carmelo Cascone41605742017-06-19 15:46:44 +0900164 * Returns the table identifier for this rule.
165 *
166 * @return a table identifier.
167 */
168 TableId table();
169
170 /**
Jonathan Hartf44e42c2015-08-04 09:58:46 -0700171 * {@inheritDoc}
172 *
173 * Equality for flow rules only considers 'match equality'. This means that
174 * two flow rules with the same match conditions will be equal, regardless
175 * of the treatment or other characteristics of the flow.
176 *
177 * @param obj the reference object with which to compare.
178 * @return {@code true} if this object is the same as the obj
179 * argument; {@code false} otherwise.
180 */
181 boolean equals(Object obj);
182
183 /**
184 * Returns whether this flow rule is an exact match to the flow rule given
185 * in the argument.
186 * <p>
187 * Exact match means that deviceId, priority, selector,
188 * tableId, flowId and treatment are equal. Note that this differs from
189 * the notion of object equality for flow rules, which does not consider the
190 * flowId or treatment when testing equality.
191 * </p>
192 *
193 * @param rule other rule to match against
194 * @return true if the rules are an exact match, otherwise false
195 */
196 boolean exactMatch(FlowRule rule);
197
198 /**
alshabibdb774072015-04-20 13:13:51 -0700199 * A flowrule builder.
200 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700201 interface Builder {
alshabibdb774072015-04-20 13:13:51 -0700202
203 /**
204 * Assigns a cookie value to this flowrule. Mutually exclusive with the
205 * fromApp method. This method is intended to take a cookie value from
206 * the dataplane and not from the application.
207 *
208 * @param cookie a long value
209 * @return this
210 */
211 Builder withCookie(long cookie);
212
213 /**
214 * Assigns the application that built this flow rule to this object.
215 * The short value of the appId will be used as a basis for the
216 * cookie value computation. It is expected that application use this
217 * call to set their application id.
218 *
219 * @param appId an application id
220 * @return this
221 */
222 Builder fromApp(ApplicationId appId);
223
224 /**
225 * Sets the priority for this flow rule.
226 *
227 * @param priority an integer
228 * @return this
229 */
230 Builder withPriority(int priority);
231
232 /**
233 * Sets the deviceId for this flow rule.
234 *
235 * @param deviceId a device id
236 * @return this
237 */
238 Builder forDevice(DeviceId deviceId);
239
240 /**
Carmelo Cascone41605742017-06-19 15:46:44 +0900241 * Sets the table id for this flow rule, when the identifier is of type {@link TableId.Type#INDEX}. Default
242 * value is 0.
243 * <p>
244 * <em>Important:</em> This method is left here for backward compatibility with applications that specifies
245 * table identifiers using integers, e.g. as in OpenFlow. Currently there is no plan to deprecate this method,
246 * however, new applications should favor using {@link #forTable(TableId)}.
alshabibdb774072015-04-20 13:13:51 -0700247 *
248 * @param tableId an integer
249 * @return this
250 */
251 Builder forTable(int tableId);
252
253 /**
Carmelo Cascone41605742017-06-19 15:46:44 +0900254 * Sets the table identifier for this flow rule.
255 * Default identifier is of type {@link TableId.Type#INDEX} and value 0.
256 *
257 * @param tableId table identifier
258 * @return this
259 */
260 Builder forTable(TableId tableId);
261
262 /**
alshabibdb774072015-04-20 13:13:51 -0700263 * Sets the selector (or match field) for this flow rule.
264 *
265 * @param selector a traffic selector
266 * @return this
267 */
268 Builder withSelector(TrafficSelector selector);
269
270 /**
271 * Sets the traffic treatment for this flow rule.
272 *
273 * @param treatment a traffic treatment
274 * @return this
275 */
276 Builder withTreatment(TrafficTreatment treatment);
277
278 /**
279 * Makes this rule permanent on the dataplane.
280 *
281 * @return this
282 */
283 Builder makePermanent();
284
285 /**
286 * Makes this rule temporary and timeout after the specified amount
287 * of time.
288 *
289 * @param timeout an integer
290 * @return this
291 */
292 Builder makeTemporary(int timeout);
293
294 /**
Thiago Santos943cd542017-01-13 13:05:09 -0300295 * Sets the idle timeout parameter in flow table.
296 *
297 * Will automatically make it permanent or temporary if the timeout is 0 or not, respectively.
298 * @param timeout an integer
299 * @return this
300 */
301 default Builder withIdleTimeout(int timeout) {
302 if (timeout == 0) {
303 return makePermanent();
304 } else {
305 return makeTemporary(timeout);
306 }
307 }
308
309 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700310 * Sets hard timeout parameter in flow table.
311 * @param timeout an integer
312 * @return this
313 */
314 Builder withHardTimeout(int timeout);
315
316 /**
317 * Sets reason parameter received from switches .
318 * @param reason a short
319 * @return this
320 */
321 Builder withReason(FlowRemoveReason reason);
322
323 /**
alshabibdb774072015-04-20 13:13:51 -0700324 * Builds a flow rule object.
325 *
326 * @return a flow rule.
327 */
328 FlowRule build();
329
330 }
tom8bb16062014-09-12 14:47:46 -0700331}