blob: 4def9534686abd36926250ac278887a84d5acef2 [file] [log] [blame]
alshabib77b88482015-04-07 15:47:50 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
alshabib77b88482015-04-07 15:47:50 -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;
Saurav Das24431192016-03-07 19:13:00 -080019
20import java.util.List;
Charles Chan33f4a912018-04-19 23:35:30 -070021import java.util.Map;
Saurav Das24431192016-03-07 19:13:00 -080022
Charles Chan33f4a912018-04-19 23:35:30 -070023import com.google.common.collect.ArrayListMultimap;
24import com.google.common.collect.ListMultimap;
25import com.google.common.collect.Maps;
26import org.apache.commons.lang.NotImplementedException;
Harshada Chaundkar5a198b02019-07-03 16:27:45 +000027import org.apache.commons.lang3.tuple.Pair;
Daniele Moro06aac702021-07-19 22:39:22 +020028import org.onosproject.core.ApplicationId;
alshabib77b88482015-04-07 15:47:50 -070029import org.onosproject.net.DeviceId;
30
alshabib77b88482015-04-07 15:47:50 -070031/**
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070032 * Service for programming data plane flow rules in manner independent of
33 * specific device table pipeline configuration.
alshabib77b88482015-04-07 15:47:50 -070034 */
Thomas Vachuskaa9d491e2015-05-20 11:17:21 -070035@Beta
alshabib77b88482015-04-07 15:47:50 -070036public interface FlowObjectiveService {
37
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070038 /**
39 * Installs the filtering rules onto the specified device.
40 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080041 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070042 * @param filteringObjective the filtering objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070043 */
alshabib2a441c62015-04-13 18:39:38 -070044 void filter(DeviceId deviceId, FilteringObjective filteringObjective);
alshabib77b88482015-04-07 15:47:50 -070045
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070046 /**
47 * Installs the forwarding rules onto the specified device.
48 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080049 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070050 * @param forwardingObjective the forwarding objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070051 */
alshabib2a441c62015-04-13 18:39:38 -070052 void forward(DeviceId deviceId, ForwardingObjective forwardingObjective);
alshabib77b88482015-04-07 15:47:50 -070053
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070054 /**
55 * Installs the next hop elements into the specified device.
56 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080057 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070058 * @param nextObjective a next objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070059 */
alshabib2a441c62015-04-13 18:39:38 -070060 void next(DeviceId deviceId, NextObjective nextObjective);
alshabib77b88482015-04-07 15:47:50 -070061
alshabibf6ea9e62015-04-21 17:08:26 -070062 /**
63 * Obtains a globally unique next objective.
Sho SHIMIZU23aa2e72015-07-01 09:48:40 -070064 *
alshabibf6ea9e62015-04-21 17:08:26 -070065 * @return an integer
66 */
67 int allocateNextId();
68
Xin Jin313708b2015-07-09 13:43:04 -070069 /**
Brian O'Connor3ac85262016-02-29 20:26:23 -080070 * Provides a composition policy expression.
71 * <p>
72 * WARNING: This method is a no-op in the default implementation.
Xin Jin313708b2015-07-09 13:43:04 -070073 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080074 * @param policy policy expression
Xin Jin313708b2015-07-09 13:43:04 -070075 */
76 void initPolicy(String policy);
Thomas Vachuska00f48162016-02-29 17:07:23 -080077
78 /**
79 * Installs the objective onto the specified device.
80 *
81 * @param deviceId device identifier
82 * @param objective the objective
83 */
84 default void apply(DeviceId deviceId, Objective objective) {
85 if (ForwardingObjective.class.isAssignableFrom(objective.getClass())) {
86 forward(deviceId, (ForwardingObjective) objective);
87 } else if (FilteringObjective.class.isAssignableFrom(objective.getClass())) {
88 filter(deviceId, (FilteringObjective) objective);
89 } else if (NextObjective.class.isAssignableFrom(objective.getClass())) {
90 next(deviceId, (NextObjective) objective);
91 } else {
92 throw new UnsupportedOperationException("Unsupported objective of type " + objective.getClass());
93 }
94 }
Saurav Das24431192016-03-07 19:13:00 -080095
96 /**
97 * Retrieve all nextObjective to group mappings known to this onos instance,
Harshada Chaundkar5a198b02019-07-03 16:27:45 +000098 * in a format meant for display via REST API, to help with debugging. Applications
99 * are only aware of next-Ids, while the group sub-system is only aware of group-ids.
100 * This method fills in the gap by providing information on the mapping
101 * between next-ids and group-ids done by device-drivers.
102 *
103 * @return a map of key as a pair of next-id and Device id to group-id mapping.
104 * Consumed by the REST API.
105 */
106 Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain();
107
108 /**
109 * Retrieve all nextObjective to group mappings known to this onos instance,
Saurav Das24431192016-03-07 19:13:00 -0800110 * in a format meant for display on the CLI, to help with debugging. Applications
111 * are only aware of next-Ids, while the group sub-system is only aware of group-ids.
112 * This method fills in the gap by providing information on the mapping
113 * between next-ids and group-ids done by device-drivers.
114 *
115 * @return a list of strings preformatted by the device-drivers to provide
116 * information on next-id to group-id mapping. Consumed by the
Saurav Dasb5c236e2016-06-07 10:08:06 -0700117 * "obj-next-ids" command on the CLI.
Saurav Das24431192016-03-07 19:13:00 -0800118 */
119 List<String> getNextMappings();
Saurav Dasb5c236e2016-06-07 10:08:06 -0700120
121 /**
122 * Retrieve all nextObjectives that are waiting to hear back from device
Saurav Das1547b3f2017-05-05 17:01:08 -0700123 * drivers, and the forwarding-objectives or next-objectives that are waiting
124 * on the successful completion of the original next-objectives. Consumed by the
Saurav Dasb5c236e2016-06-07 10:08:06 -0700125 * "obj-pending-nexts" command on the CLI.
126 *
127 * @return a list of strings preformatted to provide information on the
128 * next-ids awaiting confirmation from the device-drivers.
129 */
Saurav Das1547b3f2017-05-05 17:01:08 -0700130 List<String> getPendingFlowObjectives();
131
132 /**
Daniele Moro06aac702021-07-19 22:39:22 +0200133 * Purges all flow objectives on a given device and for a given application.
134 *
135 * @param deviceId device identifier
136 * @param appId application identifier
137 */
138 void purgeAll(DeviceId deviceId, ApplicationId appId);
139
140 /**
Charles Chan33f4a912018-04-19 23:35:30 -0700141 * Returns all filtering objective that are waiting for the completion of previous objective
142 * with the same FilteringObjQueueKey.
Saurav Das1547b3f2017-05-05 17:01:08 -0700143 *
Charles Chan33f4a912018-04-19 23:35:30 -0700144 * @return Filtering objective queue as map
Saurav Das1547b3f2017-05-05 17:01:08 -0700145 */
Charles Chan33f4a912018-04-19 23:35:30 -0700146 default ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() {
147 return ArrayListMultimap.create();
148 }
Saurav Das1547b3f2017-05-05 17:01:08 -0700149
Charles Chan33f4a912018-04-19 23:35:30 -0700150 /**
151 * Returns all forwarding objective that are waiting for the completion of previous objective
152 * with the same ForwardingObjQueueKey.
153 *
154 * @return Forwarding objective queue as map
155 */
156 default ListMultimap<ForwardingObjQueueKey, Objective> getForwardingObjQueue() {
157 return ArrayListMultimap.create();
158 }
159
160 /**
161 * Returns all next objective that are waiting for the completion of previous objective
162 * with the same NextObjQueueKey.
163 *
164 * @return Next objective queue as map
165 */
166 default ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
167 return ArrayListMultimap.create();
168 }
169
170 default Map<FilteringObjQueueKey, Objective> getFilteringObjQueueHead() {
171 return Maps.newHashMap();
172 }
173
174 default Map<ForwardingObjQueueKey, Objective> getForwardingObjQueueHead() {
175 return Maps.newHashMap();
176 }
177
178 default Map<NextObjQueueKey, Objective> getNextObjQueueHead() {
179 return Maps.newHashMap();
180 }
181
182 default void clearQueue() {
183 throw new NotImplementedException("clearQueue is not implemented");
184 }
alshabib77b88482015-04-07 15:47:50 -0700185}