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