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 | |
| 21 | /** |
| 22 | * Generic abstraction for a token bucket which can mark and/or discard |
| 23 | * traffic. Each token bucket in ONOS is made up of a set of attributes which |
| 24 | * identifies the type. |
| 25 | */ |
| 26 | @Beta |
| 27 | public interface TokenBucket { |
| 28 | |
| 29 | /** |
| 30 | * Upper bound for DSCP. |
| 31 | */ |
| 32 | short MAX_DSCP = 255; |
| 33 | /** |
| 34 | * Lower bound for DSCP. |
| 35 | */ |
| 36 | short MIN_DSCP = 0; |
| 37 | |
| 38 | /** |
Pier Luigi | 256d92b | 2017-11-15 13:22:15 +0100 | [diff] [blame] | 39 | * Token bucket type. |
| 40 | */ |
| 41 | enum Type { |
| 42 | /** |
| 43 | * Committed rate. |
| 44 | */ |
| 45 | COMMITTED, |
| 46 | /** |
| 47 | * Excess rate. |
| 48 | */ |
| 49 | EXCESS, |
| 50 | /** |
| 51 | * Peak rate. |
| 52 | */ |
| 53 | PEAK |
| 54 | } |
| 55 | |
| 56 | /** |
Pier Luigi | 09220c2 | 2017-09-14 22:00:30 +0200 | [diff] [blame] | 57 | * Action applied to the exceeding traffic. |
Pier Luigi | 256d92b | 2017-11-15 13:22:15 +0100 | [diff] [blame] | 58 | * Action in general depends on the token bucket type. |
Pier Luigi | 09220c2 | 2017-09-14 22:00:30 +0200 | [diff] [blame] | 59 | */ |
| 60 | enum Action { |
| 61 | /** |
| 62 | * Drop action. |
| 63 | */ |
| 64 | DROP, |
| 65 | /** |
| 66 | * Marking increases DSCP drop precedence. |
| 67 | */ |
| 68 | DSCP_PRECEDENCE, |
| 69 | /** |
| 70 | * Marking sets DSCP class. |
| 71 | */ |
| 72 | DSCP_CLASS, |
| 73 | /** |
| 74 | * Marking sets Drop Elegible Indicator. |
| 75 | */ |
| 76 | DEI |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Rate of traffic subject to the SLAs |
| 81 | * specified for this token bucket. |
| 82 | * |
| 83 | * @return the rate value |
| 84 | */ |
| 85 | long rate(); |
| 86 | |
| 87 | /** |
| 88 | * Maximum burst size subject to the SLAs |
| 89 | * specified for this token bucket. |
| 90 | * |
| 91 | * @return the burst size in bytes |
| 92 | */ |
| 93 | long burstSize(); |
| 94 | |
| 95 | /** |
| 96 | * Action used by this token bucket |
| 97 | * for the exceeding traffic. |
| 98 | * |
| 99 | * @return the type of action |
| 100 | */ |
| 101 | Action action(); |
| 102 | |
| 103 | /** |
| 104 | * Dscp value, it meaning depends on the used marking. |
| 105 | * |
| 106 | * @return the dscp value for this token bucket |
| 107 | */ |
| 108 | short dscp(); |
| 109 | |
| 110 | /** |
Pier Luigi | 256d92b | 2017-11-15 13:22:15 +0100 | [diff] [blame] | 111 | * Token bucket type. |
| 112 | * |
| 113 | * @return the token bucket type |
| 114 | */ |
| 115 | Type type(); |
| 116 | |
| 117 | /** |
Pier Luigi | 09220c2 | 2017-09-14 22:00:30 +0200 | [diff] [blame] | 118 | * Stats which reports how many packets have been |
| 119 | * processed so far. |
| 120 | * |
| 121 | * Availability of this information depends on the |
| 122 | * technology used for the implementation of the policer. |
| 123 | * |
| 124 | * @return the processed packets |
| 125 | */ |
| 126 | long processedPackets(); |
| 127 | |
| 128 | /** |
| 129 | * Stats which reports how many bytes have been |
| 130 | * processed so far. |
| 131 | * |
| 132 | * Availability of this information depends on the |
| 133 | * technology used for the implementation of the policer. |
| 134 | * |
| 135 | * @return the processed bytes |
| 136 | */ |
| 137 | long processedBytes(); |
| 138 | |
| 139 | /** |
| 140 | * Token bucket builder. |
| 141 | */ |
| 142 | interface Builder { |
| 143 | |
| 144 | /** |
| 145 | * Assigns the rate to this token bucket. |
| 146 | * |
| 147 | * @param rate a rate value |
| 148 | * @return this |
| 149 | */ |
| 150 | Builder withRate(long rate); |
| 151 | |
| 152 | /** |
| 153 | * Assigns the burst size to this token bucket. |
| 154 | * Default to 2 * 1500 bytes. |
| 155 | * |
| 156 | * @param burstSize a burst size |
| 157 | * @return this |
| 158 | */ |
| 159 | Builder withBurstSize(long burstSize); |
| 160 | |
| 161 | /** |
| 162 | * Assigns the action to this token bucket. |
| 163 | * <p> |
| 164 | * Note: mandatory setter for this builder |
| 165 | * </p> |
| 166 | * @param action an action |
| 167 | * @return this |
| 168 | */ |
| 169 | Builder withAction(Action action); |
| 170 | |
| 171 | /** |
| 172 | * Assigns the dscp value to this token bucket. |
| 173 | * |
| 174 | * @param dscp a dscp value |
| 175 | * @return this |
| 176 | */ |
| 177 | Builder withDscp(short dscp); |
| 178 | |
| 179 | /** |
Pier Luigi | 256d92b | 2017-11-15 13:22:15 +0100 | [diff] [blame] | 180 | * Assigns the type to this token bucket. |
| 181 | * <p> |
| 182 | * Note: mandatory setter for this builder |
| 183 | * </p> |
| 184 | * @param type the type |
| 185 | * @return this |
| 186 | */ |
| 187 | Builder withType(Type type); |
| 188 | |
| 189 | /** |
Pier Luigi | 09220c2 | 2017-09-14 22:00:30 +0200 | [diff] [blame] | 190 | * Builds the token bucket based on the specified |
| 191 | * parameters when possible. |
| 192 | * |
| 193 | * @return a token bucket |
| 194 | */ |
| 195 | TokenBucket build(); |
| 196 | |
| 197 | } |
| 198 | } |