function token
clc;
global ii;ii=0;
global lostq;
global f; f=0; %% front of queue
global r; r=0; %% Rear of queue
global q;
global ctr; ctr=0; %% counter for bufer size that is globl
global bufsize ; bufsize=100;
tnumber=200;
byte=0;tm=0;
fprintf('Number of generated tokens are : %d',tnumber);
fprintf('\n Size of bufer is : %d' , bufsize);
rate=input('\n Enter the rate of outflow : ');
for i=1:ceil(rand()*10)
count=0;
for i=1:ceil(rand()*10)
count=count+1;
p_size=ceil(rand()*400);
fprintf('\n packet comming from host is : %d',p_size);
fprintf('\n capacity of bufer is : %d \n',bufsize-ctr);
if p_size<=tnumber
disp(' And is inserted in BUCKET');
dif1=tnumber-p_size;
if (ctr-dif1)<=0
p_size=p_size+ctr;
ctr=0;
else
p_size = p_size +dif1;
ctr=ctr-dif1;
end
tic();
binsert(p_size);
pause(0.7);
en=toc();
else
dif2 = p_size - tnumber;
buffer(dif2);
end
if p_size<=tnumber
tm=tm+en;
disbucket();
bempty(p_size,tm,rate);
if f~=0
disbucket();
end
pause(0.5);
end
end
end
disp('**************************************************');
plot(lostq);
xlabel ('Number of packets that are losted');
ylabel('Size of loss');
end