blob: ecec89cafad142d8b7085b2c3873ce79972decda [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 /**
Ayaka Koshibed4e53e12014-09-18 14:24:55 -070033 * Returns the ID of this flow.
34 *
35 * @return the flow ID
36 */
37 FlowId id();
alshabib369d2942014-09-12 17:59:35 -070038
tom8bb16062014-09-12 14:47:46 -070039 /**
alshabiba68eb962014-09-24 20:34:13 -070040 * Returns the application id of this flow.
41 *
42 * @return an applicationId
43 */
alshabib92c65ad2014-10-08 21:56:05 -070044 short appId();
alshabiba68eb962014-09-24 20:34:13 -070045
46 /**
alshabib28204e52014-11-12 18:29:45 -080047 * Returns the group id of this flow.
48 *
49 * @return an groupId
50 */
Sho SHIMIZU75a5bd92014-11-25 11:22:56 -080051 GroupId groupId();
alshabib28204e52014-11-12 18:29:45 -080052
53 /**
tom8bb16062014-09-12 14:47:46 -070054 * Returns the flow rule priority given in natural order; higher numbers
55 * mean higher priorities.
56 *
57 * @return flow rule priority
58 */
59 int priority();
60
61 /**
62 * Returns the identity of the device where this rule applies.
63 *
64 * @return device identifier
65 */
66 DeviceId deviceId();
67
68 /**
jcc3d4e14a2015-04-21 11:32:05 +080069 * Returns the traffic selector that identifies what traffic this rule
70 * should apply to.
tom8bb16062014-09-12 14:47:46 -070071 *
72 * @return traffic selector
73 */
74 TrafficSelector selector();
75
76 /**
77 * Returns the traffic treatment that applies to selected traffic.
78 *
79 * @return traffic treatment
80 */
alshabib369d2942014-09-12 17:59:35 -070081 TrafficTreatment treatment();
tom8bb16062014-09-12 14:47:46 -070082
Ayaka Koshibed4e53e12014-09-18 14:24:55 -070083 /**
alshabibba5ac482014-10-02 17:15:20 -070084 * Returns the timeout for this flow requested by an application.
Jonathan Hartbc4a7932014-10-21 11:46:00 -070085 *
alshabibba5ac482014-10-02 17:15:20 -070086 * @return integer value of the timeout
alshabib6eb438a2014-10-01 16:39:37 -070087 */
alshabibba5ac482014-10-02 17:15:20 -070088 int timeout();
alshabib6eb438a2014-10-01 16:39:37 -070089
Jonathan Hartbc4a7932014-10-21 11:46:00 -070090 /**
91 * Returns whether the flow is permanent i.e. does not time out.
92 *
93 * @return true if the flow is permanent, otherwise false
94 */
95 boolean isPermanent();
96
sangho11c30ac2015-01-22 14:30:55 -080097 /**
alshabibdb774072015-04-20 13:13:51 -070098 * Returns the table id for this rule.
99 *
100 * @return an integer.
101 */
102 int tableId();
103
104 /**
Jonathan Hartf44e42c2015-08-04 09:58:46 -0700105 * {@inheritDoc}
106 *
107 * Equality for flow rules only considers 'match equality'. This means that
108 * two flow rules with the same match conditions will be equal, regardless
109 * of the treatment or other characteristics of the flow.
110 *
111 * @param obj the reference object with which to compare.
112 * @return {@code true} if this object is the same as the obj
113 * argument; {@code false} otherwise.
114 */
115 boolean equals(Object obj);
116
117 /**
118 * Returns whether this flow rule is an exact match to the flow rule given
119 * in the argument.
120 * <p>
121 * Exact match means that deviceId, priority, selector,
122 * tableId, flowId and treatment are equal. Note that this differs from
123 * the notion of object equality for flow rules, which does not consider the
124 * flowId or treatment when testing equality.
125 * </p>
126 *
127 * @param rule other rule to match against
128 * @return true if the rules are an exact match, otherwise false
129 */
130 boolean exactMatch(FlowRule rule);
131
132 /**
alshabibdb774072015-04-20 13:13:51 -0700133 * A flowrule builder.
134 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700135 interface Builder {
alshabibdb774072015-04-20 13:13:51 -0700136
137 /**
138 * Assigns a cookie value to this flowrule. Mutually exclusive with the
139 * fromApp method. This method is intended to take a cookie value from
140 * the dataplane and not from the application.
141 *
142 * @param cookie a long value
143 * @return this
144 */
145 Builder withCookie(long cookie);
146
147 /**
148 * Assigns the application that built this flow rule to this object.
149 * The short value of the appId will be used as a basis for the
150 * cookie value computation. It is expected that application use this
151 * call to set their application id.
152 *
153 * @param appId an application id
154 * @return this
155 */
156 Builder fromApp(ApplicationId appId);
157
158 /**
159 * Sets the priority for this flow rule.
160 *
161 * @param priority an integer
162 * @return this
163 */
164 Builder withPriority(int priority);
165
166 /**
167 * Sets the deviceId for this flow rule.
168 *
169 * @param deviceId a device id
170 * @return this
171 */
172 Builder forDevice(DeviceId deviceId);
173
174 /**
175 * Sets the table id for this flow rule. Default value is 0.
176 *
177 * @param tableId an integer
178 * @return this
179 */
180 Builder forTable(int tableId);
181
182 /**
183 * Sets the selector (or match field) for this flow rule.
184 *
185 * @param selector a traffic selector
186 * @return this
187 */
188 Builder withSelector(TrafficSelector selector);
189
190 /**
191 * Sets the traffic treatment for this flow rule.
192 *
193 * @param treatment a traffic treatment
194 * @return this
195 */
196 Builder withTreatment(TrafficTreatment treatment);
197
198 /**
199 * Makes this rule permanent on the dataplane.
200 *
201 * @return this
202 */
203 Builder makePermanent();
204
205 /**
206 * Makes this rule temporary and timeout after the specified amount
207 * of time.
208 *
209 * @param timeout an integer
210 * @return this
211 */
212 Builder makeTemporary(int timeout);
213
214 /**
215 * Builds a flow rule object.
216 *
217 * @return a flow rule.
218 */
219 FlowRule build();
220
221 }
222
jcc3d4e14a2015-04-21 11:32:05 +0800223 /**
224 * Returns the third party original flow rule.
225 *
226 * @return FlowRuleExtPayLoad
227 */
228 FlowRuleExtPayLoad payLoad();
tom8bb16062014-09-12 14:47:46 -0700229}