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