Revision 574b2324 lib/tbf.c

View differences:

lib/tbf.c
10 10
#include "nest/bird.h"
11 11
#include "lib/timer.h"
12 12

  
13
void
14
tbf_update(struct tbf *f)
13
int
14
tbf_limit(struct tbf *f)
15 15
{
16
  bird_clock_t delta = now - f->timestamp;
16
  btime delta = current_time() - f->timestamp;
17 17

  
18
  if (delta == 0)
19
    return;
20

  
21
  f->timestamp = now;
18
  if (delta > 0)
19
  {
20
    u64 next = f->count + delta * f->rate;
21
    u64 burst = (u64) f->burst << 20;
22
    f->count = MIN(next, burst);
23
    f->timestamp += delta;
24
  }
22 25

  
23
  if ((0 < delta) && (delta < f->burst))
26
  if (f->count < 1000000)
24 27
  {
25
    u32 next = f->count + delta * f->rate;
26
    f->count = MIN(next, f->burst);
28
    f->drop++;
29
    return 1;
27 30
  }
28 31
  else
29
    f->count = f->burst;
32
  {
33
    f->count -= 1000000;
34
    f->drop = 0;
35
    return 0;
36
  }
30 37
}

Also available in: Unified diff