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

Computer networks

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)
7 views9 pages

Computer networks

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
You are on page 1/ 9

SHADAN WOMEN’S COLLEGE OF

ENGINEERING AND TECHNOLOGY

CN LAB PRESENTATION

NAME : ZUNAIRA SANOBER


HALL.NO : 22L51A05C8
BRANCH :CSE C
YEAR : B.TECH 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
1.Input:
•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.

2.Working:
•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.

3.Output:
•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

You might also like