blob: 64379d33909a3b8ef14568a9c8aa51ad51b09540 [file] [log] [blame]
alshabib1d2bc402015-07-31 17:04:11 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
alshabib1d2bc402015-07-31 17:04:11 -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;
alshabib1d2bc402015-07-31 17:04:11 -070017
18import org.onosproject.core.ApplicationId;
Andrea Campanella5bdbe432021-05-03 15:59:19 +020019import org.onosproject.net.Annotated;
20import org.onosproject.net.Annotations;
alshabib1d2bc402015-07-31 17:04:11 -070021import org.onosproject.net.DeviceId;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090022import org.onosproject.net.pi.service.PiTranslatable;
alshabib1d2bc402015-07-31 17:04:11 -070023
24import java.util.Collection;
alshabib1d2bc402015-07-31 17:04:11 -070025
26/**
Frank Wangd7e3b4b2017-09-24 13:37:54 +090027 * Represents a generalized meter cell configuration to be deployed on a device.
alshabib1d2bc402015-07-31 17:04:11 -070028 */
Andrea Campanella5bdbe432021-05-03 15:59:19 +020029public interface Meter extends PiTranslatable, Annotated {
alshabib1d2bc402015-07-31 17:04:11 -070030
31 enum Unit {
32 /**
33 * Packets per second.
34 */
35 PKTS_PER_SEC,
36
37 /**
38 * Kilo bits per second.
39 */
Wailok Shum79919522021-08-22 19:35:34 +080040 KB_PER_SEC,
41
42 /**
43 * Bytes per second.
44 */
45 BYTES_PER_SEC
alshabib1d2bc402015-07-31 17:04:11 -070046 }
47
48 /**
49 * The target device for this meter.
50 *
51 * @return a device id
52 */
53 DeviceId deviceId();
54
55 /**
56 * This meters id.
57 *
58 * @return a meter id
Frank Wangd7e3b4b2017-09-24 13:37:54 +090059 * @deprecated in Nightingale release (version 1.13.0). Use {@link #meterCellId()} instead.
alshabib1d2bc402015-07-31 17:04:11 -070060 */
Frank Wangd7e3b4b2017-09-24 13:37:54 +090061 @Deprecated
alshabib1d2bc402015-07-31 17:04:11 -070062 MeterId id();
63
64 /**
Frank Wangd7e3b4b2017-09-24 13:37:54 +090065 * Returns the meter cell identifier of this meter.
66 *
67 * @return a meter identifier
68 */
69 MeterCellId meterCellId();
70
71 /**
alshabib1d2bc402015-07-31 17:04:11 -070072 * The id of the application which created this meter.
Wailok Shum79919522021-08-22 19:35:34 +080073 * Could be null if the meter is read from the controller southbound.
alshabib1d2bc402015-07-31 17:04:11 -070074 *
75 * @return an application id
76 */
77 ApplicationId appId();
Wailok Shum79919522021-08-22 19:35:34 +080078 // TODO: Deprecate this and create a new method returns an Optional ApplicationId
79 // TODO: Or introduce MeterEntry on south and keep this method
alshabib1d2bc402015-07-31 17:04:11 -070080
81 /**
82 * The unit used within this meter.
83 *
Ray Milkeydbbd87b2015-08-03 15:56:22 -070084 * @return the unit
alshabib1d2bc402015-07-31 17:04:11 -070085 */
86 Unit unit();
87
88 /**
89 * Signals whether this meter applies to bursts only.
90 *
91 * @return a boolean
92 */
93 boolean isBurst();
94
95 /**
96 * The collection of bands to apply on the dataplane.
97 *
98 * @return a collection of bands.
99 */
100 Collection<Band> bands();
101
102 /**
alshabib7bb05012015-08-05 10:15:09 -0700103 * Fetches the state of this meter.
104 *
105 * @return a meter state
106 */
107 MeterState state();
108
109 /**
110 * The lifetime in seconds of this meter.
111 *
112 * @return number of seconds
113 */
114 long life();
115
116 /**
117 * The number of flows pointing to this meter.
118 *
119 * @return a reference count
120 */
121 long referenceCount();
122
123 /**
124 * Number of packets processed by this meter.
125 *
126 * @return a packet count
127 */
128 long packetsSeen();
129
130 /**
131 * Number of bytes processed by this meter.
132 *
133 * @return a byte count
134 */
135 long bytesSeen();
136
137 /**
alshabib1d2bc402015-07-31 17:04:11 -0700138 * A meter builder.
139 */
140 interface Builder {
141
142 /**
143 * Assigns the target device for this meter.
144 *
145 * @param deviceId a device id
146 * @return this
147 */
148 Builder forDevice(DeviceId deviceId);
149
150 /**
151 * Assigns the id to this meter.
152 *
alshabibe1248b62015-08-20 17:21:55 -0700153 * @param id a e
alshabib1d2bc402015-07-31 17:04:11 -0700154 * @return this
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900155 * @deprecated in Nightingale release (version 1.13.0). Use {@link
156 * #withCellId(MeterCellId)} instead.
alshabib1d2bc402015-07-31 17:04:11 -0700157 */
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900158 @Deprecated
alshabib58fe6dc2015-08-19 17:16:13 -0700159 Builder withId(MeterId id);
alshabib1d2bc402015-07-31 17:04:11 -0700160
161 /**
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900162 * Assigns the id to this meter cell.
163 *
164 * @param meterId a meter cell identifier
165 * @return this
166 */
167 Builder withCellId(MeterCellId meterId);
168
169 /**
alshabib1d2bc402015-07-31 17:04:11 -0700170 * Assigns the application that built this meter.
171 *
172 * @param appId an application id
173 * @return this
174 */
175 Builder fromApp(ApplicationId appId);
176
177 /**
178 * Assigns the @See Unit to use for this meter.
179 * Defaults to kb/s
180 *
181 * @param unit a unit
182 * @return this
183 */
184 Builder withUnit(Unit unit);
185
186 /**
187 * Sets this meter as applicable to burst traffic only.
188 * Defaults to false.
189 *
190 * @return this
191 */
192 Builder burst();
193
194 /**
195 * Assigns bands to this meter. There must be at least one band.
196 *
197 * @param bands a collection of bands
198 * @return this
199 */
200 Builder withBands(Collection<Band> bands);
201
alshabib1d2bc402015-07-31 17:04:11 -0700202 /**
Andrea Campanella5bdbe432021-05-03 15:59:19 +0200203 * Sets the annotations.
204 *
205 * @param annotations annotations
206 * @return builder object
207 */
208 Builder withAnnotations(Annotations annotations);
209
210 /**
alshabib1d2bc402015-07-31 17:04:11 -0700211 * Builds the meter based on the specified parameters.
212 *
213 * @return a meter
214 */
215 Meter build();
216 }
217
218}