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