Token Bucket
Traffic regulator Receiver Sender Traffic regulator Goal: Traffic entering the network should comply to a given envelope
Traffic regulators Traffic exceeding the envelope is non-compliant. What do to with non-compliant traffic ? Buffer Traffic shaping Drop Traffic policing Allow, but assign low priority Traffic marking We focus on Traffic shapers © Jörg Liebeherr, 2006 ECE 1545
Traffic shapers Envelope Traffic shaper enforces that the departures D comply to a traffic envelope E Non-compliant traffic is stored in a FIFO buffer Buffered traffic is released as soon as allowed This type of shaper is called “Greedy Shaper” Envelope
Token Bucket Token Bucket is a traffic regulation mechanism to enforce that departures comply to the envelope Traffic Time interval b Slope r
Token Bucket Tokens are added at rate r up to a maximum size of TBmax
Token Bucket Assume: Packet can depart if enough tokens are available. Tokens are removed tokens when packet departs (Here: 10 tokens are needed)
Token Bucket Assume: Packet removes 10 tokens from buffer (Number of tokens is associated with packet size)
Token Bucket Packet must wait until enough tokens are available
Token Bucket (fluid flow version) For an analysis we work with a fluid flow version of the token bucket (Traffic can depart in arbitrary small chunks)
TBmax = b = 2 r = 1
TBmax = b = 2 r = 1 A+TB-B
Implementation
Implementation in Lab 2 (a+b) TokenBucket
Token Bucket in Lab 2 (a+b) TokenBucketReceiver (BR) TokenBucketSender (BS) if (buffer_is_empty && not(sendingInProgress) && enough_tokens_available) consume tokens; send packet; else add packet to buffer; If (buffer_is_not_empty) if (enough_tokens) consume tokens; sendingInProgress = true; remove packet from buffer; send packet; sendingInProgress = false; else get expected time when there will be enough tokens; sleep for this time; wait for packet to arrive to buffer;
Alternative implementation for Token Bucket? Idea: instead of counting tokens (and compute timestamps from tokens), work directly with timestamps VC : release time of packet (init: VC = 0) l : packet size now : current time TDTp : Target departure time of packet p b TokenBucketSender (BS) TokenBucketReceiver (BR) If (buffer_is_not_empty) if (TDThead_of_buffer ≤ now) sendingInProgress = true; remove packet from buffer; send packet; sendingInProgress = false; else sleep for now - TDThead_of_buffer ; wait for packet to arrive to buffer; VC = max {VC, now} + l/r; if ( buffer_is_empty && not(sendingInProgress) && VC - b/r ≤ now ) send packet; else Set TDTp = VC - b/r; add packet to buffer;
Peak Rate Constrained Token Bucket Adds a constraint on the maximum (“peak”) rate of traffic: Is implemented with 2 token buckets in series. Traffic Slope r b Slope P Time interval