N=16; % Số lượng ONU
Q=8*10^6; % Kích thước bộ đệm
size_p=512 ; % Kích thước bản tin REQUEST (bit)
R=10^3; % 1Gbps = 1 kb/us
Wmax=120000; % Kích thước cửa sổ truyền lớn nhất
rtt=100; % RTT của các ONU bằng nhau. RTT=100us % tạo ma trận tải từ 0.05 đến 0.95
for i=1:1:19
load(i)=0.05*i;
end
% tạo cơ sở dữ liệu for i=1:1:19
x(i,:)=poissrnd(i*560,1,1000000);
end
Đoàn Đức Sinh 102 for l=1:1:19 j=1; q=zeros(1,201); w=zeros(1,200);
for i=1:1:200 % số lượng chu kỳ khảo sát là 200 % thời gian chu kỳ thứ i
Tg(l,i) = 2*rtt + N*(w(i)+size_p)/R;
% dữ liệu đến trong khoảng thời gian chu kỳ thứ i
Ts =Tg(l,i); n = round(Ts/125); data=0; for k=1:1:n data = data + x(l,j+k-1); end
% cập nhật gói dữ liệu kế tiếp
j=j+n;
% kích thước hàng đợi trước khi truyền dữ liệu
q(i+1)=q(i)+data-w(i);
if q(i+1)>Q
q(i+1)=Q;
end
% kích thước cửa sổ truyền của chu kỳ kế tiếp (i+1)
w(i+1)=q(i)-w(i);
% tính thời gian trễ của gói tin if w(i+1)==0 t(i)=Ts/2+Ts; elseif q(i+1)<w(i+1) t(i)=Ts/2+Ts*((q(i+1)-w(i+1))/w(i+1))+q(i+1)/R; else t(i)=Ts/2+Ts*((q(i+1)-w(i+1))/w(i+1)) + mod(q(i+1)- w(i+1),w(i+1))/R; end end
Acycle(1,l)=mean(Tg(l,:))/1000; % evarage cycle time (ms)
Aqueue(1,l)=mean(q)/8; % evarage queue size (byte)
Adelay(1,l)=mean(t)/1000; % evarage delay time (ms)
Mcycle(1,l)=max(Tg(l,:))/1000; % maximum cycle time (ms)
Mqueue(1,l)=max(q)/8; % maximum queue size (byte)
Mdelay(1,l)=max(t)/1000; % maximum delay time (ms) end % LIMITED SERVICE for l=1:1:19 j=1; q=zeros(1,201); w=zeros(1,200); for i=1:1:1000
% thoi gian cua chu ky thu i
Tl(l,i) = 2*rtt + N*(w(i)+size_p)/R;
% du lieu den trong khoang thoi gian cua chu ky i
Ts =Tl(l,i);
Đoàn Đức Sinh 103 data=0; for k=1:1:n data = data + x(l,j+k-1); end
% cap nhat goi du lieu ke tiep
j=j+n;
% kich thuoc hang doi tai thoi diem truoc khi truyen du lieu
q(i+1)=q(i)+data-w(i);
if q(i+1)>Q
q(i+1)=Q;
end
% kich thuoc cua so truyen trong chu ky ke tiep
wt=q(i)-w(i); if wt>Wmax w(i+1)=Wmax; else w(i+1)=wt; end if w(i+1)==0 | q(i+1)<w(i+1) t(i)=Ts/2+Ts+q(i+1)/R; else t(i)=Ts/2+Ts*((q(i+1)-w(i+1))/w(i+1))+mod(q(i+1)-w(i+1),Wmax)/R; end end
Acycle(2,l)=mean(Tg(l,:))/1000; % evarage cycle time (ms)
Aqueue(2,l)=mean(q)/8; % evarage queue size (byte)
Adelay(2,l)=mean(t)/1000; % evarage delay time (ms)
Mcycle(2,l)=max(Tg(l,:))/1000; % maximum cycle time (ms)
Mqueue(2,l)=max(q)/8; % maximum queue size (byte)
Mdelay(2,l)=max(t)/1000; % maximum delay time (ms) end
% CONSTANT CREDIT SERVICE for l=1:1:19
j=1;
q=zeros(1,201); w=zeros(1,200);
for i=1:1:1000
% thoi gian cua chu ky thu i
Tc(l,i) = 2*rtt + N*(w(i)+size_p)/R;
% du lieu den trong khoang thoi gian cua chu ky i
Ts =Tc(l,i); n = round(Ts/125); data=0; for k=1:1:n data = data + x(l,j+k-1); end
% cap nhat goi du lieu
j=j+n;
Đoàn Đức Sinh 104 q(i+1)=q(i)+data-w(i); if q(i+1)>Q q(i+1)=Q; end
% kich thuoc cua so truyen trong chu ky ke tiep
wt=q(i)-w(i);
if (wt+800)>Wmax w(i+1)=Wmax;
else
w(i+1)=wt+800; % cap them 800 bit so voi yeu cau end
% tinh thoi gian tre cua goi tin if w(i+1)==800 | q(i+1)<w(i+1) t(i)=Ts/2+Ts+q(i+1)/R; else t(i)=Ts/2+Ts*((q(i+1)-w(i+1))/w(i+1))+mod(q(i+1)-w(i+1),Wmax)/R; end end
Acycle(3,l)=mean(Tg(l,:))/1000; % evarage cycle time (ms)
Aqueue(3,l)=mean(q)/8; % evarage queue size (byte)
Adelay(3,l)=mean(t)/1000; % evarage delay time (ms)
Mcycle(3,l)=max(Tg(l,:))/1000; % maximum cycle time (ms)
Mqueue(3,l)=max(q)/8; % maximum queue size (byte)
Mdelay(3,l)=max(t)/1000; % maximum delay time (ms) end
% LINEAR CREDIT SERVICE for l=1:1:19
j=1;
q=zeros(1,201); w=zeros(1,200);
for i=1:1:1000
% thoi gian cua chu ky thu i
Tn(l,i) = 2*rtt + N*(w(i)+size_p)/R;
% du lieu den trong khoang thoi gian cua chu ky i
Ts =Tn(l,i); n = round(Ts/125); data=0; for k=1:1:n data = data + x(l,j+k-1); end
% cap nhat goi du lieu
j=j+n;
% kich thuoc hang doi tai thoi diem truoc khi truyen du lieu
q(i+1)=q(i)+data-w(i);
if q(i+1)>Q
q(i+1)=Q;
end
% kich thuoc cua so truyen trong chu ky ke tiep
wt=q(i)-w(i);
if wt>Wmax
Đoàn Đức Sinh 105
else
w(i+1)=wt*1.1;;
end
% tinh thoi gian tre cua goi tin if w(i+1)==0 | q(i+1)<w(i+1) t(i)=Ts/2+Ts+q(i+1)/R; else t(i)=Ts/2+Ts*((q(i+1)-w(i+1))/w(i+1))+mod(q(i+1)-w(i+1),Wmax)/R; end end
Acycle(4,l)=mean(Tg(l,:))/1000; % evarage cycle time (ms)
Aqueue(4,l)=mean(q)/8; % evarage queue size (byte)
Adelay(4,l)=mean(t)/1000; % evarage delay time (ms)
Mcycle(4,l)=max(Tg(l,:))/1000; % maximum cycle time (ms)
Mqueue(4,l)=max(q)/8; % maximum queue size (byte)
Mdelay(4,l)=max(t)/1000; % maximum delay time (ms) end % FIXED SERVICE for l=1:1:19 j=1; q=zeros(1,201); w=zeros(1,200); w(1)=Wmax; qa=0; for i=1:1:1000
% thoi gian cua chu ky thu i
Tf(l,i) = 2*rtt + N*(w(i)+size_p)/R;
% du lieu den trong khoang thoi gian cua chu ky i
Ts =Tf(l,i); n = round(Ts/125); data=0; for k=1:1:n data = data + x(l,j+k-1); end
% cap nhat goi du lieu tiep theo
j=j+n;
% kich thuoc hang doi tai thoi diem truoc khi truyen du lieu
q(i+1)=qa+data;
if q(i+1)>Q
q(i+1)=Q;
end
% kich thuoc hang doi sau khi truyen du lieu if q(i+1)<Wmax
qa=0;
else
qa=q(i+1)-Wmax;
end
% kich thuoc cua so truyen trong chu ky ke tiep
Đoàn Đức Sinh 106
% tinh thoi gian tre cua goi tin if q(i+1)<w(i+1) t(i)=Ts/2+Ts+q(i+1)/R; else t(i)=Ts/2+Ts*(q(i+1)-w(i+1))/Wmax+mod(q(i+1)-w(i+1),Wmax)/R; end end
Acycle(5,l)=mean(Tg(l,:))/1000; % evarage cycle time (ms)
Aqueue(5,l)=mean(q)/8; % evarage queue size (byte)
Adelay(5,l)=mean(t)/1000; % evarage delay time (ms)
Mcycle(5,l)=max(Tg(l,:))/1000; % maximum cycle time (ms)
Mqueue(5,l)=max(q)/8; % maximum queue size (byte)
Mdelay(5,l)=max(t)/1000; % maximum delay time (ms) End
for i=1:1:19
load(i)=0.05*i;
end
xlswrite('Avecycle.xlsx',Acycle); xlswrite('Avequeue.xlsx',Aqueue); xlswrite('Avedelay.xlsx',Adelay); xlswrite('Maxcycle.xlsx',Mcycle); xlswrite('Maxqueue.xlsx',Mqueue); xlswrite('Maxdelay.xlsx',Mdelay);