A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
fdtbfq-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/integer.h>
28#include <ns3/log.h>
29#include <ns3/math.h>
30#include <ns3/pointer.h>
31#include <ns3/simulator.h>
32
33#include <cfloat>
34#include <set>
35
36namespace ns3
37{
38
39NS_LOG_COMPONENT_DEFINE("FdTbfqFfMacScheduler");
40
42static const int FdTbfqType0AllocationRbg[4] = {
43 10, // RGB size 1
44 26, // RGB size 2
45 63, // RGB size 3
46 110, // RGB size 4
47}; // see table 7.1.6.1-1 of 36.213
48
49NS_OBJECT_ENSURE_REGISTERED(FdTbfqFfMacScheduler);
50
52 : m_cschedSapUser(nullptr),
53 m_schedSapUser(nullptr),
54 m_nextRntiUl(0),
55 bankSize(0)
56{
57 m_amc = CreateObject<LteAmc>();
60 m_ffrSapProvider = nullptr;
62}
63
65{
66 NS_LOG_FUNCTION(this);
67}
68
69void
71{
72 NS_LOG_FUNCTION(this);
81 delete m_schedSapProvider;
82 delete m_ffrSapUser;
83}
84
87{
88 static TypeId tid =
89 TypeId("ns3::FdTbfqFfMacScheduler")
91 .SetGroupName("Lte")
92 .AddConstructor<FdTbfqFfMacScheduler>()
93 .AddAttribute("CqiTimerThreshold",
94 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
95 UintegerValue(1000),
97 MakeUintegerChecker<uint32_t>())
98 .AddAttribute("DebtLimit",
99 "Flow debt limit (default -625000 bytes)",
100 IntegerValue(-625000),
102 MakeIntegerChecker<int>())
103 .AddAttribute("CreditLimit",
104 "Flow credit limit (default 625000 bytes)",
105 UintegerValue(625000),
107 MakeUintegerChecker<uint32_t>())
108 .AddAttribute("TokenPoolSize",
109 "The maximum value of flow token pool (default 1 bytes)",
110 UintegerValue(1),
112 MakeUintegerChecker<uint32_t>())
113 .AddAttribute("CreditableThreshold",
114 "Threshold of flow credit (default 0 bytes)",
115 UintegerValue(0),
117 MakeUintegerChecker<uint32_t>())
118
119 .AddAttribute("HarqEnabled",
120 "Activate/Deactivate the HARQ [by default is active].",
121 BooleanValue(true),
124 .AddAttribute("UlGrantMcs",
125 "The MCS of the UL grant, must be [0..15] (default 0)",
126 UintegerValue(0),
128 MakeUintegerChecker<uint8_t>());
129 return tid;
130}
131
132void
134{
135 m_cschedSapUser = s;
136}
137
138void
140{
141 m_schedSapUser = s;
142}
143
146{
147 return m_cschedSapProvider;
148}
149
152{
153 return m_schedSapProvider;
154}
155
156void
158{
160}
161
164{
165 return m_ffrSapUser;
166}
167
168void
171{
172 NS_LOG_FUNCTION(this);
173 // Read the subset of parameters used
174 m_cschedCellConfig = params;
177 cnf.m_result = SUCCESS;
179}
180
181void
184{
185 NS_LOG_FUNCTION(this << " RNTI " << params.m_rnti << " txMode "
186 << (uint16_t)params.m_transmissionMode);
187 std::map<uint16_t, uint8_t>::iterator it = m_uesTxMode.find(params.m_rnti);
188 if (it == m_uesTxMode.end())
189 {
190 m_uesTxMode.insert(std::pair<uint16_t, double>(params.m_rnti, params.m_transmissionMode));
191 // generate HARQ buffers
192 m_dlHarqCurrentProcessId.insert(std::pair<uint16_t, uint8_t>(params.m_rnti, 0));
193 DlHarqProcessesStatus_t dlHarqPrcStatus;
194 dlHarqPrcStatus.resize(8, 0);
196 std::pair<uint16_t, DlHarqProcessesStatus_t>(params.m_rnti, dlHarqPrcStatus));
197 DlHarqProcessesTimer_t dlHarqProcessesTimer;
198 dlHarqProcessesTimer.resize(8, 0);
200 std::pair<uint16_t, DlHarqProcessesTimer_t>(params.m_rnti, dlHarqProcessesTimer));
202 dlHarqdci.resize(8);
204 std::pair<uint16_t, DlHarqProcessesDciBuffer_t>(params.m_rnti, dlHarqdci));
205 DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
206 dlHarqRlcPdu.resize(2);
207 dlHarqRlcPdu.at(0).resize(8);
208 dlHarqRlcPdu.at(1).resize(8);
210 std::pair<uint16_t, DlHarqRlcPduListBuffer_t>(params.m_rnti, dlHarqRlcPdu));
211 m_ulHarqCurrentProcessId.insert(std::pair<uint16_t, uint8_t>(params.m_rnti, 0));
212 UlHarqProcessesStatus_t ulHarqPrcStatus;
213 ulHarqPrcStatus.resize(8, 0);
215 std::pair<uint16_t, UlHarqProcessesStatus_t>(params.m_rnti, ulHarqPrcStatus));
217 ulHarqdci.resize(8);
219 std::pair<uint16_t, UlHarqProcessesDciBuffer_t>(params.m_rnti, ulHarqdci));
220 }
221 else
222 {
223 (*it).second = params.m_transmissionMode;
224 }
225}
226
227void
230{
231 NS_LOG_FUNCTION(this << " New LC, rnti: " << params.m_rnti);
232
233 std::map<uint16_t, fdtbfqsFlowPerf_t>::iterator it;
234 for (std::size_t i = 0; i < params.m_logicalChannelConfigList.size(); i++)
235 {
236 it = m_flowStatsDl.find(params.m_rnti);
237
238 if (it == m_flowStatsDl.end())
239 {
240 uint64_t mbrDlInBytes =
241 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateDl / 8; // byte/s
242 uint64_t mbrUlInBytes =
243 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateUl / 8; // byte/s
244 NS_LOG_DEBUG("mbrDlInBytes: " << mbrDlInBytes << " mbrUlInBytes: " << mbrUlInBytes);
245
246 fdtbfqsFlowPerf_t flowStatsDl;
247 flowStatsDl.flowStart = Simulator::Now();
248 flowStatsDl.packetArrivalRate = 0;
249 flowStatsDl.tokenGenerationRate = mbrDlInBytes;
250 flowStatsDl.tokenPoolSize = 0;
251 flowStatsDl.maxTokenPoolSize = m_tokenPoolSize;
252 flowStatsDl.counter = 0;
253 flowStatsDl.burstCredit = m_creditLimit; // bytes
254 flowStatsDl.debtLimit = m_debtLimit; // bytes
256 m_flowStatsDl.insert(
257 std::pair<uint16_t, fdtbfqsFlowPerf_t>(params.m_rnti, flowStatsDl));
258 fdtbfqsFlowPerf_t flowStatsUl;
259 flowStatsUl.flowStart = Simulator::Now();
260 flowStatsUl.packetArrivalRate = 0;
261 flowStatsUl.tokenGenerationRate = mbrUlInBytes;
262 flowStatsUl.tokenPoolSize = 0;
263 flowStatsUl.maxTokenPoolSize = m_tokenPoolSize;
264 flowStatsUl.counter = 0;
265 flowStatsUl.burstCredit = m_creditLimit; // bytes
266 flowStatsUl.debtLimit = m_debtLimit; // bytes
268 m_flowStatsUl.insert(
269 std::pair<uint16_t, fdtbfqsFlowPerf_t>(params.m_rnti, flowStatsUl));
270 }
271 else
272 {
273 // update MBR and GBR from UeManager::SetupDataRadioBearer ()
274 uint64_t mbrDlInBytes =
275 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateDl / 8; // byte/s
276 uint64_t mbrUlInBytes =
277 params.m_logicalChannelConfigList.at(i).m_eRabMaximulBitrateUl / 8; // byte/s
278 NS_LOG_DEBUG("mbrDlInBytes: " << mbrDlInBytes << " mbrUlInBytes: " << mbrUlInBytes);
279 m_flowStatsDl[(*it).first].tokenGenerationRate = mbrDlInBytes;
280 m_flowStatsUl[(*it).first].tokenGenerationRate = mbrUlInBytes;
281 }
282 }
283}
284
285void
288{
289 NS_LOG_FUNCTION(this);
290 for (std::size_t i = 0; i < params.m_logicalChannelIdentity.size(); i++)
291 {
292 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
293 m_rlcBufferReq.begin();
294 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
295 while (it != m_rlcBufferReq.end())
296 {
297 if (((*it).first.m_rnti == params.m_rnti) &&
298 ((*it).first.m_lcId == params.m_logicalChannelIdentity.at(i)))
299 {
300 temp = it;
301 it++;
302 m_rlcBufferReq.erase(temp);
303 }
304 else
305 {
306 it++;
307 }
308 }
309 }
310}
311
312void
315{
316 NS_LOG_FUNCTION(this);
317
318 m_uesTxMode.erase(params.m_rnti);
319 m_dlHarqCurrentProcessId.erase(params.m_rnti);
320 m_dlHarqProcessesStatus.erase(params.m_rnti);
321 m_dlHarqProcessesTimer.erase(params.m_rnti);
322 m_dlHarqProcessesDciBuffer.erase(params.m_rnti);
323 m_dlHarqProcessesRlcPduListBuffer.erase(params.m_rnti);
324 m_ulHarqCurrentProcessId.erase(params.m_rnti);
325 m_ulHarqProcessesStatus.erase(params.m_rnti);
326 m_ulHarqProcessesDciBuffer.erase(params.m_rnti);
327 m_flowStatsDl.erase(params.m_rnti);
328 m_flowStatsUl.erase(params.m_rnti);
329 m_ceBsrRxed.erase(params.m_rnti);
330 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
331 m_rlcBufferReq.begin();
332 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
333 while (it != m_rlcBufferReq.end())
334 {
335 if ((*it).first.m_rnti == params.m_rnti)
336 {
337 temp = it;
338 it++;
339 m_rlcBufferReq.erase(temp);
340 }
341 else
342 {
343 it++;
344 }
345 }
346 if (m_nextRntiUl == params.m_rnti)
347 {
348 m_nextRntiUl = 0;
349 }
350}
351
352void
355{
356 NS_LOG_FUNCTION(this << params.m_rnti << (uint32_t)params.m_logicalChannelIdentity);
357 // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
358
359 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
360
361 LteFlowId_t flow(params.m_rnti, params.m_logicalChannelIdentity);
362
363 it = m_rlcBufferReq.find(flow);
364
365 if (it == m_rlcBufferReq.end())
366 {
367 m_rlcBufferReq.insert(
368 std::pair<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>(flow,
369 params));
370 }
371 else
372 {
373 (*it).second = params;
374 }
375}
376
377void
380{
381 NS_LOG_FUNCTION(this);
382 NS_FATAL_ERROR("method not implemented");
383}
384
385void
388{
389 NS_LOG_FUNCTION(this);
390 NS_FATAL_ERROR("method not implemented");
391}
392
393int
395{
396 for (int i = 0; i < 4; i++)
397 {
398 if (dlbandwidth < FdTbfqType0AllocationRbg[i])
399 {
400 return (i + 1);
401 }
402 }
403
404 return (-1);
405}
406
407unsigned int
409{
410 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
411 unsigned int lcActive = 0;
412 for (it = m_rlcBufferReq.begin(); it != m_rlcBufferReq.end(); it++)
413 {
414 if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0) ||
415 ((*it).second.m_rlcRetransmissionQueueSize > 0) ||
416 ((*it).second.m_rlcStatusPduSize > 0)))
417 {
418 lcActive++;
419 }
420 if ((*it).first.m_rnti > rnti)
421 {
422 break;
423 }
424 }
425 return (lcActive);
426}
427
428bool
430{
431 NS_LOG_FUNCTION(this << rnti);
432
433 std::map<uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find(rnti);
434 if (it == m_dlHarqCurrentProcessId.end())
435 {
436 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
437 }
438 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
439 m_dlHarqProcessesStatus.find(rnti);
440 if (itStat == m_dlHarqProcessesStatus.end())
441 {
442 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
443 }
444 uint8_t i = (*it).second;
445 do
446 {
447 i = (i + 1) % HARQ_PROC_NUM;
448 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
449
450 return (*itStat).second.at(i) == 0;
451}
452
453uint8_t
455{
456 NS_LOG_FUNCTION(this << rnti);
457
458 if (!m_harqOn)
459 {
460 return (0);
461 }
462
463 std::map<uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find(rnti);
464 if (it == m_dlHarqCurrentProcessId.end())
465 {
466 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
467 }
468 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
469 m_dlHarqProcessesStatus.find(rnti);
470 if (itStat == m_dlHarqProcessesStatus.end())
471 {
472 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
473 }
474 uint8_t i = (*it).second;
475 do
476 {
477 i = (i + 1) % HARQ_PROC_NUM;
478 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
479 if ((*itStat).second.at(i) == 0)
480 {
481 (*it).second = i;
482 (*itStat).second.at(i) = 1;
483 }
484 else
485 {
486 NS_FATAL_ERROR("No HARQ process available for RNTI "
487 << rnti << " check before update with HarqProcessAvailability");
488 }
489
490 return ((*it).second);
491}
492
493void
495{
496 NS_LOG_FUNCTION(this);
497
498 std::map<uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
499 for (itTimers = m_dlHarqProcessesTimer.begin(); itTimers != m_dlHarqProcessesTimer.end();
500 itTimers++)
501 {
502 for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
503 {
504 if ((*itTimers).second.at(i) == HARQ_DL_TIMEOUT)
505 {
506 // reset HARQ process
507
508 NS_LOG_DEBUG(this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
509 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
510 m_dlHarqProcessesStatus.find((*itTimers).first);
511 if (itStat == m_dlHarqProcessesStatus.end())
512 {
513 NS_FATAL_ERROR("No Process Id Status found for this RNTI "
514 << (*itTimers).first);
515 }
516 (*itStat).second.at(i) = 0;
517 (*itTimers).second.at(i) = 0;
518 }
519 else
520 {
521 (*itTimers).second.at(i)++;
522 }
523 }
524 }
525}
526
527void
530{
531 NS_LOG_FUNCTION(this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
532 << (0xF & params.m_sfnSf));
533 // API generated by RLC for triggering the scheduling of a DL subframe
534
535 // evaluate the relative channel quality indicator for each UE per each RBG
536 // (since we are using allocation type 0 the small unit of allocation is RBG)
537 // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
538
540
542 int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
543 std::map<uint16_t, std::vector<uint16_t>> allocationMap; // RBs map per RNTI
544 std::vector<bool> rbgMap; // global RBGs map
545 uint16_t rbgAllocatedNum = 0;
546 std::set<uint16_t> rntiAllocated;
547 rbgMap.resize(m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
548
550 for (std::vector<bool>::iterator it = rbgMap.begin(); it != rbgMap.end(); it++)
551 {
552 if (*it)
553 {
554 rbgAllocatedNum++;
555 }
556 }
557
559
560 // update UL HARQ proc id
561 std::map<uint16_t, uint8_t>::iterator itProcId;
562 for (itProcId = m_ulHarqCurrentProcessId.begin(); itProcId != m_ulHarqCurrentProcessId.end();
563 itProcId++)
564 {
565 (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
566 }
567
568 // RACH Allocation
569 std::vector<bool> ulRbMap;
570 ulRbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
572 uint8_t maxContinuousUlBandwidth = 0;
573 uint8_t tmpMinBandwidth = 0;
574 uint16_t ffrRbStartOffset = 0;
575 uint16_t tmpFfrRbStartOffset = 0;
576 uint16_t index = 0;
577
578 for (std::vector<bool>::iterator it = ulRbMap.begin(); it != ulRbMap.end(); it++)
579 {
580 if (*it)
581 {
582 if (tmpMinBandwidth > maxContinuousUlBandwidth)
583 {
584 maxContinuousUlBandwidth = tmpMinBandwidth;
585 ffrRbStartOffset = tmpFfrRbStartOffset;
586 }
587 tmpMinBandwidth = 0;
588 }
589 else
590 {
591 if (tmpMinBandwidth == 0)
592 {
593 tmpFfrRbStartOffset = index;
594 }
595 tmpMinBandwidth++;
596 }
597 index++;
598 }
599
600 if (tmpMinBandwidth > maxContinuousUlBandwidth)
601 {
602 maxContinuousUlBandwidth = tmpMinBandwidth;
603 ffrRbStartOffset = tmpFfrRbStartOffset;
604 }
605
607 uint16_t rbStart = 0;
608 rbStart = ffrRbStartOffset;
609 std::vector<RachListElement_s>::iterator itRach;
610 for (itRach = m_rachList.begin(); itRach != m_rachList.end(); itRach++)
611 {
613 (*itRach).m_estimatedSize,
614 " Default UL Grant MCS does not allow to send RACH messages");
616 newRar.m_rnti = (*itRach).m_rnti;
617 // DL-RACH Allocation
618 // Ideal: no needs of configuring m_dci
619 // UL-RACH Allocation
620 newRar.m_grant.m_rnti = newRar.m_rnti;
621 newRar.m_grant.m_mcs = m_ulGrantMcs;
622 uint16_t rbLen = 1;
623 uint16_t tbSizeBits = 0;
624 // find lowest TB size that fits UL grant estimated size
625 while ((tbSizeBits < (*itRach).m_estimatedSize) &&
626 (rbStart + rbLen < (ffrRbStartOffset + maxContinuousUlBandwidth)))
627 {
628 rbLen++;
629 tbSizeBits = m_amc->GetUlTbSizeFromMcs(m_ulGrantMcs, rbLen);
630 }
631 if (tbSizeBits < (*itRach).m_estimatedSize)
632 {
633 // no more allocation space: finish allocation
634 break;
635 }
636 newRar.m_grant.m_rbStart = rbStart;
637 newRar.m_grant.m_rbLen = rbLen;
638 newRar.m_grant.m_tbSize = tbSizeBits / 8;
639 newRar.m_grant.m_hopping = false;
640 newRar.m_grant.m_tpc = 0;
641 newRar.m_grant.m_cqiRequest = false;
642 newRar.m_grant.m_ulDelay = false;
643 NS_LOG_INFO(this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart "
644 << rbStart << " rbLen " << rbLen << " MCS " << (uint16_t)m_ulGrantMcs
645 << " tbSize " << newRar.m_grant.m_tbSize);
646 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
647 {
648 m_rachAllocationMap.at(i) = (*itRach).m_rnti;
649 }
650
651 if (m_harqOn)
652 {
653 // generate UL-DCI for HARQ retransmissions
654 UlDciListElement_s uldci;
655 uldci.m_rnti = newRar.m_rnti;
656 uldci.m_rbLen = rbLen;
657 uldci.m_rbStart = rbStart;
658 uldci.m_mcs = m_ulGrantMcs;
659 uldci.m_tbSize = tbSizeBits / 8;
660 uldci.m_ndi = 1;
661 uldci.m_cceIndex = 0;
662 uldci.m_aggrLevel = 1;
663 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
664 uldci.m_hopping = false;
665 uldci.m_n2Dmrs = 0;
666 uldci.m_tpc = 0; // no power control
667 uldci.m_cqiRequest = false; // only period CQI at this stage
668 uldci.m_ulIndex = 0; // TDD parameter
669 uldci.m_dai = 1; // TDD parameter
670 uldci.m_freqHopping = 0;
671 uldci.m_pdcchPowerOffset = 0; // not used
672
673 uint8_t harqId = 0;
674 std::map<uint16_t, uint8_t>::iterator itProcId;
675 itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
676 if (itProcId == m_ulHarqCurrentProcessId.end())
677 {
678 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
679 }
680 harqId = (*itProcId).second;
681 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci =
683 if (itDci == m_ulHarqProcessesDciBuffer.end())
684 {
685 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
686 << uldci.m_rnti);
687 }
688 (*itDci).second.at(harqId) = uldci;
689 }
690
691 rbStart = rbStart + rbLen;
692 ret.m_buildRarList.push_back(newRar);
693 }
694 m_rachList.clear();
695
696 // Process DL HARQ feedback
698 // retrieve past HARQ retx buffered
699 if (!m_dlInfoListBuffered.empty())
700 {
701 if (!params.m_dlInfoList.empty())
702 {
703 NS_LOG_INFO(this << " Received DL-HARQ feedback");
705 params.m_dlInfoList.begin(),
706 params.m_dlInfoList.end());
707 }
708 }
709 else
710 {
711 if (!params.m_dlInfoList.empty())
712 {
713 m_dlInfoListBuffered = params.m_dlInfoList;
714 }
715 }
716 if (!m_harqOn)
717 {
718 // Ignore HARQ feedback
719 m_dlInfoListBuffered.clear();
720 }
721 std::vector<DlInfoListElement_s> dlInfoListUntxed;
722 for (std::size_t i = 0; i < m_dlInfoListBuffered.size(); i++)
723 {
724 std::set<uint16_t>::iterator itRnti = rntiAllocated.find(m_dlInfoListBuffered.at(i).m_rnti);
725 if (itRnti != rntiAllocated.end())
726 {
727 // RNTI already allocated for retx
728 continue;
729 }
730 auto nLayers = m_dlInfoListBuffered.at(i).m_harqStatus.size();
731 std::vector<bool> retx;
732 NS_LOG_INFO(this << " Processing DLHARQ feedback");
733 if (nLayers == 1)
734 {
735 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
737 retx.push_back(false);
738 }
739 else
740 {
741 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
743 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(1) ==
745 }
746 if (retx.at(0) || retx.at(1))
747 {
748 // retrieve HARQ process information
749 uint16_t rnti = m_dlInfoListBuffered.at(i).m_rnti;
750 uint8_t harqId = m_dlInfoListBuffered.at(i).m_harqProcessId;
751 NS_LOG_INFO(this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
752 std::map<uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq =
754 if (itHarq == m_dlHarqProcessesDciBuffer.end())
755 {
756 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << rnti);
757 }
758
759 DlDciListElement_s dci = (*itHarq).second.at(harqId);
760 int rv = 0;
761 if (dci.m_rv.size() == 1)
762 {
763 rv = dci.m_rv.at(0);
764 }
765 else
766 {
767 rv = (dci.m_rv.at(0) > dci.m_rv.at(1) ? dci.m_rv.at(0) : dci.m_rv.at(1));
768 }
769
770 if (rv == 3)
771 {
772 // maximum number of retx reached -> drop process
773 NS_LOG_INFO("Maximum number of retransmissions reached -> drop process");
774 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator it =
775 m_dlHarqProcessesStatus.find(rnti);
776 if (it == m_dlHarqProcessesStatus.end())
777 {
778 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
779 << m_dlInfoListBuffered.at(i).m_rnti);
780 }
781 (*it).second.at(harqId) = 0;
782 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
784 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
785 {
786 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
787 << m_dlInfoListBuffered.at(i).m_rnti);
788 }
789 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
790 {
791 (*itRlcPdu).second.at(k).at(harqId).clear();
792 }
793 continue;
794 }
795 // check the feasibility of retransmitting on the same RBGs
796 // translate the DCI to Spectrum framework
797 std::vector<int> dciRbg;
798 uint32_t mask = 0x1;
799 NS_LOG_INFO("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
800 for (int j = 0; j < 32; j++)
801 {
802 if (((dci.m_rbBitmap & mask) >> j) == 1)
803 {
804 dciRbg.push_back(j);
805 NS_LOG_INFO("\t" << j);
806 }
807 mask = (mask << 1);
808 }
809 bool free = true;
810 for (std::size_t j = 0; j < dciRbg.size(); j++)
811 {
812 if (rbgMap.at(dciRbg.at(j)))
813 {
814 free = false;
815 break;
816 }
817 }
818 if (free)
819 {
820 // use the same RBGs for the retx
821 // reserve RBGs
822 for (std::size_t j = 0; j < dciRbg.size(); j++)
823 {
824 rbgMap.at(dciRbg.at(j)) = true;
825 NS_LOG_INFO("RBG " << dciRbg.at(j) << " assigned");
826 rbgAllocatedNum++;
827 }
828
829 NS_LOG_INFO(this << " Send retx in the same RBGs");
830 }
831 else
832 {
833 // find RBGs for sending HARQ retx
834 uint8_t j = 0;
835 uint8_t rbgId = (dciRbg.at(dciRbg.size() - 1) + 1) % rbgNum;
836 uint8_t startRbg = dciRbg.at(dciRbg.size() - 1);
837 std::vector<bool> rbgMapCopy = rbgMap;
838 while ((j < dciRbg.size()) && (startRbg != rbgId))
839 {
840 if (!rbgMapCopy.at(rbgId))
841 {
842 rbgMapCopy.at(rbgId) = true;
843 dciRbg.at(j) = rbgId;
844 j++;
845 }
846 rbgId = (rbgId + 1) % rbgNum;
847 }
848 if (j == dciRbg.size())
849 {
850 // find new RBGs -> update DCI map
851 uint32_t rbgMask = 0;
852 for (std::size_t k = 0; k < dciRbg.size(); k++)
853 {
854 rbgMask = rbgMask + (0x1 << dciRbg.at(k));
855 rbgAllocatedNum++;
856 }
857 dci.m_rbBitmap = rbgMask;
858 rbgMap = rbgMapCopy;
859 NS_LOG_INFO(this << " Move retx in RBGs " << dciRbg.size());
860 }
861 else
862 {
863 // HARQ retx cannot be performed on this TTI -> store it
864 dlInfoListUntxed.push_back(m_dlInfoListBuffered.at(i));
865 NS_LOG_INFO(this << " No resource for this retx -> buffer it");
866 }
867 }
868 // retrieve RLC PDU list for retx TBsize and update DCI
870 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
872 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
873 {
874 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
875 }
876 for (std::size_t j = 0; j < nLayers; j++)
877 {
878 if (retx.at(j))
879 {
880 if (j >= dci.m_ndi.size())
881 {
882 // for avoiding errors in MIMO transient phases
883 dci.m_ndi.push_back(0);
884 dci.m_rv.push_back(0);
885 dci.m_mcs.push_back(0);
886 dci.m_tbsSize.push_back(0);
887 NS_LOG_INFO(this << " layer " << (uint16_t)j
888 << " no txed (MIMO transition)");
889 }
890 else
891 {
892 dci.m_ndi.at(j) = 0;
893 dci.m_rv.at(j)++;
894 (*itHarq).second.at(harqId).m_rv.at(j)++;
895 NS_LOG_INFO(this << " layer " << (uint16_t)j << " RV "
896 << (uint16_t)dci.m_rv.at(j));
897 }
898 }
899 else
900 {
901 // empty TB of layer j
902 dci.m_ndi.at(j) = 0;
903 dci.m_rv.at(j) = 0;
904 dci.m_mcs.at(j) = 0;
905 dci.m_tbsSize.at(j) = 0;
906 NS_LOG_INFO(this << " layer " << (uint16_t)j << " no retx");
907 }
908 }
909 for (std::size_t k = 0; k < (*itRlcPdu).second.at(0).at(dci.m_harqProcess).size(); k++)
910 {
911 std::vector<RlcPduListElement_s> rlcPduListPerLc;
912 for (std::size_t j = 0; j < nLayers; j++)
913 {
914 if (retx.at(j))
915 {
916 if (j < dci.m_ndi.size())
917 {
918 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size "
919 << dci.m_tbsSize.at(j));
920 rlcPduListPerLc.push_back(
921 (*itRlcPdu).second.at(j).at(dci.m_harqProcess).at(k));
922 }
923 }
924 else
925 { // if no retx needed on layer j, push an RlcPduListElement_s object with
926 // m_size=0 to keep the size of rlcPduListPerLc vector = 2 in case of MIMO
927 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size " << dci.m_tbsSize.at(j));
928 RlcPduListElement_s emptyElement;
929 emptyElement.m_logicalChannelIdentity = (*itRlcPdu)
930 .second.at(j)
931 .at(dci.m_harqProcess)
932 .at(k)
933 .m_logicalChannelIdentity;
934 emptyElement.m_size = 0;
935 rlcPduListPerLc.push_back(emptyElement);
936 }
937 }
938
939 if (!rlcPduListPerLc.empty())
940 {
941 newEl.m_rlcPduList.push_back(rlcPduListPerLc);
942 }
943 }
944 newEl.m_rnti = rnti;
945 newEl.m_dci = dci;
946 (*itHarq).second.at(harqId).m_rv = dci.m_rv;
947 // refresh timer
948 std::map<uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer =
949 m_dlHarqProcessesTimer.find(rnti);
950 if (itHarqTimer == m_dlHarqProcessesTimer.end())
951 {
952 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
953 }
954 (*itHarqTimer).second.at(harqId) = 0;
955 ret.m_buildDataList.push_back(newEl);
956 rntiAllocated.insert(rnti);
957 }
958 else
959 {
960 // update HARQ process status
961 NS_LOG_INFO(this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at(i).m_rnti);
962 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator it =
964 if (it == m_dlHarqProcessesStatus.end())
965 {
966 NS_FATAL_ERROR("No info find in HARQ buffer for UE "
967 << m_dlInfoListBuffered.at(i).m_rnti);
968 }
969 (*it).second.at(m_dlInfoListBuffered.at(i).m_harqProcessId) = 0;
970 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
972 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
973 {
974 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
975 << m_dlInfoListBuffered.at(i).m_rnti);
976 }
977 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
978 {
979 (*itRlcPdu).second.at(k).at(m_dlInfoListBuffered.at(i).m_harqProcessId).clear();
980 }
981 }
982 }
983 m_dlInfoListBuffered.clear();
984 m_dlInfoListBuffered = dlInfoListUntxed;
985
986 if (rbgAllocatedNum == rbgNum)
987 {
988 // all the RBGs are already allocated -> exit
989 if (!ret.m_buildDataList.empty() || !ret.m_buildRarList.empty())
990 {
992 }
993 return;
994 }
995
996 // update token pool, counter and bank size
997 std::map<uint16_t, fdtbfqsFlowPerf_t>::iterator itStats;
998 for (itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
999 {
1000 if ((*itStats).second.tokenGenerationRate / 1000 + (*itStats).second.tokenPoolSize >
1001 (*itStats).second.maxTokenPoolSize)
1002 {
1003 (*itStats).second.counter +=
1004 (*itStats).second.tokenGenerationRate / 1000 -
1005 ((*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize);
1006 (*itStats).second.tokenPoolSize = (*itStats).second.maxTokenPoolSize;
1007 bankSize += (*itStats).second.tokenGenerationRate / 1000 -
1008 ((*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize);
1009 }
1010 else
1011 {
1012 (*itStats).second.tokenPoolSize += (*itStats).second.tokenGenerationRate / 1000;
1013 }
1014 }
1015
1016 std::set<uint16_t> allocatedRnti; // store UEs which are already assigned RBGs
1017 std::set<uint8_t> allocatedRbg; // store RBGs which are already allocated to UE
1018
1019 int totalRbg = 0;
1020 while (totalRbg < rbgNum)
1021 {
1022 // select UE with largest metric
1023 std::map<uint16_t, fdtbfqsFlowPerf_t>::iterator it;
1024 std::map<uint16_t, fdtbfqsFlowPerf_t>::iterator itMax = m_flowStatsDl.end();
1025 double metricMax = 0.0;
1026 bool firstRnti = true;
1027 for (it = m_flowStatsDl.begin(); it != m_flowStatsDl.end(); it++)
1028 {
1029 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1030 if ((itRnti != rntiAllocated.end()) || (!HarqProcessAvailability((*it).first)))
1031 {
1032 // UE already allocated for HARQ or without HARQ process available -> drop it
1033 if (itRnti != rntiAllocated.end())
1034 {
1035 NS_LOG_DEBUG(this << " RNTI discarded for HARQ tx" << (uint16_t)(*it).first);
1036 }
1037 if (!HarqProcessAvailability((*it).first))
1038 {
1039 NS_LOG_DEBUG(this << " RNTI discarded for HARQ id" << (uint16_t)(*it).first);
1040 }
1041 continue;
1042 }
1043 // check first the channel conditions for this UE, if CQI!=0
1044 std::map<uint16_t, SbMeasResult_s>::iterator itCqi;
1045 itCqi = m_a30CqiRxed.find((*it).first);
1046 std::map<uint16_t, uint8_t>::iterator itTxMode;
1047 itTxMode = m_uesTxMode.find((*it).first);
1048 if (itTxMode == m_uesTxMode.end())
1049 {
1050 NS_FATAL_ERROR("No Transmission Mode info on user " << (*it).first);
1051 }
1052 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1053
1054 uint8_t cqiSum = 0;
1055 for (int k = 0; k < rbgNum; k++)
1056 {
1057 for (uint8_t j = 0; j < nLayer; j++)
1058 {
1059 if (itCqi == m_a30CqiRxed.end())
1060 {
1061 cqiSum += 1; // no info on this user -> lowest MCS
1062 }
1063 else
1064 {
1065 cqiSum += (*itCqi).second.m_higherLayerSelected.at(k).m_sbCqi.at(j);
1066 }
1067 }
1068 }
1069
1070 if (cqiSum == 0)
1071 {
1072 NS_LOG_INFO("Skip this flow, CQI==0, rnti:" << (*it).first);
1073 continue;
1074 }
1075
1076 if (LcActivePerFlow((*it).first) == 0)
1077 {
1078 continue;
1079 }
1080
1081 std::set<uint16_t>::iterator rnti;
1082 rnti = allocatedRnti.find((*it).first);
1083 if (rnti != allocatedRnti.end()) // already allocated RBGs to this UE
1084 {
1085 continue;
1086 }
1087
1088 double metric =
1089 (((double)(*it).second.counter) / ((double)(*it).second.tokenGenerationRate));
1090
1091 if (firstRnti)
1092 {
1093 metricMax = metric;
1094 itMax = it;
1095 firstRnti = false;
1096 continue;
1097 }
1098 if (metric > metricMax)
1099 {
1100 metricMax = metric;
1101 itMax = it;
1102 }
1103 } // end for m_flowStatsDl
1104
1105 if (itMax == m_flowStatsDl.end())
1106 {
1107 // all UEs are allocated RBG or all UEs already allocated for HARQ or without HARQ
1108 // process available
1109 break;
1110 }
1111
1112 // mark this UE as "allocated"
1113 allocatedRnti.insert((*itMax).first);
1114
1115 // calculate the maximum number of byte that the scheduler can assigned to this UE
1116 uint32_t budget = 0;
1117 if (bankSize > 0)
1118 {
1119 budget = (*itMax).second.counter - (*itMax).second.debtLimit;
1120 if (budget > (*itMax).second.burstCredit)
1121 {
1122 budget = (*itMax).second.burstCredit;
1123 }
1124 if (budget > bankSize)
1125 {
1126 budget = bankSize;
1127 }
1128 }
1129 budget = budget + (*itMax).second.tokenPoolSize;
1130
1131 // calculate how much bytes this UE actually need
1132 if (budget == 0)
1133 {
1134 // there are no tokens for this UE
1135 continue;
1136 }
1137 else
1138 {
1139 // calculate rlc buffer size
1140 uint32_t rlcBufSize = 0;
1141 uint8_t lcid = 0;
1142 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator
1143 itRlcBuf;
1144 for (itRlcBuf = m_rlcBufferReq.begin(); itRlcBuf != m_rlcBufferReq.end(); itRlcBuf++)
1145 {
1146 if ((*itRlcBuf).first.m_rnti == (*itMax).first)
1147 {
1148 lcid = (*itRlcBuf).first.m_lcId;
1149 }
1150 }
1151 LteFlowId_t flow((*itMax).first, lcid);
1152 itRlcBuf = m_rlcBufferReq.find(flow);
1153 if (itRlcBuf != m_rlcBufferReq.end())
1154 {
1155 rlcBufSize = (*itRlcBuf).second.m_rlcTransmissionQueueSize +
1156 (*itRlcBuf).second.m_rlcRetransmissionQueueSize +
1157 (*itRlcBuf).second.m_rlcStatusPduSize;
1158 }
1159 if (budget > rlcBufSize)
1160 {
1161 budget = rlcBufSize;
1162 NS_LOG_DEBUG("budget > rlcBufSize. budget: " << budget
1163 << " RLC buffer size: " << rlcBufSize);
1164 }
1165 }
1166
1167 // assign RBGs to this UE
1168 uint32_t bytesTxed = 0;
1169 uint32_t bytesTxedTmp = 0;
1170 int rbgIndex = 0;
1171 while (bytesTxed <= budget)
1172 {
1173 totalRbg++;
1174
1175 std::map<uint16_t, SbMeasResult_s>::iterator itCqi;
1176 itCqi = m_a30CqiRxed.find((*itMax).first);
1177 std::map<uint16_t, uint8_t>::iterator itTxMode;
1178 itTxMode = m_uesTxMode.find((*itMax).first);
1179 if (itTxMode == m_uesTxMode.end())
1180 {
1181 NS_FATAL_ERROR("No Transmission Mode info on user " << (*it).first);
1182 }
1183 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1184
1185 // find RBG with largest achievableRate
1186 double achievableRateMax = 0.0;
1187 rbgIndex = rbgNum;
1188 for (int k = 0; k < rbgNum; k++)
1189 {
1190 std::set<uint8_t>::iterator rbg;
1191 rbg = allocatedRbg.find(k);
1192 if (rbg != allocatedRbg.end()) // RBGs are already allocated to this UE
1193 {
1194 continue;
1195 }
1196
1197 if (rbgMap.at(k)) // this RBG is allocated in RACH procedure
1198 {
1199 continue;
1200 }
1201
1202 if (!m_ffrSapProvider->IsDlRbgAvailableForUe(k, (*itMax).first))
1203 {
1204 continue;
1205 }
1206
1207 std::vector<uint8_t> sbCqi;
1208 if (itCqi == m_a30CqiRxed.end())
1209 {
1210 for (uint8_t k = 0; k < nLayer; k++)
1211 {
1212 sbCqi.push_back(1); // start with lowest value
1213 }
1214 }
1215 else
1216 {
1217 sbCqi = (*itCqi).second.m_higherLayerSelected.at(k).m_sbCqi;
1218 }
1219 uint8_t cqi1 = sbCqi.at(0);
1220 uint8_t cqi2 = 0;
1221 if (sbCqi.size() > 1)
1222 {
1223 cqi2 = sbCqi.at(1);
1224 }
1225
1226 if ((cqi1 > 0) ||
1227 (cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1228 {
1229 if (LcActivePerFlow((*itMax).first) > 0)
1230 {
1231 // this UE has data to transmit
1232 double achievableRate = 0.0;
1233 for (uint8_t j = 0; j < nLayer; j++)
1234 {
1235 uint8_t mcs = 0;
1236 if (sbCqi.size() > j)
1237 {
1238 mcs = m_amc->GetMcsFromCqi(sbCqi.at(j));
1239 }
1240 else
1241 {
1242 // no info on this subband -> worst MCS
1243 mcs = 0;
1244 }
1245 achievableRate += ((m_amc->GetDlTbSizeFromMcs(mcs, rbgSize) / 8) /
1246 0.001); // = TB size / TTI
1247 }
1248
1249 if (achievableRate > achievableRateMax)
1250 {
1251 achievableRateMax = achievableRate;
1252 rbgIndex = k;
1253 }
1254 } // end of LcActivePerFlow
1255 } // end of cqi
1256 } // end of for rbgNum
1257
1258 if (rbgIndex == rbgNum) // impossible
1259 {
1260 // all RBGs are already assigned
1261 totalRbg = rbgNum;
1262 break;
1263 }
1264 else
1265 {
1266 // mark this UE as "allocated"
1267 allocatedRbg.insert(rbgIndex);
1268 }
1269
1270 // assign this RBG to UE
1271 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
1272 itMap = allocationMap.find((*itMax).first);
1273 uint16_t RbgPerRnti;
1274 if (itMap == allocationMap.end())
1275 {
1276 // insert new element
1277 std::vector<uint16_t> tempMap;
1278 tempMap.push_back(rbgIndex);
1279 allocationMap.insert(
1280 std::pair<uint16_t, std::vector<uint16_t>>((*itMax).first, tempMap));
1281 itMap = allocationMap.find(
1282 (*itMax).first); // point itMap to the first RBGs assigned to this UE
1283 }
1284 else
1285 {
1286 (*itMap).second.push_back(rbgIndex);
1287 }
1288 rbgMap.at(rbgIndex) = true; // Mark this RBG as allocated
1289
1290 RbgPerRnti = (*itMap).second.size();
1291
1292 // calculate tb size
1293 std::vector<uint8_t> worstCqi(2, 15);
1294 if (itCqi != m_a30CqiRxed.end())
1295 {
1296 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1297 {
1298 if ((*itCqi).second.m_higherLayerSelected.size() > (*itMap).second.at(k))
1299 {
1300 for (uint8_t j = 0; j < nLayer; j++)
1301 {
1302 if ((*itCqi)
1303 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1304 .m_sbCqi.size() > j)
1305 {
1306 if (((*itCqi)
1307 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1308 .m_sbCqi.at(j)) < worstCqi.at(j))
1309 {
1310 worstCqi.at(j) =
1311 ((*itCqi)
1312 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1313 .m_sbCqi.at(j));
1314 }
1315 }
1316 else
1317 {
1318 // no CQI for this layer of this suband -> worst one
1319 worstCqi.at(j) = 1;
1320 }
1321 }
1322 }
1323 else
1324 {
1325 for (uint8_t j = 0; j < nLayer; j++)
1326 {
1327 worstCqi.at(j) =
1328 1; // try with lowest MCS in RBG with no info on channel
1329 }
1330 }
1331 }
1332 }
1333 else
1334 {
1335 for (uint8_t j = 0; j < nLayer; j++)
1336 {
1337 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1338 }
1339 }
1340
1341 bytesTxedTmp = bytesTxed;
1342 bytesTxed = 0;
1343 for (uint8_t j = 0; j < nLayer; j++)
1344 {
1345 int tbSize = (m_amc->GetDlTbSizeFromMcs(m_amc->GetMcsFromCqi(worstCqi.at(j)),
1346 RbgPerRnti * rbgSize) /
1347 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1348 bytesTxed += tbSize;
1349 }
1350
1351 } // end of while()
1352
1353 // remove and unmark last RBG assigned to UE
1354 if (bytesTxed > budget)
1355 {
1356 NS_LOG_DEBUG("budget: " << budget << " bytesTxed: " << bytesTxed << " at "
1357 << Simulator::Now().As(Time::MS));
1358 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
1359 itMap = allocationMap.find((*itMax).first);
1360 (*itMap).second.pop_back();
1361 allocatedRbg.erase(rbgIndex);
1362 bytesTxed = bytesTxedTmp; // recovery bytesTxed
1363 totalRbg--;
1364 rbgMap.at(rbgIndex) = false; // unmark this RBG
1365 // If all the RBGs are removed from the allocation
1366 // of this RNTI, we remove the UE from the allocation map
1367 if ((*itMap).second.empty())
1368 {
1369 itMap = allocationMap.erase(itMap);
1370 }
1371 }
1372
1373 // only update the UE stats if it exists in the allocation map
1374 if (allocationMap.find((*itMax).first) != allocationMap.end())
1375 {
1376 // update UE stats
1377 if (bytesTxed <= (*itMax).second.tokenPoolSize)
1378 {
1379 (*itMax).second.tokenPoolSize -= bytesTxed;
1380 }
1381 else
1382 {
1383 (*itMax).second.counter =
1384 (*itMax).second.counter - (bytesTxed - (*itMax).second.tokenPoolSize);
1385 (*itMax).second.tokenPoolSize = 0;
1386 if (bankSize <= (bytesTxed - (*itMax).second.tokenPoolSize))
1387 {
1388 bankSize = 0;
1389 }
1390 else
1391 {
1392 bankSize = bankSize - (bytesTxed - (*itMax).second.tokenPoolSize);
1393 }
1394 }
1395 }
1396 } // end of RBGs
1397
1398 // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1399 // creating the correspondent DCIs
1400 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap = allocationMap.begin();
1401 while (itMap != allocationMap.end())
1402 {
1403 NS_LOG_DEBUG("Preparing DCI for RNTI " << (*itMap).first);
1404 // create new BuildDataListElement_s for this LC
1406 newEl.m_rnti = (*itMap).first;
1407 // create the DlDciListElement_s
1408 DlDciListElement_s newDci;
1409 newDci.m_rnti = (*itMap).first;
1410 newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
1411
1412 uint16_t lcActives = LcActivePerFlow((*itMap).first);
1413 NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1414 if (lcActives == 0)
1415 {
1416 // Set to max value, to avoid divide by 0 below
1417 lcActives = (uint16_t)65535; // UINT16_MAX;
1418 }
1419 uint16_t RgbPerRnti = (*itMap).second.size();
1420 std::map<uint16_t, SbMeasResult_s>::iterator itCqi;
1421 itCqi = m_a30CqiRxed.find((*itMap).first);
1422 std::map<uint16_t, uint8_t>::iterator itTxMode;
1423 itTxMode = m_uesTxMode.find((*itMap).first);
1424 if (itTxMode == m_uesTxMode.end())
1425 {
1426 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1427 }
1428 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1429 std::vector<uint8_t> worstCqi(2, 15);
1430 if (itCqi != m_a30CqiRxed.end())
1431 {
1432 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1433 {
1434 if ((*itCqi).second.m_higherLayerSelected.size() > (*itMap).second.at(k))
1435 {
1436 NS_LOG_INFO(this << " RBG " << (*itMap).second.at(k) << " CQI "
1437 << (uint16_t)((*itCqi)
1438 .second.m_higherLayerSelected
1439 .at((*itMap).second.at(k))
1440 .m_sbCqi.at(0)));
1441 for (uint8_t j = 0; j < nLayer; j++)
1442 {
1443 if ((*itCqi)
1444 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1445 .m_sbCqi.size() > j)
1446 {
1447 if (((*itCqi)
1448 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1449 .m_sbCqi.at(j)) < worstCqi.at(j))
1450 {
1451 worstCqi.at(j) =
1452 ((*itCqi)
1453 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1454 .m_sbCqi.at(j));
1455 }
1456 }
1457 else
1458 {
1459 // no CQI for this layer of this suband -> worst one
1460 worstCqi.at(j) = 1;
1461 }
1462 }
1463 }
1464 else
1465 {
1466 for (uint8_t j = 0; j < nLayer; j++)
1467 {
1468 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1469 }
1470 }
1471 }
1472 }
1473 else
1474 {
1475 for (uint8_t j = 0; j < nLayer; j++)
1476 {
1477 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1478 }
1479 }
1480 for (uint8_t j = 0; j < nLayer; j++)
1481 {
1482 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " CQI selected "
1483 << (uint16_t)worstCqi.at(j));
1484 }
1485 for (uint8_t j = 0; j < nLayer; j++)
1486 {
1487 newDci.m_mcs.push_back(m_amc->GetMcsFromCqi(worstCqi.at(j)));
1488 int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RgbPerRnti * rbgSize) /
1489 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1490 newDci.m_tbsSize.push_back(tbSize);
1491 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " MCS selected"
1492 << (uint16_t)m_amc->GetMcsFromCqi(worstCqi.at(j)));
1493 }
1494
1495 newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1496 newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1497 uint32_t rbgMask = 0;
1498 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1499 {
1500 rbgMask = rbgMask + (0x1 << (*itMap).second.at(k));
1501 NS_LOG_INFO(this << " Allocated RBG " << (*itMap).second.at(k));
1502 }
1503 newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1504
1505 // create the rlc PDUs -> equally divide resources among actives LCs
1506 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator
1507 itBufReq;
1508 for (itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1509 {
1510 if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1511 (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1512 ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1513 ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1514 {
1515 std::vector<RlcPduListElement_s> newRlcPduLe;
1516 for (uint8_t j = 0; j < nLayer; j++)
1517 {
1518 RlcPduListElement_s newRlcEl;
1519 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1520 newRlcEl.m_size = newDci.m_tbsSize.at(j) / lcActives;
1521 NS_LOG_INFO(this << " LCID " << (uint32_t)newRlcEl.m_logicalChannelIdentity
1522 << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1523 newRlcPduLe.push_back(newRlcEl);
1525 newRlcEl.m_logicalChannelIdentity,
1526 newRlcEl.m_size);
1527 if (m_harqOn)
1528 {
1529 // store RLC PDU list for HARQ
1530 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
1531 m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1532 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1533 {
1534 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1535 << (*itMap).first);
1536 }
1537 (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1538 }
1539 }
1540 newEl.m_rlcPduList.push_back(newRlcPduLe);
1541 }
1542 if ((*itBufReq).first.m_rnti > (*itMap).first)
1543 {
1544 break;
1545 }
1546 }
1547 for (uint8_t j = 0; j < nLayer; j++)
1548 {
1549 newDci.m_ndi.push_back(1);
1550 newDci.m_rv.push_back(0);
1551 }
1552
1553 newDci.m_tpc = m_ffrSapProvider->GetTpc((*itMap).first);
1554
1555 newEl.m_dci = newDci;
1556
1557 if (m_harqOn)
1558 {
1559 // store DCI for HARQ
1560 std::map<uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci =
1562 if (itDci == m_dlHarqProcessesDciBuffer.end())
1563 {
1564 NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1565 << newEl.m_rnti);
1566 }
1567 (*itDci).second.at(newDci.m_harqProcess) = newDci;
1568 // refresh timer
1569 std::map<uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer =
1570 m_dlHarqProcessesTimer.find(newEl.m_rnti);
1571 if (itHarqTimer == m_dlHarqProcessesTimer.end())
1572 {
1573 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1574 }
1575 (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1576 }
1577
1578 // ...more parameters -> ignored in this version
1579
1580 ret.m_buildDataList.push_back(newEl);
1581
1582 itMap++;
1583 } // end while allocation
1584 ret.m_nrOfPdcchOfdmSymbols = 1;
1585
1587}
1588
1589void
1592{
1593 NS_LOG_FUNCTION(this);
1594
1595 m_rachList = params.m_rachList;
1596}
1597
1598void
1601{
1602 NS_LOG_FUNCTION(this);
1604
1605 for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1606 {
1607 if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1608 {
1609 NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1610 << " reported");
1611 std::map<uint16_t, uint8_t>::iterator it;
1612 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1613 it = m_p10CqiRxed.find(rnti);
1614 if (it == m_p10CqiRxed.end())
1615 {
1616 // create the new entry
1617 m_p10CqiRxed.insert(std::pair<uint16_t, uint8_t>(
1618 rnti,
1619 params.m_cqiList.at(i).m_wbCqi.at(0))); // only codeword 0 at this stage (SISO)
1620 // generate correspondent timer
1621 m_p10CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1622 }
1623 else
1624 {
1625 // update the CQI value and refresh correspondent timer
1626 (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1627 // update correspondent timer
1628 std::map<uint16_t, uint32_t>::iterator itTimers;
1629 itTimers = m_p10CqiTimers.find(rnti);
1630 (*itTimers).second = m_cqiTimersThreshold;
1631 }
1632 }
1633 else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1634 {
1635 // subband CQI reporting high layer configured
1636 std::map<uint16_t, SbMeasResult_s>::iterator it;
1637 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1638 it = m_a30CqiRxed.find(rnti);
1639 if (it == m_a30CqiRxed.end())
1640 {
1641 // create the new entry
1642 m_a30CqiRxed.insert(
1643 std::pair<uint16_t, SbMeasResult_s>(rnti,
1644 params.m_cqiList.at(i).m_sbMeasResult));
1645 m_a30CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1646 }
1647 else
1648 {
1649 // update the CQI value and refresh correspondent timer
1650 (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1651 std::map<uint16_t, uint32_t>::iterator itTimers;
1652 itTimers = m_a30CqiTimers.find(rnti);
1653 (*itTimers).second = m_cqiTimersThreshold;
1654 }
1655 }
1656 else
1657 {
1658 NS_LOG_ERROR(this << " CQI type unknown");
1659 }
1660 }
1661}
1662
1663double
1664FdTbfqFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1665{
1666 std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find(rnti);
1667 if (itCqi == m_ueCqi.end())
1668 {
1669 // no cqi info about this UE
1670 return (NO_SINR);
1671 }
1672 else
1673 {
1674 // take the average SINR value among the available
1675 double sinrSum = 0;
1676 unsigned int sinrNum = 0;
1677 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1678 {
1679 double sinr = (*itCqi).second.at(i);
1680 if (sinr != NO_SINR)
1681 {
1682 sinrSum += sinr;
1683 sinrNum++;
1684 }
1685 }
1686 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1687 // store the value
1688 (*itCqi).second.at(rb) = estimatedSinr;
1689 return (estimatedSinr);
1690 }
1691}
1692
1693void
1696{
1697 NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1698 << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1699
1702
1703 // Generate RBs map
1705 std::vector<bool> rbMap;
1706 uint16_t rbAllocatedNum = 0;
1707 std::set<uint16_t> rntiAllocated;
1708 std::vector<uint16_t> rbgAllocationMap;
1709 // update with RACH allocation map
1710 rbgAllocationMap = m_rachAllocationMap;
1711 // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1712 m_rachAllocationMap.clear();
1714
1715 rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1716
1718
1719 for (std::vector<bool>::iterator it = rbMap.begin(); it != rbMap.end(); it++)
1720 {
1721 if (*it)
1722 {
1723 rbAllocatedNum++;
1724 }
1725 }
1726
1727 uint8_t minContinuousUlBandwidth = m_ffrSapProvider->GetMinContinuousUlBandwidth();
1728 uint8_t ffrUlBandwidth = m_cschedCellConfig.m_ulBandwidth - rbAllocatedNum;
1729
1730 // remove RACH allocation
1731 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1732 {
1733 if (rbgAllocationMap.at(i) != 0)
1734 {
1735 rbMap.at(i) = true;
1736 NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1737 }
1738 }
1739
1740 if (m_harqOn)
1741 {
1742 // Process UL HARQ feedback
1743 for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1744 {
1745 if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1746 {
1747 // retx correspondent block: retrieve the UL-DCI
1748 uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1749 std::map<uint16_t, uint8_t>::iterator itProcId =
1750 m_ulHarqCurrentProcessId.find(rnti);
1751 if (itProcId == m_ulHarqCurrentProcessId.end())
1752 {
1753 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1754 }
1755 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1756 NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1757 << " i " << i << " size " << params.m_ulInfoList.size());
1758 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq =
1759 m_ulHarqProcessesDciBuffer.find(rnti);
1760 if (itHarq == m_ulHarqProcessesDciBuffer.end())
1761 {
1762 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1763 continue;
1764 }
1765 UlDciListElement_s dci = (*itHarq).second.at(harqId);
1766 std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1767 m_ulHarqProcessesStatus.find(rnti);
1768 if (itStat == m_ulHarqProcessesStatus.end())
1769 {
1770 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1771 }
1772 if ((*itStat).second.at(harqId) >= 3)
1773 {
1774 NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1775 continue;
1776 }
1777 bool free = true;
1778 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1779 {
1780 if (rbMap.at(j))
1781 {
1782 free = false;
1783 NS_LOG_INFO(this << " BUSY " << j);
1784 }
1785 }
1786 if (free)
1787 {
1788 // retx on the same RBs
1789 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1790 {
1791 rbMap.at(j) = true;
1792 rbgAllocationMap.at(j) = dci.m_rnti;
1793 NS_LOG_INFO("\tRB " << j);
1794 rbAllocatedNum++;
1795 }
1796 NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1797 << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1798 << (*itStat).second.at(harqId) + 1);
1799 }
1800 else
1801 {
1802 NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1803 continue;
1804 }
1805 dci.m_ndi = 0;
1806 // Update HARQ buffers with new HarqId
1807 (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1808 (*itStat).second.at(harqId) = 0;
1809 (*itHarq).second.at((*itProcId).second) = dci;
1810 ret.m_dciList.push_back(dci);
1811 rntiAllocated.insert(dci.m_rnti);
1812 }
1813 else
1814 {
1815 NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1816 << params.m_ulInfoList.at(i).m_rnti);
1817 }
1818 }
1819 }
1820
1821 std::map<uint16_t, uint32_t>::iterator it;
1822 int nflows = 0;
1823
1824 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1825 {
1826 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1827 // select UEs with queues not empty and not yet allocated for HARQ
1828 if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1829 {
1830 nflows++;
1831 }
1832 }
1833
1834 if (nflows == 0)
1835 {
1836 if (!ret.m_dciList.empty())
1837 {
1838 m_allocationMaps.insert(
1839 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1841 }
1842
1843 return; // no flows to be scheduled
1844 }
1845
1846 // Divide the remaining resources equally among the active users starting from the subsequent
1847 // one served last scheduling trigger
1848 uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size());
1849 uint16_t rbPerFlow =
1850 (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1851
1852 if (rbPerFlow < 3)
1853 {
1854 rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1855 // >= 7 bytes
1856 }
1857 int rbAllocated = 0;
1858
1859 std::map<uint16_t, fdtbfqsFlowPerf_t>::iterator itStats;
1860 if (m_nextRntiUl != 0)
1861 {
1862 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1863 {
1864 if ((*it).first == m_nextRntiUl)
1865 {
1866 break;
1867 }
1868 }
1869 if (it == m_ceBsrRxed.end())
1870 {
1871 NS_LOG_ERROR(this << " no user found");
1872 }
1873 }
1874 else
1875 {
1876 it = m_ceBsrRxed.begin();
1877 m_nextRntiUl = (*it).first;
1878 }
1879 do
1880 {
1881 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1882 if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1883 {
1884 // UE already allocated for UL-HARQ -> skip it
1885 NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1886 << (*it).first);
1887 it++;
1888 if (it == m_ceBsrRxed.end())
1889 {
1890 // restart from the first
1891 it = m_ceBsrRxed.begin();
1892 }
1893 continue;
1894 }
1895 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1896 {
1897 // limit to physical resources last resource assignment
1898 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1899 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1900 if (rbPerFlow < 3)
1901 {
1902 // terminate allocation
1903 rbPerFlow = 0;
1904 }
1905 }
1906
1907 rbAllocated = 0;
1908 UlDciListElement_s uldci;
1909 uldci.m_rnti = (*it).first;
1910 uldci.m_rbLen = rbPerFlow;
1911 bool allocated = false;
1912 NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1913 << " flows " << nflows);
1914 while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1915 (rbPerFlow != 0))
1916 {
1917 // check availability
1918 bool free = true;
1919 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1920 {
1921 if (rbMap.at(j))
1922 {
1923 free = false;
1924 break;
1925 }
1926 if (!m_ffrSapProvider->IsUlRbgAvailableForUe(j, (*it).first))
1927 {
1928 free = false;
1929 break;
1930 }
1931 }
1932 if (free)
1933 {
1934 NS_LOG_INFO(this << "RNTI: " << (*it).first << " RB Allocated " << rbAllocated
1935 << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1936 uldci.m_rbStart = rbAllocated;
1937
1938 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1939 {
1940 rbMap.at(j) = true;
1941 // store info on allocation for managing ul-cqi interpretation
1942 rbgAllocationMap.at(j) = (*it).first;
1943 }
1944 rbAllocated += rbPerFlow;
1945 allocated = true;
1946 break;
1947 }
1948 rbAllocated++;
1949 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1950 {
1951 // limit to physical resources last resource assignment
1952 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1953 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1954 if (rbPerFlow < 3)
1955 {
1956 // terminate allocation
1957 rbPerFlow = 0;
1958 }
1959 }
1960 }
1961 if (!allocated)
1962 {
1963 // unable to allocate new resource: finish scheduling
1964 // m_nextRntiUl = (*it).first;
1965 // if (ret.m_dciList.size () > 0)
1966 // {
1967 // m_schedSapUser->SchedUlConfigInd (ret);
1968 // }
1969 // m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> >
1970 // (params.m_sfnSf, rbgAllocationMap)); return;
1971 break;
1972 }
1973
1974 std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find((*it).first);
1975 int cqi = 0;
1976 if (itCqi == m_ueCqi.end())
1977 {
1978 // no cqi info about this UE
1979 uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1980 }
1981 else
1982 {
1983 // take the lowest CQI value (worst RB)
1984 NS_ABORT_MSG_IF((*itCqi).second.empty(),
1985 "CQI of RNTI = " << (*it).first << " has expired");
1986 double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1987 if (minSinr == NO_SINR)
1988 {
1989 minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1990 }
1991 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1992 {
1993 double sinr = (*itCqi).second.at(i);
1994 if (sinr == NO_SINR)
1995 {
1996 sinr = EstimateUlSinr((*it).first, i);
1997 }
1998 if (sinr < minSinr)
1999 {
2000 minSinr = sinr;
2001 }
2002 }
2003
2004 // translate SINR -> cqi: WILD ACK: same as DL
2005 double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
2006 cqi = m_amc->GetCqiFromSpectralEfficiency(s);
2007 if (cqi == 0)
2008 {
2009 it++;
2010 if (it == m_ceBsrRxed.end())
2011 {
2012 // restart from the first
2013 it = m_ceBsrRxed.begin();
2014 }
2015 NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
2016 // remove UE from allocation map
2017 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
2018 {
2019 rbgAllocationMap.at(i) = 0;
2020 }
2021 continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
2022 }
2023 uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
2024 }
2025
2026 uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
2028 uldci.m_ndi = 1;
2029 uldci.m_cceIndex = 0;
2030 uldci.m_aggrLevel = 1;
2031 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
2032 uldci.m_hopping = false;
2033 uldci.m_n2Dmrs = 0;
2034 uldci.m_tpc = 0; // no power control
2035 uldci.m_cqiRequest = false; // only period CQI at this stage
2036 uldci.m_ulIndex = 0; // TDD parameter
2037 uldci.m_dai = 1; // TDD parameter
2038 uldci.m_freqHopping = 0;
2039 uldci.m_pdcchPowerOffset = 0; // not used
2040 ret.m_dciList.push_back(uldci);
2041 // store DCI for HARQ_PERIOD
2042 uint8_t harqId = 0;
2043 if (m_harqOn)
2044 {
2045 std::map<uint16_t, uint8_t>::iterator itProcId;
2046 itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
2047 if (itProcId == m_ulHarqCurrentProcessId.end())
2048 {
2049 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
2050 }
2051 harqId = (*itProcId).second;
2052 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci =
2054 if (itDci == m_ulHarqProcessesDciBuffer.end())
2055 {
2056 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
2057 << uldci.m_rnti);
2058 }
2059 (*itDci).second.at(harqId) = uldci;
2060 // Update HARQ process status (RV 0)
2061 std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
2062 m_ulHarqProcessesStatus.find(uldci.m_rnti);
2063 if (itStat == m_ulHarqProcessesStatus.end())
2064 {
2065 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
2066 << uldci.m_rnti);
2067 }
2068 (*itStat).second.at(harqId) = 0;
2069 }
2070
2071 NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
2072 << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
2073 << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
2074 << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
2075 << (uint16_t)harqId);
2076
2077 it++;
2078 if (it == m_ceBsrRxed.end())
2079 {
2080 // restart from the first
2081 it = m_ceBsrRxed.begin();
2082 }
2083 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
2084 {
2085 // Stop allocation: no more PRBs
2086 m_nextRntiUl = (*it).first;
2087 break;
2088 }
2089 } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
2090
2091 m_allocationMaps.insert(
2092 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
2094}
2095
2096void
2099{
2100 NS_LOG_FUNCTION(this);
2101}
2102
2103void
2106{
2107 NS_LOG_FUNCTION(this);
2108}
2109
2110void
2113{
2114 NS_LOG_FUNCTION(this);
2115
2116 std::map<uint16_t, uint32_t>::iterator it;
2117
2118 for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
2119 {
2120 if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
2121 {
2122 // buffer status report
2123 // note that this scheduler does not differentiate the
2124 // allocation according to which LCGs have more/less bytes
2125 // to send.
2126 // Hence the BSR of different LCGs are just summed up to get
2127 // a total queue size that is used for allocation purposes.
2128
2129 uint32_t buffer = 0;
2130 for (uint8_t lcg = 0; lcg < 4; ++lcg)
2131 {
2132 uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
2133 buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
2134 }
2135
2136 uint16_t rnti = params.m_macCeList.at(i).m_rnti;
2137 NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
2138 it = m_ceBsrRxed.find(rnti);
2139 if (it == m_ceBsrRxed.end())
2140 {
2141 // create the new entry
2142 m_ceBsrRxed.insert(std::pair<uint16_t, uint32_t>(rnti, buffer));
2143 }
2144 else
2145 {
2146 // update the buffer size value
2147 (*it).second = buffer;
2148 }
2149 }
2150 }
2151}
2152
2153void
2156{
2157 NS_LOG_FUNCTION(this);
2158 // retrieve the allocation for this subframe
2159 switch (m_ulCqiFilter)
2160 {
2162 // filter all the CQIs that are not SRS based
2163 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
2164 {
2165 return;
2166 }
2167 }
2168 break;
2170 // filter all the CQIs that are not SRS based
2171 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
2172 {
2173 return;
2174 }
2175 }
2176 break;
2177 default:
2178 NS_FATAL_ERROR("Unknown UL CQI type");
2179 }
2180
2181 switch (params.m_ulCqi.m_type)
2182 {
2183 case UlCqi_s::PUSCH: {
2184 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
2185 std::map<uint16_t, std::vector<double>>::iterator itCqi;
2186 NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
2187 << " subframe no. " << (0xF & params.m_sfnSf));
2188 itMap = m_allocationMaps.find(params.m_sfnSf);
2189 if (itMap == m_allocationMaps.end())
2190 {
2191 return;
2192 }
2193 for (uint32_t i = 0; i < (*itMap).second.size(); i++)
2194 {
2195 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
2196 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
2197 itCqi = m_ueCqi.find((*itMap).second.at(i));
2198 if (itCqi == m_ueCqi.end())
2199 {
2200 // create a new entry
2201 std::vector<double> newCqi;
2202 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2203 {
2204 if (i == j)
2205 {
2206 newCqi.push_back(sinr);
2207 }
2208 else
2209 {
2210 // initialize with NO_SINR value.
2211 newCqi.push_back(NO_SINR);
2212 }
2213 }
2214 m_ueCqi.insert(
2215 std::pair<uint16_t, std::vector<double>>((*itMap).second.at(i), newCqi));
2216 // generate correspondent timer
2217 m_ueCqiTimers.insert(
2218 std::pair<uint16_t, uint32_t>((*itMap).second.at(i), m_cqiTimersThreshold));
2219 }
2220 else
2221 {
2222 // update the value
2223 (*itCqi).second.at(i) = sinr;
2224 NS_LOG_DEBUG(this << " RNTI " << (*itMap).second.at(i) << " RB " << i << " SINR "
2225 << sinr);
2226 // update correspondent timer
2227 std::map<uint16_t, uint32_t>::iterator itTimers;
2228 itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
2229 (*itTimers).second = m_cqiTimersThreshold;
2230 }
2231 }
2232 // remove obsolete info on allocation
2233 m_allocationMaps.erase(itMap);
2234 }
2235 break;
2236 case UlCqi_s::SRS: {
2237 // get the RNTI from vendor specific parameters
2238 uint16_t rnti = 0;
2239 NS_ASSERT(!params.m_vendorSpecificList.empty());
2240 for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
2241 {
2242 if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
2243 {
2244 Ptr<SrsCqiRntiVsp> vsp =
2245 DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
2246 rnti = vsp->GetRnti();
2247 }
2248 }
2249 std::map<uint16_t, std::vector<double>>::iterator itCqi;
2250 itCqi = m_ueCqi.find(rnti);
2251 if (itCqi == m_ueCqi.end())
2252 {
2253 // create a new entry
2254 std::vector<double> newCqi;
2255 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2256 {
2257 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
2258 newCqi.push_back(sinr);
2259 NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
2260 << sinr);
2261 }
2262 m_ueCqi.insert(std::pair<uint16_t, std::vector<double>>(rnti, newCqi));
2263 // generate correspondent timer
2264 m_ueCqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
2265 }
2266 else
2267 {
2268 // update the values
2269 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2270 {
2271 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
2272 (*itCqi).second.at(j) = sinr;
2273 NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
2274 << sinr);
2275 }
2276 // update correspondent timer
2277 std::map<uint16_t, uint32_t>::iterator itTimers;
2278 itTimers = m_ueCqiTimers.find(rnti);
2279 (*itTimers).second = m_cqiTimersThreshold;
2280 }
2281 }
2282 break;
2283 case UlCqi_s::PUCCH_1:
2284 case UlCqi_s::PUCCH_2:
2285 case UlCqi_s::PRACH: {
2286 NS_FATAL_ERROR("FdTbfqFfMacScheduler supports only PUSCH and SRS UL-CQIs");
2287 }
2288 break;
2289 default:
2290 NS_FATAL_ERROR("Unknown type of UL-CQI");
2291 }
2292}
2293
2294void
2296{
2297 // refresh DL CQI P01 Map
2298 std::map<uint16_t, uint32_t>::iterator itP10 = m_p10CqiTimers.begin();
2299 while (itP10 != m_p10CqiTimers.end())
2300 {
2301 NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
2302 << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2303 if ((*itP10).second == 0)
2304 {
2305 // delete correspondent entries
2306 std::map<uint16_t, uint8_t>::iterator itMap = m_p10CqiRxed.find((*itP10).first);
2307 NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
2308 " Does not find CQI report for user " << (*itP10).first);
2309 NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
2310 m_p10CqiRxed.erase(itMap);
2311 std::map<uint16_t, uint32_t>::iterator temp = itP10;
2312 itP10++;
2313 m_p10CqiTimers.erase(temp);
2314 }
2315 else
2316 {
2317 (*itP10).second--;
2318 itP10++;
2319 }
2320 }
2321
2322 // refresh DL CQI A30 Map
2323 std::map<uint16_t, uint32_t>::iterator itA30 = m_a30CqiTimers.begin();
2324 while (itA30 != m_a30CqiTimers.end())
2325 {
2326 NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
2327 << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2328 if ((*itA30).second == 0)
2329 {
2330 // delete correspondent entries
2331 std::map<uint16_t, SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find((*itA30).first);
2332 NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
2333 " Does not find CQI report for user " << (*itA30).first);
2334 NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
2335 m_a30CqiRxed.erase(itMap);
2336 std::map<uint16_t, uint32_t>::iterator temp = itA30;
2337 itA30++;
2338 m_a30CqiTimers.erase(temp);
2339 }
2340 else
2341 {
2342 (*itA30).second--;
2343 itA30++;
2344 }
2345 }
2346}
2347
2348void
2350{
2351 // refresh UL CQI Map
2352 std::map<uint16_t, uint32_t>::iterator itUl = m_ueCqiTimers.begin();
2353 while (itUl != m_ueCqiTimers.end())
2354 {
2355 NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
2356 << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2357 if ((*itUl).second == 0)
2358 {
2359 // delete correspondent entries
2360 std::map<uint16_t, std::vector<double>>::iterator itMap = m_ueCqi.find((*itUl).first);
2361 NS_ASSERT_MSG(itMap != m_ueCqi.end(),
2362 " Does not find CQI report for user " << (*itUl).first);
2363 NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
2364 (*itMap).second.clear();
2365 m_ueCqi.erase(itMap);
2366 std::map<uint16_t, uint32_t>::iterator temp = itUl;
2367 itUl++;
2368 m_ueCqiTimers.erase(temp);
2369 }
2370 else
2371 {
2372 (*itUl).second--;
2373 itUl++;
2374 }
2375 }
2376}
2377
2378void
2379FdTbfqFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
2380{
2381 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2382 LteFlowId_t flow(rnti, lcid);
2383 it = m_rlcBufferReq.find(flow);
2384 if (it != m_rlcBufferReq.end())
2385 {
2386 NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
2387 << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
2388 << (*it).second.m_rlcRetransmissionQueueSize << " status "
2389 << (*it).second.m_rlcStatusPduSize << " decrease " << size);
2390 // Update queues: RLC tx order Status, ReTx, Tx
2391 // Update status queue
2392 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2393 {
2394 (*it).second.m_rlcStatusPduSize = 0;
2395 }
2396 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
2397 (size >= (*it).second.m_rlcRetransmissionQueueSize))
2398 {
2399 (*it).second.m_rlcRetransmissionQueueSize = 0;
2400 }
2401 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2402 {
2403 uint32_t rlcOverhead;
2404 if (lcid == 1)
2405 {
2406 // for SRB1 (using RLC AM) it's better to
2407 // overestimate RLC overhead rather than
2408 // underestimate it and risk unneeded
2409 // segmentation which increases delay
2410 rlcOverhead = 4;
2411 }
2412 else
2413 {
2414 // minimum RLC overhead due to header
2415 rlcOverhead = 2;
2416 }
2417 // update transmission queue
2418 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2419 {
2420 (*it).second.m_rlcTransmissionQueueSize = 0;
2421 }
2422 else
2423 {
2424 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2425 }
2426 }
2427 }
2428 else
2429 {
2430 NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
2431 }
2432}
2433
2434void
2436{
2437 size = size - 2; // remove the minimum RLC overhead
2438 std::map<uint16_t, uint32_t>::iterator it = m_ceBsrRxed.find(rnti);
2439 if (it != m_ceBsrRxed.end())
2440 {
2441 NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2442 if ((*it).second >= size)
2443 {
2444 (*it).second -= size;
2445 }
2446 else
2447 {
2448 (*it).second = 0;
2449 }
2450 }
2451 else
2452 {
2453 NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
2454 }
2455}
2456
2457void
2459{
2460 NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2462 params.m_rnti = rnti;
2463 params.m_transmissionMode = txMode;
2465}
2466
2467} // 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 Token Bank Fair Queue scheduler.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
uint32_t m_tokenPoolSize
maximum size of token pool (byte)
std::map< uint16_t, fdtbfqsFlowPerf_t > m_flowStatsUl
Map of UE statistics (per RNTI basis)
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
void DoSchedDlPagingBufferReq(const FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request function.
static TypeId GetTypeId()
Get the type ID.
bool HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
uint64_t bankSize
the number of bytes in token bank
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
void SetFfMacCschedSapUser(FfMacCschedSapUser *s) override
Set FF MAC Csched SAP user function.
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
friend class MemberSchedSapProvider< FdTbfqFfMacScheduler >
allow MemberSchedSapProvider<FdTbfqFfMacScheduler> claass friend access
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
LteFfrSapUser * GetLteFfrSapUser() override
Get FFR SAP user function.
~FdTbfqFfMacScheduler() override
Destructor.
void DoCschedLcConfigReq(const FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request function.
void DoSchedDlMacBufferReq(const FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request function.
uint32_t m_creditableThreshold
threshold of flow credit
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
void SetFfMacSchedSapUser(FfMacSchedSapUser *s) override
Set FF MAC sched SAP user function.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
Csched cell config.
void RefreshDlCqiMaps()
Refresh DL CQI maps function.
void DoDispose() override
Destructor implementation.
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
Estimate UL SNR function.
std::vector< RachListElement_s > m_rachList
RACH list.
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
Map of UE's DL CQI A30 received.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
void SetLteFfrSapProvider(LteFfrSapProvider *s) override
Set FFR SAP provider function.
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
Get FF MAC CSched SAP provider function.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmisson mode config update function.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
uint32_t m_creditLimit
flow credit limit (byte)
void DoSchedDlRlcBufferReq(const FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request function.
int m_debtLimit
flow debt limit (byte)
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
void DoSchedUlNoiseInterferenceReq(const FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request function.
void RefreshUlCqiMaps()
Refresh UL CQI maps function.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
void DoSchedDlRachInfoReq(const FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request function.
FfMacSchedSapProvider * m_schedSapProvider
sched SAP provider
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
void DoSchedUlMacCtrlInfoReq(const FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request function.
void DoSchedUlCqiInfoReq(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request function.
void DoCschedLcReleaseReq(const FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request function.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
void DoSchedDlCqiInfoReq(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request function.
std::map< uint16_t, fdtbfqsFlowPerf_t > m_flowStatsDl
Map of UE statistics (per RNTI basis) in downlink.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
Get FF MAC sched SAP provider function.
void DoCschedUeConfigReq(const FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request function.
FfMacSchedSapUser * m_schedSapUser
sched SAP user
void DoCschedCellConfigReq(const FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
Csched cell config request function.
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
Map of previous allocated UE per RBG (used to retrieve info from UL-CQI)
unsigned int LcActivePerFlow(uint16_t rnti)
LC Active per flow function.
void DoCschedUeReleaseReq(const FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request function.
void DoSchedUlSrInfoReq(const FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request function.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
FfMacCschedSapUser * m_cschedSapUser
Csched SAP user.
friend class MemberCschedSapProvider< FdTbfqFfMacScheduler >
allow MemberCschedSapProvider<FdTbfqFfMacScheduler> class friend access
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info function.
int GetRbgSize(int dlbandwidth)
Get RBG size function.
void DoSchedUlTriggerReq(const FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request function.
void DoSchedDlTriggerReq(const FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request function.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
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.
Hold a signed integer type.
Definition: integer.h:45
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
virtual uint8_t GetTpc(uint16_t rnti)=0
GetTpc.
virtual std::vector< bool > GetAvailableUlRbg()=0
Get vector of available RB in UL for this Cell.
virtual void ReportUlCqiInfo(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)=0
ReportUlCqiInfo.
virtual bool IsUlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in UL.
virtual void ReportDlCqiInfo(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)=0
ReportDlCqiInfo.
virtual std::vector< bool > GetAvailableDlRbg()=0
Get vector of available RBG in DL for this Cell.
virtual uint16_t GetMinContinuousUlBandwidth()=0
Get the minimum continuous Ul bandwidth.
virtual bool IsDlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in DL.
Service Access Point (SAP) offered by the eNodeB RRC instance to the Frequency Reuse algorithm instan...
Definition: lte-ffr-sap.h:140
Template for the implementation of the LteFfrSapUser as a member of an owner class of type C to which...
Definition: lte-ffr-sap.h:259
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
@ MS
millisecond
Definition: nstime.h:117
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:936
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 > MakeIntegerAccessor(T1 a1)
Definition: integer.h:46
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.
std::vector< uint8_t > UlHarqProcessesStatus_t
UL HARQ process status vector.
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector.
static const int FdTbfqType0AllocationRbg[4]
FdTbfqType0AllocationRbg value array.
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.
Time flowStart
flow start time
int counter
the number of token borrow or given to token bank
uint32_t burstCredit
the maximum number of tokens connection i can borrow from the bank each time
int debtLimit
counter threshold that the flow cannot further borrow tokens from bank
uint32_t creditableThreshold
the flow cannot borrow token from bank until the number of token it has deposited to bank reaches thi...
uint64_t packetArrivalRate
packet arrival rate( byte/s)
uint32_t tokenPoolSize
current size of token pool (byte)
uint32_t maxTokenPoolSize
maximum size of token pool (byte)
uint64_t tokenGenerationRate
token generation rate ( byte/s )