Token Bucket Implementation

JB Lorenzo
Nov 29, 2014 · 2 min read

We were tasked to add token bucket policing in our network simulator.

One experiment was performed, one is for placing the token bucket before the queues.

For the experiment, the network is arranged in the following order:

  • TCP traffic generator — generates traffic with TCP like behaviour.
  • Token bucket — immediately forwards packets when it receives it, and has sufficient tokens. Otherwise, drops the packet
  • Packet Marking — forwards packets to corresponding queue, depending on the packet’s class
  • FIFO queues — two queues, one high priority queue and one low priority queue.
  • Scheduler — performs round robin/priority scheduling on the queues

I am using the following set of parameters and results for the first experiment:

Parameters:
total packets to send = 250 packets
scheduler rate = 30 packets/sec
FIFO buffer size = 100 packets
high priority packets = 50% chance
token bucket size = 10 packets
token generation rate = 5 tokens/second
scheduler mode = round robin

Results:
total packets to send = 11182 packet
speed = 4.91 packets/sec
total time = 50.895742 secs
dropped packets = 10930 packets (97.75%)

changing token generation rate to 30 tokens/second:

Parameters:
total packets to send = 250 packets
scheduler rate = 30 packets/sec
FIFO buffer size = 100 packets
high priority packets = 50% chance
token bucket size = 10 packets
token generation rate = 30 tokens/second
scheduler mode = round robin

Results:
total packets sent = 715 packets
speed = 19.87 packets/sec
total time = 12.546619 secs
dropped packets = 383 packets (53.57%)

As expected token bucket limits the overall speed of the system. If placed just after the generator, it limits the speed of all the classes.

    JB Lorenzo

    Written by

    📱 at OLX Group, Berlin. He/Him.