A Discrete-Event Network Simulator
API
rr-ff-mac-scheduler.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Marco Miozzo <marco.miozzo@cttc.es>
19  */
20 
21 #include <ns3/log.h>
22 #include <ns3/pointer.h>
23 #include <ns3/math.h>
24 #include <cfloat>
25 #include <set>
26 #include <climits>
27 
28 #include <ns3/lte-amc.h>
29 #include <ns3/rr-ff-mac-scheduler.h>
30 #include <ns3/simulator.h>
31 #include <ns3/lte-common.h>
32 #include <ns3/lte-vendor-specific-parameters.h>
33 #include <ns3/boolean.h>
34 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("RrFfMacScheduler");
38 
40 static const int Type0AllocationRbg[4] = {
41  10, // RGB size 1
42  26, // RGB size 2
43  63, // RGB size 3
44  110 // RGB size 4
45 }; // see table 7.1.6.1-1 of 36.213
46 
47 
48 
49 
50 NS_OBJECT_ENSURE_REGISTERED (RrFfMacScheduler);
51 
52 
54  : m_cschedSapUser (0),
55  m_schedSapUser (0),
56  m_nextRntiDl (0),
57  m_nextRntiUl (0)
58 {
59  m_amc = CreateObject <LteAmc> ();
62 }
63 
65 {
66  NS_LOG_FUNCTION (this);
67 }
68 
69 void
71 {
72  NS_LOG_FUNCTION (this);
74  m_dlHarqProcessesTimer.clear ();
76  m_dlInfoListBuffered.clear ();
77  m_ulHarqCurrentProcessId.clear ();
78  m_ulHarqProcessesStatus.clear ();
80  delete m_cschedSapProvider;
81  delete m_schedSapProvider;
82 }
83 
84 TypeId
86 {
87  static TypeId tid = TypeId ("ns3::RrFfMacScheduler")
89  .SetGroupName("Lte")
90  .AddConstructor<RrFfMacScheduler> ()
91  .AddAttribute ("CqiTimerThreshold",
92  "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
93  UintegerValue (1000),
95  MakeUintegerChecker<uint32_t> ())
96  .AddAttribute ("HarqEnabled",
97  "Activate/Deactivate the HARQ [by default is active].",
98  BooleanValue (true),
101  .AddAttribute ("UlGrantMcs",
102  "The MCS of the UL grant, must be [0..15] (default 0)",
103  UintegerValue (0),
105  MakeUintegerChecker<uint8_t> ())
106  ;
107  return tid;
108 }
109 
110 
111 
112 void
114 {
115  m_cschedSapUser = s;
116 }
117 
118 void
120 {
121  m_schedSapUser = s;
122 }
123 
126 {
127  return m_cschedSapProvider;
128 }
129 
132 {
133  return m_schedSapProvider;
134 }
135 
136 void
138 {
139  m_ffrSapProvider = s;
140 }
141 
144 {
145  return m_ffrSapUser;
146 }
147 
148 void
150 {
151  NS_LOG_FUNCTION (this);
152  // Read the subset of parameters used
153  m_cschedCellConfig = params;
156  cnf.m_result = SUCCESS;
158  return;
159 }
160 
161 void
163 {
164  NS_LOG_FUNCTION (this << " RNTI " << params.m_rnti << " txMode " << (uint16_t)params.m_transmissionMode);
165  std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
166  if (it == m_uesTxMode.end ())
167  {
168  m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
169  // generate HARQ buffers
170  m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
171  DlHarqProcessesStatus_t dlHarqPrcStatus;
172  dlHarqPrcStatus.resize (8,0);
173  m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
174  DlHarqProcessesTimer_t dlHarqProcessesTimer;
175  dlHarqProcessesTimer.resize (8,0);
176  m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
177  DlHarqProcessesDciBuffer_t dlHarqdci;
178  dlHarqdci.resize (8);
179  m_dlHarqProcessesDciBuffer.insert (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);
184  m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
185  m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
186  UlHarqProcessesStatus_t ulHarqPrcStatus;
187  ulHarqPrcStatus.resize (8,0);
188  m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
189  UlHarqProcessesDciBuffer_t ulHarqdci;
190  ulHarqdci.resize (8);
191  m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
192  }
193  else
194  {
195  (*it).second = params.m_transmissionMode;
196  }
197  return;
198 }
199 
200 void
202 {
203  NS_LOG_FUNCTION (this);
204  // Not used at this stage (LCs updated by DoSchedDlRlcBufferReq)
205  return;
206 }
207 
208 void
210 {
211  NS_LOG_FUNCTION (this);
212  for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
213  {
214  std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
215  while (it!=m_rlcBufferReq.end ())
216  {
217  if (((*it).m_rnti == params.m_rnti)&&((*it).m_logicalChannelIdentity == params.m_logicalChannelIdentity.at (i)))
218  {
219  it = m_rlcBufferReq.erase (it);
220  }
221  else
222  {
223  it++;
224  }
225  }
226  }
227  return;
228 }
229 
230 void
232 {
233  NS_LOG_FUNCTION (this << " Release RNTI " << params.m_rnti);
234 
235  m_uesTxMode.erase (params.m_rnti);
236  m_dlHarqCurrentProcessId.erase (params.m_rnti);
237  m_dlHarqProcessesStatus.erase (params.m_rnti);
238  m_dlHarqProcessesTimer.erase (params.m_rnti);
239  m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
241  m_ulHarqCurrentProcessId.erase (params.m_rnti);
242  m_ulHarqProcessesStatus.erase (params.m_rnti);
243  m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
244  m_ceBsrRxed.erase (params.m_rnti);
245  std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
246  while (it != m_rlcBufferReq.end ())
247  {
248  if ((*it).m_rnti == params.m_rnti)
249  {
250  NS_LOG_INFO (this << " Erase RNTI " << (*it).m_rnti << " LC " << (uint16_t)(*it).m_logicalChannelIdentity);
251  it = m_rlcBufferReq.erase (it);
252  }
253  else
254  {
255  it++;
256  }
257  }
258  if (m_nextRntiUl == params.m_rnti)
259  {
260  m_nextRntiUl = 0;
261  }
262 
263  if (m_nextRntiDl == params.m_rnti)
264  {
265  m_nextRntiDl = 0;
266  }
267 
268  return;
269 }
270 
271 
272 void
274 {
275  NS_LOG_FUNCTION (this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
276  // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
277  std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
278  bool newLc = true;
279  while (it != m_rlcBufferReq.end ())
280  {
281  // remove old entries of this UE-LC
282  if (((*it).m_rnti == params.m_rnti)&&((*it).m_logicalChannelIdentity == params.m_logicalChannelIdentity))
283  {
284  it = m_rlcBufferReq.erase (it);
285  newLc = false;
286  }
287  else
288  {
289  ++it;
290  }
291  }
292  // add the new parameters
293  m_rlcBufferReq.insert (it, params);
294  NS_LOG_INFO (this << " RNTI " << params.m_rnti << " LC " << (uint16_t)params.m_logicalChannelIdentity << " RLC tx size " << params.m_rlcTransmissionQueueSize << " RLC retx size " << params.m_rlcRetransmissionQueueSize << " RLC stat size " << params.m_rlcStatusPduSize);
295  // initialize statistics of the flow in case of new flows
296  if (newLc == true)
297  {
298  m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (params.m_rnti, 1)); // only codeword 0 at this stage (SISO)
299  // initialized to 1 (i.e., the lowest value for transmitting a signal)
300  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (params.m_rnti, m_cqiTimersThreshold));
301  }
302 
303  return;
304 }
305 
306 void
308 {
309  NS_LOG_FUNCTION (this);
310  NS_FATAL_ERROR ("method not implemented");
311  return;
312 }
313 
314 void
316 {
317  NS_LOG_FUNCTION (this);
318  NS_FATAL_ERROR ("method not implemented");
319  return;
320 }
321 
322 int
324 {
325  for (int i = 0; i < 4; i++)
326  {
327  if (dlbandwidth < Type0AllocationRbg[i])
328  {
329  return (i + 1);
330  }
331  }
332 
333  return (-1);
334 }
335 
336 bool
338 {
339  return (i.m_rnti < j.m_rnti);
340 }
341 
342 
343 uint8_t
345 {
346  NS_LOG_FUNCTION (this << rnti);
347 
348  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
349  if (it == m_dlHarqCurrentProcessId.end ())
350  {
351  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
352  }
353  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
354  if (itStat == m_dlHarqProcessesStatus.end ())
355  {
356  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
357  }
358  uint8_t i = (*it).second;
359  do
360  {
361  i = (i + 1) % HARQ_PROC_NUM;
362  }
363  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
364  if ((*itStat).second.at (i) == 0)
365  {
366  return (true);
367  }
368  else
369  {
370  return (false); // return a not valid harq proc id
371  }
372 }
373 
374 
375 
376 uint8_t
378 {
379  NS_LOG_FUNCTION (this << rnti);
380 
381 
382  if (m_harqOn == false)
383  {
384  return (0);
385  }
386 
387  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
388  if (it == m_dlHarqCurrentProcessId.end ())
389  {
390  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
391  }
392  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
393  if (itStat == m_dlHarqProcessesStatus.end ())
394  {
395  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
396  }
397  uint8_t i = (*it).second;
398  do
399  {
400  i = (i + 1) % HARQ_PROC_NUM;
401  }
402  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
403  if ((*itStat).second.at (i) == 0)
404  {
405  (*it).second = i;
406  (*itStat).second.at (i) = 1;
407  }
408  else
409  {
410  return (9); // return a not valid harq proc id
411  }
412 
413  return ((*it).second);
414 }
415 
416 
417 void
419 {
420  NS_LOG_FUNCTION (this);
421 
422  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
423  for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers ++)
424  {
425  for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
426  {
427  if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
428  {
429  // reset HARQ process
430 
431  NS_LOG_INFO (this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
432  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
433  if (itStat == m_dlHarqProcessesStatus.end ())
434  {
435  NS_FATAL_ERROR ("No Process Id Status found for this RNTI " << (*itTimers).first);
436  }
437  (*itStat).second.at (i) = 0;
438  (*itTimers).second.at (i) = 0;
439  }
440  else
441  {
442  (*itTimers).second.at (i)++;
443  }
444  }
445  }
446 
447 }
448 
449 
450 
451 void
453 {
454  NS_LOG_FUNCTION (this << " DL Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
455  // API generated by RLC for triggering the scheduling of a DL subframe
456 
457  RefreshDlCqiMaps ();
459  int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
461 
462  // Generate RBGs map
463  std::vector <bool> rbgMap;
464  uint16_t rbgAllocatedNum = 0;
465  std::set <uint16_t> rntiAllocated;
466  rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
467 
468  // update UL HARQ proc id
469  std::map <uint16_t, uint8_t>::iterator itProcId;
470  for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
471  {
472  (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
473  }
474 
475  // RACH Allocation
477  uint16_t rbStart = 0;
478  std::vector <struct RachListElement_s>::iterator itRach;
479  for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
480  {
481  NS_ASSERT_MSG (m_amc->GetUlTbSizeFromMcs (m_ulGrantMcs, m_cschedCellConfig.m_ulBandwidth) > (*itRach).m_estimatedSize, " Default UL Grant MCS does not allow to send RACH messages");
482  BuildRarListElement_s newRar;
483  newRar.m_rnti = (*itRach).m_rnti;
484  // DL-RACH Allocation
485  // Ideal: no needs of configuring m_dci
486  // UL-RACH Allocation
487  newRar.m_grant.m_rnti = newRar.m_rnti;
488  newRar.m_grant.m_mcs = m_ulGrantMcs;
489  uint16_t rbLen = 1;
490  uint16_t tbSizeBits = 0;
491  // find lowest TB size that fits UL grant estimated size
492  while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
493  {
494  rbLen++;
495  tbSizeBits = m_amc->GetUlTbSizeFromMcs (m_ulGrantMcs, rbLen);
496  }
497  if (tbSizeBits < (*itRach).m_estimatedSize)
498  {
499  // no more allocation space: finish allocation
500  break;
501  }
502  newRar.m_grant.m_rbStart = rbStart;
503  newRar.m_grant.m_rbLen = rbLen;
504  newRar.m_grant.m_tbSize = tbSizeBits / 8;
505  newRar.m_grant.m_hopping = false;
506  newRar.m_grant.m_tpc = 0;
507  newRar.m_grant.m_cqiRequest = false;
508  newRar.m_grant.m_ulDelay = false;
509  NS_LOG_INFO (this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart " << rbStart << " rbLen " << rbLen << " MCS " << (uint16_t) m_ulGrantMcs << " tbSize " << newRar.m_grant.m_tbSize);
510  for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
511  {
512  m_rachAllocationMap.at (i) = (*itRach).m_rnti;
513  }
514 
515  if (m_harqOn == true)
516  {
517  // generate UL-DCI for HARQ retransmissions
518  UlDciListElement_s uldci;
519  uldci.m_rnti = newRar.m_rnti;
520  uldci.m_rbLen = rbLen;
521  uldci.m_rbStart = rbStart;
522  uldci.m_mcs = m_ulGrantMcs;
523  uldci.m_tbSize = tbSizeBits / 8;
524  uldci.m_ndi = 1;
525  uldci.m_cceIndex = 0;
526  uldci.m_aggrLevel = 1;
527  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
528  uldci.m_hopping = false;
529  uldci.m_n2Dmrs = 0;
530  uldci.m_tpc = 0; // no power control
531  uldci.m_cqiRequest = false; // only period CQI at this stage
532  uldci.m_ulIndex = 0; // TDD parameter
533  uldci.m_dai = 1; // TDD parameter
534  uldci.m_freqHopping = 0;
535  uldci.m_pdcchPowerOffset = 0; // not used
536 
537  uint8_t harqId = 0;
538  std::map <uint16_t, uint8_t>::iterator itProcId;
539  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
540  if (itProcId == m_ulHarqCurrentProcessId.end ())
541  {
542  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
543  }
544  harqId = (*itProcId).second;
545  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
546  if (itDci == m_ulHarqProcessesDciBuffer.end ())
547  {
548  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
549  }
550  (*itDci).second.at (harqId) = uldci;
551  }
552 
553  rbStart = rbStart + rbLen;
554  ret.m_buildRarList.push_back (newRar);
555  }
556  m_rachList.clear ();
557 
558  // Process DL HARQ feedback
560  // retrieve past HARQ retx buffered
561  if (m_dlInfoListBuffered.size () > 0)
562  {
563  if (params.m_dlInfoList.size () > 0)
564  {
565  NS_LOG_INFO (this << " Received DL-HARQ feedback");
566  m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
567  }
568  }
569  else
570  {
571  if (params.m_dlInfoList.size () > 0)
572  {
574  }
575  }
576  if (m_harqOn == false)
577  {
578  // Ignore HARQ feedback
579  m_dlInfoListBuffered.clear ();
580  }
581  std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
582  for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
583  {
584  std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
585  if (itRnti != rntiAllocated.end ())
586  {
587  // RNTI already allocated for retx
588  continue;
589  }
590  uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
591  std::vector <bool> retx;
592  NS_LOG_INFO (this << " Processing DLHARQ feedback");
593  if (nLayers == 1)
594  {
595  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
596  retx.push_back (false);
597  }
598  else
599  {
600  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
601  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
602  }
603  if (retx.at (0) || retx.at (1))
604  {
605  // retrieve HARQ process information
606  uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
607  uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
608  NS_LOG_INFO (this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
609  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
610  if (itHarq == m_dlHarqProcessesDciBuffer.end ())
611  {
612  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << rnti);
613  }
614 
615  DlDciListElement_s dci = (*itHarq).second.at (harqId);
616  int rv = 0;
617  if (dci.m_rv.size () == 1)
618  {
619  rv = dci.m_rv.at (0);
620  }
621  else
622  {
623  rv = (dci.m_rv.at (0) > dci.m_rv.at (1) ? dci.m_rv.at (0) : dci.m_rv.at (1));
624  }
625 
626  if (rv == 3)
627  {
628  // maximum number of retx reached -> drop process
629  NS_LOG_INFO ("Max number of retransmissions reached -> drop process");
630  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (rnti);
631  if (it == m_dlHarqProcessesStatus.end ())
632  {
633  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << m_dlInfoListBuffered.at (i).m_rnti);
634  }
635  (*it).second.at (harqId) = 0;
636  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
637  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
638  {
639  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
640  }
641  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
642  {
643  (*itRlcPdu).second.at (k).at (harqId).clear ();
644  }
645  continue;
646  }
647  // check the feasibility of retransmitting on the same RBGs
648  // translate the DCI to Spectrum framework
649  std::vector <int> dciRbg;
650  uint32_t mask = 0x1;
651  NS_LOG_INFO ("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
652  for (int j = 0; j < 32; j++)
653  {
654  if (((dci.m_rbBitmap & mask) >> j) == 1)
655  {
656  dciRbg.push_back (j);
657  NS_LOG_INFO ("\t" << j);
658  }
659  mask = (mask << 1);
660  }
661  bool free = true;
662  for (uint8_t j = 0; j < dciRbg.size (); j++)
663  {
664  if (rbgMap.at (dciRbg.at (j)) == true)
665  {
666  free = false;
667  break;
668  }
669  }
670  if (free)
671  {
672  // use the same RBGs for the retx
673  // reserve RBGs
674  for (uint8_t j = 0; j < dciRbg.size (); j++)
675  {
676  rbgMap.at (dciRbg.at (j)) = true;
677  NS_LOG_INFO ("RBG " << dciRbg.at (j) << " assigned");
678  rbgAllocatedNum++;
679  }
680 
681  NS_LOG_INFO (this << " Send retx in the same RBGs");
682  }
683  else
684  {
685  // find RBGs for sending HARQ retx
686  uint8_t j = 0;
687  uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
688  uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
689  std::vector <bool> rbgMapCopy = rbgMap;
690  while ((j < dciRbg.size ())&&(startRbg != rbgId))
691  {
692  if (rbgMapCopy.at (rbgId) == false)
693  {
694  rbgMapCopy.at (rbgId) = true;
695  dciRbg.at (j) = rbgId;
696  j++;
697  }
698  rbgId = (rbgId + 1) % rbgNum;
699  }
700  if (j == dciRbg.size ())
701  {
702  // find new RBGs -> update DCI map
703  uint32_t rbgMask = 0;
704  for (uint16_t k = 0; k < dciRbg.size (); k++)
705  {
706  rbgMask = rbgMask + (0x1 << dciRbg.at (k));
707  NS_LOG_INFO (this << " New allocated RBG " << dciRbg.at (k));
708  rbgAllocatedNum++;
709  }
710  dci.m_rbBitmap = rbgMask;
711  rbgMap = rbgMapCopy;
712  }
713  else
714  {
715  // HARQ retx cannot be performed on this TTI -> store it
716  dlInfoListUntxed.push_back (m_dlInfoListBuffered.at (i));
717  NS_LOG_INFO (this << " No resource for this retx -> buffer it");
718  }
719  }
720  // retrieve RLC PDU list for retx TBsize and update DCI
722  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
723  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
724  {
725  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
726  }
727  for (uint8_t j = 0; j < nLayers; j++)
728  {
729  if (retx.at (j))
730  {
731  if (j >= dci.m_ndi.size ())
732  {
733  // for avoiding errors in MIMO transient phases
734  dci.m_ndi.push_back (0);
735  dci.m_rv.push_back (0);
736  dci.m_mcs.push_back (0);
737  dci.m_tbsSize.push_back (0);
738  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no txed (MIMO transition)");
739 
740  }
741  else
742  {
743  dci.m_ndi.at (j) = 0;
744  dci.m_rv.at (j)++;
745  (*itHarq).second.at (harqId).m_rv.at (j)++;
746  NS_LOG_INFO (this << " layer " << (uint16_t)j << " RV " << (uint16_t)dci.m_rv.at (j));
747  }
748  }
749  else
750  {
751  // empty TB of layer j
752  dci.m_ndi.at (j) = 0;
753  dci.m_rv.at (j) = 0;
754  dci.m_mcs.at (j) = 0;
755  dci.m_tbsSize.at (j) = 0;
756  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no retx");
757  }
758  }
759 
760  for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.m_harqProcess).size (); k++)
761  {
762  std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
763  for (uint8_t j = 0; j < nLayers; j++)
764  {
765  if (retx.at (j))
766  {
767  if (j < dci.m_ndi.size ())
768  {
769  NS_LOG_INFO (" layer " << (uint16_t)j << " tb size " << dci.m_tbsSize.at (j));
770  rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k));
771  }
772  }
773  else
774  { // if no retx needed on layer j, push an RlcPduListElement_s object with m_size=0 to keep the size of rlcPduListPerLc vector = 2 in case of MIMO
775  NS_LOG_INFO (" layer " << (uint16_t)j << " tb size "<<dci.m_tbsSize.at (j));
776  RlcPduListElement_s emptyElement;
777  emptyElement.m_logicalChannelIdentity = (*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k).m_logicalChannelIdentity;
778  emptyElement.m_size = 0;
779  rlcPduListPerLc.push_back (emptyElement);
780  }
781  }
782 
783  if (rlcPduListPerLc.size () > 0)
784  {
785  newEl.m_rlcPduList.push_back (rlcPduListPerLc);
786  }
787  }
788  newEl.m_rnti = rnti;
789  newEl.m_dci = dci;
790  (*itHarq).second.at (harqId).m_rv = dci.m_rv;
791  // refresh timer
792  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (rnti);
793  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
794  {
795  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
796  }
797  (*itHarqTimer).second.at (harqId) = 0;
798  ret.m_buildDataList.push_back (newEl);
799  rntiAllocated.insert (rnti);
800  }
801  else
802  {
803  // update HARQ process status
804  NS_LOG_INFO (this << " HARQ ACK UE " << m_dlInfoListBuffered.at (i).m_rnti);
805  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (m_dlInfoListBuffered.at (i).m_rnti);
806  if (it == m_dlHarqProcessesStatus.end ())
807  {
808  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << m_dlInfoListBuffered.at (i).m_rnti);
809  }
810  (*it).second.at (m_dlInfoListBuffered.at (i).m_harqProcessId) = 0;
811  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (m_dlInfoListBuffered.at (i).m_rnti);
812  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
813  {
814  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
815  }
816  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
817  {
818  (*itRlcPdu).second.at (k).at (m_dlInfoListBuffered.at (i).m_harqProcessId).clear ();
819  }
820  }
821  }
822  m_dlInfoListBuffered.clear ();
823  m_dlInfoListBuffered = dlInfoListUntxed;
824 
825  if (rbgAllocatedNum == rbgNum)
826  {
827  // all the RBGs are already allocated -> exit
828  if ((ret.m_buildDataList.size () > 0) || (ret.m_buildRarList.size () > 0))
829  {
831  }
832  return;
833  }
834 
835  // Get the actual active flows (queue!=0)
836  std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
838  int nflows = 0;
839  int nTbs = 0;
840  std::map <uint16_t,uint8_t> lcActivesPerRnti; // tracks how many active LCs per RNTI there are
841  std::map <uint16_t,uint8_t>::iterator itLcRnti;
842  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
843  {
844  // remove old entries of this UE-LC
845  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).m_rnti);
846  if ( (((*it).m_rlcTransmissionQueueSize > 0)
847  || ((*it).m_rlcRetransmissionQueueSize > 0)
848  || ((*it).m_rlcStatusPduSize > 0))
849  && (itRnti == rntiAllocated.end ()) // UE must not be allocated for HARQ retx
850  && (HarqProcessAvailability ((*it).m_rnti)) ) // UE needs HARQ proc free
851 
852  {
853  NS_LOG_LOGIC (this << " User " << (*it).m_rnti << " LC " << (uint16_t)(*it).m_logicalChannelIdentity << " is active, status " << (*it).m_rlcStatusPduSize << " retx " << (*it).m_rlcRetransmissionQueueSize << " tx " << (*it).m_rlcTransmissionQueueSize);
854  std::map <uint16_t,uint8_t>::iterator itCqi = m_p10CqiRxed.find ((*it).m_rnti);
855  uint8_t cqi = 0;
856  if (itCqi != m_p10CqiRxed.end ())
857  {
858  cqi = (*itCqi).second;
859  }
860  else
861  {
862  cqi = 1; // lowest value for trying a transmission
863  }
864  if (cqi != 0)
865  {
866  // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
867  nflows++;
868  itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
869  if (itLcRnti != lcActivesPerRnti.end ())
870  {
871  (*itLcRnti).second++;
872  }
873  else
874  {
875  lcActivesPerRnti.insert (std::pair<uint16_t, uint8_t > ((*it).m_rnti, 1));
876  nTbs++;
877  }
878 
879  }
880  }
881  }
882 
883  if (nflows == 0)
884  {
885  if ((ret.m_buildDataList.size () > 0) || (ret.m_buildRarList.size () > 0))
886  {
888  }
889  return;
890  }
891  // Divide the resource equally among the active users according to
892  // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
893 
894  int rbgPerTb = (nTbs > 0) ? ((rbgNum - rbgAllocatedNum) / nTbs) : INT_MAX;
895  NS_LOG_INFO (this << " Flows to be transmitted " << nflows << " rbgPerTb " << rbgPerTb);
896  if (rbgPerTb == 0)
897  {
898  rbgPerTb = 1; // at least 1 rbg per TB (till available resource)
899  }
900  int rbgAllocated = 0;
901 
902  // round robin assignment to all UEs registered starting from the subsequent of the one
903  // served last scheduling trigger event
904  if (m_nextRntiDl != 0)
905  {
906  NS_LOG_DEBUG ("Start from the successive of " << (uint16_t) m_nextRntiDl);
907  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
908  {
909  if ((*it).m_rnti == m_nextRntiDl)
910  {
911  // select the next RNTI to starting
912  it++;
913  if (it == m_rlcBufferReq.end ())
914  {
915  it = m_rlcBufferReq.begin ();
916  }
917  m_nextRntiDl = (*it).m_rnti;
918  break;
919  }
920  }
921 
922  if (it == m_rlcBufferReq.end ())
923  {
924  NS_LOG_ERROR (this << " no user found");
925  }
926  }
927  else
928  {
929  it = m_rlcBufferReq.begin ();
930  m_nextRntiDl = (*it).m_rnti;
931  }
932  std::map <uint16_t,uint8_t>::iterator itTxMode;
933  do
934  {
935  itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
936  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).m_rnti);
937  if ((itLcRnti == lcActivesPerRnti.end ())||(itRnti != rntiAllocated.end ()))
938  {
939  // skip this RNTI (no active queue or yet allocated for HARQ)
940  uint16_t rntiDiscared = (*it).m_rnti;
941  while (it != m_rlcBufferReq.end ())
942  {
943  if ((*it).m_rnti != rntiDiscared)
944  {
945  break;
946  }
947  it++;
948  }
949  if (it == m_rlcBufferReq.end ())
950  {
951  // restart from the first
952  it = m_rlcBufferReq.begin ();
953  }
954  continue;
955  }
956  itTxMode = m_uesTxMode.find ((*it).m_rnti);
957  if (itTxMode == m_uesTxMode.end ())
958  {
959  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).m_rnti);
960  }
961  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
962  int lcNum = (*itLcRnti).second;
963  // create new BuildDataListElement_s for this RNTI
965  newEl.m_rnti = (*it).m_rnti;
966  // create the DlDciListElement_s
967  DlDciListElement_s newDci;
968  newDci.m_rnti = (*it).m_rnti;
969  newDci.m_harqProcess = UpdateHarqProcessId ((*it).m_rnti);
970  newDci.m_resAlloc = 0;
971  newDci.m_rbBitmap = 0;
972  std::map <uint16_t,uint8_t>::iterator itCqi = m_p10CqiRxed.find (newEl.m_rnti);
973  for (uint8_t i = 0; i < nLayer; i++)
974  {
975  if (itCqi == m_p10CqiRxed.end ())
976  {
977  newDci.m_mcs.push_back (0); // no info on this user -> lowest MCS
978  }
979  else
980  {
981  newDci.m_mcs.push_back ( m_amc->GetMcsFromCqi ((*itCqi).second) );
982  }
983  }
984  int tbSize = (m_amc->GetDlTbSizeFromMcs (newDci.m_mcs.at (0), rbgPerTb * rbgSize) / 8);
985  uint16_t rlcPduSize = tbSize / lcNum;
986  while ((*it).m_rnti == newEl.m_rnti)
987  {
988  if ( ((*it).m_rlcTransmissionQueueSize > 0)
989  || ((*it).m_rlcRetransmissionQueueSize > 0)
990  || ((*it).m_rlcStatusPduSize > 0) )
991  {
992  std::vector <struct RlcPduListElement_s> newRlcPduLe;
993  for (uint8_t j = 0; j < nLayer; j++)
994  {
995  RlcPduListElement_s newRlcEl;
996  newRlcEl.m_logicalChannelIdentity = (*it).m_logicalChannelIdentity;
997  NS_LOG_INFO (this << "LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << rlcPduSize << " ID " << (*it).m_rnti << " layer " << (uint16_t)j);
998  newRlcEl.m_size = rlcPduSize;
999  UpdateDlRlcBufferInfo ((*it).m_rnti, newRlcEl.m_logicalChannelIdentity, rlcPduSize);
1000  newRlcPduLe.push_back (newRlcEl);
1001 
1002  if (m_harqOn == true)
1003  {
1004  // store RLC PDU list for HARQ
1005  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*it).m_rnti);
1006  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1007  {
1008  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*it).m_rnti);
1009  }
1010  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1011  }
1012 
1013  }
1014  newEl.m_rlcPduList.push_back (newRlcPduLe);
1015  lcNum--;
1016  }
1017  it++;
1018  if (it == m_rlcBufferReq.end ())
1019  {
1020  // restart from the first
1021  it = m_rlcBufferReq.begin ();
1022  break;
1023  }
1024  }
1025  uint32_t rbgMask = 0;
1026  uint16_t i = 0;
1027  NS_LOG_INFO (this << " DL - Allocate user " << newEl.m_rnti << " LCs " << (uint16_t)(*itLcRnti).second << " bytes " << tbSize << " mcs " << (uint16_t) newDci.m_mcs.at (0) << " harqId " << (uint16_t)newDci.m_harqProcess << " layers " << nLayer);
1028  NS_LOG_INFO ("RBG:");
1029  while (i < rbgPerTb)
1030  {
1031  if (rbgMap.at (rbgAllocated) == false)
1032  {
1033  rbgMask = rbgMask + (0x1 << rbgAllocated);
1034  NS_LOG_INFO ("\t " << rbgAllocated);
1035  i++;
1036  rbgMap.at (rbgAllocated) = true;
1037  rbgAllocatedNum++;
1038  }
1039  rbgAllocated++;
1040  }
1041  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1042 
1043  for (int i = 0; i < nLayer; i++)
1044  {
1045  newDci.m_tbsSize.push_back (tbSize);
1046  newDci.m_ndi.push_back (1);
1047  newDci.m_rv.push_back (0);
1048  }
1049 
1050  newDci.m_tpc = 1; //1 is mapped to 0 in Accumulated Mode and to -1 in Absolute Mode
1051 
1052  newEl.m_dci = newDci;
1053  if (m_harqOn == true)
1054  {
1055  // store DCI for HARQ
1056  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1057  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1058  {
1059  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1060  }
1061  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1062  // refresh timer
1063  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1064  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1065  {
1066  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1067  }
1068  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1069  }
1070  // ...more parameters -> ignored in this version
1071 
1072  ret.m_buildDataList.push_back (newEl);
1073  if (rbgAllocatedNum == rbgNum)
1074  {
1075  m_nextRntiDl = newEl.m_rnti; // store last RNTI served
1076  break; // no more RGB to be allocated
1077  }
1078  }
1079  while ((*it).m_rnti != m_nextRntiDl);
1080 
1081  ret.m_nrOfPdcchOfdmSymbols = 1;
1082 
1084  return;
1085 }
1086 
1087 void
1089 {
1090  NS_LOG_FUNCTION (this);
1091 
1092  m_rachList = params.m_rachList;
1093 
1094  return;
1095 }
1096 
1097 void
1099 {
1100  NS_LOG_FUNCTION (this);
1101 
1102  std::map <uint16_t,uint8_t>::iterator it;
1103  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1104  {
1105  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1106  {
1107  NS_LOG_LOGIC ("wideband CQI " << (uint32_t) params.m_cqiList.at (i).m_wbCqi.at (0) << " reported");
1108  std::map <uint16_t,uint8_t>::iterator it;
1109  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1110  it = m_p10CqiRxed.find (rnti);
1111  if (it == m_p10CqiRxed.end ())
1112  {
1113  // create the new entry
1114  m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.m_cqiList.at (i).m_wbCqi.at (0)) ); // only codeword 0 at this stage (SISO)
1115  // generate correspondent timer
1116  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1117  }
1118  else
1119  {
1120  // update the CQI value
1121  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1122  // update correspondent timer
1123  std::map <uint16_t,uint32_t>::iterator itTimers;
1124  itTimers = m_p10CqiTimers.find (rnti);
1125  (*itTimers).second = m_cqiTimersThreshold;
1126  }
1127  }
1128  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1129  {
1130  // subband CQI reporting high layer configured
1131  // Not used by RR Scheduler
1132  }
1133  else
1134  {
1135  NS_LOG_ERROR (this << " CQI type unknown");
1136  }
1137  }
1138 
1139  return;
1140 }
1141 
1142 void
1144 {
1145  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1146 
1147  RefreshUlCqiMaps ();
1148 
1149  // Generate RBs map
1151  std::vector <bool> rbMap;
1152  uint16_t rbAllocatedNum = 0;
1153  std::set <uint16_t> rntiAllocated;
1154  std::vector <uint16_t> rbgAllocationMap;
1155  // update with RACH allocation map
1156  rbgAllocationMap = m_rachAllocationMap;
1157  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1158  m_rachAllocationMap.clear ();
1160 
1161  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1162  // remove RACH allocation
1163  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1164  {
1165  if (rbgAllocationMap.at (i) != 0)
1166  {
1167  rbMap.at (i) = true;
1168  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1169  }
1170  }
1171 
1172  if (m_harqOn == true)
1173  {
1174  // Process UL HARQ feedback
1175  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1176  {
1177  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1178  {
1179  // retx correspondent block: retrieve the UL-DCI
1180  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1181  std::map <uint16_t, uint8_t>::iterator itProcId = m_ulHarqCurrentProcessId.find (rnti);
1182  if (itProcId == m_ulHarqCurrentProcessId.end ())
1183  {
1184  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1185  }
1186  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1187  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
1188  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1189  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1190  {
1191  NS_LOG_ERROR ("No info find in UL-HARQ buffer for UE (might change eNB) " << rnti);
1192  }
1193  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1194  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1195  if (itStat == m_ulHarqProcessesStatus.end ())
1196  {
1197  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1198  }
1199  if ((*itStat).second.at (harqId) >= 3)
1200  {
1201  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1202  continue;
1203  }
1204  bool free = true;
1205  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1206  {
1207  if (rbMap.at (j) == true)
1208  {
1209  free = false;
1210  NS_LOG_INFO (this << " BUSY " << j);
1211  }
1212  }
1213  if (free)
1214  {
1215  // retx on the same RBs
1216  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1217  {
1218  rbMap.at (j) = true;
1219  rbgAllocationMap.at (j) = dci.m_rnti;
1220  NS_LOG_INFO ("\tRB " << j);
1221  rbAllocatedNum++;
1222  }
1223  NS_LOG_INFO (this << " Send retx in the same RBGs " << (uint16_t)dci.m_rbStart << " to " << dci.m_rbStart + dci.m_rbLen << " RV " << (*itStat).second.at (harqId) + 1);
1224  }
1225  else
1226  {
1227  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1228  continue;
1229  }
1230  dci.m_ndi = 0;
1231  // Update HARQ buffers with new HarqId
1232  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1233  (*itStat).second.at (harqId) = 0;
1234  (*itHarq).second.at ((*itProcId).second) = dci;
1235  ret.m_dciList.push_back (dci);
1236  rntiAllocated.insert (dci.m_rnti);
1237  }
1238  }
1239  }
1240 
1241  std::map <uint16_t,uint32_t>::iterator it;
1242  int nflows = 0;
1243 
1244  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1245  {
1246  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1247  // select UEs with queues not empty and not yet allocated for HARQ
1248  NS_LOG_INFO (this << " UE " << (*it).first << " queue " << (*it).second);
1249  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1250  {
1251  nflows++;
1252  }
1253  }
1254 
1255  if (nflows == 0)
1256  {
1257  if (ret.m_dciList.size () > 0)
1258  {
1259  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1261  }
1262  return; // no flows to be scheduled
1263  }
1264 
1265 
1266  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1267  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size ());
1268  if (rbPerFlow < 3)
1269  {
1270  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity >= 7 bytes
1271  }
1272  uint16_t rbAllocated = 0;
1273 
1274  if (m_nextRntiUl != 0)
1275  {
1276  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1277  {
1278  if ((*it).first == m_nextRntiUl)
1279  {
1280  break;
1281  }
1282  }
1283  if (it == m_ceBsrRxed.end ())
1284  {
1285  NS_LOG_ERROR (this << " no user found");
1286  }
1287  }
1288  else
1289  {
1290  it = m_ceBsrRxed.begin ();
1291  m_nextRntiUl = (*it).first;
1292  }
1293  NS_LOG_INFO (this << " NFlows " << nflows << " RB per Flow " << rbPerFlow);
1294  do
1295  {
1296  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1297  if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1298  {
1299  // UE already allocated for UL-HARQ -> skip it
1300  it++;
1301  if (it == m_ceBsrRxed.end ())
1302  {
1303  // restart from the first
1304  it = m_ceBsrRxed.begin ();
1305  }
1306  continue;
1307  }
1308  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1309  {
1310  // limit to physical resources last resource assignment
1311  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1312  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1313  if (rbPerFlow < 3)
1314  {
1315  // terminate allocation
1316  rbPerFlow = 0;
1317  }
1318  }
1319  NS_LOG_INFO (this << " try to allocate " << (*it).first);
1320  UlDciListElement_s uldci;
1321  uldci.m_rnti = (*it).first;
1322  uldci.m_rbLen = rbPerFlow;
1323  bool allocated = false;
1324  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1325  while ((!allocated)&&((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) && (rbPerFlow != 0))
1326  {
1327  // check availability
1328  bool free = true;
1329  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1330  {
1331  if (rbMap.at (j) == true)
1332  {
1333  free = false;
1334  break;
1335  }
1336  }
1337  if (free)
1338  {
1339  uldci.m_rbStart = rbAllocated;
1340 
1341  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1342  {
1343  rbMap.at (j) = true;
1344  // store info on allocation for managing ul-cqi interpretation
1345  rbgAllocationMap.at (j) = (*it).first;
1346  NS_LOG_INFO ("\t " << j);
1347  }
1348  rbAllocated += rbPerFlow;
1349  allocated = true;
1350  break;
1351  }
1352  rbAllocated++;
1353  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1354  {
1355  // limit to physical resources last resource assignment
1356  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1357  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1358  if (rbPerFlow < 3)
1359  {
1360  // terminate allocation
1361  rbPerFlow = 0;
1362  }
1363  }
1364  }
1365  if (!allocated)
1366  {
1367  // unable to allocate new resource: finish scheduling
1368  m_nextRntiUl = (*it).first;
1369  if (ret.m_dciList.size () > 0)
1370  {
1372  }
1373  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1374  return;
1375  }
1376  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1377  int cqi = 0;
1378  if (itCqi == m_ueCqi.end ())
1379  {
1380  // no cqi info about this UE
1381  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1382  NS_LOG_INFO (this << " UE does not have ULCQI " << (*it).first );
1383  }
1384  else
1385  {
1386  // take the lowest CQI value (worst RB)
1387  NS_ABORT_MSG_IF ((*itCqi).second.size() == 0, "CQI of RNTI = " << (*it).first << " has expired");
1388  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1389  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1390  {
1391  if ((*itCqi).second.at (i) < minSinr)
1392  {
1393  minSinr = (*itCqi).second.at (i);
1394  }
1395  }
1396  // translate SINR -> cqi: WILD ACK: same as DL
1397  double s = log2 ( 1 + (
1398  std::pow (10, minSinr / 10 ) /
1399  ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1400 
1401 
1402  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1403  if (cqi == 0)
1404  {
1405  it++;
1406  if (it == m_ceBsrRxed.end ())
1407  {
1408  // restart from the first
1409  it = m_ceBsrRxed.begin ();
1410  }
1411  NS_LOG_DEBUG (this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1412  // remove UE from allocation map
1413  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1414  {
1415  rbgAllocationMap.at (i) = 0;
1416  }
1417  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1418  }
1419  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1420  }
1421  uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8); // MCS 0 -> UL-AMC TBD
1422 
1423  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1424  uldci.m_ndi = 1;
1425  uldci.m_cceIndex = 0;
1426  uldci.m_aggrLevel = 1;
1427  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1428  uldci.m_hopping = false;
1429  uldci.m_n2Dmrs = 0;
1430  uldci.m_tpc = 0; // no power control
1431  uldci.m_cqiRequest = false; // only period CQI at this stage
1432  uldci.m_ulIndex = 0; // TDD parameter
1433  uldci.m_dai = 1; // TDD parameter
1434  uldci.m_freqHopping = 0;
1435  uldci.m_pdcchPowerOffset = 0; // not used
1436  ret.m_dciList.push_back (uldci);
1437  // store DCI for HARQ_PERIOD
1438  uint8_t harqId = 0;
1439  if (m_harqOn == true)
1440  {
1441  std::map <uint16_t, uint8_t>::iterator itProcId;
1442  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1443  if (itProcId == m_ulHarqCurrentProcessId.end ())
1444  {
1445  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1446  }
1447  harqId = (*itProcId).second;
1448  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1449  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1450  {
1451  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1452  }
1453  (*itDci).second.at (harqId) = uldci;
1454  // Update HARQ process status (RV 0)
1455  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (uldci.m_rnti);
1456  if (itStat == m_ulHarqProcessesStatus.end ())
1457  {
1458  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << uldci.m_rnti);
1459  }
1460  (*itStat).second.at (harqId) = 0;
1461  }
1462 
1463  NS_LOG_INFO (this << " UL Allocation - UE " << (*it).first << " startPRB " << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize " << uldci.m_tbSize << " harqId " << (uint16_t)harqId);
1464 
1465  it++;
1466  if (it == m_ceBsrRxed.end ())
1467  {
1468  // restart from the first
1469  it = m_ceBsrRxed.begin ();
1470  }
1471  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1472  {
1473  // Stop allocation: no more PRBs
1474  m_nextRntiUl = (*it).first;
1475  break;
1476  }
1477  }
1478  while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1479 
1480  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1481 
1483  return;
1484 }
1485 
1486 void
1488 {
1489  NS_LOG_FUNCTION (this);
1490  return;
1491 }
1492 
1493 void
1495 {
1496  NS_LOG_FUNCTION (this);
1497  return;
1498 }
1499 
1500 void
1502 {
1503  NS_LOG_FUNCTION (this);
1504 
1505  std::map <uint16_t,uint32_t>::iterator it;
1506 
1507  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
1508  {
1509  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1510  {
1511  // buffer status report
1512  // note that this scheduler does not differentiate the
1513  // allocation according to which LCGs have more/less bytes
1514  // to send.
1515  // Hence the BSR of different LCGs are just summed up to get
1516  // a total queue size that is used for allocation purposes.
1517 
1518  uint32_t buffer = 0;
1519  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1520  {
1521  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1522  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1523  }
1524 
1525  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1526  it = m_ceBsrRxed.find (rnti);
1527  if (it == m_ceBsrRxed.end ())
1528  {
1529  // create the new entry
1530  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1531  NS_LOG_INFO (this << " Insert RNTI " << rnti << " queue " << buffer);
1532  }
1533  else
1534  {
1535  // update the buffer size value
1536  (*it).second = buffer;
1537  NS_LOG_INFO (this << " Update RNTI " << rnti << " queue " << buffer);
1538  }
1539  }
1540  }
1541 
1542  return;
1543 }
1544 
1545 void
1547 {
1548  NS_LOG_FUNCTION (this);
1549 
1550  switch (m_ulCqiFilter)
1551  {
1553  {
1554  // filter all the CQIs that are not SRS based
1555  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1556  {
1557  return;
1558  }
1559  }
1560  break;
1562  {
1563  // filter all the CQIs that are not SRS based
1564  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1565  {
1566  return;
1567  }
1568  }
1569  break;
1570  default:
1571  NS_FATAL_ERROR ("Unknown UL CQI type");
1572  }
1573  switch (params.m_ulCqi.m_type)
1574  {
1575  case UlCqi_s::PUSCH:
1576  {
1577  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1578  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1579  itMap = m_allocationMaps.find (params.m_sfnSf);
1580  if (itMap == m_allocationMaps.end ())
1581  {
1582  NS_LOG_INFO (this << " Does not find info on allocation, size : " << m_allocationMaps.size ());
1583  return;
1584  }
1585  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1586  {
1587  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1588  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
1589  itCqi = m_ueCqi.find ((*itMap).second.at (i));
1590  if (itCqi == m_ueCqi.end ())
1591  {
1592  // create a new entry
1593  std::vector <double> newCqi;
1594  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1595  {
1596  if (i == j)
1597  {
1598  newCqi.push_back (sinr);
1599  }
1600  else
1601  {
1602  // initialize with NO_SINR value.
1603  newCqi.push_back (30.0);
1604  }
1605 
1606  }
1607  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1608  // generate correspondent timer
1609  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
1610  }
1611  else
1612  {
1613  // update the value
1614  (*itCqi).second.at (i) = sinr;
1615  // update correspondent timer
1616  std::map <uint16_t, uint32_t>::iterator itTimers;
1617  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
1618  (*itTimers).second = m_cqiTimersThreshold;
1619 
1620  }
1621 
1622  }
1623  // remove obsolete info on allocation
1624  m_allocationMaps.erase (itMap);
1625  }
1626  break;
1627  case UlCqi_s::SRS:
1628  {
1629  // get the RNTI from vendor specific parameters
1630  uint16_t rnti = 0;
1631  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
1632  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
1633  {
1634  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
1635  {
1636  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
1637  rnti = vsp->GetRnti ();
1638  }
1639  }
1640  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1641  itCqi = m_ueCqi.find (rnti);
1642  if (itCqi == m_ueCqi.end ())
1643  {
1644  // create a new entry
1645  std::vector <double> newCqi;
1646  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1647  {
1648  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1649  newCqi.push_back (sinr);
1650  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
1651 
1652  }
1653  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1654  // generate correspondent timer
1655  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1656  }
1657  else
1658  {
1659  // update the values
1660  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1661  {
1662  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1663  (*itCqi).second.at (j) = sinr;
1664  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
1665  }
1666  // update correspondent timer
1667  std::map <uint16_t, uint32_t>::iterator itTimers;
1668  itTimers = m_ueCqiTimers.find (rnti);
1669  (*itTimers).second = m_cqiTimersThreshold;
1670 
1671  }
1672 
1673 
1674  }
1675  break;
1676  case UlCqi_s::PUCCH_1:
1677  case UlCqi_s::PUCCH_2:
1678  case UlCqi_s::PRACH:
1679  {
1680  NS_FATAL_ERROR ("PfFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1681  }
1682  break;
1683  default:
1684  NS_FATAL_ERROR ("Unknown type of UL-CQI");
1685  }
1686  return;
1687 }
1688 
1689 
1690 void
1692 {
1693  NS_LOG_FUNCTION (this << m_p10CqiTimers.size ());
1694  // refresh DL CQI P01 Map
1695  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
1696  while (itP10 != m_p10CqiTimers.end ())
1697  {
1698  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1699  if ((*itP10).second == 0)
1700  {
1701  // delete correspondent entries
1702  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
1703  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
1704  NS_LOG_INFO (this << " P10-CQI exired for user " << (*itP10).first);
1705  m_p10CqiRxed.erase (itMap);
1706  std::map <uint16_t,uint32_t>::iterator temp = itP10;
1707  itP10++;
1708  m_p10CqiTimers.erase (temp);
1709  }
1710  else
1711  {
1712  (*itP10).second--;
1713  itP10++;
1714  }
1715  }
1716 
1717  return;
1718 }
1719 
1720 
1721 void
1723 {
1724  // refresh UL CQI Map
1725  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
1726  while (itUl != m_ueCqiTimers.end ())
1727  {
1728  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1729  if ((*itUl).second == 0)
1730  {
1731  // delete correspondent entries
1732  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
1733  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
1734  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
1735  (*itMap).second.clear ();
1736  m_ueCqi.erase (itMap);
1737  std::map <uint16_t,uint32_t>::iterator temp = itUl;
1738  itUl++;
1739  m_ueCqiTimers.erase (temp);
1740  }
1741  else
1742  {
1743  (*itUl).second--;
1744  itUl++;
1745  }
1746  }
1747 
1748  return;
1749 }
1750 
1751 void
1752 RrFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
1753 {
1754  NS_LOG_FUNCTION (this);
1755  std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1756  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
1757  {
1758  if (((*it).m_rnti == rnti) && ((*it).m_logicalChannelIdentity == lcid))
1759  {
1760  NS_LOG_INFO (this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue " << (*it).m_rlcTransmissionQueueSize << " retxqueue " << (*it).m_rlcRetransmissionQueueSize << " status " << (*it).m_rlcStatusPduSize << " decrease " << size);
1761  // Update queues: RLC tx order Status, ReTx, Tx
1762  // Update status queue
1763  if (((*it).m_rlcStatusPduSize > 0) && (size >= (*it).m_rlcStatusPduSize))
1764  {
1765  (*it).m_rlcStatusPduSize = 0;
1766  }
1767  else if (((*it).m_rlcRetransmissionQueueSize > 0) && (size >= (*it).m_rlcRetransmissionQueueSize))
1768  {
1769  (*it).m_rlcRetransmissionQueueSize = 0;
1770  }
1771  else if ((*it).m_rlcTransmissionQueueSize > 0)
1772  {
1773  uint32_t rlcOverhead;
1774  if (lcid == 1)
1775  {
1776  // for SRB1 (using RLC AM) it's better to
1777  // overestimate RLC overhead rather than
1778  // underestimate it and risk unneeded
1779  // segmentation which increases delay
1780  rlcOverhead = 4;
1781  }
1782  else
1783  {
1784  // minimum RLC overhead due to header
1785  rlcOverhead = 2;
1786  }
1787  // update transmission queue
1788  if ((*it).m_rlcTransmissionQueueSize <= size - rlcOverhead)
1789  {
1790  (*it).m_rlcTransmissionQueueSize = 0;
1791  }
1792  else
1793  {
1794  (*it).m_rlcTransmissionQueueSize -= size - rlcOverhead;
1795  }
1796  }
1797  return;
1798  }
1799  }
1800 }
1801 
1802 void
1803 RrFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
1804 {
1805 
1806  size = size - 2; // remove the minimum RLC overhead
1807  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
1808  if (it != m_ceBsrRxed.end ())
1809  {
1810  NS_LOG_INFO (this << " Update RLC BSR UE " << rnti << " size " << size << " BSR " << (*it).second);
1811  if ((*it).second >= size)
1812  {
1813  (*it).second -= size;
1814  }
1815  else
1816  {
1817  (*it).second = 0;
1818  }
1819  }
1820  else
1821  {
1822  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
1823  }
1824 
1825 }
1826 
1827 
1828 void
1830 {
1831  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
1833  params.m_rnti = rnti;
1834  params.m_transmissionMode = txMode;
1836 }
1837 
1838 
1839 
1840 }
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:184
Provides the CSCHED SAP.
FfMacCschedSapUser class.
virtual void CschedUeConfigUpdateInd(const struct CschedUeConfigUpdateIndParameters &params)=0
CSCHED_UE_UPDATE_IND.
virtual void CschedUeConfigCnf(const struct CschedUeConfigCnfParameters &params)=0
CSCHED_UE_CONFIG_CNF.
Provides the SCHED SAP.
FfMacSchedSapUser class.
virtual void SchedUlConfigInd(const struct SchedUlConfigIndParameters &params)=0
SCHED_UL_CONFIG_IND.
virtual void SchedDlConfigInd(const struct 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:155
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:139
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Implements the SCHED SAP and CSCHED SAP for a Round Robin scheduler.
friend class MemberCschedSapProvider< RrFfMacScheduler >
allow MemberCschedSapProvider<RrFfMacScheduler> class friend access
virtual ~RrFfMacScheduler()
Destructor.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
static TypeId GetTypeId(void)
Get the type ID.
void DoSchedDlTriggerReq(const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request.
friend class MemberSchedSapProvider< RrFfMacScheduler >
allow MemberSchedSapProvider<RrFfMacScheduler> class friend access
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
void DoCschedLcReleaseReq(const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
set the user part of the FfMacSchedSap that this Scheduler will interact with.
FfMacSchedSapUser * m_schedSapUser
Sched SAP user.
void DoSchedDlRlcBufferReq(const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request.
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
set the user part of the FfMacCschedSap that this Scheduler will interact with.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
void RefreshDlCqiMaps(void)
Refresh DL CQI maps function.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
int GetRbgSize(int dlbandwidth)
Get RBG size function.
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
std::vector< struct RachListElement_s > m_rachList
RACH list.
std::list< FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's RLC info.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
virtual LteFfrSapUser * GetLteFfrSapUser()
virtual void SetLteFfrSapProvider(LteFfrSapProvider *s)
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
uint16_t m_nextRntiDl
RNTI of the next user to be served next scheduling in DL.
void DoSchedUlCqiInfoReq(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
static bool SortRlcBufferReq(FfMacSchedSapProvider::SchedDlRlcBufferReqParameters i, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters j)
Sort RLC buffer request function.
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
Map of previous allocated UE per RBG (used to retrieve info from UL-CQI)
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
void DoSchedDlMacBufferReq(const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request.
void DoCschedUeReleaseReq(const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
void DoCschedLcConfigReq(const struct FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request.
void DoSchedDlRachInfoReq(const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request.
void DoSchedUlTriggerReq(const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void DoSchedUlMacCtrlInfoReq(const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request.
void DoSchedDlPagingBufferReq(const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request.
void RefreshUlCqiMaps(void)
Refresh UL CQI maps function.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update function.
void DoSchedDlCqiInfoReq(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request.
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request.
void DoSchedUlSrInfoReq(const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SRS info request.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
virtual void DoDispose(void)
Destructor implementation.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
void DoSchedUlNoiseInterferenceReq(const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request.
void DoCschedUeConfigReq(const struct FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info function.
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:212
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
#define HARQ_PROC_NUM
#define HARQ_DL_TIMEOUT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#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:88
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: boolean.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#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:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#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.
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
UL HARQ process DCI buffer vector.
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector typedef.
std::vector< uint8_t > DlHarqProcessesStatus_t
DL HARQ process status vector typedef.
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
vector of the 8 HARQ processes per UE
@ SUCCESS
Definition: ff-mac-common.h:62
static const int Type0AllocationRbg[4]
Type 0 RGB allocation.
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector typedef.
std::vector< uint8_t > UlHarqProcessesStatus_t
UL HARQ process status vector.
See section 4.3.8 builDataListElement.
struct DlDciListElement_s m_dci
DCI.
std::vector< std::vector< struct RlcPduListElement_s > > m_rlcPduList
RLC PDU list.
See section 4.3.10 buildRARListElement.
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:94
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:96
std::vector< uint8_t > m_mcs
MCS.
uint8_t m_resAlloc
The type of resource allocation.
Definition: ff-mac-common.h:98
std::vector< uint16_t > m_tbsSize
The TBs size.
Definition: ff-mac-common.h:99
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.
std::vector< uint8_t > m_logicalChannelIdentity
logical channel identity
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.
std::vector< struct CqiListElement_s > m_cqiList
CQI list.
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.
std::vector< struct RachListElement_s > m_rachList
RACH list.
uint32_t m_rlcRetransmissionQueueSize
RLC retransmission queue size.
uint32_t m_rlcTransmissionQueueSize
RLC transmission queue size.
Parameters of the SCHED_DL_TRIGGER_REQ primitive.
std::vector< struct DlInfoListElement_s > m_dlInfoList
DL info list.
Parameters of the SCHED_UL_CQI_INFO_REQ primitive.
std::vector< struct VendorSpecificListElement_s > m_vendorSpecificList
vendor specific list
Parameters of the SCHED_UL_MAC_CTRL_INFO_REQ primitive.
std::vector< struct MacCeListElement_s > m_macCeList
MAC CE list.
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< struct UlInfoListElement_s > m_ulInfoList
UL info list.
uint8_t m_nrOfPdcchOfdmSymbols
number of PDCCH OFDM symbols
std::vector< struct BuildDataListElement_s > m_buildDataList
build data list
std::vector< struct BuildRarListElement_s > m_buildRarList
build rar list
Parameters of the SCHED_UL_CONFIG_IND primitive.
std::vector< struct UlDciListElement_s > m_dciList
DCI list.
See section 4.3.9 rlcPDU_ListElement.
uint8_t m_logicalChannelIdentity
logical channel identity
std::vector< uint16_t > m_sinr
SINR.
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.