Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 17 | |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.core.GroupId; |
| 20 | import org.onosproject.net.DeviceId; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 21 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 22 | /** |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 23 | * Represents a generalized match & action pair to be applied to an |
| 24 | * infrastructure device. |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 25 | */ |
Sho SHIMIZU | 5e5d4aa | 2015-01-26 16:12:11 -0800 | [diff] [blame] | 26 | public interface FlowRule { |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 27 | |
Carmelo Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 28 | IndexTableId DEFAULT_TABLE = IndexTableId.of(0); |
Sho SHIMIZU | e2952e4 | 2015-09-11 17:11:21 -0700 | [diff] [blame] | 29 | int MAX_TIMEOUT = 60; |
| 30 | int MIN_PRIORITY = 0; |
Kavitha Alagesan | 14dc513 | 2016-06-13 17:25:18 +0530 | [diff] [blame] | 31 | int MAX_PRIORITY = 65535; |
alshabib | a7f7ca8 | 2014-09-22 11:41:23 -0700 | [diff] [blame] | 32 | |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 33 | /** |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 34 | * Reason for flow parameter received from switches. |
| 35 | * Used to check reason parameter in flows. |
| 36 | */ |
| 37 | enum FlowRemoveReason { |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 38 | IDLE_TIMEOUT, |
Jimmy Jin | e9b7a02 | 2016-08-12 16:56:48 -0700 | [diff] [blame] | 39 | 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 Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 51 | 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 Jin | e9b7a02 | 2016-08-12 16:56:48 -0700 | [diff] [blame] | 59 | 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 Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 67 | default : |
| 68 | return NO_REASON; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 74 | * Returns the ID of this flow. |
| 75 | * |
| 76 | * @return the flow ID |
| 77 | */ |
| 78 | FlowId id(); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 79 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 80 | /** |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 81 | * Returns the application id of this flow. |
| 82 | * |
| 83 | * @return an applicationId |
| 84 | */ |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 85 | short appId(); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 88 | * Returns the group id of this flow. |
| 89 | * |
| 90 | * @return an groupId |
| 91 | */ |
Sho SHIMIZU | 75a5bd9 | 2014-11-25 11:22:56 -0800 | [diff] [blame] | 92 | GroupId groupId(); |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 95 | * 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 | /** |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 110 | * Returns the traffic selector that identifies what traffic this rule |
| 111 | * should apply to. |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 112 | * |
| 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 | */ |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 122 | TrafficTreatment treatment(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 123 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 124 | /** |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 125 | * Returns the timeout for this flow requested by an application. |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 126 | * |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 127 | * @return integer value of the timeout |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 128 | */ |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 129 | int timeout(); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 130 | |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 131 | /** |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 132 | * Returns the hard timeout for this flow requested by an application. |
Jonathan Hart | 2b3e22b | 2017-02-03 18:31:13 -0800 | [diff] [blame] | 133 | * This parameter configure switch's flow hard timeout. |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 134 | * 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 Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 147 | * 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 | |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 153 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 154 | * Returns the table id for this rule. |
| 155 | * |
| 156 | * @return an integer. |
Carmelo Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 157 | * @deprecated in Loon release (version 1.11.0). Use {@link #table()} instead. |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 158 | */ |
Carmelo Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 159 | @Deprecated |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 160 | int tableId(); |
| 161 | |
| 162 | /** |
Carmelo Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 163 | * Returns the table identifier for this rule. |
| 164 | * |
| 165 | * @return a table identifier. |
| 166 | */ |
| 167 | TableId table(); |
| 168 | |
| 169 | /** |
Jonathan Hart | f44e42c | 2015-08-04 09:58:46 -0700 | [diff] [blame] | 170 | * {@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 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 198 | * A flowrule builder. |
| 199 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 200 | interface Builder { |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 201 | |
| 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 Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 240 | * 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)}. |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 246 | * |
| 247 | * @param tableId an integer |
| 248 | * @return this |
| 249 | */ |
| 250 | Builder forTable(int tableId); |
| 251 | |
| 252 | /** |
Carmelo Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 253 | * 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 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 262 | * 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 Santos | 943cd54 | 2017-01-13 13:05:09 -0300 | [diff] [blame] | 294 | * 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 Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 309 | * 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 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 323 | * Builds a flow rule object. |
| 324 | * |
| 325 | * @return a flow rule. |
| 326 | */ |
| 327 | FlowRule build(); |
| 328 | |
| 329 | } |
| 330 | |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 331 | /** |
| 332 | * Returns the third party original flow rule. |
| 333 | * |
| 334 | * @return FlowRuleExtPayLoad |
Jonathan Hart | 2b3e22b | 2017-02-03 18:31:13 -0800 | [diff] [blame] | 335 | * @deprecated in Junco release |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 336 | */ |
Jonathan Hart | 2b3e22b | 2017-02-03 18:31:13 -0800 | [diff] [blame] | 337 | @Deprecated |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 338 | FlowRuleExtPayLoad payLoad(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 339 | } |