blob: 11a7f5f41b62264f27dc62b42e718b6a9d536ea3 [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;
alshabib77b88482015-04-07 15:47:50 -070028import org.onosproject.net.DeviceId;
29
alshabib77b88482015-04-07 15:47:50 -070030/**
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070031 * Service for programming data plane flow rules in manner independent of
32 * specific device table pipeline configuration.
alshabib77b88482015-04-07 15:47:50 -070033 */
Thomas Vachuskaa9d491e2015-05-20 11:17:21 -070034@Beta
alshabib77b88482015-04-07 15:47:50 -070035public interface FlowObjectiveService {
36
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070037 /**
38 * Installs the filtering rules onto the specified device.
39 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080040 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070041 * @param filteringObjective the filtering objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070042 */
alshabib2a441c62015-04-13 18:39:38 -070043 void filter(DeviceId deviceId, FilteringObjective filteringObjective);
alshabib77b88482015-04-07 15:47:50 -070044
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070045 /**
46 * Installs the forwarding rules onto the specified device.
47 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080048 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070049 * @param forwardingObjective the forwarding objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070050 */
alshabib2a441c62015-04-13 18:39:38 -070051 void forward(DeviceId deviceId, ForwardingObjective forwardingObjective);
alshabib77b88482015-04-07 15:47:50 -070052
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070053 /**
54 * Installs the next hop elements into the specified device.
55 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080056 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070057 * @param nextObjective a next objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070058 */
alshabib2a441c62015-04-13 18:39:38 -070059 void next(DeviceId deviceId, NextObjective nextObjective);
alshabib77b88482015-04-07 15:47:50 -070060
alshabibf6ea9e62015-04-21 17:08:26 -070061 /**
62 * Obtains a globally unique next objective.
Sho SHIMIZU23aa2e72015-07-01 09:48:40 -070063 *
alshabibf6ea9e62015-04-21 17:08:26 -070064 * @return an integer
65 */
66 int allocateNextId();
67
Xin Jin313708b2015-07-09 13:43:04 -070068 /**
Brian O'Connor3ac85262016-02-29 20:26:23 -080069 * Provides a composition policy expression.
70 * <p>
71 * WARNING: This method is a no-op in the default implementation.
Xin Jin313708b2015-07-09 13:43:04 -070072 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080073 * @param policy policy expression
Xin Jin313708b2015-07-09 13:43:04 -070074 */
75 void initPolicy(String policy);
Thomas Vachuska00f48162016-02-29 17:07:23 -080076
77 /**
78 * Installs the objective onto the specified device.
79 *
80 * @param deviceId device identifier
81 * @param objective the objective
82 */
83 default void apply(DeviceId deviceId, Objective objective) {
84 if (ForwardingObjective.class.isAssignableFrom(objective.getClass())) {
85 forward(deviceId, (ForwardingObjective) objective);
86 } else if (FilteringObjective.class.isAssignableFrom(objective.getClass())) {
87 filter(deviceId, (FilteringObjective) objective);
88 } else if (NextObjective.class.isAssignableFrom(objective.getClass())) {
89 next(deviceId, (NextObjective) objective);
90 } else {
91 throw new UnsupportedOperationException("Unsupported objective of type " + objective.getClass());
92 }
93 }
Saurav Das24431192016-03-07 19:13:00 -080094
95 /**
96 * Retrieve all nextObjective to group mappings known to this onos instance,
Harshada Chaundkar5a198b02019-07-03 16:27:45 +000097 * in a format meant for display via REST API, to help with debugging. Applications
98 * are only aware of next-Ids, while the group sub-system is only aware of group-ids.
99 * This method fills in the gap by providing information on the mapping
100 * between next-ids and group-ids done by device-drivers.
101 *
102 * @return a map of key as a pair of next-id and Device id to group-id mapping.
103 * Consumed by the REST API.
104 */
105 Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain();
106
107 /**
108 * Retrieve all nextObjective to group mappings known to this onos instance,
Saurav Das24431192016-03-07 19:13:00 -0800109 * in a format meant for display on the CLI, to help with debugging. Applications
110 * are only aware of next-Ids, while the group sub-system is only aware of group-ids.
111 * This method fills in the gap by providing information on the mapping
112 * between next-ids and group-ids done by device-drivers.
113 *
114 * @return a list of strings preformatted by the device-drivers to provide
115 * information on next-id to group-id mapping. Consumed by the
Saurav Dasb5c236e2016-06-07 10:08:06 -0700116 * "obj-next-ids" command on the CLI.
Saurav Das24431192016-03-07 19:13:00 -0800117 */
118 List<String> getNextMappings();
Saurav Dasb5c236e2016-06-07 10:08:06 -0700119
120 /**
121 * Retrieve all nextObjectives that are waiting to hear back from device
Saurav Das1547b3f2017-05-05 17:01:08 -0700122 * drivers, and the forwarding-objectives or next-objectives that are waiting
123 * on the successful completion of the original next-objectives. Consumed by the
Saurav Dasb5c236e2016-06-07 10:08:06 -0700124 * "obj-pending-nexts" command on the CLI.
125 *
126 * @return a list of strings preformatted to provide information on the
127 * next-ids awaiting confirmation from the device-drivers.
128 */
Saurav Das1547b3f2017-05-05 17:01:08 -0700129 List<String> getPendingFlowObjectives();
130
131 /**
Charles Chan33f4a912018-04-19 23:35:30 -0700132 * Returns all filtering objective that are waiting for the completion of previous objective
133 * with the same FilteringObjQueueKey.
Saurav Das1547b3f2017-05-05 17:01:08 -0700134 *
Charles Chan33f4a912018-04-19 23:35:30 -0700135 * @return Filtering objective queue as map
Saurav Das1547b3f2017-05-05 17:01:08 -0700136 */
Charles Chan33f4a912018-04-19 23:35:30 -0700137 default ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() {
138 return ArrayListMultimap.create();
139 }
Saurav Das1547b3f2017-05-05 17:01:08 -0700140
Charles Chan33f4a912018-04-19 23:35:30 -0700141 /**
142 * Returns all forwarding objective that are waiting for the completion of previous objective
143 * with the same ForwardingObjQueueKey.
144 *
145 * @return Forwarding objective queue as map
146 */
147 default ListMultimap<ForwardingObjQueueKey, Objective> getForwardingObjQueue() {
148 return ArrayListMultimap.create();
149 }
150
151 /**
152 * Returns all next objective that are waiting for the completion of previous objective
153 * with the same NextObjQueueKey.
154 *
155 * @return Next objective queue as map
156 */
157 default ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
158 return ArrayListMultimap.create();
159 }
160
161 default Map<FilteringObjQueueKey, Objective> getFilteringObjQueueHead() {
162 return Maps.newHashMap();
163 }
164
165 default Map<ForwardingObjQueueKey, Objective> getForwardingObjQueueHead() {
166 return Maps.newHashMap();
167 }
168
169 default Map<NextObjQueueKey, Objective> getNextObjQueueHead() {
170 return Maps.newHashMap();
171 }
172
173 default void clearQueue() {
174 throw new NotImplementedException("clearQueue is not implemented");
175 }
alshabib77b88482015-04-07 15:47:50 -0700176}