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 (see table 7.1.6.1-1 of 36.213)
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};
35
36NS_OBJECT_ENSURE_REGISTERED(PfFfMacScheduler);
37
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
137{
138 NS_LOG_FUNCTION(this);
139 // Read the subset of parameters used
140 m_cschedCellConfig = params;
141 m_rachAllocationMap.resize(m_cschedCellConfig.m_ulBandwidth, 0);
143 cnf.m_result = SUCCESS;
144 m_cschedSapUser->CschedUeConfigCnf(cnf);
145}
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
458 int rbgSize = GetRbgSize(m_cschedCellConfig.m_dlBandwidth);
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
466 rbgMap = m_ffrSapProvider->GetAvailableDlRbg();
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);
488 ulRbMap = m_ffrSapProvider->GetAvailableUlRbg();
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
523 m_rachAllocationMap.resize(m_cschedCellConfig.m_ulBandwidth, 0);
524 uint16_t rbStart = 0;
525 rbStart = ffrRbStartOffset;
526 for (auto itRach = m_rachList.begin(); itRach != m_rachList.end(); itRach++)
527 {
528 NS_ASSERT_MSG(m_amc->GetUlTbSizeFromMcs(m_ulGrantMcs, m_cschedCellConfig.m_ulBandwidth) >
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 retx.reserve(2);
647 NS_LOG_INFO(this << " Processing DLHARQ feedback");
648 if (nLayers == 1)
649 {
650 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
652 retx.push_back(false);
653 }
654 else
655 {
656 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
658 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(1) ==
660 }
661 if (retx.at(0) || retx.at(1))
662 {
663 // retrieve HARQ process information
664 uint16_t rnti = m_dlInfoListBuffered.at(i).m_rnti;
665 uint8_t harqId = m_dlInfoListBuffered.at(i).m_harqProcessId;
666 NS_LOG_INFO(this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
667 auto itHarq = m_dlHarqProcessesDciBuffer.find(rnti);
668 if (itHarq == m_dlHarqProcessesDciBuffer.end())
669 {
670 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << rnti);
671 }
672
673 DlDciListElement_s dci = (*itHarq).second.at(harqId);
674 int rv = 0;
675 if (dci.m_rv.size() == 1)
676 {
677 rv = dci.m_rv.at(0);
678 }
679 else
680 {
681 rv = (dci.m_rv.at(0) > dci.m_rv.at(1) ? dci.m_rv.at(0) : dci.m_rv.at(1));
682 }
683
684 if (rv == 3)
685 {
686 // maximum number of retx reached -> drop process
687 NS_LOG_INFO("Maximum number of retransmissions reached -> drop process");
688 auto it = m_dlHarqProcessesStatus.find(rnti);
689 if (it == m_dlHarqProcessesStatus.end())
690 {
691 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
692 << m_dlInfoListBuffered.at(i).m_rnti);
693 }
694 (*it).second.at(harqId) = 0;
695 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
696 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
697 {
698 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
699 << m_dlInfoListBuffered.at(i).m_rnti);
700 }
701 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
702 {
703 (*itRlcPdu).second.at(k).at(harqId).clear();
704 }
705 continue;
706 }
707 // check the feasibility of retransmitting on the same RBGs
708 // translate the DCI to Spectrum framework
709 std::vector<int> dciRbg;
710 uint32_t mask = 0x1;
711 NS_LOG_INFO("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
712 for (int j = 0; j < 32; j++)
713 {
714 if (((dci.m_rbBitmap & mask) >> j) == 1)
715 {
716 dciRbg.push_back(j);
717 NS_LOG_INFO("\t" << j);
718 }
719 mask = (mask << 1);
720 }
721 bool free = true;
722 for (std::size_t j = 0; j < dciRbg.size(); j++)
723 {
724 if (rbgMap.at(dciRbg.at(j)))
725 {
726 free = false;
727 break;
728 }
729 }
730 if (free)
731 {
732 // use the same RBGs for the retx
733 // reserve RBGs
734 for (std::size_t j = 0; j < dciRbg.size(); j++)
735 {
736 rbgMap.at(dciRbg.at(j)) = true;
737 NS_LOG_INFO("RBG " << dciRbg.at(j) << " assigned");
738 rbgAllocatedNum++;
739 }
740
741 NS_LOG_INFO(this << " Send retx in the same RBGs");
742 }
743 else
744 {
745 // find RBGs for sending HARQ retx
746 uint8_t j = 0;
747 uint8_t rbgId = (dciRbg.at(dciRbg.size() - 1) + 1) % rbgNum;
748 uint8_t startRbg = dciRbg.at(dciRbg.size() - 1);
749 std::vector<bool> rbgMapCopy = rbgMap;
750 while ((j < dciRbg.size()) && (startRbg != rbgId))
751 {
752 if (!rbgMapCopy.at(rbgId))
753 {
754 rbgMapCopy.at(rbgId) = true;
755 dciRbg.at(j) = rbgId;
756 j++;
757 }
758 rbgId = (rbgId + 1) % rbgNum;
759 }
760 if (j == dciRbg.size())
761 {
762 // find new RBGs -> update DCI map
763 uint32_t rbgMask = 0;
764 for (std::size_t k = 0; k < dciRbg.size(); k++)
765 {
766 rbgMask = rbgMask + (0x1 << dciRbg.at(k));
767 rbgAllocatedNum++;
768 }
769 dci.m_rbBitmap = rbgMask;
770 rbgMap = rbgMapCopy;
771 NS_LOG_INFO(this << " Move retx in RBGs " << dciRbg.size());
772 }
773 else
774 {
775 // HARQ retx cannot be performed on this TTI -> store it
776 dlInfoListUntxed.push_back(m_dlInfoListBuffered.at(i));
777 NS_LOG_INFO(this << " No resource for this retx -> buffer it");
778 }
779 }
780 // retrieve RLC PDU list for retx TBsize and update DCI
782 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
783 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
784 {
785 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
786 }
787 for (std::size_t j = 0; j < nLayers; j++)
788 {
789 if (retx.at(j))
790 {
791 if (j >= dci.m_ndi.size())
792 {
793 // for avoiding errors in MIMO transient phases
794 dci.m_ndi.push_back(0);
795 dci.m_rv.push_back(0);
796 dci.m_mcs.push_back(0);
797 dci.m_tbsSize.push_back(0);
798 NS_LOG_INFO(this << " layer " << (uint16_t)j
799 << " no txed (MIMO transition)");
800 }
801 else
802 {
803 dci.m_ndi.at(j) = 0;
804 dci.m_rv.at(j)++;
805 (*itHarq).second.at(harqId).m_rv.at(j)++;
806 NS_LOG_INFO(this << " layer " << (uint16_t)j << " RV "
807 << (uint16_t)dci.m_rv.at(j));
808 }
809 }
810 else
811 {
812 // empty TB of layer j
813 dci.m_ndi.at(j) = 0;
814 dci.m_rv.at(j) = 0;
815 dci.m_mcs.at(j) = 0;
816 dci.m_tbsSize.at(j) = 0;
817 NS_LOG_INFO(this << " layer " << (uint16_t)j << " no retx");
818 }
819 }
820 for (std::size_t k = 0; k < (*itRlcPdu).second.at(0).at(dci.m_harqProcess).size(); k++)
821 {
822 std::vector<RlcPduListElement_s> rlcPduListPerLc;
823 for (std::size_t j = 0; j < nLayers; j++)
824 {
825 if (retx.at(j))
826 {
827 if (j < dci.m_ndi.size())
828 {
829 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size "
830 << dci.m_tbsSize.at(j));
831 rlcPduListPerLc.push_back(
832 (*itRlcPdu).second.at(j).at(dci.m_harqProcess).at(k));
833 }
834 }
835 else
836 { // if no retx needed on layer j, push an RlcPduListElement_s object with
837 // m_size=0 to keep the size of rlcPduListPerLc vector = 2 in case of MIMO
838 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size " << dci.m_tbsSize.at(j));
839 RlcPduListElement_s emptyElement;
840 emptyElement.m_logicalChannelIdentity = (*itRlcPdu)
841 .second.at(j)
842 .at(dci.m_harqProcess)
843 .at(k)
844 .m_logicalChannelIdentity;
845 emptyElement.m_size = 0;
846 rlcPduListPerLc.push_back(emptyElement);
847 }
848 }
849
850 if (!rlcPduListPerLc.empty())
851 {
852 newEl.m_rlcPduList.push_back(rlcPduListPerLc);
853 }
854 }
855 newEl.m_rnti = rnti;
856 newEl.m_dci = dci;
857 (*itHarq).second.at(harqId).m_rv = dci.m_rv;
858 // refresh timer
859 auto itHarqTimer = m_dlHarqProcessesTimer.find(rnti);
860 if (itHarqTimer == m_dlHarqProcessesTimer.end())
861 {
862 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
863 }
864 (*itHarqTimer).second.at(harqId) = 0;
865 ret.m_buildDataList.push_back(newEl);
866 rntiAllocated.insert(rnti);
867 }
868 else
869 {
870 // update HARQ process status
871 NS_LOG_INFO(this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at(i).m_rnti);
872 auto it = m_dlHarqProcessesStatus.find(m_dlInfoListBuffered.at(i).m_rnti);
873 if (it == m_dlHarqProcessesStatus.end())
874 {
875 NS_FATAL_ERROR("No info find in HARQ buffer for UE "
876 << m_dlInfoListBuffered.at(i).m_rnti);
877 }
878 (*it).second.at(m_dlInfoListBuffered.at(i).m_harqProcessId) = 0;
879 auto itRlcPdu =
881 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
882 {
883 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
884 << m_dlInfoListBuffered.at(i).m_rnti);
885 }
886 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
887 {
888 (*itRlcPdu).second.at(k).at(m_dlInfoListBuffered.at(i).m_harqProcessId).clear();
889 }
890 }
891 }
892 m_dlInfoListBuffered.clear();
893 m_dlInfoListBuffered = dlInfoListUntxed;
894
895 if (rbgAllocatedNum == rbgNum)
896 {
897 // all the RBGs are already allocated -> exit
898 if (!ret.m_buildDataList.empty() || !ret.m_buildRarList.empty())
899 {
900 m_schedSapUser->SchedDlConfigInd(ret);
901 }
902 return;
903 }
904
905 for (int i = 0; i < rbgNum; i++)
906 {
907 NS_LOG_INFO(this << " ALLOCATION for RBG " << i << " of " << rbgNum);
908 if (!rbgMap.at(i))
909 {
910 auto itMax = m_flowStatsDl.end();
911 double rcqiMax = 0.0;
912 for (auto it = m_flowStatsDl.begin(); it != m_flowStatsDl.end(); it++)
913 {
914 if (!m_ffrSapProvider->IsDlRbgAvailableForUe(i, (*it).first))
915 {
916 continue;
917 }
918
919 auto itRnti = rntiAllocated.find((*it).first);
920 if (itRnti != rntiAllocated.end() || !HarqProcessAvailability((*it).first))
921 {
922 // UE already allocated for HARQ or without HARQ process available -> drop it
923 if (itRnti != rntiAllocated.end())
924 {
925 NS_LOG_DEBUG(this << " RNTI discarded for HARQ tx"
926 << (uint16_t)(*it).first);
927 }
928 if (!HarqProcessAvailability((*it).first))
929 {
930 NS_LOG_DEBUG(this << " RNTI discarded for HARQ id"
931 << (uint16_t)(*it).first);
932 }
933 continue;
934 }
935 auto itCqi = m_a30CqiRxed.find((*it).first);
936 auto itTxMode = m_uesTxMode.find((*it).first);
937 if (itTxMode == m_uesTxMode.end())
938 {
939 NS_FATAL_ERROR("No Transmission Mode info on user " << (*it).first);
940 }
941 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
942 std::vector<uint8_t> sbCqi;
943 if (itCqi == m_a30CqiRxed.end())
944 {
945 sbCqi = std::vector<uint8_t>(nLayer, 1); // start with lowest value
946 }
947 else
948 {
949 sbCqi = (*itCqi).second.m_higherLayerSelected.at(i).m_sbCqi;
950 }
951 uint8_t cqi1 = sbCqi.at(0);
952 uint8_t cqi2 = 0;
953 if (sbCqi.size() > 1)
954 {
955 cqi2 = sbCqi.at(1);
956 }
957
958 if ((cqi1 > 0) ||
959 (cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
960 {
961 if (LcActivePerFlow((*it).first) > 0)
962 {
963 // this UE has data to transmit
964 double achievableRate = 0.0;
965 uint8_t mcs = 0;
966 for (uint8_t k = 0; k < nLayer; k++)
967 {
968 if (sbCqi.size() > k)
969 {
970 mcs = m_amc->GetMcsFromCqi(sbCqi.at(k));
971 }
972 else
973 {
974 // no info on this subband -> worst MCS
975 mcs = 0;
976 }
977 achievableRate += ((m_amc->GetDlTbSizeFromMcs(mcs, rbgSize) / 8) /
978 0.001); // = TB size / TTI
979 }
980
981 double rcqi = achievableRate / (*it).second.lastAveragedThroughput;
982 NS_LOG_INFO(this << " RNTI " << (*it).first << " MCS " << (uint32_t)mcs
983 << " achievableRate " << achievableRate << " avgThr "
984 << (*it).second.lastAveragedThroughput << " RCQI "
985 << rcqi);
986
987 if (rcqi > rcqiMax)
988 {
989 rcqiMax = rcqi;
990 itMax = it;
991 }
992 }
993 }
994 }
995
996 if (itMax == m_flowStatsDl.end())
997 {
998 // no UE available for this RB
999 NS_LOG_INFO(this << " any UE found");
1000 }
1001 else
1002 {
1003 rbgMap.at(i) = true;
1004 auto itMap = allocationMap.find((*itMax).first);
1005 if (itMap == allocationMap.end())
1006 {
1007 // insert new element
1008 std::vector<uint16_t> tempMap;
1009 tempMap.push_back(i);
1010 allocationMap[(*itMax).first] = tempMap;
1011 }
1012 else
1013 {
1014 (*itMap).second.push_back(i);
1015 }
1016 NS_LOG_INFO(this << " UE assigned " << (*itMax).first);
1017 }
1018 }
1019 }
1020
1021 // reset TTI stats of users
1022 for (auto itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
1023 {
1024 (*itStats).second.lastTtiBytesTransmitted = 0;
1025 }
1026
1027 // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1028 // creating the correspondent DCIs
1029 auto itMap = allocationMap.begin();
1030 while (itMap != allocationMap.end())
1031 {
1032 // create new BuildDataListElement_s for this LC
1034 newEl.m_rnti = (*itMap).first;
1035 // create the DlDciListElement_s
1036 DlDciListElement_s newDci;
1037 newDci.m_rnti = (*itMap).first;
1038 newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
1039
1040 uint16_t lcActives = LcActivePerFlow((*itMap).first);
1041 NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1042 if (lcActives == 0)
1043 {
1044 // Set to max value, to avoid divide by 0 below
1045 lcActives = (uint16_t)65535; // UINT16_MAX;
1046 }
1047 uint16_t RbgPerRnti = (*itMap).second.size();
1048 auto itCqi = m_a30CqiRxed.find((*itMap).first);
1049 auto itTxMode = m_uesTxMode.find((*itMap).first);
1050 if (itTxMode == m_uesTxMode.end())
1051 {
1052 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1053 }
1054 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1055 std::vector<uint8_t> worstCqi(2, 15);
1056 if (itCqi != m_a30CqiRxed.end())
1057 {
1058 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1059 {
1060 if ((*itCqi).second.m_higherLayerSelected.size() > (*itMap).second.at(k))
1061 {
1062 NS_LOG_INFO(this << " RBG " << (*itMap).second.at(k) << " CQI "
1063 << (uint16_t)((*itCqi)
1064 .second.m_higherLayerSelected
1065 .at((*itMap).second.at(k))
1066 .m_sbCqi.at(0)));
1067 for (uint8_t j = 0; j < nLayer; j++)
1068 {
1069 if ((*itCqi)
1070 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1071 .m_sbCqi.size() > j)
1072 {
1073 if (((*itCqi)
1074 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1075 .m_sbCqi.at(j)) < worstCqi.at(j))
1076 {
1077 worstCqi.at(j) =
1078 ((*itCqi)
1079 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1080 .m_sbCqi.at(j));
1081 }
1082 }
1083 else
1084 {
1085 // no CQI for this layer of this suband -> worst one
1086 worstCqi.at(j) = 1;
1087 }
1088 }
1089 }
1090 else
1091 {
1092 for (uint8_t j = 0; j < nLayer; j++)
1093 {
1094 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1095 }
1096 }
1097 }
1098 }
1099 else
1100 {
1101 for (uint8_t j = 0; j < nLayer; j++)
1102 {
1103 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1104 }
1105 }
1106 for (uint8_t j = 0; j < nLayer; j++)
1107 {
1108 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " CQI selected "
1109 << (uint16_t)worstCqi.at(j));
1110 }
1111 uint32_t bytesTxed = 0;
1112 for (uint8_t j = 0; j < nLayer; j++)
1113 {
1114 newDci.m_mcs.push_back(m_amc->GetMcsFromCqi(worstCqi.at(j)));
1115 int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RbgPerRnti * rbgSize) /
1116 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1117 newDci.m_tbsSize.push_back(tbSize);
1118 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " MCS selected"
1119 << m_amc->GetMcsFromCqi(worstCqi.at(j)));
1120 bytesTxed += tbSize;
1121 }
1122
1123 newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1124 newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1125 uint32_t rbgMask = 0;
1126 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1127 {
1128 rbgMask = rbgMask + (0x1 << (*itMap).second.at(k));
1129 NS_LOG_INFO(this << " Allocated RBG " << (*itMap).second.at(k));
1130 }
1131 newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1132
1133 // create the rlc PDUs -> equally divide resources among actives LCs
1134 for (auto itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1135 {
1136 if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1137 (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1138 ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1139 ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1140 {
1141 std::vector<RlcPduListElement_s> newRlcPduLe;
1142 for (uint8_t j = 0; j < nLayer; j++)
1143 {
1144 RlcPduListElement_s newRlcEl;
1145 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1146 newRlcEl.m_size = newDci.m_tbsSize.at(j) / lcActives;
1147 NS_LOG_INFO(this << " LCID " << (uint32_t)newRlcEl.m_logicalChannelIdentity
1148 << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1149 newRlcPduLe.push_back(newRlcEl);
1151 newRlcEl.m_logicalChannelIdentity,
1152 newRlcEl.m_size);
1153 if (m_harqOn)
1154 {
1155 // store RLC PDU list for HARQ
1156 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1157 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1158 {
1159 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1160 << (*itMap).first);
1161 }
1162 (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1163 }
1164 }
1165 newEl.m_rlcPduList.push_back(newRlcPduLe);
1166 }
1167 if ((*itBufReq).first.m_rnti > (*itMap).first)
1168 {
1169 break;
1170 }
1171 }
1172 for (uint8_t j = 0; j < nLayer; j++)
1173 {
1174 newDci.m_ndi.push_back(1);
1175 newDci.m_rv.push_back(0);
1176 }
1177
1178 newDci.m_tpc = m_ffrSapProvider->GetTpc((*itMap).first);
1179
1180 newEl.m_dci = newDci;
1181
1182 if (m_harqOn)
1183 {
1184 // store DCI for HARQ
1185 auto itDci = m_dlHarqProcessesDciBuffer.find(newEl.m_rnti);
1186 if (itDci == m_dlHarqProcessesDciBuffer.end())
1187 {
1188 NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1189 << newEl.m_rnti);
1190 }
1191 (*itDci).second.at(newDci.m_harqProcess) = newDci;
1192 // refresh timer
1193 auto itHarqTimer = m_dlHarqProcessesTimer.find(newEl.m_rnti);
1194 if (itHarqTimer == m_dlHarqProcessesTimer.end())
1195 {
1196 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1197 }
1198 (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1199 }
1200
1201 // ...more parameters -> ignored in this version
1202
1203 ret.m_buildDataList.push_back(newEl);
1204 // update UE stats
1205 auto it = m_flowStatsDl.find((*itMap).first);
1206 if (it != m_flowStatsDl.end())
1207 {
1208 (*it).second.lastTtiBytesTransmitted = bytesTxed;
1209 NS_LOG_INFO(this << " UE total bytes txed " << (*it).second.lastTtiBytesTransmitted);
1210 }
1211 else
1212 {
1213 NS_FATAL_ERROR(this << " No Stats for this allocated UE");
1214 }
1215
1216 itMap++;
1217 }
1218 ret.m_nrOfPdcchOfdmSymbols = 1; /// \todo check correct value according the DCIs txed
1219
1220 // update UEs stats
1221 NS_LOG_INFO(this << " Update UEs statistics");
1222 for (auto itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
1223 {
1224 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
1225 // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
1226 // Evolution, Ed Wiley)
1227 (*itStats).second.lastAveragedThroughput =
1228 ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
1229 ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1230 NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1231 NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1232 (*itStats).second.lastTtiBytesTransmitted = 0;
1233 }
1234
1235 m_schedSapUser->SchedDlConfigInd(ret);
1236}
1237
1238void
1241{
1242 NS_LOG_FUNCTION(this);
1243
1244 m_rachList = params.m_rachList;
1245}
1246
1247void
1250{
1251 NS_LOG_FUNCTION(this);
1252 m_ffrSapProvider->ReportDlCqiInfo(params);
1253
1254 for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1255 {
1256 if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1257 {
1258 NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1259 << " reported");
1260 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1261 auto it = m_p10CqiRxed.find(rnti);
1262 if (it == m_p10CqiRxed.end())
1263 {
1264 // create the new entry
1265 m_p10CqiRxed[rnti] =
1266 params.m_cqiList.at(i).m_wbCqi.at(0); // only codeword 0 at this stage (SISO)
1267 // generate correspondent timer
1269 }
1270 else
1271 {
1272 // update the CQI value and refresh correspondent timer
1273 (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1274 // update correspondent timer
1275 auto itTimers = m_p10CqiTimers.find(rnti);
1276 (*itTimers).second = m_cqiTimersThreshold;
1277 }
1278 }
1279 else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1280 {
1281 // subband CQI reporting high layer configured
1282 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1283 auto it = m_a30CqiRxed.find(rnti);
1284 if (it == m_a30CqiRxed.end())
1285 {
1286 // create the new entry
1287 m_a30CqiRxed[rnti] = params.m_cqiList.at(i).m_sbMeasResult;
1289 }
1290 else
1291 {
1292 // update the CQI value and refresh correspondent timer
1293 (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1294 auto itTimers = m_a30CqiTimers.find(rnti);
1295 (*itTimers).second = m_cqiTimersThreshold;
1296 }
1297 }
1298 else
1299 {
1300 NS_LOG_ERROR(this << " CQI type unknown");
1301 }
1302 }
1303}
1304
1305double
1306PfFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1307{
1308 auto itCqi = m_ueCqi.find(rnti);
1309 if (itCqi == m_ueCqi.end())
1310 {
1311 // no cqi info about this UE
1312 return NO_SINR;
1313 }
1314 else
1315 {
1316 // take the average SINR value among the available
1317 double sinrSum = 0;
1318 unsigned int sinrNum = 0;
1319 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1320 {
1321 double sinr = (*itCqi).second.at(i);
1322 if (sinr != NO_SINR)
1323 {
1324 sinrSum += sinr;
1325 sinrNum++;
1326 }
1327 }
1328 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1329 // store the value
1330 (*itCqi).second.at(rb) = estimatedSinr;
1331 return estimatedSinr;
1332 }
1333}
1334
1335void
1338{
1339 NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1340 << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1341
1343 m_ffrSapProvider->ReportUlCqiInfo(m_ueCqi);
1344
1345 // Generate RBs map
1347 std::vector<bool> rbMap;
1348 uint16_t rbAllocatedNum = 0;
1349 std::set<uint16_t> rntiAllocated;
1350 std::vector<uint16_t> rbgAllocationMap;
1351 // update with RACH allocation map
1352 rbgAllocationMap = m_rachAllocationMap;
1353 // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1354 m_rachAllocationMap.clear();
1355 m_rachAllocationMap.resize(m_cschedCellConfig.m_ulBandwidth, 0);
1356
1357 rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1358 rbMap = m_ffrSapProvider->GetAvailableUlRbg();
1359
1360 for (auto it = rbMap.begin(); it != rbMap.end(); it++)
1361 {
1362 if (*it)
1363 {
1364 rbAllocatedNum++;
1365 }
1366 }
1367
1368 uint8_t minContinuousUlBandwidth = m_ffrSapProvider->GetMinContinuousUlBandwidth();
1369 uint8_t ffrUlBandwidth = m_cschedCellConfig.m_ulBandwidth - rbAllocatedNum;
1370
1371 // remove RACH allocation
1372 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1373 {
1374 if (rbgAllocationMap.at(i) != 0)
1375 {
1376 rbMap.at(i) = true;
1377 NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1378 }
1379 }
1380
1381 if (m_harqOn)
1382 {
1383 // Process UL HARQ feedback
1384
1385 for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1386 {
1387 if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1388 {
1389 // retx correspondent block: retrieve the UL-DCI
1390 uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1391 auto itProcId = m_ulHarqCurrentProcessId.find(rnti);
1392 if (itProcId == m_ulHarqCurrentProcessId.end())
1393 {
1394 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1395 }
1396 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1397 NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1398 << " i " << i << " size " << params.m_ulInfoList.size());
1399 auto itHarq = m_ulHarqProcessesDciBuffer.find(rnti);
1400 if (itHarq == m_ulHarqProcessesDciBuffer.end())
1401 {
1402 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1403 continue;
1404 }
1405 UlDciListElement_s dci = (*itHarq).second.at(harqId);
1406 auto itStat = m_ulHarqProcessesStatus.find(rnti);
1407 if (itStat == m_ulHarqProcessesStatus.end())
1408 {
1409 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1410 }
1411 if ((*itStat).second.at(harqId) >= 3)
1412 {
1413 NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1414 continue;
1415 }
1416 bool free = true;
1417 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1418 {
1419 if (rbMap.at(j))
1420 {
1421 free = false;
1422 NS_LOG_INFO(this << " BUSY " << j);
1423 }
1424 }
1425 if (free)
1426 {
1427 // retx on the same RBs
1428 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1429 {
1430 rbMap.at(j) = true;
1431 rbgAllocationMap.at(j) = dci.m_rnti;
1432 NS_LOG_INFO("\tRB " << j);
1433 rbAllocatedNum++;
1434 }
1435 NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1436 << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1437 << (*itStat).second.at(harqId) + 1);
1438 }
1439 else
1440 {
1441 NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1442 continue;
1443 }
1444 dci.m_ndi = 0;
1445 // Update HARQ buffers with new HarqId
1446 (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1447 (*itStat).second.at(harqId) = 0;
1448 (*itHarq).second.at((*itProcId).second) = dci;
1449 ret.m_dciList.push_back(dci);
1450 rntiAllocated.insert(dci.m_rnti);
1451 }
1452 else
1453 {
1454 NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1455 << params.m_ulInfoList.at(i).m_rnti);
1456 }
1457 }
1458 }
1459
1460 std::map<uint16_t, uint32_t>::iterator it;
1461 int nflows = 0;
1462
1463 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1464 {
1465 auto itRnti = rntiAllocated.find((*it).first);
1466 // select UEs with queues not empty and not yet allocated for HARQ
1467 if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1468 {
1469 nflows++;
1470 }
1471 }
1472
1473 if (nflows == 0)
1474 {
1475 if (!ret.m_dciList.empty())
1476 {
1477 m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1478 m_schedSapUser->SchedUlConfigInd(ret);
1479 }
1480
1481 return; // no flows to be scheduled
1482 }
1483
1484 // Divide the remaining resources equally among the active users starting from the subsequent
1485 // one served last scheduling trigger
1486 uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size());
1487 uint16_t rbPerFlow =
1488 (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1489
1490 if (rbPerFlow < 3)
1491 {
1492 rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1493 // >= 7 bytes
1494 }
1495
1496 int rbAllocated = 0;
1497
1498 if (m_nextRntiUl != 0)
1499 {
1500 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1501 {
1502 if ((*it).first == m_nextRntiUl)
1503 {
1504 break;
1505 }
1506 }
1507 if (it == m_ceBsrRxed.end())
1508 {
1509 NS_LOG_ERROR(this << " no user found");
1510 }
1511 }
1512 else
1513 {
1514 it = m_ceBsrRxed.begin();
1515 m_nextRntiUl = (*it).first;
1516 }
1517 do
1518 {
1519 auto itRnti = rntiAllocated.find((*it).first);
1520 if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1521 {
1522 // UE already allocated for UL-HARQ -> skip it
1523 NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1524 << (*it).first);
1525 it++;
1526 if (it == m_ceBsrRxed.end())
1527 {
1528 // restart from the first
1529 it = m_ceBsrRxed.begin();
1530 }
1531 continue;
1532 }
1533 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1534 {
1535 // limit to physical resources last resource assignment
1536 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1537 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1538 if (rbPerFlow < 3)
1539 {
1540 // terminate allocation
1541 rbPerFlow = 0;
1542 }
1543 }
1544
1545 rbAllocated = 0;
1546 UlDciListElement_s uldci;
1547 uldci.m_rnti = (*it).first;
1548 uldci.m_rbLen = rbPerFlow;
1549 bool allocated = false;
1550
1551 while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1552 (rbPerFlow != 0))
1553 {
1554 // check availability
1555 bool free = true;
1556 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1557 {
1558 if (rbMap.at(j))
1559 {
1560 free = false;
1561 break;
1562 }
1563 if (!m_ffrSapProvider->IsUlRbgAvailableForUe(j, (*it).first))
1564 {
1565 free = false;
1566 break;
1567 }
1568 }
1569 if (free)
1570 {
1571 NS_LOG_INFO(this << "RNTI: " << (*it).first << " RB Allocated " << rbAllocated
1572 << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1573 uldci.m_rbStart = rbAllocated;
1574
1575 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1576 {
1577 rbMap.at(j) = true;
1578 // store info on allocation for managing ul-cqi interpretation
1579 rbgAllocationMap.at(j) = (*it).first;
1580 }
1581 rbAllocated += rbPerFlow;
1582 allocated = true;
1583 break;
1584 }
1585 rbAllocated++;
1586 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1587 {
1588 // limit to physical resources last resource assignment
1589 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1590 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1591 if (rbPerFlow < 3)
1592 {
1593 // terminate allocation
1594 rbPerFlow = 0;
1595 }
1596 }
1597 }
1598 if (!allocated)
1599 {
1600 // unable to allocate new resource: finish scheduling
1601 m_nextRntiUl = (*it).first;
1602 // if (ret.m_dciList.size () > 0)
1603 // {
1604 // m_schedSapUser->SchedUlConfigInd (ret);
1605 // }
1606 // m_allocationMaps[params.m_sfnSf] = rbgAllocationMap; return;
1607 break;
1608 }
1609
1610 auto itCqi = m_ueCqi.find((*it).first);
1611 int cqi = 0;
1612 if (itCqi == m_ueCqi.end())
1613 {
1614 // no cqi info about this UE
1615 uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1616 }
1617 else
1618 {
1619 // take the lowest CQI value (worst RB)
1620 NS_ABORT_MSG_IF((*itCqi).second.empty(),
1621 "CQI of RNTI = " << (*it).first << " has expired");
1622 double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1623 if (minSinr == NO_SINR)
1624 {
1625 minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1626 }
1627 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1628 {
1629 double sinr = (*itCqi).second.at(i);
1630 if (sinr == NO_SINR)
1631 {
1632 sinr = EstimateUlSinr((*it).first, i);
1633 }
1634 if (sinr < minSinr)
1635 {
1636 minSinr = sinr;
1637 }
1638 }
1639
1640 // translate SINR -> cqi: WILD ACK: same as DL
1641 double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1642 cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1643 if (cqi == 0)
1644 {
1645 it++;
1646 if (it == m_ceBsrRxed.end())
1647 {
1648 // restart from the first
1649 it = m_ceBsrRxed.begin();
1650 }
1651 NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1652 // remove UE from allocation map
1653 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1654 {
1655 rbgAllocationMap.at(i) = 0;
1656 }
1657 continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1658 }
1659 uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1660 }
1661
1662 uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1664 uldci.m_ndi = 1;
1665 uldci.m_cceIndex = 0;
1666 uldci.m_aggrLevel = 1;
1667 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1668 uldci.m_hopping = false;
1669 uldci.m_n2Dmrs = 0;
1670 uldci.m_tpc = 0; // no power control
1671 uldci.m_cqiRequest = false; // only period CQI at this stage
1672 uldci.m_ulIndex = 0; // TDD parameter
1673 uldci.m_dai = 1; // TDD parameter
1674 uldci.m_freqHopping = 0;
1675 uldci.m_pdcchPowerOffset = 0; // not used
1676 ret.m_dciList.push_back(uldci);
1677 // store DCI for HARQ_PERIOD
1678 uint8_t harqId = 0;
1679 if (m_harqOn)
1680 {
1681 auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1682 if (itProcId == m_ulHarqCurrentProcessId.end())
1683 {
1684 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1685 }
1686 harqId = (*itProcId).second;
1687 auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
1688 if (itDci == m_ulHarqProcessesDciBuffer.end())
1689 {
1690 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1691 << uldci.m_rnti);
1692 }
1693 (*itDci).second.at(harqId) = uldci;
1694 // Update HARQ process status (RV 0)
1695 auto itStat = m_ulHarqProcessesStatus.find(uldci.m_rnti);
1696 if (itStat == m_ulHarqProcessesStatus.end())
1697 {
1698 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1699 << uldci.m_rnti);
1700 }
1701 (*itStat).second.at(harqId) = 0;
1702 }
1703
1704 NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1705 << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1706 << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1707 << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1708 << (uint16_t)harqId);
1709
1710 // update TTI UE stats
1711 auto itStats = m_flowStatsUl.find((*it).first);
1712 if (itStats != m_flowStatsUl.end())
1713 {
1714 (*itStats).second.lastTtiBytesTransmitted = uldci.m_tbSize;
1715 }
1716 else
1717 {
1718 NS_LOG_DEBUG(this << " No Stats for this allocated UE");
1719 }
1720
1721 it++;
1722 if (it == m_ceBsrRxed.end())
1723 {
1724 // restart from the first
1725 it = m_ceBsrRxed.begin();
1726 }
1727 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1728 {
1729 // Stop allocation: no more PRBs
1730 m_nextRntiUl = (*it).first;
1731 break;
1732 }
1733 } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1734
1735 // Update global UE stats
1736 // update UEs stats
1737 for (auto itStats = m_flowStatsUl.begin(); itStats != m_flowStatsUl.end(); itStats++)
1738 {
1739 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
1740 // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
1741 // Evolution, Ed Wiley)
1742 (*itStats).second.lastAveragedThroughput =
1743 ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
1744 ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1745 NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1746 NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1747 (*itStats).second.lastTtiBytesTransmitted = 0;
1748 }
1749 m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1750 m_schedSapUser->SchedUlConfigInd(ret);
1751}
1752
1753void
1759
1760void
1766
1767void
1770{
1771 NS_LOG_FUNCTION(this);
1772
1773 for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1774 {
1775 if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1776 {
1777 // buffer status report
1778 // note that this scheduler does not differentiate the
1779 // allocation according to which LCGs have more/less bytes
1780 // to send.
1781 // Hence the BSR of different LCGs are just summed up to get
1782 // a total queue size that is used for allocation purposes.
1783
1784 uint32_t buffer = 0;
1785 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1786 {
1787 uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1788 buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1789 }
1790
1791 uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1792 NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1793 auto it = m_ceBsrRxed.find(rnti);
1794 if (it == m_ceBsrRxed.end())
1795 {
1796 // create the new entry
1797 m_ceBsrRxed[rnti] = buffer;
1798 }
1799 else
1800 {
1801 // update the buffer size value
1802 (*it).second = buffer;
1803 }
1804 }
1805 }
1806}
1807
1808void
1811{
1812 NS_LOG_FUNCTION(this);
1813 m_ffrSapProvider->ReportUlCqiInfo(params);
1814
1815 // retrieve the allocation for this subframe
1816 switch (m_ulCqiFilter)
1817 {
1819 // filter all the CQIs that are not SRS based
1820 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1821 {
1822 return;
1823 }
1824 }
1825 break;
1827 // filter all the CQIs that are not SRS based
1828 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1829 {
1830 return;
1831 }
1832 }
1833 break;
1834
1835 default:
1836 NS_FATAL_ERROR("Unknown UL CQI type");
1837 }
1838
1839 switch (params.m_ulCqi.m_type)
1840 {
1841 case UlCqi_s::PUSCH: {
1842 NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1843 << " subframe no. " << (0xF & params.m_sfnSf));
1844 auto itMap = m_allocationMaps.find(params.m_sfnSf);
1845 if (itMap == m_allocationMaps.end())
1846 {
1847 return;
1848 }
1849 for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1850 {
1851 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1852 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1853 auto itCqi = m_ueCqi.find((*itMap).second.at(i));
1854 if (itCqi == m_ueCqi.end())
1855 {
1856 // create a new entry
1857 std::vector<double> newCqi;
1858 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1859 {
1860 if (i == j)
1861 {
1862 newCqi.push_back(sinr);
1863 }
1864 else
1865 {
1866 // initialize with NO_SINR value.
1867 newCqi.push_back(NO_SINR);
1868 }
1869 }
1870 m_ueCqi[(*itMap).second.at(i)] = newCqi;
1871 // generate correspondent timer
1872 m_ueCqiTimers[(*itMap).second.at(i)] = m_cqiTimersThreshold;
1873 }
1874 else
1875 {
1876 // update the value
1877 (*itCqi).second.at(i) = sinr;
1878 NS_LOG_DEBUG(this << " RNTI " << (*itMap).second.at(i) << " RB " << i << " SINR "
1879 << sinr);
1880 // update correspondent timer
1881 auto itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1882 (*itTimers).second = m_cqiTimersThreshold;
1883 }
1884 }
1885 // remove obsolete info on allocation
1886 m_allocationMaps.erase(itMap);
1887 }
1888 break;
1889 case UlCqi_s::SRS: {
1890 NS_LOG_DEBUG(this << " Collect SRS CQIs of Frame no. " << (params.m_sfnSf >> 4)
1891 << " subframe no. " << (0xF & params.m_sfnSf));
1892 // get the RNTI from vendor specific parameters
1893 uint16_t rnti = 0;
1894 NS_ASSERT(!params.m_vendorSpecificList.empty());
1895 for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1896 {
1897 if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1898 {
1899 Ptr<SrsCqiRntiVsp> vsp =
1900 DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1901 rnti = vsp->GetRnti();
1902 }
1903 }
1904 auto itCqi = m_ueCqi.find(rnti);
1905 if (itCqi == m_ueCqi.end())
1906 {
1907 // create a new entry
1908 std::vector<double> newCqi;
1909 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1910 {
1911 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1912 newCqi.push_back(sinr);
1913 NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1914 << sinr);
1915 }
1916 m_ueCqi[rnti] = newCqi;
1917 // generate correspondent timer
1919 }
1920 else
1921 {
1922 // update the values
1923 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1924 {
1925 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1926 (*itCqi).second.at(j) = sinr;
1927 NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1928 << sinr);
1929 }
1930 // update correspondent timer
1931 auto itTimers = m_ueCqiTimers.find(rnti);
1932 (*itTimers).second = m_cqiTimersThreshold;
1933 }
1934 }
1935 break;
1936 case UlCqi_s::PUCCH_1:
1937 case UlCqi_s::PUCCH_2:
1938 case UlCqi_s::PRACH: {
1939 NS_FATAL_ERROR("PfFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1940 }
1941 break;
1942 default:
1943 NS_FATAL_ERROR("Unknown type of UL-CQI");
1944 }
1945}
1946
1947void
1949{
1950 // refresh DL CQI P01 Map
1951 auto itP10 = m_p10CqiTimers.begin();
1952 while (itP10 != m_p10CqiTimers.end())
1953 {
1954 NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1955 << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1956 if ((*itP10).second == 0)
1957 {
1958 // delete correspondent entries
1959 auto itMap = m_p10CqiRxed.find((*itP10).first);
1960 NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1961 " Does not find CQI report for user " << (*itP10).first);
1962 NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1963 m_p10CqiRxed.erase(itMap);
1964 auto temp = itP10;
1965 itP10++;
1966 m_p10CqiTimers.erase(temp);
1967 }
1968 else
1969 {
1970 (*itP10).second--;
1971 itP10++;
1972 }
1973 }
1974
1975 // refresh DL CQI A30 Map
1976 auto itA30 = m_a30CqiTimers.begin();
1977 while (itA30 != m_a30CqiTimers.end())
1978 {
1979 NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1980 << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1981 if ((*itA30).second == 0)
1982 {
1983 // delete correspondent entries
1984 auto itMap = m_a30CqiRxed.find((*itA30).first);
1985 NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1986 " Does not find CQI report for user " << (*itA30).first);
1987 NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1988 m_a30CqiRxed.erase(itMap);
1989 auto temp = itA30;
1990 itA30++;
1991 m_a30CqiTimers.erase(temp);
1992 }
1993 else
1994 {
1995 (*itA30).second--;
1996 itA30++;
1997 }
1998 }
1999}
2000
2001void
2003{
2004 // refresh UL CQI Map
2005 auto itUl = m_ueCqiTimers.begin();
2006 while (itUl != m_ueCqiTimers.end())
2007 {
2008 NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
2009 << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2010 if ((*itUl).second == 0)
2011 {
2012 // delete correspondent entries
2013 auto itMap = m_ueCqi.find((*itUl).first);
2014 NS_ASSERT_MSG(itMap != m_ueCqi.end(),
2015 " Does not find CQI report for user " << (*itUl).first);
2016 NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
2017 (*itMap).second.clear();
2018 m_ueCqi.erase(itMap);
2019 auto temp = itUl;
2020 itUl++;
2021 m_ueCqiTimers.erase(temp);
2022 }
2023 else
2024 {
2025 (*itUl).second--;
2026 itUl++;
2027 }
2028 }
2029}
2030
2031void
2032PfFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
2033{
2034 LteFlowId_t flow(rnti, lcid);
2035 auto it = m_rlcBufferReq.find(flow);
2036 if (it != m_rlcBufferReq.end())
2037 {
2038 NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
2039 << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
2040 << (*it).second.m_rlcRetransmissionQueueSize << " status "
2041 << (*it).second.m_rlcStatusPduSize << " decrease " << size);
2042 // Update queues: RLC tx order Status, ReTx, Tx
2043 // Update status queue
2044 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2045 {
2046 (*it).second.m_rlcStatusPduSize = 0;
2047 }
2048 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
2049 (size >= (*it).second.m_rlcRetransmissionQueueSize))
2050 {
2051 (*it).second.m_rlcRetransmissionQueueSize = 0;
2052 }
2053 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2054 {
2055 uint32_t rlcOverhead;
2056 if (lcid == 1)
2057 {
2058 // for SRB1 (using RLC AM) it's better to
2059 // overestimate RLC overhead rather than
2060 // underestimate it and risk unneeded
2061 // segmentation which increases delay
2062 rlcOverhead = 4;
2063 }
2064 else
2065 {
2066 // minimum RLC overhead due to header
2067 rlcOverhead = 2;
2068 }
2069 // update transmission queue
2070 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2071 {
2072 (*it).second.m_rlcTransmissionQueueSize = 0;
2073 }
2074 else
2075 {
2076 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2077 }
2078 }
2079 }
2080 else
2081 {
2082 NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
2083 }
2084}
2085
2086void
2087PfFfMacScheduler::UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
2088{
2089 size = size - 2; // remove the minimum RLC overhead
2090 auto it = m_ceBsrRxed.find(rnti);
2091 if (it != m_ceBsrRxed.end())
2092 {
2093 NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2094 if ((*it).second >= size)
2095 {
2096 (*it).second -= size;
2097 }
2098 else
2099 {
2100 (*it).second = 0;
2101 }
2102 }
2103 else
2104 {
2105 NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
2106 }
2107}
2108
2109void
2111{
2112 NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2114 params.m_rnti = rnti;
2115 params.m_transmissionMode = txMode;
2116 m_cschedSapUser->CschedUeConfigUpdateInd(params);
2117}
2118
2119} // 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...
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.
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:999
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:246
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:274
#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:267
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: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 (see table 7.1.6.1-1 of 36.213).
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.
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