Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
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 | |
Sho SHIMIZU | e2952e4 | 2015-09-11 17:11:21 -0700 | [diff] [blame] | 28 | int MAX_TIMEOUT = 60; |
| 29 | int MIN_PRIORITY = 0; |
Kavitha Alagesan | 14dc513 | 2016-06-13 17:25:18 +0530 | [diff] [blame] | 30 | int MAX_PRIORITY = 65535; |
alshabib | a7f7ca8 | 2014-09-22 11:41:23 -0700 | [diff] [blame] | 31 | |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 32 | /** |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 33 | * 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 Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 55 | * Returns the ID of this flow. |
| 56 | * |
| 57 | * @return the flow ID |
| 58 | */ |
| 59 | FlowId id(); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 60 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 61 | /** |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 62 | * Returns the application id of this flow. |
| 63 | * |
| 64 | * @return an applicationId |
| 65 | */ |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 66 | short appId(); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 69 | * Returns the group id of this flow. |
| 70 | * |
| 71 | * @return an groupId |
| 72 | */ |
Sho SHIMIZU | 75a5bd9 | 2014-11-25 11:22:56 -0800 | [diff] [blame] | 73 | GroupId groupId(); |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 76 | * 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 | /** |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 91 | * Returns the traffic selector that identifies what traffic this rule |
| 92 | * should apply to. |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 93 | * |
| 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 | */ |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 103 | TrafficTreatment treatment(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 104 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 105 | /** |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 106 | * Returns the timeout for this flow requested by an application. |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 107 | * |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 108 | * @return integer value of the timeout |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 109 | */ |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 110 | int timeout(); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 111 | |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 112 | /** |
Murat Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 113 | * 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 Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 128 | * 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 | |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 134 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 135 | * Returns the table id for this rule. |
| 136 | * |
| 137 | * @return an integer. |
| 138 | */ |
| 139 | int tableId(); |
| 140 | |
| 141 | /** |
Jonathan Hart | f44e42c | 2015-08-04 09:58:46 -0700 | [diff] [blame] | 142 | * {@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 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 170 | * A flowrule builder. |
| 171 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 172 | interface Builder { |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 173 | |
| 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 Parlakisik | c6759e8 | 2016-06-29 03:22:22 -0700 | [diff] [blame] | 252 | * 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 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 266 | * Builds a flow rule object. |
| 267 | * |
| 268 | * @return a flow rule. |
| 269 | */ |
| 270 | FlowRule build(); |
| 271 | |
| 272 | } |
| 273 | |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 274 | /** |
| 275 | * Returns the third party original flow rule. |
| 276 | * |
| 277 | * @return FlowRuleExtPayLoad |
| 278 | */ |
| 279 | FlowRuleExtPayLoad payLoad(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 280 | } |