alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 | */ |
| 63 | REMOVE_FROM_EXISTING |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
| 67 | * An identifier for this objective. |
| 68 | * |
| 69 | * @return an integer |
| 70 | */ |
| 71 | int id(); |
| 72 | |
| 73 | /** |
| 74 | * The priority for this objective. |
| 75 | * |
| 76 | * @return an integer |
| 77 | */ |
| 78 | int priority(); |
| 79 | |
| 80 | /** |
| 81 | * The application which applied this objective. |
| 82 | * |
| 83 | * @return an application id |
| 84 | */ |
| 85 | ApplicationId appId(); |
| 86 | |
| 87 | /** |
| 88 | * The timeout for this objective. |
| 89 | * |
| 90 | * @return an integer |
| 91 | */ |
| 92 | int timeout(); |
| 93 | |
| 94 | /** |
| 95 | * Whether this objective is permanent. |
| 96 | * |
| 97 | * @return a boolean |
| 98 | */ |
| 99 | boolean permanent(); |
| 100 | |
| 101 | /** |
| 102 | * The type of operation for this objective. |
| 103 | * |
| 104 | * @return an operation |
| 105 | */ |
| 106 | Operation op(); |
| 107 | |
| 108 | /** |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 109 | * Obtains an optional context. |
| 110 | * |
| 111 | * @return optional; which will be empty if there is no context. |
| 112 | * Otherwise it will return the context. |
| 113 | */ |
| 114 | Optional<ObjectiveContext> context(); |
| 115 | |
| 116 | /** |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 117 | * Returns a new builder set to create a copy of this objective. |
| 118 | * |
| 119 | * @return new builder |
| 120 | */ |
| 121 | Objective.Builder copy(); |
| 122 | |
| 123 | /** |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 124 | * An objective builder. |
| 125 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 126 | interface Builder { |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Makes the filtering objective temporary. |
| 129 | * |
| 130 | * @param timeout a timeout |
| 131 | * @return an objective builder |
| 132 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 133 | Builder makeTemporary(int timeout); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Makes the filtering objective permanent. |
| 137 | * |
| 138 | * @return an objective builder |
| 139 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 140 | Builder makePermanent(); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * Specifies the application which applied the filter. |
| 144 | * |
| 145 | * @param appId an application id |
| 146 | * @return an objective builder |
| 147 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 148 | Builder fromApp(ApplicationId appId); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * Sets the priority for this objective. |
| 152 | * |
| 153 | * @param priority an integer |
| 154 | * @return an objective builder |
| 155 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 156 | Builder withPriority(int priority); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 157 | |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 158 | /** |
| 159 | * Builds the objective that will be added. |
| 160 | * |
| 161 | * @return an objective |
| 162 | */ |
| 163 | Objective add(); |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 164 | |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 165 | /** |
| 166 | * Builds the objective that will be removed. |
| 167 | * |
| 168 | * @return an objective. |
| 169 | */ |
| 170 | Objective remove(); |
| 171 | |
| 172 | /** |
| 173 | * Builds the objective that will be added. |
| 174 | * The context will be used to notify the calling application. |
| 175 | * |
| 176 | * @param context an objective context |
| 177 | * @return an objective |
| 178 | */ |
| 179 | Objective add(ObjectiveContext context); |
| 180 | |
| 181 | /** |
| 182 | * Builds the objective that will be removed. |
| 183 | * The context will be used to notify the calling application. |
| 184 | * |
| 185 | * @param context an objective context |
| 186 | * @return an objective |
| 187 | */ |
| 188 | Objective remove(ObjectiveContext context); |
| 189 | } |
alshabib | faa1e36 | 2015-04-02 15:01:54 -0700 | [diff] [blame] | 190 | } |