A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
cqa-ff-mac-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Biljana Bojovic <bbojovic@cttc.es>, Nicola Baldo<nbaldo@cttc.es>.
7 *
8 * Note:
9 * Implementation is using many common scheduler functionalities in its
10 * original version implemented by Marco Miozzo<mmiozzo@cttc.es> in
11 * Proportional Fair and Round Robin schedulers implementations.
12 */
13
15
16#include "ff-mac-common.h"
17#include "lte-amc.h"
19
20#include "ns3/boolean.h"
21#include "ns3/integer.h"
22#include "ns3/log.h"
23#include "ns3/math.h"
24#include "ns3/pointer.h"
25#include "ns3/simulator.h"
26#include "ns3/string.h"
27
28#include <cfloat>
29#include <set>
30#include <stdexcept>
31
32namespace ns3
33{
34
35NS_LOG_COMPONENT_DEFINE("CqaFfMacScheduler");
36
38
39/// qos_rb_and_CQI_assigned_to_lc
41{
42 uint16_t resource_block_index; ///< Resource block indexHOL_GROUP_index
43 uint8_t cqi_value_for_lc; ///< CQI indicator value
44};
45
46/**
47 * CQI value comparator function
48 * @param key1 the first item
49 * @param key2 the second item
50 * @returns true if the first item is > the second item
51 */
52bool
53CQIValueDescComparator(uint8_t key1, uint8_t key2)
54{
55 return key1 > key2;
56}
57
58/**
59 * CGA group comparator function
60 * @param key1 the first item
61 * @param key2 the second item
62 * @returns true if the first item is > the second item
63 */
64bool
65CqaGroupDescComparator(int key1, int key2)
66{
67 return key1 > key2;
68}
69
70/// CQI value typedef
71typedef uint8_t CQI_value;
72/// RBG index typedef
73typedef int RBG_index;
74/// HOL group typedef
75typedef int HOL_group;
76
77/// CQI value map typedef
78typedef std::map<CQI_value, LteFlowId_t, bool (*)(uint8_t, uint8_t)> t_map_CQIToUE; // sorted
79/// RBG index map typedef
80typedef std::map<RBG_index, t_map_CQIToUE> t_map_RBGToCQIsSorted;
81/// HOL group map typedef
82typedef std::map<HOL_group, t_map_RBGToCQIsSorted> t_map_HOLGroupToRBGs;
83
84/// CQI value map iterator typedef
85typedef std::map<CQI_value, LteFlowId_t, bool (*)(uint8_t, uint8_t)>::iterator
86 t_it_CQIToUE; // sorted
87/// RBG index map iterator typedef
88typedef std::map<RBG_index, t_map_CQIToUE>::iterator t_it_RBGToCQIsSorted;
89/// HOL group map iterator typedef
90typedef std::map<HOL_group, t_map_RBGToCQIsSorted>::iterator t_it_HOLGroupToRBGs;
91
92/// HOL group map typedef
93typedef std::multimap<HOL_group, std::set<LteFlowId_t>, bool (*)(int, int)> t_map_HOLgroupToUEs;
94/// HOL group multi map iterator typedef
95typedef std::map<HOL_group, std::set<LteFlowId_t>>::iterator t_it_HOLgroupToUEs;
96
97// typedef std::map<RBG_index,CQI_value> map_RBG_to_CQI;
98// typedef std::map<LteFlowId_t,map_RBG_to_CQI> map_flowId_to_CQI_map;
99
100/**
101 * CQA key comparator
102 * @param key1 the first item
103 * @param key2 the second item
104 * @returns true if the first item > the second item
105 */
106bool
107CqaKeyDescComparator(uint16_t key1, uint16_t key2)
108{
109 return key1 > key2;
110}
111
124
129
130void
145
146TypeId
148{
149 static TypeId tid =
150 TypeId("ns3::CqaFfMacScheduler")
152 .SetGroupName("Lte")
153 .AddConstructor<CqaFfMacScheduler>()
154 .AddAttribute("CqiTimerThreshold",
155 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
156 UintegerValue(1000),
159 .AddAttribute("CqaMetric",
160 "CqaFfMacScheduler metric type that can be: CqaFf, CqaPf",
161 StringValue("CqaFf"),
164 .AddAttribute("HarqEnabled",
165 "Activate/Deactivate the HARQ [by default is active].",
166 BooleanValue(true),
169 .AddAttribute("UlGrantMcs",
170 "The MCS of the UL grant, must be [0..15] (default 0)",
171 UintegerValue(0),
174 return tid;
175}
176
177void
182
183void
188
194
200
201void
206
212
213void
216{
217 NS_LOG_FUNCTION(this);
218 // Read the subset of parameters used
219 m_cschedCellConfig = params;
220 m_rachAllocationMap.resize(m_cschedCellConfig.m_ulBandwidth, 0);
222 cnf.m_result = SUCCESS;
223 m_cschedSapUser->CschedUeConfigCnf(cnf);
224}
225
226void
229{
230 NS_LOG_FUNCTION(this << " RNTI " << params.m_rnti << " txMode "
231 << (uint16_t)params.m_transmissionMode);
232 auto it = m_uesTxMode.find(params.m_rnti);
233 if (it == m_uesTxMode.end())
234 {
235 m_uesTxMode.insert(std::pair<uint16_t, uint8_t>(params.m_rnti, params.m_transmissionMode));
236 // generate HARQ buffers
237 m_dlHarqCurrentProcessId.insert(std::pair<uint16_t, uint8_t>(params.m_rnti, 0));
238 DlHarqProcessesStatus_t dlHarqPrcStatus;
239 dlHarqPrcStatus.resize(8, 0);
240 m_dlHarqProcessesStatus[params.m_rnti] = dlHarqPrcStatus;
241 DlHarqProcessesTimer_t dlHarqProcessesTimer;
242 dlHarqProcessesTimer.resize(8, 0);
243 m_dlHarqProcessesTimer[params.m_rnti] = dlHarqProcessesTimer;
245 dlHarqdci.resize(8);
246 m_dlHarqProcessesDciBuffer[params.m_rnti] = dlHarqdci;
247 DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
248 dlHarqRlcPdu.resize(2);
249 dlHarqRlcPdu.at(0).resize(8);
250 dlHarqRlcPdu.at(1).resize(8);
251 m_dlHarqProcessesRlcPduListBuffer[params.m_rnti] = dlHarqRlcPdu;
252 m_ulHarqCurrentProcessId.insert(std::pair<uint16_t, uint8_t>(params.m_rnti, 0));
253 UlHarqProcessesStatus_t ulHarqPrcStatus;
254 ulHarqPrcStatus.resize(8, 0);
255 m_ulHarqProcessesStatus[params.m_rnti] = ulHarqPrcStatus;
257 ulHarqdci.resize(8);
258 m_ulHarqProcessesDciBuffer[params.m_rnti] = ulHarqdci;
259 }
260 else
261 {
262 (*it).second = params.m_transmissionMode;
263 }
264}
265
266void
269{
270 NS_LOG_FUNCTION(this << " New LC, rnti: " << params.m_rnti);
271
272 NS_LOG_FUNCTION("LC configuration. Number of LCs:" << params.m_logicalChannelConfigList.size());
273
274 // m_reconfigureFlat indicates if this is a reconfiguration or new UE is added, table 4.1.5 in
275 // LTE MAC scheduler specification
276 if (params.m_reconfigureFlag)
277 {
278 for (auto lcit = params.m_logicalChannelConfigList.begin();
279 lcit != params.m_logicalChannelConfigList.end();
280 lcit++)
281 {
282 LteFlowId_t flowid = LteFlowId_t(params.m_rnti, lcit->m_logicalChannelIdentity);
283
285 {
286 NS_LOG_ERROR("UE logical channels can not be reconfigured because it was not "
287 "configured before.");
288 }
289 else
290 {
291 m_ueLogicalChannelsConfigList.find(flowid)->second = *lcit;
292 }
293 }
294 }
295 else
296 {
297 // Add new UE
298 for (auto lcit = params.m_logicalChannelConfigList.begin();
299 lcit != params.m_logicalChannelConfigList.end();
300 lcit++)
301 {
302 LteFlowId_t flowId = LteFlowId_t(params.m_rnti, lcit->m_logicalChannelIdentity);
304 std::pair<LteFlowId_t, LogicalChannelConfigListElement_s>(flowId, *lcit));
305 }
306 }
307
308 for (std::size_t i = 0; i < params.m_logicalChannelConfigList.size(); i++)
309 {
310 auto it = m_flowStatsDl.find(params.m_rnti);
311
312 if (it == m_flowStatsDl.end())
313 {
314 double tbrDlInBytes =
315 params.m_logicalChannelConfigList.at(i).m_eRabGuaranteedBitrateDl / 8; // byte/s
316 double tbrUlInBytes =
317 params.m_logicalChannelConfigList.at(i).m_eRabGuaranteedBitrateUl / 8; // byte/s
318
319 CqasFlowPerf_t flowStatsDl;
320 flowStatsDl.flowStart = Simulator::Now();
321 flowStatsDl.totalBytesTransmitted = 0;
322 flowStatsDl.lastTtiBytesTransmitted = 0;
323 flowStatsDl.lastAveragedThroughput = 1;
324 flowStatsDl.secondLastAveragedThroughput = 1;
325 flowStatsDl.targetThroughput = tbrDlInBytes;
326 m_flowStatsDl.insert(std::pair<uint16_t, CqasFlowPerf_t>(params.m_rnti, flowStatsDl));
327 CqasFlowPerf_t flowStatsUl;
328 flowStatsUl.flowStart = Simulator::Now();
329 flowStatsUl.totalBytesTransmitted = 0;
330 flowStatsUl.lastTtiBytesTransmitted = 0;
331 flowStatsUl.lastAveragedThroughput = 1;
332 flowStatsUl.secondLastAveragedThroughput = 1;
333 flowStatsUl.targetThroughput = tbrUlInBytes;
334 m_flowStatsUl.insert(std::pair<uint16_t, CqasFlowPerf_t>(params.m_rnti, flowStatsUl));
335 }
336 else
337 {
338 // update GBR from UeManager::SetupDataRadioBearer ()
339 double tbrDlInBytes =
340 params.m_logicalChannelConfigList.at(i).m_eRabGuaranteedBitrateDl / 8; // byte/s
341 double tbrUlInBytes =
342 params.m_logicalChannelConfigList.at(i).m_eRabGuaranteedBitrateUl / 8; // byte/s
343 m_flowStatsDl[(*it).first].targetThroughput = tbrDlInBytes;
344 m_flowStatsUl[(*it).first].targetThroughput = tbrUlInBytes;
345 }
346 }
347}
348
349void
352{
353 NS_LOG_FUNCTION(this);
354
355 for (auto it = params.m_logicalChannelIdentity.begin();
356 it != params.m_logicalChannelIdentity.end();
357 it++)
358 {
359 LteFlowId_t flowId = LteFlowId_t(params.m_rnti, *it);
360
361 // find the logical channel with the same Logical Channel Identity in the current list,
362 // release it
364 {
365 m_ueLogicalChannelsConfigList.erase(flowId);
366 }
367 else
368 {
369 NS_FATAL_ERROR("Logical channels cannot be released because it can not be found in the "
370 "list of active LCs");
371 }
372 }
373
374 for (std::size_t i = 0; i < params.m_logicalChannelIdentity.size(); i++)
375 {
376 auto it = m_rlcBufferReq.begin();
377 while (it != m_rlcBufferReq.end())
378 {
379 if (((*it).first.m_rnti == params.m_rnti) &&
380 ((*it).first.m_lcId == params.m_logicalChannelIdentity.at(i)))
381 {
382 auto temp = it;
383 it++;
384 m_rlcBufferReq.erase(temp);
385 }
386 else
387 {
388 it++;
389 }
390 }
391 }
392}
393
394void
397{
398 NS_LOG_FUNCTION(this);
399
400 for (int i = 0; i < MAX_LC_LIST; i++)
401 {
402 LteFlowId_t flowId = LteFlowId_t(params.m_rnti, i);
403 // find the logical channel with the same Logical Channel Identity in the current list,
404 // release it
406 {
407 m_ueLogicalChannelsConfigList.erase(flowId);
408 }
409 }
410
411 m_uesTxMode.erase(params.m_rnti);
412 m_dlHarqCurrentProcessId.erase(params.m_rnti);
413 m_dlHarqProcessesStatus.erase(params.m_rnti);
414 m_dlHarqProcessesTimer.erase(params.m_rnti);
415 m_dlHarqProcessesDciBuffer.erase(params.m_rnti);
416 m_dlHarqProcessesRlcPduListBuffer.erase(params.m_rnti);
417 m_ulHarqCurrentProcessId.erase(params.m_rnti);
418 m_ulHarqProcessesStatus.erase(params.m_rnti);
419 m_ulHarqProcessesDciBuffer.erase(params.m_rnti);
420 m_flowStatsDl.erase(params.m_rnti);
421 m_flowStatsUl.erase(params.m_rnti);
422 m_ceBsrRxed.erase(params.m_rnti);
423 auto it = m_rlcBufferReq.begin();
424 while (it != m_rlcBufferReq.end())
425 {
426 if ((*it).first.m_rnti == params.m_rnti)
427 {
428 auto temp = it;
429 it++;
430 m_rlcBufferReq.erase(temp);
431 }
432 else
433 {
434 it++;
435 }
436 }
437 if (m_nextRntiUl == params.m_rnti)
438 {
439 m_nextRntiUl = 0;
440 }
441}
442
443void
446{
447 NS_LOG_FUNCTION(this << params.m_rnti << (uint32_t)params.m_logicalChannelIdentity);
448 // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
449
450 LteFlowId_t flow(params.m_rnti, params.m_logicalChannelIdentity);
451
452 auto it = m_rlcBufferReq.find(flow);
453
454 if (it == m_rlcBufferReq.end())
455 {
456 m_rlcBufferReq[flow] = params;
457 }
458 else
459 {
460 (*it).second = params;
461 }
462}
463
464void
471
472void
479
480unsigned int
482{
483 unsigned int lcActive = 0;
484 for (auto it = m_rlcBufferReq.begin(); it != m_rlcBufferReq.end(); it++)
485 {
486 if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0) ||
487 ((*it).second.m_rlcRetransmissionQueueSize > 0) ||
488 ((*it).second.m_rlcStatusPduSize > 0)))
489 {
490 lcActive++;
491 }
492 if ((*it).first.m_rnti > rnti)
493 {
494 break;
495 }
496 }
497 return lcActive;
498}
499
500bool
502{
503 NS_LOG_FUNCTION(this << rnti);
504
505 auto it = m_dlHarqCurrentProcessId.find(rnti);
506 if (it == m_dlHarqCurrentProcessId.end())
507 {
508 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
509 }
510 auto itStat = m_dlHarqProcessesStatus.find(rnti);
511 if (itStat == m_dlHarqProcessesStatus.end())
512 {
513 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
514 }
515 uint8_t i = (*it).second;
516 do
517 {
518 i = (i + 1) % HARQ_PROC_NUM;
519 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
520
521 return (*itStat).second.at(i) == 0;
522}
523
524uint8_t
526{
527 NS_LOG_FUNCTION(this << rnti);
528
529 if (!m_harqOn)
530 {
531 return 0;
532 }
533
534 auto it = m_dlHarqCurrentProcessId.find(rnti);
535 if (it == m_dlHarqCurrentProcessId.end())
536 {
537 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
538 }
539 auto itStat = m_dlHarqProcessesStatus.find(rnti);
540 if (itStat == m_dlHarqProcessesStatus.end())
541 {
542 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
543 }
544 uint8_t i = (*it).second;
545 do
546 {
547 i = (i + 1) % HARQ_PROC_NUM;
548 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
549 if ((*itStat).second.at(i) == 0)
550 {
551 (*it).second = i;
552 (*itStat).second.at(i) = 1;
553 }
554 else
555 {
556 NS_FATAL_ERROR("No HARQ process available for RNTI "
557 << rnti << " check before update with HarqProcessAvailability");
558 }
559
560 return (*it).second;
561}
562
563void
565{
566 NS_LOG_FUNCTION(this);
567
568 for (auto itTimers = m_dlHarqProcessesTimer.begin(); itTimers != m_dlHarqProcessesTimer.end();
569 itTimers++)
570 {
571 for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
572 {
573 if ((*itTimers).second.at(i) == HARQ_DL_TIMEOUT)
574 {
575 // reset HARQ process
576
577 NS_LOG_DEBUG(this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
578 auto itStat = m_dlHarqProcessesStatus.find((*itTimers).first);
579 if (itStat == m_dlHarqProcessesStatus.end())
580 {
581 NS_FATAL_ERROR("No Process Id Status found for this RNTI "
582 << (*itTimers).first);
583 }
584 (*itStat).second.at(i) = 0;
585 (*itTimers).second.at(i) = 0;
586 }
587 else
588 {
589 (*itTimers).second.at(i)++;
590 }
591 }
592 }
593}
594
595void
598{
599 NS_LOG_FUNCTION(this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
600 << (0xF & params.m_sfnSf));
601 // API generated by RLC for triggering the scheduling of a DL subframe
602 // evaluate the relative channel quality indicator for each UE per each RBG
603 // (since we are using allocation type 0 the small unit of allocation is RBG)
604 // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
605
607
608 int rbgSize = GetLteRbgSize(m_cschedCellConfig.m_dlBandwidth);
609 int numberOfRBGs = m_cschedCellConfig.m_dlBandwidth / rbgSize;
610 std::map<uint16_t, std::multimap<uint8_t, qos_rb_and_CQI_assigned_to_lc>>
611 allocationMapPerRntiPerLCId;
612 allocationMapPerRntiPerLCId.clear();
613 bool (*key_function_pointer_groups)(int, int) = CqaGroupDescComparator;
614 t_map_HOLgroupToUEs map_GBRHOLgroupToUE(key_function_pointer_groups);
615 t_map_HOLgroupToUEs map_nonGBRHOLgroupToUE(key_function_pointer_groups);
616 int grouping_parameter = 1000;
617 double tolerance = 1.1;
618 std::map<LteFlowId_t, int> UEtoHOL;
619 std::vector<bool> rbgMap; // global RBGs map
620 uint16_t rbgAllocatedNum = 0;
621 std::set<uint16_t> rntiAllocated;
622 rbgMap.resize(m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
623
624 rbgMap = m_ffrSapProvider->GetAvailableDlRbg();
625 for (auto it = rbgMap.begin(); it != rbgMap.end(); it++)
626 {
627 if (*it)
628 {
629 rbgAllocatedNum++;
630 }
631 }
632
634
635 // update UL HARQ proc id
636 for (auto itProcId = m_ulHarqCurrentProcessId.begin();
637 itProcId != m_ulHarqCurrentProcessId.end();
638 itProcId++)
639 {
640 (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
641 }
642
643 // RACH Allocation
644 std::vector<bool> ulRbMap;
645 ulRbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
646 ulRbMap = m_ffrSapProvider->GetAvailableUlRbg();
647 uint8_t maxContinuousUlBandwidth = 0;
648 uint8_t tmpMinBandwidth = 0;
649 uint16_t ffrRbStartOffset = 0;
650 uint16_t tmpFfrRbStartOffset = 0;
651 uint16_t index = 0;
652
653 for (auto it = ulRbMap.begin(); it != ulRbMap.end(); it++)
654 {
655 if (*it)
656 {
657 if (tmpMinBandwidth > maxContinuousUlBandwidth)
658 {
659 maxContinuousUlBandwidth = tmpMinBandwidth;
660 ffrRbStartOffset = tmpFfrRbStartOffset;
661 }
662 tmpMinBandwidth = 0;
663 }
664 else
665 {
666 if (tmpMinBandwidth == 0)
667 {
668 tmpFfrRbStartOffset = index;
669 }
670 tmpMinBandwidth++;
671 }
672 index++;
673 }
674
675 if (tmpMinBandwidth > maxContinuousUlBandwidth)
676 {
677 maxContinuousUlBandwidth = tmpMinBandwidth;
678 ffrRbStartOffset = tmpFfrRbStartOffset;
679 }
680
681 m_rachAllocationMap.resize(m_cschedCellConfig.m_ulBandwidth, 0);
682 uint16_t rbStart = 0;
683 rbStart = ffrRbStartOffset;
684 for (auto itRach = m_rachList.begin(); itRach != m_rachList.end(); itRach++)
685 {
686 NS_ASSERT_MSG(m_amc->GetUlTbSizeFromMcs(m_ulGrantMcs, m_cschedCellConfig.m_ulBandwidth) >
687 (*itRach).m_estimatedSize,
688 " Default UL Grant MCS does not allow to send RACH messages");
690 newRar.m_rnti = (*itRach).m_rnti;
691 // DL-RACH Allocation
692 // Ideal: no needs of configuring m_dci
693 // UL-RACH Allocation
694 newRar.m_grant.m_rnti = newRar.m_rnti;
695 newRar.m_grant.m_mcs = m_ulGrantMcs;
696 uint16_t rbLen = 1;
697 uint16_t tbSizeBits = 0;
698 // find lowest TB size that fits UL grant estimated size
699 while ((tbSizeBits < (*itRach).m_estimatedSize) &&
700 (rbStart + rbLen < (ffrRbStartOffset + maxContinuousUlBandwidth)))
701 {
702 rbLen++;
703 tbSizeBits = m_amc->GetUlTbSizeFromMcs(m_ulGrantMcs, rbLen);
704 }
705 if (tbSizeBits < (*itRach).m_estimatedSize)
706 {
707 // no more allocation space: finish allocation
708 break;
709 }
710 newRar.m_grant.m_rbStart = rbStart;
711 newRar.m_grant.m_rbLen = rbLen;
712 newRar.m_grant.m_tbSize = tbSizeBits / 8;
713 newRar.m_grant.m_hopping = false;
714 newRar.m_grant.m_tpc = 0;
715 newRar.m_grant.m_cqiRequest = false;
716 newRar.m_grant.m_ulDelay = false;
717 NS_LOG_INFO(this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart "
718 << rbStart << " rbLen " << rbLen << " MCS " << m_ulGrantMcs << " tbSize "
719 << newRar.m_grant.m_tbSize);
720 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
721 {
722 m_rachAllocationMap.at(i) = (*itRach).m_rnti;
723 }
724
725 if (m_harqOn)
726 {
727 // generate UL-DCI for HARQ retransmissions
728 UlDciListElement_s uldci;
729 uldci.m_rnti = newRar.m_rnti;
730 uldci.m_rbLen = rbLen;
731 uldci.m_rbStart = rbStart;
732 uldci.m_mcs = m_ulGrantMcs;
733 uldci.m_tbSize = tbSizeBits / 8;
734 uldci.m_ndi = 1;
735 uldci.m_cceIndex = 0;
736 uldci.m_aggrLevel = 1;
737 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
738 uldci.m_hopping = false;
739 uldci.m_n2Dmrs = 0;
740 uldci.m_tpc = 0; // no power control
741 uldci.m_cqiRequest = false; // only period CQI at this stage
742 uldci.m_ulIndex = 0; // TDD parameter
743 uldci.m_dai = 1; // TDD parameter
744 uldci.m_freqHopping = 0;
745 uldci.m_pdcchPowerOffset = 0; // not used
746
747 uint8_t harqId = 0;
748 auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
749 if (itProcId == m_ulHarqCurrentProcessId.end())
750 {
751 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
752 }
753 harqId = (*itProcId).second;
754 auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
755 if (itDci == m_ulHarqProcessesDciBuffer.end())
756 {
757 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
758 << uldci.m_rnti);
759 }
760 (*itDci).second.at(harqId) = uldci;
761 }
762
763 rbStart = rbStart + rbLen;
764 ret.m_buildRarList.push_back(newRar);
765 }
766 m_rachList.clear();
767
768 // Process DL HARQ feedback
770 // retrieve past HARQ retx buffered
771 if (!m_dlInfoListBuffered.empty())
772 {
773 if (!params.m_dlInfoList.empty())
774 {
775 NS_LOG_INFO(this << " Received DL-HARQ feedback");
777 params.m_dlInfoList.begin(),
778 params.m_dlInfoList.end());
779 }
780 }
781 else
782 {
783 if (!params.m_dlInfoList.empty())
784 {
785 m_dlInfoListBuffered = params.m_dlInfoList;
786 }
787 }
788 if (!m_harqOn)
789 {
790 // Ignore HARQ feedback
791 m_dlInfoListBuffered.clear();
792 }
793 std::vector<DlInfoListElement_s> dlInfoListUntxed;
794 for (std::size_t i = 0; i < m_dlInfoListBuffered.size(); i++)
795 {
796 auto itRnti = rntiAllocated.find(m_dlInfoListBuffered.at(i).m_rnti);
797 if (itRnti != rntiAllocated.end())
798 {
799 // RNTI already allocated for retx
800 continue;
801 }
802 auto nLayers = m_dlInfoListBuffered.at(i).m_harqStatus.size();
803 std::vector<bool> retx;
804 retx.reserve(2);
805 NS_LOG_INFO(this << " Processing DLHARQ feedback");
806 if (nLayers == 1)
807 {
808 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
810 retx.push_back(false);
811 }
812 else
813 {
814 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
816 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(1) ==
818 }
819 if (retx.at(0) || retx.at(1))
820 {
821 // retrieve HARQ process information
822 uint16_t rnti = m_dlInfoListBuffered.at(i).m_rnti;
823 uint8_t harqId = m_dlInfoListBuffered.at(i).m_harqProcessId;
824 NS_LOG_INFO(this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
825 auto itHarq = m_dlHarqProcessesDciBuffer.find(rnti);
826 if (itHarq == m_dlHarqProcessesDciBuffer.end())
827 {
828 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << rnti);
829 }
830
831 DlDciListElement_s dci = (*itHarq).second.at(harqId);
832 int rv = 0;
833 if (dci.m_rv.size() == 1)
834 {
835 rv = dci.m_rv.at(0);
836 }
837 else
838 {
839 rv = (dci.m_rv.at(0) > dci.m_rv.at(1) ? dci.m_rv.at(0) : dci.m_rv.at(1));
840 }
841
842 if (rv == 3)
843 {
844 // maximum number of retx reached -> drop process
845 NS_LOG_INFO("Maximum number of retransmissions reached -> drop process");
846 auto it = m_dlHarqProcessesStatus.find(rnti);
847 if (it == m_dlHarqProcessesStatus.end())
848 {
849 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
850 << m_dlInfoListBuffered.at(i).m_rnti);
851 }
852 (*it).second.at(harqId) = 0;
853 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
854 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
855 {
856 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
857 << m_dlInfoListBuffered.at(i).m_rnti);
858 }
859 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
860 {
861 (*itRlcPdu).second.at(k).at(harqId).clear();
862 }
863 continue;
864 }
865 // check the feasibility of retransmitting on the same RBGs
866 // translate the DCI to Spectrum framework
867 std::vector<int> dciRbg;
868 uint32_t mask = 0x1;
869 NS_LOG_INFO("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
870 for (int j = 0; j < 32; j++)
871 {
872 if (((dci.m_rbBitmap & mask) >> j) == 1)
873 {
874 dciRbg.push_back(j);
875 NS_LOG_INFO("\t" << j);
876 }
877 mask = (mask << 1);
878 }
879 bool free = true;
880 for (std::size_t j = 0; j < dciRbg.size(); j++)
881 {
882 if (rbgMap.at(dciRbg.at(j)))
883 {
884 free = false;
885 break;
886 }
887 }
888 if (free)
889 {
890 // use the same RBGs for the retx
891 // reserve RBGs
892 for (std::size_t j = 0; j < dciRbg.size(); j++)
893 {
894 rbgMap.at(dciRbg.at(j)) = true;
895 NS_LOG_INFO("RBG " << dciRbg.at(j) << " assigned");
896 rbgAllocatedNum++;
897 }
898
899 NS_LOG_INFO(this << " Send retx in the same RBGs");
900 }
901 else
902 {
903 // find RBGs for sending HARQ retx
904 uint8_t j = 0;
905 uint8_t rbgId = (dciRbg.at(dciRbg.size() - 1) + 1) % numberOfRBGs;
906 uint8_t startRbg = dciRbg.at(dciRbg.size() - 1);
907 std::vector<bool> rbgMapCopy = rbgMap;
908 while ((j < dciRbg.size()) && (startRbg != rbgId))
909 {
910 if (!rbgMapCopy.at(rbgId))
911 {
912 rbgMapCopy.at(rbgId) = true;
913 dciRbg.at(j) = rbgId;
914 j++;
915 }
916 rbgId = (rbgId + 1) % numberOfRBGs;
917 }
918 if (j == dciRbg.size())
919 {
920 // find new RBGs -> update DCI map
921 uint32_t rbgMask = 0;
922 for (std::size_t k = 0; k < dciRbg.size(); k++)
923 {
924 rbgMask = rbgMask + (0x1 << dciRbg.at(k));
925 rbgAllocatedNum++;
926 }
927 dci.m_rbBitmap = rbgMask;
928 rbgMap = rbgMapCopy;
929 NS_LOG_INFO(this << " Move retx in RBGs " << dciRbg.size());
930 }
931 else
932 {
933 // HARQ retx cannot be performed on this TTI -> store it
934 dlInfoListUntxed.push_back(m_dlInfoListBuffered.at(i));
935 NS_LOG_INFO(this << " No resource for this retx -> buffer it");
936 }
937 }
938 // retrieve RLC PDU list for retx TBsize and update DCI
940 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
941 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
942 {
943 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
944 }
945 for (std::size_t j = 0; j < nLayers; j++)
946 {
947 if (retx.at(j))
948 {
949 if (j >= dci.m_ndi.size())
950 {
951 // for avoiding errors in MIMO transient phases
952 dci.m_ndi.push_back(0);
953 dci.m_rv.push_back(0);
954 dci.m_mcs.push_back(0);
955 dci.m_tbsSize.push_back(0);
956 NS_LOG_INFO(this << " layer " << (uint16_t)j
957 << " no txed (MIMO transition)");
958 }
959 else
960 {
961 dci.m_ndi.at(j) = 0;
962 dci.m_rv.at(j)++;
963 (*itHarq).second.at(harqId).m_rv.at(j)++;
964 NS_LOG_INFO(this << " layer " << (uint16_t)j << " RV "
965 << (uint16_t)dci.m_rv.at(j));
966 }
967 }
968 else
969 {
970 // empty TB of layer j
971 dci.m_ndi.at(j) = 0;
972 dci.m_rv.at(j) = 0;
973 dci.m_mcs.at(j) = 0;
974 dci.m_tbsSize.at(j) = 0;
975 NS_LOG_INFO(this << " layer " << (uint16_t)j << " no retx");
976 }
977 }
978 for (std::size_t k = 0; k < (*itRlcPdu).second.at(0).at(dci.m_harqProcess).size(); k++)
979 {
980 std::vector<RlcPduListElement_s> rlcPduListPerLc;
981 for (std::size_t j = 0; j < nLayers; j++)
982 {
983 if (retx.at(j))
984 {
985 if (j < dci.m_ndi.size())
986 {
987 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size "
988 << dci.m_tbsSize.at(j));
989 rlcPduListPerLc.push_back(
990 (*itRlcPdu).second.at(j).at(dci.m_harqProcess).at(k));
991 }
992 }
993 else
994 { // if no retx needed on layer j, push an RlcPduListElement_s object with
995 // m_size=0 to keep the size of rlcPduListPerLc vector = 2 in case of MIMO
996 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size " << dci.m_tbsSize.at(j));
997 RlcPduListElement_s emptyElement;
998 emptyElement.m_logicalChannelIdentity = (*itRlcPdu)
999 .second.at(j)
1000 .at(dci.m_harqProcess)
1001 .at(k)
1002 .m_logicalChannelIdentity;
1003 emptyElement.m_size = 0;
1004 rlcPduListPerLc.push_back(emptyElement);
1005 }
1006 }
1007
1008 if (!rlcPduListPerLc.empty())
1009 {
1010 newEl.m_rlcPduList.push_back(rlcPduListPerLc);
1011 }
1012 }
1013 newEl.m_rnti = rnti;
1014 newEl.m_dci = dci;
1015 (*itHarq).second.at(harqId).m_rv = dci.m_rv;
1016 // refresh timer
1017 auto itHarqTimer = m_dlHarqProcessesTimer.find(rnti);
1018 if (itHarqTimer == m_dlHarqProcessesTimer.end())
1019 {
1020 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
1021 }
1022 (*itHarqTimer).second.at(harqId) = 0;
1023 ret.m_buildDataList.push_back(newEl);
1024 rntiAllocated.insert(rnti);
1025 }
1026 else
1027 {
1028 // update HARQ process status
1029 NS_LOG_INFO(this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at(i).m_rnti);
1030 auto it = m_dlHarqProcessesStatus.find(m_dlInfoListBuffered.at(i).m_rnti);
1031 if (it == m_dlHarqProcessesStatus.end())
1032 {
1033 NS_FATAL_ERROR("No info find in HARQ buffer for UE "
1034 << m_dlInfoListBuffered.at(i).m_rnti);
1035 }
1036 (*it).second.at(m_dlInfoListBuffered.at(i).m_harqProcessId) = 0;
1037 auto itRlcPdu =
1039 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1040 {
1041 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1042 << m_dlInfoListBuffered.at(i).m_rnti);
1043 }
1044 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
1045 {
1046 (*itRlcPdu).second.at(k).at(m_dlInfoListBuffered.at(i).m_harqProcessId).clear();
1047 }
1048 }
1049 }
1050 m_dlInfoListBuffered.clear();
1051 m_dlInfoListBuffered = dlInfoListUntxed;
1052
1053 if (rbgAllocatedNum == numberOfRBGs)
1054 {
1055 // all the RBGs are already allocated -> exit
1056 if (!ret.m_buildDataList.empty() || !ret.m_buildRarList.empty())
1057 {
1058 m_schedSapUser->SchedDlConfigInd(ret);
1059 }
1060 return;
1061 }
1062
1063 for (auto itLogicalChannels = m_ueLogicalChannelsConfigList.begin();
1064 itLogicalChannels != m_ueLogicalChannelsConfigList.end();
1065 itLogicalChannels++)
1066 {
1067 auto itRnti = rntiAllocated.find(itLogicalChannels->first.m_rnti);
1068 if ((itRnti != rntiAllocated.end()) ||
1069 (!HarqProcessAvailability(itLogicalChannels->first.m_rnti)))
1070 {
1071 // UE already allocated for HARQ or without HARQ process available -> drop it
1072 if (itRnti != rntiAllocated.end())
1073 {
1074 NS_LOG_DEBUG(this << " RNTI discarded for HARQ tx"
1075 << (uint16_t)(itLogicalChannels->first.m_rnti));
1076 }
1077 if (!HarqProcessAvailability(itLogicalChannels->first.m_rnti))
1078 {
1079 NS_LOG_DEBUG(this << " RNTI discarded for HARQ id"
1080 << (uint16_t)(itLogicalChannels->first.m_rnti));
1081 }
1082 continue;
1083 }
1084
1085 auto itRlcBufferReq = m_rlcBufferReq.find(itLogicalChannels->first);
1086 if (itRlcBufferReq == m_rlcBufferReq.end())
1087 {
1088 continue;
1089 }
1090
1091 int group = -1;
1092 int delay = 0;
1093
1094 if (itRlcBufferReq->second.m_rlcRetransmissionQueueSize > 0)
1095 {
1096 delay = itRlcBufferReq->second.m_rlcRetransmissionHolDelay;
1097 group = delay / grouping_parameter;
1098 }
1099 else if (itRlcBufferReq->second.m_rlcTransmissionQueueSize > 0)
1100 {
1101 delay = itRlcBufferReq->second.m_rlcTransmissionQueueHolDelay;
1102 group = delay / grouping_parameter;
1103 }
1104 else
1105 {
1106 continue;
1107 }
1108
1109 UEtoHOL.insert(std::pair<LteFlowId_t, int>(itLogicalChannels->first, delay));
1110
1111 if (itLogicalChannels->second.m_qosBearerType ==
1113 {
1114 if (map_nonGBRHOLgroupToUE.count(group) == 0)
1115 {
1116 std::set<LteFlowId_t> v;
1117 v.insert(itRlcBufferReq->first);
1118 map_nonGBRHOLgroupToUE.insert(std::pair<int, std::set<LteFlowId_t>>(group, v));
1119 }
1120 else
1121 {
1122 map_nonGBRHOLgroupToUE.find(group)->second.insert(itRlcBufferReq->first);
1123 }
1124 }
1125 else if (itLogicalChannels->second.m_qosBearerType ==
1127 itLogicalChannels->second.m_qosBearerType ==
1129 {
1130 if (map_GBRHOLgroupToUE.count(group) == 0)
1131 {
1132 std::set<LteFlowId_t> v;
1133 v.insert(itRlcBufferReq->first);
1134 map_GBRHOLgroupToUE.insert(std::pair<int, std::set<LteFlowId_t>>(group, v));
1135 }
1136 else
1137 {
1138 map_GBRHOLgroupToUE.find(group)->second.insert(itRlcBufferReq->first);
1139 }
1140 }
1141 };
1142
1143 // Prepare data for the scheduling mechanism
1144 // map: UE, to the amount of traffic they have to transfer
1145 std::map<LteFlowId_t, int> UeToAmountOfDataToTransfer;
1146 // Initialize the map per UE, how much resources is already assigned to the user
1147 std::map<LteFlowId_t, int> UeToAmountOfAssignedResources;
1148 // prepare values to calculate FF metric, this metric will be the same for all flows(logical
1149 // channels) that belong to the same RNTI
1150 std::map<uint16_t, uint8_t> sbCqiSum;
1151
1152 for (auto itrbr = m_rlcBufferReq.begin(); itrbr != m_rlcBufferReq.end(); itrbr++)
1153 {
1154 LteFlowId_t flowId = itrbr->first; // Prepare data for the scheduling mechanism
1155 // check first the channel conditions for this UE, if CQI!=0
1156 auto itCqi = m_a30CqiRxed.find((*itrbr).first.m_rnti);
1157 auto itTxMode = m_uesTxMode.find((*itrbr).first.m_rnti);
1158 if (itTxMode == m_uesTxMode.end())
1159 {
1160 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itrbr).first.m_rnti);
1161 }
1162 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1163
1164 uint8_t cqiSum = 0;
1165 for (int k = 0; k < numberOfRBGs; k++)
1166 {
1167 for (uint8_t j = 0; j < nLayer; j++)
1168 {
1169 if (itCqi == m_a30CqiRxed.end())
1170 {
1171 cqiSum += 1; // no info on this user -> lowest MCS
1172 }
1173 else
1174 {
1175 cqiSum += (*itCqi).second.m_higherLayerSelected.at(k).m_sbCqi.at(j);
1176 }
1177 }
1178 }
1179
1180 if (cqiSum == 0)
1181 {
1182 NS_LOG_INFO("Skip this flow, CQI==0, rnti:" << (*itrbr).first.m_rnti);
1183 continue;
1184 }
1185
1186 // map: UE, to the amount of traffic they have to transfer
1187 int amountOfDataToTransfer =
1188 8 * ((int)m_rlcBufferReq.find(flowId)->second.m_rlcRetransmissionQueueSize +
1189 (int)m_rlcBufferReq.find(flowId)->second.m_rlcTransmissionQueueSize);
1190
1191 UeToAmountOfDataToTransfer.insert(
1192 std::pair<LteFlowId_t, int>(flowId, amountOfDataToTransfer));
1193 UeToAmountOfAssignedResources.insert(std::pair<LteFlowId_t, int>(flowId, 0));
1194
1195 uint8_t sum = 0;
1196 for (int i = 0; i < numberOfRBGs; i++)
1197 {
1198 auto itCqi = m_a30CqiRxed.find((*itrbr).first.m_rnti);
1199 auto itTxMode = m_uesTxMode.find((*itrbr).first.m_rnti);
1200 if (itTxMode == m_uesTxMode.end())
1201 {
1202 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itrbr).first.m_rnti);
1203 }
1204 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1205 std::vector<uint8_t> sbCqis;
1206 if (itCqi == m_a30CqiRxed.end())
1207 {
1208 sbCqis = std::vector<uint8_t>(nLayer, 1); // start with lowest value
1209 }
1210 else
1211 {
1212 sbCqis = (*itCqi).second.m_higherLayerSelected.at(i).m_sbCqi;
1213 }
1214
1215 uint8_t cqi1 = sbCqis.at(0);
1216 uint8_t cqi2 = 0;
1217 if (sbCqis.size() > 1)
1218 {
1219 cqi2 = sbCqis.at(1);
1220 }
1221
1222 uint8_t sbCqi = 0;
1223 if ((cqi1 > 0) ||
1224 (cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1225 {
1226 for (uint8_t k = 0; k < nLayer; k++)
1227 {
1228 if (sbCqis.size() > k)
1229 {
1230 sbCqi = sbCqis.at(k);
1231 }
1232 else
1233 {
1234 // no info on this subband
1235 sbCqi = 0;
1236 }
1237 sum += sbCqi;
1238 }
1239 }
1240 }
1241
1242 sbCqiSum.insert(std::pair<uint16_t, uint8_t>((*itrbr).first.m_rnti, sum));
1243 }
1244
1245 // availableRBGs - set that contains indexes of available resource block groups
1246 std::set<int> availableRBGs;
1247 for (int i = 0; i < numberOfRBGs; i++)
1248 {
1249 if (!rbgMap.at(i))
1250 {
1251 availableRBGs.insert(i);
1252 }
1253 }
1254
1255 auto itGBRgroups = map_GBRHOLgroupToUE.begin();
1256 auto itnonGBRgroups = map_nonGBRHOLgroupToUE.begin();
1257
1258 // while there are more resources available, loop through the users that are grouped by HOL
1259 // value
1260 while (!availableRBGs.empty())
1261 {
1262 if (UeToAmountOfDataToTransfer.empty())
1263 {
1264 NS_LOG_INFO("No UEs to be scheduled (no data or CQI==0),");
1265 break;
1266 }
1267 std::set<LteFlowId_t> vUEs;
1268 t_it_HOLgroupToUEs itCurrentGroup;
1269
1270 if (itGBRgroups != map_GBRHOLgroupToUE.end())
1271 {
1272 itCurrentGroup = itGBRgroups;
1273 itGBRgroups++;
1274 }
1275 else if (itnonGBRgroups !=
1276 map_nonGBRHOLgroupToUE
1277 .end()) // if there are no more flows with retransmission queue start to
1278 // scheduler flows with transmission queue
1279 {
1280 itCurrentGroup = itnonGBRgroups;
1281 itnonGBRgroups++;
1282 }
1283 else
1284 {
1285 NS_LOG_INFO("Available RBGs:" << availableRBGs.size() << "but no users");
1286 break;
1287 }
1288
1289 // While there are more users in current group
1290 while (!availableRBGs.empty() && !itCurrentGroup->second.empty())
1291 {
1292 bool currentRBchecked = false;
1293 int currentRB = *(availableRBGs.begin());
1294 std::map<LteFlowId_t, CQI_value> UeToCQIValue;
1295 std::map<LteFlowId_t, double> UeToCoitaMetric;
1296 std::map<LteFlowId_t, bool> UeHasReachedGBR;
1297 double maximumValueMetric = 0;
1298 LteFlowId_t userWithMaximumMetric;
1299 UeToCQIValue.clear();
1300 UeToCoitaMetric.clear();
1301
1302 // Iterate through the users and calculate which user will use the best of the current
1303 // resource block.end() and assign to that user.
1304 for (auto it = itCurrentGroup->second.begin(); it != itCurrentGroup->second.end(); it++)
1305 {
1306 LteFlowId_t flowId = *it;
1307 uint8_t cqi_value = 1; // higher better, maximum is 15
1308 double coita_metric = 1;
1309 double coita_sum = 0;
1310 double metric = 0;
1311 uint8_t worstCQIAmongRBGsAllocatedForThisUser = 15;
1312 int numberOfRBGAllocatedForThisUser = 0;
1314 m_ueLogicalChannelsConfigList.find(flowId)->second;
1315 auto itRntiCQIsMap = m_a30CqiRxed.find(flowId.m_rnti);
1316
1317 if (!m_ffrSapProvider->IsDlRbgAvailableForUe(currentRB, flowId.m_rnti))
1318 {
1319 continue;
1320 }
1321
1322 if (m_flowStatsDl.find(flowId.m_rnti) == m_flowStatsDl.end())
1323 {
1324 continue; // TO DO: check if this should be logged and how.
1325 }
1326 currentRBchecked = true;
1327
1328 auto itStats = m_flowStatsDl.find(flowId.m_rnti);
1329 double tbr_weight =
1330 (*itStats).second.targetThroughput / (*itStats).second.lastAveragedThroughput;
1331 if (tbr_weight < 1.0)
1332 {
1333 tbr_weight = 1.0;
1334 }
1335
1336 if (itRntiCQIsMap != m_a30CqiRxed.end())
1337 {
1338 for (auto it = availableRBGs.begin(); it != availableRBGs.end(); it++)
1339 {
1340 try
1341 {
1342 int val =
1343 (itRntiCQIsMap->second.m_higherLayerSelected.at(*it).m_sbCqi.at(0));
1344 if (val == 0)
1345 {
1346 val = 1; // if no info, use minimum
1347 }
1348 if (*it == currentRB)
1349 {
1350 cqi_value = val;
1351 }
1352 coita_sum += val;
1353 }
1354 catch (std::out_of_range&)
1355 {
1356 coita_sum += 1; // if no info on channel use the worst cqi
1357 NS_LOG_INFO("No CQI for lcId:" << flowId.m_lcId
1358 << " rnti:" << flowId.m_rnti
1359 << " at subband:" << currentRB);
1360 // std::cout<<"\n No CQI for
1361 // lcId:.....................................";
1362 }
1363 }
1364 coita_metric = cqi_value / coita_sum;
1365 UeToCQIValue.insert(std::pair<LteFlowId_t, CQI_value>(flowId, cqi_value));
1366 UeToCoitaMetric.insert(std::pair<LteFlowId_t, double>(flowId, coita_metric));
1367 }
1368
1369 if (allocationMapPerRntiPerLCId.find(flowId.m_rnti) ==
1370 allocationMapPerRntiPerLCId.end())
1371 {
1372 worstCQIAmongRBGsAllocatedForThisUser = cqi_value;
1373 }
1374 else
1375 {
1376 numberOfRBGAllocatedForThisUser =
1377 (allocationMapPerRntiPerLCId.find(flowId.m_rnti)->second.size());
1378
1379 for (auto itRBG =
1380 allocationMapPerRntiPerLCId.find(flowId.m_rnti)->second.begin();
1381 itRBG != allocationMapPerRntiPerLCId.find(flowId.m_rnti)->second.end();
1382 itRBG++)
1383 {
1384 qos_rb_and_CQI_assigned_to_lc e = itRBG->second;
1385 if (e.cqi_value_for_lc < worstCQIAmongRBGsAllocatedForThisUser)
1386 {
1387 worstCQIAmongRBGsAllocatedForThisUser = e.cqi_value_for_lc;
1388 }
1389 }
1390
1391 if (cqi_value < worstCQIAmongRBGsAllocatedForThisUser)
1392 {
1393 worstCQIAmongRBGsAllocatedForThisUser = cqi_value;
1394 }
1395 }
1396
1397 int mcsForThisUser = m_amc->GetMcsFromCqi(worstCQIAmongRBGsAllocatedForThisUser);
1398 int tbSize =
1399 m_amc->GetDlTbSizeFromMcs(mcsForThisUser,
1400 (numberOfRBGAllocatedForThisUser + 1) * rbgSize) /
1401 8; // similar to calculation of TB size (size of TB in bytes according to
1402 // table 7.1.7.2.1-1 of 36.213)
1403
1404 double achievableRate =
1405 ((m_amc->GetDlTbSizeFromMcs(mcsForThisUser, rbgSize) / 8) / 0.001);
1406 double pf_weight = achievableRate / (*itStats).second.secondLastAveragedThroughput;
1407
1408 UeToAmountOfAssignedResources.find(flowId)->second = 8 * tbSize;
1410 m_rlcBufferReq.find(flowId)->second;
1411
1412 if (UeToAmountOfDataToTransfer.find(flowId)->second -
1413 UeToAmountOfAssignedResources.find(flowId)->second <
1414 0)
1415 {
1416 UeHasReachedGBR.insert(std::pair<LteFlowId_t, bool>(flowId, false));
1417 }
1418
1419 double bitRateWithNewRBG = 0;
1420
1421 if (m_flowStatsDl.find(flowId.m_rnti) !=
1422 m_flowStatsDl.end()) // there are some statistics{
1423 {
1424 bitRateWithNewRBG =
1425 (1.0 - (1.0 / m_timeWindow)) *
1426 (m_flowStatsDl.find(flowId.m_rnti)->second.lastAveragedThroughput) +
1427 ((1.0 / m_timeWindow) * (double)(tbSize * 1000));
1428 }
1429 else
1430 {
1431 bitRateWithNewRBG = (1.0 / m_timeWindow) * (double)(tbSize * 1000);
1432 }
1433
1434 if (bitRateWithNewRBG > lc.m_eRabGuaranteedBitrateDl)
1435 {
1436 UeHasReachedGBR.insert(std::pair<LteFlowId_t, bool>(flowId, true));
1437 }
1438 else
1439 {
1440 UeHasReachedGBR.insert(std::pair<LteFlowId_t, bool>(flowId, false));
1441 }
1442
1443 int hol = UEtoHOL.find(flowId)->second;
1444
1445 if (hol == 0)
1446 {
1447 hol = 1;
1448 }
1449
1450 if (m_CqaMetric == "CqaFf")
1451 {
1452 metric = coita_metric * tbr_weight * hol;
1453 }
1454 else if (m_CqaMetric == "CqaPf")
1455 {
1456 metric = tbr_weight * pf_weight * hol;
1457 }
1458 else
1459 {
1460 metric = 1;
1461 }
1462
1463 if (metric >= maximumValueMetric)
1464 {
1465 maximumValueMetric = metric;
1466 userWithMaximumMetric = flowId;
1467 }
1468 }
1469
1470 if (!currentRBchecked)
1471 {
1472 // erase current RBG from the list of available RBG
1473 availableRBGs.erase(currentRB);
1474 continue;
1475 }
1476
1478 const auto ueToCqiIt = UeToCQIValue.find(userWithMaximumMetric);
1479 s.cqi_value_for_lc = ueToCqiIt != UeToCQIValue.end() ? ueToCqiIt->second : 1;
1480 s.resource_block_index = currentRB;
1481
1482 auto itMap = allocationMapPerRntiPerLCId.find(userWithMaximumMetric.m_rnti);
1483
1484 if (itMap == allocationMapPerRntiPerLCId.end())
1485 {
1486 std::multimap<uint8_t, qos_rb_and_CQI_assigned_to_lc> tempMap;
1487 tempMap.insert(
1488 std::pair<uint8_t, qos_rb_and_CQI_assigned_to_lc>(userWithMaximumMetric.m_lcId,
1489 s));
1490 allocationMapPerRntiPerLCId.insert(
1491 std::pair<uint16_t, std::multimap<uint8_t, qos_rb_and_CQI_assigned_to_lc>>(
1492 userWithMaximumMetric.m_rnti,
1493 tempMap));
1494 }
1495 else
1496 {
1497 itMap->second.insert(
1498 std::pair<uint8_t, qos_rb_and_CQI_assigned_to_lc>(userWithMaximumMetric.m_lcId,
1499 s));
1500 }
1501
1502 // erase current RBG from the list of available RBG
1503 availableRBGs.erase(currentRB);
1504
1505 if (UeToAmountOfDataToTransfer.find(userWithMaximumMetric)->second <=
1506 UeToAmountOfAssignedResources.find(userWithMaximumMetric)->second * tolerance)
1507 //||(UeHasReachedGBR.find(userWithMaximumMetric)->second == true))
1508 {
1509 itCurrentGroup->second.erase(userWithMaximumMetric);
1510 }
1511 }
1512 }
1513
1514 // reset TTI stats of users
1515 for (auto itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
1516 {
1517 (*itStats).second.lastTtiBytesTransmitted = 0;
1518 }
1519
1520 // 3) Creating the correspondent DCIs (Generate the transmission opportunities by grouping the
1521 // RBGs of the same RNTI)
1522 // FfMacSchedSapUser::SchedDlConfigIndParameters ret;
1523 auto itMap = allocationMapPerRntiPerLCId.begin();
1524 std::map<uint16_t, double> m_rnti_per_ratio;
1525
1526 while (itMap != allocationMapPerRntiPerLCId.end())
1527 {
1528 // create new BuildDataListElement_s for this LC
1530 newEl.m_rnti = (*itMap).first;
1531 NS_LOG_INFO("Scheduled RNTI:" << newEl.m_rnti);
1532 // create the DlDciListElement_s
1533 DlDciListElement_s newDci;
1534 std::vector<RlcPduListElement_s> newRlcPduLe;
1535 newDci.m_rnti = (*itMap).first;
1536 newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
1537 uint16_t lcActives = LcActivePerFlow(itMap->first);
1538 if (lcActives == 0)
1539 { // if there is still no buffer report information on any flow
1540 lcActives = 1;
1541 }
1542 // NS_LOG_DEBUG (this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1543 uint16_t RbgPerRnti = (*itMap).second.size();
1544 double doubleRBgPerRnti = RbgPerRnti;
1545 double doubleRbgNum = numberOfRBGs;
1546 double rrRatio = doubleRBgPerRnti / doubleRbgNum;
1547 m_rnti_per_ratio.insert(std::pair<uint16_t, double>((*itMap).first, rrRatio));
1548 uint8_t worstCqi = 15;
1549
1550 // assign the worst value of CQI that user experienced on any of its subbands
1551 for (auto it = (*itMap).second.begin(); it != (*itMap).second.end(); it++)
1552 {
1553 if (it->second.cqi_value_for_lc < worstCqi)
1554 {
1555 worstCqi = it->second.cqi_value_for_lc;
1556 }
1557 }
1558
1559 newDci.m_mcs.push_back(m_amc->GetMcsFromCqi(worstCqi));
1560 int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(0), RbgPerRnti * rbgSize) /
1561 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1562 newDci.m_tbsSize.push_back(tbSize);
1563 newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1564 newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1565 uint32_t rbgMask = 0;
1566 for (auto itRBGsPerRNTI = (*itMap).second.begin(); itRBGsPerRNTI != (*itMap).second.end();
1567 itRBGsPerRNTI++)
1568 {
1569 rbgMask = rbgMask + (0x1 << itRBGsPerRNTI->second.resource_block_index);
1570 }
1571 newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1572 // NOTE: In this first version of CqaFfMacScheduler, it is assumed one flow per user.
1573 // create the rlc PDUs -> equally divide resources among active LCs
1574 for (auto itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1575 {
1576 if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1577 (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1578 ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1579 ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1580 {
1581 std::vector<RlcPduListElement_s> newRlcPduLe;
1582 // for (uint8_t j = 0; j < nLayer; j++)
1583 //{
1584 RlcPduListElement_s newRlcEl;
1585 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1586 // newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1587 newRlcEl.m_size = tbSize / lcActives;
1588 // NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity <<
1589 // " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1590 newRlcPduLe.push_back(newRlcEl);
1592 newRlcEl.m_logicalChannelIdentity,
1593 newRlcEl.m_size);
1594 if (m_harqOn)
1595 {
1596 // store RLC PDU list for HARQ
1597 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1598 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1599 {
1600 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1601 << (*itMap).first);
1602 }
1603 int j = 0;
1604 (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1605 }
1606 // }
1607 newEl.m_rlcPduList.push_back(newRlcPduLe);
1608 }
1609 if ((*itBufReq).first.m_rnti > (*itMap).first)
1610 {
1611 break;
1612 }
1613 }
1614 // for (uint8_t j = 0; j < nLayer; j++)
1615 // {
1616 newDci.m_ndi.push_back(1);
1617 newDci.m_rv.push_back(0);
1618 //}
1619
1620 newDci.m_tpc = m_ffrSapProvider->GetTpc((*itMap).first);
1621
1622 newEl.m_dci = newDci;
1623
1624 if (m_harqOn)
1625 {
1626 // store DCI for HARQ
1627 auto itDci = m_dlHarqProcessesDciBuffer.find(newEl.m_rnti);
1628 if (itDci == m_dlHarqProcessesDciBuffer.end())
1629 {
1630 NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1631 << newEl.m_rnti);
1632 }
1633 (*itDci).second.at(newDci.m_harqProcess) = newDci;
1634 // refresh timer
1635 auto itHarqTimer = m_dlHarqProcessesTimer.find(newEl.m_rnti);
1636 if (itHarqTimer == m_dlHarqProcessesTimer.end())
1637 {
1638 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1639 }
1640 (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1641 }
1642
1643 // ...more parameters -> ignored in this version
1644
1645 ret.m_buildDataList.push_back(newEl);
1646 // update UE stats
1647 auto it = m_flowStatsDl.find((*itMap).first);
1648 if (it != m_flowStatsDl.end())
1649 {
1650 (*it).second.lastTtiBytesTransmitted = tbSize;
1651 }
1652 else
1653 {
1654 NS_FATAL_ERROR(this << " No Stats for this allocated UE");
1655 }
1656
1657 itMap++;
1658 }
1659 ret.m_nrOfPdcchOfdmSymbols = 1; // TODO: check correct value according the DCIs txed
1660
1661 // update UEs stats
1662 NS_LOG_INFO(this << " Update UEs statistics");
1663 for (auto itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
1664 {
1665 if (allocationMapPerRntiPerLCId.find(itStats->first) != allocationMapPerRntiPerLCId.end())
1666 {
1667 (*itStats).second.secondLastAveragedThroughput =
1668 ((1.0 - (1 / m_timeWindow)) * (*itStats).second.secondLastAveragedThroughput) +
1669 ((1 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1670 }
1671
1672 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
1673 // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
1674 // Evolution, Ed Wiley)
1675 (*itStats).second.lastAveragedThroughput =
1676 ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
1677 ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1678 NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1679 NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1680 (*itStats).second.lastTtiBytesTransmitted = 0;
1681 }
1682
1683 m_schedSapUser->SchedDlConfigInd(ret);
1684
1685 int count_allocated_resource_blocks = 0;
1686 for (auto itMap = allocationMapPerRntiPerLCId.begin();
1687 itMap != allocationMapPerRntiPerLCId.end();
1688 itMap++)
1689 {
1690 count_allocated_resource_blocks += itMap->second.size();
1691 }
1692 NS_LOG_INFO(this << " Allocated RBs:" << count_allocated_resource_blocks);
1693}
1694
1695void
1698{
1699 NS_LOG_FUNCTION(this);
1700
1701 m_rachList = params.m_rachList;
1702}
1703
1704void
1707{
1708 NS_LOG_FUNCTION(this);
1709 m_ffrSapProvider->ReportDlCqiInfo(params);
1710
1711 for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1712 {
1713 if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1714 {
1715 NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1716 << " reported");
1717 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1718 auto it = m_p10CqiRxed.find(rnti);
1719 if (it == m_p10CqiRxed.end())
1720 {
1721 // create the new entry
1722 m_p10CqiRxed[rnti] =
1723 params.m_cqiList.at(i).m_wbCqi.at(0); // only codeword 0 at this stage (SISO)
1724 // generate correspondent timer
1725 m_p10CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1726 }
1727 else
1728 {
1729 // update the CQI value and refresh correspondent timer
1730 (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1731 // update correspondent timer
1732 auto itTimers = m_p10CqiTimers.find(rnti);
1733 (*itTimers).second = m_cqiTimersThreshold;
1734 }
1735 }
1736 else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1737 {
1738 // subband CQI reporting high layer configured
1739 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1740 auto it = m_a30CqiRxed.find(rnti);
1741 if (it == m_a30CqiRxed.end())
1742 {
1743 // create the new entry
1744 m_a30CqiRxed[rnti] = params.m_cqiList.at(i).m_sbMeasResult;
1745 m_a30CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1746 }
1747 else
1748 {
1749 // update the CQI value and refresh correspondent timer
1750 (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1751 auto itTimers = m_a30CqiTimers.find(rnti);
1752 (*itTimers).second = m_cqiTimersThreshold;
1753 }
1754 }
1755 else
1756 {
1757 NS_LOG_ERROR(this << " CQI type unknown");
1758 }
1759 }
1760}
1761
1762double
1763CqaFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1764{
1765 auto itCqi = m_ueCqi.find(rnti);
1766 if (itCqi == m_ueCqi.end())
1767 {
1768 // no cqi info about this UE
1769 return NO_SINR;
1770 }
1771 else
1772 {
1773 // take the average SINR value among the available
1774 double sinrSum = 0;
1775 unsigned int sinrNum = 0;
1776 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1777 {
1778 double sinr = (*itCqi).second.at(i);
1779 if (sinr != NO_SINR)
1780 {
1781 sinrSum += sinr;
1782 sinrNum++;
1783 }
1784 }
1785 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1786 // store the value
1787 (*itCqi).second.at(rb) = estimatedSinr;
1788 return estimatedSinr;
1789 }
1790}
1791
1792void
1795{
1796 NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1797 << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1798
1800 m_ffrSapProvider->ReportUlCqiInfo(m_ueCqi);
1801
1802 // Generate RBs map
1804 std::vector<bool> rbMap;
1805 uint16_t rbAllocatedNum = 0;
1806 std::set<uint16_t> rntiAllocated;
1807 std::vector<uint16_t> rbgAllocationMap;
1808 // update with RACH allocation map
1809 rbgAllocationMap = m_rachAllocationMap;
1810 // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1811 m_rachAllocationMap.clear();
1812 m_rachAllocationMap.resize(m_cschedCellConfig.m_ulBandwidth, 0);
1813
1814 rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1815
1816 rbMap = m_ffrSapProvider->GetAvailableUlRbg();
1817
1818 for (auto it = rbMap.begin(); it != rbMap.end(); it++)
1819 {
1820 if (*it)
1821 {
1822 rbAllocatedNum++;
1823 }
1824 }
1825
1826 uint8_t minContinuousUlBandwidth = m_ffrSapProvider->GetMinContinuousUlBandwidth();
1827 uint8_t ffrUlBandwidth = m_cschedCellConfig.m_ulBandwidth - rbAllocatedNum;
1828
1829 // remove RACH allocation
1830 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1831 {
1832 if (rbgAllocationMap.at(i) != 0)
1833 {
1834 rbMap.at(i) = true;
1835 NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1836 }
1837 }
1838
1839 if (m_harqOn)
1840 {
1841 // Process UL HARQ feedback
1842 for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1843 {
1844 if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1845 {
1846 // retx correspondent block: retrieve the UL-DCI
1847 uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1848 auto itProcId = m_ulHarqCurrentProcessId.find(rnti);
1849 if (itProcId == m_ulHarqCurrentProcessId.end())
1850 {
1851 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1852 }
1853 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1854 NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1855 << " i " << i << " size " << params.m_ulInfoList.size());
1856 auto itHarq = m_ulHarqProcessesDciBuffer.find(rnti);
1857 if (itHarq == m_ulHarqProcessesDciBuffer.end())
1858 {
1859 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1860 continue;
1861 }
1862 UlDciListElement_s dci = (*itHarq).second.at(harqId);
1863 auto itStat = m_ulHarqProcessesStatus.find(rnti);
1864 if (itStat == m_ulHarqProcessesStatus.end())
1865 {
1866 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1867 }
1868 if ((*itStat).second.at(harqId) >= 3)
1869 {
1870 NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1871 continue;
1872 }
1873 bool free = true;
1874
1875 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1876 {
1877 if (rbMap.at(j))
1878 {
1879 free = false;
1880 NS_LOG_INFO(this << " BUSY " << j);
1881 }
1882 }
1883 if (free)
1884 {
1885 // retx on the same RBs
1886 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1887 {
1888 rbMap.at(j) = true;
1889 rbgAllocationMap.at(j) = dci.m_rnti;
1890 NS_LOG_INFO("\tRB " << j);
1891 rbAllocatedNum++;
1892 }
1893 NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1894 << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1895 << (*itStat).second.at(harqId) + 1);
1896 }
1897 else
1898 {
1899 NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1900 continue;
1901 }
1902 dci.m_ndi = 0;
1903 // Update HARQ buffers with new HarqId
1904 (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1905 (*itStat).second.at(harqId) = 0;
1906 (*itHarq).second.at((*itProcId).second) = dci;
1907 ret.m_dciList.push_back(dci);
1908 rntiAllocated.insert(dci.m_rnti);
1909 }
1910 else
1911 {
1912 NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1913 << params.m_ulInfoList.at(i).m_rnti);
1914 }
1915 }
1916 }
1917
1918 std::map<uint16_t, uint32_t>::iterator it;
1919 int nflows = 0;
1920
1921 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1922 {
1923 auto itRnti = rntiAllocated.find((*it).first);
1924 // select UEs with queues not empty and not yet allocated for HARQ
1925 if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1926 {
1927 nflows++;
1928 }
1929 }
1930
1931 if (nflows == 0)
1932 {
1933 if (!ret.m_dciList.empty())
1934 {
1935 m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1936 m_schedSapUser->SchedUlConfigInd(ret);
1937 }
1938
1939 return; // no flows to be scheduled
1940 }
1941
1942 // Divide the remaining resources equally among the active users starting from the subsequent
1943 // one served last scheduling trigger
1944 uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size());
1945 uint16_t rbPerFlow =
1946 (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1947
1948 if (rbPerFlow < 3)
1949 {
1950 rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1951 // >= 7 bytes
1952 }
1953 int rbAllocated = 0;
1954
1955 if (m_nextRntiUl != 0)
1956 {
1957 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1958 {
1959 if ((*it).first == m_nextRntiUl)
1960 {
1961 break;
1962 }
1963 }
1964 if (it == m_ceBsrRxed.end())
1965 {
1966 NS_LOG_ERROR(this << " no user found");
1967 }
1968 }
1969 else
1970 {
1971 it = m_ceBsrRxed.begin();
1972 m_nextRntiUl = (*it).first;
1973 }
1974 do
1975 {
1976 auto itRnti = rntiAllocated.find((*it).first);
1977 if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1978 {
1979 // UE already allocated for UL-HARQ -> skip it
1980 NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1981 << (*it).first);
1982 it++;
1983 if (it == m_ceBsrRxed.end())
1984 {
1985 // restart from the first
1986 it = m_ceBsrRxed.begin();
1987 }
1988 continue;
1989 }
1990 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1991 {
1992 // limit to physical resources last resource assignment
1993 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1994 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1995 if (rbPerFlow < 3)
1996 {
1997 // terminate allocation
1998 rbPerFlow = 0;
1999 }
2000 }
2001
2002 rbAllocated = 0;
2003 UlDciListElement_s uldci;
2004 uldci.m_rnti = (*it).first;
2005 uldci.m_rbLen = rbPerFlow;
2006 bool allocated = false;
2007 NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
2008 << " flows " << nflows);
2009 while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
2010 (rbPerFlow != 0))
2011 {
2012 // check availability
2013 bool free = true;
2014 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
2015 {
2016 if (rbMap.at(j))
2017 {
2018 free = false;
2019 break;
2020 }
2021 if (!m_ffrSapProvider->IsUlRbgAvailableForUe(j, (*it).first))
2022 {
2023 free = false;
2024 break;
2025 }
2026 }
2027 if (free)
2028 {
2029 NS_LOG_INFO(this << "RNTI: " << (*it).first << " RB Allocated " << rbAllocated
2030 << " rbPerFlow " << rbPerFlow << " flows " << nflows);
2031 uldci.m_rbStart = rbAllocated;
2032
2033 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
2034 {
2035 rbMap.at(j) = true;
2036 // store info on allocation for managing ul-cqi interpretation
2037 rbgAllocationMap.at(j) = (*it).first;
2038 }
2039 rbAllocated += rbPerFlow;
2040 allocated = true;
2041 break;
2042 }
2043 rbAllocated++;
2044 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
2045 {
2046 // limit to physical resources last resource assignment
2047 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
2048 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
2049 if (rbPerFlow < 3)
2050 {
2051 // terminate allocation
2052 rbPerFlow = 0;
2053 }
2054 }
2055 }
2056 if (!allocated)
2057 {
2058 // unable to allocate new resource: finish scheduling
2059 // m_nextRntiUl = (*it).first;
2060 // if (ret.m_dciList.size () > 0)
2061 // {
2062 // m_schedSapUser->SchedUlConfigInd (ret);
2063 // }
2064 // m_allocationMaps[params.m_sfnSf] = rbgAllocationMap; return;
2065 break;
2066 }
2067
2068 auto itCqi = m_ueCqi.find((*it).first);
2069 int cqi = 0;
2070 if (itCqi == m_ueCqi.end())
2071 {
2072 // no cqi info about this UE
2073 uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
2074 }
2075 else
2076 {
2077 // take the lowest CQI value (worst RB)
2078 NS_ABORT_MSG_IF((*itCqi).second.empty(),
2079 "CQI of RNTI = " << (*it).first << " has expired");
2080 double minSinr = (*itCqi).second.at(uldci.m_rbStart);
2081 if (minSinr == NO_SINR)
2082 {
2083 minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
2084 }
2085 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
2086 {
2087 double sinr = (*itCqi).second.at(i);
2088 if (sinr == NO_SINR)
2089 {
2090 sinr = EstimateUlSinr((*it).first, i);
2091 }
2092 if (sinr < minSinr)
2093 {
2094 minSinr = sinr;
2095 }
2096 }
2097
2098 // translate SINR -> cqi: WILD ACK: same as DL
2099 double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
2100 cqi = m_amc->GetCqiFromSpectralEfficiency(s);
2101 if (cqi == 0)
2102 {
2103 it++;
2104 if (it == m_ceBsrRxed.end())
2105 {
2106 // restart from the first
2107 it = m_ceBsrRxed.begin();
2108 }
2109 NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
2110 // remove UE from allocation map
2111 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
2112 {
2113 rbgAllocationMap.at(i) = 0;
2114 }
2115 continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
2116 }
2117 uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
2118 }
2119
2120 uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
2122 uldci.m_ndi = 1;
2123 uldci.m_cceIndex = 0;
2124 uldci.m_aggrLevel = 1;
2125 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
2126 uldci.m_hopping = false;
2127 uldci.m_n2Dmrs = 0;
2128 uldci.m_tpc = 0; // no power control
2129 uldci.m_cqiRequest = false; // only period CQI at this stage
2130 uldci.m_ulIndex = 0; // TDD parameter
2131 uldci.m_dai = 1; // TDD parameter
2132 uldci.m_freqHopping = 0;
2133 uldci.m_pdcchPowerOffset = 0; // not used
2134 ret.m_dciList.push_back(uldci);
2135 // store DCI for HARQ_PERIOD
2136 uint8_t harqId = 0;
2137 if (m_harqOn)
2138 {
2139 auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
2140 if (itProcId == m_ulHarqCurrentProcessId.end())
2141 {
2142 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
2143 }
2144 harqId = (*itProcId).second;
2145 auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
2146 if (itDci == m_ulHarqProcessesDciBuffer.end())
2147 {
2148 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
2149 << uldci.m_rnti);
2150 }
2151 (*itDci).second.at(harqId) = uldci;
2152 // Update HARQ process status (RV 0)
2153 auto itStat = m_ulHarqProcessesStatus.find(uldci.m_rnti);
2154 if (itStat == m_ulHarqProcessesStatus.end())
2155 {
2156 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
2157 << uldci.m_rnti);
2158 }
2159 (*itStat).second.at(harqId) = 0;
2160 }
2161
2162 NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
2163 << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
2164 << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
2165 << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
2166 << (uint16_t)harqId);
2167
2168 // update TTI UE stats
2169 auto itStats = m_flowStatsUl.find((*it).first);
2170 if (itStats != m_flowStatsUl.end())
2171 {
2172 (*itStats).second.lastTtiBytesTransmitted = uldci.m_tbSize;
2173 }
2174 else
2175 {
2176 NS_LOG_DEBUG(this << " No Stats for this allocated UE");
2177 }
2178
2179 it++;
2180 if (it == m_ceBsrRxed.end())
2181 {
2182 // restart from the first
2183 it = m_ceBsrRxed.begin();
2184 }
2185 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
2186 {
2187 // Stop allocation: no more PRBs
2188 m_nextRntiUl = (*it).first;
2189 break;
2190 }
2191 } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
2192
2193 // Update global UE stats
2194 // update UEs stats
2195 for (auto itStats = m_flowStatsUl.begin(); itStats != m_flowStatsUl.end(); itStats++)
2196 {
2197 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
2198 // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
2199 // Evolution, Ed Wiley)
2200 (*itStats).second.lastAveragedThroughput =
2201 ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
2202 ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
2203 NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
2204 NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
2205 (*itStats).second.lastTtiBytesTransmitted = 0;
2206 }
2207 m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
2208 m_schedSapUser->SchedUlConfigInd(ret);
2209}
2210
2211void
2217
2218void
2224
2225void
2228{
2229 NS_LOG_FUNCTION(this);
2230
2231 for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
2232 {
2233 if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
2234 {
2235 // buffer status report
2236 // note that this scheduler does not differentiate the
2237 // allocation according to which LCGs have more/less bytes
2238 // to send.
2239 // Hence the BSR of different LCGs are just summed up to get
2240 // a total queue size that is used for allocation purposes.
2241
2242 uint32_t buffer = 0;
2243 for (uint8_t lcg = 0; lcg < 4; ++lcg)
2244 {
2245 uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
2246 buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
2247 }
2248
2249 uint16_t rnti = params.m_macCeList.at(i).m_rnti;
2250 NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
2251 auto it = m_ceBsrRxed.find(rnti);
2252 if (it == m_ceBsrRxed.end())
2253 {
2254 // create the new entry
2255 m_ceBsrRxed.insert(std::pair<uint16_t, uint32_t>(rnti, buffer));
2256 }
2257 else
2258 {
2259 // update the buffer size value
2260 (*it).second = buffer;
2261 }
2262 }
2263 }
2264}
2265
2266void
2269{
2270 NS_LOG_FUNCTION(this);
2271 // retrieve the allocation for this subframe
2272 switch (m_ulCqiFilter)
2273 {
2275 // filter all the CQIs that are not SRS based
2276 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
2277 {
2278 return;
2279 }
2280 }
2281 break;
2283 // filter all the CQIs that are not SRS based
2284 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
2285 {
2286 return;
2287 }
2288 }
2289 break;
2290 default:
2291 NS_FATAL_ERROR("Unknown UL CQI type");
2292 }
2293
2294 switch (params.m_ulCqi.m_type)
2295 {
2296 case UlCqi_s::PUSCH: {
2297 NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
2298 << " subframe no. " << (0xF & params.m_sfnSf));
2299 auto itMap = m_allocationMaps.find(params.m_sfnSf);
2300 if (itMap == m_allocationMaps.end())
2301 {
2302 return;
2303 }
2304 for (uint32_t i = 0; i < (*itMap).second.size(); i++)
2305 {
2306 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
2307 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
2308 auto itCqi = m_ueCqi.find((*itMap).second.at(i));
2309 if (itCqi == m_ueCqi.end())
2310 {
2311 // create a new entry
2312 std::vector<double> newCqi;
2313 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2314 {
2315 if (i == j)
2316 {
2317 newCqi.push_back(sinr);
2318 }
2319 else
2320 {
2321 // initialize with NO_SINR value.
2322 newCqi.push_back(NO_SINR);
2323 }
2324 }
2325 m_ueCqi[(*itMap).second.at(i)] = newCqi;
2326 // generate correspondent timer
2327 m_ueCqiTimers[(*itMap).second.at(i)] = m_cqiTimersThreshold;
2328 }
2329 else
2330 {
2331 // update the value
2332 (*itCqi).second.at(i) = sinr;
2333 NS_LOG_DEBUG(this << " RNTI " << (*itMap).second.at(i) << " RB " << i << " SINR "
2334 << sinr);
2335 // update correspondent timer
2336 auto itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
2337 (*itTimers).second = m_cqiTimersThreshold;
2338 }
2339 }
2340 // remove obsolete info on allocation
2341 m_allocationMaps.erase(itMap);
2342 }
2343 break;
2344 case UlCqi_s::SRS: {
2345 NS_LOG_DEBUG(this << " Collect SRS CQIs of Frame no. " << (params.m_sfnSf >> 4)
2346 << " subframe no. " << (0xF & params.m_sfnSf));
2347 // get the RNTI from vendor specific parameters
2348 uint16_t rnti = 0;
2349 NS_ASSERT(!params.m_vendorSpecificList.empty());
2350 for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
2351 {
2352 if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
2353 {
2354 Ptr<SrsCqiRntiVsp> vsp =
2355 DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
2356 rnti = vsp->GetRnti();
2357 }
2358 }
2359 auto itCqi = m_ueCqi.find(rnti);
2360 if (itCqi == m_ueCqi.end())
2361 {
2362 // create a new entry
2363 std::vector<double> newCqi;
2364 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2365 {
2366 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
2367 newCqi.push_back(sinr);
2368 NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
2369 << sinr);
2370 }
2371 m_ueCqi.insert(std::pair<uint16_t, std::vector<double>>(rnti, newCqi));
2372 // generate correspondent timer
2373 m_ueCqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
2374 }
2375 else
2376 {
2377 // update the values
2378 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2379 {
2380 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
2381 (*itCqi).second.at(j) = sinr;
2382 NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
2383 << sinr);
2384 }
2385 // update correspondent timer
2386 auto itTimers = m_ueCqiTimers.find(rnti);
2387 (*itTimers).second = m_cqiTimersThreshold;
2388 }
2389 }
2390 break;
2391 case UlCqi_s::PUCCH_1:
2392 case UlCqi_s::PUCCH_2:
2393 case UlCqi_s::PRACH: {
2394 NS_FATAL_ERROR("PfFfMacScheduler supports only PUSCH and SRS UL-CQIs");
2395 }
2396 break;
2397 default:
2398 NS_FATAL_ERROR("Unknown type of UL-CQI");
2399 }
2400}
2401
2402void
2404{
2405 // refresh DL CQI P01 Map
2406 auto itP10 = m_p10CqiTimers.begin();
2407 while (itP10 != m_p10CqiTimers.end())
2408 {
2409 NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
2410 << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2411 if ((*itP10).second == 0)
2412 {
2413 // delete correspondent entries
2414 auto itMap = m_p10CqiRxed.find((*itP10).first);
2415 NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
2416 " Does not find CQI report for user " << (*itP10).first);
2417 NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
2418 m_p10CqiRxed.erase(itMap);
2419 auto temp = itP10;
2420 itP10++;
2421 m_p10CqiTimers.erase(temp);
2422 }
2423 else
2424 {
2425 (*itP10).second--;
2426 itP10++;
2427 }
2428 }
2429
2430 // refresh DL CQI A30 Map
2431 auto itA30 = m_a30CqiTimers.begin();
2432 while (itA30 != m_a30CqiTimers.end())
2433 {
2434 NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
2435 << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2436 if ((*itA30).second == 0)
2437 {
2438 // delete correspondent entries
2439 auto itMap = m_a30CqiRxed.find((*itA30).first);
2440 NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
2441 " Does not find CQI report for user " << (*itA30).first);
2442 NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
2443 m_a30CqiRxed.erase(itMap);
2444 auto temp = itA30;
2445 itA30++;
2446 m_a30CqiTimers.erase(temp);
2447 }
2448 else
2449 {
2450 (*itA30).second--;
2451 itA30++;
2452 }
2453 }
2454}
2455
2456void
2458{
2459 // refresh UL CQI Map
2460 auto itUl = m_ueCqiTimers.begin();
2461 while (itUl != m_ueCqiTimers.end())
2462 {
2463 NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
2464 << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2465 if ((*itUl).second == 0)
2466 {
2467 // delete correspondent entries
2468 auto itMap = m_ueCqi.find((*itUl).first);
2469 NS_ASSERT_MSG(itMap != m_ueCqi.end(),
2470 " Does not find CQI report for user " << (*itUl).first);
2471 NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
2472 (*itMap).second.clear();
2473 m_ueCqi.erase(itMap);
2474 auto temp = itUl;
2475 itUl++;
2476 m_ueCqiTimers.erase(temp);
2477 }
2478 else
2479 {
2480 (*itUl).second--;
2481 itUl++;
2482 }
2483 }
2484}
2485
2486void
2487CqaFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
2488{
2489 LteFlowId_t flow(rnti, lcid);
2490 auto it = m_rlcBufferReq.find(flow);
2491 if (it != m_rlcBufferReq.end())
2492 {
2493 NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
2494 << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
2495 << (*it).second.m_rlcRetransmissionQueueSize << " status "
2496 << (*it).second.m_rlcStatusPduSize << " decrease " << size);
2497 // Update queues: RLC tx order Status, ReTx, Tx
2498 // Update status queue
2499 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2500 {
2501 (*it).second.m_rlcStatusPduSize = 0;
2502 }
2503 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
2504 (size >= (*it).second.m_rlcRetransmissionQueueSize))
2505 {
2506 (*it).second.m_rlcRetransmissionQueueSize = 0;
2507 }
2508 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2509 {
2510 uint32_t rlcOverhead;
2511 if (lcid == 1)
2512 {
2513 // for SRB1 (using RLC AM) it's better to
2514 // overestimate RLC overhead rather than
2515 // underestimate it and risk unneeded
2516 // segmentation which increases delay
2517 rlcOverhead = 4;
2518 }
2519 else
2520 {
2521 // minimum RLC overhead due to header
2522 rlcOverhead = 2;
2523 }
2524 // update transmission queue
2525 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2526 {
2527 (*it).second.m_rlcTransmissionQueueSize = 0;
2528 }
2529 else
2530 {
2531 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2532 }
2533 }
2534 }
2535 else
2536 {
2537 NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
2538 }
2539}
2540
2541void
2542CqaFfMacScheduler::UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
2543{
2544 size = size - 2; // remove the minimum RLC overhead
2545 auto it = m_ceBsrRxed.find(rnti);
2546 if (it != m_ceBsrRxed.end())
2547 {
2548 NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2549 if ((*it).second >= size)
2550 {
2551 (*it).second -= size;
2552 }
2553 else
2554 {
2555 (*it).second = 0;
2556 }
2557 }
2558 else
2559 {
2560 NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
2561 }
2562}
2563
2564void
2566{
2567 NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2569 params.m_rnti = rnti;
2570 params.m_transmissionMode = txMode;
2571 m_cschedSapUser->CschedUeConfigUpdateInd(params);
2572}
2573
2574} // namespace ns3
uint32_t v
static uint32_t BsrId2BufferSize(uint8_t val)
Convert BSR ID to buffer size.
Implements the SCHED SAP and CSCHED SAP for the Channel and QoS Aware Scheduler.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
FfMacCschedSapProvider * m_cschedSapProvider
Csched SAP provider.
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void DoSchedUlTriggerReq(const FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL Trigger Request.
std::map< uint16_t, CqasFlowPerf_t > m_flowStatsDl
Map of UE statistics (per RNTI basis) in downlink.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ process ID.
static TypeId GetTypeId()
Get the type ID.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timers.
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
void DoSchedDlPagingBufferReq(const FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL Paging Buffer Request.
~CqaFfMacScheduler() override
Destructor.
unsigned int LcActivePerFlow(uint16_t rnti)
LC Active per flow.
void SetLteFfrSapProvider(LteFfrSapProvider *s) override
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
FfMacSchedSapUser * m_schedSapUser
MAC Sched SAP user.
void DoSchedDlTriggerReq(const FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL RLC Buffer Request.
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
void DoSchedDlRlcBufferReq(const FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC Buffer Request.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
friend class MemberSchedSapProvider< CqaFfMacScheduler >
allow MemberSchedSapProvider<CqaFfMacScheduler> class friend access
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
Map of UE's DL CQI A30 received.
std::vector< RachListElement_s > m_rachList
RACH list.
void DoSchedDlMacBufferReq(const FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC Buffer Request.
void DoCschedLcReleaseReq(const FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
Csched LC Release Request.
void DoSchedUlMacCtrlInfoReq(const FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC Control Info Request.
void DoCschedLcConfigReq(const FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
Csched LC Config Request.
FfMacCschedSapUser * m_cschedSapUser
MAC Csched SAP user.
bool HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0).
void DoSchedUlNoiseInterferenceReq(const FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL Noise InterferenceRequest.
void DoSchedUlCqiInfoReq(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CGI Info Request.
std::map< LteFlowId_t, LogicalChannelConfigListElement_s > m_ueLogicalChannelsConfigList
Map of UE logical channel config list.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
void SetFfMacSchedSapUser(FfMacSchedSapUser *s) override
set the user part of the FfMacSchedSap that this Scheduler will interact with.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
void DoDispose() override
Destructor implementation.
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
Map of previous allocated UE per RBG (used to retrieve info from UL-CQI).
void DoSchedDlRachInfoReq(const FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH Info Request.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
void RefreshUlCqiMaps()
Refresh UL CGI maps.
Ptr< LteAmc > m_amc
LTE AMC object.
void DoSchedDlCqiInfoReq(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CGI Info Request.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
DL HARQ retx buffered.
void DoCschedUeReleaseReq(const FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
Csched UE Release Request.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
void SetFfMacCschedSapUser(FfMacCschedSapUser *s) override
set the user part of the FfMacCschedSap that this Scheduler will interact with.
std::map< uint16_t, CqasFlowPerf_t > m_flowStatsUl
Map of UE statistics (per RNTI basis).
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
void DoCschedCellConfigReq(const FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
Csched Cell Config Request.
friend class MemberCschedSapProvider< CqaFfMacScheduler >
allow MemberCschedSapProvider<CqaFfMacScheduler> class friend access
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
Estimate UL Sinr.
void RefreshDlCqiMaps()
Refresh DL CGI maps.
void DoCschedUeConfigReq(const FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
Csched UE Config Request.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
Internal parameters.
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process statuses.
LteFfrSapUser * GetLteFfrSapUser() override
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
std::string m_CqaMetric
CQA metric name.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void DoSchedUlSrInfoReq(const FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL Sr Info Request.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Trans mode config update.
Provides the CSCHED SAP.
FfMacCschedSapUser class.
Provides the SCHED SAP.
FfMacSchedSapUser class.
FfMacScheduler()
constructor
UlCqiFilter_t m_ulCqiFilter
UL CQI filter.
static double fpS11dot3toDouble(uint16_t val)
Convert from fixed point S11.3 notation to double.
Service Access Point (SAP) offered by the Frequency Reuse algorithm instance to the MAC Scheduler ins...
Definition lte-ffr-sap.h:29
Service Access Point (SAP) offered by the eNodeB RRC instance to the Frequency Reuse algorithm instan...
Template for the implementation of the LteFfrSapUser as a member of an owner class of type C to which...
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Hold variables of type string.
Definition string.h:45
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
Hold an unsigned integer type.
Definition uinteger.h:34
#define MAX_LC_LIST
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:76
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:99
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:253
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:281
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:274
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
#define HARQ_PERIOD
Definition lte-common.h:20
#define SRS_CQI_RNTI_VSP
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int RBG_index
RBG index typedef.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector.
bool CqaKeyDescComparator(uint16_t key1, uint16_t key2)
CQA key comparator.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
constexpr double NO_SINR
Value for SINR outside the range defined by FF-API, used to indicate that there is no CQI for this el...
std::map< CQI_value, LteFlowId_t, bool(*)(uint8_t, uint8_t)>::iterator t_it_CQIToUE
CQI value map iterator typedef.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
std::multimap< HOL_group, std::set< LteFlowId_t >, bool(*)(int, int)> t_map_HOLgroupToUEs
HOL group map typedef.
int HOL_group
HOL group typedef.
std::vector< uint8_t > UlHarqProcessesStatus_t
UL HARQ process status vector.
std::vector< uint8_t > DlHarqProcessesStatus_t
DL HARQ process status vector.
std::map< CQI_value, LteFlowId_t, bool(*)(uint8_t, uint8_t)> t_map_CQIToUE
CQI value map typedef.
bool CQIValueDescComparator(uint8_t key1, uint8_t key2)
CQI value comparator function.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:643
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector.
@ SUCCESS
std::map< HOL_group, t_map_RBGToCQIsSorted >::iterator t_it_HOLGroupToRBGs
HOL group map iterator typedef.
constexpr uint32_t HARQ_DL_TIMEOUT
HARQ DL timeout.
std::map< RBG_index, t_map_CQIToUE >::iterator t_it_RBGToCQIsSorted
RBG index map iterator typedef.
std::map< HOL_group, t_map_RBGToCQIsSorted > t_map_HOLGroupToRBGs
HOL group map typedef.
constexpr uint32_t HARQ_PROC_NUM
Number of HARQ processes.
Ptr< const AttributeChecker > MakeStringChecker()
Definition string.cc:19
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Definition string.h:46
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
Vector of the 8 HARQ processes per UE.
std::map< HOL_group, std::set< LteFlowId_t > >::iterator t_it_HOLgroupToUEs
HOL group multi map iterator typedef.
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
UL HARQ process DCI buffer vector.
std::map< RBG_index, t_map_CQIToUE > t_map_RBGToCQIsSorted
RBG index map typedef.
std::size_t GetLteRbgSize(uint16_t dlBandwidth)
Get the Type 0 resource block group (RBG) size for a downlink bandwidth, according to 3GPP TS 36....
Definition lte-common.cc:36
uint8_t CQI_value
CQI value typedef.
bool CqaGroupDescComparator(int key1, int key2)
CGA group comparator function.
See section 4.3.8 buildDataListElement.
std::vector< std::vector< struct RlcPduListElement_s > > m_rlcPduList
RLC PDU list.
struct DlDciListElement_s m_dci
DCI.
See section 4.3.10 buildRARListElement.
CGA Flow Performance structure.
double lastAveragedThroughput
Past average throughput.
double secondLastAveragedThroughput
Second last average throughput.
double targetThroughput
Target throughput.
Time flowStart
flow start time
unsigned int lastTtiBytesTransmitted
Total bytes send by eNB in last tti for this UE.
unsigned long totalBytesTransmitted
Total bytes send by eNb for this UE.
See section 4.3.1 dlDciListElement.
std::vector< uint8_t > m_ndi
New data indicator.
uint8_t m_harqProcess
HARQ process.
uint32_t m_rbBitmap
RB bitmap.
std::vector< uint8_t > m_mcs
MCS.
uint8_t m_resAlloc
The type of resource allocation.
std::vector< uint16_t > m_tbsSize
The TBs size.
std::vector< uint8_t > m_rv
Redundancy version.
uint8_t m_tpc
Tx power control command.
Parameters of the CSCHED_LC_CONFIG_REQ primitive.
Parameters of the CSCHED_LC_RELEASE_REQ primitive.
Parameters of the CSCHED_UE_CONFIG_REQ primitive.
Parameters of the CSCHED_UE_RELEASE_REQ primitive.
Parameters of the CSCHED_UE_CONFIG_CNF primitive.
Parameters of the CSCHED_UE_CONFIG_UPDATE_IND primitive.
Parameters of the SCHED_DL_CQI_INFO_REQ primitive.
Parameters of the SCHED_DL_MAC_BUFFER_REQ primitive.
Parameters of the SCHED_DL_PAGING_BUFFER_REQ primitive.
Parameters of the SCHED_DL_RACH_INFO_REQ primitive.
Parameters of the SCHED_DL_TRIGGER_REQ primitive.
Parameters of the SCHED_UL_CQI_INFO_REQ primitive.
Parameters of the SCHED_UL_MAC_CTRL_INFO_REQ primitive.
Parameters of the SCHED_UL_NOISE_INTERFERENCE_REQ primitive.
Parameters of the SCHED_UL_SR_INFO_REQ primitive.
Parameters of the SCHED_UL_TRIGGER_REQ primitive.
std::vector< BuildDataListElement_s > m_buildDataList
build data list
std::vector< BuildRarListElement_s > m_buildRarList
build rar list
uint8_t m_nrOfPdcchOfdmSymbols
number of PDCCH OFDM symbols
Parameters of the SCHED_UL_CONFIG_IND primitive.
std::vector< UlDciListElement_s > m_dciList
DCI list.
See section 4.3.4 logicalChannelConfigListElement.
uint64_t m_eRabGuaranteedBitrateDl
ERAB guaranteed bit rate DL.
LteFlowId structure.
Definition lte-common.h:42
uint8_t m_lcId
LCID.
Definition lte-common.h:44
uint16_t m_rnti
RNTI.
Definition lte-common.h:43
See section 4.3.9 rlcPDU_ListElement.
uint8_t m_logicalChannelIdentity
logical channel identity
See section 4.3.2 ulDciListElement.
int8_t m_pdcchPowerOffset
CCH power offset.
int8_t m_tpc
Tx power control command.
uint8_t m_dai
DL assignment index.
uint8_t m_cceIndex
Control Channel Element index.
uint8_t m_ulIndex
UL index.
uint8_t m_ueTxAntennaSelection
UE antenna selection.
bool m_cqiRequest
CQI request.
uint8_t m_freqHopping
freq hopping
uint8_t m_aggrLevel
The aggregation level.
bool m_ulDelay
UL delay?
int8_t m_tpc
Tx power control command.
bool m_cqiRequest
CQI request?
bool m_hopping
hopping?
uint16_t m_tbSize
size
uint8_t m_rbLen
length
uint8_t m_mcs
MCS.
uint8_t m_rbStart
start
uint16_t m_rnti
RNTI.
qos_rb_and_CQI_assigned_to_lc
uint8_t cqi_value_for_lc
CQI indicator value.
uint16_t resource_block_index
Resource block indexHOL_GROUP_index.