alshabib | 1d2bc40 | 2015-07-31 17:04:11 -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 | 1d2bc40 | 2015-07-31 17:04:11 -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 | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.core.ApplicationId; |
Andrea Campanella | 5bdbe43 | 2021-05-03 15:59:19 +0200 | [diff] [blame] | 19 | import org.onosproject.net.Annotated; |
| 20 | import org.onosproject.net.Annotations; |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 22 | import org.onosproject.net.pi.service.PiTranslatable; |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 23 | |
| 24 | import java.util.Collection; |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 27 | * Represents a generalized meter cell configuration to be deployed on a device. |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 28 | */ |
Andrea Campanella | 5bdbe43 | 2021-05-03 15:59:19 +0200 | [diff] [blame] | 29 | public interface Meter extends PiTranslatable, Annotated { |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 30 | |
| 31 | enum Unit { |
| 32 | /** |
| 33 | * Packets per second. |
| 34 | */ |
| 35 | PKTS_PER_SEC, |
| 36 | |
| 37 | /** |
| 38 | * Kilo bits per second. |
| 39 | */ |
Wailok Shum | 7991952 | 2021-08-22 19:35:34 +0800 | [diff] [blame] | 40 | KB_PER_SEC, |
| 41 | |
| 42 | /** |
| 43 | * Bytes per second. |
| 44 | */ |
| 45 | BYTES_PER_SEC |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 46 | } |
| 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 Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 59 | * @deprecated in Nightingale release (version 1.13.0). Use {@link #meterCellId()} instead. |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 60 | */ |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 61 | @Deprecated |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 62 | MeterId id(); |
| 63 | |
| 64 | /** |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 65 | * Returns the meter cell identifier of this meter. |
| 66 | * |
| 67 | * @return a meter identifier |
| 68 | */ |
| 69 | MeterCellId meterCellId(); |
| 70 | |
| 71 | /** |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 72 | * The id of the application which created this meter. |
Wailok Shum | 7991952 | 2021-08-22 19:35:34 +0800 | [diff] [blame] | 73 | * Could be null if the meter is read from the controller southbound. |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 74 | * |
| 75 | * @return an application id |
| 76 | */ |
| 77 | ApplicationId appId(); |
Wailok Shum | 7991952 | 2021-08-22 19:35:34 +0800 | [diff] [blame] | 78 | // TODO: Deprecate this and create a new method returns an Optional ApplicationId |
| 79 | // TODO: Or introduce MeterEntry on south and keep this method |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * The unit used within this meter. |
| 83 | * |
Ray Milkey | dbbd87b | 2015-08-03 15:56:22 -0700 | [diff] [blame] | 84 | * @return the unit |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 85 | */ |
| 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 | /** |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 103 | * 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 | /** |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 138 | * 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 | * |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 153 | * @param id a e |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 154 | * @return this |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 155 | * @deprecated in Nightingale release (version 1.13.0). Use {@link |
| 156 | * #withCellId(MeterCellId)} instead. |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 157 | */ |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 158 | @Deprecated |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 159 | Builder withId(MeterId id); |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 160 | |
| 161 | /** |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 162 | * 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 | /** |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 170 | * 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 | |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 202 | /** |
Andrea Campanella | 5bdbe43 | 2021-05-03 15:59:19 +0200 | [diff] [blame] | 203 | * Sets the annotations. |
| 204 | * |
| 205 | * @param annotations annotations |
| 206 | * @return builder object |
| 207 | */ |
| 208 | Builder withAnnotations(Annotations annotations); |
| 209 | |
| 210 | /** |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 211 | * Builds the meter based on the specified parameters. |
| 212 | * |
| 213 | * @return a meter |
| 214 | */ |
| 215 | Meter build(); |
| 216 | } |
| 217 | |
| 218 | } |