Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 2 | * Copyright 2014 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 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 28 | static final int MAX_TIMEOUT = 60; |
alshabib | a0e0498 | 2014-10-03 13:03:19 -0700 | [diff] [blame] | 29 | static final int MIN_PRIORITY = 0; |
alshabib | a7f7ca8 | 2014-09-22 11:41:23 -0700 | [diff] [blame] | 30 | |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 31 | /** |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 32 | * The FlowRule type is used to determine in which table the flow rule needs |
| 33 | * to be put for multi-table support switch. For single table switch, |
| 34 | * Default is used. |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 35 | */ |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 36 | @Deprecated |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 37 | static enum Type { |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 38 | /* |
| 39 | * Default type - used in flow rule for single table switch NOTE: this |
| 40 | * setting should not be used as Table 0 in a multi-table pipeline |
| 41 | */ |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 42 | DEFAULT, |
| 43 | /* Used in flow entry for IP table */ |
| 44 | IP, |
| 45 | /* Used in flow entry for MPLS table */ |
| 46 | MPLS, |
| 47 | /* Used in flow entry for ACL table */ |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 48 | ACL, |
| 49 | |
| 50 | /* VLAN-to-MPLS table */ |
| 51 | VLAN_MPLS, |
| 52 | |
| 53 | /* VLAN table */ |
| 54 | VLAN, |
| 55 | |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 56 | /* Ethtype table */ |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 57 | ETHER, |
| 58 | |
| 59 | /* Class of Service table */ |
| 60 | COS, |
Saurav Das | cbe6de3 | 2015-03-01 18:30:46 -0800 | [diff] [blame] | 61 | |
| 62 | /* Table 0 in a multi-table pipeline */ |
| 63 | FIRST, |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Returns the ID of this flow. |
| 68 | * |
| 69 | * @return the flow ID |
| 70 | */ |
| 71 | FlowId id(); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 72 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 73 | /** |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 74 | * Returns the application id of this flow. |
| 75 | * |
| 76 | * @return an applicationId |
| 77 | */ |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 78 | short appId(); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 81 | * Returns the group id of this flow. |
| 82 | * |
| 83 | * @return an groupId |
| 84 | */ |
Sho SHIMIZU | 75a5bd9 | 2014-11-25 11:22:56 -0800 | [diff] [blame] | 85 | GroupId groupId(); |
alshabib | 28204e5 | 2014-11-12 18:29:45 -0800 | [diff] [blame] | 86 | |
| 87 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 88 | * Returns the flow rule priority given in natural order; higher numbers |
| 89 | * mean higher priorities. |
| 90 | * |
| 91 | * @return flow rule priority |
| 92 | */ |
| 93 | int priority(); |
| 94 | |
| 95 | /** |
| 96 | * Returns the identity of the device where this rule applies. |
| 97 | * |
| 98 | * @return device identifier |
| 99 | */ |
| 100 | DeviceId deviceId(); |
| 101 | |
| 102 | /** |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 103 | * Returns the traffic selector that identifies what traffic this rule |
| 104 | * should apply to. |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 105 | * |
| 106 | * @return traffic selector |
| 107 | */ |
| 108 | TrafficSelector selector(); |
| 109 | |
| 110 | /** |
| 111 | * Returns the traffic treatment that applies to selected traffic. |
| 112 | * |
| 113 | * @return traffic treatment |
| 114 | */ |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 115 | TrafficTreatment treatment(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 116 | |
Ayaka Koshibe | d4e53e1 | 2014-09-18 14:24:55 -0700 | [diff] [blame] | 117 | /** |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 118 | * Returns the timeout for this flow requested by an application. |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 119 | * |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 120 | * @return integer value of the timeout |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 121 | */ |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 122 | int timeout(); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 123 | |
Jonathan Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 124 | /** |
| 125 | * Returns whether the flow is permanent i.e. does not time out. |
| 126 | * |
| 127 | * @return true if the flow is permanent, otherwise false |
| 128 | */ |
| 129 | boolean isPermanent(); |
| 130 | |
sangho | 11c30ac | 2015-01-22 14:30:55 -0800 | [diff] [blame] | 131 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 132 | * Returns the table id for this rule. |
| 133 | * |
| 134 | * @return an integer. |
| 135 | */ |
| 136 | int tableId(); |
| 137 | |
| 138 | /** |
Jonathan Hart | 3d459e1 | 2015-08-04 09:58:46 -0700 | [diff] [blame^] | 139 | * {@inheritDoc} |
| 140 | * |
| 141 | * Equality for flow rules only considers 'match equality'. This means that |
| 142 | * two flow rules with the same match conditions will be equal, regardless |
| 143 | * of the treatment or other characteristics of the flow. |
| 144 | * |
| 145 | * @param obj the reference object with which to compare. |
| 146 | * @return {@code true} if this object is the same as the obj |
| 147 | * argument; {@code false} otherwise. |
| 148 | */ |
| 149 | boolean equals(Object obj); |
| 150 | |
| 151 | /** |
| 152 | * Returns whether this flow rule is an exact match to the flow rule given |
| 153 | * in the argument. |
| 154 | * <p> |
| 155 | * Exact match means that deviceId, priority, selector, |
| 156 | * tableId, flowId and treatment are equal. Note that this differs from |
| 157 | * the notion of object equality for flow rules, which does not consider the |
| 158 | * flowId or treatment when testing equality. |
| 159 | * </p> |
| 160 | * |
| 161 | * @param rule other rule to match against |
| 162 | * @return true if the rules are an exact match, otherwise false |
| 163 | */ |
| 164 | boolean exactMatch(FlowRule rule); |
| 165 | |
| 166 | /** |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 167 | * A flowrule builder. |
| 168 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 169 | interface Builder { |
alshabib | db77407 | 2015-04-20 13:13:51 -0700 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * Assigns a cookie value to this flowrule. Mutually exclusive with the |
| 173 | * fromApp method. This method is intended to take a cookie value from |
| 174 | * the dataplane and not from the application. |
| 175 | * |
| 176 | * @param cookie a long value |
| 177 | * @return this |
| 178 | */ |
| 179 | Builder withCookie(long cookie); |
| 180 | |
| 181 | /** |
| 182 | * Assigns the application that built this flow rule to this object. |
| 183 | * The short value of the appId will be used as a basis for the |
| 184 | * cookie value computation. It is expected that application use this |
| 185 | * call to set their application id. |
| 186 | * |
| 187 | * @param appId an application id |
| 188 | * @return this |
| 189 | */ |
| 190 | Builder fromApp(ApplicationId appId); |
| 191 | |
| 192 | /** |
| 193 | * Sets the priority for this flow rule. |
| 194 | * |
| 195 | * @param priority an integer |
| 196 | * @return this |
| 197 | */ |
| 198 | Builder withPriority(int priority); |
| 199 | |
| 200 | /** |
| 201 | * Sets the deviceId for this flow rule. |
| 202 | * |
| 203 | * @param deviceId a device id |
| 204 | * @return this |
| 205 | */ |
| 206 | Builder forDevice(DeviceId deviceId); |
| 207 | |
| 208 | /** |
| 209 | * Sets the table id for this flow rule. Default value is 0. |
| 210 | * |
| 211 | * @param tableId an integer |
| 212 | * @return this |
| 213 | */ |
| 214 | Builder forTable(int tableId); |
| 215 | |
| 216 | /** |
| 217 | * Sets the selector (or match field) for this flow rule. |
| 218 | * |
| 219 | * @param selector a traffic selector |
| 220 | * @return this |
| 221 | */ |
| 222 | Builder withSelector(TrafficSelector selector); |
| 223 | |
| 224 | /** |
| 225 | * Sets the traffic treatment for this flow rule. |
| 226 | * |
| 227 | * @param treatment a traffic treatment |
| 228 | * @return this |
| 229 | */ |
| 230 | Builder withTreatment(TrafficTreatment treatment); |
| 231 | |
| 232 | /** |
| 233 | * Makes this rule permanent on the dataplane. |
| 234 | * |
| 235 | * @return this |
| 236 | */ |
| 237 | Builder makePermanent(); |
| 238 | |
| 239 | /** |
| 240 | * Makes this rule temporary and timeout after the specified amount |
| 241 | * of time. |
| 242 | * |
| 243 | * @param timeout an integer |
| 244 | * @return this |
| 245 | */ |
| 246 | Builder makeTemporary(int timeout); |
| 247 | |
| 248 | /** |
| 249 | * Builds a flow rule object. |
| 250 | * |
| 251 | * @return a flow rule. |
| 252 | */ |
| 253 | FlowRule build(); |
| 254 | |
| 255 | } |
| 256 | |
jcc | 3d4e14a | 2015-04-21 11:32:05 +0800 | [diff] [blame] | 257 | /** |
| 258 | * Returns the third party original flow rule. |
| 259 | * |
| 260 | * @return FlowRuleExtPayLoad |
| 261 | */ |
| 262 | FlowRuleExtPayLoad payLoad(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 263 | } |