blob: c6752317393ce9b83bbaba2c183c73c9d52ff612 [file] [log] [blame]
alshabibfaa1e362015-04-02 15:01:54 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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;
alshabibfaa1e362015-04-02 15:01:54 -070032
33 /**
34 * Type of operation.
35 */
36 enum Operation {
37 /**
Saurav Das8a0732e2015-11-20 15:27:53 -080038 * Adds the objective. Can be used for any flow objective. For forwarding
39 * and filtering objectives, existing objectives with identical selector
40 * and priority fields (but different treatments or next) will be replaced.
41 * For next objectives, if modification is desired, ADD will not
42 * do anything - use ADD_TO_EXISTING.
alshabibfaa1e362015-04-02 15:01:54 -070043 */
44 ADD,
45
46 /**
Saurav Das8a0732e2015-11-20 15:27:53 -080047 * Removes the objective. Can be used for any flow objective.
alshabibfaa1e362015-04-02 15:01:54 -070048 */
Saurav Das8a0732e2015-11-20 15:27:53 -080049 REMOVE,
50
51 /**
52 * Add to an existing Next Objective. Should not be used for any other
53 * objective.
54 */
55 ADD_TO_EXISTING,
56
57 /**
58 * Remove from an existing Next Objective. Should not be used for any
59 * other objective.
60 */
61 REMOVE_FROM_EXISTING
alshabibfaa1e362015-04-02 15:01:54 -070062 }
63
64 /**
65 * An identifier for this objective.
66 *
67 * @return an integer
68 */
69 int id();
70
71 /**
72 * The priority for this objective.
73 *
74 * @return an integer
75 */
76 int priority();
77
78 /**
79 * The application which applied this objective.
80 *
81 * @return an application id
82 */
83 ApplicationId appId();
84
85 /**
86 * The timeout for this objective.
87 *
88 * @return an integer
89 */
90 int timeout();
91
92 /**
93 * Whether this objective is permanent.
94 *
95 * @return a boolean
96 */
97 boolean permanent();
98
99 /**
100 * The type of operation for this objective.
101 *
102 * @return an operation
103 */
104 Operation op();
105
106 /**
alshabib2a441c62015-04-13 18:39:38 -0700107 * Obtains an optional context.
108 *
109 * @return optional; which will be empty if there is no context.
110 * Otherwise it will return the context.
111 */
112 Optional<ObjectiveContext> context();
113
114 /**
Thomas Vachuska00f48162016-02-29 17:07:23 -0800115 * Returns a new builder set to create a copy of this objective.
116 *
117 * @return new builder
118 */
119 Objective.Builder copy();
120
121 /**
alshabibfaa1e362015-04-02 15:01:54 -0700122 * An objective builder.
123 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700124 interface Builder {
alshabibfaa1e362015-04-02 15:01:54 -0700125 /**
126 * Makes the filtering objective temporary.
127 *
128 * @param timeout a timeout
129 * @return an objective builder
130 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700131 Builder makeTemporary(int timeout);
alshabibfaa1e362015-04-02 15:01:54 -0700132
133 /**
134 * Makes the filtering objective permanent.
135 *
136 * @return an objective builder
137 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700138 Builder makePermanent();
alshabibfaa1e362015-04-02 15:01:54 -0700139
140 /**
141 * Specifies the application which applied the filter.
142 *
143 * @param appId an application id
144 * @return an objective builder
145 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700146 Builder fromApp(ApplicationId appId);
alshabibfaa1e362015-04-02 15:01:54 -0700147
148 /**
149 * Sets the priority for this objective.
150 *
151 * @param priority an integer
152 * @return an objective builder
153 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700154 Builder withPriority(int priority);
Saurav Das8a0732e2015-11-20 15:27:53 -0800155
Thomas Vachuska00f48162016-02-29 17:07:23 -0800156 /**
157 * Builds the objective that will be added.
158 *
159 * @return an objective
160 */
161 Objective add();
alshabibfaa1e362015-04-02 15:01:54 -0700162
Thomas Vachuska00f48162016-02-29 17:07:23 -0800163 /**
164 * Builds the objective that will be removed.
165 *
166 * @return an objective.
167 */
168 Objective remove();
169
170 /**
171 * Builds the objective that will be added.
172 * The context will be used to notify the calling application.
173 *
174 * @param context an objective context
175 * @return an objective
176 */
177 Objective add(ObjectiveContext context);
178
179 /**
180 * Builds the objective that will be removed.
181 * The context will be used to notify the calling application.
182 *
183 * @param context an objective context
184 * @return an objective
185 */
186 Objective remove(ObjectiveContext context);
187 }
alshabibfaa1e362015-04-02 15:01:54 -0700188}