资源简介
差额加权轮询算法Matlab仿真,输出包含数据包到达速度、队列发送速度、数据包平均时延。
代码片段和文件信息
clc;
clear all;
%初始化各队列模型
lambda =[2.4 2.4 2.4 2.4 ]; %泊松流参数
queue_num = 4; %队列个数
Bandwidth = 5000; %带宽
packet_size = 256;
for i = 1:queue_num
ari_mean(i) = 1/lambda(i);
ari_num = 100000; %到达数据包个数
ari_interval = [];
ari_interval(i:) = exprnd(ari_mean(i)1ari_num); %平均间隔时间
ari_time(i:) = cumsum(ari_interval(i:)); %每个数据包到达时间
end
%根据优先级分配初始Dc
pri = [7 5 4 2];
for i = 1:queue_num
Dc_pri(i) = (pri(i)/sum(pri))*Bandwidth;
end
polltimes = 5000; %轮询次数
sys_time_DWRR = zeros(polltimes+1queue_num); %系统时间
sys_time_DWRR(11) = 1;
packet_ari_DWRR = zeros(polltimesqueue_num); %数据包到达个数
packet_wait_DWRR = zeros(polltimesqueue_num); %数据包排队个数
packet_send_DWRR = zeros(polltimesqueue_num); %数据包发送个数
packet_send_DWRR(1:) = 0;
packet_time_DWRR = zeros(ari_numqueue_num); %数据包发送时间
send_num_DWRR = zeros(polltimesqueue_num);
Dc_DWRR = zeros(polltimes+1queue_num);
time_interval = 0.5;
for i = 1:polltimes
for j = 1:queue_num
Dc_DWRR(1j) = Dc_pri(j);
if j==1
packet_ari_DWRR(ij) = sum(ari_time(j:) < sys_time_DWRR(ij));
elseif j>1
packet_ari_DWRR(ij) = sum(ari_time(j:) < sys_time_DWRR(ij-1));
end
if i==1
packet_wait_DWRR(ij) = packet_ari_DWRR(ij);
else
packet_wait_DWRR(ij) = packet_wait_DWRR(i-1j)+packet_ari_DWRR(ij)-packet_ari_DWRR(i-1j)-send_num_DWRR(i-1j);
end
if packet_wait_DWRR(ij)>0 && Dc_DWRR(ij)>=packet_size %有数据包等待发送且Dc够用
if Dc_DWRR(ij) send_len(ij) = floor(Dc_DWRR(ij)/packet_size) * packet_size; %单次轮询发送的数据包大小
else
send_len(ij) = packet_wait_DWRR(ij)*packet_size;
end
send_num_DWRR(ij) = send_len(ij)/packet_size; %发送数据包个数
packet_send_DWRR(ij) = sum(send_num_DWRR(:j));
send_time(ij) = send_len(ij)/Bandwidth; %数据包发送时间
if i==1 && j==1
sys_time_DWRR(ij) = sys_time_DWRR(1)+send_time(ij);
elseif i>1 && j==1
sys_time_DWRR(ij) = sys_time_DWRR(ij)+send_time(ij);
elseif j>1 && j sys_time_DWRR(ij) = sys_time_DWRR(ij-1)+send_time(ij);
elseif j==queue_num
sys_time_DWRR(ij) = sys_time_DWRR(ij-1)+send_time(ij);
sys_time_DWRR(i+11) = sys_time_DWRR(ij);
end
n = sum(packet_time_DWRR(:j)~=0);
for k = n+1 : n+send_num_DWRR(ij)
packet_time_DWRR(kj) = sys_time_DWRR(ij)-(packet_size/Bandwidth)*(n+send_num_DWRR(ij)-k); %计算每个数据包发送的时间
end
Dc_DWRR(i+1j) = Dc_DWRR(ij)-send_len(ij); %Dc减去已发送的数据长度
评论
共有 条评论