answersLogoWhite

0

//here is a simple implementation of leaky bucket.

#include<stdio.h>

#include<stdlib.h>

#include<dos.h>

void main()

{

int i,packets[10],content=0,newcontent,time,clk,bcktsize,oprate;

for(i=0;i<5;i++)

{

packets[i]=rand()%10;

if(packets[i]==0) --i;

}

printf("\n Enter output rate of the bucket: \n");

scanf("%d",&oprate);

printf("\n Enter Bucketsize\n");

scanf("%d",&bcktsize);

for(i=0;i<5;++i)

{

if((packets[i]+content)>bcktsize)

{

if(packets[i]>bcktsize)

printf("\n Incoming packet size %d greater than the size of the bucket\n",packets[i]);

else

printf("\n bucket size exceeded\n");

}

else

{

newcontent=packets[i];

content+=newcontent;

printf("\n Incoming Packet : %d\n",newcontent);

printf("\n Transmission left : %d\n",content);

time=rand()%10;

printf("\n Next packet will come at %d\n",time);

for(clk=0;clk<time && content>0;++clk)

{

printf("\n Left time %d",(time-clk));

sleep(1);

if(content)

{

printf("\n Transmitted\n");

if(content<oprate)

content=0;

else

content=content-oprate;

printf("\n Bytes remaining : %d\n",content);

}

else

printf("\n No packets to send\n");

}

}

}

}

User Avatar

Wiki User

8y ago

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
More answers

Algorithm:

Start.

Set the bucket size or the buffer size.

Set the output rate.

Transmit the packets such that there is no overflow.

Repeat the process of transmission until all packets are transmitted. (Reject packets where its size is greater than the bucket size)

Stop.

User Avatar

it c

Lvl 2
3y ago
User Avatar

One way to implement the token bucket algorithm would be to use times at regular intervals to fill the buckets with tokens. This is a simple way but there are better methods.

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: How can we implement Leaky bucket algorithm in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp