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