-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLeakyBucket.java
More file actions
56 lines (51 loc) · 1.97 KB
/
LeakyBucket.java
File metadata and controls
56 lines (51 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
public class LeakyBucket
{
public static void main(String [] args)
{
Scanner PD = new Scanner(System.in);
int no_groups, bucket_size;
System.out.println("Enter the bucket size");
bucket_size=PD.nextInt();
System.out.println("Enter the no of groups");
no_groups=PD.nextInt();
int no_packets [] = new int[no_groups];
int in_bw [] = new int[no_groups];
int out_bw, regd_bw = 0, tot_packets = 0;
for(int i=0;i<no_groups;i++)
{
System.out.println("Enter the no of packets for group "+(i+1)+"\t");
no_packets[i] = PD.nextInt();
System.out.println("Enter the input bandwidth for group "+(i+1));
in_bw[i] = PD.nextInt();
if((tot_packets)+no_packets[i] <= bucket_size)
{
tot_packets += no_packets[i];
}
else
{
do
{
System.out.println("Bucket overflow");
System.out.println("Enter the values less than "+ (bucket_size - tot_packets ));
no_packets[i]=PD.nextInt();
}
while((tot_packets + no_packets[i]) > bucket_size);
tot_packets +=no_packets[i];
}
regd_bw += (no_packets[i] * in_bw[i]);
}
System.out.println("The total required bandwidth: "+regd_bw);
System.out.println("Enter output bandwidth");
out_bw=PD.nextInt();
int temp = regd_bw;
int rem_pkts = tot_packets;
while((out_bw <= temp) && (rem_pkts>0))
{
System.out.println("Data sent \n"+(--rem_pkts)+" remaining");
System.out.println("Remaining bandwidth: "+(temp-=out_bw));
if((out_bw>temp) && (rem_pkts > 0))
System.out.println(rem_pkts+" packets discovered due to insufficient bandwidth");
}
}
}