100% found this document useful (1 vote)
572 views4 pages

Congestion Control Using Leaky Bucket Algorithm: Source Code

The document describes a Java program that simulates the Leaky Bucket algorithm for congestion control. The program takes in packet arrival times and sizes over a specified number of seconds, along with the bucket size and output rate. It then simulates the Leaky Bucket algorithm, tracking packets received, sent, left in the buffer, and dropped each second. The output shows the results of applying the algorithm to sample packet arrival data.

Uploaded by

DILIP GOKULAPATI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
572 views4 pages

Congestion Control Using Leaky Bucket Algorithm: Source Code

The document describes a Java program that simulates the Leaky Bucket algorithm for congestion control. The program takes in packet arrival times and sizes over a specified number of seconds, along with the bucket size and output rate. It then simulates the Leaky Bucket algorithm, tracking packets received, sent, left in the buffer, and dropped each second. The output shows the results of applying the algorithm to sample packet arrival data.

Uploaded by

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

6.

Congestion Control using Leaky Bucket algorithm

Source Code:
import java.util.*;
public class Leaky
{
static int min(int x,int y)
{
if(x<y)
return x;
else
return y;
}

public static void main(String[] args)


{
int drop=0,psent,nsec,cap,pleft=0,i,process;
int inp[]=new int[25];
Scanner sc=new Scanner(System.in);
System.out.println("Enter The Bucket Size\n");
cap= sc.nextInt();
System.out.println("Enter The Operation Rate\n");
process= sc.nextInt();
System.out.println("Enter The No. Of Seconds You Want To Stimulate\n");
nsec=sc.nextInt();
for(i=0;i<nsec;i++)
{
System.out.print("Enter The Size Of The Packet Entering at "+ i+1 + " sec");
inp[i] = sc.nextInt();
}
System.out.println("\nSecond | Packet Recieved | Packet Sent | Packet Left | Packet
Dropped|\n");
System.out.println("------------------------------------------------------------------------\n");
for(i=0;i<nsec;i++)
{
pleft+=inp[i];
if(pleft>cap)
{
drop=pleft-cap;
pleft=cap;
}
System.out.print(i+1);
System.out.print("\t\t"+inp[i]);
psent=min(pleft,process);
System.out.print("\t\t"+psent);
pleft=pleft-psent;
System.out.print("\t\t"+pleft);
System.out.print("\t\t"+drop);
drop=0;
System.out.println();
}

for(;pleft!=0;i++)
{
if(pleft>cap)
{
drop=pleft-cap;
pleft=cap;
}
System.out.print(i+1);
System.out.print("\t\t0");
psent=min(pleft,process);
System.out.print("\t\t"+psent);
pleft=pleft-psent;
System.out.print("\t\t"+pleft);
System.out.print("\t\t"+drop);
System.out.println();
}
}
}
Output:
1. 5 received – 2 sent = 3 left
2. 4 +3 =7 pkts  7-2 = 5 in buffer – 2 release = 3 left
3. 3 +3 = 6 pkts = 6-1= 5 , 1 drop

You might also like