forked from OUTMAN666/AC-RLNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getACRLNC.m
118 lines (95 loc) · 4.02 KB
/
getACRLNC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function [meanLatency,deliverTime,packetMatrix] = getACRLNC(th,N,RTT,p)
m = 1;
channelState = zeros(1,20*N);
channelState = generateChannelState(20*N,p,channelState);
k = RTT-1;
error = 0;
omax = 2*k;
slideWindow = zeros(1,N);
packetMatrix = zeros(20*N,N);
md = zeros(1,20*N);
ad = zeros(1,20*N);
slideWindow(1) = 1;
packetMatrix(1,:) = slideWindow;
t = 2;
while calculateDoF(slideWindow)>0
%无反馈
if t <= RTT
%滑动窗口满
if judgeEW(slideWindow,k)
%重传m次
for i = 1:m
%重传
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
end
else
%加入新的信息包
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = addNewPkt(t,packetMatrix,RTT,channelState);
end
%反馈为NACK
elseif channelState(t-RTT) == 1
error = error+1;
if calculateCriterion(channelState,packetMatrix,error,t,md,ad,RTT)>th
if ~judgeEW(slideWindow,k)
if slideWindow(N) == 1
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
else
%加入新的信息包
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = addNewPkt(t,packetMatrix,RTT,channelState);
end
else
m = ceil(k*error/(t-RTT));
for i = 1:m
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
end
end
else
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
if calculateDoF(slideWindow)>0
if judgeEW(slideWindow,k)
m = ceil(k*error/(t-RTT));
for i = 1:m
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
end
end
end
end
%反馈为ACK
else
if judgeEW(slideWindow,k)
m = ceil(k*error/(t-RTT));
for i = 1:m
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
end
end
%在上面的重传之后,可能已经传输完毕
if calculateDoF(slideWindow)>0
if calculateCriterion(channelState,packetMatrix,error,t,md,ad,RTT)<th
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
elseif slideWindow(N) == 1
%若没有新的信息包可以加入,而传输还没有结束,则继续重传
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
else
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = addNewPkt(t,packetMatrix,RTT,channelState);
end
end
end
if calculateDoF(slideWindow)>omax
while calculateDoF(slideWindow) ~= 0
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = transmitTheSameRLNC(t,packetMatrix,RTT,channelState);
end
%没有传输完毕
if packetMatrix(t-1,N) == 0
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = addNewPkt(t,packetMatrix,RTT,channelState);
end
end
%窗体为空但还没有传输完毕
if calculateDoF(slideWindow) == 0 && packetMatrix(t-1,N) == 0
[slideWindow,packetMatrix(t,:),md(t),ad(t),t] = addNewPkt(t,packetMatrix,RTT,channelState);
end
end
firstTransmitTime = calculateFirstTransmitTime(packetMatrix);
deliverTime = calculateDeliverTime(packetMatrix,RTT);
latency = deliverTime-firstTransmitTime;
meanLatency = mean(latency);
end