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