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