blob: 8dfc1760cb38c6038417d2aa3d1f60d217250907 [file] [log] [blame]
alshabibfaa1e362015-04-02 15:01:54 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
alshabibfaa1e362015-04-02 15:01:54 -07003 *
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 */
16package org.onosproject.net.flowobjective;
17
Thomas Vachuskaa9d491e2015-05-20 11:17:21 -070018import com.google.common.annotations.Beta;
alshabibfaa1e362015-04-02 15:01:54 -070019import org.onosproject.core.ApplicationId;
Andrea Campanellacbd16942021-06-01 16:33:14 +020020import org.onosproject.net.Annotated;
21import org.onosproject.net.Annotations;
alshabibfaa1e362015-04-02 15:01:54 -070022
alshabib2a441c62015-04-13 18:39:38 -070023import java.util.Optional;
24
alshabibfaa1e362015-04-02 15:01:54 -070025/**
Saurav Das8a0732e2015-11-20 15:27:53 -080026 * Base representation of a flow-objective description.
alshabibfaa1e362015-04-02 15:01:54 -070027 */
Thomas Vachuskaa9d491e2015-05-20 11:17:21 -070028@Beta
Andrea Campanellacbd16942021-06-01 16:33:14 +020029public interface Objective extends Annotated {
alshabibfaa1e362015-04-02 15:01:54 -070030
Sho SHIMIZUe2952e42015-09-11 17:11:21 -070031 boolean DEFAULT_PERMANENT = true;
32 int DEFAULT_TIMEOUT = 0;
33 int DEFAULT_PRIORITY = 32768;
Jayasree Ghosh3684dc72016-06-09 18:07:19 +053034 int MIN_PRIORITY = 0;
35 int MAX_PRIORITY = 65535;
alshabibfaa1e362015-04-02 15:01:54 -070036
37 /**
38 * Type of operation.
39 */
40 enum Operation {
41 /**
Saurav Das8a0732e2015-11-20 15:27:53 -080042 * Adds the objective. Can be used for any flow objective. For forwarding
43 * and filtering objectives, existing objectives with identical selector
44 * and priority fields (but different treatments or next) will be replaced.
45 * For next objectives, if modification is desired, ADD will not
46 * do anything - use ADD_TO_EXISTING.
alshabibfaa1e362015-04-02 15:01:54 -070047 */
48 ADD,
49
50 /**
Saurav Das8a0732e2015-11-20 15:27:53 -080051 * Removes the objective. Can be used for any flow objective.
alshabibfaa1e362015-04-02 15:01:54 -070052 */
Saurav Das8a0732e2015-11-20 15:27:53 -080053 REMOVE,
54
55 /**
56 * Add to an existing Next Objective. Should not be used for any other
57 * objective.
58 */
59 ADD_TO_EXISTING,
60
61 /**
62 * Remove from an existing Next Objective. Should not be used for any
63 * other objective.
64 */
Saurav Dasceccf242017-08-03 18:30:35 -070065 REMOVE_FROM_EXISTING,
66
67 /**
Jonghwan Hyunf810a7a2018-02-12 16:43:45 +090068 * Modify an existing Next Objective. Can be used to modify group buckets.
69 */
70 MODIFY,
71
72 /**
Saurav Dasceccf242017-08-03 18:30:35 -070073 * Verifies that an existing Next Objective's collection of treatments
74 * are correctly represented by the underlying implementation of the objective.
75 * Corrective action is taken if discrepancies are found during verification.
76 * For example, if the next objective defines 3 sets of treatments, which
77 * are meant to be implemented as 3 buckets in a group, but verification
78 * finds less or more buckets, then the appropriate buckets are added or
79 * removed to match the objective.
80 *
81 * Should not be used for any other objective.
82 */
83 VERIFY
alshabibfaa1e362015-04-02 15:01:54 -070084 }
85
86 /**
87 * An identifier for this objective.
88 *
89 * @return an integer
90 */
91 int id();
92
93 /**
94 * The priority for this objective.
95 *
96 * @return an integer
97 */
98 int priority();
99
100 /**
101 * The application which applied this objective.
102 *
103 * @return an application id
104 */
105 ApplicationId appId();
106
107 /**
108 * The timeout for this objective.
109 *
110 * @return an integer
111 */
112 int timeout();
113
114 /**
115 * Whether this objective is permanent.
116 *
117 * @return a boolean
118 */
119 boolean permanent();
120
121 /**
122 * The type of operation for this objective.
123 *
124 * @return an operation
125 */
126 Operation op();
127
128 /**
alshabib2a441c62015-04-13 18:39:38 -0700129 * Obtains an optional context.
130 *
131 * @return optional; which will be empty if there is no context.
132 * Otherwise it will return the context.
133 */
134 Optional<ObjectiveContext> context();
135
136 /**
Thomas Vachuska00f48162016-02-29 17:07:23 -0800137 * Returns a new builder set to create a copy of this objective.
138 *
139 * @return new builder
140 */
141 Objective.Builder copy();
142
143 /**
alshabibfaa1e362015-04-02 15:01:54 -0700144 * An objective builder.
145 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700146 interface Builder {
alshabibfaa1e362015-04-02 15:01:54 -0700147 /**
148 * Makes the filtering objective temporary.
149 *
150 * @param timeout a timeout
151 * @return an objective builder
152 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700153 Builder makeTemporary(int timeout);
alshabibfaa1e362015-04-02 15:01:54 -0700154
155 /**
156 * Makes the filtering objective permanent.
157 *
158 * @return an objective builder
159 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700160 Builder makePermanent();
alshabibfaa1e362015-04-02 15:01:54 -0700161
162 /**
163 * Specifies the application which applied the filter.
164 *
165 * @param appId an application id
166 * @return an objective builder
167 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700168 Builder fromApp(ApplicationId appId);
alshabibfaa1e362015-04-02 15:01:54 -0700169
170 /**
171 * Sets the priority for this objective.
172 *
173 * @param priority an integer
174 * @return an objective builder
175 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700176 Builder withPriority(int priority);
Saurav Das8a0732e2015-11-20 15:27:53 -0800177
Thomas Vachuska00f48162016-02-29 17:07:23 -0800178 /**
Andrea Campanellacbd16942021-06-01 16:33:14 +0200179 * Adds annotations to the objective.
180 *
181 * @param annotations the annotations for the objective
182 * @return an objective builder
183 */
184 Builder withAnnotations(Annotations annotations);
185
186 /**
Thomas Vachuska00f48162016-02-29 17:07:23 -0800187 * Builds the objective that will be added.
188 *
189 * @return an objective
190 */
191 Objective add();
alshabibfaa1e362015-04-02 15:01:54 -0700192
Thomas Vachuska00f48162016-02-29 17:07:23 -0800193 /**
194 * Builds the objective that will be removed.
195 *
196 * @return an objective.
197 */
198 Objective remove();
199
200 /**
201 * Builds the objective that will be added.
202 * The context will be used to notify the calling application.
203 *
204 * @param context an objective context
205 * @return an objective
206 */
207 Objective add(ObjectiveContext context);
208
209 /**
210 * Builds the objective that will be removed.
211 * The context will be used to notify the calling application.
212 *
213 * @param context an objective context
214 * @return an objective
215 */
216 Objective remove(ObjectiveContext context);
217 }
alshabibfaa1e362015-04-02 15:01:54 -0700218}