-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path12.LeakyBucket.java
More file actions
59 lines (50 loc) · 1.68 KB
/
12.LeakyBucket.java
File metadata and controls
59 lines (50 loc) · 1.68 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
57
58
59
/*
12. Write a program for congestion control using leaky bucket algorithm.
*/
import java.util.Scanner;
import java.util.TreeSet;
class LeakyBucket {
public static void main(String[] args) {
TreeSet<Integer> arrivalTimes = new TreeSet<Integer>();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Burstiness in Network");
int L = scanner.nextInt();
System.out.println("Enter Packet Inter Arrival");
int I = scanner.nextInt();
System.out.println("Enter Arrival Times of Packets (Enter non integer value at end)");
while (scanner.hasNextInt()) {
arrivalTimes.add(scanner.nextInt());
}
int LCT = arrivalTimes.first();
int X = 0;
for (Integer t : arrivalTimes) {
int temp = X - (t - LCT);
if (temp > L) {
System.out.println("Packet at time " + t + " is Non Conforming");
} else {
X = temp + I;
LCT = t;
System.out.println("Packet at time " + t + " is Conforming");
}
}
}
}
////////////
// Output
// Enter Burstiness in Network
// 6
// Enter Packet Inter Arrival
// 4
// Enter Arrival Times of Packets (Enter non integer value at end)
// 1 2 3 5 6 8 11 12 13 15 19 q
// Packet at time 1 is Conforming
// Packet at time 2 is Conforming
// Packet at time 3 is Conforming
// Packet at time 5 is Non Conforming
// Packet at time 6 is Non Conforming
// Packet at time 8 is Conforming
// Packet at time 11 is Conforming
// Packet at time 12 is Non Conforming
// Packet at time 13 is Non Conforming
// Packet at time 15 is Conforming
// Packet at time 19 is Conforming