0% found this document useful (0 votes)
36 views9 pages

Leaky Bucket Algorithm for Congestion Control

The document presents a program for congestion control using the Leaky Bucket Algorithm, which regulates data flow in computer networks. It includes an explanation of the algorithm's steps, a C program implementation, and a description of the program's input, working, and output. A sample input and output table is also provided to illustrate the algorithm's functionality.

Uploaded by

zunairasanober
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views9 pages

Leaky Bucket Algorithm for Congestion Control

The document presents a program for congestion control using the Leaky Bucket Algorithm, which regulates data flow in computer networks. It includes an explanation of the algorithm's steps, a C program implementation, and a description of the program's input, working, and output. A sample input and output table is also provided to illustrate the algorithm's functionality.

Uploaded by

zunairasanober
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

SHADAN WOMEN’S COLLEGE OF

ENGINEERING AND TECHNOLOGY

CN LAB PRESENTATION

NAME : ZUNAIRA SANOBER


[Link] : 22L51A05C8
BRANCH :CSE C
YEAR : [Link] 3RD YEAR 2ND SEM
Congestion Control Using Leaky Bucket
Algorithm
The Leaky Bucket Algorithm is a widely used technique for
congestion control in computer networks. It helps regulate data
flow by controlling the rate at which packets are sent into the
network, ensuring that the network does not get overwhelmed
with traffic. This method is inspired by the concept of water
dripping out of a leaky bucket at a constant rate.

Steps in the Leaky Bucket Algorithm


1. Incoming packets are added to the bucket.
2. If adding a packet exceeds the bucket's capacity, the packet
is dropped.
3. Packets are transmitted from the bucket at a fixed rate (leak
rate), ensuring a steady flow.
4. The algorithm repeats for every incoming packet and every
time unit.
WRITE A PROGRAM FOR CONGESTION CONTROL USING LEAKY
BUCKET ALGORITHM:

AIM:
A program for congestion control using leaky bucket algorithm

PROGRAM:
#include <stdio.h>
#include <stdlib.h>

void leakyBucket(int incomingPacket[], int n, int bucketSize, int


outputRate) {
int bucketContent = 0; // Tracks current bucket content

printf("Time\tIncoming\tBucket Content\tOutgoing\tDropped\
n");
for (int i = 0; i < n; i++) {
printf("%d\t", i + 1); // Display time
// Incoming packet at current time
printf("%d\t\t", incomingPacket[i]);

// Add incoming packet to bucket


if (bucketContent + incomingPacket[i] <= bucketSize) {
bucketContent += incomingPacket[i];
} else {
// Packet is dropped if bucket overflows
int dropped = (bucketContent + incomingPacket[i]) - bucketSize;
printf("%d\t\t", bucketSize);
printf("%d\t\t%d\n", outputRate, dropped);
bucketContent = bucketSize; // Bucket remains at maximum
capacity
continue;
}

// Display bucket content


printf("%d\t\t", bucketContent);
// Outgoing packet at fixed output rate
if (bucketContent >= outputRate) {
bucketContent -= outputRate;
printf("%d\t\t0\n", outputRate); // No packets
dropped
} else {
printf("%d\t\t0\n", bucketContent); // All packets in
bucket are sent
bucketContent = 0;
}
}
}

int main() {
int bucketSize, outputRate, n;

// User inputs
printf("Enter the bucket size: ");
scanf("%d", &bucketSize);
printf("Enter the output rate: ");
scanf("%d", &outputRate);
printf("Enter the number of incoming packets: ");
scanf("%d", &n);
int incomingPacket[n];
printf("Enter the incoming packets (space-
separated):\n");
for (int i = 0; i < n; i++) {
scanf("%d", &incomingPacket[i]);
}

// Call the leaky bucket algorithm


leakyBucket(incomingPacket, n, bucketSize,
outputRate);

return 0;
}
Explanation of the Program
[Link]:
•bucketSize: The maximum capacity of the bucket (buffer).
•outputRate: The constant rate at which packets are
transmitted from the bucket.
•incomingPacket: An array of incoming packet sizes for each
time unit.

[Link]:
•At each time unit:
•The program attempts to add the incoming packet to the bucket.
•If adding the packet exceeds the bucket size, the excess packets are
dropped.
•Packets are transmitted from the bucket at the specified output rate.
•The program tracks and displays the bucket content, outgoing packets, and
dropped packets at each time step.

