blob: c758c48836ed6256f5342d3dfd732b7f4235af83 [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
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
Sho SHIMIZUe2952e42015-09-11 17:11:21 -070028 int MAX_TIMEOUT = 60;
29 int MIN_PRIORITY = 0;
Kavitha Alagesan14dc5132016-06-13 17:25:18 +053030 int MAX_PRIORITY = 65535;
alshabiba7f7ca82014-09-22 11:41:23 -070031
sangho11c30ac2015-01-22 14:30:55 -080032 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -070033 * Reason for flow parameter received from switches.
34 * Used to check reason parameter in flows.
35 */
36 enum FlowRemoveReason {
Murat Parlakisikc6759e82016-06-29 03:22:22 -070037 IDLE_TIMEOUT,
Jimmy Jine9b7a022016-08-12 16:56:48 -070038 HARD_TIMEOUT,
39 DELETE,
40 GROUP_DELETE,
41 METER_DELETE,
42 EVICTION,
43 NO_REASON;
44
45 /**
46 * Covert short to enum.
47 * @return reason in enum
48 * @param reason remove reason in integer
49 */
Murat Parlakisikc6759e82016-06-29 03:22:22 -070050 public static FlowRemoveReason parseShort(short reason) {
51 switch (reason) {
52 case -1 :
53 return NO_REASON;
54 case 0:
55 return IDLE_TIMEOUT;
56 case 1:
57 return HARD_TIMEOUT;
Jimmy Jine9b7a022016-08-12 16:56:48 -070058 case 2 :
59 return DELETE;
60 case 3:
61 return GROUP_DELETE;
62 case 4:
63 return METER_DELETE;
64 case 5:
65 return EVICTION;
Murat Parlakisikc6759e82016-06-29 03:22:22 -070066 default :
67 return NO_REASON;
68 }
69 }
70 }
71
72 /**
Ayaka Koshibed4e53e12014-09-18 14:24:55 -070073 * Returns the ID of this flow.
74 *
75 * @return the flow ID
76 */
77 FlowId id();
alshabib369d2942014-09-12 17:59:35 -070078
tom8bb16062014-09-12 14:47:46 -070079 /**
alshabiba68eb962014-09-24 20:34:13 -070080 * Returns the application id of this flow.
81 *
82 * @return an applicationId
83 */
alshabib92c65ad2014-10-08 21:56:05 -070084 short appId();
alshabiba68eb962014-09-24 20:34:13 -070085
86 /**
alshabib28204e52014-11-12 18:29:45 -080087 * Returns the group id of this flow.
88 *
89 * @return an groupId
90 */
Sho SHIMIZU75a5bd92014-11-25 11:22:56 -080091 GroupId groupId();
alshabib28204e52014-11-12 18:29:45 -080092
93 /**
tom8bb16062014-09-12 14:47:46 -070094 * Returns the flow rule priority given in natural order; higher numbers
95 * mean higher priorities.
96 *
97 * @return flow rule priority
98 */
99 int priority();
100
101 /**
102 * Returns the identity of the device where this rule applies.
103 *
104 * @return device identifier
105 */
106 DeviceId deviceId();
107
108 /**
jcc3d4e14a2015-04-21 11:32:05 +0800109 * Returns the traffic selector that identifies what traffic this rule
110 * should apply to.
tom8bb16062014-09-12 14:47:46 -0700111 *
112 * @return traffic selector
113 */
114 TrafficSelector selector();
115
116 /**
117 * Returns the traffic treatment that applies to selected traffic.
118 *
119 * @return traffic treatment
120 */
alshabib369d2942014-09-12 17:59:35 -0700121 TrafficTreatment treatment();
tom8bb16062014-09-12 14:47:46 -0700122
Ayaka Koshibed4e53e12014-09-18 14:24:55 -0700123 /**
alshabibba5ac482014-10-02 17:15:20 -0700124 * Returns the timeout for this flow requested by an application.
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700125 *
alshabibba5ac482014-10-02 17:15:20 -0700126 * @return integer value of the timeout
alshabib6eb438a2014-10-01 16:39:37 -0700127 */
alshabibba5ac482014-10-02 17:15:20 -0700128 int timeout();
alshabib6eb438a2014-10-01 16:39:37 -0700129
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700130 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700131 * Returns the hard timeout for this flow requested by an application.
Jonathan Hart2b3e22b2017-02-03 18:31:13 -0800132 * This parameter configure switch's flow hard timeout.
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700133 * In case of controller-switch connection lost, this variable can be useful.
134 * @return integer value of the hard Timeout
135 */
136 int hardTimeout();
137
138 /**
139 * Returns the reason for the flow received from switches.
140 *
141 * @return FlowRemoveReason value of reason
142 */
143 FlowRemoveReason reason();
144
145 /**
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700146 * Returns whether the flow is permanent i.e. does not time out.
147 *
148 * @return true if the flow is permanent, otherwise false
149 */
150 boolean isPermanent();
151
sangho11c30ac2015-01-22 14:30:55 -0800152 /**
alshabibdb774072015-04-20 13:13:51 -0700153 * Returns the table id for this rule.
154 *
155 * @return an integer.
156 */
157 int tableId();
158
159 /**
Jonathan Hartf44e42c2015-08-04 09:58:46 -0700160 * {@inheritDoc}
161 *
162 * Equality for flow rules only considers 'match equality'. This means that
163 * two flow rules with the same match conditions will be equal, regardless
164 * of the treatment or other characteristics of the flow.
165 *
166 * @param obj the reference object with which to compare.
167 * @return {@code true} if this object is the same as the obj
168 * argument; {@code false} otherwise.
169 */
170 boolean equals(Object obj);
171
172 /**
173 * Returns whether this flow rule is an exact match to the flow rule given
174 * in the argument.
175 * <p>
176 * Exact match means that deviceId, priority, selector,
177 * tableId, flowId and treatment are equal. Note that this differs from
178 * the notion of object equality for flow rules, which does not consider the
179 * flowId or treatment when testing equality.
180 * </p>
181 *
182 * @param rule other rule to match against
183 * @return true if the rules are an exact match, otherwise false
184 */
185 boolean exactMatch(FlowRule rule);
186
187 /**
alshabibdb774072015-04-20 13:13:51 -0700188 * A flowrule builder.
189 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700190 interface Builder {
alshabibdb774072015-04-20 13:13:51 -0700191
192 /**
193 * Assigns a cookie value to this flowrule. Mutually exclusive with the
194 * fromApp method. This method is intended to take a cookie value from
195 * the dataplane and not from the application.
196 *
197 * @param cookie a long value
198 * @return this
199 */
200 Builder withCookie(long cookie);
201
202 /**
203 * Assigns the application that built this flow rule to this object.
204 * The short value of the appId will be used as a basis for the
205 * cookie value computation. It is expected that application use this
206 * call to set their application id.
207 *
208 * @param appId an application id
209 * @return this
210 */
211 Builder fromApp(ApplicationId appId);
212
213 /**
214 * Sets the priority for this flow rule.
215 *
216 * @param priority an integer
217 * @return this
218 */
219 Builder withPriority(int priority);
220
221 /**
222 * Sets the deviceId for this flow rule.
223 *
224 * @param deviceId a device id
225 * @return this
226 */
227 Builder forDevice(DeviceId deviceId);
228
229 /**
230 * Sets the table id for this flow rule. Default value is 0.
231 *
232 * @param tableId an integer
233 * @return this
234 */
235 Builder forTable(int tableId);
236
237 /**
238 * Sets the selector (or match field) for this flow rule.
239 *
240 * @param selector a traffic selector
241 * @return this
242 */
243 Builder withSelector(TrafficSelector selector);
244
245 /**
246 * Sets the traffic treatment for this flow rule.
247 *
248 * @param treatment a traffic treatment
249 * @return this
250 */
251 Builder withTreatment(TrafficTreatment treatment);
252
253 /**
254 * Makes this rule permanent on the dataplane.
255 *
256 * @return this
257 */
258 Builder makePermanent();
259
260 /**
261 * Makes this rule temporary and timeout after the specified amount
262 * of time.
263 *
264 * @param timeout an integer
265 * @return this
266 */
267 Builder makeTemporary(int timeout);
268
269 /**
Thiago Santos943cd542017-01-13 13:05:09 -0300270 * Sets the idle timeout parameter in flow table.
271 *
272 * Will automatically make it permanent or temporary if the timeout is 0 or not, respectively.
273 * @param timeout an integer
274 * @return this
275 */
276 default Builder withIdleTimeout(int timeout) {
277 if (timeout == 0) {
278 return makePermanent();
279 } else {
280 return makeTemporary(timeout);
281 }
282 }
283
284 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700285 * Sets hard timeout parameter in flow table.
286 * @param timeout an integer
287 * @return this
288 */
289 Builder withHardTimeout(int timeout);
290
291 /**
292 * Sets reason parameter received from switches .
293 * @param reason a short
294 * @return this
295 */
296 Builder withReason(FlowRemoveReason reason);
297
298 /**
alshabibdb774072015-04-20 13:13:51 -0700299 * Builds a flow rule object.
300 *
301 * @return a flow rule.
302 */
303 FlowRule build();
304
305 }
306
jcc3d4e14a2015-04-21 11:32:05 +0800307 /**
308 * Returns the third party original flow rule.
309 *
310 * @return FlowRuleExtPayLoad
Jonathan Hart2b3e22b2017-02-03 18:31:13 -0800311 * @deprecated in Junco release
jcc3d4e14a2015-04-21 11:32:05 +0800312 */
Jonathan Hart2b3e22b2017-02-03 18:31:13 -0800313 @Deprecated
jcc3d4e14a2015-04-21 11:32:05 +0800314 FlowRuleExtPayLoad payLoad();
tom8bb16062014-09-12 14:47:46 -0700315}