When too many packets are present in the network it causes packet delay and loss of packet which degrades the performance of the system. This situation is called congestion.
The network layer and transport layer share the responsibility for handling congestions. One of the most effective ways to control congestion is trying to reduce the load that transport layer is placing on the network. To maintain this, network and transport layers have to work together.
With too much traffic, performance drops sharply.
There are two types of Congestion control algorithms, which are explained below −
It mainly controls the total amount and the rate of the traffic sent to the network.
Step 1 − Let us imagine a bucket with a small hole at the bottom where the rate at which water is poured into the bucket is not constant and can vary but it leaks from the bucket at a constant rate.
Step 2 − So (up to water is present in the bucket), the rate at which the water leaks does not depend on the rate at which the water is input to the bucket.
Step 3 − If the bucket is full, additional water that enters into the bucket that spills over the sides and is lost.
Step 4 − Thus the same concept applied to packets in the network. Consider that data is coming from the source at variable speeds. Suppose that a source sends data at 10 Mbps for 4 seconds. Then there is no data for 3 seconds. The source again transmits data at a rate of 8 Mbps for 2 seconds. Thus, in a time span of 8 seconds, 68 Mb data has been transmitted.
That’s why a leaky bucket algorithm is used. The data flow would be 8 Mbps for 9 seconds. Thus, the constant flow is maintained.
Token bucket algorithms are used to overcome the problems that we are facing using leaky bucket algorithms. The leaky bucket algorithm’s main problem is that it cannot control burst data, as it only allows average rate i.e. constant rate of data flow and also it does not consider idle time of host.
Step 1 − For example, if the host was idle for 12 seconds and now it is willing to send data at a very high speed for another 12 seconds, the total data transmission will be divided into 24 seconds and average data rate will be maintained.
Step 2 − The host has no advantage of sitting idle for 12 seconds. Thus, we adopted a token bucket algorithm.
Step 3 − Hence, the token bucket algorithm is modification of leaky bucket in which leaky bucket contains tokens.
Step 4 − In this a token(s) are generated at every clock tick. For every packet to be transmitted, the system must remove token(s) from the bucket. Thus, the token bucket algorithm allows idle hosts to accumulate credit for the future in the form of tokens.
For example, if a system generates 10 tokens in one clock tick and the host is idle for 10 ticks. The bucket will contain 10, 00 tokens. Now, suppose the host wants to send burst data, it consumes all 10, 00 tokens at once for sending 10, 00 cells or bytes. Thus, the host can be able to send burst data as long as the bucket is not empty.