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