Pier Luigi | 09220c2 | 2017-09-14 22:00:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.net.behaviour.trafficcontrol; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
| 23 | import java.util.Collection; |
| 24 | |
| 25 | /** |
| 26 | * Generic abstraction for a policer which can mark and/or discard ingress |
| 27 | * traffic. Each policer is made up of an identifier and a set of attributes |
| 28 | * which defines the type of policer. |
| 29 | * <p> |
| 30 | * For example a policer specifying only a single token bucket, it will model |
| 31 | * a simple drop policer or a marker policer. For the former, the traffic in |
| 32 | * profile is green or red if it is out-of-profile. The latter envisages green |
| 33 | * or yellow traffic. Currently there is no RFC for this kind of policer but |
| 34 | * some vendors implement this model. |
| 35 | * <p> |
| 36 | * RFC 2697 can be modelled creating a policer with a collection of two |
| 37 | * token buckets: [0] CIR + CBS; [1] CIR + EBS. In this way, it is possible |
| 38 | * to create a policer single rate three color marker. |
| 39 | * <p> |
| 40 | * RFC 2698 and P4 meter are modelled in the same way but different attributes |
| 41 | * for the token buckets: [0] PIR + PBS; [2] CIR + CBS. In this way, we can |
| 42 | * create a policer two rate three color marker. |
| 43 | * <p> |
| 44 | * How these policers will be implemented depends on the specific technology |
| 45 | * used in the device. For an OF device, the single rate two color marker it |
| 46 | * could be implemented with a simple meter with a drop band. |
| 47 | * <p> |
| 48 | * Following abstraction has been designed to cover several types of policing |
| 49 | * that have been specified during the years. However, this does not assure that |
| 50 | * used technology will support all possible scenarios. For example, OF limitations |
| 51 | * are well known in this field and implementations are even worse. |
| 52 | */ |
| 53 | @Beta |
| 54 | public interface Policer { |
| 55 | |
| 56 | /** |
| 57 | * Unit of traffic used by this policer. |
| 58 | */ |
| 59 | enum Unit { |
| 60 | /** |
| 61 | * Packets per second. |
| 62 | */ |
| 63 | PKTS_PER_SEC, |
| 64 | /** |
| 65 | * Byte per second. |
| 66 | */ |
| 67 | B_PER_SEC, |
| 68 | /** |
| 69 | * KByte per second. |
| 70 | */ |
| 71 | KB_PER_SEC, |
| 72 | /** |
| 73 | * MByte per second. |
| 74 | */ |
| 75 | MB_PER_SEC |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * The device of this policer, where policing |
| 80 | * is applied. |
| 81 | * |
| 82 | * @return the device id |
| 83 | */ |
| 84 | DeviceId deviceId(); |
| 85 | |
| 86 | /** |
| 87 | * The id of the application which created this policer. |
| 88 | * |
| 89 | * @return the identifier of the application |
| 90 | */ |
| 91 | ApplicationId applicationId(); |
| 92 | |
| 93 | /** |
| 94 | * Returns how many are referencing this policer. |
| 95 | * |
| 96 | * Availability of this information depends on the |
| 97 | * technology used for the implementation of this policer. |
| 98 | * |
| 99 | * @return the reference count |
| 100 | */ |
| 101 | long referenceCount(); |
| 102 | |
| 103 | /** |
| 104 | * Stats which reports how many packets have been |
| 105 | * processed so far. |
| 106 | * |
| 107 | * Availability of this information depends on the |
| 108 | * technology used for the implementation of this policer. |
| 109 | * |
| 110 | * @return the processed packets |
| 111 | */ |
| 112 | long processedPackets(); |
| 113 | |
| 114 | /** |
| 115 | * Stats which reports how many bytes have been |
| 116 | * processed so far. |
| 117 | * |
| 118 | * Availability of this information depends on the |
| 119 | * technology used for the implementation of this policer. |
| 120 | * |
| 121 | * @return the processed bytes |
| 122 | */ |
| 123 | long processedBytes(); |
| 124 | |
| 125 | /** |
| 126 | * The id of this policer. |
| 127 | * |
| 128 | * @return the policer id |
| 129 | */ |
| 130 | PolicerId policerId(); |
| 131 | |
| 132 | /** |
| 133 | * Indicates if this policer is aware of the marking indication |
| 134 | * in the ethernet frames. |
| 135 | * |
| 136 | * TODO Understand for the future how it is implemented by the vendors |
| 137 | * |
| 138 | * @return true if this policer is color aware. |
| 139 | */ |
| 140 | boolean isColorAware(); |
| 141 | |
| 142 | /** |
| 143 | * The lifetime in seconds of this policer. |
| 144 | * |
| 145 | * Availability of this information depends on the |
| 146 | * technology used for the implementation of this policer. |
| 147 | * |
| 148 | * @return number of seconds |
| 149 | */ |
| 150 | long life(); |
| 151 | |
| 152 | /** |
| 153 | * The unit used within this policer. |
| 154 | * |
| 155 | * @return the unit |
| 156 | */ |
| 157 | Unit unit(); |
| 158 | |
| 159 | /** |
| 160 | * The token buckets used within this policer. |
| 161 | * |
| 162 | * @return the list of the token buckets |
| 163 | */ |
| 164 | Collection<TokenBucket> tokenBuckets(); |
| 165 | |
| 166 | /** |
| 167 | * Brief description of this policer. |
| 168 | * |
| 169 | * @return human readable description |
| 170 | */ |
| 171 | String description(); |
| 172 | |
| 173 | /** |
| 174 | * A policer builder. |
| 175 | */ |
| 176 | interface Builder { |
| 177 | |
| 178 | /** |
| 179 | * Assigns the device for this policer. |
| 180 | * <p> |
| 181 | * Note: mandatory setter for this builder |
| 182 | * </p> |
| 183 | * @param deviceId a device id |
| 184 | * @return this |
| 185 | */ |
| 186 | Builder forDeviceId(DeviceId deviceId); |
| 187 | |
| 188 | /** |
| 189 | * Assigns the application that built this policer. |
| 190 | * <p> |
| 191 | * Note: mandatory setter for this builder |
| 192 | * </p> |
| 193 | * @param appId an application id |
| 194 | * @return this |
| 195 | */ |
| 196 | Builder fromApp(ApplicationId appId); |
| 197 | |
| 198 | /** |
| 199 | * Assigns the id to this policer. |
| 200 | * <p> |
| 201 | * Note: mandatory setter for this builder |
| 202 | * </p> |
| 203 | * @param id an identifier |
| 204 | * @return this |
| 205 | */ |
| 206 | Builder withId(PolicerId id); |
| 207 | |
| 208 | /** |
| 209 | * Sets this policer to be color aware. |
| 210 | * Defaults to false. |
| 211 | * |
| 212 | * @param isColorAware if it is color aware or not |
| 213 | * @return this |
| 214 | */ |
| 215 | Builder colorAware(boolean isColorAware); |
| 216 | |
| 217 | /** |
| 218 | * Assigns the unit to use for this policer. |
| 219 | * Defaults to MB/s. |
| 220 | * |
| 221 | * @param unit a unit |
| 222 | * @return this |
| 223 | */ |
| 224 | Builder withUnit(Unit unit); |
| 225 | |
| 226 | /** |
| 227 | * Assigns policer id and device id for this policer. |
| 228 | * |
| 229 | * @param policingResource the policing resource |
| 230 | * @return this |
| 231 | */ |
| 232 | Builder withPolicingResource(PolicingResource policingResource); |
| 233 | |
| 234 | /** |
| 235 | * Assigns token buckets for this policer. |
| 236 | * <p> |
| 237 | * Note: at least one token bucket |
| 238 | * </p> |
| 239 | * @param tokenBuckets the collection of token buckets |
| 240 | * @return this |
| 241 | */ |
| 242 | Builder withTokenBuckets(Collection<TokenBucket> tokenBuckets); |
| 243 | |
| 244 | /** |
| 245 | * Assigns description for this policer. |
| 246 | * Default is empty description. |
| 247 | * |
| 248 | * @param description the description |
| 249 | * @return this |
| 250 | */ |
| 251 | Builder withDescription(String description); |
| 252 | |
| 253 | /** |
| 254 | * Builds the policer based on the specified parameters |
| 255 | * when possible. |
| 256 | * |
| 257 | * @return a policer |
| 258 | */ |
| 259 | Policer build(); |
| 260 | } |
| 261 | |
| 262 | } |