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