blob: f0e43056d20ac47d98237e1c1081a4d0b69dedce [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;
20
alshabib2a441c62015-04-13 18:39:38 -070021import java.util.Optional;
22
alshabibfaa1e362015-04-02 15:01:54 -070023/**
Saurav Das8a0732e2015-11-20 15:27:53 -080024 * Base representation of a flow-objective description.
alshabibfaa1e362015-04-02 15:01:54 -070025 */
Thomas Vachuskaa9d491e2015-05-20 11:17:21 -070026@Beta
alshabibfaa1e362015-04-02 15:01:54 -070027public interface Objective {
28
Sho SHIMIZUe2952e42015-09-11 17:11:21 -070029 boolean DEFAULT_PERMANENT = true;
30 int DEFAULT_TIMEOUT = 0;
31 int DEFAULT_PRIORITY = 32768;
Jayasree Ghosh3684dc72016-06-09 18:07:19 +053032 int MIN_PRIORITY = 0;
33 int MAX_PRIORITY = 65535;
alshabibfaa1e362015-04-02 15:01:54 -070034
35 /**
36 * Type of operation.
37 */
38 enum Operation {
39 /**
Saurav Das8a0732e2015-11-20 15:27:53 -080040 * 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.
alshabibfaa1e362015-04-02 15:01:54 -070045 */
46 ADD,
47
48 /**
Saurav Das8a0732e2015-11-20 15:27:53 -080049 * Removes the objective. Can be used for any flow objective.
alshabibfaa1e362015-04-02 15:01:54 -070050 */
Saurav Das8a0732e2015-11-20 15:27:53 -080051 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 Dasceccf242017-08-03 18:30:35 -070063 REMOVE_FROM_EXISTING,
64
65 /**
66 * Verifies that an existing Next Objective's collection of treatments
67 * are correctly represented by the underlying implementation of the objective.
68 * Corrective action is taken if discrepancies are found during verification.
69 * For example, if the next objective defines 3 sets of treatments, which
70 * are meant to be implemented as 3 buckets in a group, but verification
71 * finds less or more buckets, then the appropriate buckets are added or
72 * removed to match the objective.
73 *
74 * Should not be used for any other objective.
75 */
76 VERIFY
alshabibfaa1e362015-04-02 15:01:54 -070077 }
78
79 /**
80 * An identifier for this objective.
81 *
82 * @return an integer
83 */
84 int id();
85
86 /**
87 * The priority for this objective.
88 *
89 * @return an integer
90 */
91 int priority();
92
93 /**
94 * The application which applied this objective.
95 *
96 * @return an application id
97 */
98 ApplicationId appId();
99
100 /**
101 * The timeout for this objective.
102 *
103 * @return an integer
104 */
105 int timeout();
106
107 /**
108 * Whether this objective is permanent.
109 *
110 * @return a boolean
111 */
112 boolean permanent();
113
114 /**
115 * The type of operation for this objective.
116 *
117 * @return an operation
118 */
119 Operation op();
120
121 /**
alshabib2a441c62015-04-13 18:39:38 -0700122 * Obtains an optional context.
123 *
124 * @return optional; which will be empty if there is no context.
125 * Otherwise it will return the context.
126 */
127 Optional<ObjectiveContext> context();
128
129 /**
Thomas Vachuska00f48162016-02-29 17:07:23 -0800130 * Returns a new builder set to create a copy of this objective.
131 *
132 * @return new builder
133 */
134 Objective.Builder copy();
135
136 /**
alshabibfaa1e362015-04-02 15:01:54 -0700137 * An objective builder.
138 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700139 interface Builder {
alshabibfaa1e362015-04-02 15:01:54 -0700140 /**
141 * Makes the filtering objective temporary.
142 *
143 * @param timeout a timeout
144 * @return an objective builder
145 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700146 Builder makeTemporary(int timeout);
alshabibfaa1e362015-04-02 15:01:54 -0700147
148 /**
149 * Makes the filtering objective permanent.
150 *
151 * @return an objective builder
152 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700153 Builder makePermanent();
alshabibfaa1e362015-04-02 15:01:54 -0700154
155 /**
156 * Specifies the application which applied the filter.
157 *
158 * @param appId an application id
159 * @return an objective builder
160 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700161 Builder fromApp(ApplicationId appId);
alshabibfaa1e362015-04-02 15:01:54 -0700162
163 /**
164 * Sets the priority for this objective.
165 *
166 * @param priority an integer
167 * @return an objective builder
168 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700169 Builder withPriority(int priority);
Saurav Das8a0732e2015-11-20 15:27:53 -0800170
Thomas Vachuska00f48162016-02-29 17:07:23 -0800171 /**
172 * Builds the objective that will be added.
173 *
174 * @return an objective
175 */
176 Objective add();
alshabibfaa1e362015-04-02 15:01:54 -0700177
Thomas Vachuska00f48162016-02-29 17:07:23 -0800178 /**
179 * Builds the objective that will be removed.
180 *
181 * @return an objective.
182 */
183 Objective remove();
184
185 /**
186 * Builds the objective that will be added.
187 * The context will be used to notify the calling application.
188 *
189 * @param context an objective context
190 * @return an objective
191 */
192 Objective add(ObjectiveContext context);
193
194 /**
195 * Builds the objective that will be removed.
196 * The context will be used to notify the calling application.
197 *
198 * @param context an objective context
199 * @return an objective
200 */
201 Objective remove(ObjectiveContext context);
202 }
alshabibfaa1e362015-04-02 15:01:54 -0700203}