blob: f15438b8d7a5bb5b9af15cd889fc8321d5afd3f0 [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 /**
alshabib7bb05012015-08-05 10:15:09 -070039 * Deletes a meter from the store.
40 *
41 * @param meter a meter
alshabibeadfc8e2015-08-18 15:40:46 -070042 * @return a future indicating the result of the store operation
alshabib7bb05012015-08-05 10:15:09 -070043 */
alshabibeadfc8e2015-08-18 15:40:46 -070044 CompletableFuture<MeterStoreResult> deleteMeter(Meter meter);
alshabib7bb05012015-08-05 10:15:09 -070045
Jordi Ortizaa8de492016-12-01 00:21:36 +010046 /**
47 * Adds the meter features to the store.
48 *
49 * @param meterfeatures the meter features
50 * @return the result of the store operation
51 */
52 MeterStoreResult storeMeterFeatures(MeterFeatures meterfeatures);
53
54 /**
Wailok Shum6a249352021-07-29 00:02:56 +080055 * Adds a collection of meter features to the store.
56 *
57 * @param meterfeatures the collection of meter features
58 * @return the result of the store operation
59 */
60 MeterStoreResult storeMeterFeatures(Collection<MeterFeatures> meterfeatures);
61
62 /**
Jordi Ortizaa8de492016-12-01 00:21:36 +010063 * Deletes the meter features from the store.
64 *
65 * @param deviceId the device id
66 * @return a future indicating the result of the store operation
67 */
68 MeterStoreResult deleteMeterFeatures(DeviceId deviceId);
69
alshabib7bb05012015-08-05 10:15:09 -070070 /**
Wailok Shum6a249352021-07-29 00:02:56 +080071 * Deletes a collection of meter features from the store.
72 *
73 * @param meterfeatures a collection of meter features
74 * @return a future indicating the result of the store operation
75 */
76 MeterStoreResult deleteMeterFeatures(Collection<MeterFeatures> meterfeatures);
77
78 /**
alshabib7bb05012015-08-05 10:15:09 -070079 * Updates a given meter's state with the provided state.
alshabibeadfc8e2015-08-18 15:40:46 -070080 *
alshabib7bb05012015-08-05 10:15:09 -070081 * @param meter a meter
pierventre44220052020-09-22 12:51:06 +020082 * @return the updated meter
alshabib7bb05012015-08-05 10:15:09 -070083 */
pierventre44220052020-09-22 12:51:06 +020084 Meter updateMeterState(Meter meter);
alshabib7bb05012015-08-05 10:15:09 -070085
86 /**
alshabib70aaa1b2015-09-25 14:30:59 -070087 * Obtains a meter matching the given meter key.
alshabib7bb05012015-08-05 10:15:09 -070088 *
alshabib70aaa1b2015-09-25 14:30:59 -070089 * @param key a meter key
alshabib7bb05012015-08-05 10:15:09 -070090 * @return a meter
91 */
alshabib70aaa1b2015-09-25 14:30:59 -070092 Meter getMeter(MeterKey key);
alshabib7bb05012015-08-05 10:15:09 -070093
94 /**
95 * Returns all meters stored in the store.
96 *
pierventre44220052020-09-22 12:51:06 +020097 * @return an immutable copy of all meters
alshabib7bb05012015-08-05 10:15:09 -070098 */
99 Collection<Meter> getAllMeters();
100
101 /**
Jordi Ortiz9287b632017-06-22 11:01:37 +0200102 * Returns all meters stored in the store for a
103 * precise device.
104 *
105 * @param deviceId the device to get the meter list from
pierventre44220052020-09-22 12:51:06 +0200106 * @return an immutable copy of the meters stored for a given device
Jordi Ortiz9287b632017-06-22 11:01:37 +0200107 */
108 Collection<Meter> getAllMeters(DeviceId deviceId);
109
110 /**
pierventrec0914ec2021-08-27 15:25:02 +0200111 * Returns all meters stored in the store for a
112 * precise device and scope.
113 *
114 * @param deviceId a device id
115 * @param scope meters scope
116 * @return an immutable copy of the meters stored for a given device
117 * withing a given scope
118 */
119 Collection<Meter> getAllMeters(DeviceId deviceId, MeterScope scope);
120
121 /**
alshabib7bb05012015-08-05 10:15:09 -0700122 * Update the store by deleting the failed meter.
123 * Notifies the delegate that the meter failed to allow it
124 * to nofity the app.
125 *
Gamze Abakaf57ef602019-03-11 06:52:48 +0000126 * @param op a failed meter operation
alshabib7bb05012015-08-05 10:15:09 -0700127 * @param reason a failure reason
128 */
129 void failedMeter(MeterOperation op, MeterFailReason reason);
alshabib5eb79392015-08-19 18:09:55 -0700130
131 /**
132 * Delete this meter immediately.
Gamze Abakaf57ef602019-03-11 06:52:48 +0000133 *
alshabib5eb79392015-08-19 18:09:55 -0700134 * @param m a meter
Wailok Shumf013a782021-07-26 16:51:01 +0800135 */
136 void purgeMeter(Meter m);
137
138 /**
Wailok Shumf013a782021-07-26 16:51:01 +0800139 * Allocates the first available MeterId.
140 *
141 * @param deviceId the device id
142 * @param meterScope the meter scope
143 * @return the meter Id or null if it was not possible
144 * to allocate a meter id
145 */
146 MeterCellId allocateMeterId(DeviceId deviceId, MeterScope meterScope);
147
148 /**
Pier Luigif094c612017-10-14 12:15:02 +0200149 * Frees the given meter id.
150 *
151 * @param deviceId the device id
Gamze Abakaf57ef602019-03-11 06:52:48 +0000152 * @param meterId the id to be freed
Wailok Shumf013a782021-07-26 16:51:01 +0800153 * @deprecated in onos-2.5, freeing an ID is closely related to removal of a meter
154 * so, this function is no longer exposed on interface
Pier Luigif094c612017-10-14 12:15:02 +0200155 */
Wailok Shumf013a782021-07-26 16:51:01 +0800156 @Deprecated
Pier Luigif094c612017-10-14 12:15:02 +0200157 void freeMeterId(DeviceId deviceId, MeterId meterId);
Jordi Ortiz6c847762017-01-30 17:13:05 +0100158
Gamze Abakaf57ef602019-03-11 06:52:48 +0000159 /**
160 * Removes all meters of given device from store.
Daniele Moro43ac2892021-07-15 17:02:59 +0200161 * This API is typically used when the device is offline.
Gamze Abakaf57ef602019-03-11 06:52:48 +0000162 *
163 * @param deviceId the device id
pierventre3b39bd82021-08-18 09:40:14 +0200164 */
165 void purgeMeters(DeviceId deviceId);
166
167 /**
Daniele Moro43ac2892021-07-15 17:02:59 +0200168 * Removes all meters of given device and for the given application from store.
169 * This API is typically used when the device is offline.
170 *
171 * @param deviceId the device id
172 * @param appId the application id
173 */
174 void purgeMeters(DeviceId deviceId, ApplicationId appId);
175
pierventre3b39bd82021-08-18 09:40:14 +0200176 /**
177 * Enables/disables user defined index mode for the store. In this mode users
178 * can provide an index for the meter. Store may reject switching mode requests
179 * at run time if meters were already allocated.
180 *
181 * @param enable to enable/disable the user defined index mode.
182 * @return true if user defined index mode is enabled. False otherwise.
183 */
184 boolean userDefinedIndexMode(boolean enable);
185
alshabib7bb05012015-08-05 10:15:09 -0700186}