A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tta-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("TtaFfMacScheduler");
39
41static const int TtaType0AllocationRbg[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(TtaFfMacScheduler);
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::TtaFfMacScheduler")
86 .SetGroupName("Lte")
87 .AddConstructor<TtaFfMacScheduler>()
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 < TtaType0AllocationRbg[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 itSbCqi;
909 itSbCqi = m_a30CqiRxed.find((*it));
910 std::map<uint16_t, uint8_t>::iterator itWbCqi;
911 itWbCqi = m_p10CqiRxed.find((*it));
912
913 std::map<uint16_t, uint8_t>::iterator itTxMode;
914 itTxMode = m_uesTxMode.find((*it));
915 if (itTxMode == m_uesTxMode.end())
916 {
917 NS_FATAL_ERROR("No Transmission Mode info on user " << (*it));
918 }
919 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
920
921 std::vector<uint8_t> sbCqi;
922 if (itSbCqi == 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 = (*itSbCqi).second.m_higherLayerSelected.at(i).m_sbCqi;
932 }
933
934 uint8_t wbCqi = 0;
935 if (itWbCqi != m_p10CqiRxed.end())
936 {
937 wbCqi = (*itWbCqi).second;
938 }
939 else
940 {
941 wbCqi = 1; // lowest value for trying a transmission
942 }
943
944 uint8_t cqi1 = sbCqi.at(0);
945 uint8_t cqi2 = 0;
946 if (sbCqi.size() > 1)
947 {
948 cqi2 = sbCqi.at(1);
949 }
950 if ((cqi1 > 0) ||
951 (cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
952 {
953 if (LcActivePerFlow((*it)) > 0)
954 {
955 // this UE has data to transmit
956 double achievableSbRate = 0.0;
957 double achievableWbRate = 0.0;
958 uint8_t sbMcs = 0;
959 uint8_t wbMcs = 0;
960 for (uint8_t k = 0; k < nLayer; k++)
961 {
962 if (sbCqi.size() > k)
963 {
964 sbMcs = m_amc->GetMcsFromCqi(sbCqi.at(k));
965 }
966 else
967 {
968 // no info on this subband -> worst MCS
969 sbMcs = 0;
970 }
971 achievableSbRate += ((m_amc->GetDlTbSizeFromMcs(sbMcs, rbgSize) / 8) /
972 0.001); // = TB size / TTI
973 wbMcs = m_amc->GetMcsFromCqi(wbCqi);
974 achievableWbRate += ((m_amc->GetDlTbSizeFromMcs(wbMcs, rbgSize) / 8) /
975 0.001); // = TB size / TTI
976 }
977
978 double metric = achievableSbRate / achievableWbRate;
979
980 if (metric > rcqiMax)
981 {
982 rcqiMax = metric;
983 itMax = it;
984 }
985 }
986 } // end if cqi
987
988 } // end for m_rlcBufferReq
989
990 if (itMax == m_flowStatsDl.end())
991 {
992 // no UE available for this RB
993 NS_LOG_INFO(this << " any UE found");
994 }
995 else
996 {
997 rbgMap.at(i) = true;
998 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
999 itMap = allocationMap.find((*itMax));
1000 if (itMap == allocationMap.end())
1001 {
1002 // insert new element
1003 std::vector<uint16_t> tempMap;
1004 tempMap.push_back(i);
1005 allocationMap.insert(
1006 std::pair<uint16_t, std::vector<uint16_t>>((*itMax), tempMap));
1007 }
1008 else
1009 {
1010 (*itMap).second.push_back(i);
1011 }
1012 NS_LOG_INFO(this << " UE assigned " << (*itMax));
1013 }
1014 } // end for RBG free
1015 } // end for RBGs
1016
1017 // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1018 // creating the correspondent DCIs
1019 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap = allocationMap.begin();
1020 while (itMap != allocationMap.end())
1021 {
1022 // create new BuildDataListElement_s for this LC
1024 newEl.m_rnti = (*itMap).first;
1025 // create the DlDciListElement_s
1026 DlDciListElement_s newDci;
1027 newDci.m_rnti = (*itMap).first;
1028 newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
1029
1030 uint16_t lcActives = LcActivePerFlow((*itMap).first);
1031 NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1032 if (lcActives == 0)
1033 {
1034 // Set to max value, to avoid divide by 0 below
1035 lcActives = (uint16_t)65535; // UINT16_MAX;
1036 }
1037 uint16_t RgbPerRnti = (*itMap).second.size();
1038 std::map<uint16_t, SbMeasResult_s>::iterator itCqi;
1039 itCqi = m_a30CqiRxed.find((*itMap).first);
1040 std::map<uint16_t, uint8_t>::iterator itTxMode;
1041 itTxMode = m_uesTxMode.find((*itMap).first);
1042 if (itTxMode == m_uesTxMode.end())
1043 {
1044 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1045 }
1046 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1047 std::vector<uint8_t> worstCqi(2, 15);
1048 if (itCqi != m_a30CqiRxed.end())
1049 {
1050 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1051 {
1052 if ((*itCqi).second.m_higherLayerSelected.size() > (*itMap).second.at(k))
1053 {
1054 NS_LOG_INFO(this << " RBG " << (*itMap).second.at(k) << " CQI "
1055 << (uint16_t)((*itCqi)
1056 .second.m_higherLayerSelected
1057 .at((*itMap).second.at(k))
1058 .m_sbCqi.at(0)));
1059 for (uint8_t j = 0; j < nLayer; j++)
1060 {
1061 if ((*itCqi)
1062 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1063 .m_sbCqi.size() > j)
1064 {
1065 if (((*itCqi)
1066 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1067 .m_sbCqi.at(j)) < worstCqi.at(j))
1068 {
1069 worstCqi.at(j) =
1070 ((*itCqi)
1071 .second.m_higherLayerSelected.at((*itMap).second.at(k))
1072 .m_sbCqi.at(j));
1073 }
1074 }
1075 else
1076 {
1077 // no CQI for this layer of this suband -> worst one
1078 worstCqi.at(j) = 1;
1079 }
1080 }
1081 }
1082 else
1083 {
1084 for (uint8_t j = 0; j < nLayer; j++)
1085 {
1086 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1087 }
1088 }
1089 }
1090 }
1091 else
1092 {
1093 for (uint8_t j = 0; j < nLayer; j++)
1094 {
1095 worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1096 }
1097 }
1098 for (uint8_t j = 0; j < nLayer; j++)
1099 {
1100 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " CQI selected "
1101 << (uint16_t)worstCqi.at(j));
1102 }
1103 for (uint8_t j = 0; j < nLayer; j++)
1104 {
1105 newDci.m_mcs.push_back(m_amc->GetMcsFromCqi(worstCqi.at(j)));
1106 int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RgbPerRnti * rbgSize) /
1107 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1108 newDci.m_tbsSize.push_back(tbSize);
1109 NS_LOG_INFO(this << " Layer " << (uint16_t)j << " MCS selected"
1110 << m_amc->GetMcsFromCqi(worstCqi.at(j)));
1111 }
1112
1113 newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1114 newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1115 uint32_t rbgMask = 0;
1116 for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1117 {
1118 rbgMask = rbgMask + (0x1 << (*itMap).second.at(k));
1119 NS_LOG_INFO(this << " Allocated RBG " << (*itMap).second.at(k));
1120 }
1121 newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1122
1123 // create the rlc PDUs -> equally divide resources among actives LCs
1124 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator
1125 itBufReq;
1126 for (itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1127 {
1128 if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1129 (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1130 ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1131 ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1132 {
1133 std::vector<RlcPduListElement_s> newRlcPduLe;
1134 for (uint8_t j = 0; j < nLayer; j++)
1135 {
1136 RlcPduListElement_s newRlcEl;
1137 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1138 newRlcEl.m_size = newDci.m_tbsSize.at(j) / lcActives;
1139 NS_LOG_INFO(this << " LCID " << (uint32_t)newRlcEl.m_logicalChannelIdentity
1140 << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1141 newRlcPduLe.push_back(newRlcEl);
1143 newRlcEl.m_logicalChannelIdentity,
1144 newRlcEl.m_size);
1145 if (m_harqOn)
1146 {
1147 // store RLC PDU list for HARQ
1148 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
1149 m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1150 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1151 {
1152 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1153 << (*itMap).first);
1154 }
1155 (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1156 }
1157 }
1158 newEl.m_rlcPduList.push_back(newRlcPduLe);
1159 }
1160 if ((*itBufReq).first.m_rnti > (*itMap).first)
1161 {
1162 break;
1163 }
1164 }
1165 for (uint8_t j = 0; j < nLayer; j++)
1166 {
1167 newDci.m_ndi.push_back(1);
1168 newDci.m_rv.push_back(0);
1169 }
1170
1171 newDci.m_tpc = 1; // 1 is mapped to 0 in Accumulated Mode and to -1 in Absolute Mode
1172
1173 newEl.m_dci = newDci;
1174
1175 if (m_harqOn)
1176 {
1177 // store DCI for HARQ
1178 std::map<uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci =
1180 if (itDci == m_dlHarqProcessesDciBuffer.end())
1181 {
1182 NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1183 << newEl.m_rnti);
1184 }
1185 (*itDci).second.at(newDci.m_harqProcess) = newDci;
1186 // refresh timer
1187 std::map<uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer =
1188 m_dlHarqProcessesTimer.find(newEl.m_rnti);
1189 if (itHarqTimer == m_dlHarqProcessesTimer.end())
1190 {
1191 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1192 }
1193 (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1194 }
1195
1196 // ...more parameters -> ignored in this version
1197
1198 ret.m_buildDataList.push_back(newEl);
1199
1200 itMap++;
1201 } // end while allocation
1202 ret.m_nrOfPdcchOfdmSymbols = 1;
1203
1205}
1206
1207void
1210{
1211 NS_LOG_FUNCTION(this);
1212
1213 m_rachList = params.m_rachList;
1214}
1215
1216void
1219{
1220 NS_LOG_FUNCTION(this);
1221
1222 for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1223 {
1224 if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1225 {
1226 NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1227 << " reported");
1228 std::map<uint16_t, uint8_t>::iterator it;
1229 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1230 it = m_p10CqiRxed.find(rnti);
1231 if (it == m_p10CqiRxed.end())
1232 {
1233 // create the new entry
1234 m_p10CqiRxed.insert(std::pair<uint16_t, uint8_t>(
1235 rnti,
1236 params.m_cqiList.at(i).m_wbCqi.at(0))); // only codeword 0 at this stage (SISO)
1237 // generate correspondent timer
1238 m_p10CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1239 }
1240 else
1241 {
1242 // update the CQI value and refresh correspondent timer
1243 (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1244 // update correspondent timer
1245 std::map<uint16_t, uint32_t>::iterator itTimers;
1246 itTimers = m_p10CqiTimers.find(rnti);
1247 (*itTimers).second = m_cqiTimersThreshold;
1248 }
1249 }
1250 else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1251 {
1252 // subband CQI reporting high layer configured
1253 std::map<uint16_t, SbMeasResult_s>::iterator it;
1254 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1255 it = m_a30CqiRxed.find(rnti);
1256 if (it == m_a30CqiRxed.end())
1257 {
1258 // create the new entry
1259 m_a30CqiRxed.insert(
1260 std::pair<uint16_t, SbMeasResult_s>(rnti,
1261 params.m_cqiList.at(i).m_sbMeasResult));
1262 m_a30CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1263 }
1264 else
1265 {
1266 // update the CQI value and refresh correspondent timer
1267 (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1268 std::map<uint16_t, uint32_t>::iterator itTimers;
1269 itTimers = m_a30CqiTimers.find(rnti);
1270 (*itTimers).second = m_cqiTimersThreshold;
1271 }
1272 }
1273 else
1274 {
1275 NS_LOG_ERROR(this << " CQI type unknown");
1276 }
1277 }
1278}
1279
1280double
1281TtaFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1282{
1283 std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find(rnti);
1284 if (itCqi == m_ueCqi.end())
1285 {
1286 // no cqi info about this UE
1287 return (NO_SINR);
1288 }
1289 else
1290 {
1291 // take the average SINR value among the available
1292 double sinrSum = 0;
1293 unsigned int sinrNum = 0;
1294 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1295 {
1296 double sinr = (*itCqi).second.at(i);
1297 if (sinr != NO_SINR)
1298 {
1299 sinrSum += sinr;
1300 sinrNum++;
1301 }
1302 }
1303 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1304 // store the value
1305 (*itCqi).second.at(rb) = estimatedSinr;
1306 return (estimatedSinr);
1307 }
1308}
1309
1310void
1313{
1314 NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1315 << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1316
1318
1319 // Generate RBs map
1321 std::vector<bool> rbMap;
1322 std::set<uint16_t> rntiAllocated;
1323 std::vector<uint16_t> rbgAllocationMap;
1324 // update with RACH allocation map
1325 rbgAllocationMap = m_rachAllocationMap;
1326 // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1327 m_rachAllocationMap.clear();
1329
1330 rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1331 // remove RACH allocation
1332 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1333 {
1334 if (rbgAllocationMap.at(i) != 0)
1335 {
1336 rbMap.at(i) = true;
1337 NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1338 }
1339 }
1340
1341 if (m_harqOn)
1342 {
1343 // Process UL HARQ feedback
1344 for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1345 {
1346 if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1347 {
1348 // retx correspondent block: retrieve the UL-DCI
1349 uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1350 std::map<uint16_t, uint8_t>::iterator itProcId =
1351 m_ulHarqCurrentProcessId.find(rnti);
1352 if (itProcId == m_ulHarqCurrentProcessId.end())
1353 {
1354 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1355 }
1356 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1357 NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1358 << " i " << i << " size " << params.m_ulInfoList.size());
1359 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq =
1360 m_ulHarqProcessesDciBuffer.find(rnti);
1361 if (itHarq == m_ulHarqProcessesDciBuffer.end())
1362 {
1363 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1364 continue;
1365 }
1366 UlDciListElement_s dci = (*itHarq).second.at(harqId);
1367 std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1368 m_ulHarqProcessesStatus.find(rnti);
1369 if (itStat == m_ulHarqProcessesStatus.end())
1370 {
1371 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1372 }
1373 if ((*itStat).second.at(harqId) >= 3)
1374 {
1375 NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1376 continue;
1377 }
1378 bool free = true;
1379 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1380 {
1381 if (rbMap.at(j))
1382 {
1383 free = false;
1384 NS_LOG_INFO(this << " BUSY " << j);
1385 }
1386 }
1387 if (free)
1388 {
1389 // retx on the same RBs
1390 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1391 {
1392 rbMap.at(j) = true;
1393 rbgAllocationMap.at(j) = dci.m_rnti;
1394 NS_LOG_INFO("\tRB " << j);
1395 }
1396 NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1397 << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1398 << (*itStat).second.at(harqId) + 1);
1399 }
1400 else
1401 {
1402 NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1403 continue;
1404 }
1405 dci.m_ndi = 0;
1406 // Update HARQ buffers with new HarqId
1407 (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1408 (*itStat).second.at(harqId) = 0;
1409 (*itHarq).second.at((*itProcId).second) = dci;
1410 ret.m_dciList.push_back(dci);
1411 rntiAllocated.insert(dci.m_rnti);
1412 }
1413 else
1414 {
1415 NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1416 << params.m_ulInfoList.at(i).m_rnti);
1417 }
1418 }
1419 }
1420
1421 std::map<uint16_t, uint32_t>::iterator it;
1422 int nflows = 0;
1423
1424 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1425 {
1426 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1427 // select UEs with queues not empty and not yet allocated for HARQ
1428 if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1429 {
1430 nflows++;
1431 }
1432 }
1433
1434 if (nflows == 0)
1435 {
1436 if (!ret.m_dciList.empty())
1437 {
1438 m_allocationMaps.insert(
1439 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1441 }
1442
1443 return; // no flows to be scheduled
1444 }
1445
1446 // Divide the remaining resources equally among the active users starting from the subsequent
1447 // one served last scheduling trigger
1448 uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size());
1449 if (rbPerFlow < 3)
1450 {
1451 rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1452 // >= 7 bytes
1453 }
1454 int rbAllocated = 0;
1455
1456 if (m_nextRntiUl != 0)
1457 {
1458 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1459 {
1460 if ((*it).first == m_nextRntiUl)
1461 {
1462 break;
1463 }
1464 }
1465 if (it == m_ceBsrRxed.end())
1466 {
1467 NS_LOG_ERROR(this << " no user found");
1468 }
1469 }
1470 else
1471 {
1472 it = m_ceBsrRxed.begin();
1473 m_nextRntiUl = (*it).first;
1474 }
1475 do
1476 {
1477 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1478 if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1479 {
1480 // UE already allocated for UL-HARQ -> skip it
1481 NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1482 << (*it).first);
1483 it++;
1484 if (it == m_ceBsrRxed.end())
1485 {
1486 // restart from the first
1487 it = m_ceBsrRxed.begin();
1488 }
1489 continue;
1490 }
1491 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1492 {
1493 // limit to physical resources last resource assignment
1494 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1495 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1496 if (rbPerFlow < 3)
1497 {
1498 // terminate allocation
1499 rbPerFlow = 0;
1500 }
1501 }
1502
1503 UlDciListElement_s uldci;
1504 uldci.m_rnti = (*it).first;
1505 uldci.m_rbLen = rbPerFlow;
1506 bool allocated = false;
1507 NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1508 << " flows " << nflows);
1509 while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1510 (rbPerFlow != 0))
1511 {
1512 // check availability
1513 bool free = true;
1514 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1515 {
1516 if (rbMap.at(j))
1517 {
1518 free = false;
1519 break;
1520 }
1521 }
1522 if (free)
1523 {
1524 uldci.m_rbStart = rbAllocated;
1525
1526 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1527 {
1528 rbMap.at(j) = true;
1529 // store info on allocation for managing ul-cqi interpretation
1530 rbgAllocationMap.at(j) = (*it).first;
1531 }
1532 rbAllocated += rbPerFlow;
1533 allocated = true;
1534 break;
1535 }
1536 rbAllocated++;
1537 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1538 {
1539 // limit to physical resources last resource assignment
1540 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1541 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1542 if (rbPerFlow < 3)
1543 {
1544 // terminate allocation
1545 rbPerFlow = 0;
1546 }
1547 }
1548 }
1549 if (!allocated)
1550 {
1551 // unable to allocate new resource: finish scheduling
1552 m_nextRntiUl = (*it).first;
1553 if (!ret.m_dciList.empty())
1554 {
1556 }
1557 m_allocationMaps.insert(
1558 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1559 return;
1560 }
1561
1562 std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find((*it).first);
1563 int cqi = 0;
1564 if (itCqi == m_ueCqi.end())
1565 {
1566 // no cqi info about this UE
1567 uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1568 }
1569 else
1570 {
1571 // take the lowest CQI value (worst RB)
1572 NS_ABORT_MSG_IF((*itCqi).second.empty(),
1573 "CQI of RNTI = " << (*it).first << " has expired");
1574 double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1575 if (minSinr == NO_SINR)
1576 {
1577 minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1578 }
1579 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1580 {
1581 double sinr = (*itCqi).second.at(i);
1582 if (sinr == NO_SINR)
1583 {
1584 sinr = EstimateUlSinr((*it).first, i);
1585 }
1586 if (sinr < minSinr)
1587 {
1588 minSinr = sinr;
1589 }
1590 }
1591
1592 // translate SINR -> cqi: WILD ACK: same as DL
1593 double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1594 cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1595 if (cqi == 0)
1596 {
1597 it++;
1598 if (it == m_ceBsrRxed.end())
1599 {
1600 // restart from the first
1601 it = m_ceBsrRxed.begin();
1602 }
1603 NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1604 // remove UE from allocation map
1605 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1606 {
1607 rbgAllocationMap.at(i) = 0;
1608 }
1609 continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1610 }
1611 uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1612 }
1613
1614 uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1616 uldci.m_ndi = 1;
1617 uldci.m_cceIndex = 0;
1618 uldci.m_aggrLevel = 1;
1619 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1620 uldci.m_hopping = false;
1621 uldci.m_n2Dmrs = 0;
1622 uldci.m_tpc = 0; // no power control
1623 uldci.m_cqiRequest = false; // only period CQI at this stage
1624 uldci.m_ulIndex = 0; // TDD parameter
1625 uldci.m_dai = 1; // TDD parameter
1626 uldci.m_freqHopping = 0;
1627 uldci.m_pdcchPowerOffset = 0; // not used
1628 ret.m_dciList.push_back(uldci);
1629 // store DCI for HARQ_PERIOD
1630 uint8_t harqId = 0;
1631 if (m_harqOn)
1632 {
1633 std::map<uint16_t, uint8_t>::iterator itProcId;
1634 itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1635 if (itProcId == m_ulHarqCurrentProcessId.end())
1636 {
1637 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1638 }
1639 harqId = (*itProcId).second;
1640 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci =
1642 if (itDci == m_ulHarqProcessesDciBuffer.end())
1643 {
1644 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1645 << uldci.m_rnti);
1646 }
1647 (*itDci).second.at(harqId) = uldci;
1648 // Update HARQ process status (RV 0)
1649 std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1650 m_ulHarqProcessesStatus.find(uldci.m_rnti);
1651 if (itStat == m_ulHarqProcessesStatus.end())
1652 {
1653 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1654 << uldci.m_rnti);
1655 }
1656 (*itStat).second.at(harqId) = 0;
1657 }
1658
1659 NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1660 << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1661 << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1662 << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1663 << (uint16_t)harqId);
1664
1665 it++;
1666 if (it == m_ceBsrRxed.end())
1667 {
1668 // restart from the first
1669 it = m_ceBsrRxed.begin();
1670 }
1671 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1672 {
1673 // Stop allocation: no more PRBs
1674 m_nextRntiUl = (*it).first;
1675 break;
1676 }
1677 } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1678
1679 m_allocationMaps.insert(
1680 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1682}
1683
1684void
1687{
1688 NS_LOG_FUNCTION(this);
1689}
1690
1691void
1694{
1695 NS_LOG_FUNCTION(this);
1696}
1697
1698void
1701{
1702 NS_LOG_FUNCTION(this);
1703
1704 std::map<uint16_t, uint32_t>::iterator it;
1705
1706 for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1707 {
1708 if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1709 {
1710 // buffer status report
1711 // note that this scheduler does not differentiate the
1712 // allocation according to which LCGs have more/less bytes
1713 // to send.
1714 // Hence the BSR of different LCGs are just summed up to get
1715 // a total queue size that is used for allocation purposes.
1716
1717 uint32_t buffer = 0;
1718 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1719 {
1720 uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1721 buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1722 }
1723
1724 uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1725 NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1726 it = m_ceBsrRxed.find(rnti);
1727 if (it == m_ceBsrRxed.end())
1728 {
1729 // create the new entry
1730 m_ceBsrRxed.insert(std::pair<uint16_t, uint32_t>(rnti, buffer));
1731 }
1732 else
1733 {
1734 // update the buffer size value
1735 (*it).second = buffer;
1736 }
1737 }
1738 }
1739}
1740
1741void
1744{
1745 NS_LOG_FUNCTION(this);
1746 // retrieve the allocation for this subframe
1747 switch (m_ulCqiFilter)
1748 {
1750 // filter all the CQIs that are not SRS based
1751 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1752 {
1753 return;
1754 }
1755 }
1756 break;
1758 // filter all the CQIs that are not SRS based
1759 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1760 {
1761 return;
1762 }
1763 }
1764 break;
1765 default:
1766 NS_FATAL_ERROR("Unknown UL CQI type");
1767 }
1768
1769 switch (params.m_ulCqi.m_type)
1770 {
1771 case UlCqi_s::PUSCH: {
1772 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
1773 std::map<uint16_t, std::vector<double>>::iterator itCqi;
1774 NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1775 << " subframe no. " << (0xF & params.m_sfnSf));
1776 itMap = m_allocationMaps.find(params.m_sfnSf);
1777 if (itMap == m_allocationMaps.end())
1778 {
1779 return;
1780 }
1781 for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1782 {
1783 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1784 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1785 itCqi = m_ueCqi.find((*itMap).second.at(i));
1786 if (itCqi == m_ueCqi.end())
1787 {
1788 // create a new entry
1789 std::vector<double> newCqi;
1790 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1791 {
1792 if (i == j)
1793 {
1794 newCqi.push_back(sinr);
1795 }
1796 else
1797 {
1798 // initialize with NO_SINR value.
1799 newCqi.push_back(NO_SINR);
1800 }
1801 }
1802 m_ueCqi.insert(
1803 std::pair<uint16_t, std::vector<double>>((*itMap).second.at(i), newCqi));
1804 // generate correspondent timer
1805 m_ueCqiTimers.insert(
1806 std::pair<uint16_t, uint32_t>((*itMap).second.at(i), m_cqiTimersThreshold));
1807 }
1808 else
1809 {
1810 // update the value
1811 (*itCqi).second.at(i) = sinr;
1812 // NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR
1813 // " << sinr);
1814 // update correspondent timer
1815 std::map<uint16_t, uint32_t>::iterator itTimers;
1816 itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1817 (*itTimers).second = m_cqiTimersThreshold;
1818 }
1819 }
1820 // remove obsolete info on allocation
1821 m_allocationMaps.erase(itMap);
1822 }
1823 break;
1824 case UlCqi_s::SRS: {
1825 // get the RNTI from vendor specific parameters
1826 uint16_t rnti = 0;
1827 NS_ASSERT(!params.m_vendorSpecificList.empty());
1828 for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1829 {
1830 if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1831 {
1832 Ptr<SrsCqiRntiVsp> vsp =
1833 DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1834 rnti = vsp->GetRnti();
1835 }
1836 }
1837 std::map<uint16_t, std::vector<double>>::iterator itCqi;
1838 itCqi = m_ueCqi.find(rnti);
1839 if (itCqi == m_ueCqi.end())
1840 {
1841 // create a new entry
1842 std::vector<double> newCqi;
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 newCqi.push_back(sinr);
1847 NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1848 << sinr);
1849 }
1850 m_ueCqi.insert(std::pair<uint16_t, std::vector<double>>(rnti, newCqi));
1851 // generate correspondent timer
1852 m_ueCqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1853 }
1854 else
1855 {
1856 // update the values
1857 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1858 {
1859 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1860 (*itCqi).second.at(j) = sinr;
1861 NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1862 << sinr);
1863 }
1864 // update correspondent timer
1865 std::map<uint16_t, uint32_t>::iterator itTimers;
1866 itTimers = m_ueCqiTimers.find(rnti);
1867 (*itTimers).second = m_cqiTimersThreshold;
1868 }
1869 }
1870 break;
1871 case UlCqi_s::PUCCH_1:
1872 case UlCqi_s::PUCCH_2:
1873 case UlCqi_s::PRACH: {
1874 NS_FATAL_ERROR("TtaFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1875 }
1876 break;
1877 default:
1878 NS_FATAL_ERROR("Unknown type of UL-CQI");
1879 }
1880}
1881
1882void
1884{
1885 // refresh DL CQI P01 Map
1886 std::map<uint16_t, uint32_t>::iterator itP10 = m_p10CqiTimers.begin();
1887 while (itP10 != m_p10CqiTimers.end())
1888 {
1889 NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1890 << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1891 if ((*itP10).second == 0)
1892 {
1893 // delete correspondent entries
1894 std::map<uint16_t, uint8_t>::iterator itMap = m_p10CqiRxed.find((*itP10).first);
1895 NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1896 " Does not find CQI report for user " << (*itP10).first);
1897 NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1898 m_p10CqiRxed.erase(itMap);
1899 std::map<uint16_t, uint32_t>::iterator temp = itP10;
1900 itP10++;
1901 m_p10CqiTimers.erase(temp);
1902 }
1903 else
1904 {
1905 (*itP10).second--;
1906 itP10++;
1907 }
1908 }
1909
1910 // refresh DL CQI A30 Map
1911 std::map<uint16_t, uint32_t>::iterator itA30 = m_a30CqiTimers.begin();
1912 while (itA30 != m_a30CqiTimers.end())
1913 {
1914 NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1915 << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1916 if ((*itA30).second == 0)
1917 {
1918 // delete correspondent entries
1919 std::map<uint16_t, SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find((*itA30).first);
1920 NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1921 " Does not find CQI report for user " << (*itA30).first);
1922 NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1923 m_a30CqiRxed.erase(itMap);
1924 std::map<uint16_t, uint32_t>::iterator temp = itA30;
1925 itA30++;
1926 m_a30CqiTimers.erase(temp);
1927 }
1928 else
1929 {
1930 (*itA30).second--;
1931 itA30++;
1932 }
1933 }
1934}
1935
1936void
1938{
1939 // refresh UL CQI Map
1940 std::map<uint16_t, uint32_t>::iterator itUl = m_ueCqiTimers.begin();
1941 while (itUl != m_ueCqiTimers.end())
1942 {
1943 NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
1944 << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1945 if ((*itUl).second == 0)
1946 {
1947 // delete correspondent entries
1948 std::map<uint16_t, std::vector<double>>::iterator itMap = m_ueCqi.find((*itUl).first);
1949 NS_ASSERT_MSG(itMap != m_ueCqi.end(),
1950 " Does not find CQI report for user " << (*itUl).first);
1951 NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
1952 (*itMap).second.clear();
1953 m_ueCqi.erase(itMap);
1954 std::map<uint16_t, uint32_t>::iterator temp = itUl;
1955 itUl++;
1956 m_ueCqiTimers.erase(temp);
1957 }
1958 else
1959 {
1960 (*itUl).second--;
1961 itUl++;
1962 }
1963 }
1964}
1965
1966void
1967TtaFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
1968{
1969 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1970 LteFlowId_t flow(rnti, lcid);
1971 it = m_rlcBufferReq.find(flow);
1972 if (it != m_rlcBufferReq.end())
1973 {
1974 NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
1975 << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
1976 << (*it).second.m_rlcRetransmissionQueueSize << " status "
1977 << (*it).second.m_rlcStatusPduSize << " decrease " << size);
1978 // Update queues: RLC tx order Status, ReTx, Tx
1979 // Update status queue
1980 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1981 {
1982 (*it).second.m_rlcStatusPduSize = 0;
1983 }
1984 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
1985 (size >= (*it).second.m_rlcRetransmissionQueueSize))
1986 {
1987 (*it).second.m_rlcRetransmissionQueueSize = 0;
1988 }
1989 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1990 {
1991 uint32_t rlcOverhead;
1992 if (lcid == 1)
1993 {
1994 // for SRB1 (using RLC AM) it's better to
1995 // overestimate RLC overhead rather than
1996 // underestimate it and risk unneeded
1997 // segmentation which increases delay
1998 rlcOverhead = 4;
1999 }
2000 else
2001 {
2002 // minimum RLC overhead due to header
2003 rlcOverhead = 2;
2004 }
2005 // update transmission queue
2006 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2007 {
2008 (*it).second.m_rlcTransmissionQueueSize = 0;
2009 }
2010 else
2011 {
2012 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2013 }
2014 }
2015 }
2016 else
2017 {
2018 NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
2019 }
2020}
2021
2022void
2023TtaFfMacScheduler::UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
2024{
2025 size = size - 2; // remove the minimum RLC overhead
2026 std::map<uint16_t, uint32_t>::iterator it = m_ceBsrRxed.find(rnti);
2027 if (it != m_ceBsrRxed.end())
2028 {
2029 NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2030 if ((*it).second >= size)
2031 {
2032 (*it).second -= size;
2033 }
2034 else
2035 {
2036 (*it).second = 0;
2037 }
2038 }
2039 else
2040 {
2041 NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
2042 }
2043}
2044
2045void
2047{
2048 NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2050 params.m_rnti = rnti;
2051 params.m_transmissionMode = txMode;
2053}
2054
2055} // 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
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
Implements the SCHED SAP and CSCHED SAP for a Throughput to Average scheduler.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
FfMacSchedSapUser * m_schedSapUser
Sched SAP user.
void DoSchedDlCqiInfoReq(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request function.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void DoSchedUlCqiInfoReq(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request function.
void SetLteFfrSapProvider(LteFfrSapProvider *s) override
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
std::set< uint16_t > m_flowStatsDl
Set of UE statistics (per RNTI basis) in downlink.
void DoSchedDlRachInfoReq(const FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request function.
void DoDispose() override
Destructor implementation.
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
void DoSchedDlPagingBufferReq(const FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request function.
int GetRbgSize(int dlbandwidth)
Get RBG size function.
void SetFfMacCschedSapUser(FfMacCschedSapUser *s) override
set the user part of the FfMacCschedSap that this Scheduler will interact with.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
void RefreshDlCqiMaps()
Refresh DL CQI maps.
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 SINR function.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
friend class MemberSchedSapProvider< TtaFfMacScheduler >
allow MemberSchedSapProvider<TtaFfMacScheduler> class friend access
void RefreshUlCqiMaps()
Refresh UL CQI maps.
static TypeId GetTypeId()
Get the type ID.
~TtaFfMacScheduler() override
Destructor.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
void DoCschedLcReleaseReq(const FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request function.
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
Map of previous allocated UE per RBG (used to retrieve info from UL-CQI)
void SetFfMacSchedSapUser(FfMacSchedSapUser *s) override
set the user part of the FfMacSchedSap that this Scheduler will interact with.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
void DoSchedUlMacCtrlInfoReq(const FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request function.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
void DoSchedUlTriggerReq(const FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request function.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
LteFfrSapUser * GetLteFfrSapUser() override
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
void DoSchedDlTriggerReq(const FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request function.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
void DoSchedUlSrInfoReq(const FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request function.
void DoCschedLcConfigReq(const FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request function.
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update.
void DoSchedDlMacBufferReq(const FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request function.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update DL RLC buffer info function.
void DoSchedUlNoiseInterferenceReq(const FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request function.
void DoCschedCellConfigReq(const FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request function.
bool HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
unsigned int LcActivePerFlow(uint16_t rnti)
LC active per flow function.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
void DoSchedDlRlcBufferReq(const FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request function.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
void DoCschedUeReleaseReq(const FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request function.
friend class MemberCschedSapProvider< TtaFfMacScheduler >
allow MemberCschedSapProvider<TtaFfMacScheduler> class friend access
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
std::set< uint16_t > m_flowStatsUl
Set of UE statistics (per RNTI basis)
std::vector< RachListElement_s > m_rachList
RACH list.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
void DoCschedUeConfigReq(const FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request function.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
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.
constexpr uint32_t HARQ_PROC_NUM
Number of HARQ processes.
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector.
static const int TtaType0AllocationRbg[4]
TTA type 0 allocation RBG.
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.