[Link]:
•A table showing the time, incoming packets, bucket content, outgoing
packets, and dropped packets.
Sample Input/Output
INPUT:
Enter the bucket size: 10
Enter the output rate: 4
Enter the number of incoming packets: 5
Enter the incoming packets (space-separated):
58216

OUTPUT:

Time Incoming Bucket Content Outgoing Dropped


1 5 5 4 0
2 8 9 4 0
3 2 7 4 0
4 1 4 4 0
5 6 6 4 0
THANK YOU

Common questions

Powered by AI

The Leaky Bucket Algorithm handles bursty traffic by smoothing the bursts, allowing data to be sent at a consistent output rate. During a traffic burst, packets would fill the bucket until it reaches capacity; any additional packets would be dropped, leading to packet loss. This smoothing is critical to managing congested networks, but it can be inefficient if bursts occur frequently or if packet loss during bursts becomes significant, suggesting potential for optimization or integration with adaptive mechanisms to better handle such traffic patterns .

In the Leaky Bucket Algorithm, as packets arrive, they are added to a buffer (the bucket). If the buffer has enough space, incoming packets are added until the bucket is full. When the buffer is full, any additional incoming packets are dropped. Packets are then transmitted out of the buffer at a fixed rate, as defined by the output rate. This allows for a steady and constant packet flow, preventing congestion and ensuring network stability .

The provided program ensures the Leaky Bucket Algorithm operates effectively through several steps: it initializes the bucket content to track the current buffer; it reads incoming packets each time unit, checking if adding them exceeds the bucket capacity and dropping excess when necessary; it outputs packets at the specified rate, updating the bucket content accordingly; and it regularly displays the bucket's content, outgoing packets, and dropped packets, allowing continuous monitoring and diagnostics to optimize congestion control .

The Leaky Bucket Algorithm ensures a steady flow of data by allowing packets to be added to the bucket up to its maximum capacity and leaked out at a constant output rate. This consistent rate prevents sudden bursts of data that can lead to congestion. If this steady flow is not maintained, it could result in network congestion, leading to packet loss, increased latency, and decreased overall network performance. The algorithm helps mitigate these risks by controlling the packet flow rate .

The output rate in the Leaky Bucket Algorithm is crucial as it determines the steady flow rate of packets sent from the bucket to the network. It ensures that packets are transmitted consistently, which helps manage data flow and prevent surges that could cause congestion. The algorithm's effectiveness relies on balancing this rate with the bucket's capacity to optimize throughput and minimize packet loss while preventing network overload .

The bucket content in the Leaky Bucket algorithm represents the current amount of data (packets) held within the buffer at any given time. It is important because it indicates how many packets are ready for transmission at the specified output rate. By tracking the bucket content, the algorithm can manage the flow of data into the network, ensure packets are sent at a manageable rate, and prevent overflow conditions where packets would need to be dropped .

The key parameters a user must define to run the Leaky Bucket Algorithm include the bucket size, the output rate, and the incoming packet sizes for each time unit. The bucket size determines the maximum buffer capacity, influencing how many packets can be handled at once before being dropped. The output rate controls the speed at which packets are transmitted, affecting how well the algorithm can manage data flow without causing congestion. Incoming packet sizes directly impact how quickly the bucket fills, influencing drop rates during high traffic periods .

When incoming packets exceed the bucket's capacity in the Leaky Bucket Algorithm, the excess packets are dropped. This is done to prevent the network from becoming congested. The algorithm ensures that the amount in the bucket never exceeds its maximum capacity by discarding packets that try to overflow the bucket, thus maintaining network stability .

The Leaky Bucket Algorithm remains effective in modern network environments for controlling data flow and preventing congestion, especially in scenarios where consistent data rates are required. However, compared to its original design purposes, modern networks often deal with more dynamic and high-throughput traffic patterns that may require more sophisticated algorithms. While the Leaky Bucket ensures simplicity and reliability, its rigid output rate can be less adaptable to varying traffic demands, highlighting the need for complementary techniques like the Token Bucket Algorithm that allows for burst tolerance .

The primary objective of using the Leaky Bucket Algorithm in network congestion control is to regulate data flow by controlling the rate at which packets are sent into a network, thereby ensuring that the network does not get overwhelmed with traffic. This is achieved by allowing packets to leave the bucket at a constant rate, similar to water dripping from a leaky bucket, which helps maintain a steady flow and prevents congestion .

You might also like