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