0% found this document useful (0 votes)
12 views

Lab Program 12

Uploaded by

shilpakv2024
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab Program 12

Uploaded by

shilpakv2024
Copyright
© © All Rights Reserved
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 leaky {

static int bucketSize=500;

static void bktInput(int a,int b) {

if(a>bucketSize)

System.out.printf("\n\t\t Bucket overflow, Hence Packet


discarded");

else {

while(a>b){

System.out.printf("\n\t\t %d bytes sent",b);

a-=b;
}

if (a>0)

System.out.printf("\n\t\t %d bytes sent \t",a);

System.out.printf("\n\t\t Packet sent successfully");


}
}

public static void main(String args[])


{
int pktSize;
int size[]=new int[10];
int i;

Scanner t;

t=new Scanner(System.in);

System.out.println("Enter the output rate.....");

int op=t.nextInt();

t=new Scanner(System.in);

System.out.println("Enter the number of packets.....");

int n=t.nextInt();

t=new Scanner(System.in);
System.out.println("Enter the size of each packets....");
for(i=1;i<=n;i++)
{

size[i]=t.nextInt();
}

t=new Scanner(System.in);

for(i=1;i<=n;i++){

System.out.printf("\n Packet no %d",i);

bktInput(size[i],op);
}

OUTPUT

Enter the output rate.....

25

Enter the number of packets.....

Enter the size of each packets....


600
100
50

Packet no 1
Bucket overflow, Hence Packet discarded

Packet no 2
25 bytes sent
25 bytes sent
25 bytes sent
25 bytes sent
Packet sent successfully
Packet no 3
25 bytes sent
25 bytes sent
Packet sent successfully

You might also like