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