blob: 103691c2167bcc745ea479d81b7dbb2b604e2f21 [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;
alshabib77b88482015-04-07 15:47:50 -070027import org.onosproject.net.DeviceId;
28
alshabib77b88482015-04-07 15:47:50 -070029/**
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070030 * Service for programming data plane flow rules in manner independent of
31 * specific device table pipeline configuration.
alshabib77b88482015-04-07 15:47:50 -070032 */
Thomas Vachuskaa9d491e2015-05-20 11:17:21 -070033@Beta
alshabib77b88482015-04-07 15:47:50 -070034public interface FlowObjectiveService {
35
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070036 /**
37 * Installs the filtering rules onto the specified device.
38 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080039 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070040 * @param filteringObjective the filtering objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070041 */
alshabib2a441c62015-04-13 18:39:38 -070042 void filter(DeviceId deviceId, FilteringObjective filteringObjective);
alshabib77b88482015-04-07 15:47:50 -070043
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070044 /**
45 * Installs the forwarding rules onto the specified device.
46 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080047 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070048 * @param forwardingObjective the forwarding objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070049 */
alshabib2a441c62015-04-13 18:39:38 -070050 void forward(DeviceId deviceId, ForwardingObjective forwardingObjective);
alshabib77b88482015-04-07 15:47:50 -070051
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070052 /**
53 * Installs the next hop elements into the specified device.
54 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080055 * @param deviceId device identifier
alshabib2a441c62015-04-13 18:39:38 -070056 * @param nextObjective a next objective
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070057 */
alshabib2a441c62015-04-13 18:39:38 -070058 void next(DeviceId deviceId, NextObjective nextObjective);
alshabib77b88482015-04-07 15:47:50 -070059
alshabibf6ea9e62015-04-21 17:08:26 -070060 /**
61 * Obtains a globally unique next objective.
Sho SHIMIZU23aa2e72015-07-01 09:48:40 -070062 *
alshabibf6ea9e62015-04-21 17:08:26 -070063 * @return an integer
64 */
65 int allocateNextId();
66
Xin Jin313708b2015-07-09 13:43:04 -070067 /**
Brian O'Connor3ac85262016-02-29 20:26:23 -080068 * Provides a composition policy expression.
69 * <p>
70 * WARNING: This method is a no-op in the default implementation.
Xin Jin313708b2015-07-09 13:43:04 -070071 *
Thomas Vachuska00f48162016-02-29 17:07:23 -080072 * @param policy policy expression
Xin Jin313708b2015-07-09 13:43:04 -070073 */
74 void initPolicy(String policy);
Thomas Vachuska00f48162016-02-29 17:07:23 -080075
76 /**
77 * Installs the objective onto the specified device.
78 *
79 * @param deviceId device identifier
80 * @param objective the objective
81 */
82 default void apply(DeviceId deviceId, Objective objective) {
83 if (ForwardingObjective.class.isAssignableFrom(objective.getClass())) {
84 forward(deviceId, (ForwardingObjective) objective);
85 } else if (FilteringObjective.class.isAssignableFrom(objective.getClass())) {
86 filter(deviceId, (FilteringObjective) objective);
87 } else if (NextObjective.class.isAssignableFrom(objective.getClass())) {
88 next(deviceId, (NextObjective) objective);
89 } else {
90 throw new UnsupportedOperationException("Unsupported objective of type " + objective.getClass());
91 }
92 }
Saurav Das24431192016-03-07 19:13:00 -080093
94 /**
95 * Retrieve all nextObjective to group mappings known to this onos instance,
96 * in a format meant for display on the CLI, to help with debugging. Applications
97 * are only aware of next-Ids, while the group sub-system is only aware of group-ids.
98 * This method fills in the gap by providing information on the mapping
99 * between next-ids and group-ids done by device-drivers.
100 *
101 * @return a list of strings preformatted by the device-drivers to provide
102 * information on next-id to group-id mapping. Consumed by the
Saurav Dasb5c236e2016-06-07 10:08:06 -0700103 * "obj-next-ids" command on the CLI.
Saurav Das24431192016-03-07 19:13:00 -0800104 */
105 List<String> getNextMappings();
Saurav Dasb5c236e2016-06-07 10:08:06 -0700106
107 /**
108 * Retrieve all nextObjectives that are waiting to hear back from device
Saurav Das1547b3f2017-05-05 17:01:08 -0700109 * drivers, and the forwarding-objectives or next-objectives that are waiting
110 * on the successful completion of the original next-objectives. Consumed by the
Saurav Dasb5c236e2016-06-07 10:08:06 -0700111 * "obj-pending-nexts" command on the CLI.
112 *
113 * @return a list of strings preformatted to provide information on the
114 * next-ids awaiting confirmation from the device-drivers.
115 */
Saurav Das1547b3f2017-05-05 17:01:08 -0700116 List<String> getPendingFlowObjectives();
117
118 /**
Charles Chan33f4a912018-04-19 23:35:30 -0700119 * Returns all filtering objective that are waiting for the completion of previous objective
120 * with the same FilteringObjQueueKey.
Saurav Das1547b3f2017-05-05 17:01:08 -0700121 *
Charles Chan33f4a912018-04-19 23:35:30 -0700122 * @return Filtering objective queue as map
Saurav Das1547b3f2017-05-05 17:01:08 -0700123 */
Charles Chan33f4a912018-04-19 23:35:30 -0700124 default ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() {
125 return ArrayListMultimap.create();
126 }
Saurav Das1547b3f2017-05-05 17:01:08 -0700127
Charles Chan33f4a912018-04-19 23:35:30 -0700128 /**
129 * Returns all forwarding objective that are waiting for the completion of previous objective
130 * with the same ForwardingObjQueueKey.
131 *
132 * @return Forwarding objective queue as map
133 */
134 default ListMultimap<ForwardingObjQueueKey, Objective> getForwardingObjQueue() {
135 return ArrayListMultimap.create();
136 }
137
138 /**
139 * Returns all next objective that are waiting for the completion of previous objective
140 * with the same NextObjQueueKey.
141 *
142 * @return Next objective queue as map
143 */
144 default ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
145 return ArrayListMultimap.create();
146 }
147
148 default Map<FilteringObjQueueKey, Objective> getFilteringObjQueueHead() {
149 return Maps.newHashMap();
150 }
151
152 default Map<ForwardingObjQueueKey, Objective> getForwardingObjQueueHead() {
153 return Maps.newHashMap();
154 }
155
156 default Map<NextObjQueueKey, Objective> getNextObjQueueHead() {
157 return Maps.newHashMap();
158 }
159
160 default void clearQueue() {
161 throw new NotImplementedException("clearQueue is not implemented");
162 }
alshabib77b88482015-04-07 15:47:50 -0700163}