0% found this document useful (0 votes)
34 views2 pages

Leaky Bucket

The program implements a leaky bucket algorithm for congestion control. It takes user input for bucket size, outgoing rate, number of packets, and packet sizes. It tracks the incoming and outgoing packets, calculating if packets will exceed the bucket size and be dropped, or if the bucket size is within limits. The buffer size is continuously updated and output.

Uploaded by

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

Leaky Bucket

The program implements a leaky bucket algorithm for congestion control. It takes user input for bucket size, outgoing rate, number of packets, and packet sizes. It tracks the incoming and outgoing packets, calculating if packets will exceed the bucket size and be dropped, or if the bucket size is within limits. The buffer size is continuously updated and output.

Uploaded by

UJWAL R GOWDA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

12. Write a program for congestion control using leaky bucket algorithm.

import java.util.Scanner;
public class LeakyBucket {

public static void main(String[] args) throws InterruptedException {

int n, incoming, outgoing, store=0, bucketsize;


Scanner scan = new Scanner(System.in);
System.out.println("Enter bucket size, outgoing rate, number of inputs and incoming size");

bucketsize = scan.nextInt();
outgoing = scan.nextInt();
n = scan.nextInt();
incoming = scan.nextInt();

while(n!=0)
{
System.out.println("Incoming size is " + incoming);
if(incoming <= (bucketsize-store))
{
store+=incoming;
System.out.println("Bucket buffer size is " + store +" out of " + bucketsize);
}
else
{
System.out.println("Packet loss : " + (incoming-(bucketsize-store)));

store=bucketsize;

System.out.println("Bucket buffer size is " + store +" out of " + bucketsize);


}

store-=outgoing;

System.out.println("After outgoing: " + store + " packets left out of " + bucketsize
+ "in buffer");

n--;
Thread.sleep(3000);
}
scan.close();
}
}
Output:

You might also like