100% found this document useful (2 votes)
12K views

Leaky Bucket Program

This document contains a C program that implements the leaky bucket algorithm for congestion control. The program takes in parameters like bucket size, processing rate, and simulation time. It then accepts packet sizes entering each second, tracks the bucket level and processes packets at the given rate. Any packets exceeding the bucket size are dropped. The output displays seconds, incoming/outgoing packets, remaining packets and dropped packets over the simulation time.

Uploaded by

Praveen Reddy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
12K views

Leaky Bucket Program

This document contains a C program that implements the leaky bucket algorithm for congestion control. The program takes in parameters like bucket size, processing rate, and simulation time. It then accepts packet sizes entering each second, tracks the bucket level and processes packets at the given rate. Any packets exceeding the bucket size are dropped. The output displays seconds, incoming/outgoing packets, remaining packets and dropped packets over the simulation time.

Uploaded by

Praveen Reddy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Networks Lab

2010-2011

Progarm8. Write a program for Congestion control using the leaky bucket algorithm #include<stdio.h> int min(int x,int y) { if(x < y) { return x; } else return y; } int main() { int drop=0, mini, nsec, cap, count = 0; int i,inp[25],process; printf("Enter the Bucket Size:\n"); scanf("%d",&cap); printf("Enter the Processing Rate:\n"); scanf("%d",&process); printf("Enter The No. Of Seconds You Want To Stimulate:\n"); scanf("%d",&nsec);

Dept. of CS&E, BAE

Networks Lab

2010-2011

for(i=0;i<nsec;i++) { printf("Enter the Size of the Packet Entering at %d sec:\n",i+1); scanf("%d",&inp[i]); } printf("\nSecond|Packet Recieved|Packet Sent|Packet Left|Packet Dropped|\n"); printf("-------------------------------------------------------\n"); for(i=0;i<nsec;i++) { count+=inp[i]; if(count>cap) { drop=count-cap; count=cap; } printf("%d",i+1); printf("\t%d",inp[i]); mini=min(count,process); printf("\t\t\t\t%d",mini); count=count-mini; printf("\t\t\t\t%d",count); printf("\t\t\t\t%d\n",drop); drop=0; }

Dept. of CS&E, BAE

Networks Lab

2010-2011

for(;count!=0;i++) { if(count>cap) { drop=count-cap; count=cap; } printf("%d",i+1); printf("\t0"); mini=min(count,process); printf("\t\t%d",mini); count=count-mini; printf("\t\t%d",count); printf("\t\t%d\n",drop); } }

Dept. of CS&E, BAE

Networks Lab

2010-2011

Execution and Output: $ cc 8.c $ ./a.out

Enter the Bucket Size: 5 Enter the Processing Rate: 2 Enter The No. Of Seconds You Want To Stimulate: 3 Enter the Size of the Packet Entering at 1 sec: 5 Enter the Size of the Packet Entering at 2 sec: 4 Enter the Size of the Packet Entering at 3 sec: 3 Second 1 2 3 4 5 Packet Received 5 4 3 0 0 Packet Sent 2 2 2 2 1 Packet Left 3 3 3 1 0 Packet Dropped 0 2 1 0 0

Dept. of CS&E, BAE

Networks Lab

2010-2011

Dept. of CS&E, BAE

You might also like