#include <rate-limit-strategy.h>
Inheritance diagram for TokenBucketRateLimiter:


Public Member Functions | |
| TokenBucketRateLimiter () | |
| int | rateLimit (Packet *p, double estRate, double targetRate, int mine, int lowDemand) |
| void | reset () |
Public Attributes | |
| double | bucket_depth_ |
| double | tbucket_ |
| double | time_last_token_ |
| double | total_passed_ |
| double | total_dropped_ |
|
|
Definition at line 214 of file rate-limit-strategy.cc. References bucket_depth_, Scheduler::clock(), DEFAULT_BUCKET_DEPTH, Scheduler::instance(), tbucket_, time_last_token_, total_dropped_, and total_passed_.
00214 {
00215
00216 bucket_depth_ = DEFAULT_BUCKET_DEPTH;
00217 tbucket_ = bucket_depth_;
00218 total_passed_ = 0.0;
00219 total_dropped_ = 0.0;
00220 time_last_token_ = Scheduler::instance().clock();
00221 }
|
Here is the call graph for this function:

|
||||||||||||||||||||||||
|
Implements RateLimiter. Definition at line 224 of file rate-limit-strategy.cc. References bucket_depth_, Scheduler::clock(), HDR_CMN, Scheduler::instance(), hdr_cmn::size_, tbucket_, time_last_token_, total_dropped_, and total_passed_.
00224 {
00225
00226 hdr_cmn* hdr = HDR_CMN(p);
00227 double now = Scheduler::instance().clock();
00228 double time_elapsed = now - time_last_token_;
00229
00230 //printf("TB: now = %g last_sent = %g elapsed = %g\n", now, time_last_token_, time_elapsed);
00231 tbucket_ += (time_elapsed * targetRate)/8.0;
00232 time_last_token_ = now;
00233
00234 if (tbucket_ > bucket_depth_)
00235 tbucket_ = bucket_depth_; /* never overflow */
00236
00237 //printf("TB: tbucket_ = %g pktSize = %g\n", tbucket_, (double)hdr->size_);
00238 //printf("TB: in = %g out = %g\n", total_passed_, total_dropped_);
00239
00240 if ((double)hdr->size_ < tbucket_ || (mine && lowDemand) ) {
00241 tbucket_ -= hdr->size_;
00242 total_passed_ += (double) hdr->size_;
00243 //printf("Passed Packet in Rate Limiter\n");
00244 return 0;
00245 }
00246 else {
00247 total_dropped_ += (double) hdr->size_;
00248 // printf("Dropped Packet in Rate Limiter\n");
00249 return 1;
00250 }
00251 }
|
Here is the call graph for this function:

|
|
Implements RateLimiter. Definition at line 262 of file rate-limit-strategy.cc. References Scheduler::clock(), Scheduler::instance(), tbucket_, time_last_token_, total_dropped_, and total_passed_.
00262 {
00263 total_dropped_ = 0;
00264 total_passed_ = 0;
00265 tbucket_ = 0;
00266 time_last_token_ = Scheduler::instance().clock();
00267 }
|
Here is the call graph for this function:

|
|
Definition at line 102 of file rate-limit-strategy.h. Referenced by rateLimit(), and TokenBucketRateLimiter(). |
|
|
Definition at line 105 of file rate-limit-strategy.h. Referenced by rateLimit(), reset(), and TokenBucketRateLimiter(). |
|
|
Definition at line 106 of file rate-limit-strategy.h. Referenced by rateLimit(), reset(), and TokenBucketRateLimiter(). |
|
|
Definition at line 108 of file rate-limit-strategy.h. Referenced by rateLimit(), reset(), and TokenBucketRateLimiter(). |
|
|
Definition at line 107 of file rate-limit-strategy.h. Referenced by rateLimit(), reset(), and TokenBucketRateLimiter(). |
1.3.3