A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tdmt-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/tdmt-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 ("TdMtFfMacScheduler");
34 
35 namespace ns3 {
36 
37 int TdMtType0AllocationRbg[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 (TdMtFfMacScheduler);
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  TdMtFfMacScheduler* m_scheduler;
64 };
65 
66 TdMtSchedulerMemberCschedSapProvider::TdMtSchedulerMemberCschedSapProvider ()
67 {
68 }
69 
70 TdMtSchedulerMemberCschedSapProvider::TdMtSchedulerMemberCschedSapProvider (TdMtFfMacScheduler* scheduler) : m_scheduler (scheduler)
71 {
72 }
73 
74 
75 void
77 {
78  m_scheduler->DoCschedCellConfigReq (params);
79 }
80 
81 void
82 TdMtSchedulerMemberCschedSapProvider::CschedUeConfigReq (const struct CschedUeConfigReqParameters& params)
83 {
84  m_scheduler->DoCschedUeConfigReq (params);
85 }
86 
87 
88 void
89 TdMtSchedulerMemberCschedSapProvider::CschedLcConfigReq (const struct CschedLcConfigReqParameters& params)
90 {
91  m_scheduler->DoCschedLcConfigReq (params);
92 }
93 
94 void
95 TdMtSchedulerMemberCschedSapProvider::CschedLcReleaseReq (const struct CschedLcReleaseReqParameters& params)
96 {
97  m_scheduler->DoCschedLcReleaseReq (params);
98 }
99 
100 void
101 TdMtSchedulerMemberCschedSapProvider::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  TdMtFfMacScheduler* m_scheduler;
131 };
132 
133 
134 
135 TdMtSchedulerMemberSchedSapProvider::TdMtSchedulerMemberSchedSapProvider ()
136 {
137 }
138 
139 
140 TdMtSchedulerMemberSchedSapProvider::TdMtSchedulerMemberSchedSapProvider (TdMtFfMacScheduler* scheduler)
141  : m_scheduler (scheduler)
142 {
143 }
144 
145 void
146 TdMtSchedulerMemberSchedSapProvider::SchedDlRlcBufferReq (const struct SchedDlRlcBufferReqParameters& params)
147 {
148  m_scheduler->DoSchedDlRlcBufferReq (params);
149 }
150 
151 void
152 TdMtSchedulerMemberSchedSapProvider::SchedDlPagingBufferReq (const struct SchedDlPagingBufferReqParameters& params)
153 {
154  m_scheduler->DoSchedDlPagingBufferReq (params);
155 }
156 
157 void
158 TdMtSchedulerMemberSchedSapProvider::SchedDlMacBufferReq (const struct SchedDlMacBufferReqParameters& params)
159 {
160  m_scheduler->DoSchedDlMacBufferReq (params);
161 }
162 
163 void
164 TdMtSchedulerMemberSchedSapProvider::SchedDlTriggerReq (const struct SchedDlTriggerReqParameters& params)
165 {
166  m_scheduler->DoSchedDlTriggerReq (params);
167 }
168 
169 void
170 TdMtSchedulerMemberSchedSapProvider::SchedDlRachInfoReq (const struct SchedDlRachInfoReqParameters& params)
171 {
172  m_scheduler->DoSchedDlRachInfoReq (params);
173 }
174 
175 void
176 TdMtSchedulerMemberSchedSapProvider::SchedDlCqiInfoReq (const struct SchedDlCqiInfoReqParameters& params)
177 {
178  m_scheduler->DoSchedDlCqiInfoReq (params);
179 }
180 
181 void
182 TdMtSchedulerMemberSchedSapProvider::SchedUlTriggerReq (const struct SchedUlTriggerReqParameters& params)
183 {
184  m_scheduler->DoSchedUlTriggerReq (params);
185 }
186 
187 void
188 TdMtSchedulerMemberSchedSapProvider::SchedUlNoiseInterferenceReq (const struct SchedUlNoiseInterferenceReqParameters& params)
189 {
190  m_scheduler->DoSchedUlNoiseInterferenceReq (params);
191 }
192 
193 void
194 TdMtSchedulerMemberSchedSapProvider::SchedUlSrInfoReq (const struct SchedUlSrInfoReqParameters& params)
195 {
196  m_scheduler->DoSchedUlSrInfoReq (params);
197 }
198 
199 void
200 TdMtSchedulerMemberSchedSapProvider::SchedUlMacCtrlInfoReq (const struct SchedUlMacCtrlInfoReqParameters& params)
201 {
202  m_scheduler->DoSchedUlMacCtrlInfoReq (params);
203 }
204 
205 void
206 TdMtSchedulerMemberSchedSapProvider::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 TdMtSchedulerMemberCschedSapProvider (this);
222  m_schedSapProvider = new TdMtSchedulerMemberSchedSapProvider (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 TdMtFfMacScheduler::GetTypeId (void)
247 {
248  static TypeId tid = TypeId ("ns3::TdMtFfMacScheduler")
250  .AddConstructor<TdMtFfMacScheduler> ()
251  .AddAttribute ("CqiTimerThreshold",
252  "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
253  UintegerValue (1000),
254  MakeUintegerAccessor (&TdMtFfMacScheduler::m_cqiTimersThreshold),
255  MakeUintegerChecker<uint32_t> ())
256  .AddAttribute ("HarqEnabled",
257  "Activate/Deactivate the HARQ [by default is active].",
258  BooleanValue (true),
259  MakeBooleanAccessor (&TdMtFfMacScheduler::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 (&TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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 TdMtFfMacScheduler::GetRbgSize (int dlbandwidth)
480 {
481  for (int i = 0; i < 4; i++)
482  {
483  if (dlbandwidth < TdMtType0AllocationRbg[i])
484  {
485  return (i + 1);
486  }
487  }
488 
489  return (-1);
490 }
491 
492 
493 int
494 TdMtFfMacScheduler::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 TdMtFfMacScheduler::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  std::set <uint16_t>::iterator it;
949  std::set <uint16_t>::iterator itMax = m_flowStatsDl.end ();
950  double metricMax = 0.0;
951  for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it++)
952  {
953  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it));
954  if ((itRnti != rntiAllocated.end ())||(!HarqProcessAvailability ((*it))))
955  {
956  // UE already allocated for HARQ or without HARQ process available -> drop it
957  if (itRnti != rntiAllocated.end ())
958  {
959  NS_LOG_DEBUG (this << " RNTI discared for HARQ tx" << (uint16_t)(*it));
960  }
961  if (!HarqProcessAvailability ((*it)))
962  {
963  NS_LOG_DEBUG (this << " RNTI discared for HARQ id" << (uint16_t)(*it));
964  }
965 
966  continue;
967  }
968 
969  std::map <uint16_t,uint8_t>::iterator itTxMode;
970  itTxMode = m_uesTxMode.find ((*it));
971  if (itTxMode == m_uesTxMode.end ())
972  {
973  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it));
974  }
975  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
976  std::map <uint16_t,uint8_t>::iterator itCqi = m_p10CqiRxed.find ((*it));
977  uint8_t wbCqi = 0;
978  if (itCqi != m_p10CqiRxed.end ())
979  {
980  wbCqi = (*itCqi).second;
981  }
982  else
983  {
984  wbCqi = 1; // lowest value fro trying a transmission
985  }
986 
987  if (wbCqi != 0)
988  {
989  // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
990  if (LcActivePerFlow (*it) > 0)
991  {
992  // this UE has data to transmit
993  double achievableRate = 0.0;
994  for (uint8_t k = 0; k < nLayer; k++)
995  {
996  uint8_t mcs = 0;
997  mcs = m_amc->GetMcsFromCqi (wbCqi);
998  achievableRate += ((m_amc->GetTbSizeFromMcs (mcs, rbgSize) / 8) / 0.001); // = TB size / TTI
999 
1000  NS_LOG_DEBUG (this << " RNTI " << (*it) << " MCS " << (uint32_t)mcs << " achievableRate " << achievableRate );
1001  }
1002 
1003  double metric = achievableRate;
1004 
1005  if (metric > metricMax)
1006  {
1007  metricMax = metric;
1008  itMax = it;
1009  }
1010  } // LcActivePerFlow
1011 
1012  } // cqi
1013 
1014  } // end for m_flowStatsDl
1015 
1016  if (itMax == m_flowStatsDl.end ())
1017  {
1018  // no UE available for downlink
1019  NS_LOG_INFO (this << " any UE found");
1020  }
1021  else
1022  {
1023  // assign all free RBGs to this UE
1024  std::vector <uint16_t> tempMap;
1025  for (int i = 0; i < rbgNum; i++)
1026  {
1027  NS_LOG_INFO (this << " ALLOCATION for RBG " << i << " of " << rbgNum);
1028  NS_LOG_DEBUG (this << " ALLOCATION for RBG " << i << " of " << rbgNum);
1029  if (rbgMap.at (i) == false)
1030  {
1031  rbgMap.at (i) = true;
1032  tempMap.push_back (i);
1033  } // end for RBG free
1034 
1035  } // end for RBGs
1036 
1037  allocationMap.insert (std::pair <uint16_t, std::vector <uint16_t> > ((*itMax), tempMap));
1038  }
1039 
1040  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1041  // creating the correspondent DCIs
1042  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1043  while (itMap != allocationMap.end ())
1044  {
1045  // create new BuildDataListElement_s for this LC
1046  BuildDataListElement_s newEl;
1047  newEl.m_rnti = (*itMap).first;
1048  // create the DlDciListElement_s
1049  DlDciListElement_s newDci;
1050  newDci.m_rnti = (*itMap).first;
1051  newDci.m_harqProcess = UpdateHarqProcessId ((*itMap).first);
1052 
1053  uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1054  NS_LOG_INFO (this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1055  uint16_t RgbPerRnti = (*itMap).second.size ();
1056  std::map <uint16_t,uint8_t>::iterator itCqi;
1057  itCqi = m_p10CqiRxed.find ((*itMap).first);
1058  std::map <uint16_t,uint8_t>::iterator itTxMode;
1059  itTxMode = m_uesTxMode.find ((*itMap).first);
1060  if (itTxMode == m_uesTxMode.end ())
1061  {
1062  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*itMap).first);
1063  }
1064  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1065  for (uint8_t j = 0; j < nLayer; j++)
1066  {
1067  if (itCqi == m_p10CqiRxed.end ())
1068  {
1069  newDci.m_mcs.push_back (0); // no info on this user -> lowest MCS
1070  }
1071  else
1072  {
1073  newDci.m_mcs.push_back ( m_amc->GetMcsFromCqi ((*itCqi).second) );
1074  }
1075 
1076  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)
1077  newDci.m_tbsSize.push_back (tbSize);
1078  }
1079 
1080  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1081  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1082  uint32_t rbgMask = 0;
1083  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1084  {
1085  rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1086  NS_LOG_INFO (this << " Allocated RBG " << (*itMap).second.at (k));
1087  }
1088  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1089 
1090  // create the rlc PDUs -> equally divide resources among actives LCs
1091  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1092  for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1093  {
1094  if (((*itBufReq).first.m_rnti == (*itMap).first)
1095  && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1096  || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1097  || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1098  {
1099  std::vector <struct RlcPduListElement_s> newRlcPduLe;
1100  for (uint8_t j = 0; j < nLayer; j++)
1101  {
1102  RlcPduListElement_s newRlcEl;
1103  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1104  newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1105  NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1106  newRlcPduLe.push_back (newRlcEl);
1107  UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1108  if (m_harqOn == true)
1109  {
1110  // store RLC PDU list for HARQ
1111  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1112  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1113  {
1114  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1115  }
1116  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1117  }
1118  }
1119  newEl.m_rlcPduList.push_back (newRlcPduLe);
1120  }
1121  if ((*itBufReq).first.m_rnti > (*itMap).first)
1122  {
1123  break;
1124  }
1125  }
1126  for (uint8_t j = 0; j < nLayer; j++)
1127  {
1128  newDci.m_ndi.push_back (1);
1129  newDci.m_rv.push_back (0);
1130  }
1131 
1132  newEl.m_dci = newDci;
1133 
1134  if (m_harqOn == true)
1135  {
1136  // store DCI for HARQ
1137  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1138  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1139  {
1140  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1141  }
1142  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1143  // refresh timer
1144  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1145  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1146  {
1147  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1148  }
1149  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1150  }
1151 
1152  // ...more parameters -> ingored in this version
1153 
1154  ret.m_buildDataList.push_back (newEl);
1155 
1156  itMap++;
1157  } // end while allocation
1158  ret.m_nrOfPdcchOfdmSymbols = 1; // TODO: check correct value according the DCIs txed
1159 
1160  m_schedSapUser->SchedDlConfigInd (ret);
1161 
1162 
1163  return;
1164 }
1165 
1166 void
1167 TdMtFfMacScheduler::DoSchedDlRachInfoReq (const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters& params)
1168 {
1169  NS_LOG_FUNCTION (this);
1170 
1171  m_rachList = params.m_rachList;
1172 
1173  return;
1174 }
1175 
1176 void
1177 TdMtFfMacScheduler::DoSchedDlCqiInfoReq (const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters& params)
1178 {
1179  NS_LOG_FUNCTION (this);
1180 
1181  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1182  {
1183  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1184  {
1185  // wideband CQI reporting
1186  std::map <uint16_t,uint8_t>::iterator it;
1187  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1188  it = m_p10CqiRxed.find (rnti);
1189  if (it == m_p10CqiRxed.end ())
1190  {
1191  // create the new entry
1192  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)
1193  // generate correspondent timer
1194  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1195  }
1196  else
1197  {
1198  // update the CQI value and refresh correspondent timer
1199  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1200  // update correspondent timer
1201  std::map <uint16_t,uint32_t>::iterator itTimers;
1202  itTimers = m_p10CqiTimers.find (rnti);
1203  (*itTimers).second = m_cqiTimersThreshold;
1204  }
1205  }
1206  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1207  {
1208  // subband CQI reporting high layer configured
1209  std::map <uint16_t,SbMeasResult_s>::iterator it;
1210  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1211  it = m_a30CqiRxed.find (rnti);
1212  if (it == m_a30CqiRxed.end ())
1213  {
1214  // create the new entry
1215  m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1216  m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1217  }
1218  else
1219  {
1220  // update the CQI value and refresh correspondent timer
1221  (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1222  std::map <uint16_t,uint32_t>::iterator itTimers;
1223  itTimers = m_a30CqiTimers.find (rnti);
1224  (*itTimers).second = m_cqiTimersThreshold;
1225  }
1226  }
1227  else
1228  {
1229  NS_LOG_ERROR (this << " CQI type unknown");
1230  }
1231  }
1232 
1233  return;
1234 }
1235 
1236 
1237 double
1238 TdMtFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1239 {
1240  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1241  if (itCqi == m_ueCqi.end ())
1242  {
1243  // no cqi info about this UE
1244  return (NO_SINR);
1245 
1246  }
1247  else
1248  {
1249  // take the average SINR value among the available
1250  double sinrSum = 0;
1251  int sinrNum = 0;
1252  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1253  {
1254  double sinr = (*itCqi).second.at (i);
1255  if (sinr != NO_SINR)
1256  {
1257  sinrSum += sinr;
1258  sinrNum++;
1259  }
1260  }
1261  double estimatedSinr = sinrSum / (double)sinrNum;
1262  // store the value
1263  (*itCqi).second.at (rb) = estimatedSinr;
1264  return (estimatedSinr);
1265  }
1266 }
1267 
1268 void
1269 TdMtFfMacScheduler::DoSchedUlTriggerReq (const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters& params)
1270 {
1271  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1272 
1273  RefreshUlCqiMaps ();
1274 
1275  // Generate RBs map
1276  FfMacSchedSapUser::SchedUlConfigIndParameters ret;
1277  std::vector <bool> rbMap;
1278  uint16_t rbAllocatedNum = 0;
1279  std::set <uint16_t> rntiAllocated;
1280  std::vector <uint16_t> rbgAllocationMap;
1281  // update with RACH allocation map
1282  rbgAllocationMap = m_rachAllocationMap;
1283  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1284  m_rachAllocationMap.clear ();
1285  m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1286 
1287  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1288  // remove RACH allocation
1289  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1290  {
1291  if (rbgAllocationMap.at (i) != 0)
1292  {
1293  rbMap.at (i) = true;
1294  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1295  }
1296  }
1297 
1298 
1299  if (m_harqOn == true)
1300  {
1301  // Process UL HARQ feedback
1302  // update UL HARQ proc id
1303  std::map <uint16_t, uint8_t>::iterator itProcId;
1304  for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
1305  {
1306  (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
1307  }
1308 
1309  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1310  {
1311  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1312  {
1313  // retx correspondent block: retrieve the UL-DCI
1314  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1315  itProcId = m_ulHarqCurrentProcessId.find (rnti);
1316  if (itProcId == m_ulHarqCurrentProcessId.end ())
1317  {
1318  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1319  }
1320  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1321  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId << " i " << i << " size " << params.m_ulInfoList.size ());
1322  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1323  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1324  {
1325  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1326  continue;
1327  }
1328  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1329  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1330  if (itStat == m_ulHarqProcessesStatus.end ())
1331  {
1332  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1333  }
1334  if ((*itStat).second.at (harqId) >= 3)
1335  {
1336  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1337  continue;
1338  }
1339  bool free = true;
1340  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1341  {
1342  if (rbMap.at (j) == true)
1343  {
1344  free = false;
1345  NS_LOG_INFO (this << " BUSY " << j);
1346  }
1347  }
1348  if (free)
1349  {
1350  // retx on the same RBs
1351  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1352  {
1353  rbMap.at (j) = true;
1354  rbgAllocationMap.at (j) = dci.m_rnti;
1355  NS_LOG_INFO ("\tRB " << j);
1356  rbAllocatedNum++;
1357  }
1358  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);
1359  }
1360  else
1361  {
1362  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1363  continue;
1364  }
1365  dci.m_ndi = 0;
1366  // Update HARQ buffers with new HarqId
1367  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1368  (*itStat).second.at (harqId) = 0;
1369  (*itHarq).second.at ((*itProcId).second) = dci;
1370  ret.m_dciList.push_back (dci);
1371  rntiAllocated.insert (dci.m_rnti);
1372  }
1373  else
1374  {
1375  NS_LOG_INFO (this << " HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1376  }
1377  }
1378  }
1379 
1380  std::map <uint16_t,uint32_t>::iterator it;
1381  int nflows = 0;
1382 
1383  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1384  {
1385  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1386  // select UEs with queues not empty and not yet allocated for HARQ
1387  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1388  {
1389  nflows++;
1390  }
1391  }
1392 
1393  if (nflows == 0)
1394  {
1395  if (ret.m_dciList.size () > 0)
1396  {
1397  m_schedSapUser->SchedUlConfigInd (ret);
1398  }
1399 
1400  return; // no flows to be scheduled
1401  }
1402 
1403 
1404  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1405  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size ());
1406  if (rbPerFlow < 3)
1407  {
1408  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity >= 7 bytes
1409  }
1410  int rbAllocated = 0;
1411 
1412  if (m_nextRntiUl != 0)
1413  {
1414  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1415  {
1416  if ((*it).first == m_nextRntiUl)
1417  {
1418  break;
1419  }
1420  }
1421  if (it == m_ceBsrRxed.end ())
1422  {
1423  NS_LOG_ERROR (this << " no user found");
1424  }
1425  }
1426  else
1427  {
1428  it = m_ceBsrRxed.begin ();
1429  m_nextRntiUl = (*it).first;
1430  }
1431  do
1432  {
1433  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1434  if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1435  {
1436  // UE already allocated for UL-HARQ -> skip it
1437  it++;
1438  if (it == m_ceBsrRxed.end ())
1439  {
1440  // restart from the first
1441  it = m_ceBsrRxed.begin ();
1442  }
1443  continue;
1444  }
1445  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1446  {
1447  // limit to physical resources last resource assignment
1448  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1449  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1450  if (rbPerFlow < 3)
1451  {
1452  // terminate allocation
1453  rbPerFlow = 0;
1454  }
1455  }
1456 
1457  UlDciListElement_s uldci;
1458  uldci.m_rnti = (*it).first;
1459  uldci.m_rbLen = rbPerFlow;
1460  bool allocated = false;
1461  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow);
1462  while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0))
1463  {
1464  // check availability
1465  bool free = true;
1466  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1467  {
1468  if (rbMap.at (j) == true)
1469  {
1470  free = false;
1471  break;
1472  }
1473  }
1474  if (free)
1475  {
1476  uldci.m_rbStart = rbAllocated;
1477 
1478  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1479  {
1480  rbMap.at (j) = true;
1481  // store info on allocation for managing ul-cqi interpretation
1482  rbgAllocationMap.at (j) = (*it).first;
1483  }
1484  rbAllocated += rbPerFlow;
1485  allocated = true;
1486  break;
1487  }
1488  rbAllocated++;
1489  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1490  {
1491  // limit to physical resources last resource assignment
1492  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1493  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1494  if (rbPerFlow < 3)
1495  {
1496  // terminate allocation
1497  rbPerFlow = 0;
1498  }
1499  }
1500  }
1501  if (!allocated)
1502  {
1503  // unable to allocate new resource: finish scheduling
1504  m_nextRntiUl = (*it).first;
1505  if (ret.m_dciList.size () > 0)
1506  {
1507  m_schedSapUser->SchedUlConfigInd (ret);
1508  }
1509  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1510  return;
1511  }
1512 
1513 
1514 
1515  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1516  int cqi = 0;
1517  if (itCqi == m_ueCqi.end ())
1518  {
1519  // no cqi info about this UE
1520  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1521  }
1522  else
1523  {
1524  // take the lowest CQI value (worst RB)
1525  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1526  if (minSinr == NO_SINR)
1527  {
1528  minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1529  }
1530  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1531  {
1532  double sinr = (*itCqi).second.at (i);
1533  if (sinr == NO_SINR)
1534  {
1535  sinr = EstimateUlSinr ((*it).first, i);
1536  }
1537  if ((*itCqi).second.at (i) < minSinr)
1538  {
1539  minSinr = (*itCqi).second.at (i);
1540  }
1541  }
1542 
1543  // translate SINR -> cqi: WILD ACK: same as DL
1544  double s = log2 ( 1 + (
1545  pow (10, minSinr / 10 ) /
1546  ( (-log (5.0 * 0.00005 )) / 1.5) ));
1547  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1548  if (cqi == 0)
1549  {
1550  it++;
1551  if (it == m_ceBsrRxed.end ())
1552  {
1553  // restart from the first
1554  it = m_ceBsrRxed.begin ();
1555  }
1556  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1557  }
1558  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1559  }
1560 
1561  uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1562  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1563  uldci.m_ndi = 1;
1564  uldci.m_cceIndex = 0;
1565  uldci.m_aggrLevel = 1;
1566  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1567  uldci.m_hopping = false;
1568  uldci.m_n2Dmrs = 0;
1569  uldci.m_tpc = 0; // no power control
1570  uldci.m_cqiRequest = false; // only period CQI at this stage
1571  uldci.m_ulIndex = 0; // TDD parameter
1572  uldci.m_dai = 1; // TDD parameter
1573  uldci.m_freqHopping = 0;
1574  uldci.m_pdcchPowerOffset = 0; // not used
1575  ret.m_dciList.push_back (uldci);
1576  // store DCI for HARQ_PERIOD
1577  uint8_t harqId = 0;
1578  if (m_harqOn == true)
1579  {
1580  std::map <uint16_t, uint8_t>::iterator itProcId;
1581  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1582  if (itProcId == m_ulHarqCurrentProcessId.end ())
1583  {
1584  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1585  }
1586  harqId = (*itProcId).second;
1587  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1588  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1589  {
1590  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1591  }
1592  (*itDci).second.at (harqId) = uldci;
1593  }
1594 
1595  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);
1596 
1597 
1598  it++;
1599  if (it == m_ceBsrRxed.end ())
1600  {
1601  // restart from the first
1602  it = m_ceBsrRxed.begin ();
1603  }
1604  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1605  {
1606  // Stop allocation: no more PRBs
1607  m_nextRntiUl = (*it).first;
1608  break;
1609  }
1610  }
1611  while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1612 
1613 
1614  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1615  m_schedSapUser->SchedUlConfigInd (ret);
1616 
1617  return;
1618 }
1619 
1620 void
1621 TdMtFfMacScheduler::DoSchedUlNoiseInterferenceReq (const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters& params)
1622 {
1623  NS_LOG_FUNCTION (this);
1624  return;
1625 }
1626 
1627 void
1628 TdMtFfMacScheduler::DoSchedUlSrInfoReq (const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters& params)
1629 {
1630  NS_LOG_FUNCTION (this);
1631  return;
1632 }
1633 
1634 void
1635 TdMtFfMacScheduler::DoSchedUlMacCtrlInfoReq (const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters& params)
1636 {
1637  NS_LOG_FUNCTION (this);
1638 
1639  std::map <uint16_t,uint32_t>::iterator it;
1640 
1641  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
1642  {
1643  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1644  {
1645  // buffer status report
1646  // note that this scheduler does not differentiate the
1647  // allocation according to which LCGs have more/less bytes
1648  // to send.
1649  // Hence the BSR of different LCGs are just summed up to get
1650  // a total queue size that is used for allocation purposes.
1651 
1652  uint32_t buffer = 0;
1653  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1654  {
1655  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1656  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1657  }
1658 
1659  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1660  NS_LOG_LOGIC (this << "RNTI=" << rnti << " buffer=" << buffer);
1661  it = m_ceBsrRxed.find (rnti);
1662  if (it == m_ceBsrRxed.end ())
1663  {
1664  // create the new entry
1665  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1666  }
1667  else
1668  {
1669  // update the buffer size value
1670  (*it).second = buffer;
1671  }
1672  }
1673  }
1674 
1675  return;
1676 }
1677 
1678 void
1679 TdMtFfMacScheduler::DoSchedUlCqiInfoReq (const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters& params)
1680 {
1681  NS_LOG_FUNCTION (this);
1682 // retrieve the allocation for this subframe
1683  switch (m_ulCqiFilter)
1684  {
1685  case FfMacScheduler::SRS_UL_CQI:
1686  {
1687  // filter all the CQIs that are not SRS based
1688  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1689  {
1690  return;
1691  }
1692  }
1693  break;
1694  case FfMacScheduler::PUSCH_UL_CQI:
1695  {
1696  // filter all the CQIs that are not SRS based
1697  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1698  {
1699  return;
1700  }
1701  }
1702  case FfMacScheduler::ALL_UL_CQI:
1703  break;
1704 
1705  default:
1706  NS_FATAL_ERROR ("Unknown UL CQI type");
1707  }
1708 
1709  switch (params.m_ulCqi.m_type)
1710  {
1711  case UlCqi_s::PUSCH:
1712  {
1713  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1714  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1715  NS_LOG_DEBUG (this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
1716  itMap = m_allocationMaps.find (params.m_sfnSf);
1717  if (itMap == m_allocationMaps.end ())
1718  {
1719  return;
1720  }
1721  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1722  {
1723  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1724  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
1725  itCqi = m_ueCqi.find ((*itMap).second.at (i));
1726  if (itCqi == m_ueCqi.end ())
1727  {
1728  // create a new entry
1729  std::vector <double> newCqi;
1730  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1731  {
1732  if (i == j)
1733  {
1734  newCqi.push_back (sinr);
1735  }
1736  else
1737  {
1738  // initialize with NO_SINR value.
1739  newCqi.push_back (NO_SINR);
1740  }
1741 
1742  }
1743  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1744  // generate correspondent timer
1745  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
1746  }
1747  else
1748  {
1749  // update the value
1750  (*itCqi).second.at (i) = sinr;
1751  NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR " << sinr);
1752  // update correspondent timer
1753  std::map <uint16_t, uint32_t>::iterator itTimers;
1754  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
1755  (*itTimers).second = m_cqiTimersThreshold;
1756 
1757  }
1758 
1759  }
1760  // remove obsolete info on allocation
1761  m_allocationMaps.erase (itMap);
1762  }
1763  break;
1764  case UlCqi_s::SRS:
1765  {
1766  // get the RNTI from vendor specific parameters
1767  uint16_t rnti = 0;
1768  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
1769  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
1770  {
1771  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
1772  {
1773  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
1774  rnti = vsp->GetRnti ();
1775  }
1776  }
1777  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1778  itCqi = m_ueCqi.find (rnti);
1779  if (itCqi == m_ueCqi.end ())
1780  {
1781  // create a new entry
1782  std::vector <double> newCqi;
1783  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1784  {
1785  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1786  newCqi.push_back (sinr);
1787  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
1788 
1789  }
1790  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1791  // generate correspondent timer
1792  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1793  }
1794  else
1795  {
1796  // update the values
1797  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1798  {
1799  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1800  (*itCqi).second.at (j) = sinr;
1801  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
1802  }
1803  // update correspondent timer
1804  std::map <uint16_t, uint32_t>::iterator itTimers;
1805  itTimers = m_ueCqiTimers.find (rnti);
1806  (*itTimers).second = m_cqiTimersThreshold;
1807 
1808  }
1809 
1810 
1811  }
1812  break;
1813  case UlCqi_s::PUCCH_1:
1814  case UlCqi_s::PUCCH_2:
1815  case UlCqi_s::PRACH:
1816  {
1817  NS_FATAL_ERROR ("TdMtFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1818  }
1819  break;
1820  default:
1821  NS_FATAL_ERROR ("Unknown type of UL-CQI");
1822  }
1823  return;
1824 }
1825 
1826 void
1827 TdMtFfMacScheduler::RefreshDlCqiMaps (void)
1828 {
1829  // refresh DL CQI P01 Map
1830  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
1831  while (itP10 != m_p10CqiTimers.end ())
1832  {
1833  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1834  if ((*itP10).second == 0)
1835  {
1836  // delete correspondent entries
1837  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
1838  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
1839  NS_LOG_INFO (this << " P10-CQI expired for user " << (*itP10).first);
1840  m_p10CqiRxed.erase (itMap);
1841  std::map <uint16_t,uint32_t>::iterator temp = itP10;
1842  itP10++;
1843  m_p10CqiTimers.erase (temp);
1844  }
1845  else
1846  {
1847  (*itP10).second--;
1848  itP10++;
1849  }
1850  }
1851 
1852  // refresh DL CQI A30 Map
1853  std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
1854  while (itA30 != m_a30CqiTimers.end ())
1855  {
1856  NS_LOG_INFO (this << " A30-CQI for user " << (*itA30).first << " is " << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1857  if ((*itA30).second == 0)
1858  {
1859  // delete correspondent entries
1860  std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
1861  NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (), " Does not find CQI report for user " << (*itA30).first);
1862  NS_LOG_INFO (this << " A30-CQI expired for user " << (*itA30).first);
1863  m_a30CqiRxed.erase (itMap);
1864  std::map <uint16_t,uint32_t>::iterator temp = itA30;
1865  itA30++;
1866  m_a30CqiTimers.erase (temp);
1867  }
1868  else
1869  {
1870  (*itA30).second--;
1871  itA30++;
1872  }
1873  }
1874 
1875  return;
1876 }
1877 
1878 
1879 void
1880 TdMtFfMacScheduler::RefreshUlCqiMaps (void)
1881 {
1882  // refresh UL CQI Map
1883  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
1884  while (itUl != m_ueCqiTimers.end ())
1885  {
1886  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1887  if ((*itUl).second == 0)
1888  {
1889  // delete correspondent entries
1890  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
1891  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
1892  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
1893  (*itMap).second.clear ();
1894  m_ueCqi.erase (itMap);
1895  std::map <uint16_t,uint32_t>::iterator temp = itUl;
1896  itUl++;
1897  m_ueCqiTimers.erase (temp);
1898  }
1899  else
1900  {
1901  (*itUl).second--;
1902  itUl++;
1903  }
1904  }
1905 
1906  return;
1907 }
1908 
1909 void
1910 TdMtFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
1911 {
1912  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1913  LteFlowId_t flow (rnti, lcid);
1914  it = m_rlcBufferReq.find (flow);
1915  if (it != m_rlcBufferReq.end ())
1916  {
1917  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);
1918  // Update queues: RLC tx order Status, ReTx, Tx
1919  // Update status queue
1920  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1921  {
1922  (*it).second.m_rlcStatusPduSize = 0;
1923  }
1924  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
1925  {
1926  (*it).second.m_rlcRetransmissionQueueSize = 0;
1927  }
1928  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1929  {
1930  // update transmission queue
1931  if ((*it).second.m_rlcTransmissionQueueSize <= size)
1932  {
1933  (*it).second.m_rlcTransmissionQueueSize = 0;
1934  }
1935  else
1936  {
1937  size -= 2; // remove minimun RLC overhead due to header
1938  (*it).second.m_rlcTransmissionQueueSize -= size;
1939  }
1940  }
1941  }
1942  else
1943  {
1944  NS_LOG_ERROR (this << " Does not find DL RLC Buffer Report of UE " << rnti);
1945  }
1946 }
1947 
1948 void
1949 TdMtFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
1950 {
1951 
1952  size = size - 2; // remove the minimum RLC overhead
1953  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
1954  if (it != m_ceBsrRxed.end ())
1955  {
1956  NS_LOG_INFO (this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
1957  if ((*it).second >= size)
1958  {
1959  (*it).second -= size;
1960  }
1961  else
1962  {
1963  (*it).second = 0;
1964  }
1965  }
1966  else
1967  {
1968  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
1969  }
1970 
1971 }
1972 
1973 void
1974 TdMtFfMacScheduler::TransmissionModeConfigurationUpdate (uint16_t rnti, uint8_t txMode)
1975 {
1976  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
1977  FfMacCschedSapUser::CschedUeConfigUpdateIndParameters params;
1978  params.m_rnti = rnti;
1979  params.m_transmissionMode = txMode;
1980  m_cschedSapUser->CschedUeConfigUpdateInd (params);
1981 }
1982 
1983 
1984 }
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
Hold a bool native type.
Definition: boolean.h:38
virtual void CschedCellConfigReq(const struct CschedCellConfigReqParameters &params)
CSCHED_CELL_CONFIG_REQ.
#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.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
Hold an unsigned integer type.
Definition: uinteger.h:46
Provides the SCHED SAP.
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
#define NS_LOG_ERROR(msg)
Definition: log.h:237
Implements the SCHED SAP and CSCHED SAP for a Time Domain Maximize Throughput scheduler.
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.