⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectiverepeat.asv

📁 本程序是用java编写的一些关于arq协议实现的小程序
💻 ASV
📖 第 1 页 / 共 4 页
字号:
   
      if time>=busysender & LFS<LFA+SWS % not transimitting, and can fit in receiver window
         busysender=time+Ttran;         %start transmitting next packet
         LFS=LFS+1;                     %indicate that you sent packet
         stacktimeout=[stacktimeout; LFS time+Timeout]; %%appending and indicating when it will get timedout
         framen=rem(LFS,Maxfrn);    % assign packet a frame number
         gotit=rand>Ploss;          % see if the packet was recieved
         if gotit               
            Pak=[Pak; LFS time time+Tprop+Ttran framen]; %if you received it record in PAK array [packet, sent time , arrival time, frame#)
            stackarrive=[stackarrive; LFS time+Tprop+Ttran]; %updating the the packet you receive and the time you received it   
         else
            Pak=[Pak; LFS time Inf framen]; %if you don't receive it then go to the PAK array and set to  INF
         end      
      end   
      
      % check of arrival at receiver
            
      ind=find(stackarrive(:,2)<=time); % return packet (row) which has arrived (time=time+prop+tran)
      if length(ind)        %if there are any packet arrivals
         newpak=stackarrive(1,1);   %if arrival take the first one and update in stack arrive
        % if newpak==LFR | newpak==LFR+1 | newpak<LFR    
        if newpak<LFR+SWS
            if newpak>=LFR LFR=newpak;
            end;
            framen=rem(newpak,Maxfrn);%assign the packet a frame number
            gotack=rand>Ploss;
            if gotack   
               Ack=[Ack; newpak time time+Tprop framen];%ack being sent with packet # and timesent time received frame number
               stackack=[stackack; newpak time+Tprop];  %ack is in array set for timed simulated arrival
            else
               Ack=[Ack; newpak time Inf framen];  %this means that ack is in array with inf simulating lost
            end          
        else                                    %if there was no arrived packet
            gotack=rand>Ploss;
            framen=rem(LFR,Maxfrn);%this is the ack number
            if gotack
              % Ack=[Ack; LFR time time+Tprop framen];         % packet
                                                                % ack, time
                                                                % packet act,  time  received, ack framenumber
                                                                % and replaced with next line  
               Ack=[Ack; newpak time time+Tprop framen];
               %%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
               stackack=[stackack; LFR time+Tprop];              
               %xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
               
            else
              % Ack=[Ack; LFR time Inf framen];                 %took out
                                                                % and replaced with next line
              Ack=[Ack; newpak time Inf framen]; % ack is not received and put it into the ACK's
            end 
        end         
          stackarrive(1,:)=[]; %this clears out the packet that was received 
      end
      
      % check of arrival of ack
      
      ind=find(stackack(:,2)<=time);% find the acks that have been received time is up, return row number
      if length(ind)    %if there was one recieved
         newack=stackack(1,1);  % them most recent recieved ack
         if newack==LFA | newack==LFA+1 %if you recieved the LFA or the 
            LFA=newack;
            ind=find(stacktimeout(:,1)==LFA);
            if length(ind)
               stacktimeout(ind,:)=[];
            end;            
         end
         stackack(1,:)=[];
      end
      
   	
   	time=time+timestep;
	end;

	Umas(j)=LFS*Ttran/time;

end;




                                                                                                                                                                                                                                                                                                                                                                            if(SWS==5)
    
    
                                                                                                                                                                                                                                                                                                                                                                            %Debugging purposes
                                                                                                                                                                                                                                                                                                                                                                              Pak = [0	0	Inf	0
                                                                                                                                                                                                                                                                                                                                                                            1	2	5	1
                                                                                                                                                                                                                                                                                                                                                                            2	4	7	0
                                                                                                                                                                                                                                                                                                                                                                            0	6.02	9.02	2
                                                                                                                                                                                                                                                                                                                                                                            3	8.04	11.04	3
                                                                                                                                                                                                                                                                                                                                                                            4	10.06	Inf	4
                                                                                                                                                                                                                                                                                                                                                                            5	12.08	15.08	5
                                                                                                                                                                                                                                                                                                                                                                            6	14.1	17.1	4
                                                                                                                                                                                                                                                                                                                                                                            4	16.12	19.12	6
                                                                                                                                                                                                                                                                                                                                                                            7	18.14	21.14	7
                                                                                                                                                                                                                                                                                                                                                                            8	20.16	23.16	8
                                                                                                                                                                                                                                                                                                                                                                            9	22.18	25.18	0
                                                                                                                                                                                                                                                                                                                                                                            10	24.2	27.2	1
                                                                                                                                                                                                                                                                                                                                                                            11	26.22	29.22	2
                                                                                                                                                                                                                                                                                                                                                                            12	28.24	31.24	3
                                                                                                                                                                                                                                                                                                                                                                            13	30.26	33.26	4
                                                                                                                                                                                                                                                                                                                                                                            14	32.26	35.26	5

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -