-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcqa-ff-mac-scheduler.cc
2640 lines (2351 loc) · 96.7 KB
/
cqa-ff-mac-scheduler.cc
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Biljana Bojovic <bbojovic@cttc.es>, Nicola Baldo<nbaldo@cttc.es>.
*
* Note:
* Implementation is using many common scheduler functionalities in its
* original version implemented by Marco Miozzo<mmiozzo@cttc.es> in
* Proportional Fair and Round Robin schedulers implementations.
*/
#include <ns3/log.h>
#include <ns3/pointer.h>
#include <ns3/math.h>
#include <ns3/simulator.h>
#include <ns3/lte-amc.h>
#include <ns3/cqa-ff-mac-scheduler.h>
#include <ns3/ff-mac-common.h>
#include <ns3/lte-vendor-specific-parameters.h>
#include <ns3/boolean.h>
#include <cfloat>
#include <set>
#include <stdexcept>
#include <ns3/integer.h>
#include <ns3/string.h>
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("CqaFfMacScheduler");
static const int CqaType0AllocationRbg[4] = {
10, // RGB size 1
26, // RGB size 2
63, // RGB size 3
110 // RGB size 4
}; // see table 7.1.6.1-1 of 36.213
NS_OBJECT_ENSURE_REGISTERED (CqaFfMacScheduler);
struct qos_rb_and_CQI_assigned_to_lc
{
uint16_t resource_block_index; //Resource block indexHOL_GROUP_index
uint8_t cqi_value_for_lc; // CQI indicator value
};
bool CQIValueDescComparator (uint8_t key1, uint8_t key2)
{
return key1>key2;
}
bool CqaGroupDescComparator (int key1, int key2)
{
return key1>key2;
}
typedef uint8_t CQI_value;
typedef int RBG_index;
typedef int HOL_group;
typedef std::map<CQI_value,LteFlowId_t,bool(*)(uint8_t,uint8_t)> t_map_CQIToUE; //sorted
typedef std::map<RBG_index,t_map_CQIToUE> t_map_RBGToCQIsSorted;
typedef std::map<HOL_group,t_map_RBGToCQIsSorted> t_map_HOLGroupToRBGs;
typedef std::map<CQI_value,LteFlowId_t,bool(*)(uint8_t,uint8_t)>::iterator t_it_CQIToUE; //sorted
typedef std::map<RBG_index,t_map_CQIToUE>::iterator t_it_RBGToCQIsSorted;
typedef std::map<HOL_group,t_map_RBGToCQIsSorted>::iterator t_it_HOLGroupToRBGs;
typedef std::multimap<HOL_group,std::set<LteFlowId_t>,bool(*)(int,int)> t_map_HOLgroupToUEs;
typedef std::map<HOL_group,std::set<LteFlowId_t> >::iterator t_it_HOLgroupToUEs;
//typedef std::map<RBG_index,CQI_value> map_RBG_to_CQI;
//typedef std::map<LteFlowId_t,map_RBG_to_CQI> map_flowId_to_CQI_map;
bool CqaKeyDescComparator (uint16_t key1, uint16_t key2)
{
return key1>key2;
}
class CqaSchedulerMemberCschedSapProvider : public FfMacCschedSapProvider
{
public:
CqaSchedulerMemberCschedSapProvider (CqaFfMacScheduler* scheduler);
// inherited from FfMacCschedSapProvider
virtual void CschedCellConfigReq (const struct CschedCellConfigReqParameters& params);
virtual void CschedUeConfigReq (const struct CschedUeConfigReqParameters& params);
virtual void CschedLcConfigReq (const struct CschedLcConfigReqParameters& params);
virtual void CschedLcReleaseReq (const struct CschedLcReleaseReqParameters& params);
virtual void CschedUeReleaseReq (const struct CschedUeReleaseReqParameters& params);
private:
CqaSchedulerMemberCschedSapProvider ();
CqaFfMacScheduler* m_scheduler;
};
CqaSchedulerMemberCschedSapProvider::CqaSchedulerMemberCschedSapProvider ()
{
}
CqaSchedulerMemberCschedSapProvider::CqaSchedulerMemberCschedSapProvider (CqaFfMacScheduler* scheduler) : m_scheduler (scheduler)
{
}
void
CqaSchedulerMemberCschedSapProvider::CschedCellConfigReq (const struct CschedCellConfigReqParameters& params)
{
m_scheduler->DoCschedCellConfigReq (params);
}
void
CqaSchedulerMemberCschedSapProvider::CschedUeConfigReq (const struct CschedUeConfigReqParameters& params)
{
m_scheduler->DoCschedUeConfigReq (params);
}
void
CqaSchedulerMemberCschedSapProvider::CschedLcConfigReq (const struct CschedLcConfigReqParameters& params)
{
m_scheduler->DoCschedLcConfigReq (params);
}
void
CqaSchedulerMemberCschedSapProvider::CschedLcReleaseReq (const struct CschedLcReleaseReqParameters& params)
{
m_scheduler->DoCschedLcReleaseReq (params);
}
void
CqaSchedulerMemberCschedSapProvider::CschedUeReleaseReq (const struct CschedUeReleaseReqParameters& params)
{
m_scheduler->DoCschedUeReleaseReq (params);
}
class CqaSchedulerMemberSchedSapProvider : public FfMacSchedSapProvider
{
public:
CqaSchedulerMemberSchedSapProvider (CqaFfMacScheduler* scheduler);
// inherited from FfMacSchedSapProvider
virtual void SchedDlRlcBufferReq (const struct SchedDlRlcBufferReqParameters& params);
virtual void SchedDlPagingBufferReq (const struct SchedDlPagingBufferReqParameters& params);
virtual void SchedDlMacBufferReq (const struct SchedDlMacBufferReqParameters& params);
virtual void SchedDlTriggerReq (const struct SchedDlTriggerReqParameters& params);
virtual void SchedDlRachInfoReq (const struct SchedDlRachInfoReqParameters& params);
virtual void SchedDlCqiInfoReq (const struct SchedDlCqiInfoReqParameters& params);
virtual void SchedUlTriggerReq (const struct SchedUlTriggerReqParameters& params);
virtual void SchedUlNoiseInterferenceReq (const struct SchedUlNoiseInterferenceReqParameters& params);
virtual void SchedUlSrInfoReq (const struct SchedUlSrInfoReqParameters& params);
virtual void SchedUlMacCtrlInfoReq (const struct SchedUlMacCtrlInfoReqParameters& params);
virtual void SchedUlCqiInfoReq (const struct SchedUlCqiInfoReqParameters& params);
private:
CqaSchedulerMemberSchedSapProvider ();
CqaFfMacScheduler* m_scheduler;
};
CqaSchedulerMemberSchedSapProvider::CqaSchedulerMemberSchedSapProvider ()
{
}
CqaSchedulerMemberSchedSapProvider::CqaSchedulerMemberSchedSapProvider (CqaFfMacScheduler* scheduler)
: m_scheduler (scheduler)
{
}
void
CqaSchedulerMemberSchedSapProvider::SchedDlRlcBufferReq (const struct SchedDlRlcBufferReqParameters& params)
{
m_scheduler->DoSchedDlRlcBufferReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedDlPagingBufferReq (const struct SchedDlPagingBufferReqParameters& params)
{
m_scheduler->DoSchedDlPagingBufferReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedDlMacBufferReq (const struct SchedDlMacBufferReqParameters& params)
{
m_scheduler->DoSchedDlMacBufferReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedDlTriggerReq (const struct SchedDlTriggerReqParameters& params)
{
m_scheduler->DoSchedDlTriggerReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedDlRachInfoReq (const struct SchedDlRachInfoReqParameters& params)
{
m_scheduler->DoSchedDlRachInfoReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedDlCqiInfoReq (const struct SchedDlCqiInfoReqParameters& params)
{
m_scheduler->DoSchedDlCqiInfoReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedUlTriggerReq (const struct SchedUlTriggerReqParameters& params)
{
m_scheduler->DoSchedUlTriggerReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedUlNoiseInterferenceReq (const struct SchedUlNoiseInterferenceReqParameters& params)
{
m_scheduler->DoSchedUlNoiseInterferenceReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedUlSrInfoReq (const struct SchedUlSrInfoReqParameters& params)
{
m_scheduler->DoSchedUlSrInfoReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedUlMacCtrlInfoReq (const struct SchedUlMacCtrlInfoReqParameters& params)
{
m_scheduler->DoSchedUlMacCtrlInfoReq (params);
}
void
CqaSchedulerMemberSchedSapProvider::SchedUlCqiInfoReq (const struct SchedUlCqiInfoReqParameters& params)
{
m_scheduler->DoSchedUlCqiInfoReq (params);
}
CqaFfMacScheduler::CqaFfMacScheduler ()
: m_cschedSapUser (0),
m_schedSapUser (0),
m_timeWindow (99.0),
m_nextRntiUl (0)
{
m_amc = CreateObject <LteAmc> ();
m_cschedSapProvider = new CqaSchedulerMemberCschedSapProvider (this);
m_schedSapProvider = new CqaSchedulerMemberSchedSapProvider (this);
m_ffrSapProvider = 0;
m_ffrSapUser = new MemberLteFfrSapUser<CqaFfMacScheduler> (this);
}
CqaFfMacScheduler::~CqaFfMacScheduler ()
{
NS_LOG_FUNCTION (this);
}
void
CqaFfMacScheduler::DoDispose ()
{
NS_LOG_FUNCTION (this);
m_dlHarqProcessesDciBuffer.clear ();
m_dlHarqProcessesTimer.clear ();
m_dlHarqProcessesRlcPduListBuffer.clear ();
m_dlInfoListBuffered.clear ();
m_ulHarqCurrentProcessId.clear ();
m_ulHarqProcessesStatus.clear ();
m_ulHarqProcessesDciBuffer.clear ();
delete m_cschedSapProvider;
delete m_schedSapProvider;
delete m_ffrSapUser;
}
TypeId
CqaFfMacScheduler::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::CqaFfMacScheduler")
.SetParent<FfMacScheduler> ()
.SetGroupName("Lte")
.AddConstructor<CqaFfMacScheduler>()
.AddAttribute ("CqiTimerThreshold",
"The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
UintegerValue (1000),
MakeUintegerAccessor (&CqaFfMacScheduler::m_cqiTimersThreshold),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("CqaMetric",
"CqaFfMacScheduler metric type that can be: CqaFf, CqaPf",
StringValue ("CqaFf"),
MakeStringAccessor (&CqaFfMacScheduler::m_CqaMetric),
MakeStringChecker ())
.AddAttribute ("HarqEnabled",
"Activate/Deactivate the HARQ [by default is active].",
BooleanValue (true),
MakeBooleanAccessor (&CqaFfMacScheduler::m_harqOn),
MakeBooleanChecker ())
.AddAttribute ("UlGrantMcs",
"The MCS of the UL grant, must be [0..15] (default 0)",
UintegerValue (0),
MakeUintegerAccessor (&CqaFfMacScheduler::m_ulGrantMcs),
MakeUintegerChecker<uint8_t> ())
;
return tid;
}
void
CqaFfMacScheduler::SetFfMacCschedSapUser (FfMacCschedSapUser* s)
{
m_cschedSapUser = s;
}
void
CqaFfMacScheduler::SetFfMacSchedSapUser (FfMacSchedSapUser* s)
{
m_schedSapUser = s;
}
FfMacCschedSapProvider*
CqaFfMacScheduler::GetFfMacCschedSapProvider ()
{
return m_cschedSapProvider;
}
FfMacSchedSapProvider*
CqaFfMacScheduler::GetFfMacSchedSapProvider ()
{
return m_schedSapProvider;
}
void
CqaFfMacScheduler::SetLteFfrSapProvider (LteFfrSapProvider* s)
{
m_ffrSapProvider = s;
}
LteFfrSapUser*
CqaFfMacScheduler::GetLteFfrSapUser ()
{
return m_ffrSapUser;
}
void
CqaFfMacScheduler::DoCschedCellConfigReq (const struct FfMacCschedSapProvider::CschedCellConfigReqParameters& params)
{
NS_LOG_FUNCTION (this);
// Read the subset of parameters used
m_cschedCellConfig = params;
m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
FfMacCschedSapUser::CschedUeConfigCnfParameters cnf;
cnf.m_result = SUCCESS;
m_cschedSapUser->CschedUeConfigCnf (cnf);
return;
}
void
CqaFfMacScheduler::DoCschedUeConfigReq (const struct FfMacCschedSapProvider::CschedUeConfigReqParameters& params)
{
NS_LOG_FUNCTION (this << " RNTI " << params.m_rnti << " txMode " << (uint16_t)params.m_transmissionMode);
std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
if (it == m_uesTxMode.end ())
{
m_uesTxMode.insert (std::pair <uint16_t, uint8_t> (params.m_rnti, params.m_transmissionMode));
// generate HARQ buffers
m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
DlHarqProcessesStatus_t dlHarqPrcStatus;
dlHarqPrcStatus.resize (8,0);
m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
DlHarqProcessesTimer_t dlHarqProcessesTimer;
dlHarqProcessesTimer.resize (8,0);
m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
DlHarqProcessesDciBuffer_t dlHarqdci;
dlHarqdci.resize (8);
m_dlHarqProcessesDciBuffer.insert (std::pair <uint16_t, DlHarqProcessesDciBuffer_t> (params.m_rnti, dlHarqdci));
DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
dlHarqRlcPdu.resize (2);
dlHarqRlcPdu.at (0).resize (8);
dlHarqRlcPdu.at (1).resize (8);
m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
UlHarqProcessesStatus_t ulHarqPrcStatus;
ulHarqPrcStatus.resize (8,0);
m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
UlHarqProcessesDciBuffer_t ulHarqdci;
ulHarqdci.resize (8);
m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
}
else
{
(*it).second = params.m_transmissionMode;
}
return;
}
void
CqaFfMacScheduler::DoCschedLcConfigReq (const struct FfMacCschedSapProvider::CschedLcConfigReqParameters& params)
{
NS_LOG_FUNCTION (this << " New LC, rnti: " << params.m_rnti);
NS_LOG_FUNCTION ("LC configuration. Number of LCs:"<<params.m_logicalChannelConfigList.size ());
// m_reconfigureFlat indicates if this is a reconfiguration or new UE is added, table 4.1.5 in LTE MAC scheduler specification
if (params.m_reconfigureFlag)
{
std::vector <struct LogicalChannelConfigListElement_s>::const_iterator lcit;
for(lcit = params.m_logicalChannelConfigList.begin (); lcit!= params.m_logicalChannelConfigList.end (); lcit++)
{
LteFlowId_t flowid = LteFlowId_t (params.m_rnti,lcit->m_logicalChannelIdentity);
if (m_ueLogicalChannelsConfigList.find (flowid) == m_ueLogicalChannelsConfigList.end ())
{
NS_LOG_ERROR ("UE logical channels can not be reconfigured because it was not configured before.");
}
else
{
m_ueLogicalChannelsConfigList.find (flowid)->second = *lcit;
}
}
} // else new UE is added
else
{
std::vector <struct LogicalChannelConfigListElement_s>::const_iterator lcit;
for (lcit = params.m_logicalChannelConfigList.begin (); lcit != params.m_logicalChannelConfigList.end (); lcit++)
{
LteFlowId_t flowId = LteFlowId_t (params.m_rnti,lcit->m_logicalChannelIdentity);
m_ueLogicalChannelsConfigList.insert (std::pair<LteFlowId_t, LogicalChannelConfigListElement_s>(flowId,*lcit));
}
}
std::map <uint16_t, CqasFlowPerf_t>::iterator it;
for (uint16_t i = 0; i < params.m_logicalChannelConfigList.size (); i++)
{
it = m_flowStatsDl.find (params.m_rnti);
if (it == m_flowStatsDl.end ())
{
double tbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateDl / 8; // byte/s
double tbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateUl / 8; // byte/s
CqasFlowPerf_t flowStatsDl;
flowStatsDl.flowStart = Simulator::Now ();
flowStatsDl.totalBytesTransmitted = 0;
flowStatsDl.lastTtiBytesTransmitted = 0;
flowStatsDl.lastAveragedThroughput = 1;
flowStatsDl.secondLastAveragedThroughput = 1;
flowStatsDl.targetThroughput = tbrDlInBytes;
m_flowStatsDl.insert (std::pair<uint16_t, CqasFlowPerf_t> (params.m_rnti, flowStatsDl));
CqasFlowPerf_t flowStatsUl;
flowStatsUl.flowStart = Simulator::Now ();
flowStatsUl.totalBytesTransmitted = 0;
flowStatsUl.lastTtiBytesTransmitted = 0;
flowStatsUl.lastAveragedThroughput = 1;
flowStatsUl.secondLastAveragedThroughput = 1;
flowStatsUl.targetThroughput = tbrUlInBytes;
m_flowStatsUl.insert (std::pair<uint16_t, CqasFlowPerf_t> (params.m_rnti, flowStatsUl));
}
else
{
// update GBR from UeManager::SetupDataRadioBearer ()
double tbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateDl / 8; // byte/s
double tbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateUl / 8; // byte/s
m_flowStatsDl[(*it).first].targetThroughput = tbrDlInBytes;
m_flowStatsUl[(*it).first].targetThroughput = tbrUlInBytes;
}
}
return;
}
void
CqaFfMacScheduler::DoCschedLcReleaseReq (const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters& params)
{
NS_LOG_FUNCTION (this);
std::vector <uint8_t>::const_iterator it;
for (it = params.m_logicalChannelIdentity.begin (); it != params.m_logicalChannelIdentity.end (); it++)
{
LteFlowId_t flowId = LteFlowId_t (params.m_rnti, *it);
// find the logical channel with the same Logical Channel Identity in the current list, release it
if (m_ueLogicalChannelsConfigList.find (flowId)!= m_ueLogicalChannelsConfigList.end ())
{
m_ueLogicalChannelsConfigList.erase (flowId);
}
else
{
NS_FATAL_ERROR ("Logical channels cannot be released because it can not be found in the list of active LCs");
}
}
for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
{
std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
while (it!=m_rlcBufferReq.end ())
{
if (((*it).first.m_rnti == params.m_rnti) && ((*it).first.m_lcId == params.m_logicalChannelIdentity.at (i)))
{
temp = it;
it++;
m_rlcBufferReq.erase (temp);
}
else
{
it++;
}
}
}
return;
}
void
CqaFfMacScheduler::DoCschedUeReleaseReq (const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters& params)
{
NS_LOG_FUNCTION (this);
for (int i=0; i < MAX_LC_LIST; i++)
{
LteFlowId_t flowId = LteFlowId_t (params.m_rnti,i);
// find the logical channel with the same Logical Channel Identity in the current list, release it
if (m_ueLogicalChannelsConfigList.find (flowId)!= m_ueLogicalChannelsConfigList.end ())
{
m_ueLogicalChannelsConfigList.erase (flowId);
}
}
m_uesTxMode.erase (params.m_rnti);
m_dlHarqCurrentProcessId.erase (params.m_rnti);
m_dlHarqProcessesStatus.erase (params.m_rnti);
m_dlHarqProcessesTimer.erase (params.m_rnti);
m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
m_dlHarqProcessesRlcPduListBuffer.erase (params.m_rnti);
m_ulHarqCurrentProcessId.erase (params.m_rnti);
m_ulHarqProcessesStatus.erase (params.m_rnti);
m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
m_flowStatsDl.erase (params.m_rnti);
m_flowStatsUl.erase (params.m_rnti);
m_ceBsrRxed.erase (params.m_rnti);
std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
while (it!=m_rlcBufferReq.end ())
{
if ((*it).first.m_rnti == params.m_rnti)
{
temp = it;
it++;
m_rlcBufferReq.erase (temp);
}
else
{
it++;
}
}
if (m_nextRntiUl == params.m_rnti)
{
m_nextRntiUl = 0;
}
return;
}
void
CqaFfMacScheduler::DoSchedDlRlcBufferReq (const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters& params)
{
NS_LOG_FUNCTION (this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
// API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
LteFlowId_t flow (params.m_rnti, params.m_logicalChannelIdentity);
it = m_rlcBufferReq.find (flow);
if (it == m_rlcBufferReq.end ())
{
m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
}
else
{
(*it).second = params;
}
return;
}
void
CqaFfMacScheduler::DoSchedDlPagingBufferReq (const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters& params)
{
NS_LOG_FUNCTION (this);
NS_FATAL_ERROR ("method not implemented");
return;
}
void
CqaFfMacScheduler::DoSchedDlMacBufferReq (const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters& params)
{
NS_LOG_FUNCTION (this);
NS_FATAL_ERROR ("method not implemented");
return;
}
int
CqaFfMacScheduler::GetRbgSize (int dlbandwidth)
{
for (int i = 0; i < 4; i++)
{
if (dlbandwidth < CqaType0AllocationRbg[i])
{
return (i + 1);
}
}
return (-1);
}
int
CqaFfMacScheduler::LcActivePerFlow (uint16_t rnti)
{
std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
int lcActive = 0;
for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
{
if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
|| ((*it).second.m_rlcRetransmissionQueueSize > 0)
|| ((*it).second.m_rlcStatusPduSize > 0) ))
{
lcActive++;
}
if ((*it).first.m_rnti > rnti)
{
break;
}
}
return (lcActive);
}
uint8_t
CqaFfMacScheduler::HarqProcessAvailability (uint16_t rnti)
{
NS_LOG_FUNCTION (this << rnti);
std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
if (it == m_dlHarqCurrentProcessId.end ())
{
NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
}
std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
if (itStat == m_dlHarqProcessesStatus.end ())
{
NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
}
uint8_t i = (*it).second;
do
{
i = (i + 1) % HARQ_PROC_NUM;
}
while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
if ((*itStat).second.at (i) == 0)
{
return (true);
}
else
{
return (false); // return a not valid harq proc id
}
}
uint8_t
CqaFfMacScheduler::UpdateHarqProcessId (uint16_t rnti)
{
NS_LOG_FUNCTION (this << rnti);
if (m_harqOn == false)
{
return (0);
}
std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
if (it == m_dlHarqCurrentProcessId.end ())
{
NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
}
std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
if (itStat == m_dlHarqProcessesStatus.end ())
{
NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
}
uint8_t i = (*it).second;
do
{
i = (i + 1) % HARQ_PROC_NUM;
}
while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
if ((*itStat).second.at (i) == 0)
{
(*it).second = i;
(*itStat).second.at (i) = 1;
}
else
{
NS_FATAL_ERROR ("No HARQ process available for RNTI " << rnti << " check before update with HarqProcessAvailability");
}
return ((*it).second);
}
void
CqaFfMacScheduler::RefreshHarqProcesses ()
{
NS_LOG_FUNCTION (this);
std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers++)
{
for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
{
if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
{
// reset HARQ process
NS_LOG_DEBUG (this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
if (itStat == m_dlHarqProcessesStatus.end ())
{
NS_FATAL_ERROR ("No Process Id Status found for this RNTI " << (*itTimers).first);
}
(*itStat).second.at (i) = 0;
(*itTimers).second.at (i) = 0;
}
else
{
(*itTimers).second.at (i)++;
}
}
}
}
void
CqaFfMacScheduler::DoSchedDlTriggerReq (const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters& params)
{
NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
// API generated by RLC for triggering the scheduling of a DL subframe
// evaluate the relative channel quality indicator for each UE per each RBG
// (since we are using allocation type 0 the small unit of allocation is RBG)
// Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
RefreshDlCqiMaps ();
int rbgSize = GetRbgSize (m_cschedCellConfig.m_dlBandwidth);
int numberOfRBGs = m_cschedCellConfig.m_dlBandwidth / rbgSize;
std::map <uint16_t, std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> > allocationMapPerRntiPerLCId;
std::map <uint16_t, std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> >::iterator itMap;
allocationMapPerRntiPerLCId.clear ();
bool(*key_function_pointer_groups)(int,int) = CqaGroupDescComparator;
t_map_HOLgroupToUEs map_GBRHOLgroupToUE (key_function_pointer_groups);
t_map_HOLgroupToUEs map_nonGBRHOLgroupToUE (key_function_pointer_groups);
int grouping_parameter = 1000;
double tolerance = 1.1;
std::map<LteFlowId_t,int> UEtoHOL;
std::vector <bool> rbgMap; // global RBGs map
uint16_t rbgAllocatedNum = 0;
std::set <uint16_t> rntiAllocated;
rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
rbgMap = m_ffrSapProvider->GetAvailableDlRbg ();
for (std::vector<bool>::iterator it = rbgMap.begin (); it != rbgMap.end (); it++)
{
if ((*it) == true )
{
rbgAllocatedNum++;
}
}
FfMacSchedSapUser::SchedDlConfigIndParameters ret;
// update UL HARQ proc id
std::map <uint16_t, uint8_t>::iterator itProcId;
for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
{
(*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
}
// RACH Allocation
uint16_t rbAllocatedNum = 0;
std::vector <bool> ulRbMap;
ulRbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
ulRbMap = m_ffrSapProvider->GetAvailableUlRbg ();
uint8_t maxContinuousUlBandwidth = 0;
uint8_t tmpMinBandwidth = 0;
uint16_t ffrRbStartOffset = 0;
uint16_t tmpFfrRbStartOffset = 0;
uint16_t index = 0;
for (std::vector<bool>::iterator it = ulRbMap.begin (); it != ulRbMap.end (); it++)
{
if ((*it) == true )
{
rbAllocatedNum++;
if (tmpMinBandwidth > maxContinuousUlBandwidth)
{
maxContinuousUlBandwidth = tmpMinBandwidth;
ffrRbStartOffset = tmpFfrRbStartOffset;
}
tmpMinBandwidth = 0;
}
else
{
if (tmpMinBandwidth == 0)
{
tmpFfrRbStartOffset = index;
}
tmpMinBandwidth++;
}
index++;
}
if (tmpMinBandwidth > maxContinuousUlBandwidth)
{
maxContinuousUlBandwidth = tmpMinBandwidth;
ffrRbStartOffset = tmpFfrRbStartOffset;
}
m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
uint16_t rbStart = 0;
rbStart = ffrRbStartOffset;
std::vector <struct RachListElement_s>::iterator itRach;
for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
{
NS_ASSERT_MSG (m_amc->GetTbSizeFromMcs (m_ulGrantMcs, m_cschedCellConfig.m_ulBandwidth) > (*itRach).m_estimatedSize, " Default UL Grant MCS does not allow to send RACH messages");
BuildRarListElement_s newRar;
newRar.m_rnti = (*itRach).m_rnti;
// DL-RACH Allocation
// Ideal: no needs of configuring m_dci
// UL-RACH Allocation
newRar.m_grant.m_rnti = newRar.m_rnti;
newRar.m_grant.m_mcs = m_ulGrantMcs;
uint16_t rbLen = 1;
uint16_t tbSizeBits = 0;
// find lowest TB size that fits UL grant estimated size
while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < (ffrRbStartOffset + maxContinuousUlBandwidth)))
{
rbLen++;
tbSizeBits = m_amc->GetTbSizeFromMcs (m_ulGrantMcs, rbLen);
}
if (tbSizeBits < (*itRach).m_estimatedSize)
{
// no more allocation space: finish allocation
break;
}
newRar.m_grant.m_rbStart = rbStart;
newRar.m_grant.m_rbLen = rbLen;
newRar.m_grant.m_tbSize = tbSizeBits / 8;
newRar.m_grant.m_hopping = false;
newRar.m_grant.m_tpc = 0;
newRar.m_grant.m_cqiRequest = false;
newRar.m_grant.m_ulDelay = false;
NS_LOG_INFO (this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart " << rbStart << " rbLen " << rbLen << " MCS " << m_ulGrantMcs << " tbSize " << newRar.m_grant.m_tbSize);
for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
{
m_rachAllocationMap.at (i) = (*itRach).m_rnti;
}
if (m_harqOn == true)
{
// generate UL-DCI for HARQ retransmissions
UlDciListElement_s uldci;
uldci.m_rnti = newRar.m_rnti;
uldci.m_rbLen = rbLen;
uldci.m_rbStart = rbStart;
uldci.m_mcs = m_ulGrantMcs;
uldci.m_tbSize = tbSizeBits / 8;
uldci.m_ndi = 1;
uldci.m_cceIndex = 0;
uldci.m_aggrLevel = 1;
uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
uldci.m_hopping = false;
uldci.m_n2Dmrs = 0;
uldci.m_tpc = 0; // no power control
uldci.m_cqiRequest = false; // only period CQI at this stage
uldci.m_ulIndex = 0; // TDD parameter
uldci.m_dai = 1; // TDD parameter
uldci.m_freqHopping = 0;
uldci.m_pdcchPowerOffset = 0; // not used
uint8_t harqId = 0;
std::map <uint16_t, uint8_t>::iterator itProcId;
itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
if (itProcId == m_ulHarqCurrentProcessId.end ())
{
NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
}
harqId = (*itProcId).second;
std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
if (itDci == m_ulHarqProcessesDciBuffer.end ())
{
NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
}
(*itDci).second.at (harqId) = uldci;
}
rbStart = rbStart + rbLen;
ret.m_buildRarList.push_back (newRar);
}
m_rachList.clear ();
// Process DL HARQ feedback
RefreshHarqProcesses ();
// retrieve past HARQ retx buffered
if (m_dlInfoListBuffered.size () > 0)
{
if (params.m_dlInfoList.size () > 0)
{
NS_LOG_INFO (this << " Received DL-HARQ feedback");
m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
}
}
else
{
if (params.m_dlInfoList.size () > 0)
{
m_dlInfoListBuffered = params.m_dlInfoList;
}
}
if (m_harqOn == false)
{
// Ignore HARQ feedback
m_dlInfoListBuffered.clear ();
}
std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
{
std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
if (itRnti != rntiAllocated.end ())
{
// RNTI already allocated for retx
continue;
}
uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
std::vector <bool> retx;
NS_LOG_INFO (this << " Processing DLHARQ feedback");
if (nLayers == 1)
{
retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
retx.push_back (false);
}
else
{
retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
}
if (retx.at (0) || retx.at (1))
{
// retrieve HARQ process information
uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
NS_LOG_INFO (this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
if (itHarq == m_dlHarqProcessesDciBuffer.end ())