-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsingleTxDynamicSchwithHARQ.m
More file actions
223 lines (218 loc) · 12 KB
/
Copy pathsingleTxDynamicSchwithHARQ.m
File metadata and controls
223 lines (218 loc) · 12 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
% singleTxDynamicSchwithHARQ
% retx indicates if a packet is retransmitted
retx=zeros(N,iter,N_MC);
% retx_time indicates the time when a packet is retransmitted
retx_time=100000*ones(N,iter,N_MC);
fretx_GB=zeros(N,iter);
t_ini=-1000*ones(N,iter);
RButilization_avg=0;
nframes=0;
currentTime=0;
flag=0;
while 1
% the next UE to be served is the one that generates the next packet
[nextPacketperUser,iTb]=min(Tb,[],1);
[nextT,user]=min(nextPacketperUser);
if nextT>=tsim
break;
end
if flagDiscardPkts==1 && TaOriginal(user,ind(user)+1)>=tsim
break;
end
ind(user)=iTb(user);
if ind(user)>=iter
break;
end
retx_index=1;
if latency(user,ind(user))>=300000
Tb(ind(user),user)=4*tsim;
continue;
end
for nUERx=1:N_MC
if 1 %all RBs are allocated in the same symbols
fretx=0;
flag=0;
while 1
m=find(current_time_frame>=nextT);
[n,p]=find(current_frame(:,m)==0);
if isempty(m) || isempty(n)
if strcmp(scheduling,'GF')
[retx,retx_time,current_frame,latency,flag,fretx]=schedule_retxs(retx,...
retx_time,current_frame,current_time_frame,...
next_frame,frame_l,TaOriginal',latency,t_ini,...
RBs_UEs,Tslot,iter,TprocRx,TprocTx,BLER,N_MC,...
maxN_retx,Tp,flagDiscardPkts,deadtime,scheduling,...
N_OS,symbPerSlot);
end
past_frame=current_frame;
current_frame=next_frame;
next_frame=zeros(NRB,symbols_per_frame);%remember that
% symbols_per_frame is equal to symbols_per_frame
% when full-slot txs are considered
current_time_frame=current_time_frame+frame_l;
if traffic==0 && nframes<limInf
nframes=nframes+1;
else
nframes=nframes+1;
RButilization_avg=RButilization_avg+sum(sum(past_frame))/(slots_per_frame*symbPerSlot*NRB);
end
if flagControl
if link_direction==1
% we reserve RBs for the SS/PBCH --> 1 block transmitted each 20
% slots. Each block is composed of 240 subcarriers x 4 OFDM symbols
i_SSB=i_SSB-symbols_per_frame;
while i_SSB<=symbols_per_frame
next_frame(1:20,i_SSB:i_SSB+factor)=1;
i_SSB=i_SSB+20*symbPerSlot;
end
elseif link_direction==2
i_RACH=i_RACH-slots_per_frame;
while i_RACH<=slots_per_frame
iaux=0;
while iaux<slotsperms
i_RACHaux=(i_RACH-1+iaux)*symbPerSlot+1;
next_frame(1:12,i_RACHaux:i_RACHaux+factor)=1;
iaux=iaux+1;
end
%next_frame(1:12,i_RACH:i_RACH+slotsperms-1)=1;
i_RACH=i_RACH+5*slotsperms;
end
end
end
else
if strcmp(scheduling,'GB') && nUERx==1 && fretx_GB(user,ind(user))==1
fretx_GB(user,ind(user))=0;
[retx(user,ind(user),:), retx_time(user,ind(user),:),...
current_frame, latency(user,ind(user)), flag,...
fretx]=schedule_retxs(retx(user,ind(user),:),...
retx_time(user,ind(user),:), current_frame,...
current_time_frame, next_frame, frame_l,...
TaOriginal(user,ind(user):end)', latency(user,ind(user)),...
t_ini(user,ind(user)), RBs_UEs(user), Tslot,...
iter, TprocRx, TprocTx, BLER, N_MC, maxN_retx, Tp,...
flagDiscardPkts, deadtime, scheduling, N_OS, symbPerSlot);
if flag==2 || sum(retx_time(user,ind(user),:))==N_MC*100000
Tb(ind(user),user)=4*tsim;
else
Tb(ind(user),user)=retx_time(user,ind(user),1);
fretx_GB(user,ind(user))=1;
end
flag=2;
break;
else
if flagDiscardPkts==1
deadtime=TaOriginal(user,ind(user)+1)-TaOriginal(user,ind(user));
end
[current_frame,tend,flag,fretx]=schedule_tx(nextT,ind(user),...
user,current_frame,current_time_frame,TaOriginal',...
RBs_UEs(user),Tslot/symbPerSlot,iter,BLER,Tp,deadtime,N_OS);
if flag==2
latency(user,ind(user))=100000;
% ind(user)=ind(user)+1;
% if ind(user)>iter
% return;
% end
Tb(ind(user),user)=4*tsim;
break;
end
if fretx==1
retx(user,ind(user),retx_index)=retx(user,ind(user),retx_index)+1;
if retx(user,ind(user),retx_index)<=maxN_retx
auxtime=tend+TprocRx+TprocTxHARQ;
if link_direction==1
% NACK is transmitted in the PUCCH
% PUCCH is transmitted in the last
% symbol of every slot
ACK_time=ceil(auxtime/Tslot)*Tslot+TprocRxHARQ;
% we add the latency introduced by
% the retransmission process using HARQ
[retx_time(user,ind(user),retx_index),latency(user,ind(user))]=DL_Scheduling_process(ACK_time,Tslot,TprocTx,TprocRx,TprocTxHARQ,TprocRxHARQ,latency(user,ind(user)),tsim,PDCCH_config,flag_control);
else
% NACK is transmitted in the PDCCH
% PUCCH is transmitted in the first
% symbol of every slot
auxtime2=mod(auxtime,Tslot); %Tslot-auxtime2 is the allignment time
ACK_time=auxtime+(Tslot-auxtime2)+Tslot/14+TprocRxHARQ; %(Tslot-auxtime2) es el frame alignment hasta el siguiente slot
% we add the latency introduced by
% the retransmission process using HARQ
[retx_time(user,ind(user),retx_index),latency(user,ind(user))]=SR_Grant_process(ACK_time,Tslot,TprocTx,TprocRx,TprocTxHARQ,TprocRxHARQ,latency(user,ind(user)),tsim,PDCCH_config,PUCCH_config,flag_control);
end
t_ini(user,ind(user))=TaOriginal(user,ind(user));%nextT-TprocTx;
if strcmp(scheduling,'GB')
Tb(ind(user),user)=retx_time(user,ind(user),retx_index);
fretx_GB(user,ind(user))=1;
end
retx_index=retx_index+1;
end
end
if flag==0
if flagDiscardPkts==1
deadtime=TaOriginal(user,ind(user)+1)-TaOriginal(user,ind(user));
end
[next_frame,tend,flag,fretx]=schedule_tx(nextT,ind(user),user,next_frame,current_time_frame+frame_l,TaOriginal',RBs_UEs(user),Tslot/symbPerSlot,iter,BLER,Tp,deadtime,N_OS);
if flag==2
latency(user,ind(user))=100000;
Tb(ind(user),user)=4*tsim;
break;
end
if fretx==1
retx(user,ind(user),retx_index)=retx(user,ind(user),retx_index)+1;
if retx(user,ind(user),retx_index)<=maxN_retx
auxtime=tend+TprocRx+TprocTxHARQ;
if link_direction==1
% NACK is transmitted in the PUCCH
% PUCCH is transmitted in the last
% symbol of every slot
ACK_time=ceil(auxtime/Tslot)*Tslot+TprocRxHARQ;
% we add the latency introduced by
% the retransmission process using HARQ
[retx_time(user,ind(user),retx_index),latency(user,ind(user))]=DL_Scheduling_process(ACK_time,Tslot,TprocTx,TprocRx,TprocTxHARQ,TprocRxHARQ,latency(user,ind(user)),tsim,PDCCH_config,flag_control);
else
% NACK is transmitted in the PDCCH
% PUCCH is transmitted in the first
% symbol of every slot
auxtime2=mod(auxtime,Tslot);
ACK_time=auxtime+(Tslot-auxtime2)+Tslot/14+TprocRxHARQ; %(Tslot-auxtime2) es el frame alignment hasta el siguiente slot
% we add the latency introduced by
% the retransmission process using HARQ
[retx_time(user,ind(user),retx_index),latency(user,ind(user))]=SR_Grant_process(ACK_time,Tslot,TprocTx,TprocRx,TprocTxHARQ,TprocRxHARQ,latency(user,ind(user)),tsim,PDCCH_config,PUCCH_config,flag_control);
end
t_ini(user,ind(user))=TaOriginal(user,ind(user));%nextT-TprocTx;
if strcmp(scheduling,'GB')
Tb(ind(user),user)=retx_time(user,ind(user),retx_index);
fretx_GB(user,ind(user))=1;
end
retx_index=retx_index+1;
end
end
end
if flag==0
disp('error: you should not be here');
end
end
break;
end
end
end
if flag==2
break;
end
end
if flag==2
continue;
end
aux=0;
if fretx_GB(user,ind(user))==0
retx_index=1;
while retx_index<=N_MC && retx(user,ind(user),retx_index)<=maxN_retx
retx_index=retx_index+1;
end
if retx_index<=N_MC
latency(user,ind(user))=200000;
else
% latency(user,ind(user))=TprocTx+(tend-nextT)+TprocRx;
latency(user,ind(user))=tend+TprocRx-TaOriginal(user,ind(user));
end
Tb(ind(user),user)=4*tsim;
end
end