Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 17 | |
Daniele Moro | cfd7740 | 2021-07-15 17:02:59 +0200 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.DeviceId; |
Ray Milkey | 7bf273c | 2017-09-27 16:15:15 -0700 | [diff] [blame] | 20 | import org.onosproject.net.flow.oldbatch.FlowRuleBatchEvent; |
| 21 | import org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.store.Store; |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 23 | |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 24 | import java.util.List; |
| 25 | |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 26 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 27 | * Manages inventory of flow rules; not intended for direct use. |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 28 | */ |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 29 | public interface FlowRuleStore extends Store<FlowRuleBatchEvent, FlowRuleStoreDelegate> { |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 32 | * Returns the number of flow rules in the store. |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 33 | * |
| 34 | * @return number of flow rules |
| 35 | */ |
| 36 | int getFlowRuleCount(); |
| 37 | |
| 38 | /** |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 39 | * Returns the number of flow rules for the given device in the store. |
| 40 | * |
| 41 | * @param deviceId device identifier |
| 42 | * @return number of flow rules for the given device |
| 43 | */ |
| 44 | default int getFlowRuleCount(DeviceId deviceId) { |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | /** |
Jordan Halterman | b81fdc1 | 2019-03-04 18:12:20 -0800 | [diff] [blame] | 49 | * Returns the number of flow rules in the given state for the given device. |
| 50 | * |
| 51 | * @param deviceId the device identifier |
| 52 | * @param state the state for which to count flow rules |
| 53 | * @return number of flow rules in the given state for the given device |
| 54 | */ |
| 55 | default int getFlowRuleCount(DeviceId deviceId, FlowEntry.FlowEntryState state) { |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | /** |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 60 | * Returns the stored flow. |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 61 | * |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 62 | * @param rule the rule to look for |
| 63 | * @return a flow rule |
| 64 | */ |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 65 | FlowEntry getFlowEntry(FlowRule rule); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 68 | * Returns the flow entries associated with a device. |
| 69 | * |
| 70 | * @param deviceId the device ID |
| 71 | * @return the flow entries |
| 72 | */ |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 73 | Iterable<FlowEntry> getFlowEntries(DeviceId deviceId); |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 76 | * // TODO: Better description of method behavior. |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 77 | * Stores a new flow rule without generating events. |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 78 | * |
| 79 | * @param rule the flow rule to add |
Sho SHIMIZU | be63b23 | 2015-06-30 10:57:58 -0700 | [diff] [blame] | 80 | * @deprecated in Cardinal Release |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 81 | */ |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 82 | @Deprecated |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 83 | void storeFlowRule(FlowRule rule); |
| 84 | |
| 85 | /** |
| 86 | * Stores a batch of flow rules. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 87 | * |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 88 | * @param batchOperation batch of flow rules. |
Yuta HIGUCHI | 885868f | 2014-11-13 19:12:07 -0800 | [diff] [blame] | 89 | * A batch can contain flow rules for a single device only. |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 90 | * |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 91 | */ |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 92 | void storeBatch(FlowRuleBatchOperation batchOperation); |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Invoked on the completion of a storeBatch operation. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 96 | * |
| 97 | * @param event flow rule batch event |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 98 | */ |
| 99 | void batchOperationComplete(FlowRuleBatchEvent event); |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 102 | * Marks a flow rule for deletion. Actual deletion will occur |
| 103 | * when the provider indicates that the flow has been removed. |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 104 | * |
| 105 | * @param rule the flow rule to delete |
| 106 | */ |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 107 | void deleteFlowRule(FlowRule rule); |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Stores a new flow rule, or updates an existing entry. |
| 111 | * |
| 112 | * @param rule the flow rule to add or update |
| 113 | * @return flow_added event, or null if just an update |
| 114 | */ |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 115 | FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule); |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 116 | |
| 117 | /** |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 118 | * @param rule the flow entry to remove |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 119 | * @return flow_removed event, or null if nothing removed |
| 120 | */ |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 121 | FlowRuleEvent removeFlowRule(FlowEntry rule); |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
Charles Chan | 93fa727 | 2016-01-26 22:27:02 -0800 | [diff] [blame] | 124 | * Marks a flow rule as PENDING_ADD during retry. |
| 125 | * |
| 126 | * Emits flow_update event if the state is changed |
| 127 | * |
| 128 | * @param rule the flow rule that is retrying |
| 129 | * @return flow_updated event, or null if nothing updated |
| 130 | */ |
| 131 | FlowRuleEvent pendingFlowRule(FlowEntry rule); |
| 132 | |
| 133 | /** |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 134 | * Removes all flow entries of given device from store. |
| 135 | * |
| 136 | * @param deviceId device id |
| 137 | */ |
Victor Silva | 139bca4 | 2016-08-18 11:46:35 -0300 | [diff] [blame] | 138 | default void purgeFlowRule(DeviceId deviceId) {} |
| 139 | |
| 140 | /** |
Daniele Moro | cfd7740 | 2021-07-15 17:02:59 +0200 | [diff] [blame] | 141 | * Removes all flow entries of given device and application ID from store. |
| 142 | * |
| 143 | * @param deviceId device id |
| 144 | * @param appId application id |
| 145 | * @return true if operation was successful, false otherwise. |
| 146 | */ |
| 147 | boolean purgeFlowRules(DeviceId deviceId, ApplicationId appId); |
| 148 | |
| 149 | /** |
Victor Silva | 139bca4 | 2016-08-18 11:46:35 -0300 | [diff] [blame] | 150 | * Removes all flow entries from store. |
| 151 | */ |
| 152 | void purgeFlowRules(); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 153 | |
| 154 | /** |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 155 | * Updates the flow table statistics of the specified device using |
| 156 | * the given statistics. |
| 157 | * |
| 158 | * @param deviceId device identifier |
| 159 | * @param tableStats list of table statistics |
| 160 | * @return ready to send event describing what occurred; |
| 161 | */ |
| 162 | FlowRuleEvent updateTableStatistics(DeviceId deviceId, |
| 163 | List<TableStatisticsEntry> tableStats); |
| 164 | |
| 165 | /** |
| 166 | * Returns the flow table statistics associated with a device. |
| 167 | * |
| 168 | * @param deviceId the device ID |
| 169 | * @return the flow table statistics |
| 170 | */ |
| 171 | Iterable<TableStatisticsEntry> getTableStatistics(DeviceId deviceId); |
Patryk Konopka | 7e40c01 | 2017-06-06 13:38:06 +0200 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | * Returns number of flow rules in ADDED state for specified device. |
| 175 | * |
| 176 | * @param deviceId the device ID |
| 177 | * @return number of flow rules in ADDED state |
Jordan Halterman | b81fdc1 | 2019-03-04 18:12:20 -0800 | [diff] [blame] | 178 | * @deprecated since 2.1 |
Patryk Konopka | 7e40c01 | 2017-06-06 13:38:06 +0200 | [diff] [blame] | 179 | */ |
Jordan Halterman | b81fdc1 | 2019-03-04 18:12:20 -0800 | [diff] [blame] | 180 | @Deprecated |
Patryk Konopka | 7e40c01 | 2017-06-06 13:38:06 +0200 | [diff] [blame] | 181 | long getActiveFlowRuleCount(DeviceId deviceId); |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 182 | } |