A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tdtbfq-ff-mac-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Marco Miozzo <marco.miozzo@cttc.es>
7 * Modification: Dizhi Zhou <dizhi.zhou@gmail.com> // modify codes related to downlink scheduler
8 */
9
11
12#include "lte-amc.h"
14
15#include <ns3/boolean.h>
16#include <ns3/integer.h>
17#include <ns3/log.h>
18#include <ns3/math.h>
19#include <ns3/pointer.h>
20#include <ns3/simulator.h>
21
22#include <cfloat>
23#include <set>
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("TdTbfqFfMacScheduler");
29
30/// TDTBFQ type 0 allocation RBG
31static const int TdTbfqType0AllocationRbg[4] = {
32 10, // RBG size 1
33 26, // RBG size 2
34 63, // RBG size 3
35 110, // RBG size 4
36}; // see table 7.1.6.1-1 of 36.213
37
38NS_OBJECT_ENSURE_REGISTERED(TdTbfqFfMacScheduler);
39
41 : m_cschedSapUser(nullptr),
42 m_schedSapUser(nullptr),
43 m_nextRntiUl(0),
44 bankSize(0)
45{
49 m_ffrSapProvider = nullptr;
51}
52
57
58void
73
76{
77 static TypeId tid =
78 TypeId("ns3::TdTbfqFfMacScheduler")
80 .SetGroupName("Lte")
81 .AddConstructor<TdTbfqFfMacScheduler>()
82 .AddAttribute("CqiTimerThreshold",
83 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
84 UintegerValue(1000),
87 .AddAttribute("DebtLimit",
88 "Flow debt limit (default -625000 bytes)",
89 IntegerValue(-625000),
92 .AddAttribute("CreditLimit",
93 "Flow credit limit (default 625000 bytes)",
94 UintegerValue(625000),
97 .AddAttribute("TokenPoolSize",
98 "The maximum value of flow token pool (default 1 bytes)",
102 .AddAttribute("CreditableThreshold",
103 "Threshold of flow credit (default 0 bytes)",
104 UintegerValue(0),
107
108 .AddAttribute("HarqEnabled",
109 "Activate/Deactivate the HARQ [by default is active].",
110 BooleanValue(true),
113 .AddAttribute("UlGrantMcs",
114 "The MCS of the UL grant, must be [0..15] (default 0)",
115 UintegerValue(0),
118 return tid;
119}
120
121void
126
127void
132
138
144
145void
150
156
157void
169
170void
173{
174 NS_LOG_FUNCTION(this << " RNTI " << params.m_rnti << " txMode "
175 << (uint16_t)params.m_transmissionMode);
176 auto it = m_uesTxMode.find(params.m_rnti);
177 if (it == m_uesTxMode.end())
178 {
179 m_uesTxMode[params.m_rnti] = params.m_transmissionMode;
180 // generate HARQ buffers
181 m_dlHarqCurrentProcessId[params.m_rnti] = 0;
182 DlHarqProcessesStatus_t dlHarqPrcStatus;
183 dlHarqPrcStatus.resize(8, 0);
184 m_dlHarqProcessesStatus[params.m_rnti] = dlHarqPrcStatus;
185 DlHarqProcessesTimer_t dlHarqProcessesTimer;
186 dlHarqProcessesTimer.resize(8, 0);
187 m_dlHarqProcessesTimer[params.m_rnti] = dlHarqProcessesTimer;
189 dlHarqdci.resize(8);
190 m_dlHarqProcessesDciBuffer[params.m_rnti] = dlHarqdci;
191 DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
192 dlHarqRlcPdu.resize(2);
193 dlHarqRlcPdu.at(0).resize(8);
194 dlHarqRlcPdu.at(1).resize(8);
195 m_dlHarqProcessesRlcPduListBuffer[params.m_rnti] = dlHarqRlcPdu;
196 m_ulHarqCurrentProcessId[params.m_rnti] = 0;
197 UlHarqProcessesStatus_t ulHarqPrcStatus;
198 ulHarqPrcStatus.resize(8, 0);
199 m_ulHarqProcessesStatus[params.m_rnti] = ulHarqPrcStatus;
201 ulHarqdci.resize(8);
202 m_ulHarqProcessesDciBuffer[params.m_rnti] = ulHarqdci;
203 }
204 else
205 {
206 (*it).second = params.m_transmissionMode;
207 }
208}
209
210void
213{
214 NS_LOG_FUNCTION(this << " New LC, rnti: " << params.m_rnti);
215
216 for (std::size_t i = 0; i < params.m_logicalChannelConfigList.size(); i++)
217 {
218 auto it = m_flowStatsDl.find(params.m_rnti);
219
220 if (it == m_flowStatsDl.end())
221 {
222 uint64_t mbrDlInBytes =
223 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateDl / 8; // byte/s
224 uint64_t mbrUlInBytes =
225 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateUl / 8; // byte/s
226
227 tdtbfqsFlowPerf_t flowStatsDl;
228 flowStatsDl.flowStart = Simulator::Now();
229 flowStatsDl.packetArrivalRate = 0;
230 flowStatsDl.tokenGenerationRate = mbrDlInBytes;
231 flowStatsDl.tokenPoolSize = 0;
232 flowStatsDl.maxTokenPoolSize = m_tokenPoolSize;
233 flowStatsDl.counter = 0;
234 flowStatsDl.burstCredit = m_creditLimit; // bytes
235 flowStatsDl.debtLimit = m_debtLimit; // bytes
237 m_flowStatsDl[params.m_rnti] = flowStatsDl;
238 tdtbfqsFlowPerf_t flowStatsUl;
239 flowStatsUl.flowStart = Simulator::Now();
240 flowStatsUl.packetArrivalRate = 0;
241 flowStatsUl.tokenGenerationRate = mbrUlInBytes;
242 flowStatsUl.tokenPoolSize = 0;
243 flowStatsUl.maxTokenPoolSize = m_tokenPoolSize;
244 flowStatsUl.counter = 0;
245 flowStatsUl.burstCredit = m_creditLimit; // bytes
246 flowStatsUl.debtLimit = m_debtLimit; // bytes
248 m_flowStatsUl[params.m_rnti] = flowStatsUl;
249 }
250 else
251 {
252 // update MBR and GBR from UeManager::SetupDataRadioBearer ()
253 uint64_t mbrDlInBytes =
254 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateDl / 8; // byte/s
255 uint64_t mbrUlInBytes =
256 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateUl / 8; // byte/s
257 m_flowStatsDl[(*it).first].tokenGenerationRate = mbrDlInBytes;
258 m_flowStatsUl[(*it).first].tokenGenerationRate = mbrUlInBytes;
259 }
260 }
261}
262
263void
266{
267 NS_LOG_FUNCTION(this);
268 for (std::size_t i = 0; i < params.m_logicalChannelIdentity.size(); i++)
269 {
270 auto it = m_rlcBufferReq.begin();
271 while (it != m_rlcBufferReq.end())
272 {
273 if (((*it).first.m_rnti == params.m_rnti) &&
274 ((*it).first.m_lcId == params.m_logicalChannelIdentity.at(i)))
275 {
276 auto temp = it;
277 it++;
278 m_rlcBufferReq.erase(temp);
279 }
280 else
281 {
282 it++;
283 }
284 }
285 }
286}
287
288void
291{
292 NS_LOG_FUNCTION(this);
293
294 m_uesTxMode.erase(params.m_rnti);
295 m_dlHarqCurrentProcessId.erase(params.m_rnti);
296 m_dlHarqProcessesStatus.erase(params.m_rnti);
297 m_dlHarqProcessesTimer.erase(params.m_rnti);
298 m_dlHarqProcessesDciBuffer.erase(params.m_rnti);
299 m_dlHarqProcessesRlcPduListBuffer.erase(params.m_rnti);
300 m_ulHarqCurrentProcessId.erase(params.m_rnti);
301 m_ulHarqProcessesStatus.erase(params.m_rnti);
302 m_ulHarqProcessesDciBuffer.erase(params.m_rnti);
303 m_flowStatsDl.erase(params.m_rnti);
304 m_flowStatsUl.erase(params.m_rnti);
305 m_ceBsrRxed.erase(params.m_rnti);
306 auto it = m_rlcBufferReq.begin();
307 while (it != m_rlcBufferReq.end())
308 {
309 if ((*it).first.m_rnti == params.m_rnti)
310 {
311 auto temp = it;
312 it++;
313 m_rlcBufferReq.erase(temp);
314 }
315 else
316 {
317 it++;
318 }
319 }
320 if (m_nextRntiUl == params.m_rnti)
321 {
322 m_nextRntiUl = 0;
323 }
324}
325
326void
329{
330 NS_LOG_FUNCTION(this << params.m_rnti << (uint32_t)params.m_logicalChannelIdentity);
331 // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
332
333 LteFlowId_t flow(params.m_rnti, params.m_logicalChannelIdentity);
334
335 auto it = m_rlcBufferReq.find(flow);
336
337 if (it == m_rlcBufferReq.end())
338 {
339 m_rlcBufferReq[flow] = params;
340 }
341 else
342 {
343 (*it).second = params;
344 }
345}
346
347void
354
355void
362
363int
365{
366 for (int i = 0; i < 4; i++)
367 {
368 if (dlbandwidth < TdTbfqType0AllocationRbg[i])
369 {
370 return i + 1;
371 }
372 }
373
374 return -1;
375}
376
377unsigned int
379{
380 unsigned int lcActive = 0;
381 for (auto it = m_rlcBufferReq.begin(); it != m_rlcBufferReq.end(); it++)
382 {
383 if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0) ||
384 ((*it).second.m_rlcRetransmissionQueueSize > 0) ||
385 ((*it).second.m_rlcStatusPduSize > 0)))
386 {
387 lcActive++;
388 }
389 if ((*it).first.m_rnti > rnti)
390 {
391 break;
392 }
393 }
394 return lcActive;
395}
396
397bool
399{
400 NS_LOG_FUNCTION(this << rnti);
401
402 auto it = m_dlHarqCurrentProcessId.find(rnti);
403 if (it == m_dlHarqCurrentProcessId.end())
404 {
405 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
406 }
407 auto itStat = m_dlHarqProcessesStatus.find(rnti);
408 if (itStat == m_dlHarqProcessesStatus.end())
409 {
410 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
411 }
412 uint8_t i = (*it).second;
413 do
414 {
415 i = (i + 1) % HARQ_PROC_NUM;
416 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
417
418 return (*itStat).second.at(i) == 0;
419}
420
421uint8_t
423{
424 NS_LOG_FUNCTION(this << rnti);
425
426 if (!m_harqOn)
427 {
428 return 0;
429 }
430
431 auto it = m_dlHarqCurrentProcessId.find(rnti);
432 if (it == m_dlHarqCurrentProcessId.end())
433 {
434 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
435 }
436 auto itStat = m_dlHarqProcessesStatus.find(rnti);
437 if (itStat == m_dlHarqProcessesStatus.end())
438 {
439 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
440 }
441 uint8_t i = (*it).second;
442 do
443 {
444 i = (i + 1) % HARQ_PROC_NUM;
445 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
446 if ((*itStat).second.at(i) == 0)
447 {
448 (*it).second = i;
449 (*itStat).second.at(i) = 1;
450 }
451 else
452 {
453 NS_FATAL_ERROR("No HARQ process available for RNTI "
454 << rnti << " check before update with HarqProcessAvailability");
455 }
456
457 return (*it).second;
458}
459
460void
462{
463 NS_LOG_FUNCTION(this);
464
465 for (auto itTimers = m_dlHarqProcessesTimer.begin(); itTimers != m_dlHarqProcessesTimer.end();
466 itTimers++)
467 {
468 for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
469 {
470 if ((*itTimers).second.at(i) == HARQ_DL_TIMEOUT)
471 {
472 // reset HARQ process
473
474 NS_LOG_DEBUG(this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
475 auto itStat = m_dlHarqProcessesStatus.find((*itTimers).first);
476 if (itStat == m_dlHarqProcessesStatus.end())
477 {
478 NS_FATAL_ERROR("No Process Id Status found for this RNTI "
479 << (*itTimers).first);
480 }
481 (*itStat).second.at(i) = 0;
482 (*itTimers).second.at(i) = 0;
483 }
484 else
485 {
486 (*itTimers).second.at(i)++;
487 }
488 }
489 }
490}
491
492void
495{
496 NS_LOG_FUNCTION(this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
497 << (0xF & params.m_sfnSf));
498 // API generated by RLC for triggering the scheduling of a DL subframe
499
500 // evaluate the relative channel quality indicator for each UE per each RBG
501 // (since we are using allocation type 0 the small unit of allocation is RBG)
502 // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
503
505
507 int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
508 std::map<uint16_t, std::vector<uint16_t>> allocationMap; // RBs map per RNTI
509 std::vector<bool> rbgMap; // global RBGs map
510 uint16_t rbgAllocatedNum = 0;
511 std::set<uint16_t> rntiAllocated;
512 rbgMap.resize(m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
513
515 for (auto it = rbgMap.begin(); it != rbgMap.end(); it++)
516 {
517 if (*it)
518 {
519 rbgAllocatedNum++;
520 }
521 }
522
524
525 // update UL HARQ proc id
526 for (auto itProcId = m_ulHarqCurrentProcessId.begin();
527 itProcId != m_ulHarqCurrentProcessId.end();
528 itProcId++)
529 {
530 (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
531 }
532
533 // RACH Allocation
534 std::vector<bool> ulRbMap;
535 ulRbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
537 uint8_t maxContinuousUlBandwidth = 0;
538 uint8_t tmpMinBandwidth = 0;
539 uint16_t ffrRbStartOffset = 0;
540 uint16_t tmpFfrRbStartOffset = 0;
541 uint16_t index = 0;
542
543 for (auto it = ulRbMap.begin(); it != ulRbMap.end(); it++)
544 {
545 if (*it)
546 {
547 if (tmpMinBandwidth > maxContinuousUlBandwidth)
548 {
549 maxContinuousUlBandwidth = tmpMinBandwidth;
550 ffrRbStartOffset = tmpFfrRbStartOffset;
551 }
552 tmpMinBandwidth = 0;
553 }
554 else
555 {
556 if (tmpMinBandwidth == 0)
557 {
558 tmpFfrRbStartOffset = index;
559 }
560 tmpMinBandwidth++;
561 }
562 index++;
563 }
564
565 if (tmpMinBandwidth > maxContinuousUlBandwidth)
566 {
567 maxContinuousUlBandwidth = tmpMinBandwidth;
568 ffrRbStartOffset = tmpFfrRbStartOffset;
569 }
570
572 uint16_t rbStart = 0;
573 rbStart = ffrRbStartOffset;
574 for (auto itRach = m_rachList.begin(); itRach != m_rachList.end(); itRach++)
575 {
577 (*itRach).m_estimatedSize,
578 " Default UL Grant MCS does not allow to send RACH messages");
580 newRar.m_rnti = (*itRach).m_rnti;
581 // DL-RACH Allocation
582 // Ideal: no needs of configuring m_dci
583 // UL-RACH Allocation
584 newRar.m_grant.m_rnti = newRar.m_rnti;
585 newRar.m_grant.m_mcs = m_ulGrantMcs;
586 uint16_t rbLen = 1;
587 uint16_t tbSizeBits = 0;
588 // find lowest TB size that fits UL grant estimated size
589 while ((tbSizeBits < (*itRach).m_estimatedSize) &&
590 (rbStart + rbLen < (ffrRbStartOffset + maxContinuousUlBandwidth)))
591 {
592 rbLen++;
593 tbSizeBits = m_amc->GetUlTbSizeFromMcs(m_ulGrantMcs, rbLen);
594 }
595 if (tbSizeBits < (*itRach).m_estimatedSize)
596 {
597 // no more allocation space: finish allocation
598 break;
599 }
600 newRar.m_grant.m_rbStart = rbStart;
601 newRar.m_grant.m_rbLen = rbLen;
602 newRar.m_grant.m_tbSize = tbSizeBits / 8;
603 newRar.m_grant.m_hopping = false;
604 newRar.m_grant.m_tpc = 0;
605 newRar.m_grant.m_cqiRequest = false;
606 newRar.m_grant.m_ulDelay = false;
607 NS_LOG_INFO(this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart "
608 << rbStart << " rbLen " << rbLen << " MCS " << m_ulGrantMcs << " tbSize "
609 << newRar.m_grant.m_tbSize);
610 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
611 {
612 m_rachAllocationMap.at(i) = (*itRach).m_rnti;
613 }
614
615 if (m_harqOn)
616 {
617 // generate UL-DCI for HARQ retransmissions
618 UlDciListElement_s uldci;
619 uldci.m_rnti = newRar.m_rnti;
620 uldci.m_rbLen = rbLen;
621 uldci.m_rbStart = rbStart;
622 uldci.m_mcs = m_ulGrantMcs;
623 uldci.m_tbSize = tbSizeBits / 8;
624 uldci.m_ndi = 1;
625 uldci.m_cceIndex = 0;
626 uldci.m_aggrLevel = 1;
627 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
628 uldci.m_hopping = false;
629 uldci.m_n2Dmrs = 0;
630 uldci.m_tpc = 0; // no power control
631 uldci.m_cqiRequest = false; // only period CQI at this stage
632 uldci.m_ulIndex = 0; // TDD parameter
633 uldci.m_dai = 1; // TDD parameter
634 uldci.m_freqHopping = 0;
635 uldci.m_pdcchPowerOffset = 0; // not used
636
637 uint8_t harqId = 0;
638 auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
639 if (itProcId == m_ulHarqCurrentProcessId.end())
640 {
641 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
642 }
643 harqId = (*itProcId).second;
644 auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
645 if (itDci == m_ulHarqProcessesDciBuffer.end())
646 {
647 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
648 << uldci.m_rnti);
649 }
650 (*itDci).second.at(harqId) = uldci;
651 }
652
653 rbStart = rbStart + rbLen;
654 ret.m_buildRarList.push_back(newRar);
655 }
656 m_rachList.clear();
657
658 // Process DL HARQ feedback
660 // retrieve past HARQ retx buffered
661 if (!m_dlInfoListBuffered.empty())
662 {
663 if (!params.m_dlInfoList.empty())
664 {
665 NS_LOG_INFO(this << " Received DL-HARQ feedback");
667 params.m_dlInfoList.begin(),
668 params.m_dlInfoList.end());
669 }
670 }
671 else
672 {
673 if (!params.m_dlInfoList.empty())
674 {
675 m_dlInfoListBuffered = params.m_dlInfoList;
676 }
677 }
678 if (!m_harqOn)
679 {
680 // Ignore HARQ feedback
681 m_dlInfoListBuffered.clear();
682 }
683 std::vector<DlInfoListElement_s> dlInfoListUntxed;
684 for (std::size_t i = 0; i < m_dlInfoListBuffered.size(); i++)
685 {
686 auto itRnti = rntiAllocated.find(m_dlInfoListBuffered.at(i).m_rnti);
687 if (itRnti != rntiAllocated.end())
688 {
689 // RNTI already allocated for retx
690 continue;
691 }
692 auto nLayers = m_dlInfoListBuffered.at(i).m_harqStatus.size();
693 std::vector<bool> retx;
694 NS_LOG_INFO(this << " Processing DLHARQ feedback");
695 if (nLayers == 1)
696 {
697 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
699 retx.push_back(false);
700 }
701 else
702 {
703 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
705 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(1) ==
707 }
708 if (retx.at(0) || retx.at(1))
709 {
710 // retrieve HARQ process information
711 uint16_t rnti = m_dlInfoListBuffered.at(i).m_rnti;
712 uint8_t harqId = m_dlInfoListBuffered.at(i).m_harqProcessId;
713 NS_LOG_INFO(this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
714 auto itHarq = m_dlHarqProcessesDciBuffer.find(rnti);
715 if (itHarq == m_dlHarqProcessesDciBuffer.end())
716 {
717 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << rnti);
718 }
719
720 DlDciListElement_s dci = (*itHarq).second.at(harqId);
721 int rv = 0;
722 if (dci.m_rv.size() == 1)
723 {
724 rv = dci.m_rv.at(0);
725 }
726 else
727 {
728 rv = (dci.m_rv.at(0) > dci.m_rv.at(1) ? dci.m_rv.at(0) : dci.m_rv.at(1));
729 }
730
731 if (rv == 3)
732 {
733 // maximum number of retx reached -> drop process
734 NS_LOG_INFO("Maximum number of retransmissions reached -> drop process");
735 auto it = m_dlHarqProcessesStatus.find(rnti);
736 if (it == m_dlHarqProcessesStatus.end())
737 {
738 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
739 << m_dlInfoListBuffered.at(i).m_rnti);
740 }
741 (*it).second.at(harqId) = 0;
742 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
743 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
744 {
745 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
746 << m_dlInfoListBuffered.at(i).m_rnti);
747 }
748 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
749 {
750 (*itRlcPdu).second.at(k).at(harqId).clear();
751 }
752 continue;
753 }
754 // check the feasibility of retransmitting on the same RBGs
755 // translate the DCI to Spectrum framework
756 std::vector<int> dciRbg;
757 uint32_t mask = 0x1;
758 NS_LOG_INFO("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
759 for (int j = 0; j < 32; j++)
760 {
761 if (((dci.m_rbBitmap & mask) >> j) == 1)
762 {
763 dciRbg.push_back(j);
764 NS_LOG_INFO("\t" << j);
765 }
766 mask = (mask << 1);
767 }
768 bool free = true;
769 for (std::size_t j = 0; j < dciRbg.size(); j++)
770 {
771 if (rbgMap.at(dciRbg.at(j)))
772 {
773 free = false;
774 break;
775 }
776 }
777 if (free)
778 {
779 // use the same RBGs for the retx
780 // reserve RBGs
781 for (std::size_t j = 0; j < dciRbg.size(); j++)
782 {
783 rbgMap.at(dciRbg.at(j)) = true;
784 NS_LOG_INFO("RBG " << dciRbg.at(j) << " assigned");
785 rbgAllocatedNum++;
786 }
787
788 NS_LOG_INFO(this << " Send retx in the same RBGs");
789 }
790 else
791 {
792 // find RBGs for sending HARQ retx
793 uint8_t j = 0;
794 uint8_t rbgId = (dciRbg.at(dciRbg.size() - 1) + 1) % rbgNum;
795 uint8_t startRbg = dciRbg.at(dciRbg.size() - 1);
796 std::vector<bool> rbgMapCopy = rbgMap;
797 while ((j < dciRbg.size()) && (startRbg != rbgId))
798 {
799 if (!rbgMapCopy.at(rbgId))
800 {
801 rbgMapCopy.at(rbgId) = true;
802 dciRbg.at(j) = rbgId;
803 j++;
804 }
805 rbgId = (rbgId + 1) % rbgNum;
806 }
807 if (j == dciRbg.size())
808 {
809 // find new RBGs -> update DCI map
810 uint32_t rbgMask = 0;
811 for (std::size_t k = 0; k < dciRbg.size(); k++)
812 {
813 rbgMask = rbgMask + (0x1 << dciRbg.at(k));
814 rbgAllocatedNum++;
815 }
816 dci.m_rbBitmap = rbgMask;
817 rbgMap = rbgMapCopy;
818 NS_LOG_INFO(this << " Move retx in RBGs " << dciRbg.size());
819 }
820 else
821 {
822 // HARQ retx cannot be performed on this TTI -> store it
823 dlInfoListUntxed.push_back(m_dlInfoListBuffered.at(i));
824 NS_LOG_INFO(this << " No resource for this retx -> buffer it");
825 }
826 }
827 // retrieve RLC PDU list for retx TBsize and update DCI
829 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
830 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
831 {
832 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
833 }
834 for (std::size_t j = 0; j < nLayers; j++)
835 {
836 if (retx.at(j))
837 {
838 if (j >= dci.m_ndi.size())
839 {
840 // for avoiding errors in MIMO transient phases
841 dci.m_ndi.push_back(0);
842 dci.m_rv.push_back(0);
843 dci.m_mcs.push_back(0);
844 dci.m_tbsSize.push_back(0);
845 NS_LOG_INFO(this << " layer " << (uint16_t)j
846 << " no txed (MIMO transition)");
847 }
848 else
849 {
850 dci.m_ndi.at(j) = 0;
851 dci.m_rv.at(j)++;
852 (*itHarq).second.at(harqId).m_rv.at(j)++;
853 NS_LOG_INFO(this << " layer " << (uint16_t)j << " RV "
854 << (uint16_t)dci.m_rv.at(j));
855 }
856 }
857 else
858 {
859 // empty TB of layer j
860 dci.m_ndi.at(j) = 0;
861 dci.m_rv.at(j) = 0;
862 dci.m_mcs.at(j) = 0;
863 dci.m_tbsSize.at(j) = 0;
864 NS_LOG_INFO(this << " layer " << (uint16_t)j << " no retx");
865 }
866 }
867 for (std::size_t k = 0; k < (*itRlcPdu).second.at(0).at(dci.m_harqProcess).size(); k++)
868 {
869 std::vector<RlcPduListElement_s> rlcPduListPerLc;
870 for (std::size_t j = 0; j < nLayers; j++)
871 {
872 if (retx.at(j))
873 {
874 if (j < dci.m_ndi.size())
875 {
876 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size "
877 << dci.m_tbsSize.at(j));
878 rlcPduListPerLc.push_back(
879 (*itRlcPdu).second.at(j).at(dci.m_harqProcess).at(k));
880 }
881 }
882 else
883 { // if no retx needed on layer j, push an RlcPduListElement_s object with
884 // m_size=0 to keep the size of rlcPduListPerLc vector = 2 in case of MIMO
885 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size " << dci.m_tbsSize.at(j));
886 RlcPduListElement_s emptyElement;
887 emptyElement.m_logicalChannelIdentity = (*itRlcPdu)
888 .second.at(j)
889 .at(dci.m_harqProcess)
890 .at(k)
891 .m_logicalChannelIdentity;
892 emptyElement.m_size = 0;
893 rlcPduListPerLc.push_back(emptyElement);
894 }
895 }
896
897 if (!rlcPduListPerLc.empty())
898 {
899 newEl.m_rlcPduList.push_back(rlcPduListPerLc);
900 }
901 }
902 newEl.m_rnti = rnti;
903 newEl.m_dci = dci;
904 (*itHarq).second.at(harqId).m_rv = dci.m_rv;
905 // refresh timer
906 auto itHarqTimer = m_dlHarqProcessesTimer.find(rnti);
907 if (itHarqTimer == m_dlHarqProcessesTimer.end())
908 {
909 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
910 }
911 (*itHarqTimer).second.at(harqId) = 0;
912 ret.m_buildDataList.push_back(newEl);
913 rntiAllocated.insert(rnti);
914 }
915 else
916 {
917 // update HARQ process status
918 NS_LOG_INFO(this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at(i).m_rnti);
919 auto it = m_dlHarqProcessesStatus.find(m_dlInfoListBuffered.at(i).m_rnti);
920 if (it == m_dlHarqProcessesStatus.end())
921 {
922 NS_FATAL_ERROR("No info find in HARQ buffer for UE "
923 << m_dlInfoListBuffered.at(i).m_rnti);
924 }
925 (*it).second.at(m_dlInfoListBuffered.at(i).m_harqProcessId) = 0;
926 auto itRlcPdu =
928 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
929 {
930 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
931 << m_dlInfoListBuffered.at(i).m_rnti);
932 }
933 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
934 {
935 (*itRlcPdu).second.at(k).at(m_dlInfoListBuffered.at(i).m_harqProcessId).clear();
936 }
937 }
938 }
939 m_dlInfoListBuffered.clear();
940 m_dlInfoListBuffered = dlInfoListUntxed;
941
942 if (rbgAllocatedNum == rbgNum)
943 {
944 // all the RBGs are already allocated -> exit
945 if (!ret.m_buildDataList.empty() || !ret.m_buildRarList.empty())
946 {
948 }
949 return;
950 }
951
952 // update token pool, counter and bank size
953 for (auto itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
954 {
955 if ((*itStats).second.tokenGenerationRate / 1000 + (*itStats).second.tokenPoolSize >
956 (*itStats).second.maxTokenPoolSize)
957 {
958 (*itStats).second.counter +=
959 (*itStats).second.tokenGenerationRate / 1000 -
960 ((*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize);
961 (*itStats).second.tokenPoolSize = (*itStats).second.maxTokenPoolSize;
962 bankSize += (*itStats).second.tokenGenerationRate / 1000 -
963 ((*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize);
964 }
965 else
966 {
967 (*itStats).second.tokenPoolSize += (*itStats).second.tokenGenerationRate / 1000;
968 }
969 }
970
971 // select UE with largest metric
972 auto itMax = m_flowStatsDl.end();
973 double metricMax = 0.0;
974 bool firstRnti = true;
975 for (auto it = m_flowStatsDl.begin(); it != m_flowStatsDl.end(); it++)
976 {
977 auto itRnti = rntiAllocated.find((*it).first);
978 if ((itRnti != rntiAllocated.end()) || (!HarqProcessAvailability((*it).first)))
979 {
980 // UE already allocated for HARQ or without HARQ process available -> drop it
981 if (itRnti != rntiAllocated.end())
982 {
983 NS_LOG_DEBUG(this << " RNTI discarded for HARQ tx" << (uint16_t)(*it).first);
984 }
985 if (!HarqProcessAvailability((*it).first))
986 {
987 NS_LOG_DEBUG(this << " RNTI discarded for HARQ id" << (uint16_t)(*it).first);
988 }
989 continue;
990 }
991
992 // check first the channel conditions for this UE, if CQI!=0
993 auto itCqi = m_a30CqiRxed.find((*it).first);
994 auto itTxMode = m_uesTxMode.find((*it).first);
995 if (itTxMode == m_uesTxMode.end())
996 {
997 NS_FATAL_ERROR("No Transmission Mode info on user " << (*it).first);
998 }
999 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1000
1001 uint8_t cqiSum = 0;
1002 for (int k = 0; k < rbgNum; k++)
1003 {
1004 for (uint8_t j = 0; j < nLayer; j++)
1005 {
1006 if (itCqi == m_a30CqiRxed.end())
1007 {
1008 cqiSum += 1; // no info on this user -> lowest MCS
1009 }
1010 else
1011 {
1012 cqiSum += (*itCqi).second.m_higherLayerSelected.at(k).m_sbCqi.at(j);
1013 }
1014 }
1015 }
1016
1017 if (cqiSum == 0)
1018 {
1019 NS_LOG_INFO("Skip this flow, CQI==0, rnti:" << (*it).first);
1020 continue;
1021 }
1022
1023 /*
1024 if (LcActivePerFlow ((*it).first) == 0)
1025 {
1026 continue;
1027 }
1028 */
1029
1030 double metric =
1031 (((double)(*it).second.counter) / ((double)(*it).second.tokenGenerationRate));
1032
1033 if (firstRnti)
1034 {
1035 metricMax = metric;
1036 itMax = it;
1037 firstRnti = false;
1038 continue;
1039 }
1040 if (metric > metricMax)
1041 {
1042 metricMax = metric;
1043 itMax = it;
1044 }
1045 } // end for m_flowStatsDl
1046
1047 if (itMax == m_flowStatsDl.end())
1048 {
1049 // all UEs are allocated RBG or all UEs already allocated for HARQ or without HARQ process
1050 // available
1051 return;
1052 }
1053 else
1054 {
1055 // assign all RBGs to this UE
1056 std::vector<uint16_t> tempMap;
1057 for (int i = 0; i < rbgNum; i++)
1058 {
1059 if (rbgMap.at(i))
1060 { // this RBG is allocated in RACH procedure
1061 continue;
1062 }
1063
1064 if (!m_ffrSapProvider->IsDlRbgAvailableForUe(i, (*itMax).first))
1065 {
1066 continue;
1067 }
1068
1069 tempMap.push_back(i);
1070 rbgMap.at(i) = true;
1071 }
1072 if (!tempMap.empty())
1073 {
1074 allocationMap[(*itMax).first] = tempMap;
1075 }
1076 }
1077
1078 // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1079 // creating the correspondent DCIs
1080 auto itMap = allocationMap.begin();
1081 while (itMap != allocationMap.end())
1082 {
1083 // create new BuildDataListElement_s for this LC
1085 newEl.m_rnti = (*itMap).first;
1086 // create the DlDciListElement_s
1087 DlDciListElement_s newDci;
1088 newDci.m_rnti = (*itMap).first;
1089 newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
1090
1091 uint16_t lcActives = LcActivePerFlow((*itMap).first);
1092 NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1093 if (lcActives == 0)
1094 {
1095 // Set to max value, to avoid divide by 0 below
1096 lcActives = (uint16_t)65535; // UINT16_MAX;
1097 }
1098 uint16_t RbgPerRnti = (*itMap).second.size();
1099 auto itCqi = m_a30CqiRxed.find((*itMap).first);
1100 auto itTxMode = m_uesTxMode.find((*itMap).first);
1101 if (itTxMode == m_uesTxMode.end())
1102 {
1103 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1104 }
1105 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1106 std::vector<uint8_t> worstCqi(2, 15);
1107 if (itCqi != m_a30CqiRxed.end())
1108 {
1109 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1110 {
1111 if ((*itCqi).second.m_higherLayerSelected.size() > (*itMap).second.at(k))
1112 {
1113 for (uint8_t j = 0; j < nLayer; j++)
1114 {
1115 if ((*itCqi)
1116 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1117 .m_sbCqi.size() > j)
1118 {
1119 if (((*itCqi)
1120 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1121 .m_sbCqi.at(j)) < worstCqi.at(j))
1122 {
1123 worstCqi.at(j) =
1124 ((*itCqi)
1125 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1126 .m_sbCqi.at(j));
1127 }
1128 }
1129 else
1130 {
1131 // no CQI for this layer of this suband -> worst one
1132 worstCqi.at(j) = 1;
1133 }
1134 }
1135 }
1136 else
1137 {
1138 for (uint8_t j = 0; j < nLayer; j++)
1139 {
1140 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1141 }
1142 }
1143 }
1144 }
1145 else
1146 {
1147 for (uint8_t j = 0; j < nLayer; j++)
1148 {
1149 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1150 }
1151 }
1152 uint32_t bytesTxed = 0;
1153 for (uint8_t j = 0; j < nLayer; j++)
1154 {
1155 newDci.m_mcs.push_back(m_amc->GetMcsFromCqi(worstCqi.at(j)));
1156 int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RbgPerRnti * rbgSize) /
1157 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1158 newDci.m_tbsSize.push_back(tbSize);
1159 bytesTxed += tbSize;
1160 }
1161
1162 newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1163 newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1164 uint32_t rbgMask = 0;
1165 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1166 {
1167 rbgMask = rbgMask + (0x1 << (*itMap).second.at(k));
1168 NS_LOG_INFO(this << " Allocated RBG " << (*itMap).second.at(k));
1169 }
1170 newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1171
1172 // create the rlc PDUs -> equally divide resources among actives LCs
1173 for (auto itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1174 {
1175 if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1176 (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1177 ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1178 ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1179 {
1180 std::vector<RlcPduListElement_s> newRlcPduLe;
1181 for (uint8_t j = 0; j < nLayer; j++)
1182 {
1183 RlcPduListElement_s newRlcEl;
1184 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1185 newRlcEl.m_size = newDci.m_tbsSize.at(j) / lcActives;
1186 NS_LOG_INFO(this << " LCID " << (uint32_t)newRlcEl.m_logicalChannelIdentity
1187 << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1188 newRlcPduLe.push_back(newRlcEl);
1190 newRlcEl.m_logicalChannelIdentity,
1191 newRlcEl.m_size);
1192 if (m_harqOn)
1193 {
1194 // store RLC PDU list for HARQ
1195 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1196 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1197 {
1198 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1199 << (*itMap).first);
1200 }
1201 (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1202 }
1203 }
1204 newEl.m_rlcPduList.push_back(newRlcPduLe);
1205 }
1206 if ((*itBufReq).first.m_rnti > (*itMap).first)
1207 {
1208 break;
1209 }
1210 }
1211 for (uint8_t j = 0; j < nLayer; j++)
1212 {
1213 newDci.m_ndi.push_back(1);
1214 newDci.m_rv.push_back(0);
1215 }
1216
1217 newDci.m_tpc = m_ffrSapProvider->GetTpc((*itMap).first);
1218
1219 newEl.m_dci = newDci;
1220
1221 if (m_harqOn)
1222 {
1223 // store DCI for HARQ
1224 auto itDci = m_dlHarqProcessesDciBuffer.find(newEl.m_rnti);
1225 if (itDci == m_dlHarqProcessesDciBuffer.end())
1226 {
1227 NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1228 << newEl.m_rnti);
1229 }
1230 (*itDci).second.at(newDci.m_harqProcess) = newDci;
1231 // refresh timer
1232 auto itHarqTimer = m_dlHarqProcessesTimer.find(newEl.m_rnti);
1233 if (itHarqTimer == m_dlHarqProcessesTimer.end())
1234 {
1235 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1236 }
1237 (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1238 }
1239
1240 // update UE stats
1241 if (bytesTxed <= (*itMax).second.tokenPoolSize)
1242 {
1243 (*itMax).second.tokenPoolSize -= bytesTxed;
1244 }
1245 else
1246 {
1247 (*itMax).second.counter =
1248 (*itMax).second.counter - (bytesTxed - (*itMax).second.tokenPoolSize);
1249 (*itMax).second.tokenPoolSize = 0;
1250 if (bankSize <= (bytesTxed - (*itMax).second.tokenPoolSize))
1251 {
1252 bankSize = 0;
1253 }
1254 else
1255 {
1256 bankSize = bankSize - (bytesTxed - (*itMax).second.tokenPoolSize);
1257 }
1258 }
1259
1260 // ...more parameters -> ignored in this version
1261
1262 ret.m_buildDataList.push_back(newEl);
1263
1264 itMap++;
1265 } // end while allocation
1266 ret.m_nrOfPdcchOfdmSymbols = 1; /// \todo check correct value according the DCIs txed
1267
1269}
1270
1271void
1279
1280void
1283{
1284 NS_LOG_FUNCTION(this);
1286
1287 for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1288 {
1289 if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1290 {
1291 NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1292 << " reported");
1293 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1294 auto it = m_p10CqiRxed.find(rnti);
1295 if (it == m_p10CqiRxed.end())
1296 {
1297 // create the new entry
1298 m_p10CqiRxed[rnti] =
1299 params.m_cqiList.at(i).m_wbCqi.at(0); // only codeword 0 at this stage (SISO)
1300 // generate correspondent timer
1302 }
1303 else
1304 {
1305 // update the CQI value and refresh correspondent timer
1306 (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1307 // update correspondent timer
1308 auto itTimers = m_p10CqiTimers.find(rnti);
1309 (*itTimers).second = m_cqiTimersThreshold;
1310 }
1311 }
1312 else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1313 {
1314 // subband CQI reporting high layer configured
1315 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1316 auto it = m_a30CqiRxed.find(rnti);
1317 if (it == m_a30CqiRxed.end())
1318 {
1319 // create the new entry
1320 m_a30CqiRxed[rnti] = params.m_cqiList.at(i).m_sbMeasResult;
1322 }
1323 else
1324 {
1325 // update the CQI value and refresh correspondent timer
1326 (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1327 auto itTimers = m_a30CqiTimers.find(rnti);
1328 (*itTimers).second = m_cqiTimersThreshold;
1329 }
1330 }
1331 else
1332 {
1333 NS_LOG_ERROR(this << " CQI type unknown");
1334 }
1335 }
1336}
1337
1338double
1339TdTbfqFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1340{
1341 auto itCqi = m_ueCqi.find(rnti);
1342 if (itCqi == m_ueCqi.end())
1343 {
1344 // no cqi info about this UE
1345 return NO_SINR;
1346 }
1347 else
1348 {
1349 // take the average SINR value among the available
1350 double sinrSum = 0;
1351 unsigned int sinrNum = 0;
1352 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1353 {
1354 double sinr = (*itCqi).second.at(i);
1355 if (sinr != NO_SINR)
1356 {
1357 sinrSum += sinr;
1358 sinrNum++;
1359 }
1360 }
1361 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1362 // store the value
1363 (*itCqi).second.at(rb) = estimatedSinr;
1364 return estimatedSinr;
1365 }
1366}
1367
1368void
1371{
1372 NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1373 << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1374
1377
1378 // Generate RBs map
1380 std::vector<bool> rbMap;
1381 uint16_t rbAllocatedNum = 0;
1382 std::set<uint16_t> rntiAllocated;
1383 std::vector<uint16_t> rbgAllocationMap;
1384 // update with RACH allocation map
1385 rbgAllocationMap = m_rachAllocationMap;
1386 // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1387 m_rachAllocationMap.clear();
1389
1390 rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1391
1393
1394 for (auto it = rbMap.begin(); it != rbMap.end(); it++)
1395 {
1396 if (*it)
1397 {
1398 rbAllocatedNum++;
1399 }
1400 }
1401
1402 uint8_t minContinuousUlBandwidth = m_ffrSapProvider->GetMinContinuousUlBandwidth();
1403 uint8_t ffrUlBandwidth = m_cschedCellConfig.m_ulBandwidth - rbAllocatedNum;
1404
1405 // remove RACH allocation
1406 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1407 {
1408 if (rbgAllocationMap.at(i) != 0)
1409 {
1410 rbMap.at(i) = true;
1411 NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1412 }
1413 }
1414
1415 if (m_harqOn)
1416 {
1417 // Process UL HARQ feedback
1418 for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1419 {
1420 if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1421 {
1422 // retx correspondent block: retrieve the UL-DCI
1423 uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1424 auto itProcId = m_ulHarqCurrentProcessId.find(rnti);
1425 if (itProcId == m_ulHarqCurrentProcessId.end())
1426 {
1427 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1428 }
1429 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1430 NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1431 << " i " << i << " size " << params.m_ulInfoList.size());
1432 auto itHarq = m_ulHarqProcessesDciBuffer.find(rnti);
1433 if (itHarq == m_ulHarqProcessesDciBuffer.end())
1434 {
1435 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1436 continue;
1437 }
1438 UlDciListElement_s dci = (*itHarq).second.at(harqId);
1439 auto itStat = m_ulHarqProcessesStatus.find(rnti);
1440 if (itStat == m_ulHarqProcessesStatus.end())
1441 {
1442 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1443 }
1444 if ((*itStat).second.at(harqId) >= 3)
1445 {
1446 NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1447 continue;
1448 }
1449 bool free = true;
1450 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1451 {
1452 if (rbMap.at(j))
1453 {
1454 free = false;
1455 NS_LOG_INFO(this << " BUSY " << j);
1456 }
1457 }
1458 if (free)
1459 {
1460 // retx on the same RBs
1461 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1462 {
1463 rbMap.at(j) = true;
1464 rbgAllocationMap.at(j) = dci.m_rnti;
1465 NS_LOG_INFO("\tRB " << j);
1466 rbAllocatedNum++;
1467 }
1468 NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1469 << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1470 << (*itStat).second.at(harqId) + 1);
1471 }
1472 else
1473 {
1474 NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1475 continue;
1476 }
1477 dci.m_ndi = 0;
1478 // Update HARQ buffers with new HarqId
1479 (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1480 (*itStat).second.at(harqId) = 0;
1481 (*itHarq).second.at((*itProcId).second) = dci;
1482 ret.m_dciList.push_back(dci);
1483 rntiAllocated.insert(dci.m_rnti);
1484 }
1485 else
1486 {
1487 NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1488 << params.m_ulInfoList.at(i).m_rnti);
1489 }
1490 }
1491 }
1492
1493 std::map<uint16_t, uint32_t>::iterator it;
1494 int nflows = 0;
1495
1496 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1497 {
1498 auto itRnti = rntiAllocated.find((*it).first);
1499 // select UEs with queues not empty and not yet allocated for HARQ
1500 if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1501 {
1502 nflows++;
1503 }
1504 }
1505
1506 if (nflows == 0)
1507 {
1508 if (!ret.m_dciList.empty())
1509 {
1510 m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1512 }
1513
1514 return; // no flows to be scheduled
1515 }
1516
1517 // Divide the remaining resources equally among the active users starting from the subsequent
1518 // one served last scheduling trigger
1519 uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size());
1520 uint16_t rbPerFlow =
1521 (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1522
1523 if (rbPerFlow < 3)
1524 {
1525 rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1526 // >= 7 bytes
1527 }
1528 int rbAllocated = 0;
1529
1530 if (m_nextRntiUl != 0)
1531 {
1532 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1533 {
1534 if ((*it).first == m_nextRntiUl)
1535 {
1536 break;
1537 }
1538 }
1539 if (it == m_ceBsrRxed.end())
1540 {
1541 NS_LOG_ERROR(this << " no user found");
1542 }
1543 }
1544 else
1545 {
1546 it = m_ceBsrRxed.begin();
1547 m_nextRntiUl = (*it).first;
1548 }
1549 do
1550 {
1551 auto itRnti = rntiAllocated.find((*it).first);
1552 if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1553 {
1554 // UE already allocated for UL-HARQ -> skip it
1555 NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1556 << (*it).first);
1557 it++;
1558 if (it == m_ceBsrRxed.end())
1559 {
1560 // restart from the first
1561 it = m_ceBsrRxed.begin();
1562 }
1563 continue;
1564 }
1565 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1566 {
1567 // limit to physical resources last resource assignment
1568 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1569 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1570 if (rbPerFlow < 3)
1571 {
1572 // terminate allocation
1573 rbPerFlow = 0;
1574 }
1575 }
1576
1577 rbAllocated = 0;
1578 UlDciListElement_s uldci;
1579 uldci.m_rnti = (*it).first;
1580 uldci.m_rbLen = rbPerFlow;
1581 bool allocated = false;
1582 NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1583 << " flows " << nflows);
1584 while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1585 (rbPerFlow != 0))
1586 {
1587 // check availability
1588 bool free = true;
1589 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1590 {
1591 if (rbMap.at(j))
1592 {
1593 free = false;
1594 break;
1595 }
1596 if (!m_ffrSapProvider->IsUlRbgAvailableForUe(j, (*it).first))
1597 {
1598 free = false;
1599 break;
1600 }
1601 }
1602 if (free)
1603 {
1604 NS_LOG_INFO(this << "RNTI: " << (*it).first << " RB Allocated " << rbAllocated
1605 << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1606 uldci.m_rbStart = rbAllocated;
1607
1608 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1609 {
1610 rbMap.at(j) = true;
1611 // store info on allocation for managing ul-cqi interpretation
1612 rbgAllocationMap.at(j) = (*it).first;
1613 }
1614 rbAllocated += rbPerFlow;
1615 allocated = true;
1616 break;
1617 }
1618 rbAllocated++;
1619 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1620 {
1621 // limit to physical resources last resource assignment
1622 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1623 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1624 if (rbPerFlow < 3)
1625 {
1626 // terminate allocation
1627 rbPerFlow = 0;
1628 }
1629 }
1630 }
1631 if (!allocated)
1632 {
1633 // unable to allocate new resource: finish scheduling
1634 // m_nextRntiUl = (*it).first;
1635 // if (ret.m_dciList.size () > 0)
1636 // {
1637 // m_schedSapUser->SchedUlConfigInd (ret);
1638 // }
1639 // m_allocationMaps[params.m_sfnSf] = rbgAllocationMap; return;
1640 break;
1641 }
1642
1643 auto itCqi = m_ueCqi.find((*it).first);
1644 int cqi = 0;
1645 if (itCqi == m_ueCqi.end())
1646 {
1647 // no cqi info about this UE
1648 uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1649 }
1650 else
1651 {
1652 // take the lowest CQI value (worst RB)
1653 NS_ABORT_MSG_IF((*itCqi).second.empty(),
1654 "CQI of RNTI = " << (*it).first << " has expired");
1655 double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1656 if (minSinr == NO_SINR)
1657 {
1658 minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1659 }
1660 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1661 {
1662 double sinr = (*itCqi).second.at(i);
1663 if (sinr == NO_SINR)
1664 {
1665 sinr = EstimateUlSinr((*it).first, i);
1666 }
1667 if (sinr < minSinr)
1668 {
1669 minSinr = sinr;
1670 }
1671 }
1672
1673 // translate SINR -> cqi: WILD ACK: same as DL
1674 double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1675 cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1676 if (cqi == 0)
1677 {
1678 it++;
1679 if (it == m_ceBsrRxed.end())
1680 {
1681 // restart from the first
1682 it = m_ceBsrRxed.begin();
1683 }
1684 NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1685 // remove UE from allocation map
1686 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1687 {
1688 rbgAllocationMap.at(i) = 0;
1689 }
1690 continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1691 }
1692 uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1693 }
1694
1695 uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1697 uldci.m_ndi = 1;
1698 uldci.m_cceIndex = 0;
1699 uldci.m_aggrLevel = 1;
1700 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1701 uldci.m_hopping = false;
1702 uldci.m_n2Dmrs = 0;
1703 uldci.m_tpc = 0; // no power control
1704 uldci.m_cqiRequest = false; // only period CQI at this stage
1705 uldci.m_ulIndex = 0; // TDD parameter
1706 uldci.m_dai = 1; // TDD parameter
1707 uldci.m_freqHopping = 0;
1708 uldci.m_pdcchPowerOffset = 0; // not used
1709 ret.m_dciList.push_back(uldci);
1710 // store DCI for HARQ_PERIOD
1711 uint8_t harqId = 0;
1712 if (m_harqOn)
1713 {
1714 auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1715 if (itProcId == m_ulHarqCurrentProcessId.end())
1716 {
1717 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1718 }
1719 harqId = (*itProcId).second;
1720 auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
1721 if (itDci == m_ulHarqProcessesDciBuffer.end())
1722 {
1723 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1724 << uldci.m_rnti);
1725 }
1726 (*itDci).second.at(harqId) = uldci;
1727 // Update HARQ process status (RV 0)
1728 auto itStat = m_ulHarqProcessesStatus.find(uldci.m_rnti);
1729 if (itStat == m_ulHarqProcessesStatus.end())
1730 {
1731 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1732 << uldci.m_rnti);
1733 }
1734 (*itStat).second.at(harqId) = 0;
1735 }
1736
1737 NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1738 << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1739 << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1740 << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1741 << (uint16_t)harqId);
1742
1743 it++;
1744 if (it == m_ceBsrRxed.end())
1745 {
1746 // restart from the first
1747 it = m_ceBsrRxed.begin();
1748 }
1749 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1750 {
1751 // Stop allocation: no more PRBs
1752 m_nextRntiUl = (*it).first;
1753 break;
1754 }
1755 } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1756
1757 m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1759}
1760
1761void
1767
1768void
1774
1775void
1778{
1779 NS_LOG_FUNCTION(this);
1780
1781 for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1782 {
1783 if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1784 {
1785 // buffer status report
1786 // note that this scheduler does not differentiate the
1787 // allocation according to which LCGs have more/less bytes
1788 // to send.
1789 // Hence the BSR of different LCGs are just summed up to get
1790 // a total queue size that is used for allocation purposes.
1791
1792 uint32_t buffer = 0;
1793 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1794 {
1795 uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1796 buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1797 }
1798
1799 uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1800 NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1801 auto it = m_ceBsrRxed.find(rnti);
1802 if (it == m_ceBsrRxed.end())
1803 {
1804 // create the new entry
1805 m_ceBsrRxed[rnti] = buffer;
1806 }
1807 else
1808 {
1809 // update the buffer size value
1810 (*it).second = buffer;
1811 }
1812 }
1813 }
1814}
1815
1816void
1819{
1820 NS_LOG_FUNCTION(this);
1821 // retrieve the allocation for this subframe
1822 switch (m_ulCqiFilter)
1823 {
1825 // filter all the CQIs that are not SRS based
1826 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1827 {
1828 return;
1829 }
1830 }
1831 break;
1833 // filter all the CQIs that are not SRS based
1834 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1835 {
1836 return;
1837 }
1838 }
1839 break;
1840 default:
1841 NS_FATAL_ERROR("Unknown UL CQI type");
1842 }
1843
1844 switch (params.m_ulCqi.m_type)
1845 {
1846 case UlCqi_s::PUSCH: {
1847 NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1848 << " subframe no. " << (0xF & params.m_sfnSf));
1849 auto itMap = m_allocationMaps.find(params.m_sfnSf);
1850 if (itMap == m_allocationMaps.end())
1851 {
1852 return;
1853 }
1854 for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1855 {
1856 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1857 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1858 auto itCqi = m_ueCqi.find((*itMap).second.at(i));
1859 if (itCqi == m_ueCqi.end())
1860 {
1861 // create a new entry
1862 std::vector<double> newCqi;
1863 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1864 {
1865 if (i == j)
1866 {
1867 newCqi.push_back(sinr);
1868 }
1869 else
1870 {
1871 // initialize with NO_SINR value.
1872 newCqi.push_back(NO_SINR);
1873 }
1874 }
1875 m_ueCqi[(*itMap).second.at(i)] = newCqi;
1876 // generate correspondent timer
1877 m_ueCqiTimers[(*itMap).second.at(i)] = m_cqiTimersThreshold;
1878 }
1879 else
1880 {
1881 // update the value
1882 (*itCqi).second.at(i) = sinr;
1883 NS_LOG_DEBUG(this << " RNTI " << (*itMap).second.at(i) << " RB " << i << " SINR "
1884 << sinr);
1885 // update correspondent timer
1886 auto itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1887 (*itTimers).second = m_cqiTimersThreshold;
1888 }
1889 }
1890 // remove obsolete info on allocation
1891 m_allocationMaps.erase(itMap);
1892 }
1893 break;
1894 case UlCqi_s::SRS: {
1895 // get the RNTI from vendor specific parameters
1896 uint16_t rnti = 0;
1897 NS_ASSERT(!params.m_vendorSpecificList.empty());
1898 for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1899 {
1900 if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1901 {
1902 Ptr<SrsCqiRntiVsp> vsp =
1903 DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1904 rnti = vsp->GetRnti();
1905 }
1906 }
1907 auto itCqi = m_ueCqi.find(rnti);
1908 if (itCqi == m_ueCqi.end())
1909 {
1910 // create a new entry
1911 std::vector<double> newCqi;
1912 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1913 {
1914 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1915 newCqi.push_back(sinr);
1916 NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1917 << sinr);
1918 }
1919 m_ueCqi[rnti] = newCqi;
1920 // generate correspondent timer
1922 }
1923 else
1924 {
1925 // update the values
1926 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1927 {
1928 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1929 (*itCqi).second.at(j) = sinr;
1930 NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1931 << sinr);
1932 }
1933 // update correspondent timer
1934 auto itTimers = m_ueCqiTimers.find(rnti);
1935 (*itTimers).second = m_cqiTimersThreshold;
1936 }
1937 }
1938 break;
1939 case UlCqi_s::PUCCH_1:
1940 case UlCqi_s::PUCCH_2:
1941 case UlCqi_s::PRACH: {
1942 NS_FATAL_ERROR("TdTbfqFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1943 }
1944 break;
1945 default:
1946 NS_FATAL_ERROR("Unknown type of UL-CQI");
1947 }
1948}
1949
1950void
1952{
1953 // refresh DL CQI P01 Map
1954 auto itP10 = m_p10CqiTimers.begin();
1955 while (itP10 != m_p10CqiTimers.end())
1956 {
1957 NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1958 << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1959 if ((*itP10).second == 0)
1960 {
1961 // delete correspondent entries
1962 auto itMap = m_p10CqiRxed.find((*itP10).first);
1963 NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1964 " Does not find CQI report for user " << (*itP10).first);
1965 NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1966 m_p10CqiRxed.erase(itMap);
1967 auto temp = itP10;
1968 itP10++;
1969 m_p10CqiTimers.erase(temp);
1970 }
1971 else
1972 {
1973 (*itP10).second--;
1974 itP10++;
1975 }
1976 }
1977
1978 // refresh DL CQI A30 Map
1979 auto itA30 = m_a30CqiTimers.begin();
1980 while (itA30 != m_a30CqiTimers.end())
1981 {
1982 NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1983 << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1984 if ((*itA30).second == 0)
1985 {
1986 // delete correspondent entries
1987 auto itMap = m_a30CqiRxed.find((*itA30).first);
1988 NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1989 " Does not find CQI report for user " << (*itA30).first);
1990 NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1991 m_a30CqiRxed.erase(itMap);
1992 auto temp = itA30;
1993 itA30++;
1994 m_a30CqiTimers.erase(temp);
1995 }
1996 else
1997 {
1998 (*itA30).second--;
1999 itA30++;
2000 }
2001 }
2002}
2003
2004void
2006{
2007 // refresh UL CQI Map
2008 auto itUl = m_ueCqiTimers.begin();
2009 while (itUl != m_ueCqiTimers.end())
2010 {
2011 NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
2012 << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2013 if ((*itUl).second == 0)
2014 {
2015 // delete correspondent entries
2016 auto itMap = m_ueCqi.find((*itUl).first);
2017 NS_ASSERT_MSG(itMap != m_ueCqi.end(),
2018 " Does not find CQI report for user " << (*itUl).first);
2019 NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
2020 (*itMap).second.clear();
2021 m_ueCqi.erase(itMap);
2022 auto temp = itUl;
2023 itUl++;
2024 m_ueCqiTimers.erase(temp);
2025 }
2026 else
2027 {
2028 (*itUl).second--;
2029 itUl++;
2030 }
2031 }
2032}
2033
2034void
2035TdTbfqFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
2036{
2037 LteFlowId_t flow(rnti, lcid);
2038 auto it = m_rlcBufferReq.find(flow);
2039 if (it != m_rlcBufferReq.end())
2040 {
2041 NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
2042 << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
2043 << (*it).second.m_rlcRetransmissionQueueSize << " status "
2044 << (*it).second.m_rlcStatusPduSize << " decrease " << size);
2045 // Update queues: RLC tx order Status, ReTx, Tx
2046 // Update status queue
2047 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2048 {
2049 (*it).second.m_rlcStatusPduSize = 0;
2050 }
2051 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
2052 (size >= (*it).second.m_rlcRetransmissionQueueSize))
2053 {
2054 (*it).second.m_rlcRetransmissionQueueSize = 0;
2055 }
2056 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2057 {
2058 uint32_t rlcOverhead;
2059 if (lcid == 1)
2060 {
2061 // for SRB1 (using RLC AM) it's better to
2062 // overestimate RLC overhead rather than
2063 // underestimate it and risk unneeded
2064 // segmentation which increases delay
2065 rlcOverhead = 4;
2066 }
2067 else
2068 {
2069 // minimum RLC overhead due to header
2070 rlcOverhead = 2;
2071 }
2072 // update transmission queue
2073 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2074 {
2075 (*it).second.m_rlcTransmissionQueueSize = 0;
2076 }
2077 else
2078 {
2079 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2080 }
2081 }
2082 }
2083 else
2084 {
2085 NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
2086 }
2087}
2088
2089void
2091{
2092 size = size - 2; // remove the minimum RLC overhead
2093 auto it = m_ceBsrRxed.find(rnti);
2094 if (it != m_ceBsrRxed.end())
2095 {
2096 NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2097 if ((*it).second >= size)
2098 {
2099 (*it).second -= size;
2100 }
2101 else
2102 {
2103 (*it).second = 0;
2104 }
2105 }
2106 else
2107 {
2108 NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
2109 }
2110}
2111
2112void
2114{
2115 NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2117 params.m_rnti = rnti;
2118 params.m_transmissionMode = txMode;
2120}
2121
2122} // namespace ns3
AttributeValue implementation for Boolean.
Definition boolean.h:26
static uint32_t BsrId2BufferSize(uint8_t val)
Convert BSR ID to buffer size.
Provides the CSCHED SAP.
FfMacCschedSapUser class.
virtual void CschedUeConfigCnf(const CschedUeConfigCnfParameters &params)=0
CSCHED_UE_CONFIG_CNF.
virtual void CschedUeConfigUpdateInd(const CschedUeConfigUpdateIndParameters &params)=0
CSCHED_UE_UPDATE_IND.
Provides the SCHED SAP.
FfMacSchedSapUser class.
virtual void SchedUlConfigInd(const SchedUlConfigIndParameters &params)=0
SCHED_UL_CONFIG_IND.
virtual void SchedDlConfigInd(const SchedDlConfigIndParameters &params)=0
SCHED_DL_CONFIG_IND.
This abstract base class identifies the interface by means of which the helper object can plug on the...
UlCqiFilter_t m_ulCqiFilter
UL CQI filter.
Hold a signed integer type.
Definition integer.h:34
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
virtual uint8_t GetTpc(uint16_t rnti)=0
GetTpc.
virtual std::vector< bool > GetAvailableUlRbg()=0
Get vector of available RB in UL for this Cell.
virtual void ReportUlCqiInfo(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)=0
ReportUlCqiInfo.
virtual bool IsUlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in UL.
virtual void ReportDlCqiInfo(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)=0
ReportDlCqiInfo.
virtual std::vector< bool > GetAvailableDlRbg()=0
Get vector of available RBG in DL for this Cell.
virtual uint16_t GetMinContinuousUlBandwidth()=0
Get the minimum continuous Ul bandwidth.
virtual bool IsDlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in DL.
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.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Implements the SCHED SAP and CSCHED SAP for a Time Domain Token Bank Fair Queue scheduler.
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
bool HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
void SetLteFfrSapProvider(LteFfrSapProvider *s) override
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
static TypeId GetTypeId()
Get the type ID.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info function.
~TdTbfqFfMacScheduler() override
Destructor.
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
FfMacSchedSapUser * m_schedSapUser
A=Sched SAP user.
unsigned int LcActivePerFlow(uint16_t rnti)
LC active flow size.
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
uint32_t m_creditLimit
flow credit limit (byte)
void DoSchedUlMacCtrlInfoReq(const FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
void DoSchedUlTriggerReq(const FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request.
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
int GetRbgSize(int dlbandwidth)
Get RBG size.
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_ulHarqCurrentProcessId
UL HARQ current process ID.
void DoSchedDlPagingBufferReq(const FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request.
void RefreshDlCqiMaps()
Refresh DL CQI maps function.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
uint32_t m_creditableThreshold
threshold of flow credit
void DoSchedDlTriggerReq(const FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request.
std::map< uint16_t, tdtbfqsFlowPerf_t > m_flowStatsUl
Map of UE statistics (per RNTI basis)
LteFfrSapUser * GetLteFfrSapUser() override
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
void DoSchedDlMacBufferReq(const FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request.
void DoCschedLcConfigReq(const FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mde configuration update function.
friend class MemberCschedSapProvider< TdTbfqFfMacScheduler >
allow MemberCschedSapProvider<TdTbfqFfMacScheduler> class friend access
void DoSchedDlRachInfoReq(const FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
void RefreshUlCqiMaps()
Refresh UL CQI maps function.
void DoSchedUlCqiInfoReq(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request.
void SetFfMacSchedSapUser(FfMacSchedSapUser *s) override
set the user part of the FfMacSchedSap that this Scheduler will interact with.
int m_debtLimit
flow debt limit (byte)
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
Estimate UL SINR function.
std::vector< RachListElement_s > m_rachList
RACH list.
void DoCschedLcReleaseReq(const FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
void DoSchedUlSrInfoReq(const FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
void DoCschedUeConfigReq(const FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request.
friend class MemberSchedSapProvider< TdTbfqFfMacScheduler >
allow MemberSchedSapProvider<TdTbfqFfMacScheduler> class friend access
uint32_t m_tokenPoolSize
maximum size of token pool (byte)
void DoCschedUeReleaseReq(const FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request.
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
void DoSchedDlRlcBufferReq(const FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request.
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
void DoDispose() override
Destructor implementation.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
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 RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void SetFfMacCschedSapUser(FfMacCschedSapUser *s) override
set the user part of the FfMacCschedSap that this Scheduler will interact with.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
void DoSchedUlNoiseInterferenceReq(const FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
void DoCschedCellConfigReq(const FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request.
void DoSchedDlCqiInfoReq(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request.
std::map< uint16_t, tdtbfqsFlowPerf_t > m_flowStatsDl
Map of UE statistics (per RNTI basis) in downlink.
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
Map of UE's DL CQI A30 received.
uint64_t bankSize
the number of bytes in token bank
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#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:75
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition boolean.h:70
Ptr< const AttributeChecker > MakeIntegerChecker()
Definition integer.h:99
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition integer.h:35
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
#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:97
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:19
#define SRS_CQI_RNTI_VSP
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector.
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...
static const int TdTbfqType0AllocationRbg[4]
TDTBFQ type 0 allocation RBG.
std::vector< uint8_t > UlHarqProcessesStatus_t
UL HARQ process status vector.
std::vector< uint8_t > DlHarqProcessesStatus_t
DL HARQ process status vector.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector.
@ SUCCESS
constexpr uint32_t HARQ_DL_TIMEOUT
HARQ DL timeout.
constexpr uint32_t HARQ_PROC_NUM
Number of HARQ processes.
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
Vector of the 8 HARQ processes per UE.
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
UL HARQ process DCI buffer vector.
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.
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.
LteFlowId structure.
Definition lte-common.h:32
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.
uint32_t tokenPoolSize
current size of token pool (byte)
int debtLimit
counter threshold that the flow cannot further borrow tokens from bank
uint32_t maxTokenPoolSize
maximum size of token pool (byte)
int counter
the number of token borrow or given to token bank
uint32_t creditableThreshold
the flow cannot borrow token from bank until the number of token it has deposited to bank reaches thi...
uint64_t packetArrivalRate
packet arrival rate( byte/s)
uint64_t tokenGenerationRate
token generation rate ( byte/s )
uint32_t burstCredit
the maximum number of tokens connection i can borrow from the bank each time