A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tta-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("TtaFfMacScheduler");
39
41static const int TtaType0AllocationRbg[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(TtaFfMacScheduler);
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::TtaFfMacScheduler")
86 .SetGroupName("Lte")
87 .AddConstructor<TtaFfMacScheduler>()
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 < TtaType0AllocationRbg[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 itSbCqi = m_a30CqiRxed.find((*it));
887 auto itWbCqi = m_p10CqiRxed.find((*it));
888
889 auto itTxMode = m_uesTxMode.find((*it));
890 if (itTxMode == m_uesTxMode.end())
891 {
892 NS_FATAL_ERROR("No Transmission Mode info on user " << (*it));
893 }
894 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
895
896 std::vector<uint8_t> sbCqi;
897 if (itSbCqi == m_a30CqiRxed.end())
898 {
899 sbCqi = std::vector<uint8_t>(nLayer, 1); // start with lowest value
900 }
901 else
902 {
903 sbCqi = (*itSbCqi).second.m_higherLayerSelected.at(i).m_sbCqi;
904 }
905
906 uint8_t wbCqi = 0;
907 if (itWbCqi != m_p10CqiRxed.end())
908 {
909 wbCqi = (*itWbCqi).second;
910 }
911 else
912 {
913 wbCqi = 1; // lowest value for trying a transmission
914 }
915
916 uint8_t cqi1 = sbCqi.at(0);
917 uint8_t cqi2 = 0;
918 if (sbCqi.size() > 1)
919 {
920 cqi2 = sbCqi.at(1);
921 }
922 if ((cqi1 > 0) ||
923 (cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
924 {
925 if (LcActivePerFlow((*it)) > 0)
926 {
927 // this UE has data to transmit
928 double achievableSbRate = 0.0;
929 double achievableWbRate = 0.0;
930 uint8_t sbMcs = 0;
931 uint8_t wbMcs = 0;
932 for (uint8_t k = 0; k < nLayer; k++)
933 {
934 if (sbCqi.size() > k)
935 {
936 sbMcs = m_amc->GetMcsFromCqi(sbCqi.at(k));
937 }
938 else
939 {
940 // no info on this subband -> worst MCS
941 sbMcs = 0;
942 }
943 achievableSbRate += ((m_amc->GetDlTbSizeFromMcs(sbMcs, rbgSize) / 8) /
944 0.001); // = TB size / TTI
945 wbMcs = m_amc->GetMcsFromCqi(wbCqi);
946 achievableWbRate += ((m_amc->GetDlTbSizeFromMcs(wbMcs, rbgSize) / 8) /
947 0.001); // = TB size / TTI
948 }
949
950 double metric = achievableSbRate / achievableWbRate;
951
952 if (metric > rcqiMax)
953 {
954 rcqiMax = metric;
955 itMax = it;
956 }
957 }
958 } // end if cqi
959
960 } // end for m_rlcBufferReq
961
962 if (itMax == m_flowStatsDl.end())
963 {
964 // no UE available for this RB
965 NS_LOG_INFO(this << " any UE found");
966 }
967 else
968 {
969 rbgMap.at(i) = true;
970 auto itMap = allocationMap.find((*itMax));
971 if (itMap == allocationMap.end())
972 {
973 // insert new element
974 std::vector<uint16_t> tempMap;
975 tempMap.push_back(i);
976 allocationMap.insert(
977 std::pair<uint16_t, std::vector<uint16_t>>((*itMax), tempMap));
978 }
979 else
980 {
981 (*itMap).second.push_back(i);
982 }
983 NS_LOG_INFO(this << " UE assigned " << (*itMax));
984 }
985 } // end for RBG free
986 } // end for RBGs
987
988 // generate the transmission opportunities by grouping the RBGs of the same RNTI and
989 // creating the correspondent DCIs
990 auto itMap = allocationMap.begin();
991 while (itMap != allocationMap.end())
992 {
993 // create new BuildDataListElement_s for this LC
995 newEl.m_rnti = (*itMap).first;
996 // create the DlDciListElement_s
997 DlDciListElement_s newDci;
998 newDci.m_rnti = (*itMap).first;
999 newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
1000
1001 uint16_t lcActives = LcActivePerFlow((*itMap).first);
1002 NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1003 if (lcActives == 0)
1004 {
1005 // Set to max value, to avoid divide by 0 below
1006 lcActives = (uint16_t)65535; // UINT16_MAX;
1007 }
1008 uint16_t RgbPerRnti = (*itMap).second.size();
1009 auto itCqi = m_a30CqiRxed.find((*itMap).first);
1010 auto itTxMode = m_uesTxMode.find((*itMap).first);
1011 if (itTxMode == m_uesTxMode.end())
1012 {
1013 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1014 }
1015 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1016 std::vector<uint8_t> worstCqi(2, 15);
1017 if (itCqi != m_a30CqiRxed.end())
1018 {
1019 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1020 {
1021 if ((*itCqi).second.m_higherLayerSelected.size() > (*itMap).second.at(k))
1022 {
1023 NS_LOG_INFO(this << " RBG " << (*itMap).second.at(k) << " CQI "
1024 << (uint16_t)((*itCqi)
1025 .second.m_higherLayerSelected
1026 .at((*itMap).second.at(k))
1027 .m_sbCqi.at(0)));
1028 for (uint8_t j = 0; j < nLayer; j++)
1029 {
1030 if ((*itCqi)
1031 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1032 .m_sbCqi.size() > j)
1033 {
1034 if (((*itCqi)
1035 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1036 .m_sbCqi.at(j)) < worstCqi.at(j))
1037 {
1038 worstCqi.at(j) =
1039 ((*itCqi)
1040 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1041 .m_sbCqi.at(j));
1042 }
1043 }
1044 else
1045 {
1046 // no CQI for this layer of this suband -> worst one
1047 worstCqi.at(j) = 1;
1048 }
1049 }
1050 }
1051 else
1052 {
1053 for (uint8_t j = 0; j < nLayer; j++)
1054 {
1055 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1056 }
1057 }
1058 }
1059 }
1060 else
1061 {
1062 for (uint8_t j = 0; j < nLayer; j++)
1063 {
1064 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1065 }
1066 }
1067 for (uint8_t j = 0; j < nLayer; j++)
1068 {
1069 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " CQI selected "
1070 << (uint16_t)worstCqi.at(j));
1071 }
1072 for (uint8_t j = 0; j < nLayer; j++)
1073 {
1074 newDci.m_mcs.push_back(m_amc->GetMcsFromCqi(worstCqi.at(j)));
1075 int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RgbPerRnti * rbgSize) /
1076 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1077 newDci.m_tbsSize.push_back(tbSize);
1078 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " MCS selected"
1079 << m_amc->GetMcsFromCqi(worstCqi.at(j)));
1080 }
1081
1082 newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1083 newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1084 uint32_t rbgMask = 0;
1085 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1086 {
1087 rbgMask = rbgMask + (0x1 << (*itMap).second.at(k));
1088 NS_LOG_INFO(this << " Allocated RBG " << (*itMap).second.at(k));
1089 }
1090 newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1091
1092 // create the rlc PDUs -> equally divide resources among actives LCs
1093 for (auto itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1094 {
1095 if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1096 (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1097 ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1098 ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1099 {
1100 std::vector<RlcPduListElement_s> newRlcPduLe;
1101 for (uint8_t j = 0; j < nLayer; j++)
1102 {
1103 RlcPduListElement_s newRlcEl;
1104 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1105 newRlcEl.m_size = newDci.m_tbsSize.at(j) / lcActives;
1106 NS_LOG_INFO(this << " LCID " << (uint32_t)newRlcEl.m_logicalChannelIdentity
1107 << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1108 newRlcPduLe.push_back(newRlcEl);
1110 newRlcEl.m_logicalChannelIdentity,
1111 newRlcEl.m_size);
1112 if (m_harqOn)
1113 {
1114 // store RLC PDU list for HARQ
1115 auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1116 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1117 {
1118 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1119 << (*itMap).first);
1120 }
1121 (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1122 }
1123 }
1124 newEl.m_rlcPduList.push_back(newRlcPduLe);
1125 }
1126 if ((*itBufReq).first.m_rnti > (*itMap).first)
1127 {
1128 break;
1129 }
1130 }
1131 for (uint8_t j = 0; j < nLayer; j++)
1132 {
1133 newDci.m_ndi.push_back(1);
1134 newDci.m_rv.push_back(0);
1135 }
1136
1137 newDci.m_tpc = 1; // 1 is mapped to 0 in Accumulated Mode and to -1 in Absolute Mode
1138
1139 newEl.m_dci = newDci;
1140
1141 if (m_harqOn)
1142 {
1143 // store DCI for HARQ
1144 auto itDci = m_dlHarqProcessesDciBuffer.find(newEl.m_rnti);
1145 if (itDci == m_dlHarqProcessesDciBuffer.end())
1146 {
1147 NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1148 << newEl.m_rnti);
1149 }
1150 (*itDci).second.at(newDci.m_harqProcess) = newDci;
1151 // refresh timer
1152 auto itHarqTimer = m_dlHarqProcessesTimer.find(newEl.m_rnti);
1153 if (itHarqTimer == m_dlHarqProcessesTimer.end())
1154 {
1155 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1156 }
1157 (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1158 }
1159
1160 // ...more parameters -> ignored in this version
1161
1162 ret.m_buildDataList.push_back(newEl);
1163
1164 itMap++;
1165 } // end while allocation
1166 ret.m_nrOfPdcchOfdmSymbols = 1;
1167
1169}
1170
1171void
1174{
1175 NS_LOG_FUNCTION(this);
1176
1177 m_rachList = params.m_rachList;
1178}
1179
1180void
1183{
1184 NS_LOG_FUNCTION(this);
1185
1186 for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1187 {
1188 if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1189 {
1190 NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1191 << " reported");
1192 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1193 auto it = m_p10CqiRxed.find(rnti);
1194 if (it == m_p10CqiRxed.end())
1195 {
1196 // create the new entry
1197 m_p10CqiRxed.insert(std::pair<uint16_t, uint8_t>(
1198 rnti,
1199 params.m_cqiList.at(i).m_wbCqi.at(0))); // only codeword 0 at this stage (SISO)
1200 // generate correspondent timer
1201 m_p10CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1202 }
1203 else
1204 {
1205 // update the CQI value and refresh correspondent timer
1206 (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1207 // update correspondent timer
1208 auto itTimers = m_p10CqiTimers.find(rnti);
1209 (*itTimers).second = m_cqiTimersThreshold;
1210 }
1211 }
1212 else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1213 {
1214 // subband CQI reporting high layer configured
1215 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1216 auto it = m_a30CqiRxed.find(rnti);
1217 if (it == m_a30CqiRxed.end())
1218 {
1219 // create the new entry
1220 m_a30CqiRxed.insert(
1221 std::pair<uint16_t, SbMeasResult_s>(rnti,
1222 params.m_cqiList.at(i).m_sbMeasResult));
1223 m_a30CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1224 }
1225 else
1226 {
1227 // update the CQI value and refresh correspondent timer
1228 (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1229 auto itTimers = m_a30CqiTimers.find(rnti);
1230 (*itTimers).second = m_cqiTimersThreshold;
1231 }
1232 }
1233 else
1234 {
1235 NS_LOG_ERROR(this << " CQI type unknown");
1236 }
1237 }
1238}
1239
1240double
1241TtaFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1242{
1243 auto itCqi = m_ueCqi.find(rnti);
1244 if (itCqi == m_ueCqi.end())
1245 {
1246 // no cqi info about this UE
1247 return (NO_SINR);
1248 }
1249 else
1250 {
1251 // take the average SINR value among the available
1252 double sinrSum = 0;
1253 unsigned int sinrNum = 0;
1254 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1255 {
1256 double sinr = (*itCqi).second.at(i);
1257 if (sinr != NO_SINR)
1258 {
1259 sinrSum += sinr;
1260 sinrNum++;
1261 }
1262 }
1263 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1264 // store the value
1265 (*itCqi).second.at(rb) = estimatedSinr;
1266 return (estimatedSinr);
1267 }
1268}
1269
1270void
1273{
1274 NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1275 << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1276
1278
1279 // Generate RBs map
1281 std::vector<bool> rbMap;
1282 std::set<uint16_t> rntiAllocated;
1283 std::vector<uint16_t> rbgAllocationMap;
1284 // update with RACH allocation map
1285 rbgAllocationMap = m_rachAllocationMap;
1286 // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1287 m_rachAllocationMap.clear();
1289
1290 rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1291 // remove RACH allocation
1292 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1293 {
1294 if (rbgAllocationMap.at(i) != 0)
1295 {
1296 rbMap.at(i) = true;
1297 NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1298 }
1299 }
1300
1301 if (m_harqOn)
1302 {
1303 // Process UL HARQ feedback
1304 for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1305 {
1306 if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1307 {
1308 // retx correspondent block: retrieve the UL-DCI
1309 uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1310 auto itProcId = m_ulHarqCurrentProcessId.find(rnti);
1311 if (itProcId == m_ulHarqCurrentProcessId.end())
1312 {
1313 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1314 }
1315 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1316 NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1317 << " i " << i << " size " << params.m_ulInfoList.size());
1318 auto itHarq = m_ulHarqProcessesDciBuffer.find(rnti);
1319 if (itHarq == m_ulHarqProcessesDciBuffer.end())
1320 {
1321 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1322 continue;
1323 }
1324 UlDciListElement_s dci = (*itHarq).second.at(harqId);
1325 auto itStat = m_ulHarqProcessesStatus.find(rnti);
1326 if (itStat == m_ulHarqProcessesStatus.end())
1327 {
1328 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1329 }
1330 if ((*itStat).second.at(harqId) >= 3)
1331 {
1332 NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1333 continue;
1334 }
1335 bool free = true;
1336 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1337 {
1338 if (rbMap.at(j))
1339 {
1340 free = false;
1341 NS_LOG_INFO(this << " BUSY " << j);
1342 }
1343 }
1344 if (free)
1345 {
1346 // retx on the same RBs
1347 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1348 {
1349 rbMap.at(j) = true;
1350 rbgAllocationMap.at(j) = dci.m_rnti;
1351 NS_LOG_INFO("\tRB " << j);
1352 }
1353 NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1354 << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1355 << (*itStat).second.at(harqId) + 1);
1356 }
1357 else
1358 {
1359 NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1360 continue;
1361 }
1362 dci.m_ndi = 0;
1363 // Update HARQ buffers with new HarqId
1364 (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1365 (*itStat).second.at(harqId) = 0;
1366 (*itHarq).second.at((*itProcId).second) = dci;
1367 ret.m_dciList.push_back(dci);
1368 rntiAllocated.insert(dci.m_rnti);
1369 }
1370 else
1371 {
1372 NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1373 << params.m_ulInfoList.at(i).m_rnti);
1374 }
1375 }
1376 }
1377
1378 std::map<uint16_t, uint32_t>::iterator it;
1379 int nflows = 0;
1380
1381 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1382 {
1383 auto itRnti = rntiAllocated.find((*it).first);
1384 // select UEs with queues not empty and not yet allocated for HARQ
1385 if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1386 {
1387 nflows++;
1388 }
1389 }
1390
1391 if (nflows == 0)
1392 {
1393 if (!ret.m_dciList.empty())
1394 {
1395 m_allocationMaps.insert(
1396 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1398 }
1399
1400 return; // no flows to be scheduled
1401 }
1402
1403 // Divide the remaining resources equally among the active users starting from the subsequent
1404 // one served last scheduling trigger
1405 uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size());
1406 if (rbPerFlow < 3)
1407 {
1408 rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1409 // >= 7 bytes
1410 }
1411 int rbAllocated = 0;
1412
1413 if (m_nextRntiUl != 0)
1414 {
1415 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1416 {
1417 if ((*it).first == m_nextRntiUl)
1418 {
1419 break;
1420 }
1421 }
1422 if (it == m_ceBsrRxed.end())
1423 {
1424 NS_LOG_ERROR(this << " no user found");
1425 }
1426 }
1427 else
1428 {
1429 it = m_ceBsrRxed.begin();
1430 m_nextRntiUl = (*it).first;
1431 }
1432 do
1433 {
1434 auto itRnti = rntiAllocated.find((*it).first);
1435 if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1436 {
1437 // UE already allocated for UL-HARQ -> skip it
1438 NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1439 << (*it).first);
1440 it++;
1441 if (it == m_ceBsrRxed.end())
1442 {
1443 // restart from the first
1444 it = m_ceBsrRxed.begin();
1445 }
1446 continue;
1447 }
1448 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1449 {
1450 // limit to physical resources last resource assignment
1451 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1452 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1453 if (rbPerFlow < 3)
1454 {
1455 // terminate allocation
1456 rbPerFlow = 0;
1457 }
1458 }
1459
1460 UlDciListElement_s uldci;
1461 uldci.m_rnti = (*it).first;
1462 uldci.m_rbLen = rbPerFlow;
1463 bool allocated = false;
1464 NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1465 << " flows " << nflows);
1466 while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1467 (rbPerFlow != 0))
1468 {
1469 // check availability
1470 bool free = true;
1471 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1472 {
1473 if (rbMap.at(j))
1474 {
1475 free = false;
1476 break;
1477 }
1478 }
1479 if (free)
1480 {
1481 uldci.m_rbStart = rbAllocated;
1482
1483 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1484 {
1485 rbMap.at(j) = true;
1486 // store info on allocation for managing ul-cqi interpretation
1487 rbgAllocationMap.at(j) = (*it).first;
1488 }
1489 rbAllocated += rbPerFlow;
1490 allocated = true;
1491 break;
1492 }
1493 rbAllocated++;
1494 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1495 {
1496 // limit to physical resources last resource assignment
1497 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1498 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1499 if (rbPerFlow < 3)
1500 {
1501 // terminate allocation
1502 rbPerFlow = 0;
1503 }
1504 }
1505 }
1506 if (!allocated)
1507 {
1508 // unable to allocate new resource: finish scheduling
1509 m_nextRntiUl = (*it).first;
1510 if (!ret.m_dciList.empty())
1511 {
1513 }
1514 m_allocationMaps.insert(
1515 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1516 return;
1517 }
1518
1519 auto itCqi = m_ueCqi.find((*it).first);
1520 int cqi = 0;
1521 if (itCqi == m_ueCqi.end())
1522 {
1523 // no cqi info about this UE
1524 uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1525 }
1526 else
1527 {
1528 // take the lowest CQI value (worst RB)
1529 NS_ABORT_MSG_IF((*itCqi).second.empty(),
1530 "CQI of RNTI = " << (*it).first << " has expired");
1531 double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1532 if (minSinr == NO_SINR)
1533 {
1534 minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1535 }
1536 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1537 {
1538 double sinr = (*itCqi).second.at(i);
1539 if (sinr == NO_SINR)
1540 {
1541 sinr = EstimateUlSinr((*it).first, i);
1542 }
1543 if (sinr < minSinr)
1544 {
1545 minSinr = sinr;
1546 }
1547 }
1548
1549 // translate SINR -> cqi: WILD ACK: same as DL
1550 double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1551 cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1552 if (cqi == 0)
1553 {
1554 it++;
1555 if (it == m_ceBsrRxed.end())
1556 {
1557 // restart from the first
1558 it = m_ceBsrRxed.begin();
1559 }
1560 NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1561 // remove UE from allocation map
1562 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1563 {
1564 rbgAllocationMap.at(i) = 0;
1565 }
1566 continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1567 }
1568 uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1569 }
1570
1571 uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1573 uldci.m_ndi = 1;
1574 uldci.m_cceIndex = 0;
1575 uldci.m_aggrLevel = 1;
1576 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1577 uldci.m_hopping = false;
1578 uldci.m_n2Dmrs = 0;
1579 uldci.m_tpc = 0; // no power control
1580 uldci.m_cqiRequest = false; // only period CQI at this stage
1581 uldci.m_ulIndex = 0; // TDD parameter
1582 uldci.m_dai = 1; // TDD parameter
1583 uldci.m_freqHopping = 0;
1584 uldci.m_pdcchPowerOffset = 0; // not used
1585 ret.m_dciList.push_back(uldci);
1586 // store DCI for HARQ_PERIOD
1587 uint8_t harqId = 0;
1588 if (m_harqOn)
1589 {
1590 auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1591 if (itProcId == m_ulHarqCurrentProcessId.end())
1592 {
1593 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1594 }
1595 harqId = (*itProcId).second;
1596 auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
1597 if (itDci == m_ulHarqProcessesDciBuffer.end())
1598 {
1599 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1600 << uldci.m_rnti);
1601 }
1602 (*itDci).second.at(harqId) = uldci;
1603 // Update HARQ process status (RV 0)
1604 auto itStat = m_ulHarqProcessesStatus.find(uldci.m_rnti);
1605 if (itStat == m_ulHarqProcessesStatus.end())
1606 {
1607 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1608 << uldci.m_rnti);
1609 }
1610 (*itStat).second.at(harqId) = 0;
1611 }
1612
1613 NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1614 << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1615 << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1616 << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1617 << (uint16_t)harqId);
1618
1619 it++;
1620 if (it == m_ceBsrRxed.end())
1621 {
1622 // restart from the first
1623 it = m_ceBsrRxed.begin();
1624 }
1625 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1626 {
1627 // Stop allocation: no more PRBs
1628 m_nextRntiUl = (*it).first;
1629 break;
1630 }
1631 } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1632
1633 m_allocationMaps.insert(
1634 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1636}
1637
1638void
1641{
1642 NS_LOG_FUNCTION(this);
1643}
1644
1645void
1648{
1649 NS_LOG_FUNCTION(this);
1650}
1651
1652void
1655{
1656 NS_LOG_FUNCTION(this);
1657
1658 for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1659 {
1660 if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1661 {
1662 // buffer status report
1663 // note that this scheduler does not differentiate the
1664 // allocation according to which LCGs have more/less bytes
1665 // to send.
1666 // Hence the BSR of different LCGs are just summed up to get
1667 // a total queue size that is used for allocation purposes.
1668
1669 uint32_t buffer = 0;
1670 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1671 {
1672 uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1673 buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1674 }
1675
1676 uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1677 NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1678 auto it = m_ceBsrRxed.find(rnti);
1679 if (it == m_ceBsrRxed.end())
1680 {
1681 // create the new entry
1682 m_ceBsrRxed.insert(std::pair<uint16_t, uint32_t>(rnti, buffer));
1683 }
1684 else
1685 {
1686 // update the buffer size value
1687 (*it).second = buffer;
1688 }
1689 }
1690 }
1691}
1692
1693void
1696{
1697 NS_LOG_FUNCTION(this);
1698 // retrieve the allocation for this subframe
1699 switch (m_ulCqiFilter)
1700 {
1702 // filter all the CQIs that are not SRS based
1703 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1704 {
1705 return;
1706 }
1707 }
1708 break;
1710 // filter all the CQIs that are not SRS based
1711 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1712 {
1713 return;
1714 }
1715 }
1716 break;
1717 default:
1718 NS_FATAL_ERROR("Unknown UL CQI type");
1719 }
1720
1721 switch (params.m_ulCqi.m_type)
1722 {
1723 case UlCqi_s::PUSCH: {
1724 NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1725 << " subframe no. " << (0xF & params.m_sfnSf));
1726 auto itMap = m_allocationMaps.find(params.m_sfnSf);
1727 if (itMap == m_allocationMaps.end())
1728 {
1729 return;
1730 }
1731 for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1732 {
1733 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1734 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1735 auto itCqi = m_ueCqi.find((*itMap).second.at(i));
1736 if (itCqi == m_ueCqi.end())
1737 {
1738 // create a new entry
1739 std::vector<double> newCqi;
1740 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1741 {
1742 if (i == j)
1743 {
1744 newCqi.push_back(sinr);
1745 }
1746 else
1747 {
1748 // initialize with NO_SINR value.
1749 newCqi.push_back(NO_SINR);
1750 }
1751 }
1752 m_ueCqi.insert(
1753 std::pair<uint16_t, std::vector<double>>((*itMap).second.at(i), newCqi));
1754 // generate correspondent timer
1755 m_ueCqiTimers.insert(
1756 std::pair<uint16_t, uint32_t>((*itMap).second.at(i), m_cqiTimersThreshold));
1757 }
1758 else
1759 {
1760 // update the value
1761 (*itCqi).second.at(i) = sinr;
1762 // NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR
1763 // " << sinr);
1764 // update correspondent timer
1765 auto itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1766 (*itTimers).second = m_cqiTimersThreshold;
1767 }
1768 }
1769 // remove obsolete info on allocation
1770 m_allocationMaps.erase(itMap);
1771 }
1772 break;
1773 case UlCqi_s::SRS: {
1774 // get the RNTI from vendor specific parameters
1775 uint16_t rnti = 0;
1776 NS_ASSERT(!params.m_vendorSpecificList.empty());
1777 for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1778 {
1779 if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1780 {
1781 Ptr<SrsCqiRntiVsp> vsp =
1782 DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1783 rnti = vsp->GetRnti();
1784 }
1785 }
1786 auto itCqi = m_ueCqi.find(rnti);
1787 if (itCqi == m_ueCqi.end())
1788 {
1789 // create a new entry
1790 std::vector<double> newCqi;
1791 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1792 {
1793 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1794 newCqi.push_back(sinr);
1795 NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1796 << sinr);
1797 }
1798 m_ueCqi.insert(std::pair<uint16_t, std::vector<double>>(rnti, newCqi));
1799 // generate correspondent timer
1800 m_ueCqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1801 }
1802 else
1803 {
1804 // update the values
1805 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1806 {
1807 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1808 (*itCqi).second.at(j) = sinr;
1809 NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1810 << sinr);
1811 }
1812 // update correspondent timer
1813 auto itTimers = m_ueCqiTimers.find(rnti);
1814 (*itTimers).second = m_cqiTimersThreshold;
1815 }
1816 }
1817 break;
1818 case UlCqi_s::PUCCH_1:
1819 case UlCqi_s::PUCCH_2:
1820 case UlCqi_s::PRACH: {
1821 NS_FATAL_ERROR("TtaFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1822 }
1823 break;
1824 default:
1825 NS_FATAL_ERROR("Unknown type of UL-CQI");
1826 }
1827}
1828
1829void
1831{
1832 // refresh DL CQI P01 Map
1833 auto itP10 = m_p10CqiTimers.begin();
1834 while (itP10 != m_p10CqiTimers.end())
1835 {
1836 NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1837 << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1838 if ((*itP10).second == 0)
1839 {
1840 // delete correspondent entries
1841 auto itMap = m_p10CqiRxed.find((*itP10).first);
1842 NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1843 " Does not find CQI report for user " << (*itP10).first);
1844 NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1845 m_p10CqiRxed.erase(itMap);
1846 auto temp = itP10;
1847 itP10++;
1848 m_p10CqiTimers.erase(temp);
1849 }
1850 else
1851 {
1852 (*itP10).second--;
1853 itP10++;
1854 }
1855 }
1856
1857 // refresh DL CQI A30 Map
1858 auto itA30 = m_a30CqiTimers.begin();
1859 while (itA30 != m_a30CqiTimers.end())
1860 {
1861 NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1862 << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1863 if ((*itA30).second == 0)
1864 {
1865 // delete correspondent entries
1866 auto itMap = m_a30CqiRxed.find((*itA30).first);
1867 NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1868 " Does not find CQI report for user " << (*itA30).first);
1869 NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1870 m_a30CqiRxed.erase(itMap);
1871 auto temp = itA30;
1872 itA30++;
1873 m_a30CqiTimers.erase(temp);
1874 }
1875 else
1876 {
1877 (*itA30).second--;
1878 itA30++;
1879 }
1880 }
1881}
1882
1883void
1885{
1886 // refresh UL CQI Map
1887 auto itUl = m_ueCqiTimers.begin();
1888 while (itUl != m_ueCqiTimers.end())
1889 {
1890 NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
1891 << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1892 if ((*itUl).second == 0)
1893 {
1894 // delete correspondent entries
1895 auto itMap = m_ueCqi.find((*itUl).first);
1896 NS_ASSERT_MSG(itMap != m_ueCqi.end(),
1897 " Does not find CQI report for user " << (*itUl).first);
1898 NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
1899 (*itMap).second.clear();
1900 m_ueCqi.erase(itMap);
1901 auto temp = itUl;
1902 itUl++;
1903 m_ueCqiTimers.erase(temp);
1904 }
1905 else
1906 {
1907 (*itUl).second--;
1908 itUl++;
1909 }
1910 }
1911}
1912
1913void
1914TtaFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
1915{
1916 LteFlowId_t flow(rnti, lcid);
1917 auto it = m_rlcBufferReq.find(flow);
1918 if (it != m_rlcBufferReq.end())
1919 {
1920 NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
1921 << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
1922 << (*it).second.m_rlcRetransmissionQueueSize << " status "
1923 << (*it).second.m_rlcStatusPduSize << " decrease " << size);
1924 // Update queues: RLC tx order Status, ReTx, Tx
1925 // Update status queue
1926 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1927 {
1928 (*it).second.m_rlcStatusPduSize = 0;
1929 }
1930 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
1931 (size >= (*it).second.m_rlcRetransmissionQueueSize))
1932 {
1933 (*it).second.m_rlcRetransmissionQueueSize = 0;
1934 }
1935 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1936 {
1937 uint32_t rlcOverhead;
1938 if (lcid == 1)
1939 {
1940 // for SRB1 (using RLC AM) it's better to
1941 // overestimate RLC overhead rather than
1942 // underestimate it and risk unneeded
1943 // segmentation which increases delay
1944 rlcOverhead = 4;
1945 }
1946 else
1947 {
1948 // minimum RLC overhead due to header
1949 rlcOverhead = 2;
1950 }
1951 // update transmission queue
1952 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
1953 {
1954 (*it).second.m_rlcTransmissionQueueSize = 0;
1955 }
1956 else
1957 {
1958 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
1959 }
1960 }
1961 }
1962 else
1963 {
1964 NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
1965 }
1966}
1967
1968void
1969TtaFfMacScheduler::UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
1970{
1971 size = size - 2; // remove the minimum RLC overhead
1972 auto it = m_ceBsrRxed.find(rnti);
1973 if (it != m_ceBsrRxed.end())
1974 {
1975 NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
1976 if ((*it).second >= size)
1977 {
1978 (*it).second -= size;
1979 }
1980 else
1981 {
1982 (*it).second = 0;
1983 }
1984 }
1985 else
1986 {
1987 NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
1988 }
1989}
1990
1991void
1993{
1994 NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
1996 params.m_rnti = rnti;
1997 params.m_transmissionMode = txMode;
1999}
2000
2001} // 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
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
Implements the SCHED SAP and CSCHED SAP for a Throughput to Average scheduler.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
FfMacSchedSapUser * m_schedSapUser
Sched SAP user.
void DoSchedDlCqiInfoReq(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request function.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void DoSchedUlCqiInfoReq(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request function.
void SetLteFfrSapProvider(LteFfrSapProvider *s) override
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
std::set< uint16_t > m_flowStatsDl
Set of UE statistics (per RNTI basis) in downlink.
void DoSchedDlRachInfoReq(const FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request function.
void DoDispose() override
Destructor implementation.
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
void DoSchedDlPagingBufferReq(const FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request function.
int GetRbgSize(int dlbandwidth)
Get RBG size function.
void SetFfMacCschedSapUser(FfMacCschedSapUser *s) override
set the user part of the FfMacCschedSap that this Scheduler will interact with.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
void RefreshDlCqiMaps()
Refresh DL CQI maps.
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 SINR function.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
friend class MemberSchedSapProvider< TtaFfMacScheduler >
allow MemberSchedSapProvider<TtaFfMacScheduler> class friend access
void RefreshUlCqiMaps()
Refresh UL CQI maps.
static TypeId GetTypeId()
Get the type ID.
~TtaFfMacScheduler() override
Destructor.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
void DoCschedLcReleaseReq(const FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release 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)
void SetFfMacSchedSapUser(FfMacSchedSapUser *s) override
set the user part of the FfMacSchedSap that this Scheduler will interact with.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
void DoSchedUlMacCtrlInfoReq(const FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request function.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
void DoSchedUlTriggerReq(const FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request function.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
LteFfrSapUser * GetLteFfrSapUser() override
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
void DoSchedDlTriggerReq(const FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request function.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
void DoSchedUlSrInfoReq(const FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request function.
void DoCschedLcConfigReq(const FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request function.
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update.
void DoSchedDlMacBufferReq(const FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request function.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update DL RLC buffer info function.
void DoSchedUlNoiseInterferenceReq(const FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request function.
void DoCschedCellConfigReq(const FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request function.
bool HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
unsigned int LcActivePerFlow(uint16_t rnti)
LC active per flow function.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
void DoSchedDlRlcBufferReq(const FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request function.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
void DoCschedUeReleaseReq(const FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request function.
friend class MemberCschedSapProvider< TtaFfMacScheduler >
allow MemberCschedSapProvider<TtaFfMacScheduler> class friend access
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
std::set< uint16_t > m_flowStatsUl
Set of UE statistics (per RNTI basis)
std::vector< RachListElement_s > m_rachList
RACH list.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
void DoCschedUeConfigReq(const FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request function.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
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.
constexpr uint32_t HARQ_PROC_NUM
Number of HARQ processes.
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector.
static const int TtaType0AllocationRbg[4]
TTA type 0 allocation RBG.
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.