blob: 7f4de4b727390bf5cc2d086bc940151bf75407d9 [file] [log] [blame]
alshabib7bb05012015-08-05 10:15:09 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
alshabib7bb05012015-08-05 10:15:09 -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 */
alshabib10c810b2015-08-18 16:59:04 -070016package org.onosproject.net.meter;
alshabib7bb05012015-08-05 10:15:09 -070017
Daniele Moro43ac2892021-07-15 17:02:59 +020018import org.onosproject.core.ApplicationId;
Jordi Ortizaa8de492016-12-01 00:21:36 +010019import org.onosproject.net.DeviceId;
alshabib7bb05012015-08-05 10:15:09 -070020import org.onosproject.store.Store;
21
22import java.util.Collection;
alshabibeadfc8e2015-08-18 15:40:46 -070023import java.util.concurrent.CompletableFuture;
alshabib7bb05012015-08-05 10:15:09 -070024
25/**
26 * Entity that stores and distributed meter objects.
27 */
28public interface MeterStore extends Store<MeterEvent, MeterStoreDelegate> {
29
30 /**
Wailok Shum6a249352021-07-29 00:02:56 +080031 * Adds a meter to the store or updates a meter in the store.
alshabib7bb05012015-08-05 10:15:09 -070032 *
33 * @param meter a meter
alshabibeadfc8e2015-08-18 15:40:46 -070034 * @return a future indicating the result of the store operation
alshabib7bb05012015-08-05 10:15:09 -070035 */
Wailok Shum6a249352021-07-29 00:02:56 +080036 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
alshabibeadfc8e2015-08-18 15:40:46 -070046 CompletableFuture<MeterStoreResult> storeMeter(Meter meter);
alshabib7bb05012015-08-05 10:15:09 -070047
48 /**
49 * Deletes a meter from the store.
50 *
51 * @param meter a meter
alshabibeadfc8e2015-08-18 15:40:46 -070052 * @return a future indicating the result of the store operation
alshabib7bb05012015-08-05 10:15:09 -070053 */
alshabibeadfc8e2015-08-18 15:40:46 -070054 CompletableFuture<MeterStoreResult> deleteMeter(Meter meter);
alshabib7bb05012015-08-05 10:15:09 -070055
Jordi Ortizaa8de492016-12-01 00:21:36 +010056 /**
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 Shum6a249352021-07-29 00:02:56 +080065 * 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 Ortizaa8de492016-12-01 00:21:36 +010073 * 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
alshabib7bb05012015-08-05 10:15:09 -070080 /**
Wailok Shum6a249352021-07-29 00:02:56 +080081 * 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 /**
alshabib7bb05012015-08-05 10:15:09 -070089 * Updates a given meter's state with the provided state.
alshabibeadfc8e2015-08-18 15:40:46 -070090 *
alshabib7bb05012015-08-05 10:15:09 -070091 * @param meter a meter
pierventre44220052020-09-22 12:51:06 +020092 * @return the updated meter
alshabib7bb05012015-08-05 10:15:09 -070093 */
pierventre44220052020-09-22 12:51:06 +020094 Meter updateMeterState(Meter meter);
alshabib7bb05012015-08-05 10:15:09 -070095
96 /**
alshabib70aaa1b2015-09-25 14:30:59 -070097 * Obtains a meter matching the given meter key.
alshabib7bb05012015-08-05 10:15:09 -070098 *
alshabib70aaa1b2015-09-25 14:30:59 -070099 * @param key a meter key
alshabib7bb05012015-08-05 10:15:09 -0700100 * @return a meter
101 */
alshabib70aaa1b2015-09-25 14:30:59 -0700102 Meter getMeter(MeterKey key);
alshabib7bb05012015-08-05 10:15:09 -0700103
104 /**
105 * Returns all meters stored in the store.
106 *
pierventre44220052020-09-22 12:51:06 +0200107 * @return an immutable copy of all meters
alshabib7bb05012015-08-05 10:15:09 -0700108 */
109 Collection<Meter> getAllMeters();
110
111 /**
Jordi Ortiz9287b632017-06-22 11:01:37 +0200112 * Returns all meters stored in the store for a
113 * precise device.
114 *
115 * @param deviceId the device to get the meter list from
pierventre44220052020-09-22 12:51:06 +0200116 * @return an immutable copy of the meters stored for a given device
Jordi Ortiz9287b632017-06-22 11:01:37 +0200117 */
118 Collection<Meter> getAllMeters(DeviceId deviceId);
119
120 /**
alshabib7bb05012015-08-05 10:15:09 -0700121 * Update the store by deleting the failed meter.
122 * Notifies the delegate that the meter failed to allow it
123 * to nofity the app.
124 *
Gamze Abakaf57ef602019-03-11 06:52:48 +0000125 * @param op a failed meter operation
alshabib7bb05012015-08-05 10:15:09 -0700126 * @param reason a failure reason
127 */
128 void failedMeter(MeterOperation op, MeterFailReason reason);
alshabib5eb79392015-08-19 18:09:55 -0700129
130 /**
131 * Delete this meter immediately.
Gamze Abakaf57ef602019-03-11 06:52:48 +0000132 *
alshabib5eb79392015-08-19 18:09:55 -0700133 * @param m a meter
Wailok Shumf013a782021-07-26 16:51:01 +0800134 * @deprecated in onos-2.5 renamed {@link #purgeMeter(Meter)}
alshabib5eb79392015-08-19 18:09:55 -0700135 */
Wailok Shumf013a782021-07-26 16:51:01 +0800136 @Deprecated
alshabib5eb79392015-08-19 18:09:55 -0700137 void deleteMeterNow(Meter m);
138
Jordi Ortizaa8de492016-12-01 00:21:36 +0100139 /**
Wailok Shumf013a782021-07-26 16:51:01 +0800140 * Delete this meter immediately.
141 *
142 * @param m a meter
143 */
144 void purgeMeter(Meter m);
145
146 /**
Jordi Ortizaa8de492016-12-01 00:21:36 +0100147 * Retrieve maximum meters available for the device.
148 *
149 * @param key the meter features key
150 * @return the maximum number of meters supported by the device
Wailok Shumf013a782021-07-26 16:51:01 +0800151 * @deprecated in onos-2.5, Max meters is replaced by start and end index
Jordi Ortizaa8de492016-12-01 00:21:36 +0100152 */
Wailok Shumf013a782021-07-26 16:51:01 +0800153 @Deprecated
Jordi Ortizaa8de492016-12-01 00:21:36 +0100154 long getMaxMeters(MeterFeaturesKey key);
155
Jordi Ortiz6c847762017-01-30 17:13:05 +0100156 /**
Pier Luigif094c612017-10-14 12:15:02 +0200157 * Allocates the first available MeterId.
Jordi Ortiz6c847762017-01-30 17:13:05 +0100158 *
159 * @param deviceId the device id
Pier Luigif094c612017-10-14 12:15:02 +0200160 * @return the meter Id or null if it was not possible
161 * to allocate a meter id
Wailok Shumf013a782021-07-26 16:51:01 +0800162 * @deprecated in onos-2.5 replaced by {@link #allocateMeterId(DeviceId, MeterScope)}
Jordi Ortiz6c847762017-01-30 17:13:05 +0100163 */
Wailok Shumf013a782021-07-26 16:51:01 +0800164 @Deprecated
Pier Luigif094c612017-10-14 12:15:02 +0200165 MeterId allocateMeterId(DeviceId deviceId);
166
167 /**
Wailok Shumf013a782021-07-26 16:51:01 +0800168 * Allocates the first available MeterId.
169 *
170 * @param deviceId the device id
171 * @param meterScope the meter scope
172 * @return the meter Id or null if it was not possible
173 * to allocate a meter id
174 */
175 MeterCellId allocateMeterId(DeviceId deviceId, MeterScope meterScope);
176
177 /**
Pier Luigif094c612017-10-14 12:15:02 +0200178 * Frees the given meter id.
179 *
180 * @param deviceId the device id
Gamze Abakaf57ef602019-03-11 06:52:48 +0000181 * @param meterId the id to be freed
Wailok Shumf013a782021-07-26 16:51:01 +0800182 * @deprecated in onos-2.5, freeing an ID is closely related to removal of a meter
183 * so, this function is no longer exposed on interface
Pier Luigif094c612017-10-14 12:15:02 +0200184 */
Wailok Shumf013a782021-07-26 16:51:01 +0800185 @Deprecated
Pier Luigif094c612017-10-14 12:15:02 +0200186 void freeMeterId(DeviceId deviceId, MeterId meterId);
Jordi Ortiz6c847762017-01-30 17:13:05 +0100187
Gamze Abakaf57ef602019-03-11 06:52:48 +0000188 /**
189 * Removes all meters of given device from store.
Daniele Moro43ac2892021-07-15 17:02:59 +0200190 * This API is typically used when the device is offline.
Gamze Abakaf57ef602019-03-11 06:52:48 +0000191 *
192 * @param deviceId the device id
pierventre3b39bd82021-08-18 09:40:14 +0200193 * @deprecated in onos-2.5, replaced by {@link #purgeMeters(DeviceId)}
Gamze Abakaf57ef602019-03-11 06:52:48 +0000194 */
pierventre3b39bd82021-08-18 09:40:14 +0200195 @Deprecated
Gamze Abakaf57ef602019-03-11 06:52:48 +0000196 void purgeMeter(DeviceId deviceId);
197
Daniele Moro43ac2892021-07-15 17:02:59 +0200198 /**
pierventre3b39bd82021-08-18 09:40:14 +0200199 * Removes all meters of given device from store.
200 * This API is typically used when the device is offline.
201 *
202 * @param deviceId the device id
203 */
204 void purgeMeters(DeviceId deviceId);
205
206 /**
Daniele Moro43ac2892021-07-15 17:02:59 +0200207 * 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
pierventre3b39bd82021-08-18 09:40:14 +0200215 /**
216 * Enables/disables user defined index mode for the store. In this mode users
217 * can provide an index for the meter. Store may reject switching mode requests
218 * at run time if meters were already allocated.
219 *
220 * @param enable to enable/disable the user defined index mode.
221 * @return true if user defined index mode is enabled. False otherwise.
222 */
223 boolean userDefinedIndexMode(boolean enable);
224
alshabib7bb05012015-08-05 10:15:09 -0700225}