alshabib | 7bb0501 | 2015-08-05 10:15:09 -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 | 7bb0501 | 2015-08-05 10:15:09 -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 | */ |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 16 | package org.onosproject.net.meter; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 17 | |
Daniele Moro | 43ac289 | 2021-07-15 17:02:59 +0200 | [diff] [blame^] | 18 | import org.onosproject.core.ApplicationId; |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 19 | import org.onosproject.net.DeviceId; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 20 | import org.onosproject.store.Store; |
| 21 | |
| 22 | import java.util.Collection; |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 23 | import java.util.concurrent.CompletableFuture; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Entity that stores and distributed meter objects. |
| 27 | */ |
| 28 | public interface MeterStore extends Store<MeterEvent, MeterStoreDelegate> { |
| 29 | |
| 30 | /** |
Wailok Shum | 6a24935 | 2021-07-29 00:02:56 +0800 | [diff] [blame] | 31 | * Adds a meter to the store or updates a meter in the store. |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 32 | * |
| 33 | * @param meter a meter |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 34 | * @return a future indicating the result of the store operation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 35 | */ |
Wailok Shum | 6a24935 | 2021-07-29 00:02:56 +0800 | [diff] [blame] | 36 | CompletableFuture<MeterStoreResult> addOrUpdateMeter(Meter meter); |
| 37 | |
| 38 | /** |
| 39 | * Adds a meter to the store. |
| 40 | * |
| 41 | * @param meter a meter |
| 42 | * @return a future indicating the result of the store operation |
| 43 | * @deprecated in onos-2.5 replaced by {@link #addOrUpdateMeter(Meter)} |
| 44 | */ |
| 45 | @Deprecated |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 46 | CompletableFuture<MeterStoreResult> storeMeter(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Deletes a meter from the store. |
| 50 | * |
| 51 | * @param meter a meter |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 52 | * @return a future indicating the result of the store operation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 53 | */ |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 54 | CompletableFuture<MeterStoreResult> deleteMeter(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 55 | |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 56 | /** |
| 57 | * Adds the meter features to the store. |
| 58 | * |
| 59 | * @param meterfeatures the meter features |
| 60 | * @return the result of the store operation |
| 61 | */ |
| 62 | MeterStoreResult storeMeterFeatures(MeterFeatures meterfeatures); |
| 63 | |
| 64 | /** |
Wailok Shum | 6a24935 | 2021-07-29 00:02:56 +0800 | [diff] [blame] | 65 | * Adds a collection of meter features to the store. |
| 66 | * |
| 67 | * @param meterfeatures the collection of meter features |
| 68 | * @return the result of the store operation |
| 69 | */ |
| 70 | MeterStoreResult storeMeterFeatures(Collection<MeterFeatures> meterfeatures); |
| 71 | |
| 72 | /** |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 73 | * Deletes the meter features from the store. |
| 74 | * |
| 75 | * @param deviceId the device id |
| 76 | * @return a future indicating the result of the store operation |
| 77 | */ |
| 78 | MeterStoreResult deleteMeterFeatures(DeviceId deviceId); |
| 79 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 80 | /** |
Wailok Shum | 6a24935 | 2021-07-29 00:02:56 +0800 | [diff] [blame] | 81 | * Deletes a collection of meter features from the store. |
| 82 | * |
| 83 | * @param meterfeatures a collection of meter features |
| 84 | * @return a future indicating the result of the store operation |
| 85 | */ |
| 86 | MeterStoreResult deleteMeterFeatures(Collection<MeterFeatures> meterfeatures); |
| 87 | |
| 88 | /** |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 89 | * Updates a meter whose meter id is the same as the passed meter. |
| 90 | * |
| 91 | * @param meter a new meter |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 92 | * @return a future indicating the result of the store operation |
Wailok Shum | 6a24935 | 2021-07-29 00:02:56 +0800 | [diff] [blame] | 93 | * @deprecated in onos-2.5 replaced by {@link #addOrUpdateMeter(Meter)} |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 94 | */ |
Wailok Shum | 6a24935 | 2021-07-29 00:02:56 +0800 | [diff] [blame] | 95 | @Deprecated |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 96 | CompletableFuture<MeterStoreResult> updateMeter(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Updates a given meter's state with the provided state. |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 100 | * |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 101 | * @param meter a meter |
pierventre | 4422005 | 2020-09-22 12:51:06 +0200 | [diff] [blame] | 102 | * @return the updated meter |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 103 | */ |
pierventre | 4422005 | 2020-09-22 12:51:06 +0200 | [diff] [blame] | 104 | Meter updateMeterState(Meter meter); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 107 | * Obtains a meter matching the given meter key. |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 108 | * |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 109 | * @param key a meter key |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 110 | * @return a meter |
| 111 | */ |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 112 | Meter getMeter(MeterKey key); |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Returns all meters stored in the store. |
| 116 | * |
pierventre | 4422005 | 2020-09-22 12:51:06 +0200 | [diff] [blame] | 117 | * @return an immutable copy of all meters |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 118 | */ |
| 119 | Collection<Meter> getAllMeters(); |
| 120 | |
| 121 | /** |
Jordi Ortiz | 9287b63 | 2017-06-22 11:01:37 +0200 | [diff] [blame] | 122 | * Returns all meters stored in the store for a |
| 123 | * precise device. |
| 124 | * |
| 125 | * @param deviceId the device to get the meter list from |
pierventre | 4422005 | 2020-09-22 12:51:06 +0200 | [diff] [blame] | 126 | * @return an immutable copy of the meters stored for a given device |
Jordi Ortiz | 9287b63 | 2017-06-22 11:01:37 +0200 | [diff] [blame] | 127 | */ |
| 128 | Collection<Meter> getAllMeters(DeviceId deviceId); |
| 129 | |
| 130 | /** |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 131 | * Update the store by deleting the failed meter. |
| 132 | * Notifies the delegate that the meter failed to allow it |
| 133 | * to nofity the app. |
| 134 | * |
Gamze Abaka | f57ef60 | 2019-03-11 06:52:48 +0000 | [diff] [blame] | 135 | * @param op a failed meter operation |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 136 | * @param reason a failure reason |
| 137 | */ |
| 138 | void failedMeter(MeterOperation op, MeterFailReason reason); |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Delete this meter immediately. |
Gamze Abaka | f57ef60 | 2019-03-11 06:52:48 +0000 | [diff] [blame] | 142 | * |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 143 | * @param m a meter |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 144 | * @deprecated in onos-2.5 renamed {@link #purgeMeter(Meter)} |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 145 | */ |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 146 | @Deprecated |
alshabib | 5eb7939 | 2015-08-19 18:09:55 -0700 | [diff] [blame] | 147 | void deleteMeterNow(Meter m); |
| 148 | |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 149 | /** |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 150 | * Delete this meter immediately. |
| 151 | * |
| 152 | * @param m a meter |
| 153 | */ |
| 154 | void purgeMeter(Meter m); |
| 155 | |
| 156 | /** |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 157 | * Retrieve maximum meters available for the device. |
| 158 | * |
| 159 | * @param key the meter features key |
| 160 | * @return the maximum number of meters supported by the device |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 161 | * @deprecated in onos-2.5, Max meters is replaced by start and end index |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 162 | */ |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 163 | @Deprecated |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 164 | long getMaxMeters(MeterFeaturesKey key); |
| 165 | |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 166 | /** |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 167 | * Allocates the first available MeterId. |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 168 | * |
| 169 | * @param deviceId the device id |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 170 | * @return the meter Id or null if it was not possible |
| 171 | * to allocate a meter id |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 172 | * @deprecated in onos-2.5 replaced by {@link #allocateMeterId(DeviceId, MeterScope)} |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 173 | */ |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 174 | @Deprecated |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 175 | MeterId allocateMeterId(DeviceId deviceId); |
| 176 | |
| 177 | /** |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 178 | * Allocates the first available MeterId. |
| 179 | * |
| 180 | * @param deviceId the device id |
| 181 | * @param meterScope the meter scope |
| 182 | * @return the meter Id or null if it was not possible |
| 183 | * to allocate a meter id |
| 184 | */ |
| 185 | MeterCellId allocateMeterId(DeviceId deviceId, MeterScope meterScope); |
| 186 | |
| 187 | /** |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 188 | * Frees the given meter id. |
| 189 | * |
| 190 | * @param deviceId the device id |
Gamze Abaka | f57ef60 | 2019-03-11 06:52:48 +0000 | [diff] [blame] | 191 | * @param meterId the id to be freed |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 192 | * @deprecated in onos-2.5, freeing an ID is closely related to removal of a meter |
| 193 | * so, this function is no longer exposed on interface |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 194 | */ |
Wailok Shum | f013a78 | 2021-07-26 16:51:01 +0800 | [diff] [blame] | 195 | @Deprecated |
Pier Luigi | f094c61 | 2017-10-14 12:15:02 +0200 | [diff] [blame] | 196 | void freeMeterId(DeviceId deviceId, MeterId meterId); |
Jordi Ortiz | 6c84776 | 2017-01-30 17:13:05 +0100 | [diff] [blame] | 197 | |
Gamze Abaka | f57ef60 | 2019-03-11 06:52:48 +0000 | [diff] [blame] | 198 | /** |
| 199 | * Removes all meters of given device from store. |
Daniele Moro | 43ac289 | 2021-07-15 17:02:59 +0200 | [diff] [blame^] | 200 | * This API is typically used when the device is offline. |
Gamze Abaka | f57ef60 | 2019-03-11 06:52:48 +0000 | [diff] [blame] | 201 | * |
| 202 | * @param deviceId the device id |
| 203 | */ |
| 204 | void purgeMeter(DeviceId deviceId); |
| 205 | |
Daniele Moro | 43ac289 | 2021-07-15 17:02:59 +0200 | [diff] [blame^] | 206 | /** |
| 207 | * Removes all meters of given device and for the given application from store. |
| 208 | * This API is typically used when the device is offline. |
| 209 | * |
| 210 | * @param deviceId the device id |
| 211 | * @param appId the application id |
| 212 | */ |
| 213 | void purgeMeters(DeviceId deviceId, ApplicationId appId); |
| 214 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 215 | } |