blob: 35804b8f09577e2dce37ec44964c1a2debc48135 [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 {
37 NO_REASON,
38 IDLE_TIMEOUT,
39 HARD_TIMEOUT;
40 public static FlowRemoveReason parseShort(short reason) {
41 switch (reason) {
42 case -1 :
43 return NO_REASON;
44 case 0:
45 return IDLE_TIMEOUT;
46 case 1:
47 return HARD_TIMEOUT;
48 default :
49 return NO_REASON;
50 }
51 }
52 }
53
54 /**
Ayaka Koshibed4e53e12014-09-18 14:24:55 -070055 * Returns the ID of this flow.
56 *
57 * @return the flow ID
58 */
59 FlowId id();
alshabib369d2942014-09-12 17:59:35 -070060
tom8bb16062014-09-12 14:47:46 -070061 /**
alshabiba68eb962014-09-24 20:34:13 -070062 * Returns the application id of this flow.
63 *
64 * @return an applicationId
65 */
alshabib92c65ad2014-10-08 21:56:05 -070066 short appId();
alshabiba68eb962014-09-24 20:34:13 -070067
68 /**
alshabib28204e52014-11-12 18:29:45 -080069 * Returns the group id of this flow.
70 *
71 * @return an groupId
72 */
Sho SHIMIZU75a5bd92014-11-25 11:22:56 -080073 GroupId groupId();
alshabib28204e52014-11-12 18:29:45 -080074
75 /**
tom8bb16062014-09-12 14:47:46 -070076 * Returns the flow rule priority given in natural order; higher numbers
77 * mean higher priorities.
78 *
79 * @return flow rule priority
80 */
81 int priority();
82
83 /**
84 * Returns the identity of the device where this rule applies.
85 *
86 * @return device identifier
87 */
88 DeviceId deviceId();
89
90 /**
jcc3d4e14a2015-04-21 11:32:05 +080091 * Returns the traffic selector that identifies what traffic this rule
92 * should apply to.
tom8bb16062014-09-12 14:47:46 -070093 *
94 * @return traffic selector
95 */
96 TrafficSelector selector();
97
98 /**
99 * Returns the traffic treatment that applies to selected traffic.
100 *
101 * @return traffic treatment
102 */
alshabib369d2942014-09-12 17:59:35 -0700103 TrafficTreatment treatment();
tom8bb16062014-09-12 14:47:46 -0700104
Ayaka Koshibed4e53e12014-09-18 14:24:55 -0700105 /**
alshabibba5ac482014-10-02 17:15:20 -0700106 * Returns the timeout for this flow requested by an application.
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700107 *
alshabibba5ac482014-10-02 17:15:20 -0700108 * @return integer value of the timeout
alshabib6eb438a2014-10-01 16:39:37 -0700109 */
alshabibba5ac482014-10-02 17:15:20 -0700110 int timeout();
alshabib6eb438a2014-10-01 16:39:37 -0700111
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700112 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700113 * Returns the hard timeout for this flow requested by an application.
114 * This paremeter configure switch's flow hard timeout.
115 * In case of controller-switch connection lost, this variable can be useful.
116 * @return integer value of the hard Timeout
117 */
118 int hardTimeout();
119
120 /**
121 * Returns the reason for the flow received from switches.
122 *
123 * @return FlowRemoveReason value of reason
124 */
125 FlowRemoveReason reason();
126
127 /**
Jonathan Hartbc4a7932014-10-21 11:46:00 -0700128 * Returns whether the flow is permanent i.e. does not time out.
129 *
130 * @return true if the flow is permanent, otherwise false
131 */
132 boolean isPermanent();
133
sangho11c30ac2015-01-22 14:30:55 -0800134 /**
alshabibdb774072015-04-20 13:13:51 -0700135 * Returns the table id for this rule.
136 *
137 * @return an integer.
138 */
139 int tableId();
140
141 /**
Jonathan Hartf44e42c2015-08-04 09:58:46 -0700142 * {@inheritDoc}
143 *
144 * Equality for flow rules only considers 'match equality'. This means that
145 * two flow rules with the same match conditions will be equal, regardless
146 * of the treatment or other characteristics of the flow.
147 *
148 * @param obj the reference object with which to compare.
149 * @return {@code true} if this object is the same as the obj
150 * argument; {@code false} otherwise.
151 */
152 boolean equals(Object obj);
153
154 /**
155 * Returns whether this flow rule is an exact match to the flow rule given
156 * in the argument.
157 * <p>
158 * Exact match means that deviceId, priority, selector,
159 * tableId, flowId and treatment are equal. Note that this differs from
160 * the notion of object equality for flow rules, which does not consider the
161 * flowId or treatment when testing equality.
162 * </p>
163 *
164 * @param rule other rule to match against
165 * @return true if the rules are an exact match, otherwise false
166 */
167 boolean exactMatch(FlowRule rule);
168
169 /**
alshabibdb774072015-04-20 13:13:51 -0700170 * A flowrule builder.
171 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700172 interface Builder {
alshabibdb774072015-04-20 13:13:51 -0700173
174 /**
175 * Assigns a cookie value to this flowrule. Mutually exclusive with the
176 * fromApp method. This method is intended to take a cookie value from
177 * the dataplane and not from the application.
178 *
179 * @param cookie a long value
180 * @return this
181 */
182 Builder withCookie(long cookie);
183
184 /**
185 * Assigns the application that built this flow rule to this object.
186 * The short value of the appId will be used as a basis for the
187 * cookie value computation. It is expected that application use this
188 * call to set their application id.
189 *
190 * @param appId an application id
191 * @return this
192 */
193 Builder fromApp(ApplicationId appId);
194
195 /**
196 * Sets the priority for this flow rule.
197 *
198 * @param priority an integer
199 * @return this
200 */
201 Builder withPriority(int priority);
202
203 /**
204 * Sets the deviceId for this flow rule.
205 *
206 * @param deviceId a device id
207 * @return this
208 */
209 Builder forDevice(DeviceId deviceId);
210
211 /**
212 * Sets the table id for this flow rule. Default value is 0.
213 *
214 * @param tableId an integer
215 * @return this
216 */
217 Builder forTable(int tableId);
218
219 /**
220 * Sets the selector (or match field) for this flow rule.
221 *
222 * @param selector a traffic selector
223 * @return this
224 */
225 Builder withSelector(TrafficSelector selector);
226
227 /**
228 * Sets the traffic treatment for this flow rule.
229 *
230 * @param treatment a traffic treatment
231 * @return this
232 */
233 Builder withTreatment(TrafficTreatment treatment);
234
235 /**
236 * Makes this rule permanent on the dataplane.
237 *
238 * @return this
239 */
240 Builder makePermanent();
241
242 /**
243 * Makes this rule temporary and timeout after the specified amount
244 * of time.
245 *
246 * @param timeout an integer
247 * @return this
248 */
249 Builder makeTemporary(int timeout);
250
251 /**
Murat Parlakisikc6759e82016-06-29 03:22:22 -0700252 * Sets hard timeout parameter in flow table.
253 * @param timeout an integer
254 * @return this
255 */
256 Builder withHardTimeout(int timeout);
257
258 /**
259 * Sets reason parameter received from switches .
260 * @param reason a short
261 * @return this
262 */
263 Builder withReason(FlowRemoveReason reason);
264
265 /**
alshabibdb774072015-04-20 13:13:51 -0700266 * Builds a flow rule object.
267 *
268 * @return a flow rule.
269 */
270 FlowRule build();
271
272 }
273
jcc3d4e14a2015-04-21 11:32:05 +0800274 /**
275 * Returns the third party original flow rule.
276 *
277 * @return FlowRuleExtPayLoad
278 */
279 FlowRuleExtPayLoad payLoad();
tom8bb16062014-09-12 14:47:46 -0700280}