alshabib | bc37196 | 2015-07-09 22:26:21 -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 | bc37196 | 2015-07-09 22:26:21 -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 | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Represents a band used within a meter. |
| 20 | */ |
| 21 | public interface Band { |
| 22 | |
Jayasree Ghosh | e7a240c | 2016-09-10 14:45:15 +0530 | [diff] [blame] | 23 | short MIN_PRECEDENCE = 0; |
| 24 | short MAX_PRECEDENCE = 255; |
| 25 | String ERR_MSG = "Precedence out of range"; |
| 26 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Specifies the type of band. |
| 29 | */ |
| 30 | enum Type { |
| 31 | /** |
| 32 | * Simple rate limiter which drops packets |
| 33 | * when the rate is exceeded. |
| 34 | */ |
| 35 | DROP, |
| 36 | |
| 37 | /** |
Aaron Kruglikov | a361310 | 2017-08-07 11:28:18 -0700 | [diff] [blame] | 38 | * Defines a simple DiffServ policer that remark |
Yuta HIGUCHI | 734e1e6 | 2016-09-07 09:12:20 -0700 | [diff] [blame] | 39 | * the drop precedence of the DSCP field in the |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 40 | * IP header of the packets that exceed the band |
| 41 | * rate value. |
| 42 | */ |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 43 | REMARK, |
| 44 | |
| 45 | /** |
Aaron Kruglikov | a361310 | 2017-08-07 11:28:18 -0700 | [diff] [blame] | 46 | * Defines an experimental meter band. |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 47 | */ |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 48 | EXPERIMENTAL, |
| 49 | |
| 50 | /** |
| 51 | * Defines a meter band with no action, used to mark |
| 52 | * packets internally in the pipeline, i.e. without |
| 53 | * modifying the packet headers. |
| 54 | */ |
| 55 | NONE, |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
| 59 | * The rate at which this meter applies. |
| 60 | * |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 61 | * @return the long value of the rate |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 62 | */ |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 63 | long rate(); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * The burst size at which the meter applies. |
| 67 | * |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 68 | * @return the long value of the size |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 69 | */ |
Jian Li | 5c41123 | 2015-12-16 15:29:16 -0800 | [diff] [blame] | 70 | Long burst(); |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Only meaningful in the case of a REMARK band type. |
| 74 | * indicates by which amount the drop precedence of |
| 75 | * the packet should be increase if the band is exceeded. |
| 76 | * |
| 77 | * @return a short value |
| 78 | */ |
Jian Li | 5c41123 | 2015-12-16 15:29:16 -0800 | [diff] [blame] | 79 | Short dropPrecedence(); |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * Signals the type of band to create. |
| 83 | * |
| 84 | * @return a band type |
| 85 | */ |
| 86 | Type type(); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 87 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Returns the packets seen by this band. |
| 90 | * |
| 91 | * @return a long value |
| 92 | */ |
| 93 | long packets(); |
| 94 | |
| 95 | /** |
| 96 | * Return the bytes seen by this band. |
| 97 | * |
| 98 | * @return a byte counter |
| 99 | */ |
| 100 | long bytes(); |
| 101 | |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 102 | interface Builder { |
| 103 | |
| 104 | /** |
| 105 | * Assigns a rate to this band. The units for this rate |
| 106 | * are defined in the encapsulating meter. |
| 107 | * |
| 108 | * @param rate a long value |
| 109 | * @return this |
| 110 | */ |
| 111 | Builder withRate(long rate); |
| 112 | |
| 113 | /** |
| 114 | * Assigns a burst size to this band. Only meaningful if |
| 115 | * the encapsulating meter is of burst type. |
| 116 | * |
| 117 | * @param burstSize a long value. |
| 118 | * @return this |
| 119 | */ |
| 120 | Builder burstSize(long burstSize); |
| 121 | |
| 122 | /** |
| 123 | * Assigns the drop precedence for this band. Only meaningful if |
| 124 | * the band is of REMARK type. |
| 125 | * |
| 126 | * @param prec a short value |
| 127 | * @return this |
| 128 | */ |
| 129 | Builder dropPrecedence(short prec); |
| 130 | |
| 131 | /** |
Yuta HIGUCHI | 734e1e6 | 2016-09-07 09:12:20 -0700 | [diff] [blame] | 132 | * Assigns the {@link Type} of this band. |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 133 | * |
| 134 | * @param type a band type |
| 135 | * @return this |
| 136 | */ |
| 137 | Builder ofType(Type type); |
| 138 | |
| 139 | /** |
| 140 | * Builds the band. |
| 141 | * |
| 142 | * @return a band |
| 143 | */ |
| 144 | Band build(); |
| 145 | |
| 146 | } |
| 147 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 148 | |
| 149 | } |