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