No BSD License  

Highlights from
Home Networking Basis

Home Networking Basis

by

 

11 Aug 2003 (Updated )

M-files for chapters 2-10 and Simulink models for Ethernet and Wireless Ethernet.

RASlotAloha.m
%SIMULATION PARAMETERS
%simulation for slotted Aloha protocol
%total simulation time in seconds
runtime=0.2;
%total number of stations
nstation=10;
%transmission throughput of the media in bits per second
netthrou=10e6;
%frame size in bits
fsize=8000;
%avarage frame arrival rate per second for each station
%frate=10;
for frate=1:5:150
%average frame arrival rate per simulation iteration
trh=frate/10000;
%random wait window
wwind=100;
%EVENTS VARIABLES
%transmit active
tr=zeros(1,nstation);
%transmit queue
tq=zeros(1,nstation);
%transmit progress counter
tcnt=zeros(1,nstation);
%collision keeper
colis=zeros(1,10000*runtime);
%collision station index
colin=zeros(1,nstation);
%random wait after collision
rwait=zeros(1,nstation);
%transmit keeper
trkeep=zeros(nstation,10000*runtime);
%packet arrival keeper
pakeep=0;
for i=1:10000*runtime
for j=1:nstation
    %check if the transmitter is active
    if tr(j)==1
        trkeep(j,i)=1;
    end
    %check if the packet has been sent
     if tcnt(j)>0
        tcnt(j)=tcnt(j)-1;
        if tcnt(j)==0
            tr(j)=0;
            %check if the transmission is collision free
            if colin(j)==1
                rwait(j)=ceil(wwind*rand(1,1));
                tq(j)=tq(j)+1;
                colin(j)=0;
            end
        end
    else
        if tq(j)>0 & rwait(j)==0 & mod(i,8)==0
            tr(j)=1;
            tcnt(j)=ceil(fsize/netthrou*10000);
            tq(j)=tq(j)-1;
        end
    end
    %check if a new packet has arrived
    pa=rand(1,1);
    if pa<trh
        pakeep=pakeep+1;
        %if the transmit is ready
        if tr(j)==0 & rwait(j)==0 & mod(i,8)==0
           tr(j)=1;
           tcnt(j)=ceil(fsize/netthrou*10000);
       else
           tq(j)=tq(j)+1;
       end
    end
    %decreaserandom waiting count
    if rwait(j)>0
        rwait(j)=rwait(j)-1;
    end
end
%check for collision
if sum(tr)>1
        colis(i)=1;
        for k=1:nstation
            if tr(k)==1
                colin(k)=1;
            end
        end
end
end
px2(frate)=(pakeep-sum(tq));
py2(frate)=pakeep;
end
g2=[0:0.01:1.2];
s2=g2.*exp(-g2);
figure(2)
plot(px2*8000/runtime,py2*8000/runtime,'x',s2*1e7,g2*1e7,'-')
grid
xlabel('Throughput (bps)')
ylabel('Arrival Rate (bps)')

    
        

Contact us