-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLeaky bucket.c
63 lines (55 loc) · 1.42 KB
/
Leaky bucket.c
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
60
61
62
63
#include<stdio.h>
#include<unistd.h>
int main()
{
int bucket ;
int n;
int output = 20;
int i, size;
int currentBucket = 0;
printf("Enter the bucket size:\n");
scanf("%d",&bucket);
printf("Enter the number of packets:\n");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter the size of packet %d: ", i + 1);
scanf("%d", &size);
if (size <= (bucket - currentBucket))
{
currentBucket += size;
printf("Current bucket size: %d\n",currentBucket);
}
else
{
printf("Packet of size %d is dropped. Not enough space in the bucket.\n", size);
}
if (currentBucket > 0)
{
int sent = (currentBucket < output) ? currentBucket : output;
currentBucket -= sent;
printf("Sent %d units. Current bucket size after sending: %d\n", sent, currentBucket);
}
else
{
printf("No packets to send.\n");
}
sleep(1);
}
while(currentBucket!=0)
{
if(currentBucket<=bucket)
{
printf("Remaing packet is transmited of size %d \n",currentBucket);
currentBucket=0;
}
else
{
printf("Remaing packet is of size %d \n",currentBucket);
int r = currentBucket-bucket;
printf("Transmitted packet :%d \n",r);
}
}
printf("Final bucket size: %d\n", currentBucket);
return 0;
}