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