alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | package org.onosproject.net.flowobjective; |
| 17 | |
Thomas Vachuska | a9d491e | 2015-05-20 11:17:21 -0700 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 19 | import org.onosproject.core.ApplicationId; |
| 20 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 21 | import java.util.Optional; |
| 22 | |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 23 | /** |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 24 | * Base representation of a flow-objective description. |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 25 | */ |
Thomas Vachuska | a9d491e | 2015-05-20 11:17:21 -0700 | [diff] [blame] | 26 | @Beta |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 27 | public interface Objective { |
| 28 | |
Sho SHIMIZU | e2952e4 | 2015-09-11 17:11:21 -0700 | [diff] [blame] | 29 | boolean DEFAULT_PERMANENT = true; |
| 30 | int DEFAULT_TIMEOUT = 0; |
| 31 | int DEFAULT_PRIORITY = 32768; |
Jayasree Ghosh | 3684dc7 | 2016-06-09 18:07:19 +0530 | [diff] [blame] | 32 | int MIN_PRIORITY = 0; |
| 33 | int MAX_PRIORITY = 65535; |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Type of operation. |
| 37 | */ |
| 38 | enum Operation { |
| 39 | /** |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 40 | * Adds the objective. Can be used for any flow objective. For forwarding |
| 41 | * and filtering objectives, existing objectives with identical selector |
| 42 | * and priority fields (but different treatments or next) will be replaced. |
| 43 | * For next objectives, if modification is desired, ADD will not |
| 44 | * do anything - use ADD_TO_EXISTING. |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 45 | */ |
| 46 | ADD, |
| 47 | |
| 48 | /** |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 49 | * Removes the objective. Can be used for any flow objective. |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 50 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 51 | REMOVE, |
| 52 | |
| 53 | /** |
| 54 | * Add to an existing Next Objective. Should not be used for any other |
| 55 | * objective. |
| 56 | */ |
| 57 | ADD_TO_EXISTING, |
| 58 | |
| 59 | /** |
| 60 | * Remove from an existing Next Objective. Should not be used for any |
| 61 | * other objective. |
| 62 | */ |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 63 | REMOVE_FROM_EXISTING, |
| 64 | |
| 65 | /** |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 66 | * Modify an existing Next Objective. Can be used to modify group buckets. |
| 67 | */ |
| 68 | MODIFY, |
| 69 | |
| 70 | /** |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 71 | * Verifies that an existing Next Objective's collection of treatments |
| 72 | * are correctly represented by the underlying implementation of the objective. |
| 73 | * Corrective action is taken if discrepancies are found during verification. |
| 74 | * For example, if the next objective defines 3 sets of treatments, which |
| 75 | * are meant to be implemented as 3 buckets in a group, but verification |
| 76 | * finds less or more buckets, then the appropriate buckets are added or |
| 77 | * removed to match the objective. |
| 78 | * |
| 79 | * Should not be used for any other objective. |
| 80 | */ |
| 81 | VERIFY |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
| 85 | * An identifier for this objective. |
| 86 | * |
| 87 | * @return an integer |
| 88 | */ |
| 89 | int id(); |
| 90 | |
| 91 | /** |
| 92 | * The priority for this objective. |
| 93 | * |
| 94 | * @return an integer |
| 95 | */ |
| 96 | int priority(); |
| 97 | |
| 98 | /** |
| 99 | * The application which applied this objective. |
| 100 | * |
| 101 | * @return an application id |
| 102 | */ |
| 103 | ApplicationId appId(); |
| 104 | |
| 105 | /** |
| 106 | * The timeout for this objective. |
| 107 | * |
| 108 | * @return an integer |
| 109 | */ |
| 110 | int timeout(); |
| 111 | |
| 112 | /** |
| 113 | * Whether this objective is permanent. |
| 114 | * |
| 115 | * @return a boolean |
| 116 | */ |
| 117 | boolean permanent(); |
| 118 | |
| 119 | /** |
| 120 | * The type of operation for this objective. |
| 121 | * |
| 122 | * @return an operation |
| 123 | */ |
| 124 | Operation op(); |
| 125 | |
| 126 | /** |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 127 | * Obtains an optional context. |
| 128 | * |
| 129 | * @return optional; which will be empty if there is no context. |
| 130 | * Otherwise it will return the context. |
| 131 | */ |
| 132 | Optional<ObjectiveContext> context(); |
| 133 | |
| 134 | /** |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 135 | * Returns a new builder set to create a copy of this objective. |
| 136 | * |
| 137 | * @return new builder |
| 138 | */ |
| 139 | Objective.Builder copy(); |
| 140 | |
| 141 | /** |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 142 | * An objective builder. |
| 143 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 144 | interface Builder { |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 145 | /** |
| 146 | * Makes the filtering objective temporary. |
| 147 | * |
| 148 | * @param timeout a timeout |
| 149 | * @return an objective builder |
| 150 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 151 | Builder makeTemporary(int timeout); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * Makes the filtering objective permanent. |
| 155 | * |
| 156 | * @return an objective builder |
| 157 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 158 | Builder makePermanent(); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Specifies the application which applied the filter. |
| 162 | * |
| 163 | * @param appId an application id |
| 164 | * @return an objective builder |
| 165 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 166 | Builder fromApp(ApplicationId appId); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * Sets the priority for this objective. |
| 170 | * |
| 171 | * @param priority an integer |
| 172 | * @return an objective builder |
| 173 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 174 | Builder withPriority(int priority); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 175 | |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 176 | /** |
| 177 | * Builds the objective that will be added. |
| 178 | * |
| 179 | * @return an objective |
| 180 | */ |
| 181 | Objective add(); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 182 | |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Builds the objective that will be removed. |
| 185 | * |
| 186 | * @return an objective. |
| 187 | */ |
| 188 | Objective remove(); |
| 189 | |
| 190 | /** |
| 191 | * Builds the objective that will be added. |
| 192 | * The context will be used to notify the calling application. |
| 193 | * |
| 194 | * @param context an objective context |
| 195 | * @return an objective |
| 196 | */ |
| 197 | Objective add(ObjectiveContext context); |
| 198 | |
| 199 | /** |
| 200 | * Builds the objective that will be removed. |
| 201 | * The context will be used to notify the calling application. |
| 202 | * |
| 203 | * @param context an objective context |
| 204 | * @return an objective |
| 205 | */ |
| 206 | Objective remove(ObjectiveContext context); |
| 207 | } |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 208 | } |