alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.net.flowobjective; |
| 17 | |
Thomas Vachuska | a9d491e | 2015-05-20 11:17:21 -0700 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 19 | |
| 20 | import java.util.List; |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 21 | import java.util.Map; |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 22 | |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 23 | import com.google.common.collect.ArrayListMultimap; |
| 24 | import com.google.common.collect.ListMultimap; |
| 25 | import com.google.common.collect.Maps; |
| 26 | import org.apache.commons.lang.NotImplementedException; |
Harshada Chaundkar | 5a198b0 | 2019-07-03 16:27:45 +0000 | [diff] [blame] | 27 | import org.apache.commons.lang3.tuple.Pair; |
Daniele Moro | 06aac70 | 2021-07-19 22:39:22 +0200 | [diff] [blame] | 28 | import org.onosproject.core.ApplicationId; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
| 30 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 31 | /** |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 32 | * Service for programming data plane flow rules in manner independent of |
| 33 | * specific device table pipeline configuration. |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 34 | */ |
Thomas Vachuska | a9d491e | 2015-05-20 11:17:21 -0700 | [diff] [blame] | 35 | @Beta |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 36 | public interface FlowObjectiveService { |
| 37 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Installs the filtering rules onto the specified device. |
| 40 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 41 | * @param deviceId device identifier |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 42 | * @param filteringObjective the filtering objective |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 43 | */ |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 44 | void filter(DeviceId deviceId, FilteringObjective filteringObjective); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 45 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Installs the forwarding rules onto the specified device. |
| 48 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 49 | * @param deviceId device identifier |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 50 | * @param forwardingObjective the forwarding objective |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 51 | */ |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 52 | void forward(DeviceId deviceId, ForwardingObjective forwardingObjective); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 53 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Installs the next hop elements into the specified device. |
| 56 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 57 | * @param deviceId device identifier |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 58 | * @param nextObjective a next objective |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 59 | */ |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 60 | void next(DeviceId deviceId, NextObjective nextObjective); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 61 | |
alshabib | f6ea9e6 | 2015-04-21 17:08:26 -0700 | [diff] [blame] | 62 | /** |
| 63 | * Obtains a globally unique next objective. |
Sho SHIMIZU | 23aa2e7 | 2015-07-01 09:48:40 -0700 | [diff] [blame] | 64 | * |
alshabib | f6ea9e6 | 2015-04-21 17:08:26 -0700 | [diff] [blame] | 65 | * @return an integer |
| 66 | */ |
| 67 | int allocateNextId(); |
| 68 | |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 69 | /** |
Brian O'Connor | 3ac8526 | 2016-02-29 20:26:23 -0800 | [diff] [blame] | 70 | * Provides a composition policy expression. |
| 71 | * <p> |
| 72 | * WARNING: This method is a no-op in the default implementation. |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 73 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 74 | * @param policy policy expression |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 75 | */ |
| 76 | void initPolicy(String policy); |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 77 | |
| 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 Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Retrieve all nextObjective to group mappings known to this onos instance, |
Harshada Chaundkar | 5a198b0 | 2019-07-03 16:27:45 +0000 | [diff] [blame] | 98 | * 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 Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 110 | * 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 Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 117 | * "obj-next-ids" command on the CLI. |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 118 | */ |
| 119 | List<String> getNextMappings(); |
Saurav Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Retrieve all nextObjectives that are waiting to hear back from device |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 123 | * 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 Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 125 | * "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 Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 130 | List<String> getPendingFlowObjectives(); |
| 131 | |
| 132 | /** |
Daniele Moro | 06aac70 | 2021-07-19 22:39:22 +0200 | [diff] [blame] | 133 | * 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 Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 141 | * Returns all filtering objective that are waiting for the completion of previous objective |
| 142 | * with the same FilteringObjQueueKey. |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 143 | * |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 144 | * @return Filtering objective queue as map |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 145 | */ |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 146 | default ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() { |
| 147 | return ArrayListMultimap.create(); |
| 148 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 149 | |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 150 | /** |
| 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 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 185 | } |