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

Leaky Bucket

Uploaded by

Khyathi Kiran
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)
19 views2 pages

Leaky Bucket

Uploaded by

Khyathi Kiran
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

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

import java.util.Scanner;
public class LeakyBucket {
public static void main(String args[]) {
int n, outgoing, store, bucketSize;
int incoming[];
Scanner scan = new Scanner(System.in);
System.out.println("Enter number of inputs");
n = scan.nextInt();
incoming = new int[n];
for(int i = 0 ;i< n ; i++) {
System.out.println("Enter incoming packet size "+(i+1));
incoming[i] = scan.nextInt();
}
System.out.println("Enter bucket size");
bucketSize = scan.nextInt();
System.out.println("Enter outgoing rate");
outgoing = scan.nextInt();
store = 0;
int i = 0;
System.out.println("Packet Recieved | Packet Dropped | Packet Sent | Packet Left");
do {
int pktReceived = 0, pktSent = 0,pktDrop = 0;
if(i < n) {
pktReceived = incoming[i];
if(pktReceived <= (bucketSize - store)) {
store += pktReceived ;
}
else {
pktDrop = pktReceived -(bucketSize - store);
store = bucketSize;
}
}
if(store > outgoing) {
store -= outgoing;
pktSent = outgoing;
}
else {
pktSent = store;
store = 0;
}
System.out.println(pktReceived
+"\t\t"+pktDrop+"\t\t"+pktSent+"\t\t"+store);
try {
Thread.sleep(2000);
}
catch(Exception e) {
e.printStackTrace();
}
i++;
}while(store != 0 || i < n);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy