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