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; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 27 | import org.onosproject.net.DeviceId; |
| 28 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 29 | /** |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 30 | * Service for programming data plane flow rules in manner independent of |
| 31 | * specific device table pipeline configuration. |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 32 | */ |
Thomas Vachuska | a9d491e | 2015-05-20 11:17:21 -0700 | [diff] [blame] | 33 | @Beta |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 34 | public interface FlowObjectiveService { |
| 35 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Installs the filtering rules onto the specified device. |
| 38 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 39 | * @param deviceId device identifier |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 40 | * @param filteringObjective the filtering objective |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 41 | */ |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 42 | void filter(DeviceId deviceId, FilteringObjective filteringObjective); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 43 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Installs the forwarding rules onto the specified device. |
| 46 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 47 | * @param deviceId device identifier |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 48 | * @param forwardingObjective the forwarding objective |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 49 | */ |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 50 | void forward(DeviceId deviceId, ForwardingObjective forwardingObjective); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 51 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Installs the next hop elements into the specified device. |
| 54 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 55 | * @param deviceId device identifier |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 56 | * @param nextObjective a next objective |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 57 | */ |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 58 | void next(DeviceId deviceId, NextObjective nextObjective); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 59 | |
alshabib | f6ea9e6 | 2015-04-21 17:08:26 -0700 | [diff] [blame] | 60 | /** |
| 61 | * Obtains a globally unique next objective. |
Sho SHIMIZU | 23aa2e7 | 2015-07-01 09:48:40 -0700 | [diff] [blame] | 62 | * |
alshabib | f6ea9e6 | 2015-04-21 17:08:26 -0700 | [diff] [blame] | 63 | * @return an integer |
| 64 | */ |
| 65 | int allocateNextId(); |
| 66 | |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 67 | /** |
Brian O'Connor | 3ac8526 | 2016-02-29 20:26:23 -0800 | [diff] [blame] | 68 | * Provides a composition policy expression. |
| 69 | * <p> |
| 70 | * WARNING: This method is a no-op in the default implementation. |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 71 | * |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 72 | * @param policy policy expression |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 73 | */ |
| 74 | void initPolicy(String policy); |
Thomas Vachuska | 00f4816 | 2016-02-29 17:07:23 -0800 | [diff] [blame] | 75 | |
| 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 Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 93 | |
| 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 Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 103 | * "obj-next-ids" command on the CLI. |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 104 | */ |
| 105 | List<String> getNextMappings(); |
Saurav Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Retrieve all nextObjectives that are waiting to hear back from device |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 109 | * 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 Das | b5c236e | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 111 | * "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 Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 116 | List<String> getPendingFlowObjectives(); |
| 117 | |
| 118 | /** |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 119 | * Returns all filtering objective that are waiting for the completion of previous objective |
| 120 | * with the same FilteringObjQueueKey. |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 121 | * |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 122 | * @return Filtering objective queue as map |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 123 | */ |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 124 | default ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() { |
| 125 | return ArrayListMultimap.create(); |
| 126 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 127 | |
Charles Chan | 33f4a91 | 2018-04-19 23:35:30 -0700 | [diff] [blame] | 128 | /** |
| 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 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 163 | } |