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