alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | |
| 21 | import java.util.Collection; |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Represents a generalized meter to be deployed on a device. |
| 25 | */ |
| 26 | public interface Meter { |
| 27 | |
| 28 | enum Unit { |
| 29 | /** |
| 30 | * Packets per second. |
| 31 | */ |
| 32 | PKTS_PER_SEC, |
| 33 | |
| 34 | /** |
| 35 | * Kilo bits per second. |
| 36 | */ |
| 37 | KB_PER_SEC |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * The target device for this meter. |
| 42 | * |
| 43 | * @return a device id |
| 44 | */ |
| 45 | DeviceId deviceId(); |
| 46 | |
| 47 | /** |
| 48 | * This meters id. |
| 49 | * |
| 50 | * @return a meter id |
| 51 | */ |
| 52 | MeterId id(); |
| 53 | |
| 54 | /** |
| 55 | * The id of the application which created this meter. |
| 56 | * |
| 57 | * @return an application id |
| 58 | */ |
| 59 | ApplicationId appId(); |
| 60 | |
| 61 | /** |
| 62 | * The unit used within this meter. |
| 63 | * |
Ray Milkey | dbbd87b | 2015-08-03 15:56:22 -0700 | [diff] [blame] | 64 | * @return the unit |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 65 | */ |
| 66 | Unit unit(); |
| 67 | |
| 68 | /** |
| 69 | * Signals whether this meter applies to bursts only. |
| 70 | * |
| 71 | * @return a boolean |
| 72 | */ |
| 73 | boolean isBurst(); |
| 74 | |
| 75 | /** |
| 76 | * The collection of bands to apply on the dataplane. |
| 77 | * |
| 78 | * @return a collection of bands. |
| 79 | */ |
| 80 | Collection<Band> bands(); |
| 81 | |
| 82 | /** |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 83 | * Fetches the state of this meter. |
| 84 | * |
| 85 | * @return a meter state |
| 86 | */ |
| 87 | MeterState state(); |
| 88 | |
| 89 | /** |
| 90 | * The lifetime in seconds of this meter. |
| 91 | * |
| 92 | * @return number of seconds |
| 93 | */ |
| 94 | long life(); |
| 95 | |
| 96 | /** |
| 97 | * The number of flows pointing to this meter. |
| 98 | * |
| 99 | * @return a reference count |
| 100 | */ |
| 101 | long referenceCount(); |
| 102 | |
| 103 | /** |
| 104 | * Number of packets processed by this meter. |
| 105 | * |
| 106 | * @return a packet count |
| 107 | */ |
| 108 | long packetsSeen(); |
| 109 | |
| 110 | /** |
| 111 | * Number of bytes processed by this meter. |
| 112 | * |
| 113 | * @return a byte count |
| 114 | */ |
| 115 | long bytesSeen(); |
| 116 | |
| 117 | /** |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 118 | * A meter builder. |
| 119 | */ |
| 120 | interface Builder { |
| 121 | |
| 122 | /** |
| 123 | * Assigns the target device for this meter. |
| 124 | * |
| 125 | * @param deviceId a device id |
| 126 | * @return this |
| 127 | */ |
| 128 | Builder forDevice(DeviceId deviceId); |
| 129 | |
| 130 | /** |
| 131 | * Assigns the id to this meter. |
| 132 | * |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 133 | * @param id a e |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 134 | * @return this |
| 135 | */ |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 136 | Builder withId(MeterId id); |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * Assigns the application that built this meter. |
| 140 | * |
| 141 | * @param appId an application id |
| 142 | * @return this |
| 143 | */ |
| 144 | Builder fromApp(ApplicationId appId); |
| 145 | |
| 146 | /** |
| 147 | * Assigns the @See Unit to use for this meter. |
| 148 | * Defaults to kb/s |
| 149 | * |
| 150 | * @param unit a unit |
| 151 | * @return this |
| 152 | */ |
| 153 | Builder withUnit(Unit unit); |
| 154 | |
| 155 | /** |
| 156 | * Sets this meter as applicable to burst traffic only. |
| 157 | * Defaults to false. |
| 158 | * |
| 159 | * @return this |
| 160 | */ |
| 161 | Builder burst(); |
| 162 | |
| 163 | /** |
| 164 | * Assigns bands to this meter. There must be at least one band. |
| 165 | * |
| 166 | * @param bands a collection of bands |
| 167 | * @return this |
| 168 | */ |
| 169 | Builder withBands(Collection<Band> bands); |
| 170 | |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 171 | /** |
| 172 | * Builds the meter based on the specified parameters. |
| 173 | * |
| 174 | * @return a meter |
| 175 | */ |
| 176 | Meter build(); |
| 177 | } |
| 178 | |
| 179 | } |