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 std::map<uint16_t, uint8_t>::iterator 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 std::map<uint16_t, tdbetsFlowPerf_t>::iterator it;
209 for (std::size_t i = 0; i < params.m_logicalChannelConfigList.size(); i++)
210 {
211 it = m_flowStatsDl.find(params.m_rnti);
212
213 if (it == m_flowStatsDl.end())
214 {
215 tdbetsFlowPerf_t flowStatsDl;
216 flowStatsDl.flowStart = Simulator::Now();
217 flowStatsDl.totalBytesTransmitted = 0;
218 flowStatsDl.lastTtiBytesTrasmitted = 0;
219 flowStatsDl.lastAveragedThroughput = 1;
220 m_flowStatsDl.insert(std::pair<uint16_t, tdbetsFlowPerf_t>(params.m_rnti, flowStatsDl));
221 tdbetsFlowPerf_t flowStatsUl;
222 flowStatsUl.flowStart = Simulator::Now();
223 flowStatsUl.totalBytesTransmitted = 0;
224 flowStatsUl.lastTtiBytesTrasmitted = 0;
225 flowStatsUl.lastAveragedThroughput = 1;
226 m_flowStatsUl.insert(std::pair<uint16_t, tdbetsFlowPerf_t>(params.m_rnti, flowStatsUl));
227 }
228 }
229}
230
231void
234{
235 NS_LOG_FUNCTION(this);
236 for (std::size_t i = 0; i < params.m_logicalChannelIdentity.size(); i++)
237 {
238 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
239 m_rlcBufferReq.begin();
240 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
241 while (it != m_rlcBufferReq.end())
242 {
243 if (((*it).first.m_rnti == params.m_rnti) &&
244 ((*it).first.m_lcId == params.m_logicalChannelIdentity.at(i)))
245 {
246 temp = it;
247 it++;
248 m_rlcBufferReq.erase(temp);
249 }
250 else
251 {
252 it++;
253 }
254 }
255 }
256}
257
258void
261{
262 NS_LOG_FUNCTION(this);
263
264 m_uesTxMode.erase(params.m_rnti);
265 m_dlHarqCurrentProcessId.erase(params.m_rnti);
266 m_dlHarqProcessesStatus.erase(params.m_rnti);
267 m_dlHarqProcessesTimer.erase(params.m_rnti);
268 m_dlHarqProcessesDciBuffer.erase(params.m_rnti);
269 m_dlHarqProcessesRlcPduListBuffer.erase(params.m_rnti);
270 m_ulHarqCurrentProcessId.erase(params.m_rnti);
271 m_ulHarqProcessesStatus.erase(params.m_rnti);
272 m_ulHarqProcessesDciBuffer.erase(params.m_rnti);
273 m_flowStatsDl.erase(params.m_rnti);
274 m_flowStatsUl.erase(params.m_rnti);
275 m_ceBsrRxed.erase(params.m_rnti);
276 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
277 m_rlcBufferReq.begin();
278 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
279 while (it != m_rlcBufferReq.end())
280 {
281 if ((*it).first.m_rnti == params.m_rnti)
282 {
283 temp = it;
284 it++;
285 m_rlcBufferReq.erase(temp);
286 }
287 else
288 {
289 it++;
290 }
291 }
292 if (m_nextRntiUl == params.m_rnti)
293 {
294 m_nextRntiUl = 0;
295 }
296}
297
298void
301{
302 NS_LOG_FUNCTION(this << params.m_rnti << (uint32_t)params.m_logicalChannelIdentity);
303 // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
304
305 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
306
307 LteFlowId_t flow(params.m_rnti, params.m_logicalChannelIdentity);
308
309 it = m_rlcBufferReq.find(flow);
310
311 if (it == m_rlcBufferReq.end())
312 {
313 m_rlcBufferReq.insert(
314 std::pair<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>(flow,
315 params));
316 }
317 else
318 {
319 (*it).second = params;
320 }
321}
322
323void
326{
327 NS_LOG_FUNCTION(this);
328 NS_FATAL_ERROR("method not implemented");
329}
330
331void
334{
335 NS_LOG_FUNCTION(this);
336 NS_FATAL_ERROR("method not implemented");
337}
338
339int
341{
342 for (int i = 0; i < 4; i++)
343 {
344 if (dlbandwidth < TdBetType0AllocationRbg[i])
345 {
346 return (i + 1);
347 }
348 }
349
350 return (-1);
351}
352
353unsigned int
355{
356 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
357 unsigned int lcActive = 0;
358 for (it = m_rlcBufferReq.begin(); it != m_rlcBufferReq.end(); it++)
359 {
360 if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0) ||
361 ((*it).second.m_rlcRetransmissionQueueSize > 0) ||
362 ((*it).second.m_rlcStatusPduSize > 0)))
363 {
364 lcActive++;
365 }
366 if ((*it).first.m_rnti > rnti)
367 {
368 break;
369 }
370 }
371 return (lcActive);
372}
373
374bool
376{
377 NS_LOG_FUNCTION(this << rnti);
378
379 std::map<uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find(rnti);
380 if (it == m_dlHarqCurrentProcessId.end())
381 {
382 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
383 }
384 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
385 m_dlHarqProcessesStatus.find(rnti);
386 if (itStat == m_dlHarqProcessesStatus.end())
387 {
388 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
389 }
390 uint8_t i = (*it).second;
391 do
392 {
393 i = (i + 1) % HARQ_PROC_NUM;
394 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
395
396 return (*itStat).second.at(i) == 0;
397}
398
399uint8_t
401{
402 NS_LOG_FUNCTION(this << rnti);
403
404 if (!m_harqOn)
405 {
406 return (0);
407 }
408
409 std::map<uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find(rnti);
410 if (it == m_dlHarqCurrentProcessId.end())
411 {
412 NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
413 }
414 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
415 m_dlHarqProcessesStatus.find(rnti);
416 if (itStat == m_dlHarqProcessesStatus.end())
417 {
418 NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
419 }
420 uint8_t i = (*it).second;
421 do
422 {
423 i = (i + 1) % HARQ_PROC_NUM;
424 } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
425 if ((*itStat).second.at(i) == 0)
426 {
427 (*it).second = i;
428 (*itStat).second.at(i) = 1;
429 }
430 else
431 {
432 NS_FATAL_ERROR("No HARQ process available for RNTI "
433 << rnti << " check before update with HarqProcessAvailability");
434 }
435
436 return ((*it).second);
437}
438
439void
441{
442 NS_LOG_FUNCTION(this);
443
444 std::map<uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
445 for (itTimers = m_dlHarqProcessesTimer.begin(); itTimers != m_dlHarqProcessesTimer.end();
446 itTimers++)
447 {
448 for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
449 {
450 if ((*itTimers).second.at(i) == HARQ_DL_TIMEOUT)
451 {
452 // reset HARQ process
453
454 NS_LOG_DEBUG(this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
455 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
456 m_dlHarqProcessesStatus.find((*itTimers).first);
457 if (itStat == m_dlHarqProcessesStatus.end())
458 {
459 NS_FATAL_ERROR("No Process Id Status found for this RNTI "
460 << (*itTimers).first);
461 }
462 (*itStat).second.at(i) = 0;
463 (*itTimers).second.at(i) = 0;
464 }
465 else
466 {
467 (*itTimers).second.at(i)++;
468 }
469 }
470 }
471}
472
473void
476{
477 NS_LOG_FUNCTION(this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
478 << (0xF & params.m_sfnSf));
479 // API generated by RLC for triggering the scheduling of a DL subframe
480
481 // evaluate the relative channel quality indicator for each UE per each RBG
482 // (since we are using allocation type 0 the small unit of allocation is RBG)
483 // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
484
486
488 int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
489 std::map<uint16_t, std::vector<uint16_t>> allocationMap; // RBs map per RNTI
490 std::vector<bool> rbgMap; // global RBGs map
491 uint16_t rbgAllocatedNum = 0;
492 std::set<uint16_t> rntiAllocated;
493 rbgMap.resize(m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
495
496 // update UL HARQ proc id
497 std::map<uint16_t, uint8_t>::iterator itProcId;
498 for (itProcId = m_ulHarqCurrentProcessId.begin(); itProcId != m_ulHarqCurrentProcessId.end();
499 itProcId++)
500 {
501 (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
502 }
503
504 // RACH Allocation
506 uint16_t rbStart = 0;
507 std::vector<RachListElement_s>::iterator itRach;
508 for (itRach = m_rachList.begin(); itRach != m_rachList.end(); itRach++)
509 {
511 (*itRach).m_estimatedSize,
512 " Default UL Grant MCS does not allow to send RACH messages");
514 newRar.m_rnti = (*itRach).m_rnti;
515 // DL-RACH Allocation
516 // Ideal: no needs of configuring m_dci
517 // UL-RACH Allocation
518 newRar.m_grant.m_rnti = newRar.m_rnti;
519 newRar.m_grant.m_mcs = m_ulGrantMcs;
520 uint16_t rbLen = 1;
521 uint16_t tbSizeBits = 0;
522 // find lowest TB size that fits UL grant estimated size
523 while ((tbSizeBits < (*itRach).m_estimatedSize) &&
524 (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
525 {
526 rbLen++;
527 tbSizeBits = m_amc->GetUlTbSizeFromMcs(m_ulGrantMcs, rbLen);
528 }
529 if (tbSizeBits < (*itRach).m_estimatedSize)
530 {
531 // no more allocation space: finish allocation
532 break;
533 }
534 newRar.m_grant.m_rbStart = rbStart;
535 newRar.m_grant.m_rbLen = rbLen;
536 newRar.m_grant.m_tbSize = tbSizeBits / 8;
537 newRar.m_grant.m_hopping = false;
538 newRar.m_grant.m_tpc = 0;
539 newRar.m_grant.m_cqiRequest = false;
540 newRar.m_grant.m_ulDelay = false;
541 NS_LOG_INFO(this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart "
542 << rbStart << " rbLen " << rbLen << " MCS " << m_ulGrantMcs << " tbSize "
543 << newRar.m_grant.m_tbSize);
544 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
545 {
546 m_rachAllocationMap.at(i) = (*itRach).m_rnti;
547 }
548
549 if (m_harqOn)
550 {
551 // generate UL-DCI for HARQ retransmissions
552 UlDciListElement_s uldci;
553 uldci.m_rnti = newRar.m_rnti;
554 uldci.m_rbLen = rbLen;
555 uldci.m_rbStart = rbStart;
556 uldci.m_mcs = m_ulGrantMcs;
557 uldci.m_tbSize = tbSizeBits / 8;
558 uldci.m_ndi = 1;
559 uldci.m_cceIndex = 0;
560 uldci.m_aggrLevel = 1;
561 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
562 uldci.m_hopping = false;
563 uldci.m_n2Dmrs = 0;
564 uldci.m_tpc = 0; // no power control
565 uldci.m_cqiRequest = false; // only period CQI at this stage
566 uldci.m_ulIndex = 0; // TDD parameter
567 uldci.m_dai = 1; // TDD parameter
568 uldci.m_freqHopping = 0;
569 uldci.m_pdcchPowerOffset = 0; // not used
570
571 uint8_t harqId = 0;
572 std::map<uint16_t, uint8_t>::iterator itProcId;
573 itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
574 if (itProcId == m_ulHarqCurrentProcessId.end())
575 {
576 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
577 }
578 harqId = (*itProcId).second;
579 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci =
581 if (itDci == m_ulHarqProcessesDciBuffer.end())
582 {
583 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
584 << uldci.m_rnti);
585 }
586 (*itDci).second.at(harqId) = uldci;
587 }
588
589 rbStart = rbStart + rbLen;
590 ret.m_buildRarList.push_back(newRar);
591 }
592 m_rachList.clear();
593
594 // Process DL HARQ feedback
596 // retrieve past HARQ retx buffered
597 if (!m_dlInfoListBuffered.empty())
598 {
599 if (!params.m_dlInfoList.empty())
600 {
601 NS_LOG_INFO(this << " Received DL-HARQ feedback");
603 params.m_dlInfoList.begin(),
604 params.m_dlInfoList.end());
605 }
606 }
607 else
608 {
609 if (!params.m_dlInfoList.empty())
610 {
611 m_dlInfoListBuffered = params.m_dlInfoList;
612 }
613 }
614 if (!m_harqOn)
615 {
616 // Ignore HARQ feedback
617 m_dlInfoListBuffered.clear();
618 }
619 std::vector<DlInfoListElement_s> dlInfoListUntxed;
620 for (std::size_t i = 0; i < m_dlInfoListBuffered.size(); i++)
621 {
622 std::set<uint16_t>::iterator itRnti = rntiAllocated.find(m_dlInfoListBuffered.at(i).m_rnti);
623 if (itRnti != rntiAllocated.end())
624 {
625 // RNTI already allocated for retx
626 continue;
627 }
628 auto nLayers = m_dlInfoListBuffered.at(i).m_harqStatus.size();
629 std::vector<bool> retx;
630 NS_LOG_INFO(this << " Processing DLHARQ feedback");
631 if (nLayers == 1)
632 {
633 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
635 retx.push_back(false);
636 }
637 else
638 {
639 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
641 retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(1) ==
643 }
644 if (retx.at(0) || retx.at(1))
645 {
646 // retrieve HARQ process information
647 uint16_t rnti = m_dlInfoListBuffered.at(i).m_rnti;
648 uint8_t harqId = m_dlInfoListBuffered.at(i).m_harqProcessId;
649 NS_LOG_INFO(this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
650 std::map<uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq =
652 if (itHarq == m_dlHarqProcessesDciBuffer.end())
653 {
654 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << rnti);
655 }
656
657 DlDciListElement_s dci = (*itHarq).second.at(harqId);
658 int rv = 0;
659 if (dci.m_rv.size() == 1)
660 {
661 rv = dci.m_rv.at(0);
662 }
663 else
664 {
665 rv = (dci.m_rv.at(0) > dci.m_rv.at(1) ? dci.m_rv.at(0) : dci.m_rv.at(1));
666 }
667
668 if (rv == 3)
669 {
670 // maximum number of retx reached -> drop process
671 NS_LOG_INFO("Maximum number of retransmissions reached -> drop process");
672 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator it =
673 m_dlHarqProcessesStatus.find(rnti);
674 if (it == m_dlHarqProcessesStatus.end())
675 {
676 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
677 << m_dlInfoListBuffered.at(i).m_rnti);
678 }
679 (*it).second.at(harqId) = 0;
680 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
682 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
683 {
684 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
685 << m_dlInfoListBuffered.at(i).m_rnti);
686 }
687 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
688 {
689 (*itRlcPdu).second.at(k).at(harqId).clear();
690 }
691 continue;
692 }
693 // check the feasibility of retransmitting on the same RBGs
694 // translate the DCI to Spectrum framework
695 std::vector<int> dciRbg;
696 uint32_t mask = 0x1;
697 NS_LOG_INFO("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
698 for (int j = 0; j < 32; j++)
699 {
700 if (((dci.m_rbBitmap & mask) >> j) == 1)
701 {
702 dciRbg.push_back(j);
703 NS_LOG_INFO("\t" << j);
704 }
705 mask = (mask << 1);
706 }
707 bool free = true;
708 for (std::size_t j = 0; j < dciRbg.size(); j++)
709 {
710 if (rbgMap.at(dciRbg.at(j)))
711 {
712 free = false;
713 break;
714 }
715 }
716 if (free)
717 {
718 // use the same RBGs for the retx
719 // reserve RBGs
720 for (std::size_t j = 0; j < dciRbg.size(); j++)
721 {
722 rbgMap.at(dciRbg.at(j)) = true;
723 NS_LOG_INFO("RBG " << dciRbg.at(j) << " assigned");
724 rbgAllocatedNum++;
725 }
726
727 NS_LOG_INFO(this << " Send retx in the same RBGs");
728 }
729 else
730 {
731 // find RBGs for sending HARQ retx
732 uint8_t j = 0;
733 uint8_t rbgId = (dciRbg.at(dciRbg.size() - 1) + 1) % rbgNum;
734 uint8_t startRbg = dciRbg.at(dciRbg.size() - 1);
735 std::vector<bool> rbgMapCopy = rbgMap;
736 while ((j < dciRbg.size()) && (startRbg != rbgId))
737 {
738 if (!rbgMapCopy.at(rbgId))
739 {
740 rbgMapCopy.at(rbgId) = true;
741 dciRbg.at(j) = rbgId;
742 j++;
743 }
744 rbgId = (rbgId + 1) % rbgNum;
745 }
746 if (j == dciRbg.size())
747 {
748 // find new RBGs -> update DCI map
749 uint32_t rbgMask = 0;
750 for (std::size_t k = 0; k < dciRbg.size(); k++)
751 {
752 rbgMask = rbgMask + (0x1 << dciRbg.at(k));
753 rbgAllocatedNum++;
754 }
755 dci.m_rbBitmap = rbgMask;
756 rbgMap = rbgMapCopy;
757 NS_LOG_INFO(this << " Move retx in RBGs " << dciRbg.size());
758 }
759 else
760 {
761 // HARQ retx cannot be performed on this TTI -> store it
762 dlInfoListUntxed.push_back(m_dlInfoListBuffered.at(i));
763 NS_LOG_INFO(this << " No resource for this retx -> buffer it");
764 }
765 }
766 // retrieve RLC PDU list for retx TBsize and update DCI
768 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
770 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
771 {
772 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
773 }
774 for (std::size_t j = 0; j < nLayers; j++)
775 {
776 if (retx.at(j))
777 {
778 if (j >= dci.m_ndi.size())
779 {
780 // for avoiding errors in MIMO transient phases
781 dci.m_ndi.push_back(0);
782 dci.m_rv.push_back(0);
783 dci.m_mcs.push_back(0);
784 dci.m_tbsSize.push_back(0);
785 NS_LOG_INFO(this << " layer " << (uint16_t)j
786 << " no txed (MIMO transition)");
787 }
788 else
789 {
790 dci.m_ndi.at(j) = 0;
791 dci.m_rv.at(j)++;
792 (*itHarq).second.at(harqId).m_rv.at(j)++;
793 NS_LOG_INFO(this << " layer " << (uint16_t)j << " RV "
794 << (uint16_t)dci.m_rv.at(j));
795 }
796 }
797 else
798 {
799 // empty TB of layer j
800 dci.m_ndi.at(j) = 0;
801 dci.m_rv.at(j) = 0;
802 dci.m_mcs.at(j) = 0;
803 dci.m_tbsSize.at(j) = 0;
804 NS_LOG_INFO(this << " layer " << (uint16_t)j << " no retx");
805 }
806 }
807 for (std::size_t k = 0; k < (*itRlcPdu).second.at(0).at(dci.m_harqProcess).size(); k++)
808 {
809 std::vector<RlcPduListElement_s> rlcPduListPerLc;
810 for (std::size_t j = 0; j < nLayers; j++)
811 {
812 if (retx.at(j))
813 {
814 if (j < dci.m_ndi.size())
815 {
816 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size "
817 << dci.m_tbsSize.at(j));
818 rlcPduListPerLc.push_back(
819 (*itRlcPdu).second.at(j).at(dci.m_harqProcess).at(k));
820 }
821 }
822 else
823 { // if no retx needed on layer j, push an RlcPduListElement_s object with
824 // m_size=0 to keep the size of rlcPduListPerLc vector = 2 in case of MIMO
825 NS_LOG_INFO(" layer " << (uint16_t)j << " tb size " << dci.m_tbsSize.at(j));
826 RlcPduListElement_s emptyElement;
827 emptyElement.m_logicalChannelIdentity = (*itRlcPdu)
828 .second.at(j)
829 .at(dci.m_harqProcess)
830 .at(k)
831 .m_logicalChannelIdentity;
832 emptyElement.m_size = 0;
833 rlcPduListPerLc.push_back(emptyElement);
834 }
835 }
836
837 if (!rlcPduListPerLc.empty())
838 {
839 newEl.m_rlcPduList.push_back(rlcPduListPerLc);
840 }
841 }
842 newEl.m_rnti = rnti;
843 newEl.m_dci = dci;
844 (*itHarq).second.at(harqId).m_rv = dci.m_rv;
845 // refresh timer
846 std::map<uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer =
847 m_dlHarqProcessesTimer.find(rnti);
848 if (itHarqTimer == m_dlHarqProcessesTimer.end())
849 {
850 NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
851 }
852 (*itHarqTimer).second.at(harqId) = 0;
853 ret.m_buildDataList.push_back(newEl);
854 rntiAllocated.insert(rnti);
855 }
856 else
857 {
858 // update HARQ process status
859 NS_LOG_INFO(this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at(i).m_rnti);
860 std::map<uint16_t, DlHarqProcessesStatus_t>::iterator it =
862 if (it == m_dlHarqProcessesStatus.end())
863 {
864 NS_FATAL_ERROR("No info find in HARQ buffer for UE "
865 << m_dlInfoListBuffered.at(i).m_rnti);
866 }
867 (*it).second.at(m_dlInfoListBuffered.at(i).m_harqProcessId) = 0;
868 std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
870 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
871 {
872 NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
873 << m_dlInfoListBuffered.at(i).m_rnti);
874 }
875 for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
876 {
877 (*itRlcPdu).second.at(k).at(m_dlInfoListBuffered.at(i).m_harqProcessId).clear();
878 }
879 }
880 }
881 m_dlInfoListBuffered.clear();
882 m_dlInfoListBuffered = dlInfoListUntxed;
883
884 if (rbgAllocatedNum == rbgNum)
885 {
886 // all the RBGs are already allocated -> exit
887 if (!ret.m_buildDataList.empty() || !ret.m_buildRarList.empty())
888 {
890 }
891 return;
892 }
893
894 std::map<uint16_t, tdbetsFlowPerf_t>::iterator it;
895 std::map<uint16_t, tdbetsFlowPerf_t>::iterator itMax = m_flowStatsDl.end();
896 double metricMax = 0.0;
897 for (it = m_flowStatsDl.begin(); it != m_flowStatsDl.end(); it++)
898 {
899 // check first what are channel conditions for this UE, if CQI!=0
900 std::map<uint16_t, uint8_t>::iterator itCqi;
901 itCqi = m_p10CqiRxed.find((*it).first);
902 std::map<uint16_t, uint8_t>::iterator itTxMode;
903 itTxMode = m_uesTxMode.find((*it).first);
904 if (itTxMode == m_uesTxMode.end())
905 {
906 NS_FATAL_ERROR("No Transmission Mode info on user " << (*it).first);
907 }
908 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
909
910 uint8_t cqiSum = 0;
911 for (uint8_t j = 0; j < nLayer; j++)
912 {
913 if (itCqi == m_p10CqiRxed.end())
914 {
915 cqiSum += 1; // no info on this user -> lowest MCS
916 }
917 else
918 {
919 cqiSum = (*itCqi).second;
920 }
921 }
922 if (cqiSum == 0)
923 {
924 NS_LOG_INFO("Skip this flow, CQI==0, rnti:" << (*it).first);
925 continue;
926 }
927
928 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
929 if ((itRnti != rntiAllocated.end()) || (!HarqProcessAvailability((*it).first)))
930 {
931 // UE already allocated for HARQ or without HARQ process available -> drop it
932 if (itRnti != rntiAllocated.end())
933 {
934 NS_LOG_DEBUG(this << " RNTI discarded for HARQ tx" << (uint16_t)(*it).first);
935 }
936 if (!HarqProcessAvailability((*it).first))
937 {
938 NS_LOG_DEBUG(this << " RNTI discarded for HARQ id" << (uint16_t)(*it).first);
939 }
940 continue;
941 }
942
943 double metric = 1 / (*it).second.lastAveragedThroughput;
944
945 if (metric > metricMax)
946 {
947 metricMax = metric;
948 itMax = it;
949 }
950 } // end for m_flowStatsDl
951
952 if (itMax == m_flowStatsDl.end())
953 {
954 // no UE available for downlink
955 return;
956 }
957 else
958 {
959 // assign all RBGs to this UE
960 std::vector<uint16_t> tempMap;
961 tempMap.reserve(rbgNum);
962 for (int i = 0; i < rbgNum; i++)
963 {
964 tempMap.push_back(i);
965 }
966 allocationMap.insert(std::pair<uint16_t, std::vector<uint16_t>>((*itMax).first, tempMap));
967 }
968
969 // reset TTI stats of users
970 std::map<uint16_t, tdbetsFlowPerf_t>::iterator itStats;
971 for (itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
972 {
973 (*itStats).second.lastTtiBytesTrasmitted = 0;
974 }
975
976 // generate the transmission opportunities by grouping the RBGs of the same RNTI and
977 // creating the correspondent DCIs
978 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap = allocationMap.begin();
979 while (itMap != allocationMap.end())
980 {
981 // create new BuildDataListElement_s for this LC
983 newEl.m_rnti = (*itMap).first;
984 // create the DlDciListElement_s
985 DlDciListElement_s newDci;
986 newDci.m_rnti = (*itMap).first;
987 newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
988
989 uint16_t lcActives = LcActivePerFlow((*itMap).first);
990 NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
991 if (lcActives == 0)
992 {
993 // Set to max value, to avoid divide by 0 below
994 lcActives = (uint16_t)65535; // UINT16_MAX;
995 }
996 uint16_t RgbPerRnti = (*itMap).second.size();
997 std::map<uint16_t, uint8_t>::iterator itCqi;
998 itCqi = m_p10CqiRxed.find((*itMap).first);
999 std::map<uint16_t, uint8_t>::iterator itTxMode;
1000 itTxMode = m_uesTxMode.find((*itMap).first);
1001 if (itTxMode == m_uesTxMode.end())
1002 {
1003 NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1004 }
1005 auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1006
1007 uint32_t bytesTxed = 0;
1008 for (uint8_t j = 0; j < nLayer; j++)
1009 {
1010 if (itCqi == m_p10CqiRxed.end())
1011 {
1012 newDci.m_mcs.push_back(0); // no info on this user -> lowest MCS
1013 }
1014 else
1015 {
1016 newDci.m_mcs.push_back(m_amc->GetMcsFromCqi((*itCqi).second));
1017 }
1018
1019 int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RgbPerRnti * rbgSize) /
1020 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1021 newDci.m_tbsSize.push_back(tbSize);
1022 bytesTxed += 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 // update UE stats
1112 std::map<uint16_t, tdbetsFlowPerf_t>::iterator it;
1113 it = m_flowStatsDl.find((*itMap).first);
1114 if (it != m_flowStatsDl.end())
1115 {
1116 (*it).second.lastTtiBytesTrasmitted = bytesTxed;
1117 NS_LOG_INFO(this << " UE total bytes txed " << (*it).second.lastTtiBytesTrasmitted);
1118 }
1119 else
1120 {
1121 NS_FATAL_ERROR(this << " No Stats for this allocated UE");
1122 }
1123
1124 itMap++;
1125 } // end while allocation
1126 ret.m_nrOfPdcchOfdmSymbols = 1;
1127
1128 // update UEs stats
1129 NS_LOG_INFO(this << " Update UEs statistics");
1130 for (itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
1131 {
1132 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTrasmitted;
1133 // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
1134 // Evolution, Ed Wiley)
1135 (*itStats).second.lastAveragedThroughput =
1136 ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
1137 ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTrasmitted / 0.001));
1138 NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1139 NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1140 (*itStats).second.lastTtiBytesTrasmitted = 0;
1141 }
1142
1144}
1145
1146void
1149{
1150 NS_LOG_FUNCTION(this);
1151
1152 m_rachList = params.m_rachList;
1153}
1154
1155void
1158{
1159 NS_LOG_FUNCTION(this);
1160
1161 for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1162 {
1163 if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1164 {
1165 NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1166 << " reported");
1167 std::map<uint16_t, uint8_t>::iterator it;
1168 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1169 it = m_p10CqiRxed.find(rnti);
1170 if (it == m_p10CqiRxed.end())
1171 {
1172 // create the new entry
1173 m_p10CqiRxed.insert(std::pair<uint16_t, uint8_t>(
1174 rnti,
1175 params.m_cqiList.at(i).m_wbCqi.at(0))); // only codeword 0 at this stage (SISO)
1176 // generate correspondent timer
1177 m_p10CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1178 }
1179 else
1180 {
1181 // update the CQI value and refresh correspondent timer
1182 (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1183 // update correspondent timer
1184 std::map<uint16_t, uint32_t>::iterator itTimers;
1185 itTimers = m_p10CqiTimers.find(rnti);
1186 (*itTimers).second = m_cqiTimersThreshold;
1187 }
1188 }
1189 else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1190 {
1191 // subband CQI reporting high layer configured
1192 std::map<uint16_t, SbMeasResult_s>::iterator it;
1193 uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1194 it = m_a30CqiRxed.find(rnti);
1195 if (it == m_a30CqiRxed.end())
1196 {
1197 // create the new entry
1198 m_a30CqiRxed.insert(
1199 std::pair<uint16_t, SbMeasResult_s>(rnti,
1200 params.m_cqiList.at(i).m_sbMeasResult));
1201 m_a30CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1202 }
1203 else
1204 {
1205 // update the CQI value and refresh correspondent timer
1206 (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1207 std::map<uint16_t, uint32_t>::iterator itTimers;
1208 itTimers = m_a30CqiTimers.find(rnti);
1209 (*itTimers).second = m_cqiTimersThreshold;
1210 }
1211 }
1212 else
1213 {
1214 NS_LOG_ERROR(this << " CQI type unknown");
1215 }
1216 }
1217}
1218
1219double
1220TdBetFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1221{
1222 std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find(rnti);
1223 if (itCqi == m_ueCqi.end())
1224 {
1225 // no cqi info about this UE
1226 return (NO_SINR);
1227 }
1228 else
1229 {
1230 // take the average SINR value among the available
1231 double sinrSum = 0;
1232 unsigned int sinrNum = 0;
1233 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1234 {
1235 double sinr = (*itCqi).second.at(i);
1236 if (sinr != NO_SINR)
1237 {
1238 sinrSum += sinr;
1239 sinrNum++;
1240 }
1241 }
1242 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1243 // store the value
1244 (*itCqi).second.at(rb) = estimatedSinr;
1245 return (estimatedSinr);
1246 }
1247}
1248
1249void
1252{
1253 NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1254 << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1255
1257
1258 // Generate RBs map
1260 std::vector<bool> rbMap;
1261 std::set<uint16_t> rntiAllocated;
1262 std::vector<uint16_t> rbgAllocationMap;
1263 // update with RACH allocation map
1264 rbgAllocationMap = m_rachAllocationMap;
1265 // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1266 m_rachAllocationMap.clear();
1268
1269 rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1270 // remove RACH allocation
1271 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1272 {
1273 if (rbgAllocationMap.at(i) != 0)
1274 {
1275 rbMap.at(i) = true;
1276 NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1277 }
1278 }
1279
1280 if (m_harqOn)
1281 {
1282 // Process UL HARQ feedback
1283 for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1284 {
1285 if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1286 {
1287 // retx correspondent block: retrieve the UL-DCI
1288 uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1289 std::map<uint16_t, uint8_t>::iterator itProcId =
1290 m_ulHarqCurrentProcessId.find(rnti);
1291 if (itProcId == m_ulHarqCurrentProcessId.end())
1292 {
1293 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1294 }
1295 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1296 NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1297 << " i " << i << " size " << params.m_ulInfoList.size());
1298 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq =
1299 m_ulHarqProcessesDciBuffer.find(rnti);
1300 if (itHarq == m_ulHarqProcessesDciBuffer.end())
1301 {
1302 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1303 continue;
1304 }
1305 UlDciListElement_s dci = (*itHarq).second.at(harqId);
1306 std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1307 m_ulHarqProcessesStatus.find(rnti);
1308 if (itStat == m_ulHarqProcessesStatus.end())
1309 {
1310 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1311 }
1312 if ((*itStat).second.at(harqId) >= 3)
1313 {
1314 NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1315 continue;
1316 }
1317 bool free = true;
1318 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1319 {
1320 if (rbMap.at(j))
1321 {
1322 free = false;
1323 NS_LOG_INFO(this << " BUSY " << j);
1324 }
1325 }
1326 if (free)
1327 {
1328 // retx on the same RBs
1329 for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1330 {
1331 rbMap.at(j) = true;
1332 rbgAllocationMap.at(j) = dci.m_rnti;
1333 NS_LOG_INFO("\tRB " << j);
1334 }
1335 NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1336 << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1337 << (*itStat).second.at(harqId) + 1);
1338 }
1339 else
1340 {
1341 NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1342 continue;
1343 }
1344 dci.m_ndi = 0;
1345 // Update HARQ buffers with new HarqId
1346 (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1347 (*itStat).second.at(harqId) = 0;
1348 (*itHarq).second.at((*itProcId).second) = dci;
1349 ret.m_dciList.push_back(dci);
1350 rntiAllocated.insert(dci.m_rnti);
1351 }
1352 else
1353 {
1354 NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1355 << params.m_ulInfoList.at(i).m_rnti);
1356 }
1357 }
1358 }
1359
1360 std::map<uint16_t, uint32_t>::iterator it;
1361 int nflows = 0;
1362
1363 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1364 {
1365 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1366 // select UEs with queues not empty and not yet allocated for HARQ
1367 if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1368 {
1369 nflows++;
1370 }
1371 }
1372
1373 if (nflows == 0)
1374 {
1375 if (!ret.m_dciList.empty())
1376 {
1377 m_allocationMaps.insert(
1378 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1380 }
1381
1382 return; // no flows to be scheduled
1383 }
1384
1385 // Divide the remaining resources equally among the active users starting from the subsequent
1386 // one served last scheduling trigger
1387 uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size());
1388 if (rbPerFlow < 3)
1389 {
1390 rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1391 // >= 7 bytes
1392 }
1393 int rbAllocated = 0;
1394
1395 std::map<uint16_t, tdbetsFlowPerf_t>::iterator itStats;
1396 if (m_nextRntiUl != 0)
1397 {
1398 for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1399 {
1400 if ((*it).first == m_nextRntiUl)
1401 {
1402 break;
1403 }
1404 }
1405 if (it == m_ceBsrRxed.end())
1406 {
1407 NS_LOG_ERROR(this << " no user found");
1408 }
1409 }
1410 else
1411 {
1412 it = m_ceBsrRxed.begin();
1413 m_nextRntiUl = (*it).first;
1414 }
1415 do
1416 {
1417 std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1418 if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1419 {
1420 // UE already allocated for UL-HARQ -> skip it
1421 NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1422 << (*it).first);
1423 it++;
1424 if (it == m_ceBsrRxed.end())
1425 {
1426 // restart from the first
1427 it = m_ceBsrRxed.begin();
1428 }
1429 continue;
1430 }
1431 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1432 {
1433 // limit to physical resources last resource assignment
1434 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1435 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1436 if (rbPerFlow < 3)
1437 {
1438 // terminate allocation
1439 rbPerFlow = 0;
1440 }
1441 }
1442
1443 UlDciListElement_s uldci;
1444 uldci.m_rnti = (*it).first;
1445 uldci.m_rbLen = rbPerFlow;
1446 bool allocated = false;
1447 NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1448 << " flows " << nflows);
1449 while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1450 (rbPerFlow != 0))
1451 {
1452 // check availability
1453 bool free = true;
1454 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1455 {
1456 if (rbMap.at(j))
1457 {
1458 free = false;
1459 break;
1460 }
1461 }
1462 if (free)
1463 {
1464 uldci.m_rbStart = rbAllocated;
1465
1466 for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1467 {
1468 rbMap.at(j) = true;
1469 // store info on allocation for managing ul-cqi interpretation
1470 rbgAllocationMap.at(j) = (*it).first;
1471 }
1472 rbAllocated += rbPerFlow;
1473 allocated = true;
1474 break;
1475 }
1476 rbAllocated++;
1477 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1478 {
1479 // limit to physical resources last resource assignment
1480 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1481 // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1482 if (rbPerFlow < 3)
1483 {
1484 // terminate allocation
1485 rbPerFlow = 0;
1486 }
1487 }
1488 }
1489 if (!allocated)
1490 {
1491 // unable to allocate new resource: finish scheduling
1492 m_nextRntiUl = (*it).first;
1493 if (!ret.m_dciList.empty())
1494 {
1496 }
1497 m_allocationMaps.insert(
1498 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1499 return;
1500 }
1501
1502 std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find((*it).first);
1503 int cqi = 0;
1504 if (itCqi == m_ueCqi.end())
1505 {
1506 // no cqi info about this UE
1507 uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1508 }
1509 else
1510 {
1511 // take the lowest CQI value (worst RB)
1512 NS_ABORT_MSG_IF((*itCqi).second.empty(),
1513 "CQI of RNTI = " << (*it).first << " has expired");
1514 double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1515 if (minSinr == NO_SINR)
1516 {
1517 minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1518 }
1519 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1520 {
1521 double sinr = (*itCqi).second.at(i);
1522 if (sinr == NO_SINR)
1523 {
1524 sinr = EstimateUlSinr((*it).first, i);
1525 }
1526 if (sinr < minSinr)
1527 {
1528 minSinr = sinr;
1529 }
1530 }
1531
1532 // translate SINR -> cqi: WILD ACK: same as DL
1533 double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1534 cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1535 if (cqi == 0)
1536 {
1537 it++;
1538 if (it == m_ceBsrRxed.end())
1539 {
1540 // restart from the first
1541 it = m_ceBsrRxed.begin();
1542 }
1543 NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1544 // remove UE from allocation map
1545 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1546 {
1547 rbgAllocationMap.at(i) = 0;
1548 }
1549 continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1550 }
1551 uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1552 }
1553
1554 uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1556 uldci.m_ndi = 1;
1557 uldci.m_cceIndex = 0;
1558 uldci.m_aggrLevel = 1;
1559 uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1560 uldci.m_hopping = false;
1561 uldci.m_n2Dmrs = 0;
1562 uldci.m_tpc = 0; // no power control
1563 uldci.m_cqiRequest = false; // only period CQI at this stage
1564 uldci.m_ulIndex = 0; // TDD parameter
1565 uldci.m_dai = 1; // TDD parameter
1566 uldci.m_freqHopping = 0;
1567 uldci.m_pdcchPowerOffset = 0; // not used
1568 ret.m_dciList.push_back(uldci);
1569 // store DCI for HARQ_PERIOD
1570 uint8_t harqId = 0;
1571 if (m_harqOn)
1572 {
1573 std::map<uint16_t, uint8_t>::iterator itProcId;
1574 itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1575 if (itProcId == m_ulHarqCurrentProcessId.end())
1576 {
1577 NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1578 }
1579 harqId = (*itProcId).second;
1580 std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci =
1582 if (itDci == m_ulHarqProcessesDciBuffer.end())
1583 {
1584 NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1585 << uldci.m_rnti);
1586 }
1587 (*itDci).second.at(harqId) = uldci;
1588 // Update HARQ process status (RV 0)
1589 std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1590 m_ulHarqProcessesStatus.find(uldci.m_rnti);
1591 if (itStat == m_ulHarqProcessesStatus.end())
1592 {
1593 NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1594 << uldci.m_rnti);
1595 }
1596 (*itStat).second.at(harqId) = 0;
1597 }
1598
1599 NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1600 << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1601 << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1602 << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1603 << (uint16_t)harqId);
1604
1605 // update TTI UE stats
1606 itStats = m_flowStatsUl.find((*it).first);
1607 if (itStats != m_flowStatsUl.end())
1608 {
1609 (*itStats).second.lastTtiBytesTrasmitted = uldci.m_tbSize;
1610 }
1611 else
1612 {
1613 NS_LOG_DEBUG(this << " No Stats for this allocated UE");
1614 }
1615
1616 it++;
1617 if (it == m_ceBsrRxed.end())
1618 {
1619 // restart from the first
1620 it = m_ceBsrRxed.begin();
1621 }
1622 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1623 {
1624 // Stop allocation: no more PRBs
1625 m_nextRntiUl = (*it).first;
1626 break;
1627 }
1628 } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1629
1630 // Update global UE stats
1631 // update UEs stats
1632 for (itStats = m_flowStatsUl.begin(); itStats != m_flowStatsUl.end(); itStats++)
1633 {
1634 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTrasmitted;
1635 // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
1636 // Evolution, Ed Wiley)
1637 (*itStats).second.lastAveragedThroughput =
1638 ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
1639 ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTrasmitted / 0.001));
1640 NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1641 NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1642 (*itStats).second.lastTtiBytesTrasmitted = 0;
1643 }
1644 m_allocationMaps.insert(
1645 std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1647}
1648
1649void
1652{
1653 NS_LOG_FUNCTION(this);
1654}
1655
1656void
1659{
1660 NS_LOG_FUNCTION(this);
1661}
1662
1663void
1666{
1667 NS_LOG_FUNCTION(this);
1668
1669 std::map<uint16_t, uint32_t>::iterator it;
1670
1671 for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1672 {
1673 if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1674 {
1675 // buffer status report
1676 // note that this scheduler does not differentiate the
1677 // allocation according to which LCGs have more/less bytes
1678 // to send.
1679 // Hence the BSR of different LCGs are just summed up to get
1680 // a total queue size that is used for allocation purposes.
1681
1682 uint32_t buffer = 0;
1683 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1684 {
1685 uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1686 buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1687 }
1688
1689 uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1690 NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1691 it = m_ceBsrRxed.find(rnti);
1692 if (it == m_ceBsrRxed.end())
1693 {
1694 // create the new entry
1695 m_ceBsrRxed.insert(std::pair<uint16_t, uint32_t>(rnti, buffer));
1696 }
1697 else
1698 {
1699 // update the buffer size value
1700 (*it).second = buffer;
1701 }
1702 }
1703 }
1704}
1705
1706void
1709{
1710 NS_LOG_FUNCTION(this);
1711 // retrieve the allocation for this subframe
1712 switch (m_ulCqiFilter)
1713 {
1715 // filter all the CQIs that are not SRS based
1716 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1717 {
1718 return;
1719 }
1720 }
1721 break;
1723 // filter all the CQIs that are not SRS based
1724 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1725 {
1726 return;
1727 }
1728 }
1729 break;
1730 default:
1731 NS_FATAL_ERROR("Unknown UL CQI type");
1732 }
1733
1734 switch (params.m_ulCqi.m_type)
1735 {
1736 case UlCqi_s::PUSCH: {
1737 std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
1738 std::map<uint16_t, std::vector<double>>::iterator itCqi;
1739 NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1740 << " subframe no. " << (0xF & params.m_sfnSf));
1741 itMap = m_allocationMaps.find(params.m_sfnSf);
1742 if (itMap == m_allocationMaps.end())
1743 {
1744 return;
1745 }
1746 for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1747 {
1748 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1749 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1750 itCqi = m_ueCqi.find((*itMap).second.at(i));
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 if (i == j)
1758 {
1759 newCqi.push_back(sinr);
1760 }
1761 else
1762 {
1763 // initialize with NO_SINR value.
1764 newCqi.push_back(NO_SINR);
1765 }
1766 }
1767 m_ueCqi.insert(
1768 std::pair<uint16_t, std::vector<double>>((*itMap).second.at(i), newCqi));
1769 // generate correspondent timer
1770 m_ueCqiTimers.insert(
1771 std::pair<uint16_t, uint32_t>((*itMap).second.at(i), m_cqiTimersThreshold));
1772 }
1773 else
1774 {
1775 // update the value
1776 (*itCqi).second.at(i) = sinr;
1777 NS_LOG_DEBUG(this << " RNTI " << (*itMap).second.at(i) << " RB " << i << " SINR "
1778 << sinr);
1779 // update correspondent timer
1780 std::map<uint16_t, uint32_t>::iterator itTimers;
1781 itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1782 (*itTimers).second = m_cqiTimersThreshold;
1783 }
1784 }
1785 // remove obsolete info on allocation
1786 m_allocationMaps.erase(itMap);
1787 }
1788 break;
1789 case UlCqi_s::SRS: {
1790 // get the RNTI from vendor specific parameters
1791 uint16_t rnti = 0;
1792 NS_ASSERT(!params.m_vendorSpecificList.empty());
1793 for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1794 {
1795 if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1796 {
1797 Ptr<SrsCqiRntiVsp> vsp =
1798 DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1799 rnti = vsp->GetRnti();
1800 }
1801 }
1802 std::map<uint16_t, std::vector<double>>::iterator itCqi;
1803 itCqi = m_ueCqi.find(rnti);
1804 if (itCqi == m_ueCqi.end())
1805 {
1806 // create a new entry
1807 std::vector<double> newCqi;
1808 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1809 {
1810 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1811 newCqi.push_back(sinr);
1812 NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1813 << sinr);
1814 }
1815 m_ueCqi.insert(std::pair<uint16_t, std::vector<double>>(rnti, newCqi));
1816 // generate correspondent timer
1817 m_ueCqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1818 }
1819 else
1820 {
1821 // update the values
1822 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1823 {
1824 double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1825 (*itCqi).second.at(j) = sinr;
1826 NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1827 << sinr);
1828 }
1829 // update correspondent timer
1830 std::map<uint16_t, uint32_t>::iterator itTimers;
1831 itTimers = m_ueCqiTimers.find(rnti);
1832 (*itTimers).second = m_cqiTimersThreshold;
1833 }
1834 }
1835 break;
1836 case UlCqi_s::PUCCH_1:
1837 case UlCqi_s::PUCCH_2:
1838 case UlCqi_s::PRACH: {
1839 NS_FATAL_ERROR("TdBetFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1840 }
1841 break;
1842 default:
1843 NS_FATAL_ERROR("Unknown type of UL-CQI");
1844 }
1845}
1846
1847void
1849{
1850 // refresh DL CQI P01 Map
1851 std::map<uint16_t, uint32_t>::iterator itP10 = m_p10CqiTimers.begin();
1852 while (itP10 != m_p10CqiTimers.end())
1853 {
1854 NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1855 << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1856 if ((*itP10).second == 0)
1857 {
1858 // delete correspondent entries
1859 std::map<uint16_t, uint8_t>::iterator itMap = m_p10CqiRxed.find((*itP10).first);
1860 NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1861 " Does not find CQI report for user " << (*itP10).first);
1862 NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1863 m_p10CqiRxed.erase(itMap);
1864 std::map<uint16_t, uint32_t>::iterator temp = itP10;
1865 itP10++;
1866 m_p10CqiTimers.erase(temp);
1867 }
1868 else
1869 {
1870 (*itP10).second--;
1871 itP10++;
1872 }
1873 }
1874
1875 // refresh DL CQI A30 Map
1876 std::map<uint16_t, uint32_t>::iterator itA30 = m_a30CqiTimers.begin();
1877 while (itA30 != m_a30CqiTimers.end())
1878 {
1879 NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1880 << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1881 if ((*itA30).second == 0)
1882 {
1883 // delete correspondent entries
1884 std::map<uint16_t, SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find((*itA30).first);
1885 NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1886 " Does not find CQI report for user " << (*itA30).first);
1887 NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1888 m_a30CqiRxed.erase(itMap);
1889 std::map<uint16_t, uint32_t>::iterator temp = itA30;
1890 itA30++;
1891 m_a30CqiTimers.erase(temp);
1892 }
1893 else
1894 {
1895 (*itA30).second--;
1896 itA30++;
1897 }
1898 }
1899}
1900
1901void
1903{
1904 // refresh UL CQI Map
1905 std::map<uint16_t, uint32_t>::iterator itUl = m_ueCqiTimers.begin();
1906 while (itUl != m_ueCqiTimers.end())
1907 {
1908 NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
1909 << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1910 if ((*itUl).second == 0)
1911 {
1912 // delete correspondent entries
1913 std::map<uint16_t, std::vector<double>>::iterator itMap = m_ueCqi.find((*itUl).first);
1914 NS_ASSERT_MSG(itMap != m_ueCqi.end(),
1915 " Does not find CQI report for user " << (*itUl).first);
1916 NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
1917 (*itMap).second.clear();
1918 m_ueCqi.erase(itMap);
1919 std::map<uint16_t, uint32_t>::iterator temp = itUl;
1920 itUl++;
1921 m_ueCqiTimers.erase(temp);
1922 }
1923 else
1924 {
1925 (*itUl).second--;
1926 itUl++;
1927 }
1928 }
1929}
1930
1931void
1932TdBetFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
1933{
1934 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1935 LteFlowId_t flow(rnti, lcid);
1936 it = m_rlcBufferReq.find(flow);
1937 if (it != m_rlcBufferReq.end())
1938 {
1939 NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
1940 << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
1941 << (*it).second.m_rlcRetransmissionQueueSize << " status "
1942 << (*it).second.m_rlcStatusPduSize << " decrease " << size);
1943 // Update queues: RLC tx order Status, ReTx, Tx
1944 // Update status queue
1945 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1946 {
1947 (*it).second.m_rlcStatusPduSize = 0;
1948 }
1949 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
1950 (size >= (*it).second.m_rlcRetransmissionQueueSize))
1951 {
1952 (*it).second.m_rlcRetransmissionQueueSize = 0;
1953 }
1954 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1955 {
1956 uint32_t rlcOverhead;
1957 if (lcid == 1)
1958 {
1959 // for SRB1 (using RLC AM) it's better to
1960 // overestimate RLC overhead rather than
1961 // underestimate it and risk unneeded
1962 // segmentation which increases delay
1963 rlcOverhead = 4;
1964 }
1965 else
1966 {
1967 // minimum RLC overhead due to header
1968 rlcOverhead = 2;
1969 }
1970 // update transmission queue
1971 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
1972 {
1973 (*it).second.m_rlcTransmissionQueueSize = 0;
1974 }
1975 else
1976 {
1977 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
1978 }
1979 }
1980 }
1981 else
1982 {
1983 NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
1984 }
1985}
1986
1987void
1989{
1990 size = size - 2; // remove the minimum RLC overhead
1991 std::map<uint16_t, uint32_t>::iterator it = m_ceBsrRxed.find(rnti);
1992 if (it != m_ceBsrRxed.end())
1993 {
1994 NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
1995 if ((*it).second >= size)
1996 {
1997 (*it).second -= size;
1998 }
1999 else
2000 {
2001 (*it).second = 0;
2002 }
2003 }
2004 else
2005 {
2006 NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
2007 }
2008}
2009
2010void
2012{
2013 NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2015 params.m_rnti = rnti;
2016 params.m_transmissionMode = txMode;
2018}
2019
2020} // 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: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.
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