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_rlcTransmissionQueueHolDelay << " 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  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1388  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1389  {
1390  if ((*itCqi).second.at (i) < minSinr)
1391  {
1392  minSinr = (*itCqi).second.at (i);
1393  }
1394  }
1395  // translate SINR -> cqi: WILD ACK: same as DL
1396  double s = log2 ( 1 + (
1397  std::pow (10, minSinr / 10 ) /
1398  ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1399 
1400 
1401  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1402  if (cqi == 0)
1403  {
1404  it++;
1405  if (it == m_ceBsrRxed.end ())
1406  {
1407  // restart from the first
1408  it = m_ceBsrRxed.begin ();
1409  }
1410  NS_LOG_DEBUG (this << " UE discared for CQI=0, RNTI " << uldci.m_rnti);
1411  // remove UE from allocation map
1412  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1413  {
1414  rbgAllocationMap.at (i) = 0;
1415  }
1416  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1417  }
1418  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1419  }
1420  uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8); // MCS 0 -> UL-AMC TBD
1421 
1422  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1423  uldci.m_ndi = 1;
1424  uldci.m_cceIndex = 0;
1425  uldci.m_aggrLevel = 1;
1426  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1427  uldci.m_hopping = false;
1428  uldci.m_n2Dmrs = 0;
1429  uldci.m_tpc = 0; // no power control
1430  uldci.m_cqiRequest = false; // only period CQI at this stage
1431  uldci.m_ulIndex = 0; // TDD parameter
1432  uldci.m_dai = 1; // TDD parameter
1433  uldci.m_freqHopping = 0;
1434  uldci.m_pdcchPowerOffset = 0; // not used
1435  ret.m_dciList.push_back (uldci);
1436  // store DCI for HARQ_PERIOD
1437  uint8_t harqId = 0;
1438  if (m_harqOn == true)
1439  {
1440  std::map <uint16_t, uint8_t>::iterator itProcId;
1441  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1442  if (itProcId == m_ulHarqCurrentProcessId.end ())
1443  {
1444  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1445  }
1446  harqId = (*itProcId).second;
1447  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1448  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1449  {
1450  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1451  }
1452  (*itDci).second.at (harqId) = uldci;
1453  // Update HARQ process status (RV 0)
1454  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (uldci.m_rnti);
1455  if (itStat == m_ulHarqProcessesStatus.end ())
1456  {
1457  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << uldci.m_rnti);
1458  }
1459  (*itStat).second.at (harqId) = 0;
1460  }
1461 
1462  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);
1463 
1464  it++;
1465  if (it == m_ceBsrRxed.end ())
1466  {
1467  // restart from the first
1468  it = m_ceBsrRxed.begin ();
1469  }
1470  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1471  {
1472  // Stop allocation: no more PRBs
1473  m_nextRntiUl = (*it).first;
1474  break;
1475  }
1476  }
1477  while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1478 
1479  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1480 
1482  return;
1483 }
1484 
1485 void
1487 {
1488  NS_LOG_FUNCTION (this);
1489  return;
1490 }
1491 
1492 void
1494 {
1495  NS_LOG_FUNCTION (this);
1496  return;
1497 }
1498 
1499 void
1501 {
1502  NS_LOG_FUNCTION (this);
1503 
1504  std::map <uint16_t,uint32_t>::iterator it;
1505 
1506  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
1507  {
1508  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1509  {
1510  // buffer status report
1511  // note that this scheduler does not differentiate the
1512  // allocation according to which LCGs have more/less bytes
1513  // to send.
1514  // Hence the BSR of different LCGs are just summed up to get
1515  // a total queue size that is used for allocation purposes.
1516 
1517  uint32_t buffer = 0;
1518  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1519  {
1520  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1521  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1522  }
1523 
1524  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1525  it = m_ceBsrRxed.find (rnti);
1526  if (it == m_ceBsrRxed.end ())
1527  {
1528  // create the new entry
1529  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1530  NS_LOG_INFO (this << " Insert RNTI " << rnti << " queue " << buffer);
1531  }
1532  else
1533  {
1534  // update the buffer size value
1535  (*it).second = buffer;
1536  NS_LOG_INFO (this << " Update RNTI " << rnti << " queue " << buffer);
1537  }
1538  }
1539  }
1540 
1541  return;
1542 }
1543 
1544 void
1546 {
1547  NS_LOG_FUNCTION (this);
1548 
1549  switch (m_ulCqiFilter)
1550  {
1552  {
1553  // filter all the CQIs that are not SRS based
1554  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1555  {
1556  return;
1557  }
1558  }
1559  break;
1561  {
1562  // filter all the CQIs that are not SRS based
1563  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1564  {
1565  return;
1566  }
1567  }
1569  break;
1570 
1571  default:
1572  NS_FATAL_ERROR ("Unknown UL CQI type");
1573  }
1574  switch (params.m_ulCqi.m_type)
1575  {
1576  case UlCqi_s::PUSCH:
1577  {
1578  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1579  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1580  itMap = m_allocationMaps.find (params.m_sfnSf);
1581  if (itMap == m_allocationMaps.end ())
1582  {
1583  NS_LOG_INFO (this << " Does not find info on allocation, size : " << m_allocationMaps.size ());
1584  return;
1585  }
1586  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1587  {
1588  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1589  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
1590  itCqi = m_ueCqi.find ((*itMap).second.at (i));
1591  if (itCqi == m_ueCqi.end ())
1592  {
1593  // create a new entry
1594  std::vector <double> newCqi;
1595  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1596  {
1597  if (i == j)
1598  {
1599  newCqi.push_back (sinr);
1600  }
1601  else
1602  {
1603  // initialize with NO_SINR value.
1604  newCqi.push_back (30.0);
1605  }
1606 
1607  }
1608  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1609  // generate correspondent timer
1610  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
1611  }
1612  else
1613  {
1614  // update the value
1615  (*itCqi).second.at (i) = sinr;
1616  // update correspondent timer
1617  std::map <uint16_t, uint32_t>::iterator itTimers;
1618  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
1619  (*itTimers).second = m_cqiTimersThreshold;
1620 
1621  }
1622 
1623  }
1624  // remove obsolete info on allocation
1625  m_allocationMaps.erase (itMap);
1626  }
1627  break;
1628  case UlCqi_s::SRS:
1629  {
1630  // get the RNTI from vendor specific parameters
1631  uint16_t rnti = 0;
1632  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
1633  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
1634  {
1635  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
1636  {
1637  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
1638  rnti = vsp->GetRnti ();
1639  }
1640  }
1641  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1642  itCqi = m_ueCqi.find (rnti);
1643  if (itCqi == m_ueCqi.end ())
1644  {
1645  // create a new entry
1646  std::vector <double> newCqi;
1647  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1648  {
1649  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1650  newCqi.push_back (sinr);
1651  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
1652 
1653  }
1654  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1655  // generate correspondent timer
1656  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1657  }
1658  else
1659  {
1660  // update the values
1661  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1662  {
1663  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1664  (*itCqi).second.at (j) = sinr;
1665  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
1666  }
1667  // update correspondent timer
1668  std::map <uint16_t, uint32_t>::iterator itTimers;
1669  itTimers = m_ueCqiTimers.find (rnti);
1670  (*itTimers).second = m_cqiTimersThreshold;
1671 
1672  }
1673 
1674 
1675  }
1676  break;
1677  case UlCqi_s::PUCCH_1:
1678  case UlCqi_s::PUCCH_2:
1679  case UlCqi_s::PRACH:
1680  {
1681  NS_FATAL_ERROR ("PfFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1682  }
1683  break;
1684  default:
1685  NS_FATAL_ERROR ("Unknown type of UL-CQI");
1686  }
1687  return;
1688 }
1689 
1690 
1691 void
1693 {
1694  NS_LOG_FUNCTION (this << m_p10CqiTimers.size ());
1695  // refresh DL CQI P01 Map
1696  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
1697  while (itP10 != m_p10CqiTimers.end ())
1698  {
1699  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1700  if ((*itP10).second == 0)
1701  {
1702  // delete correspondent entries
1703  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
1704  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
1705  NS_LOG_INFO (this << " P10-CQI exired for user " << (*itP10).first);
1706  m_p10CqiRxed.erase (itMap);
1707  std::map <uint16_t,uint32_t>::iterator temp = itP10;
1708  itP10++;
1709  m_p10CqiTimers.erase (temp);
1710  }
1711  else
1712  {
1713  (*itP10).second--;
1714  itP10++;
1715  }
1716  }
1717 
1718  return;
1719 }
1720 
1721 
1722 void
1724 {
1725  // refresh UL CQI Map
1726  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
1727  while (itUl != m_ueCqiTimers.end ())
1728  {
1729  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1730  if ((*itUl).second == 0)
1731  {
1732  // delete correspondent entries
1733  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
1734  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
1735  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
1736  (*itMap).second.clear ();
1737  m_ueCqi.erase (itMap);
1738  std::map <uint16_t,uint32_t>::iterator temp = itUl;
1739  itUl++;
1740  m_ueCqiTimers.erase (temp);
1741  }
1742  else
1743  {
1744  (*itUl).second--;
1745  itUl++;
1746  }
1747  }
1748 
1749  return;
1750 }
1751 
1752 void
1753 RrFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
1754 {
1755  NS_LOG_FUNCTION (this);
1756  std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1757  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
1758  {
1759  if (((*it).m_rnti == rnti) && ((*it).m_logicalChannelIdentity == lcid))
1760  {
1761  NS_LOG_INFO (this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue " << (*it).m_rlcTransmissionQueueSize << " retxqueue " << (*it).m_rlcRetransmissionQueueSize << " status " << (*it).m_rlcStatusPduSize << " decrease " << size);
1762  // Update queues: RLC tx order Status, ReTx, Tx
1763  // Update status queue
1764  if (((*it).m_rlcStatusPduSize > 0) && (size >= (*it).m_rlcStatusPduSize))
1765  {
1766  (*it).m_rlcStatusPduSize = 0;
1767  }
1768  else if (((*it).m_rlcRetransmissionQueueSize > 0) && (size >= (*it).m_rlcRetransmissionQueueSize))
1769  {
1770  (*it).m_rlcRetransmissionQueueSize = 0;
1771  }
1772  else if ((*it).m_rlcTransmissionQueueSize > 0)
1773  {
1774  uint32_t rlcOverhead;
1775  if (lcid == 1)
1776  {
1777  // for SRB1 (using RLC AM) it's better to
1778  // overestimate RLC overhead rather than
1779  // underestimate it and risk unneeded
1780  // segmentation which increases delay
1781  rlcOverhead = 4;
1782  }
1783  else
1784  {
1785  // minimum RLC overhead due to header
1786  rlcOverhead = 2;
1787  }
1788  // update transmission queue
1789  if ((*it).m_rlcTransmissionQueueSize <= size - rlcOverhead)
1790  {
1791  (*it).m_rlcTransmissionQueueSize = 0;
1792  }
1793  else
1794  {
1795  (*it).m_rlcTransmissionQueueSize -= size - rlcOverhead;
1796  }
1797  }
1798  return;
1799  }
1800  }
1801 }
1802 
1803 void
1804 RrFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
1805 {
1806 
1807  size = size - 2; // remove the minimum RLC overhead
1808  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
1809  if (it != m_ceBsrRxed.end ())
1810  {
1811  NS_LOG_INFO (this << " Update RLC BSR UE " << rnti << " size " << size << " BSR " << (*it).second);
1812  if ((*it).second >= size)
1813  {
1814  (*it).second -= size;
1815  }
1816  else
1817  {
1818  (*it).second = 0;
1819  }
1820  }
1821  else
1822  {
1823  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
1824  }
1825 
1826 }
1827 
1828 
1829 void
1831 {
1832  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
1834  params.m_rnti = rnti;
1835  params.m_transmissionMode = txMode;
1837 }
1838 
1839 
1840 
1841 }
std::vector< struct UlInfoListElement_s > m_ulInfoList
UL info list.
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:93
void RefreshUlCqiMaps(void)
Refresh UL CQI maps function.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Service Access Point (SAP) offered by the eNodeB RRC instance to the Frequency Reuse algorithm instan...
Definition: lte-ffr-sap.h:138
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define HARQ_PERIOD
Definition: lte-common.h:30
AttributeValue implementation for Boolean.
Definition: boolean.h:36
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
Ptr< LteAmc > m_amc
AMC.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs&#39; timers on UL-CQI per RBG.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Parameters of the CSCHED_UE_CONFIG_CNF primitive.
Parameters of the CSCHED_UE_RELEASE_REQ primitive.
static TypeId GetTypeId(void)
Get the type ID.
enum ns3::UlCqi_s::Type_e m_type
type
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:84
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
UL HARQ process DCI buffer vector.
std::vector< uint16_t > m_sinr
SINR.
void RefreshDlCqiMaps(void)
Refresh DL CQI maps function.
uint16_t m_rnti
RNTI.
Definition: ff-mac-common.h:95
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector typedef.
#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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request.
std::vector< uint8_t > m_mcs
mcs
See section 4.3.2 ulDciListElement.
Provides the CSCHED SAP.
static bool SortRlcBufferReq(FfMacSchedSapProvider::SchedDlRlcBufferReqParameters i, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters j)
Sort RLC buffer request function.
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
set the user part of the FfMacSchedSap that this Scheduler will interact with.
std::vector< struct UlDciListElement_s > m_dciList
DCI list.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
See section 4.3.10 buildRARListElement.
Parameters of the CSCHED_UE_CONFIG_UPDATE_IND primitive.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
Parameters of the CSCHED_LC_RELEASE_REQ primitive.
void DoCschedLcConfigReq(const struct FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request.
void DoCschedUeConfigReq(const struct FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request.
uint32_t m_rlcRetransmissionQueueSize
RLC retransmission queue size.
void DoSchedDlRachInfoReq(const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request.
std::vector< std::vector< struct RlcPduListElement_s > > m_rlcPduList
RLC PDU list.
FfMacSchedSapUser * m_schedSapUser
Sched SAP user.
Parameters of the SCHED_DL_TRIGGER_REQ primitive.
virtual ~RrFfMacScheduler()
Destructor.
uint8_t m_rbLen
length
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
void DoSchedDlPagingBufferReq(const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request.
uint8_t m_harqProcess
HARQ process.
static const int Type0AllocationRbg[4]
Type 0 RGB allocation.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
vector of the 8 HARQ processes per UE
Parameters of the SCHED_DL_MAC_BUFFER_REQ primitive.
Parameters of the SCHED_DL_PAGING_BUFFER_REQ primitive.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE&#39;s DL CQI P01 received.
virtual void CschedUeConfigUpdateInd(const struct CschedUeConfigUpdateIndParameters &params)=0
CSCHED_UE_UPDATE_IND.
std::vector< struct VendorSpecificListElement_s > m_vendorSpecificList
vendor specific list
uint8_t m_aggrLevel
aggr level
virtual LteFfrSapUser * GetLteFfrSapUser()
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
Service Access Point (SAP) offered by the Frequency Reuse algorithm instance to the MAC Scheduler ins...
Definition: lte-ffr-sap.h:39
Parameters of the SCHED_UL_TRIGGER_REQ primitive.
uint32_t m_rbBitmap
rb bitmap
Definition: ff-mac-common.h:96
Hold an unsigned integer type.
Definition: uinteger.h:44
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
Definition: lte-common.cc:212
bool m_cqiRequest
CQI request.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
std::vector< uint8_t > m_ndi
ndi
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
set the user part of the FfMacCschedSap that this Scheduler will interact with.
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
Map of previous allocated UE per RBG (used to retrieve info from UL-CQI)
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
void DoSchedDlRlcBufferReq(const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request.
uint8_t m_cceIndex
CCE index.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
Provides the SCHED SAP.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE&#39;s timers on DL CQI P01 received.
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
void DoSchedUlCqiInfoReq(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request.
virtual void CschedUeConfigCnf(const struct CschedUeConfigCnfParameters &params)=0
CSCHED_UE_CONFIG_CNF.
std::vector< uint8_t > m_logicalChannelIdentity
logical channel identity
Parameters of the SCHED_UL_NOISE_INTERFERENCE_REQ primitive.
uint8_t m_logicalChannelIdentity
logical channel indentity
std::vector< struct CqiListElement_s > m_cqiList
CQI list.
std::vector< struct DlInfoListElement_s > m_dlInfoList
DL info list.
virtual void SetLteFfrSapProvider(LteFfrSapProvider *s)
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void DoSchedUlSrInfoReq(const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SRS info request.
virtual void SchedDlConfigInd(const struct SchedDlConfigIndParameters &params)=0
SCHED_DL_CONFIG_IND.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info function.
int8_t m_pdcchPowerOffset
CCH power offset.
void DoSchedUlMacCtrlInfoReq(const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request.
std::vector< uint16_t > m_tbsSize
tbs size
Definition: ff-mac-common.h:99
See section 4.3.9 rlcPDU_ListElement.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
int GetRbgSize(int dlbandwidth)
Get RBG size function.
std::list< FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE&#39;s RLC info.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs&#39; UL-CQI per RBG.
uint8_t m_freqHopping
freq hopping
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector typedef.
Parameters of the CSCHED_LC_CONFIG_REQ primitive.
void DoSchedUlNoiseInterferenceReq(const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request.
std::vector< uint8_t > m_rv
rv
MemberCschedSapProvider class.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
virtual void SchedUlConfigInd(const struct SchedUlConfigIndParameters &params)=0
SCHED_UL_CONFIG_IND.
uint8_t m_ulIndex
UL index.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
UlCqiFilter_t m_ulCqiFilter
UL CQI filter.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
void DoCschedLcReleaseReq(const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request.
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
#define SRS_CQI_RNTI_VSP
This abstract base class identifies the interface by means of which the helper object can plug on the...
FfMacCschedSapUser class.
uint8_t m_nrOfPdcchOfdmSymbols
number of PDCCH OFDM symbols
Parameters of the SCHED_DL_CQI_INFO_REQ primitive.
std::vector< struct MacCeListElement_s > m_macCeList
MAC CE list.
std::vector< struct RachListElement_s > m_rachList
RACH list.
static double fpS11dot3toDouble(uint16_t val)
Convert from fixed point S11.3 notation to double.
Definition: lte-common.cc:155
uint8_t m_n2Dmrs
n2 DMRS
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
Implements the SCHED SAP and CSCHED SAP for a Round Robin scheduler.
std::vector< uint8_t > UlHarqProcessesStatus_t
UL HARQ process status vector.
RrFfMacScheduler()
Constructor.
std::vector< uint8_t > DlHarqProcessesStatus_t
DL HARQ process status vector typedef.
Parameters of the SCHED_UL_CQI_INFO_REQ primitive.
static uint32_t BsrId2BufferSize(uint8_t val)
Convert BSR ID to buffer size.
Definition: lte-common.cc:184
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
std::vector< struct RachListElement_s > m_rachList
RACH list.
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
Parameters of the SCHED_UL_MAC_CTRL_INFO_REQ primitive.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
void DoSchedDlTriggerReq(const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request.
void DoCschedUeReleaseReq(const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request.
uint32_t m_cqiTimersThreshold
of TTIs for which a CQI can be considered valid
Parameters of the SCHED_UL_SR_INFO_REQ primitive.
uint16_t m_nextRntiDl
RNTI of the next user to be served next scheduling in DL.
void DoSchedDlCqiInfoReq(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update function.
Parameters of the SCHED_DL_RACH_INFO_REQ primitive.
Parameters of the SCHED_UL_CONFIG_IND primitive.
void DoSchedDlMacBufferReq(const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request.
uint16_t m_rlcTransmissionQueueHolDelay
RLC transmission queue HOL delay.
MemberSchedSapProvider class.
Parameters of the CSCHED_UE_CONFIG_REQ primitive.
virtual void DoDispose(void)
Destructor implementation.
#define HARQ_DL_TIMEOUT
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE&#39;s buffer status reports received.
struct DlDciListElement_s m_dci
DCI.
std::vector< struct BuildRarListElement_s > m_buildRarList
build rar list
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
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
a unique identifier for an interface.
Definition: type-id.h:58
uint8_t m_resAlloc
res allocate
Definition: ff-mac-common.h:98
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
#define HARQ_PROC_NUM
FfMacSchedSapUser class.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
std::vector< struct BuildDataListElement_s > m_buildDataList
build data list
void DoSchedUlTriggerReq(const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request.
uint8_t m_ueTxAntennaSelection
UE antenna selection.
See section 4.3.8 builDataListElement.