Traffic Policing and Shaping
(CHECK THE TEXTBOOK ONCE AGAIN PG. 410)
Traffic Policing
Measure the byte rate of arriving packets If the value is above the threshold, drop the traffic $$Packetarrivaltime-previouspacketarrivaltime\cdot police/8$$
Traffic Shaping
More forgiving Buffers all the excess packets to give a constant stream of traffic May drop packet (if the bucket is full).
| Feature | Traffic Policing | Traffic Shaping |
|---|---|---|
| Action | Drops or remarks excess packets immediately. | Buffers (delays) excess packets in a queue. |
| Goal | Strict limit enforcement. "Do not pass X Mbps." | Smoother flow. "Send at X Mbps average." |
| Effect on Traffic | Creates a "saw-tooth" pattern (clipped peaks). | Creates a smooth, constant output stream. |
| Direction | Inbound (Ingress) and Outbound (Egress). | Typically Outbound (Egress) only (you can't buffer what hasn't arrived). |
| Analogy | A bouncer at a club who kicks people out once capacity is reached. | A funnel: you pour water in quickly, but it flows out slowly and steadily. |
| ### The Algorithms |
The Leaky Bucket Algorithm
-
Concept: No matter how fast water (packets) enters the bucket, it leaks out of the hole at a constant rate.
-
Mechanism:
-
If traffic arrives faster than the leak rate, it fills up the bucket (buffer).
-
If the bucket is full, new packets "spill over" and are lost (dropped).
-
-
Result: It turns bursty traffic into a rigid, constant stream.
-
Constraint: It is very strict. It does not allow any burstiness, even if the network is idle.
The Token Bucket Algorithm
This is the more flexible alternative widely used in modern ISPs and OS scheduling.
-
Concept: Instead of a hole leaking water, you have a bucket that fills with tokens at a constant rate.
-
Mechanism:
-
To send a packet, you must "pay" a token from the bucket.
-
If the bucket has accumulated tokens (because you were silent for a while), you can spend them all at once to send a burst of traffic.
-
If the bucket is empty, you must wait for new tokens to arrive.
-
-
Result: It allows for a specific Average Rate (token generation speed) while permitting a controlled Burst Size (bucket capacity).
$${\displaylines Rfill=Ri-Rout\ B=Rfill\cdot BurstDuration}$$
Question
A computer outputs packets at a certain bursty rate (e.g., peak of 100 MB/sec), but the leaky bucket limits the output to a steady 20 MB/sec. You have to calculate how long the queue (bucket) needs to be to avoid dropping packets.
Question
A token bucket scheme is used for traffic shaping. A new token is put into the bucket every 5μsec. Each token is good for one short packet, which contains 48 bytes of data. What is the maximum sustainable data rate?