📄 selectiverepeat.asv
字号:
function [Umas,Pak,Ack]=selectiverepeat(amas,Nsimul,Ploss,SWS);
%function [Umas,Pak,Ack]=gobackn(amas,Nsimul,Ploss,SWS);
% function [Umas,Pak,Ack]=selectiverepeat(amas,Nsimul,Ploss,SWS);
%
% GoBackN algoritnm simulation
% MaxSeqNum=SWS+1
%
%
% Input:
%
% amas - t_prop/t_transm - can be an array, in which case
% simulation is repeated for each value of an array and
% cirresponding utilization is recorded in corresponding element of Umas
%
% Nsimul - number of sent frames to simulate
% time required is proportional to Nsimul
% quality of utilization estimates improves with Nsimul
% recommended Nsimul=100;
%
% Ploss - probability of packet loss (or receiving with an error)
% this probability is assumed the same for data packets and acknowledgments
%
% SWS - sender window size
% note: receiver window size - 1 in this algorith
%
% Output:
%
% Umas - vector containing channel utilization estimates for values of a
% in amas parameter. Length(Umas)=Length(amas)
%
% In case of the length(amas)>1 the following 2 output parameters
% output the result for the simulation for the last entry of vector amas
%
% Pak - matrix, each raw contains a signature of the simulated data packet sent.
% structure of the raw: (Pak# Time_sent Time_received sequence#)
% Time_received = Inf if the packet is lost
%
% Ack - matrix, each raw contains a signature of the simulated acknowledgment
% packet sent.
% structure of the raw: (Ack# Time_sent Time_received sequence#)
% Time_received = Inf if the ack is lost
%
if Ploss<0 | Ploss>1
error('Ploss not in limits [0,1]');
end
if SWS<1
error('wrong SWS');
end
Umas=[];
for j=1:length(amas)
a=amas(j);
Tprop=1;
Ttran=Tprop/a;
Pak=[];
% Pak - matrix, each raw contains a signature of the simulated data packet sent.
% structure of the raw: (Pak# Time_sent Time_received sequence#)
% Time_received = Inf if the packet is lost
Ack=[];
% Ack - matrix, each raw contains a signature of the simulated acknowledgment
% packet sent.
% structure of the raw: (Ack# Time_sent Time_received sequence#)
% Time_received = Inf if the ack is lost
time=0;
framen=0;
U=0;
Maxfrn=floor(2*SWS-1); %for SR SWS<(MaxSeqNum+1)/2 (definition)
LFR=-1; %last frame recv
LFA=-1; %last frame acked
LFS=-1; %last frame sent
busysender=0;
stackarrive=[0 0];
stackarrive(1,:)=[];
stackack=[0 0];
stackack(1,:)=[];
stacktimeout=[0 0]; %every packed goes in timeout array until it is received, then overwritten
stacktimeout(1,:)=[];
timestep=min(Tprop,Ttran)/50;
Timeout=Ttran+2*Tprop+3*timestep; %make timeout be slightly greater than the normal time to send packet and receive ack
paknum = 0;
%----------------------------------------------------------
time2=time;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -