blob: a86466b0cb4183847352d19194008c3150153693 [file] [log] [blame]
Pier Luigi09220c22017-09-14 22:00:30 +02001/*
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
17package org.onosproject.net.behaviour.trafficcontrol;
18
19import 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
27public 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 /**
39 * Action applied to the exceeding traffic.
40 * Action depends on the tocken bucket type
41 */
42 enum Action {
43 /**
44 * Drop action.
45 */
46 DROP,
47 /**
48 * Marking increases DSCP drop precedence.
49 */
50 DSCP_PRECEDENCE,
51 /**
52 * Marking sets DSCP class.
53 */
54 DSCP_CLASS,
55 /**
56 * Marking sets Drop Elegible Indicator.
57 */
58 DEI
59 }
60
61 /**
62 * Rate of traffic subject to the SLAs
63 * specified for this token bucket.
64 *
65 * @return the rate value
66 */
67 long rate();
68
69 /**
70 * Maximum burst size subject to the SLAs
71 * specified for this token bucket.
72 *
73 * @return the burst size in bytes
74 */
75 long burstSize();
76
77 /**
78 * Action used by this token bucket
79 * for the exceeding traffic.
80 *
81 * @return the type of action
82 */
83 Action action();
84
85 /**
86 * Dscp value, it meaning depends on the used marking.
87 *
88 * @return the dscp value for this token bucket
89 */
90 short dscp();
91
92 /**
93 * Stats which reports how many packets have been
94 * processed so far.
95 *
96 * Availability of this information depends on the
97 * technology used for the implementation of the policer.
98 *
99 * @return the processed packets
100 */
101 long processedPackets();
102
103 /**
104 * Stats which reports how many bytes have been
105 * processed so far.
106 *
107 * Availability of this information depends on the
108 * technology used for the implementation of the policer.
109 *
110 * @return the processed bytes
111 */
112 long processedBytes();
113
114 /**
115 * Token bucket builder.
116 */
117 interface Builder {
118
119 /**
120 * Assigns the rate to this token bucket.
121 *
122 * @param rate a rate value
123 * @return this
124 */
125 Builder withRate(long rate);
126
127 /**
128 * Assigns the burst size to this token bucket.
129 * Default to 2 * 1500 bytes.
130 *
131 * @param burstSize a burst size
132 * @return this
133 */
134 Builder withBurstSize(long burstSize);
135
136 /**
137 * Assigns the action to this token bucket.
138 * <p>
139 * Note: mandatory setter for this builder
140 * </p>
141 * @param action an action
142 * @return this
143 */
144 Builder withAction(Action action);
145
146 /**
147 * Assigns the dscp value to this token bucket.
148 *
149 * @param dscp a dscp value
150 * @return this
151 */
152 Builder withDscp(short dscp);
153
154 /**
155 * Builds the token bucket based on the specified
156 * parameters when possible.
157 *
158 * @return a token bucket
159 */
160 TokenBucket build();
161
162 }
163}