2 * Copyright (c) 2012 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef TOKEN_BUCKET_H
18 #define TOKEN_BUCKET_H 1
24 /* Configuration settings. */
25 unsigned int rate; /* Tokens added per millisecond. */
26 unsigned int burst; /* Max cumulative tokens credit. */
29 unsigned int tokens; /* Current number of tokens. */
30 long long int last_fill; /* Last time tokens added. */
33 #define TOKEN_BUCKET_INIT(RATE, BURST) { RATE, BURST, 0, LLONG_MIN }
35 void token_bucket_init(struct token_bucket *,
36 unsigned int rate, unsigned int burst);
37 void token_bucket_set(struct token_bucket *,
38 unsigned int rate, unsigned int burst);
39 bool token_bucket_withdraw(struct token_bucket *, unsigned int n);
40 void token_bucket_wait(struct token_bucket *, unsigned int n);
42 #endif /* token-bucket.h */