Computer networks
Computer networks
CN LAB PRESENTATION
AIM:
A program for congestion control using leaky bucket algorithm
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
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]);
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]);
}
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: